add haupauge-1657 dual usb capture support, add deinterlace to recordmonitor, asset...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / presetsgui.C.sav
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 #if 0
23
24
25
26
27 #include "edl.h"
28 #include "keyframe.h"
29 #include "keys.h"
30 #include "language.h"
31 #include "localsession.h"
32 #include "mainsession.h"
33 #include "mainundo.h"
34 #include "mwindow.h"
35 #include "mwindowgui.h"
36 #include "plugin.h"
37 #include "presets.h"
38 #include "presetsgui.h"
39 #include "theme.h"
40 #include "trackcanvas.h"
41 #include "tracks.h"
42
43
44
45
46
47
48
49
50
51
52
53 PresetsThread::PresetsThread(MWindow *mwindow)
54  : BC_DialogThread()
55 {
56         this->mwindow = mwindow;
57         plugin = 0;
58         data = new ArrayList<BC_ListBoxItem*>;
59         presets_db = new PresetsDB;
60         plugin_title[0] = 0;
61         window_title[0] = 0;
62 }
63
64 PresetsThread::~PresetsThread()
65 {
66         close_window();
67         delete data;
68 }
69
70 void PresetsThread::calculate_list()
71 {
72         data->remove_all_objects();
73         int total_presets = presets_db->get_total_presets(plugin_title);
74         for(int i = 0; i < total_presets; i++)
75         {
76                 data->append(new BC_ListBoxItem(presets_db->get_preset_title(
77                         plugin_title,
78                         i)));
79         }
80 }
81
82
83 void PresetsThread::start_window(Plugin *plugin)
84 {
85         if(!BC_DialogThread::is_running())
86         {
87                 this->plugin = plugin;
88                 plugin->calculate_title(plugin_title, 0);
89                 sprintf(window_title, _(PROGRAM_NAME ": %s Presets"), plugin_title);
90
91
92 // Calculate database
93                 presets_db->load();
94                 calculate_list();
95
96
97                 mwindow->gui->unlock_window();
98                 BC_DialogThread::start();
99                 mwindow->gui->lock_window("PresetsThread::start_window");
100         }
101 }
102
103 BC_Window* PresetsThread::new_gui()
104 {
105         mwindow->gui->lock_window("PresetsThread::new_gui");
106         int x = mwindow->gui->get_abs_cursor_x(0) -
107                 mwindow->session->plugindialog_w / 2;
108         int y = mwindow->gui->get_abs_cursor_y(0) -
109                 mwindow->session->plugindialog_h / 2;
110
111         PresetsWindow *window = new PresetsWindow(mwindow,
112                 this,
113                 x,
114                 y,
115                 window_title);
116
117         window->create_objects();
118         mwindow->gui->unlock_window();
119         return window;
120 }
121
122 void PresetsThread::handle_done_event(int result)
123 {
124 // Apply the preset
125         if(!result)
126         {
127                 char *title = ((PresetsWindow*)get_gui())->title_text->get_text();
128                 apply_preset(title);
129         }
130 }
131
132 void PresetsThread::handle_close_event(int result)
133 {
134 }
135
136 void PresetsThread::save_preset(char *title)
137 {
138         get_gui()->unlock_window();
139         mwindow->gui->lock_window("PresetsThread::save_preset");
140
141 // Test EDL for plugin existence
142         if(!mwindow->edl->tracks->plugin_exists(plugin))
143         {
144                 mwindow->gui->unlock_window();
145                 get_gui()->lock_window("PresetsThread::save_preset 2");
146                 return;
147         }
148
149
150 // Get current plugin keyframe
151         EDL *edl = mwindow->edl;
152         Track *track = plugin->track;
153         KeyFrame *keyframe = plugin->get_prev_keyframe(
154                         track->to_units(edl->local_session->get_selectionstart(1), 0),
155                         PLAY_FORWARD);
156
157 // Send to database
158         presets_db->save_preset(plugin_title, title, keyframe->get_data());
159
160         mwindow->gui->unlock_window();
161         get_gui()->lock_window("PresetsThread::save_preset 2");
162
163
164 // Update list
165         calculate_list();
166         ((PresetsWindow*)get_gui())->list->update(data,
167                 0,
168                 0,
169                 1);
170 }
171
172 void PresetsThread::delete_preset(char *title)
173 {
174         get_gui()->unlock_window();
175         mwindow->gui->lock_window("PresetsThread::save_preset");
176
177 // Test EDL for plugin existence
178         if(!mwindow->edl->tracks->plugin_exists(plugin))
179         {
180                 mwindow->gui->unlock_window();
181                 get_gui()->lock_window("PresetsThread::delete_preset 1");
182                 return;
183         }
184
185         presets_db->delete_preset(plugin_title, title);
186
187         mwindow->gui->unlock_window();
188         get_gui()->lock_window("PresetsThread::delete_preset 2");
189
190
191 // Update list
192         calculate_list();
193         ((PresetsWindow*)get_gui())->list->update(data,
194                 0,
195                 0,
196                 1);
197 }
198
199
200 void PresetsThread::apply_preset(char *title)
201 {
202         if(presets_db->preset_exists(plugin_title, title))
203         {
204                 get_gui()->unlock_window();
205                 mwindow->gui->lock_window("PresetsThread::apply_preset");
206
207 // Test EDL for plugin existence
208                 if(!mwindow->edl->tracks->plugin_exists(plugin))
209                 {
210                         mwindow->gui->unlock_window();
211                         get_gui()->lock_window("PresetsThread::delete_preset 1");
212                         return;
213                 }
214
215                 mwindow->undo->update_undo_before();
216                 KeyFrame *keyframe = plugin->get_keyframe();
217                 presets_db->load_preset(plugin_title, title, keyframe);
218                 mwindow->save_backup();
219                 mwindow->undo->update_undo_after(_("apply preset"), LOAD_AUTOMATION);
220
221                 mwindow->update_plugin_guis();
222                 mwindow->gui->canvas->draw_overlays();
223                 mwindow->gui->canvas->flash();
224                 mwindow->sync_parameters(CHANGE_PARAMS);
225
226                 mwindow->gui->unlock_window();
227                 get_gui()->lock_window("PresetsThread::apply_preset");
228         }
229 }
230
231
232
233
234
235 PresetsList::PresetsList(PresetsThread *thread,
236         PresetsWindow *window,
237         int x,
238         int y,
239         int w,
240         int h)
241  : BC_ListBox(x,
242                 y,
243                 w,
244                 h,
245                 LISTBOX_TEXT,
246                 thread->data)
247 {
248         this->thread = thread;
249         this->window = window;
250 }
251
252 int PresetsList::selection_changed()
253 {
254         window->title_text->update(
255                 thread->data->get(get_selection_number(0, 0))->get_text());
256         return 0;
257 }
258
259 int PresetsList::handle_event()
260 {
261         window->set_done(0);
262         return 0;
263 }
264
265
266
267
268
269
270
271
272
273
274 PresetsText::PresetsText(PresetsThread *thread,
275         PresetsWindow *window,
276         int x,
277         int y,
278         int w)
279  : BC_TextBox(x,
280         y,
281         w,
282         1,
283         "")
284 {
285         this->thread = thread;
286         this->window = window;
287 }
288
289 int PresetsText::handle_event()
290 {
291         return 0;
292 }
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310 PresetsDelete::PresetsDelete(PresetsThread *thread,
311         PresetsWindow *window,
312         int x,
313         int y)
314  : BC_GenericButton(x, y, _("Delete"))
315 {
316         this->thread = thread;
317         this->window = window;
318 }
319
320 int PresetsDelete::handle_event()
321 {
322         thread->delete_preset(window->title_text->get_text());
323         return 1;
324 }
325
326
327
328
329
330
331
332 PresetsSave::PresetsSave(PresetsThread *thread,
333         PresetsWindow *window,
334         int x,
335         int y)
336 : BC_GenericButton(x, y, _("Save"))
337 {
338         this->thread = thread;
339         this->window = window;
340 }
341
342 int PresetsSave::handle_event()
343 {
344         thread->save_preset(window->title_text->get_text());
345         return 1;
346 }
347
348
349
350
351
352
353
354
355 PresetsApply::PresetsApply(PresetsThread *thread,
356         PresetsWindow *window,
357         int x,
358         int y)
359  : BC_GenericButton(x, y, _("Apply"))
360 {
361         this->thread = thread;
362         this->window = window;
363 }
364
365 int PresetsApply::handle_event()
366 {
367         thread->apply_preset(window->title_text->get_text());
368         return 1;
369 }
370
371
372
373 PresetsOK::PresetsOK(PresetsThread *thread,
374         PresetsWindow *window)
375  : BC_OKButton(window)
376 {
377         this->thread = thread;
378         this->window = window;
379 }
380
381 int PresetsOK::keypress_event()
382 {
383         if(get_keypress() == RETURN)
384         {
385 printf("PresetsOK::keypress_event %d\n", __LINE__);
386                 if(thread->presets_db->preset_exists(thread->plugin_title,
387                         window->title_text->get_text()))
388                 {
389 printf("PresetsOK::keypress_event %d\n", __LINE__);
390                         window->set_done(0);
391                         return 1;
392                 }
393                 else
394                 {
395 printf("PresetsOK::keypress_event %d\n", __LINE__);
396                         thread->save_preset(window->title_text->get_text());
397                         return 1;
398                 }
399         }
400         return 0;
401 }
402
403
404
405
406
407
408
409
410
411
412 PresetsWindow::PresetsWindow(MWindow *mwindow,
413         PresetsThread *thread,
414         int x,
415         int y,
416         char *title_string)
417  : BC_Window(title_string,
418         x, y,
419         mwindow->session->presetdialog_w,
420         mwindow->session->presetdialog_h,
421         xS(320), yS(240), 1, 0, 1)
422 {
423         this->mwindow = mwindow;
424         this->thread = thread;
425 }
426
427 void PresetsWindow::create_objects()
428 {
429         Theme *theme = mwindow->theme;
430
431         lock_window("PresetsWindow::create_objects");
432         theme->get_presetdialog_sizes(this);
433
434         add_subwindow(title1 = new BC_Title(theme->presets_list_x,
435                 theme->presets_list_y - BC_Title::calculate_h(this, "P") - theme->widget_border,
436                 _("Saved presets:")));
437         add_subwindow(list = new PresetsList(thread,
438                 this,
439                 theme->presets_list_x,
440                 theme->presets_list_y,
441                 theme->presets_list_w,
442                 theme->presets_list_h));
443         add_subwindow(title2 = new BC_Title(theme->presets_text_x,
444                 theme->presets_text_y - BC_Title::calculate_h(this, "P") - theme->widget_border,
445                 _("Preset title:")));
446         add_subwindow(title_text = new PresetsText(thread,
447                 this,
448                 theme->presets_text_x,
449                 theme->presets_text_y,
450                 theme->presets_text_w));
451         add_subwindow(delete_button = new PresetsDelete(thread,
452                 this,
453                 theme->presets_delete_x,
454                 theme->presets_delete_y));
455         add_subwindow(save_button = new PresetsSave(thread,
456                 this,
457                 theme->presets_save_x,
458                 theme->presets_save_y));
459         add_subwindow(apply_button = new PresetsApply(thread,
460                 this,
461                 theme->presets_apply_x,
462                 theme->presets_apply_y));
463
464         add_subwindow(new PresetsOK(thread, this));
465         add_subwindow(new BC_CancelButton(this));
466
467         show_window();
468         unlock_window();
469 }
470
471 int PresetsWindow::resize_event(int w, int h)
472 {
473         Theme *theme = mwindow->theme;
474         mwindow->session->presetdialog_w = w;
475         mwindow->session->presetdialog_h = h;
476         theme->get_presetdialog_sizes(this);
477
478         title1->reposition_window(theme->presets_list_x,
479                 theme->presets_list_y - BC_Title::calculate_h(this, "P") - theme->widget_border);
480         title2->reposition_window(theme->presets_text_x,
481                 theme->presets_text_y - BC_Title::calculate_h(this, "P") - theme->widget_border);
482         list->reposition_window(theme->presets_list_x,
483                 theme->presets_list_y,
484                 theme->presets_list_w,
485                 theme->presets_list_h);
486         title_text->reposition_window(theme->presets_text_x,
487                 theme->presets_text_y,
488                 theme->presets_text_w);
489         delete_button->reposition_window(theme->presets_delete_x,
490                 theme->presets_delete_y);
491         save_button->reposition_window(theme->presets_save_x,
492                 theme->presets_save_y);
493         apply_button->reposition_window(theme->presets_apply_x,
494                 theme->presets_apply_y);
495         return 0;
496 }
497
498
499
500
501
502
503 #endif
504