mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 20:17:04 +03:00
Initialize and sanitize spectrum and artwork prefs.
This commit is contained in:
@@ -3,6 +3,7 @@ package Plugins::SqueezeESP32::Graphics;
|
||||
use strict;
|
||||
|
||||
use base qw(Slim::Display::Squeezebox2);
|
||||
use Storable qw(dclone);
|
||||
|
||||
use Slim::Utils::Prefs;
|
||||
use Slim::Utils::Log;
|
||||
@@ -17,6 +18,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 +45,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 +120,19 @@ sub displayHeight {
|
||||
return 32;
|
||||
}
|
||||
|
||||
sub sanitizeSpectrum {
|
||||
my ($spectrum) = shift;
|
||||
|
||||
$spectrum->{small} ||= dclone($SPECTRUM_DEFAULTS{small});
|
||||
$spectrum->{small}->{size} ||= $SPECTRUM_DEFAULTS{small}->{size};
|
||||
$spectrum->{small}->{band} ||= $SPECTRUM_DEFAULTS{small}->{band};
|
||||
|
||||
$spectrum->{full} ||= dclone($SPECTRUM_DEFAULTS{full});
|
||||
$spectrum->{full}->{band} ||= $SPECTRUM_DEFAULTS{full}->{band};
|
||||
|
||||
return $spectrum;
|
||||
}
|
||||
|
||||
sub build_modes {
|
||||
my $client = shift->client;
|
||||
my $cprefs = $prefs->client($client);
|
||||
@@ -118,9 +145,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),
|
||||
|
||||
@@ -43,12 +43,18 @@ 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 = {
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user