7

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

user1724416
  • 914
  • 2
  • 11
  • 24
  • 1
    I wonder, how did you understood, that exactly this method causes your program to start up to 2 minutes? Have you added some printouts before/after method with time comparison? – Andremoniy Feb 14 '13 at 07:37
  • Can you add which Java version you are referring to? And which sequencer is returned (ie name, vendor string)? I'm currently running Oracle jdk1.7.0_06 64 bit, and I cannot reproduce your problem (few milliseconds for this call). What can take up to a minute in my case is loading a huge soundfont into the synthesizer. Maybe your default synthesizer does something strange? Does MidiSystem.getSynthesizer() take just as long? – bluenote10 Feb 15 '13 at 07:53
  • Tried in 1.6.0_37 (Mac Os), this call takes from 0.25 to 4 seconds; when called, icon appears in dock. When first time started [test app](https://gist.github.com/kolen/4990019), it generated short loud noise through sound output. – kolen Feb 19 '13 at 21:18

1 Answers1

1

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.

default_avatar
  • 306
  • 3
  • 14