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
22 #include "bcdisplayinfo.h"
26 #include "edlsession.h"
29 #include "mwindowgui.h"
31 #include "transition.h"
34 #include "transitionpopup.h"
37 TransitionLengthThread::TransitionLengthThread(MWindow *mwindow)
40 this->mwindow = mwindow;
43 TransitionLengthThread::~TransitionLengthThread()
48 void TransitionLengthThread::start(Transition *transition, double length)
50 this->transition = transition;
51 this->orig_length = length;
52 this->new_length = length;
53 BC_DialogThread::start();
59 BC_Window* TransitionLengthThread::new_gui()
61 BC_DisplayInfo display_info;
62 int x = display_info.get_abs_cursor_x() - TLW_W / 2;
63 int y = display_info.get_abs_cursor_y() - TLW_H / 2;
64 TransitionLengthDialog *gui = new TransitionLengthDialog(mwindow, this, x, y);
65 gui->create_objects();
69 void TransitionLengthThread::handle_close_event(int result)
71 if( mwindow->in_destructor ) return;
74 mwindow->set_transition_length(transition, new_length);
76 mwindow->set_transition_length(new_length);
82 int TransitionLengthThread::update(double length)
84 if( !EQUIV(this->new_length, length) ) {
85 this->new_length = length;
87 transition->length = transition->track->to_units(length, 1);
88 mwindow->sync_parameters(CHANGE_EDL);
89 mwindow->gui->lock_window();
90 mwindow->gui->draw_overlays(1);
91 mwindow->gui->unlock_window();
98 TransitionUnitsItem::TransitionUnitsItem(TransitionUnitsPopup *popup,
99 const char *text, int id)
106 TransitionUnitsItem::~TransitionUnitsItem()
110 int TransitionUnitsItem::handle_event()
112 TransitionUnitsPopup *units_popup = (TransitionUnitsPopup *)get_popup_menu();
113 TransitionLengthDialog *gui = units_popup->gui;
114 double length = gui->thread->new_length;
115 units_popup->units = id;
116 gui->update_text(length);
117 units_popup->set_text(get_text());
121 TransitionUnitsPopup::TransitionUnitsPopup(TransitionLengthDialog *gui, int x, int y)
122 : BC_PopupMenu(x, y, xS(120), "", 1)
125 units = TIME_SECONDS;
128 TransitionUnitsPopup::~TransitionUnitsPopup()
132 void TransitionUnitsPopup::create_objects()
134 TransitionUnitsItem *units_item;
135 add_item(units_item = new TransitionUnitsItem(this, _("Seconds"), TIME_SECONDS));
136 add_item(new TransitionUnitsItem(this, _("Frames"), TIME_FRAMES));
137 add_item(new TransitionUnitsItem(this, _("Samples"), TIME_SAMPLES));
138 add_item(new TransitionUnitsItem(this, _("H:M:S.xxx"), TIME_HMS));
139 add_item(new TransitionUnitsItem(this, _("H:M:S:frm"), TIME_HMSF));
140 set_text(units_item->get_text());
144 TransitionLengthDialog::TransitionLengthDialog(MWindow *mwindow,
145 TransitionLengthThread *thread, int x, int y)
146 : BC_Window(_(PROGRAM_NAME ": Transition length"), x, y,
147 TLW_W, TLW_H, -1, -1, 0, 0, 1)
149 this->mwindow = mwindow;
150 this->thread = thread;
153 TransitionLengthDialog::~TransitionLengthDialog()
158 void TransitionLengthDialog::create_objects()
160 lock_window("TransitionLengthDialog::create_objects");
161 add_subwindow(units_popup = new TransitionUnitsPopup(this, xS(10), yS(10)));
162 units_popup->create_objects();
163 text = new TransitionLengthText(mwindow, this, xS(160), yS(10));
164 text->create_objects();
165 text->set_precision(3);
166 text->set_increment(0.1);
167 add_subwindow(new BC_OKButton(this));
168 add_subwindow(new BC_CancelButton(this));
173 int TransitionLengthDialog::close_event()
179 void TransitionLengthDialog::update_text(double length)
181 int units = units_popup->units;
182 EDLSession *session = mwindow->edl->session;
183 char string[BCSTRLEN];
184 Units::totext(string, length, units,
185 session->sample_rate, session->frame_rate,
186 session->frames_per_foot);
187 text->update(string);
191 TransitionLengthText::TransitionLengthText(MWindow *mwindow,
192 TransitionLengthDialog *gui, int x, int y)
193 : BC_TumbleTextBox(gui, (float)gui->thread->new_length,
194 0.f, 100.f, x, y, xS(100))
196 this->mwindow = mwindow;
200 int TransitionLengthText::handle_event()
202 const char *text = get_text();
203 int units = gui->units_popup->units;
204 EDLSession *session = gui->mwindow->edl->session;
205 double result = Units::text_to_seconds(text, session->sample_rate,
206 units, session->frame_rate, session->frames_per_foot);
207 return gui->thread->update(result);
210 int TransitionLengthText::handle_up_down(int dir)
213 int units = gui->units_popup->units;
214 EDLSession *session = gui->mwindow->edl->session;
222 delta = session->frame_rate > 0 ? 1./session->frame_rate : 0;
225 delta = session->sample_rate > 0 ? 1./session->sample_rate : 0;
228 double length = gui->thread->new_length + delta * dir;
229 gui->update_text(length);
230 return gui->thread->update(length);
233 int TransitionLengthText::handle_up_event()
235 return handle_up_down(+1);
237 int TransitionLengthText::handle_down_event()
239 return handle_up_down(-1);
243 TransitionPopup::TransitionPopup(MWindow *mwindow, MWindowGUI *gui)
244 : BC_PopupMenu(0, 0, 0, "", 0)
246 this->mwindow = mwindow;
250 TransitionPopup::~TransitionPopup()
252 delete length_thread;
253 // delete dialog_thread;
257 void TransitionPopup::create_objects()
259 length_thread = new TransitionLengthThread(mwindow);
260 // add_item(attach = new TransitionPopupAttach(mwindow, this));
261 add_item(show = new TransitionPopupShow(mwindow, this));
262 add_item(on = new TransitionPopupOn(mwindow, this));
263 add_item(length_item = new TransitionPopupLength(mwindow, this));
264 add_item(detach = new TransitionPopupDetach(mwindow, this));
267 int TransitionPopup::update(Transition *transition)
269 this->transition = transition;
270 show->set_checked(transition->show);
271 on->set_checked(transition->on);
273 sprintf(len_text, _("Length: %2.2f sec"), transition->track->from_units(transition->length));
274 length_item->set_text(len_text);
279 TransitionPopupAttach::TransitionPopupAttach(MWindow *mwindow, TransitionPopup *popup)
280 : BC_MenuItem(_("Attach..."))
282 this->mwindow = mwindow;
286 TransitionPopupAttach::~TransitionPopupAttach()
290 int TransitionPopupAttach::handle_event()
292 // popup->dialog_thread->start();
297 TransitionPopupDetach::TransitionPopupDetach(MWindow *mwindow, TransitionPopup *popup)
298 : BC_MenuItem(_("Detach"))
300 this->mwindow = mwindow;
304 TransitionPopupDetach::~TransitionPopupDetach()
308 int TransitionPopupDetach::handle_event()
310 mwindow->detach_transition(popup->transition);
315 TransitionPopupOn::TransitionPopupOn(MWindow *mwindow, TransitionPopup *popup)
316 : BC_MenuItem(_("On"))
318 this->mwindow = mwindow;
322 TransitionPopupOn::~TransitionPopupOn()
326 int TransitionPopupOn::handle_event()
328 popup->transition->on = !get_checked();
329 mwindow->sync_parameters(CHANGE_EDL);
334 TransitionPopupShow::TransitionPopupShow(MWindow *mwindow, TransitionPopup *popup)
335 : BC_MenuItem(_("Show"))
337 this->mwindow = mwindow;
341 TransitionPopupShow::~TransitionPopupShow()
345 int TransitionPopupShow::handle_event()
347 mwindow->show_plugin(popup->transition);
352 TransitionPopupLength::TransitionPopupLength(MWindow *mwindow, TransitionPopup *popup)
353 : BC_MenuItem(_("Length"))
355 this->mwindow = mwindow;
359 TransitionPopupLength::~TransitionPopupLength()
363 int TransitionPopupLength::handle_event()
365 Transition *transition = popup->transition;
366 double length = transition->edit->track->from_units(transition->length);
367 popup->length_thread->start(popup->transition, length);