CreateModule(55, 120, 40, 0, 0, 'AutoFader');
CreateConnection('AutoOSC', 'out', 'AutoFader', 'in');
Set of procedures to create dynamic patches: creations of modules, connections, etc.
| Procedure | Description |
|---|---|
function SetTargetPatch(AName: string):boolean; |
Set the target patch where subsequent module operations will take place. If the AName is empty then the current patch containing the script is used as target. Returns TRUE if the operation succeed FALSE otherwise. |
function CreateFileModule(Left, Top: integer; AFileName, OptionalContent, AModuleName: string):boolean; |
Create a new module from a file at the specified position and name, optionally providing inline content. If a module already exists with the specified AModuleName it is deleted before the creation of a new one. Returns TRUE if the operation succeed FALSE otherwise. |
function procedure CreateModule(numID, Left, Top, QueryIdx1, QueryIdx2: integer; AModuleName: string):boolean; |
Create a new module by its numeric ID and position within the patch see module's id page. If a module already exists with the specified AModuleName it is deleted before the creation of a new one. Returns TRUE if the operation succeed FALSE otherwise. |
procedure DeleteModule(AName: string); |
Delete a module from the patch by its name |
procedure CreateConnection(AModuleSrcName, AModuleSrcOutletName, AModuleTargName, AModuleTargInletName: string); |
Create a connection between two module terminals (source outlet → target inlet) |
procedure DeleteConnection(AModuleSrcName, AModuleSrcOutletName, AModuleTargName, AModuleTargInletName: string); |
Delete an existing connection between two module terminals |
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: string); overload; |
Set a string value on a module terminal (inlet or outlet) |
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: single); overload; |
Set a float value on a module terminal |
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: TAlphaColor); overload; |
Set a color value on a module terminal |
procedure SetModuleArrayValue(AModuleName, AModuleTletName: string; AValues: array of single); overload; |
Set multiple float values on an array-type module terminal |
procedure SetModuleArrayValue(AModuleName, AModuleTletName: string; AValues: array of TAlphaColor); overload; |
Set multiple color values on an array-type module terminal |
function GetModuleValue(AModuleName, AModuleTletName: string): TAlphaColor; overload; |
Get the color value of a module terminal |
function GetModuleValue(AModuleName, AModuleTletName: string): single; overload; |
Get the float value of a module terminal |
function GetModuleValue(AModuleName, AModuleTletName: string): string; overload; |
Get the string value of a module terminal |
function GetModulesUserNamesList: string; |
Return a comma-separated list of all user-named modules in the current patch |
procedure CopyModuleValue(AModuleName, AModuleTletName: string; AParameter: TParameter); |
Copy the value from a specified module terminal (inlet or outlet) into a TParameter variable |
function OpenPatch(AFileName, ANewName: string):boolean; |
Loads the current target patch from a file and eventually renames it with a new name. Returns TRUE if the operation succeed FALSE otherwise. |
function ClearPatch(ANewName: string):boolean; |
Clears the current target patch renames it a new name. Returns TRUE if the operation succeed FALSE otherwise. |
| Procedure | Description |
|---|---|
function LoadModuleDesign(AModuleName, AFileName: string): boolean; |
Load a module’s visual design from a specified file and apply it to the given module. Returns TRUE if the operation succeed FALSE otherwise. |
function SetModuleControlPosition(AModuleName: string; X, Y: single): boolean; |
Set the on-screen position of a module’s control interface.Returns TRUE if the operation succeed FALSE otherwise. |
function SetModuleControlSize(AModuleName: string; Width, Height: single): boolean; |
Set the width and height of a module’s control interface. Returns TRUE if the operation succeed FALSE otherwise. |
////////////////////////////////////////////////////////////////////////////////
// Dynamic Patch Demo - shows how to create/delete modules on the fly, connect
// them, tweak parameters, and inspect the resulting patch state via scripts.
////////////////////////////////////////////////////////////////////////////////
const PATCH_DEFAULT = 'MyDynamicPatch';
const FADER_ID = 55; // module ID for a single fader (see Usine module id list)
const FADER_NAME = 'DemoFader';
const OSC_MODULE_FILE = 'oscillator.pat'; // file-based module used for the demo source
const OSC_MODULE_NAME = 'DemoOSC';
var
BuildBtn : TParameter;
RefreshBtn : TParameter;
CleanupBtn : TParameter;
TargetPatch : TParameter;
InfoOutput : TParameter;
procedure RefreshStatus; forward;
procedure BuildDynamicPatch;
var
curveValues : array[0..3] of single;
begin
SetTargetPatch(TargetPatch.asString); // choose which patch receives the new modules
CreateModule(FADER_ID, 80, 40, 0, 0, FADER_NAME);
CreateFileModule(20, 40, OSC_MODULE_FILE, '', OSC_MODULE_NAME);
CreateConnection(OSC_MODULE_NAME, 'out', FADER_NAME, 'in');
SetModuleValue(FADER_NAME, 'caption', 'Dynamic Fader'); // string value
SetModuleValue(FADER_NAME, 'gain', 0.75); // float value
SetModuleValue(FADER_NAME, 'led-color', $FF00FF66); // color value (ARGB)
curveValues[0] := 0.0;
curveValues[1] := 0.2;
curveValues[2] := 0.8;
curveValues[3] := 1.0;
SetModuleArrayValue(FADER_NAME, 'curve', curveValues); // float array example
RefreshStatus;
InfoOutput.asString('Dynamic patch built and configured.');
end;
procedure RefreshStatus;
var
caption : string;
gainValue : single;
colorValue : TAlphaColor;
moduleNames : string;
report : string;
begin
caption := GetModuleValue(FADER_NAME, 'caption');
gainValue := GetModuleValue(FADER_NAME, 'out');
colorValue := GetModuleValue(FADER_NAME, 'led-color');
moduleNames := GetModulesUserNamesList;
report := 'Caption="' + caption +
'" gain=' + FloatToStr(gainValue) +
' color RGB=(' + IntToStr(colorValue.R) + ',' + IntToStr(colorValue.G) + ',' + IntToStr(colorValue.B) + ')' +
' modules=[' + moduleNames + ']';
InfoOutput.asString(report);
end;
procedure CleanupDynamicPatch;
begin
DeleteConnection(OSC_MODULE_NAME, 'out', FADER_NAME, 'in');
DeleteModule(OSC_MODULE_NAME);
DeleteModule(FADER_NAME);
InfoOutput.asString('Dynamic modules removed from patch "' + TargetPatch.asString + '".');
end;
procedure Init;
begin
ModuleColor($FF2E7D32);
BuildBtn := CreateParam('build', ptButton, pioInput);
RefreshBtn := CreateParam('refresh', ptButton, pioInput);
CleanupBtn := CreateParam('cleanup', ptButton, pioInput);
TargetPatch := CreateParam('target patch', ptTextField, pioInput);
InfoOutput := CreateParam('info', ptTextField, pioOutput);
TargetPatch.asString(PATCH_DEFAULT);
InfoOutput.asString('Set the target patch, then click "build" to spawn modules.');
end;
procedure Callback(N: integer);
begin
if N = BuildBtn then
BuildDynamicPatch;
if N = RefreshBtn then
RefreshStatus;
if N = CleanupBtn then
CleanupDynamicPatch;
end;
function SetTargetPatch(AName: string):boolean;
Set the target patch where subsequent module operations will take place.
If AName is empty, the current patch containing the script is used as target.
Returns TRUE if the operation succeed FALSE otherwise.
function CreateFileModule(Left, Top: integer; AFileName, OptionalContent, AModuleName: string):boolean;
Create a new module from a file at the specified position and name, optionally providing inline content.
If a module already exists with the specified AModuleName, it is deleted before the creation of a new one.
Returns TRUE if the operation succeed FALSE otherwise.
function CreateModule(numID, Left, Top, QueryIdx1, QueryIdx2: integer; AModuleName: string): boolean;
Create a new module by its numeric ID and position within the patch.
If a module already exists with the specified AModuleName, it is deleted before the creation of a new one.
Returns TRUE if the operation succeed FALSE otherwise.
See module's id.
procedure DeleteModule(AName: string);
Delete a module from the patch by its name.
procedure CreateConnection(AModuleSrcName, AModuleSrcOutletName, AModuleTargName, AModuleTargInletName: string);
Create a connection between two module terminals (source outlet → target inlet).
procedure DeleteConnection(AModuleSrcName, AModuleSrcOutletName, AModuleTargName, AModuleTargInletName: string);
Delete an existing connection between two module terminals.
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: string); overload;
Set a string value on a module terminal (inlet or outlet).
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: single); overload;
Set a float value on a module terminal.
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: TAlphaColor); overload;
Set a color value on a module terminal.
procedure SetModuleArrayValue(AModuleName, AModuleTletName: string; AValues: array of single); overload;
Set multiple float values on an array-type module terminal.
procedure SetModuleArrayValue(AModuleName, AModuleTletName: string; AValues: array of TAlphaColor); overload;
Set multiple color values on an array-type module terminal.
function GetModuleValue(AModuleName, AModuleTletName: string): TAlphaColor; overload;
Get the color value of a module terminal.
function GetModuleValue(AModuleName, AModuleTletName: string): single; overload;
Get the float value of a module terminal.
function GetModuleValue(AModuleName, AModuleTletName: string): string; overload;
Get the string value of a module terminal.
function GetModulesUserNamesList: string;
Return a comma-separated list of all user-named modules in the current patch.
function OpenPatch(AFileName, ANewName: string):boolean;
Loads the current target patch from a file and eventually renames it with a new name. Returns TRUE if the operation succeed FALSE otherwise.
function ClearPatch(ANewName: string):boolean;
Clears the current target patch renames it a new name. Returns TRUE if the operation succeed FALSE otherwise.
function LoadModuleDesign(AModuleName, AFileName: string): boolean;
Load a module’s visual design from a specified file and apply it to the given module. Returns TRUE if the operation succeed FALSE otherwise.
function SetModuleControlPosition(AModuleName: string; X, Y: single): boolean;
Set the on-screen position of a module’s control interface.Returns TRUE if the operation succeed FALSE otherwise.
function SetModuleControlSize(AModuleName: string; Width, Height: single): boolean;
Set the width and height of a module’s control interface. Returns TRUE if the operation succeed FALSE otherwise.
version 7.0.250121
Edit All Pages