diff --git a/src/sfizz/modulations/ModKey.cpp b/src/sfizz/modulations/ModKey.cpp index 9750070c..051a4f8e 100644 --- a/src/sfizz/modulations/ModKey.cpp +++ b/src/sfizz/modulations/ModKey.cpp @@ -15,18 +15,26 @@ 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)); + std::memset( + static_cast(this), + 0, sizeof(RawParameters)); } ModKey::Parameters::Parameters(const Parameters& other) noexcept { - std::memcpy(this, &other, sizeof(*this)); + std::memcpy( + static_cast(this), + static_cast(&other), + sizeof(RawParameters)); } ModKey::Parameters& ModKey::Parameters::operator=(const Parameters& other) noexcept { if (this != &other) - std::memcpy(this, &other, sizeof(*this)); + std::memcpy( + static_cast(this), + static_cast(&other), + sizeof(RawParameters)); return *this; } diff --git a/src/sfizz/modulations/ModKey.h b/src/sfizz/modulations/ModKey.h index e3f484c4..ce16c7a2 100644 --- a/src/sfizz/modulations/ModKey.h +++ b/src/sfizz/modulations/ModKey.h @@ -42,24 +42,7 @@ public: bool isTarget() const noexcept; std::string toString() const; - struct Parameters { - 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 - { - return std::memcmp(this, &other, sizeof(*this)) == 0; - } - - bool operator!=(const Parameters& other) const noexcept - { - return std::memcmp(this, &other, sizeof(*this)) != 0; - } - + struct RawParameters { union { //! Parameters if this key identifies a CC source struct { uint16_t cc; uint8_t curve, smooth; float step; }; @@ -71,6 +54,28 @@ public: }; }; + struct Parameters : RawParameters { + 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 + { + return std::memcmp( + static_cast(this), + static_cast(&other), + sizeof(RawParameters)) == 0; + } + + bool operator!=(const Parameters& other) const noexcept + { + return !operator==(other); + } + }; + public: bool operator==(const ModKey &other) const noexcept {