idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
150,800
@ SuppressWarnings ( "SameParameterValue" ) private byte [ ] readResponseWithExpectedSize ( InputStream is , int size , String description ) throws IOException { byte [ ] result = receiveBytes ( is ) ; if ( result . length != size ) { logger . warn ( "Expected " + size + " bytes while reading " + description + " respon...
Receive an expected number of bytes from the player logging a warning if we get a different number of them .
150,801
private synchronized void closeIdleClients ( ) { List < Client > candidates = new LinkedList < Client > ( openClients . values ( ) ) ; logger . debug ( "Scanning for idle clients; " + candidates . size ( ) + " candidates." ) ; for ( Client client : candidates ) { if ( ( useCounts . get ( client ) < 1 ) && ( ( timestamp...
Finds any clients which are not currently in use and which have been idle for longer than the idle timeout and closes them .
150,802
public synchronized void start ( ) throws SocketException { if ( ! isRunning ( ) ) { DeviceFinder . getInstance ( ) . addLifecycleListener ( lifecycleListener ) ; DeviceFinder . getInstance ( ) . addDeviceAnnouncementListener ( announcementListener ) ; DeviceFinder . getInstance ( ) . start ( ) ; for ( DeviceAnnounceme...
Start offering shared dbserver sessions .
150,803
public synchronized void stop ( ) { if ( isRunning ( ) ) { running . set ( false ) ; DeviceFinder . getInstance ( ) . removeDeviceAnnouncementListener ( announcementListener ) ; dbServerPorts . clear ( ) ; for ( Client client : openClients . values ( ) ) { try { client . close ( ) ; } catch ( Exception e ) { logger . w...
Stop offering shared dbserver sessions .
150,804
private SearchableItem buildSearchableItem ( Message menuItem ) { return new SearchableItem ( ( int ) ( ( NumberField ) menuItem . arguments . get ( 1 ) ) . getValue ( ) , ( ( StringField ) menuItem . arguments . get ( 3 ) ) . getValue ( ) ) ; }
Creates a searchable item that represents a metadata field found for a track .
150,805
private ColorItem buildColorItem ( Message menuItem ) { final int colorId = ( int ) ( ( NumberField ) menuItem . arguments . get ( 1 ) ) . getValue ( ) ; final String label = ( ( StringField ) menuItem . arguments . get ( 3 ) ) . getValue ( ) ; return buildColorItem ( colorId , label ) ; }
Creates a color item that represents a color field found for a track based on a dbserver message .
150,806
private ColorItem buildColorItem ( int colorId , String label ) { Color color ; String colorName ; switch ( colorId ) { case 0 : color = new Color ( 0 , 0 , 0 , 0 ) ; colorName = "No Color" ; break ; case 1 : color = Color . PINK ; colorName = "Pink" ; break ; case 2 : color = Color . RED ; colorName = "Red" ; break ; ...
Creates a color item that represents a color field fond for a track .
150,807
private void parseMetadataItem ( Message item ) { switch ( item . getMenuItemType ( ) ) { case TRACK_TITLE : title = ( ( StringField ) item . arguments . get ( 3 ) ) . getValue ( ) ; artworkId = ( int ) ( ( NumberField ) item . arguments . get ( 8 ) ) . getValue ( ) ; break ; case ARTIST : artist = buildSearchableItem ...
Processes one of the menu responses that jointly constitute the track metadata updating our fields accordingly .
150,808
@ SuppressWarnings ( "WeakerAccess" ) public ByteBuffer getRawData ( ) { if ( rawData != null ) { rawData . rewind ( ) ; return rawData . slice ( ) ; } return null ; }
Get the raw bytes of the beat grid as it was read over the network . This can be used to analyze fields that have not yet been reliably understood and is also used for storing the beat grid in a cache file . This is not available when the beat grid was loaded by Crate Digger .
150,809
private RekordboxAnlz . BeatGridTag findTag ( RekordboxAnlz anlzFile ) { for ( RekordboxAnlz . TaggedSection section : anlzFile . sections ( ) ) { if ( section . body ( ) instanceof RekordboxAnlz . BeatGridTag ) { return ( RekordboxAnlz . BeatGridTag ) section . body ( ) ; } } throw new IllegalArgumentException ( "No b...
Helper function to find the beat grid section in a rekordbox track analysis file .
150,810
private int beatOffset ( int beatNumber ) { if ( beatCount == 0 ) { throw new IllegalStateException ( "There are no beats in this beat grid." ) ; } if ( beatNumber < 1 || beatNumber > beatCount ) { throw new IndexOutOfBoundsException ( "beatNumber (" + beatNumber + ") must be between 1 and " + beatCount ) ; } return be...
Calculate where within the beat grid array the information for the specified beat can be found . Yes this is a super simple calculation ; the main point of the method is to provide a nice exception when the beat is out of bounds .
150,811
@ SuppressWarnings ( "WeakerAccess" ) public int findBeatAtTime ( long milliseconds ) { int found = Arrays . binarySearch ( timeWithinTrackValues , milliseconds ) ; if ( found >= 0 ) { return found + 1 ; } else if ( found == - 1 ) { return found ; } else { return - ( found + 1 ) ; } }
Finds the beat in which the specified track position falls .
150,812
public List < Message > requestTrackMenuFrom ( final SlotReference slotReference , final int sortOrder ) throws Exception { ConnectionManager . ClientTask < List < Message > > task = new ConnectionManager . ClientTask < List < Message > > ( ) { public List < Message > useClient ( Client client ) throws Exception { retu...
Ask the specified player for a Track menu .
150,813
public List < Message > requestArtistMenuFrom ( final SlotReference slotReference , final int sortOrder ) throws Exception { ConnectionManager . ClientTask < List < Message > > task = new ConnectionManager . ClientTask < List < Message > > ( ) { public List < Message > useClient ( Client client ) throws Exception { if ...
Ask the specified player for an Artist menu .
150,814
public List < Message > requestFolderMenuFrom ( final SlotReference slotReference , final int sortOrder , final int folderId ) throws Exception { ConnectionManager . ClientTask < List < Message > > task = new ConnectionManager . ClientTask < List < Message > > ( ) { public List < Message > useClient ( Client client ) t...
Ask the specified player for a Folder menu for exploring its raw filesystem . This is a request for unanalyzed items so we do a typed menu request .
150,815
public static Field read ( DataInputStream is ) throws IOException { final byte tag = is . readByte ( ) ; final Field result ; switch ( tag ) { case 0x0f : case 0x10 : case 0x11 : result = new NumberField ( tag , is ) ; break ; case 0x14 : result = new BinaryField ( is ) ; break ; case 0x26 : result = new StringField (...
Read a field from the supplied stream starting with the tag that identifies the type and reading enough to collect the corresponding value .
150,816
public void write ( WritableByteChannel channel ) throws IOException { logger . debug ( "..writing> {}" , this ) ; Util . writeFully ( getBytes ( ) , channel ) ; }
Write the field to the specified channel .
150,817
@ SuppressWarnings ( "WeakerAccess" ) public TrackMetadata requestMetadataFrom ( final CdjStatus status ) { if ( status . getTrackSourceSlot ( ) == CdjStatus . TrackSourceSlot . NO_TRACK || status . getRekordboxId ( ) == 0 ) { return null ; } final DataReference track = new DataReference ( status . getTrackSourcePlayer...
Given a status update from a CDJ find the metadata for the track that it has loaded if any . If there is an appropriate metadata cache will use that otherwise makes a query to the players dbserver .
150,818
@ SuppressWarnings ( "WeakerAccess" ) public TrackMetadata requestMetadataFrom ( final DataReference track , final CdjStatus . TrackType trackType ) { return requestMetadataInternal ( track , trackType , false ) ; }
Ask the specified player for metadata about the track in the specified slot with the specified rekordbox ID unless we have a metadata cache available for the specified media slot in which case that will be used instead .
150,819
private TrackMetadata requestMetadataInternal ( final DataReference track , final CdjStatus . TrackType trackType , final boolean failIfPassive ) { MetadataCache cache = getMetadataCache ( SlotReference . getSlotReference ( track ) ) ; if ( cache != null && trackType == CdjStatus . TrackType . REKORDBOX ) { return cach...
Ask the specified player for metadata about the track in the specified slot with the specified rekordbox ID using cached media instead if it is available and possibly giving up if we are in passive mode .
150,820
TrackMetadata queryMetadata ( final DataReference track , final CdjStatus . TrackType trackType , final Client client ) throws IOException , InterruptedException , TimeoutException { if ( client . tryLockingForMenuOperations ( 20 , TimeUnit . SECONDS ) ) { try { final Message . KnownType requestType = ( trackType == Cd...
Request metadata for a specific track ID given a dbserver connection to a player that has already been set up . Separated into its own method so it could be used multiple times with the same connection when gathering all track metadata .
150,821
CueList getCueList ( int rekordboxId , CdjStatus . TrackSourceSlot slot , Client client ) throws IOException { Message response = client . simpleRequest ( Message . KnownType . CUE_LIST_REQ , null , client . buildRMST ( Message . MenuIdentifier . DATA , slot ) , new NumberField ( rekordboxId ) ) ; if ( response . known...
Requests the cue list for a specific track ID given a dbserver connection to a player that has already been set up .
150,822
List < Message > getFullTrackList ( final CdjStatus . TrackSourceSlot slot , final Client client , final int sortOrder ) throws IOException , InterruptedException , TimeoutException { if ( client . tryLockingForMenuOperations ( MENU_TIMEOUT , TimeUnit . SECONDS ) ) { try { Message response = client . menuRequest ( Mess...
Request the list of all tracks in the specified slot given a dbserver connection to a player that has already been set up .
150,823
private void clearDeck ( CdjStatus update ) { if ( hotCache . remove ( DeckReference . getDeckReference ( update . getDeviceNumber ( ) , 0 ) ) != null ) { deliverTrackMetadataUpdate ( update . getDeviceNumber ( ) , null ) ; } }
We have received an update that invalidates any previous metadata for that player so clear it out and alert any listeners if this represents a change . This does not affect the hot cues ; they will stick around until the player loads a new track that overwrites one or more of them .
150,824
private void clearMetadata ( DeviceAnnouncement announcement ) { final int player = announcement . getNumber ( ) ; for ( DeckReference deck : new HashSet < DeckReference > ( hotCache . keySet ( ) ) ) { if ( deck . player == player ) { hotCache . remove ( deck ) ; if ( deck . hotCue == 0 ) { deliverTrackMetadataUpdate (...
We have received notification that a device is no longer on the network so clear out its metadata .
150,825
private void updateMetadata ( CdjStatus update , TrackMetadata data ) { hotCache . put ( DeckReference . getDeckReference ( update . getDeviceNumber ( ) , 0 ) , data ) ; if ( data . getCueList ( ) != null ) { for ( CueList . Entry entry : data . getCueList ( ) . entries ) { if ( entry . hotCueNumber != 0 ) { hotCache ....
We have obtained metadata for a device so store it and alert any listeners .
150,826
public Map < DeckReference , TrackMetadata > getLoadedTracks ( ) { ensureRunning ( ) ; return Collections . unmodifiableMap ( new HashMap < DeckReference , TrackMetadata > ( hotCache ) ) ; }
Get the metadata of all tracks currently loaded in any player either on the play deck or in a hot cue .
150,827
public void attachMetadataCache ( SlotReference slot , File file ) throws IOException { ensureRunning ( ) ; if ( slot . player < 1 || slot . player > 4 || DeviceFinder . getInstance ( ) . getLatestAnnouncementFrom ( slot . player ) == null ) { throw new IllegalArgumentException ( "unable to attach metadata cache for pl...
Attach a metadata cache file to a particular player media slot so the cache will be used instead of querying the player for metadata . This supports operation with metadata during shows where DJs are using all four player numbers and heavily cross - linking between them .
150,828
void attachMetadataCacheInternal ( SlotReference slot , MetadataCache cache ) { MetadataCache oldCache = metadataCacheFiles . put ( slot , cache ) ; if ( oldCache != null ) { try { oldCache . close ( ) ; } catch ( IOException e ) { logger . error ( "Problem closing previous metadata cache" , e ) ; } } deliverCacheUpdat...
Finishes the process of attaching a metadata cache file once it has been opened and validated .
150,829
public void detachMetadataCache ( SlotReference slot ) { MetadataCache oldCache = metadataCacheFiles . remove ( slot ) ; if ( oldCache != null ) { try { oldCache . close ( ) ; } catch ( IOException e ) { logger . error ( "Problem closing metadata cache" , e ) ; } deliverCacheUpdate ( slot , null ) ; } }
Removes any metadata cache file that might have been assigned to a particular player media slot so metadata will be looked up from the player itself .
150,830
public List < File > getAutoAttachCacheFiles ( ) { ArrayList < File > currentFiles = new ArrayList < File > ( autoAttachCacheFiles ) ; Collections . sort ( currentFiles , new Comparator < File > ( ) { public int compare ( File o1 , File o2 ) { return o1 . getName ( ) . compareTo ( o2 . getName ( ) ) ; } } ) ; return Co...
Get the metadata cache files that are currently configured to be automatically attached when matching media is mounted in a player on the network .
150,831
private void flushHotCacheSlot ( SlotReference slot ) { for ( Map . Entry < DeckReference , TrackMetadata > entry : new HashMap < DeckReference , TrackMetadata > ( hotCache ) . entrySet ( ) ) { if ( slot == SlotReference . getSlotReference ( entry . getValue ( ) . trackReference ) ) { logger . debug ( "Evicting cached ...
Discards any tracks from the hot cache that were loaded from a now - unmounted media slot because they are no longer valid .
150,832
private void recordMount ( SlotReference slot ) { if ( mediaMounts . add ( slot ) ) { deliverMountUpdate ( slot , true ) ; } if ( ! mediaDetails . containsKey ( slot ) ) { try { VirtualCdj . getInstance ( ) . sendMediaQuery ( slot ) ; } catch ( Exception e ) { logger . warn ( "Problem trying to request media details fo...
Records that there is media mounted in a particular media player slot updating listeners if this is a change . Also send a query to the player requesting details about the media mounted in that slot if we don t already have that information .
150,833
private void removeMount ( SlotReference slot ) { mediaDetails . remove ( slot ) ; if ( mediaMounts . remove ( slot ) ) { deliverMountUpdate ( slot , false ) ; } }
Records that there is no media mounted in a particular media player slot updating listeners if this is a change and clearing any affected items from our in - memory caches .
150,834
private void deliverMountUpdate ( SlotReference slot , boolean mounted ) { if ( mounted ) { logger . info ( "Reporting media mounted in " + slot ) ; } else { logger . info ( "Reporting media removed from " + slot ) ; } for ( final MountListener listener : getMountListeners ( ) ) { try { if ( mounted ) { listener . medi...
Send a mount update announcement to all registered listeners and see if we can auto - attach a media cache file .
150,835
private void deliverCacheUpdate ( SlotReference slot , MetadataCache cache ) { for ( final MetadataCacheListener listener : getCacheListeners ( ) ) { try { if ( cache == null ) { listener . cacheDetached ( slot ) ; } else { listener . cacheAttached ( slot , cache ) ; } } catch ( Throwable t ) { logger . warn ( "Problem...
Send a metadata cache update announcement to all registered listeners .
150,836
private void deliverTrackMetadataUpdate ( int player , TrackMetadata metadata ) { if ( ! getTrackMetadataListeners ( ) . isEmpty ( ) ) { final TrackMetadataUpdate update = new TrackMetadataUpdate ( player , metadata ) ; for ( final TrackMetadataListener listener : getTrackMetadataListeners ( ) ) { try { listener . meta...
Send a track metadata update announcement to all registered listeners .
150,837
private void addMetadataProviderForMedia ( String key , MetadataProvider provider ) { if ( ! metadataProviders . containsKey ( key ) ) { metadataProviders . put ( key , Collections . newSetFromMap ( new ConcurrentHashMap < MetadataProvider , Boolean > ( ) ) ) ; } Set < MetadataProvider > providers = metadataProviders ....
Internal method that adds a metadata provider to the set associated with a particular hash key creating the set if needed .
150,838
public void removeMetadataProvider ( MetadataProvider provider ) { for ( Set < MetadataProvider > providers : metadataProviders . values ( ) ) { providers . remove ( provider ) ; } }
Removes a metadata provider so it will no longer be consulted to provide metadata for tracks loaded from any media .
150,839
public Set < MetadataProvider > getMetadataProviders ( MediaDetails sourceMedia ) { String key = ( sourceMedia == null ) ? "" : sourceMedia . hashKey ( ) ; Set < MetadataProvider > result = metadataProviders . get ( key ) ; if ( result == null ) { return Collections . emptySet ( ) ; } return Collections . unmodifiableS...
Get the set of metadata providers that can offer metadata for tracks loaded from the specified media .
150,840
private void handleUpdate ( final CdjStatus update ) { if ( update . isLocalUsbEmpty ( ) ) { final SlotReference slot = SlotReference . getSlotReference ( update . getDeviceNumber ( ) , CdjStatus . TrackSourceSlot . USB_SLOT ) ; detachMetadataCache ( slot ) ; flushHotCacheSlot ( slot ) ; removeMount ( slot ) ; } else i...
Process an update packet from one of the CDJs . See if it has a valid track loaded ; if not clear any metadata we had stored for that player . If so see if it is the same track we already know about ; if not request the metadata associated with that track .
150,841
private int getColorWaveformBits ( final ByteBuffer waveBytes , final int segment ) { final int base = ( segment * 2 ) ; final int big = Util . unsign ( waveBytes . get ( base ) ) ; final int small = Util . unsign ( waveBytes . get ( base + 1 ) ) ; return big * 256 + small ; }
Color waveforms are represented by a series of sixteen bit integers into which color and height information are packed . This function returns the integer corresponding to a particular half - frame in the waveform .
150,842
private static void addCacheFormatEntry ( List < Message > trackListEntries , int playlistId , ZipOutputStream zos ) throws IOException { zos . putNextEntry ( new ZipEntry ( CACHE_FORMAT_ENTRY ) ) ; String formatEntry = CACHE_FORMAT_IDENTIFIER + ":" + playlistId + ":" + trackListEntries . size ( ) ; zos . write ( forma...
Add a marker so we can recognize this as a metadata archive . I would use the ZipFile comment but that is not available until Java 7 and Beat Link is supposed to be backwards compatible with Java 6 . Since we are doing this anyway we can also provide information about the nature of the cache and how many metadata entri...
150,843
private static void addCacheDetailsEntry ( SlotReference slot , ZipOutputStream zos , WritableByteChannel channel ) throws IOException { MediaDetails details = MetadataFinder . getInstance ( ) . getMediaDetailsFor ( slot ) ; if ( details != null ) { zos . putNextEntry ( new ZipEntry ( CACHE_DETAILS_ENTRY ) ) ; Util . w...
Record the details of the media being cached to make it easier to recognize now that we have access to that information .
150,844
private String getCacheFormatEntry ( ) throws IOException { ZipEntry zipEntry = zipFile . getEntry ( CACHE_FORMAT_ENTRY ) ; InputStream is = zipFile . getInputStream ( zipEntry ) ; try { Scanner s = new Scanner ( is , "UTF-8" ) . useDelimiter ( "\\A" ) ; String tag = null ; if ( s . hasNext ( ) ) tag = s . next ( ) ; r...
Find and read the cache format entry in a metadata cache file .
150,845
public List < Integer > getTrackIds ( ) { ArrayList < Integer > results = new ArrayList < Integer > ( trackCount ) ; Enumeration < ? extends ZipEntry > entries = zipFile . entries ( ) ; while ( entries . hasMoreElements ( ) ) { ZipEntry entry = entries . nextElement ( ) ; if ( entry . getName ( ) . startsWith ( CACHE_M...
Returns a list of the rekordbox IDs of the tracks contained in the cache .
150,846
public static void createMetadataCache ( SlotReference slot , int playlistId , File cache ) throws Exception { createMetadataCache ( slot , playlistId , cache , null ) ; }
Creates a metadata cache archive file of all tracks in the specified slot on the specified player . Any previous contents of the specified file will be replaced .
150,847
static void tryAutoAttaching ( final SlotReference slot ) { if ( ! MetadataFinder . getInstance ( ) . getMountedMediaSlots ( ) . contains ( slot ) ) { logger . error ( "Unable to auto-attach cache to empty slot {}" , slot ) ; return ; } if ( MetadataFinder . getInstance ( ) . getMetadataCache ( slot ) != null ) { logge...
See if there is an auto - attach cache file that seems to match the media in the specified slot and if so attach it .
150,848
private static Map < Integer , LinkedList < MetadataCache > > gatherCandidateAttachmentGroups ( ) { Map < Integer , LinkedList < MetadataCache > > candidateGroups = new TreeMap < Integer , LinkedList < MetadataCache > > ( ) ; final Iterator < File > iterator = MetadataFinder . getInstance ( ) . getAutoAttachCacheFiles ...
Groups all of the metadata cache files that are candidates for auto - attachment to player slots into lists that are keyed by the playlist ID used to create the cache file . Files that cache all tracks have a playlist ID of 0 .
150,849
private static int findTrackIdAtOffset ( SlotReference slot , Client client , int offset ) throws IOException { Message entry = client . renderMenuItems ( Message . MenuIdentifier . MAIN_MENU , slot . slot , CdjStatus . TrackType . REKORDBOX , offset , 1 ) . get ( 0 ) ; if ( entry . getMenuItemType ( ) == Message . Men...
As part of checking whether a metadata cache can be auto - mounted for a particular media slot this method looks up the track at the specified offset within the player s track list and returns its rekordbox ID .
150,850
private boolean isPacketLongEnough ( DatagramPacket packet , int expectedLength , String name ) { final int length = packet . getLength ( ) ; if ( length < expectedLength ) { logger . warn ( "Ignoring too-short " + name + " packet; expecting " + expectedLength + " bytes and got " + length + "." ) ; return false ; } if ...
Helper method to check that we got the right size packet .
150,851
public synchronized void stop ( ) { if ( isRunning ( ) ) { socket . get ( ) . close ( ) ; socket . set ( null ) ; deliverLifecycleAnnouncement ( logger , false ) ; } }
Stop listening for beats .
150,852
private void deliverSyncCommand ( byte command ) { for ( final SyncListener listener : getSyncListeners ( ) ) { try { switch ( command ) { case 0x01 : listener . becomeMaster ( ) ; case 0x10 : listener . setSyncMode ( true ) ; break ; case 0x20 : listener . setSyncMode ( false ) ; break ; } } catch ( Throwable t ) { lo...
Send a sync command to all registered listeners .
150,853
private void deliverMasterYieldCommand ( int toPlayer ) { for ( final MasterHandoffListener listener : getMasterHandoffListeners ( ) ) { try { listener . yieldMasterTo ( toPlayer ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering master yield command to listener" , t ) ; } } }
Send a master handoff yield command to all registered listeners .
150,854
private void deliverMasterYieldResponse ( int fromPlayer , boolean yielded ) { for ( final MasterHandoffListener listener : getMasterHandoffListeners ( ) ) { try { listener . yieldResponse ( fromPlayer , yielded ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering master yield response to listener" , t ) ;...
Send a master handoff yield response to all registered listeners .
150,855
private void deliverOnAirUpdate ( Set < Integer > audibleChannels ) { for ( final OnAirListener listener : getOnAirListeners ( ) ) { try { listener . channelsOnAir ( audibleChannels ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering channels on-air update to listener" , t ) ; } } }
Send a channels on - air update to all registered listeners .
150,856
private void deliverFaderStartCommand ( Set < Integer > playersToStart , Set < Integer > playersToStop ) { for ( final FaderStartListener listener : getFaderStartListeners ( ) ) { try { listener . fadersChanged ( playersToStart , playersToStop ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering fader star...
Send a fader start command to all registered listeners .
150,857
public void write ( WritableByteChannel channel ) throws IOException { logger . debug ( "Writing> {}" , this ) ; for ( Field field : fields ) { field . write ( channel ) ; } }
Writes the message to the specified channel for example when creating metadata cache files .
150,858
public final void setFindDetails ( boolean findDetails ) { this . findDetails . set ( findDetails ) ; if ( findDetails ) { primeCache ( ) ; } else { final Set < DeckReference > dyingCache = new HashSet < DeckReference > ( detailHotCache . keySet ( ) ) ; detailHotCache . clear ( ) ; SwingUtilities . invokeLater ( new Ru...
Set whether we should retrieve the waveform details in addition to the waveform previews .
150,859
public final void setColorPreferred ( boolean preferColor ) { if ( this . preferColor . compareAndSet ( ! preferColor , preferColor ) && isRunning ( ) ) { stop ( ) ; try { start ( ) ; } catch ( Exception e ) { logger . error ( "Unexplained exception restarting; we had been running already!" , e ) ; } } }
Set whether we should obtain color versions of waveforms and previews when they are available . This will only affect waveforms loaded after the setting has been changed . If this changes the setting and we were running stop and restart in order to flush and reload the correct waveform versions .
150,860
private void clearDeckPreview ( TrackMetadataUpdate update ) { if ( previewHotCache . remove ( DeckReference . getDeckReference ( update . player , 0 ) ) != null ) { deliverWaveformPreviewUpdate ( update . player , null ) ; } }
We have received an update that invalidates the waveform preview for a player so clear it and alert any listeners if this represents a change . This does not affect the hot cues ; they will stick around until the player loads a new track that overwrites one or more of them .
150,861
private void clearDeckDetail ( TrackMetadataUpdate update ) { if ( detailHotCache . remove ( DeckReference . getDeckReference ( update . player , 0 ) ) != null ) { deliverWaveformDetailUpdate ( update . player , null ) ; } }
We have received an update that invalidates the waveform detail for a player so clear it and alert any listeners if this represents a change . This does not affect the hot cues ; they will stick around until the player loads a new track that overwrites one or more of them .
150,862
private void clearWaveforms ( DeviceAnnouncement announcement ) { final int player = announcement . getNumber ( ) ; for ( DeckReference deck : new HashSet < DeckReference > ( previewHotCache . keySet ( ) ) ) { if ( deck . player == player ) { previewHotCache . remove ( deck ) ; if ( deck . hotCue == 0 ) { deliverWavefo...
We have received notification that a device is no longer on the network so clear out all its waveforms .
150,863
private void updatePreview ( TrackMetadataUpdate update , WaveformPreview preview ) { previewHotCache . put ( DeckReference . getDeckReference ( update . player , 0 ) , preview ) ; if ( update . metadata . getCueList ( ) != null ) { for ( CueList . Entry entry : update . metadata . getCueList ( ) . entries ) { if ( ent...
We have obtained a waveform preview for a device so store it and alert any listeners .
150,864
private void updateDetail ( TrackMetadataUpdate update , WaveformDetail detail ) { detailHotCache . put ( DeckReference . getDeckReference ( update . player , 0 ) , detail ) ; if ( update . metadata . getCueList ( ) != null ) { for ( CueList . Entry entry : update . metadata . getCueList ( ) . entries ) { if ( entry . ...
We have obtained waveform detail for a device so store it and alert any listeners .
150,865
@ SuppressWarnings ( "WeakerAccess" ) public Map < DeckReference , WaveformPreview > getLoadedPreviews ( ) { ensureRunning ( ) ; return Collections . unmodifiableMap ( new HashMap < DeckReference , WaveformPreview > ( previewHotCache ) ) ; }
Get the waveform previews available for all tracks currently loaded in any player either on the play deck or in a hot cue .
150,866
@ SuppressWarnings ( "WeakerAccess" ) public Map < DeckReference , WaveformDetail > getLoadedDetails ( ) { ensureRunning ( ) ; if ( ! isFindingDetails ( ) ) { throw new IllegalStateException ( "WaveformFinder is not configured to find waveform details." ) ; } return Collections . unmodifiableMap ( new HashMap < DeckRef...
Get the waveform details available for all tracks currently loaded in any player either on the play deck or in a hot cue .
150,867
private WaveformPreview requestPreviewInternal ( final DataReference trackReference , final boolean failIfPassive ) { MetadataCache cache = MetadataFinder . getInstance ( ) . getMetadataCache ( SlotReference . getSlotReference ( trackReference ) ) ; if ( cache != null ) { return cache . getWaveformPreview ( null , trac...
Ask the specified player for the waveform preview in the specified slot with the specified rekordbox ID using cached media instead if it is available and possibly giving up if we are in passive mode .
150,868
public WaveformPreview requestWaveformPreviewFrom ( final DataReference dataReference ) { ensureRunning ( ) ; for ( WaveformPreview cached : previewHotCache . values ( ) ) { if ( cached . dataReference . equals ( dataReference ) ) { return cached ; } } return requestPreviewInternal ( dataReference , false ) ; }
Ask the specified player for the specified waveform preview from the specified media slot first checking if we have a cached copy .
150,869
WaveformPreview getWaveformPreview ( int rekordboxId , SlotReference slot , Client client ) throws IOException { final NumberField idField = new NumberField ( rekordboxId ) ; if ( preferColor . get ( ) ) { try { Message response = client . simpleRequest ( Message . KnownType . ANLZ_TAG_REQ , Message . KnownType . ANLZ_...
Requests the waveform preview for a specific track ID given a connection to a player that has already been set up .
150,870
public WaveformDetail requestWaveformDetailFrom ( final DataReference dataReference ) { ensureRunning ( ) ; for ( WaveformDetail cached : detailHotCache . values ( ) ) { if ( cached . dataReference . equals ( dataReference ) ) { return cached ; } } return requestDetailInternal ( dataReference , false ) ; }
Ask the specified player for the specified waveform detail from the specified media slot first checking if we have a cached copy .
150,871
WaveformDetail getWaveformDetail ( int rekordboxId , SlotReference slot , Client client ) throws IOException { final NumberField idField = new NumberField ( rekordboxId ) ; if ( preferColor . get ( ) ) { try { Message response = client . simpleRequest ( Message . KnownType . ANLZ_TAG_REQ , Message . KnownType . ANLZ_TA...
Requests the waveform detail for a specific track ID given a connection to a player that has already been set up .
150,872
private void deliverWaveformPreviewUpdate ( final int player , final WaveformPreview preview ) { final Set < WaveformListener > listeners = getWaveformListeners ( ) ; if ( ! listeners . isEmpty ( ) ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { final WaveformPreviewUpdate update = new Wavef...
Send a waveform preview update announcement to all registered listeners .
150,873
private void deliverWaveformDetailUpdate ( final int player , final WaveformDetail detail ) { if ( ! getWaveformListeners ( ) . isEmpty ( ) ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { final WaveformDetailUpdate update = new WaveformDetailUpdate ( player , detail ) ; for ( final WaveformL...
Send a waveform detail update announcement to all registered listeners .
150,874
private void primeCache ( ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { for ( Map . Entry < DeckReference , TrackMetadata > entry : MetadataFinder . getInstance ( ) . getLoadedTracks ( ) . entrySet ( ) ) { if ( entry . getKey ( ) . hotCue == 0 ) { handleUpdate ( new TrackMetadataUpdate ( e...
Send ourselves updates about any tracks that were loaded before we started or before we were requesting details since we missed them .
150,875
@ SuppressWarnings ( "WeakerAccess" ) public synchronized void stop ( ) { if ( isRunning ( ) ) { MetadataFinder . getInstance ( ) . removeTrackMetadataListener ( metadataListener ) ; running . set ( false ) ; pendingUpdates . clear ( ) ; queueHandler . interrupt ( ) ; queueHandler = null ; final Set < DeckReference > d...
Stop finding waveforms for all active players .
150,876
private void clearArt ( DeviceAnnouncement announcement ) { final int player = announcement . getNumber ( ) ; for ( DeckReference deck : new HashSet < DeckReference > ( hotCache . keySet ( ) ) ) { if ( deck . player == player ) { hotCache . remove ( deck ) ; if ( deck . hotCue == 0 ) { deliverAlbumArtUpdate ( player , ...
We have received notification that a device is no longer on the network so clear out its artwork .
150,877
private void updateArt ( TrackMetadataUpdate update , AlbumArt art ) { hotCache . put ( DeckReference . getDeckReference ( update . player , 0 ) , art ) ; if ( update . metadata . getCueList ( ) != null ) { for ( CueList . Entry entry : update . metadata . getCueList ( ) . entries ) { if ( entry . hotCueNumber != 0 ) {...
We have obtained album art for a device so store it and alert any listeners .
150,878
public Map < DeckReference , AlbumArt > getLoadedArt ( ) { ensureRunning ( ) ; return Collections . unmodifiableMap ( new HashMap < DeckReference , AlbumArt > ( hotCache ) ) ; }
Get the art available for all tracks currently loaded in any player either on the play deck or in a hot cue .
150,879
private AlbumArt requestArtworkInternal ( final DataReference artReference , final CdjStatus . TrackType trackType , final boolean failIfPassive ) { MetadataCache cache = MetadataFinder . getInstance ( ) . getMetadataCache ( SlotReference . getSlotReference ( artReference ) ) ; if ( cache != null ) { final AlbumArt res...
Ask the specified player for the album art in the specified slot with the specified rekordbox ID using cached media instead if it is available and possibly giving up if we are in passive mode .
150,880
public AlbumArt requestArtworkFrom ( final DataReference artReference , final CdjStatus . TrackType trackType ) { ensureRunning ( ) ; AlbumArt artwork = findArtInMemoryCaches ( artReference ) ; if ( artwork == null ) { artwork = requestArtworkInternal ( artReference , trackType , false ) ; } return artwork ; }
Ask the specified player for the specified artwork from the specified media slot first checking if we have a cached copy .
150,881
AlbumArt getArtwork ( int artworkId , SlotReference slot , CdjStatus . TrackType trackType , Client client ) throws IOException { Message response = client . simpleRequest ( Message . KnownType . ALBUM_ART_REQ , Message . KnownType . ALBUM_ART , client . buildRMST ( Message . MenuIdentifier . DATA , slot . slot , track...
Request the artwork with a particular artwork ID given a connection to a player that has already been set up .
150,882
private AlbumArt findArtInMemoryCaches ( DataReference artReference ) { for ( AlbumArt cached : hotCache . values ( ) ) { if ( cached . artReference . equals ( artReference ) ) { return cached ; } } return artCache . get ( artReference ) ; }
Look for the specified album art in both the hot cache of loaded tracks and the longer - lived LRU cache .
150,883
private void deliverAlbumArtUpdate ( int player , AlbumArt art ) { if ( ! getAlbumArtListeners ( ) . isEmpty ( ) ) { final AlbumArtUpdate update = new AlbumArtUpdate ( player , art ) ; for ( final AlbumArtListener listener : getAlbumArtListeners ( ) ) { try { listener . albumArtChanged ( update ) ; } catch ( Throwable ...
Send an album art update announcement to all registered listeners .
150,884
public BufferedImage getImage ( ) { ByteBuffer artwork = getRawBytes ( ) ; artwork . rewind ( ) ; byte [ ] imageBytes = new byte [ artwork . remaining ( ) ] ; artwork . get ( imageBytes ) ; try { return ImageIO . read ( new ByteArrayInputStream ( imageBytes ) ) ; } catch ( IOException e ) { logger . error ( "Weird! Cau...
Given the byte buffer containing album art build an actual image from it for easy rendering .
150,885
private TrackSourceSlot findTrackSourceSlot ( ) { TrackSourceSlot result = TRACK_SOURCE_SLOT_MAP . get ( packetBytes [ 41 ] ) ; if ( result == null ) { return TrackSourceSlot . UNKNOWN ; } return result ; }
Determine the enum value corresponding to the track source slot found in the packet .
150,886
private TrackType findTrackType ( ) { TrackType result = TRACK_TYPE_MAP . get ( packetBytes [ 42 ] ) ; if ( result == null ) { return TrackType . UNKNOWN ; } return result ; }
Determine the enum value corresponding to the track type found in the packet .
150,887
private PlayState1 findPlayState1 ( ) { PlayState1 result = PLAY_STATE_1_MAP . get ( packetBytes [ 123 ] ) ; if ( result == null ) { return PlayState1 . UNKNOWN ; } return result ; }
Determine the enum value corresponding to the first play state found in the packet .
150,888
private PlayState3 findPlayState3 ( ) { PlayState3 result = PLAY_STATE_3_MAP . get ( packetBytes [ 157 ] ) ; if ( result == null ) { return PlayState3 . UNKNOWN ; } return result ; }
Determine the enum value corresponding to the third play state found in the packet .
150,889
@ SuppressWarnings ( "WeakerAccess" ) public boolean isPlaying ( ) { if ( packetBytes . length >= 212 ) { return ( packetBytes [ STATUS_FLAGS ] & PLAYING_FLAG ) > 0 ; } else { final PlayState1 state = getPlayState1 ( ) ; return state == PlayState1 . PLAYING || state == PlayState1 . LOOPING || ( state == PlayState1 . SE...
Was the CDJ playing a track when this update was sent?
150,890
@ SuppressWarnings ( "WeakerAccess" ) public String formatCueCountdown ( ) { int count = getCueCountdown ( ) ; if ( count == 511 ) { return "--.-" ; } if ( ( count >= 1 ) && ( count <= 256 ) ) { int bars = ( count - 1 ) / 4 ; int beats = ( ( count - 1 ) % 4 ) + 1 ; return String . format ( "%02d.%d" , bars , beats ) ; ...
Format a cue countdown indicator in the same way as the CDJ would at this point in the track .
150,891
private void clearDeck ( TrackMetadataUpdate update ) { if ( hotCache . remove ( DeckReference . getDeckReference ( update . player , 0 ) ) != null ) { deliverBeatGridUpdate ( update . player , null ) ; } }
We have received an update that invalidates the beat grid for a player so clear it and alert any listeners if this represents a change . This does not affect the hot cues ; they will stick around until the player loads a new track that overwrites one or more of them .
150,892
private void clearBeatGrids ( DeviceAnnouncement announcement ) { final int player = announcement . getNumber ( ) ; for ( DeckReference deck : new HashSet < DeckReference > ( hotCache . keySet ( ) ) ) { if ( deck . player == player ) { hotCache . remove ( deck ) ; if ( deck . hotCue == 0 ) { deliverBeatGridUpdate ( pla...
We have received notification that a device is no longer on the network so clear out all its beat grids .
150,893
private void updateBeatGrid ( TrackMetadataUpdate update , BeatGrid beatGrid ) { hotCache . put ( DeckReference . getDeckReference ( update . player , 0 ) , beatGrid ) ; if ( update . metadata . getCueList ( ) != null ) { for ( CueList . Entry entry : update . metadata . getCueList ( ) . entries ) { if ( entry . hotCue...
We have obtained a beat grid for a device so store it and alert any listeners .
150,894
@ SuppressWarnings ( "WeakerAccess" ) public Map < DeckReference , BeatGrid > getLoadedBeatGrids ( ) { ensureRunning ( ) ; return Collections . unmodifiableMap ( new HashMap < DeckReference , BeatGrid > ( hotCache ) ) ; }
Get the beat grids available for all tracks currently loaded in any player either on the play deck or in a hot cue .
150,895
public BeatGrid requestBeatGridFrom ( final DataReference track ) { for ( BeatGrid cached : hotCache . values ( ) ) { if ( cached . dataReference . equals ( track ) ) { return cached ; } } return requestBeatGridInternal ( track , false ) ; }
Ask the specified player for the beat grid of the track in the specified slot with the specified rekordbox ID first checking if we have a cache we can use instead .
150,896
BeatGrid getBeatGrid ( int rekordboxId , SlotReference slot , Client client ) throws IOException { Message response = client . simpleRequest ( Message . KnownType . BEAT_GRID_REQ , null , client . buildRMST ( Message . MenuIdentifier . DATA , slot . slot ) , new NumberField ( rekordboxId ) ) ; if ( response . knownType...
Requests the beat grid for a specific track ID given a connection to a player that has already been set up .
150,897
private void deliverBeatGridUpdate ( int player , BeatGrid beatGrid ) { if ( ! getBeatGridListeners ( ) . isEmpty ( ) ) { final BeatGridUpdate update = new BeatGridUpdate ( player , beatGrid ) ; for ( final BeatGridListener listener : getBeatGridListeners ( ) ) { try { listener . beatGridChanged ( update ) ; } catch ( ...
Send a beat grid update announcement to all registered listeners .
150,898
@ SuppressWarnings ( "WeakerAccess" ) public synchronized void stop ( ) { if ( isRunning ( ) ) { MetadataFinder . getInstance ( ) . removeTrackMetadataListener ( metadataListener ) ; running . set ( false ) ; pendingUpdates . clear ( ) ; queueHandler . interrupt ( ) ; queueHandler = null ; final Set < DeckReference > d...
Stop finding beat grids for all active players .
150,899
private long interpolateTimeSinceUpdate ( TrackPositionUpdate update , long currentTimestamp ) { if ( ! update . playing ) { return update . milliseconds ; } long elapsedMillis = ( currentTimestamp - update . timestamp ) / 1000000 ; long moved = Math . round ( update . pitch * elapsedMillis ) ; if ( update . reverse ) ...
Figure out based on how much time has elapsed since we received an update and the playback position speed and direction at the time of that update where the player will be now .