本文整理匯總了Java中javax.sound.midi.Sequence.getMicrosecondLength方法的典型用法代碼示例。如果您正苦於以下問題:Java Sequence.getMicrosecondLength方法的具體用法?Java Sequence.getMicrosecondLength怎麽用?Java Sequence.getMicrosecondLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.midi.Sequence
的用法示例。
在下文中一共展示了Sequence.getMicrosecondLength方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAudioFileFormat
import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public AudioFileFormat getAudioFileFormat(Sequence seq)
throws UnsupportedAudioFileException, IOException {
long totallen = seq.getMicrosecondLength() / 1000000;
long len = (long) (format.getFrameRate() * (totallen + 4));
return new AudioFileFormat(MIDI, format, (int) len);
}
示例2: writeToTrack
import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/**
* Loads and adds the effects to the given midi track
*
* @param track The track to write to
* @param channel The channel to write to
*/
@Override
public void writeToTrack(Track track, int channel) {
long lastEnd = 0;
for (String name : effects.keySet()) {
Sequence sequence = FileUtils.LoadMidiFile("effects/" + name + ".mid");
if (sequence != null) {
int start =// Position effect in track
(int) (QUARTER * tempo.averageBpm / 60.0 * //beats per second
15 * //because 15 seconds
effects.get(name) //i-th word in text
);
if (start < lastEnd)
start = (int) lastEnd;
if (sequence.getMicrosecondLength() / 1000000.0 + TicksInSecs(start, tempo.resolution) > 15.0) {
start -= SecsInTicks(TicksInSecs(start, tempo.resolution) + sequence.getMicrosecondLength() / 1000000.0 - 15, tempo.resolution);
}
float scale = tempo.resolution / (float) sequence.getResolution(); // Make the tempo fit
for (Track t : sequence.getTracks()) {
for (int i = 0; i < t.size(); i++) {
MidiEvent event = t.get(i);
byte[] data = event.getMessage().getMessage();//(command & 0xF0) | (channel & 0x0F)
data[0] += 2; // Keep channel 1 and 2 free
long tick = (long) (event.getTick() * scale) + start;
MidiEvent ev = new MidiEvent(new MidiMessage(data) {
@Override
public Object clone() {
return null;
}
}, tick);
track.add(ev);
if (tick > lastEnd)
lastEnd = tick;
}
}
}
}
}
示例3: main
import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Sequence s = null;
//File midiFile = new File("outsmpte.mid");
//InputStream is = new FileInputStream(midiFile);
//is = new BufferedInputStream(is);
InputStream is = new ByteArrayInputStream(smptemidifile);
s = MidiSystem.getSequence(is);
long duration = s.getMicrosecondLength() / 1000000;
System.out.println("Duration: "+duration+" seconds ");
if (duration > 14) {
throw new Exception("SMPTE time reader is broken! Test FAILED");
}
System.out.println("Test passed");
}
示例4: main
import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
InputStream is = new ByteArrayInputStream(midifile);
// create a buffered input stream that seems
// to be on an unfortunate boundary for the
// 1.4.2 SMF parser implementation
is = new ChunkInputStream(is, 32);
Sequence sequence = MidiSystem.getSequence(is);
long duration = sequence.getMicrosecondLength() / 10000;
System.out.println("Duration: "+duration+" deciseconds ");
// the test is passed if no exception thrown
System.out.println("Test passed");
}
示例5: getAudioFileFormat
import javax.sound.midi.Sequence; //導入方法依賴的package包/類
private static StandardFileFormat getAudioFileFormat(final Sequence seq) {
long totallen = seq.getMicrosecondLength() / 1000000;
long len = (long) (format.getFrameRate() * (totallen + 4));
return new StandardFileFormat(MIDI, format, len);
}