private void processUpdate ( DeviceUpdate update ) { updates . put ( update . getAddress ( ) , update ) ; // Keep track of the largest sync number we see. if ( update instanceof CdjStatus ) { int syncNumber = ( ( CdjStatus ) update ) . getSyncNumber ( ) ; if ( syncNumber > this . largestSyncCounter . get ( ) ) { this . largestSyncCounter . set ( syncNumber ) ; } } // Deal with the tempo master complexities, including handoff to/from us. if ( update . isTempoMaster ( ) ) { final Integer packetYieldingTo = update . getDeviceMasterIsBeingYieldedTo ( ) ; if ( packetYieldingTo == null ) { // This is a normal, non-yielding master packet. Update our notion of the current master, and, // if we were yielding, finish that process, updating our sync number appropriately. if ( master . get ( ) ) { if ( nextMaster . get ( ) == update . deviceNumber ) { syncCounter . set ( largestSyncCounter . get ( ) + 1 ) ; } else { if ( nextMaster . get ( ) == 0xff ) { logger . warn ( "Saw master asserted by player " + update . deviceNumber + " when we were not yielding it." ) ; } else { logger . warn ( "Expected to yield master role to player " + nextMaster . get ( ) + " but saw master asserted by player " + update . deviceNumber ) ; } } } master . set ( false ) ; nextMaster . set ( 0xff ) ; setTempoMaster ( update ) ; setMasterTempo ( update . getEffectiveTempo ( ) ) ; } else { // This is a yielding master packet. If it is us that is being yielded to, take over master. // Log a message if it was unsolicited, and a warning if it's coming from a different player than // we asked. if ( packetYieldingTo == getDeviceNumber ( ) ) { if ( update . deviceNumber != masterYieldedFrom . get ( ) ) { if ( masterYieldedFrom . get ( ) == 0 ) { logger . info ( "Accepting unsolicited Master yield; we must be the only synced device playing." ) ; } else { logger . warn ( "Expected player " + masterYieldedFrom . get ( ) + " to yield master to us, but player " + update . deviceNumber + " did." ) ; } } master . set ( true ) ; masterYieldedFrom . set ( 0 ) ; setTempoMaster ( null ) ; setMasterTempo ( getTempo ( ) ) ; } } } else { // This update was not acting as a tempo master; if we thought it should be, update our records. DeviceUpdate oldMaster = getTempoMaster ( ) ; if ( oldMaster != null && oldMaster . getAddress ( ) . equals ( update . getAddress ( ) ) ) { // This device has resigned master status, and nobody else has claimed it so far setTempoMaster ( null ) ; } } deliverDeviceUpdate ( update ) ; }
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 role from or to another device .