From dd8e6339bf0ba94f583227f583919ce95b69eb3d Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Sun, 31 Dec 2023 02:06:05 -0500 Subject: [PATCH 1/3] Add 'X' hotkey for removing selected audio from the playlist --- FModel/Settings/UserSettings.cs | 7 +++++++ FModel/Views/AudioPlayer.xaml.cs | 2 ++ FModel/Views/SettingsView.xaml | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/FModel/Settings/UserSettings.cs b/FModel/Settings/UserSettings.cs index cdbbaae4..bf82a53a 100644 --- a/FModel/Settings/UserSettings.cs +++ b/FModel/Settings/UserSettings.cs @@ -307,6 +307,13 @@ public Hotkey AddAudio set => SetProperty(ref _addAudio, value); } + private Hotkey _removeAudio = new(Key.X); + public Hotkey RemoveAudio + { + get => _removeAudio; + set => SetProperty(ref _removeAudio, value); + } + private Hotkey _playPauseAudio = new(Key.K); public Hotkey PlayPauseAudio { diff --git a/FModel/Views/AudioPlayer.xaml.cs b/FModel/Views/AudioPlayer.xaml.cs index 6367e35c..e0191c9e 100644 --- a/FModel/Views/AudioPlayer.xaml.cs +++ b/FModel/Views/AudioPlayer.xaml.cs @@ -75,6 +75,8 @@ private void OnPreviewKeyDown(object sender, KeyEventArgs e) _applicationView.AudioPlayer.Previous(); else if (UserSettings.Default.NextAudio.IsTriggered(e.Key)) _applicationView.AudioPlayer.Next(); + else if (UserSettings.Default.RemoveAudio.IsTriggered(e.Key)) + _applicationView.AudioPlayer.Remove(); } private void OnAudioFileMouseDoubleClick(object sender, MouseButtonEventArgs e) diff --git a/FModel/Views/SettingsView.xaml b/FModel/Views/SettingsView.xaml index f5373a08..2b0fc8a3 100644 --- a/FModel/Views/SettingsView.xaml +++ b/FModel/Views/SettingsView.xaml @@ -440,6 +440,7 @@ + @@ -483,6 +484,9 @@ + + From ae4015f33dd2301095768fa312f37292aacc9ac0 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Sun, 31 Dec 2023 02:13:16 -0500 Subject: [PATCH 2/3] Stop playback if removed file was currently playing file --- FModel/ViewModels/AudioPlayerViewModel.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/FModel/ViewModels/AudioPlayerViewModel.cs b/FModel/ViewModels/AudioPlayerViewModel.cs index e6c099db..96fb1f0b 100644 --- a/FModel/ViewModels/AudioPlayerViewModel.cs +++ b/FModel/ViewModels/AudioPlayerViewModel.cs @@ -265,6 +265,13 @@ public void Remove() if (_audioFiles.Count < 1) return; Application.Current.Dispatcher.Invoke(() => { + var removedPlaying = false; + if (PlayedFile.Id == SelectedAudioFile.Id) + { + removedPlaying = true; + Stop(); + } + _audioFiles.RemoveAt(SelectedAudioFile.Id); for (var i = 0; i < _audioFiles.Count; i++) { From 587a2bb4c86fcbac5f51365facc5987f4b3148c9 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Sun, 31 Dec 2023 02:17:47 -0500 Subject: [PATCH 3/3] Clear _waveSource and PlayedFile if last file was removed --- FModel/ViewModels/AudioPlayerViewModel.cs | 31 +++++++++++++++++++ .../Resources/Controls/Aup/SourceEventArgs.cs | 5 +-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/FModel/ViewModels/AudioPlayerViewModel.cs b/FModel/ViewModels/AudioPlayerViewModel.cs index 96fb1f0b..53c4096d 100644 --- a/FModel/ViewModels/AudioPlayerViewModel.cs +++ b/FModel/ViewModels/AudioPlayerViewModel.cs @@ -234,6 +234,20 @@ public void Load() }); } + public void Unload() + { + Application.Current.Dispatcher.Invoke(() => + { + _waveSource = null; + + PlayedFile = new AudioFile(-1, "No audio file"); + Spectrum = null; + + RaiseSourceEvent(ESourceEventType.Clearing); + ClearSoundOut(); + }); + } + public void AddToPlaylist(byte[] data, string filePath) { Application.Current.Dispatcher.Invoke(() => @@ -277,6 +291,18 @@ public void Remove() { _audioFiles[i].Id = i; } + + if (_audioFiles.Count < 1) + { + Unload(); + return; + } + + SelectedAudioFile = _audioFiles[SelectedAudioFile.Id]; + + if (!removedPlaying) return; + Load(); + Play(); }); } @@ -508,6 +534,11 @@ private void LoadSoundOut() _soundOut.Volume = UserSettings.Default.AudioPlayerVolume / 100; } + private void ClearSoundOut() + { + _soundOut = null; + } + private IEnumerable EnumerateDevices() { using var deviceEnumerator = new MMDeviceEnumerator(); diff --git a/FModel/Views/Resources/Controls/Aup/SourceEventArgs.cs b/FModel/Views/Resources/Controls/Aup/SourceEventArgs.cs index aeca57f0..5507d4c7 100644 --- a/FModel/Views/Resources/Controls/Aup/SourceEventArgs.cs +++ b/FModel/Views/Resources/Controls/Aup/SourceEventArgs.cs @@ -4,7 +4,8 @@ namespace FModel.Views.Resources.Controls.Aup; public enum ESourceEventType { - Loading + Loading, + Clearing } public class SourceEventArgs : EventArgs @@ -15,4 +16,4 @@ public SourceEventArgs(ESourceEventType e) { Event = e; } -} \ No newline at end of file +}