4 * Copyright (C) 1997-2012 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
22 #include "assetedit.h"
23 #include "clippopup.h"
24 #include "assetremove.h"
26 #include "awindowgui.h"
27 #include "bcsignals.h"
31 #include "cwindowgui.h"
35 #include "edlsession.h"
38 #include "localsession.h"
39 #include "mainerror.h"
40 #include "mainindexes.h"
41 #include "mainsession.h"
43 #include "mwindowgui.h"
47 #include "vwindowgui.h"
51 ClipPopup::ClipPopup(MWindow *mwindow, AWindowGUI *gui)
52 : BC_PopupMenu(0, 0, 0, "", 0)
54 this->mwindow = mwindow;
58 ClipPopup::~ClipPopup()
62 void ClipPopup::create_objects()
64 BC_MenuItem *menu_item;
66 add_item(info = new ClipPopupInfo(mwindow, this));
67 add_item(format = new AWindowListFormat(mwindow, gui));
68 add_item(sort = new ClipPopupSort(mwindow, this));
69 add_item(open_edl = new ClipPopupOpenEDL(mwindow, this));
70 add_item(close_edl = new ClipPopupCloseEDL(mwindow, gui));
71 add_item(to_media = new ClipPopupToMedia(mwindow, this));
72 add_item(view = new ClipPopupView(mwindow, this));
73 add_item(view_window = new ClipPopupViewWindow(mwindow, this));
74 add_item(copy = new ClipPopupCopy(mwindow, this));
75 add_item(paste = new ClipPopupPaste(mwindow, this));
76 add_item(menu_item = new BC_MenuItem(_("Match...")));
77 menu_item->add_submenu(submenu = new BC_SubMenu());
78 submenu->add_submenuitem(new ClipMatchSize(mwindow, this));
79 submenu->add_submenuitem(new ClipMatchRate(mwindow, this));
80 submenu->add_submenuitem(new ClipMatchAll(mwindow, this));
81 add_item(new ClipPopupDelete(mwindow, this));
84 void ClipPopup::paste_assets()
86 // Collect items into the drag vectors for temporary storage
87 gui->lock_window("ClipPopup::paste_assets");
88 mwindow->gui->lock_window("ClipPopup::paste_assets");
89 mwindow->cwindow->gui->lock_window("ClipPopup::paste_assets");
91 gui->collect_assets();
92 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
93 mwindow->edl->tracks->first,
94 0); // do not overwrite
97 mwindow->gui->unlock_window();
98 mwindow->cwindow->gui->unlock_window();
101 void ClipPopup::match_size()
103 // Collect items into the drag vectors for temporary storage
104 gui->collect_assets();
105 mwindow->gui->lock_window("ClipPopup::match_size");
106 mwindow->asset_to_size();
107 mwindow->gui->unlock_window();
110 void ClipPopup::match_rate()
112 // Collect items into the drag vectors for temporary storage
113 gui->collect_assets();
114 mwindow->gui->lock_window("ClipPopup::match_rate");
115 mwindow->asset_to_rate();
116 mwindow->gui->unlock_window();
119 void ClipPopup::match_all()
121 // Collect items into the drag vectors for temporary storage
122 gui->collect_assets();
123 mwindow->gui->lock_window("ClipPopup::match_rate");
124 mwindow->asset_to_all();
125 mwindow->gui->unlock_window();
128 int ClipPopup::update()
131 gui->collect_assets();
136 ClipPopupInfo::ClipPopupInfo(MWindow *mwindow, ClipPopup *popup)
137 : BC_MenuItem(_("Info..."))
139 this->mwindow = mwindow;
143 ClipPopupInfo::~ClipPopupInfo()
147 int ClipPopupInfo::handle_event()
150 popup->gui->get_abs_cursor(cur_x, cur_y, 0);
152 if( mwindow->session->drag_assets->total ) {
153 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
154 asset_edit->edit_asset(
155 mwindow->session->drag_assets->values[0], cur_x, cur_y);
158 if( mwindow->session->drag_clips->total ) {
159 popup->gui->awindow->clip_edit->edit_clip(
160 mwindow->session->drag_clips->values[0], cur_x, cur_y);
166 ClipPopupSort::ClipPopupSort(MWindow *mwindow, ClipPopup *popup)
167 : BC_MenuItem(_("Sort items"))
169 this->mwindow = mwindow;
173 ClipPopupSort::~ClipPopupSort()
177 int ClipPopupSort::handle_event()
179 mwindow->awindow->gui->sort_assets();
184 ClipPopupView::ClipPopupView(MWindow *mwindow, ClipPopup *popup)
185 : BC_MenuItem(_("View"))
187 this->mwindow = mwindow;
191 ClipPopupView::~ClipPopupView()
195 int ClipPopupView::handle_event()
197 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
199 if( mwindow->session->drag_assets->total )
200 vwindow->change_source(
201 mwindow->session->drag_assets->values[0]);
203 if( mwindow->session->drag_clips->total )
204 vwindow->change_source(
205 mwindow->session->drag_clips->values[0]);
211 ClipPopupViewWindow::ClipPopupViewWindow(MWindow *mwindow, ClipPopup *popup)
212 : BC_MenuItem(_("View in new window"))
214 this->mwindow = mwindow;
218 ClipPopupViewWindow::~ClipPopupViewWindow()
222 int ClipPopupViewWindow::handle_event()
224 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
225 VWindow *vwindow = mwindow->get_viewer(1);
226 vwindow->gui->lock_window("ClipPopupView::handle_event 1");
227 vwindow->change_source(mwindow->session->drag_assets->get(i));
228 vwindow->gui->unlock_window();
230 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
231 VWindow *vwindow = mwindow->get_viewer(1);
232 vwindow->gui->lock_window("ClipPopupView::handle_event 2");
233 vwindow->change_source(mwindow->session->drag_clips->get(i));
234 vwindow->gui->unlock_window();
240 ClipPopupCopy::ClipPopupCopy(MWindow *mwindow, ClipPopup *popup)
241 : BC_MenuItem(_("Copy"))
243 this->mwindow = mwindow;
246 ClipPopupCopy::~ClipPopupCopy()
250 int ClipPopupCopy::handle_event()
252 MWindowGUI *gui = mwindow->gui;
253 gui->lock_window("ClipPopupCopy::handle_event");
254 if( mwindow->session->drag_clips->total > 0 ) {
255 EDL *edl = mwindow->session->drag_clips->values[0];
256 EDL *copy_edl = new EDL; // no parent or assets wont be copied
257 copy_edl->create_objects();
258 copy_edl->copy_all(edl);
260 double start = 0, end = edl->tracks->total_length();
261 copy_edl->copy(COPY_EDL, start, end, &file, "", 1);
262 copy_edl->remove_user();
263 const char *file_string = file.string();
264 long file_length = strlen(file_string);
265 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
266 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
268 gui->unlock_window();
273 ClipPopupPaste::ClipPopupPaste(MWindow *mwindow, ClipPopup *popup)
274 : BC_MenuItem(_("Paste"))
276 this->mwindow = mwindow;
280 ClipPopupPaste::~ClipPopupPaste()
284 int ClipPopupPaste::handle_event()
286 popup->paste_assets();
291 ClipMatchSize::ClipMatchSize(MWindow *mwindow, ClipPopup *popup)
292 : BC_MenuItem(_("Match project size"))
294 this->mwindow = mwindow;
298 int ClipMatchSize::handle_event()
305 ClipMatchRate::ClipMatchRate(MWindow *mwindow, ClipPopup *popup)
306 : BC_MenuItem(_("Match frame rate"))
308 this->mwindow = mwindow;
312 int ClipMatchRate::handle_event()
319 ClipMatchAll::ClipMatchAll(MWindow *mwindow, ClipPopup *popup)
320 : BC_MenuItem(_("Match all"))
322 this->mwindow = mwindow;
326 int ClipMatchAll::handle_event()
333 ClipPopupDelete::ClipPopupDelete(MWindow *mwindow, ClipPopup *popup)
334 : BC_MenuItem(_("Delete"))
336 this->mwindow = mwindow;
341 ClipPopupDelete::~ClipPopupDelete()
345 int ClipPopupDelete::handle_event()
347 popup->gui->unlock_window();
348 mwindow->remove_assets_from_project(1, 1, 0, 0,
349 mwindow->session->drag_clips);
350 popup->gui->lock_window("ClipPopupDelete::handle_event");
355 ClipPasteToFolder::ClipPasteToFolder(MWindow *mwindow)
356 : BC_MenuItem(_("Paste Clip"))
358 this->mwindow = mwindow;
361 int ClipPasteToFolder::handle_event()
363 MWindowGUI *gui = mwindow->gui;
364 gui->lock_window("ClipPasteToFolder::handle_event 1");
365 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
367 char *string = new char[len];
368 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
369 const char *clip_header = "<EDL VERSION=";
370 if( !strncmp(clip_header, string, strlen(clip_header)) ) {
372 file.read_from_string(string);
373 EDL *edl = mwindow->edl;
374 EDL *new_edl = new EDL(mwindow->edl);
375 new_edl->create_objects();
376 new_edl->load_xml(&file, LOAD_ALL);
377 edl->update_assets(new_edl);
378 mwindow->save_clip(new_edl, _("paste clip: "));
381 char *cp = strchr(string, '\n');
382 if( cp && cp-string < 32 ) *cp = 0;
383 else if( len > 32 ) string[32] = 0;
384 eprintf("paste buffer is not EDL:\n%s", string);
389 eprintf("paste buffer empty");
391 gui->unlock_window();
396 ClipListMenu::ClipListMenu(MWindow *mwindow, AWindowGUI *gui)
397 : BC_PopupMenu(0, 0, 0, "", 0)
399 this->mwindow = mwindow;
403 ClipListMenu::~ClipListMenu()
407 void ClipListMenu::create_objects()
409 add_item(format = new AWindowListFormat(mwindow, gui));
410 add_item(close_edl = new ClipPopupCloseEDL(mwindow, gui));
411 add_item(new AWindowListSort(mwindow, gui));
412 add_item(new ClipPasteToFolder(mwindow));
416 void ClipListMenu::update()
422 ClipPopupToMedia::ClipPopupToMedia(MWindow *mwindow, ClipPopup *popup)
423 : BC_MenuItem(_("Nest to Media"))
425 this->mwindow = mwindow;
428 ClipPopupToMedia::~ClipPopupToMedia()
432 int ClipPopupToMedia::handle_event()
434 if( mwindow->edl->session->proxy_scale == 1 )
435 mwindow->clip_to_media();
437 eprintf("Nesting not allowed when proxy scale != 1");
442 ClipPopupOpenEDL::ClipPopupOpenEDL(MWindow *mwindow, ClipPopup *popup)
443 : BC_MenuItem(_("Open EDL"))
445 this->mwindow = mwindow;
449 ClipPopupOpenEDL::~ClipPopupOpenEDL()
453 int ClipPopupOpenEDL::handle_event()
455 int clips_total = mwindow->session->drag_clips->total;
457 popup->unlock_window();
458 EDL *clip = mwindow->session->drag_clips->values[0];
459 mwindow->stack_push(clip);
460 popup->lock_window("ClipPopupOpenEDL::handle_event");
465 ClipPopupCloseEDL::ClipPopupCloseEDL(MWindow *mwindow, AWindowGUI *gui)
466 : BC_MenuItem(_("Close EDL"))
468 this->mwindow = mwindow;
471 ClipPopupCloseEDL::~ClipPopupCloseEDL()
475 int ClipPopupCloseEDL::handle_event()
477 gui->unlock_window();
478 mwindow->gui->lock_window("ClipPopupCloseEDL::handle_event");
479 mwindow->stack_pop();
480 mwindow->gui->unlock_window();
481 gui->lock_window("ClipPopupCloseEDL::handle_event");