-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcueparser.h
More file actions
187 lines (166 loc) · 7.39 KB
/
cueparser.h
File metadata and controls
187 lines (166 loc) · 7.39 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
/**
* Copyright (C) 2023 Jo2003 (olenka.joerg@gmail.com)
* This file is part of cd2netmd_gui (NetMD Wizard)
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NetMD Wizard 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*/
#pragma once
#include "audio.h"
#include <QString>
#include <QTextStream>
#include <QVector>
//------------------------------------------------------------------------------
//! @brief This class describes a simple cue parser.
//------------------------------------------------------------------------------
class CueParser
{
public:
//--------------------------------------------------------------------------
//! @brief track type
//--------------------------------------------------------------------------
using TrackType = c2n::TrackType;
//--------------------------------------------------------------------------
//! @brief describes an audio track
//--------------------------------------------------------------------------
struct Track
{
int mNo; ///< track number (not index based)
TrackType mType; ///< type \a TrackType
QString mTitle; ///< track title
QString mPerformer; ///< artist / performer
QString mAudioFile; ///< audio file name
uint32_t mStartMs; ///< start position in ms related to audio file
uint32_t mEndMs; ///< end position related to audio file
uint32_t mStartLba; ///< start sector relative to pseudo CD
uint32_t mLbaCount; ///< length in LBA
uint32_t mConversion; ///< any conversion needed?
//----------------------------------------------------------------------
//! @brief Qstring conversion operator.
//----------------------------------------------------------------------
operator QString() const
{
QString s;
QTextStream ts(&s);
ts << mNo << ") " << (!mPerformer.isEmpty() ? (mPerformer + " - ") : "") << mTitle << Qt::endl
<< "\tFile: " << mAudioFile << ", type: " << ((mType == TrackType::AUDIO) ? "AUDIO" : "DATA") << Qt::endl
<< "\ttime: " << mStartMs << " ms ... " << mEndMs
<< " ms, lba start: " << mStartLba << ", count: " << mLbaCount
<< ", conv.: " << QString::number(mConversion, 16) << "h";
return s;
}
};
//--------------------------------------------------------------------------
//! @brief describes an audio disc (CD)
//--------------------------------------------------------------------------
struct Disc
{
QString mTitle; ///< disc title
QString mPerformer; ///< disc performer 7 artist
uint32_t mLenInMs; ///< disc length in ms
int mYear; ///< year
QVector<Track> mTracks; ///< audio tracks
//----------------------------------------------------------------------
//! @brief Qstring conversion operator.
//----------------------------------------------------------------------
operator QString() const
{
QString s;
QTextStream ts(&s);
ts << (!mPerformer.isEmpty() ? (mPerformer + " - ") : "") << mTitle;
if (mYear > 0)
{
ts << ", Year: " << mYear;
}
ts << " (" << mLenInMs << " ms)" << Qt::endl;
for (const auto& t : mTracks)
{
ts << static_cast<QString>(t) << Qt::endl;
}
return s;
}
};
//--------------------------------------------------------------------------
//! @brief Constructs a new instance.
//!
//! @param[in] cueFileName The cue file name
//--------------------------------------------------------------------------
CueParser(const QString& cueFileName = "");
//--------------------------------------------------------------------------
//! @brief parse the cue file
//!
//! @param[in] cueFileName The cue file name
//!
//! @return 0 on success; < 0 on error
//--------------------------------------------------------------------------
int parse(const QString& cueFileName);
//--------------------------------------------------------------------------
//! @brief get track count
//!
//! @return number of tracks
//--------------------------------------------------------------------------
int trackCount() const;
//--------------------------------------------------------------------------
//! @brief git disc title
//!
//! @return title as string
//--------------------------------------------------------------------------
const QString& discTitle() const;
//--------------------------------------------------------------------------
//! @brief get disc artist / performer
//!
//! @return artist as string
//--------------------------------------------------------------------------
const QString& discPerfromer() const;
//--------------------------------------------------------------------------
//! @brief get disc audio length in ms
//!
//! @return length in ms
//--------------------------------------------------------------------------
uint32_t discLength() const;
//--------------------------------------------------------------------------
//! @brief get disc year
//!
//! @return year
//--------------------------------------------------------------------------
int discYear() const;
//--------------------------------------------------------------------------
//! @brief get complete track information
//!
//! @param[in] no track number, starts with 1
//!
//! @return track information or empty struct
//--------------------------------------------------------------------------
const Track& track(int no) const;
//--------------------------------------------------------------------------
//! @brief sanity check in Disc structure
//!
//! @return true if valid; false if not
//--------------------------------------------------------------------------
bool isValid() const;
//--------------------------------------------------------------------------
//! @brief find the audio file, try some simple searches
//!
//! @param[in] path where to look for the audio file
//! @param[in,out] file name as searched / found
//!
//! @return true file found, false not found
//--------------------------------------------------------------------------
bool findAudioFile(const QString& path, QString& fileName) const;
private:
/// stores disc information
Disc mDiscData{"", "", 0, -1, {}};
/// stores an empty track
Track mEmptyTrack{-1, TrackType::DATA, "", "", "", 0, 0, 0, 0, 0};
/// validness flag
bool mValid{false};
};