Mercurial > hg > beaglert
comparison examples/basic_libpd/render.cpp @ 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 | 5e2780bfbfed |
comparison
equal
deleted
inserted
replaced
324:9151fe15c194 | 325:a9905703219d |
---|---|
47 while(!gShouldStop){ | 47 while(!gShouldStop){ |
48 libpd_sys_microsleep(0); | 48 libpd_sys_microsleep(0); |
49 usleep(1000); | 49 usleep(1000); |
50 } | 50 } |
51 } | 51 } |
52 | 52 #define PARSE_MIDI |
53 AuxiliaryTask udpReadTask; | 53 AuxiliaryTask udpReadTask; |
54 Midi midi; | 54 Midi midi; |
55 bool setup(BelaContext *context, void *userData) | 55 bool setup(BelaContext *context, void *userData) |
56 { | 56 { |
57 midi.readFrom(0); | 57 midi.readFrom(0); |
58 midi.writeTo(0); | 58 midi.writeTo(0); |
59 #ifdef PARSE_MIDI | |
59 midi.enableParser(true); | 60 midi.enableParser(true); |
61 #else | |
62 midi.enableParser(false); | |
63 #endif /* PARSE_MIDI */ | |
60 gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse); | 64 gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse); |
61 udpServer.bindToPort(1234); | 65 udpServer.bindToPort(1234); |
62 | 66 |
63 // check that we are not running with a blocksize smaller than DEFDACBLKSIZE | 67 // check that we are not running with a blocksize smaller than DEFDACBLKSIZE |
64 // it would still work, but the load would be executed unevenly between calls to render | 68 // it would still work, but the load would be executed unevenly between calls to render |
108 // will be 0. | 112 // will be 0. |
109 BelaContext *c; | 113 BelaContext *c; |
110 void render(BelaContext *context, void *userData) | 114 void render(BelaContext *context, void *userData) |
111 { | 115 { |
112 int num; | 116 int num; |
117 #ifdef PARSE_MIDI | |
113 while((num = midi.getParser()->numAvailableMessages()) > 0){ | 118 while((num = midi.getParser()->numAvailableMessages()) > 0){ |
114 static MidiChannelMessage message; | 119 static MidiChannelMessage message; |
115 message = midi.getParser()->getNextChannelMessage(); | 120 message = midi.getParser()->getNextChannelMessage(); |
116 message.prettyPrint(); | 121 // message.prettyPrint(); // use this to print beautified message (channel, data bytes) |
117 switch(message.getType()){ | 122 switch(message.getType()){ |
118 case kmmNoteOn: { | 123 case kmmNoteOn: |
124 { | |
119 int noteNumber = message.getDataByte(0); | 125 int noteNumber = message.getDataByte(0); |
120 int velocity = message.getDataByte(1); | 126 int velocity = message.getDataByte(1); |
121 int channel = message.getChannel(); | 127 int channel = message.getChannel(); |
122 rt_printf("message: noteNumber: %f, velocity: %f, channel: %f\n", noteNumber, velocity, channel); | |
123 libpd_noteon(channel, noteNumber, velocity); | 128 libpd_noteon(channel, noteNumber, velocity); |
124 } | 129 break; |
125 break; | 130 } |
126 case kmmControlChange: { | 131 case kmmNoteOff: |
127 int channel = message.getChannel(); | 132 { |
128 int controller = message.getDataByte(0); | 133 /* PureData does not seem to handle noteoff messages as per the MIDI specs, |
129 int value = message.getDataByte(1); | 134 * so that the noteoff velocity is ignored. Here we convert them to noteon |
130 libpd_controlchange(channel, controller, value); | 135 * with a velocity of 0. |
131 } | 136 */ |
132 break; | 137 int noteNumber = message.getDataByte(0); |
133 case kmmProgramChange: | 138 // int velocity = message.getDataByte(1); // would be ignored by Pd |
134 int channel = message.getChannel(); | 139 int channel = message.getChannel(); |
135 int program = message.getDataByte(0); | 140 libpd_noteon(channel, noteNumber, 0); |
136 libpd_programchange(channel, program); | 141 break; |
137 break; | 142 } |
138 } | 143 case kmmControlChange: |
139 } | 144 { |
145 int channel = message.getChannel(); | |
146 int controller = message.getDataByte(0); | |
147 int value = message.getDataByte(1); | |
148 libpd_controlchange(channel, controller, value); | |
149 break; | |
150 } | |
151 case kmmProgramChange: | |
152 { | |
153 int channel = message.getChannel(); | |
154 int program = message.getDataByte(0); | |
155 libpd_programchange(channel, program); | |
156 break; | |
157 } | |
158 case kmmPolyphonicKeyPressure: | |
159 { | |
160 int channel = message.getChannel(); | |
161 int pitch = message.getDataByte(0); | |
162 int value = message.getDataByte(1); | |
163 libpd_polyaftertouch(channel, pitch, value); | |
164 break; | |
165 } | |
166 case kmmChannelPressure: | |
167 { | |
168 int channel = message.getChannel(); | |
169 int value = message.getDataByte(0); | |
170 libpd_aftertouch(channel, value); | |
171 break; | |
172 } | |
173 case kmmPitchBend: | |
174 { | |
175 int channel = message.getChannel(); | |
176 int value = (message.getDataByte(1) << 7)| message.getDataByte(0); | |
177 libpd_pitchbend(channel, value); | |
178 break; | |
179 } | |
180 } | |
181 } | |
182 #else | |
183 int input; | |
184 while((input = midi.getInput()) >= 0){ | |
185 libpd_midibyte(0, input); | |
186 rt_printf("input: %d\n", input); | |
187 } | |
188 #endif /* PARSE_MIDI */ | |
140 static int inW = 0; | 189 static int inW = 0; |
141 static int outR = 0; | 190 static int outR = 0; |
142 /* | 191 /* |
143 * NOTE: if you are only using audio (or only analogs) and you are using interleaved buffers | 192 * NOTE: if you are only using audio (or only analogs) and you are using interleaved buffers |
144 * and the blocksize of Bela is the same as DEFDACBLKSIZE, then you probably | 193 * and the blocksize of Bela is the same as DEFDACBLKSIZE, then you probably |