public synchronized void setMonitoredPlayer ( final int player ) { if ( player < 0 ) { throw new IllegalArgumentException ( "player cannot be negative" ) ; } clearPlaybackState ( ) ; monitoredPlayer . set ( player ) ; if ( player > 0 ) { // Start monitoring the specified player setPlaybackState ( player , 0 , false ) ; // Start with default values for required simple state. VirtualCdj . getInstance ( ) . addUpdateListener ( updateListener ) ; MetadataFinder . getInstance ( ) . addTrackMetadataListener ( metadataListener ) ; cueList . set ( null ) ; // Assume the worst, but see if we have one available next. if ( MetadataFinder . getInstance ( ) . isRunning ( ) ) { TrackMetadata metadata = MetadataFinder . getInstance ( ) . getLatestMetadataFor ( player ) ; if ( metadata != null ) { cueList . set ( metadata . getCueList ( ) ) ; } } WaveformFinder . getInstance ( ) . addWaveformListener ( waveformListener ) ; if ( WaveformFinder . getInstance ( ) . isRunning ( ) && WaveformFinder . getInstance ( ) . isFindingDetails ( ) ) { waveform . set ( WaveformFinder . getInstance ( ) . getLatestDetailFor ( player ) ) ; } else { waveform . set ( null ) ; } BeatGridFinder . getInstance ( ) . addBeatGridListener ( beatGridListener ) ; if ( BeatGridFinder . getInstance ( ) . isRunning ( ) ) { beatGrid . set ( BeatGridFinder . getInstance ( ) . getLatestBeatGridFor ( player ) ) ; } else { beatGrid . set ( null ) ; } try { TimeFinder . getInstance ( ) . start ( ) ; if ( ! animating . getAndSet ( true ) ) { // Create the thread to update our position smoothly as the track plays new Thread ( new Runnable ( ) { @ Override public void run ( ) { while ( animating . get ( ) ) { try { Thread . sleep ( 33 ) ; // Animate at 30 fps } catch ( InterruptedException e ) { logger . warn ( "Waveform animation thread interrupted; ending" ) ; animating . set ( false ) ; } setPlaybackPosition ( TimeFinder . getInstance ( ) . getTimeFor ( getMonitoredPlayer ( ) ) ) ; } } } ) . start ( ) ; } } catch ( Exception e ) { logger . error ( "Unable to start the TimeFinder to animate the waveform detail view" ) ; animating . set ( false ) ; } } else { // Stop monitoring any player animating . set ( false ) ; VirtualCdj . getInstance ( ) . removeUpdateListener ( updateListener ) ; MetadataFinder . getInstance ( ) . removeTrackMetadataListener ( metadataListener ) ; WaveformFinder . getInstance ( ) . removeWaveformListener ( waveformListener ) ; cueList . set ( null ) ; waveform . set ( null ) ; beatGrid . set ( null ) ; } if ( ! autoScroll . get ( ) ) { invalidate ( ) ; } repaint ( ) ; }
Configures the player whose current track waveforms and status will automatically be reflected . Whenever a new track is loaded on that player the waveform and metadata will be updated and the current playback position and state of the player will be reflected by the component .