fix LTC alignment.
[ardour.git] / libs / ardour / ltc_slave.cc
index bdb4fbead9ca115fd44c4223dfd327324a3951da..e0da586f3ed347a0508ade322ff4a72e05affd94 100644 (file)
 */
 #include <iostream>
 #include <errno.h>
-#include <poll.h>
 #include <sys/types.h>
 #include <unistd.h>
 
 #include "pbd/error.h"
+#include "pbd/pthread_utils.h"
 
 #include "ardour/debug.h"
 #include "ardour/slave.h"
@@ -150,7 +150,7 @@ LTC_Slave::reset()
 }
 
 void
-LTC_Slave::parse_ltc(const pframes_t nframes, const Sample* const in, const framecnt_t posinfo)
+LTC_Slave::parse_ltc(const ARDOUR::pframes_t nframes, const Sample* const in, const ARDOUR::framecnt_t posinfo)
 {
        pframes_t i;
        unsigned char sound[8192];
@@ -381,6 +381,8 @@ LTC_Slave::process_ltc(framepos_t const /*now*/)
                        timecode_negative_offset, timecode_offset
                        );
 
+               ltc_frame += ltc_slave_latency.max + session.worst_playback_latency();
+
                framepos_t cur_timestamp = frame.off_end + 1;
                DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC F: %1 LF: %2  N: %3 L: %4\n", ltc_frame, last_ltc_frame, cur_timestamp, last_timestamp));
                if (frame.off_end + 1 <= last_timestamp || last_timestamp == 0) {
@@ -432,7 +434,7 @@ LTC_Slave::speed_and_position (double& speed, framepos_t& pos)
 
        frameoffset_t skip = now - (monotonic_cnt + nframes);
        monotonic_cnt = now;
-       DEBUG_TRACE (DEBUG::LTC, string_compose ("speed_and_position - TID:%1 | latency: %2 | skip %3\n", ::pthread_self(), ltc_slave_latency.max, skip));
+       DEBUG_TRACE (DEBUG::LTC, string_compose ("speed_and_position - TID:%1 | latency: %2 | skip %3\n", pthread_name(), ltc_slave_latency.max, skip));
 
        if (last_timestamp == 0) {
                engine_dll_initstate = 0;
@@ -463,7 +465,7 @@ LTC_Slave::speed_and_position (double& speed, framepos_t& pos)
                        reset();
                }
 
-               parse_ltc(nframes, in, now - ltc_slave_latency.max );
+               parse_ltc(nframes, in, now);
                process_ltc(now);
        }
 
@@ -588,10 +590,10 @@ LTC_Slave::approximate_current_delta() const
        if (last_timestamp == 0 || engine_dll_initstate == 0) {
                snprintf(delta, sizeof(delta), "\u2012\u2012\u2012\u2012");
        } else if ((monotonic_cnt - last_timestamp) > 2 * frames_per_ltc_frame) {
-               snprintf(delta, sizeof(delta), _("flywheel"));
+               snprintf(delta, sizeof(delta), "%s", _("flywheel"));
        } else {
-               snprintf(delta, sizeof(delta), "\u0394<span foreground=\"green\" face=\"monospace\" >%s%s%" PRIi64 "</span>sm",
-                               LEADINGZERO(abs(current_delta)), PLUSMINUS(-current_delta), abs(current_delta));
+               snprintf(delta, sizeof(delta), "\u0394<span foreground=\"green\" face=\"monospace\" >%s%s%lld</span>sm",
+                               LEADINGZERO(llabs(current_delta)), PLUSMINUS(-current_delta), llabs(current_delta));
        }
        return std::string(delta);
 }