mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
add CueSheet object wrapper
This commit is contained in:
@@ -564,7 +564,7 @@ namespace FLAC {
|
||||
|
||||
//! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
|
||||
//! \note Only the Entry's field name will be used.
|
||||
bool set_vendor_string(const Entry &entry); // only the Entry's field name will be used
|
||||
bool set_vendor_string(const Entry &entry);
|
||||
|
||||
//! See FLAC__metadata_object_vorbiscomment_set_comment()
|
||||
bool set_comment(unsigned index, const Entry &entry);
|
||||
@@ -576,6 +576,117 @@ namespace FLAC {
|
||||
bool delete_comment(unsigned index);
|
||||
};
|
||||
|
||||
/** CUESHEET metadata block.
|
||||
* See <A HREF="../format.html#metadata_block_cuesheet">format specification</A>.
|
||||
*/
|
||||
class FLACPP_API CueSheet : public Prototype {
|
||||
public:
|
||||
/** Convenience class for encapsulating a cue sheet
|
||||
* track.
|
||||
*
|
||||
* Always check is_valid() after the constructor or operator=
|
||||
* to make sure memory was properly allocated.
|
||||
*/
|
||||
class FLACPP_API Track {
|
||||
protected:
|
||||
::FLAC__StreamMetadata_CueSheet_Track *object_;
|
||||
public:
|
||||
Track();
|
||||
Track(const ::FLAC__StreamMetadata_CueSheet_Track *track);
|
||||
Track(const Track &track);
|
||||
void operator=(const Track &track);
|
||||
|
||||
virtual ~Track();
|
||||
|
||||
virtual bool is_valid() const;
|
||||
|
||||
inline FLAC__uint64 get_offset() const { return object_->offset; }
|
||||
inline FLAC__byte get_number() const { return object_->number; }
|
||||
inline const char *get_isrc() const { return object_->isrc; }
|
||||
inline unsigned get_type() const { return object_->type; }
|
||||
inline bool get_pre_emphasis() const { return object_->pre_emphasis; }
|
||||
|
||||
inline bool get_num_indices() const { return object_->num_indices; }
|
||||
::FLAC__StreamMetadata_CueSheet_Index get_index(unsigned i) const;
|
||||
|
||||
inline const ::FLAC__StreamMetadata_CueSheet_Track *get_track() const { return object_; }
|
||||
|
||||
inline void set_offset(FLAC__uint64 value) { object_->offset = value; }
|
||||
inline void set_number(FLAC__byte value) { object_->number = value; }
|
||||
void set_isrc(char value[12]);
|
||||
void set_type(unsigned value);
|
||||
inline void set_pre_emphasis(bool value) { object_->pre_emphasis = value? 1 : 0; }
|
||||
|
||||
void set_index(unsigned i, const ::FLAC__StreamMetadata_CueSheet_Index &index);
|
||||
};
|
||||
|
||||
CueSheet();
|
||||
|
||||
//@{
|
||||
/** Constructs a copy of the given object. This form
|
||||
* always performs a deep copy.
|
||||
*/
|
||||
inline CueSheet(const CueSheet &object): Prototype(object) { }
|
||||
inline CueSheet(const ::FLAC__StreamMetadata &object): Prototype(object) { }
|
||||
inline CueSheet(const ::FLAC__StreamMetadata *object): Prototype(object) { }
|
||||
//@}
|
||||
|
||||
/** Constructs an object with copy control. See
|
||||
* Prototype(::FLAC__StreamMetadata *object, bool copy).
|
||||
*/
|
||||
inline CueSheet(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
|
||||
|
||||
~CueSheet();
|
||||
|
||||
//@{
|
||||
/** Assign from another object. Always performs a deep copy. */
|
||||
inline void operator=(const CueSheet &object) { Prototype::operator=(object); }
|
||||
inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
|
||||
inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
|
||||
//@}
|
||||
|
||||
//@{
|
||||
/** Check for equality, performing a deep compare by following pointers. */
|
||||
inline bool operator==(const CueSheet &object) const { return Prototype::operator==(object); }
|
||||
inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
|
||||
inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
|
||||
//@}
|
||||
|
||||
//@{
|
||||
/** Check for inequality, performing a deep compare by following pointers. */
|
||||
inline bool operator!=(const CueSheet &object) const { return Prototype::operator!=(object); }
|
||||
inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
|
||||
inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
|
||||
//@}
|
||||
|
||||
const char *get_media_catalog_number() const;
|
||||
FLAC__uint64 get_lead_in() const;
|
||||
|
||||
unsigned get_num_tracks() const;
|
||||
Track get_track(unsigned i) const;
|
||||
|
||||
void set_media_catalog_number(char value[128]);
|
||||
void set_offset(FLAC__uint64 value);
|
||||
|
||||
//! See FLAC__metadata_object_cuesheet_track_insert_index()
|
||||
bool insert_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
|
||||
|
||||
//! See FLAC__metadata_object_cuesheet_track_delete_index()
|
||||
bool delete_index(unsigned track_num, unsigned index_num);
|
||||
|
||||
//! See FLAC__metadata_object_cuesheet_set_track()
|
||||
bool set_track(unsigned i, const Track &track);
|
||||
|
||||
//! See FLAC__metadata_object_cuesheet_insert_track()
|
||||
bool insert_track(unsigned i, const Track &track);
|
||||
|
||||
//! See FLAC__metadata_object_cuesheet_delete_track()
|
||||
bool delete_track(unsigned i);
|
||||
|
||||
//! See FLAC__metadata_object_cuesheet_is_legal()
|
||||
bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const;
|
||||
};
|
||||
|
||||
/* \} */
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,9 @@ namespace FLAC {
|
||||
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
|
||||
ret = new VorbisComment(object, /*copy=*/false);
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_CUESHEET:
|
||||
ret = new CueSheet(object, /*copy=*/false);
|
||||
break;
|
||||
default:
|
||||
FLAC__ASSERT(0);
|
||||
break;
|
||||
@@ -739,6 +742,138 @@ namespace FLAC {
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CueSheet::Track
|
||||
//
|
||||
|
||||
CueSheet::Track::Track():
|
||||
object_(::FLAC__metadata_object_cuesheet_track_new())
|
||||
{ }
|
||||
|
||||
CueSheet::Track::Track(const ::FLAC__StreamMetadata_CueSheet_Track *track):
|
||||
object_(::FLAC__metadata_object_cuesheet_track_clone(track))
|
||||
{ }
|
||||
|
||||
CueSheet::Track::Track(const Track &track):
|
||||
object_(::FLAC__metadata_object_cuesheet_track_clone(track.object_))
|
||||
{ }
|
||||
|
||||
void CueSheet::Track::operator=(const Track &track)
|
||||
{
|
||||
object_ = ::FLAC__metadata_object_cuesheet_track_clone(track.object_);
|
||||
}
|
||||
|
||||
CueSheet::Track::~Track()
|
||||
{
|
||||
if(0 != object_)
|
||||
delete object_;
|
||||
}
|
||||
|
||||
bool CueSheet::Track::is_valid() const
|
||||
{
|
||||
return(0 != object_);
|
||||
}
|
||||
|
||||
::FLAC__StreamMetadata_CueSheet_Index CueSheet::Track::get_index(unsigned i) const
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(i < object_->num_indices);
|
||||
return object_->indices[i];
|
||||
}
|
||||
|
||||
void CueSheet::Track::set_isrc(char value[12])
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(0 != value);
|
||||
memcpy(object_->isrc, value, 12);
|
||||
object_->isrc[12] = '\0';
|
||||
}
|
||||
|
||||
void CueSheet::Track::set_type(unsigned value)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(value <= 1);
|
||||
object_->type = value;
|
||||
}
|
||||
|
||||
void CueSheet::Track::set_index(unsigned i, const ::FLAC__StreamMetadata_CueSheet_Index &index)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(i < object_->num_indices);
|
||||
object_->indices[i] = index;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CueSheet
|
||||
//
|
||||
|
||||
CueSheet::CueSheet():
|
||||
Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET), /*copy=*/false)
|
||||
{ }
|
||||
|
||||
CueSheet::~CueSheet()
|
||||
{ }
|
||||
|
||||
unsigned CueSheet::get_num_tracks() const
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
return object_->data.cue_sheet.num_tracks;
|
||||
}
|
||||
|
||||
CueSheet::Track CueSheet::get_track(unsigned i) const
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks);
|
||||
return Track(object_->data.cue_sheet.tracks + i);
|
||||
}
|
||||
|
||||
bool CueSheet::insert_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks);
|
||||
FLAC__ASSERT(index_num <= object_->data.cue_sheet.tracks[track_num].num_indices);
|
||||
return (bool)::FLAC__metadata_object_cuesheet_track_insert_index(object_, track_num, index_num, index);
|
||||
}
|
||||
|
||||
bool CueSheet::delete_index(unsigned track_num, unsigned index_num)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks);
|
||||
FLAC__ASSERT(index_num < object_->data.cue_sheet.tracks[track_num].num_indices);
|
||||
return (bool)::FLAC__metadata_object_cuesheet_track_delete_index(object_, track_num, index_num);
|
||||
}
|
||||
|
||||
bool CueSheet::set_track(unsigned i, const CueSheet::Track &track)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks);
|
||||
// We can safely const_cast since copy=true
|
||||
return (bool)::FLAC__metadata_object_cuesheet_set_track(object_, i, const_cast< ::FLAC__StreamMetadata_CueSheet_Track*>(track.get_track()), /*copy=*/true);
|
||||
}
|
||||
|
||||
bool CueSheet::insert_track(unsigned i, const CueSheet::Track &track)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(i <= object_->data.cue_sheet.num_tracks);
|
||||
// We can safely const_cast since copy=true
|
||||
return (bool)::FLAC__metadata_object_cuesheet_insert_track(object_, i, const_cast< ::FLAC__StreamMetadata_CueSheet_Track*>(track.get_track()), /*copy=*/true);
|
||||
}
|
||||
|
||||
bool CueSheet::delete_track(unsigned i)
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks);
|
||||
return (bool)::FLAC__metadata_object_cuesheet_delete_track(object_, i);
|
||||
}
|
||||
|
||||
bool CueSheet::is_legal(bool check_cd_da_subset, const char **violation) const
|
||||
{
|
||||
FLAC__ASSERT(is_valid());
|
||||
return (bool)::FLAC__metadata_object_cuesheet_is_legal(object_, check_cd_da_subset, violation);
|
||||
}
|
||||
|
||||
|
||||
// ============================================================
|
||||
//
|
||||
// Level 0
|
||||
|
||||
Reference in New Issue
Block a user