AL: Detecting our OSC Offset in a midi script

Official support for: expertsleepers.co.uk
Post Reply New Topic
RELATED
PRODUCTS

Post

So… I'm getting a bit fancy with my AL midi.lua – I'm making a couple of state machines to manage button state (turning a sequence of 'noteOn/noteOff' events into a sequence of events like this: recButtonDown, recButtonClicked, playButtonDown, playButtonLongPressed, playButtonDownAgain, playButtonClicked), which then feed another more complex state machine which manages the instance's state.

That's fine for a single instance of AL, but less fine when there are multiple instances in place because we do all the work to set up the state machines in every instance, and then forget about them entirely in all but our lead instance (the one with an OSC offset of 1, for instance). This does not make me happy.

I tried doing

Code: Select all

getParameter(getParameterID('OSC Port Offset'))
but despite having instances set to 1 and 2, it returned 0, so I assume that parameter isn't in scope outside the skinning instance. One option, I suppose would be to extend my gui.lua to do something like:

Code: Select all

sendOSC(pathToLeadInstance, '/exec', 'registerInstance', getParameterID('OSC Port Offset'))
Then only the lead instance will receive any OSC messages and can set up the machinery it needs to track which instance is current and start listening for MIDI events and the follower instances can just sit and listen for parameter changes or, if I'm feeling fancy, they can maintain their own looper state machine and be controlled by OSC messages.

Hmm this should work, but it feels kludgy as heck and relies on the MIDI script being up and running before the GUI script (fixable with a timer if it isn't) and on it not dropping any OSC messages, which seems slightly hopeful given that OSC is transmitted over UDP (but sort of doable by randomising the timer to hopefully avoid everything arriving at once).

Which is a long-winded way of asking if it would be possible to expose the OSC Offset (and ideally the base port too because that could allow for distributing far more robust scripts) to the MIDI Scripting environment?

Post

'OSC Port Offset' is a parameter like any other so you should be able to get its value in the normal way.

Can you successfully retrieve other parameter values in the same place in the code?

Post

Oh... that's interesting:

Code: Select all

function reportOSCOffset() 
  print('OSC Port Offset: ' .. getParameter('OSC Port Offset))
end
reportOSCOffset() -- yields 0
requestNoteOn(1, reportOSCOffset) -- the 'real' OSC offset
So, at the point when midi.lua (or someothername.lua) runs, the offset hasn't been set. So I tried:

Code: Select all

requestTimedCallback(0, function(...) print(getParameter('OSC Port Offset')) end)
and got the right value.

So… I can do anything that doesn't depend on accurate values of this (and presumably other params) in the mainline of the script, but any setup that depends on parameter values can be pushed into some 'afterLoading' function and called using 'requestTimedCallback(0,afterLoading)'.

I looked through the manual and there's a warning that you can't call 'getParameter' immediately from gui.lua, but I didn't spot a similar warning about midi scripts.

Post

No, that's a fair point. I think the assumption was that the main body of the script would just call various request...() functions.

Post

I’m nearly at the point of publishing a script on github and I’ll write it up too. I’m rather liking Lua.

Post Reply

Return to “Expert Sleepers”