예제 #1
0
  public void PlayMidiFile(String name, String filename) {
    Sequencer seq = null;
    Transmitter seqTrans = null;
    Synthesizer synth;
    Receiver synthRcvr = null;
    File midiFile = null;

    try {
      seq = MidiSystem.getSequencer();
      seqTrans = seq.getTransmitter();
      synth = MidiSystem.getSynthesizer();
      synthRcvr = synth.getReceiver();
      midiFile = new File(filename);

      if (seq == null) {
        Debug.showMessage("MidiCSD::PlayMidiFile: Sequencer nicht gefunden!");
      } else {
        seq.open();

        seqTrans.setReceiver(synthRcvr);

        Sequence mySeq;
        mySeq = MidiSystem.getSequence(midiFile);

        new Player(name, seq, mySeq, synth, m_playing).start();
      }
    } catch (MidiUnavailableException e) {
      Debug.showException(e, "MidiCSD::PlayMidiFile: MidiUnavailable" + e.getMessage());
    } catch (InvalidMidiDataException e) {
      Debug.showException(e, "MidiCSD::PlayMidiFile: InvalidMidiDataException" + e.getMessage());
    } catch (IOException e) {
      Debug.showException(e, "MidiCSD::PlayMidiFile:IOException (fn:" + filename + ")");
    }
  }
예제 #2
0
 static {
   try {
     Synthesizer synth = MidiSystem.getSynthesizer();
     synth.open();
     channels = synth.getChannels();
   } catch (MidiUnavailableException ex) {
     System.out.println(ex.getMessage());
   }
 }
예제 #3
0
 /** Closes MIDI resources - be sure to call this after play() has returned. */
 public void close() {
   getSequencer().close();
   try {
     if (MidiSystem.getSynthesizer() != null) {
       MidiSystem.getSynthesizer().close();
     }
   } catch (MidiUnavailableException e) {
     throw new JFugueException(JFugueException.GENERAL_ERROR + e.getMessage());
   }
 }
예제 #4
0
  private void openSequencer() {
    if (getSequencer() == null) {
      throw new JFugueException(JFugueException.SEQUENCER_DEVICE_NOT_SUPPORTED);
    }

    // Open the sequencer, if it is not already open
    if (!getSequencer().isOpen()) {
      try {
        getSequencer().open();
      } catch (MidiUnavailableException e) {
        throw new JFugueException(
            JFugueException.SEQUENCER_DEVICE_NOT_SUPPORTED_WITH_EXCEPTION + e.getMessage());
      }
    }
  }
예제 #5
0
 /**
  * Instantiates a new Player object, which is used for playing music. The <code>connected</code>
  * parameter is passed directly to MidiSystem.getSequencer. Pass false when you do not want to
  * copy a live synthesizer - for example, if your Player is on a server, and you don't want to
  * create new synthesizers every time the constructor is called.
  */
 public Player(boolean connected) {
   try {
     // Get default sequencer.
     setSequencer(MidiSystem.getSequencer(connected)); // use non
     // connected
     // sequencer so
     // no copy of
     // live
     // synthesizer
     // will be
     // created.
   } catch (MidiUnavailableException e) {
     throw new JFugueException(
         JFugueException.SEQUENCER_DEVICE_NOT_SUPPORTED_WITH_EXCEPTION + e.getMessage());
   }
   initParser();
 }
  /** Fill MIDI devices comboboxes. */
  public void updateMidiDevices(MidiDevice.Info[] midiDeviceInfo) {
    _midiInComboBox.removeAllItems();
    _midiOutComboBox.removeAllItems();

    try {
      int n = midiDeviceInfo.length;
      for (int i = 0; i < n; i++) {
        MidiDevice midiDevice = MidiSystem.getMidiDevice(midiDeviceInfo[i]);

        if (midiDevice.getMaxTransmitters() != 0) {
          _midiInComboBox.addItem(midiDeviceInfo[i]);
        }
        if (midiDevice.getMaxReceivers() != 0) {
          _midiOutComboBox.addItem(midiDeviceInfo[i]);
        }
      }

      _midiInComboBox.setSelectedIndex(-1);
      _midiOutComboBox.setSelectedIndex(-1);
    } catch (MidiUnavailableException exception) {
      System.out.println("MIDI device unavailable: " + exception.getMessage());
    }
  }