Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MidiSystem.getSequencer() very slow

Tags:

java

midi

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

Sequencer sequencer = MidiSystem.getSequencer();

But this causes my program to start very, very slow up to 2 mins for this one method call!

Any ideas how to fix this? Thank you

like image 284
user1724416 Avatar asked Feb 12 '13 22:02

user1724416


1 Answers

looking at the code for MidiSystem.getSequencer() it looks like it tries to connect various things trying to connect the next one if the previous one fails. This means that if all connection attempts fail down to the last it could take a lot of time.

To test this theory try using

Sequencer sequencer = MidiSystem.getSequencer(false);

and see if that line executes any faster, if it does then the issue is the time taken to connect to the default synthesizer.

when calling getSequencer() the series of events are

  1. obtain default Sequencer connected to default device
  2. returned Sequencer is connected to default Synthesizer...
  3. if there is no Synthesizer available or default cannot be opened connect to default Receiver. The connection is made by getting a Transmitter instance from Sequencer and setting it's Receiver.

This text is almost verbatim what is in the javadoc but as you can see there is enough attempting to create connections to make the call a bit slow.

like image 113
default_avatar Avatar answered Oct 14 '22 08:10

default_avatar