2
* Created on 29-nov-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.song.models;
9
import org.herac.tuxguitar.song.factory.TGFactory;
13
* TODO To change the template for this generated type comment go to
14
* Window - Preferences - Java - Code Style - Code Templates
16
public abstract class TGDuration {
18
* tiempo por defecto de la Negra.
20
public static final long QUARTER_TIME = 960;
24
public static final int WHOLE = 1;
29
public static final int HALF = 2;
34
public static final int QUARTER = 4;
39
public static final int EIGHTH = 8;
44
public static final int SIXTEENTH = 16;
49
public static final int THIRTY_SECOND = 32;
54
public static final int SIXTY_FOURTH = 64;
62
private boolean dotted;
66
private boolean doubleDotted;
70
private TGTupleto tupleto;
72
public TGDuration(TGFactory factory){
75
this.doubleDotted = false;
76
this.tupleto = factory.newTupleto();
79
public int getValue() {
83
public void setValue(int value) {
87
public boolean isDotted() {
91
public void setDotted(boolean dotted) {
95
public boolean isDoubleDotted() {
96
return this.doubleDotted;
99
public void setDoubleDotted(boolean doubleDotted) {
100
this.doubleDotted = doubleDotted;
103
public TGTupleto getTupleto(){
107
public long getTime(){
108
long time = (long)( QUARTER_TIME * ( 4.0f / this.value ) ) ;
111
}else if(this.doubleDotted){
112
time += ((time / 4) * 3);
114
return this.tupleto.convertTime(time);
117
public static TGDuration fromTime(TGFactory factory,long time){
118
TGDuration duration = factory.newDuration();
119
duration.setValue(TGDuration.SIXTY_FOURTH);
120
duration.setDotted(false);
121
duration.setDoubleDotted(false);
122
duration.getTupleto().setEnters(3);
123
duration.getTupleto().setTimes(2);
124
return fromTime(factory,time,duration);
127
public static TGDuration fromTime(TGFactory factory,long time,TGDuration minDuration){
128
return fromTime(factory, time, minDuration, 10);
131
public static TGDuration fromTime(TGFactory factory,long time,TGDuration minimum, int diff){
132
TGDuration duration = minimum.clone(factory);
133
TGDuration tmpDuration = factory.newDuration();
134
tmpDuration.setValue(TGDuration.WHOLE);
135
tmpDuration.setDotted(true);
136
boolean finish = false;
138
long tmpTime = tmpDuration.getTime();
139
if(tmpTime - diff <= time){
140
//if(tmpTime > duration.getTime()){
141
if(Math.abs( tmpTime - time ) < Math.abs( duration.getTime() - time ) ){
142
duration = tmpDuration.clone(factory);
145
if(tmpDuration.isDotted()){
146
tmpDuration.setDotted(false);
147
}else if(tmpDuration.getTupleto().isEqual(TGTupleto.NORMAL)){
148
tmpDuration.getTupleto().setEnters(3);
149
tmpDuration.getTupleto().setTimes(2);
151
tmpDuration.setValue(tmpDuration.getValue() * 2);
152
tmpDuration.setDotted(true);
153
tmpDuration.getTupleto().setEnters(1);
154
tmpDuration.getTupleto().setTimes(1);
156
if(tmpDuration.getValue() > TGDuration.SIXTY_FOURTH){
164
return (int)((Math.log(getValue() ) / Math.log(2.0)) + 0.5f );
167
public int getIndex(){
169
int value = this.value;
170
while( ( value = ( value >> 1 ) ) > 0 ){
176
public boolean isEqual(TGDuration d){
177
return (getValue() == d.getValue() && isDotted() == d.isDotted() && isDoubleDotted() == d.isDoubleDotted() && getTupleto().isEqual(d.getTupleto()));
180
public TGDuration clone(TGFactory factory){
181
TGDuration duration = factory.newDuration();
186
public void copy(TGDuration duration){
187
duration.setValue(getValue());
188
duration.setDotted(isDotted());
189
duration.setDoubleDotted(isDoubleDotted());
190
getTupleto().copy(duration.getTupleto());