2020-07-27 17:32:25 +02:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
|
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
|
|
|
|
// license. You should have receive a LICENSE.md file along with the code.
|
|
|
|
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
|
|
|
|
|
2020-08-10 17:22:49 +02:00
|
|
|
#include "TestHelpers.h"
|
2020-07-27 17:32:25 +02:00
|
|
|
#include "sfizz/modulations/ModId.h"
|
|
|
|
|
|
|
|
|
|
size_t RegionCCView::size() const
|
|
|
|
|
{
|
|
|
|
|
size_t count = 0;
|
|
|
|
|
for (const sfz::Region::Connection& conn : region_.connections)
|
|
|
|
|
count += match(conn);
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RegionCCView::empty() const
|
|
|
|
|
{
|
|
|
|
|
for (const sfz::Region::Connection& conn : region_.connections)
|
|
|
|
|
if (match(conn))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sfz::ModKey::Parameters RegionCCView::at(int cc) const
|
|
|
|
|
{
|
|
|
|
|
for (const sfz::Region::Connection& conn : region_.connections) {
|
|
|
|
|
if (match(conn)) {
|
2020-07-28 13:52:38 +02:00
|
|
|
const sfz::ModKey::Parameters p = conn.source.parameters();
|
2020-07-27 17:32:25 +02:00
|
|
|
if (p.cc == cc)
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw std::out_of_range("Region CC");
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 03:53:32 +02:00
|
|
|
float RegionCCView::valueAt(int cc) const
|
|
|
|
|
{
|
|
|
|
|
for (const sfz::Region::Connection& conn : region_.connections) {
|
|
|
|
|
if (match(conn)) {
|
|
|
|
|
const sfz::ModKey::Parameters p = conn.source.parameters();
|
|
|
|
|
if (p.cc == cc)
|
|
|
|
|
return conn.sourceDepth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw std::out_of_range("Region CC");
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 17:32:25 +02:00
|
|
|
bool RegionCCView::match(const sfz::Region::Connection& conn) const
|
|
|
|
|
{
|
2020-07-28 13:52:38 +02:00
|
|
|
return conn.source.id() == sfz::ModId::Controller && conn.target == target_;
|
2020-07-27 17:32:25 +02:00
|
|
|
}
|
2020-08-10 17:22:49 +02:00
|
|
|
|
|
|
|
|
const std::vector<const sfz::Voice*> getActiveVoices(const sfz::Synth& synth)
|
|
|
|
|
{
|
|
|
|
|
std::vector<const sfz::Voice*> activeVoices;
|
|
|
|
|
for (int i = 0; i < synth.getNumVoices(); ++i) {
|
|
|
|
|
const auto* voice = synth.getVoiceView(i);
|
|
|
|
|
if (!voice->isFree())
|
|
|
|
|
activeVoices.push_back(voice);
|
|
|
|
|
}
|
|
|
|
|
return activeVoices;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 00:47:31 +02:00
|
|
|
const std::vector<const sfz::Voice*> getPlayingVoices(const sfz::Synth& synth)
|
|
|
|
|
{
|
|
|
|
|
std::vector<const sfz::Voice*> playingVoices;
|
|
|
|
|
for (int i = 0; i < synth.getNumVoices(); ++i) {
|
|
|
|
|
const auto* voice = synth.getVoiceView(i);
|
|
|
|
|
if (!voice->releasedOrFree())
|
|
|
|
|
playingVoices.push_back(voice);
|
|
|
|
|
}
|
|
|
|
|
return playingVoices;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 17:22:49 +02:00
|
|
|
unsigned numPlayingVoices(const sfz::Synth& synth)
|
|
|
|
|
{
|
|
|
|
|
return absl::c_count_if(getActiveVoices(synth), [](const sfz::Voice* v) {
|
|
|
|
|
return !v->releasedOrFree();
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-09-16 09:03:39 +02:00
|
|
|
|
2020-10-04 23:00:52 +02:00
|
|
|
std::string createDefaultGraph(std::vector<std::string> lines, int numRegions)
|
2020-09-16 09:03:39 +02:00
|
|
|
{
|
|
|
|
|
for (int regionIdx = 0; regionIdx < numRegions; ++regionIdx) {
|
2020-09-26 17:29:40 +02:00
|
|
|
lines.push_back(absl::StrCat(
|
|
|
|
|
R"("AmplitudeEG {)", regionIdx, R"(}" -> "MasterAmplitude {)", regionIdx, R"(}")"
|
|
|
|
|
));
|
2020-09-16 09:03:39 +02:00
|
|
|
lines.push_back(absl::StrCat(
|
2020-10-06 03:53:32 +02:00
|
|
|
R"("Controller 7 {curve=4, smooth=10, step=0}" -> "Amplitude {)",
|
2020-09-16 09:03:39 +02:00
|
|
|
regionIdx,
|
|
|
|
|
R"(}")"
|
|
|
|
|
));
|
|
|
|
|
lines.push_back(absl::StrCat(
|
2020-10-06 03:53:32 +02:00
|
|
|
R"("Controller 10 {curve=1, smooth=10, step=0}" -> "Pan {)",
|
2020-09-16 09:03:39 +02:00
|
|
|
regionIdx,
|
|
|
|
|
R"(}")"
|
|
|
|
|
));
|
2020-10-07 14:36:27 +02:00
|
|
|
lines.push_back(absl::StrCat(
|
|
|
|
|
R"("Controller 11 {curve=4, smooth=10, step=0}" -> "Amplitude {)",
|
|
|
|
|
regionIdx,
|
|
|
|
|
R"(}")"
|
|
|
|
|
));
|
2020-09-16 09:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-04 23:00:52 +02:00
|
|
|
return createModulationDotGraph(lines);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::string createModulationDotGraph(std::vector<std::string> lines)
|
|
|
|
|
{
|
2020-09-16 09:03:39 +02:00
|
|
|
std::sort(lines.begin(), lines.end());
|
|
|
|
|
|
|
|
|
|
std::string graph;
|
|
|
|
|
graph.reserve(1024);
|
|
|
|
|
|
|
|
|
|
graph += "digraph {\n";
|
|
|
|
|
for (const std::string& line : lines) {
|
|
|
|
|
graph.push_back('\t');
|
|
|
|
|
graph += line;
|
|
|
|
|
graph.push_back('\n');
|
|
|
|
|
}
|
|
|
|
|
graph += "}\n";
|
|
|
|
|
|
|
|
|
|
return graph;
|
2020-10-04 23:00:52 +02:00
|
|
|
}
|