The Midi Sequences Loader
MidisLoader
stores sequences as a collection of MidiInfo
objects in a HashMap
, keyed by their names. The name and filename for a sequence are obtained from an information file loaded when MidisLoader
is created. The file is assumed to be in the subdirectory Sounds/.
MidisLoader
allows a specified sequence to be played, stopped, resumed, and looped. A SoundsWatcher
can be attached to the sequencer and not to a sequence. MidisLoader
deliberately offers almost the same interface as ClipsLoader
(see Figure 8-2), though it has some internal differences.
MidisLoader
was designed to have one Sequencer
object for playing all the sequences, which avoids the overhead of supporting multiple sequencers. Consequently, one sequence will play at a time. This contrasts with ClipsLoader
, where multiple clips can be playing concurrently since multiple Clip
objects are created by ClipsLoader
. A reference to the sequencer is passed to each MidiInfo
object, thereby giving them the responsibility for playing, stopping, resuming and looping their sequences.
The MidisLoader
initializes the sequencer using initSequencer()
and loads the information file:
// globals private Sequencer sequencer; private HashMap midisMap; private MidiInfo currentMidi = null; // reference to currently playing MidiInfo object public MidisLoader() { midisMap = new HashMap(); initSequencer(); } public MidisLoader(String soundsFnm) { midisMap = new HashMap(); initSequencer(); loadSoundsFile(soundsFnm); ...
Get Killer Game Programming in Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.