Programmatically Assign Macro Connections?
-
Is this possible yet? I remember posting about it a few years ago and couldn't find a solution.
There's
MacroHandler.setMacroDataFromObjectbut I'm not sure how the JSON is supposed to look. -
@iamlamprey This will show you how the object should look
https://docs.hise.audio/scripting/scripting-api/macrohandler/index.html#getmacrodataobject
-
@d-healey Ah it's in the
ScriptingObjects::ScriptedMacroHandler::setFromCallbackArgfunction and called from the parent function, my eyes hurt -
Okay for anyone else wanting to do programmatic macro assignment for GUI elements:
// First you need to setup some stuff: const mh = Engine.createMacroHandler(); Engine.setFrontendMacros(["a", "b", "c", "d", "e", "f", "g", "h"]); reg obj; // this will be what we pass to the function as an object // To see the full JSON object: inline function getObject(component, value) { // This button fetches our existing Macro connections object obj = mh.getMacroDataObject(); Console.print(obj); // Insert a breakpoint here and inspect the ScriptWatchTable "obj" element. }; Content.getComponent("Button1").setControlCallback(getObject);The object looks like this:
{ "MacroIndex": 0, // zero-based macro index "Processor": "Interface", // the script processor we're working in (usually "Interface") "Attribute": "Knob1", // the name of the UI control "FullStart": 0.0, // the UI control's "min" value "FullEnd": 127.0, // the UI control's "max" value "Inverted": false, // invert the connection "Interval": 0.0, // no idea "Skew": 1.0, // skew "Start": 0.0, // the macro control's "min" "End": 127.0 // the macro control's "max" }Finally to assign your own custom macro stuff:
inline function assignMacro(componentName, index, fMin, fMax, min, max) { local obj = { "MacroIndex" : index, "Processor" : "Interface", "Attribute" : componentName, "FullStart" : fMin, "FullEnd" : fMax, "Start" : min, "End" : max } mh.setMacroDataFromObject(obj); }NOTE: This will likely crash and brick your project if you do it INSIDE HISE. Compile it / export it to Rhapsody before trying to use the actual assignment function.
If you do brick your project, open the Preset.xml file and delete all the data in the
MacrosectionEg:
<controlled_parameter id="Interface" parameter="155" parameter_name="knbFilterCutoff" min="20.0" max="20000.0" low="20.0" high="20000.0" skew="0.266319563348789" step="0.01" inverted="0" readonly="0" converter="37.nT6K8CBGgC..VEFa0U1Pu4lckIGckIG.ADPXiQWZ1UF.ADf..."/>