Clean up ccModDepth/ccModParameters

This commit is contained in:
Jean Pierre Cimalando 2020-12-12 11:48:47 +01:00
parent 171a5e5083
commit c8e5483c59
2 changed files with 37 additions and 31 deletions

View file

@ -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<float> sfz::Region::ccModDepth(int cc, ModId id) const noexcept
absl::optional<float> 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<Region*>(this)->getConnectionFromCC(cc, target);
if (!conn)
return {};
return conn->sourceDepth;
}
absl::optional<sfz::ModKey::Parameters> sfz::Region::ccModParameters(int cc, ModId id) const noexcept
absl::optional<sfz::ModKey::Parameters> 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<Region*>(this)->getConnectionFromCC(cc, target);
if (!conn)
return {};
return conn->source.parameters();
}

View file

@ -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<float>
*/
absl::optional<float> ccModDepth(int cc, ModId id) const noexcept;
absl::optional<float> 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<ModKey::Parameters>
*/
absl::optional<ModKey::Parameters> ccModParameters(int cc, ModId id) const noexcept;
absl::optional<ModKey::Parameters> 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<Region> id;
@ -466,6 +469,7 @@ struct Region {
std::vector<Connection> 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 };