[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.24,0:00:04.12,Default,,0000,0000,0000,,HI, this is X-Raym, for the 8th part\Nof our ReaScript Tutorial. Dialogue: 0,0:00:04.16,0:00:08.28,Default,,0000,0000,0000,,Scripts can define new values\Nto REAPER objects. Dialogue: 0,0:00:08.32,0:00:10.48,Default,,0000,0000,0000,,But you have to be careful. Dialogue: 0,0:00:10.52,0:00:13.60,Default,,0000,0000,0000,,Because these values\Ncan be invalid. Dialogue: 0,0:00:13.64,0:00:17.28,Default,,0000,0000,0000,,No error message may appear, Dialogue: 0,0:00:17.32,0:00:21.32,Default,,0000,0000,0000,,but the value inserted in the project\Nwill be invalid. Dialogue: 0,0:00:21.36,0:00:24.88,Default,,0000,0000,0000,,This is not fatal, be reassured, Dialogue: 0,0:00:24.92,0:00:29.04,Default,,0000,0000,0000,,it cannot corrupt a project\Nand make it unable to be open. Dialogue: 0,0:00:29.08,0:00:32.60,Default,,0000,0000,0000,,We will take back our script\Nwhich modify fade-out length Dialogue: 0,0:00:32.64,0:00:36.24,Default,,0000,0000,0000,,In order to show you\Nhow to prevent this kind of error. Dialogue: 0,0:00:36.28,0:00:38.56,Default,,0000,0000,0000,,In order to ease\Nthe understanding of the phenomenon, Dialogue: 0,0:00:38.60,0:00:40.32,Default,,0000,0000,0000,,I will simplify our script. Dialogue: 0,0:00:40.36,0:00:43.68,Default,,0000,0000,0000,,To do that, I will not\Nrun the {\i1}Main{\i0} function Dialogue: 0,0:00:43.72,0:00:46.64,Default,,0000,0000,0000,,but a new function that\Nwe will call {\i1}Test{\i0}. Dialogue: 0,0:00:46.68,0:00:51.24,Default,,0000,0000,0000,,I declare this function\Nbefore it's execution. Dialogue: 0,0:00:51.56,0:00:53.48,Default,,0000,0000,0000,,{\i1}Function Test(){\i0} Dialogue: 0,0:00:53.52,0:00:56.96,Default,,0000,0000,0000,,And this function will only act\Non the first selected item. Dialogue: 0,0:01:07.00,0:01:08.44,Default,,0000,0000,0000,,0 for the current project, Dialogue: 0,0:01:08.48,0:01:10.12,Default,,0000,0000,0000,,0 for the first item. Dialogue: 0,0:01:13.36,0:01:15.48,Default,,0000,0000,0000,,I check that there is at least\None selected item. Dialogue: 0,0:01:24.52,0:01:26.60,Default,,0000,0000,0000,,If there is one item selected Dialogue: 0,0:01:26.64,0:01:29.56,Default,,0000,0000,0000,,Our script will execute a custom function, Dialogue: 0,0:01:29.60,0:01:33.48,Default,,0000,0000,0000,,I call it {\i1}SetltemFadeOut{\i0} Dialogue: 0,0:01:33.96,0:01:35.52,Default,,0000,0000,0000,,She will have as parameter Dialogue: 0,0:01:38.24,0:01:39.24,Default,,0000,0000,0000,,an item Dialogue: 0,0:01:43.56,0:01:44.80,Default,,0000,0000,0000,,But also an item length Dialogue: 0,0:01:50.28,0:01:53.04,Default,,0000,0000,0000,,and a new value of fade out length. Dialogue: 0,0:02:00.08,0:02:07.88,Default,,0000,0000,0000,,We will get the item length\Nthanks to this function here. Dialogue: 0,0:02:12.68,0:02:16.04,Default,,0000,0000,0000,,I replace {\i1}item{\i0} by\N{\i1}first_sel_item{\i0}. Dialogue: 0,0:02:16.20,0:02:20.48,Default,,0000,0000,0000,,We will write the new value here... Dialogue: 0,0:02:20.76,0:02:21.76,Default,,0000,0000,0000,,and it will be 0. Dialogue: 0,0:02:24.48,0:02:26.20,Default,,0000,0000,0000,,Now I declare this function Dialogue: 0,0:02:32.20,0:02:34.08,Default,,0000,0000,0000,,It has 3 parameters Dialogue: 0,0:02:34.12,0:02:37.24,Default,,0000,0000,0000,,The first parameter is an item. Dialogue: 0,0:02:37.28,0:02:43.36,Default,,0000,0000,0000,,The 2nd will be a length\NI will name it {\i1}item_len{\i0} Dialogue: 0,0:02:43.56,0:02:45.60,Default,,0000,0000,0000,,the 3rd parameter\Na new fade-out length value. Dialogue: 0,0:02:50.72,0:02:55.72,Default,,0000,0000,0000,,This function will define the\Nfade-out length of the first selected item. Dialogue: 0,0:02:56.16,0:02:58.48,Default,,0000,0000,0000,,I copy this function here. Dialogue: 0,0:03:00.88,0:03:07.36,Default,,0000,0000,0000,,I replace the variables by\Nthe parameters of our function. Dialogue: 0,0:03:09.56,0:03:12.76,Default,,0000,0000,0000,,I add {\i1}UpdateArrange{\i0} Dialogue: 0,0:03:15.12,0:03:19.44,Default,,0000,0000,0000,,A define a fade on our item\Nand if all happen as expected, Dialogue: 0,0:03:19.48,0:03:23.64,Default,,0000,0000,0000,,The fade-out length value of the first\Nselected item should be equal to 0. Dialogue: 0,0:03:23.68,0:03:25.60,Default,,0000,0000,0000,,I run the script. Dialogue: 0,0:03:26.20,0:03:28.16,Default,,0000,0000,0000,,All happen as expected. Dialogue: 0,0:03:28.80,0:03:31.36,Default,,0000,0000,0000,,Now imagine the following thing. Dialogue: 0,0:03:31.92,0:03:36.16,Default,,0000,0000,0000,,If {\i1}fade_out_new_value{\i0} is\Nequal to {\i1}100{\i0} Dialogue: 0,0:03:36.20,0:03:41.08,Default,,0000,0000,0000,,Knowing that this value is in seconds\Nand that the item length is only 1 second. Dialogue: 0,0:03:41.12,0:03:42.44,Default,,0000,0000,0000,,Let's see what happens. Dialogue: 0,0:03:45.48,0:03:50.16,Default,,0000,0000,0000,,As you can see the fade-out length\Nseems to match the item length. Dialogue: 0,0:03:50.20,0:03:58.20,Default,,0000,0000,0000,,However, if I display the item properties, I can see\Nthat its fade-out length value is equal to 100 seconds. Dialogue: 0,0:03:58.72,0:04:06.72,Default,,0000,0000,0000,,And you can see that the mouse doesn't behave\Nlike usual, because of this invalid value. Dialogue: 0,0:04:07.12,0:04:13.00,Default,,0000,0000,0000,,Usually, you can see the fade icon-cursor\Nbeing displayed hover the fade. Dialogue: 0,0:04:13.12,0:04:18.36,Default,,0000,0000,0000,,But in our case, there is a bug\Nbecause of an invalid value. Dialogue: 0,0:04:19.00,0:04:23.24,Default,,0000,0000,0000,,So, we will use this function here\Nto prevent this kind of error. Dialogue: 0,0:04:26.68,0:04:28.72,Default,,0000,0000,0000,,We will write the following thing. Dialogue: 0,0:04:29.28,0:04:35.56,Default,,0000,0000,0000,,If the fade length is bigger than\Nthe item length, Dialogue: 0,0:04:35.68,0:04:43.68,Default,,0000,0000,0000,,then the fade-out length\Nwill be equal to the item length. Dialogue: 0,0:04:43.80,0:04:45.76,Default,,0000,0000,0000,,I run the script. Dialogue: 0,0:04:45.80,0:04:50.96,Default,,0000,0000,0000,,Nothing change visually,\Nbut it seems that it is corrected. Dialogue: 0,0:04:51.00,0:04:53.68,Default,,0000,0000,0000,,I check the item properties. Dialogue: 0,0:04:53.88,0:04:57.44,Default,,0000,0000,0000,,The fade-out is not\Nbigger than the item length. Dialogue: 0,0:04:58.44,0:05:03.08,Default,,0000,0000,0000,,Let's see a more complex case:\Nwhat if there was a fade-in? Dialogue: 0,0:05:03.12,0:05:04.24,Default,,0000,0000,0000,,I run the script. Dialogue: 0,0:05:07.80,0:05:10.52,Default,,0000,0000,0000,,It seems to be good Dialogue: 0,0:05:10.56,0:05:15.04,Default,,0000,0000,0000,,but as you can see\Nwe can feel a problem. Dialogue: 0,0:05:15.08,0:05:20.48,Default,,0000,0000,0000,,If I check the item properties I can see\Nthat the fade-out as an invalid value Dialogue: 0,0:05:20.52,0:05:25.16,Default,,0000,0000,0000,,because it is as long as the item, and this\Nis not possible as there is a fade-in. Dialogue: 0,0:05:25.40,0:05:26.88,Default,,0000,0000,0000,,So, I will write the following thing. Dialogue: 0,0:05:35.16,0:05:39.84,Default,,0000,0000,0000,,Here I will get\Nthe fade-in length value. Dialogue: 0,0:05:47.92,0:05:53.76,Default,,0000,0000,0000,,The parameter is {\i1}"D_FADEINLENGTH"{\i0} Dialogue: 0,0:05:55.92,0:05:57.72,Default,,0000,0000,0000,,and I write the following condition: Dialogue: 0,0:05:57.76,0:06:05.76,Default,,0000,0000,0000,,If fade-out length is bigger\Nthan item_length minus the fade-in length Dialogue: 0,0:06:07.60,0:06:14.12,Default,,0000,0000,0000,,then the fade-out length will be equal\Nto item length minus fade-in length. Dialogue: 0,0:06:14.16,0:06:21.16,Default,,0000,0000,0000,,Rather that making the calculation twice\NI will write a max_value variable Dialogue: 0,0:06:23.32,0:06:26.76,Default,,0000,0000,0000,,and I place there here. Dialogue: 0,0:06:26.80,0:06:29.16,Default,,0000,0000,0000,,Oops, small mistake here Dialogue: 0,0:06:29.20,0:06:31.08,Default,,0000,0000,0000,,I run the script. Dialogue: 0,0:06:31.12,0:06:34.16,Default,,0000,0000,0000,,Nothing has visually change,\Nbut if I check the properties, Dialogue: 0,0:06:34.20,0:06:37.08,Default,,0000,0000,0000,,We see that the fade-out length\Nhas a vlaid value. Dialogue: 0,0:06:39.16,0:06:42.24,Default,,0000,0000,0000,,I can now use this function here Dialogue: 0,0:06:44.40,0:06:46.24,Default,,0000,0000,0000,,in our {\i1}Main{\i0} function. Dialogue: 0,0:06:46.28,0:06:49.32,Default,,0000,0000,0000,,Rather than setting a new fade-out length\Nvalue directly here, Dialogue: 0,0:06:49.36,0:06:52.00,Default,,0000,0000,0000,,I use our function Dialogue: 0,0:06:52.08,0:06:55.48,Default,,0000,0000,0000,,which take as first parameter: the item Dialogue: 0,0:06:55.52,0:06:57.68,Default,,0000,0000,0000,,2nd parameter: the item length Dialogue: 0,0:06:57.72,0:06:59.96,Default,,0000,0000,0000,,which has already been calculated here Dialogue: 0,0:07:00.00,0:07:04.40,Default,,0000,0000,0000,,and as new value, the fade-out length\Nof the item udner mouse Dialogue: 0,0:07:04.44,0:07:07.68,Default,,0000,0000,0000,,It was here. Dialogue: 0,0:07:12.16,0:07:15.76,Default,,0000,0000,0000,,I don't need the {\i1}test{\i0} function anymore\Nso I delete it. Dialogue: 0,0:07:18.20,0:07:22.20,Default,,0000,0000,0000,,I replace the execution of the\N{\i1}Test{\i0} function by {\i1}Main{\i0}. Dialogue: 0,0:07:25.24,0:07:31.36,Default,,0000,0000,0000,,{\i1}Main{\i0} works on item in time selection\Non selected tracks. Dialogue: 0,0:07:37.28,0:07:45.28,Default,,0000,0000,0000,,I define a big fade-out length\Non our reference item. Dialogue: 0,0:07:46.64,0:07:49.80,Default,,0000,0000,0000,,I make these items sshorter. Dialogue: 0,0:07:53.68,0:07:55.80,Default,,0000,0000,0000,,I pute some fades-in. Dialogue: 0,0:07:59.64,0:08:05.12,Default,,0000,0000,0000,,I propagate the length value of this fade-out\Non these items and check if there is no errors. Dialogue: 0,0:08:05.76,0:08:12.08,Default,,0000,0000,0000,,As you can see, all seems to be fine. Dialogue: 0,0:08:12.12,0:08:14.12,Default,,0000,0000,0000,,I check. Dialogue: 0,0:08:14.68,0:08:17.96,Default,,0000,0000,0000,,It seems to be good,\Nthe sums seems to be good. Dialogue: 0,0:08:18.00,0:08:24.92,Default,,0000,0000,0000,,Voilà, with simple conditions, we have prevented\Ninvalid values insertions in our project. Dialogue: 0,0:08:24.96,0:08:27.48,Default,,0000,0000,0000,,In general, the rule is simple: Dialogue: 0,0:08:27.52,0:08:34.36,Default,,0000,0000,0000,,determine the minimum and maximum value\Nthat a parameter can have, Dialogue: 0,0:08:34.40,0:08:37.28,Default,,0000,0000,0000,,compare this to the new value\Nwe want to set, Dialogue: 0,0:08:37.32,0:08:45.32,Default,,0000,0000,0000,,and write some conditions to avoid this value to be\Nlower than the minimum or greater than the maximum. Dialogue: 0,0:08:46.24,0:08:50.36,Default,,0000,0000,0000,,In the next video, we will see\Nhow to use tables. See ya!