Java Code Examples for javax.sound.midi.MidiDevice#getMaxTransmitters()
The following examples show how to use
javax.sound.midi.MidiDevice#getMaxTransmitters() .
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: MiPortProvider.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
public static MidiDevice getDevice(String inDeviceName) throws MiException { MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); for(int i = 0; i < infos.length; i++) { if(infos[i].getName().equals(inDeviceName)) { try { MidiDevice device = MidiSystem.getMidiDevice(infos[i]); if( device.getMaxTransmitters() == 0 || device instanceof Sequencer) continue; return(device); } catch(MidiUnavailableException mue) { throw new MiException(TuxGuitar.getProperty("midiinput.error.midi.unavailable"), mue); } } } return(null); }
Example 2
Source File: Reopen.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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: MidiDeviceTools.java From jsyn with Apache License 2.0 | 5 votes |
/** Find a MIDI transmitter that contains text in the name. */ public static MidiDevice findKeyboard(String text) { MidiDevice keyboard = null; // Ask the MidiSystem what is available. MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); // Print info about each device. for (MidiDevice.Info info : infos) { try { MidiDevice device = MidiSystem.getMidiDevice(info); // Hardware devices are not Synthesizers or Sequencers. if (!(device instanceof Synthesizer) && !(device instanceof Sequencer)) { // Is this a transmitter? // Might be -1 if unlimited. if (device.getMaxTransmitters() != 0) { if ((text == null) || (info.getDescription().toLowerCase() .contains(text.toLowerCase()))) { keyboard = device; System.out.println("Chose: " + info.getDescription()); break; } } } } catch (MidiUnavailableException e) { e.printStackTrace(); } } return keyboard; }
Example 4
Source File: MidiDeviceTools.java From jsyn with Apache License 2.0 | 5 votes |
/** Find a MIDI transmitter that contains text in the name. */ public static MidiDevice findKeyboard(String text) { MidiDevice keyboard = null; // Ask the MidiSystem what is available. MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); // Print info about each device. for (MidiDevice.Info info : infos) { try { MidiDevice device = MidiSystem.getMidiDevice(info); // Hardware devices are not Synthesizers or Sequencers. if (!(device instanceof Synthesizer) && !(device instanceof Sequencer)) { // Is this a transmitter? // Might be -1 if unlimited. if (device.getMaxTransmitters() != 0) { if ((text == null) || (info.getDescription().toLowerCase() .contains(text.toLowerCase()))) { keyboard = device; System.out.println("Chose: " + info.getDescription()); break; } } } } catch (MidiUnavailableException e) { e.printStackTrace(); } } return keyboard; }
Example 5
Source File: IOLoop.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static String canIn(MidiDevice dev) { if (dev.getMaxTransmitters() != 0) { return "IN "; } return " "; }
Example 6
Source File: MidiIO.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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: MiPortProvider.java From tuxguitar with GNU Lesser General Public License v2.1 | 4 votes |
public static List<String> listPortsNames() throws MiException { try { List<String> portsNames = new ArrayList<String>(); MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); for(int i = 0; i < infos.length; i++) { try { Iterator<String> it = portsNames.iterator(); boolean exists = false; while(it.hasNext()) { if(((String)it.next()).equals(infos[i].getName())) { exists = true; break; } } if(!exists) { MidiDevice device = MidiSystem.getMidiDevice(infos[i]); if( device.getMaxTransmitters() == 0 || device instanceof Sequencer) continue; portsNames.add(infos[i].getName()); } } catch (MidiUnavailableException mue) { throw new MiException(TuxGuitar.getProperty("midiinput.error.midi.unavailable"), mue); } } return portsNames; } catch(Throwable t) { throw new MiException(TuxGuitar.getProperty("midiinput.error.unknown"), t); } }
Example 8
Source File: PortsItemEventHandler.java From EWItool with GNU General Public License v3.0 | 4 votes |
@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() ); } } }