Source code: | loop1.cpp |
loop is a monophonic drum sequencer. There are 9 instruments which can played by pressing the computer keyboard characters "1" through "9" which play the following General MIDI percussion instruments on MIDI channel 10 (offset 1):
1 LOW_TOM 6 MUTE_CUICA 2 LOW_MID_TOM 7 OPEN_CUICA 3 HIGH_MID_TOM 8 MUTE_TRIANGLE 4 HIGH_TOM 9 ACOUSTIC_BASS_DRUM 5 HI_BONGO 0 REST
The primary implementation for the loop program is an array which contains one element for each subdivision of each beat. At the start of the program, you are asked for the number of beats and the number of subdivisions for each beat as well as the tempo. An array is then created which holds the note status of each subdivision for all beats. While the program is running a pointer is kept on the currently active subdivision of the loop, and if any subdivision contains a note to be played, then a MIDI message will be sent to the synthesizer telling it to play the specified instrument.
Note that there is no attack-velocity control in this program. All instruments are played at the exact same loudness.
Also note that the loop program is monophonic. You can only store one instrument at a time in the performance array. The loop2 program is designed to be polyphonic.
In the loop program, all of the instruments are percussion timbres, so the program doesn't have to send out note off messages when a not is finished playing. What would happen with a sustaining instrument?
In the loop program, you can save or load patterns from a text file called "loop.txt".
Here are some rhythmic patterns which can be loaded into the loop.exe program (after renaming them "loop.txt")
Here is a demonstration of how a rhythmic loop is implemented in the performance array (using the Afican bell loop pattern):
The loop program keeps track of the current subdivision being played. When the next subdivision is ready to be played, the program looks at the next array index location. If there is a 0 in that array location, then nothing will happen, but if there is a non-zero number in the current array location, then a MIDI note will be generated with the current array value being used as the MIDI key number in the MIDI note message.