Old 11-14-2019, 04:11 PM   #1
Human being with feelings
Join Date: Mar 2015
Posts: 45
Default Looking for [Action: Invert CC Events]

There should be an Action to invert CC event data for the MIDI Editor.

Found a useful JSFX to invert a CC lane here:
but this is a JSFX Plugin and not an action for working within the MIDI Editor. There's already a reverse action that horizontally mirrors the selection of CC events, and it'd be useful to have also a "vertical mirror" of selection in the sense of "inversion" of selected event data, i.e., 0 = 127, 20 = [127-20].

Is there an action already that I'm overlooking that someone knows of? Slightly surprised at not finding anything in the ReaPack.


P.S. Interestingly there is an invert action for track envelopes, but again, can't find anything equivalent for CC data. Hrm.

Last edited by worldwideweary; 11-14-2019 at 09:57 PM.
worldwideweary is offline   Reply With Quote
Old 11-15-2019, 07:43 PM   #2
Human being with feelings
Join Date: Mar 2015
Posts: 45

I put together a little lua action-script for this. Normally it seems you'd make a regular combination action, but the problem is that to do this requires some actions from the [Main] section and also [MIDI Editor], and apparently this requires some ReaScript action.

If anyone wants to test this, it's merely doing a bunch of basic logical steps using a few actions from basic Reaper + a few SWS actions. The logic is as follows (and yes, it is a huge workaround, but it works):

0) User makes a selection of CC events in MIDI Editor, and then runs the script:

-- 1) Create and select first track
reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_CREATETRK1"), 0)

-- 2) Track: Select pan envelope [of first track]
reaper.Main_OnCommand(41868, 0)

-- MIDI Editor:
-- 3) SWS/BR: Convert selected CC events in active item 
-- to linear envelope points in selected envelope
-- (clear existing envelope points)
hwnd = reaper.MIDIEditor_GetActive()
reaper.MIDIEditor_OnCommand(hwnd, reaper.NamedCommandLookup("_BR_ME_CC_TO_ENV_LINEAR_CLEAR"))

-- MAIN:
-- 4) Envelope: Select all points (of envelope)
reaper.Main_OnCommand(40332, 0)
reaper.Main_OnCommand(40332, 0) 
-- had to duplicate this (hrm) to get the points selected

-- 5) Envelope: Invert selected points
reaper.Main_OnCommand(40334, 0)

-- 6) SWS/BR: Convert selected envelope's curve in time
--    selection to  CC events in last clicked CC lane
--    in last active MIDI editor
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_ENV_TO_CC_CLEAR"), 0)

-- 7) Track: Select Track 01 ONLY
reaper.Main_OnCommand( reaper.NamedCommandLookup("_SWS_SEL1"), 0)
-- 8) Track: Remove Tracks
reaper.Main_OnCommand(40005, 0)


reaper.Undo_EndBlock("Script: Invert CC Data (Workaround from envelopes)", -1 )

This could be done by adding an envelope to the currently selected track hosting the midi item, thereby negating the need for a temporary track here, but this envelope might already exist on the track and so creating a new, temporary track seemed like a safe bet. Again, this is a little over the top as a workaround, and if I knew how lua + Reaper's exposure worked this could be easily achieved otherwise, but in the meantime it definitely does work, yet it takes about a second to run or so (the delay is from the conversion of cc to envelope and back again). Still, better than nothing if you would find this useful. If there are any flaws or side-effects, if anyone even tries this at all and I'm not the only one, leave a comment here. And lemme know when an actual standard action does this, haha.

Attached Files
File Type: lua CCSelectionInvert.lua (1.4 KB, 3 views)

Last edited by worldwideweary; 11-16-2019 at 05:02 PM.
worldwideweary 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 02:09 PM.

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