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." ) ; } // Is there someone we need to ask to yield to us? final DeviceUpdate currentMaster = getTempoMaster ( ) ; if ( currentMaster != null ) { // Send the yield request; we will become master when we get a successful response. byte [ ] payload = new byte [ MASTER_HANDOFF_REQUEST_PAYLOAD . length ] ; System . arraycopy ( MASTER_HANDOFF_REQUEST_PAYLOAD , 0 , payload , 0 , MASTER_HANDOFF_REQUEST_PAYLOAD . length ) ; payload [ 2 ] = getDeviceNumber ( ) ; payload [ 8 ] = getDeviceNumber ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Sending master yield request to player " + currentMaster ) ; } requestingMasterRoleFromPlayer . set ( currentMaster . deviceNumber ) ; assembleAndSendPacket ( Util . PacketType . MASTER_HANDOFF_REQUEST , payload , currentMaster . address , BeatFinder . BEAT_PORT ) ; } else if ( ! master . get ( ) ) { // There is no other master, we can just become it immediately. requestingMasterRoleFromPlayer . set ( 0 ) ; setMasterTempo ( getTempo ( ) ) ; master . set ( true ) ; } }
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 .