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_ */
QList< CAMusElement * > _musElementList
Definition: voice.h:112
int _voiceNumber
Definition: voice.h:114
int voiceNumber()
Definition: voice.h:86
CANote::CAStemDirection stemDirection()
Definition: voice.h:89
void addLyricsContext(CALyricsContext *lc)
Definition: voice.h:102
CANote * nextNote(int timeStart)
Definition: voice.cpp:690
CAStemDirection
Direction of the note's stem.
Definition: note.h:20
Definition: clef.h:18
CAMusElement * musElementAt(int i)
Definition: voice.h:47
Represents a key signature sign in the staff.
Definition: keysignature.h:19
unsigned char _midiChannel
Definition: voice.h:123
int lastTimeEnd()
Definition: voice.h:71
bool removeLyricsContext(CALyricsContext *lc)
Definition: voice.h:105
CATimeSignature * getTimeSig(CAMusElement *elt)
Definition: voice.cpp:261
QList< CAMusElement * > getBar(int time)
Definition: voice.cpp:554
CAPlayable * insertInTupletAndVoiceAt(CAPlayable *p, CAPlayable *n)
Definition: voice.cpp:207
void setLyricsContexts(QList< CALyricsContext * > list)
Definition: voice.h:103
Represents a rest in the score.
Definition: rest.h:15
Class which represents a voice in the staff.
Definition: voice.h:22
Represents a time signature in the staff.
Definition: timesignature.h:18
void setMidiProgram(const unsigned char program)
Definition: voice.h:99
QList< CALyricsContext * > lyricsContextList()
Definition: voice.h:101
CAMusElement * previous(CAMusElement *elt)
Definition: voice.cpp:671
void setName(const QString name)
Definition: voice.h:93
CAMusElement * previousByType(CAMusElement::CAMusElementType type, CAMusElement *elt)
Definition: voice.cpp:659
CAVoice(const QString name, CAStaff *staff, CANote::CAStemDirection stemDirection=CANote::StemNeutral, int voiceNumber=0)
Definition: voice.cpp:36
void cloneVoiceProperties(CAVoice *v)
Definition: voice.cpp:85
QList< CAMusElement * > getEltByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:476
~CAVoice()
Definition: voice.cpp:57
int indexOf(CAMusElement *elt)
Definition: voice.h:48
Represents a note in the score.
Definition: note.h:18
CARest * previousRest(int timeStart)
Definition: voice.cpp:747
bool addNoteToChord(CANote *note, CANote *referenceNote)
Definition: voice.cpp:389
QList< CANote * > getNoteList()
Definition: voice.cpp:589
QList< CAMusElement * > getSignList()
Definition: voice.cpp:604
CAKeySignature * getKeySig(CAMusElement *elt)
Definition: voice.cpp:274
CAPlayable * nextPlayable(int timeStart)
Definition: voice.cpp:766
int lastTimeStart()
Definition: voice.h:72
int voiceIndex(CAVoice *voice)
Definition: staff.h:36
QList< CAMusElement * > & musElementList()
Definition: voice.h:70
Musical note pitch.
Definition: diatonicpitch.h:14
CAMusElement * lastMusElement()
Definition: voice.h:73
void setStaff(CAStaff *staff)
Definition: voice.h:29
CAMusElementType
Definition: muselement.h:22
CAStaff * _staff
Definition: voice.h:113
QString _name
Definition: voice.h:118
void addLyricsContexts(QList< CALyricsContext * > list)
Definition: voice.h:104
bool isFirstVoice()
Definition: voice.h:87
bool updateTimes(int idx, int length, bool signsToo=false)
Definition: voice.cpp:807
void append(CAMusElement *elt, bool addToChord=false)
Definition: voice.cpp:123
void setMidiChannel(const unsigned char ch)
Definition: voice.h:96
unsigned char _midiProgram
Definition: voice.h:124
CAPlayable * lastPlayableElt()
Definition: voice.cpp:447
QList< CAPlayable * > getChord(int time)
Definition: voice.cpp:524
Definition: note.h:21
bool insert(CAMusElement *eltAfter, CAMusElement *elt, bool addToChord=false)
Definition: voice.cpp:157
An abstract class which represents every music element in the score.
Definition: muselement.h:20
One stanza line of lyrics.
Definition: lyricscontext.h:19
CAVoice * clone(CAStaff *newStaff=0)
Definition: voice.cpp:74
CAMusElement * next(CAMusElement *elt)
Definition: voice.cpp:619
Playable instances of music elements.
Definition: playable.h:18
CANote * previousNote(int timeStart)
Definition: voice.cpp:709
CAStaff * staff()
Definition: voice.h:28
Represents a staff in the sheet.
Definition: staff.h:24
CANote * lastNote()
Definition: voice.cpp:461
void clear()
Definition: voice.cpp:100
bool containsPitch(int noteName, int timeStart)
Definition: voice.cpp:869
CAClef * getClef(CAMusElement *elt)
Definition: voice.cpp:248
CADiatonicPitch lastNotePitch(bool inChord=false)
Definition: voice.cpp:419
QList< CAMusElement * > getPreviousByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:500
CARest * nextRest(int timeStart)
Definition: voice.cpp:728
int musElementCount()
Definition: voice.h:46
CAPlayable * previousPlayable(int timeStart)
Definition: voice.cpp:785
bool insertMusElement(CAMusElement *before, CAMusElement *elt)
Definition: voice.cpp:352
QList< CALyricsContext * > _lyricsContextList
Definition: voice.h:116
CANote::CAStemDirection _stemDirection
Definition: voice.h:115
unsigned char midiChannel()
Definition: voice.h:95
bool synchronizeMusElements()
Definition: voice.cpp:828
unsigned char midiProgram()
Definition: voice.h:98
void setStemDirection(CANote::CAStemDirection direction)
Definition: voice.h:90
bool contains(CAMusElement *elt)
Definition: voice.h:49
CAMusElement * nextByType(CAMusElement::CAMusElementType type, CAMusElement *elt)
Definition: voice.cpp:645
const QString name()
Definition: voice.h:92