1
package org.herac.tuxguitar.player.impl.midiport.fluidsynth;
3
public class MidiSynth {
5
private static final String JNI_LIBRARY_NAME = new String("tuxguitar-fluidsynth-jni");
8
System.loadLibrary(JNI_LIBRARY_NAME);
11
private long instance;
12
private MidiPortImpl loadedPort;
15
this.instance = malloc();
16
this.loadedPort = null;
19
public boolean isInitialized(){
20
return (this.instance != 0);
23
public void finalize(){
25
this.free(this.instance);
30
public boolean isConnected(MidiPortImpl port){
31
return (port != null && this.loadedPort != null && this.loadedPort.equals( port ) );
34
public void connect(MidiPortImpl port){
36
this.disconnect( this.loadedPort );
37
this.loadFont(this.instance, port.getSoundFont());
38
this.loadedPort = port;
42
public void disconnect(MidiPortImpl port){
43
if(isInitialized() && isConnected(port)){
44
this.unloadFont(this.instance);
45
this.loadedPort = null;
49
public void sendSystemReset() {
51
this.systemReset(this.instance);
55
public void sendNoteOn(int channel, int key, int velocity) {
57
this.noteOn(this.instance,channel, key, velocity);
61
public void sendNoteOff(int channel, int key, int velocity) {
63
this.noteOff(this.instance,channel, key, velocity);
67
public void sendControlChange(int channel, int controller, int value) {
69
this.controlChange(this.instance,channel, controller, value);
73
public void sendProgramChange(int channel, int value) {
75
this.programChange(this.instance,channel, value);
79
public void sendPitchBend(int channel, int value) {
81
this.pitchBend(this.instance,channel, value);
85
private native long malloc();
87
private native void free(long instance);
89
private native void loadFont(long instance, String path);
91
private native void unloadFont(long instance);
93
private native void systemReset(long instance);
95
private native void noteOn(long instance,int channel,int note,int velocity);
97
private native void noteOff(long instance,int channel,int note,int velocity);
99
private native void controlChange(long instance,int channel,int control,int value);
101
private native void programChange(long instance,int channel,int program);
103
private native void pitchBend(long instance,int channel,int value);