Help capturing MIDI stream to file ...

G

Gerald

Hi all,

I'm trying to capture MIDI data from a Yamaha keyboard to a MIDI file.
If I first get the MidiDevice for the Yamaha (the "YAMAHA CBX Driver")
and hook this up to the default synthesizer, it plays on the computer
great. However, if I try to dump it into a sequencer first and then
play from the sequencer, it fails with a NullPointerException. Essence
of the code is below. What am I doing wrong?

Gerald.


MidiDevice cbxa = getMidiDevice("YAMAHA CBX Driver");
cbxa.open();

Sequencer sqr = MidiSystem.getSequencer();
sqr.open();

Sequence s = new Sequence(Sequence.PPQ, 10);
Track t = s.createTrack();
sqr.setSequence(s);

cbxa.getTransmitter().setReceiver(sqr.getReceiver());

sqr.recordEnable(t, -1);
System.out.println("Start recording");
sqr.startRecording();
Thread.sleep(5000);
sqr.stopRecording();
System.out.println("Stop recording");

System.out.println("Try playing");
Synthesizer syn = MidiSystem.getSynthesizer();
syn.open();
sqr.getTransmitter().setReceiver(syn.getReceiver());
sqr.start();
Thread.sleep(5000);
sqr.stop();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top