sfizz/tests/MidiStateT.cpp

74 lines
2 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"
2019-12-15 02:05:53 +01:00
#include "catch2/catch.hpp"
#include "absl/strings/string_view.h"
using namespace Catch::literals;
TEST_CASE("[MidiState] Initial values")
{
sfz::MidiState state;
for (auto& cc: state.getCCArray())
2019-12-15 02:05:53 +01:00
REQUIRE( cc == 0 );
REQUIRE( state.getPitchBend() == 0 );
2019-12-15 02:05:53 +01:00
}
TEST_CASE("[MidiState] Set and get CCs")
{
sfz::MidiState state;
const auto& cc = state.getCCArray();
2020-03-04 23:26:42 +01:00
state.ccEvent(0, 24, 23);
state.ccEvent(0, 123, 124);
REQUIRE(state.getCCValue(24) == 23);
REQUIRE(cc[24] == 23);
REQUIRE(state.getCCValue(123) == 124);
REQUIRE(cc[123] == 124);
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);
state.noteOnEvent(0, 64, 24);
state.ccEvent(0, 123, 124);
state.reset(0);
REQUIRE(state.getPitchBend() == 0);
REQUIRE(state.getNoteVelocity(64) == 0);
REQUIRE(state.getCCValue(123) == 0);
2019-12-15 02:05:53 +01:00
}
TEST_CASE("[MidiState] Set and get note velocities")
{
sfz::MidiState state;
2020-03-04 23:26:42 +01:00
state.noteOnEvent(0, 64, 24);
REQUIRE(+state.getNoteVelocity(64) == 24);
2020-03-04 23:26:42 +01:00
state.noteOnEvent(0, 64, 123);
REQUIRE(+state.getNoteVelocity(64) == 123);
}
TEST_CASE("[MidiState] Extended CCs")
{
sfz::MidiState state;
REQUIRE(state.getCCArray().size() >= 142);
2020-03-04 23:26:42 +01:00
state.ccEvent(0, 142, 64); // should not trap
}