Old 11-16-2019, 04:54 PM   #1
worldwideweary
Human being with feelings
 
Join Date: Mar 2015
Posts: 51
Default Scripts of the built-in actions

Hello,
Getting back into learning a little more thoroughly DAW functionality, specifically in Reaper, and wondering if Reaper's built-in actions that are found in the Actions search are available as lua code? If so, some of the actions would be worth studying to learn a bit of how it works (without reading manuals, haha). Thanks for any response.

P.S. I wanted to take the code for instance of [Edit: Reverse selected events] in the Midi Editor so I could potentially implement a "Inverse CC events" rather than do a workaround of converting into track envelopes, inverting, then reconverting back again as found here: https://forum.cockos.com/showthread.php?t=227124
worldwideweary is offline   Reply With Quote
Old 11-16-2019, 05:42 PM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

The native actions are written in C++, so they don't exist in Lua form anywhere.

Writing them yourself in script form is a great way to practice, if nothing else. Just FYI a script will almost always be significantly slower, but unless you're working with a lot of items/events/tracks/etc. we're still talking "runs pretty much instantly".

As for what you want to do, that workaround is a really awkward way of doing things because it uses only native actions - it's effectively a custom action rather than a script. A script can just get all of the events, filter out which ones are CCs, and directly set their values.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 11-16-2019, 07:16 PM   #3
worldwideweary
Human being with feelings
 
Join Date: Mar 2015
Posts: 51
Default

Quote:
Originally Posted by Lokasenna View Post
that workaround is a really awkward way of doing things because it uses only native actions
Yeah, I wrote as much in the paragraphs of that post, but had to use a script because of the dual use of [main + midi editor] actions. I suppose I'll try to find a similar non-native script that does something basic to figure it out, and "quite frankly," I'm surprised that there isn't a lua script already out there to invert cc values. Thanks for replying about the code being c/c++.
worldwideweary is offline   Reply With Quote
Old 11-16-2019, 09:37 PM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

I've just uploaded Lokasenna_Invert selected CC event values to ReaPack; should be available in a few minutes.

As I suggested, it's a lot more straightforward to do when we don't have to fiddle with native actions. Here's the code with some extra comments:
Code:
local editor = reaper.MIDIEditor_GetActive()
if not editor then return end

local take = reaper.MIDIEditor_GetTake(editor)
if not take then return end

reaper.Undo_BeginBlock()

-- This loop structure keeps asking Reaper for the next selected
-- CC event until Reaper says there aren't any more.
local ccIdx = -1
while true do
  ccIdx = reaper.MIDI_EnumSelCC(take, ccIdx)
  if ccIdx == -1 then break end

  -- msg3 is the CC value
  local _, _, _, _, _, _, _, msg3 = reaper.MIDI_GetCC(take, ccIdx)

  reaper.MIDI_SetCC(take, ccIdx, nil, nil, nil, nil, nil, nil, 127 - msg3, true)
end

-- For performance reasons, it's better to tell Reaper not to do
-- any sorting while we loop through the events and then sort them
-- all at once afterward
reaper.MIDI_Sort(take)

-- Hack to make Reaper recognize that the item was altered so we
-- get a correct Undo point
local item = reaper.GetMediaItemTake_Item(take)
reaper.SetMediaItemSelected(item, false)
reaper.SetMediaItemSelected(item, true)

reaper.Undo_EndBlock("Invert selected CC event values", 4)
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 11-16-2019, 09:44 PM   #5
worldwideweary
Human being with feelings
 
Join Date: Mar 2015
Posts: 51
Default

Quote:
Originally Posted by Lokasenna View Post
Here's the code with some extra comments.
Hey thanks for taking the time. Hopefully others will also have a use case for inverting CC events (i.e. contrary motions of two cc lanes) and use this script.

As was imagined, the algorithm is super simple, just 127-the value of a CC in a selection, cycled through the whole selection of current lane. Makes the previous custom action obsolete in a 'good way'.
worldwideweary 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 07:17 AM.


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