Supporters update.
[dcpomatic.git] / src / lib / frame_rate_change.cc
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "compose.hpp"
23 #include "content.h"
24 #include "film.h"
25 #include "frame_rate_change.h"
26 #include <cmath>
27
28 #include "i18n.h"
29
30
31 using std::shared_ptr;
32 using std::string;
33
34
35 FrameRateChange::FrameRateChange ()
36 {
37
38 }
39
40
41 FrameRateChange::FrameRateChange (double source_, int dcp_)
42 {
43         source = source_;
44         dcp = dcp_;
45
46         if (fabs(source / 2.0 - dcp) < fabs(source - dcp)) {
47                 /* The difference between source and DCP frame rate will be lower
48                    (i.e. better) if we skip.
49                 */
50                 skip = true;
51         } else if (fabs(source * 2 - dcp) < fabs(source - dcp)) {
52                 /* The difference between source and DCP frame rate would be better
53                    if we repeated each frame once; it may be better still if we
54                    repeated more than once.  Work out the required repeat.
55                 */
56                 repeat = round (dcp / source);
57         }
58
59         speed_up = dcp / (source * factor());
60
61         auto about_equal = [](double a, double b) {
62                 return (fabs (a - b) < VIDEO_FRAME_RATE_EPSILON);
63         };
64
65         change_speed = !about_equal (speed_up, 1.0);
66 }
67
68
69 FrameRateChange::FrameRateChange (shared_ptr<const Film> film, shared_ptr<const Content> content)
70         : FrameRateChange (content->active_video_frame_rate(film), film->video_frame_rate())
71 {
72
73 }
74
75
76 FrameRateChange::FrameRateChange (shared_ptr<const Film> film, Content const * content)
77         : FrameRateChange (content->active_video_frame_rate(film), film->video_frame_rate())
78 {
79
80 }
81
82
83 string
84 FrameRateChange::description () const
85 {
86         string description;
87
88         if (!skip && repeat == 1 && !change_speed) {
89                 description = _("Content and DCP have the same rate.\n");
90         } else {
91                 if (skip) {
92                         description = _("DCP will use every other frame of the content.\n");
93                 } else if (repeat == 2) {
94                         description = _("Each content frame will be doubled in the DCP.\n");
95                 } else if (repeat > 2) {
96                         description = String::compose (_("Each content frame will be repeated %1 more times in the DCP.\n"), repeat - 1);
97                 }
98
99                 if (change_speed) {
100                         double const pc = dcp * 100 / (source * factor());
101                         char buffer[256];
102                         snprintf (buffer, sizeof(buffer), _("DCP will run at %.1f%% of the content speed.\n"), pc);
103                         description += buffer;
104                 }
105         }
106
107         return description;
108 }