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


Java Sequencer.close方法代碼示例

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


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

示例1: test

import javax.sound.midi.Sequencer; //導入方法依賴的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

示例2: main

import javax.sound.midi.Sequencer; //導入方法依賴的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

示例3: LMidiSound

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
public LMidiSound() {
	if (rendererStatus == UNINITIALIZED) {
		rendererStatus = INITIALIZING;
		Thread thread = new Thread() {
			public final void run() {
				try {

					Sequencer sequencer = MidiSystem.getSequencer();
					sequencer.open();
					volumeSupported = (sequencer instanceof Synthesizer);

					sequencer.close();
					available = true;
				} catch (Throwable e) {
					available = false;
				}
				rendererStatus = INITIALIZED;
			}
		};
		thread.setDaemon(true);
		thread.start();
	}
}
 
開發者ID:cping,項目名稱:RipplePower,代碼行數:24,代碼來源:LMidiSound.java

示例4: main

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
			
	Synthesizer synth = MidiSystem.getSynthesizer();
	synth.open();
	synth.unloadAllInstruments(synth.getDefaultSoundbank());
	synth.loadAllInstruments(new MyOscillator());
	Sequence seq = MidiSystem.getSequence(FMTest1.class.getResource("/FMTest1.mid"));
	Sequencer seqr = MidiSystem.getSequencer(false);
	seqr.open();
	seqr.getTransmitter().setReceiver(synth.getReceiver());
	seqr.setSequence(seq);
	seqr.start();
	
	System.out.println();
	System.out.println("Is active, press enter to stop");
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	br.readLine();
	System.out.println("Stop...");
	
	seqr.stop();
	seqr.close();
	synth.close();
	
	System.exit(0);
}
 
開發者ID:bluenote10,項目名稱:gervill,代碼行數:26,代碼來源:FMTest1.java

示例5: hasSequencer

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
static boolean hasSequencer() {
    try {
        Sequencer seq = MidiSystem.getSequencer();
        if (seq != null) {
            seq.open();
            seq.close();
            return true;
        }
    } catch (Exception e) {}
    System.out.println("No sequencer available! Cannot execute test.");
    return false;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:TickLength.java

示例6: hasSequencer

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
static boolean hasSequencer() {
    try {
        Sequencer seq = MidiSystem.getSequencer();
        if (seq != null) {
            if (seq.isOpen()) {
                seq.close();
            }
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("No sequencer available! Cannot execute test.");
    return false;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:LoopIAE.java

示例7: hasSequencer

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
private static boolean hasSequencer() {
    try {
        Sequencer seq = MidiSystem.getSequencer();
        if (seq != null) {
            seq.open();
            seq.close();
            return true;
        }
    } catch (Exception e) {}
    System.out.println("No sequencer available! Cannot execute test.");
    return false;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:SequencerState.java

示例8: play

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
@Test
@Ignore
public void play() throws Exception
{
	// Obtains the default Sequencer connected to a default device.
	Sequencer sequencer = MidiSystem.getSequencer();

	// Opens the device, indicating that it should now acquire any
	// system resources it requires and become operational.
	sequencer.open();

	try
	{
		// create a stream from a file
		java.io.InputStream is = new FileInputStream(new File("D:\\rs\\07\\cache\\track1\\name-687938017.midi"));

		// Sets the current sequence on which the sequencer operates.
		// The stream must point to MIDI file data.
		sequencer.setSequence(is);

		// Starts playback of the MIDI data in the currently loaded sequence.
		sequencer.start();

		while (sequencer.isRunning())
		{
			Thread.sleep(1000L);
		}
	}
	finally
	{
		sequencer.close();
	}
}
 
開發者ID:runelite,項目名稱:runelite,代碼行數:34,代碼來源:TrackDumperTest.java

示例9: doTest

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
public static void doTest(int mode) {
    Sequencer seq = null;
    boolean connected = false;

    try {
        switch (mode) {
        case 1:
            seq = MidiSystem.getSequencer();
            connected = true;
            break;
        case 2:
            seq = MidiSystem.getSequencer(false);
            connected = false;
            break;
        case 3:
            seq = MidiSystem.getSequencer(true);
            connected = true;
            break;
        }
        out("Testing Sequencer "+seq);
        if (connected) {
            out("  opened in connected mode.");
        } else {
            out("  opened in non-connected mode.");
        }
        System.out.println("  opening...");
        seq.open();
    } catch (MidiUnavailableException mue) {
        System.err.println("MidiUnavailableException was thrown: " + mue);
        System.err.println("  could not test this sequencer.");
        return;
    }

    try {
        List<Transmitter> transmitters = seq.getTransmitters();
        int size = transmitters.size();
        out("  transmitters.size()="+size);
        if (size != 1 && connected) {
            out("  should have 1 connection! Failed.");
            failed = true;
        }
        if (size != 0 && !connected) {
            out("  should have 0 connections! Failed.");
            failed = true;
        }
        out("  closing...");
        seq.close();
        transmitters = seq.getTransmitters();
        size = transmitters.size();
        out("  transmitters.size()="+size);
        if (size != 0) {
            out("  should have 0 connections! Failed.");
            failed = true;
        }

        out("  opening again...");
        seq.open();
        transmitters = seq.getTransmitters();
        size = transmitters.size();
        out("  transmitters.size()="+size);
        if (size != 1 && connected) {
            out("  should have 1 connection! Failed.");
            failed = true;
        }
        if (size != 0 && !connected) {
            out("  should have 0 connections! Failed.");
            failed = true;
        }
    } catch (Exception e) {
        System.err.println("  unexpectedException was thrown: " + e);
        System.err.println("  causes this test to FAIL.");
        failed = true;
    }
    seq.close();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:76,代碼來源:GetSequencer.java

示例10: main

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
public static void main(String argv[]) {
    Sequencer s = null;
    try {
        s = MidiSystem.getSequencer();
        s.open();
    } catch (final MidiUnavailableException ignored) {
        // the test is not applicable
        return;
    }
    try {
        Sequence seq = new Sequence(Sequence.PPQ, 384, 2);
        s.setSequence(seq);
        Track t = seq.getTracks()[0];
        ShortMessage msg = new ShortMessage();
        msg.setMessage(0x90, 0x40, 0x7F);
        t.add(new MidiEvent(msg, 11000));
        msg.setMessage(0x90, 0x40, 0x00);
        t.add(new MidiEvent(msg, 12000));
        t = seq.getTracks()[1];
        s.recordEnable(t, -1);
        System.out.println("Started recording...");
        s.startRecording();
        Receiver r = s.getReceiver();
        Thread.sleep(100);
        // send a normal message
        System.out.println("Recording a normal NOTE ON message...");
        msg.setMessage(0x90, 0x40, 0x6F);
        r.send(msg, -1);
        Thread.sleep(100);
        // send a normal message
        System.out.println("Recording a normal NOTE OFF message...");
        msg.setMessage(0x90, 0x40, 0x00);
        r.send(msg, -1);
        Thread.sleep(100);
        s.stop();
        // now see if the messages were recorded
        System.out.println("Recorded messages:");
        int sameMessage = 0;
        for (int i = 0; i < t.size(); i++) {
            System.out.print(" "+(i+1)+". ");
            printEvent(t.get(i));
            if (t.get(i).getMessage() == msg) {
                System.out.println("## Failed: Same Message reference!");
                sameMessage++;
            }
        }
        if (sameMessage > 0) {
            System.out.println("## Failed: The same instance was recorded!");
            throw new Exception("Test FAILED!");
        }
        System.out.println("Did not detect any duplicate messages.");
        System.out.println("Test passed.");
    } catch (Exception e) {
        System.out.println("Unexpected Exception: "+e);
        //e.printStackTrace();
        throw new RuntimeException("Test FAILED!");
    } finally {
        s.close();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:61,代碼來源:SeqRecordDoesNotCopy.java

示例11: main

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
    if (!hasSequencer()) {
        return;
    }
    Sequencer sequencer = MidiSystem.getSequencer();
    Sequence sequence = new Sequence(Sequence.PPQ, 240);
    Track track = sequence.createTrack();

    track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,100),0));
    track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,0),0 + 240));
    track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,100),10*20));
    track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,0),10*20 + 10));

    try {
        sequencer.open();
        sequencer.setSequence(sequence);
        sequencer.setTempoInBPM(100);

        System.out.println("Setting loop end point to 1");
        sequencer.setLoopEndPoint(1);
        System.out.println("  -> effectively: "+sequencer.getLoopEndPoint());
        System.out.println("Setting loop start point to 2 -- should throw IAE");
        sequencer.setLoopStartPoint(2);
        System.out.println("  -> effectively: "+sequencer.getLoopStartPoint());
        System.out.println("No IllegalArgumentException was thrown!");
        failed = true;
    } catch (IllegalArgumentException iae) {
        System.out.println("IAE was thrown correctly.");
    } catch (MidiUnavailableException mue) {
        System.out.println("MidiUnavailableException was thrown: " + mue);
        System.out.println("Cannot execute test.");
    } catch (InvalidMidiDataException imEx) {
        System.out.println("InvalidMidiDataException was thrown.");
        imEx.printStackTrace();
        System.out.println("Cannot execute test.");
    } finally {
        if (sequencer != null && sequencer.isOpen()) {
            sequencer.close();
        }
    }
    if (failed) {
        throw new Exception("Test FAILED!");
    }
    System.out.println("test passed.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:46,代碼來源:LoopIAE.java


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