billthefarmer / mididriver

Android midi driver using Sonivox EAS library
176 stars 52 forks source link

Change channel #18

Closed methelas2 closed 8 years ago

methelas2 commented 8 years ago

I know it have been asked in first issue here, but apparently the person who asked it figured it out without leaving a trace of explanation.

Is there any way I can change channel to which will be NOTE_ON/NOTE_OFF msg sent? For example: I'd like to send it to channel 10, which according to General MIDi is reserved for percussion instruments.

billthefarmer commented 8 years ago

The channel is encoded in the lower part of the note on and note off message. See the spec: https://www.midi.org/specifications/item/table-1-summary-of-midi-message. For example you could write yourself a noteOn() function like this:

    public boolean noteOn(int channel, int note, int volume)
    {
      byte noteMsg[] = new byte[3];

      noteMsg[0] = (byte)(channel + 0x90);
      noteMsg[1] = (byte)note;
      noteMsg[2] = (byte)volume;

      return midi.write(noteMsg);
    }
methelas2 commented 8 years ago

Well thank you! Thats what I've been looking for :)