Mercurial > hg > beaglert
comparison examples/basic_libpd/render.cpp @ 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 | 1feb9c23ac57 |
children | a9905703219d |
comparison
equal
deleted
inserted
replaced
323:b99b8ab317dd | 324:9151fe15c194 |
---|---|
11 #include <I2c_Codec.h> | 11 #include <I2c_Codec.h> |
12 #include <PRU.h> | 12 #include <PRU.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include "z_libpd.h" | 14 #include "z_libpd.h" |
15 #include <UdpServer.h> | 15 #include <UdpServer.h> |
16 #include <Midi.h> | |
17 | |
16 | 18 |
17 // setup() is called once before the audio rendering starts. | 19 // setup() is called once before the audio rendering starts. |
18 // Use it to perform any initialisation and allocation which is dependent | 20 // Use it to perform any initialisation and allocation which is dependent |
19 // on the period size or sample rate. | 21 // on the period size or sample rate. |
20 // | 22 // |
47 usleep(1000); | 49 usleep(1000); |
48 } | 50 } |
49 } | 51 } |
50 | 52 |
51 AuxiliaryTask udpReadTask; | 53 AuxiliaryTask udpReadTask; |
54 Midi midi; | |
52 bool setup(BelaContext *context, void *userData) | 55 bool setup(BelaContext *context, void *userData) |
53 { | 56 { |
57 midi.readFrom(0); | |
58 midi.writeTo(0); | |
59 midi.enableParser(true); | |
54 gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse); | 60 gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse); |
55 udpServer.bindToPort(1234); | 61 udpServer.bindToPort(1234); |
56 | 62 |
57 // check that we are not running with a blocksize smaller than DEFDACBLKSIZE | 63 // check that we are not running with a blocksize smaller than DEFDACBLKSIZE |
58 // it would still work, but the load would be executed unevenly between calls to render | 64 // it would still work, but the load would be executed unevenly between calls to render |
101 // ADCs and DACs (if available). If only audio is available, numMatrixFrames | 107 // ADCs and DACs (if available). If only audio is available, numMatrixFrames |
102 // will be 0. | 108 // will be 0. |
103 BelaContext *c; | 109 BelaContext *c; |
104 void render(BelaContext *context, void *userData) | 110 void render(BelaContext *context, void *userData) |
105 { | 111 { |
112 int num; | |
113 while((num = midi.getParser()->numAvailableMessages()) > 0){ | |
114 static MidiChannelMessage message; | |
115 message = midi.getParser()->getNextChannelMessage(); | |
116 message.prettyPrint(); | |
117 switch(message.getType()){ | |
118 case kmmNoteOn: { | |
119 int noteNumber = message.getDataByte(0); | |
120 int velocity = message.getDataByte(1); | |
121 int channel = message.getChannel(); | |
122 rt_printf("message: noteNumber: %f, velocity: %f, channel: %f\n", noteNumber, velocity, channel); | |
123 libpd_noteon(channel, noteNumber, velocity); | |
124 } | |
125 break; | |
126 case kmmControlChange: { | |
127 int channel = message.getChannel(); | |
128 int controller = message.getDataByte(0); | |
129 int value = message.getDataByte(1); | |
130 libpd_controlchange(channel, controller, value); | |
131 } | |
132 break; | |
133 case kmmProgramChange: | |
134 int channel = message.getChannel(); | |
135 int program = message.getDataByte(0); | |
136 libpd_programchange(channel, program); | |
137 break; | |
138 } | |
139 } | |
106 static int inW = 0; | 140 static int inW = 0; |
107 static int outR = 0; | 141 static int outR = 0; |
108 /* | 142 /* |
109 * NOTE: if you are only using audio (or only analogs) and you are using interleaved buffers | 143 * NOTE: if you are only using audio (or only analogs) and you are using interleaved buffers |
110 * and the blocksize of Bela is the same as DEFDACBLKSIZE, then you probably | 144 * and the blocksize of Bela is the same as DEFDACBLKSIZE, then you probably |