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


Java MidiDevice.open方法代碼示例

本文整理匯總了Java中javax.sound.midi.MidiDevice.open方法的典型用法代碼示例。如果您正苦於以下問題:Java MidiDevice.open方法的具體用法?Java MidiDevice.open怎麽用?Java MidiDevice.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.sound.midi.MidiDevice的用法示例。


在下文中一共展示了MidiDevice.open方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

示例2: MidiReciever

import javax.sound.midi.MidiDevice; //導入方法依賴的package包/類
public MidiReciever()
    {
        MidiDevice device;
        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
        for (int i = 0; i < infos.length; i++) {
            try {
            device = MidiSystem.getMidiDevice(infos[i]);
            //does the device have any transmitters?
            //if it does, add it to the device list
            System.out.println(infos[i]);

            //get all transmitters
            List<Transmitter> transmitters = device.getTransmitters();
            //and for each transmitter

            for(int j = 0; j<transmitters.size();j++) {
                //create a new receiver
                transmitters.get(j).setReceiver(
                        //using my own MidiInputReceiver
                        new MidiInputReceiver(device.getDeviceInfo().toString())
                );
            }

            Transmitter trans = device.getTransmitter();
            trans.setReceiver(new MidiInputReceiver(device.getDeviceInfo().toString()));

            //open each device
            device.open();
            //if code gets this far without throwing an exception
            //print a success message
            System.out.println(device.getDeviceInfo()+" Was Opened");


        } catch (MidiUnavailableException e) {}
    }


}
 
開發者ID:JorenSix,項目名稱:Panako,代碼行數:39,代碼來源:MidiReciever.java

示例3: open

import javax.sound.midi.MidiDevice; //導入方法依賴的package包/類
/**
 * Opens the MIDI device.
 *
 * @param device the MIDI device.
 */
public static void open(MidiDevice device) {
    if (device != null && !device.isOpen()) {
        try {
            device.open();
        } catch (MidiUnavailableException e) {
            throw SpongeUtils.wrapException(e);
        }
    }
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:15,代碼來源:MidiUtils.java

示例4: main

import javax.sound.midi.MidiDevice; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    MidiDevice/*Synthesizer*/ synth = null;

    try {
        synth = MidiSystem.getSynthesizer();
        //synth = MidiSystem.getMidiDevice(infos[0]);

        System.out.println("Synthesizer: " + synth.getDeviceInfo());
        synth.open();
        MidiMessage msg = new GenericMidiMessage(0x90, 0x3C, 0x40);
        //ShortMessage msg = new ShortMessage();
        //msg.setMessage(0x90, 0x3C, 0x40);

        synth.getReceiver().send(msg, 0);
        Thread.sleep(2000);

    } catch (Exception ex) {
        ex.printStackTrace();
        throw ex;
    } finally {
        if (synth != null && synth.isOpen())
            synth.close();
    }
    System.out.print("Did you heard a note? (enter 'y' or 'n') ");
    int result = System.in.read();
    System.in.skip(1000);
    if (result == 'y' || result == 'Y')
    {
        System.out.println("Test passed sucessfully.");
    }
    else
    {
        System.out.println("Test FAILED.");
        throw new RuntimeException("Test failed.");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,代碼來源:bug6186488.java

示例5: doTest

import javax.sound.midi.MidiDevice; //導入方法依賴的package包/類
private static boolean doTest(int numIterations, boolean input) throws Exception {
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    MidiDevice outDevice = null;
    MidiDevice inDevice = null;
    for (int i = 0; i < infos.length; i++) {
        MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
        if (! (device instanceof Sequencer) &&
            ! (device instanceof Synthesizer)) {
            if (device.getMaxReceivers() != 0) {
                outDevice = device;
            }
            if (device.getMaxTransmitters() != 0) {
                inDevice = device;
            }
        }
    }
    MidiDevice testDevice = null;
    if (input) {
        testDevice = inDevice;
    } else {
        testDevice = outDevice;
    }
    if (testDevice == null) {
        out("Cannot test: device not available.");
        return true;
    }
    out("Using Device: " + testDevice);

    for (int i = 0; i < numIterations; i++) {
        out("@@@ ITERATION: " + i);
        testDevice.open();
        // This sleep ensures that the thread of MidiInDevice is started.
        sleep(50);
        testDevice.close();
    }
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:Reopen.java

示例6: useDevice

import javax.sound.midi.MidiDevice; //導入方法依賴的package包/類
private static void useDevice(MidiDevice device) throws MidiUnavailableException
{
    Integer i = deviceUsage.get(device);
    if (i == null)
    {
        device.open();
        deviceUsage.put(device, 1);
    }
    else deviceUsage.put(device, i + 1);
}
 
開發者ID:SmashMaster,項目名稱:KraftigAudio,代碼行數:11,代碼來源:MidiOutput.java

示例7: useDevice

import javax.sound.midi.MidiDevice; //導入方法依賴的package包/類
private static void useDevice(MidiDevice device) throws MidiUnavailableException
{
    Integer i = USAGE.get(device);
    if (i == null)
    {
        device.open();
        long time = System.nanoTime();
        TIME.put(device, time);
        USAGE.put(device, 1);
    }
    else USAGE.put(device, i + 1);
}
 
開發者ID:SmashMaster,項目名稱:KraftigAudio,代碼行數:13,代碼來源:MidiInput.java

示例8: testDevice

import javax.sound.midi.MidiDevice; //導入方法依賴的package包/類
private static void testDevice(MidiDevice device) throws Exception {
    boolean timestampsAvailable = false;
    boolean timestampPrecisionOk = false;
    try {
        // expected behaviour if not opened?
        device.open();
        /* First, we're testing if timestamps are provided at all.
           Returning -1 (unsupported), while allowed by the API
           specification, is not sufficient to pass this test. */
        long timestamp = device.getMicrosecondPosition();
        timestampsAvailable = (timestamp != -1);

        /* Then, we're testing the precision. Note that the system time
           is measured in milliseconds, while the device time is measured
           in microseconds. */

        long systemTime1 = System.currentTimeMillis();
        long deviceTime1 = device.getMicrosecondPosition();
        // rest for 5 seconds
        Thread.sleep(5000);
        long systemTime2 = System.currentTimeMillis();
        long deviceTime2 = device.getMicrosecondPosition();

        // now both period measurements are calculated in milliseconds.
        long systemDuration = systemTime2 - systemTime1;
        long deviceDuration = (deviceTime2 - deviceTime1) / 1000;
        long delta = Math.abs(systemDuration - deviceDuration);
        // a deviation of 0.5 seconds (= 500 ms) is allowed.
        timestampPrecisionOk = (delta <= 500);
    } catch (Throwable t) {
        System.out.println("  - Caught exception. Not failed.");
        System.out.println("  - " + t.toString());
        return;
    } finally {
        device.close();
    }
    if (! timestampsAvailable) {
        throw new Exception("timestamps are not supported");
    }
    if (! timestampPrecisionOk) {
        throw new Exception("device timer not precise enough");
    }
    successfulTests++;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:45,代碼來源:MidiOutGetMicrosecondPositionBug.java


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