【问题标题】:Message to Mididriver for changing instrument and playing melody with specific bpm向 Mididriver 发送消息以更改乐器并使用特定 bpm 演奏旋律
【发布时间】: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 文件和信号也是二进制的(也许?)。无论如何,有些问题我无法解决。

  1. 如何构造消息来更改频道上的乐器?

我在网上找到了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 乐器编号。

  1. 合成器如何决定哪条消息告诉它播放/停止音符,哪条消息告诉它改变通道上的乐器?是字节数组的长度吗?

  2. 到目前为止,我的应用程序仅根据按下的按钮播放特定的音符。如果我想以特定的 bpm 播放一系列音符。说 180 bpm 和每拍一个音符。我必须用代码做所有这些吗?或者有没有办法将一些二进制消息提供给合成器,它可以以特定的速率 (bpm) 播放指定音符的数组或序列。如果有,怎么做?

【问题讨论】:

    标签: android midi


    【解决方案1】:

    状态字节的高四位指定消息类型。阅读MIDI specification

    android.media.midi 包不包含 MIDI 音序器。如果您的 MIDI 消息不是实时生成的,最好将它们写入 .mid 文件并告诉系统播放它。

    【讨论】:

    • Midi 消息不是实时生成的。假设我确实将它写入了一个 MIDI 文件。我如何告诉 midiDriver 播放这个 midi 文件?我是否将文件作为参数传递给 write 函数。
    • 该驱动程序是 Android 内部 MIDI 合成器的副本。你应该可以使用MediaPlayer
    猜你喜欢
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2020-02-15
    • 2017-01-13
    相关资源
    最近更新 更多