added read-only support for s3m, it and xm

This commit is contained in:
Mathias Panzenböck
2011-06-13 03:19:21 +02:00
parent c3c88b4f55
commit 5332fb5cf8
20 changed files with 1499 additions and 0 deletions

143
taglib/s3m/s3mfile.cpp Normal file
View File

@ -0,0 +1,143 @@
/***************************************************************************
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 "s3mfile.h"
#include "tstringlist.h"
namespace TagLib {
namespace S3M {
File::File(FileName file, bool readProperties,
AudioProperties::ReadStyle propertiesStyle) :
Mod::File(file), m_tag(0), m_properties(0) {
read(readProperties, propertiesStyle);
}
File::~File() {
delete m_tag;
delete m_properties;
}
Mod::Tag *File::tag() const {
return m_tag;
}
S3M::Properties *File::audioProperties() const {
return m_properties;
}
bool File::save() {
return false;
}
void File::read(bool, AudioProperties::ReadStyle propertiesStyle) {
delete m_tag;
delete m_properties;
m_tag = new Mod::Tag();
m_properties = new S3M::Properties(propertiesStyle);
if (!isOpen())
return;
try {
m_tag->setTitle(readString(28));
uint8_t mark = readByte();
uint8_t type = readByte();
if (mark != 0x1A || type != 0x10) {
throw Mod::ReadError();
}
seek(32);
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());
ByteVector mod_id(readBytes(4UL));
if (mod_id != "SCRM") {
throw Mod::ReadError();
}
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);
seek(10, Current);
int channels = 0;
for (int i = 0; i < 32; ++ i) {
if (readByte() != 0xff) ++ channels;
}
m_properties->setChannels(channels);
seek(channels, Current);
StringList comment;
for (uint16_t i = 0; i < sampleCount; ++ i) {
seek(96 + length + (i << 1));
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"));
}
catch (const Mod::ReadError&) {
setValid(false);
}
}
}
}

82
taglib/s3m/s3mfile.h Normal file
View File

@ -0,0 +1,82 @@
/***************************************************************************
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_S3MFILE_H
#define TAGLIB_S3MFILE_H
#include <stdint.h>
#include "tfile.h"
#include "audioproperties.h"
#include "taglib_export.h"
#include "modfile.h"
#include "modtag.h"
#include "s3mproperties.h"
namespace TagLib {
namespace S3M {
class TAGLIB_EXPORT File : public Mod::File {
public:
/*!
* Contructs a ScreamTracker III file from \a file. If \a readProperties
* 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);
/*!
* Destroys this instance of the File.
*/
virtual ~File();
virtual 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;
/*!
* Save the file.
* This is the same as calling save(AllTags);
*
* \note Saving ScreamTracker III tags is not supported.
*/
virtual bool save();
void read(bool readProperties, AudioProperties::ReadStyle propertiesStyle);
private:
File(const File &);
File &operator=(const File &);
Mod::Tag *m_tag;
S3M::Properties *m_properties;
};
}
}
#endif

View File

@ -0,0 +1,37 @@
/***************************************************************************
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

@ -0,0 +1,35 @@
/***************************************************************************
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

103
taglib/s3m/s3mproperties.h Normal file
View File

@ -0,0 +1,103 @@
/***************************************************************************
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_S3MPROPERTIES_H
#define TAGLIB_S3MPROPERTIES_H
#include <stdint.h>
#include "audioproperties.h"
namespace TagLib {
namespace S3M {
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) {}
int length() const { return 0; }
int bitrate() const { return 0; }
int sampleRate() const { return 0; }
int channels() const { return m_channels; }
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; }
protected:
void setSampleLength(uint16_t sampleLength) { m_sampleLength = sampleLength; }
void setChannels(int channels) { m_channels = 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;
}
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;
};
}
}
#endif