change copy packed clip to unpacked in move_edits
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / signalstatus.C
1 #ifdef HAVE_DVB
2
3 #include "bctitle.h"
4 #include "bccolors.h"
5 #include "devicedvbinput.h"
6 #include "fonts.h"
7 #include "signalstatus.h"
8
9 #include <unistd.h>
10
11
12 SignalStatus::SignalStatus(BC_WindowBase *wdw, int x, int y)
13  : BC_SubWindow(x, y, 100, 35)
14 {
15         this->wdw = wdw;
16         dvb_input = 0;
17
18         channel_title = 0;
19         lck_x = lck_y = 0;
20         crr_x = crr_y = 0;
21         pwr_x = pwr_y = 0;
22         snr_x = snr_y = 0;
23         ber_x = ber_y = 0;
24         unc_x = unc_y = 0;
25 }
26
27 SignalStatus::~SignalStatus()
28 {
29         if( dvb_input )
30                 dvb_input->set_signal_status(0);
31 }
32
33
34 void SignalStatus::create_objects()
35 {
36         clear_box(0,0,get_w(),get_h());
37         int x = 0, y = 0;
38         channel_title = new BC_Title(x, y, " ", SMALLFONT, GREEN);
39         add_subwindow(channel_title);
40         y += channel_title->get_h();
41         BC_Title *title;
42         add_subwindow(title = new BC_Title(x, y, "lk:", SMALLFONT, YELLOW));
43         lck_x = x + title->get_w() + pad0;
44         lck_y = y + pad0;
45         int x1 = lck_x + lck_w + pad1;
46         int y1 = y + title->get_h();
47         add_subwindow(title = new BC_Title(x, y1, "cr:", SMALLFONT, YELLOW));
48         crr_x = lck_x;
49         crr_y = y1 + pad0;
50         add_subwindow(title = new BC_Title(x1, y, "pwr", SMALLFONT, YELLOW));
51         pwr_x = x1 + title->get_w() + pad0;
52         pwr_y = y + pad0;
53         snr_x = pwr_x;
54         snr_y = pwr_y + pwr_h;
55         add_subwindow(title = new BC_Title(x1, y1, "err", SMALLFONT, YELLOW));
56         ber_x = pwr_x;
57         ber_y = y1 + pad0;
58         unc_x = ber_x;
59         unc_y = ber_y + ber_h;
60 }
61
62 int SignalStatus::calculate_w(BC_WindowBase *wdw)
63 {
64         return BC_Title::calculate_w(wdw, "lk:", SMALLFONT) + pad0 + lck_w + pad1 +
65                 BC_Title::calculate_w(wdw, "pwr", SMALLFONT) + pad0 + pwr_w;
66 }
67
68 int SignalStatus::calculate_h(BC_WindowBase *wdw)
69 {
70         return 3*BC_Title::calculate_h(wdw, "lk:", SMALLFONT);
71 }
72
73 void SignalStatus::update_lck(int v)
74 {
75         set_color(v>0 ? GREEN : RED);
76         draw_box(lck_x, lck_y, lck_w, lck_h);
77 }
78
79 void SignalStatus::update_crr(int v)
80 {
81         set_color(v>0 ? GREEN : RED);
82         draw_box(crr_x, crr_y, crr_w, crr_h);
83 }
84
85 void SignalStatus::update_pwr(int v)
86 {
87         if( v < 0 ) v = 0;
88         int w0 = (v*pwr_w) / 65535, w1 = pwr_w-w0;
89         if( w0 > 0 ) { set_color(GREEN); draw_box(pwr_x, pwr_y, w0, pwr_h); }
90         if( w1 > 0 ) clear_box(pwr_x+w0, pwr_y, w1, pwr_h);
91 }
92
93 void SignalStatus::update_snr(int v)
94 {
95         if( v < 0 ) v = 0;
96         int w0 = (v*snr_w) / 65535, w1 = pwr_w-w0;
97         if( w0 > 0 ) { set_color(BLUE); draw_box(snr_x, snr_y, w0, snr_h); }
98         if( w1 > 0 ) clear_box(snr_x+w0, snr_y, w1, snr_h);
99 }
100
101 void SignalStatus::update_ber(int v)
102 {
103         if( v < 0 ) v = 0;
104         int b = 0;
105         while( v > 0 ) { ++b; v>>=1; }
106         int w0 = (ber_w*b)/16, w1 = ber_w-w0;
107         if( w0 > 0 ) { set_color(YELLOW); draw_box(ber_x, ber_y, w0, ber_h); }
108         if( w1 > 0 ) clear_box(ber_x+w0, ber_y, w1, ber_h);
109 }
110
111 void SignalStatus::update_unc(int v)
112 {
113         if( v < 0 ) v = 0;
114         int b = 0;
115         while( v > 0 ) { ++b; v>>=1; }
116         int w0 = (unc_w*b)/16, w1 = unc_w-w0;
117         if( w0 > 0 ) { set_color(RED); draw_box(unc_x, unc_y, w0, unc_h); }
118         if( w1 > 0 ) clear_box(unc_x+w0, unc_y, w1, unc_h);
119 }
120
121
122 void SignalStatus::update()
123 {
124         channel_title->update(dvb_input->channel_title());
125         update_lck(dvb_input->signal_lck);  update_crr(dvb_input->signal_crr);
126         update_pwr(dvb_input->signal_pwr);  update_snr(dvb_input->signal_snr);
127         update_ber(dvb_input->signal_ber);  update_unc(dvb_input->signal_unc);
128         flash();
129 }
130
131 #endif