sfizz/tests/RegionActivationT.cpp

266 lines
9.6 KiB
C++
Raw Normal View History

2019-08-11 13:31:16 +02:00
#include "../sources/Region.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;
TEST_CASE("Region activation", "Region tests")
{
2019-08-25 14:01:03 +02:00
sfz::Region region {};
2019-08-11 13:31:16 +02:00
region.parseOpcode({ "sample", "*sine" });
SECTION("Basic state")
{
region.registerCC(1, 4, 0);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
}
SECTION("Single CC range")
{
region.parseOpcode({ "locc4", "56" });
region.parseOpcode({ "hicc4", "59" });
region.registerCC(1, 4, 0);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 57);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 56);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 59);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 43);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 65);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 6, 57);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.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" });
region.registerCC(1, 4, 0);
region.registerCC(1, 54, 0);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 57);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 54, 19);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 54, 18);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 54, 27);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 56);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 59);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 54, 2);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 54, 26);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerCC(1, 4, 65);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
}
SECTION("Bend ranges")
{
region.parseOpcode({ "lobend", "56" });
region.parseOpcode({ "hibend", "243" });
region.registerPitchWheel(1, 0);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerPitchWheel(1, 56);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerPitchWheel(1, 243);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerPitchWheel(1, 245);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
}
SECTION("Aftertouch ranges")
{
region.parseOpcode({ "lochanaft", "56" });
region.parseOpcode({ "hichanaft", "68" });
region.registerAftertouch(1, 0);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerAftertouch(1, 56);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerAftertouch(1, 68);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerAftertouch(1, 98);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
}
SECTION("BPM ranges")
{
region.parseOpcode({ "lobpm", "56" });
region.parseOpcode({ "hibpm", "68" });
region.registerTempo(2.0f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerTempo(0.90f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerTempo(1.01f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerTempo(1.1f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
}
// TODO: add keyswitches
SECTION("Keyswitches: sw_last")
{
region.parseOpcode({ "sw_last", "40" });
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 41, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 41, 0, 0.5f);
}
SECTION("Keyswitches: sw_last with non-default keyswitch range")
{
region.parseOpcode({ "sw_lokey", "30" });
region.parseOpcode({ "sw_hikey", "50" });
region.parseOpcode({ "sw_last", "40" });
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 60, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 60, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 60, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 60, 0, 0.5f);
region.registerNoteOn(1, 41, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 41, 0, 0.5f);
}
SECTION("Keyswitches: sw_down with non-default keyswitch range")
{
region.parseOpcode({ "sw_lokey", "30" });
region.parseOpcode({ "sw_hikey", "50" });
region.parseOpcode({ "sw_down", "40" });
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 60, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 60, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 60, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 60, 0, 0.5f);
region.registerNoteOn(1, 41, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 41, 0, 0.5f);
}
SECTION("Keyswitches: sw_up with non-default keyswitch range")
{
region.parseOpcode({ "sw_lokey", "30" });
region.parseOpcode({ "sw_hikey", "50" });
region.parseOpcode({ "sw_up", "40" });
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 41, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
region.registerNoteOff(1, 41, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
}
SECTION("Keyswitches: sw_previous")
{
region.parseOpcode({ "sw_previous", "40" });
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 41, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
region.registerNoteOff(1, 41, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 41, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 41, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
}
2019-08-25 14:01:03 +02:00
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" });
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.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" });
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.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" });
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(!region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOn(1, 40, 64, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
region.registerNoteOff(1, 40, 0, 0.5f);
2019-08-25 14:01:03 +02:00
REQUIRE(region.isSwitchedOn());
2019-08-11 13:31:16 +02:00
}
}