Lua Scripting with REAPER 5 - Part. 7: Loop in Items on Selected Tracks
-
0:00 - 0:05HI, this is X-Raym, for the 7th part
of our ReaScript Course. -
0:05 - 0:10In this episode, will wee learn how to get an item,
according to its position on its parent track. -
0:10 - 0:17Imagine that I want to restrict our script
on items on selected tracks -
0:17 - 0:19but still in time selection.
-
0:19 - 0:21I will have to get my items
in a different way. -
0:21 - 0:29But before going further, I will clean the
script a bit by create a new functions. -
0:33 - 0:36I will call it Action.
-
0:37 - 0:43I delete my warning messages,
we don't need it anymore. -
0:47 - 0:51So Main here will check if our action
can be executed, -
0:51 - 0:56And we will create a new function
called Action. -
1:13 - 1:17I check if the script still works.
-
1:20 - 1:24It seems to work fine, I can
continue from here. -
1:24 - 1:27I want to consider only
selected tracks. -
1:27 - 1:32I will have to make a loop
from selected tracks. -
1:34 - 1:37Count... sel... tracks...
-
1:37 - 1:39I search for the function...
-
1:49 - 1:54I paste it here.
The project is 0. -
1:55 - 2:00For every selected tracks...
-
2:04 - 2:07count_sel_tracks - 1
-
2:07 - 2:09do
-
2:09 - 2:11I add end
-
2:12 - 2:15For every track selected,
-
2:15 - 2:20we will get the track,
-
2:21 - 2:24"get sel track"
-
2:28 - 2:33This function to return a track
-
2:33 - 2:37according to it's index in selection.
-
2:37 - 2:41We already saw the equivalent function
for selected items. -
2:41 - 2:43I put j
-
2:43 - 2:46The loop look for selected track.
-
2:46 - 2:49I will count the number of items they have.
-
2:52 - 2:55Count item
-
2:55 - 3:02CountTrackMedialtems which allows
to count the number of items on the track. -
3:02 - 3:08I will create the variable
count_items_on_tracks -
3:10 - 3:13Here, I have to put a track,
-
3:13 - 3:17and this track came from
my variable named track -
3:21 - 3:26For every item on the track
-
3:35 - 3:37do the following thing,
-
3:40 - 3:47Get the item according to
it's index on the track. -
3:51 - 3:52Here is the function.
-
3:54 - 4:02This track return an item according to
a track and a index on that track. -
4:02 - 4:05The track still came
from the variable track, -
4:05 - 4:09and the item index is defined by the loop
which starts here. -
4:09 - 4:11So, I put i.
-
4:13 - 4:15I don't need this anymore.
-
4:15 - 4:19I can delete this.
-
4:19 - 4:23And all this is the same thing...
-
4:39 - 4:46Recap: the Action function will,
for every selected tracks, -
4:46 - 4:53check all their items, and if an
item is inside the time selection -
4:53 - 4:56then a new fade-out
length value will be set. -
4:56 - 5:02This value came from the
item under mouse. -
5:02 - 5:04I run the script to see.
-
5:06 - 5:09I set a fade here.
-
5:10 - 5:12And I check.
-
5:12 - 5:17We see that it does nothing.
-
5:18 - 5:23If I select this track,
the fade-out length value get propagated -
5:23 - 5:26on items on selected tracks
which are in time selection. -
5:26 - 5:28If I select this 3 tracks...
-
5:30 - 5:32We see that it works as expected.
-
5:32 - 5:34The loop could be a bit more optimized.
-
5:34 - 5:40Indeed, we don't need to check the items
that are after the time selection. -
5:40 - 5:43I can do the following thing:
-
5:45 - 5:47if
-
5:47 - 5:50If item_pos
-
5:50 - 5:56is after the end of the time selection,
-
5:59 - 6:01then
-
6:01 - 6:04break, in other words
"Break the loop" -
6:04 - 6:06else
-
6:08 - 6:11modify the items as desired.
-
6:11 - 6:17Break allows to stop on loop
so that it doesn't get executed unecessary. -
6:18 - 6:21I will display i
-
6:23 - 6:26I will display i and j in the console.
-
6:26 - 6:31I duplicated some items,
and I run the script. -
6:33 - 6:38As you can see, this doesn't consider the
other items (aka, beyond time selection). -
6:38 - 6:41If I delete break,
-
6:48 - 6:53You can see that all items on selected
tracks have been unecessary checked. -
6:53 - 6:59Break allows to save a bit of performance when
it is not necessary to calculate certain things. -
6:59 - 7:03Our function check the first item,
-
7:03 - 7:08then the next item, and if its position is
after the end of time selection -
7:08 - 7:11which means that every items after
this one will be in the same case, -
7:11 - 7:18So no need to check their position and their
end to see if they are in time selection. -
7:18 - 7:23In the next items, we will see how to use
a REAPER native function inside a script.
- Title:
- Lua Scripting with REAPER 5 - Part. 7: Loop in Items on Selected Tracks
- Description:
-
Source Article and Exercice:
http://extremraym.com/en/reascript-video-items-on-tracksPlease consider making a donation if you liked it:
http//extremraym.com/en/donationCheers !
- Video Language:
- French
- Duration:
- 07:23