giuliomoro coming back to the heavy lv2 custom render file i have a strange behaviour that you maybe can explain?
if i run this simple test patch:
/*
____ _____ _ _
| __ )| ____| | / \
| _ \| _| | | / _ \
| |_) | |___| |___ / ___ \
|____/|_____|_____/_/ \_\
The platform for ultra-low latency audio and sensor processing
http://bela.io
A project of the Augmented Instruments Laboratory within the
Centre for Digital Music at Queen Mary University of London.
http://www.eecs.qmul.ac.uk/~andrewm
(c) 2016 Augmented Instruments Laboratory: Andrew McPherson,
Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack,
Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved.
The Bela software is distributed under the GNU Lesser General Public License
(LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt
*/
#include <Bela.h>
int gCount = 0; //counts elapsed samples
int tap = 0; //count taps
#define DEBOUNCE_TIME 40 //how long the button has to be "off" to be considered off
bool cState_b0 = 0;
bool cState_b1 = 0;
bool pState_b0 = 1;
bool pState_b1 = 1;
int debounce_b0 = 0;
int debounce_b1 = 0;
int switch_fx = 0;
int old_fx = 1;
bool setup(BelaContext *context, void *userData)
{
pinMode(context,0,1, OUTPUT); // LED1
pinMode(context,0,2, OUTPUT); // LED2
pinMode(context,0,3, INPUT); //Button 1
pinMode(context,0,4, INPUT); //Button 2
return true;
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->digitalFrames; ++n){
cState_b0 = digitalRead(context, n, 4);
cState_b1 = digitalRead(context, n, 3);
gCount++;
}
if (gCount > 100000*(tap+1)) tap = 0;
if (!cState_b0 && pState_b0) {
switch_fx = (switch_fx + 1)%3;
}
if (cState_b0 && !pState_b0) {
if (debounce_b0 < DEBOUNCE_TIME) {
debounce_b0++;
cState_b0 = 0;
} else debounce_b0 = 0;
}
pState_b0 = cState_b0;
if (!cState_b1 && pState_b1) {
//taptempo
if (!tap) gCount = 0;
tap = tap + 1;
if (tap == 5) {
tap = 0;
float tempo = 240.0/float(gCount/context->digitalSampleRate);
rt_printf("tempo: %f\n", tempo);
}
}
if (cState_b1 && !pState_b1) {
if (debounce_b1 < DEBOUNCE_TIME) {
debounce_b1++;
cState_b1 = 0;
} else debounce_b1 = 0;
}
pState_b1 = cState_b1;
if (switch_fx != old_fx) {
switch (switch_fx) {
case 0: {
digitalWrite(context, 0, 1, 1);
digitalWrite(context, 0, 2, 1);
break;
}
case 1: {
digitalWrite(context, 0, 1, 0);
digitalWrite(context, 0, 2, 1);
break;
}
case 2: {
digitalWrite(context, 0, 1, 1);
digitalWrite(context, 0, 2, 0);
break;
}
}
}
old_fx = switch_fx;
}
void cleanup(BelaContext *context, void *userData)
{
// Nothing to do here
}
everything works as expected, as i press the button either both, the left or the right LED are lit up to indicate at which switch_fx i am.
however if i run the same things in my big render.cpp file (the one with heavy and lv2) i put the above code into the heavy (default render() function). of course before my if statements that switch out the heavy and lv2 part.
now for the strange part:
the switching works just fine, but the LED's don't go dark when they should, they stay lit all the time albeit at a little different brightnesses depending on the value of switch_fx. as soon as i remove the if (switch_fx != old_fx) {
bracket around the digitalWrite part it works as expected, but it seems like a waste of CPU to run the digitalWrite even if nothing has changed. or is this just how it works? but why would it then work in the example patch by just writing once per change?