Skip to content

Commit

Permalink
Add copy to clipboard to ModList
Browse files Browse the repository at this point in the history
puts a human readable version of the modlist into the clipboard
for sharing with other humans.

Closes surge-synthesizer#6577
  • Loading branch information
baconpaul committed Jan 8, 2023
1 parent 2039036 commit 155b165
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/surge-xt/gui/overlays/ModulationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ struct ModulationSideControls : public juce::Component,
dispW->setValue(dwv / 3.0);
dispW->setDraggable(true);
valueChanged(dispW.get());

copyW = std::make_unique<Surge::Widgets::SelfDrawButton>("Copy to Clipboard");
copyW->setAccessible(true);
copyW->setStorage(&(editor->synth->storage));
copyW->setTitle("Copy to Clipboard");
copyW->setDescription("Copy to Clipboard");
copyW->setSkin(skin);
copyW->onClick = [this]() { doCopyToClipboard(); };
addAndMakeVisible(*copyW);
}

void resized() override
Expand Down Expand Up @@ -162,6 +171,9 @@ struct ModulationSideControls : public juce::Component,
dispL->setBounds(b);
b = b.translated(0, h);
dispW->setBounds(b.withHeight(h * 4));

b = b.translated(0, h * 4.5 + m);
copyW->setBounds(b);
}

void paint(juce::Graphics &g) override
Expand Down Expand Up @@ -241,9 +253,12 @@ struct ModulationSideControls : public juce::Component,
}
}

void doCopyToClipboard();

std::unique_ptr<juce::Label> sortL, filterL, addL, dispL;
std::unique_ptr<Surge::Widgets::MultiSwitchSelfDraw> sortW, filterW, addSourceW, addTargetW,
dispW;
std::unique_ptr<Surge::Widgets::SelfDrawButton> copyW;
SurgeGUIEditor *sge;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ModulationSideControls);
Expand Down Expand Up @@ -515,7 +530,8 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC
{
contents->editor->viewport->setViewPosition(0, 0);
}
surgeLikeSlider->grabKeyboardFocus();
if (surgeLikeSlider->isShowing())
surgeLikeSlider->grabKeyboardFocus();
}
bool firstInSort{false}, hasFollower{false};
bool isTop{false}, isAfterTop{false}, isLast{false};
Expand Down Expand Up @@ -1102,6 +1118,18 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ModulationListContents);
};

void ModulationSideControls::doCopyToClipboard()
{
std::ostringstream oss;
oss << "Modulation List for " << editor->ed->getStorage()->getPatch().name << "\n";
for (const auto &r : editor->modContents->dataRows)
{
oss << " Source: " << r.sname << "; Target: " << r.pname << "; Depth: " << r.mss.valplus
<< " " << (r.isBipolar ? "(Bipolar)" : "(Unipolar)") << "\n";
}
juce::SystemClipboard::copyTextToClipboard(oss.str());
}

void ModulationSideControls::valueChanged(GUI::IComponentTagValue *c)
{
auto tag = c->getTag();
Expand Down

0 comments on commit 155b165

Please sign in to comment.