From 1532f218ab5fce53fe8584b7d985aa7ae002c3b1 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Tue, 29 Mar 2022 18:26:16 +1100 Subject: [PATCH] ptformat: Update to upstream c1c6475 This changes region to track entries to make importing easier. Entries are now sequential, gapless and numbered from zero. --- libs/ptformat/ptformat.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libs/ptformat/ptformat.cc b/libs/ptformat/ptformat.cc index ca7f74df18..17aaa387b8 100644 --- a/libs/ptformat/ptformat.cc +++ b/libs/ptformat/ptformat.cc @@ -1066,6 +1066,42 @@ PTFFormat::parserest(void) { tr++; } } + + if (_tracks.begin() == _tracks.end()) + return found; + + /* Sort track entries by index */ + std::sort(_tracks.begin(), _tracks.end()); + + /* Renumber track entries to be gapless */ + for (std::vector::iterator tr = _tracks.begin() + 1; + tr != _tracks.end(); tr++) { + while ((*tr).index == (*(tr-1)).index) { + tr++; + if (tr == _tracks.end()) { + break; + } + } + if (tr == _tracks.end()) { + break; + } + int diffn = (*tr).index - (*(tr-1)).index - 1; + if (diffn) { + for (std::vector::iterator rest = tr; + rest != _tracks.end(); rest++) { + (*rest).index -= diffn; + } + } + } + + /* Renumber track entries to be zero based */ + int first = _tracks[0].index; + if (first > 0) { + for (std::vector::iterator tr = _tracks.begin(); + tr != _tracks.end(); tr++) { + (*tr).index -= first; + } + } return found; }