Old 09-23-2019, 08:50 PM   #1
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default Lua: Generate script from custom action

I've seen this requested a few times, mostly because scripts are so much easier to share with other users.









Lokasenna_Generate script from custom action is available now on your friendly neighbourhood ReaPack.
__________________
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

Last edited by Lokasenna; 09-25-2019 at 06:51 AM.
Lokasenna is offline   Reply With Quote
Old 09-23-2019, 10:19 PM   #2
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,255
Default

No way. Does it work for cycle actions? Trying this now...

Damn. Doesn't work. Would love to turn all my CA into scripts... Thanks anyway.
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 09-24-2019, 05:57 AM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

I did mention that in the OP. :P The file format for cycle actions is really easy, so I'm hoping to have one for them some time soon.
__________________
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 09-24-2019, 07:31 AM   #4
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,255
Default

Derp. I'll learn how to read one of these days, I swear.... But seriously, that might be enough for me to get my head around scripting.

No more opening that clunky CA editor and I'll finally be able to keep all the unnecessary ones out of the Undo History.
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 09-24-2019, 10:21 AM   #5
todoublez
Human being with feelings
 
todoublez's Avatar
 
Join Date: Aug 2019
Location: beijing
Posts: 612
Default

Holy molly...
Much appreciated !
Gonna try this for sure tomorrow.
Thx for y’all talents...
Life saver lol
todoublez is offline   Reply With Quote
Old 09-24-2019, 10:25 AM   #6
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

If I get it right, it creates a script which runs the given actions just like the "regular-actions-combination-concept" in Reaper?
__________________
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 09-24-2019, 10:33 AM   #7
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Pretty much - it just reads reaper-kb.ini to get the list of commands and spits out the Main_OnCommand for them, with options for PreventUIRefresh and Undo_BeginBlock.
__________________
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 09-25-2019, 01:51 AM   #8
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default

Quote:
Originally Posted by Lokasenna View Post
I've seen this requested a few times, mostly because scripts are so much easier to share with other users.

1. Run the script.
2. Paste the ID for a custom action. (No cycle actions... yet)
3. Press 'Go'.
4. Go find your new file in the same folder as the script.

Lokasenna_Generate script from custom action is available now on your friendly neighbourhood ReaPack.
What is this script doing? If I have a custom action 40 actions, will this script combine them in such a way, I have only a single new script which does exactly same? If yes, how does it do this magic? It can not be just a simple copy and paste?
TonE is offline   Reply With Quote
Old 09-25-2019, 01:58 AM   #9
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default

Quote:
Originally Posted by foxAsteria View Post
No way. Does it work for cycle actions? Trying this now...
Anything should be possible what is possible with lua.

Rather than being "only" a recreation of original custom action, it could go one step beyond, by allowing certain extras, like checking for certain cases then doing different things for each. I have no good example now, but what comes to my mind something general like:
- detecting peak/resonant frequencies first
- then doing for each peak/resonant frequency something, like adding a sharp notch

Or frequency sweeping, then doing something with the peaks.
TonE is offline   Reply With Quote
Old 09-25-2019, 06:28 AM   #10
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by TonE View Post
What is this script doing? If I have a custom action 40 actions, will this script combine them in such a way, I have only a single new script which does exactly same? If yes, how does it do this magic? It can not be just a simple copy and paste?
Exactly that.

Quote:
Originally Posted by TonE View Post
Anything should be possible what is possible with lua.

Rather than being "only" a recreation of original custom action, it could go one step beyond, by allowing certain extras, like checking for certain cases then doing different things for each. I have no good example now, but what comes to my mind something general like:
- detecting peak/resonant frequencies first
- then doing for each peak/resonant frequency something, like adding a sharp notch

Or frequency sweeping, then doing something with the peaks.
That's definitely a LOT more complicated, but I've been toying with a similar idea for ages - look at Cubase's Project Logical Editor for an example of what could be done.
__________________
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 09-25-2019, 06:35 AM   #11
todoublez
Human being with feelings
 
todoublez's Avatar
 
Join Date: Aug 2019
Location: beijing
Posts: 612
Default

Generate script from custom action.lua:28: attempt to call a nil value.

is it something I'm missing here ?
I'm using mac btw.
couldnt find this script on my ReaPack browser so I searched it from GitHub.
:/
todoublez is offline   Reply With Quote
Old 09-25-2019, 06:47 AM   #12
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

If it's crashing there you probably don't have my GUI library installed, but it should be giving you a specific error message telling you that.

- Run Extensions -> ReaPack -> Synchronize packages
- Open the ReaPack browser
- Search for "Lokasenna's GUI library v2 for Lua" and select it to install
- Search for "Generate script from custom action" and select it to install (I just checked and it IS showing up on ReaPack)
- In your action list, run "Set Lokasenna_GUI v2 library path".
- You should be able to run "Generate script from custom action" now.
__________________
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 09-25-2019, 06:51 AM   #13
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Added some example images to the OP since my explanation apparently sucked.
__________________
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 09-25-2019, 10:33 PM   #14
todoublez
Human being with feelings
 
todoublez's Avatar
 
Join Date: Aug 2019
Location: beijing
Posts: 612
Default

Quote:
Originally Posted by Lokasenna View Post
- In your action list, run "Set Lokasenna_GUI v2 library path".
- You should be able to run "Generate script from custom action" now.
thanx!
Ah-ha! it works now, thanx for the tip!
Didn't know I gotta run "Set Lokasenna_GUI v2 library path" 1st.
Many thanx! Much appreciated.
todoublez is offline   Reply With Quote
Old 09-26-2019, 04:22 AM   #15
lexaproductions
Human being with feelings
 
Join Date: Jan 2013
Posts: 1,126
Default

Didn’t try it yet, but does it work with CAs that have some CONSOLE actions in them?
lexaproductions is offline   Reply With Quote
Old 09-26-2019, 04:37 AM   #16
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Holy Moly!!!

Absolutely brilliant idea!!
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 09-26-2019, 05:59 AM   #17
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by lexaproductions View Post
Didn’t try it yet, but does it work with CAs that have some CONSOLE actions in them?
I don't see why it wouldn't.
__________________
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 09-26-2019, 07:01 AM   #18
lexaproductions
Human being with feelings
 
Join Date: Jan 2013
Posts: 1,126
Default

Well I didn’t even know you could address the reaconsole from the lua API
lexaproductions is offline   Reply With Quote
Old 09-26-2019, 07:57 AM   #19
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

Thanks for the great script!

Sorry for the semi-offtopic. But, I'm curious. What is the advantage of scripts over customs? Is it just convenience, or are there any technically important details?
cool is offline   Reply With Quote
Old 09-26-2019, 08:04 AM   #20
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default

There are no advantages, except it is a single file, but custom actions are maybe also a single file somewhere, not sure, if not that would be one advantage. Weakness is still this script is still dependent on possible many other scripts. Cool would be if this dependency would be removed, what I thought first. So from my perspective there are no advantages.
TonE is offline   Reply With Quote
Old 09-26-2019, 08:32 AM   #21
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by lexaproductions View Post
Well I didn’t even know you could address the reaconsole from the lua API
You can't - this is just using whatever commands are in your custom action. There are actions for things like "Open ReaConsole with 'v' to do whatever it is that 'v' does" - are we talking about something more than that?

Quote:
Originally Posted by cool View Post
Sorry for the semi-offtopic. But, I'm curious. What is the advantage of scripts over customs? Is it just convenience, or are there any technically important details?
1. Sharing.

Custom actions are all stored in one .ini file, so you would have to open that file, find the right action, copy the entire line and post it somewhere. Then someone else would have to copy it, open their copy of that file, paste it in, and reload Reaper. I'm not even sure if that works because Reaper generates a custom ID for the script, so copy/pasting to a different machine might cause trouble.

In contrast, a script is just a file that you load from the action list. Or upload to ReaPack.

2. Efficiency.

Some custom actions, especially if they're doing more things or being used in a larger project, might take a bit of time to operate - you can sometimes even see it doing X to one track at a time. This is because Reaper updates its UI each time you do something, and UI updates are really "expensive" compared to just shuffling information around under the hood.

Scripts can tell Reaper to pause the UI while they run so all of that appears to happen at once. I've had scripts take 30 seconds because of UI updates and drop down to less than 1 with the UI paused.

Quote:
Originally Posted by TonE View Post
Weakness is still this script is still dependent on possible many other scripts. Cool would be if this dependency would be removed, what I thought first.
That would be pretty cool. I'll add it to my giant list of ideas.
__________________
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 09-26-2019, 09:36 AM   #22
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

Quote:
Originally Posted by Lokasenna View Post

1. Sharing.

Custom actions are all stored in one .ini file, so you would have to open that file, find the right action, copy the entire line and post it somewhere. Then someone else would have to copy it, open their copy of that file, paste it in, and reload Reaper. I'm not even sure if that works because Reaper generates a custom ID for the script, so copy/pasting to a different machine might cause trouble.

In contrast, a script is just a file that you load from the action list. Or upload to ReaPack.

2. Efficiency.

Some custom actions, especially if they're doing more things or being used in a larger project, might take a bit of time to operate - you can sometimes even see it doing X to one track at a time. This is because Reaper updates its UI each time you do something, and UI updates are really "expensive" compared to just shuffling information around under the hood.

Scripts can tell Reaper to pause the UI while they run so all of that appears to happen at once. I've had scripts take 30 seconds because of UI updates and drop down to less than 1 with the UI paused.
Thanks for the detailed answer!
cool is offline   Reply With Quote
Old 09-26-2019, 01:15 PM   #23
Nostrap
Human being with feelings
 
Join Date: Dec 2017
Posts: 179
Default

This script is awesome thanks so much!
Nostrap is offline   Reply With Quote
Old 09-26-2019, 02:40 PM   #24
Tod
Human being with feelings
 
Tod's Avatar
 
Join Date: Jan 2010
Location: Kalispell
Posts: 14,745
Default

Hi Loka, this is great, I've got hundreds, and hundreds, and hundreds of custom actions and there's several of the I'd like to put in a script.

Question: Do the Command IDs stay the same if I send them to somebody or will they be different?
Tod is offline   Reply With Quote
Old 09-26-2019, 03:06 PM   #25
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by Tod View Post
Question: Do the Command IDs stay the same if I send them to somebody or will they be different?
Any actions from Reaper or SWS will be fine. Scripts might cause trouble, although if both you and the other user installed them via ReaPack I think they'll be okay because the IDs are (AFAIK) generated based on the file path and ReaPack is consistent in that regard.
__________________
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-04-2019, 03:29 PM   #26
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,134
Default

Thank you, great idea.

One question, i see that scripts which have long alphanumeric IDs are referenced with nice 5 digit long IDs in the generated scripts which aren't found with a simple search in the reaper-kb.ini. How does this work?
Buy One is online now   Reply With Quote
Old 11-04-2019, 03:41 PM   #27
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

It takes the IDs from reaper-kb.ini and passes them to reaper.NamedCommandLookup. I guess Reaper processes the long names into a shorter ID internally, and that's what it gives back.
__________________
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-05-2019, 07:43 AM   #28
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,134
Default

Quote:
Originally Posted by Lokasenna View Post
It takes the IDs from reaper-kb.ini and passes them to reaper.NamedCommandLookup. I guess Reaper processes the long names into a shorter ID internally, and that's what it gives back.
and i gather that these are not cross machine compatible even when another user has the same individual scripts but hosted at different paths, or are they and scripts IDs don't depend on the location or other contingencies and are the same across the board?

Last edited by Buy One; 11-05-2019 at 07:51 AM.
Buy One is online now   Reply With Quote
Old 11-05-2019, 07:52 AM   #29
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

I... don't actually know.
__________________
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-05-2019, 01:01 PM   #30
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,134
Default

Alright, thank you for the explanation
Buy One is online now   Reply With Quote
Old 11-05-2019, 02:12 PM   #31
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

schwa says here that the command ID numbers for custom actions/scripts are generated at Reaper startup and aren't fixed (unlike for native actions).

edit:
Just to be clear, as mentioned above, the command ID strings are deterministic.
https://forum.cockos.com/showpost.ph...7&postcount=19

Last edited by nofish; 11-05-2019 at 02:36 PM.
nofish is offline   Reply With Quote
Old 11-05-2019, 02:17 PM   #32
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by nofish View Post
schwa says here that the command ID numbers for custom actions/scripts are generated at Reaper startup and aren't fixed (unlike for native actions).
Thanks. I should probably not have the script use those then... :P
__________________
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
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:58 AM.


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