~ubuntu-branches/ubuntu/trusty/vdr-plugin-xineliboutput/trusty-proposed

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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * equalizer.c: audio equalizer OSD control
 *
 * See the main source file 'xineliboutput.c' for copyright information and
 * how to reach the author.
 *
 * $Id: equalizer.c,v 1.4 2007/10/15 00:15:07 phintuka Exp $
 *
 */

#include <vdr/config.h>

#include "config.h"
#include "device.h"
#include "equalizer.h"

cEqualizer::cEqualizer() : cOsdObject()
{
  m_Values = new int[AUDIO_EQ_count];
  memcpy(m_Values, xc.audio_equalizer, sizeof(xc.audio_equalizer));
  m_Osd = NULL;
  m_Current = 0;
}

cEqualizer::~cEqualizer()
{
  delete m_Osd;
  delete m_Values;
}

#define OSD_W (220)
#define OSD_H (220)
#define OSD_X (720-50-OSD_W)
#define OSD_Y (576-50-OSD_H)
/* dvbdevice requires bpp*width to be n*8 */

#define ADJUST_MIN  (-100)
#define ADJUST_MAX  (100)
#define ADJUST_STEP (5)

void cEqualizer::Show()
{
  tArea areas [] = { {0, 0, OSD_W - 1, OSD_H - 1, 4} };

#if VDRVERSNUM >= 10509
  m_Osd = cOsdProvider::NewOsd(OSD_X, OSD_Y, 0);
#else
  m_Osd = cOsdProvider::NewOsd(OSD_X, OSD_Y);
#endif

  if(m_Osd) {
    if (m_Osd->CanHandleAreas(areas, sizeof(areas) / sizeof(tArea) ) == oeOk) {
      m_Osd->SetAreas(areas, sizeof(areas) / sizeof(tArea));
      m_Osd->Flush();
      DrawBackground();
      DrawBar(0,true);
      for(int i=1; i<AUDIO_EQ_count; i++) 
	DrawBar(i);
    }
  }
}

eOSState cEqualizer::ProcessKey(eKeys key)
{
  eOSState state = cOsdObject::ProcessKey(key);
  if (state == osUnknown) {
    switch (key & ~k_Repeat) {
      case kDown:  
	m_Values[m_Current] -= ADJUST_STEP;
	if(m_Values[m_Current] < ADJUST_MIN)
	  m_Values[m_Current] = ADJUST_MIN;
	DrawBar(m_Current,true);
	cXinelibDevice::Instance().ConfigurePostprocessing(xc.deinterlace_method, xc.audio_delay, xc.audio_compression, m_Values, xc.audio_surround, xc.speaker_type);
	break;
      case kUp:
	m_Values[m_Current] += ADJUST_STEP;
	if(m_Values[m_Current] > ADJUST_MAX)
	  m_Values[m_Current] = ADJUST_MAX;
	DrawBar(m_Current,true);
	cXinelibDevice::Instance().ConfigurePostprocessing(xc.deinterlace_method, xc.audio_delay, xc.audio_compression, m_Values, xc.audio_surround, xc.speaker_type);
	break;
      case kLeft: 
	if(m_Current>0) {
	  DrawBar(m_Current);	  
	  m_Current--;
	  DrawBar(m_Current, true);
	}
	break;
      case kRight:
	if(m_Current+1 < AUDIO_EQ_count) {
	  DrawBar(m_Current);
	  m_Current++;
	  DrawBar(m_Current, true);
	}
	break;
      case kBack:
        cXinelibDevice::Instance().ConfigurePostprocessing(xc.deinterlace_method, xc.audio_delay, xc.audio_compression, xc.audio_equalizer, xc.audio_surround, xc.speaker_type);
	return osEnd;
      case kOk:
        memcpy(xc.audio_equalizer, m_Values, sizeof(xc.audio_equalizer));
	return osEnd;
    }
  }

  return state;
}

#define COL_BORDER     0xffb0b0b0
#define COL_BG         0x7f7f7f7f
#define COL_BAR        0xff000000
#define COL_BAR_SEL    0xffff0000
#define COL_BAR_ON     0xff00FF00
#define COL_BAR_OFF    0xff000000
#define COL_BAR_BORDER 0xff7f7f7f

void cEqualizer::DrawBackground()
{
  // border
  m_Osd->DrawRectangle(0, 0, OSD_W - 1, OSD_H - 1, COL_BORDER);
  m_Osd->DrawRectangle(1, 1, OSD_W - 2, OSD_H - 2, COL_BORDER);
  // background
  m_Osd->DrawRectangle(2, 2, OSD_W - 3, OSD_H - 3, COL_BG);
  // line
  m_Osd->DrawRectangle(5, 10+100-1, OSD_W-6, 10+100, COL_BAR);
  // commit
  m_Osd->Flush();
}

void cEqualizer::DrawBar(int Index, bool Selected)
{
  // bar
  if(Selected)
    m_Osd->DrawRectangle(10+20*Index, 10, 10+20*Index+7, OSD_H - 10, COL_BAR_SEL);
  else
    m_Osd->DrawRectangle(10+20*Index, 10, 10+20*Index+7, OSD_H - 10, COL_BAR);
  // off
  m_Osd->DrawRectangle(12+20*Index, 10, 10+20*Index+5, OSD_H - 10, COL_BAR_OFF);
  // on
  if(m_Values[Index]>0) 
    m_Osd->DrawRectangle(12+20*Index, 10+100-m_Values[Index], 10+20*Index+5, 10+100, COL_BAR_ON);
  else
    m_Osd->DrawRectangle(12+20*Index, 10+100, 10+20*Index+5, 10+100-m_Values[Index], COL_BAR_ON);
  // line
  m_Osd->DrawRectangle(12+20*Index, 10+100-1, 10+20*Index+5, 10+100, COL_BAR_ON);

  m_Osd->Flush();
}