package ac.essex.ooechs.music.util.midi;

/**
 * Stores the tempo which affects the pace of the music.
 *
 * @author Olly Oechsle, University of Essex, Date: 05-Jul-2007
 * @version 1.0
 */
public class Tempo {

    private static int tempo = 100;

    private static int[] durations;

    public static void setTempo(int t) {
        tempo = t;
        calculateDurations();
    }

    public static int getTempo() {
        return tempo;
    }

    public static int getDuration(int type) {
        if (durations == null) calculateDurations();
        return durations[type];
    }

    private static void calculateDurations() {
        durations = new int[2];
        int crotchetDuration = 60000 / tempo;
        durations[Note.CROTCHET] = crotchetDuration;
        durations[Note.QUAVER] = crotchetDuration / 2;
    }

}
