Old 11-30-2020, 01:09 PM   #1
Malfunction
Human being with feelings
 
Malfunction's Avatar
 
Join Date: Sep 2020
Posts: 149
Default Delete cc values under note by script

It seems like I must run the same script multiple times to clear the time selection of cc values. This seem to happen with multiple scripts. Is this a known problem?
Malfunction is offline   Reply With Quote
Old 12-01-2020, 06:45 PM   #2
Malfunction
Human being with feelings
 
Malfunction's Avatar
 
Join Date: Sep 2020
Posts: 149
Default

Nevermind , this script takes care of it


Code:
cclane=3

hwnd = reaper.MIDIEditor_GetActive()

--command_id=41735 -- select all CC under selected notes
--reaper.MIDIEditor_OnCommand(hwnd, command_id)

function del(cclane,tt)  
    take = reaper.MIDIEditor_GetTake(hwnd)
    local i = reaper.MIDI_EnumSelCC(take, -1)
    local t=0
      while i~=-1 do
          _, _, _, ppqpos, chanmsg, chan, msg2, msg3 = reaper.MIDI_GetCC( take, i )
          if chanmsg==0xB0 then 
            if msg2==cclane then
               t=t+1
               local ok=false 
               while ok~=true do
                 ok=reaper.MIDI_DeleteCC(take,i)
               end
             end 
           end 
           i = reaper.MIDI_EnumSelCC(take, i)   
       end
    if t~=0 then return del(cclane,tt+1) 
    else return tt end
end

del(cclane,1)
Malfunction is offline   Reply With Quote
Old 12-01-2020, 06:53 PM   #3
Malfunction
Human being with feelings
 
Malfunction's Avatar
 
Join Date: Sep 2020
Posts: 149
Default

its best to enable the option "CC selection follows note selection" for selecting cc values.
Malfunction is offline   Reply With Quote
Old 12-01-2020, 07:04 PM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,628
Default

One wild guess: have you tried deleting cc backwards? With the last one deleted first and the first one deleted last?
Cause it looks like the common problem people have, who try to delete MediaItems and after script-run, there are still items left, who should've been deleted.
Usually the solution (when wanting to delete item 5 through 10) is to delete the items in the order: 10, 9, 8, 7, 6, 5, NOT 5, 6, 7, 8, 9, 10.

Have no clue about cc so maybe, what I was trying to suggest is way off of the actual problem
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 12-02-2020, 05:54 AM   #5
Malfunction
Human being with feelings
 
Malfunction's Avatar
 
Join Date: Sep 2020
Posts: 149
Default

This is as far as i got.
I collected the id's of the cc values beloning to lane 3, and did a reverse for loop.
It ends up deleting values outside the selection (scary)
It doesnt look like I can just perform an action on a cc value by index.



Code:
--delete backwards

function msg(s)
    return reaper.ShowConsoleMsg(s .."\n") 
end 


hwnd=reaper.MIDIEditor_GetActive() 
take=reaper.MIDIEditor_GetTake(hwnd) 

cclane=3

--command_id=41735 -- select all CC under selected notes
--reaper.MIDIEditor_OnCommand(hwnd, command_id)

function del(cclane,tt)  
  take = reaper.MIDIEditor_GetTake(hwnd)
  local i = reaper.MIDI_EnumSelCC(take, -1)
  local t=0
  local b={}
  while i~=-1 do
      _, _, _, ppqpos, chanmsg, chan, msg2, msg3 = reaper.MIDI_GetCC( take, i )
      if chanmsg==0xB0 then 
         if msg2==cclane then
             t=t+1
             b[t]=i
         end 
        
         msg("idx = "..i.. "    cclane =  "..msg2)
     end 
           
     i = reaper.MIDI_EnumSelCC(take, i)
 
   end
       
   msg("List all indexes with cclane "..cclane)
   
   local lastone=0
   for i, v in ipairs(b) do
     msg("i = "..i.."   v = "..v)
    
     lastone=i
   end
   msg("lastone = "..lastone)
   msg("In reversed order")
   reaper.MIDI_Sort( take)
   
   for i=#b ,1,-1 do 
      msg("i = "..i.."   v = "..b[i]) 
   end
   
 
   msg("Delete Backwards")
   for i=#b ,1,-1 do 
      local ok=false
      while ok~=true do
         ok=reaper.MIDI_DeleteCC(take,i)
      end
   end  
   --ok=reaper.MIDI_DeleteCC(take,lastone)
  
end
 
del(3,1)
Malfunction is offline   Reply With Quote
Reply

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 02:00 AM.


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