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 TransitionLengthText *length_text = gui->text;
115 EDLSession *session = gui->mwindow->edl->session;
116 double length = gui->thread->new_length;
118 units_popup->units = id;
119 Units::totext(text, length, units_popup->units, session->sample_rate,
120 session->frame_rate, session->frames_per_foot);
121 length_text->update(text);
122 units_popup->set_text(get_text());
126 TransitionUnitsPopup::TransitionUnitsPopup(TransitionLengthDialog *gui, int x, int y)
127 : BC_PopupMenu(x, y, xS(120), "", 1)
130 units = TIME_SECONDS;
133 TransitionUnitsPopup::~TransitionUnitsPopup()
137 void TransitionUnitsPopup::create_objects()
139 TransitionUnitsItem *units_item;
140 add_item(units_item = new TransitionUnitsItem(this, _("Seconds"), TIME_SECONDS));
141 add_item(new TransitionUnitsItem(this, _("Frames"), TIME_FRAMES));
142 add_item(new TransitionUnitsItem(this, _("Samples"), TIME_SAMPLES));
143 add_item(new TransitionUnitsItem(this, _("H:M:S.xxx"), TIME_HMS));
144 add_item(new TransitionUnitsItem(this, _("H:M:S:frm"), TIME_HMSF));
145 set_text(units_item->get_text());
149 TransitionLengthDialog::TransitionLengthDialog(MWindow *mwindow,
150 TransitionLengthThread *thread, int x, int y)
151 : BC_Window(_(PROGRAM_NAME ": Transition length"), x, y,
152 TLW_W, TLW_H, -1, -1, 0, 0, 1)
154 this->mwindow = mwindow;
155 this->thread = thread;
158 TransitionLengthDialog::~TransitionLengthDialog()
163 void TransitionLengthDialog::create_objects()
165 lock_window("TransitionLengthDialog::create_objects");
166 add_subwindow(units_popup = new TransitionUnitsPopup(this, xS(10), yS(10)));
167 units_popup->create_objects();
168 text = new TransitionLengthText(mwindow, this, xS(160), yS(10));
169 text->create_objects();
170 text->set_precision(3);
171 text->set_increment(0.1);
172 add_subwindow(new BC_OKButton(this));
173 add_subwindow(new BC_CancelButton(this));
178 int TransitionLengthDialog::close_event()
185 TransitionLengthText::TransitionLengthText(MWindow *mwindow,
186 TransitionLengthDialog *gui, int x, int y)
187 : BC_TumbleTextBox(gui, (float)gui->thread->new_length,
188 0.f, 100.f, x, y, xS(100))
190 this->mwindow = mwindow;
194 int TransitionLengthText::handle_event()
196 const char *text = get_text();
197 int units = gui->units_popup->units;
198 EDLSession *session = gui->mwindow->edl->session;
199 double result = Units::text_to_seconds(text, session->sample_rate,
200 units, session->frame_rate, session->frames_per_foot);
201 return gui->thread->update(result);
204 int TransitionLengthText::handle_up_down(int dir)
207 int units = gui->units_popup->units;
208 EDLSession *session = gui->mwindow->edl->session;
216 delta = session->frame_rate > 0 ? 1./session->frame_rate : 0;
219 delta = session->sample_rate > 0 ? 1./session->sample_rate : 0;
222 double length = gui->thread->new_length + delta * dir;
224 Units::totext(text, length, units,
225 session->sample_rate, session->frame_rate,
226 session->frames_per_foot);
228 return gui->thread->update(length);
231 int TransitionLengthText::handle_up_event()
233 return handle_up_down(+1);
235 int TransitionLengthText::handle_down_event()
237 return handle_up_down(-1);
241 TransitionPopup::TransitionPopup(MWindow *mwindow, MWindowGUI *gui)
242 : BC_PopupMenu(0, 0, 0, "", 0)
244 this->mwindow = mwindow;
248 TransitionPopup::~TransitionPopup()
250 delete length_thread;
251 // delete dialog_thread;
255 void TransitionPopup::create_objects()
257 length_thread = new TransitionLengthThread(mwindow);
258 // add_item(attach = new TransitionPopupAttach(mwindow, this));
259 add_item(show = new TransitionPopupShow(mwindow, this));
260 add_item(on = new TransitionPopupOn(mwindow, this));
261 add_item(length_item = new TransitionPopupLength(mwindow, this));
262 add_item(detach = new TransitionPopupDetach(mwindow, this));
265 int TransitionPopup::update(Transition *transition)
267 this->transition = transition;
268 show->set_checked(transition->show);
269 on->set_checked(transition->on);
271 sprintf(len_text, _("Length: %2.2f sec"), transition->track->from_units(transition->length));
272 length_item->set_text(len_text);
277 TransitionPopupAttach::TransitionPopupAttach(MWindow *mwindow, TransitionPopup *popup)
278 : BC_MenuItem(_("Attach..."))
280 this->mwindow = mwindow;
284 TransitionPopupAttach::~TransitionPopupAttach()
288 int TransitionPopupAttach::handle_event()
290 // popup->dialog_thread->start();
295 TransitionPopupDetach::TransitionPopupDetach(MWindow *mwindow, TransitionPopup *popup)
296 : BC_MenuItem(_("Detach"))
298 this->mwindow = mwindow;
302 TransitionPopupDetach::~TransitionPopupDetach()
306 int TransitionPopupDetach::handle_event()
308 mwindow->detach_transition(popup->transition);
313 TransitionPopupOn::TransitionPopupOn(MWindow *mwindow, TransitionPopup *popup)
314 : BC_MenuItem(_("On"))
316 this->mwindow = mwindow;
320 TransitionPopupOn::~TransitionPopupOn()
324 int TransitionPopupOn::handle_event()
326 popup->transition->on = !get_checked();
327 mwindow->sync_parameters(CHANGE_EDL);
332 TransitionPopupShow::TransitionPopupShow(MWindow *mwindow, TransitionPopup *popup)
333 : BC_MenuItem(_("Show"))
335 this->mwindow = mwindow;
339 TransitionPopupShow::~TransitionPopupShow()
343 int TransitionPopupShow::handle_event()
345 mwindow->show_plugin(popup->transition);
350 TransitionPopupLength::TransitionPopupLength(MWindow *mwindow, TransitionPopup *popup)
351 : BC_MenuItem(_("Length"))
353 this->mwindow = mwindow;
357 TransitionPopupLength::~TransitionPopupLength()
361 int TransitionPopupLength::handle_event()
363 Transition *transition = popup->transition;
364 double length = transition->edit->track->from_units(transition->length);
365 popup->length_thread->start(popup->transition, length);