diff 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
line wrap: on
line diff
--- a/projects/basic_midi/render.cpp	Thu Feb 04 18:41:30 2016 +0000
+++ b/projects/basic_midi/render.cpp	Fri Feb 05 06:16:35 2016 +0000
@@ -25,6 +25,7 @@
 {
 	midi.readFrom(0);
 	midi.writeTo(0);
+	midi.enableParser(true);
 	if(context->analogFrames == 0) {
 		rt_printf("Error: this example needs the matrix enabled\n");
 		return false;
@@ -44,12 +45,14 @@
 {
 	static float f0;
 	static float phaseIncrement = 0;
-	int message;
 	static bool noteOn = 0;
 	static int velocity = 0;
 	static int noteNumber = 0;
 	static int waitingFor = kNoteOn;
 	static int playingNote = -1;
+///*
+	int message;
+	if(0) // one way of getting the midi data is to parse them yourself (you should set midi.enableParser(false) above):
 	while ((message = midi.getInput()) >= 0){
 		rt_printf("%d\n", message);
 		switch(waitingFor){
@@ -88,6 +91,14 @@
 			break;
 		}
 	}
+//*/
+	int num;
+	//alternatively, you can use the built-in parser (only processes channel messages at the moment).
+	while((num = midi.getParser()->numAvailableMessages()) > 0){
+		static MidiChannelMessage message;
+		message = midi.getParser()->getNextChannelMessage();
+		message.prettyPrint();
+	}
 
 	for(unsigned int n = 0; n < context->analogFrames; n++){
 		static int count = 0;