-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTGBeat.cpp
More file actions
115 lines (103 loc) · 2.03 KB
/
Copy pathTGBeat.cpp
File metadata and controls
115 lines (103 loc) · 2.03 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "TGBeat.h"
#include "TGDuration.h"
#include "TGVoice.h"
#include "TGStroke.h"
#include "TGText.h"
#include "TGChord.h"
TGBeat::TGBeat(TGFactory* factory)
{
chord = NULL;
text = NULL;
measure = NULL;
start = TGDuration_QUARTER_TIME;
stroke = factory->newStroke();
for (int i=0; i<TGBeat_MAX_VOICES; ++i)
{
voices[i] = NULL;
setVoice(i, factory->newVoice(i));
}
}
TGBeat::~TGBeat()
{
#ifndef AUTOMATIC_DELETE
for (int i=0; i<TGBeat_MAX_VOICES; ++i)
{
delete voices[i]; voices[i] = NULL;
}
delete stroke;
stroke = NULL;
if (text) delete text;
if (chord) delete chord;
text = NULL;
chord = NULL;
#endif
}
void TGBeat::setVoice(int _index, TGVoice* _voice)
{
if (_index >= 0 && _index < TGBeat_MAX_VOICES)
{
if (voices[_index])
{
#ifndef AUTOMATIC_DELETE
delete voices[_index];
#endif
voices[_index] = NULL;
}
voices[_index] = _voice;
voices[_index]->setBeat(this);
}
}
TGVoice* TGBeat::getVoice(int _index)
{
if (_index >= 0 && _index < TGBeat_MAX_VOICES)
{
return voices[_index];
}
return NULL;
}
void TGBeat::setText(TGText* _text)
{
text = _text;
text->setBeat(this);
}
bool TGBeat::isRestBeat()
{
for (int i=0; i<countVoices(); ++i)
{
TGVoice* v = getVoice(i);
if (!v->isEmpty() && !v->isRestVoice() )
{
return false;
}
}
return true;
}
TGBeat* TGBeat::clone(TGFactory* factory)
{
TGBeat* beat = factory->newBeat();
beat->setStart(getStart());
getStroke()->copy( beat->getStroke() );
for (int i=0; i<TGBeat_MAX_VOICES; ++i)
{
beat->setVoice(i, voices[i]->clone(factory));
}
if (chord != NULL)
{
beat->setChord( chord->clone(factory) );
}
if (text != NULL)
{
beat->setText( text->clone(factory) );
}
return beat;
}
void TGBeat::removeChord() {
#ifndef AUTOMATIC_DELETE
delete chord; chord = NULL;
#endif
}
void TGBeat::removeText() {
#ifndef AUTOMATIC_DELETE
delete text; text = NULL;
#endif
}