javax.microedition.media.control
Interface TempoControl

All Superinterfaces:
Control, RateControl

public interface TempoControl
extends RateControl

TempoControl controls the tempo, in musical terms, of a song.

TempoControl is typically implemented in Players for MIDI media, i.e. playback of a Standard MIDI File (SMF).

TempControl is basic functionality for a MIDI playback application. This is in contrast to MIDIControl, which targets advanced applications. Moreover, TempoControl needs a sequence - e.g. a MIDI file - to operate. MIDIControl does not require a sequence.

Musical tempo is usually specified in beats per minute. To provide a means to access tempos with fractional beats per minute, the methods to set and get the tempo work on "milli-beat" per minute. A simle division by 1000 is sufficient to get the actual beats per minute.

As a MIDI file can contain any number of tempo changes during playback, the absolute tempo is a state of the sequencer. During playback of a MIDI file, setting the tempo in response to a user interaction will not always yield the desired result: the user's tempo can be overriden by the playing MIDI file to another tempo just momens later.

In order to overcome this problem, a relative tempo rate is used (in Java Sound terms: tempo factor). This rate is applied to all tempo settings. The tempo rate is specified in "milli-percent", i.e. a value of 100'000 means playback at original tempo. The tempo rate is set with the setRate method of the super class, RateControl.

The concept of tempo rate allows one to play back a MIDI sequence at a different tempo without losing the relative tempo changes in it.

The setTempo() and getTempo() methods do not affect or reflect the playback rate. This means that changing the rate will not result in a change of hte value returned by getTempo(). Similarly, setting the tempo with setTempo() does not change the rate, i.e. the return value of getRate() is not changed. The effective playback tempo is always the product of tempo and rate:

    effectiveBeatsPerMinute = getTempo() getRate() / 1000 / 100000
 

See Also:
Player, RateControl, PitchControl, MIDIControl
Since:
BlackBerry API 4.0.0

Method Summary
 int getTempo()
          Gets the current playback tempo.
 int setTempo(int millitempo)
          Sets the current playback tempo.
 
Methods inherited from interface javax.microedition.media.control.RateControl
getMaxRate, getMinRate, getRate, setRate
 



Method Detail

setTempo

int setTempo(int millitempo)
Sets the current playback tempo. Tempo is a volatile state of the sequencer. As MIDI sequences may contain META tempo events, tempo may change during playback of the sequence. Setting the tempo with setTempo() does not prevent the tempo from being changed subsequently by tempo events in the MIDI sequence. Example: during playback of a sequence, the user changes the tempo. But just moments later, the MIDI sequence changes the tempo to another value, so effectively the user interaction is ignored. To overcome this, and to allow consistent user interaction, use setRate inherited from RateControl.

The setTempo() method reutrns the actual tempo set by the Player's implementation. It sets the tempo as close to the requested value as possible, but is not required to set it to the excat value. Specifically, implementations may have a lower or upper limit, which will be used as tempo if the requested tempo is out of limits. 0 or negative tempo does not exist and will always result in the lower tempo limit of the implementation. Implementations are guaranteed to support 10'000 to 300'000 milli-beats per minute.

Setting tempo to a stopped sequence will force the sequence to start with that tempo, even if the sequence has a tempo event at the start position. Any subsequent tempo events in the sequence will be considered, though. Rewinding back to a position with a tempo event will result in a tempo change causeed by the tempo event, too. Example: a sequence with initial tempo of 120bpm has not been started yet. The user sets the tempo to 140bpm and starts playback. When the playback position is reset to the beginning, the tempo will be set to 120bpm due to the tempo event at the beginning of the sequence.

Playback rate (see setRate) and tempo are independent factors of the effective tempo. Modifying tempo with setTempo does not affect the playback rate and vice versa. The effective tempo is the product of tempo and rate.

Parameters:
millitempo - The tempo specified in milli-beats per minute (must be > 0, e.g. 120'000 for 120 beats per minute).
Returns:
tempo that was actually set, expressed in milli-beats per minute
See Also:
TempoControl.getTempo()
Since:
BlackBerry API 4.0.0

getTempo

int getTempo()
Gets the current playback tempo. This represents the current state of the sequencer:

Returns:
current tempo, expressed in milli-beats per minute
See Also:
TempoControl.setTempo(int)
Since:
BlackBerry API 4.0.0





Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.