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
24 #include "edlsession.h"
26 #include "mainsession.h"
27 #include "menuattachtransition.h"
29 #include "mwindowgui.h"
30 #include "plugindialog.h"
31 #include "pluginserver.h"
39 MenuAttachTransition::MenuAttachTransition(MWindow *mwindow, int data_type)
40 : BC_MenuItem(_("Attach Transition..."))
42 this->mwindow = mwindow;
43 this->data_type = data_type;
44 thread = new TransitionDialogThread(mwindow, data_type);
47 MenuAttachTransition::~MenuAttachTransition()
52 int MenuAttachTransition::handle_event()
59 TransitionDialogThread::TransitionDialogThread(MWindow *mwindow, int data_type)
62 this->mwindow = mwindow;
63 this->data_type = data_type;
67 TransitionDialogThread::~TransitionDialogThread()
72 void TransitionDialogThread::start()
74 if(!transition_names.total)
76 // strcpy(transition_title, data_type == TRACK_AUDIO ?
77 // mwindow->edl->session->default_atransition :
78 // mwindow->edl->session->default_vtransition);
80 // Construct listbox names
81 ArrayList<PluginServer*> plugindb;
82 mwindow->search_plugindb(data_type == TRACK_AUDIO,
83 data_type == TRACK_VIDEO, 0, 1, 0, plugindb);
84 for(int i = 0; i < plugindb.total; i++) {
85 const char *title = plugindb.values[i]->title;
86 if( !strcmp(transition_title, title) ) number = i;
87 transition_names.append(new BC_ListBoxItem(_(title)));
91 mwindow->gui->unlock_window();
92 BC_DialogThread::start();
93 mwindow->gui->lock_window("TransitionDialogThread::start");
98 BC_Window* TransitionDialogThread::new_gui()
100 mwindow->gui->lock_window("TransitionDialogThread::new_gui");
101 int x = mwindow->gui->get_abs_cursor_x(0) -
102 mwindow->session->transitiondialog_w / 2;
103 int y = mwindow->gui->get_abs_cursor_y(0) -
104 mwindow->session->transitiondialog_h / 2;
105 TransitionDialog *window = new TransitionDialog(mwindow, this, x, y);
106 window->create_objects();
107 mwindow->gui->unlock_window();
111 void TransitionDialogThread::handle_close_event(int result)
115 // Re-search plugindb and use untranslated plugin name
116 ArrayList<PluginServer*> plugindb;
117 mwindow->search_plugindb(data_type == TRACK_AUDIO,
118 data_type == TRACK_VIDEO, 0, 1, 0, plugindb);
119 for(int i = 0; i < plugindb.total; i++) {
120 const char *title = _(plugindb.values[i]->title);
121 if( !strcmp(transition_title, title)) {
122 strcpy(transition_title, N_(plugindb.values[i]->title));
126 mwindow->paste_transitions(data_type, transition_title);
132 TransitionDialog::TransitionDialog(MWindow *mwindow,
133 TransitionDialogThread *thread, int x, int y)
134 : BC_Window(_("Attach Transition"), x, y,
135 mwindow->session->transitiondialog_w,
136 mwindow->session->transitiondialog_h,
137 xS(320), yS(240), 1, 0, 1)
139 this->mwindow = mwindow;
140 this->thread = thread;
141 // *** CONTEXT_HELP ***
142 switch( thread->data_type ) {
144 context_help_set_keyword("Audio Transitions");
147 context_help_set_keyword("Video Transitions");
150 context_help_set_keyword("Transition Plugins");
155 TransitionSetDefault::TransitionSetDefault(TransitionDialog *window, int x, int y)
156 : BC_GenericButton(x, y, _("Set Default Transition"))
158 this->window = window;
161 TransitionSetDefault::~TransitionSetDefault()
165 int TransitionSetDefault::handle_event()
167 TransitionDialogThread *thread = (TransitionDialogThread *)window->thread;
168 const char *transition_title = thread->transition_title;
169 EDL *edl = window->mwindow->edl;
171 // Re-search plugindb and use untranslated plugin name
173 ArrayList<PluginServer*> plugindb;
174 thread->mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
175 thread->data_type == TRACK_VIDEO, 0, 1, 0, plugindb);
176 for(int i = 0; i < plugindb.total; i++) {
177 const char *title = _(plugindb.values[i]->title);
178 if( !strcmp(transition_title, title)) {
179 strcpy(thread->transition_title_untranslated, N_(plugindb.values[i]->title));
184 switch( thread->data_type ) {
186 strcpy(edl->session->default_atransition, thread->transition_title_untranslated);
189 strcpy(edl->session->default_vtransition, thread->transition_title_untranslated);
192 window->set_default_text->update(transition_title);
196 TransitionDefaultText::TransitionDefaultText(TransitionDialog *window,
197 int x, int y, int w, const char * text)
198 : BC_TextBox(x, y, w, 1, text)
200 this->window = window;
203 TransitionDefaultText::~TransitionDefaultText()
208 void TransitionDialog::create_objects()
213 lock_window("TransitionDialog::create_objects");
214 add_subwindow(name_title = new BC_Title(x, y, _("Select transition from list")));
215 y += name_title->get_h() + yS(5);
216 add_subwindow(name_list = new TransitionDialogName(thread,
217 &thread->transition_names,
221 get_h() - y - BC_OKButton::calculate_h() - yS(100)));
222 y += name_list->get_h() + yS(20);
223 add_subwindow(set_default = new TransitionSetDefault(this, x, y));
224 y += set_default->get_h() + yS(10);
225 const char *default_transition = "";
226 EDL *edl = mwindow->edl;
227 switch( thread->data_type ) {
229 default_transition = edl->session->default_atransition;
232 default_transition = edl->session->default_vtransition;
235 add_subwindow(set_default_text = new TransitionDefaultText(this, x, y,
236 get_w()-x-xS(20), default_transition));
237 if( thread->number >= 0 ) {
238 name_list->update_selection(&thread->transition_names, thread->number, 0);
239 name_list->draw_items(0);
241 add_subwindow(new BC_OKButton(this));
242 add_subwindow(new BC_CancelButton(this));
248 int TransitionDialog::resize_event(int w, int h)
253 name_title->reposition_window(x, y);
254 y += name_title->get_h() + yS(5);
255 name_list->reposition_window(x, y,
256 w - x - x, h - y - BC_OKButton::calculate_h() - yS(100));
257 y += name_list->get_h() + yS(20);
258 set_default->reposition_window(x, y);
259 y += set_default->get_h() + yS(10);
260 set_default_text->reposition_window(x, y, get_w()-x-xS(20));
265 TransitionDialogName::TransitionDialogName(TransitionDialogThread *thread,
266 ArrayList<BC_ListBoxItem*> *standalone_data, int x, int y, int w, int h)
274 this->thread = thread;
277 int TransitionDialogName::handle_event()
283 int TransitionDialogName::selection_changed()
285 thread->number = get_selection_number(0, 0);
286 strcpy(thread->transition_title,
287 thread->transition_names.values[thread->number]->get_text());