Adding More Control
A decent synthesizer should respond to MIDI volume, hold and pitchbend messages. We already have a volume controller in our synth. To make it response to MIDI volume messages you just need to modify the module's parameters. Set it's Rx MIDI Event paremeter to Controller and Rx MIDI Parm parameter to 7 (MIDI controller 7 is volume, according to MIDI spec). Now if you can transmit the volume controller from your MIDI keyboard (or another MIDI source) you can watch the volume knob to respond to the controller movement (the synthesizer must be in the playing state, that is button must be down!).
You can notice a slight click as you change the volume while playing the keys. That is because the controller changes not continuously but in steps (there are only 128 values per the entire controller range). The clicks can be avoided by inserting a low-pass filter after the controller knob. 1-pole filter with cutoff set to 10 Hz will do.
To make the synthesizer respond to the hold we need to avoid the gate signal to the envelopes (both amplitude and filter) dropping below zero while the hold controller is more than halfway up (according to the MIDI spec, values greater than or equal to 64 define the on state of the hold controller).
Remove the Gate module from both Filter and Amplifier macros and make a new input called G in each of these macros. Inside each macro route the G input to the envelope.
Create a Gate module within the ensemble structure instead of the two removed Gate modules. Then right-click the background and select Standard->MIDI->Hold Peak. Connect the Gate to the Hold Peak module. Route the Hold Peak output to G inputs of the Filter and Amplifier. This module is going to sustain the gate while the hold is on.
Now you can try the hold pedal. Play some notes with the pedal either up or down.
Notice. This hold macro cannot be used for monophonic synthesizers driven by single-trigger gate. If this hold macro is inserted into a monophonic gate signal path, pressing down the hold pedal would trigger the envelopes because the output value becomes greater than zero.
Now for the pitchbend. The pitchbend controller is going to change the oscillator frequency. While we can add some value to the OnFreq output, better to multiply the OnFreq value by something (remember, the frequency scale is logarithmic). With small frequency deviations the two above methods do not differ much, but if you want to pitchbend range to be +/-1 octave you need the latter one. -1 octave is multiplying the frequency by 0.5 and +1 octave is multiplying the frequency by 2.
OK, create a new macro, call it pitchbend and route the OnFreq output through this macro to the oscillator.
Switch to the macro's internal structure. Create a controller, called pitchbend. Set its appearance to none, scale to linear and range to [-1..1] (by the way MIDI pitchbend controller range is [-8192..8192]) and set its Rx MIDI Event to pitchbend.
Create another controller knob with linear scale and range [0..12]. Call it 'Pitchbend range'. Set its Step parameter to 1 and Show Value to Yes. This knob is goind to define the pitchbend range in semitones. Multiply the pitchbend controller output by this knob's output.
Route the Mult's output to the dP2FF module (Standard->Auxiliary->dP2FF). This module converts semitones to frequency factor (the number we are going to multiply the frequency by). You can choose the precision of dP2FF module computation by right-clicking it and selecting Show Panel. This module is a macro module created the same way you did with your macros. It has its own panel on which there is a switch letting you choose the module precision. This time you can choose the precision set to infinite since there are not too many pitchbend MIDI messages per time unit to consume significant fraction of the CPU time (higher precisions require more CPU power).
Multiply the pitchbend macro's input by dP2FF output and route it to the output. Now we have multiplied the oscillator frequency by the factor corresponding to the pitchbend.
Try the pitchbend and hear the sound affected. Remember to switch to the panel and set the pitchbend sensitivity to a nonzero value.
next page>>