Skip to content

Commit

Permalink
Add a data cache; add a cross-editor subscription (#1424)
Browse files Browse the repository at this point in the history
* Add a data cache; add a cross-editor subscription

Basically make it so shared ui data has a place to live
and that editors on it can detect they are multiple and
show you the changes.

Applied right now to group pan and amplitude only but its
all generalizable.

* Duh - do that properly
  • Loading branch information
baconpaul authored Oct 17, 2024
1 parent 8cc78bd commit 186719a
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 20 deletions.
2 changes: 1 addition & 1 deletion libs/sst/sst-jucegui
1 change: 1 addition & 0 deletions src-ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(${PROJECT_NAME} STATIC
app/editor-impl/SCXTEditor.cpp
app/editor-impl/SCXTEditorMenus.cpp
app/editor-impl/SCXTEditorResponseHandlers.cpp
app/editor-impl/SCXTEditorDataCache.cpp

app/edit-screen/EditScreen.cpp
app/edit-screen/components/AdsrPane.cpp
Expand Down
2 changes: 2 additions & 0 deletions src-ui/app/HasEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct HasEditor
template <typename T> void updateValueTooltip(const T &attachment);
template <typename W, typename A>
void setupWidgetForValueTooltip(W *widget, const A &attachment);

template <typename P, typename A> void addSubscription(const P &, A &);
};
} // namespace scxt::ui::app
#endif // SHORTCIRCUIT_HASEDITOR_H
26 changes: 25 additions & 1 deletion src-ui/app/SCXTEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include "app/editor-impl/SCXTJuceLookAndFeel.h"
#include "engine/engine.h"
#include "engine/patch.h"
#include "messaging/client/selection_messages.h"
#include "messaging/messaging.h"
#include "selection/selection_manager.h"
Expand All @@ -46,10 +45,13 @@
#include "messaging/client/zone_messages.h"
#include "browser/browser.h"

#include "SCXTEditorDataCache.h"
#include "HasEditor.h"

#include "theme/ThemeApplier.h"

#include "connectors/PayloadDataAttachment.h"

namespace melatonin
{
class Inspector;
Expand Down Expand Up @@ -125,6 +127,12 @@ struct SCXTEditor : sst::jucegui::components::WindowPanel, juce::DragAndDropCont
juce::Colour themeColor(scxt::ui::theme::ColorMap::Colors, float alpha = 1.f) const;
void resetColorsFromUserPreferences();

/*
* See the comment in SCXTEditorDataCache for more on this class. Shared space to
* cache the UI data types
*/
SCXTEditorDataCache editorDataCache;

sst::basic_blocks::dsp::RNG rng;

static constexpr int edWidth{1186}, edHeight{816};
Expand Down Expand Up @@ -367,6 +375,22 @@ inline void HasEditor::setupWidgetForValueTooltip(W *w, const A &a)
};
}
}

template <typename P, typename A> void HasEditor::addSubscription(const P &p, A &a)
{
auto *dc = &editor->editorDataCache;
auto dce = dc + sizeof(SCXTEditorDataCache);
if ((size_t)&p >= (size_t)dc && (size_t)&p < (size_t)dce)
{
auto *edCopy = editor;
auto *vp = (void *)&p;

connectors::addGuiStep(*a, [edCopy, vp, f = a.get()](auto &) {
edCopy->editorDataCache.fireSubscription(vp, f);
});
editor->editorDataCache.addSubscription(vp, a.get());
}
}
} // namespace scxt::ui::app

#endif // SCXT_SRC_UI_COMPONENTS_SCXTEDITOR_H
91 changes: 91 additions & 0 deletions src-ui/app/SCXTEditorDataCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Shortcircuit XT - a Surge Synth Team product
*
* A fully featured creative sampler, available as a standalone
* and plugin for multiple platforms.
*
* Copyright 2019 - 2024, Various authors, as described in the github
* transaction log.
*
* ShortcircuitXT is released under the Gnu General Public Licence
* V3 or later (GPL-3.0-or-later). The license is found in the file
* "LICENSE" in the root of this repository or at
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* Individual sections of code which comprises ShortcircuitXT in this
* repository may also be used under an MIT license. Please see the
* section "Licensing" in "README.md" for details.
*
* ShortcircuitXT is inspired by, and shares code with, the
* commercial product Shortcircuit 1 and 2, released by VemberTech
* in the mid 2000s. The code for Shortcircuit 2 was opensourced in
* 2020 at the outset of this project.
*
* All source for ShortcircuitXT is available at
* https://github.com/surge-synthesizer/shortcircuit-xt
*/

#ifndef SCXT_SRC_UI_APP_SCXTEDITORDATACACHE_H
#define SCXT_SRC_UI_APP_SCXTEDITORDATACACHE_H

#include <unordered_map>
#include <unordered_set>

#include "engine/bus.h"
#include "engine/part.h"
#include "engine/group.h"
#include "engine/zone.h"
#include "engine/patch.h"

#include "sst/jucegui/data/Continuous.h"
#include "sst/jucegui/data/Discrete.h"

namespace scxt::ui::app
{
/**
* The iriginal design of the SC UI (which is still partly that way) has local copies
* of the data cache right next to the particular panel. This works well until you want
* to share data across more than one panel, and then it gets clumsy, or if your heirarchy
* gets deep.
*
* So this class exists to have a place for the SCXTEditorResonder thingy to push data
* copies and for hte UI to bind to, since the UI will reliably be components which
* haveeditor.
*/
struct SCXTEditorDataCache
{
// Displayed group tab output info
scxt::engine::Group::GroupOutputInfo groupOutputInfo;
// Displayed zone tab output info
scxt::engine::Zone::ZoneOutputInfo zoneOutputInfo;

void addSubscription(void *el, sst::jucegui::data::Continuous *);
void addSubscription(void *el, sst::jucegui::data::Discrete *);
void fireSubscription(void *el, sst::jucegui::data::Continuous *);
void fireSubscription(void *el, sst::jucegui::data::Discrete *);

private:
std::unordered_map<void *, std::unordered_set<sst::jucegui::data::Continuous *>> csubs;
std::unordered_map<void *, std::unordered_set<sst::jucegui::data::Discrete *>> dsubs;

struct CListener : sst::jucegui::data::Continuous::DataListener
{
SCXTEditorDataCache &cache;
CListener(SCXTEditorDataCache &dc) : cache(dc){};
virtual ~CListener() = default;
void dataChanged() override{};
void sourceVanished(sst::jucegui::data::Continuous *c) override;
} clistener{*this};

struct DListener : sst::jucegui::data::Discrete::DataListener
{
SCXTEditorDataCache &cache;
DListener(SCXTEditorDataCache &dc) : cache(dc){};
virtual ~DListener() = default;
void dataChanged() override{};
void sourceVanished(sst::jucegui::data::Discrete *c) override;
} dlistener{*this};
};
} // namespace scxt::ui::app

#endif // SCXTEDITORDATACACHE_H
11 changes: 7 additions & 4 deletions src-ui/app/edit-screen/components/GroupSettingsCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@

#include "GroupSettingsCard.h"
#include "app/SCXTEditor.h"
#include "connectors/PayloadDataAttachment.h"

namespace scxt::ui::app::edit_screen
{
namespace jcmp = sst::jucegui::components;

GroupSettingsCard::GroupSettingsCard(SCXTEditor *e) : HasEditor(e)
GroupSettingsCard::GroupSettingsCard(SCXTEditor *e)
: HasEditor(e), info(e->editorDataCache.groupOutputInfo)
{
using fac = connectors::SingleValueFactory<attachment_t, floatMsg_t>;

auto mkg = [this](auto gl) {
auto res = std::make_unique<jcmp::GlyphPainter>(gl);
addAndMakeVisible(*res);
Expand Down Expand Up @@ -67,9 +69,10 @@ GroupSettingsCard::GroupSettingsCard(SCXTEditor *e) : HasEditor(e)
glideDrag = mkd('gdrg', "Glide");

volGlyph = mkg(jcmp::GlyphPainter::GlyphType::VOLUME);
volDrag = mkd('grvl', "Volume");
fac::attachAndAdd(info, info.amplitude, this, volAttachment, volDrag);
panGlyph = mkg(jcmp::GlyphPainter::GlyphType::PAN);
panDrag = mkd('grpn', "Pan");
fac::attachAndAdd(info, info.pan, this, panAttachment, panDrag);

tuneGlyph = mkg(jcmp::GlyphPainter::GlyphType::TUNING);
tuneDrag = mkd('grtn', "Tune");
}
Expand Down
10 changes: 10 additions & 0 deletions src-ui/app/edit-screen/components/GroupSettingsCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include "sst/jucegui/components/Label.h"
#include "sst/jucegui/components/GlyphButton.h"

#include "messaging/messaging.h"
#include "connectors/PayloadDataAttachment.h"

#include "app/HasEditor.h"

namespace scxt::ui::app::edit_screen
Expand All @@ -52,6 +55,13 @@ struct GroupSettingsCard : juce::Component, HasEditor
glideMenu, srcMenu;
std::unique_ptr<sst::jucegui::components::DraggableTextEditableValue> pbDnVal, pbUpDrag,
glideDrag, volDrag, panDrag, tuneDrag;

using floatMsg_t = scxt::messaging::client::UpdateGroupOutputFloatValue;
typedef connectors::PayloadDataAttachment<engine::Group::GroupOutputInfo> attachment_t;

std::unique_ptr<attachment_t> volAttachment, panAttachment;

engine::Group::GroupOutputInfo &info;
};
} // namespace scxt::ui::app::edit_screen
#endif // GROUPSETTINGSCARD_H
25 changes: 17 additions & 8 deletions src-ui/app/edit-screen/components/OutputPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ namespace scxt::ui::app::edit_screen
namespace jcmp = sst::jucegui::components;
namespace cmsg = scxt::messaging::client;

engine::Zone::ZoneOutputInfo &OutPaneZoneTraits::outputInfo(SCXTEditor *e)
{
return e->editorDataCache.zoneOutputInfo;
}

engine::Group::GroupOutputInfo &OutPaneGroupTraits::outputInfo(SCXTEditor *e)
{
return e->editorDataCache.groupOutputInfo;
}

template <typename OTTraits> struct ProcTab : juce::Component, HasEditor
{
OutputPane<OTTraits> *outputPane{nullptr};
std::unique_ptr<jcmp::MenuButton> procRouting;

ProcTab(SCXTEditor *e, OutputPane<OTTraits> *pane) : HasEditor(e), outputPane(pane)
ProcTab(SCXTEditor *e, OutputPane<OTTraits> *pane)
: HasEditor(e), outputPane(pane), info(OTTraits::outputInfo(e))
{
procRouting = std::make_unique<jcmp::MenuButton>();
procRouting->setLabel(OTTraits::defaultRoutingLocationName);
Expand Down Expand Up @@ -148,7 +159,7 @@ template <typename OTTraits> struct ProcTab : juce::Component, HasEditor
}
}

typename OTTraits::info_t info;
typename OTTraits::info_t &info;
};

template <typename OTTraits> struct OutputTab : juce::Component, HasEditor
Expand All @@ -165,7 +176,8 @@ template <typename OTTraits> struct OutputTab : juce::Component, HasEditor
std::unique_ptr<bool_attachment_t> oversampleAttachment;
std::unique_ptr<jcmp::ToggleButton> oversampleButton;

OutputTab(SCXTEditor *e, OutputPane<OTTraits> *p) : HasEditor(e), parent(p)
OutputTab(SCXTEditor *e, OutputPane<OTTraits> *p)
: HasEditor(e), parent(p), info(OTTraits::outputInfo(e))
{
using fac = connectors::SingleValueFactory<attachment_t, typename OTTraits::floatMsg_t>;

Expand Down Expand Up @@ -272,7 +284,7 @@ template <typename OTTraits> struct OutputTab : juce::Component, HasEditor
}
p.showMenuAsync(editor->defaultPopupMenuOptions());
}
typename OTTraits::info_t info;
typename OTTraits::info_t &info;
};

template <typename OTTraits>
Expand Down Expand Up @@ -333,14 +345,11 @@ template <typename OTTraits> void OutputPane<OTTraits>::setActive(bool b)
onTabSelected(selectedTab);
}

template <typename OTTraits>
void OutputPane<OTTraits>::setOutputData(const typename OTTraits::info_t &d)
template <typename OTTraits> void OutputPane<OTTraits>::updateFromOutputInfo()
{
output->info = d;
output->updateRoutingLabel();
output->repaint();

proc->info = d;
proc->updateProcRoutingLabel();
proc->repaint();
}
Expand Down
7 changes: 6 additions & 1 deletion src-ui/app/edit-screen/components/OutputPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct OutPaneZoneTraits

using floatMsg_t = scxt::messaging::client::UpdateZoneOutputFloatValue;
using int16Msg_t = scxt::messaging::client::UpdateZoneOutputInt16TValue;

static engine::Zone::ZoneOutputInfo &outputInfo(SCXTEditor *e);
};

struct OutPaneGroupTraits
Expand All @@ -58,6 +60,8 @@ struct OutPaneGroupTraits

using floatMsg_t = scxt::messaging::client::UpdateGroupOutputFloatValue;
using int16Msg_t = scxt::messaging::client::UpdateGroupOutputInt16TValue;

static engine::Group::GroupOutputInfo &outputInfo(SCXTEditor *e);
};
template <typename OTTraits> struct OutputTab;
template <typename OTTraits> struct ProcTab;
Expand All @@ -69,7 +73,8 @@ template <typename OTTraits> struct OutputPane : sst::jucegui::components::Named

void resized() override;
void setActive(bool);
void setOutputData(const typename OTTraits::info_t &);

void updateFromOutputInfo();

std::unique_ptr<OutputTab<OTTraits>> output;
std::unique_ptr<ProcTab<OTTraits>> proc;
Expand Down
Loading

0 comments on commit 186719a

Please sign in to comment.