Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/util/cue_parser.h
4223 views
1
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#pragma once
5
#include "cd_image.h"
6
#include "common/types.h"
7
#include <optional>
8
#include <string_view>
9
#include <utility>
10
#include <vector>
11
12
namespace Common {
13
class Error;
14
}
15
16
namespace CueParser {
17
18
using TrackMode = CDImage::TrackMode;
19
using MSF = CDImage::Position;
20
21
enum : s32
22
{
23
MIN_TRACK_NUMBER = 1,
24
MAX_TRACK_NUMBER = 99,
25
MIN_INDEX_NUMBER = 0,
26
MAX_INDEX_NUMBER = 99
27
};
28
29
enum class TrackFlag : u8
30
{
31
PreEmphasis = (1 << 0),
32
CopyPermitted = (1 << 1),
33
FourChannelAudio = (1 << 2),
34
SerialCopyManagement = (1 << 3),
35
};
36
37
enum class FileFormat : u8
38
{
39
Binary,
40
Wave,
41
MaxCount
42
};
43
44
struct Track
45
{
46
u8 number;
47
u8 flags;
48
TrackMode mode;
49
FileFormat file_format;
50
std::string file;
51
std::vector<std::pair<u32, MSF>> indices;
52
MSF start;
53
std::optional<MSF> length;
54
std::optional<MSF> zero_pregap;
55
56
const MSF* GetIndex(u32 n) const;
57
58
ALWAYS_INLINE bool HasFlag(TrackFlag flag) const { return (flags & static_cast<u32>(flag)) != 0; }
59
ALWAYS_INLINE void SetFlag(TrackFlag flag) { flags |= static_cast<u32>(flag); }
60
ALWAYS_INLINE void RemoveFlag(TrackFlag flag) { flags &= ~static_cast<u32>(flag); }
61
};
62
63
class File
64
{
65
public:
66
File();
67
~File();
68
69
const Track* GetTrack(u32 n) const;
70
71
bool Parse(std::FILE* fp, Error* error);
72
73
private:
74
Track* GetMutableTrack(u32 n);
75
76
void SetError(u32 line_number, Error* error, const char* format, ...);
77
78
static std::string_view GetToken(const char*& line);
79
static std::optional<MSF> GetMSF(std::string_view token);
80
81
bool ParseLine(const char* line, u32 line_number, Error* error);
82
83
bool HandleFileCommand(const char* line, u32 line_number, Error* error);
84
bool HandleTrackCommand(const char* line, u32 line_number, Error* error);
85
bool HandleIndexCommand(const char* line, u32 line_number, Error* error);
86
bool HandlePregapCommand(const char* line, u32 line_number, Error* error);
87
bool HandleFlagCommand(const char* line, u32 line_number, Error* error);
88
89
bool CompleteLastTrack(u32 line_number, Error* error);
90
bool SetTrackLengths(u32 line_number, Error* error);
91
92
std::vector<Track> m_tracks;
93
std::optional<std::pair<std::string, FileFormat>> m_current_file;
94
std::optional<Track> m_current_track;
95
};
96
97
} // namespace CueParser
98