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
16class CAKeySignature;
17class CATimeSignature;
18class CAClef;
19class CALyricsContext;
20class CARest;
21class CATempo;
22
23class CAVoice {
24 friend class CAStaff; // used for insertion of music elements and updateTimes() when inserting elements and synchronizing voices
25
26public:
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 );
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);
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
119private:
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_ */
Definition: clef.h:18
Musical note pitch.
Definition: diatonicpitch.h:16
Represents a key signature sign in the staff.
Definition: keysignature.h:19
One stanza line of lyrics.
Definition: lyricscontext.h:19
An abstract class which represents every music element in the score.
Definition: muselement.h:21
CAMusElementType
Definition: muselement.h:23
Represents a note in the score.
Definition: note.h:18
CAStemDirection
Direction of the note's stem.
Definition: note.h:20
@ StemNeutral
Definition: note.h:22
Playable instances of music elements.
Definition: playable.h:18
Represents a rest in the score.
Definition: rest.h:15
Represents a staff in the sheet.
Definition: staff.h:25
const QList< CAVoice * > & voiceList()
Definition: staff.h:35
Tempo mark.
Definition: tempo.h:14
Represents a time signature in the staff.
Definition: timesignature.h:18
Class which represents a voice in the staff.
Definition: voice.h:23
QList< CAMusElement * > _musElementList
Definition: voice.h:125
CANote::CAStemDirection _stemDirection
Definition: voice.h:128
CARest * previousRest(int timeStart)
Definition: voice.cpp:841
CAMusElement * next(CAMusElement *elt)
Definition: voice.cpp:713
QList< CAMusElement * > getEltByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:550
bool isFirstVoice()
Definition: voice.h:96
const QList< CAMusElement * > & musElementList()
Definition: voice.h:47
QList< CAMusElement * > getSignList()
Definition: voice.cpp:698
void setName(const QString name)
Definition: voice.h:102
void setLyricsContexts(QList< CALyricsContext * > list)
Definition: voice.h:115
QList< CAPlayable * > getChord(int time)
Definition: voice.cpp:618
QList< CAMusElement * > getTimeSignature(int startTime)
Definition: voice.cpp:1047
CAMusElement * lastMusElement()
Definition: voice.h:74
QList< CAMusElement * > getKeySignature(int startTime)
Definition: voice.cpp:1026
CAKeySignature * getKeySig(CAMusElement *elt)
Definition: voice.cpp:283
QList< CANote * > getNoteList()
Definition: voice.cpp:683
unsigned char midiProgram()
Definition: voice.h:107
QList< CALyricsContext * > _lyricsContextList
Definition: voice.h:129
CATempo * getTempo(int time)
Definition: voice.cpp:998
bool binarySearch_startTime(int time, int &position)
\A common binary search Algorithm with its pseudocode
Definition: voice.cpp:507
const QString name()
Definition: voice.h:101
CANote * lastNote()
Definition: voice.cpp:495
CAMusElement * nextByType(CAMusElement::CAMusElementType type, CAMusElement *elt)
Definition: voice.cpp:739
CAClef * getClef(CAMusElement *elt)
Definition: voice.cpp:249
bool addNoteToChord(CANote *note, CANote *referenceNote)
Definition: voice.cpp:423
CAPlayable * previousPlayable(int timeStart)
Definition: voice.cpp:879
void setMidiPitchOffset(const char midiPitchOffset)
Definition: voice.h:111
void setStemDirection(CANote::CAStemDirection direction)
Definition: voice.h:99
CAVoice(const QString name, CAStaff *staff, CANote::CAStemDirection stemDirection=CANote::StemNeutral)
Definition: voice.cpp:37
CAMusElement * previousByType(CAMusElement::CAMusElementType type, CAMusElement *elt)
Definition: voice.cpp:753
CAStaff * _staff
Definition: voice.h:126
CATimeSignature * getTimeSig(CAMusElement *elt)
Definition: voice.cpp:266
bool insert(CAMusElement *eltAfter, CAMusElement *elt, bool addToChord=false)
Definition: voice.cpp:154
void setMidiProgram(const unsigned char program)
Definition: voice.h:108
~CAVoice()
Definition: voice.cpp:53
void clear()
Definition: voice.cpp:97
void cloneVoiceProperties(CAVoice *v)
Definition: voice.cpp:81
unsigned char _midiProgram
Definition: voice.h:137
unsigned char midiChannel()
Definition: voice.h:104
QList< CAMusElement * > getPreviousKeySignature(int startTime)
Definition: voice.cpp:1090
CAPlayable * insertInTupletAndVoiceAt(CAPlayable *p, CAPlayable *n)
Definition: voice.cpp:204
char _midiPitchOffset
Definition: voice.h:138
CAMusElement * previous(CAMusElement *elt)
Definition: voice.cpp:765
void setMidiChannel(const unsigned char ch)
Definition: voice.h:105
QList< CAMusElement * > getBar(int time)
Definition: voice.cpp:648
QList< CAMusElement * > getPreviousByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:594
bool synchronizeMusElements()
Definition: voice.cpp:923
void addLyricsContexts(QList< CALyricsContext * > list)
Definition: voice.h:116
bool remove(CAMusElement *elt, bool updateSignsTimes=true)
Definition: voice.cpp:307
CANote * previousNote(int timeStart)
Definition: voice.cpp:803
bool removeLyricsContext(CALyricsContext *lc)
Definition: voice.h:117
void append(CAMusElement *elt, bool addToChord=false)
Definition: voice.cpp:120
void addLyricsContext(CALyricsContext *lc)
Definition: voice.h:114
CADiatonicPitch lastNotePitch(bool inChord=false)
Definition: voice.cpp:453
CAMusElement * getOnePreviousByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:572
CANote::CAStemDirection stemDirection()
Definition: voice.h:98
bool updateTimes(int idx, int length, bool signsToo=false)
Definition: voice.cpp:901
CANote * nextNote(int timeStart)
Definition: voice.cpp:784
char midiPitchOffset()
Definition: voice.h:110
CARest * nextRest(int timeStart)
Definition: voice.cpp:822
QList< CAMusElement * > getPreviousClef(int startTime)
Definition: voice.cpp:1132
CAPlayable * nextPlayable(int timeStart)
Definition: voice.cpp:860
int lastTimeStart()
Definition: voice.h:73
int lastTimeEnd()
Definition: voice.h:72
void setStaff(CAStaff *staff)
Definition: voice.h:30
CAPlayable * lastPlayableElt()
Definition: voice.cpp:481
bool containsPitch(int noteName, int timeStart)
Definition: voice.cpp:967
QList< CAMusElement * > getPreviousTimeSignature(int startTime)
Definition: voice.cpp:1111
CAMusElement * getOneEltByType(CAMusElement::CAMusElementType type, int startTime)
Definition: voice.cpp:530
const QList< CALyricsContext * > & lyricsContextList()
Definition: voice.h:113
unsigned char _midiChannel
Definition: voice.h:136
bool insertMusElement(CAMusElement *before, CAMusElement *elt)
Definition: voice.cpp:366
CAStaff * staff()
Definition: voice.h:29
QString _name
Definition: voice.h:131
CAVoice * clone(CAStaff *newStaff=0)
Definition: voice.cpp:70
int voiceNumber()
Definition: voice.h:95