mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 12:37:01 +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 strict;
|
||||||
|
|
||||||
use base qw(Slim::Display::Squeezebox2);
|
use base qw(Slim::Display::Squeezebox2);
|
||||||
|
use Storable qw(dclone);
|
||||||
|
|
||||||
use Slim::Utils::Prefs;
|
use Slim::Utils::Prefs;
|
||||||
use Slim::Utils::Log;
|
use Slim::Utils::Log;
|
||||||
@@ -17,6 +18,17 @@ my $VISUALIZER_WAVEFORM = 3;
|
|||||||
my $VISUALIZER_VUMETER_ESP32 = 0x11;
|
my $VISUALIZER_VUMETER_ESP32 = 0x11;
|
||||||
my $VISUALIZER_SPECTRUM_ANALYZER_ESP32 = 0x12;
|
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('array', 'modes');
|
||||||
__PACKAGE__->mk_accessor('rw', 'modes');
|
__PACKAGE__->mk_accessor('rw', 'modes');
|
||||||
@@ -33,12 +45,14 @@ sub new {
|
|||||||
$cprefs->init( {
|
$cprefs->init( {
|
||||||
width => 128,
|
width => 128,
|
||||||
small_VU => 15,
|
small_VU => 15,
|
||||||
spectrum => { scale => 25,
|
spectrum => \%SPECTRUM_DEFAULTS,
|
||||||
small => { size => 25, band => 5.33 },
|
} );
|
||||||
full => { band => 8 },
|
|
||||||
},
|
$prefs->migrateClient(2, sub {
|
||||||
}
|
my ($cprefs, $client) = @_;
|
||||||
);
|
sanitizeSpectrum($cprefs->get('spectrum'));
|
||||||
|
1;
|
||||||
|
});
|
||||||
|
|
||||||
$display->init_accessor(
|
$display->init_accessor(
|
||||||
modes => $display->build_modes,
|
modes => $display->build_modes,
|
||||||
@@ -106,6 +120,19 @@ sub displayHeight {
|
|||||||
return 32;
|
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 {
|
sub build_modes {
|
||||||
my $client = shift->client;
|
my $client = shift->client;
|
||||||
my $cprefs = $prefs->client($client);
|
my $cprefs = $prefs->client($client);
|
||||||
@@ -118,7 +145,7 @@ sub build_modes {
|
|||||||
my $width_low = ($artwork->{'enable'} && $artwork->{'x'} && ($artwork->{'y'} >= 32 || $disp_width - $artwork->{'x'} > 32)) ? $artwork->{'x'} : $disp_width;
|
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 $small_VU = $cprefs->get('small_VU');
|
||||||
my $spectrum = $cprefs->get('spectrum');
|
my $spectrum = sanitizeSpectrum($cprefs->get('sprectrum'));
|
||||||
|
|
||||||
my $small_spectrum_pos = { x => $width - int ($spectrum->{small}->{size} * $width / 100),
|
my $small_spectrum_pos = { x => $width - int ($spectrum->{small}->{size} * $width / 100),
|
||||||
width => int ($spectrum->{small}->{size} * $width / 100),
|
width => int ($spectrum->{small}->{size} * $width / 100),
|
||||||
|
|||||||
@@ -43,12 +43,18 @@ sub handler {
|
|||||||
if ($paramRef->{'saveSettings'}) {
|
if ($paramRef->{'saveSettings'}) {
|
||||||
if ($client->displayWidth) {
|
if ($client->displayWidth) {
|
||||||
$cprefs->set('small_VU', $paramRef->{'pref_small_VU'} || 15);
|
$cprefs->set('small_VU', $paramRef->{'pref_small_VU'} || 15);
|
||||||
my $spectrum = {
|
|
||||||
scale => $paramRef->{'pref_spectrum_scale'} || 25,
|
require Plugins::SqueezeESP32::Graphics;
|
||||||
small => { size => $paramRef->{'pref_spectrum_small_size'} || 25,
|
my $spectrum = Plugins::SqueezeESP32::Graphics::sanitizeSpectrum({
|
||||||
band => $paramRef->{'pref_spectrum_small_band'} || 5.33 },
|
scale => $paramRef->{'pref_spectrum_scale'},
|
||||||
full => { band => $paramRef->{'pref_spectrum_full_band'} } || 8,
|
small => {
|
||||||
};
|
size => $paramRef->{'pref_spectrum_small_size'},
|
||||||
|
band => $paramRef->{'pref_spectrum_small_band'}
|
||||||
|
},
|
||||||
|
full => {
|
||||||
|
band => $paramRef->{'pref_spectrum_full_band'}
|
||||||
|
},
|
||||||
|
});
|
||||||
$cprefs->set('spectrum', $spectrum);
|
$cprefs->set('spectrum', $spectrum);
|
||||||
|
|
||||||
my $artwork = {
|
my $artwork = {
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ $prefs->migrateClient(1, sub {
|
|||||||
1;
|
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 {
|
$prefs->setChange(sub {
|
||||||
$_[2]->send_equalizer;
|
$_[2]->send_equalizer;
|
||||||
}, 'equalizer');
|
}, 'equalizer');
|
||||||
|
|||||||
Reference in New Issue
Block a user