Skip to content

Commit

Permalink
added support for device_categories
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jun 19, 2024
1 parent df2c9a3 commit be2a38f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/cpp/re/mock/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,28 @@ std::unique_ptr<resource::Sample> Config::findSampleResource(std::string const &
return nullptr;
}

//------------------------------------------------------------------------
// checkAllowedCategory
//------------------------------------------------------------------------
void checkAllowedCategory(std::string_view iCategory)
{
static auto kAllowedCategories = std::set<std::string>(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<std::string> const &iCategories)
{
RE_MOCK_ASSERT(iCategories.size() > 0, "device_categories cannot be empty");
for(auto const &category: iCategories)
checkAllowedCategory(category);
}

namespace impl {

//------------------------------------------------------------------------
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions src/cpp/re/mock/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> const &iCategories);

enum class JboxObjectType : int
{
kUnknown = 0,
Expand Down Expand Up @@ -167,6 +176,7 @@ using ConfigSource = std::variant<resource::File, resource::String>;
struct Info
{
DeviceType fDeviceType{DeviceType::kUnknown};
std::vector<std::string> fDeviceCategories{ {"Misc"} };
bool fSupportPatches{};
std::string fDefaultPatch{};
bool fAcceptNotes{};
Expand All @@ -182,6 +192,7 @@ struct Info
bool fSupportsPerformanceAutomation{};

Info &device_type(DeviceType t) { fDeviceType = t; return *this; }
Info &device_categories(std::vector<std::string> 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; }
Expand Down
23 changes: 23 additions & 0 deletions src/cpp/re/mock/lua/InfoLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,6 +138,28 @@ std::string InfoLua::device_type()
return L.getGlobalAsString("device_type");
}

//------------------------------------------------------------------------
// InfoLua::device_categories
//------------------------------------------------------------------------
std::vector<std::string> InfoLua::device_categories()
{
std::vector<std::string> 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
//------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/re/mock/lua/InfoLua.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define RE_MOCK_INFO_H

#include "MockJBox.h"
#include <vector>

namespace re::mock::lua {

Expand All @@ -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
Expand All @@ -57,6 +59,7 @@ class InfoLua : public MockJBox
std::string manufacturer();
std::string version_number();
std::string device_type();
std::vector<std::string> device_categories();
bool supports_patches();
std::string default_patch();
bool accepts_notes();
Expand Down
1 change: 1 addition & 0 deletions test/cpp/re/mock/lua/TestInfoLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>{"Misc"});
ASSERT_TRUE(def->supports_patches());
ASSERT_EQ(def->default_patch(), "/Public/Plain Sinus.repatch");
ASSERT_TRUE(def->accepts_notes());
Expand Down
1 change: 1 addition & 0 deletions test/resources/re/mock/lua/simple_instrument-info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be2a38f

Please sign in to comment.