< Return to Video

Lua Scripting with REAPER 5 - Part. 6: Time Selection

  • 0:00 - 0:05
    Hi everyone, this is X-Raym,
    for the 6th part of our ReaScript tutorial.
  • 0:05 - 0:10
    Imagine that we want our previous
    transformation to be applied
  • 0:10 - 0:14
    on items in time selection
    rather than on selected one
  • 0:14 - 0:19
    I clean that... car we will start
    where we stopped.
  • 0:21 - 0:25
    In order to get items in time selection,
  • 0:25 - 0:31
    I will search in the doc how to get
    this time selection.
  • 0:39 - 0:42
    I take the second function, as it is
    more complete.
  • 0:42 - 0:44
    I paste it here.
  • 0:46 - 0:50
    I clean up a bit before
    renaming the variables.
  • 0:52 - 0:54
    I add = here...
  • 0:55 - 0:59
    Current project is 0
  • 1:00 - 1:04
    Set means that you can define new
    values, or get the actual ones.
  • 1:04 - 1:09
    It expect a bolean value, so I writte false
    (for Get.)
  • 1:09 - 1:11
    I don't want to define a new selection.
  • 1:11 - 1:17
    IsLoop is false too,
    as I want the Time selection.
  • 1:18 - 1:19
    For Loop, it would be true.
  • 1:19 - 1:25
    Here I put 0 cause it needs a number,
    and here too.
  • 1:25 - 1:30
    And here I set false.
  • 1:30 - 1:33
    GetSet_LoopTimeRange2 returns two values
  • 1:33 - 1:40
    I name the first start_time,
    and the second end_time.
  • 1:40 - 1:48
    Reacap: I use GetSet_LoopTimeRange2 to get
    start and end time of the time selection
  • 1:52 - 1:56
    without setting new value.
  • 1:56 - 2:02
    And here I have to set 0 because this function
    expect number as 4th and 5th argument,
  • 2:02 - 2:06
    but it will have no influence on
    the returned values.
  • 2:06 - 2:11
    If there is no time selection,
    start_time and end_time will be equal.
  • 2:11 - 2:14
    So, I will add a conditions.
  • 2:18 - 2:20
    If start_time is different than end_time
  • 2:20 - 2:24
    in other words, if there
    is a time selection,
  • 2:24 - 2:26
    then, run the following part.
  • 2:26 - 2:31
    Now I will have to get the items
    that are in time selection.
  • 2:31 - 2:35
    I will first put a function to count
    the number of items in the project.
  • 2:42 - 2:46
    CountMedialtems
  • 2:48 - 2:55
    I name my variable count_items, I paste
    this. I set 0 for current project.
  • 2:55 - 2:57
    I create a loop.
  • 2:59 - 3:04
    For i = 0, count_items - 1,
    - 1 because we start i at 0
  • 3:04 - 3:12
    do
    Reaper. SetMedialtemlnfo_Value()
  • 3:15 - 3:22
    as third parameters, I set the new value,
    which is item_mouse_fadeout
  • 3:24 - 3:31
    We will create the variable item,
  • 3:33 - 3:41
    and to get an item based on is index
    in the project, it is GetMedialtem
  • 3:47 - 3:55
    project is 0, and inddex integer is i,
    our incrementation variable.
  • 3:56 - 4:04
    I will add else to display a message
    if there is no time selection.
  • 4:07 - 4:11
    As you can see, if
    start_time is different than
  • 4:11 - 4:14
    end_time aka, if there
    is a time selection,
  • 4:14 - 4:18
    all this get executed, else a message
    will be displayed in the console.
  • 4:18 - 4:23
    If delete the time selection and
    put the mouse under no item
  • 4:23 - 4:26
    A message told me that I don't have
    any item under the mouse.
  • 4:26 - 4:33
    If I execute the script over an item, but
    without time selection, a message will warn me.
  • 4:33 - 4:38
    If I make a time selection, and that
    I run the script hover an item.
  • 4:38 - 4:46
    It works. However, at this time, I didn't make any
    conditions to check if the item is in time selection or not,
  • 4:47 - 4:50
    to check if we modify its
    fade-out length value or not.
  • 4:50 - 4:54
    As you can see, the script has an effect
    an all items, in time selection or not.
  • 4:54 - 4:58
    I will have to get the items
    position and its length and
  • 4:58 - 5:02
    add a new conditions, before
    modify their fade-out length.
  • 5:05 - 5:08
    Item_pos =
  • 5:08 - 5:10
    I copy that.
  • 5:12 - 5:19
    The position is "D_POSITION.
    It is not
  • 5:20 - 5:26
    I duplicate and I rename it to item_length
  • 5:26 - 5:31
    length parameter is "D_LENGTH"...
  • 5:31 - 5:35
    This parameters value can be find in
    the doc at GetMedialtemlnfo_Value
  • 5:35 - 5:37
    here are "D_POSITION"
    and "D_LENGTH"
  • 5:37 - 5:42
    There is not Item End parameter, so I will
    create a small calculation...
  • 5:42 - 5:50
    item_end = item_pos + item_len
  • 5:51 - 5:57
    Now I have to check that item start (item
    pos) and item end are in the time selection
  • 5:57 - 6:00
    I will write the following condition:
  • 6:00 - 6:08
    if...then...
    I prepare the room...
  • 6:11 - 6:19
    If... item position is after than
    time selection start...
  • 6:25 - 6:33
    and that item position is before than
    time selection end...
  • 6:35 - 6:42
    I put that bewteen parenthis as all that
    should be compared to another possibilities...
  • 6:42 - 6:44
    OR (of if)
  • 6:47 - 6:55
    item end is after time selection start,
    and before end of time selection
  • 7:13 - 7:18
    Then run the set fade-out length function.
  • 7:18 - 7:23
    It is a complicated condition,
    but we only try to find ways
  • 7:23 - 7:26
    to see if an item is inside
    the time selection or not.
  • 7:30 - 7:33
    Let's analyse the function.
    It tells the following thing:
  • 7:33 - 7:41
    if item position is after time selection
    start and below time selection end,
  • 7:44 - 7:48
    it means that if the item position is between
    here and here, the set functions is executed.
  • 7:48 - 7:53
    Indeed, the item belong to the
    time selection.
  • 7:53 - 7:57
    2nd conditions: or if the item end
    is after time selection start
  • 7:57 - 8:01
    and before time selection end,
    the set function is executed.
  • 8:07 - 8:10
    There is a 3rd case.
  • 8:12 - 8:20
    If item start is before time selection start
    and item end is after time selection end,
  • 8:27 - 8:32
    I will add this other condition...
  • 8:32 - 8:40
    If item pos is before time selection start,
    and if item end is after time selection end
  • 8:52 - 8:59
    I put in place the third case described...
  • 8:59 - 9:06
    If item is at time selection start, end,
    all over, or outside
  • 9:08 - 9:10
    I set fades.
  • 9:10 - 9:13
    And I run this script, from this item.
  • 9:13 - 9:15
    As you can see, all happend
    as expected (item under mouse
  • 9:15 - 9:18
    (fade-out length get propagated
    to item in time selection).
  • 9:18 - 9:23
    In the next video, we will see how to
    get items according to selected tracks,
  • 9:23 - 9:28
    and we will continue to develop our script
    in order to learn new functions. See ya!
Title:
Lua Scripting with REAPER 5 - Part. 6: Time Selection
Description:

Source Article and Exercice:
http://extremraym.com/en/reascript-vi...

Please consider making a donation if you liked it:
http//extremraym.com/en/donation

Cheers !

more » « less
Video Language:
French

English, British subtitles

Revisions