1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include "../src/core/midiEvent.h"
#include "../src/core/const.h"
#include "../src/deps/mcl-utils/src/math.hpp"
#include <catch2/catch_test_macros.hpp>
TEST_CASE("MidiEvent")
{
namespace math = mcl::utils::math;
using namespace giada::m;
constexpr uint32_t raw = 0x912C5000; // Note on, channel 1, key 44 (0x2C), velocity 80 (0x50)
SECTION("Test Channel message")
{
MidiEvent e = MidiEvent::makeFromRaw(raw, /*numBytes=*/3, /*timestamp=*/0.0);
REQUIRE(e.getRaw() == raw);
REQUIRE(e.getRawNoVelocity() == 0x912C0000);
REQUIRE(e.getType() == MidiEvent::Type::CHANNEL);
REQUIRE(e.getNumBytes() == 3);
REQUIRE(e.getStatus() == 0x90);
REQUIRE(e.getChannel() == 1);
REQUIRE(e.getNote() == 44);
REQUIRE(e.getVelocity() == 80);
REQUIRE(e.getByte1() == 0x91);
REQUIRE(e.getByte2() == 0x2C);
REQUIRE(e.getByte3() == 0x50);
}
SECTION("Test get/set properties")
{
MidiEvent e = MidiEvent::makeFromRaw(raw, /*numBytes=*/3, /*timestamp=*/0.0);
SECTION("Test velocity")
{
e.setVelocity(33);
REQUIRE(e.getChannel() == 1);
REQUIRE(e.getNote() == 44);
REQUIRE(e.getVelocity() == 33);
REQUIRE(e.getVelocityFloat() == math::map(33, G_MAX_VELOCITY, G_MAX_VELOCITY_FLOAT));
e.setVelocityFloat(0.4f);
REQUIRE(e.getVelocity() == math::map(0.4f, G_MAX_VELOCITY_FLOAT, G_MAX_VELOCITY));
REQUIRE(e.getVelocityFloat() == 0.4f);
}
SECTION("Test channel")
{
e.setChannel(4);
REQUIRE(e.getChannel() == 4);
REQUIRE(e.getNote() == 44);
REQUIRE(e.getVelocity() == 80);
REQUIRE(e.getVelocityFloat() == math::map(80, G_MAX_VELOCITY, G_MAX_VELOCITY_FLOAT));
}
}
}
|