diff --git a/examples/organ.dsp b/examples/organ.dsp new file mode 100644 index 0000000..3763da0 --- /dev/null +++ b/examples/organ.dsp @@ -0,0 +1,24 @@ +import("stdfaust.lib"); +import("rack.lib"); + +vol = hslider("vol [knob:1]", 0.3, 0, 10, 0.01); +pan = hslider("pan [knob:2]", 0.5, 0, 1, 0.01); + +attack = hslider("attack", 0.01, 0, 1, 0.001); +decay = hslider("decay", 0.3, 0, 1, 0.001); +sustain = hslider("sustain", 0.5, 0, 1, 0.01); +release = hslider("release", 0.2, 0, 1, 0.001); + +panner(c) = _ <: *(1-c), *(c); + +voice(freq) = os.osc(freq) + 0.5*os.osc(2*freq) + 0.25*os.osc(3*freq); + +/* +Additive synth: 3 sine oscillators with adsr envelop. +Use the 3 first VC inputs to control pitch, gate and velocity. +*/ + +process(pitch, gate, vel) = voice(freq) * en.adsr(attack, decay, sustain, release, gate) * vel : *(vol) : panner(pan) +with { + freq = cv_pitch2freq(pitch); +}; \ No newline at end of file diff --git a/examples/test1.dsp b/examples/test1.dsp new file mode 100644 index 0000000..7516467 --- /dev/null +++ b/examples/test1.dsp @@ -0,0 +1,32 @@ + +import("stdfaust.lib"); +import("rack.lib"); + +// Using knobs (from 1 to 6). Knob [0..1] range is mapped on [min..max] slider range, taking 'scale' metadata in account + +vol1 = hslider("volume1 [knob:1]", 0.1, 0, 1, 0.01); +freq1 = hslider("freq1 [knob:2] [unit:Hz] [scale:lin]", 300, 200, 300, 1); + +vol2 = hslider("volume2 [knob:3]", 0.1, 0, 1, 0.01); +freq2 = hslider("freq2 [knob:4] [unit:Hz] ", 300, 200, 300, 1); + +// Using switches (from 1 to 6) + +gate = button("gate [switch:1]"); + +// Using bargraph to control leds (from 1 to 6 with 3 colors) + +led_1_r = vbargraph("[led_red:1]", 0, 1); +led_1_g = vbargraph("[led_green:1]", 0, 1); +led_1_b = vbargraph("[led_blue:1]", 0, 1); + +// Using bargraph to control switch leds (from 1 to 6 with 3 colors) + +switch_2_r = vbargraph("[switch_red:2]", 0, 1); +switch_2_g = vbargraph("[switch_green:2]", 0, 1); +switch_2_b = vbargraph("[switch_blue:2]", 0, 1); + +process = os.osc(freq1) * vol1, + os.sawtooth(freq2) * vol2 * gate, + (os.osc(1):led_1_r + os.osc(1.4):led_1_g + os.osc(1.7):led_1_b), + (os.osc(1):switch_2_r + os.osc(1.2):switch_2_g + os.osc(1.7):switch_2_b); diff --git a/src/FaustEngine.cpp b/src/FaustEngine.cpp index e302a39..1f70208 100644 --- a/src/FaustEngine.cpp +++ b/src/FaustEngine.cpp @@ -37,12 +37,22 @@ extern rack::Plugin* pluginInstance; // UI handler for switches, knobs and leds struct RackUI : public GenericUI { + // 0|1 switches FAUSTFLOAT* fSwitches[NUM_ROWS]; + + // Knobs with [0..1] <==> [min..max] mapping and medata 'scale' handling ConverterZoneControl* fKnobs[NUM_ROWS]; + + // Leds FAUSTFLOAT* fLedRed[NUM_ROWS]; FAUSTFLOAT* fLedGreen[NUM_ROWS]; FAUSTFLOAT* fLedBlue[NUM_ROWS]; + // Switch Leds + FAUSTFLOAT* fSwitchRed[NUM_ROWS]; + FAUSTFLOAT* fSwitchGreen[NUM_ROWS]; + FAUSTFLOAT* fSwitchBlue[NUM_ROWS]; + std::string fKey, fValue, fScale; void addItem(FAUSTFLOAT* table[NUM_ROWS], FAUSTFLOAT* zone, const std::string& value) @@ -91,6 +101,9 @@ struct RackUI : public GenericUI fLedRed[i] = nullptr; fLedGreen[i] = nullptr; fLedBlue[i] = nullptr; + fSwitchRed[i] = nullptr; + fSwitchGreen[i] = nullptr; + fSwitchBlue[i] = nullptr; } } @@ -131,6 +144,12 @@ struct RackUI : public GenericUI addItem(fLedGreen, zone, fValue); } else if (fKey == "led_blue") { addItem(fLedBlue, zone, fValue); + } else if (fKey == "switch_red") { + addItem(fSwitchRed, zone, fValue); + } else if (fKey == "switch_green") { + addItem(fSwitchGreen, zone, fValue); + } else if (fKey == "switch_blue") { + addItem(fSwitchBlue, zone, fValue); } } @@ -149,7 +168,10 @@ struct RackUI : public GenericUI || (std::string(key) == "knob") || (std::string(key) == "led_red") || (std::string(key) == "led_green") - || (std::string(key) == "led_blue")) { + || (std::string(key) == "led_blue") + || (std::string(key) == "switch_red") + || (std::string(key) == "switch_green") + || (std::string(key) == "switch_blue")) { fKey = key; fValue = val; } else if (std::string(key) == "scale") { @@ -208,7 +230,7 @@ class FaustEngine : public ScriptEngine { fDSPFactory = createDSPFactoryFromString("FaustDSP", script, argc, argv, "", error_msg, -1); if (!fDSPFactory) { display("ERROR : cannot create factory !"); - std::cerr << error_msg; + WARN("Faust Prototype : %s", error_msg.c_str()); return -1; } else { // And save the cache @@ -294,6 +316,15 @@ class FaustEngine : public ScriptEngine { if (fRackUI.fLedBlue[i]) { block->lights[i][2] = *fRackUI.fLedBlue[i]; } + if (fRackUI.fSwitchRed[i]) { + block->switchLights[i][0] = *fRackUI.fSwitchRed[i]; + } + if (fRackUI.fSwitchGreen[i]) { + block->switchLights[i][1] = *fRackUI.fSwitchGreen[i]; + } + if (fRackUI.fSwitchBlue[i]) { + block->switchLights[i][2] = *fRackUI.fSwitchBlue[i]; + } } return 0;