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

« back to all changes in this revision

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