Bugfix
This commit is contained in:
parent
5a43a1284e
commit
52b0a6fc85
@ -5,7 +5,9 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using MpcNET;
|
||||||
using MpcNET.Commands.Database;
|
using MpcNET.Commands.Database;
|
||||||
|
using MpcNET.Commands.Playback;
|
||||||
using MpcNET.Commands.Queue;
|
using MpcNET.Commands.Queue;
|
||||||
using MpcNET.Commands.Reflection;
|
using MpcNET.Commands.Reflection;
|
||||||
using MpcNET.Tags;
|
using MpcNET.Tags;
|
||||||
@ -16,49 +18,35 @@ namespace unison
|
|||||||
{
|
{
|
||||||
class ShuffleHandler
|
class ShuffleHandler
|
||||||
{
|
{
|
||||||
private MPDHandler _mpd;
|
private readonly MPDHandler _mpd;
|
||||||
public List<string> _songList { get; }
|
|
||||||
public int AddedSongs = 0;
|
public int AddedSongs = 0;
|
||||||
|
|
||||||
|
public List<string> SongList { get; }
|
||||||
|
|
||||||
public ShuffleHandler()
|
public ShuffleHandler()
|
||||||
{
|
{
|
||||||
_songList = new();
|
SongList = new();
|
||||||
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private bool IsOnMainThread()
|
|
||||||
{
|
|
||||||
return Application.Current.Dispatcher.Thread == System.Threading.Thread.CurrentThread;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public async Task GetSongsFromFilter(List<IFilter> filter, CancellationToken token)
|
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());
|
|
||||||
|
|
||||||
if (token.IsCancellationRequested)
|
if (token.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_songList.Clear();
|
SongList.Clear();
|
||||||
int song = _mpd.GetStats().Songs;
|
int song = _mpd.GetStats().Songs;
|
||||||
|
|
||||||
Debug.WriteLine("before search command / song == " + song);
|
Debug.WriteLine("before search command / song == " + song);
|
||||||
|
|
||||||
//var response = await Task.Run(async () =>
|
IEnumerable<IMpdFile> response = await _mpd.SafelySendCommandAsync(new SearchCommand(filter, 0, song + 1));
|
||||||
//{
|
|
||||||
/*return*/ IEnumerable<IMpdFile> response = await _mpd.SafelySendCommandAsync(new SearchCommand(filter, 0, song + 1));
|
|
||||||
//});
|
|
||||||
|
|
||||||
Debug.WriteLine("got response => " + response.Count());
|
Debug.WriteLine("got response => " + response.Count());
|
||||||
|
|
||||||
foreach (IMpdFile file in response)
|
foreach (IMpdFile file in response)
|
||||||
{
|
{
|
||||||
_songList.Add(file.Path);
|
SongList.Add(file.Path);
|
||||||
//Debug.WriteLine(file.Path);
|
|
||||||
}
|
}
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddToQueueRandom(int SongNumber, CancellationToken token)
|
public async Task AddToQueueRandom(int SongNumber, CancellationToken token)
|
||||||
@ -68,87 +56,75 @@ namespace unison
|
|||||||
if (token.IsCancellationRequested)
|
if (token.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//await Task.Run(async () =>
|
|
||||||
//{
|
|
||||||
int AddedSongs = 0;
|
int AddedSongs = 0;
|
||||||
|
|
||||||
Debug.WriteLine("song to add => " + SongNumber);
|
Debug.WriteLine("song to add => " + SongNumber);
|
||||||
|
|
||||||
|
var commandList = new CommandList();
|
||||||
|
int songTotal = _mpd.GetStats().Songs;
|
||||||
|
|
||||||
for (int i = 0; i < SongNumber; i++)
|
for (int i = 0; i < SongNumber; i++)
|
||||||
{
|
{
|
||||||
// generate random number
|
int song = new Random().Next(0, songTotal - 1);
|
||||||
int song = new Random().Next(0, _mpd.GetStats().Songs - 1);
|
commandList.Add(new SearchAddCommand(new FilterTag(MpdTags.Title, "", FilterOperator.Contains), song, song + 1));
|
||||||
Debug.WriteLine("song " + song + " - song total " + _mpd.GetStats().Songs);
|
|
||||||
IEnumerable<IMpdFile> Response = await _mpd.SafelySendCommandAsync(new SearchCommand(new FilterTag(MpdTags.Title, "", FilterOperator.Contains), song, song + 1));
|
|
||||||
|
|
||||||
Debug.WriteLine("got response");
|
|
||||||
|
|
||||||
await Task.Delay(1);
|
|
||||||
if (Response.Count() > 0)
|
|
||||||
{
|
|
||||||
string filePath = Response.First().Path;
|
|
||||||
_mpd.AddSong(filePath);
|
|
||||||
Debug.WriteLine("song path => " + filePath);
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
if (!_mpd.IsPlaying())
|
|
||||||
_mpd.Play(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
AddedSongs++;
|
AddedSongs++;
|
||||||
}
|
|
||||||
}
|
|
||||||
//});
|
|
||||||
|
|
||||||
Debug.WriteLine("Add To Queue Random - finished");
|
// play if stopped or unknown state (no queue managing at the moment, so mandatory)
|
||||||
|
if (i == 0 && (_mpd.GetStatus().State != MpdState.Play && _mpd.GetStatus().State != MpdState.Pause))
|
||||||
|
commandList.Add(new PlayCommand(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
await _mpd.SafelySendCommandAsync(commandList);
|
||||||
|
|
||||||
|
Debug.WriteLine("Add To Queue Random - finished with " + AddedSongs + " songs");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddToQueueFilter(int SongNumber, CancellationToken token)
|
public async Task AddToQueueFilter(int SongNumber, CancellationToken token)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Add To Queue Filter");
|
Debug.WriteLine("Add To Queue Filter - start");
|
||||||
|
|
||||||
if (token.IsCancellationRequested)
|
if (token.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//await Task.Run(async () =>
|
|
||||||
//{
|
|
||||||
int AddedSongs = 0;
|
int AddedSongs = 0;
|
||||||
|
|
||||||
Debug.WriteLine("song to add => " + SongNumber);
|
Debug.WriteLine("song to add => " + SongNumber);
|
||||||
// more requested songs than available => add everything
|
// more (or equal) requested songs than available => add everything
|
||||||
if (SongNumber > _songList.Count)
|
if (SongNumber >= SongList.Count)
|
||||||
{
|
{
|
||||||
var commandList = new CommandList();
|
Trace.WriteLine("more requested songs than available => add everything");
|
||||||
|
|
||||||
foreach (string path in _songList)
|
var commandList = new CommandList();
|
||||||
|
foreach (string path in SongList)
|
||||||
{
|
{
|
||||||
commandList.Add(new AddCommand(path));
|
commandList.Add(new AddCommand(path));
|
||||||
AddedSongs++;
|
AddedSongs++;
|
||||||
}
|
}
|
||||||
Trace.WriteLine("Added " + AddedSongs + " songs");
|
|
||||||
await _mpd.SafelySendCommandAsync(commandList);
|
await _mpd.SafelySendCommandAsync(commandList);
|
||||||
}
|
}
|
||||||
// more available songs than requested =>
|
// more available songs than requested =>
|
||||||
// we add unique indexes until we reach the requested amount
|
// we add unique indexes until we reach the requested amount
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Trace.WriteLine("more available songs than requested");
|
||||||
|
|
||||||
HashSet<int> SongIndex = new();
|
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);
|
int MaxIndex = new Random().Next(0, SongList.Count - 1);
|
||||||
SongIndex.Add(MaxIndex);
|
SongIndex.Add(MaxIndex);
|
||||||
}
|
}
|
||||||
Debug.WriteLine("while - middle");
|
|
||||||
var commandList = new CommandList();
|
|
||||||
|
|
||||||
|
var commandList = new CommandList();
|
||||||
foreach (int index in SongIndex)
|
foreach (int index in SongIndex)
|
||||||
commandList.Add(new AddCommand(_songList[index]));
|
{
|
||||||
await _mpd.SafelySendCommandAsync(commandList);
|
commandList.Add(new AddCommand(SongList[index]));
|
||||||
//_mpd.AddSong(_songList[index]);
|
AddedSongs++;
|
||||||
Debug.WriteLine("while - after");
|
}
|
||||||
|
|
||||||
|
await _mpd.SafelySendCommandAsync(commandList);
|
||||||
}
|
}
|
||||||
//});
|
|
||||||
|
|
||||||
Debug.WriteLine("Add To Queue Filter - finished");
|
Debug.WriteLine("Add To Queue Filter - finished");
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using unison.Handlers;
|
using unison.Handlers;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
|
||||||
namespace unison
|
namespace unison
|
||||||
{
|
{
|
||||||
@ -133,7 +134,10 @@ namespace unison
|
|||||||
Debug.WriteLine("playlist length => " + _mpd.GetStatus().PlaylistLength);
|
Debug.WriteLine("playlist length => " + _mpd.GetStatus().PlaylistLength);
|
||||||
|
|
||||||
if (_mpd.GetStatus().PlaylistLength > 4)
|
if (_mpd.GetStatus().PlaylistLength > 4)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("return :)");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Debug.WriteLine("start continuous handling");
|
Debug.WriteLine("start continuous handling");
|
||||||
_mpd.CanPrevNext = false;
|
_mpd.CanPrevNext = false;
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<ComboBox x:Name="FilterType" SelectionChanged="FilterType_SelectionChanged" ItemsSource="{StaticResource FilterType}" SelectedIndex="0" Width="100" ScrollViewer.CanContentScroll="False" FocusVisualStyle="{x:Null}"/>
|
<ComboBox x:Name="FilterType" SelectionChanged="FilterType_SelectionChanged" ItemsSource="{StaticResource FilterType}" SelectedIndex="0" Width="100" ScrollViewer.CanContentScroll="False" FocusVisualStyle="{x:Null}"/>
|
||||||
<ComboBox x:Name="FilterOperator" SelectionChanged="OperatorType_SelectionChanged" ItemsSource="{StaticResource OperatorTypeA}" SelectedIndex="0" Width="80" ScrollViewer.CanContentScroll="False" Margin="5,0,0,0" FocusVisualStyle="{x:Null}"/>
|
<ComboBox x:Name="FilterOperator" SelectionChanged="OperatorType_SelectionChanged" ItemsSource="{StaticResource OperatorTypeA}" SelectedIndex="0" Width="80" ScrollViewer.CanContentScroll="False" Margin="5,0,0,0" FocusVisualStyle="{x:Null}"/>
|
||||||
<ComboBox x:Name="FilterList" SelectedIndex="0" Width="240" Visibility="Collapsed" ScrollViewer.CanContentScroll="False" Margin="5,0,0,0" FocusVisualStyle="{x:Null}"/>
|
<ComboBox x:Name="FilterList" SelectedIndex="0" Width="240" Visibility="Collapsed" ScrollViewer.CanContentScroll="False" Margin="5,0,0,0" FocusVisualStyle="{x:Null}"/>
|
||||||
<TextBox x:Name="FilterValue" Width="240" Margin="5,0,0,0"/>
|
<TextBox x:Name="FilterValue" KeyUp="QueryFilterHandler" Width="240" Margin="5,0,0,0"/>
|
||||||
<Button Content="-" Padding="5, 2" Click="RemoveFilter_Clicked" Width="20" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}" Margin="5,0,0,0"/>
|
<Button Content="-" Padding="5, 2" Click="RemoveFilter_Clicked" Width="20" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}" Margin="5,0,0,0"/>
|
||||||
<Button Content="+" Padding="5, 2" Click="AddFilter_Clicked" Width="20" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}" Margin="5,0,0,0"/>
|
<Button Content="+" Padding="5, 2" Click="AddFilter_Clicked" Width="20" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}" Margin="5,0,0,0"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
@ -68,7 +68,7 @@
|
|||||||
<StackPanel Orientation="Horizontal" Margin="0,5,0,5">
|
<StackPanel Orientation="Horizontal" Margin="0,5,0,5">
|
||||||
<Button Content="Query filter" Click="UpdateFilter_Clicked" Padding="5, 2" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}" Margin="0,0,10,0"/>
|
<Button Content="Query filter" Click="UpdateFilter_Clicked" Padding="5, 2" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}" Margin="0,0,10,0"/>
|
||||||
<Button Content="Reset" Click="Reset_Clicked" Padding="5, 2" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}"/>
|
<Button Content="Reset" Click="Reset_Clicked" Padding="5, 2" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}"/>
|
||||||
<TextBlock Text="Querying filter..." Margin="15,3,0,0" FontStyle="Italic" Visibility="Visible" />
|
<TextBlock x:Name="QueryFilterText" Text="Querying filter..." Margin="15,3,0,0" FontStyle="Italic" Visibility="Collapsed" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
@ -86,12 +86,12 @@
|
|||||||
<StackPanel Orientation="Vertical" Margin="5,5,5,0">
|
<StackPanel Orientation="Vertical" Margin="5,5,5,0">
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||||
<TextBlock Text="Songs to add" Margin="0,0,5,5"/>
|
<TextBlock Text="Songs to add" Margin="0,0,5,5"/>
|
||||||
<TextBox x:Name="SongNumber" PreviewTextInput="QueueValidationTextBox" MaxLength="4" Text="15" Width="35" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
<TextBox x:Name="SongNumber" KeyUp="AddToQueueHandler" PreviewTextInput="QueueValidationTextBox" MaxLength="4" Text="15" Width="35" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
|
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
|
||||||
<Button Content="Add to queue" Click="AddToQueue_Clicked" Padding="5, 2" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}"/>
|
<Button Content="Add to queue" Click="AddToQueue_Clicked" Padding="5, 2" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}"/>
|
||||||
<TextBlock x:Name="SearchStatus" Margin="15,3,0,0" FontStyle="Italic" Visibility="Collapsed">
|
<TextBlock x:Name="SearchStatus" Margin="15,3,0,0" FontStyle="Italic" Visibility="Collapsed">
|
||||||
<Run Text="Added "/><Run x:Name="NumberAddedSongs"/><Run Text=" songs"/>
|
<Run Text="Adding "/><Run x:Name="NumberAddedSongs"/><Run Text=" songs..."/>
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
using MpcNET.Commands.Database;
|
using System;
|
||||||
using MpcNET.Tags;
|
|
||||||
using MpcNET.Types;
|
|
||||||
using MpcNET.Types.Filters;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -15,24 +11,30 @@ using System.Linq;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using MpcNET.Commands.Database;
|
||||||
|
using MpcNET.Tags;
|
||||||
|
using MpcNET.Types;
|
||||||
|
using MpcNET.Types.Filters;
|
||||||
|
|
||||||
namespace unison
|
namespace unison
|
||||||
{
|
{
|
||||||
public partial class Shuffle : Window
|
public partial class Shuffle : Window
|
||||||
{
|
{
|
||||||
private MPDHandler _mpd;
|
private readonly MPDHandler _mpd;
|
||||||
private ShuffleHandler _shuffle;
|
private readonly ShuffleHandler _shuffle;
|
||||||
|
|
||||||
|
List<string> GenreList { get; }
|
||||||
|
List<string> FolderList { get; }
|
||||||
|
List<IFilter> Filters { get; }
|
||||||
|
|
||||||
bool _continuous = false;
|
bool _continuous = false;
|
||||||
List<string> _genreList { get; }
|
|
||||||
List<string> _folderList { get; }
|
|
||||||
List<IFilter> _filters { get; }
|
|
||||||
|
|
||||||
public Shuffle()
|
public Shuffle()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_genreList = new();
|
GenreList = new();
|
||||||
_folderList = new();
|
FolderList = new();
|
||||||
_filters = new();
|
Filters = new();
|
||||||
SongFilterNumber.Text = "0";
|
SongFilterNumber.Text = "0";
|
||||||
|
|
||||||
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||||
@ -47,7 +49,7 @@ namespace unison
|
|||||||
|
|
||||||
public async void ListGenre(CancellationToken token)
|
public async void ListGenre(CancellationToken token)
|
||||||
{
|
{
|
||||||
if (_genreList.Count != 0)
|
if (GenreList.Count != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (token.IsCancellationRequested)
|
if (token.IsCancellationRequested)
|
||||||
@ -59,12 +61,12 @@ namespace unison
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (string genre in Response)
|
foreach (string genre in Response)
|
||||||
_genreList.Add(genre);
|
GenreList.Add(genre);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void ListFolder(CancellationToken token)
|
public async void ListFolder(CancellationToken token)
|
||||||
{
|
{
|
||||||
if (_folderList.Count != 0)
|
if (FolderList.Count != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (token.IsCancellationRequested)
|
if (token.IsCancellationRequested)
|
||||||
@ -76,34 +78,16 @@ namespace unison
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (IMpdFilePath folder in Response)
|
foreach (IMpdFilePath folder in Response)
|
||||||
_folderList.Add(folder.Name);
|
FolderList.Add(folder.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsFilterEmpty()
|
private bool IsFilterEmpty()
|
||||||
{
|
{
|
||||||
if (_filters.Count() == 0)
|
if (Filters.Count() == 0)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_Closing(object sender, CancelEventArgs e)
|
|
||||||
{
|
|
||||||
e.Cancel = true;
|
|
||||||
WindowState = WindowState.Minimized;
|
|
||||||
Hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InitHwnd()
|
|
||||||
{
|
|
||||||
WindowInteropHelper helper = new(this);
|
|
||||||
helper.EnsureHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*private bool IsOnMainThread()
|
|
||||||
{
|
|
||||||
return App.Current.Dispatcher.Thread == System.Threading.Thread.CurrentThread;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private T FindParent<T>(DependencyObject child) where T : DependencyObject
|
private T FindParent<T>(DependencyObject child) where T : DependencyObject
|
||||||
{
|
{
|
||||||
var parent = VisualTreeHelper.GetParent(child);
|
var parent = VisualTreeHelper.GetParent(child);
|
||||||
@ -137,7 +121,7 @@ namespace unison
|
|||||||
FilterPanel.Children.RemoveRange(0, FilterPanel.Children.Count);
|
FilterPanel.Children.RemoveRange(0, FilterPanel.Children.Count);
|
||||||
FilterPanel.Children.Add(new ContentPresenter { ContentTemplate = (DataTemplate)FindResource("FilterPanel") });
|
FilterPanel.Children.Add(new ContentPresenter { ContentTemplate = (DataTemplate)FindResource("FilterPanel") });
|
||||||
SongFilterNumber.Text = "0";
|
SongFilterNumber.Text = "0";
|
||||||
_shuffle._songList.Clear();
|
_shuffle.SongList.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ITag FilterEquivalence_Type(string value)
|
private ITag FilterEquivalence_Type(string value)
|
||||||
@ -168,16 +152,16 @@ namespace unison
|
|||||||
|
|
||||||
private async void UpdateFilter_Clicked(object sender, RoutedEventArgs e)
|
private async void UpdateFilter_Clicked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
QueryFilterText.Visibility = Visibility.Visible;
|
||||||
await UpdateFilter();
|
await UpdateFilter();
|
||||||
|
QueryFilterText.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateFilter()
|
private async Task UpdateFilter()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("update filter => start");
|
Debug.WriteLine("update filter => start");
|
||||||
|
|
||||||
_filters.Clear();
|
Filters.Clear();
|
||||||
|
|
||||||
//Debug.WriteLine("is on main thread => " + IsOnMainThread());
|
|
||||||
|
|
||||||
foreach (ContentPresenter superChild in FilterPanel.Children)
|
foreach (ContentPresenter superChild in FilterPanel.Children)
|
||||||
{
|
{
|
||||||
@ -219,16 +203,16 @@ namespace unison
|
|||||||
if (value != "")
|
if (value != "")
|
||||||
{
|
{
|
||||||
if (!isDir)
|
if (!isDir)
|
||||||
_filters.Add(new FilterTag(tag, value, op));
|
Filters.Add(new FilterTag(tag, value, op));
|
||||||
else
|
else
|
||||||
_filters.Add(new FilterBase(value, FilterOperator.None));
|
Filters.Add(new FilterBase(value, FilterOperator.None));
|
||||||
|
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await _shuffle.GetSongsFromFilter(_filters, _mpd._cancelCommand.Token);
|
await _shuffle.GetSongsFromFilter(Filters, _mpd._cancelCommand.Token);
|
||||||
});
|
});
|
||||||
SongFilterPanel.Visibility = Visibility.Visible;
|
SongFilterPanel.Visibility = Visibility.Visible;
|
||||||
SongFilterNumber.Text = _shuffle._songList.Count.ToString();
|
SongFilterNumber.Text = _shuffle.SongList.Count.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine("update filter => part 4");
|
Debug.WriteLine("update filter => part 4");
|
||||||
@ -268,9 +252,9 @@ namespace unison
|
|||||||
{
|
{
|
||||||
string item = e.AddedItems[0].ToString();
|
string item = e.AddedItems[0].ToString();
|
||||||
if (item == "Genre")
|
if (item == "Genre")
|
||||||
FilterType_Change(sender, "OperatorTypeB", _genreList);
|
FilterType_Change(sender, "OperatorTypeB", GenreList);
|
||||||
else if (item == "Directory")
|
else if (item == "Directory")
|
||||||
FilterType_Change(sender, "OperatorTypeC", _folderList);
|
FilterType_Change(sender, "OperatorTypeC", FolderList);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ComboBox combobox = sender as ComboBox;
|
ComboBox combobox = sender as ComboBox;
|
||||||
@ -309,58 +293,85 @@ namespace unison
|
|||||||
|
|
||||||
private void QueueValidationNumber()
|
private void QueueValidationNumber()
|
||||||
{
|
{
|
||||||
if (int.Parse(SongNumber.Text) < 1)
|
int Number;
|
||||||
SongNumber.Text = "1";
|
try
|
||||||
if (int.Parse(SongNumber.Text) > 1000)
|
{
|
||||||
SongNumber.Text = "1000";
|
Number = int.Parse(SongNumber.Text);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void AddToQueue_Clicked(object sender, RoutedEventArgs e)
|
if (Number < 1)
|
||||||
|
SongNumber.Text = "1";
|
||||||
|
if (IsFilterEmpty())
|
||||||
{
|
{
|
||||||
QueueValidationNumber();
|
if (Number > 100)
|
||||||
|
SongNumber.Text = "100";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Number > 1000)
|
||||||
|
SongNumber.Text = "1000";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void AddToQueue()
|
||||||
|
{
|
||||||
if (_mpd.GetStats() == null)
|
if (_mpd.GetStats() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NumberAddedSongs.Text = "0";
|
await UpdateFilter();
|
||||||
|
QueueValidationNumber();
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// Added => Adding songs...
|
||||||
|
// to
|
||||||
|
// Added X songs! (display for 5 seconds)
|
||||||
|
|
||||||
|
NumberAddedSongs.Text = SongNumber.Text;
|
||||||
SearchStatus.Visibility = Visibility.Visible;
|
SearchStatus.Visibility = Visibility.Visible;
|
||||||
|
|
||||||
// start dispatcher
|
int Num = int.Parse(SongNumber.Text);
|
||||||
// write _shuffle.AddedSongs in dispatcher
|
await AddToQueue_Internal(Num);
|
||||||
|
|
||||||
|
|
||||||
await UpdateFilter();
|
|
||||||
await AddToQueue(int.Parse(SongNumber.Text));
|
|
||||||
|
|
||||||
Debug.WriteLine("add to queue finished");
|
|
||||||
|
|
||||||
SearchStatus.Visibility = Visibility.Collapsed;
|
SearchStatus.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AddToQueue(int NumberToAdd)
|
private async Task AddToQueue_Internal(int Num)
|
||||||
{
|
{
|
||||||
//await UpdateFilter();
|
|
||||||
|
|
||||||
Debug.WriteLine("check filters");
|
|
||||||
|
|
||||||
if (IsFilterEmpty())
|
if (IsFilterEmpty())
|
||||||
{
|
{
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await _shuffle.AddToQueueRandom(NumberToAdd, _mpd._cancelCommand.Token);
|
await _shuffle.AddToQueueRandom(Num, _mpd._cancelCommand.Token);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("add to queue filter - before");
|
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await _shuffle.AddToQueueFilter(NumberToAdd, _mpd._cancelCommand.Token);
|
await _shuffle.AddToQueueFilter(Num, _mpd._cancelCommand.Token);
|
||||||
});
|
});
|
||||||
Debug.WriteLine("add to queue filter - after");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine("add to queue finished");
|
private void QueryFilterHandler(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Return)
|
||||||
|
UpdateFilter_Clicked(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddToQueueHandler(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Return)
|
||||||
|
AddToQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddToQueue_Clicked(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
AddToQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetContinuous()
|
public bool GetContinuous()
|
||||||
@ -377,11 +388,12 @@ namespace unison
|
|||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine("continuous __before__ add to queue");
|
Debug.WriteLine("continuous __before__ add to queue");
|
||||||
|
|
||||||
await UpdateFilter();
|
await UpdateFilter();
|
||||||
await Task.Run(async () =>
|
|
||||||
{
|
int Num = 5;
|
||||||
await AddToQueue(5);
|
await AddToQueue_Internal(Num);
|
||||||
});
|
|
||||||
Debug.WriteLine("continuous __after__ add to queue");
|
Debug.WriteLine("continuous __after__ add to queue");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,11 +404,21 @@ namespace unison
|
|||||||
else
|
else
|
||||||
_continuous = false;
|
_continuous = false;
|
||||||
|
|
||||||
int Length = _mpd.GetStatus().PlaylistLength;
|
if (_mpd.GetStatus().PlaylistLength < 5)
|
||||||
Trace.WriteLine("Length is " + Length);
|
|
||||||
|
|
||||||
if (/*_mpd.GetStatus().PlaylistLength*/Length < 5)
|
|
||||||
await HandleContinuous();
|
await HandleContinuous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Window_Closing(object sender, CancelEventArgs e)
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
WindowState = WindowState.Minimized;
|
||||||
|
Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InitHwnd()
|
||||||
|
{
|
||||||
|
WindowInteropHelper helper = new(this);
|
||||||
|
helper.EnsureHandle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user