mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 11:14:39 +00:00
Common -> Models
This commit is contained in:
@@ -65,6 +65,8 @@ namespace RedBookPlayer.GUI
|
||||
|
||||
Instance.Width = ((PlayerView)Instance.ContentControl.Content).Width;
|
||||
Instance.Height = ((PlayerView)Instance.ContentControl.Content).Height;
|
||||
|
||||
pvm.InitializeDigits();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -82,6 +84,8 @@ namespace RedBookPlayer.GUI
|
||||
|
||||
ContentControl.Content = new PlayerView();
|
||||
|
||||
((PlayerView)ContentControl.Content).PlayerViewModel.InitializeDigits();
|
||||
|
||||
CanResize = false;
|
||||
|
||||
KeyDown += OnKeyDown;
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
public PlayerViewModel PlayerViewModel => DataContext as PlayerViewModel;
|
||||
|
||||
/// <summary>
|
||||
/// Set of images representing the digits for the UI
|
||||
/// </summary>
|
||||
private Image[] _digits;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the UI based on the default theme
|
||||
/// </summary>
|
||||
@@ -42,15 +30,12 @@ namespace RedBookPlayer.GUI
|
||||
/// <param name="playerViewModel">Existing PlayerViewModel to load in instead of creating a new one</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the png image for a given character based on the theme
|
||||
/// </summary>
|
||||
/// <param name="character">Character to load the image for</param>
|
||||
/// <returns>Bitmap representing the loaded image</returns>
|
||||
private Bitmap GetBitmap(char character)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(App.Settings.SelectedTheme == "default")
|
||||
{
|
||||
IAssetLoader assets = AvaloniaLocator.Current.GetService<IAssetLoader>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the displayed digits array
|
||||
/// </summary>
|
||||
private void InitializeDigits()
|
||||
{
|
||||
_digits = new Image[]
|
||||
{
|
||||
this.FindControl<Image>("TrackDigit1"),
|
||||
this.FindControl<Image>("TrackDigit2"),
|
||||
|
||||
this.FindControl<Image>("IndexDigit1"),
|
||||
this.FindControl<Image>("IndexDigit2"),
|
||||
|
||||
this.FindControl<Image>("TimeDigit1"),
|
||||
this.FindControl<Image>("TimeDigit2"),
|
||||
this.FindControl<Image>("TimeDigit3"),
|
||||
this.FindControl<Image>("TimeDigit4"),
|
||||
this.FindControl<Image>("TimeDigit5"),
|
||||
this.FindControl<Image>("TimeDigit6"),
|
||||
|
||||
this.FindControl<Image>("TotalTracksDigit1"),
|
||||
this.FindControl<Image>("TotalTracksDigit2"),
|
||||
|
||||
this.FindControl<Image>("TotalIndexesDigit1"),
|
||||
this.FindControl<Image>("TotalIndexesDigit2"),
|
||||
|
||||
this.FindControl<Image>("TotalTimeDigit1"),
|
||||
this.FindControl<Image>("TotalTimeDigit2"),
|
||||
this.FindControl<Image>("TotalTimeDigit3"),
|
||||
this.FindControl<Image>("TotalTimeDigit4"),
|
||||
this.FindControl<Image>("TotalTimeDigit5"),
|
||||
this.FindControl<Image>("TotalTimeDigit6"),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the theme from a XAML, if possible
|
||||
/// </summary>
|
||||
@@ -146,23 +68,6 @@ namespace RedBookPlayer.GUI
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the UI from the view-model
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.12" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RedBookPlayer.Common\RedBookPlayer.Common.csproj" />
|
||||
<ProjectReference Include="..\RedBookPlayer.Models\RedBookPlayer.Models.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\*" />
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
private Player _player;
|
||||
|
||||
/// <summary>
|
||||
/// Set of images representing the digits for the UI
|
||||
/// </summary>
|
||||
private Image[] _digits;
|
||||
|
||||
#region Player Passthrough
|
||||
|
||||
#region OpticalDisc Passthrough
|
||||
@@ -433,11 +443,88 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Load a disc image from a selection box
|
||||
/// </summary>
|
||||
public async void ExecuteLoad()
|
||||
{
|
||||
string path = await GetPath();
|
||||
if(path == null)
|
||||
return;
|
||||
|
||||
await LoadImage(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the displayed digits array
|
||||
/// </summary>
|
||||
public void InitializeDigits()
|
||||
{
|
||||
PlayerView playerView = MainWindow.Instance.ContentControl.Content as PlayerView;
|
||||
|
||||
_digits = new Image[]
|
||||
{
|
||||
playerView.FindControl<Image>("TrackDigit1"),
|
||||
playerView.FindControl<Image>("TrackDigit2"),
|
||||
|
||||
playerView.FindControl<Image>("IndexDigit1"),
|
||||
playerView.FindControl<Image>("IndexDigit2"),
|
||||
|
||||
playerView.FindControl<Image>("TimeDigit1"),
|
||||
playerView.FindControl<Image>("TimeDigit2"),
|
||||
playerView.FindControl<Image>("TimeDigit3"),
|
||||
playerView.FindControl<Image>("TimeDigit4"),
|
||||
playerView.FindControl<Image>("TimeDigit5"),
|
||||
playerView.FindControl<Image>("TimeDigit6"),
|
||||
|
||||
playerView.FindControl<Image>("TotalTracksDigit1"),
|
||||
playerView.FindControl<Image>("TotalTracksDigit2"),
|
||||
|
||||
playerView.FindControl<Image>("TotalIndexesDigit1"),
|
||||
playerView.FindControl<Image>("TotalIndexesDigit2"),
|
||||
|
||||
playerView.FindControl<Image>("TotalTimeDigit1"),
|
||||
playerView.FindControl<Image>("TotalTimeDigit2"),
|
||||
playerView.FindControl<Image>("TotalTimeDigit3"),
|
||||
playerView.FindControl<Image>("TotalTimeDigit4"),
|
||||
playerView.FindControl<Image>("TotalTimeDigit5"),
|
||||
playerView.FindControl<Image>("TotalTimeDigit6"),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an image from the path
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the image to load</param>
|
||||
public async Task<bool> 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;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the value for loading data tracks [CompactDisc only]
|
||||
/// </summary>
|
||||
/// <param name="load">True to enable loading data tracks, false otherwise</param>
|
||||
public void SetLoadDataTracks(bool load) => _player?.SetLoadDataTracks(load);
|
||||
|
||||
/// <summary>
|
||||
/// Set the value for loading hidden tracks [CompactDisc only]
|
||||
/// </summary>
|
||||
/// <param name="load">True to enable loading hidden tracks, false otherwise</param>
|
||||
public void SetLoadHiddenTracks(bool load) => _player?.SetLoadHiddenTracks(load);
|
||||
|
||||
/// <summary>
|
||||
/// Generate the digit string to be interpreted by the frontend
|
||||
/// </summary>
|
||||
/// <returns>String representing the digits for the frontend</returns>
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load a disc image from a selection box
|
||||
/// Load the png image for a given character based on the theme
|
||||
/// </summary>
|
||||
public async void ExecuteLoad()
|
||||
/// <param name="character">Character to load the image for</param>
|
||||
/// <returns>Bitmap representing the loaded image</returns>
|
||||
private Bitmap GetBitmap(char character)
|
||||
{
|
||||
string path = await GetPath();
|
||||
if(path == null)
|
||||
return;
|
||||
|
||||
await LoadImage(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an image from the path
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the image to load</param>
|
||||
public async Task<bool> 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<IAssetLoader>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the value for loading data tracks [CompactDisc only]
|
||||
/// </summary>
|
||||
/// <param name="load">True to enable loading data tracks, false otherwise</param>
|
||||
public void SetLoadDataTracks(bool load) => _player?.SetLoadDataTracks(load);
|
||||
|
||||
/// <summary>
|
||||
/// Set the value for loading hidden tracks [CompactDisc only]
|
||||
/// </summary>
|
||||
/// <param name="load">True to enable loading hidden tracks, false otherwise</param>
|
||||
public void SetLoadHiddenTracks(bool load) => _player?.SetLoadHiddenTracks(load);
|
||||
|
||||
/// <summary>
|
||||
/// Get current sector time, accounting for offsets
|
||||
/// </summary>
|
||||
@@ -533,15 +608,18 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
/// <returns>User-selected path, if possible</returns>
|
||||
private async Task<string> GetPath()
|
||||
{
|
||||
var dialog = new OpenFileDialog { AllowMultiple = false };
|
||||
List<string> 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<string> 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();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -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
|
||||
{
|
||||
@@ -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
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using NWaves.Filters.BiQuad;
|
||||
|
||||
namespace RedBookPlayer.Common.Hardware
|
||||
namespace RedBookPlayer.Models.Hardware
|
||||
{
|
||||
/// <summary>
|
||||
/// Filter for applying de-emphasis to audio
|
||||
@@ -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
|
||||
{
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
using CSCore;
|
||||
using WaveFormat = CSCore.WaveFormat;
|
||||
|
||||
namespace RedBookPlayer.Common.Hardware
|
||||
namespace RedBookPlayer.Models.Hardware
|
||||
{
|
||||
public class PlayerSource : IWaveSource
|
||||
{
|
||||
@@ -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
|
||||
{
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user