Skip to content

Commit

Permalink
Added style icon
Browse files Browse the repository at this point in the history
  • Loading branch information
EX3exp committed Oct 14, 2024
1 parent 41e0a36 commit 932bf39
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 31 deletions.
Binary file modified Mirivoice/Assets/DefaultVoicers/Miri.z01
Binary file not shown.
Binary file modified Mirivoice/Assets/DefaultVoicers/Miri.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions Mirivoice/Commands/MementoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Execute(bool isRedoing)
if (!isRedoing)
{
_originator.ClearRedoMemento();
_originator.PrintMemento();
//_originator.PrintMemento();

//Log.Debug($"-- exec");
}
Expand All @@ -37,7 +37,7 @@ public void Execute(bool isRedoing)
}
//Log.Debug($"-- Redoing");
_originator.RestoreFromRedoMemento();
_originator.PrintMemento();
//_originator.PrintMemento();
}
}

Expand Down
5 changes: 1 addition & 4 deletions Mirivoice/Commands/SetComboboxOriginator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Mirivoice.Mirivoice.Core.Format;
using Mirivoice.ViewModels;
using Serilog;
using System;

namespace Mirivoice.Commands
{
Expand All @@ -20,7 +17,7 @@ public SetProsodyOriginator(ref int index, MResult v) : base(ref index)

public override void UpdateProperties()
{
Log.Debug("[Updating Properties] -- {obj}", obj);
//Log.Debug("[Updating Properties] -- {obj}", obj);
v.NotProcessingSetProsodyCommand = true; // prevent recursion loop
v.Prosody = obj;
}
Expand Down
8 changes: 2 additions & 6 deletions Mirivoice/Commands/VITS2SetExpOriginator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Mirivoice.Engines;
using Mirivoice.Mirivoice.Core.Format;
using Mirivoice.ViewModels;
using Serilog;
using System;
using Mirivoice.ViewModels;

namespace Mirivoice.Commands
{
Expand All @@ -29,7 +25,7 @@ public VITS2SetExpOriginator(ref int index, ExpressionEditViewModelVITS2 v, ExpV

public override void UpdateProperties()
{
Log.Debug("[Updating Properties] -- {obj}", obj);
//Log.Debug("[Updating Properties] -- {obj}", obj);
switch (type)
{
case ExpVITS2.Speed:
Expand Down
4 changes: 2 additions & 2 deletions Mirivoice/Engines/VoicerMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public partial class VoicerMeta
public string Phrase { get; set; } = "";
public string Description { get; set; } = "";


public string StyleIcon { get; set; } = "";





public VoicerMeta()
{
Expand Down
8 changes: 7 additions & 1 deletion Mirivoice/Mirivoice.Core/Editor/VoicerSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ public Voicer CurrentVoicer
{
this.RaiseAndSetIfChanged(ref _currentVoicer, value);
_currentVoicer.RefreshNickAndStyle();
v.OnStyleChanged();
OnPropertyChanged(nameof(CurrentVoicer));
v._currentDefaultVoicerIndex = Voicers.IndexOf(value);
OnPropertyChanged(nameof(CurrentDefaultVoicerIndex));

}

}
}



public event PropertyChangedEventHandler PropertyChanged;

Check warning on line 48 in Mirivoice/Mirivoice.Core/Editor/VoicerSelector.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

'VoicerSelector.PropertyChanged' hides inherited member 'ReactiveObject.PropertyChanged'. Use the new keyword if hiding was intended.

Check warning on line 48 in Mirivoice/Mirivoice.Core/Editor/VoicerSelector.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

Nullability of reference types in type of 'event PropertyChangedEventHandler VoicerSelector.PropertyChanged' doesn't match implicitly implemented member 'event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged'.

Check warning on line 48 in Mirivoice/Mirivoice.Core/Editor/VoicerSelector.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

'VoicerSelector.PropertyChanged' hides inherited member 'ReactiveObject.PropertyChanged'. Use the new keyword if hiding was intended.

Check warning on line 48 in Mirivoice/Mirivoice.Core/Editor/VoicerSelector.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

Nullability of reference types in type of 'event PropertyChangedEventHandler VoicerSelector.PropertyChanged' doesn't match implicitly implemented member 'event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged'.

Check warning on line 48 in Mirivoice/Mirivoice.Core/Editor/VoicerSelector.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

'VoicerSelector.PropertyChanged' hides inherited member 'ReactiveObject.PropertyChanged'. Use the new keyword if hiding was intended.

Check warning on line 48 in Mirivoice/Mirivoice.Core/Editor/VoicerSelector.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

Nullability of reference types in type of 'event PropertyChangedEventHandler VoicerSelector.PropertyChanged' doesn't match implicitly implemented member 'event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged'.

protected virtual void OnPropertyChanged(string propertyName)
Expand Down Expand Up @@ -119,6 +121,7 @@ public void UpdateVoicerCollection()
}
updatedVoicer.CurrentVoicerMeta = updatedVoicer.VoicerMetaCollection[metaIndex];
updatedVoicer.RefreshNickAndStyle();


voicersToUpdate.Add(new VoicerUpdate(updatedVoicer, updatedVoicerIndex));

Expand Down Expand Up @@ -223,6 +226,9 @@ public int CurrentDefaultVoicerIndex
this.RaiseAndSetIfChanged(ref _currentDefaultVoicerIndex, value);
_currentVoicer = Voicers[_currentDefaultVoicerIndex];
_currentVoicer.RefreshNickAndStyle();
v.OnStyleChanged();



v.OnVoicerChanged(_currentVoicer);
OnPropertyChanged(nameof(CurrentVoicer));
Expand Down
1 change: 1 addition & 0 deletions Mirivoice/Mirivoice.Core/Format/MResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class MResult : VoicerSelectingViewModelBase
int lastProsodyIndex;
public override MTextBoxEditor mTextBoxEditor { get; set; }

public override void OnStyleChanged() { }
private ImageBrush _bosIcon;
public ImageBrush BosIcon
{
Expand Down
15 changes: 15 additions & 0 deletions Mirivoice/Mirivoice.Core/Format/Voicer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Mirivoice.Commands;
using Mirivoice.Engines;
using Mirivoice.Engines.TTS;
using Mirivoice.ViewModels;
using Mirivoice.Views;
using ReactiveUI;
using Serilog;
Expand Down Expand Up @@ -51,6 +52,7 @@ public class Voicer : ReactiveObject, INotifyPropertyChanged

private VoicerMeta _currentVoicerMeta;
private VoicerMeta lastVoicerMeta;
private LineBoxViewModel lv;

private bool Undobackuped = false;

Expand All @@ -67,6 +69,14 @@ public void SetRootPath(string rootPath)
Engine.Init(this);
}

public void SetLineBoxViewModel(LineBoxViewModel lv)
{
this.lv = lv;
if (lv is not null)
{
lv.OnStyleChanged();
}
}
public void Inference(string ipaText, string cacheFilePath, LineBoxView l)
{
//Log.Debug("[Infer Started] --- ipaText");
Expand Down Expand Up @@ -129,6 +139,11 @@ public VoicerMeta CurrentVoicerMeta
}
this.RaiseAndSetIfChanged(ref _currentVoicerMeta, value);
this.RefreshNickAndStyle();

if (lv is not null)
{
lv.OnStyleChanged();
}
OnPropertyChanged(nameof(NickAndStyle));
OnPropertyChanged(nameof(CurrentVoicerMeta));

Expand Down
6 changes: 5 additions & 1 deletion Mirivoice/Mirivoice.Core/Managers/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@ private void OnPlaybackStopped(object? sender, EventArgs e)
if (audioPaths.Count == 0) // when stopped
{
v.isPlaying = false;
v.EnableGlobalPlay = true;
if (!_player.Paused)
{
v.EnableGlobalPlay = true;
}

v.EnablePreviewPlay = true;
if (!MainViewModelPlaying)
{
Expand Down
6 changes: 3 additions & 3 deletions Mirivoice/Mirivoice.Core/Managers/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void ClearStacks()
}
public void ExecuteCommand(ICommand command)
{
Log.Debug("======== ExecuteCommand ========");
//Log.Debug("======== ExecuteCommand ========");
command.Execute(false);
_undoStack.Push(command);
_redoStack.Clear();
Expand All @@ -71,7 +71,7 @@ public void ExecuteCommand(ICommand command)
StreamWriter writer = new StreamWriter("filePath", false, Encoding.UTF8);
public void Undo()
{
Log.Debug("======== Undo ========");
//Log.Debug("======== Undo ========");
if (_undoStack.Count > 0)
{
var command = _undoStack.Pop();
Expand All @@ -89,7 +89,7 @@ public void Undo()

public void Redo()
{
Log.Debug("======== Redo ========");
//Log.Debug("======== Redo ========");
if (_redoStack.Count > 0)
{
var command = _redoStack.Pop();
Expand Down
124 changes: 115 additions & 9 deletions Mirivoice/ViewModels/LineBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public string LineNo
}
}

private string _langCode;
private string _langCode;
public string LangCode
{
get => _langCode;
Expand Down Expand Up @@ -91,7 +91,7 @@ public string LineText
{
this.RaiseAndSetIfChanged(ref _lineText, value);
OnPropertyChanged(nameof(LineText));

}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ public ImageBrush Icon
{
get => _icon;

set
set
{
this.RaiseAndSetIfChanged(ref _icon, value);
OnPropertyChanged(nameof(Icon));
Expand All @@ -147,14 +147,16 @@ public override void OnVoicerChanged(Voicer voicer)
{
//Log.Debug($"OnVoicerChanged: {voicer.NickAndStyle}");
VoicerInfo vInfo = voicer.Info;
voicer.SetLineBoxViewModel(this);


if (phonemizer is null)
{
phonemizer = GetPhonemizer(voicerSelector.CurrentVoicer.Info.LangCode);
}
if (lastType is not null && lastType != voicer.Info.Type)
{
Log.Debug("Type Changed: {0}", voicer.Info.Type);
//Log.Debug("Type Changed: {0}", voicer.Info.Type);
l.ResetExpEditor(voicer.Info.Type);
}

Expand All @@ -164,18 +166,52 @@ public override void OnVoicerChanged(Voicer voicer)
VoicerType = voicer.Info.Type;
if (vInfo.Icon != null && vInfo.Icon != string.Empty)
{
string voicerIconPath = Path.Combine(voicer.RootPath,
vInfo.Icon.Replace('/', Path.DirectorySeparatorChar));
if (!File.Exists(voicerIconPath))
string voicerIconPath = null;
if (voicer.CurrentVoicerMeta.StyleIcon is not null)
{
return;
voicerIconPath = Path.Combine(voicer.RootPath,
voicer.CurrentVoicerMeta.StyleIcon.Replace('/', Path.DirectorySeparatorChar));
// try to get icon from style
if (voicerIconPath is not null && !File.Exists(voicerIconPath))
{
voicerIconPath = Path.Combine(voicer.RootPath,
vInfo.Icon.Replace('/', Path.DirectorySeparatorChar));
}
}
else
{
voicerIconPath = Path.Combine(voicerSelector.CurrentVoicer.RootPath,
vInfo.Icon.Replace('/', Path.DirectorySeparatorChar));
}


Icon
// try to get icon from voicer
if (voicerIconPath is not null && !File.Exists(voicerIconPath))
{
return;
}
if (voicerIconPath is not null)
{
Icon
= new ImageBrush(new Bitmap(voicerIconPath))
{
Stretch = Stretch.UniformToFill,
};
}
else
{
var uri = new Uri("avares://Mirivoice.Main/Assets/default_icon.bmp");
var assets = AssetLoader.Open(uri);

using (var stream = assets)
{
var bitmap = new Bitmap(stream);
Icon = new ImageBrush(bitmap)
{
Stretch = Stretch.UniformToFill
};
}
}

}
else
Expand All @@ -193,7 +229,77 @@ public override void OnVoicerChanged(Voicer voicer)
}
}
}
public override void OnStyleChanged()
{
Log.Information("OnStyleChanged");
VoicerInfo vInfo = voicerSelector.CurrentVoicer.Info;
if (vInfo.Icon != null && vInfo.Icon != string.Empty)
{
string voicerIconPath = null;
if (voicerSelector.CurrentVoicer.CurrentVoicerMeta.StyleIcon is not null)
{
voicerIconPath = Path.Combine(voicerSelector.CurrentVoicer.RootPath,
voicerSelector.CurrentVoicer.CurrentVoicerMeta.StyleIcon.Replace('/', Path.DirectorySeparatorChar));
// try to get icon from style
if (voicerIconPath is not null && !File.Exists(voicerIconPath))
{
voicerIconPath = Path.Combine(voicerSelector.CurrentVoicer.RootPath,
vInfo.Icon.Replace('/', Path.DirectorySeparatorChar));
}
}
else
{
voicerIconPath = Path.Combine(voicerSelector.CurrentVoicer.RootPath,
vInfo.Icon.Replace('/', Path.DirectorySeparatorChar));
}


// try to get icon from voicer
if (voicerIconPath is not null && !File.Exists(voicerIconPath))
{
return;
}
if (voicerIconPath is not null)
{
Icon
= new ImageBrush(new Bitmap(voicerIconPath))
{
Stretch = Stretch.UniformToFill,
};
}
else
{
var uri = new Uri("avares://Mirivoice.Main/Assets/default_icon.bmp");
var assets = AssetLoader.Open(uri);

using (var stream = assets)
{
var bitmap = new Bitmap(stream);
Icon = new ImageBrush(bitmap)
{
Stretch = Stretch.UniformToFill
};
}
}

OnPropertyChanged(nameof(Icon));
}
else
{
var uri = new Uri("avares://Mirivoice.Main/Assets/default_icon.bmp");
var assets = AssetLoader.Open(uri);

using (var stream = assets)
{
var bitmap = new Bitmap(stream);
Icon = new ImageBrush(bitmap)
{
Stretch = Stretch.UniformToFill
};
}
OnPropertyChanged(nameof(Icon));
}
}
bool cultureChangedFirst = false;
public override void OnVoicerCultureChanged(CultureInfo culture)
{
Expand Down
Loading

0 comments on commit 932bf39

Please sign in to comment.