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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/player/impl/sequencer/MidiEventPlayer.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 java.util.ArrayList;
 
4
import java.util.List;
 
5
 
 
6
import org.herac.tuxguitar.player.base.MidiPlayerException;
 
7
 
 
8
public class MidiEventPlayer{
 
9
        private MidiSequencerImpl sequencer;
 
10
        private List events;
 
11
        
 
12
        private long tick;
 
13
        private long lastTick;
 
14
        private boolean reset;
 
15
        
 
16
        public MidiEventPlayer(MidiSequencerImpl sequencer){
 
17
                this.sequencer = sequencer;
 
18
                this.events = new ArrayList();
 
19
                this.reset();
 
20
        }
 
21
        
 
22
        public void process() throws MidiPlayerException {
 
23
                this.lastTick = this.tick;
 
24
                this.tick = this.sequencer.getTickPosition();
 
25
                for(int i = 0;i < this.events.size();i ++){
 
26
                        MidiEvent event = (MidiEvent)this.events.get(i);
 
27
                        if(shouldSend(event,this.tick,this.lastTick)){
 
28
                                this.sequencer.sendEvent(event);
 
29
                        }
 
30
                }
 
31
                this.reset = false;
 
32
        }
 
33
        
 
34
        private boolean shouldSend(MidiEvent event,long tick,long lastTick){
 
35
                if(event.getTick() > tick){
 
36
                        return false;
 
37
                }
 
38
                if(event.getTrack() != MidiEvent.ALL_TRACKS){
 
39
                        if(this.sequencer.getMidiTrackController().isMute(event.getTrack())){
 
40
                                return false;
 
41
                        }
 
42
                        if(this.sequencer.getMidiTrackController().isAnySolo() && !this.sequencer.getMidiTrackController().isSolo(event.getTrack())){
 
43
                                return false;
 
44
                        }
 
45
                }
 
46
                if(this.reset){
 
47
                        if(event.getType() == MidiEvent.MIDI_SYSTEM_EVENT){
 
48
                                return true;
 
49
                        }
 
50
                        if(event.getType() == MidiEvent.MIDI_EVENT_CONTROL_CHANGE){
 
51
                                return true;
 
52
                        }
 
53
                        if(event.getType() == MidiEvent.MIDI_EVENT_PROGRAM_CHANGE){
 
54
                                return true;
 
55
                        }
 
56
                }
 
57
                return (event.getTick() > lastTick);
 
58
        }
 
59
        
 
60
        public void addEvent(MidiEvent event){
 
61
                this.events.add(event);
 
62
        }
 
63
        
 
64
        public void clearEvents(){
 
65
                this.events.clear();
 
66
        }
 
67
        
 
68
        public void reset(){
 
69
                this.tick = (this.sequencer.getTickPosition() - 1);
 
70
                this.reset = true;
 
71
        }
 
72
        
 
73
}