Looks like most of shuffle issues are resolved
This commit is contained in:
parent
06207d9791
commit
5a43a1284e
@ -67,7 +67,7 @@ namespace unison
|
||||
private MpcConnection _commandConnection;
|
||||
private IPEndPoint _mpdEndpoint;
|
||||
|
||||
private CancellationTokenSource _cancelCommand;
|
||||
public CancellationTokenSource _cancelCommand;
|
||||
private CancellationTokenSource _cancelConnect;
|
||||
|
||||
public MPDHandler()
|
||||
|
@ -75,7 +75,6 @@ namespace unison.Handlers
|
||||
|
||||
public async Task<List<StationInfo>> AdvancedSearch(AdvancedSearchOptions options)
|
||||
{
|
||||
|
||||
return await _radioBrowser.Search.AdvancedAsync(options);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
using MpcNET.Commands.Database;
|
||||
using MpcNET.Commands.Queue;
|
||||
using MpcNET.Tags;
|
||||
using MpcNET.Types;
|
||||
using MpcNET.Types.Filters;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using MpcNET.Commands.Database;
|
||||
using MpcNET.Commands.Queue;
|
||||
using MpcNET.Commands.Reflection;
|
||||
using MpcNET.Tags;
|
||||
using MpcNET.Types;
|
||||
using MpcNET.Types.Filters;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
@ -24,39 +26,50 @@ namespace unison
|
||||
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
}
|
||||
|
||||
private bool IsOnMainThread()
|
||||
/*private bool IsOnMainThread()
|
||||
{
|
||||
return Application.Current.Dispatcher.Thread == System.Threading.Thread.CurrentThread;
|
||||
}
|
||||
}*/
|
||||
|
||||
public async Task GetSongsFromFilter(List<IFilter> filter)
|
||||
public async Task GetSongsFromFilter(List<IFilter> filter, CancellationToken token)
|
||||
{
|
||||
Debug.WriteLine("[GetSongsFromFilterBefore] is on main thread => " + IsOnMainThread());
|
||||
await Task.Run(async() =>
|
||||
{
|
||||
Debug.WriteLine("[GetSongsFromFilterAfter] is on main thread => " + IsOnMainThread());
|
||||
//Debug.WriteLine("[GetSongsFromFilterBefore] is on main thread => " + IsOnMainThread());
|
||||
//await Task.Run(async() =>
|
||||
//{
|
||||
//Debug.WriteLine("[GetSongsFromFilterAfter] is on main thread => " + IsOnMainThread());
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
_songList.Clear();
|
||||
int song = _mpd.GetStats().Songs;
|
||||
|
||||
IEnumerable<IMpdFile> response = await _mpd.SafelySendCommandAsync(new SearchCommand(filter, 0, song + 1));
|
||||
Debug.WriteLine("before search command / song == " + song);
|
||||
|
||||
//var response = await Task.Run(async () =>
|
||||
//{
|
||||
/*return*/ IEnumerable<IMpdFile> response = await _mpd.SafelySendCommandAsync(new SearchCommand(filter, 0, song + 1));
|
||||
//});
|
||||
|
||||
Debug.WriteLine("got response => " + response.Count());
|
||||
|
||||
foreach (IMpdFile file in response)
|
||||
{
|
||||
_songList.Add(file.Path);
|
||||
Debug.WriteLine(file.Path);
|
||||
//Debug.WriteLine(file.Path);
|
||||
}
|
||||
});
|
||||
//});
|
||||
}
|
||||
|
||||
public async Task AddToQueueRandom(int SongNumber)
|
||||
public async Task AddToQueueRandom(int SongNumber, CancellationToken token)
|
||||
{
|
||||
Debug.WriteLine("Add To Queue Random");
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
if (token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
//await Task.Run(async () =>
|
||||
//{
|
||||
int AddedSongs = 0;
|
||||
|
||||
Debug.WriteLine("song to add => " + SongNumber);
|
||||
@ -85,30 +98,35 @@ namespace unison
|
||||
AddedSongs++;
|
||||
}
|
||||
}
|
||||
});
|
||||
//});
|
||||
|
||||
Debug.WriteLine("Add To Queue Random - finished");
|
||||
}
|
||||
|
||||
public async Task AddToQueueFilter(int SongNumber)
|
||||
public async Task AddToQueueFilter(int SongNumber, CancellationToken token)
|
||||
{
|
||||
Debug.WriteLine("Add To Queue Filter");
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
if (token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
//await Task.Run(async () =>
|
||||
//{
|
||||
int AddedSongs = 0;
|
||||
|
||||
Debug.WriteLine("song to add => " + SongNumber);
|
||||
// more requested songs than available => add everything
|
||||
if (SongNumber > _songList.Count)
|
||||
{
|
||||
var commandList = new CommandList();
|
||||
|
||||
foreach (string path in _songList)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
_mpd.AddSong(path);
|
||||
Debug.WriteLine("song path => " + path);
|
||||
commandList.Add(new AddCommand(path));
|
||||
AddedSongs++;
|
||||
}
|
||||
Trace.WriteLine("Added " + AddedSongs + " songs");
|
||||
await _mpd.SafelySendCommandAsync(commandList);
|
||||
}
|
||||
// more available songs than requested =>
|
||||
// we add unique indexes until we reach the requested amount
|
||||
@ -116,17 +134,21 @@ namespace unison
|
||||
{
|
||||
HashSet<int> SongIndex = new();
|
||||
Debug.WriteLine("while - before");
|
||||
while (SongIndex.Count < SongNumber)
|
||||
while (SongIndex.Count < SongNumber)//_songList.Count - 1)//SongNumber)
|
||||
{
|
||||
int MaxIndex = new Random().Next(0, _songList.Count - 1);
|
||||
SongIndex.Add(MaxIndex);
|
||||
}
|
||||
Debug.WriteLine("while - middle");
|
||||
var commandList = new CommandList();
|
||||
|
||||
foreach (int index in SongIndex)
|
||||
_mpd.AddSong(_songList[index]);
|
||||
commandList.Add(new AddCommand(_songList[index]));
|
||||
await _mpd.SafelySendCommandAsync(commandList);
|
||||
//_mpd.AddSong(_songList[index]);
|
||||
Debug.WriteLine("while - after");
|
||||
}
|
||||
});
|
||||
//});
|
||||
|
||||
Debug.WriteLine("Add To Queue Filter - finished");
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ using System.Windows.Media;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
@ -40,15 +41,18 @@ namespace unison
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
ListGenre();
|
||||
ListFolder();
|
||||
ListGenre(_mpd._cancelCommand.Token);
|
||||
ListFolder(_mpd._cancelCommand.Token);
|
||||
}
|
||||
|
||||
public async void ListGenre()
|
||||
public async void ListGenre(CancellationToken token)
|
||||
{
|
||||
if (_genreList.Count != 0)
|
||||
return;
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
List<string> Response = await _mpd.SafelySendCommandAsync(new ListCommand(MpdTags.Genre, null, null));
|
||||
|
||||
if (Response == null)
|
||||
@ -58,11 +62,14 @@ namespace unison
|
||||
_genreList.Add(genre);
|
||||
}
|
||||
|
||||
public async void ListFolder()
|
||||
public async void ListFolder(CancellationToken token)
|
||||
{
|
||||
if (_folderList.Count != 0)
|
||||
return;
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
IEnumerable<IMpdFilePath> Response = await _mpd.SafelySendCommandAsync(new LsInfoCommand(""));
|
||||
|
||||
if (Response == null)
|
||||
@ -92,10 +99,10 @@ namespace unison
|
||||
helper.EnsureHandle();
|
||||
}
|
||||
|
||||
private bool IsOnMainThread()
|
||||
/*private bool IsOnMainThread()
|
||||
{
|
||||
return App.Current.Dispatcher.Thread == System.Threading.Thread.CurrentThread;
|
||||
}
|
||||
}*/
|
||||
|
||||
private T FindParent<T>(DependencyObject child) where T : DependencyObject
|
||||
{
|
||||
@ -170,7 +177,7 @@ namespace unison
|
||||
|
||||
_filters.Clear();
|
||||
|
||||
Debug.WriteLine("is on main thread => " + IsOnMainThread());
|
||||
//Debug.WriteLine("is on main thread => " + IsOnMainThread());
|
||||
|
||||
foreach (ContentPresenter superChild in FilterPanel.Children)
|
||||
{
|
||||
@ -179,12 +186,17 @@ namespace unison
|
||||
string value = "";
|
||||
bool isDir = false;
|
||||
|
||||
Debug.WriteLine("update filter => part 1");
|
||||
|
||||
StackPanel stackPanel = VisualTreeHelper.GetChild(superChild, 0) as StackPanel;
|
||||
foreach (TextBox child in stackPanel.Children.OfType<TextBox>())
|
||||
{
|
||||
if (child.Name == "FilterValue")
|
||||
value = child.Text;
|
||||
}
|
||||
|
||||
Debug.WriteLine("update filter => part 2");
|
||||
|
||||
foreach (ComboBox child in stackPanel.Children.OfType<ComboBox>())
|
||||
{
|
||||
if (child.Name == "FilterType")
|
||||
@ -202,6 +214,8 @@ namespace unison
|
||||
value = child.SelectedItem.ToString();
|
||||
}
|
||||
|
||||
Debug.WriteLine("update filter => part 3");
|
||||
|
||||
if (value != "")
|
||||
{
|
||||
if (!isDir)
|
||||
@ -209,10 +223,15 @@ namespace unison
|
||||
else
|
||||
_filters.Add(new FilterBase(value, FilterOperator.None));
|
||||
|
||||
await _shuffle.GetSongsFromFilter(_filters);
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await _shuffle.GetSongsFromFilter(_filters, _mpd._cancelCommand.Token);
|
||||
});
|
||||
SongFilterPanel.Visibility = Visibility.Visible;
|
||||
SongFilterNumber.Text = _shuffle._songList.Count.ToString();
|
||||
}
|
||||
|
||||
Debug.WriteLine("update filter => part 4");
|
||||
}
|
||||
|
||||
Debug.WriteLine("update filter => stop");
|
||||
@ -309,6 +328,8 @@ namespace unison
|
||||
// start dispatcher
|
||||
// write _shuffle.AddedSongs in dispatcher
|
||||
|
||||
|
||||
await UpdateFilter();
|
||||
await AddToQueue(int.Parse(SongNumber.Text));
|
||||
|
||||
Debug.WriteLine("add to queue finished");
|
||||
@ -318,16 +339,24 @@ namespace unison
|
||||
|
||||
private async Task AddToQueue(int NumberToAdd)
|
||||
{
|
||||
await UpdateFilter();
|
||||
//await UpdateFilter();
|
||||
|
||||
Debug.WriteLine("check filters");
|
||||
|
||||
if (IsFilterEmpty())
|
||||
await _shuffle.AddToQueueRandom(NumberToAdd);
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await _shuffle.AddToQueueRandom(NumberToAdd, _mpd._cancelCommand.Token);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("add to queue filter - before");
|
||||
await _shuffle.AddToQueueFilter(NumberToAdd);
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await _shuffle.AddToQueueFilter(NumberToAdd, _mpd._cancelCommand.Token);
|
||||
});
|
||||
Debug.WriteLine("add to queue filter - after");
|
||||
}
|
||||
|
||||
@ -348,7 +377,11 @@ namespace unison
|
||||
}
|
||||
|
||||
Debug.WriteLine("continuous __before__ add to queue");
|
||||
await UpdateFilter();
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await AddToQueue(5);
|
||||
});
|
||||
Debug.WriteLine("continuous __after__ add to queue");
|
||||
}
|
||||
|
||||
@ -359,7 +392,10 @@ namespace unison
|
||||
else
|
||||
_continuous = false;
|
||||
|
||||
if (_mpd.GetStatus().PlaylistLength < 5)
|
||||
int Length = _mpd.GetStatus().PlaylistLength;
|
||||
Trace.WriteLine("Length is " + Length);
|
||||
|
||||
if (/*_mpd.GetStatus().PlaylistLength*/Length < 5)
|
||||
await HandleContinuous();
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<ApplicationIcon>Resources\icon-full.ico</ApplicationIcon>
|
||||
<Win32Resource></Win32Resource>
|
||||
<StartupObject>unison.App</StartupObject>
|
||||
<Version>1.3.1</Version>
|
||||
<Version>1.4</Version>
|
||||
<Company />
|
||||
<Authors>Théo Marchal</Authors>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
|
Loading…
Reference in New Issue
Block a user