ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | List of all members
PlaybackState Class Reference

This object holds the state of how the currently-in-memory Music sheet should be performed over time. More...

#include <PlaybackState.h>

Inheritance diagram for PlaybackState:
Inheritance graph
[legend]

Public Member Functions

 PlaybackState ()
 Constructor. More...
 
 ~PlaybackState ()
 Destructor. More...
 
virtual void SetToDefaultState ()
 Sets this object to its just-constructed state. More...
 
virtual status_t SetFromArchive (const ConstMessageRef &archive)
 Replaces this sheet's current contents with the contents from (archive) More...
 
virtual status_t SaveToArchive (const MessageRef &archive) const
 Saves this sheet's current contents into (archive) More...
 
virtual uint32 GetCurrentChecksum () const
 Just calls CalculateChecksum(), since this database is very small and thus CalculateChecksum() is still cheap. More...
 
virtual uint32 CalculateChecksum () const
 Calculates and returns a checksum for this object. More...
 
virtual ConstMessageRef SeniorUpdate (const ConstMessageRef &seniorDoMsg)
 Updates our state as specified in the (seniorDoMsg). More...
 
virtual status_t JuniorUpdate (const ConstMessageRef &juniorDoMsg)
 Updates our state as specified in the (juniorDoMsg). More...
 
uint64 GetNetworkStartTimeMicros () const
 Returns the time corresponding to the triggering of playback of the first note in the MusicSheet (or MUSCLE_TIME_NEVER if we shouldn't play) More...
 
uint64 GetMicrosPerChord () const
 Returns the number of microseconds to be allotted to each chord in the MusicSheet. More...
 
uint32 GetPausedIndex () const
 If we're paused, returns the index of the chord that the playhead is currently paused at (or MUSCLE_NO_LIMIT if we aren't paused) More...
 
void SetNetworkStartTimeMicros (uint64 networkStartTimeMicros)
 Sets the time corresponding to the triggering of playback of the first note in the MusicSheet (or MUSCLE_TIME_NEVER if we shouldn't play) More...
 
void SetMicrosPerChord (uint64 microsPerChord, uint64 optNetworkNow=MUSCLE_TIME_NEVER)
 Sets the number of microseconds to be allotted to each chord in the MusicSheet. More...
 
void SetPausedIndex (bool pausedIndex)
 Sets returns the index of the chord that the playhead is currently paused at (or MUSCLE_NO_LIMIT if we don't want to be paused) More...
 
bool IsPaused () const
 Convenience method – returns true iff we are currently paused. More...
 
void SetLoop (bool loop)
 Set true if the music playback should loop; false if it should play through just once. More...
 
bool IsLoop () const
 Returns true iff we should loop playback indefinitely (false means we should play only once) More...
 
void StartPlayback (uint64 networkNow)
 Convenience method – starts playback at the current seek position, if we're not already playing. More...
 
void PausePlayback (uint64 networkNow)
 Convenience method – pauses playback at the current seek position, if we're not already paused. More...
 
void SeekTo (uint64 networkNow, uint32 whichChord)
 Convenience method – seeks the current playback position to the specified chord. More...
 
uint32 GetChordIndexForNetworkTimeStamp (uint64 networkTimeStamp, uint32 optLoopLengthChords) const
 Convenience method: Given a network time stamp, returns the chord-index that corresponds to that time. More...
 
uint64 GetNetworkTimeToPlayChord (uint32 chordIndex) const
 Convenience method: Given a chord index, returns the network-time at which that chord should be played. More...
 
int64 GetPlaybackPositionForNetworkTimeMicroseconds (uint64 networkTimestamp) const
 Convenience method: Given a network-timestamp, returns the corresponding offset from the top of the song (may be negative!) More...
 
virtual String ToString () const
 Returns a string representation of this object, for debugging purposes. More...
 
ZGDatabasePeerSessionGetDatabasePeerSession ()
 Returns a pointer to the ZGDatabasePeerSession object that created us, or NULL if this object was not created by a ZGDatabasePeerSession. More...
 
const ZGDatabasePeerSessionGetDatabasePeerSession () const
 As above, but returns a const/read-only pointer. More...
 

Protected Member Functions

ChoirSessionGetChoirSession ()
 Returns a pointer to the ChoirSession object that created this object. More...
 
const ChoirSessionGetChoirSession () const
 Returns a read-only pointer to the ChoirSession object that created this object. More...
 
ConstMessageRef SendFullStateToGUI (bool allowReviewTrigger)
 Saves the state of this object into a Message and sends that Message to the GUI thread. More...
 
void SendMessageToGUI (const ConstMessageRef &msg, bool allowReviewTrigger)
 Sends the specified Message to the GUI thread. More...
 
void SetReviewResults (uint64 allNotesUsedChord)
 Convenience method; calls SetReviewResults(allNotesUsedChord) on our ChoirSession object. More...
 
const IDatabaseObjectGetDatabaseObject (uint32 whichDatabase) const
 Returns a read-only pointer to the specified IDatabaseObject held by our ZGDatabasePeerSession, or NULL if we don't have a ZGDatabasePeerSession or if the specified database doesn't exist. More...
 
bool IsPeerOnline (const ZGPeerID &pid) const
 Returns true iff the peer with the specified ID is currently on line. More...
 
const Hashtable< ZGPeerID,
ConstMessageRef > & 
GetOnlinePeers () const
 Returns a table of the currently online peers (and their attributes), or an empty table if we have no ZGDatabasePeerSession. More...
 
virtual uint64 GetNetworkTime64 () const
 Returns the current network time, or 0 if we have no ZGDatabasePeerSession. More...
 
virtual uint64 GetRunTime64ForNetworkTime64 (uint64 networkTime64TimeStamp) const
 Returns the local time corresponding to a given network time, or 0 if we have no ZGDatabasePeerSession. More...
 
virtual uint64 GetNetworkTime64ForRunTime64 (uint64 runTime64TimeStamp) const
 Returns the network time corresponding to a given local time, or 0 if we have no ZGDatabasePeerSession. More...
 
virtual int64 GetToNetworkTimeOffset () const
 Returns the number of microseconds that should be added to a GetRunTime64() value to turn it into a GetNetworkTime64() value, or subtracted to do the inverse operation. More...
 

Detailed Description

This object holds the state of how the currently-in-memory Music sheet should be performed over time.

Definition at line 9 of file PlaybackState.h.

Constructor & Destructor Documentation

Constructor.

Destructor.

Member Function Documentation

virtual uint32 CalculateChecksum ( ) const
virtual

Calculates and returns a checksum for this object.

Implements IDatabaseObject.

Referenced by PlaybackState::GetCurrentChecksum().

ChoirSession* GetChoirSession ( )
protectedinherited

Returns a pointer to the ChoirSession object that created this object.

const ChoirSession* GetChoirSession ( ) const
protectedinherited

Returns a read-only pointer to the ChoirSession object that created this object.

uint32 GetChordIndexForNetworkTimeStamp ( uint64  networkTimeStamp,
uint32  optLoopLengthChords 
) const

Convenience method: Given a network time stamp, returns the chord-index that corresponds to that time.

Parameters
networkTimeStamptime-stamp to return a chord-index for
optLoopLengthChordsif valid, we'll use this loop-length in our calculation. If 0 or MUSCLE_TIME_NEVER, we won't.
virtual uint32 GetCurrentChecksum ( ) const
inlinevirtual

Just calls CalculateChecksum(), since this database is very small and thus CalculateChecksum() is still cheap.

Implements IDatabaseObject.

Definition at line 28 of file PlaybackState.h.

References PlaybackState::CalculateChecksum().

const IDatabaseObject* GetDatabaseObject ( uint32  whichDatabase) const
protectedinherited

Returns a read-only pointer to the specified IDatabaseObject held by our ZGDatabasePeerSession, or NULL if we don't have a ZGDatabasePeerSession or if the specified database doesn't exist.

Parameters
whichDatabaseindex of the database object we want to access
ZGDatabasePeerSession* GetDatabasePeerSession ( )
inlineinherited

Returns a pointer to the ZGDatabasePeerSession object that created us, or NULL if this object was not created by a ZGDatabasePeerSession.

(Note that this pointer is not set until after our constructor returns, this method will always return NULL if called from a constructor)

Definition at line 85 of file IDatabaseObject.h.

const ZGDatabasePeerSession* GetDatabasePeerSession ( ) const
inlineinherited

As above, but returns a const/read-only pointer.

Definition at line 88 of file IDatabaseObject.h.

uint64 GetMicrosPerChord ( ) const
inline

Returns the number of microseconds to be allotted to each chord in the MusicSheet.

Definition at line 49 of file PlaybackState.h.

uint64 GetNetworkStartTimeMicros ( ) const
inline

Returns the time corresponding to the triggering of playback of the first note in the MusicSheet (or MUSCLE_TIME_NEVER if we shouldn't play)

Definition at line 46 of file PlaybackState.h.

virtual uint64 GetNetworkTime64 ( ) const
protectedvirtualinherited

Returns the current network time, or 0 if we have no ZGDatabasePeerSession.

Implements INetworkTimeProvider.

virtual uint64 GetNetworkTime64ForRunTime64 ( uint64  runTime64TimeStamp) const
protectedvirtualinherited

Returns the network time corresponding to a given local time, or 0 if we have no ZGDatabasePeerSession.

Parameters
runTime64TimeStampa local-clock time, in microseconds

Implements INetworkTimeProvider.

uint64 GetNetworkTimeToPlayChord ( uint32  chordIndex) const

Convenience method: Given a chord index, returns the network-time at which that chord should be played.

const Hashtable<ZGPeerID, ConstMessageRef>& GetOnlinePeers ( ) const
protectedinherited

Returns a table of the currently online peers (and their attributes), or an empty table if we have no ZGDatabasePeerSession.

uint32 GetPausedIndex ( ) const
inline

If we're paused, returns the index of the chord that the playhead is currently paused at (or MUSCLE_NO_LIMIT if we aren't paused)

Definition at line 52 of file PlaybackState.h.

int64 GetPlaybackPositionForNetworkTimeMicroseconds ( uint64  networkTimestamp) const

Convenience method: Given a network-timestamp, returns the corresponding offset from the top of the song (may be negative!)

virtual uint64 GetRunTime64ForNetworkTime64 ( uint64  networkTime64TimeStamp) const
protectedvirtualinherited

Returns the local time corresponding to a given network time, or 0 if we have no ZGDatabasePeerSession.

Parameters
networkTime64TimeStampa network-clock time, in microseconds

Implements INetworkTimeProvider.

virtual int64 GetToNetworkTimeOffset ( ) const
protectedvirtualinherited

Returns the number of microseconds that should be added to a GetRunTime64() value to turn it into a GetNetworkTime64() value, or subtracted to do the inverse operation.

Note that this value will vary from one moment to the next!

Implements INetworkTimeProvider.

bool IsLoop ( ) const
inline

Returns true iff we should loop playback indefinitely (false means we should play only once)

Definition at line 74 of file PlaybackState.h.

bool IsPaused ( ) const
inline

Convenience method – returns true iff we are currently paused.

Definition at line 68 of file PlaybackState.h.

bool IsPeerOnline ( const ZGPeerID pid) const
protectedinherited

Returns true iff the peer with the specified ID is currently on line.

Parameters
pidThe ID of the peer we are interested in. If we have no ZGDatabasePeerSession then this will always return false.
virtual status_t JuniorUpdate ( const ConstMessageRef &  juniorDoMsg)
virtual

Updates our state as specified in the (juniorDoMsg).

Will only be called on the instance running on the senior peer.

Parameters
juniorDoMsgA Message containing instructions for how to update our state on a junior peer.
Returns
B_NO_ERROR on success, or B_ERROR on failure.

Implements IDatabaseObject.

void PausePlayback ( uint64  networkNow)

Convenience method – pauses playback at the current seek position, if we're not already paused.

Parameters
networkNowThe current network time (used to calculate the network-start-time-micros value)
virtual status_t SaveToArchive ( const MessageRef &  archive) const
virtual

Saves this sheet's current contents into (archive)

Implements IDatabaseObject.

void SeekTo ( uint64  networkNow,
uint32  whichChord 
)

Convenience method – seeks the current playback position to the specified chord.

Parameters
networkNowThe current network time (used to calculate the network-start-time-micros value)
whichChordThe chord to seek to (0 == start of song, 1 == second chord, etc)
ConstMessageRef SendFullStateToGUI ( bool  allowReviewTrigger)
protectedinherited

Saves the state of this object into a Message and sends that Message to the GUI thread.

Parameters
allowReviewTriggerif true, this method may also trigger a review of the current bell-assignments to see if they need updating.
Returns
a read-only reference to the Message we sent, on success, or a NULL reference on failure.
void SendMessageToGUI ( const ConstMessageRef &  msg,
bool  allowReviewTrigger 
)
protectedinherited

Sends the specified Message to the GUI thread.

Parameters
msgThe Message to send to the GUI thread.
allowReviewTriggerif true, this method may also trigger a review of the current bell-assignments to see if they need updating.
virtual ConstMessageRef SeniorUpdate ( const ConstMessageRef &  seniorDoMsg)
virtual

Updates our state as specified in the (seniorDoMsg).

Will only be called on the instance running on the senior peer.

Parameters
seniorDoMsgA Message containing instructions for how to update our state on the senior peer.
Returns
a Message to send to the JuniorUpdate() method on the junior peers on success, or a NULL reference on failure.

Implements IDatabaseObject.

virtual status_t SetFromArchive ( const ConstMessageRef &  archive)
virtual

Replaces this sheet's current contents with the contents from (archive)

Implements IDatabaseObject.

void SetLoop ( bool  loop)
inline

Set true if the music playback should loop; false if it should play through just once.

Definition at line 71 of file PlaybackState.h.

void SetMicrosPerChord ( uint64  microsPerChord,
uint64  optNetworkNow = MUSCLE_TIME_NEVER 
)

Sets the number of microseconds to be allotted to each chord in the MusicSheet.

Parameters
microsPerChordthe new microseconds-per-chord value to use (smaller == faster playback)
optNetworkNowIf specified, and the state is currently set to "playing", we'll use this information to try to keep the current-playback-point roughly constant despite the change in tempo.
void SetNetworkStartTimeMicros ( uint64  networkStartTimeMicros)
inline

Sets the time corresponding to the triggering of playback of the first note in the MusicSheet (or MUSCLE_TIME_NEVER if we shouldn't play)

Definition at line 55 of file PlaybackState.h.

void SetPausedIndex ( bool  pausedIndex)
inline

Sets returns the index of the chord that the playhead is currently paused at (or MUSCLE_NO_LIMIT if we don't want to be paused)

Definition at line 65 of file PlaybackState.h.

void SetReviewResults ( uint64  allNotesUsedChord)
protectedinherited

Convenience method; calls SetReviewResults(allNotesUsedChord) on our ChoirSession object.

Parameters
allNotesUsedChorda bit-chord of CHOIR_NOTE_* values indicating which notes are present in our current song.
virtual void SetToDefaultState ( )
virtual

Sets this object to its just-constructed state.

Implements IDatabaseObject.

void StartPlayback ( uint64  networkNow)

Convenience method – starts playback at the current seek position, if we're not already playing.

Parameters
networkNowThe current network time (used to calculate the network-start-time-micros value)
virtual String ToString ( ) const
virtual

Returns a string representation of this object, for debugging purposes.

Implements IDatabaseObject.


The documentation for this class was generated from the following file: