Compare commits
4 Commits
06207d9791
...
shuffle
Author | SHA1 | Date | |
---|---|---|---|
f6eb00759a | |||
468ec8be07 | |||
52b0a6fc85 | |||
5a43a1284e |
@ -67,7 +67,7 @@ namespace unison
|
|||||||
private MpcConnection _commandConnection;
|
private MpcConnection _commandConnection;
|
||||||
private IPEndPoint _mpdEndpoint;
|
private IPEndPoint _mpdEndpoint;
|
||||||
|
|
||||||
private CancellationTokenSource _cancelCommand;
|
public CancellationTokenSource _cancelCommand;
|
||||||
private CancellationTokenSource _cancelConnect;
|
private CancellationTokenSource _cancelConnect;
|
||||||
|
|
||||||
public MPDHandler()
|
public MPDHandler()
|
||||||
|
@ -75,7 +75,6 @@ namespace unison.Handlers
|
|||||||
|
|
||||||
public async Task<List<StationInfo>> AdvancedSearch(AdvancedSearchOptions options)
|
public async Task<List<StationInfo>> AdvancedSearch(AdvancedSearchOptions options)
|
||||||
{
|
{
|
||||||
|
|
||||||
return await _radioBrowser.Search.AdvancedAsync(options);
|
return await _radioBrowser.Search.AdvancedAsync(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,134 +1,108 @@
|
|||||||
using MpcNET.Commands.Database;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using MpcNET;
|
||||||
|
using MpcNET.Commands.Database;
|
||||||
|
using MpcNET.Commands.Playback;
|
||||||
using MpcNET.Commands.Queue;
|
using MpcNET.Commands.Queue;
|
||||||
|
using MpcNET.Commands.Reflection;
|
||||||
using MpcNET.Tags;
|
using MpcNET.Tags;
|
||||||
using MpcNET.Types;
|
using MpcNET.Types;
|
||||||
using MpcNET.Types.Filters;
|
using MpcNET.Types.Filters;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
|
||||||
|
|
||||||
namespace unison
|
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()
|
public async Task GetSongsFromFilter(List<IFilter> filter, CancellationToken token)
|
||||||
{
|
{
|
||||||
return Application.Current.Dispatcher.Thread == System.Threading.Thread.CurrentThread;
|
if (token.IsCancellationRequested)
|
||||||
}
|
return;
|
||||||
|
|
||||||
public async Task GetSongsFromFilter(List<IFilter> filter)
|
SongList.Clear();
|
||||||
{
|
|
||||||
Debug.WriteLine("[GetSongsFromFilterBefore] is on main thread => " + IsOnMainThread());
|
|
||||||
await Task.Run(async() =>
|
|
||||||
{
|
|
||||||
Debug.WriteLine("[GetSongsFromFilterAfter] is on main thread => " + IsOnMainThread());
|
|
||||||
|
|
||||||
_songList.Clear();
|
|
||||||
int song = _mpd.GetStats().Songs;
|
int song = _mpd.GetStats().Songs;
|
||||||
|
|
||||||
IEnumerable<IMpdFile> response = await _mpd.SafelySendCommandAsync(new SearchCommand(filter, 0, song + 1));
|
IEnumerable<IMpdFile> response = await _mpd.SafelySendCommandAsync(new SearchCommand(filter, 0, song + 1));
|
||||||
|
|
||||||
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)
|
public async Task AddToQueueRandom(int SongNumber, CancellationToken token)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Add To Queue Random");
|
if (token.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
|
||||||
await Task.Run(async () =>
|
|
||||||
{
|
|
||||||
int AddedSongs = 0;
|
int AddedSongs = 0;
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddToQueueFilter(int SongNumber)
|
await _mpd.SafelySendCommandAsync(commandList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddToQueueFilter(int SongNumber, CancellationToken token)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Add To Queue Filter");
|
if (token.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
|
||||||
await Task.Run(async () =>
|
|
||||||
{
|
|
||||||
int AddedSongs = 0;
|
int AddedSongs = 0;
|
||||||
|
|
||||||
Debug.WriteLine("song to add => " + SongNumber);
|
// more (or equal) requested songs than available => add everything
|
||||||
// more requested songs than available => add everything
|
if (SongNumber >= SongList.Count)
|
||||||
if (SongNumber > _songList.Count)
|
|
||||||
{
|
{
|
||||||
foreach (string path in _songList)
|
var commandList = new CommandList();
|
||||||
|
foreach (string path in SongList)
|
||||||
{
|
{
|
||||||
await Task.Delay(1);
|
commandList.Add(new AddCommand(path));
|
||||||
_mpd.AddSong(path);
|
|
||||||
Debug.WriteLine("song path => " + path);
|
|
||||||
AddedSongs++;
|
AddedSongs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
{
|
{
|
||||||
HashSet<int> SongIndex = new();
|
HashSet<int> SongIndex = new();
|
||||||
Debug.WriteLine("while - before");
|
|
||||||
while (SongIndex.Count < SongNumber)
|
while (SongIndex.Count < 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var commandList = new CommandList();
|
||||||
foreach (int index in SongIndex)
|
foreach (int index in SongIndex)
|
||||||
_mpd.AddSong(_songList[index]);
|
{
|
||||||
Debug.WriteLine("while - after");
|
commandList.Add(new AddCommand(SongList[index]));
|
||||||
|
AddedSongs++;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
Debug.WriteLine("Add To Queue Filter - finished");
|
await _mpd.SafelySendCommandAsync(commandList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,9 +7,6 @@ using System.Windows.Interop;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using unison.Handlers;
|
|
||||||
|
|
||||||
namespace unison
|
namespace unison
|
||||||
{
|
{
|
||||||
@ -125,21 +122,14 @@ namespace unison
|
|||||||
EndTime.Text = FormatSeconds(_mpd.GetCurrentSong().Time);
|
EndTime.Text = FormatSeconds(_mpd.GetCurrentSong().Time);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine("Song changed called!");
|
Trace.WriteLine("Song changed called!");
|
||||||
|
|
||||||
if (!_shuffleWin.GetContinuous())
|
if (_shuffleWin.GetContinuous())
|
||||||
return;
|
{
|
||||||
|
|
||||||
Debug.WriteLine("playlist length => " + _mpd.GetStatus().PlaylistLength);
|
|
||||||
|
|
||||||
if (_mpd.GetStatus().PlaylistLength > 4)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Debug.WriteLine("start continuous handling");
|
|
||||||
_mpd.CanPrevNext = false;
|
_mpd.CanPrevNext = false;
|
||||||
await _shuffleWin.HandleContinuous();
|
await _shuffleWin.HandleContinuous();
|
||||||
_mpd.CanPrevNext = true;
|
_mpd.CanPrevNext = true;
|
||||||
Debug.WriteLine("finished continuous");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnStatusChanged(object sender, EventArgs e)
|
public void OnStatusChanged(object sender, EventArgs e)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System.Diagnostics;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
@ -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,37 +1,40 @@
|
|||||||
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.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Linq;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
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"];
|
||||||
@ -40,13 +43,16 @@ namespace unison
|
|||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
ListGenre();
|
ListGenre(_mpd._cancelCommand.Token);
|
||||||
ListFolder();
|
ListFolder(_mpd._cancelCommand.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void ListGenre()
|
public async void ListGenre(CancellationToken token)
|
||||||
{
|
{
|
||||||
if (_genreList.Count != 0)
|
if (GenreList.Count != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (token.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<string> Response = await _mpd.SafelySendCommandAsync(new ListCommand(MpdTags.Genre, null, null));
|
List<string> Response = await _mpd.SafelySendCommandAsync(new ListCommand(MpdTags.Genre, null, null));
|
||||||
@ -55,12 +61,15 @@ namespace unison
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (string genre in Response)
|
foreach (string genre in Response)
|
||||||
_genreList.Add(genre);
|
GenreList.Add(genre);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void ListFolder()
|
public async void ListFolder(CancellationToken token)
|
||||||
{
|
{
|
||||||
if (_folderList.Count != 0)
|
if (FolderList.Count != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (token.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IEnumerable<IMpdFilePath> Response = await _mpd.SafelySendCommandAsync(new LsInfoCommand(""));
|
IEnumerable<IMpdFilePath> Response = await _mpd.SafelySendCommandAsync(new LsInfoCommand(""));
|
||||||
@ -69,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);
|
||||||
@ -130,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)
|
||||||
@ -159,65 +150,6 @@ namespace unison
|
|||||||
return FilterOperator.Equal;
|
return FilterOperator.Equal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void UpdateFilter_Clicked(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
await UpdateFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task UpdateFilter()
|
|
||||||
{
|
|
||||||
Debug.WriteLine("update filter => start");
|
|
||||||
|
|
||||||
_filters.Clear();
|
|
||||||
|
|
||||||
Debug.WriteLine("is on main thread => " + IsOnMainThread());
|
|
||||||
|
|
||||||
foreach (ContentPresenter superChild in FilterPanel.Children)
|
|
||||||
{
|
|
||||||
ITag tag = MpdTags.Title;
|
|
||||||
FilterOperator op = FilterOperator.None;
|
|
||||||
string value = "";
|
|
||||||
bool isDir = false;
|
|
||||||
|
|
||||||
StackPanel stackPanel = VisualTreeHelper.GetChild(superChild, 0) as StackPanel;
|
|
||||||
foreach (TextBox child in stackPanel.Children.OfType<TextBox>())
|
|
||||||
{
|
|
||||||
if (child.Name == "FilterValue")
|
|
||||||
value = child.Text;
|
|
||||||
}
|
|
||||||
foreach (ComboBox child in stackPanel.Children.OfType<ComboBox>())
|
|
||||||
{
|
|
||||||
if (child.Name == "FilterType")
|
|
||||||
{
|
|
||||||
if (child.SelectedItem.ToString() == "Directory")
|
|
||||||
isDir = true;
|
|
||||||
else
|
|
||||||
tag = FilterEquivalence_Type(child.SelectedItem.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child.Name == "FilterOperator")
|
|
||||||
op = FilterEquivalence_Operator(child.SelectedItem.ToString());
|
|
||||||
|
|
||||||
if (child.Name == "FilterList" && child.Visibility == Visibility.Visible)
|
|
||||||
value = child.SelectedItem.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value != "")
|
|
||||||
{
|
|
||||||
if (!isDir)
|
|
||||||
_filters.Add(new FilterTag(tag, value, op));
|
|
||||||
else
|
|
||||||
_filters.Add(new FilterBase(value, FilterOperator.None));
|
|
||||||
|
|
||||||
await _shuffle.GetSongsFromFilter(_filters);
|
|
||||||
SongFilterPanel.Visibility = Visibility.Visible;
|
|
||||||
SongFilterNumber.Text = _shuffle._songList.Count.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.WriteLine("update filter => stop");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FilterType_Change(object sender, string Operator, List<string> Listing)
|
private void FilterType_Change(object sender, string Operator, List<string> Listing)
|
||||||
{
|
{
|
||||||
ComboBox comboBox = sender as ComboBox;
|
ComboBox comboBox = sender as ComboBox;
|
||||||
@ -249,9 +181,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;
|
||||||
@ -278,10 +210,86 @@ namespace unison
|
|||||||
|
|
||||||
private void OperatorType_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void OperatorType_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("selection changed => operator type");
|
|
||||||
SongFilterNumber.Text = "0";
|
SongFilterNumber.Text = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void UpdateFilter_Clicked(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
QueryFilterText.Visibility = Visibility.Visible;
|
||||||
|
await UpdateFilter();
|
||||||
|
TimedText(QueryFilterText, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TimedText(TextBlock textBlock, int time)
|
||||||
|
{
|
||||||
|
DispatcherTimer Timer = new DispatcherTimer();
|
||||||
|
Timer.Interval = TimeSpan.FromSeconds(time);
|
||||||
|
Timer.Tick += (sender, args) =>
|
||||||
|
{
|
||||||
|
Timer.Stop();
|
||||||
|
textBlock.Visibility = Visibility.Collapsed;
|
||||||
|
};
|
||||||
|
Timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UpdateFilter()
|
||||||
|
{
|
||||||
|
Filters.Clear();
|
||||||
|
|
||||||
|
foreach (ContentPresenter superChild in FilterPanel.Children)
|
||||||
|
{
|
||||||
|
ITag tag = MpdTags.Title;
|
||||||
|
FilterOperator op = FilterOperator.None;
|
||||||
|
string value = "";
|
||||||
|
bool isDir = false;
|
||||||
|
|
||||||
|
StackPanel stackPanel = VisualTreeHelper.GetChild(superChild, 0) as StackPanel;
|
||||||
|
foreach (TextBox child in stackPanel.Children.OfType<TextBox>())
|
||||||
|
{
|
||||||
|
if (child.Name == "FilterValue")
|
||||||
|
value = child.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ComboBox child in stackPanel.Children.OfType<ComboBox>())
|
||||||
|
{
|
||||||
|
if (child.Name == "FilterType")
|
||||||
|
{
|
||||||
|
if (child.SelectedItem.ToString() == "Directory")
|
||||||
|
isDir = true;
|
||||||
|
else
|
||||||
|
tag = FilterEquivalence_Type(child.SelectedItem.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.Name == "FilterOperator")
|
||||||
|
op = FilterEquivalence_Operator(child.SelectedItem.ToString());
|
||||||
|
|
||||||
|
if (child.Name == "FilterList" && child.Visibility == Visibility.Visible)
|
||||||
|
value = child.SelectedItem.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value != "")
|
||||||
|
{
|
||||||
|
if (!isDir)
|
||||||
|
Filters.Add(new FilterTag(tag, value, op));
|
||||||
|
else
|
||||||
|
Filters.Add(new FilterBase(value, FilterOperator.None));
|
||||||
|
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await _shuffle.GetSongsFromFilter(Filters, _mpd._cancelCommand.Token);
|
||||||
|
});
|
||||||
|
SongFilterPanel.Visibility = Visibility.Visible;
|
||||||
|
SongFilterNumber.Text = _shuffle.SongList.Count.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void QueryFilterHandler(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Return)
|
||||||
|
UpdateFilter_Clicked(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
private void QueueValidationTextBox(object sender, TextCompositionEventArgs e)
|
private void QueueValidationTextBox(object sender, TextCompositionEventArgs e)
|
||||||
{
|
{
|
||||||
Regex regex = new Regex("[^0-9]+");
|
Regex regex = new Regex("[^0-9]+");
|
||||||
@ -290,48 +298,79 @@ 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 AddToQueue(int.Parse(SongNumber.Text));
|
TimedText(SearchStatus, 2);
|
||||||
|
|
||||||
Debug.WriteLine("add to queue finished");
|
|
||||||
|
|
||||||
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 _shuffle.AddToQueueRandom(NumberToAdd);
|
{
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await _shuffle.AddToQueueRandom(Num, _mpd._cancelCommand.Token);
|
||||||
|
});
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("add to queue filter - before");
|
await Task.Run(async () =>
|
||||||
await _shuffle.AddToQueueFilter(NumberToAdd);
|
{
|
||||||
Debug.WriteLine("add to queue filter - after");
|
await _shuffle.AddToQueueFilter(Num, _mpd._cancelCommand.Token);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine("add to queue finished");
|
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()
|
||||||
@ -342,14 +381,15 @@ namespace unison
|
|||||||
public async Task HandleContinuous()
|
public async Task HandleContinuous()
|
||||||
{
|
{
|
||||||
if (!_continuous)
|
if (!_continuous)
|
||||||
{
|
|
||||||
Debug.WriteLine("continuous return nothing!");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
Debug.WriteLine("continuous __before__ add to queue");
|
int PlaylistLength = _mpd.GetStatus().PlaylistLength;
|
||||||
await AddToQueue(5);
|
int Num = 10 - PlaylistLength;
|
||||||
Debug.WriteLine("continuous __after__ add to queue");
|
if (Num < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await UpdateFilter();
|
||||||
|
await AddToQueue_Internal(Num);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ContinuousShuffle_Checked(object sender, RoutedEventArgs e)
|
private async void ContinuousShuffle_Checked(object sender, RoutedEventArgs e)
|
||||||
@ -359,8 +399,21 @@ namespace unison
|
|||||||
else
|
else
|
||||||
_continuous = false;
|
_continuous = false;
|
||||||
|
|
||||||
if (_mpd.GetStatus().PlaylistLength < 5)
|
if (_mpd.GetStatus().PlaylistLength < 10)
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@
|
|||||||
<ApplicationIcon>Resources\icon-full.ico</ApplicationIcon>
|
<ApplicationIcon>Resources\icon-full.ico</ApplicationIcon>
|
||||||
<Win32Resource></Win32Resource>
|
<Win32Resource></Win32Resource>
|
||||||
<StartupObject>unison.App</StartupObject>
|
<StartupObject>unison.App</StartupObject>
|
||||||
<Version>1.3.1</Version>
|
<Version>1.4</Version>
|
||||||
<Company />
|
<Company />
|
||||||
<Authors>Théo Marchal</Authors>
|
<Authors>Théo Marchal</Authors>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
|
Reference in New Issue
Block a user