LUA Scripting and static variables

I’m continuing to work on my MIDI activate script and I’m having a problem.
I guess I don’t understand the context in which the lua code is running.
It is a “dsp” script.

Is "dsp_run() I want to set a boolean to true, and then check it on subsequent calls to dsp_run.

Is my script working like a module? What is the global context?
I’ve looked at some of the other scripts but I’ve not been able to figure it out.

Thanks in advance!

1 Like

A ‘dsp’ script is equivalent to a VST, or LV2 plugin.
It runs in realtime context as part of a track (or bus, aka route).
Each Lua DSP script has its own interpreter, so they cannot interfere with each other.

You can declare that variable outside of the dsp_run function.

An example would be cur_gain in https://github.com/Ardour/ardour/blob/master/share/scripts/amp5.lua The variable It is declared and initialized in line 28 and then later modified as needed in the run function.

1 Like

Thank you.
That helps a lot.

That script also helped me understand how to get from dsp_params() to:
local ctrl = CtrlPorts:array() – get control port array