/** * Capture midi input events, dispatching them to given Receiver. * The MidiDevice returned is the device providing the input, and * should be closed when input events are no longer needed. * Note that this method returns the first MidiDevice which * has at least one transmitter. * * @param receiver the Receiver to which midi input events should be dispatched * @return the MidiDevice providing the input events * @throws MidiUnavailableException if midi input can't be found */ public static MidiDevice getMidiInput(Receiver receiver) throws MidiUnavailableException { MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); for (MidiDevice.Info info : infos) { MidiDevice device; device = MidiSystem.getMidiDevice(info); if (DEBUG) { System.out.println("Found: " + device); } int maxTransmitters = device.getMaxTransmitters(); if (DEBUG) { System.out.println(" Max transmitters: " + maxTransmitters); } if (maxTransmitters == -1 || maxTransmitters > 0) { Transmitter transmitter = device.getTransmitter(); transmitter.setReceiver(receiver); device.open(); return device; } } throw new MidiUnavailableException("Could not find any midi input sources"); }
/** Obtain the value of a default provider property. @param typeClass The type of the default provider property. This should be one of Receiver.class, Transmitter.class, Sequencer.class, Synthesizer.class, SourceDataLine.class, TargetDataLine.class, Clip.class or Port.class. @return The complete value of the property, if available. If the property is not set, null is returned. */ private static synchronized String getDefaultProvider(Class typeClass) { if (!SourceDataLine.class.equals(typeClass) && !TargetDataLine.class.equals(typeClass) && !Clip.class.equals(typeClass) && !Port.class.equals(typeClass) && !Receiver.class.equals(typeClass) && !Transmitter.class.equals(typeClass) && !Synthesizer.class.equals(typeClass) && !Sequencer.class.equals(typeClass)) { return null; } String name = typeClass.getName(); String value = AccessController.doPrivileged( (PrivilegedAction<String>) () -> System.getProperty(name)); if (value == null) { value = getProperties().getProperty(name); } if ("".equals(value)) { value = null; } return value; }
static MidiDevice getConnectedDevice(Sequencer sequencer) { List<Transmitter> trans = sequencer.getTransmitters(); log(" sequencer has " + trans.size() + " opened transmitters:"); for (Transmitter tr: trans) { Receiver r = tr.getReceiver(); log(" " + getClassStr(tr) + " connected to " + getClassStr(r)); if (r instanceof MidiDeviceReceiver) { MidiDeviceReceiver recv = (MidiDeviceReceiver)r; MidiDevice dev = recv.getMidiDevice(); log(" - receiver of " + getClassStr(dev)); return dev; } else { log(" - does NOT implement MidiDeviceReceiver"); } } return null; }
/** Obtain the value of a default provider property. @param typeClass The type of the default provider property. This should be one of Receiver.class, Transmitter.class, Sequencer.class, Synthesizer.class, SourceDataLine.class, TargetDataLine.class, Clip.class or Port.class. @return The complete value of the property, if available. If the property is not set, null is returned. */ private static synchronized String getDefaultProvider(Class<?> typeClass) { if (!SourceDataLine.class.equals(typeClass) && !TargetDataLine.class.equals(typeClass) && !Clip.class.equals(typeClass) && !Port.class.equals(typeClass) && !Receiver.class.equals(typeClass) && !Transmitter.class.equals(typeClass) && !Synthesizer.class.equals(typeClass) && !Sequencer.class.equals(typeClass)) { return null; } String name = typeClass.getName(); String value = AccessController.doPrivileged( (PrivilegedAction<String>) () -> System.getProperty(name)); if (value == null) { value = getProperties().getProperty(name); } if ("".equals(value)) { value = null; } return value; }
public static void openInput() throws Exception { setup(); if (bUseDefaultSynthesizer) { Synthesizer synth = MidiSystem.getSynthesizer(); synth.open(); r = synth.getReceiver(); try { Transmitter t = launchpad_s_plus.Launchpad.getInputDevice() .getTransmitter(); t.setReceiver(r); } catch (MidiUnavailableException e) { out("wasn't able to connect the device's Transmitter to the default Synthesizer:"); out(e); launchpad_s_plus.Launchpad.getInputDevice().close(); System.exit(1); } } out("\nNow taking input."); }
public static void listenStart(){ close(); openedDevices.clear(); MidiDevice device; MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); for (int i = 0; i < infos.length; i++) { try { device = MidiSystem.getMidiDevice(infos[i]); System.out.println(infos[i] +" -- "+ infos[i].getDescription()); java.util.List<Transmitter> transmitters = device.getTransmitters(); for(int j = 0; j<transmitters.size();j++) { transmitters.get(j).setReceiver(receiver); } Transmitter trans = device.getTransmitter(); trans.setReceiver(receiver); device.open(); openedDevices.add(device); System.out.println(device.getDeviceInfo()+" Was Opened"); } catch (MidiUnavailableException e) { // e.printStackTrace(); } } }
/** Obtain the value of a default provider property. @param typeClass The type of the default provider property. This should be one of Receiver.class, Transmitter.class, Sequencer.class, Synthesizer.class, SourceDataLine.class, TargetDataLine.class, Clip.class or Port.class. @return The complete value of the property, if available. If the property is not set, null is returned. */ private static synchronized String getDefaultProvider(Class typeClass) { if (!SourceDataLine.class.equals(typeClass) && !TargetDataLine.class.equals(typeClass) && !Clip.class.equals(typeClass) && !Port.class.equals(typeClass) && !Receiver.class.equals(typeClass) && !Transmitter.class.equals(typeClass) && !Synthesizer.class.equals(typeClass) && !Sequencer.class.equals(typeClass)) { return null; } String value; String propertyName = typeClass.getName(); value = JSSecurityManager.getProperty(propertyName); if (value == null) { value = getProperties().getProperty(propertyName); } if ("".equals(value)) { value = null; } return value; }
public MidiReciever() { MidiDevice device; MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); for (int i = 0; i < infos.length; i++) { try { device = MidiSystem.getMidiDevice(infos[i]); //does the device have any transmitters? //if it does, add it to the device list System.out.println(infos[i]); //get all transmitters List<Transmitter> transmitters = device.getTransmitters(); //and for each transmitter for(int j = 0; j<transmitters.size();j++) { //create a new receiver transmitters.get(j).setReceiver( //using my own MidiInputReceiver new MidiInputReceiver(device.getDeviceInfo().toString()) ); } Transmitter trans = device.getTransmitter(); trans.setReceiver(new MidiInputReceiver(device.getDeviceInfo().toString())); //open each device device.open(); //if code gets this far without throwing an exception //print a success message System.out.println(device.getDeviceInfo()+" Was Opened"); } catch (MidiUnavailableException e) {} } }
/** * Returns the default input MIDI device. * * @return the default input MIDI device or {@code null} if not found. */ public static MidiDevice getDefaultInputDevice() { try { Transmitter transmitter = MidiSystem.getTransmitter(); if (transmitter != null && transmitter instanceof MidiDeviceTransmitter) { return ((MidiDeviceTransmitter) transmitter).getMidiDevice(); } return null; } catch (MidiUnavailableException e) { throw SpongeUtils.wrapException(e); } }
/** * Closes the MIDI transmitter. * * @param transmitter the MIDI transmitter. */ public static void close(Transmitter transmitter) { try { if (transmitter != null) { transmitter.close(); } } catch (Exception e) { logger.warn("close", e); } }
/** * This implementation uses createTransmitter, which may throw an exception. * If a transmitter is returned in createTransmitter, it is added to the internal * TransmitterList */ @Override public final Transmitter getTransmitter() throws MidiUnavailableException { Transmitter transmitter; synchronized (traRecLock) { transmitter = createTransmitter(); // may throw MidiUnavailableException getTransmitterList().add(transmitter); } return transmitter; }
@Override @SuppressWarnings("unchecked") // Cast of result of clone public final List<Transmitter> getTransmitters() { List<Transmitter> tras; synchronized (traRecLock) { if (transmitterList == null || transmitterList.transmitters.size() == 0) { tras = Collections.unmodifiableList(new ArrayList<Transmitter>(0)); } else { tras = Collections.unmodifiableList((List<Transmitter>) (transmitterList.transmitters.clone())); } } return tras; }
/** Retrieve a Transmitter and open the device implicitly. This method is called by MidiSystem.getTransmitter(). */ @Override public final Transmitter getTransmitterReferenceCounting() throws MidiUnavailableException { /* Keep this order of commands! If getTransmitter() throws an exception, openInternal() should not be called! */ Transmitter transmitter; synchronized (traRecLock) { transmitter = getTransmitter(); AbstractMidiDevice.this.openInternal(transmitter); } return transmitter; }
private void add(Transmitter t) { synchronized(transmitters) { transmitters.add(t); } if (t instanceof BasicTransmitter) { ((BasicTransmitter) t).setTransmitterList(this); } if (Printer.debug) Printer.debug("--added transmitter "+t); }
private void remove(Transmitter t) { synchronized(transmitters) { int index = transmitters.indexOf(t); if (index >= 0) { transmitters.remove(index); if (Printer.debug) Printer.debug("--removed transmitter "+t); } } }
public static void setup() { try { Transmitter t = launchpad_s_plus.Launchpad.getInputDevice() .getTransmitter(); t.setReceiver(r); } catch (MidiUnavailableException e) { out("wasn't able to connect the device's Transmitter to the Receiver:"); out(e); System.exit(1); } }
protected void connectTransmitter(Transmitter inTransmitter) { f_Transmitter = inTransmitter; if(f_Transmitter != null) f_Transmitter.setReceiver(this); }