Skip to content

Commit

Permalink
Selection on Deleteion. Tab memory. (surge-synthesizer#1170)
Browse files Browse the repository at this point in the history
* Selection on Deleteion. Tab memory.

- Deleting the selected zone reliabl finds at least something
  else to be the selected zone. Closes surge-synthesizer#1151
- OutputInfo stored in otherTab persistence structure. Closes surge-synthesizer#1163
  • Loading branch information
baconpaul authored Aug 21, 2024
1 parent baf5211 commit 0babc62
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 17 deletions.
15 changes: 15 additions & 0 deletions src-ui/app/edit-screen/EditScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ void EditScreen::onOtherTabSelection()
if (zt >= 0 && zt < lfosPerZone)
zoneElements->lfo->selectTab(zt);
}

gts = editor->queryTabSelection(tabKey("multi.group.output"));
if (!gts.empty())
{
auto gt = std::atoi(gts.c_str());
if (gt >= 0 && gt < lfosPerGroup)
groupElements->outPane->selectTab(gt);
}
zts = editor->queryTabSelection(tabKey("multi.zone.output"));
if (!zts.empty())
{
auto zt = std::atoi(zts.c_str());
if (zt >= 0 && zt < lfosPerZone)
zoneElements->outPane->selectTab(zt);
}
auto mts = editor->queryTabSelection(tabKey("multi.mapping"));
if (!mts.empty())
{
Expand Down
28 changes: 18 additions & 10 deletions src-ui/app/edit-screen/components/OutputPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "connectors/PayloadDataAttachment.h"
#include "datamodel/metadata.h"
#include "theme/Layout.h"
#include "app/edit-screen/EditScreen.h"

namespace scxt::ui::app::edit_screen
{
Expand Down Expand Up @@ -297,22 +298,29 @@ OutputPane<OTTraits>::OutputPane(SCXTEditor *e) : jcmp::NamedPanel(""), HasEdito
onTabSelected = [wt = juce::Component::SafePointer(this)](int i) {
if (!wt)
return;
if ((OTTraits::forZone && i == 1) || (!OTTraits::forZone && i == 0))
{
wt->output->setVisible(wt->active);
wt->proc->setVisible(false);
}
else
{
wt->output->setVisible(false);
wt->proc->setVisible(wt->active);
}
wt->setSelectedTab(i);
};
onTabSelected(selectedTab);
}

template <typename OTTraits> OutputPane<OTTraits>::~OutputPane() {}

template <typename OTTraits> void OutputPane<OTTraits>::setSelectedTab(int i)
{
if ((OTTraits::forZone && i == 1) || (!OTTraits::forZone && i == 0))
{
output->setVisible(active);
proc->setVisible(false);
}
else
{
output->setVisible(false);
proc->setVisible(active);
}
auto kn = std::string("multi") + (OTTraits::forZone ? ".zone.output" : ".group.output");
editor->setTabSelection(editor->editScreen->tabKey(kn), std::to_string(i));
}

template <typename OTTraits> void OutputPane<OTTraits>::resized()
{
output->setBounds(getContentArea());
Expand Down
2 changes: 2 additions & 0 deletions src-ui/app/edit-screen/components/OutputPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ template <typename OTTraits> struct OutputPane : sst::jucegui::components::Named
void updateFromProcessorPanes();
std::array<juce::Component::SafePointer<ProcessorPane>, scxt::processorsPerZoneAndGroup>
procWeakRefs;

void setSelectedTab(int i);
};
} // namespace scxt::ui::app::edit_screen
#endif // SHORTCIRCUIT_MAPPINGPANE_H
10 changes: 6 additions & 4 deletions src/messaging/client/structure_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ inline void removeZone(const selection::SelectionManager::ZoneAddress &a, engine
},
[t = a](auto &engine) {
engine.getSampleManager()->purgeUnreferencedSamples();
engine.getSelectionManager()->guaranteeConsistencyAfterDeletes(engine);
engine.getSelectionManager()->guaranteeConsistencyAfterDeletes(engine, true, t);
serializationSendToClient(s2c_send_pgz_structure, engine.getPartGroupZoneStructure(),
*(engine.getMessageController()));
serializationSendToClient(s2c_send_selected_group_zone_mapping_summary,
Expand Down Expand Up @@ -202,7 +202,8 @@ inline void removeSelectedZones(const bool &, engine::Engine &engine, MessageCon
},
[t = part](auto &engine) {
engine.getSampleManager()->purgeUnreferencedSamples();
engine.getSelectionManager()->guaranteeConsistencyAfterDeletes(engine);
engine.getSelectionManager()->guaranteeConsistencyAfterDeletes(engine, true,
{t, -1, -1});

serializationSendToClient(s2c_send_pgz_structure, engine.getPartGroupZoneStructure(),
*(engine.getMessageController()));
Expand Down Expand Up @@ -237,7 +238,7 @@ inline void removeGroup(const selection::SelectionManager::ZoneAddress &a, engin
},
[t = a](auto &engine) {
engine.getSampleManager()->purgeUnreferencedSamples();
engine.getSelectionManager()->guaranteeConsistencyAfterDeletes(engine);
engine.getSelectionManager()->guaranteeConsistencyAfterDeletes(engine, false, t);

serializationSendToClient(s2c_send_pgz_structure, engine.getPartGroupZoneStructure(),
*(engine.getMessageController()));
Expand All @@ -264,7 +265,8 @@ inline void clearPart(const int p, engine::Engine &engine, MessageController &co
},
[pt = p](auto &engine) {
engine.getSampleManager()->purgeUnreferencedSamples();
engine.getSelectionManager()->guaranteeConsistencyAfterDeletes(engine);
engine.getSelectionManager()->guaranteeConsistencyAfterDeletes(engine, false,
{pt, -1, -1});

serializationSendToClient(s2c_send_pgz_structure, engine.getPartGroupZoneStructure(),
*(engine.getMessageController()));
Expand Down
47 changes: 45 additions & 2 deletions src/selection/selection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ void SelectionManager::adjustInternalStateForAction(
}
}

void SelectionManager::guaranteeConsistencyAfterDeletes(const engine::Engine &engine)
void SelectionManager::guaranteeConsistencyAfterDeletes(const engine::Engine &engine,
bool zoneDeleted,
const ZoneAddress &whatIDeleted)
{
bool morphed{false};
auto zit = allSelectedZones[selectedPart].begin();
Expand Down Expand Up @@ -296,13 +298,54 @@ void SelectionManager::guaranteeConsistencyAfterDeletes(const engine::Engine &en

if (morphed)
{
guaranteeSelectedLead();
auto [p, g, z] = whatIDeleted;
guaranteeSelectedLeadSomewhereIn(p, (zoneDeleted ? g : -1), -1);
sendClientDataForLeadSelectionState();
sendSelectedZonesToClient();
debugDumpSelectionState();
}
}

void SelectionManager::guaranteeSelectedLeadSomewhereIn(int part, int group, int zone)
{
guaranteeSelectedLead();
if (leadZone[selectedPart] == ZoneAddress())
{
const auto &partO = engine.getPatch()->getPart(part);
bool gotOne{false};
if (!partO->getGroups().empty())
{
if (group >= 0 && group < partO->getGroups().size())
{
auto &groupO = partO->getGroup(group);
if (!groupO->getZones().empty())
{
leadZone[selectedPart] = {part, group, 0};
leadGroup[selectedPart] = {part, group, -1};
gotOne = true;
}
}
if (!gotOne)
{
auto gs = partO->getGroups().size();
for (int i = 0; i < gs && !gotOne; ++i)
{
if (!partO->getGroup(i)->getZones().empty())
{
leadZone[selectedPart] = {part, i, 0};
leadGroup[selectedPart] = {part, group, -1};
gotOne = true;
}
}
}
if (gotOne)
{
guaranteeSelectedLead();
}
}
}
}

void SelectionManager::guaranteeSelectedLead()
{
// Now at the end of this the lead zone could not be selected
Expand Down
4 changes: 3 additions & 1 deletion src/selection/selection_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ struct SelectionManager

void selectAction(const SelectActionContents &z);
void multiSelectAction(const std::vector<SelectActionContents> &v);
void guaranteeConsistencyAfterDeletes(const engine::Engine &);
void guaranteeConsistencyAfterDeletes(const engine::Engine &, bool zoneDeleted,
const ZoneAddress &addressDeleted);
void selectPart(int16_t part);
void clearAllSelections();

protected:
void adjustInternalStateForAction(const SelectActionContents &);
void guaranteeSelectedLead();
void guaranteeSelectedLeadSomewhereIn(int part, int group, int zone);
void debugDumpSelectionState();

public:
Expand Down

0 comments on commit 0babc62

Please sign in to comment.