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
25 #include "awindowgui.h"
28 #include "editpopup.h"
30 #include "edlsession.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainsession.h"
38 #include "mwindowgui.h"
39 #include "plugindialog.h"
40 #include "resizetrackthread.h"
43 #include "trackcanvas.h"
47 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
48 : BC_PopupMenu(0, 0, 0, "", 0)
50 this->mwindow = mwindow;
54 EditPopup::~EditPopup()
58 void EditPopup::create_objects()
60 add_item(new EditAttachEffect(mwindow, this));
61 add_item(new EditMoveTrackUp(mwindow, this));
62 add_item(new EditMoveTrackDown(mwindow, this));
63 add_item(new EditPopupDeleteTrack(mwindow, this));
64 add_item(new EditPopupAddTrack(mwindow, this));
65 add_item(new EditPopupFindAsset(mwindow, this));
66 add_item(new EditPopupTitle(mwindow, this));
67 add_item(new EditPopupShow(mwindow, this));
72 int EditPopup::update(Track *track, Edit *edit)
77 if(track->data_type == TRACK_VIDEO && !resize_option)
79 add_item(resize_option = new EditPopupResize(mwindow, this));
80 add_item(matchsize_option = new EditPopupMatchSize(mwindow, this));
83 if(track->data_type == TRACK_AUDIO && resize_option)
85 del_item(resize_option); resize_option = 0;
86 del_item(matchsize_option); matchsize_option = 0;
92 EditAttachEffect::EditAttachEffect(MWindow *mwindow, EditPopup *popup)
93 : BC_MenuItem(_("Attach effect..."))
95 this->mwindow = mwindow;
97 dialog_thread = new PluginDialogThread(mwindow);
100 EditAttachEffect::~EditAttachEffect()
102 delete dialog_thread;
105 int EditAttachEffect::handle_event()
107 dialog_thread->start_window(popup->track,
108 0, _(PROGRAM_NAME ": Attach Effect"),
109 0, popup->track->data_type);
114 EditMoveTrackUp::EditMoveTrackUp(MWindow *mwindow, EditPopup *popup)
115 : BC_MenuItem(_("Move up"))
117 this->mwindow = mwindow;
120 EditMoveTrackUp::~EditMoveTrackUp()
123 int EditMoveTrackUp::handle_event()
125 mwindow->move_track_up(popup->track);
131 EditMoveTrackDown::EditMoveTrackDown(MWindow *mwindow, EditPopup *popup)
132 : BC_MenuItem(_("Move down"))
134 this->mwindow = mwindow;
137 EditMoveTrackDown::~EditMoveTrackDown()
140 int EditMoveTrackDown::handle_event()
142 mwindow->move_track_down(popup->track);
147 EditPopupResize::EditPopupResize(MWindow *mwindow, EditPopup *popup)
148 : BC_MenuItem(_("Resize track..."))
150 this->mwindow = mwindow;
152 dialog_thread = new ResizeTrackThread(mwindow);
154 EditPopupResize::~EditPopupResize()
156 delete dialog_thread;
159 int EditPopupResize::handle_event()
161 dialog_thread->start_window(popup->track);
166 EditPopupMatchSize::EditPopupMatchSize(MWindow *mwindow, EditPopup *popup)
167 : BC_MenuItem(_("Match output size"))
169 this->mwindow = mwindow;
172 EditPopupMatchSize::~EditPopupMatchSize()
176 int EditPopupMatchSize::handle_event()
178 mwindow->match_output_size(popup->track);
183 EditPopupDeleteTrack::EditPopupDeleteTrack(MWindow *mwindow, EditPopup *popup)
184 : BC_MenuItem(_("Delete track"))
186 this->mwindow = mwindow;
189 int EditPopupDeleteTrack::handle_event()
191 mwindow->delete_track(popup->track);
196 EditPopupAddTrack::EditPopupAddTrack(MWindow *mwindow, EditPopup *popup)
197 : BC_MenuItem(_("Add track"))
199 this->mwindow = mwindow;
203 int EditPopupAddTrack::handle_event()
205 switch( popup->track->data_type ) {
207 mwindow->add_audio_track_entry(1, popup->track);
210 mwindow->add_video_track_entry(popup->track);
213 mwindow->add_subttl_track_entry(popup->track);
219 EditPopupFindAsset::EditPopupFindAsset(MWindow *mwindow, EditPopup *popup)
220 : BC_MenuItem(_("Find in Resources"))
222 this->mwindow = mwindow;
226 int EditPopupFindAsset::handle_event()
228 Edit *edit = popup->edit;
230 Indexable *idxbl = (Indexable *)edit->asset;
231 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
233 AWindowGUI *agui = mwindow->awindow->gui;
234 agui->lock_window("EditPopupFindAsset::handle_event");
235 AssetPicon *picon = 0;
236 for( int i=0, n=agui->assets.size(); i<n; ++i ) {
237 AssetPicon *ap = (AssetPicon *)agui->assets[i];
238 int found = ap->indexable && ( idxbl == ap->indexable ||
239 !strcmp(idxbl->path, ap->indexable->path) );
240 if( found && !picon ) picon = ap;
241 ap->set_selected(found);
244 int selected_folder = picon->indexable->awindow_folder;
245 mwindow->edl->session->awindow_folder = selected_folder;
246 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
247 AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
248 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
249 folder_item->set_selected(selected);
252 agui->unlock_window();
253 agui->async_update_assets();
260 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
261 : BC_MenuItem(_("User title..."))
263 this->mwindow = mwindow;
265 dialog_thread = new EditTitleDialogThread(this);
268 EditPopupTitle::~EditPopupTitle()
270 delete dialog_thread;
273 int EditPopupTitle::handle_event()
276 dialog_thread->close_window();
277 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
278 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
279 dialog_thread->start(wx, wy);
284 void EditTitleDialogThread::start(int wx, int wy)
286 this->wx = wx; this->wy = wy;
287 BC_DialogThread::start();
290 EditTitleDialogThread::EditTitleDialogThread(EditPopupTitle *edit_title)
292 this->edit_title = edit_title;
295 EditTitleDialogThread::~EditTitleDialogThread()
300 BC_Window* EditTitleDialogThread::new_gui()
302 MWindow *mwindow = edit_title->mwindow;
303 EditPopup *popup = edit_title->popup;
304 window = new EditPopupTitleWindow(mwindow, popup, wx, wy);
305 window->create_objects();
309 void EditTitleDialogThread::handle_close_event(int result)
314 void EditTitleDialogThread::handle_done_event(int result)
317 MWindow *mwindow = edit_title->mwindow;
318 EditPopup *popup = edit_title->popup;
319 strcpy(popup->edit->user_title, window->title_text->get_text());
320 mwindow->gui->lock_window("EditTitleDialogThread::handle_done_event");
321 mwindow->gui->draw_canvas(1, 0);
322 mwindow->gui->flash_canvas(1);
323 mwindow->gui->unlock_window();
326 EditPopupTitleWindow::EditPopupTitleWindow(MWindow *mwindow,
327 EditPopup *popup, int wx, int wy)
328 : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
329 300, 130, 300, 130, 0, 0, 1)
331 this->mwindow = mwindow;
333 strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
336 EditPopupTitleWindow::~EditPopupTitleWindow()
340 void EditPopupTitleWindow::create_objects()
342 lock_window("EditPopupTitleWindow::create_objects");
344 add_subwindow(new BC_Title(x, y, _("User title:")));
345 title_text = new EditPopupTitleText(this, mwindow, x+15, y+20, new_text);
346 add_subwindow(title_text);
347 add_tool(new BC_OKButton(this));
348 add_tool(new BC_CancelButton(this));
357 EditPopupTitleText::EditPopupTitleText(EditPopupTitleWindow *window,
358 MWindow *mwindow, int x, int y, const char *text)
359 : BC_TextBox(x, y, 250, 1, text)
361 this->window = window;
362 this->mwindow = mwindow;
365 EditPopupTitleText::~EditPopupTitleText()
369 int EditPopupTitleText::handle_event()
371 if( get_keypress() == RETURN )
377 EditPopupShow::EditPopupShow(MWindow *mwindow, EditPopup *popup)
378 : BC_MenuItem(_("Show edit"))
380 this->mwindow = mwindow;
382 dialog_thread = new EditShowDialogThread(this);
385 EditPopupShow::~EditPopupShow()
387 delete dialog_thread;
390 int EditPopupShow::handle_event()
393 dialog_thread->close_window();
394 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
395 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
396 dialog_thread->start(wx, wy);
401 void EditShowDialogThread::start(int wx, int wy)
403 this->wx = wx; this->wy = wy;
404 BC_DialogThread::start();
407 EditShowDialogThread::EditShowDialogThread(EditPopupShow *edit_show)
409 this->edit_show = edit_show;
412 EditShowDialogThread::~EditShowDialogThread()
417 BC_Window* EditShowDialogThread::new_gui()
419 MWindow *mwindow = edit_show->mwindow;
420 EditPopup *popup = edit_show->popup;
421 window = new EditPopupShowWindow(mwindow, popup, wx, wy);
422 window->create_objects();
426 void EditShowDialogThread::handle_close_event(int result)
431 EditPopupShowWindow::EditPopupShowWindow(MWindow *mwindow,
432 EditPopup *popup, int wx, int wy)
433 : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
434 300, 220, 300, 220, 0, 0, 1)
436 this->mwindow = mwindow;
440 EditPopupShowWindow::~EditPopupShowWindow()
444 void EditPopupShowWindow::create_objects()
446 lock_window("EditPopupShowWindow::create_objects");
449 char text[BCTEXTLEN];
450 Track *track = popup->track;
451 Edit *edit = popup->edit;
452 sprintf(text, _("Track %d:"), mwindow->edl->tracks->number_of(track)+1);
453 add_subwindow(title = new BC_Title(x, y, text));
454 int x1 = x + title->get_w() + 10;
455 int tw = get_w() - x1 - 20;
456 truncate_text(text, track->title, tw);
457 add_subwindow(new BC_Title(x1, y, text));
458 y += title->get_h() + 5;
459 sprintf(text, _("Edit %d:"), track->edits->number_of(edit)+1);
460 add_subwindow(title = new BC_Title(x, y, text));
461 char edit_title[BCTEXTLEN];
462 edit->get_title(edit_title);
463 truncate_text(text, edit_title, tw);
464 add_subwindow(new BC_Title(x1, y, text));
465 y += title->get_h() + 5;
467 EDLSession *session = mwindow->edl->session;
468 int time_format = session->time_format;
469 int sample_rate = session->sample_rate;
470 double frame_rate = session->frame_rate;
471 double frames_per_foot = session->frames_per_foot;
473 double startsource = track->from_units(edit->startsource);
474 double startproject = track->from_units(edit->startproject);
475 double length = track->from_units(edit->length);
477 char text_startsource[BCSTRLEN];
478 char text_startproject[BCSTRLEN];
479 char text_length[BCSTRLEN];
480 sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
481 Units::totext(text_startsource, startsource,
482 time_format, sample_rate, frame_rate, frames_per_foot),
483 Units::totext(text_startproject, startproject,
484 time_format, sample_rate, frame_rate, frames_per_foot),
485 Units::totext(text_length, length,
486 time_format, sample_rate, frame_rate, frames_per_foot));
487 show_text = new EditPopupShowText(this, mwindow, x+15, y+10, text);
488 add_subwindow(show_text);
489 add_tool(new BC_OKButton(this));
497 EditPopupShowText::EditPopupShowText(EditPopupShowWindow *window,
498 MWindow *mwindow, int x, int y, const char *text)
499 : BC_TextBox(x, y, 250, 4, text)
501 this->window = window;
502 this->mwindow = mwindow;
505 EditPopupShowText::~EditPopupShowText()