diff --git a/src/sfizz/modulations/ModKey.cpp b/src/sfizz/modulations/ModKey.cpp index fc60df9c..57038748 100644 --- a/src/sfizz/modulations/ModKey.cpp +++ b/src/sfizz/modulations/ModKey.cpp @@ -12,6 +12,36 @@ namespace sfz { +ModKey::Parameters::Parameters() noexcept +{ + // zero-fill the structure + // 1. this ensures that non-used values will be always 0 + // 2. this makes the object memcmp-comparable + std::memset(this, 0, sizeof(*this)); +} + +ModKey::Parameters::Parameters(const Parameters& other) noexcept +{ + std::memcpy(this, &other, sizeof(*this)); +} + +ModKey::Parameters& ModKey::Parameters::operator=(const Parameters& other) noexcept +{ + if (this != &other) + std::memcpy(this, &other, sizeof(*this)); + return *this; +} + +bool ModKey::Parameters::operator==(const Parameters& other) const noexcept +{ + return std::memcmp(this, &other, sizeof(*this)) == 0; +} + +bool ModKey::Parameters::operator!=(const Parameters& other) const noexcept +{ + return std::memcmp(this, &other, sizeof(*this)) != 0; +} + ModKey ModKey::createCC(uint16_t cc, uint8_t curve, uint8_t smooth, float value, float step) { ModKey::Parameters p; @@ -84,7 +114,7 @@ std::string ModKey::toString() const bool sfz::ModKey::operator==(const ModKey &other) const noexcept { return id_ == other.id_ && region_ && other.region_ && - !std::memcmp(¶meters(), &other.parameters(), sizeof(ModKey::Parameters)); + parameters() == other.parameters(); } bool sfz::ModKey::operator!=(const ModKey &other) const noexcept diff --git a/src/sfizz/modulations/ModKey.h b/src/sfizz/modulations/ModKey.h index 3fd5d470..48977537 100644 --- a/src/sfizz/modulations/ModKey.h +++ b/src/sfizz/modulations/ModKey.h @@ -8,7 +8,6 @@ #include "ModKeyHash.h" #include "../NumericId.h" #include -#include namespace sfz { @@ -42,7 +41,16 @@ public: std::string toString() const; struct Parameters { - Parameters() { std::memset(this, 0, sizeof(*this)); } + Parameters() noexcept; + Parameters(const Parameters& other) noexcept; + Parameters& operator=(const Parameters& other) noexcept; + + Parameters(Parameters&&) = delete; + Parameters &operator=(Parameters&&) = delete; + + bool operator==(const Parameters& other) const noexcept; + bool operator!=(const Parameters& other) const noexcept; + union { //! Parameters if this key identifies a CC source struct { uint16_t cc; uint8_t curve, smooth; float value, step; };