idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
150,900
private long interpolateTimeFromUpdate ( TrackPositionUpdate lastTrackUpdate , CdjStatus newDeviceUpdate , BeatGrid beatGrid ) { final int beatNumber = newDeviceUpdate . getBeatNumber ( ) ; final boolean noLongerPlaying = ! newDeviceUpdate . isPlaying ( ) ; if ( lastTrackUpdate . playing && noLongerPlaying ) { final Cu...
Sanity - check a new non - beat update make sure we are still interpolating a sensible position and correct as needed .
150,901
public long getTimeFor ( int player ) { TrackPositionUpdate update = positions . get ( player ) ; if ( update != null ) { return interpolateTimeSinceUpdate ( update , System . nanoTime ( ) ) ; } return - 1 ; }
Get the best guess we have for the current track position on the specified player .
150,902
private boolean interpolationsDisagree ( TrackPositionUpdate lastUpdate , TrackPositionUpdate currentUpdate ) { long now = System . nanoTime ( ) ; return Math . abs ( interpolateTimeSinceUpdate ( lastUpdate , now ) - interpolateTimeSinceUpdate ( currentUpdate , now ) ) > slack . get ( ) ; }
Check whether we have diverged from what we would predict from the last update that was sent to a particular track position listener .
150,903
@ SuppressWarnings ( "WeakerAccess" ) public synchronized void stop ( ) { if ( isRunning ( ) ) { BeatFinder . getInstance ( ) . removeBeatListener ( beatListener ) ; VirtualCdj . getInstance ( ) . removeUpdateListener ( updateListener ) ; running . set ( false ) ; positions . clear ( ) ; updates . clear ( ) ; deliverLi...
Stop interpolating playback position for all active players .
150,904
public static synchronized DeckReference getDeckReference ( int player , int hotCue ) { Map < Integer , DeckReference > playerMap = instances . get ( player ) ; if ( playerMap == null ) { playerMap = new HashMap < Integer , DeckReference > ( ) ; instances . put ( player , playerMap ) ; } DeckReference result = playerMa...
Get a unique reference to a place where a track is currently loaded in a player .
150,905
public synchronized void setDeviceName ( String name ) { if ( name . getBytes ( ) . length > DEVICE_NAME_LENGTH ) { throw new IllegalArgumentException ( "name cannot be more than " + DEVICE_NAME_LENGTH + " bytes long" ) ; } Arrays . fill ( announcementBytes , DEVICE_NAME_OFFSET , DEVICE_NAME_LENGTH , ( byte ) 0 ) ; Sys...
Set the name to be used in announcing our presence on the network . The name can be no longer than twenty bytes and should be normal ASCII no Unicode .
150,906
private void setTempoMaster ( DeviceUpdate newMaster ) { DeviceUpdate oldMaster = tempoMaster . getAndSet ( newMaster ) ; if ( ( newMaster == null && oldMaster != null ) || ( newMaster != null && ( ( oldMaster == null ) || ! newMaster . getAddress ( ) . equals ( oldMaster . getAddress ( ) ) ) ) ) { deliverMasterChanged...
Establish a new tempo master and if it is a change from the existing one report it to the listeners .
150,907
private void setMasterTempo ( double newTempo ) { double oldTempo = Double . longBitsToDouble ( masterTempo . getAndSet ( Double . doubleToLongBits ( newTempo ) ) ) ; if ( ( getTempoMaster ( ) != null ) && ( Math . abs ( newTempo - oldTempo ) > getTempoEpsilon ( ) ) ) { if ( isSynced ( ) ) { metronome . setTempo ( newT...
Establish a new master tempo and if it is a change from the existing one report it to the listeners .
150,908
private void processUpdate ( DeviceUpdate update ) { updates . put ( update . getAddress ( ) , update ) ; if ( update instanceof CdjStatus ) { int syncNumber = ( ( CdjStatus ) update ) . getSyncNumber ( ) ; if ( syncNumber > this . largestSyncCounter . get ( ) ) { this . largestSyncCounter . set ( syncNumber ) ; } } if...
Process a device update once it has been received . Track it as the most recent update from its address and notify any registered listeners including master listeners if it results in changes to tracked state such as the current master player and tempo . Also handles the Baroque dance of handing off the tempo master ro...
150,909
void processBeat ( Beat beat ) { if ( isRunning ( ) && beat . isTempoMaster ( ) ) { setMasterTempo ( beat . getEffectiveTempo ( ) ) ; deliverBeatAnnouncement ( beat ) ; } }
Process a beat packet potentially updating the master tempo and sending our listeners a master beat notification . Does nothing if we are not active .
150,910
private InterfaceAddress findMatchingAddress ( DeviceAnnouncement aDevice , NetworkInterface networkInterface ) { for ( InterfaceAddress address : networkInterface . getInterfaceAddresses ( ) ) { if ( ( address . getBroadcast ( ) != null ) && Util . sameNetwork ( address . getNetworkPrefixLength ( ) , aDevice . getAddr...
Scan a network interface to find if it has an address space which matches the device we are trying to reach . If so return the address specification .
150,911
public Set < DeviceAnnouncement > findUnreachablePlayers ( ) { ensureRunning ( ) ; Set < DeviceAnnouncement > result = new HashSet < DeviceAnnouncement > ( ) ; for ( DeviceAnnouncement candidate : DeviceFinder . getInstance ( ) . getCurrentDevices ( ) ) { if ( ! Util . sameNetwork ( matchedAddress . getNetworkPrefixLen...
Checks if we can see any players that are on a different network than the one we chose for the Virtual CDJ . If so we are not going to be able to communicate with them and they should all be moved onto a single network .
150,912
public synchronized void stop ( ) { if ( isRunning ( ) ) { try { setSendingStatus ( false ) ; } catch ( Throwable t ) { logger . error ( "Problem stopping sending status during shutdown" , t ) ; } DeviceFinder . getInstance ( ) . removeIgnoredAddress ( socket . get ( ) . getLocalAddress ( ) ) ; socket . get ( ) . close...
Stop announcing ourselves and listening for status updates .
150,913
private void sendAnnouncement ( InetAddress broadcastAddress ) { try { DatagramPacket announcement = new DatagramPacket ( announcementBytes , announcementBytes . length , broadcastAddress , DeviceFinder . ANNOUNCEMENT_PORT ) ; socket . get ( ) . send ( announcement ) ; Thread . sleep ( getAnnounceInterval ( ) ) ; } cat...
Send an announcement packet so the other devices see us as being part of the DJ Link network and send us updates .
150,914
private void deliverMasterChangedAnnouncement ( final DeviceUpdate update ) { for ( final MasterListener listener : getMasterListeners ( ) ) { try { listener . masterChanged ( update ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering master changed announcement to listener" , t ) ; } } }
Send a master changed announcement to all registered master listeners .
150,915
private void deliverTempoChangedAnnouncement ( final double tempo ) { for ( final MasterListener listener : getMasterListeners ( ) ) { try { listener . tempoChanged ( tempo ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering tempo changed announcement to listener" , t ) ; } } }
Send a tempo changed announcement to all registered master listeners .
150,916
private void deliverBeatAnnouncement ( final Beat beat ) { for ( final MasterListener listener : getMasterListeners ( ) ) { try { listener . newBeat ( beat ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering master beat announcement to listener" , t ) ; } } }
Send a beat announcement to all registered master listeners .
150,917
private void deliverDeviceUpdate ( final DeviceUpdate update ) { for ( DeviceUpdateListener listener : getUpdateListeners ( ) ) { try { listener . received ( update ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering device update to listener" , t ) ; } } }
Send a device update to all registered update listeners .
150,918
private void deliverMediaDetailsUpdate ( final MediaDetails details ) { for ( MediaDetailsListener listener : getMediaDetailsListeners ( ) ) { try { listener . detailsAvailable ( details ) ; } catch ( Throwable t ) { logger . warn ( "Problem delivering media details response to listener" , t ) ; } } }
Send a media details response to all registered listeners .
150,919
@ SuppressWarnings ( "SameParameterValue" ) private void assembleAndSendPacket ( Util . PacketType kind , byte [ ] payload , InetAddress destination , int port ) throws IOException { DatagramPacket packet = Util . buildPacket ( kind , ByteBuffer . wrap ( announcementBytes , DEVICE_NAME_OFFSET , DEVICE_NAME_LENGTH ) . a...
Finish the work of building and sending a protocol packet .
150,920
private void sendSyncControlCommand ( DeviceUpdate target , byte command ) throws IOException { ensureRunning ( ) ; byte [ ] payload = new byte [ SYNC_CONTROL_PAYLOAD . length ] ; System . arraycopy ( SYNC_CONTROL_PAYLOAD , 0 , payload , 0 , SYNC_CONTROL_PAYLOAD . length ) ; payload [ 2 ] = getDeviceNumber ( ) ; payloa...
Assemble and send a packet that performs sync control turning a device s sync mode on or off or telling it to become the tempo master .
150,921
public void sendSyncModeCommand ( int deviceNumber , boolean synced ) throws IOException { final DeviceUpdate update = getLatestStatusFor ( deviceNumber ) ; if ( update == null ) { throw new IllegalArgumentException ( "Device " + deviceNumber + " not found on network." ) ; } sendSyncModeCommand ( update , synced ) ; }
Tell a device to turn sync on or off .
150,922
public void appointTempoMaster ( int deviceNumber ) throws IOException { final DeviceUpdate update = getLatestStatusFor ( deviceNumber ) ; if ( update == null ) { throw new IllegalArgumentException ( "Device " + deviceNumber + " not found on network." ) ; } appointTempoMaster ( update ) ; }
Tell a device to become tempo master .
150,923
public void sendFaderStartCommand ( Set < Integer > deviceNumbersToStart , Set < Integer > deviceNumbersToStop ) throws IOException { ensureRunning ( ) ; byte [ ] payload = new byte [ FADER_START_PAYLOAD . length ] ; System . arraycopy ( FADER_START_PAYLOAD , 0 , payload , 0 , FADER_START_PAYLOAD . length ) ; payload [...
Broadcast a packet that tells some players to start playing and others to stop . If a player number is in both sets it will be told to stop . Numbers outside the range 1 to 4 are ignored .
150,924
public void sendLoadTrackCommand ( int targetPlayer , int rekordboxId , int sourcePlayer , CdjStatus . TrackSourceSlot sourceSlot , CdjStatus . TrackType sourceType ) throws IOException { final DeviceUpdate update = getLatestStatusFor ( targetPlayer ) ; if ( update == null ) { throw new IllegalArgumentException ( "Devi...
Send a packet to the target player telling it to load the specified track from the specified source player .
150,925
public void sendLoadTrackCommand ( DeviceUpdate target , int rekordboxId , int sourcePlayer , CdjStatus . TrackSourceSlot sourceSlot , CdjStatus . TrackType sourceType ) throws IOException { ensureRunning ( ) ; byte [ ] payload = new byte [ LOAD_TRACK_PAYLOAD . length ] ; System . arraycopy ( LOAD_TRACK_PAYLOAD , 0 , p...
Send a packet to the target device telling it to load the specified track from the specified source player .
150,926
public synchronized void setSendingStatus ( boolean send ) throws IOException { if ( isSendingStatus ( ) == send ) { return ; } if ( send ) { ensureRunning ( ) ; if ( ( getDeviceNumber ( ) < 1 ) || ( getDeviceNumber ( ) > 4 ) ) { throw new IllegalStateException ( "Can only send status when using a standard player numbe...
Control whether the Virtual CDJ sends status packets to the other players . Most uses of Beat Link will not require this level of activity . However if you want to be able to take over the tempo master role and control the tempo and beat alignment of other players you will need to turn on this feature which also requir...
150,927
public void setPlaying ( boolean playing ) { if ( this . playing . get ( ) == playing ) { return ; } this . playing . set ( playing ) ; if ( playing ) { metronome . jumpToBeat ( whereStopped . get ( ) . getBeat ( ) ) ; if ( isSendingStatus ( ) ) { beatSender . set ( new BeatSender ( metronome ) ) ; } } else { final Bea...
Controls whether we report that we are playing . This will only have an impact when we are sending status and beat packets .
150,928
public synchronized void becomeTempoMaster ( ) throws IOException { logger . debug ( "Trying to become master." ) ; if ( ! isSendingStatus ( ) ) { throw new IllegalStateException ( "Must be sending status updates to become the tempo master." ) ; } final DeviceUpdate currentMaster = getTempoMaster ( ) ; if ( currentMast...
Arrange to become the tempo master . Starts a sequence of interactions with the other players that should end up with us in charge of the group tempo and beat alignment .
150,929
public synchronized void setSynced ( boolean sync ) { if ( synced . get ( ) != sync ) { if ( sync && isSendingStatus ( ) ) { addMasterListener ( ourSyncMasterListener ) ; } else { removeMasterListener ( ourSyncMasterListener ) ; } if ( ! isTempoMaster ( ) && getTempoMaster ( ) != null ) { setTempo ( getMasterTempo ( ) ...
Controls whether we are currently staying in sync with the tempo master . Will only be meaningful if we are sending status packets .
150,930
public synchronized void jumpToBeat ( int beat ) { if ( beat < 1 ) { beat = 1 ; } else { beat = wrapBeat ( beat ) ; } if ( playing . get ( ) ) { metronome . jumpToBeat ( beat ) ; } else { whereStopped . set ( metronome . getSnapshot ( metronome . getTimeOfBeat ( beat ) ) ) ; } }
Moves our current playback position to the specified beat ; this will be reflected in any status and beat packets that we are sending . An incoming value less than one will jump us to the first beat .
150,931
public Set < PlaybackState > getPlaybackState ( ) { Set < PlaybackState > result = new HashSet < PlaybackState > ( playbackStateMap . values ( ) ) ; return Collections . unmodifiableSet ( result ) ; }
Look up all recorded playback state information .
150,932
private void setPlaybackPosition ( long milliseconds ) { PlaybackState oldState = currentSimpleState ( ) ; if ( oldState != null && oldState . position != milliseconds ) { setPlaybackState ( oldState . player , milliseconds , oldState . playing ) ; } }
Set the current playback position . This method can only be used in situations where the component is tied to a single player and therefore always has a single playback position .
150,933
private void setPlaying ( boolean playing ) { PlaybackState oldState = currentSimpleState ( ) ; if ( oldState != null && oldState . playing != playing ) { setPlaybackState ( oldState . player , oldState . position , playing ) ; } }
Set whether the player holding the waveform is playing which changes the indicator color to white from red . This method can only be used in situations where the component is tied to a single player and therefore has a single playback position .
150,934
public synchronized void setMonitoredPlayer ( final int player ) { if ( player < 0 ) { throw new IllegalArgumentException ( "player cannot be negative" ) ; } clearPlaybackState ( ) ; monitoredPlayer . set ( player ) ; if ( player > 0 ) { setPlaybackState ( player , 0 , false ) ; VirtualCdj . getInstance ( ) . addUpdate...
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 .
150,935
public PlaybackState getFurthestPlaybackState ( ) { PlaybackState result = null ; for ( PlaybackState state : playbackStateMap . values ( ) ) { if ( result == null || ( ! result . playing && state . playing ) || ( result . position < state . position ) && ( state . playing || ! result . playing ) ) { result = state ; }...
Look up the playback state that has reached furthest in the track but give playing players priority over stopped players . This is used to choose the scroll center when auto - scrolling is active .
150,936
private int getSegmentForX ( int x ) { if ( autoScroll . get ( ) ) { int playHead = ( x - ( getWidth ( ) / 2 ) ) ; int offset = Util . timeToHalfFrame ( getFurthestPlaybackPosition ( ) ) / scale . get ( ) ; return ( playHead + offset ) * scale . get ( ) ; } return x * scale . get ( ) ; }
Figure out the starting waveform segment that corresponds to the specified coordinate in the window .
150,937
public int getXForBeat ( int beat ) { BeatGrid grid = beatGrid . get ( ) ; if ( grid != null ) { return millisecondsToX ( grid . getTimeWithinTrack ( beat ) ) ; } return 0 ; }
Determine the X coordinate within the component at which the specified beat begins .
150,938
public int millisecondsToX ( long milliseconds ) { if ( autoScroll . get ( ) ) { int playHead = ( getWidth ( ) / 2 ) + 2 ; long offset = milliseconds - getFurthestPlaybackPosition ( ) ; return playHead + ( Util . timeToHalfFrame ( offset ) / scale . get ( ) ) ; } return Util . timeToHalfFrame ( milliseconds ) / scale ....
Converts a time in milliseconds to the appropriate x coordinate for drawing something at that time .
150,939
public static Color cueColor ( CueList . Entry entry ) { if ( entry . hotCueNumber > 0 ) { return Color . GREEN ; } if ( entry . isLoop ) { return Color . ORANGE ; } return Color . RED ; }
Determine the color to use to draw a cue list entry . Hot cues are green ordinary memory points are red and loops are orange .
150,940
public byte [ ] getPacketBytes ( ) { byte [ ] result = new byte [ packetBytes . length ] ; System . arraycopy ( packetBytes , 0 , result , 0 , packetBytes . length ) ; return result ; }
Get the raw data bytes of the device update packet .
150,941
public static DatagramPacket buildPacket ( PacketType type , ByteBuffer deviceName , ByteBuffer payload ) { ByteBuffer content = ByteBuffer . allocate ( 0x1f + payload . remaining ( ) ) ; content . put ( getMagicHeader ( ) ) ; content . put ( type . protocolValue ) ; content . put ( deviceName ) ; content . put ( paylo...
Build a standard - format UDP packet for sending to port 50001 or 50002 in the protocol .
150,942
public static PacketType validateHeader ( DatagramPacket packet , int port ) { byte [ ] data = packet . getData ( ) ; if ( data . length < PACKET_TYPE_OFFSET ) { logger . warn ( "Packet is too short to be a Pro DJ Link packet; must be at least " + PACKET_TYPE_OFFSET + " bytes long, was only " + data . length + "." ) ; ...
Check to see whether a packet starts with the standard header bytes followed by a known byte identifying it . If so return the kind of packet that has been recognized .
150,943
public static long bytesToNumber ( byte [ ] buffer , int start , int length ) { long result = 0 ; for ( int index = start ; index < start + length ; index ++ ) { result = ( result << 8 ) + unsign ( buffer [ index ] ) ; } return result ; }
Reconstructs a number that is represented by more than one byte in a network packet in big - endian order .
150,944
@ SuppressWarnings ( "SameParameterValue" ) public static long bytesToNumberLittleEndian ( byte [ ] buffer , int start , int length ) { long result = 0 ; for ( int index = start + length - 1 ; index >= start ; index -- ) { result = ( result << 8 ) + unsign ( buffer [ index ] ) ; } return result ; }
Reconstructs a number that is represented by more than one byte in a network packet in little - endian order for the very few protocol values that are sent in this quirky way .
150,945
public static void numberToBytes ( int number , byte [ ] buffer , int start , int length ) { for ( int index = start + length - 1 ; index >= start ; index -- ) { buffer [ index ] = ( byte ) ( number & 0xff ) ; number = number >> 8 ; } }
Writes a number to the specified byte array field breaking it into its component bytes in big - endian order . If the number is too large to fit in the specified number of bytes only the low - order bytes are written .
150,946
public static long addressToLong ( InetAddress address ) { long result = 0 ; for ( byte element : address . getAddress ( ) ) { result = ( result << 8 ) + unsign ( element ) ; } return result ; }
Converts the bytes that make up an internet address into the corresponding integer value to make it easier to perform bit - masking operations on them .
150,947
public static boolean sameNetwork ( int prefixLength , InetAddress address1 , InetAddress address2 ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Comparing address " + address1 . getHostAddress ( ) + " with " + address2 . getHostAddress ( ) + ", prefixLength=" + prefixLength ) ; } long prefixMask = 0xffffff...
Checks whether two internet addresses are on the same subnet .
150,948
public static void writeFully ( ByteBuffer buffer , WritableByteChannel channel ) throws IOException { while ( buffer . hasRemaining ( ) ) { channel . write ( buffer ) ; } }
Writes the entire remaining contents of the buffer to the channel . May complete in one operation but the documentation is vague so this keeps going until we are sure .
150,949
public Map < Integer , String > getSignatures ( ) { ensureRunning ( ) ; return Collections . unmodifiableMap ( new HashMap < Integer , String > ( signatures ) ) ; }
Get the signatures that have been computed for all tracks currently loaded in any player for which we have been able to obtain all necessary metadata .
150,950
private void checkExistingTracks ( ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { for ( Map . Entry < DeckReference , TrackMetadata > entry : MetadataFinder . getInstance ( ) . getLoadedTracks ( ) . entrySet ( ) ) { if ( entry . getKey ( ) . hotCue == 0 ) { checkIfSignatureReady ( entry . g...
Send ourselves updates about any tracks that were loaded before we started since we missed them .
150,951
private void digestInteger ( MessageDigest digest , int value ) { byte [ ] valueBytes = new byte [ 4 ] ; Util . numberToBytes ( value , valueBytes , 0 , 4 ) ; digest . update ( valueBytes ) ; }
Helper method to add a Java integer value to a message digest .
150,952
public String computeTrackSignature ( final String title , final SearchableItem artist , final int duration , final WaveformDetail waveformDetail , final BeatGrid beatGrid ) { final String safeTitle = ( title == null ) ? "" : title ; final String artistName = ( artist == null ) ? "[no artist]" : artist . label ; try { ...
Calculate the signature by which we can reliably recognize a loaded track .
150,953
private void handleUpdate ( final int player ) { final TrackMetadata metadata = MetadataFinder . getInstance ( ) . getLatestMetadataFor ( player ) ; final WaveformDetail waveformDetail = WaveformFinder . getInstance ( ) . getLatestDetailFor ( player ) ; final BeatGrid beatGrid = BeatGridFinder . getInstance ( ) . getLa...
We have reason to believe we might have enough information to calculate a signature for the track loaded on a player . Verify that and if so perform the computation and record and report the new signature .
150,954
public synchronized void stop ( ) { if ( isRunning ( ) ) { MetadataFinder . getInstance ( ) . removeTrackMetadataListener ( metadataListener ) ; WaveformFinder . getInstance ( ) . removeWaveformListener ( waveformListener ) ; BeatGridFinder . getInstance ( ) . removeBeatGridListener ( beatGridListener ) ; running . set...
Stop finding signatures for all active players .
150,955
private void expireDevices ( ) { long now = System . currentTimeMillis ( ) ; Map < InetAddress , DeviceAnnouncement > copy = new HashMap < InetAddress , DeviceAnnouncement > ( devices ) ; for ( Map . Entry < InetAddress , DeviceAnnouncement > entry : copy . entrySet ( ) ) { if ( now - entry . getValue ( ) . getTimestam...
Remove any device announcements that are so old that the device seems to have gone away .
150,956
private void updateDevices ( DeviceAnnouncement announcement ) { firstDeviceTime . compareAndSet ( 0 , System . currentTimeMillis ( ) ) ; devices . put ( announcement . getAddress ( ) , announcement ) ; }
Record a device announcement in the devices map so we know whe saw it .
150,957
public synchronized void start ( ) throws SocketException { if ( ! isRunning ( ) ) { socket . set ( new DatagramSocket ( ANNOUNCEMENT_PORT ) ) ; startTime . set ( System . currentTimeMillis ( ) ) ; deliverLifecycleAnnouncement ( logger , true ) ; final byte [ ] buffer = new byte [ 512 ] ; final DatagramPacket packet = ...
Start listening for device announcements and keeping track of the DJ Link devices visible on the network . If already listening has no effect .
150,958
@ SuppressWarnings ( "WeakerAccess" ) public synchronized void stop ( ) { if ( isRunning ( ) ) { final Set < DeviceAnnouncement > lastDevices = getCurrentDevices ( ) ; socket . get ( ) . close ( ) ; socket . set ( null ) ; devices . clear ( ) ; firstDeviceTime . set ( 0 ) ; SwingUtilities . invokeLater ( new Runnable (...
Stop listening for device announcements . Also discard any announcements which had been received and notify any registered listeners that those devices have been lost .
150,959
private void deliverFoundAnnouncement ( final DeviceAnnouncement announcement ) { for ( final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners ( ) ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { try { listener . deviceFound ( announcement ) ; } catch ( Throwable t ) { log...
Send a device found announcement to all registered listeners .
150,960
private void deliverLostAnnouncement ( final DeviceAnnouncement announcement ) { for ( final DeviceAnnouncementListener listener : getDeviceAnnouncementListeners ( ) ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { try { listener . deviceLost ( announcement ) ; } catch ( Throwable t ) { logge...
Send a device lost announcement to all registered listeners .
150,961
private void performSetupExchange ( ) throws IOException { Message setupRequest = new Message ( 0xfffffffeL , Message . KnownType . SETUP_REQ , new NumberField ( posingAsPlayer , 4 ) ) ; sendMessage ( setupRequest ) ; Message response = Message . read ( is ) ; if ( response . knownType != Message . KnownType . MENU_AVA...
Exchanges the initial fully - formed messages which establishes the transaction context for queries to the dbserver .
150,962
private void performTeardownExchange ( ) throws IOException { Message teardownRequest = new Message ( 0xfffffffeL , Message . KnownType . TEARDOWN_REQ ) ; sendMessage ( teardownRequest ) ; }
Exchanges the final messages which politely report our intention to disconnect from the dbserver .
150,963
void close ( ) { try { performTeardownExchange ( ) ; } catch ( IOException e ) { logger . warn ( "Problem reporting our intention to close the dbserver connection" , e ) ; } try { channel . close ( ) ; } catch ( IOException e ) { logger . warn ( "Problem closing dbserver client output channel" , e ) ; } try { os . clos...
Closes the connection to the dbserver . This instance can no longer be used after this action .
150,964
@ SuppressWarnings ( "SameParameterValue" ) private void sendField ( Field field ) throws IOException { if ( isConnected ( ) ) { try { field . write ( channel ) ; } catch ( IOException e ) { logger . warn ( "Problem trying to write field to dbserver, closing connection" , e ) ; close ( ) ; throw e ; } return ; } throw ...
Attempt to send the specified field to the dbserver . This low - level function is available only to the package itself for use in setting up the connection . It was previously also used for sending parts of larger - scale messages but because that sometimes led to them being fragmented into multiple network packets an...
150,965
private void sendMessage ( Message message ) throws IOException { logger . debug ( "Sending> {}" , message ) ; int totalSize = 0 ; for ( Field field : message . fields ) { totalSize += field . getBytes ( ) . remaining ( ) ; } ByteBuffer combined = ByteBuffer . allocate ( totalSize ) ; for ( Field field : message . fiel...
Sends a message to the dbserver first assembling it into a single byte buffer so that it can be sent as a single packet .
150,966
public synchronized Message simpleRequest ( Message . KnownType requestType , Message . KnownType responseType , Field ... arguments ) throws IOException { final NumberField transaction = assignTransactionNumber ( ) ; final Message request = new Message ( transaction , new NumberField ( requestType . protocolValue , 2 ...
Send a request that expects a single message as its response then read and return that response .
150,967
public synchronized Message menuRequestTyped ( Message . KnownType requestType , Message . MenuIdentifier targetMenu , CdjStatus . TrackSourceSlot slot , CdjStatus . TrackType trackType , Field ... arguments ) throws IOException { if ( ! menuLock . isHeldByCurrentThread ( ) ) { throw new IllegalStateException ( "render...
Send a request for a menu that we will retrieve items from in subsequent requests when the request must reflect the actual type of track being asked about .
150,968
@ SuppressWarnings ( "WeakerAccess" ) public static synchronized SlotReference getSlotReference ( int player , CdjStatus . TrackSourceSlot slot ) { Map < CdjStatus . TrackSourceSlot , SlotReference > playerMap = instances . get ( player ) ; if ( playerMap == null ) { playerMap = new HashMap < CdjStatus . TrackSourceSlo...
Get a unique reference to a media slot on the network from which tracks can be loaded .
150,969
@ SuppressWarnings ( "WeakerAccess" ) public static SlotReference getSlotReference ( DataReference dataReference ) { return getSlotReference ( dataReference . player , dataReference . slot ) ; }
Get a unique reference to the media slot on the network from which the specified data was loaded .
150,970
public boolean isTempoMaster ( ) { DeviceUpdate master = VirtualCdj . getInstance ( ) . getTempoMaster ( ) ; return ( master != null ) && master . getAddress ( ) . equals ( address ) ; }
Was this beat sent by the current tempo master?
150,971
protected void deliverLifecycleAnnouncement ( final Logger logger , final boolean starting ) { new Thread ( new Runnable ( ) { public void run ( ) { for ( final LifecycleListener listener : getLifecycleListeners ( ) ) { try { if ( starting ) { listener . started ( LifecycleParticipant . this ) ; } else { listener . sto...
Send a lifecycle announcement to all registered listeners .
150,972
private String mountPath ( CdjStatus . TrackSourceSlot slot ) { switch ( slot ) { case SD_SLOT : return "/B/" ; case USB_SLOT : return "/C/" ; } throw new IllegalArgumentException ( "Don't know how to NFS mount filesystem for slot " + slot ) ; }
Return the filesystem path needed to mount the NFS filesystem associated with a particular media slot .
150,973
private void deliverDatabaseUpdate ( SlotReference slot , Database database , boolean available ) { for ( final DatabaseListener listener : getDatabaseListeners ( ) ) { try { if ( available ) { listener . databaseMounted ( slot , database ) ; } else { listener . databaseUnmounted ( slot , database ) ; } } catch ( Throw...
Send a database announcement to all registered listeners .
150,974
@ SuppressWarnings ( "SameParameterValue" ) private void delegatingRepaint ( int x , int y , int width , int height ) { final RepaintDelegate delegate = repaintDelegate . get ( ) ; if ( delegate != null ) { delegate . repaint ( x , y , width , height ) ; } else { repaint ( x , y , width , height ) ; } }
Determine whether we should use the normal repaint process or delegate that to another component that is hosting us in a soft - loaded manner to save memory .
150,975
private void updateWaveform ( WaveformPreview preview ) { this . preview . set ( preview ) ; if ( preview == null ) { waveformImage . set ( null ) ; } else { BufferedImage image = new BufferedImage ( preview . segmentCount , preview . maxHeight , BufferedImage . TYPE_INT_RGB ) ; Graphics g = image . getGraphics ( ) ; g...
Create an image of the proper size to hold a new waveform preview image and draw it .
150,976
private int getMaxHeight ( ) { int result = 0 ; for ( int i = 0 ; i < segmentCount ; i ++ ) { result = Math . max ( result , segmentHeight ( i , false ) ) ; } return result ; }
Scan the segments to find the largest height value present .
150,977
@ SuppressWarnings ( "WeakerAccess" ) public int segmentHeight ( final int segment , final boolean front ) { final ByteBuffer bytes = getData ( ) ; if ( isColor ) { final int base = segment * 6 ; final int frontHeight = Util . unsign ( bytes . get ( base + 5 ) ) ; if ( front ) { return frontHeight ; } else { return Mat...
Determine the height of the preview given an index into it .
150,978
@ SuppressWarnings ( "WeakerAccess" ) public Color segmentColor ( final int segment , final boolean front ) { final ByteBuffer bytes = getData ( ) ; if ( isColor ) { final int base = segment * 6 ; final int backHeight = segmentHeight ( segment , false ) ; if ( backHeight == 0 ) { return Color . BLACK ; } final int maxL...
Determine the color of the waveform given an index into it .
150,979
public boolean hasChanged ( MediaDetails originalMedia ) { if ( ! hashKey ( ) . equals ( originalMedia . hashKey ( ) ) ) { throw new IllegalArgumentException ( "Can't compare media details with different hashKey values" ) ; } return playlistCount != originalMedia . playlistCount || trackCount != originalMedia . trackCo...
Check whether the media seems to have changed since a saved version of it was used . We ignore changes in free space because those probably just reflect history entries being added .
150,980
public byte [ ] getValueAsArray ( ) { ByteBuffer buffer = getValue ( ) ; byte [ ] result = new byte [ buffer . remaining ( ) ] ; buffer . get ( result ) ; return result ; }
Get the bytes which represent the payload of this field without the leading type tag and length header as a newly - allocated byte array .
150,981
public int getHotCueCount ( ) { if ( rawMessage != null ) { return ( int ) ( ( NumberField ) rawMessage . arguments . get ( 5 ) ) . getValue ( ) ; } int total = 0 ; for ( Entry entry : entries ) { if ( entry . hotCueNumber > 0 ) { ++ total ; } } return total ; }
Return the number of entries in the cue list that represent hot cues .
150,982
private List < Entry > sortEntries ( List < Entry > loadedEntries ) { Collections . sort ( loadedEntries , new Comparator < Entry > ( ) { public int compare ( Entry entry1 , Entry entry2 ) { int result = ( int ) ( entry1 . cuePosition - entry2 . cuePosition ) ; if ( result == 0 ) { int h1 = ( entry1 . hotCueNumber != 0...
Sorts the entries into the order we want to present them in which is by position with hot cues coming after ordinary memory points if both exist at the same position which often happens .
150,983
private void addEntriesFromTag ( List < Entry > entries , RekordboxAnlz . CueTag tag ) { for ( RekordboxAnlz . CueEntry cueEntry : tag . cues ( ) ) { if ( cueEntry . type ( ) == RekordboxAnlz . CueEntryType . LOOP ) { entries . add ( new Entry ( ( int ) cueEntry . hotCue ( ) , Util . timeToHalfFrame ( cueEntry . time (...
Helper method to add cue list entries from a parsed ANLZ cue tag
150,984
public final static String process ( final String input , final Configuration configuration ) { try { return process ( new StringReader ( input ) , configuration ) ; } catch ( final IOException e ) { return null ; } }
Transforms an input String into HTML using the given Configuration .
150,985
public final static String process ( final File file , final Configuration configuration ) throws IOException { final FileInputStream input = new FileInputStream ( file ) ; final String ret = process ( input , configuration ) ; input . close ( ) ; return ret ; }
Transforms an input file into HTML using the given Configuration .
150,986
public final static String process ( final File file , final boolean safeMode ) throws IOException { return process ( file , Configuration . builder ( ) . setSafeMode ( safeMode ) . build ( ) ) ; }
Transforms an input file into HTML .
150,987
public static void main ( final String [ ] args ) throws IOException { BufferedReader reader = null ; if ( args . length == 0 ) { System . err . println ( "No input file specified." ) ; System . exit ( - 1 ) ; } if ( args . length > 1 ) { reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( args ...
Static main .
150,988
public static List < String > parse ( final String [ ] args , final Object ... objs ) throws IOException { final List < String > ret = Colls . list ( ) ; final List < Arg > allArgs = Colls . list ( ) ; final HashMap < String , Arg > shortArgs = new HashMap < String , Arg > ( ) ; final HashMap < String , Arg > longArgs ...
Parses command line arguments .
150,989
public final static int readUntil ( final StringBuilder out , final String in , final int start , final char end ) { int pos = start ; while ( pos < in . length ( ) ) { final char ch = in . charAt ( pos ) ; if ( ch == '\\' && pos + 1 < in . length ( ) ) { pos = escape ( out , in . charAt ( pos + 1 ) , pos ) ; } else { ...
Reads characters until the end character is encountered .
150,990
public final static int readMdLink ( final StringBuilder out , final String in , final int start ) { int pos = start ; int counter = 1 ; while ( pos < in . length ( ) ) { final char ch = in . charAt ( pos ) ; if ( ch == '\\' && pos + 1 < in . length ( ) ) { pos = escape ( out , in . charAt ( pos + 1 ) , pos ) ; } else ...
Reads a markdown link .
150,991
public final static int readMdLinkId ( final StringBuilder out , final String in , final int start ) { int pos = start ; int counter = 1 ; while ( pos < in . length ( ) ) { final char ch = in . charAt ( pos ) ; boolean endReached = false ; switch ( ch ) { case '\n' : out . append ( ' ' ) ; break ; case '[' : counter ++...
Reads a markdown link ID .
150,992
public final static int readXMLUntil ( final StringBuilder out , final String in , final int start , final char ... end ) { int pos = start ; boolean inString = false ; char stringChar = 0 ; while ( pos < in . length ( ) ) { final char ch = in . charAt ( pos ) ; if ( inString ) { if ( ch == '\\' ) { out . append ( ch )...
Reads characters until any end character is encountered ignoring escape sequences .
150,993
public final static void appendCode ( final StringBuilder out , final String in , final int start , final int end ) { for ( int i = start ; i < end ; i ++ ) { final char c ; switch ( c = in . charAt ( i ) ) { case '&' : out . append ( "&amp;" ) ; break ; case '<' : out . append ( "&lt;" ) ; break ; case '>' : out . app...
Appends the given string encoding special HTML characters .
150,994
public final static void appendDecEntity ( final StringBuilder out , final char value ) { out . append ( "&#" ) ; out . append ( ( int ) value ) ; out . append ( ';' ) ; }
Append the given char as a decimal HTML entity .
150,995
public final static void codeEncode ( final StringBuilder out , final String value , final int offset ) { for ( int i = offset ; i < value . length ( ) ; i ++ ) { final char c = value . charAt ( i ) ; switch ( c ) { case '&' : out . append ( "&amp;" ) ; break ; case '<' : out . append ( "&lt;" ) ; break ; case '>' : ou...
Appends the given string to the given StringBuilder replacing &amp ; &lt ; and &gt ; by their respective HTML entities .
150,996
private int countCharsStart ( final char ch , final boolean allowSpaces ) { int count = 0 ; for ( int i = 0 ; i < this . value . length ( ) ; i ++ ) { final char c = this . value . charAt ( i ) ; if ( c == ' ' && allowSpaces ) { continue ; } if ( c == ch ) { count ++ ; } else { break ; } } return count ; }
Counts the amount of ch at the start of this line optionally ignoring spaces .
150,997
public SimplifySpanBuild append ( String text ) { if ( TextUtils . isEmpty ( text ) ) return this ; mNormalSizeText . append ( text ) ; mStringBuilder . append ( text ) ; return this ; }
append normal text
150,998
public SimplifySpanBuild appendMultiClickable ( SpecialClickableUnit specialClickableUnit , Object ... specialUnitOrStrings ) { processMultiClickableSpecialUnit ( false , specialClickableUnit , specialUnitOrStrings ) ; return this ; }
append multi clickable SpecialUnit or String
150,999
public void Invoke ( final String method , JSONArray args , HubInvokeCallback callback ) { if ( method == null ) { throw new IllegalArgumentException ( "method" ) ; } if ( args == null ) { throw new IllegalArgumentException ( "args" ) ; } final String callbackId = mConnection . RegisterCallback ( callback ) ; HubInvoca...
Executes a method on the server asynchronously