Skip to content

Commit

Permalink
Added Exp slider undo & redo
Browse files Browse the repository at this point in the history
TODO Set Slider memento's interval
  • Loading branch information
EX3exp committed Oct 14, 2024
1 parent 8f7230d commit 729fb7c
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 19 deletions.
5 changes: 5 additions & 0 deletions Mirivoice/Commands/AddLineBoxesReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public override void UndoAction()
v.CurrentSingleLineEditor = null;
v.MResultsCollection.Clear();
}
if (v.CurrentEditIndex == 1)
{
v.CurrentEdit = null;
v.OnPropertyChanged(nameof(v.CurrentEdit));
}
v.OnPropertyChanged(nameof(v.CurrentSingleLineEditor));
v.LineBoxCollection.RemoveAt(i);
}
Expand Down
53 changes: 53 additions & 0 deletions Mirivoice/Commands/VITS2SetExpOriginator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Mirivoice.Engines;
using Mirivoice.Mirivoice.Core.Format;
using Mirivoice.ViewModels;
using Serilog;
using System;

namespace Mirivoice.Commands
{
public enum ExpVITS2
{
Speed = 0,
Noise1 = 1,
Noise2 = 2,
}
public class VITS2SetExpOriginator : MOriginator<int>
{
private int index;

private readonly ExpressionEditViewModelVITS2 v;

ExpVITS2 type;
public VITS2SetExpOriginator(ref int index, ExpressionEditViewModelVITS2 v, ExpVITS2 type) : base(ref index)
{
this.index = index;
this.v = v;
this.type = type;
}


public override void UpdateProperties()
{
Log.Debug("[Updating Properties] -- {obj}", obj);
switch (type)
{
case ExpVITS2.Speed:
v.NotProcessingSpeedCommand = true; // prevent recursion loop
v._vits2Speed = obj;
v.OnPropertyChanged(nameof(v.VITS2Speed));
break;
case ExpVITS2.Noise1:
v.NotProcessingNoise1Command = true; // prevent recursion loop
v._vits2Noise1 = obj;
v.OnPropertyChanged(nameof(v.VITS2Noise1));
break;
case ExpVITS2.Noise2:
v.NotProcessingNoise2Command = true; // prevent recursion loop
v._vits2Noise2 = obj;
v.OnPropertyChanged(nameof(v.VITS2Noise2));
break;
}
}
}
}
151 changes: 136 additions & 15 deletions Mirivoice/ViewModels/ExpressionEditViewModelVITS2.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Layout;
using Mirivoice.Commands;
using Mirivoice.Engines;
using Mirivoice.Mirivoice.Core;
using Mirivoice.Mirivoice.Core.Format;
using Mirivoice.Views;
using ReactiveUI;
Expand All @@ -13,6 +15,19 @@ 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 @@ -22,60 +37,166 @@ public class ExpressionEditViewModelVITS2: ViewModelBase
public int MaxNoise2 { get; set; } = 100;
public int MinNoise2 { get; set; } = 0;

private int _vits2Speed;
public int _vits2Speed;
public int VITS2Speed
{
get => _vits2Speed;
get
{
return _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;
OnPropertyChanged(nameof(VITS2Speed));
OnPropertyChanged(nameof(l.Exp.VITS2Speed));
}
}

private int _vits2Noise1;
public int _vits2Noise1;
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;
OnPropertyChanged(nameof(VITS2Noise1));
OnPropertyChanged(nameof(l.Exp.VITS2Noise1));
}
}

private int _vits2Noise2;
public int _vits2Noise2;
public int VITS2Noise2
{
get => _vits2Noise2;
set
{
this.RaiseAndSetIfChanged(ref _vits2Noise2, value);
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;
OnPropertyChanged(nameof(VITS2Noise2));
OnPropertyChanged(nameof(l.Exp.VITS2Noise2));
}
}
public ExpressionEditViewModelVITS2(LineBoxView l)
{
this.l = 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);

_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
8 changes: 4 additions & 4 deletions Mirivoice/Views/ExpressionEditViewVITS2.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
x:Class="Mirivoice.ExpressionEditViewVITS2">

<Border BorderBrush="DarkSlateGray" BorderThickness="1" Background="Gray">
<ScrollViewer AllowAutoHide="False" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
<ScrollViewer AllowAutoHide="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<StackPanel Background="White">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{DynamicResource edits.expression.speedVITS2} " MaxLines="2" TextWrapping="Wrap" TextElement.FontWeight="Bold" Foreground="DarkSlateGray" TextAlignment="Center" Width="50" FontSize="14" Margin="13 15 15 15" />

<NumericUpDown Value="{Binding VITS2Speed}" Minimum="{Binding MinSpeed}" Maximum="{Binding MaxSpeed}" HorizontalContentAlignment="Center" TextElement.FontSize="15" ParsingNumberStyle="Integer" Increment="1" Margin="13 5 15 5" />
<Slider PointerPressed="ClearVITS2Speed" Value="{Binding VITS2Speed}" Minimum="{Binding MinSpeed}" Width="300" Maximum="{Binding MaxSpeed}" SmallChange="1" LargeChange="10" Margin="13 5 15 5" />
<Slider PropertyChanged="OnChangedSpeed" TickFrequency="1" PointerPressed="ClearVITS2Speed" Value="{Binding VITS2Speed}" Minimum="{Binding MinSpeed}" MinWidth="320" Maximum="{Binding MaxSpeed}" Margin="13 5 15 5" />

</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{DynamicResource edits.expression.noise1VITS2} " MaxLines="2" TextWrapping="Wrap" TextElement.FontWeight="Bold" Foreground="DarkSlateGray" TextAlignment="Center" Width="50" FontSize="14" Margin="13 15 15 15" />

<NumericUpDown Value="{Binding VITS2Noise1}" Minimum="{Binding MinNoise1}" Maximum="{Binding MaxNoise1}" HorizontalContentAlignment="Center" TextElement.FontSize="15" ParsingNumberStyle="Integer" Increment="1" Margin="13 5 15 5" />
<Slider PointerPressed="ClearVITS2Noise1" Value="{Binding VITS2Noise1}" Minimum="{Binding MinNoise1}" Width="300" Maximum="{Binding MaxNoise1}" SmallChange="1" LargeChange="10" Margin="13 5 15 5" />
<Slider PropertyChanged="OnChangedNoise1" TickFrequency="1" PointerPressed="ClearVITS2Noise1" Value="{Binding VITS2Noise1}" Minimum="{Binding MinNoise1}" MinWidth="320" Maximum="{Binding MaxNoise1}" Margin="13 5 15 5" />

</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{DynamicResource edits.expression.noise2VITS2} " MaxLines="2" TextWrapping="Wrap" TextElement.FontWeight="Bold" Foreground="DarkSlateGray" TextAlignment="Center" Width="50" FontSize="14" Margin="13 15 15 15" />

<NumericUpDown Value="{Binding VITS2Noise2}" Minimum="{Binding MinNoise2}" Maximum="{Binding MaxNoise2}" HorizontalContentAlignment="Center" TextElement.FontSize="15" ParsingNumberStyle="Integer" Increment="1" Margin="13 5 15 5" />
<Slider PointerPressed="ClearVITS2Noise2" Value="{Binding VITS2Noise2}" Minimum="{Binding MinNoise2}" Width="300" Maximum="{Binding MaxNoise2}" SmallChange="1" LargeChange="10" Margin="13 5 15 5" />
<Slider PropertyChanged="OnChangedNoise2" TickFrequency="1" PointerPressed="ClearVITS2Noise2" Value="{Binding VITS2Noise2}" Minimum="{Binding MinNoise2}" MinWidth="320" Maximum="{Binding MaxNoise2}" Margin="13 5 15 5" />

</StackPanel>
</StackPanel>
Expand Down
36 changes: 36 additions & 0 deletions Mirivoice/Views/ExpressionEditViewVITS2.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Mirivoice.Engines;
using Mirivoice.Mirivoice.Core;
using Mirivoice.Mirivoice.Core.Format;
using Mirivoice.ViewModels;
using Mirivoice.Views;
using Org.BouncyCastle.Crmf;
using ReactiveUI;
using System;
using System.ComponentModel;
using Serilog;

namespace Mirivoice;

Expand All @@ -22,6 +29,28 @@ public ExpressionEditViewVITS2(LineBoxView l)

}

private void OnChangedSpeed(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (viewModel is null)
return;
viewModel.IsDragging = false;
viewModel.OnPropertyChanged(nameof(viewModel.VITS2Speed));
}
private void OnChangedNoise1(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (viewModel is null)
return;
viewModel.IsDragging = false;
viewModel.OnPropertyChanged(nameof(viewModel.VITS2Noise1));
}

private void OnChangedNoise2(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (viewModel is null)
return;
viewModel.IsDragging = false;
viewModel.OnPropertyChanged(nameof(viewModel.VITS2Noise2));
}

private void ClearVITS2Speed(object sender, PointerPressedEventArgs e)
{
Expand All @@ -32,6 +61,12 @@ private void ClearVITS2Speed(object sender, PointerPressedEventArgs e)

}

private void Tapped(object sender, TappedEventArgs e)

Check warning on line 64 in Mirivoice/Views/ExpressionEditViewVITS2.axaml.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

'ExpressionEditViewVITS2.Tapped(object, TappedEventArgs)' hides inherited member 'InputElement.Tapped'. Use the new keyword if hiding was intended.

Check warning on line 64 in Mirivoice/Views/ExpressionEditViewVITS2.axaml.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

'ExpressionEditViewVITS2.Tapped(object, TappedEventArgs)' hides inherited member 'InputElement.Tapped'. Use the new keyword if hiding was intended.

Check warning on line 64 in Mirivoice/Views/ExpressionEditViewVITS2.axaml.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

'ExpressionEditViewVITS2.Tapped(object, TappedEventArgs)' hides inherited member 'InputElement.Tapped'. Use the new keyword if hiding was intended.
{
Log.Debug("Tapped");
viewModel.IsDragging = true;
}

private void ClearVITS2Noise1(object sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsRightButtonPressed)
Expand All @@ -53,4 +88,5 @@ private void InitializeComponent(LineBoxView l)
DataContext = viewModel = new ExpressionEditViewModelVITS2(l);
}


}

0 comments on commit 729fb7c

Please sign in to comment.