From 65d474304236f79773713be28e3d4d3ab320b480 Mon Sep 17 00:00:00 2001 From: Dan Green Date: Fri, 10 Nov 2023 17:24:07 -0800 Subject: [PATCH] Move image field to ImageElement base class simplifies some duplicate code simplifies some braces for Elements Also fix some `this` captures --- .../src/VCV_adaptor/widget_convert/Befaco.hh | 40 +++++------ .../src/VCV_adaptor/widget_convert/Rack.hh | 70 +++++++++---------- .../VCV_adaptor/widget_convert/hetrickcv.hh | 4 +- firmware/src/gui/elements/draw.hh | 60 +++++----------- firmware/src/gui/elements/module_drawer.hh | 6 +- .../src/gui/pages/manual_control_popup.hh | 10 +-- firmware/tests/element_tests.cc | 10 +-- shared/CoreModules/elements/4ms_elements.hh | 38 +++++----- shared/CoreModules/elements/base_element.hh | 30 +++----- .../tests/element_state_conversion_tests.cc | 4 +- 10 files changed, 117 insertions(+), 155 deletions(-) diff --git a/firmware/src/VCV_adaptor/widget_convert/Befaco.hh b/firmware/src/VCV_adaptor/widget_convert/Befaco.hh index c4c5c7d5f..3c6ac52ac 100644 --- a/firmware/src/VCV_adaptor/widget_convert/Befaco.hh +++ b/firmware/src/VCV_adaptor/widget_convert/Befaco.hh @@ -40,12 +40,17 @@ namespace MetaModule template<> inline Element make_element<::CKSSVert7>(BaseElement b) { - return SlideSwitch{{b}, 7, "SwitchTallVert.png", "SwitchTallVertHandle.png", SlideSwitch::Ascend::UpLeft}; + return SlideSwitch{{b, "SwitchTallVert.png"}, 7, "SwitchTallVertHandle.png", SlideSwitch::Ascend::UpLeft}; } template<> inline Element make_element<::CKSSHoriz4>(BaseElement b) { - return SlideSwitch{{b}, 4, "SwitchWideHoriz_bg.png", "SwitchWideHoriz_fg.png"}; + return SlideSwitch{{b, "SwitchWideHoriz_bg.png"}, 4, "SwitchWideHoriz_fg.png", SlideSwitch::Ascend::DownRight}; +} + +template<> +inline Element make_element<::CKSSThreeDragable>(BaseElement b) { + return SlideSwitch{{b, "CKSSThree_bg.png"}, 3, "CKSSThree_fg.png", SlideSwitch::Ascend::UpLeft}; } template<> @@ -63,11 +68,6 @@ inline Element make_element<::CKSSNarrow3>(BaseElement b) { return FlipSwitch{{b}, 3, {"SwitchNarrow_0.png", "SwitchNarrow_1.png", "SwitchNarrow_2.png"}}; } -template<> -inline Element make_element<::CKSSThreeDragable>(BaseElement b) { - return SlideSwitch{{b}, 3, "CKSSThree_bg.png", "CKSSThree_fg.png", SlideSwitch::Ascend::UpLeft}; -} - template<> inline Element make_element<::ThreeStateBefacoSwitchMomentary>(BaseElement b) { return FlipSwitch{ @@ -81,67 +81,67 @@ inline Element make_element<::Knurlie>(BaseElement b) { template<> inline Element make_element<::BefacoTinyKnobWhite>(BaseElement b) { - return Knob{{b}, "BefacoTinyKnobWhite.png"}; + return Knob{b, "BefacoTinyKnobWhite.png"}; }; template<> inline Element make_element<::BefacoTinyKnobRed>(BaseElement b) { - return Knob{{b}, "BefacoTinyKnobRed.png"}; + return Knob{b, "BefacoTinyKnobRed.png"}; }; template<> inline Element make_element<::BefacoTinyKnobDarkGrey>(BaseElement b) { - return Knob{{b}, "BefacoTinyKnobDarkGrey.png"}; + return Knob{b, "BefacoTinyKnobDarkGrey.png"}; }; template<> inline Element make_element<::BefacoTinyKnobLightGrey>(BaseElement b) { - return Knob{{b}, "BefacoTinyKnobLightGrey.png"}; + return Knob{b, "BefacoTinyKnobLightGrey.png"}; }; template<> inline Element make_element<::BefacoTinyKnobBlack>(BaseElement b) { - return Knob{{b}, "BefacoTinyKnobBlack.png"}; + return Knob{b, "BefacoTinyKnobBlack.png"}; }; template<> inline Element make_element<::Davies1900hLargeGreyKnob>(BaseElement b) { - return Knob{{b}, "Davies1900hLargeGrey.png"}; + return Knob{b, "Davies1900hLargeGrey.png"}; }; template<> inline Element make_element<::Davies1900hLightGreyKnob>(BaseElement b) { - return Knob{{b}, "Davies1900hLightGrey.png"}; + return Knob{b, "Davies1900hLightGrey.png"}; }; template<> inline Element make_element<::Davies1900hLargeLightGreyKnob>(BaseElement b) { - return Knob{{b}, "Davies1900hLargeLightGrey.png"}; + return Knob{b, "Davies1900hLargeLightGrey.png"}; }; template<> inline Element make_element<::Davies1900hDarkGreyKnob>(BaseElement b) { - return Knob{{b}, "Davies1900hDarkGrey.png"}; + return Knob{b, "Davies1900hDarkGrey.png"}; }; template<> inline Element make_element<::Crossfader>(BaseElement b) { - return Slider{{b}, "Crossfader.png", "CrossfaderHandle.png"}; + return Slider{{b, "Crossfader.png"}, "CrossfaderHandle.png"}; }; template<> inline Element make_element<::BefacoSlidePotSmall>(BaseElement b) { - return Slider{{b}, "BefacoSlidePotSmall.png", "BefacoSlidePotHandleSmall.png"}; + return Slider{{b, "BefacoSlidePotSmall.png"}, "BefacoSlidePotHandleSmall.png"}; }; template<> inline Element make_element_output<::BananutRed>(BaseElement b) { - return JackOutput{{{b}, "BananutRed.png"}}; + return JackOutput{b, "BananutRed.png"}; }; template<> inline Element make_element_input<::BananutBlack>(BaseElement b) { - return JackInput{{{b}, "BananutBlack.png"}}; + return JackInput{b, "BananutBlack.png"}; }; } // namespace MetaModule diff --git a/firmware/src/VCV_adaptor/widget_convert/Rack.hh b/firmware/src/VCV_adaptor/widget_convert/Rack.hh index 21c03aabd..9c14192bd 100644 --- a/firmware/src/VCV_adaptor/widget_convert/Rack.hh +++ b/firmware/src/VCV_adaptor/widget_convert/Rack.hh @@ -19,117 +19,117 @@ inline Element make_element(BaseElement b) { template<> inline Element make_element(BaseElement b) { - return MomentaryButton{{{b}, "BefacoPush_0.png"}}; + return MomentaryButton{b, "BefacoPush_0.png"}; }; template<> inline Element make_element(BaseElement b) { - return MomentaryButton{{{b}, "CKD6_0.png"}}; + return MomentaryButton{b, "CKD6_0.png"}; }; template<> inline Element make_element(BaseElement b) { - return MomentaryButton{{{b}, "TL1105.png"}}; + return MomentaryButton{b, "TL1105.png"}; }; template<> inline Element make_element(BaseElement b) { - return MomentaryButton{{{b}, "VCVBezel.png"}}; + return MomentaryButton{b, "VCVBezel.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "BefacoBigKnob.png"}; + return Knob{b, "BefacoBigKnob.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "BefacoTinyKnobWhite.png"}; + return Knob{b, "BefacoTinyKnobWhite.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Davies1900hBlack.png"}; + return Knob{b, "Davies1900hBlack.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Davies1900hWhite.png"}; + return Knob{b, "Davies1900hWhite.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Davies1900hRed.png"}; + return Knob{b, "Davies1900hRed.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Davies1900hLargeWhite.png"}; + return Knob{b, "Davies1900hLargeWhite.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan1PSGreen.png"}; + return Knob{b, "Rogan1PSGreen.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan1PSRed.png"}; + return Knob{b, "Rogan1PSRed.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan1PSWhite.png"}; + return Knob{b, "Rogan1PSWhite.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan2SGray.png"}; + return Knob{b, "Rogan2SGray.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan2PSWhite.png"}; + return Knob{b, "Rogan2PSWhite.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan1PRed.png"}; + return Knob{b, "Rogan1PRed.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan1PRed.png"}; + return Knob{b, "Rogan1PRed.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan2PSRed.png"}; + return Knob{b, "Rogan2PSRed.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan2PSGreen.png"}; + return Knob{b, "Rogan2PSGreen.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan3PSWhite.png"}; + return Knob{b, "Rogan3PSWhite.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan3PSRed.png"}; + return Knob{b, "Rogan3PSRed.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Rogan3PSGreen.png"}; + return Knob{b, "Rogan3PSGreen.png"}; }; template<> inline Element make_element(BaseElement b) { - return Knob{{b}, "Trimpot.png"}; + return Knob{b, "Trimpot.png"}; }; // @@ -137,7 +137,7 @@ inline Element make_element(BaseElement b) { // template<> inline Element make_element(BaseElement b) { - return Slider{{b}, "BefacoSlidePot.png", "BefacoSlidePotHandle.png"}; + return Slider{{b, "BefacoSlidePot.png"}, "BefacoSlidePotHandle.png"}; }; // @@ -147,37 +147,37 @@ inline Element make_element(BaseElement template<> inline Element make_element>(BaseElement b) { - return RgbLight{{{b}, "VCVBezel.png"}}; + return RgbLight{{b, "VCVBezel.png"}}; }; template<> inline Element make_element>(BaseElement b) { - return MonoLight{{{b}, "SmallLight.png"}, 0xF800}; + return MonoLight{{b, "SmallLight.png"}, 0xF800}; }; template<> inline Element make_element>(BaseElement b) { - return MonoLight{{{b}, "SmallLight.png"}, 0x07E0}; + return MonoLight{{b, "SmallLight.png"}, 0x07E0}; }; template<> inline Element make_element>(BaseElement b) { - return DualLight{{{b}, "SmallLight.png"}, {0x07E0, 0xF800}}; + return DualLight{{b, "SmallLight.png"}, {0x07E0, 0xF800}}; }; template<> inline Element make_element>(BaseElement b) { - return DualLight{{{b}, "MediumLight.png"}, {0x07E0, 0xF800}}; + return DualLight{{b, "MediumLight.png"}, {0x07E0, 0xF800}}; }; template<> inline Element make_element>(BaseElement b) { - return MonoLight{{{b}, "MediumLight.png"}, 0xF800}; + return MonoLight{{b, "MediumLight.png"}, 0xF800}; }; template<> inline Element make_element>(BaseElement b) { - return MonoLight{{{b}, "MediumLight.png"}, 0x07E0}; + return MonoLight{{b, "MediumLight.png"}, 0x07E0}; }; // @@ -188,24 +188,24 @@ inline Element make_element inline Element make_element_input(BaseElement b) { - return JackInput{{{b}, "jack_x.png"}}; + return JackInput{b, "jack_x.png"}; }; template<> inline Element make_element_input(BaseElement b) { - return JackInput{{{b}, "jack_x.png"}}; + return JackInput{b, "jack_x.png"}; }; // Outputs template<> inline Element make_element_output(BaseElement b) { - return JackOutput{{{b}, "jack_x.png"}}; + return JackOutput{b, "jack_x.png"}; }; template<> inline Element make_element_output(BaseElement b) { - return JackOutput{{{b}, "jack_x.png"}}; + return JackOutput{b, "jack_x.png"}; }; } // namespace MetaModule diff --git a/firmware/src/VCV_adaptor/widget_convert/hetrickcv.hh b/firmware/src/VCV_adaptor/widget_convert/hetrickcv.hh index eac684a6e..d74f1915f 100644 --- a/firmware/src/VCV_adaptor/widget_convert/hetrickcv.hh +++ b/firmware/src/VCV_adaptor/widget_convert/hetrickcv.hh @@ -10,12 +10,12 @@ namespace MetaModule template<> inline Element make_element<::CKSSRot>(BaseElement b) { - return MetaModule::SlideSwitch{{b}, 2, "CKSS_rot_bg.png", "CKSS_rot_fg.png"}; + return MetaModule::SlideSwitch{{b, "CKSS_rot_bg.png"}, 2, "CKSS_rot_fg.png"}; } template<> inline Element make_element(BaseElement b) { - return MetaModule::Knob{{b}, "Rogan1PRed.png"}; + return MetaModule::Knob{b, "Rogan1PRed.png"}; } } // namespace MetaModule diff --git a/firmware/src/gui/elements/draw.hh b/firmware/src/gui/elements/draw.hh index 8b35aa816..a7a96c497 100644 --- a/firmware/src/gui/elements/draw.hh +++ b/firmware/src/gui/elements/draw.hh @@ -9,45 +9,29 @@ #include #include -namespace MetaModule -{ - -namespace ElementDrawerImpl +namespace MetaModule::ElementDrawer { inline lv_obj_t *draw_element(const BaseElement &, lv_obj_t *, uint32_t) { return nullptr; } -//TODO: once we move image into BaseElement, all these overloads go away -inline lv_obj_t *draw_element(const JackElement &el, lv_obj_t *canvas, uint32_t module_height) { - auto img = PNGFileSystem::read(el.image); - auto obj = draw_image(BaseElement(el), img, canvas, module_height); - return obj; -} - -inline lv_obj_t *draw_element(const Knob &el, lv_obj_t *canvas, uint32_t module_height) { - auto img = PNGFileSystem::read(el.image); - auto obj = draw_image(BaseElement(el), img, canvas, module_height); - return obj; -} - -inline lv_obj_t *draw_element(const Button &el, lv_obj_t *canvas, uint32_t module_height) { +inline lv_obj_t *draw_element(const ImageElement &el, lv_obj_t *canvas, uint32_t module_height) { auto img = PNGFileSystem::read(el.image); - auto obj = draw_image(BaseElement(el), img, canvas, module_height); + auto obj = ElementDrawerImpl::draw_image(BaseElement(el), img, canvas, module_height); return obj; } inline lv_obj_t *draw_element(const FlipSwitch &el, lv_obj_t *canvas, uint32_t module_height) { auto img = PNGFileSystem::read(el.frames[0]); - auto obj = draw_image(BaseElement(el), img, canvas, module_height); + auto obj = ElementDrawerImpl::draw_image(BaseElement(el), img, canvas, module_height); return obj; } // Draw slider with its handle as a sub-object inline lv_obj_t *draw_element(const Slider &el, lv_obj_t *canvas, uint32_t module_height) { - auto img = PNGFileSystem::read(el.image); - auto obj = draw_image(BaseElement(el), img, canvas, module_height); + auto body_img = PNGFileSystem::read(el.image); + auto obj = ElementDrawerImpl::draw_image(BaseElement(el), body_img, canvas, module_height); if (!obj) return nullptr; @@ -56,12 +40,12 @@ inline lv_obj_t *draw_element(const Slider &el, lv_obj_t *canvas, uint32_t modul handle = lv_img_create(obj); auto handle_img = PNGFileSystem::read(el.image_handle); if (handle_img) - draw_image(0, 0, Coords::TopLeft, handle_img, handle, module_height); + ElementDrawerImpl::draw_image(0, 0, Coords::TopLeft, handle_img, handle, module_height); else pr_err("No handle image found for %.*s!\n", (int)el.image_handle.size(), el.image_handle.data()); } else { - lv_coord_t w = img ? img->header.w : 5; - lv_coord_t h = img ? img->header.h : 5; + lv_coord_t w = body_img ? body_img->header.w : 5; + lv_coord_t h = body_img ? body_img->header.h : 5; handle = lv_obj_create(obj); if (w <= h) { // Vertical @@ -84,22 +68,22 @@ inline lv_obj_t *draw_element(const Slider &el, lv_obj_t *canvas, uint32_t modul //Draw slide switch with handle as a sub-object inline lv_obj_t *draw_element(const SlideSwitch &el, lv_obj_t *canvas, uint32_t module_height) { - auto body_img = PNGFileSystem::read(el.image_bg); + auto body_img = PNGFileSystem::read(el.image); if (body_img == nullptr) return nullptr; - auto obj = draw_image(BaseElement(el), body_img, canvas, module_height); + auto obj = ElementDrawerImpl::draw_image(BaseElement(el), body_img, canvas, module_height); lv_obj_t *handle; // Use image for handle, if image exists - if (el.image_fg.size()) { + if (el.image_handle.size()) { handle = lv_img_create(obj); - auto handle_img = PNGFileSystem::read(el.image_fg); + auto handle_img = PNGFileSystem::read(el.image_handle); if (handle_img) - draw_image(0, 0, Coords::TopLeft, handle_img, handle, module_height); + ElementDrawerImpl::draw_image(0, 0, Coords::TopLeft, handle_img, handle, module_height); else - pr_err("No handle image found for %.*s!\n", (int)el.image_fg.size(), el.image_fg.data()); + pr_err("No handle image found for %.*s!\n", (int)el.image_handle.size(), el.image_handle.data()); } else { // If there's no handle img, draw a handle with LVGL styles: @@ -119,16 +103,4 @@ inline lv_obj_t *draw_element(const SlideSwitch &el, lv_obj_t *canvas, uint32_t return obj; } -} // namespace ElementDrawerImpl - -struct ElementDrawer { - uint32_t module_height; - lv_obj_t *canvas; - - template - lv_obj_t *draw_element(T element) { - return ElementDrawerImpl::draw_element(element, canvas, module_height); - } -}; - -} // namespace MetaModule +} // namespace MetaModule::ElementDrawer diff --git a/firmware/src/gui/elements/module_drawer.hh b/firmware/src/gui/elements/module_drawer.hh index 91f616afb..daef60fbe 100644 --- a/firmware/src/gui/elements/module_drawer.hh +++ b/firmware/src/gui/elements/module_drawer.hh @@ -70,7 +70,6 @@ struct ModuleDrawer { // Draw module controls const auto moduleinfo = ModuleFactory::getModuleInfo(slug); - auto el_drawer = ElementDrawer{height, canvas}; //Reserve enough for what we will append drawn_elements.reserve(drawn_elements.size() + moduleinfo.elements.size()); @@ -78,9 +77,8 @@ struct ModuleDrawer { ElementCount::Indices indices{}; for (const auto &element : moduleinfo.elements) { auto element_ctx = std::visit( - [height = height, &el_drawer, &patch, &indices, module_idx, canvas, active_knob_set]( - auto &el) -> GuiElement { - auto obj = el_drawer.draw_element(el); + [height = height, &patch, &indices, module_idx, canvas, active_knob_set](auto &el) -> GuiElement { + auto obj = ElementDrawer::draw_element(el, canvas, height); auto mapping_id = ElementMapping::find_mapping(el, patch, module_idx, active_knob_set, indices); auto mapped_ring = MapRingDrawer::draw_mapped_ring(el, obj, canvas, mapping_id, height); diff --git a/firmware/src/gui/pages/manual_control_popup.hh b/firmware/src/gui/pages/manual_control_popup.hh index 6334f3468..f39b569d2 100644 --- a/firmware/src/gui/pages/manual_control_popup.hh +++ b/firmware/src/gui/pages/manual_control_popup.hh @@ -78,10 +78,10 @@ private: std::visit(overloaded{ // default: do nothing - [=](const BaseElement &) {}, + [](const BaseElement &) {}, // switches: increment value, wrapping - [=](const Switch &) { + [this](const Switch &) { auto new_value = lv_arc_get_value(ui_ControlArc) + 1; if (new_value > lv_arc_get_max_value(ui_ControlArc)) new_value = lv_arc_get_min_value(ui_ControlArc); @@ -90,13 +90,13 @@ private: }, // latching button: toggle state - [=](const LatchingButton &) { + [this](const LatchingButton &) { lv_arc_set_value(ui_ControlArc, lv_arc_get_value(ui_ControlArc) ? 0 : 1); arc_change_value(); }, // MomentaryButton: encoder press/release translated to button press/release - [=](const MomentaryButton &el) { + [this](const MomentaryButton &el) { lv_arc_set_value(ui_ControlArc, 1); arc_change_value(); }, @@ -112,7 +112,7 @@ private: std::visit(overloaded{ [](const BaseElement &) {}, - [=](const MomentaryButton &el) { + [this](const MomentaryButton &el) { lv_arc_set_value(ui_ControlArc, 0); arc_change_value(); }, diff --git a/firmware/tests/element_tests.cc b/firmware/tests/element_tests.cc index b4c28e56e..3781ead0c 100644 --- a/firmware/tests/element_tests.cc +++ b/firmware/tests/element_tests.cc @@ -9,10 +9,10 @@ struct TestInfo : MetaModule::ModuleInfoBase { using enum MetaModule::Coords; static constexpr std::array Elements{ - MetaModule::Slider{{{{1, 2, Center, "Slider1", ""}}}}, //Param 0 + MetaModule::Slider{{{{{1, 2, Center, "Slider1", ""}}}}}, //Param 0 MetaModule::GateJackInput4ms{{5, 6, Center, "Gate In 1", ""}}, //Input 0 MetaModule::RedLight{{5, 6, Center, "Gate In 1", ""}}, //Light 0 - MetaModule::EncoderRGB{{{{3, 4, Center, "Encoder RGB 1", ""}}}}, //Param 1, Lights 1,2,3 + MetaModule::EncoderRGB{{{{{3, 4, Center, "Encoder RGB 1", ""}}}}}, //Param 1, Lights 1,2,3 MetaModule::AnalogJackOutput4ms{{5, 6, Center, "Audio Out 1", ""}}, //Output 0 MetaModule::AnalogJackOutput4ms{{5, 7, Center, "Audio Out 2", ""}}, //Output 1 MetaModule::AnalogJackInput4ms{{4, 6, Center, "Audio In 1", ""}}, //Input 1 @@ -55,7 +55,7 @@ TEST_CASE("Can get param index") { constexpr auto Light2 = get(TestInfo::Elements[7]); constexpr auto SliderLED = get(TestInfo::Elements[8]); - constexpr auto NonExistingKnob = MetaModule::EncoderRGB{{{{1, 2, MetaModule::Coords::Center, "DNE", ""}}}}; + constexpr auto NonExistingKnob = MetaModule::EncoderRGB{{{{{1, 2, MetaModule::Coords::Center, "DNE", ""}}}}}; CHECK(ElementCount::get_indices(Slider1).value().param_idx == 0); CHECK(ElementCount::get_indices(Encoder1).value().param_idx == 1); @@ -152,8 +152,8 @@ struct DEVInfo : ModuleInfoBase { Toggle3pos{{to_mm<72>(50.49), to_mm<72>(41.905), Center, "Fall A Switch", ""}}, Toggle3pos{{to_mm<72>(179.89), to_mm<72>(41.905), Center, "Rise B Switch", ""}}, Toggle3pos{{to_mm<72>(212.77), to_mm<72>(41.905), Center, "Fall B Switch", ""}}, - LatchingButtonMonoLight{{to_mm<72>(82.8), to_mm<72>(41.64), Center, "Cycle A", ""}}, - LatchingButtonMonoLight{{to_mm<72>(147.61), to_mm<72>(41.68), Center, "Cycle B", ""}}, + LatchingButtonMonoLight{{{{to_mm<72>(82.8), to_mm<72>(41.64), Center, "Cycle A", ""}}}}, + LatchingButtonMonoLight{{{{to_mm<72>(147.61), to_mm<72>(41.68), Center, "Cycle B", ""}}}}, OrangeLight{{to_mm<72>(130.68), to_mm<72>(261.07), Center, "extra", ""}}, }}; diff --git a/shared/CoreModules/elements/4ms_elements.hh b/shared/CoreModules/elements/4ms_elements.hh index 411837248..b766b3b6e 100644 --- a/shared/CoreModules/elements/4ms_elements.hh +++ b/shared/CoreModules/elements/4ms_elements.hh @@ -12,21 +12,21 @@ using Color565 = uint16_t; struct Knob9mm : Knob { constexpr Knob9mm() = default; constexpr Knob9mm(BaseElement b) - : Knob{{b}, "knob9mm_x.png"} { + : Knob{b, "knob9mm_x.png"} { } }; struct DaviesLargeKnob : Knob { constexpr DaviesLargeKnob() = default; constexpr DaviesLargeKnob(BaseElement b) - : Knob{{b}, "knob_large_x.png"} { + : Knob{b, "knob_large_x.png"} { } }; struct Davies1900hBlackKnob : Knob { constexpr Davies1900hBlackKnob() = default; constexpr Davies1900hBlackKnob(BaseElement b) - : Knob{{b}, "knob_x.png"} { + : Knob{b, "knob_x.png"} { } }; @@ -36,14 +36,14 @@ struct Davies1900hBlackKnob : Knob { struct Slider25mmHorizLED : SliderLight { constexpr Slider25mmHorizLED() = default; constexpr Slider25mmHorizLED(BaseElement b) - : SliderLight{{{b}, "slider_horiz_x.png", ""}, 0xFFFF} { + : SliderLight{{{b, "slider_horiz_x.png"}, ""}, 0xFFFF} { } }; struct Slider25mmVertLED : SliderLight { constexpr Slider25mmVertLED() = default; constexpr Slider25mmVertLED(BaseElement b) - : SliderLight{{{b}, "slider_x.png", ""}, 0xFFFF} { + : SliderLight{{{b, "slider_x.png"}, ""}, 0xFFFF} { } }; @@ -52,28 +52,28 @@ struct Slider25mmVertLED : SliderLight { // struct OrangeButton : LatchingButton { constexpr OrangeButton(BaseElement b) - : LatchingButton{{{b}, "button_x.png"}, 0xfd40} { + : LatchingButton{{b, "button_x.png"}, 0xfd40} { } }; struct WhiteMomentary7mm : MomentaryButtonWhiteLight { constexpr WhiteMomentary7mm() = default; constexpr WhiteMomentary7mm(BaseElement b) - : MomentaryButtonWhiteLight{{{{b}, "button_x.png"}}} { + : MomentaryButtonWhiteLight{b, "button_x.png"} { } }; struct MomentaryRGB7mm : MomentaryButtonRGB { constexpr MomentaryRGB7mm() = default; constexpr MomentaryRGB7mm(BaseElement b) - : MomentaryButtonRGB{{{{b}, "button_x.png"}}} { + : MomentaryButtonRGB{b, "button_x.png"} { } }; struct MomentaryRGB5mm : MomentaryButtonRGB { constexpr MomentaryRGB5mm() = default; constexpr MomentaryRGB5mm(BaseElement b) - : MomentaryButtonRGB{{{{b}, "button_x.png"}}} { + : MomentaryButtonRGB{b, "button_x.png"} { } }; @@ -134,7 +134,7 @@ struct Toggle3posHoriz : FlipSwitch { struct Encoder9mmRGB : EncoderRGB { constexpr Encoder9mmRGB(BaseElement b) - : EncoderRGB{{{b}, "knob_unlined_x.png"}} { + : EncoderRGB{b, "knob_unlined_x.png"} { } }; @@ -144,12 +144,12 @@ struct Encoder9mmRGB : EncoderRGB { struct GateJackInput4ms : JackInput { constexpr GateJackInput4ms(BaseElement b) - : JackInput{{{b}, "jack_x.png"}} { + : JackInput{b, "jack_x.png"} { } }; struct AnalogJackInput4ms : JackInput { constexpr AnalogJackInput4ms(BaseElement b) - : JackInput{{{b}, "jack_x.png"}} { + : JackInput{b, "jack_x.png"} { } }; @@ -159,12 +159,12 @@ struct AnalogJackInput4ms : JackInput { struct GateJackOutput4ms : JackOutput { constexpr GateJackOutput4ms(BaseElement b) - : JackOutput{{{b}, "jack_x.png"}} { + : JackOutput{b, "jack_x.png"} { } }; struct AnalogJackOutput4ms : JackOutput { constexpr AnalogJackOutput4ms(BaseElement b) - : JackOutput{{{b}, "jack_x.png"}} { + : JackOutput{b, "jack_x.png"} { } }; @@ -174,31 +174,31 @@ struct AnalogJackOutput4ms : JackOutput { struct RedLight : MonoLight { constexpr RedLight(BaseElement b) - : MonoLight{{{b}, "led_x.png"}, 0xF800} { + : MonoLight{{b, "led_x.png"}, 0xF800} { } }; struct BlueLight : MonoLight { constexpr BlueLight(BaseElement b) - : MonoLight{{{b}, "led_x.png"}, 0x07E0} { + : MonoLight{{b, "led_x.png"}, 0x07E0} { } }; struct OrangeLight : MonoLight { constexpr OrangeLight(BaseElement b) - : MonoLight{{{b}, "led_x.png"}, 0xFD40} { + : MonoLight{{b, "led_x.png"}, 0xFD40} { } }; struct RedBlueLight : DualLight { constexpr RedBlueLight(BaseElement b) - : DualLight{{{b}, "led_x.png"}, {0xF800, 0x001F}} { + : DualLight{{b, "led_x.png"}, {0xF800, 0x001F}} { } }; struct RedGreenBlueLight : RgbLight { constexpr RedGreenBlueLight(BaseElement b) - : RgbLight{{{b}, "led_x.png"}} { + : RgbLight{{b, "led_x.png"}} { } }; diff --git a/shared/CoreModules/elements/base_element.hh b/shared/CoreModules/elements/base_element.hh index 4e04ab7ba..09b655c1f 100644 --- a/shared/CoreModules/elements/base_element.hh +++ b/shared/CoreModules/elements/base_element.hh @@ -45,10 +45,14 @@ struct BaseElement { using State_t = void; }; +struct ImageElement : BaseElement { + std::string_view image = ""; +}; + struct NullElement : BaseElement {}; // ParamElement: base class for pot, encoder, switch/button -struct ParamElement : BaseElement { +struct ParamElement : ImageElement { static constexpr size_t NumParams = 1; }; @@ -57,12 +61,9 @@ struct Pot : ParamElement { using State_t = float; }; -struct Knob : Pot { - std::string_view image = ""; -}; +struct Knob : Pot {}; struct Slider : Pot { - std::string_view image = ""; std::string_view image_handle = ""; }; @@ -74,9 +75,7 @@ struct SliderLight : Slider { // // Buttons // -struct Button : ParamElement { - std::string_view image = ""; -}; +struct Button : ParamElement {}; struct MomentaryButton : Button { enum class State_t { PRESSED, RELEASED }; @@ -125,25 +124,20 @@ struct FlipSwitch : Switch { struct SlideSwitch : Switch { using State_t = unsigned; State_t num_pos = 2; - std::string_view image_bg = ""; - std::string_view image_fg = ""; + std::string_view image_handle = ""; enum class Ascend { UpLeft, DownRight } direction = Ascend::DownRight; std::array pos_names{}; }; // Encoders -struct Encoder : ParamElement { - std::string_view image = ""; -}; +struct Encoder : ParamElement {}; struct EncoderRGB : Encoder { static constexpr size_t NumLights = 3; }; // Jacks -struct JackElement : BaseElement { - std::string_view image = ""; -}; +struct JackElement : ImageElement {}; struct JackInput : JackElement { static constexpr size_t NumInputs = 1; @@ -154,9 +148,7 @@ struct JackOutput : JackElement { }; // Lights -struct LightElement : BaseElement { - std::string_view image = ""; -}; +struct LightElement : ImageElement {}; struct MonoLight : LightElement { static constexpr size_t NumLights = 1; diff --git a/shared/CoreModules/tests/element_state_conversion_tests.cc b/shared/CoreModules/tests/element_state_conversion_tests.cc index ae1318f2e..eb7b5b798 100644 --- a/shared/CoreModules/tests/element_state_conversion_tests.cc +++ b/shared/CoreModules/tests/element_state_conversion_tests.cc @@ -5,7 +5,7 @@ TEST_CASE("Convert State SlideSwitch 7 pos") { unsigned num_pos = 7; - auto sw = MetaModule::SlideSwitch{MetaModule::BaseElement{}, num_pos}; + auto sw = MetaModule::SlideSwitch{MetaModule::BaseElement{}, "", num_pos}; //Positions: // 1/7 2/7 3/7 4/7 5/7 6/7 7/7 @@ -40,7 +40,7 @@ TEST_CASE("Convert State SlideSwitch 7 pos") { TEST_CASE("Convert State SlideSwitch 2 pos") { unsigned num_pos = 2; - auto sw = MetaModule::SlideSwitch{MetaModule::BaseElement{}, num_pos}; + auto sw = MetaModule::SlideSwitch{MetaModule::BaseElement{}, "", num_pos}; //Positions: // 1/2 2/2