我正在尝试制作一个将充当其他设备的主时钟的定序器。
我已经设法让同步计时器启动并运行,并用它控制 DAW。但是,节奏非常不稳定,摇摆不定,幅度为 +- 1 BPM。
我最初在我的应用程序中使用了标准的 24 PPQ,但很快就发现时间质量不好,所以我尝试了 96 PPQ,这导致速度比应有的快了几倍。
我正在使用计时器,方法 scheduleAtFixedRate 将计时时钟消息添加到输出队列,如下所示:
/**
* Used every time the tempo is changed.
*
* Adds a Timer to a list. When a new Timer is added, the previous one is removed.
* Timing clock messages are added to the output queue at a rate set by the current
* Timer in the List.
*/
private void setNewTempoTimer()
{
Log.i(DEBUG_TAG, "set new tempo timer.");
if(!timerList.isEmpty())
{
timerList.getFirst().cancel();
timerList.removeFirst();
}
final Timer timer = new Timer();
timerList.add(timer);
/**
* The shortest time interval in MIDI
*/
long tick = _sixteenthNote / 6;
/**
* Starts adding messages to the output queue
*/
timer.scheduleAtFixedRate(
new TimerTask()
{
@Override
public void run()
{
if(_running)
{
setNewTimingMessage();
}
}
}, 0, tick);
}
节奏是这样计算的:
/**
* Calculates the length of a semiquaver in the sequencer
* @return the time of a semiquaver in milliseconds
*/
private void calculateTempo()
{
Log.i(DEBUG_TAG , "Calculated tempo.");
/**
* Fjärdedelsnot
*/
_quarterNote = Math.round(((60000/_tempo))*100000)/100000;
/**
* Sextondel
*/
_sixteenthNote = (_quarterNote/4);
_sixteenthNote = Math.round(_sixteenthNote*100000)/100000;
}
新的计时消息设置如下:
/**
* Sets new timing message in the midi output queue
*/
private void setNewTimingMessage()
{
try
{
_midiOut.addMessageToQueue(MIDI_TIMING_CLOCK, 0,0);
}
catch (InvalidMidiDataException e)
{
e.printStackTrace();
}
Log.i(DEBUG_TAG , "Set new message.");
}
请为我点亮一盏灯。
问候/米