08-04-2018, 08:34 AM | #1 |
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
API: Some OnCommand calls don't play nicely in loops (FIXED)
I'm working on a script to flip through the basic track envelopes for all selected tracks, and ran into a bit of a snag.
The native actions for Track: Select volume envelope only apply to the first selected track, which isn't normally a problem. I grab all of the tracks, loop through, select them one at a time using SetOnlyTrackSelected, and run the action on each of them individually. Easy peasy, I've done it a million times for similar situations. Nope. It still only works on the first track. Example script: Code:
local function Msg(str) reaper.ShowConsoleMsg(tostring(str) .. "\n") end -- Count selected tracks local tracks = {} local count = reaper.CountSelectedTracks(0) if count == 0 then return end -- Get all of their MediaTracks for i = 0, count - 1 do tracks[i] = reaper.GetSelectedTrack(0, i) end -- Select the envelopes individually for _, track in pairs(tracks) do Msg("selecting only track " .. _) reaper.SetOnlyTrackSelected(track) Msg("there are currently " .. reaper.CountSelectedTracks(0) .. " selected tracks") reaper.Main_OnCommand(41866, 0) -- Track: Select volume envelope end -- Restore the track selection for _, track in pairs(tracks) do reaper.SetTrackSelected(track, true) end (I can't use envelope chunks because the envelope may or may not exist yet)
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :( Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate |
08-04-2018, 04:04 PM | #2 |
Human being with feelings
Join Date: Apr 2017
Location: St. Petersburg, FL
Posts: 880
|
I tested this and it seems to be command 41866 and some similar commands. Basically anything showing an envelope.
Action `Toggle track volume envelope visible` (40406) works fine. |
08-05-2018, 05:56 PM | #3 |
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 16,117
|
Ah the bug here (I think) is that SetOnlyTrackSelected() doesn't update the "last touched track" state, which is what those actions use. Fixing.
|
08-05-2018, 06:01 PM | #4 |
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
+1, would report bug again.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :( Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate |
Thread Tools | |
Display Modes | |
|
|