Class MidiUtils

java.lang.Object
org.jjazz.midi.api.sequencer.MidiUtils

public final class MidiUtils extends Object
Some utilities for MIDI (some stuff is used from javax.sound.midi)
Author:
Florian Bomers
  • Field Details

  • Method Details

    • checkSysexStatus

      public static void checkSysexStatus(byte[] data, int length) throws InvalidMidiDataException
      Checks the status byte for the system exclusive message.
      Parameters:
      data - the system exclusive message data
      length - the length of the valid message data in the array
      Throws:
      InvalidMidiDataException - if the status byte is invalid for a system exclusive message
    • checkSysexStatus

      public static void checkSysexStatus(int status) throws InvalidMidiDataException
      Checks the status byte for the system exclusive message.
      Parameters:
      status - the status byte for the message (0xF0 or 0xF7)
      Throws:
      InvalidMidiDataException - if the status byte is invalid for a system exclusive message
    • isMetaEndOfTrack

      public static boolean isMetaEndOfTrack(MidiMessage midiMsg)
      return true if the passed message is Meta End Of Track
    • isMetaTempo

      public static boolean isMetaTempo(MidiMessage midiMsg)
      return if the given message is a meta tempo message
    • getTempoMPQ

      public static int getTempoMPQ(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(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(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(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