123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package Plugins::SqueezeESP32::Plugin;
- use strict;
- use base qw(Slim::Plugin::Base);
- use Slim::Utils::Prefs;
- use Slim::Utils::Log;
- use Slim::Web::ImageProxy;
- my $prefs = preferences('plugin.squeezeesp32');
- my $log = Slim::Utils::Log->addLogCategory({
- 'category' => 'plugin.squeezeesp32',
- 'defaultLevel' => 'INFO',
- 'description' => 'PLUGIN_SQUEEZEESP32',
- });
- # migrate 'eq' pref, as that's a reserved word and could cause problems in the future
- $prefs->migrateClient(1, sub {
- my ($cprefs, $client) = @_;
- $cprefs->set('equalizer', $cprefs->get('eq'));
- $cprefs->remove('eq');
- 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');
- $prefs->setChange(sub {
- $_[2]->send_loudness;
- }, 'loudness');
- sub initPlugin {
- my $class = shift;
- # enable the following to test the firmware downloading code without a SqueezeliteESP32 player
- # require Plugins::SqueezeESP32::FirmwareHelper;
- # Plugins::SqueezeESP32::FirmwareHelper::init();
- if ( main::WEBUI ) {
- require Plugins::SqueezeESP32::PlayerSettings;
- Plugins::SqueezeESP32::PlayerSettings->new;
- }
- $class->SUPER::initPlugin(@_);
- # 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]);
- Slim::Control::Request::addDispatch(['squeezeesp32', 'setld', '_ld'], [1, 0, 0, \&setLD]);
- # 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'] ]);
- Slim::Control::Request::subscribe( \&onStopClear, [ ['playlist'], ['stop', 'clear'] ]);
- }
- sub onStopClear {
- my $request = shift;
- my $client = $request->client || return;
- if ($client->isa('Plugins::SqueezeESP32::Player')) {
- $client->clear_artwork(0, $request->getRequestString());
- }
- }
- sub onNotification {
- my $request = shift;
- my $client = $request->client || return;
- foreach my $player ($client->syncGroupActiveMembers) {
- next unless $player->isa('Plugins::SqueezeESP32::Player');
- $player->update_artwork;
- }
- }
- 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;
- }
- $client->send_equalizer(\@eqParams);
- }
- sub setLD {
- my $request = shift;
- # check this is the correct command.
- if ($request->isNotCommand([['squeezeesp32'],['setld']])) {
- $request->setStatusBadDispatch();
- return;
- }
- # get our parameters
- my $client = $request->client();
- my $loudness = $request->getParam('_ld') || 0;
- $client->send_loudness($loudness);
- }
- 1;
|