Class WaveformPreview


  • public class WaveformPreview
    extends Object
    Gives a birds-eye 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 and cue points, if the appropriate metadata is available.
    Author:
    James Elliott
    • Field Detail

      • 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 preview.
      • rawMessage

        public final Message rawMessage
        The message holding the preview as it was read over the network, if it came from the dbserver. 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.
      • isColor

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

        public final int segmentCount
        The pixel width (number of waveform preview columns) available.
      • maxHeight

        public final int maxHeight
        Holds the maximum height of any point along the waveform, so that it can drawn in a normalized manner to fit its display area.
      • INTENSE_COLOR

        public static final Color INTENSE_COLOR
        The color at which segments of the blue waveform marked most intense are drawn.
      • NORMAL_COLOR

        public static final Color NORMAL_COLOR
        The color at which non-intense blue waveform segments are drawn.
    • Constructor Detail

      • WaveformPreview

        public WaveformPreview​(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
      • WaveformPreview

        public WaveformPreview​(DataReference reference,
                               ByteBuffer data,
                               boolean isColor)
        Constructor when creating from an external caching mechanism.
        Parameters:
        reference - the unique database reference that was used to request this waveform preview
        data - the expanded data as will be returned by getData()
        isColor - indicates whether the data represents a color preview
    • Method Detail

      • getData

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

        public JComponent createViewComponent​(TrackMetadata metadata)
        Create a standard Swing component which can be added to a user interface that will draw this waveform preview, 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
        Returns:
        the component which will draw the annotated waveform preview
      • segmentHeight

        public int segmentHeight​(int segment,
                                 boolean front)
        Determine the height of the preview given an index into it.
        Parameters:
        segment - the index of the waveform preview segment to examine
        front - if true the height of the front (brighter) segment of a color waveform preview is returned, otherwise the height of the back (dimmer) segment is returned. Has no effect for blue previews.
        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,
                                  boolean front)
        Determine the color of the waveform given an index into it.
        Parameters:
        segment - the index of the first waveform byte to examine
        front - if true the front (brighter) segment of a color waveform preview is returned, otherwise the back (dimmer) segment is returned. Has no effect for blue previews.
        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