Graphics.pm 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. use Data::Dumper;
  18. sub new {
  19. my $class = shift;
  20. my $client = shift;
  21. my $display = $class->SUPER::new($client);
  22. $display->init_accessor(
  23. modes => $display->build_modes,
  24. vfdmodel => 'graphic-<width>x32', # doesn't matter much
  25. );
  26. return $display;
  27. }
  28. =comment
  29. sub modes {
  30. return \@modes;
  31. }
  32. =cut
  33. sub nmodes {
  34. # -1 for LMS bug workaround
  35. return scalar(@{shift->modes}) - 1;
  36. }
  37. sub displayWidth {
  38. my $display = shift;
  39. my $client = $display->client;
  40. # if we're showing the always-on visualizer & the current buttonmode
  41. # hasn't overridden, then use the playing display mode to index
  42. # into the display width, otherwise, it's fullscreen.
  43. my $mode = 0;
  44. if ( $display->showVisualizer() && !defined($client->modeParam('visu')) ) {
  45. my $cprefs = preferences('server')->client($client);
  46. $mode = $cprefs->get('playingDisplayModes')->[ $cprefs->get('playingDisplayMode') ];
  47. }
  48. if ($display->widthOverride) {
  49. return $display->widthOverride + ($display->modes->[$mode || 0]{_width} || 0);
  50. } else {
  51. return $display->modes->[$mode || 0]{width};
  52. }
  53. }
  54. sub brightnessMap {
  55. return (65535, 10, 50, 100, 200);
  56. }
  57. =comment
  58. sub bytesPerColumn {
  59. return 4;
  60. }
  61. =cut
  62. # I don't think LMS renderer handles properly screens other than 32 pixels. It
  63. # seems that all we get is a 32 pixel-tall data with anything else padded to 0
  64. # i.e. if we try 64 pixels height, bytes 0..3 and 4..7 will contains the same
  65. # pattern than the 32 pixels version, where one would have expected bytes 4..7
  66. # to be empty
  67. sub displayHeight {
  68. return 32;
  69. }
  70. =comment
  71. sub vfdmodel {
  72. return 'graphic-'.$width.'x32';
  73. }
  74. =cut
  75. sub build_modes {
  76. my $client = shift->client;
  77. print("CLIENT IN BUILD MODE $client\n");
  78. my $cprefs = $prefs->client($client);
  79. my $width = shift || $cprefs->get('width') || $prefs->get('width') || 128;
  80. my $small_VU = shift || $cprefs->get('small_vu') || 0.15;
  81. my $small_spectrum = shift || $cprefs->get('small_spectrum') || 0.25;
  82. my $spectrum_bar = shift || $cprefs->get('spectrum_bar') || { 'small' => 0.1875, 'full' => 0.125 };
  83. my $spectrum_scale = shift || $cprefs->get('spectrum_scale') || $prefs->get('spectrum_scale') || 50;
  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),
  116. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space)
  117. params => [$VISUALIZER_VUMETER, int ($small_VU* $width), 32, int -($small_VU*$width), 0, 2] },
  118. # mode 8
  119. { desc => ['VISUALIZER_SPECTRUM_ANALYZER_SMALL'],
  120. bar => 0, secs => 0, width => $width, _width => int -($small_spectrum*$width),
  121. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), left_space, bars)
  122. params => [$VISUALIZER_SPECTRUM_ANALYZER, int ($small_spectrum*$width), 32, int -($small_spectrum*$width), 0, 2, int ($small_spectrum*$width*$spectrum_bar->{small}), $spectrum_scale] },
  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_bar->{full}), $spectrum_scale] },
  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_bar->{full}), $spectrum_scale] },
  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_bar->{full}), $spectrum_scale] },
  150. # dummy for LMS bug workaround
  151. { desc => [], bar => 0, secs => -1, width => $width,params => [] },
  152. );
  153. return \@modes;
  154. }
  155. 1;