14 typedef unsigned char midi_byte_t;
17 typedef enum midiMessageType{
20 kmmPolyphonicKeyPressure,
28 #define midiMessageStatusBytesLength 7+2 //2 being kmmNone and kmmAny 30 extern midi_byte_t midiMessageStatusBytes[midiMessageStatusBytesLength];
31 extern unsigned int midiMessageNumDataBytes[midiMessageStatusBytesLength];
38 MidiMessageType getType();
40 unsigned int getNumDataBytes(){
41 return midiMessageNumDataBytes[(
unsigned int)_type];
43 void setDataByte(
unsigned int dataByteIndex, midi_byte_t input){
44 _dataBytes[dataByteIndex] = input;
46 void setType(MidiMessageType type){
48 _statusByte = midiMessageStatusBytes[_type];
50 void setChannel(midi_byte_t channel){
53 midi_byte_t getDataByte(
unsigned int index){
54 return _dataBytes[index];
57 for(
int n = 0; n<maxDataBytes; n++){
64 rt_printf(
"MessageType: %x, ", this->getType());
65 rt_printf(
"channel: %u, ", this->getChannel());
66 for(
unsigned int n = 0; n < this->getNumDataBytes(); n++){
67 rt_printf(
"data%d: %d, ", n + 1, this->getDataByte(n));
73 const static int maxDataBytes = 2;
75 midi_byte_t _statusByte;
76 midi_byte_t _dataBytes[maxDataBytes];
77 MidiMessageType _type;
113 std::vector<MidiChannelMessage> messages;
114 unsigned int writePointer;
115 unsigned int readPointer;
116 unsigned int elapsedDataBytes;
117 bool waitingForStatus;
119 bool callbackEnabled;
123 waitingForStatus =
true;
125 messages.resize(100);
128 callbackEnabled =
false;
129 messageReadyCallback = NULL;
141 int parse(midi_byte_t* input,
unsigned int length);
162 messageReadyCallback = newCallback;
163 if(newCallback != NULL){
164 callbackEnabled =
true;
166 callbackEnabled =
false;
176 return callbackEnabled;
186 int num = (writePointer - readPointer + messages.size() ) % messages.size();
202 message = messages[readPointer];
203 if(message.getType() == kmmNone){
206 messages[readPointer].setType(kmmNone);
208 if(readPointer == messages.size()){
241 void enableParser(
bool enable);
261 enableParser(callback != NULL);
270 int readFrom(
int port);
277 int writeTo(
int port);
291 int writeOutput(midi_byte_t byte);
299 int writeOutput(midi_byte_t* bytes,
unsigned int length);
307 static void midiInputLoop();
308 static void midiOutputLoop();
309 static bool staticConstructed;
310 static void staticConstructor();
313 void readInputLoop();
314 void writeOutputLoop();
317 std::vector<midi_byte_t> inputBytes;
318 unsigned int inputBytesWritePointer;
319 unsigned int inputBytesReadPointer;
320 std::vector<midi_byte_t> outputBytes;
321 unsigned int outputBytesWritePointer;
322 unsigned int outputBytesReadPointer;
325 static std::vector<Midi*> objAddrs[2];
int numAvailableMessages()
Definition: Midi.h:185
bool isCallbackEnabled()
Definition: Midi.h:175
MidiChannelMessage getNextChannelMessage()
Definition: Midi.h:200
void setParserCallback(void(*callback)(MidiChannelMessage, void *), void *arg=NULL)
Definition: Midi.h:259
void * AuxiliaryTask
Definition: Bela.h:289
void setCallback(void(*newCallback)(MidiChannelMessage, void *), void *arg=NULL)
Definition: Midi.h:160