Browse Source

Item under cursor - next take - osc: initial commit

master
Ludwig Frühschütz 4 years ago
parent
commit
e996d670e7
1 changed files with 93 additions and 0 deletions
  1. +93
    -0
      ItemUnderCursor_NextTake_OSC/ItemUnderCursor_NextTake_OSC.lua

+ 93
- 0
ItemUnderCursor_NextTake_OSC/ItemUnderCursor_NextTake_OSC.lua View File

@ -0,0 +1,93 @@
-- Reaper Script that switches the item under the edit cursor, on the specified track to
-- the next (or previous) take. To specify the track, this script MUST be called by a
-- OSC message defined as a shortcut for this script in the action list.
-- The OSC message must carry a float value as data which is the track (zero based)
-- divided by 100 e.g. 0.42 stands for track number 43 (or with osc_first_track_nr = 1
-- it may stand for track number 42)
-- Features:
-- - stores selected tracks and items before execution and restores them afterwards
-- - saves only one consolidated undo point
-- Requires
-- - Reaper 5 or 6
-- - SWS extensions must be installed (http://standingwaterstudios.com/)
-- - can only be used by a special OSC message, not by keyboard shortcut or "action" OSC message
-- Author: Ludwig Frühschütz
-- Source: https://www.eleton-audio.de
-- Git: https://files.eleton-audio.de/gitea/Ludwig/Reaper-Scripts.git
-- License: GPL v3.0
-- Settings that may be edited:
local osc_first_track_nr = 0 -- specify if OSC track numbers are zero based (= 0) or one based (= 1)
local select_next_take = true -- select if the script switches to next take (= true) of previous take (= false)
-- some variables...
local init_sel_tracks = {}
local init_sel_items = {}
local tracknr = 0
local osc_tracknr = -1
local osc_resolution = 1
-- Send a message to the console
function msg(m)
reaper.ShowConsoleMsg(tostring(m) .. "\n")
end
-- Round number
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
-- START HERE
-- check if SWS extensions are present, otherwise quit
if reaper.NamedCommandLookup('_SWS_ABOUT') <= 0 then
msg('Item under cursor - next take script:')
msg('SWS extensions missing, please install them first!')
return
end
-- Get track number from osc message that triggered this script. If not specified, quit.
_, _, _, _, _, osc_resolution, osc_tracknr = reaper.get_action_context()
if osc_tracknr < 0 then
msg('Item under cursor - next take script:')
msg('No valid track number specified or script not triggered by OSC message!')
return
end
tracknr = round((osc_tracknr / osc_resolution) * 100, 0) - osc_first_track_nr
-- Quit if there is no track with the specified number
if tracknr >= reaper.CountTracks(0) then -- note: tracknr is zero-based!
return
end
-- store selected tracks and items before work and begin undo block...
reaper.Undo_BeginBlock()
for i = 0, reaper.CountSelectedTracks(0)-1 do
init_sel_tracks[i+1] = reaper.GetSelectedTrack(0, i)
end
reaper.Main_OnCommand(40297, 0) -- Unselect all tracks
for i = 0, reaper.CountSelectedMediaItems(0)-1 do
init_sel_items[i+1] = reaper.GetSelectedMediaItem(0, i)
end
reaper.Main_OnCommand(40289, 0) -- Unselect all items
-- Select item on specified track under edit cursor:
local track = reaper.GetTrack(0, tracknr) -- Get track object from track number (zero based)
reaper.SetTrackSelected(track, true) -- Select track
reaper.Main_OnCommand( reaper.NamedCommandLookup('_XENAKIOS_SELITEMSUNDEDCURSELTX'), 0 ) -- select item under edit cursor on selected track
-- Switch item to next take or previous take (depending on settings in this file)
if select_next_take then
reaper.Main_OnCommand(40125, 0) -- Switch item to next take
else
reaper.Main_OnCommand(40126, 0) -- Switch item to next take
end
-- restore selected tracks and items after work and end undo block
reaper.Main_OnCommand(40297, 0) -- Unselect all tracks
for _, track in ipairs(init_sel_tracks) do
reaper.SetTrackSelected(track, true)
end
reaper.Main_OnCommand(40289, 0) -- Unselect all items
for _, item in ipairs(init_sel_items) do
reaper.SetMediaItemSelected(item, true)
end
reaper.Undo_EndBlock('Changed take for item under cursor (OSC)', 4) -- 4 is a flag for actions concerning items

Loading…
Cancel
Save