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

« back to all changes in this revision

Viewing changes to TuxGuitar-CoreAudio/src/org/herac/tuxguitar/player/impl/midiport/coreaudio/MidiOutImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080619003030-agens2gvd5m4dacu
New upstream release (Closes: #481728) also (LP: #176979, #212207)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.player.impl.midiport.coreaudio;
 
2
 
 
3
import java.util.ArrayList;
 
4
import java.util.Collections;
 
5
import java.util.List;
 
6
 
 
7
import org.herac.tuxguitar.player.base.MidiControllers;
 
8
import org.herac.tuxguitar.player.base.MidiOut;
 
9
import org.herac.tuxguitar.player.impl.midiport.coreaudio.MidiPortImpl;
 
10
 
 
11
public class MidiOutImpl extends MidiReceiverJNI implements MidiOut{
 
12
        private boolean open; // unncessary
 
13
    private boolean connected;  
 
14
        private List ports;
 
15
        
 
16
        public MidiOutImpl(){
 
17
                this.ports = new ArrayList();   
 
18
        this.connected = false;
 
19
        }
 
20
 
 
21
        public void open(){
 
22
                super.open();
 
23
                this.open = true;
 
24
        }
 
25
 
 
26
        public void close(){
 
27
                if(this.isOpen()){
 
28
                        this.disconnect();
 
29
                        super.close();
 
30
                        this.open = false;
 
31
                }
 
32
        }       
 
33
                
 
34
        public boolean isOpen(){
 
35
                return (this.open);
 
36
        }       
 
37
                        
 
38
        public boolean isConnected(){
 
39
                return (this.isOpen() && this.connected);
 
40
        }       
 
41
                        
 
42
    public void connect(){
 
43
        if(isOpen()){
 
44
            if(!isConnected()){             
 
45
                this.connected = true;
 
46
                this.openDevice();
 
47
            }
 
48
        }
 
49
    }
 
50
 
 
51
        public void disconnect() {
 
52
                if(isConnected()){
 
53
                        this.closeDevice();
 
54
                        this.connected = false;
 
55
                }
 
56
        }               
 
57
                
 
58
        public List listPorts(){
 
59
                if(isOpen()){
 
60
                        this.ports.clear();
 
61
                        this.ports.add(new MidiPortImpl(this, "Core Audio midi playback" , "coreaudio" ));
 
62
                        return this.ports;
 
63
                }
 
64
                return Collections.EMPTY_LIST;
 
65
        }               
 
66
 
 
67
        public void sendSystemReset() {
 
68
                if(isOpen()){
 
69
                        //not implemented
 
70
                }
 
71
        }
 
72
        
 
73
        public void sendAllNotesOff() {
 
74
 
 
75
                for(int i = 0; i < 16; i ++){
 
76
                        sendControlChange(i,MidiControllers.ALL_NOTES_OFF,0);           
 
77
                }       
 
78
/*
 
79
                for(int i = 0; i < 16; i ++){
 
80
                        sendControlChange(i,120 ,0);            
 
81
                }       
 
82
 */
 
83
        }
 
84
 
 
85
        public void sendControlChange(int channel, int controller, int value) {
 
86
                if(isOpen()){
 
87
                        super.controlChange(channel, controller, value);
 
88
                }
 
89
        }
 
90
 
 
91
        public void sendNoteOff(int channel, int key, int velocity) {
 
92
                if(isOpen()){
 
93
                        super.noteOff(channel, key, velocity);
 
94
                }
 
95
        }
 
96
 
 
97
        public void sendNoteOn(int channel, int key, int velocity) {
 
98
                if(isOpen()){
 
99
                        super.noteOn(channel, key, velocity);
 
100
                }
 
101
        }
 
102
 
 
103
        public void sendPitchBend(int channel, int value) {
 
104
                if(isOpen()){
 
105
                        super.pitchBend(channel, value);
 
106
                }
 
107
        }
 
108
 
 
109
        public void sendProgramChange(int channel, int value) {
 
110
                if(isOpen()){
 
111
                        super.programChange(channel, value);
 
112
                }
 
113
        }
 
114
}