【发布时间】:2020-05-03 07:02:44
【问题描述】:
我在安卓上使用billthefarmer/mididriver 来播放midi 音符。我在这里使用this question 作为起点。现在我可以向内部 android 合成器发送一条消息,以在某个通道上以给定的速度播放特定音符,并停止播放该音符。
private void playNote(int noteNumber) {
// Construct a note ON message for the specified at maximum velocity on channel 1:
event = new byte[3];
event[0] = (byte) (0x90 | 0x00); // This is the channel I guess but why two hex?
event[1] = (byte) noteNumber; // specified note
event[2] = (byte) 127; // 0x7F = the maximum velocity (127)
// Internally this just calls write() and can be considered obsoleted:
//midiDriver.queueEvent(event);
// Send the MIDI event to the synthesizer.
midiDriver.write(event);
}
private void stopNote(int noteNumber) {
// Construct a note OFF message for the specified note at minimum velocity on channel 1:
event = new byte[3];
event[0] = (byte) (0x80 | 0x00); // again why two hex?
event[1] = (byte) noteNumber; // specified note
event[2] = (byte) 0x00; // 0x00 = the minimum velocity (0)
// Send the MIDI event to the synthesizer.
midiDriver.write(event);
}
据我推测,这些消息以字节形式发送,因为 midi 文件和信号也是二进制的(也许?)。无论如何,有些问题我无法解决。
- 如何构造消息来更改频道上的乐器?
我在网上找到了this。这是正确的实施方式吗?
private void selectInstrument(int instrument) {
// message to select the instrument on channel 1:
event = new byte[2];
event[0] = (byte)(0xC0 | 0x00); // Can't I use int 0 for channel 1?
event[1] = (byte)instrument;
// Send the MIDI event to the synthesizer.
midiDriver.write(event);
}
int instrument 是通用 MIDI 级别 1 乐器编号。
合成器如何决定哪条消息告诉它播放/停止音符,哪条消息告诉它改变通道上的乐器?是字节数组的长度吗?
到目前为止,我的应用程序仅根据按下的按钮播放特定的音符。如果我想以特定的 bpm 播放一系列音符。说 180 bpm 和每拍一个音符。我必须用代码做所有这些吗?或者有没有办法将一些二进制消息提供给合成器,它可以以特定的速率 (bpm) 播放指定音符的数组或序列。如果有,怎么做?
【问题讨论】: