diff examples/basic_libpd/render.cpp @ 354:1b23300f3e78 prerelease

DigitalChannelManager takes care of managing digital channels for libpd/Heavy use
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 08 Jun 2016 21:11:36 +0100
parents bec5d43e4e7a
children bad8a536c157
line wrap: on
line diff
--- a/examples/basic_libpd/render.cpp	Wed Jun 08 19:44:21 2016 +0100
+++ b/examples/basic_libpd/render.cpp	Wed Jun 08 21:11:36 2016 +0100
@@ -63,26 +63,27 @@
 	if(strcmp(source, "bela_setDigital") == 0){
 		// symbol is the direction, argv[0] is the channel, argv[1] (optional)
 		// is signal(\"sig\" or \"~\") or message(\"mess\", default) rate
-		bool error = false;
 		bool isMessageRate = true; // defaults to message rate
-		bool direction;
+		bool direction = 0; // initialize it just to avoid the compiler's warning
+		bool disable = false;
 		if(strcmp(symbol, "in") == 0){
 			direction = INPUT;
 		} else if(strcmp(symbol, "out") == 0){
 			direction = OUTPUT;
+		} else if(strcmp(symbol, "disable") == 0){
+			disable = true;
 		} else {
-			error = true;
+			return;
 		}
 		if(argc == 0){
-			error = true;
+			return;
 		} else if (libpd_is_float(&argv[0]) == false){
-			error = true;
-		}
-		if(error == true){
-			rt_printf("bela_setDigital requires at least [direction channel(\n");
 			return;
 		}
 		int channel = libpd_get_float(&argv[0]) - LIBPD_DIGITAL_OFFSET;
+		if(disable == true){
+			dcm.unmanage(channel);
+		}
 		if(argc >= 2){
 			t_atom* a = &argv[1];
 			if(libpd_is_symbol(a)){
@@ -92,7 +93,7 @@
 				}
 			}
 		}
-		dcm.setPinMode(channel, direction, isMessageRate);
+		dcm.manage(channel, direction, isMessageRate);
 	}
 }
 
@@ -111,7 +112,7 @@
 				unsigned int channel = receiver - 11; // go back to the actual Bela digital channel number
 				if(channel >= 0 && channel < 16){ //16 is the hardcoded value for the number of digital channels
 					//TODO: here we should check if this channel has been registered as message-rate output
-					dcm.setOutput(channel, value);
+					dcm.setValue(channel, value);
 //					rt_printf("clear 0x%x set 0x%x\n", clearDataOut, setDataOut);
 				}
 			}
@@ -372,6 +373,7 @@
 				audioWrite(context, audioFrameBase + j, k, *p1);
 			}
 		}
+
 		//analog
 		if(context->analogChannels == 8){
 			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames