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


Java Sequencer.setTempoInBPM方法代碼示例

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


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

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

示例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[] 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.setTempoInBPM方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。