2
0

Graphics.pm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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) {
  64. return $artwork->{x} + ($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 (65535, 10, 50, 100, 200);
  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 $width = $cprefs->get('width') || 128;
  92. my $artwork = $cprefs->get('artwork');
  93. # if artwork is in main display, reduce width
  94. $width = $artwork->{'x'} if $artwork->{'enable'} && $artwork->{y} < 32;
  95. my $small_VU = $cprefs->get('small_VU');
  96. my $spectrum = $cprefs->get('spectrum');
  97. my $small_spectrum_pos = { x => $width - int ($spectrum->{small}->{size} * $width / 100),
  98. width => int ($spectrum->{small}->{size} * $width / 100),
  99. };
  100. my $small_VU_pos = { x => $width - int ($small_VU * $width / 100),
  101. width => int ($small_VU * $width / 100),
  102. };
  103. my @modes = (
  104. # mode 0
  105. { desc => ['BLANK'],
  106. bar => 0, secs => 0, width => $width,
  107. params => [$VISUALIZER_NONE] },
  108. # mode 1
  109. { desc => ['PROGRESS_BAR'],
  110. bar => 1, secs => 0, width => $width,
  111. params => [$VISUALIZER_NONE] },
  112. # mode 2
  113. { desc => ['ELAPSED'],
  114. bar => 0, secs => 1, width => $width,
  115. params => [$VISUALIZER_NONE] },
  116. # mode 3
  117. { desc => ['ELAPSED', 'AND', 'PROGRESS_BAR'],
  118. bar => 1, secs => 1, width => $width,
  119. params => [$VISUALIZER_NONE] },
  120. # mode 4
  121. { desc => ['REMAINING'],
  122. bar => 0, secs => -1, width => $width,
  123. params => [$VISUALIZER_NONE] },
  124. # mode 5
  125. { desc => ['CLOCK'],
  126. bar => 0, secs => 0, width => $width, clock => 1,
  127. params => [$VISUALIZER_NONE] },
  128. # mode 6
  129. { desc => ['SETUP_SHOWBUFFERFULLNESS'],
  130. bar => 0, secs => 0, width => $width, fullness => 1,
  131. params => [$VISUALIZER_NONE] },
  132. # mode 7
  133. { desc => ['VISUALIZER_VUMETER_SMALL'],
  134. bar => 0, secs => 0, width => $width, _width => -$small_VU_pos->{'width'},
  135. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space)
  136. params => [$VISUALIZER_VUMETER_ESP32, $small_VU_pos->{'width'}, 32, $small_VU_pos->{'x'}, 0, 2] },
  137. # mode 8
  138. { desc => ['VISUALIZER_SPECTRUM_ANALYZER_SMALL'],
  139. bar => 0, secs => 0, width => $width, _width => -$small_spectrum_pos->{'width'},
  140. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space, #bars, scale)
  141. 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}] },
  142. # mode 9
  143. { desc => ['VISUALIZER_VUMETER'],
  144. bar => 0, secs => 0, width => $width,
  145. params => [$VISUALIZER_VUMETER_ESP32, 0] },
  146. # mode 10
  147. { desc => ['VISUALIZER_ANALOG_VUMETER'],
  148. bar => 0, secs => 0, width => $width,
  149. params => [$VISUALIZER_VUMETER_ESP32, 1] },
  150. # mode 11
  151. { desc => ['VISUALIZER_SPECTRUM_ANALYZER'],
  152. bar => 0, secs => 0, width => $width,
  153. # extra parameters (bars)
  154. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  155. );
  156. my @extra = (
  157. # mode E1
  158. { desc => ['VISUALIZER_VUMETER', 'AND', 'ELAPSED'],
  159. bar => 0, secs => 1, width => $width,
  160. params => [$VISUALIZER_VUMETER_ESP32, 0] },
  161. # mode E2
  162. { desc => ['VISUALIZER_ANALOG_VUMETER', 'AND', 'ELAPSED'],
  163. bar => 0, secs => 1, width => $width,
  164. params => [$VISUALIZER_VUMETER_ESP32, 1] },
  165. # mode E3
  166. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'ELAPSED'],
  167. bar => 0, secs => 1, width => $width,
  168. # extra parameters (bars)
  169. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  170. # mode E4
  171. { desc => ['VISUALIZER_VUMETER', 'AND', 'REMAINING'],
  172. bar => 0, secs => -1, width => $width,
  173. params => [$VISUALIZER_VUMETER_ESP32, 0] },
  174. # mode E5
  175. { desc => ['VISUALIZER_ANALOG_VUMETER', 'AND', 'REMAINING'],
  176. bar => 0, secs => -1, width => $width,
  177. params => [$VISUALIZER_VUMETER_ESP32, 1] },
  178. # mode E6
  179. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'REMAINING'],
  180. bar => 0, secs => -1, width => $width,
  181. # extra parameters (bars)
  182. params => [$VISUALIZER_SPECTRUM_ANALYZER_ESP32, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}] },
  183. );
  184. @modes = (@modes, @extra) if $cprefs->get('height') > 32;
  185. return \@modes;
  186. }
  187. 1;