Java Code Examples for javax.sound.midi.spi.MidiDeviceProvider#getDevice()

The following examples show how to use javax.sound.midi.spi.MidiDeviceProvider#getDevice() . 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: MidiSystem.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** Return a MidiDevice with a given name from a given MidiDeviceProvider.
  @param deviceName The name of the MidiDevice to be returned.
  @param provider The MidiDeviceProvider to check for MidiDevices.
  @param deviceClass The requested device type, one of Synthesizer.class,
  Sequencer.class, Receiver.class or Transmitter.class.

  @return A MidiDevice matching the requirements, or null if none is found.
 */
private static MidiDevice getNamedDevice(String deviceName,
                                         MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        if (infos[i].getName().equals(deviceName)) {
            MidiDevice device = provider.getDevice(infos[i]);
            if (isAppropriateDevice(device, deviceClass,
                                    allowSynthesizer, allowSequencer)) {
                return device;
            }
        }
    }
    return null;
}
 
Example 2
Source File: MidiSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** Return a MidiDevice with a given name from a given MidiDeviceProvider.
  @param deviceName The name of the MidiDevice to be returned.
  @param provider The MidiDeviceProvider to check for MidiDevices.
  @param deviceClass The requested device type, one of Synthesizer.class,
  Sequencer.class, Receiver.class or Transmitter.class.

  @return A MidiDevice matching the requirements, or null if none is found.
 */
private static MidiDevice getNamedDevice(String deviceName,
                                         MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        if (infos[i].getName().equals(deviceName)) {
            MidiDevice device = provider.getDevice(infos[i]);
            if (isAppropriateDevice(device, deviceClass,
                                    allowSynthesizer, allowSequencer)) {
                return device;
            }
        }
    }
    return null;
}
 
Example 3
Source File: MidiSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Return a MidiDevice with a given name from a given MidiDeviceProvider.
  @param deviceName The name of the MidiDevice to be returned.
  @param provider The MidiDeviceProvider to check for MidiDevices.
  @param deviceClass The requested device type, one of Synthesizer.class,
  Sequencer.class, Receiver.class or Transmitter.class.

  @return A MidiDevice matching the requirements, or null if none is found.
 */
private static MidiDevice getNamedDevice(String deviceName,
                                         MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        if (infos[i].getName().equals(deviceName)) {
            MidiDevice device = provider.getDevice(infos[i]);
            if (isAppropriateDevice(device, deviceClass,
                                    allowSynthesizer, allowSequencer)) {
                return device;
            }
        }
    }
    return null;
}
 
Example 4
Source File: MidiSystem.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/** Return a MidiDevice with a given name from a given MidiDeviceProvider.
  @param deviceName The name of the MidiDevice to be returned.
  @param provider The MidiDeviceProvider to check for MidiDevices.
  @param deviceClass The requested device type, one of Synthesizer.class,
  Sequencer.class, Receiver.class or Transmitter.class.

  @return A MidiDevice matching the requirements, or null if none is found.
 */
private static MidiDevice getNamedDevice(String deviceName,
                                         MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        if (infos[i].getName().equals(deviceName)) {
            MidiDevice device = provider.getDevice(infos[i]);
            if (isAppropriateDevice(device, deviceClass,
                                    allowSynthesizer, allowSequencer)) {
                return device;
            }
        }
    }
    return null;
}
 
Example 5
Source File: UnsupportedInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    final MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
        for (final MidiDevice.Info info : infos) {
            if (mdp.isDeviceSupported(info)) {
                if (mdp.getDevice(info) == null) {
                    throw new RuntimeException("MidiDevice is null");
                }
            } else {
                try {
                    mdp.getDevice(info);
                    throw new RuntimeException(
                            "IllegalArgumentException expected");
                } catch (final IllegalArgumentException ignored) {
                    // expected
                }
            }
        }
    }
}
 
Example 6
Source File: MidiSystem.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/** Return a MidiDevice with a given name from a given MidiDeviceProvider.
  @param deviceName The name of the MidiDevice to be returned.
  @param provider The MidiDeviceProvider to check for MidiDevices.
  @param deviceClass The requested device type, one of Synthesizer.class,
  Sequencer.class, Receiver.class or Transmitter.class.

  @return A MidiDevice matching the requirements, or null if none is found.
 */
private static MidiDevice getNamedDevice(String deviceName,
                                         MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        if (infos[i].getName().equals(deviceName)) {
            MidiDevice device = provider.getDevice(infos[i]);
            if (isAppropriateDevice(device, deviceClass,
                                    allowSynthesizer, allowSequencer)) {
                return device;
            }
        }
    }
    return null;
}
 
Example 7
Source File: MidiSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/** From a given MidiDeviceProvider, return the first appropriate device.
    @param provider The MidiDeviceProvider to check for MidiDevices.
    @param deviceClass The requested device type, one of Synthesizer.class,
    Sequencer.class, Receiver.class or Transmitter.class.
    @return A MidiDevice is considered appropriate, or null if no
    appropriate device is found.
 */
private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int j = 0; j < infos.length; j++) {
        MidiDevice device = provider.getDevice(infos[j]);
        if (isAppropriateDevice(device, deviceClass,
                                allowSynthesizer, allowSequencer)) {
            return device;
        }
    }
    return null;
}
 
Example 8
Source File: MidiSystem.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** From a given MidiDeviceProvider, return the first appropriate device.
    @param provider The MidiDeviceProvider to check for MidiDevices.
    @param deviceClass The requested device type, one of Synthesizer.class,
    Sequencer.class, Receiver.class or Transmitter.class.
    @return A MidiDevice is considered appropriate, or null if no
    appropriate device is found.
 */
private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int j = 0; j < infos.length; j++) {
        MidiDevice device = provider.getDevice(infos[j]);
        if (isAppropriateDevice(device, deviceClass,
                                allowSynthesizer, allowSequencer)) {
            return device;
        }
    }
    return null;
}
 
Example 9
Source File: MidiSystem.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** From a given MidiDeviceProvider, return the first appropriate device.
    @param provider The MidiDeviceProvider to check for MidiDevices.
    @param deviceClass The requested device type, one of Synthesizer.class,
    Sequencer.class, Receiver.class or Transmitter.class.
    @return A MidiDevice is considered appropriate, or null if no
    appropriate device is found.
 */
private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int j = 0; j < infos.length; j++) {
        MidiDevice device = provider.getDevice(infos[j]);
        if (isAppropriateDevice(device, deviceClass,
                                allowSynthesizer, allowSequencer)) {
            return device;
        }
    }
    return null;
}
 
Example 10
Source File: MidiSystem.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains the requested MIDI device.
 *
 * @param info a device information object representing the desired device.
 * @return the requested device
 * @throws MidiUnavailableException if the requested device is not available
 * due to resource restrictions
 * @throws IllegalArgumentException if the info object does not represent
 * a MIDI device installed on the system
 * @see #getMidiDeviceInfo
 */
public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
    List providers = getMidiDeviceProviders();

    for(int i = 0; i < providers.size(); i++) {
        MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
        if (provider.isDeviceSupported(info)) {
            MidiDevice device = provider.getDevice(info);
            return device;
        }
    }
    throw new IllegalArgumentException("Requested device not installed: " + info);
}
 
Example 11
Source File: MidiSystem.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the requested MIDI device.
 *
 * @param info a device information object representing the desired device.
 * @return the requested device
 * @throws MidiUnavailableException if the requested device is not available
 * due to resource restrictions
 * @throws IllegalArgumentException if the info object does not represent
 * a MIDI device installed on the system
 * @see #getMidiDeviceInfo
 */
public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
    List providers = getMidiDeviceProviders();

    for(int i = 0; i < providers.size(); i++) {
        MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
        if (provider.isDeviceSupported(info)) {
            MidiDevice device = provider.getDevice(info);
            return device;
        }
    }
    throw new IllegalArgumentException("Requested device not installed: " + info);
}
 
Example 12
Source File: MidiSystem.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains the requested MIDI device.
 *
 * @param info a device information object representing the desired device.
 * @return the requested device
 * @throws MidiUnavailableException if the requested device is not available
 * due to resource restrictions
 * @throws IllegalArgumentException if the info object does not represent
 * a MIDI device installed on the system
 * @see #getMidiDeviceInfo
 */
public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
    List providers = getMidiDeviceProviders();

    for(int i = 0; i < providers.size(); i++) {
        MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
        if (provider.isDeviceSupported(info)) {
            MidiDevice device = provider.getDevice(info);
            return device;
        }
    }
    throw new IllegalArgumentException("Requested device not installed: " + info);
}
 
Example 13
Source File: MidiSystem.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains the requested MIDI device.
 *
 * @param info a device information object representing the desired device.
 * @return the requested device
 * @throws MidiUnavailableException if the requested device is not available
 * due to resource restrictions
 * @throws IllegalArgumentException if the info object does not represent
 * a MIDI device installed on the system
 * @see #getMidiDeviceInfo
 */
public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
    List providers = getMidiDeviceProviders();

    for(int i = 0; i < providers.size(); i++) {
        MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
        if (provider.isDeviceSupported(info)) {
            MidiDevice device = provider.getDevice(info);
            return device;
        }
    }
    throw new IllegalArgumentException("Requested device not installed: " + info);
}
 
Example 14
Source File: MidiSystem.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/** From a given MidiDeviceProvider, return the first appropriate device.
    @param provider The MidiDeviceProvider to check for MidiDevices.
    @param deviceClass The requested device type, one of Synthesizer.class,
    Sequencer.class, Receiver.class or Transmitter.class.
    @return A MidiDevice is considered appropriate, or null if no
    appropriate device is found.
 */
private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int j = 0; j < infos.length; j++) {
        MidiDevice device = provider.getDevice(infos[j]);
        if (isAppropriateDevice(device, deviceClass,
                                allowSynthesizer, allowSequencer)) {
            return device;
        }
    }
    return null;
}
 
Example 15
Source File: MidiSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains the requested MIDI device.
 *
 * @param info a device information object representing the desired device.
 * @return the requested device
 * @throws MidiUnavailableException if the requested device is not available
 * due to resource restrictions
 * @throws IllegalArgumentException if the info object does not represent
 * a MIDI device installed on the system
 * @see #getMidiDeviceInfo
 */
public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
    List providers = getMidiDeviceProviders();

    for(int i = 0; i < providers.size(); i++) {
        MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
        if (provider.isDeviceSupported(info)) {
            MidiDevice device = provider.getDevice(info);
            return device;
        }
    }
    throw new IllegalArgumentException("Requested device not installed: " + info);
}
 
Example 16
Source File: MidiSystem.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** From a given MidiDeviceProvider, return the first appropriate device.
    @param provider The MidiDeviceProvider to check for MidiDevices.
    @param deviceClass The requested device type, one of Synthesizer.class,
    Sequencer.class, Receiver.class or Transmitter.class.
    @return A MidiDevice is considered appropriate, or null if no
    appropriate device is found.
 */
private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
                                         Class deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int j = 0; j < infos.length; j++) {
        MidiDevice device = provider.getDevice(infos[j]);
        if (isAppropriateDevice(device, deviceClass,
                                allowSynthesizer, allowSequencer)) {
            return device;
        }
    }
    return null;
}
 
Example 17
Source File: MidiSystem.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains the requested MIDI device.
 *
 * @param info a device information object representing the desired device.
 * @return the requested device
 * @throws MidiUnavailableException if the requested device is not available
 * due to resource restrictions
 * @throws IllegalArgumentException if the info object does not represent
 * a MIDI device installed on the system
 * @see #getMidiDeviceInfo
 */
public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
    List providers = getMidiDeviceProviders();

    for(int i = 0; i < providers.size(); i++) {
        MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
        if (provider.isDeviceSupported(info)) {
            MidiDevice device = provider.getDevice(info);
            return device;
        }
    }
    throw new IllegalArgumentException("Requested device not installed: " + info);
}
 
Example 18
Source File: MidiSystem.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Return a MidiDevice with a given name from a given MidiDeviceProvider.
 *
 * @param  deviceName The name of the MidiDevice to be returned
 * @param  provider The MidiDeviceProvider to check for MidiDevices
 * @param  deviceClass The requested device type, one of Synthesizer.class,
 *         Sequencer.class, Receiver.class or Transmitter.class
 * @param  allowSynthesizer if true, Synthesizers are considered
 *         appropriate. Otherwise only pure MidiDevices are considered
 *         appropriate (unless allowSequencer is true). This flag only has
 *         an effect for deviceClass Receiver and Transmitter. For other
 *         device classes (Sequencer and Synthesizer), this flag has no
 *         effect.
 * @param  allowSequencer if true, Sequencers are considered appropriate.
 *         Otherwise only pure MidiDevices are considered appropriate
 *         (unless allowSynthesizer is true). This flag only has an effect
 *         for deviceClass Receiver and Transmitter. For other device
 *         classes (Sequencer and Synthesizer), this flag has no effect.
 * @return A MidiDevice matching the requirements, or null if none is found
 */
private static MidiDevice getNamedDevice(String deviceName,
                                         MidiDeviceProvider provider,
                                         Class<?> deviceClass,
                                         boolean allowSynthesizer,
                                         boolean allowSequencer) {
    MidiDevice.Info[] infos = provider.getDeviceInfo();
    for (int i = 0; i < infos.length; i++) {
        if (infos[i].getName().equals(deviceName)) {
            MidiDevice device = provider.getDevice(infos[i]);
            if (isAppropriateDevice(device, deviceClass,
                                    allowSynthesizer, allowSequencer)) {
                return device;
            }
        }
    }
    return null;
}
 
Example 19
Source File: MidiSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains the requested MIDI device.
 *
 * @param  info a device information object representing the desired device
 * @return the requested device
 * @throws MidiUnavailableException if the requested device is not available
 *         due to resource restrictions
 * @throws IllegalArgumentException if the info object does not represent a
 *         MIDI device installed on the system
 * @throws NullPointerException if {@code info} is {@code null}
 * @see #getMidiDeviceInfo
 */
public static MidiDevice getMidiDevice(final MidiDevice.Info info)
        throws MidiUnavailableException {
    Objects.requireNonNull(info);
    for (final MidiDeviceProvider provider : getMidiDeviceProviders()) {
        if (provider.isDeviceSupported(info)) {
            return provider.getDevice(info);
        }
    }
    throw new IllegalArgumentException(String.format(
            "Requested device not installed: %s", info));
}
 
Example 20
Source File: MidiSystem.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains the requested MIDI device.
 *
 * @param  info a device information object representing the desired device
 * @return the requested device
 * @throws MidiUnavailableException if the requested device is not available
 *         due to resource restrictions
 * @throws IllegalArgumentException if the info object does not represent a
 *         MIDI device installed on the system
 * @throws NullPointerException if {@code info} is {@code null}
 * @see #getMidiDeviceInfo
 */
public static MidiDevice getMidiDevice(final MidiDevice.Info info)
        throws MidiUnavailableException {
    Objects.requireNonNull(info);
    for (final MidiDeviceProvider provider : getMidiDeviceProviders()) {
        if (provider.isDeviceSupported(info)) {
            return provider.getDevice(info);
        }
    }
    throw new IllegalArgumentException(String.format(
            "Requested device not installed: %s", info));
}