changeset 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 441c8429f27c
files scripts/hvresources/heavy_render.cpp
diffstat 1 files changed, 34 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/hvresources/heavy_render.cpp	Tue Jun 21 15:18:13 2016 +0100
+++ b/scripts/hvresources/heavy_render.cpp	Tue Jun 21 16:28:59 2016 +0100
@@ -156,12 +156,20 @@
 bool setup(BelaContext *context, void *userData)	{
 	/* HEAVY */
 	hvMidiHashes[kmmNoteOn] = hv_stringToHash("__hv_notein");
-	hvMidiHashes[kmmNoteOff] = hv_stringToHash("noteoff"); // this is handled differently, see the render function
+//	hvMidiHashes[kmmNoteOff] = hv_stringToHash("noteoff"); // this is handled differently, see the render function
 	hvMidiHashes[kmmControlChange] = hv_stringToHash("__hv_ctlin");
-	hvMidiHashes[kmmProgramChange] = hv_stringToHash("pgmin");
-	hvMidiHashes[kmmPolyphonicKeyPressure] = hv_stringToHash("polytouchin");
-	hvMidiHashes[kmmChannelPressure] = hv_stringToHash("touchin");
-	hvMidiHashes[kmmPitchBend] = hv_stringToHash("bendin");
+	// Note that the ones below are not defined by Heavy, but they are here for (wishing) forward-compatibility
+	// You need to receive from the corresponding symbol in Pd and unpack the message, e.g.:
+	//[r __hv_pgmin]
+	//|
+	//[unpack f f]
+	//|   |
+	//|   [print pgmin_channel]
+	//[print pgmin_number]
+	hvMidiHashes[kmmProgramChange] = hv_stringToHash("__hv_pgmin");
+	hvMidiHashes[kmmPolyphonicKeyPressure] = hv_stringToHash("__hv_polytouchin");
+	hvMidiHashes[kmmChannelPressure] = hv_stringToHash("__hv_touch");
+	hvMidiHashes[kmmPitchBend] = hv_stringToHash("__hv_bendin");
 
 	gHeavyContext = hv_bbb_new(context->audioSampleRate);
 
@@ -227,70 +235,71 @@
 			message = midi.getParser()->getNextChannelMessage();
 			switch(message.getType()){
 			case kmmNoteOn: {
-				// message.prettyPrint();
-				float noteNumber = message.getDataByte(0);
-				float velocity = message.getDataByte(1);
-				float channel = message.getChannel();
+				//message.prettyPrint();
+				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);
-				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmNoteOn], 0, "fff", noteNumber, velocity, channel);
+				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmNoteOn], 0, "fff",
+						(float)noteNumber, (float)velocity, (float)channel);
 				break;
 			}
-			case kmmNoteOff:
-			{
+			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.
 				 */
-				float noteNumber = message.getDataByte(0);
+				int noteNumber = message.getDataByte(0);
 				// int velocity = message.getDataByte(1); // would be ignored by Pd
-				float channel = message.getChannel();
+				int channel = message.getChannel();
 				// note we are sending the below to hvHashes[kmmNoteOn] !!
-				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmNoteOn], 0, "fff", noteNumber, 0, channel);
+				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmNoteOn], 0, "fff",
+						(float)noteNumber, (float)0, (float)channel);
 				break;
 			}
 			case kmmControlChange: {
+				message.prettyPrint();
 				int channel = message.getChannel();
 				int controller = message.getDataByte(0);
 				int value = message.getDataByte(1);
-				//TODO: maybe the order of the arguments is wrong here?
 				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmControlChange], 0, "fff",
-						value, controller, channel);
+						(float)value, (float)controller, (float)channel);
 				break;
 			}
 			case kmmProgramChange: {
 				int channel = message.getChannel();
 				int program = message.getDataByte(0);
 				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmProgramChange], 0, "ff",
-						program, channel);
-				//TODO: maybe the order of the arguments is wrong here?
+						(float)program, (float)channel);
 				break;
 			}
 			case kmmPolyphonicKeyPressure: {
+				//TODO: untested, I do not have anything with polyTouch... who does, anyhow?
 				int channel = message.getChannel();
 				int pitch = message.getDataByte(0);
 				int value = message.getDataByte(1);
-				//TODO: maybe the order of the arguments is wrong here?
 				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmPolyphonicKeyPressure], 0, "fff",
-						channel, pitch, value);
+						(float)channel, (float)pitch, (float)value);
 				break;
 			}
 			case kmmChannelPressure:
 			{
+				//TODO: untested, I do not have anything with aftertouch...
 				int channel = message.getChannel();
 				int value = message.getDataByte(0);
 				//TODO: maybe the order of the arguments is wrong here?
 				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmChannelPressure], 0, "ff",
-						channel, value);
+						(float)channel, (float)value);
 				break;
 			}
 			case kmmPitchBend:
 			{
+				//TODO: untested, I do not have anything with bend at the moment...
+				//TODO: check for both argument order and if the value range is correct?
 				int channel = message.getChannel();
 				int value = ((message.getDataByte(1) << 7) | message.getDataByte(0)) + 8192;
-				//TODO: is the value range correct?
-				//TODO: maybe the order of the arguments is wrong here?
 				hv_vscheduleMessageForReceiver(gHeavyContext, hvMidiHashes[kmmPitchBend], 0, "ff",
-						channel, value);
+						(float)channel, (float)value);
 				break;
 			}
 			case kmmNone: