Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab State in Selection manager #1134

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/sst/sst-jucegui
1 change: 1 addition & 0 deletions src-ui/components/HeaderRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,5 @@ void HeaderRegion::showMultiSelectionMenu()
});
p.showMenuAsync(editor->defaultPopupMenuOptions(multiMenuButton.get()));
}

} // namespace scxt::ui
14 changes: 14 additions & 0 deletions src-ui/components/MixerScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void MixerScreen::selectBus(int index)
b->setSelected(false);
}
busPane->channelStrips[index]->selected = true;
editor->setTabSelection("mixer_screen", std::to_string(index));
repaint();
}

Expand Down Expand Up @@ -197,4 +198,17 @@ void MixerScreen::setVULevelForBusses(
}
}

void MixerScreen::onOtherTabSelection()
{
auto bs = editor->queryTabSelection("mixer_screen");
if (!bs.empty())
{
auto v = std::atoi(bs.c_str());
if (v >= 0 && v < busPane->channelStrips.size())
{
selectBus(v);
}
}
}

} // namespace scxt::ui
2 changes: 2 additions & 0 deletions src-ui/components/MixerScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ struct MixerScreen : juce::Component, HasEditor

void setVULevelForBusses(
const std::array<std::array<std::atomic<float>, 2>, engine::Patch::Busses::busCount> &x);

void onOtherTabSelection();
};
} // namespace scxt::ui
#endif // SHORTCIRCUIT_SENDFXSCREEN_H
38 changes: 38 additions & 0 deletions src-ui/components/MultiScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,44 @@ void MultiScreen::ZoneOrGroupElements<ZGTrait>::layoutInto(const juce::Rectangle
lfo->setBounds(envRect.withWidth(ew * 2).translated(ew * 2, 0));
}

void MultiScreen::onOtherTabSelection()
{
auto pgz = editor->queryTabSelection(tabKey("multi.pgz"));
if (pgz.empty())
{
}
if (pgz == "part")
parts->setSelectedTab(0);
else if (pgz == "group")
parts->setSelectedTab(1);
else if (pgz == "zone")
parts->setSelectedTab(2);
else
SCLOG("Unknown multi.pgz key " << pgz);

auto gts = editor->queryTabSelection(tabKey("multi.group.lfo"));
if (!gts.empty())
{
auto gt = std::atoi(gts.c_str());
if (gt >= 0 && gt < lfosPerGroup)
groupElements->lfo->selectTab(gt);
}
auto zts = editor->queryTabSelection(tabKey("multi.zone.lfo"));
if (!zts.empty())
{
auto zt = std::atoi(zts.c_str());
if (zt >= 0 && zt < lfosPerZone)
zoneElements->lfo->selectTab(zt);
}
auto mts = editor->queryTabSelection(tabKey("multi.mapping"));
if (!mts.empty())
{
auto mt = std::atoi(mts.c_str());
if (mt >= 0 && mt < 3)
sample->setSelectedTab(mt);
}
}

template struct MultiScreen::ZoneOrGroupElements<typename MultiScreen::ZoneTraits>;
template struct MultiScreen::ZoneOrGroupElements<typename MultiScreen::GroupTraits>;
} // namespace scxt::ui
5 changes: 5 additions & 0 deletions src-ui/components/MultiScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ struct MultiScreen : juce::Component, HasEditor
} selectionMode{SelectionMode::NONE};
void setSelectionMode(SelectionMode m);

void onOtherTabSelection();
// This allows us, in the future, to make this return s + selected part to have
// part differentiated selection
std::string tabKey(const std::string &s) { return s; }

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MultiScreen);
};
} // namespace scxt::ui
Expand Down
18 changes: 18 additions & 0 deletions src-ui/components/SCXTEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,35 @@ void SCXTEditor::setActiveScreen(ActiveScreen s)
activeScreen = s;
aboutScreen->setVisible(false);
logScreen->setVisible(false);
std::string val{};
switch (s)
{
case MULTI:
multiScreen->setVisible(true);
mixerScreen->setVisible(false);
playScreen->setVisible(false);
val = "multi";
resized();
break;

case MIXER:
multiScreen->setVisible(false);
mixerScreen->setVisible(true);
playScreen->setVisible(false);
val = "mixer";
resized();
break;

case PLAY:
multiScreen->setVisible(false);
mixerScreen->setVisible(false);
playScreen->setVisible(true);
val = "play";
resized();
break;
}

setTabSelection("main_screen", val);
repaint();
}

Expand Down Expand Up @@ -415,4 +421,16 @@ void SCXTEditor::resetColorsFromUserPreferences()
themeApplier.recolorStylesheetWith(std::move(cm), style());
}

std::string SCXTEditor::queryTabSelection(const std::string &k)
{
auto p = otherTabSelection.find(k);
if (p != otherTabSelection.end())
return p->second;
return {};
}

void SCXTEditor::setTabSelection(const std::string &k, const std::string &t)
{
sendToSerialization(messaging::client::UpdateOtherTabSelection({k, t}));
}
} // namespace scxt::ui
5 changes: 5 additions & 0 deletions src-ui/components/SCXTEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ struct SCXTEditor : sst::jucegui::components::WindowPanel, juce::DragAndDropCont
void onSelectedPart(const int16_t);
int16_t getSelectedPart() const;

selection::SelectionManager::otherTabSelection_t otherTabSelection;
void onOtherTabSelection(const scxt::selection::SelectionManager::otherTabSelection_t &p);
std::string queryTabSelection(const std::string &k);
void setTabSelection(const std::string &k, const std::string &t);

void onMixerBusEffectFullData(const scxt::messaging::client::busEffectFullData_t &);
void onMixerBusSendData(const scxt::messaging::client::busSendData_t &);

Expand Down
39 changes: 39 additions & 0 deletions src-ui/components/SCXTEditorResponseHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ void SCXTEditor::onSelectedPart(const int16_t p)
multiScreen->parts->selectedPartChanged();
if (multiScreen && multiScreen->sample)
multiScreen->sample->selectedPartChanged();
if (multiScreen)
multiScreen->onOtherTabSelection();

repaint();
}
Expand Down Expand Up @@ -350,4 +352,41 @@ void SCXTEditor::onMacroValue(const scxt::messaging::client::macroValue_t &s)
multiScreen->sample->repaint();
playScreen->repaint();
}

void SCXTEditor::onOtherTabSelection(
const scxt::selection::SelectionManager::otherTabSelection_t &p)
{
otherTabSelection = p;

auto mainScreen = queryTabSelection("main_screen");
if (mainScreen.empty())
{
}
else if (mainScreen == "mixer")
{
setActiveScreen(MIXER);
}
else if (mainScreen == "multi")
{
setActiveScreen(MULTI);
}
else if (mainScreen == "play")
{
setActiveScreen(PLAY);
}
else
{
SCLOG("Unknown main screen " << mainScreen);
}

if (mixerScreen)
{
mixerScreen->onOtherTabSelection();
}

if (multiScreen)
{
multiScreen->onOtherTabSelection();
}
}
} // namespace scxt::ui
3 changes: 3 additions & 0 deletions src-ui/components/multi/LFOPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

// Included so we can have UI-thread exceution for curve rendering
#include "modulation/modulators/steplfo.h"
#include "components/MultiScreen.h"

namespace scxt::ui::multi
{
Expand Down Expand Up @@ -712,6 +713,8 @@ void LfoPane::tabChanged(int i)
{
getContentAreaComponent()->removeAllChildren();
rebuildPanelComponents();
auto kn = std::string("multi") + (forZone ? ".zone.lfo" : ".group.lfo");
editor->setTabSelection(editor->multiScreen->tabKey(kn), std::to_string(i));
}

void LfoPane::setActive(int i, bool b)
Expand Down
22 changes: 17 additions & 5 deletions src-ui/components/multi/MappingPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "MappingPane.h"
#include "components/SCXTEditor.h"
#include "components/MultiScreen.h"
#include "components/multi/SingleMacroEditor.h"
#include "datamodel/metadata.h"
#include "selection/selection_manager.h"
Expand Down Expand Up @@ -2414,7 +2415,7 @@ struct SampleDisplay : juce::Component, HasEditor
for (const auto &entry : fs::directory_iterator(parent_path))
{
if (entry.is_regular_file() &&
browser::Browser::isLoadableSingleSample(entry.path()))
scxt::browser::Browser::isLoadableSingleSample(entry.path()))
{
v.push_back(entry.path().u8string());
}
Expand Down Expand Up @@ -2455,7 +2456,7 @@ struct SampleDisplay : juce::Component, HasEditor
void showFileBrowser()
{
std::string filePattern;
for (auto s : browser::Browser::LoadableFile::singleSample)
for (auto s : scxt::browser::Browser::LoadableFile::singleSample)
{
filePattern += "*" + s + ",";
}
Expand Down Expand Up @@ -3030,15 +3031,26 @@ MappingPane::MappingPane(SCXTEditor *e) : sst::jucegui::components::NamedPanel("
onTabSelected = [wt = juce::Component::SafePointer(this)](int i) {
if (wt)
{
wt->sampleDisplay->setVisible(i == 2);
wt->mappingDisplay->setVisible(i == 1);
wt->macroDisplay->setVisible(i == 0);
wt->setSelectedTab(i);
}
};
}

MappingPane::~MappingPane() {}

void MappingPane::setSelectedTab(int i)
{
if (i < 0 || i > 2)
return;
selectedTab = i;
sampleDisplay->setVisible(i == 2);
mappingDisplay->setVisible(i == 1);
macroDisplay->setVisible(i == 0);

repaint();
editor->setTabSelection(editor->multiScreen->tabKey("multi.mapping"), std::to_string(i));
}

void MappingPane::resized()
{
mappingDisplay->setBounds(getContentArea());
Expand Down
1 change: 1 addition & 0 deletions src-ui/components/multi/MappingPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct MappingPane : sst::jucegui::components::NamedPanel, HasEditor
void macroDataChanged(int part, int index);
void editorSelectionChanged();
void setActive(bool b);
void setSelectedTab(int i);

std::unique_ptr<MappingDisplay> mappingDisplay;
std::unique_ptr<SampleDisplay> sampleDisplay;
Expand Down
34 changes: 22 additions & 12 deletions src-ui/components/multi/PartGroupSidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,7 @@ PartGroupSidebar::PartGroupSidebar(SCXTEditor *e)
if (!w->partSidebar || !w->groupSidebar || !w->zoneSidebar)
return;

bool p = (t == 0), g = (t == 1), z = (t == 2);
w->partSidebar->setVisible(p);
w->groupSidebar->setVisible(g);
w->zoneSidebar->setVisible(z);

w->editor->multiScreen->setSelectionMode(g ? MultiScreen::SelectionMode::GROUP
: MultiScreen::SelectionMode::ZONE);

if (g)
w->editor->themeApplier.applyGroupMultiScreenTheme(w);
else
w->editor->themeApplier.applyZoneMultiScreenTheme(w);
w->setSelectedTab(t);
};
resetTabState();

Expand Down Expand Up @@ -455,4 +444,25 @@ void PartGroupSidebar::editorSelectionChanged()
}
repaint();
}

void PartGroupSidebar::setSelectedTab(int t)
{
selectedTab = t;
bool p = (t == 0), g = (t == 1), z = (t == 2);
partSidebar->setVisible(p);
groupSidebar->setVisible(g);
zoneSidebar->setVisible(z);

editor->multiScreen->setSelectionMode(g ? MultiScreen::SelectionMode::GROUP
: MultiScreen::SelectionMode::ZONE);

if (g)
editor->themeApplier.applyGroupMultiScreenTheme(this);
else
editor->themeApplier.applyZoneMultiScreenTheme(this);

editor->setTabSelection(editor->multiScreen->tabKey("multi.pgz"),
(t == 0 ? "part" : (t == 1 ? "group" : "zone")));
repaint();
}
} // namespace scxt::ui::multi
2 changes: 2 additions & 0 deletions src-ui/components/multi/PartGroupSidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct PartGroupSidebar : sst::jucegui::components::NamedPanel, HasEditor
void selectParts() {}
void selectGroups() {}

void setSelectedTab(int t); // part / group / zone

std::unique_ptr<ZoneSidebar> zoneSidebar;
std::unique_ptr<GroupSidebar> groupSidebar;
std::unique_ptr<PartSidebar> partSidebar;
Expand Down
1 change: 1 addition & 0 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ void Engine::sendFullRefreshToClient() const
getSelectionManager()->sendClientDataForLeadSelectionState();
getSelectionManager()->sendSelectedZonesToClient();
getSelectionManager()->sendSelectedPartMacrosToClient();
getSelectionManager()->sendOtherTabsSelectionToClient();
}

void Engine::clearAll()
Expand Down
3 changes: 3 additions & 0 deletions src/messaging/client/client_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ enum ClientToSerializationMessagesIds
c2s_request_host_callback,
c2s_macro_begin_end_edit,

c2s_set_othertab_selection,

num_clientToSerializationMessages
};

Expand Down Expand Up @@ -152,6 +154,7 @@ enum SerializationToClientMessageIds
s2c_send_selected_part,
s2c_send_selected_group_zone_mapping_summary,
s2c_send_selection_state,
s2c_send_othertab_selection,

s2c_bus_effect_full_data,
s2c_bus_send_data,
Expand Down
11 changes: 11 additions & 0 deletions src/messaging/client/selection_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ typedef std::tuple<std::optional<selection::SelectionManager::ZoneAddress>,
SERIAL_TO_CLIENT(SetSelectionState, s2c_send_selection_state, selectedStateMessage_t,
onSelectionState);

SERIAL_TO_CLIENT(SetOtherTabSelection, s2c_send_othertab_selection,
scxt::selection::SelectionManager::otherTabSelection_t, onOtherTabSelection);

using updateOther_t = std::pair<std::string, std::string>;
inline void doUpdateOtherTabSelection(const updateOther_t &pl, const engine::Engine &engine)
{
engine.getSelectionManager()->otherTabSelection[pl.first] = pl.second;
}
CLIENT_TO_SERIAL(UpdateOtherTabSelection, c2s_set_othertab_selection, updateOther_t,
doUpdateOtherTabSelection(payload, engine));

// Begin and End Edit messages. These are a mess. See #775
using editGestureFor_t = bool;
inline void doBeginEndEdit(bool isBegin, const editGestureFor_t &payload,
Expand Down
Loading
Loading