Update MpcNET from 1.3 to 1.4 to use filters

This commit is contained in:
Théo Marchal 2022-04-14 01:06:33 +02:00
parent 6ad4d9c813
commit 5d6e3b6d1e
5 changed files with 55 additions and 40 deletions

View File

@ -110,14 +110,15 @@
</Border>
</Grid>
<Grid x:Name="BottomLayout" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" Width="Auto" MinHeight="40">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,10,0">
<Button x:Name="Snapcast" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Snapcast_Clicked" Margin="10,0,0,0" Padding="5, 2" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}" IsEnabled="False">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" Margin="10,0,0,0">
<Button x:Name="Shuffle" Padding="5, 2" Click="Shuffle_Clicked" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}" Margin="0,0,10,0">
<StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="🔊" Padding="0,0,0,2"/>
<TextBlock x:Name="SnapcastText" Text="{x:Static properties:Resources.StartSnapcast}" Margin="5, 0, 0, 0"/>
<emoji:TextBlock Text="🔁" Padding="0,0,0,2"/>
<TextBlock Text="Shuffle" Margin="5, 0, 0, 0"/>
</StackPanel>
</Button>
<Button x:Name="Radio" Padding="5, 2" HorizontalAlignment="Left" Click="Radios_Clicked" Margin="5,0,10,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}" IsEnabled="False">
<Button x:Name="Radio" Padding="5, 2" HorizontalAlignment="Left" Click="Radios_Clicked" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}" IsEnabled="False">
<StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="📻" Padding="0,0,0,2"/>
<TextBlock Text="{x:Static properties:Resources.Radios}" Margin="5, 0, 0, 0"/>
@ -135,12 +136,13 @@
<TextBlock x:Name="Connection" HorizontalAlignment="Center" Text="Not connected" TextWrapping="Wrap" VerticalAlignment="Top" TextAlignment="Center" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Margin="5,0,0,0" />
</StackPanel>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,10,0">
<Button x:Name="Shuffle" Padding="5, 2" Click="Shuffle_Clicked" Margin="0,0,10,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}">
<Button x:Name="Snapcast" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Snapcast_Clicked" Margin="0,0,10,0" Padding="5, 2" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}" IsEnabled="False">
<StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="🔁" Padding="0,0,0,2"/>
<TextBlock Text="Shuffle" Margin="5, 0, 0, 0"/>
<emoji:TextBlock Text="🔊" Padding="0,0,0,2"/>
<TextBlock x:Name="SnapcastText" Text="{x:Static properties:Resources.StartSnapcast}" Margin="5, 0, 0, 0"/>
</StackPanel>
</Button>
<Button x:Name="Settings" Padding="5, 2" Click="Settings_Clicked" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}">
<StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="🛠️" Padding="0,0,0,2"/>

View File

@ -53,6 +53,9 @@ namespace unison
Snapcast.IsEnabled = true;
ConnectionOkIcon.Visibility = Visibility.Visible;
ConnectionFailIcon.Visibility = Visibility.Collapsed;
_shuffleWin.ListGenre();
_shuffleWin.ListFolder();
}
else
{
@ -63,9 +66,6 @@ namespace unison
}
_settingsWin.UpdateConnectionStatus();
Connection.Text = $"{Properties.Settings.Default.mpd_host}:{Properties.Settings.Default.mpd_port}";
_shuffleWin.ListGenre();
_shuffleWin.ListFolder();
}
public async void OnSongChanged(object sender, EventArgs e)

View File

@ -44,11 +44,11 @@
<StackPanel Orientation="Horizontal" Margin="0,5,0,5">
<StackPanel Orientation="Vertical">
<TextBlock Text="Genre" Margin="0,0,0,2"/>
<ComboBox x:Name="Genre" SelectedIndex="0" Width="240" ScrollViewer.CanContentScroll="False" Margin="5,0,0,0"/>
<ComboBox x:Name="Genre" SelectedIndex="0" Width="240" ScrollViewer.CanContentScroll="False" Margin="5,0,0,0" FocusVisualStyle="{x:Null}"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,0,0">
<TextBlock Text="Directory" Margin="0,0,0,2" TextDecorations="{x:Null}"/>
<ComboBox x:Name="Directory" SelectedIndex="0" Width="240" ScrollViewer.CanContentScroll="False" Margin="5,0,0,0" IsEnabled="False"/>
<ComboBox x:Name="Directory" SelectedIndex="0" Width="240" ScrollViewer.CanContentScroll="False" Margin="5,0,0,0" IsEnabled="True"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,5,0,5">
@ -70,7 +70,7 @@
</TextBlock>
</GroupBox.Header>
<StackPanel Orientation="Horizontal" Margin="5,8,0,0">
<CheckBox x:Name="ContinuousShuffle" Checked="ContinuousShuffle_Checked" Unchecked="ContinuousShuffle_Checked">
<CheckBox x:Name="ContinuousShuffle" Checked="ContinuousShuffle_Checked" Unchecked="ContinuousShuffle_Checked" FocusVisualStyle="{x:Null}">
<TextBlock Text="Enable continuous shuffle" TextWrapping="Wrap"/>
</CheckBox>
</StackPanel>

View File

@ -2,6 +2,8 @@
using MpcNET.Commands.Database;
using MpcNET.Commands.Reflection;
using MpcNET.Tags;
using MpcNET.Types;
using MpcNET.Types.Filters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -24,6 +26,13 @@ namespace unison
_songList = new();
}
private bool IsFilterEmpty()
{
if (Song.Text.Length == 0 && Artist.Text.Length == 0 && Album.Text.Length == 0 && Year.Text.Length == 0 && Genre.SelectedIndex == 0 && Directory.Text.Length == 0)
return true;
return false;
}
public bool GetContinuous()
{
return _continuous;
@ -31,8 +40,9 @@ namespace unison
public void AddContinuousSongs()
{
if (Song.Text.Length == 0 && Artist.Text.Length == 0 && Album.Text.Length == 0 && Year.Text.Length == 0 && Genre.SelectedIndex == 0)
if (IsFilterEmpty())
{
// add a completely random song
ContinuousShuffle_AddToQueueRandom();
return;
}
@ -75,14 +85,13 @@ namespace unison
if (Directory.Items.Count == 0)
{
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
List<string> Response = await _mpd.SafelySendCommandAsync(new ListFilesCommand());
IEnumerable<IMpdFilePath> Response = await _mpd.SafelySendCommandAsync(new LsInfoCommand(""));
if (Response.Count > 0)
if (Response != null)
{
Directory.Items.Add("");
for (int i = 0; i < Response.Count; i++)
if (i % 2 != 1)
Directory.Items.Add(Response[i]);
foreach (var directory in Response)
Directory.Items.Add(directory.Name);
}
}
}
@ -107,6 +116,7 @@ namespace unison
Album.Text = "";
Year.Text = "";
Genre.SelectedIndex = 0;
Directory.SelectedIndex = 0;
}
private async void ContinuousShuffle_Checked(object sender, RoutedEventArgs e)
@ -116,10 +126,7 @@ namespace unison
AddToQueueGroup.IsEnabled = false;
_continuous = true;
_songList.Clear();
if (Song.Text.Length == 0 && Artist.Text.Length == 0 && Album.Text.Length == 0 && Year.Text.Length == 0 && Genre.SelectedIndex == 0)
{
}
else
if (!IsFilterEmpty())
{
/*await*/
GetSongsFromFilter();
@ -196,16 +203,27 @@ namespace unison
int song = _mpd.GetStats().Songs;
List<KeyValuePair<ITag, string>> filters = new();
filters.Add(new KeyValuePair<ITag, string>(MpdTags.Title, Song.Text));
filters.Add(new KeyValuePair<ITag, string>(MpdTags.Artist, Artist.Text));
filters.Add(new KeyValuePair<ITag, string>(MpdTags.Album, Album.Text));
filters.Add(new KeyValuePair<ITag, string>(MpdTags.Date, Year.Text));
filters.Add(new KeyValuePair<ITag, string>(MpdTags.Genre, Genre.Text));
List<IFilter> filtersA = new();
if (Song.Text != "")
filtersA.Add(new FilterTag(MpdTags.Title, Song.Text, FilterOperator.Contains));
if (Artist.Text != "")
filtersA.Add(new FilterTag(MpdTags.Artist, Artist.Text, FilterOperator.Contains));
if (Album.Text != "")
filtersA.Add(new FilterTag(MpdTags.Album, Album.Text, FilterOperator.Contains));
if (Year.Text != "")
filtersA.Add(new FilterTag(MpdTags.Date, Year.Text, FilterOperator.Contains));
if (Genre.Text != "")
filtersA.Add(new FilterTag(MpdTags.Genre, Genre.Text, FilterOperator.Contains));
if (Directory.Text != "")
filtersA.Add(new FilterBase(Directory.Text, FilterOperator.None));
CommandList commandList = new CommandList(new IMpcCommand<object>[] { new SearchCommand(filters, 0, song + 1) });
Debug.WriteLine(Directory.Text);
CommandList commandList = new CommandList(new IMpcCommand<object>[] { new SearchCommand(filtersA, 0, song + 1) });
string Response = await _mpd.SafelySendCommandAsync(commandList);
Debug.WriteLine(Response);
// create a list of the file url
string[] value = Response.Split(", [file, ");
@ -222,6 +240,7 @@ namespace unison
int end = file.IndexOf("],");
string filePath = file.Substring(start, end - start);
Debug.WriteLine(filePath);
_songList.Add(filePath);
SongFilterNumber.Text = _songList.Count.ToString();
@ -232,12 +251,6 @@ namespace unison
SongFilterPanel.Visibility = Visibility.Visible;
SongFilterNumber.Text = _songList.Count.ToString();
// DEBUG
//foreach (var a in _songList)
// Debug.WriteLine(a);
Debug.WriteLine("number of songs found: " + _songList.Count);
Debug.WriteLine("number of songs requested: " + int.Parse(SongNumber.Text));
}
private async void AddToQueueFilter()
@ -285,7 +298,7 @@ namespace unison
if (_mpd.GetStats() == null)
return;
if (Song.Text.Length == 0 && Artist.Text.Length == 0 && Album.Text.Length == 0 && Year.Text.Length == 0 && Genre.SelectedIndex == 0)
if (IsFilterEmpty())
AddToQueueRandom();
else
AddToQueueFilter();

View File

@ -7,7 +7,7 @@
<ApplicationIcon>Resources\icon-full.ico</ApplicationIcon>
<Win32Resource></Win32Resource>
<StartupObject>unison.App</StartupObject>
<Version>1.2</Version>
<Version>1.3</Version>
<Company />
<Authors>Théo Marchal</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
@ -47,7 +47,7 @@
<PackageReference Include="Emoji.Wpf" Version="0.3.3" />
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="RadioBrowser" Version="0.6.1" />
<PackageReference Include="MpcNET" Version="1.3.0" />
<PackageReference Include="MpcNET" Version="1.4.0" />
</ItemGroup>
<ItemGroup>