Tag Parser: flac/flacmetadata.h Source File

Tag Parser 12.5.2 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
flacmetadata.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_FLACMETADATAHEADER_H
2#define TAG_PARSER_FLACMETADATAHEADER_H
3
4#include "../global.h"
5
6#include <cstdint>
7#include <iostream>
8
9namespace TagParser {
10
11class TagValue;
12
16 enum class FlacMetaDataBlockType : std::uint8_t { StreamInfo = 0, Padding, Application, SeekTable, VorbisComment, CuseSheet, Picture };
17
18 constexpr bool operator==(std::uint8_t lhs, FlacMetaDataBlockType type)
19{
20 return lhs == static_cast<std::uint8_t>(type);
21}
22
23 constexpr bool operator!=(std::uint8_t lhs, FlacMetaDataBlockType type)
24{
25 return lhs != static_cast<std::uint8_t>(type);
26}
27
28 class TAG_PARSER_EXPORT FlacMetaDataBlockHeader {
29public:
30 constexpr FlacMetaDataBlockHeader();
31
32 void parseHeader(std::string_view buffer);
33 void makeHeader(std::ostream &outputStream);
34
35 constexpr std::uint8_t isLast() const;
36 void setLast(std::uint8_t last);
37 constexpr std::uint8_t type() const;
38 void setType(FlacMetaDataBlockType type);
39 constexpr std::uint32_t dataSize() const;
40 void setDataSize(std::uint32_t dataSize);
41
42private:
43 std::uint8_t m_last;
44 std::uint8_t m_type;
45 std::uint32_t m_dataSize;
46};
47
51 constexpr FlacMetaDataBlockHeader::FlacMetaDataBlockHeader()
52 : m_last(0)
53 , m_type(0)
54 , m_dataSize(0)
55{
56}
57
62 constexpr std::uint8_t FlacMetaDataBlockHeader::isLast() const
63{
64 return m_last;
65}
66
70 inline void FlacMetaDataBlockHeader::setLast(std::uint8_t last)
71{
72 m_last = last;
73}
74
79 constexpr std::uint8_t FlacMetaDataBlockHeader::type() const
80{
81 return m_type;
82}
83
87 inline void FlacMetaDataBlockHeader::setType(FlacMetaDataBlockType type)
88{
89 m_type = static_cast<std::uint8_t>(type);
90}
91
95 constexpr std::uint32_t FlacMetaDataBlockHeader::dataSize() const
96{
97 return m_dataSize;
98}
99
104 inline void FlacMetaDataBlockHeader::setDataSize(std::uint32_t dataSize)
105{
106 m_dataSize = dataSize;
107}
108
109 class TAG_PARSER_EXPORT FlacMetaDataBlockStreamInfo {
110public:
111 constexpr FlacMetaDataBlockStreamInfo();
112
113 void parse(std::string_view buffer);
114
115 constexpr std::uint16_t minBlockSize() const;
116 constexpr std::uint16_t maxBlockSize() const;
117 constexpr std::uint32_t minFrameSize() const;
118 constexpr std::uint32_t maxFrameSize() const;
119 constexpr std::uint32_t samplingFrequency() const;
120 constexpr std::uint8_t channelCount() const;
121 constexpr std::uint8_t bitsPerSample() const;
122 constexpr std::uint64_t totalSampleCount() const;
123 constexpr const char *md5Sum() const;
124
125private:
126 std::uint16_t m_minBlockSize;
127 std::uint16_t m_maxBlockSize;
128 std::uint32_t m_minFrameSize;
129 std::uint32_t m_maxFrameSize;
130 std::uint32_t m_samplingFrequency;
131 std::uint8_t m_channelCount;
132 std::uint8_t m_bitsPerSample;
133 std::uint64_t m_totalSampleCount;
134 char m_md5Sum[16];
135};
136
140 constexpr FlacMetaDataBlockStreamInfo::FlacMetaDataBlockStreamInfo()
141 : m_minBlockSize(0)
142 , m_maxBlockSize(0)
143 , m_minFrameSize(0)
144 , m_maxFrameSize(0)
145 , m_samplingFrequency(0)
146 , m_channelCount(0)
147 , m_bitsPerSample(0)
148 , m_totalSampleCount(0)
149 , m_md5Sum{ 0 }
150{
151}
152
156 constexpr std::uint16_t FlacMetaDataBlockStreamInfo::minBlockSize() const
157{
158 return m_minBlockSize;
159}
160
166 constexpr std::uint16_t FlacMetaDataBlockStreamInfo::maxBlockSize() const
167{
168 return m_maxBlockSize;
169}
170
176 constexpr std::uint32_t FlacMetaDataBlockStreamInfo::minFrameSize() const
177{
178 return m_minFrameSize;
179}
180
186 constexpr std::uint32_t FlacMetaDataBlockStreamInfo::maxFrameSize() const
187{
188 return m_maxFrameSize;
189}
190
197 constexpr std::uint32_t FlacMetaDataBlockStreamInfo::samplingFrequency() const
198{
199 return m_samplingFrequency;
200}
201
207 constexpr std::uint8_t FlacMetaDataBlockStreamInfo::channelCount() const
208{
209 return m_channelCount;
210}
211
219 constexpr std::uint8_t FlacMetaDataBlockStreamInfo::bitsPerSample() const
220{
221 return m_bitsPerSample;
222}
223
232 constexpr std::uint64_t FlacMetaDataBlockStreamInfo::totalSampleCount() const
233{
234 return m_totalSampleCount;
235}
236
243 constexpr const char *FlacMetaDataBlockStreamInfo::md5Sum() const
244{
245 return m_md5Sum;
246}
247
248 class TAG_PARSER_EXPORT FlacMetaDataBlockPicture {
249public:
250 FlacMetaDataBlockPicture(TagValue &tagValue);
251
252 void parse(std::istream &inputStream, std::uint32_t maxSize);
253 std::uint32_t requiredSize() const;
254 void make(std::ostream &outputStream);
255
256 std::uint32_t pictureType() const;
257 void setPictureType(std::uint32_t pictureType);
258 TagValue &value();
259
260private:
261 std::uint32_t m_pictureType;
262 TagValue &m_value;
263};
264
272 inline FlacMetaDataBlockPicture::FlacMetaDataBlockPicture(TagValue &tagValue)
273 : m_pictureType(0)
274 , m_value(tagValue)
275{
276}
277
281 inline std::uint32_t FlacMetaDataBlockPicture::pictureType() const
282{
283 return m_pictureType;
284}
285
289 inline void FlacMetaDataBlockPicture::setPictureType(std::uint32_t pictureType)
290{
291 m_pictureType = pictureType;
292}
293
297 inline TagValue &FlacMetaDataBlockPicture::value()
298{
299 return m_value;
300}
301
302} // namespace TagParser
303
304#endif // TAG_PARSER_FLACMETADATAHEADER_H
TagParser::FlacMetaDataBlockHeader::dataSize
constexpr std::uint32_t dataSize() const
Returns the length in bytes of the meta data (excluding the size of the header itself).
Definition flacmetadata.h:95
TagParser::FlacMetaDataBlockHeader::setType
void setType(FlacMetaDataBlockType type)
Sets the block type.
Definition flacmetadata.h:87
TagParser::FlacMetaDataBlockHeader::type
constexpr std::uint8_t type() const
Returns the block type.
Definition flacmetadata.h:79
TagParser::FlacMetaDataBlockHeader::setLast
void setLast(std::uint8_t last)
Sets whether this is the last metadata block before the audio blocks.
Definition flacmetadata.h:70
TagParser::FlacMetaDataBlockHeader::isLast
constexpr std::uint8_t isLast() const
Returns whether this is the last metadata block before the audio blocks.
Definition flacmetadata.h:62
TagParser::FlacMetaDataBlockHeader::setDataSize
void setDataSize(std::uint32_t dataSize)
Sets the length in bytes of the meta data (excluding the size of the header itself).
Definition flacmetadata.h:104
TagParser::FlacMetaDataBlockHeader::parseHeader
void parseHeader(std::string_view buffer)
Parses the FLAC "METADATA_BLOCK_HEADER" which is read using the specified iterator.
Definition flacmetadata.cpp:29
TagParser::FlacMetaDataBlockHeader::FlacMetaDataBlockHeader
constexpr FlacMetaDataBlockHeader()
Constructs a new FLAC "METADATA_BLOCK_HEADER".
Definition flacmetadata.h:51
TagParser::FlacMetaDataBlockHeader::makeHeader
void makeHeader(std::ostream &outputStream)
Writes the header to the specified outputStream.
Definition flacmetadata.cpp:40
TagParser::FlacMetaDataBlockPicture::requiredSize
std::uint32_t requiredSize() const
Returns the number of bytes make() will write.
Definition flacmetadata.cpp:112
TagParser::FlacMetaDataBlockPicture::make
void make(std::ostream &outputStream)
Makes the FLAC "METADATA_BLOCK_PICTURE".
Definition flacmetadata.cpp:125
TagParser::FlacMetaDataBlockPicture::setPictureType
void setPictureType(std::uint32_t pictureType)
Sets the picture type according to the ID3v2 APIC frame.
Definition flacmetadata.h:289
TagParser::FlacMetaDataBlockPicture::parse
void parse(std::istream &inputStream, std::uint32_t maxSize)
Parses the FLAC "METADATA_BLOCK_PICTURE".
Definition flacmetadata.cpp:83
TagParser::FlacMetaDataBlockPicture::FlacMetaDataBlockPicture
FlacMetaDataBlockPicture(TagValue &tagValue)
Constructs a new FLAC "METADATA_BLOCK_PICTURE".
Definition flacmetadata.h:272
TagParser::FlacMetaDataBlockPicture::pictureType
std::uint32_t pictureType() const
Returns the picture type according to the ID3v2 APIC frame.
Definition flacmetadata.h:281
TagParser::FlacMetaDataBlockPicture::value
TagValue & value()
Returns the tag value the picture is read from/stored to.
Definition flacmetadata.h:297
TagParser::FlacMetaDataBlockStreamInfo::totalSampleCount
constexpr std::uint64_t totalSampleCount() const
Returns the total samples in stream.
Definition flacmetadata.h:232
TagParser::FlacMetaDataBlockStreamInfo::md5Sum
constexpr const char * md5Sum() const
Returns the MD5 signature of the unencoded audio data.
Definition flacmetadata.h:243
TagParser::FlacMetaDataBlockStreamInfo::samplingFrequency
constexpr std::uint32_t samplingFrequency() const
Returns the sampling frequency in Hz.
Definition flacmetadata.h:197
TagParser::FlacMetaDataBlockStreamInfo::maxBlockSize
constexpr std::uint16_t maxBlockSize() const
Returns the maximum block size (in samples) used in the stream.
Definition flacmetadata.h:166
TagParser::FlacMetaDataBlockStreamInfo::maxFrameSize
constexpr std::uint32_t maxFrameSize() const
The maximum frame size (in bytes) used in the stream.
Definition flacmetadata.h:186
TagParser::FlacMetaDataBlockStreamInfo::minFrameSize
constexpr std::uint32_t minFrameSize() const
Returns the minimum frame size (in bytes) used in the stream.
Definition flacmetadata.h:176
TagParser::FlacMetaDataBlockStreamInfo::FlacMetaDataBlockStreamInfo
constexpr FlacMetaDataBlockStreamInfo()
Constructs a new FLAC "METADATA_BLOCK_STREAMINFO".
Definition flacmetadata.h:140
TagParser::FlacMetaDataBlockStreamInfo::bitsPerSample
constexpr std::uint8_t bitsPerSample() const
Returns the bits per sample.
Definition flacmetadata.h:219
TagParser::FlacMetaDataBlockStreamInfo::minBlockSize
constexpr std::uint16_t minBlockSize() const
Returns the minimum block size (in samples) used in the stream.
Definition flacmetadata.h:156
TagParser::FlacMetaDataBlockStreamInfo::channelCount
constexpr std::uint8_t channelCount() const
Returns the number of channels.
Definition flacmetadata.h:207
TagParser::FlacMetaDataBlockStreamInfo::parse
void parse(std::string_view buffer)
Parses the FLAC "METADATA_BLOCK_STREAMINFO" which is read using the specified iterator.
Definition flacmetadata.cpp:58
TagParser::TagValue
The TagValue class wraps values of different types.
Definition tagvalue.h:147
TagParser::VorbisComment
Implementation of TagParser::Tag for Vorbis comments.
Definition vorbiscomment.h:27
global.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::FlacMetaDataBlockType
FlacMetaDataBlockType
The FlacMetaDataBlockType enum specifies the type of FlacMetaDataBlockHeader.
Definition flacmetadata.h:16
TagParser::FlacMetaDataBlockType::SeekTable
@ SeekTable
Definition flacmetadata.h:16
TagParser::FlacMetaDataBlockType::Picture
@ Picture
Definition flacmetadata.h:16
TagParser::FlacMetaDataBlockType::Padding
@ Padding
Definition flacmetadata.h:16
TagParser::FlacMetaDataBlockType::CuseSheet
@ CuseSheet
Definition flacmetadata.h:16
TagParser::FlacMetaDataBlockType::Application
@ Application
Definition flacmetadata.h:16
TagParser::FlacMetaDataBlockType::StreamInfo
@ StreamInfo
Definition flacmetadata.h:16
TagParser::operator!=
constexpr bool operator!=(std::uint8_t lhs, FlacMetaDataBlockType type)
Definition flacmetadata.h:23
TagParser::operator==
constexpr bool operator==(std::uint8_t lhs, FlacMetaDataBlockType type)
Definition flacmetadata.h:18