Philippe G před 4 roky
rodič
revize
3c317b0b86

binární
plugin/SqueezeESP32.zip


+ 22 - 3
plugin/SqueezeESP32/Player.pm

@@ -91,12 +91,19 @@ sub init {
 	}
 	
 	$client->SUPER::init(@_);
-	$client->config_artwork;
-}
+	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],
+		artwork => 0,	
+	} );
+
 	$client->SUPER::initPrefs;
 }
 
@@ -146,6 +153,15 @@ sub treble {
 	return $value;
 }
 
+sub send_equalizer {
+	my ($client, $equalizer) = @_;
+
+	$equalizer ||= $prefs->client($client)->get('equalizer') || [(0) x 10];
+	my $size = @$equalizer;
+	my $data = pack("c[$size]", @{$equalizer});
+	$client->sendFrame( eqlz => \$data );
+}
+
 sub update_equalizer {
 	my ($client, $value, $index) = @_;
 	return if $client->tone_update;
@@ -240,8 +256,11 @@ sub config_artwork {
 
 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

+ 3 - 3
plugin/SqueezeESP32/PlayerSettings.pm

@@ -31,7 +31,7 @@ sub page {
 sub prefs {
 	my ($class, $client) = @_;
 	my @prefs;
-	push @prefs, qw(width small_VU) if defined $client->displayWidth;
+	push @prefs, qw(width small_VU) if $client->displayWidth;
 	return ($prefs->client($client), @prefs);
 }
 
@@ -41,7 +41,7 @@ sub handler {
 	my ($cprefs, @prefs) = $class->prefs($client);
 
 	if ($paramRef->{'saveSettings'}) {
-		if (defined $client->displayWidth) {
+		if ($client->displayWidth) {
 			$cprefs->set('small_VU', $paramRef->{'pref_small_VU'} || 15);
 			my $spectrum = {
 				scale => $paramRef->{'pref_spectrum_scale'} || 25,
@@ -76,7 +76,7 @@ sub handler {
 		$client->update_tones($equalizer);
 	}
 
-	if (defined $client->displayWidth) {
+	if ($client->displayWidth) {
 		# the Settings super class can't handle anything but scalar values
 		# we need to populate the $paramRef for the other prefs manually
 		$paramRef->{'pref_spectrum'} = $cprefs->get('spectrum');

+ 6 - 32
plugin/SqueezeESP32/Plugin.pm

@@ -25,7 +25,7 @@ $prefs->migrateClient(1, sub {
 });
 
 $prefs->setChange(sub {
-	send_equalizer($_[2]);
+	$_[2]->send_equalizer;
 }, 'equalizer');
 
 sub initPlugin {
@@ -40,8 +40,10 @@ sub initPlugin {
 	}
 
 	$class->SUPER::initPlugin(@_);
-	Slim::Networking::Slimproto::addPlayerClass($class, 100, 'squeezeesp32', { client => 'Plugins::SqueezeESP32::Player', display => 'Plugins::SqueezeESP32::Graphics' });
-	main::INFOLOG && $log->is_info && $log->info("Added class 100 for SqueezeESP32");
+	# no name can be a subset of others due to a bug in addPlayerClass
+	Slim::Networking::Slimproto::addPlayerClass($class, 100, 'squeezeesp32-basic', { client => 'Plugins::SqueezeESP32::Player', display => 'Plugins::SqueezeESP32::Graphics' });
+	Slim::Networking::Slimproto::addPlayerClass($class, 101, 'squeezeesp32-graphic', { client => 'Plugins::SqueezeESP32::Player', display => 'Slim::Display::NoDisplay' });		
+	main::INFOLOG && $log->is_info && $log->info("Added class 100 and 101 for SqueezeESP32");
 
 	# register a command to set the EQ - without saving the values! Send params as single comma separated list of values
 	Slim::Control::Request::addDispatch(['squeezeesp32', 'seteq', '_eq'], [1, 0, 0, \&setEQ]);
@@ -50,9 +52,6 @@ sub initPlugin {
 	Slim::Control::Request::subscribe( sub { onNotification(@_) }, [ ['newmetadata'] ] );
 	Slim::Control::Request::subscribe( sub { onNotification(@_) }, [ ['playlist'], ['open', 'newsong'] ]);
 	Slim::Control::Request::subscribe( \&onStopClear, [ ['playlist'], ['stop', 'clear'] ]);
-
-	# the custom player class is only initialized if it has a display - thus we need to listen to connect events in order to initializes other player prefs
-	Slim::Control::Request::subscribe( \&onPlayer,[ ['client'], [ 'new', 'reconnect' ] ] );
 }
 
 sub onStopClear {
@@ -64,20 +63,6 @@ sub onStopClear {
 	}
 }
 
-sub onPlayer {
-	my $request = shift;
-	my $client  = $request->client || return;
-
-	if ($client->model eq 'squeezeesp32') {
-		main::INFOLOG && $log->is_info && $log->info("SqueezeESP player connected: " . $client->id);
-
-		$prefs->client($client)->init( {
-			equalizer => [(0) x 10],
-		} );
-		send_equalizer($client);
-	}
-}
-
 sub onNotification {
 	my $request = shift;
 	my $client  = $request->client || return;
@@ -104,18 +89,7 @@ sub setEQ {
 		$eqParams[$x] ||= 0;
 	}
 
-	send_equalizer($client, \@eqParams);
-}
-
-sub send_equalizer {
-	my ($client, $equalizer) = @_;
-
-	if ($client->model eq 'squeezeesp32') {
-		$equalizer ||= $prefs->client($client)->get('equalizer') || [(0) x 10];
-		my $size = @$equalizer;
-		my $data = pack("c[$size]", @{$equalizer});
-		$client->sendFrame( eqlz => \$data );
-	}
+	$client->send_equalizer(\@eqParams);
 }
 
 1;

+ 1 - 1
plugin/SqueezeESP32/install.xml

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

+ 2 - 2
plugin/repo.xml

@@ -1,10 +1,10 @@
 <?xml version='1.0' standalone='yes'?>
 <extensions>
   <plugins>
-    <plugin version="0.200" name="SqueezeESP32" minTarget="7.9" maxTarget="*">
+    <plugin version="0.201" name="SqueezeESP32" minTarget="7.9" maxTarget="*">
       <link>https://github.com/sle118/squeezelite-esp32</link>
       <creator>Philippe</creator>
-      <sha>ab2d65f5ba8e73f0f78a1a8650af19ebb1e8e724</sha>
+      <sha>c7134a3f03fbb836c48c929700ad7765854644f7</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>