diff --git a/src/cpp/re/mock/Config.cpp b/src/cpp/re/mock/Config.cpp index b28ba84..64b49b3 100644 --- a/src/cpp/re/mock/Config.cpp +++ b/src/cpp/re/mock/Config.cpp @@ -568,6 +568,28 @@ std::unique_ptr Config::findSampleResource(std::string const & return nullptr; } +//------------------------------------------------------------------------ +// checkAllowedCategory +//------------------------------------------------------------------------ +void checkAllowedCategory(std::string_view iCategory) +{ + static auto kAllowedCategories = std::set(std::begin(kDeviceCategories), std::end(kDeviceCategories)); + if(std::find(kAllowedCategories.begin(), kAllowedCategories.end(), iCategory) == kAllowedCategories.end()) + { + RE_MOCK_ASSERT(false, "[%s] is not a valid device category", iCategory.data()); + } +} + +//------------------------------------------------------------------------ +// checkValidCategories +//------------------------------------------------------------------------ +void checkValidCategories(std::vector const &iCategories) +{ + RE_MOCK_ASSERT(iCategories.size() > 0, "device_categories cannot be empty"); + for(auto const &category: iCategories) + checkAllowedCategory(category); +} + namespace impl { //------------------------------------------------------------------------ @@ -600,6 +622,7 @@ Info fromInfoLua(lua::InfoLua &iInfo) Info res{}; res.device_type(deviceTypeFromString(iInfo.device_type())); + res.device_categories(iInfo.device_categories()); res.default_patch(iInfo.default_patch()); res.fSupportPatches = iInfo.supports_patches(); res.fAcceptNotes = iInfo.accepts_notes(); diff --git a/src/cpp/re/mock/Config.h b/src/cpp/re/mock/Config.h index 563b2d5..e5d5de5 100644 --- a/src/cpp/re/mock/Config.h +++ b/src/cpp/re/mock/Config.h @@ -50,6 +50,15 @@ enum class DeviceType : int kNotePlayer = 1 << 4 }; +constexpr char const* kDeviceCategories[] = { + "Amps", "Arpeggio", "Audio Meter", "Audio Mixer", "Bass", "Chords", "CV Meter", "CV Processor", "CV Source", + "Delay", "Dist", "Drums", "Dynamics", "EQ", "Filter", "Guitar", "Keys", "Loops", "Misc", "Modulation", "Note FX", + "Orchestral", "Pitch", "Reverb", "Samples", "Sequencer", "Stereo", "Synth", "Vocoder" +}; + +void checkAllowedCategory(std::string_view iCategory); +void checkValidCategories(std::vector const &iCategories); + enum class JboxObjectType : int { kUnknown = 0, @@ -167,6 +176,7 @@ using ConfigSource = std::variant; struct Info { DeviceType fDeviceType{DeviceType::kUnknown}; + std::vector fDeviceCategories{ {"Misc"} }; bool fSupportPatches{}; std::string fDefaultPatch{}; bool fAcceptNotes{}; @@ -182,6 +192,7 @@ struct Info bool fSupportsPerformanceAutomation{}; Info &device_type(DeviceType t) { fDeviceType = t; return *this; } + Info &device_categories(std::vector c) { checkValidCategories(c); fDeviceCategories = std::move(c); return *this; } Info &default_patch(std::string s) { fDefaultPatch = std::move(s); fSupportPatches = !fDefaultPatch.empty(); return *this; } Info &accept_notes(bool b) { fAcceptNotes = b; return *this; } Info &device_height_ru(int i) { fDeviceHeightRU = i; return *this; } diff --git a/src/cpp/re/mock/lua/InfoLua.cpp b/src/cpp/re/mock/lua/InfoLua.cpp index 7b25043..0caf4d7 100644 --- a/src/cpp/re/mock/lua/InfoLua.cpp +++ b/src/cpp/re/mock/lua/InfoLua.cpp @@ -34,6 +34,7 @@ product_id = "se.propellerheads.SimpleInstrument" manufacturer = "Propellerhead Software" version_number = "1.0.0d1" device_type = "instrument" +device_categories = { "Misc" } supports_patches = true default_patch = "/Public/Plain Sinus.repatch" accepts_notes = true @@ -137,6 +138,28 @@ std::string InfoLua::device_type() return L.getGlobalAsString("device_type"); } +//------------------------------------------------------------------------ +// InfoLua::device_categories +//------------------------------------------------------------------------ +std::vector InfoLua::device_categories() +{ + std::vector res{}; + if(lua_getglobal(L, "device_categories") != LUA_TNIL) + { + auto count = L.getTableSize(); + for(auto i = 1; i <= count; i++) + { + lua_geti(L, -1, i); + auto s = lua_tostring(L, -1); + if(s != nullptr) + res.emplace_back(s); + lua_pop(L, 1); + } + } + lua_pop(L, 1); + return res; +} + //------------------------------------------------------------------------ // InfoLua::accepts_notes //------------------------------------------------------------------------ diff --git a/src/cpp/re/mock/lua/InfoLua.h b/src/cpp/re/mock/lua/InfoLua.h index cb68352..8dcf65e 100644 --- a/src/cpp/re/mock/lua/InfoLua.h +++ b/src/cpp/re/mock/lua/InfoLua.h @@ -20,6 +20,7 @@ #define RE_MOCK_INFO_H #include "MockJBox.h" +#include namespace re::mock::lua { @@ -37,6 +38,7 @@ product_id = "se.propellerheads.SimpleInstrument" manufacturer = "Propellerhead Software" version_number = "1.0.0d1" device_type = "instrument" +device_categories = {"Misc"} supports_patches = true default_patch = "/Public/Plain Sinus.repatch" accepts_notes = true @@ -57,6 +59,7 @@ class InfoLua : public MockJBox std::string manufacturer(); std::string version_number(); std::string device_type(); + std::vector device_categories(); bool supports_patches(); std::string default_patch(); bool accepts_notes(); diff --git a/test/cpp/re/mock/lua/TestInfoLua.cpp b/test/cpp/re/mock/lua/TestInfoLua.cpp index 47bdee2..7a155aa 100644 --- a/test/cpp/re/mock/lua/TestInfoLua.cpp +++ b/test/cpp/re/mock/lua/TestInfoLua.cpp @@ -56,6 +56,7 @@ TEST(InfoLua, Basic) ASSERT_EQ(def->manufacturer(), "Propellerhead Software"); ASSERT_EQ(def->version_number(), "1.0.0d1"); ASSERT_EQ(def->device_type(), "instrument"); + ASSERT_EQ(def->device_categories(), std::vector{"Misc"}); ASSERT_TRUE(def->supports_patches()); ASSERT_EQ(def->default_patch(), "/Public/Plain Sinus.repatch"); ASSERT_TRUE(def->accepts_notes()); diff --git a/test/resources/re/mock/lua/simple_instrument-info.lua b/test/resources/re/mock/lua/simple_instrument-info.lua index 0b2f14a..3bb4ee9 100644 --- a/test/resources/re/mock/lua/simple_instrument-info.lua +++ b/test/resources/re/mock/lua/simple_instrument-info.lua @@ -15,6 +15,7 @@ product_id = "se.propellerheads.SimpleInstrument" manufacturer = "Propellerhead Software" version_number = "1.0.0d1" device_type = "instrument" +device_categories = { "Misc" } supports_patches = true default_patch = "/Public/Plain Sinus.repatch" accepts_notes = true