comparison examples/basic_libpd/render.cpp @ 357:f3dd39be15e4 prerelease

Cleanup
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 08 Jun 2016 22:03:50 +0100
parents bad8a536c157
children 6e428d6b57ef
comparison
equal deleted inserted replaced
356:44e4962ee37a 357:f3dd39be15e4
48 static AuxiliaryTask libpdReadFilesTask; 48 static AuxiliaryTask libpdReadFilesTask;
49 static Midi midi; 49 static Midi midi;
50 static DigitalChannelManager dcm; 50 static DigitalChannelManager dcm;
51 //UdpServer udpServer; 51 //UdpServer udpServer;
52 52
53
54
55 void sendDigitalMessage(bool state, unsigned int delay, void* receiverName){ 53 void sendDigitalMessage(bool state, unsigned int delay, void* receiverName){
56 libpd_float((char*)receiverName, (float)state); 54 libpd_float((char*)receiverName, (float)state);
57 // rt_printf("%s: %d\n", (char*)receiverName, state); 55 // rt_printf("%s: %d\n", (char*)receiverName, state);
58 } 56 }
59 57
97 dcm.manage(channel, direction, isMessageRate); 95 dcm.manage(channel, direction, isMessageRate);
98 } 96 }
99 } 97 }
100 98
101 void Bela_floatHook(const char *source, float value){ 99 void Bela_floatHook(const char *source, float value){
102 // rt_printf("received: %s %f\n", source, value);
103 // let's make this as optimized as possible for built-in digital Out parsing 100 // let's make this as optimized as possible for built-in digital Out parsing
104 // the built-in digital receivers are of the form "bela_digitalOutXX" where XX is between 11 and 26 101 // the built-in digital receivers are of the form "bela_digitalOutXX" where XX is between 11 and 26
105 static int prefixLength = 15; // strlen("bela_digitalOut") 102 static int prefixLength = 15; // strlen("bela_digitalOut")
106 if(strncmp(source, "bela_digitalOut", prefixLength)==0){ 103 if(strncmp(source, "bela_digitalOut", prefixLength)==0){
107 if(source[prefixLength] != 0){ //the two ifs are used instead of if(strlen(source) >= prefixLength+2) 104 if(source[prefixLength] != 0){ //the two ifs are used instead of if(strlen(source) >= prefixLength+2)
108 if(source[prefixLength + 1] != 0){ 105 if(source[prefixLength + 1] != 0){
109 // quickly convert the suffix to integer, assuming they are numbers, avoiding to call atoi 106 // quickly convert the suffix to integer, assuming they are numbers, avoiding to call atoi
110 int receiver = ((source[prefixLength] - 48) * 10); 107 int receiver = ((source[prefixLength] - 48) * 10);
111 receiver += (source[prefixLength+1] - 48); 108 receiver += (source[prefixLength+1] - 48);
112 // rt_printf("received on digital %d value %.0f\n", receiver, value);
113 unsigned int channel = receiver - 11; // go back to the actual Bela digital channel number 109 unsigned int channel = receiver - 11; // go back to the actual Bela digital channel number
114 if(channel >= 0 && channel < 16){ //16 is the hardcoded value for the number of digital channels 110 if(channel >= 0 && channel < 16){ //16 is the hardcoded value for the number of digital channels
115 //TODO: here we should check if this channel has been registered as message-rate output
116 dcm.setValue(channel, value); 111 dcm.setValue(channel, value);
117 // rt_printf("clear 0x%x set 0x%x\n", clearDataOut, setDataOut);
118 } 112 }
119 } 113 }
120 } 114 }
121 } 115 }
122 } 116 }
163 libpd_set_floathook(Bela_floatHook); 157 libpd_set_floathook(Bela_floatHook);
164 libpd_set_messagehook(Bela_messageHook); 158 libpd_set_messagehook(Bela_messageHook);
165 libpd_set_noteonhook(pdnoteon); 159 libpd_set_noteonhook(pdnoteon);
166 //TODO: add hooks for other midi events and generate MIDI output appropriately 160 //TODO: add hooks for other midi events and generate MIDI output appropriately
167 libpd_init(); 161 libpd_init();
168 //TODO: ideally, we would analyse the ASCII of the patch file and find the in/outs to use 162 //TODO: ideally, we would analyse the ASCII of the patch file and find out which in/outs to use
169 libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate); 163 libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate);
170 gInBuf = libpd_get_sys_soundin(); 164 gInBuf = libpd_get_sys_soundin();
171 gOutBuf = libpd_get_sys_soundout(); 165 gOutBuf = libpd_get_sys_soundout();
172 166
173 libpd_start_message(1); // one entry in list 167 libpd_start_message(1); // one entry in list