kshoji / javax.sound.midi-for-Android

Package javax.sound.midi porting for Android
Apache License 2.0
75 stars 34 forks source link

sequencer.getTransmitter() returns null #2

Closed victorsalle closed 8 years ago

victorsalle commented 9 years ago

Hi,

I'm trying to retrieve the "transmitter" in order to assign it my own "receiver" (to handle every MidiMessage).

Sequence sequence = MidiSystem.getSequence(getResources().openRawResource(R.raw.my_midi));

midiSequencer = MidiSystem.getSequencer();
midiSequencer.open();
midiSequencer.setSequence(sequence);
midiSequencer.start();

From here midiSequencer.getTransmitter() returns null. Please note the same piece of code using the javax.sound.midi API works well.

PS: I don't use USB/BLE features. I also tried with and without calling MidiSystem.initialize()/MidiSystem.terminate(), and the result is the same.

Thanks, Victor

kshoji commented 8 years ago

Sorry for late reply.

I've modified MidiSystem.addMidiDevice(MidiDevice) to public method. This makes enable to append custom MidiDevice instance that provides Receiver.

At first, add a class that imprements jp.kshoji.javax.sound.midi.MidiDevice. Then implement getReceivers, getReceiver and getMaxReceivers methods.

Resulting, the code will be like this:

MidiSystem.addMidiDevice(new MyMidiDevice());

Sequence sequence = MidiSystem.getSequence(getResources().openRawResource(R.raw.my_midi));

midiSequencer = MidiSystem.getSequencer();
midiSequencer.open();
midiSequencer.setSequence(sequence);
midiSequencer.start();

To try this fix, check out this branch. https://github.com/kshoji/javax.sound.midi-for-Android/tree/feature/fix_for_issue_2

Regards, Kaoru

kshoji commented 8 years ago

I've tested with some SMF files. And merged into develop branch.