本文整理汇总了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;
}
}
示例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();}
}
示例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();}
}
示例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();}
}
示例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.");
}