changeset 324:9151fe15c194 prerelease

Added basic MIDI support in libpd_basic. You can now use the regular midiin object family
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 02 Jun 2016 02:17:08 +0100
parents b99b8ab317dd
children a9905703219d
files examples/basic_libpd/render.cpp
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/examples/basic_libpd/render.cpp	Thu Jun 02 02:15:40 2016 +0100
+++ b/examples/basic_libpd/render.cpp	Thu Jun 02 02:17:08 2016 +0100
@@ -13,6 +13,8 @@
 #include <stdio.h>
 #include "z_libpd.h"
 #include <UdpServer.h>
+#include <Midi.h>
+
 
 // setup() is called once before the audio rendering starts.
 // Use it to perform any initialisation and allocation which is dependent
@@ -49,8 +51,12 @@
 }
 
 AuxiliaryTask  udpReadTask;
+Midi midi;
 bool setup(BelaContext *context, void *userData)
 {
+	midi.readFrom(0);
+	midi.writeTo(0);
+	midi.enableParser(true);
 	gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse);
 	udpServer.bindToPort(1234);
 
@@ -103,6 +109,34 @@
 BelaContext *c;
 void render(BelaContext *context, void *userData)
 {
+	int num;
+	while((num = midi.getParser()->numAvailableMessages()) > 0){
+		static MidiChannelMessage message;
+		message = midi.getParser()->getNextChannelMessage();
+		message.prettyPrint();
+		switch(message.getType()){
+		case kmmNoteOn: {
+				int noteNumber = message.getDataByte(0);
+				int velocity = message.getDataByte(1);
+				int channel = message.getChannel();
+				rt_printf("message: noteNumber: %f, velocity: %f, channel: %f\n", noteNumber, velocity, channel);
+				libpd_noteon(channel, noteNumber, velocity);
+			}
+			break;
+		case kmmControlChange: {
+			int channel = message.getChannel();
+			int controller = message.getDataByte(0);
+			int value = message.getDataByte(1);
+			libpd_controlchange(channel, controller, value);
+			}
+			break;
+		case kmmProgramChange:
+			int channel = message.getChannel();
+			int program = message.getDataByte(0);
+			libpd_programchange(channel, program);
+			break;
+		}
+	}
 	static int inW = 0;
 	static int outR = 0;
 /*