From 5bfa7d3b5b3fbe3f847cdc49434d71fd3d2211ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Sun, 17 Apr 2022 16:02:09 +0200 Subject: [PATCH] Basic shuffle features, must fix deadlocks --- Handlers/MPDHandler.cs | 4 + Views/MainWindow.xaml.cs | 54 ++--- Views/Settings.xaml | 13 +- Views/Shuffle.xaml | 140 ++++++----- Views/Shuffle.xaml.cs | 496 +++++++++++++++++++++++++++------------ 5 files changed, 451 insertions(+), 256 deletions(-) diff --git a/Handlers/MPDHandler.cs b/Handlers/MPDHandler.cs index e233ec0..6f39980 100644 --- a/Handlers/MPDHandler.cs +++ b/Handlers/MPDHandler.cs @@ -155,7 +155,9 @@ namespace unison try { + Debug.WriteLine("SafelySendCommandAsync => before command"); IMpdMessage response = await _commandConnection.SendAsync(command); + Debug.WriteLine("SafelySendCommandAsync => after command"); if (!response.IsResponseValid) { string mpdError = response.Response?.Result?.MpdError; @@ -498,6 +500,8 @@ namespace unison public void Next() => SendCommand(new NextCommand()); public void PlayPause() => SendCommand(new PauseResumeCommand()); + public void Play(int pos) => SendCommand(new PlayCommand(pos)); + public void Random() => SendCommand(new RandomCommand(!_currentRandom)); public void Repeat() => SendCommand(new RepeatCommand(!_currentRepeat)); public void Single() => SendCommand(new SingleCommand(!_currentSingle)); diff --git a/Views/MainWindow.xaml.cs b/Views/MainWindow.xaml.cs index 0bd2541..0faecd4 100644 --- a/Views/MainWindow.xaml.cs +++ b/Views/MainWindow.xaml.cs @@ -50,12 +50,13 @@ namespace unison { if (_mpd.IsConnected()) { + _mpd.QueryStats(); + _settingsWin.UpdateStats(); + Snapcast.IsEnabled = true; ConnectionOkIcon.Visibility = Visibility.Visible; ConnectionFailIcon.Visibility = Visibility.Collapsed; - - _shuffleWin.ListGenre(); - _shuffleWin.ListFolder(); + _shuffleWin.Initialize(); } else { @@ -117,29 +118,15 @@ namespace unison Debug.WriteLine("Song changed called!"); - // handle continuous shuffle - if (_shuffleWin.GetContinuous()) - { - System.Collections.Generic.IEnumerable a = await _mpd.SafelySendCommandAsync(new PlaylistCommand()); - int queueSize = 0; - foreach (var i in a) - { - Debug.WriteLine(i.Path); - queueSize++; - } - Debug.WriteLine("queue size is: " + queueSize); + if (!_shuffleWin.GetContinuous()) + return; - if (queueSize < 5) - { - _shuffleWin.AddContinuousSongs(); - } - - // query queue - // if (queue.SongRemaining < 5) - //{ - // // query shuffle songs - //} - } + NextTrack.IsEnabled = false; + PreviousTrack.IsEnabled = false; + await _shuffleWin.HandleContinuous(); + NextTrack.IsEnabled = true; + PreviousTrack.IsEnabled = true; + Debug.WriteLine("finished continuous"); } public void OnStatusChanged(object sender, EventArgs e) @@ -168,9 +155,6 @@ namespace unison DefaultState(); } } - - _mpd.QueryStats(); - _settingsWin.UpdateStats(); } private void DefaultState(bool LostConnection = false) @@ -243,8 +227,18 @@ namespace unison } public void Pause_Clicked(object sender, RoutedEventArgs e) => _mpd.PlayPause(); - public void Previous_Clicked(object sender, RoutedEventArgs e) => _mpd.Prev(); - public void Next_Clicked(object sender, RoutedEventArgs e) => _mpd.Next(); + + public void Previous_Clicked(object sender, RoutedEventArgs e) + { + if (PreviousTrack.IsEnabled) + _mpd.Prev(); + } + + public void Next_Clicked(object sender, RoutedEventArgs e) + { + if (NextTrack.IsEnabled) + _mpd.Next(); + } public void Random_Clicked(object sender, RoutedEventArgs e) => _mpd.Random(); public void Repeat_Clicked(object sender, RoutedEventArgs e) => _mpd.Repeat(); diff --git a/Views/Settings.xaml b/Views/Settings.xaml index 89090c6..f73af9c 100644 --- a/Views/Settings.xaml +++ b/Views/Settings.xaml @@ -208,19 +208,16 @@ - - - - - + The shuffle window allows to add random songs to your queue. Both options take into account the filter. If the filter is empty, the entire music library is taken into account. - Continuous shuffle - By enabling this option, unison will automatically add songs to the queue so you never run out of songs to listen to. - Add to queue Add a fixed number of songs to the queue. It can take a long time to add more than 100 songs, so the option is limited to 1000 songs. + + + Continuous shuffle + By enabling this option, unison will automatically add songs to the queue so you never run out of songs to listen to. diff --git a/Views/Shuffle.xaml b/Views/Shuffle.xaml index 307806c..0c99c00 100644 --- a/Views/Shuffle.xaml +++ b/Views/Shuffle.xaml @@ -4,10 +4,44 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf" - xmlns:local="clr-namespace:unison" + xmlns:local="clr-namespace:unison" xmlns:sys="clr-namespace:System;assembly=System.Runtime" mc:Ignorable="d" Title="Shuffle" Closing="Window_Closing" SizeToContent="WidthAndHeight" ResizeMode="NoResize"> + + + Song + Artist + Album + Year + Genre + Directory + + + contains + is + is not + + + is + is not + + + is + + + + + + + + +