Class WaveformDetail


  • public class WaveformDetail
    extends Object
    Gives a detail view of the audio content of a track, and offers a Swing component for rendering that view as part of a user interface, along with annotations showing the current playback position, beats, and cue points, if the appropriate metadata is available.
    Author:
    James Elliott
    • Field Detail

      • LEADING_DBSERVER_JUNK_BYTES

        public static final int LEADING_DBSERVER_JUNK_BYTES
        The number of bytes at the start of the waveform data which do not seem to be valid or used when it is served by the dbserver protocol. They are not present when the ANLZ.EXT file is loaded directly by Crate Digger.
        See Also:
        Constant Field Values
      • LEADING_DBSERVER_COLOR_JUNK_BYTES

        public static final int LEADING_DBSERVER_COLOR_JUNK_BYTES
        The number of bytes at the start of the color waveform data to be skipped when that was loaded using the nxs2 ANLZ tag request. We actually know what these mean, now that we know how to parse EXT files, but we can simply skip them anyway.
        See Also:
        Constant Field Values
      • dataReference

        public final DataReference dataReference
        The unique identifier that was used to request this waveform detail.
      • rawMessage

        public final Message rawMessage
        The message holding the detail 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 cue list in a file. This will be null if the data was obtained from Crate Digger.
      • isColor

        public final boolean isColor
        Indicates whether this is an NXS2-style color waveform, or a monochrome (blue) waveform.
      • COLOR_MAP

        public static final Color[] COLOR_MAP
        The different colors the monochrome (blue) waveform can be based on its intensity.
    • Constructor Detail

      • WaveformDetail

        public WaveformDetail​(DataReference reference,
                              Message message)
        Constructor when reading from the network or a file.
        Parameters:
        reference - the unique database reference that was used to request this waveform detail
        message - the response that contains the preview
      • WaveformDetail

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

        public WaveformDetail​(DataReference reference,
                              ByteBuffer data,
                              boolean isColor)
        Constructor for use with external caching mechanisms.
        Parameters:
        reference - the unique database reference that was used to request this waveform preview
        data - the waveform data as will be returned by getData()
        isColor - indicates whether the data represents a color waveform
    • Method Detail

      • getData

        public ByteBuffer getData()
        Get the raw bytes of the waveform detail data
        Returns:
        the bytes from which the detail can be drawn, as described in the Packet Analysis document.
      • getFrameCount

        public int getFrameCount()
        Count the half-frames of waveform available.
        Returns:
        the number of half-frames (pixel columns) that make up the track
      • getTotalTime

        public long getTotalTime()
        Determine how long the track plays, in milliseconds. This provides a more accurate value than the track metadata, which is accurate only to the second, because we know how many half-frames (1/150 of a second) the track is composed of.
        Returns:
        the number of milliseconds it will take to play all half-frames that make up the track
      • createViewComponent

        public JComponent createViewComponent​(TrackMetadata metadata,
                                              BeatGrid beatGrid)
        Create a standard Swing component which can be added to a user interface that will draw this waveform detail, optionally including annotations like the current playback position and minute markers (if you supply TrackMetadata so the total length can be determined), and cue markers (if you also supply a CueList). The playback position can be
        Parameters:
        metadata - Information about the track whose waveform we are drawing, so we can translate times into positions
        beatGrid - The locations of all the beats in the track, so they can be drawn
        Returns:
        the component which will draw the annotated waveform preview
      • segmentHeight

        public int segmentHeight​(int segment,
                                 int scale)
        Determine the height of the waveform given an index into it. If scale is larger than 1 we are zoomed out, so we determine an average height of scale segments starting with the specified one.
        Parameters:
        segment - the index of the first waveform byte to examine
        scale - the number of wave segments being drawn as a single pixel column
        Returns:
        a value from 0 to 31 representing the height of the waveform at that segment, which may be an average of a number of values starting there, determined by the scale
      • segmentColor

        public Color segmentColor​(int segment,
                                  int scale)
        Determine the color of the waveform given an index into it. If scale is larger than 1 we are zoomed out, so we determine an average color of scale segments starting with the specified one.
        Parameters:
        segment - the index of the first waveform byte to examine
        scale - the number of wave segments being drawn as a single pixel column
        Returns:
        the color of the waveform at that segment, which may be based on an average of a number of values starting there, determined by the scale