Class BeatBox

java.lang.Object
  extended byBeatBox

public class BeatBox
extends java.lang.Object

The BeatBox is a class that can play rhythm tracks. The tracks to play are defined by a sequence of calls to the beat box as follows:

   newTrack  - start the definition of a new track.
   addBeat*  - add a beat to the track (call multiple times).
   endTrack  - end the definition of a track.
   
   start     - start playing the defined track.
   stop      - stop playing the currently palying track.
 
The beat box can also be used to do a single hit on an instrument by using the 'beat(..)' method.

Version:
2004-11-16
Author:
M. Kolling

Constructor Summary
BeatBox()
          Create a beatbox engine.
 
Method Summary
 void addBeat(int tick, int instrument)
          Add a beat to the current beat track.
 void beat(int instrument)
          Do a single hit on a single instrument and stop again.
 void endTrack()
          End the definition of a beat track.
 boolean isPlaying()
          Tell whether the beat box is currently playing.
 void newTrack(int length)
          Start defining a new track.
 void setLoop(boolean loop)
          Set the beat box looping mode: When 'loop' is true, the track is played in a loop indefinitely until stopped.
 void setTempo(int newTempo)
          Set the playback tempo (in beats per minute).
 void start()
          Start playing the current track.
 void stop()
          Stop playing the current track.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeatBox

public BeatBox()
Create a beatbox engine.

Method Detail

addBeat

public void addBeat(int tick,
                    int instrument)
Add a beat to the current beat track. The parameters define the instrument being used, and the tick in the track at which it is hit. Before calling this method, startTrack() must be called. After repeatedly calling this method (befor playing), endTrack() must be called.

Parameters:
tick - The tick number of this beat in the track.
instrument - The instrument type used.

beat

public void beat(int instrument)
Do a single hit on a single instrument and stop again.

Parameters:
instrument - The instument constant (see interface Instruments).

endTrack

public void endTrack()
End the definition of a beat track. This method may only be called after startTrack() has been called.


isPlaying

public boolean isPlaying()
Tell whether the beat box is currently playing.


newTrack

public void newTrack(int length)
Start defining a new track. 'length' is the length of the track in ticks. For length N, valid ticks for beats are [0 .. N-1]. After calling newTrack, you can repeatedly call addBeat, and then endTrack to finalise the track. Calling start will then play the track.

Parameters:
length - The length of the track in ticks.

setLoop

public void setLoop(boolean loop)
Set the beat box looping mode: When 'loop' is true, the track is played in a loop indefinitely until stopped. By default, loop is true.


setTempo

public void setTempo(int newTempo)
Set the playback tempo (in beats per minute). The default tempo is 120.


start

public void start()
Start playing the current track. The current track must have been completely defined before playing (by calling a sequence of newTrack/{addBeat}/endTrack).


stop

public void stop()
Stop playing the current track.