本文整理汇总了Java中javax.sound.midi.Sequence.PPQ属性的典型用法代码示例。如果您正苦于以下问题:Java Sequence.PPQ属性的具体用法?Java Sequence.PPQ怎么用?Java Sequence.PPQ使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.sound.midi.Sequence
的用法示例。
在下文中一共展示了Sequence.PPQ属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupMidi
public void setupMidi() throws Exception {
synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
midiChannels = synthesizer.getChannels();
sequencer = MidiSystem.getSequencer();
sequence = new Sequence(Sequence.PPQ, 10);
Soundbank sb = synthesizer.getDefaultSoundbank();
if (sb != null) {
instruments = synthesizer.getDefaultSoundbank().getInstruments();
for (int i = 0; i < instruments.length; i++) {
System.out.printf("%4d: %s%n", i, instruments[i]);
}
if (instruments.length > 0) {
synthesizer.loadInstrument(instruments[0]);
midiChannels[currentChannel].programChange(0);
}
if (instruments.length > 14) {
synthesizer.loadInstrument(instruments[14]);
midiChannels[currentChannel].programChange(14);
}
}
}
示例2: createSequence
/**
* Creates a sequence based on the resolution defined in ticksPerQuarterNote
*
*/
public void createSequence() {
if (sequence == null) {
try {
if (ticksPerQuarterNote == 0) {
ticksPerQuarterNote = FrinikaConfig.TICKS_PER_QUARTER;
}
sequence = new FrinikaSequence(Sequence.PPQ,
ticksPerQuarterNote, 1);
sequencer.setSequence(sequence);
} catch (InvalidMidiDataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
示例3: main
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();}
}
示例4: go
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();}
}
示例5: millis2tick
private long millis2tick(long millis) {
if (divisionType != Sequence.PPQ) {
double dTick = ((((double) millis) * tempoFactor)
* ((double) divisionType)
* ((double) resolution))
/ ((double) 1000);
return (long) dTick;
}
return MidiUtils.microsec2ticks(millis * 1000,
currTempo * inverseTempoFactor,
resolution);
}
示例6: tick2millis
private long tick2millis(long tick) {
if (divisionType != Sequence.PPQ) {
double dMillis = ((((double) tick) * 1000) /
(tempoFactor * ((double) divisionType) * ((double) resolution)));
return (long) dMillis;
}
return MidiUtils.ticks2microsec(tick,
currTempo * inverseTempoFactor,
resolution) / 1000;
}
示例7: main
public static void main(String argv[]) throws Exception {
Sequence seq = new Sequence(Sequence.PPQ, 240);
Track t = seq.createTrack();
log("add 10 events in random order");
t.add(createEvent(10, 5));
t.add(createEvent(0, 0));
t.add(createEvent(10, 6));
t.add(createEvent(11, 8));
t.add(createEvent(10, 7));
t.add(createEvent(0, 1));
t.add(createEvent(0, 2));
t.add(createEvent(15, 9));
t.add(createEvent(0, 3));
t.add(createEvent(1, 4));
// now compare the events.
// The note param will tell us the
// the expected position
long lastTick = 0;
for (int i = 0; i < t.size(); i++) {
MidiEvent ev = t.get(i);
if (ev.getMessage() instanceof ShortMessage) {
ShortMessage msg = (ShortMessage) ev.getMessage();
log(""+i+": ShortMessage at tick "+ev.getTick()
+" with expected position "+msg.getData1());
if (ev.getTick() < lastTick) {
log(" FAILED: last tick is larger than this event's tick!");
failed = true;
}
if (i != msg.getData1()) {
log(" FAILED: Track did not order correctly.");
failed = true;
}
}
}
if (failed) throw new Exception("Test FAILED!");
log("Test passed.");
}
示例8: MetaCallback
MetaCallback() throws Exception {
sequencer=MidiSystem.getSequencer();
sequence=new Sequence(Sequence.PPQ,240);
track=sequence.createTrack();
sequencer.addMetaEventListener(this);
byte[] data = new byte[1];
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));
int c;
for(c=0; c < TOTAL_COUNT; c++) {
data[0]=(byte)(c+1);
MetaMessage meta = new MetaMessage();
meta.setMessage(1, data, 1); // type, data, length
track.add(new MidiEvent(meta,c*20));
}
track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,100),c*20));
track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,0),c*20 + 10));
sequencer.setSlaveSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
sequencer.setMasterSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
sequencer.open();
sequencer.setSequence(sequence);
sequencer.setTempoInBPM(100);
System.out.println("Starting playback...");
this.start();
while (!finished && sequencer.getTickPosition() < sequencer.getTickLength()) {
System.out.println("Tick "+sequencer.getTickPosition()+"...");
Thread.sleep(1000);
}
System.out.println("Stopping playback...");
this.stop();
if (metaCount != TOTAL_COUNT) {
throw new Exception("Expected "+TOTAL_COUNT+" callbacks, but got "+metaCount+"!");
}
}
示例9: init
private void init(){
try {
this.sequence = new Sequence(Sequence.PPQ,(int)TGDuration.QUARTER_TIME);
this.midiTracks = new Track[getTracks()];
for (int i = 0; i < this.midiTracks.length; i++) {
this.midiTracks[i] = this.sequence.createTrack();
}
} catch (InvalidMidiDataException e) {
e.printStackTrace();
}
}
示例10: MidiSequenceBuilder
public MidiSequenceBuilder(final int ppq) {
try {
sequence = new Sequence(Sequence.PPQ, ppq);
} catch (InvalidMidiDataException e) {
e.printStackTrace();
}
}
示例11: MidiWriter
/**
* Create a new MidiWriter to write out to the given File.
*
* @param outFile {@link #outFile}
* @param tt {@link #timeTracker}
*
* @throws InvalidMidiDataException If somehow the TimeTracker has an invalid PPQ value.
*/
public MidiWriter(File outFile, TimeTracker tt) throws InvalidMidiDataException {
this.outFile = outFile;
timeTracker = tt;
sequence = new Sequence(Sequence.PPQ, (int) timeTracker.getPPQ());
sequence.createTrack();
writeTimeTracker();
}
示例12: ChangeResolution
/**
* Change resolution (TPQN) and retiming events.
* @param seq Sequence to be processed.
* @param resolution Ticks per quarter note of new sequence.
* @return New sequence with new resolution.
* @throws InvalidMidiDataException throw if MIDI data is invalid.
*/
public static Sequence ChangeResolution(Sequence sourceSeq, int resolution) throws InvalidMidiDataException
{
// sequence must be tick-based
if (sourceSeq.getDivisionType() != Sequence.PPQ)
{
throw new UnsupportedOperationException("SMPTE is not supported.");
}
Sequence seq = new Sequence(sourceSeq.getDivisionType(), resolution);
// process all input tracks
for (int trackIndex = 0; trackIndex < sourceSeq.getTracks().length; trackIndex++)
{
Track sourceTrack = sourceSeq.getTracks()[trackIndex];
Track track = seq.createTrack();
// process all events
double timingRate = (double) resolution / sourceSeq.getResolution();
for (int eventIndex = 0; eventIndex < sourceTrack.size(); eventIndex++)
{
MidiEvent sourceEvent = sourceTrack.get(eventIndex);
MidiEvent event = new MidiEvent(sourceEvent.getMessage(), Math.round(sourceEvent.getTick() * timingRate));
track.add(event);
}
}
// if the target resolution is shorter than source resolution,
// events at different timing might be located at the same timing.
// As a result, there might be zero-length note and/or
// same control changes at the same timing.
//
// Probably, they should be removed for better conversion.
// I do not remove them anyway at the moment,
// because it does not cause any major problems.
return seq;
}
示例13: tickToMicros
@Override public long tickToMicros(long tick)
{
if (divisionType != Sequence.PPQ)
return (long) (TimingInfo.ONE_SECOND_MICROS * ((double) tick / (double) (divisionType * tickResolution)));
TempoEvent te = getTempoEventForTick(tick);
return te.micros + MidiUtils.ticks2microsec(tick - te.tick, te.tempoMPQ, tickResolution);
}
示例14: createFastPrototypes
/**
* A hack to get a real FastShortMessage that can be cloned, e.g. Prototype
*/
private static void createFastPrototypes() {
try {
// create a sequence with a ShortMessage
Sequence sequence = new Sequence(Sequence.PPQ, 10);
Track track = sequence.createTrack();
track.add(new MidiEvent(new ShortMessage(), 0l));
// save the sequence
try {
File file = File.createTempFile("FSMhack", "mid");
MidiSystem.write(sequence, 0, file);
// load the sequence and get back the FastShortMessage
sequence = MidiSystem.getSequence(file);
track = sequence.getTracks()[0];
MidiMessage msg = null;
for ( int i = 0; i < track.size(); i++ ) {
msg = track.get(i).getMessage();
Class clazz = msg.getClass();
if ( fastShortPrototype == null &&
clazz.getCanonicalName().equals("com.sun.media.sound.FastShortMessage") ) {
fastShortPrototype = msg;
}
}
file.delete();
} catch ( IOException ioe ) {
}
} catch ( InvalidMidiDataException imde ) {
}
}
示例15: play
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();}
}