uk.org.toot.midi.sequencer
Class MidiUtils

java.lang.Object
  extended by uk.org.toot.midi.sequencer.MidiUtils

public class MidiUtils
extends java.lang.Object

Some utilities for MIDI (some stuff is used from javax.sound.midi)

Version:
1.11, 07/08/03
Author:
Florian Bomers

Nested Class Summary
static class MidiUtils.TempoCache
           
 
Field Summary
static int DEFAULT_TEMPO_MPQ
           
static int META_END_OF_TRACK_TYPE
           
static int META_TEMPO_TYPE
           
 
Constructor Summary
MidiUtils()
           
 
Method Summary
static double convertTempo(double tempo)
          converts
1 - MPQ-Tempo to BPM tempo
2 - BPM tempo to MPQ tempo
static int getTempoMPQ(javax.sound.midi.MidiMessage midiMsg)
          parses this message for a META tempo message and returns the tempo in MPQ, or -1 if this isn't a tempo message
static boolean isMetaEndOfTrack(javax.sound.midi.MidiMessage midiMsg)
          return true if the passed message is Meta End Of Track
static boolean isMetaTempo(javax.sound.midi.MidiMessage midiMsg)
          return if the given message is a meta tempo message
static long microsec2ticks(long us, double tempoMPQ, int resolution)
          convert tempo to microsecond with given tempo Does not take tempo changes into account.
static long microsecond2tick(javax.sound.midi.Sequence seq, long micros, MidiUtils.TempoCache cache)
          Given a microsecond time, convert to tick.
static int tick2index(javax.sound.midi.Track track, long tick)
          Binary search for the event indexes of the track
static long tick2microsecond(javax.sound.midi.Sequence seq, long tick, MidiUtils.TempoCache cache)
          Given a tick, convert to microsecond
static long ticks2microsec(long tick, double tempoMPQ, int resolution)
          convert tick to microsecond with given tempo.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TEMPO_MPQ

public static final int DEFAULT_TEMPO_MPQ
See Also:
Constant Field Values

META_END_OF_TRACK_TYPE

public static final int META_END_OF_TRACK_TYPE
See Also:
Constant Field Values

META_TEMPO_TYPE

public static final int META_TEMPO_TYPE
See Also:
Constant Field Values
Constructor Detail

MidiUtils

public MidiUtils()
Method Detail

isMetaEndOfTrack

public static boolean isMetaEndOfTrack(javax.sound.midi.MidiMessage midiMsg)
return true if the passed message is Meta End Of Track


isMetaTempo

public static boolean isMetaTempo(javax.sound.midi.MidiMessage midiMsg)
return if the given message is a meta tempo message


getTempoMPQ

public static int getTempoMPQ(javax.sound.midi.MidiMessage midiMsg)
parses this message for a META tempo message and returns the tempo in MPQ, or -1 if this isn't a tempo message


convertTempo

public static double convertTempo(double tempo)
converts
1 - MPQ-Tempo to BPM tempo
2 - BPM tempo to MPQ tempo


ticks2microsec

public static long ticks2microsec(long tick,
                                  double tempoMPQ,
                                  int resolution)
convert tick to microsecond with given tempo. Does not take tempo changes into account. Does not work for SMPTE timing!


microsec2ticks

public static long microsec2ticks(long us,
                                  double tempoMPQ,
                                  int resolution)
convert tempo to microsecond with given tempo Does not take tempo changes into account. Does not work for SMPTE timing!


tick2microsecond

public static long tick2microsecond(javax.sound.midi.Sequence seq,
                                    long tick,
                                    MidiUtils.TempoCache cache)
Given a tick, convert to microsecond

Parameters:
cache - tempo info and current tempo

microsecond2tick

public static long microsecond2tick(javax.sound.midi.Sequence seq,
                                    long micros,
                                    MidiUtils.TempoCache cache)
Given a microsecond time, convert to tick. returns tempo at the given time in cache.getCurrTempoMPQ


tick2index

public static int tick2index(javax.sound.midi.Track track,
                             long tick)
Binary search for the event indexes of the track

Parameters:
tick - - tick number of index to be found in array
Returns:
index in track which is on or after "tick". if no entries are found that follow after tick, track.size() is returned


Copyright © 2004, 2005, 2006, 2007 Steve Taylor. All Rights Reserved.