Mercurial > hg > beaglert
comparison projects/basic_midi/render.cpp @ 197:265a527f8be8
Added MidiParser for channel messages
| author | Giulio Moro <giuliomoro@yahoo.it> |
|---|---|
| date | Fri, 05 Feb 2016 06:16:35 +0000 |
| parents | b3a306da03e0 |
| children | b128e3ea84ff |
comparison
equal
deleted
inserted
replaced
| 196:0029562391b1 | 197:265a527f8be8 |
|---|---|
| 23 Midi midi; | 23 Midi midi; |
| 24 bool setup(BeagleRTContext *context, void *userData) | 24 bool setup(BeagleRTContext *context, void *userData) |
| 25 { | 25 { |
| 26 midi.readFrom(0); | 26 midi.readFrom(0); |
| 27 midi.writeTo(0); | 27 midi.writeTo(0); |
| 28 midi.enableParser(true); | |
| 28 if(context->analogFrames == 0) { | 29 if(context->analogFrames == 0) { |
| 29 rt_printf("Error: this example needs the matrix enabled\n"); | 30 rt_printf("Error: this example needs the matrix enabled\n"); |
| 30 return false; | 31 return false; |
| 31 } | 32 } |
| 32 return true; | 33 return true; |
| 42 enum {kVelocity, kNoteOn, kNoteNumber}; | 43 enum {kVelocity, kNoteOn, kNoteNumber}; |
| 43 void render(BeagleRTContext *context, void *userData) | 44 void render(BeagleRTContext *context, void *userData) |
| 44 { | 45 { |
| 45 static float f0; | 46 static float f0; |
| 46 static float phaseIncrement = 0; | 47 static float phaseIncrement = 0; |
| 47 int message; | |
| 48 static bool noteOn = 0; | 48 static bool noteOn = 0; |
| 49 static int velocity = 0; | 49 static int velocity = 0; |
| 50 static int noteNumber = 0; | 50 static int noteNumber = 0; |
| 51 static int waitingFor = kNoteOn; | 51 static int waitingFor = kNoteOn; |
| 52 static int playingNote = -1; | 52 static int playingNote = -1; |
| 53 ///* | |
| 54 int message; | |
| 55 if(0) // one way of getting the midi data is to parse them yourself (you should set midi.enableParser(false) above): | |
| 53 while ((message = midi.getInput()) >= 0){ | 56 while ((message = midi.getInput()) >= 0){ |
| 54 rt_printf("%d\n", message); | 57 rt_printf("%d\n", message); |
| 55 switch(waitingFor){ | 58 switch(waitingFor){ |
| 56 case kNoteOn: | 59 case kNoteOn: |
| 57 if(message == noteOnStatus){ | 60 if(message == noteOnStatus){ |
| 86 rt_printf("NoteOn: %d, NoteNumber: %d, velocity: %d\n", noteOn, noteNumber, velocity); | 89 rt_printf("NoteOn: %d, NoteNumber: %d, velocity: %d\n", noteOn, noteNumber, velocity); |
| 87 } | 90 } |
| 88 break; | 91 break; |
| 89 } | 92 } |
| 90 } | 93 } |
| 94 //*/ | |
| 95 int num; | |
| 96 //alternatively, you can use the built-in parser (only processes channel messages at the moment). | |
| 97 while((num = midi.getParser()->numAvailableMessages()) > 0){ | |
| 98 static MidiChannelMessage message; | |
| 99 message = midi.getParser()->getNextChannelMessage(); | |
| 100 message.prettyPrint(); | |
| 101 } | |
| 91 | 102 |
| 92 for(unsigned int n = 0; n < context->analogFrames; n++){ | 103 for(unsigned int n = 0; n < context->analogFrames; n++){ |
| 93 static int count = 0; | 104 static int count = 0; |
| 94 static bool state = 0; | 105 static bool state = 0; |
| 95 analogWriteFrameOnce(context, n, 1, state); | 106 analogWriteFrameOnce(context, n, 1, state); |
