Java and Core-Audio Midi interface
Java and Core-Audio Midi interface
- Subject: Java and Core-Audio Midi interface
- From: Wolfgang Jung <email@hidden>
- Date: Tue, 5 Dec 2006 19:21:44 +0100
Hi,
I'm trying to implement a simple java application listening to
incoming midi events. Since there is no implementation of
javax.sound.midi in
the JDK (besides Mandolane, which can't be used due to licensing
issues) i've used the more or less undocumented core-audio midi classes.
All information found in the SDK and some search results led to the
following code, which crashes the VM after the first midi event:
import com.apple.audio.midi.*;
import com.apple.audio.util.CAFString;
public class CAMidi implements MIDIReadProc, MIDINotifyProc
{
public static void main(String[] args) throws Exception
{
CAMidi p = new CAMidi();
Thread.sleep(200000);
}
public CAMidi()
{
try {
MIDIClient mc = new MIDIClient(new CAFString("Client"), this);
MIDIInputPort ipA = mc.inputPortCreate(new CAFString("Client-
In"), this);
MIDIOutputPort outA = mc.outputPortCreate(new CAFString
("Client-Out"));
MIDIDevice bcr2000 = null;
int numberOfSources = MIDISetup.getNumberOfSources();
for (int i = 0; i < numberOfSources; i++) {
System.out.println("Source " + i + MIDISetup.getSource
(i).getStringProperty(MIDIConstants.kMIDIPropertyName));
}
for (int i = 0; i < MIDIDevice.getNumberOfDevices(); i++) {
MIDIDevice temp = MIDIDevice.getDevice(i);
if (temp.getStringProperty
(MIDIConstants.kMIDIPropertyName).toString().equals("IAC Driver")) {
bcr2000 = temp;
}
}
assert bcr2000 != null : "No IAC enabled";
MIDIEntity port1 = null;
for (int i = 0; i < bcr2000.getNumberOfEntities(); i++) {
MIDIEntity temp2 = bcr2000.getEntity(i);
if (temp2.getStringProperty
(MIDIConstants.kMIDIPropertyName).toString().equals("Bus 1")) {
port1 = temp2;
}
}
assert port1 != null : "No Bus 'IAC-Bus 1' found";
MIDIEndpoint INA = port1.getSource(0);
ipA.connectSource(INA);
System.out.println("connected");
} catch (Exception e) {
e.printStackTrace();
}
}
public void execute(MIDIInputPort port, MIDIEndpoint srcEndPoint,
MIDIPacketList list)
{
System.out.println(list.numPackets() + "packet(s).");
}
public void execute(MIDIClient arg0, MIDINotification arg1)
{
System.out.println(arg1 + " not");
}
}
No exception, but a "java.crash.log" indicating a:
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000015
Thread 10 Crashed:
0 CoreAudio 0x027ca2dd
Java_com_apple_audio_jdirect_MethodClosure_DisposeMethodClosure + 91
1 com.apple.audio.midi.CoreMIDI 0x9664a403
LocalMIDIReceiverList::HandleMIDIIn(void*, void*, MIDIPacketList*) + 195
2 com.apple.audio.midi.CoreMIDI 0x966270bf
MIDIInPortThread::Run() + 245
3 com.apple.audio.midi.CoreMIDI 0x96627d1b XThread::RunHelper
(void*) + 17
4 com.apple.audio.midi.CoreMIDI 0x9662f617 CAPThread::Entry
(CAPThread*) + 93
5 libSystem.B.dylib 0x90023d87 _pthread_body + 84
It's not a hardware issue, since the java-vm crashes even with
messages on the IAC bus. Whats going wrong with this
piece of code? I'm using 10.4.8 on an Intel MBP.
Any idea?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden