IT: strings require term. NUL. mod files: tableLength -> lengthInPatterns
authorMathias Panzenböck <grosser.meister.morti@gmx.net>
Thu, 23 Jun 2011 23:11:10 +0000 (01:11 +0200)
committerMathias Panzenböck <grosser.meister.morti@gmx.net>
Thu, 23 Jun 2011 23:11:10 +0000 (01:11 +0200)
Also added enums for S3M/IT/XM flags.

15 files changed:
taglib/it/itfile.cpp
taglib/it/itproperties.cpp
taglib/it/itproperties.h
taglib/mod/modfile.cpp
taglib/mod/modproperties.cpp
taglib/mod/modproperties.h
taglib/s3m/s3mfile.cpp
taglib/s3m/s3mproperties.cpp
taglib/s3m/s3mproperties.h
taglib/xm/xmfile.cpp
taglib/xm/xmproperties.cpp
taglib/xm/xmproperties.h
tests/test_mod.cpp
tests/test_s3m.cpp
tests/test_xm.cpp

index 09ff077d63637670f372e42142b2c4d61da2dd39..ed175c85f2ad78f51d9cd6ecbf0b5c0b962b2fd7 100644 (file)
@@ -78,7 +78,8 @@ bool IT::File::save()
     return false;
   }
   seek(4);
-  writeString(d->tag.title(), 26);
+  writeString(d->tag.title(), 25);
+  writeByte(0);
 
   seek(2, Current);
 
@@ -103,9 +104,10 @@ bool IT::File::save()
     seek(instrumentOffset + 32);
 
     if(i < lines.size())
-      writeString(lines[i], 26);
+      writeString(lines[i], 25);
     else
-      writeString(String::null, 26);
+      writeString(String::null, 25);
+    writeByte(0);
   }
 
   for(ushort i = 0; i < sampleCount; ++ i)
@@ -118,9 +120,10 @@ bool IT::File::save()
     seek(sampleOffset + 20);
 
     if((i + instrumentCount) < lines.size())
-      writeString(lines[i + instrumentCount], 26);
+      writeString(lines[i + instrumentCount], 25);
     else
-      writeString(String::null, 26);
+      writeString(String::null, 25);
+    writeByte(0);
   }
 
   // write rest as message:
@@ -128,6 +131,9 @@ bool IT::File::save()
   for(uint i = instrumentCount + sampleCount; i < lines.size(); ++ i)
     messageLines.append(lines[i]);
   ByteVector message = messageLines.toString("\r").data(String::Latin1);
+  if(message.size() > 8000)
+    message.resize(8000);
+
   ushort special = 0;
   ushort messageLength = 0;
   ulong  messageOffset = 0;
@@ -249,7 +255,7 @@ void IT::File::read(bool)
     if(order == 255) break;
     if(order != 254) ++ realLength;
   }
-  d->properties.setTableLength(realLength);
+  d->properties.setLengthInPatterns(realLength);
 
   StringList comment;
   // Note: I found files that have nil characters somewhere
@@ -290,6 +296,7 @@ void IT::File::read(bool)
     READ_BYTE_AS(sampleFlags);
     READ_BYTE_AS(sampleVolume);
     READ_STRING_AS(sampleName, 26);
+    /*
     READ_BYTE_AS(sampleCvt);
     READ_BYTE_AS(samplePanning);
     READ_U32L_AS(sampleLength);
@@ -303,15 +310,13 @@ void IT::File::read(bool)
     READ_BYTE_AS(vibratoDepth);
     READ_BYTE_AS(vibratoRate);
     READ_BYTE_AS(vibratoType);
+    */
     
     comment.append(sampleName);
   }
 
-  if(comment.size() > 0 && message.size() > 0)
-    d->tag.setComment(comment.toString("\n") + "\n" + message);
-  else if(comment.size() > 0)
-    d->tag.setComment(comment.toString("\n"));
-  else
-    d->tag.setComment(message);
+  if(message.size() > 0)
+    comment.append(message);
+  d->tag.setComment(comment.toString("\n"));
   d->tag.setTrackerName("Impulse Tracker");
 }
index ce9cefaaeea8de9529fd4ee00e22f0eccfafda33..7d181d5706558a126c853bba93dcc1943a224d09 100644 (file)
@@ -29,8 +29,7 @@ class IT::Properties::PropertiesPrivate
 public:
   PropertiesPrivate() :
     channels(0),
-    tableLength(0),
-    stereo(false),
+    lengthInPatterns(0),
     instrumentCount(0),
     sampleCount(0),
     patternCount(0),
@@ -48,8 +47,7 @@ public:
   }
 
   int    channels;
-  ushort tableLength;
-  bool   stereo;
+  ushort lengthInPatterns;
   ushort instrumentCount;
   ushort sampleCount;
   ushort patternCount;
@@ -96,14 +94,14 @@ int IT::Properties::channels() const
   return d->channels;
 }
 
-ushort IT::Properties::tableLength() const
+ushort IT::Properties::lengthInPatterns() const
 {
-  return d->tableLength;
+  return d->lengthInPatterns;
 }
 
 bool IT::Properties::stereo() const
 {
-  return d->stereo;
+  return d->flags & F_STEREO;
 }
 
 ushort IT::Properties::instrumentCount() const
@@ -176,14 +174,9 @@ void IT::Properties::setChannels(int channels)
   d->channels = channels;
 }
 
-void IT::Properties::setTableLength(ushort tableLength)
+void IT::Properties::setLengthInPatterns(ushort lengthInPatterns)
 {
-  d->tableLength = tableLength;
-}
-
-void IT::Properties::setStereo(bool stereo)
-{
-  d->stereo = stereo;
+  d->lengthInPatterns = lengthInPatterns;
 }
 
 void IT::Properties::setInstrumentCount(ushort instrumentCount) {
index 5e60ec58a33995dbda96450996a9bf84c872c0e6..632b87a887ed37180bf47890b2da666e7e256187 100644 (file)
@@ -30,6 +30,24 @@ namespace TagLib {
     class TAGLIB_EXPORT Properties : public AudioProperties {
       friend class File;
     public:
+      /*! Flag bits. */
+      enum {
+        F_STEREO             =   1,
+        F_VOL0_MIX_OPT       =   2,
+        F_INSTRUMENTS        =   4,
+        F_LINEAR_SLIDES      =   8,
+        F_OLD_EFFECTS        =  16,
+        F_LINK_EFFECT        =  32,
+        F_MIDI_PITCH_CTRL    =  64,
+        F_EMBEDDED_MIDI_CONF = 128
+      };
+
+      /*! Special bits. */
+      enum {
+        S_MESSAGE            = 1,
+        S_EMBEDDED_MIDI_CONF = 8
+      };
+
       Properties(AudioProperties::ReadStyle propertiesStyle);
       virtual ~Properties();
       
@@ -38,7 +56,7 @@ namespace TagLib {
       int sampleRate() const;
       int channels()   const;
 
-      ushort tableLength()       const;
+      ushort lengthInPatterns()  const;
       bool   stereo()            const;
       ushort instrumentCount()   const;
       ushort sampleCount()       const;
@@ -57,8 +75,7 @@ namespace TagLib {
     protected:
       void setChannels(int channels);
 
-      void setTableLength(ushort tableLength);
-      void setStereo(bool stereo);
+      void setLengthInPatterns(ushort lengthInPatterns);
       void setInstrumentCount(ushort instrumentCount);
       void setSampleCount (ushort sampleCount);
       void setPatternCount(ushort patternCount);
index 7047e857949b342bb3867a9be44500ba5fc561e5..9eb74f4b326d004d3a34b9d97decc9162ec422de 100644 (file)
@@ -178,7 +178,7 @@ void Mod::File::read(bool)
     comment.append(instrumentName);
   }
 
-  READ_BYTE(d->properties.setTableLength);
+  READ_BYTE(d->properties.setLengthInPatterns);
 
   d->tag.setComment(comment.toString("\n"));
 }
index a6fe47391ea54e6e8743ec895c7aad58c452ed6c..479034546757fa0dc2145fe32be971b7374f66ba 100644 (file)
@@ -30,13 +30,13 @@ public:
   PropertiesPrivate() :
     channels(0),
     instrumentCount(0),
-    tableLength(0)
+    lengthInPatterns(0)
   {
   }
   
   int   channels;
   uint  instrumentCount;
-  uchar tableLength;
+  uchar lengthInPatterns;
 };
 
 Mod::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) :
@@ -75,9 +75,9 @@ uint Mod::Properties::instrumentCount() const
   return d->instrumentCount;
 }
 
-uchar Mod::Properties::tableLength() const
+uchar Mod::Properties::lengthInPatterns() const
 {
-  return d->tableLength;
+  return d->lengthInPatterns;
 }
 
 void Mod::Properties::setChannels(int channels)
@@ -90,7 +90,7 @@ void Mod::Properties::setInstrumentCount(uint instrumentCount)
   d->instrumentCount = instrumentCount;
 }
 
-void Mod::Properties::setTableLength(uchar tableLength)
+void Mod::Properties::setLengthInPatterns(uchar lengthInPatterns)
 {
-  d->tableLength = tableLength;
+  d->lengthInPatterns = lengthInPatterns;
 }
index 40bce747f2e441638c24f5f78dad4be28cbe29f1..8bf3ac5ea0ab7cafc96385a0350c1a88c3266d51 100644 (file)
@@ -38,14 +38,14 @@ namespace TagLib {
       int sampleRate() const;
       int channels()   const;
 
-      uint  instrumentCount() const;
-      uchar tableLength()     const;
+      uint  instrumentCount()  const;
+      uchar lengthInPatterns() const;
 
     protected:
       void setChannels(int channels);
 
       void setInstrumentCount(uint sampleCount);
-      void setTableLength(uchar tableLength);
+      void setLengthInPatterns(uchar lengthInPatterns);
 
     private:
       Properties(const Properties&);
index a739ea524cbd7c9be9f046ff9c60b0ac09f617d2..e3f9c8ecfb000ccfcab441526898d91e2570030b 100644 (file)
@@ -191,7 +191,7 @@ void S3M::File::read(bool)
          if(order == 255) break;
          if(order != 254) ++ realLength;
   }
-  d->properties.setTableLength(realLength);
+  d->properties.setLengthInPatterns(realLength);
 
   seek(channels, Current);
 
index d7f40c8f570e1b701f0478a10957bdb3950211a8..8b50a60b545f84ab08becf9851c917df75a45aae 100644 (file)
@@ -28,7 +28,7 @@ class S3M::Properties::PropertiesPrivate
 {
 public:
   PropertiesPrivate() :
-    tableLength(0),
+    lengthInPatterns(0),
     channels(0),
     stereo(false),
     sampleCount(0),
@@ -43,7 +43,7 @@ public:
   {
   }
   
-  ushort tableLength;
+  ushort lengthInPatterns;
   int    channels;
   bool   stereo;
   ushort sampleCount;
@@ -88,9 +88,9 @@ int S3M::Properties::channels() const
   return d->channels;
 }
 
-ushort S3M::Properties::tableLength() const
+ushort S3M::Properties::lengthInPatterns() const
 {
-  return d->tableLength;
+  return d->lengthInPatterns;
 }
 
 bool S3M::Properties::stereo() const
@@ -143,9 +143,9 @@ uchar S3M::Properties::bpmSpeed() const
   return d->bpmSpeed;
 }
 
-void S3M::Properties::setTableLength(ushort tableLength)
+void S3M::Properties::setLengthInPatterns(ushort lengthInPatterns)
 {
-  d->tableLength = tableLength;
+  d->lengthInPatterns = lengthInPatterns;
 }
 
 void S3M::Properties::setChannels(int channels)
index 8721477071ab049123daf6f1c5cf9c7ddd052068..bbfc7c61335e069ce0d40e63c77c4ef04ce58ca9 100644 (file)
@@ -30,6 +30,17 @@ namespace TagLib {
     class TAGLIB_EXPORT Properties : public AudioProperties {
       friend class File;
     public:
+      /*! Flag bits. */
+      enum {
+        F_ST2_VIBRATO   =   1,
+        F_ST2_TEMPO     =   2,
+        F_AMIGA_SLIDES  =   4,
+        F_VOL0_MIX_OPT  =   8,
+        F_AMIGA_LIMITS  =  16,
+        F_ENABLE_FILTER =  32,
+        F_CUSTOM_DATA   = 128
+      };
+
       Properties(AudioProperties::ReadStyle propertiesStyle);
       virtual ~Properties();
       
@@ -38,7 +49,7 @@ namespace TagLib {
       int sampleRate() const;
       int channels()   const;
 
-      ushort tableLength()       const;
+      ushort lengthInPatterns()  const;
       bool   stereo()            const;
       ushort sampleCount()       const;
       ushort patternCount()      const;
@@ -51,9 +62,9 @@ namespace TagLib {
       uchar  bpmSpeed()          const;
 
     protected:
-      void setTableLength(ushort tableLength);
       void setChannels(int channels);
 
+      void setLengthInPatterns (ushort lengthInPatterns);
       void setStereo           (bool stereo);
       void setSampleCount      (ushort sampleCount);
       void setPatternCount     (ushort patternCount);
index 7b07d116b656c1596dc92e6b6384bac97a8b3105..1ea9e027e6abd3b3c667780742a0e4b66b784c61 100644 (file)
@@ -465,10 +465,10 @@ bool XM::File::save()
         {
           if(sampleHeaderSize > 4U)
           {
-            ulong length = 0;
-            if(!readU32L(length))
+            ulong sampleLength = 0;
+            if(!readU32L(sampleLength))
               return false;
-            offset += length;
+            offset += sampleLength;
 
             seek(std::min(sampleHeaderSize, 14UL), Current);
             if(sampleHeaderSize > 18U)
@@ -523,7 +523,7 @@ void XM::File::read(bool)
   READ_U32L_AS(headerSize);
   READ_ASSERT(headerSize >= 4);
 
-  ushort tableLength     = 0;
+  ushort length          = 0;
   ushort restartPosition = 0;
   ushort channels        = 0;
   ushort patternCount    = 0;
@@ -533,7 +533,7 @@ void XM::File::read(bool)
   ushort bpmSpeed = 0;
 
   StructReader header;
-  header.u16L(tableLength)
+  header.u16L(length)
         .u16L(restartPosition)
         .u16L(channels)
         .u16L(patternCount)
@@ -547,7 +547,7 @@ void XM::File::read(bool)
   
   READ_ASSERT(count == size);
 
-  d->properties.setTableLength(tableLength);
+  d->properties.setLengthInPatterns(length);
   d->properties.setRestartPosition(restartPosition);
   d->properties.setChannels(channels);
   d->properties.setPatternCount(patternCount);
@@ -609,18 +609,18 @@ void XM::File::read(bool)
 
       for(ushort j = 0; j < sampleCount; ++ j)
       {
-        ulong length      = 0;
-        ulong loopStart   = 0;
-        ulong loopLength  = 0;
-        uchar volume      = 0;
-        uchar finetune    = 0;
-        uchar sampleType  = 0;
-        uchar panning     = 0;
-        uchar noteNumber  = 0;
-        uchar compression = 0;
+        ulong sampleLength = 0;
+        ulong loopStart    = 0;
+        ulong loopLength   = 0;
+        uchar volume       = 0;
+        uchar finetune     = 0;
+        uchar sampleType   = 0;
+        uchar panning      = 0;
+        uchar noteNumber   = 0;
+        uchar compression  = 0;
         String sampleName;
         StructReader sample;
-        sample.u32L(length)
+        sample.u32L(sampleLength)
               .u32L(loopStart)
               .u32L(loopLength)
               .byte(volume)
@@ -636,7 +636,7 @@ void XM::File::read(bool)
         // skip unhandeled header proportion:
         seek(sampleHeaderSize - count, Current);
 
-        offset += length;
+        offset += sampleLength;
         sampleNames.append(sampleName);
       }
     }
index c6b2b7f3b10affb2e280e2b6f72bb412b228974c..e0b489acff2293b33a4ba3016d8be950e7595dd0 100644 (file)
@@ -28,7 +28,7 @@ class XM::Properties::PropertiesPrivate
 {
 public:
   PropertiesPrivate() :
-    tableLength(0),
+    lengthInPatterns(0),
     channels(0),
     version(0),
     restartPosition(0),
@@ -41,7 +41,7 @@ public:
   {
   }
   
-  ushort tableLength;
+  ushort lengthInPatterns;
   int    channels;
   ushort version;
   ushort restartPosition;
@@ -84,9 +84,9 @@ int XM::Properties::channels() const
   return d->channels;
 }
 
-ushort XM::Properties::tableLength() const
+ushort XM::Properties::lengthInPatterns() const
 {
-  return d->tableLength;
+  return d->lengthInPatterns;
 }
 
 ushort XM::Properties::version() const
@@ -129,9 +129,9 @@ ushort XM::Properties::bpmSpeed() const
   return d->bpmSpeed;
 }
 
-void XM::Properties::setTableLength(ushort tableLength)
+void XM::Properties::setLengthInPatterns(ushort lengthInPatterns)
 {
-  d->tableLength = tableLength;
+  d->lengthInPatterns = lengthInPatterns;
 }
 
 void XM::Properties::setChannels(int channels)
index fb8397aa651cef5b8c81c7766704e22860f4ac9f..f1aba4049cdfea9e6764c3a70c649177fe290f1c 100644 (file)
@@ -31,6 +31,11 @@ namespace TagLib {
     class Properties : public AudioProperties {
       friend class File;
     public:
+      /*! Flag bits. */
+      enum {
+        F_AMIGA_FREQ = 1
+      };
+
       Properties(AudioProperties::ReadStyle propertiesStyle);
       virtual ~Properties();
       
@@ -39,20 +44,20 @@ namespace TagLib {
       int sampleRate() const;
       int channels()   const;
 
-      ushort tableLength()     const;
-      ushort version()         const;
-      ushort restartPosition() const;
-      ushort patternCount()    const;
-      ushort instrumentCount() const;
-      uint   sampleCount()     const;
-      ushort flags()           const;
-      ushort tempo()           const;
-      ushort bpmSpeed()        const;
+      ushort lengthInPatterns() const;
+      ushort version()          const;
+      ushort restartPosition()  const;
+      ushort patternCount()     const;
+      ushort instrumentCount()  const;
+      uint   sampleCount()      const;
+      ushort flags()            const;
+      ushort tempo()            const;
+      ushort bpmSpeed()         const;
 
     protected:
       void setChannels(int channels);
 
-      void setTableLength(ushort tableLength);
+      void setLengthInPatterns(ushort lengthInPatterns);
       void setVersion(ushort version);
       void setRestartPosition(ushort restartPosition);
       void setPatternCount(ushort patternCount);
index 49a8f182349c5836e0cc32126f61a5468b76eb08..67c46f28340ddf670cfb001c4ab867f79182364d 100644 (file)
@@ -93,7 +93,7 @@ private:
     CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
     CPPUNIT_ASSERT_EQUAL(8, p->channels());
     CPPUNIT_ASSERT_EQUAL(31U, p->instrumentCount());
-    CPPUNIT_ASSERT_EQUAL((uchar)1, p->tableLength());
+    CPPUNIT_ASSERT_EQUAL((uchar)1, p->lengthInPatterns());
     CPPUNIT_ASSERT_EQUAL(title, t->title());
     CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
     CPPUNIT_ASSERT_EQUAL(String::null, t->album());
index efc9745c51f246fd36d8d8a0c3041d9c75450f37..e25666267edc793ee23d2ca6ad628bfb0e1f80a0 100644 (file)
@@ -98,7 +98,7 @@ private:
     CPPUNIT_ASSERT_EQUAL( 0, p->bitrate());
     CPPUNIT_ASSERT_EQUAL( 0, p->sampleRate());
     CPPUNIT_ASSERT_EQUAL(16, p->channels());
-    CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  0, p->tableLength());
+    CPPUNIT_ASSERT_EQUAL((TagLib::ushort)   0, p->lengthInPatterns());
     CPPUNIT_ASSERT_EQUAL(false, p->stereo());
     CPPUNIT_ASSERT_EQUAL((TagLib::ushort)   5, p->sampleCount());
     CPPUNIT_ASSERT_EQUAL((TagLib::ushort)   1, p->patternCount());
index 3e74524da947c750c1ac27cea9c5b04ef410abc5..c6af369ecb885de3b80507b23cbd04bf9b217824 100644 (file)
@@ -130,7 +130,7 @@ public:
     CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
     CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
     CPPUNIT_ASSERT_EQUAL(8, p->channels());
-    CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  1, p->tableLength());
+    CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  1, p->lengthInPatterns());
     CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  0, p->version());
     CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  0 , p->restartPosition());
     CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  1, p->patternCount());
@@ -176,7 +176,7 @@ private:
     CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
     CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
     CPPUNIT_ASSERT_EQUAL(8, p->channels());
-    CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  1, p->tableLength());
+    CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  1, p->lengthInPatterns());
     CPPUNIT_ASSERT_EQUAL((TagLib::ushort)260, p->version());
     CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  0, p->restartPosition());
     CPPUNIT_ASSERT_EQUAL((TagLib::ushort)  1, p->patternCount());