mixer align audio, track dump tweak, zwdw refresh edl fix, sketcher tweak
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / deinterlace-cv / deinterwindow-cv.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "deinterwindow-cv.h"
24 #include "language.h"
25 #include <string.h>
26
27
28 DeInterlaceWindow::DeInterlaceWindow(DeInterlaceMain *client)
29  : PluginClientWindow(client,
30         400,
31         200,
32         400,
33         200,
34         0)
35 {
36         this->client = client;
37         adaptive=0; dominance_top=0; dominance_bottom=0; threshold=0;
38
39 }
40
41 DeInterlaceWindow::~DeInterlaceWindow()
42 {
43 }
44
45 void DeInterlaceWindow::create_objects()
46 {
47         int x = 10, y = 10;
48         add_tool(new BC_Title(x, y, _("Select deinterlacing mode")));
49         y += 25;
50         add_tool(mode = new DeInterlaceMode(client, this, x, y));
51         mode->create_objects();
52         y += 25;
53         optional_controls_x=x;
54         optional_controls_y=y;
55         y += 125;
56         char string[BCTEXTLEN];
57         get_status_string(string, 0);
58         add_tool(status = new BC_Title(x, y, string));
59         flash();
60         show_window();
61         set_mode(client->config.mode,0);
62 }
63
64 void DeInterlaceWindow::get_status_string(char *string, int changed_rows)
65 {
66         sprintf(string, _("Changed rows: %d\n"), changed_rows);
67 }
68
69 int DeInterlaceWindow::set_mode(int mode, int recursive)
70 {
71         int x,y;
72         client->config.mode = mode;
73
74 /* Restore position of controls */
75         x=optional_controls_x;
76         y=optional_controls_y;
77         if (adaptive) { delete adaptive; adaptive=0; }
78         if (threshold) { delete threshold; threshold=0; }
79         if (dominance_top) { delete dominance_top; dominance_top=0; }
80         if (dominance_bottom) { delete dominance_bottom; dominance_bottom=0; }
81
82 /* Display Dominance controls */
83         switch (mode)
84         {
85                 case DEINTERLACE_KEEP:
86                 case DEINTERLACE_BOBWEAVE:
87                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Keep top field")));
88                         y+=25;
89                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Keep bottom field")));
90                         y+=25;
91                         break;
92                 case DEINTERLACE_AVG_1F:
93                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Average top fields")));
94                         y+=25;
95                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y,_("Average bottom fields")));
96                         y+=25;
97                         break;
98                 case DEINTERLACE_SWAP:
99                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
100                         y+=25;
101                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
102                         y+=25;
103                         break;
104                 case DEINTERLACE_TEMPORALSWAP:
105                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
106                         y+=25;
107                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
108                         y+=25;
109                         break;
110                 case DEINTERLACE_NONE:
111                 case  DEINTERLACE_AVG:
112                 default:
113                         ;
114         }
115
116         if (dominance_top&&dominance_bottom)  {
117                 dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
118                 dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
119         }
120
121 /* Display Threshold and adaptive controls */
122         switch (mode) {
123                 case  DEINTERLACE_AVG_1F:
124                         add_subwindow(adaptive = new DeInterlaceAdaptive(client, x, y));
125
126                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + 150, y));
127                         add_subwindow(threshold->title_caption=new BC_Title(x+150, y + 50, _("Threshold")));
128                         adaptive->update(client->config.adaptive?BC_Toggle::TOGGLE_CHECKED:0);
129                         break;
130                 case DEINTERLACE_BOBWEAVE:
131                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + 150, y));
132                         add_subwindow(threshold->title_caption=new BC_Title(x+150, y + 50, _("Bob Threshold")));
133                         break;
134                 case DEINTERLACE_NONE:
135                 case DEINTERLACE_KEEP:
136                 case DEINTERLACE_AVG:
137                 case DEINTERLACE_SWAP:
138                 case DEINTERLACE_TEMPORALSWAP:
139                 default:
140
141                 break;
142         }
143
144
145         if(!recursive)
146                 client->send_configure_change();
147         return 0;
148 }
149
150
151 DeInterlaceOption::DeInterlaceOption(DeInterlaceMain *client,
152                 DeInterlaceWindow *window,
153                 int output,
154                 int x,
155                 int y,
156                 char *text)
157  : BC_Radial(x, y, client->config.mode == output, text)
158 {
159         this->client = client;
160         this->window = window;
161         this->output = output;
162 }
163
164 DeInterlaceOption::~DeInterlaceOption()
165 {
166 }
167 int DeInterlaceOption::handle_event()
168 {
169         window->set_mode(output, 0);
170         return 1;
171 }
172
173
174 DeInterlaceAdaptive::DeInterlaceAdaptive(DeInterlaceMain *client, int x, int y)
175  : BC_CheckBox(x, y, client->config.adaptive, _("Adaptive"))
176 {
177         this->client = client;
178 }
179 int DeInterlaceAdaptive::handle_event()
180 {
181         client->config.adaptive = get_value();
182         client->send_configure_change();
183         return 1;
184 }
185
186 DeInterlaceDominanceTop::DeInterlaceDominanceTop(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
187  : BC_Radial(x, y, client->config.dominance, title)
188 {
189         this->client = client;
190         this->window = window;
191
192 }
193 int DeInterlaceDominanceTop::handle_event()
194 {
195         client->config.dominance = (get_value()==0);
196         window->dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
197         client->send_configure_change();
198         return 1;
199 }
200
201
202 DeInterlaceDominanceBottom::DeInterlaceDominanceBottom(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, const char * title)
203  : BC_Radial(x, y, client->config.dominance, title)
204 {
205         this->client = client;
206         this->window = window;
207 }
208 int DeInterlaceDominanceBottom::handle_event()
209 {
210
211         client->config.dominance = (get_value() != 0 );
212         window->dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
213         client->send_configure_change();
214         return 1;
215 }
216
217
218 DeInterlaceThreshold::DeInterlaceThreshold(DeInterlaceMain *client, int x, int y)
219  : BC_IPot(x, y, client->config.threshold, 0, 100)
220 {
221         this->client = client;
222         title_caption=NULL;
223 }
224 int DeInterlaceThreshold::handle_event()
225 {
226         client->config.threshold = get_value();
227         client->send_configure_change();
228         return 1;
229 }
230
231 DeInterlaceThreshold::~DeInterlaceThreshold()
232 {
233   if (title_caption) delete title_caption;
234 }
235
236 DeInterlaceMode::DeInterlaceMode(DeInterlaceMain*plugin,
237         DeInterlaceWindow *gui,
238         int x,
239         int y)
240  : BC_PopupMenu(x, y, 200, to_text(plugin->config.mode), 1)
241 {
242         this->plugin = plugin;
243         this->gui = gui;
244 }
245 void DeInterlaceMode::create_objects()
246 {
247         add_item(new BC_MenuItem(to_text(DEINTERLACE_NONE)));
248         add_item(new BC_MenuItem(to_text(DEINTERLACE_KEEP)));
249         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG)));
250         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG_1F)));
251         add_item(new BC_MenuItem(to_text(DEINTERLACE_BOBWEAVE)));
252         add_item(new BC_MenuItem(to_text(DEINTERLACE_SWAP)));
253         add_item(new BC_MenuItem(to_text(DEINTERLACE_TEMPORALSWAP)));
254 }
255
256 char* DeInterlaceMode::to_text(int mode)
257 {
258         switch(mode)
259         {
260                 case DEINTERLACE_KEEP:
261                         return _("Duplicate one field");
262                 case DEINTERLACE_AVG_1F:
263                         return _("Average one field");
264                 case DEINTERLACE_AVG:
265                         return _("Average both fields");
266                 case DEINTERLACE_BOBWEAVE:
267                         return _("Bob & Weave");
268                 case DEINTERLACE_SWAP:
269                         return _("Spatial field swap");
270                 case DEINTERLACE_TEMPORALSWAP:
271                         return _("Temporal field swap");
272                 default:
273                         return _("Do Nothing");
274         }
275 }
276 int DeInterlaceMode::from_text(char *text)
277 {
278         if(!strcmp(text, to_text(DEINTERLACE_KEEP)))
279                 return DEINTERLACE_KEEP;
280         if(!strcmp(text, to_text(DEINTERLACE_AVG)))
281                 return DEINTERLACE_AVG;
282         if(!strcmp(text, to_text(DEINTERLACE_AVG_1F)))
283                 return DEINTERLACE_AVG_1F;
284         if(!strcmp(text, to_text(DEINTERLACE_BOBWEAVE)))
285                 return DEINTERLACE_BOBWEAVE;
286         if(!strcmp(text, to_text(DEINTERLACE_SWAP)))
287                 return DEINTERLACE_SWAP;
288         if(!strcmp(text, to_text(DEINTERLACE_TEMPORALSWAP)))
289                 return DEINTERLACE_TEMPORALSWAP;
290         return DEINTERLACE_NONE;
291 }
292
293 int DeInterlaceMode::handle_event()
294 {
295         plugin->config.mode = from_text(get_text());
296         gui->set_mode(plugin->config.mode,0);
297         plugin->send_configure_change();
298         return 1;
299 }
300
301
302