debug instrumentation for locate time
[ardour.git] / libs / ardour / mtc_slave.cc
index 0dee2a071bdd4e3ce5035a25589cde25ee5d8009..cbb97cf1ad25f6dd21419733c798dedbbad6d06b 100644 (file)
@@ -34,7 +34,7 @@
 
 #include <glibmm/timer.h>
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -65,7 +65,7 @@ MTC_Slave::MTC_Slave (Session& s, MidiPort& p)
        busy_guard1 = busy_guard2 = 0;
 
        last_mtc_fps_byte = session.get_mtc_timecode_bits ();
-       quarter_frame_duration = (double(session.frames_per_timecode_frame()) / 4.0);
+       quarter_frame_duration = (double(session.samples_per_timecode_frame()) / 4.0);
 
        mtc_timecode = session.config.get_timecode_format();
        a3e_timecode = session.config.get_timecode_format();
@@ -213,6 +213,7 @@ MTC_Slave::reset (bool with_position)
        window_end = 0;
        transport_direction = 1;
        current_delta = 0;
+       ActiveChanged(false);
 }
 
 void
@@ -309,11 +310,7 @@ MTC_Slave::update_mtc_time (const MIDI::byte *msg, bool was_full, framepos_t now
           to use a timestamp indicating when this MTC time was received. example: when we received
           a locate command via MMC.
        */
-#ifdef COMPILER_MSVC
-       DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC::update_mtc_time - TID:%1\n", ::pthread_self().p));
-#else
-       DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC::update_mtc_time - TID:%1\n", ::pthread_self()));
-#endif
+       DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC::update_mtc_time - TID:%1\n", pthread_name()));
        TimecodeFormat tc_format;
        bool reset_tc = true;
 
@@ -429,9 +426,10 @@ MTC_Slave::update_mtc_time (const MIDI::byte *msg, bool was_full, framepos_t now
                                                 now, timecode, mtc_frame, was_full, speedup_due_to_tc_mismatch));
 
        if (was_full || outside_window (mtc_frame)) {
-               DEBUG_TRACE (DEBUG::MTC, string_compose ("update_mtc_time: full TC %1 or outside window %2\n", was_full, outside_window (mtc_frame)));
-               session.request_locate (mtc_frame, false);
+               DEBUG_TRACE (DEBUG::MTC, string_compose ("update_mtc_time: full TC %1 or outside window %2 MTC %3\n", was_full, outside_window (mtc_frame), mtc_frame));
+               session.set_requested_return_frame (-1);
                session.request_transport_speed (0);
+               session.request_locate (mtc_frame, false);
                update_mtc_status (MIDI::MTC_Stopped);
                reset (false);
                reset_window (mtc_frame);
@@ -451,7 +449,7 @@ MTC_Slave::update_mtc_time (const MIDI::byte *msg, bool was_full, framepos_t now
                long int mtc_off = (long) rint(7.0 * qtr);
 
                DEBUG_TRACE (DEBUG::MTC, string_compose ("new mtc_frame: %1 | MTC-FpT: %2 A3-FpT:%3\n",
-                                                        mtc_frame, (4.0*qtr), session.frames_per_timecode_frame()));
+                                                        mtc_frame, (4.0*qtr), session.samples_per_timecode_frame()));
 
                switch (port->self_parser().mtc_running()) {
                case MTC_Backward:
@@ -472,6 +470,7 @@ MTC_Slave::update_mtc_time (const MIDI::byte *msg, bool was_full, framepos_t now
                                first_mtc_timestamp = now;
                                init_mtc_dll(mtc_frame, qtr);
                                mtc_frame_dll = mtc_frame;
+                               ActiveChanged (true); // emit signal
                        }
                        current.guard1++;
                        current.position = mtc_frame;
@@ -493,7 +492,7 @@ MTC_Slave::update_mtc_status (MIDI::MTC_Status status)
        /* XXX !!! thread safety ... called from MIDI I/O context
         * on locate (via ::update_mtc_time())
         */
-       DEBUG_TRACE (DEBUG::MTC, string_compose("MTC_Slave::update_mtc_status - TID:%1\n", pthread_name()));
+       DEBUG_TRACE (DEBUG::MTC, string_compose("MTC_Slave::update_mtc_status - TID:%1 MTC:%2\n", pthread_name(), mtc_frame));
        return; // why was this fn needed anyway ? it just messes up things -> use reset.
        busy_guard1++;
 
@@ -598,7 +597,7 @@ MTC_Slave::speed_and_position (double& speed, framepos_t& pos)
        read_current (&last);
 
        DEBUG_TRACE (DEBUG::MTC, string_compose ("speed&pos: timestamp %1 speed %2 initstate %3 dir %4 tpos %5 now %6 last-in %7\n",
-                                                last.timestamp, 
+                                                last.timestamp,
                                                 last.speed,
                                                 engine_dll_initstate,
                                                 transport_direction,
@@ -607,8 +606,8 @@ MTC_Slave::speed_and_position (double& speed, framepos_t& pos)
                                                 last_inbound_frame));
 
        /* re-init engine DLL here when state changed (direction, first_mtc_timestamp) */
-       if (last.timestamp == 0) { 
-               engine_dll_initstate = 0; 
+       if (last.timestamp == 0) {
+               engine_dll_initstate = 0;
        } else if (engine_dll_initstate != transport_direction && last.speed != 0) {
                engine_dll_initstate = transport_direction;
                init_engine_dll(last.position, session.engine().samples_per_cycle());
@@ -626,11 +625,13 @@ MTC_Slave::speed_and_position (double& speed, framepos_t& pos)
        if (last_inbound_frame && now > last_inbound_frame && now - last_inbound_frame > labs(seekahead_distance())) {
                speed = 0;
                pos = last.position;
+               session.set_requested_return_frame (-1);
                session.request_locate (pos, false);
                session.request_transport_speed (0);
                engine_dll_initstate = 0;
                queue_reset (false);
-               DEBUG_TRACE (DEBUG::MTC, "MTC not seen for 2 frames - reset pending\n");
+               ActiveChanged (false);
+               DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC not seen for 2 frames - reset pending, pos = %1\n", pos));
                return false;
        }