2020-01-25 10:04:31 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
2020-01-25 13:13:07 +01:00
|
|
|
// 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
|
2019-08-30 00:49:58 +02:00
|
|
|
|
2021-03-25 21:46:21 +01:00
|
|
|
#include "sfizz/Layer.h"
|
2020-01-18 17:35:27 +01:00
|
|
|
#include "sfizz/Region.h"
|
2020-10-26 22:07:40 +01:00
|
|
|
#include "sfizz/Synth.h"
|
2020-03-26 00:25:26 +01:00
|
|
|
#include "sfizz/SfzHelpers.h"
|
2019-08-25 14:01:03 +02:00
|
|
|
#include "catch2/catch.hpp"
|
2019-08-11 13:31:16 +02:00
|
|
|
using namespace Catch::literals;
|
2020-03-26 00:25:26 +01:00
|
|
|
using namespace sfz::literals;
|
2019-08-11 13:31:16 +02:00
|
|
|
|
|
|
|
|
TEST_CASE("Region activation", "Region tests")
|
|
|
|
|
{
|
2019-09-21 01:07:53 +02:00
|
|
|
sfz::MidiState midiState;
|
2021-03-25 21:46:21 +01:00
|
|
|
sfz::Region region { 0 };
|
2019-12-23 01:25:20 +01:00
|
|
|
|
2019-08-11 13:31:16 +02:00
|
|
|
region.parseOpcode({ "sample", "*sine" });
|
|
|
|
|
SECTION("Basic state")
|
|
|
|
|
{
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
layer.registerCC(4, 0_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("Single CC range")
|
|
|
|
|
{
|
|
|
|
|
region.parseOpcode({ "locc4", "56" });
|
|
|
|
|
region.parseOpcode({ "hicc4", "59" });
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
layer.registerCC(4, 0_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 57_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 56_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 59_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 43_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 65_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(6, 57_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("Multiple CC ranges")
|
|
|
|
|
{
|
|
|
|
|
region.parseOpcode({ "locc4", "56" });
|
|
|
|
|
region.parseOpcode({ "hicc4", "59" });
|
|
|
|
|
region.parseOpcode({ "locc54", "18" });
|
|
|
|
|
region.parseOpcode({ "hicc54", "27" });
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
layer.registerCC(4, 0_norm);
|
|
|
|
|
layer.registerCC(54, 0_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 57_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(54, 19_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(54, 17_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(54, 27_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 56_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 59_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(54, 2_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(54, 26_norm);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerCC(4, 65_norm);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("Bend ranges")
|
|
|
|
|
{
|
|
|
|
|
region.parseOpcode({ "lobend", "56" });
|
|
|
|
|
region.parseOpcode({ "hibend", "243" });
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
layer.registerPitchWheel(0);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerPitchWheel(sfz::normalizeBend(56));
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerPitchWheel(sfz::normalizeBend(243));
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerPitchWheel(sfz::normalizeBend(245));
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("Aftertouch ranges")
|
|
|
|
|
{
|
|
|
|
|
region.parseOpcode({ "lochanaft", "56" });
|
|
|
|
|
region.parseOpcode({ "hichanaft", "68" });
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
layer.registerAftertouch(sfz::normalize7Bits(0));
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerAftertouch(sfz::normalize7Bits(56));
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerAftertouch(sfz::normalize7Bits(68));
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerAftertouch(sfz::normalize7Bits(98));
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("BPM ranges")
|
|
|
|
|
{
|
|
|
|
|
region.parseOpcode({ "lobpm", "56" });
|
|
|
|
|
region.parseOpcode({ "hibpm", "68" });
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
layer.registerTempo(2.0f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerTempo(0.90f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerTempo(1.01f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerTempo(1.1f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("Sequences: length 2, default position")
|
|
|
|
|
{
|
|
|
|
|
region.parseOpcode({ "seq_length", "2" });
|
|
|
|
|
region.parseOpcode({ "seq_position", "1" });
|
|
|
|
|
region.parseOpcode({ "key", "40" });
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
SECTION("Sequences: length 2, position 2")
|
|
|
|
|
{
|
|
|
|
|
region.parseOpcode({ "seq_length", "2" });
|
|
|
|
|
region.parseOpcode({ "seq_position", "2" });
|
|
|
|
|
region.parseOpcode({ "key", "40" });
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
SECTION("Sequences: length 3, position 2")
|
|
|
|
|
{
|
|
|
|
|
region.parseOpcode({ "seq_length", "3" });
|
|
|
|
|
region.parseOpcode({ "seq_position", "2" });
|
|
|
|
|
region.parseOpcode({ "key", "40" });
|
2021-03-30 17:49:17 +02:00
|
|
|
sfz::Layer layer { region, midiState };
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOn(40, 64_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
|
|
|
|
layer.registerNoteOff(40, 0_norm, 0.5f);
|
|
|
|
|
REQUIRE(!layer.isSwitchedOn());
|
2019-08-11 13:31:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-26 22:07:40 +01:00
|
|
|
|
2020-10-27 11:19:12 +01:00
|
|
|
TEST_CASE("[Keyswitches] Normal lastKeyswitch range")
|
2020-10-26 22:07:40 +01:00
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/keyswitches.sfz", R"(
|
|
|
|
|
<global> sw_lokey=40 sw_hikey=42 sw_default=40
|
|
|
|
|
<region> sw_last=40 key=60 sample=*sine
|
|
|
|
|
<region> sw_last=41 key=62 sample=*saw
|
|
|
|
|
)");
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 41, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-27 11:19:12 +01:00
|
|
|
TEST_CASE("[Keyswitches] No lastKeyswitch range")
|
2020-10-26 22:07:40 +01:00
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/keyswitches.sfz", R"(
|
|
|
|
|
<region> sw_last=40 key=60 sample=*sine
|
|
|
|
|
<region> sw_last=41 key=62 sample=*saw
|
|
|
|
|
)");
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 41, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-27 11:19:12 +01:00
|
|
|
TEST_CASE("[Keyswitches] Out of lastKeyswitch range")
|
2020-10-26 22:07:40 +01:00
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/keyswitches.sfz", R"(
|
|
|
|
|
<global> sw_lokey=40 sw_hikey=42 sw_default=40
|
|
|
|
|
<region> sw_last=40 key=60 sample=*sine
|
|
|
|
|
<region> sw_last=43 key=62 sample=*saw
|
|
|
|
|
)");
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 43, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-27 11:19:12 +01:00
|
|
|
TEST_CASE("[Keyswitches] Overlapping key and lastKeyswitch range")
|
2020-10-26 22:07:40 +01:00
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/keyswitches.sfz", R"(
|
|
|
|
|
<global> sw_lokey=1 sw_hikey=127 sw_default=40
|
|
|
|
|
<region> sw_last=40 key=60 sample=*sine
|
|
|
|
|
<region> sw_last=41 key=62 sample=*saw
|
|
|
|
|
)");
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 41, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 43, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 3);
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_down, in range")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/keyswitches.sfz", R"(
|
|
|
|
|
<global> sw_lokey=1 sw_hikey=127 sw_default=40
|
|
|
|
|
<region> sw_down=40 key=60 sample=*sine
|
|
|
|
|
)");
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOff(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_down, out of range")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/keyswitches.sfz", R"(
|
|
|
|
|
<global> sw_lokey=1 sw_hikey=10 sw_default=40
|
|
|
|
|
<region> sw_down=40 key=60 sample=*sine
|
|
|
|
|
)");
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOff(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_up, in range")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/keyswitches.sfz", R"(
|
|
|
|
|
<global> sw_lokey=1 sw_hikey=127 sw_default=40
|
|
|
|
|
<region> sw_up=40 key=60 sample=*sine
|
|
|
|
|
)");
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOff(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_up, out of range")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/keyswitches.sfz", R"(
|
|
|
|
|
<global> sw_lokey=1 sw_hikey=127 sw_default=40
|
|
|
|
|
<region> sw_up=40 key=60 sample=*sine
|
|
|
|
|
)");
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOff(0, 40, 64);
|
|
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_default")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_default.sfz", R"(
|
|
|
|
|
<global> sw_lokey=30 sw_hikey=50 sw_default=40
|
|
|
|
|
<region> sw_last=41 key=51 sample=*sine
|
|
|
|
|
<region> sw_last=40 key=52 sample=*sine
|
|
|
|
|
<region> sw_last=41 key=53 sample=*sine
|
|
|
|
|
<region> sw_last=40 key=54 sample=*sine
|
|
|
|
|
)");
|
|
|
|
|
REQUIRE( synth.getNumRegions() == 4 );
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE( !synth.getLayerView(0)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( synth.getLayerView(1)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( !synth.getLayerView(2)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( synth.getLayerView(3)->isSwitchedOn() );
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_default and playing with switches")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_default.sfz", R"(
|
|
|
|
|
<global> sw_lokey=30 sw_hikey=50 sw_default=40
|
|
|
|
|
<region> sw_last=41 key=51 sample=*sine
|
|
|
|
|
<region> sw_last=40 key=52 sample=*sine
|
|
|
|
|
<region> sw_last=41 key=53 sample=*sine
|
|
|
|
|
<region> sw_last=40 key=54 sample=*sine
|
|
|
|
|
)");
|
|
|
|
|
REQUIRE( synth.getNumRegions() == 4 );
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE( !synth.getLayerView(0)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( synth.getLayerView(1)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( !synth.getLayerView(2)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( synth.getLayerView(3)->isSwitchedOn() );
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 41, 64);
|
|
|
|
|
synth.noteOff(0, 41, 0);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE( synth.getLayerView(0)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( !synth.getLayerView(1)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( synth.getLayerView(2)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( !synth.getLayerView(3)->isSwitchedOn() );
|
2020-10-26 22:07:40 +01:00
|
|
|
synth.noteOn(0, 40, 64);
|
|
|
|
|
synth.noteOff(0, 40, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE( !synth.getLayerView(0)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( synth.getLayerView(1)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( !synth.getLayerView(2)->isSwitchedOn() );
|
|
|
|
|
REQUIRE( synth.getLayerView(3)->isSwitchedOn() );
|
2020-10-26 22:07:40 +01:00
|
|
|
}
|
2020-10-27 11:04:25 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_previous in range")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
|
|
|
|
|
<region> sample=*saw sw_previous=60 lokey=50 hikey=70
|
|
|
|
|
)");
|
|
|
|
|
// Note: sforzando seems to activate by default if sw_previous is indeed 60,
|
|
|
|
|
// but not any other value. As it does not seem really useful at this point
|
|
|
|
|
// the test assumes that sw_previous regions are disabled by default
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 51, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 51, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 2);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_previous out of range")
|
|
|
|
|
{
|
|
|
|
|
// The behavior is the same in this case, regardless of the keyrange
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
|
|
|
|
|
<region> sample=*saw sw_previous=60 lokey=50 hikey=55
|
|
|
|
|
)");
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 51, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 0);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 51, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 60, 64);
|
2020-10-31 19:28:23 +01:00
|
|
|
REQUIRE(synth.getNumActiveVoices() == 1);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
synth.noteOn(0, 61, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
2020-10-27 11:04:25 +01:00
|
|
|
}
|
2020-10-27 14:50:31 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_lolast and sw_hilast")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
|
|
|
|
|
<region> sw_lolast=57 sw_hilast=59 key=70 sample=*saw
|
|
|
|
|
<region> sw_lolast=60 sw_hilast=62 key=72 sample=*sine
|
|
|
|
|
)");
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 51, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 57, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 60, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 58, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 61, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 59, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 62, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_lolast and sw_hilast with sw_last")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
|
|
|
|
|
<region> sw_last=40 sw_lolast=57 sw_hilast=59 key=70 sample=*saw
|
|
|
|
|
<region> sw_lolast=60 sw_hilast=62 sw_last=41 key=72 sample=*sine
|
|
|
|
|
)");
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 40, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 41, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 57, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 41, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 60, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
synth.noteOn(0, 40, 64);
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 14:50:31 +01:00
|
|
|
}
|
2020-10-27 15:11:51 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] sw_lolast and sw_hilast with sw_default")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
|
|
|
|
|
<global> sw_default=58
|
|
|
|
|
<region> sw_lolast=57 sw_hilast=59 key=70 sample=*saw
|
|
|
|
|
<region> sw_lolast=60 sw_hilast=62 key=72 sample=*sine
|
|
|
|
|
)");
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-27 15:11:51 +01:00
|
|
|
}
|
2020-10-28 16:12:42 +01:00
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] Multiple sw_default")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
|
|
|
|
|
<global> sw_default=60
|
|
|
|
|
<region> sw_last=60 key=70 sample=*saw
|
|
|
|
|
<group> sw_default=58
|
|
|
|
|
<region> sw_last=59 key=72 sample=*saw
|
|
|
|
|
<master> sw_default=59
|
|
|
|
|
<region> sw_last=62 key=73 sample=*saw
|
|
|
|
|
)");
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(!synth.getLayerView(0)->isSwitchedOn());
|
2020-10-28 16:12:42 +01:00
|
|
|
// Only the last one is taken into account
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(1)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(2)->isSwitchedOn());
|
2020-10-28 16:12:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[Keyswitches] Multiple sw_default, in region")
|
|
|
|
|
{
|
|
|
|
|
sfz::Synth synth;
|
|
|
|
|
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
|
|
|
|
|
<global> sw_default=60
|
|
|
|
|
<region> sw_last=58 key=70 sample=*saw
|
|
|
|
|
<region> sw_default=58 sw_last=59 key=72 sample=*saw
|
|
|
|
|
)");
|
2021-03-25 21:46:21 +01:00
|
|
|
REQUIRE(synth.getLayerView(0)->isSwitchedOn());
|
|
|
|
|
REQUIRE(!synth.getLayerView(1)->isSwitchedOn());
|
2020-10-28 16:12:42 +01:00
|
|
|
}
|
|
|
|
|
|