PlayerSettings.pm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package Plugins::SqueezeESP32::PlayerSettings;
  2. use strict;
  3. use base qw(Slim::Web::Settings);
  4. use List::Util qw(first);
  5. use Slim::Utils::Log;
  6. use Slim::Utils::Prefs;
  7. my $sprefs = preferences('server');
  8. my $prefs = preferences('plugin.squeezeesp32');
  9. my $log = logger('plugin.squeezeesp32');
  10. sub name {
  11. return Slim::Web::HTTP::CSRF->protectName('PLUGIN_SQUEEZEESP32_PLAYERSETTINGS');
  12. }
  13. sub needsClient {
  14. return 1;
  15. }
  16. sub validFor {
  17. my ($class, $client) = @_;
  18. return $client->model eq 'squeezeesp32';
  19. }
  20. sub page {
  21. return Slim::Web::HTTP::CSRF->protectURI('plugins/SqueezeESP32/settings/player.html');
  22. }
  23. sub prefs {
  24. my ($class, $client) = @_;
  25. my @prefs;
  26. push @prefs, qw(width small_VU) if $client->displayWidth;
  27. return ($prefs->client($client), @prefs);
  28. }
  29. sub handler {
  30. my ($class, $client, $paramRef) = @_;
  31. my ($cprefs, @prefs) = $class->prefs($client);
  32. if ($paramRef->{'saveSettings'}) {
  33. if ($client->displayWidth) {
  34. $cprefs->set('small_VU', $paramRef->{'pref_small_VU'} || 15);
  35. require Plugins::SqueezeESP32::Graphics;
  36. my $spectrum = Plugins::SqueezeESP32::Graphics::sanitizeSpectrum({
  37. scale => $paramRef->{'pref_spectrum_scale'},
  38. small => {
  39. size => $paramRef->{'pref_spectrum_small_size'},
  40. band => $paramRef->{'pref_spectrum_small_band'}
  41. },
  42. full => {
  43. band => $paramRef->{'pref_spectrum_full_band'}
  44. },
  45. });
  46. $cprefs->set('spectrum', $spectrum);
  47. my $artwork = {
  48. enable => $paramRef->{'pref_artwork_enable'} eq 'on',
  49. x => $paramRef->{'pref_artwork_x'} || 0,
  50. y => $paramRef->{'pref_artwork_y'} || 0,
  51. };
  52. $cprefs->set('artwork', $artwork);
  53. $client->display->modes($client->display->build_modes);
  54. # the display update will be done below, after all is completed
  55. # force update or disable artwork
  56. if ($artwork->{'enable'}) {
  57. $client->update_artwork(1);
  58. } else {
  59. $client->config_artwork();
  60. }
  61. }
  62. if ($client->depth == 16) {
  63. my $equalizer = $cprefs->get('equalizer');
  64. for my $i (0 .. $#{$equalizer}) {
  65. $equalizer->[$i] = $paramRef->{"pref_equalizer.$i"} || 0;
  66. }
  67. $cprefs->set('equalizer', $equalizer);
  68. $client->update_tones($equalizer);
  69. }
  70. }
  71. if ($client->displayWidth) {
  72. # the Settings super class can't handle anything but scalar values
  73. # we need to populate the $paramRef for the other prefs manually
  74. $paramRef->{'pref_spectrum'} = $cprefs->get('spectrum');
  75. $paramRef->{'pref_artwork'} = $cprefs->get('artwork');
  76. }
  77. $paramRef->{'pref_equalizer'} = $cprefs->get('equalizer') if $client->depth == 16;
  78. return $class->SUPER::handler($client, $paramRef);
  79. }
  80. 1;