我希望能够独立发送多个MIDI信息。但问题是,我必须等到上一封信结束。我必须为我所有的声音创建一条线吗?假设我想同时演奏10个音符。那我就得创建10个线程了?
我通过javax.sound.midi发送了MIDI消息
public void playNote(int pitch, int length, int velocity) {
try {
msg.setMessage(ShortMessage.NOTE_ON, 0, pitch, velocity);
rcvr.send(msg, timeStamp);
Thread.sleep(length);
msg.setMessage(ShortMessage.NOTE_OFF, 0, pitch, 0);
rcvr.send(msg, timeStamp);
} catch (Exception e) {
e.printStackTrace();
}
}发布于 2014-07-01 10:07:11
您不需要在下一个寄出之前等待便条。创建MIDI事件的FIFO:
public class MidiEvent
{
/**Number of time units to wait until this message should be sent.
*/
public int time_delta;
/**First status byte.
*/
public byte byte_0;
/**Second status byte.
*/
public byte byte_1;
/**Third status byte.
*/
public byte byte_2;
}然后将这些对象添加到队列中。在发送下一个事件之前,播放机线程将休眠time_delta单元。如果time_delta是零,那就马上发送。发送此事件后,将从FIFO获取下一个事件。
在循环中发送一串MIDI消息是“同时”的,因为发送者将足够快地发送笔记。
https://stackoverflow.com/questions/24507286
复制相似问题