Graphics.pm 5.8 KB

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