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 java.io.Serializable;
13
* TODO To change the template for this generated type comment go to
14
* Window - Preferences - Java - Code Style - Code Templates
16
public class Duration implements Serializable{
18
* tiempo por defecto de la Negra.
20
public static final long QUARTER_TIME = 1000;
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;
59
public static final Tupleto NO_TUPLETO = new Tupleto(1,1);
67
private boolean dotted;
71
private boolean doubleDotted;
75
private Tupleto tupleto;
77
public Duration(int value,boolean dotted,boolean doubleDotted,Tupleto tupleto){
80
this.doubleDotted = doubleDotted;
81
this.tupleto = tupleto;
84
public Duration(int value){
85
this(value,false,false,new Tupleto(1,1));
88
public int getValue() {
91
public void setValue(int value) {
95
public boolean isDotted() {
98
public void setDotted(boolean dotted) {
102
public boolean isDoubleDotted() {
106
public void setDoubleDotted(boolean doubleDotted) {
107
this.doubleDotted = doubleDotted;
110
public Tupleto getTupleto(){
114
public long getTime(){
118
time = QUARTER_TIME * 4;
121
time = QUARTER_TIME * 2;
127
time = QUARTER_TIME / 2;
130
time = QUARTER_TIME / 4;
133
time = QUARTER_TIME / 8;
136
time = QUARTER_TIME / 16;
141
}else if(this.doubleDotted){
142
time += ((time / 4) * 3);
145
return this.tupleto.convertTime(time);
148
public static Duration fromTime(long time){
149
return fromTime(time,new Duration(Duration.SIXTY_FOURTH,false,false,new Tupleto(3,2)));
152
public static Duration fromTime(long time,Duration minDuration){
153
//Duration duration = new Duration(Duration.SIXTY_FOURTH,false,false,new Tupleto(3,2));
154
Duration duration = (Duration)minDuration.clone();
158
Duration tempDuration = new Duration(Duration.WHOLE);
159
tempDuration.setDotted(true);
161
boolean finish = false;
163
long currentDurationTime = tempDuration.getTime();
164
if(currentDurationTime - marginTime <= time){
165
if(currentDurationTime > duration.getTime()){
166
duration = (Duration)tempDuration.clone();
170
if(tempDuration.isDotted()){
171
tempDuration.setDotted(false);
172
}else if(tempDuration.getTupleto().isEqual(Duration.NO_TUPLETO)){
173
tempDuration.getTupleto().setEnters(3);
174
tempDuration.getTupleto().setTimes(2);
176
tempDuration.setValue(tempDuration.getValue() * 2);
177
tempDuration.setDotted(true);
178
tempDuration.getTupleto().setEnters(1);
179
tempDuration.getTupleto().setTimes(1);
181
if(tempDuration.getValue() > Duration.SIXTY_FOURTH){
190
long currentDurationTime = duration.getTime();
191
if(currentDurationTime - marginTime <= time){
194
if(duration.isDotted()){
195
duration.setDotted(false);
197
duration.setValue(duration.getValue() * 2);
198
duration.setDotted(true);
201
if(duration.getValue() > Duration.SIXTY_FOURTH){
210
return (int)(Math.log(getValue() ) / Math.log(2.0));
213
public boolean isEqual(Duration d){
214
return (getValue() == d.getValue() && isDotted() == d.isDotted() && isDoubleDotted() == d.isDoubleDotted() && getTupleto().isEqual(d.getTupleto()));
217
public Object clone(){
218
return new Duration(this.value,this.dotted,this.doubleDotted,(Tupleto)this.tupleto.clone());