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

« back to all changes in this revision

Viewing changes to TuxGuitar-alsa/src/org/herac/tuxguitar/player/impl/midiport/alsa/MidiSystem.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.alsa;
 
2
 
 
3
import java.util.ArrayList;
 
4
import java.util.List;
 
5
 
 
6
public class MidiSystem{
 
7
        
 
8
        private static final String JNI_LIBRARY_NAME = new String("tuxguitar-alsa-jni");
 
9
        
 
10
        static{
 
11
                System.loadLibrary(JNI_LIBRARY_NAME);
 
12
        }
 
13
        
 
14
        private long instance;
 
15
        private boolean open;
 
16
        private List ports;
 
17
        
 
18
        public MidiSystem() {
 
19
                this.instance = malloc();
 
20
                this.open = false;
 
21
                this.ports = new ArrayList();
 
22
        }
 
23
        
 
24
        public boolean isOpen(){
 
25
                return (this.instance != 0 && this.open);
 
26
        }
 
27
        
 
28
        public void finalize(){
 
29
                if(this.instance != 0){
 
30
                        this.free(this.instance);
 
31
                        this.instance = 0;
 
32
                }
 
33
        }
 
34
        
 
35
        public void open(){
 
36
                if(this.instance != 0 && !this.open){
 
37
                        this.open(this.instance);
 
38
                        this.open = true;
 
39
                }
 
40
        }
 
41
        
 
42
        public void close(){
 
43
                if(this.instance != 0 && this.open){
 
44
                        this.close(this.instance);
 
45
                        this.open = false;
 
46
                }
 
47
        }
 
48
        
 
49
        public List findPorts(){
 
50
                this.ports.clear();
 
51
                if(this.instance != 0 && this.open){
 
52
                        this.findPorts(this.instance);
 
53
                }
 
54
                return this.ports;
 
55
        }
 
56
        
 
57
        public void openPort(int client,int port){
 
58
                if(this.instance != 0 && this.open){
 
59
                        this.openPort(this.instance, client, port);
 
60
                }
 
61
        }
 
62
        
 
63
        public void closePort(){
 
64
                if(this.instance != 0 && this.open){
 
65
                        this.closePort(this.instance);
 
66
                }
 
67
        }
 
68
        
 
69
        public void noteOn(int channel,int note,int velocity){
 
70
                if(this.instance != 0 && this.open){
 
71
                        this.noteOn(this.instance, channel, note, velocity);
 
72
                }
 
73
        }
 
74
        
 
75
        public void noteOff(int channel,int note,int velocity){
 
76
                if(this.instance != 0 && this.open){
 
77
                        this.noteOff(this.instance, channel, note, velocity);
 
78
                }
 
79
        }
 
80
        
 
81
        public void controlChange(int channel,int control,int value){
 
82
                if(this.instance != 0 && this.open){
 
83
                        this.controlChange(this.instance, channel, control, value);
 
84
                }
 
85
        }
 
86
        
 
87
        public void programChange(int channel,int program){
 
88
                if(this.instance != 0 && this.open){
 
89
                        this.programChange(this.instance, channel, program);
 
90
                }
 
91
        }
 
92
        
 
93
        public void pitchBend(int channel,int value){
 
94
                if(this.instance != 0 && this.open){
 
95
                        this.pitchBend(this.instance, channel, value);
 
96
                }
 
97
        }
 
98
        
 
99
        protected void addPort(String name,int client,int port){
 
100
                this.ports.add(new MidiPortImpl(this,name,client,port));
 
101
        }
 
102
        
 
103
        private native long malloc();
 
104
        
 
105
        private native void free(long instance);
 
106
        
 
107
        private native void open(long instance);
 
108
        
 
109
        private native void close(long instance);
 
110
        
 
111
        private native void findPorts(long instance);
 
112
        
 
113
        private native void openPort(long instance,int client,int port);
 
114
        
 
115
        private native void closePort(long instance);
 
116
        
 
117
        private native void noteOn(long instance,int channel,int note,int velocity);
 
118
        
 
119
        private native void noteOff(long instance,int channel,int note,int velocity);
 
120
        
 
121
        private native void controlChange(long instance,int channel,int control,int value);
 
122
        
 
123
        private native void programChange(long instance,int channel,int program);
 
124
        
 
125
        private native void pitchBend(long instance,int channel,int value);
 
126
        
 
127
}