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"
35 #include "localsession.h"
36 #include "mainerror.h"
37 #include "mainsession.h"
39 #include "mwindowgui.h"
40 #include "plugindialog.h"
41 #include "resizetrackthread.h"
44 #include "trackcanvas.h"
48 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
49 : BC_PopupMenu(0, 0, 0, "", 0)
51 this->mwindow = mwindow;
62 EditPopup::~EditPopup()
66 void EditPopup::create_objects()
68 add_item(open_edl = new EditPopupOpenEDL(mwindow, this));
69 add_item(new EditPopupClearSelect(mwindow, this));
70 add_item(new EditPopupSelectEdits(mwindow, this));
71 add_item(new EditPopupDeselectEdits(mwindow, this));
72 add_item(new EditPopupCopy(mwindow, this));
73 add_item(new EditPopupCut(mwindow, this));
74 add_item(new EditPopupMute(mwindow, this));
75 add_item(new EditPopupCopyPack(mwindow, this));
76 add_item(new EditPopupCutPack(mwindow, this));
77 add_item(new EditPopupMutePack(mwindow, this));
78 add_item(new EditPopupPaste(mwindow, this));
79 add_item(new EditPopupOverwrite(mwindow, this));
80 add_item(new BC_MenuItem("-"));
81 add_item(new EditPopupOverwritePlugins(mwindow, this));
82 add_item(new EditCollectEffects(mwindow, this));
83 add_item(new EditPasteEffects(mwindow, this));
84 add_item(new EditPopupTimecode(mwindow, this));
87 int EditPopup::activate_menu(Track *track, Edit *edit,
88 PluginSet *pluginset, Plugin *plugin, double position)
92 this->pluginset = pluginset;
93 this->plugin = plugin;
94 this->position = position;
95 int enable = !edit ? 0 :
96 edit->nested_edl ? 1 :
98 edit->asset->format == FILE_REF ? 1 : 0;
99 open_edl->set_enabled(enable);
100 return BC_PopupMenu::activate_menu();
103 EditPopupOpenEDL::EditPopupOpenEDL(MWindow *mwindow, EditPopup *popup)
104 : BC_MenuItem(_("Open EDL"))
106 this->mwindow = mwindow;
112 int EditPopupOpenEDL::handle_event()
114 Edit *edit = popup->edit;
115 if( !edit ) return 1;
117 Indexable *idxbl = 0;
118 if( edit->asset && edit->asset->format == FILE_REF ) {
120 const char *filename = edit->asset->path;
121 if( xml_file.read_from_file(filename, 1) ) {
122 eprintf(_("Error: unable to open:\n %s"), filename);
126 edl->create_objects();
127 if( edl->load_xml(&xml_file, LOAD_ALL) ) {
128 eprintf(_("Error: unable to load:\n %s"), filename);
134 else if( edit->nested_edl ) {
135 edl = edit->nested_edl;
140 char edit_title[BCTEXTLEN];
141 edit->get_title(edit_title);
142 eprintf(_("Edit is not EDL: %s"), edit_title);
145 mwindow->stack_push(edl, idxbl);
149 EditPopupClearSelect::EditPopupClearSelect(MWindow *mwindow, EditPopup *popup)
150 : BC_MenuItem(_("Clear Select"),_("Ctrl-Shift-A"),'A')
152 this->mwindow = mwindow;
158 int EditPopupClearSelect::handle_event()
160 mwindow->clear_select();
164 EditPopupSelectEdits::EditPopupSelectEdits(MWindow *mwindow, EditPopup *popup)
165 : BC_MenuItem(_("Select Edits"),_("Ctrl-Alt-'"),'\'')
167 this->mwindow = mwindow;
173 int EditPopupSelectEdits::handle_event()
175 mwindow->select_edits(1);
179 EditPopupDeselectEdits::EditPopupDeselectEdits(MWindow *mwindow, EditPopup *popup)
180 : BC_MenuItem(_("Deselect Edits"))
182 this->mwindow = mwindow;
186 int EditPopupDeselectEdits::handle_event()
188 mwindow->select_edits(0);
192 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
193 : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
195 this->mwindow = mwindow;
200 int EditPopupCopy::handle_event()
202 mwindow->selected_edits_to_clipboard(0);
206 EditPopupCopyPack::EditPopupCopyPack(MWindow *mwindow, EditPopup *popup)
207 : BC_MenuItem(_("Copy pack"),_("Ctrl-Shift-C"),'C')
209 this->mwindow = mwindow;
215 int EditPopupCopyPack::handle_event()
217 mwindow->selected_edits_to_clipboard(1);
221 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
222 : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
224 this->mwindow = mwindow;
229 int EditPopupCut::handle_event()
231 mwindow->cut_selected_edits(1, 0);
235 EditPopupCutPack::EditPopupCutPack(MWindow *mwindow, EditPopup *popup)
236 : BC_MenuItem(_("Cut pack"),_("Ctrl-Alt-z"),'z')
238 this->mwindow = mwindow;
244 int EditPopupCutPack::handle_event()
246 mwindow->cut_selected_edits(1, 1);
250 EditPopupMute::EditPopupMute(MWindow *mwindow, EditPopup *popup)
251 : BC_MenuItem(C_("Mute"),_("Ctrl-m"),'m')
253 this->mwindow = mwindow;
258 int EditPopupMute::handle_event()
260 mwindow->cut_selected_edits(0, 0);
264 EditPopupMutePack::EditPopupMutePack(MWindow *mwindow, EditPopup *popup)
265 : BC_MenuItem(_("Mute pack"),_("Ctrl-Shift-M"),'M')
267 this->mwindow = mwindow;
273 int EditPopupMutePack::handle_event()
275 mwindow->cut_selected_edits(0, 1);
279 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
280 : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
282 this->mwindow = mwindow;
287 int EditPopupPaste::handle_event()
289 mwindow->paste(popup->position, popup->track, 0, 0);
290 mwindow->edl->tracks->clear_selected_edits();
291 popup->gui->draw_overlays(1);
292 if( mwindow->session->current_operation == DROP_TARGETING ) {
293 mwindow->session->current_operation = NO_OPERATION;
294 popup->gui->update_cursor();
299 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
300 : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
302 this->mwindow = mwindow;
307 int EditPopupOverwrite::handle_event()
309 mwindow->paste(popup->position, popup->track, 0, -1);
310 mwindow->edl->tracks->clear_selected_edits();
311 popup->gui->draw_overlays(1);
312 if( mwindow->session->current_operation == DROP_TARGETING ) {
313 mwindow->session->current_operation = NO_OPERATION;
314 popup->gui->update_cursor();
319 EditPopupOverwritePlugins::EditPopupOverwritePlugins(MWindow *mwindow, EditPopup *popup)
320 : BC_MenuItem(_("Overwrite Plugins"),_("Ctrl-Shift-P"),'P')
322 this->mwindow = mwindow;
328 int EditPopupOverwritePlugins::handle_event()
330 mwindow->paste_clipboard(popup->track, popup->position, 1, 0,
331 mwindow->edl->session->labels_follow_edits,
332 mwindow->edl->session->autos_follow_edits,
333 mwindow->edl->session->plugins_follow_edits);
334 mwindow->edl->tracks->clear_selected_edits();
335 if( mwindow->session->current_operation == DROP_TARGETING ) {
336 mwindow->session->current_operation = NO_OPERATION;
337 popup->gui->update_cursor();
343 EditCollectEffects::EditCollectEffects(MWindow *mwindow, EditPopup *popup)
344 : BC_MenuItem(_("Collect Effects"))
346 this->mwindow = mwindow;
351 int EditCollectEffects::handle_event()
353 if( mwindow->session->current_operation == NO_OPERATION )
354 mwindow->collect_effects();
358 EditPasteEffects::EditPasteEffects(MWindow *mwindow, EditPopup *popup)
359 : BC_MenuItem(_("Paste Effects"))
361 this->mwindow = mwindow;
367 int EditPasteEffects::handle_event()
369 if( mwindow->session->current_operation == NO_OPERATION )
370 mwindow->paste_effects();
374 EditPopupTimecode::EditPopupTimecode(MWindow *mwindow, EditPopup *popup)
375 : BC_MenuItem(_("Timecode"),_("Ctrl-!"),'!')
377 this->mwindow = mwindow;
383 int EditPopupTimecode::handle_event()
385 if( mwindow->session->current_operation != NO_OPERATION ) return 1;
386 Edit *edit = popup->edit;
387 if( !edit || !edit->asset ) return 1;
388 Asset *asset = edit->asset;
389 double timecode = asset->timecode != -2 ? asset->timecode :
390 FFMPEG::get_timecode(asset->path,
391 edit->track->data_type, edit->channel,
392 mwindow->edl->session->frame_rate);
393 asset->timecode = timecode;
394 if( timecode >= 0 ) {
395 int64_t pos = edit->startproject + edit->startsource;
396 double position = edit->track->from_units(pos);
397 mwindow->set_timecode_offset(timecode - position);
400 mwindow->set_timecode_offset(0);