|
Canorus
0.7
|
00001 00008 #ifndef VOICE_H_ 00009 #define VOICE_H_ 00010 00011 #include <QList> 00012 00013 #include "core/muselement.h" 00014 #include "core/note.h" 00015 00016 class CAKeySignature; 00017 class CATimeSignature; 00018 class CAClef; 00019 class CALyricsContext; 00020 class CARest; 00021 00022 class CAVoice { 00023 friend class CAStaff; // used for insertion of music elements and updateTimes() when inserting elements and synchronizing voices 00024 00025 public: 00026 CAVoice( const QString name, CAStaff *staff, CANote::CAStemDirection stemDirection=CANote::StemNeutral, int voiceNumber=0 ); 00027 ~CAVoice(); 00028 inline CAStaff *staff() { return _staff; } 00029 inline void setStaff(CAStaff *staff) { _staff = staff; } 00030 void clear(); 00031 CAVoice *clone( CAStaff *newStaff = 0 ); 00032 void cloneVoiceProperties( CAVoice* v ); 00033 00035 // Notes, rests and signs manipulation // 00037 void append( CAMusElement *elt, bool addToChord=false ); 00038 bool insert( CAMusElement *eltAfter, CAMusElement *elt, bool addToChord=false ); 00039 bool remove( CAMusElement *elt, bool updateSignsTimes=true ); 00040 CAPlayable* insertInTupletAndVoiceAt( CAPlayable *p, CAPlayable *n ); 00041 bool synchronizeMusElements(); 00042 00044 // Voice analysis and query // 00046 inline int musElementCount() { return musElementList().count(); } 00047 inline CAMusElement *musElementAt(int i) { return musElementList()[i]; } 00048 inline int indexOf(CAMusElement *elt) { return musElementList().indexOf(elt); } 00049 inline bool contains(CAMusElement *elt) { return musElementList().contains(elt); } 00050 00051 QList<CAMusElement*> getSignList(); 00052 QList<CANote*> getNoteList(); 00053 bool containsPitch( int noteName , int timeStart ); 00054 bool containsPitch( CADiatonicPitch p, int timeStart ); 00055 CAMusElement *next(CAMusElement *elt); 00056 CAMusElement *previous(CAMusElement *elt); 00057 CAMusElement *nextByType(CAMusElement::CAMusElementType type, CAMusElement *elt); 00058 CAMusElement *previousByType(CAMusElement::CAMusElementType type, CAMusElement *elt); 00059 00060 CANote *nextNote(int timeStart); 00061 CANote *previousNote(int timeStart); 00062 CARest *nextRest(int timeStart); 00063 CARest *previousRest(int timeStart); 00064 CAPlayable *nextPlayable(int timeStart); 00065 CAPlayable *previousPlayable(int timeStart); 00066 00067 QList<CAMusElement*> getEltByType(CAMusElement::CAMusElementType type, int startTime); 00068 QList<CAMusElement*> getPreviousByType(CAMusElement::CAMusElementType type, int startTime); 00069 00070 inline QList<CAMusElement*>& musElementList() { return _musElementList; } 00071 inline int lastTimeEnd() { return (musElementList().size()?musElementList().back()->timeEnd():0); } 00072 inline int lastTimeStart() { return (musElementList().size()?musElementList().back()->timeStart():0); } 00073 inline CAMusElement *lastMusElement() { return musElementList().size()?musElementList().back():0; } 00074 CADiatonicPitch lastNotePitch(bool inChord=false); 00075 CAPlayable* lastPlayableElt(); 00076 CANote* lastNote(); 00077 CATimeSignature* getTimeSig(CAMusElement *elt); 00078 CAKeySignature* getKeySig(CAMusElement *elt); 00079 CAClef* getClef(CAMusElement *elt); 00080 QList<CAPlayable*> getChord(int time); 00081 QList<CAMusElement*> getBar( int time ); 00082 00084 // Properties // 00086 inline int voiceNumber() { return (staff()?(staff()->voiceIndex(this)+1):1); } 00087 inline bool isFirstVoice() { return (voiceNumber()==1); } 00088 00089 inline CANote::CAStemDirection stemDirection() { return _stemDirection; } 00090 inline void setStemDirection( CANote::CAStemDirection direction ) { _stemDirection = direction; } 00091 00092 inline const QString name() { return _name; } 00093 inline void setName(const QString name) { _name = name; } 00094 00095 inline unsigned char midiChannel() { return _midiChannel; } 00096 inline void setMidiChannel(const unsigned char ch) { _midiChannel = ch; } 00097 00098 inline unsigned char midiProgram() { return _midiProgram; } 00099 inline void setMidiProgram(const unsigned char program) { _midiProgram = program; } 00100 00101 inline QList<CALyricsContext*> lyricsContextList() { return _lyricsContextList; } 00102 inline void addLyricsContext( CALyricsContext *lc ) { _lyricsContextList << lc; } 00103 inline void setLyricsContexts( QList<CALyricsContext*> list ) { _lyricsContextList = list; } 00104 inline void addLyricsContexts( QList<CALyricsContext*> list ) { _lyricsContextList += list; } 00105 inline bool removeLyricsContext( CALyricsContext *lc ) { return _lyricsContextList.removeAll(lc); } 00106 00107 private: 00108 bool addNoteToChord(CANote *note, CANote *referenceNote); 00109 bool insertMusElement( CAMusElement *before, CAMusElement *elt ); 00110 bool updateTimes( int idx, int length, bool signsToo=false ); 00111 00112 QList<CAMusElement *> _musElementList; 00113 CAStaff *_staff; // parent staff 00114 int _voiceNumber; // voice number starting at 1 00115 CANote::CAStemDirection _stemDirection; 00116 QList<CALyricsContext*> _lyricsContextList; 00117 00118 QString _name; 00119 00121 // MIDI properties // 00123 unsigned char _midiChannel; 00124 unsigned char _midiProgram; 00125 }; 00126 #endif /* VOICE_H_ */
1.8.0