0:00:00.151,0:00:05.014 HI, this is X-Raym, for the 7th part[br]of our ReaScript Course. 0:00:05.015,0:00:10.108 In this episode, will wee learn how to get an item,[br]according to its position on its parent track. 0:00:10.109,0:00:16.504 Imagine that I want to restrict our script[br]on items on selected tracks 0:00:16.505,0:00:18.707 but still in time selection. 0:00:18.708,0:00:21.314 I will have to get my items[br]in a different way. 0:00:21.315,0:00:28.523 But before going further, I will clean the[br]script a bit by create a new functions. 0:00:32.744,0:00:35.828 I will call it Action. 0:00:37.057,0:00:42.621 I delete my warning messages,[br]we don't need it anymore. 0:00:46.822,0:00:51.270 So Main here will check if our action[br]can be executed, 0:00:51.271,0:00:55.775 And we will create a new function[br]called Action. 0:01:13.429,0:01:17.087 I check if the script still works. 0:01:20.305,0:01:24.028 It seems to work fine, I can[br]continue from here. 0:01:24.029,0:01:26.987 I want to consider only[br]selected tracks. 0:01:26.988,0:01:31.554 I will have to make a loop[br]from selected tracks. 0:01:33.869,0:01:36.839 Count... sel... tracks... 0:01:36.968,0:01:39.387 I search for the function... 0:01:49.186,0:01:54.377 I paste it here.[br]The project is 0. 0:01:55.420,0:02:00.294 For every selected tracks... 0:02:04.179,0:02:07.203 count_sel_tracks - 1 0:02:07.204,0:02:09.009 do 0:02:09.011,0:02:11.023 I add end 0:02:11.859,0:02:14.732 For every track selected, 0:02:15.112,0:02:19.715 we will get the track, 0:02:20.795,0:02:24.140 "get sel track" 0:02:28.180,0:02:32.690 This function to return a track 0:02:33.460,0:02:37.027 according to it's index in selection. 0:02:37.435,0:02:41.197 We already saw the equivalent function[br]for selected items. 0:02:41.198,0:02:42.892 I put j 0:02:42.893,0:02:46.140 The loop look for selected track. 0:02:46.141,0:02:49.210 I will count the number of items they have. 0:02:52.251,0:02:54.530 Count item 0:02:54.531,0:03:01.758 CountTrackMedialtems which allows[br]to count the number of items on the track. 0:03:02.312,0:03:07.734 I will create the variable[br]count_items_on_tracks 0:03:09.720,0:03:13.385 Here, I have to put a track, 0:03:13.386,0:03:16.655 and this track came from[br]my variable named track 0:03:20.656,0:03:25.763 For every item on the track 0:03:35.094,0:03:37.292 do the following thing, 0:03:40.013,0:03:47.419 Get the item according to[br]it's index on the track. 0:03:50.630,0:03:52.494 Here is the function. 0:03:54.134,0:04:01.928 This track return an item according to[br]a track and a index on that track. 0:04:01.929,0:04:05.121 The track still came[br]from the variable track, 0:04:05.122,0:04:09.366 and the item index is defined by the loop[br]which starts here. 0:04:09.367,0:04:11.487 So, I put i. 0:04:13.036,0:04:15.286 I don't need this anymore. 0:04:15.287,0:04:18.947 I can delete this. 0:04:18.947,0:04:23.260 And all this is the same thing... 0:04:38.976,0:04:46.323 Recap: the Action function will,[br]for every selected tracks, 0:04:46.324,0:04:52.843 check all their items, and if an[br]item is inside the time selection 0:04:52.844,0:04:55.641 then a new fade-out[br]length value will be set. 0:04:55.642,0:05:01.954 This value came from the[br]item under mouse. 0:05:01.955,0:05:04.429 I run the script to see. 0:05:06.053,0:05:08.510 I set a fade here. 0:05:09.526,0:05:11.565 And I check. 0:05:12.257,0:05:17.206 We see that it does nothing. 0:05:17.766,0:05:22.680 If I select this track,[br]the fade-out length value get propagated 0:05:22.681,0:05:25.765 on items on selected tracks[br]which are in time selection. 0:05:25.766,0:05:28.372 If I select this 3 tracks... 0:05:29.854,0:05:32.085 We see that it works as expected. 0:05:32.086,0:05:34.449 The loop could be a bit more optimized. 0:05:34.450,0:05:40.227 Indeed, we don't need to check the items[br]that are after the time selection. 0:05:40.228,0:05:43.321 I can do the following thing: 0:05:45.070,0:05:46.643 if 0:05:46.644,0:05:50.107 If item_pos 0:05:50.108,0:05:56.082 is after the end of the time selection, 0:05:58.576,0:06:00.506 then 0:06:00.507,0:06:04.309 break, in other words[br]"Break the loop" 0:06:04.463,0:06:06.448 else 0:06:08.150,0:06:10.597 modify the items as desired. 0:06:10.974,0:06:17.014 Break allows to stop on loop[br]so that it doesn't get executed unecessary. 0:06:17.605,0:06:21.088 I will display i 0:06:22.895,0:06:25.842 I will display i and j in the console. 0:06:25.843,0:06:31.416 I duplicated some items,[br]and I run the script. 0:06:33.207,0:06:37.758 As you can see, this doesn't consider the[br]other items (aka, beyond time selection). 0:06:37.759,0:06:41.187 If I delete break, 0:06:47.754,0:06:52.602 You can see that all items on selected[br]tracks have been unecessary checked. 0:06:52.603,0:06:59.376 Break allows to save a bit of performance when[br]it is not necessary to calculate certain things. 0:06:59.377,0:07:02.754 Our function check the first item, 0:07:02.755,0:07:07.573 then the next item, and if its position is[br]after the end of time selection 0:07:07.574,0:07:10.923 which means that every items after[br]this one will be in the same case, 0:07:10.924,0:07:17.689 So no need to check their position and their[br]end to see if they are in time selection. 0:07:17.690,0:07:22.643 In the next items, we will see how to use[br]a REAPER native function inside a script.