Compare commits

..

No commits in common. "c93a9a326ed17f066abdaa1307818e29dc875fb5" and "4c71d6a6e06162faa9b80dacbee75555c473dff0" have entirely different histories.

5 changed files with 29 additions and 100 deletions

View File

@ -497,23 +497,21 @@ namespace unison
public async void QueryStats() public async void QueryStats()
{ {
Dictionary<string, string> Response = await SafelySendCommandAsync(new StatsCommand()); Dictionary<string, string> response = await SafelySendCommandAsync(new StatsCommand());
if (Response == null)
return;
_stats.Songs = int.Parse(Response["songs"]); _stats.Songs = int.Parse(response["songs"]);
_stats.Albums = int.Parse(Response["albums"]); _stats.Albums = int.Parse(response["albums"]);
_stats.Artists = int.Parse(Response["artists"]); _stats.Artists = int.Parse(response["artists"]);
TimeSpan time; TimeSpan time;
time = TimeSpan.FromSeconds(int.Parse(Response["uptime"])); time = TimeSpan.FromSeconds(int.Parse(response["uptime"]));
_stats.Uptime = time.ToString(@"dd\:hh\:mm\:ss"); _stats.Uptime = time.ToString(@"dd\:hh\:mm\:ss");
time = TimeSpan.FromSeconds(int.Parse(Response["db_playtime"])); time = TimeSpan.FromSeconds(int.Parse(response["db_playtime"]));
_stats.TotalPlaytime = time.ToString(@"dd\:hh\:mm\:ss"); _stats.TotalPlaytime = time.ToString(@"dd\:hh\:mm\:ss");
time = TimeSpan.FromSeconds(int.Parse(Response["playtime"])); time = TimeSpan.FromSeconds(int.Parse(response["playtime"]));
_stats.TotalTimePlayed = time.ToString(@"dd\:hh\:mm\:ss"); _stats.TotalTimePlayed = time.ToString(@"dd\:hh\:mm\:ss");
DateTime date = new DateTime(1970, 1, 1).AddSeconds(int.Parse(Response["db_update"])).ToLocalTime(); DateTime date = new DateTime(1970, 1, 1).AddSeconds(int.Parse(response["db_update"])).ToLocalTime();
_stats.DatabaseUpdate = date.ToString("dd/MM/yyyy @ HH:mm"); _stats.DatabaseUpdate = date.ToString("dd/MM/yyyy @ HH:mm");
} }
} }

View File

@ -65,7 +65,6 @@ namespace unison
Connection.Text = $"{Properties.Settings.Default.mpd_host}:{Properties.Settings.Default.mpd_port}"; Connection.Text = $"{Properties.Settings.Default.mpd_host}:{Properties.Settings.Default.mpd_port}";
_shuffleWin.ListGenre(); _shuffleWin.ListGenre();
_shuffleWin.ListFolder();
} }
public async void OnSongChanged(object sender, EventArgs e) public async void OnSongChanged(object sender, EventArgs e)

View File

@ -57,8 +57,8 @@
<Grid> <Grid>
<StackPanel> <StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBox x:Name="VolumeOffset" TextWrapping="Wrap" Width="25" PreviewTextInput="NumberValidationTextBox" Margin="0,2,0,0"/> <TextBlock Text="{x:Static properties:Resources.Settings_VolumeOffset}" TextWrapping="Wrap" Margin="0,2,0,0"/>
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeOffset}" TextWrapping="Wrap" Margin="5,2,0,0"/> <TextBox x:Name="VolumeOffset" TextWrapping="Wrap" Width="25" PreviewTextInput="NumberValidationTextBox" Margin="8,2,0,0"/>
</StackPanel> </StackPanel>
<Grid MinWidth="300" Margin="0,5,0,0"> <Grid MinWidth="300" Margin="0,5,0,0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@ -137,11 +137,7 @@
</GroupBox.Header> </GroupBox.Header>
<Grid MaxWidth="500"> <Grid MaxWidth="500">
<StackPanel> <StackPanel>
<StackPanel Orientation="Horizontal"> <TextBlock TextWrapping="Wrap">
<TextBox TextWrapping="Wrap" Width="25" PreviewTextInput="NumberValidationTextBox" Margin="0,2,0,0"/>
<TextBlock Text="Prevent repetition rate (0-100%)" TextWrapping="Wrap" Margin="5,2,0,0"/>
</StackPanel>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0">
<Run>The shuffle window allows to add random songs to your queue. Both options take into account the filter.</Run> <Run>The shuffle window allows to add random songs to your queue. Both options take into account the filter.</Run>
<Run>If the filter is empty, the entire music library is taken into account.</Run><LineBreak/><LineBreak/> <Run>If the filter is empty, the entire music library is taken into account.</Run><LineBreak/><LineBreak/>
<Run FontWeight="Bold">Continuous shuffle</Run><LineBreak/> <Run FontWeight="Bold">Continuous shuffle</Run><LineBreak/>

View File

@ -22,37 +22,31 @@
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<TextBlock Text="Song" Margin="0,0,0,2"/> <TextBlock Text="Song" Margin="0,0,0,2"/>
<TextBox x:Name="Song" Width="240" Margin="5,0,0,0"/> <TextBox x:Name="Song" Width="240"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,0,0"> <StackPanel Orientation="Vertical" Margin="20,0,0,0">
<TextBlock Text="Artist" Margin="0,0,0,2"/> <TextBlock Text="Artist" Margin="0,0,0,2"/>
<TextBox x:Name="Artist" Width="240" Margin="5,0,0,0"/> <TextBox x:Name="Artist" Width="240"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,5,0,0"> <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<TextBlock Text="Album" Margin="0,0,0,2"/> <TextBlock Text="Album" Margin="0,0,0,2"/>
<TextBox x:Name="Album" Width="240" Margin="5,0,0,0"/> <TextBox x:Name="Album" Width="240"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,0,0"> <StackPanel Orientation="Vertical" Margin="20,0,0,0">
<TextBlock Text="Year" Margin="0,0,0,2"/> <TextBlock Text="Year" Margin="0,0,0,2"/>
<TextBox x:Name="Year" Width="240" Margin="5,0,0,0"/> <TextBox x:Name="Year" Width="240"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,5,0,5"> <StackPanel Orientation="Horizontal" Margin="0,5,0,5">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<TextBlock Text="Genre" Margin="0,0,0,2"/> <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"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,0,0"> <Button Content="Reset" Click="Reset_Clicked" Padding="5, 2" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="20,0,0,0" FocusVisualStyle="{x:Null}"/>
<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"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,5,0,5">
<Button Content="Reset" Click="Reset_Clicked" Padding="5, 2" VerticalAlignment="Bottom" HorizontalAlignment="Left" FocusVisualStyle="{x:Null}"/>
</StackPanel> </StackPanel>
<StackPanel x:Name="SongFilterPanel" Margin="0,5,0,0" Visibility="Collapsed"> <StackPanel x:Name="SongFilterPanel" Margin="0,5,0,0" Visibility="Collapsed">
<TextBlock> <TextBlock>

View File

@ -10,6 +10,8 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
// https://mpd.readthedocs.io/en/stable/protocol.html#binary
namespace unison namespace unison
{ {
public partial class Shuffle : Window public partial class Shuffle : Window
@ -31,12 +33,6 @@ namespace unison
public void AddContinuousSongs() public void AddContinuousSongs()
{ {
if (Song.Text.Length == 0 && Artist.Text.Length == 0 && Album.Text.Length == 0 && Year.Text.Length == 0 && Genre.SelectedIndex == 0)
{
ContinuousShuffle_AddToQueueRandom();
return;
}
int AddedSongs = 0; int AddedSongs = 0;
NumberAddedSongs.Text = AddedSongs.ToString(); NumberAddedSongs.Text = AddedSongs.ToString();
SearchStatus.Visibility = Visibility.Visible; SearchStatus.Visibility = Visibility.Visible;
@ -59,32 +55,17 @@ namespace unison
if (Genre.Items.Count == 0) if (Genre.Items.Count == 0)
{ {
_mpd = (MPDHandler)Application.Current.Properties["mpd"]; _mpd = (MPDHandler)Application.Current.Properties["mpd"];
Genre.Items.Add("");
List<string> Response = await _mpd.SafelySendCommandAsync(new ListCommand(MpdTags.Genre, null, null)); List<string> Response = await _mpd.SafelySendCommandAsync(new ListCommand(MpdTags.Genre, null, null));
foreach (var genre in Response)
if (Response.Count > 0) Genre.Items.Add(genre);
{
Genre.Items.Add("");
foreach (var genre in Response)
Genre.Items.Add(genre);
}
} }
} }
public async void ListFolder() public async void ListFolder()
{ {
if (Directory.Items.Count == 0) _mpd = (MPDHandler)Application.Current.Properties["mpd"];
{ //await _mpd.SafelySendCommandAsync(new )
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
List<string> Response = await _mpd.SafelySendCommandAsync(new ListFilesCommand());
if (Response.Count > 0)
{
Directory.Items.Add("");
for (int i = 0; i < Response.Count; i++)
if (i % 2 != 1)
Directory.Items.Add(Response[i]);
}
}
} }
private void Window_Closing(object sender, CancelEventArgs e) private void Window_Closing(object sender, CancelEventArgs e)
@ -116,14 +97,7 @@ namespace unison
AddToQueueGroup.IsEnabled = false; AddToQueueGroup.IsEnabled = false;
_continuous = true; _continuous = true;
_songList.Clear(); _songList.Clear();
if (Song.Text.Length == 0 && Artist.Text.Length == 0 && Album.Text.Length == 0 && Year.Text.Length == 0 && Genre.SelectedIndex == 0) await GetSongsFromFilter();
{
}
else
{
/*await*/
GetSongsFromFilter();
}
} }
else else
{ {
@ -132,30 +106,8 @@ namespace unison
} }
} }
private async void ContinuousShuffle_AddToQueueRandom() // search "((title contains ''))" window 38669:38670
{ // listfiles
for (int i = 0; i < 2; i++)
{
// generate random number
int song = new Random().Next(0, _mpd.GetStats().Songs - 1);
// query random song
CommandList commandList = new CommandList(new IMpcCommand<object>[] { new SearchCommand(MpdTags.Title, "", song, song + 1) });
string Response = await _mpd.SafelySendCommandAsync(commandList);
await Task.Delay(1);
if (Response.Length > 0)
{
// parse song and add it to queue
int start = Response.IndexOf("[file, ");
int end = Response.IndexOf("],");
string filePath = Response.Substring(start + 7, end - (start + 7));
_mpd.AddSong(filePath);
}
}
SearchStatus.Visibility = Visibility.Collapsed;
}
private async void AddToQueueRandom() private async void AddToQueueRandom()
{ {
@ -192,7 +144,6 @@ namespace unison
private async Task GetSongsFromFilter() private async Task GetSongsFromFilter()
{ {
_songList.Clear(); _songList.Clear();
SongFilterPanel.Visibility = Visibility.Visible;
int song = _mpd.GetStats().Songs; int song = _mpd.GetStats().Songs;
@ -209,13 +160,6 @@ namespace unison
// create a list of the file url // create a list of the file url
string[] value = Response.Split(", [file, "); string[] value = Response.Split(", [file, ");
// there are no song in this filter
if (value[0] == "")
{
SongFilterNumber.Text = _songList.Count.ToString();
return;
}
foreach (string file in value) foreach (string file in value)
{ {
int start = 0; int start = 0;
@ -223,8 +167,6 @@ namespace unison
string filePath = file.Substring(start, end - start); string filePath = file.Substring(start, end - start);
_songList.Add(filePath); _songList.Add(filePath);
SongFilterNumber.Text = _songList.Count.ToString();
} }
// remove characters from first file // remove characters from first file
@ -234,8 +176,8 @@ namespace unison
SongFilterNumber.Text = _songList.Count.ToString(); SongFilterNumber.Text = _songList.Count.ToString();
// DEBUG // DEBUG
//foreach (var a in _songList) foreach (var a in _songList)
// Debug.WriteLine(a); Debug.WriteLine(a);
Debug.WriteLine("number of songs found: " + _songList.Count); Debug.WriteLine("number of songs found: " + _songList.Count);
Debug.WriteLine("number of songs requested: " + int.Parse(SongNumber.Text)); Debug.WriteLine("number of songs requested: " + int.Parse(SongNumber.Text));
} }