diff --git a/sources/ADSREnvelope.cpp b/sources/ADSREnvelope.cpp index b6603527..626d99d3 100644 --- a/sources/ADSREnvelope.cpp +++ b/sources/ADSREnvelope.cpp @@ -1,13 +1,12 @@ -#include "Globals.h" -#include "SIMDHelpers.h" -#include "Helpers.h" #include "ADSREnvelope.h" +#include "Globals.h" +#include "Helpers.h" +#include "SIMDHelpers.h" #include -namespace sfz -{ +namespace sfz { -template +template void ADSREnvelope::reset(int attack, int release, Type sustain, int delay, int decay, int hold, Type start, Type depth) noexcept { ASSERT(start <= 1.0f); @@ -32,44 +31,40 @@ void ADSREnvelope::reset(int attack, int release, Type sustain, int delay, currentState = State::Delay; } -template +template Type ADSREnvelope::getNextValue() noexcept { - if (shouldRelease && releaseDelay-- == 0) - { + if (shouldRelease && releaseDelay-- == 0) { currentState = State::Release; step = std::exp((std::log(config::virtuallyZero) - std::log(currentValue)) / (release > 0 ? release : 1)); } - - switch(currentState) - { + + switch (currentState) { case State::Delay: if (delay-- > 0) return start; - + currentState = State::Attack; step = (1.0 - currentValue) / (attack > 0 ? attack : 1); [[fallthrough]]; case State::Attack: - if (attack-- > 0) - { + if (attack-- > 0) { currentValue += step; return currentValue; } - + currentState = State::Hold; currentValue = 1.0; [[fallthrough]]; case State::Hold: if (hold-- > 0) return currentValue; - + step = std::exp(std::log(sustain) / (decay > 0 ? decay : 1)); currentState = State::Decay; [[fallthrough]]; case State::Decay: - if (decay-- > 0) - { + if (decay-- > 0) { currentValue *= step; return currentValue; } @@ -80,8 +75,7 @@ Type ADSREnvelope::getNextValue() noexcept case State::Sustain: return currentValue; case State::Release: - if (release-- > 0) - { + if (release-- > 0) { currentValue *= step; return currentValue; } @@ -94,14 +88,13 @@ Type ADSREnvelope::getNextValue() noexcept } } -template +template void ADSREnvelope::getBlock(absl::Span output) noexcept { auto originalSpan = output; auto remainingSamples = static_cast(output.size()); int length; - switch(currentState) - { + switch (currentState) { case State::Delay: length = min(remainingSamples, delay); ::fill(output, currentValue); @@ -110,7 +103,7 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept delay -= length; if (remainingSamples == 0) break; - + currentState = State::Attack; step = (peak - start) / (attack > 0 ? attack : 1); [[fallthrough]]; @@ -122,7 +115,7 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept attack -= length; if (remainingSamples == 0) break; - + currentValue = peak; currentState = State::Hold; [[fallthrough]]; @@ -134,7 +127,7 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept hold -= length; if (remainingSamples == 0) break; - + step = std::exp(std::log(sustain) / (decay > 0 ? decay : 1)); currentState = State::Decay; [[fallthrough]]; @@ -171,15 +164,13 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept } ::fill(output, currentValue); - if (shouldRelease) - { + if (shouldRelease) { remainingSamples = static_cast(originalSpan.size()); - if (releaseDelay > remainingSamples) - { + if (releaseDelay > remainingSamples) { releaseDelay -= remainingSamples; return; } - + originalSpan.remove_prefix(releaseDelay); if (originalSpan.size() > 0) currentValue = originalSpan.front(); @@ -191,22 +182,20 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept originalSpan.remove_prefix(length); release -= length; - if (release == 0) - { + if (release == 0) { currentValue = 0.0; currentState = State::Done; ::fill(originalSpan, 0.0); } - } } -template +template bool ADSREnvelope::isSmoothing() noexcept { return currentState != State::Done; } -template +template void ADSREnvelope::startRelease(int releaseDelay) noexcept { shouldRelease = true; diff --git a/sources/ADSREnvelope.h b/sources/ADSREnvelope.h index c9727292..ebc9d5aa 100644 --- a/sources/ADSREnvelope.h +++ b/sources/ADSREnvelope.h @@ -1,23 +1,27 @@ #pragma once -#include #include "Helpers.h" -namespace sfz -{ +#include +namespace sfz { -template -class ADSREnvelope -{ +template +class ADSREnvelope { public: ADSREnvelope() = default; - void reset(int attack, int release, Type sustain=1.0, int delay = 0, int decay = 0, int hold = 0, Type start=0.0, Type depth=1) noexcept; + void reset(int attack, int release, Type sustain = 1.0, int delay = 0, int decay = 0, int hold = 0, Type start = 0.0, Type depth = 1) noexcept; Type getNextValue() noexcept; void getBlock(absl::Span output) noexcept; void startRelease(int releaseDelay) noexcept; bool isSmoothing() noexcept; + private: - enum class State - { - Delay, Attack, Hold, Decay, Sustain, Release, Done + enum class State { + Delay, + Attack, + Hold, + Decay, + Sustain, + Release, + Done }; State currentState { State::Done }; Type currentValue { 0.0 }; diff --git a/sources/Buffer.h b/sources/Buffer.h index c3c9c60f..ef0f22fb 100644 --- a/sources/Buffer.h +++ b/sources/Buffer.h @@ -7,14 +7,13 @@ #include #include template -class Buffer -{ +class Buffer { public: using value_type = std::remove_cv_t; - using pointer = value_type *; - using const_pointer = const value_type *; - using reference = value_type &; - using const_reference = const value_type &; + using pointer = value_type*; + using const_pointer = const value_type*; + using reference = value_type&; + using const_reference = const value_type&; using iterator = pointer; using const_iterator = const_pointer; using reverse_iterator = std::reverse_iterator; @@ -22,7 +21,7 @@ public: using size_type = size_t; using difference_type = ptrdiff_t; - Buffer() + Buffer() { } Buffer(size_t size) @@ -31,16 +30,14 @@ public: } bool resize(size_t newSize) { - if (newSize == 0) - { + if (newSize == 0) { clear(); return true; } auto tempSize = newSize + 2 * AlignmentMask; // To ensure that we have leeway at the beginning and at the end - auto *newData = paddedData != nullptr ? std::realloc(paddedData, tempSize * sizeof(value_type)) : std::malloc(tempSize * sizeof(value_type)); - if (newData == nullptr) - { + auto* newData = paddedData != nullptr ? std::realloc(paddedData, tempSize * sizeof(value_type)) : std::malloc(tempSize * sizeof(value_type)); + if (newData == nullptr) { return false; } @@ -53,7 +50,7 @@ public: _alignedEnd = normalEnd + Alignment - endMisalignment; else _alignedEnd = normalEnd; - + return true; } @@ -71,15 +68,14 @@ public: std::free(paddedData); } - Buffer(const Buffer &other) + Buffer(const Buffer& other) { - if (resize(other.size())) - { + if (resize(other.size())) { std::memcpy(this->data(), other.data(), other.size() * sizeof(value_type)); } } - Buffer(Buffer &&other) + Buffer(Buffer&& other) { largerSize = std::exchange(other.largerSize, 0); alignedSize = std::exchange(other.alignedSize, 0); @@ -89,20 +85,18 @@ public: _alignedEnd = std::exchange(other._alignedEnd, nullptr); } - Buffer &operator=(const Buffer &other) + Buffer& operator=(const Buffer& other) { - if (this != &other) - { + if (this != &other) { if (resize(other.size())) std::memcpy(this->data(), other.data(), other.size() * sizeof(value_type)); } return *this; } - Buffer &operator=(Buffer &&other) + Buffer& operator=(Buffer&& other) { - if (this != &other) - { + if (this != &other) { std::free(paddedData); largerSize = std::exchange(other.largerSize, 0); alignedSize = std::exchange(other.alignedSize, 0); @@ -114,7 +108,7 @@ public: return *this; } - Type &operator[](int idx) { return *(normalData + idx); } + Type& operator[](int idx) { return *(normalData + idx); } constexpr pointer data() const noexcept { return normalData; } constexpr size_type size() const noexcept { return alignedSize; } constexpr bool empty() const noexcept { return alignedSize == 0; } @@ -123,17 +117,17 @@ public: constexpr pointer alignedEnd() noexcept { return _alignedEnd; } private: - static constexpr auto AlignmentMask{Alignment - 1}; - static constexpr auto TypeAlignment{Alignment / sizeof(value_type)}; - static constexpr auto TypeAlignmentMask{TypeAlignment - 1}; + static constexpr auto AlignmentMask { Alignment - 1 }; + static constexpr auto TypeAlignment { Alignment / sizeof(value_type) }; + static constexpr auto TypeAlignmentMask { TypeAlignment - 1 }; static_assert(std::is_arithmetic::value, "Type should be arithmetic"); static_assert(Alignment == 0 || Alignment == 4 || Alignment == 8 || Alignment == 16, "Bad alignment value"); static_assert(TypeAlignment * sizeof(value_type) == Alignment, "The alignment does not appear to be divided by the size of the Type"); - size_type largerSize{0}; - size_type alignedSize{0}; - pointer normalData{nullptr}; - pointer paddedData{nullptr}; - pointer normalEnd{nullptr}; - pointer _alignedEnd{nullptr}; + size_type largerSize { 0 }; + size_type alignedSize { 0 }; + pointer normalData { nullptr }; + pointer paddedData { nullptr }; + pointer normalEnd { nullptr }; + pointer _alignedEnd { nullptr }; LEAK_DETECTOR(Buffer); }; \ No newline at end of file diff --git a/sources/CCMap.h b/sources/CCMap.h index 69fba5d3..58ec3138 100644 --- a/sources/CCMap.h +++ b/sources/CCMap.h @@ -1,33 +1,31 @@ #pragma once -#include #include "Helpers.h" +#include -namespace sfz -{ -template -class CCMap -{ +namespace sfz { +template +class CCMap { public: CCMap() = delete; - CCMap(const ValueType& defaultValue) : defaultValue(defaultValue) { } + CCMap(const ValueType& defaultValue) + : defaultValue(defaultValue) + { + } CCMap(CCMap&&) = default; CCMap(const CCMap&) = default; ~CCMap() = default; - const ValueType &getWithDefault(int index) const noexcept + const ValueType& getWithDefault(int index) const noexcept { auto it = container.find(index); - if (it == end(container)) - { + if (it == end(container)) { return defaultValue; - } - else - { + } else { return it->second; } } - ValueType &operator[](const int &key) noexcept + ValueType& operator[](const int& key) noexcept { if (!contains(key)) container.emplace(key, defaultValue); @@ -35,7 +33,7 @@ public: } inline bool empty() const { return container.empty(); } - const ValueType &at(int index) const { return container.at(index); } + const ValueType& at(int index) const { return container.at(index); } bool contains(int index) const noexcept { return container.find(index) != end(container); } private: diff --git a/sources/FilePool.cpp b/sources/FilePool.cpp index 2b4f36aa..c66e7fc8 100644 --- a/sources/FilePool.cpp +++ b/sources/FilePool.cpp @@ -58,7 +58,7 @@ void sfz::FilePool::loadingThread() } SndfileHandle sndFile(reinterpret_cast(file.c_str())); - // auto deleteAndTrackBuffers = [this] + // auto deleteAndTrackBuffers = [this] std::unique_ptr, std::function*)>> fileLoaded(new StereoBuffer(fileToLoad.numFrames), deleteAndTrackBuffers); auto readBuffer = std::make_unique>(fileToLoad.numFrames * 2); sndFile.readf(readBuffer->data(), fileToLoad.numFrames); diff --git a/sources/FilePool.h b/sources/FilePool.h index ccae535b..93aa9e1d 100644 --- a/sources/FilePool.h +++ b/sources/FilePool.h @@ -1,25 +1,22 @@ #pragma once -#include "StereoBuffer.h" #include "Defaults.h" +#include "StereoBuffer.h" #include "Voice.h" -#include -#include -#include -#include -#include -#include #include "readerwriterqueue.h" +#include +#include +#include +#include +#include +#include #include -namespace sfz -{ -class FilePool -{ +namespace sfz { +class FilePool { public: FilePool() - : fileLoadingThread(std::thread(&FilePool::loadingThread, this)) + : fileLoadingThread(std::thread(&FilePool::loadingThread, this)) { - } ~FilePool() @@ -30,8 +27,7 @@ public: void setRootDirectory(const std::filesystem::path& directory) { rootDirectory = directory; } size_t getNumPreloadedSamples() { return preloadedData.size(); } - struct FileInformation - { + struct FileInformation { uint32_t end { Default::sampleEndRange.getEnd() }; uint32_t loopBegin { Default::loopRange.getStart() }; uint32_t loopEnd { Default::loopRange.getEnd() }; @@ -40,7 +36,8 @@ public: }; std::optional getFileInformation(std::string_view filename); void enqueueLoading(Voice* voice, std::string_view sample, int numFrames); - static void deleteAndTrackBuffers(StereoBuffer* buffer) { + static void deleteAndTrackBuffers(StereoBuffer* buffer) + { fileBuffers--; delete buffer; }; @@ -48,15 +45,15 @@ public: { return fileBuffers.load(); } + private: std::filesystem::path rootDirectory; - struct FileLoadingInformation - { + struct FileLoadingInformation { Voice* voice; std::string_view sample; int numFrames; }; - + inline static std::atomic fileBuffers { 0 }; moodycamel::BlockingReaderWriterQueue loadingQueue; @@ -64,7 +61,7 @@ private: std::thread fileLoadingThread; bool quitThread { false }; Buffer tempReadBuffer { config::preloadSize * 2 }; - + // std::map>> preloadedData; absl::flat_hash_map>> preloadedData; LEAK_DETECTOR(FilePool); diff --git a/sources/Globals.h b/sources/Globals.h index ea52b1b6..8d44c3d4 100644 --- a/sources/Globals.h +++ b/sources/Globals.h @@ -1,10 +1,8 @@ #pragma once -namespace sfz -{ +namespace sfz { -namespace config -{ +namespace config { constexpr float defaultSampleRate { 48000 }; constexpr int defaultSamplesPerBlock { 1024 }; constexpr int preloadSize { 8192 }; @@ -21,21 +19,20 @@ namespace config } // namespace sfz -namespace SIMDConfig -{ - constexpr unsigned int defaultAlignment { 16 }; - constexpr bool writeInterleaved { true }; - constexpr bool readInterleaved { true }; - constexpr bool fill { true }; - constexpr bool gain { false }; - constexpr bool mathfuns { false }; - constexpr bool loopingSFZIndex { true }; - constexpr bool linearRamp { false }; - constexpr bool multiplicativeRamp { true }; - constexpr bool add { false }; +namespace SIMDConfig { +constexpr unsigned int defaultAlignment { 16 }; +constexpr bool writeInterleaved { true }; +constexpr bool readInterleaved { true }; +constexpr bool fill { true }; +constexpr bool gain { false }; +constexpr bool mathfuns { false }; +constexpr bool loopingSFZIndex { true }; +constexpr bool linearRamp { false }; +constexpr bool multiplicativeRamp { true }; +constexpr bool add { false }; #if USE_SIMD - constexpr bool useSIMD { true }; +constexpr bool useSIMD { true }; #else - constexpr bool useSIMD { false }; +constexpr bool useSIMD { false }; #endif } \ No newline at end of file diff --git a/sources/Helpers.h b/sources/Helpers.h index 058c4a5f..121ac2ca 100644 --- a/sources/Helpers.h +++ b/sources/Helpers.h @@ -3,17 +3,14 @@ #include #include -inline void trimInPlace(std::string_view &s) +inline void trimInPlace(std::string_view& s) { const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v"); - if (leftPosition != s.npos) - { + if (leftPosition != s.npos) { s.remove_prefix(leftPosition); const auto rightPosition = s.find_last_not_of(" \r\t\n\f\v"); s.remove_suffix(s.size() - rightPosition - 1); - } - else - { + } else { s.remove_suffix(s.size()); } } @@ -21,14 +18,11 @@ inline void trimInPlace(std::string_view &s) inline std::string_view trim(std::string_view s) { const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v"); - if (leftPosition != s.npos) - { + if (leftPosition != s.npos) { s.remove_prefix(leftPosition); const auto rightPosition = s.find_last_not_of(" \r\t\n\f\v"); s.remove_suffix(s.size() - rightPosition - 1); - } - else - { + } else { s.remove_suffix(s.size()); } return s; @@ -36,7 +30,7 @@ inline std::string_view trim(std::string_view s) inline constexpr unsigned int Fnv1aBasis = 0x811C9DC5; inline constexpr unsigned int Fnv1aPrime = 0x01000193; -inline constexpr unsigned int hash(const char *s, unsigned int h = Fnv1aBasis) +inline constexpr unsigned int hash(const char* s, unsigned int h = Fnv1aBasis) { return !*s ? h : hash(s + 1, static_cast((h ^ *s) * static_cast(Fnv1aPrime))); } @@ -112,10 +106,9 @@ inline constexpr Type mag2db(Type in) return static_cast(20.0) * std::log10(in); } -namespace Random -{ +namespace Random { static inline std::random_device randomDevice; -static inline std::mt19937 randomGenerator{randomDevice()}; +static inline std::mt19937 randomGenerator { randomDevice() }; } // namespace Random inline float midiNoteFrequency(const int noteNumber) @@ -124,30 +117,28 @@ inline float midiNoteFrequency(const int noteNumber) } template -constexpr Type pi{3.141592653589793238462643383279502884}; +constexpr Type pi { 3.141592653589793238462643383279502884 }; template -constexpr Type twoPi{2 * pi}; +constexpr Type twoPi { 2 * pi }; template -constexpr Type piTwo{pi / 2}; +constexpr Type piTwo { pi / 2 }; #include template -class LeakDetector -{ +class LeakDetector { public: LeakDetector() { objectCounter.count++; } - LeakDetector(const LeakDetector &) + LeakDetector(const LeakDetector&) { objectCounter.count++; } ~LeakDetector() { objectCounter.count--; - if (objectCounter.count.load() < 0) - { + if (objectCounter.count.load() < 0) { DBG("Deleted a dangling pointer for class " << Owner::getClassName()); // Deleted a dangling pointer! ASSERTFALSE; @@ -155,19 +146,17 @@ public: } private: - struct ObjectCounter - { + struct ObjectCounter { ObjectCounter() = default; ~ObjectCounter() { - if (auto residualCount = count.load() > 0) - { + if (auto residualCount = count.load() > 0) { DBG("Leaked " << residualCount << " instance(s) of class " << Owner::getClassName()); // Leaked ojects ASSERTFALSE; } }; - std::atomic count{0}; + std::atomic count { 0 }; }; static inline ObjectCounter objectCounter; }; @@ -175,7 +164,7 @@ private: #ifndef NDEBUG #define LEAK_DETECTOR(Class) \ friend class LeakDetector; \ - static const char *getClassName() { return #Class; } \ + static const char* getClassName() { return #Class; } \ LeakDetector leakDetector; #else #define LEAK_DETECTOR(Class) diff --git a/sources/LinearEnvelope.cpp b/sources/LinearEnvelope.cpp index 9ca7c36a..0fbd1149 100644 --- a/sources/LinearEnvelope.cpp +++ b/sources/LinearEnvelope.cpp @@ -3,56 +3,55 @@ #include "SIMDHelpers.h" #include -namespace sfz -{ +namespace sfz { -template +template LinearEnvelope::LinearEnvelope() { setMaxCapacity(maxCapacity); } -template +template LinearEnvelope::LinearEnvelope(int maxCapacity, std::function function) { setMaxCapacity(maxCapacity); setFunction(function); } -template +template void LinearEnvelope::setMaxCapacity(int maxCapacity) { events.reserve(maxCapacity); this->maxCapacity = maxCapacity; } -template +template void LinearEnvelope::setFunction(std::function function) { this->function = function; } -template +template void LinearEnvelope::registerEvent(int timestamp, Type inputValue) { if (static_cast(events.size()) < maxCapacity) events.emplace_back(timestamp, function(inputValue)); } -template +template void LinearEnvelope::clear() { events.clear(); } -template +template void LinearEnvelope::reset(Type value) { clear(); currentValue = function(value); } -template +template void LinearEnvelope::getBlock(absl::Span output) { absl::c_sort(events, [](const auto& lhs, const auto& rhs) { @@ -60,15 +59,13 @@ void LinearEnvelope::getBlock(absl::Span output) }); int index { 0 }; - for (auto& event: events) - { + for (auto& event : events) { const auto length = min(event.first, static_cast(output.size())) - index; - if (length == 0) - { + if (length == 0) { currentValue = event.second; continue; } - + const auto step = (event.second - currentValue) / length; currentValue = ::linearRamp(output.subspan(index, length), currentValue, step); index += length; @@ -76,7 +73,7 @@ void LinearEnvelope::getBlock(absl::Span output) if (index < static_cast(output.size())) ::fill(output.subspan(index), currentValue); - + clear(); } diff --git a/sources/LinearEnvelope.h b/sources/LinearEnvelope.h index 675b9e79..222f2db5 100644 --- a/sources/LinearEnvelope.h +++ b/sources/LinearEnvelope.h @@ -1,16 +1,14 @@ #pragma once #include "Globals.h" #include "Helpers.h" -#include -#include #include +#include +#include -namespace sfz -{ +namespace sfz { -template -class LinearEnvelope -{ +template +class LinearEnvelope { public: LinearEnvelope(); LinearEnvelope(int maxCapacity, std::function function); @@ -18,8 +16,9 @@ public: void setFunction(std::function function); void registerEvent(int timestamp, Type inputValue); void clear(); - void reset(Type value=0.0); + void reset(Type value = 0.0); void getBlock(absl::Span output); + private: std::function function { [](Type input) { return input; } }; static_assert(std::is_arithmetic::value); diff --git a/sources/OnePoleFilter.h b/sources/OnePoleFilter.h index a35500e4..cffb58c1 100644 --- a/sources/OnePoleFilter.h +++ b/sources/OnePoleFilter.h @@ -1,20 +1,19 @@ #pragma once #include "Globals.h" -#include #include +#include -template -class OnePoleFilter -{ +template +class OnePoleFilter { public: OnePoleFilter() = default; // Normalized cutoff with respect to the sampling rate - template + template static Type normalizedGain(Type cutoff, C sampleRate) { - return std::tan( cutoff / static_cast(sampleRate) * M_PIf32 ); + return std::tan(cutoff / static_cast(sampleRate) * M_PIf32); } - + OnePoleFilter(Type gain) { setGain(gain); @@ -23,16 +22,15 @@ public: void setGain(Type gain) { this->gain = gain; - G = gain / ( 1 + gain); + G = gain / (1 + gain); } Type getGain() const { return gain; } int processLowpass(absl::Span input, absl::Span lowpass) { - for (auto [in, out] = std::pair(input.begin(), lowpass.begin()); - in < input.end() && out < lowpass.end(); in++, out++) - { + for (auto [in, out] = std::pair(input.begin(), lowpass.begin()); + in < input.end() && out < lowpass.end(); in++, out++) { oneLowpass(in, out); } return std::min(input.size(), lowpass.size()); @@ -40,9 +38,8 @@ public: int processHighpass(absl::Span input, absl::Span highpass) { - for (auto [in, out] = std::pair(input.begin(), highpass.begin()); - in < input.end() && out < highpass.end(); in++, out++) - { + for (auto [in, out] = std::pair(input.begin(), highpass.begin()); + in < input.end() && out < highpass.end(); in++, out++) { oneHighpass(in, out); } return std::min(input.size(), highpass.size()); @@ -50,35 +47,34 @@ public: int processLowpassVariableGain(absl::Span input, absl::Span lowpass, absl::Span gain) { - for (auto [in, out, g] = std::tuple(input.begin(), lowpass.begin(), gain.begin()); - in < input.end() && out < lowpass.end() && g < gain.end(); in++, out++, g++) - { + for (auto [in, out, g] = std::tuple(input.begin(), lowpass.begin(), gain.begin()); + in < input.end() && out < lowpass.end() && g < gain.end(); in++, out++, g++) { setGain(*g); oneLowpass(in, out); } - + return std::min({ input.size(), lowpass.size(), gain.size() }); } int processHighpassVariableGain(absl::Span input, absl::Span highpass, absl::Span gain) { - for (auto [in, out, g] = std::tuple(input.begin(), highpass.begin(), gain.begin()); - in < input.end() && out < highpass.end() && g < gain.end(); in++, out++, g++) - { + for (auto [in, out, g] = std::tuple(input.begin(), highpass.begin(), gain.begin()); + in < input.end() && out < highpass.end() && g < gain.end(); in++, out++, g++) { setGain(*g); oneHighpass(in, out); } - + return std::min({ input.size(), highpass.size(), gain.size() }); } void reset() { state = 0.0; } + private: Type state { 0.0 }; Type gain { 0.25 }; Type intermediate { 0.0 }; Type G { gain / (1 + gain) }; - + inline void oneLowpass(const Type* in, Type* out) { intermediate = G * (*in - state); @@ -90,6 +86,6 @@ private: { intermediate = G * (*in - state); *out = *in - intermediate - state; - state += 2*intermediate; + state += 2 * intermediate; } }; \ No newline at end of file diff --git a/sources/Opcode.cpp b/sources/Opcode.cpp index c9f51317..79f3e2ba 100644 --- a/sources/Opcode.cpp +++ b/sources/Opcode.cpp @@ -1,15 +1,14 @@ #include "Opcode.h" sfz::Opcode::Opcode(std::string_view inputOpcode, std::string_view inputValue) -:opcode(inputOpcode), value(inputValue) + : opcode(inputOpcode) + , value(inputValue) { - if (const auto lastCharIndex = inputOpcode.find_last_not_of("1234567890"); lastCharIndex != inputOpcode.npos) - { + if (const auto lastCharIndex = inputOpcode.find_last_not_of("1234567890"); lastCharIndex != inputOpcode.npos) { int returnedValue; std::string_view parameterView = inputOpcode; parameterView.remove_prefix(lastCharIndex + 1); - if (absl::SimpleAtoi(parameterView, &returnedValue)) - { + if (absl::SimpleAtoi(parameterView, &returnedValue)) { parameter = returnedValue; opcode.remove_suffix(opcode.size() - lastCharIndex - 1); } diff --git a/sources/Opcode.h b/sources/Opcode.h index e9070810..f533a836 100644 --- a/sources/Opcode.h +++ b/sources/Opcode.h @@ -1,32 +1,29 @@ #pragma once -#include "Helpers.h" -#include "SfzHelpers.h" #include "Defaults.h" +#include "Helpers.h" #include "Range.h" -#include +#include "SfzHelpers.h" #include +#include // charconv support is still sketchy with clang/gcc so we use abseil's numbers #include "absl/strings/numbers.h" -namespace sfz -{ -struct Opcode -{ +namespace sfz { +struct Opcode { Opcode() = delete; Opcode(std::string_view inputOpcode, std::string_view inputValue); - std::string_view opcode{}; - std::string_view value{}; + std::string_view opcode {}; + std::string_view value {}; // This is to handle the integer parameter of some opcodes std::optional parameter; LEAK_DETECTOR(Opcode); }; -template +template inline std::optional readOpcode(std::string_view value, const Range& validRange) { - if constexpr(std::is_integral::value) - { + if constexpr (std::is_integral::value) { int64_t returnedValue; if (!absl::SimpleAtoi(value, &returnedValue)) return {}; @@ -37,9 +34,7 @@ inline std::optional readOpcode(std::string_view value, const Range::min(); return validRange.clamp(static_cast(returnedValue)); - } - else - { + } else { float returnedValue; if (!absl::SimpleAtof(value, &returnedValue)) return std::nullopt; @@ -48,7 +43,7 @@ inline std::optional readOpcode(std::string_view value, const Range +template inline void setValueFromOpcode(const Opcode& opcode, ValueType& target, const Range& validRange) { auto value = readOpcode(opcode.value, validRange); @@ -58,7 +53,7 @@ inline void setValueFromOpcode(const Opcode& opcode, ValueType& target, const Ra target = *value; } -template +template inline void setValueFromOpcode(const Opcode& opcode, std::optional& target, const Range& validRange) { auto value = readOpcode(opcode.value, validRange); @@ -68,7 +63,7 @@ inline void setValueFromOpcode(const Opcode& opcode, std::optional& t target = *value; } -template +template inline void setRangeEndFromOpcode(const Opcode& opcode, Range& target, const Range& validRange) { auto value = readOpcode(opcode.value, validRange); @@ -78,7 +73,7 @@ inline void setRangeEndFromOpcode(const Opcode& opcode, Range& target target.setEnd(*value); } -template +template inline void setRangeStartFromOpcode(const Opcode& opcode, Range& target, const Range& validRange) { auto value = readOpcode(opcode.value, validRange); @@ -88,11 +83,11 @@ inline void setRangeStartFromOpcode(const Opcode& opcode, Range& targ target.setStart(*value); } -template +template inline void setCCPairFromOpcode(const Opcode& opcode, std::optional& target, const Range& validRange) { auto value = readOpcode(opcode.value, validRange); - if (value && opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter)) + if (value && opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter)) target = std::make_pair(*opcode.parameter, *value); else target = {}; diff --git a/sources/Parser.cpp b/sources/Parser.cpp index 01be13cf..dd6ff151 100644 --- a/sources/Parser.cpp +++ b/sources/Parser.cpp @@ -1,143 +1,130 @@ #include "Parser.h" -#include "Helpers.h" #include "Globals.h" +#include "Helpers.h" #include "absl/strings/str_join.h" -#include #include +#include using svregex_iterator = std::regex_iterator; using svmatch_results = std::match_results; -void removeCommentOnLine(std::string_view &line) +void removeCommentOnLine(std::string_view& line) { - if (auto position = line.find("//"); position != line.npos) - line.remove_suffix(line.size() - position); + if (auto position = line.find("//"); position != line.npos) + line.remove_suffix(line.size() - position); } -bool sfz::Parser::loadSfzFile(const std::filesystem::path &file) +bool sfz::Parser::loadSfzFile(const std::filesystem::path& file) { - const auto sfzFile = file.is_absolute() ? file : rootDirectory / file; - if (!std::filesystem::exists(sfzFile)) - return false; + const auto sfzFile = file.is_absolute() ? file : rootDirectory / file; + if (!std::filesystem::exists(sfzFile)) + return false; - rootDirectory = file.parent_path(); - std::vector lines; - readSfzFile(file, lines); + rootDirectory = file.parent_path(); + std::vector lines; + readSfzFile(file, lines); - aggregatedContent = absl::StrJoin(lines, " "); - const std::string_view aggregatedView{aggregatedContent}; + aggregatedContent = absl::StrJoin(lines, " "); + const std::string_view aggregatedView { aggregatedContent }; - svregex_iterator headerIterator(aggregatedView.cbegin(), aggregatedView.cend(), sfz::Regexes::headers); - const auto regexEnd = svregex_iterator(); + svregex_iterator headerIterator(aggregatedView.cbegin(), aggregatedView.cend(), sfz::Regexes::headers); + const auto regexEnd = svregex_iterator(); - std::vector currentMembers; + std::vector currentMembers; - for (; headerIterator != regexEnd; ++headerIterator) - { - svmatch_results headerMatch = *headerIterator; + for (; headerIterator != regexEnd; ++headerIterator) { + 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()); - auto paramIterator = svregex_iterator(members.cbegin(), members.cend(), sfz::Regexes::members); + // 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()); + 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()); - currentMembers.emplace_back(opcode, value); - } - callback(header, currentMembers); - currentMembers.clear(); - } + // 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()); + currentMembers.emplace_back(opcode, value); + } + callback(header, currentMembers); + currentMembers.clear(); + } - return true; + return true; } -void sfz::Parser::readSfzFile(const std::filesystem::path &fileName, std::vector &lines) noexcept +void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector& lines) noexcept { - std::ifstream fileStream(fileName.c_str()); - if (!fileStream) - return; + std::ifstream fileStream(fileName.c_str()); + if (!fileStream) + return; - // spdlog::info("Including file {}", fileName.string()); - svmatch_results includeMatch; - svmatch_results defineMatch; + // spdlog::info("Including file {}", fileName.string()); + svmatch_results includeMatch; + svmatch_results defineMatch; - std::string tmpString; - while (std::getline(fileStream, tmpString)) - { - std::string_view tmpView{tmpString}; + std::string tmpString; + while (std::getline(fileStream, tmpString)) { + std::string_view tmpView { tmpString }; - removeCommentOnLine(tmpView); - trimInPlace(tmpView); + removeCommentOnLine(tmpView); + trimInPlace(tmpView); - if (tmpView.empty()) - continue; + if (tmpView.empty()) + continue; - // New #include - if (std::regex_search(tmpView.begin(), tmpView.end(), includeMatch, sfz::Regexes::includes)) - { - auto includePath = includeMatch.str(1); - std::replace(includePath.begin(), includePath.end(), '\\', '/'); - const auto newFile = rootDirectory / includePath; - auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile); - if (std::filesystem::exists(newFile)) - { - if (alreadyIncluded == includedFiles.end()) - { - includedFiles.push_back(newFile); - readSfzFile(newFile, lines); - } - else if (!recursiveIncludeGuard) - { - readSfzFile(newFile, lines); - } - } - continue; - } + // New #include + if (std::regex_search(tmpView.begin(), tmpView.end(), includeMatch, sfz::Regexes::includes)) { + auto includePath = includeMatch.str(1); + std::replace(includePath.begin(), includePath.end(), '\\', '/'); + const auto newFile = rootDirectory / includePath; + auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile); + if (std::filesystem::exists(newFile)) { + if (alreadyIncluded == includedFiles.end()) { + includedFiles.push_back(newFile); + readSfzFile(newFile, lines); + } else if (!recursiveIncludeGuard) { + readSfzFile(newFile, lines); + } + } + continue; + } - // New #define - if (std::regex_search(tmpView.begin(), tmpView.end(), defineMatch, sfz::Regexes::defines)) - { - defines[defineMatch.str(1)] = defineMatch.str(2); - continue; - } + // New #define + if (std::regex_search(tmpView.begin(), tmpView.end(), defineMatch, sfz::Regexes::defines)) { + defines[defineMatch.str(1)] = defineMatch.str(2); + continue; + } - // Replace defined variables starting with $ - std::string newString; - newString.reserve(tmpView.length()); - std::string::size_type lastPos = 0; - std::string::size_type findPos = tmpView.find(sfz::config::defineCharacter, lastPos); + // Replace defined variables starting with $ + std::string newString; + newString.reserve(tmpView.length()); + std::string::size_type lastPos = 0; + std::string::size_type findPos = tmpView.find(sfz::config::defineCharacter, lastPos); - while (findPos < tmpView.npos) - { - newString.append(tmpView, lastPos, findPos - lastPos); + while (findPos < tmpView.npos) { + newString.append(tmpView, lastPos, findPos - lastPos); - for (auto &definePair : defines) - { - std::string_view candidate = tmpView.substr(findPos, definePair.first.length()); - if (candidate == definePair.first) - { - newString += definePair.second; - lastPos = findPos + definePair.first.length(); - break; - } - } + for (auto& definePair : defines) { + std::string_view candidate = tmpView.substr(findPos, definePair.first.length()); + if (candidate == definePair.first) { + newString += definePair.second; + lastPos = findPos + definePair.first.length(); + break; + } + } - if (lastPos <= findPos) - { - newString += sfz::config::defineCharacter; - lastPos = findPos + 1; - } + if (lastPos <= findPos) { + newString += sfz::config::defineCharacter; + lastPos = findPos + 1; + } - findPos = tmpView.find(sfz::config::defineCharacter, lastPos); - } + findPos = tmpView.find(sfz::config::defineCharacter, lastPos); + } - // Copy the rest of the string - newString += tmpView.substr(lastPos); - lines.push_back(std::move(newString)); - } + // Copy the rest of the string + newString += tmpView.substr(lastPos); + lines.push_back(std::move(newString)); + } } \ No newline at end of file diff --git a/sources/Parser.h b/sources/Parser.h index 9462d2f1..8de4b64f 100644 --- a/sources/Parser.h +++ b/sources/Parser.h @@ -1,39 +1,38 @@ #pragma once #include "Opcode.h" #include -#include #include +#include #include -#include #include +#include -namespace sfz -{ -namespace Regexes -{ +namespace sfz { +namespace Regexes { inline static std::regex includes { R"V(#include\s*"(.*?)".*$)V", std::regex::optimize }; inline static std::regex defines { R"(#define\s*(\$[a-zA-Z0-9]+)\s+([a-zA-Z0-9]+)(?=\s|$))", std::regex::optimize }; inline static std::regex headers { R"(<(.*?)>(.*?)(?=<|$))", std::regex::optimize }; inline static std::regex members { R"(([a-zA-Z0-9_]+)=([a-zA-Z0-9-_#.\/\s\\\(\),\*]+)(?![a-zA-Z0-9_]*=))", std::regex::optimize }; - inline static std::regex opcodeParameters{ R"(([a-zA-Z0-9_]+?)([0-9]+)$)", std::regex::optimize }; + inline static std::regex opcodeParameters { R"(([a-zA-Z0-9_]+?)([0-9]+)$)", std::regex::optimize }; } -class Parser -{ +class Parser { public: virtual bool loadSfzFile(const std::filesystem::path& file); const std::map& getDefines() const noexcept { return defines; } const std::vector& getIncludedFiles() const noexcept { return includedFiles; } void disableRecursiveIncludeGuard() { recursiveIncludeGuard = false; } void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; } + protected: virtual void callback(std::string_view header, const std::vector& members) = 0; std::filesystem::path rootDirectory { std::filesystem::current_path() }; + private: bool recursiveIncludeGuard { false }; std::map defines; std::vector includedFiles; - std::string aggregatedContent { }; + std::string aggregatedContent {}; void readSfzFile(const std::filesystem::path& fileName, std::vector& lines) noexcept; }; diff --git a/sources/Range.h b/sources/Range.h index 297cb318..5f369d6d 100644 --- a/sources/Range.h +++ b/sources/Range.h @@ -1,12 +1,12 @@ #pragma once -#include -#include #include +#include +#include -template -class Range -{ +template +class Range { static_assert(std::is_arithmetic::value, "The Type should be arithmetic"); + public: constexpr Range() = default; // constexpr Range(std::initializer_list list) @@ -25,11 +25,14 @@ public: // } // } constexpr Range(Type start, Type end) noexcept - : _start(start), _end(std::max(start, end)) {} + : _start(start) + , _end(std::max(start, end)) + { + } ~Range() = default; Type getStart() const noexcept { return _start; } Type getEnd() const noexcept { return _end; } - std::pair getPair() const noexcept { return std::make_pair(_start, _end); } + std::pair getPair() const noexcept { return std::make_pair(_start, _end); } Range(const Range& range) = default; Range(Range&& range) = default; void setStart(Type start) noexcept @@ -48,35 +51,36 @@ public: Type clamp(Type value) const noexcept { return std::clamp(value, _start, _end); } bool containsWithEnd(Type value) const noexcept { return (value >= _start && value <= _end); } bool contains(Type value) const noexcept { return (value >= _start && value < _end); } - void shrinkIfSmaller( Type start, Type end) + void shrinkIfSmaller(Type start, Type end) { if (start > end) std::swap(start, end); - + if (start > _start) _start = start; if (end < _end) _end = end; } + private: Type _start { static_cast(0.0) }; Type _end { static_cast(0.0) }; }; -template +template bool operator==(const Range& lhs, const Range& rhs) { return (lhs.getStart() == rhs.getStart()) && (lhs.getEnd() == rhs.getEnd()); } -template +template bool operator==(const Range& lhs, const std::pair& rhs) { return (lhs.getStart() == rhs.first) && (lhs.getEnd() == rhs.second); } -template +template bool operator==(const std::pair& lhs, const Range& rhs) { return rhs == lhs; diff --git a/sources/Region.cpp b/sources/Region.cpp index 467c2739..09ae77a0 100644 --- a/sources/Region.cpp +++ b/sources/Region.cpp @@ -4,13 +4,12 @@ #include #include -bool sfz::Region::parseOpcode(const Opcode &opcode) +bool sfz::Region::parseOpcode(const Opcode& opcode) { - switch (hash(opcode.opcode)) - { + switch (hash(opcode.opcode)) { // Sound source: sample playback case hash("sample"): - sample = absl::StrReplaceAll(trim(opcode.value), {{"\\", "/"}}); + sample = absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } }); break; case hash("delay"): setValueFromOpcode(opcode, delay, Default::delayRange); @@ -34,8 +33,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode) break; case hash("loopmode"): case hash("loop_mode"): - switch (hash(opcode.value)) - { + switch (hash(opcode.value)) { case hash("no_loop"): loopMode = SfzLoopMode::no_loop; break; @@ -70,8 +68,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode) setValueFromOpcode(opcode, offBy, Default::groupRange); break; case hash("off_mode"): - switch (hash(opcode.value)) - { + switch (hash(opcode.value)) { case hash("fast"): offMode = SfzOffMode::fast; break; @@ -115,8 +112,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode) setRangeEndFromOpcode(opcode, bendRange, Default::bendRange); break; case hash("locc"): - if (opcode.parameter) - { + if (opcode.parameter) { setRangeStartFromOpcode(opcode, ccConditions[*opcode.parameter], Default::ccRange); } break; @@ -146,8 +142,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode) previousKeySwitched = false; break; case hash("sw_vel"): - switch (hash(opcode.value)) - { + switch (hash(opcode.value)) { case hash("current"): velocityOverride = SfzVelocityOverride::current; break; @@ -186,8 +181,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode) break; // Region logic: triggers case hash("trigger"): - switch (hash(opcode.value)) - { + switch (hash(opcode.value)) { case hash("attack"): trigger = SfzTrigger::attack; break; @@ -263,8 +257,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode) gainDistribution.param(std::uniform_real_distribution::param_type(-ampRandom, ampRandom)); break; case hash("amp_velcurve_"): - if (opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter)) - { + if (opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter)) { if (auto value = readOpcode(opcode.value, Default::ampVelcurveRange); value) velocityPoints.emplace_back(*opcode.parameter, *value); } @@ -294,8 +287,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode) setRangeEndFromOpcode(opcode, crossfadeVelOutRange, Default::velocityRange); break; case hash("xf_keycurve"): - switch (hash(opcode.value)) - { + switch (hash(opcode.value)) { case hash("power"): crossfadeKeyCurve = SfzCrossfadeCurve::power; break; @@ -307,8 +299,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode) } break; case hash("xf_velcurve"): - switch (hash(opcode.value)) - { + switch (hash(opcode.value)) { case hash("power"): crossfadeVelCurve = SfzCrossfadeCurve::power; break; @@ -423,10 +414,8 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity, if (!chanOk) return false; - if (keyswitchRange.containsWithEnd(noteNumber)) - { - if (keyswitch) - { + if (keyswitchRange.containsWithEnd(noteNumber)) { + if (keyswitch) { if (*keyswitch == noteNumber) keySwitched = true; else @@ -441,8 +430,7 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity, } const bool keyOk = keyRange.containsWithEnd(noteNumber); - if (keyOk) - { + if (keyOk) { // Update the number of notes playing for the region activeNotesInRange++; @@ -457,8 +445,7 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity, if (trigger == SfzTrigger::release_key || velocityOverride == SfzVelocityOverride::previous) lastNoteVelocities[noteNumber] = velocity; - if (previousNote) - { + if (previousNote) { if (*previousNote == noteNumber) previousKeySwitched = true; else @@ -481,14 +468,13 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity, return keyOk && velOk && chanOk && randOk && (attackTrigger || firstLegatoNote || notFirstLegatoNote); } -bool sfz::Region::registerNoteOff(int channel, int noteNumber, uint8_t velocity[[maybe_unused]], float randValue) +bool sfz::Region::registerNoteOff(int channel, int noteNumber, uint8_t velocity [[maybe_unused]], float randValue) { const bool chanOk = channelRange.containsWithEnd(channel); if (!chanOk) return false; - if (keyswitchRange.containsWithEnd(noteNumber)) - { + if (keyswitchRange.containsWithEnd(noteNumber)) { if (keyswitchDown && *keyswitchDown == noteNumber) keySwitched = false; diff --git a/sources/Region.h b/sources/Region.h index a4aaaf78..5654e198 100644 --- a/sources/Region.h +++ b/sources/Region.h @@ -1,21 +1,19 @@ #pragma once -#include "Helpers.h" -#include -#include -#include -#include -#include "Opcode.h" -#include "EGDescription.h" -#include "StereoBuffer.h" -#include "Defaults.h" #include "CCMap.h" +#include "Defaults.h" +#include "EGDescription.h" +#include "Helpers.h" +#include "Opcode.h" +#include "StereoBuffer.h" +#include #include +#include #include +#include +#include -namespace sfz -{ -struct Region -{ +namespace sfz { +struct Region { Region() { ccSwitched.set(); @@ -72,14 +70,14 @@ struct Region SfzOffMode offMode { Default::offMode }; // off_mode // Region logic: key mapping - Range keyRange{ Default::keyRange }; //lokey, hikey and key - Range velocityRange{ Default::velocityRange }; // hivel and lovel + Range keyRange { Default::keyRange }; //lokey, hikey and key + Range velocityRange { Default::velocityRange }; // hivel and lovel // Region logic: MIDI conditions - Range channelRange{ Default::channelRange }; //lochan and hichan - Range bendRange{ Default::bendRange }; // hibend and lobend + Range channelRange { Default::channelRange }; //lochan and hichan + Range bendRange { Default::bendRange }; // hibend and lobend CCMap> ccConditions { Default::ccRange }; - Range keyswitchRange{ Default::keyRange }; // sw_hikey and sw_lokey + Range keyswitchRange { Default::keyRange }; // sw_hikey and sw_lokey std::optional keyswitch {}; // sw_last std::optional keyswitchUp {}; // sw_up std::optional keyswitchDown {}; // sw_down @@ -87,9 +85,9 @@ struct Region SfzVelocityOverride velocityOverride { Default::velocityOverride }; // sw_vel // Region logic: internal conditions - Range aftertouchRange{ Default::aftertouchRange }; // hichanaft and lochanaft - Range bpmRange{ Default::bpmRange }; // hibpm and lobpm - Range randRange{ Default::randRange }; // hirand and lorand + Range aftertouchRange { Default::aftertouchRange }; // hichanaft and lochanaft + Range bpmRange { Default::bpmRange }; // hibpm and lobpm + Range randRange { Default::randRange }; // hirand and lorand uint8_t sequenceLength { Default::sequenceLength }; // seq_length uint8_t sequencePosition { Default::sequencePosition }; // seq_position @@ -122,10 +120,10 @@ struct Region SfzCrossfadeCurve crossfadeVelCurve { Default::crossfadeVelCurve }; // Performance parameters: pitch - uint8_t pitchKeycenter{Default::pitchKeycenter}; // pitch_keycenter - int pitchKeytrack{ Default::pitchKeytrack }; // pitch_keytrack - int pitchRandom{ Default::pitchRandom }; // pitch_random - int pitchVeltrack{ Default::pitchVeltrack }; // pitch_veltrack + uint8_t pitchKeycenter { Default::pitchKeycenter }; // pitch_keycenter + int pitchKeytrack { Default::pitchKeytrack }; // pitch_keytrack + int pitchRandom { Default::pitchRandom }; // pitch_random + int pitchVeltrack { Default::pitchVeltrack }; // pitch_veltrack int transpose { Default::transpose }; // transpose int tune { Default::tune }; // tune @@ -137,6 +135,7 @@ struct Region double sampleRate { config::defaultSampleRate }; int numChannels { 1 }; std::shared_ptr> preloadedData { nullptr }; + private: bool keySwitched { true }; bool previousKeySwitched { true }; diff --git a/sources/SIMDDummy.cpp b/sources/SIMDDummy.cpp index e8236686..815f9137 100644 --- a/sources/SIMDDummy.cpp +++ b/sources/SIMDDummy.cpp @@ -1,79 +1,79 @@ -#include "SIMDHelpers.h" #include "Helpers.h" +#include "SIMDHelpers.h" -template<> +template <> void readInterleaved(absl::Span input, absl::Span outputLeft, absl::Span outputRight) noexcept { readInterleaved(input, outputLeft, outputRight); } -template<> +template <> void writeInterleaved(absl::Span inputLeft, absl::Span inputRight, absl::Span output) noexcept { writeInterleaved(inputLeft, inputRight, output); } -template<> +template <> void fill(absl::Span output, float value) noexcept { fill(output, value); } -template<> +template <> void exp(absl::Span input, absl::Span output) noexcept { exp(input, output); } -template<> +template <> void log(absl::Span input, absl::Span output) noexcept { log(input, output); } -template<> +template <> void sin(absl::Span input, absl::Span output) noexcept { sin(input, output); } -template<> +template <> void cos(absl::Span input, absl::Span output) noexcept { cos(input, output); } -template<> +template <> void applyGain(float gain, absl::Span input, absl::Span output) noexcept { applyGain(gain, input, output); } -template<> +template <> void applyGain(absl::Span gain, absl::Span input, absl::Span output) noexcept { applyGain(gain, input, output); } -template<> +template <> void loopingSFZIndex(absl::Span jumps, absl::Span leftCoeff, absl::Span rightCoeff, absl::Span indices, float floatIndex, float loopEnd, float loopStart) noexcept { loopingSFZIndex(jumps, leftCoeff, rightCoeff, indices, floatIndex, loopEnd, loopStart); } -template<> +template <> float linearRamp(absl::Span output, float start, float step) noexcept { return linearRamp(output, start, step); } -template<> +template <> float multiplicativeRamp(absl::Span output, float start, float step) noexcept { return multiplicativeRamp(output, start, step); } -template<> +template <> void add(absl::Span input, absl::Span output) noexcept { add(input, output); diff --git a/sources/SIMDHelpers.h b/sources/SIMDHelpers.h index cecd5d13..be685c8b 100644 --- a/sources/SIMDHelpers.h +++ b/sources/SIMDHelpers.h @@ -1,18 +1,18 @@ #pragma once #include "Globals.h" -#include -#include #include "Helpers.h" +#include +#include #include -template +template inline void snippetRead(const T*& input, T*& outputLeft, T*& outputRight) { *outputLeft++ = *input++; *outputRight++ = *input++; } -template +template void readInterleaved(absl::Span input, absl::Span outputLeft, absl::Span outputRight) noexcept { // The size of the output is not big enough for the input... @@ -26,14 +26,14 @@ void readInterleaved(absl::Span input, absl::Span outputLeft, absl:: snippetRead(in, lOut, rOut); } -template +template inline void snippetWrite(T*& output, const T*& inputLeft, const T*& inputRight) { *output++ = *inputLeft++; *output++ = *inputRight++; } -template +template void writeInterleaved(absl::Span inputLeft, absl::Span inputRight, absl::Span output) noexcept { ASSERT(inputLeft.size() <= output.size() / 2); @@ -47,21 +47,21 @@ void writeInterleaved(absl::Span inputLeft, absl::Span inputRi } // Specializations -template<> +template <> void writeInterleaved(absl::Span inputLeft, absl::Span inputRight, absl::Span output) noexcept; -template<> +template <> void readInterleaved(absl::Span input, absl::Span outputLeft, absl::Span outputRight) noexcept; -template +template void fill(absl::Span output, T value) noexcept { absl::c_fill(output, value); } -template<> +template <> void fill(absl::Span output, float value) noexcept; -template +template void exp(absl::Span input, absl::Span output) noexcept { ASSERT(output.size() >= input.size()); @@ -70,10 +70,10 @@ void exp(absl::Span input, absl::Span output) noexcept output[i] = std::exp(input[i]); } -template<> +template <> void exp(absl::Span input, absl::Span output) noexcept; -template +template void log(absl::Span input, absl::Span output) noexcept { ASSERT(output.size() >= input.size()); @@ -82,10 +82,10 @@ void log(absl::Span input, absl::Span output) noexcept output[i] = std::log(input[i]); } -template<> +template <> void log(absl::Span input, absl::Span output) noexcept; -template +template void sin(absl::Span input, absl::Span output) noexcept { ASSERT(output.size() >= input.size()); @@ -94,10 +94,10 @@ void sin(absl::Span input, absl::Span output) noexcept output[i] = std::sin(input[i]); } -template<> +template <> void sin(absl::Span input, absl::Span output) noexcept; -template +template void cos(absl::Span input, absl::Span output) noexcept { ASSERT(output.size() >= input.size()); @@ -106,10 +106,10 @@ void cos(absl::Span input, absl::Span output) noexcept output[i] = std::cos(input[i]); } -template<> +template <> void cos(absl::Span input, absl::Span output) noexcept; -template +template inline void snippetLoopingIndex(const T*& jump, T*& leftCoeff, T*& rightCoeff, int*& index, T& floatIndex, T loopEnd, T loopStart) { floatIndex += *jump; @@ -124,7 +124,7 @@ inline void snippetLoopingIndex(const T*& jump, T*& leftCoeff, T*& rightCoeff, i jump++; } -template +template void loopingSFZIndex(absl::Span jumps, absl::Span leftCoeffs, absl::Span rightCoeffs, absl::Span indices, T floatIndex, T loopEnd, T loopStart) noexcept { ASSERT(indices.size() >= jumps.size()); @@ -137,21 +137,21 @@ void loopingSFZIndex(absl::Span jumps, absl::Span leftCoeffs, absl:: auto* jump = jumps.begin(); const auto size = min(jumps.size(), indices.size(), leftCoeffs.size(), rightCoeffs.size()); auto* sentinel = jumps.begin() + size; - + while (jump < sentinel) snippetLoopingIndex(jump, leftCoeff, rightCoeff, index, floatIndex, loopEnd, loopStart); } -template<> +template <> void loopingSFZIndex(absl::Span jumps, absl::Span leftCoeff, absl::Span rightCoeff, absl::Span indices, float floatIndex, float loopEnd, float loopStart) noexcept; -template +template inline void snippetGain(T gain, const T*& input, T*& output) { *output++ = gain * (*input++); } -template +template void applyGain(T gain, absl::Span input, absl::Span output) noexcept { ASSERT(input.size() <= output.size()); @@ -162,13 +162,13 @@ void applyGain(T gain, absl::Span input, absl::Span output) noexcept snippetGain(gain, in, out); } -template +template inline void snippetGainSpan(const T*& gain, const T*& input, T*& output) { *output++ = (*gain++) * (*input++); } -template +template void applyGain(absl::Span gain, absl::Span input, absl::Span output) noexcept { ASSERT(gain.size() == input.size()); @@ -181,69 +181,69 @@ void applyGain(absl::Span gain, absl::Span input, absl::Span(g, in, out); } -template +template void applyGain(T gain, absl::Span output) noexcept { applyGain(gain, output, output); } -template +template void applyGain(absl::Span gain, absl::Span output) noexcept { applyGain(gain, output, output); } -template<> +template <> void applyGain(float gain, absl::Span input, absl::Span output) noexcept; -template<> +template <> void applyGain(absl::Span gain, absl::Span input, absl::Span output) noexcept; -template +template inline void snippetRampLinear(T*& output, T& value, T step) { value += step; *output++ = value; } -template +template T linearRamp(absl::Span output, T start, T step) noexcept { auto* out = output.begin(); - while(out < output.end()) + while (out < output.end()) snippetRampLinear(out, start, step); return start; } -template +template inline void snippetRampMultiplicative(T*& output, T& value, T step) { value *= step; *output++ = value; } -template +template T multiplicativeRamp(absl::Span output, T start, T step) noexcept { auto* out = output.begin(); - while(out < output.end()) + while (out < output.end()) snippetRampMultiplicative(out, start, step); return start; } -template<> +template <> float linearRamp(absl::Span output, float start, float step) noexcept; -template<> +template <> float multiplicativeRamp(absl::Span output, float start, float step) noexcept; -template +template inline void snippetAdd(const T*& input, T*& output) { *output++ += *input++; } -template +template void add(absl::Span input, absl::Span output) noexcept { ASSERT(output.size() >= input.size()); @@ -254,5 +254,5 @@ void add(absl::Span input, absl::Span output) noexcept snippetAdd(in, out); } -template<> +template <> void add(absl::Span input, absl::Span output) noexcept; \ No newline at end of file diff --git a/sources/SIMDSSE.cpp b/sources/SIMDSSE.cpp index 93ae8fc8..d48c56ac 100644 --- a/sources/SIMDSSE.cpp +++ b/sources/SIMDSSE.cpp @@ -283,13 +283,13 @@ void applyGain(absl::Span gain, absl::Span -void loopingSFZIndex( absl::Span jumps, - absl::Span leftCoeffs, - absl::Span rightCoeffs, - absl::Span indices, - float floatIndex, - float loopEnd, - float loopStart) noexcept +void loopingSFZIndex(absl::Span jumps, + absl::Span leftCoeffs, + absl::Span rightCoeffs, + absl::Span indices, + float floatIndex, + float loopEnd, + float loopStart) noexcept { ASSERT(indices.size() >= jumps.size()); ASSERT(indices.size() == leftCoeffs.size()); diff --git a/sources/Synth.cpp b/sources/Synth.cpp index 5f7b48a9..31356133 100644 --- a/sources/Synth.cpp +++ b/sources/Synth.cpp @@ -1,13 +1,12 @@ #include "Synth.h" #include "Helpers.h" +#include #include #include -#include void sfz::Synth::callback(std::string_view header, const std::vector& members) { - switch (hash(header)) - { + switch (hash(header)) { case hash("global"): // We shouldn't have multiple global headers in file ASSERT(!hasGlobal); @@ -23,7 +22,7 @@ void sfz::Synth::callback(std::string_view header, const std::vector& me masterOpcodes = members; numMasters++; break; - case hash("group"): + case hash("group"): groupOpcodes = members; numGroups++; break; @@ -35,7 +34,7 @@ void sfz::Synth::callback(std::string_view header, const std::vector& me numCurves++; break; case hash("effect"): - // TODO: implement curves + // TODO: implement effects break; default: std::cerr << "Unknown header: " << header << '\n'; @@ -45,9 +44,9 @@ void sfz::Synth::callback(std::string_view header, const std::vector& me void sfz::Synth::buildRegion(const std::vector& regionOpcodes) { auto lastRegion = std::make_unique(); - + auto parseOpcodes = [&](const auto& opcodes) { - for (auto& opcode: opcodes) + for (auto& opcode : opcodes) if (!lastRegion->parseOpcode(opcode)) unknownOpcodes.insert(opcode.opcode); }; @@ -68,7 +67,7 @@ void sfz::Synth::clear() numMasters = 0; numCurves = 0; defaultSwitch = std::nullopt; - for (auto& state: ccState) + for (auto& state : ccState) state = 0; ccNames.clear(); globalOpcodes.clear(); @@ -79,8 +78,7 @@ void sfz::Synth::clear() void sfz::Synth::handleGlobalOpcodes(const std::vector& members) { - for (auto& member: members) - { + for (auto& member : members) { if (member.opcode == "sw_default") setValueFromOpcode(member, defaultSwitch, Default::keyRange); } @@ -88,10 +86,8 @@ void sfz::Synth::handleGlobalOpcodes(const std::vector& members) void sfz::Synth::handleControlOpcodes(const std::vector& members) { - for (auto& member: members) - { - switch (hash(member.opcode)) - { + for (auto& member : members) { + switch (hash(member.opcode)) { case hash("set_cc"): if (member.parameter && Default::ccRange.containsWithEnd(*member.parameter)) setValueFromOpcode(member, ccState[*member.parameter], Default::ccRange); @@ -117,7 +113,7 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename) auto parserReturned = sfz::Parser::loadSfzFile(filename); if (!parserReturned) return false; - + if (regions.empty()) return false; @@ -125,19 +121,16 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename) auto lastRegion = regions.end() - 1; auto currentRegion = regions.begin(); - while (currentRegion <= lastRegion) - { + while (currentRegion <= lastRegion) { auto region = currentRegion->get(); - - if (region->isGenerator()) - { + + if (region->isGenerator()) { currentRegion++; continue; } auto fileInformation = filePool.getFileInformation(region->sample); - if (!fileInformation) - { + if (!fileInformation) { DBG("Removing the region with sample " << region->sample); std::iter_swap(currentRegion, lastRegion); lastRegion--; @@ -154,20 +147,19 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename) for (auto cc = region->keyRange.getStart(); cc <= region->keyRange.getEnd(); cc++) ccActivationLists[cc].push_back(region); - + // Defaults for (int ccIndex = 1; ccIndex < 128; ccIndex++) region->registerCC(region->channelRange.getStart(), ccIndex, ccState[ccIndex]); - if (defaultSwitch) - { + if (defaultSwitch) { region->registerNoteOn(region->channelRange.getStart(), *defaultSwitch, 127, 1.0); region->registerNoteOff(region->channelRange.getStart(), *defaultSwitch, 0, 1.0); } region->registerPitchWheel(region->channelRange.getStart(), 0); region->registerAftertouch(region->channelRange.getStart(), 0); region->registerTempo(2.0f); - + currentRegion++; } diff --git a/sources/Synth.h b/sources/Synth.h index 1bc9b6b4..15fb676b 100644 --- a/sources/Synth.h +++ b/sources/Synth.h @@ -5,13 +5,13 @@ #include "SfzHelpers.h" #include "StereoSpan.h" #include "absl/types/span.h" +#include #include #include #include #include #include #include -#include using namespace std::literals; namespace sfz { @@ -129,7 +129,7 @@ public: void tempo(int delay, float secondsPerQuarter); protected: - void callback(std::string_view header, const std::vector& members) final; + void callback(std::string_view header, const std::vector& members) final; private: Voice* findFreeVoice() @@ -177,13 +177,12 @@ private: std::thread garbageCollectionThread { [&]() { while (!threadsShouldQuit) { auto activeVoices { 0 }; - for (auto& voice : voices) - { + for (auto& voice : voices) { voice->garbageCollect(); if (!voice->isFree()) activeVoices++; } - DBG("Active voices:" << activeVoices << " | Stray buffers: " << FilePool::getFileBuffers()); + DBG("Active voices:" << activeVoices << " | Stray buffers: " << FilePool::getFileBuffers()); std::this_thread::sleep_for(1s); } } }; @@ -192,7 +191,7 @@ private: { return randomDistribution(randomGenerator); } - + LEAK_DETECTOR(Synth); }; diff --git a/sources/Voice.h b/sources/Voice.h index ac5af232..f7f787c0 100644 --- a/sources/Voice.h +++ b/sources/Voice.h @@ -1,5 +1,6 @@ #pragma once #include "ADSREnvelope.h" +#include "Defaults.h" #include "Globals.h" #include "Region.h" #include "SIMDHelpers.h" @@ -7,7 +8,6 @@ #include "StereoBuffer.h" #include "StereoSpan.h" #include "absl/types/span.h" -#include "Defaults.h" #include #include @@ -92,7 +92,6 @@ public: if (ccState[64] < 63) egEnvelope.startRelease(delay); } - } void registerCC(int delay [[maybe_unused]], int channel [[maybe_unused]], int ccNumber [[maybe_unused]], uint8_t ccValue [[maybe_unused]]) diff --git a/tests/ADSREnvelopeT.cpp b/tests/ADSREnvelopeT.cpp index 1bec2fa0..f753ffab 100644 --- a/tests/ADSREnvelopeT.cpp +++ b/tests/ADSREnvelopeT.cpp @@ -1,21 +1,20 @@ -#include "catch2/catch.hpp" #include "../sources/ADSREnvelope.h" -#include -#include -#include -#include +#include "catch2/catch.hpp" #include +#include +#include +#include +#include using namespace Catch::literals; -template -inline bool approxEqual(absl::Span lhs, absl::Span rhs, Type eps=1e-3) +template +inline bool approxEqual(absl::Span lhs, absl::Span rhs, Type eps = 1e-3) { if (lhs.size() != rhs.size()) return false; for (size_t i = 0; i < rhs.size(); ++i) - if (rhs[i] != Approx(lhs[i]).epsilon(eps)) - { + if (rhs[i] != Approx(lhs[i]).epsilon(eps)) { std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n'; return false; } @@ -28,13 +27,13 @@ TEST_CASE("[ADSREnvelope] Basic state") sfz::ADSREnvelope envelope; std::array output; std::array expected { 0.0, 0.0, 0.0, 0.0, 0.0 }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Attack") @@ -43,14 +42,14 @@ TEST_CASE("[ADSREnvelope] Attack") envelope.reset(2, 0); std::array output; std::array expected { 0.5, 1.0, 1.0, 1.0, 1.0 }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); envelope.reset(2, 0); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Attack again") @@ -59,14 +58,14 @@ TEST_CASE("[ADSREnvelope] Attack again") envelope.reset(3, 0); std::array output; std::array expected { 0.33333, 0.66667, 1.0, 1.0, 1.0 }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); envelope.reset(3, 0); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Release") @@ -76,15 +75,15 @@ TEST_CASE("[ADSREnvelope] Release") envelope.startRelease(2); std::array output; std::array expected { 0.5, 1.0, 0.08409f, 0.00707f, 0.000594604f, 0.00005f, 0.0f, 0.0f }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); - + REQUIRE(approxEqual(output, expected)); + envelope.reset(2, 4); envelope.startRelease(2); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Delay") @@ -94,15 +93,15 @@ TEST_CASE("[ADSREnvelope] Delay") std::array output; envelope.startRelease(4); std::array expected { 0.0, 0.0, 0.5, 1.0, 0.08409f, 0.00707f, 0.000594604f, 0.00005f, 0.0f, 0.0f }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); - + REQUIRE(approxEqual(output, expected)); + envelope.reset(2, 4, 1.0f, 2); envelope.startRelease(4); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Lower sustain") @@ -111,14 +110,14 @@ TEST_CASE("[ADSREnvelope] Lower sustain") envelope.reset(2, 4, 0.5, 2); std::array output; std::array expected { 0.0, 0.0, 0.5, 1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); envelope.reset(2, 4, 0.5, 2); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Decay") @@ -127,14 +126,14 @@ TEST_CASE("[ADSREnvelope] Decay") envelope.reset(2, 4, 0.5, 2, 2); std::array output; std::array expected { 0.0, 0.0, 0.5, 1.0, 0.707107, 0.5, 0.5, 0.5, 0.5, 0.5 }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); envelope.reset(2, 4, 0.5, 2, 2); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Hold") @@ -143,14 +142,14 @@ TEST_CASE("[ADSREnvelope] Hold") envelope.reset(2, 4, 0.5, 2, 2, 2); std::array output; std::array expected { 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 0.707107, 0.5, 0.5, 0.5, 0.5, 0.5 }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); envelope.reset(2, 4, 0.5, 2, 2, 2); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Hold with release") @@ -159,16 +158,16 @@ TEST_CASE("[ADSREnvelope] Hold with release") envelope.reset(2, 4, 0.5, 2, 2, 2); envelope.startRelease(8); std::array output; - std::array expected { 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 0.707107, 0.5, 0.05, 0.005, 0.0005, 0.00005, 0.0, 0.0 }; - for (auto& out: output) + std::array expected { 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 0.707107, 0.5, 0.05, 0.005, 0.0005, 0.00005, 0.0, 0.0 }; + for (auto& out : output) out = envelope.getNextValue(); - - REQUIRE( approxEqual(output, expected) ); + + REQUIRE(approxEqual(output, expected)); envelope.reset(2, 4, 0.5, 2, 2, 2); envelope.startRelease(8); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } TEST_CASE("[ADSREnvelope] Hold with release 2") @@ -178,12 +177,12 @@ TEST_CASE("[ADSREnvelope] Hold with release 2") envelope.startRelease(4); std::array output; std::array expected { 0.0, 0.0, 0.5, 1.0, 0.08409, 0.00707, 0.000594604, 0.00005, 0.0, 0.0, 0.0, 0.0 }; - for (auto& out: output) + for (auto& out : output) out = envelope.getNextValue(); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); envelope.reset(2, 4, 0.5, 2, 2, 2); envelope.startRelease(4); absl::c_fill(output, -1.0); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( approxEqual(output, expected) ); + REQUIRE(approxEqual(output, expected)); } \ No newline at end of file diff --git a/tests/FilesT.cpp b/tests/FilesT.cpp index 50ec99db..06e7c5b6 100644 --- a/tests/FilesT.cpp +++ b/tests/FilesT.cpp @@ -1,5 +1,5 @@ -#include "catch2/catch.hpp" #include "../sources/Synth.h" +#include "catch2/catch.hpp" #include using namespace Catch::literals; @@ -7,76 +7,76 @@ TEST_CASE("[Files] Single region (regions_one.sfz)") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Regions/regions_one.sfz"); - REQUIRE( synth.getNumRegions() == 1 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" ); + REQUIRE(synth.getNumRegions() == 1); + REQUIRE(synth.getRegionView(0)->sample == "dummy.wav"); } TEST_CASE("[Files] Multiple regions (regions_many.sfz)") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Regions/regions_many.sfz"); - REQUIRE( synth.getNumRegions() == 3 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" ); - REQUIRE( synth.getRegionView(1)->sample == "dummy.1.wav" ); - REQUIRE( synth.getRegionView(2)->sample == "dummy.2.wav" ); + REQUIRE(synth.getNumRegions() == 3); + REQUIRE(synth.getRegionView(0)->sample == "dummy.wav"); + REQUIRE(synth.getRegionView(1)->sample == "dummy.1.wav"); + REQUIRE(synth.getRegionView(2)->sample == "dummy.2.wav"); } TEST_CASE("[Files] Basic opcodes (regions_opcodes.sfz)") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Regions/regions_opcodes.sfz"); - REQUIRE( synth.getNumRegions() == 1 ); - REQUIRE( synth.getRegionView(0)->channelRange == Range(2, 14) ); + REQUIRE(synth.getNumRegions() == 1); + REQUIRE(synth.getRegionView(0)->channelRange == Range(2, 14)); } TEST_CASE("[Files] Underscore opcodes (underscore_opcodes.sfz)") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Regions/underscore_opcodes.sfz"); - REQUIRE( synth.getNumRegions() == 1 ); - REQUIRE( synth.getRegionView(0)->loopMode == SfzLoopMode::loop_sustain ); + REQUIRE(synth.getNumRegions() == 1); + REQUIRE(synth.getRegionView(0)->loopMode == SfzLoopMode::loop_sustain); } TEST_CASE("[Files] Local include") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_local.sfz"); - REQUIRE( synth.getNumRegions() == 1 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" ); + REQUIRE(synth.getNumRegions() == 1); + REQUIRE(synth.getRegionView(0)->sample == "dummy.wav"); } TEST_CASE("[Files] Multiple includes") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/multiple_includes.sfz"); - REQUIRE( synth.getNumRegions() == 2 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" ); - REQUIRE( synth.getRegionView(1)->sample == "dummy2.wav" ); + REQUIRE(synth.getNumRegions() == 2); + REQUIRE(synth.getRegionView(0)->sample == "dummy.wav"); + REQUIRE(synth.getRegionView(1)->sample == "dummy2.wav"); } TEST_CASE("[Files] Multiple includes with comments") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/multiple_includes_with_comments.sfz"); - REQUIRE( synth.getNumRegions() == 2 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" ); - REQUIRE( synth.getRegionView(1)->sample == "dummy2.wav" ); + REQUIRE(synth.getNumRegions() == 2); + REQUIRE(synth.getRegionView(0)->sample == "dummy.wav"); + REQUIRE(synth.getRegionView(1)->sample == "dummy2.wav"); } TEST_CASE("[Files] Subdir include") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_subdir.sfz"); - REQUIRE( synth.getNumRegions() == 1 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy_subdir.wav" ); + REQUIRE(synth.getNumRegions() == 1); + REQUIRE(synth.getRegionView(0)->sample == "dummy_subdir.wav"); } TEST_CASE("[Files] Subdir include Win") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_subdir_win.sfz"); - REQUIRE( synth.getNumRegions() == 1 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy_subdir.wav" ); + REQUIRE(synth.getNumRegions() == 1); + REQUIRE(synth.getRegionView(0)->sample == "dummy_subdir.wav"); } TEST_CASE("[Files] Recursive include (with include guard)") @@ -84,9 +84,9 @@ TEST_CASE("[Files] Recursive include (with include guard)") sfz::Synth synth; synth.enableRecursiveIncludeGuard(); synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_recursive.sfz"); - REQUIRE( synth.getNumRegions() == 2 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy_recursive2.wav" ); - REQUIRE( synth.getRegionView(1)->sample == "dummy_recursive1.wav" ); + REQUIRE(synth.getNumRegions() == 2); + REQUIRE(synth.getRegionView(0)->sample == "dummy_recursive2.wav"); + REQUIRE(synth.getRegionView(1)->sample == "dummy_recursive1.wav"); } TEST_CASE("[Files] Include loops (with include guard)") @@ -94,88 +94,85 @@ TEST_CASE("[Files] Include loops (with include guard)") sfz::Synth synth; synth.enableRecursiveIncludeGuard(); synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_loop.sfz"); - REQUIRE( synth.getNumRegions() == 2 ); - REQUIRE( synth.getRegionView(0)->sample == "dummy_loop2.wav" ); - REQUIRE( synth.getRegionView(1)->sample == "dummy_loop1.wav" ); + REQUIRE(synth.getNumRegions() == 2); + REQUIRE(synth.getRegionView(0)->sample == "dummy_loop2.wav"); + REQUIRE(synth.getRegionView(1)->sample == "dummy_loop1.wav"); } TEST_CASE("[Files] Define test") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/defines.sfz"); - REQUIRE( synth.getNumRegions() == 3 ); - REQUIRE( synth.getRegionView(0)->keyRange == Range(36, 36) ); - REQUIRE( synth.getRegionView(1)->keyRange == Range(38, 38) ); - REQUIRE( synth.getRegionView(2)->keyRange == Range(42, 42) ); + REQUIRE(synth.getNumRegions() == 3); + REQUIRE(synth.getRegionView(0)->keyRange == Range(36, 36)); + REQUIRE(synth.getRegionView(1)->keyRange == Range(38, 38)); + REQUIRE(synth.getRegionView(2)->keyRange == Range(42, 42)); } - TEST_CASE("[Files] Group from AVL") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/groups_avl.sfz"); - REQUIRE( synth.getNumRegions() == 5 ); - for (int i = 0; i < synth.getNumRegions(); ++i) - { - REQUIRE( synth.getRegionView(i)->volume == 6.0f ); - REQUIRE( synth.getRegionView(i)->keyRange == Range(36, 36) ); + REQUIRE(synth.getNumRegions() == 5); + for (int i = 0; i < synth.getNumRegions(); ++i) { + REQUIRE(synth.getRegionView(i)->volume == 6.0f); + REQUIRE(synth.getRegionView(i)->keyRange == Range(36, 36)); } - REQUIRE( synth.getRegionView(0)->velocityRange == Range(1, 26) ); - REQUIRE( synth.getRegionView(1)->velocityRange == Range(27, 52) ); - REQUIRE( synth.getRegionView(2)->velocityRange == Range(53, 77) ); - REQUIRE( synth.getRegionView(3)->velocityRange == Range(78, 102) ); - REQUIRE( synth.getRegionView(4)->velocityRange == Range(103, 127) ); + REQUIRE(synth.getRegionView(0)->velocityRange == Range(1, 26)); + REQUIRE(synth.getRegionView(1)->velocityRange == Range(27, 52)); + REQUIRE(synth.getRegionView(2)->velocityRange == Range(53, 77)); + REQUIRE(synth.getRegionView(3)->velocityRange == Range(78, 102)); + REQUIRE(synth.getRegionView(4)->velocityRange == Range(103, 127)); } TEST_CASE("[Files] Full hierarchy") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy.sfz"); - REQUIRE( synth.getNumRegions() == 8 ); - for (int i = 0; i < synth.getNumRegions(); ++i) - { - REQUIRE( synth.getRegionView(i)->width == 40.0f ); + REQUIRE(synth.getNumRegions() == 8); + for (int i = 0; i < synth.getNumRegions(); ++i) { + REQUIRE(synth.getRegionView(i)->width == 40.0f); } - REQUIRE( synth.getRegionView(0)->pan == 30.0f ); - REQUIRE( synth.getRegionView(0)->delay == 67 ); - REQUIRE( synth.getRegionView(0)->keyRange == Range(60, 60) ); + REQUIRE(synth.getRegionView(0)->pan == 30.0f); + REQUIRE(synth.getRegionView(0)->delay == 67); + REQUIRE(synth.getRegionView(0)->keyRange == Range(60, 60)); - REQUIRE( synth.getRegionView(1)->pan == 30.0f ); - REQUIRE( synth.getRegionView(1)->delay == 67 ); - REQUIRE( synth.getRegionView(1)->keyRange == Range(61, 61) ); + REQUIRE(synth.getRegionView(1)->pan == 30.0f); + REQUIRE(synth.getRegionView(1)->delay == 67); + REQUIRE(synth.getRegionView(1)->keyRange == Range(61, 61)); - REQUIRE( synth.getRegionView(2)->pan == 30.0f ); - REQUIRE( synth.getRegionView(2)->delay == 56 ); - REQUIRE( synth.getRegionView(2)->keyRange == Range(50, 50) ); + REQUIRE(synth.getRegionView(2)->pan == 30.0f); + REQUIRE(synth.getRegionView(2)->delay == 56); + REQUIRE(synth.getRegionView(2)->keyRange == Range(50, 50)); - REQUIRE( synth.getRegionView(3)->pan == 30.0f ); - REQUIRE( synth.getRegionView(3)->delay == 56 ); - REQUIRE( synth.getRegionView(3)->keyRange == Range(51, 51) ); + REQUIRE(synth.getRegionView(3)->pan == 30.0f); + REQUIRE(synth.getRegionView(3)->delay == 56); + REQUIRE(synth.getRegionView(3)->keyRange == Range(51, 51)); - REQUIRE( synth.getRegionView(4)->pan == -10.0f ); - REQUIRE( synth.getRegionView(4)->delay == 47 ); - REQUIRE( synth.getRegionView(4)->keyRange == Range(40, 40) ); + REQUIRE(synth.getRegionView(4)->pan == -10.0f); + REQUIRE(synth.getRegionView(4)->delay == 47); + REQUIRE(synth.getRegionView(4)->keyRange == Range(40, 40)); - REQUIRE( synth.getRegionView(5)->pan == -10.0f ); - REQUIRE( synth.getRegionView(5)->delay == 47 ); - REQUIRE( synth.getRegionView(5)->keyRange == Range(41, 41) ); + REQUIRE(synth.getRegionView(5)->pan == -10.0f); + REQUIRE(synth.getRegionView(5)->delay == 47); + REQUIRE(synth.getRegionView(5)->keyRange == Range(41, 41)); - REQUIRE( synth.getRegionView(6)->pan == -10.0f ); - REQUIRE( synth.getRegionView(6)->delay == 36 ); - REQUIRE( synth.getRegionView(6)->keyRange == Range(30, 30) ); + REQUIRE(synth.getRegionView(6)->pan == -10.0f); + REQUIRE(synth.getRegionView(6)->delay == 36); + REQUIRE(synth.getRegionView(6)->keyRange == Range(30, 30)); - REQUIRE( synth.getRegionView(7)->pan == -10.0f ); - REQUIRE( synth.getRegionView(7)->delay == 36 ); - REQUIRE( synth.getRegionView(7)->keyRange == Range(31, 31) ); + REQUIRE(synth.getRegionView(7)->pan == -10.0f); + REQUIRE(synth.getRegionView(7)->delay == 36); + REQUIRE(synth.getRegionView(7)->keyRange == Range(31, 31)); } TEST_CASE("[Files] Reloading files") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy.sfz"); - REQUIRE( synth.getNumRegions() == 8 ); + REQUIRE(synth.getNumRegions() == 8); synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy.sfz"); - REQUIRE( synth.getNumRegions() == 8 ); + REQUIRE(synth.getNumRegions() == 8); } TEST_CASE("[Files] Full hierarchy with antislashes") @@ -183,29 +180,29 @@ TEST_CASE("[Files] Full hierarchy with antislashes") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy.sfz"); - REQUIRE( synth.getNumRegions() == 8 ); - REQUIRE( synth.getRegionView(0)->sample == "Regions/dummy.wav" ); - REQUIRE( synth.getRegionView(1)->sample == "Regions/dummy.1.wav" ); - REQUIRE( synth.getRegionView(2)->sample == "Regions/dummy.wav" ); - REQUIRE( synth.getRegionView(3)->sample == "Regions/dummy.1.wav" ); - REQUIRE( synth.getRegionView(4)->sample == "Regions/dummy.wav" ); - REQUIRE( synth.getRegionView(5)->sample == "Regions/dummy.1.wav" ); - REQUIRE( synth.getRegionView(6)->sample == "Regions/dummy.wav" ); - REQUIRE( synth.getRegionView(7)->sample == "Regions/dummy.1.wav" ); + REQUIRE(synth.getNumRegions() == 8); + REQUIRE(synth.getRegionView(0)->sample == "Regions/dummy.wav"); + REQUIRE(synth.getRegionView(1)->sample == "Regions/dummy.1.wav"); + REQUIRE(synth.getRegionView(2)->sample == "Regions/dummy.wav"); + REQUIRE(synth.getRegionView(3)->sample == "Regions/dummy.1.wav"); + REQUIRE(synth.getRegionView(4)->sample == "Regions/dummy.wav"); + REQUIRE(synth.getRegionView(5)->sample == "Regions/dummy.1.wav"); + REQUIRE(synth.getRegionView(6)->sample == "Regions/dummy.wav"); + REQUIRE(synth.getRegionView(7)->sample == "Regions/dummy.1.wav"); } { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy_antislash.sfz"); - REQUIRE( synth.getNumRegions() == 8 ); - REQUIRE( synth.getRegionView(0)->sample == "Regions/dummy.wav" ); - REQUIRE( synth.getRegionView(1)->sample == "Regions/dummy.1.wav" ); - REQUIRE( synth.getRegionView(2)->sample == "Regions/dummy.wav" ); - REQUIRE( synth.getRegionView(3)->sample == "Regions/dummy.1.wav" ); - REQUIRE( synth.getRegionView(4)->sample == "Regions/dummy.wav" ); - REQUIRE( synth.getRegionView(5)->sample == "Regions/dummy.1.wav" ); - REQUIRE( synth.getRegionView(6)->sample == "Regions/dummy.wav" ); - REQUIRE( synth.getRegionView(7)->sample == "Regions/dummy.1.wav" ); + REQUIRE(synth.getNumRegions() == 8); + REQUIRE(synth.getRegionView(0)->sample == "Regions/dummy.wav"); + REQUIRE(synth.getRegionView(1)->sample == "Regions/dummy.1.wav"); + REQUIRE(synth.getRegionView(2)->sample == "Regions/dummy.wav"); + REQUIRE(synth.getRegionView(3)->sample == "Regions/dummy.1.wav"); + REQUIRE(synth.getRegionView(4)->sample == "Regions/dummy.wav"); + REQUIRE(synth.getRegionView(5)->sample == "Regions/dummy.1.wav"); + REQUIRE(synth.getRegionView(6)->sample == "Regions/dummy.wav"); + REQUIRE(synth.getRegionView(7)->sample == "Regions/dummy.1.wav"); } } @@ -213,22 +210,21 @@ TEST_CASE("[Files] Pizz basic") { sfz::Synth synth; synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/SpecificBugs/MeatBassPizz/Programs/pizz.sfz"); - REQUIRE( synth.getNumRegions() == 4 ); - for (int i = 0; i < synth.getNumRegions(); ++i) - { - REQUIRE( synth.getRegionView(i)->keyRange == Range(12, 22) ); - REQUIRE( synth.getRegionView(i)->velocityRange == Range(97, 127) ); - REQUIRE( synth.getRegionView(i)->pitchKeycenter == 21 ); - REQUIRE( synth.getRegionView(i)->ccConditions.getWithDefault(107) == Range(0, 13) ); + REQUIRE(synth.getNumRegions() == 4); + for (int i = 0; i < synth.getNumRegions(); ++i) { + REQUIRE(synth.getRegionView(i)->keyRange == Range(12, 22)); + REQUIRE(synth.getRegionView(i)->velocityRange == Range(97, 127)); + REQUIRE(synth.getRegionView(i)->pitchKeycenter == 21); + REQUIRE(synth.getRegionView(i)->ccConditions.getWithDefault(107) == Range(0, 13)); } - REQUIRE( synth.getRegionView(0)->randRange == Range(0, 0.25) ); - REQUIRE( synth.getRegionView(1)->randRange == Range(0.25, 0.5) ); - REQUIRE( synth.getRegionView(2)->randRange == Range(0.5, 0.75) ); - REQUIRE( synth.getRegionView(3)->randRange == Range(0.75, 1.0) ); - REQUIRE( synth.getRegionView(0)->sample == R"(../Samples/pizz/a0_vl4_rr1.wav)" ); - REQUIRE( synth.getRegionView(1)->sample == R"(../Samples/pizz/a0_vl4_rr2.wav)" ); - REQUIRE( synth.getRegionView(2)->sample == R"(../Samples/pizz/a0_vl4_rr3.wav)" ); - REQUIRE( synth.getRegionView(3)->sample == R"(../Samples/pizz/a0_vl4_rr4.wav)" ); + REQUIRE(synth.getRegionView(0)->randRange == Range(0, 0.25)); + REQUIRE(synth.getRegionView(1)->randRange == Range(0.25, 0.5)); + REQUIRE(synth.getRegionView(2)->randRange == Range(0.5, 0.75)); + REQUIRE(synth.getRegionView(3)->randRange == Range(0.75, 1.0)); + REQUIRE(synth.getRegionView(0)->sample == R"(../Samples/pizz/a0_vl4_rr1.wav)"); + REQUIRE(synth.getRegionView(1)->sample == R"(../Samples/pizz/a0_vl4_rr2.wav)"); + REQUIRE(synth.getRegionView(2)->sample == R"(../Samples/pizz/a0_vl4_rr3.wav)"); + REQUIRE(synth.getRegionView(3)->sample == R"(../Samples/pizz/a0_vl4_rr4.wav)"); } // TEST_CASE("[Files] sw_default") diff --git a/tests/HelpersT.cpp b/tests/HelpersT.cpp index 449e94be..36f32f81 100644 --- a/tests/HelpersT.cpp +++ b/tests/HelpersT.cpp @@ -1,8 +1,8 @@ -#include "catch2/catch.hpp" #include "../sources/Helpers.h" +#include "catch2/catch.hpp" #include using namespace Catch::literals; -using namespace std::literals::string_view_literals; +using namespace std::literals::string_view_literals; TEST_CASE("[Helpers] trimInPlace") { @@ -10,28 +10,28 @@ TEST_CASE("[Helpers] trimInPlace") { auto input { "view"sv }; trimInPlace(input); - REQUIRE( input == "view"sv ); + REQUIRE(input == "view"sv); } SECTION("Trim spaces") { auto input { " view "sv }; trimInPlace(input); - REQUIRE( input == "view"sv ); + REQUIRE(input == "view"sv); } SECTION("Trim other chars") { auto input { " \tview \t"sv }; trimInPlace(input); - REQUIRE( input == "view"sv ); + REQUIRE(input == "view"sv); } SECTION("Empty view") { auto input { " "sv }; trimInPlace(input); - REQUIRE( input.empty() ); + REQUIRE(input.empty()); } } @@ -40,24 +40,24 @@ TEST_CASE("[Helpers] trim") SECTION("Trim nothing") { auto input { "view"sv }; - REQUIRE( trim(input) == "view"sv ); + REQUIRE(trim(input) == "view"sv); } SECTION("Trim spaces") { auto input { " view "sv }; - REQUIRE( trim(input) == "view"sv ); + REQUIRE(trim(input) == "view"sv); } SECTION("Trim other chars") { auto input { " \tview \t"sv }; - REQUIRE( trim(input) == "view"sv ); + REQUIRE(trim(input) == "view"sv); } SECTION("Empty view") { auto input { " "sv }; - REQUIRE( trim(input).empty() ); + REQUIRE(trim(input).empty()); } } \ No newline at end of file diff --git a/tests/LinearEnvelopeT.cpp b/tests/LinearEnvelopeT.cpp index dc70842b..880478f9 100644 --- a/tests/LinearEnvelopeT.cpp +++ b/tests/LinearEnvelopeT.cpp @@ -1,21 +1,20 @@ -#include "catch2/catch.hpp" #include "../sources/LinearEnvelope.h" -#include -#include -#include -#include +#include "catch2/catch.hpp" #include +#include +#include +#include +#include using namespace Catch::literals; -template -inline bool approxEqual(absl::Span lhs, absl::Span rhs, Type eps=1e-3) +template +inline bool approxEqual(absl::Span lhs, absl::Span rhs, Type eps = 1e-3) { if (lhs.size() != rhs.size()) return false; for (size_t i = 0; i < rhs.size(); ++i) - if (rhs[i] != Approx(lhs[i]).epsilon(eps)) - { + if (rhs[i] != Approx(lhs[i]).epsilon(eps)) { std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n'; return false; } @@ -29,7 +28,7 @@ TEST_CASE("[LinearEnvelope] Basic state") std::array output; std::array expected { 0.0, 0.0, 0.0, 0.0, 0.0 }; envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] Basic event") @@ -39,7 +38,7 @@ TEST_CASE("[LinearEnvelope] Basic event") std::array output; std::array expected { 0.25, 0.5, 0.75, 1.0, 1.0, 1.0, 1.0, 1.0 }; envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] 2 events, close") @@ -50,7 +49,7 @@ TEST_CASE("[LinearEnvelope] 2 events, close") std::array output; std::array expected { 0.25, 0.5, 0.75, 1.0, 2.0, 2.0, 2.0, 2.0 }; envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] 2 events, far") @@ -61,7 +60,7 @@ TEST_CASE("[LinearEnvelope] 2 events, far") std::array output; std::array expected { 0.5, 1, 1.25, 1.5, 1.75, 2.0, 2.0, 2.0 }; envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] 2 events, reversed") @@ -72,7 +71,7 @@ TEST_CASE("[LinearEnvelope] 2 events, reversed") std::array output; std::array expected { 0.5, 1, 1.25, 1.5, 1.75, 2.0, 2.0, 2.0 }; envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] 3 events, overlapping") @@ -84,7 +83,7 @@ TEST_CASE("[LinearEnvelope] 3 events, overlapping") std::array output; std::array expected { 0.5, 1, 1.25, 1.5, 1.75, 2.0, 3.0, 3.0 }; envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] 3 events, out of block") @@ -96,7 +95,7 @@ TEST_CASE("[LinearEnvelope] 3 events, out of block") std::array output; std::array expected { 0.5, 1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0 }; envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] 3 events, out of block, with another block call") @@ -109,7 +108,7 @@ TEST_CASE("[LinearEnvelope] 3 events, out of block, with another block call") std::array expected { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 }; envelope.getBlock(absl::MakeSpan(output)); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] 2 events, with another block call") @@ -121,17 +120,17 @@ TEST_CASE("[LinearEnvelope] 2 events, with another block call") std::array expected { 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 }; envelope.getBlock(absl::MakeSpan(output)); envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[LinearEnvelope] 2 events, function") { sfz::LinearEnvelope envelope; - envelope.setFunction([](auto x) { return 2*x; }); + envelope.setFunction([](auto x) { return 2 * x; }); envelope.registerEvent(2, 1.0); envelope.registerEvent(6, 2.0); std::array output; std::array expected { 1, 2, 2.5, 3, 3.5, 4.0, 4.0, 4.0 }; envelope.getBlock(absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } \ No newline at end of file diff --git a/tests/OnePoleFilterT.cpp b/tests/OnePoleFilterT.cpp index 229e8ec3..37700812 100644 --- a/tests/OnePoleFilterT.cpp +++ b/tests/OnePoleFilterT.cpp @@ -1,21 +1,20 @@ #include "../sources/OnePoleFilter.h" #include "catch2/catch.hpp" #include "cnpy.h" -#include -#include -#include #include +#include +#include +#include using namespace Catch::literals; -template +template inline bool approxEqual(const std::vector& lhs, const std::vector& rhs) { if (lhs.size() != rhs.size()) return false; for (size_t i = 0; i < rhs.size(); ++i) - if (lhs[i] != Approx(rhs[i]).epsilon(1e-3)) - { + if (lhs[i] != Approx(rhs[i]).epsilon(1e-3)) { std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n'; return false; } @@ -23,74 +22,74 @@ inline bool approxEqual(const std::vector& lhs, const std::vector& r return true; } -template +template void testLowpass(const std::filesystem::path& inputNumpyFile, const std::filesystem::path& outputNumpyFile, Type gain) { const auto input = cnpy::npy_load(inputNumpyFile.string()); - REQUIRE( input.word_size == 8 ); + REQUIRE(input.word_size == 8); const auto inputSpan = absl::MakeSpan(input.data(), input.shape[0]); const auto output = cnpy::npy_load(outputNumpyFile.string()); - REQUIRE( output.word_size == 8 ); + REQUIRE(output.word_size == 8); const auto outputSpan = absl::MakeSpan(output.data(), output.shape[0]); auto size = std::min(outputSpan.size(), inputSpan.size()); - REQUIRE( size > 0 ); + REQUIRE(size > 0); std::vector inputData; std::vector expectedData; inputData.reserve(size); expectedData.reserve(size); - for (auto& data: inputSpan) + for (auto& data : inputSpan) inputData.push_back(static_cast(data)); - for (auto& data: outputSpan) + for (auto& data : outputSpan) expectedData.push_back(static_cast(data)); - + OnePoleFilter filter { gain }; - std::vector outputData (size); + std::vector outputData(size); filter.processLowpass(inputData, absl::MakeSpan(outputData)); - REQUIRE( approxEqual(outputData, expectedData) ); + REQUIRE(approxEqual(outputData, expectedData)); filter.reset(); std::fill(outputData.begin(), outputData.end(), 0.0); std::vector gains(size); std::fill(gains.begin(), gains.end(), gain); filter.processLowpassVariableGain(inputData, absl::MakeSpan(outputData), gains); - REQUIRE( approxEqual(outputData, expectedData) ); + REQUIRE(approxEqual(outputData, expectedData)); } -template +template void testHighpass(const std::filesystem::path& inputNumpyFile, const std::filesystem::path& outputNumpyFile, Type gain) { const auto input = cnpy::npy_load(inputNumpyFile.string()); - REQUIRE( input.word_size == 8 ); + REQUIRE(input.word_size == 8); const auto inputSpan = absl::MakeSpan(input.data(), input.shape[0]); const auto output = cnpy::npy_load(outputNumpyFile.string()); - REQUIRE( output.word_size == 8 ); + REQUIRE(output.word_size == 8); const auto outputSpan = absl::MakeSpan(output.data(), output.shape[0]); auto size = std::min(outputSpan.size(), inputSpan.size()); - REQUIRE( size > 0 ); + REQUIRE(size > 0); std::vector inputData; std::vector expectedData; inputData.reserve(size); expectedData.reserve(size); - for (auto& data: inputSpan) + for (auto& data : inputSpan) inputData.push_back(static_cast(data)); - for (auto& data: outputSpan) + for (auto& data : outputSpan) expectedData.push_back(static_cast(data)); - + OnePoleFilter filter { gain }; - std::vector outputData (size); + std::vector outputData(size); filter.processHighpass(inputData, absl::MakeSpan(outputData)); - REQUIRE( approxEqual(outputData, expectedData) ); + REQUIRE(approxEqual(outputData, expectedData)); filter.reset(); std::fill(outputData.begin(), outputData.end(), 0.0); std::vector gains(size); std::fill(gains.begin(), gains.end(), gain); filter.processHighpassVariableGain(inputData, absl::MakeSpan(outputData), gains); - REQUIRE( approxEqual(outputData, expectedData) ); + REQUIRE(approxEqual(outputData, expectedData)); } TEST_CASE("[OnePoleFilter] Lowpass Float") @@ -98,28 +97,23 @@ TEST_CASE("[OnePoleFilter] Lowpass Float") testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.1.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.1.npy", - 0.1f - ); + 0.1f); testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.3.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.3.npy", - 0.3f - ); + 0.3f); testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.5.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.5.npy", - 0.5f - ); + 0.5f); testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.7.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.7.npy", - 0.7f - ); + 0.7f); testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.9.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.9.npy", - 0.9f - ); + 0.9f); } TEST_CASE("[OnePoleFilter] Lowpass Double") @@ -127,28 +121,23 @@ TEST_CASE("[OnePoleFilter] Lowpass Double") testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.1.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.1.npy", - 0.1f - ); + 0.1f); testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.3.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.3.npy", - 0.3f - ); + 0.3f); testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.5.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.5.npy", - 0.5f - ); + 0.5f); testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.7.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.7.npy", - 0.7f - ); + 0.7f); testLowpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.9.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.9.npy", - 0.9f - ); + 0.9f); } TEST_CASE("[OnePoleFilter] Highpass Float") @@ -156,28 +145,23 @@ TEST_CASE("[OnePoleFilter] Highpass Float") testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.1.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.1.npy", - 0.1f - ); + 0.1f); testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.3.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.3.npy", - 0.3f - ); + 0.3f); testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.5.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.5.npy", - 0.5f - ); + 0.5f); testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.7.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.7.npy", - 0.7f - ); + 0.7f); testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.9.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.9.npy", - 0.9f - ); + 0.9f); } TEST_CASE("[OnePoleFilter] Highpass Double") @@ -185,26 +169,21 @@ TEST_CASE("[OnePoleFilter] Highpass Double") testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.1.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.1.npy", - 0.1f - ); + 0.1f); testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.3.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.3.npy", - 0.3f - ); + 0.3f); testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.5.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.5.npy", - 0.5f - ); + 0.5f); testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.7.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.7.npy", - 0.7f - ); + 0.7f); testHighpass( std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.9.npy", std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.9.npy", - 0.9f - ); + 0.9f); } diff --git a/tests/OpcodeT.cpp b/tests/OpcodeT.cpp index b965f604..51984f36 100644 --- a/tests/OpcodeT.cpp +++ b/tests/OpcodeT.cpp @@ -1,62 +1,62 @@ -#include "catch2/catch.hpp" #include "../sources/Region.h" +#include "catch2/catch.hpp" using namespace Catch::literals; TEST_CASE("[Opcode] Construction") { SECTION("Normal construction") { - sfz::Opcode opcode { "sample", "dummy"}; - REQUIRE( opcode.opcode == "sample" ); - REQUIRE( opcode.value == "dummy" ); - REQUIRE( !opcode.parameter ); + sfz::Opcode opcode { "sample", "dummy" }; + REQUIRE(opcode.opcode == "sample"); + REQUIRE(opcode.value == "dummy"); + REQUIRE(!opcode.parameter); } SECTION("Normal construction with underscore") { - sfz::Opcode opcode { "sample_underscore", "dummy"}; - REQUIRE( opcode.opcode == "sample_underscore" ); - REQUIRE( opcode.value == "dummy" ); - REQUIRE( !opcode.parameter ); + sfz::Opcode opcode { "sample_underscore", "dummy" }; + REQUIRE(opcode.opcode == "sample_underscore"); + REQUIRE(opcode.value == "dummy"); + REQUIRE(!opcode.parameter); } SECTION("Parameterized opcode") { - sfz::Opcode opcode { "sample123", "dummy"}; - REQUIRE( opcode.opcode == "sample" ); - REQUIRE( opcode.value == "dummy" ); - REQUIRE( opcode.parameter ); - REQUIRE( *opcode.parameter == 123 ); + sfz::Opcode opcode { "sample123", "dummy" }; + REQUIRE(opcode.opcode == "sample"); + REQUIRE(opcode.value == "dummy"); + REQUIRE(opcode.parameter); + REQUIRE(*opcode.parameter == 123); } SECTION("Parameterized opcode with underscore") { - sfz::Opcode opcode { "sample_underscore123", "dummy"}; - REQUIRE( opcode.opcode == "sample_underscore" ); - REQUIRE( opcode.value == "dummy" ); - REQUIRE( opcode.parameter ); - REQUIRE( *opcode.parameter == 123 ); + sfz::Opcode opcode { "sample_underscore123", "dummy" }; + REQUIRE(opcode.opcode == "sample_underscore"); + REQUIRE(opcode.value == "dummy"); + REQUIRE(opcode.parameter); + REQUIRE(*opcode.parameter == 123); } } TEST_CASE("[Opcode] Note values") { auto noteValue = sfz::readNoteValue("c-1"); - REQUIRE( noteValue ); - REQUIRE( *noteValue == 0); + REQUIRE(noteValue); + REQUIRE(*noteValue == 0); noteValue = sfz::readNoteValue("C-1"); - REQUIRE( noteValue ); - REQUIRE( *noteValue == 0); + REQUIRE(noteValue); + REQUIRE(*noteValue == 0); noteValue = sfz::readNoteValue("g9"); - REQUIRE( noteValue ); - REQUIRE( *noteValue == 127); + REQUIRE(noteValue); + REQUIRE(*noteValue == 127); noteValue = sfz::readNoteValue("G9"); - REQUIRE( noteValue ); - REQUIRE( *noteValue == 127); + REQUIRE(noteValue); + REQUIRE(*noteValue == 127); noteValue = sfz::readNoteValue("c#4"); - REQUIRE( noteValue ); - REQUIRE( *noteValue == 61); + REQUIRE(noteValue); + REQUIRE(*noteValue == 61); noteValue = sfz::readNoteValue("C#4"); - REQUIRE( noteValue ); - REQUIRE( *noteValue == 61); + REQUIRE(noteValue); + REQUIRE(*noteValue == 61); } diff --git a/tests/RangeT.cpp b/tests/RangeT.cpp index 72fe8391..cf1349c2 100644 --- a/tests/RangeT.cpp +++ b/tests/RangeT.cpp @@ -4,88 +4,88 @@ using namespace Catch::literals; TEST_CASE("[Range] Equality operators") { - Range intRange {1, 1}; - REQUIRE( intRange == Range(1, 1) ); - REQUIRE( intRange == std::pair(1, 1) ); - REQUIRE( std::pair(1, 1) == intRange ); + Range intRange { 1, 1 }; + REQUIRE(intRange == Range(1, 1)); + REQUIRE(intRange == std::pair(1, 1)); + REQUIRE(std::pair(1, 1) == intRange); - Range floatRange {1.0f, 1.0f}; - REQUIRE( floatRange == Range(1.0f, 1.0f) ); - REQUIRE( floatRange == std::pair(1.0f, 1.0f) ); - REQUIRE( std::pair(1.0f, 1.0f) == floatRange); + Range floatRange { 1.0f, 1.0f }; + REQUIRE(floatRange == Range(1.0f, 1.0f)); + REQUIRE(floatRange == std::pair(1.0f, 1.0f)); + REQUIRE(std::pair(1.0f, 1.0f) == floatRange); } TEST_CASE("[Range] Default ranges for classical types") { Range intRange; - REQUIRE( intRange == Range(0, 0) ); + REQUIRE(intRange == Range(0, 0)); Range int32_tRange; - REQUIRE( int32_tRange == Range(0, 0) ); + REQUIRE(int32_tRange == Range(0, 0)); Range uint32_tRange; - REQUIRE( uint32_tRange == Range(0, 0) ); + REQUIRE(uint32_tRange == Range(0, 0)); Range int64_tRange; - REQUIRE( int64_tRange == Range(0, 0) ); + REQUIRE(int64_tRange == Range(0, 0)); Range uint64_tRange; - REQUIRE( uint64_tRange == Range(0, 0) ); + REQUIRE(uint64_tRange == Range(0, 0)); Range floatRange; - REQUIRE( floatRange == Range(0, 0) ); + REQUIRE(floatRange == Range(0, 0)); Range doubleRange; - REQUIRE( doubleRange == Range(0, 0) ); + REQUIRE(doubleRange == Range(0, 0)); } TEST_CASE("[Range] Contains") { - Range intRange {1, 10}; - REQUIRE( !intRange.contains(0) ); - REQUIRE( intRange.contains(1) ); - REQUIRE( intRange.contains(5) ); - REQUIRE( !intRange.contains(10) ); - REQUIRE( !intRange.containsWithEnd(0) ); - REQUIRE( intRange.containsWithEnd(1) ); - REQUIRE( intRange.containsWithEnd(5) ); - REQUIRE( intRange.containsWithEnd(10) ); + Range intRange { 1, 10 }; + REQUIRE(!intRange.contains(0)); + REQUIRE(intRange.contains(1)); + REQUIRE(intRange.contains(5)); + REQUIRE(!intRange.contains(10)); + REQUIRE(!intRange.containsWithEnd(0)); + REQUIRE(intRange.containsWithEnd(1)); + REQUIRE(intRange.containsWithEnd(5)); + REQUIRE(intRange.containsWithEnd(10)); - Range floatRange {1.0, 10.0}; - REQUIRE( !floatRange.contains(0.0) ); - REQUIRE( floatRange.contains(1.0) ); - REQUIRE( floatRange.contains(5.0) ); - REQUIRE( !floatRange.contains(10.0) ); - REQUIRE( !floatRange.containsWithEnd(0.0) ); - REQUIRE( floatRange.containsWithEnd(1.0) ); - REQUIRE( floatRange.containsWithEnd(5.0) ); - REQUIRE( floatRange.containsWithEnd(10.0) ); + Range floatRange { 1.0, 10.0 }; + REQUIRE(!floatRange.contains(0.0)); + REQUIRE(floatRange.contains(1.0)); + REQUIRE(floatRange.contains(5.0)); + REQUIRE(!floatRange.contains(10.0)); + REQUIRE(!floatRange.containsWithEnd(0.0)); + REQUIRE(floatRange.containsWithEnd(1.0)); + REQUIRE(floatRange.containsWithEnd(5.0)); + REQUIRE(floatRange.containsWithEnd(10.0)); } TEST_CASE("[Range] Clamp") { - Range intRange {1, 10}; - REQUIRE( intRange.clamp(0) == 1 ); - REQUIRE( intRange.clamp(1) == 1 ); - REQUIRE( intRange.clamp(5) == 5 ); - REQUIRE( intRange.clamp(10) == 10 ); - REQUIRE( intRange.clamp(11) == 10 ); + Range intRange { 1, 10 }; + REQUIRE(intRange.clamp(0) == 1); + REQUIRE(intRange.clamp(1) == 1); + REQUIRE(intRange.clamp(5) == 5); + REQUIRE(intRange.clamp(10) == 10); + REQUIRE(intRange.clamp(11) == 10); - Range floatRange {1.0, 10.0}; - REQUIRE( floatRange.clamp(0.0) == 1.0_a ); - REQUIRE( floatRange.clamp(1.0) == 1.0_a ); - REQUIRE( floatRange.clamp(5.0) == 5.0_a ); - REQUIRE( floatRange.clamp(10.0) == 10.0_a ); - REQUIRE( floatRange.clamp(11.0) == 10.0_a ); + Range floatRange { 1.0, 10.0 }; + REQUIRE(floatRange.clamp(0.0) == 1.0_a); + REQUIRE(floatRange.clamp(1.0) == 1.0_a); + REQUIRE(floatRange.clamp(5.0) == 5.0_a); + REQUIRE(floatRange.clamp(10.0) == 10.0_a); + REQUIRE(floatRange.clamp(11.0) == 10.0_a); } TEST_CASE("[Range] shrinkIfSmaller") { - Range intRange {2, 10}; + Range intRange { 2, 10 }; intRange.shrinkIfSmaller(0, 10); - REQUIRE( intRange == Range(2, 10) ); + REQUIRE(intRange == Range(2, 10)); intRange.shrinkIfSmaller(2, 11); - REQUIRE( intRange == Range(2, 10) ); + REQUIRE(intRange == Range(2, 10)); intRange.shrinkIfSmaller(2, 9); - REQUIRE( intRange == Range(2, 9) ); + REQUIRE(intRange == Range(2, 9)); intRange.shrinkIfSmaller(3, 9); - REQUIRE( intRange == Range(3, 9) ); + REQUIRE(intRange == Range(3, 9)); intRange.shrinkIfSmaller(4, 7); - REQUIRE( intRange == Range(4, 7) ); + REQUIRE(intRange == Range(4, 7)); intRange.shrinkIfSmaller(6, 5); - REQUIRE( intRange == Range(5, 6) ); + REQUIRE(intRange == Range(5, 6)); } \ No newline at end of file diff --git a/tests/RegexT.cpp b/tests/RegexT.cpp index ff4f52e1..80e81a48 100644 --- a/tests/RegexT.cpp +++ b/tests/RegexT.cpp @@ -1,5 +1,5 @@ -#include "catch2/catch.hpp" #include "../sources/Parser.h" +#include "catch2/catch.hpp" using namespace Catch::literals; void includeTest(const std::string& line, const std::string& fileName) @@ -57,7 +57,7 @@ TEST_CASE("[Regex] Header") SECTION("Basic header match") { std::smatch headerMatch; - std::string line{"
param1=value1 param2=value2"}; + std::string line { "
param1=value1 param2=value2" }; auto found = std::regex_search(line, headerMatch, sfz::Regexes::headers); REQUIRE(found); REQUIRE(headerMatch[1] == "header"); @@ -66,7 +66,7 @@ TEST_CASE("[Regex] Header") SECTION("EOL header match") { std::smatch headerMatch; - std::string line{"
param1=value1 param2=value2"}; + std::string line { "
param1=value1 param2=value2" }; auto found = std::regex_search(line, headerMatch, sfz::Regexes::headers); REQUIRE(found); REQUIRE(headerMatch[1] == "header"); @@ -74,7 +74,7 @@ TEST_CASE("[Regex] Header") } } -void memberTest(const std::string &line, const std::string &variable, const std::string &value) +void memberTest(const std::string& line, const std::string& variable, const std::string& value) { std::smatch memberMatch; auto found = std::regex_search(line, memberMatch, sfz::Regexes::members); @@ -114,7 +114,7 @@ void parameterTest(const std::string& line, const std::string& opcode, const std REQUIRE(parameterMatch[2] == parameter); } -void parameterFail(const std::string &line) +void parameterFail(const std::string& line) { std::smatch parameterMatch; auto found = std::regex_search(line, parameterMatch, sfz::Regexes::opcodeParameters); diff --git a/tests/RegionActivationT.cpp b/tests/RegionActivationT.cpp index b89a987d..f5bbdca1 100644 --- a/tests/RegionActivationT.cpp +++ b/tests/RegionActivationT.cpp @@ -1,15 +1,15 @@ -#include "catch2/catch.hpp" #include "../sources/Region.h" +#include "catch2/catch.hpp" using namespace Catch::literals; TEST_CASE("Region activation", "Region tests") { - sfz::Region region { }; + sfz::Region region {}; region.parseOpcode({ "sample", "*sine" }); SECTION("Basic state") { region.registerCC(1, 4, 0); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); } SECTION("Single CC range") @@ -17,19 +17,19 @@ TEST_CASE("Region activation", "Region tests") region.parseOpcode({ "locc4", "56" }); region.parseOpcode({ "hicc4", "59" }); region.registerCC(1, 4, 0); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerCC(1, 4, 57); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 4, 56); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 4, 59); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 4, 43); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerCC(1, 4, 65); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerCC(1, 6, 57); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); } SECTION("Multiple CC ranges") @@ -40,25 +40,25 @@ TEST_CASE("Region activation", "Region tests") region.parseOpcode({ "hicc54", "27" }); region.registerCC(1, 4, 0); region.registerCC(1, 54, 0); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerCC(1, 4, 57); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerCC(1, 54, 19); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 54, 18); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 54, 27); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 4, 56); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 4, 59); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 54, 2); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerCC(1, 54, 26); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerCC(1, 4, 65); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); } SECTION("Bend ranges") @@ -66,13 +66,13 @@ TEST_CASE("Region activation", "Region tests") region.parseOpcode({ "lobend", "56" }); region.parseOpcode({ "hibend", "243" }); region.registerPitchWheel(1, 0); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerPitchWheel(1, 56); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerPitchWheel(1, 243); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerPitchWheel(1, 245); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); } SECTION("Aftertouch ranges") @@ -80,13 +80,13 @@ TEST_CASE("Region activation", "Region tests") region.parseOpcode({ "lochanaft", "56" }); region.parseOpcode({ "hichanaft", "68" }); region.registerAftertouch(1, 0); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerAftertouch(1, 56); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerAftertouch(1, 68); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerAftertouch(1, 98); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); } SECTION("BPM ranges") @@ -94,26 +94,26 @@ TEST_CASE("Region activation", "Region tests") region.parseOpcode({ "lobpm", "56" }); region.parseOpcode({ "hibpm", "68" }); region.registerTempo(2.0f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerTempo(0.90f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerTempo(1.01f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerTempo(1.1f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); } // TODO: add keyswitches SECTION("Keyswitches: sw_last") { region.parseOpcode({ "sw_last", "40" }); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 41, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 41, 0, 0.5f); } @@ -122,20 +122,20 @@ TEST_CASE("Region activation", "Region tests") region.parseOpcode({ "sw_lokey", "30" }); region.parseOpcode({ "sw_hikey", "50" }); region.parseOpcode({ "sw_last", "40" }); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 60, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 60, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 60, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 60, 0, 0.5f); region.registerNoteOn(1, 41, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 41, 0, 0.5f); } @@ -144,20 +144,20 @@ TEST_CASE("Region activation", "Region tests") region.parseOpcode({ "sw_lokey", "30" }); region.parseOpcode({ "sw_hikey", "50" }); region.parseOpcode({ "sw_down", "40" }); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 60, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 60, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 60, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 60, 0, 0.5f); region.registerNoteOn(1, 41, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 41, 0, 0.5f); } @@ -166,103 +166,100 @@ TEST_CASE("Region activation", "Region tests") region.parseOpcode({ "sw_lokey", "30" }); region.parseOpcode({ "sw_hikey", "50" }); region.parseOpcode({ "sw_up", "40" }); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 41, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); region.registerNoteOff(1, 41, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); } SECTION("Keyswitches: sw_previous") { region.parseOpcode({ "sw_previous", "40" }); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 41, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); region.registerNoteOff(1, 41, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 41, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 41, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); } - + SECTION("Sequences: length 2, default position") { region.parseOpcode({ "seq_length", "2" }); region.parseOpcode({ "seq_position", "1" }); region.parseOpcode({ "key", "40" }); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); - + REQUIRE(!region.isSwitchedOn()); } SECTION("Sequences: length 2, position 2") { region.parseOpcode({ "seq_length", "2" }); region.parseOpcode({ "seq_position", "2" }); region.parseOpcode({ "key", "40" }); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); - + REQUIRE(region.isSwitchedOn()); } SECTION("Sequences: length 3, position 2") { region.parseOpcode({ "seq_length", "3" }); region.parseOpcode({ "seq_position", "2" }); region.parseOpcode({ "key", "40" }); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( !region.isSwitchedOn() ); + REQUIRE(!region.isSwitchedOn()); region.registerNoteOn(1, 40, 64, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); region.registerNoteOff(1, 40, 0, 0.5f); - REQUIRE( region.isSwitchedOn() ); + REQUIRE(region.isSwitchedOn()); } } - diff --git a/tests/RegionT.cpp b/tests/RegionT.cpp index dc2a0649..5ad1b89a 100644 --- a/tests/RegionT.cpp +++ b/tests/RegionT.cpp @@ -1,5 +1,5 @@ -#include "catch2/catch.hpp" #include "../sources/Region.h" +#include "catch2/catch.hpp" using namespace Catch::literals; TEST_CASE("[Region] Parsing opcodes") @@ -7,772 +7,771 @@ TEST_CASE("[Region] Parsing opcodes") sfz::Region region; SECTION("sample") { - REQUIRE( region.sample == "" ); + REQUIRE(region.sample == ""); region.parseOpcode({ "sample", "dummy.wav" }); - REQUIRE( region.sample == "dummy.wav" ); + REQUIRE(region.sample == "dummy.wav"); } SECTION("delay") { - REQUIRE( region.delay == 0.0 ); + REQUIRE(region.delay == 0.0); region.parseOpcode({ "delay", "1.0" }); - REQUIRE( region.delay == 1.0 ); + REQUIRE(region.delay == 1.0); region.parseOpcode({ "delay", "-1.0" }); - REQUIRE( region.delay == 0.0 ); + REQUIRE(region.delay == 0.0); region.parseOpcode({ "delay", "110.0" }); - REQUIRE( region.delay == 100.0 ); + REQUIRE(region.delay == 100.0); } SECTION("delay_random") { - REQUIRE( region.delayRandom == 0.0 ); + REQUIRE(region.delayRandom == 0.0); region.parseOpcode({ "delay_random", "1.0" }); - REQUIRE( region.delayRandom == 1.0); + REQUIRE(region.delayRandom == 1.0); region.parseOpcode({ "delay_random", "-1.0" }); - REQUIRE( region.delayRandom == 0.0 ); + REQUIRE(region.delayRandom == 0.0); region.parseOpcode({ "delay_random", "110.0" }); - REQUIRE( region.delayRandom == 100.0 ); + REQUIRE(region.delayRandom == 100.0); } SECTION("offset") { - REQUIRE( region.offset == 0 ); + REQUIRE(region.offset == 0); region.parseOpcode({ "offset", "1" }); - REQUIRE( region.offset == 1 ); + REQUIRE(region.offset == 1); region.parseOpcode({ "offset", "-1" }); - REQUIRE( region.offset == 0 ); + REQUIRE(region.offset == 0); } SECTION("offset_random") { - REQUIRE( region.offsetRandom == 0 ); + REQUIRE(region.offsetRandom == 0); region.parseOpcode({ "offset_random", "1" }); - REQUIRE( region.offsetRandom == 1 ); + REQUIRE(region.offsetRandom == 1); region.parseOpcode({ "offset_random", "-1" }); - REQUIRE( region.offsetRandom == 0); + REQUIRE(region.offsetRandom == 0); } SECTION("end") { region.parseOpcode({ "end", "184" }); - REQUIRE( region.sampleEnd == 184 ); + REQUIRE(region.sampleEnd == 184); region.parseOpcode({ "end", "-1" }); - REQUIRE( region.sampleEnd == 0 ); + REQUIRE(region.sampleEnd == 0); } SECTION("count") { - REQUIRE( !region.sampleCount ); + REQUIRE(!region.sampleCount); region.parseOpcode({ "count", "184" }); - REQUIRE( region.sampleCount ); - REQUIRE( *region.sampleCount == 184 ); + REQUIRE(region.sampleCount); + REQUIRE(*region.sampleCount == 184); region.parseOpcode({ "count", "-1" }); - REQUIRE( region.sampleCount ); - REQUIRE( *region.sampleCount == 0 ); + REQUIRE(region.sampleCount); + REQUIRE(*region.sampleCount == 0); } SECTION("loop_mode") { - REQUIRE( region.loopMode == SfzLoopMode::no_loop ); + REQUIRE(region.loopMode == SfzLoopMode::no_loop); region.parseOpcode({ "loop_mode", "no_loop" }); - REQUIRE( region.loopMode == SfzLoopMode::no_loop ); + REQUIRE(region.loopMode == SfzLoopMode::no_loop); region.parseOpcode({ "loop_mode", "one_shot" }); - REQUIRE( region.loopMode == SfzLoopMode::one_shot ); + REQUIRE(region.loopMode == SfzLoopMode::one_shot); region.parseOpcode({ "loop_mode", "loop_continuous" }); - REQUIRE( region.loopMode == SfzLoopMode::loop_continuous ); + REQUIRE(region.loopMode == SfzLoopMode::loop_continuous); region.parseOpcode({ "loop_mode", "loop_sustain" }); - REQUIRE( region.loopMode == SfzLoopMode::loop_sustain ); + REQUIRE(region.loopMode == SfzLoopMode::loop_sustain); } SECTION("loopmode") { - REQUIRE( region.loopMode == SfzLoopMode::no_loop ); + REQUIRE(region.loopMode == SfzLoopMode::no_loop); region.parseOpcode({ "loopmode", "no_loop" }); - REQUIRE( region.loopMode == SfzLoopMode::no_loop ); + REQUIRE(region.loopMode == SfzLoopMode::no_loop); region.parseOpcode({ "loopmode", "one_shot" }); - REQUIRE( region.loopMode == SfzLoopMode::one_shot ); + REQUIRE(region.loopMode == SfzLoopMode::one_shot); region.parseOpcode({ "loopmode", "loop_continuous" }); - REQUIRE( region.loopMode == SfzLoopMode::loop_continuous ); + REQUIRE(region.loopMode == SfzLoopMode::loop_continuous); region.parseOpcode({ "loopmode", "loop_sustain" }); - REQUIRE( region.loopMode == SfzLoopMode::loop_sustain ); + REQUIRE(region.loopMode == SfzLoopMode::loop_sustain); } SECTION("loop_end") { - REQUIRE( region.loopRange == Range(0, 4294967295) ); + REQUIRE(region.loopRange == Range(0, 4294967295)); region.parseOpcode({ "loop_end", "184" }); - REQUIRE( region.loopRange == Range(0, 184) ); + REQUIRE(region.loopRange == Range(0, 184)); region.parseOpcode({ "loop_end", "-1" }); - REQUIRE( region.loopRange == Range(0, 0) ); + REQUIRE(region.loopRange == Range(0, 0)); } SECTION("loop_start") { region.parseOpcode({ "loop_start", "184" }); - REQUIRE( region.loopRange == Range(184, 4294967295) ); + REQUIRE(region.loopRange == Range(184, 4294967295)); region.parseOpcode({ "loop_start", "-1" }); - REQUIRE( region.loopRange == Range(0, 4294967295) ); + REQUIRE(region.loopRange == Range(0, 4294967295)); } SECTION("loopend") { - REQUIRE( region.loopRange == Range(0, 4294967295) ); + REQUIRE(region.loopRange == Range(0, 4294967295)); region.parseOpcode({ "loopend", "184" }); - REQUIRE( region.loopRange == Range(0, 184) ); + REQUIRE(region.loopRange == Range(0, 184)); region.parseOpcode({ "loopend", "-1" }); - REQUIRE( region.loopRange == Range(0, 0) ); + REQUIRE(region.loopRange == Range(0, 0)); } SECTION("loopstart") { region.parseOpcode({ "loopstart", "184" }); - REQUIRE( region.loopRange == Range(184, 4294967295) ); + REQUIRE(region.loopRange == Range(184, 4294967295)); region.parseOpcode({ "loopstart", "-1" }); - REQUIRE( region.loopRange == Range(0, 4294967295) ); + REQUIRE(region.loopRange == Range(0, 4294967295)); } SECTION("group") { - REQUIRE( region.group == 0 ); + REQUIRE(region.group == 0); region.parseOpcode({ "group", "5" }); - REQUIRE( region.group == 5 ); + REQUIRE(region.group == 5); region.parseOpcode({ "group", "-1" }); - REQUIRE( region.group == 0 ); + REQUIRE(region.group == 0); } SECTION("off_by") { - REQUIRE( !region.offBy ); + REQUIRE(!region.offBy); region.parseOpcode({ "off_by", "5" }); - REQUIRE( region.offBy ); - REQUIRE( region.offBy == 5 ); + REQUIRE(region.offBy); + REQUIRE(region.offBy == 5); region.parseOpcode({ "off_by", "-1" }); - REQUIRE( region.offBy ); - REQUIRE( region.offBy == 0 ); + REQUIRE(region.offBy); + REQUIRE(region.offBy == 0); } SECTION("off_mode") { - REQUIRE( region.offMode == SfzOffMode::fast ); + REQUIRE(region.offMode == SfzOffMode::fast); region.parseOpcode({ "off_mode", "fast" }); - REQUIRE( region.offMode == SfzOffMode::fast ); + REQUIRE(region.offMode == SfzOffMode::fast); region.parseOpcode({ "off_mode", "normal" }); - REQUIRE( region.offMode == SfzOffMode::normal ); + REQUIRE(region.offMode == SfzOffMode::normal); } SECTION("lokey, hikey, and key") { - REQUIRE( region.keyRange == Range(0, 127) ); + REQUIRE(region.keyRange == Range(0, 127)); region.parseOpcode({ "lokey", "37" }); - REQUIRE( region.keyRange == Range(37, 127) ); + REQUIRE(region.keyRange == Range(37, 127)); region.parseOpcode({ "lokey", "c4" }); - REQUIRE( region.keyRange == Range(60, 127) ); + REQUIRE(region.keyRange == Range(60, 127)); region.parseOpcode({ "lokey", "128" }); - REQUIRE( region.keyRange == Range(127, 127) ); + REQUIRE(region.keyRange == Range(127, 127)); region.parseOpcode({ "lokey", "-3" }); - REQUIRE( region.keyRange == Range(0, 127) ); + REQUIRE(region.keyRange == Range(0, 127)); region.parseOpcode({ "hikey", "65" }); - REQUIRE( region.keyRange == Range(0, 65) ); + REQUIRE(region.keyRange == Range(0, 65)); region.parseOpcode({ "hikey", "c4" }); - REQUIRE( region.keyRange == Range(0, 60) ); + REQUIRE(region.keyRange == Range(0, 60)); region.parseOpcode({ "hikey", "-1" }); - REQUIRE( region.keyRange == Range(0, 0) ); + REQUIRE(region.keyRange == Range(0, 0)); region.parseOpcode({ "hikey", "128" }); - REQUIRE( region.keyRange == Range(0, 127) ); + REQUIRE(region.keyRange == Range(0, 127)); region.parseOpcode({ "key", "26" }); - REQUIRE( region.keyRange == Range(26, 26) ); - REQUIRE( region.pitchKeycenter == 26 ); + REQUIRE(region.keyRange == Range(26, 26)); + REQUIRE(region.pitchKeycenter == 26); region.parseOpcode({ "key", "-26" }); - REQUIRE( region.keyRange == Range(0, 0) ); - REQUIRE( region.pitchKeycenter == 0 ); + REQUIRE(region.keyRange == Range(0, 0)); + REQUIRE(region.pitchKeycenter == 0); region.parseOpcode({ "key", "234" }); - REQUIRE( region.keyRange == Range(127, 127) ); - REQUIRE( region.pitchKeycenter == 127 ); + REQUIRE(region.keyRange == Range(127, 127)); + REQUIRE(region.pitchKeycenter == 127); region.parseOpcode({ "key", "c4" }); - REQUIRE( region.keyRange == Range(60, 60) ); - REQUIRE( region.pitchKeycenter == 60 ); + REQUIRE(region.keyRange == Range(60, 60)); + REQUIRE(region.pitchKeycenter == 60); } SECTION("lovel, hivel") { - REQUIRE( region.velocityRange == Range(0, 127) ); + REQUIRE(region.velocityRange == Range(0, 127)); region.parseOpcode({ "lovel", "37" }); - REQUIRE( region.velocityRange == Range(37, 127) ); + REQUIRE(region.velocityRange == Range(37, 127)); region.parseOpcode({ "lovel", "128" }); - REQUIRE( region.velocityRange == Range(127, 127) ); + REQUIRE(region.velocityRange == Range(127, 127)); region.parseOpcode({ "lovel", "-3" }); - REQUIRE( region.velocityRange == Range(0, 127) ); + REQUIRE(region.velocityRange == Range(0, 127)); region.parseOpcode({ "hivel", "65" }); - REQUIRE( region.velocityRange == Range(0, 65) ); + REQUIRE(region.velocityRange == Range(0, 65)); region.parseOpcode({ "hivel", "-1" }); - REQUIRE( region.velocityRange == Range(0, 0) ); + REQUIRE(region.velocityRange == Range(0, 0)); region.parseOpcode({ "hivel", "128" }); - REQUIRE( region.velocityRange == Range(0, 127) ); + REQUIRE(region.velocityRange == Range(0, 127)); } SECTION("lochan, hichan") { - REQUIRE( region.channelRange == Range(1, 16) ); + REQUIRE(region.channelRange == Range(1, 16)); region.parseOpcode({ "lochan", "4" }); - REQUIRE( region.channelRange == Range(4, 16) ); + REQUIRE(region.channelRange == Range(4, 16)); region.parseOpcode({ "lochan", "128" }); - REQUIRE( region.channelRange == Range(16, 16) ); + REQUIRE(region.channelRange == Range(16, 16)); region.parseOpcode({ "lochan", "-3" }); - REQUIRE( region.channelRange == Range(1, 16) ); + REQUIRE(region.channelRange == Range(1, 16)); region.parseOpcode({ "hichan", "13" }); - REQUIRE( region.channelRange == Range(1, 13) ); + REQUIRE(region.channelRange == Range(1, 13)); region.parseOpcode({ "hichan", "-1" }); - REQUIRE( region.channelRange == Range(1, 1) ); + REQUIRE(region.channelRange == Range(1, 1)); region.parseOpcode({ "hichan", "128" }); - REQUIRE( region.channelRange == Range(1, 16) ); + REQUIRE(region.channelRange == Range(1, 16)); } SECTION("lobend, hibend") { - REQUIRE( region.bendRange == Range(-8192, 8192) ); + REQUIRE(region.bendRange == Range(-8192, 8192)); region.parseOpcode({ "lobend", "4" }); - REQUIRE( region.bendRange == Range(4, 8192) ); + REQUIRE(region.bendRange == Range(4, 8192)); region.parseOpcode({ "lobend", "-128" }); - REQUIRE( region.bendRange == Range(-128, 8192) ); + REQUIRE(region.bendRange == Range(-128, 8192)); region.parseOpcode({ "lobend", "-10000" }); - REQUIRE( region.bendRange == Range(-8192, 8192) ); + REQUIRE(region.bendRange == Range(-8192, 8192)); region.parseOpcode({ "hibend", "13" }); - REQUIRE( region.bendRange == Range(-8192, 13) ); + REQUIRE(region.bendRange == Range(-8192, 13)); region.parseOpcode({ "hibend", "-1" }); - REQUIRE( region.bendRange == Range(-8192, -1) ); + REQUIRE(region.bendRange == Range(-8192, -1)); region.parseOpcode({ "hibend", "10000" }); - REQUIRE( region.bendRange == Range(-8192, 8192) ); + REQUIRE(region.bendRange == Range(-8192, 8192)); } SECTION("locc, hicc") { - REQUIRE( region.ccConditions.getWithDefault(0) == Range(0, 127) ); - REQUIRE( region.ccConditions[127] == Range(0, 127) ); + REQUIRE(region.ccConditions.getWithDefault(0) == Range(0, 127)); + REQUIRE(region.ccConditions[127] == Range(0, 127)); region.parseOpcode({ "locc6", "4" }); - REQUIRE( region.ccConditions[6] == Range(4, 127) ); + REQUIRE(region.ccConditions[6] == Range(4, 127)); region.parseOpcode({ "locc12", "-128" }); - REQUIRE( region.ccConditions[12] == Range(0, 127) ); + REQUIRE(region.ccConditions[12] == Range(0, 127)); region.parseOpcode({ "hicc65", "39" }); - REQUIRE( region.ccConditions[65] == Range(0, 39) ); + REQUIRE(region.ccConditions[65] == Range(0, 39)); region.parseOpcode({ "hicc127", "135" }); - REQUIRE( region.ccConditions[127] == Range(0, 127) ); + REQUIRE(region.ccConditions[127] == Range(0, 127)); } SECTION("sw_lokey, sw_hikey") { - REQUIRE( region.keyswitchRange == Range(0, 127) ); + REQUIRE(region.keyswitchRange == Range(0, 127)); region.parseOpcode({ "sw_lokey", "4" }); - REQUIRE( region.keyswitchRange == Range(4, 127) ); + REQUIRE(region.keyswitchRange == Range(4, 127)); region.parseOpcode({ "sw_lokey", "128" }); - REQUIRE( region.keyswitchRange == Range(127, 127) ); + REQUIRE(region.keyswitchRange == Range(127, 127)); region.parseOpcode({ "sw_lokey", "0" }); - REQUIRE( region.keyswitchRange == Range(0, 127) ); + REQUIRE(region.keyswitchRange == Range(0, 127)); region.parseOpcode({ "sw_hikey", "39" }); - REQUIRE( region.keyswitchRange == Range(0, 39) ); + REQUIRE(region.keyswitchRange == Range(0, 39)); region.parseOpcode({ "sw_hikey", "135" }); - REQUIRE( region.keyswitchRange == Range(0, 127) ); + REQUIRE(region.keyswitchRange == Range(0, 127)); region.parseOpcode({ "sw_hikey", "-1" }); - REQUIRE( region.keyswitchRange == Range(0, 0) ); + REQUIRE(region.keyswitchRange == Range(0, 0)); } SECTION("sw_last") { - REQUIRE( !region.keyswitch ); + REQUIRE(!region.keyswitch); region.parseOpcode({ "sw_last", "4" }); - REQUIRE( region.keyswitch ); - REQUIRE( *region.keyswitch == 4 ); + REQUIRE(region.keyswitch); + REQUIRE(*region.keyswitch == 4); region.parseOpcode({ "sw_last", "128" }); - REQUIRE( region.keyswitch ); - REQUIRE( *region.keyswitch == 127 ); + REQUIRE(region.keyswitch); + REQUIRE(*region.keyswitch == 127); region.parseOpcode({ "sw_last", "-1" }); - REQUIRE( region.keyswitch ); - REQUIRE( *region.keyswitch == 0 ); + REQUIRE(region.keyswitch); + REQUIRE(*region.keyswitch == 0); } SECTION("sw_up") { - REQUIRE( !region.keyswitchUp ); + REQUIRE(!region.keyswitchUp); region.parseOpcode({ "sw_up", "4" }); - REQUIRE( region.keyswitchUp ); - REQUIRE( *region.keyswitchUp == 4 ); + REQUIRE(region.keyswitchUp); + REQUIRE(*region.keyswitchUp == 4); region.parseOpcode({ "sw_up", "128" }); - REQUIRE( region.keyswitchUp ); - REQUIRE( *region.keyswitchUp == 127 ); + REQUIRE(region.keyswitchUp); + REQUIRE(*region.keyswitchUp == 127); region.parseOpcode({ "sw_up", "-1" }); - REQUIRE( region.keyswitchUp ); - REQUIRE( *region.keyswitchUp == 0 ); + REQUIRE(region.keyswitchUp); + REQUIRE(*region.keyswitchUp == 0); } SECTION("sw_down") { - REQUIRE( !region.keyswitchDown ); + REQUIRE(!region.keyswitchDown); region.parseOpcode({ "sw_down", "4" }); - REQUIRE( region.keyswitchDown ); - REQUIRE( *region.keyswitchDown == 4 ); + REQUIRE(region.keyswitchDown); + REQUIRE(*region.keyswitchDown == 4); region.parseOpcode({ "sw_down", "128" }); - REQUIRE( region.keyswitchDown ); - REQUIRE( *region.keyswitchDown == 127 ); + REQUIRE(region.keyswitchDown); + REQUIRE(*region.keyswitchDown == 127); region.parseOpcode({ "sw_down", "-1" }); - REQUIRE( region.keyswitchDown ); - REQUIRE( *region.keyswitchDown == 0 ); + REQUIRE(region.keyswitchDown); + REQUIRE(*region.keyswitchDown == 0); } SECTION("sw_previous") { - REQUIRE( !region.previousNote ); + REQUIRE(!region.previousNote); region.parseOpcode({ "sw_previous", "4" }); - REQUIRE( region.previousNote ); - REQUIRE( *region.previousNote == 4 ); + REQUIRE(region.previousNote); + REQUIRE(*region.previousNote == 4); region.parseOpcode({ "sw_previous", "128" }); - REQUIRE( region.previousNote ); - REQUIRE( *region.previousNote == 127 ); + REQUIRE(region.previousNote); + REQUIRE(*region.previousNote == 127); region.parseOpcode({ "sw_previous", "-1" }); - REQUIRE( region.previousNote ); - REQUIRE( *region.previousNote == 0 ); + REQUIRE(region.previousNote); + REQUIRE(*region.previousNote == 0); } SECTION("sw_vel") { - REQUIRE( region.velocityOverride == SfzVelocityOverride::current ); + REQUIRE(region.velocityOverride == SfzVelocityOverride::current); region.parseOpcode({ "sw_vel", "current" }); - REQUIRE( region.velocityOverride == SfzVelocityOverride::current ); + REQUIRE(region.velocityOverride == SfzVelocityOverride::current); region.parseOpcode({ "sw_vel", "previous" }); - REQUIRE( region.velocityOverride == SfzVelocityOverride::previous ); + REQUIRE(region.velocityOverride == SfzVelocityOverride::previous); } SECTION("lochanaft, hichanaft") { - REQUIRE( region.aftertouchRange == Range(0, 127) ); + REQUIRE(region.aftertouchRange == Range(0, 127)); region.parseOpcode({ "lochanaft", "4" }); - REQUIRE( region.aftertouchRange == Range(4, 127) ); + REQUIRE(region.aftertouchRange == Range(4, 127)); region.parseOpcode({ "lochanaft", "128" }); - REQUIRE( region.aftertouchRange == Range(127, 127) ); + REQUIRE(region.aftertouchRange == Range(127, 127)); region.parseOpcode({ "lochanaft", "0" }); - REQUIRE( region.aftertouchRange == Range(0, 127) ); + REQUIRE(region.aftertouchRange == Range(0, 127)); region.parseOpcode({ "hichanaft", "39" }); - REQUIRE( region.aftertouchRange == Range(0, 39) ); + REQUIRE(region.aftertouchRange == Range(0, 39)); region.parseOpcode({ "hichanaft", "135" }); - REQUIRE( region.aftertouchRange == Range(0, 127) ); + REQUIRE(region.aftertouchRange == Range(0, 127)); region.parseOpcode({ "hichanaft", "-1" }); - REQUIRE( region.aftertouchRange == Range(0, 0) ); + REQUIRE(region.aftertouchRange == Range(0, 0)); } SECTION("lobpm, hibpm") { - REQUIRE( region.bpmRange == Range(0, 500) ); + REQUIRE(region.bpmRange == Range(0, 500)); region.parseOpcode({ "lobpm", "47.5" }); - REQUIRE( region.bpmRange == Range(47.5, 500) ); + REQUIRE(region.bpmRange == Range(47.5, 500)); region.parseOpcode({ "lobpm", "594" }); - REQUIRE( region.bpmRange == Range(500, 500) ); + REQUIRE(region.bpmRange == Range(500, 500)); region.parseOpcode({ "lobpm", "0" }); - REQUIRE( region.bpmRange == Range(0, 500) ); + REQUIRE(region.bpmRange == Range(0, 500)); region.parseOpcode({ "hibpm", "78" }); - REQUIRE( region.bpmRange == Range(0, 78) ); + REQUIRE(region.bpmRange == Range(0, 78)); region.parseOpcode({ "hibpm", "895.4" }); - REQUIRE( region.bpmRange == Range(0, 500) ); + REQUIRE(region.bpmRange == Range(0, 500)); region.parseOpcode({ "hibpm", "-1" }); - REQUIRE( region.bpmRange == Range(0, 0) ); + REQUIRE(region.bpmRange == Range(0, 0)); } SECTION("lorand, hirand") { - REQUIRE( region.randRange == Range(0, 1) ); + REQUIRE(region.randRange == Range(0, 1)); region.parseOpcode({ "lorand", "0.5" }); - REQUIRE( region.randRange == Range(0.5, 1) ); + REQUIRE(region.randRange == Range(0.5, 1)); region.parseOpcode({ "lorand", "4" }); - REQUIRE( region.randRange == Range(1, 1) ); + REQUIRE(region.randRange == Range(1, 1)); region.parseOpcode({ "lorand", "0" }); - REQUIRE( region.randRange == Range(0, 1) ); + REQUIRE(region.randRange == Range(0, 1)); region.parseOpcode({ "hirand", "39" }); - REQUIRE( region.randRange == Range(0, 1) ); + REQUIRE(region.randRange == Range(0, 1)); region.parseOpcode({ "hirand", "0.7" }); - REQUIRE( region.randRange == Range(0, 0.7f) ); + REQUIRE(region.randRange == Range(0, 0.7f)); region.parseOpcode({ "hirand", "-1" }); - REQUIRE( region.randRange == Range(0, 0) ); + REQUIRE(region.randRange == Range(0, 0)); } SECTION("seq_length") { - REQUIRE( region.sequenceLength == 1 ); + REQUIRE(region.sequenceLength == 1); region.parseOpcode({ "seq_length", "89" }); - REQUIRE( region.sequenceLength == 89 ); + REQUIRE(region.sequenceLength == 89); region.parseOpcode({ "seq_length", "189" }); - REQUIRE( region.sequenceLength == 100 ); + REQUIRE(region.sequenceLength == 100); region.parseOpcode({ "seq_length", "-1" }); - REQUIRE( region.sequenceLength == 1 ); + REQUIRE(region.sequenceLength == 1); } SECTION("seq_position") { - REQUIRE( region.sequencePosition == 1 ); + REQUIRE(region.sequencePosition == 1); region.parseOpcode({ "seq_position", "89" }); - REQUIRE( region.sequencePosition == 89 ); + REQUIRE(region.sequencePosition == 89); region.parseOpcode({ "seq_position", "189" }); - REQUIRE( region.sequencePosition == 100 ); + REQUIRE(region.sequencePosition == 100); region.parseOpcode({ "seq_position", "-1" }); - REQUIRE( region.sequencePosition == 1 ); + REQUIRE(region.sequencePosition == 1); } SECTION("trigger") { - REQUIRE( region.trigger == SfzTrigger::attack ); + REQUIRE(region.trigger == SfzTrigger::attack); region.parseOpcode({ "trigger", "attack" }); - REQUIRE( region.trigger == SfzTrigger::attack ); + REQUIRE(region.trigger == SfzTrigger::attack); region.parseOpcode({ "trigger", "release" }); - REQUIRE( region.trigger == SfzTrigger::release ); + REQUIRE(region.trigger == SfzTrigger::release); region.parseOpcode({ "trigger", "first" }); - REQUIRE( region.trigger == SfzTrigger::first ); + REQUIRE(region.trigger == SfzTrigger::first); region.parseOpcode({ "trigger", "legato" }); - REQUIRE( region.trigger == SfzTrigger::legato ); + REQUIRE(region.trigger == SfzTrigger::legato); } SECTION("on_locc, on_hicc") { - for (int ccIdx = 1; ccIdx < 128; ++ccIdx) - { - REQUIRE( !region.ccTriggers.contains(ccIdx) ); + for (int ccIdx = 1; ccIdx < 128; ++ccIdx) { + REQUIRE(!region.ccTriggers.contains(ccIdx)); } region.parseOpcode({ "on_locc45", "15" }); - REQUIRE( region.ccTriggers.contains(45) ); - REQUIRE( region.ccTriggers[45] == Range(15, 127) ); + REQUIRE(region.ccTriggers.contains(45)); + REQUIRE(region.ccTriggers[45] == Range(15, 127)); region.parseOpcode({ "on_hicc4", "47" }); - REQUIRE( region.ccTriggers.contains(45) ); - REQUIRE( region.ccTriggers[4] == Range(0, 47) ); + REQUIRE(region.ccTriggers.contains(45)); + REQUIRE(region.ccTriggers[4] == Range(0, 47)); } SECTION("volume") { - REQUIRE( region.volume == 0.0f ); + REQUIRE(region.volume == 0.0f); region.parseOpcode({ "volume", "4.2" }); - REQUIRE( region.volume == 4.2f ); + REQUIRE(region.volume == 4.2f); region.parseOpcode({ "volume", "-4.2" }); - REQUIRE( region.volume == -4.2f ); + REQUIRE(region.volume == -4.2f); region.parseOpcode({ "volume", "-123" }); - REQUIRE( region.volume == -123.0f ); + REQUIRE(region.volume == -123.0f); region.parseOpcode({ "volume", "-185" }); - REQUIRE( region.volume == -144.0f ); + REQUIRE(region.volume == -144.0f); region.parseOpcode({ "volume", "19" }); - REQUIRE( region.volume == 6.0f ); + REQUIRE(region.volume == 6.0f); } SECTION("pan") { - REQUIRE( region.pan == 0.0f ); + REQUIRE(region.pan == 0.0f); region.parseOpcode({ "pan", "4.2" }); - REQUIRE( region.pan == 4.2f ); + REQUIRE(region.pan == 4.2f); region.parseOpcode({ "pan", "-4.2" }); - REQUIRE( region.pan == -4.2f ); + REQUIRE(region.pan == -4.2f); region.parseOpcode({ "pan", "-123" }); - REQUIRE( region.pan == -100.0f ); + REQUIRE(region.pan == -100.0f); region.parseOpcode({ "pan", "132" }); - REQUIRE( region.pan == 100.0f ); + REQUIRE(region.pan == 100.0f); } SECTION("pan_oncc") { - REQUIRE( !region.panCC ); + REQUIRE(!region.panCC); region.parseOpcode({ "pan_oncc45", "4.2" }); - REQUIRE( region.panCC ); - REQUIRE( region.panCC->first == 45 ); - REQUIRE( region.panCC->second == 4.2f ); + REQUIRE(region.panCC); + REQUIRE(region.panCC->first == 45); + REQUIRE(region.panCC->second == 4.2f); } SECTION("width") { - REQUIRE( region.width == 0.0f ); + REQUIRE(region.width == 0.0f); region.parseOpcode({ "width", "4.2" }); - REQUIRE( region.width == 4.2f ); + REQUIRE(region.width == 4.2f); region.parseOpcode({ "width", "-4.2" }); - REQUIRE( region.width == -4.2f ); + REQUIRE(region.width == -4.2f); region.parseOpcode({ "width", "-123" }); - REQUIRE( region.width == -100.0f ); + REQUIRE(region.width == -100.0f); region.parseOpcode({ "width", "132" }); - REQUIRE( region.width == 100.0f ); + REQUIRE(region.width == 100.0f); } SECTION("width_oncc") { - REQUIRE( !region.widthCC ); + REQUIRE(!region.widthCC); region.parseOpcode({ "width_oncc45", "4.2" }); - REQUIRE( region.widthCC ); - REQUIRE( region.widthCC->first == 45 ); - REQUIRE( region.widthCC->second == 4.2f ); + REQUIRE(region.widthCC); + REQUIRE(region.widthCC->first == 45); + REQUIRE(region.widthCC->second == 4.2f); } SECTION("position") { - REQUIRE( region.position == 0.0f ); + REQUIRE(region.position == 0.0f); region.parseOpcode({ "position", "4.2" }); - REQUIRE( region.position == 4.2f ); + REQUIRE(region.position == 4.2f); region.parseOpcode({ "position", "-4.2" }); - REQUIRE( region.position == -4.2f ); + REQUIRE(region.position == -4.2f); region.parseOpcode({ "position", "-123" }); - REQUIRE( region.position == -100.0f ); + REQUIRE(region.position == -100.0f); region.parseOpcode({ "position", "132" }); - REQUIRE( region.position == 100.0f ); + REQUIRE(region.position == 100.0f); } SECTION("position_oncc") { - REQUIRE( !region.positionCC ); + REQUIRE(!region.positionCC); region.parseOpcode({ "position_oncc45", "4.2" }); - REQUIRE( region.positionCC ); - REQUIRE( region.positionCC->first == 45 ); - REQUIRE( region.positionCC->second == 4.2f ); + REQUIRE(region.positionCC); + REQUIRE(region.positionCC->first == 45); + REQUIRE(region.positionCC->second == 4.2f); } SECTION("amp_keycenter") { - REQUIRE( region.ampKeycenter == 60 ); + REQUIRE(region.ampKeycenter == 60); region.parseOpcode({ "amp_keycenter", "40" }); - REQUIRE( region.ampKeycenter == 40 ); + REQUIRE(region.ampKeycenter == 40); region.parseOpcode({ "amp_keycenter", "-1" }); - REQUIRE( region.ampKeycenter == 0 ); + REQUIRE(region.ampKeycenter == 0); region.parseOpcode({ "amp_keycenter", "132" }); - REQUIRE( region.ampKeycenter == 127 ); + REQUIRE(region.ampKeycenter == 127); } SECTION("amp_keytrack") { - REQUIRE( region.ampKeytrack == 0.0f ); + REQUIRE(region.ampKeytrack == 0.0f); region.parseOpcode({ "amp_keytrack", "4.2" }); - REQUIRE( region.ampKeytrack == 4.2f ); + REQUIRE(region.ampKeytrack == 4.2f); region.parseOpcode({ "amp_keytrack", "-4.2" }); - REQUIRE( region.ampKeytrack == -4.2f ); + REQUIRE(region.ampKeytrack == -4.2f); region.parseOpcode({ "amp_keytrack", "-123" }); - REQUIRE( region.ampKeytrack == -96.0f ); + REQUIRE(region.ampKeytrack == -96.0f); region.parseOpcode({ "amp_keytrack", "132" }); - REQUIRE( region.ampKeytrack == 12.0f ); + REQUIRE(region.ampKeytrack == 12.0f); } SECTION("amp_veltrack") { - REQUIRE( region.ampVeltrack == 100.0f ); + REQUIRE(region.ampVeltrack == 100.0f); region.parseOpcode({ "amp_veltrack", "4.2" }); - REQUIRE( region.ampVeltrack == 4.2f ); + REQUIRE(region.ampVeltrack == 4.2f); region.parseOpcode({ "amp_veltrack", "-4.2" }); - REQUIRE( region.ampVeltrack == -4.2f ); + REQUIRE(region.ampVeltrack == -4.2f); region.parseOpcode({ "amp_veltrack", "-123" }); - REQUIRE( region.ampVeltrack == -100.0f ); + REQUIRE(region.ampVeltrack == -100.0f); region.parseOpcode({ "amp_veltrack", "132" }); - REQUIRE( region.ampVeltrack == 100.0f ); + REQUIRE(region.ampVeltrack == 100.0f); } SECTION("amp_random") { - REQUIRE( region.ampRandom == 0.0f ); + REQUIRE(region.ampRandom == 0.0f); region.parseOpcode({ "amp_random", "4.2" }); - REQUIRE( region.ampRandom == 4.2f ); + REQUIRE(region.ampRandom == 4.2f); region.parseOpcode({ "amp_random", "-4.2" }); - REQUIRE( region.ampRandom == 0.0f ); + REQUIRE(region.ampRandom == 0.0f); region.parseOpcode({ "amp_random", "132" }); - REQUIRE( region.ampRandom == 24.0f ); + REQUIRE(region.ampRandom == 24.0f); } SECTION("amp_velcurve") { region.parseOpcode({ "amp_velcurve_6", "0.4" }); - REQUIRE( region.velocityPoints.back() == std::make_pair(6, 0.4f) ); + REQUIRE(region.velocityPoints.back() == std::make_pair(6, 0.4f)); region.parseOpcode({ "amp_velcurve_127", "-1.0" }); - REQUIRE( region.velocityPoints.back() == std::make_pair(127, 0.0f) ); + REQUIRE(region.velocityPoints.back() == std::make_pair(127, 0.0f)); } SECTION("xfin_lokey, xfin_hikey") { REQUIRE(region.crossfadeKeyInRange == Range(0, 0)); - region.parseOpcode({"xfin_lokey", "4"}); + region.parseOpcode({ "xfin_lokey", "4" }); REQUIRE(region.crossfadeKeyInRange == Range(4, 4)); - region.parseOpcode({"xfin_lokey", "128"}); + region.parseOpcode({ "xfin_lokey", "128" }); REQUIRE(region.crossfadeKeyInRange == Range(127, 127)); - region.parseOpcode({"xfin_lokey", "59"}); + region.parseOpcode({ "xfin_lokey", "59" }); REQUIRE(region.crossfadeKeyInRange == Range(59, 127)); - region.parseOpcode({"xfin_hikey", "59"}); + region.parseOpcode({ "xfin_hikey", "59" }); REQUIRE(region.crossfadeKeyInRange == Range(59, 59)); - region.parseOpcode({"xfin_hikey", "128"}); + region.parseOpcode({ "xfin_hikey", "128" }); REQUIRE(region.crossfadeKeyInRange == Range(59, 127)); - region.parseOpcode({"xfin_hikey", "0"}); + region.parseOpcode({ "xfin_hikey", "0" }); REQUIRE(region.crossfadeKeyInRange == Range(0, 0)); - region.parseOpcode({"xfin_hikey", "-1"}); + region.parseOpcode({ "xfin_hikey", "-1" }); REQUIRE(region.crossfadeKeyInRange == Range(0, 0)); } SECTION("xfin_lovel, xfin_hivel") { REQUIRE(region.crossfadeVelInRange == Range(0, 0)); - region.parseOpcode({"xfin_lovel", "4"}); + region.parseOpcode({ "xfin_lovel", "4" }); REQUIRE(region.crossfadeVelInRange == Range(4, 4)); - region.parseOpcode({"xfin_lovel", "128"}); + region.parseOpcode({ "xfin_lovel", "128" }); REQUIRE(region.crossfadeVelInRange == Range(127, 127)); - region.parseOpcode({"xfin_lovel", "59"}); + region.parseOpcode({ "xfin_lovel", "59" }); REQUIRE(region.crossfadeVelInRange == Range(59, 127)); - region.parseOpcode({"xfin_hivel", "59"}); + region.parseOpcode({ "xfin_hivel", "59" }); REQUIRE(region.crossfadeVelInRange == Range(59, 59)); - region.parseOpcode({"xfin_hivel", "128"}); + region.parseOpcode({ "xfin_hivel", "128" }); REQUIRE(region.crossfadeVelInRange == Range(59, 127)); - region.parseOpcode({"xfin_hivel", "0"}); + region.parseOpcode({ "xfin_hivel", "0" }); REQUIRE(region.crossfadeVelInRange == Range(0, 0)); - region.parseOpcode({"xfin_hivel", "-1"}); + region.parseOpcode({ "xfin_hivel", "-1" }); REQUIRE(region.crossfadeVelInRange == Range(0, 0)); } SECTION("xfout_lokey, xfout_hikey") { REQUIRE(region.crossfadeKeyOutRange == Range(127, 127)); - region.parseOpcode({"xfout_lokey", "4"}); + region.parseOpcode({ "xfout_lokey", "4" }); REQUIRE(region.crossfadeKeyOutRange == Range(4, 127)); - region.parseOpcode({"xfout_lokey", "128"}); + region.parseOpcode({ "xfout_lokey", "128" }); REQUIRE(region.crossfadeKeyOutRange == Range(127, 127)); - region.parseOpcode({"xfout_lokey", "59"}); + region.parseOpcode({ "xfout_lokey", "59" }); REQUIRE(region.crossfadeKeyOutRange == Range(59, 127)); - region.parseOpcode({"xfout_hikey", "59"}); + region.parseOpcode({ "xfout_hikey", "59" }); REQUIRE(region.crossfadeKeyOutRange == Range(59, 59)); - region.parseOpcode({"xfout_hikey", "128"}); + region.parseOpcode({ "xfout_hikey", "128" }); REQUIRE(region.crossfadeKeyOutRange == Range(59, 127)); - region.parseOpcode({"xfout_hikey", "0"}); + region.parseOpcode({ "xfout_hikey", "0" }); REQUIRE(region.crossfadeKeyOutRange == Range(0, 0)); - region.parseOpcode({"xfout_hikey", "-1"}); + region.parseOpcode({ "xfout_hikey", "-1" }); REQUIRE(region.crossfadeKeyOutRange == Range(0, 0)); } SECTION("xfout_lovel, xfout_hivel") { REQUIRE(region.crossfadeVelOutRange == Range(127, 127)); - region.parseOpcode({"xfout_lovel", "4"}); + region.parseOpcode({ "xfout_lovel", "4" }); REQUIRE(region.crossfadeVelOutRange == Range(4, 127)); - region.parseOpcode({"xfout_lovel", "128"}); + region.parseOpcode({ "xfout_lovel", "128" }); REQUIRE(region.crossfadeVelOutRange == Range(127, 127)); - region.parseOpcode({"xfout_lovel", "59"}); + region.parseOpcode({ "xfout_lovel", "59" }); REQUIRE(region.crossfadeVelOutRange == Range(59, 127)); - region.parseOpcode({"xfout_hivel", "59"}); + region.parseOpcode({ "xfout_hivel", "59" }); REQUIRE(region.crossfadeVelOutRange == Range(59, 59)); - region.parseOpcode({"xfout_hivel", "128"}); + region.parseOpcode({ "xfout_hivel", "128" }); REQUIRE(region.crossfadeVelOutRange == Range(59, 127)); - region.parseOpcode({"xfout_hivel", "0"}); + region.parseOpcode({ "xfout_hivel", "0" }); REQUIRE(region.crossfadeVelOutRange == Range(0, 0)); - region.parseOpcode({"xfout_hivel", "-1"}); + region.parseOpcode({ "xfout_hivel", "-1" }); REQUIRE(region.crossfadeVelOutRange == Range(0, 0)); } SECTION("xf_keycurve") { REQUIRE(region.crossfadeKeyCurve == SfzCrossfadeCurve::power); - region.parseOpcode({"xf_keycurve", "gain"}); + region.parseOpcode({ "xf_keycurve", "gain" }); REQUIRE(region.crossfadeKeyCurve == SfzCrossfadeCurve::gain); - region.parseOpcode({"xf_keycurve", "power"}); + region.parseOpcode({ "xf_keycurve", "power" }); REQUIRE(region.crossfadeKeyCurve == SfzCrossfadeCurve::power); - region.parseOpcode({"xf_keycurve", "something"}); + region.parseOpcode({ "xf_keycurve", "something" }); REQUIRE(region.crossfadeKeyCurve == SfzCrossfadeCurve::power); - region.parseOpcode({"xf_keycurve", "gain"}); - region.parseOpcode({"xf_keycurve", "something"}); + region.parseOpcode({ "xf_keycurve", "gain" }); + region.parseOpcode({ "xf_keycurve", "something" }); REQUIRE(region.crossfadeKeyCurve == SfzCrossfadeCurve::gain); } SECTION("xf_velcurve") { REQUIRE(region.crossfadeVelCurve == SfzCrossfadeCurve::power); - region.parseOpcode({"xf_velcurve", "gain"}); + region.parseOpcode({ "xf_velcurve", "gain" }); REQUIRE(region.crossfadeVelCurve == SfzCrossfadeCurve::gain); - region.parseOpcode({"xf_velcurve", "power"}); + region.parseOpcode({ "xf_velcurve", "power" }); REQUIRE(region.crossfadeVelCurve == SfzCrossfadeCurve::power); - region.parseOpcode({"xf_velcurve", "something"}); + region.parseOpcode({ "xf_velcurve", "something" }); REQUIRE(region.crossfadeVelCurve == SfzCrossfadeCurve::power); - region.parseOpcode({"xf_velcurve", "gain"}); - region.parseOpcode({"xf_velcurve", "something"}); + region.parseOpcode({ "xf_velcurve", "gain" }); + region.parseOpcode({ "xf_velcurve", "something" }); REQUIRE(region.crossfadeVelCurve == SfzCrossfadeCurve::gain); } SECTION("pitch_keycenter") { - REQUIRE( region.pitchKeycenter == 60 ); + REQUIRE(region.pitchKeycenter == 60); region.parseOpcode({ "pitch_keycenter", "40" }); - REQUIRE( region.pitchKeycenter == 40 ); + REQUIRE(region.pitchKeycenter == 40); region.parseOpcode({ "pitch_keycenter", "-1" }); - REQUIRE( region.pitchKeycenter == 0 ); + REQUIRE(region.pitchKeycenter == 0); region.parseOpcode({ "pitch_keycenter", "132" }); - REQUIRE( region.pitchKeycenter == 127 ); + REQUIRE(region.pitchKeycenter == 127); } SECTION("pitch_keytrack") { - REQUIRE( region.pitchKeytrack == 100 ); + REQUIRE(region.pitchKeytrack == 100); region.parseOpcode({ "pitch_keytrack", "40" }); - REQUIRE( region.pitchKeytrack == 40 ); + REQUIRE(region.pitchKeytrack == 40); region.parseOpcode({ "pitch_keytrack", "-1" }); - REQUIRE( region.pitchKeytrack == -1 ); + REQUIRE(region.pitchKeytrack == -1); region.parseOpcode({ "pitch_keytrack", "1320" }); - REQUIRE( region.pitchKeytrack == 1200 ); + REQUIRE(region.pitchKeytrack == 1200); region.parseOpcode({ "pitch_keytrack", "-1320" }); - REQUIRE( region.pitchKeytrack == -1200 ); + REQUIRE(region.pitchKeytrack == -1200); } SECTION("pitch_random") { - REQUIRE( region.pitchRandom == 0 ); + REQUIRE(region.pitchRandom == 0); region.parseOpcode({ "pitch_random", "40" }); - REQUIRE( region.pitchRandom == 40 ); + REQUIRE(region.pitchRandom == 40); region.parseOpcode({ "pitch_random", "-1" }); - REQUIRE( region.pitchRandom == 0 ); + REQUIRE(region.pitchRandom == 0); region.parseOpcode({ "pitch_random", "10320" }); - REQUIRE( region.pitchRandom == 9600 ); + REQUIRE(region.pitchRandom == 9600); } SECTION("pitch_veltrack") { - REQUIRE( region.pitchVeltrack == 0 ); + REQUIRE(region.pitchVeltrack == 0); region.parseOpcode({ "pitch_veltrack", "40" }); - REQUIRE( region.pitchVeltrack == 40 ); + REQUIRE(region.pitchVeltrack == 40); region.parseOpcode({ "pitch_veltrack", "-1" }); - REQUIRE( region.pitchVeltrack == -1 ); + REQUIRE(region.pitchVeltrack == -1); region.parseOpcode({ "pitch_veltrack", "13020" }); - REQUIRE( region.pitchVeltrack == 9600 ); + REQUIRE(region.pitchVeltrack == 9600); region.parseOpcode({ "pitch_veltrack", "-13020" }); - REQUIRE( region.pitchVeltrack == -9600 ); + REQUIRE(region.pitchVeltrack == -9600); } SECTION("transpose") { - REQUIRE( region.transpose == 0 ); + REQUIRE(region.transpose == 0); region.parseOpcode({ "transpose", "40" }); - REQUIRE( region.transpose == 40 ); + REQUIRE(region.transpose == 40); region.parseOpcode({ "transpose", "-1" }); - REQUIRE( region.transpose == -1 ); + REQUIRE(region.transpose == -1); region.parseOpcode({ "transpose", "154" }); - REQUIRE( region.transpose == 127 ); + REQUIRE(region.transpose == 127); region.parseOpcode({ "transpose", "-154" }); - REQUIRE( region.transpose == -127 ); + REQUIRE(region.transpose == -127); } SECTION("tune") { - REQUIRE( region.tune == 0 ); + REQUIRE(region.tune == 0); region.parseOpcode({ "tune", "40" }); - REQUIRE( region.tune == 40 ); + REQUIRE(region.tune == 40); region.parseOpcode({ "tune", "-1" }); - REQUIRE( region.tune == -1 ); + REQUIRE(region.tune == -1); region.parseOpcode({ "tune", "154" }); - REQUIRE( region.tune == 100 ); + REQUIRE(region.tune == 100); region.parseOpcode({ "tune", "-154" }); - REQUIRE( region.tune == -100 ); + REQUIRE(region.tune == -100); } SECTION("ampeg") { // Defaults - REQUIRE( region.amplitudeEG.attack == 0.0f ); - REQUIRE( region.amplitudeEG.decay == 0.0f ); - REQUIRE( region.amplitudeEG.delay == 0.0f ); - REQUIRE( region.amplitudeEG.hold == 0.0f ); - REQUIRE( region.amplitudeEG.release == 0.0f ); - REQUIRE( region.amplitudeEG.start == 0.0f ); - REQUIRE( region.amplitudeEG.sustain == 100.0f ); - REQUIRE( region.amplitudeEG.depth == 0 ); - REQUIRE( region.amplitudeEG.vel2attack == 0.0f ); - REQUIRE( region.amplitudeEG.vel2decay == 0.0f ); - REQUIRE( region.amplitudeEG.vel2delay == 0.0f ); - REQUIRE( region.amplitudeEG.vel2hold == 0.0f ); - REQUIRE( region.amplitudeEG.vel2release == 0.0f ); - REQUIRE( region.amplitudeEG.vel2sustain == 0.0f ); - REQUIRE( region.amplitudeEG.vel2depth == 0 ); + REQUIRE(region.amplitudeEG.attack == 0.0f); + REQUIRE(region.amplitudeEG.decay == 0.0f); + REQUIRE(region.amplitudeEG.delay == 0.0f); + REQUIRE(region.amplitudeEG.hold == 0.0f); + REQUIRE(region.amplitudeEG.release == 0.0f); + REQUIRE(region.amplitudeEG.start == 0.0f); + REQUIRE(region.amplitudeEG.sustain == 100.0f); + REQUIRE(region.amplitudeEG.depth == 0); + REQUIRE(region.amplitudeEG.vel2attack == 0.0f); + REQUIRE(region.amplitudeEG.vel2decay == 0.0f); + REQUIRE(region.amplitudeEG.vel2delay == 0.0f); + REQUIRE(region.amplitudeEG.vel2hold == 0.0f); + REQUIRE(region.amplitudeEG.vel2release == 0.0f); + REQUIRE(region.amplitudeEG.vel2sustain == 0.0f); + REQUIRE(region.amplitudeEG.vel2depth == 0); // region.parseOpcode({ "ampeg_attack", "1" }); region.parseOpcode({ "ampeg_decay", "2" }); @@ -789,21 +788,21 @@ TEST_CASE("[Region] Parsing opcodes") region.parseOpcode({ "ampeg_vel2release", "13" }); region.parseOpcode({ "ampeg_vel2sustain", "14" }); region.parseOpcode({ "ampeg_vel2depth", "15" }); - REQUIRE( region.amplitudeEG.attack == 1.0f ); - REQUIRE( region.amplitudeEG.decay == 2.0f ); - REQUIRE( region.amplitudeEG.delay == 3.0f ); - REQUIRE( region.amplitudeEG.hold == 4.0f ); - REQUIRE( region.amplitudeEG.release == 5.0f ); - REQUIRE( region.amplitudeEG.start == 6.0f ); - REQUIRE( region.amplitudeEG.sustain == 7.0f ); - REQUIRE( region.amplitudeEG.depth == 0 ); // ignored for ampeg - REQUIRE( region.amplitudeEG.vel2attack == 9.0f ); - REQUIRE( region.amplitudeEG.vel2decay == 10.0f ); - REQUIRE( region.amplitudeEG.vel2delay == 11.0f ); - REQUIRE( region.amplitudeEG.vel2hold == 12.0f ); - REQUIRE( region.amplitudeEG.vel2release == 13.0f ); - REQUIRE( region.amplitudeEG.vel2sustain == 14.0f ); - REQUIRE( region.amplitudeEG.vel2depth == 0 ); // ignored for ampeg + REQUIRE(region.amplitudeEG.attack == 1.0f); + REQUIRE(region.amplitudeEG.decay == 2.0f); + REQUIRE(region.amplitudeEG.delay == 3.0f); + REQUIRE(region.amplitudeEG.hold == 4.0f); + REQUIRE(region.amplitudeEG.release == 5.0f); + REQUIRE(region.amplitudeEG.start == 6.0f); + REQUIRE(region.amplitudeEG.sustain == 7.0f); + REQUIRE(region.amplitudeEG.depth == 0); // ignored for ampeg + REQUIRE(region.amplitudeEG.vel2attack == 9.0f); + REQUIRE(region.amplitudeEG.vel2decay == 10.0f); + REQUIRE(region.amplitudeEG.vel2delay == 11.0f); + REQUIRE(region.amplitudeEG.vel2hold == 12.0f); + REQUIRE(region.amplitudeEG.vel2release == 13.0f); + REQUIRE(region.amplitudeEG.vel2sustain == 14.0f); + REQUIRE(region.amplitudeEG.vel2depth == 0); // ignored for ampeg // region.parseOpcode({ "ampeg_attack", "1000" }); region.parseOpcode({ "ampeg_decay", "1000" }); @@ -820,21 +819,21 @@ TEST_CASE("[Region] Parsing opcodes") region.parseOpcode({ "ampeg_vel2release", "1000" }); region.parseOpcode({ "ampeg_vel2sustain", "1000" }); region.parseOpcode({ "ampeg_vel2depth", "1000" }); - REQUIRE( region.amplitudeEG.attack == 100.0f ); - REQUIRE( region.amplitudeEG.decay == 100.0f ); - REQUIRE( region.amplitudeEG.delay == 100.0f ); - REQUIRE( region.amplitudeEG.hold == 100.0f ); - REQUIRE( region.amplitudeEG.release == 100.0f ); - REQUIRE( region.amplitudeEG.start == 100.0f ); - REQUIRE( region.amplitudeEG.sustain == 100.0f ); - REQUIRE( region.amplitudeEG.depth == 0 ); // ignored for ampeg - REQUIRE( region.amplitudeEG.vel2attack == 100.0f ); - REQUIRE( region.amplitudeEG.vel2decay == 100.0f ); - REQUIRE( region.amplitudeEG.vel2delay == 100.0f ); - REQUIRE( region.amplitudeEG.vel2hold == 100.0f ); - REQUIRE( region.amplitudeEG.vel2release == 100.0f ); - REQUIRE( region.amplitudeEG.vel2sustain == 100.0f ); - REQUIRE( region.amplitudeEG.vel2depth == 0 ); // ignored for ampeg + REQUIRE(region.amplitudeEG.attack == 100.0f); + REQUIRE(region.amplitudeEG.decay == 100.0f); + REQUIRE(region.amplitudeEG.delay == 100.0f); + REQUIRE(region.amplitudeEG.hold == 100.0f); + REQUIRE(region.amplitudeEG.release == 100.0f); + REQUIRE(region.amplitudeEG.start == 100.0f); + REQUIRE(region.amplitudeEG.sustain == 100.0f); + REQUIRE(region.amplitudeEG.depth == 0); // ignored for ampeg + REQUIRE(region.amplitudeEG.vel2attack == 100.0f); + REQUIRE(region.amplitudeEG.vel2decay == 100.0f); + REQUIRE(region.amplitudeEG.vel2delay == 100.0f); + REQUIRE(region.amplitudeEG.vel2hold == 100.0f); + REQUIRE(region.amplitudeEG.vel2release == 100.0f); + REQUIRE(region.amplitudeEG.vel2sustain == 100.0f); + REQUIRE(region.amplitudeEG.vel2depth == 0); // ignored for ampeg // region.parseOpcode({ "ampeg_attack", "-101" }); region.parseOpcode({ "ampeg_decay", "-101" }); @@ -851,32 +850,32 @@ TEST_CASE("[Region] Parsing opcodes") region.parseOpcode({ "ampeg_vel2release", "-101" }); region.parseOpcode({ "ampeg_vel2sustain", "-101" }); region.parseOpcode({ "ampeg_vel2depth", "-101" }); - REQUIRE( region.amplitudeEG.attack == 0.0f ); - REQUIRE( region.amplitudeEG.decay == 0.0f ); - REQUIRE( region.amplitudeEG.delay == 0.0f ); - REQUIRE( region.amplitudeEG.hold == 0.0f ); - REQUIRE( region.amplitudeEG.release == 0.0f ); - REQUIRE( region.amplitudeEG.start == 0.0f ); - REQUIRE( region.amplitudeEG.sustain == 0.0f ); - REQUIRE( region.amplitudeEG.depth == 0 ); // ignored for ampeg - REQUIRE( region.amplitudeEG.vel2attack == -100.0f ); - REQUIRE( region.amplitudeEG.vel2decay == -100.0f ); - REQUIRE( region.amplitudeEG.vel2delay == -100.0f ); - REQUIRE( region.amplitudeEG.vel2hold == -100.0f ); - REQUIRE( region.amplitudeEG.vel2release == -100.0f ); - REQUIRE( region.amplitudeEG.vel2sustain == -100.0f ); + REQUIRE(region.amplitudeEG.attack == 0.0f); + REQUIRE(region.amplitudeEG.decay == 0.0f); + REQUIRE(region.amplitudeEG.delay == 0.0f); + REQUIRE(region.amplitudeEG.hold == 0.0f); + REQUIRE(region.amplitudeEG.release == 0.0f); + REQUIRE(region.amplitudeEG.start == 0.0f); + REQUIRE(region.amplitudeEG.sustain == 0.0f); + REQUIRE(region.amplitudeEG.depth == 0); // ignored for ampeg + REQUIRE(region.amplitudeEG.vel2attack == -100.0f); + REQUIRE(region.amplitudeEG.vel2decay == -100.0f); + REQUIRE(region.amplitudeEG.vel2delay == -100.0f); + REQUIRE(region.amplitudeEG.vel2hold == -100.0f); + REQUIRE(region.amplitudeEG.vel2release == -100.0f); + REQUIRE(region.amplitudeEG.vel2sustain == -100.0f); } SECTION("ampeg_XX_onccNN") { // Defaults - REQUIRE( !region.amplitudeEG.ccAttack ); - REQUIRE( !region.amplitudeEG.ccDecay ); - REQUIRE( !region.amplitudeEG.ccDelay ); - REQUIRE( !region.amplitudeEG.ccHold ); - REQUIRE( !region.amplitudeEG.ccRelease ); - REQUIRE( !region.amplitudeEG.ccStart ); - REQUIRE( !region.amplitudeEG.ccSustain ); + REQUIRE(!region.amplitudeEG.ccAttack); + REQUIRE(!region.amplitudeEG.ccDecay); + REQUIRE(!region.amplitudeEG.ccDelay); + REQUIRE(!region.amplitudeEG.ccHold); + REQUIRE(!region.amplitudeEG.ccRelease); + REQUIRE(!region.amplitudeEG.ccStart); + REQUIRE(!region.amplitudeEG.ccSustain); // region.parseOpcode({ "ampeg_attack_oncc1", "1" }); region.parseOpcode({ "ampeg_decay_oncc2", "2" }); @@ -885,27 +884,27 @@ TEST_CASE("[Region] Parsing opcodes") region.parseOpcode({ "ampeg_release_oncc5", "5" }); region.parseOpcode({ "ampeg_start_oncc6", "6" }); region.parseOpcode({ "ampeg_sustain_oncc7", "7" }); - REQUIRE( region.amplitudeEG.ccAttack ); - REQUIRE( region.amplitudeEG.ccDecay ); - REQUIRE( region.amplitudeEG.ccDelay ); - REQUIRE( region.amplitudeEG.ccHold ); - REQUIRE( region.amplitudeEG.ccRelease ); - REQUIRE( region.amplitudeEG.ccStart ); - REQUIRE( region.amplitudeEG.ccSustain ); - REQUIRE( region.amplitudeEG.ccAttack->first == 1 ); - REQUIRE( region.amplitudeEG.ccDecay->first == 2 ); - REQUIRE( region.amplitudeEG.ccDelay->first == 3 ); - REQUIRE( region.amplitudeEG.ccHold->first == 4 ); - REQUIRE( region.amplitudeEG.ccRelease->first == 5 ); - REQUIRE( region.amplitudeEG.ccStart->first == 6 ); - REQUIRE( region.amplitudeEG.ccSustain->first == 7 ); - REQUIRE( region.amplitudeEG.ccAttack->second == 1.0f ); - REQUIRE( region.amplitudeEG.ccDecay->second == 2.0f ); - REQUIRE( region.amplitudeEG.ccDelay->second == 3.0f ); - REQUIRE( region.amplitudeEG.ccHold->second == 4.0f ); - REQUIRE( region.amplitudeEG.ccRelease->second == 5.0f ); - REQUIRE( region.amplitudeEG.ccStart->second == 6.0f ); - REQUIRE( region.amplitudeEG.ccSustain->second == 7.0f ); + REQUIRE(region.amplitudeEG.ccAttack); + REQUIRE(region.amplitudeEG.ccDecay); + REQUIRE(region.amplitudeEG.ccDelay); + REQUIRE(region.amplitudeEG.ccHold); + REQUIRE(region.amplitudeEG.ccRelease); + REQUIRE(region.amplitudeEG.ccStart); + REQUIRE(region.amplitudeEG.ccSustain); + REQUIRE(region.amplitudeEG.ccAttack->first == 1); + REQUIRE(region.amplitudeEG.ccDecay->first == 2); + REQUIRE(region.amplitudeEG.ccDelay->first == 3); + REQUIRE(region.amplitudeEG.ccHold->first == 4); + REQUIRE(region.amplitudeEG.ccRelease->first == 5); + REQUIRE(region.amplitudeEG.ccStart->first == 6); + REQUIRE(region.amplitudeEG.ccSustain->first == 7); + REQUIRE(region.amplitudeEG.ccAttack->second == 1.0f); + REQUIRE(region.amplitudeEG.ccDecay->second == 2.0f); + REQUIRE(region.amplitudeEG.ccDelay->second == 3.0f); + REQUIRE(region.amplitudeEG.ccHold->second == 4.0f); + REQUIRE(region.amplitudeEG.ccRelease->second == 5.0f); + REQUIRE(region.amplitudeEG.ccStart->second == 6.0f); + REQUIRE(region.amplitudeEG.ccSustain->second == 7.0f); // region.parseOpcode({ "ampeg_attack_oncc1", "101" }); region.parseOpcode({ "ampeg_decay_oncc2", "101" }); @@ -914,13 +913,13 @@ TEST_CASE("[Region] Parsing opcodes") region.parseOpcode({ "ampeg_release_oncc5", "101" }); region.parseOpcode({ "ampeg_start_oncc6", "101" }); region.parseOpcode({ "ampeg_sustain_oncc7", "101" }); - REQUIRE( region.amplitudeEG.ccAttack->second == 100.0f ); - REQUIRE( region.amplitudeEG.ccDecay->second == 100.0f ); - REQUIRE( region.amplitudeEG.ccDelay->second == 100.0f ); - REQUIRE( region.amplitudeEG.ccHold->second == 100.0f ); - REQUIRE( region.amplitudeEG.ccRelease->second == 100.0f ); - REQUIRE( region.amplitudeEG.ccStart->second == 100.0f ); - REQUIRE( region.amplitudeEG.ccSustain->second == 100.0f ); + REQUIRE(region.amplitudeEG.ccAttack->second == 100.0f); + REQUIRE(region.amplitudeEG.ccDecay->second == 100.0f); + REQUIRE(region.amplitudeEG.ccDelay->second == 100.0f); + REQUIRE(region.amplitudeEG.ccHold->second == 100.0f); + REQUIRE(region.amplitudeEG.ccRelease->second == 100.0f); + REQUIRE(region.amplitudeEG.ccStart->second == 100.0f); + REQUIRE(region.amplitudeEG.ccSustain->second == 100.0f); // region.parseOpcode({ "ampeg_attack_oncc1", "-101" }); region.parseOpcode({ "ampeg_decay_oncc2", "-101" }); @@ -929,12 +928,12 @@ TEST_CASE("[Region] Parsing opcodes") region.parseOpcode({ "ampeg_release_oncc5", "-101" }); region.parseOpcode({ "ampeg_start_oncc6", "-101" }); region.parseOpcode({ "ampeg_sustain_oncc7", "-101" }); - REQUIRE( region.amplitudeEG.ccAttack->second == -100.0f ); - REQUIRE( region.amplitudeEG.ccDecay->second == -100.0f ); - REQUIRE( region.amplitudeEG.ccDelay->second == -100.0f ); - REQUIRE( region.amplitudeEG.ccHold->second == -100.0f ); - REQUIRE( region.amplitudeEG.ccRelease->second == -100.0f ); - REQUIRE( region.amplitudeEG.ccStart->second == -100.0f ); - REQUIRE( region.amplitudeEG.ccSustain->second == -100.0f ); + REQUIRE(region.amplitudeEG.ccAttack->second == -100.0f); + REQUIRE(region.amplitudeEG.ccDecay->second == -100.0f); + REQUIRE(region.amplitudeEG.ccDelay->second == -100.0f); + REQUIRE(region.amplitudeEG.ccHold->second == -100.0f); + REQUIRE(region.amplitudeEG.ccRelease->second == -100.0f); + REQUIRE(region.amplitudeEG.ccStart->second == -100.0f); + REQUIRE(region.amplitudeEG.ccSustain->second == -100.0f); } } \ No newline at end of file diff --git a/tests/RegionTriggersT.cpp b/tests/RegionTriggersT.cpp index 0718ae92..c6a88d30 100644 --- a/tests/RegionTriggersT.cpp +++ b/tests/RegionTriggersT.cpp @@ -1,5 +1,5 @@ -#include "catch2/catch.hpp" #include "../sources/Region.h" +#include "catch2/catch.hpp" using namespace Catch::literals; TEST_CASE("Basic triggers", "Region triggers") @@ -9,44 +9,44 @@ TEST_CASE("Basic triggers", "Region triggers") SECTION("key") { region.parseOpcode({ "key", "40" }); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.5f) ); - REQUIRE( !region.registerNoteOff(1, 40, 64, 0.5f) ); - REQUIRE( !region.registerNoteOn(1, 41, 64, 0.5f) ); - REQUIRE( !region.registerCC(1, 63, 64) ); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.5f)); + REQUIRE(!region.registerNoteOff(1, 40, 64, 0.5f)); + REQUIRE(!region.registerNoteOn(1, 41, 64, 0.5f)); + REQUIRE(!region.registerCC(1, 63, 64)); } SECTION("lokey and hikey") { region.parseOpcode({ "lokey", "40" }); region.parseOpcode({ "hikey", "42" }); - REQUIRE( !region.registerNoteOn(1, 39, 64, 0.5f) ); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.5f) ); - REQUIRE( !region.registerNoteOff(1, 40, 64, 0.5f) ); - REQUIRE( region.registerNoteOn(1, 41, 64, 0.5f) ); - REQUIRE( region.registerNoteOn(1, 42, 64, 0.5f) ); - REQUIRE( !region.registerNoteOn(1, 43, 64, 0.5f) ); - REQUIRE( !region.registerNoteOff(1, 42, 64, 0.5f) ); - REQUIRE( !region.registerNoteOff(1, 42, 64, 0.5f) ); - REQUIRE( !region.registerCC(1, 63, 64) ); + REQUIRE(!region.registerNoteOn(1, 39, 64, 0.5f)); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.5f)); + REQUIRE(!region.registerNoteOff(1, 40, 64, 0.5f)); + REQUIRE(region.registerNoteOn(1, 41, 64, 0.5f)); + REQUIRE(region.registerNoteOn(1, 42, 64, 0.5f)); + REQUIRE(!region.registerNoteOn(1, 43, 64, 0.5f)); + REQUIRE(!region.registerNoteOff(1, 42, 64, 0.5f)); + REQUIRE(!region.registerNoteOff(1, 42, 64, 0.5f)); + REQUIRE(!region.registerCC(1, 63, 64)); } SECTION("key and release trigger") { region.parseOpcode({ "key", "40" }); region.parseOpcode({ "trigger", "release" }); - REQUIRE( !region.registerNoteOn(1, 40, 64, 0.5f) ); - REQUIRE( region.registerNoteOff(1, 40, 64, 0.5f) ); - REQUIRE( !region.registerNoteOn(1, 41, 64, 0.5f) ); - REQUIRE( !region.registerNoteOff(1, 41, 64, 0.5f) ); - REQUIRE( !region.registerCC(1, 63, 64) ); + REQUIRE(!region.registerNoteOn(1, 40, 64, 0.5f)); + REQUIRE(region.registerNoteOff(1, 40, 64, 0.5f)); + REQUIRE(!region.registerNoteOn(1, 41, 64, 0.5f)); + REQUIRE(!region.registerNoteOff(1, 41, 64, 0.5f)); + REQUIRE(!region.registerCC(1, 63, 64)); } SECTION("key and release_key trigger") { region.parseOpcode({ "key", "40" }); region.parseOpcode({ "trigger", "release_key" }); - REQUIRE( !region.registerNoteOn(1, 40, 64, 0.5f) ); - REQUIRE( region.registerNoteOff(1, 40, 64, 0.5f) ); - REQUIRE( !region.registerNoteOn(1, 41, 64, 0.5f) ); - REQUIRE( !region.registerNoteOff(1, 41, 64, 0.5f) ); - REQUIRE( !region.registerCC(1, 63, 64) ); + REQUIRE(!region.registerNoteOn(1, 40, 64, 0.5f)); + REQUIRE(region.registerNoteOff(1, 40, 64, 0.5f)); + REQUIRE(!region.registerNoteOn(1, 41, 64, 0.5f)); + REQUIRE(!region.registerNoteOff(1, 41, 64, 0.5f)); + REQUIRE(!region.registerCC(1, 63, 64)); } // TODO: first and legato triggers SECTION("lovel and hivel") @@ -54,22 +54,22 @@ TEST_CASE("Basic triggers", "Region triggers") region.parseOpcode({ "key", "40" }); region.parseOpcode({ "lovel", "60" }); region.parseOpcode({ "hivel", "70" }); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.5f) ); - REQUIRE( region.registerNoteOn(1, 40, 60, 0.5f) ); - REQUIRE( region.registerNoteOn(1, 40, 70, 0.5f) ); - REQUIRE( !region.registerNoteOn(1, 41, 71, 0.5f) ); - REQUIRE( !region.registerNoteOn(1, 41, 59, 0.5f) ); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.5f)); + REQUIRE(region.registerNoteOn(1, 40, 60, 0.5f)); + REQUIRE(region.registerNoteOn(1, 40, 70, 0.5f)); + REQUIRE(!region.registerNoteOn(1, 41, 71, 0.5f)); + REQUIRE(!region.registerNoteOn(1, 41, 59, 0.5f)); } SECTION("lochan and hichan") { region.parseOpcode({ "key", "40" }); region.parseOpcode({ "lochan", "2" }); region.parseOpcode({ "hichan", "4" }); - REQUIRE( !region.registerNoteOn(1, 40, 64, 0.5f) ); - REQUIRE( region.registerNoteOn(2, 40, 64, 0.5f) ); - REQUIRE( region.registerNoteOn(3, 40, 64, 0.5f) ); - REQUIRE( region.registerNoteOn(4, 40, 64, 0.5f) ); - REQUIRE( !region.registerNoteOn(5, 40, 64, 0.5f) ); + REQUIRE(!region.registerNoteOn(1, 40, 64, 0.5f)); + REQUIRE(region.registerNoteOn(2, 40, 64, 0.5f)); + REQUIRE(region.registerNoteOn(3, 40, 64, 0.5f)); + REQUIRE(region.registerNoteOn(4, 40, 64, 0.5f)); + REQUIRE(!region.registerNoteOn(5, 40, 64, 0.5f)); } SECTION("lorand and hirand") @@ -77,37 +77,37 @@ TEST_CASE("Basic triggers", "Region triggers") region.parseOpcode({ "key", "40" }); region.parseOpcode({ "lorand", "0.35" }); region.parseOpcode({ "hirand", "0.40" }); - REQUIRE( !region.registerNoteOn(1, 40, 64, 0.34f) ); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.35f) ); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.36f) ); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.37f) ); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.38f) ); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.39f) ); - REQUIRE( !region.registerNoteOn(1, 40, 64, 0.40f) ); - REQUIRE( !region.registerNoteOn(1, 40, 64, 0.41f) ); + REQUIRE(!region.registerNoteOn(1, 40, 64, 0.34f)); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.35f)); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.36f)); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.37f)); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.38f)); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.39f)); + REQUIRE(!region.registerNoteOn(1, 40, 64, 0.40f)); + REQUIRE(!region.registerNoteOn(1, 40, 64, 0.41f)); } SECTION("lorand and hirand on 1.0f") { region.parseOpcode({ "key", "40" }); region.parseOpcode({ "lorand", "0.35" }); - REQUIRE( !region.registerNoteOn(1, 40, 64, 0.34f) ); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.35f) ); - REQUIRE( region.registerNoteOn(1, 40, 64, 1.0f) ); + REQUIRE(!region.registerNoteOn(1, 40, 64, 0.34f)); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.35f)); + REQUIRE(region.registerNoteOn(1, 40, 64, 1.0f)); } SECTION("on_loccN, on_hiccN") { region.parseOpcode({ "on_locc47", "64" }); region.parseOpcode({ "on_hicc47", "68" }); - REQUIRE( !region.registerCC(1, 47, 63) ); - REQUIRE( region.registerCC(1, 47, 64) ); - REQUIRE( region.registerCC(1, 47, 65) ); - REQUIRE( region.registerCC(1, 47, 66) ); - REQUIRE( region.registerCC(1, 47, 67) ); - REQUIRE( region.registerCC(1, 47, 68) ); - REQUIRE( !region.registerCC(1, 47, 69) ); - REQUIRE( !region.registerCC(1, 40, 64) ); + REQUIRE(!region.registerCC(1, 47, 63)); + REQUIRE(region.registerCC(1, 47, 64)); + REQUIRE(region.registerCC(1, 47, 65)); + REQUIRE(region.registerCC(1, 47, 66)); + REQUIRE(region.registerCC(1, 47, 67)); + REQUIRE(region.registerCC(1, 47, 68)); + REQUIRE(!region.registerCC(1, 47, 69)); + REQUIRE(!region.registerCC(1, 40, 64)); } } @@ -120,11 +120,11 @@ TEST_CASE("Legato triggers", "Region triggers") region.parseOpcode({ "lokey", "40" }); region.parseOpcode({ "hikey", "50" }); region.parseOpcode({ "trigger", "first" }); - REQUIRE( region.registerNoteOn(1, 40, 64, 0.5f) ); - REQUIRE( !region.registerNoteOn(1, 41, 64, 0.5f) ); + REQUIRE(region.registerNoteOn(1, 40, 64, 0.5f)); + REQUIRE(!region.registerNoteOn(1, 41, 64, 0.5f)); region.registerNoteOff(1, 40, 0, 0.5f); region.registerNoteOff(1, 41, 0, 0.5f); - REQUIRE( region.registerNoteOn(1, 42, 64, 0.5f) ); + REQUIRE(region.registerNoteOn(1, 42, 64, 0.5f)); } SECTION("Second note playing") @@ -132,10 +132,10 @@ TEST_CASE("Legato triggers", "Region triggers") region.parseOpcode({ "lokey", "40" }); region.parseOpcode({ "hikey", "50" }); region.parseOpcode({ "trigger", "legato" }); - REQUIRE( !region.registerNoteOn(1, 40, 64, 0.5f) ); - REQUIRE( region.registerNoteOn(1, 41, 64, 0.5f) ); + REQUIRE(!region.registerNoteOn(1, 40, 64, 0.5f)); + REQUIRE(region.registerNoteOn(1, 41, 64, 0.5f)); region.registerNoteOff(1, 40, 0, 0.5f); region.registerNoteOff(1, 41, 0, 0.5f); - REQUIRE( !region.registerNoteOn(1, 42, 64, 0.5f) ); + REQUIRE(!region.registerNoteOn(1, 42, 64, 0.5f)); } } \ No newline at end of file diff --git a/tests/SIMDHelpersT.cpp b/tests/SIMDHelpersT.cpp index 3a77d144..005bd42d 100644 --- a/tests/SIMDHelpersT.cpp +++ b/tests/SIMDHelpersT.cpp @@ -1,10 +1,10 @@ -#include "catch2/catch.hpp" #include "../sources/SIMDHelpers.h" -#include -#include -#include -#include +#include "catch2/catch.hpp" #include +#include +#include +#include +#include using namespace Catch::literals; constexpr int smallBufferSize { 3 }; @@ -12,15 +12,14 @@ constexpr int bigBufferSize { 4095 }; constexpr int medBufferSize { 127 }; constexpr double fillValue { 1.3 }; -template -inline bool approxEqual(absl::Span lhs, absl::Span rhs, Type eps=1e-3) +template +inline bool approxEqual(absl::Span lhs, absl::Span rhs, Type eps = 1e-3) { if (lhs.size() != rhs.size()) return false; for (size_t i = 0; i < rhs.size(); ++i) - if (rhs[i] != Approx(lhs[i]).epsilon(eps)) - { + if (rhs[i] != Approx(lhs[i]).epsilon(eps)) { std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n'; return false; } @@ -30,7 +29,7 @@ inline bool approxEqual(absl::Span lhs, absl::Span rhs, TEST_CASE("[Helpers] fill() - Manual buffer") { - std::vector buffer (5); + std::vector buffer(5); std::vector expected { fillValue, fillValue, fillValue, fillValue, fillValue }; fill(absl::MakeSpan(buffer), fillValue); REQUIRE(buffer == expected); @@ -38,8 +37,8 @@ TEST_CASE("[Helpers] fill() - Manual buffer") TEST_CASE("[Helpers] fill() - Small buffer") { - std::vector buffer (smallBufferSize); - std::vector expected (smallBufferSize); + std::vector buffer(smallBufferSize); + std::vector expected(smallBufferSize); std::fill(expected.begin(), expected.end(), fillValue); fill(absl::MakeSpan(buffer), fillValue); @@ -48,8 +47,8 @@ TEST_CASE("[Helpers] fill() - Small buffer") TEST_CASE("[Helpers] fill() - Big buffer") { - std::vector buffer (bigBufferSize); - std::vector expected (bigBufferSize); + std::vector buffer(bigBufferSize); + std::vector expected(bigBufferSize); std::fill(expected.begin(), expected.end(), fillValue); fill(absl::MakeSpan(buffer), fillValue); @@ -58,8 +57,8 @@ TEST_CASE("[Helpers] fill() - Big buffer") TEST_CASE("[Helpers] fill() - Small buffer -- SIMD") { - std::vector buffer (smallBufferSize); - std::vector expected (smallBufferSize); + std::vector buffer(smallBufferSize); + std::vector expected(smallBufferSize); std::fill(expected.begin(), expected.end(), fillValue); fill(absl::MakeSpan(buffer), fillValue); @@ -68,8 +67,8 @@ TEST_CASE("[Helpers] fill() - Small buffer -- SIMD") TEST_CASE("[Helpers] fill() - Big buffer -- SIMD") { - std::vector buffer (bigBufferSize); - std::vector expected (bigBufferSize); + std::vector buffer(bigBufferSize); + std::vector expected(bigBufferSize); std::fill(expected.begin(), expected.end(), fillValue); fill(absl::MakeSpan(buffer), fillValue); @@ -78,8 +77,8 @@ TEST_CASE("[Helpers] fill() - Big buffer -- SIMD") TEST_CASE("[Helpers] fill() - Small buffer -- doubles") { - std::vector buffer (smallBufferSize); - std::vector expected (smallBufferSize); + std::vector buffer(smallBufferSize); + std::vector expected(smallBufferSize); std::fill(expected.begin(), expected.end(), fillValue); fill(absl::MakeSpan(buffer), fillValue); @@ -88,18 +87,17 @@ TEST_CASE("[Helpers] fill() - Small buffer -- doubles") TEST_CASE("[Helpers] fill() - Big buffer -- doubles") { - std::vector buffer (bigBufferSize); - std::vector expected (bigBufferSize); + std::vector buffer(bigBufferSize); + std::vector expected(bigBufferSize); std::fill(expected.begin(), expected.end(), fillValue); fill(absl::MakeSpan(buffer), fillValue); REQUIRE(buffer == expected); } - TEST_CASE("[Helpers] Interleaved read") { - std::array input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f}; + std::array input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f }; std::array expected { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f }; std::array leftOutput; std::array rightOutput; @@ -107,50 +105,50 @@ TEST_CASE("[Helpers] Interleaved read") std::array real; auto realIdx = 0; - for (auto value: leftOutput) + for (auto value : leftOutput) real[realIdx++] = value; - for (auto value: rightOutput) + for (auto value : rightOutput) real[realIdx++] = value; - REQUIRE( real == expected ); + REQUIRE(real == expected); } TEST_CASE("[Helpers] Interleaved read unaligned end") { - std::array input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f}; - std::array expected { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f}; + std::array input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f }; + std::array expected { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f }; std::array leftOutput; std::array rightOutput; readInterleaved(input, absl::MakeSpan(leftOutput), absl::MakeSpan(rightOutput)); std::array real; auto realIdx = 0; - for (auto value: leftOutput) + for (auto value : leftOutput) real[realIdx++] = value; - for (auto value: rightOutput) + for (auto value : rightOutput) real[realIdx++] = value; - REQUIRE( real == expected ); + REQUIRE(real == expected); } TEST_CASE("[Helpers] Small interleaved read unaligned end") { - std::array input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f}; - std::array expected { 0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f}; + std::array input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f }; + std::array expected { 0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f }; std::array leftOutput; std::array rightOutput; readInterleaved(input, absl::MakeSpan(leftOutput), absl::MakeSpan(rightOutput)); std::array real; auto realIdx = 0; - for (auto value: leftOutput) + for (auto value : leftOutput) real[realIdx++] = value; - for (auto value: rightOutput) + for (auto value : rightOutput) real[realIdx++] = value; - REQUIRE( real == expected ); + REQUIRE(real == expected); } TEST_CASE("[Helpers] Interleaved read -- SIMD") { - std::array input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f}; + std::array input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f }; std::array expected = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f }; std::array leftOutput; std::array rightOutput; @@ -158,45 +156,45 @@ TEST_CASE("[Helpers] Interleaved read -- SIMD") std::array real; auto realIdx = 0; - for (auto value: leftOutput) + for (auto value : leftOutput) real[realIdx++] = value; - for (auto value: rightOutput) + for (auto value : rightOutput) real[realIdx++] = value; - REQUIRE( real == expected ); + REQUIRE(real == expected); } TEST_CASE("[Helpers] Interleaved read unaligned end -- SIMD") { - std::array input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f}; - std::array expected = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f}; + std::array input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f }; + std::array expected = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f }; std::array leftOutput; std::array rightOutput; readInterleaved(input, absl::MakeSpan(leftOutput), absl::MakeSpan(rightOutput)); std::array real; auto realIdx = 0; - for (auto value: leftOutput) + for (auto value : leftOutput) real[realIdx++] = value; - for (auto value: rightOutput) + for (auto value : rightOutput) real[realIdx++] = value; - REQUIRE( real == expected ); + REQUIRE(real == expected); } TEST_CASE("[Helpers] Small interleaved read unaligned end -- SIMD") { - std::array input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f}; - std::array expected { 0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f}; + std::array input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f }; + std::array expected { 0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f }; std::array leftOutput; std::array rightOutput; readInterleaved(input, absl::MakeSpan(leftOutput), absl::MakeSpan(rightOutput)); std::array real; auto realIdx = 0; - for (auto value: leftOutput) + for (auto value : leftOutput) real[realIdx++] = value; - for (auto value: rightOutput) + for (auto value : rightOutput) real[realIdx++] = value; - REQUIRE( real == expected ); + REQUIRE(real == expected); } TEST_CASE("[Helpers] Interleaved read SIMD vs Scalar") @@ -209,68 +207,86 @@ TEST_CASE("[Helpers] Interleaved read SIMD vs Scalar") std::iota(input.begin(), input.end(), 0.0f); readInterleaved(input, absl::MakeSpan(leftOutputScalar), absl::MakeSpan(rightOutputScalar)); readInterleaved(input, absl::MakeSpan(leftOutputSIMD), absl::MakeSpan(rightOutputSIMD)); - REQUIRE( leftOutputScalar == leftOutputSIMD ); - REQUIRE( rightOutputScalar == rightOutputSIMD ); + REQUIRE(leftOutputScalar == leftOutputSIMD); + REQUIRE(rightOutputScalar == rightOutputSIMD); } TEST_CASE("[Helpers] Interleaved write") { - std::array leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, }; + std::array leftInput { + 0.0f, + 1.0f, + 2.0f, + 3.0f, + 4.0f, + 5.0f, + 6.0f, + 7.0f, + }; std::array rightInput { 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f }; std::array output; - std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f}; + std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f }; writeInterleaved(leftInput, rightInput, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Interleaved write unaligned end") { - std::array leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; + std::array leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; std::array rightInput { 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f }; std::array output; - std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f}; + std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f }; writeInterleaved(leftInput, rightInput, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Small interleaved write unaligned end") { - std::array leftInput { 0.0f, 1.0f, 2.0f}; + std::array leftInput { 0.0f, 1.0f, 2.0f }; std::array rightInput { 10.0f, 11.0f, 12.0f }; std::array output; - std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f}; + std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f }; writeInterleaved(leftInput, rightInput, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Interleaved write -- SIMD") { - std::array leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, }; + std::array leftInput { + 0.0f, + 1.0f, + 2.0f, + 3.0f, + 4.0f, + 5.0f, + 6.0f, + 7.0f, + }; std::array rightInput { 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f }; std::array output; - std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f}; + std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f }; writeInterleaved(leftInput, rightInput, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Interleaved write unaligned end -- SIMD") { - std::array leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; + std::array leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; std::array rightInput { 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f }; std::array output; - std::array expected = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f}; + std::array expected = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f }; writeInterleaved(leftInput, rightInput, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Small interleaved write unaligned end -- SIMD") { - std::array leftInput { 0.0f, 1.0f, 2.0f}; + std::array leftInput { 0.0f, 1.0f, 2.0f }; std::array rightInput { 10.0f, 11.0f, 12.0f }; std::array output; - std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f}; + std::array expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f }; writeInterleaved(leftInput, rightInput, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Interleaved write SIMD vs Scalar") @@ -283,7 +299,7 @@ TEST_CASE("[Helpers] Interleaved write SIMD vs Scalar") std::iota(rightInput.begin(), rightInput.end(), medBufferSize); writeInterleaved(leftInput, rightInput, absl::MakeSpan(outputScalar)); writeInterleaved(leftInput, rightInput, absl::MakeSpan(outputSIMD)); - REQUIRE( outputScalar == outputSIMD ); + REQUIRE(outputScalar == outputSIMD); } TEST_CASE("[Helpers] Gain, single") @@ -292,7 +308,7 @@ TEST_CASE("[Helpers] Gain, single") std::array output { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; std::array expected { fillValue, fillValue, fillValue, fillValue, fillValue }; applyGain(fillValue, input, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Gain, single and inplace") @@ -300,7 +316,7 @@ TEST_CASE("[Helpers] Gain, single and inplace") std::array buffer { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; std::array expected { fillValue, fillValue, fillValue, fillValue, fillValue }; applyGain(fillValue, buffer, absl::MakeSpan(buffer)); - REQUIRE( buffer == expected ); + REQUIRE(buffer == expected); } TEST_CASE("[Helpers] Gain, spans") @@ -310,7 +326,7 @@ TEST_CASE("[Helpers] Gain, spans") std::array output { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; std::array expected { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; applyGain(gain, input, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Gain, spans and inplace") @@ -319,7 +335,7 @@ TEST_CASE("[Helpers] Gain, spans and inplace") std::array gain { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; std::array expected { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; applyGain(gain, buffer, absl::MakeSpan(buffer)); - REQUIRE( buffer == expected ); + REQUIRE(buffer == expected); } TEST_CASE("[Helpers] Gain, single (SIMD)") @@ -328,7 +344,7 @@ TEST_CASE("[Helpers] Gain, single (SIMD)") std::array output { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; std::array expected { fillValue, fillValue, fillValue, fillValue, fillValue }; applyGain(fillValue, input, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Gain, single and inplace (SIMD)") @@ -336,7 +352,7 @@ TEST_CASE("[Helpers] Gain, single and inplace (SIMD)") std::array buffer { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; std::array expected { fillValue, fillValue, fillValue, fillValue, fillValue }; applyGain(fillValue, buffer, absl::MakeSpan(buffer)); - REQUIRE( buffer == expected ); + REQUIRE(buffer == expected); } TEST_CASE("[Helpers] Gain, spans (SIMD)") @@ -346,7 +362,7 @@ TEST_CASE("[Helpers] Gain, spans (SIMD)") std::array output { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; std::array expected { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; applyGain(gain, input, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Gain, spans and inplace (SIMD)") @@ -355,12 +371,12 @@ TEST_CASE("[Helpers] Gain, spans and inplace (SIMD)") std::array gain { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; std::array expected { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; applyGain(gain, buffer, absl::MakeSpan(buffer)); - REQUIRE( buffer == expected ); + REQUIRE(buffer == expected); } TEST_CASE("[Helpers] SFZ looping index") { - std::array jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f}; // 1.1 2.3 3.6 5.0 6.5 8.1 + std::array jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0 6.5 8.1 std::array indices; std::array leftCoeffs; std::array rightCoeffs; @@ -368,14 +384,14 @@ TEST_CASE("[Helpers] SFZ looping index") std::array expectedLeft { 0.9f, 0.7f, 0.4f, 1.0f, 0.5f, 0.9f }; std::array expectedRight { 0.1f, 0.3f, 0.6f, 0.0f, 0.5f, 0.1f }; loopingSFZIndex(jumps, absl::MakeSpan(leftCoeffs), absl::MakeSpan(rightCoeffs), absl::MakeSpan(indices), 1.0f, 6, 1); - REQUIRE( indices == expectedIndices ); - REQUIRE( approxEqual(leftCoeffs, expectedLeft) ); - REQUIRE( approxEqual(rightCoeffs, expectedRight) ); + REQUIRE(indices == expectedIndices); + REQUIRE(approxEqual(leftCoeffs, expectedLeft)); + REQUIRE(approxEqual(rightCoeffs, expectedRight)); } TEST_CASE("[Helpers] SFZ looping index (SIMD)") { - std::array jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f}; // 1.1 2.3 3.6 5.0 6.5 8.1 + std::array jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0 6.5 8.1 std::array indices; std::array leftCoeffs; std::array rightCoeffs; @@ -383,9 +399,9 @@ TEST_CASE("[Helpers] SFZ looping index (SIMD)") std::array expectedLeft { 0.9f, 0.7f, 0.4f, 1.0f, 0.5f, 0.9f }; std::array expectedRight { 0.1f, 0.3f, 0.6f, 0.0f, 0.5f, 0.1f }; loopingSFZIndex(jumps, absl::MakeSpan(leftCoeffs), absl::MakeSpan(rightCoeffs), absl::MakeSpan(indices), 1.0f, 6, 1); - REQUIRE( indices == expectedIndices ); - REQUIRE( approxEqual(leftCoeffs, expectedLeft) ); - REQUIRE( approxEqual(rightCoeffs, expectedRight) ); + REQUIRE(indices == expectedIndices); + REQUIRE(approxEqual(leftCoeffs, expectedLeft)); + REQUIRE(approxEqual(rightCoeffs, expectedRight)); } // TEST_CASE("[Helpers] SFZ looping index (SIMD vs Scalar)") @@ -397,7 +413,7 @@ TEST_CASE("[Helpers] SFZ looping index (SIMD)") // std::vector indices(bigBufferSize); // std::vector leftCoeffs(bigBufferSize); // std::vector rightCoeffs(bigBufferSize); - + // std::vector indicesSIMD(bigBufferSize); // std::vector leftCoeffsSIMD(bigBufferSize); // std::vector rightCoeffsSIMD(bigBufferSize); @@ -413,9 +429,9 @@ TEST_CASE("[Helpers] Linear Ramp") const float start { 0.0f }; const float v { fillValue }; std::array output; - std::array expected {v, v + v, v + v + v, v + v + v + v, v + v + v + v + v, v + v + v + v + v + v} ; + std::array expected { v, v + v, v + v + v, v + v + v + v, v + v + v + v + v, v + v + v + v + v + v }; linearRamp(absl::MakeSpan(output), start, v); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Linear Ramp (SIMD)") @@ -423,9 +439,9 @@ TEST_CASE("[Helpers] Linear Ramp (SIMD)") const float start { 0.0f }; const float v { fillValue }; std::array output; - std::array expected {v, v + v, v + v + v, v + v + v + v, v + v + v + v + v, v + v + v + v + v + v} ; + std::array expected { v, v + v, v + v + v, v + v + v + v, v + v + v + v + v, v + v + v + v + v + v }; linearRamp(absl::MakeSpan(output), start, v); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Linear Ramp (SIMD vs scalar)") @@ -435,7 +451,7 @@ TEST_CASE("[Helpers] Linear Ramp (SIMD vs scalar)") std::vector outputSIMD(bigBufferSize); linearRamp(absl::MakeSpan(outputScalar), start, fillValue); linearRamp(absl::MakeSpan(outputSIMD), start, fillValue); - REQUIRE( approxEqual(outputScalar, outputSIMD) ); + REQUIRE(approxEqual(outputScalar, outputSIMD)); } TEST_CASE("[Helpers] Linear Ramp unaligned (SIMD vs scalar)") @@ -445,7 +461,7 @@ TEST_CASE("[Helpers] Linear Ramp unaligned (SIMD vs scalar)") std::vector outputSIMD(bigBufferSize); linearRamp(absl::MakeSpan(outputScalar).subspan(1), start, fillValue); linearRamp(absl::MakeSpan(outputSIMD).subspan(1), start, fillValue); - REQUIRE( approxEqual(outputScalar, outputSIMD) ); + REQUIRE(approxEqual(outputScalar, outputSIMD)); } TEST_CASE("[Helpers] Multiplicative Ramp") @@ -453,9 +469,9 @@ TEST_CASE("[Helpers] Multiplicative Ramp") const float start { 1.0f }; const float v { fillValue }; std::array output; - std::array expected {v, v * v, v * v * v, v * v * v * v, v * v * v * v * v, v * v * v * v * v * v} ; + std::array expected { v, v * v, v * v * v, v * v * v * v, v * v * v * v * v, v * v * v * v * v * v }; multiplicativeRamp(absl::MakeSpan(output), start, v); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Multiplicative Ramp (SIMD)") @@ -463,9 +479,9 @@ TEST_CASE("[Helpers] Multiplicative Ramp (SIMD)") const float start { 1.0f }; const float v { fillValue }; std::array output; - std::array expected {v, v * v, v * v * v, v * v * v * v, v * v * v * v * v, v * v * v * v * v * v} ; + std::array expected { v, v * v, v * v * v, v * v * v * v, v * v * v * v * v, v * v * v * v * v * v }; multiplicativeRamp(absl::MakeSpan(output), start, v); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Multiplicative Ramp (SIMD vs scalar)") @@ -475,7 +491,7 @@ TEST_CASE("[Helpers] Multiplicative Ramp (SIMD vs scalar)") std::vector outputSIMD(bigBufferSize); multiplicativeRamp(absl::MakeSpan(outputScalar), start, fillValue); multiplicativeRamp(absl::MakeSpan(outputSIMD), start, fillValue); - REQUIRE( approxEqual(outputScalar, outputSIMD) ); + REQUIRE(approxEqual(outputScalar, outputSIMD)); } TEST_CASE("[Helpers] Multiplicative Ramp unaligned (SIMD vs scalar)") @@ -485,7 +501,7 @@ TEST_CASE("[Helpers] Multiplicative Ramp unaligned (SIMD vs scalar)") std::vector outputSIMD(bigBufferSize); multiplicativeRamp(absl::MakeSpan(outputScalar).subspan(1), start, fillValue); multiplicativeRamp(absl::MakeSpan(outputSIMD).subspan(1), start, fillValue); - REQUIRE( approxEqual(outputScalar, outputSIMD) ); + REQUIRE(approxEqual(outputScalar, outputSIMD)); } TEST_CASE("[Helpers] Add") @@ -494,7 +510,7 @@ TEST_CASE("[Helpers] Add") std::array output { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; std::array expected { 2.0, 3.0, 4.0, 5.0, 6.0 }; add(input, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Add (SIMD)") @@ -503,7 +519,7 @@ TEST_CASE("[Helpers] Add (SIMD)") std::array output { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; std::array expected { 2.0, 3.0, 4.0, 5.0, 6.0 }; add(input, absl::MakeSpan(output)); - REQUIRE( output == expected ); + REQUIRE(output == expected); } TEST_CASE("[Helpers] Add (SIMD vs scalar)") @@ -517,5 +533,5 @@ TEST_CASE("[Helpers] Add (SIMD vs scalar)") add(input, absl::MakeSpan(outputScalar)); add(input, absl::MakeSpan(outputSIMD)); - REQUIRE( approxEqual(outputScalar, outputSIMD) ); + REQUIRE(approxEqual(outputScalar, outputSIMD)); } diff --git a/tests/StereoBufferT.cpp b/tests/StereoBufferT.cpp index a8fb661e..e4e5c9ca 100644 --- a/tests/StereoBufferT.cpp +++ b/tests/StereoBufferT.cpp @@ -1,5 +1,5 @@ -#include "catch2/catch.hpp" #include "../sources/StereoBuffer.h" +#include "catch2/catch.hpp" #include using namespace Catch::literals; @@ -33,16 +33,14 @@ TEST_CASE("[StereoBuffer] Access") { const int size { 5 }; StereoBuffer doubleBuffer(size); - for (auto frameIdx = 0; frameIdx < doubleBuffer.getNumFrames(); ++frameIdx) - { + for (auto frameIdx = 0; frameIdx < doubleBuffer.getNumFrames(); ++frameIdx) { doubleBuffer.getSample(Channel::left, frameIdx) = static_cast(doubleBuffer.getNumFrames()) + frameIdx; doubleBuffer.getSample(Channel::right, frameIdx) = static_cast(doubleBuffer.getNumFrames()) - frameIdx; } - for (auto frameIdx = 0; frameIdx < doubleBuffer.getNumFrames(); ++frameIdx) - { - REQUIRE(doubleBuffer.getSample(Channel::left, frameIdx) == static_cast(doubleBuffer.getNumFrames()) + frameIdx); - REQUIRE(doubleBuffer(Channel::left, frameIdx) == static_cast(doubleBuffer.getNumFrames()) + frameIdx); + for (auto frameIdx = 0; frameIdx < doubleBuffer.getNumFrames(); ++frameIdx) { + REQUIRE(doubleBuffer.getSample(Channel::left, frameIdx) == static_cast(doubleBuffer.getNumFrames()) + frameIdx); + REQUIRE(doubleBuffer(Channel::left, frameIdx) == static_cast(doubleBuffer.getNumFrames()) + frameIdx); REQUIRE(doubleBuffer.getSample(Channel::right, frameIdx) == static_cast(doubleBuffer.getNumFrames()) - frameIdx); REQUIRE(doubleBuffer(Channel::right, frameIdx) == static_cast(doubleBuffer.getNumFrames()) - frameIdx); } @@ -56,17 +54,17 @@ TEST_CASE("[StereoBuffer] Iterators") std::fill(buffer.begin(Channel::left), buffer.end(Channel::left), fillValue); std::fill(buffer.begin(Channel::right), buffer.end(Channel::right), fillValue); - REQUIRE( std::all_of(buffer.begin(Channel::left), buffer.end(Channel::left), [fillValue](auto value) { return value == fillValue; }) ); - REQUIRE( std::all_of(buffer.begin(Channel::right), buffer.end(Channel::right), [fillValue](auto value) { return value == fillValue; }) ); + REQUIRE(std::all_of(buffer.begin(Channel::left), buffer.end(Channel::left), [fillValue](auto value) { return value == fillValue; })); + REQUIRE(std::all_of(buffer.begin(Channel::right), buffer.end(Channel::right), [fillValue](auto value) { return value == fillValue; })); } -template +template void channelAlignmentTest(int size) { static constexpr auto AlignmentMask { Alignment - 1 }; StereoBuffer buffer(size); - REQUIRE( ((size_t)buffer.getChannel(Channel::left) & AlignmentMask) == 0 ); - REQUIRE( ((size_t)buffer.getChannel(Channel::right) & AlignmentMask) == 0 ); + REQUIRE(((size_t)buffer.getChannel(Channel::left) & AlignmentMask) == 0); + REQUIRE(((size_t)buffer.getChannel(Channel::right) & AlignmentMask) == 0); } TEST_CASE("[StereoBuffer] Channel alignments (floats)") @@ -140,19 +138,18 @@ TEST_CASE("[AudioBuffer] fills") for (auto frameIdx = 0; frameIdx < buffer.getNumFrames(); ++frameIdx) real[frameIdx] = buffer(Channel::left, frameIdx); - REQUIRE( real == expected ); + REQUIRE(real == expected); for (auto frameIdx = 0; frameIdx < buffer.getNumFrames(); ++frameIdx) real[frameIdx] = buffer(Channel::right, frameIdx); - REQUIRE( real == expected ); + REQUIRE(real == expected); } - TEST_CASE("[AudioBuffer] Fill a big Audiobuffer") { constexpr int size { 2039247 }; - StereoBuffer buffer (size); - std::vector input (2*size); + StereoBuffer buffer(size); + std::vector input(2 * size); std::iota(input.begin(), input.end(), 1.0f); buffer.readInterleaved(input); } @@ -160,29 +157,29 @@ TEST_CASE("[AudioBuffer] Fill a big Audiobuffer") TEST_CASE("[StereoBuffer] Interleaved write -- Scalar") { StereoBuffer buffer(10); - std::array input = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f}; + std::array input = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f }; std::array output { 0.0f }; buffer.readInterleaved(input); buffer.writeInterleaved(absl::MakeSpan(output)); - REQUIRE( output == input ); + REQUIRE(output == input); } TEST_CASE("[StereoBuffer] Interleaved write -- SIMD") { StereoBuffer buffer(10); - std::array input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f}; + std::array input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f }; std::array output { 0.0f }; buffer.readInterleaved(input); buffer.writeInterleaved(absl::MakeSpan(output)); - REQUIRE( output == input ); + REQUIRE(output == input); } TEST_CASE("[StereoBuffer] Small interleaved write -- SIMD") { StereoBuffer buffer(3); - std::array input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f}; + std::array input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f }; std::array output { 0.0f }; buffer.readInterleaved(input); buffer.writeInterleaved(absl::MakeSpan(output)); - REQUIRE( output == input ); + REQUIRE(output == input); } \ No newline at end of file