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
23 #include "assetedit.h"
24 #include "assetpopup.h"
25 #include "assetremove.h"
27 #include "awindowgui.h"
28 #include "bcdisplayinfo.h"
29 #include "bcsignals.h"
33 #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"
46 #include "vwindowgui.h"
50 AssetPopup::AssetPopup(MWindow *mwindow, AWindowGUI *gui)
51 : BC_PopupMenu(0, 0, 0, "", 0)
53 this->mwindow = mwindow;
57 AssetPopup::~AssetPopup()
61 void AssetPopup::create_objects()
63 BC_MenuItem *menu_item;
65 add_item(info = new AssetPopupInfo(mwindow, this));
66 add_item(format = new AWindowListFormat(mwindow, gui));
67 add_item(menu_item = new BC_MenuItem(_("Sort...")));
68 menu_item->add_submenu(submenu = new BC_SubMenu());
69 submenu->add_submenuitem(new AssetPopupSortNames(mwindow, this));
70 submenu->add_submenuitem(new AssetPopupSortTimes(mwindow, this));
71 add_item(index = new AssetPopupBuildIndex(mwindow, this));
72 add_item(view = new AssetPopupView(mwindow, this));
73 add_item(view_window = new AssetPopupViewWindow(mwindow, this));
74 add_item(mixer = new AssetPopupMixer(mwindow, this));
75 add_item(new AssetPopupPaste(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 AssetMatchSize(mwindow, this));
79 submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
80 submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
81 add_item(menu_item = new BC_MenuItem(_("Remove...")));
82 menu_item->add_submenu(submenu = new BC_SubMenu());
83 submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
84 submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
87 void AssetPopup::paste_assets()
89 // Collect items into the drag vectors for temporary storage
90 gui->lock_window("AssetPopup::paste_assets");
91 mwindow->gui->lock_window("AssetPopup::paste_assets");
92 mwindow->cwindow->gui->lock_window("AssetPopup::paste_assets");
94 gui->collect_assets();
95 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
96 mwindow->edl->tracks->first,
97 0); // do not overwrite
100 mwindow->gui->unlock_window();
101 mwindow->cwindow->gui->unlock_window();
104 void AssetPopup::match_size()
106 // Collect items into the drag vectors for temporary storage
107 gui->collect_assets();
108 mwindow->gui->lock_window("AssetPopup::match_size");
109 mwindow->asset_to_size();
110 mwindow->gui->unlock_window();
113 void AssetPopup::match_rate()
115 // Collect items into the drag vectors for temporary storage
116 gui->collect_assets();
117 mwindow->gui->lock_window("AssetPopup::match_rate");
118 mwindow->asset_to_rate();
119 mwindow->gui->unlock_window();
122 void AssetPopup::match_all()
124 // Collect items into the drag vectors for temporary storage
125 gui->collect_assets();
126 mwindow->gui->lock_window("AssetPopup::match_rate");
127 mwindow->asset_to_all();
128 mwindow->gui->unlock_window();
131 int AssetPopup::update()
134 gui->collect_assets();
139 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
140 : BC_MenuItem(_("Info..."))
142 this->mwindow = mwindow;
146 AssetPopupInfo::~AssetPopupInfo()
150 int AssetPopupInfo::handle_event()
153 popup->gui->get_abs_cursor(cur_x, cur_y);
154 if( mwindow->session->drag_assets->size() ) {
155 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
156 asset_edit->edit_asset(
157 mwindow->session->drag_assets->values[0], cur_x, cur_y);
159 else if( mwindow->session->drag_clips->size() ) {
160 popup->gui->awindow->clip_edit->edit_clip(
161 mwindow->session->drag_clips->values[0], cur_x, cur_y);
167 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
168 : BC_MenuItem(_("Rebuild index"))
170 this->mwindow = mwindow;
174 AssetPopupBuildIndex::~AssetPopupBuildIndex()
178 int AssetPopupBuildIndex::handle_event()
180 //printf("AssetPopupBuildIndex::handle_event 1\n");
181 mwindow->rebuild_indices();
186 AssetPopupSortNames::AssetPopupSortNames(MWindow *mwindow, AssetPopup *popup)
187 : BC_MenuItem(_("Sort names"))
189 this->mwindow = mwindow;
193 AssetPopupSortNames::~AssetPopupSortNames()
197 int AssetPopupSortNames::handle_event()
199 mwindow->awindow->gui->sort_assets(0);
203 AssetPopupSortTimes::AssetPopupSortTimes(MWindow *mwindow, AssetPopup *popup)
204 : BC_MenuItem(_("Sort times"))
206 this->mwindow = mwindow;
210 AssetPopupSortTimes::~AssetPopupSortTimes()
214 int AssetPopupSortTimes::handle_event()
216 mwindow->awindow->gui->sort_assets(1);
221 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
222 : BC_MenuItem(_("View"))
224 this->mwindow = mwindow;
228 AssetPopupView::~AssetPopupView()
232 int AssetPopupView::handle_event()
234 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
235 vwindow->gui->lock_window("AssetPopupView::handle_event");
237 if( mwindow->session->drag_assets->total )
238 vwindow->change_source(
239 mwindow->session->drag_assets->values[0]);
241 if( mwindow->session->drag_clips->total )
242 vwindow->change_source(
243 mwindow->session->drag_clips->values[0]);
245 vwindow->gui->unlock_window();
250 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
251 : BC_MenuItem(_("View in new window"))
253 this->mwindow = mwindow;
257 AssetPopupViewWindow::~AssetPopupViewWindow()
261 int AssetPopupViewWindow::handle_event()
263 // Find window with nothing
264 VWindow *vwindow = mwindow->get_viewer(1);
266 // TODO: create new vwindow or change current vwindow
267 vwindow->gui->lock_window("AssetPopupView::handle_event");
269 if( mwindow->session->drag_assets->total )
270 vwindow->change_source(
271 mwindow->session->drag_assets->values[0]);
273 if( mwindow->session->drag_clips->total )
274 vwindow->change_source(
275 mwindow->session->drag_clips->values[0]);
277 vwindow->gui->unlock_window();
281 AssetPopupMixer::AssetPopupMixer(MWindow *mwindow, AssetPopup *popup)
282 : BC_MenuItem(_("Open Mixers"))
284 this->mwindow = mwindow;
288 AssetPopupMixer::~AssetPopupMixer()
292 int AssetPopupMixer::handle_event()
294 ArrayList<ZWindow *>new_mixers;
296 mwindow->select_zwindow(0);
297 for( int i=0; i<mwindow->session->drag_assets->total; ++i ) {
298 Indexable *indexable = mwindow->session->drag_assets->values[i];
299 ArrayList<Indexable*> new_assets;
300 new_assets.append(indexable);
301 Track *track = mwindow->edl->tracks->last;
302 mwindow->load_assets(&new_assets, -1, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
303 track = !track ? mwindow->edl->tracks->first : track->next;
305 ZWindow *zwindow = mwindow->get_mixer(mixer);
307 track->play = track->record = 0;
308 if( track->data_type == TRACK_VIDEO ) {
309 sprintf(track->title, _("Mixer %d"), zwindow->idx);
311 mixer->mixer_ids.append(track->get_mixer_id());
314 char *path = indexable->path;
315 char *tp = strrchr(path, '/');
316 if( !tp ) tp = path; else ++tp;
317 zwindow->set_title(tp);
318 new_mixers.append(zwindow);
321 mwindow->tile_mixers();
322 for( int i=0; i<new_mixers.size(); ++i )
323 new_mixers[i]->start();
325 mwindow->refresh_mixers();
326 mwindow->resync_guis();
330 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
331 : BC_MenuItem(_("Paste"))
333 this->mwindow = mwindow;
337 AssetPopupPaste::~AssetPopupPaste()
341 int AssetPopupPaste::handle_event()
343 popup->paste_assets();
348 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
349 : BC_MenuItem(_("Match project size"))
351 this->mwindow = mwindow;
355 int AssetMatchSize::handle_event()
361 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
362 : BC_MenuItem(_("Match frame rate"))
364 this->mwindow = mwindow;
368 int AssetMatchRate::handle_event()
374 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
375 : BC_MenuItem(_("Match all"))
377 this->mwindow = mwindow;
381 int AssetMatchAll::handle_event()
388 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
389 : BC_MenuItem(_("Remove from project"))
391 this->mwindow = mwindow;
395 AssetPopupProjectRemove::~AssetPopupProjectRemove()
399 int AssetPopupProjectRemove::handle_event()
401 mwindow->remove_assets_from_project(1, 1,
402 mwindow->session->drag_assets,
403 mwindow->session->drag_clips);
408 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
409 : BC_MenuItem(_("Remove from disk"))
411 this->mwindow = mwindow;
416 AssetPopupDiskRemove::~AssetPopupDiskRemove()
420 int AssetPopupDiskRemove::handle_event()
422 mwindow->awindow->asset_remove->start();
427 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
428 : BC_PopupMenu(0, 0, 0, "", 0)
430 this->mwindow = mwindow;
434 AssetListMenu::~AssetListMenu()
438 void AssetListMenu::create_objects()
440 add_item(format = new AWindowListFormat(mwindow, gui));
441 add_item(new AWindowListSort(mwindow, gui));
442 add_item(new AssetListCopy(mwindow, gui));
443 add_item(new AssetListPaste(mwindow, gui));
447 void AssetListMenu::update_titles()
452 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
453 : BC_MenuItem(_("Copy file list"))
455 this->mwindow = mwindow;
459 AssetListCopy::~AssetListCopy()
464 int AssetListCopy::handle_event()
467 MWindowGUI *gui = mwindow->gui;
468 gui->lock_window("AssetListCopy::handle_event");
469 mwindow->awindow->gui->collect_assets();
470 int n = mwindow->session->drag_assets->total;
471 for( int i=0; i<n; ++i ) {
472 Indexable *indexable = mwindow->session->drag_assets->values[i];
473 const char *path = indexable->path;
474 if( !*path ) continue;
475 len += strlen(path) + 1;
477 char *text = new char[len+1], *cp = text;
478 for( int i=0; i<n; ++i ) {
479 Indexable *indexable = mwindow->session->drag_assets->values[i];
480 const char *path = indexable->path;
481 if( !*path ) continue;
482 cp += sprintf(cp, "%s\n", path);
486 gui->get_abs_cursor(cur_x, cur_y, 0);
487 gui->unlock_window();
491 copy_dialog = new AssetCopyDialog(this);
492 copy_dialog->start(text, cur_x, cur_y);
495 eprintf(_("Nothing selected"));
501 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
508 void AssetCopyDialog::start(char *text, int x, int y)
512 this->x = x; this->y = y;
513 BC_DialogThread::start();
516 AssetCopyDialog::~AssetCopyDialog()
521 BC_Window* AssetCopyDialog::new_gui()
523 BC_DisplayInfo display_info;
525 copy_window = new AssetCopyWindow(this);
526 copy_window->create_objects();
530 void AssetCopyDialog::handle_done_event(int result)
532 delete [] text; text = 0;
535 void AssetCopyDialog::handle_close_event(int result)
541 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
542 : BC_Window(_(PROGRAM_NAME ": Copy File List"),
543 copy_dialog->x - 500/2, copy_dialog->y - 200/2,
544 500, 200, 500, 200, 1, 0, 1)
546 this->copy_dialog = copy_dialog;
549 AssetCopyWindow::~AssetCopyWindow()
553 void AssetCopyWindow::create_objects()
556 int x = 10, y = 10, pad = 5;
557 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
558 y += title->get_h() + pad;
559 int text_w = get_w() - x - 10;
560 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
561 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
562 char *text = copy_dialog->text;
563 int len = strlen(text) + BCTEXTLEN;
564 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
565 file_list->create_objects();
567 add_subwindow(new BC_OKButton(this));
571 int AssetCopyWindow::resize_event(int w, int h)
573 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
574 int text_w = w - fx - 10;
575 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
576 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
577 file_list->reposition_window(fx, fy, text_w, text_rows);
581 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
582 : BC_MenuItem(_("Paste file list"))
584 this->mwindow = mwindow;
588 AssetListPaste::~AssetListPaste()
593 int AssetListPaste::handle_event()
596 paste_dialog = new AssetPasteDialog(this);
598 paste_dialog->close_window();
600 gui->get_abs_cursor(cur_x, cur_y, 0);
601 paste_dialog->start(cur_x, cur_y);
605 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
612 AssetPasteDialog::~AssetPasteDialog()
617 BC_Window* AssetPasteDialog::new_gui()
619 paste_window = new AssetPasteWindow(this);
620 paste_window->create_objects();
624 void AssetPasteDialog::handle_done_event(int result)
627 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
628 ArrayList<char*> path_list;
629 path_list.set_array_delete();
631 for( const char *cp=bp; cp<ep && *cp; ) {
632 const char *dp = strchr(cp, '\n');
634 char path[BCTEXTLEN], *pp = path;
635 int len = sizeof(path)-1;
636 while( --len>0 && cp<dp ) *pp++ = *cp++;
639 if( !strlen(path) ) continue;
640 path_list.append(cstrdup(path));
642 if( !path_list.size() ) return;
644 MWindow *mwindow = paste->mwindow;
645 mwindow->interrupt_indexes();
646 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
647 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
648 mwindow->gui->unlock_window();
649 path_list.remove_all_objects();
650 mwindow->save_backup();
651 mwindow->restart_brender();
652 mwindow->session->changes_made = 1;
655 void AssetPasteDialog::handle_close_event(int result)
660 void AssetPasteDialog::start(int x, int y)
662 this->x = x; this->y = y;
663 BC_DialogThread::start();
666 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
667 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
668 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
669 500, 200, 500, 200, 1, 0, 1)
671 this->paste_dialog = paste_dialog;
674 AssetPasteWindow::~AssetPasteWindow()
678 void AssetPasteWindow::create_objects()
681 int x = 10, y = 10, pad = 5;
682 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
683 y += title->get_h() + pad;
684 int text_w = get_w() - x - 10;
685 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
686 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
687 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
688 file_list->create_objects();
689 add_subwindow(new BC_OKButton(this));
690 add_subwindow(new BC_CancelButton(this));
694 int AssetPasteWindow::resize_event(int w, int h)
696 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
697 int text_w = w - fx - 10;
698 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
699 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
700 file_list->reposition_window(fx, fy, text_w, text_rows);