From 81a9f7a956f3cf3c353f72e6d80e4d7bec0271c7 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Tue, 2 Feb 2016 16:49:12 +1100 Subject: Unjumble the PT5 wav ordering in regions/tracks by sorting alphanumerically and case insensitively Signed-off-by: Damien Zammit --- libs/ptformat/ptfformat.cc | 28 +++++++++++++++++++++++++--- libs/ptformat/ptfformat.h | 8 +++++++- 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'libs/ptformat') diff --git a/libs/ptformat/ptfformat.cc b/libs/ptformat/ptfformat.cc index f233f51dfa..99c89510dc 100644 --- a/libs/ptformat/ptfformat.cc +++ b/libs/ptformat/ptfformat.cc @@ -630,6 +630,17 @@ PTFFormat::parserest5(void) { } } +void +PTFFormat::resort(std::vector *ws) { + int j = 0; + std::sort((*ws).begin(), (*ws).end()); + for (std::vector::iterator i = (*ws).begin(); + i != (*ws).end(); ++i) { + (*i).index = j; + j++; + } +} + void PTFFormat::parseaudio5(void) { int i,k,l; @@ -670,6 +681,7 @@ PTFFormat::parseaudio5(void) { wavnumber = 0; i+=16; + char ext[5]; while (i < len && numberofwavs > 0) { i++; if ( (ptfunxored[i ] == 0x5a) && @@ -684,11 +696,19 @@ PTFFormat::parseaudio5(void) { wavname[l] = ptfunxored[i+l]; l++; } - i+=lengthofname + 4; + i+=lengthofname; + ext[0] = ptfunxored[i++]; + ext[1] = ptfunxored[i++]; + ext[2] = ptfunxored[i++]; + ext[3] = ptfunxored[i++]; + ext[4] = '\0'; + wavname[l] = 0; - if (foundin(wavname, ".wav")) { + if (foundin(wavname, ".L") || foundin(wavname, ".R")) { + extension = string(""); + } else if (foundin(wavname, ".wav") || foundin(ext, "WAVE")) { extension = string(".wav"); - } else if (foundin(wavname, ".aif")) { + } else if (foundin(wavname, ".aif") || foundin(ext, "AIFF")) { extension = string(".aif"); } else { extension = string(""); @@ -707,6 +727,8 @@ PTFFormat::parseaudio5(void) { numberofwavs--; i += 7; } + resort(&actualwavs); + resort(&audiofiles); } void diff --git a/libs/ptformat/ptfformat.h b/libs/ptformat/ptfformat.h index be7076dbfd..1d3dac2ba3 100644 --- a/libs/ptformat/ptfformat.h +++ b/libs/ptformat/ptfformat.h @@ -16,10 +16,10 @@ #define PTFFORMAT_H #include +#include #include #include #include - #include "ptformat/visibility.h" class LIBPTFORMAT_API PTFFormat { @@ -39,6 +39,11 @@ public: int64_t posabsolute; int64_t length; + bool operator <(const struct wav& other) { + return (strcasecmp(this->filename.c_str(), + other.filename.c_str()) < 0); + } + bool operator ==(const struct wav& other) { return (this->filename == other.filename || this->index == other.index); @@ -125,6 +130,7 @@ private: void parserest10(void); void parseaudio5(void); void parseaudio(void); + void resort(std::vector *ws); std::vector actualwavs; float ratefactor; std::string extension; -- cgit v1.2.3