Example #1
0
 public synchronized void init() throws MidiUnavailableException {
   if (unusedChannels != null) return;
   if (synthesizer == null) synthesizer = MidiSystem.getSynthesizer();
   if (!synthesizer.isOpen()) synthesizer.open();
   MidiChannel[] chn = synthesizer.getChannels();
   playTasks = new ArrayList<PlayTask>();
   if (receiver == null) receiver = synthesizer.getReceiver();
   unusedChannels = new ArrayList<Integer>(chn.length);
   for (int i = 0; i < chn.length; i++) if (i != 9) unusedChannels.add(i);
 }
Example #2
0
 /** Stops all notes from playing on all MIDI channels. */
 public static void allNotesOff(Synthesizer synth) {
   try {
     if (!synth.isOpen()) {
       synth.open();
     }
     MidiChannel[] channels = synth.getChannels();
     for (int i = 0; i < channels.length; i++) {
       channels[i].allNotesOff();
     }
   } catch (MidiUnavailableException e) {
     throw new JFugueException(JFugueException.GENERAL_ERROR);
   }
 }
Example #3
0
 /**
  * Returns an instance of a Sequencer that uses the provided Synthesizer as its receiver. This is
  * useful when you have made changes to a specific Synthesizer--for example, you've loaded in new
  * patches--that you want the Sequencer to use. You can then pass the Sequencer to the Player
  * constructor.
  *
  * @param synth The Synthesizer to use as the receiver for the returned Sequencer
  * @return a Sequencer with the provided Synthesizer as its receiver
  * @throws MidiUnavailableException
  * @version 4.0
  */
 public static Sequencer getSequencerConnectedToSynthesizer(Synthesizer synth)
     throws MidiUnavailableException {
   Sequencer sequencer = MidiSystem.getSequencer(false); // Get Sequencer
   // which is not
   // connected to
   // new
   // Synthesizer.
   sequencer.open();
   if (!synth.isOpen()) {
     synth.open();
   }
   sequencer.getTransmitter().setReceiver(synth.getReceiver()); // Connect
   // the
   // Synthesizer
   // to
   // our
   // synthesizer
   // instance.
   return sequencer;
 }