Documentation : Scripting


The default script object


To create a script : drag a "script" tool on a panel, open the editor (mousewheel over the editor pin) , edit the default script and click "execute"



The default script does nothing, just relaying the audio buffers and the parameter value to the output pins.
The "open" function is called when the program is loaded, then the "render" function is called for every audio buffer :
({
open: function(obj) {
  obj.listParameterPinIn.nbPins=1;
  obj.listParameterPinOut.nbPins=1;
  obj.listAudioPinIn.nbPins=1;
  obj.listAudioPinOut.nbPins=1;
},
render: function(obj) {
  obj.ParamOut0.value=obj.ParamIn0.value;
  obj.AudioOut0.buffer=obj.AudioIn0.buffer;
}
})

This script converts an audio level to a parameter value :
({
open: function(obj) {
  obj.listParameterPinIn.nbPins=0;
  obj.listParameterPinOut.nbPins=1;
  obj.listAudioPinIn.nbPins=1;
  obj.listAudioPinOut.nbPins=0;
},
render: function(obj) {
  obj.ParamOut0.value=obj.AudioIn0.value;
}
})

Simple audio switch : the signal goes to the 1st or 2nd pin depending on the parameter value :
({
open: function(obj) {
  obj.listParameterPinIn.nbPins=1;
  obj.listParameterPinOut.nbPins=0;
  obj.listAudioPinIn.nbPins=1;
  obj.listAudioPinOut.nbPins=2;
},
render: function(obj) {
if(obj.ParamIn0.value<0.5) {
  obj.AudioOut0.buffer=obj.AudioIn0.buffer;
} else {
  obj.AudioOut1.buffer=obj.AudioIn0.buffer;
}
}
})

Program and group selection :
({
open: function(obj) {
  obj.listParameterPinIn.nbPins=2;
  obj.listParameterPinOut.nbPins=2;
  obj.listAudioPinIn.nbPins=0;
  obj.listAudioPinOut.nbPins=0;
  this.prg=Math.round(obj.ParamIn0.value*10);
  this.grp=Math.round(obj.ParamIn1.value*10);
},
render: function(obj) {
  var p;
  p = Math.round(obj.ParamIn0.value*10);
  if(p!=this.prg) {
    this.prg=p;
    Programs.prog=this.prg;
  }
  obj.ParamOut0.value=Programs.prog/10;
  var g;
  g = Math.round(obj.ParamIn1.value*10);
  if(g!=this.grp) {
    this.grp=g;
    Programs.group=this.grp;
  }
  obj.ParamOut1.value=Programs.group/10;
}
})

1 comment:

  1. you can use obj.alert(someVariable) but be careful when using it in the render function !

    ReplyDelete