Welcome to %s forums

BrainModular Users Forum

Login Register

script contest

I need help on a Patch
Post Reply
joffo78
Member
Posts: 1033
Contact:

script contest

Unread post by joffo78 » 26 Apr 2023, 15:15

Hello .
I'm trying to learn about scripting.
To start I opened the script
simplest callback example which displays the index of the last input whose value has been modified.
I would like to :
1) to be able to add an output that would display the value of the last modified input
2) to reproduce the same script but with an array input.

Thank you to enlighten me.
Here attached the script :

Code: Select all

//////////////////////////
//Simplest Callback exemple: check wich in changed
/////////////////////////                                          
var In1 , In2 , In3 : Tparameter;          
var inputChanged    : Tparameter;
var ChangedValues   : Tparameter;


//////////////////////////////////////   
// Init is started on script compilation to create the in/outs
PROCEDURE INIT;
BEGIN                                    
  In1:= CreateParam('Input1',PtDataField,pioInput); 
  In2:= CreateParam('Input2',PtDataField,pioInput); 
  In3:= CreateParam('Input3',PtDataField,pioInput); 
  
  InputChanged:= CreateParam('InputChanged',PtDataField,pioOutput);
  InputChanged.Min(0);
  InputChanged.Max(2);
  ChangedValues:= CreateParam('ValueChanged',PtdataField,pioOutput);
END; 
//////////////////////////////////////
// Callback procedure                      
// inputs have an id (n) from first (top) to n last, the callback proc
// scans the inputs to detect changes, 
// and notes the index if detecting one.
// that will allows to launchs different process depending on wich kind of
// inputs changed
Procedure Callback(N:integer);             
BEGIN                
  if n<3
  then inputchanged.asInteger(n); 

 
END;               
    




 : 

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 02 May 2023, 09:12

Something like that ?
But I'm shure that you can do that very efficiently with simple modules ?

Code: Select all

//////////////////////////
//Simplest Callback exemple: check wich in changed
/////////////////////////                                          
const SIZE_ARRAY_MAX = 1024; // max size of array inputs
const NB_INPUTS = 3;
type TmemoArray = array[0..SIZE_ARRAY_MAX-1] of single;

var Inp : array [0..NB_INPUTS-1] of Tparameter;          
var inputChanged    : Tparameter;
var ValueChanged   : Tparameter;
var ArrayIndexChanged : Tparameter;
var memoArray : array[0..NB_INPUTS-1] of TmemoArray;

//////////////////////////////////////   
// Init is started on script compilation to create the in/outs
PROCEDURE INIT;
var i : integer;
BEGIN                                    
  for i := 0 to NB_INPUTS-1
  do Inp[i] := CreateParam('Input'+inttostr(i),PtArray,pioInput); 
  
  InputChanged:= CreateParam('InputChanged',PtDataField,pioOutput);
  InputChanged.Max(2);

  ValueChanged:= CreateParam('ValueChanged',PtdataField,pioOutput);
  ArrayIndexChanged := CreateParam('ArrayIndexChanged',PtdataField,pioOutput);
END;

//////////////////////////////////////
// Test changes                      
Procedure TestChanged(N:integer);
var mx,i : integer;
var v : single;
BEGIN
   mx := minI(SIZE_ARRAY_MAX,inp[n].length);
   for i := 0 to mx-1
   do begin     
      v := inp[n].asArray(i);
      if memoArray[n][i] <> v
      then begin
         ArrayIndexChanged.asinteger(i);
         ValueChanged.asfloat(v);
      end;
      memoArray[n][i] := v;
   end;
   inputchanged.asInteger(n);
END;


//////////////////////////////////////
// Callback procedure                      
Procedure Callback(N:integer);             
BEGIN                
  if n<NB_INPUTS
  then TestChanged(N);
END;               

joffo78
Member
Posts: 1033
Contact:

Unread post by joffo78 » 03 May 2023, 10:50

Thank you senso.
i choose to do that by script only for learning.

Post Reply

Who is online

Users browsing this forum: No registered users and 83 guests