comparison 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
comparison
equal deleted inserted replaced
353:bec5d43e4e7a 354:1b23300f3e78
61 61
62 void Bela_messageHook(const char *source, const char *symbol, int argc, t_atom *argv){ 62 void Bela_messageHook(const char *source, const char *symbol, int argc, t_atom *argv){
63 if(strcmp(source, "bela_setDigital") == 0){ 63 if(strcmp(source, "bela_setDigital") == 0){
64 // symbol is the direction, argv[0] is the channel, argv[1] (optional) 64 // symbol is the direction, argv[0] is the channel, argv[1] (optional)
65 // is signal(\"sig\" or \"~\") or message(\"mess\", default) rate 65 // is signal(\"sig\" or \"~\") or message(\"mess\", default) rate
66 bool error = false;
67 bool isMessageRate = true; // defaults to message rate 66 bool isMessageRate = true; // defaults to message rate
68 bool direction; 67 bool direction = 0; // initialize it just to avoid the compiler's warning
68 bool disable = false;
69 if(strcmp(symbol, "in") == 0){ 69 if(strcmp(symbol, "in") == 0){
70 direction = INPUT; 70 direction = INPUT;
71 } else if(strcmp(symbol, "out") == 0){ 71 } else if(strcmp(symbol, "out") == 0){
72 direction = OUTPUT; 72 direction = OUTPUT;
73 } else if(strcmp(symbol, "disable") == 0){
74 disable = true;
73 } else { 75 } else {
74 error = true; 76 return;
75 } 77 }
76 if(argc == 0){ 78 if(argc == 0){
77 error = true; 79 return;
78 } else if (libpd_is_float(&argv[0]) == false){ 80 } else if (libpd_is_float(&argv[0]) == false){
79 error = true;
80 }
81 if(error == true){
82 rt_printf("bela_setDigital requires at least [direction channel(\n");
83 return; 81 return;
84 } 82 }
85 int channel = libpd_get_float(&argv[0]) - LIBPD_DIGITAL_OFFSET; 83 int channel = libpd_get_float(&argv[0]) - LIBPD_DIGITAL_OFFSET;
84 if(disable == true){
85 dcm.unmanage(channel);
86 }
86 if(argc >= 2){ 87 if(argc >= 2){
87 t_atom* a = &argv[1]; 88 t_atom* a = &argv[1];
88 if(libpd_is_symbol(a)){ 89 if(libpd_is_symbol(a)){
89 char *s = libpd_get_symbol(a); 90 char *s = libpd_get_symbol(a);
90 if(strcmp(s, "~") == 0 || strncmp(s, "sig", 3) == 0){ 91 if(strcmp(s, "~") == 0 || strncmp(s, "sig", 3) == 0){
91 isMessageRate = false; 92 isMessageRate = false;
92 } 93 }
93 } 94 }
94 } 95 }
95 dcm.setPinMode(channel, direction, isMessageRate); 96 dcm.manage(channel, direction, isMessageRate);
96 } 97 }
97 } 98 }
98 99
99 void Bela_floatHook(const char *source, float value){ 100 void Bela_floatHook(const char *source, float value){
100 // rt_printf("received: %s %f\n", source, value); 101 // rt_printf("received: %s %f\n", source, value);
109 receiver += (source[prefixLength+1] - 48); 110 receiver += (source[prefixLength+1] - 48);
110 // rt_printf("received on digital %d value %.0f\n", receiver, value); 111 // rt_printf("received on digital %d value %.0f\n", receiver, value);
111 unsigned int channel = receiver - 11; // go back to the actual Bela digital channel number 112 unsigned int channel = receiver - 11; // go back to the actual Bela digital channel number
112 if(channel >= 0 && channel < 16){ //16 is the hardcoded value for the number of digital channels 113 if(channel >= 0 && channel < 16){ //16 is the hardcoded value for the number of digital channels
113 //TODO: here we should check if this channel has been registered as message-rate output 114 //TODO: here we should check if this channel has been registered as message-rate output
114 dcm.setOutput(channel, value); 115 dcm.setValue(channel, value);
115 // rt_printf("clear 0x%x set 0x%x\n", clearDataOut, setDataOut); 116 // rt_printf("clear 0x%x set 0x%x\n", clearDataOut, setDataOut);
116 } 117 }
117 } 118 }
118 } 119 }
119 } 120 }
370 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) { 371 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
371 for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) { 372 for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
372 audioWrite(context, audioFrameBase + j, k, *p1); 373 audioWrite(context, audioFrameBase + j, k, *p1);
373 } 374 }
374 } 375 }
376
375 //analog 377 //analog
376 if(context->analogChannels == 8){ 378 if(context->analogChannels == 8){
377 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames 379 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames
378 unsigned int analogFrame = (audioFrameBase + j) / 2; 380 unsigned int analogFrame = (audioFrameBase + j) / 2;
379 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) { 381 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {