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(new AssetPopupSort(mwindow, this));
68 add_item(index = new AssetPopupBuildIndex(mwindow, this));
69 add_item(view = new AssetPopupView(mwindow, this));
70 add_item(view_window = new AssetPopupViewWindow(mwindow, this));
71 add_item(mixer = new AssetPopupMixer(mwindow, this));
72 add_item(new AssetPopupPaste(mwindow, this));
73 add_item(menu_item = new BC_MenuItem(_("Match...")));
74 menu_item->add_submenu(submenu = new BC_SubMenu());
75 submenu->add_submenuitem(new AssetMatchSize(mwindow, this));
76 submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
77 submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
78 add_item(menu_item = new BC_MenuItem(_("Remove...")));
79 menu_item->add_submenu(submenu = new BC_SubMenu());
80 submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
81 submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
84 void AssetPopup::paste_assets()
86 // Collect items into the drag vectors for temporary storage
87 gui->lock_window("AssetPopup::paste_assets");
88 mwindow->gui->lock_window("AssetPopup::paste_assets");
89 mwindow->cwindow->gui->lock_window("AssetPopup::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 AssetPopup::match_size()
103 // Collect items into the drag vectors for temporary storage
104 gui->collect_assets();
105 mwindow->gui->lock_window("AssetPopup::match_size");
106 mwindow->asset_to_size();
107 mwindow->gui->unlock_window();
110 void AssetPopup::match_rate()
112 // Collect items into the drag vectors for temporary storage
113 gui->collect_assets();
114 mwindow->gui->lock_window("AssetPopup::match_rate");
115 mwindow->asset_to_rate();
116 mwindow->gui->unlock_window();
119 void AssetPopup::match_all()
121 // Collect items into the drag vectors for temporary storage
122 gui->collect_assets();
123 mwindow->gui->lock_window("AssetPopup::match_rate");
124 mwindow->asset_to_all();
125 mwindow->gui->unlock_window();
128 int AssetPopup::update()
131 gui->collect_assets();
136 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
137 : BC_MenuItem(_("Info..."))
139 this->mwindow = mwindow;
143 AssetPopupInfo::~AssetPopupInfo()
147 int AssetPopupInfo::handle_event()
150 popup->gui->get_abs_cursor(cur_x, cur_y);
151 if( mwindow->session->drag_assets->size() ) {
152 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
153 asset_edit->edit_asset(
154 mwindow->session->drag_assets->values[0], cur_x, cur_y);
156 else if( mwindow->session->drag_clips->size() ) {
157 popup->gui->awindow->clip_edit->edit_clip(
158 mwindow->session->drag_clips->values[0], cur_x, cur_y);
164 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
165 : BC_MenuItem(_("Rebuild index"))
167 this->mwindow = mwindow;
171 AssetPopupBuildIndex::~AssetPopupBuildIndex()
175 int AssetPopupBuildIndex::handle_event()
177 //printf("AssetPopupBuildIndex::handle_event 1\n");
178 mwindow->rebuild_indices();
183 AssetPopupSort::AssetPopupSort(MWindow *mwindow, AssetPopup *popup)
184 : BC_MenuItem(_("Sort items"))
186 this->mwindow = mwindow;
190 AssetPopupSort::~AssetPopupSort()
194 int AssetPopupSort::handle_event()
196 mwindow->awindow->gui->sort_assets();
201 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
202 : BC_MenuItem(_("View"))
204 this->mwindow = mwindow;
208 AssetPopupView::~AssetPopupView()
212 int AssetPopupView::handle_event()
214 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
215 vwindow->gui->lock_window("AssetPopupView::handle_event");
217 if( mwindow->session->drag_assets->total )
218 vwindow->change_source(
219 mwindow->session->drag_assets->values[0]);
221 if( mwindow->session->drag_clips->total )
222 vwindow->change_source(
223 mwindow->session->drag_clips->values[0]);
225 vwindow->gui->unlock_window();
230 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
231 : BC_MenuItem(_("View in new window"))
233 this->mwindow = mwindow;
237 AssetPopupViewWindow::~AssetPopupViewWindow()
241 int AssetPopupViewWindow::handle_event()
243 // Find window with nothing
244 VWindow *vwindow = mwindow->get_viewer(1);
246 // TODO: create new vwindow or change current vwindow
247 vwindow->gui->lock_window("AssetPopupView::handle_event");
249 if( mwindow->session->drag_assets->total )
250 vwindow->change_source(
251 mwindow->session->drag_assets->values[0]);
253 if( mwindow->session->drag_clips->total )
254 vwindow->change_source(
255 mwindow->session->drag_clips->values[0]);
257 vwindow->gui->unlock_window();
261 AssetPopupMixer::AssetPopupMixer(MWindow *mwindow, AssetPopup *popup)
262 : BC_MenuItem(_("Open Mixers"))
264 this->mwindow = mwindow;
268 AssetPopupMixer::~AssetPopupMixer()
272 int AssetPopupMixer::handle_event()
274 mwindow->select_zwindow(0);
275 for( int i=0; i<mwindow->session->drag_assets->total; ++i ) {
276 Indexable *indexable = mwindow->session->drag_assets->values[i];
277 ArrayList<Indexable*> new_assets;
278 new_assets.append(indexable);
279 Track *track = mwindow->edl->tracks->last;
280 mwindow->load_assets(&new_assets, -1, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
281 track = !track ? mwindow->edl->tracks->first : track->next;
283 ZWindow *zwindow = mwindow->get_mixer(mixer);
285 track->play = track->record = 0;
286 mixer->mixer_ids.append(track->get_mixer_id());
289 char *path = indexable->path;
290 char *tp = strrchr(path, '/');
291 if( !tp ) tp = path; else ++tp;
292 zwindow->set_title(tp);
295 mwindow->queue_mixers(mwindow->edl,CURRENT_FRAME,0,0,1,0);
296 mwindow->resync_guis();
300 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
301 : BC_MenuItem(_("Paste"))
303 this->mwindow = mwindow;
307 AssetPopupPaste::~AssetPopupPaste()
311 int AssetPopupPaste::handle_event()
313 popup->paste_assets();
318 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
319 : BC_MenuItem(_("Match project size"))
321 this->mwindow = mwindow;
325 int AssetMatchSize::handle_event()
331 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
332 : BC_MenuItem(_("Match frame rate"))
334 this->mwindow = mwindow;
338 int AssetMatchRate::handle_event()
344 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
345 : BC_MenuItem(_("Match all"))
347 this->mwindow = mwindow;
351 int AssetMatchAll::handle_event()
358 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
359 : BC_MenuItem(_("Remove from project"))
361 this->mwindow = mwindow;
365 AssetPopupProjectRemove::~AssetPopupProjectRemove()
369 int AssetPopupProjectRemove::handle_event()
371 mwindow->remove_assets_from_project(1, 1,
372 mwindow->session->drag_assets,
373 mwindow->session->drag_clips);
378 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
379 : BC_MenuItem(_("Remove from disk"))
381 this->mwindow = mwindow;
386 AssetPopupDiskRemove::~AssetPopupDiskRemove()
390 int AssetPopupDiskRemove::handle_event()
392 mwindow->awindow->asset_remove->start();
397 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
398 : BC_PopupMenu(0, 0, 0, "", 0)
400 this->mwindow = mwindow;
404 AssetListMenu::~AssetListMenu()
408 void AssetListMenu::create_objects()
410 add_item(format = new AWindowListFormat(mwindow, gui));
411 add_item(new AWindowListSort(mwindow, gui));
412 add_item(new AssetListCopy(mwindow, gui));
413 add_item(new AssetListPaste(mwindow, gui));
417 void AssetListMenu::update_titles()
422 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
423 : BC_MenuItem(_("Copy file list"))
425 this->mwindow = mwindow;
429 AssetListCopy::~AssetListCopy()
434 int AssetListCopy::handle_event()
437 MWindowGUI *gui = mwindow->gui;
438 gui->lock_window("AssetListCopy::handle_event");
439 mwindow->awindow->gui->collect_assets();
440 int n = mwindow->session->drag_assets->total;
441 for( int i=0; i<n; ++i ) {
442 Indexable *indexable = mwindow->session->drag_assets->values[i];
443 const char *path = indexable->path;
444 if( !*path ) continue;
445 len += strlen(path) + 1;
447 char *text = new char[len+1], *cp = text;
448 for( int i=0; i<n; ++i ) {
449 Indexable *indexable = mwindow->session->drag_assets->values[i];
450 const char *path = indexable->path;
451 if( !*path ) continue;
452 cp += sprintf(cp, "%s\n", path);
456 gui->get_abs_cursor(cur_x, cur_y, 0);
457 gui->unlock_window();
461 copy_dialog = new AssetCopyDialog(this);
462 copy_dialog->start(text, cur_x, cur_y);
465 eprintf(_("Nothing selected"));
471 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
478 void AssetCopyDialog::start(char *text, int x, int y)
482 this->x = x; this->y = y;
483 BC_DialogThread::start();
486 AssetCopyDialog::~AssetCopyDialog()
491 BC_Window* AssetCopyDialog::new_gui()
493 BC_DisplayInfo display_info;
495 copy_window = new AssetCopyWindow(this);
496 copy_window->create_objects();
500 void AssetCopyDialog::handle_done_event(int result)
502 delete [] text; text = 0;
505 void AssetCopyDialog::handle_close_event(int result)
511 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
512 : BC_Window(_(PROGRAM_NAME ": Copy File List"),
513 copy_dialog->x - 500/2, copy_dialog->y - 200/2,
514 500, 200, 500, 200, 1, 0, 1)
516 this->copy_dialog = copy_dialog;
519 AssetCopyWindow::~AssetCopyWindow()
523 void AssetCopyWindow::create_objects()
526 int x = 10, y = 10, pad = 5;
527 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
528 y += title->get_h() + pad;
529 int text_w = get_w() - x - 10;
530 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
531 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
532 char *text = copy_dialog->text;
533 int len = strlen(text) + BCTEXTLEN;
534 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
535 file_list->create_objects();
537 add_subwindow(new BC_OKButton(this));
541 int AssetCopyWindow::resize_event(int w, int h)
543 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
544 int text_w = w - fx - 10;
545 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
546 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
547 file_list->reposition_window(fx, fy, text_w, text_rows);
551 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
552 : BC_MenuItem(_("Paste file list"))
554 this->mwindow = mwindow;
558 AssetListPaste::~AssetListPaste()
563 int AssetListPaste::handle_event()
566 paste_dialog = new AssetPasteDialog(this);
568 paste_dialog->close_window();
570 gui->get_abs_cursor(cur_x, cur_y, 0);
571 paste_dialog->start(cur_x, cur_y);
575 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
582 AssetPasteDialog::~AssetPasteDialog()
587 BC_Window* AssetPasteDialog::new_gui()
589 paste_window = new AssetPasteWindow(this);
590 paste_window->create_objects();
594 void AssetPasteDialog::handle_done_event(int result)
597 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
598 ArrayList<char*> path_list;
599 path_list.set_array_delete();
601 for( const char *cp=bp; cp<ep && *cp; ) {
602 const char *dp = strchr(cp, '\n');
604 char path[BCTEXTLEN], *pp = path;
605 int len = sizeof(path)-1;
606 while( --len>0 && cp<dp ) *pp++ = *cp++;
609 if( !strlen(path) ) continue;
610 path_list.append(cstrdup(path));
612 if( !path_list.size() ) return;
614 MWindow *mwindow = paste->mwindow;
615 mwindow->interrupt_indexes();
616 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
617 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
618 mwindow->gui->unlock_window();
619 path_list.remove_all_objects();
620 mwindow->save_backup();
621 mwindow->restart_brender();
622 mwindow->session->changes_made = 1;
625 void AssetPasteDialog::handle_close_event(int result)
630 void AssetPasteDialog::start(int x, int y)
632 this->x = x; this->y = y;
633 BC_DialogThread::start();
636 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
637 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
638 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
639 500, 200, 500, 200, 1, 0, 1)
641 this->paste_dialog = paste_dialog;
644 AssetPasteWindow::~AssetPasteWindow()
648 void AssetPasteWindow::create_objects()
651 int x = 10, y = 10, pad = 5;
652 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
653 y += title->get_h() + pad;
654 int text_w = get_w() - x - 10;
655 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
656 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
657 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
658 file_list->create_objects();
659 add_subwindow(new BC_OKButton(this));
660 add_subwindow(new BC_CancelButton(this));
664 int AssetPasteWindow::resize_event(int w, int h)
666 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
667 int text_w = w - fx - 10;
668 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
669 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
670 file_list->reposition_window(fx, fy, text_w, text_rows);