ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
PlaybackState.h
Go to the documentation of this file.
1 #ifndef PlaybackState_h
2 #define PlaybackState_h
3 
4 #include "MusicData.h"
5 
6 namespace choir {
7 
10 {
11 public:
13  PlaybackState();
14 
17 
19  virtual void SetToDefaultState();
20 
22  virtual status_t SetFromArchive(const ConstMessageRef & archive);
23 
25  virtual status_t SaveToArchive(const MessageRef & archive) const;
26 
28  virtual uint32 GetCurrentChecksum() const {return CalculateChecksum();}
29 
31  virtual uint32 CalculateChecksum() const;
32 
37  virtual ConstMessageRef SeniorUpdate(const ConstMessageRef & seniorDoMsg);
38 
43  virtual status_t JuniorUpdate(const ConstMessageRef & juniorDoMsg);
44 
46  uint64 GetNetworkStartTimeMicros() const {return _networkStartTimeMicros;}
47 
49  uint64 GetMicrosPerChord() const {return _microsPerChord;}
50 
52  uint32 GetPausedIndex() const {return _pausedIndex;};
53 
55  void SetNetworkStartTimeMicros(uint64 networkStartTimeMicros) {_networkStartTimeMicros = networkStartTimeMicros;}
56 
62  void SetMicrosPerChord(uint64 microsPerChord, uint64 optNetworkNow = MUSCLE_TIME_NEVER);
63 
65  void SetPausedIndex(bool pausedIndex) {_pausedIndex = pausedIndex;};
66 
68  bool IsPaused() const {return (_pausedIndex != MUSCLE_NO_LIMIT);}
69 
71  void SetLoop(bool loop) {_loop = loop;}
72 
74  bool IsLoop() const {return _loop;}
75 
79  void StartPlayback(uint64 networkNow);
80 
84  void PausePlayback(uint64 networkNow);
85 
90  void SeekTo(uint64 networkNow, uint32 whichChord);
91 
96  uint32 GetChordIndexForNetworkTimeStamp(uint64 networkTimeStamp, uint32 optLoopLengthChords) const;
97 
99  uint64 GetNetworkTimeToPlayChord(uint32 chordIndex) const;
100 
102  int64 GetPlaybackPositionForNetworkTimeMicroseconds(uint64 networkTimestamp) const;
103 
105  virtual String ToString() const;
106 
107 private:
108  void SetToDefaultStateAux();
109  MessageRef SeniorAdjustPlaybackState(uint32 whatCode, const uint64 * optNewMicrosPerChord, const uint32 * optSeekTo, bool * optSetLoop);
110 
111  uint64 _networkStartTimeMicros; // the network-time at which chord #0 is/was to be played
112  uint64 _microsPerChord; // How many microseconds each chord represents (i.e. this controls the playback tempo)
113  uint32 _pausedIndex; // If playback is paused, this is the chord it's currently at; if MUSCLE_NO_LIMIT then we're playing
114  bool _loop; // If true, then playback should loop forever; if false, we'll only play through once
115 };
116 DECLARE_REFTYPES(PlaybackState);
117 
118 }; // end namespace choir
119 
120 #endif
virtual status_t JuniorUpdate(const ConstMessageRef &juniorDoMsg)
Updates our state as specified in the (juniorDoMsg).
~PlaybackState()
Destructor.
void SetMicrosPerChord(uint64 microsPerChord, uint64 optNetworkNow=MUSCLE_TIME_NEVER)
Sets the number of microseconds to be allotted to each chord in the MusicSheet.
A slight specialization of the IDatabaseObject class, just so I can add some application-specific hel...
Definition: MusicData.h:74
uint64 GetNetworkTimeToPlayChord(uint32 chordIndex) const
Convenience method: Given a chord index, returns the network-time at which that chord should be playe...
bool IsLoop() const
Returns true iff we should loop playback indefinitely (false means we should play only once) ...
Definition: PlaybackState.h:74
uint32 GetChordIndexForNetworkTimeStamp(uint64 networkTimeStamp, uint32 optLoopLengthChords) const
Convenience method: Given a network time stamp, returns the chord-index that corresponds to that time...
This object holds the state of how the currently-in-memory Music sheet should be performed over time...
Definition: PlaybackState.h:9
uint32 GetPausedIndex() const
If we're paused, returns the index of the chord that the playhead is currently paused at (or MUSCLE_N...
Definition: PlaybackState.h:52
void SetPausedIndex(bool pausedIndex)
Sets returns the index of the chord that the playhead is currently paused at (or MUSCLE_NO_LIMIT if w...
Definition: PlaybackState.h:65
PlaybackState()
Constructor.
void SetNetworkStartTimeMicros(uint64 networkStartTimeMicros)
Sets the time corresponding to the triggering of playback of the first note in the MusicSheet (or MUS...
Definition: PlaybackState.h:55
virtual uint32 GetCurrentChecksum() const
Just calls CalculateChecksum(), since this database is very small and thus CalculateChecksum() is sti...
Definition: PlaybackState.h:28
void StartPlayback(uint64 networkNow)
Convenience method – starts playback at the current seek position, if we're not already playing...
void SeekTo(uint64 networkNow, uint32 whichChord)
Convenience method – seeks the current playback position to the specified chord. ...
virtual uint32 CalculateChecksum() const
Calculates and returns a checksum for this object.
virtual String ToString() const
Returns a string representation of this object, for debugging purposes.
virtual status_t SetFromArchive(const ConstMessageRef &archive)
Replaces this sheet's current contents with the contents from (archive)
virtual status_t SaveToArchive(const MessageRef &archive) const
Saves this sheet's current contents into (archive)
uint64 GetMicrosPerChord() const
Returns the number of microseconds to be allotted to each chord in the MusicSheet.
Definition: PlaybackState.h:49
virtual ConstMessageRef SeniorUpdate(const ConstMessageRef &seniorDoMsg)
Updates our state as specified in the (seniorDoMsg).
The choir namespace contains the code specific to the ZGChoir demonstration application.
Definition: ChoirNameSpace.h:7
uint64 GetNetworkStartTimeMicros() const
Returns the time corresponding to the triggering of playback of the first note in the MusicSheet (or ...
Definition: PlaybackState.h:46
int64 GetPlaybackPositionForNetworkTimeMicroseconds(uint64 networkTimestamp) const
Convenience method: Given a network-timestamp, returns the corresponding offset from the top of the s...
virtual void SetToDefaultState()
Sets this object to its just-constructed state.
bool IsPaused() const
Convenience method – returns true iff we are currently paused.
Definition: PlaybackState.h:68
void SetLoop(bool loop)
Set true if the music playback should loop; false if it should play through just once.
Definition: PlaybackState.h:71
void PausePlayback(uint64 networkNow)
Convenience method – pauses playback at the current seek position, if we're not already paused...