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()
69 void PresetsThread::calculate_list()
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++)
75 data->append(new BC_ListBoxItem(presets_db->get_preset_title(
82 void PresetsThread::start_window(Plugin *plugin)
84 if(!BC_DialogThread::is_running())
86 this->plugin = plugin;
87 plugin->calculate_title(plugin_title, 0);
88 sprintf(window_title, PROGRAM_NAME ": %s Presets", plugin_title);
96 mwindow->gui->unlock_window();
97 BC_DialogThread::start();
98 mwindow->gui->lock_window("PresetsThread::start_window");
102 BC_Window* PresetsThread::new_gui()
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;
110 PresetsWindow *window = new PresetsWindow(mwindow,
116 window->create_objects();
117 mwindow->gui->unlock_window();
121 void PresetsThread::handle_done_event(int result)
126 char *title = ((PresetsWindow*)get_gui())->title_text->get_text();
131 void PresetsThread::handle_close_event(int result)
135 void PresetsThread::save_preset(char *title)
137 get_gui()->unlock_window();
138 mwindow->gui->lock_window("PresetsThread::save_preset");
140 // Test EDL for plugin existence
141 if(!mwindow->edl->tracks->plugin_exists(plugin))
143 mwindow->gui->unlock_window();
144 get_gui()->lock_window("PresetsThread::save_preset 2");
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),
157 presets_db->save_preset(plugin_title, title, keyframe->get_data());
159 mwindow->gui->unlock_window();
160 get_gui()->lock_window("PresetsThread::save_preset 2");
165 ((PresetsWindow*)get_gui())->list->update(data,
171 void PresetsThread::delete_preset(char *title)
173 get_gui()->unlock_window();
174 mwindow->gui->lock_window("PresetsThread::save_preset");
176 // Test EDL for plugin existence
177 if(!mwindow->edl->tracks->plugin_exists(plugin))
179 mwindow->gui->unlock_window();
180 get_gui()->lock_window("PresetsThread::delete_preset 1");
184 presets_db->delete_preset(plugin_title, title);
186 mwindow->gui->unlock_window();
187 get_gui()->lock_window("PresetsThread::delete_preset 2");
192 ((PresetsWindow*)get_gui())->list->update(data,
199 void PresetsThread::apply_preset(char *title)
201 if(presets_db->preset_exists(plugin_title, title))
203 get_gui()->unlock_window();
204 mwindow->gui->lock_window("PresetsThread::apply_preset");
206 // Test EDL for plugin existence
207 if(!mwindow->edl->tracks->plugin_exists(plugin))
209 mwindow->gui->unlock_window();
210 get_gui()->lock_window("PresetsThread::delete_preset 1");
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);
220 mwindow->update_plugin_guis();
221 mwindow->gui->canvas->draw_overlays();
222 mwindow->gui->canvas->flash();
223 mwindow->sync_parameters(CHANGE_PARAMS);
225 mwindow->gui->unlock_window();
226 get_gui()->lock_window("PresetsThread::apply_preset");
234 PresetsList::PresetsList(PresetsThread *thread,
235 PresetsWindow *window,
247 this->thread = thread;
248 this->window = window;
251 int PresetsList::selection_changed()
253 window->title_text->update(
254 thread->data->get(get_selection_number(0, 0))->get_text());
258 int PresetsList::handle_event()
273 PresetsText::PresetsText(PresetsThread *thread,
274 PresetsWindow *window,
284 this->thread = thread;
285 this->window = window;
288 int PresetsText::handle_event()
309 PresetsDelete::PresetsDelete(PresetsThread *thread,
310 PresetsWindow *window,
313 : BC_GenericButton(x, y, _("Delete"))
315 this->thread = thread;
316 this->window = window;
319 int PresetsDelete::handle_event()
321 thread->delete_preset(window->title_text->get_text());
331 PresetsSave::PresetsSave(PresetsThread *thread,
332 PresetsWindow *window,
335 : BC_GenericButton(x, y, C_("Save"))
337 this->thread = thread;
338 this->window = window;
341 int PresetsSave::handle_event()
343 thread->save_preset(window->title_text->get_text());
354 PresetsApply::PresetsApply(PresetsThread *thread,
355 PresetsWindow *window,
358 : BC_GenericButton(x, y, _("Apply"))
360 this->thread = thread;
361 this->window = window;
364 int PresetsApply::handle_event()
366 thread->apply_preset(window->title_text->get_text());
372 PresetsOK::PresetsOK(PresetsThread *thread,
373 PresetsWindow *window)
374 : BC_OKButton(window)
376 this->thread = thread;
377 this->window = window;
380 int PresetsOK::keypress_event()
382 if(get_keypress() == RETURN)
384 printf("PresetsOK::keypress_event %d\n", __LINE__);
385 if(thread->presets_db->preset_exists(thread->plugin_title,
386 window->title_text->get_text()))
388 printf("PresetsOK::keypress_event %d\n", __LINE__);
394 printf("PresetsOK::keypress_event %d\n", __LINE__);
395 thread->save_preset(window->title_text->get_text());
411 PresetsWindow::PresetsWindow(MWindow *mwindow,
412 PresetsThread *thread,
416 : BC_Window(title_string,
419 mwindow->session->presetdialog_w,
420 mwindow->session->presetdialog_h,
427 this->mwindow = mwindow;
428 this->thread = thread;
431 void PresetsWindow::create_objects()
433 Theme *theme = mwindow->theme;
435 lock_window("PresetsWindow::create_objects");
436 theme->get_presetdialog_sizes(this);
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,
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,
452 theme->presets_text_x,
453 theme->presets_text_y,
454 theme->presets_text_w));
455 add_subwindow(delete_button = new PresetsDelete(thread,
457 theme->presets_delete_x,
458 theme->presets_delete_y));
459 add_subwindow(save_button = new PresetsSave(thread,
461 theme->presets_save_x,
462 theme->presets_save_y));
463 add_subwindow(apply_button = new PresetsApply(thread,
465 theme->presets_apply_x,
466 theme->presets_apply_y));
468 add_subwindow(new PresetsOK(thread, this));
469 add_subwindow(new BC_CancelButton(this));
475 int PresetsWindow::resize_event(int w, int h)
477 Theme *theme = mwindow->theme;
478 mwindow->session->presetdialog_w = w;
479 mwindow->session->presetdialog_h = h;
480 theme->get_presetdialog_sizes(this);
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);