Reload/Reset from file/script?

Anyone know if it’s possible to get a similar result of clicking either one of the script reload/reset buttons from within the script itself, so that it could be assigned to a macro button?

1 Like

I’m not aware of on option to reset the script from the script itself (and thus from macro page button).

But you can write a function that sets the parameters and global variables to their default values. You can even re-define the parameters again if you want. Then use this function as a callback of a “reset” parameter.

Another option could be to wrap everything into functions from the beginning. You can have a function that creates all the parameters and global variables. Then when you want to reset the script just use the same function as a callback.

Hi @jackorez369!
In addition to what @misohoza said, you can reload the script as part of a preset into a layer.
Reinstantiating the preset will force a script reload.
I did some experiments abusing HALion for live coding, like Supercollider. To keep it musical I wrote one script that loads and replaces a midi module with another script after each bar.
I suppose that this is not infinitely scalable, as reloading bigger presets or libraries might cause interruptions.

function refresha()
  print("Reloading now!")
  local instance = this.program.instance --ensure we are working with the current program
  local loadedProgram = loadPreset("path/to/your/midigen01.vstpreset")
  -- get the first MIDI module from the loaded program
  module = loadedProgram:getMidiModule("Lua Script")
  local module = this.program:getLayer("reloading_layer"):getMidiModule("reloaded_module")
  -- we need to delete the midi module or we will get an error that the same module can't be added twice.
  this.program:getLayer("reloading_layer"):insertMidiModule(module, 1)

function onIdle()

Instead of calling the function on idle, you could remove the waitBeat and put it in a parameter callback.

(appologies for the cringe function name, this was never supposed to be viewed by anyone but me :sweat_smile::see_no_evil:)


Thank you very much for the suggestion, however I’m not sure if it’ll work for what I’m trying to accomplish.

Here is one example case:
I made a script which can take slices from one or multiple envelopes and combine them into the user envelope, I then have a macro button which when pushed copies the newly created envelope over into one of the other envelopes. Now…, all of that works, however if I want to repeat the process on the new envelope or a newly loaded one, the script needs to be refreshed in order to bring in the new table data.

I was hoping to be able to define a parameter that can refresh the script and then attach that to a MIDI CC or note so that I can freely experiment without having to reach for the mouse as much. :smiley:

Oh, I should note that I am using the envelope during this process, that is, the envelope is running. So I think anything involved with reloading the program would interrupt the audio.

1 Like

In that case it seems to be better to go with the strategies suggested by @misohoza.
It is a classical software design problem of setting and getting data.