Misc. fixes, added volume offset option

This commit is contained in:
2021-08-27 18:45:53 +02:00
parent 89ddb81840
commit 8896c13442
9 changed files with 99 additions and 41 deletions

View File

@ -1,12 +1,6 @@
using System.Windows; using System.Windows;
using Hardcodet.Wpf.TaskbarNotification; using Hardcodet.Wpf.TaskbarNotification;
// todo:
//
// * show mpd version
// * change volume offset
// * fix window resize (if it still happens?)
namespace unison namespace unison
{ {
public partial class App : Application public partial class App : Application

View File

@ -75,11 +75,15 @@ namespace unison
mpd.Prev(); mpd.Prev();
break; break;
case VK_VOLUME_DOWN: case VK_VOLUME_DOWN:
mpd._currentVolume -= 5; mpd._currentVolume -= Properties.Settings.Default.volume_offset;
if (mpd._currentVolume < 0)
mpd._currentVolume = 0;
mpd.SetVolume(mpd._currentVolume); mpd.SetVolume(mpd._currentVolume);
break; break;
case VK_VOLUME_UP: case VK_VOLUME_UP:
mpd._currentVolume += 5; mpd._currentVolume += Properties.Settings.Default.volume_offset;
if (mpd._currentVolume > 100)
mpd._currentVolume = 100;
mpd.SetVolume(mpd._currentVolume); mpd.SetVolume(mpd._currentVolume);
break; break;
case VK_MEDIA_PLAY_PAUSE: case VK_MEDIA_PLAY_PAUSE:
@ -94,8 +98,17 @@ namespace unison
} }
else else
{ {
AppWindow.Hide(); if (AppWindow.IsActive)
AppWindow.WindowState = WindowState.Minimized; {
AppWindow.Hide();
AppWindow.WindowState = WindowState.Minimized;
}
else // not minimized but not in front
{
AppWindow.Show();
AppWindow.Activate();
AppWindow.WindowState = WindowState.Normal;
}
} }
break; break;
} }

View File

@ -59,7 +59,6 @@ namespace unison
_elapsedTimer = new System.Timers.Timer(500); _elapsedTimer = new System.Timers.Timer(500);
_elapsedTimer.Elapsed += new System.Timers.ElapsedEventHandler(ElapsedTimer); _elapsedTimer.Elapsed += new System.Timers.ElapsedEventHandler(ElapsedTimer);
DispatcherTimer timer = new DispatcherTimer(); DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(2); timer.Interval = TimeSpan.FromSeconds(2);
timer.Tick += QueryStatus; timer.Tick += QueryStatus;
@ -228,7 +227,8 @@ namespace unison
_elapsedTimer.Stop(); _elapsedTimer.Stop();
} }
await _mpd.MpdQueryAlbumArt(_currentSong.File, false); if (_currentSong != null)
await _mpd.MpdQueryAlbumArt(_currentSong.File, false);
} }
public SongInfoEx GetCurrentSong() => _currentSong; public SongInfoEx GetCurrentSong() => _currentSong;
@ -291,5 +291,10 @@ namespace unison
{ {
return _currentStatus?.MpdState == MPDCtrl.Models.Status.MpdPlayState.Play; return _currentStatus?.MpdState == MPDCtrl.Models.Status.MpdPlayState.Play;
} }
public string GetVersion()
{
return _mpd.MpdVerText;
}
} }
} }

View File

@ -94,5 +94,17 @@ namespace unison.Properties {
this["snapcast_port"] = value; this["snapcast_port"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("5")]
public int volume_offset {
get {
return ((int)(this["volume_offset"]));
}
set {
this["volume_offset"] = value;
}
}
} }
} }

View File

@ -20,5 +20,8 @@
<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>
</Setting> </Setting>
<Setting Name="volume_offset" Type="System.Int32" Scope="User">
<Value Profile="(Default)">5</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@ -9,7 +9,7 @@ namespace unison
{ {
public partial class MainWindow : Window, INotifyPropertyChanged public partial class MainWindow : Window, INotifyPropertyChanged
{ {
private readonly Settings SettingsWindow = new Settings(); public readonly Settings SettingsWindow = new Settings();
private MPDHandler mpd; private MPDHandler mpd;

View File

@ -34,7 +34,9 @@
<TextBlock Text="Password" TextWrapping="Wrap" Margin="5,0,0,0"/> <TextBlock Text="Password" TextWrapping="Wrap" Margin="5,0,0,0"/>
<TextBox x:Name="MpdPassword" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/> <TextBox x:Name="MpdPassword" TextWrapping="Wrap" Width="250" Margin="10,2,0,0"/>
</StackPanel> </StackPanel>
<Button Content="Connect" Margin="0,10,0,0" Width="120" Click="MPDConnect_Clicked"/>
<TextBlock x:Name="ConnectionStatus" Text="Not connected." TextWrapping="Wrap" Margin="5,10,0,0"/>
<Button x:Name="ConnectButton" Content="Connect" Margin="0,10,0,0" Width="120" Click="MPDConnect_Clicked"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</GroupBox> </GroupBox>
@ -79,33 +81,39 @@
</StackPanel> </StackPanel>
</GroupBox.Header> </GroupBox.Header>
<Grid> <Grid>
<Grid MinWidth="220"> <StackPanel>
<Grid.ColumnDefinitions> <StackPanel Orientation="Horizontal">
<ColumnDefinition/> <TextBlock Text="Volume offset" TextWrapping="Wrap"/>
<ColumnDefinition/> <TextBox x:Name="VolumeOffset" TextWrapping="Wrap" Width="25" PreviewTextInput="NumberValidationTextBox" Margin="8,2,0,0"/>
</Grid.ColumnDefinitions> </StackPanel>
<Grid.RowDefinitions> <Grid MinWidth="220" Margin="0,5,0,0">
<RowDefinition/> <Grid.ColumnDefinitions>
<RowDefinition/> <ColumnDefinition/>
<RowDefinition/> <ColumnDefinition/>
<RowDefinition/> </Grid.ColumnDefinitions>
<RowDefinition/> <Grid.RowDefinitions>
<RowDefinition/> <RowDefinition/>
</Grid.RowDefinitions> <RowDefinition/>
<TextBlock Text="Next track" TextWrapping="Wrap" Grid.Column="0" Grid.Row="0" Margin="1"/> <RowDefinition/>
<TextBlock Text="Previous track" TextWrapping="Wrap" Grid.Column="0" Grid.Row="1" Margin="1"/> <RowDefinition/>
<TextBlock Text="Play / Pause" TextWrapping="Wrap" Grid.Column="0" Grid.Row="2" Margin="1"/> <RowDefinition/>
<TextBlock Text="Volume up" TextWrapping="Wrap" Grid.Column="0" Grid.Row="3" Margin="1"/> <RowDefinition/>
<TextBlock Text="Volume down" TextWrapping="Wrap" Grid.Column="0" Grid.Row="4" Margin="1"/> </Grid.RowDefinitions>
<TextBlock Text="Show window" TextWrapping="Wrap" Grid.Column="0" Grid.Row="5" Margin="1"/> <TextBlock Text="Next track" TextWrapping="Wrap" Grid.Column="0" Grid.Row="0" Margin="1"/>
<TextBlock Text="Previous track" TextWrapping="Wrap" Grid.Column="0" Grid.Row="1" Margin="1"/>
<TextBlock Text="Play / Pause" TextWrapping="Wrap" Grid.Column="0" Grid.Row="2" Margin="1"/>
<TextBlock Text="Volume up" TextWrapping="Wrap" Grid.Column="0" Grid.Row="3" Margin="1"/>
<TextBlock Text="Volume down" TextWrapping="Wrap" Grid.Column="0" Grid.Row="4" Margin="1"/>
<TextBlock Text="Show window" TextWrapping="Wrap" Grid.Column="0" Grid.Row="5" Margin="1"/>
<TextBlock Text="ctrl + media_next" TextWrapping="Wrap" Grid.Column="1" Grid.Row="0" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/> <TextBlock Text="ctrl + media_next" TextWrapping="Wrap" Grid.Column="1" Grid.Row="0" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + media_prev" TextWrapping="Wrap" Grid.Column="1" Grid.Row="1" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/> <TextBlock Text="ctrl + media_prev" TextWrapping="Wrap" Grid.Column="1" Grid.Row="1" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + media_play" TextWrapping="Wrap" Grid.Column="1" Grid.Row="2" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/> <TextBlock Text="ctrl + media_play" TextWrapping="Wrap" Grid.Column="1" Grid.Row="2" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + volume_up" TextWrapping="Wrap" Grid.Column="1" Grid.Row="3" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/> <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_down" TextWrapping="Wrap" Grid.Column="1" Grid.Row="4" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
<TextBlock Text="ctrl + alt + enter" 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="5" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
</Grid> </Grid>
</StackPanel>
</Grid> </Grid>
</GroupBox> </GroupBox>
</DockPanel> </DockPanel>

View File

@ -50,6 +50,7 @@ namespace unison
SnapcastStartup.IsChecked = Properties.Settings.Default.snapcast_startup; SnapcastStartup.IsChecked = Properties.Settings.Default.snapcast_startup;
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();
} }
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
@ -66,11 +67,22 @@ namespace unison
e.Handled = true; e.Handled = true;
} }
public void UpdateConnectionStatus()
{
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
if (mpd._connected)
{
ConnectionStatus.Text = "Connected to MPD " + mpd.GetVersion() + ".";
ConnectButton.IsEnabled = false;
}
}
private void MPDConnect_Clicked(object sender, RoutedEventArgs e) private void MPDConnect_Clicked(object sender, RoutedEventArgs e)
{ {
SaveSettings(); SaveSettings();
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"]; MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
//mpd.Connect(); mpd.Start();
UpdateConnectionStatus();
} }
private void SnapcastReset_Clicked(object sender, RoutedEventArgs e) private void SnapcastReset_Clicked(object sender, RoutedEventArgs e)
@ -87,6 +99,7 @@ namespace unison
Properties.Settings.Default.snapcast_startup = (bool)SnapcastStartup.IsChecked; Properties.Settings.Default.snapcast_startup = (bool)SnapcastStartup.IsChecked;
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.Save(); Properties.Settings.Default.Save();
} }

View File

@ -8,6 +8,12 @@
<Win32Resource></Win32Resource> <Win32Resource></Win32Resource>
<StartupObject>unison.App</StartupObject> <StartupObject>unison.App</StartupObject>
<Version>0.0.1</Version> <Version>0.0.1</Version>
<Company />
<Authors>Théo Marchal</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://git.n700.ovh/keb/unison</PackageProjectUrl>
<RepositoryUrl>https://git.n700.ovh/keb/unison</RepositoryUrl>
<Copyright>Théo Marchal</Copyright>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -21,6 +27,10 @@
<None Remove="snapclient_0.25.0-1_win64\snapclient.exe" /> <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\soxr.dll" />
<None Remove="snapclient_0.25.0-1_win64\vorbis.dll" /> <None Remove="snapclient_0.25.0-1_win64\vorbis.dll" />
<None Include="LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>