MidiSystem.getSequencer () is very slow

I create a MIDI sequencer and initialize the sequencer, as far as I know, I need to use:

Sequencer sequencer = MidiSystem.getSequencer(); 

But this makes my program run very, very slowly up to 2 minutes for this call to one method!

Any ideas how to fix this? Thanks you

+7
source share
1 answer

looking at the code for MidiSystem.getSequencer (), it looks like it is trying to connect various things, trying to connect the next if the previous one fails. This means that if all connection attempts end before the last, it can take a long time.

To test this theory, try using

Sequencer Sequencer = MidiSystem.getSequencer (false);

and see if this line will run faster if it happens, then the problem is the time spent connecting to standard synthesizers.

when the getSequencer () method is called, the sequence of events

  • get the default sequencer connected to the device by default
  • Return Sequencer is connected to the Synthesizer by default ...
  • If there is no Synthesizer available or by default, it is not possible to open a connection to the receiver by default. The connection is made by obtaining a Transmitter instance from the Sequencer and installing its Receiver.

This text is almost literal as there is in javadoc, but as you can see, there are enough attempts to create connections to make the call a little slow.

+1
source

All Articles