diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/types.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/types.hpp index 69aeb0f5..e43e4109 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/types.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/devices/types.hpp @@ -4,7 +4,7 @@ namespace HyperSonicDrivers::devices { enum class eDeviceType { - Opl, + Opl = 0, Mt32, }; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp index 0c6c937e..79d4d5c5 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp @@ -96,14 +96,18 @@ namespace HyperSonicDrivers::drivers bool MIDDriver::resetBankOP2() noexcept { - if (m_device->type == devices::eDeviceType::Opl) + switch (m_device->type) { + using enum devices::eDeviceType; + case Opl: m_midiDriver = std::make_unique(std::dynamic_pointer_cast(m_device)); - } - else - { - // must be mt32 (TODO) + break; + case Mt32: m_midiDriver = std::make_unique(std::dynamic_pointer_cast(m_device)); + break; + default: + utils::throwLogC(std::format("unknown device type {:d}", static_cast(m_device->type))); + break; } return open_(); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/SpyDevice.hpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/SpyDevice.hpp index bdd466ec..ea24f72f 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/SpyDevice.hpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/SpyDevice.hpp @@ -3,14 +3,20 @@ #include #include #include +#include namespace HyperSonicDrivers::devices { - class SpyDevice : public IDevice + template + class SpyDevice : public T { public: - SpyDevice(const std::shared_ptr& mixer, const eDeviceType type) : IDevice(mixer, type) {}; - SpyDevice() : IDevice(audio::make_mixer(), eDeviceType::Opl) {}; + SpyDevice(const std::shared_ptr& mixer) : T(mixer) { + static_assert(std::is_base_of_v); + }; + SpyDevice() : T(audio::make_mixer()) { + static_assert(std::is_base_of_v); + }; bool init() noexcept override { return true; }; bool shutdown() noexcept override { return true; }; diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestIDevice.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestIDevice.cpp index 8ba74f51..bec67d7c 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestIDevice.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/devices/TestIDevice.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include namespace HyperSonicDrivers::devices @@ -10,7 +11,7 @@ namespace HyperSonicDrivers::devices TEST(IDevice, double_acquire) { - auto device = std::make_shared(); + auto device = std::make_shared>(); MIDDriverMock middrv(device); EXPECT_THROW(MIDDriverMock middrv2(device), std::runtime_error); @@ -18,7 +19,7 @@ namespace HyperSonicDrivers::devices TEST(IDevice, acquire_release) { - auto device = std::make_shared(); + auto device = std::make_shared>(); MIDDriverMock middrv(device); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp index a71b549e..a2adb833 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,7 @@ namespace HyperSonicDrivers::drivers TEST(MIDDriver, SEQUENCE_NAME_META_EVENT) { - auto device = std::make_shared(); + auto device = std::make_shared>(); ILogger::instance->setLevel(ILogger::eLevel::Trace, ILogger::eCategory::Audio); @@ -54,7 +55,7 @@ namespace HyperSonicDrivers::drivers TEST(MIDDriver, force_stop_on_long_delta_time_delay) { - auto device = std::make_shared(); + auto device = std::make_shared>(); { MIDIEvent e; @@ -104,7 +105,7 @@ namespace HyperSonicDrivers::drivers TEST(MIDDriver, getTempo) { auto mf = files::MIDFile("../fixtures/midifile_sample.mid"); - auto device = std::make_shared(); + auto device = std::make_shared>(); MIDDriverMock md(device); EXPECT_EQ(md.getTempo(), 0); EXPECT_FALSE(md.isTempoChanged());