In this orchestra we have introduced two MIDI "value converters," cpsmidi and ampmidi because we need some way to convert MIDI note numbers to their Hz (or cps) equivalent as required by the grain opcode. We also need a way of mapping MIDI velocity to maximum linear amplitude. In this case the velocities from 0-127 will be scaled to a range of 0-10000. Controller 80, scaled from a range of 0 to 10000, will be added to the base-frequency derived from the note played on the MIDI keyboard (icps + kcps). The other 4 controllers (16,17,18 and 19) are also scaled to specific ranges and assigned to grain duration, grain density, amplitude and pitch offset.
One of the important considerations of this and every MIDI instrument is reflected in the use of the linenr opcode. In the past, Csound instruments always "knew" the duration of the note when the instrument was initialized. This is because every note statement, in fact, required three parameters to be specified - instrument number (p1), start time (p2), and duration (p3). All other parameters in the score were left up to the sound designer. But in a MIDI instrument, how can you know the duration of the note in advance? The note's duration depends on how long you hold your fingers down on the keys. So, Vercoe had to create a new class of MIDI envelope opcodes that go into a "release phase" when a noteoff is sensed - all of these MIDI-based signal modifiers end with the letter "r" (linenr, linsegr, exponr, etc.).
The score file for our MIDI instrument is unique also because it can contain no notes. Rather, a dummy f-table is used to keep the instrument active for a certain amount of time. In the case of our granular MIDI instrument, the instrument is kept active for 30 seconds - f0 30 as seen in figure 9.