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"
37 #include "localsession.h"
38 #include "mainerror.h"
39 #include "mainindexes.h"
40 #include "mainsession.h"
42 #include "mwindowgui.h"
46 #include "vwindowgui.h"
50 ClipPopup::ClipPopup(MWindow *mwindow, AWindowGUI *gui)
51 : BC_PopupMenu(0, 0, 0, "", 0)
53 this->mwindow = mwindow;
57 ClipPopup::~ClipPopup()
61 void ClipPopup::create_objects()
63 BC_MenuItem *menu_item;
65 add_item(info = new ClipPopupInfo(mwindow, this));
66 add_item(format = new AWindowListFormat(mwindow, gui));
67 add_item(new ClipPopupSort(mwindow, this));
68 add_item(view = new ClipPopupView(mwindow, this));
69 add_item(view_window = new ClipPopupViewWindow(mwindow, this));
70 add_item(new ClipPopupCopy(mwindow, this));
71 add_item(new ClipPopupNest(mwindow, this));
72 add_item(new ClipPopupUnNest(mwindow, this));
73 add_item(new ClipPopupPaste(mwindow, this));
74 add_item(menu_item = new BC_MenuItem(_("Match...")));
75 menu_item->add_submenu(submenu = new BC_SubMenu());
76 submenu->add_submenuitem(new ClipMatchSize(mwindow, this));
77 submenu->add_submenuitem(new ClipMatchRate(mwindow, this));
78 submenu->add_submenuitem(new ClipMatchAll(mwindow, this));
79 add_item(new ClipPopupDelete(mwindow, this));
82 void ClipPopup::paste_assets()
84 // Collect items into the drag vectors for temporary storage
85 gui->lock_window("ClipPopup::paste_assets");
86 mwindow->gui->lock_window("ClipPopup::paste_assets");
87 mwindow->cwindow->gui->lock_window("ClipPopup::paste_assets");
89 gui->collect_assets();
90 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
91 mwindow->edl->tracks->first,
92 0); // do not overwrite
95 mwindow->gui->unlock_window();
96 mwindow->cwindow->gui->unlock_window();
99 void ClipPopup::match_size()
101 // Collect items into the drag vectors for temporary storage
102 gui->collect_assets();
103 mwindow->gui->lock_window("ClipPopup::match_size");
104 mwindow->asset_to_size();
105 mwindow->gui->unlock_window();
108 void ClipPopup::match_rate()
110 // Collect items into the drag vectors for temporary storage
111 gui->collect_assets();
112 mwindow->gui->lock_window("ClipPopup::match_rate");
113 mwindow->asset_to_rate();
114 mwindow->gui->unlock_window();
117 void ClipPopup::match_all()
119 // Collect items into the drag vectors for temporary storage
120 gui->collect_assets();
121 mwindow->gui->lock_window("ClipPopup::match_rate");
122 mwindow->asset_to_all();
123 mwindow->gui->unlock_window();
126 int ClipPopup::update()
129 gui->collect_assets();
134 ClipPopupInfo::ClipPopupInfo(MWindow *mwindow, ClipPopup *popup)
135 : BC_MenuItem(_("Info..."))
137 this->mwindow = mwindow;
141 ClipPopupInfo::~ClipPopupInfo()
145 int ClipPopupInfo::handle_event()
148 popup->gui->get_abs_cursor(cur_x, cur_y, 0);
150 if( mwindow->session->drag_assets->total ) {
151 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
152 asset_edit->edit_asset(
153 mwindow->session->drag_assets->values[0], cur_x, cur_y);
156 if( mwindow->session->drag_clips->total ) {
157 popup->gui->awindow->clip_edit->edit_clip(
158 mwindow->session->drag_clips->values[0], cur_x, cur_y);
164 ClipPopupSort::ClipPopupSort(MWindow *mwindow, ClipPopup *popup)
165 : BC_MenuItem(_("Sort items"))
167 this->mwindow = mwindow;
171 ClipPopupSort::~ClipPopupSort()
175 int ClipPopupSort::handle_event()
177 mwindow->awindow->gui->sort_assets(0);
182 ClipPopupView::ClipPopupView(MWindow *mwindow, ClipPopup *popup)
183 : BC_MenuItem(_("View"))
185 this->mwindow = mwindow;
189 ClipPopupView::~ClipPopupView()
193 int ClipPopupView::handle_event()
195 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
197 if( mwindow->session->drag_assets->total )
198 vwindow->change_source(
199 mwindow->session->drag_assets->values[0]);
201 if( mwindow->session->drag_clips->total )
202 vwindow->change_source(
203 mwindow->session->drag_clips->values[0]);
209 ClipPopupViewWindow::ClipPopupViewWindow(MWindow *mwindow, ClipPopup *popup)
210 : BC_MenuItem(_("View in new window"))
212 this->mwindow = mwindow;
216 ClipPopupViewWindow::~ClipPopupViewWindow()
220 int ClipPopupViewWindow::handle_event()
222 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
223 VWindow *vwindow = mwindow->get_viewer(1);
224 vwindow->gui->lock_window("ClipPopupView::handle_event 1");
225 vwindow->change_source(mwindow->session->drag_assets->get(i));
226 vwindow->gui->unlock_window();
228 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
229 VWindow *vwindow = mwindow->get_viewer(1);
230 vwindow->gui->lock_window("ClipPopupView::handle_event 2");
231 vwindow->change_source(mwindow->session->drag_clips->get(i));
232 vwindow->gui->unlock_window();
238 ClipPopupCopy::ClipPopupCopy(MWindow *mwindow, ClipPopup *popup)
239 : BC_MenuItem(_("Copy"))
241 this->mwindow = mwindow;
244 ClipPopupCopy::~ClipPopupCopy()
248 int ClipPopupCopy::handle_event()
250 MWindowGUI *gui = mwindow->gui;
251 gui->lock_window("ClipPopupCopy::handle_event");
252 if( mwindow->session->drag_clips->total > 0 ) {
253 EDL *edl = mwindow->session->drag_clips->values[0];
254 EDL *copy_edl = new EDL; // no parent or assets wont be copied
255 copy_edl->create_objects();
256 copy_edl->copy_all(edl);
258 double start = 0, end = edl->tracks->total_length();
259 copy_edl->copy(start, end, 1, &file, "", 1);
260 copy_edl->remove_user();
261 const char *file_string = file.string();
262 long file_length = strlen(file_string);
263 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
264 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
266 gui->unlock_window();
271 ClipPopupPaste::ClipPopupPaste(MWindow *mwindow, ClipPopup *popup)
272 : BC_MenuItem(_("Paste"))
274 this->mwindow = mwindow;
278 ClipPopupPaste::~ClipPopupPaste()
282 int ClipPopupPaste::handle_event()
284 popup->paste_assets();
289 ClipMatchSize::ClipMatchSize(MWindow *mwindow, ClipPopup *popup)
290 : BC_MenuItem(_("Match project size"))
292 this->mwindow = mwindow;
296 int ClipMatchSize::handle_event()
303 ClipMatchRate::ClipMatchRate(MWindow *mwindow, ClipPopup *popup)
304 : BC_MenuItem(_("Match frame rate"))
306 this->mwindow = mwindow;
310 int ClipMatchRate::handle_event()
317 ClipMatchAll::ClipMatchAll(MWindow *mwindow, ClipPopup *popup)
318 : BC_MenuItem(_("Match all"))
320 this->mwindow = mwindow;
324 int ClipMatchAll::handle_event()
331 ClipPopupDelete::ClipPopupDelete(MWindow *mwindow, ClipPopup *popup)
332 : BC_MenuItem(_("Delete"))
334 this->mwindow = mwindow;
339 ClipPopupDelete::~ClipPopupDelete()
343 int ClipPopupDelete::handle_event()
345 mwindow->remove_assets_from_project(1, 1,
346 mwindow->session->drag_assets,
347 mwindow->session->drag_clips);
352 ClipPasteToFolder::ClipPasteToFolder(MWindow *mwindow)
353 : BC_MenuItem(_("Paste Clip"))
355 this->mwindow = mwindow;
358 int ClipPasteToFolder::handle_event()
360 MWindowGUI *gui = mwindow->gui;
361 gui->lock_window("ClipPasteToFolder::handle_event 1");
362 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
364 char *string = new char[len];
365 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
366 const char *clip_header = "<EDL VERSION=";
367 if( !strncmp(clip_header, string, strlen(clip_header)) ) {
369 file.read_from_string(string);
370 EDL *edl = mwindow->edl;
371 EDL *new_edl = new EDL(mwindow->edl);
372 new_edl->create_objects();
373 new_edl->load_xml(&file, LOAD_ALL);
374 edl->update_assets(new_edl);
375 mwindow->save_clip(new_edl, _("paste clip: "));
378 char *cp = strchr(string, '\n');
379 if( cp-string < 32 ) *cp = 0;
380 else if( len > 32 ) string[32] = 0;
381 eprintf("paste buffer is not EDL:\n%s", string);
386 eprintf("paste buffer empty");
388 gui->unlock_window();
393 ClipListMenu::ClipListMenu(MWindow *mwindow, AWindowGUI *gui)
394 : BC_PopupMenu(0, 0, 0, "", 0)
396 this->mwindow = mwindow;
400 ClipListMenu::~ClipListMenu()
404 void ClipListMenu::create_objects()
406 add_item(format = new AWindowListFormat(mwindow, gui));
407 add_item(new AWindowListSort(mwindow, gui));
408 add_item(new ClipPasteToFolder(mwindow));
412 void ClipListMenu::update()
418 ClipPopupNest::ClipPopupNest(MWindow *mwindow, ClipPopup *popup)
419 : BC_MenuItem(_("Nest"))
421 this->mwindow = mwindow;
424 ClipPopupNest::~ClipPopupNest()
428 int ClipPopupNest::handle_event()
430 MWindowGUI *gui = mwindow->gui;
431 gui->lock_window("ClipPopupNest::handle_event 1");
432 if( mwindow->session->drag_clips->total > 0 ) {
433 EDL *edl = mwindow->edl;
434 time_t dt; time(&dt);
435 struct tm dtm; localtime_r(&dt, &dtm);
437 sprintf(path, _("Nested_%02d%02d%02d-%02d%02d%02d"),
438 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
439 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
440 EDL *clip = mwindow->session->drag_clips->values[0];
441 EDL *nested = edl->new_nested(clip, path);
442 EDL *new_clip = edl->create_nested_clip(nested);
443 new_clip->awindow_folder = AW_CLIP_FOLDER;
444 sprintf(new_clip->local_session->clip_icon,
445 "clip_%02d%02d%02d-%02d%02d%02d.png",
446 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
447 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
448 snprintf(new_clip->local_session->clip_title,
449 sizeof(new_clip->local_session->clip_title),
450 _("Nested: %s"), clip->local_session->clip_title);
451 strcpy(new_clip->local_session->clip_notes,
452 clip->local_session->clip_notes);
453 int idx = edl->clips.number_of(clip);
455 edl->clips[idx] = new_clip;
459 edl->clips.append(new_clip);
460 mwindow->mainindexes->add_next_asset(0, nested);
461 mwindow->mainindexes->start_build();
462 popup->gui->async_update_assets();
464 gui->unlock_window();
469 ClipPopupUnNest::ClipPopupUnNest(MWindow *mwindow, ClipPopup *popup)
470 : BC_MenuItem(_("UnNest"))
472 this->mwindow = mwindow;
475 ClipPopupUnNest::~ClipPopupUnNest()
479 int ClipPopupUnNest::handle_event()
482 MWindowGUI *gui = mwindow->gui;
483 gui->lock_window("ClipPopupUnNest::handle_event 1");
484 if( mwindow->session->drag_clips->total > 0 ) {
485 EDL *clip = mwindow->session->drag_clips->values[0];
486 Track *track = clip->tracks->first;
487 Edit *edit = track ? track->edits->first : 0;
488 nested_edl = edit && !edit->next && !edit->asset ? edit->nested_edl : 0;
489 while( nested_edl && (track=track->next)!=0 ) {
490 Edit *edit = track->edits->first;
491 if( !edit || edit->next || edit->nested_edl != nested_edl )
495 EDL *edl = mwindow->edl;
496 EDL *new_clip = new EDL(edl);
497 new_clip->create_objects();
498 new_clip->copy_all(nested_edl);
499 new_clip->awindow_folder = AW_CLIP_FOLDER;
500 int idx = edl->clips.number_of(clip);
502 edl->clips[idx] = new_clip;
506 edl->clips.append(new_clip);
507 popup->gui->async_update_assets();
510 gui->unlock_window();