4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "bcdisplayinfo.h"
27 #include "edlsession.h"
30 #include "mwindowgui.h"
32 #include "transition.h"
35 #include "transitionpopup.h"
38 TransitionLengthThread::TransitionLengthThread(MWindow *mwindow)
41 this->mwindow = mwindow;
44 TransitionLengthThread::~TransitionLengthThread()
49 void TransitionLengthThread::start(Transition *transition, double length)
51 this->transition = transition;
52 this->orig_length = length;
53 this->new_length = length;
54 BC_DialogThread::start();
60 BC_Window* TransitionLengthThread::new_gui()
62 BC_DisplayInfo display_info;
63 int x = display_info.get_abs_cursor_x() - TLW_W / 2;
64 int y = display_info.get_abs_cursor_y() - TLW_H / 2;
65 TransitionLengthDialog *gui = new TransitionLengthDialog(mwindow, this, x, y);
66 gui->create_objects();
70 void TransitionLengthThread::handle_close_event(int result)
72 if( mwindow->in_destructor ) return;
75 mwindow->set_transition_length(transition, new_length);
77 mwindow->set_transition_length(new_length);
83 int TransitionLengthThread::update(double length)
85 if( !EQUIV(this->new_length, length) ) {
86 this->new_length = length;
88 transition->length = transition->track->to_units(length, 1);
89 mwindow->sync_parameters(CHANGE_EDL);
90 mwindow->gui->lock_window();
91 mwindow->gui->draw_overlays(1);
92 mwindow->gui->unlock_window();
99 TransitionUnitsItem::TransitionUnitsItem(TransitionUnitsPopup *popup,
100 const char *text, int id)
107 TransitionUnitsItem::~TransitionUnitsItem()
111 int TransitionUnitsItem::handle_event()
113 TransitionUnitsPopup *units_popup = (TransitionUnitsPopup *)get_popup_menu();
114 TransitionLengthDialog *gui = units_popup->gui;
115 double length = gui->thread->new_length;
116 units_popup->units = id;
117 gui->update_text(length);
118 units_popup->set_text(get_text());
122 TransitionUnitsPopup::TransitionUnitsPopup(TransitionLengthDialog *gui, int x, int y)
123 : BC_PopupMenu(x, y, xS(120), "", 1)
126 units = TIME_SECONDS;
129 TransitionUnitsPopup::~TransitionUnitsPopup()
133 void TransitionUnitsPopup::create_objects()
135 TransitionUnitsItem *units_item;
136 add_item(units_item = new TransitionUnitsItem(this, _("Seconds"), TIME_SECONDS));
137 add_item(new TransitionUnitsItem(this, _("Frames"), TIME_FRAMES));
138 add_item(new TransitionUnitsItem(this, _("Samples"), TIME_SAMPLES));
139 add_item(new TransitionUnitsItem(this, _("H:M:S.xxx"), TIME_HMS));
140 add_item(new TransitionUnitsItem(this, _("H:M:S:frm"), TIME_HMSF));
141 set_text(units_item->get_text());
145 TransitionLengthDialog::TransitionLengthDialog(MWindow *mwindow,
146 TransitionLengthThread *thread, int x, int y)
147 : BC_Window(_(PROGRAM_NAME ": Transition length"), x, y,
148 TLW_W, TLW_H, -1, -1, 0, 0, 1)
150 this->mwindow = mwindow;
151 this->thread = thread;
152 // *** CONTEXT_HELP ***
153 context_help_set_keyword("Transition Plugins");
156 TransitionLengthDialog::~TransitionLengthDialog()
161 void TransitionLengthDialog::create_objects()
163 lock_window("TransitionLengthDialog::create_objects");
164 add_subwindow(units_popup = new TransitionUnitsPopup(this, xS(10), yS(10)));
165 units_popup->create_objects();
166 text = new TransitionLengthText(mwindow, this, xS(160), yS(10));
167 text->create_objects();
168 text->set_precision(3);
169 text->set_increment(0.1);
170 add_subwindow(new BC_OKButton(this));
171 add_subwindow(new BC_CancelButton(this));
176 int TransitionLengthDialog::close_event()
182 void TransitionLengthDialog::update_text(double length)
184 int units = units_popup->units;
185 EDLSession *session = mwindow->edl->session;
186 char string[BCSTRLEN];
187 Units::totext(string, length, units,
188 session->sample_rate, session->frame_rate,
189 session->frames_per_foot);
190 text->update(string);
194 TransitionLengthText::TransitionLengthText(MWindow *mwindow,
195 TransitionLengthDialog *gui, int x, int y)
196 : BC_TumbleTextBox(gui, (float)gui->thread->new_length,
197 0.f, 100.f, x, y, xS(100))
199 this->mwindow = mwindow;
203 int TransitionLengthText::handle_event()
205 const char *text = get_text();
206 int units = gui->units_popup->units;
207 EDLSession *session = gui->mwindow->edl->session;
208 double result = Units::text_to_seconds(text, session->sample_rate,
209 units, session->frame_rate, session->frames_per_foot);
210 return gui->thread->update(result);
213 int TransitionLengthText::handle_up_down(int dir)
216 int units = gui->units_popup->units;
217 EDLSession *session = gui->mwindow->edl->session;
225 delta = session->frame_rate > 0 ? 1./session->frame_rate : 0;
228 delta = session->sample_rate > 0 ? 1./session->sample_rate : 0;
231 double length = gui->thread->new_length + delta * dir;
232 gui->update_text(length);
233 return gui->thread->update(length);
236 int TransitionLengthText::handle_up_event()
238 return handle_up_down(+1);
240 int TransitionLengthText::handle_down_event()
242 return handle_up_down(-1);
246 TransitionPopup::TransitionPopup(MWindow *mwindow, MWindowGUI *gui)
247 : BC_PopupMenu(0, 0, 0, "", 0)
249 this->mwindow = mwindow;
253 TransitionPopup::~TransitionPopup()
255 delete length_thread;
256 // delete dialog_thread;
260 void TransitionPopup::create_objects()
262 length_thread = new TransitionLengthThread(mwindow);
263 // add_item(attach = new TransitionPopupAttach(mwindow, this));
264 add_item(show = new TransitionPopupShow(mwindow, this));
265 add_item(on = new TransitionPopupOn(mwindow, this));
266 add_item(length_item = new TransitionPopupLength(mwindow, this));
267 add_item(detach = new TransitionPopupDetach(mwindow, this));
270 int TransitionPopup::update(Transition *transition)
272 this->transition = transition;
273 show->set_checked(transition->show);
274 on->set_checked(transition->on);
276 sprintf(len_text, _("Length: %2.2f sec"), transition->track->from_units(transition->length));
277 length_item->set_text(len_text);
282 TransitionPopupAttach::TransitionPopupAttach(MWindow *mwindow, TransitionPopup *popup)
283 : BC_MenuItem(_("Attach..."))
285 this->mwindow = mwindow;
289 TransitionPopupAttach::~TransitionPopupAttach()
293 int TransitionPopupAttach::handle_event()
295 // popup->dialog_thread->start();
300 TransitionPopupDetach::TransitionPopupDetach(MWindow *mwindow, TransitionPopup *popup)
301 : BC_MenuItem(_("Detach"))
303 this->mwindow = mwindow;
307 TransitionPopupDetach::~TransitionPopupDetach()
311 int TransitionPopupDetach::handle_event()
313 mwindow->detach_transition(popup->transition);
318 TransitionPopupOn::TransitionPopupOn(MWindow *mwindow, TransitionPopup *popup)
319 : BC_MenuItem(_("On"))
321 this->mwindow = mwindow;
325 TransitionPopupOn::~TransitionPopupOn()
329 int TransitionPopupOn::handle_event()
331 popup->transition->on = !get_checked();
332 mwindow->sync_parameters(CHANGE_EDL);
337 TransitionPopupShow::TransitionPopupShow(MWindow *mwindow, TransitionPopup *popup)
338 : BC_MenuItem(_("Show"))
340 this->mwindow = mwindow;
344 TransitionPopupShow::~TransitionPopupShow()
348 int TransitionPopupShow::handle_event()
350 mwindow->show_plugin(popup->transition);
355 TransitionPopupLength::TransitionPopupLength(MWindow *mwindow, TransitionPopup *popup)
356 : BC_MenuItem(_("Length"))
358 this->mwindow = mwindow;
362 TransitionPopupLength::~TransitionPopupLength()
366 int TransitionPopupLength::handle_event()
368 Transition *transition = popup->transition;
369 double length = transition->edit->track->from_units(transition->length);
370 popup->length_thread->start(popup->transition, length);