void JackOutput::updateTransportInfo() { if ( locate_countdown == 1 ) locate( locate_frame ); if ( locate_countdown > 0 ) locate_countdown--; if ( Preferences::get_instance()->m_bJackTransportMode != Preferences::USE_JACK_TRANSPORT ) return; m_JackTransportState = jack_transport_query( client, &m_JackTransportPos ); // update m_transport with jack-transport data switch ( m_JackTransportState ) { case JackTransportStopped: m_transport.m_status = TransportInfo::STOPPED; //infoLog( "[updateTransportInfo] STOPPED - frames: " + to_string(m_transportPos.frame) ); break; case JackTransportRolling: if ( m_transport.m_status != TransportInfo::ROLLING && ( m_JackTransportPos.valid & JackPositionBBT ) ) { must_relocate = 2; //WARNINGLOG( "Jack transport starting: Resyncing in 2 x Buffersize!!" ); } m_transport.m_status = TransportInfo::ROLLING; //infoLog( "[updateTransportInfo] ROLLING - frames: " + to_string(m_transportPos.frame) ); break; case JackTransportStarting: m_transport.m_status = TransportInfo::STOPPED; //infoLog( "[updateTransportInfo] STARTING (stopped) - frames: " + to_string(m_transportPos.frame) ); break; default: ERRORLOG( "Unknown jack transport state" ); } // FIXME // TickSize and BPM Hydrogen * H = Hydrogen::get_instance(); H->setTimelineBpm(); // dlr: fix #168, jack may have re-located us anywhere, check for bpm change every cycle if ( m_JackTransportPos.valid & JackPositionBBT ) { float bpm = ( float )m_JackTransportPos.beats_per_minute; if ( m_transport.m_nBPM != bpm ) { if ( Preferences::get_instance()->m_bJackMasterMode == Preferences::NO_JACK_TIME_MASTER ){ // WARNINGLOG( QString( "Tempo change from jack-transport: %1" ).arg( bpm ) ); m_transport.m_nBPM = bpm; must_relocate = 1; // The tempo change has happened somewhere during the previous cycle; relocate right away. // This commenting out is rude perhaps, but I cant't figure out what this bit is doing. // In any case, setting must_relocate = 1 here causes too many relocates. Jakob Lund /* } else { if ( m_transport.m_status == TransportInfo::STOPPED ) { oldpo = H->getPatternPos(); must_relocate = 1; //changer =1; }*/ } // Hydrogen::get_instance()->setBPM( m_JackTransportPos.beats_per_minute ); // unnecessary, as Song->m_BPM gets updated in audioEngine_process_transport (after calling this function) } } if ( m_transport.m_nFrames + bbt_frame_offset != m_JackTransportPos.frame ) { if ( ( m_JackTransportPos.valid & JackPositionBBT ) && must_relocate == 0 ) { WARNINGLOG( "Frame offset mismatch; triggering resync in 2 cycles" ); must_relocate = 2; } else { if ( Preferences::get_instance()->m_bJackMasterMode == Preferences::NO_JACK_TIME_MASTER ) { // If There's no timebase_master, and audioEngine_process_checkBPMChanged handled a tempo change during last cycle, the offset doesn't match, but hopefully it was calculated correctly: //this perform Jakobs mod in pattern mode, but both m_transport.m_nFrames works with the same result in pattern Mode // in songmode the first case dont work. //so we can remove this "if query" and only use this old mod: m_transport.m_nFrames = H->getHumantimeFrames(); //because to get the songmode we have to add this "H2Core::Hydrogen *m_pEngine" to the header file //if we remove this we also can remove *m_pEngine from header #if 0 // dlr: fix #169, why do we have a different behaviour for SONG_MODE? if ( m_pEngine->getSong()->get_mode() == Song::PATTERN_MODE ){ m_transport.m_nFrames = m_JackTransportPos.frame/* - bbt_frame_offset*/; ///see comment in svn changeset 753 } else { m_transport.m_nFrames = H->getHumantimeFrames(); } #else m_transport.m_nFrames = m_JackTransportPos.frame; bbt_frame_offset = 0; // dlr: stop re-syncing in every cycle when STOPPED #endif // In jack 'slave' mode, if there's no master, the following line is needed to be able to relocate by clicking the song ruler (wierd corner case, but still...) if ( m_transport.m_status == TransportInfo::ROLLING ) H->triggerRelocateDuringPlay(); } else { ///this is experimantal... but it works for the moment... fix me fix :-) wolke // ... will this actually happen? keeping it for now ( jakob lund ) m_transport.m_nFrames = H->getHumantimeFrames(); } } } // humantime fix if ( H->getHumantimeFrames() != m_JackTransportPos.frame ) { H->setHumantimeFrames(m_JackTransportPos.frame); //WARNINGLOG("fix Humantime " + to_string (m_JackTransportPos.frame)); } if ( must_relocate == 1 ) { //WARNINGLOG( "Resyncing!" ); relocateBBT(); if ( m_transport.m_status == TransportInfo::ROLLING ) { H->triggerRelocateDuringPlay(); } } if ( must_relocate > 0 ) must_relocate--; }
void JackAudioDriver::updateTransportInfo() { // The following four lines do only cover the special case of // audioEngine_updateNoteQueue() returning -1 in // audioEngine_process() and triggering an addition relocation // of the transport position to the beginning of the song // using locateInNCycles() to possibly keep synchronization // with Ardour. if ( locate_countdown == 1 ) locate( locate_frame ); if ( locate_countdown > 0 ) locate_countdown--; if ( Preferences::get_instance()->m_bJackTransportMode != Preferences::USE_JACK_TRANSPORT ){ return; } // jack_transport_query() (jack/transport.h) queries the // current transport state and position. If called from the // process thread, the second argument, which is a pointer to // a structure for returning current transport, corresponds to // the first frame of the current cycle and the state returned // is valid for the entire cycle. #m_JackTransportPos->valid // will show which fields contain valid data. If // #m_JackTransportPos is NULL, do not return position // information. m_JackTransportState = jack_transport_query( m_pClient, &m_JackTransportPos ); // WARNINGLOG( QString( "[Jack-Query] state: %1, frame: %2, position bit: %3, bpm: %4" ) // .arg( m_JackTransportState ) // .arg( m_JackTransportPos.frame ) // .arg( m_JackTransportPos.valid ) // .arg( m_JackTransportPos.beats_per_minute ) ); // Update the TransportInfo in m_transport based on the state // returned by jack_transport_query. switch ( m_JackTransportState ) { case JackTransportStopped: // Transport is halted m_transport.m_status = TransportInfo::STOPPED; //INFOLOG( "[updateTransportInfo] STOPPED - frames: " + to_string(m_transportPos.frame) ); break; case JackTransportRolling: // Transport is playing // If the valid member matches the JackPositionBBT // bits, there is a JACK timebase master present // supplying bar, beat, and tick information along // with the plain transport position in frames. We // will use it for re-positioning. But only at the end // of the next cycle, because this timebase master has // to properly initialize its state during this cycle // too. if ( m_transport.m_status != TransportInfo::ROLLING && ( m_JackTransportPos.valid & JackPositionBBT ) ) { must_relocate = 2; //WARNINGLOG( "Jack transport starting: Resyncing in 2 x Buffersize!!" ); } m_transport.m_status = TransportInfo::ROLLING; //INFOLOG( "[updateTransportInfo] ROLLING - frames: " + to_string(m_transportPos.frame) ); break; case JackTransportStarting: // Waiting for sync ready. If // there are slow-sync clients, // this can take more than one // cycle. m_transport.m_status = TransportInfo::STOPPED; //INFOLOG( "[updateTransportInfo] STARTING (stopped) - frames: " + to_string(m_transportPos.frame) ); break; default: ERRORLOG( "Unknown jack transport state" ); } // Updating TickSize and BPM Hydrogen * H = Hydrogen::get_instance(); // JACK may have re-located us anywhere. Therefore, we have to // check for a bpm change every cycle. We will do so by // updating both the global speed of the song, as well as the // fallback speed (H->getNewBpmJTM) with the local tempo at // the current position on the timeline. H->setTimelineBpm(); // Check whether another JACK master is present (the second if // clause won't evaluate to true if Hydrogen itself is the // timebase master) and whether it changed the transport // state. Note that only the JACK timebase master and not // arbitrary clients can do this. If so, the speed is updated // an a relocation according to the bar, beat, and tick // information will be triggered right away. if ( m_JackTransportPos.valid & JackPositionBBT ) { float bpm = ( float )m_JackTransportPos.beats_per_minute; if ( m_transport.m_nBPM != bpm ) { if ( Preferences::get_instance()->m_bJackMasterMode == Preferences::NO_JACK_TIME_MASTER ){ // WARNINGLOG( QString( "Tempo change from jack-transport: %1" ).arg( bpm ) ); m_transport.m_nBPM = bpm; must_relocate = 1; } } } // This clause detects a re-location, which was either // triggered by an user-interaction (e.g. clicking the forward // button or clicking somewhere on the timeline) or by a // different JACK client. if ( m_transport.m_nFrames + bbt_frame_offset != m_JackTransportPos.frame ) { // Whether there is a JACK timebase master registered // but the audio engine was neither (re)started nor a // change in the speed was found beforehand. if ( ( m_JackTransportPos.valid & JackPositionBBT ) && must_relocate == 0 ) { // WARNINGLOG( "Frame offset mismatch; triggering resync in 2 cycles" ); must_relocate = 2; // re-locate at the end of // the next cycle. } else { if ( Preferences::get_instance()->m_bJackMasterMode == Preferences::NO_JACK_TIME_MASTER ) { // Just consider the transport // position as dirty, reassign the // one obtained in the query, and // reset the offset. m_transport.m_nFrames = m_JackTransportPos.frame; bbt_frame_offset = 0; // If not registered as JACK time // master, the following line is // needed to be able to relocate by // clicking the song ruler (wired // corner case, but still...) if ( m_transport.m_status == TransportInfo::ROLLING ) // Setting // H->m_nPatternStartTick = -1 // if in pattern mode. H->triggerRelocateDuringPlay(); } else { // Fallback to the transport position // of the last cycle. m_transport.m_nFrames = H->getHumantimeFrames(); } } } // Only used if Hydrogen is in JACK timebase master // mode. Updated every cycle. if ( H->getHumantimeFrames() != m_JackTransportPos.frame ) { H->setHumantimeFrames(m_JackTransportPos.frame); // WARNINGLOG( QString( "fix Humantime: %1" ).arg( m_JackTransportPos.frame ) ); } // Trigger the re-location based on the information provided // by another JACK timebase master. if ( must_relocate == 1 ) { WARNINGLOG( QString( "Resyncing! bbt_frame_offset: %1" ).arg( bbt_frame_offset ) ); relocateBBT(); if ( m_transport.m_status == TransportInfo::ROLLING ) { // Setting H->m_nPatternStartTick = -1 if in // pattern mode H->triggerRelocateDuringPlay(); } } if ( must_relocate > 0 ) must_relocate--; }