Mercurial > hg > beaglert
changeset 325:a9905703219d prerelease
More extensive support for MIDI types for libpd. Untested
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 03 Jun 2016 14:43:58 +0100 |
parents | 9151fe15c194 |
children | bd54819ccfa7 |
files | examples/basic_libpd/render.cpp include/Midi.h |
diffstat | 2 files changed, 66 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/basic_libpd/render.cpp Thu Jun 02 02:17:08 2016 +0100 +++ b/examples/basic_libpd/render.cpp Fri Jun 03 14:43:58 2016 +0100 @@ -49,14 +49,18 @@ usleep(1000); } } - +#define PARSE_MIDI AuxiliaryTask udpReadTask; Midi midi; bool setup(BelaContext *context, void *userData) { midi.readFrom(0); midi.writeTo(0); +#ifdef PARSE_MIDI midi.enableParser(true); +#else + midi.enableParser(false); +#endif /* PARSE_MIDI */ gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse); udpServer.bindToPort(1234); @@ -110,33 +114,78 @@ void render(BelaContext *context, void *userData) { int num; +#ifdef PARSE_MIDI while((num = midi.getParser()->numAvailableMessages()) > 0){ static MidiChannelMessage message; message = midi.getParser()->getNextChannelMessage(); - message.prettyPrint(); +// message.prettyPrint(); // use this to print beautified message (channel, data bytes) switch(message.getType()){ - case kmmNoteOn: { + 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; } - break; - case kmmControlChange: { - int channel = message.getChannel(); - int controller = message.getDataByte(0); - int value = message.getDataByte(1); - libpd_controlchange(channel, controller, value); + case kmmNoteOff: + { + /* PureData does not seem to handle noteoff messages as per the MIDI specs, + * so that the noteoff velocity is ignored. Here we convert them to noteon + * with a velocity of 0. + */ + int noteNumber = message.getDataByte(0); +// int velocity = message.getDataByte(1); // would be ignored by Pd + int channel = message.getChannel(); + libpd_noteon(channel, noteNumber, 0); + break; } - break; - case kmmProgramChange: - int channel = message.getChannel(); - int program = message.getDataByte(0); - libpd_programchange(channel, program); - 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; + } + case kmmPolyphonicKeyPressure: + { + int channel = message.getChannel(); + int pitch = message.getDataByte(0); + int value = message.getDataByte(1); + libpd_polyaftertouch(channel, pitch, value); + break; + } + case kmmChannelPressure: + { + int channel = message.getChannel(); + int value = message.getDataByte(0); + libpd_aftertouch(channel, value); + break; + } + case kmmPitchBend: + { + int channel = message.getChannel(); + int value = (message.getDataByte(1) << 7)| message.getDataByte(0); + libpd_pitchbend(channel, value); + break; + } } } +#else + int input; + while((input = midi.getInput()) >= 0){ + libpd_midibyte(0, input); + rt_printf("input: %d\n", input); + } +#endif /* PARSE_MIDI */ static int inW = 0; static int outR = 0; /*