Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 08-04-2018, 08:34 AM   #1
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default 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
Bug, or PEBKAC? Cheers.

(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
Lokasenna is offline   Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.