Skip to content
Permalink
Browse files

Correct OSC and MIDI in Bela architecture.

  • Loading branch information
sletz committed Dec 1, 2019
1 parent 54ead80 commit c2a6f90c50b1815e0e9d8eddcaec8640148856a4
@@ -63,7 +63,6 @@ using namespace std;

// for OSC support
#ifdef OSCCTRL
#include "faust/gui/OSCUI.h"
#include "faust/gui/BelaOSCUI.h"
#endif

@@ -174,88 +173,88 @@ enum EInOutPin
class BelaWidget
{

protected:

EInOutPin fBelaPin;
FAUSTFLOAT* fZone; // zone
const char* fLabel; // label
FAUSTFLOAT fMin; // minimal value
FAUSTFLOAT fRange; // value range (max-min)

public:

BelaWidget()
:fBelaPin(kNoPin)
,fZone(0)
,fLabel("")
,fMin(0)
,fRange(1)
{}

BelaWidget(const BelaWidget& w)
:fBelaPin(w.fBelaPin)
,fZone(w.fZone)
,fLabel(w.fLabel)
,fMin(w.fMin)
,fRange(w.fRange)
{}

BelaWidget(EInOutPin pin, FAUSTFLOAT* z, const char* l, FAUSTFLOAT lo, FAUSTFLOAT hi)
:fBelaPin(pin)
,fZone(z)
,fLabel(l)
,fMin(lo)
,fRange(hi-lo)
{}

void update(BelaContext* context)
{
switch(fBelaPin) {
case kANALOG_0:
case kANALOG_1:
case kANALOG_2:
case kANALOG_3:
case kANALOG_4:
case kANALOG_5:
case kANALOG_6:
case kANALOG_7:
*fZone = fMin + fRange * analogReadNI(context, 0, (int)fBelaPin);
break;

case kDIGITAL_0:
case kDIGITAL_1:
case kDIGITAL_2:
case kDIGITAL_3:
case kDIGITAL_4:
case kDIGITAL_5:
case kDIGITAL_6:
case kDIGITAL_7:
case kDIGITAL_8:
case kDIGITAL_9:
case kDIGITAL_10:
case kDIGITAL_11:
case kDIGITAL_12:
case kDIGITAL_13:
case kDIGITAL_14:
case kDIGITAL_15:
*fZone = digitalRead(context, 0, ((int)fBelaPin - kDIGITAL_0)) == 0 ? fMin : fMin+fRange;
break;

case kANALOG_OUT_0:
case kANALOG_OUT_1:
case kANALOG_OUT_2:
case kANALOG_OUT_3:
case kANALOG_OUT_4:
case kANALOG_OUT_5:
case kANALOG_OUT_6:
case kANALOG_OUT_7:
analogWriteNI(context, 0, ((int)fBelaPin) - kANALOG_OUT_0, (*fZone - fMin)/(fRange+fMin));
break;

default:
break;
};
}
protected:
EInOutPin fBelaPin;
FAUSTFLOAT* fZone; // zone
const char* fLabel; // label
FAUSTFLOAT fMin; // minimal value
FAUSTFLOAT fRange; // value range (max-min)
public:
BelaWidget()
:fBelaPin(kNoPin)
,fZone(0)
,fLabel("")
,fMin(0)
,fRange(1)
{}
BelaWidget(const BelaWidget& w)
:fBelaPin(w.fBelaPin)
,fZone(w.fZone)
,fLabel(w.fLabel)
,fMin(w.fMin)
,fRange(w.fRange)
{}
BelaWidget(EInOutPin pin, FAUSTFLOAT* z, const char* l, FAUSTFLOAT lo, FAUSTFLOAT hi)
:fBelaPin(pin)
,fZone(z)
,fLabel(l)
,fMin(lo)
,fRange(hi-lo)
{}
void update(BelaContext* context)
{
switch(fBelaPin) {
case kANALOG_0:
case kANALOG_1:
case kANALOG_2:
case kANALOG_3:
case kANALOG_4:
case kANALOG_5:
case kANALOG_6:
case kANALOG_7:
*fZone = fMin + fRange * analogReadNI(context, 0, (int)fBelaPin);
break;
case kDIGITAL_0:
case kDIGITAL_1:
case kDIGITAL_2:
case kDIGITAL_3:
case kDIGITAL_4:
case kDIGITAL_5:
case kDIGITAL_6:
case kDIGITAL_7:
case kDIGITAL_8:
case kDIGITAL_9:
case kDIGITAL_10:
case kDIGITAL_11:
case kDIGITAL_12:
case kDIGITAL_13:
case kDIGITAL_14:
case kDIGITAL_15:
*fZone = digitalRead(context, 0, ((int)fBelaPin - kDIGITAL_0)) == 0 ? fMin : fMin+fRange;
break;
case kANALOG_OUT_0:
case kANALOG_OUT_1:
case kANALOG_OUT_2:
case kANALOG_OUT_3:
case kANALOG_OUT_4:
case kANALOG_OUT_5:
case kANALOG_OUT_6:
case kANALOG_OUT_7:
analogWriteNI(context, 0, ((int)fBelaPin) - kANALOG_OUT_0, (*fZone - fMin)/(fRange+fMin));
break;
default:
break;
};
}

};

@@ -276,61 +275,61 @@ class BelaWidget
class BelaUI : public GenericUI
{

private:

int fIndex; // number of BelaWidgets collected so far
EInOutPin fBelaPin; // current pin id
BelaWidget fTable[MAXBELAWIDGETS]; // kind of static list of BelaWidgets

// check if the widget is linked to a Bela parameter and, if so, add the corresponding BelaWidget
void addBelaWidget(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi)
{
if (fBelaPin != kNoPin && (fIndex < MAXBELAWIDGETS)) {
fTable[fIndex] = BelaWidget(fBelaPin, zone, label, lo, hi);
fIndex++;
private:

int fIndex; // number of BelaWidgets collected so far
EInOutPin fBelaPin; // current pin id
BelaWidget fTable[MAXBELAWIDGETS]; // kind of static list of BelaWidgets

// check if the widget is linked to a Bela parameter and, if so, add the corresponding BelaWidget
void addBelaWidget(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi)
{
if (fBelaPin != kNoPin && (fIndex < MAXBELAWIDGETS)) {
fTable[fIndex] = BelaWidget(fBelaPin, zone, label, lo, hi);
fIndex++;
}
fBelaPin = kNoPin;
}
fBelaPin = kNoPin;
}

public:

BelaUI()
: fIndex(0)
, fBelaPin(kNoPin)
{}

virtual ~BelaUI() {}

// should be called before compute() to update widget's zones registered as Bela parameters
void update(BelaContext* context)
{
for (int i = 0; i < fIndex; i++) {
fTable[i].update(context);

public:

BelaUI()
: fIndex(0)
, fBelaPin(kNoPin)
{}

virtual ~BelaUI() {}

// should be called before compute() to update widget's zones registered as Bela parameters
void update(BelaContext* context)
{
for (int i = 0; i < fIndex; i++) {
fTable[i].update(context);
}
}
}

// -- active widgets
virtual void addButton(const char* label, FAUSTFLOAT* zone) { addBelaWidget(label, zone, FAUSTFLOAT(0), FAUSTFLOAT(1)); }
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) { addBelaWidget(label, zone, FAUSTFLOAT(0), FAUSTFLOAT(1)); }
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step) { addBelaWidget(label, zone, lo, hi); }
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step) { addBelaWidget(label, zone, lo, hi); }
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step) { addBelaWidget(label, zone, lo, hi); }

// -- passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi) { addBelaWidget(label, zone, lo, hi); }
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi) { addBelaWidget(label, zone, lo, hi); }

// -- metadata declarations
virtual void declare(FAUSTFLOAT* z, const char* k, const char* id)
{
if (strcasecmp(k,"BELA") == 0) {
for (int i = 0; i < kNumInputPins; i++) {
if (strcasecmp(id, pinNamesStrings[i]) == 0) {
fBelaPin = (EInOutPin)i;
// -- active widgets
virtual void addButton(const char* label, FAUSTFLOAT* zone) { addBelaWidget(label, zone, FAUSTFLOAT(0), FAUSTFLOAT(1)); }
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) { addBelaWidget(label, zone, FAUSTFLOAT(0), FAUSTFLOAT(1)); }
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step) { addBelaWidget(label, zone, lo, hi); }
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step) { addBelaWidget(label, zone, lo, hi); }
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step) { addBelaWidget(label, zone, lo, hi); }
// -- passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi) { addBelaWidget(label, zone, lo, hi); }
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi) { addBelaWidget(label, zone, lo, hi); }
// -- metadata declarations
virtual void declare(FAUSTFLOAT* z, const char* k, const char* id)
{
if (strcasecmp(k,"BELA") == 0) {
for (int i = 0; i < kNumInputPins; i++) {
if (strcasecmp(id, pinNamesStrings[i]) == 0) {
fBelaPin = (EInOutPin)i;
}
}
}
}
}

};

@@ -505,10 +504,6 @@ bool setup(BelaContext* context, void* userData)

void render(BelaContext* context, void* userData)
{
// OSC event handling
#ifdef OSCCTRL
gOSCUI.scheduleOSC();
#endif
// Reads Bela pins and updates corresponding Faust Widgets zones
gControlUI.update(context);
// Synchronize all GUI controllers

0 comments on commit c2a6f90

Please sign in to comment.
You can’t perform that action at this time.