Mercurial > hg > beaglert
comparison scripts/hvresources/heavy_render.cpp @ 487:7eefd4b3aec3 prerelease
Fixed and tested (for what possible) heavy Midi behaviour. Would be good to have abstraction wrappers for regular [pgmin] [polytouchin] [bendin] and [touchin]
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 21 Jun 2016 16:28:59 +0100 |
parents | 7f8d1a3e4cef |
children | 45dee9066d43 |
comparison
equal
deleted
inserted
replaced
486:7f8d1a3e4cef | 487:7eefd4b3aec3 |
---|---|
154 | 154 |
155 | 155 |
156 bool setup(BelaContext *context, void *userData) { | 156 bool setup(BelaContext *context, void *userData) { |
157 /* HEAVY */ | 157 /* HEAVY */ |
158 hvMidiHashes[kmmNoteOn] = hv_stringToHash("__hv_notein"); | 158 hvMidiHashes[kmmNoteOn] = hv_stringToHash("__hv_notein"); |
159 hvMidiHashes[kmmNoteOff] = hv_stringToHash("noteoff"); // this is handled differently, see the render function | 159 // hvMidiHashes[kmmNoteOff] = hv_stringToHash("noteoff"); // this is handled differently, see the render function |
160 hvMidiHashes[kmmControlChange] = hv_stringToHash("__hv_ctlin"); | 160 hvMidiHashes[kmmControlChange] = hv_stringToHash("__hv_ctlin"); |
161 hvMidiHashes[kmmProgramChange] = hv_stringToHash("pgmin"); | 161 // Note that the ones below are not defined by Heavy, but they are here for (wishing) forward-compatibility |
162 hvMidiHashes[kmmPolyphonicKeyPressure] = hv_stringToHash("polytouchin"); | 162 // You need to receive from the corresponding symbol in Pd and unpack the message, e.g.: |
163 hvMidiHashes[kmmChannelPressure] = hv_stringToHash("touchin"); | 163 //[r __hv_pgmin] |
164 hvMidiHashes[kmmPitchBend] = hv_stringToHash("bendin"); | 164 //| |
165 //[unpack f f] | |
166 //| | | |
167 //| [print pgmin_channel] | |
168 //[print pgmin_number] | |
169 hvMidiHashes[kmmProgramChange] = hv_stringToHash("__hv_pgmin"); | |
170 hvMidiHashes[kmmPolyphonicKeyPressure] = hv_stringToHash("__hv_polytouchin"); | |
171 hvMidiHashes[kmmChannelPressure] = hv_stringToHash("__hv_touch"); | |
172 hvMidiHashes[kmmPitchBend] = hv_stringToHash("__hv_bendin"); | |
165 | 173 |
166 gHeavyContext = hv_bbb_new(context->audioSampleRate); | 174 gHeavyContext = hv_bbb_new(context->audioSampleRate); |
167 | 175 |
168 gHvInputChannels = hv_getNumInputChannels(gHeavyContext); | 176 gHvInputChannels = hv_getNumInputChannels(gHeavyContext); |
169 gHvOutputChannels = hv_getNumOutputChannels(gHeavyContext); | 177 gHvOutputChannels = hv_getNumOutputChannels(gHeavyContext); |
225 while((num = midi.getParser()->numAvailableMessages()) > 0){ | 233 while((num = midi.getParser()->numAvailableMessages()) > 0){ |
226 static MidiChannelMessage message; | 234 static MidiChannelMessage message; |
227 message = midi.getParser()->getNextChannelMessage(); | 235 message = midi.getParser()->getNextChannelMessage(); |
228 switch(message.getType()){ | 236 switch(message.getType()){ |
229 case kmmNoteOn: { | 237 case kmmNoteOn: { |
230 // message.prettyPrint(); | 238 //message.prettyPrint(); |
231 float noteNumber = message.getDataByte(0); | 239 int noteNumber = message.getDataByte(0); |
232 float velocity = message.getDataByte(1); | 240 int velocity = message.getDataByte(1); |
233 float channel = message.getChannel(); | 241 int channel = message.getChannel(); |
234 // rt_printf("message: noteNumber: %f, velocity: %f, channel: %f\n", noteNumber, velocity, channel); | 242 // rt_printf("message: noteNumber: %f, velocity: %f, channel: %f\n", noteNumber, velocity, channel); |
235 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmNoteOn], 0, "fff", noteNumber, velocity, channel); | 243 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmNoteOn], 0, "fff", |
236 break; | 244 (float)noteNumber, (float)velocity, (float)channel); |
237 } | 245 break; |
238 case kmmNoteOff: | 246 } |
239 { | 247 case kmmNoteOff: { |
240 /* PureData does not seem to handle noteoff messages as per the MIDI specs, | 248 /* PureData does not seem to handle noteoff messages as per the MIDI specs, |
241 * so that the noteoff velocity is ignored. Here we convert them to noteon | 249 * so that the noteoff velocity is ignored. Here we convert them to noteon |
242 * with a velocity of 0. | 250 * with a velocity of 0. |
243 */ | 251 */ |
244 float noteNumber = message.getDataByte(0); | 252 int noteNumber = message.getDataByte(0); |
245 // int velocity = message.getDataByte(1); // would be ignored by Pd | 253 // int velocity = message.getDataByte(1); // would be ignored by Pd |
246 float channel = message.getChannel(); | 254 int channel = message.getChannel(); |
247 // note we are sending the below to hvHashes[kmmNoteOn] !! | 255 // note we are sending the below to hvHashes[kmmNoteOn] !! |
248 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmNoteOn], 0, "fff", noteNumber, 0, channel); | 256 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmNoteOn], 0, "fff", |
257 (float)noteNumber, (float)0, (float)channel); | |
249 break; | 258 break; |
250 } | 259 } |
251 case kmmControlChange: { | 260 case kmmControlChange: { |
261 message.prettyPrint(); | |
252 int channel = message.getChannel(); | 262 int channel = message.getChannel(); |
253 int controller = message.getDataByte(0); | 263 int controller = message.getDataByte(0); |
254 int value = message.getDataByte(1); | 264 int value = message.getDataByte(1); |
255 //TODO: maybe the order of the arguments is wrong here? | |
256 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmControlChange], 0, "fff", | 265 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmControlChange], 0, "fff", |
257 value, controller, channel); | 266 (float)value, (float)controller, (float)channel); |
258 break; | 267 break; |
259 } | 268 } |
260 case kmmProgramChange: { | 269 case kmmProgramChange: { |
261 int channel = message.getChannel(); | 270 int channel = message.getChannel(); |
262 int program = message.getDataByte(0); | 271 int program = message.getDataByte(0); |
263 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmProgramChange], 0, "ff", | 272 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmProgramChange], 0, "ff", |
264 program, channel); | 273 (float)program, (float)channel); |
265 //TODO: maybe the order of the arguments is wrong here? | |
266 break; | 274 break; |
267 } | 275 } |
268 case kmmPolyphonicKeyPressure: { | 276 case kmmPolyphonicKeyPressure: { |
277 //TODO: untested, I do not have anything with polyTouch... who does, anyhow? | |
269 int channel = message.getChannel(); | 278 int channel = message.getChannel(); |
270 int pitch = message.getDataByte(0); | 279 int pitch = message.getDataByte(0); |
271 int value = message.getDataByte(1); | 280 int value = message.getDataByte(1); |
272 //TODO: maybe the order of the arguments is wrong here? | |
273 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmPolyphonicKeyPressure], 0, "fff", | 281 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmPolyphonicKeyPressure], 0, "fff", |
274 channel, pitch, value); | 282 (float)channel, (float)pitch, (float)value); |
275 break; | 283 break; |
276 } | 284 } |
277 case kmmChannelPressure: | 285 case kmmChannelPressure: |
278 { | 286 { |
287 //TODO: untested, I do not have anything with aftertouch... | |
279 int channel = message.getChannel(); | 288 int channel = message.getChannel(); |
280 int value = message.getDataByte(0); | 289 int value = message.getDataByte(0); |
281 //TODO: maybe the order of the arguments is wrong here? | 290 //TODO: maybe the order of the arguments is wrong here? |
282 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmChannelPressure], 0, "ff", | 291 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmChannelPressure], 0, "ff", |
283 channel, value); | 292 (float)channel, (float)value); |
284 break; | 293 break; |
285 } | 294 } |
286 case kmmPitchBend: | 295 case kmmPitchBend: |
287 { | 296 { |
297 //TODO: untested, I do not have anything with bend at the moment... | |
298 //TODO: check for both argument order and if the value range is correct? | |
288 int channel = message.getChannel(); | 299 int channel = message.getChannel(); |
289 int value = ((message.getDataByte(1) << 7) | message.getDataByte(0)) + 8192; | 300 int value = ((message.getDataByte(1) << 7) | message.getDataByte(0)) + 8192; |
290 //TODO: is the value range correct? | |
291 //TODO: maybe the order of the arguments is wrong here? | |
292 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmPitchBend], 0, "ff", | 301 hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmPitchBend], 0, "ff", |
293 channel, value); | 302 (float)channel, (float)value); |
294 break; | 303 break; |
295 } | 304 } |
296 case kmmNone: | 305 case kmmNone: |
297 case kmmAny: | 306 case kmmAny: |
298 break; | 307 break; |