Skip to content

Commit

Permalink
Tag Support expanded in a couple of ways
Browse files Browse the repository at this point in the history
1. Shift-Save adds a tag field
2. Tag field gets saved and restored consistently
3. tag field injected into sql db
4. Tag field used in plain text search in sql

Closes surge-synthesizer#6663
  • Loading branch information
baconpaul committed Oct 24, 2022
1 parent 38945b9 commit 024e4a2
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 37 deletions.
43 changes: 39 additions & 4 deletions src/common/PatchDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ struct TxnGuard

struct PatchDB::WriterWorker
{
static constexpr const char *schema_version = "11"; // I will rebuild if this is not my version
static constexpr const char *schema_version = "14"; // I will rebuild if this is not my version

// language=SQL
static constexpr const char *setup_sql = R"SQL(
DROP TABLE IF EXISTS "Patches";
DROP TABLE IF EXISTS "PatchFeature";
Expand All @@ -244,6 +243,7 @@ CREATE TABLE "Patches" (
id integer primary key,
path varchar(2048),
name varchar(256),
search_over varchar(1024),
category varchar(2048),
category_type int,
last_write_time big int
Expand Down Expand Up @@ -562,6 +562,17 @@ CREATE TABLE IF NOT EXISTS Favorites (
{
res.emplace_back("AUTHOR", STRING, 0, meta->Attribute("author"));
}

auto tags = TINYXML_SAFE_TO_ELEMENT(meta->FirstChild("tags"));
if (tags)
{
auto tag = tags->FirstChildElement();
while (tag)
{
res.emplace_back("TAG", STRING, 0, tag->Attribute("tag"));
tag = tag->NextSiblingElement();
}
}
}

auto parameters = TINYXML_SAFE_TO_ELEMENT(patch->FirstChild("parameters"));
Expand Down Expand Up @@ -801,6 +812,9 @@ CREATE TABLE IF NOT EXISTS Favorites (
return;
}

std::ostringstream searchName;
searchName << p.name << " ";

std::ifstream stream(p.path, std::ios::in | std::ios::binary);
std::vector<uint8_t> contents((std::istreambuf_iterator<char>(stream)),
std::istreambuf_iterator<char>());
Expand Down Expand Up @@ -862,6 +876,7 @@ CREATE TABLE IF NOT EXISTS Favorites (
auto feat = extractFeaturesFromXML(xml);
for (auto f : feat)
{
auto ftype = std::get<0>(f);
ins.bindi64(1, patchid);
ins.bind(2, std::get<0>(f));
ins.bind(3, (int)std::get<1>(f));
Expand All @@ -872,6 +887,10 @@ CREATE TABLE IF NOT EXISTS Favorites (

ins.clearBindings();
ins.reset();
if (ftype == "TAG")
{
searchName << " " << std::get<3>(f);
}
}

ins.finalize();
Expand All @@ -881,6 +900,22 @@ CREATE TABLE IF NOT EXISTS Favorites (
storage->reportError(e.what(), "PatchDB - FXP Features");
return;
}

auto sns = searchName.str();
try
{
auto ins = SQL::Statement(dbh, "UPDATE PATCHES SET search_over=?1 WHERE id=?2");
ins.bind(1, sns);
ins.bind(2, patchid);

ins.step();
ins.finalize();
}
catch (const SQL::Exception &e)
{
storage->reportError(e.what(), "PatchDB - FXP Features");
return;
}
}

void setFavorite(const std::string &p, bool v)
Expand Down Expand Up @@ -1420,7 +1455,7 @@ std::string PatchDB::sqlWhereClauseFor(const std::unique_ptr<PatchDBQueryParser:
}
break;
case PatchDBQueryParser::LITERAL:
oss << "( p.name LIKE '%" << protect(t->content) << "%' )";
oss << "( p.search_over LIKE '%" << protect(t->content) << "%' )";
break;
case PatchDBQueryParser::AND:
case PatchDBQueryParser::OR:
Expand Down Expand Up @@ -1448,7 +1483,7 @@ PatchDB::queryFromQueryString(const std::unique_ptr<PatchDBQueryParser::Token> &

// FIXME - cache this by pushing it to the worker
std::string query = "select p.id, p.path, p.category as category, p.name, pf.feature_svalue as "
"author from Patches "
"author, p.search_over from Patches "
"as p, PatchFeature as pf where pf.patch_id == p.id and pf.feature LIKE "
"'AUTHOR' and " +
sqlWhereClauseFor(t) + " ORDER BY p.category_type, p.category, p.name";
Expand Down
8 changes: 6 additions & 2 deletions src/surge-xt/gui/SurgeGUIEditorOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::makeStorePatc

// since it is now modal center in the window
auto posRect = skinCtrl->getRect().withCentre(frame->getBounds().getCentre());

pb->setEnclosingParentTitle("Save Patch");
pb->setEnclosingParentPosition(posRect);
pb->setHasIndependentClose(false);
Expand Down Expand Up @@ -405,6 +406,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay

return nullptr;
}

void SurgeGUIEditor::showOverlay(OverlayTags olt,
std::function<void(Surge::Overlays::OverlayComponent *)> setup)
{
Expand All @@ -416,13 +418,13 @@ void SurgeGUIEditor::showOverlay(OverlayTags olt,
return;
}

setup(ol.get());

// copy these before the std::move below
auto t = ol->getEnclosingParentTitle();
auto r = ol->getEnclosingParentPosition();
auto c = ol->getHasIndependentClose();

setup(ol.get());

std::function<void()> onClose = []() {};
bool isModal = false;

Expand Down Expand Up @@ -463,6 +465,7 @@ void SurgeGUIEditor::showOverlay(OverlayTags olt,
default:
break;
}

addJuceEditorOverlay(std::move(ol), t, olt, r, c, onClose, isModal);

switch (olt)
Expand Down Expand Up @@ -492,6 +495,7 @@ void SurgeGUIEditor::showOverlay(OverlayTags olt,

getOverlayIfOpen(olt)->grabKeyboardFocus();
}

void SurgeGUIEditor::closeOverlay(OverlayTags olt)
{
auto olw = getOverlayWrapperIfOpen(olt);
Expand Down
26 changes: 23 additions & 3 deletions src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
#include "widgets/Switch.h"
#include "widgets/PatchSelector.h"
#include "widgets/ParameterInfowindow.h"
#include "widgets/WaveShaperSelector.h"
#include "widgets/XMLConfiguredMenus.h"

#include "overlays/TypeinParamEditor.h"
#include "widgets/WaveShaperSelector.h"
#include "overlays/ModulationEditor.h"
#include "overlays/PatchStoreDialog.h"
#include "overlays/TypeinParamEditor.h"

std::string decodeControllerID(int id)
{
Expand Down Expand Up @@ -3478,7 +3479,26 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control)
break;
case tag_store:
{
showOverlay(SAVE_PATCH);
bool showTags = juce::ModifierKeys::currentModifiers.isShiftDown() ||
juce::ModifierKeys::currentModifiers.isAltDown();

showOverlay(SurgeGUIEditor::SAVE_PATCH,
[this, showTags](Surge::Overlays::OverlayComponent *co) {
auto psd = dynamic_cast<Surge::Overlays::PatchStoreDialog *>(co);

if (!psd)
{
return;
}

psd->setShowTagsField(showTags);

if (showTags)
{
auto pos = psd->getEnclosingParentPosition();
pos = pos.withHeight(pos.getHeight() + 25);
}
});
}
break;

Expand Down
Loading

0 comments on commit 024e4a2

Please sign in to comment.