From 828440651f828cf5ae4524e72456d2c2afdaf081 Mon Sep 17 00:00:00 2001 From: redtide Date: Wed, 18 Sep 2019 20:33:08 +0200 Subject: [PATCH] WIP fixes: replace optional, string_view, nullopt with abseil versions, temporary clamp alternative. --- clients/sfzprint.cpp | 2 +- sfizz/ADSREnvelope.cpp | 2 +- sfizz/Buffer.h | 5 +- sfizz/Defaults.h | 184 +++++++++++++++++++------------------- sfizz/EGDescription.h | 18 ++-- sfizz/FilePool.cpp | 7 +- sfizz/FilePool.h | 10 +-- sfizz/LinearEnvelope.h | 3 +- sfizz/Opcode.cpp | 4 +- sfizz/Opcode.h | 20 ++--- sfizz/Parser.cpp | 23 ++--- sfizz/Parser.h | 2 +- sfizz/Range.h | 4 +- sfizz/Region.h | 24 ++--- sfizz/SfzHelpers.cpp | 2 +- sfizz/SfzHelpers.h | 9 +- sfizz/StringViewHelpers.h | 6 +- sfizz/Synth.cpp | 10 +-- sfizz/Synth.h | 10 +-- sfizz/compat/algorithm.h | 39 ++++++++ sfizz/filesystem.h | 14 +-- 21 files changed, 221 insertions(+), 177 deletions(-) create mode 100644 sfizz/compat/algorithm.h diff --git a/clients/sfzprint.cpp b/clients/sfzprint.cpp index 41e87b06..5a15f833 100644 --- a/clients/sfzprint.cpp +++ b/clients/sfzprint.cpp @@ -37,7 +37,7 @@ public: int getNumMasters() const noexcept { return numMasters; } int getNumCurves() const noexcept { return numCurves; } protected: - void callback(std::string_view header, const std::vector& members [[maybe_unused]]) final + void callback(absl::string_view header, const std::vector& members [[maybe_unused]]) final { switch (hash(header)) { diff --git a/sfizz/ADSREnvelope.cpp b/sfizz/ADSREnvelope.cpp index a5b12bc1..1a48030d 100644 --- a/sfizz/ADSREnvelope.cpp +++ b/sfizz/ADSREnvelope.cpp @@ -24,7 +24,7 @@ #include "ADSREnvelope.h" #include "Config.h" #include "SIMDHelpers.h" -#include +#include "compat/algorithm.h" namespace sfz { diff --git a/sfizz/Buffer.h b/sfizz/Buffer.h index c0f7f3bb..ca4e5c6f 100644 --- a/sfizz/Buffer.h +++ b/sfizz/Buffer.h @@ -72,7 +72,8 @@ public: paddedData = static_cast(newData); normalData = static_cast(std::align(Alignment, alignedSize, newData, tempSize)); normalEnd = normalData + alignedSize; - if (auto endMisalignment = (alignedSize & TypeAlignmentMask); endMisalignment != 0) + auto endMisalignment = (alignedSize & TypeAlignmentMask); + if (endMisalignment != 0) _alignedEnd = normalEnd + Alignment - endMisalignment; else _alignedEnd = normalEnd; @@ -156,4 +157,4 @@ private: pointer normalEnd { nullptr }; pointer _alignedEnd { nullptr }; LEAK_DETECTOR(Buffer); -}; \ No newline at end of file +}; diff --git a/sfizz/Defaults.h b/sfizz/Defaults.h index a4119be6..bbc0400a 100644 --- a/sfizz/Defaults.h +++ b/sfizz/Defaults.h @@ -39,114 +39,114 @@ namespace Default // The categories match http://sfzformat.com/ // ******* SFZ 1 ******* // Sound source: sample playback - inline constexpr float delay { 0.0 }; - inline constexpr float delayRandom { 0.0 }; - inline constexpr Range delayRange { 0.0, 100.0 }; - inline constexpr uint32_t offset { 0 }; - inline constexpr uint32_t offsetRandom { 0 }; - inline constexpr Range offsetRange { 0, std::numeric_limits::max() }; - inline constexpr Range sampleEndRange { 0, std::numeric_limits::max() }; - inline constexpr Range sampleCountRange { 0, std::numeric_limits::max() }; - inline constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop }; - inline constexpr Range loopRange { 0, std::numeric_limits::max() }; + constexpr float delay { 0.0 }; + constexpr float delayRandom { 0.0 }; + constexpr Range delayRange { 0.0, 100.0 }; + constexpr uint32_t offset { 0 }; + constexpr uint32_t offsetRandom { 0 }; + constexpr Range offsetRange { 0, std::numeric_limits::max() }; + constexpr Range sampleEndRange { 0, std::numeric_limits::max() }; + constexpr Range sampleCountRange { 0, std::numeric_limits::max() }; + constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop }; + constexpr Range loopRange { 0, std::numeric_limits::max() }; // Instrument setting: voice lifecycle - inline constexpr uint32_t group { 0 }; - inline constexpr Range groupRange { 0, std::numeric_limits::max() }; - inline constexpr SfzOffMode offMode { SfzOffMode::fast }; + constexpr uint32_t group { 0 }; + constexpr Range groupRange { 0, std::numeric_limits::max() }; + constexpr SfzOffMode offMode { SfzOffMode::fast }; // Region logic: key mapping - inline constexpr Range keyRange { 0, 127 }; - inline constexpr Range velocityRange { 0, 127 }; + constexpr Range keyRange { 0, 127 }; + constexpr Range velocityRange { 0, 127 }; // Region logic: MIDI conditions - inline constexpr Range channelRange { 1, 16 }; - inline constexpr Range ccRange { 0, 127 }; - inline constexpr uint8_t cc { 0 }; - inline constexpr Range bendRange { -8192, 8192 }; - inline constexpr int bend { 0 }; - inline constexpr SfzVelocityOverride velocityOverride { SfzVelocityOverride::current }; + constexpr Range channelRange { 1, 16 }; + constexpr Range ccRange { 0, 127 }; + constexpr uint8_t cc { 0 }; + constexpr Range bendRange { -8192, 8192 }; + constexpr int bend { 0 }; + constexpr SfzVelocityOverride velocityOverride { SfzVelocityOverride::current }; // Region logic: internal conditions - inline constexpr Range randRange { 0.0, 1.0 }; - inline constexpr Range aftertouchRange { 0, 127 }; - inline constexpr uint8_t aftertouch { 0 }; - inline constexpr Range bpmRange { 0.0, 500.0 }; - inline constexpr float bpm { 120.0 }; - inline constexpr uint8_t sequenceLength{ 1 }; - inline constexpr uint8_t sequencePosition{ 1 }; - inline constexpr Range sequenceRange { 1, 100 }; + constexpr Range randRange { 0.0, 1.0 }; + constexpr Range aftertouchRange { 0, 127 }; + constexpr uint8_t aftertouch { 0 }; + constexpr Range bpmRange { 0.0, 500.0 }; + constexpr float bpm { 120.0 }; + constexpr uint8_t sequenceLength{ 1 }; + constexpr uint8_t sequencePosition{ 1 }; + constexpr Range sequenceRange { 1, 100 }; // Region logic: Triggers - inline constexpr SfzTrigger trigger { SfzTrigger::attack }; - inline constexpr Range ccTriggerValueRange{ 0, 127 }; + constexpr SfzTrigger trigger { SfzTrigger::attack }; + constexpr Range ccTriggerValueRange{ 0, 127 }; // Performance parameters: amplifier - inline constexpr float volume { -3.0 }; - inline constexpr Range volumeRange { -144.0, 6.0 }; - inline constexpr Range volumeCCRange { -144.0, 6.0 }; - inline constexpr float amplitude { 100.0 }; - inline constexpr Range amplitudeRange { 0.0, 100.0 }; - inline constexpr float pan { 0.0 }; - inline constexpr Range panRange { -100.0, 100.0 }; - inline constexpr Range panCCRange { -200.0, 200.0 }; - inline constexpr float position { 0.0 }; - inline constexpr Range positionRange { -100.0, 100.0 }; - inline constexpr Range positionCCRange { -200.0, 200.0 }; - inline constexpr float width { 0.0 }; - inline constexpr Range widthRange { -100.0, 100.0 }; - inline constexpr Range widthCCRange { -200.0, 200.0 }; - inline constexpr uint8_t ampKeycenter { 60 }; - inline constexpr float ampKeytrack { 0.0 }; - inline constexpr Range ampKeytrackRange { -96, 12 }; - inline constexpr float ampVeltrack { 100.0 }; - inline constexpr Range ampVeltrackRange { -100.0, 100.0 }; - inline constexpr Range ampVelcurveRange { 0.0, 1.0 }; - inline constexpr float ampRandom { 0.0 }; - inline constexpr Range ampRandomRange { 0.0, 24.0 }; - inline constexpr Range crossfadeKeyInRange { 0, 0 }; - inline constexpr Range crossfadeKeyOutRange { 127, 127 }; - inline constexpr Range crossfadeVelInRange { 0, 0 }; - inline constexpr Range crossfadeVelOutRange { 127, 127 }; - inline constexpr Range crossfadeCCInRange { 0, 0 }; - inline constexpr Range crossfadeCCOutRange { 127, 127 }; - inline constexpr SfzCrossfadeCurve crossfadeKeyCurve { SfzCrossfadeCurve::power }; - inline constexpr SfzCrossfadeCurve crossfadeVelCurve { SfzCrossfadeCurve::power }; - inline constexpr SfzCrossfadeCurve crossfadeCCCurve { SfzCrossfadeCurve::power }; - inline constexpr float rtDecay { 0.0f }; - inline constexpr Range rtDecayRange { 0.0f, 200.0f }; + constexpr float volume { -3.0 }; + constexpr Range volumeRange { -144.0, 6.0 }; + constexpr Range volumeCCRange { -144.0, 6.0 }; + constexpr float amplitude { 100.0 }; + constexpr Range amplitudeRange { 0.0, 100.0 }; + constexpr float pan { 0.0 }; + constexpr Range panRange { -100.0, 100.0 }; + constexpr Range panCCRange { -200.0, 200.0 }; + constexpr float position { 0.0 }; + constexpr Range positionRange { -100.0, 100.0 }; + constexpr Range positionCCRange { -200.0, 200.0 }; + constexpr float width { 0.0 }; + constexpr Range widthRange { -100.0, 100.0 }; + constexpr Range widthCCRange { -200.0, 200.0 }; + constexpr uint8_t ampKeycenter { 60 }; + constexpr float ampKeytrack { 0.0 }; + constexpr Range ampKeytrackRange { -96, 12 }; + constexpr float ampVeltrack { 100.0 }; + constexpr Range ampVeltrackRange { -100.0, 100.0 }; + constexpr Range ampVelcurveRange { 0.0, 1.0 }; + constexpr float ampRandom { 0.0 }; + constexpr Range ampRandomRange { 0.0, 24.0 }; + constexpr Range crossfadeKeyInRange { 0, 0 }; + constexpr Range crossfadeKeyOutRange { 127, 127 }; + constexpr Range crossfadeVelInRange { 0, 0 }; + constexpr Range crossfadeVelOutRange { 127, 127 }; + constexpr Range crossfadeCCInRange { 0, 0 }; + constexpr Range crossfadeCCOutRange { 127, 127 }; + constexpr SfzCrossfadeCurve crossfadeKeyCurve { SfzCrossfadeCurve::power }; + constexpr SfzCrossfadeCurve crossfadeVelCurve { SfzCrossfadeCurve::power }; + constexpr SfzCrossfadeCurve crossfadeCCCurve { SfzCrossfadeCurve::power }; + constexpr float rtDecay { 0.0f }; + constexpr Range rtDecayRange { 0.0f, 200.0f }; // Performance parameters: pitch - inline constexpr uint8_t pitchKeycenter { 60 }; - inline constexpr int pitchKeytrack { 100 }; - inline constexpr Range pitchKeytrackRange { -1200, 1200 }; - inline constexpr int pitchRandom { 0 }; - inline constexpr Range pitchRandomRange { 0, 9600 }; - inline constexpr int pitchVeltrack { 0 }; - inline constexpr Range pitchVeltrackRange { -9600, 9600 }; - inline constexpr int transpose { 0 }; - inline constexpr Range transposeRange { -127, 127 }; - inline constexpr int tune { 0 }; - inline constexpr Range tuneRange { -100, 100 }; + constexpr uint8_t pitchKeycenter { 60 }; + constexpr int pitchKeytrack { 100 }; + constexpr Range pitchKeytrackRange { -1200, 1200 }; + constexpr int pitchRandom { 0 }; + constexpr Range pitchRandomRange { 0, 9600 }; + constexpr int pitchVeltrack { 0 }; + constexpr Range pitchVeltrackRange { -9600, 9600 }; + constexpr int transpose { 0 }; + constexpr Range transposeRange { -127, 127 }; + constexpr int tune { 0 }; + constexpr Range tuneRange { -100, 100 }; // Envelope generators - inline constexpr float attack { 0 }; - inline constexpr float decay { 0 }; - inline constexpr float delayEG { 0 }; - inline constexpr float hold { 0 }; - inline constexpr float release { 0 }; - inline constexpr float start { 0.0 }; - inline constexpr float sustain { 100.0 }; - inline constexpr float vel2sustain { 0.0 }; - inline constexpr int depth { 0 }; - inline constexpr Range egTimeRange { 0.0, 100.0 }; - inline constexpr Range egPercentRange { 0.0, 100.0 }; - inline constexpr Range egDepthRange { -12000, 12000 }; - inline constexpr Range egOnCCTimeRange { -100.0, 100.0 }; - inline constexpr Range egOnCCPercentRange { -100.0, 100.0 }; + constexpr float attack { 0 }; + constexpr float decay { 0 }; + constexpr float delayEG { 0 }; + constexpr float hold { 0 }; + constexpr float release { 0 }; + constexpr float start { 0.0 }; + constexpr float sustain { 100.0 }; + constexpr float vel2sustain { 0.0 }; + constexpr int depth { 0 }; + constexpr Range egTimeRange { 0.0, 100.0 }; + constexpr Range egPercentRange { 0.0, 100.0 }; + constexpr Range egDepthRange { -12000, 12000 }; + constexpr Range egOnCCTimeRange { -100.0, 100.0 }; + constexpr Range egOnCCPercentRange { -100.0, 100.0 }; // ***** SFZ v2 ******** - inline constexpr bool checkSustain { true }; // sustain_sw - inline constexpr bool checkSostenuto { true }; // sostenuto_sw + constexpr bool checkSustain { true }; // sustain_sw + constexpr bool checkSostenuto { true }; // sostenuto_sw +} } -} \ No newline at end of file diff --git a/sfizz/EGDescription.h b/sfizz/EGDescription.h index c5fc1e0e..ee40fba5 100644 --- a/sfizz/EGDescription.h +++ b/sfizz/EGDescription.h @@ -26,7 +26,7 @@ #include "Defaults.h" #include "LeakDetector.h" #include "SfzHelpers.h" -#include +#include namespace sfz @@ -55,13 +55,13 @@ struct EGDescription float vel2sustain { Default::vel2sustain }; int vel2depth { Default::depth }; - std::optional ccAttack; - std::optional ccDecay; - std::optional ccDelay; - std::optional ccHold; - std::optional ccRelease; - std::optional ccStart; - std::optional ccSustain; + absl::optional ccAttack; + absl::optional ccDecay; + absl::optional ccDelay; + absl::optional ccHold; + absl::optional ccRelease; + absl::optional ccStart; + absl::optional ccSustain; float getAttack(const CCValueArray &ccValues, uint8_t velocity) const noexcept { @@ -94,4 +94,4 @@ struct EGDescription LEAK_DETECTOR(EGDescription); }; -} //namespace sfz \ No newline at end of file +} //namespace sfz diff --git a/sfizz/FilePool.cpp b/sfizz/FilePool.cpp index 9b20a6b1..8392afb9 100644 --- a/sfizz/FilePool.cpp +++ b/sfizz/FilePool.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using namespace std::chrono_literals; template @@ -47,7 +48,7 @@ std::unique_ptr> readFromFile(SndfileHandle& sndFile, int numFram return returnedBuffer; } -std::optional sfz::FilePool::getFileInformation(std::string_view filename, uint32_t offset) noexcept +absl::optional sfz::FilePool::getFileInformation(absl::string_view filename, uint32_t offset) noexcept { std::filesystem::path file { rootDirectory / filename }; if (!std::filesystem::exists(file)) @@ -101,7 +102,7 @@ std::optional sfz::FilePool::getFileInformation( return returnedValue; } -void sfz::FilePool::enqueueLoading(Voice* voice, std::string_view sample, int numFrames, unsigned ticket) noexcept +void sfz::FilePool::enqueueLoading(Voice* voice, absl::string_view sample, int numFrames, unsigned ticket) noexcept { if (!loadingQueue.try_enqueue({ voice, sample, numFrames, ticket })) { DBG("Problem enqueuing a file read for file " << sample); @@ -161,4 +162,4 @@ void sfz::FilePool::clear() while (loadingQueue.pop()) { // Pop the queue } -} \ No newline at end of file +} diff --git a/sfizz/FilePool.h b/sfizz/FilePool.h index 453f7145..62270961 100644 --- a/sfizz/FilePool.h +++ b/sfizz/FilePool.h @@ -31,7 +31,7 @@ #include "readerwriterqueue.h" #include #include -#include +#include #include #include @@ -56,14 +56,14 @@ public: double sampleRate { config::defaultSampleRate }; std::shared_ptr> preloadedData; }; - std::optional getFileInformation(std::string_view filename, uint32_t offset) noexcept; - void enqueueLoading(Voice* voice, std::string_view sample, int numFrames, unsigned ticket) noexcept; + absl::optional getFileInformation(absl::string_view filename, uint32_t offset) noexcept; + void enqueueLoading(Voice* voice, absl::string_view sample, int numFrames, unsigned ticket) noexcept; void clear(); private: std::filesystem::path rootDirectory; struct FileLoadingInformation { Voice* voice; - std::string_view sample; + absl::string_view sample; int numFrames; unsigned ticket; }; @@ -76,7 +76,7 @@ private: std::thread garbageCollectionThread { &FilePool::garbageThread, this }; std::vector>> fileHandles; std::mutex fileHandleMutex; - absl::flat_hash_map>> preloadedData; + absl::flat_hash_map>> preloadedData; LEAK_DETECTOR(FilePool); }; } diff --git a/sfizz/LinearEnvelope.h b/sfizz/LinearEnvelope.h index 20a25b94..e246629f 100644 --- a/sfizz/LinearEnvelope.h +++ b/sfizz/LinearEnvelope.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace sfz { @@ -50,4 +51,4 @@ private: LEAK_DETECTOR(LinearEnvelope); }; -} \ No newline at end of file +} diff --git a/sfizz/Opcode.cpp b/sfizz/Opcode.cpp index a52203fd..f75ce0e9 100644 --- a/sfizz/Opcode.cpp +++ b/sfizz/Opcode.cpp @@ -24,13 +24,13 @@ #include "Opcode.h" #include "StringViewHelpers.h" -sfz::Opcode::Opcode(std::string_view inputOpcode, std::string_view inputValue) +sfz::Opcode::Opcode(absl::string_view inputOpcode, absl::string_view inputValue) : opcode(inputOpcode) , value(inputValue) { if (const auto lastCharIndex = inputOpcode.find_last_not_of("1234567890"); lastCharIndex != inputOpcode.npos) { int returnedValue; - std::string_view parameterView = inputOpcode; + absl::string_view parameterView = inputOpcode; parameterView.remove_prefix(lastCharIndex + 1); if (absl::SimpleAtoi(parameterView, &returnedValue)) { parameter = returnedValue; diff --git a/sfizz/Opcode.h b/sfizz/Opcode.h index be818f86..f392e45d 100644 --- a/sfizz/Opcode.h +++ b/sfizz/Opcode.h @@ -27,7 +27,7 @@ #include "Range.h" #include "SfzHelpers.h" #include "StringViewHelpers.h" -#include +#include #include // charconv support is still sketchy with clang/gcc so we use abseil's numbers @@ -36,16 +36,16 @@ namespace sfz { struct Opcode { Opcode() = delete; - Opcode(std::string_view inputOpcode, std::string_view inputValue); - std::string_view opcode {}; - std::string_view value {}; + Opcode(absl::string_view inputOpcode, absl::string_view inputValue); + absl::string_view opcode {}; + absl::string_view value {}; // This is to handle the integer parameter of some opcodes - std::optional parameter; + absl::optional parameter; LEAK_DETECTOR(Opcode); }; template -inline std::optional readOpcode(std::string_view value, const Range& validRange) +inline absl::optional readOpcode(absl::string_view value, const Range& validRange) { if constexpr (std::is_integral::value) { int64_t returnedValue; @@ -65,13 +65,13 @@ inline std::optional readOpcode(std::string_view value, const Range readBooleanFromOpcode(const Opcode& opcode) +inline absl::optional readBooleanFromOpcode(const Opcode& opcode) { switch (hash(opcode.value)) { case hash("off"): @@ -94,7 +94,7 @@ inline void setValueFromOpcode(const Opcode& opcode, ValueType& target, const Ra } template -inline void setValueFromOpcode(const Opcode& opcode, std::optional& target, const Range& validRange) +inline void setValueFromOpcode(const Opcode& opcode, absl::optional& target, const Range& validRange) { auto value = readOpcode(opcode.value, validRange); if (!value) // Try and read a note rather than a number @@ -124,7 +124,7 @@ inline void setRangeStartFromOpcode(const Opcode& opcode, Range& targ } template -inline void setCCPairFromOpcode(const Opcode& opcode, std::optional& target, const Range& validRange) +inline void setCCPairFromOpcode(const Opcode& opcode, absl::optional& target, const Range& validRange) { auto value = readOpcode(opcode.value, validRange); if (value && opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter)) diff --git a/sfizz/Parser.cpp b/sfizz/Parser.cpp index 64551cee..d3d8e471 100644 --- a/sfizz/Parser.cpp +++ b/sfizz/Parser.cpp @@ -28,12 +28,13 @@ #include #include -using svregex_iterator = std::regex_iterator; -using svmatch_results = std::match_results; +using svregex_iterator = std::regex_iterator; +using svmatch_results = std::match_results; -void removeCommentOnLine(std::string_view& line) +void removeCommentOnLine(absl::string_view& line) { - if (auto position = line.find("//"); position != line.npos) + auto position = line.find("//"); + if (position != line.npos) line.remove_suffix(line.size() - position); } @@ -48,7 +49,7 @@ bool sfz::Parser::loadSfzFile(const std::filesystem::path& file) readSfzFile(file, lines); aggregatedContent = absl::StrJoin(lines, " "); - const std::string_view aggregatedView { aggregatedContent }; + const absl::string_view aggregatedView { aggregatedContent }; svregex_iterator headerIterator(aggregatedView.cbegin(), aggregatedView.cend(), sfz::Regexes::headers); const auto regexEnd = svregex_iterator(); @@ -59,15 +60,15 @@ bool sfz::Parser::loadSfzFile(const std::filesystem::path& file) svmatch_results headerMatch = *headerIterator; // Can't use uniform initialization here because it generates narrowing conversions - const std::string_view header(&*headerMatch[1].first, headerMatch[1].length()); - const std::string_view members(&*headerMatch[2].first, headerMatch[2].length()); + const absl::string_view header(&*headerMatch[1].first, headerMatch[1].length()); + const absl::string_view members(&*headerMatch[2].first, headerMatch[2].length()); auto paramIterator = svregex_iterator(members.cbegin(), members.cend(), sfz::Regexes::members); // Store or handle members for (; paramIterator != regexEnd; ++paramIterator) { const svmatch_results paramMatch = *paramIterator; - const std::string_view opcode(&*paramMatch[1].first, paramMatch[1].length()); - const std::string_view value(&*paramMatch[2].first, paramMatch[2].length()); + const absl::string_view opcode(&*paramMatch[1].first, paramMatch[1].length()); + const absl::string_view value(&*paramMatch[2].first, paramMatch[2].length()); currentMembers.emplace_back(opcode, value); } callback(header, currentMembers); @@ -89,7 +90,7 @@ void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector std::string tmpString; while (std::getline(fileStream, tmpString)) { - std::string_view tmpView { tmpString }; + absl::string_view tmpView { tmpString }; removeCommentOnLine(tmpView); trimInPlace(tmpView); @@ -152,4 +153,4 @@ void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector newString += tmpView.substr(lastPos); lines.push_back(std::move(newString)); } -} \ No newline at end of file +} diff --git a/sfizz/Parser.h b/sfizz/Parser.h index ce94bad6..009c360e 100644 --- a/sfizz/Parser.h +++ b/sfizz/Parser.h @@ -47,7 +47,7 @@ public: void disableRecursiveIncludeGuard() { recursiveIncludeGuard = false; } void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; } protected: - virtual void callback(std::string_view header, const std::vector& members) = 0; + virtual void callback(absl::string_view header, const std::vector& members) = 0; std::filesystem::path rootDirectory { std::filesystem::current_path() }; private: bool recursiveIncludeGuard { false }; diff --git a/sfizz/Range.h b/sfizz/Range.h index 087fd112..dc56f057 100644 --- a/sfizz/Range.h +++ b/sfizz/Range.h @@ -22,7 +22,7 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once -#include +#include "compat/algorithm.h" #include #include @@ -108,4 +108,4 @@ template bool operator==(const std::pair& lhs, const Range& rhs) { return rhs == lhs; -} \ No newline at end of file +} diff --git a/sfizz/Region.h b/sfizz/Region.h index 352b8798..61a9a6e1 100644 --- a/sfizz/Region.h +++ b/sfizz/Region.h @@ -29,7 +29,7 @@ #include "Opcode.h" #include "AudioBuffer.h" #include -#include +#include #include #include #include @@ -73,13 +73,13 @@ struct Region { uint32_t offset { Default::offset }; // offset uint32_t offsetRandom { Default::offsetRandom }; // offset_random uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end - std::optional sampleCount {}; // count + absl::optional sampleCount {}; // count SfzLoopMode loopMode { Default::loopMode }; // loopmode Range loopRange { Default::loopRange }; //loopstart and loopend // Instrument settings: voice lifecycle uint32_t group { Default::group }; // group - std::optional offBy {}; // off_by + absl::optional offBy {}; // off_by SfzOffMode offMode { Default::offMode }; // off_mode // Region logic: key mapping @@ -91,10 +91,10 @@ struct Region { Range bendRange { Default::bendRange }; // hibend and lobend CCMap> ccConditions { Default::ccRange }; Range keyswitchRange { Default::keyRange }; // sw_hikey and sw_lokey - std::optional keyswitch {}; // sw_last - std::optional keyswitchUp {}; // sw_up - std::optional keyswitchDown {}; // sw_down - std::optional previousNote {}; // sw_previous + absl::optional keyswitch {}; // sw_last + absl::optional keyswitchUp {}; // sw_up + absl::optional keyswitchDown {}; // sw_down + absl::optional previousNote {}; // sw_previous SfzVelocityOverride velocityOverride { Default::velocityOverride }; // sw_vel bool checkSustain { Default::checkSustain }; // sustain_sw bool checkSostenuto { Default::checkSostenuto }; // sostenuto_sw @@ -116,11 +116,11 @@ struct Region { float pan { Default::pan }; // pan float width { Default::width }; // width float position { Default::position }; // position - std::optional volumeCC; // volume_oncc - std::optional amplitudeCC; // amplitude_oncc - std::optional panCC; // pan_oncc - std::optional widthCC; // width_oncc - std::optional positionCC; // position_oncc + absl::optional volumeCC; // volume_oncc + absl::optional amplitudeCC; // amplitude_oncc + absl::optional panCC; // pan_oncc + absl::optional widthCC; // width_oncc + absl::optional positionCC; // position_oncc uint8_t ampKeycenter { Default::ampKeycenter }; // amp_keycenter float ampKeytrack { Default::ampKeytrack }; // amp_keytrack float ampVeltrack { Default::ampVeltrack }; // amp_keytrack diff --git a/sfizz/SfzHelpers.cpp b/sfizz/SfzHelpers.cpp index 2a08b833..f72278bd 100644 --- a/sfizz/SfzHelpers.cpp +++ b/sfizz/SfzHelpers.cpp @@ -24,7 +24,7 @@ #include "SfzHelpers.h" #include "StringViewHelpers.h" -std::optional sfz::readNoteValue(const std::string_view& value) +absl::optional sfz::readNoteValue(const absl::string_view& value) { switch(hash(value)) { diff --git a/sfizz/SfzHelpers.h b/sfizz/SfzHelpers.h index eedb3039..10151814 100644 --- a/sfizz/SfzHelpers.h +++ b/sfizz/SfzHelpers.h @@ -22,8 +22,9 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once -#include -#include +#include +#include +//#include #include #include @@ -59,7 +60,7 @@ inline constexpr float normalizeNegativePercents(T percentValue) return std::min(std::max(static_cast(percentValue), -100.0f), 100.0f) / 100.0f; } -inline float ccSwitchedValue(const CCValueArray& ccValues, const std::optional& ccSwitch, float value) noexcept +inline float ccSwitchedValue(const CCValueArray& ccValues, const absl::optional& ccSwitch, float value) noexcept { if (ccSwitch) return value + ccSwitch->second * normalizeCC(ccValues[ccSwitch->first]); @@ -67,7 +68,7 @@ inline float ccSwitchedValue(const CCValueArray& ccValues, const std::optional readNoteValue(const std::string_view& value); +absl::optional readNoteValue(const absl::string_view& value); } // namespace sfz diff --git a/sfizz/StringViewHelpers.h b/sfizz/StringViewHelpers.h index 039f4c3f..22b127ab 100644 --- a/sfizz/StringViewHelpers.h +++ b/sfizz/StringViewHelpers.h @@ -24,7 +24,7 @@ #pragma once #include -inline void trimInPlace(std::string_view& s) +inline void trimInPlace(absl::string_view& s) { const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v"); if (leftPosition != s.npos) { @@ -36,7 +36,7 @@ inline void trimInPlace(std::string_view& s) } } -inline std::string_view trim(std::string_view s) +inline absl::string_view trim(absl::string_view s) { const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v"); if (leftPosition != s.npos) { @@ -52,7 +52,7 @@ inline std::string_view trim(std::string_view s) inline constexpr uint64_t Fnv1aBasis = 0x811C9DC5; inline constexpr uint64_t Fnv1aPrime = 0x01000193; -inline constexpr uint64_t hash(std::string_view s, uint64_t h = Fnv1aBasis) +inline constexpr uint64_t hash(absl::string_view s, uint64_t h = Fnv1aBasis) { if (s.length() > 0) return hash( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime ); diff --git a/sfizz/Synth.cpp b/sfizz/Synth.cpp index c523b71b..3d87726a 100644 --- a/sfizz/Synth.cpp +++ b/sfizz/Synth.cpp @@ -41,7 +41,7 @@ sfz::Synth::Synth() voiceViewArray.reserve(config::numVoices); } -void sfz::Synth::callback(std::string_view header, const std::vector& members) +void sfz::Synth::callback(absl::string_view header, const std::vector& members) { switch (hash(header)) { case hash("global"): @@ -87,7 +87,7 @@ void sfz::Synth::buildRegion(const std::vector& regionOpcodes) auto parseOpcodes = [&](const auto& opcodes) { for (auto& opcode : opcodes) { - const auto unknown = absl::c_find_if(unknownOpcodes, [&](std::string_view sv) { return sv.compare(opcode.opcode) == 0; }); + const auto unknown = absl::c_find_if(unknownOpcodes, [&](absl::string_view sv) { return sv.compare(opcode.opcode) == 0; }); if (unknown != unknownOpcodes.end()) { continue; } @@ -113,7 +113,7 @@ void sfz::Synth::clear() numMasters = 0; numCurves = 0; fileTicket = -1; - defaultSwitch = std::nullopt; + defaultSwitch = absl::nullopt; for (auto& state : ccState) state = 0; ccNames.clear(); @@ -426,11 +426,11 @@ const sfz::Region* sfz::Synth::getRegionView(int idx) const noexcept { return (size_t)idx < regions.size() ? regions[idx].get() : nullptr; } -std::set sfz::Synth::getUnknownOpcodes() const noexcept +std::set sfz::Synth::getUnknownOpcodes() const noexcept { return unknownOpcodes; } size_t sfz::Synth::getNumPreloadedSamples() const noexcept { return filePool.getNumPreloadedSamples(); -} \ No newline at end of file +} diff --git a/sfizz/Synth.h b/sfizz/Synth.h index 4954b37a..80f45343 100644 --- a/sfizz/Synth.h +++ b/sfizz/Synth.h @@ -28,7 +28,7 @@ #include "LeakDetector.h" #include "AudioSpan.h" #include "absl/types/span.h" -#include +#include #include #include #include @@ -46,7 +46,7 @@ public: int getNumMasters() const noexcept; int getNumCurves() const noexcept; const Region* getRegionView(int idx) const noexcept; - std::set getUnknownOpcodes() const noexcept; + std::set getUnknownOpcodes() const noexcept; size_t getNumPreloadedSamples() const noexcept; void setSamplesPerBlock(int samplesPerBlock) noexcept; @@ -62,7 +62,7 @@ public: void getNumActiveVoices() const noexcept; void garbageCollect() noexcept; protected: - void callback(std::string_view header, const std::vector& members) final; + void callback(absl::string_view header, const std::vector& members) final; private: bool hasGlobal { false }; @@ -83,8 +83,8 @@ private: CCValueArray ccState; Voice* findFreeVoice() noexcept; std::vector ccNames; - std::optional defaultSwitch; - std::set unknownOpcodes; + absl::optional defaultSwitch; + std::set unknownOpcodes; using RegionPtrVector = std::vector; using VoicePtrVector = std::vector; std::vector> regions; diff --git a/sfizz/compat/algorithm.h b/sfizz/compat/algorithm.h new file mode 100644 index 00000000..0993c4b8 --- /dev/null +++ b/sfizz/compat/algorithm.h @@ -0,0 +1,39 @@ +// Copyright (c) 2019, Paul Ferrand +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: + +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#include + +#if __cplusplus <= 201402L + #include + namespace std + { + template + constexpr const T& clamp( const T& v, const T& lo, const T& hi ) + { + assert( !(hi < lo) ); + return (v < lo) ? lo : (hi < v) ? hi : v; + } + } +#endif // lower than C++17 diff --git a/sfizz/filesystem.h b/sfizz/filesystem.h index 3ad22a65..7d5f5c14 100644 --- a/sfizz/filesystem.h +++ b/sfizz/filesystem.h @@ -24,12 +24,12 @@ #pragma once #if defined(__cpp_lib_filesystem) || (defined(__has_include) && __has_include()) -#include -#elif defined(__cpp_lib_experimental_filesystem) || (defined(__has_include) && __has_include()) -#include -namespace std { - namespace filesystem = std::experimental::filesystem; -} + #include +#elif __cplusplus >= 201103L + #include + namespace std { + namespace filesystem = std::experimental::filesystem; + } #else -#error no filesystem support + #error no filesystem support #endif