Skip to content

Commit

Permalink
Move mirror options to a submenu & only list hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
Dewb committed Sep 17, 2023
1 parent c5f89a2 commit 1c080e5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/common/core/GridConnection/GridConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct Grid
virtual void updateQuadrant(int x, int y, uint8_t* leds) = 0;
virtual void updateRing(int n, uint8_t leds[64]) = 0;
virtual void clearAll() = 0;
virtual bool isHardware() = 0;
};

struct GridConsumer
Expand Down
10 changes: 8 additions & 2 deletions src/common/core/GridConnection/GridConnectionMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void menuUserReacquireGrid(GridConsumer* consumer, std::string lastDeviceId, Act
}
}

void appendDeviceConnectionMenu(rack::Menu* menu, GridConsumer* consumer, ActionQueue* actionQueue)
void appendDeviceConnectionMenu(rack::Menu* menu, GridConsumer* consumer, ActionQueue* actionQueue, bool hardwareOnly)
{
std::string currentConnectedDeviceId = consumer->gridGetCurrentDeviceId();
std::string lastConnectedDeviceId = consumer->gridGetLastDeviceId(false);
Expand Down Expand Up @@ -70,6 +70,11 @@ void appendDeviceConnectionMenu(rack::Menu* menu, GridConsumer* consumer, Action
bool preferredDeviceFound = false;
for (Grid* grid : GridConnectionManager::get().getGrids())
{
if (hardwareOnly && !grid->isHardware())
{
continue;
}

auto connectItem = new NewConnectGridItem();
connectItem->text = "" + grid->getDevice().type + " (" + grid->getDevice().id + ") ";

Expand All @@ -96,7 +101,8 @@ void appendDeviceConnectionMenu(rack::Menu* menu, GridConsumer* consumer, Action

if (deviceCount == 0)
{
menu->addChild(construct<MenuLabel>(&MenuLabel::text, " (no physical or virtual devices found)"));
std::string message = hardwareOnly ? "no hardware devices found" : "no hardware or virtual devices found";
menu->addChild(construct<MenuLabel>(&MenuLabel::text, " (" + message + ")"));
}

if (currentConnectedDeviceId == "" && lastConnectedDeviceId != "")
Expand Down
2 changes: 1 addition & 1 deletion src/common/core/GridConnection/GridConnectionMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#include "GridConnection.hpp"
#include "ActionQueue.hpp"

void appendDeviceConnectionMenu(rack::Menu* menu, GridConsumer* consumer, ActionQueue* queue);
void appendDeviceConnectionMenu(rack::Menu* menu, GridConsumer* consumer, ActionQueue* queue, bool hardwareOnly = false);
1 change: 1 addition & 0 deletions src/common/core/GridConnection/SerialOscGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ struct SerialOscGrid : Grid
void updateQuadrant(int x, int y, uint8_t* leds) override;
void updateRing(int n, uint8_t leds[64]) override;
void clearAll() override;
bool isHardware() override { return true; }
};
1 change: 1 addition & 0 deletions src/virtualgrid/VirtualGridModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct VirtualGridModule : rack::Module, Grid
void updateQuadrant(int x_offset, int y_offset, uint8_t* leds) override;
void updateRing(int n, uint8_t leds[64]) override {};
void clearAll() override;
bool isHardware() override { return false; }

GridConsumer* mirrorModeConsumer;
ActionQueue audioThreadActions;
Expand Down
8 changes: 6 additions & 2 deletions src/virtualgrid/VirtualGridWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,16 @@ void VirtualGridWidget::appendContextMenu(Menu * menu)
screenshotModulePNG(this, "grid-screenshot.png");
}));

appendDeviceConnectionMenu(menu, grid->mirrorModeConsumer, &grid->audioThreadActions);
menu->addChild(createSubmenuItem("Mirror hardware grid", "", [=](Menu *childMenu) {
appendDeviceConnectionMenu(childMenu, grid->mirrorModeConsumer, &grid->audioThreadActions, true);
}));

menu->addChild(new MenuSeparator());
menu->addChild(createIndexPtrSubmenuItem("Theme", { "Red", "Orange", "Yellow", "White" }, &grid->theme));
menu->addChild(createIndexSubmenuItem("Protocol", {"40h", "Series", "Mext (varibright)"},
[=]() { return grid ? grid->device.protocol : 0; },
[=]() {
return grid ? grid->device.protocol : 0;
},
[=](size_t index) {
setProtocol(grid, static_cast<MonomeProtocol>(index));
}));
Expand Down

0 comments on commit 1c080e5

Please sign in to comment.