2
0

Graphics.pm 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. # Only seems to matter for screensaver and update to decide font. Not
  36. # any value is acceptable, so use Boom value which seems to be best
  37. # compromise
  38. vfdmodel => 'graphic-160x32',
  39. );
  40. return $display;
  41. }
  42. =comment
  43. sub modes {
  44. return \@modes;
  45. }
  46. =cut
  47. sub nmodes {
  48. return scalar($#{shift->modes()});
  49. }
  50. sub displayWidth {
  51. my $display = shift;
  52. my $client = $display->client;
  53. # if we're showing the always-on visualizer & the current buttonmode
  54. # hasn't overridden, then use the playing display mode to index
  55. # into the display width, otherwise, it's fullscreen.
  56. my $mode = 0;
  57. if ( $display->showVisualizer() && !defined($client->modeParam('visu')) ) {
  58. my $cprefs = preferences('server')->client($client);
  59. $mode = $cprefs->get('playingDisplayModes')->[ $cprefs->get('playingDisplayMode') ];
  60. }
  61. if ($display->widthOverride) {
  62. my $artwork = $prefs->client($client)->get('artwork');
  63. if ($artwork->{'enable'} && $artwork->{'y'} < 32 && ($client->isPlaying || $client->isPaused)) {
  64. return ($artwork->{x} || $display->widthOverride) + ($display->modes->[$mode || 0]{_width} || 0);
  65. } else {
  66. return $display->widthOverride + ($display->modes->[$mode || 0]{_width} || 0);
  67. }
  68. } else {
  69. return $display->modes->[$mode || 0]{width};
  70. }
  71. }
  72. sub brightnessMap {
  73. return (0 .. 5);
  74. }
  75. =comment
  76. sub bytesPerColumn {
  77. return 4;
  78. }
  79. =cut
  80. # I don't think LMS renderer handles properly screens other than 32 pixels. It
  81. # seems that all we get is a 32 pixel-tall data with anything else padded to 0
  82. # i.e. if we try 64 pixels height, bytes 0..3 and 4..7 will contains the same
  83. # pattern than the 32 pixels version, where one would have expected bytes 4..7
  84. # to be empty
  85. sub displayHeight {
  86. return 32;
  87. }
  88. sub build_modes {
  89. my $client = shift->client;
  90. my $cprefs = $prefs->client($client);
  91. my $artwork = $cprefs->get('artwork');
  92. my $disp_width = $cprefs->get('width') || 128;
  93. # if artwork is in main display, reduce width but when artwork is (0,0) fake it
  94. my $width = ($artwork->{'enable'} && $artwork->{'y'} < 32 && $artwork->{'x'}) ? $artwork->{'x'} : $disp_width;
  95. my $width_low = ($artwork->{'enable'} && $artwork->{'x'} && ($artwork->{'y'} >= 32 || $disp_width - $artwork->{'x'} > 32)) ? $artwork->{'x'} : $disp_width;
  96. my $small_VU = $cprefs->get('small_VU');
  97. my $spectrum = $cprefs->get('spectrum');
  98. my $small_spectrum_pos = { x => $width - int ($spectrum->{small}->{size} * $width / 100),
  99. width => int ($spectrum->{small}->{size} * $width / 100),
  100. };
  101. my $small_VU_pos = { x => $width - int ($small_VU * $width / 100),
  102. width => int ($small_VU * $width / 100),
  103. };
  104. my @modes = (
  105. # mode 0
  106. { desc => ['BLANK'],
  107. bar => 0, secs => 0, width => $width,
  108. params => [$VISUALIZER_NONE] },
  109. # mode 1
  110. { desc => ['PROGRESS_BAR'],
  111. bar => 1, secs => 0, width => $width,
  112. params => [$VISUALIZER_NONE] },
  113. # mode 2
  114. { desc => ['ELAPSED'],
  115. bar => 0, secs => 1, width => $width,
  116. params => [$VISUALIZER_NONE] },
  117. # mode 3
  118. { desc => ['ELAPSED', 'AND', 'PROGRESS_BAR'],
  119. bar => 1, secs => 1, width => $width,
  120. params => [$VISUALIZER_NONE] },
  121. # mode 4
  122. { desc => ['REMAINING'],
  123. bar => 0, secs => -1, width => $width,
  124. params => [$VISUALIZER_NONE] },
  125. # mode 5
  126. { desc => ['CLOCK'],
  127. bar => 0, secs => 0, width => $width, clock => 1,
  128. params => [$VISUALIZER_NONE] },
  129. # mode 6
  130. { desc => ['SETUP_SHOWBUFFERFULLNESS'],
  131. bar => 0, secs => 0, width => $width, fullness => 1,
  132. params => [$VISUALIZER_NONE] },
  133. # mode 7
  134. { desc => ['VISUALIZER_VUMETER_SMALL'],
  135. bar => 0, secs => 0, width => $width, _width => -$small_VU_pos->{'width'},
  136. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space)
  137. params => [$VISUALIZER_VUMETER_ESP32, $small_VU_pos->{'width'}, 32, $small_VU_pos->{'x'}, 0, 2] },
  138. # mode 8
  139. { desc => ['VISUALIZER_SPECTRUM_ANALYZER_SMALL'],
  140. bar => 0, secs => 0, width => $width, _width => -$small_spectrum_pos->{'width'},
  141. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space, #bars, scale)
  142. 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}] },
  143. # mode 9
  144. { desc => ['VISUALIZER_VUMETER'],
  145. bar => 0, secs => 0, width => $width,
  146. params => [$VISUALIZER_VUMETER_ESP32, $width_low, 0] },
  147. # mode 10
  148. { desc => ['VISUALIZER_ANALOG_VUMETER'],
  149. bar => 0, secs => 0, width => $width,
  150. params => [$VISUALIZER_VUMETER_ESP32, $width_low, 1] },
  151. # mode 11
  152. { desc => ['VISUALIZER_SPECTRUM_ANALYZER'],
  153. bar => 0, secs => 0, width => $width,
  154. # extra parameters (bars)
  155. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, $width_low, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  156. );
  157. my @extra = (
  158. # mode E1
  159. { desc => ['VISUALIZER_VUMETER', 'AND', 'ELAPSED'],
  160. bar => 0, secs => 1, width => $width,
  161. params => [$VISUALIZER_VUMETER_ESP32, $width_low, 0] },
  162. # mode E2
  163. { desc => ['VISUALIZER_ANALOG_VUMETER', 'AND', 'ELAPSED'],
  164. bar => 0, secs => 1, width => $width,
  165. params => [$VISUALIZER_VUMETER_ESP32, $width_low, 1] },
  166. # mode E3
  167. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'ELAPSED'],
  168. bar => 0, secs => 1, width => $width,
  169. # extra parameters (bars)
  170. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, $width_low, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  171. # mode E4
  172. { desc => ['VISUALIZER_VUMETER', 'AND', 'REMAINING'],
  173. bar => 0, secs => -1, width => $width,
  174. params => [$VISUALIZER_VUMETER_ESP32, $width_low, 0] },
  175. # mode E5
  176. { desc => ['VISUALIZER_ANALOG_VUMETER', 'AND', 'REMAINING'],
  177. bar => 0, secs => -1, width => $width,
  178. params => [$VISUALIZER_VUMETER_ESP32, $width_low, 1] },
  179. # mode E6
  180. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'REMAINING'],
  181. bar => 0, secs => -1, width => $width,
  182. # extra parameters (bars)
  183. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, $width_low, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  184. # mode E7
  185. { desc => ['VISUALIZER_VUMETER', 'AND', 'PROGRESS_BAR', 'AND', 'REMAINING'],
  186. bar => 1, secs => -1, width => $width,
  187. params => [$VISUALIZER_VUMETER_ESP32, $width_low, 0] },
  188. # mode E8
  189. { desc => ['VISUALIZER_ANALOG_VUMETER', 'AND', 'PROGRESS_BAR', 'AND', 'REMAINING'],
  190. bar => 1, secs => -1, width => $width,
  191. params => [$VISUALIZER_VUMETER_ESP32, $width_low, 1] },
  192. # mode E9
  193. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'PROGRESS_BAR', 'AND', 'REMAINING'],
  194. bar => 1, secs => -1, width => $width,
  195. # extra parameters (bars)
  196. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, $width_low, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  197. );
  198. @modes = (@modes, @extra) if $cprefs->get('height') > 32;
  199. return \@modes;
  200. }
  201. 1;