Java Code Examples for javax.sound.midi.MidiSystem#getSequence()

The following examples show how to use javax.sound.midi.MidiSystem#getSequence() . 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: MidiTest.java    From kyoko with MIT License 7 votes vote down vote up
public static void main(String... args) throws MidiUnavailableException, IOException, InvalidMidiDataException {
    var synth = MidiSystem.getSynthesizer();
    synth.loadAllInstruments(synth.getDefaultSoundbank());

    var sequencer = MidiSystem.getSequencer();
    var sequence = MidiSystem.getSequence(new File("test.mid"));

    // sequencer.getTransmitter().setReceiver(synth.getReceiver());
    sequencer.open();
    sequencer.setSequence(sequence);
    sequencer.setTempoFactor(1f);
    sequencer.addMetaEventListener(meta -> {
        if (meta.getType() == 47) { // track end
            sequencer.setTickPosition(0);
            sequencer.start();
        }
    });
    sequencer.start();
}
 
Example 2
Source File: MidiEngine.java    From javagame with MIT License 6 votes vote down vote up
/**
 * MIDI�t�@�C�������[�h
 * @param url MIDI�t�@�C����URL
 */
public static void load(URL url) throws MidiUnavailableException, InvalidMidiDataException, IOException {
    if (sequencer == null) {
        // �V�[�P���T���擾
        sequencer = MidiSystem.getSequencer();
        // �V�[�P���T���J��
        sequencer.open();
        // ���^�C�x���g���X�i�[��o�^
        sequencer.addMetaEventListener(new MyMetaEventListener());
    }

    // MIDI�V�[�P���X��o�^
    sequences[counter] = MidiSystem.getSequence(url);

    counter++;
}
 
Example 3
Source File: MidiEngine.java    From javagame with MIT License 6 votes vote down vote up
/**
 * MIDI�t�@�C�������[�h
 * @param url MIDI�t�@�C����URL
 */
public static void load(URL url) throws MidiUnavailableException, InvalidMidiDataException, IOException {
    if (sequencer == null) {
        // �V�[�P���T���擾
        sequencer = MidiSystem.getSequencer();
        // �V�[�P���T���J��
        sequencer.open();
        // ���^�C�x���g���X�i�[��o�^
        sequencer.addMetaEventListener(new MyMetaEventListener());
    }

    // MIDI�V�[�P���X��o�^
    sequences[counter] = MidiSystem.getSequence(url);

    counter++;
}
 
Example 4
Source File: MidiEngine.java    From javagame with MIT License 6 votes vote down vote up
/**
 * MIDI�t�@�C�������[�h
 * @param url MIDI�t�@�C����URL
 */
public static void load(URL url) throws MidiUnavailableException, InvalidMidiDataException, IOException {
    if (sequencer == null) {
        // �V�[�P���T���擾
        sequencer = MidiSystem.getSequencer();
        // �V�[�P���T���J��
        sequencer.open();
        // ���^�C�x���g���X�i�[��o�^
        sequencer.addMetaEventListener(new MyMetaEventListener());
    }

    // MIDI�V�[�P���X��o�^
    sequences[counter] = MidiSystem.getSequence(url);

    counter++;
}
 
Example 5
Source File: LMidiSound.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public void playSound(InputStream in) {
	try {
		System.setProperty("javax.sound.midi.Sequencer", "com.sun.media.sound.RealTimeSequencerProvider");
		if (this.sequencer == null) {
			this.sequencer = MidiSystem.getSequencer();
			if (!this.sequencer.isOpen()) {
				this.sequencer.open();
			}
		}

		Sequence seq = MidiSystem.getSequence(in);
		this.sequencer.setSequence(seq);
		this.sequencer.start();
		this.sequencer.addMetaEventListener(this);

		if (this.volume != 1) {
			this.setSoundVolume(this.volume);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 6
Source File: MidiEngine.java    From javagame with MIT License 6 votes vote down vote up
/**
 * MIDI�t�@�C�������[�h
 * 
 * @param url MIDI�t�@�C����URL
 */
public static void load(URL url) throws MidiUnavailableException,
        InvalidMidiDataException, IOException {
    if (sequencer == null) {
        // �V�[�P���T���擾
        sequencer = MidiSystem.getSequencer();
        // �V�[�P���T���J��
        sequencer.open();
        // ���^�C�x���g���X�i�[��o�^
        sequencer.addMetaEventListener(new MyMetaEventListener());
    }

    // MIDI�V�[�P���X��o�^
    sequences[counter] = MidiSystem.getSequence(url);

    counter++;
}
 
Example 7
Source File: MidiEngine.java    From javagame with MIT License 6 votes vote down vote up
/**
 * MIDI�t�@�C�������[�h
 * @param url MIDI�t�@�C����URL
 */
public static void load(URL url) throws MidiUnavailableException, InvalidMidiDataException, IOException {
    if (sequencer == null) {
        // �V�[�P���T���擾
        sequencer = MidiSystem.getSequencer();
        // �V�[�P���T���J��
        sequencer.open();
        // ���^�C�x���g���X�i�[��o�^
        sequencer.addMetaEventListener(new MyMetaEventListener());
    }

    // MIDI�V�[�P���X��o�^
    sequences[counter] = MidiSystem.getSequence(url);

    counter++;
}
 
Example 8
Source File: MidiSMPTE.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Sequence s = null;
    //File midiFile = new File("outsmpte.mid");
    //InputStream is = new FileInputStream(midiFile);
    //is = new BufferedInputStream(is);
    InputStream is = new ByteArrayInputStream(smptemidifile);
    s = MidiSystem.getSequence(is);
    long duration = s.getMicrosecondLength() / 1000000;
    System.out.println("Duration: "+duration+" seconds ");
    if (duration > 14) {
        throw new Exception("SMPTE time reader is broken! Test FAILED");
    }
    System.out.println("Test passed");
}
 
Example 9
Source File: MidiEngine.java    From javagame with MIT License 5 votes vote down vote up
/**
 * MIDI�t�@�C�������[�h
 * @param url MIDI�t�@�C����URL
 */
public static void load(URL url) throws MidiUnavailableException, InvalidMidiDataException, IOException {
    if (sequencer == null) {
        // �V�[�P���T���擾
        sequencer = MidiSystem.getSequencer();
        // �V�[�P���T���J��
        sequencer.open();
        // ���^�C�x���g���X�i�[��o�^
        sequencer.addMetaEventListener(new MyMetaEventListener());
    }

    // MIDI�V�[�P���X��o�^
    sequences[counter] = MidiSystem.getSequence(url);
    counter++;
}
 
Example 10
Source File: JavaSoundAudioClip.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean createSequencer(BufferedInputStream in) throws IOException {

        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");

        // get the sequencer
        try {
            sequencer = MidiSystem.getSequencer( );
        } catch(MidiUnavailableException me) {
            if (DEBUG || Printer.err)me.printStackTrace();
            return false;
        }
        if (sequencer==null) {
            return false;
        }

        try {
            sequence = MidiSystem.getSequence(in);
            if (sequence == null) {
                return false;
            }
        } catch (InvalidMidiDataException e) {
            if (DEBUG || Printer.err)e.printStackTrace();
            return false;
        }

        if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
        return true;
    }
 
Example 11
Source File: Midi2WavRenderer.java    From computoser with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void midi2wav(InputStream is, OutputStream os) {
    try {
        Sequence sequence = MidiSystem.getSequence(is);
        render(sequence, os);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source File: JavaSoundAudioClip.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean createSequencer(BufferedInputStream in) throws IOException {

        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");

        // get the sequencer
        try {
            sequencer = MidiSystem.getSequencer( );
        } catch(MidiUnavailableException me) {
            if (DEBUG || Printer.err)me.printStackTrace();
            return false;
        }
        if (sequencer==null) {
            return false;
        }

        try {
            sequence = MidiSystem.getSequence(in);
            if (sequence == null) {
                return false;
            }
        } catch (InvalidMidiDataException e) {
            if (DEBUG || Printer.err)e.printStackTrace();
            return false;
        }

        if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
        return true;
    }
 
Example 13
Source File: MidiText.java    From haxademic with MIT License 5 votes vote down vote up
/**
 * args[0] should be a path to the MIDI file
 */
public static void main(String[] args) {
    Sequence midiFile = null;
    try {
        System.out.println("Reading " + args[0]);
        midiFile = MidiSystem.getSequence(new File(args[0]));
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    convertMidi2Text(midiFile);
}
 
Example 14
Source File: JavaSoundAudioClip.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean createSequencer(BufferedInputStream in) throws IOException {

        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");

        // get the sequencer
        try {
            sequencer = MidiSystem.getSequencer( );
        } catch(MidiUnavailableException me) {
            if (DEBUG || Printer.err)me.printStackTrace();
            return false;
        }
        if (sequencer==null) {
            return false;
        }

        try {
            sequence = MidiSystem.getSequence(in);
            if (sequence == null) {
                return false;
            }
        } catch (InvalidMidiDataException e) {
            if (DEBUG || Printer.err)e.printStackTrace();
            return false;
        }

        if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
        return true;
    }
 
Example 15
Source File: RealTimeSequencer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void setSequence(InputStream stream) throws IOException, InvalidMidiDataException {
    if (stream == null) {
        setSequence((Sequence) null);
        return;
    }

    Sequence seq = MidiSystem.getSequence(stream); // can throw IOException, InvalidMidiDataException

    setSequence(seq);
}
 
Example 16
Source File: MidiRealTime.java    From haxademic with MIT License 5 votes vote down vote up
/**
 * args[0] should be a path to the MIDI file
 */
public static void main(String[] args) {
    // TODO code application logic here
    try {
        System.out.println("Reading " + args[0]);
        seq = MidiSystem.getSequence(new File(args[0]));
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    convertMidi2RealTime(seq);
}
 
Example 17
Source File: JavaSoundAudioClip.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private boolean createSequencer(BufferedInputStream in) throws IOException {

        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");

        // get the sequencer
        try {
            sequencer = MidiSystem.getSequencer( );
        } catch(MidiUnavailableException me) {
            if (DEBUG || Printer.err)me.printStackTrace();
            return false;
        }
        if (sequencer==null) {
            return false;
        }

        try {
            sequence = MidiSystem.getSequence(in);
            if (sequence == null) {
                return false;
            }
        } catch (InvalidMidiDataException e) {
            if (DEBUG || Printer.err)e.printStackTrace();
            return false;
        }

        if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
        return true;
    }
 
Example 18
Source File: JavaSoundAudioClip.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private boolean createSequencer(BufferedInputStream in) throws IOException {

        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");

        // get the sequencer
        try {
            sequencer = MidiSystem.getSequencer( );
        } catch(MidiUnavailableException me) {
            if (DEBUG || Printer.err)me.printStackTrace();
            return false;
        }
        if (sequencer==null) {
            return false;
        }

        try {
            sequence = MidiSystem.getSequence(in);
            if (sequence == null) {
                return false;
            }
        } catch (InvalidMidiDataException e) {
            if (DEBUG || Printer.err)e.printStackTrace();
            return false;
        }

        if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
        return true;
    }
 
Example 19
Source File: JavaSoundAudioClip.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean createSequencer(BufferedInputStream in) throws IOException {

        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");

        // get the sequencer
        try {
            sequencer = MidiSystem.getSequencer( );
        } catch(MidiUnavailableException me) {
            if (DEBUG || Printer.err)me.printStackTrace();
            return false;
        }
        if (sequencer==null) {
            return false;
        }

        try {
            sequence = MidiSystem.getSequence(in);
            if (sequence == null) {
                return false;
            }
        } catch (InvalidMidiDataException e) {
            if (DEBUG || Printer.err)e.printStackTrace();
            return false;
        }

        if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
        return true;
    }
 
Example 20
Source File: RealTimeSequencer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void setSequence(InputStream stream) throws IOException, InvalidMidiDataException {

    if (Printer.trace) Printer.trace(">> RealTimeSequencer: setSequence(" + stream +")");

    if (stream == null) {
        setSequence((Sequence) null);
        return;
    }

    Sequence seq = MidiSystem.getSequence(stream); // can throw IOException, InvalidMidiDataException

    setSequence(seq);

    if (Printer.trace) Printer.trace("<< RealTimeSequencer: setSequence(" + stream +") completed");

}