Class BeatGrid


  • public class BeatGrid
    extends Object
    Provides information about each beat in a track: the number of milliseconds after the start of the track that the beat occurs, and where the beat falls within a measure.
    Author:
    James Elliott
    • Field Detail

      • dataReference

        public final DataReference dataReference
        The unique identifier that was used to request this beat grid.
      • beatCount

        public final int beatCount
        The number of beats in the track.
    • Constructor Detail

      • BeatGrid

        public BeatGrid​(DataReference reference,
                        Message message)
        Constructor for when reading from the network.
        Parameters:
        reference - the unique database reference that was used to request this waveform detail
        message - the response that contained the beat grid data
      • BeatGrid

        public BeatGrid​(DataReference reference,
                        ByteBuffer buffer)
        Constructor for reading from a file.
        Parameters:
        reference - the unique database reference that was used to request this waveform detail
        buffer - the raw bytes representing the beat grid
      • BeatGrid

        public BeatGrid​(DataReference reference,
                        RekordboxAnlz anlzFile)
        Constructor for when fetched from Crate Digger.
        Parameters:
        reference - the unique database reference that was used to request this waveform detail
        anlzFile - the parsed rekordbox track analysis file containing the waveform preview
      • BeatGrid

        public BeatGrid​(DataReference reference,
                        int[] beatWithinBarValues,
                        int[] bpmValues,
                        long[] timeWithinTrackValues)
        Constructor for use by an external storage system.
        Parameters:
        reference - the unique database reference that was used to request this waveform detail
        beatWithinBarValues - the musical time on which each beat in the grid falls
        bpmValues - the tempo of the track at each beat, as beats per minute multiplied by 100
        timeWithinTrackValues - the time, in milliseconds, at which each beat occurs in the track
    • Method Detail

      • getRawData

        public ByteBuffer getRawData()
        Get the raw bytes of the beat grid as it was read over the network. This can be used to analyze fields that have not yet been reliably understood, and is also used for storing the beat grid in a file. This is not available when the beat grid was loaded by Crate Digger.
        Returns:
        the bytes that make up the beat grid
      • getTimeWithinTrack

        public long getTimeWithinTrack​(int beatNumber)
        Returns the time at which the specified beat falls within the track. Beat 0 means we are before the first beat (e.g. ready to play the track), so we return 0.
        Parameters:
        beatNumber - the beat number desired, must fall within the range 1..beatCount
        Returns:
        the number of milliseconds into the track at which the specified beat occurs
        Throws:
        IllegalArgumentException - if number is less than 0 or greater than beatCount
      • getBeatWithinBar

        public int getBeatWithinBar​(int beatNumber)
        Returns the musical count of the specified beat, represented by Bb in the Packet Analysis document. A number from 1 to 4, where 1 is the downbeat, or the start of a new measure.
        Parameters:
        beatNumber - the number of the beat of interest, must fall within the range 1..beatCount
        Returns:
        where that beat falls in a bar of music
        Throws:
        IllegalArgumentException - if number is less than 1 or greater than beatCount
      • getBpm

        public int getBpm​(int beatNumber)
        Get the track BPM at the time of a beat. This is an integer representing the BPM times 100, so a track running at 120.5 BPM would be represented by the value 12050.
        Parameters:
        beatNumber - the beat number desired, must fall within the range 1..beatCount
        Returns:
        the track BPM at the specified beat number to two decimal places multiplied by 100
      • getBarNumber

        public int getBarNumber​(int beatNumber)
        Return the bar number within which the specified beat falls. Like beats, bars are numbered starting at 1. Handles the case where the first bar is incomplete (the first beat is not a downbeat); like rekordbox, in such cases bar 1 is the fist complete bar, and the preceding bar is bar -1.
        Parameters:
        beatNumber - the beat number whose bar number is desired
        Returns:
        the bar within which the specified beat falls
      • findBeatAtTime

        public int findBeatAtTime​(long milliseconds)
        Finds the beat in which the specified track position falls.
        Parameters:
        milliseconds - how long the track has been playing
        Returns:
        the beat number represented by that time, or -1 if the time is before the first beat