Real-time Midi Input

Now, assuming you have a MIDI interface properly installed, you can play your first instrument by changing the sco file like this:

f1 0 8192 10 1
f0 10000 ; dummy table, keeps the instrument
         ; active for 10000 seconds
and compiling your orc/sco files so:
csound -o devaudio -W -dm6 -M /dev/midi my.orc my.sco
where -M /dev/midi tells Csound to look for MIDI input instead of score sound events.

Another way of triggering my.orc is to use a Standard MIDI File. The orc/sco can be used as in the last example, but the command line changes to:

csound -o devaudio -W -dm6 -F my.mid my.orc my.sco
where -F my.mid tells Csound to expect input from the MIDI file.

If we want to make our sounds more interesting, we can map MIDI values into the orc file and arbitrarily utilize that data as shown in Listing 1.

Listing 1

Our score file (sco) is as before, but with an added function table:

f1 0 8192 10 1 ; sine wave
f2 0 8192 10 1 .9 .8 .7 .6 .5 .4 .3 .2 .1
                   ; ramp wave
f0 10000
Once again, these files can be compiled for control by either a MIDI input device or a MIDI file. They demonstrate that simple Csound components can easily be built into elaborate sounds and control structures. I have used the simplest instrument here, but already it is quickly evolving toward greater complexity.

Real-time MIDI Output

Listing 2

Using Gabriel Maldonado's MIDI output opcodes is a little different. The following example demonstrates a more complex control system as shown in Listing 2. The sco file for this instrument is as follows:

; MIDI OUT opcodes
; mussle.sco

t 0 60 ; tempo indicator
i1 1.0 1.0 ; the different p3 durations will
; stretch out
i1 2.0 7.0 ; the play of the notes indicated by
; knum
i1 9.0 18.0
i1 18.0 17.0
i11 0.0 1
i100 0 1
The command line for compiling these files looks like this:
csound -Q0 -n -dm6 mussle.orc mussle.sco
where -Q0 selects the first MIDI device and -n suppresses write to disk (for performance enhancement).

Given a fast enough CPU and disk, it is possible to combine the various real-time I/O options. I have tested simultaneous real-time audio with MIDI output opcodes; it works, but with a big performance hit. Considering that my machine is a lowly AMD 486/120, it is to be hoped that a fast Pentium would lessen that hit.