In this example we test a melody in different synth voices by sending MIDI notes and program change events to an external synthesizer, which could be hardware or software.
First let's create a MIDI system output to connect to the synth:
local midiOutput = Midi.Output("synth")
Now we'll create a one-bar MIDI Pattern from ABC notation, a simple melody courtesy of Ludwig van Beethoven:
local pattern = Midi.ABCReader().read("| B B c d d c B A |")
We want to test all the patches for the current bank so we create a basic loop to count over all the patches in the current bank (note program numbers are zero based):
for(local program = 0; program < 128; program++) {
We only want to schedule our midi pattern for every other measure to give the synthesizer a pause to change the patch, a process which may take some time on some equipment. Also note the measure counts starts at one and not zero so we compute the measure as so:
local measure = program * 2 + 1
Now we create our MIDI program change message for this program:
local pc = Midi.ProgramChange(program)
We schedule the program change to occur at the halfway mark of the first bar of each iteration, this gives the last iteration a half-measure to fade out (if there is e.g. a reverb or echo effect) and also gives the synth a half-measure to change the patch before the next melody plays:
midiOutput.schedule(pc, measure + 0.5)
Now schedule the melody to play at the second measure of each loop iteration:
midiOutput.schedule(pattern, measure + 1)
Finally, a transport master set to 99 BPM:
} Transport.Master(99)
Starting the transport will play the melody on each of the patches in order.
local midiOutput = Midi.Output("synth")
local pattern = Midi.ABCReader().read("| B B c d d c B A |")
for(local program = 0; program < 128; program++) {
local measure = program * 2 + 1
local pc = Midi.ProgramChange(program)
midiOutput.schedule(pc, measure + 0.5)
midiOutput.schedule(pattern, measure + 1)
}
Transport.Master(99)
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.