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

Depth slider gets an RMB typein which is in the mdulation #1354

Merged
merged 2 commits into from
Sep 20, 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
72 changes: 69 additions & 3 deletions src-ui/app/edit-screen/components/ModPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "sst/jucegui/components/TextPushButton.h"
#include "sst/jucegui/components/Viewport.h"
#include "messaging/client/client_serial.h"
#include "app/shared/MenuValueTypein.h"

namespace scxt::ui::app::edit_screen
{
Expand All @@ -52,8 +53,12 @@ template <typename GZTrait> struct ModRow : juce::Component, HasEditor

struct ReScaler : sst::jucegui::data::Continuous
{
ModRow *parentRow{nullptr};
sst::jucegui::data::Continuous *under{nullptr};
ReScaler(sst::jucegui::data::Continuous *u) : under(u) {}
ReScaler(ModRow *parentRow, sst::jucegui::data::Continuous *u)
: parentRow(parentRow), under(u)
{
}

std::string getLabel() const override { return under->getLabel(); }
float scaleFromUnder(float f) const
Expand Down Expand Up @@ -157,7 +162,7 @@ template <typename GZTrait> struct ModRow : juce::Component, HasEditor
}
},
row.depth);
depthRescaler = std::make_unique<ReScaler>(depthAttachment.get());
depthRescaler = std::make_unique<ReScaler>(this, depthAttachment.get());
depth = std::make_unique<jcmp::HSliderFilled>();
depth->verticalReduction = 3;

Expand All @@ -175,6 +180,12 @@ template <typename GZTrait> struct ModRow : juce::Component, HasEditor
};
depth->onIdleHover = depth->onBeginEdit;
depth->onIdleHoverEnd = depth->onEndEdit;
depth->onPopupMenu = [w = juce::Component::SafePointer(this)](auto mods) {
if (!w)
return;
w->editor->hideTooltip();
w->showDepthPopup();
};

addAndMakeVisible(*depth);

Expand Down Expand Up @@ -417,7 +428,8 @@ template <typename GZTrait> struct ModRow : juce::Component, HasEditor
rDelta.rightAlignText = v->valUp;
}
rDepth.rowLeadingGlyph = jcmp::GlyphPainter::GlyphType::VOLUME;
rDepth.leftAlignText = fmt::format("{:.2f} %", at.value * 100);
// rDepth.leftAlignText = fmt::format("{} ({:.2f} %)", v->value, at.value * 100);
rDepth.leftAlignText = fmt::format("{}", v->value);
}
editor->setTooltipContents(lineOne, {rDepth, rDelta});
}
Expand Down Expand Up @@ -693,6 +705,60 @@ template <typename GZTrait> struct ModRow : juce::Component, HasEditor

p.showMenuAsync(editor->defaultPopupMenuOptions());
}

struct ModDepthTypein : shared::MenuValueTypeinBase
{
ModRow *row{nullptr};
ModDepthTypein(SCXTEditor *e, ModRow *r) : row(r), shared::MenuValueTypeinBase(e) {}

std::string getInitialText() const override
{
auto dv = row->depthAttachment->getValue();
auto ep = row->parent->routingTable.routes[row->index].extraPayload;
if (!ep.has_value())
return "Error";
auto md = ep->targetMetadata;

auto v = md.modulationNaturalToString(
ep->targetBaseValue, row->depthAttachment->value * (md.maxVal - md.minVal), false);

return v->value;
}
void setValueString(const std::string &s) override
{
auto dv = row->depthAttachment->getValue();
auto ep = row->parent->routingTable.routes[row->index].extraPayload;
if (!ep.has_value())
return;
auto md = ep->targetMetadata;

std::string emsg;
auto v = md.modulationNaturalFromString(s, ep->targetBaseValue, emsg);

if (!v.has_value())
{
SCLOG(emsg);
}

row->depthAttachment->setValueFromGUI(*v / (md.maxVal - md.minVal));
row->repaint();
return;
}
juce::Colour getValueColour() const override
{
return editor->themeColor(theme::ColorMap::accent_2b);
}
};
void showDepthPopup()
{
auto p = juce::PopupMenu();
p.addSectionHeader(target->getLabel());

p.addSeparator();
p.addCustomItem(-1, std::make_unique<ModDepthTypein>(editor, this));

p.showMenuAsync(editor->defaultPopupMenuOptions());
}
};

template <typename GZTrait>
Expand Down
53 changes: 27 additions & 26 deletions src-ui/app/shared/MenuValueTypein.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,36 @@
namespace scxt::ui::app::shared
{

MenuValueTypein::MenuValueTypein(
SCXTEditor *editor,
juce::Component::SafePointer<sst::jucegui::components::ContinuousParamEditor> under)
: HasEditor(editor), underComp(under), juce::PopupMenu::CustomComponent(false)
MenuValueTypeinBase::MenuValueTypeinBase(SCXTEditor *editor)
: HasEditor(editor), juce::PopupMenu::CustomComponent(false)
{
textEditor = std::make_unique<juce::TextEditor>();
textEditor->setText(under->continuous()->getValueAsString(),
juce::NotificationType::dontSendNotification);
textEditor->setWantsKeyboardFocus(true);
textEditor->addListener(this);
textEditor->setIndents(2, 0);

addAndMakeVisible(*textEditor);
}

void MenuValueTypeinBase::textEditorReturnKeyPressed(juce::TextEditor &ed)
{
auto s = ed.getText().toStdString();
setValueString(s);
triggerMenuItem();
}

juce::Colour MenuValueTypeinBase::getValueColour() const
{
auto valCol = editor->style()->getColour(
sst::jucegui::components::ContinuousParamEditor::Styles::styleClass,
sst::jucegui::components::ContinuousParamEditor::Styles::value);

if (auto styleCon =
dynamic_cast<sst::jucegui::style::StyleConsumer *>(underComp.getComponent()))
{
valCol =
styleCon->getColour(sst::jucegui::components::ContinuousParamEditor::Styles::value);
}
return valCol;
}

void MenuValueTypeinBase::setupTextEditorStyle()
{
auto valCol = getValueColour();

textEditor->setColour(juce::TextEditor::ColourIds::backgroundColourId, valCol.withAlpha(0.2f));
textEditor->setColour(juce::TextEditor::ColourIds::highlightColourId, valCol.withAlpha(0.32f));
Expand All @@ -65,25 +73,18 @@ MenuValueTypein::MenuValueTypein(
textEditor->applyColourToAllText(editor->themeColor(theme::ColorMap::generic_content_high),
true);
textEditor->applyFontToAllText(editor->themeApplier.interMediumFor(13), true);

addAndMakeVisible(*textEditor);
}

void MenuValueTypein::textEditorReturnKeyPressed(juce::TextEditor &ed)
juce::Colour MenuValueTypein::getValueColour() const
{
auto s = ed.getText().toStdString();
if (underComp && underComp->continuous())
auto valCol = MenuValueTypeinBase::getValueColour();
if (auto styleCon =
dynamic_cast<sst::jucegui::style::StyleConsumer *>(underComp.getComponent()))
{
if (s.empty())
{
underComp->continuous()->setValueFromGUI(underComp->continuous()->getDefaultValue());
}
else
{
underComp->continuous()->setValueAsString(s);
}
valCol =
styleCon->getColour(sst::jucegui::components::ContinuousParamEditor::Styles::value);
}
triggerMenuItem();
return valCol;
}

} // namespace scxt::ui::app::shared
49 changes: 44 additions & 5 deletions src-ui/app/shared/MenuValueTypein.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@
namespace scxt::ui::app::shared
{

struct MenuValueTypein : HasEditor, juce::PopupMenu::CustomComponent, juce::TextEditor::Listener
struct MenuValueTypeinBase : HasEditor, juce::PopupMenu::CustomComponent, juce::TextEditor::Listener
{
std::unique_ptr<juce::TextEditor> textEditor;
juce::Component::SafePointer<sst::jucegui::components::ContinuousParamEditor> underComp;
MenuValueTypein(
SCXTEditor *editor,
juce::Component::SafePointer<sst::jucegui::components::ContinuousParamEditor> under);
MenuValueTypeinBase(SCXTEditor *editor);

void getIdealSize(int &w, int &h) override
{
Expand All @@ -55,15 +52,57 @@ struct MenuValueTypein : HasEditor, juce::PopupMenu::CustomComponent, juce::Text
juce::Timer::callAfterDelay(2, [this]() {
if (textEditor->isVisible())
{
textEditor->setText(getInitialText(), juce::NotificationType::dontSendNotification);
setupTextEditorStyle();
textEditor->grabKeyboardFocus();
textEditor->selectAll();
}
});
}

virtual std::string getInitialText() const = 0;
virtual void setValueString(const std::string &) = 0;
virtual juce::Colour getValueColour() const;

void setupTextEditorStyle();

void textEditorReturnKeyPressed(juce::TextEditor &ed) override;
void textEditorEscapeKeyPressed(juce::TextEditor &) override { triggerMenuItem(); }
};

struct MenuValueTypein : MenuValueTypeinBase
{
juce::Component::SafePointer<sst::jucegui::components::ContinuousParamEditor> underComp;

MenuValueTypein(
SCXTEditor *editor,
juce::Component::SafePointer<sst::jucegui::components::ContinuousParamEditor> under)
: MenuValueTypeinBase(editor), underComp(under)
{
}

std::string getInitialText() const override
{
return underComp->continuous()->getValueAsString();
}

void setValueString(const std::string &s) override
{
if (underComp && underComp->continuous())
{
if (s.empty())
{
underComp->continuous()->setValueFromGUI(
underComp->continuous()->getDefaultValue());
}
else
{
underComp->continuous()->setValueAsString(s);
}
}
}

juce::Colour getValueColour() const override;
};
} // namespace scxt::ui::app::shared
#endif // MENUVALUETYPEIN_H
Loading