Lua Macros

Seems a few users would benefit from a Macro layer in Renoise.

Macro, instead of script, in the sense that you would be allowed to send keystroke combinations directly to Renoise, procedurally and programatically.

So instead of this:

  
function toggle_edit_mode()  
 if renoise.song().transport.edit_mode == true then   
 renoise.song().transport.edit_mode = false  
 else  
 renoise.song().transport.edit_mode = true  
 end  
end  
  

A user could do this:

  
renoise.macro().send({ name = 'esc' })  
  

Or even better, this:

  
local key = renoise.macro().query("Pattern Editor:Play:Toggle EditMode")  
renoise.macro().send(key)  
  

Better syntax, welcome.

1 Like

hmmā€¦ So one could have a macro which runs through multiple keyboard shortcuts, which each start a different script?

thisā€™d be really swell for rather complex workflowsā€¦ iā€™d really have to think about what i want renoise to do which renoise isnā€™t capable of doing right now.

btw, your macro suggestion currently sends keycommands. what if it could also start buttons? I have a few in mind which cannot be accessed via LUA (Automatically Detect Transients and Place Slice Markers) (Sample_Recorder line-input and also channel)ā€¦

The only problem with something like having a macro which sends esc is if the user has changed esc to do something else. (for me, esc is follow pattern toggle/on/off, for instance.).

I actually thought (and mentioned it) that a Macro-builder would be part of the Scripting when it was announced.

It shouldnā€™t matter if your keyboard shortcuts are different to somebody elses. Although building a Marco, and finding the command you want to do, may be easier with entering a keyboard shortcut, the Macro should be saved and made in a readable way using the names as they are displays in the Preferences -> Keys section.

Iā€™ve been wanting this feature but didnā€™t know how to articulate how it would work.
I have script ideas that would be made possible/so much easier with this.

Iā€™ve made my own hacky renoise macros using external software so that I could do processes like adding 50 instances of a device and then offsetting a parameter on each one. So many possibilities to control a lot of stuff and do tasks that might be cool but would waste too much time otherwise. If there were an implementation of macros in Renoise that supported recording mouse clicks, hotkeys etc, I would be thrilled. So many doors would open up in terms of sound design.

Yes, macros! +1

Beautiful! How about an observable as well? By this we can actually add a behaviour to existing shortcuts.

(Perhaps the observable should even override the native macro, as you can always trig the native function if you want to include it.)

+1 for
renoise.macro().send({ name = ā€˜Enterā€™ })

Yes, please. This would rock so hard it hurts. :guitar:

Edited for the format Iā€™d personally prefer see it in ;)

I see these letting you access (for eg) Pattern Editor keyboard shortcuts from the Sample Editor as well as making it easy to set up a Macro (list of functions/shortcuts executed in turn.)

Here goes:
renoise.macro().send name = ā€˜Enterā€™

+1
:D

+1, but I donā€™t fully understand the syntax in any of the (pseudo)scripting parts yā€™all posted. Conner, could you give an example 1on1 of what you want to get replaced by what?

Hi Cas,

The syntax comes from the existing spec for key_handler_func() in the current docs.

  
"key" is a table with the fields:  
-- > key = {   
-- > name, -- name of the key, like 'esc' or 'a' - always valid   
-- > modifiers, -- modifier states. 'shift + control' - always valid   
-- > character, -- character representation of the key or nil   
-- > note, -- virtual keyboard piano key value (starting from 0) or nil   
-- > repeated, -- true when the key is soft repeated (hold down)   
-- > }  
  

My pseudo example is simply:

  
renoise.macro().send(key)  
  

Or:

  
local key = renoise.macro().query("Pattern Editor:Play:Toggle EditMode")  
renoise.macro().send(key)  
  

Where key is defined like the spec above.

Whatā€™s missing from all this, of course, is ā€œmiddle clickā€ aka ā€œorange borderā€ aka the selected view you would send keystrokes too.

Iā€™m not sure of the best approach for that particularity.

Improved syntax, welcome.

Hacking in mouse support could ā€œprobablyā€ be done fairly quickly by abusing the key table:

name = L_CLICK, R_CLICK, M_CLICK  
modifiers = empty  
character = nil  
note = nil  
repeated = false / true for single / double click respectively.  

Itā€™s not elegent, itā€™s not The Right Thing, but it may be feasible as Iā€™ve seen other APIs report mouse events in this way.

Iā€™m not 100% convinced itā€™s a good idea though.

Not at all! We are talking about sending direct function shortcuts, not press-of-a-key shortcuts. Sure it does mean you could end up pasting a load of data into the Pattern Editor while you canā€™t currently see it (for one of a infinite number of examples) but it also means it will work on anybodyā€™s install of Renoise, when whereas if you used key macros it wouldnā€™t work if your keyboard shortcuts were different from somebody elseā€™s.

And as macros could be nested in functions you could well have if focus is x pane check then do y or z macro depending. I see no issue with this!

The problem is that you can assign the same shortcut combo more than once, depending on the selected view. An out of the box example:

Edit ā†’ Preferences ā†’ Keys:

  • Sample Editor:Edit:Paste = CTRL + V
  • Automation:Process:Paste = CTRL + V
  • Track DSPs Chain:Edit:Paste Device = CTRL + V
  • ā€¦

So when I do

  
local key = { name = 'v', modifiers = 'control' }  
renoise.macro().send(key)  
  

Which one of am I doing? If I do:

  
local key = renoise.macro().query("Track DSPs Chain:Edit:Paste Device")  
  

Then key is { name = ā€˜vā€™, modifiers = ā€˜controlā€™ }, nothing more.

Thereā€™s no magic ā€œI see what you did there, you mean Pattern Editor?ā€ built into the query system. Itā€™s just going to query the assignment table, and return the key, not the view.

Am I wrong? I havenā€™t looked at this in a while. Honest question.

But If Iā€™m right we either have to add the view to the key table which is not there now, which could break backward compatibly, and so on. Or do something new which I have no good idea for.

Becasue the Macro does not ever refer to which key is being pressed!!! Then your Macros couldnā€™t be shared to people who use different keyobard shortcuts to you!! What I suggested is that they are always defined with the Track DSPs Chain:Edit:Paste Device type syntax, not by letter name/modifier combinations! Therefore there is never any mistaking what you are wanting to do!! And you can very easily set up shortcuts to do operations in areas which donā€™t currently have focus, which currently require a lot more lines of code to reprogram purely in the API!

So you above example:

You have created a macro with the name v with a junk bit of code called modifiers. So it will sit in the root levels of any macros list. But no sensible definitionā€¦

My syntax is likely to be out here as not on a computer with a Renoise installā€¦ Anyway this is a lot closer to what I would hope to see:

  
function pastefill()  
 renoise.macro():run(Pattern Editor:Edit:Copy Selection)  
 renoise.macro():run(Pattern Editor:Navigation:Goto Top of Pattern)  
 renoise.macro():run(Pattern Editor:Edit:Paste Continuously)  
end  
  
renoise.macro():create{  
 name = "Kaza's Test:Paste Fill"  
 invoke = function() pastefill end  
}  

Possibly all commands within the function could be part of the same macro():run call and separated by semi-colonsā€¦