简体   繁体   English

在midi序列中达到某个刻度时,如何通知我?

[英]How can I be notified when a certain tick is reached in a midi sequence?

I'm using javax.sound.midi.Sequencer to play a sequence and I need to jump to an other part of the sequence when a certain tick is reached. 我正在使用javax.sound.midi.Sequencer播放序列,当达到某个刻度时,我需要跳到序列的另一部分。 Imagine a loop that when we reach tick number "y" we jump back to tick number "x". 想象一下一个循环,当我们到达刻度号“ y”时,我们跳回到刻度号“ x”。 But I'm not doing a loop so the built in looping methods won't work for me. 但是我没有做循环,所以内置的循环方法对我不起作用。

At the moment I'm using a swing timer that fires a getTickPosition() every millisecond until I reach my desired tick but this is giving me slightly inconsistent results and I have a feeling it is using a lot of CPU for a fairly simple task. 目前,我正在使用一个摆动计时器,该计时器每毫秒触发一次getTickPosition()直到达到所需的滴答声为止,但这给我带来了一些不一致的结果,并且我感觉它正在使用大量CPU来完成一个相当简单的任务。

I wish there was an event listener that would notify me when a certain tick is processed by the sequencer but there isn't AFAIK. 我希望有一个事件侦听器,当音序器处理了某个滴答声但没有AFAIK时会通知我。 Any suggestions would be greatly appreciated. 任何建议将不胜感激。

我对midi知之甚少,但总是对计算机音乐着迷,因此我四处张望,发现您可以在所需的滴答处将MetaMessage添加到其中一个曲目中,并使用MetaEventListener在消息出现时得到通知被处理了吗?

I would suggest you reduce your 我建议你减少你的

getTickPosition() every millisecond 每毫秒getTickPosition()

which = 1000 x second - is too often You could reduce by a factor of 100 to 10 x Second This would reduce you CPU usage (to 1% of what it currently is?) 哪个= 1000 x秒-太频繁了,您可以减少100到10 x秒,这将减少CPU使用率(降至当前的1%?)

The MIDI timing clock messages are (at 120 bpm) only two beats / per second which is (at 24 ticks per quarter note) 1/50th of a second (20 mSecs) to capture sub beat intervals - is that what you need to do? MIDI定时时钟信息(每秒120 bpm)仅每秒2个节拍,即(每四分音符24个滴答声)1/50秒(20毫秒)以捕获次节拍间隔-这就是您需要做的?

The better solution might be for the Sequencer to tell you when it has arrived but I don't know if a mechanism exists for this 更好的解决方案可能是让Sequencer告诉您何时到达,但我不知道是否存在对此的机制

I would be interested to know what fix works for you 我想知道哪种修补程序对您有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM