我正在使用下面的 js 代码来执行以下操作:
- 查看是否存在任何具有 .varname 名称的对象
- 如果他们这样做,请删除它们
- 使用特定的 .varname 创建新的
- 将对象连接在一起
该代码适用于单次迭代,但我想设置一个循环,以便它重复从 1 到并包括全局变量 (g.channelcount) 的值的函数。
欢迎任何帮助!
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
}
}