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

The following examples show how to use javax.sound.midi.MidiSystem#getSequencer() . 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: JavaSoundActiveMediaPlayer.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
public void realize() {
  if (!useAudioBuffer) {
    try {
      if (midi) {
        if (sequencer == null)
          sequencer = MidiSystem.getSequencer();
      } else {
        if (clip != null && !clip.isOpen()) {
          clip.open();
        }
      }
    } catch (Exception e) {
      System.err.println("Error realizing media \"" + mc.mediaFileName + "\"\n" + e);
    }
  }
}
 
Example 2
Source File: LMidiSound.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
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();
	}
}
 
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 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 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: SequencerImplicitSynthOpen.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        log("getting sequencer...");
        Sequencer sequencer = MidiSystem.getSequencer();
        log("  - got " + getDeviceStr(sequencer));

        // obtain connected device (usually synthesizer)
        MidiDevice synth = getConnectedDevice(sequencer);
        if (synth == null) {
            log("could not get connected device, returning");
            return;
        }

        log("connected device: " + getDeviceStr(synth));

        int success = 0;
        for (int i=0; i<TEST_COUNT; i++) {
            if (test(sequencer)) {
                success++;
            }
        }

        if (success != TEST_COUNT) {
            throw new RuntimeException("test FAILS");
        }
    } catch (MidiUnavailableException ex) {
        // this is not a failure
        log("Could not get Sequencer");
    }
    log("test PASSED.");
}
 
Example 9
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 10
Source File: SequencerImplicitSynthOpen.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        log("getting sequencer...");
        Sequencer sequencer = MidiSystem.getSequencer();
        log("  - got " + getDeviceStr(sequencer));

        // obtain connected device (usually synthesizer)
        MidiDevice synth = getConnectedDevice(sequencer);
        if (synth == null) {
            log("could not get connected device, returning");
            return;
        }

        log("connected device: " + getDeviceStr(synth));

        int success = 0;
        for (int i=0; i<TEST_COUNT; i++) {
            if (test(sequencer)) {
                success++;
            }
        }

        if (success != TEST_COUNT) {
            throw new RuntimeException("test FAILS");
        }
    } catch (MidiUnavailableException ex) {
        // this is not a failure
        log("Could not get Sequencer");
    }
    log("test PASSED.");
}
 
Example 11
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 12
Source File: SequencerImplicitSynthOpen.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        log("getting sequencer...");
        Sequencer sequencer = MidiSystem.getSequencer();
        log("  - got " + getDeviceStr(sequencer));

        // obtain connected device (usually synthesizer)
        MidiDevice synth = getConnectedDevice(sequencer);
        if (synth == null) {
            log("could not get connected device, returning");
            return;
        }

        log("connected device: " + getDeviceStr(synth));

        int success = 0;
        for (int i=0; i<TEST_COUNT; i++) {
            if (test(sequencer)) {
                success++;
            }
        }

        if (success != TEST_COUNT) {
            throw new RuntimeException("test FAILS");
        }
    } catch (MidiUnavailableException ex) {
        // this is not a failure
        log("Could not get Sequencer");
    }
    log("test PASSED.");
}
 
Example 13
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 14
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 15
Source File: SequencerImplicitSynthOpen.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        log("getting sequencer...");
        Sequencer sequencer = MidiSystem.getSequencer();
        log("  - got " + getDeviceStr(sequencer));

        // obtain connected device (usually synthesizer)
        MidiDevice synth = getConnectedDevice(sequencer);
        if (synth == null) {
            log("could not get connected device, returning");
            return;
        }

        log("connected device: " + getDeviceStr(synth));

        int success = 0;
        for (int i=0; i<TEST_COUNT; i++) {
            if (test(sequencer)) {
                success++;
            }
        }

        if (success != TEST_COUNT) {
            throw new RuntimeException("test FAILS");
        }
    } catch (MidiUnavailableException ex) {
        // this is not a failure
        log("Could not get Sequencer");
    }
    log("test PASSED.");
}
 
Example 16
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 17
Source File: SequencerImplicitSynthOpen.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        log("getting sequencer...");
        Sequencer sequencer = MidiSystem.getSequencer();
        log("  - got " + getDeviceStr(sequencer));

        // obtain connected device (usually synthesizer)
        MidiDevice synth = getConnectedDevice(sequencer);
        if (synth == null) {
            log("could not get connected device, returning");
            return;
        }

        log("connected device: " + getDeviceStr(synth));

        int success = 0;
        for (int i=0; i<TEST_COUNT; i++) {
            if (test(sequencer)) {
                success++;
            }
        }

        if (success != TEST_COUNT) {
            throw new RuntimeException("test FAILS");
        }
    } catch (MidiUnavailableException ex) {
        // this is not a failure
        log("Could not get Sequencer");
    }
    log("test PASSED.");
}
 
Example 18
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 19
Source File: SequencerImplicitSynthOpen.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        log("getting sequencer...");
        Sequencer sequencer = MidiSystem.getSequencer();
        log("  - got " + getDeviceStr(sequencer));

        // obtain connected device (usually synthesizer)
        MidiDevice synth = getConnectedDevice(sequencer);
        if (synth == null) {
            log("could not get connected device, returning");
            return;
        }

        log("connected device: " + getDeviceStr(synth));

        int success = 0;
        for (int i=0; i<TEST_COUNT; i++) {
            if (test(sequencer)) {
                success++;
            }
        }

        if (success != TEST_COUNT) {
            throw new RuntimeException("test FAILS");
        }
    } catch (MidiUnavailableException ex) {
        // this is not a failure
        log("Could not get Sequencer");
    }
    log("test PASSED.");
}
 
Example 20
Source File: JmMidiPlayer.java    From jmg with GNU General Public License v2.0 4 votes vote down vote up
public JmMidiPlayer()  throws MidiUnavailableException {

        //System.out.println("Getting Sequencer");        
        sequencer   = MidiSystem.getSequencer();
        //System.out.println("Getting Synthesizer");        
        synthesizer = JmMidiPlayer.getSynthesizer();
        //System.out.println("Getting Transmitter");        
        transmitter = sequencer.getTransmitter();
        //System.out.println("Getting Receiver");        
        receiver    = synthesizer.getReceiver(); 
        //System.out.println("Connecting Receiver");        
        transmitter.setReceiver(receiver);      
        sequencer.open();
        if (sequencer.isOpen()) {
            //System.out.println("Sequencer is Open" );
        }
        else {
            //System.out.println("Sequencer is Not Open" );
        }                                    
        os = new ByteArrayOutputStream();
        //System.out.println("End of Midi Construction");        
        
        MidiDevice.Info synthInfo = synthesizer.getDeviceInfo();
        //System.out.println(
         //       "Synthesizer =" +  synthInfo.toString() 
        //);    
        
        MidiDevice.Info seqInfo   = sequencer.getDeviceInfo();
        //System.out.println( 
               // "Sequencer =" + seqInfo.toString() 
       // );    
        
        MidiDevice.Info[]   devsInfo 
            = MidiSystem.getMidiDeviceInfo();
        MidiDevice.Info     devInfo;
        MidiDevice          dev;
        for( int i=0; i <  devsInfo.length; ++i) {
            devInfo = devsInfo[i];            
            System.out.print(devInfo.toString());  
            try {
                dev = MidiSystem.getMidiDevice(devInfo);
                //System.out.println( " Available");  
            }
            catch(MidiUnavailableException e) {
                System.out.println( " Unavailable");  
            }                                    
        }            
        if (sequencer.isOpen()) {
            //System.out.println("Sequencer is Still Open" );
        }
        else {
           // System.out.println("Sequencer is Not Open" );
        }                                    
    }