public class TimeFinder extends LifecycleParticipant
Watches the beat packets and transport information contained in player status update to infer the current track playback position based on the most recent information available, the time at which that was received, and the playback pitch and direction that was in effect at that time.
Can only operate properly when track metadata and beat grids are available, as these are necessary to convert beat numbers into track positions.
| Modifier and Type | Method and Description |
|---|---|
void |
addTrackPositionListener(int player,
TrackPositionListener listener)
Add a listener that wants to closely follow track playback for a particular player.
|
static TimeFinder |
getInstance()
Get the singleton instance of this class.
|
TrackPositionUpdate |
getLatestPositionFor(DeviceUpdate update)
Get the latest information we have for the player that sent the supplied status update.
|
TrackPositionUpdate |
getLatestPositionFor(int player)
Get the latest information we have for the specified player.
|
Map<Integer,TrackPositionUpdate> |
getLatestPositions()
Get the latest track position reports available for all visible players.
|
DeviceUpdate |
getLatestUpdateFor(int player)
Get the beat or status update reported by the specified player, whichever is most recent.
|
Map<Integer,DeviceUpdate> |
getLatestUpdates()
Get the latest device updates (either beats or status updates) available for all visible players.
|
long |
getSlack()
Check how many milliseconds our interpolated time is allowed to drift from what is being reported by a player
before we consider it a significant enough change to report to listeners that are trying to closely track a
player's playback position.
|
long |
getTimeFor(DeviceUpdate update)
Get the best guess we have for the current track position on the player that sent the specified update.
|
long |
getTimeFor(int player)
Get the best guess we have for the current track position on the specified player.
|
boolean |
isRunning()
Check whether we are currently running.
|
void |
removeTrackPositionListener(TrackPositionListener listener)
Remove a listener that was following track playback movement.
|
void |
setSlack(long slack)
Set how many milliseconds our interpolated time is allowed to drift from what is being reported by a player
before we consider it a significant enough change to report to listeners that are trying to closely track a
player's playback position.
|
void |
start()
Start interpolating playback position for all active players.
|
void |
stop()
Stop interpolating playback position for all active players.
|
String |
toString() |
addLifecycleListener, deliverLifecycleAnnouncement, ensureRunning, getLifecycleListeners, removeLifecycleListenerpublic boolean isRunning()
isRunning in class LifecycleParticipantpublic Map<Integer,TrackPositionUpdate> getLatestPositions()
IllegalStateException - if the TimeFinder is not runningpublic Map<Integer,DeviceUpdate> getLatestUpdates()
public TrackPositionUpdate getLatestPositionFor(int player)
player - the player number whose position information is desirednull if we
do not have enough information to calculate itIllegalStateException - if the TimeFinder is not runningpublic TrackPositionUpdate getLatestPositionFor(DeviceUpdate update)
update - the device update from a player whose position information is desirednull if we
do not have enough information to calculate itIllegalStateException - if the TimeFinder is not runningpublic DeviceUpdate getLatestUpdateFor(int player)
player - the player number whose most recent status is desirednull if we have not heard anyIllegalStateException - if the TimeFinder is not runningpublic long getTimeFor(int player)
player - the player number whose position is desiredIllegalStateException - if the TimeFinder is not runningpublic long getTimeFor(DeviceUpdate update)
update - the device update from a player whose position is desiredIllegalStateException - if the TimeFinder is not runningpublic void addTrackPositionListener(int player,
TrackPositionListener listener)
TrackPositionUpdate for the specified player, and whenever there is an
unexpected change in playback position, speed, or state on that player.player - the player number that the listener is interested inlistener - the interface that will be called when there are changes in track playback on the playerpublic void removeTrackPositionListener(TrackPositionListener listener)
listener - the interface that will no longer be called for changes in track playbackpublic long getSlack()
public void setSlack(long slack)
slack - the maximum number of milliseconds we will allow our listeners to diverge from the reported playback
position before reporting a jumppublic void start()
throws Exception
Start interpolating playback position for all active players. Starts the BeatGridFinder,
BeatFinder, and VirtualCdj if they are not already running, because we need them to
perform our calculations. This in turn starts the DeviceFinder, so we can keep track of the
comings and goings of players themselves.
Exception - if there is a problem starting the required componentspublic void stop()
public static TimeFinder getInstance()
Copyright © 2016–2018 Deep Symmetry, LLC. All rights reserved.