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();
132 EDL *clip = !mwindow->session->drag_clips->size() ? 0 :
133 mwindow->session->drag_clips->get(0);
134 int enable_open = clip ? 1 : 0;
135 open_edl->set_enabled(enable_open);
136 int enable_close = mwindow->stack.size() > 0 ? 1 : 0;
137 close_edl->set_enabled(enable_close);
142 ClipPopupInfo::ClipPopupInfo(MWindow *mwindow, ClipPopup *popup)
143 : BC_MenuItem(_("Info..."))
145 this->mwindow = mwindow;
149 ClipPopupInfo::~ClipPopupInfo()
153 int ClipPopupInfo::handle_event()
156 popup->gui->get_abs_cursor(cur_x, cur_y, 0);
158 if( mwindow->session->drag_assets->total ) {
159 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
160 asset_edit->edit_asset(
161 mwindow->session->drag_assets->values[0], cur_x, cur_y);
164 if( mwindow->session->drag_clips->total ) {
165 popup->gui->awindow->clip_edit->edit_clip(
166 mwindow->session->drag_clips->values[0], cur_x, cur_y);
172 ClipPopupSort::ClipPopupSort(MWindow *mwindow, ClipPopup *popup)
173 : BC_MenuItem(_("Sort items"))
175 this->mwindow = mwindow;
179 ClipPopupSort::~ClipPopupSort()
183 int ClipPopupSort::handle_event()
185 mwindow->awindow->gui->sort_assets();
190 ClipPopupView::ClipPopupView(MWindow *mwindow, ClipPopup *popup)
191 : BC_MenuItem(_("View"))
193 this->mwindow = mwindow;
197 ClipPopupView::~ClipPopupView()
201 int ClipPopupView::handle_event()
203 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
205 if( mwindow->session->drag_assets->total )
206 vwindow->change_source(
207 mwindow->session->drag_assets->values[0]);
209 if( mwindow->session->drag_clips->total )
210 vwindow->change_source(
211 mwindow->session->drag_clips->values[0]);
217 ClipPopupViewWindow::ClipPopupViewWindow(MWindow *mwindow, ClipPopup *popup)
218 : BC_MenuItem(_("View in new window"))
220 this->mwindow = mwindow;
224 ClipPopupViewWindow::~ClipPopupViewWindow()
228 int ClipPopupViewWindow::handle_event()
230 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
231 VWindow *vwindow = mwindow->get_viewer(1);
232 vwindow->gui->lock_window("ClipPopupView::handle_event 1");
233 vwindow->change_source(mwindow->session->drag_assets->get(i));
234 vwindow->gui->unlock_window();
236 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
237 VWindow *vwindow = mwindow->get_viewer(1);
238 vwindow->gui->lock_window("ClipPopupView::handle_event 2");
239 vwindow->change_source(mwindow->session->drag_clips->get(i));
240 vwindow->gui->unlock_window();
246 ClipPopupCopy::ClipPopupCopy(MWindow *mwindow, ClipPopup *popup)
247 : BC_MenuItem(_("Copy"))
249 this->mwindow = mwindow;
252 ClipPopupCopy::~ClipPopupCopy()
256 int ClipPopupCopy::handle_event()
258 MWindowGUI *gui = mwindow->gui;
259 gui->lock_window("ClipPopupCopy::handle_event");
260 if( mwindow->session->drag_clips->total > 0 ) {
261 EDL *edl = mwindow->session->drag_clips->values[0];
262 EDL *copy_edl = new EDL; // no parent or assets wont be copied
263 copy_edl->create_objects();
264 copy_edl->copy_all(edl);
266 double start = 0, end = edl->tracks->total_length();
267 copy_edl->copy(COPY_EDL, start, end, &file, "", 1);
268 copy_edl->remove_user();
269 const char *file_string = file.string();
270 long file_length = strlen(file_string);
271 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
272 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
274 gui->unlock_window();
279 ClipPopupPaste::ClipPopupPaste(MWindow *mwindow, ClipPopup *popup)
280 : BC_MenuItem(_("Paste"))
282 this->mwindow = mwindow;
286 ClipPopupPaste::~ClipPopupPaste()
290 int ClipPopupPaste::handle_event()
292 popup->paste_assets();
297 ClipMatchSize::ClipMatchSize(MWindow *mwindow, ClipPopup *popup)
298 : BC_MenuItem(_("Match project size"))
300 this->mwindow = mwindow;
304 int ClipMatchSize::handle_event()
311 ClipMatchRate::ClipMatchRate(MWindow *mwindow, ClipPopup *popup)
312 : BC_MenuItem(_("Match frame rate"))
314 this->mwindow = mwindow;
318 int ClipMatchRate::handle_event()
325 ClipMatchAll::ClipMatchAll(MWindow *mwindow, ClipPopup *popup)
326 : BC_MenuItem(_("Match all"))
328 this->mwindow = mwindow;
332 int ClipMatchAll::handle_event()
339 ClipPopupDelete::ClipPopupDelete(MWindow *mwindow, ClipPopup *popup)
340 : BC_MenuItem(_("Delete"))
342 this->mwindow = mwindow;
347 ClipPopupDelete::~ClipPopupDelete()
351 int ClipPopupDelete::handle_event()
353 popup->gui->unlock_window();
354 mwindow->remove_assets_from_project(1, 1, 0, 0,
355 mwindow->session->drag_clips);
356 popup->gui->lock_window("ClipPopupDelete::handle_event");
361 ClipPasteToFolder::ClipPasteToFolder(MWindow *mwindow)
362 : BC_MenuItem(_("Paste Clip"))
364 this->mwindow = mwindow;
367 int ClipPasteToFolder::handle_event()
369 MWindowGUI *gui = mwindow->gui;
370 gui->lock_window("ClipPasteToFolder::handle_event 1");
371 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
373 char *string = new char[len];
374 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
375 const char *clip_header = "<EDL VERSION=";
376 if( !strncmp(clip_header, string, strlen(clip_header)) ) {
378 file.read_from_string(string);
379 EDL *edl = mwindow->edl;
380 EDL *new_edl = new EDL(mwindow->edl);
381 new_edl->create_objects();
382 new_edl->load_xml(&file, LOAD_ALL);
383 edl->update_assets(new_edl);
384 mwindow->save_clip(new_edl, _("paste clip: "));
387 char *cp = strchr(string, '\n');
388 if( cp && cp-string < 32 ) *cp = 0;
389 else if( len > 32 ) string[32] = 0;
390 eprintf("paste buffer is not EDL:\n%s", string);
395 eprintf("paste buffer empty");
397 gui->unlock_window();
402 ClipListMenu::ClipListMenu(MWindow *mwindow, AWindowGUI *gui)
403 : BC_PopupMenu(0, 0, 0, "", 0)
405 this->mwindow = mwindow;
409 ClipListMenu::~ClipListMenu()
413 void ClipListMenu::create_objects()
415 add_item(format = new AWindowListFormat(mwindow, gui));
416 add_item(close_edl = new ClipPopupCloseEDL(mwindow, gui));
417 add_item(new AWindowListSort(mwindow, gui));
418 add_item(new ClipPasteToFolder(mwindow));
422 void ClipListMenu::update()
425 int enable_close = mwindow->stack.size() > 0 ? 1 : 0;
426 close_edl->set_enabled(enable_close);
430 ClipPopupToMedia::ClipPopupToMedia(MWindow *mwindow, ClipPopup *popup)
431 : BC_MenuItem(_("Nest to Media"))
433 this->mwindow = mwindow;
436 ClipPopupToMedia::~ClipPopupToMedia()
440 int ClipPopupToMedia::handle_event()
442 if( mwindow->edl->session->proxy_scale == 1 )
443 mwindow->clip_to_media();
445 eprintf("Nesting not allowed when proxy scale != 1");
450 ClipPopupOpenEDL::ClipPopupOpenEDL(MWindow *mwindow, ClipPopup *popup)
451 : BC_MenuItem(_("Open EDL"))
453 this->mwindow = mwindow;
457 ClipPopupOpenEDL::~ClipPopupOpenEDL()
461 int ClipPopupOpenEDL::handle_event()
463 int clips_total = mwindow->session->drag_clips->total;
465 popup->unlock_window();
466 EDL *clip = mwindow->session->drag_clips->values[0];
467 mwindow->stack_push(clip, 0);
468 popup->lock_window("ClipPopupOpenEDL::handle_event");
473 ClipPopupCloseEDL::ClipPopupCloseEDL(MWindow *mwindow, AWindowGUI *gui)
474 : BC_MenuItem(_("Close EDL"))
476 this->mwindow = mwindow;
479 ClipPopupCloseEDL::~ClipPopupCloseEDL()
483 int ClipPopupCloseEDL::handle_event()
485 gui->unlock_window();
486 mwindow->gui->lock_window("ClipPopupCloseEDL::handle_event");
487 mwindow->stack_pop();
488 mwindow->gui->unlock_window();
489 gui->lock_window("ClipPopupCloseEDL::handle_event");