diff projects/basic_midi/render.cpp @ 191:b3a306da03e0

Implemented Midi output
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 03 Feb 2016 01:18:30 +0000
parents d7148d21aaa5
children 265a527f8be8
line wrap: on
line diff
--- a/projects/basic_midi/render.cpp	Tue Jan 26 00:02:15 2016 +0000
+++ b/projects/basic_midi/render.cpp	Wed Feb 03 01:18:30 2016 +0000
@@ -24,6 +24,7 @@
 bool setup(BeagleRTContext *context, void *userData)
 {
 	midi.readFrom(0);
+	midi.writeTo(0);
 	if(context->analogFrames == 0) {
 		rt_printf("Error: this example needs the matrix enabled\n");
 		return false;
@@ -36,7 +37,7 @@
 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
 // will be 0.
 
-static midi_byte_t noteOnStatus =0x90; //on channel 1
+static midi_byte_t noteOnStatus = 0x90; //on channel 1
 
 enum {kVelocity, kNoteOn, kNoteNumber};
 void render(BeagleRTContext *context, void *userData)
@@ -50,6 +51,7 @@
 	static int waitingFor = kNoteOn;
 	static int playingNote = -1;
 	while ((message = midi.getInput()) >= 0){
+		rt_printf("%d\n", message);
 		switch(waitingFor){
 		case kNoteOn:
 			if(message == noteOnStatus){
@@ -86,7 +88,17 @@
 			break;
 		}
 	}
-	for(unsigned int n = 0; n < context->audioFrames; n++){
+
+	for(unsigned int n = 0; n < context->analogFrames; n++){
+		static int count = 0;
+		static bool state = 0;
+		analogWriteFrameOnce(context, n, 1, state);
+		if(count % 40000 == 0){
+			state = !state;
+			midi_byte_t bytes[6] = {176, 30, state*127, 176, 67, 30}; // toggle the OWL led and ask for the led status
+			midi.writeOutput(bytes, 6);
+		}
+
 		if(noteOn == 1){
 			static float phase = 0;
 			phase += phaseIncrement;
@@ -99,6 +111,7 @@
 			audioWriteFrame(context, n, 0, 0);
 			audioWriteFrame(context, n, 1, 0);
 		}
+		count++;
 	}
 }