[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.14,0:00:04.20,Default,,0000,0000,0000,,Hello everyone, this is X-Raym,\Nfor the third part of the tutorial Dialogue: 0,0:00:04.20,0:00:08.82,Default,,0000,0000,0000,,about Lua coding for\NREAPER ReaScript. Dialogue: 0,0:00:08.82,0:00:12.42,Default,,0000,0000,0000,,Today, we will work on Items. Dialogue: 0,0:00:12.42,0:00:16.02,Default,,0000,0000,0000,,We will get infos of first selected items, Dialogue: 0,0:00:16.02,0:00:19.80,Default,,0000,0000,0000,,and then, we will learn\Nhow to modify them. Dialogue: 0,0:00:19.80,0:00:23.98,Default,,0000,0000,0000,,We will start by the script\Nwe wrote last time. Dialogue: 0,0:00:25.00,0:00:32.44,Default,,0000,0000,0000,,I will set Notepad++ this way\Nso that it stay in foreground. Dialogue: 0,0:00:32.44,0:00:37.50,Default,,0000,0000,0000,,Imagine that I want to get\Nthe infos of that items. Dialogue: 0,0:00:38.79,0:00:44.03,Default,,0000,0000,0000,,First, I have to return this item\Nin a variable. Dialogue: 0,0:00:45.04,0:00:50.24,Default,,0000,0000,0000,,I check the API Doc,\Nand I write "Selected Item" Dialogue: 0,0:00:50.24,0:00:54.75,Default,,0000,0000,0000,,We see that there are some\Nfunctions about Item Selection Dialogue: 0,0:00:55.77,0:00:59.10,Default,,0000,0000,0000,,The function that we want\Nis this one. Dialogue: 0,0:00:59.11,0:01:00.97,Default,,0000,0000,0000,,"GetSelectedMedialtem" Dialogue: 0,0:01:02.30,0:01:08.83,Default,,0000,0000,0000,,If we add a project number ID\Nand an integer Dialogue: 0,0:01:08.83,0:01:10.44,Default,,0000,0000,0000,,we get an Item. Dialogue: 0,0:01:11.70,0:01:15.03,Default,,0000,0000,0000,,Project ID is 0 for current project. Dialogue: 0,0:01:15.03,0:01:19.90,Default,,0000,0000,0000,,And the integer is the place\Nof the item in selection. Dialogue: 0,0:01:19.90,0:01:25.10,Default,,0000,0000,0000,,If it is the first item,\Nthe integer will be 0. Dialogue: 0,0:01:25.10,0:01:30.93,Default,,0000,0000,0000,,Demo. I will create a function "Main" Dialogue: 0,0:01:30.93,0:01:35.36,Default,,0000,0000,0000,,which will contain the core\Nof my script. Dialogue: 0,0:01:35.36,0:01:38.22,Default,,0000,0000,0000,,Hop, I put the function end Dialogue: 0,0:01:38.22,0:01:41.21,Default,,0000,0000,0000,,at the end of the script,\NI call "Main". Dialogue: 0,0:01:41.21,0:01:47.97,Default,,0000,0000,0000,,I move the call to that function below\Nso that it is more clean Dialogue: 0,0:01:47.97,0:01:51.10,Default,,0000,0000,0000,,just before the call of Main. Dialogue: 0,0:01:51.10,0:01:54.70,Default,,0000,0000,0000,,Remember, ShowConsoleMsg("")\Nis used to clean the console. Dialogue: 0,0:01:54.70,0:02:01.44,Default,,0000,0000,0000,,I take this.\NThis function return an item. Dialogue: 0,0:02:01.44,0:02:05.13,Default,,0000,0000,0000,,So I will stock this item in a variable. Dialogue: 0,0:02:05.13,0:02:10.67,Default,,0000,0000,0000,,Item = reaper. GetSelectedMedialtem() Dialogue: 0,0:02:10.67,0:02:15.65,Default,,0000,0000,0000,,Here I delete value type reference,\Nwe don't need it. Dialogue: 0,0:02:15.65,0:02:20.07,Default,,0000,0000,0000,,As first parameter,\N0 for current project, Dialogue: 0,0:02:20.07,0:02:27.25,Default,,0000,0000,0000,,and 0 as ineteger,\Nfor First Selected Item. Dialogue: 0,0:02:29.18,0:02:30.99,Default,,0000,0000,0000,,If I run the scrip... Dialogue: 0,0:02:34.05,0:02:38.55,Default,,0000,0000,0000,,The console open because of\NShowConsoleMsg(""), but nothing happen. Dialogue: 0,0:02:39.88,0:02:42.82,Default,,0000,0000,0000,,If I display item in the console... Dialogue: 0,0:02:45.26,0:02:48.43,Default,,0000,0000,0000,,Hop, save, run.. Dialogue: 0,0:02:48.43,0:02:52.94,Default,,0000,0000,0000,,We see that the item\Nis a special type of data Dialogue: 0,0:02:52.94,0:02:55.22,Default,,0000,0000,0000,,called userdata. Dialogue: 0,0:02:55.22,0:02:59.39,Default,,0000,0000,0000,,Userdata in Lua represent an array value... Dialogue: 0,0:02:59.39,0:03:03.87,Default,,0000,0000,0000,,but all you have to remember is that Dialogue: 0,0:03:03.87,0:03:09.82,Default,,0000,0000,0000,,this userdata is specific to this item\Nthe project with a unique ID. Dialogue: 0,0:03:09.82,0:03:13.08,Default,,0000,0000,0000,,We will try to get infos on this item. Dialogue: 0,0:03:15.08,0:03:20.70,Default,,0000,0000,0000,,I get back in function list,\NAnd I enter Item Infos. Dialogue: 0,0:03:21.92,0:03:26.07,Default,,0000,0000,0000,,I see that there is a function\NGetMedialtemlnfo_Value Dialogue: 0,0:03:26.07,0:03:28.77,Default,,0000,0000,0000,,and there is a variant for Take properties. Dialogue: 0,0:03:28.78,0:03:32.75,Default,,0000,0000,0000,,We will focus on item.\NSo, I click on GetMedialtemlnfo_Value Dialogue: 0,0:03:32.75,0:03:35.26,Default,,0000,0000,0000,,and I see this function. Dialogue: 0,0:03:35.26,0:03:40.39,Default,,0000,0000,0000,,If I want to get the state of\NMute of the item. Dialogue: 0,0:03:42.49,0:03:45.52,Default,,0000,0000,0000,,I add a breakline,\Nit is more readable. Dialogue: 0,0:03:45.52,0:03:49.78,Default,,0000,0000,0000,,I add item_mute = Dialogue: 0,0:03:49.78,0:03:51.49,Default,,0000,0000,0000,,and I copy this function. Dialogue: 0,0:03:55.03,0:04:02.68,Default,,0000,0000,0000,,The item that we will set as parameter\Nis the item stored in item variable. Dialogue: 0,0:04:02.68,0:04:06.44,Default,,0000,0000,0000,,I activate the automatic break lines\Nof Notepad++ so it is more readable... Dialogue: 0,0:04:07.79,0:04:13.24,Default,,0000,0000,0000,,As second parameter, it asks for the\Nname of the type of value we want Dialogue: 0,0:04:13.24,0:04:18.45,Default,,0000,0000,0000,,It has to be a string\Nso I write "". Dialogue: 0,0:04:18.45,0:04:22.28,Default,,0000,0000,0000,,The parameter we want in our case\Nis called "B_Mute". Dialogue: 0,0:04:22.28,0:04:25.09,Default,,0000,0000,0000,,I copy "B_Mute"\Nand I paste it here. Dialogue: 0,0:04:27.57,0:04:34.04,Default,,0000,0000,0000,,I delete that...\NI add a break line here... Dialogue: 0,0:04:39.18,0:04:43.05,Default,,0000,0000,0000,,and I ask to the console\Nto display the value of item_mute. Dialogue: 0,0:04:44.99,0:04:46.21,Default,,0000,0000,0000,,I get back here. Dialogue: 0,0:04:47.49,0:04:49.09,Default,,0000,0000,0000,,I run the script. Dialogue: 0,0:04:49.09,0:04:52.12,Default,,0000,0000,0000,,And we see that the value is 0. Dialogue: 0,0:04:52.12,0:04:57.06,Default,,0000,0000,0000,,If I mute the item\Nand I run the script again... Dialogue: 0,0:04:57.06,0:05:01.92,Default,,0000,0000,0000,,we see that when the item is muted,\Nthe value displayed is one. Dialogue: 0,0:05:01.92,0:05:07.67,Default,,0000,0000,0000,,In other words,\NGetMedialtemlnfo_Value("B_Mute") Dialogue: 0,0:05:07.68,0:05:12.41,Default,,0000,0000,0000,,return 1, when the item is muted. Dialogue: 0,0:05:12.41,0:05:17.41,Default,,0000,0000,0000,,Another parameter very interesting\Nis the position. Dialogue: 0,0:05:18.42,0:05:22.55,Default,,0000,0000,0000,,We will duplicate this line. Dialogue: 0,0:05:22.55,0:05:25.64,Default,,0000,0000,0000,,We name this variable item_pos. Dialogue: 0,0:05:27.60,0:05:30.65,Default,,0000,0000,0000,,We add the parameter "D_POS" Dialogue: 0,0:05:30.65,0:05:35.97,Default,,0000,0000,0000,,and we will display the value\Nof this variable. Dialogue: 0,0:05:35.97,0:05:39.92,Default,,0000,0000,0000,,So that we can see better,\NI will add... Dialogue: 0,0:05:39.92,0:05:45.47,Default,,0000,0000,0000,,"Item Mute =" .. Dialogue: 0,0:05:47.19,0:05:50.96,Default,,0000,0000,0000,,And here "Item Position =" .. Dialogue: 0,0:05:59.08,0:06:01.37,Default,,0000,0000,0000,,I save and run. Dialogue: 0,0:06:03.25,0:06:08.04,Default,,0000,0000,0000,,It seems that I made a mistake somewhere... Dialogue: 0,0:06:08.04,0:06:13.82,Default,,0000,0000,0000,,Oh I forgot to add points\Nto tell we merge two strings. Dialogue: 0,0:06:13.82,0:06:15.64,Default,,0000,0000,0000,,I run the script again. Dialogue: 0,0:06:15.64,0:06:19.88,Default,,0000,0000,0000,,We see Item Mute = 0 and\NItem Position = 0 Dialogue: 0,0:06:19.88,0:06:25.64,Default,,0000,0000,0000,,Item Position = 0 because\NI made a mistake here (one trailing space). Dialogue: 0,0:06:25.64,0:06:32.30,Default,,0000,0000,0000,,We will have to be vigilent when coding one small\Nspace at the wrong place can broke the script. Dialogue: 0,0:06:32.30,0:06:33.79,Default,,0000,0000,0000,,I run the script again. Dialogue: 0,0:06:36.29,0:06:41.39,Default,,0000,0000,0000,,Here we see the item position\Nin seconds. Dialogue: 0,0:06:41.39,0:06:48.11,Default,,0000,0000,0000,,As you can see, it is very precise. Dialogue: 0,0:06:48.11,0:06:51.47,Default,,0000,0000,0000,,If I want to display the duration,\NI duplicate Dialogue: 0,0:06:52.72,0:06:56.27,Default,,0000,0000,0000,,I get the parameter value here. Dialogue: 0,0:07:00.11,0:07:01.76,Default,,0000,0000,0000,,I replace. Dialogue: 0,0:07:02.82,0:07:06.26,Default,,0000,0000,0000,,I rename the variable. Dialogue: 0,0:07:07.67,0:07:13.08,Default,,0000,0000,0000,,And I duplicate that too,\Nand display the item length. Dialogue: 0,0:07:15.48,0:07:19.25,Default,,0000,0000,0000,,I save, I select the item\NI run the script. Dialogue: 0,0:07:20.48,0:07:24.51,Default,,0000,0000,0000,,We see that the item length\Nas the same value as the item pos Dialogue: 0,0:07:24.51,0:07:30.22,Default,,0000,0000,0000,,because I forgot to copy paste\Nthe variable here... Dialogue: 0,0:07:30.22,0:07:32.41,Default,,0000,0000,0000,,Voilà. I run again. Dialogue: 0,0:07:35.01,0:07:37.32,Default,,0000,0000,0000,,We will see that the\Nitem length is 9 seconds. Dialogue: 0,0:07:37.32,0:07:45.32,Default,,0000,0000,0000,,If I make it shorter, it display 5s,\Nif I extend, it displays 9 seconds. Dialogue: 0,0:07:46.16,0:07:51.68,Default,,0000,0000,0000,,Another item parameter often used\Nby scripters is the volume. Dialogue: 0,0:07:51.68,0:07:55.74,Default,,0000,0000,0000,,I will show you how it works,\Nbecause it is a bit special. Dialogue: 0,0:07:55.74,0:07:58.46,Default,,0000,0000,0000,,I duplicate this. Dialogue: 0,0:07:58.47,0:08:00.32,Default,,0000,0000,0000,,"D_VOL" Dialogue: 0,0:08:00.32,0:08:07.03,Default,,0000,0000,0000,,Note that the variable can be named\Nwith every name that you want. Dialogue: 0,0:08:09.56,0:08:13.04,Default,,0000,0000,0000,,I duplicate this line. Dialogue: 0,0:08:16.22,0:08:18.08,Default,,0000,0000,0000,,And I wrote item_vol here. Dialogue: 0,0:08:19.57,0:08:23.08,Default,,0000,0000,0000,,If I execute the script, I can see that\Nitem_vol = 1 Dialogue: 0,0:08:23.08,0:08:27.33,Default,,0000,0000,0000,,However, I see that item volume\Nis set to 0 dB. Dialogue: 0,0:08:28.34,0:08:31.89,Default,,0000,0000,0000,,It is because the scale of the\Nvol parameter displayed in the console Dialogue: 0,0:08:31.89,0:08:36.35,Default,,0000,0000,0000,,is completly different. Dialogue: 0,0:08:36.35,0:08:41.34,Default,,0000,0000,0000,,The value returned bu "D_VOL"\Nis on a log scale. Dialogue: 0,0:08:42.48,0:08:49.70,Default,,0000,0000,0000,,If item_vol = 0, it means that\Nthat item volume is -inf dB Dialogue: 0,0:08:49.70,0:08:55.10,Default,,0000,0000,0000,,If item_vol > 1, it means that\Nthe item had a volume boost. Dialogue: 0,0:08:55.11,0:08:59.69,Default,,0000,0000,0000,,I'll show you, if I set -7 dB,\Nand that I run the script again... Dialogue: 0,0:08:59.70,0:09:02.81,Default,,0000,0000,0000,,We see that it is 0.4 (log scale) Dialogue: 0,0:09:02.81,0:09:07.58,Default,,0000,0000,0000,,If I boost at 10 dB, it is equal to 3\N(approx). Dialogue: 0,0:09:07.58,0:09:12.43,Default,,0000,0000,0000,,2 on log scale is for 6 dB boost\N(approx). Dialogue: 0,0:09:12.43,0:09:16.25,Default,,0000,0000,0000,,To convert the log scale value\Ninto dB Dialogue: 0,0:09:16.26,0:09:18.56,Default,,0000,0000,0000,,We have to do some maths. Dialogue: 0,0:09:18.56,0:09:23.02,Default,,0000,0000,0000,,It is a bit complicated but\Nwe can use a code snippet Dialogue: 0,0:09:23.02,0:09:30.53,Default,,0000,0000,0000,,a small code chunk that you can use\Nwithout having to write it from scratch Dialogue: 0,0:09:30.53,0:09:34.56,Default,,0000,0000,0000,,You only have to understand\Nwhat variable you have to replace. Dialogue: 0,0:09:34.56,0:09:38.53,Default,,0000,0000,0000,,Here, we just have to replace\Nsome variable names. Dialogue: 0,0:09:38.53,0:09:46.53,Default,,0000,0000,0000,,We will replace VolDB by item_voldB so\Nthat it matches our other variable naming Dialogue: 0,0:09:46.71,0:09:50.93,Default,,0000,0000,0000,,Here, the value to put\Nis the value of item_vol Dialogue: 0,0:09:52.21,0:09:56.94,Default,,0000,0000,0000,,which is transform\Nby this formula. Dialogue: 0,0:09:56.94,0:10:02.95,Default,,0000,0000,0000,,If I display item_volDB here... Dialogue: 0,0:10:02.95,0:10:05.94,Default,,0000,0000,0000,,we can see that here is 0dB. Dialogue: 0,0:10:05.94,0:10:10.25,Default,,0000,0000,0000,,And here is too. If I set to -7db\Nit displays -7 in the console. Dialogue: 0,0:10:10.25,0:10:13.91,Default,,0000,0000,0000,,If I go to +6db it displays +6. Dialogue: 0,0:10:13.91,0:10:19.45,Default,,0000,0000,0000,,There is other nice parameters, Dialogue: 0,0:10:19.45,0:10:20.94,Default,,0000,0000,0000,,such as fades length, Dialogue: 0,0:10:22.41,0:10:25.38,Default,,0000,0000,0000,,snap offset position, Dialogue: 0,0:10:25.38,0:10:27.79,Default,,0000,0000,0000,,and color of the object. Dialogue: 0,0:10:27.79,0:10:32.14,Default,,0000,0000,0000,,Now imagine that we want to\Nmodify these values. Dialogue: 0,0:10:32.15,0:10:38.20,Default,,0000,0000,0000,,There is a sister function of\NGetMedialtemlnfo_Value which is... Dialogue: 0,0:10:38.20,0:10:40.08,Default,,0000,0000,0000,,I'll show you... Dialogue: 0,0:10:43.25,0:10:46.31,Default,,0000,0000,0000,,which is SetMedialtemlnfo_Value Dialogue: 0,0:10:46.31,0:10:52.32,Default,,0000,0000,0000,,we can see that it look like the Get\Nversion so that there a third parameter Dialogue: 0,0:10:52.32,0:10:54.91,Default,,0000,0000,0000,,which is the new value we want\Nto set. Dialogue: 0,0:10:54.91,0:10:56.47,Default,,0000,0000,0000,,I will copy that. Dialogue: 0,0:10:58.57,0:10:59.57,Default,,0000,0000,0000,,Put it here... Dialogue: 0,0:11:00.98,0:11:05.39,Default,,0000,0000,0000,,The item we want to modify\Nis still in the {\i1}item{\i0} variable. Dialogue: 0,0:11:05.39,0:11:12.18,Default,,0000,0000,0000,,We will start by setting\Nthe mute parameter. Dialogue: 0,0:11:15.10,0:11:17.83,Default,,0000,0000,0000,,"B_MUTE" Dialogue: 0,0:11:17.83,0:11:21.88,Default,,0000,0000,0000,,As new value, we set 0. Dialogue: 0,0:11:21.89,0:11:23.24,Default,,0000,0000,0000,,If I run the script... Dialogue: 0,0:11:24.42,0:11:25.95,Default,,0000,0000,0000,,Nothing happens. Dialogue: 0,0:11:25.95,0:11:29.89,Default,,0000,0000,0000,,But if I zoom out,\Nor click, you see that Dialogue: 0,0:11:29.90,0:11:32.18,Default,,0000,0000,0000,,the item has been unmuted. Dialogue: 0,0:11:32.19,0:11:35.08,Default,,0000,0000,0000,,We have to add at the end of the script Dialogue: 0,0:11:35.08,0:11:38.33,Default,,0000,0000,0000,,a simple function UpdateArrange Dialogue: 0,0:11:38.33,0:11:42.49,Default,,0000,0000,0000,,which allows to update the arrange view\Nif some items have been modified. Dialogue: 0,0:11:42.49,0:11:45.43,Default,,0000,0000,0000,,Now, if I change the script... Dialogue: 0,0:11:46.49,0:11:49.71,Default,,0000,0000,0000,,You see that I don't need to click Dialogue: 0,0:11:50.91,0:11:52.95,Default,,0000,0000,0000,,to refresh the arrange view\N(and the item). Dialogue: 0,0:11:53.97,0:11:55.62,Default,,0000,0000,0000,,Now if I want to modify... Dialogue: 0,0:11:57.47,0:11:59.98,Default,,0000,0000,0000,,the position... Dialogue: 0,0:11:59.98,0:12:03.55,Default,,0000,0000,0000,,I write a new position in seconds. Dialogue: 0,0:12:05.33,0:12:09.62,Default,,0000,0000,0000,,I set "D_POSITION" as second parameter. Dialogue: 0,0:12:09.62,0:12:14.36,Default,,0000,0000,0000,,And now my item should go to 1.5 second. Dialogue: 0,0:12:14.36,0:12:17.10,Default,,0000,0000,0000,,The item is nicely placed at 1.5 s\Nin the project. Dialogue: 0,0:12:20.87,0:12:22.86,Default,,0000,0000,0000,,If I set 3... Dialogue: 0,0:12:24.18,0:12:25.47,Default,,0000,0000,0000,,it will go there... Dialogue: 0,0:12:25.48,0:12:28.32,Default,,0000,0000,0000,,We can of course use calculations. Dialogue: 0,0:12:28.32,0:12:30.73,Default,,0000,0000,0000,,5 + 10 Dialogue: 0,0:12:30.73,0:12:33.12,Default,,0000,0000,0000,,and it will go at position 15 s. Dialogue: 0,0:12:33.12,0:12:35.44,Default,,0000,0000,0000,,To modify the volume, Dialogue: 0,0:12:35.44,0:12:39.83,Default,,0000,0000,0000,,I will advice you to modify the\Nvolume converted in dB. Dialogue: 0,0:12:39.84,0:12:44.50,Default,,0000,0000,0000,,But you will have to set it back\Nto log to make the modification valid. Dialogue: 0,0:12:44.50,0:12:49.07,Default,,0000,0000,0000,,If we want to add\N+1 dB to our item Dialogue: 0,0:12:50.10,0:12:53.00,Default,,0000,0000,0000,,We can do the following thing... Dialogue: 0,0:12:53.00,0:12:54.39,Default,,0000,0000,0000,,And here I do... Dialogue: 0,0:12:55.99,0:12:59.21,Default,,0000,0000,0000,,reaper. SeMedialtemlnfo_Value(item,\N"D_VOL"... Dialogue: 0,0:13:03.37,0:13:06.41,Default,,0000,0000,0000,,reaper. SeMedialtemlnfo_Value(item,\N"D_VOL", item_volDB) Dialogue: 0,0:13:06.41,0:13:12.28,Default,,0000,0000,0000,,It is still express into dB\Nwe have to convert it in Log scale Dialogue: 0,0:13:12.28,0:13:16.51,Default,,0000,0000,0000,,Here is the code snippet. Dialogue: 0,0:13:19.55,0:13:21.23,Default,,0000,0000,0000,,We put it here. Dialogue: 0,0:13:22.50,0:13:29.69,Default,,0000,0000,0000,,And we replace {\i1}calc{\i0}\Nthe variable we have to change, Dialogue: 0,0:13:29.70,0:13:35.45,Default,,0000,0000,0000,,by what we wanted (our dB value +1) Dialogue: 0,0:13:35.45,0:13:39.06,Default,,0000,0000,0000,,I unmute the item,\Nand I run the script. Dialogue: 0,0:13:42.69,0:13:48.14,Default,,0000,0000,0000,,The item goes to position 0,\Nits volume had a +1 dB boost, Dialogue: 0,0:13:48.14,0:13:51.43,Default,,0000,0000,0000,,and it is not muted anymore.\NIf I run the script again... Dialogue: 0,0:13:51.43,0:13:54.97,Default,,0000,0000,0000,,we will see that the item volume\Ngets another extra +1 dB boost. Dialogue: 0,0:13:54.97,0:14:00.72,Default,,0000,0000,0000,,If I want to substract 1 dB,\NI set - here, and when I run the script... Dialogue: 0,0:14:02.23,0:14:03.62,Default,,0000,0000,0000,,The item volume goes down. Dialogue: 0,0:14:03.62,0:14:08.76,Default,,0000,0000,0000,,In the next videos, we will see how to get the\Nparameter values of several selected items Dialogue: 0,0:14:08.76,0:14:11.48,Default,,0000,0000,0000,,and how to modify them\None after the other.