Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / signalstatus.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2016-2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20
21 #ifdef HAVE_DVB
22
23 #include "bctitle.h"
24 #include "bccolors.h"
25 #include "devicedvbinput.h"
26 #include "fonts.h"
27 #include "signalstatus.h"
28
29 #include <unistd.h>
30
31
32 SignalStatus::SignalStatus(BC_WindowBase *wdw, int x, int y)
33  : BC_SubWindow(x, y, xS(100), yS(35))
34 {
35         this->wdw = wdw;
36         dvb_input = 0;
37
38         channel_title = 0;
39         lck_x = lck_y = 0;
40         crr_x = crr_y = 0;
41         pwr_x = pwr_y = 0;
42         snr_x = snr_y = 0;
43         ber_x = ber_y = 0;
44         unc_x = unc_y = 0;
45 }
46
47 SignalStatus::~SignalStatus()
48 {
49         if( dvb_input )
50                 dvb_input->set_signal_status(0);
51 }
52
53
54 void SignalStatus::create_objects()
55 {
56         clear_box(0,0,get_w(),get_h());
57         int x = 0, y = 0;
58         channel_title = new BC_Title(x, y, " ", SMALLFONT, GREEN);
59         add_subwindow(channel_title);
60         y += channel_title->get_h();
61         BC_Title *title;
62         add_subwindow(title = new BC_Title(x, y, "lk:", SMALLFONT, YELLOW));
63         lck_x = x + title->get_w() + pad0;
64         lck_y = y + pad0;
65         int x1 = lck_x + lck_w + pad1;
66         int y1 = y + title->get_h();
67         add_subwindow(title = new BC_Title(x, y1, "cr:", SMALLFONT, YELLOW));
68         crr_x = lck_x;
69         crr_y = y1 + pad0;
70         add_subwindow(title = new BC_Title(x1, y, "pwr", SMALLFONT, YELLOW));
71         pwr_x = x1 + title->get_w() + pad0;
72         pwr_y = y + pad0;
73         snr_x = pwr_x;
74         snr_y = pwr_y + pwr_h;
75         add_subwindow(title = new BC_Title(x1, y1, "err", SMALLFONT, YELLOW));
76         ber_x = pwr_x;
77         ber_y = y1 + pad0;
78         unc_x = ber_x;
79         unc_y = ber_y + ber_h;
80 }
81
82 int SignalStatus::calculate_w(BC_WindowBase *wdw)
83 {
84         return BC_Title::calculate_w(wdw, "lk:", SMALLFONT) + pad0 + lck_w + pad1 +
85                 BC_Title::calculate_w(wdw, "pwr", SMALLFONT) + pad0 + pwr_w;
86 }
87
88 int SignalStatus::calculate_h(BC_WindowBase *wdw)
89 {
90         return 3*BC_Title::calculate_h(wdw, "lk:", SMALLFONT);
91 }
92
93 void SignalStatus::update_lck(int v)
94 {
95         set_color(v>0 ? GREEN : RED);
96         draw_box(lck_x, lck_y, lck_w, lck_h);
97 }
98
99 void SignalStatus::update_crr(int v)
100 {
101         set_color(v>0 ? GREEN : RED);
102         draw_box(crr_x, crr_y, crr_w, crr_h);
103 }
104
105 void SignalStatus::update_pwr(int v)
106 {
107         if( v < 0 ) v = 0;
108         int w0 = (v*pwr_w) / 65535, w1 = pwr_w-w0;
109         if( w0 > 0 ) { set_color(GREEN); draw_box(pwr_x, pwr_y, w0, pwr_h); }
110         if( w1 > 0 ) clear_box(pwr_x+w0, pwr_y, w1, pwr_h);
111 }
112
113 void SignalStatus::update_snr(int v)
114 {
115         if( v < 0 ) v = 0;
116         int w0 = (v*snr_w) / 65535, w1 = pwr_w-w0;
117         if( w0 > 0 ) { set_color(BLUE); draw_box(snr_x, snr_y, w0, snr_h); }
118         if( w1 > 0 ) clear_box(snr_x+w0, snr_y, w1, snr_h);
119 }
120
121 void SignalStatus::update_ber(int v)
122 {
123         if( v < 0 ) v = 0;
124         int b = 0;
125         while( v > 0 ) { ++b; v>>=1; }
126         int w0 = (ber_w*b)/16, w1 = ber_w-w0;
127         if( w0 > 0 ) { set_color(YELLOW); draw_box(ber_x, ber_y, w0, ber_h); }
128         if( w1 > 0 ) clear_box(ber_x+w0, ber_y, w1, ber_h);
129 }
130
131 void SignalStatus::update_unc(int v)
132 {
133         if( v < 0 ) v = 0;
134         int b = 0;
135         while( v > 0 ) { ++b; v>>=1; }
136         int w0 = (unc_w*b)/16, w1 = unc_w-w0;
137         if( w0 > 0 ) { set_color(RED); draw_box(unc_x, unc_y, w0, unc_h); }
138         if( w1 > 0 ) clear_box(unc_x+w0, unc_y, w1, unc_h);
139 }
140
141
142 void SignalStatus::update()
143 {
144         channel_title->update(dvb_input->channel_title());
145         update_lck(dvb_input->signal_lck);  update_crr(dvb_input->signal_crr);
146         update_pwr(dvb_input->signal_pwr);  update_snr(dvb_input->signal_snr);
147         update_ber(dvb_input->signal_ber);  update_unc(dvb_input->signal_unc);
148         flash();
149 }
150
151 #endif