1 #ifndef INCLUDE_AL_IO_MIDI_HPP
2 #define INCLUDE_AL_IO_MIDI_HPP
41 int getMIDIDeviceIndex(std::string deviceName);;
48 #define BITS_(a, b, c, d, e, f, g, h) \
49 (a << 7 | b << 6 | c << 5 | d << 4 | e << 3 | f << 2 | g << 1 | h)
53 static const unsigned char
57 BITS_(1, 1, 1, 1, 0, 0, 0, 0),
60 BITS_(1, 0, 0, 0, 0, 0, 0, 0),
62 BITS_(1, 0, 0, 1, 0, 0, 0, 0),
83 BITS_(1, 0, 1, 0, 0, 0, 0,
86 BITS_(1, 1, 0, 1, 0, 0, 0,
89 BITS_(1, 1, 1, 0, 0, 0, 0, 0),
98 BITS_(1, 1, 1, 1, 0, 0, 0, 1),
100 BITS_(1, 1, 1, 1, 0, 0, 1, 0),
102 BITS_(1, 1, 1, 1, 0, 0, 1, 1),
104 BITS_(1, 1, 1, 1, 0, 1, 1, 0),
106 BITS_(1, 1, 1, 1, 1, 0, 0, 0),
112 BITS_(1, 1, 1, 1, 1, 1, 0, 0),
133 unsigned char byte3);
141 unsigned char bytes[3];
144 unsigned char b2 = 0,
unsigned char b3 = 0,
145 unsigned char*
data =
nullptr);
148 unsigned port()
const {
return mPort; }
154 unsigned char status()
const {
return bytes[0]; }
169 double velocity(
double mul = 1. / 127.)
const {
return bytes[2] * mul; }
175 return double(v - 8192) / 8191.;
182 double controlValue(
double mul = 1. / 127.)
const {
return bytes[2] * mul; }
185 unsigned char*
data()
const {
return mData; }
188 void print(std::ostream& stream = std::cout)
const;
193 unsigned char* mData;
207 void bindTo(RtMidiIn& RtMidiIn,
unsigned port = 0);
209 void clearBindings() {
210 for (
auto& binding : mBindings) {
211 binding.midiIn->cancelCallback();
223 std::vector<Binding> mBindings;
static const char * controlNumberString(unsigned char controlNumber)
Get string with control type from control number.
static const unsigned char MESSAGE_MASK
Message status byte type mask.
static const unsigned char ACTIVE_SENSING
Active sensing system message type.
static const unsigned char TIMING_CLOCK
Timing clock system message type.
static const unsigned char SYS_EX_END
End of system exclusive system message type.
static const unsigned char NOTE_ON
Note on channel message type.
static const unsigned char SOFT_PEDAL
Soft pedal control number.
static const unsigned char EXPRESSION
Expression controller control number.
static const unsigned char RESET
Reset all receivers system message type.
static const unsigned char BANK_SELECT
Bank select control number.
static const unsigned char CHANNEL_MASK
Channel message status byte channel mask.
static const unsigned char NOTE_OFF
Note off channel message type.
static const unsigned char PRESSURE_CHAN
Channel pressure (aftertouch) channel message type.
static const unsigned char PROGRAM_CHANGE
Program change channel message type.
static const unsigned char SYS_EX
System exclusive system message type.
static const unsigned char BREATH
Breath controller control number.
static const unsigned char DAMPER_PEDAL
Damper pedal control number.
static const unsigned char TUNE_REQUEST
Tune request system message type.
static const unsigned char PORTAMENTO_TIME
Portamento time control number.
static const char * messageTypeString(unsigned char statusByte)
Get string with message type from status byte.
static const unsigned char SEQ_STOP
Stop sequence system message type.
static const unsigned char SOSTENUTO_ON
Sostenuto on/off control number.
static const unsigned char PITCH_BEND
Pitch bend channel message type.
static const unsigned char VOLUME
Channel volume control number.
static const unsigned char SONG_POSITION
Song position system message type.
static const unsigned char FOOT
Foot controller control number.
static const unsigned char BALANCE
Balance control number.
static const unsigned char LEGATO_ON
Legato on/off control number.
static const unsigned char PORTAMENTO_ON
Portamento on/off control number.
static unsigned short convertPitchBend(unsigned char byte2, unsigned char byte3)
Convert pitch bend message bytes into a 14-bit value in [0, 16384)
static const unsigned char SONG_SELECT
Song select system message type.
static const unsigned char SEQ_START
Start sequence system message type.
static bool isChannelMessage(unsigned char statusByte)
Check status byte to see if the message is a channel message.
static const unsigned char PAN
Pan control number.
static const unsigned char SEQ_CONTINUE
Continue sequence system message type.
static const unsigned char PRESSURE_POLY
Polyphonic pressure (aftertouch) channel message type.
static const unsigned char MODULATION
Modulation wheel/stick control number.
static const unsigned char SYSTEM_MSG
System message type.
static const unsigned char TIME_CODE
Time code system message type.
static const unsigned char CONTROL_CHANGE
Control change channel message type.
void bindTo(RtMidiIn &RtMidiIn, unsigned port=0)
Bind handler to a MIDI input.
virtual void onMIDIMessage(const MIDIMessage &m)=0
Called when a MIDI message is received.
unsigned char type() const
Get the message type (see MIDIByte)
bool isChannelMessage() const
Returns whether this is a channel (versus system) message.
double pitchBend() const
Get mapped pitch bend amount in [-1,1] (type must be PITCH_BEND)
double timeStamp() const
Get time stamp of message.
unsigned char status() const
Get the status byte.
unsigned char noteNumber() const
Get note number (type must be NOTE_ON or NOTE_OFF)
unsigned char controlNumber() const
Get controller number (type must be CONTROL_CHANGE)
double velocity(double mul=1./127.) const
Get mapped note velocity (type must be NOTE_ON or NOTE_OFF)
void print(std::ostream &stream=std::cout) const
Print general information about message.
unsigned port() const
Get the MIDI device port.
double controlValue(double mul=1./127.) const
Get mapped controller value (type must be CONTROL_CHANGE)
unsigned char channel() const
Get the channel number (0-15)
unsigned char * data() const
Get sysex message data.
double noteToHz(double noteNumber)