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


Java MidiUnavailableException类代码示例

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


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

示例1: playWarningSound

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
private static void playWarningSound() {
//        if (2 > 1) {
//            return;
//        }

        try {
//            int velocity = 127;    // max volume
            int velocity = 90;    // max volume
            int sound = 65;
            Synthesizer synthesizer = MidiSystem.getSynthesizer();
            synthesizer.open();
            MidiChannel channel = synthesizer.getChannels()[9];  // drums channel.
            for (int i = 0; i < 10; i++) {
                Thread.sleep(100);
                channel.noteOn(sound + i, velocity);
                Thread.sleep(100);
                channel.noteOff(sound + i);
            }
        } catch (MidiUnavailableException | InterruptedException e1) {
            e1.printStackTrace();
        }
    }
 
开发者ID:teddyted,项目名称:iSeleda,代码行数:23,代码来源:Dialogs.java

示例2: play

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
public void play() {
	if (isPlaying) { // 如果已经在播放,返回
		return;
	}

	try {
		sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequencer.setSequence(sequence);
		sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY );
		sequencer.addMetaEventListener(this);
	} catch (InvalidMidiDataException ex) {
	} catch (MidiUnavailableException e) {
	}

	thread = new Thread(this);
	thread.start();
}
 
开发者ID:zhangjikai,项目名称:LinkGame,代码行数:19,代码来源:BackMusic.java

示例3: updateSequencer

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
/**
 * Updates the sequencer state. This method should be invoked after setting the sequencer in the plugin.
 */
public void updateSequencer() {
    lock.lock();
    try {
        MidiUtils.open(sequencer);

        // Close existing and create a sequencer transmitter that sends Sponge events.
        MidiUtils.close(sequencerTransmitter);
        if (sequencer != null) {
            sequencerTransmitter = sequencer.getTransmitter();
            sequencerTransmitter.setReceiver(new MidiSpongeEventReceiver(this));

            sequencer.addMetaEventListener(message -> {
                getEngine().getOperations().event(new MidiMetaMessageEvent(getMidiMetaMessageEventName(),
                        getEngine().getDefaultParameters().getEventClonePolicy(), message)).send();
            });
        }
    } catch (MidiUnavailableException e) {
        throw SpongeUtils.wrapException(e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:26,代码来源:MidiPlugin.java

示例4: updateSynthesizer

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
/**
 * Updates the synthesizer state. This method should be invoked after setting the synthesizer in the plugin.
 */
public void updateSynthesizer() {
    lock.lock();
    try {
        MidiUtils.open(synthesizer);

        // Close existing and create a new synthesizer receiver to generate sounds.
        MidiUtils.close(synthesizerReceiver);
        if (synthesizer != null) {
            synthesizerReceiver = synthesizer.getReceiver();
        }
    } catch (MidiUnavailableException e) {
        throw SpongeUtils.wrapException(e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:20,代码来源:MidiPlugin.java

示例5: updateInputDevice

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
/**
 * Updates the input device state. This method should be invoked after setting the input device in the plugin.
 */
public void updateInputDevice() {
    lock.lock();
    try {
        MidiUtils.open(inputDevice);

        // Close existing and create an input device transmitter that sends Sponge events.
        MidiUtils.close(inputTransmitter);
        if (inputDevice != null) {
            inputTransmitter = inputDevice.getTransmitter();
            inputTransmitter.setReceiver(new MidiSpongeEventReceiver(this));
        }
    } catch (MidiUnavailableException e) {
        throw SpongeUtils.wrapException(e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:21,代码来源:MidiPlugin.java

示例6: open

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

示例7: test

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

示例8: implOpen

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
@Override
protected synchronized void implOpen() throws MidiUnavailableException {
    if (Printer.trace) Printer.trace("> MidiInDevice: implOpen()");

    int index = ((MidiInDeviceProvider.MidiInDeviceInfo)getDeviceInfo()).getIndex();
    id = nOpen(index); // can throw MidiUnavailableException

    if (id == 0) {
        throw new MidiUnavailableException("Unable to open native device");
    }

    // create / start a thread to get messages
    if (midiInThread == null) {
        midiInThread = JSSecurityManager.createThread(this,
                                                "Java Sound MidiInDevice Thread",   // name
                                                false,  // daemon
                                                -1,    // priority
                                                true); // doStart
    }

    nStart(id); // can throw MidiUnavailableException
    if (Printer.trace) Printer.trace("< MidiInDevice: implOpen() completed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:MidiInDevice.java

示例9: implOpen

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
@Override
protected void implOpen() throws MidiUnavailableException {
    if (Printer.trace) Printer.trace(">> RealTimeSequencer: implOpen()");

    //openInternalSynth();

    // create PlayThread
    playThread = new PlayThread();

    //id = nOpen();
    //if (id == 0) {
    //    throw new MidiUnavailableException("unable to open sequencer");
    //}
    if (sequence != null) {
        playThread.setSequence(sequence);
    }

    // propagate caches
    propagateCaches();

    if (doAutoConnectAtNextOpen) {
        doAutoConnect();
    }
    if (Printer.trace) Printer.trace("<< RealTimeSequencer: implOpen() succeeded");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:RealTimeSequencer.java

示例10: runTest

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
static boolean runTest(
        boolean reloadInstr,    // reload all instruments?
        boolean unloadTo,       // unload "to" instrument?
        boolean unloadFrom      // unload "from" instrument?
        )
{
    boolean success = false;
    try {
        success = test(reloadInstr, unloadFrom, unloadTo);
    } catch (final MidiUnavailableException ignored) {
        // the test is not applicable
        success = true;
    } catch (Exception ex) {
        log("Exception: " + ex.toString());
    }
    cleanup();
    return success;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:bug4685396.java

示例11: main

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
public static void main(String argv[]) {
    Sequencer seq = null;
    try {
        seq = MidiSystem.getSequencer();
        seq.open();
    } catch (final MidiUnavailableException ignored) {
        // the test is not applicable
        return;
    }
    try {
        seq.startRecording();
        System.out.println("Test passed.");
    } catch (NullPointerException npe) {
        System.out.println("Caught NPE: "+npe);
        npe.printStackTrace();
        throw new RuntimeException("Test FAILED!");
    } catch (Exception e) {
        System.out.println("Unexpected Exception: "+e);
        e.printStackTrace();
        System.out.println("Test NOT failed.");
    } finally {
        seq.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:SeqStartRecording.java

示例12: testReceiverSend

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
/**
 * Execute Receiver.send() and expect that there is no exception.
 */
private static boolean testReceiverSend() {
    boolean result = true;

    Receiver receiver;
    ShortMessage shMsg = new ShortMessage();

    try {
        receiver = MidiSystem.getReceiver();
        shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
        try {
            receiver.send( shMsg, -1 );
        } catch(IllegalStateException ilEx) {
            ilEx.printStackTrace(System.out);
            out("IllegalStateException was thrown incorrectly!");
            result = false;
        }
        receiver.close();
    } catch(MidiUnavailableException e) {
        out("Midi unavailable, cannot test.");
    } catch(InvalidMidiDataException ine) {
        out("InvalidMidiDataException, cannot test.");
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ClosedReceiver.java

示例13: doAllTests

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

示例14: openInput

import javax.sound.midi.MidiUnavailableException; //导入依赖的package包/类
public static void openInput() throws Exception {
	setup();

	if (bUseDefaultSynthesizer) {
		Synthesizer synth = MidiSystem.getSynthesizer();
		synth.open();
		r = synth.getReceiver();
		try {
			Transmitter t = launchpad_s_plus.Launchpad.getInputDevice()
					.getTransmitter();
			t.setReceiver(r);
		} catch (MidiUnavailableException e) {
			out("wasn't able to connect the device's Transmitter to the default Synthesizer:");
			out(e);
			launchpad_s_plus.Launchpad.getInputDevice().close();
			System.exit(1);
		}
	}

	out("\nNow taking input.");

}
 
开发者ID:helionmusic,项目名称:launchpad_s_plus,代码行数:23,代码来源:MidiInDump.java

示例15: getMidiDeviceInfo

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


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