Last updated:

ReaScript Video Tutorial — Part. 6: Time Selection

In this video, we will work on time selection, and make more complex conditions.

Code Snippet:

-- This is an extract of the script
start_time, end_time = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false) -- Get start and end time selection value in seconds

if start_time ~= end_time then -- if there is a time selection
    
    count_items = reaper.CountMediaItems(0) -- count items in the project
    
    for i = 0, count_items - 1
        
        item = reaper.GetMediaItem(0, i)
        item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
        item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")

        item_end = item_pos + item_len -- Calculate the item end position

        if (item_pos > start_time and item_pos < end_time) or (item_end > start_time and item_end < end_time) or (item_pos < start_time and item_end > end_time) then -- check if item is in time selection
                
            reaper.SetMediaItemInfo_Value(item, "D_FADEOUTLEN", item_mouse_fadeout) -- Set new value
                
        end -- end if item is in time selection
        
    end
    
end

Next videos will show you how to get items based on selected tracks.

Help us translate the subtitles of this video in your language using Amara.org !