You’ve almost certainly heard the sound of a drum machine before, since synthetic drum sounds are ubiquitous in commercial music. In fact, some brands and models of drum machines have become legendary among fans of certain genres of music, just as certain manufacturers of conventional musical instruments have enjoyed great acclaim in the rest of the musical world. In this project, you will design an application that implements a drum machine with a simple sequencer.
We will specify a high-level architecture for your project, called the model-view-controller pattern. This high-level architecture will make it easier for you to avoid inappropriate coupling between classes and design reusable code. Your design will also have to meet certain lower-level constraints, but you will have a great deal of flexibility within those constraints. We will provide some guidelines for evaluating your design, but it is up to you to determine whether or not your design is a “good” design. Therefore, plan on spending a fair amount of time examining and evaluating your design. We strongly recommend that you work in pairs for this assignment. Talking about your design early and often with a pair programming partner will help you find “bugs” sooner rather than later.
The remaining sections of this document provide some background information on drum machines, describe the model-view-controller pattern and the other constraints imposed upon your design, suggest some hints for how to evaluate your design, and (most importantly) describe what to hand in!
In its most basic form, a drum machine is simply an electronic musical instrument that can trigger several different sounds. The different sounds produced by the drum machine were intended to resemble the sounds of real drums and percussion instruments, but historically the resemblance has been poor at best. Commercially available drum machines have existed since the 1950s. The earliest machines supported only pre-programmed rhythms, but later models allowed a human musician to trigger the different sounds.
Beginning in the early 1980s, drum machines began to support pattern sequencers. Such machines were not restricted to pre-programmed rhythms and did not require a human to operate them during a performance; instead, the drum machine user was able to program patterns of rhythms and arrange sequences of patterns into a song, which the drum machine was then able to play back in real-time without human intervention.
You can think of a pattern as a short part of a song. Each pattern is a fixed length and has a certain number of steps. (Generally, the number of steps is 16 or 32.) At each step, the pattern describes whether or not each sound is to be triggered. You can see an example pattern with 7 sounds (one in each row) and 16 steps (one in each column) below. Filled-in squares correspond to triggered sounds, and empty squares indicate that the sound is not triggered at that step.
When the drum machine plays back the pattern, it reads the pattern one step at a time, playing sounds that are triggered. The rate at which the drum machine reads steps and triggers sounds is a function of the song’s tempo. In the example above, the drum machine will trigger the sound for the bass drum at steps 0, 7, and 10. (You can hear this pattern here)
Of course, a song that just has a short drum pattern repeating over and over again would probably be really boring. To enable musicians to generate and maintain interest, most drum machines allow users to specify a song as a sequence of patterns. For example, a song might play one pattern in the introduction, another during the verse and still another during the chorus.
You can imagine the actions of a drum machine as it plays back a song as a sort of nested for loop:
for (int songPosition = 0; songPosition < SONG_LENGTH; songPosition++) {
/* Code to get the appropriate pattern for this song position goes here */
for (int curStep = 0; curStep < PATTERN_LENGTH; curStep++) {
/* Code to get and play the active sounds for the
current step goes here */
/* Code to wait for a short time (depending on the song
tempo) before advancing to the next step goes here */
}
}
(Don’t worry, you won’t have to implement the part of the drum machine that actually makes the sounds.)
The drum machine we’ll be designing and implementing in this course will play back sampled sounds. This means that when, for example, a bass drum is triggered, our drum machine will play back a recording (a so-called “sample“) of a bass drum. When a snare drum is triggered, our drum machine will play back a sample of a snare drum. (Some real-world drum machines have special methods that generate synthetic sounds mathematically, rather than by using recorded sounds like ours does.) Different songs call for different kinds of sounds, and your drum machine will have to deal with song files that request particular sample files.