-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTGDuration.cpp
More file actions
51 lines (48 loc) · 1.5 KB
/
TGDuration.cpp
File metadata and controls
51 lines (48 loc) · 1.5 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
#include "TGDuration.h"
#include "TGTupleto.h"
long TGDuration::getTime() {
long time = (long)( TGDuration_QUARTER_TIME * ( 4.0f / value ) ) ;
if(dotted){
time += time / 2;
}else if(doubleDotted){
time += ((time / 4) * 3);
}
return tupleto->convertTime(time);
}
void TGDuration::copy(TGDuration* duration){
duration->setValue(getValue());
duration->setDotted(isDotted());
duration->setDoubleDotted(isDoubleDotted());
getTupleto()->copy(duration->getTupleto());
}
TGDuration* TGDuration::fromTime(TGFactory* factory,long time,TGDuration* minimum, int diff)
{
TGDuration *duration = minimum->clone(factory);
TGDuration *tmpDuration = factory->newDuration();
tmpDuration->setValue(TGDuration_WHOLE);
tmpDuration->setDotted(true);
bool finish = false;
while(!finish){
long tmpTime = tmpDuration->getTime();
if(tmpTime - diff <= time){
if(abs( tmpTime - time ) < abs( duration->getTime() - time ) ){
duration = tmpDuration->clone(factory);
}
}
if(tmpDuration->isDotted()){
tmpDuration->setDotted(false);
}else if(tmpDuration->getTupleto()->isEqualToNormal()){
tmpDuration->getTupleto()->setEnters(3);
tmpDuration->getTupleto()->setTimes(2);
}else{
tmpDuration->setValue(tmpDuration->getValue() * 2);
tmpDuration->setDotted(true);
tmpDuration->getTupleto()->setEnters(1);
tmpDuration->getTupleto()->setTimes(1);
}
if(tmpDuration->getValue() > TGDuration_SIXTY_FOURTH){
finish = true;
}
}
return duration;
}