Class BeatFinder


  • public class BeatFinder
    extends LifecycleParticipant

    Watches for devices to report new beats by broadcasting beat packets on port 50001, and passes them on to registered listeners. When players are actively playing music, they send beat packets at the start of each beat which, in addition to announcing the start of the beat, provide information about where the beat falls within a measure of music (assuming that the track was properly configured in rekordbox, and is in 4/4 time), the current BPM of the track being played, and the current player pitch adjustment, from which the actual effective BPM can be calculated.

    When players are stopped, they do not send beat packets, but the mixer continues sending them at the last BPM reported by the master player, so it acts as the most reliable synchronization source. The mixer does not make any effort to keep its notion of measures (down beats) consistent with any player, however. So systems which want to stay in sync with measures as well as beats will want to use the VirtualCdj to maintain awareness of which player is the master player.

    This class also receives special sync and on-air control messages which are sent to the same port as beat packets. If the VirtualCdj is sending status packets, it needs to be notified about these so it can properly update its sync and on-air state if the mixer tells it to, so it will ensure the BeatFinder is running whenever it is sending status updates.
    Author:
    James Elliott
    • Field Detail

      • BEAT_PORT

        public static final int BEAT_PORT
        The port to which devices broadcast beat messages.
        See Also:
        Constant Field Values
    • Method Detail

      • isRunning

        public boolean isRunning()
        Check whether we are presently listening for beat packets.
        Specified by:
        isRunning in class LifecycleParticipant
        Returns:
        true if our socket is open and monitoring for DJ Link beat packets on the network
      • start

        public void start()
                   throws SocketException
        Start listening for beat announcements and sync commands. If already listening, has no effect.
        Throws:
        SocketException - if the socket to listen on port 50001 cannot be created
      • stop

        public void stop()
        Stop listening for beats.
      • addBeatListener

        public void addBeatListener​(BeatListener listener)

        Adds the specified beat listener to receive beat announcements when DJ Link devices broadcast them on the network. If listener is null or already present in the list of registered listeners, no exception is thrown and no action is performed.

        To reduce latency, beat announcements are delivered to listeners directly on the thread that is receiving them them from the network, so if you want to interact with user interface objects in listener methods, you need to use javax.swing.SwingUtilities.invokeLater(Runnable) to do so on the Event Dispatch Thread.

        Even if you are not interacting with user interface objects, any code in the listener method must finish quickly, or it will add latency for other listeners, and beat announcements will back up. If you want to perform lengthy processing of any sort, do so on another thread.

        Parameters:
        listener - the beat listener to add
      • removeBeatListener

        public void removeBeatListener​(BeatListener listener)
        Removes the specified beat listener so that it no longer receives beat announcements when DJ Link devices broadcast them to the network. If listener is null or not present in the list of registered listeners, no exception is thrown and no action is performed.
        Parameters:
        listener - the beat listener to remove
      • getBeatListeners

        public Set<BeatListener> getBeatListeners()
        Get the set of beat listeners that are currently registered.
        Returns:
        the currently registered beat listeners
      • addPrecisePositionListener

        public void addPrecisePositionListener​(PrecisePositionListener listener)

        Adds the specified precise position listener to receive precise position updates when DJ Link devices send them to Beat Link. If listener is null or already present in the list of registered listeners, no exception is thrown and no action is performed.

        To reduce latency, precise position updates are delivered to listeners directly on the thread that is receiving them them from the network, so if you want to interact with user interface objects in listener methods, you need to use javax.swing.SwingUtilities.invokeLater(Runnable) to do so on the Event Dispatch Thread.

        Even if you are not interacting with user interface objects, any code in the listener method must finish quickly, or it will add latency for other listeners, and precise position updates (which are sent frequently, at intervals of roughly 30 milliseconds) will back up. If you want to perform lengthy processing of any sort, do so on another thread.

        Parameters:
        listener - the precise position listener to add
      • removePrecisePositionListener

        public void removePrecisePositionListener​(PrecisePositionListener listener)
        Removes the specified precise position listener so that it no longer receives precise position updates when DJ Link devices send them to Beat Link. If listener is null or not present in the list of registered listeners, no exception is thrown and no action is performed.
        Parameters:
        listener - the precise position listener to remove
      • getPrecisePositionListeners

        public Set<PrecisePositionListener> getPrecisePositionListeners()
        Get the set precise position listeners that are currently registered.
        Returns:
        the currently registered precise position listeners
      • addSyncListener

        public void addSyncListener​(SyncListener listener)

        Adds the specified sync command listener to receive sync commands when DJ Link devices send them to Beat Link. If listener is null or already present in the list of registered listeners, no exception is thrown and no action is performed.

        To reduce latency, sync commands are delivered to listeners directly on the thread that is receiving them them from the network, so if you want to interact with user interface objects in listener methods, you need to use javax.swing.SwingUtilities.invokeLater(Runnable) to do so on the Event Dispatch Thread.

        Even if you are not interacting with user interface objects, any code in the listener method must finish quickly, or it will add latency for other listeners, and beat announcements will back up. If you want to perform lengthy processing of any sort, do so on another thread.

        Parameters:
        listener - the sync listener to add
      • removeSyncListener

        public void removeSyncListener​(SyncListener listener)
        Removes the specified sync listener so that it no longer receives sync commands when DJ Link devices send them to Beat Link. If listener is null or not present in the list of registered listeners, no exception is thrown and no action is performed.
        Parameters:
        listener - the sync listener to remove
      • getSyncListeners

        public Set<SyncListener> getSyncListeners()
        Get the set of sync command listeners that are currently registered.
        Returns:
        the currently registered sync listeners
      • addMasterHandoffListener

        public void addMasterHandoffListener​(MasterHandoffListener listener)

        Adds the specified master handoff listener to receive tempo master handoff commands when DJ Link devices send them to Beat Link. If listener is null or already present in the list of registered listeners, no exception is thrown and no action is performed.

        To reduce latency, handoff commands are delivered to listeners directly on the thread that is receiving them them from the network, so if you want to interact with user interface objects in listener methods, you need to use javax.swing.SwingUtilities.invokeLater(Runnable) to do so on the Event Dispatch Thread.

        Even if you are not interacting with user interface objects, any code in the listener method must finish quickly, or it will add latency for other listeners, and beat announcements will back up. If you want to perform lengthy processing of any sort, do so on another thread.

        Parameters:
        listener - the tempo master handoff listener to add
      • removeMasterHandoffListener

        public void removeMasterHandoffListener​(MasterHandoffListener listener)
        Removes the specified master handoff listener so that it no longer receives tempo master handoff commands when DJ Link devices send them to Beat Link. If listener is null or not present in the list of registered listeners, no exception is thrown and no action is performed.
        Parameters:
        listener - the tempo master handoff listener to remove
      • getMasterHandoffListeners

        public Set<MasterHandoffListener> getMasterHandoffListeners()
        Get the set of master handoff command listeners that are currently registered.
        Returns:
        the currently registered tempo master handoff command listeners
      • addOnAirListener

        public void addOnAirListener​(OnAirListener listener)

        Adds the specified on-air listener to receive channel on-air updates when the mixer broadcasts them on the network. If listener is null or already present in the list of registered listeners, no exception is thrown and no action is performed.

        To reduce latency, on-air updates are delivered to listeners directly on the thread that is receiving them them from the network, so if you want to interact with user interface objects in listener methods, you need to use javax.swing.SwingUtilities.invokeLater(Runnable) to do so on the Event Dispatch Thread.

        Even if you are not interacting with user interface objects, any code in the listener method must finish quickly, or it will add latency for other listeners, and beat announcements will back up. If you want to perform lengthy processing of any sort, do so on another thread.

        Parameters:
        listener - the on-air listener to add
      • removeOnAirListener

        public void removeOnAirListener​(OnAirListener listener)
        Removes the specified on-air listener so that it no longer receives channel on-air updates when the mixer broadcasts them to the network. If listener is null or not present in the list of registered listeners, no exception is thrown and no action is performed.
        Parameters:
        listener - the on-air listener to remove
      • getOnAirListeners

        public Set<OnAirListener> getOnAirListeners()
        Get the set of on-air listeners that are currently registered.
        Returns:
        the currently registered on-air listeners
      • addFaderStartListener

        public void addFaderStartListener​(FaderStartListener listener)

        Adds the specified fader start listener to receive fader start commands when the mixer broadcasts them on the network. If listener is null or already present in the list of registered listeners, no exception is thrown and no action is performed.

        To reduce latency, fader start commands are delivered to listeners directly on the thread that is receiving them them from the network, so if you want to interact with user interface objects in listener methods, you need to use javax.swing.SwingUtilities.invokeLater(Runnable) to do so on the Event Dispatch Thread.

        Even if you are not interacting with user interface objects, any code in the listener method must finish quickly, or it will add latency for other listeners, and beat announcements will back up. If you want to perform lengthy processing of any sort, do so on another thread.

        Parameters:
        listener - the fader start listener to add
      • removeFaderStartListener

        public void removeFaderStartListener​(FaderStartListener listener)
        Removes the specified fader start listener so that it no longer receives fader start commands when the mixer broadcasts them to the network. If listener is null or not present in the list of registered listeners, no exception is thrown and no action is performed.
        Parameters:
        listener - the fader start listener to remove
      • getFaderStartListeners

        public Set<FaderStartListener> getFaderStartListeners()
        Get the set of fader start listeners that are currently registered.
        Returns:
        the currently registered fader start listeners
      • getInstance

        public static BeatFinder getInstance()
        Get the singleton instance of this class.
        Returns:
        the only instance of this class which exists.