first round of audio-clock font rendering update
[ardour.git] / libs / ardour / ltc_slave.cc
index ea40fea654265380e6e3fe78a3ce860a297ee68b..8cc12c2b5d2e75fdaa96171c98ecdcfe6bea4269 100644 (file)
@@ -53,8 +53,8 @@ LTC_Slave::LTC_Slave (Session& s)
        monotonic_cnt = 0;
        fps_detected=false;
 
-       ltc_timecode = timecode_60; // track changes of LTC fps
-       a3e_timecode = timecode_60; // track changes of Ardour's fps
+       ltc_timecode = session.config.get_timecode_format();
+       a3e_timecode = session.config.get_timecode_format();
        printed_timecode_warning = false;
        ltc_detect_fps_cnt = ltc_detect_fps_max = 0;
        memset(&prev_frame, 0, sizeof(LTCFrameExt));
@@ -108,7 +108,7 @@ LTC_Slave::resync_latency()
        DEBUG_TRACE (DEBUG::LTC, "LTC resync_latency()\n");
        engine_dll_initstate = 0;
 
-       if (session.ltc_output_io()) { /* check if Port exits */
+       if (!session.deletion_in_progress() && session.ltc_output_io()) { /* check if Port exits */
                boost::shared_ptr<Port> ltcport = session.ltc_input_port();
                ltcport->get_connected_latency_range(ltc_slave_latency, false);
        }
@@ -198,22 +198,23 @@ LTC_Slave::detect_ltc_fps(int frameno, bool df)
        }
        ltc_detect_fps_cnt++;
 
-       if (ltc_detect_fps_cnt > 40)
-       {
-               if (ltc_detect_fps_cnt > ltc_detect_fps_max
-                   && (   ceil(timecode.rate) != (ltc_detect_fps_max + 1)
-                       || timecode.drop != df
-                       )
-                   )
-               {
-                       DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC detected FPS %1%2",
-                                       ltc_detect_fps_max + 1, timecode.drop ? "df" : ""));
+       if (ltc_detect_fps_cnt > 40) {
+               if (ltc_detect_fps_cnt > ltc_detect_fps_max) {
                        detected_fps = ltc_detect_fps_max + 1;
                        if (df) {
                                /* LTC df -> indicates fractional framerate */
-                               detected_fps = detected_fps * 1000.0 / 1001.0;
+                               if (Config->get_timecode_source_2997()) {
+                                       detected_fps = detected_fps * 999.0 / 1000.0;
+                               } else {
+                                       detected_fps = detected_fps * 1000.0 / 1001.0;
+                               }
+                       }
+
+                       if (timecode.rate != detected_fps || timecode.drop != df) {
+                               DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC detected FPS: %1%2\n", detected_fps, df?"df":"ndf"));
+                       } else {
+                               detected_fps = 0; /* no cange */
                        }
-                       DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC detected FPS: %1%2\n", detected_fps, df?"df":"ndf"));
                }
                ltc_detect_fps_cnt = ltc_detect_fps_max = 0;
        }
@@ -231,6 +232,7 @@ LTC_Slave::detect_ltc_fps(int frameno, bool df)
        /* poll and check session TC */
        TimecodeFormat tc_format = apparent_timecode_format();
        TimecodeFormat cur_timecode = session.config.get_timecode_format();
+
        if (Config->get_timecode_sync_frame_rate()) {
                /* enforce time-code */
                if (!did_reset_tc_format) {
@@ -238,10 +240,12 @@ LTC_Slave::detect_ltc_fps(int frameno, bool df)
                        did_reset_tc_format = true;
                }
                if (cur_timecode != tc_format) {
-                       warning << string_compose(_("Session framerate adjusted from %1 to LTC's %2."),
-                                       Timecode::timecode_format_name(cur_timecode),
-                                       Timecode::timecode_format_name(tc_format))
-                               << endmsg;
+                       if (ceil(Timecode::timecode_to_frames_per_second(cur_timecode)) != ceil(Timecode::timecode_to_frames_per_second(tc_format))) {
+                               warning << string_compose(_("Session framerate adjusted from %1 to LTC's %2."),
+                                               Timecode::timecode_format_name(cur_timecode),
+                                               Timecode::timecode_format_name(tc_format))
+                                       << endmsg;
+                       }
                        session.config.set_timecode_format (tc_format);
                }
        } else {
@@ -250,10 +254,12 @@ LTC_Slave::detect_ltc_fps(int frameno, bool df)
                if (a3e_timecode != cur_timecode) printed_timecode_warning = false;
 
                if (cur_timecode != tc_format && ! printed_timecode_warning) {
-                       warning << string_compose(_("Session and LTC framerate mismatch: LTC:%1 Session:%2."),
-                                       Timecode::timecode_format_name(tc_format),
-                                       Timecode::timecode_format_name(cur_timecode))
-                               << endmsg;
+                       if (ceil(Timecode::timecode_to_frames_per_second(cur_timecode)) != ceil(Timecode::timecode_to_frames_per_second(tc_format))) {
+                               warning << string_compose(_("Session and LTC framerate mismatch: LTC:%1 Session:%2."),
+                                               Timecode::timecode_format_name(tc_format),
+                                               Timecode::timecode_format_name(cur_timecode))
+                                       << endmsg;
+                       }
                        printed_timecode_warning = true;
                }
        }
@@ -325,7 +331,7 @@ LTC_Slave::process_ltc(framepos_t const now)
 
                /* map LTC timecode to session TC setting */
                framepos_t ltc_frame; ///< audio-frame corresponding to LTC frame
-               Timecode::timecode_to_sample (timecode, ltc_frame, true, false,
+               Timecode::timecode_to_sample (timecode, ltc_frame, false, false,
                        double(session.frame_rate()),
                        session.config.get_subframes_per_frame(),
                        session.config.get_timecode_offset_negative(), session.config.get_timecode_offset()
@@ -510,9 +516,9 @@ LTC_Slave::apparent_timecode_format () const
        else if (timecode.rate == 25 && !timecode.drop)
                return timecode_25;
        else if (rint(timecode.rate * 100) == 2997 && !timecode.drop)
-               return timecode_2997;
+               return (Config->get_timecode_source_2997() ? timecode_2997000 : timecode_2997);
        else if (rint(timecode.rate * 100) == 2997 &&  timecode.drop)
-               return timecode_2997drop;
+               return (Config->get_timecode_source_2997() ? timecode_2997000drop : timecode_2997drop);
        else if (timecode.rate == 30 &&  timecode.drop)
                return timecode_2997drop; // timecode_30drop; // LTC counting to 30 frames w/DF *means* 29.97 df
        else if (timecode.rate == 30 && !timecode.drop)
@@ -526,7 +532,7 @@ std::string
 LTC_Slave::approximate_current_position() const
 {
        if (last_timestamp == 0) {
-               return " --:--:--:--";
+               return " \u2012\u2012:\u2012\u2012:\u2012\u2012:\u2012\u2012";
        }
        return Timecode::timecode_format_time(timecode);
 }
@@ -534,13 +540,13 @@ LTC_Slave::approximate_current_position() const
 std::string
 LTC_Slave::approximate_current_delta() const
 {
-       char delta[24];
+       char delta[80];
        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), _("flywheel"));
        } else {
-               snprintf(delta, sizeof(delta), "%s%4" PRIi64 " sm",
+               snprintf(delta, sizeof(delta), "\u0394<span foreground=\"green\" face=\"monospace\" >%s%5" PRIi64 "</span>sm",
                                PLUSMINUS(-current_delta), abs(current_delta));
        }
        return std::string(delta);