Graphics.pm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. return $display->widthOverride + ($display->modes->[$mode || 0]{_width} || 0);
  58. } else {
  59. return $display->modes->[$mode || 0]{width};
  60. }
  61. }
  62. sub brightnessMap {
  63. return (65535, 10, 50, 100, 200);
  64. }
  65. =comment
  66. sub bytesPerColumn {
  67. return 4;
  68. }
  69. =cut
  70. # I don't think LMS renderer handles properly screens other than 32 pixels. It
  71. # seems that all we get is a 32 pixel-tall data with anything else padded to 0
  72. # i.e. if we try 64 pixels height, bytes 0..3 and 4..7 will contains the same
  73. # pattern than the 32 pixels version, where one would have expected bytes 4..7
  74. # to be empty
  75. sub displayHeight {
  76. return 32;
  77. }
  78. sub build_modes {
  79. my $client = shift->client;
  80. my $cprefs = $prefs->client($client);
  81. my $width = shift || $cprefs->get('width') || 128;
  82. my $small_VU = $cprefs->get('small_VU');
  83. my $spectrum = $cprefs->get('spectrum');
  84. my @modes = (
  85. # mode 0
  86. { desc => ['BLANK'],
  87. bar => 0, secs => 0, width => $width,
  88. params => [$VISUALIZER_NONE] },
  89. # mode 1
  90. { desc => ['PROGRESS_BAR'],
  91. bar => 1, secs => 0, width => $width,
  92. params => [$VISUALIZER_NONE] },
  93. # mode 2
  94. { desc => ['ELAPSED'],
  95. bar => 0, secs => 1, width => $width,
  96. params => [$VISUALIZER_NONE] },
  97. # mode 3
  98. { desc => ['ELAPSED', 'AND', 'PROGRESS_BAR'],
  99. bar => 1, secs => 1, width => $width,
  100. params => [$VISUALIZER_NONE] },
  101. # mode 4
  102. { desc => ['REMAINING'],
  103. bar => 0, secs => -1, width => $width,
  104. params => [$VISUALIZER_NONE] },
  105. # mode 5
  106. { desc => ['CLOCK'],
  107. bar => 0, secs => 0, width => $width, clock => 1,
  108. params => [$VISUALIZER_NONE] },
  109. # mode 6
  110. { desc => ['SETUP_SHOWBUFFERFULLNESS'],
  111. bar => 0, secs => 0, width => $width, fullness => 1,
  112. params => [$VISUALIZER_NONE] },
  113. # mode 7
  114. { desc => ['VISUALIZER_VUMETER_SMALL'],
  115. bar => 0, secs => 0, width => $width, _width => int -($small_VU*$width/100),
  116. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space)
  117. params => [$VISUALIZER_VUMETER, int ($small_VU*$width/100), 32, int -($small_VU*$width/100), 0, 2] },
  118. # mode 8
  119. { desc => ['VISUALIZER_SPECTRUM_ANALYZER_SMALL'],
  120. bar => 0, secs => 0, width => $width, _width => int -($spectrum->{small}->{size}*$width/100),
  121. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space, bars)
  122. params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($spectrum->{small}->{size}*$width/100), 32, int -($spectrum->{small}->{size}*$width/100), 0, 2, int ($spectrum->{small}->{size}/100*$width/$spectrum->{small}->{band}), $spectrum->{scale}/100] },
  123. # mode 9
  124. { desc => ['VISUALIZER_VUMETER'],
  125. bar => 0, secs => 0, width => $width,
  126. params => [$VISUALIZER_VUMETER] },
  127. # mode 10
  128. { desc => ['VISUALIZER_SPECTRUM_ANALYZER'],
  129. bar => 0, secs => 0, width => $width,
  130. # extra parameters (bars)
  131. params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}/100] },
  132. # mode 11
  133. { desc => ['VISUALIZER_VUMETER', 'AND', 'ELAPSED'],
  134. bar => 0, secs => 1, width => $width,
  135. params => [$VISUALIZER_VUMETER] },
  136. # mode 12
  137. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'ELAPSED'],
  138. bar => 0, secs => 1, width => $width,
  139. # extra parameters (bars)
  140. params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}/100] },
  141. # mode 13
  142. { desc => ['VISUALIZER_VUMETER', 'AND', 'REMAINING'],
  143. bar => 0, secs => -1, width => $width,
  144. params => [$VISUALIZER_VUMETER] },
  145. # mode 14
  146. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'REMAINING'],
  147. bar => 0, secs => -1, width => $width,
  148. # extra parameters (bars)
  149. params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($width/$spectrum->{full}->{band}), $spectrum->{scale}/100] },
  150. );
  151. return \@modes;
  152. }
  153. 1;