Canorus  0.0
voice.h
Go to the documentation of this file.
1 
8 #ifndef VOICE_H_
9 #define VOICE_H_
10 
11 #include <QList> // music elements container
12 
13 #include "score/muselement.h"
14 #include "score/note.h"
15 
16 class CAKeySignature;
17 class CATimeSignature;
18 class CAClef;
19 class CALyricsContext;
20 class CARest;
21 class CATempo;
22 
23 class CAVoice {
24  friend class CAStaff; // used for insertion of music elements and updateTimes() when inserting elements and synchronizing voices
25 
26 public:
28  ~CAVoice();
29  inline CAStaff *staff() { return _staff; }
30  inline void setStaff(CAStaff *staff) { _staff = staff; }
31  void clear();
32  CAVoice *clone( CAStaff *newStaff = 0 );
33  void cloneVoiceProperties( CAVoice* v );
34 
36  // Notes, rests and signs manipulation //
38  void append( CAMusElement *elt, bool addToChord=false );
39  bool insert( CAMusElement *eltAfter, CAMusElement *elt, bool addToChord=false );
40  bool remove( CAMusElement *elt, bool updateSignsTimes=true );
43 
45  // Voice analysis and query //
47  inline const QList<CAMusElement*>& musElementList() { return _musElementList; }
48 
49  QList<CAMusElement*> getSignList();
50  QList<CANote*> getNoteList();
51  bool containsPitch( int noteName , int timeStart );
52  bool containsPitch( CADiatonicPitch p, int timeStart );
57 
58  CANote *nextNote(int timeStart);
59  CANote *previousNote(int timeStart);
60  CARest *nextRest(int timeStart);
61  CARest *previousRest(int timeStart);
62  CAPlayable *nextPlayable(int timeStart);
63  CAPlayable *previousPlayable(int timeStart);
64 
65  bool binarySearch_startTime(int time, int& position);
66 
68  QList<CAMusElement*> getEltByType(CAMusElement::CAMusElementType type, int startTime);
70  QList<CAMusElement*> getPreviousByType(CAMusElement::CAMusElementType type, int startTime);
71 
72  inline int lastTimeEnd() { return (musElementList().size()?musElementList().back()->timeEnd():0); }
73  inline int lastTimeStart() { return (musElementList().size()?musElementList().back()->timeStart():0); }
74  inline CAMusElement *lastMusElement() { return musElementList().size()?musElementList().back():0; }
75  CADiatonicPitch lastNotePitch(bool inChord=false);
77  CANote* lastNote();
81  QList<CAPlayable*> getChord( int time );
82  QList<CAMusElement*> getBar( int time );
83  CATempo *getTempo( int time );
84 
85  QList<CAMusElement*> getKeySignature(int startTime);
86  QList<CAMusElement*> getTimeSignature(int startTime);
87  QList<CAMusElement*> getClef(int startTime);
88  QList<CAMusElement*> getPreviousKeySignature(int startTime);
89  QList<CAMusElement*> getPreviousTimeSignature(int startTime);
90  QList<CAMusElement*> getPreviousClef(int startTime);
91 
93  // Properties //
95  inline int voiceNumber() { return (staff()?(staff()->voiceList().indexOf(this)+1):1); }
96  inline bool isFirstVoice() { return (voiceNumber()==1); }
97 
99  inline void setStemDirection( CANote::CAStemDirection direction ) { _stemDirection = direction; }
100 
101  inline const QString name() { return _name; }
102  inline void setName(const QString name) { _name = name; }
103 
104  inline unsigned char midiChannel() { return _midiChannel; }
105  inline void setMidiChannel(const unsigned char ch) { _midiChannel = ch; }
106 
107  inline unsigned char midiProgram() { return _midiProgram; }
108  inline void setMidiProgram(const unsigned char program) { _midiProgram = program; }
109 
110  inline char midiPitchOffset() { return _midiPitchOffset; }
112 
113  inline const QList<CALyricsContext*>& lyricsContextList() { return _lyricsContextList; }
115  inline void setLyricsContexts( QList<CALyricsContext*> list ) { _lyricsContextList = list; }
116  inline void addLyricsContexts( QList<CALyricsContext*> list ) { _lyricsContextList += list; }
117  inline bool removeLyricsContext( CALyricsContext *lc ) { return _lyricsContextList.removeAll(lc); }
118 
119 private:
120  bool addNoteToChord(CANote *note, CANote *referenceNote);
121  bool insertMusElement( CAMusElement *before, CAMusElement *elt );
122  bool updateTimes( int idx, int length, bool signsToo=false );
123 
124  // list of all the music elements
125  QList<CAMusElement *> _musElementList;
126  CAStaff *_staff; // parent staff
127 
129  QList<CALyricsContext*> _lyricsContextList;
130 
131  QString _name;
132 
134  // MIDI properties //
136  unsigned char _midiChannel;
137  unsigned char _midiProgram;
139 };
140 #endif /* VOICE_H_ */
QList< CAMusElement * > _musElementList
Definition: voice.h:125
Tempo mark.
Definition: tempo.h:14
int voiceNumber()
Definition: voice.h:95
CANote::CAStemDirection stemDirection()
Definition: voice.h:98
void addLyricsContext(CALyricsContext *lc)
Definition: voice.h:114
CATempo * getTempo(int time)
Definition: voice.cpp:998
CANote * nextNote(int timeStart)
Definition: voice.cpp:784
CAStemDirection
Direction of the note's stem.
Definition: note.h:20
void setMidiPitchOffset(const char midiPitchOffset)
Definition: voice.h:111
Definition: clef.h:18
Represents a key signature sign in the staff.
Definition: keysignature.h:19
bool remove(CAMusElement *elt, bool updateSignsTimes=true)
Definition: voice.cpp:307
unsigned char _midiChannel
Definition: voice.h:136
int lastTimeEnd()
Definition: voice.h:72
bool removeLyricsContext(CALyricsContext *lc)
Definition: voice.h:117
CATimeSignature * getTimeSig(CAMusElement *elt)
Definition: voice.cpp:266
QList< CAMusElement * > getBar(int time)
Definition: voice.cpp:648
CAPlayable * insertInTupletAndVoiceAt(CAPlayable *p, CAPlayable *n)
Definition: voice.cpp:204
void setLyricsContexts(QList< CALyricsContext * > list)
Definition: voice.h:115
Represents a rest in the score.
Definition: rest.h:15
Class which represents a voice in the staff.
Definition: voice.h:23
Represents a time signature in the staff.
Definition: timesignature.h:18
void setMidiProgram(const unsigned char program)
Definition: voice.h:108
CAMusElement * previous(CAMusElement *elt)
Definition: voice.cpp:765
char midiPitchOffset()
Definition: voice.h:110
void setName(const QString name)
Definition: voice.h:102
CAMusElement * getOnePreviousByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:572
CAMusElement * previousByType(CAMusElement::CAMusElementType type, CAMusElement *elt)
Definition: voice.cpp:753
void cloneVoiceProperties(CAVoice *v)
Definition: voice.cpp:81
QList< CAMusElement * > getEltByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:550
~CAVoice()
Definition: voice.cpp:53
const QList< CALyricsContext * > & lyricsContextList()
Definition: voice.h:113
Represents a note in the score.
Definition: note.h:18
CARest * previousRest(int timeStart)
Definition: voice.cpp:841
bool binarySearch_startTime(int time, int &position)
\A common binary search Algorithm with its pseudocode
Definition: voice.cpp:507
bool addNoteToChord(CANote *note, CANote *referenceNote)
Definition: voice.cpp:423
QList< CANote * > getNoteList()
Definition: voice.cpp:683
CAMusElement * getOneEltByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:530
QList< CAMusElement * > getSignList()
Definition: voice.cpp:698
char _midiPitchOffset
Definition: voice.h:138
CAKeySignature * getKeySig(CAMusElement *elt)
Definition: voice.cpp:283
CAPlayable * nextPlayable(int timeStart)
Definition: voice.cpp:860
QList< CAMusElement * > getKeySignature(int startTime)
Definition: voice.cpp:1026
int lastTimeStart()
Definition: voice.h:73
const QList< CAMusElement * > & musElementList()
Definition: voice.h:47
Musical note pitch.
Definition: diatonicpitch.h:16
CAMusElement * lastMusElement()
Definition: voice.h:74
void setStaff(CAStaff *staff)
Definition: voice.h:30
CAMusElementType
Definition: muselement.h:23
CAStaff * _staff
Definition: voice.h:126
QString _name
Definition: voice.h:131
void addLyricsContexts(QList< CALyricsContext * > list)
Definition: voice.h:116
bool isFirstVoice()
Definition: voice.h:96
bool updateTimes(int idx, int length, bool signsToo=false)
Definition: voice.cpp:901
void append(CAMusElement *elt, bool addToChord=false)
Definition: voice.cpp:120
void setMidiChannel(const unsigned char ch)
Definition: voice.h:105
unsigned char _midiProgram
Definition: voice.h:137
CAPlayable * lastPlayableElt()
Definition: voice.cpp:481
QList< CAPlayable * > getChord(int time)
Definition: voice.cpp:618
Definition: note.h:22
bool insert(CAMusElement *eltAfter, CAMusElement *elt, bool addToChord=false)
Definition: voice.cpp:154
QList< CAMusElement * > getPreviousClef(int startTime)
Definition: voice.cpp:1132
An abstract class which represents every music element in the score.
Definition: muselement.h:21
One stanza line of lyrics.
Definition: lyricscontext.h:19
CAVoice * clone(CAStaff *newStaff=0)
Definition: voice.cpp:70
CAMusElement * next(CAMusElement *elt)
Definition: voice.cpp:713
Playable instances of music elements.
Definition: playable.h:18
CANote * previousNote(int timeStart)
Definition: voice.cpp:803
QList< CAMusElement * > getPreviousTimeSignature(int startTime)
Definition: voice.cpp:1111
CAStaff * staff()
Definition: voice.h:29
Represents a staff in the sheet.
Definition: staff.h:25
CANote * lastNote()
Definition: voice.cpp:495
void clear()
Definition: voice.cpp:97
bool containsPitch(int noteName, int timeStart)
Definition: voice.cpp:967
CAClef * getClef(CAMusElement *elt)
Definition: voice.cpp:249
CADiatonicPitch lastNotePitch(bool inChord=false)
Definition: voice.cpp:453
QList< CAMusElement * > getPreviousByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:594
QList< CAMusElement * > getTimeSignature(int startTime)
Definition: voice.cpp:1047
CARest * nextRest(int timeStart)
Definition: voice.cpp:822
CAPlayable * previousPlayable(int timeStart)
Definition: voice.cpp:879
bool insertMusElement(CAMusElement *before, CAMusElement *elt)
Definition: voice.cpp:366
QList< CALyricsContext * > _lyricsContextList
Definition: voice.h:129
CANote::CAStemDirection _stemDirection
Definition: voice.h:128
QList< CAMusElement * > getPreviousKeySignature(int startTime)
Definition: voice.cpp:1090
unsigned char midiChannel()
Definition: voice.h:104
bool synchronizeMusElements()
Definition: voice.cpp:923
unsigned char midiProgram()
Definition: voice.h:107
void setStemDirection(CANote::CAStemDirection direction)
Definition: voice.h:99
CAMusElement * nextByType(CAMusElement::CAMusElementType type, CAMusElement *elt)
Definition: voice.cpp:739
const QString name()
Definition: voice.h:101
CAVoice(const QString name, CAStaff *staff, CANote::CAStemDirection stemDirection=CANote::StemNeutral)
Definition: voice.cpp:37
const QList< CAVoice * > & voiceList()
Definition: staff.h:35