IML Messages

SendUsineMsg('SET_TARGET_PATCH', 'RackA.MyPatch');
SendUsineMsg('PLAY_WORKSPACE');
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, arg6: string); Send a Usine message with five arguments (note: arg6 may be a typo for arg5)
function GetUsineVariableString(name: string): string; Retrieve the value of a Usine variable as a string
function GetUsineVariableInteger(name: string): integer; Retrieve the value of a Usine variable as an integer
function GetUsineVariableFloat(name: string): double; Retrieve the value of a Usine variable as a floating-point number

The SendUsinelMsg script command should not be executed in the process procedure context.

You can use safely it in the processIDLE procedure. In the callback procedure set SetCallbackMode(cbMainThread); to asynchronously execute the callback function that contains the SendUsineMsg calls in the Usine IDLE processing thread instead of the process thread. Otherwise IML calls might lead to undefined behavior (function might not be executed, Usine crashes, etc.)

// example
// sets the active patch as the current patch
SendUsineMsg ('SET-TARGET-PATCH','SENDER-PATCH');

// get the value of the module named Input1.asString inlet Input2.asString
// and stores it into the internal variable 'THEPARAMVALUE'
SendUsineMsg ('GET-VALUE',Input1.asString,Input2.asString,'THEPARAMVALUE');

// assign the value of inlet number 1 of the module named 'THEMODULE' 
// to the value 'THEPARAMVALUE' previously stored
SendUsineMsg ('SET-VALUE','THEMODULE','1','THEPARAMVALUE');

// sets the value of the module Input1.asString, inlet Input2.asString to 
// the value of Input3.asFloat
SendUsineMsg ('SET-VALUE',Input1.asString,Input2.asString,FloatTostr(Input3.asFloat));

SendUsineMsgFile

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;

SendUsineMsg (no arguments)

procedure SendUsineMsg(msg: string);

Send a single Usine message without arguments.

var
  PlayBtn: TParameter;

procedure Init;
begin
  PlayBtn := CreateParam('play workspace', ptButton, pioInput);
  PlayBtn.CallbackMode(cbMainThread);                     // keep IML off the audio thread
end;

procedure Callback(N: integer);
begin
  if N = PlayBtn then
    SendUsineMsg('CREATE_MODULE data1 284 MOUSE_X MOUSE_Y');                         
end;

SendUsineMsg (1 argument)

procedure SendUsineMsg(msg, arg1: string);

Send a Usine message with one argument.

var
  TargetPatchBtn: TParameter;
  PatchPath     : TParameter;

procedure Init;
begin
  TargetPatchBtn := CreateParam('set target patch', ptButton, pioInput);
  TargetPatchBtn.CallbackMode(cbMainThread);

  PatchPath := CreateParam('patch path', ptTextField, pioInput);
  PatchPath.asString('RackA.MyPatch');
end;

procedure Callback(N: integer);
begin
  if N = TargetPatchBtn then
    SendUsineMsg('SET_TARGET_PATCH', PatchPath.asString);
end;

SendUsineMsg (2 arguments)

procedure SendUsineMsg(msg, arg1, arg2: string);

Send a Usine message with two arguments.

SendUsineMsg (3 arguments)

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 path', ptTextField, pioInput);
  ModulePath.asString('RackA.MyPatch.MyFader');

  TerminalName := CreateParam('terminal name', ptTextField, pioInput);
  TerminalName.asString('gain');
end;

procedure Callback(N: integer);
begin
  if N = QueryBtn then
  begin
    SendUsineMsg('GET_VALUE',
                 ModulePath.asString,
                 TerminalName.asString,
                 'demo.variable');
    Trace('current gain', GetVariableFloat('demo.variable'));
  end;
end;

SendUsineMsg (4 arguments)

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('RackA.SourceOSC');

  SourcePin := CreateParam('source pin', ptTextField, pioInput);
  SourcePin.asString('out');

  TargetModule := CreateParam('target module', ptTextField, pioInput);
  TargetModule.asString('RackA.Mixer');

  TargetPin := CreateParam('target pin', ptTextField, pioInput);
  TargetPin.asString('in');
end;

procedure Callback(N: integer);
begin
  if N = ConnectBtn then
    SendUsineMsg('CREATE_LINK',
                 SourceModule.asString,
                 SourcePin.asString,
                 TargetModule.asString,
                 TargetPin.asString);
end;

SendUsineMsg (5 arguments)

procedure SendUsineMsg(msg, arg1, arg2, arg3, arg4, arg6: string);

Send a Usine message with five arguments (note: arg6 may be a typo for arg5).

SendUsineMsg (5 arguments)

Send a Usine message with five arguments (note: arg6 may be a typo for arg5).

var
  SpawnBtn    : TParameter;
  ModuleID    : TParameter;
  PatchTarget : 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('55');                         // single fader module ID

  PatchTarget := CreateParam('patch path', ptTextField, pioInput);
  PatchTarget.asString('RackA.MyPatch');

  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
  if N = SpawnBtn then
    SendUsineMsg('CREATE_MODULE',
                 ModuleID.asString,
                 PatchTarget.asString,
                 ModuleName.asString,
                 PosX.asString,
                 PosY.asString);
end;

GetUsineVariableString

function GetVariableString(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 := GetVariableString(VariableName.asString);
    OutputText.asString(value);
  end;
end;

GetUsineVariableInteger

function GetVariableInteger(name: string): integer;

Retrieve the value of a Usine variable as an integer.

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(GetVariableInteger(IntegerVarName.asString));
end;

GetUsineVariableFloat

function GetVariableFloat(name: string): double;

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(GetVariableFloat(FloatVarName.asString));
end;

more about scripts

version 7.0.250121

Edit All Pages