This series of classes introduces a
simple, but extendible, drum machine program. It is a series of jm-550
tutorials (influenced by the drum patterns of the Boss DR-550 drum
machine) which show the development of a Java graphical user interface
for a jMusic application. This first tutorial looks at the application
without any GUI code, in the next tutorial some simple start and stop
buttons are displayed in a window frame, then sliders are added to
control tempo and volume, then a list
of drum patterns is added. So here
goes... |
abstract class Basic_550 implements JMC { |
After some import statements (not shown) the class is declared and some static class variables created. These variable, such as the Score drumScore, will be accessible by all the classes that extend this one. We only need declare them here once which will save time for the classes that implement each of the drum patterns.
The constructor empties the score and drum part of any previous content (the first time through this is unnecessary but subsequently it is required) then calls the makePattern() method.
The makePattern() method simply adds the drum part to the score,
then calls changeDynamics() to adjust the dynamic of every note in the score to
the current volume level (this is set at present but later on
we'll add a slider in the GUI to change this dynamically).
Simply adding a part seems trivial - especially considering
that up to this point the part appears to be empty - but in the
classes that extend this one their role will be to fill the part with
phrases for each of the drums (kick, snare, cymbals etc.).
The last two methods are fairly basic: playback()andstopPlayback() do exactly that - they can be called to play or stop the percussion loop. This function is used in the next tutorial.
public void setTempo(double tempo){ |
Above is the code for access methods for any of the class variables we might want to use later on. The exception is setTempo() which is NOT a class variable, rather it changes the property of the drumScore, so it cannot be static. In typical Java style all these methods are labelled getXXX and setXXX where XXX is the name of the variable or property.
// this method used by many others below |
In these methods we find the 'hard yakka' (Australian colloquialism for work) of this class. To make the extended classes as simple as possible these classes take input in the form of a pitch (for the particular drum we are concerned with, i.e., 36 for kick drum in general MIDI devices), an array of the rhythm values, and the start time of the rhythms (for example the snare may not start until the second beat of the bar).
// kick |
To see all the percussive instruments supported by this class check the source code.
OK. Now lets look at the extended classes - the ones we actually run. First the EightBeat1 class.
import jm.JMC;
|
It creates an array for the rhythm of each part of the drum kit used in the EightBeat pattern. Also its sets up attributes of the accents() call - more on this latter.
The main method calls the default constructor - which in turn runs the constructor of the super class, Basic_550. Then the score is printed to the standard output for verification and saved as a MIDI file.
The constructor first runs the constructor of its super class (this is a standard function in Java when one class extends another) then calls the kck(), snr(), and chh() methods inherited from Basic_550 to create the kick, snare and closed hi hat phrases. Finally the Mod.accents() method is called which applies a slight dynamic boost to notes occurring on particular beat locations - specified in the accents array. Many of the patterns on the DR-550 drum machine used this accent function which is why it is replicated here. This and the slight dynamic deviation applied in the Basic_550 class provide some 'feel' to the drum patterns.
The fill-in class follows the same procedure as above, but for a different drum pattern. Notice that it uses low, mid and high toms and a crash cymbal, and pedal hi hats rather than closed hihats. It's accent points are more complex as well.
import jm.JMC;
|
Move on to the next tutorial which
adds a graphical user interface to these classes:
JM-550 Drum Machine: Simple AWT GUI
|
|
|
© 2001 Andrew R. Brown |
|
|