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


Java Sequencer類代碼示例

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


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

示例1: getDefaultProvider

import javax.sound.midi.Sequencer; //導入依賴的package包/類
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:31,代碼來源:JDK13Services.java

示例2: play

import javax.sound.midi.Sequencer; //導入依賴的package包/類
public void play() {
	if (isPlaying) { // 如果已經在播放,返回
		return;
	}

	try {
		sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequencer.setSequence(sequence);
		sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY );
		sequencer.addMetaEventListener(this);
	} catch (InvalidMidiDataException ex) {
	} catch (MidiUnavailableException e) {
	}

	thread = new Thread(this);
	thread.start();
}
 
開發者ID:zhangjikai,項目名稱:LinkGame,代碼行數:19,代碼來源:BackMusic.java

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

示例4: getConnectedDevice

import javax.sound.midi.Sequencer; //導入依賴的package包/類
static MidiDevice getConnectedDevice(Sequencer sequencer) {
    List<Transmitter> trans = sequencer.getTransmitters();
    log("  sequencer has " + trans.size() + " opened transmitters:");
    for (Transmitter tr: trans) {
        Receiver r = tr.getReceiver();
        log("    " + getClassStr(tr) + " connected to " + getClassStr(r));
        if (r instanceof MidiDeviceReceiver) {
            MidiDeviceReceiver recv = (MidiDeviceReceiver)r;
            MidiDevice dev = recv.getMidiDevice();
            log("      - receiver of " + getClassStr(dev));
            return dev;
        } else {
            log("      - does NOT implement MidiDeviceReceiver");
        }
    }
    return null;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:SequencerImplicitSynthOpen.java

示例5: getDefaultProvider

import javax.sound.midi.Sequencer; //導入依賴的package包/類
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class<?> typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:JDK13Services.java

示例6: doTest

import javax.sound.midi.Sequencer; //導入依賴的package包/類
public static void doTest(Sequencer seq) throws Exception {
    seq.setTempoInMPQ(3.0f);
    System.out.println("Setting tempo in MPQ to "+3.0f);
    if (!equalsFloat(seq.getTempoInMPQ(), 3.0f)) {
        System.err.println("getTempoInMPQ() returns wrong value : "
            + seq.getTempoInMPQ());
        failed = true;
    }

    System.out.println("Setting tempo factor to "+2.0f);
    seq.setTempoFactor(2.0f);
    if (!equalsFloat(seq.getTempoFactor(), 2.0f)) {
        System.err.println("getTempoFactor() returns: " + seq.getTempoFactor());
        failed = true;
    }

    float bpmTempo = 120.0f;
    System.out.println("Setting tempo to "+120.0f+"bpm");
    seq.setTempoInBPM(bpmTempo);
    if (!equalsFloat(seq.getTempoInMPQ(), (60000000.0f/seq.getTempoInBPM()))) {
        System.err.println("getTempoInMPQ() returns: " + seq.getTempoInMPQ());
        System.err.println("getTempoInBPM() returns: " + seq.getTempoInBPM());
        failed = true;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:SequencerCacheValues.java

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

示例8: isMidiInstalled

import javax.sound.midi.Sequencer; //導入依賴的package包/類
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
public static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:OpenClose.java

示例9: isMidiInstalled

import javax.sound.midi.Sequencer; //導入依賴的package包/類
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
private static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = !(device instanceof Sequencer)
                    && !(device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ClosedReceiver.java

示例10: doAll

import javax.sound.midi.Sequencer; //導入依賴的package包/類
private static void doAll() throws Exception {
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    for (int i=0; i < infos.length; i++) {
        MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
        if ((! (device instanceof Sequencer)) &&
            (! (device instanceof Synthesizer)) &&
            (device.getMaxReceivers() > 0 || device.getMaxReceivers() == -1)) {

            System.out.println("--------------");
            System.out.println("Testing MIDI device: " + infos[i]);
            testDevice(device);
        }
        if (infos.length==0) {
            System.out.println("No MIDI devices available!");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:MidiOutGetMicrosecondPositionBug.java

示例11: isMidiInstalled

import javax.sound.midi.Sequencer; //導入依賴的package包/類
/**
 * Returns true if at least one MIDI (port) device is correctly installed on
 * the system.
 */
public static boolean isMidiInstalled() {
    boolean result = false;
    MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
    for (int i = 0; i < devices.length; i++) {
        try {
            MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
            result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
        } catch (Exception e1) {
            System.err.println(e1);
        }
        if (result)
            break;
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:MidiOutGetMicrosecondPositionBug.java

示例12: getDevice

import javax.sound.midi.Sequencer; //導入依賴的package包/類
public static MidiDevice getDevice(String inDeviceName) throws MiException
{
MidiDevice.Info[]	infos = MidiSystem.getMidiDeviceInfo();

for(int i = 0; i < infos.length; i++)
	{
	if(infos[i].getName().equals(inDeviceName))
		{
		try {
			MidiDevice device = MidiSystem.getMidiDevice(infos[i]);

			if(	device.getMaxTransmitters() == 0 ||
				device instanceof Sequencer)
				continue;

			return(device);
			}
		catch(MidiUnavailableException mue)
			{
			throw new MiException(TuxGuitar.getProperty("midiinput.error.midi.unavailable"), mue);
			}
		}
	}

return(null);
}
 
開發者ID:theokyr,項目名稱:TuxGuitar-1.3.1-fork,代碼行數:27,代碼來源:MiPortProvider.java

示例13: DesktopMidiPlayer

import javax.sound.midi.Sequencer; //導入依賴的package包/類
public DesktopMidiPlayer() throws MidiUnavailableException, IOException, InvalidMidiDataException {
	// 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();
	// create a stream from a file
	// FileHandle fh = Gdx.files.internal(Constants.MUSIC);
	// InputStream is = new BufferedInputStream(new FileInputStream(fh.file()));
	InputStream is = new BufferedInputStream(new FileInputStream(new File(Constants.MUSIC2)));
	// 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();
	/*try {
		this.sequencer = MidiSystem.getSequencer();
	} catch (MidiUnavailableException e) {
		// Log.error("Error opening midi device.", e);
	}*/

}
 
開發者ID:TheElk205,項目名稱:KillTheNerd,代碼行數:23,代碼來源:DesktopMidiPlayer.java

示例14: go

import javax.sound.midi.Sequencer; //導入依賴的package包/類
public void go() {
	setUpGui();

	try {
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequencer.addControllerEventListener(ml, new int[] {127});
		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		int r = 0;
		for (int i = 0; i < 60; i+=4) {
			r = (int) ((Math.random() * 50) + 1);
			track.add(makeEvent(144, 1, r, 100, i));
			track.add(makeEvent(176, 1, 127, 0, i));
			track.add(makeEvent(128, 1, r, 100, i + 2));
		} // end loop

		sequencer.setSequence(seq);
		sequencer.start();
		sequencer.setTempoInBPM(120);
	} catch (Exception ex) {ex.printStackTrace();}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:24,代碼來源:MiniMusicPlayer3.java

示例15: go

import javax.sound.midi.Sequencer; //導入依賴的package包/類
public void go() {
	try {
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();

		int[] eventsIWant = {127};
		sequencer.addControllerEventListener(this, eventsIWant);

		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		for (int i = 5; i < 60; i+= 4) {
			track.add(makeEvent(144, 1, i, 100, i));

			track.add(makeEvent(176, 1, 127, 0, i));

			track.add(makeEvent(128, 1, i, 100, i + 2));
		} // end loop

		sequencer.setSequence(seq);
		sequencer.setTempoInBPM(220);
		sequencer.start();
	} catch (Exception ex) {ex.printStackTrace();}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:25,代碼來源:MiniMusicPlayer2.java


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