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

« back to all changes in this revision

Viewing changes to TuxGuitar-fluidsynth/src/org/herac/tuxguitar/player/impl/midiport/fluidsynth/MidiSynth.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.fluidsynth;
 
2
 
 
3
public class MidiSynth {
 
4
        
 
5
        private static final String JNI_LIBRARY_NAME = new String("tuxguitar-fluidsynth-jni");
 
6
        
 
7
        static{
 
8
                System.loadLibrary(JNI_LIBRARY_NAME);
 
9
        }
 
10
        
 
11
        private long instance;
 
12
        private MidiPortImpl loadedPort;
 
13
        
 
14
        public MidiSynth(){
 
15
                this.instance = malloc();
 
16
                this.loadedPort = null;
 
17
        }
 
18
        
 
19
        public boolean isInitialized(){
 
20
                return (this.instance != 0);
 
21
        }
 
22
        
 
23
        public void finalize(){
 
24
                if(isInitialized()){
 
25
                        this.free(this.instance);
 
26
                        this.instance = 0;
 
27
                }
 
28
        }
 
29
        
 
30
        public boolean isConnected(MidiPortImpl port){
 
31
                return (port != null && this.loadedPort != null && this.loadedPort.equals( port ) );
 
32
        }
 
33
        
 
34
        public void connect(MidiPortImpl port){
 
35
                if(isInitialized()){
 
36
                        this.disconnect( this.loadedPort );
 
37
                        this.loadFont(this.instance, port.getSoundFont());
 
38
                        this.loadedPort = port;
 
39
                }
 
40
        }
 
41
        
 
42
        public void disconnect(MidiPortImpl port){
 
43
                if(isInitialized() && isConnected(port)){
 
44
                        this.unloadFont(this.instance);
 
45
                        this.loadedPort = null;
 
46
                }
 
47
        }
 
48
        
 
49
        public void sendSystemReset() {
 
50
                if(isInitialized()){
 
51
                        this.systemReset(this.instance);
 
52
                }
 
53
        }
 
54
        
 
55
        public void sendNoteOn(int channel, int key, int velocity) {
 
56
                if(isInitialized()){
 
57
                        this.noteOn(this.instance,channel, key, velocity);
 
58
                }
 
59
        }
 
60
        
 
61
        public void sendNoteOff(int channel, int key, int velocity) {
 
62
                if(isInitialized()){
 
63
                        this.noteOff(this.instance,channel, key, velocity);
 
64
                }
 
65
        }
 
66
        
 
67
        public void sendControlChange(int channel, int controller, int value) {
 
68
                if(isInitialized()){
 
69
                        this.controlChange(this.instance,channel, controller, value);
 
70
                }
 
71
        }
 
72
        
 
73
        public void sendProgramChange(int channel, int value) {
 
74
                if(isInitialized()){
 
75
                        this.programChange(this.instance,channel, value);
 
76
                }
 
77
        }
 
78
        
 
79
        public void sendPitchBend(int channel, int value) {
 
80
                if(isInitialized()){
 
81
                        this.pitchBend(this.instance,channel, value);
 
82
                }
 
83
        }
 
84
        
 
85
        private native long malloc();
 
86
        
 
87
        private native void free(long instance);
 
88
        
 
89
        private native void loadFont(long instance, String path);
 
90
        
 
91
        private native void unloadFont(long instance);
 
92
        
 
93
        private native void systemReset(long instance);
 
94
        
 
95
        private native void noteOn(long instance,int channel,int note,int velocity);
 
96
        
 
97
        private native void noteOff(long instance,int channel,int note,int velocity);
 
98
        
 
99
        private native void controlChange(long instance,int channel,int control,int value);
 
100
        
 
101
        private native void programChange(long instance,int channel,int program);
 
102
        
 
103
        private native void pitchBend(long instance,int channel,int value);
 
104
        
 
105
}