~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/editors/tab/TablatureUtil.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Created on 25-nov-2005
3
 
 *
4
 
 * TODO To change the template for this generated file go to
5
 
 * Window - Preferences - Java - Code Style - Code Templates
6
 
 */
7
 
package org.herac.tuxguitar.gui.editors.tab;
8
 
 
9
 
import java.util.ArrayList;
10
 
import java.util.List;
11
 
 
12
 
import org.herac.tuxguitar.song.models.Duration;
13
 
import org.herac.tuxguitar.song.models.Measure;
14
 
import org.herac.tuxguitar.song.models.TimeSignature;
15
 
/**
16
 
 * @author julian
17
 
 *
18
 
 * TODO To change the template for this generated type comment go to
19
 
 * Window - Preferences - Java - Code Style - Code Templates
20
 
 */
21
 
public class TablatureUtil {
22
 
  
23
 
    /**
24
 
     * Calcula la posicion inicial de una nota, dependiendo de el span
25
 
     */
26
 
    public static final int getStartPosition(Measure measure,long start,int span){
27
 
        double newStart = (double)start - (double)measure.getStart();
28
 
        double displayPosition = 0.0;
29
 
        if(newStart > 0){
30
 
            double position = ((double)newStart / (double)Duration.QUARTER_TIME);               
31
 
            displayPosition = (position * span);
32
 
        }
33
 
        return (int)displayPosition;
34
 
    }
35
 
    
36
 
 
37
 
    
38
 
    public static List createDurations(long time){
39
 
        List durations = new ArrayList();
40
 
        Duration tempDuration = new Duration(Duration.WHOLE);
41
 
        tempDuration.setDotted(true);
42
 
        long tempTime = time;
43
 
        
44
 
        boolean finish = false;
45
 
        while(!finish){
46
 
            long currentDurationTime = tempDuration.getTime();
47
 
            if(currentDurationTime <= tempTime){
48
 
                durations.add((Duration)tempDuration.clone());
49
 
                tempTime -= currentDurationTime;
50
 
            }else{
51
 
                if(tempDuration.isDotted()){                
52
 
                    tempDuration.setDotted(false);
53
 
                }else{
54
 
                    tempDuration.setValue(tempDuration.getValue() * 2);
55
 
                    tempDuration.setDotted(true);
56
 
                }
57
 
            }
58
 
            if(tempDuration.getValue() > Duration.SIXTY_FOURTH){
59
 
                finish = true;
60
 
            }
61
 
        }
62
 
        return durations;        
63
 
    }    
64
 
    
65
 
    public static long getBeatLength(TimeSignature timeSignature){        
66
 
        long defaultLenght = Duration.QUARTER_TIME;
67
 
        
68
 
        int denominator = timeSignature.getDenominator().getValue();
69
 
        switch(denominator){
70
 
                case Duration.EIGHTH:
71
 
                    if(timeSignature.getNumerator() % 3 == 0){
72
 
                        defaultLenght += Duration.QUARTER_TIME / 2;
73
 
                    }
74
 
                    break;
75
 
        }        
76
 
        
77
 
        return defaultLenght;
78
 
    }
79
 
}