Javascript 使用不同时间嵌套设置间隔或在LCD上计算设置间隔
我正在尝试创建几个不同的乐器,每个乐器都有一个或多个音阶,所有音阶都由一个或多个节拍组成 乐器有自己的节奏,单位为BPM(每分钟拍数)。因此,如果乐器播放其“乐曲”,则长度/持续时间(毫秒)由Javascript 使用不同时间嵌套设置间隔或在LCD上计算设置间隔,javascript,Javascript,我正在尝试创建几个不同的乐器,每个乐器都有一个或多个音阶,所有音阶都由一个或多个节拍组成 乐器有自己的节奏,单位为BPM(每分钟拍数)。因此,如果乐器播放其“乐曲”,则长度/持续时间(毫秒)由numberofmeasuresintrument*beatsInSingleMeasure/instrumentTempo*60.0*1000.0 beatsinglemeasure也可以称为签名,因为音乐是以4/4等单位定义的 我试着循环一首“歌”。因此,如果我有多个持续时间不同的乐器,我希望它们都能同
numberofmeasuresintrument*beatsInSingleMeasure/instrumentTempo*60.0*1000.0
beatsinglemeasure也可以称为签名
,因为音乐是以4/4等单位定义的
我试着循环一首“歌”。因此,如果我有多个持续时间不同的乐器,我希望它们都能同时开始演奏,直到他们自己的“记分表”结束,然后等待所有乐器演奏完毕(即乐器持续时间最长),然后再重新开始(这实际上是使每个“记分表”的持续时间相等,并加上适当数量的休息和节奏,使其等于最长持续时间的乐器)。因此,所有乐器都应该同时开始,并以其节奏的间隔播放节拍,我认为这应该由另一个setInterval()来管理
是一把小提琴,用来说明彼此之间的持续时间。
让我们假设第一种乐器的持续时间为2秒,第二种乐器的持续时间为1.6秒,第三种乐器的持续时间为1.5秒。这将使第一种乐器的节拍每.66秒播放一次,第二种乐器的节拍每.4秒播放一次,第三种乐器的节拍每.25秒播放一次
我应该如何做到这一点?从概念上讲,我有理由嵌套间隔,说每2秒开始,并在适当的间隔播放你的节拍数(第一:每.66s三次;第二:每.4s四次;第三:每.25s六次;)。这似乎比试图找出节拍持续时间的LCD并以这种方式播放它们更容易,因为我需要跟踪什么是节拍或休息,以及什么是填充物以确保它在LCD单元中,在这种情况下,它是.25、.4和.66=>0.01666 s(也就是60Hz或1/60秒)的LCD
目前我有以下几点:
//Which beat are we on? first ones are in the negative to allow the 'song'to buffer once through the 'song', required by HTML5 Audio buffer
var beatCounter = 0-(signature*measuresCount-1);
// How many measures?
var measureCounter = 0;
// Are we waiting on another instrument to play, because we haven't reached the maximum play duration
var waitCounter = false;
function calculateWaiting(){
if ( beatCounter*dur == currentInstrumentDuration && currentInstrumentDuration < maxDuration ){
waitCounter = true;
} else {
waitCounter = false;
}
};
//This is the instrument interval
this.animationIntervalID = setInterval((function(self) {
return function() {
//this is the beat interval
this.beatAnimationIntervalID = setInterval((function(self) {
return function() {
//if we have not yet played all the beats and are waiting on the
if (waitCounter == false){
// As long as we are still have beats to play, keep playing
if (beatCounter >= 0 && beatCounter < totalNumberOfBeats) {
//Get all the beats
var beats = $('#measure-rep-'+self.measureRepModel.cid).find('.audio-beat');
// If the beat is selected, ie not a rest....
var selected = self.parentMeasureModel.get('beats').models[beatCounter].get('selected');
//animate it
self.audioAnimate(beats.eq(beatCounter)[0], dur, selected);
}
//Increase the beatCounter until all of the beats have played, then reset the beatCounter
if (beatCounter < (totalNumberOfBeats-1)) {
beatCounter ++;
} else {
beatCounter = 0;
}
calculateWaiting();
} else {
// Waiting until the longest measure is complete
console.log('waiting until the longer instrument is done playing');
}
};
})(this), dur); //dur is the cycle at which every beat should be animating/lasting
};
})(this), maxDuration); //maxDuration is the cycle at which every instrument should be waiting for to repeat
以及我试图实现的线性视觉:
//Scroll this window to see it linearly with time
// Let's assume that the first instrument plays for a duration of 2 seconds, the second
// plays for 1.6 s, and the third plays for 1.5 s. That would make the first instruments
// beats play at an interval of every .66s, the second instrument's beats play every
// .4 s, and the third instrument's beats play every .25s.
//
// The LCD of all instrument's beats is .01666s (60 Hz or 1/60th of a second), so it
// should look something like this: P meaning Play the beat, p, meaning the beat still
// being sustained, I meaning the LCD interval, and W meaning waiting
//
// 0s .5s 1s 1.5s 2s
// ^ ^ ^ ^ ^
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// 1: PpppppppppppppppppppppppppppppppppppppppPpppppppppppppppppppppppppppppppppppppppPppppppppppppppppppppppppppppppppppppppp
// 2: PpppppppppppppppppppppppPpppppppppppppppppppppppPpppppppppppppppppppppppPpppppppppppppppppppppppWWWWWWWWWWWWWWWWWWWWWWWW
// 3: PppppppppppppppPppppppppppppppPppppppppppppppPppppppppppppppPppppppppppppppPppppppppppppppWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
你想实时而不是模拟吗?我不确定你所说的模拟是什么意思,但间隔是用于动画的,必须映射到音频。我们计算动画应该发生的时间。因此我假设这意味着模拟。有什么理由使用BPM(每分钟拍数)吗小节不是用来代替量度和每个量度的节拍吗?还有,什么是乐器节拍(它是如何表示节拍的)?最后,“量度”代表什么(小节?如果不是怎么表示的量度)?您的代码目前如何不起作用?您不能只计算所有乐器中的最大持续时间,并在开始播放每种乐器时添加一行
setInterval((函数(self){…再次播放..},最大持续时间
)`@Ken AbdiasSoftware你所说的条是什么意思?
?度量用来表示一个整体的概念,由任意数量的拍组成,以不同的方式表示{矩形、直线、圆或脉冲}。乐器的签名是指该乐器任何一个小节中的节拍数,因为乐器中的所有小节将共享相同的节拍数,但不同乐器的节拍数可能不同。乐器节拍是以BPM(每分钟节拍)表示的乐器节拍因此,乐器的节拍也直接起作用。
//Scroll this window to see it linearly with time
// Let's assume that the first instrument plays for a duration of 2 seconds, the second
// plays for 1.6 s, and the third plays for 1.5 s. That would make the first instruments
// beats play at an interval of every .66s, the second instrument's beats play every
// .4 s, and the third instrument's beats play every .25s.
//
// The LCD of all instrument's beats is .01666s (60 Hz or 1/60th of a second), so it
// should look something like this: P meaning Play the beat, p, meaning the beat still
// being sustained, I meaning the LCD interval, and W meaning waiting
//
// 0s .5s 1s 1.5s 2s
// ^ ^ ^ ^ ^
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
// 1: PpppppppppppppppppppppppppppppppppppppppPpppppppppppppppppppppppppppppppppppppppPppppppppppppppppppppppppppppppppppppppp
// 2: PpppppppppppppppppppppppPpppppppppppppppppppppppPpppppppppppppppppppppppPpppppppppppppppppppppppWWWWWWWWWWWWWWWWWWWWWWWW
// 3: PppppppppppppppPppppppppppppppPppppppppppppppPppppppppppppppPppppppppppppppPppppppppppppppWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW