Parameter Creation and Layout

gain := CreateParam('Gain', ptDataFader, pioBoth);
gain.Min(-24); gain.Max(6); gain.Format('%.1f dB');

Parameters represent inlets, outlets, and internal controls. Define them in Init and configure them with the methods below to mimic module UI.

Method Description
function CreateParam(caption: string; typ: TParamType, ioTyp : TParamIOType ):TParameter; Creates an inlet/outlet
TParameter.IsInput(val: Boolean) Enables the inlet port.
TParameter.IsOutput(val: Boolean) Enables the outlet port.
TParameter.Scale(val: TScale) Applies linear, logarithmic, or exponential scaling to faders.
TParameter.Color(val: TAlphaColor) Sets the foreground/ON color.
TParameter.OffColor(val: TAlphaColor) Sets the OFF color for switch-style controls.
TParameter.Visible(val: Boolean) Shows or hides the control in the module panel.
TParameter.Min(val: Single) Defines the minimum allowed value.
TParameter.Max(val: Single) Defines the maximum allowed value.
TParameter.MinMaxNoLimit(val: Boolean) Unlocks values beyond the defined min/max.
TParameter.DefaultValue(val: Single) Declares the reset/default value; in Init it also sets the value.
TParameter.Caption(val: String) Updates the displayed caption.
TParameter.Symbol(val: String) Adds a suffix such as ms or %.
TParameter.Format(val: String) Controls numeric formatting via Pascal format strings.
TParameter.StringValue(val: String) Assigns text to string parameters.
TParameter.ListboxString(val: String) Sets combo-box items using comma-text.
TParameter.ReadOnly(val: Boolean) Locks or unlocks user edits.
TParameter.FastCallback(val: Boolean) Toggles fast callbacks for realtime response. DEPRECATED use TParameter.CallbackMode instead
TParameter.CallbackMode(mode: TCallbackMode) Sets the thread on which the parameter's callback executes: cbMainThread, cbImmediate, cbAsync, cbGraphic (cbVideo, cbRealTime and cbNetwork run as cbMainThread)
TParameter.DontSave(val: Boolean) Excludes the parameter from patch persistence.
TParameter.SavedName(val: String) Overrides the storage key used on disk.
TParameter.IsSeparator(val: Boolean) Inserts a blank row before the control in the UI.

CreateParam

function CreateParam (caption: string; typ: TParamType, ioTyp : TParamIOType ):TParameter;

Creates a parameter and returns its handle. Choose the caption, visual type, and IO role to expose in the patch.

gain := CreateParam('Gain', ptDataFader, pioInput);
mix := CreateParam('Mix', ptDataFader, pioBoth);
audioOut := CreateParam('Output', ptAudio, pioOutput);
TParamType

Define the visual style and data semantics for parameters created through CreateParam. Pick the variant that matches the hardware control or data you need to expose.

Type Description
ptTextField Text field inlet/outlet.
ptColor Color picker inlet/outlet.
ptMIDI MIDI inlet/outlet.
ptGainFader Gain fader inlet/outlet (-84 to +12 dB).
ptAudio Audio inlet/outlet.
ptDataField Numeric inlet/outlet without a fader; click to edit the value.
ptDataFader Numeric inlet/outlet with a mouse-driven fader.
ptButton Momentary trigger inlet/outlet.
ptListBox Combo box inlet/outlet; populate with ListBoxString.
ptSwitch Toggle switch inlet/outlet.
ptArray Array inlet/outlet.
ptIpAddress IPv4-formatted inlet/outlet (xxx.xxx.xxx.xxx).
ptTimecode Timecode inlet/outlet (HH:MM:SS:FF).
ptMIDINoteFader MIDI note fader inlet/outlet for notes 0..127, shown as note names.
ptPointerBitMap Hexadecimal bitmap pointer inlet/outlet.
ptPointer General hexadecimal pointer inlet/outlet.
ptRightLed LED-style toggle inlet/outlet, the LED drawn at the right.
ptLed Former name of ptRightLed, kept for compatibility: the LED drawn at the right.
ptFolderName Folder picker inlet/outlet.
ptChooseFolder Former name of ptFolderName, kept for compatibility.
ptLeftLed LED-style toggle inlet/outlet, the LED drawn at the left.
ptTriggerLed LED trigger inlet/outlet, the LED drawn at the right.
ptFileName File picker inlet/outlet.
ptBitwise Bitwise flag inlet/outlet.

TParamIOType Control whether a parameter shows up as an inlet, outlet, both, or only within the script.

Type Description
pioInput Parameter appears as an inlet.
pioOutput Parameter appears as an outlet.
pioBoth Parameter functions as both inlet and outlet.
pioNone Parameter stays internal and is hidden on the module.

TParameter.IsInput

procedure TParameter.IsInput (val: boolean);

Overrides the IO direction after creation.

buffer := CreateParam('Buffer', ptArray, pioNone);
buffer.IsInput(true);

TParameter.IsOutput

procedure TParameter.IsOutput (val: boolean);

Turns a parameter into an outlet even if it was created as internal.

diagnostic := CreateParam('Log', ptDataField, pioNone);
diagnostic.IsOutput(true);

TParameter.Scale

Sets exponential, logarithmic, or linear scaling for faders so they mirror BrainModular gain or filter modules.

frequency.Scale(lsExp);
TScale

procedure TParameter.Scale (val: TScale);

Available scaling curves for fader-style parameters.

Type Description
lsLinear Linear response; equal steps per unit.
lsLog Logarithmic response; more resolution near the minimum.
lsExp Exponential response; more resolution near the maximum.

TParameter.Color

TParameter.Color(val: TAlphaColor)

Set the foreground color of the parameter.

transient.Color($FF1ABC9C);

TParameter.OffColor

TParameter.OffColor(val: TAlphaColor)

Defines the inactive color on switch-style parameters.

bypass.OffColor($FF303030);

TParameter.Visible

TParameter.Visible (val: Boolean);

Hides the parameter in the module while keeping them addressable from scripts or snapshots.

advanced.Visible(false);

TParameter.Min

TParameter.Min(val: Single)

Sets the minimum numerical value and clamps incoming automation. By default the min value is 0.

feedback.Min(0.0);

TParameter.Max

TParameter.Max(val: Single)

Sets the maximum permissible value. By default the min value is 1.

feedback.Max(0.95);

TParameter.MinMaxNoLimit

TParameter.MinMaxNoLimit(val: Boolean)

Allows a data field to exceed the standard min/max, ideal when mirroring Array modules.

offset.MinMaxNoLimit(true);

TParameter.DefaultValue

TParameter.DefaultValue(val: Single)

Defines the default value of the parameter: the value that a reset of the control gives it.

Called in Init, it also sets the value of a parameter of one value (a number, a gain, a MIDI note, a time code, a switch, a button, a list), without calling Callback, at once and again when Init has returned: Min and Max are then known, so DefaultValue can come before them. Outside Init it only changes the default value. Compile, which keeps the values, and a patch that loads still give the parameter its former value back.

rate.DefaultValue(1.0);

TParameter.Caption

TParameter.Caption(val: String)

Renames the label shown in the control panel without rebuilding the parameter.

spread.Caption('Stereo Spread');

TParameter.Symbol

TParameter.Symbol(val: String)

Displays a unit suffix.

delay.Symbol('ms');

TParameter.Format

TParameter.Format(val: String)

Controls numeric rendering using Pascal format strings.

delay.Format('%.1f');
example 1

with an input number = 12345.678

  • Decimal : %d (12345)
  • Exponent : %e (1.23456780000000E+004)
  • Fixed 2 digits : %.2f (12345.68)
  • General : %g (12345.678)
  • 12 width fixed 2 digits : %12.2f ( 12345.68)
example 2
  // Just 1 data item
  Trace(Format('%s', ['Hello']));

  // A mix of literal text and a data item
  Trace(Format('String = %s', ['Hello']));
  Trace('');

  // Examples of each of the data types
  Trace(Format('Decimal          = %d', [-123]));
  Trace(Format('Exponent         = %e', [12345.678]));
  Trace(Format('Fixed            = %f', [12345.678]));
  Trace(Format('General          = %g', [12345.678]));
  Trace(Format('Number           = %n', [12345.678]));
  Trace(Format('Money            = %m', [12345.678]));
  Trace(Format('Pointer          = %p', [addr(text)]));
  Trace(Format('String           = %s', ['Hello']));
  Trace(Format('Unsigned decimal = %u', [123]));
  Trace(Format('Hexadecimal      = %x', [140]));

output

Hello
String = Hello

Decimal = -123
Exponent = 1.23456780000000E+004
Fixed = 12345.68
General = 12345.678
Number = 12,345.68
Money = ¤12,345.68
Pointer = 0069FC90
String = Hello
Unsigned decimal = 123
Hexadecimal = 8C
example 3
  // The width value dictates the output size
  // with blank padding to the left
  // Note the <> characters are added to show formatting
  Trace(Format('Padded decimal    = <%7d>', [1234]));

  // With the '-' operator, the data is left justified
  Trace(Format('Justified decimal = <%-7d>', [1234]));

  // The precision value forces 0 padding to the desired size
  Trace(Format('0 padded decimal  = <%.6d>', [1234]));

  // A combination of width and precision
  // Note that width value precedes the precision value
  Trace(Format('Width + precision = <%8.6d>', [1234]));

  // The index value allows the next value in the data array
  // to be changed
  Trace(Format('Reposition after 3 strings = %s %s %s %1:s %s',
               ['Zero', 'One', 'Two', 'Three']));

  // One or more of the values may be provided by the
  // data array itself.
  Trace(Format('In line           = <%10.4d>', [1234]));
  Trace(Format('Part data driven  = <%*.4d>', [10, 1234]));
  Trace(Format('Data driven       = <%*.*d>', [10, 4, 1234]));

output

Padded decimal    = <   1234>
Justified decimal = <1234   >
0 padded decimal  = <001234>
Width + precision = <  001234>
Reposition after 3 strings = Zero One Two One Two
In line           = <      1234>
Part data driven  = <      1234>
Data driven       = <      1234>

TParameter.ListBoxString

TParameter.ListboxString(val: String)

Populates combo boxes with comma-text options.

mode.ListBoxString('"Round Robin","Ascending","Random"');

TParameter.ReadOnly

TParameter.ReadOnly(val: Boolean)

Locks a parameter from user edits while still allowing script updates.

status.ReadOnly(true);

TParameter.FastCallback

TParameter.FastCallback(val: Boolean)

DEPRECATED use TParameter.CallbackMode instead

Enables the immediate callback path for tactile controls.

gate.CallbackMode(cbImmediate);

TParameter.CallbackMode

TParameter.CallbackMode(mode: TCallbackMode)

Selects the exact thread on which the parameter's Callback will execute. Available modes are : cbMainThread, cbImmediate, cbAsync, cbGraphic. The modes cbVideo, cbRealTime and cbNetwork are not available to scripts: the callback then runs in cbMainThread mode, and a warning is traced.

TCallbackMode
Mode Thread Typical use
cbMainThread Main message queue (~25–50 ms) Default. Safe for UI updates, dynamic patching, and non-time-critical work. Equivalent to CallbackMode(cbMainThread).
cbImmediate Audio thread (queued, before Process) The callback is queued and runs at the start of the module's next process step, just before Process, in the same thread (usually the audio thread). Equivalent to CallbackMode(cbImmediate). Use for reactions that must stay in step with Process.
cbAsync Main thread (async queue) Runs on the main thread, from a queue processed right after the cbMainThread one: it does not block the audio but blocks the UI while it runs — put file I/O and heavy computation in ProcessThread.
cbVideo Main message queue Not available to scripts: the callback runs as cbMainThread, and a warning is traced.
cbRealTime Main message queue Not available to scripts: the callback runs as cbMainThread, and a warning is traced.
cbGraphic Main thread (graphic queue) Runs on the main thread during the graphic refresh pass. Ideal for repainting custom displays, updating colors, or resizing panels.
cbNetwork Main message queue Not available to scripts: the callback runs as cbMainThread, and a warning is traced.
procedure Init;
begin
  trigger := CreateParam('Trigger', ptButton, pioInput);
  trigger.CallbackMode(cbImmediate);

  display := CreateParam('Display', ptTextField, pioNone);
  display.CallbackMode(cbGraphic);
end;

cbMainThread is the default mode. Only change it when you have a clear reason — choosing the wrong thread can introduce race conditions or block time-critical processing.

TParameter.DontSave

TParameter.DontSave(val: Boolean)

Marks transient parameters that should not persist in patches or workspaces.

runtimeId.DontSave(true);

TParameter.SavedName

TParameter.SavedName(val: String)

Overrides the storage key used in the workspace. By default the saved name is the caption. Can be useful if several inlets have the same caption.

transpose.SavedName('transposeSemitones');

TParameter.IsSeparator

TParameter.IsSeparator(val: Boolean)

Inserts a blank line before the control inside the module inspector.

sectionBreak.IsSeparator(true);

Parameter Value Access

Procedure Description
procedure TParameter.asFloat(val : single); Set the value of a float parameter
function TParameter.asFloat: single; Get the value of a float parameter
procedure TParameter.asInteger(val : integer); Set the value of an integer parameter
function TParameter.asInteger: integer; Get the value of an integer parameter
procedure TParameter.asString(val : string); Set the value of a string parameter
function TParameter.asString: string; Get the value of a string parameter
procedure TParameter.asMidi(index : integer; val : TMIDI); Set the value of a MIDI parameter at the index
function TParameter.asMidi(index : integer): TMIDI; Get the value of a MIDI parameter at the index
procedure TParameter.asArray(index : integer; val : single); Set the value of a float array parameter at the index
function TParameter.asArray(index : integer): single; Get the value of a float array parameter at the index
procedure TParameter.asColor(val : TAlphaColor); Set the value of a color parameter
function TParameter.asColor: TAlphaColor; Get the value of a color parameter
procedure TParameter.asColorArray(index : integer; val : TAlphaColor); Set the value of a color array parameter at the index
function TParameter.asColorArray(index : integer): TAlphaColor; Get the value of a color array parameter at the index
procedure TParameter.asBoolean(val : boolean); Set the value of a boolean parameter
function TParameter.asBoolean: boolean; Get the value of a boolean parameter
procedure TParameter.asBitWise(val : uInt32); Set the value of a bitwise parameter
function TParameter.asBitWise: uInt32; Get the value of a bitwise parameter
function TParameter.asPointer: single; Returns a pointer to the value
procedure TParameter.Length(l : integer); Set the length of a parameter
function TParameter.Length: integer; Get the length of a parameter
function TParameter.equal1: boolean; Return True if the parameter’s value is equal to 1
function TParameter.equal0: boolean; Return True if the parameter’s value is equal to 0
function TParameter.CopyFromModule(AModuleName, AModuleTletName: string):boolean; Copy the value from a specified module terminal (inlet or outlet) into the current parameter. See dynamic-patching. Returns TRUE if the operation succeed FALSE otherwise.
function TParameter.CopyToModule(AModuleName, AModuleTletName: string): boolean; Copy the current parameter value to a specified module terminal (inlet or outlet); a module setting that is not a control is only written on the main thread. See dynamic-patching. Returns TRUE if the operation succeed FALSE otherwise.
procedure TParameter.ReadFromChunk(ChunkName, ItemName: string); Read a parameter value from a specified chunk and item. See chunks
procedure TParameter.WriteToChunk(ChunkName, ItemName: string); Write a parameter value to a specified chunk and item. See chunks

TParameter.asFloat

procedure TParameter.asFloat(val : single);
function TParameter.asFloat: single;

Reads or writes a single-precision value, the primary way to control faders and numeric inlets.

procedure Process;
begin
  lfo := depth.asFloat * sin(phase);
  output.asFloat(lfo);
end;

TParameter.asInteger

procedure TParameter.asInteger(val : integer);
function TParameter.asInteger: integer;

Handles discrete values for switches, list boxes, and counters.

if voiceCount.asInteger = 0 then
  voiceCount.asInteger(1);

TParameter.asString

procedure TParameter.asString(val : string);
function TParameter.asString: string;

Stores formatted text in captions, log outputs, or TCP/IP helpers.

status.asString(Format('Active voices: %d', [voiceCount.asInteger]));

TParameter.asMidi

procedure TParameter.asMidi(index : integer; val : TMIDI);
function TParameter.asMidi(index : integer): TMIDI;

Reads and writes MIDI events indexed per block. Combine with Length to iterate polyphonic buffers.

msg := noteIn.asMidi(i);
msg.data1 := msg.data1 + transpose.asInteger;
noteOut.asMidi(i, msg);
TMIDI

type TMIDI = record Channel: integer; Msg: integer; Data1: integer; Data2: integer; end;

Field Description
Channel MIDI channel, 1 to 16.
Msg Status byte without the channel: $90 note on, $80 note off, $A0 key aftertouch, $B0 control change, $C0 program change, $D0 channel aftertouch, $E0 pitch bend.
Data1 First data byte, 0 to 127: note number, controller number, program number.
Data2 Second data byte, 0 to 127: velocity, controller value.

When a TMIDI is written, Data1 and Data2 are clamped to 0..127. A note-on of the middle C with velocity 100 on channel 1:

var msg: TMIDI;
begin
  msg.Channel := 1;
  msg.Msg     := $90;   // note on
  msg.Data1   := 60;    // middle C
  msg.Data2   := 100;   // velocity
  noteOut.asMidi(0, msg);
  noteOut.Length(1);
end;

TParameter.asArray

procedure TParameter.asArray(index : integer; val : single);
function TParameter.asArray(index : integer): single;

Accesses array parameters element by element, matching Array modules or bus buffers.

for i := 0 to shapeIn.Length - 1 do
begin
  shapeOut.asArray(i, shapeIn.asArray(i) * gain.asFloat);
end;
shapeOut.Length(shapeIn.Length);

TParameter.asColor

procedure TParameter.asColor(val : TAlphaColor);
function TParameter.asColor: TAlphaColor;

Gets or sets ARGB colors using TAlphaColor, enabling palette manipulation alongside XY Draw or LED grid modules.

var col: TAlphaColor;
begin
  col := colorIn.asColor;
  col := col xor $00FFFFFF;
  colorOut.asColor(col);
end;

TParameter.asColorArray

procedure TParameter.asColorArray(index : integer; val : TAlphaColor);
function TParameter.asColorArray(index : integer): TAlphaColor;

Accesses color array parameters element by element, like asArray but for TAlphaColor values. Combine with Length to build or scan color palettes.

for i := 0 to paletteIn.Length - 1 do
begin
  paletteOut.asColorArray(i, paletteIn.asColorArray(i) xor $00FFFFFF);
end;
paletteOut.Length(paletteIn.Length);

TParameter.asBoolean

procedure TParameter.asBoolean(val : boolean);
function TParameter.asBoolean: boolean;

Reads or writes a boolean value. The getter returns True when the parameter's rounded value equals 1, False otherwise. Convenient for switches and toggles.

if bypass.asBoolean then
  output.asFloat(input.asFloat)
else
  output.asFloat(input.asFloat * gain.asFloat);

TParameter.asBitWise

procedure TParameter.asBitWise(val : uInt32);
function TParameter.asBitWise: uInt32;

Reads or writes bit masks used by logic or OSC modules.

flags.asBitWise(flags.asBitWise or $00000010);

TParameter.Length

procedure TParameter.Length(l : integer);
function TParameter.Length: integer;

Defines the number of elements for array and MIDI parameters.

noteOut.Length(activeCount);

TParameter.equal1

function TParameter.equal1: boolean;

Return TRUE if the parameter's value is equal to 1.

TParameter.equal0

function TParameter.equal0: boolean;

Return TRUE if the parameter's value is equal to 0.

TParameter.CopyFromModule

function TParameter.CopyFromModule(AModuleName, AModuleTletName: string):boolean;

Copy the value from a specified module terminal (inlet or outlet) into the current parameter. See dynamic-patching. Returns TRUE if the operation succeed FALSE otherwise.

TParameter.CopyToModule

function TParameter.CopyToModule(AModuleName, AModuleTletName: string): boolean;

Copy the current parameter value to a specified module terminal (inlet or outlet). See dynamic-patching. Returns TRUE if the operation succeed FALSE otherwise. When AModuleTletName is one of the module's settings (a value of its settings panel that is not one of its controls, such as the nb polyphony of a sub-patch), it is only written when called on the main thread: on another thread (always in ProcessThread, usually in Process and in callbacks in cbImmediate mode), nothing is written, it returns FALSE and a script error is traced.

TParameter.ReadFromChunk

procedure TParameter.ReadFromChunk(ChunkName, ItemName: string);

Read a parameter value from a specified chunk and item. See chunks.

TParameter.WriteToChunk

procedure TParameter.WriteToChunk(ChunkName, ItemName: string);

Write a parameter value to a specified chunk and item. See chunks.

more about scripts

version 7.0.250921

Edit All Pages