Plugin.pm 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package Plugins::SqueezeESP32::Plugin;
  2. use strict;
  3. use base qw(Slim::Plugin::Base);
  4. use Slim::Utils::Prefs;
  5. use Slim::Utils::Log;
  6. use Slim::Web::ImageProxy;
  7. my $prefs = preferences('plugin.squeezeesp32');
  8. my $log = Slim::Utils::Log->addLogCategory({
  9. 'category' => 'plugin.squeezeesp32',
  10. 'defaultLevel' => 'INFO',
  11. 'description' => 'PLUGIN_SQUEEZEESP32',
  12. });
  13. # migrate 'eq' pref, as that's a reserved word and could cause problems in the future
  14. $prefs->migrateClient(1, sub {
  15. my ($cprefs, $client) = @_;
  16. $cprefs->set('equalizer', $cprefs->get('eq'));
  17. $cprefs->remove('eq');
  18. 1;
  19. });
  20. $prefs->setChange(sub {
  21. $_[2]->send_equalizer;
  22. }, 'equalizer');
  23. sub initPlugin {
  24. my $class = shift;
  25. if ( main::WEBUI ) {
  26. require Plugins::SqueezeESP32::PlayerSettings;
  27. Plugins::SqueezeESP32::PlayerSettings->new;
  28. # require Plugins::SqueezeESP32::Settings;
  29. # Plugins::SqueezeESP32::Settings->new;
  30. }
  31. $class->SUPER::initPlugin(@_);
  32. # no name can be a subset of others due to a bug in addPlayerClass
  33. Slim::Networking::Slimproto::addPlayerClass($class, 100, 'squeezeesp32-basic', { client => 'Plugins::SqueezeESP32::Player', display => 'Plugins::SqueezeESP32::Graphics' });
  34. Slim::Networking::Slimproto::addPlayerClass($class, 101, 'squeezeesp32-graphic', { client => 'Plugins::SqueezeESP32::Player', display => 'Slim::Display::NoDisplay' });
  35. main::INFOLOG && $log->is_info && $log->info("Added class 100 and 101 for SqueezeESP32");
  36. # register a command to set the EQ - without saving the values! Send params as single comma separated list of values
  37. Slim::Control::Request::addDispatch(['squeezeesp32', 'seteq', '_eq'], [1, 0, 0, \&setEQ]);
  38. # Note for some forgetful know-it-all: we need to wrap the callback to make it unique. Otherwise subscriptions would overwrite each other.
  39. Slim::Control::Request::subscribe( sub { onNotification(@_) }, [ ['newmetadata'] ] );
  40. Slim::Control::Request::subscribe( sub { onNotification(@_) }, [ ['playlist'], ['open', 'newsong'] ]);
  41. Slim::Control::Request::subscribe( \&onStopClear, [ ['playlist'], ['stop', 'clear'] ]);
  42. }
  43. sub onStopClear {
  44. my $request = shift;
  45. my $client = $request->client || return;
  46. if ($client->isa('Plugins::SqueezeESP32::Player')) {
  47. $client->clear_artwork($request);
  48. }
  49. }
  50. sub onNotification {
  51. my $request = shift;
  52. my $client = $request->client || return;
  53. if ($client->isa('Plugins::SqueezeESP32::Player')) {
  54. $client->update_artwork();
  55. }
  56. }
  57. sub setEQ {
  58. my $request = shift;
  59. # check this is the correct command.
  60. if ($request->isNotCommand([['squeezeesp32'],['seteq']])) {
  61. $request->setStatusBadDispatch();
  62. return;
  63. }
  64. # get our parameters
  65. my $client = $request->client();
  66. my @eqParams = split(/,/, $request->getParam('_eq') || '');
  67. for (my $x = 0; $x < 10; $x++) {
  68. $eqParams[$x] ||= 0;
  69. }
  70. $client->send_equalizer(\@eqParams);
  71. }
  72. 1;