Rename PRORES -> PRORES_HQ
[dcpomatic.git] / src / lib / export_config.cc
1 /*
2     Copyright (C) 2022 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 "config.h"
23 #include "export_config.h"
24 #include <dcp/raw_convert.h>
25 #include <dcp/warnings.h>
26 LIBDCP_DISABLE_WARNINGS
27 #include <libxml++/libxml++.h>
28 LIBDCP_ENABLE_WARNINGS
29
30
31 using std::string;
32
33
34 ExportConfig::ExportConfig(Config* parent)
35         : _config(parent)
36 {
37
38 }
39
40
41 void
42 ExportConfig::set_defaults()
43 {
44         _format = ExportFormat::PRORES_HQ;
45         _mixdown_to_stereo = false;
46         _split_reels = false;
47         _split_streams = false;
48         _x264_crf = 23;
49 }
50
51
52 void
53 ExportConfig::read(cxml::ConstNodePtr node)
54 {
55         if (!node) {
56                 set_defaults();
57                 return;
58         }
59
60         auto const format = node->string_child("Format");
61
62         if (format == "subtitles-dcp") {
63                 _format = ExportFormat::SUBTITLES_DCP;
64         } else if (format == "h264-aac") {
65                 _format = ExportFormat::H264_AAC;
66         } else {
67                 _format = ExportFormat::PRORES_HQ;
68         }
69
70         _mixdown_to_stereo = node->bool_child("MixdownToStereo");
71         _split_reels = node->bool_child("SplitReels");
72         _split_streams = node->bool_child("SplitStreams");
73         _x264_crf = node->number_child<int>("X264CRF");
74 }
75
76
77 void
78 ExportConfig::write(xmlpp::Element* node) const
79 {
80         string name;
81
82         switch (_format) {
83                 case ExportFormat::PRORES_HQ:
84                         name = "prores";
85                         break;
86                 case ExportFormat::H264_AAC:
87                         name = "h264-aac";
88                         break;
89                 case ExportFormat::SUBTITLES_DCP:
90                         name = "subtitles-dcp";
91                         break;
92         }
93
94         node->add_child("Format")->add_child_text(name);
95         node->add_child("MixdownToStereo")->add_child_text(_mixdown_to_stereo ? "1" : "0");
96         node->add_child("SplitReels")->add_child_text(_split_reels ? "1" : "0");
97         node->add_child("SplitStreams")->add_child_text(_split_streams ? "1" : "0");
98         node->add_child("X264CRF")->add_child_text(dcp::raw_convert<string>(_x264_crf));
99 }
100
101
102 void
103 ExportConfig::set_format(ExportFormat format)
104 {
105         _config->maybe_set(_format, format);
106 }
107
108
109 void
110 ExportConfig::set_mixdown_to_stereo(bool mixdown)
111 {
112         _config->maybe_set(_mixdown_to_stereo, mixdown);
113 }
114
115
116 void
117 ExportConfig::set_split_reels(bool split)
118 {
119         _config->maybe_set(_split_reels, split);
120 }
121
122
123 void
124 ExportConfig::set_split_streams(bool split)
125 {
126         _config->maybe_set(_split_streams, split);
127 }
128
129
130 void
131 ExportConfig::set_x264_crf(int crf)
132 {
133         _config->maybe_set(_x264_crf, crf);
134 }
135