diff --git a/src-ui/app/edit-screen/components/ModPane.cpp b/src-ui/app/edit-screen/components/ModPane.cpp index a2e65911..6ed5a31d 100644 --- a/src-ui/app/edit-screen/components/ModPane.cpp +++ b/src-ui/app/edit-screen/components/ModPane.cpp @@ -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 { @@ -52,8 +53,12 @@ template 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 @@ -157,7 +162,7 @@ template struct ModRow : juce::Component, HasEditor } }, row.depth); - depthRescaler = std::make_unique(depthAttachment.get()); + depthRescaler = std::make_unique(this, depthAttachment.get()); depth = std::make_unique(); depth->verticalReduction = 3; @@ -175,6 +180,12 @@ template 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); @@ -417,7 +428,8 @@ template 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}); } @@ -693,6 +705,60 @@ template 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(editor, this)); + + p.showMenuAsync(editor->defaultPopupMenuOptions()); + } }; template diff --git a/src-ui/app/shared/MenuValueTypein.cpp b/src-ui/app/shared/MenuValueTypein.cpp index 200341ca..dcbe2b15 100644 --- a/src-ui/app/shared/MenuValueTypein.cpp +++ b/src-ui/app/shared/MenuValueTypein.cpp @@ -31,28 +31,36 @@ namespace scxt::ui::app::shared { -MenuValueTypein::MenuValueTypein( - SCXTEditor *editor, - juce::Component::SafePointer under) - : HasEditor(editor), underComp(under), juce::PopupMenu::CustomComponent(false) +MenuValueTypeinBase::MenuValueTypeinBase(SCXTEditor *editor) + : HasEditor(editor), juce::PopupMenu::CustomComponent(false) { textEditor = std::make_unique(); - 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(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)); @@ -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(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 \ No newline at end of file diff --git a/src-ui/app/shared/MenuValueTypein.h b/src-ui/app/shared/MenuValueTypein.h index 513b4c85..42e07391 100644 --- a/src-ui/app/shared/MenuValueTypein.h +++ b/src-ui/app/shared/MenuValueTypein.h @@ -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 textEditor; - juce::Component::SafePointer underComp; - MenuValueTypein( - SCXTEditor *editor, - juce::Component::SafePointer under); + MenuValueTypeinBase(SCXTEditor *editor); void getIdealSize(int &w, int &h) override { @@ -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 underComp; + + MenuValueTypein( + SCXTEditor *editor, + juce::Component::SafePointer 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