Skip to content

Commit

Permalink
More Undo Changes
Browse files Browse the repository at this point in the history
- Swap LFO display on LFO undo
- Rename LFO and Macro
- Macro Values
- LFO Type Undo/Redo
- Modulation List Gestures in Undo/Redo
- An Undo/Redo button

Addresses surge-synthesizer#694
  • Loading branch information
baconpaul committed Apr 7, 2022
1 parent dced24f commit 9d6b51a
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 7 deletions.
15 changes: 15 additions & 0 deletions resources/classic-skin-svgs/bmp00189.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions resources/classic-skin-svgs/bmp00190.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/common/SkinModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,14 @@ Connector patch_category_jog =
Connector("controls.category.prevnext", 157, 42, Connector::JOG_PATCHCATEGORY).asJogPlusMinus();
Connector patch_jog =
Connector("controls.patch.prevnext", 246, 42, Connector::JOG_PATCH).asJogPlusMinus();

Connector action_undo = Connector("controls.action.undo", 510 - 35 - 40, 42, 31, 12,
Components::Switch, Connector::ACTION_UNDO)
.withBackground(IDB_UNDO_BUTTON);
Connector action_redo = Connector("controls.action.redo", 510 - 40, 42, 31, 12, Components::Switch,
Connector::ACTION_REDO)
.withBackground(IDB_REDO_BUTTON);

Connector patch_save = Connector("controls.patch.save", 510, 42, 37, 12, Components::MultiSwitch,
Connector::SAVE_PATCH)
.withHSwitch2Properties(IDB_SAVE_PATCH, 1, 1, 1)
Expand Down
4 changes: 4 additions & 0 deletions src/common/SkinModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ struct Connector
STATUS_TUNE,
STATUS_ZOOM,

ACTION_UNDO,
ACTION_REDO,

LFO_LABEL,
FXPRESET_LABEL,

Expand Down Expand Up @@ -426,6 +429,7 @@ extern Surge::Skin::Connector surge_menu;
extern Surge::Skin::Connector patch_category_jog, patch_jog, patch_save;

extern Surge::Skin::Connector status_mpe, status_zoom, status_tune;
extern Surge::Skin::Connector action_undo, action_redo;

extern Surge::Skin::Connector vu_meter;

Expand Down
2 changes: 2 additions & 0 deletions src/common/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#define IDB_FAVORITE_BUTTON 186
#define IDB_SEARCH_BUTTON 187
#define IDB_FAVORITE_MENU_ICON 188
#define IDB_UNDO_BUTTON 189
#define IDB_REDO_BUTTON 190

// == SVG == Do not remove this comment - it indicates the start of the automated SVG adding block
#define IDB_MSEG_NODES 301
Expand Down
3 changes: 3 additions & 0 deletions src/surge-xt/gui/SkinImageMaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ inline std::unordered_set<int> allowedImageIds()
allowed.insert(185);
allowed.insert(186);
allowed.insert(187);
allowed.insert(188);
allowed.insert(189);
allowed.insert(190);
allowed.insert(301);
allowed.insert(302);
allowed.insert(303);
Expand Down
82 changes: 82 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,27 @@ void SurgeGUIEditor::idle()
}
}

if (undoButton && redoButton)
{
auto us = dynamic_cast<Surge::Widgets::Switch *>(undoButton);
auto rs = dynamic_cast<Surge::Widgets::Switch *>(redoButton);

auto hasU = undoManager()->canUndo();
auto hasR = undoManager()->canRedo();

if (hasU != (!us->isDeactivated))
{
us->setDeactivated(!hasU);
us->repaint();
}

if (hasR != (!rs->isDeactivated))
{
rs->setDeactivated(!hasR);
rs->repaint();
}
}

{
bool expected = true;
if (synth->rawLoadNeedsUIDawExtraState.compare_exchange_weak(expected, true) &&
Expand Down Expand Up @@ -1525,6 +1546,20 @@ void SurgeGUIEditor::openOrRecreateEditor()
"Configure");
break;
}
case Surge::Skin::Connector::NonParameterConnection::ACTION_UNDO:
{
actionUndo = layoutComponentForSkin(skinCtrl, tag_action_undo);
setAccessibilityInformationByTitleAndAction(actionUndo->asJuceComponent(), "Undo",
"Undo");
break;
}
case Surge::Skin::Connector::NonParameterConnection::ACTION_REDO:
{
actionRedo = layoutComponentForSkin(skinCtrl, tag_action_redo);
setAccessibilityInformationByTitleAndAction(actionRedo->asJuceComponent(), "Redo",
"Redo");
break;
}
case Surge::Skin::Connector::NonParameterConnection::SAVE_PATCH:
{
auto q = layoutComponentForSkin(skinCtrl, tag_store);
Expand Down Expand Up @@ -2176,10 +2211,41 @@ void SurgeGUIEditor::setParamFromUndo(int paramId, pdata val)

void SurgeGUIEditor::setStepSequencerFromUndo(int scene, int lfoid, const StepSequencerStorage &val)
{
if (scene != current_scene || lfoid != modsource - ms_lfo1)
{
changeSelectedScene(scene);
modsource = (modsources)(lfoid + ms_lfo1);
modsource_index = 0;
modsource_editor[scene] = modsource;
refresh_mod();
}
synth->storage.getPatch().stepsequences[scene][lfoid] = val;
synth->refresh_editor = true;
}

void SurgeGUIEditor::setLFONameFromUndo(int scene, int lfoid, int index, const std::string &n)
{
strxcpy(synth->storage.getPatch().LFOBankLabel[scene][lfoid][index], n.c_str(),
CUSTOM_CONTROLLER_LABEL_SIZE - 1);
synth->refresh_editor = true;
}
void SurgeGUIEditor::setMacroNameFromUndo(int ccid, const std::string &n)
{
strxcpy(synth->storage.getPatch().CustomControllerLabel[ccid], n.c_str(),
CUSTOM_CONTROLLER_LABEL_SIZE - 1);
synth->refresh_editor = true;
}

void SurgeGUIEditor::setMacroValueFromUndo(int ccid, float val)
{
((ControllerModulationSource *)synth->storage.getPatch()
.scene[current_scene]
.modsources[ccid + ms_ctrl1])
->set_target01(val, false);
synth->getParent()->surgeMacroUpdated(ccid, val);
synth->refresh_editor = true;
}

void SurgeGUIEditor::pushParamToUndoRedo(int paramId, Surge::GUI::UndoManager::Target which)
{
auto p = synth->storage.getPatch().param_ptr[paramId];
Expand Down Expand Up @@ -4812,6 +4878,8 @@ void SurgeGUIEditor::openMacroRenameDialog(const int ccid, const juce::Point<int
useS = "-";
}

undoManager()->pushMacroRename(ccid,
synth->storage.getPatch().CustomControllerLabel[ccid]);
strxcpy(synth->storage.getPatch().CustomControllerLabel[ccid], useS.c_str(),
CUSTOM_CONTROLLER_LABEL_SIZE - 1);
synth->storage.getPatch()
Expand Down Expand Up @@ -4841,6 +4909,7 @@ void SurgeGUIEditor::openLFORenameDialog(const int lfo_id, const juce::Point<int

auto callback = [this, lfo_id, msi](const std::string &nv) {
auto cp = synth->storage.getPatch().LFOBankLabel[current_scene][lfo_id][msi];
undoManager()->pushLFORename(current_scene, lfo_id, msi, cp);
strxcpy(cp, nv.c_str(), CUSTOM_CONTROLLER_LABEL_SIZE);
synth->storage.getPatch().isDirty = true;
synth->refresh_editor = true;
Expand Down Expand Up @@ -5228,6 +5297,14 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
addAndMakeVisibleWithTracking(frame->getSynthControlsLayer(), *hsw);
tuneStatus = hsw.get();
break;
case tag_action_undo:
addAndMakeVisibleWithTracking(frame->getSynthControlsLayer(), *hsw);
undoButton = hsw.get();
break;
case tag_action_redo:
addAndMakeVisibleWithTracking(frame->getSynthControlsLayer(), *hsw);
redoButton = hsw.get();
break;
case tag_mseg_edit:
addAndMakeVisibleWithTrackingInCG(cg_LFO, *hsw);
break;
Expand Down Expand Up @@ -5853,6 +5930,11 @@ void SurgeGUIEditor::lfoShapeChanged(int prior, int curr)
{
if (prior != curr)
{
auto lfoid = modsource - ms_lfo1;
auto id = synth->storage.getPatch().scene[current_scene].lfo[lfoid].shape.id;
auto pd = pdata();
pd.i = prior;
undoManager()->pushParameterChange(id, pd);
synth->storage.getPatch().isDirty = true;
}

Expand Down
8 changes: 6 additions & 2 deletions src/surge-xt/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,
void pushModulationToUndoRedo(int paramId, modsources ms, int scene, int idx,
Surge::GUI::UndoManager::Target which);
void setStepSequencerFromUndo(int scene, int lfoid, const StepSequencerStorage &val);
void setLFONameFromUndo(int scene, int lfoid, int index, const std::string &n);
void setMacroNameFromUndo(int ccid, const std::string &n);
void setMacroValueFromUndo(int ccid, float val);

private:
juce::Rectangle<int> positionForModulationGrid(modsources entry);
Expand Down Expand Up @@ -601,7 +604,8 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,
std::unique_ptr<Surge::Widgets::EffectChooser> effectChooser;

Surge::GUI::IComponentTagValue *statusMPE = nullptr, *statusTune = nullptr,
*statusZoom = nullptr;
*statusZoom = nullptr, *actionUndo = nullptr,
*actionRedo = nullptr;
std::unique_ptr<Surge::Overlays::AboutScreen> aboutScreen;

std::unique_ptr<juce::Drawable> midiLearnOverlay;
Expand Down Expand Up @@ -632,7 +636,7 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,
* Weak pointers to some logical items for focus return
*/
juce::Component *mpeStatus{nullptr}, *zoomStatus{nullptr}, *tuneStatus{nullptr},
*mainMenu{nullptr}, *lfoMenuButton{nullptr};
*mainMenu{nullptr}, *lfoMenuButton{nullptr}, *undoButton{nullptr}, *redoButton{nullptr};

/*
* This is the JUCE component management
Expand Down
2 changes: 2 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditorTags.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum SurgeGUIEditorTags
tag_status_mpe,
tag_status_zoom,
tag_status_tune,
tag_action_undo,
tag_action_redo,

tag_mseg_edit,
tag_lfo_menu,
Expand Down
27 changes: 23 additions & 4 deletions src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,20 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control)
return;
}

if (tag == tag_action_undo)
{
control->setValue(0);
undoManager()->undo();
return;
}

if (tag == tag_action_redo)
{
control->setValue(0);
undoManager()->redo();
return;
}

if (tag == tag_lfo_menu)
{
control->setValue(0);
Expand Down Expand Up @@ -2714,10 +2728,11 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control)
if (cms->getMouseMode() == Surge::Widgets::ModulationSourceButton::DRAG_VALUE)
{
int t = (tag - tag_mod_source0);
((ControllerModulationSource *)synth->storage.getPatch()
.scene[current_scene]
.modsources[t])
->set_target01(control->getValue(), false);
auto cmsrc = ((ControllerModulationSource *)synth->storage.getPatch()
.scene[current_scene]
.modsources[t]);
undoManager()->pushMacroChange(t - ms_ctrl1, cmsrc->get_target01(0));
cmsrc->set_target01(control->getValue(), false);
synth->getParent()->surgeMacroUpdated(t - ms_ctrl1, control->getValue());

lfoDisplay->repaint();
Expand Down Expand Up @@ -3436,6 +3451,10 @@ bool SurgeGUIEditor::setControlFromString(modsources ms, const std::string &s)
auto cms = ((ControllerModulationSource *)synth->storage.getPatch()
.scene[current_scene]
.modsources[ms]);
if (ms >= ms_ctrl1 && ms <= ms_ctrl8)
{
undoManager()->pushMacroChange(ms - ms_ctrl1, cms->get_target01(0));
}
bool bp = cms->is_bipolar();
float val = std::atof(s.c_str()) / 100.0;
if ((bp && val >= -1 && val <= 1) || (val >= 0 && val <= 1))
Expand Down
2 changes: 2 additions & 0 deletions src/surge-xt/gui/SurgeImageStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ void SurgeImageStore::setupBuiltinBitmaps()
addEntry(IDB_FAVORITE_BUTTON);
addEntry(IDB_SEARCH_BUTTON);
addEntry(IDB_FAVORITE_MENU_ICON);
addEntry(IDB_UNDO_BUTTON);
addEntry(IDB_REDO_BUTTON);

// == SVG == Do not remove this comment - it indicates the start of the automated SVG adding
// block
Expand Down
Loading

0 comments on commit 9d6b51a

Please sign in to comment.