Skip to content

Commit

Permalink
Cleared up namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Peking Duck committed Apr 1, 2014
1 parent 6565e49 commit 5f79eb1
Show file tree
Hide file tree
Showing 7 changed files with 522 additions and 525 deletions.
106 changes: 58 additions & 48 deletions src/dsffile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
#include "dsffile.h"
#include "dsfheader.h"

using namespace TagLib;
//using namespace TagLib;

class DSF::File::FilePrivate
class DSFFile::FilePrivate
{
public:
FilePrivate(ID3v2::FrameFactory *frameFactory = ID3v2::FrameFactory::instance()) :
FilePrivate(TagLib::ID3v2::FrameFactory *frameFactory
= TagLib::ID3v2::FrameFactory::instance()) :
ID3v2FrameFactory(frameFactory),
ID3v2Location(0),
ID3v2OriginalSize(0),
Expand All @@ -49,7 +50,7 @@ class DSF::File::FilePrivate
if (tag) delete tag;
}

const ID3v2::FrameFactory *ID3v2FrameFactory;
const TagLib::ID3v2::FrameFactory *ID3v2FrameFactory;

uint64_t ID3v2Location; // For DSD it's always > 0 if tag is present
uint64_t ID3v2OriginalSize;
Expand All @@ -61,9 +62,11 @@ class DSF::File::FilePrivate

bool hasID3v2;

Properties *properties;
DSFProperties *properties;

static inline ByteVector& uint64ToVector(uint64_t num, ByteVector &v) {
static inline TagLib::ByteVector& uint64ToVector(uint64_t num,
TagLib::ByteVector &v)
{
char raw[8];

for (int i = 0; i < 8; i++) {
Expand All @@ -86,16 +89,16 @@ class DSF::File::FilePrivate
void shrinkTag();
};

void DSF::File::FilePrivate::shrinkTag() {
ID3v2::FrameList olist = tag->frameList();
ID3v2::FrameList nlist;
ID3v2::FrameList::ConstIterator it;
void DSFFile::FilePrivate::shrinkTag() {
TagLib::ID3v2::FrameList olist = tag->frameList();
TagLib::ID3v2::FrameList nlist;
TagLib::ID3v2::FrameList::ConstIterator it;

for (it = olist.begin(); it != olist.end(); it++) {
nlist.append(*it);
}

ID3v2::Tag *ntag = new ID3v2::Tag();
TagLib::ID3v2::Tag *ntag = new TagLib::ID3v2::Tag();
for (it = nlist.begin(); it != nlist.end(); it++) {
tag->removeFrame(*it, false); // Don't delete, just transfer the ownership
ntag->addFrame(*it);
Expand All @@ -110,17 +113,20 @@ void DSF::File::FilePrivate::shrinkTag() {
// public members
////////////////////////////////////////////////////////////////////////////////

DSF::File::File(FileName file, bool readProperties,
Properties::ReadStyle propertiesStyle) : TagLib::File(file)
DSFFile::DSFFile(TagLib::FileName file, bool readProperties,
TagLib::AudioProperties::ReadStyle propertiesStyle)
: TagLib::File(file)
{
d = new FilePrivate;

if(isOpen())
read(readProperties, propertiesStyle);
}

DSF::File::File(FileName file, ID3v2::FrameFactory *frameFactory,
bool readProperties, Properties::ReadStyle propertiesStyle) :
DSFFile::DSFFile(TagLib::FileName file,
TagLib::ID3v2::FrameFactory *frameFactory,
bool readProperties,
TagLib::AudioProperties::ReadStyle propertiesStyle) :
TagLib::File(file)
{
d = new FilePrivate(frameFactory);
Expand All @@ -129,8 +135,10 @@ DSF::File::File(FileName file, ID3v2::FrameFactory *frameFactory,
read(readProperties, propertiesStyle);
}

DSF::File::File(IOStream *stream, ID3v2::FrameFactory *frameFactory,
bool readProperties, Properties::ReadStyle propertiesStyle) :
DSFFile::DSFFile(TagLib::IOStream *stream,
TagLib::ID3v2::FrameFactory *frameFactory,
bool readProperties,
TagLib::AudioProperties::ReadStyle propertiesStyle) :
TagLib::File(stream)
{
d = new FilePrivate(frameFactory);
Expand All @@ -139,48 +147,48 @@ DSF::File::File(IOStream *stream, ID3v2::FrameFactory *frameFactory,
read(readProperties, propertiesStyle);
}

DSF::File::~File()
DSFFile::~DSFFile()
{
delete d;
}

TagLib::Tag *DSF::File::tag() const
TagLib::Tag *DSFFile::tag() const
{
return d->tag;
}

PropertyMap DSF::File::properties() const
TagLib::PropertyMap DSFFile::properties() const
{
if(d->hasID3v2)
return d->tag->properties();
return PropertyMap();
return TagLib::PropertyMap();
}

void DSF::File::removeUnsupportedProperties(const StringList &properties)
void DSFFile::removeUnsupportedProperties(const TagLib::StringList &properties)
{
if(d->hasID3v2)
d->tag->removeUnsupportedProperties(properties);
}

PropertyMap DSF::File::setProperties(const PropertyMap &properties)
TagLib::PropertyMap DSFFile::setProperties(const TagLib::PropertyMap &properties)
{
return d->tag->setProperties(properties);
}

DSF::Properties *DSF::File::audioProperties() const
TagLib::AudioProperties *DSFFile::audioProperties() const
{
return d->properties;
}

bool DSF::File::save()
bool DSFFile::save()
{
return save(4);
}

bool DSF::File::save(int id3v2Version, bool shrink)
bool DSFFile::save(int id3v2Version, bool shrink)
{
if(readOnly()) {
std::cerr << "DSF::File::save() -- File is read only." << std::endl;
std::cerr << "DSFFile::save() -- File is read only." << std::endl;
return false;
}

Expand All @@ -190,22 +198,22 @@ bool DSF::File::save(int id3v2Version, bool shrink)
if (shrink) // remove padding 0's
d->shrinkTag();

ByteVector id3v2_v = ID3v2Tag()->render(id3v2Version);
TagLib::ByteVector id3v2_v = ID3v2Tag()->render(id3v2Version);
uint64_t fileSize = d->fileSize + id3v2_v.size() - d->ID3v2OriginalSize;
ByteVector fileSize_v;
TagLib::ByteVector fileSize_v;

// Write new file size to DSD header
DSF::File::FilePrivate::uint64ToVector(fileSize, fileSize_v);
insert(fileSize_v, 12, DSF::Header::LONG_INT_SIZE);
DSFFile::FilePrivate::uint64ToVector(fileSize, fileSize_v);
insert(fileSize_v, 12, DSFHeader::LONG_INT_SIZE);

// The file didn't have an ID3v2 metadata block
// Make the offset point to the end of file
if (d->ID3v2Location == 0) {
d->ID3v2Location = d->fileSize;

ByteVector offset_v;
DSF::File::FilePrivate::uint64ToVector(d->fileSize, offset_v);
insert(offset_v, 20, DSF::Header::LONG_INT_SIZE);
TagLib::ByteVector offset_v;
DSFFile::FilePrivate::uint64ToVector(d->fileSize, offset_v);
insert(offset_v, 20, DSFHeader::LONG_INT_SIZE);
}

// Write ID3v2 to the end of the file
Expand All @@ -220,12 +228,12 @@ bool DSF::File::save(int id3v2Version, bool shrink)
// All frames have been deleted. Remove ID3v2 block
//

ByteVector nulls_v(DSF::Header::LONG_INT_SIZE, 0); // a bunch of zeroes
ByteVector fileSize_v;
TagLib::ByteVector nulls_v(DSFHeader::LONG_INT_SIZE, 0);
TagLib::ByteVector fileSize_v;

DSF::File::FilePrivate::uint64ToVector(d->ID3v2Location, fileSize_v);
insert(fileSize_v, 12, DSF::Header::LONG_INT_SIZE); // new file size
insert(nulls_v, 20, DSF::Header::LONG_INT_SIZE); // set metadata offset to 0
DSFFile::FilePrivate::uint64ToVector(d->ID3v2Location, fileSize_v);
insert(fileSize_v, 12, DSFHeader::LONG_INT_SIZE); // new file size
insert(nulls_v, 20, DSFHeader::LONG_INT_SIZE); // set metadata offset to 0
removeBlock(d->ID3v2Location, d->ID3v2OriginalSize);

// Reset header info
Expand All @@ -237,22 +245,23 @@ bool DSF::File::save(int id3v2Version, bool shrink)

// Reinitialize properties because DSD header may have been changed
delete d->properties;
d->properties = new Properties(this, Properties::Average);
d->properties = new DSFProperties(this,
TagLib::AudioProperties::Average);

return success;
}

ID3v2::Tag *DSF::File::ID3v2Tag() const
TagLib::ID3v2::Tag *DSFFile::ID3v2Tag() const
{
return d->tag;
}

void DSF::File::setID3v2FrameFactory(const ID3v2::FrameFactory *factory)
void DSFFile::setID3v2FrameFactory(const TagLib::ID3v2::FrameFactory *factory)
{
d->ID3v2FrameFactory = factory;
}

bool DSF::File::hasID3v2Tag() const
bool DSFFile::hasID3v2Tag() const
{
return d->hasID3v2;
}
Expand All @@ -261,30 +270,31 @@ bool DSF::File::hasID3v2Tag() const
// private members
////////////////////////////////////////////////////////////////////////////////

bool DSF::File::secondSynchByte(char byte)
bool DSFFile::secondSynchByte(char byte)
{
std::bitset<8> b(byte);

// check to see if the byte matches 111xxxxx
return b.test(7) && b.test(6) && b.test(5);
}

void DSF::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
void DSFFile::read(bool readProperties,
TagLib::AudioProperties::ReadStyle propertiesStyle)
{
if(readProperties)
d->properties = new Properties(this, propertiesStyle);
d->properties = new DSFProperties(this, propertiesStyle);

d->ID3v2Location = d->properties->ID3v2Offset();
d->fileSize = d->properties->fileSize();

if(d->ID3v2Location > 0) {
d->tag = new ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory);
d->tag = new TagLib::ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory);
d->ID3v2OriginalSize = d->tag->header()->completeTagSize();

if(d->tag->header()->tagSize() > 0)
d->hasID3v2 = true;
} else {
// No ID3v2 Tag found, create an empty object.
d->tag = new ID3v2::Tag();
d->tag = new TagLib::ID3v2::Tag();
}
}
Loading

0 comments on commit 5f79eb1

Please sign in to comment.