Hey all,
I'm working on a toggle select CC X script. Selecting works great, however unselecting is still a bit buggy. I can't seem to find the issue here.
The code looks okay to me. Maybe someone can help?
Here's what's happening:
- I select all CC1 events
- then I select all CC2 events
- again executing the toggle CC1 script, to deselect CC1
= only one CC event gets deselected and that's the one missing in CC2
I somehow seem to be missing some condition.
Code:
for i = 0, reaper.CountSelectedMediaItems(0)-1 do -- loop through all selected items
item = reaper.GetSelectedMediaItem(0, i)
for t = 0, reaper.CountTakes(item)-1 do -- Loop through all takes within each selected item
take = reaper.GetTake(item, t)
if reaper.TakeIsMIDI(take) then -- make sure, that take is MIDI
_, _, ccCount, _ = reaper.MIDI_CountEvts(take) -- count CCs and save amount to "ccCount"
for c = 0, ccCount-1 do -- loop thru all CCs
_, selected, _, _, _, _, cc, _ = reaper.MIDI_GetCC(take, c) -- get values from CCs
if cc == 1 and selected == false then -- if CC is CC1 and CC1 is not selected
reaper.MIDI_SetCC(take, c, true, nil, nil, nil, nil, nil, nil, nil) -- select CC1
reaper.ShowConsoleMsg(c.." ".."CC"..cc.." "..tostring(selected).."\n")
elseif cc == 1 and selected == true then -- if CC is CC1 and CC1 is selected
reaper.MIDI_SetCC(take, c, false, nil, nil, nil, nil, nil, nil, nil) -- unselect CC1
reaper.ShowConsoleMsg(c.." ".."CC"..cc.." "..tostring(selected).."\n")
end
end
end
end
end