By player screen settings

This commit is contained in:
philippe44
2020-03-05 19:46:06 -08:00
parent 831410752a
commit c865dfbe9c
9 changed files with 160 additions and 40 deletions

Binary file not shown.

View File

@@ -21,13 +21,22 @@ my $VISUALIZER_WAVEFORM = 3;
__PACKAGE__->mk_accessor('rw', qw(vfdmodel));
}
use Data::Dumper;
sub new {
my $class = shift;
my $client = shift;
my $display = $class->SUPER::new($client);
my $cprefs = $prefs->client($client);
$cprefs->init( {
width => 128,
small_VU => 15,
spectrum => { scale => 25,
small => { size => 25, band => 5.33 },
full => { band => 8 },
},
}
);
$display->init_accessor(
modes => $display->build_modes,
@@ -44,14 +53,13 @@ sub modes {
=cut
sub nmodes {
# -1 for LMS bug workaround
return scalar(@{shift->modes}) - 1;
return scalar($#{shift->modes()});
}
sub displayWidth {
my $display = shift;
my $client = $display->client;
# if we're showing the always-on visualizer & the current buttonmode
# hasn't overridden, then use the playing display mode to index
# into the display width, otherwise, it's fullscreen.
@@ -88,22 +96,13 @@ sub displayHeight {
return 32;
}
=comment
sub vfdmodel {
return 'graphic-'.$width.'x32';
}
=cut
sub build_modes {
my $client = shift->client;
print("CLIENT IN BUILD MODE $client\n");
my $cprefs = $prefs->client($client);
my $width = shift || $cprefs->get('width') || $prefs->get('width') || 128;
my $small_VU = shift || $cprefs->get('small_vu') || 0.15;
my $small_spectrum = shift || $cprefs->get('small_spectrum') || 0.25;
my $spectrum_bar = shift || $cprefs->get('spectrum_bar') || { 'small' => 0.1875, 'full' => 0.125 };
my $spectrum_scale = shift || $cprefs->get('spectrum_scale') || $prefs->get('spectrum_scale') || 50;
my $width = shift || $cprefs->get('width') || 128;
my $small_VU = $cprefs->get('small_VU');
my $spectrum = $cprefs->get('spectrum');
my @modes = (
# mode 0
@@ -136,14 +135,14 @@ sub build_modes {
params => [$VISUALIZER_NONE] },
# mode 7
{ desc => ['VISUALIZER_VUMETER_SMALL'],
bar => 0, secs => 0, width => $width, _width => int -($small_VU*$width),
bar => 0, secs => 0, width => $width, _width => int -($small_VU*$width/100),
# extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space)
params => [$VISUALIZER_VUMETER, int ($small_VU* $width), 32, int -($small_VU*$width), 0, 2] },
params => [$VISUALIZER_VUMETER, int ($small_VU*$width/100), 32, int -($small_VU*$width/100), 0, 2] },
# mode 8
{ desc => ['VISUALIZER_SPECTRUM_ANALYZER_SMALL'],
bar => 0, secs => 0, width => $width, _width => int -($small_spectrum*$width),
bar => 0, secs => 0, width => $width, _width => int -($spectrum->{small}->{size}*$width/100),
# extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space, bars)
params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($small_spectrum*$width), 32, int -($small_spectrum*$width), 0, 2, int ($small_spectrum*$width*$spectrum_bar->{small}), $spectrum_scale] },
params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($spectrum->{small}->{size}*$width/100), 32, int -($spectrum->{small}->{size}*$width/100), 0, 2, int ($spectrum->{small}->{size}/100*$width/$spectrum->{small}->{band}), $spectrum->{scale}/100] },
# mode 9
{ desc => ['VISUALIZER_VUMETER'],
bar => 0, secs => 0, width => $width,
@@ -152,7 +151,7 @@ sub build_modes {
{ desc => ['VISUALIZER_SPECTRUM_ANALYZER'],
bar => 0, secs => 0, width => $width,
# extra parameters (bars)
params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width * $spectrum_bar->{full}), $spectrum_scale] },
params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}/100] },
# mode 11
{ desc => ['VISUALIZER_VUMETER', 'AND', 'ELAPSED'],
bar => 0, secs => 1, width => $width,
@@ -161,7 +160,7 @@ sub build_modes {
{ desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'ELAPSED'],
bar => 0, secs => 1, width => $width,
# extra parameters (bars)
params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width * $spectrum_bar->{full}), $spectrum_scale] },
params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}/100] },
# mode 13
{ desc => ['VISUALIZER_VUMETER', 'AND', 'REMAINING'],
bar => 0, secs => -1, width => $width,
@@ -170,9 +169,7 @@ sub build_modes {
{ desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'REMAINING'],
bar => 0, secs => -1, width => $width,
# extra parameters (bars)
params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width * $spectrum_bar->{full}), $spectrum_scale] },
# dummy for LMS bug workaround
{ desc => [], bar => 0, secs => -1, width => $width,params => [] },
params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}/100] },
);
return \@modes;

View File

@@ -0,0 +1,28 @@
[% PROCESS settings/header.html %]
[% WRAPPER setting title="PLUGIN_SQUEEZEESP32_WIDTH" desc="PLUGIN_SQUEEZEESP32_WIDTH_DESC" %]
<!--<input type="text" readonly class="stdedit" name="pref_width" id="width" value="[% prefs.pref_width %]" size="3">-->
[% prefs.pref_width %]
[% END %]
[% WRAPPER setting title="PLUGIN_SQUEEZEESP32_SMALL_VU" desc="PLUGIN_SQUEEZEESP32_SMALL_VU_DESC" %]
<input type="number" min="10" max= "50" step="5"class="stdedit" name="pref_small_VU" id="small_VU" value="[% prefs.pref_small_VU %]" size="3">
[% END %]
[% WRAPPER setting title="PLUGIN_SQUEEZEESP32_SPECTRUM_SCALE" desc="PLUGIN_SQUEEZEESP32_SPECTRUM_SCALE_DESC" %]
<input type="number" min="10" max= "50" step="5" class="stdedit" name="pref_spectrum_scale" id="spectrum_scale" value="[% prefs.pref_spectrum.scale %]" size="3">
[% END %]
[% WRAPPER setting title="PLUGIN_SQUEEZEESP32_SMALL_SPECTRUM" desc="PLUGIN_SQUEEZEESP32_SMALL_SPECTRUM_DESC" %]
[% "PLUGIN_SQUEEZEESP32_SMALL_SPECTRUM_SIZE" | string %]&nbsp
<input type="number" min="10" max= "50" step="5"class="stdedit" name="pref_spectrum_small_size" id="spectrum_small_size" value="[% prefs.pref_spectrum.small.size %]" size="3">
[% "PLUGIN_SQUEEZEESP32_SMALL_SPECTRUM_BAND" | string %]&nbsp
<input type="text" class="stdedit" name="pref_spectrum_small_band" id="spectrum_small_band" value="[% prefs.pref_spectrum.small.band %]" size="3">
[% END %]
[% WRAPPER setting title="PLUGIN_SQUEEZEESP32_FULL_SPECTRUM_BAND" desc="PLUGIN_SQUEEZEESP32_FULL_SPECTRUM_BAND_DESC" %]
<input type="text" class="stdedit" name="pref_spectrum_full_band" id="spectrum_full_band" value="[% prefs.pref_spectrum.full.band %]" size="3">
[% END %]
[% PROCESS settings/footer.html %]

View File

@@ -25,6 +25,7 @@ sub playerSettingsFrame {
if ($id == 0xfe) {
$value = (unpack('Cn', $$data_ref))[1];
if ($value > 100 && $value < 400) {
$prefs->client($client)->set('width', $value);
$client->display->modes($client->display->build_modes($value));
$client->display->widthOverride(1, $value);
$client->update;

View File

@@ -0,0 +1,66 @@
package Plugins::SqueezeESP32::PlayerSettings;
use strict;
use base qw(Slim::Web::Settings);
use List::Util qw(first);
use Slim::Utils::Log;
use Slim::Utils::Prefs;
my $sprefs = preferences('server');
my $prefs = preferences('plugin.squeezeesp32');
my $log = logger('plugin.squeezeesp32');
sub name {
return Slim::Web::HTTP::CSRF->protectName('PLUGIN_SQUEEZEESP32_PLAYERSETTINGS');
}
sub needsClient {
return 1;
}
sub validFor {
my ($class, $client) = @_;
return $client->model eq 'squeezeesp32';
}
sub page {
return Slim::Web::HTTP::CSRF->protectURI('plugins/SqueezeESP32/settings/player.html');
}
sub prefs {
my ($class, $client) = @_;
my @prefs = qw(width small_VU spectrum);
return ($prefs->client($client), @prefs);
}
sub handler {
my ($class, $client, $paramRef) = @_;
my ($cprefs, @prefs) = $class->prefs($client);
if ($paramRef->{'saveSettings'}) {
$cprefs->set('small_VU', $paramRef->{'pref_small_VU'});
my $spectrum = { 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);
$client->display->modes($client->display->build_modes);
$client->display->update;
}
# as there is nothing captured, we need to re-set these variables
$paramRef->{'pref_width'} = $cprefs->get('width');
# here I don't know why you need to set again spectrum which is a reference
# to a hash. Using $paramRef->{prefs} does not work either. It seems that
# soem are copies of value, some are references, can't figure out.This whole
# logic of "Settings" is beyond me and I really hate it
$paramRef->{'pref_spectrum'} = $cprefs->get('spectrum');
return $class->SUPER::handler($client, $paramRef);
}
1;

View File

@@ -8,11 +8,6 @@ use Slim::Utils::Log;
my $prefs = preferences('plugin.squeezeesp32');
$prefs->init({
width => 128,
spectrum_scale => 50,
});
my $log = Slim::Utils::Log->addLogCategory({
'category' => 'plugin.squeezeesp32',
'defaultLevel' => 'INFO',
@@ -23,10 +18,13 @@ sub initPlugin {
my $class = shift;
if ( main::WEBUI ) {
require Plugins::SqueezeESP32::Settings;
Plugins::SqueezeESP32::Settings->new;
require Plugins::SqueezeESP32::PlayerSettings;
Plugins::SqueezeESP32::PlayerSettings->new;
# require Plugins::SqueezeESP32::Settings;
# Plugins::SqueezeESP32::Settings->new;
}
$class->SUPER::initPlugin(@_);
Slim::Networking::Slimproto::addPlayerClass($class, 100, 'squeezeesp32', { client => 'Plugins::SqueezeESP32::Player', display => 'Plugins::SqueezeESP32::Graphics' });
$log->info("Added class 100 for SqueezeESP32");

View File

@@ -10,6 +10,6 @@
<name>PLUGIN_SQUEEZEESP32</name>
<description>PLUGIN_SQUEEZEESP32_DESC</description>
<module>Plugins::SqueezeESP32::Plugin</module>
<version>0.21</version>
<version>0.30</version>
<creator>Philippe</creator>
</extensions>

View File

@@ -13,13 +13,43 @@ PLUGIN_SQUEEZEESP32_BANNER_TEXT
PLUGIN_SQUEEZEESP32_DESC
EN Adds a new player id (100) to enable display with SqueezeESP32
PLUGIN_SQUEEZEESP32_PLAYERSETTINGS
EN Display (ESP32)
PLUGIN_SQUEEZEESP32_WIDTH
EN Screen width
PLUGIN_SQUEEZEESP32_WIDTH_DESC
EN Width of the display in pixel as reported by the player
PLUGIN_SQUEEZEESP32_SMALL_VU
EN Small VU size
PLUGIN_SQUEEZEESP32_SMALL_VU_DESC
EN % of the display used for small VU (right-justified)
PLUGIN_SQUEEZEESP32_SPECTRUM_SCALE
EN Spectrum scale
EN Spectrum scaling
PLUGIN_SQUEEZEESP32_SPECTRUM_SCALE_DESC
EN Sets the scale factor % of spectrum visualizer by halves for better representation.
EN For example, 50 means that 50% of spectrum is displayed in 1/2 of the screen, so it's linear...
EN % of Spectrum displayed in first half of the screen. For example, 50 means that 50% of spectrum is displayed in 1/2 of the screen
EN But 25 means that only 25% of spectrum is displayed in 1/2 of the screen, so it's a sort of log
PLUGIN_SQUEEZEESP32_SMALL_SPECTRUM
EN Small spectrum options
PLUGIN_SQUEEZEESP32_SMALL_SPECTRUM_DESC
EN <i>Size</i>: % of the screen used by small spectrum
EN <br><i>Band factor</i>: number of bands is the width of the <b>spectrum</b> screen divided by this factor
PLUGIN_SQUEEZEESP32_SMALL_SPECTRUM_SIZE
EN Size
PLUGIN_SQUEEZEESP32_SMALL_SPECTRUM_BAND
EN Band factor
PLUGIN_SQUEEZEESP32_FULL_SPECTRUM_BAND
EN Full spectrum band factor
PLUGIN_SQUEEZEESP32_FULL_SPECTRUM_BAND_DESC
EN The number of bands is the width of the screen divided by this factor

View File

@@ -4,7 +4,7 @@
<plugin version="0.21" name="SqueezeESP32" minTarget="7.5" maxTarget="*">
<link>https://github.com/sle118/squeezelite-esp32</link>
<creator>Philippe</creator>
<sha>f1955a3c930a0c1809a1d2dac85970905c9b68a0</sha>
<sha>a110570f53f24c571492b13cf225cbfd1bdf9a52</sha>
<email>philippe_44@outlook.com</email>
<desc lang="EN">SqueezeESP32 additional player id (100)</desc>
<url>http://github.com/sle118/squeezelite-esp32/raw/master/plugin/SqueezeESP32.zip</url>