see chunks
ValueInput.WriteToChunk('demo.chunk', 'fader');
ValueDisplay.ReadFromChunk('demo.chunk', 'fader');
| Procedure | Description |
|---|---|
procedure TParameter.ReadFromChunk(ChunkName, ItemName: string); |
Read a parameter value from a specified chunk and item |
procedure TParameter.WriteToChunk(ChunkName, ItemName: string); |
Write a parameter value to a specified chunk and item |
procedure SubscribeChunk(ChunkName, ItemName: string; CallBackID: uint32; Immediate: boolean); |
Subscribe to changes in a chunk item, with optional immediate callback |
procedure unSubscribeAll(); |
Unsubscribe from all previously subscribed chunks |
procedure ClearChunkItem(ChunkName, ItemName: string); |
Clear a specific item within a chunk |
procedure ClearChunk(ChunkName: string); |
Clear all data within a specified chunk |
////////////////////////////////////////////////////////////////////////////////
// Chunk Management Demo - demonstrates chunk subscriptions and read/write
// helpers. Use the controls to push a value to a chunk, read it back, and clear
// chunk items while observing callback notifications.
////////////////////////////////////////////////////////////////////////////////
const CHUNK_NAME = 'demo.chunk';
const CHUNK_ITEM = 'fader';
const CALLBACK_ID = $01;
var
WriteBtn : TParameter;
ReadBtn : TParameter;
ClearItemBtn : TParameter;
ClearChunkBtn : TParameter;
ValueInput : TParameter;
ValueDisplay : TParameter;
InfoText : TParameter;
procedure UpdateInfo(const msg: string);
begin
InfoText.asString(msg);
end;
procedure PushToChunk;
begin
ValueInput.WriteToChunk(CHUNK_NAME, CHUNK_ITEM);
UpdateInfo('Value written to chunk "' + CHUNK_NAME + '" item "' + CHUNK_ITEM + '".');
end;
procedure PullFromChunk;
begin
ValueDisplay.ReadFromChunk(CHUNK_NAME, CHUNK_ITEM);
UpdateInfo('Value read from chunk "' + CHUNK_NAME + '" item "' + CHUNK_ITEM + '".');
end;
procedure Init;
begin
ModuleColor($FF7E57C2);
WriteBtn := CreateParam('write chunk', ptButton, pioInput);
ReadBtn := CreateParam('read chunk', ptButton, pioInput);
ClearItemBtn := CreateParam('clear item', ptButton, pioInput);
ClearChunkBtn := CreateParam('clear chunk', ptButton, pioInput);
ValueInput := CreateParam('value in', ptDataFader, pioInput);
ValueDisplay := CreateParam('value out', ptDataField, pioOutput);
InfoText := CreateParam('info', ptTextField, pioOutput);
ValueInput.Min(0);
ValueInput.Max(1);
ValueInput.AsFloat(0.5);
ValueDisplay.Min(0);
ValueDisplay.Max(1);
UpdateInfo('Press "write chunk" to store the current value.');
// Subscribe to chunk changes so the Callback gets triggered on updates.
SubscribeChunk(CHUNK_NAME, CHUNK_ITEM, CALLBACK_ID, true);
end;
procedure Destroy;
begin
// Unsubscribe and clear chunk data when this script is released.
unSubscribeAll;
ClearChunk(CHUNK_NAME);
end;
procedure Callback(N: integer);
begin
if N = WriteBtn then
PushToChunk;
if N = ReadBtn then
PullFromChunk;
if N = ClearItemBtn then
begin
ClearChunkItem(CHUNK_NAME, CHUNK_ITEM);
UpdateInfo('Chunk item "' + CHUNK_ITEM + '" cleared.');
ValueDisplay.asFloat(0);
end;
if N = ClearChunkBtn then
begin
ClearChunk(CHUNK_NAME);
UpdateInfo('Entire chunk "' + CHUNK_NAME + '" cleared.');
ValueDisplay.asFloat(0);
end;
// Handle the chunk subscription callback (CALLBACK_ID).
if N = CALLBACK_ID then
begin
ValueDisplay.ReadFromChunk(CHUNK_NAME, CHUNK_ITEM);
UpdateInfo('Callback received for chunk update; value refreshed.');
end;
end;
procedure TParameter.ReadFromChunk (ChunkName,ItemName : string);
Copy parameter into a named chunk.
//write to a chunk
PROCEDURE PROCESS();
BEGIN
clearChunk('MYCHUNK') // not mandatory, in any case the `item1` will be rewritten.
input.WriteToChunk('MYCHUNK','item1');
END;
procedure TParameter.WriteToChunk (ChunkName,ItemName : string);
Restores a parameter from a chunk entry.
//read a chunk
PROCEDURE PROCESS();
BEGIN
output.ReadFromChunk('MYCHUNK','item2');
END;
procedure ClearChunkItem(ChunkName, ItemName: string);
Clears a specific item within a chunk
ClearChunkItem('ArpState', 'notes');
procedure ClearChunk(ChunkName: string);
Clear all data within a specified chunk.
ClearChunk('ArpState');
procedure SubscribeChunk(ChunkName, ItemName: string; CallBackID: uint32; Immediate: boolean);
Registers a callback to receive notifications when a module alter a chunk. The script is informed of the change by sending a message in the callback procedure if ItemName is empty, the script will subscribe to any changes of the chunk (any item)
If immediate is set to TRUE the callback is called immediately after the changes occurs, and is done in the audio thread. Otherwise, it passes thru the main thread with a 25-50ms delay.
var output : TParameter;
//INIT PROCEDURE
PROCEDURE INIT();
BEGIN
output:=CreateParam('out',ptDataFader,pioOutput);
SubscribeChunk('QSDF','i1',$A01,true);
END;
//CALLBACK
PROCEDURE CALLBACK(N:INTEGER);
BEGIN
CASE N OF
$A01: Begin
output.ReadFromChunk('QSDF','i1');
End;
End;//END MAIN CASE
END;
procedure ClearChunk(ChunkName: string);
Cancels every chunk subscription.
Procedure Destroy;
UnSubscribeAll;
End;
version 7.0.250121
Edit All Pages