SetGlobalArrayFloat('demo.global.array', i, LocalArrayOut.asArray(i));
GlobalArrayIn.asArray(i, GetGlobalArrayFloat('demo.global.array', i));
SetGlobalArrayString('track.names', 2, 'drums');
SetGlobalArrayTrigger('tracks.changed', 0);
see global-array and global-array
Write the name as the global-array module displays it. Usine puts it in upper case, so the case used in the script does not matter, but the module keeps only the first 40 characters of its name, then adds its suffix (name suffix setting): give that name, suffix included. A longer name, or the name without its suffix, finds no global array. A user suffix is kept as it is typed, while the script puts the whole name in upper case: type the user suffix in upper case, or no script finds the array.
| Procedure | Description |
|---|---|
function GetGlobalArraySize(name: string): integer; |
Get the size (number of elements) of a global array |
procedure SetGlobalArraySize(name: string; newsize: integer); |
Set the size (number of elements) of a global array |
function GetGlobalArrayFloat(name: string; index: integer): single; |
Get the float value of a global array element at the given index |
procedure SetGlobalArrayFloat(name: string; index: integer; v: single); |
Set the float value of a global array element at the given index |
function GetGlobalArrayColor(name: string; index: integer): TAlphaColor; |
Get the color of a color global array element at the given index |
procedure SetGlobalArrayColor(name: string; index: integer; v: TAlphaColor); |
Set the color of a color global array element at the given index |
function GetGlobalArrayString(name: string; index: integer): string; |
Get the text of a string global array element at the given index |
procedure SetGlobalArrayString(name: string; index: integer; v: string); |
Set the text of a string global array element at the given index |
procedure SetGlobalArrayTrigger(name: string; index: integer); |
Fire a trigger global array at the given index |
A global array has the type of the module that creates it, and each function reads or writes one type:
GetGlobalArrayFloat and SetGlobalArrayFloat,GetGlobalArrayColor and SetGlobalArrayColor, with $AARRGGBB values,GetGlobalArrayString and SetGlobalArrayString,SetGlobalArrayTrigger.The functions of the colors, the texts and the triggers raise a script error on a global array of another type, and do nothing. GetGlobalArrayFloat and SetGlobalArrayFloat do not check the type: on a string array they read 0 and write nothing.
The global constants are global arrays too: the functions read them, but SetGlobalArraySize and the SetGlobalArray... procedures raise a script error on a constant, which only its set module changes.
A name that matches no global array raises a script error as well: the function then reads 0 or an empty text and writes nothing.
The indexes start at 0. A write after the end grows the array, up to 16384 elements: the elements in between read 0, or are empty texts in a string array, and an index below 0 or above 16383 writes nothing. A read at an index below 0 gives 0 (an empty text for GetGlobalArrayString, which also gives an empty text after the last element): read the size with GetGlobalArraySize to stay inside the array.
A write is seen at once by the modules that read the array, and the array is sent to the shared computers when its module is set to send to shared computers. Writing the value an element already holds changes nothing.
////////////////////////////////////////////////////////////////////////////////
// Global Array Demo - showcases how to populate and read Usine global arrays.
// Press "write array" to push local values to the global store, then use
// "read array" to inspect the global array contents.
////////////////////////////////////////////////////////////////////////////////
const GLOBAL_ARRAY_NAME = 'demo.global.array';
const LOCAL_SIZE = 8;
var
WriteBtn : TParameter;
ReadBtn : TParameter;
LocalArrayOut : TParameter;
GlobalArrayIn : TParameter;
InfoText : TParameter;
procedure PushLocalToGlobal;
var
i: integer;
begin
SetGlobalArraySize(GLOBAL_ARRAY_NAME, LOCAL_SIZE);
for i := 0 to LOCAL_SIZE - 1 do
SetGlobalArrayFloat(GLOBAL_ARRAY_NAME, i, LocalArrayOut.asArray(i));
InfoText.asString('Wrote ' + IntToStr(LOCAL_SIZE) + ' elements to "' + GLOBAL_ARRAY_NAME + '".');
end;
procedure PullGlobalToLocal;
var
globalSize: integer;
i: integer;
value: single;
begin
globalSize := GetGlobalArraySize(GLOBAL_ARRAY_NAME);
GlobalArrayIn.Length(globalSize);
for i := 0 to globalSize - 1 do
begin
value := GetGlobalArrayFloat(GLOBAL_ARRAY_NAME, i);
GlobalArrayIn.asArray(i, value);
end;
InfoText.asString('Loaded global array "' + GLOBAL_ARRAY_NAME + '" size=' + IntToStr(globalSize) + '.');
end;
procedure Init;
var
i: integer;
begin
ModuleColor($FF455A64);
WriteBtn := CreateParam('write array', ptButton, pioInput);
ReadBtn := CreateParam('read array', ptButton, pioInput);
LocalArrayOut := CreateParam('local array', ptArray, pioInput);
GlobalArrayIn := CreateParam('global array',ptArray, pioOutput);
InfoText := CreateParam('info', ptTextField, pioOutput);
LocalArrayOut.Length(LOCAL_SIZE);
GlobalArrayIn.Length(0);
for i := 0 to LOCAL_SIZE - 1 do
LocalArrayOut.asArray(i, i * 0.1); // seed local array with simple ramp values
InfoText.asString('Use "write array" to push the local ramp into the global array.');
end;
procedure Callback(N: integer);
begin
if N = WriteBtn then
PushLocalToGlobal;
if N = ReadBtn then
PullGlobalToLocal;
end;
////////////////////////////////////////////////////////////////////////////////
// Track Names Demo - writes the name and the color of a track in the string
// array TRACK.NAMES and the color array TRACK.COLORS, then fires the trigger
// array TRACKS.CHANGED: the global-array-trigger-get modules of that name tell
// the other patches to read the arrays again.
// Create the global-array-string, global-array-color and global-array-trigger
// modules with these names first.
////////////////////////////////////////////////////////////////////////////////
const NAMES_ARRAY = 'track.names';
const COLORS_ARRAY = 'track.colors';
const CHANGED_TRIGGER = 'tracks.changed';
var
TrackNum : TParameter;
TrackName : TParameter;
TrackColor : TParameter;
WriteBtn : TParameter;
InfoText : TParameter;
procedure WriteTrack;
var
i: integer;
begin
i := TrackNum.asInteger;
SetGlobalArrayString(NAMES_ARRAY, i, TrackName.asString);
SetGlobalArrayColor(COLORS_ARRAY, i, TrackColor.asColor);
SetGlobalArrayTrigger(CHANGED_TRIGGER, 0);
InfoText.asString('track ' + IntToStr(i) + ' = ' + GetGlobalArrayString(NAMES_ARRAY, i)
+ ', ' + IntToStr(GetGlobalArraySize(NAMES_ARRAY)) + ' tracks');
end;
procedure Init;
begin
ModuleColor($FF00897B);
TrackNum := CreateParam('track', ptDataField, pioInput);
TrackName := CreateParam('track name', ptTextField, pioInput);
TrackColor := CreateParam('color', ptColor, pioInput);
WriteBtn := CreateParam('write', ptButton, pioInput);
InfoText := CreateParam('info', ptTextField, pioOutput);
TrackNum.Min(0);
TrackNum.Max(15);
end;
procedure Callback(N: integer);
begin
if N = WriteBtn then
WriteTrack;
end;
function GetGlobalArraySize(name: string): integer;
Returns the number of elements of a named global array, the number of texts for a string array.
size := GetGlobalArraySize('spectrum');
procedure SetGlobalArraySize(name: string; newsize: integer);
Sets the number of elements of a named global array, from 0 to 16384: a negative size gives 0, a larger one 16384. The elements added read 0, or are empty texts in a string array, and the elements removed are lost. The modules that read the array see its new size at once. As a write after the end grows the array, set the size to shorten an array, or to give it a known length before the script reads it. Set it also before filling a large array element by element: each write after the end gives the whole array to the module of the array.
SetGlobalArraySize('spectrum', 512);
function GetGlobalArrayFloat(name: string; index: integer): single;
Reads a value from a float global array at a given index. On a trigger global array, it gives a value that changes each time the array is fired (see SetGlobalArrayTrigger).
energy := GetGlobalArrayFloat('spectrum', bin);
procedure SetGlobalArrayFloat(name: string; index: integer; v: single);
Writes a value in a float global array at a given index.
SetGlobalArrayFloat('spectrum', bin, analyzerBuffer[bin]);
function GetGlobalArrayColor(name: string; index: integer): TAlphaColor;
Reads a color from a color global array (global-array-color) at a given index, as a $AARRGGBB value: see color to read its components.
LedColor.asColor(GetGlobalArrayColor('track.colors', 3));
procedure SetGlobalArrayColor(name: string; index: integer; v: TAlphaColor);
Writes a color in a color global array at a given index.
SetGlobalArrayColor('track.colors', 3, $FFE53935);
function GetGlobalArrayString(name: string; index: integer): string;
Reads a text from a string global array (global-array-string) at a given index. An index after the last text gives an empty text.
TrackName.asString(GetGlobalArrayString('track.names', 3));
procedure SetGlobalArrayString(name: string; index: integer; v: string);
Writes a text in a string global array at a given index. Written after the last text, it grows the array: the elements in between are empty texts.
SetGlobalArrayString('track.names', 3, 'drums');
procedure SetGlobalArrayTrigger(name: string; index: integer);
Fires a trigger global array (global-array-trigger), as the global-array-trigger-set module does: every global-array-trigger-get module of that name sends a trigger. The trigger set module fires the index 0; another index fires another element of the array, which a global-array-watch-modified module tells apart in its modified indexes.
A trigger get module sends at most one trigger every two audio blocks: fires closer than that, for example from Process in two blocks in a row, give one trigger.
Each call writes a new value at the index, which GetGlobalArrayFloat reads: compare it with the value read before to know in a script that the array was fired.
SetGlobalArrayTrigger('tracks.changed', 0);
version 7.0.250921
Edit All Pages