Correctly handle the case when Preset and/or Tune is "UNSPECIFIED".
[simple-x264-launcher.git] / src / model_options.h
blob1fe30bd3a1c5a3cf8270907acaae9d85588e1c2b
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #pragma once
24 #include <QObject>
25 #include <QString>
26 #include <QMap>
28 class SysinfoModel;
29 class QSettings;
31 class OptionsModel
33 public:
34 OptionsModel(const SysinfoModel *sysinfo);
35 OptionsModel(const OptionsModel &rhs);
36 ~OptionsModel(void);
38 enum EncType
40 EncType_X264 = 0,
41 EncType_X265 = 1,
43 EncType_MIN = EncType_X264,
44 EncType_MAX = EncType_X265,
47 enum EncArch
49 EncArch_x86_32 = 0,
50 EncArch_x86_64 = 1,
52 EncArch_MIN = EncArch_x86_32,
53 EncArch_MAX = EncArch_x86_64
56 enum EncVariant
58 EncVariant_8Bit = 1,
59 EncVariant_10Bit = 2,
60 EncVariant_12Bit = 4,
62 EncVariant_MIN = EncVariant_8Bit,
63 EncVariant_MAX = EncVariant_12Bit
66 enum RCMode
68 RCMode_CRF = 0,
69 RCMode_CQ = 1,
70 RCMode_2Pass = 2,
71 RCMode_ABR = 3,
73 RCMode_MIN = RCMode_CRF,
74 RCMode_MAX = RCMode_ABR,
77 static const char *const SETTING_UNSPECIFIED;
78 static const char *const PROFILE_UNRESTRICTED;
80 //Getter
81 EncType encType(void) const { return m_encoderType; }
82 EncArch encArch(void) const { return m_encoderArch; }
83 EncVariant encVariant(void) const { return m_encoderVariant; }
84 RCMode rcMode(void) const { return m_rcMode; }
85 unsigned int bitrate(void) const { return m_bitrate; }
86 double quantizer(void) const { return m_quantizer; }
87 QString preset(void) const { return m_preset; }
88 QString tune(void) const { return m_tune; }
89 QString profile(void) const { return m_profile; }
90 QString customEncParams(void) const { return m_custom_encoder; }
91 QString customAvs2YUV(void) const { return m_custom_avs2yuv; }
93 //Setter
94 void setEncType(EncType type) { m_encoderType = qBound(EncType_X264, type, EncType_X265); }
95 void setEncArch(EncArch arch) { m_encoderArch = qBound(EncArch_x86_32, arch, EncArch_x86_64); }
96 void setEncVariant(EncVariant variant) { m_encoderVariant = qBound(EncVariant_8Bit, variant, EncVariant_12Bit); }
97 void setRCMode(RCMode mode) { m_rcMode = qBound(RCMode_CRF, mode, RCMode_ABR); }
98 void setBitrate(unsigned int bitrate) { m_bitrate = qBound(10U, bitrate, 800000U); }
99 void setQuantizer(double quantizer) { m_quantizer = qBound(0.0, quantizer, 52.0); }
100 void setPreset(const QString &preset) { m_preset = preset.trimmed(); }
101 void setTune(const QString &tune) { m_tune = tune.trimmed(); }
102 void setProfile(const QString &profile) { m_profile = profile.trimmed(); }
103 void setCustomEncParams(const QString &custom) { m_custom_encoder = custom.trimmed(); }
104 void setCustomAvs2YUV(const QString &custom) { m_custom_avs2yuv = custom.trimmed(); }
106 //Stuff
107 bool equals(const OptionsModel *model);
109 //Static functions
110 static QString rcMode2String(RCMode mode);
111 static bool saveTemplate(const OptionsModel *model, const QString &name);
112 static bool loadTemplate(OptionsModel *model, const QString &name);
113 static QMap<QString, OptionsModel*> loadAllTemplates(const SysinfoModel *sysinfo);
114 static bool templateExists(const QString &name);
115 static bool deleteTemplate(const QString &name);
116 static bool saveOptions(const OptionsModel *model, QSettings &settingsFile);
117 static bool loadOptions(OptionsModel *model, QSettings &settingsFile);
119 protected:
120 EncType m_encoderType;
121 EncArch m_encoderArch;
122 EncVariant m_encoderVariant;
123 RCMode m_rcMode;
124 unsigned int m_bitrate;
125 double m_quantizer;
126 QString m_preset;
127 QString m_tune;
128 QString m_profile;
129 QString m_custom_encoder;
130 QString m_custom_avs2yuv;
132 private:
133 static void fixTemplate(QSettings &settingsFile);