Class UpdatableSongSession
- All Implemented Interfaces:
PropertyChangeListener,EventListener,ControlTrackProvider,EndOfPlaybackActionProvider,PlaybackSession,SongContextProvider
- Direct Known Subclasses:
UpdatableSongSessionOnePlay
updateSequence(org.jjazz.musiccontrol.api.playbacksession.UpdatableSongSession.Update).
Authorized udpates are notes+control track changes which do not change the Sequence size. Only user phrase modification or removal is supported.
The class uses buffer tracks and mute/unmute tracks to enable on-the-fly sequence changes.
If the BaseSongSession is an instance of UpdateProvider, the UpdatableSongSession listens to updates availability and automatically apply the updates.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA song update produced by an UpdateProvider and processed by the UpdatableSongSession.static interfaceA SongContextSession capability: can provide updates after sequence was generated (i.e. while session is in the GENERATED state).Nested classes/interfaces inherited from interface org.jjazz.musiccontrol.api.playbacksession.PlaybackSession
PlaybackSession.State -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringnewValue = UpdatableSongSession.Update received.Fields inherited from interface org.jjazz.musiccontrol.api.playbacksession.ControlTrackProvider
ENABLED_STATEFields inherited from interface org.jjazz.musiccontrol.api.playbacksession.PlaybackSession
PROP_DIRTY, PROP_LOOP_COUNT, PROP_MUTED_TRACKS, PROP_STATE, PROP_TEMPO -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose()Put session in the CLOSED state and release used resources, so that session can be disposed.booleanOverridden to do the equals only on the underlying BaseSongSession.voidgenerate(boolean silent) Create the sequence and the related data.The bar range corresponding to the sequence.get the control track.Get the current Phrase for each RhythmVoice track.An action to be executed when music playback is stopped or paused (because user stopped it or end of sequence is reached).getFreshCopy(SongContext sgContext) Get a copy of this session in the NEW state for the specified context.intThe sequencer loop count (see Java Sequencer setLoopCount()).longThe tick position of the end of the loop.longThe tick position of the start of the loop.intThe number of playing tracks (excluding the additional double buffering extra tracks).A map giving the original resulting Phrase for each RhythmVoice, in the current context.A map providing the original track id corresponding to each used RhythmVoice in the given context.longThe size in ticks of the original generated sequence.Get the sequence which contains the original song tracks plus additional empty tracks to allow "double buffering modification" via muting/unmuting tracks.static UpdatableSongSessiongetSession(BaseSongSession session) Create or reuse a session for the specified parameters.getState()Get the state of this session.intgetTempo()Get the tempo in BPM.longgetTick(int barIndex) Get the start tick position corresponding to the specified bar.Get the mute status of each track id.inthashCode()Overridden to do the hash only on the underlying BaseSongSession.booleanisDirty()Return true if the sequence is not up-to-date with its underlying data.booleanCheck is this session is enabled.voidvoidvoidsetEnabled(boolean b) Disable the session: session will ignore received updates.toString()voidUpdate the sequence with the specified parameter.
-
Field Details
-
PROP_ENABLED
- See Also:
-
PROP_UPDATE_RECEIVED
newValue = UpdatableSongSession.Update received.- See Also:
-
-
Method Details
-
getSession
Create or reuse a session for the specified parameters.Sessions are cached: if an existing session already exists for the same parameters then return it, otherwise a new session is created.
- Parameters:
session- Must be in the NEW or GENERATED state. If it is an UpdateProvider instance automatically apply the updates when available.- Returns:
-
getBaseSession
-
getFreshCopy
Description copied from interface:PlaybackSessionGet a copy of this session in the NEW state for the specified context.- Specified by:
getFreshCopyin interfacePlaybackSession- Parameters:
sgContext- If null use a copy of this session'SongContext- Returns:
-
generate
Description copied from interface:PlaybackSessionCreate the sequence and the related data.If generation is successful the method changes the state from NEW to GENERATED.
- Specified by:
generatein interfacePlaybackSession- Parameters:
silent- If false a modal progress bar is shown why generating the music.- Throws:
MusicGenerationException
-
getSequence
Get the sequence which contains the original song tracks plus additional empty tracks to allow "double buffering modification" via muting/unmuting tracks.The total number of tracks is 2 * getNbPlayingTracks().
- Specified by:
getSequencein interfacePlaybackSession- Returns:
-
getNbPlayingTracks
public int getNbPlayingTracks()The number of playing tracks (excluding the additional double buffering extra tracks).- Returns:
-
getOriginalSequenceSize
public long getOriginalSequenceSize()The size in ticks of the original generated sequence.- Returns:
-
isEnabled
public boolean isEnabled()Check is this session is enabled.The session is enabled by default upon creation. It might be automatically disabled when our base song session is an UpdateProvider which can not provide updates anymore.
- Returns:
-
setEnabled
public void setEnabled(boolean b) Disable the session: session will ignore received updates.- Parameters:
b-- See Also:
-
updateSequence
Update the sequence with the specified parameter.Update RhythmVoice tracks for which there is an actual change. Changes are first applied to muted "buffer tracks", then we switch the mute status between the buffer and the playing tracks. The transition might be noticeable if notes were still ringing when tracks mute state is switched.
Fire a PROP_UPDATED_RECEIVED change event.
The method does nothing if session is disabled.
- Parameters:
update-- Throws:
IllegalArgumentException- If a MidiEvent tick position is beyond getOriginalSequenceSize(), or if session is not in the GENERATED state.
-
getOriginalRvTrackIdMap
A map providing the original track id corresponding to each used RhythmVoice in the given context.If a song uses rhythms R1 and R2 and context is only on R2 bars, then the map only contains R2 rhythm voices and track id.
- Returns:
- See Also:
-
getOriginalTrackEvents()
-
getOriginalRvPhraseMap
A map giving the original resulting Phrase for each RhythmVoice, in the current context.- Returns:
-
getCurrentRvPhraseMap
Get the current Phrase for each RhythmVoice track.- Returns:
-
getState
Description copied from interface:PlaybackSessionGet the state of this session.- Specified by:
getStatein interfacePlaybackSession- Returns:
- See Also:
-
isDirty
public boolean isDirty()Description copied from interface:PlaybackSessionReturn true if the sequence is not up-to-date with its underlying data.If playback is stopped a new session should be created.
- Specified by:
isDirtyin interfacePlaybackSession- Returns:
- See Also:
-
getTempo
public int getTempo()Description copied from interface:PlaybackSessionGet the tempo in BPM.- Specified by:
getTempoin interfacePlaybackSession- Returns:
- -1 if no meaningful value can be returned.
- See Also:
-
getTracksMuteStatus
Description copied from interface:PlaybackSessionGet the mute status of each track id.Note that track 0 (e.g. mandatory track for sequence name, tempo and time signature changes, etc.) is not included.
- Specified by:
getTracksMuteStatusin interfacePlaybackSession- Returns:
- Key=track id, Value=true if track is muted. Can be null if no meaningful value can be returned.
- See Also:
-
getLoopEndTick
public long getLoopEndTick()Description copied from interface:PlaybackSessionThe tick position of the end of the loop.- Specified by:
getLoopEndTickin interfacePlaybackSession- Returns:
- -1 if no meaningful value can be returned (loop will be at the end of sequence)
-
getLoopStartTick
public long getLoopStartTick()Description copied from interface:PlaybackSessionThe tick position of the start of the loop.- Specified by:
getLoopStartTickin interfacePlaybackSession- Returns:
- -1 if no meaningful value can be returned.
-
getLoopCount
public int getLoopCount()Description copied from interface:PlaybackSessionThe sequencer loop count (see Java Sequencer setLoopCount()).- Specified by:
getLoopCountin interfacePlaybackSession- Returns:
- 0 means sequence is played only once, 1 means sequence is played twice, etc. -1 means loop forever.
-
getBarRange
Description copied from interface:PlaybackSessionThe bar range corresponding to the sequence.- Specified by:
getBarRangein interfacePlaybackSession- Returns:
- Null if no meaningful value can be returned.
-
getTick
public long getTick(int barIndex) Description copied from interface:PlaybackSessionGet the start tick position corresponding to the specified bar.- Specified by:
getTickin interfacePlaybackSession- Returns:
- -1 if no meaningful value can be returned.
-
close
public void close()Description copied from interface:PlaybackSessionPut session in the CLOSED state and release used resources, so that session can be disposed.- Specified by:
closein interfacePlaybackSession- See Also:
-
addPropertyChangeListener
- Specified by:
addPropertyChangeListenerin interfacePlaybackSession
-
removePropertyChangeListener
- Specified by:
removePropertyChangeListenerin interfacePlaybackSession
-
equals
Overridden to do the equals only on the underlying BaseSongSession. -
hashCode
public int hashCode()Overridden to do the hash only on the underlying BaseSongSession. -
getSongContext
- Specified by:
getSongContextin interfaceSongContextProvider
-
getControlTrack
Description copied from interface:ControlTrackProviderget the control track.- Specified by:
getControlTrackin interfaceControlTrackProvider- Returns:
- Null if no contral track available.
-
getEndOfPlaybackAction
Description copied from interface:EndOfPlaybackActionProviderAn action to be executed when music playback is stopped or paused (because user stopped it or end of sequence is reached).- Specified by:
getEndOfPlaybackActionin interfaceEndOfPlaybackActionProvider- Returns:
- Can be null
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-
toString
-