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

@ -20,124 +20,142 @@
***************************************************************************/
#include "s3mfile.h"
#include "tstringlist.h"
#include "modfileprivate.h"
namespace TagLib {
using namespace TagLib;
using namespace S3M;
namespace S3M {
class S3M::File::FilePrivate
{
public:
FilePrivate(AudioProperties::ReadStyle propertiesStyle)
: properties(propertiesStyle)
{
}
File::File(FileName file, bool readProperties,
Mod::Tag tag;
S3M::Properties properties;
};
S3M::File::File(FileName file, bool readProperties,
AudioProperties::ReadStyle propertiesStyle) :
Mod::File(file), m_tag(0), m_properties(0) {
read(readProperties, propertiesStyle);
Mod::File(file)
{
d = new FilePrivate(propertiesStyle);
read(readProperties);
}
File::~File() {
delete m_tag;
delete m_properties;
S3M::File::File(IOStream *stream, bool readProperties,
AudioProperties::ReadStyle propertiesStyle) :
Mod::File(stream)
{
d = new FilePrivate(propertiesStyle);
read(readProperties);
}
Mod::Tag *File::tag() const {
return m_tag;
S3M::File::~File()
{
delete d;
}
S3M::Properties *File::audioProperties() const {
return m_properties;
Mod::Tag *S3M::File::tag() const
{
return &d->tag;
}
bool File::save() {
return false;
S3M::Properties *S3M::File::audioProperties() const
{
return &d->properties;
}
void File::read(bool, AudioProperties::ReadStyle propertiesStyle) {
delete m_tag;
delete m_properties;
bool S3M::File::save()
{
// note: if title starts with "Extended Module: "
// the file would look like an .xm file
seek(0);
writeString(d->tag.title(), 28);
// TODO: write comment as sample names
return true;
}
m_tag = new Mod::Tag();
m_properties = new S3M::Properties(propertiesStyle);
if (!isOpen())
void S3M::File::read(bool)
{
if(!isOpen())
return;
try {
m_tag->setTitle(readString(28));
READ_STRING(d->tag.setTitle, 28);
READ_BYTE_AS(mark);
READ_BYTE_AS(type);
uint8_t mark = readByte();
uint8_t type = readByte();
READ_ASSERT(mark == 0x1A && type == 0x10);
if (mark != 0x1A || type != 0x10) {
throw Mod::ReadError();
}
seek(32);
seek(32);
READ_U16L_AS(length);
READ_U16L_AS(sampleCount);
uint16_t length = readU16L();
uint16_t sampleCount = readU16L();
m_properties->setSampleLength(length);
m_properties->setSampleCount(sampleCount);
m_properties->setPatternCount(readU16L());
m_properties->setFlags(readU16L());
m_properties->setVersion(readU16L());
m_properties->setSamplesType(readU16L());
d->properties.setSampleLength(length);
d->properties.setSampleCount(sampleCount);
ByteVector mod_id(readBytes(4UL));
READ_U16L(d->properties.setPatternCount);
READ_U16L(d->properties.setFlags);
READ_U16L(d->properties.setVersion);
READ_U16L(d->properties.setSamplesType);
if (mod_id != "SCRM") {
throw Mod::ReadError();
}
READ_ASSERT(readBlock(4) == "SCRM");
m_properties->setBaseVolume(readByte() << 1);
m_properties->setTempo(readByte());
m_properties->setBpmSpeed(readByte());
m_properties->setStereo((readByte() & 0x80) != 0);
m_properties->setUltraClick(readByte());
m_properties->setUsePanningValues(readByte() == 0xFC);
READ_BYTE_AS(baseVolume);
d->properties.setBaseVolume(baseVolume << 1);
seek(10, Current);
READ_BYTE(d->properties.setTempo);
READ_BYTE(d->properties.setBpmSpeed);
int channels = 0;
for (int i = 0; i < 32; ++ i) {
if (readByte() != 0xff) ++ channels;
}
m_properties->setChannels(channels);
READ_BYTE_AS(stereo);
d->properties.setStereo((stereo & 0x80) != 0);
READ_BYTE(d->properties.setUltraClick);
seek(channels, Current);
READ_BYTE_AS(usePanningValues);
d->properties.setUsePanningValues(usePanningValues == 0xFC);
StringList comment;
for (uint16_t i = 0; i < sampleCount; ++ i) {
seek(96 + length + (i << 1));
seek(10, Current);
uint16_t instrumentOffset = readU16L();
seek(instrumentOffset << 4);
uint8_t sampleType = readByte();
String dosFileName = readString(13);
uint16_t sampleOffset = readU16L();
uint32_t sampleLength = readU32L();
uint32_t repeatStart = readU32L();
uint32_t repeatStop = readU32L();
uint8_t sampleColume = readByte();
seek(2, Current);
uint8_t sampleFlags = readByte();
uint32_t baseFrequency = readU32L();
seek(12, Current);
String sampleName = readString(28);
comment.append(sampleName);
}
m_tag->setComment(comment.toString("\n"));
int channels = 0;
for(int i = 0; i < 32; ++ i)
{
READ_BYTE_AS(terminator);
if (terminator != 0xff) ++ channels;
}
catch (const Mod::ReadError&) {
setValid(false);
}
}
d->properties.setChannels(channels);
seek(channels, Current);
StringList comment;
for(ushort i = 0; i < sampleCount; ++ i)
{
seek(96 + length + (i << 1));
READ_U16L_AS(instrumentOffset);
seek(instrumentOffset << 4);
READ_BYTE_AS(sampleType);
READ_STRING_AS(dosFileName, 13);
READ_U16L_AS(sampleOffset);
READ_U32L_AS(sampleLength);
READ_U32L_AS(repeatStart);
READ_U32L_AS(repeatStop);
READ_BYTE_AS(sampleVolume);
seek(2, Current);
READ_BYTE_AS(sampleFlags);
READ_U32L_AS(baseFrequency);
seek(12, Current);
READ_STRING_AS(sampleName, 28);
comment.append(sampleName);
}
d->tag.setComment(comment.toString("\n"));
}

View File

@ -42,22 +42,31 @@ namespace TagLib {
* is true the file's audio properties will also be read using
* \a propertiesStyle. If false, \a propertiesStyle is ignored.
*/
explicit File(FileName file, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
File(FileName file, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*!
* Contructs a ScreamTracker III file from \a stream. If \a readProperties
* is true the file's audio properties will also be read using
* \a propertiesStyle. If false, \a propertiesStyle is ignored.
*/
File(IOStream *stream, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*!
* Destroys this instance of the File.
*/
virtual ~File();
virtual Mod::Tag *tag() const;
Mod::Tag *tag() const;
/*!
* Returns the S3M::Properties for this file. If no audio properties
* were read then this will return a null pointer.
*/
virtual S3M::Properties *audioProperties() const;
S3M::Properties *audioProperties() const;
/*!
* Save the file.
@ -65,16 +74,16 @@ namespace TagLib {
*
* \note Saving ScreamTracker III tags is not supported.
*/
virtual bool save();
void read(bool readProperties, AudioProperties::ReadStyle propertiesStyle);
bool save();
private:
File(const File &);
File &operator=(const File &);
Mod::Tag *m_tag;
S3M::Properties *m_properties;
void read(bool readProperties);
class FilePrivate;
FilePrivate *d;
};
}
}

View File

@ -1,37 +0,0 @@
/***************************************************************************
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 "s3mfiletyperesolver.h"
#include "s3mfile.h"
TagLib::File *S3MFileTypeResolver::createFile(
TagLib::FileName fileName,
bool readProperties,
TagLib::AudioProperties::ReadStyle propertiesStyle) const {
TagLib::S3M::File *f = new TagLib::S3M::File(fileName, readProperties, propertiesStyle);
if (f->isValid()) {
return f;
}
else {
delete f;
return 0;
}
}

View File

@ -1,35 +0,0 @@
/***************************************************************************
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_S3MFILETYPERESOLVER_H
#define TAGLIB_S3MFILETYPERESOLVER_H
#include "fileref.h"
#include "taglib_export.h"
class TAGLIB_EXPORT S3MFileTypeResolver : public TagLib::FileRef::FileTypeResolver {
TagLib::File *createFile(TagLib::FileName fileName,
bool readAudioProperties,
TagLib::AudioProperties::ReadStyle audioPropertiesStyle) const;
~S3MFileTypeResolver() {}
};
#endif

View File

@ -0,0 +1,214 @@
/***************************************************************************
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 "s3mproperties.h"
using namespace TagLib;
using namespace S3M;
class S3M::Properties::PropertiesPrivate
{
public:
PropertiesPrivate() :
sampleLength(0),
channels(0),
stereo(0),
sampleCount(0),
patternCount(0),
flags(0),
version(0),
samplesType(0),
baseVolume(0),
tempo(0),
bpmSpeed(0),
ultraClick(0),
usePanningValues(false) {}
ushort sampleLength;
int channels;
bool stereo;
ushort sampleCount;
ushort patternCount;
ushort flags;
ushort version;
ushort samplesType;
int baseVolume;
uchar tempo;
uchar bpmSpeed;
uchar ultraClick;
bool usePanningValues;
};
S3M::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) :
AudioProperties(propertiesStyle),
d(new PropertiesPrivate)
{
}
S3M::Properties::~Properties()
{
delete d;
}
int S3M::Properties::length() const
{
return 0;
}
int S3M::Properties::bitrate() const
{
return 0;
}
int S3M::Properties::sampleRate() const
{
return 0;
}
int S3M::Properties::channels() const
{
return d->channels;
}
ushort S3M::Properties::sampleLength() const
{
return d->sampleLength;
}
bool S3M::Properties::stereo() const
{
return d->stereo;
}
ushort S3M::Properties::sampleCount() const
{
return d->sampleCount;
}
ushort S3M::Properties::patternCount() const
{
return d->patternCount;
}
ushort S3M::Properties::flags() const
{
return d->flags;
}
ushort S3M::Properties::version() const
{
return d->version;
}
ushort S3M::Properties::samplesType() const
{
return d->samplesType;
}
int S3M::Properties::baseVolume() const
{
return d->baseVolume;
}
uchar S3M::Properties::tempo() const
{
return d->tempo;
}
uchar S3M::Properties::bpmSpeed() const
{
return d->bpmSpeed;
}
uchar S3M::Properties::ultraClick() const
{
return d->ultraClick;
}
bool S3M::Properties::usePanningValues() const
{
return d->usePanningValues;
}
void S3M::Properties::setSampleLength(ushort sampleLength)
{
d->sampleLength = sampleLength;
}
void S3M::Properties::setChannels(int channels)
{
d->channels = channels;
}
void S3M::Properties::setStereo(bool stereo)
{
d->stereo = stereo;
}
void S3M::Properties::setSampleCount(ushort sampleCount)
{
d->sampleCount = sampleCount;
}
void S3M::Properties::setPatternCount(ushort patternCount)
{
d->patternCount = patternCount;
}
void S3M::Properties::setFlags(ushort flags)
{
d->flags = flags;
}
void S3M::Properties::setVersion(ushort version)
{
d->version = version;
}
void S3M::Properties::setSamplesType(ushort samplesType)
{
d->samplesType = samplesType;
}
void S3M::Properties::setBaseVolume(int baseVolume)
{
d->baseVolume = baseVolume;
}
void S3M::Properties::setTempo(uchar tempo)
{
d->tempo = tempo;
}
void S3M::Properties::setBpmSpeed(uchar bpmSpeed)
{
d->bpmSpeed = bpmSpeed;
}
void S3M::Properties::setUltraClick(uchar ultraClick)
{
d->ultraClick = ultraClick;
}
void S3M::Properties::setUsePanningValues(bool usePanningValues)
{
d->usePanningValues = usePanningValues;
}

View File

@ -22,7 +22,7 @@
#ifndef TAGLIB_S3MPROPERTIES_H
#define TAGLIB_S3MPROPERTIES_H
#include <stdint.h>
#include "taglib.h"
#include "audioproperties.h"
namespace TagLib {
@ -30,72 +30,49 @@ namespace TagLib {
class TAGLIB_EXPORT Properties : public AudioProperties {
friend class File;
public:
Properties(AudioProperties::ReadStyle propertiesStyle) :
AudioProperties(propertiesStyle),
m_sampleLength(0),
m_channels(0),
m_stereo(false),
m_sampleCount(0),
m_patternCount(0),
m_flags(0),
m_version(0),
m_samplesType(0),
m_baseVolume(0),
m_tempo(0),
m_bpmSpeed(0),
m_ultraClick(0),
m_usePanningValues(false) {}
Properties(AudioProperties::ReadStyle propertiesStyle);
virtual ~Properties();
int length() const { return 0; }
int bitrate() const { return 0; }
int sampleRate() const { return 0; }
int channels() const { return m_channels; }
int length() const;
int bitrate() const;
int sampleRate() const;
int channels() const;
uint16_t sampleLength() const { return m_sampleLength; }
bool stereo() const { return m_stereo; }
uint16_t sampleCount() const { return m_sampleCount; }
uint16_t patternCount() const { return m_patternCount; }
uint16_t flags() const { return m_flags; }
uint16_t version() const { return m_version; }
uint16_t samplesType() const { return m_samplesType; }
int baseVolume() const { return m_baseVolume; }
uint8_t tempo() const { return m_tempo; }
uint8_t bpmSpeed() const { return m_bpmSpeed; }
uint8_t ultraClick() const { return m_ultraClick; }
bool usePanningValues() const { return m_usePanningValues; }
ushort sampleLength() const;
bool stereo() const;
ushort sampleCount() const;
ushort patternCount() const;
ushort flags() const;
ushort version() const;
ushort samplesType() const;
int baseVolume() const;
uchar tempo() const;
uchar bpmSpeed() const;
uchar ultraClick() const;
bool usePanningValues() const;
protected:
void setSampleLength(uint16_t sampleLength) { m_sampleLength = sampleLength; }
void setChannels(int channels) { m_channels = channels; }
void setSampleLength(ushort sampleLength);
void setChannels(int channels);
void setStereo (bool stereo) { m_stereo = stereo; }
void setSampleCount (uint16_t sampleCount) { m_sampleCount = sampleCount; }
void setPatternCount(uint16_t patternCount) { m_patternCount = patternCount; }
void setFlags (uint16_t flags) { m_flags = flags; }
void setVersion (uint16_t version) { m_version = version; }
void setSamplesType (uint16_t samplesType) { m_samplesType = samplesType; }
void setBaseVolume (int baseVolume) { m_baseVolume = baseVolume; }
void setTempo (uint8_t tempo) { m_tempo = tempo; }
void setBpmSpeed (uint8_t bpmSpeed) { m_bpmSpeed = bpmSpeed; }
void setUltraClick (uint8_t ultraClick) { m_ultraClick = ultraClick; }
void setUsePanningValues(bool usePanningValues) {
m_usePanningValues = usePanningValues;
}
void setStereo (bool stereo);
void setSampleCount (ushort sampleCount);
void setPatternCount(ushort patternCount);
void setFlags (ushort flags);
void setVersion (ushort version);
void setSamplesType (ushort samplesType);
void setBaseVolume (int baseVolume);
void setTempo (uchar tempo);
void setBpmSpeed (uchar bpmSpeed);
void setUltraClick (uchar ultraClick);
void setUsePanningValues(bool usePanningValues);
private:
uint16_t m_sampleLength;
int m_channels;
bool m_stereo;
uint16_t m_sampleCount;
uint16_t m_patternCount;
uint16_t m_flags;
uint16_t m_version;
uint16_t m_samplesType;
int m_baseVolume;
uint8_t m_tempo;
uint8_t m_bpmSpeed;
uint8_t m_ultraClick;
bool m_usePanningValues;
Properties(const Properties&);
Properties &operator=(const Properties&);
class PropertiesPrivate;
PropertiesPrivate *d;
};
}
}