forked from flacon/flacon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.h
231 lines (188 loc) · 5.19 KB
/
types.h
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
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* Flacon - audio File Encoder
* https://github.com/flacon/flacon
*
* Copyright: 2017
* Alexander Sokoloff <sokoloff.a@gmail.com>
*
* 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>
#define CODEC_AUTODETECT "AUTODETECT"
typedef quint16 DiscNum;
typedef quint16 DiscCount;
typedef quint16 TrackNum;
typedef quint16 TrackCount;
typedef uint Duration;
enum class TagId {
Album,
Catalog,
CDTextfile,
Comment,
Date,
Flags,
Genre,
ISRC,
Artist,
SongWriter,
Title,
DiscId,
File,
DiscNum,
DiscCount,
CueFile,
AlbumArtist,
TrackNum,
TrackCount,
};
enum class PreGapType {
Skip,
ExtractToFile,
AddToFirstTrack
};
QString preGapTypeToString(PreGapType type);
PreGapType strToPreGapType(const QString &str);
enum class GainType {
Disable,
Track,
Album
};
QString gainTypeToString(GainType type);
GainType strToGainType(const QString &str);
enum class CoverMode {
Disable,
OrigSize,
Scale
};
QString coverModeToString(CoverMode mode);
CoverMode strToCoverMode(const QString &str);
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 CueIndex
{
public:
explicit CueIndex(const QString &str = "");
bool isNull() const { return mNull; }
QString toString(bool cdQuality = true) const;
CueIndex operator-(const CueIndex &other) const;
bool operator==(const CueIndex &other) const;
bool operator!=(const CueIndex &other) const;
uint milliseconds() const { return mHiValue; }
uint frames() const { return mCdValue; }
private:
bool mNull;
int mCdValue;
int mHiValue;
bool parse(const QString &str);
};
typedef CueIndex CueTime;
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)
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,
};
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);
typedef quint8 Percent;
typedef quint64 TrackId;
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);
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;
};
#endif // TYPES_H