From 065155931c4422487b304f7c5bc3a8b5c1d0899e Mon Sep 17 00:00:00 2001 From: Matt Firth Date: Tue, 21 May 2024 11:58:48 +0100 Subject: [PATCH] Remove redundant funcs and associated tests --- .../src/reaper_adm/reaperapi.h | 3 - .../src/reaper_adm/reaperapiimpl.cpp | 125 ------------------ .../src/reaper_adm/reaperapiimpl.h | 3 - .../test/reaper_adm/mocks/reaperapi.h | 3 - .../test/reaper_adm/pluginrenametests.cpp | 121 ----------------- 5 files changed, 255 deletions(-) diff --git a/reaper-adm-extension/src/reaper_adm/reaperapi.h b/reaper-adm-extension/src/reaper_adm/reaperapi.h index 16945417d..b110c8d0a 100644 --- a/reaper-adm-extension/src/reaper_adm/reaperapi.h +++ b/reaper-adm-extension/src/reaper_adm/reaperapi.h @@ -194,9 +194,6 @@ class ReaperAPI { virtual void CleanFXName(std::string& name) const = 0; virtual int TrackFX_PositionByActualName(MediaTrack* track, const std::string& fxName) const = 0; virtual int TrackFX_AddByActualName(MediaTrack* track, const char* fxname, bool recFX, int instantiate) const = 0; - virtual std::vector> GetVSTElementsFromTrackStateChunk(const std::string& fullChunk) const = 0; - virtual std::vector SplitVSTElement(const std::string& elm, bool stripBoundingQuotes, bool includeSeperators) const = 0; - virtual std::string GetTrackStateChunkStr(MediaTrack* track) const = 0; virtual int GetDawChannelCount() const = 0; }; diff --git a/reaper-adm-extension/src/reaper_adm/reaperapiimpl.cpp b/reaper-adm-extension/src/reaper_adm/reaperapiimpl.cpp index 5769bc460..eb493d1bc 100644 --- a/reaper-adm-extension/src/reaper_adm/reaperapiimpl.cpp +++ b/reaper-adm-extension/src/reaper_adm/reaperapiimpl.cpp @@ -824,131 +824,6 @@ std::optional> admplug::ReaperAPIImpl::getTrackAudioBo return std::optional>(); } -std::vector> admplug::ReaperAPIImpl::GetVSTElementsFromTrackStateChunk(const std::string& fullChunk) const -{ - std::vector> vst3Elements; - - const std::vector quoteMarks{ '\'', '`', '"' }; - int elmStart = -1; - - for (int pos = 0; pos < fullChunk.length(); ++pos) { - - bool escapedQuote = false; - for (auto quote : quoteMarks) { - if (fullChunk[pos] == quote) { - // Entered a quote mark - if (pos == fullChunk.length() - 1) { - // Already at EOF - don't attempt to find - escapedQuote = true; - break; - } - // Find end quote mark - auto newPos = fullChunk.find(quote, pos + 1); - if (newPos == std::string::npos) { - // End not found to EOF - abort - escapedQuote = true; - break; - } - pos = newPos; - } - } - if (escapedQuote) { - break; - } - - if (elmStart == -1) { - // Not in an element - check if at start of one - if (fullChunk.substr(pos, 5) == "") { - vst3Elements.push_back(std::make_pair( - elmStart, - fullChunk.substr(elmStart, pos - elmStart + 1)) - ); - elmStart = -1; - } - } - } - - return vst3Elements; -} - -std::vector admplug::ReaperAPIImpl::SplitVSTElement(const std::string& elm, bool stripBoundingQuotes, bool includeSeperators) const -{ - std::vector sec; - - const std::vector quoteMarks{ '\'', '`', '"' }; - const std::vector splitMarks{ ' ', '\r', '\n' }; - int secStart = 5; - - for (int pos = 5; pos < elm.length(); ++pos) { - - bool escapedQuote = false; - for (auto quote : quoteMarks) { - if (elm[pos] == quote) { - // Entered a quote mark - if (pos == elm.length() - 1) { - // Already at EOF - don't attempt to find - escapedQuote = true; - break; - } - // Find end quote mark - auto newPos = elm.find(quote, pos + 1); - if (newPos == std::string::npos) { - // End not found to EOF - abort - escapedQuote = true; - break; - } - pos = newPos; - } - } - if (escapedQuote) { - break; - } - - for (auto splitMark : splitMarks) { - if (elm[pos] == splitMark) { - // Close this section and start a new one - sec.push_back(elm.substr(secStart, pos - secStart)); - if (includeSeperators) { - sec.push_back(std::string{ splitMark }); - } - secStart = pos + 1; - break; - } - } - } - - if (stripBoundingQuotes) { - for (auto& s : sec) { - if (s.length() >= 2) { - for (auto quote : quoteMarks) { - if (s[0] == quote && s[s.length() - 1] == quote) { - s = s.substr(1, s.length() - 2); - break; - } - } - } - } - } - - return sec; -} - -std::string admplug::ReaperAPIImpl::GetTrackStateChunkStr(MediaTrack* track) const -{ - const size_t chunkMaxLen = 65535; // Should be plenty - char chunk[chunkMaxLen]; - auto res = GetTrackStateChunk(track, chunk, chunkMaxLen, false); - if (!res) return std::string(); - std::string fullChunk{ chunk, strnlen(chunk, chunkMaxLen) }; - return fullChunk; -} - int admplug::ReaperAPIImpl::GetDawChannelCount() const { return GetReaperChannelCount(GetAppVersion()); diff --git a/reaper-adm-extension/src/reaper_adm/reaperapiimpl.h b/reaper-adm-extension/src/reaper_adm/reaperapiimpl.h index 38f576a37..52d005863 100644 --- a/reaper-adm-extension/src/reaper_adm/reaperapiimpl.h +++ b/reaper-adm-extension/src/reaper_adm/reaperapiimpl.h @@ -144,9 +144,6 @@ class ReaperAPIImpl : public ReaperAPI void CleanFXName(std::string& name) const override; int TrackFX_PositionByActualName(MediaTrack* track, const std::string& fxName) const override; int TrackFX_AddByActualName(MediaTrack* track, const char* fxname, bool recFX, int instantiate) const override; - std::vector> GetVSTElementsFromTrackStateChunk(const std::string& fullChunk) const override; - std::vector SplitVSTElement(const std::string& elm, bool stripBoundingQuotes, bool includeSeperators) const override; - std::string GetTrackStateChunkStr(MediaTrack* track) const override; int GetDawChannelCount() const override; private: diff --git a/reaper-adm-extension/test/reaper_adm/mocks/reaperapi.h b/reaper-adm-extension/test/reaper_adm/mocks/reaperapi.h index f18be660f..60a712f41 100644 --- a/reaper-adm-extension/test/reaper_adm/mocks/reaperapi.h +++ b/reaper-adm-extension/test/reaper_adm/mocks/reaperapi.h @@ -236,9 +236,6 @@ class MockReaperAPI : public ReaperAPI { MOCK_CONST_METHOD1(CleanFXName, void(std::string& name)); MOCK_CONST_METHOD2(TrackFX_PositionByActualName, int(MediaTrack* track, const std::string& fxName)); MOCK_CONST_METHOD4(TrackFX_AddByActualName, int(MediaTrack* track, const char* fxname, bool recFX, int instantiate)); - MOCK_CONST_METHOD1(GetVSTElementsFromTrackStateChunk, std::vector>(const std::string& fullChunk)); - MOCK_CONST_METHOD3(SplitVSTElement, std::vector(const std::string& elm, bool stripBoundingQuotes, bool includeSeperators)); - MOCK_CONST_METHOD1(GetTrackStateChunkStr, std::string(MediaTrack* track)); MOCK_CONST_METHOD0(GetDawChannelCount, int()); }; diff --git a/reaper-adm-extension/test/reaper_adm/pluginrenametests.cpp b/reaper-adm-extension/test/reaper_adm/pluginrenametests.cpp index 0f47b35bd..f514c1e61 100644 --- a/reaper-adm-extension/test/reaper_adm/pluginrenametests.cpp +++ b/reaper-adm-extension/test/reaper_adm/pluginrenametests.cpp @@ -2,129 +2,8 @@ #include #include -const std::string trackState = -R"STATESTRING( -PRESETNAME "Program 1" -FLOATPOS 1944 -62 616 512 -FXID {159FD704-E101-42BC-A4D2-8F3F263F5160} -WAK 0 0 -BYPASS 0 0 0 - -PRESETNAME "Program 1" -FLOATPOS 1944 -62 742 738 -FXID {66EFE191-C8CE-4786-8C38-4BE42D751146} -WAK 0 0 -BYPASS 0 0 0 - -PRESETNAME "Program 1" -FLOATPOS 1944 -62 742 738 -FXID {24D3CD65-1A9A-44D6-B8A1-5FBC65C39DD5} -WAK 0 0 -BYPASS 0 0 0 - -PRESETNAME "Program 1" -FLOATPOS 1944 -62 742 738 -FXID {493829B3-8224-4E57-AC50-ED2C5E652E31} -WAK 0 0 -BYPASS 0 0 0 - -PRESETNAME "Program 1" -FLOATPOS 1944 -62 742 738 -FXID {17FB49CB-DDA3-41B4-BAF3-9365DF7AC29C} -WAK 0 0 -> ->)STATESTRING"; - using namespace admplug; -TEST_CASE("Track State Chunk Parsing") { - - reaper_plugin_info_t info{}; - admplug::ReaperAPIImpl api(info); - - auto vst3Elements = api.GetVSTElementsFromTrackStateChunk(trackState); - - REQUIRE(vst3Elements.size() == 5); - - for (int i = 0; i < vst3Elements.size(); ++i) { - auto el = vst3Elements[i]; - auto s = api.SplitVSTElement(el.second, true, false); - - REQUIRE(s.size() >= 6); - REQUIRE(s[0] == "VST3: EAR Object (EBU)"); - REQUIRE(s[1] == "EAR Object.vst3"); - - if (i == 0) REQUIRE(s[3] == "Custom Name"); - if (i == 1) REQUIRE(s[3] == "SingleWord"); - if (i == 2) REQUIRE(s[3] == "'quote' \"Marks\" 'lol'"); - if (i == 3) REQUIRE(s[3] == "\"just in quotes\""); - if (i == 4) REQUIRE(s[3] == ""); - } - -} - TEST_CASE("Clean Plugin Name") { reaper_plugin_info_t info{};