diff --git a/OpenUtau.Core/Classic/PluginRunner.cs b/OpenUtau.Core/Classic/PluginRunner.cs index ab99288ac..0ee65635f 100644 --- a/OpenUtau.Core/Classic/PluginRunner.cs +++ b/OpenUtau.Core/Classic/PluginRunner.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Security.Cryptography; +using System.Threading.Tasks; using OpenUtau.Core; using OpenUtau.Core.Ustx; using Serilog; @@ -44,7 +45,7 @@ public PluginRunner(PathManager pathManager, Action onRepl OnError = onError; } - public void Execute(UProject project, UVoicePart part, UNote? first, UNote? last, IPlugin plugin) { + public async Task Execute(UProject project, UVoicePart part, UNote? first, UNote? last, IPlugin plugin) { if (first == null || last == null) { return; } @@ -59,7 +60,11 @@ public void Execute(UProject project, UVoicePart part, UNote? first, UNote? last return; } Log.Information("Legacy plugin temp file has changed."); - var (toRemove, toAdd) = Ust.ParsePlugin(project, part, first, last, sequence, tempFile, encoding: plugin.Encoding); + + var (toRemove, toAdd) = await Task.Run(() => + Ust.ParsePlugin(project, part, first, last, sequence, tempFile, encoding: plugin.Encoding) + ); + OnReplaceNote(new ReplaceNoteEventArgs(part, toRemove, toAdd)); } catch (Exception e) { OnError(new PluginErrorEventArgs("Failed to execute plugin", e)); diff --git a/OpenUtau/ViewModels/PianoRollViewModel.cs b/OpenUtau/ViewModels/PianoRollViewModel.cs index 2bcec2b0b..751043e22 100644 --- a/OpenUtau/ViewModels/PianoRollViewModel.cs +++ b/OpenUtau/ViewModels/PianoRollViewModel.cs @@ -147,27 +147,26 @@ public PianoRollViewModel() { DocManager.Inst.EndUndoGroup(); }); - legacyPluginCommand = ReactiveCommand.CreateFromTask(async plugin => { + legacyPluginCommand = ReactiveCommand.Create(async plugin => { if (NotesViewModel.Part == null || NotesViewModel.Part.notes.Count == 0) { return; } DocManager.Inst.ExecuteCmd(new LoadingNotification(typeof(PianoRollWindow), true, "legacy plugin")); try { - await Task.Run(() => { - var part = NotesViewModel.Part; - UNote? first; - UNote? last; - if (NotesViewModel.Selection.IsEmpty) { - first = part.notes.First(); - last = part.notes.Last(); - } else { - first = NotesViewModel.Selection.FirstOrDefault(); - last = NotesViewModel.Selection.LastOrDefault(); - } - var runner = PluginRunner.from(PathManager.Inst, DocManager.Inst); - runner.Execute(NotesViewModel.Project, part, first, last, plugin); - }); + var part = NotesViewModel.Part; + UNote? first; + UNote? last; + if (NotesViewModel.Selection.IsEmpty) { + first = part.notes.First(); + last = part.notes.Last(); + } else { + first = NotesViewModel.Selection.FirstOrDefault(); + last = NotesViewModel.Selection.LastOrDefault(); + } + var runner = PluginRunner.from(PathManager.Inst, DocManager.Inst); + await runner.Execute(NotesViewModel.Project, part, first, last, plugin); + } catch (Exception e) { DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(e)); } finally { diff --git a/OpenUtau/Views/MainWindow.axaml.cs b/OpenUtau/Views/MainWindow.axaml.cs index 673b6c6ea..159800d74 100644 --- a/OpenUtau/Views/MainWindow.axaml.cs +++ b/OpenUtau/Views/MainWindow.axaml.cs @@ -59,6 +59,7 @@ public MainWindow() { AskIfSaveAndContinue = AskIfSaveAndContinue }; + viewModel.NewProject(); viewModel.AddTempoChangeCmd = ReactiveCommand.Create(tick => AddTempoChange(tick)); viewModel.DelTempoChangeCmd = ReactiveCommand.Create(tick => DelTempoChange(tick)); viewModel.AddTimeSigChangeCmd = ReactiveCommand.Create(bar => AddTimeSigChange(bar)); @@ -509,8 +510,8 @@ void OnMenuExpressionss(object sender, RoutedEventArgs args) { } } - void OnMenuSingers(object sender, RoutedEventArgs args) { - OpenSingersWindow(); + async void OnMenuSingers(object sender, RoutedEventArgs args) { + await OpenSingersWindowAsync(); } /// @@ -525,11 +526,7 @@ void OnMenuSingers(object sender, RoutedEventArgs args) { return null; } - public void OpenSingersWindow() { - LoadingWindow.RunAsyncOnUIThread(OpenSingersWindowAsync); - } - - public async void OpenSingersWindowAsync() { + public async Task OpenSingersWindowAsync() { var lifetime = Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime; if (lifetime == null) { return; diff --git a/OpenUtau/Views/PianoRollWindow.axaml.cs b/OpenUtau/Views/PianoRollWindow.axaml.cs index 42b26a962..c3162c706 100644 --- a/OpenUtau/Views/PianoRollWindow.axaml.cs +++ b/OpenUtau/Views/PianoRollWindow.axaml.cs @@ -275,8 +275,10 @@ void OnMenuPlaybackAutoScroll(object sender, RoutedEventArgs args) { } } - void OnMenuSingers(object sender, RoutedEventArgs args) { - MainWindow?.OpenSingersWindow(); + async void OnMenuSingers(object sender, RoutedEventArgs args) { + if (MainWindow != null) { + await MainWindow.OpenSingersWindowAsync(); + } this.Activate(); try { USinger? singer = null; @@ -979,7 +981,7 @@ public void PhonemeCanvasDoubleTapped(object sender, TappedEventArgs args) { LyricBox?.Show(ViewModel.NotesViewModel.Part, new LyricBoxPhoneme(phoneme!), phoneme!.phoneme); } - public void PhonemeCanvasPointerPressed(object sender, PointerPressedEventArgs args) { + public async void PhonemeCanvasPointerPressed(object sender, PointerPressedEventArgs args) { LyricBox?.EndEdit(); if (ViewModel?.NotesViewModel?.Part == null) { return; @@ -997,7 +999,9 @@ public void PhonemeCanvasPointerPressed(object sender, PointerPressedEventArgs a if (Preferences.Default.OtoEditor == 1 && !string.IsNullOrEmpty(Preferences.Default.VLabelerPath)) { Integrations.VLabelerClient.Inst.GotoOto(singer, hitAliasInfo.phoneme.oto); } else { - MainWindow?.OpenSingersWindow(); + if (MainWindow != null) { + await MainWindow.OpenSingersWindowAsync(); + } this.Activate(); DocManager.Inst.ExecuteCmd(new GotoOtoNotification(singer, hitAliasInfo.phoneme.oto)); } @@ -1795,7 +1799,7 @@ public void AttachExpressions() { public void OnNext(UCommand cmd, bool isUndo) { if (cmd is LoadingNotification loadingNotif && loadingNotif.window == typeof(PianoRollWindow)) { if (loadingNotif.startLoading) { - LoadingWindow.BeginLoading(this); + LoadingWindow.BeginLoadingImmediate(this); } else { LoadingWindow.EndLoading(); }