Skip to content

Commit be2a38f

Browse files
committed
added support for device_categories
1 parent df2c9a3 commit be2a38f

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

src/cpp/re/mock/Config.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,28 @@ std::unique_ptr<resource::Sample> Config::findSampleResource(std::string const &
568568
return nullptr;
569569
}
570570

571+
//------------------------------------------------------------------------
572+
// checkAllowedCategory
573+
//------------------------------------------------------------------------
574+
void checkAllowedCategory(std::string_view iCategory)
575+
{
576+
static auto kAllowedCategories = std::set<std::string>(std::begin(kDeviceCategories), std::end(kDeviceCategories));
577+
if(std::find(kAllowedCategories.begin(), kAllowedCategories.end(), iCategory) == kAllowedCategories.end())
578+
{
579+
RE_MOCK_ASSERT(false, "[%s] is not a valid device category", iCategory.data());
580+
}
581+
}
582+
583+
//------------------------------------------------------------------------
584+
// checkValidCategories
585+
//------------------------------------------------------------------------
586+
void checkValidCategories(std::vector<std::string> const &iCategories)
587+
{
588+
RE_MOCK_ASSERT(iCategories.size() > 0, "device_categories cannot be empty");
589+
for(auto const &category: iCategories)
590+
checkAllowedCategory(category);
591+
}
592+
571593
namespace impl {
572594

573595
//------------------------------------------------------------------------
@@ -600,6 +622,7 @@ Info fromInfoLua(lua::InfoLua &iInfo)
600622
Info res{};
601623

602624
res.device_type(deviceTypeFromString(iInfo.device_type()));
625+
res.device_categories(iInfo.device_categories());
603626
res.default_patch(iInfo.default_patch());
604627
res.fSupportPatches = iInfo.supports_patches();
605628
res.fAcceptNotes = iInfo.accepts_notes();

src/cpp/re/mock/Config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ enum class DeviceType : int
5050
kNotePlayer = 1 << 4
5151
};
5252

53+
constexpr char const* kDeviceCategories[] = {
54+
"Amps", "Arpeggio", "Audio Meter", "Audio Mixer", "Bass", "Chords", "CV Meter", "CV Processor", "CV Source",
55+
"Delay", "Dist", "Drums", "Dynamics", "EQ", "Filter", "Guitar", "Keys", "Loops", "Misc", "Modulation", "Note FX",
56+
"Orchestral", "Pitch", "Reverb", "Samples", "Sequencer", "Stereo", "Synth", "Vocoder"
57+
};
58+
59+
void checkAllowedCategory(std::string_view iCategory);
60+
void checkValidCategories(std::vector<std::string> const &iCategories);
61+
5362
enum class JboxObjectType : int
5463
{
5564
kUnknown = 0,
@@ -167,6 +176,7 @@ using ConfigSource = std::variant<resource::File, resource::String>;
167176
struct Info
168177
{
169178
DeviceType fDeviceType{DeviceType::kUnknown};
179+
std::vector<std::string> fDeviceCategories{ {"Misc"} };
170180
bool fSupportPatches{};
171181
std::string fDefaultPatch{};
172182
bool fAcceptNotes{};
@@ -182,6 +192,7 @@ struct Info
182192
bool fSupportsPerformanceAutomation{};
183193

184194
Info &device_type(DeviceType t) { fDeviceType = t; return *this; }
195+
Info &device_categories(std::vector<std::string> c) { checkValidCategories(c); fDeviceCategories = std::move(c); return *this; }
185196
Info &default_patch(std::string s) { fDefaultPatch = std::move(s); fSupportPatches = !fDefaultPatch.empty(); return *this; }
186197
Info &accept_notes(bool b) { fAcceptNotes = b; return *this; }
187198
Info &device_height_ru(int i) { fDeviceHeightRU = i; return *this; }

src/cpp/re/mock/lua/InfoLua.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ product_id = "se.propellerheads.SimpleInstrument"
3434
manufacturer = "Propellerhead Software"
3535
version_number = "1.0.0d1"
3636
device_type = "instrument"
37+
device_categories = { "Misc" }
3738
supports_patches = true
3839
default_patch = "/Public/Plain Sinus.repatch"
3940
accepts_notes = true
@@ -137,6 +138,28 @@ std::string InfoLua::device_type()
137138
return L.getGlobalAsString("device_type");
138139
}
139140

141+
//------------------------------------------------------------------------
142+
// InfoLua::device_categories
143+
//------------------------------------------------------------------------
144+
std::vector<std::string> InfoLua::device_categories()
145+
{
146+
std::vector<std::string> res{};
147+
if(lua_getglobal(L, "device_categories") != LUA_TNIL)
148+
{
149+
auto count = L.getTableSize();
150+
for(auto i = 1; i <= count; i++)
151+
{
152+
lua_geti(L, -1, i);
153+
auto s = lua_tostring(L, -1);
154+
if(s != nullptr)
155+
res.emplace_back(s);
156+
lua_pop(L, 1);
157+
}
158+
}
159+
lua_pop(L, 1);
160+
return res;
161+
}
162+
140163
//------------------------------------------------------------------------
141164
// InfoLua::accepts_notes
142165
//------------------------------------------------------------------------

src/cpp/re/mock/lua/InfoLua.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define RE_MOCK_INFO_H
2121

2222
#include "MockJBox.h"
23+
#include <vector>
2324

2425
namespace re::mock::lua {
2526

@@ -37,6 +38,7 @@ product_id = "se.propellerheads.SimpleInstrument"
3738
manufacturer = "Propellerhead Software"
3839
version_number = "1.0.0d1"
3940
device_type = "instrument"
41+
device_categories = {"Misc"}
4042
supports_patches = true
4143
default_patch = "/Public/Plain Sinus.repatch"
4244
accepts_notes = true
@@ -57,6 +59,7 @@ class InfoLua : public MockJBox
5759
std::string manufacturer();
5860
std::string version_number();
5961
std::string device_type();
62+
std::vector<std::string> device_categories();
6063
bool supports_patches();
6164
std::string default_patch();
6265
bool accepts_notes();

test/cpp/re/mock/lua/TestInfoLua.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ TEST(InfoLua, Basic)
5656
ASSERT_EQ(def->manufacturer(), "Propellerhead Software");
5757
ASSERT_EQ(def->version_number(), "1.0.0d1");
5858
ASSERT_EQ(def->device_type(), "instrument");
59+
ASSERT_EQ(def->device_categories(), std::vector<std::string>{"Misc"});
5960
ASSERT_TRUE(def->supports_patches());
6061
ASSERT_EQ(def->default_patch(), "/Public/Plain Sinus.repatch");
6162
ASSERT_TRUE(def->accepts_notes());

test/resources/re/mock/lua/simple_instrument-info.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ product_id = "se.propellerheads.SimpleInstrument"
1515
manufacturer = "Propellerhead Software"
1616
version_number = "1.0.0d1"
1717
device_type = "instrument"
18+
device_categories = { "Misc" }
1819
supports_patches = true
1920
default_patch = "/Public/Plain Sinus.repatch"
2021
accepts_notes = true

0 commit comments

Comments
 (0)