refactored for ABI compat and write support of some tags of s3m/it/xm files

tags that can be written:
 * s3m: title
 * it: title
 * xm: title, trackerName
This commit is contained in:
Mathias Panzenböck
2011-06-14 00:46:23 +02:00
parent 5332fb5cf8
commit f6dbd32ed3
25 changed files with 1457 additions and 734 deletions

View File

@ -21,69 +21,58 @@
#include "modfile.h"
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#endif
using namespace TagLib;
using namespace Mod;
namespace TagLib {
namespace Mod {
ByteVector File::readBytes(unsigned long size) {
ByteVector data(readBlock(size));
if (data.size() != size) throw ReadError();
return data;
Mod::File::File(FileName file) : TagLib::File(file)
{
}
String File::readString(unsigned long size) {
ByteVector data(readBytes(size));
Mod::File::File(IOStream *stream) : TagLib::File(stream)
{
}
void Mod::File::writeString(const String &s, ulong size)
{
ByteVector data(s.data(String::Latin1));
data.resize(size, 0);
writeBlock(data);
}
bool Mod::File::readString(String &s, ulong size)
{
ByteVector data(readBlock(size));
if(data.size() < size) return false;
int index = data.find((char) 0);
if (index > -1) {
if(index > -1)
{
data.resize(index);
}
data.replace((char) 0xff, ' ');
return String(data);
s = data;
return true;
}
uint8_t File::readByte() {
return readBytes(1)[0];
bool Mod::File::readByte(uchar &byte)
{
ByteVector data(readBlock(1));
if(data.size() < 1) return false;
byte = data[0];
return true;
}
#ifdef HAVE_ENDIAN_H
uint16_t File::readU16B() {
return be16toh(*(uint16_t*) readBytes(2).data());
bool Mod::File::readU16L(ushort &number)
{
ByteVector data(readBlock(2));
if(data.size() < 2) return false;
number = data.toUShort(false);
return true;
}
uint16_t File::readU16L() {
return le16toh(*(uint16_t*) readBytes(2).data());
}
uint32_t File::readU32B() {
return be32toh(*(uint32_t*) readBytes(4).data());
}
uint32_t File::readU32L() {
return le32toh(*(uint32_t*) readBytes(4).data());
}
#else
uint16_t File::readU16B() {
return readBytes(2).toUShort(true);
}
uint16_t File::readU16L() {
return readBytes(2).toUShort(false);
}
// XXX: who knows if this works if sizeof(int) > 4?
uint32_t File::readU32B() {
return readBytes(4).toUInt(true);
}
uint32_t File::readU32L() {
return readBytes(4).toUInt(false);
}
#endif
}
bool Mod::File::readU32L(ulong &number) {
ByteVector data(readBlock(4));
if(data.size() < 4) return false;
number = data.toUInt(false);
return true;
}

View File

@ -22,28 +22,23 @@
#ifndef TAGLIB_MODFILE_H
#define TAGLIB_MODFILE_H
#include <stdint.h>
#include "taglib.h"
#include "tfile.h"
#include "tstring.h"
#include "taglib_export.h"
namespace TagLib {
namespace Mod {
class ReadError {
};
class TAGLIB_EXPORT File : public TagLib::File {
public:
File(FileName file) : TagLib::File(file) {}
protected:
File(FileName file);
File(IOStream *stream);
ByteVector readBytes(unsigned long size);
String readString(unsigned long size);
uint8_t readByte();
uint16_t readU16B();
uint16_t readU16L();
uint32_t readU32B();
uint32_t readU32L();
void writeString(const String &s, ulong size);
bool readString(String &s, ulong size);
bool readByte(uchar &byte);
bool readU16L(ushort &number);
bool readU32L(ulong &number);
};
}
}

View File

@ -0,0 +1,63 @@
/***************************************************************************
copyright : (C) 2011 by Mathias Panzenböck
email : grosser.meister.morti@gmx.net
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301 USA *
***************************************************************************/
#ifndef TAGLIB_MODFILEPRIVATE_H
#define TAGLIB_MODFILEPRIVATE_H
// some helper-macros only used internally by (s3m|it|xm)file.cpp
#define READ_ASSERT(cond) \
if(!(cond)) \
{ \
setValid(false); \
return; \
}
#define READ(setter,type,read) \
{ \
type number; \
READ_ASSERT(read(number)); \
setter(number); \
}
#define READ_BYTE(setter) READ(setter,uchar,readByte)
#define READ_U16L(setter) READ(setter,ushort,readU16L)
#define READ_U32L(setter) READ(setter,ulong,readU32L)
#define READ_STRING(setter,size) \
{ \
String s; \
READ_ASSERT(readString(s, size)); \
setter(s); \
}
#define READ_AS(type,name,read) \
type name = 0; \
READ_ASSERT(read(name));
#define READ_BYTE_AS(name) READ_AS(uchar,name,readByte)
#define READ_U16L_AS(name) READ_AS(ushort,name,readU16L)
#define READ_U32L_AS(name) READ_AS(ulong,name,readU32L)
#define READ_STRING_AS(name,size) \
String name; \
READ_ASSERT(readString(name, size));
#endif

109
taglib/mod/modtag.cpp Normal file
View File

@ -0,0 +1,109 @@
/***************************************************************************
copyright : (C) 2011 by Mathias Panzenböck
email : grosser.meister.morti@gmx.net
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301 USA *
***************************************************************************/
#include "modtag.h"
using namespace TagLib;
using namespace Mod;
class Mod::Tag::TagPrivate
{
public:
TagPrivate() {}
String title;
String comment;
};
Mod::Tag::Tag() : TagLib::Tag()
{
d = new TagPrivate;
}
Mod::Tag::~Tag()
{
delete d;
}
String Mod::Tag::title() const
{
return d->title;
}
String Mod::Tag::artist() const
{
return String::null;
}
String Mod::Tag::album() const
{
return String::null;
}
String Mod::Tag::comment() const
{
return d->comment;
}
String Mod::Tag::genre() const
{
return String::null;
}
uint Mod::Tag::year() const
{
return 0;
}
uint Mod::Tag::track() const
{
return 0;
}
void Mod::Tag::setTitle(const String &title)
{
d->title = title;
}
void Mod::Tag::setArtist(const String &)
{
}
void Mod::Tag::setAlbum(const String &)
{
}
void Mod::Tag::setComment(const String &comment)
{
d->comment = comment;
}
void Mod::Tag::setGenre(const String &)
{
}
void Mod::Tag::setYear(uint)
{
}
void Mod::Tag::setTrack(uint)
{
}

View File

@ -22,31 +22,37 @@
#ifndef TAGLIB_MODTAG_H
#define TAGLIB_MODTAG_H
#include <taglib/tag.h>
#include "tag.h"
namespace TagLib {
namespace Mod {
class TAGLIB_EXPORT Tag : public TagLib::Tag {
public:
String title() const { return m_title; }
String artist() const { return String::null; }
String album() const { return String::null; }
String comment() const { return m_comment; }
String genre() const { return String::null; }
uint year() const { return 0; }
uint track() const { return 0; }
Tag();
virtual ~Tag();
void setTitle (const String &title) { m_title = title; }
void setArtist (const String &) {}
void setAlbum (const String &) {}
void setComment(const String &comment) { m_comment = comment; }
void setGenre (const String &) {}
void setYear (uint) {}
void setTrack(uint) {}
String title() const;
String artist() const;
String album() const;
String comment() const;
String genre() const;
uint year() const;
uint track() const;
void setTitle (const String &title);
void setArtist (const String &artist);
void setAlbum (const String &album);
void setComment(const String &comment);
void setGenre (const String &genre);
void setYear (uint year);
void setTrack(uint track);
private:
String m_title;
String m_comment;
Tag(const Tag &);
Tag &operator=(const Tag &);
class TagPrivate;
TagPrivate *d;
};
}
}