What's new

Reaper: action that does different things depending if there are notes selected or not

vicontrolu

Senior Member
So this is what i want:

- No midi notes selected --> adds 5 velocity to all of the notes inside the midi clip
- Midi notes are selected --> adds 5 velocity only to the selected notes

Just want to figure out if there´s a way that doesnt involve scripting. I saw some conditional actions could be made by using cycle actions but apparently the actins after IF need to be state actions, which i think doesnt apply here to notes selected/notes not selected.
 
I'm pretty sure that's correct. The conditionals in the cycle actions rely on the state 'on' or 'off' of other actions. Which can be really useful but quite limiting, particularly as you want to deal with selected MIDI notes. I think it'd be easier just to script it.

I'm no Lua programmer but I've thrown something together for you that I think you're trying to achieve?

Code:
function boostVel(num)
  new_vel = num + 5
  if new_vel > 127 then
     new_vel = 127
  end
end

-- Get hwnd
hwnd = reaper.MIDIEditor_GetActive()

-- Get current take in the MIDI Editor
take = reaper.MIDIEditor_GetTake(hwnd)
retval, notes, ccs, sysex = reaper.MIDI_CountEvts(take)

-- Set number of selected notes to variable
selected_notes_count = 0


-- Loop through all the MIDI notes     
for k = 0, notes-1 do         
  retval, sel, muted, startppqposOut, endppqposOut, chan, pitch, vel = reaper.MIDI_GetNote(take, k)
 
  -- If a note is selected do something
  if sel == true then
     selected_notes_count = selected_notes_count + 1
     boostVel(vel)
     reaper.MIDI_SetNote(take, k, sel, muted, start_ppq, end_ppq, chan, pitch, new_vel, true)
  end 
end
 

-- If no notes were selected
if selected_notes_count == 0 then

  -- Loop through all notes and boost the velocity of all
  for k = 0, notes-1 do
    retval, sel, muted, startppqposOut, endppqposOut, chan, pitch, vel = reaper.MIDI_GetNote(take, k)
    boostVel(vel)
    reaper.MIDI_SetNote(take, k, sel, muted, start_ppq, end_ppq, chan, pitch, new_vel, true)
  end

end

Anyone out there please feel free to post a more elegant solution :geek:
 
great! thanks a lot James. I might start looking at this script to create some others and learn a bit of Lua. Would you recommend Lua over eel or python to create Reaper scripts?
 
I'm don't feel knowledgeable enough to make a recommendation but from what I've seen people use either Lua or EEL.

I started off watching tutorials like this (I had to turn English caps on), and also use the Reascript API as a reference all the time when trying to hack something together.

I find it very frustrating and difficult sometimes but it does open up almost infinite possibilities for customisation. It helps to have a bit of a programming background to start with but anyone can learn it if they persevere.
 
Last edited:
Yes, script with Lua rather than Python or EEL (I believe this is the devs' recommendation, also). With Python there's external setup you need to do and you don't have access to the graphics API, and EEL, while it apparently runs faster for some uses, isn't as broadly flexible/well-documented as Lua is.
 
there's a script already for what you want " Script: X-Raym_Add 10 to selected notes velocity.eel" You just have to change the 10 to a 5

for all - just hit ctrl A to select all and then run the modded X-Raym script, then deselect (existing action). Or put them together into a new action
 
Last edited:
there's a script already for what you want " Script: X-Raym_Add 10 to selected notes velocity.eel" You just have to change the 10 to a 5
for all - just hit ctrl A to select all and then run the modded X-Raym script, then deselect (existing action). Or put them together into a new action

That doesn't satisfy the first requirement vicontrolu had:

So this is what i want:
- No midi notes selected --> adds 5 velocity to all of the notes inside the midi clip

I did check if a script for this existed first and did see the X-Raym script, but it doesn't fit exactly with what was asked. Having to CTRL+A, then run the modded X-Raym script, then run a deselect action is three steps instead of one o_O
 
Yeah but thats something involving ctrl+A. And i want to do this stuff for a lot of actions, not just add 5 velocity. So with scripts like this i am saving tons of ctrl+A, deselect, custom actions, etc.
 
Top Bottom