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