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:
167
taglib/it/itfile.cpp
Normal file
167
taglib/it/itfile.cpp
Normal file
@ -0,0 +1,167 @@
|
||||
/***************************************************************************
|
||||
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 "itfile.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace IT {
|
||||
|
||||
uint8_t AUTOVIB_IT_TO_XM[] = {0, 3, 1, 4, 2, 0, 0, 0};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
IT::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 IT::Properties(propertiesStyle);
|
||||
|
||||
if (!isOpen())
|
||||
return;
|
||||
|
||||
try {
|
||||
ByteVector mod_id(readBytes(4UL));
|
||||
if (mod_id != "IMPM") {
|
||||
throw Mod::ReadError();
|
||||
}
|
||||
|
||||
m_tag->setTitle(readString(26));
|
||||
seek(2, Current);
|
||||
|
||||
uint16_t length = readU16L();
|
||||
uint16_t instrumentCount = readU16L();
|
||||
uint16_t sampleCount = readU16L();
|
||||
|
||||
m_properties->setSampleLength(length);
|
||||
m_properties->setInstrumentCount(instrumentCount);
|
||||
m_properties->setSampleCount(sampleCount);
|
||||
m_properties->setPatternCount(readU16L());
|
||||
m_properties->setVersion(readU16L());
|
||||
m_properties->setCmwt(readU16L());
|
||||
m_properties->setFlags(readU16L());
|
||||
|
||||
uint16_t special = readU16L();
|
||||
|
||||
m_properties->setSpecial(special);
|
||||
m_properties->setBaseVolume(readU16L());
|
||||
|
||||
seek(1, Current);
|
||||
|
||||
m_properties->setTempo(readByte());
|
||||
m_properties->setBpmSpeed(readByte());
|
||||
|
||||
StringList comment;
|
||||
|
||||
for (uint16_t i = 0; i < instrumentCount; ++ i) {
|
||||
seek(192 + length + (i << 2));
|
||||
uint32_t instrumentOffset = readU32L();
|
||||
seek(instrumentOffset);
|
||||
|
||||
ByteVector instrumentMagic = readBytes(4);
|
||||
if (instrumentMagic != "IMPS" && instrumentMagic != "IMPI") {
|
||||
throw Mod::ReadError();
|
||||
}
|
||||
|
||||
String dosFileName = readString(13);
|
||||
|
||||
seek(15, Current);
|
||||
|
||||
String instrumentName = readString(26);
|
||||
|
||||
comment.append(instrumentName);
|
||||
}
|
||||
|
||||
for (uint16_t i = 0; i < sampleCount; ++ i) {
|
||||
seek(192 + length + (instrumentCount << 2) + (i << 2));
|
||||
uint32_t sampleOffset = readU32L();
|
||||
seek(sampleOffset);
|
||||
|
||||
ByteVector sampleMagic = readBytes(4);
|
||||
if (sampleMagic != "IMPS" && sampleMagic != "IMPI") {
|
||||
throw Mod::ReadError();
|
||||
}
|
||||
|
||||
String dosFileName = readString(13);
|
||||
uint8_t globalVolume = readByte();
|
||||
uint8_t sampleFlags = readByte();
|
||||
uint8_t sampleValume = readByte();
|
||||
String sampleName = readString(26);
|
||||
uint8_t sampleCvt = readByte();
|
||||
uint8_t samplePanning = readByte();
|
||||
uint32_t sampleLength = readU32L();
|
||||
uint32_t repeatStart = readU32L();
|
||||
uint32_t repeatStop = readU32L();
|
||||
uint32_t c4speed = readU32L();
|
||||
uint32_t sustainLoopStart = readU32L();
|
||||
uint32_t sustainLoopEnd = readU32L();
|
||||
uint32_t sampleDataOffset = readU32L();
|
||||
uint8_t vibratoRate = readByte();
|
||||
uint8_t vibratoDepth = readByte();
|
||||
uint8_t vibratoSweep = readByte();
|
||||
uint8_t vibratoType = readByte();
|
||||
|
||||
if (c4speed == 0) {
|
||||
c4speed = 8363;
|
||||
}
|
||||
else if (c4speed < 256) {
|
||||
c4speed = 256;
|
||||
}
|
||||
|
||||
vibratoDepth = vibratoDepth & 0x7F;
|
||||
vibratoSweep = (vibratoSweep + 3) >> 2;
|
||||
vibratoType = AUTOVIB_IT_TO_XM[vibratoType & 0x07];
|
||||
|
||||
comment.append(sampleName);
|
||||
}
|
||||
|
||||
m_tag->setComment(comment.toString("\n"));
|
||||
}
|
||||
catch (const Mod::ReadError&) {
|
||||
setValid(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
83
taglib/it/itfile.h
Normal file
83
taglib/it/itfile.h
Normal file
@ -0,0 +1,83 @@
|
||||
/***************************************************************************
|
||||
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_ITFILE_H
|
||||
#define TAGLIB_ITFILE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "tfile.h"
|
||||
#include "audioproperties.h"
|
||||
#include "taglib_export.h"
|
||||
#include "modfile.h"
|
||||
#include "modtag.h"
|
||||
#include "itproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace IT {
|
||||
|
||||
class TAGLIB_EXPORT File : public Mod::File {
|
||||
public:
|
||||
/*!
|
||||
* Contructs a Impulse Tracker 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 IT::Properties for this file. If no audio properties
|
||||
* were read then this will return a null pointer.
|
||||
*/
|
||||
virtual IT::Properties *audioProperties() const;
|
||||
|
||||
/*!
|
||||
* Save the file.
|
||||
* This is the same as calling save(AllTags);
|
||||
*
|
||||
* \note Saving Impulse Tracker 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;
|
||||
IT::Properties *m_properties;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
37
taglib/it/itfiletyperesolver.cpp
Normal file
37
taglib/it/itfiletyperesolver.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 "itfiletyperesolver.h"
|
||||
#include "itfile.h"
|
||||
|
||||
TagLib::File *ITFileTypeResolver::createFile(
|
||||
TagLib::FileName fileName,
|
||||
bool readProperties,
|
||||
TagLib::AudioProperties::ReadStyle propertiesStyle) const {
|
||||
TagLib::IT::File *f = new TagLib::IT::File(fileName, readProperties, propertiesStyle);
|
||||
if (f->isValid()) {
|
||||
return f;
|
||||
}
|
||||
else {
|
||||
delete f;
|
||||
return 0;
|
||||
}
|
||||
}
|
35
taglib/it/itfiletyperesolver.h
Normal file
35
taglib/it/itfiletyperesolver.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_ITFILETYPERESOLVER_H
|
||||
#define TAGLIB_ITFILETYPERESOLVER_H
|
||||
|
||||
#include "fileref.h"
|
||||
#include "taglib_export.h"
|
||||
|
||||
class TAGLIB_EXPORT ITFileTypeResolver : public TagLib::FileRef::FileTypeResolver {
|
||||
TagLib::File *createFile(TagLib::FileName fileName,
|
||||
bool readAudioProperties,
|
||||
TagLib::AudioProperties::ReadStyle audioPropertiesStyle) const;
|
||||
~ITFileTypeResolver() {}
|
||||
};
|
||||
|
||||
#endif
|
101
taglib/it/itproperties.h
Normal file
101
taglib/it/itproperties.h
Normal file
@ -0,0 +1,101 @@
|
||||
/***************************************************************************
|
||||
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_ITPROPERTIES_H
|
||||
#define TAGLIB_ITPROPERTIES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "audioproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
namespace IT {
|
||||
class TAGLIB_EXPORT Properties : public AudioProperties {
|
||||
friend class File;
|
||||
public:
|
||||
Properties(AudioProperties::ReadStyle propertiesStyle) :
|
||||
AudioProperties(propertiesStyle),
|
||||
m_sampleLength(0),
|
||||
m_stereo(false),
|
||||
m_instrumentCount(0),
|
||||
m_sampleCount(0),
|
||||
m_patternCount(0),
|
||||
m_version(0),
|
||||
m_cmwt(0),
|
||||
m_flags(0),
|
||||
m_special(0),
|
||||
m_baseVolume(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_stereo ? 2 : 1; }
|
||||
|
||||
uint16_t sampleLength() const { return m_sampleLength; }
|
||||
bool stereo() const { return m_stereo; }
|
||||
uint16_t instrumentCount() const { return m_instrumentCount; }
|
||||
uint16_t sampleCount() const { return m_sampleCount; }
|
||||
uint16_t patternCount() const { return m_patternCount; }
|
||||
uint16_t version() const { return m_version; }
|
||||
uint16_t cmwt() const { return m_cmwt; }
|
||||
uint16_t flags() const { return m_flags; }
|
||||
uint16_t special() const { return m_special; }
|
||||
int baseVolume() const { return m_baseVolume; }
|
||||
uint8_t tempo() const { return m_tempo; }
|
||||
uint8_t bpmSpeed() const { return m_bpmSpeed; }
|
||||
|
||||
protected:
|
||||
void setSampleLength(uint16_t sampleLength) { m_sampleLength = sampleLength; }
|
||||
void setStereo(bool stereo) { m_stereo = stereo; }
|
||||
|
||||
void setInstrumentCount (uint16_t instrumentCount) {
|
||||
m_instrumentCount = instrumentCount;
|
||||
}
|
||||
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 setSpecial (uint16_t special) { m_special = special; }
|
||||
void setCmwt (uint16_t cmwt) { m_cmwt = cmwt; }
|
||||
void setVersion (uint16_t version) { m_version = version; }
|
||||
void setBaseVolume (int baseVolume) { m_baseVolume = baseVolume; }
|
||||
void setTempo (uint8_t tempo) { m_tempo = tempo; }
|
||||
void setBpmSpeed (uint8_t bpmSpeed) { m_bpmSpeed = bpmSpeed; }
|
||||
|
||||
private:
|
||||
uint16_t m_sampleLength;
|
||||
bool m_stereo;
|
||||
uint16_t m_instrumentCount;
|
||||
uint16_t m_sampleCount;
|
||||
uint16_t m_patternCount;
|
||||
uint16_t m_version;
|
||||
uint16_t m_cmwt;
|
||||
uint16_t m_flags;
|
||||
uint16_t m_special;
|
||||
int m_baseVolume;
|
||||
uint8_t m_tempo;
|
||||
uint8_t m_bpmSpeed;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user