当前位置: 首页>>代码示例>>Java>>正文


Java MidiSystem.getMidiDevice方法代码示例

本文整理汇总了Java中javax.sound.midi.MidiSystem.getMidiDevice方法的典型用法代码示例。如果您正苦于以下问题:Java MidiSystem.getMidiDevice方法的具体用法?Java MidiSystem.getMidiDevice怎么用?Java MidiSystem.getMidiDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.midi.MidiSystem的用法示例。


在下文中一共展示了MidiSystem.getMidiDevice方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: init

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
private void init() throws MidiUnavailableException {
	devIn = MidiSystem.getMidiDevice(inInfo); devIn.open();
	devOut = MidiSystem.getMidiDevice(outInfo); devOut.open();
	midiIn = new MidiInput(); devIn.getTransmitter().setReceiver(midiIn);
	midiOut = (MidiDeviceReceiver)devOut.getReceiver();
	
	//MIDI Message Sender Thread:
	midiTx = new Thread(() -> { while(true) {
		int size; while((size=cue.size()) > 0) {
			MidiMessage msg; synchronized(this) { msg = cue.get(0); cue.remove(0); } midiOut.send(msg, -1);
			if(size > 10000) { //Keep array under 10,000...
				synchronized(this) { size=cue.size(); while(size > 50) { cue.remove(size-1); size--; }}
				debug("Buffer had to be force-cleared!");
			} if(Thread.interrupted()) return;
		} if(Thread.interrupted()) return;
	}}); midiTx.setPriority(1); midiTx.start();
	
	programMode(); setAll(-1); //Reset LaunchPad Lights.
}
 
开发者ID:Pecacheu,项目名称:LaunchPad-MC,代码行数:20,代码来源:LaunchPad.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: listenStart

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
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();
			}
		}
	}
 
开发者ID:soma-arc,项目名称:K-Visions,代码行数:26,代码来源:MidiHandler.java

示例15: listDevices

import javax.sound.midi.MidiSystem; //导入方法依赖的package包/类
/** Print the available MIDI Devices. */
public static void listDevices() {
    // Ask the MidiSystem what is available.
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    // Print info about each device.
    for (MidiDevice.Info info : infos) {
        System.out.println("MIDI Info: " + info.getDescription() + ", " + info.getName() + ", "
                + info.getVendor() + ", " + info.getVersion());
        // Get the device for more information.
        try {
            MidiDevice device = MidiSystem.getMidiDevice(info);
            System.out.println("   Device: " + ", #recv = " + device.getMaxReceivers()
                    + ", #xmit = " + device.getMaxTransmitters() + ", open = "
                    + device.isOpen() + ", " + device);
        } catch (MidiUnavailableException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:philburk,项目名称:jsyn,代码行数:20,代码来源:MidiDeviceTools.java


注:本文中的javax.sound.midi.MidiSystem.getMidiDevice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。