world.sound.tunes
Class MusicBox

java.lang.Object
  extended by world.sound.tunes.MusicBox
All Implemented Interfaces:
SoundConstants

public class MusicBox
extends java.lang.Object
implements SoundConstants

Represents/initializes the MIDI synthesizer and manages the channels/instruments in the MIDI program. Based in part on a class originally designed by Viera K. Proulx.


Field Summary
 
Fields inherited from interface world.sound.tunes.SoundConstants
Accordion, AcousticBass, AcousticBassDrum, AcousticGrandPiano, AcousticGuitar_nylon, AcousticGuitar_steel, AcousticSnare, Agogo, AltoSax, Applause, APPLAUSE, Bagpipe, BAGPIPE, Banjo, BaritoneSax, BASS, BassDrum_1, Bassoon, BIRD_TWEET, BirdTweet, BlownBottle, BrassSection, BreathNoise, BrightAcousticPiano, Cabasa, Celesta, Cello, CELLO, ChineseCymbal, CHOIR, ChoirAahs, ChurchOrgan, Clarinet, Claves, Clavi, ClosedHiHat, Contrabass, Cowbell, CrashCymbal_1, CrashCymbal_2, DistortionGuitar, DrawbarOrgan, Dulcimer, ElectricBass_finger, ElectricBass_pick, ElectricGrandPiano, ElectricGuitar_clean, ElectricGuitar_jazz, ElectricGuitar_muted, ElectricPiano_1, ElectricPiano_2, ElectricSnare, EnglishHorn, Fiddle, Flute, FrenchHorn, FretlessBass, FX_1_rain, FX_2_soundtrack, FX_3_crystal, FX_4_atmosphere, FX_5_brightness, FX_6_goblins, FX_7_echoes, FX_8_scifi, Glockenspiel, GuitarFretNoise, GuitarHarmonics, Gunshot, HandClap, Harmonica, Harpsichord, Helicopter, HiBongo, HighAgogo, HighFloorTom, HighTimbale, HighTom, HiMidTom, HiWoodBlock, HonkyTonkPiano, INSTRUMENT_NAMES, INSTRUMENTS, Kalimba, Koto, Lead_1_square, Lead_2_sawtooth, Lead_3_calliope, Lead_4_chiff, Lead_5_charang, Lead_6_voice, Lead_7_fifths, Lead_8_basslead, LongGuiro, LongWhistle, LowAgogo, LowBongo, LowConga, LowFloorTom, LowMidTom, LowTimbale, LowTom, LowWoodBlock, Maracas, Marimba, MelodicTom, MusicBox, MuteCuica, MutedTrumpet, MuteHiConga, MuteTriangle, NoteA, NoteAp, NoteB, NoteC, NoteCp, NoteD, NoteDownA, NoteDownAp, NoteDownB, NoteDownC, NoteDownCp, NoteDownD, NoteDownDp, NoteDownE, NoteDownF, NoteDownFp, NoteDownG, NoteDownGp, NoteDp, NoteE, NoteF, NoteFp, NoteG, NoteGp, NoteUpA, NoteUpAp, NoteUpB, NoteUpC, NoteUpCp, NoteUpD, NoteUpDp, NoteUpE, NoteUpF, NoteUpFp, NoteUpG, NoteUpGp, Oboe, Ocarina, OpenCuica, OpenHiConga, OpenHiHat, OpenTriangle, OrchestraHit, OrchestralHarp, ORGAN, OverdrivenGuitar, Pad_1_newage, Pad_2_warm, Pad_3_polysynth, Pad_4_choir, Pad_5_bowed, Pad_6_metallic, Pad_7_halo, Pad_8_sweep, PanFlute, PedalHiHat, PERCUSSION, PercussiveOrgan, PIANO, Piccolo, PizzicatoStrings, Recorder, ReedOrgan, ReverseCymbal, RideBell, RideCymbal_2, RideCymbal1, RockOrgan, SAX, Seashore, SEASHORE, Shamisen, Shanai, ShortGuiro, ShortWhistle, SideStick, Sitar, Skakuhachi, SlapBass_1, SlapBass_2, SopranoSax, SplashCymbal, STEELDRUM, SteelDrums, StringEnsemble_1, StringEnsemble_2, SynthBass_1, SynthBass_2, SynthBrass_1, SynthBrass_2, SynthDrum, SynthStrings_1, SynthStrings_2, SynthVoice, TaikoDrum, Tambourine, TangoAccordion, TELEPHONE, TelephoneRing, TenorSax, Timpani, TinkleBell, TremoloStrings, Trombone, Trumpet, Tuba, TUBA, TubularBells, Vibraphone, Vibraslap, Viola, Violin, VIOLIN, VoiceOohs, Whistle, WOOD_BLOCK, Woodblock, Xylophone
 
Constructor Summary
MusicBox()
          The default constructor just initializes the MIDI synthesizer and sets the default program for the instruments.
MusicBox(int... instruments)
          The MIDI synthesizer can also be initialized with a list of instrument numbers rather than setting the default program.
 
Method Summary
 int getProgram(int channel)
          Produce the instrument currently assigned to the given channel.
 void initChannels()
          Initialize the program to the default set of instruments defined in SoundConstants.
 void initChannels(int... instruments)
          Initialize the MIDI channels to the given set of instruments.
 boolean isReady()
          Has this music box been initialized?
 void playOff(java.util.ArrayList<Tune> tunes)
          Stop playing all tunes in the given list of Tunes.
 void playOn(java.util.ArrayList<Tune> tunes)
          Play all tunes in the given list of Tunes
 void playTune(Tune tune)
          Play the given tune on the channel assigned to it.
 void stopTune(Tune tune)
          Stop playing the given tune on the channel assigned to it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MusicBox

public MusicBox()
The default constructor just initializes the MIDI synthesizer and sets the default program for the instruments.


MusicBox

public MusicBox(int... instruments)
The MIDI synthesizer can also be initialized with a list of instrument numbers rather than setting the default program.

Method Detail

initChannels

public void initChannels()
Initialize the program to the default set of instruments defined in SoundConstants.


initChannels

public void initChannels(int... instruments)
Initialize the MIDI channels to the given set of instruments. You may give up to 16 instrument numbers (as instrument numbers defined in SoundConstants) to assign to the channels.


getProgram

public int getProgram(int channel)
Produce the instrument currently assigned to the given channel.


playOn

public void playOn(java.util.ArrayList<Tune> tunes)
Play all tunes in the given list of Tunes


playTune

public void playTune(Tune tune)
Play the given tune on the channel assigned to it.


playOff

public void playOff(java.util.ArrayList<Tune> tunes)
Stop playing all tunes in the given list of Tunes.


stopTune

public void stopTune(Tune tune)
Stop playing the given tune on the channel assigned to it.


isReady

public boolean isReady()
Has this music box been initialized?