add 2 asset list fmts, user title rework, added show edit, bt tweak
[goodguy/history.git] / cinelerra-5.1 / cinelerra / editpopup.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 "asset.h"
23 #include "assets.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "edit.h"
27 #include "editpopup.h"
28 #include "edl.h"
29 #include "edlsession.h"
30 #include "file.h"
31 #include "keys.h"
32 #include "language.h"
33 #include "localsession.h"
34 #include "mainerror.h"
35 #include "mainsession.h"
36 #include "mwindow.h"
37 #include "mwindowgui.h"
38 #include "plugindialog.h"
39 #include "resizetrackthread.h"
40 #include "track.h"
41 #include "tracks.h"
42 #include "trackcanvas.h"
43
44 #include <string.h>
45
46 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
47  : BC_PopupMenu(0, 0, 0, "", 0)
48 {
49         this->mwindow = mwindow;
50         this->gui = gui;
51 }
52
53 EditPopup::~EditPopup()
54 {
55 }
56
57 void EditPopup::create_objects()
58 {
59         add_item(new EditAttachEffect(mwindow, this));
60         add_item(new EditMoveTrackUp(mwindow, this));
61         add_item(new EditMoveTrackDown(mwindow, this));
62         add_item(new EditPopupDeleteTrack(mwindow, this));
63         add_item(new EditPopupAddTrack(mwindow, this));
64         add_item(new EditPopupFindAsset(mwindow, this));
65         add_item(new EditPopupTitle(mwindow, this));
66         add_item(new EditPopupShow(mwindow, this));
67         resize_option = 0;
68         matchsize_option = 0;
69 }
70
71 int EditPopup::update(Track *track, Edit *edit)
72 {
73         this->edit = edit;
74         this->track = track;
75
76         if(track->data_type == TRACK_VIDEO && !resize_option)
77         {
78                 add_item(resize_option = new EditPopupResize(mwindow, this));
79                 add_item(matchsize_option = new EditPopupMatchSize(mwindow, this));
80         }
81         else
82         if(track->data_type == TRACK_AUDIO && resize_option)
83         {
84                 del_item(resize_option);     resize_option = 0;
85                 del_item(matchsize_option);  matchsize_option = 0;
86         }
87         return 0;
88 }
89
90
91 EditAttachEffect::EditAttachEffect(MWindow *mwindow, EditPopup *popup)
92  : BC_MenuItem(_("Attach effect..."))
93 {
94         this->mwindow = mwindow;
95         this->popup = popup;
96         dialog_thread = new PluginDialogThread(mwindow);
97 }
98
99 EditAttachEffect::~EditAttachEffect()
100 {
101         delete dialog_thread;
102 }
103
104 int EditAttachEffect::handle_event()
105 {
106         dialog_thread->start_window(popup->track,
107                 0, _(PROGRAM_NAME ": Attach Effect"),
108                 0, popup->track->data_type);
109         return 1;
110 }
111
112
113 EditMoveTrackUp::EditMoveTrackUp(MWindow *mwindow, EditPopup *popup)
114  : BC_MenuItem(_("Move up"))
115 {
116         this->mwindow = mwindow;
117         this->popup = popup;
118 }
119 EditMoveTrackUp::~EditMoveTrackUp()
120 {
121 }
122 int EditMoveTrackUp::handle_event()
123 {
124         mwindow->move_track_up(popup->track);
125         return 1;
126 }
127
128
129
130 EditMoveTrackDown::EditMoveTrackDown(MWindow *mwindow, EditPopup *popup)
131  : BC_MenuItem(_("Move down"))
132 {
133         this->mwindow = mwindow;
134         this->popup = popup;
135 }
136 EditMoveTrackDown::~EditMoveTrackDown()
137 {
138 }
139 int EditMoveTrackDown::handle_event()
140 {
141         mwindow->move_track_down(popup->track);
142         return 1;
143 }
144
145
146 EditPopupResize::EditPopupResize(MWindow *mwindow, EditPopup *popup)
147  : BC_MenuItem(_("Resize track..."))
148 {
149         this->mwindow = mwindow;
150         this->popup = popup;
151         dialog_thread = new ResizeTrackThread(mwindow);
152 }
153 EditPopupResize::~EditPopupResize()
154 {
155         delete dialog_thread;
156 }
157
158 int EditPopupResize::handle_event()
159 {
160         dialog_thread->start_window(popup->track);
161         return 1;
162 }
163
164
165 EditPopupMatchSize::EditPopupMatchSize(MWindow *mwindow, EditPopup *popup)
166  : BC_MenuItem(_("Match output size"))
167 {
168         this->mwindow = mwindow;
169         this->popup = popup;
170 }
171 EditPopupMatchSize::~EditPopupMatchSize()
172 {
173 }
174
175 int EditPopupMatchSize::handle_event()
176 {
177         mwindow->match_output_size(popup->track);
178         return 1;
179 }
180
181
182 EditPopupDeleteTrack::EditPopupDeleteTrack(MWindow *mwindow, EditPopup *popup)
183  : BC_MenuItem(_("Delete track"))
184 {
185         this->mwindow = mwindow;
186         this->popup = popup;
187 }
188 int EditPopupDeleteTrack::handle_event()
189 {
190         mwindow->delete_track(popup->track);
191         return 1;
192 }
193
194
195 EditPopupAddTrack::EditPopupAddTrack(MWindow *mwindow, EditPopup *popup)
196  : BC_MenuItem(_("Add track"))
197 {
198         this->mwindow = mwindow;
199         this->popup = popup;
200 }
201
202 int EditPopupAddTrack::handle_event()
203 {
204         switch( popup->track->data_type ) {
205         case TRACK_AUDIO:
206                 mwindow->add_audio_track_entry(1, popup->track);
207                 break;
208         case TRACK_VIDEO:
209                 mwindow->add_video_track_entry(popup->track);
210                 break;
211         case TRACK_SUBTITLE:
212                 mwindow->add_subttl_track_entry(popup->track);
213                 break;
214         }
215         return 1;
216 }
217
218 EditPopupFindAsset::EditPopupFindAsset(MWindow *mwindow, EditPopup *popup)
219  : BC_MenuItem(_("Find in Resources"))
220 {
221         this->mwindow = mwindow;
222         this->popup = popup;
223 }
224
225 int EditPopupFindAsset::handle_event()
226 {
227         Edit *edit = popup->edit;
228         if( edit ) {
229                 Indexable *idxbl = (Indexable *)edit->asset;
230                 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
231                 if( idxbl ) {
232                         AWindowGUI *agui = mwindow->awindow->gui;
233                         agui->lock_window("EditPopupFindAsset::handle_event");
234                         AssetPicon *picon = 0;
235                         for( int i=0, n=agui->assets.size(); i<n; ++i ) {
236                                 AssetPicon *ap = (AssetPicon *)agui->assets[i];
237                                 int found = ap->indexable && ( idxbl == ap->indexable ||
238                                         !strcmp(idxbl->path, ap->indexable->path) );
239                                 if( found && !picon ) picon = ap;
240                                 ap->set_selected(found);
241                         }
242                         if( picon ) {
243                                 int selected_folder = picon->indexable->awindow_folder;
244                                 mwindow->edl->session->awindow_folder = selected_folder;
245                                 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
246                                         AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
247                                         int selected = folder_item->foldernum == selected_folder ? 1 : 0;
248                                         folder_item->set_selected(selected);
249                                 }
250                         }
251                         agui->unlock_window();
252                         agui->async_update_assets();
253                 }
254         }
255         return 1;
256 }
257
258
259 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
260  : BC_MenuItem(_("User title..."))
261 {
262         this->mwindow = mwindow;
263         this->popup = popup;
264         dialog_thread = new EditTitleDialogThread(this);
265 }
266
267 EditPopupTitle::~EditPopupTitle()
268 {
269         delete dialog_thread;
270 }
271
272 int EditPopupTitle::handle_event()
273 {
274         if( popup->edit ) {
275                 dialog_thread->close_window();
276                 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
277                 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
278                 dialog_thread->start(wx, wy);
279         }
280         return 1;
281 }
282
283 void EditTitleDialogThread::start(int wx, int wy)
284 {
285         this->wx = wx;  this->wy = wy;
286         BC_DialogThread::start();
287 }
288
289 EditTitleDialogThread::EditTitleDialogThread(EditPopupTitle *edit_title)
290 {
291         this->edit_title = edit_title;
292         window = 0;
293 }
294 EditTitleDialogThread::~EditTitleDialogThread()
295 {
296         close_window();
297 }
298
299 BC_Window* EditTitleDialogThread::new_gui()
300 {
301         MWindow *mwindow = edit_title->mwindow;
302         EditPopup *popup = edit_title->popup;
303         window = new EditPopupTitleWindow(mwindow, popup, wx, wy);
304         window->create_objects();
305         return window;
306 }
307
308 void EditTitleDialogThread::handle_close_event(int result)
309 {
310         window = 0;
311 }
312
313 void EditTitleDialogThread::handle_done_event(int result)
314 {
315         if( result ) return;
316         MWindow *mwindow = edit_title->mwindow;
317         EditPopup *popup = edit_title->popup;
318         strcpy(popup->edit->user_title, window->title_text->get_text());
319         mwindow->gui->lock_window("EditTitleDialogThread::handle_done_event");
320         mwindow->gui->draw_canvas(1, 0);
321         mwindow->gui->flash_canvas(1);
322         mwindow->gui->unlock_window();
323 }
324
325 EditPopupTitleWindow::EditPopupTitleWindow(MWindow *mwindow,
326                 EditPopup *popup, int wx, int wy)
327  : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
328         300, 130, 300, 130, 0, 0, 1)
329 {
330         this->mwindow = mwindow;
331         this->popup = popup;
332         strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
333 }
334
335 EditPopupTitleWindow::~EditPopupTitleWindow()
336 {
337 }
338
339 void EditPopupTitleWindow::create_objects()
340 {
341         lock_window("EditPopupTitleWindow::create_objects");
342         int x = 10, y = 10;
343         add_subwindow(new BC_Title(x, y, _("User title:")));
344         title_text = new EditPopupTitleText(this, mwindow, x+15, y+20, new_text);
345         add_subwindow(title_text);
346         add_tool(new BC_OKButton(this));
347         add_tool(new BC_CancelButton(this));
348
349
350         show_window();
351         flush();
352         unlock_window();
353 }
354
355
356 EditPopupTitleText::EditPopupTitleText(EditPopupTitleWindow *window,
357         MWindow *mwindow, int x, int y, const char *text)
358  : BC_TextBox(x, y, 250, 1, text)
359 {
360         this->window = window;
361         this->mwindow = mwindow;
362 }
363
364 EditPopupTitleText::~EditPopupTitleText()
365 {
366 }
367
368 int EditPopupTitleText::handle_event()
369 {
370         if( get_keypress() == RETURN )
371                 window->set_done(0);
372         return 1;
373 }
374
375
376 EditPopupShow::EditPopupShow(MWindow *mwindow, EditPopup *popup)
377  : BC_MenuItem(_("Show edit"))
378 {
379         this->mwindow = mwindow;
380         this->popup = popup;
381         dialog_thread = new EditShowDialogThread(this);
382 }
383
384 EditPopupShow::~EditPopupShow()
385 {
386         delete dialog_thread;
387 }
388
389 int EditPopupShow::handle_event()
390 {
391         if( popup->edit ) {
392                 dialog_thread->close_window();
393                 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
394                 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
395                 dialog_thread->start(wx, wy);
396         }
397         return 1;
398 }
399
400 void EditShowDialogThread::start(int wx, int wy)
401 {
402         this->wx = wx;  this->wy = wy;
403         BC_DialogThread::start();
404 }
405
406 EditShowDialogThread::EditShowDialogThread(EditPopupShow *edit_show)
407 {
408         this->edit_show = edit_show;
409         window = 0;
410 }
411 EditShowDialogThread::~EditShowDialogThread()
412 {
413         close_window();
414 }
415
416 BC_Window* EditShowDialogThread::new_gui()
417 {
418         MWindow *mwindow = edit_show->mwindow;
419         EditPopup *popup = edit_show->popup;
420         window = new EditPopupShowWindow(mwindow, popup, wx, wy);
421         window->create_objects();
422         return window;
423 }
424
425 void EditShowDialogThread::handle_close_event(int result)
426 {
427         window = 0;
428 }
429
430 EditPopupShowWindow::EditPopupShowWindow(MWindow *mwindow,
431                 EditPopup *popup, int wx, int wy)
432  : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
433         300, 200, 300, 200, 0, 0, 1)
434 {
435         this->mwindow = mwindow;
436         this->popup = popup;
437 }
438
439 EditPopupShowWindow::~EditPopupShowWindow()
440 {
441 }
442
443 void EditPopupShowWindow::create_objects()
444 {
445         lock_window("EditPopupShowWindow::create_objects");
446         int x = 10, y = 10;
447         add_subwindow(new BC_Title(x, y, _("Show edit:")));
448
449         EDLSession *session = mwindow->edl->session;
450         int time_format = session->time_format;
451         int sample_rate = session->sample_rate;
452         double frame_rate = session->frame_rate;
453         double frames_per_foot = session->frames_per_foot;
454
455         Track *track = popup->track;
456         Edit *edit = popup->edit;
457         double startsource = track->from_units(edit->startsource);
458         double startproject = track->from_units(edit->startproject);
459         double length = track->from_units(edit->length);
460
461         char text[BCTEXTLEN], text_length[BCSTRLEN];
462         char text_startsource[BCSTRLEN], text_startproject[BCSTRLEN];
463         sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
464                 Units::totext(text_startsource, startsource,
465                         time_format, sample_rate, frame_rate, frames_per_foot),
466                 Units::totext(text_startproject, startproject,
467                         time_format, sample_rate, frame_rate, frames_per_foot),
468                 Units::totext(text_length, length,
469                         time_format, sample_rate, frame_rate, frames_per_foot));
470         show_text = new EditPopupShowText(this, mwindow, x+15, y+20, text);
471         add_subwindow(show_text);
472         add_tool(new BC_OKButton(this));
473
474         show_window();
475         flush();
476         unlock_window();
477 }
478
479
480 EditPopupShowText::EditPopupShowText(EditPopupShowWindow *window,
481         MWindow *mwindow, int x, int y, const char *text)
482  : BC_TextBox(x, y, 250, 4, text)
483 {
484         this->window = window;
485         this->mwindow = mwindow;
486 }
487
488 EditPopupShowText::~EditPopupShowText()
489 {
490 }
491