Using abstractions (red patches) .
NOTE, mc->f, f->mc, arithm-ser.
This patch generates a harmonic spectrum starting from a given fondamental. We will see in this example the encapsulation of a patch (red patch) inside our main patch.
A: Input the fundemantal note by using the second input of NOTE or open the NOTE editing window and edit your note.
B: Now let us build a patch which will calculate the harmonics of our spectrum. We will first create a patch inside our main patch by command-clicking inside our patch in the same way as calling a function. At first, a small window will appear :
Then we will type 'patch':
This will create a red patch:
We can now rename the patch 'harmonic series' by double-clicking' in the name area 'mypatch'.Let us now open the patch by double-clicking on its icon. You will notice on the upper left corner two buttons representing output and input icons. By double-clicking on them we create outputs and inputs.
For our patch we will need four inputs and one output:
C: To generate a harmonic spectrum we must multiply the frequency of the fondame ntal note by the harmonic rank (for example, if the fondamental is 60 Hz, we must multiply it by 1,2,3 etc...).
To be able to do so, we will convert our midicent value into frequency by using mc->f (D)
E: To generate a listof harmonic ranks, we will use arithm-ser function. The first input will be the starting rank (the first harmonic: 1) . The second input is the last harmonic desired. The third input will be the stepping between the ranks (one might choose the value 2 which will output odd harmonics (1 3 5 7...)).
F: After multiplying the fondamental with the output of arithm-ser by using om*, we will convert again the frequencies into midicents with the f->mc function.
We can now connect the four inputs and our output as shown above and rename them as we did with our patch (double-clicking in the text zone). If you evaluate f->mc you will get an error message. That is because the inputs are not initialized. They always return nil in their initial state. To test the red patch in its open state you should specify the inputs default value. To do this, double click on the input's icon to open a dialogue box:
Input your Defval and hit the return key. You can also document your inputs.This will appear when you command-click on the inputs of the red patch.
G: Now we can evaluate the CHORD box (G) and obtain the harmonic spectrum.