Skip to content

Commit

Permalink
Improved Slider undo & redo
Browse files Browse the repository at this point in the history
TODO fix minor bugs about slider undo&redo
  • Loading branch information
EX3exp committed Dec 6, 2024
1 parent 8602c94 commit 23b14f1
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 196 deletions.
1 change: 0 additions & 1 deletion Mirivoice/Commands/SetProsodyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Mirivoice.Commands
{
public class SetProsodyCommand : ICommand
{
// TODO
private MResult v;

int undoMem;
Expand Down
113 changes: 113 additions & 0 deletions Mirivoice/Commands/VITS2SetExpCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using Avalonia;
using Mirivoice.Mirivoice.Core.Format;
using Mirivoice.ViewModels;
using Serilog;

namespace Mirivoice.Commands
{
public enum ExpVITS2
{
Speed = 0,
Noise1 = 1,
Noise2 = 2,
}

public class VITS2SetExpCommand : ICommand
{
int undoMem;
int redoMem;

readonly ExpressionEditViewModelVITS2 viewModel;
readonly ExpVITS2 mode;
public VITS2SetExpCommand(ExpressionEditViewModelVITS2 viewModel, ExpVITS2 mode)
{
//Log.Debug("LineEditCommand created");
this.mode = mode;
this.viewModel = viewModel;
switch (mode)
{
case ExpVITS2.Speed:
undoMem = viewModel.VITS2Speed;
break;
case ExpVITS2.Noise1:
undoMem = viewModel.VITS2Noise1;
break;
case ExpVITS2.Noise2:
undoMem = viewModel.VITS2Noise2;
break;
default:
Log.Error("VITS2 Exp editor -- Invalid mode");
break;
}
}


bool isFirstExec = true;
public void Execute(bool isRedoing)
{
if (isRedoing)
{
switch (mode)
{
case ExpVITS2.Speed:
viewModel.VITS2Speed = redoMem;
break;
case ExpVITS2.Noise1:
viewModel.VITS2Noise1 = redoMem;
break;
case ExpVITS2.Noise2:
viewModel.VITS2Noise2 = redoMem;
break;
default:
Log.Error("VITS2 Exp editor -- Invalid mode");
break;
}
}
else
{
if (!isFirstExec)
{
switch (mode)
{
case ExpVITS2.Speed:
undoMem = viewModel.VITS2Speed;
break;
case ExpVITS2.Noise1:
undoMem = viewModel.VITS2Noise1;
break;
case ExpVITS2.Noise2:
undoMem = viewModel.VITS2Noise2;
break;
default:
Log.Error("VITS2 Exp editor -- Invalid mode");
break;
}
}
isFirstExec = false;
}
}

public void UnExecute()
{
switch (mode)
{
case ExpVITS2.Speed:
redoMem = viewModel.VITS2Speed;
viewModel.VITS2Speed = undoMem;
break;
case ExpVITS2.Noise1:
redoMem = viewModel.VITS2Noise1;
viewModel.VITS2Noise1 = undoMem;
break;
case ExpVITS2.Noise2:
redoMem = viewModel.VITS2Noise2;
viewModel.VITS2Noise2 = undoMem;
break;
default:
Log.Error("VITS2 Exp editor -- Invalid mode");
break;
}
}
}

}
49 changes: 0 additions & 49 deletions Mirivoice/Commands/VITS2SetExpOriginator.cs

This file was deleted.

6 changes: 6 additions & 0 deletions Mirivoice/Mirivoice.Core/Managers/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.IO;
using Mirivoice.ViewModels;
using System.Linq;

namespace Mirivoice.Mirivoice.Core.Managers
{
Expand All @@ -19,6 +20,11 @@ public class CommandManager
public CommandManager()
{
}

public bool IsAlreadyExecuted(ICommand target)
{
return _undoStack.Count > 0 && _undoStack.Peek() == target;
}
public void SetMainViewModel(MainViewModel v)
{
this.v = v;
Expand Down
122 changes: 11 additions & 111 deletions Mirivoice/ViewModels/ExpressionEditViewModelVITS2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Mirivoice.Mirivoice.Core.Format;
using Mirivoice.Views;
using ReactiveUI;
using Serilog;
using System;

namespace Mirivoice.ViewModels
Expand All @@ -16,17 +17,12 @@ public class ExpressionEditViewModelVITS2: ViewModelBase
public StackPanel CurrentExpression { get; set; }
private readonly LineBoxView l;

public bool NotProcessingSpeedCommand = false;
public bool NotProcessingNoise1Command = false;
public bool NotProcessingNoise2Command = false;

public int lastSpeed;
public int lastNoise1;
public int lastNoise2;

public bool UndobackupSpeed = false;
public bool UndobackupNoise1 = false;
public bool UndobackupNoise2 = false;


public int MaxSpeed { get; set; } = 100;
public int MinSpeed { get; set; } = 0;
Expand All @@ -37,6 +33,8 @@ public class ExpressionEditViewModelVITS2: ViewModelBase
public int MaxNoise2 { get; set; } = 100;
public int MinNoise2 { get; set; } = 0;



public int _vits2Speed;
public int VITS2Speed
{
Expand All @@ -47,41 +45,14 @@ public int VITS2Speed
set
{

lastSpeed = _vits2Speed;

if (!IsDragging)
{
if (NotProcessingSpeedCommand)
{
if (!UndobackupSpeed)
{


SetSpeedCommand.Backup(lastSpeed);
UndobackupSpeed = true;
}
MainManager.Instance.cmd.ExecuteCommand(SetSpeedCommand);

UndobackupSpeed = false;
}
else
{
NotProcessingSpeedCommand = false;

}
}
else
{
NotProcessingSpeedCommand = true;
}


this.RaiseAndSetIfChanged(ref _vits2Speed, value);

OnPropertyChanged(nameof(VITS2Speed));

l.Exp.VITS2Speed = ScaleValue(100 - value, 0.5f, 1.5f);
l.IsCacheIsVaild = false;


}
}

Expand All @@ -91,36 +62,12 @@ public int VITS2Noise1
get => _vits2Noise1;
set
{
lastNoise1 = _vits2Noise1;

if (!IsDragging)
{
if (NotProcessingNoise1Command)
{
if (!UndobackupNoise1)
{
SetNoise1Command.Backup(lastNoise1);
UndobackupNoise1 = true;
}
MainManager.Instance.cmd.ExecuteCommand(SetNoise1Command);
UndobackupNoise1 = false;
}
else
{
NotProcessingNoise1Command = false;

}
}
else
{
NotProcessingNoise1Command = true;
}


this.RaiseAndSetIfChanged(ref _vits2Noise1, value);
OnPropertyChanged(nameof(VITS2Noise1));
l.Exp.VITS2Noise1 = ScaleValue(value, -0.3335f, 1.6675f);
l.IsCacheIsVaild = false;


}
}

Expand All @@ -130,36 +77,13 @@ public int VITS2Noise2
get => _vits2Noise2;
set
{
lastNoise2 = _vits2Noise2;

if (!IsDragging)
{
if (NotProcessingNoise2Command)
{
if (!UndobackupNoise2)
{
SetNoise2Command.Backup(lastNoise2);
UndobackupNoise2 = true;
}
MainManager.Instance.cmd.ExecuteCommand(SetNoise2Command);
UndobackupNoise2 = false;
}
else
{
NotProcessingNoise2Command = false;

}
}
else
{
NotProcessingNoise2Command = true;
}


this.RaiseAndSetIfChanged(ref _vits2Noise2, value);
OnPropertyChanged(nameof(VITS2Noise2));
l.Exp.VITS2Noise2 = ScaleValue(value, -0.4f, 2f);
l.IsCacheIsVaild = false;


}
}
public ExpressionEditViewModelVITS2(LineBoxView l)
Expand All @@ -169,34 +93,10 @@ public ExpressionEditViewModelVITS2(LineBoxView l)
_vits2Speed = 100 - GetSliderValue(l.Exp.VITS2Speed, 0.5f, 1.5f);
_vits2Noise1 = GetSliderValue(l.Exp.VITS2Noise1, -0.3335f, 1.6675f);
_vits2Noise2 = GetSliderValue(l.Exp.VITS2Noise2, -0.4f, 2f);
SetCommands();
}

public bool IsDragging = false;




MOriginator<int> SetSpeedOriginator;
public MementoCommand<int> SetSpeedCommand;
MOriginator<int> SetNoise1Originator;
public MementoCommand<int> SetNoise1Command;
MOriginator<int> SetNoise2Originator;
public MementoCommand<int> SetNoise2Command;
void SetCommands()
{
SetSpeedOriginator = new VITS2SetExpOriginator(ref _vits2Speed, this, ExpVITS2.Speed);
SetSpeedCommand = new MementoCommand<int>(SetSpeedOriginator);
NotProcessingSpeedCommand = true;
}

SetNoise1Originator = new VITS2SetExpOriginator(ref _vits2Noise1, this, ExpVITS2.Noise1);
SetNoise1Command = new MementoCommand<int>(SetNoise1Originator);
NotProcessingNoise1Command = true;

SetNoise2Originator = new VITS2SetExpOriginator(ref _vits2Noise2, this, ExpVITS2.Noise2);
SetNoise2Command = new MementoCommand<int>(SetNoise2Originator);
NotProcessingNoise2Command = true;
}
public static float ScaleValue(int input, float minValue, float maxValue)
{

Expand Down
Loading

0 comments on commit 23b14f1

Please sign in to comment.