-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathtypes.h
More file actions
276 lines (220 loc) · 6.67 KB
/
types.h
File metadata and controls
276 lines (220 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* Flacon - audio File Encoder
* https://github.com/flacon/flacon
*
* Copyright: 2017
* Alexander Sokoloff <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#ifndef TYPES_H
#define TYPES_H
#include <QString>
#include <QIcon>
#include <QMetaType>
#define CODEC_AUTODETECT "AUTODETECT"
// clang-format off
template <typename T> struct AutoRegMetaType { AutoRegMetaType() { qRegisterMetaType<T>(); } };
// clang-format on
using DiscNum = quint16;
using DiscCount = quint16;
using TrackNum = quint16;
using TrackCount = quint16;
using Duration = uint;
using mSec = int;
using Percent = quint8;
enum class PreGapType {
Skip = 0,
ExtractToFile,
AddToFirstTrack
};
QString preGapTypeToString(PreGapType type);
PreGapType strToPreGapType(const QString &str, PreGapType def = PreGapType::AddToFirstTrack);
enum class GainType {
Disable,
Track,
Album
};
QString gainTypeToString(GainType type);
GainType strToGainType(const QString &str, GainType def = GainType::Disable);
enum class CoverMode {
Disable,
OrigSize,
Scale
};
QString coverModeToString(CoverMode mode);
CoverMode strToCoverMode(const QString &str, CoverMode def = CoverMode::Disable);
struct CoverOptions
{
CoverMode mode = CoverMode::Disable;
int size = 0;
};
unsigned int levenshteinDistance(const QString &s1, const QString &s2);
class FlaconError : public std::runtime_error
{
public:
explicit FlaconError(const char *msg) :
std::runtime_error(msg) { }
explicit FlaconError(const std::string &msg) :
std::runtime_error(msg) { }
explicit FlaconError(const QString &msg) :
std::runtime_error(msg.toStdString()) { }
};
class Abort : public std::runtime_error
{
public:
Abort() :
std::runtime_error("") { }
static void check() noexcept(false);
};
class CueTime
{
public:
explicit CueTime(const QString &str = "");
bool isNull() const { return mNull; }
QString toString(bool cdQuality = true) const;
CueTime operator+(const CueTime &other) const;
CueTime operator-(const CueTime &other) const;
bool operator==(const CueTime &other) const;
bool operator!=(const CueTime &other) const;
uint milliseconds() const { return mHiValue; }
uint frames() const { return mCdValue; }
private:
bool mNull = true;
int mCdValue = 0;
int mHiValue = 0;
bool parse(const QString &str);
};
class CueIndex : public ::CueTime
{
public:
CueIndex() = default;
explicit CueIndex(const QString &str, const QByteArray &file);
QByteArray file() const { return mFile; }
bool isEmpty() const { return mFile.isEmpty(); }
bool operator==(const CueIndex &other) const;
bool operator!=(const CueIndex &other) const;
private:
QByteArray mFile;
};
struct CueFlags
{
public:
CueFlags() = default;
CueFlags &operator=(const CueFlags &other) = default;
explicit CueFlags(const QString &tag);
QString toString() const;
bool isEmpty() const;
bool digitalCopyPermitted = false; /// DCP – Digital copy permitted
bool fourChannel = false; /// 4CH – Four channel audio
bool preEmphasis = false; /// PRE – Pre-emphasis enabled (audio tracks only)
bool serialCopyManagement = false; /// SCMS – Serial copy management system (not supported by all recorders)
};
enum class TrackState {
NotRunning = 0,
Canceled = 1,
Error = 2,
Aborted = 3,
OK = 4,
Splitting = 5,
Encoding = 6,
Queued = 7,
WaitGain = 8,
CalcGain = 9,
WriteGain = 10
};
Q_DECLARE_METATYPE(TrackState)
QString trackStateToString(TrackState state);
enum class DiskState {
NotRunning = 0,
Canceled = 1,
Error = 2,
Aborted = 3,
OK = 4,
Running = 5,
};
Q_DECLARE_METATYPE(DiskState)
DiskState calcDiskState(const QList<TrackState> &trackStates);
enum BitsPerSample {
AsSourcee = 0,
Bit_16 = 16,
Bit_24 = 24,
Bit_32 = 32,
Bit_64 = 64,
};
Q_DECLARE_METATYPE(BitsPerSample)
enum SampleRate {
AsSource = 0,
Hz_44100 = 44100,
Hz_48000 = 48000,
Hz_96000 = 96000,
Hz_192000 = 192000,
Hz_384000 = 384000,
Hz_768000 = 768000,
};
Q_DECLARE_METATYPE(SampleRate)
enum class FormatOption {
NoOptions = 0x0,
Lossless = 0x1,
SupportGain = 0x2,
SupportEmbeddedCue = 0x4,
SupportEmbeddedImage = 0x8,
};
Q_DECLARE_FLAGS(FormatOptions, FormatOption)
Q_DECLARE_OPERATORS_FOR_FLAGS(FormatOptions)
inline bool operator&&(const FormatOptions &flags, const FormatOption flag) noexcept
{
return flags.testFlag(flag);
}
int calcSampleRate(int input, SampleRate resample);
int calcQuality(int input, int preferences, int formatMax);
enum class ProxyType {
NoProxy,
HttpProxy,
Socks5Proxy,
};
QByteArray leftPart(const QByteArray &line, const char separator);
QByteArray rightPart(const QByteArray &line, const char separator);
void initTypes();
QString safeString(const QString &str);
QString debugProgramArgs(const QString &prog, const QStringList &args);
QString htmlToText(const QString &html);
class Messages
{
public:
static void error(const QString &message);
class Handler
{
public:
virtual void showErrorMessage(const QString &message) = 0;
};
static void setHandler(Handler *handler);
private:
static Handler *mHandler;
};
QString expandFilePath(const QString &path);
QString firstNotNullString(const QString &s1, const QString &s2);
QString firstNotNullString(const QString &s1, const QString &s2, const QString &s3);
QString firstNotEmptyString(const QString &s1, const QString &s2);
QString firstNotEmptyString(const QString &s1, const QString &s2, const QString &s3);
enum class ExitCodes {
Ok = 0,
ArgsError = 1,
NoInputFiles = 10,
ConverterError = 11,
ValidationError = 12,
};
#endif // TYPES_H