+ /* The following methods are type specific and only make sense for the
+ correct event type. It is the caller's responsibility to only call
+ methods which make sense for the given event type. Currently this means
+ they all only make sense for MIDI, but built-in support may be added for
+ other protocols in the future, or the internal representation may change
+ to be protocol agnostic. */
+
+ uint8_t type() const { return _buf[0] & 0xF0; }
+ uint8_t channel() const { return _buf[0] & 0x0F; }
+ bool is_note_on() const { return type() == MIDI_CMD_NOTE_ON; }
+ bool is_note_off() const { return type() == MIDI_CMD_NOTE_OFF; }
+ bool is_note() const { return is_note_on() || is_note_off(); }
+ bool is_poly_pressure() const { return type() == MIDI_CMD_NOTE_PRESSURE; }
+ bool is_channel_pressure() const { return type() == MIDI_CMD_CHANNEL_PRESSURE; }
+ bool is_cc() const { return type() == MIDI_CMD_CONTROL; }
+ bool is_pgm_change() const { return type() == MIDI_CMD_PGM_CHANGE; }
+ bool is_pitch_bender() const { return type() == MIDI_CMD_BENDER; }
+ bool is_channel_event() const { return (0x80 <= type()) && (type() <= 0xE0); }
+ bool is_smf_meta_event() const { return _buf[0] == 0xFF; }
+ bool is_sysex() const { return _buf[0] == 0xF0 || _buf[0] == 0xF7; }
+ bool is_spp() const { return _buf[0] == 0xF2 && size() == 1; }
+ bool is_mtc_quarter() const { return _buf[0] == 0xF1 && size() == 1; }
+ bool is_mtc_full() const { return (size() == 10 &&
+ _buf[0] == 0xF0 && _buf[1] == 0x7F &&
+ _buf[3] == 0x01 && _buf[4] == 0x01); }
+
+ uint8_t note() const { return _buf[1]; }
+ uint8_t velocity() const { return _buf[2]; }
+ uint8_t poly_note() const { return _buf[1]; }
+ uint8_t poly_pressure() const { return _buf[2]; }
+ uint8_t channel_pressure() const { return _buf[1]; }
+ uint8_t cc_number() const { return _buf[1]; }
+ uint8_t cc_value() const { return _buf[2]; }
+ uint8_t pgm_number() const { return _buf[1]; }
+ uint8_t pitch_bender_lsb() const { return _buf[1]; }
+ uint8_t pitch_bender_msb() const { return _buf[2]; }
+ uint16_t pitch_bender_value() const { return ((0x7F & _buf[2]) << 7 | (0x7F & _buf[1])); }
+
+ void set_channel(uint8_t channel) { _buf[0] = (0xF0 & _buf[0]) | (0x0F & channel); }
+ void set_type(uint8_t type) { _buf[0] = (0x0F & _buf[0]) | (0xF0 & type); }
+ void set_note(uint8_t num) { _buf[1] = num; }
+ void set_velocity(uint8_t val) { _buf[2] = val; }
+ void set_cc_number(uint8_t num) { _buf[1] = num; }
+ void set_cc_value(uint8_t val) { _buf[2] = val; }
+ void set_pgm_number(uint8_t num) { _buf[1] = num; }
+
+ uint16_t value() const {
+ switch (type()) {
+ case MIDI_CMD_CONTROL:
+ return cc_value();
+ case MIDI_CMD_BENDER:
+ return pitch_bender_value();
+ case MIDI_CMD_NOTE_PRESSURE:
+ return poly_pressure();
+ case MIDI_CMD_CHANNEL_PRESSURE:
+ return channel_pressure();
+ case MIDI_CMD_PGM_CHANGE:
+ return pgm_number();
+ default:
+ return 0;
+ }
+ }
+