本文整理汇总了Java中javax.sound.midi.MidiSystem.getMidiDeviceInfo方法的典型用法代码示例。如果您正苦于以下问题:Java MidiSystem.getMidiDeviceInfo方法的具体用法?Java MidiSystem.getMidiDeviceInfo怎么用?Java MidiSystem.getMidiDeviceInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.midi.MidiSystem
的用法示例。
在下文中一共展示了MidiSystem.getMidiDeviceInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMidiInput
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* 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");
}
示例2: open
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private void open () throws MidiUnavailableException{
synth = MidiSystem.getSynthesizer();
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
MidiDevice.Info msInfo = null;
StringBuilder sb = new StringBuilder();
sb.append("Available MidiDevice are\n");
for ( MidiDevice.Info i:infos ){
if ( i.toString().contains("Microsoft GS Wavetable Synth") ){
msInfo = i;
sb.append(" *****");
}
sb.append("\t" + i.toString() + ": " + i.getDescription() + '\n');
}
// MidiDevice msDevice = MidiSystem.getMidiDevice(msInfo);
synth.open();
sb.append("synth=" + synth.getDeviceInfo().toString() + " with default soundbank " + synth.getDefaultSoundbank().getDescription() + '\n');
sb.append("max synthesizer latency =" + synth.getLatency() + " us\n");
log.info(sb.toString());
channels = synth.getChannels();
channel = channels[PERCUSSION_CHANNEL];
}
示例3: main
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
boolean allOk = true;
MidiDevice.Info[] infos;
out("\nTesting MidiDevices retrieved via MidiSystem");
infos = MidiSystem.getMidiDeviceInfo();
allOk &= testDevices(infos, null);
out("\nTesting MidiDevices retrieved from MidiDeviceProviders");
List providers = JDK13Services.getProviders(MidiDeviceProvider.class);
for (int i = 0; i < providers.size(); i++) {
MidiDeviceProvider provider = (MidiDeviceProvider)providers.get(i);
infos = provider.getDeviceInfo();
allOk &= testDevices(infos, provider.getClass().getName());
}
if (!allOk) {
throw new Exception("Test failed");
} else {
out("Test passed");
}
}
示例4: main
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
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
}
}
}
}
}
示例5: isMidiInstalled
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Returns true if at least one MIDI (port) device is correctly installed on
* the system.
*/
public static boolean isMidiInstalled() {
boolean result = false;
MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < devices.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
} catch (Exception e1) {
System.err.println(e1);
}
if (result)
break;
}
return result;
}
示例6: isMidiInstalled
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Returns true if at least one MIDI (port) device is correctly installed on
* the system.
*/
private static boolean isMidiInstalled() {
boolean result = false;
MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < devices.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
result = !(device instanceof Sequencer)
&& !(device instanceof Synthesizer);
} catch (Exception e1) {
System.err.println(e1);
}
if (result)
break;
}
return result;
}
示例7: doAllTests
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private static void doAllTests() {
boolean problemOccured = false;
boolean succeeded = true;
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < infos.length; i++) {
MidiDevice device = null;
try {
device = MidiSystem.getMidiDevice(infos[i]);
succeeded &= doTest(device);
} catch (MidiUnavailableException e) {
out("exception occured; cannot test");
problemOccured = true;
}
}
if (infos.length == 0) {
out("Soundcard does not exist or sound drivers not installed!");
out("This test requires sound drivers for execution.");
}
isTestExecuted = !problemOccured;
isTestPassed = succeeded;
}
示例8: doAll
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
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!");
}
}
}
示例9: isMidiInstalled
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Returns true if at least one MIDI (port) device is correctly installed on
* the system.
*/
public static boolean isMidiInstalled() {
boolean result = false;
MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < devices.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
} catch (Exception e1) {
System.err.println(e1);
}
if (result)
break;
}
if (!result) {
System.err.println("Soundcard does not exist or sound drivers not installed!");
System.err.println("This test requires sound drivers for execution.");
}
return result;
}
示例10: getMidiDeviceInfo
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Retrieve a MidiDevice.Info for a given name.
*
* This method tries to return a MidiDevice.Info whose name matches the
* passed name. If no matching MidiDevice.Info is found, null is returned.
* If bForOutput is true, then only output devices are searched, otherwise
* only input devices.
*
* @param strDeviceName
* the name of the device for which an info object should be
* retrieved.
* @param bForOutput
* If true, only output devices are considered. If false, only
* input devices are considered.
*
* @return A MidiDevice.Info object matching the passed device name or null
* if none could be found.
*/
public static MidiDevice.Info getMidiDeviceInfo(String strDeviceName,
boolean bForOutput) {
MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < aInfos.length; i++) {
if (aInfos[i].getName().contains(strDeviceName)) {
try {
MidiDevice device = MidiSystem.getMidiDevice(aInfos[i]);
boolean bAllowsInput = (device.getMaxTransmitters() != 0);
boolean bAllowsOutput = (device.getMaxReceivers() != 0);
if ((bAllowsOutput && bForOutput)
|| (bAllowsInput && !bForOutput)) {
return aInfos[i];
}
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
}
}
return null;
}
示例11: getDevice
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
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);
}
示例12: findAudioSynthesizer
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private Synthesizer findAudioSynthesizer() throws MidiUnavailableException, ClassNotFoundException {
Class<?> audioSynth = Class.forName("com.sun.media.sound.AudioSynthesizer");
// First check if default synthesizer is AudioSynthesizer.
Synthesizer synth = MidiSystem.getSynthesizer();
if (audioSynth.isAssignableFrom(synth.getClass())) {
return synth;
}
// If default synthesizer is not AudioSynthesizer, check others.
MidiDevice.Info[] midiDeviceInfo = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < midiDeviceInfo.length; i++) {
MidiDevice dev = MidiSystem.getMidiDevice(midiDeviceInfo[i]);
if (audioSynth.isAssignableFrom(dev.getClass())) {
return (Synthesizer)dev;
}
}
return null;
}
示例13: getAvailableTransmitters
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Get a list of MidiDevices which are advertised as having
* at least one Transmitter.
*
* @return list of MidiDevices
* @throws MidiUnavailableException
*/
public static List<MidiDevice> getAvailableTransmitters() throws MidiUnavailableException {
ArrayList<MidiDevice> result = new ArrayList<MidiDevice>();
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for (MidiDevice.Info info : infos) {
MidiDevice device = MidiSystem.getMidiDevice(info);
int maxTransmitters = device.getMaxTransmitters();
if (maxTransmitters == -1 || maxTransmitters > 0) {
result.add(device);
}
}
return result;
}
示例14: getMidiDeviceInfo
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Retrieve a MidiDevice.Info for a given name.
*
* This method tries to return a MidiDevice.Info whose name matches the
* passed name. If no matching MidiDevice.Info is found, null is returned.
* If bForOutput is true, then only output devices are searched, otherwise
* only input devices.
*
* @param strDeviceName
* the name of the device for which an info object should be
* retrieved.
* @param bForOutput
* If true, only output devices are considered. If false, only
* input devices are considered.
* @return A MidiDevice.Info object matching the passed device name or null
* if none could be found.
*/
public static MidiDevice.Info getMidiDeviceInfo(String strDeviceName,
boolean bForOutput) {
MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < aInfos.length; i++) {
if (aInfos[i].getName().equals(strDeviceName)) {
try {
MidiDevice device = MidiSystem.getMidiDevice(aInfos[i]);
boolean bAllowsInput = (device.getMaxTransmitters() != 0);
boolean bAllowsOutput = (device.getMaxReceivers() != 0);
if ((bAllowsOutput && bForOutput)
|| (bAllowsInput && !bForOutput)) {
return aInfos[i];
}
} catch (MidiUnavailableException e) {
// TODO:
}
}
}
return null;
}
示例15: getMidiDevice
import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/**
* Gets a midi device by name
*
* @param midiDeviceName
* The name of the midi device
* @param outputDevice
* "OUT" only output devices are considered, "IN" only input
* devices are considered.
* @return The midi device
* @throws MidiUnavailableException
* If the midi device can not be found
*/
public static MidiDevice getMidiDevice(String midiDeviceName,
String direction) throws MidiUnavailableException {
MidiDevice.Info[] midiInfos;
MidiDevice device = null;
if (midiDeviceName != null) {
midiInfos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < midiInfos.length; i++) {
if (midiInfos[i].getName().equals(midiDeviceName)) {
device = MidiSystem.getMidiDevice(midiInfos[i]);
if (getDirectionOfMidiDevice(device).equals(direction)) {
return device;
}
}
}
}
throw new MidiUnavailableException();
}