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