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 EditPopupCopy(mwindow, this));
72 add_item(new EditPopupCut(mwindow, this));
73 add_item(new EditPopupMute(mwindow, this));
74 add_item(new EditPopupCopyPack(mwindow, this));
75 add_item(new EditPopupCutPack(mwindow, this));
76 add_item(new EditPopupMutePack(mwindow, this));
77 add_item(new EditPopupPaste(mwindow, this));
78 add_item(new EditPopupOverwrite(mwindow, this));
79 add_item(new BC_MenuItem("-"));
80 add_item(new EditPopupOverwritePlugins(mwindow, this));
81 add_item(new EditCollectEffects(mwindow, this));
82 add_item(new EditPasteEffects(mwindow, this));
83 add_item(new EditPopupTimecode(mwindow, this));
86 int EditPopup::activate_menu(Track *track, Edit *edit,
87 PluginSet *pluginset, Plugin *plugin, double position)
91 this->pluginset = pluginset;
92 this->plugin = plugin;
93 this->position = position;
94 int enable = !edit ? 0 :
95 edit->nested_edl ? 1 :
97 edit->asset->format == FILE_REF ? 1 : 0;
98 open_edl->set_enabled(enable);
99 return BC_PopupMenu::activate_menu();
102 EditPopupOpenEDL::EditPopupOpenEDL(MWindow *mwindow, EditPopup *popup)
103 : BC_MenuItem(_("Open EDL"))
105 this->mwindow = mwindow;
111 int EditPopupOpenEDL::handle_event()
113 Edit *edit = popup->edit;
114 if( !edit ) return 1;
116 Indexable *idxbl = 0;
117 if( edit->asset && edit->asset->format == FILE_REF ) {
119 const char *filename = edit->asset->path;
120 if( xml_file.read_from_file(filename, 1) ) {
121 eprintf(_("Error: unable to open:\n %s"), filename);
125 edl->create_objects();
126 if( edl->load_xml(&xml_file, LOAD_ALL) ) {
127 eprintf(_("Error: unable to load:\n %s"), filename);
133 else if( edit->nested_edl ) {
134 edl = edit->nested_edl;
139 char edit_title[BCTEXTLEN];
140 edit->get_title(edit_title);
141 eprintf(_("Edit is not EDL: %s"), edit_title);
144 mwindow->stack_push(edl, idxbl);
148 EditPopupClearSelect::EditPopupClearSelect(MWindow *mwindow, EditPopup *popup)
149 : BC_MenuItem(_("Clear Select"),_("Ctrl-Shift-A"),'A')
151 this->mwindow = mwindow;
157 int EditPopupClearSelect::handle_event()
159 mwindow->clear_select();
163 EditPopupSelectEdits::EditPopupSelectEdits(MWindow *mwindow, EditPopup *popup)
164 : BC_MenuItem(_("Select Edits"),_("Ctrl-Alt-a"),'a')
166 this->mwindow = mwindow;
172 int EditPopupSelectEdits::handle_event()
174 mwindow->select_edits();
178 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
179 : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
181 this->mwindow = mwindow;
186 int EditPopupCopy::handle_event()
188 mwindow->selected_edits_to_clipboard(0);
192 EditPopupCopyPack::EditPopupCopyPack(MWindow *mwindow, EditPopup *popup)
193 : BC_MenuItem(_("Copy pack"),_("Ctrl-Shift-C"),'C')
195 this->mwindow = mwindow;
201 int EditPopupCopyPack::handle_event()
203 mwindow->selected_edits_to_clipboard(1);
207 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
208 : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
210 this->mwindow = mwindow;
215 int EditPopupCut::handle_event()
217 mwindow->cut_selected_edits(1, 0);
221 EditPopupCutPack::EditPopupCutPack(MWindow *mwindow, EditPopup *popup)
222 : BC_MenuItem(_("Cut pack"),_("Ctrl-Alt-z"),'z')
224 this->mwindow = mwindow;
230 int EditPopupCutPack::handle_event()
232 mwindow->cut_selected_edits(1, 1);
236 EditPopupMute::EditPopupMute(MWindow *mwindow, EditPopup *popup)
237 : BC_MenuItem(C_("Mute"),_("Ctrl-m"),'m')
239 this->mwindow = mwindow;
244 int EditPopupMute::handle_event()
246 mwindow->cut_selected_edits(0, 0);
250 EditPopupMutePack::EditPopupMutePack(MWindow *mwindow, EditPopup *popup)
251 : BC_MenuItem(_("Mute pack"),_("Ctrl-Shift-M"),'M')
253 this->mwindow = mwindow;
259 int EditPopupMutePack::handle_event()
261 mwindow->cut_selected_edits(0, 1);
265 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
266 : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
268 this->mwindow = mwindow;
273 int EditPopupPaste::handle_event()
275 mwindow->paste(popup->position, popup->track, 0, 0);
276 mwindow->edl->tracks->clear_selected_edits();
277 popup->gui->draw_overlays(1);
278 if( mwindow->session->current_operation == DROP_TARGETING ) {
279 mwindow->session->current_operation = NO_OPERATION;
280 popup->gui->update_cursor();
285 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
286 : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
288 this->mwindow = mwindow;
293 int EditPopupOverwrite::handle_event()
295 mwindow->paste(popup->position, popup->track, 0, -1);
296 mwindow->edl->tracks->clear_selected_edits();
297 popup->gui->draw_overlays(1);
298 if( mwindow->session->current_operation == DROP_TARGETING ) {
299 mwindow->session->current_operation = NO_OPERATION;
300 popup->gui->update_cursor();
305 EditPopupOverwritePlugins::EditPopupOverwritePlugins(MWindow *mwindow, EditPopup *popup)
306 : BC_MenuItem(_("Overwrite Plugins"),_("Ctrl-Shift-P"),'P')
308 this->mwindow = mwindow;
314 int EditPopupOverwritePlugins::handle_event()
316 mwindow->paste_clipboard(popup->track, popup->position, 1, 0,
317 mwindow->edl->session->labels_follow_edits,
318 mwindow->edl->session->autos_follow_edits,
319 mwindow->edl->session->plugins_follow_edits);
320 mwindow->edl->tracks->clear_selected_edits();
321 if( mwindow->session->current_operation == DROP_TARGETING ) {
322 mwindow->session->current_operation = NO_OPERATION;
323 popup->gui->update_cursor();
329 EditCollectEffects::EditCollectEffects(MWindow *mwindow, EditPopup *popup)
330 : BC_MenuItem(_("Collect Effects"))
332 this->mwindow = mwindow;
337 int EditCollectEffects::handle_event()
339 if( mwindow->session->current_operation == NO_OPERATION )
340 mwindow->collect_effects();
344 EditPasteEffects::EditPasteEffects(MWindow *mwindow, EditPopup *popup)
345 : BC_MenuItem(_("Paste Effects"))
347 this->mwindow = mwindow;
353 int EditPasteEffects::handle_event()
355 if( mwindow->session->current_operation == NO_OPERATION )
356 mwindow->paste_effects();
360 EditPopupTimecode::EditPopupTimecode(MWindow *mwindow, EditPopup *popup)
361 : BC_MenuItem(_("Timecode"),_("Ctrl-!"),'!')
363 this->mwindow = mwindow;
368 int EditPopupTimecode::handle_event()
370 if( mwindow->session->current_operation != NO_OPERATION ) return 1;
371 Edit *edit = popup->edit;
372 if( !edit || !edit->asset ) return 1;
373 Asset *asset = edit->asset;
374 double timecode = asset->timecode != -2 ? asset->timecode :
375 FFMPEG::get_timecode(asset->path,
376 edit->track->data_type, edit->channel,
377 mwindow->edl->session->frame_rate);
378 asset->timecode = timecode;
379 if( timecode >= 0 ) {
380 int64_t pos = edit->startproject + edit->startsource;
381 double position = edit->track->from_units(pos);
382 mwindow->set_timecode_offset(timecode - position);
385 mwindow->set_timecode_offset(0);