当前位置: 首页>>代码示例>>Java>>正文


Java Sequencer.open方法代码示例

本文整理汇总了Java中javax.sound.midi.Sequencer.open方法的典型用法代码示例。如果您正苦于以下问题:Java Sequencer.open方法的具体用法?Java Sequencer.open怎么用?Java Sequencer.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.midi.Sequencer的用法示例。


在下文中一共展示了Sequencer.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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

示例6: main

import javax.sound.midi.Sequencer; //导入方法依赖的package包/类
public static void main(String[] args) {
	try {
		// make and open a sequencer
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();

		// make a sequence and a track
		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		// make a bunch of events to make the notes keep going up
		// (from piano note 5 to piano note 61)
		for (int i = 5; i < 61; i+=4) {
			track.add(makeEvent(144, 1, i, 100, 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,代码行数:23,代码来源:MiniMusicPlayer1.java

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

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

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

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

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

示例12: playAudio

import javax.sound.midi.Sequencer; //导入方法依赖的package包/类
/**
 * Plays the audio of the current song.
 * 
 * @throws MidiUnavailableException
 * @throws InvalidMidiDataException
 */
public void playAudio() throws MidiUnavailableException, InvalidMidiDataException {
	Sequencer player = MidiSystem.getSequencer();
    
	player.open();
	player.setSequence(song);
	player.start();
}
 
开发者ID:apmcleod,项目名称:voice-splitting,代码行数:14,代码来源:EventParser.java

示例13: play

import javax.sound.midi.Sequencer; //导入方法依赖的package包/类
public void play(int instrument, int note) {
	try {
		Sequencer player = MidiSystem.getSequencer();
		player.open();
		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		MidiEvent event = null;

		ShortMessage first = new ShortMessage();
		first.setMessage(192, 1, instrument, 0);
		MidiEvent changeInstrument = new MidiEvent(first, 1);
		track.add(changeInstrument);

		ShortMessage a = new ShortMessage();
		a.setMessage(144, 1, note, 100);
		MidiEvent noteOn = new MidiEvent(a, 1);
		track.add(noteOn);

		ShortMessage b = new ShortMessage();
		b.setMessage(128, 1, note, 100);
		MidiEvent noteOff = new MidiEvent(b, 16);
		track.add(noteOff);
		player.setSequence(seq);
		player.start();
	} catch (Exception ex) {ex.printStackTrace();}
}
 
开发者ID:miguelalba-old,项目名称:Head-First-Java,代码行数:28,代码来源:MiniMusicCmdLine.java

示例14: play

import javax.sound.midi.Sequencer; //导入方法依赖的package包/类
public void play() {
	try {
		// Get a sequencer and open it
		Sequencer player = MidiSystem.getSequencer();
		player.open();

		// Set up sequence
		Sequence seq = new Sequence(Sequence.PPQ, 4);

		// Ask the sequence for a Track
		Track track = seq.createTrack();

		// Put some MidiEvents into the Track
		ShortMessage a = new ShortMessage();
		a.setMessage(144, 1, 44, 100);
		MidiEvent noteOn = new MidiEvent(a, 1);
		track.add(noteOn);

		ShortMessage b = new ShortMessage();
		b.setMessage(128, 1, 44, 100);
		MidiEvent noteOff = new MidiEvent(b, 16);
		track.add(noteOff);

		// Give the sequence to the sequencer
		player.setSequence(seq);

		// Start() the sequencer
		player.start();

	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:miguelalba-old,项目名称:Head-First-Java,代码行数:34,代码来源:MiniMiniMusicApp.java

示例15: loadMidi

import javax.sound.midi.Sequencer; //导入方法依赖的package包/类
private static void loadMidi(String path) {
	try {
		Sequence sequence = MidiSystem.getSequence(SoundManager.class.getResourceAsStream(path));
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequencer.setSequence(sequence);

		Log.debug("Load Midi: " + path);
		midis.put(path, sequencer);
	} catch (Exception e) {
		Log.error("Can not load clip: " + path);
		e.printStackTrace();
	}
}
 
开发者ID:AppleJuiceStudios,项目名称:DoubleYou,代码行数:15,代码来源:ResourceManager.java


注:本文中的javax.sound.midi.Sequencer.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。