From c8e5483c59b969c8800b1e61363804c253b2e712 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Sat, 12 Dec 2020 11:48:47 +0100 Subject: [PATCH] Clean up ccModDepth/ccModParameters --- src/sfizz/Region.cpp | 46 +++++++++++++++++++++++--------------------- src/sfizz/Region.h | 22 ++++++++++++--------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 0c0b84c7..816211ba 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -1932,35 +1932,37 @@ sfz::Region::Connection& sfz::Region::getOrCreateConnection(const ModKey& source return connections.back(); } +sfz::Region::Connection* sfz::Region::getConnectionFromCC(int sourceCC, const ModKey& target) +{ + for (sfz::Region::Connection& conn : connections) { + if (conn.source.id() == sfz::ModId::Controller && conn.target == target) { + auto p = conn.source.parameters(); + if (p.cc == sourceCC) + return &conn; + } + } + return nullptr; +} + bool sfz::Region::disabled() const noexcept { return (sampleEnd == 0); } -absl::optional sfz::Region::ccModDepth(int cc, ModId id) const noexcept +absl::optional sfz::Region::ccModDepth(int cc, ModId id, uint8_t N, uint8_t X, uint8_t Y, uint8_t Z) const noexcept { - const ModKey target = ModKey::createNXYZ(id, getId()); - for (const sfz::Region::Connection& conn : connections) { - if (conn.source.id() == sfz::ModId::Controller && conn.target == target) { - auto p = conn.source.parameters(); - if (p.cc == cc) - return conn.sourceDepth; - } - } - - return {}; + const ModKey target = ModKey::createNXYZ(id, getId(), N, X, Y, Z); + const Connection *conn = const_cast(this)->getConnectionFromCC(cc, target); + if (!conn) + return {}; + return conn->sourceDepth; } -absl::optional sfz::Region::ccModParameters(int cc, ModId id) const noexcept +absl::optional sfz::Region::ccModParameters(int cc, ModId id, uint8_t N, uint8_t X, uint8_t Y, uint8_t Z) const noexcept { - const ModKey target = ModKey::createNXYZ(id, getId()); - for (const sfz::Region::Connection& conn : connections) { - if (conn.source.id() == sfz::ModId::Controller && conn.target == target) { - auto p = conn.source.parameters(); - if (p.cc == cc) - return p; - } - } - - return {}; + const ModKey target = ModKey::createNXYZ(id, getId(), N, X, Y, Z); + const Connection *conn = const_cast(this)->getConnectionFromCC(cc, target); + if (!conn) + return {}; + return conn->source.parameters(); } diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index 384b090f..92ecf255 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -304,22 +304,25 @@ struct Region { bool disabled() const noexcept; /** - * @brief Extract the source depth modifier for a given cc and id. + * @brief Extract the source depth of the unique connection identified + * by a given CC and NXYZ target. * - * @param cc - * @param id + * @param cc the CC number of the modulation source + * @param id the ID of the modulation target, which must be regional * @return absl::optional */ - absl::optional ccModDepth(int cc, ModId id) const noexcept; + absl::optional ccModDepth(int cc, ModId id, uint8_t N = 0, uint8_t X = 0, uint8_t Y = 0, uint8_t Z = 0) const noexcept; /** - * @brief Extract the parameters for a given modulation cc and id. + * @brief Extract the source parameters of the unique connection identified + * by a given CC and NXYZ target. * - * @param cc - * @param id - * @return float + * @param cc the CC number of the modulation source + * @param cc the CC number of the modulation source + * @param id the ID of the modulation target, which must be regional + * @return absl::optional */ - absl::optional ccModParameters(int cc, ModId id) const noexcept; + absl::optional ccModParameters(int cc, ModId id, uint8_t N = 0, uint8_t X = 0, uint8_t Y = 0, uint8_t Z = 0) const noexcept; const NumericId id; @@ -466,6 +469,7 @@ struct Region { std::vector connections; Connection* getConnection(const ModKey& source, const ModKey& target); Connection& getOrCreateConnection(const ModKey& source, const ModKey& target); + Connection* getConnectionFromCC(int sourceCC, const ModKey& target); // Parent RegionSet* parent { nullptr };