]> granicus.if.org Git - taglib/commitdiff
added read-only support for s3m, it and xm
authorMathias Panzenböck <grosser.meister.morti@gmx.net>
Mon, 13 Jun 2011 01:19:21 +0000 (03:19 +0200)
committerMathias Panzenböck <grosser.meister.morti@gmx.net>
Mon, 13 Jun 2011 01:19:21 +0000 (03:19 +0200)
20 files changed:
taglib/CMakeLists.txt
taglib/it/itfile.cpp [new file with mode: 0644]
taglib/it/itfile.h [new file with mode: 0644]
taglib/it/itfiletyperesolver.cpp [new file with mode: 0644]
taglib/it/itfiletyperesolver.h [new file with mode: 0644]
taglib/it/itproperties.h [new file with mode: 0644]
taglib/mod/modfile.cpp [new file with mode: 0644]
taglib/mod/modfile.h [new file with mode: 0644]
taglib/mod/modtag.h [new file with mode: 0644]
taglib/s3m/s3mfile.cpp [new file with mode: 0644]
taglib/s3m/s3mfile.h [new file with mode: 0644]
taglib/s3m/s3mfiletyperesolver.cpp [new file with mode: 0644]
taglib/s3m/s3mfiletyperesolver.h [new file with mode: 0644]
taglib/s3m/s3mproperties.h [new file with mode: 0644]
taglib/xm/xmfile.cpp [new file with mode: 0644]
taglib/xm/xmfile.h [new file with mode: 0644]
taglib/xm/xmfiletyperesolver.cpp [new file with mode: 0644]
taglib/xm/xmfiletyperesolver.h [new file with mode: 0644]
taglib/xm/xmproperties.h [new file with mode: 0644]
taglib/xm/xmtag.h [new file with mode: 0644]

index 0bb01d08480bffcc74997f5574466557a6b7715f..d72f5f853296e15c444f5662cc4ab0f4b032decc 100644 (file)
@@ -19,6 +19,10 @@ include_directories(
   ${CMAKE_CURRENT_SOURCE_DIR}/riff
   ${CMAKE_CURRENT_SOURCE_DIR}/riff/aiff
   ${CMAKE_CURRENT_SOURCE_DIR}/riff/wav
+  ${CMAKE_CURRENT_SOURCE_DIR}/mod
+  ${CMAKE_CURRENT_SOURCE_DIR}/s3m
+  ${CMAKE_CURRENT_SOURCE_DIR}/it
+  ${CMAKE_CURRENT_SOURCE_DIR}/xm
 )
 
 if(ZLIB_FOUND)
@@ -97,6 +101,18 @@ set(tag_HDRS
   riff/aiff/aiffproperties.h
   riff/wav/wavfile.h
   riff/wav/wavproperties.h
+  mod/modfile.h
+  mod/modtag.h
+  it/itfile.h
+  it/itfiletyperesolver.h
+  it/itproperties.h
+  s3m/s3mfile.h
+  s3m/s3mfiletyperesolver.h
+  s3m/s3mproperties.h
+  xm/xmfile.h
+  xm/xmfiletyperesolver.h
+  xm/xmproperties.h
+  xm/xmtag.h
 )
 if(WITH_ASF)
   set(tag_HDRS ${tag_HDRS}
@@ -237,6 +253,25 @@ set(wav_SRCS
   riff/wav/wavproperties.cpp
 )
 
+set(mod_SRCS
+  mod/modfile.cpp
+)
+
+set(s3m_SRCS
+  s3m/s3mfile.cpp
+  s3m/s3mfiletyperesolver.cpp
+)
+
+set(it_SRCS
+  it/itfile.cpp
+  it/itfiletyperesolver.cpp
+)
+
+set(xm_SRCS
+  xm/xmfile.cpp
+  xm/xmfiletyperesolver.cpp
+)
+
 set(toolkit_SRCS
   toolkit/tstring.cpp
   toolkit/tstringlist.cpp
@@ -254,6 +289,7 @@ set(tag_LIB_SRCS
   ${mpeg_SRCS} ${id3v1_SRCS} ${id3v2_SRCS} ${frames_SRCS} ${ogg_SRCS}
   ${vorbis_SRCS} ${oggflacs_SRCS} ${mpc_SRCS} ${ape_SRCS} ${toolkit_SRCS} ${flacs_SRCS}
   ${wavpack_SRCS} ${speex_SRCS} ${trueaudio_SRCS} ${riff_SRCS} ${aiff_SRCS} ${wav_SRCS}
+  ${mod_SRCS} ${s3m_SRCS} ${it_SRCS} ${xm_SRCS}
   tag.cpp
   tagunion.cpp
   fileref.cpp
diff --git a/taglib/it/itfile.cpp b/taglib/it/itfile.cpp
new file mode 100644 (file)
index 0000000..f0c4d77
--- /dev/null
@@ -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);
+       }
+}
+
+       }
+}
diff --git a/taglib/it/itfile.h b/taglib/it/itfile.h
new file mode 100644 (file)
index 0000000..2647d45
--- /dev/null
@@ -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
diff --git a/taglib/it/itfiletyperesolver.cpp b/taglib/it/itfiletyperesolver.cpp
new file mode 100644 (file)
index 0000000..e35ad25
--- /dev/null
@@ -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;
+       }
+}
diff --git a/taglib/it/itfiletyperesolver.h b/taglib/it/itfiletyperesolver.h
new file mode 100644 (file)
index 0000000..2faaa3b
--- /dev/null
@@ -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
diff --git a/taglib/it/itproperties.h b/taglib/it/itproperties.h
new file mode 100644 (file)
index 0000000..9e1155e
--- /dev/null
@@ -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
diff --git a/taglib/mod/modfile.cpp b/taglib/mod/modfile.cpp
new file mode 100644 (file)
index 0000000..eedd20c
--- /dev/null
@@ -0,0 +1,89 @@
+/***************************************************************************
+    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 "modfile.h"
+
+#ifdef HAVE_ENDIAN_H
+#include <endian.h>
+#endif
+
+namespace TagLib {
+
+       namespace Mod {
+
+ByteVector File::readBytes(unsigned long size) {
+       ByteVector data(readBlock(size));
+       if (data.size() != size) throw ReadError();
+       return data;
+}
+
+String File::readString(unsigned long size) {
+       ByteVector data(readBytes(size));
+       int index = data.find((char) 0);
+       if (index > -1) {
+               data.resize(index);
+       }
+       data.replace((char) 0xff, ' ');
+
+       return String(data);
+}
+
+uint8_t File::readByte() {
+       return readBytes(1)[0];
+}
+
+#ifdef HAVE_ENDIAN_H
+uint16_t File::readU16B() {
+       return be16toh(*(uint16_t*) readBytes(2).data());
+}
+
+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
+
+       }
+}
diff --git a/taglib/mod/modfile.h b/taglib/mod/modfile.h
new file mode 100644 (file)
index 0000000..d2f9e21
--- /dev/null
@@ -0,0 +1,51 @@
+/***************************************************************************
+    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_MODFILE_H
+#define TAGLIB_MODFILE_H
+
+#include <stdint.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) {}
+
+                               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();
+               };
+       }
+}
+
+#endif
diff --git a/taglib/mod/modtag.h b/taglib/mod/modtag.h
new file mode 100644 (file)
index 0000000..2b53efb
--- /dev/null
@@ -0,0 +1,54 @@
+/***************************************************************************
+    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_MODTAG_H
+#define TAGLIB_MODTAG_H
+
+#include <taglib/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; }
+
+                               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) {}
+
+                       private:
+                               String m_title;
+                               String m_comment;
+               };
+       }
+}
+
+#endif
diff --git a/taglib/s3m/s3mfile.cpp b/taglib/s3m/s3mfile.cpp
new file mode 100644 (file)
index 0000000..5bc24e2
--- /dev/null
@@ -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);
+       }
+}
+
+       }
+}
diff --git a/taglib/s3m/s3mfile.h b/taglib/s3m/s3mfile.h
new file mode 100644 (file)
index 0000000..8cc1194
--- /dev/null
@@ -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
diff --git a/taglib/s3m/s3mfiletyperesolver.cpp b/taglib/s3m/s3mfiletyperesolver.cpp
new file mode 100644 (file)
index 0000000..7ac67f1
--- /dev/null
@@ -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;
+       }
+}
diff --git a/taglib/s3m/s3mfiletyperesolver.h b/taglib/s3m/s3mfiletyperesolver.h
new file mode 100644 (file)
index 0000000..bbf87e1
--- /dev/null
@@ -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
diff --git a/taglib/s3m/s3mproperties.h b/taglib/s3m/s3mproperties.h
new file mode 100644 (file)
index 0000000..202a3d9
--- /dev/null
@@ -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
diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp
new file mode 100644 (file)
index 0000000..a71a56a
--- /dev/null
@@ -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);
+       }
+}
+
+       }
+}
diff --git a/taglib/xm/xmfile.h b/taglib/xm/xmfile.h
new file mode 100644 (file)
index 0000000..3dfadec
--- /dev/null
@@ -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
diff --git a/taglib/xm/xmfiletyperesolver.cpp b/taglib/xm/xmfiletyperesolver.cpp
new file mode 100644 (file)
index 0000000..16541bd
--- /dev/null
@@ -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;
+       }
+}
diff --git a/taglib/xm/xmfiletyperesolver.h b/taglib/xm/xmfiletyperesolver.h
new file mode 100644 (file)
index 0000000..4870988
--- /dev/null
@@ -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
diff --git a/taglib/xm/xmproperties.h b/taglib/xm/xmproperties.h
new file mode 100644 (file)
index 0000000..aee086f
--- /dev/null
@@ -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
diff --git a/taglib/xm/xmtag.h b/taglib/xm/xmtag.h
new file mode 100644 (file)
index 0000000..adbc546
--- /dev/null
@@ -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