diff --git a/RedBookPlayer.GUI/MainWindow.xaml.cs b/RedBookPlayer.GUI/MainWindow.xaml.cs
index 08fd2b1..95d8ff0 100644
--- a/RedBookPlayer.GUI/MainWindow.xaml.cs
+++ b/RedBookPlayer.GUI/MainWindow.xaml.cs
@@ -65,6 +65,8 @@ namespace RedBookPlayer.GUI
Instance.Width = ((PlayerView)Instance.ContentControl.Content).Width;
Instance.Height = ((PlayerView)Instance.ContentControl.Content).Height;
+
+ pvm.InitializeDigits();
}
///
@@ -82,6 +84,8 @@ namespace RedBookPlayer.GUI
ContentControl.Content = new PlayerView();
+ ((PlayerView)ContentControl.Content).PlayerViewModel.InitializeDigits();
+
CanResize = false;
KeyDown += OnKeyDown;
diff --git a/RedBookPlayer.GUI/PlayerView.xaml.cs b/RedBookPlayer.GUI/PlayerView.xaml.cs
index a4596fd..bda4343 100644
--- a/RedBookPlayer.GUI/PlayerView.xaml.cs
+++ b/RedBookPlayer.GUI/PlayerView.xaml.cs
@@ -1,12 +1,5 @@
-using System;
-using System.ComponentModel;
-using System.IO;
-using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
-using Avalonia.Media.Imaging;
-using Avalonia.Platform;
-using Avalonia.Threading;
using RedBookPlayer.GUI.ViewModels;
namespace RedBookPlayer.GUI
@@ -18,11 +11,6 @@ namespace RedBookPlayer.GUI
///
public PlayerViewModel PlayerViewModel => DataContext as PlayerViewModel;
- ///
- /// Set of images representing the digits for the UI
- ///
- private Image[] _digits;
-
///
/// Initialize the UI based on the default theme
///
@@ -42,15 +30,12 @@ namespace RedBookPlayer.GUI
/// Existing PlayerViewModel to load in instead of creating a new one
public PlayerView(string xaml, PlayerViewModel playerViewModel)
{
+ LoadTheme(xaml);
+
if(playerViewModel != null)
DataContext = playerViewModel;
else
DataContext = new PlayerViewModel();
-
- PlayerViewModel.PropertyChanged += PlayerViewModelStateChanged;
-
- LoadTheme(xaml);
- InitializeDigits();
}
#region Helpers
@@ -64,69 +49,6 @@ namespace RedBookPlayer.GUI
PlayerViewModel.SetLoadHiddenTracks(App.Settings.PlayHiddenTracks);
}
- ///
- /// Load the png image for a given character based on the theme
- ///
- /// Character to load the image for
- /// Bitmap representing the loaded image
- private Bitmap GetBitmap(char character)
- {
- try
- {
- if(App.Settings.SelectedTheme == "default")
- {
- IAssetLoader assets = AvaloniaLocator.Current.GetService();
-
- return new Bitmap(assets.Open(new Uri($"avares://RedBookPlayer/Assets/{character}.png")));
- }
- else
- {
- string themeDirectory = $"{Directory.GetCurrentDirectory()}/themes/{App.Settings.SelectedTheme}";
- using FileStream stream = File.Open($"{themeDirectory}/{character}.png", FileMode.Open);
- return new Bitmap(stream);
- }
- }
- catch
- {
- return null;
- }
- }
-
- ///
- /// Initialize the displayed digits array
- ///
- private void InitializeDigits()
- {
- _digits = new Image[]
- {
- this.FindControl("TrackDigit1"),
- this.FindControl("TrackDigit2"),
-
- this.FindControl("IndexDigit1"),
- this.FindControl("IndexDigit2"),
-
- this.FindControl("TimeDigit1"),
- this.FindControl("TimeDigit2"),
- this.FindControl("TimeDigit3"),
- this.FindControl("TimeDigit4"),
- this.FindControl("TimeDigit5"),
- this.FindControl("TimeDigit6"),
-
- this.FindControl("TotalTracksDigit1"),
- this.FindControl("TotalTracksDigit2"),
-
- this.FindControl("TotalIndexesDigit1"),
- this.FindControl("TotalIndexesDigit2"),
-
- this.FindControl("TotalTimeDigit1"),
- this.FindControl("TotalTimeDigit2"),
- this.FindControl("TotalTimeDigit3"),
- this.FindControl("TotalTimeDigit4"),
- this.FindControl("TotalTimeDigit5"),
- this.FindControl("TotalTimeDigit6"),
- };
- }
-
///
/// Load the theme from a XAML, if possible
///
@@ -146,23 +68,6 @@ namespace RedBookPlayer.GUI
}
}
- ///
- /// Update the UI from the view-model
- ///
- private void PlayerViewModelStateChanged(object sender, PropertyChangedEventArgs e)
- {
- Dispatcher.UIThread.InvokeAsync(() =>
- {
- string digitString = PlayerViewModel?.GenerateDigitString() ?? string.Empty.PadLeft(20, '-');
- for(int i = 0; i < _digits.Length; i++)
- {
- Bitmap digitImage = GetBitmap(digitString[i]);
- if(_digits[i] != null && digitImage != null)
- _digits[i].Source = digitImage;
- }
- });
- }
-
#endregion
}
}
\ No newline at end of file
diff --git a/RedBookPlayer.GUI/RedBookPlayer.GUI.csproj b/RedBookPlayer.GUI/RedBookPlayer.GUI.csproj
index d2a03b6..36d6bb4 100644
--- a/RedBookPlayer.GUI/RedBookPlayer.GUI.csproj
+++ b/RedBookPlayer.GUI/RedBookPlayer.GUI.csproj
@@ -23,7 +23,7 @@
-
+
diff --git a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs
index df8269b..b7b227d 100644
--- a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs
+++ b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs
@@ -1,12 +1,17 @@
+using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.IO;
using System.Linq;
using System.Reactive;
using System.Threading.Tasks;
+using Avalonia;
using Avalonia.Controls;
+using Avalonia.Media.Imaging;
+using Avalonia.Platform;
using Avalonia.Threading;
using ReactiveUI;
-using RedBookPlayer.Common.Hardware;
+using RedBookPlayer.Models.Hardware;
namespace RedBookPlayer.GUI.ViewModels
{
@@ -17,6 +22,11 @@ namespace RedBookPlayer.GUI.ViewModels
///
private Player _player;
+ ///
+ /// Set of images representing the digits for the UI
+ ///
+ private Image[] _digits;
+
#region Player Passthrough
#region OpticalDisc Passthrough
@@ -433,11 +443,88 @@ namespace RedBookPlayer.GUI.ViewModels
#region Helpers
+ ///
+ /// Load a disc image from a selection box
+ ///
+ public async void ExecuteLoad()
+ {
+ string path = await GetPath();
+ if(path == null)
+ return;
+
+ await LoadImage(path);
+ }
+
+ ///
+ /// Initialize the displayed digits array
+ ///
+ public void InitializeDigits()
+ {
+ PlayerView playerView = MainWindow.Instance.ContentControl.Content as PlayerView;
+
+ _digits = new Image[]
+ {
+ playerView.FindControl("TrackDigit1"),
+ playerView.FindControl("TrackDigit2"),
+
+ playerView.FindControl("IndexDigit1"),
+ playerView.FindControl("IndexDigit2"),
+
+ playerView.FindControl("TimeDigit1"),
+ playerView.FindControl("TimeDigit2"),
+ playerView.FindControl("TimeDigit3"),
+ playerView.FindControl("TimeDigit4"),
+ playerView.FindControl("TimeDigit5"),
+ playerView.FindControl("TimeDigit6"),
+
+ playerView.FindControl("TotalTracksDigit1"),
+ playerView.FindControl("TotalTracksDigit2"),
+
+ playerView.FindControl("TotalIndexesDigit1"),
+ playerView.FindControl("TotalIndexesDigit2"),
+
+ playerView.FindControl("TotalTimeDigit1"),
+ playerView.FindControl("TotalTimeDigit2"),
+ playerView.FindControl("TotalTimeDigit3"),
+ playerView.FindControl("TotalTimeDigit4"),
+ playerView.FindControl("TotalTimeDigit5"),
+ playerView.FindControl("TotalTimeDigit6"),
+ };
+ }
+
+ ///
+ /// Load an image from the path
+ ///
+ /// Path to the image to load
+ public async Task LoadImage(string path)
+ {
+ return await Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ Init(path, App.Settings.GenerateMissingTOC, App.Settings.PlayHiddenTracks, App.Settings.PlayDataTracks, App.Settings.AutoPlay, App.Settings.Volume);
+ if(Initialized)
+ MainWindow.Instance.Title = "RedBookPlayer - " + path.Split('/').Last().Split('\\').Last();
+
+ return Initialized;
+ });
+ }
+
+ ///
+ /// Set the value for loading data tracks [CompactDisc only]
+ ///
+ /// True to enable loading data tracks, false otherwise
+ public void SetLoadDataTracks(bool load) => _player?.SetLoadDataTracks(load);
+
+ ///
+ /// Set the value for loading hidden tracks [CompactDisc only]
+ ///
+ /// True to enable loading hidden tracks, false otherwise
+ public void SetLoadHiddenTracks(bool load) => _player?.SetLoadHiddenTracks(load);
+
///
/// Generate the digit string to be interpreted by the frontend
///
/// String representing the digits for the frontend
- public string GenerateDigitString()
+ private string GenerateDigitString()
{
// If the disc isn't initialized, return all '-' characters
if(Initialized != true)
@@ -473,45 +560,33 @@ namespace RedBookPlayer.GUI.ViewModels
}
///
- /// Load a disc image from a selection box
+ /// Load the png image for a given character based on the theme
///
- public async void ExecuteLoad()
+ /// Character to load the image for
+ /// Bitmap representing the loaded image
+ private Bitmap GetBitmap(char character)
{
- string path = await GetPath();
- if(path == null)
- return;
-
- await LoadImage(path);
- }
-
- ///
- /// Load an image from the path
- ///
- /// Path to the image to load
- public async Task LoadImage(string path)
- {
- return await Dispatcher.UIThread.InvokeAsync(() =>
+ try
{
- Init(path, App.Settings.GenerateMissingTOC, App.Settings.PlayHiddenTracks, App.Settings.PlayDataTracks, App.Settings.AutoPlay, App.Settings.Volume);
- if(Initialized)
- MainWindow.Instance.Title = "RedBookPlayer - " + path.Split('/').Last().Split('\\').Last();
+ if(App.Settings.SelectedTheme == "default")
+ {
+ IAssetLoader assets = AvaloniaLocator.Current.GetService();
- return Initialized;
- });
+ return new Bitmap(assets.Open(new Uri($"avares://RedBookPlayer/Assets/{character}.png")));
+ }
+ else
+ {
+ string themeDirectory = $"{Directory.GetCurrentDirectory()}/themes/{App.Settings.SelectedTheme}";
+ using FileStream stream = File.Open($"{themeDirectory}/{character}.png", FileMode.Open);
+ return new Bitmap(stream);
+ }
+ }
+ catch
+ {
+ return null;
+ }
}
- ///
- /// Set the value for loading data tracks [CompactDisc only]
- ///
- /// True to enable loading data tracks, false otherwise
- public void SetLoadDataTracks(bool load) => _player?.SetLoadDataTracks(load);
-
- ///
- /// Set the value for loading hidden tracks [CompactDisc only]
- ///
- /// True to enable loading hidden tracks, false otherwise
- public void SetLoadHiddenTracks(bool load) => _player?.SetLoadHiddenTracks(load);
-
///
/// Get current sector time, accounting for offsets
///
@@ -533,15 +608,18 @@ namespace RedBookPlayer.GUI.ViewModels
/// User-selected path, if possible
private async Task GetPath()
{
- var dialog = new OpenFileDialog { AllowMultiple = false };
- List knownExtensions = new Aaru.DiscImages.AaruFormat().KnownExtensions.ToList();
- dialog.Filters.Add(new FileDialogFilter()
+ return await Dispatcher.UIThread.InvokeAsync(async () =>
{
- Name = "Aaru Image Format (*" + string.Join(", *", knownExtensions) + ")",
- Extensions = knownExtensions.ConvertAll(e => e.TrimStart('.'))
- });
+ var dialog = new OpenFileDialog { AllowMultiple = false };
+ List knownExtensions = new Aaru.DiscImages.AaruFormat().KnownExtensions.ToList();
+ dialog.Filters.Add(new FileDialogFilter()
+ {
+ Name = "Aaru Image Format (*" + string.Join(", *", knownExtensions) + ")",
+ Extensions = knownExtensions.ConvertAll(e => e.TrimStart('.'))
+ });
- return (await dialog.ShowAsync(MainWindow.Instance))?.FirstOrDefault();
+ return (await dialog.ShowAsync(MainWindow.Instance))?.FirstOrDefault();
+ });
}
///
@@ -567,6 +645,17 @@ namespace RedBookPlayer.GUI.ViewModels
Playing = _player.Playing;
ApplyDeEmphasis = _player.ApplyDeEmphasis;
Volume = _player.Volume;
+
+ Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ string digitString = GenerateDigitString() ?? string.Empty.PadLeft(20, '-');
+ for(int i = 0; i < _digits.Length; i++)
+ {
+ Bitmap digitImage = GetBitmap(digitString[i]);
+ if(_digits[i] != null && digitImage != null)
+ _digits[i].Source = digitImage;
+ }
+ });
}
#endregion
diff --git a/RedBookPlayer.Common/Discs/CompactDisc.cs b/RedBookPlayer.Models/Discs/CompactDisc.cs
similarity index 99%
rename from RedBookPlayer.Common/Discs/CompactDisc.cs
rename to RedBookPlayer.Models/Discs/CompactDisc.cs
index 45c634e..6690b6e 100644
--- a/RedBookPlayer.Common/Discs/CompactDisc.cs
+++ b/RedBookPlayer.Models/Discs/CompactDisc.cs
@@ -9,7 +9,7 @@ using Aaru.Helpers;
using ReactiveUI;
using static Aaru.Decoders.CD.FullTOC;
-namespace RedBookPlayer.Common.Discs
+namespace RedBookPlayer.Models.Discs
{
public class CompactDisc : OpticalDiscBase, IReactiveObject
{
diff --git a/RedBookPlayer.Common/Discs/OpticalDiscBase.cs b/RedBookPlayer.Models/Discs/OpticalDiscBase.cs
similarity index 99%
rename from RedBookPlayer.Common/Discs/OpticalDiscBase.cs
rename to RedBookPlayer.Models/Discs/OpticalDiscBase.cs
index 0a0ab60..f2ce155 100644
--- a/RedBookPlayer.Common/Discs/OpticalDiscBase.cs
+++ b/RedBookPlayer.Models/Discs/OpticalDiscBase.cs
@@ -2,7 +2,7 @@ using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using ReactiveUI;
-namespace RedBookPlayer.Common.Discs
+namespace RedBookPlayer.Models.Discs
{
public abstract class OpticalDiscBase : ReactiveObject
{
diff --git a/RedBookPlayer.Common/Factories/OpticalDiscFactory.cs b/RedBookPlayer.Models/Factories/OpticalDiscFactory.cs
similarity index 98%
rename from RedBookPlayer.Common/Factories/OpticalDiscFactory.cs
rename to RedBookPlayer.Models/Factories/OpticalDiscFactory.cs
index b4f290c..d09beaf 100644
--- a/RedBookPlayer.Common/Factories/OpticalDiscFactory.cs
+++ b/RedBookPlayer.Models/Factories/OpticalDiscFactory.cs
@@ -3,9 +3,9 @@ using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Metadata;
using Aaru.DiscImages;
using Aaru.Filters;
-using RedBookPlayer.Common.Discs;
+using RedBookPlayer.Models.Discs;
-namespace RedBookPlayer.Common.Factories
+namespace RedBookPlayer.Models.Factories
{
public static class OpticalDiscFactory
{
diff --git a/RedBookPlayer.Common/Hardware/DeEmphasisFilter.cs b/RedBookPlayer.Models/Hardware/DeEmphasisFilter.cs
similarity index 97%
rename from RedBookPlayer.Common/Hardware/DeEmphasisFilter.cs
rename to RedBookPlayer.Models/Hardware/DeEmphasisFilter.cs
index d33117e..5b74b1d 100644
--- a/RedBookPlayer.Common/Hardware/DeEmphasisFilter.cs
+++ b/RedBookPlayer.Models/Hardware/DeEmphasisFilter.cs
@@ -1,7 +1,7 @@
using System;
using NWaves.Filters.BiQuad;
-namespace RedBookPlayer.Common.Hardware
+namespace RedBookPlayer.Models.Hardware
{
///
/// Filter for applying de-emphasis to audio
diff --git a/RedBookPlayer.Common/Hardware/Player.cs b/RedBookPlayer.Models/Hardware/Player.cs
similarity index 99%
rename from RedBookPlayer.Common/Hardware/Player.cs
rename to RedBookPlayer.Models/Hardware/Player.cs
index 8bf225c..7db9f0c 100644
--- a/RedBookPlayer.Common/Hardware/Player.cs
+++ b/RedBookPlayer.Models/Hardware/Player.cs
@@ -2,10 +2,10 @@ using System;
using System.ComponentModel;
using Aaru.CommonTypes.Enums;
using ReactiveUI;
-using RedBookPlayer.Common.Discs;
-using RedBookPlayer.Common.Factories;
+using RedBookPlayer.Models.Discs;
+using RedBookPlayer.Models.Factories;
-namespace RedBookPlayer.Common.Hardware
+namespace RedBookPlayer.Models.Hardware
{
public class Player : ReactiveObject
{
diff --git a/RedBookPlayer.Common/Hardware/PlayerSource.cs b/RedBookPlayer.Models/Hardware/PlayerSource.cs
similarity index 96%
rename from RedBookPlayer.Common/Hardware/PlayerSource.cs
rename to RedBookPlayer.Models/Hardware/PlayerSource.cs
index 630a8d1..203ff4f 100644
--- a/RedBookPlayer.Common/Hardware/PlayerSource.cs
+++ b/RedBookPlayer.Models/Hardware/PlayerSource.cs
@@ -2,7 +2,7 @@ using System;
using CSCore;
using WaveFormat = CSCore.WaveFormat;
-namespace RedBookPlayer.Common.Hardware
+namespace RedBookPlayer.Models.Hardware
{
public class PlayerSource : IWaveSource
{
diff --git a/RedBookPlayer.Common/Hardware/SoundOutput.cs b/RedBookPlayer.Models/Hardware/SoundOutput.cs
similarity index 99%
rename from RedBookPlayer.Common/Hardware/SoundOutput.cs
rename to RedBookPlayer.Models/Hardware/SoundOutput.cs
index 89f2b8c..743c35b 100644
--- a/RedBookPlayer.Common/Hardware/SoundOutput.cs
+++ b/RedBookPlayer.Models/Hardware/SoundOutput.cs
@@ -5,9 +5,9 @@ using CSCore.SoundOut;
using NWaves.Audio;
using NWaves.Filters.BiQuad;
using ReactiveUI;
-using RedBookPlayer.Common.Discs;
+using RedBookPlayer.Models.Discs;
-namespace RedBookPlayer.Common.Hardware
+namespace RedBookPlayer.Models.Hardware
{
public class SoundOutput : ReactiveObject
{
diff --git a/RedBookPlayer.Common/RedBookPlayer.Common.csproj b/RedBookPlayer.Models/RedBookPlayer.Models.csproj
similarity index 100%
rename from RedBookPlayer.Common/RedBookPlayer.Common.csproj
rename to RedBookPlayer.Models/RedBookPlayer.Models.csproj
diff --git a/RedBookPlayer.Common/nuget.config b/RedBookPlayer.Models/nuget.config
similarity index 100%
rename from RedBookPlayer.Common/nuget.config
rename to RedBookPlayer.Models/nuget.config
diff --git a/RedBookPlayer.sln b/RedBookPlayer.sln
index a36debc..3b35228 100644
--- a/RedBookPlayer.sln
+++ b/RedBookPlayer.sln
@@ -40,7 +40,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedBookPlayer.Common", "RedBookPlayer.Common\RedBookPlayer.Common.csproj", "{462A3B8E-A5D4-4539-8469-1647B47AB2A8}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedBookPlayer.Models", "RedBookPlayer.Models\RedBookPlayer.Models.csproj", "{462A3B8E-A5D4-4539-8469-1647B47AB2A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution