-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTGMeasure.cpp
More file actions
83 lines (69 loc) · 1.76 KB
/
Copy pathTGMeasure.cpp
File metadata and controls
83 lines (69 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "TGMeasure.h"
#include "TGBeat.h"
#include <algorithm>
TGMeasure::TGMeasure(TGMeasureHeader* aHeader){
track = NULL;
header = aHeader;
clef = TGMeasure_DEFAULT_CLEF;
keySignature = TGMeasure_DEFAULT_KEY_SIGNATURE;
}
TGMeasure::~TGMeasure()
{
#ifndef AUTOMATIC_DELETE
for (TGBeatList::iterator i=beats.begin(); i!=beats.end(); ++i)
{
delete *i;
}
#endif
beats.clear();
}
void TGMeasure::addBeat(TGBeat *beat){
beat->setMeasure(this);
beats.push_back(beat);
}
void TGMeasure::moveBeat(int index, TGBeat* beat){
removeBeat(beat);
beats.insert(beats.begin()+index,beat);
}
void TGMeasure::removeBeat(TGBeat *beat){
TGBeatList::iterator i = std::find(
beats.begin(),
beats.end(),
beat);
if (i != beats.end())
{
beats.erase(i);
#ifndef AUTOMATIC_DELETE
delete *i;
#endif
}
}
TGBeat *TGMeasure::getBeat(int index){
if(index >= 0 && index < countBeats()){
return beats.at(index);
}
return NULL;
}
int TGMeasure::countBeats(){
return beats.size();
}
void TGMeasure::makeEqual(TGMeasure* measure){
clef = measure->getClef();
keySignature = measure->getKeySignature();
beats.clear();
for(int i = 0; i < measure->countBeats(); i ++){
TGBeat *beat = measure->getBeat(i);
addBeat(beat);
}
}
TGMeasure* TGMeasure::clone(TGFactory *factory,TGMeasureHeader *header){
TGMeasure *measure = factory->newMeasure(header);
measure->setClef(getClef());
measure->setKeySignature(getKeySignature());
for (TGBeatList::iterator i=beats.begin(); i!=beats.end(); ++i)
{
TGBeat *beat = *i;
measure->addBeat(beat->clone(factory));
}
return measure;
}