Skip to content

Commit

Permalink
Merge pull request stakira#1327 from stakira/splash
Browse files Browse the repository at this point in the history
Adds a splash window
  • Loading branch information
stakira authored Nov 19, 2024
2 parents 45f3604 + 34d075b commit 2672d22
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 128 deletions.
6 changes: 3 additions & 3 deletions OpenUtau.Core/DocManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class DocManager : SingletonBase<DocManager> {
public List<UNote> NotesClipboard { get; set; }
internal PhonemizerRunner PhonemizerRunner { get; private set; }

public void Initialize() {
public void Initialize(Thread mainThread, TaskScheduler mainScheduler) {
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((sender, args) => {
CrashSave();
});
SearchAllPlugins();
SearchAllLegacyPlugins();
mainThread = Thread.CurrentThread;
mainScheduler = TaskScheduler.FromCurrentSynchronizationContext();
this.mainThread = mainThread;
this.mainScheduler = mainScheduler;
PhonemizerRunner = new PhonemizerRunner(mainScheduler);
}

Expand Down
53 changes: 20 additions & 33 deletions OpenUtau.Core/SingerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,31 @@ namespace OpenUtau.Core {
public class SingerManager : SingletonBase<SingerManager> {
public Dictionary<string, USinger> Singers { get; private set; } = new Dictionary<string, USinger>();
public Dictionary<USingerType, List<USinger>> SingerGroups { get; private set; } = new Dictionary<USingerType, List<USinger>>();
public Task? InitializationTask = null;

private readonly ConcurrentQueue<USinger> reloadQueue = new ConcurrentQueue<USinger>();
private CancellationTokenSource reloadCancellation;

private HashSet<USinger> singersUsed = new HashSet<USinger>();

public void Initialize() {
InitializationTask = Task.Run(() => {
SearchAllSingers();
});
SearchAllSingers();
}

public void SearchAllSingers() {
try {
Log.Information("Searching singers.");
Directory.CreateDirectory(PathManager.Inst.SingersPath);
var stopWatch = Stopwatch.StartNew();
var singers = ClassicSingerLoader.FindAllSingers()
.Concat(Vogen.VogenSingerLoader.FindAllSingers())
.Distinct();
Singers = singers
.ToLookup(s => s.Id)
.ToDictionary(g => g.Key, g => g.First());
SingerGroups = singers
.GroupBy(s => s.SingerType)
.ToDictionary(s => s.Key, s => s.LocalizedOrderBy(singer => singer.LocalizedName).ToList());
stopWatch.Stop();
Log.Information($"Search all singers: {stopWatch.Elapsed}");
} catch (Exception e) {
if (InitializationTask.Status == TaskStatus.Running) {
Log.Error(e, "Failed to search singers.");
} else {
var customEx = new MessageCustomizableException("Failed to search singers.", "<translate:errors.failed.searchsinger>", e);
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(customEx));
}
Singers = new Dictionary<string, USinger>();
}
Log.Information("Searching singers.");
Directory.CreateDirectory(PathManager.Inst.SingersPath);
var stopWatch = Stopwatch.StartNew();
var singers = ClassicSingerLoader.FindAllSingers()
.Concat(Vogen.VogenSingerLoader.FindAllSingers())
.Distinct();
Singers = singers
.ToLookup(s => s.Id)
.ToDictionary(g => g.Key, g => g.First());
SingerGroups = singers
.GroupBy(s => s.SingerType)
.ToDictionary(s => s.Key, s => s.LocalizedOrderBy(singer => singer.LocalizedName).ToList());
stopWatch.Stop();
Log.Information($"Search all singers: {stopWatch.Elapsed}");
}

public USinger GetSinger(string name) {
Expand Down Expand Up @@ -122,15 +109,15 @@ private void Refresh() {
public void ReleaseSingersNotInUse(UProject project) {
//Check which singers are in use
var singersInUse = new HashSet<USinger>();
foreach(var track in project.tracks){
foreach (var track in project.tracks) {
var singer = track.Singer;
if(singer != null && singer.Found && !singersInUse.Contains(singer)) {
if (singer != null && singer.Found && !singersInUse.Contains(singer)) {
singersInUse.Add(singer);
}
}
//Release singers that are no longer in use
foreach(var singer in singersUsed){
if(!singersInUse.Contains(singer)){
foreach (var singer in singersUsed) {
if (!singersInUse.Contains(singer)) {
singer.FreeMemory();
}
}
Expand Down
31 changes: 1 addition & 30 deletions OpenUtau/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ public override void Initialize() {
AvaloniaXamlLoader.Load(this);
InitializeCulture();
InitializeTheme();
InitOpenUtau();
InitAudio();
Log.Information("Initialized application.");
}

public override void OnFrameworkInitializationCompleted() {
Log.Information("Framework initialization completed.");
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
desktop.MainWindow = new MainWindow();
desktop.MainWindow = new SplashWindow();
}

base.OnFrameworkInitializationCompleted();
Expand Down Expand Up @@ -112,32 +110,5 @@ public static void SetTheme() {
}
ThemeManager.LoadTheme();
}

public static void InitOpenUtau() {
Log.Information("Initializing OpenUtau.");
ToolsManager.Inst.Initialize();
SingerManager.Inst.Initialize();
DocManager.Inst.Initialize();
DocManager.Inst.PostOnUIThread = action => Avalonia.Threading.Dispatcher.UIThread.Post(action);
Log.Information("Initialized OpenUtau.");
}

public static void InitAudio() {
Log.Information("Initializing audio.");
if (!OS.IsWindows() || Core.Util.Preferences.Default.PreferPortAudio) {
try {
PlaybackManager.Inst.AudioOutput = new Audio.MiniAudioOutput();
} catch (Exception e1) {
Log.Error(e1, "Failed to init MiniAudio");
}
} else {
try {
PlaybackManager.Inst.AudioOutput = new Audio.NAudioOutput();
} catch (Exception e2) {
Log.Error(e2, "Failed to init NAudio");
}
}
Log.Information("Initialized audio.");
}
}
}
4 changes: 0 additions & 4 deletions OpenUtau/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ public void Redo() {
DocManager.Inst.Redo();
}

public Task? GetInitSingerTask() {
return SingerManager.Inst.InitializationTask;
}

public void InitProject() {
var args = Environment.GetCommandLineArgs();
if (args.Length == 2 && File.Exists(args[1])) {
Expand Down
5 changes: 1 addition & 4 deletions OpenUtau/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</Style>
</Window.Styles>
<Grid>
<Grid Name="MainGrid" DragDrop.AllowDrop="True" IsEnabled="False" IsVisible="False" Margin="{Binding $parent[1].WindowDecorationMargin}">
<Grid Name="MainGrid" DragDrop.AllowDrop="True" Margin="{Binding $parent[1].WindowDecorationMargin}">
<Grid RowDefinitions="24,24,1*,20,4" ColumnDefinitions="300,*,24" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Menu Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left"
Opened="OnMainMenuOpened" Closed="OnMainMenuClosed" PointerExited="OnMainMenuPointerLeave">
Expand Down Expand Up @@ -269,8 +269,5 @@
<ProgressBar Grid.Row="4" Grid.ColumnSpan="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Value="{Binding Progress}"/>
</Grid>
</Grid>
<Border Name="Splash">
<TextBlock Text="{DynamicResource progress.loadingsingers}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</Grid>
</Window>
Loading

0 comments on commit 2672d22

Please sign in to comment.