Skip to content

Commit

Permalink
Allow undo/redo when acquisition is active
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Sep 24, 2024
1 parent cdcfa92 commit dfdc40d
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 37 deletions.
6 changes: 3 additions & 3 deletions Plugins/ChannelMap/ChannelMapEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void ChannelMapEditor::mouseDown (const MouseEvent& e)
{
EnableChannelAction* action = new EnableChannelAction (processor, processor->getDataStream (getCurrentStream()), buttonIndex, isActive);

CoreServices::getUndoManager()->beginNewTransaction();
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
CoreServices::getUndoManager()->perform ((UndoableAction*) action);
}
else if (result == 2)
Expand All @@ -274,7 +274,7 @@ void ChannelMapEditor::mouseDown (const MouseEvent& e)
{
ResetStreamAction* action = new ResetStreamAction (processor, processor->getDataStream (getCurrentStream()));

CoreServices::getUndoManager()->beginNewTransaction();
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
CoreServices::getUndoManager()->perform ((UndoableAction*) action);
}
}
Expand Down Expand Up @@ -424,7 +424,7 @@ void ChannelMapEditor::mouseUp (const MouseEvent& e)

MapChannelsAction* action = new MapChannelsAction ((ChannelMap*) getProcessor(), getProcessor()->getDataStream (getCurrentStream()), newChannelOrder);

CoreServices::getUndoManager()->beginNewTransaction();
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
CoreServices::getUndoManager()->perform ((UndoableAction*) action);
}
}
4 changes: 2 additions & 2 deletions Plugins/SpikeDetector/SpikeDetectorEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void SpikeDetectorEditor::addSpikeChannels (PopupConfigurationWindow* window, Sp

AddSpikeChannels* action = new AddSpikeChannels (processor, stream, type, count, startChannels, nextAvailableChannel);

CoreServices::getUndoManager()->beginNewTransaction ("addSpikeChannels");
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
CoreServices::getUndoManager()->perform ((UndoableAction*) action);

if (window != nullptr)
Expand All @@ -101,7 +101,7 @@ void SpikeDetectorEditor::removeSpikeChannels (PopupConfigurationWindow* window,

RemoveSpikeChannels* action = new RemoveSpikeChannels (processor, stream, spikeChannelsToRemove, indeces);

CoreServices::getUndoManager()->beginNewTransaction ("removeSpikeChannels");
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
CoreServices::getUndoManager()->perform ((UndoableAction*) action);

if (window != nullptr)
Expand Down
66 changes: 55 additions & 11 deletions Source/Processors/Parameter/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ void BooleanParameter::setNextValue (var newValue_, bool undoable)

ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}

Expand Down Expand Up @@ -351,7 +355,11 @@ void CategoricalParameter::setNextValue (var newValue_, bool undoable)

ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}

Expand Down Expand Up @@ -440,7 +448,11 @@ void IntParameter::setNextValue (var newValue_, bool undoable)

ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}

Expand Down Expand Up @@ -501,7 +513,11 @@ void StringParameter::setNextValue (var newValue_, bool undoable)

ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}

Expand Down Expand Up @@ -574,7 +590,11 @@ void FloatParameter::setNextValue (var newValue_, bool undoable)
{
ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}
}
Expand Down Expand Up @@ -665,7 +685,11 @@ void SelectedChannelsParameter::setNextValue (var newValue_, bool undoable)

Parameter::ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}

Expand Down Expand Up @@ -840,7 +864,11 @@ void MaskChannelsParameter::setNextValue (var newValue_, bool undoable)

Parameter::ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}

Expand Down Expand Up @@ -1036,7 +1064,11 @@ void TtlLineParameter::setNextValue (var newValue_, bool undoable)

ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}
}
Expand Down Expand Up @@ -1110,7 +1142,11 @@ void PathParameter::setNextValue (var newValue_, bool undoable)

ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}
else
Expand Down Expand Up @@ -1188,7 +1224,11 @@ void SelectedStreamParameter::setNextValue (var newValue_, bool undoable)

ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}
else
Expand Down Expand Up @@ -1280,7 +1320,11 @@ void TimeParameter::setNextValue (var newValue_, bool undoable)
{
ChangeValue* action = new TimeParameter::ChangeValue (getKey(), newValue);

AccessClass::getUndoManager()->beginNewTransaction();
if (shouldDeactivateDuringAcquisition())
AccessClass::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
else
AccessClass::getUndoManager()->beginNewTransaction();

AccessClass::getUndoManager()->perform (action);
}
else
Expand Down
18 changes: 9 additions & 9 deletions Source/UI/EditorViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ GenericProcessor* EditorViewport::addProcessor (Plugin::Description description,

if (! loadingConfig)
{
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction ("Disabled during acquisition");
AccessClass::getProcessorGraph()->getUndoManager()->perform (action);
return action->processor;
}
Expand All @@ -280,7 +280,7 @@ void EditorViewport::clearSignalChain()
{
LOGD ("Clearing signal chain.");

AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction ("Disabled during acquisition");
ClearSignalChain* action = new ClearSignalChain();
AccessClass::getProcessorGraph()->getUndoManager()->perform (action);
}
Expand Down Expand Up @@ -632,7 +632,7 @@ bool EditorViewport::keyPressed (const KeyPress& key)

void EditorViewport::switchIO (GenericProcessor* processor, int path)
{
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction ("Disabled during acquisition");

SwitchIO* switchIO = new SwitchIO (processor, path);

Expand Down Expand Up @@ -735,7 +735,7 @@ void EditorViewport::paste()
processorInfo.add (xml);
}

AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction ("Disabled during acquisition");

GenericProcessor* source = nullptr;
GenericProcessor* dest = nullptr;
Expand Down Expand Up @@ -1072,7 +1072,7 @@ void EditorViewport::mouseUp (const MouseEvent& e)

if (! getScreenBounds().contains (e.getScreenPosition()))
{
//AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
//AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction("Disabled during acquisition");

//DeleteProcessor* action =
// new DeleteProcessor(
Expand Down Expand Up @@ -1109,7 +1109,7 @@ void EditorViewport::mouseUp (const MouseEvent& e)
newDest = editorArray[insertionPoint]->getProcessor();
}

AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction ("Disabled during acquisition");

MoveProcessor* action = new MoveProcessor (
editorArray[indexOfMovingComponent]->getProcessor(),
Expand Down Expand Up @@ -1528,7 +1528,7 @@ const String EditorViewport::loadPluginState (File fileToLoad, GenericEditor* se
}
else
{
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction ("Disabled during acquisition");

LoadPluginSettings* action = new LoadPluginSettings (selectedEditor->getProcessor(), xml.get());
AccessClass::getProcessorGraph()->getUndoManager()->perform (action);
Expand Down Expand Up @@ -1615,7 +1615,7 @@ const String EditorViewport::loadState (File fileToLoad)
return "Not a valid file.";
}

AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction ("Disabled during acquisition");

LoadSignalChain* action = new LoadSignalChain (xml);
AccessClass::getProcessorGraph()->getUndoManager()->perform (action);
Expand All @@ -1636,7 +1636,7 @@ void EditorViewport::deleteSelectedProcessors()
if (signalChainIsLocked)
return;

AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction();
AccessClass::getProcessorGraph()->getUndoManager()->beginNewTransaction ("Disabled during acquisition");

Array<GenericEditor*> editors = Array (editorArray);

Expand Down
10 changes: 8 additions & 2 deletions Source/UI/UIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,16 +613,22 @@ void UIComponent::getCommandInfo (CommandID commandID, ApplicationCommandInfo& r
break;

case undo:
{
result.setInfo ("Undo", "Undo the last action.", "General", 0);
result.addDefaultKeypress ('Z', ModifierKeys::commandModifier);
result.setActive (! acquisitionStarted && AccessClass::getProcessorGraph()->getUndoManager()->canUndo() && ! getEditorViewport()->isSignalChainLocked());
bool undoDisabled = acquisitionStarted && AccessClass::getUndoManager()->getUndoDescription().contains ("Disabled during acquisition");
result.setActive (! undoDisabled && AccessClass::getUndoManager()->canUndo() && ! getEditorViewport()->isSignalChainLocked());
break;
}

case redo:
{
result.setInfo ("Redo", "Undo the last action.", "General", 0);
result.addDefaultKeypress ('Z', ModifierKeys::commandModifier | ModifierKeys::shiftModifier);
result.setActive (! acquisitionStarted && AccessClass::getProcessorGraph()->getUndoManager()->canRedo() && ! getEditorViewport()->isSignalChainLocked());
bool redoDisabled = acquisitionStarted && AccessClass::getUndoManager()->getRedoDescription().contains ("Disabled during acquisition");
result.setActive (! redoDisabled && AccessClass::getUndoManager()->canRedo() && ! getEditorViewport()->isSignalChainLocked());
break;
}

case copySignalChain:
result.setInfo ("Copy", "Copy selected processors.", "General", 0);
Expand Down
30 changes: 20 additions & 10 deletions Source/Utils/OpenEphysHttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ class OpenEphysHttpServer : juce::Thread

MessageManager::callAsync([this, processor, &processorDeleted] {
DeleteProcessor* action = new DeleteProcessor(processor);
graph_->getUndoManager()->beginNewTransaction();
graph_->getUndoManager()->beginNewTransaction("Disabled during acquisition");
graph_->getUndoManager()->perform(action);
processorDeleted.set_value(); // Signal that processor has been deleted
});
Expand Down Expand Up @@ -960,7 +960,7 @@ class OpenEphysHttpServer : juce::Thread

MessageManager::callAsync([this, description, sourceProcessor, destProcessor, &processorAdded] {
AddProcessor* action = new AddProcessor(description, sourceProcessor, destProcessor, false);
graph_->getUndoManager()->beginNewTransaction();
graph_->getUndoManager()->beginNewTransaction("Disabled during acquisition");
graph_->getUndoManager()->perform(action);
processorAdded.set_value(); // Signal that processor has been added
});
Expand All @@ -983,13 +983,18 @@ class OpenEphysHttpServer : juce::Thread

String return_msg;

if (!CoreServices::getAcquisitionStatus())
auto* um = graph_->getUndoManager();

bool undoDisabled = CoreServices::getAcquisitionStatus()
&& um->getUndoDescription().contains ("Disabled during acquisition");

if (! undoDisabled && um->canUndo())
{
std::promise<void> undoCompleted;
std::future<void> undoCompletedFuture = undoCompleted.get_future();

MessageManager::callAsync([this, &undoCompleted] {
graph_->getUndoManager()->undo();
MessageManager::callAsync([um, &undoCompleted] {
um->undo();
undoCompleted.set_value(); // Signal that undo is finished
});

Expand All @@ -1010,13 +1015,18 @@ class OpenEphysHttpServer : juce::Thread

String return_msg;

if (!CoreServices::getAcquisitionStatus())
auto* um = graph_->getUndoManager();

bool redoDisabled = CoreServices::getAcquisitionStatus()
&& um->getRedoDescription().contains ("Disabled during acquisition");

if (!redoDisabled && um->canRedo())
{
std::promise<void> redoCompleted;
std::future<void> redoCompletedFuture = redoCompleted.get_future();

MessageManager::callAsync([this, &redoCompleted] {
graph_->getUndoManager()->redo();
MessageManager::callAsync([um, &redoCompleted] {
um->redo();
redoCompleted.set_value(); // Signal that redo is finished
});

Expand Down Expand Up @@ -1495,14 +1505,14 @@ class OpenEphysHttpServer : juce::Thread
{
json stream_json;
stream_latency_to_json (processor, stream, &stream_json);
(*processor_json)["streams"].push_back(stream_json);
(*processor_json)["streams"].push_back (stream_json);
}
}

inline static void stream_latency_to_json (const GenericProcessor* processor, const DataStream* stream, json* stream_json)
{
(*stream_json)["name"] = stream->getName().toStdString();
(*stream_json)["latency"] = processor->getLatency(stream->getStreamId());
(*stream_json)["latency"] = processor->getLatency (stream->getStreamId());
}

inline GenericProcessor* find_processor (const std::string& id_string)
Expand Down

0 comments on commit dfdc40d

Please sign in to comment.