Fix the build for older macOS.
[dcpomatic.git] / src / lib / frame_rate_change.cc
index 80a167029009349913b21e15c35d6aa0c760b4f2..a1ff2ae650a93d7ec19782763f359b4b6a0c883a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 #include "frame_rate_change.h"
 #include "types.h"
+#include "content.h"
+#include "film.h"
 #include "compose.hpp"
 #include <cmath>
 
 #include "i18n.h"
 
+
 using std::string;
+using std::shared_ptr;
+
 
-static bool
-about_equal (double a, double b)
+FrameRateChange::FrameRateChange ()
 {
-       return (fabs (a - b) < VIDEO_FRAME_RATE_EPSILON);
+
 }
 
 
 FrameRateChange::FrameRateChange (double source_, int dcp_)
-       : source (source_)
-       , dcp (dcp_)
-       , skip (false)
-       , repeat (1)
-       , change_speed (false)
 {
-       if (fabs (source / 2.0 - dcp) < fabs (source - dcp)) {
+       source = source_;
+       dcp = dcp_;
+
+       if (fabs(source / 2.0 - dcp) < fabs(source - dcp)) {
                /* The difference between source and DCP frame rate will be lower
                   (i.e. better) if we skip.
                */
                skip = true;
-       } else if (fabs (source * 2 - dcp) < fabs (source - dcp)) {
+       } else if (fabs(source * 2 - dcp) < fabs(source - dcp)) {
                /* The difference between source and DCP frame rate would be better
                   if we repeated each frame once; it may be better still if we
                   repeated more than once.  Work out the required repeat.
@@ -55,9 +58,29 @@ FrameRateChange::FrameRateChange (double source_, int dcp_)
        }
 
        speed_up = dcp / (source * factor());
+
+       auto about_equal = [](double a, double b) {
+               return (fabs (a - b) < VIDEO_FRAME_RATE_EPSILON);
+       };
+
        change_speed = !about_equal (speed_up, 1.0);
 }
 
+
+FrameRateChange::FrameRateChange (shared_ptr<const Film> film, shared_ptr<const Content> content)
+       : FrameRateChange (content->active_video_frame_rate(film), film->video_frame_rate())
+{
+
+}
+
+
+FrameRateChange::FrameRateChange (shared_ptr<const Film> film, Content const * content)
+       : FrameRateChange (content->active_video_frame_rate(film), film->video_frame_rate())
+{
+
+}
+
+
 string
 FrameRateChange::description () const
 {
@@ -76,7 +99,9 @@ FrameRateChange::description () const
 
                if (change_speed) {
                        double const pc = dcp * 100 / (source * factor());
-                       description += String::compose (_("DCP will run at %1%% of the content speed.\n"), pc);
+                       char buffer[256];
+                       snprintf (buffer, sizeof(buffer), _("DCP will run at %.1f%% of the content speed.\n"), pc);
+                       description += buffer;
                }
        }