mirror of
https://github.com/taglib/taglib.git
synced 2025-07-22 15:04:24 -04:00
added read-only support for s3m, it and xm
This commit is contained in:
158
taglib/xm/xmfile.cpp
Normal file
158
taglib/xm/xmfile.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
/***************************************************************************
|
||||
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 "tstringlist.h"
|
||||
#include "xmfile.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace XM {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
XM::Tag *File::tag() const {
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
XM::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 XM::Tag();
|
||||
m_properties = new XM::Properties(propertiesStyle);
|
||||
|
||||
if (!isOpen())
|
||||
return;
|
||||
|
||||
try {
|
||||
if (readBytes(17) != "Extended Module: ") {
|
||||
throw Mod::ReadError();
|
||||
}
|
||||
|
||||
m_tag->setTitle(readString(20));
|
||||
|
||||
if (readByte() != 0x1A) {
|
||||
throw Mod::ReadError();
|
||||
}
|
||||
|
||||
m_tag->setTrackerName(readString(20));
|
||||
m_properties->setVersion(readU16L());
|
||||
uint32_t headerSize = readU32L();
|
||||
m_properties->setSampleLength(readU16L());
|
||||
m_properties->setRestartPosition(readU16L());
|
||||
m_properties->setChannels(readU16L());
|
||||
uint32_t patternCount = readU16L();
|
||||
m_properties->setPatternCount(patternCount);
|
||||
uint32_t instrumentCount = readU16L();
|
||||
m_properties->setInstrumentCount(instrumentCount);
|
||||
m_properties->setFlags(readU16L());
|
||||
m_properties->setTempo(readU16L());
|
||||
m_properties->setBpmSpeed(readU16L());
|
||||
|
||||
seek(60 + headerSize);
|
||||
|
||||
for (uint16_t i = 0; i < patternCount; ++ i) {
|
||||
uint32_t patternHeaderLength = readU32L();
|
||||
uint8_t patternType = readByte();
|
||||
uint16_t rowCount = readU16L();
|
||||
uint16_t patternDataSize = readU16L();
|
||||
|
||||
seek(patternHeaderLength - (4+1+2+2) + patternDataSize, Current);
|
||||
}
|
||||
|
||||
StringList intrumentNames;
|
||||
StringList sampleNames;
|
||||
for (uint16_t i = 0; i < instrumentCount; ++ i) {
|
||||
long pos = tell();
|
||||
uint32_t instrumentSize = readU32L();
|
||||
|
||||
String instrumentName;
|
||||
uint8_t instrumentType = 0;
|
||||
uint16_t sampleCount = 0;
|
||||
|
||||
if (instrumentSize > 4) {
|
||||
instrumentName = readString(std::min((uint32_t)22,instrumentSize-4));
|
||||
|
||||
if (instrumentSize >= (4+22+1)) {
|
||||
instrumentType = readByte();
|
||||
|
||||
if (instrumentSize >= (4+22+1+2)) {
|
||||
sampleCount = readU16L();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t sampleHeaderSize = 0;
|
||||
uint32_t sumSampleLength = 0;
|
||||
if (sampleCount > 0) {
|
||||
sampleHeaderSize = readU32L();
|
||||
seek(pos + instrumentSize);
|
||||
|
||||
long sampleheaderPos = tell();
|
||||
for (uint16_t j = 0; j < sampleCount; ++ j) {
|
||||
seek(sampleheaderPos + sampleHeaderSize * j);
|
||||
uint32_t length = readU32L();
|
||||
uint32_t loopStart = readU32L();
|
||||
uint32_t loopLength = readU32L();
|
||||
uint8_t volume = readByte();
|
||||
uint8_t finetune = readByte();
|
||||
uint8_t sampleType = readByte();
|
||||
uint8_t panning = readByte();
|
||||
uint8_t noteNumber = readByte();
|
||||
uint8_t compression = readByte();
|
||||
String sampleName = readString(22);
|
||||
|
||||
sumSampleLength += length;
|
||||
sampleNames.append(sampleName);
|
||||
}
|
||||
}
|
||||
intrumentNames.append(instrumentName);
|
||||
seek(pos + instrumentSize + sampleHeaderSize * sampleCount + sumSampleLength);
|
||||
}
|
||||
|
||||
m_tag->setComment(intrumentNames.toString("\n") + "\n" + sampleNames.toString("\n"));
|
||||
}
|
||||
catch (const Mod::ReadError&) {
|
||||
setValid(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
82
taglib/xm/xmfile.h
Normal file
82
taglib/xm/xmfile.h
Normal 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_XMFILE_H
|
||||
#define TAGLIB_XMFILE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "tfile.h"
|
||||
#include "audioproperties.h"
|
||||
#include "taglib_export.h"
|
||||
#include "modfile.h"
|
||||
#include "xmtag.h"
|
||||
#include "xmproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace XM {
|
||||
|
||||
class TAGLIB_EXPORT File : public Mod::File {
|
||||
public:
|
||||
/*!
|
||||
* Contructs a Extended Module 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 XM::Tag *tag() const;
|
||||
|
||||
/*!
|
||||
* Returns the XM::Properties for this file. If no audio properties
|
||||
* were read then this will return a null pointer.
|
||||
*/
|
||||
virtual XM::Properties *audioProperties() const;
|
||||
|
||||
/*!
|
||||
* Save the file.
|
||||
* This is the same as calling save(AllTags);
|
||||
*
|
||||
* \note Saving Extended Module tags is not supported.
|
||||
*/
|
||||
virtual bool save();
|
||||
|
||||
void read(bool readProperties, AudioProperties::ReadStyle propertiesStyle);
|
||||
|
||||
private:
|
||||
File(const File &);
|
||||
File &operator=(const File &);
|
||||
|
||||
XM::Tag *m_tag;
|
||||
XM::Properties *m_properties;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
37
taglib/xm/xmfiletyperesolver.cpp
Normal file
37
taglib/xm/xmfiletyperesolver.cpp
Normal 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 "xmfiletyperesolver.h"
|
||||
#include "xmfile.h"
|
||||
|
||||
TagLib::File *XMFileTypeResolver::createFile(
|
||||
TagLib::FileName fileName,
|
||||
bool readProperties,
|
||||
TagLib::AudioProperties::ReadStyle propertiesStyle) const {
|
||||
TagLib::XM::File *f = new TagLib::XM::File(fileName, readProperties, propertiesStyle);
|
||||
if (f->isValid()) {
|
||||
return f;
|
||||
}
|
||||
else {
|
||||
delete f;
|
||||
return 0;
|
||||
}
|
||||
}
|
35
taglib/xm/xmfiletyperesolver.h
Normal file
35
taglib/xm/xmfiletyperesolver.h
Normal 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_XMFILETYPERESOLVER_H
|
||||
#define TAGLIB_XMFILETYPERESOLVER_H
|
||||
|
||||
#include "fileref.h"
|
||||
#include "taglib_export.h"
|
||||
|
||||
class TAGLIB_EXPORT XMFileTypeResolver : public TagLib::FileRef::FileTypeResolver {
|
||||
TagLib::File *createFile(TagLib::FileName fileName,
|
||||
bool readAudioProperties,
|
||||
TagLib::AudioProperties::ReadStyle audioPropertiesStyle) const;
|
||||
~XMFileTypeResolver() {}
|
||||
};
|
||||
|
||||
#endif
|
91
taglib/xm/xmproperties.h
Normal file
91
taglib/xm/xmproperties.h
Normal file
@ -0,0 +1,91 @@
|
||||
/***************************************************************************
|
||||
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_XMPROPERTIES_H
|
||||
#define TAGLIB_XMPROPERTIES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "tstring.h"
|
||||
#include "audioproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
namespace XM {
|
||||
class Properties : public AudioProperties {
|
||||
friend class File;
|
||||
public:
|
||||
Properties(AudioProperties::ReadStyle propertiesStyle) :
|
||||
AudioProperties(propertiesStyle),
|
||||
m_sampleLength(0),
|
||||
m_channels(0),
|
||||
m_version(0),
|
||||
m_restartPosition(0),
|
||||
m_patternCount(0),
|
||||
m_instrumentCount(0),
|
||||
m_flags(0),
|
||||
m_tempo(0),
|
||||
m_bpmSpeed(0) {}
|
||||
|
||||
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; }
|
||||
uint16_t version() const { return m_version; }
|
||||
uint16_t restartPosition() const { return m_restartPosition; }
|
||||
uint16_t patternCount() const { return m_patternCount; }
|
||||
uint16_t instrumentCount() const { return m_instrumentCount; }
|
||||
uint16_t flags() const { return m_flags; }
|
||||
uint16_t tempo() const { return m_tempo; }
|
||||
uint16_t bpmSpeed() const { return m_bpmSpeed; }
|
||||
|
||||
protected:
|
||||
void setSampleLength(int sampleLength) { m_sampleLength = sampleLength; }
|
||||
void setChannels(int channels) { m_channels = channels; }
|
||||
|
||||
void setVersion(uint16_t version) { m_version = version; }
|
||||
void setRestartPosition(uint16_t restartPosition) {
|
||||
m_restartPosition = restartPosition;
|
||||
}
|
||||
void setPatternCount(uint16_t patternCount) { m_patternCount = patternCount; }
|
||||
void setInstrumentCount(uint16_t instrumentCount) {
|
||||
m_instrumentCount = instrumentCount;
|
||||
}
|
||||
void setFlags (uint16_t flags) { m_flags = flags; }
|
||||
void setTempo (uint16_t tempo) { m_tempo = tempo; }
|
||||
void setBpmSpeed(uint16_t bpmSpeed) { m_bpmSpeed = bpmSpeed; }
|
||||
|
||||
private:
|
||||
uint16_t m_sampleLength;
|
||||
int m_channels;
|
||||
uint16_t m_version;
|
||||
uint16_t m_restartPosition;
|
||||
uint16_t m_patternCount;
|
||||
uint16_t m_instrumentCount;
|
||||
uint16_t m_flags;
|
||||
uint16_t m_tempo;
|
||||
uint16_t m_bpmSpeed;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
43
taglib/xm/xmtag.h
Normal file
43
taglib/xm/xmtag.h
Normal file
@ -0,0 +1,43 @@
|
||||
/***************************************************************************
|
||||
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_XMTAG_H
|
||||
#define TAGLIB_XMTAG_H
|
||||
|
||||
#include "modtag.h"
|
||||
|
||||
namespace TagLib {
|
||||
namespace XM {
|
||||
class Tag : public Mod::Tag {
|
||||
public:
|
||||
String trackerName() const { return m_trackerName; }
|
||||
|
||||
void setTrackerName(const String &trackerName) {
|
||||
m_trackerName = trackerName;
|
||||
}
|
||||
|
||||
private:
|
||||
String m_trackerName;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user