Java Code Examples for javax.sound.midi.MidiDevice#getMaxReceivers()

The following examples show how to use javax.sound.midi.MidiDevice#getMaxReceivers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MidiOutGetMicrosecondPositionBug.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void doAll() throws Exception {
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i=0; i < infos.length; i++) {
        MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
        if ((! (device instanceof Sequencer)) &&
            (! (device instanceof Synthesizer)) &&
            (device.getMaxReceivers() > 0 || device.getMaxReceivers() == -1)) {

            System.out.println("--------------");
            System.out.println("Testing MIDI device: " + infos[i]);
            testDevice(device);
        }
        if (infos.length==0) {
            System.out.println("No MIDI devices available!");
        }
    }
}
 
Example 2
Source File: Reopen.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean doTest(int numIterations, boolean input) throws Exception {
    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 Sequencer) &&
            ! (device instanceof Synthesizer)) {
            if (device.getMaxReceivers() != 0) {
                outDevice = device;
            }
            if (device.getMaxTransmitters() != 0) {
                inDevice = device;
            }
        }
    }
    MidiDevice testDevice = null;
    if (input) {
        testDevice = inDevice;
    } else {
        testDevice = outDevice;
    }
    if (testDevice == null) {
        out("Cannot test: device not available.");
        return true;
    }
    out("Using Device: " + testDevice);

    for (int i = 0; i < numIterations; i++) {
        out("@@@ ITERATION: " + i);
        testDevice.open();
        // This sleep ensures that the thread of MidiInDevice is started.
        sleep(50);
        testDevice.close();
    }
    return true;
}
 
Example 3
Source File: MidiPortProviderImpl.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public List<MidiOutputPort> listPorts() throws MidiPlayerException{
	try {
		List<MidiOutputPort> ports = new ArrayList<MidiOutputPort>();
		MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
		for(int i = 0; i < infos.length; i++){
			try {
				Iterator<MidiOutputPort> it = ports.iterator();
				boolean exists = false;
				while(it.hasNext()){
					if( ((MidiOutputPort)it.next()).getKey().equals(infos[i].getName()) ){
						exists = true;
						break;
					}
				}
				if(!exists){
					MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
					if(device.getMaxReceivers() == 0 || device instanceof Sequencer){
						continue;
					}
					if(device instanceof Synthesizer){
						ports.add(new MidiPortSynthesizer(this.context, (Synthesizer)device));
					}
					else{
						ports.add(new MidiPortOut(device));
					}
				}
			} catch (MidiUnavailableException e) {
				throw new MidiPlayerException(TuxGuitar.getProperty("jsa.error.midi.unavailable"),e);
			}
		}
		return ports;
	}catch (Throwable t) {
		throw new MidiPlayerException(TuxGuitar.getProperty("jsa.error.unknown"),t);
	}
}
 
Example 4
Source File: MidiPortProviderImpl.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public List<MidiOutputPort> listPorts() throws MidiPlayerException{
	try {
		List<MidiOutputPort> ports = new ArrayList<MidiOutputPort>();
		MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
		for(int i = 0; i < infos.length; i++){
			try {
				Iterator<MidiOutputPort> it = ports.iterator();
				boolean exists = false;
				while(it.hasNext()){
					if( ((MidiOutputPort)it.next()).getKey().equals(infos[i].getName()) ){
						exists = true;
						break;
					}
				}
				if(!exists){
					MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
					if(device.getMaxReceivers() == 0 || device instanceof Sequencer){
						continue;
					}
					if(device instanceof Synthesizer){
						ports.add(new MidiPortSynthesizer((Synthesizer)device));
					}
					else{
						ports.add(new MidiPortOut(device));
					}
				}
			} catch (MidiUnavailableException e) {
				throw new MidiPlayerException("jsa.error.midi.unavailable", e);
			}
		}
		return ports;
	}catch (Throwable t) {
		throw new MidiPlayerException("jsa.error.unknown", t);
	}
}
 
Example 5
Source File: IOLoop.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static String canOut(MidiDevice dev) {
    if (dev.getMaxReceivers() != 0) {
        return "OUT ";
    }
    return "   ";
}
 
Example 6
Source File: MidiIO.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    out("4356787: MIDI device I/O is not working (windows)");

    if (System.getProperty("os.name").startsWith("Windows")) {
        boolean forInput=true;
        boolean forOutput=true;
        int outOnlyCount=0;
        int inOnlyCount=0;
        out("  available MIDI devices:");
        MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
        for (int i = 0; i < aInfos.length; i++) {
            try {
                MidiDevice      device = MidiSystem.getMidiDevice(aInfos[i]);
                boolean         bAllowsInput = (device.getMaxTransmitters() != 0);
                boolean         bAllowsOutput = (device.getMaxReceivers() != 0);
                if (bAllowsInput && !bAllowsOutput) {
                    inOnlyCount++;
                }
                if (!bAllowsInput && bAllowsOutput) {
                    outOnlyCount++;
                }
                if ((bAllowsInput && forInput) || (bAllowsOutput && forOutput)) {
                    out(""+i+"  "
                            +(bAllowsInput?"IN ":"   ")
                            +(bAllowsOutput?"OUT ":"    ")
                            +aInfos[i].getName()+", "
                            +aInfos[i].getVendor()+", "
                            +aInfos[i].getVersion()+", "
                            +aInfos[i].getDescription());
                }
            }
            catch (MidiUnavailableException e) {
                // device is obviously not available...
            }
        }
        if (aInfos.length == 0) {
            out("No devices available. Test should be run on systems with MIDI drivers installed.");
        } else {
            if (outOnlyCount>1) {
                if (inOnlyCount==0) {
                    //throw new Exception("No input devices! test fails.");
                    out("System provides out devices, but no input devices. This means either");
                    out("a bug in Java Sound, or the drivers are not set up correctly.");
                }
                out("Test passed.");
            } else {
                out("no MIDI I/O installed. Test should be run on systems with MIDI drivers installed.");
            }
        }
    } else {
        out("  -- not on Windows. Test doesn't apply.");
    }
}
 
Example 7
Source File: PortsItemEventHandler.java    From EWItool with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handle( ActionEvent arg0 ) {
  
  Dialog<ButtonType> dialog = new Dialog<>();
  dialog.setTitle( "EWItool - Select MIDI Ports" );
  dialog.getDialogPane().getButtonTypes().addAll( ButtonType.CANCEL, ButtonType.OK );
  GridPane gp = new GridPane();
  
  gp.add( new Label( "MIDI In Ports" ), 0, 0 );
  gp.add( new Label( "MIDI Out Ports" ), 1, 0 );
  
  ListView<String> inView, outView;
  List<String> inPortList = new ArrayList<>(),
               outPortList = new ArrayList<>();
  ObservableList<String> inPorts = FXCollections.observableArrayList( inPortList ), 
                         outPorts = FXCollections.observableArrayList( outPortList );
  inView = new ListView<>( inPorts );
  outView = new ListView<>( outPorts );
     
  String lastInDevice = userPrefs.getMidiInPort();
  String lastOutDevice = userPrefs.getMidiOutPort();
  int ipIx = -1, opIx = -1;
  
  MidiDevice device;
  MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
  for ( MidiDevice.Info info : infos ) {
    try {
      device = MidiSystem.getMidiDevice( info );
      if (!( device instanceof Sequencer ) && !( device instanceof Synthesizer )) {
        if (device.getMaxReceivers() != 0) {
          opIx++;
          outPorts.add( info.getName() );
          if (info.getName().equals( lastOutDevice )) {
            outView.getSelectionModel().clearAndSelect( opIx );
          }
          Debugger.log( "DEBUG - Found OUT Port: " + info.getName() + " - " + info.getDescription() );
        } else if (device.getMaxTransmitters() != 0) {
          ipIx++;
          inPorts.add( info.getName() );
          if (info.getName().equals( lastInDevice )) {
            inView.getSelectionModel().clearAndSelect( ipIx );
          }
          Debugger.log( "DEBUG - Found IN Port: " + info.getName() + " - " + info.getDescription() );
        }
      }
    } catch (MidiUnavailableException ex) {
      ex.printStackTrace();
    }
  }
 
  gp.add( inView, 0, 1 );
  gp.add( outView, 1, 1 );
  dialog.getDialogPane().setContent( gp );
  
  Optional<ButtonType> rc = dialog.showAndWait();
  
  if (rc.get() == ButtonType.OK) {
    if (outView.getSelectionModel().getSelectedIndex() != -1) {
      userPrefs.setMidiOutPort( outView.getSelectionModel().getSelectedItem() );
    }
    if (inView.getSelectionModel().getSelectedIndex() != -1) {
      userPrefs.setMidiInPort( inView.getSelectionModel().getSelectedItem() );
    } 
  }
}