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


Java MidiDevice类代码示例

本文整理汇总了Java中javax.sound.midi.MidiDevice的典型用法代码示例。如果您正苦于以下问题:Java MidiDevice类的具体用法?Java MidiDevice怎么用?Java MidiDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MidiDevice类属于javax.sound.midi包,在下文中一共展示了MidiDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doAll

import javax.sound.midi.MidiDevice; //导入依赖的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

示例2: getDevice

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
public final MidiDevice getDevice(MidiDevice.Info info) {
    if (info instanceof Info) {
        readDeviceInfos();
        MidiDevice[] devices = getDeviceCache();
        Info[] infos = getInfoCache();
        Info thisInfo = (Info) info;
        int index = thisInfo.getIndex();
        if (index >= 0 && index < devices.length && infos[index] == info) {
            if (devices[index] == null) {
                devices[index] = createDevice(thisInfo);
            }
            if (devices[index] != null) {
                return devices[index];
            }
        }
    }

    throw new IllegalArgumentException("MidiDevice " + info.toString()
                                       + " not supported by this provider.");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:AbstractMidiDeviceProvider.java

示例3: isMidiInstalled

import javax.sound.midi.MidiDevice; //导入依赖的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

示例4: main

import javax.sound.midi.MidiDevice; //导入依赖的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: test

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
static boolean test(Sequencer sequencer) throws MidiUnavailableException {
    log("");
    log("opening sequencer...");
    sequencer.open();   // opens connected synthesizer implicitly
    MidiDevice synth = getConnectedDevice(sequencer);
    log("  connected device: " + getDeviceStr(synth));

    log("closing sequencer...");
    sequencer.close();  // closes the synth implicitly
    log("  synth is " + getDeviceStr(synth));
    MidiDevice synth2 = getConnectedDevice(sequencer);
    log("  currently connected device: " + getDeviceStr(synth2));

    if (synth != null && synth.isOpen()) {
        log("FAIL.");
        return false;
    }
    log("OK.");
    return true;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:SequencerImplicitSynthOpen.java

示例6: getConnectedDevice

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:SequencerImplicitSynthOpen.java

示例7: isMidiInstalled

import javax.sound.midi.MidiDevice; //导入依赖的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

示例8: getDevice

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
@Override
public final MidiDevice getDevice(final MidiDevice.Info info) {
    Objects.requireNonNull(info);
    if (info instanceof Info) {
        readDeviceInfos();
        MidiDevice[] devices = getDeviceCache();
        Info[] infos = getInfoCache();
        Info thisInfo = (Info) info;
        int index = thisInfo.getIndex();
        if (index >= 0 && index < devices.length && infos[index] == info) {
            if (devices[index] == null) {
                devices[index] = createDevice(thisInfo);
            }
            if (devices[index] != null) {
                return devices[index];
            }
        }
    }
    throw MidiUtils.unsupportedDevice(info);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:AbstractMidiDeviceProvider.java

示例9: doAllTests

import javax.sound.midi.MidiDevice; //导入依赖的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

示例10: main

import javax.sound.midi.MidiDevice; //导入依赖的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

示例11: testDevice

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
private static boolean testDevice(MidiDevice device, Class type,
        String providerClassName, boolean testWrong, boolean expectedResult) {
    boolean allOk = true;
    String instanceName = device.getDeviceInfo().getName();

    // no error
    allOk &= testDevice(device, type, providerClassName,
                        instanceName, expectedResult);

    if (testWrong) {
        // erroneous provider class name, correct instance name
        allOk &= testDevice(device, type, ERROR_PROVIDER_CLASS_NAME,
                            instanceName, expectedResult);

        // correct provider class name, erroneous instance name
        // we presume that provider provides only one class of requested type
        allOk &= testDevice(device, type, providerClassName,
                            ERROR_INSTANCE_NAME, expectedResult);
    }

    return allOk;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:DefaultDevices.java

示例12: update

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
@Override
public void update() throws Exception
{
	this.transmitterLoop++;
	if (this.transmitterLoop % 600 == 0)
	{
		MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
		for (int i = 0; i < infos.length; i++)
		{
			MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
			if (NMOConfiguration.INSTANCE.integrations.midiTransmitter.transmitters.contains(device.getDeviceInfo().getName()))
			{
				if (!device.isOpen() && device.getMaxTransmitters() != 0)
				{
					final String name = device.getDeviceInfo().getName() + "/" + device.getDeviceInfo().getDescription() + "/" + device.getDeviceInfo().getVendor();
					log.info("Connected MIDI device: " + name);
					device.getTransmitter().setReceiver(new Receiver()
					{
						@Override
						public void send(MidiMessage message, long timeStamp)
						{
							MainDialog.resetActivityTimer(MIDI_TRANSMITTER);
						}

						@Override
						public void close()
						{
							log.info("Disconnected MIDI device: " + name);
						}
					});
					device.open();
				}
			}
		}
	}
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:37,代码来源:IntegrationMidiTransmitter.java

示例13: connectInputDevice

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
/**
 * Sets and updates the input MIDI device in the plugin. If there has already been connected an another input device then replaces it.
 *
 * @param deviceName the input MIDI device name.
 */
public void connectInputDevice(String deviceName) {
    MidiDevice device = getDeviceByName(deviceName);
    if (device == null) {
        throw new SpongeException("MIDI device named '" + deviceName + "' not found");
    }

    setInputDevice(device);
    updateInputDevice();
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:15,代码来源:MidiPlugin.java

示例14: checkOpen

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
private void checkOpen(MidiDevice device, boolean desiredState) {
    if (device.isOpen() != desiredState) {
        out("device should be " +
                            getStateString(desiredState) + ", but isn't!");
        failed = true;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:OpenClose.java

示例15: setInputDevice

import javax.sound.midi.MidiDevice; //导入依赖的package包/类
/**
 * Sets the input device. If there has already been an another input device set then it will be closed.
 *
 * @param inputDevice the input device.
 */
public void setInputDevice(MidiDevice inputDevice) {
    if (inputDevice != this.inputDevice) {
        MidiUtils.close(this.inputDevice);
    }

    this.inputDevice = inputDevice;
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:13,代码来源:MidiPlugin.java


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