# HG changeset patch # User Giulio Moro # Date 1464830228 -3600 # Node ID 9151fe15c1943783bde72ca9ff961ba7bc595c36 # Parent b99b8ab317dd576015b02130ab84a203a502d797 Added basic MIDI support in libpd_basic. You can now use the regular midiin object family diff -r b99b8ab317dd -r 9151fe15c194 examples/basic_libpd/render.cpp --- 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 #include "z_libpd.h" #include +#include + // 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; /*