sfizz/tests/MidiStateT.cpp

85 lines
2.4 KiB
C++
Raw Normal View History

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-12-15 02:05:53 +01:00
/**
* @brief This file holds some of the specific MidiState tests. Some tests on the
* effects of the midi state are also available in e.g. RegionValueComputationT.cpp
* and SynthT.cpp.
*/
2020-01-18 17:35:27 +01:00
#include "sfizz/MidiState.h"
#include "sfizz/SfzHelpers.h"
2019-12-15 02:05:53 +01:00
#include "catch2/catch.hpp"
#include "absl/strings/string_view.h"
using namespace Catch::literals;
using namespace sfz::literals;
2019-12-15 02:05:53 +01:00
TEST_CASE("[MidiState] Initial values")
{
sfz::MidiState state;
for (unsigned cc = 0; cc < sfz::config::numCCs; cc++)
2020-03-26 00:37:25 +01:00
REQUIRE( state.getCCValue(cc) == 0_norm );
REQUIRE( state.getPitchBend() == 0 );
2019-12-15 02:05:53 +01:00
}
TEST_CASE("[MidiState] Set and get CCs")
{
sfz::MidiState state;
2020-03-26 00:37:25 +01:00
state.ccEvent(0, 24, 23_norm);
state.ccEvent(0, 123, 124_norm);
REQUIRE(state.getCCValue(24) == 23_norm);
REQUIRE(state.getCCValue(123) == 124_norm);
2019-12-15 02:05:53 +01:00
}
TEST_CASE("[MidiState] Set and get pitch bends")
{
sfz::MidiState state;
2020-03-04 23:26:42 +01:00
state.pitchBendEvent(0, 894);
REQUIRE(state.getPitchBend() == 894);
2020-03-04 23:26:42 +01:00
state.pitchBendEvent(0, 0);
REQUIRE(state.getPitchBend() == 0);
2019-12-15 02:05:53 +01:00
}
TEST_CASE("[MidiState] Reset")
{
sfz::MidiState state;
2020-03-04 23:26:42 +01:00
state.pitchBendEvent(0, 894);
2020-03-26 00:37:25 +01:00
state.noteOnEvent(0, 64, 24_norm);
state.ccEvent(0, 123, 124_norm);
2020-03-29 13:20:41 +02:00
state.reset();
REQUIRE(state.getPitchBend() == 0);
2020-03-26 00:37:25 +01:00
REQUIRE(state.getNoteVelocity(64) == 0_norm);
REQUIRE(state.getCCValue(123) == 0_norm);
2019-12-15 02:05:53 +01:00
}
2020-03-29 13:20:41 +02:00
TEST_CASE("[MidiState] Reset all controllers")
{
sfz::MidiState state;
state.pitchBendEvent(20, 894);
state.ccEvent(10, 122, 124_norm);
REQUIRE(state.getPitchBend() == 894);
REQUIRE(state.getCCValue(122) == 124_norm);
state.resetAllControllers(30);
REQUIRE(state.getPitchBend() == 0);
REQUIRE(state.getCCValue(122) == 0_norm);
REQUIRE(state.getCCValue(4) == 0_norm);
}
2019-12-15 02:05:53 +01:00
TEST_CASE("[MidiState] Set and get note velocities")
{
sfz::MidiState state;
2020-03-26 00:37:25 +01:00
state.noteOnEvent(0, 64, 24_norm);
REQUIRE(+state.getNoteVelocity(64) == 24_norm);
state.noteOnEvent(0, 64, 123_norm);
REQUIRE(+state.getNoteVelocity(64) == 123_norm);
}
TEST_CASE("[MidiState] Extended CCs")
{
sfz::MidiState state;
2020-03-26 00:37:25 +01:00
state.ccEvent(0, 142, 64_norm); // should not trap
}