Old 10-16-2021, 03:04 AM   #1
SymboliC
Human being with feelings
 
SymboliC's Avatar
 
Join Date: Dec 2013
Posts: 289
Default MIDI item Cleanup in Arrange View

Hi,

I have script like the one below that I've found some time ago in these forums. It works but it iterates all MIDI items in arrange view and cleans them up all at once. How can I make it cleanup only the selected MIDI item? or is there an alternative script that I can use on per-selected-item basis?

The script is lua and as follows,

Code:
-- Remove all CCs from all tracks and all takes

num_items = reaper.CountMediaItems(0)

for i = 0, num_items-1 do
    cur_item = reaper.GetMediaItem(0, i)
    num_takes = reaper.CountTakes(cur_item)
  
    for t = 0, num_takes-1 do
        cur_take = reaper.GetTake(cur_item, t)
        
        if(reaper.TakeIsMIDI(cur_take)) then
          
            -- What is the fastest way of deleting all CCs? 
            -- Here are a few options:
            
            --[[
            _, _, ccevtcnt, _ = reaper.MIDI_CountEvts(cur_take)
            for i = ccevtcnt-1, 0, -1 do
                reaper.MIDI_DeleteCC(cur_take, i)
            end
            ]]
            
            --[[
            repeat
                _, _, ccevtcnt, _ = reaper.MIDI_CountEvts(cur_take)
                if ccevtcnt > 0 then reaper.MIDI_DeleteCC(cur_take, ccevtcnt-1) end
            until ccevtcnt == 0
            ]]
            
            -- This option seems to  be the fastest:
            repeat
                deleteOK = reaper.MIDI_DeleteCC(cur_take, 0)
            until deleteOK == false 
        
        end -- if(reaper.TakeIsMIDI(cur_take))  
     
    end -- for t = 0, num_takes-1 do
  
end -- for i = 0, num_items-1 do

reaper.UpdateArrange()
reaper.Undo_OnStateChange("Remove all CCs from all tracks")
* By cleanup, I mean remove all CC/bank etc data other than plain MIDI notes.

Thank you all!
__________________
Just music. Nothing more, nothing less.
SymboliC is offline   Reply With Quote
Old 10-16-2021, 05:29 AM   #2
xpander
Human being with feelings
 
xpander's Avatar
 
Join Date: Jun 2007
Location: Terra incognita
Posts: 7,670
Default

You could edit that juliansaders script by changing

num_items = reaper.CountMediaItems(0) to
num_items = reaper.CountSelectedMediaItems(0)

and
cur_item = reaper.GetMediaItem(0, i) to
cur_item = reaper.GetSelectedMediaItem(0, i)
xpander is offline   Reply With Quote
Old 10-16-2021, 08:46 AM   #3
SymboliC
Human being with feelings
 
SymboliC's Avatar
 
Join Date: Dec 2013
Posts: 289
Default

Quote:
Originally Posted by xpander View Post
You could edit that juliansaders script by changing

num_items = reaper.CountMediaItems(0) to
num_items = reaper.CountSelectedMediaItems(0)

and
cur_item = reaper.GetMediaItem(0, i) to
cur_item = reaper.GetSelectedMediaItem(0, i)
Thank you so much! It worked like a charm!

I've googled and found this page dedicated to ReaScript APIs which also covers the methods that you advised me to change.

I previously had some experience with C#. Do you think I can adapt myself to write my own Lua scripts by following that source?

Thank you again!
__________________
Just music. Nothing more, nothing less.
SymboliC is offline   Reply With Quote
Old 10-16-2021, 09:46 AM   #4
xpander
Human being with feelings
 
xpander's Avatar
 
Join Date: Jun 2007
Location: Terra incognita
Posts: 7,670
Default

Glad to hear that it worked. I'm not able to tell how easy it is to go from C# to Lua, but any coding experience could help with the basic concepts.

My only official code studies were decades ago for Basic. Later on I have had to deal with some others, but here with EEL and Lua scripts I have relied on that API and examples of far more experienced people we are lucky to have on our boards.
xpander 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 12:28 PM.


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