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"
30 #include "cwindowgui.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainsession.h"
38 #include "mwindowgui.h"
41 #include "vwindowgui.h"
45 ClipPopup::ClipPopup(MWindow *mwindow, AWindowGUI *gui)
46 : BC_PopupMenu(0, 0, 0, "", 0)
48 this->mwindow = mwindow;
52 ClipPopup::~ClipPopup()
56 void ClipPopup::create_objects()
58 BC_MenuItem *menu_item;
60 add_item(info = new ClipPopupInfo(mwindow, this));
61 add_item(format = new AWindowListFormat(mwindow, gui));
62 add_item(new ClipPopupSort(mwindow, this));
63 add_item(view = new ClipPopupView(mwindow, this));
64 add_item(view_window = new ClipPopupViewWindow(mwindow, this));
65 add_item(new ClipPopupCopy(mwindow, this));
66 add_item(new ClipPopupPaste(mwindow, this));
67 add_item(menu_item = new BC_MenuItem(_("Match...")));
68 menu_item->add_submenu(submenu = new BC_SubMenu());
69 submenu->add_submenuitem(new ClipMatchSize(mwindow, this));
70 submenu->add_submenuitem(new ClipMatchRate(mwindow, this));
71 submenu->add_submenuitem(new ClipMatchAll(mwindow, this));
72 add_item(new ClipPopupDelete(mwindow, this));
75 void ClipPopup::paste_assets()
77 // Collect items into the drag vectors for temporary storage
78 gui->lock_window("ClipPopup::paste_assets");
79 mwindow->gui->lock_window("ClipPopup::paste_assets");
80 mwindow->cwindow->gui->lock_window("ClipPopup::paste_assets");
82 gui->collect_assets();
83 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
84 mwindow->edl->tracks->first,
85 0); // do not overwrite
88 mwindow->gui->unlock_window();
89 mwindow->cwindow->gui->unlock_window();
92 void ClipPopup::match_size()
94 // Collect items into the drag vectors for temporary storage
95 gui->collect_assets();
96 mwindow->gui->lock_window("ClipPopup::match_size");
97 mwindow->asset_to_size();
98 mwindow->gui->unlock_window();
101 void ClipPopup::match_rate()
103 // Collect items into the drag vectors for temporary storage
104 gui->collect_assets();
105 mwindow->gui->lock_window("ClipPopup::match_rate");
106 mwindow->asset_to_rate();
107 mwindow->gui->unlock_window();
110 void ClipPopup::match_all()
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_all();
116 mwindow->gui->unlock_window();
119 int ClipPopup::update()
122 gui->collect_assets();
127 ClipPopupInfo::ClipPopupInfo(MWindow *mwindow, ClipPopup *popup)
128 : BC_MenuItem(_("Info..."))
130 this->mwindow = mwindow;
134 ClipPopupInfo::~ClipPopupInfo()
138 int ClipPopupInfo::handle_event()
141 popup->gui->get_abs_cursor(cur_x, cur_y, 0);
143 if( mwindow->session->drag_assets->total ) {
144 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
145 asset_edit->edit_asset(
146 mwindow->session->drag_assets->values[0], cur_x, cur_y);
149 if( mwindow->session->drag_clips->total ) {
150 popup->gui->awindow->clip_edit->edit_clip(
151 mwindow->session->drag_clips->values[0], cur_x, cur_y);
157 ClipPopupSort::ClipPopupSort(MWindow *mwindow, ClipPopup *popup)
158 : BC_MenuItem(_("Sort items"))
160 this->mwindow = mwindow;
164 ClipPopupSort::~ClipPopupSort()
168 int ClipPopupSort::handle_event()
170 mwindow->awindow->gui->sort_assets(0);
175 ClipPopupView::ClipPopupView(MWindow *mwindow, ClipPopup *popup)
176 : BC_MenuItem(_("View"))
178 this->mwindow = mwindow;
182 ClipPopupView::~ClipPopupView()
186 int ClipPopupView::handle_event()
188 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
190 if( mwindow->session->drag_assets->total )
191 vwindow->change_source(
192 mwindow->session->drag_assets->values[0]);
194 if( mwindow->session->drag_clips->total )
195 vwindow->change_source(
196 mwindow->session->drag_clips->values[0]);
202 ClipPopupViewWindow::ClipPopupViewWindow(MWindow *mwindow, ClipPopup *popup)
203 : BC_MenuItem(_("View in new window"))
205 this->mwindow = mwindow;
209 ClipPopupViewWindow::~ClipPopupViewWindow()
213 int ClipPopupViewWindow::handle_event()
215 // Find window with nothing
216 VWindow *vwindow = mwindow->get_viewer(1);
218 // TODO: create new vwindow or change current vwindow
219 vwindow->gui->lock_window("ClipPopupView::handle_event");
221 if( mwindow->session->drag_assets->total )
222 vwindow->change_source(
223 mwindow->session->drag_assets->values[0]);
225 if( mwindow->session->drag_clips->total )
226 vwindow->change_source(
227 mwindow->session->drag_clips->values[0]);
229 vwindow->gui->unlock_window();
234 ClipPopupCopy::ClipPopupCopy(MWindow *mwindow, ClipPopup *popup)
235 : BC_MenuItem(_("Copy"))
237 this->mwindow = mwindow;
240 ClipPopupCopy::~ClipPopupCopy()
244 int ClipPopupCopy::handle_event()
246 MWindowGUI *gui = mwindow->gui;
247 gui->lock_window("ClipPopupCopy::handle_event");
248 if( mwindow->session->drag_clips->total > 0 ) {
250 EDL *edl = mwindow->session->drag_clips->values[0];
251 double start = 0, end = edl->tracks->total_length();
252 edl->copy(start, end, 1, 0, 0, &file, "", 1);
253 const char *file_string = file.string();
254 long file_length = strlen(file_string);
255 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
256 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
258 gui->unlock_window();
263 ClipPopupPaste::ClipPopupPaste(MWindow *mwindow, ClipPopup *popup)
264 : BC_MenuItem(_("Paste"))
266 this->mwindow = mwindow;
270 ClipPopupPaste::~ClipPopupPaste()
274 int ClipPopupPaste::handle_event()
276 popup->paste_assets();
281 ClipMatchSize::ClipMatchSize(MWindow *mwindow, ClipPopup *popup)
282 : BC_MenuItem(_("Match project size"))
284 this->mwindow = mwindow;
288 int ClipMatchSize::handle_event()
295 ClipMatchRate::ClipMatchRate(MWindow *mwindow, ClipPopup *popup)
296 : BC_MenuItem(_("Match frame rate"))
298 this->mwindow = mwindow;
302 int ClipMatchRate::handle_event()
309 ClipMatchAll::ClipMatchAll(MWindow *mwindow, ClipPopup *popup)
310 : BC_MenuItem(_("Match all"))
312 this->mwindow = mwindow;
316 int ClipMatchAll::handle_event()
323 ClipPopupDelete::ClipPopupDelete(MWindow *mwindow, ClipPopup *popup)
324 : BC_MenuItem(_("Delete"))
326 this->mwindow = mwindow;
331 ClipPopupDelete::~ClipPopupDelete()
335 int ClipPopupDelete::handle_event()
337 mwindow->remove_assets_from_project(1, 1,
338 mwindow->session->drag_assets,
339 mwindow->session->drag_clips);
344 ClipPasteToFolder::ClipPasteToFolder(MWindow *mwindow)
345 : BC_MenuItem(_("Paste Clip"))
347 this->mwindow = mwindow;
350 int ClipPasteToFolder::handle_event()
352 MWindowGUI *gui = mwindow->gui;
353 gui->lock_window("ClipPasteToFolder::handle_event 1");
354 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
356 char *string = new char[len];
357 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
358 const char *clip_header = "<EDL VERSION=";
359 if( !strncmp(clip_header, string, strlen(clip_header)) ) {
361 file.read_from_string(string);
362 EDL *edl = mwindow->edl;
363 EDL *new_edl = new EDL(mwindow->edl);
364 new_edl->create_objects();
365 new_edl->load_xml(&file, LOAD_ALL);
366 edl->update_assets(new_edl);
367 mwindow->save_clip(new_edl, _("paste clip: "));
370 char *cp = strchr(string, '\n');
371 if( cp-string < 32 ) *cp = 0;
372 else if( len > 32 ) string[32] = 0;
373 eprintf("paste buffer is not EDL:\n%s", string);
378 eprintf("paste buffer empty");
380 gui->unlock_window();
385 ClipListMenu::ClipListMenu(MWindow *mwindow, AWindowGUI *gui)
386 : BC_PopupMenu(0, 0, 0, "", 0)
388 this->mwindow = mwindow;
392 ClipListMenu::~ClipListMenu()
396 void ClipListMenu::create_objects()
398 add_item(format = new AWindowListFormat(mwindow, gui));
399 add_item(new AWindowListSort(mwindow, gui));
400 add_item(new ClipPasteToFolder(mwindow));
404 void ClipListMenu::update()