II.3.4. Adding Parameter Control
To add parameter controls, we can setup one or more of control array element. Each element (control[0], control[1],..,control[5]) has mode which is set to default value CM_DISABLED by the system’s setup.
- Setup the control name (control[n].name) to a self-descriptive name for the control function, such as “Out Level”, “Gain”, “Distortion Level”, etc.
- The control mode (control[n].mode) can be set to one of the following values to enable the port: CM_POT, CM_SELECTOR, CM_TOGGLE, CM_MOMENTARY, CM_TAPTEMPO, and CM_MULTIBUTTON.
- Setting up control[n].mode to CM_POT setup the port for reading analog potentiometer, analog expression pedal, or analog control voltage (CV) inputs. The default resolution of the reading is 128 steps (0-127), to change the resolution you can set control[n].levelCount to an integer value between 2-256.
- Setting up control[n].mode to CM_SELECTOR will setup the port for reading a selector switch. Set the control[n].levelCount value to an integer ranging for 2 – 12, which setup the position count of the selector switch. If you use a potentiometer instead of selector switch, it would work but note that the reading won’t apply any hysteresis between adjacent level so it could be triggered back and fort when taper is positioned between two levels.
- The inverted property will setup the turning-direction of the potentiometer and the selector switch.
- For CM_TOGGLE, CM_MOMENTARY, and CM_TAPTEMPO modes, the setting for the other properties is similar with button control (section II.3.1.2.)
- The CM_MULTIBUTTON mode is not yet implemented in the current version library.
Noisy Triggering on CM_POT Control Mode
On some board, especially with ES8388 version, potentiometer control can be triggered by internal noise although he knob is not being turned. To suppress this erroneous triggering, we can do the following:
- Set smaller value for levelCount (control[n].levelCount), this will make the hysteresis between the steps bigger and getting more noise-resistant.
- Set the property slowSpeed to true (control[n].slowSpeed = true;), this will make the system apply more aggressive filtering to remove the noise by setting up the cut-off frequency to 4 Hz instead of 10 Hz.
Example Codes
Let’s suppose to have a knob at H1 port for output level control and a 3-position switch at H2 port for gain range control. The knob would control the output level in 128 steps from silent (0) to the maximum (127), while the switch will set the gain range so that at the maximum level the gain will be selectable as 0.5, 1.0, and 2.0. Here is the initialization code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
void gainDoubler::init() { //select the appropriate device by uncommenting one of the following two lines: //setDeviceType(DT_ESP32_A1S_AC101); setDeviceType(DT_ESP32_A1S_ES8388); //define your effect name name = "GAIN DOUBLER"; //define the input mode (IM_LR or IM_LMIC) inputMode = IM_LR; //setting up the buttons button[0].mode = BM_TOGGLE; encoderMode = EM_BUTTONS; button[1].mode = BM_TAPTEMPO; button[1].min = 50; button[1].max = 2000; button[2].mode = BM_MOMENTARY; //add gain control control[0].name = "Gain"; control[0].mode = CM_POT; control[0].levelCount = 128; control[0].slowSpeed = true; //add range control control[1].name = "Range"; control[1].mode = CM_SELECTOR; control[1].levelCount = 3; } |
After setting up the control inside the init() function, we can directly access the value (control[n].value) inside our processing function and we can also write the event handler that perform some task whenever the value changes (see section II.3.1.5.).