4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
31 #include "localsession.h"
32 #include "mainsession.h"
35 #include "mwindowgui.h"
38 #include "presetsgui.h"
40 #include "trackcanvas.h"
53 PresetsThread::PresetsThread(MWindow *mwindow)
56 this->mwindow = mwindow;
58 data = new ArrayList<BC_ListBoxItem*>;
59 presets_db = new PresetsDB;
64 PresetsThread::~PresetsThread()
70 void PresetsThread::calculate_list()
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++)
76 data->append(new BC_ListBoxItem(presets_db->get_preset_title(
83 void PresetsThread::start_window(Plugin *plugin)
85 if(!BC_DialogThread::is_running())
87 this->plugin = plugin;
88 plugin->calculate_title(plugin_title, 0);
89 sprintf(window_title, _(PROGRAM_NAME ": %s Presets"), plugin_title);
97 mwindow->gui->unlock_window();
98 BC_DialogThread::start();
99 mwindow->gui->lock_window("PresetsThread::start_window");
103 BC_Window* PresetsThread::new_gui()
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;
111 PresetsWindow *window = new PresetsWindow(mwindow,
117 window->create_objects();
118 mwindow->gui->unlock_window();
122 void PresetsThread::handle_done_event(int result)
127 char *title = ((PresetsWindow*)get_gui())->title_text->get_text();
132 void PresetsThread::handle_close_event(int result)
136 void PresetsThread::save_preset(char *title)
138 get_gui()->unlock_window();
139 mwindow->gui->lock_window("PresetsThread::save_preset");
141 // Test EDL for plugin existence
142 if(!mwindow->edl->tracks->plugin_exists(plugin))
144 mwindow->gui->unlock_window();
145 get_gui()->lock_window("PresetsThread::save_preset 2");
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),
158 presets_db->save_preset(plugin_title, title, keyframe->get_data());
160 mwindow->gui->unlock_window();
161 get_gui()->lock_window("PresetsThread::save_preset 2");
166 ((PresetsWindow*)get_gui())->list->update(data,
172 void PresetsThread::delete_preset(char *title)
174 get_gui()->unlock_window();
175 mwindow->gui->lock_window("PresetsThread::save_preset");
177 // Test EDL for plugin existence
178 if(!mwindow->edl->tracks->plugin_exists(plugin))
180 mwindow->gui->unlock_window();
181 get_gui()->lock_window("PresetsThread::delete_preset 1");
185 presets_db->delete_preset(plugin_title, title);
187 mwindow->gui->unlock_window();
188 get_gui()->lock_window("PresetsThread::delete_preset 2");
193 ((PresetsWindow*)get_gui())->list->update(data,
200 void PresetsThread::apply_preset(char *title)
202 if(presets_db->preset_exists(plugin_title, title))
204 get_gui()->unlock_window();
205 mwindow->gui->lock_window("PresetsThread::apply_preset");
207 // Test EDL for plugin existence
208 if(!mwindow->edl->tracks->plugin_exists(plugin))
210 mwindow->gui->unlock_window();
211 get_gui()->lock_window("PresetsThread::delete_preset 1");
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);
221 mwindow->update_plugin_guis();
222 mwindow->gui->canvas->draw_overlays();
223 mwindow->gui->canvas->flash();
224 mwindow->sync_parameters(CHANGE_PARAMS);
226 mwindow->gui->unlock_window();
227 get_gui()->lock_window("PresetsThread::apply_preset");
235 PresetsList::PresetsList(PresetsThread *thread,
236 PresetsWindow *window,
248 this->thread = thread;
249 this->window = window;
252 int PresetsList::selection_changed()
254 window->title_text->update(
255 thread->data->get(get_selection_number(0, 0))->get_text());
259 int PresetsList::handle_event()
274 PresetsText::PresetsText(PresetsThread *thread,
275 PresetsWindow *window,
285 this->thread = thread;
286 this->window = window;
289 int PresetsText::handle_event()
310 PresetsDelete::PresetsDelete(PresetsThread *thread,
311 PresetsWindow *window,
314 : BC_GenericButton(x, y, _("Delete"))
316 this->thread = thread;
317 this->window = window;
320 int PresetsDelete::handle_event()
322 thread->delete_preset(window->title_text->get_text());
332 PresetsSave::PresetsSave(PresetsThread *thread,
333 PresetsWindow *window,
336 : BC_GenericButton(x, y, _("Save"))
338 this->thread = thread;
339 this->window = window;
342 int PresetsSave::handle_event()
344 thread->save_preset(window->title_text->get_text());
355 PresetsApply::PresetsApply(PresetsThread *thread,
356 PresetsWindow *window,
359 : BC_GenericButton(x, y, _("Apply"))
361 this->thread = thread;
362 this->window = window;
365 int PresetsApply::handle_event()
367 thread->apply_preset(window->title_text->get_text());
373 PresetsOK::PresetsOK(PresetsThread *thread,
374 PresetsWindow *window)
375 : BC_OKButton(window)
377 this->thread = thread;
378 this->window = window;
381 int PresetsOK::keypress_event()
383 if(get_keypress() == RETURN)
385 printf("PresetsOK::keypress_event %d\n", __LINE__);
386 if(thread->presets_db->preset_exists(thread->plugin_title,
387 window->title_text->get_text()))
389 printf("PresetsOK::keypress_event %d\n", __LINE__);
395 printf("PresetsOK::keypress_event %d\n", __LINE__);
396 thread->save_preset(window->title_text->get_text());
412 PresetsWindow::PresetsWindow(MWindow *mwindow,
413 PresetsThread *thread,
417 : BC_Window(title_string,
420 mwindow->session->presetdialog_w,
421 mwindow->session->presetdialog_h,
428 this->mwindow = mwindow;
429 this->thread = thread;
432 void PresetsWindow::create_objects()
434 Theme *theme = mwindow->theme;
436 lock_window("PresetsWindow::create_objects");
437 theme->get_presetdialog_sizes(this);
439 add_subwindow(title1 = new BC_Title(theme->presets_list_x,
440 theme->presets_list_y - BC_Title::calculate_h(this, "P") - theme->widget_border,
441 _("Saved presets:")));
442 add_subwindow(list = new PresetsList(thread,
444 theme->presets_list_x,
445 theme->presets_list_y,
446 theme->presets_list_w,
447 theme->presets_list_h));
448 add_subwindow(title2 = new BC_Title(theme->presets_text_x,
449 theme->presets_text_y - BC_Title::calculate_h(this, "P") - theme->widget_border,
450 _("Preset title:")));
451 add_subwindow(title_text = new PresetsText(thread,
453 theme->presets_text_x,
454 theme->presets_text_y,
455 theme->presets_text_w));
456 add_subwindow(delete_button = new PresetsDelete(thread,
458 theme->presets_delete_x,
459 theme->presets_delete_y));
460 add_subwindow(save_button = new PresetsSave(thread,
462 theme->presets_save_x,
463 theme->presets_save_y));
464 add_subwindow(apply_button = new PresetsApply(thread,
466 theme->presets_apply_x,
467 theme->presets_apply_y));
469 add_subwindow(new PresetsOK(thread, this));
470 add_subwindow(new BC_CancelButton(this));
476 int PresetsWindow::resize_event(int w, int h)
478 Theme *theme = mwindow->theme;
479 mwindow->session->presetdialog_w = w;
480 mwindow->session->presetdialog_h = h;
481 theme->get_presetdialog_sizes(this);
483 title1->reposition_window(theme->presets_list_x,
484 theme->presets_list_y - BC_Title::calculate_h(this, "P") - theme->widget_border);
485 title2->reposition_window(theme->presets_text_x,
486 theme->presets_text_y - BC_Title::calculate_h(this, "P") - theme->widget_border);
487 list->reposition_window(theme->presets_list_x,
488 theme->presets_list_y,
489 theme->presets_list_w,
490 theme->presets_list_h);
491 title_text->reposition_window(theme->presets_text_x,
492 theme->presets_text_y,
493 theme->presets_text_w);
494 delete_button->reposition_window(theme->presets_delete_x,
495 theme->presets_delete_y);
496 save_button->reposition_window(theme->presets_save_x,
497 theme->presets_save_y);
498 apply_button->reposition_window(theme->presets_apply_x,
499 theme->presets_apply_y);