List of usage examples for javax.sound.midi MidiSystem getMidiDevice
public static MidiDevice getMidiDevice(final MidiDevice.Info info) throws MidiUnavailableException
From source file:de.ailis.midi4js.Midi4JS.java
/** * Returns the handle for the midi device with the specified index. The * device must be released by calling the releaseMidiDevice() method! * * @param index//ww w .j a va 2s . c o m * The device index. * @return The device handle. * @throws MidiUnavailableException * If the midi device is not available. */ public int getMidiDevice(final int index) throws MidiUnavailableException { final Info[] infos = MidiSystem.getMidiDeviceInfo(); final MidiDevice device = MidiSystem.getMidiDevice(infos[index]); final int handle = System.identityHashCode(device); this.deviceMap.put(handle, device); return handle; }
From source file:com.github.dakusui.symfonion.CLI.java
private Map<String, MidiDevice> prepareMidiDevices(PrintStream ps, String deviceType, Map<String, Pattern> portDefinitions) throws CLIException { Map<String, MidiDevice> devices = new HashMap<String, MidiDevice>(); for (String portname : portDefinitions.keySet()) { Pattern regex = portDefinitions.get(portname); MidiDeviceScanner scanner = MidiDeviceScanner.chooseOutputDevices(ps, regex); scanner.scan();/*from w w w . j a v a 2 s.c o m*/ MidiDevice.Info[] matchedInfos = scanner.getMatchedDevices(); if (matchedInfos.length > 1) { String msg = String.format(""); throw new CLIException(msg); } else if (matchedInfos.length == 0) { String msg = String.format(""); throw new CLIException(msg); } try { devices.put(portname, MidiSystem.getMidiDevice(matchedInfos[0])); } catch (MidiUnavailableException e) { String msg = this.composeErrMsg(String.format("Failed to access MIDI-%s device:'%s'.", deviceType, matchedInfos[0].getName()), "O", null); throw new CLIException(msg, e); } } return devices; }
From source file:org.monome.pages.configuration.Configuration.java
/** * Enables or disables a MIDI input device * /*from w w w .j a va 2s .com*/ * @param sMidiDevice The name of the MIDI device to toggle */ public void actionAddMidiInput(String sMidiDevice) { Info[] midiInfo = MidiSystem.getMidiDeviceInfo(); MidiDevice midiDevice; for (int i = 0; i < midiInfo.length; i++) { try { midiDevice = MidiSystem.getMidiDevice(midiInfo[i]); if (sMidiDevice.compareTo(midiDevice.getDeviceInfo().toString()) == 0) { if (midiDevice.getMaxTransmitters() != 0) { MidiDeviceFactory.toggleMidiInDevice(midiDevice); } } } catch (MidiUnavailableException e) { e.printStackTrace(); } } }
From source file:org.monome.pages.configuration.Configuration.java
/** * Enables or disables a MIDI output device * /*from w ww.j a va 2s. c om*/ * @param sMidiDevice The MIDI output device to enable or disable */ public void actionAddMidiOutput(String sMidiDevice) { Info[] midiInfo = MidiSystem.getMidiDeviceInfo(); MidiDevice midiDevice; for (int i = 0; i < midiInfo.length; i++) { try { midiDevice = MidiSystem.getMidiDevice(midiInfo[i]); if (sMidiDevice.compareTo(midiDevice.getDeviceInfo().toString()) == 0) { if (midiDevice.getMaxReceivers() != 0) { MidiDeviceFactory.toggleMidiOutDevice(midiDevice); } } } catch (MidiUnavailableException e) { e.printStackTrace(); } } }