SendUsineMsg('SET_VAR', 'demo.tempo', '120');
SendUsineMsg('SET_VALUE', 'VOL1', 'gain', '-6');
| Procedure | Description |
|---|---|
procedure SendUsineMsgFile(const FileName: string); |
Send a list of Usine messages stored in a text file |
procedure SendUsineMsg(msg: string); |
Send a single Usine message without arguments |
procedure SendUsineMsg(msg, arg1: string); |
Send a Usine message with one argument |
procedure SendUsineMsg(msg, arg1, arg2: string); |
Send a Usine message with two arguments |
procedure SendUsineMsg(msg, arg1, arg2, arg3: string); |
Send a Usine message with three arguments |
procedure SendUsineMsg(msg, arg1, arg2, arg3, arg4: string); |
Send a Usine message with four arguments |
procedure SendUsineMsg(msg, arg1, arg2, arg3, arg4, arg5: string); |
Send a Usine message with five arguments |
function GetUsineVariableString(name: string): string; |
Retrieve the value of a Usine variable as a string; if the variable is not defined, the name itself is echoed back |
function GetUsineVariableInteger(name: string): integer; |
Retrieve the value of a Usine variable as an integer |
function GetUsineVariableFloat(name: string): single; |
Retrieve the value of a Usine variable as a floating-point number |
SendUsineMsg and SendUsineMsgFile run only on the main thread: in Init, ProcessIDLE, OnReset, Destroy and the callbacks in cbMainThread (the default), cbAsync or cbGraphic mode. Called on another thread (Process while the engine runs, ProcessThread, a callback in cbImmediate mode, a chunk notification), they send nothing and trace a script error.
You can use them safely in the processIDLE procedure.
In the callback procedure keep the parameter in the cbMainThread mode, the default (MyInlet.CallbackMode(cbMainThread);), so that the callback that contains the SendUsineMsg calls runs on the main thread.
SET_VALUE, GET_VALUE, SET_VAR, SET_TARGET_PATCH, CREATE_MODULE, CREATE_LINK, DELETE_MODULE... With the overloads that take arguments, give the command name in upper case and with its underscores ('SET_VALUE'), then each argument as a string. SendUsineMsg(msg) alone reads a whole command line: its words are separated by spaces, the words without quotes are read in upper case, and a word in quotes ("My Patch") keeps its case and its spaces.SET_VALUE, never SET-VALUE). There is no command that starts the audio engine: set the on switch of a Usine Master Settings module of the patch, SendUsineMsg('SET_VALUE', 'MASTER', 'on', '1') for a module of user name MASTER.RackA.MyPatch.MyFader) is not read. A terminal is named by its caption, else by its index from 0.SendUsineMsg call first makes the patch of the script (its sub-patch when it is in one) the target patch. A SET_TARGET_PATCH sent alone therefore lasts until the next call only: put it in a file sent with SendUsineMsgFile, where it holds for the next lines, or use the function SetTargetPatch for the dynamic patching functions. SET_TARGET_PATCH takes a rack index and a patch index (from 0), the caption of a patch of a rack of the current workspace, the user name of a sub-patch module, SENDER_PATCH (the target stays as it is) or PARENT_PATCH (the parent of the target).DELETE_MODULE and RECREATE_MODULE of the script itself or of a sub-patch or a procedure that holds it; DELETE_PATCH, CLEAR_PATCH, LOAD_PATCH, RELOAD_PATCH, UNDO_PATCH and REDO_PATCH of a patch that holds it; CLEAR_RACK, DELETE_RACK and LOAD_RACK of its rack; CLEAR_WORKSPACE and LOAD_WORKSPACE when the script is in the current workspace. Since SendUsineMsg targets the patch of the script, CLEAR_PATCH, LOAD_PATCH, RELOAD_PATCH, UNDO_PATCH and REDO_PATCH sent with it are always refused: send them from a file, after a SET_TARGET_PATCH to another patch.GET_VALUE is stored in a variable: read it with GetUsineVariableFloat or GetUsineVariableString, not GetUsineVariableInteger.// example: the modules named here are modules of the patch of the script
// get the value of the module named Input1.asString, terminal Input2.asString,
// and store it in the internal variable 'THEPARAMVALUE'
SendUsineMsg('GET_VALUE', Input1.asString, Input2.asString, 'THEPARAMVALUE');
// set the terminal '1' of the module named 'THEMODULE' (the terminal captioned '1',
// else the second terminal) to the value 'THEPARAMVALUE' stored above
SendUsineMsg('SET_VALUE', 'THEMODULE', '1', 'THEPARAMVALUE');
// set the terminal Input2.asString of the module Input1.asString
// to the value of Input3.asFloat
SendUsineMsg('SET_VALUE', Input1.asString, Input2.asString, FloatToStr(Input3.asFloat));
procedure SendUsineMsgFile(const FileName: string);
Send a list of Usine messages stored in a text file.
var
BatchBtn : TParameter;
MessageFile: TParameter;
procedure Init;
begin
BatchBtn := CreateParam('send file', ptButton, pioInput);
BatchBtn.CallbackMode(cbMainThread); // run in the GUI/IDLE thread
MessageFile := CreateParam('message file', ptTextField, pioInput);
MessageFile.asString(IncludeTrailingPathDelimiter(GetApplicationPath) +
'iml-demo-messages.txt');
end;
procedure Callback(N: integer);
begin
if N = BatchBtn then
SendUsineMsgFile(MessageFile.asString);
end;
The file holds one command per line, read as SendUsineMsg(msg) reads its text; a target set by a line holds for the lines after it:
SET_TARGET_PATCH "Synth"
SET_VALUE VOL1 gain -6
SET_VALUE OSC1 frequency 220
procedure SendUsineMsg(msg: string);
Send a single Usine message without arguments, or a whole command line: the words of the line are its command and its arguments, read in upper case unless they are in quotes.
var
AddFaderBtn: TParameter;
procedure Init;
begin
AddFaderBtn := CreateParam('add fader', ptButton, pioInput);
AddFaderBtn.CallbackMode(cbMainThread); // keep IML off the audio thread
end;
procedure Callback(N: integer);
begin
// a horizontal fader (class 3) named FADER1 at 100, 100 in the patch of the script
if N = AddFaderBtn then
SendUsineMsg('CREATE_MODULE fader1 3 100 100');
end;
procedure SendUsineMsg(msg, arg1: string);
Send a Usine message with one argument.
var
DeleteBtn : TParameter;
ModuleName: TParameter;
procedure Init;
begin
DeleteBtn := CreateParam('delete module', ptButton, pioInput);
DeleteBtn.CallbackMode(cbMainThread);
ModuleName := CreateParam('module name', ptTextField, pioInput);
ModuleName.asString('FADER1');
end;
procedure Callback(N: integer);
begin
// deletes the module of that user name in the patch of the script (never the script itself)
if N = DeleteBtn then
SendUsineMsg('DELETE_MODULE', ModuleName.asString);
end;
procedure SendUsineMsg(msg, arg1, arg2: string);
Send a Usine message with two arguments.
var
StoreBtn : TParameter;
TempoIn : TParameter;
procedure Init;
begin
StoreBtn := CreateParam('store tempo', ptButton, pioInput);
StoreBtn.CallbackMode(cbMainThread);
TempoIn := CreateParam('tempo', ptDataField, pioInput);
TempoIn.Max(300);
end;
procedure Callback(N: integer);
begin
if N = StoreBtn then
begin
// SET_VAR variable_name value: stores the value in the Usine variable 'demo.tempo'
SendUsineMsg('SET_VAR', 'demo.tempo', IntToStr(TempoIn.asInteger));
Trace('demo.tempo = ', GetUsineVariableInteger('demo.tempo'));
end;
end;
procedure SendUsineMsg(msg, arg1, arg2, arg3: string);
Send a Usine message with three arguments.
var
QueryBtn : TParameter;
ModulePath : TParameter;
TerminalName : TParameter;
procedure Init;
begin
QueryBtn := CreateParam('query value', ptButton, pioInput);
QueryBtn.CallbackMode(cbMainThread);
ModulePath := CreateParam('module name', ptTextField, pioInput);
ModulePath.asString('VOL1'); // the user name of a module, not a path
TerminalName := CreateParam('terminal name', ptTextField, pioInput);
TerminalName.asString('gain');
end;
procedure Callback(N: integer);
begin
if N = QueryBtn then
begin
// GET_VALUE module terminal variable: stores the value in the variable 'demo.variable'
SendUsineMsg('GET_VALUE',
ModulePath.asString,
TerminalName.asString,
'demo.variable');
Trace('current gain', GetUsineVariableFloat('demo.variable'));
end;
end;
procedure SendUsineMsg(msg, arg1, arg2, arg3, arg4: string);
Send a Usine message with four arguments.
var
ConnectBtn : TParameter;
SourceModule: TParameter;
SourcePin : TParameter;
TargetModule: TParameter;
TargetPin : TParameter;
procedure Init;
begin
ConnectBtn := CreateParam('create connection', ptButton, pioInput);
ConnectBtn.CallbackMode(cbMainThread);
SourceModule := CreateParam('source module', ptTextField, pioInput);
SourceModule.asString('OSC1'); // user names of modules of the patch of the script
SourcePin := CreateParam('source pin', ptTextField, pioInput);
SourcePin.asString('out sin');
TargetModule := CreateParam('target module', ptTextField, pioInput);
TargetModule.asString('VOL1');
TargetPin := CreateParam('target pin', ptTextField, pioInput);
TargetPin.asString('in 1');
end;
procedure Callback(N: integer);
begin
// CREATE_LINK source_module source_outlet target_module target_inlet
if N = ConnectBtn then
SendUsineMsg('CREATE_LINK',
SourceModule.asString,
SourcePin.asString,
TargetModule.asString,
TargetPin.asString);
end;
procedure SendUsineMsg(msg, arg1, arg2, arg3, arg4, arg5: string);
Send a Usine message with five arguments.
CREATE_MODULE takes the user name of the new module, the id of its class (see module's id), its left and its top, then the first query value of a class that asks one (the number of channels of an audio module, for example), or the file of a module made from a file, or -1: no value, and a class that asks one opens its query window. The module is created in the target patch, the patch of the script. The second query value, and the query values that follow a file, go in the command line of SendUsineMsg(msg): CREATE_MODULE name class left top value1 value2.
var
SpawnBtn : TParameter;
ModuleID : TParameter;
ModuleName : TParameter;
PosX : TParameter;
PosY : TParameter;
procedure Init;
begin
SpawnBtn := CreateParam('create module', ptButton, pioInput);
SpawnBtn.CallbackMode(cbMainThread);
ModuleID := CreateParam('module id', ptTextField, pioInput);
ModuleID.asString('3'); // a horizontal fader (control-fader-horizontal)
ModuleName := CreateParam('module name', ptTextField, pioInput);
ModuleName.asString('AutoFader');
PosX := CreateParam('pos x', ptTextField, pioInput);
PosX.asString('120');
PosY := CreateParam('pos y', ptTextField, pioInput);
PosY.asString('40');
end;
procedure Callback(N: integer);
begin
// CREATE_MODULE user_name class_id left top query_value
if N = SpawnBtn then
SendUsineMsg('CREATE_MODULE',
ModuleName.asString,
ModuleID.asString,
PosX.asString,
PosY.asString,
'-1'); // -1: no query value (a fader asks none)
end;
function GetUsineVariableString(const name: string): string;
Retrieve the value of a Usine variable as a string.
var
ReadStringBtn: TParameter;
VariableName : TParameter;
OutputText : TParameter;
procedure Init;
begin
ReadStringBtn := CreateParam('read string', ptButton, pioInput);
ReadStringBtn.CallbackMode(cbMainThread);
VariableName := CreateParam('variable name', ptTextField, pioInput);
VariableName.asString('demo.string');
OutputText := CreateParam('value out', ptTextField, pioOutput);
end;
procedure Callback(N: integer);
var
value: string;
begin
if N = ReadStringBtn then
begin
value := GetUsineVariableString(VariableName.asString);
OutputText.asString(value);
end;
end;
function GetUsineVariableInteger(const name: string): integer;
Retrieve the value of a Usine variable as an integer. A value stored by GET_VALUE is not an integer variable and gives -1: read it with GetUsineVariableFloat or GetUsineVariableString.
var
ReadIntegerBtn: TParameter;
IntegerVarName: TParameter;
IntegerOutput : TParameter;
procedure Init;
begin
ReadIntegerBtn := CreateParam('read integer', ptButton, pioInput);
ReadIntegerBtn.CallbackMode(cbMainThread);
IntegerVarName := CreateParam('variable name', ptTextField, pioInput);
IntegerVarName.asString('demo.integer');
IntegerOutput := CreateParam('value out', ptDataField, pioOutput);
end;
procedure Callback(N: integer);
begin
if N = ReadIntegerBtn then
IntegerOutput.asFloat(GetUsineVariableInteger(IntegerVarName.asString));
end;
function GetUsineVariableFloat(const name: string): single;
Retrieve the value of a Usine variable as a floating-point number.
var
ReadFloatBtn: TParameter;
FloatVarName: TParameter;
FloatOutput : TParameter;
procedure Init;
begin
ReadFloatBtn := CreateParam('read float', ptButton, pioInput);
ReadFloatBtn.CallbackMode(cbMainThread);
FloatVarName := CreateParam('variable name', ptTextField, pioInput);
FloatVarName.asString('demo.float');
FloatOutput := CreateParam('value out', ptDataField, pioOutput);
end;
procedure Callback(N: integer);
begin
if N = ReadFloatBtn then
FloatOutput.asFloat(GetUsineVariableFloat(FloatVarName.asString));
end;
version 7.0.250921
Edit All Pages