2

I am trying to replace the default soundfont of a MIDI file with my own soundfont; however, the new soundfont plays on top of the old one rather than flat-out replacing the old one. My code:

Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
synthesizer.unloadAllInstruments(synthesizer.getDefaultSoundbank());
synthesizer.loadAllInstruments(MidiSystem.getSoundbank(new File("Airhorn.sf2")));

Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.getTransmitter().setReceiver(synthesizer.getReceiver());

InputStream inputStream = new BufferedInputStream(new FileInputStream(new File("Test.mid")));
sequencer.setSequence(inputStream);
sequencer.start();
Anon10W1z
  • 167
  • 10

1 Answers1

1

You can use

MidiSystem.getSequencer(false)

to get your sequencer and prevent connecting it to the default device. Worked by me, JDK 8, Windows 10.

belgther
  • 2,544
  • 17
  • 15