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 // Find window with nothing
223 VWindow *vwindow = mwindow->get_viewer(1);
225 // TODO: create new vwindow or change current vwindow
226 vwindow->gui->lock_window("ClipPopupView::handle_event");
228 if( mwindow->session->drag_assets->total )
229 vwindow->change_source(
230 mwindow->session->drag_assets->values[0]);
232 if( mwindow->session->drag_clips->total )
233 vwindow->change_source(
234 mwindow->session->drag_clips->values[0]);
236 vwindow->gui->unlock_window();
241 ClipPopupCopy::ClipPopupCopy(MWindow *mwindow, ClipPopup *popup)
242 : BC_MenuItem(_("Copy"))
244 this->mwindow = mwindow;
247 ClipPopupCopy::~ClipPopupCopy()
251 int ClipPopupCopy::handle_event()
253 MWindowGUI *gui = mwindow->gui;
254 gui->lock_window("ClipPopupCopy::handle_event");
255 if( mwindow->session->drag_clips->total > 0 ) {
257 EDL *edl = mwindow->session->drag_clips->values[0];
258 double start = 0, end = edl->tracks->total_length();
259 edl->copy(start, end, 1, &file, "", 1);
260 const char *file_string = file.string();
261 long file_length = strlen(file_string);
262 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
263 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
265 gui->unlock_window();
270 ClipPopupPaste::ClipPopupPaste(MWindow *mwindow, ClipPopup *popup)
271 : BC_MenuItem(_("Paste"))
273 this->mwindow = mwindow;
277 ClipPopupPaste::~ClipPopupPaste()
281 int ClipPopupPaste::handle_event()
283 popup->paste_assets();
288 ClipMatchSize::ClipMatchSize(MWindow *mwindow, ClipPopup *popup)
289 : BC_MenuItem(_("Match project size"))
291 this->mwindow = mwindow;
295 int ClipMatchSize::handle_event()
302 ClipMatchRate::ClipMatchRate(MWindow *mwindow, ClipPopup *popup)
303 : BC_MenuItem(_("Match frame rate"))
305 this->mwindow = mwindow;
309 int ClipMatchRate::handle_event()
316 ClipMatchAll::ClipMatchAll(MWindow *mwindow, ClipPopup *popup)
317 : BC_MenuItem(_("Match all"))
319 this->mwindow = mwindow;
323 int ClipMatchAll::handle_event()
330 ClipPopupDelete::ClipPopupDelete(MWindow *mwindow, ClipPopup *popup)
331 : BC_MenuItem(_("Delete"))
333 this->mwindow = mwindow;
338 ClipPopupDelete::~ClipPopupDelete()
342 int ClipPopupDelete::handle_event()
344 mwindow->remove_assets_from_project(1, 1,
345 mwindow->session->drag_assets,
346 mwindow->session->drag_clips);
351 ClipPasteToFolder::ClipPasteToFolder(MWindow *mwindow)
352 : BC_MenuItem(_("Paste Clip"))
354 this->mwindow = mwindow;
357 int ClipPasteToFolder::handle_event()
359 MWindowGUI *gui = mwindow->gui;
360 gui->lock_window("ClipPasteToFolder::handle_event 1");
361 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
363 char *string = new char[len];
364 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
365 const char *clip_header = "<EDL VERSION=";
366 if( !strncmp(clip_header, string, strlen(clip_header)) ) {
368 file.read_from_string(string);
369 EDL *edl = mwindow->edl;
370 EDL *new_edl = new EDL(mwindow->edl);
371 new_edl->create_objects();
372 new_edl->load_xml(&file, LOAD_ALL);
373 edl->update_assets(new_edl);
374 mwindow->save_clip(new_edl, _("paste clip: "));
377 char *cp = strchr(string, '\n');
378 if( cp-string < 32 ) *cp = 0;
379 else if( len > 32 ) string[32] = 0;
380 eprintf("paste buffer is not EDL:\n%s", string);
385 eprintf("paste buffer empty");
387 gui->unlock_window();
392 ClipListMenu::ClipListMenu(MWindow *mwindow, AWindowGUI *gui)
393 : BC_PopupMenu(0, 0, 0, "", 0)
395 this->mwindow = mwindow;
399 ClipListMenu::~ClipListMenu()
403 void ClipListMenu::create_objects()
405 add_item(format = new AWindowListFormat(mwindow, gui));
406 add_item(new AWindowListSort(mwindow, gui));
407 add_item(new ClipPasteToFolder(mwindow));
411 void ClipListMenu::update()
417 ClipPopupNest::ClipPopupNest(MWindow *mwindow, ClipPopup *popup)
418 : BC_MenuItem(_("Nest"))
420 this->mwindow = mwindow;
423 ClipPopupNest::~ClipPopupNest()
427 int ClipPopupNest::handle_event()
429 MWindowGUI *gui = mwindow->gui;
430 gui->lock_window("ClipPopupNest::handle_event 1");
431 if( mwindow->session->drag_clips->total > 0 ) {
432 EDL *edl = mwindow->edl;
433 EDL *clip = mwindow->session->drag_clips->values[0];
434 EDL *clip_edl = new EDL; // no parent for nested clip
435 clip_edl->create_objects();
436 clip_edl->copy_all(clip);
437 EDL *new_clip = new EDL(edl);
438 new_clip->create_objects();
439 new_clip->awindow_folder = AW_CLIP_FOLDER;
440 snprintf(new_clip->local_session->clip_title,
441 sizeof(new_clip->local_session->clip_title),
442 _("Nested: %s"), clip->local_session->clip_title);
443 strcpy(new_clip->local_session->clip_notes,
444 clip->local_session->clip_notes);
445 time_t dt; time(&dt);
446 struct tm dtm; localtime_r(&dt, &dtm);
448 sprintf(path, _("Nested_%02d%02d%02d-%02d%02d%02d"),
449 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
450 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
451 clip_edl->set_path(path);
452 new_clip->set_path(path);
453 new_clip->to_nested(clip_edl);
454 int idx = edl->clips.number_of(clip);
456 edl->clips[idx] = new_clip;
460 edl->clips.append(new_clip);
461 mwindow->mainindexes->add_next_asset(0, clip_edl);
462 mwindow->mainindexes->start_build();
463 clip_edl->remove_user();
464 popup->gui->async_update_assets();
466 gui->unlock_window();
471 ClipPopupUnNest::ClipPopupUnNest(MWindow *mwindow, ClipPopup *popup)
472 : BC_MenuItem(_("UnNest"))
474 this->mwindow = mwindow;
477 ClipPopupUnNest::~ClipPopupUnNest()
481 int ClipPopupUnNest::handle_event()
484 MWindowGUI *gui = mwindow->gui;
485 gui->lock_window("ClipPopupUnNest::handle_event 1");
486 if( mwindow->session->drag_clips->total > 0 ) {
487 EDL *clip = mwindow->session->drag_clips->values[0];
488 Track *track = clip->tracks->first;
489 Edit *edit = track ? track->edits->first : 0;
490 nested_edl = edit && !edit->next && !edit->asset ? edit->nested_edl : 0;
491 while( nested_edl && (track=track->next)!=0 ) {
492 Edit *edit = track->edits->first;
493 if( !edit || edit->next || edit->nested_edl != nested_edl )
497 EDL *edl = mwindow->edl;
498 EDL *new_clip = new EDL(edl);
499 new_clip->create_objects();
500 new_clip->copy_all(nested_edl);
501 new_clip->awindow_folder = AW_CLIP_FOLDER;
502 int idx = edl->clips.number_of(clip);
504 edl->clips[idx] = new_clip;
508 edl->clips.append(new_clip);
509 edl->clips.add_clip(new_clip);
510 popup->gui->async_update_assets();
513 gui->unlock_window();