我有一个对象 ,toKeep
其中每个对象的标签属性中都包含一个 MIDI 音符。
我希望它在一定延迟后播放,具体取决于收到的音符数量。
现在的问题是变量pinned_neighbor
保持不变,即使它应该改变。
是setTimeout
函数没有接收到数据的问题吗?
for (var ed = 0; ed < toKeep.length; ed++) {
var pinned_neighbor = toKeep[ed].label
if (pinned_neighbor != undefined) {
setTimeout(function(pinned_neighrbor) {
output.playNote(pinned_neighbor, parseInt(midi.substr(2, 2)));
output.stopNote(pinned_neighbor, parseInt(midi.substr(2, 2)), { time: "+" + Math.floor(timefloor / toKeep.length) });
console.log('playing an edge note ' + pinned_neighbor + ' at ' + timecodea + ' on ' + parseInt(midi.substr(2, 2)));
timecodea = timecodea + Math.floor(timefloor / toKeep.length);
}, timecodea);
}
}