-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
executable file
·84 lines (54 loc) · 2.52 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Introduction
JRtMidi is a Java wrapper for the RtMidi library.
For more information on RtMidi, please see the documentation included in the RtMidi subdirectory. Or go to http://www.music.mcgill.ca/~gary/rtmidi/
Building
JRtMidi requires ANT, SCons and SWIG to build:
ANT - http://ant.apache.org
SCons - http://www.scons.org
SWIG - http://www.swig.org
To build the complete distribution, including Jar and library type 'ant'. This will generate the wrappers, build the library, compile the class files, create a jar file, then put the Jar and the library into the 'dist' folder.
To test the implementation using virtual ports type 'ant test'. Note; you will need to connect the virtual ports by hand. For example, in Linux:
'aconnect 129 130'
will connect client 129 to 130.
If you would like to build JRtMidi with a newer version of RtMidi you will need to change the RT_MIDI_FOLDER variable in the SConstruct file, and update the 'rtmidi.version' variable in build.xml
Usage
To see an example of it's usage, check out 'jtest/VirtualPortInOutTest.java'.
To send a MIDI message you will need to do something like:
'MySender.java':
class MySender {
public static void main(String[] args) {
System.loadLibrary("jrtmidi");
RtMidiOut output = new RtMidiOut("My Input Client");
CharVector vector = new CharVector(3);
vector.set(0,(short)144); //'note on, channel 1' MIDI status byte
vector.set(1,(short)90); //note
vector.set(2,(short)66); //velocity
input.openVirtualPort("foooz");
input.sendMessage(vector);
}
}
To receive a messages, you *should* use a callback (rather than polling with 'getMessage()'):
'MyCallback.java':
import org.rtmidi.RtCallback;
import org.rtmidi.CharVector;
class MyCallback extends RtCallback {
public void receiveMessage(double timeStamp, CharVector message) {
String str = "";
for (int i = 0; i < message.size(); i++) {
if (i != 0) str += ", ";
str += message.get(i);
}
System.out.println("Received: " + str);
}
}
'MyReceiver.java':
import org.rtmidi.*;
class MyReceiver {
public static void main(String[] args) {
System.loadLibrary("jrtmidi");
RtMidiIn input = new RtMidiIn("My Input");
input.setCallback( new MyCallback() );
input.openVirtualPort();
}
}
NOTE: 'libjrtmidi.so' must be in one of library paths! These paths are different from class paths. You can make sure it is by exporting the environment variable LD_LIBRARY_PATH to a path which contains libjrtmidi.so. This is kind of awkward; I'm sure there is a way to automate this.