Skip to content

Commit

Permalink
fixed phonemeEdits are not updated sometime
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Sep 23, 2024
1 parent 9aa82bc commit 10f65d3
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Mirivoice/Assets/Lang/strings-en-US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


<system:String x:Key="updater.title">Update Checker</system:String>
<system:String x:Key="updater.description">An Universal TTS Platform</system:String>
<system:String x:Key="updater.description">Universal TTS Platform</system:String>
<system:String x:Key="updater.status.available">Mirivoice v{0} is available!</system:String>
<system:String x:Key="updater.status.checking">Checking for Updates...</system:String>
<system:String x:Key="updater.status.notavailable">(Latest)</system:String>
Expand Down
9 changes: 2 additions & 7 deletions Mirivoice/Commands/AddLineBoxReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ public override void DoAction()

var lineBox = new LineBoxView(v);
int LineNoToBeAdded = v.LineBoxCollection.Count + 1;

foreach (var lineB in v.LineBoxCollection)
{
lineB.DeActivatePhonemizer = true; // prevent freezing
}

lineBox.DeActivatePhonemizer = true ;

lineBox.viewModel.SetLineNo(LineNoToBeAdded);
lineBox.ShouldPhonemizeWhenSelected = true;

v.LineBoxCollection.Add(lineBox);
LineBoxIndexLastAdded = v.LineBoxCollection.Count - 1;
Expand Down
5 changes: 0 additions & 5 deletions Mirivoice/Commands/AddLineBoxesReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public override void DoAction()
}
}

foreach (var result in results)
{
//Log.Information("MultipleEditScriptParser parsed: {result}", result);
//Log.Debug($"'{result}'");
}

MainManager.Instance.DefaultVoicerIndex = DefaultVoicerOriginal;
MainManager.Instance.DefaultMetaIndex = DefaultVoicerMetaOriginal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ await Dispatcher.UIThread.InvokeAsync(async () =>
IPAPhonemes.Clear();
bool divideWord = false;
var wordTasks = variatedWords
.Select(async (word, index) =>
.Select(async (word, index) => await Task.Run(()=>
{
string phoneme = string.Join("", ToPhonemes(word, out _));
if (words.Length != variatedWords.Length)
Expand Down Expand Up @@ -154,7 +154,7 @@ await Dispatcher.UIThread.InvokeAsync(async () =>
divideWord = true;


});
}));

await Task.WhenAll(wordTasks);

Expand Down Expand Up @@ -226,9 +226,9 @@ await Dispatcher.UIThread.InvokeAsync(() =>

//Log.Information("Phonemize: {sentence}", sentence);

int unitWidth = 64;
int unitHeight = 48;
int wordBorderWidth = 1;
//int unitWidth = 64;
//int unitHeight = 48;
//int wordBorderWidth = 1;
bool editable = true;


Expand All @@ -242,7 +242,7 @@ await Dispatcher.UIThread.InvokeAsync(async () =>

bool divideWord = false;
var wordTasks = variatedWords
.Select(async (word, index)=>
.Select(async (word, index) =>
{

string phoneme = string.Join("", ToPhonemes(word, out editable));
Expand Down Expand Up @@ -299,7 +299,7 @@ await Dispatcher.UIThread.InvokeAsync(async () =>

bool divideWord = false;
var phonemeTasks = l.MResultsCollection
.Select(async (mResult, index) =>
.Select(async (mResult, index) => await Task.Run(() =>
{

string phoneme = mResult.mTextBoxEditor.CurrentScript;
Expand All @@ -324,7 +324,7 @@ await Dispatcher.UIThread.InvokeAsync(async () =>
divideWord = true;


});
}));

await Task.WhenAll(phonemeTasks);
if (l != null)
Expand Down
5 changes: 3 additions & 2 deletions Mirivoice/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MainViewModel : VoicerSelectingViewModelBase


Mrp initMrp;
Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Version version = System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version;

private bool _mainWindowGetInput = true;
public bool MainWindowGetInput
Expand Down Expand Up @@ -356,8 +356,9 @@ public bool isPlaying {
OnPropertyChanged(nameof(isPlaying));
}
}
public async void OnPlayButtonClick()
public void OnPlayButtonClick()
{

StopButtonEnabled = true;
if (!isPlaying)
{
Expand Down
22 changes: 14 additions & 8 deletions Mirivoice/Views/LineBoxView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private async Task PhonemizeLine(bool ApplyToCurrentEdit = true)
double lastY;


bool ShouldPhonemizeWhenSelected = false;
public bool ShouldPhonemizeWhenSelected = false;

SingleLineEditorView singleLineEditorView;
public ObservableCollection<MResult> MResultsCollection { get; set; } = new ObservableCollection<MResult>();
Expand All @@ -149,7 +149,6 @@ public LineBoxView(MainViewModel v, string line="")

this.v = v;

ShouldPhonemize = false;
DeActivatePhonemizer = true;

if (line != string.Empty)
Expand Down Expand Up @@ -195,8 +194,6 @@ public LineBoxView(LineBoxView l)

string line = viewModel.LineText;

this.v = v;

ShouldPhonemize = false;
DeActivatePhonemizer = true;

Expand Down Expand Up @@ -265,8 +262,17 @@ public LineBoxView(MLinePrototype mLinePrototype, MainViewModel v, int index, in
{
ShouldPhonemizeWhenSelected = false;
}

singleLineEditorView = new SingleLineEditorView(this);
if (mLinePrototype.PhonemeEdit.Length > 0)
{
// if phonemeEdit is not empty, use phonemeEdit's results
singleLineEditorView = new SingleLineEditorView(this, false);
}
else
{
// if phonemeEdit is empty, use newly phonemized one
singleLineEditorView = new SingleLineEditorView(this);
}

}
// Commands
public MCommand DelLineBoxCommand { get; set; }
Expand Down Expand Up @@ -491,8 +497,8 @@ private void OnDragStart(object sender, RoutedEventArgs e)
{

v.CurrentSingleLineEditor = singleLineEditorView;
//Log.Debug("CurrentLineBox: {0}", v.CurrentLineBox);
//Log.Debug("CurrentSingleLineTextBox: {0}", v.CurrentSingleLineEditor);
Log.Debug("CurrentLineBox: {0}", v.CurrentLineBox);
Log.Debug("CurrentSingleLineTextBox: {0}", v.CurrentSingleLineEditor);

ShouldPhonemize = true;

Expand Down
2 changes: 1 addition & 1 deletion Mirivoice/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@


<Panel Grid.Column="2">
<Grid RowDefinitions="20*, 80*">
<Grid RowDefinitions="20*, 80*" >
<Button IsHitTestVisible="{Binding MainWindowGetInput}" Focusable="False" Cursor="Hand" Grid.Row="0" Command="{Binding OnAddButtonClick}" Background="LightSlateGray" Width="50" Height="50">
<Path Data="{StaticResource add_regular}" Fill="Wheat" Stretch="Fill"/>
</Button>
Expand Down
2 changes: 1 addition & 1 deletion Mirivoice/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:li="using:LoadingIndicators.Avalonia"
x:Class="Mirivoice.Views.MainWindow"
Icon="/Assets/mirivoice-logo.ico"
Icon="/Assets/mirivoice-logo.ico"
Title="{Binding Title}">
<Window.KeyBindings>
<KeyBinding Gesture="Ctrl + Z" Command="{Binding Undo}" />
Expand Down
11 changes: 10 additions & 1 deletion Mirivoice/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Mirivoice.ViewModels;

using Serilog;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
namespace Mirivoice.Views;

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Log.Information("Main window checking Update.");
AppUpdaterWindow.CheckForUpdate(
dialog => dialog.Show(this),
() => (Application.Current?.ApplicationLifetime as IControlledApplicationLifetime)?.Shutdown(),
TaskScheduler.FromCurrentSynchronizationContext());
Log.Information("Created main window.");
}

private void InitializeComponent()
Expand Down
2 changes: 1 addition & 1 deletion Mirivoice/Views/SingleLineEditorView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
x:Class="Mirivoice.SingleLineEditorView">

<Border>
<TextBox AcceptsReturn="True" LostFocus="LineLostFocus" GotFocus="LineGotFocus" TextChanging="LineTextChanging" TextWrapping="Wrap" Text="{Binding mTextBoxEditor.CurrentScript, Mode=TwoWay}" IsUndoEnabled="False" Watermark="(Line is Empty)" FontSize="15" CornerRadius="0"></TextBox>
<TextBox AcceptsReturn="True" LostFocus="LineLostFocus" GotFocus="LineGotFocus" TextChanged="LineTextChanged" TextWrapping="Wrap" Text="{Binding mTextBoxEditor.CurrentScript, Mode=TwoWay}" IsUndoEnabled="False" Watermark="(Line is Empty)" FontSize="15" CornerRadius="0"></TextBox>
</Border>
</UserControl>
37 changes: 27 additions & 10 deletions Mirivoice/Views/SingleLineEditorView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ public partial class SingleLineEditorView : UserControl
private readonly LineBoxView l;
private bool pointerExit;
public SingleLineEditorViewModel viewModel;
bool FirstUpdate = false;

public SingleLineEditorView(LineBoxView l)
public SingleLineEditorView(LineBoxView l, bool FirstUpdate = true)
{
InitializeComponent(l);
this.l = l;
this.pointerExit = false;


l.DeActivatePhonemizer = false;
this.FirstUpdate = FirstUpdate;
}


private async void LineTextChanging(object sender, TextChangingEventArgs e)
private async void LineTextChanged(object sender, TextChangedEventArgs e)
{

var textBox = sender as TextBox;
Expand All @@ -37,24 +38,30 @@ private async void LineTextChanging(object sender, TextChangingEventArgs e)
string textChanged = textBox.Text;
if (l is null)
{
//Log.Debug("LineBoxView is null");
Log.Debug("LineBoxView is null");
return;
}
if (l.viewModel.LineText == textBox.Text)
{
//Log.Debug($"No need to phonemize ---- SingleLineTBox '{textBox.Text}' // linePreview '{l.viewModel.LineText}' "); ;
Log.Debug($"No need to phonemize ---- SingleLineTBox '{textBox.Text}' // linePreview '{l.viewModel.LineText}' "); ;
l.DeActivatePhonemizer = true; // no need to phonemize
}
else
{
//Log.Debug($"SingleLineTBox '{textBox.Text}' // linePreview '{l.viewModel.LineText}' "); ;
Log.Debug($"SingleLineTBox '{textBox.Text}' // linePreview '{l.viewModel.LineText}' "); ;
l.viewModel.LineText = textChanged;
l.DeActivatePhonemizer = false;
if (FirstUpdate)
{
FirstUpdate = false;
Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));
return;
}
if (l.ShouldPhonemize && !l.DeActivatePhonemizer)
{
await Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(textChanged, l));

}



}
Expand All @@ -76,11 +83,21 @@ private async void LineTextChanging(object sender, TextChangingEventArgs e)
private void LineLostFocus(object sender, RoutedEventArgs e)
{
//Log.Debug("SingleLineTBox Lost Focus");

if (! l.DeActivatePhonemizer)

if (FirstUpdate)
{
FirstUpdate = false;
Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l));
return;
}


if (! l.DeActivatePhonemizer || l.MResultsCollection.Count == 0 && !string.IsNullOrEmpty(l.viewModel.LineText))
{
l.ShouldPhonemize = true;

}


}

Expand Down

0 comments on commit 10f65d3

Please sign in to comment.