Developing Virtual Synthesizers with VCV Rack by Leonardo Gabrielli
Author:Leonardo Gabrielli [Leonardo Gabrielli]
Language: eng
Format: epub
Publisher: Focal Press
Published: 2020-02-06T16:00:00+00:00
As with lights and ports, the set/get methods return or set the value of the parameter. While the latter is of use in some special cases (e.g. when you reset or randomize the parameter), you will use the getValue() most of the time to read any change in the value from the user input.
The parameters are added to the ModuleWidget subclass to indicate their position and bind them to one of the parameters in the enum ParamIds. Let us look at this example:
addParam(createParam<ParameterType>(Vec(X, Y), module, MyModule::OUTPUT_GAIN));
The details you have to input in this line are the ParameterType (i.e. the name of a class defining the graphical aspect and other properties of the object, the positioning coordinates X and Y, and the parameter from the enum ParamIds of the Module struct to which you bind this parameter).
The last bit of information to give to the system is the value mapping and a couple of strings. All these are set through the configParam method, which goes into the Module constructor. One example follows:
configParam(OUTPUT_GAIN, 0.f, 2.f, 1.f, “Volume”);
In this case, we are telling the Module that the knob or slider related to the parameter OUTPUT_GAIN should go from 0 to 2, and by default (initialization) will be 1. The string to associate to it when right-clicking is “Volume.” Further arguments allow you to make this more powerful, but we’ll see this later in this chapter.
Now let us move through the implementation of the whole module, AMuxDemux. The module will host both mux and demux sections, and thus two selector knobs will be necessary. We shall have four inputs for the mux and four outputs for the demux. We shall also place light indicators near each of the selectable inputs for the mux, and near each of the selectable outputs for the demux.
In our case, if we define the enums as:
enum ParamIds { M_SELECTOR_PARAM, D_SELECTOR_PARAM, NUM_PARAMS, }; enum InputIds { M_INPUT_1, M_INPUT_2, M_INPUT_3, M_INPUT_4, D_MAIN_IN, NUM_INPUTS, N_MUX_IN = M_INPUT_4, }; enum OutputIds { D_OUTPUT_1, D_OUTPUT_2, D_OUTPUT_3, D_OUTPUT_4, M_MAIN_OUT, NUM_OUTPUTS, N_DEMUX_OUT = D_OUTPUT_4, };
enum LightsIds { M_LIGHT_1, M_LIGHT_2, M_LIGHT_3, M_LIGHT_4, D_LIGHT_1, D_LIGHT_2, D_LIGHT_3, D_LIGHT_4, NUM_LIGHTS, };
we declare two integer variables to hold the two selector values. To make their values consistent across each step of the process(…) method, we declare them as members of the AMuxDemux struct:
unsigned int selMux, selDemux;
They are zeroed in the Module constructor, where the value mapping of the selectors is also defined:
AMuxDemux() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); configParam(M_SELECTOR_PARAM, 0.0, 3.0, 0.0, “Mux Selector"); configParam(D_SELECTOR_PARAM, 0.0, 3.0, 0.0, “Demux Selector"); selMux = selDemux = 0; }
We can now implement the process method as follows:
void AMuxDemux::process(const ProcessArgs &args) {
/* MUX */ lights[selMux].setBrightness(0.f); selMux = (unsigned int)clamp((int)params[M_SELECTOR_PARAM].getValue(), 0, N_MUX_IN); lights[selMux].setBrightness(1.f);
if (outputs[M_MAIN_OUT].isConnected()) { if (inputs[selMux].isConnected()) {
outputs[M_MAIN_OUT].setVoltage(inputs[selMux].getVoltage()); } } /* DEMUX */ lights[selDemux+N_MUX_IN+1].setBrightness(0.f); selDemux = (unsigned int)clamp((int)params[D_SELECTOR_PARAM].getValue(), 0, N_DEMUX_OUT); lights[selDemux+N_MUX_IN+1].setBrightness(1.f);
if (inputs[D_MAIN_IN].isConnected()) { if (outputs[selDemux].isConnected()) {
outputs[selDemux].setVoltage(inputs[D_MAIN_IN].getVoltage()); } } }
As you can see, there are several checks and casts. We need to cast the input value to an integer because it is used as an index in the array of inputs.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Listening Through the Noise by Joanna Demers(454)
How to Wreck a Nice Beach by Dave Tompkins(453)
Rise of The Super Furry Animals by Ric Rawlins(294)
Developing Virtual Synthesizers with VCV Rack by Leonardo Gabrielli(270)
The Rhythmic Event by Ikoniadou Eleni(268)
Rise of The Super Furry Animals by ric rawlins(251)
Mars by 1980: The Story of Electronic Music by David Stubbs(199)
Kraftwerk by Uwe Schütte(190)
