Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
voice.h
Go to the documentation of this file.
1 
8 #ifndef VOICE_H_
9 #define VOICE_H_
10 
11 #include <QList>
12 
13 #include "core/muselement.h"
14 #include "core/note.h"
15 
16 class CAKeySignature;
17 class CATimeSignature;
18 class CAClef;
19 class CALyricsContext;
20 class CARest;
21 
22 class CAVoice {
23  friend class CAStaff; // used for insertion of music elements and updateTimes() when inserting elements and synchronizing voices
24 
25 public:
27  ~CAVoice();
28  inline CAStaff *staff() { return _staff; }
29  inline void setStaff(CAStaff *staff) { _staff = staff; }
30  void clear();
31  CAVoice *clone( CAStaff *newStaff = 0 );
32  void cloneVoiceProperties( CAVoice* v );
33 
35  // Notes, rests and signs manipulation //
37  void append( CAMusElement *elt, bool addToChord=false );
38  bool insert( CAMusElement *eltAfter, CAMusElement *elt, bool addToChord=false );
39  bool remove( CAMusElement *elt, bool updateSignsTimes=true );
42 
44  // Voice analysis and query //
46  inline int musElementCount() { return musElementList().count(); }
47  inline CAMusElement *musElementAt(int i) { return musElementList()[i]; }
48  inline int indexOf(CAMusElement *elt) { return musElementList().indexOf(elt); }
49  inline bool contains(CAMusElement *elt) { return musElementList().contains(elt); }
50 
51  QList<CAMusElement*> getSignList();
52  QList<CANote*> getNoteList();
53  bool containsPitch( int noteName , int timeStart );
54  bool containsPitch( CADiatonicPitch p, int timeStart );
59 
60  CANote *nextNote(int timeStart);
61  CANote *previousNote(int timeStart);
62  CARest *nextRest(int timeStart);
63  CARest *previousRest(int timeStart);
64  CAPlayable *nextPlayable(int timeStart);
65  CAPlayable *previousPlayable(int timeStart);
66 
67  QList<CAMusElement*> getEltByType(CAMusElement::CAMusElementType type, int startTime);
68  QList<CAMusElement*> getPreviousByType(CAMusElement::CAMusElementType type, int startTime);
69 
70  inline QList<CAMusElement*>& musElementList() { return _musElementList; }
71  inline int lastTimeEnd() { return (musElementList().size()?musElementList().back()->timeEnd():0); }
72  inline int lastTimeStart() { return (musElementList().size()?musElementList().back()->timeStart():0); }
73  inline CAMusElement *lastMusElement() { return musElementList().size()?musElementList().back():0; }
74  CADiatonicPitch lastNotePitch(bool inChord=false);
76  CANote* lastNote();
80  QList<CAPlayable*> getChord(int time);
81  QList<CAMusElement*> getBar( int time );
82 
84  // Properties //
86  inline int voiceNumber() { return (staff()?(staff()->voiceIndex(this)+1):1); }
87  inline bool isFirstVoice() { return (voiceNumber()==1); }
88 
90  inline void setStemDirection( CANote::CAStemDirection direction ) { _stemDirection = direction; }
91 
92  inline const QString name() { return _name; }
93  inline void setName(const QString name) { _name = name; }
94 
95  inline unsigned char midiChannel() { return _midiChannel; }
96  inline void setMidiChannel(const unsigned char ch) { _midiChannel = ch; }
97 
98  inline unsigned char midiProgram() { return _midiProgram; }
99  inline void setMidiProgram(const unsigned char program) { _midiProgram = program; }
100 
101  inline QList<CALyricsContext*> lyricsContextList() { return _lyricsContextList; }
103  inline void setLyricsContexts( QList<CALyricsContext*> list ) { _lyricsContextList = list; }
104  inline void addLyricsContexts( QList<CALyricsContext*> list ) { _lyricsContextList += list; }
105  inline bool removeLyricsContext( CALyricsContext *lc ) { return _lyricsContextList.removeAll(lc); }
106 
107 private:
108  bool addNoteToChord(CANote *note, CANote *referenceNote);
109  bool insertMusElement( CAMusElement *before, CAMusElement *elt );
110  bool updateTimes( int idx, int length, bool signsToo=false );
111 
112  QList<CAMusElement *> _musElementList;
113  CAStaff *_staff; // parent staff
114  int _voiceNumber; // voice number starting at 1
116  QList<CALyricsContext*> _lyricsContextList;
117 
118  QString _name;
119 
121  // MIDI properties //
123  unsigned char _midiChannel;
124  unsigned char _midiProgram;
125 };
126 #endif /* VOICE_H_ */