ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
MusicSheet.h
Go to the documentation of this file.
1 #ifndef MusicSheet_h
2 #define MusicSheet_h
3 
4 #include "MusicData.h"
5 
6 namespace choir {
7 
10 {
11 public:
13  MusicSheet();
14 
16  MusicSheet(const MusicSheet & rhs);
17 
19  ~MusicSheet();
20 
22  MusicSheet & operator = (const MusicSheet & rhs);
23 
25  virtual void SetToDefaultState();
26 
28  virtual status_t SetFromArchive(const ConstMessageRef & archive);
29 
31  virtual status_t SaveToArchive(const MessageRef & archive) const;
32 
34  status_t UpdateFromArchive(const ConstMessageRef & archive);
35 
37  void SetSongFilePath(const String & songFilePath);
38 
40  const String & GetSongFilePath() const {return _songFilePath;}
41 
43  const OrderedKeysHashtable<uint32, uint64> & GetChordsTable() const {return _chords;}
44 
46  uint64 GetChordAtIndex(uint32 whichChord, bool useLoopingLogic) const {return _chords.GetWithDefault(useLoopingLogic?(whichChord%GetSongLengthInChords(false)):whichChord);}
47 
53  status_t PutChord(uint32 whichChord, uint64 chordValue);
54 
59  void RemoveChord(uint32 whichChord) {(void) PutChord(whichChord, 0);}
60 
62  void InsertChordAt(uint32 whichChord);
63 
65  void DeleteChordAt(uint32 whichChord);
66 
68  uint32 GetSongLengthInChords(bool useLoopingLogic) const {return ((useLoopingLogic)&&(_chords.HasItems())) ? MUSCLE_NO_LIMIT : (_chords.GetLastKeyWithDefault()+1);}
69 
71  uint64 GetAllUsedNotesChord() const {return _usedNotes;}
72 
74  virtual uint32 GetCurrentChecksum() const {return _checksum;}
75 
77  virtual uint32 CalculateChecksum() const;
78 
83  virtual ConstMessageRef SeniorUpdate(const ConstMessageRef & seniorDoMsg);
84 
89  virtual status_t JuniorUpdate(const ConstMessageRef & juniorDoMsg);
90 
92  virtual String ToString() const;
93 
94 private:
95  uint32 CalculateChecksumForChord(uint32 whichChord, uint64 chordValue) const {return ((whichChord+1)*CalculateChecksumForUint64(chordValue));}
96  void MoveChordsBackOneStartingAt(uint32 whichChord);
97  void SetToDefaultStateAux();
98 
99  String _songFilePath; // filepath this song was saved to (also used to generate a user-readable song title)
100  OrderedKeysHashtable<uint32, uint64> _chords; // time-index -> notes-chord (each bit indicates the presence or absence of a note)
101 
102  Hashtable<uint8, uint32> _noteHistogram; // how many times each note is used in this song
103  uint64 _usedNotes; // bit-chord of currently used notes (computed from the histogram)
104 
105  uint32 _checksum; // always kept current, by updating it after each change
106 };
107 DECLARE_REFTYPES(MusicSheet);
108 
109 }; // end namespace choir
110 
111 #endif
virtual ConstMessageRef SeniorUpdate(const ConstMessageRef &seniorDoMsg)
Updates our state as specified in the (seniorDoMsg).
uint64 GetAllUsedNotesChord() const
Returns a bit-chord that describes the full set of all the notes that are currently used anywhere in ...
Definition: MusicSheet.h:71
void DeleteChordAt(uint32 whichChord)
Deletes the chord at the given index (if any).
MusicSheet()
Constructor.
A slight specialization of the IDatabaseObject class, just so I can add some application-specific hel...
Definition: MusicData.h:74
virtual String ToString() const
Returns a string representation of this object, for debugging purposes.
status_t UpdateFromArchive(const ConstMessageRef &archive)
Incrementally updates this sheet's contents, based on the information in the Message.
virtual status_t SaveToArchive(const MessageRef &archive) const
Saves this sheet's current contents into (archive)
virtual status_t SetFromArchive(const ConstMessageRef &archive)
Replaces this sheet's current contents with the contents from (archive)
status_t PutChord(uint32 whichChord, uint64 chordValue)
Places the specified chord into our chords-set.
virtual status_t JuniorUpdate(const ConstMessageRef &juniorDoMsg)
Updates our state as specified in the (juniorDoMsg).
void SetSongFilePath(const String &songFilePath)
Set the user-visible file-path string for this piece of music.
uint64 GetChordAtIndex(uint32 whichChord, bool useLoopingLogic) const
Convenience method – returns the chord at the specified chord-index, or 0 if there are no notes at t...
Definition: MusicSheet.h:46
const String & GetSongFilePath() const
Returns the current user-visible file-path string for this piece of music.
Definition: MusicSheet.h:40
MusicSheet & operator=(const MusicSheet &rhs)
Assignment operator.
virtual void SetToDefaultState()
Clears our state to the state of a just-constructed MusicSheet object.
void InsertChordAt(uint32 whichChord)
Inserts space for a new chord at the given index.
~MusicSheet()
Destructor.
virtual uint32 CalculateChecksum() const
Calculates our current checksum from scratch (expensive!)
void RemoveChord(uint32 whichChord)
Convenience method; removes the given chord from the chords-set, if it exists.
Definition: MusicSheet.h:59
The choir namespace contains the code specific to the ZGChoir demonstration application.
Definition: ChoirNameSpace.h:7
const OrderedKeysHashtable< uint32, uint64 > & GetChordsTable() const
Read-only access to our current table of chords.
Definition: MusicSheet.h:43
This object is the in-memory representation of a song, as a collection of notes over time...
Definition: MusicSheet.h:9
uint32 GetSongLengthInChords(bool useLoopingLogic) const
Returns the length of this song, in chords (i.e.
Definition: MusicSheet.h:68
virtual uint32 GetCurrentChecksum() const
Returns the checksum of this object (which is updated whenever this object's contents change) ...
Definition: MusicSheet.h:74