Class MusicController
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
,MetaEventListener
The PlaybackSession provides the Sequence to be played and various related data which impact how the MusicController manage the Sequence.
Property changes are fired for:
- start/pause/stop/disabled state changes
Use NoteListener to get notified of note ON/OFF events. Use PlaybackListener to get notified of other events (e.g. bar/beat changes)
during playback. Note that listeners will be notified out of the Swing EDT.
The current output synth latency is taken into account to fire events to NoteListeners and PlaybackListeners.
Use acquireSequencer()/releaseSequencer() if you want to use the Java system sequencer independently.
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionacquireSequencer
(Object lockHolder) Try to temporarily acquire the java sequencer opened and connected to the default Midi out device.void
addNoteListener
(NoteListener listener) Add a listener of note ON/OFF events.void
addPlaybackListener
(PlaybackListener listener) Add a listener to be notified of playback bar/beat changes events etc.void
void
changePausedBar
(int barIndex) Change the current bar when in PAUSED state.The current playback position updated at every natural beat (eg 0, 1, 2, 3 in 4/4).The current CLI_ChordSymbol being played.The current SongPart being played.static MusicController
Get the current playback session.getState()
boolean
True if the current playing session is a special arranger session.boolean
void
meta
(MetaMessage meta) void
pause()
Stop the playback of the sequence and leave the position unchanged.void
play
(int fromBarIndex) Play the current playback session from the specified bar.void
void
releaseSequencer
(Object lockHolder) Release the external sequencer lock.void
removeNoteListener
(NoteListener listener) void
removePlaybackListener
(PlaybackListener listener) void
void
resume()
Resume playback from the pause state.void
setDebugPlayedSequence
(boolean b) void
setPlaybackSession
(PlaybackSession session, boolean silent) Set the current playback session and try to generate the sequence if required.void
stop()
Stop the playback of the sequence if it was playing, and reset the position to the beginning of the sequence.
-
Field Details
-
PROP_STATE
- See Also:
-
PROP_PLAYBACK_SESSION
- See Also:
-
-
Method Details
-
getInstance
-
acquireSequencer
Try to temporarily acquire the java sequencer opened and connected to the default Midi out device.You can acquire the sequencer only if MusicController is in the STOPPED state. If acquisition is successful the MusicController is put in DISABLED state since it can't use the sequencer anymore. When the caller is done with the sequencer, he must call releaseSequencer(lockHolder) so that the MusicController can use it again.
- Parameters:
lockHolder
- Must be non-null- Returns:
- Null if sequencer has already a different lock or if MusicController is in the PLAYING state.
-
releaseSequencer
Release the external sequencer lock.Once released, MusicController becomes able to take the Sequencer lock when playing music.
- Parameters:
lockHolder
-- Throws:
IllegalArgumentException
- If lockHolder does not match
-
setPlaybackSession
public void setPlaybackSession(PlaybackSession session, boolean silent) throws MusicGenerationException Set the current playback session and try to generate the sequence if required.If MusicController is paused then current playback is stopped.
- Parameters:
session
- Can be null. If not null, must be in NEW or GENERATED state, and can't be dirty.silent
- If false and session needs to be generated, a progress dialog is shown while generating music- Throws:
MusicGenerationException
- E.g. if song is already playing, missing start section chord, etc.IllegalStateException
- If session is dirty or is CLOSED.- See Also:
-
play
Play the current playback session from the specified bar.Do nothing if no playback session set.
- Parameters:
fromBarIndex
-- Throws:
MusicGenerationException
- If a problem occurred which prevents song playing: no Midi out, rhythm music generation problem, MusicController state is not PAUSED nor STOPPED, etc.IllegalStateException
- If current session is not in the GENERATED state, or if fromBarIndex is invalid
-
resume
Resume playback from the pause state.If state is not PAUSED, nothing is done.
- Throws:
MusicGenerationException
- For example if state==DISABLEDIllegalStateException
- If current playback session is not in the GENERATED state.
-
stop
public void stop()Stop the playback of the sequence if it was playing, and reset the position to the beginning of the sequence. -
pause
public void pause()Stop the playback of the sequence and leave the position unchanged.If state is not PLAYING, do nothing. If session is dirty, use stop() instead.
-
changePausedBar
public void changePausedBar(int barIndex) Change the current bar when in PAUSED state.Do nothing if not in PAUSED state.
- Parameters:
barIndex
-- Throws:
IllegalArgumentException
- If bar index is not valid for the current PlaybackSession.
-
getCurrentBeatPosition
The current playback position updated at every natural beat (eg 0, 1, 2, 3 in 4/4).Note: value is meaningful only for PlaybackSessions which are also ControlTrackProviders. Otherwise returned value is always bar=0, beat=0.
- Returns:
- See Also:
-
getCurrentChordSymbol
The current CLI_ChordSymbol being played.Note: value is meaningful only when playback is on or paused, and for PlaybackSessions which are also ControlTrackProviders. Otherwise return value is null.
- Returns:
- Can be null.
- See Also:
-
getCurrentSongPart
The current SongPart being played.Note: value is meaningful only when playback is on or paused, and for PlaybackSessions which are also ControlTrackProviders and SongContextProviders. Otherwise return value is null.
- Returns:
- Can be null.
- See Also:
-
getState
-
getPlaybackSession
Get the current playback session.- Returns:
- Can be null if no song has ever been played.
-
isArrangerPlaying
public boolean isArrangerPlaying()True if the current playing session is a special arranger session.- Returns:
-
setDebugPlayedSequence
public void setDebugPlayedSequence(boolean b) -
isDebugPlayedSequence
public boolean isDebugPlayedSequence() -
addNoteListener
Add a listener of note ON/OFF events.Listeners will be called out of the Swing EDT (Event Dispatch Thread).
- Parameters:
listener
-
-
removeNoteListener
-
addPlaybackListener
Add a listener to be notified of playback bar/beat changes events etc.Listeners will be called out of the Swing EDT (Event Dispatch Thread).
- Parameters:
listener
-
-
removePlaybackListener
-
addPropertyChangeListener
-
removePropertyChangeListener
-
meta
- Specified by:
meta
in interfaceMetaEventListener
-
propertyChange
- Specified by:
propertyChange
in interfacePropertyChangeListener
-