浏览代码

Merge pull request #26 from michaelherger/live-eq

Make the EQ in player settings update the player in "real time"
philippe44 4 年之前
父节点
当前提交
2821a85328

+ 27 - 0
plugin/SqueezeESP32/HTML/EN/plugins/SqueezeESP32/settings/player.html

@@ -39,8 +39,35 @@
 	[% END %]
 
 	[% WRAPPER setting title="PLUGIN_SQUEEZEESP32_EQUALIZER" desc="" %]
+		<div>[% "PLUGIN_SQUEEZEESP32_EQUALIZER_SAVE" | string %]</div>
 	[% END %]
 
+	<script TYPE="text/javascript">
+		if (Ext) {
+			Ext.onReady(function () {
+				new Ext.util.TaskRunner().start({
+					run: checkEq,
+					interval: 1000
+				});
+			});
+
+			function checkEq() {
+				var eqValues = [];
+				this.lastValues = this.lastValues || [];
+
+				for (var x = 0; x < 10; x++) {
+					eqValues[x] = Ext.get('pref_equalizer.' + x).dom.value || 0;
+				}
+
+				if (eqValues.join() != this.lastValues.join()) {
+					this.lastValues = eqValues;
+					SqueezeJS.Controller.request({
+						params: ['[% playerid %]', ['squeezeesp32', 'seteq', eqValues.join()]]
+					});
+				}
+			}
+		}
+	</script>
 	[% WRAPPER settingSection %]
 		[% WRAPPER settingGroup title='31Hz' desc="" %]
 			<input type="text" class="stdedit sliderInput_-13_20" name="pref_equalizer.0" id="pref_equalizer.0" value="[% pref_equalizer.0 %]" size="2"">

+ 25 - 2
plugin/SqueezeESP32/Plugin.pm

@@ -43,6 +43,9 @@ sub 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");
 
+	# 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]);
+
 	# Note for some forgetful know-it-all: we need to wrap the callback to make it unique. Otherwise subscriptions would overwrite each other.
 	Slim::Control::Request::subscribe( sub { onNotification(@_) }, [ ['newmetadata'] ] );
 	Slim::Control::Request::subscribe( sub { onNotification(@_) }, [ ['playlist'], ['open', 'newsong'] ]);
@@ -84,11 +87,31 @@ sub onNotification {
 	}
 }
 
+sub setEQ {
+	my $request = shift;
+
+	# check this is the correct command.
+	if ($request->isNotCommand([['squeezeesp32'],['seteq']])) {
+		$request->setStatusBadDispatch();
+		return;
+	}
+
+	# get our parameters
+	my $client   = $request->client();
+	my @eqParams = split(/,/, $request->getParam('_eq') || '');
+
+	for (my $x = 0; $x < 10; $x++) {
+		$eqParams[$x] ||= 0;
+	}
+
+	send_equalizer($client, \@eqParams);
+}
+
 sub send_equalizer {
-	my ($client) = @_;
+	my ($client, $equalizer) = @_;
 
 	if ($client->model eq 'squeezeesp32') {
-		my $equalizer = $prefs->client($client)->get('equalizer') || [(0) x 10];
+		$equalizer ||= $prefs->client($client)->get('equalizer') || [(0) x 10];
 		my $size = @$equalizer;
 		my $data = pack("c[$size]", @{$equalizer});
 		$client->sendFrame( eqlz => \$data );

+ 3 - 0
plugin/SqueezeESP32/strings.txt

@@ -97,3 +97,6 @@ PLUGIN_SQUEEZEESP32_EQUALIZER
 	DE	Parametrischer Equalizer
 	EN	Parametric equalizer
 
+PLUGIN_SQUEEZEESP32_EQUALIZER_SAVE
+	DE	Bitte speichern Sie die Equalizer Einstellungen, falls das Gerät diese dauerhaft verwenden soll. Ansonsten werden sie beim nächsten Start zurückgesetzt.
+	EN	Don't forget to save the Equalizer settings if you want them to stick. Otherwise they'll be reset next time you restart the device.