Welcome to %s forums

BrainModular Users Forum

Login Register

scripting only if changed

I need help on a Patch
woodslanding
Member
Posts: 1327

Unread post by woodslanding » 22 Oct 2011, 00:20

Is there a way to do only if changed in a script? What would I set the output value to?

Also, I'm wondering what the math is for COEFF->DB ??

Thanks for any tips,
-e
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

23fx23
Member
Posts: 2548

Unread post by 23fx23 » 22 Oct 2011, 01:00

pass if change is done in script via setting length of the output to 0.

but then need to set back to size 1 if a float or arraysize for activating and setting values, and usually this imply that the callback trig a procedure, set sizes and values, trig a counter in process, and then in next process bloc (count+1) it will set back size to 0.
i have no clues for the db math thing sorry..

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

Unread post by senso » 22 Oct 2011, 12:07

right 23fx,
Just a detail, to have a real NULL event set its size to -1 instead of 0, it's more general and efficient in Usine.

Code: Select all

setLength(output,-1);
also the about the "Coeff to DB"

To change the volume of an audio flow, you can do a multiplication by a Coeff:

Code: Select all

-6 dB = mult by 0.5
-12db = mult by 0.25
...
The coeff to db is to retrieve the associated dB of a coeff (the inverse of the function above)

Code: Select all

coeffTodB(0.5) = -6
coeffTodB(0.25) = -12
...

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 24 Oct 2011, 04:47

Thanks, all!
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 28 Oct 2011, 10:28

Hey, this worked great, and I have created my most sophisticated script yet.

Thanks so much!!!
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 03 Nov 2011, 19:06

senso wrote:The coeff to db is to retrieve the associated dB of a coeff (the inverse of the function above)

Code: Select all

coeffTodB(0.5) = -6
coeffTodB(0.25) = -12
...
Olivier:

I'm getting:

Undeclared Identifier

when I use the function coeffToDB(single)
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 04 Apr 2012, 02:06

Revisiting this.... this time, I want to do Only If Changed for an Array.... but I can't do setValue(-1) or setLength(-1) on an array. How do I do this??

Thanks!!
-eric
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Unread post by nay-seven » 04 Apr 2012, 09:11

find this in my library, don't know the author
not exactly what you want but maybe a source of inspiration

Code: Select all

////////////////////////////////////////////////////////////////////////////////////////////
// Pass If Chg Array create an array where only values that changed in array in will pass //
// As it need 2 blocs (one to check, one to store) it relies on Process procedure         //
// The callback will trig a counter. at bloc 0 it will compare new array with previously  //
// stored one. At bloc 1 it will store the array to be compared next                      //
// The values that didn't changed are those where substracting equal 0, will set          //
// corresponding output length to 0, behaviour of passifChange in Usine                   //
////////////////////////////////////////////////////////////////////////////////////////////
const SIZE = 16;          // nb of out wanted = size of array
const PREFIX = 'OUT_';   // PEFIX for outputs names, folowed by Integer;
var ArrayIn: Tparameter;
var OUTPUTS: Array Of Tparameter;     // we will use an array of Tparameters, to allow N creations easily
var i,l,count: integer;               // we declare the variable we will use and their type
var valtmp:    single;
var ArrayLast: Array of single;       // ArrayLast will be used to store array to check wich values changed on new in
                                      // chg.
/////////////////////////////////////
PROCEDURE INIT;
BEGIN
 
 ArrayIn :=CreateParam('ArrayIn',PtArray); SetIsOutput(ArrayIn,False);
 setMin(arrayIn,0);setMax(ArrayIn,127);
 
  SetArrayLength(OUTPUTS,SIZE);       // we set the arraylength to create N outputs of size defined by constant on top
                                      // of script.
   for i:=0 to SIZE -1 do begin
    OUTPUTS[i]:= CreateParam(PREFIX+IntToStr(i),PtDataField); SetIsInput(OUTPUTS[i],false);
    end;   // we create the outputs, names with the prefix followed by their corresponding nb.
 
setArrayLength(ArrayLast,SIZE);   //we set the memory array the same size
setdontsave(arrayIn,false);       // by doing this the arrayin can be saved to Pm or on quiting the patch
END;//INit
//////////////////////////////
PROCEDURE Callback(N:integer); 
BEGIN  
   if (n=arrayIn) then begin
       l:= getlength(ArrayIn);
       count:=-1;                 // if detected arrayin chg, we trig the counter for process to start.
     end;
END;//callback
//////////////////////////////
PROCEDURE PROCESS;
BEGIN
 
if count >= -1 then begin        //start counting when callback has set count to -1
   count:=count+1;               // -1+1=0 so at first bloc count is 0
   end;
 
   if count = 0 then begin        // at first bloc we compare all values of new array with previous one.
     for i:=0 to l-1 do begin
       if ArrayLast&#91;i&#93;-getDataArrayValue&#40;ArrayIn,i&#41;<>0 then begin   // if there is a difference that mean
        valtmp&#58;= getDataArrayValue&#40;ArrayIn,i&#41;;                     //this value has changed
           setLength&#40;OUTPUTS&#91;i&#93;,1&#41;;                         // we make a size 1 to activate data pass
           setValue&#40;OUTPUTS&#91;i&#93;,valtmp&#41;;                    // and set the value with discovered one
       end
      else begin                                 // otherwise if no differences
          setLength&#40;OUTPUTS&#91;i&#93;,0&#41;;              // we setLength of 0 = don't pass.
       end;
      end;
      end;
 
    if count = 1 then begin                // on next bloc we store the array to internal memory for next compare.
       for i&#58;=0 to L-1 do begin
           ArrayLast&#91;i&#93;&#58;=getdataArrayValue&#40;ArrayIn,i&#41;;
                setLength&#40;OUTPUTS&#91;i&#93;,0&#41;;                // and make no values pass anymore.
             end;
      count&#58;=-2;                                      // and stop the counter as we reset it to -2
      end;
 
end;

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 04 Apr 2012, 16:55

Thanks Nay, that looks like the right info!
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 05 Apr 2012, 10:03

hmmm..... this is sort of not helping. I want to stop an array type out, and you are only stopping individual datafield elements of an array of TParameters. I know how to stop a datafield.

Still can't figure out how to stop a PTArray.
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

23fx23
Member
Posts: 2548

Unread post by 23fx23 » 05 Apr 2012, 13:44

i made this script a while back , but indeed it's more complex as it was made as an individual outpts PIC from an array (and have to correct the setlength to -1 and not 0 ideally, but should still work as is).

if for the whole array, just set the array to correct size when need to set values, then next bloc set it's lenght to -1. = stopped,
one solution like here is to trigg a counter when callback used to set your array changes, and when the count=+1 in process you setlength back to -1. Alternatively you can trig the back to -1 size via another input callback if wanna avoid process, but imo unless you really want to do all by script and complexify in this case, better make simple script for the functions you need and add a pic module after that, like bsork suggested me once ;)

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 05 Apr 2012, 15:55

I actually just want to stop the array when I get a 1 from the STOP input to the script.

this script has the only syntax I could find that compiles, and it doesn't work. I just want to be able to set the values of a few specific elements of the array, and be able to stop it from a switch. Seems easy enough.... but I can't get it working. I'm seeing all zeroes at the output no matter the value of STOP:

Code: Select all

/////////////////////////////////////

/////////////////////////
Const COUNT = 9;

var paramsOUT  &#58; TParameter;
var paramsIN  &#58; TParameter;
Var indicesIN  &#58;TParameter;
Var valuesIN  &#58; Array&#91;0..COUNT-1&#93; of TParameter;
Var stopIN    &#58;Tparameter;

Var indices &#58; TStringList;

Procedure Destroy;
begin
   indices.free;
end;

// initialisation &#58; create parameters
procedure init;
var i &#58; integer;
begin
  paramsIN &#58;= CreateParam&#40;'param arr',PtArray&#41;;
  SetIsOutput&#40;paramsIN,false&#41;;
  SetFastCallback&#40;paramsIN,false&#41;;
  SetMax&#40;paramsIn,MAXINT&#41;;

  paramsOUT &#58;= CreateParam&#40;'param arr',PtArray&#41;;
  SetIsInput&#40;paramsOUT,false&#41;;
  SetFastCallback&#40;paramsOUT,false&#41;;
  SetMax&#40;paramsOUT,MAXINT&#41;; 
  
  for i &#58;= 0 to &#40;COUNT - 1&#41; DO BEGIN
     valuesIN&#91;i&#93; &#58;= CreateParam&#40;'value' + intToStr&#40;i&#41;, PtTextfield&#41;;
     SetIsOutput&#40;valuesIN&#91;i&#93;,false&#41;;
     SetFastCallback&#40;valuesIN&#91;i&#93;,false&#41;;
  END; 
 
  indicesIN &#58;= CreateParam&#40;'indices', PtTextfield&#41;;
  SetIsOutput&#40;indicesIN,false&#41;;
  SetFastCallback&#40;indicesIN,false&#41;; 

  stopIN &#58;= CreateParam&#40;'stop', PtSwitch&#41;;
  SetIsOutput&#40;stopIN,false&#41;;
  SetFastCallback&#40;stopIN,false&#41;; 

end;

// Callback procedure
Procedure Callback&#40;N&#58;integer&#41;; 
var i,idx,stop,length &#58; integer;
value &#58; double;
name &#58; String;
begin
    stop &#58;= trunc&#40;getValue&#40;stopIN&#41;&#41;;
     // how to stop an array???
    length &#58;= getLength&#40;paramsIN&#41;;
    
    IF &#40;n = stopIN&#41; and &#40;stop = 1&#41; then FOR i &#58;= 0 to &#40;length - 1&#41; DO setLength&#40;paramsOUT, -1&#41;
    ELSE BEGIN
        setLength&#40;paramsOUT, length&#41;;
        for i &#58;= 0 to &#40;length - 1&#41; DO
           setDataArrayValue&#40;paramsOUT, i, paramsIN&#41;;
        indices.CommaText &#58;= GetStringValue&#40;indicesIN&#41;;
        // set the value of the array output at the index to the fader value coming in.
        FOR i &#58;= 0 to &#40;COUNT - 1&#41; DO setDataArrayValue&#40;paramsOUT,strToInt&#40;indices.Strings&#91;i&#93;&#41;,getValue&#40;valuesIN&#91;i&#93;&#41;&#41;;
    END
end;



//////////////////////////////
// main proc
//////////////////////////////
Procedure Process;
begin
end;
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

23fx23
Member
Posts: 2548

Unread post by 23fx23 » 06 Apr 2012, 13:38

will have a look at home this weekend, but from quick read you don't need to loop thru the whole array with a 'for i' but just set the global array length once, and i suspect pb comming from the else linked to (n=stop), as if any other inputs change, even if stop is 1 it will trig back the lenght to a positive value. try to link only to stop value, something like:

IF (stop = 1) then begin setlength(paramsOUT,-1); end else begin setlength(paramsOUT,length);end;

then your loop to set the values.

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 09 Apr 2012, 04:08

Don't spend too much time on that--I just realized once I am sending params as an array, I can stop the whole thing with one OIC module on the array input.... so no real need to put that in the script. I just need to be able to extract certain values from the array, manipulate them, and add the new values back into the appropriate slots in the array. I think I can do all that.

Thanks so much!
-eric
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 24 May 2012, 06:48

Getting back to this (as I'm doing it in a script again) so the length of a ptArray is set by setLength(x), not setArrayLength(x)?

Because getLength on a ptArray won't compile--it says not enough parameters. But the wiki shows only one parameter.

edit:

Okay, I am much closer.... my script is almost working, but my array out length is not the same as the input array. How can I do this?

Niether of these works:

//setLength(paramsOUT, getLength(paramsIN));
//setValue(paramsOUT, getValue(paramsIN));

In both cases, my output array shows length 1 ( paramsOUT[1] ) regardless of the size of the input array.

Do I have to iterate through the in and set the out element by element? That's fine, but I can't even get a correct length for the output array, after setting it to length -1!

Thanks!!!

-eric
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

23fx23
Member
Posts: 2548

Unread post by 23fx23 » 24 May 2012, 09:52

mmm strange. if a real red pin, it's get/set/length, if you made an array of tparameter, then it would be getarraylength,
after that yes you would have to loop trhu and set elmts by elmts.

woodslanding
Member
Posts: 1327

Unread post by woodslanding » 24 May 2012, 15:07

I did get this to work, not sure why it was refusing to compile before....

I did iterate, and it is working, thanks!!
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

Post Reply