Designing a step sequencer

by Nick_Zaillian » Mon, 27 Jul 2009 06:45:01 GMT

Sponsored Links
 Hey all.  This is my first post to the Android group.  I grabbed the
Android SDK a few days ago and have been playing around with it in the
time that has elapsed since.  I've built a few simple apps to get a
feel for everything and have been generally pleased.  In any case, I
am posting here because I am interested in building an app with a step
sequencer and am not quite sure how best to go about doing it.  My
idea is that the user would be presented with a row of 16 toggle
switches, a tempo control, and a few buttons to select instruments
(kick drum, snare, etc...this is basically an emulator of old-
fashioned drum machines).  Each instrument would have its own 16-step
pattern and when the user pressed a "play" button, all of the
individual patterns (which might more appropriately be called "parts")
would play back simultaneously.  Accomplishing all of this would be
relatively straightforward if Android/Dalvik had a javax.sound
implementation (it includes midi tools and audio playback tools) but I
know that it doesn't.  I was thinking, then, that the best way to go
about building my program would be to have a bunch of MediaPlayer
instances and some sort of scheme for representing patterns as strings
(maybe something as simple as 0s for "no-hit" and 1s for "hit").  I
was thinking I'd keep these pattern strings in an XML file and update
it every time the user changed the state of a toggle switch.  For
playback, I was thinking I'd parse the XML file such that I'd have a
16-element array of, let's say, 10 (if there are 10 instruments)-
element arrays of 2-element arrays where the 2-element arrays consist
of [(instrument), (hit/no hit)].  I'd then use a timer (set to user-
selected Tempo) to step through the 16 element array and, when an
instrument represented in the contained array had a "hit" state, call
the start method of the corresponding MediaPlayer instance.  So,
that's my fairly convoluted solution to the problem.  I am posting to
the group because I am so new to the SDK and figured that I should
probably ask of those more experienced whether there is some glaring
problem with this solution or, perhaps, if there is a far more simple
way to go about accomplishing what I'm trying to accomplish.