18 new shapewipe transitions from rafa, rework savefile/confirm for nested edl edits
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / transitionpopup.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "edit.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "language.h"
28 #include "mwindow.h"
29 #include "mwindowgui.h"
30 #include "plugin.h"
31 #include "transition.h"
32 #include "track.h"
33 #include "tracks.h"
34 #include "transitionpopup.h"
35
36
37 TransitionLengthThread::TransitionLengthThread(MWindow *mwindow)
38  : BC_DialogThread()
39 {
40         this->mwindow = mwindow;
41 }
42
43 TransitionLengthThread::~TransitionLengthThread()
44 {
45         close_window();
46 }
47
48 void TransitionLengthThread::start(Transition *transition, double length)
49 {
50         this->transition = transition;
51         this->orig_length = length;
52         this->new_length = length;
53         BC_DialogThread::start();
54 }
55
56 #define TLW_W xS(300)
57 #define TLW_H yS(100)
58
59 BC_Window* TransitionLengthThread::new_gui()
60 {
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();
66         return gui;
67 }
68
69 void TransitionLengthThread::handle_close_event(int result)
70 {
71         if( mwindow->in_destructor ) return;
72         if( !result ) {
73                 if( transition )
74                         mwindow->set_transition_length(transition, new_length);
75                 else
76                         mwindow->set_transition_length(new_length);
77         }
78         else
79                 update(orig_length);
80 }
81
82 int TransitionLengthThread::update(double length)
83 {
84         if( !EQUIV(this->new_length, length) ) {
85                 this->new_length = length;
86                 if( transition ) {
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();
92                 }
93         }
94         return 1;
95 }
96
97
98 TransitionUnitsItem::TransitionUnitsItem(TransitionUnitsPopup *popup,
99                 const char *text, int id)
100  : BC_MenuItem(text)
101 {
102         this->popup = popup;
103         this->id = id;
104 }
105
106 TransitionUnitsItem::~TransitionUnitsItem()
107 {
108 }
109
110 int TransitionUnitsItem::handle_event()
111 {
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;
117         char text[BCSTRLEN];
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());
123         return 1;
124 }
125
126 TransitionUnitsPopup::TransitionUnitsPopup(TransitionLengthDialog *gui, int x, int y)
127  : BC_PopupMenu(x, y, xS(120), "", 1)
128 {
129         this->gui = gui;
130         units = TIME_SECONDS;
131 }
132
133 TransitionUnitsPopup::~TransitionUnitsPopup()
134 {
135 }
136
137 void TransitionUnitsPopup::create_objects()
138 {
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());
146 }
147
148
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)
153 {
154         this->mwindow = mwindow;
155         this->thread = thread;
156 }
157
158 TransitionLengthDialog::~TransitionLengthDialog()
159 {
160 }
161
162
163 void TransitionLengthDialog::create_objects()
164 {
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));
174         show_window();
175         unlock_window();
176 }
177
178 int TransitionLengthDialog::close_event()
179 {
180         set_done(0);
181         return 1;
182 }
183
184
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))
189 {
190         this->mwindow = mwindow;
191         this->gui = gui;
192 }
193
194 int TransitionLengthText::handle_event()
195 {
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);
202 }
203
204 int TransitionLengthText::handle_up_down(int dir)
205 {
206         double delta = 0;
207         int units = gui->units_popup->units;
208         EDLSession *session = gui->mwindow->edl->session;
209         switch( units ) {
210         case TIME_SECONDS:
211         case TIME_HMS:
212                 delta = 0.1;
213                 break;
214         case TIME_HMSF:
215         case TIME_FRAMES:
216                 delta = session->frame_rate > 0 ? 1./session->frame_rate : 0;
217                 break;
218         case TIME_SAMPLES:
219                 delta = session->sample_rate > 0 ? 1./session->sample_rate : 0;
220                 break;
221         }
222         double length = gui->thread->new_length + delta * dir;
223         char text[BCSTRLEN];
224         Units::totext(text, length, units,
225                 session->sample_rate, session->frame_rate,
226                 session->frames_per_foot);
227         update(text);
228         return gui->thread->update(length);
229 }
230
231 int TransitionLengthText::handle_up_event()
232 {
233         return handle_up_down(+1);
234 }
235 int TransitionLengthText::handle_down_event()
236 {
237         return handle_up_down(-1);
238 }
239
240
241 TransitionPopup::TransitionPopup(MWindow *mwindow, MWindowGUI *gui)
242  : BC_PopupMenu(0, 0, 0, "", 0)
243 {
244         this->mwindow = mwindow;
245         this->gui = gui;
246 }
247
248 TransitionPopup::~TransitionPopup()
249 {
250         delete length_thread;
251 //      delete dialog_thread;
252 }
253
254
255 void TransitionPopup::create_objects()
256 {
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));
263 }
264
265 int TransitionPopup::update(Transition *transition)
266 {
267         this->transition = transition;
268         show->set_checked(transition->show);
269         on->set_checked(transition->on);
270         char len_text[50];
271         sprintf(len_text, _("Length: %2.2f sec"), transition->track->from_units(transition->length));
272         length_item->set_text(len_text);
273         return 0;
274 }
275
276
277 TransitionPopupAttach::TransitionPopupAttach(MWindow *mwindow, TransitionPopup *popup)
278  : BC_MenuItem(_("Attach..."))
279 {
280         this->mwindow = mwindow;
281         this->popup = popup;
282 }
283
284 TransitionPopupAttach::~TransitionPopupAttach()
285 {
286 }
287
288 int TransitionPopupAttach::handle_event()
289 {
290 //      popup->dialog_thread->start();
291         return 1;
292 }
293
294
295 TransitionPopupDetach::TransitionPopupDetach(MWindow *mwindow, TransitionPopup *popup)
296  : BC_MenuItem(_("Detach"))
297 {
298         this->mwindow = mwindow;
299         this->popup = popup;
300 }
301
302 TransitionPopupDetach::~TransitionPopupDetach()
303 {
304 }
305
306 int TransitionPopupDetach::handle_event()
307 {
308         mwindow->detach_transition(popup->transition);
309         return 1;
310 }
311
312
313 TransitionPopupOn::TransitionPopupOn(MWindow *mwindow, TransitionPopup *popup)
314  : BC_MenuItem(_("On"))
315 {
316         this->mwindow = mwindow;
317         this->popup = popup;
318 }
319
320 TransitionPopupOn::~TransitionPopupOn()
321 {
322 }
323
324 int TransitionPopupOn::handle_event()
325 {
326         popup->transition->on = !get_checked();
327         mwindow->sync_parameters(CHANGE_EDL);
328         return 1;
329 }
330
331
332 TransitionPopupShow::TransitionPopupShow(MWindow *mwindow, TransitionPopup *popup)
333  : BC_MenuItem(_("Show"))
334 {
335         this->mwindow = mwindow;
336         this->popup = popup;
337 }
338
339 TransitionPopupShow::~TransitionPopupShow()
340 {
341 }
342
343 int TransitionPopupShow::handle_event()
344 {
345         mwindow->show_plugin(popup->transition);
346         return 1;
347 }
348
349
350 TransitionPopupLength::TransitionPopupLength(MWindow *mwindow, TransitionPopup *popup)
351  : BC_MenuItem(_("Length"))
352 {
353         this->mwindow = mwindow;
354         this->popup = popup;
355 }
356
357 TransitionPopupLength::~TransitionPopupLength()
358 {
359 }
360
361 int TransitionPopupLength::handle_event()
362 {
363         Transition *transition = popup->transition;
364         double length = transition->edit->track->from_units(transition->length);
365         popup->length_thread->start(popup->transition, length);
366         return 1;
367 }
368