mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 19:24:41 +00:00
Port only distinct new feature work
This commit is contained in:
@@ -40,6 +40,23 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
PlayerView?.ViewModel?.ExecuteLoad();
|
||||
}
|
||||
|
||||
// Save track(s)
|
||||
else if(e.Key == App.Settings.SaveTrackKey)
|
||||
{
|
||||
if(PlayerView?.ViewModel == null || !PlayerView.ViewModel.Initialized)
|
||||
return;
|
||||
|
||||
var dialog = new OpenFolderDialog();
|
||||
string path = await dialog.ShowAsync(App.MainWindow);
|
||||
if(string.IsNullOrWhiteSpace(path))
|
||||
return;
|
||||
|
||||
if(e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||
PlayerView.ViewModel.ExtractAllTracksToWav(path);
|
||||
else
|
||||
PlayerView.ViewModel.ExtractSingleTrackToWav((uint)PlayerView.ViewModel.CurrentTrackNumber, path);
|
||||
}
|
||||
|
||||
// Toggle playback
|
||||
else if(e.Key == App.Settings.TogglePlaybackKey || e.Key == Key.MediaPlayPause)
|
||||
{
|
||||
@@ -52,6 +69,12 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
PlayerView?.ViewModel?.ExecuteStop();
|
||||
}
|
||||
|
||||
// Eject
|
||||
else if(e.Key == App.Settings.EjectKey)
|
||||
{
|
||||
PlayerView?.ViewModel?.ExecuteEject();
|
||||
}
|
||||
|
||||
// Next Track
|
||||
else if(e.Key == App.Settings.NextTrackKey || e.Key == Key.MediaNextTrack)
|
||||
{
|
||||
|
||||
@@ -6,11 +6,9 @@ using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
using RedBookPlayer.Models;
|
||||
@@ -193,6 +191,15 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
private set => this.RaiseAndSetIfChanged(ref _dataPlayback, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the repeat mode
|
||||
/// </summary>
|
||||
public RepeatMode RepeatMode
|
||||
{
|
||||
get => _repeatMode;
|
||||
private set => this.RaiseAndSetIfChanged(ref _repeatMode, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if de-emphasis should be applied
|
||||
/// </summary>
|
||||
@@ -214,6 +221,7 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
private bool _initialized;
|
||||
private PlayerState _playerState;
|
||||
private DataPlayback _dataPlayback;
|
||||
private RepeatMode _repeatMode;
|
||||
private bool _applyDeEmphasis;
|
||||
private int _volume;
|
||||
|
||||
@@ -250,6 +258,11 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
/// </summary>
|
||||
public ReactiveCommand<Unit, Unit> StopCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Command for ejecting the current disc
|
||||
/// </summary>
|
||||
public ReactiveCommand<Unit, Unit> EjectCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Command for moving to the next track
|
||||
/// </summary>
|
||||
@@ -334,6 +347,7 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
PauseCommand = ReactiveCommand.Create(ExecutePause);
|
||||
TogglePlayPauseCommand = ReactiveCommand.Create(ExecuteTogglePlayPause);
|
||||
StopCommand = ReactiveCommand.Create(ExecuteStop);
|
||||
EjectCommand = ReactiveCommand.Create(ExecuteEject);
|
||||
NextTrackCommand = ReactiveCommand.Create(ExecuteNextTrack);
|
||||
PreviousTrackCommand = ReactiveCommand.Create(ExecutePreviousTrack);
|
||||
NextIndexCommand = ReactiveCommand.Create(ExecuteNextIndex);
|
||||
@@ -359,15 +373,16 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the disc image</param>
|
||||
/// <param name="options">Options to pass to the optical disc factory</param>
|
||||
/// <param name="repeatMode">RepeatMode for sound output</param>
|
||||
/// <param name="autoPlay">True if playback should begin immediately, false otherwise</param>
|
||||
public void Init(string path, OpticalDiscOptions options, bool autoPlay)
|
||||
public void Init(string path, OpticalDiscOptions options, RepeatMode repeatMode, bool autoPlay)
|
||||
{
|
||||
// Stop current playback, if necessary
|
||||
if(PlayerState != PlayerState.NoDisc)
|
||||
ExecuteStop();
|
||||
|
||||
// Attempt to initialize Player
|
||||
_player.Init(path, options, autoPlay);
|
||||
_player.Init(path, options, repeatMode, autoPlay);
|
||||
if(_player.Initialized)
|
||||
{
|
||||
_player.PropertyChanged += PlayerStateChanged;
|
||||
@@ -397,6 +412,11 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
/// </summary>
|
||||
public void ExecuteStop() => _player?.Stop();
|
||||
|
||||
/// <summary>
|
||||
/// Eject the currently loaded disc
|
||||
/// </summary>
|
||||
public void ExecuteEject() => _player?.Eject();
|
||||
|
||||
/// <summary>
|
||||
/// Move to the next playable track
|
||||
/// </summary>
|
||||
@@ -578,13 +598,14 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
DataPlayback = App.Settings.DataPlayback,
|
||||
GenerateMissingToc = App.Settings.GenerateMissingTOC,
|
||||
LoadHiddenTracks = App.Settings.PlayHiddenTracks,
|
||||
SessionHandling = App.Settings.SessionHandling,
|
||||
};
|
||||
|
||||
// Ensure the context and view model are set
|
||||
App.PlayerView.DataContext = this;
|
||||
App.PlayerView.ViewModel = this;
|
||||
|
||||
Init(path, options, App.Settings.AutoPlay);
|
||||
Init(path, options, App.Settings.RepeatMode, App.Settings.AutoPlay);
|
||||
if(Initialized)
|
||||
App.MainWindow.Title = "RedBookPlayer - " + path.Split('/').Last().Split('\\').Last();
|
||||
|
||||
@@ -599,8 +620,23 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
{
|
||||
SetDataPlayback(App.Settings.DataPlayback);
|
||||
SetLoadHiddenTracks(App.Settings.PlayHiddenTracks);
|
||||
SetRepeatMode(App.Settings.RepeatMode);
|
||||
SetSessionHandling(App.Settings.SessionHandling);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract a single track from the image to WAV
|
||||
/// </summary>
|
||||
/// <param name="trackNumber"></param>
|
||||
/// <param name="outputDirectory">Output path to write data to</param
|
||||
public void ExtractSingleTrackToWav(uint trackNumber, string outputDirectory) => _player?.ExtractSingleTrackToWav(trackNumber, outputDirectory);
|
||||
|
||||
/// <summary>
|
||||
/// Extract all tracks from the image to WAV
|
||||
/// </summary>
|
||||
/// <param name="outputDirectory">Output path to write data to</param
|
||||
public void ExtractAllTracksToWav(string outputDirectory) => _player?.ExtractAllTracksToWav(outputDirectory);
|
||||
|
||||
/// <summary>
|
||||
/// Set data playback method [CompactDisc only]
|
||||
/// </summary>
|
||||
@@ -613,6 +649,18 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
/// <param name="load">True to enable loading hidden tracks, false otherwise</param>
|
||||
public void SetLoadHiddenTracks(bool load) => _player?.SetLoadHiddenTracks(load);
|
||||
|
||||
/// <summary>
|
||||
/// Set repeat mode
|
||||
/// </summary>
|
||||
/// <param name="repeatMode">New repeat mode value</param>
|
||||
public void SetRepeatMode(RepeatMode repeatMode) => _player?.SetRepeatMode(repeatMode);
|
||||
|
||||
/// <summary>
|
||||
/// Set session handling
|
||||
/// </summary>
|
||||
/// <param name="sessionHandling">New session handling value</param>
|
||||
public void SetSessionHandling(SessionHandling sessionHandling) => _player?.SetSessionHandling(sessionHandling);
|
||||
|
||||
/// <summary>
|
||||
/// Generate the digit string to be interpreted by the frontend
|
||||
/// </summary>
|
||||
@@ -754,6 +802,7 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
|
||||
CurrentTrackNumber = _player.CurrentTrackNumber;
|
||||
CurrentTrackIndex = _player.CurrentTrackIndex;
|
||||
CurrentTrackSession = _player.CurrentTrackSession;
|
||||
CurrentSector = _player.CurrentSector;
|
||||
SectionStartSector = _player.SectionStartSector;
|
||||
|
||||
@@ -766,6 +815,7 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
|
||||
PlayerState = _player.PlayerState;
|
||||
DataPlayback = _player.DataPlayback;
|
||||
RepeatMode = _player.RepeatMode;
|
||||
ApplyDeEmphasis = _player.ApplyDeEmphasis;
|
||||
Volume = _player.Volume;
|
||||
|
||||
|
||||
@@ -21,6 +21,18 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
[JsonIgnore]
|
||||
public List<DataPlayback> DataPlaybackValues => GenerateDataPlaybackList();
|
||||
|
||||
/// <summary>
|
||||
/// List of all repeat mode values
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<RepeatMode> RepeatModeValues => GenerateRepeatModeList();
|
||||
|
||||
/// <summary>
|
||||
/// List of all session handling values
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<SessionHandling> SessionHandlingValues => GenerateSessionHandlingList();
|
||||
|
||||
/// <summary>
|
||||
/// List of all themes
|
||||
/// </summary>
|
||||
@@ -57,6 +69,16 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
/// </summary>
|
||||
public DataPlayback DataPlayback { get; set; } = DataPlayback.Skip;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates how to repeat tracks
|
||||
/// </summary>
|
||||
public RepeatMode RepeatMode { get; set; } = RepeatMode.All;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates how to handle tracks on different sessions
|
||||
/// </summary>
|
||||
public SessionHandling SessionHandling { get; set; } = SessionHandling.FirstSessionOnly;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the default playback volume
|
||||
/// </summary>
|
||||
@@ -102,6 +124,11 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
/// </summary>
|
||||
public Key LoadImageKey { get; set; } = Key.F2;
|
||||
|
||||
/// <summary>
|
||||
/// Key assigned to save the current track or all tracks
|
||||
/// </summary>
|
||||
public Key SaveTrackKey { get; set; } = Key.S;
|
||||
|
||||
/// <summary>
|
||||
/// Key assigned to toggle play and pause
|
||||
/// </summary>
|
||||
@@ -253,6 +280,16 @@ namespace RedBookPlayer.GUI.ViewModels
|
||||
/// </summary>
|
||||
private List<Key> GenerateKeyList() => Enum.GetValues(typeof(Key)).Cast<Key>().ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Generate the list of RepeatMode values
|
||||
/// </summary>
|
||||
private List<RepeatMode> GenerateRepeatModeList() => Enum.GetValues(typeof(RepeatMode)).Cast<RepeatMode>().ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Generate the list of SessionHandling values
|
||||
/// </summary>
|
||||
private List<SessionHandling> GenerateSessionHandlingList() => Enum.GetValues(typeof(SessionHandling)).Cast<SessionHandling>().ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Generate the list of valid themes
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user