20 Commits

Author SHA1 Message Date
5d6e3b6d1e Update MpcNET from 1.3 to 1.4 to use filters 2022-04-14 01:06:33 +02:00
6ad4d9c813 Merge branch 'main' into shuffle 2022-04-07 00:59:00 +02:00
301309737b Update readme for new version 2022-04-07 00:37:14 +02:00
ab46442108 Shortcut translation to French 2022-04-07 00:36:58 +02:00
3c1aad7d27 Merge branch 'shortcuts' 2022-04-07 00:02:40 +02:00
d1b6d97fe8 Working rebindable shortcuts 2022-04-07 00:01:55 +02:00
15db118dd6 Add GitHub link in Settings 2022-04-05 00:36:14 +02:00
67315f90b0 Fix RadioBrowser crashes if no internet connection 2022-04-05 00:23:55 +02:00
6d75f88927 Customisable shortcuts: first bulky implementation 2022-04-05 00:09:40 +02:00
7fdf349c28 Fix crash when the IP is invalid, also supports hostnames 2022-04-01 14:07:58 +02:00
9a5f686dde Fix exception on connection 2022-03-31 00:27:33 +02:00
b209cb2556 Update Snapcast: v0.25 to v0.26 2022-03-30 13:04:10 +02:00
6e1f43bed0 Switch to new MpcNET package 2022-03-30 02:05:13 +02:00
c93a9a326e Better working continuous shuffle 2021-10-07 22:14:09 +02:00
c055c59de7 Handle no response when querying stats 2021-10-07 22:13:18 +02:00
4c71d6a6e0 Rough working shuffle system 2021-10-06 22:54:55 +02:00
3685c369b4 Merge branch 'main' into shuffle 2021-10-05 19:20:00 +02:00
9bd088fac8 Stats translation and resources 2021-10-05 18:54:49 +02:00
e0d640532c Shuffle window (only visual) 2021-10-05 14:23:23 +02:00
0be28ab205 Stats panel in settings 2021-10-05 14:18:58 +02:00
34 changed files with 1652 additions and 244 deletions

View File

@ -37,7 +37,7 @@ namespace unison
{ {
_systray.Dispose(); _systray.Dispose();
_snapcast.LaunchOrExit(true); _snapcast.LaunchOrExit(true);
_hotkeys.RemoveHotKeys(); _hotkeys.RemoveHotkeys();
base.OnExit(e); base.OnExit(e);
} }
} }

View File

@ -15,21 +15,168 @@ namespace unison
private const int HOTKEY_ID = 9000; private const int HOTKEY_ID = 9000;
// modifiers public enum MOD : int
private const uint MOD_NONE = 0x0000; {
private const uint MOD_ALT = 0x0001; None = 0x0000,
private const uint MOD_CONTROL = 0x0002; Alt = 0x0001,
private const uint MOD_SHIFT = 0x0004; Control = 0x0002,
private const uint MOD_WIN = 0x0008; Shift = 0x0004,
//Win = 0x0008
};
// reference => https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes // reference => https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
private const uint VK_MEDIA_PREV_TRACK = 0xB1; public enum VK : int
private const uint VK_MEDIA_NEXT_TRACK = 0xB0; {
private const uint VK_MEDIA_PLAY_PAUSE = 0xB3; None = 0x00,
private const uint VK_VOLUME_UP = 0xAF; Back = 0x08,
private const uint VK_VOLUME_DOWN = 0xAE; Tab = 0x09,
private const uint VK_VOLUME_MUTE = 0xAD; Clear = 0x0c,
private const uint VK_ENTER = 0x0D; Return = 0x0d,
Menu = 0x12,
Pause = 0x13,
Capital = 0x14,
Kana = 0x15,
Hangul = 0x15,
Junja = 0x17,
Final = 0x18,
Hanja = 0x19,
Kanji = 0x19,
Escape = 0x1b,
Convert = 0x1c,
NonConvert = 0x1d,
Accept = 0x1e,
ModeChange = 0x1f,
Space = 0x20,
Prior = 0x21,
Next = 0x22,
End = 0x23,
Home = 0x24,
Left = 0x25,
Up = 0x26,
Right = 0x27,
Down = 0x28,
Select = 0x29,
Print = 0x2a,
Execute = 0x2b,
Snapshot = 0x2c,
Insert = 0x2d,
Delete = 0x2e,
Help = 0x2f,
NumRow0 = 0x30,
NumRow1 = 0x31,
NumRow2 = 0x32,
NumRow3 = 0x33,
NumRow4 = 0x34,
NumRow5 = 0x35,
NumRow6 = 0x36,
NumRow7 = 0x37,
NumRow8 = 0x38,
NumRow9 = 0x39,
A = 0x41,
B = 0x42,
C = 0x43,
D = 0x44,
E = 0x45,
F = 0x46,
G = 0x47,
H = 0x48,
I = 0x49,
J = 0x4a,
K = 0x4b,
L = 0x4c,
M = 0x4d,
N = 0x4e,
O = 0x4f,
P = 0x50,
Q = 0x51,
R = 0x52,
S = 0x53,
T = 0x54,
U = 0x55,
V = 0x56,
W = 0x57,
X = 0x58,
Y = 0x59,
Z = 0x5a,
Apps = 0x5d,
Sleep = 0x5f,
NumPad0 = 0x60,
NumPad1 = 0x61,
NumPad2 = 0x62,
NumPad3 = 0x63,
NumPad4 = 0x64,
NumPad5 = 0x65,
NumPad6 = 0x66,
NumPad7 = 0x67,
NumPad8 = 0x68,
NumPad9 = 0x69,
Multiply = 0x6a,
Add = 0x6b,
Separator = 0x6c,
Subtract = 0x6d,
Decimal = 0x6e,
Divide = 0x6f,
F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
F4 = 0x73,
F5 = 0x74,
F6 = 0x75,
F7 = 0x76,
F8 = 0x77,
F9 = 0x78,
F10 = 0x79,
F11 = 0x7a,
F12 = 0x7b,
F13 = 0x7c,
F14 = 0x7d,
F15 = 0x7e,
F16 = 0x7f,
F17 = 0x80,
F18 = 0x81,
F19 = 0x82,
F20 = 0x83,
F21 = 0x84,
F22 = 0x85,
F23 = 0x86,
F24 = 0x87,
NumLock = 0x90,
Scroll = 0x91,
LMenu = 0xa4,
RMenu = 0xa5,
BrowserBack = 0xa6,
BrowserForward = 0xa7,
BrowserRefresh = 0xa8,
BrowserStop = 0xa9,
BrowserSearch = 0xaa,
BrowserFavorites = 0xab,
BrowserHome = 0xac,
VolumeMute = 0xad,
VolumeDown = 0xae,
VolumeUp = 0xaf,
MediaNextTrack = 0xb0,
MediaPreviousTrack = 0xb1,
MediaStop = 0xb2,
MediaPlayPause = 0xb3,
LaunchMail = 0xb4,
LaunchMediaSelect = 0xb5,
LaunchApp1 = 0xb6,
LaunchApp2 = 0xb7,
};
public struct HotkeyPair
{
public MOD mod;
public VK vk;
public HotkeyPair(MOD _mod, VK _vk) { mod = _mod; vk = _vk; }
public uint GetMOD() { return (uint)mod; }
public uint GetVK() { return (uint)vk; }
public void SetMOD(MOD modmod) { mod = modmod; }
public void SetVK(VK vkvk) { vk = vkvk; }
}
private MainWindow _appWindow; private MainWindow _appWindow;
private readonly MPDHandler _mpd; private readonly MPDHandler _mpd;
@ -37,9 +184,31 @@ namespace unison
private IntPtr _windowHandle; private IntPtr _windowHandle;
private HwndSource _source; private HwndSource _source;
public HotkeyPair _NextTrack;
public HotkeyPair _PreviousTrack;
public HotkeyPair _PlayPause;
public HotkeyPair _VolumeUp;
public HotkeyPair _VolumeDown;
public HotkeyPair _VolumeMute;
public HotkeyPair _ShowWindow;
public HotkeyPair[] _Shortcuts;
public HotkeyHandler() public HotkeyHandler()
{ {
_mpd = (MPDHandler)Application.Current.Properties["mpd"]; _mpd = (MPDHandler)Application.Current.Properties["mpd"];
Initialize();
}
public void Initialize()
{
_NextTrack = new HotkeyPair((MOD)Properties.Settings.Default.nextTrack_mod, (VK)Properties.Settings.Default.nextTrack_vk);
_PreviousTrack = new HotkeyPair((MOD)Properties.Settings.Default.previousTrack_mod, (VK)Properties.Settings.Default.previousTrack_vk);
_PlayPause = new HotkeyPair((MOD)Properties.Settings.Default.playPause_mod, (VK)Properties.Settings.Default.playPause_vk);
_VolumeUp = new HotkeyPair((MOD)Properties.Settings.Default.volumeUp_mod, (VK)Properties.Settings.Default.volumeUp_vk);
_VolumeDown = new HotkeyPair((MOD)Properties.Settings.Default.volumeDown_mod, (VK)Properties.Settings.Default.volumeDown_vk);
_VolumeMute = new HotkeyPair((MOD)Properties.Settings.Default.volumeMute_mod, (VK)Properties.Settings.Default.volumeMute_vk);
_ShowWindow = new HotkeyPair((MOD)Properties.Settings.Default.showWindow_mod, (VK)Properties.Settings.Default.showWindow_vk);
_Shortcuts = new HotkeyPair[] { _NextTrack, _PreviousTrack, _PlayPause, _VolumeUp, _VolumeDown, _VolumeMute, _ShowWindow };
} }
public void Activate(Window win) public void Activate(Window win)
@ -48,18 +217,28 @@ namespace unison
{ {
_windowHandle = new WindowInteropHelper(win).Handle; _windowHandle = new WindowInteropHelper(win).Handle;
_source = HwndSource.FromHwnd(_windowHandle); _source = HwndSource.FromHwnd(_windowHandle);
_source.AddHook(HwndHook); AddHotkeys();
RegisterHotKey(_windowHandle, HOTKEY_ID, MOD_CONTROL, VK_MEDIA_PREV_TRACK);
RegisterHotKey(_windowHandle, HOTKEY_ID, MOD_CONTROL, VK_MEDIA_NEXT_TRACK);
RegisterHotKey(_windowHandle, HOTKEY_ID, MOD_CONTROL, VK_MEDIA_PLAY_PAUSE);
RegisterHotKey(_windowHandle, HOTKEY_ID, MOD_CONTROL, VK_VOLUME_UP);
RegisterHotKey(_windowHandle, HOTKEY_ID, MOD_CONTROL, VK_VOLUME_DOWN);
RegisterHotKey(_windowHandle, HOTKEY_ID, MOD_CONTROL, VK_VOLUME_MUTE);
RegisterHotKey(_windowHandle, HOTKEY_ID, MOD_CONTROL | MOD_ALT, VK_ENTER);
} }
} }
public void AddHotkeys()
{
_source.AddHook(HwndHook);
RegisterHotKey(_windowHandle, HOTKEY_ID, _NextTrack.GetMOD(), _NextTrack.GetVK());
RegisterHotKey(_windowHandle, HOTKEY_ID, _PreviousTrack.GetMOD(), _PreviousTrack.GetVK());
RegisterHotKey(_windowHandle, HOTKEY_ID, _PlayPause.GetMOD(), _PlayPause.GetVK());
RegisterHotKey(_windowHandle, HOTKEY_ID, _VolumeUp.GetMOD(), _VolumeUp.GetVK());
RegisterHotKey(_windowHandle, HOTKEY_ID, _VolumeDown.GetMOD(), _VolumeDown.GetVK());
RegisterHotKey(_windowHandle, HOTKEY_ID, _VolumeMute.GetMOD(), _VolumeMute.GetVK());
RegisterHotKey(_windowHandle, HOTKEY_ID, _ShowWindow.GetMOD(), _ShowWindow.GetVK());
}
public void RemoveHotkeys()
{
_source.RemoveHook(HwndHook);
UnregisterHotKey(_windowHandle, HOTKEY_ID);
}
private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{ {
const int WM_HOTKEY = 0x0312; const int WM_HOTKEY = 0x0312;
@ -67,27 +246,21 @@ namespace unison
if (msg == WM_HOTKEY && wParam.ToInt32() == HOTKEY_ID) if (msg == WM_HOTKEY && wParam.ToInt32() == HOTKEY_ID)
{ {
uint vkey = ((uint)lParam >> 16) & 0xFFFF; uint vkey = ((uint)lParam >> 16) & 0xFFFF;
switch (vkey)
{ if (vkey == _NextTrack.GetVK())
case VK_MEDIA_NEXT_TRACK:
_mpd.Next(); _mpd.Next();
break; else if (vkey == _PreviousTrack.GetVK())
case VK_MEDIA_PREV_TRACK:
_mpd.Prev(); _mpd.Prev();
break; else if (vkey == _PlayPause.GetVK())
case VK_VOLUME_DOWN:
_mpd.VolumeDown();
break;
case VK_VOLUME_UP:
_mpd.VolumeUp();
break;
case VK_VOLUME_MUTE:
_mpd.VolumeMute();
break;
case VK_MEDIA_PLAY_PAUSE:
_mpd.PlayPause(); _mpd.PlayPause();
break; else if (vkey == _VolumeUp.GetVK())
case VK_ENTER: _mpd.VolumeUp();
else if (vkey == _VolumeDown.GetVK())
_mpd.VolumeDown();
else if (vkey == _VolumeMute.GetVK())
_mpd.VolumeMute();
else if (vkey == _ShowWindow.GetVK())
{
if (_appWindow == null) if (_appWindow == null)
_appWindow = (MainWindow)Application.Current.MainWindow; _appWindow = (MainWindow)Application.Current.MainWindow;
@ -111,17 +284,10 @@ namespace unison
_appWindow.WindowState = WindowState.Normal; _appWindow.WindowState = WindowState.Normal;
} }
} }
break;
} }
handled = true; handled = true;
} }
return IntPtr.Zero; return IntPtr.Zero;
} }
public void RemoveHotKeys()
{
_source.RemoveHook(HwndHook);
UnregisterHotKey(_windowHandle, HOTKEY_ID);
}
} }
} }

View File

@ -20,6 +20,17 @@ using MpcNET.Types;
namespace unison namespace unison
{ {
public class Statistics
{
public int Songs { get; set; }
public int Albums { get; set; }
public int Artists { get; set; }
public string TotalPlaytime { get; set; }
public string Uptime { get; set; }
public string TotalTimePlayed { get; set; }
public string DatabaseUpdate { get; set; }
}
public class MPDHandler public class MPDHandler
{ {
private bool _connected; private bool _connected;
@ -36,12 +47,15 @@ namespace unison
private MpdStatus _currentStatus; private MpdStatus _currentStatus;
private IMpdFile _currentSong; private IMpdFile _currentSong;
private BitmapFrame _cover; private BitmapFrame _cover;
public Statistics _stats;
private readonly System.Timers.Timer _elapsedTimer; private readonly System.Timers.Timer _elapsedTimer;
private DispatcherTimer _retryTimer; private DispatcherTimer _retryTimer;
bool _isUpdatingStatus = false; bool _isUpdatingStatus = false;
bool _isUpdatingSong = false; bool _isUpdatingSong = false;
bool _invalidIp = false;
private event EventHandler ConnectionChanged; private event EventHandler ConnectionChanged;
private event EventHandler StatusChanged; private event EventHandler StatusChanged;
private event EventHandler SongChanged; private event EventHandler SongChanged;
@ -58,6 +72,8 @@ namespace unison
Initialize(null, null); Initialize(null, null);
_stats = new Statistics();
_retryTimer = new DispatcherTimer(); _retryTimer = new DispatcherTimer();
_retryTimer.Interval = TimeSpan.FromSeconds(5); _retryTimer.Interval = TimeSpan.FromSeconds(5);
_retryTimer.Tick += Initialize; _retryTimer.Tick += Initialize;
@ -81,7 +97,7 @@ namespace unison
void OnConnectionChanged(object sender, EventArgs e) void OnConnectionChanged(object sender, EventArgs e)
{ {
if (!_connected) if (!_connected && !_invalidIp)
_retryTimer.Start(); _retryTimer.Start();
else else
_retryTimer.Stop(); _retryTimer.Stop();
@ -175,12 +191,13 @@ namespace unison
_connection = await ConnectInternal(token); _connection = await ConnectInternal(token);
_commandConnection = await ConnectInternal(token); _commandConnection = await ConnectInternal(token);
} }
catch(MpcNET.Exceptions.MpcConnectException exception) catch(MpcNET.Exceptions.MpcConnectException)
{ {
Trace.WriteLine("exception: " + exception); _invalidIp = true;
} }
if (_connection != null && _commandConnection != null) if (_connection != null && _commandConnection != null)
{ {
_invalidIp = false;
if (_connection.IsConnected && _commandConnection.IsConnected) if (_connection.IsConnected && _commandConnection.IsConnected)
{ {
_connected = true; _connected = true;
@ -204,6 +221,21 @@ namespace unison
{ {
IPAddress.TryParse(Properties.Settings.Default.mpd_host, out IPAddress ipAddress); IPAddress.TryParse(Properties.Settings.Default.mpd_host, out IPAddress ipAddress);
if (ipAddress == null)
{
IPAddress[] addrList;
try
{
addrList = Dns.GetHostAddresses(Properties.Settings.Default.mpd_host);
if (addrList.Length > 0)
ipAddress = addrList[0];
}
catch (Exception)
{
throw new MpcNET.Exceptions.MpcConnectException("No correct IP provided by user.");
}
}
_mpdEndpoint = new IPEndPoint(ipAddress, Properties.Settings.Default.mpd_port); _mpdEndpoint = new IPEndPoint(ipAddress, Properties.Settings.Default.mpd_port);
MpcConnection connection = new MpcConnection(_mpdEndpoint); MpcConnection connection = new MpcConnection(_mpdEndpoint);
await connection.ConnectAsync(token); await connection.ConnectAsync(token);
@ -334,14 +366,14 @@ namespace unison
List<byte> data = new List<byte>(); List<byte> data = new List<byte>();
try try
{ {
if (_connection == null)
return;
long totalBinarySize = 9999; long totalBinarySize = 9999;
long currentSize = 0; long currentSize = 0;
do do
{ {
if (_connection == null)
return;
var albumReq = await _connection.SendAsync(new AlbumArtCommand(path, currentSize)); var albumReq = await _connection.SendAsync(new AlbumArtCommand(path, currentSize));
if (!albumReq.IsResponseValid) if (!albumReq.IsResponseValid)
break; break;
@ -417,6 +449,7 @@ namespace unison
public MpdStatus GetStatus() => _currentStatus; public MpdStatus GetStatus() => _currentStatus;
public BitmapFrame GetCover() => _cover; public BitmapFrame GetCover() => _cover;
public string GetVersion() => _version; public string GetVersion() => _version;
public Statistics GetStats() => _stats;
public double GetCurrentTime() => _currentTime; public double GetCurrentTime() => _currentTime;
public bool IsConnected() => _connected; public bool IsConnected() => _connected;
@ -479,5 +512,27 @@ namespace unison
CommandList commandList = new CommandList(new IMpcCommand<object>[] { new ClearCommand(), new AddCommand(Uri), new PlayCommand(0) }); CommandList commandList = new CommandList(new IMpcCommand<object>[] { new ClearCommand(), new AddCommand(Uri), new PlayCommand(0) });
SendCommand(commandList); SendCommand(commandList);
} }
public async void QueryStats()
{
Dictionary<string, string> Response = await SafelySendCommandAsync(new StatsCommand());
if (Response == null)
return;
_stats.Songs = int.Parse(Response["songs"]);
_stats.Albums = int.Parse(Response["albums"]);
_stats.Artists = int.Parse(Response["artists"]);
TimeSpan time;
time = TimeSpan.FromSeconds(int.Parse(Response["uptime"]));
_stats.Uptime = time.ToString(@"dd\:hh\:mm\:ss");
time = TimeSpan.FromSeconds(int.Parse(Response["db_playtime"]));
_stats.TotalPlaytime = time.ToString(@"dd\:hh\:mm\:ss");
time = TimeSpan.FromSeconds(int.Parse(Response["playtime"]));
_stats.TotalTimePlayed = time.ToString(@"dd\:hh\:mm\:ss");
DateTime date = new DateTime(1970, 1, 1).AddSeconds(int.Parse(Response["db_update"])).ToLocalTime();
_stats.DatabaseUpdate = date.ToString("dd/MM/yyyy @ HH:mm");
}
} }
} }

View File

@ -1,4 +1,4 @@
MIT License Copyright (c) 2021 Théo Marchal MIT License Copyright (c) 2022 Théo Marchal
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -73,7 +73,19 @@ namespace unison.Properties {
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("snapclient_0.25.0-1_win64")] [global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool snapcast_window {
get {
return ((bool)(this["snapcast_window"]));
}
set {
this["snapcast_window"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("snapclient_0.26.0-1_win64")]
public string snapcast_path { public string snapcast_path {
get { get {
return ((string)(this["snapcast_path"])); return ((string)(this["snapcast_path"]));
@ -109,13 +121,169 @@ namespace unison.Properties {
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")] [global::System.Configuration.DefaultSettingValueAttribute("2")]
public bool snapcast_window { public uint nextTrack_mod {
get { get {
return ((bool)(this["snapcast_window"])); return ((uint)(this["nextTrack_mod"]));
} }
set { set {
this["snapcast_window"] = value; this["nextTrack_mod"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("176")]
public uint nextTrack_vk {
get {
return ((uint)(this["nextTrack_vk"]));
}
set {
this["nextTrack_vk"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("2")]
public uint previousTrack_mod {
get {
return ((uint)(this["previousTrack_mod"]));
}
set {
this["previousTrack_mod"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("177")]
public uint previousTrack_vk {
get {
return ((uint)(this["previousTrack_vk"]));
}
set {
this["previousTrack_vk"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("2")]
public uint playPause_mod {
get {
return ((uint)(this["playPause_mod"]));
}
set {
this["playPause_mod"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("179")]
public uint playPause_vk {
get {
return ((uint)(this["playPause_vk"]));
}
set {
this["playPause_vk"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("2")]
public uint volumeUp_mod {
get {
return ((uint)(this["volumeUp_mod"]));
}
set {
this["volumeUp_mod"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("175")]
public uint volumeUp_vk {
get {
return ((uint)(this["volumeUp_vk"]));
}
set {
this["volumeUp_vk"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("2")]
public uint volumeDown_mod {
get {
return ((uint)(this["volumeDown_mod"]));
}
set {
this["volumeDown_mod"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("174")]
public uint volumeDown_vk {
get {
return ((uint)(this["volumeDown_vk"]));
}
set {
this["volumeDown_vk"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("2")]
public uint volumeMute_mod {
get {
return ((uint)(this["volumeMute_mod"]));
}
set {
this["volumeMute_mod"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("173")]
public uint volumeMute_vk {
get {
return ((uint)(this["volumeMute_vk"]));
}
set {
this["volumeMute_vk"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("3")]
public uint showWindow_mod {
get {
return ((uint)(this["showWindow_mod"]));
}
set {
this["showWindow_mod"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("13")]
public uint showWindow_vk {
get {
return ((uint)(this["showWindow_vk"]));
}
set {
this["showWindow_vk"] = value;
} }
} }
} }

View File

@ -18,7 +18,7 @@
<Value Profile="(Default)">False</Value> <Value Profile="(Default)">False</Value>
</Setting> </Setting>
<Setting Name="snapcast_path" Type="System.String" Scope="User"> <Setting Name="snapcast_path" Type="System.String" Scope="User">
<Value Profile="(Default)">snapclient_0.25.0-1_win64</Value> <Value Profile="(Default)">snapclient_0.26.0-1_win64</Value>
</Setting> </Setting>
<Setting Name="snapcast_port" Type="System.Int32" Scope="User"> <Setting Name="snapcast_port" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1704</Value> <Value Profile="(Default)">1704</Value>
@ -26,5 +26,47 @@
<Setting Name="volume_offset" Type="System.Int32" Scope="User"> <Setting Name="volume_offset" Type="System.Int32" Scope="User">
<Value Profile="(Default)">5</Value> <Value Profile="(Default)">5</Value>
</Setting> </Setting>
<Setting Name="nextTrack_mod" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="nextTrack_vk" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">176</Value>
</Setting>
<Setting Name="previousTrack_mod" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="previousTrack_vk" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">177</Value>
</Setting>
<Setting Name="playPause_mod" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="playPause_vk" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">179</Value>
</Setting>
<Setting Name="volumeUp_mod" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="volumeUp_vk" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">175</Value>
</Setting>
<Setting Name="volumeDown_mod" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="volumeDown_vk" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">174</Value>
</Setting>
<Setting Name="volumeMute_mod" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="volumeMute_vk" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">173</Value>
</Setting>
<Setting Name="showWindow_mod" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">3</Value>
</Setting>
<Setting Name="showWindow_vk" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">13</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@ -5,7 +5,7 @@
**unison** is a very simple [Music Player Daemon (MPD)](https://www.musicpd.org/) daemon client with the following goals: **unison** is a very simple [Music Player Daemon (MPD)](https://www.musicpd.org/) daemon client with the following goals:
* lightweight window that can be toggled with shortcuts * lightweight window that can be toggled with shortcuts
* music control through shortcuts * music control through rebindable shortcuts
* [Snapcast](https://mjaggard.github.io/snapcast/) integration * [Snapcast](https://mjaggard.github.io/snapcast/) integration
* Radio stations * Radio stations
@ -19,17 +19,17 @@ By default, unison works as a daemon in the taskbar system tray. You can display
### Shortcuts ### Shortcuts
You can control your music at anytime with the shortcuts. They can of course be used if the window is not visible. You can control your music at anytime with the shortcuts. They are usable system-wide, even if the window is not visible. They are of course fully rebindable.
![Settings => shortcuts](Screenshots/screen3.png) ![Settings => shortcuts](Screenshots/screen3.png)
### Snapcast ### Snapcast
The main goal of embedding Snapcast is the ability to listen locally to music when I'm not using my main audio system. The computer running unison can then play music easily. Embedding a Snapcast client allows to listen to music on multiple devices. For example, if you music is on a distant server connected to speakers in your living room, you can still listen to it on your computer running unison with this integrated client.
### Radio stations ### Radio stations
Through [Radio-Browser](https://www.radio-browser.info), a community database, you can play radio-streams directly from unison. There are more than 28,000 stations recorded on this service, so it should be a nice way to discover new music and cultures. Through [Radio-Browser](https://www.radio-browser.info), a community database, you can play radio streams directly from unison. There are more than 28,000 stations recorded on this service, so it is a nice way to discover new music and cultures.
![Radio stations](Screenshots/screen4.png) ![Radio stations](Screenshots/screen4.png)
@ -37,13 +37,12 @@ Through [Radio-Browser](https://www.radio-browser.info), a community database, y
### Missing features ### Missing features
* Custom shortcuts.
* MPD passwords: I don't really see the point, but if asked, I will integrate them. * MPD passwords: I don't really see the point, but if asked, I will integrate them.
* Any sort of playlist and queue management. I use other software to do it, but I might implement them at some point.
### Wanted features ### Planned features
* A complete shuffle system based on set criteria, aka a smart playlist. * A complete shuffle system based on set criteria, aka a smart playlist.
* Playlist, queue and library management. I use other software to do it, but I will implement them at some point.
## Translations ## Translations

View File

@ -249,15 +249,6 @@ namespace unison.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to &apos;s updated MpcNET.
/// </summary>
public static string Settings_MpcNET {
get {
return ResourceManager.GetString("Settings_MpcNET", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Next track. /// Looks up a localized string similar to Next track.
/// </summary> /// </summary>
@ -303,6 +294,24 @@ namespace unison.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Please note that if the input key is not recognized, this is due to a limitation on how virtual keys work..
/// </summary>
public static string Settings_ShortcutsInfo {
get {
return ResourceManager.GetString("Settings_ShortcutsInfo", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enter a key....
/// </summary>
public static string Settings_ShortcutsKey {
get {
return ResourceManager.GetString("Settings_ShortcutsKey", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Show window. /// Looks up a localized string similar to Show window.
/// </summary> /// </summary>
@ -501,6 +510,78 @@ namespace unison.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Stats.
/// </summary>
public static string Stats {
get {
return ResourceManager.GetString("Stats", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Albums:.
/// </summary>
public static string Stats_Albums {
get {
return ResourceManager.GetString("Stats_Albums", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Artists:.
/// </summary>
public static string Stats_Artists {
get {
return ResourceManager.GetString("Stats_Artists", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Last database update:.
/// </summary>
public static string Stats_LastDatabaseUpdate {
get {
return ResourceManager.GetString("Stats_LastDatabaseUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Songs:.
/// </summary>
public static string Stats_Songs {
get {
return ResourceManager.GetString("Stats_Songs", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Total playtime:.
/// </summary>
public static string Stats_TotalPlaytime {
get {
return ResourceManager.GetString("Stats_TotalPlaytime", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Total time played:.
/// </summary>
public static string Stats_TotalTimePlayed {
get {
return ResourceManager.GetString("Stats_TotalTimePlayed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to MPD uptime:.
/// </summary>
public static string Stats_Uptime {
get {
return ResourceManager.GetString("Stats_Uptime", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Stop Snapcast. /// Looks up a localized string similar to Stop Snapcast.
/// </summary> /// </summary>

View File

@ -180,9 +180,6 @@
<data name="Settings_MadeBy" xml:space="preserve"> <data name="Settings_MadeBy" xml:space="preserve">
<value>Créé par</value> <value>Créé par</value>
</data> </data>
<data name="Settings_MpcNET" xml:space="preserve">
<value> et sa version de MpcNET</value>
</data>
<data name="Settings_NextTrack" xml:space="preserve"> <data name="Settings_NextTrack" xml:space="preserve">
<value>Piste suivante</value> <value>Piste suivante</value>
</data> </data>
@ -198,6 +195,12 @@
<data name="Settings_Shortcuts" xml:space="preserve"> <data name="Settings_Shortcuts" xml:space="preserve">
<value>Raccourcis</value> <value>Raccourcis</value>
</data> </data>
<data name="Settings_ShortcutsInfo" xml:space="preserve">
<value>Veuillez noter que si votre touche n'est pas reconnue, cela est du à la manière dont les touches virtuelles sont gérées par Windows.</value>
</data>
<data name="Settings_ShortcutsKey" xml:space="preserve">
<value>Appuyez sur une touche...</value>
</data>
<data name="Settings_ShowWindow" xml:space="preserve"> <data name="Settings_ShowWindow" xml:space="preserve">
<value>Afficher la fenêtre</value> <value>Afficher la fenêtre</value>
</data> </data>
@ -264,6 +267,30 @@
<data name="StartSnapcast" xml:space="preserve"> <data name="StartSnapcast" xml:space="preserve">
<value>Démarrer Snapcast</value> <value>Démarrer Snapcast</value>
</data> </data>
<data name="Stats" xml:space="preserve">
<value>Stats</value>
</data>
<data name="Stats_Albums" xml:space="preserve">
<value>Albums :</value>
</data>
<data name="Stats_Artists" xml:space="preserve">
<value>Artistes :</value>
</data>
<data name="Stats_LastDatabaseUpdate" xml:space="preserve">
<value>Mise à jour de la base de données :</value>
</data>
<data name="Stats_Songs" xml:space="preserve">
<value>Morceaux :</value>
</data>
<data name="Stats_TotalPlaytime" xml:space="preserve">
<value>Temps total :</value>
</data>
<data name="Stats_TotalTimePlayed" xml:space="preserve">
<value>Temps d'écoute écoulé :</value>
</data>
<data name="Stats_Uptime" xml:space="preserve">
<value>MPD lancé depuis : </value>
</data>
<data name="StopSnapcast" xml:space="preserve"> <data name="StopSnapcast" xml:space="preserve">
<value>Stopper Snapcast</value> <value>Stopper Snapcast</value>
</data> </data>

View File

@ -180,9 +180,6 @@
<data name="Settings_MadeBy" xml:space="preserve"> <data name="Settings_MadeBy" xml:space="preserve">
<value>Made by</value> <value>Made by</value>
</data> </data>
<data name="Settings_MpcNET" xml:space="preserve">
<value>'s updated MpcNET</value>
</data>
<data name="Settings_NextTrack" xml:space="preserve"> <data name="Settings_NextTrack" xml:space="preserve">
<value>Next track</value> <value>Next track</value>
</data> </data>
@ -198,6 +195,12 @@
<data name="Settings_Shortcuts" xml:space="preserve"> <data name="Settings_Shortcuts" xml:space="preserve">
<value>Shortcuts</value> <value>Shortcuts</value>
</data> </data>
<data name="Settings_ShortcutsInfo" xml:space="preserve">
<value>Please note that if the input key is not recognized, this is due to a limitation on how virtual keys work.</value>
</data>
<data name="Settings_ShortcutsKey" xml:space="preserve">
<value>Enter a key...</value>
</data>
<data name="Settings_ShowWindow" xml:space="preserve"> <data name="Settings_ShowWindow" xml:space="preserve">
<value>Show window</value> <value>Show window</value>
</data> </data>
@ -264,6 +267,30 @@
<data name="StartSnapcast" xml:space="preserve"> <data name="StartSnapcast" xml:space="preserve">
<value>Start Snapcast</value> <value>Start Snapcast</value>
</data> </data>
<data name="Stats" xml:space="preserve">
<value>Stats</value>
</data>
<data name="Stats_Albums" xml:space="preserve">
<value>Albums:</value>
</data>
<data name="Stats_Artists" xml:space="preserve">
<value>Artists:</value>
</data>
<data name="Stats_LastDatabaseUpdate" xml:space="preserve">
<value>Last database update:</value>
</data>
<data name="Stats_Songs" xml:space="preserve">
<value>Songs:</value>
</data>
<data name="Stats_TotalPlaytime" xml:space="preserve">
<value>Total playtime:</value>
</data>
<data name="Stats_TotalTimePlayed" xml:space="preserve">
<value>Total time played:</value>
</data>
<data name="Stats_Uptime" xml:space="preserve">
<value>MPD uptime:</value>
</data>
<data name="StopSnapcast" xml:space="preserve"> <data name="StopSnapcast" xml:space="preserve">
<value>Stop Snapcast</value> <value>Stop Snapcast</value>
</data> </data>

View File

@ -1,15 +1,28 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"> xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:sys="clr-namespace:System;assembly=System.Runtime">
<system:String x:Key="snapcastPath">snapclient_0.25.0-1_win64</system:String> <system:String x:Key="snapcastPath">snapclient_0.26.0-1_win64</system:String>
<system:String x:Key="snapcastPort">1704</system:String> <system:String x:Key="snapcastPort">1704</system:String>
<system:String x:Key="connectionOk1">&#xf385;</system:String>
<system:String x:Key="connectionOk2">&#xf386;</system:String>
<system:String x:Key="connectionFail">&#xf384;</system:String>
<system:String x:Key="playButton">&#xedb4;</system:String> <system:String x:Key="playButton">&#xedb4;</system:String>
<system:String x:Key="pauseButton">&#xedb5;</system:String> <system:String x:Key="pauseButton">&#xedb5;</system:String>
<system:String x:Key="volume_offset">5</system:String>
<system:UInt32 x:Key="nextTrack_mod">2</system:UInt32>
<system:UInt32 x:Key="nextTrack_vk">176</system:UInt32>
<system:UInt32 x:Key="previousTrack_mod">2</system:UInt32>
<system:UInt32 x:Key="previousTrack_vk">177</system:UInt32>
<system:UInt32 x:Key="playPause_mod">2</system:UInt32>
<system:UInt32 x:Key="playPause_vk">179</system:UInt32>
<system:UInt32 x:Key="volumeUp_mod">2</system:UInt32>
<system:UInt32 x:Key="volumeUp_vk">175</system:UInt32>
<system:UInt32 x:Key="volumeDown_mod">2</system:UInt32>
<system:UInt32 x:Key="volumeDown_vk">174</system:UInt32>
<system:UInt32 x:Key="volumeMute_mod">2</system:UInt32>
<system:UInt32 x:Key="volumeMute_vk">173</system:UInt32>
<system:UInt32 x:Key="showWindow_mod">3</system:UInt32>
<system:UInt32 x:Key="showWindow_vk">13</system:UInt32>
</ResourceDictionary> </ResourceDictionary>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -110,14 +110,15 @@
</Border> </Border>
</Grid> </Grid>
<Grid x:Name="BottomLayout" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" Width="Auto" MinHeight="40"> <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"> <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" Margin="10,0,0,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"> <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"> <StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="🔊" Padding="0,0,0,2"/> <emoji:TextBlock Text="🔁" Padding="0,0,0,2"/>
<TextBlock x:Name="SnapcastText" Text="{x:Static properties:Resources.StartSnapcast}" Margin="5, 0, 0, 0"/> <TextBlock Text="Shuffle" Margin="5, 0, 0, 0"/>
</StackPanel> </StackPanel>
</Button> </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}">
<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"> <StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="📻" Padding="0,0,0,2"/> <emoji:TextBlock Text="📻" Padding="0,0,0,2"/>
<TextBlock Text="{x:Static properties:Resources.Radios}" Margin="5, 0, 0, 0"/> <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" /> <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>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,10,0"> <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,10,0">
<!--<Button x:Name="Shuffle" Padding="5, 2" HorizontalAlignment="Right" Margin="0,0,10,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"> <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"> <StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="🔁" Padding="0,0,0,2"/> <emoji:TextBlock Text="🔊" Padding="0,0,0,2"/>
<TextBlock Text="Shuffle" Margin="5, 0, 0, 0"/> <TextBlock x:Name="SnapcastText" Text="{x:Static properties:Resources.StartSnapcast}" Margin="5, 0, 0, 0"/>
</StackPanel> </StackPanel>
</Button>--> </Button>
<Button x:Name="Settings" Padding="5, 2" Click="Settings_Clicked" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}"> <Button x:Name="Settings" Padding="5, 2" Click="Settings_Clicked" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="🛠️" Padding="0,0,0,2"/> <emoji:TextBlock Text="🛠️" Padding="0,0,0,2"/>

View File

@ -6,6 +6,8 @@ using System.Windows.Threading;
using System.Windows.Interop; using System.Windows.Interop;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using MpcNET.Commands.Queue;
using System.Diagnostics;
namespace unison namespace unison
{ {
@ -13,6 +15,7 @@ namespace unison
{ {
private readonly Settings _settingsWin; private readonly Settings _settingsWin;
private readonly Radios _radiosWin; private readonly Radios _radiosWin;
private readonly Shuffle _shuffleWin;
private readonly DispatcherTimer _timer; private readonly DispatcherTimer _timer;
private readonly MPDHandler _mpd; private readonly MPDHandler _mpd;
@ -25,6 +28,7 @@ namespace unison
_settingsWin = new Settings(); _settingsWin = new Settings();
_radiosWin = new Radios(); _radiosWin = new Radios();
_shuffleWin = new Shuffle();
_timer = new DispatcherTimer(); _timer = new DispatcherTimer();
_mpd = (MPDHandler)Application.Current.Properties["mpd"]; _mpd = (MPDHandler)Application.Current.Properties["mpd"];
@ -49,6 +53,9 @@ namespace unison
Snapcast.IsEnabled = true; Snapcast.IsEnabled = true;
ConnectionOkIcon.Visibility = Visibility.Visible; ConnectionOkIcon.Visibility = Visibility.Visible;
ConnectionFailIcon.Visibility = Visibility.Collapsed; ConnectionFailIcon.Visibility = Visibility.Collapsed;
_shuffleWin.ListGenre();
_shuffleWin.ListFolder();
} }
else else
{ {
@ -61,7 +68,7 @@ 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}";
} }
public void OnSongChanged(object sender, EventArgs e) public async void OnSongChanged(object sender, EventArgs e)
{ {
if (_mpd.GetCurrentSong() == null) if (_mpd.GetCurrentSong() == null)
return; return;
@ -107,6 +114,32 @@ namespace unison
_timer.Start(); _timer.Start();
EndTime.Text = FormatSeconds(_mpd.GetCurrentSong().Time); EndTime.Text = FormatSeconds(_mpd.GetCurrentSong().Time);
} }
Debug.WriteLine("Song changed called!");
// handle continuous shuffle
if (_shuffleWin.GetContinuous())
{
System.Collections.Generic.IEnumerable<MpcNET.Types.IMpdFile> a = await _mpd.SafelySendCommandAsync(new PlaylistCommand());
int queueSize = 0;
foreach (var i in a)
{
Debug.WriteLine(i.Path);
queueSize++;
}
Debug.WriteLine("queue size is: " + queueSize);
if (queueSize < 5)
{
_shuffleWin.AddContinuousSongs();
}
// query queue
// if (queue.SongRemaining < 5)
//{
// // query shuffle songs
//}
}
} }
public void OnStatusChanged(object sender, EventArgs e) public void OnStatusChanged(object sender, EventArgs e)
@ -135,6 +168,9 @@ namespace unison
DefaultState(); DefaultState();
} }
} }
_mpd.QueryStats();
_settingsWin.UpdateStats();
} }
private void DefaultState(bool LostConnection = false) private void DefaultState(bool LostConnection = false)
@ -185,6 +221,11 @@ namespace unison
SnapcastText.Text = unison.Resources.Resources.StartSnapcast; SnapcastText.Text = unison.Resources.Resources.StartSnapcast;
} }
public void OnRadioBrowserConnected()
{
Radio.IsEnabled = true;
}
public void UpdateButton(ref Border border, bool b) public void UpdateButton(ref Border border, bool b)
{ {
border.Style = b ? (Style)Resources["SelectedButton"] : (Style)Resources["UnselectedButton"]; border.Style = b ? (Style)Resources["SelectedButton"] : (Style)Resources["UnselectedButton"];
@ -226,6 +267,15 @@ namespace unison
_radiosWin.WindowState = WindowState.Normal; _radiosWin.WindowState = WindowState.Normal;
} }
public void Shuffle_Clicked(object sender, RoutedEventArgs e)
{
_shuffleWin.Show();
_shuffleWin.Activate();
if (_shuffleWin.WindowState == WindowState.Minimized)
_shuffleWin.WindowState = WindowState.Normal;
}
public void Settings_Clicked(object sender, RoutedEventArgs e) public void Settings_Clicked(object sender, RoutedEventArgs e)
{ {
_settingsWin.Show(); _settingsWin.Show();

View File

@ -59,9 +59,22 @@ namespace unison
{ {
InitializeComponent(); InitializeComponent();
try
{
_radioBrowser = new RadioBrowserClient(); _radioBrowser = new RadioBrowserClient();
Initialize(); Initialize();
} }
catch (Exception e)
{
Debug.WriteLine("Exception while connecting to RadioBrowser: " + e.Message);
return;
}
Application.Current.Dispatcher.Invoke(() =>
{
MainWindow MainWin = (MainWindow)Application.Current.MainWindow;
MainWin.OnRadioBrowserConnected();
});
}
public async void Initialize() public async void Initialize()
{ {
@ -84,6 +97,8 @@ namespace unison
} }
public async Task SearchAdvanced(string name, string country, string tags) public async Task SearchAdvanced(string name, string country, string tags)
{
try
{ {
SearchStatus.Text = unison.Resources.Resources.Radio_Loading; SearchStatus.Text = unison.Resources.Resources.Radio_Loading;
@ -115,6 +130,11 @@ namespace unison
else else
SearchStatus.Text = unison.Resources.Resources.Radio_NotFound; SearchStatus.Text = unison.Resources.Resources.Radio_NotFound;
} }
catch (Exception except)
{
Debug.WriteLine("Error on RadioBrowser search advanced: " + except.Message);
}
}
private void FitToContent() private void FitToContent()
{ {
@ -147,10 +167,17 @@ namespace unison
} }
private async void Search_Clicked(object sender, RoutedEventArgs e) private async void Search_Clicked(object sender, RoutedEventArgs e)
{
try
{ {
CountryListItem a = (CountryListItem)CountryList.SelectedItem; CountryListItem a = (CountryListItem)CountryList.SelectedItem;
await SearchAdvanced(NameSearch.Text, a?.Name, TagSearch.Text); await SearchAdvanced(NameSearch.Text, a?.Name, TagSearch.Text);
} }
catch (Exception except)
{
Debug.WriteLine("Error on RadioBrowser search: " + except.Message);
}
}
private void Reset_Clicked(object sender, RoutedEventArgs e) private void Reset_Clicked(object sender, RoutedEventArgs e)
{ {

View File

@ -4,9 +4,19 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf" xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
xmlns:properties="clr-namespace:unison.Resources" xmlns:properties="clr-namespace:unison.Resources" xmlns:sys="clr-namespace:System;assembly=System.Runtime"
mc:Ignorable="d" mc:Ignorable="d"
Closing="Window_Closing" Title="{x:Static properties:Resources.Settings}" ResizeMode="CanMinimize" Icon="/Resources/icon-full.ico" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight"> Closing="Window_Closing" Title="{x:Static properties:Resources.Settings}" ResizeMode="CanMinimize" Icon="/Resources/icon-full.ico" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
<Window.Resources>
<x:Array x:Key="ShortcutItems" Type="sys:String">
<sys:String>None</sys:String>
<sys:String>Alt</sys:String>
<sys:String>Control</sys:String>
<sys:String>Shift</sys:String>
</x:Array>
</Window.Resources>
<Grid> <Grid>
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<TabControl Margin="10"> <TabControl Margin="10">
@ -14,12 +24,10 @@
<DockPanel Margin="8"> <DockPanel Margin="8">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0"> <GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
<GroupBox.Header> <GroupBox.Header>
<StackPanel Orientation="Horizontal">
<TextBlock> <TextBlock>
<emoji:EmojiInline Text="📶"/> <emoji:EmojiInline Text="📶"/>
<Run Text="{x:Static properties:Resources.Settings_Connection}"/> <Run Text="{x:Static properties:Resources.Settings_Connection}"/>
</TextBlock> </TextBlock>
</StackPanel>
</GroupBox.Header> </GroupBox.Header>
<Grid VerticalAlignment="Top"> <Grid VerticalAlignment="Top">
<StackPanel> <StackPanel>
@ -46,13 +54,118 @@
</DockPanel> </DockPanel>
</TabItem> </TabItem>
<TabItem Header="{x:Static properties:Resources.Settings_Shortcuts}">
<DockPanel Margin="8">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
<GroupBox.Header>
<TextBlock>
<emoji:EmojiInline Text="⌨️ "/>
<Run Text="{x:Static properties:Resources.Settings_Shortcuts}"></Run>
</TextBlock>
</GroupBox.Header>
<Grid>
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeOffset}" TextWrapping="Wrap" Margin="0,2,0,0"/>
<TextBox x:Name="VolumeOffset" TextWrapping="Wrap" Width="25" PreviewTextInput="NumberValidationTextBox" Margin="8,2,0,0"/>
</StackPanel>
<Grid Margin="0,5,0,0" x:Name="RebindKeyWrapper">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{x:Static properties:Resources.Settings_NextTrack}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="0" Margin="1,1,1,1" Grid.RowSpan="2"/>
<TextBlock Text="{x:Static properties:Resources.Settings_PreviousTrack}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="2" Margin="1,1,1,1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_PlayPause}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="3" Margin="1,1,1,1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeUp}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="4" Margin="1,1,1,1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeDown}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="5" Margin="1,1,1,1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeMute}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="6" Margin="1,1,1,1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_ShowWindow}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="7" Margin="1,1,1,1"/>
<StackPanel x:Name="Shortcut_NextTrack" Orientation="Horizontal" Grid.Column="1" Grid.Row="0" Margin="10,0,0,2" Grid.RowSpan="2">
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
</Button>
</StackPanel>
<StackPanel x:Name="Shortcut_PreviousTrack" Orientation="Horizontal" Grid.Column="1" Grid.Row="2" Margin="10,0,0,2">
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
</Button>
</StackPanel>
<StackPanel x:Name="Shortcut_PlayPause" Orientation="Horizontal" Grid.Column="1" Grid.Row="3" Margin="10,0,0,2">
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
</Button>
</StackPanel>
<StackPanel x:Name="Shortcut_VolumeUp" Orientation="Horizontal" Grid.Column="1" Grid.Row="4" Margin="10,0,0,2">
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
</Button>
</StackPanel>
<StackPanel x:Name="Shortcut_VolumeDown" Orientation="Horizontal" Grid.Column="1" Grid.Row="5" Margin="10,0,0,2">
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
</Button>
</StackPanel>
<StackPanel x:Name="Shortcut_VolumeMute" Orientation="Horizontal" Grid.Column="1" Grid.Row="6" Margin="10,0,0,2">
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
</Button>
</StackPanel>
<StackPanel x:Name="Shortcut_ShowWindow" Orientation="Horizontal" Grid.Column="1" Grid.Row="7" Margin="10,0,0,0">
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
</Button>
</StackPanel>
</Grid>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Text="{x:Static properties:Resources.Settings_ShortcutsInfo}" TextWrapping="Wrap" Margin="0,2,0,0" MaxWidth="420" />
</StackPanel>
<Button Content="{x:Static properties:Resources.Settings_SnapcastResetButton}" Margin="0,10,0,0" Width="120" Click="ShortcutsReset_Clicked"/>
</StackPanel>
</Grid>
</GroupBox>
</DockPanel>
</TabItem>
<TabItem Header="Snapcast"> <TabItem Header="Snapcast">
<DockPanel Margin="8"> <DockPanel Margin="8">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0"> <GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
<GroupBox.Header> <GroupBox.Header>
<StackPanel Orientation="Horizontal">
<emoji:TextBlock Text="🔊 Snapcast"/> <emoji:TextBlock Text="🔊 Snapcast"/>
</StackPanel>
</GroupBox.Header> </GroupBox.Header>
<Grid VerticalAlignment="Top"> <Grid VerticalAlignment="Top">
<StackPanel> <StackPanel>
@ -78,59 +191,61 @@
</DockPanel> </DockPanel>
</TabItem> </TabItem>
<TabItem Header="{x:Static properties:Resources.Settings_Shortcuts}"> <TabItem Header="Shuffle">
<DockPanel Margin="8"> <DockPanel Margin="8">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0"> <GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
<GroupBox.Header> <GroupBox.Header>
<StackPanel Orientation="Horizontal">
<TextBlock> <TextBlock>
<emoji:EmojiInline Text="⌨️ "/> <emoji:EmojiInline Text="🔁 "/>
<Run Text="{x:Static properties:Resources.Settings_Shortcuts}"></Run> <Run Text="Shuffle"></Run>
</TextBlock> </TextBlock>
</StackPanel>
</GroupBox.Header> </GroupBox.Header>
<Grid> <Grid MaxWidth="500">
<StackPanel> <StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeOffset}" TextWrapping="Wrap"/> <TextBox TextWrapping="Wrap" Width="25" PreviewTextInput="NumberValidationTextBox" Margin="0,2,0,0"/>
<TextBox x:Name="VolumeOffset" TextWrapping="Wrap" Width="25" PreviewTextInput="NumberValidationTextBox" Margin="8,2,0,0"/> <TextBlock Text="Prevent repetition rate (0-100%)" TextWrapping="Wrap" Margin="5,2,0,0"/>
</StackPanel> </StackPanel>
<Grid MinWidth="300" Margin="0,5,0,0"> <TextBlock TextWrapping="Wrap" Margin="0,10,0,0">
<Grid.ColumnDefinitions> <Run>The shuffle window allows to add random songs to your queue. Both options take into account the filter.</Run>
<ColumnDefinition/> <Run>If the filter is empty, the entire music library is taken into account.</Run><LineBreak/><LineBreak/>
<ColumnDefinition/> <Run FontWeight="Bold">Continuous shuffle</Run><LineBreak/>
</Grid.ColumnDefinitions> <Run>By enabling this option, unison will automatically add songs to the queue so you never run out of songs to listen to.</Run>
<Grid.RowDefinitions> <LineBreak/><LineBreak/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{x:Static properties:Resources.Settings_NextTrack}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="0" Margin="1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_PreviousTrack}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="1" Margin="1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_PlayPause}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="2" Margin="1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeUp}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="3" Margin="1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeDown}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="4" Margin="1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_VolumeMute}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="5" Margin="1"/>
<TextBlock Text="{x:Static properties:Resources.Settings_ShowWindow}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="6" Margin="1"/>
<TextBlock Text="ctrl + media_next" TextWrapping="Wrap" Grid.Column="1" Grid.Row="0" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/> <Run FontWeight="Bold">Add to queue</Run><LineBreak/>
<TextBlock Text="ctrl + media_prev" TextWrapping="Wrap" Grid.Column="1" Grid.Row="1" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/> <Run>Add a fixed number of songs to the queue. It can take a long time to add more than 100 songs, so the option is limited to 1000 songs.</Run>
<TextBlock Text="ctrl + media_play" TextWrapping="Wrap" Grid.Column="1" Grid.Row="2" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/> </TextBlock>
<TextBlock Text="ctrl + volume_up" TextWrapping="Wrap" Grid.Column="1" Grid.Row="3" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + volume_down" TextWrapping="Wrap" Grid.Column="1" Grid.Row="4" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + volume_mute" TextWrapping="Wrap" Grid.Column="1" Grid.Row="5" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + alt + enter" TextWrapping="Wrap" Grid.Column="1" Grid.Row="6" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
</Grid>
</StackPanel> </StackPanel>
</Grid> </Grid>
</GroupBox> </GroupBox>
</DockPanel> </DockPanel>
</TabItem> </TabItem>
<TabItem Header="{x:Static properties:Resources.Stats}">
<DockPanel Margin="8">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
<GroupBox.Header>
<TextBlock>
<emoji:EmojiInline Text="📊"/>
<Run Text="{x:Static properties:Resources.Stats}"/>
</TextBlock>
</GroupBox.Header>
<Grid VerticalAlignment="Top">
<TextBlock>
<Run Text="{x:Static properties:Resources.Stats_Songs}"/><Run Text=" "/><Run x:Name="StatSong"/><LineBreak/>
<Run Text="{x:Static properties:Resources.Stats_Albums}"/><Run Text=" "/><Run x:Name="StatAlbum"/><LineBreak/>
<Run Text="{x:Static properties:Resources.Stats_Artists}"/><Run Text=" "/><Run x:Name="StatArtist"/><LineBreak/>
<Run Text="{x:Static properties:Resources.Stats_TotalPlaytime}"/><Run Text=" "/><Run x:Name="StatTotalPlaytime"/><LineBreak/><LineBreak/>
<Run Text="{x:Static properties:Resources.Stats_Uptime}"/><Run Text=" "/><Run x:Name="StatUptime"/><LineBreak/>
<Run Text="{x:Static properties:Resources.Stats_TotalTimePlayed}"/><Run Text=" "/><Run x:Name="StatTotalTimePlayed"/><LineBreak/>
<Run Text="{x:Static properties:Resources.Stats_LastDatabaseUpdate}"/><Run Text=" "/><Run x:Name="StatDatabaseUpdate"/>
</TextBlock>
</Grid>
</GroupBox>
</DockPanel>
</TabItem>
<TabItem Header="{x:Static properties:Resources.Settings_About}" Height="20" VerticalAlignment="Bottom"> <TabItem Header="{x:Static properties:Resources.Settings_About}" Height="20" VerticalAlignment="Bottom">
<DockPanel Margin="8"> <DockPanel Margin="8">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0"> <GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
@ -145,14 +260,14 @@
</TextBlock> </TextBlock>
<TextBlock TextWrapping="Wrap" VerticalAlignment="Top"> <TextBlock TextWrapping="Wrap" VerticalAlignment="Top">
<Run Text="{x:Static properties:Resources.Settings_AboutInfo}" /><LineBreak/> <Run Text="{x:Static properties:Resources.Settings_AboutInfo}" /><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/Difegue/Stylophone" RequestNavigate="Hyperlink_RequestNavigate">Stylophone</Hyperlink><Run Text="{x:Static properties:Resources.Settings_MpcNET}" /><LineBreak/> ※ <Hyperlink NavigateUri="https://github.com/Difegue/MpcNET" RequestNavigate="Hyperlink_RequestNavigate">MpcNET</Hyperlink><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/hardcodet/wpf-notifyicon" RequestNavigate="Hyperlink_RequestNavigate">wpf-notifyicon</Hyperlink><LineBreak/> ※ <Hyperlink NavigateUri="https://github.com/hardcodet/wpf-notifyicon" RequestNavigate="Hyperlink_RequestNavigate">wpf-notifyicon</Hyperlink><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/samhocevar/emoji.wpf" RequestNavigate="Hyperlink_RequestNavigate">Emoji.WPF</Hyperlink><LineBreak/> ※ <Hyperlink NavigateUri="https://github.com/samhocevar/emoji.wpf" RequestNavigate="Hyperlink_RequestNavigate">Emoji.WPF</Hyperlink><LineBreak/>
※ <Hyperlink NavigateUri="https://github.com/tof4/RadioBrowser" RequestNavigate="Hyperlink_RequestNavigate">RadioBrowser</Hyperlink> ※ <Hyperlink NavigateUri="https://github.com/tof4/RadioBrowser" RequestNavigate="Hyperlink_RequestNavigate">RadioBrowser</Hyperlink>
</TextBlock> </TextBlock>
<TextBlock Margin="0,10,0,0"> <TextBlock Margin="0,10,0,0">
<Run Text="{x:Static properties:Resources.Settings_SourceCode1}" /> <Run Text="{x:Static properties:Resources.Settings_SourceCode1}" />
<Hyperlink NavigateUri="https://git.n700.ovh/keb/unison" RequestNavigate="Hyperlink_RequestNavigate"> <Hyperlink NavigateUri="https://github.com/ZetaKebab/unison" RequestNavigate="Hyperlink_RequestNavigate">
<Run Text="{x:Static properties:Resources.Settings_SourceCode2}" /> <Run Text="{x:Static properties:Resources.Settings_SourceCode2}" />
</Hyperlink>. </Hyperlink>.
</TextBlock> </TextBlock>

View File

@ -2,9 +2,11 @@
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Interop; using System.Windows.Interop;
using System.Windows.Navigation; using System.Windows.Navigation;
@ -33,6 +35,8 @@ namespace unison
} }
} }
HotkeyHandler _hotkeys = (HotkeyHandler)Application.Current.Properties["hotkeys"];
public Settings() public Settings()
{ {
InitHwnd(); InitHwnd();
@ -41,6 +45,11 @@ namespace unison
WindowState = WindowState.Minimized; WindowState = WindowState.Minimized;
Initialize();
}
void Initialize()
{
MpdHost.Text = Properties.Settings.Default.mpd_host; MpdHost.Text = Properties.Settings.Default.mpd_host;
MpdPort.Text = Properties.Settings.Default.mpd_port.ToString(); MpdPort.Text = Properties.Settings.Default.mpd_port.ToString();
//MpdPassword.Text = Properties.Settings.Default.mpd_password; //MpdPassword.Text = Properties.Settings.Default.mpd_password;
@ -49,6 +58,54 @@ namespace unison
SnapcastPath.Text = Properties.Settings.Default.snapcast_path; SnapcastPath.Text = Properties.Settings.Default.snapcast_path;
SnapcastPort.Text = Properties.Settings.Default.snapcast_port.ToString(); SnapcastPort.Text = Properties.Settings.Default.snapcast_port.ToString();
VolumeOffset.Text = Properties.Settings.Default.volume_offset.ToString(); VolumeOffset.Text = Properties.Settings.Default.volume_offset.ToString();
InitializeShortcuts();
}
void InitializeShortcuts()
{
System.Collections.Generic.IEnumerable<StackPanel> stackPanelCollection = RebindKeyWrapper.Children.OfType<StackPanel>();
StackPanel[] stackPanelList = stackPanelCollection.ToArray();
// Default state
for (int i = 0; i < stackPanelList.Length; i++)
{
ComboBox[] comboBoxList = stackPanelList[i].Children.OfType<ComboBox>().ToArray();
foreach (ComboBox comboBox in comboBoxList) // default status (for reset)
{
comboBox.FontWeight = FontWeights.Light;
comboBox.SelectedItem = "None";
}
TextBlock textBlock = (TextBlock)stackPanelList[i].Children.OfType<Button>().FirstOrDefault().Content;
textBlock.Text = "None";
}
// Populate values
for (int i = 0; i < stackPanelList.Length; i++)
{
// setup MOD
HotkeyHandler.MOD mod = _hotkeys._Shortcuts[i].mod;
HotkeyHandler.MOD[] MODList = System.Enum.GetValues(typeof(HotkeyHandler.MOD))
.OfType<HotkeyHandler.MOD>()
.Select(x => x & _hotkeys._Shortcuts[i].mod)
.Where(x => x != HotkeyHandler.MOD.None)
.ToArray();
ComboBox[] comboBox = stackPanelList[i].Children.OfType<ComboBox>().ToArray();
for (int j = 0; j < MODList.Length; j++)
{
comboBox[j].SelectedItem = MODList[j].ToString();
if (comboBox[j].SelectedItem.ToString() != "None")
comboBox[j].FontWeight = FontWeights.Bold;
}
// setup VK
TextBlock textBlock = (TextBlock)stackPanelList[i].Children.OfType<Button>().FirstOrDefault().Content;
textBlock.Text = _hotkeys._Shortcuts[i].vk.ToString();
if (textBlock.Text != "None")
textBlock.FontWeight = FontWeights.Bold;
}
} }
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
@ -88,6 +145,169 @@ namespace unison
SnapcastPort.Text = (string)Application.Current.FindResource("snapcastPort"); SnapcastPort.Text = (string)Application.Current.FindResource("snapcastPort");
} }
public void UpdateStats()
{
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
StatSong.Text = mpd.GetStats().Songs.ToString();
StatAlbum.Text = mpd.GetStats().Albums.ToString();
StatArtist.Text = mpd.GetStats().Artists.ToString();
StatTotalPlaytime.Text = mpd.GetStats().TotalPlaytime.ToString();
StatUptime.Text = mpd.GetStats().Uptime.ToString();
StatTotalTimePlayed.Text = mpd.GetStats().TotalTimePlayed.ToString();
StatDatabaseUpdate.Text = mpd.GetStats().DatabaseUpdate.ToString();
}
private void HotkeyChanged()
{
_hotkeys.RemoveHotkeys();
_hotkeys.AddHotkeys();
}
private ref HotkeyHandler.HotkeyPair GetHotkeyVariable(string Name)
{
if (Name == "Shortcut_NextTrack")
return ref _hotkeys._NextTrack;
if (Name == "Shortcut_PreviousTrack")
return ref _hotkeys._PreviousTrack;
if (Name == "Shortcut_PlayPause")
return ref _hotkeys._PlayPause;
if (Name == "Shortcut_VolumeUp")
return ref _hotkeys._VolumeUp;
if (Name == "Shortcut_VolumeDown")
return ref _hotkeys._VolumeDown;
if (Name == "Shortcut_VolumeMute")
return ref _hotkeys._VolumeMute;
if (Name == "Shortcut_ShowWindow")
return ref _hotkeys._ShowWindow;
return ref _hotkeys._NextTrack;
}
private void UpdateHotkey_MOD(string Name, HotkeyHandler.MOD mod) => GetHotkeyVariable(Name).SetMOD(mod);
private void UpdateHotkey_VK(string Name, HotkeyHandler.VK vk) => GetHotkeyVariable(Name).SetVK(vk);
private void MOD_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!IsLoaded)
return;
ComboBox comboBox = (ComboBox)sender;
StackPanel stackPanel = (StackPanel)comboBox.Parent;
System.Collections.Generic.IEnumerable<ComboBox> stackPanelCollection = stackPanel.Children.OfType<ComboBox>();
HotkeyHandler.MOD MOD1, MOD2;
// we need to do this because the element is modified -after- this function
if (comboBox.Tag.ToString() == "MOD1")
{
MOD1 = GetMOD(e.AddedItems[0].ToString());
MOD2 = GetMOD(stackPanelCollection.Last().Text);
}
else
{
MOD1 = GetMOD(stackPanelCollection.First().Text);
MOD2 = GetMOD(e.AddedItems[0].ToString());
}
if (e.AddedItems[0].ToString() == "None")
comboBox.FontWeight = FontWeights.Light;
else
comboBox.FontWeight = FontWeights.Bold;
HotkeyHandler.MOD ModKey = MOD1 | MOD2;
UpdateHotkey_MOD(stackPanel.Name, ModKey);
HotkeyChanged();
}
private void RemapKey_Clicked(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
TextBlock textBlock = (TextBlock)button.Content;
textBlock.Text = unison.Resources.Resources.Settings_ShortcutsKey;
textBlock.FontWeight = FontWeights.Bold;
button.PreviewKeyDown += DetectPressedKey;
}
private void DetectPressedKey(object sender, KeyEventArgs e)
{
e.Handled = true;
Key pressedKey = e.Key;
HotkeyHandler.VK VirtualKey = GetVirtualKey(pressedKey);
Button button = (Button)sender;
TextBlock textBlock = (TextBlock)button.Content;
StackPanel stackPanel = (StackPanel)button.Parent;
if (VirtualKey == HotkeyHandler.VK.None)
{
pressedKey = Key.None;
textBlock.FontWeight = FontWeights.Light;
}
else
textBlock.FontWeight = FontWeights.Bold;
textBlock.Text = pressedKey.ToString();
button.PreviewKeyDown -= DetectPressedKey;
UpdateHotkey_VK(stackPanel.Name, VirtualKey);
HotkeyChanged();
}
private HotkeyHandler.VK GetVirtualKey(Key key)
{
foreach (object value in System.Enum.GetValues(typeof(HotkeyHandler.VK)))
{
if (key.ToString().ToLower() == value.ToString().ToLower())
return (HotkeyHandler.VK)value;
}
return HotkeyHandler.VK.None;
}
private HotkeyHandler.MOD GetMOD(string str)
{
foreach (object value in System.Enum.GetValues(typeof(HotkeyHandler.MOD)))
{
if (str.ToLower() == value.ToString().ToLower())
return (HotkeyHandler.MOD)value;
}
return HotkeyHandler.MOD.None;
}
private void ShortcutsReset_Clicked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.nextTrack_mod = (uint)Application.Current.FindResource("nextTrack_mod");
Properties.Settings.Default.nextTrack_vk = (uint)Application.Current.FindResource("nextTrack_vk");
Properties.Settings.Default.previousTrack_mod = (uint)Application.Current.FindResource("previousTrack_mod");
Properties.Settings.Default.previousTrack_vk = (uint)Application.Current.FindResource("previousTrack_vk");
Properties.Settings.Default.playPause_mod = (uint)Application.Current.FindResource("playPause_mod");
Properties.Settings.Default.playPause_vk = (uint)Application.Current.FindResource("playPause_vk");
Properties.Settings.Default.volumeUp_mod = (uint)Application.Current.FindResource("volumeUp_mod");
Properties.Settings.Default.volumeUp_vk = (uint)Application.Current.FindResource("volumeUp_vk");
Properties.Settings.Default.volumeDown_mod = (uint)Application.Current.FindResource("volumeDown_mod");
Properties.Settings.Default.volumeDown_vk = (uint)Application.Current.FindResource("volumeDown_vk");
Properties.Settings.Default.volumeMute_mod = (uint)Application.Current.FindResource("volumeMute_mod");
Properties.Settings.Default.volumeMute_vk = (uint)Application.Current.FindResource("volumeMute_vk");
Properties.Settings.Default.showWindow_mod = (uint)Application.Current.FindResource("showWindow_mod");
Properties.Settings.Default.showWindow_vk = (uint)Application.Current.FindResource("showWindow_vk");
_hotkeys.Initialize();
HotkeyChanged();
InitializeShortcuts();
}
public uint GetMod(StackPanel stackPanel)
{
return (uint)(GetMOD(stackPanel.Children.OfType<ComboBox>().First().SelectedItem.ToString()) | GetMOD(stackPanel.Children.OfType<ComboBox>().Last().SelectedItem.ToString()));
}
public uint GetVk(StackPanel stackPanel)
{
Button button = stackPanel.Children.OfType<Button>().First();
TextBlock textBlock = (TextBlock)button.Content;
return (uint)(HotkeyHandler.VK)System.Enum.Parse(typeof(HotkeyHandler.VK), textBlock.Text, true);
}
public void SaveSettings() public void SaveSettings()
{ {
Properties.Settings.Default.mpd_host = MpdHost.Text; Properties.Settings.Default.mpd_host = MpdHost.Text;
@ -98,6 +318,22 @@ namespace unison
Properties.Settings.Default.snapcast_path = SnapcastPath.Text; Properties.Settings.Default.snapcast_path = SnapcastPath.Text;
Properties.Settings.Default.snapcast_port = int.Parse(SnapcastPort.Text, CultureInfo.InvariantCulture); Properties.Settings.Default.snapcast_port = int.Parse(SnapcastPort.Text, CultureInfo.InvariantCulture);
Properties.Settings.Default.volume_offset = int.Parse(VolumeOffset.Text, CultureInfo.InvariantCulture); Properties.Settings.Default.volume_offset = int.Parse(VolumeOffset.Text, CultureInfo.InvariantCulture);
Properties.Settings.Default.nextTrack_mod = GetMod(Shortcut_NextTrack);
Properties.Settings.Default.nextTrack_vk = GetVk(Shortcut_NextTrack);
Properties.Settings.Default.previousTrack_mod = GetMod(Shortcut_PreviousTrack);
Properties.Settings.Default.previousTrack_vk = GetVk(Shortcut_PreviousTrack);
Properties.Settings.Default.playPause_mod = GetMod(Shortcut_PlayPause);
Properties.Settings.Default.playPause_vk = GetVk(Shortcut_PlayPause);
Properties.Settings.Default.volumeUp_mod = GetMod(Shortcut_VolumeUp);
Properties.Settings.Default.volumeUp_vk = GetVk(Shortcut_VolumeUp);
Properties.Settings.Default.volumeDown_mod = GetMod(Shortcut_VolumeDown);
Properties.Settings.Default.volumeDown_vk = GetVk(Shortcut_VolumeDown);
Properties.Settings.Default.volumeMute_mod = GetMod(Shortcut_VolumeMute);
Properties.Settings.Default.volumeMute_vk = GetVk(Shortcut_VolumeMute);
Properties.Settings.Default.showWindow_mod = GetMod(Shortcut_ShowWindow);
Properties.Settings.Default.showWindow_vk = GetVk(Shortcut_ShowWindow);
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} }

102
Views/Shuffle.xaml Normal file
View File

@ -0,0 +1,102 @@
<Window x:Class="unison.Shuffle"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
xmlns:local="clr-namespace:unison"
mc:Ignorable="d"
Title="Shuffle" Closing="Window_Closing" SizeToContent="WidthAndHeight" ResizeMode="NoResize">
<Grid>
<StackPanel>
<StackPanel HorizontalAlignment="Left" Orientation="Vertical" Margin="5,0,5,5">
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
<GroupBox.Header>
<TextBlock>
<emoji:EmojiInline Text="🔡"/>
<Run Text="Filter"/>
</TextBlock>
</GroupBox.Header>
<StackPanel Orientation="Vertical" Margin="5,0,5,0">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<TextBlock Text="Song" Margin="0,0,0,2"/>
<TextBox x:Name="Song" Width="240" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,0,0">
<TextBlock Text="Artist" Margin="0,0,0,2"/>
<TextBox x:Name="Artist" Width="240" Margin="5,0,0,0"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<StackPanel Orientation="Vertical">
<TextBlock Text="Album" Margin="0,0,0,2"/>
<TextBox x:Name="Album" Width="240" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,0,0">
<TextBlock Text="Year" Margin="0,0,0,2"/>
<TextBox x:Name="Year" Width="240" Margin="5,0,0,0"/>
</StackPanel>
</StackPanel>
<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" 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="True"/>
</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 x:Name="SongFilterPanel" Margin="0,5,0,0" Visibility="Collapsed">
<TextBlock>
<Run Text="Number of songs in filter: "/><Run x:Name="SongFilterNumber" FontWeight="Bold"/>
</TextBlock>
</StackPanel>
</StackPanel>
</GroupBox>
<GroupBox Margin="0,5,0,0" HorizontalAlignment="Stretch">
<GroupBox.Header>
<TextBlock>
<emoji:EmojiInline Text="♾️"/>
<Run Text="Continuous shuffle"/>
</TextBlock>
</GroupBox.Header>
<StackPanel Orientation="Horizontal" Margin="5,8,0,0">
<CheckBox x:Name="ContinuousShuffle" Checked="ContinuousShuffle_Checked" Unchecked="ContinuousShuffle_Checked" FocusVisualStyle="{x:Null}">
<TextBlock Text="Enable continuous shuffle" TextWrapping="Wrap"/>
</CheckBox>
</StackPanel>
</GroupBox>
<GroupBox x:Name="AddToQueueGroup" Margin="0,5,0,0" HorizontalAlignment="Stretch">
<GroupBox.Header>
<TextBlock>
<emoji:EmojiInline Text=""/>
<Run Text="Add to queue"/>
</TextBlock>
</GroupBox.Header>
<StackPanel Margin="5,0,0,0">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,10,0,0">
<TextBox x:Name="SongNumber" Text="100" Width="35" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBlock Text="Number of songs to add" Margin="5,0,0,5"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,2,0,0">
<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">
<Run Text="Added "/><Run x:Name="NumberAddedSongs"/><Run Text=" songs to the queue..."/>
</TextBlock>
</StackPanel>
</StackPanel>
</GroupBox>
</StackPanel>
</StackPanel>
</Grid>
</Window>

307
Views/Shuffle.xaml.cs Normal file
View File

@ -0,0 +1,307 @@
using MpcNET;
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;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
namespace unison
{
public partial class Shuffle : Window
{
private MPDHandler _mpd;
bool _continuous = false;
List<string> _songList { get; }
public Shuffle()
{
InitializeComponent();
_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;
}
public void AddContinuousSongs()
{
if (IsFilterEmpty())
{
// add a completely random song
ContinuousShuffle_AddToQueueRandom();
return;
}
int AddedSongs = 0;
NumberAddedSongs.Text = AddedSongs.ToString();
SearchStatus.Visibility = Visibility.Visible;
HashSet<int> SongIndex = new();
while (SongIndex.Count < 2)
{
int MaxIndex = new Random().Next(0, _songList.Count - 1);
SongIndex.Add(MaxIndex);
}
foreach (int index in SongIndex)
_mpd.AddSong(_songList[index]);
SearchStatus.Visibility = Visibility.Collapsed;
}
public async void ListGenre()
{
if (Genre.Items.Count == 0)
{
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
List<string> Response = await _mpd.SafelySendCommandAsync(new ListCommand(MpdTags.Genre, null, null));
if (Response.Count > 0)
{
Genre.Items.Add("");
foreach (var genre in Response)
Genre.Items.Add(genre);
}
}
}
public async void ListFolder()
{
if (Directory.Items.Count == 0)
{
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
IEnumerable<IMpdFilePath> Response = await _mpd.SafelySendCommandAsync(new LsInfoCommand(""));
if (Response != null)
{
Directory.Items.Add("");
foreach (var directory in Response)
Directory.Items.Add(directory.Name);
}
}
}
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 void Reset_Clicked(object sender, RoutedEventArgs e)
{
Song.Text = "";
Artist.Text = "";
Album.Text = "";
Year.Text = "";
Genre.SelectedIndex = 0;
Directory.SelectedIndex = 0;
}
private async void ContinuousShuffle_Checked(object sender, RoutedEventArgs e)
{
if (ContinuousShuffle.IsChecked == true)
{
AddToQueueGroup.IsEnabled = false;
_continuous = true;
_songList.Clear();
if (!IsFilterEmpty())
{
/*await*/
GetSongsFromFilter();
}
}
else
{
AddToQueueGroup.IsEnabled = true;
_continuous = false;
}
}
private async void ContinuousShuffle_AddToQueueRandom()
{
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()
{
int AddedSongs = 0;
NumberAddedSongs.Text = AddedSongs.ToString();
SearchStatus.Visibility = Visibility.Visible;
for (int i = 0; i < int.Parse(SongNumber.Text); 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);
AddedSongs++;
NumberAddedSongs.Text = AddedSongs.ToString();
}
}
SearchStatus.Visibility = Visibility.Collapsed;
}
private async Task GetSongsFromFilter()
{
_songList.Clear();
SongFilterPanel.Visibility = Visibility.Visible;
int song = _mpd.GetStats().Songs;
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));
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, ");
// there are no song in this filter
if (value[0] == "")
{
SongFilterNumber.Text = _songList.Count.ToString();
return;
}
foreach (string file in value)
{
int start = 0;
int end = file.IndexOf("],");
string filePath = file.Substring(start, end - start);
Debug.WriteLine(filePath);
_songList.Add(filePath);
SongFilterNumber.Text = _songList.Count.ToString();
}
// remove characters from first file
_songList[0] = _songList[0].Substring(7, _songList[0].Length - 7);
SongFilterPanel.Visibility = Visibility.Visible;
SongFilterNumber.Text = _songList.Count.ToString();
}
private async void AddToQueueFilter()
{
await GetSongsFromFilter();
int AddedSongs = 0;
NumberAddedSongs.Text = AddedSongs.ToString();
SearchStatus.Visibility = Visibility.Visible;
// more requested songs than available => add everything
if (int.Parse(SongNumber.Text) > _songList.Count)
{
foreach (string path in _songList)
{
await Task.Delay(1);
_mpd.AddSong(path);
AddedSongs++;
NumberAddedSongs.Text = AddedSongs.ToString();
}
}
// more available songs than requested =>
// we add unique indexes until we reach the requested amount
else
{
HashSet<int> SongIndex = new();
while (SongIndex.Count < int.Parse(SongNumber.Text))
{
int MaxIndex = new Random().Next(0, _songList.Count - 1);
SongIndex.Add(MaxIndex);
}
foreach (int index in SongIndex)
_mpd.AddSong(_songList[index]);
}
SearchStatus.Visibility = Visibility.Collapsed;
}
private void AddToQueue_Clicked(object sender, RoutedEventArgs e)
{
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
if (_mpd.GetStats() == null)
return;
if (IsFilterEmpty())
AddToQueueRandom();
else
AddToQueueFilter();
}
}
}

View File

@ -30,11 +30,11 @@
<Image Width="16" Height="16" emoji:Image.Source="📻" /> <Image Width="16" Height="16" emoji:Image.Source="📻" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<!--<MenuItem Header="Shuffle" Command="{Binding Shuffle}"> <MenuItem Header="Shuffle" Command="{Binding Shuffle}">
<MenuItem.Icon> <MenuItem.Icon>
<Image Width="16" Height="16" emoji:Image.Source="🔀" /> <Image Width="16" Height="16" emoji:Image.Source="🔀" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem>--> </MenuItem>
<MenuItem Header="{x:Static properties:Resources.Settings}" Command="{Binding Settings}"> <MenuItem Header="{x:Static properties:Resources.Settings}" Command="{Binding Settings}">
<MenuItem.Icon> <MenuItem.Icon>
<Image Width="16" Height="16" emoji:Image.Source="🛠️" /> <Image Width="16" Height="16" emoji:Image.Source="🛠️" />

View File

@ -71,6 +71,18 @@ namespace unison
} }
} }
public ICommand Shuffle
{
get
{
return new DelegateCommand
{
CommandAction = () => ((MainWindow)Application.Current.MainWindow).Shuffle_Clicked(null, null),
CanExecuteFunc = () => true
};
}
}
public ICommand Settings public ICommand Settings
{ {
get get

Binary file not shown.

View File

@ -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.1</Version> <Version>1.3</Version>
<Company /> <Company />
<Authors>Théo Marchal</Authors> <Authors>Théo Marchal</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile> <PackageLicenseFile>LICENSE</PackageLicenseFile>
@ -22,13 +22,6 @@
<None Remove="Resources\icon-mini.ico" /> <None Remove="Resources\icon-mini.ico" />
<None Remove="Resources\nocover.png" /> <None Remove="Resources\nocover.png" />
<None Remove="LICENSE" /> <None Remove="LICENSE" />
<None Remove="snapclient_0.25.0-1_win64\FLAC.dll" />
<None Remove="snapclient_0.25.0-1_win64\ogg.dll" />
<None Remove="snapclient_0.25.0-1_win64\opus.dll" />
<None Remove="snapclient_0.25.0-1_win64\README.txt" />
<None Remove="snapclient_0.25.0-1_win64\snapclient.exe" />
<None Remove="snapclient_0.25.0-1_win64\soxr.dll" />
<None Remove="snapclient_0.25.0-1_win64\vorbis.dll" />
<None Include="LICENSE"> <None Include="LICENSE">
<Pack>True</Pack> <Pack>True</Pack>
<PackagePath></PackagePath> <PackagePath></PackagePath>
@ -48,37 +41,13 @@
<Content Include="LICENSE"> <Content Include="LICENSE">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="snapclient_0.25.0-1_win64\README.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="snapclient_0.25.0-1_win64\FLAC.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="snapclient_0.25.0-1_win64\ogg.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="snapclient_0.25.0-1_win64\opus.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="snapclient_0.25.0-1_win64\snapclient.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="snapclient_0.25.0-1_win64\soxr.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="snapclient_0.25.0-1_win64\vorbis.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Emoji.Wpf" Version="0.3.3" /> <PackageReference Include="Emoji.Wpf" Version="0.3.3" />
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" /> <PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="RadioBrowser" Version="0.6.1" /> <PackageReference Include="RadioBrowser" Version="0.6.1" />
</ItemGroup> <PackageReference Include="MpcNET" Version="1.4.0" />
<ItemGroup>
<ProjectReference Include="..\MpcNET\MpcNET.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -109,6 +78,27 @@
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None> </None>
<None Update="snapclient_0.26.0-1_win64\FLAC.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="snapclient_0.26.0-1_win64\ogg.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="snapclient_0.26.0-1_win64\opus.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="snapclient_0.26.0-1_win64\README.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="snapclient_0.26.0-1_win64\snapclient.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="snapclient_0.26.0-1_win64\soxr.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="snapclient_0.26.0-1_win64\vorbis.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -4,11 +4,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 16.0.31515.178 VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "unison", "unison.csproj", "{489048C4-3FCA-4573-B34C-943D03F94D04}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "unison", "unison.csproj", "{489048C4-3FCA-4573-B34C-943D03F94D04}"
ProjectSection(ProjectDependencies) = postProject
{230556C6-5AC3-4FD8-8947-C9ABF1416D19} = {230556C6-5AC3-4FD8-8947-C9ABF1416D19}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MpcNET", "..\MpcNET\MpcNET.csproj", "{230556C6-5AC3-4FD8-8947-C9ABF1416D19}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -23,12 +18,6 @@ Global
{489048C4-3FCA-4573-B34C-943D03F94D04}.Release|Any CPU.Build.0 = Release|Any CPU {489048C4-3FCA-4573-B34C-943D03F94D04}.Release|Any CPU.Build.0 = Release|Any CPU
{489048C4-3FCA-4573-B34C-943D03F94D04}.Release-Stable|Any CPU.ActiveCfg = Release|Any CPU {489048C4-3FCA-4573-B34C-943D03F94D04}.Release-Stable|Any CPU.ActiveCfg = Release|Any CPU
{489048C4-3FCA-4573-B34C-943D03F94D04}.Release-Stable|Any CPU.Build.0 = Release|Any CPU {489048C4-3FCA-4573-B34C-943D03F94D04}.Release-Stable|Any CPU.Build.0 = Release|Any CPU
{230556C6-5AC3-4FD8-8947-C9ABF1416D19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{230556C6-5AC3-4FD8-8947-C9ABF1416D19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{230556C6-5AC3-4FD8-8947-C9ABF1416D19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{230556C6-5AC3-4FD8-8947-C9ABF1416D19}.Release|Any CPU.Build.0 = Release|Any CPU
{230556C6-5AC3-4FD8-8947-C9ABF1416D19}.Release-Stable|Any CPU.ActiveCfg = Release-Stable|Any CPU
{230556C6-5AC3-4FD8-8947-C9ABF1416D19}.Release-Stable|Any CPU.Build.0 = Release-Stable|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE