Skip to content

Commit

Permalink
Add a License field to Save Patch dialog (surge-synthesizer#6770)
Browse files Browse the repository at this point in the history
Add CC0 license text to factory and Jacky templates
  • Loading branch information
mkruselj authored Jan 7, 2023
1 parent d533fe4 commit 09e61ca
Show file tree
Hide file tree
Showing 30 changed files with 59 additions and 15 deletions.
Binary file modified resources/data/patches_3rdparty/Jacky Ligon/Templates/Alias.fxp
Binary file not shown.
Binary file not shown.
Binary file modified resources/data/patches_3rdparty/Jacky Ligon/Templates/FM2.fxp
Binary file not shown.
Binary file modified resources/data/patches_3rdparty/Jacky Ligon/Templates/FM3.fxp
Binary file not shown.
Binary file modified resources/data/patches_3rdparty/Jacky Ligon/Templates/Modern.fxp
Binary file not shown.
Binary file not shown.
Binary file modified resources/data/patches_3rdparty/Jacky Ligon/Templates/Sine.fxp
Binary file not shown.
Binary file modified resources/data/patches_3rdparty/Jacky Ligon/Templates/String.fxp
Binary file not shown.
Binary file modified resources/data/patches_3rdparty/Jacky Ligon/Templates/Twist.fxp
Binary file not shown.
Binary file not shown.
Binary file modified resources/data/patches_3rdparty/Jacky Ligon/Templates/Window.fxp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified resources/data/patches_factory/Templates/Audio In Mono Osc 1.fxp
Binary file not shown.
Binary file modified resources/data/patches_factory/Templates/Audio In Stereo Osc 1.fxp
Binary file not shown.
Binary file modified resources/data/patches_factory/Templates/Init Env Per Osc.fxp
Binary file not shown.
Binary file modified resources/data/patches_factory/Templates/Init FM2.fxp
Binary file not shown.
Binary file modified resources/data/patches_factory/Templates/Init Karplus-Strong.fxp
Binary file not shown.
Binary file modified resources/data/patches_factory/Templates/Init Saw.fxp
Binary file not shown.
Binary file modified resources/data/patches_factory/Templates/Init Sine.fxp
Binary file not shown.
2 changes: 1 addition & 1 deletion src/common/SkinModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ Connector oscilloscope = Connector("oscilloscope.window", 300, 263, 450, 212, Co
Connector ws_analysis = Connector("filter.waveshaper_analysis.window", 450, 237, 300, 160,
Components::Custom, Connector::WAVESHAPER_ANALYSIS_WINDOW);

Connector save_patch_dialog = Connector("controls.patch.save.window", 157, 57, 390, 270,
Connector save_patch_dialog = Connector("controls.patch.save.window", 157, 57, 390, 300,
Components::Custom, Connector::SAVE_PATCH_DIALOG);

// modulation panel is special, so it shows up as 'CUSTOM' with no connector and is special-cased in
Expand Down
12 changes: 12 additions & 0 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,17 @@ void SurgePatch::load_xml(const void *data, int datasize, bool is_preset)
author = s;
}

s = meta->Attribute("license");

if (s)
{
license = s;
}
else
{
license = "";
}

auto *tagsX = TINYXML_SAFE_TO_ELEMENT(meta->FirstChild("tags"));
tags.clear();

Expand Down Expand Up @@ -2883,6 +2894,7 @@ unsigned int SurgePatch::save_xml(void **data) // allocates mem, must be freed b
meta.SetAttribute("category", this->category);
meta.SetAttribute("comment", comment);
meta.SetAttribute("author", author);
meta.SetAttribute("license", license);

TiXmlElement tagsX("tags");

Expand Down
2 changes: 1 addition & 1 deletion src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ class SurgePatch
SurgeStorage *storage;

// metadata
std::string name, category, author, comment;
std::string name, category, author, license, comment;

struct Tag
{
Expand Down
1 change: 1 addition & 0 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ SurgeSynthesizer::SurgeSynthesizer(PluginLayer *parent, const std::string &suppl
storage.getPatch().name = "Init";
storage.getPatch().comment = "";
storage.getPatch().author = "Surge Synth Team";
storage.getPatch().license = "Licensed under the maximally permissive CC0 license";
midiprogramshavechanged = false;

for (int i = 0; i < BLOCK_SIZE; i++)
Expand Down
6 changes: 6 additions & 0 deletions src/common/SurgeSynthesizerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,17 @@ bool SurgeSynthesizer::loadPatchByPath(const char *fxpPath, int categoryId, cons

int cs = vt_read_int32BE(fxp.chunkSize);
std::unique_ptr<char[]> data{new char[cs]};

if (f.sgetn(data.get(), cs) != cs)
{
perror("Error while loading patch!");
}

f.close();

storage.getPatch().comment = "";
storage.getPatch().author = "";

if (categoryId >= 0)
{
storage.getPatch().category = storage.patch_category[categoryId].name;
Expand All @@ -275,6 +280,7 @@ bool SurgeSynthesizer::loadPatchByPath(const char *fxpPath, int categoryId, cons
{
storage.getPatch().category = "Drag & Drop";
}

current_category_id = categoryId;
storage.getPatch().name = patchName;

Expand Down
2 changes: 2 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditorOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::makeStorePatc
std::string name = synth->storage.getPatch().name;
std::string category = synth->storage.getPatch().category;
std::string author = synth->storage.getPatch().author;
std::string license = synth->storage.getPatch().license;
std::string comments = synth->storage.getPatch().comment;

auto defaultAuthor = Surge::Storage::getUserDefaultValue(
Expand Down Expand Up @@ -88,6 +89,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::makeStorePatc
pb->setSkin(currentSkin);
pb->setName(name);
pb->setAuthor(author);
pb->setLicense(license);
pb->setCategory(category);
pb->setComment(comments);
pb->setTags(synth->storage.getPatch().tags);
Expand Down
17 changes: 14 additions & 3 deletions src/surge-xt/gui/overlays/PatchStoreDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ PatchStoreDialog::PatchStoreDialog()
nameEd->setWantsKeyboardFocus(true);
authorEd = makeEd("patch author");
authorEd->setSelectAllWhenFocused(true);
tagEd = makeEd("patch tags");
tagEd->setVisible(showTagsField);
licenseEd = makeEd("patch license");
licenseEd->setSelectAllWhenFocused(true);
commentEd = makeEd("patch comment");
commentEd->setMultiLine(true, true);
commentEd->setReturnKeyStartsNewLine(true);
commentEd->setJustification(juce::Justification::topLeft);
tagEd = makeEd("patch tags");
tagEd->setVisible(showTagsField);

categoryProvider = std::make_unique<PatchStoreDialogCategoryProvider>();
auto ta = std::make_unique<Surge::Widgets::TypeAhead>("patch category", categoryProvider.get());
Expand All @@ -178,6 +180,7 @@ PatchStoreDialog::PatchStoreDialog()
nameEdL = makeL("Name");
authorEdL = makeL("Author");
tagEdL = makeL("Tags");
licenseEdL = makeL("License");
catEdL = makeL("Category");
commentEdL = makeL("Comment");

Expand Down Expand Up @@ -274,12 +277,14 @@ void PatchStoreDialog::onSkinChanged()
resetColors(authorEd);
resetColors(catEd);
resetColors(tagEd);
resetColors(licenseEd);
resetColors(commentEd);

resetLabel(nameEdL);
resetLabel(authorEdL);
resetLabel(catEdL);
resetLabel(tagEdL);
resetLabel(licenseEdL);
resetLabel(commentEdL);
resetLabel(storeTuningLabel);

Expand Down Expand Up @@ -309,7 +314,7 @@ void PatchStoreDialog::setIsRename(bool b) { isRename = b; }
void PatchStoreDialog::resized()
{
auto h = 25;
auto commH = getHeight() - (5 + showTagsField) * h + 8;
auto commH = getHeight() - (6 + showTagsField) * h + 8;
auto xSplit = 70;
auto buttonWidth = 50;
auto margin = 4;
Expand All @@ -328,6 +333,9 @@ void PatchStoreDialog::resized()
ce = ce.translated(0, h);
authorEd->setBounds(ce);
authorEd->setIndents(4, (authorEd->getHeight() - authorEd->getTextHeight()) / 2);
ce = ce.translated(0, h);
licenseEd->setBounds(ce);
licenseEd->setIndents(4, (licenseEd->getHeight() - licenseEd->getTextHeight()) / 2);

if (isVisible())
{
Expand Down Expand Up @@ -364,6 +372,8 @@ void PatchStoreDialog::resized()
catEdL->setBounds(cl);
cl = cl.translated(0, h);
authorEdL->setBounds(cl);
cl = cl.translated(0, h);
licenseEdL->setBounds(cl);

if (showTagsField)
{
Expand Down Expand Up @@ -406,6 +416,7 @@ void PatchStoreDialog::buttonClicked(juce::Button *button)
synth->storage.getPatch().name = nameEd->getText().toStdString();
synth->storage.getPatch().author = authorEd->getText().toStdString();
synth->storage.getPatch().category = catEd->getText().toStdString();
synth->storage.getPatch().license = licenseEd->getText().toStdString();
synth->storage.getPatch().comment = commentEd->getText().toStdString();

auto tagString = tagEd->getText();
Expand Down
5 changes: 3 additions & 2 deletions src/surge-xt/gui/overlays/PatchStoreDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ struct PatchStoreDialog : public OverlayComponent,

void setName(const std::string &n) { nameEd->setText(n, juce::dontSendNotification); }
void setAuthor(const std::string &a) { authorEd->setText(a, juce::dontSendNotification); }
void setLicense(const std::string &a) { licenseEd->setText(a, juce::dontSendNotification); }
void setCategory(const std::string &c) { catEd->setText(c, juce::dontSendNotification); }
void setComment(const std::string &c) { commentEd->setText(c, juce::dontSendNotification); }
void setTags(const std::vector<SurgePatch::Tag> &t);
void setStoreTuningInPatch(const bool value);

void onSkinChanged() override;
void buttonClicked(juce::Button *button) override;
std::unique_ptr<juce::TextEditor> nameEd, authorEd, catEd, tagEd, commentEd;
std::unique_ptr<juce::Label> nameEdL, authorEdL, catEdL, tagEdL, commentEdL;
std::unique_ptr<juce::TextEditor> nameEd, authorEd, catEd, licenseEd, tagEd, commentEd;
std::unique_ptr<juce::Label> nameEdL, authorEdL, catEdL, licenseEdL, tagEdL, commentEdL;
std::unique_ptr<Widgets::SurgeTextButton> okButton, okOverButton, cancelButton;
std::unique_ptr<juce::Label> storeTuningLabel;
std::unique_ptr<juce::ToggleButton> storeTuningButton;
Expand Down
25 changes: 18 additions & 7 deletions src/surge-xt/gui/widgets/PatchSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,30 +1379,41 @@ void PatchSelectorCommentTooltip::paint(juce::Graphics &g)
}

void PatchSelectorCommentTooltip::positionForComment(const juce::Point<int> &centerPoint,
const std::string &c, const int maxWidth)
const std::string &c,
const int maxTooltipWidth)
{
comment = c;

std::stringstream ss(comment);
std::string to;

int idx = 0;
int numLines = 0;

auto ft = skin->fontManager->getLatoAtSize(9);
auto width = 0;
auto width = 0.f;

while (std::getline(ss, to, '\n'))
{
auto w = ft.getStringWidth(to);
auto w = ft.getStringWidthFloat(to);

// in case of an empty line, we still need to count it as an extra row
// so bump it up a bit so that the rows calculation ceils to 1
if (w == 0.f)
{
w = 1.f;
}

auto rows = std::ceil(w / (float)maxTooltipWidth);

width = std::max(w, width);
idx++;
numLines += (int)rows;
}

auto height = std::max(idx * (ft.getHeight() + 2), 30.f);
auto height = std::max(numLines * (ft.getHeight() + 2), 30.f);

auto r = juce::Rectangle<int>()
.withCentre(juce::Point(centerPoint.x, centerPoint.y))
.withSizeKeepingCentre(std::min(width + 12, maxWidth), height)
.withSizeKeepingCentre(std::min(width, (float)maxTooltipWidth), height)
.translated(0, height / 2);

setBounds(r);
Expand Down
2 changes: 1 addition & 1 deletion src/surge-xt/gui/widgets/PatchSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ struct PatchSelectorCommentTooltip : public juce::Component,

std::string comment;
void positionForComment(const juce::Point<int> &centerPoint, const std::string &comment,
const int maxWidth);
const int maxTooltipWidth);

protected:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PatchSelectorCommentTooltip);
Expand Down

0 comments on commit 09e61ca

Please sign in to comment.