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


Java Sequencer.setSequence方法代碼示例

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


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

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

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

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

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

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

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

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

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

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

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

示例11: run

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
@Override
public void run() {
	try {
		Sequence song1 = MidiSystem.getSequence(File);
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequencer.setSequence(song1);
		sequencer.start();
		sequencer.setLoopCount(LOOP_FOREVER);
	} catch (IOException  |InvalidMidiDataException |MidiUnavailableException exep  ) {
	}
}
 
開發者ID:ProfAmesBC,項目名稱:Game2013,代碼行數:13,代碼來源:MusicPlayer.java

示例12: getSequencer

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
/**
	 * Returns a {@link Sequencer} to play a {@link Sequence}.
	 *
	 * @param sequence for {@link Sequencer}
	 * @return MIDI {@link Sequencer}
	 * @throws MidiUnavailableException
	 * @throws InvalidMidiDataException
	 * @see Sequence
	 * @see Sequencer
	 * @since 0.0.1
	 */
	public static Sequencer getSequencer(final Sequence sequence) throws MidiUnavailableException, InvalidMidiDataException { //$JUnit$
		if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(sequence));
		if (null == sequence) {
			throw new RuntimeExceptionIsNull("sequence"); //$NON-NLS-1$
		}

		final Sequencer result = MidiSystem.getSequencer();  // Used to play sequences
		result.open(); // Turn it on.

		// Get a Synthesizer for the Sequencer to send notes to
//		try (Synthesizer synth = MidiSystem.getSynthesizer()) {
			final Synthesizer synth = MidiSystem.getSynthesizer();
			synth.open();  // acquire whatever resources it needs
	
			// The Sequencer obtained above may be connected to a Synthesizer
			// by default, or it may not.  Therefore, we explicitly connect it.
//			try (Transmitter transmitter = result.getTransmitter()) {
				final Transmitter transmitter = result.getTransmitter();
				transmitter.setReceiver(synth.getReceiver());
//			}
//		}
		// Read the sequence from the file and tell the sequencer about it
		result.setSequence(sequence);

		if (log.isDebugEnabled()) log.debug(HelperLog.methodExit(result));
		return result;
	}
 
開發者ID:slaubenberger,項目名稱:wichtel,代碼行數:39,代碼來源:HelperSound.java

示例13: MidiPlayer

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
public MidiPlayer(File midiFile) {

		// Play once
		try {
			Sequencer sequencer = MidiSystem.getSequencer();
			sequencer.setSequence(MidiSystem.getSequence(midiFile));
			sequencer.open();
			sequencer.start();
			/*
			 while(true) {
			 if(sequencer.isRunning()) {
			 try {
			 Thread.sleep(1000); // Check every second
			 } catch(InterruptedException ignore) {
			 break;
			 }
			 } else {
			 break;
			 }
			 }
			 // Close the MidiDevice & free resources
			 sequencer.stop();
			 sequencer.close();
			 */
		} catch (MidiUnavailableException mue) {
			log.error("Midi device unavailable!", mue);
		} catch (InvalidMidiDataException imde) {
			log.error("Invalid Midi data!", imde);
		} catch (IOException ioe) {
			log.error("I/O Error!", ioe);
		}

	}
 
開發者ID:cwpenhale,項目名稱:red5-mobileconsole,代碼行數:34,代碼來源:MidiPlayer.java

示例14: main

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:61,代碼來源:SeqRecordDoesNotCopy.java

示例15: main

import javax.sound.midi.Sequencer; //導入方法依賴的package包/類
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.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:46,代碼來源:LoopIAE.java


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