Graphics.pm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package Plugins::SqueezeESP32::Graphics;
  2. use strict;
  3. use base qw(Slim::Display::Squeezebox2);
  4. use Slim::Utils::Prefs;
  5. use Slim::Utils::Log;
  6. my $prefs = preferences('plugin.squeezeesp32');
  7. my $log = logger('plugin.squeezeesp32');
  8. my $VISUALIZER_NONE = 0;
  9. my $VISUALIZER_VUMETER = 1;
  10. my $VISUALIZER_SPECTRUM_ANALYZER = 2;
  11. my $VISUALIZER_WAVEFORM = 3;
  12. my $VISUALIZER_VUMETER_ESP32 = 0x11;
  13. my $VISUALIZER_SPECTRUM_ANALYZER_ESP32 = 0x12;
  14. {
  15. #__PACKAGE__->mk_accessor('array', 'modes');
  16. __PACKAGE__->mk_accessor('rw', 'modes');
  17. __PACKAGE__->mk_accessor('rw', qw(vfdmodel));
  18. }
  19. sub new {
  20. my $class = shift;
  21. my $client = shift;
  22. my $display = $class->SUPER::new($client);
  23. my $cprefs = $prefs->client($client);
  24. $cprefs->init( {
  25. width => 128,
  26. small_VU => 15,
  27. spectrum => { scale => 25,
  28. small => { size => 25, band => 5.33 },
  29. full => { band => 8 },
  30. },
  31. }
  32. );
  33. $display->init_accessor(
  34. modes => $display->build_modes,
  35. vfdmodel => 'graphic-<width>x32', # doesn't matter much
  36. );
  37. return $display;
  38. }
  39. =comment
  40. sub modes {
  41. return \@modes;
  42. }
  43. =cut
  44. sub nmodes {
  45. return scalar($#{shift->modes()});
  46. }
  47. sub displayWidth {
  48. my $display = shift;
  49. my $client = $display->client;
  50. # if we're showing the always-on visualizer & the current buttonmode
  51. # hasn't overridden, then use the playing display mode to index
  52. # into the display width, otherwise, it's fullscreen.
  53. my $mode = 0;
  54. if ( $display->showVisualizer() && !defined($client->modeParam('visu')) ) {
  55. my $cprefs = preferences('server')->client($client);
  56. $mode = $cprefs->get('playingDisplayModes')->[ $cprefs->get('playingDisplayMode') ];
  57. }
  58. if ($display->widthOverride) {
  59. my $artwork = $prefs->client($client)->get('artwork');
  60. if ($artwork->{'enable'} && $artwork->{'y'} < 32 && $client->isPlaying) {
  61. return $artwork->{x} + ($display->modes->[$mode || 0]{_width} || 0);
  62. } else {
  63. return $display->widthOverride + ($display->modes->[$mode || 0]{_width} || 0);
  64. }
  65. } else {
  66. return $display->modes->[$mode || 0]{width};
  67. }
  68. }
  69. sub brightnessMap {
  70. return (65535, 10, 50, 100, 200);
  71. }
  72. =comment
  73. sub bytesPerColumn {
  74. return 4;
  75. }
  76. =cut
  77. # I don't think LMS renderer handles properly screens other than 32 pixels. It
  78. # seems that all we get is a 32 pixel-tall data with anything else padded to 0
  79. # i.e. if we try 64 pixels height, bytes 0..3 and 4..7 will contains the same
  80. # pattern than the 32 pixels version, where one would have expected bytes 4..7
  81. # to be empty
  82. sub displayHeight {
  83. return 32;
  84. }
  85. sub build_modes {
  86. my $client = shift->client;
  87. my $cprefs = $prefs->client($client);
  88. my $width = $cprefs->get('width') || 128;
  89. my $artwork = $cprefs->get('artwork');
  90. # if artwork is in main display, reduce width
  91. $width = $artwork->{'x'} if $artwork->{'enable'} && $artwork->{y} < 32;
  92. my $small_VU = $cprefs->get('small_VU');
  93. my $spectrum = $cprefs->get('spectrum');
  94. my $small_spectrum_pos = { x => $width - int ($spectrum->{small}->{size} * $width / 100),
  95. width => int ($spectrum->{small}->{size} * $width / 100),
  96. };
  97. my $small_VU_pos = { x => $width - int ($small_VU * $width / 100),
  98. width => int ($small_VU * $width / 100),
  99. };
  100. my @modes = (
  101. # mode 0
  102. { desc => ['BLANK'],
  103. bar => 0, secs => 0, width => $width,
  104. params => [$VISUALIZER_NONE] },
  105. # mode 1
  106. { desc => ['PROGRESS_BAR'],
  107. bar => 1, secs => 0, width => $width,
  108. params => [$VISUALIZER_NONE] },
  109. # mode 2
  110. { desc => ['ELAPSED'],
  111. bar => 0, secs => 1, width => $width,
  112. params => [$VISUALIZER_NONE] },
  113. # mode 3
  114. { desc => ['ELAPSED', 'AND', 'PROGRESS_BAR'],
  115. bar => 1, secs => 1, width => $width,
  116. params => [$VISUALIZER_NONE] },
  117. # mode 4
  118. { desc => ['REMAINING'],
  119. bar => 0, secs => -1, width => $width,
  120. params => [$VISUALIZER_NONE] },
  121. # mode 5
  122. { desc => ['CLOCK'],
  123. bar => 0, secs => 0, width => $width, clock => 1,
  124. params => [$VISUALIZER_NONE] },
  125. # mode 6
  126. { desc => ['SETUP_SHOWBUFFERFULLNESS'],
  127. bar => 0, secs => 0, width => $width, fullness => 1,
  128. params => [$VISUALIZER_NONE] },
  129. # mode 7
  130. { desc => ['VISUALIZER_VUMETER_SMALL'],
  131. bar => 0, secs => 0, width => $width, _width => -$small_VU_pos->{'width'},
  132. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space)
  133. params => [$VISUALIZER_VUMETER_ESP32, $small_VU_pos->{'width'}, 32, $small_VU_pos->{'x'}, 0, 2] },
  134. # mode 8
  135. { desc => ['VISUALIZER_SPECTRUM_ANALYZER_SMALL'],
  136. bar => 0, secs => 0, width => $width, _width => -$small_spectrum_pos->{'width'},
  137. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space, #bars, scale)
  138. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, $small_spectrum_pos->{width}, 32, $small_spectrum_pos->{'x'}, 0, 2, $small_spectrum_pos->{'width'} / $spectrum->{small}->{band}, $spectrum->{scale}] },
  139. # mode 9
  140. { desc => ['VISUALIZER_VUMETER'],
  141. bar => 0, secs => 0, width => $width,
  142. params => [$VISUALIZER_VUMETER_ESP32] },
  143. # mode 10
  144. { desc => ['VISUALIZER_SPECTRUM_ANALYZER'],
  145. bar => 0, secs => 0, width => $width,
  146. # extra parameters (bars)
  147. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  148. # mode 11
  149. { desc => ['VISUALIZER_VUMETER', 'AND', 'ELAPSED'],
  150. bar => 0, secs => 1, width => $width,
  151. params => [$VISUALIZER_VUMETER_ESP32] },
  152. # mode 12
  153. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'ELAPSED'],
  154. bar => 0, secs => 1, width => $width,
  155. # extra parameters (bars)
  156. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  157. # mode 13
  158. { desc => ['VISUALIZER_VUMETER', 'AND', 'REMAINING'],
  159. bar => 0, secs => -1, width => $width,
  160. params => [$VISUALIZER_VUMETER_ESP32] },
  161. # mode 14
  162. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'REMAINING'],
  163. bar => 0, secs => -1, width => $width,
  164. # extra parameters (bars)
  165. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  166. );
  167. return \@modes;
  168. }
  169. 1;