Logic and the outside world 

This workshop deals mainly with logic used to process keys pressed on the keyboard or received by MIDI.

Delaying the transposition of a sequence until the next clockpulse

If an oscillator is connected to a note sequencer and the oscillator also followes the keyboard the sequence can be transposed just by pressing the right key on the keyboard. That transposition is by default immediate, but you might want to delay the transposition to the next clockpulse. To do this we first have to make shure the oscillator(s) won't react to the keyboard automatically. So the first step is to turn keyboardtracking off by either depressing the KBT button or turning the KBT knob completely anti-clock wise. Next step is to sample the Note value of the Keyboard module on the clock that is used to clock the sequencer, for this we use the Sample and Hold module which can be found under the Audio-Tab in the editor program. Now we feed the sequencer module's output value to one of the two oscillator's control inputs and the output of the Sample and hold module to the other control input. As the keyboard Note value is sampled on the sequencers clock a transposition can only take place on the moment a new note starts. The Sample and hold now acts as a memory storing the Note value that was present at the moment of the sequencers clock OFF/ON transition and holds this value until the next OFF/ON transition of the clock.

You might want to delay the transposition until the moment the whole sequence restarts. The only thing we have to change for this is reconnect the Sample and hold module's yellow input to the sequencer module's Snc output.

Adding an Event sequencer module that runs in parallel with the Note sequencer and having one row of buttons trigger the Sample and hold module gives us the possibility to program a pattern for which moments the sequence is allowed to transpose.

These three examples are to show the importance of the Sample and hold module to synchronise realworld events like a keypress to a patch event like the sequencer clock.

Starting an envelope with a keypress and stopping it at the next keypress with a toggle flip-flop

If we want to start a drone by pressing a specific key on the keyboard, but that drone should continue when we release the key, to attend to other things on stage, and stop it by pressing that key again, we need to store that keypress somewhere. For storing things always think of the Sample and hold module first, as it is in fact a storing module. But what we actually need to do is to toggle an ON/OFF signal with the OFF/ON transition of a keypress. In digital circuitry this is done by a circuit called a flip-flop.

This is how we do it:

The notedetect module detects if our note is pressed and it triggers a Sample and hold. The output of the Sample and hold is connected to a logic inverter, and the output of the logic inverter is connected to the input of the Sample and hold. Initially on patchload the output of a Sample and hold is always level 0 -> logical OFF. The inverter inverts this to logical ON, which is present on the input of the Sample and hold. So when the C4 key is pressed the logical value ON is sampled and passed on to the output of the Sample and hold. As this output is also connected to the gate of the envelope the envelope is opened. Releasing the C4 key does not do anything as the Sample and hold only reacts on a OFF/ON transition, see the up-pointing arrow next to the Sample and hold's yellow input. The inverter now puts a logical OFF on the input of the Sample and hold, so on the next keypress this logical OFF is passed on to the output and consequently the envelope stops.

The envelope could be replaced by a gain-controller module from the mixers tab, only that could introduce a click in the sound, with the envelope module we can set a small attack value and a small release value that effectively avoid any clicks or pops in the sound.

A 'DSP-cheap' suboctave oscillator/frequency divider

The same Sample and hold/Inverter patching from the previous example can be used to generate audio suboctaves as well, as it actually divides the frequency of an oscillators signal by one octave. As the output of the Logic inverter module is between 0 and 64 we subtract a value of 32 from the signal to make it a nice symmetric audio signal.

This can also be used for clock signals. There might be a reason why in some cases you would prefer this patching over using the clock divider module, as this patching only reacts on a OFF/ON flank of a pulse and the clock divider module on both flanks of a pulse.

More types of flip-flops

There are more kinds of flip-flops, usable for different purposes. The principle is quite simple, look at the the following very simple patch:

After loading this patch you will hear a sound with a very high pitch. Shortcircuiting an inverter module generates a squarewave of exactly 12kHz. The logic modules are calculated 24000 times a second, on the first calculation the module sees an ON state on its input as the output is by default ON on patchload. It now inverts this ON and turns its output OFF. On the next calculation it finds an OFF state on its input so it turns its ouput ON and goes on to do this on each calculation. 24000 times a second, on each calculation the output flips its state from ON to OFF or from OFF to ON, and so generates the squarewave of 24000/2 Hz. This patching we can use if we make elaborate logic patchings where we need a stable fast clockpulse. The frequency can be divided to a lower frequency by a clockdivider module. The advantage of this circuit is that it is absolutely in sync with the systemclock that regulates the calculations of both yellow and blue outputs.

The RS-type flipflop

But what if we add anothe inverter and patch it like in the next example:

The high pitched sound has stopped now. The two inverters are in a stable state, one inverts the ON from the first inverter into an OFF that is inverted into an ON by the first one and so the outputs have stopped flipping states. The only thing we know now is that one output will be ON and the other will be OFF, so not much use to us. But we can force one of the inverters output to OFF if we could force its input to ON, this is done by inserting an OR gate just before its input. This will make the output of the other inverter change to ON, of course. Adding an OR gate in front of the other inverter will give the possibility to force that ones output to an OFF state as well. Now we have a simple socalled reset/set flipflop or RS-type flipflop. It has two inputs and if the input to one of the OR gates is momentarily set to ON the output of that OR gate will change to on forcing the output of the other OR gate to OFF.

Pressing the C4 key will now gate and open the envelope module as can be seen on its green led and pressing D4 will close the envelope. There is only one limitation, what if we press both C4 and D4 at the same time? This will totally confuse the inverters and the patching becomes unstable. This is a socalled forbidden state and we can minimize the chance this happens by adding pulse modules with pulse of 1 msec. to the set and reset inputs. When triggering the RS flipflop from keys the chance that we now press both keys within the same millisecond is pretty small.

So here's the basic patching that does the job.

To resume: the heart of the SetReset flip-flop is the two Logic processor modules combined with the two Logic inverters. One input of each logic processor is connected to the inverted output of the other logic processor, the input that remains on each logic processor is either the set or reset input. A logic ON signal on the input of one of the logic processors will set the output of that processor to ON and the output of the other one to OFF. As said, there is one problem with this circuit and that is that if both inputs have an ON signal the circuit will not function properly, the so called forbidden state. A true digital SetReset flip-flop will be much more complex than this one to prevent this forbidden state. In our case we will simply add pulse modules at the inputs, set to 1 msec pulses to minimize the chances that both inputs receive an ON signal at the same time. This will do for almost all situations.

The RS-type flipflop can be used to start something, e.g. a sequence or drone, by one key and stop it by another key.

One of the times you might want to use this circuit is if you want sevearl sequences to be started by separate keys but have the possibility of stopping them by one key, like in the next example where a note is started by the C4 key and another can be started by the D4 key and both can be stopped By the E4 key.

The D-type flipflop with reset.

Another common type of flip-flop is the D-Type with reset. We can use such a patching to conditionally start a sequence by a key and force it to stop with another key, the condition being the state of the D-input. A sample and hold module in itself is a simple D-type flip-flop where a logic state on the input can be sampled and hold in the same way as a blue or red signal. However on occasions we might want an extra input that forces the output to an OFF state no matter what the inputvalue might be. To do this we put a Gain controller module just before the input of the sample and hold. What we do now is combine the normal clock input and the reset input by a Logic processor set to the OR function, but we invert the reset input so it is ON by default, and open the Gain controller with this signal. So normally the Gain controller passes the input signal, but the moment a On signal presents itself at the reset input the Gain controller closes, and a value of 0 equivalent to a logic OFF state is sampled instead of the input signal.
The patching has the disadvantage that if either the sample or the reset input is ON the other input is inhibited, so to minimize the chance this happens we do the same as with the previous example and add Pulse modules to both inputs.
The patching can be used to sample blue signals instead of logic signals as well.

In the next example we use the D-type flip-flop to start a sequence by the C4 key and let it run for the number of times set by the ClkDiv module.

The One-and-only-one flipflop

A patching that on occasion can be handy is a so called one-and-only-one patching. This patching accepts two inputs, on one of them is e.g. a regular sequencer clock. If there is a pulse on the other input the output of the patching generates a pulse that starts on the next time the sequencer clock goes from OFF to ON and on the OFF/ON transition that follows it will stop the pulse. So if in the example the C4 key is pressed the patching waits for the arrival of the next clock module pulse, opens the ADSR gate and keeps it open until another clock pulse arrives and then shuts the ADSR, whether we keep the C4 key pressed or not.

The one-and-only-one can be used to e.g. isolate one note from a sequence to e.g. give this one note expression like in the next example.

This ends the flip-flop subject.

Suppressing the retrigger of an envelope while the envelope still lasts.

Sometimes you might want a drone or noodle to start on a keypress, but you wouldn't want it to be retriggered accidentally until it's finished. You might also want it to fade in and out and to last for a specified time.
If we connect a logic module, e.g. an inverter module to the blue output of an ADSR envelope module, we get a logic signal that lasts exactly for as long as all the ADSR stages last. Only when the release phase has died out completely will this signal change again. Using an inverter module we get a logic ON signal if the envelope is off and a logic OFF signal if the envelope is on. We can use this signal to prevent the ADSR from being retriggered. But we also want the ADSR to be on for a specified amount of time, let's say we want it to fade in during 10 seconds, being sustained for another 10 seconds and then have it fade out of again 10 seconds. For this we need a gate signal that lasts as long as 20 seconds and an additional release of 10 seconds. The following patching will do exactly what we want.

The AR envelope module's LED monitors what happens to the output of the Inverter module. By default this output is ON as the signal at the input is exactly 0 units if the ADSR envelope is off. The Logic processor module set to the AND function is now able to pass the Gate signal from the C4 key to a patching consisting of two Negative Edge delays that will generate the gatepulse of exactly 20 seconds, the first one is set to its maximum value of 18 seconds and the second one adds another two seconds to this pulse. If we press the C4 key the 20 second pulse opens the ADSR envelope and immediately when the envelope signal rises to greater than 0 units the output signal of the logic inverter will go off and block the C4 key's Gate signal in the logic processor. After 20 seconds the ADSR has gone through it's A, D and S phases and the LED on the ADSR will go off. But the output of the inverter will still be OFF as the envelope is still in it's release state, the Control LED will still be off so a new keypress will have no effect. Only after the release phase has completely died out will the inverters output be ON again and enable another C4 keypress.

You can use this patching e.g. on stage, or when recording with the help of a MIDI sequencer program. In the last case you will only need one MIDI NoteOn event that doesn't have to last very long to start the process of fading in, holding for some time and fading out the drone patch. Using the AudioInput module to feed the ADSR module(s) makes this a sort of a mixer automation patch.

The next example combines the previous technique to have two ADSR envelopes alternately trigger each other and modulate some sound. A third ADSR is used to fade the drone in and out on the C4 key and reset the other two envelopes by means of inverting the gate loopback by a XOR function for a very short time. Remember that the output of the logic processor directly after the C4 key module is almost immediately forced to OFF after a keypress, by the inverter module that processes the blue envelope signal. The logic signals from the inverters on the other ADSR's are also used to control the modulation of the oscillator.

Try to figure out yourself the routing of the logic signals and what they do. If you can, then you can be assured that by now you have become a master of logic and we can go on to look at some more elaborate uses of the logic modules.