I'm using the js code below to do the following:
- See if any objects with a .varname name exist
- Delete them if they do
- Create new ones with a certain .varname
- Connect the objects together
The code works for a single iteration, but I'd like to set a loop going so it repeats the function from a value of 1 up to and including the value of the global variable (g.channelcount).
Any help is welcomed!
function bang(){
g.channelCount = buff.channelcount();//gets buffer channel count
var deleteWaveform = this.patcher.getnamed("waveform");//delete waveform and fromsymbol objects
var deleteSymbol = this.patcher.getnamed("symbol");
this.patcher.remove(deleteWaveform);
this.patcher.remove(deleteSymbol);
var waveform = this.patcher.newdefault(96, 756, "waveform~");//creates new waveform and fromsymbol objects and gives them a scripting name
var symbol = this.patcher.newdefault(186, 698, "fromsymbol");
waveform.varname = "waveform";
symbol.varname = "symbol";
post(g.channelCount);
var jsBox = this.patcher.getnamed("js_wave");//connects the objects together
this.patcher.connect(jsBox, 0, waveform, 0);
this.patcher.connect(jsBox, 1, symbol, 0);
this.patcher.connect(symbol, 0, waveform, 0);
outlet(1, "name loop");//loads the loop buffer into the waveform object
}
}