| @@ -15,13 +15,13 @@ The 6 *switches*, *knobs* as well as the *lights* and *switchLights* can be conn | |||||
| - `[switch:N]` (with N from 1 to 6) has to be used in a `button` or `checkbox` item to connect it to the prototype interface switch number N. Pushed buttons will become red when on, and checkboxes will become white when on. | - `[switch:N]` (with N from 1 to 6) has to be used in a `button` or `checkbox` item to connect it to the prototype interface switch number N. Pushed buttons will become red when on, and checkboxes will become white when on. | ||||
| - `[knob:N]` (with N from 1 to 6) has to be used in a `vslider`, `hslider` or `nentry` item to connect it to the prototype interface knob number N. The knob [0..1] range will be mapped to the slider/nentry [min..max] range. | - `[knob:N]` (with N from 1 to 6) has to be used in a `vslider`, `hslider` or `nentry` item to connect it to the prototype interface knob number N. The knob [0..1] range will be mapped to the slider/nentry [min..max] range. | ||||
| - `[light_red|green|red:N]` (with N from 1 to 6) has to be used in a `vbargraph` or `hbargraph` item to connect it to the prototype interface light number N. | |||||
| - `[switchlight_red|green|red:N]` (with N from 1 to 6) has to be used in a `vbargraph` or `hbargraph` to connect it to the prototype interface switchLight number N. | |||||
| - `[light_red:N|light_green:N|light_blue:N]` (with N from 1 to 6) has to be used in a `vbargraph` or `hbargraph` item to connect it to the prototype interface light number N. | |||||
| - `[switchlight_red:N|switchlight_green:N|switchlight_blue:N]` (with N from 1 to 6) has to be used in a `vbargraph` or `hbargraph` to connect it to the prototype interface switchLight number N. | |||||
| Other metadata: | Other metadata: | ||||
| - `[scale:lin|log|exp]` metadata is implemented. | - `[scale:lin|log|exp]` metadata is implemented. | ||||
| The [faust_libraries/rack.lib](https://github.com/sletz/VCV-Prototype/blob/master/faust_libraries/rack.lib) Faust library contains usefull functions to convert VC signals, and can be enriched if needed. | |||||
| The [res/faust/rack.lib](https://github.com/VCVRack/VCV-Prototype/blob/faust/res/faust/rack.lib) Faust library contains usefull functions to convert VC signals, and can be enriched if needed. | |||||
| ## DSP examples | ## DSP examples | ||||
| @@ -0,0 +1,15 @@ | |||||
| // Simplest possible script using all variables | |||||
| import("stdfaust.lib"); | |||||
| // Switch button | |||||
| switch(i) = button("switch%i [switch:%i]"); | |||||
| // Highlight in red | |||||
| light_red(i) = hbargraph("[light_red:%i]", 0, 1); | |||||
| // Gain slider | |||||
| gain(i) = hslider("gain%i [knob:%i]", 0.1, 0, 1, 0.01); | |||||
| process(x) = par(i, 6, x * gain(i+1) * (1-switch(i+1)) : light_red(i+1)); | |||||
| @@ -0,0 +1,54 @@ | |||||
| // Rainbow RGB LED example | |||||
| import("stdfaust.lib"); | |||||
| // From https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB | |||||
| hsvToRgb(h, s, v) = r, g, b | |||||
| with { | |||||
| h1 = h * 6; | |||||
| c1 = v * s; | |||||
| v1 = v; | |||||
| x = c1 * (1 - abs(h1 % 2 - 1)); | |||||
| r1 = ba.if((h1 < 1), c1, | |||||
| ba.if((h1 < 2), x, | |||||
| ba.if((h1 < 3), 0, | |||||
| ba.if((h1 < 4), 0, | |||||
| ba.if((h1 < 5), x, c1))))); | |||||
| g1 = ba.if((h1 < 1), x, | |||||
| ba.if((h1 < 2), c1, | |||||
| ba.if((h1 < 3), c1, | |||||
| ba.if((h1 < 4), x, | |||||
| ba.if((h1 < 5), 0, 0))))); | |||||
| b1 = ba.if((h1 < 1), 0, | |||||
| ba.if((h1 < 2), 0, | |||||
| ba.if((h1 < 3), x, | |||||
| ba.if((h1 < 4), c1, | |||||
| ba.if((h1 < 5), c1, x))))); | |||||
| m = v1 - c1; | |||||
| r = r1 + m; | |||||
| g = g1 + m; | |||||
| b = b1 + m; | |||||
| }; | |||||
| process = par(i, 6, out(i+1)) | |||||
| with { | |||||
| phasor(freq) = freq/ma.SR : (+ : decimal) ~ _ with { decimal(x) = x-int(x); }; | |||||
| out(i) = (sin(2 * ma.PI * h) * 5 + 5) <: (red(i), green(i), blue(i)) :> _ | |||||
| with { | |||||
| h = (1 - i / 6 + phase) % 1; | |||||
| rgb = hsvToRgb(h, 1, 1); | |||||
| r = rgb : _,!,!; | |||||
| g = rgb : !,_,!; | |||||
| b = rgb : !,!,_; | |||||
| red(i,x) = attach(x, r : hbargraph("r1%i [switchlight_red:%i]", 0, 1) : hbargraph("r2%i [light_red:%i]", 0, 1)); | |||||
| green(i,x) = attach(x, g : hbargraph("g1%i [switchlight_green:%i]", 0, 1) : hbargraph("g2%i [light_green:%i]", 0, 1)); | |||||
| blue(i,x) = attach(x, b : hbargraph("b1%i [switchlight_blue:%i]", 0, 1) : hbargraph("b2%i [light_blue:%i]", 0, 1)); | |||||
| phase = phasor(0.5); | |||||
| }; | |||||
| }; | |||||
| @@ -0,0 +1,22 @@ | |||||
| // Import libraries | |||||
| import("stdfaust.lib"); | |||||
| import("rack.lib"); | |||||
| // Switch button | |||||
| switch(i) = button("switch%i [switch:%i]"); | |||||
| // Param slider | |||||
| param(i) = hslider("param%i [knob:%i]", 0.1, 0, 1, 0.01); | |||||
| // Highlight | |||||
| l_red(i) = hbargraph("[light_red:%i]", 0, 1); | |||||
| l_green(i) = hbargraph("[light_green:%i]", 0, 1); | |||||
| l_blue(i) = hbargraph("[light_blue:%i]", 0, 1); | |||||
| swl_red(i) = hbargraph("[switchlight_red:%i]", 0, 1); | |||||
| swl_green(i) = hbargraph("[switchlight_green:%i]", 0, 1); | |||||
| swl_blue(i) = hbargraph("[switchlight_blue:%i]", 0, 1); | |||||
| // Process definition | |||||
| process = par(i, 6, _); | |||||
| @@ -0,0 +1,16 @@ | |||||
| // Voltage-controlled oscillator example | |||||
| import("stdfaust.lib"); | |||||
| // Create a phasor with a given frequency | |||||
| phasor(freq) = freq/ma.SR : (+ : decimal) ~ _ with { decimal(x) = x-int(x); }; | |||||
| // Pitch to freq conversion (also included in the rack.lib library) | |||||
| cv_pitch2freq(cv_pitch) = 440 * 2 ^ (cv_pitch - 0.75); | |||||
| gain = hslider("gain [knob:1]", 0.1, 0, 1, 0.01) * 10 - 5; | |||||
| pitch(x) = x + gain; | |||||
| process(x) = sin(2 * ma.PI * phasor(cv_pitch2freq(pitch(x)))) * 5; | |||||