예제 #1
0
  /** Method to get all available midi ports and add them to the corresponding device list. */
  private void getAvailablePorts() {
    javax.sound.midi.MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
      try {
        javax.sound.midi.MidiDevice theDevice = MidiSystem.getMidiDevice(infos[i]);

        if (theDevice instanceof javax.sound.midi.Sequencer) {
          // Ignore this device as it's a sequencer
        } else if (theDevice.getMaxReceivers() != 0) {
          midiOutDevices.add(theDevice);
        } else if (theDevice.getMaxTransmitters() != 0) {
          midiInputDevices.add(theDevice);
        }
      } catch (MidiUnavailableException e) {
        e.printStackTrace();
      }
    }
  }
  /** 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());
    }
  }
예제 #3
0
파일: MidiUtils.java 프로젝트: wesen/nmedit
 public static boolean allowsReceivers(MidiDevice device) {
   return probe(device.getMaxReceivers()) || probe(device.getReceivers());
 }
예제 #4
0
파일: MidiUtils.java 프로젝트: wesen/nmedit
 public static boolean hasAvailableReceivers(MidiDevice device) {
   return probe(device.getMaxReceivers());
 }
예제 #5
0
  public static void main(String[] args) throws Exception {
    boolean failed = false;
    out("#4616517: Receiver.send() does not work properly");
    if (!isMidiInstalled()) {
      out("Soundcard does not exist or sound drivers not installed!");
      out("This test requires sound drivers for execution.");
      return;
    }
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    MidiDevice outDevice = null;
    MidiDevice inDevice = null;
    for (int i = 0; i < infos.length; i++) {
      MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
      if (!(device instanceof Synthesizer) && !(device instanceof Sequencer)) {
        if (device.getMaxReceivers() != 0) {
          outDevice = device;
        }
        if (device.getMaxTransmitters() != 0) {
          inDevice = device;
        }
      }
    }
    if (outDevice != null) {
      // set the default provider properties
      System.setProperty(Receiver.class.getName(), "#" + outDevice.getDeviceInfo().getName());
    }
    if (inDevice != null) {
      System.setProperty(Transmitter.class.getName(), "#" + inDevice.getDeviceInfo().getName());
    }
    out("Using MIDI OUT Device: " + outDevice);
    out("Using MIDI IN Device: " + inDevice);

    isTestExecuted = false;
    if (outDevice != null) {
      isTestExecuted = true;
      TestHelper testHelper = new ReceiverTestHelper(outDevice);
      try {
        doTest("Receiver", testHelper);
        failed |= testHelper.hasFailed();
      } catch (Exception e) {
        out("Exception occured, cannot test!");
        isTestExecuted = false;
      }
    }

    if (inDevice != null) {
      isTestExecuted = true;
      TestHelper testHelper = new TransmitterTestHelper(inDevice);
      try {
        doTest("Transmitter", testHelper);
        failed |= testHelper.hasFailed();
      } catch (Exception e) {
        out("Exception occured, cannot test!");
        isTestExecuted = false;
      }
    }

    isTestPassed = !failed;

    if (isTestExecuted) {
      if (isTestPassed) {
        out("Test PASSED.");
      } else {
        throw new Exception("Test FAILED.");
      }
    } else {
      out("Test NOT FAILED");
    }
  }