Class BeatTrackDisplay

  • java.lang.Object
    • java.awt.Component
      • java.awt.Container
        • javax.swing.JComponent
          • javax.swing.JPanel
            • at.ofai.music.beatroot.BeatTrackDisplay
  • All Implemented Interfaces:
    java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener


    public class BeatTrackDisplay
    extends javax.swing.JPanel
    implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener
    Main panel of BeatRoot's GUI, which displays the audio and beat data and allows editing, scrolling, selecting, etc
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static double adjustment
      for synchronising audio and graphics, a constant related to the size of the audio buffer in seconds
      static double allowedError
      For evaluation of beat tracking results, the largest difference allowed between the computed and annotated beat times.
      protected java.util.ListIterator<Event> beatPtr
      location of selected beat (previous()) in the EventList beats
      protected EventList beats
      beat data encoded as a list of Events
      static boolean centred
      mode for scrolling the display: if true the cursor remains centred on the screen and the data scrolls; if false the cursor moves and the data is changed just before the cursor reaches the edge of the screen.
      protected java.awt.Rectangle clipRect
      the clip rectangle for painting only those areas which have changed
      static java.awt.Color[] colour
      colour map used in the spectrogram
      static boolean debug
      Flag for enabling debugging output
      static int DEFAULT_MODE
      the default display mode
      protected int defaultXSize
      width in pixels of this panel
      protected double endSelection
      end of selected data region (may be < start)
      protected double[] env
      the times corresponding to each point in the magnitudes array
      protected int fontSize
      size of font for inter-beat intervals and axis labels
      protected java.awt.Graphics gImage
      the Graphics object for drawing on img
      protected GUI gui
      handle to the GUI (parent) object
      protected java.awt.image.BufferedImage img
      background image showing audio data but not beats
      protected int[] magnitudes
      smoothed amplitude envelope of audio signal
      protected double[] offsets
      the times of offsets (in seconds) for MIDI data
      protected EventList onsetList
      a list of onset events for passing to the tempo induction and beat tracking methods
      protected double[] onsets
      the times of onsets (in seconds)
      protected int[] pitches
      the pitches of MIDI notes
      protected boolean regionSelected
      flag indicating whether a region is selected
      protected int scrollDirection
      the direction of scrolling when dragging outside the displayed bounds
      protected Event selectedBeat
      the current beat (in editing and annotation operations)
      protected double selectedBeatTime
      time of selected beat (for undo)
      static long serialVersionUID
      avoid compiler warning
      static int SHOW_AUDIO 
      static int SHOW_BEATS
      Constants defining the various elements that can be displayed on the main data panel
      static int SHOW_DATA 
      static int SHOW_IBI 
      static int SHOW_MIDI 
      static int SHOW_ONSETS 
      static int SHOW_SPECTRO 
      protected double[][] spectro
      spectrogram data
      protected int spectroLength
      number of frames of valid spectrogram data
      protected double startSelection
      beginning of selected data region
      protected double tInc
      time interval between frames of spectrogram data (hop time)
      protected static double UNKNOWN
      Constant representing an unknown relationship between metrical levels
      static boolean usePScore
      For evaluation, select whether to use the P-score or T-score
      static boolean useRelativeError
      For evaluation of beat tracking results, indicates whether allowedError is interpreted as absolute (in seconds) or relative (0-1).
      protected int x0
      x-coordinate corresponding to time t = 0 (could be off-screen)
      protected int xSize 
      protected int yBottom
      y-coordinate of bottom of data area (position of x-axis)
      protected int yMid
      y-coordinate of the bottom of the spectrogram and top of the amplitude envelope area
      protected int ySize
      height in pixels of this panel
      protected int yTop
      y-coordinate of top of data area
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addAfterSelectedBeat()
      Interpolates a new beat between the currently selected and the following beat
      void addBeat(double time)
      Adds a beat at the given time.
      void addBeatNow()
      Adds a beat at the current playback time, with an adjustment for audio latency.
      void beatTrack()
      Performs automatic beat tracking and updates the GUI accordingly.
      static EventList beatTrack(EventList events)
      Perform beat tracking where the GUI is not active; there is no selected region.
      static EventList beatTrack(EventList events, EventList beats)
      Perform beat tracking where the GUI is not active; there is no selected region.
      void clearBeats()
      Clears all beats in the selected area and sets beatPtr to point between the beats surrounding the deleted area.
      protected void clearImage()
      Clears the background image to white
      void ensureShowing(double time, boolean isRunning)
      Ensures that the given time is visible on the screen, by requesting a scroll if it is off the screen.
      void evaluate(java.lang.String beatsFile)
      Evaluates a beat tracking solution against an annotation of the data.
      static void evaluate(java.lang.String beatsFile, double[] beatsArr)
      Evaluates a beat tracking solution against an annotation of the data.
      static void evaluate(java.lang.String beatsFile, EventList beats)
      Evaluates a beat tracking solution against an annotation of the data.
      static void evaluate(java.lang.String annotationFile, java.lang.String testFile)
      Evaluates a beat tracking solution against an annotation of the data.
      static double getAverageIBI(double[] d)
      Finds the mean tempo (as inter-beat interval) from an array of beat times
      EventList getBeats() 
      double getCurrentTime() 
      int getMaximum() 
      static double getMedianIBI(double[] d)
      Finds the median tempo (as inter-beat interval) from an array of beat times
      int getMinimum() 
      double[] getOffsets() 
      double[] getOnsets() 
      int[] getPitches() 
      static double getRhythmicLevel(double[] beats, double[] correct)
      Estimates the metrical relationship between two beat sequences.
      java.lang.String getSelectedRegion(java.lang.String prefix)
      Gets the start (selectedStart) and length (selectedLength) of the region of audio which has been selected (if any).
      int getValue()
      Returns the time corresponding to the left edge of the display; used in scrolling
      int getVisibleAmount()
      Gets the length of audio that is visible at any one time (i.e.
      void init(boolean resetSelection)
      Initialises the panel after new data is loaded or preferences are changed.
      double locationToTime(int loc)
      Finds the time corresponding to a given x-coordinate.
      void markMetricalLevel(int level, int len, int phase)
      Marks (only) the selected metrical level as specified.
      void mouseClicked(java.awt.event.MouseEvent e)
      Ignore composite events (already processed as press/drag/release events)
      void mouseDragged(java.awt.event.MouseEvent e)
      Called when the mouse is moved with a button down; if a beat is selected, it is moved under the cursor, and if a region is selected it is expanded or shrunk under the cursor.
      void mouseEntered(java.awt.event.MouseEvent e)
      Request focus for key events whenever the mouse enters the window.
      void mouseExited(java.awt.event.MouseEvent e)
      Ignore mouse exit events
      void mouseMoved(java.awt.event.MouseEvent e)
      Ignore mouse movement with no button pressed
      void mousePressed(java.awt.event.MouseEvent e)
      A mouse button press can be used to move (left button), add (middle button), or delete (right button) a beat, or to select or deselect a region, by clicking on the axis.
      void mouseReleased(java.awt.event.MouseEvent e)
      Called when the mouse button is released, to finalise move/add/delete operations.
      void moveBeat(double t1, double t2)
      Changes the time of a beat, and re-sorts the list.
      static Event newBeat(double time, int beatNum)
      Creates a new Event object representing a beat.
      void paint(java.awt.Graphics g)
      Renders the panel.
      protected void paintAudioData(java.awt.Graphics g)
      Paints the audio amplitude envelope and onset markers.
      protected void paintAxes(java.awt.Graphics g)
      Paints the time axis and labels
      protected void paintBackground(java.awt.Graphics g)
      Paints the background of the spectrogram and selected area (if any).
      protected void paintBeats(java.awt.Graphics g)
      Paints the beats and inter-beat intervals
      protected void paintMidiData(java.awt.Graphics g)
      Paints MIDI data in piano-roll notation.
      protected void paintSpectroData(java.awt.Graphics g)
      Paints the spectrogram data.
      void removeBeat(double time)
      Deletes a beat.
      void removeSelectedBeat()
      Deletes the currently selected beat
      void reorderBeats()
      The current beat (pointed to by beatPtr) is moved to its correct place in the otherwise sorted list of beats.
      protected void repaintImage()
      Updates the background image, after creating it if necessary
      void resizeX()
      WG: To resize the panel in the x dimension.
      void scrollTo(double time, boolean isRunning)
      Updates the screen to show data for the current time, by scrolling and/or moving the cursor.
      void selectBeat(int x, int err)
      Selects the nearest beat to a given x-coordinate.
      void selectFirstBeat()
      Selects the first beat
      void selectLastBeat()
      Selects the last beat
      void selectNextBeat()
      Selects the beat after the currently selected beat
      double selectOnset(int x)
      Finds the nearest detected onset time location to a given x-coordinate.
      void selectPreviousBeat()
      Selects the beat before the currently selected beat
      void setBeats(EventList b)
      Sets the list of beats.
      void setCurrentTime(double currentTime) 
      void setEnvTimes(double[] envTimes)
      Sets the array of times of amplitude envelope points, for displaying.
      void setMagnitudes(int[] mag)
      Sets the array of magnitude values, for displaying.
      void setMetricalLevel(int x)
      Marks the selected beat with all metrical levels up to and including x.
      void setMode(int on, int off)
      Changes the display mode (which elements are displayed on the panel).
      void setOffsets(double[] off)
      Sets the array of offset times, for displaying MIDI input data.
      void setOnsetDetectionParam(double param1, double param2) 
      void setOnsetList(EventList on)
      Sets the onset times as a list of Events, for use by the beat tracking methods.
      void setOnsets(double[] on)
      Sets the array of onset times, for displaying MIDI or audio input data.
      void setPitches(int[] p)
      Sets the array of pitch values, for displaying MIDI input data.
      void setSpectro(double[][] spec, int len, double inc, double lap)
      Sets the data for the spectrogram.
      void setValue(int value)
      Scrolls the data so that the left edge of the panel corresponds to the given time.
      void setVisibleAmount(int msec)
      Sets the length of audio that is visible at any one time (i.e.
      int timeToLocation(double time)
      Finds the x-coordinate corresponding to the given time.
      void toggleAnnotateMode()
      Turns keyboard annotation of metrical levels on and off
      void update(java.awt.Graphics g)
      Don't clear before repainting
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • adjustment

        public static double adjustment
        for synchronising audio and graphics, a constant related to the size of the audio buffer in seconds
      • allowedError

        public static double allowedError
        For evaluation of beat tracking results, the largest difference allowed between the computed and annotated beat times.
      • beatPtr

        protected java.util.ListIterator<Event> beatPtr
        location of selected beat (previous()) in the EventList beats
      • beats

        protected EventList beats
        beat data encoded as a list of Events
      • centred

        public static boolean centred
        mode for scrolling the display: if true the cursor remains centred on the screen and the data scrolls; if false the cursor moves and the data is changed just before the cursor reaches the edge of the screen.
      • clipRect

        protected java.awt.Rectangle clipRect
        the clip rectangle for painting only those areas which have changed
      • colour

        public static final java.awt.Color[] colour
        colour map used in the spectrogram
      • debug

        public static boolean debug
        Flag for enabling debugging output
      • DEFAULT_MODE

        public static final int DEFAULT_MODE
        the default display mode
        See Also:
        Constant Field Values
      • defaultXSize

        protected final int defaultXSize
        width in pixels of this panel
        See Also:
        Constant Field Values
      • endSelection

        protected double endSelection
        end of selected data region (may be < start)
      • env

        protected double[] env
        the times corresponding to each point in the magnitudes array
      • fontSize

        protected int fontSize
        size of font for inter-beat intervals and axis labels
      • gImage

        protected java.awt.Graphics gImage
        the Graphics object for drawing on img
      • gui

        protected GUI gui
        handle to the GUI (parent) object
      • img

        protected java.awt.image.BufferedImage img
        background image showing audio data but not beats
      • magnitudes

        protected int[] magnitudes
        smoothed amplitude envelope of audio signal
      • offsets

        protected double[] offsets
        the times of offsets (in seconds) for MIDI data
      • onsetList

        protected EventList onsetList
        a list of onset events for passing to the tempo induction and beat tracking methods
      • onsets

        protected double[] onsets
        the times of onsets (in seconds)
      • pitches

        protected int[] pitches
        the pitches of MIDI notes
      • regionSelected

        protected boolean regionSelected
        flag indicating whether a region is selected
      • scrollDirection

        protected int scrollDirection
        the direction of scrolling when dragging outside the displayed bounds
      • selectedBeat

        protected Event selectedBeat
        the current beat (in editing and annotation operations)
      • selectedBeatTime

        protected double selectedBeatTime
        time of selected beat (for undo)
      • serialVersionUID

        public static final long serialVersionUID
        avoid compiler warning
        See Also:
        Constant Field Values
      • SHOW_BEATS

        public static final int SHOW_BEATS
        Constants defining the various elements that can be displayed on the main data panel
        See Also:
        Constant Field Values
      • spectro

        protected double[][] spectro
        spectrogram data
      • spectroLength

        protected int spectroLength
        number of frames of valid spectrogram data
      • startSelection

        protected double startSelection
        beginning of selected data region
      • tInc

        protected double tInc
        time interval between frames of spectrogram data (hop time)
      • UNKNOWN

        protected static final double UNKNOWN
        Constant representing an unknown relationship between metrical levels
        See Also:
        Constant Field Values
      • usePScore

        public static boolean usePScore
        For evaluation, select whether to use the P-score or T-score
      • useRelativeError

        public static boolean useRelativeError
        For evaluation of beat tracking results, indicates whether allowedError is interpreted as absolute (in seconds) or relative (0-1).
      • x0

        protected int x0
        x-coordinate corresponding to time t = 0 (could be off-screen)
      • xSize

        protected int xSize
      • yBottom

        protected int yBottom
        y-coordinate of bottom of data area (position of x-axis)
      • yMid

        protected int yMid
        y-coordinate of the bottom of the spectrogram and top of the amplitude envelope area
      • ySize

        protected int ySize
        height in pixels of this panel
      • yTop

        protected int yTop
        y-coordinate of top of data area
    • Constructor Detail

      • BeatTrackDisplay

        public BeatTrackDisplay(GUI g,
                                EventList b)
        Constructor:
        Parameters:
        g - A handle to the parent GUI object
        b - The list of beats
    • Method Detail

      • init

        public void init(boolean resetSelection)
        Initialises the panel after new data is loaded or preferences are changed.
        Parameters:
        resetSelection - Indicates whether the selected region should be cleared
      • setMode

        public void setMode(int on,
                            int off)
        Changes the display mode (which elements are displayed on the panel). Constant values (SHOW_BEATS, etc.) are defined above.
        Parameters:
        on - A bit string indicating the elements that should be switched on
        off - A bit string indicating the elements that should be switched off
      • getMinimum

        public int getMinimum()
        Returns:
        The minimum time that might need to be displayed for this data
      • getMaximum

        public int getMaximum()
        Returns:
        The maximum time that might need to be displayed for this data
      • getValue

        public int getValue()
        Returns the time corresponding to the left edge of the display; used in scrolling
        Returns:
        The time in milliseconds of the left edge of the display
      • setValue

        public void setValue(int value)
        Scrolls the data so that the left edge of the panel corresponds to the given time.
        Parameters:
        value - The given time in milliseconds
      • ensureShowing

        public void ensureShowing(double time,
                                  boolean isRunning)
        Ensures that the given time is visible on the screen, by requesting a scroll if it is off the screen.
        Parameters:
        time - The current time of audio output in seconds
        isRunning - Flag indicating whether audio output is active
      • scrollTo

        public void scrollTo(double time,
                             boolean isRunning)
        Updates the screen to show data for the current time, by scrolling and/or moving the cursor.
        Parameters:
        time - The current time of audio output in seconds
        isRunning - Flag indicating whether audio output is active
      • getSelectedRegion

        public java.lang.String getSelectedRegion(java.lang.String prefix)
        Gets the start (selectedStart) and length (selectedLength) of the region of audio which has been selected (if any). The result is returned as a String containing a list of attribute-value pairs, where the attribute and value are separated by '=' and the pairs are separated by a space.
        Parameters:
        prefix - Other attribute-value pairs
        Returns:
        The prefix followed by the start and length pairs if set
      • getVisibleAmount

        public int getVisibleAmount()
        Gets the length of audio that is visible at any one time (i.e. zoom factor).
        Returns:
        Length in milliseconds
      • setVisibleAmount

        public void setVisibleAmount(int msec)
        Sets the length of audio that is visible at any one time (i.e. zoom factor).
        Parameters:
        msec - Length in milliseconds
      • update

        public void update(java.awt.Graphics g)
        Don't clear before repainting
        Overrides:
        update in class javax.swing.JComponent
      • paint

        public void paint(java.awt.Graphics g)
        Renders the panel.
        Overrides:
        paint in class javax.swing.JComponent
        Parameters:
        g - The Graphics object for painting on this panel.
      • clearImage

        protected void clearImage()
        Clears the background image to white
      • repaintImage

        protected void repaintImage()
        Updates the background image, after creating it if necessary
      • paintBackground

        protected void paintBackground(java.awt.Graphics g)
        Paints the background of the spectrogram and selected area (if any).
        Parameters:
        g - The Graphics object to paint to (i.e. img)
      • paintAxes

        protected void paintAxes(java.awt.Graphics g)
        Paints the time axis and labels
        Parameters:
        g - The Graphics object to paint to
      • paintBeats

        protected void paintBeats(java.awt.Graphics g)
        Paints the beats and inter-beat intervals
        Parameters:
        g - The Graphics object to paint to
      • paintMidiData

        protected void paintMidiData(java.awt.Graphics g)
        Paints MIDI data in piano-roll notation.
        Parameters:
        g - The Graphics object to paint to (i.e. img)
      • paintAudioData

        protected void paintAudioData(java.awt.Graphics g)
        Paints the audio amplitude envelope and onset markers.
        Parameters:
        g - The Graphics object to paint to (i.e. img)
      • paintSpectroData

        protected void paintSpectroData(java.awt.Graphics g)
        Paints the spectrogram data.
        Parameters:
        g - The Graphics object to paint to (i.e. img)
      • timeToLocation

        public int timeToLocation(double time)
        Finds the x-coordinate corresponding to the given time.
        Parameters:
        time - Time in seconds
        Returns:
        The corresponding x-coordinate
      • locationToTime

        public double locationToTime(int loc)
        Finds the time corresponding to a given x-coordinate.
        Parameters:
        loc - The given x-coordinate
        Returns:
        The corresponding time in seconds
      • toggleAnnotateMode

        public void toggleAnnotateMode()
        Turns keyboard annotation of metrical levels on and off
      • selectFirstBeat

        public void selectFirstBeat()
        Selects the first beat
      • selectLastBeat

        public void selectLastBeat()
        Selects the last beat
      • selectNextBeat

        public void selectNextBeat()
        Selects the beat after the currently selected beat
      • selectPreviousBeat

        public void selectPreviousBeat()
        Selects the beat before the currently selected beat
      • removeSelectedBeat

        public void removeSelectedBeat()
        Deletes the currently selected beat
      • addAfterSelectedBeat

        public void addAfterSelectedBeat()
        Interpolates a new beat between the currently selected and the following beat
      • setMetricalLevel

        public void setMetricalLevel(int x)
        Marks the selected beat with all metrical levels up to and including x.
        Parameters:
        x - The given highest metrical level
      • markMetricalLevel

        public void markMetricalLevel(int level,
                                      int len,
                                      int phase)
        Marks (only) the selected metrical level as specified.
        Parameters:
        level - The given metrical level
        len - The number of lowest-level beats in one unit of this metrical level
        phase - The position of the first lowest-level beat relative to the boundaries of this metrical level, where 0 means it is aligned
      • selectBeat

        public void selectBeat(int x,
                               int err)
        Selects the nearest beat to a given x-coordinate.
        Parameters:
        x - The x-coordinate (e.g. of a mouse-click) near which a beat is sought
        err - The allowed error in the beat location: if negative, no limit is imposed on the beat, otherwise the beat must be within err pixels of x. If no suitable beat is found, there is no selected beat.
      • selectOnset

        public double selectOnset(int x)
        Finds the nearest detected onset time location to a given x-coordinate.
        Parameters:
        x - The x-coordinate (e.g. of a mouse-click) near shich a beat is sought
        Returns:
        The onset time (s) of the nearest detected onset. inserted by WG, 7 Aug 2009
      • newBeat

        public static Event newBeat(double time,
                                    int beatNum)
        Creates a new Event object representing a beat.
        Parameters:
        time - The time of the beat in seconds
        beatNum - The index of the beat
        Returns:
        The Event object representing the beat
      • addBeatNow

        public void addBeatNow()
        Adds a beat at the current playback time, with an adjustment for audio latency. This was a failed attempt at a tapping interface to BeatRoot, as the timing doesn't appear to be at all stable on my platform.
      • addBeat

        public void addBeat(double time)
        Adds a beat at the given time.
        Parameters:
        time - Time in seconds of the new beat
      • moveBeat

        public void moveBeat(double t1,
                             double t2)
        Changes the time of a beat, and re-sorts the list. If no beat is found at the given time, an error message is printed and nothing further occurs.
        Parameters:
        t1 - The original time of the beat
        t2 - The new time of the beat
      • removeBeat

        public void removeBeat(double time)
        Deletes a beat.
        Parameters:
        time - The time of the beat (in seconds)
      • clearBeats

        public void clearBeats()
        Clears all beats in the selected area and sets beatPtr to point between the beats surrounding the deleted area.
      • reorderBeats

        public void reorderBeats()
        The current beat (pointed to by beatPtr) is moved to its correct place in the otherwise sorted list of beats.
      • beatTrack

        public static EventList beatTrack(EventList events)
        Perform beat tracking where the GUI is not active; there is no selected region.
        Parameters:
        events - The onsets or peaks in a feature list
        Returns:
        The list of beats, or an empty list if beat tracking fails
      • beatTrack

        public static EventList beatTrack(EventList events,
                                          EventList beats)
        Perform beat tracking where the GUI is not active; there is no selected region.
        Parameters:
        events - The onsets or peaks in a feature list
        beats - The initial beats which are given, if any
        Returns:
        The list of beats, or an empty list if beat tracking fails
      • beatTrack

        public void beatTrack()
        Performs automatic beat tracking and updates the GUI accordingly. If a region is selected, the beats outside the region are kept intact and the tempo preserved across the region boundaries.
      • getAverageIBI

        public static double getAverageIBI(double[] d)
        Finds the mean tempo (as inter-beat interval) from an array of beat times
        Parameters:
        d - An array of beat times
        Returns:
        The average inter-beat interval
      • getMedianIBI

        public static double getMedianIBI(double[] d)
        Finds the median tempo (as inter-beat interval) from an array of beat times
        Parameters:
        d - An array of beat times
        Returns:
        The median inter-beat interval
      • getRhythmicLevel

        public static double getRhythmicLevel(double[] beats,
                                              double[] correct)
        Estimates the metrical relationship between two beat sequences.
        Parameters:
        beats - The system's beat times
        correct - The annotated beat times
        Returns:
        A double encoding the metrical relationship between the sequences, which ideally should be an integer or reciprocal of an integer.
      • evaluate

        public void evaluate(java.lang.String beatsFile)
        Evaluates a beat tracking solution against an annotation of the data.
        Parameters:
        beatsFile - The file name of the annotation data
      • evaluate

        public static void evaluate(java.lang.String beatsFile,
                                    EventList beats)
        Evaluates a beat tracking solution against an annotation of the data.
        Parameters:
        beatsFile - The file name of the annotation data
        beats - The list of beats to be evaluated
      • evaluate

        public static void evaluate(java.lang.String annotationFile,
                                    java.lang.String testFile)
        Evaluates a beat tracking solution against an annotation of the data.
        Parameters:
        annotationFile - The file name of the annotation data
        testFile - The file name containing the beat times (as text) to be evaluated
      • evaluate

        public static void evaluate(java.lang.String beatsFile,
                                    double[] beatsArr)
        Evaluates a beat tracking solution against an annotation of the data.
        Parameters:
        beatsFile - The file name of the annotation data
        beatsArr - The array of beat times to be evaluated
      • mouseClicked

        public void mouseClicked(java.awt.event.MouseEvent e)
        Ignore composite events (already processed as press/drag/release events)
        Specified by:
        mouseClicked in interface java.awt.event.MouseListener
      • mouseExited

        public void mouseExited(java.awt.event.MouseEvent e)
        Ignore mouse exit events
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
      • mouseMoved

        public void mouseMoved(java.awt.event.MouseEvent e)
        Ignore mouse movement with no button pressed
        Specified by:
        mouseMoved in interface java.awt.event.MouseMotionListener
      • mouseEntered

        public void mouseEntered(java.awt.event.MouseEvent e)
        Request focus for key events whenever the mouse enters the window.
        Specified by:
        mouseEntered in interface java.awt.event.MouseListener
      • mousePressed

        public void mousePressed(java.awt.event.MouseEvent e)
        A mouse button press can be used to move (left button), add (middle button), or delete (right button) a beat, or to select or deselect a region, by clicking on the axis.
        Specified by:
        mousePressed in interface java.awt.event.MouseListener
        Parameters:
        e - The object describing the event that occurred
      • mouseDragged

        public void mouseDragged(java.awt.event.MouseEvent e)
        Called when the mouse is moved with a button down; if a beat is selected, it is moved under the cursor, and if a region is selected it is expanded or shrunk under the cursor.
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
      • mouseReleased

        public void mouseReleased(java.awt.event.MouseEvent e)
        Called when the mouse button is released, to finalise move/add/delete operations.
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
      • getBeats

        public EventList getBeats()
        Returns:
        the list of beats
      • getOnsets

        public double[] getOnsets()
        Returns:
        the array of onset times
      • getOffsets

        public double[] getOffsets()
        Returns:
        the array of offset times
      • getPitches

        public int[] getPitches()
        Returns:
        the array of MIDI pitches
      • setOnsetList

        public void setOnsetList(EventList on)
        Sets the onset times as a list of Events, for use by the beat tracking methods.
        Parameters:
        on - The times of onsets in seconds
      • setOnsets

        public void setOnsets(double[] on)
        Sets the array of onset times, for displaying MIDI or audio input data.
        Parameters:
        on - The times of onsets in seconds
      • setOffsets

        public void setOffsets(double[] off)
        Sets the array of offset times, for displaying MIDI input data.
        Parameters:
        off - The array of MIDI offset times
      • setEnvTimes

        public void setEnvTimes(double[] envTimes)
        Sets the array of times of amplitude envelope points, for displaying.
        Parameters:
        envTimes - The array of times in seconds corresponding to the values in magnitudes
      • setMagnitudes

        public void setMagnitudes(int[] mag)
        Sets the array of magnitude values, for displaying.
        Parameters:
        mag - The array of amplitude envelope values
      • setPitches

        public void setPitches(int[] p)
        Sets the array of pitch values, for displaying MIDI input data.
        Parameters:
        p - The array of MIDI pitch values
      • setBeats

        public void setBeats(EventList b)
        Sets the list of beats.
        Parameters:
        b - The list of beats
      • setSpectro

        public void setSpectro(double[][] spec,
                               int len,
                               double inc,
                               double lap)
        Sets the data for the spectrogram.
        Parameters:
        spec - The spectrogram data, indexed by time and frequency
        len - The number of frames of spectrogram data
        inc - The time interval between frames of spectrogram data
        lap - The ratio between hop size and frame size
      • resizeX

        public void resizeX()
        WG: To resize the panel in the x dimension.
      • getCurrentTime

        public double getCurrentTime()
      • setCurrentTime

        public void setCurrentTime(double currentTime)
      • setOnsetDetectionParam

        public void setOnsetDetectionParam(double param1,
                                           double param2)