From d1cb8ae09db9f2379168696b51ba165846bcf9f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mathias=20Panzenb=C3=B6ck?= Date: Mon, 20 Jun 2011 02:19:16 +0200 Subject: [PATCH] IT: support channels property --- taglib/it/itfile.cpp | 17 +++++++++++++++++ taglib/it/itproperties.cpp | 13 ++++++++++--- taglib/it/itproperties.h | 7 ++++--- taglib/mod/modproperties.cpp | 10 +++++----- taglib/mod/modproperties.h | 6 +++--- tests/test_mod.cpp | 2 +- 6 files changed, 40 insertions(+), 15 deletions(-) diff --git a/taglib/it/itfile.cpp b/taglib/it/itfile.cpp index 1ec69313..d8040cdb 100644 --- a/taglib/it/itfile.cpp +++ b/taglib/it/itfile.cpp @@ -176,6 +176,23 @@ void IT::File::read(bool) } */ + seek(64); + + ByteVector pannings = readBlock(64); + ByteVector volumes = readBlock(64); + READ_ASSERT(pannings.size() == 64 && volumes.size() == 64); + int channels = 0; + for(int i = 0; i < 64; ++ i) + { + // Strictly speaking an IT file has always 64 channels, but + // I don't count disabled and muted channels. + // But this always gives 64 channels for all my files anyway. + // Strangely VLC does report other values. I wonder how VLC + // gets it's values. + if(pannings[i] < 128 && volumes[i] > 0) ++ channels; + } + d->properties.setChannels(channels); + StringList comment; // Note: I found files that have nil characters somewhere // in the instrument/sample names and more characters diff --git a/taglib/it/itproperties.cpp b/taglib/it/itproperties.cpp index d74779c8..84d69da9 100644 --- a/taglib/it/itproperties.cpp +++ b/taglib/it/itproperties.cpp @@ -28,6 +28,7 @@ class IT::Properties::PropertiesPrivate { public: PropertiesPrivate() : + channels(0), tableLength(0), stereo(false), instrumentCount(0), @@ -41,11 +42,12 @@ public: mixVolume(0), tempo(0), bpmSpeed(0), - panningSeparation(0), - pitchWheelDepth(0) + panningSeparation(0), + pitchWheelDepth(0) { } + int channels; ushort tableLength; bool stereo; ushort instrumentCount; @@ -91,7 +93,7 @@ int IT::Properties::sampleRate() const int IT::Properties::channels() const { - return d->stereo ? 2 : 1; + return d->channels; } ushort IT::Properties::tableLength() const @@ -169,6 +171,11 @@ uchar IT::Properties::pitchWheelDepth() const return d->pitchWheelDepth; } +void IT::Properties::setChannels(int channels) +{ + d->channels = channels; +} + void IT::Properties::setTableLength(ushort tableLength) { d->tableLength = tableLength; diff --git a/taglib/it/itproperties.h b/taglib/it/itproperties.h index dfcf3a62..fcf18dfc 100644 --- a/taglib/it/itproperties.h +++ b/taglib/it/itproperties.h @@ -51,13 +51,14 @@ namespace TagLib { ushort mixVolume() const; uchar tempo() const; uchar bpmSpeed() const; - uchar panningSeparation() const; - uchar pitchWheelDepth() const; + uchar panningSeparation() const; + uchar pitchWheelDepth() const; protected: + void setChannels(int channels); + void setTableLength(ushort tableLength); void setStereo(bool stereo); - void setInstrumentCount(ushort instrumentCount); void setSampleCount (ushort sampleCount); void setPatternCount(ushort patternCount); diff --git a/taglib/mod/modproperties.cpp b/taglib/mod/modproperties.cpp index 65215d16..a6fe4739 100644 --- a/taglib/mod/modproperties.cpp +++ b/taglib/mod/modproperties.cpp @@ -34,9 +34,9 @@ public: { } - int channels; - uint instrumentCount; - uint tableLength; + int channels; + uint instrumentCount; + uchar tableLength; }; Mod::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) : @@ -75,7 +75,7 @@ uint Mod::Properties::instrumentCount() const return d->instrumentCount; } -uint Mod::Properties::tableLength() const +uchar Mod::Properties::tableLength() const { return d->tableLength; } @@ -90,7 +90,7 @@ void Mod::Properties::setInstrumentCount(uint instrumentCount) d->instrumentCount = instrumentCount; } -void Mod::Properties::setTableLength(uint tableLength) +void Mod::Properties::setTableLength(uchar tableLength) { d->tableLength = tableLength; } diff --git a/taglib/mod/modproperties.h b/taglib/mod/modproperties.h index c92fd022..40bce747 100644 --- a/taglib/mod/modproperties.h +++ b/taglib/mod/modproperties.h @@ -38,14 +38,14 @@ namespace TagLib { int sampleRate() const; int channels() const; - uint instrumentCount() const; - uint tableLength() const; + uint instrumentCount() const; + uchar tableLength() const; protected: void setChannels(int channels); void setInstrumentCount(uint sampleCount); - void setTableLength(uint tableLength); + void setTableLength(uchar tableLength); private: Properties(const Properties&); diff --git a/tests/test_mod.cpp b/tests/test_mod.cpp index 2f6ff92f..49a8f182 100644 --- a/tests/test_mod.cpp +++ b/tests/test_mod.cpp @@ -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(1U, p->tableLength()); + CPPUNIT_ASSERT_EQUAL((uchar)1, p->tableLength()); CPPUNIT_ASSERT_EQUAL(title, t->title()); CPPUNIT_ASSERT_EQUAL(String::null, t->artist()); CPPUNIT_ASSERT_EQUAL(String::null, t->album()); -- 2.40.0