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

« back to all changes in this revision

Viewing changes to TuxGuitar-oss/src/org/herac/tuxguitar/player/impl/midiport/oss/MidiOutImpl.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.midiport.oss;
 
2
 
 
3
import org.herac.tuxguitar.player.base.MidiControllers;
 
4
import org.herac.tuxguitar.player.base.MidiOut;
 
5
 
 
6
public class MidiOutImpl implements MidiOut{
 
7
        
 
8
        private boolean connected;
 
9
        private MidiPortImpl midiPort;
 
10
        private MidiSystem midiSystem;
 
11
        
 
12
        public MidiOutImpl(MidiPortImpl midiPort, MidiSystem midiSystem){
 
13
                this.midiPort = midiPort;
 
14
                this.midiSystem = midiSystem;
 
15
                this.connected = false;
 
16
        }
 
17
        
 
18
        public boolean isConnected(){
 
19
                return this.connected;
 
20
        }
 
21
        
 
22
        public void connect(){
 
23
                if(!isConnected()){
 
24
                        this.midiSystem.openPort(this.midiPort);
 
25
                        this.connected = true;
 
26
                }
 
27
        }
 
28
        
 
29
        public void disconnect() {
 
30
                if(isConnected()){
 
31
                        this.midiSystem.closePort();
 
32
                        this.connected = false;
 
33
                }
 
34
        }
 
35
        
 
36
        public void sendAllNotesOff() {
 
37
                for(int i = 0; i < 16; i ++){
 
38
                        sendControlChange(i,MidiControllers.ALL_NOTES_OFF,0);
 
39
                }
 
40
        }
 
41
        
 
42
        public void sendControlChange(int channel, int controller, int value) {
 
43
                if(isConnected()){
 
44
                        this.midiSystem.controlChange(channel, controller, value);
 
45
                }
 
46
        }
 
47
        
 
48
        public void sendNoteOff(int channel, int key, int velocity) {
 
49
                if(isConnected()){
 
50
                        this.midiSystem.noteOff(channel, key, velocity);
 
51
                }
 
52
        }
 
53
        
 
54
        public void sendNoteOn(int channel, int key, int velocity) {
 
55
                if(isConnected()){
 
56
                        this.midiSystem.noteOn(channel, key, velocity);
 
57
                }
 
58
        }
 
59
        
 
60
        public void sendPitchBend(int channel, int value) {
 
61
                if(isConnected()){
 
62
                        this.midiSystem.pitchBend(channel, value);
 
63
                }
 
64
        }
 
65
        
 
66
        public void sendProgramChange(int channel, int value) {
 
67
                if(isConnected()){
 
68
                        this.midiSystem.programChange(channel, value);
 
69
                }
 
70
        }
 
71
        
 
72
        public void sendSystemReset() {
 
73
                //not implemented
 
74
        }
 
75
}