Skip to content

Commit

Permalink
Refactor parameter change handling for non-undoable changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Oct 1, 2024
1 parent d88adf3 commit dfa6a17
Showing 1 changed file with 139 additions and 56 deletions.
195 changes: 139 additions & 56 deletions Source/Processors/Parameter/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,22 @@ void BooleanParameter::setNextValue (var newValue_, bool undoable)
newValue = newValue_;
}

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

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

AccessClass::getUndoManager()->perform (action);
AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}

bool BooleanParameter::getBoolValue()
Expand Down Expand Up @@ -348,19 +356,30 @@ CategoricalParameter::CategoricalParameter (ParameterOwner* owner,

void CategoricalParameter::setNextValue (var newValue_, bool undoable)
{
if (newValue_ == currentValue)
if (newValue_ == currentValue
|| ! newValue_.isInt()
|| (int) newValue_ < 0
|| (int) newValue_ >= categories.size())
return;

newValue = (int) newValue_;

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

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

AccessClass::getUndoManager()->perform (action);
AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}

int CategoricalParameter::getSelectedIndex()
Expand Down Expand Up @@ -446,14 +465,22 @@ void IntParameter::setNextValue (var newValue_, bool undoable)
else
newValue = value;

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

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

AccessClass::getUndoManager()->perform (action);
AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}

int IntParameter::getIntValue()
Expand Down Expand Up @@ -511,14 +538,22 @@ void StringParameter::setNextValue (var newValue_, bool undoable)

newValue = newValue_.toString();

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

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

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

AccessClass::getUndoManager()->perform (action);
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}

String StringParameter::getStringValue()
Expand Down Expand Up @@ -586,7 +621,10 @@ void FloatParameter::setNextValue (var newValue_, bool undoable)
newValue = value;
}

if (currentValue != newValue)
if (currentValue == newValue)
return;

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

Expand All @@ -597,6 +635,11 @@ void FloatParameter::setNextValue (var newValue_, bool undoable)

AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}

float FloatParameter::getFloatValue()
Expand Down Expand Up @@ -684,14 +727,22 @@ void SelectedChannelsParameter::setNextValue (var newValue_, bool undoable)
return;
}

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

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

AccessClass::getUndoManager()->perform (action);
AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}

std::vector<bool> SelectedChannelsParameter::getChannelStates()
Expand Down Expand Up @@ -863,14 +914,22 @@ void MaskChannelsParameter::setNextValue (var newValue_, bool undoable)

newValue = values;

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

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

AccessClass::getUndoManager()->perform (action);
AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}

std::vector<bool> MaskChannelsParameter::getChannelStates()
Expand Down Expand Up @@ -1063,14 +1122,22 @@ void TtlLineParameter::setNextValue (var newValue_, bool undoable)
{
newValue = newValue_;

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

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

AccessClass::getUndoManager()->perform (action);
AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}
}

Expand Down Expand Up @@ -1141,14 +1208,22 @@ void PathParameter::setNextValue (var newValue_, bool undoable)
newValue = newValue_;
}

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

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

AccessClass::getUndoManager()->perform (action);
AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}
else
{
Expand Down Expand Up @@ -1223,14 +1298,22 @@ void SelectedStreamParameter::setNextValue (var newValue_, bool undoable)
{
newValue = newValue_;

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

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

AccessClass::getUndoManager()->perform (action);
AccessClass::getUndoManager()->perform (action);
}
else
{
getOwner()->parameterChangeRequest (this);
valueChanged();
}
}
else
{
Expand Down

0 comments on commit dfa6a17

Please sign in to comment.