A Simple Drum MachineThis demo will start you on the track to rock or techno with jMusic, and generally introduce techniques for multi-part ostinati which might also be used for minimalist, African, or Gamelan music. To hear the result play the MIDI file below.
Lets have a closer look.
This section declares the class and sets class variables for most levels of the jMusic data structure. Phrases will hold a pattern for each drum, the 'drum' part will hold those phrases and, although there is only one instrument in this demo, the music in jMusic always needs to be in a score format to create a MIDI file. The part is set to the 10th MIDI channel (i.e. channel 9, counting from 0) for GM playback of drum and percussion sounds. The number 0.0, which is an argument to the Phrase constructor, tells the new phrases that they will start at the beginning of the piece. The final println statement simply keeps us informed of the program's progress as it runs by printing to the standard output.
The first phrase to be created is the bass drum. It consists of four crotchet note - crotchet rest pairs. The General MIDI (GM) drum kit uses note number 36 for bass drum. Each note and rest is added to the bass drum phrase (phrBD) by calling the 'addNote' method in the Phrase class.
A similar process creates the snare and hi hat parts. The snare plays on the opposite beats to the bass drum. The hi hat is normally closed (note 42 in GM) but an open hi hat is added to the end of the phrase just for some small aesthetic interest.
Mod.repeat() is used to create loops of each phrase. In this case the same number of repeats are used for each phrase and each phrase is the same length. However, interesting effects could be created by 'phasing' patterns of different lengths to create continually varying rhythmic combinations.
|
|
|
|
|
|
|