Java Code Examples for javax.sound.midi.Sequencer#close()

The following examples show how to use javax.sound.midi.Sequencer#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SequencerImplicitSynthOpen.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: SequencerImplicitSynthOpen.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: SequencerImplicitSynthOpen.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: SequencerImplicitSynthOpen.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: SequencerImplicitSynthOpen.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: SequencerImplicitSynthOpen.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: SequencerImplicitSynthOpen.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 8
Source File: SequencerImplicitSynthOpen.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 9
Source File: SequencerImplicitSynthOpen.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 10
Source File: SequencerImplicitSynthOpen.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 11
Source File: SequencerImplicitSynthOpen.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 12
Source File: LMidiSound.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public LMidiSound(String fileName) throws IOException {
	bytes = new ArrayByte(UIRes.getStream(fileName), ArrayByte.BIG_ENDIAN);
	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();
	}
}
 
Example 13
Source File: MetaCallback.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: LoopIAE.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 15
Source File: TrackDumperTest.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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();
	}
}
 
Example 16
Source File: TickLength.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 17
Source File: SequencerState.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 18
Source File: LoopIAE.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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.");
}
 
Example 19
Source File: SeqRecordDoesNotCopy.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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();
    }
}
 
Example 20
Source File: GetSequencer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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();
}