本文整理汇总了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);
}