diff --git a/plugin/SqueezeESP32/Graphics.pm b/plugin/SqueezeESP32/Graphics.pm index 6f763be7..80cc1307 100644 --- a/plugin/SqueezeESP32/Graphics.pm +++ b/plugin/SqueezeESP32/Graphics.pm @@ -17,6 +17,17 @@ my $VISUALIZER_WAVEFORM = 3; my $VISUALIZER_VUMETER_ESP32 = 0x11; my $VISUALIZER_SPECTRUM_ANALYZER_ESP32 = 0x12; +my %SPECTRUM_DEFAULTS = ( + scale => 25, + small => { + size => 25, + band => 5.33 + }, + full => { + band => 8 + }, +); + { #__PACKAGE__->mk_accessor('array', 'modes'); __PACKAGE__->mk_accessor('rw', 'modes'); @@ -33,14 +44,16 @@ sub new { $cprefs->init( { width => 128, small_VU => 15, - spectrum => { scale => 25, - small => { size => 25, band => 5.33 }, - full => { band => 8 }, - }, - } - ); - - $display->init_accessor( + spectrum => \%SPECTRUM_DEFAULTS, + } ); + + $prefs->migrateClient(2, sub { + my ($cprefs, $client) = @_; + sanitizeSpectrum($cprefs->get('spectrum')); + 1; + }); + + $display->init_accessor( modes => $display->build_modes, # Only seems to matter for screensaver and update to decide font. Not # any value is acceptable, so use Boom value which seems to be best @@ -106,6 +119,16 @@ sub displayHeight { return 32; } +sub sanitizeSpectrum { + my ($spectrum) = shift; + + $spectrum->{small}->{size} ||= $SPECTRUM_DEFAULTS{small}->{size}; + $spectrum->{small}->{band} ||= $SPECTRUM_DEFAULTS{small}->{band}; + $spectrum->{full}->{band} ||= $SPECTRUM_DEFAULTS{full}->{band}; + + return $spectrum; +} + sub build_modes { my $client = shift->client; my $cprefs = $prefs->client($client); @@ -118,9 +141,9 @@ sub build_modes { my $width_low = ($artwork->{'enable'} && $artwork->{'x'} && ($artwork->{'y'} >= 32 || $disp_width - $artwork->{'x'} > 32)) ? $artwork->{'x'} : $disp_width; my $small_VU = $cprefs->get('small_VU'); - my $spectrum = $cprefs->get('spectrum'); - - my $small_spectrum_pos = { x => $width - int ($spectrum->{small}->{size} * $width / 100), + my $spectrum = sanitizeSpectrum($cprefs->get('sprectrum')); + + my $small_spectrum_pos = { x => $width - int ($spectrum->{small}->{size} * $width / 100), width => int ($spectrum->{small}->{size} * $width / 100), }; my $small_VU_pos = { x => $width - int ($small_VU * $width / 100), @@ -224,7 +247,7 @@ my @extra = ( ); @modes = (@modes, @extra) if $cprefs->get('height') > 32; - + return \@modes; } diff --git a/plugin/SqueezeESP32/Player.pm b/plugin/SqueezeESP32/Player.pm index 5dddc64a..2f97ba6f 100644 --- a/plugin/SqueezeESP32/Player.pm +++ b/plugin/SqueezeESP32/Player.pm @@ -91,16 +91,19 @@ sub init { } $client->SUPER::init(@_); - $client->config_artwork; - $client->send_equalizer; - main::INFOLOG && $log->is_info && $log->info("SqueezeESP player connected: " . $client->id); } sub initPrefs { my $client = shift; + $sprefs->client($client)->init($defaultPrefs); - $prefs->client($client)->init( { equalizer => [(0) x 10] } ); + + $prefs->client($client)->init( { + equalizer => [(0) x 10], + artwork => undef, + } ); + $client->SUPER::initPrefs; } @@ -184,11 +187,13 @@ sub update_artwork { my $cprefs = $prefs->client($client); my $artwork = $cprefs->get('artwork') || return; - return unless $artwork->{'enable'}; + + my $header = pack('Nnn', $artwork->{'enable'}, $artwork->{'x'}, $artwork->{'y'}); + $client->sendFrame( grfa => \$header ); + $client->display->update; my $s = min($cprefs->get('height') - $artwork->{'y'}, $cprefs->get('width') - $artwork->{'x'}); - my $params = { force => shift || 0 }; my $path = 'music/current/cover_' . $s . 'x' . $s . '_o.jpg'; my $body = Slim::Web::Graphics::artworkRequest($client, $path, $params, \&send_artwork, undef, HTTP::Response->new); @@ -248,13 +253,17 @@ sub config_artwork { if ( my $artwork = $prefs->client($client)->get('artwork') ) { my $header = pack('Nnn', $artwork->{'enable'}, $artwork->{'x'}, $artwork->{'y'}); $client->sendFrame( grfa => \$header ); + $client->display->update; } } sub reconnect { my $client = shift; - $client->pluginData('artwork_md5', ''); $client->SUPER::reconnect(@_); + + $client->pluginData('artwork_md5', ''); + $client->config_artwork; + $client->send_equalizer; } # Change the analog output mode between headphone and sub-woofer diff --git a/plugin/SqueezeESP32/PlayerSettings.pm b/plugin/SqueezeESP32/PlayerSettings.pm index d4a4e2d6..b2bbf166 100644 --- a/plugin/SqueezeESP32/PlayerSettings.pm +++ b/plugin/SqueezeESP32/PlayerSettings.pm @@ -43,22 +43,29 @@ sub handler { if ($paramRef->{'saveSettings'}) { if ($client->displayWidth) { $cprefs->set('small_VU', $paramRef->{'pref_small_VU'} || 15); - my $spectrum = { - scale => $paramRef->{'pref_spectrum_scale'} || 25, - small => { size => $paramRef->{'pref_spectrum_small_size'} || 25, - band => $paramRef->{'pref_spectrum_small_band'} || 5.33 }, - full => { band => $paramRef->{'pref_spectrum_full_band'} } || 8, - }; + + require Plugins::SqueezeESP32::Graphics; + my $spectrum = Plugins::SqueezeESP32::Graphics::sanitizeSpectrum({ + scale => $paramRef->{'pref_spectrum_scale'}, + small => { + size => $paramRef->{'pref_spectrum_small_size'}, + band => $paramRef->{'pref_spectrum_small_band'} + }, + full => { + band => $paramRef->{'pref_spectrum_full_band'} + }, + }); $cprefs->set('spectrum', $spectrum); my $artwork = { - enable => $paramRef->{'pref_artwork_enable'}, + enable => $paramRef->{'pref_artwork_enable'} eq 'on', x => $paramRef->{'pref_artwork_x'} || 0, y => $paramRef->{'pref_artwork_y'} || 0, }; + $cprefs->set('artwork', $artwork); $client->display->modes($client->display->build_modes); - $client->display->update; + # the display update will be done below, after all is completed # force update or disable artwork if ($artwork->{'enable'}) { @@ -66,6 +73,7 @@ sub handler { } else { $client->config_artwork(); } + } my $equalizer = $cprefs->get('equalizer'); diff --git a/plugin/SqueezeESP32/Plugin.pm b/plugin/SqueezeESP32/Plugin.pm index 007f65f4..ddc81a09 100644 --- a/plugin/SqueezeESP32/Plugin.pm +++ b/plugin/SqueezeESP32/Plugin.pm @@ -24,6 +24,12 @@ $prefs->migrateClient(1, sub { 1; }); +$prefs->migrateClient(2, sub { + my ($cprefs, $client) = @_; + $cprefs->set('artwork', undef) if $cprefs->get('artwork') && ref $cprefs->get('artwork') ne 'HASH'; + 1; +}); + $prefs->setChange(sub { $_[2]->send_equalizer; }, 'equalizer'); diff --git a/plugin/SqueezeESP32/install.xml b/plugin/SqueezeESP32/install.xml index e241642f..3348a9db 100644 --- a/plugin/SqueezeESP32/install.xml +++ b/plugin/SqueezeESP32/install.xml @@ -10,6 +10,6 @@ PLUGIN_SQUEEZEESP32 PLUGIN_SQUEEZEESP32_DESC Plugins::SqueezeESP32::Plugin - 0.200 + 0.210 Philippe diff --git a/plugin/SqueezeESP32/strings.txt b/plugin/SqueezeESP32/strings.txt index 0ab48a8c..965e67de 100644 --- a/plugin/SqueezeESP32/strings.txt +++ b/plugin/SqueezeESP32/strings.txt @@ -80,8 +80,10 @@ PLUGIN_SQUEEZEESP32_ARTWORK PLUGIN_SQUEEZEESP32_ARTWORK_DESC DE Wenn die Y Position kleiner als 32 ist, dann werden Plattenhüllen auf der rechten Seite angezeigt, und x definiert die Startposition. DE Plattenhüllen werden auf Displays mit weniger als 16 Graustufen in sehr geringer Qualität angezeigt. - EN When Y position is less than 32, then artwork is displayed at the right of the main screen and x defines the starting position - EN Using artwork on less than 16-levels grayscale display if really poor quality + EN When Y position is less than 32, then artwork is displayed at the right of the main screen and X defines the starting position + EN
On large screen, it's possible to rotate the VU/Spectrum by setting a small X offset (typically 32). That will push the + EN artwork to the right and make space for a vertical VU to its left. + EN
Note that using artwork on less than 16-levels grayscale display if really poor quality PLUGIN_SQUEEZEESP32_ARTWORK_ENABLE DE Aktivieren