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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/player/impl/sequencer/MidiTickPlayer.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
package org.herac.tuxguitar.player.impl.sequencer;
 
2
 
 
3
import org.herac.tuxguitar.song.models.TGDuration;
 
4
 
 
5
public class MidiTickPlayer {
 
6
        
 
7
        private static final int SECOND_IN_MILLIS = 1000;
 
8
        
 
9
        private int tempo;
 
10
        private long tick;
 
11
        private long time;
 
12
        private long lastTime;
 
13
        private long tickLength;
 
14
        private boolean tickChanged;
 
15
        
 
16
        public MidiTickPlayer(){
 
17
                super();
 
18
        }
 
19
        
 
20
        public void process() {
 
21
                this.lastTime = this.time;
 
22
                this.time = System.currentTimeMillis();
 
23
                if(!this.tickChanged){
 
24
                        this.tick += (TGDuration.QUARTER_TIME * ((float)getTempo() * (float)(this.time - this.lastTime) / 60f) / SECOND_IN_MILLIS);
 
25
                }
 
26
                this.tickChanged = false;
 
27
        }
 
28
        
 
29
        public void clearTick(){
 
30
                this.tickLength = 0;
 
31
        }
 
32
        
 
33
        public int getTempo() {
 
34
                return this.tempo;
 
35
        }
 
36
        
 
37
        public void setTempo(int tempo) {
 
38
                this.tempo = tempo;
 
39
        }
 
40
        
 
41
        public long getTick() {
 
42
                return this.tick;
 
43
        }
 
44
        
 
45
        public void setTick(long tick) {
 
46
                this.tick = tick;
 
47
                this.tickChanged = true;
 
48
        }
 
49
        
 
50
        public long getTickLength() {
 
51
                return this.tickLength;
 
52
        }
 
53
        
 
54
        public void notifyTick(long tick){
 
55
                this.tickLength = Math.max(this.tickLength,tick);
 
56
        }
 
57
}