Graphics.pm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 $width = $prefs->get('width') || 128;
  13. my @modes = (
  14. # mode 0
  15. { desc => ['BLANK'],
  16. bar => 0, secs => 0, width => $width,
  17. params => [$VISUALIZER_NONE] },
  18. # mode 1
  19. { desc => ['PROGRESS_BAR'],
  20. bar => 1, secs => 0, width => $width,
  21. params => [$VISUALIZER_NONE] },
  22. # mode 2
  23. { desc => ['ELAPSED'],
  24. bar => 0, secs => 1, width => $width,
  25. params => [$VISUALIZER_NONE] },
  26. # mode 3
  27. { desc => ['ELAPSED', 'AND', 'PROGRESS_BAR'],
  28. bar => 1, secs => 1, width => $width,
  29. params => [$VISUALIZER_NONE] },
  30. # mode 4
  31. { desc => ['REMAINING'],
  32. bar => 0, secs => -1, width => $width,
  33. params => [$VISUALIZER_NONE] },
  34. # mode 5
  35. { desc => ['CLOCK'],
  36. bar => 0, secs => 0, width => $width, clock => 1,
  37. params => [$VISUALIZER_NONE] },
  38. # mode 6
  39. { desc => ['SETUP_SHOWBUFFERFULLNESS'],
  40. bar => 0, secs => 0, width => $width, fullness => 1,
  41. params => [$VISUALIZER_NONE] },
  42. # mode 7
  43. { desc => ['VISUALIZER_VUMETER_SMALL'],
  44. bar => 0, secs => 0, width => $width, _width => -20,
  45. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), bars, left space)
  46. params => [$VISUALIZER_VUMETER, 20, 32, -20, 0, 2] },
  47. # mode 8
  48. { desc => ['VISUALIZER_SPECTRUM_ANALYZER_SMALL'],
  49. bar => 0, secs => 0, width => $width, _width => -32,
  50. # extra parameters (width, height, col (< 0 = from right), row (< 0 = from bottom), bars, left space)
  51. params => [$VISUALIZER_SPECTRUM_ANALYZER, 32, 32, -32, 0, 2, 6] },
  52. # mode 9
  53. { desc => ['VISUALIZER_VUMETER'],
  54. bar => 0, secs => 0, width => $width,
  55. params => [$VISUALIZER_VUMETER] },
  56. # mode 10
  57. { desc => ['VISUALIZER_SPECTRUM_ANALYZER'],
  58. bar => 0, secs => 0, width => $width,
  59. # extra parameters (bars)
  60. params => [$VISUALIZER_SPECTRUM_ANALYZER, 16] },
  61. # mode 11
  62. { desc => ['VISUALIZER_VUMETER', 'AND', 'ELAPSED'],
  63. bar => 0, secs => 1, width => $width,
  64. params => [$VISUALIZER_VUMETER] },
  65. # mode 12
  66. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'ELAPSED'],
  67. bar => 0, secs => 1, width => $width,
  68. # extra parameters (bars)
  69. params => [$VISUALIZER_SPECTRUM_ANALYZER, 16] },
  70. # mode 13
  71. { desc => ['VISUALIZER_VUMETER', 'AND', 'REMAINING'],
  72. bar => 0, secs => -1, width => $width,
  73. params => [$VISUALIZER_VUMETER] },
  74. # mode 14
  75. { desc => ['VISUALIZER_SPECTRUM_ANALYZER', 'AND', 'REMAINING'],
  76. bar => 0, secs => -1, width => $width,
  77. # extra parameters (bars)
  78. params => [$VISUALIZER_SPECTRUM_ANALYZER, 16] },
  79. );
  80. sub modes {
  81. return \@modes;
  82. }
  83. sub nmodes {
  84. return $#modes;
  85. }
  86. sub displayWidth {
  87. my $display = shift;
  88. my $client = $display->client;
  89. # if we're showing the always-on visualizer & the current buttonmode
  90. # hasn't overridden, then use the playing display mode to index
  91. # into the display width, otherwise, it's fullscreen.
  92. my $mode = 0;
  93. if ( $display->showVisualizer() && !defined($client->modeParam('visu')) ) {
  94. my $cprefs = preferences('server')->client($client);
  95. $mode = $cprefs->get('playingDisplayModes')->[ $cprefs->get('playingDisplayMode') ];
  96. }
  97. if ($display->widthOverride) {
  98. return $display->widthOverride + ($display->modes->[$mode || 0]{_width} || 0);
  99. } else {
  100. return $display->modes->[$mode || 0]{width};
  101. }
  102. }
  103. # I don't think LMS renderer handles properly screens other than 32 pixels. It
  104. # seems that all we get is a 32 pixel-tall data with anything else padded to 0
  105. # i.e. if we try 64 pixels height, bytes 0..3 and 4..7 will contains the same
  106. # pattern than the 32 pixels version, where one would have expected bytes 4..7
  107. # to be empty
  108. sub brightnessMap {
  109. return (65535, 10, 50, 100, 200);
  110. }
  111. =comment
  112. sub bytesPerColumn {
  113. return 4;
  114. }
  115. =cut
  116. sub displayHeight {
  117. return 32;
  118. }
  119. sub updateWidth {
  120. my ($display, $width) = @_;
  121. foreach my $mode (@{$display->modes}) {
  122. $mode->{width} = $width + 1 + $mode->{_width} || 0;
  123. }
  124. }
  125. sub vfdmodel {
  126. return 'graphic-'.$width.'x32';
  127. }
  128. 1;