HI, this is X-Raym, for the 7th part
of our ReaScript Course.
In this episode, will wee learn how to get an item,
according to its position on its parent track.
Imagine that I want to restrict our script
on items on selected tracks
but still in time selection.
I will have to get my items
in a different way.
But before going further, I will clean the
script a bit by create a new functions.
I will call it Action.
I delete my warning messages,
we don't need it anymore.
So Main here will check if our action
can be executed,
And we will create a new function
called Action.
I check if the script still works.
It seems to work fine, I can
continue from here.
I want to consider only
selected tracks.
I will have to make a loop
from selected tracks.
Count... sel... tracks...
I search for the function...
I paste it here.
The project is 0.
For every selected tracks...
count_sel_tracks - 1
do
I add end
For every track selected,
we will get the track,
"get sel track"
This function to return a track
according to it's index in selection.
We already saw the equivalent function
for selected items.
I put j
The loop look for selected track.
I will count the number of items they have.
Count item
CountTrackMedialtems which allows
to count the number of items on the track.
I will create the variable
count_items_on_tracks
Here, I have to put a track,
and this track came from
my variable named track
For every item on the track
do the following thing,
Get the item according to
it's index on the track.
Here is the function.
This track return an item according to
a track and a index on that track.
The track still came
from the variable track,
and the item index is defined by the loop
which starts here.
So, I put i.
I don't need this anymore.
I can delete this.
And all this is the same thing...
Recap: the Action function will,
for every selected tracks,
check all their items, and if an
item is inside the time selection
then a new fade-out
length value will be set.
This value came from the
item under mouse.
I run the script to see.
I set a fade here.
And I check.
We see that it does nothing.
If I select this track,
the fade-out length value get propagated
on items on selected tracks
which are in time selection.
If I select this 3 tracks...
We see that it works as expected.
The loop could be a bit more optimized.
Indeed, we don't need to check the items
that are after the time selection.
I can do the following thing:
if
If item_pos
is after the end of the time selection,
then
break, in other words
"Break the loop"
else
modify the items as desired.
Break allows to stop on loop
so that it doesn't get executed unecessary.
I will display i
I will display i and j in the console.
I duplicated some items,
and I run the script.
As you can see, this doesn't consider the
other items (aka, beyond time selection).
If I delete break,
You can see that all items on selected
tracks have been unecessary checked.
Break allows to save a bit of performance when
it is not necessary to calculate certain things.
Our function check the first item,
then the next item, and if its position is
after the end of time selection
which means that every items after
this one will be in the same case,
So no need to check their position and their
end to see if they are in time selection.
In the next items, we will see how to use
a REAPER native function inside a script.