When you play a note with MIDI, you usually want the note to sustain as long as the key is held down, then you want it to turn off (either immediately or gradually) when the key is released (when the note-off message is received). Because MIDI is designed to function in real time, in live performance, there is no duration information contained in a note-on message. The duration can only be known once the key has been released.
This is a bare-bones monophonic MIDI synthesizer that uses the pitch and velocity information from incoming MIDI note messages to control the frequency and amplitude of a sawtooth waveform. It works, but it could definitely be improved. It's nearly identical to the even more bare-bones "Overly simple MIDI synth" example, but with one improvement, the addition of the poly object, described below.
This patch demonstrates the technique of wavetable synthesis: using one cycle of a stored waveform as the wave type for a synthesizer tone. The cycle~ object with no argument produces a cosine wave; however, cycle~ can also refer to a waveform stored in a buffer~, and use that as a wavetable. To do that, you need to create a buffer~, store a waveform in it, and then refer to that buffer~ by creating a cycle~ with the same name.
To use floating point numbers with the poly object separate the integer portion and the fractional portion. Then recombine them after the poly object, as in the example.
This example shows the patch from another example being used as a subpatch in a larger patch. You will need to download the patch from “Generating a simple 2-operator FM tone” and save it with the name "FMtone~" in order for this example to work.
Any given MSP patch cord represents a single channel of audio. If you want to generate or process multiple sounds or channels, you need to treat each sound or channel separately. For example, each sfplay~ object can have multiple loaded sound cues so that it's ready to play any one of several files, but it can only play one sound file at any given instant. And if it's a stereo file you need to treat each channel separately for mixing, processing, etc. This patch demonstrates that.