public class MoppyManager extends Object implements StatusConsumer, AutoCloseable
Modifier and Type | Class and Description |
---|---|
static class |
MoppyManager.Callback
Callbacks fired when each method has completed successfully.
|
Constructor and Description |
---|
MoppyManager(Context context)
Constructs a new
MoppyManager . |
Modifier and Type | Method and Description |
---|---|
boolean |
addReceiver(Receiver receiver)
Adds a
Receiver to forward all MIDI messages to, regardless of if they originated on
the MIDI wire input or the MIDI file input. |
void |
close()
Releases held resources.
|
Receiver |
getInputReceiver()
Gets the
Receiver that can be used to send MIDI messages to Moppy. |
MidiLibrary.MidiFile |
getLoadedFile()
Gets the currently loaded
MidiLibrary.MidiFile . |
long |
getMillisecondsLength()
Uses the calculations of the loaded
Sequence to get the song length. |
long |
getMillisecondsPosition()
Gets the current position within the loaded song.
|
Receiver |
getReceiver()
Gets the
ReceiverDispatcher that messages are forwarded to. |
boolean |
isPlaying()
Checks if the
Sequencer is playing. |
void |
load(MidiLibrary.MidiFile file,
Context context)
Loads a
MidiLibrary.MidiFile into the sequencer. |
void |
pause()
Pauses playback if not already paused.
|
void |
play()
Starts playback if not already playing.
|
void |
receiveUpdate(StatusUpdate update)
Triggered when the sequencer posts a
StatusUpdate . |
void |
registerCallback(MoppyManager.Callback callback)
Registers a
MoppyManager.Callback with this MoppyManager to receive calls upon method completion. |
boolean |
removeReceiver(Receiver receiver)
Removes a
Receiver from the list to forward messages to. |
void |
seekTo(long millis,
boolean callPlay)
Seeks to the provided millisecond position within the loaded song.
|
void |
stop()
Stops and resets playback.
|
boolean |
unregisterCallback(MoppyManager.Callback callback)
Removes a
MoppyManager.Callback registered with this MoppManager . |
public MoppyManager(Context context) throws MidiUnavailableException
MoppyManager
.context
- the context to create the MoppyManager
inMidiUnavailableException
- if a MoppyMIDISequencer
cannot be createdpublic void receiveUpdate(StatusUpdate update)
StatusUpdate
.receiveUpdate
in interface StatusConsumer
update
- the posted StatusUpdate
public void close()
MoppyManager
's destruction.close
in interface AutoCloseable
public void play()
public void pause()
public void stop()
StatusType.SEQUENCE_STOPPED
message is broadcasted to all registered StatusConsumer
s,
and connected Moppy devices are sent a MoppyMessage.SYS_RESET
message.public void load(MidiLibrary.MidiFile file, Context context) throws IOException, InvalidMidiDataException
MidiLibrary.MidiFile
into the sequencer.file
- the file to loadcontext
- the Context
to use to open the fileIOException
- if the file couldn't be openedInvalidMidiDataException
- if the file wasn't a valid MIDI filepublic long getMillisecondsLength()
Sequence
to get the song length.public long getMillisecondsPosition()
public void seekTo(long millis, boolean callPlay)
millis
is greater
than the length of the song, the Sequencer
is advanced to the end of the song. Since
reaching the end of the song automatically pauses the Sequencer
, the parameter
callPlay
is provided to allow the caller to automatically restart playback after the seek.millis
- the position to seek tocallPlay
- true
to ensure the Sequencer
is playing, false
to not alter the playback statepublic boolean isPlaying()
Sequencer
is playing.true
if playing, otherwise false
public MidiLibrary.MidiFile getLoadedFile()
MidiLibrary.MidiFile
.MidiFile
public Receiver getInputReceiver()
Receiver
that can be used to send MIDI messages to Moppy.Receiver
to send messages topublic Receiver getReceiver()
ReceiverDispatcher
that messages are forwarded to.ReceiverDispatcher
as a Receiver
addReceiver(Receiver)
,
removeReceiver(Receiver)
public boolean addReceiver(Receiver receiver)
Receiver
to forward all MIDI messages to, regardless of if they originated on
the MIDI wire input or the MIDI file input. See ReceiverDispatcher.add(Receiver)
for
more information.receiver
- the Receiver
to addtrue
if receiver
was added, false
if receiver
was null or duplicateremoveReceiver(Receiver)
public boolean removeReceiver(Receiver receiver)
Receiver
from the list to forward messages to.receiver
- the Receiver
to removetrue
if receiver
was removed, false
if it was null
or not addedaddReceiver(Receiver)
public void registerCallback(MoppyManager.Callback callback)
MoppyManager.Callback
with this MoppyManager
to receive calls upon method completion.callback
- the Callback
instance to registerpublic boolean unregisterCallback(MoppyManager.Callback callback)
MoppyManager.Callback
registered with this MoppManager
.callback
- the Callback
instance to unregistertrue
if callback
was formerly registered, otherwise false
registerCallback(Callback)