當前位置: 首頁>>代碼示例>>Java>>正文


Java MidiSystem.getMidiDeviceInfo方法代碼示例

本文整理匯總了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");
}
 
開發者ID:daveho,項目名稱:Gervill4Beads,代碼行數:36,代碼來源:CaptureMidiMessages.java

示例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];
    }
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:23,代碼來源:DrumSound.java

示例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");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:DefaultDevices.java

示例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
                }
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:UnsupportedInfo.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:OpenClose.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ClosedReceiver.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ReceiverTransmitterAvailable.java

示例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!");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:MidiOutGetMicrosecondPositionBug.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:MidiOutGetMicrosecondPositionBug.java

示例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;
}
 
開發者ID:helionmusic,項目名稱:launchpad_s_plus,代碼行數:39,代碼來源:MidiCommon.java

示例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);
}
 
開發者ID:theokyr,項目名稱:TuxGuitar-1.3.1-fork,代碼行數:27,代碼來源:MiPortProvider.java

示例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;
}
 
開發者ID:arisona,項目名稱:ether,代碼行數:20,代碼來源:URLAudioSource.java

示例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;
}
 
開發者ID:daveho,項目名稱:Gervill4Beads,代碼行數:24,代碼來源:CaptureMidiMessages.java

示例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;
}
 
開發者ID:aguelle,項目名稱:MIDI-Automator,代碼行數:43,代碼來源:MidiUtils.java

示例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();
}
 
開發者ID:aguelle,項目名稱:MIDI-Automator,代碼行數:36,代碼來源:MidiUtils.java


注:本文中的javax.sound.midi.MidiSystem.getMidiDeviceInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。