summaryrefslogtreecommitdiff
path: root/span.c
blob: de007ea200d6d4195a0ec7ed1b92fde262e37d40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * targavfd plugin for VDR (C++)
 *
 * (C) 2010 Andreas Brachold <vdr07 AT deltab de>
 *     Span handling suggest by span-plugin
 *
 * This targavfd plugin is free software: you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as published 
 * by the Free Software Foundation, version 3 of the License.
 *
 * See the files README and COPYING for details.
 *
 */

#include "targavfd.h"
#include "span.h"

/*
 * Spectrum Analyzer visualization
 * need as middleware span-plugin
 */
bool cVFDWatch::RenderSpectrumAnalyzer()
{
  bool bDraw = false;
  /*if ( theSetup.m_bEnableSpectrumAnalyzer )*/ {
    if (cPluginManager::CallFirstService(SPAN_GET_BAR_HEIGHTS_ID, NULL)) {
      Span_GetBarHeights_v1_0 gbh;

      int bands = 19;
      int falloff = 8;
      int i,x,y;

      unsigned int *barHeights = new unsigned int[bands];
      unsigned int *barHeightsLeftChannel = new unsigned int[bands];
      unsigned int *barHeightsRightChannel = new unsigned int[bands];
      unsigned int volumeLeftChannel;
      unsigned int volumeRightChannel;
      unsigned int volumeBothChannels;
      unsigned int *barPeaksBothChannels = new unsigned int[bands];
      unsigned int *barPeaksLeftChannel  = new unsigned int[bands];
      unsigned int *barPeaksRightChannel = new unsigned int[bands];

      gbh.bands                     = bands;
      gbh.barHeights                = barHeights;
      gbh.barHeightsLeftChannel     = barHeightsLeftChannel;
      gbh.barHeightsRightChannel    = barHeightsRightChannel;
      gbh.volumeLeftChannel         = &volumeLeftChannel;
      gbh.volumeRightChannel        = &volumeRightChannel;
      gbh.volumeBothChannels        = &volumeBothChannels;
      gbh.name                      = "targavfd";
      gbh.falloff                   = falloff;
      gbh.barPeaksBothChannels      = barPeaksBothChannels;
      gbh.barPeaksLeftChannel       = barPeaksLeftChannel;
      gbh.barPeaksRightChannel      = barPeaksRightChannel;

      if ( cPluginManager::CallFirstService(SPAN_GET_BAR_HEIGHTS_ID, &gbh )) {

        int barWidth = (this->Width() - bands)/bands;
        int saEndY = this->Height();
  
        this->clear(); 

        for ( i=0; i < bands; i++ ) {
          // draw bar
          y = (barHeights[i]*(saEndY))/SPAN_HEIGHT;
          x = (barWidth*i) + i;
          this->Rectangle(x,
              saEndY,
              x + barWidth - 1,
              saEndY - y,
              true);

          // draw peak
          y = (barPeaksBothChannels[i]*(saEndY))/SPAN_HEIGHT;
          if ( y   > 0) {
            this->Rectangle(x,
                saEndY - y,
                x + barWidth - 1,
                saEndY - y,
                true);
          }
        }
        bDraw = true;
      }
      delete [] barHeights;
      delete [] barHeightsLeftChannel;
      delete [] barHeightsRightChannel;
      delete [] barPeaksBothChannels;
      delete [] barPeaksLeftChannel;
      delete [] barPeaksRightChannel;
    }
  }
  return bDraw;
}

/*
 * Report presence of Spectrum Analyzer visualization
 * from span-plugin requested 
 */
bool cPluginTargaVFD::Service(const char *Id, void *Data) {
  if (Id && strcmp(Id, SPAN_CLIENT_CHECK_ID) == 0) {
    if ( /*theSetup.m_bEnableSpectrumAnalyzer &&*/ (Data != NULL) ) {
      *((Span_Client_Check_1_0*)Data)->isActive = true;
    }
    return true;
  }
  return false;
}