Java Reference
In-Depth Information
Reusable blocks of tones can be defined. To begin a block definition, use
ToneControl.BLOCK_START and supply a block number. Then supply the notes and durations
that go into the block. To end a block definition, use ToneControl.BLOCK_END and supply
the same block number. To actually play a block, use ToneControl.PLAY_BLOCK and
supply the number of the block you wish to play. Blocks must be defined following the
VERSION , TEMPO , and RESOLUTION in a sequence.
The volume can be set at any time during a sequence for dramatic dynamic effects. For
example, ToneControl.SET_VOLUME, 25 sets the volume to one quarter of its maximum value.
To indicate a rest of a certain duration, use the special note value ToneControl.SILENCE .
You can repeat a single note multiple times. For example, ToneControl.REPEAT, 7, 60, 16
plays middle C (60) seven times with a duration of 16.
The MIDlet in Listing 16-4 contains several examples that will help you write your own
tone sequences.
Listing 16-4. Old Classics in Monophonic Glory
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class ToneMIDlet
extends MIDlet
implements CommandListener {
private final static String kSoundOfMusic = "Sound of Music";
private final static String kQuandoMenVo = "Quando men vo";
private final static String kTwinkle = "Twinkle number VII";
private Display mDisplay;
private List mMainScreen;
public void startApp() {
mDisplay = Display.getDisplay(this);
if (mMainScreen == null) {
mMainScreen = new List("AudioMIDlet", List.IMPLICIT);
Search WWH ::




Custom Search