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"
28 #include "awindowgui.h"
29 #include "bccapture.h"
30 #include "bcdisplayinfo.h"
31 #include "bcsignals.h"
36 #include "cwindowgui.h"
38 #include "edlsession.h"
40 #include "filesystem.h"
44 #include "localsession.h"
45 #include "mainerror.h"
46 #include "mainindexes.h"
48 #include "mainsession.h"
50 #include "mwindowgui.h"
51 #include "preferences.h"
52 #include "renderengine.h"
54 #include "transportque.h"
58 #include "vwindowgui.h"
62 AssetPopup::AssetPopup(MWindow *mwindow, AWindowGUI *gui)
63 : BC_PopupMenu(0, 0, 0, "", 0)
65 this->mwindow = mwindow;
69 AssetPopup::~AssetPopup()
73 void AssetPopup::create_objects()
75 BC_MenuItem *menu_item;
77 add_item(info = new AssetPopupInfo(mwindow, this));
78 add_item(format = new AWindowListFormat(mwindow, gui));
79 add_item(open_edl = new AssetPopupOpenEDL(mwindow, this));
80 add_item(close_edl = new AssetPopupCloseEDL(mwindow, gui));
81 add_item(to_clip = new AssetPopupToClip(mwindow, this));
82 add_item(sort = new AssetPopupSort(mwindow, this));
83 add_item(index = new AssetPopupBuildIndex(mwindow, this));
84 add_item(view = new AssetPopupView(mwindow, this));
85 add_item(view_window = new AssetPopupViewWindow(mwindow, this));
86 add_item(open_mixer = new AssetPopupOpenMixer(mwindow, this));
87 add_item(insert_mixer = new AssetPopupInsertMixer(mwindow, this));
88 add_item(paste = new AssetPopupPaste(mwindow, this));
89 add_item(menu_item = new BC_MenuItem(_("Match...")));
90 menu_item->add_submenu(submenu = new BC_SubMenu());
91 submenu->add_submenuitem(new AssetMatchSize(mwindow, this));
92 submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
93 submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
94 add_item(menu_item = new BC_MenuItem(_("Remove...")));
95 menu_item->add_submenu(submenu = new BC_SubMenu());
96 submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
97 submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
100 void AssetPopup::paste_assets()
102 // Collect items into the drag vectors for temporary storage
103 gui->lock_window("AssetPopup::paste_assets");
104 mwindow->gui->lock_window("AssetPopup::paste_assets");
105 mwindow->cwindow->gui->lock_window("AssetPopup::paste_assets");
107 int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
108 gui->collect_assets(proxy);
109 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
110 mwindow->edl->tracks->first, 0); // do not overwrite
112 gui->unlock_window();
113 mwindow->gui->unlock_window();
114 mwindow->cwindow->gui->unlock_window();
117 void AssetPopup::match_size()
119 // Collect items into the drag vectors for temporary storage
120 gui->collect_assets();
121 mwindow->gui->lock_window("AssetPopup::match_size");
122 mwindow->asset_to_size();
123 mwindow->gui->unlock_window();
126 void AssetPopup::match_rate()
128 // Collect items into the drag vectors for temporary storage
129 gui->collect_assets();
130 mwindow->gui->lock_window("AssetPopup::match_rate");
131 mwindow->asset_to_rate();
132 mwindow->gui->unlock_window();
135 void AssetPopup::match_all()
137 // Collect items into the drag vectors for temporary storage
138 gui->collect_assets();
139 mwindow->gui->lock_window("AssetPopup::match_rate");
140 mwindow->asset_to_all();
141 mwindow->gui->unlock_window();
144 int AssetPopup::update()
147 int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
148 gui->collect_assets(proxy);
150 int assets_total = mwindow->session->drag_assets->size();
151 Indexable *idxbl = !assets_total ? 0 :
152 mwindow->session->drag_assets->get(0);
154 if( idxbl->is_asset ) {
155 Asset *asset = (Asset *)idxbl;
156 if( asset->format == FILE_REF )
162 open_edl->set_enabled(enable_open);
163 int enable_close = mwindow->stack.size() > 0 ? 1 : 0;
164 close_edl->set_enabled(enable_close);
166 for( int i=0; !enable_clip && i<assets_total; ++i ) {
167 Indexable *idxbl = mwindow->session->drag_assets->get(i);
168 if( !idxbl->is_asset ) enable_clip = 1;
170 to_clip->set_enabled(enable_clip);
175 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
176 : BC_MenuItem(_("Info..."))
178 this->mwindow = mwindow;
182 AssetPopupInfo::~AssetPopupInfo()
186 int AssetPopupInfo::handle_event()
189 popup->gui->get_abs_cursor(cur_x, cur_y);
190 int n = mwindow->session->drag_assets->size();
192 int xs30 = xS(30), ys30 = yS(30);
193 for( int i=0; i<n; ++i ) {
194 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
195 asset_edit->edit_asset(
196 mwindow->session->drag_assets->values[i], cur_x-xs30*i, cur_y-ys30*i);
199 else if( mwindow->session->drag_clips->size() ) {
200 popup->gui->awindow->clip_edit->edit_clip(
201 mwindow->session->drag_clips->values[0], cur_x, cur_y);
207 AssetPopupOpenEDL::AssetPopupOpenEDL(MWindow *mwindow, AssetPopup *popup)
208 : BC_MenuItem(_("Open EDL"))
210 this->mwindow = mwindow;
213 AssetPopupOpenEDL::~AssetPopupOpenEDL()
217 int AssetPopupOpenEDL::handle_event()
219 int assets_total = mwindow->session->drag_assets->size();
220 if( !assets_total ) return 1;
221 popup->unlock_window();
223 Indexable *idxbl = mwindow->session->drag_assets->get(0);
224 if( idxbl->is_asset ) {
225 Asset *asset = (Asset *)idxbl;
226 if( asset->format == FILE_REF ) {
228 const char *filename = asset->path;
229 if( xml_file.read_from_file(filename, 1) ) {
230 eprintf(_("Error: unable to open:\n %s"), filename);
234 edl->create_objects();
235 if( edl->load_xml(&xml_file, LOAD_ALL) ) {
236 eprintf(_("Error: unable to load:\n %s"), filename);
246 mwindow->stack_push(edl, idxbl);
248 eprintf(_("media is not EDL:\n%s"), idxbl->path);
249 popup->lock_window("AssetPopupOpenEDL::handle_event");
253 AssetPopupCloseEDL::AssetPopupCloseEDL(MWindow *mwindow, AWindowGUI *gui)
254 : BC_MenuItem(_("Close EDL"))
256 this->mwindow = mwindow;
259 AssetPopupCloseEDL::~AssetPopupCloseEDL()
263 int AssetPopupCloseEDL::handle_event()
265 gui->unlock_window();
266 mwindow->gui->lock_window("AssetPopupCloseEDL::handle_event");
267 mwindow->stack_pop();
268 mwindow->gui->unlock_window();
269 gui->lock_window("AssetPopupCloseEDL::handle_event");
274 AssetPopupToClip::AssetPopupToClip(MWindow *mwindow, AssetPopup *popup)
275 : BC_MenuItem(_("EDL to clip"))
277 this->mwindow = mwindow;
281 AssetPopupToClip::~AssetPopupToClip()
285 int AssetPopupToClip::handle_event()
287 mwindow->media_to_clip();
292 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
293 : BC_MenuItem(_("Rebuild index"))
295 this->mwindow = mwindow;
299 AssetPopupBuildIndex::~AssetPopupBuildIndex()
303 int AssetPopupBuildIndex::handle_event()
305 //printf("AssetPopupBuildIndex::handle_event 1\n");
306 mwindow->rebuild_indices();
311 AssetPopupSort::AssetPopupSort(MWindow *mwindow, AssetPopup *popup)
312 : BC_MenuItem(_("Sort"))
314 this->mwindow = mwindow;
318 AssetPopupSort::~AssetPopupSort()
322 int AssetPopupSort::handle_event()
324 mwindow->awindow->gui->sort_assets();
329 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
330 : BC_MenuItem(_("View"))
332 this->mwindow = mwindow;
336 AssetPopupView::~AssetPopupView()
340 int AssetPopupView::handle_event()
342 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
344 if( mwindow->session->drag_assets->total )
345 vwindow->change_source(
346 mwindow->session->drag_assets->values[0]);
348 if( mwindow->session->drag_clips->total )
349 vwindow->change_source(
350 mwindow->session->drag_clips->values[0]);
356 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
357 : BC_MenuItem(_("View in new window"))
359 this->mwindow = mwindow;
363 AssetPopupViewWindow::~AssetPopupViewWindow()
367 int AssetPopupViewWindow::handle_event()
369 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
370 VWindow *vwindow = mwindow->get_viewer(1);
371 vwindow->gui->lock_window("AssetPopupView::handle_event 1");
372 vwindow->change_source(mwindow->session->drag_assets->get(i));
373 vwindow->gui->unlock_window();
375 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
376 VWindow *vwindow = mwindow->get_viewer(1);
377 vwindow->gui->lock_window("AssetPopupView::handle_event 2");
378 vwindow->change_source(mwindow->session->drag_clips->get(i));
379 vwindow->gui->unlock_window();
384 AssetPopupOpenMixer::AssetPopupOpenMixer(MWindow *mwindow, AssetPopup *popup)
385 : BC_MenuItem(_("Open Mixers"))
387 this->mwindow = mwindow;
391 AssetPopupOpenMixer::~AssetPopupOpenMixer()
395 int AssetPopupOpenMixer::handle_event()
397 mwindow->gui->lock_window("AssetPopupOpenMixer::handle_event");
398 mwindow->create_mixers();
399 mwindow->gui->unlock_window();
403 AssetPopupInsertMixer::AssetPopupInsertMixer(MWindow *mwindow, AssetPopup *popup)
404 : BC_MenuItem(_("Insert Mixers"))
406 this->mwindow = mwindow;
410 AssetPopupInsertMixer::~AssetPopupInsertMixer()
414 int AssetPopupInsertMixer::handle_event()
416 mwindow->gui->lock_window("AssetPopupInsertMixer::handle_event");
417 mwindow->create_mixers(-1);
418 mwindow->gui->unlock_window();
422 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
423 : BC_MenuItem(C_("Paste"))
425 this->mwindow = mwindow;
429 AssetPopupPaste::~AssetPopupPaste()
433 int AssetPopupPaste::handle_event()
435 popup->paste_assets();
440 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
441 : BC_MenuItem(_("Match project size"))
443 this->mwindow = mwindow;
447 int AssetMatchSize::handle_event()
453 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
454 : BC_MenuItem(_("Match frame rate"))
456 this->mwindow = mwindow;
460 int AssetMatchRate::handle_event()
466 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
467 : BC_MenuItem(_("Match all"))
469 this->mwindow = mwindow;
473 int AssetMatchAll::handle_event()
480 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
481 : BC_MenuItem(_("Remove from project"))
483 this->mwindow = mwindow;
487 AssetPopupProjectRemove::~AssetPopupProjectRemove()
491 int AssetPopupProjectRemove::handle_event()
493 popup->gui->unlock_window();
494 mwindow->remove_assets_from_project(1, 1, 1,
495 mwindow->session->drag_assets, 0);
496 popup->gui->lock_window("AssetPopupProjectRemove::handle_event");
501 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
502 : BC_MenuItem(_("Remove from disk"))
504 this->mwindow = mwindow;
509 AssetPopupDiskRemove::~AssetPopupDiskRemove()
513 int AssetPopupDiskRemove::handle_event()
515 mwindow->awindow->asset_remove->start();
520 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
521 : BC_PopupMenu(0, 0, 0, "", 0)
523 this->mwindow = mwindow;
527 AssetListMenu::~AssetListMenu()
531 void AssetListMenu::create_objects()
533 add_item(load_file = new AssetPopupLoadFile(mwindow, gui));
534 add_item(format = new AWindowListFormat(mwindow, gui));
535 add_item(close_edl = new AssetPopupCloseEDL(mwindow, gui));
536 add_item(select_used = new AssetSelectUsed(mwindow, gui));
538 select_used->add_submenu(submenu = new BC_SubMenu());
539 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("All"), SELECT_ALL));
540 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("Used"), SELECT_USED));
541 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("Unused"), SELECT_UNUSED));
542 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("None"), SELECT_NONE));
543 add_item(new AWindowListSort(mwindow, gui));
544 add_item(new AssetListCopy(mwindow, gui));
545 add_item(new AssetListPaste(mwindow, gui));
546 SnapshotSubMenu *snapshot_submenu;
547 add_item(asset_snapshot = new AssetSnapshot(mwindow, this));
548 asset_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(asset_snapshot));
549 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"), SNAPSHOT_PNG));
550 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
551 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
552 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("ppm"), SNAPSHOT_PPM));
553 GrabshotSubMenu *grabshot_submenu;
554 add_item(asset_grabshot = new AssetGrabshot(mwindow, this));
555 asset_grabshot->add_submenu(grabshot_submenu = new GrabshotSubMenu(asset_grabshot));
556 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("png"), GRABSHOT_PNG));
557 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("jpeg"), GRABSHOT_JPEG));
558 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("tiff"), GRABSHOT_TIFF));
559 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("ppm"), GRABSHOT_PPM));
563 AssetPopupLoadFile::AssetPopupLoadFile(MWindow *mwindow, AWindowGUI *gui)
564 : BC_MenuItem(_("Load files..."), "o", 'o')
566 this->mwindow = mwindow;
570 AssetPopupLoadFile::~AssetPopupLoadFile()
574 int AssetPopupLoadFile::handle_event()
576 mwindow->gui->mainmenu->load_file->thread->start();
580 void AssetListMenu::update_titles(int shots)
583 int enable_close = mwindow->stack.size() > 0 ? 1 : 0;
584 close_edl->set_enabled(enable_close);
585 asset_snapshot->set_enabled(shots);
586 asset_grabshot->set_enabled(shots);
589 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
590 : BC_MenuItem(_("Copy file list"))
592 this->mwindow = mwindow;
596 AssetListCopy::~AssetListCopy()
601 int AssetListCopy::handle_event()
604 MWindowGUI *gui = mwindow->gui;
605 gui->lock_window("AssetListCopy::handle_event");
606 mwindow->awindow->gui->collect_assets();
607 int n = mwindow->session->drag_assets->total;
608 for( int i=0; i<n; ++i ) {
609 Indexable *indexable = mwindow->session->drag_assets->values[i];
610 const char *path = indexable->path;
611 if( !*path ) continue;
612 len += strlen(path) + 1;
614 char *text = new char[len+1], *cp = text;
615 for( int i=0; i<n; ++i ) {
616 Indexable *indexable = mwindow->session->drag_assets->values[i];
617 const char *path = indexable->path;
618 if( !*path ) continue;
619 cp += sprintf(cp, "%s\n", path);
623 gui->get_abs_cursor(cur_x, cur_y, 0);
624 gui->unlock_window();
628 copy_dialog = new AssetCopyDialog(this);
629 copy_dialog->start(text, cur_x, cur_y);
632 eprintf(_("Nothing selected"));
638 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
645 void AssetCopyDialog::start(char *text, int x, int y)
649 this->x = x; this->y = y;
650 BC_DialogThread::start();
653 AssetCopyDialog::~AssetCopyDialog()
658 BC_Window* AssetCopyDialog::new_gui()
660 BC_DisplayInfo display_info;
662 copy_window = new AssetCopyWindow(this);
663 copy_window->create_objects();
667 void AssetCopyDialog::handle_done_event(int result)
669 delete [] text; text = 0;
672 void AssetCopyDialog::handle_close_event(int result)
677 #define ACW_W xS(500)
678 #define ACW_H yS(200)
680 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
681 : BC_Window(_(PROGRAM_NAME ": Copy File List"),
682 copy_dialog->x - ACW_W/2, copy_dialog->y - ACW_H/2,
683 ACW_W, ACW_H, ACW_W, ACW_H, 1, 0, 1)
685 this->copy_dialog = copy_dialog;
688 AssetCopyWindow::~AssetCopyWindow()
692 void AssetCopyWindow::create_objects()
694 lock_window("AssetCopyWindow::create_objects");
697 int ys5 = yS(5), ys10 = yS(10);
698 int x = xs10, y = ys10;
699 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
700 y += title->get_h() + ys5;
701 int text_w = get_w() - x - 10;
702 int text_h = get_h() - y - BC_OKButton::calculate_h() - ys5;
703 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
704 char *text = copy_dialog->text;
705 int len = strlen(text) + BCTEXTLEN;
706 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
707 file_list->create_objects();
709 add_subwindow(new BC_OKButton(this));
714 int AssetCopyWindow::resize_event(int w, int h)
716 int fx = file_list->get_x(), fy = file_list->get_y();
717 int text_w = w - fx - xS(10);
718 int text_h = h - fy - BC_OKButton::calculate_h() - yS(5);
719 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
720 file_list->reposition_window(fx, fy, text_w, text_rows);
724 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
725 : BC_MenuItem(_("Paste file list"))
727 this->mwindow = mwindow;
731 AssetListPaste::~AssetListPaste()
736 int AssetListPaste::handle_event()
739 paste_dialog = new AssetPasteDialog(this);
741 paste_dialog->close_window();
743 gui->get_abs_cursor(cur_x, cur_y, 0);
744 paste_dialog->start(cur_x, cur_y);
748 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
755 AssetPasteDialog::~AssetPasteDialog()
760 BC_Window* AssetPasteDialog::new_gui()
762 paste_window = new AssetPasteWindow(this);
763 paste_window->create_objects();
767 void AssetPasteDialog::handle_done_event(int result)
770 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
771 ArrayList<char*> path_list;
772 path_list.set_array_delete();
774 for( const char *cp=bp; cp<ep && *cp; ) {
775 const char *dp = strchr(cp, '\n');
777 char path[BCTEXTLEN], *pp = path;
778 int len = sizeof(path)-1;
779 while( --len>0 && cp<dp ) *pp++ = *cp++;
782 if( !strlen(path) ) continue;
783 path_list.append(cstrdup(path));
785 if( !path_list.size() ) return;
787 MWindow *mwindow = paste->mwindow;
788 mwindow->interrupt_indexes();
789 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
790 result = mwindow->load_filenames(&path_list,
791 LOADMODE_RESOURCESONLY, LOADMODE_EDL_CLIP, 0);
792 mwindow->gui->unlock_window();
793 path_list.remove_all_objects();
794 mwindow->save_backup();
795 mwindow->restart_brender();
796 mwindow->session->changes_made = 1;
799 void AssetPasteDialog::handle_close_event(int result)
804 void AssetPasteDialog::start(int x, int y)
806 this->x = x; this->y = y;
807 BC_DialogThread::start();
810 #define APW_W xS(500)
811 #define APW_H yS(200)
813 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
814 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
815 paste_dialog->x - APW_W/2, paste_dialog->y - APW_H/2,
816 APW_W, APW_H, APW_W, APW_H, 1, 0, 1)
818 this->paste_dialog = paste_dialog;
821 AssetPasteWindow::~AssetPasteWindow()
825 void AssetPasteWindow::create_objects()
827 lock_window("AssetPasteWindow::create_objects()");
830 int ys5 = yS(5), ys10 = yS(10);
831 int x = xs10, y = ys10;
832 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
833 y += title->get_h() + ys5;
834 int text_w = get_w() - x - xs10;
835 int text_h = get_h() - y - BC_OKButton::calculate_h() - ys5;
836 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
837 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
838 file_list->create_objects();
839 add_subwindow(new BC_OKButton(this));
840 add_subwindow(new BC_CancelButton(this));
845 int AssetPasteWindow::resize_event(int w, int h)
847 int fx = file_list->get_x(), fy = file_list->get_y();
848 int text_w = w - fx - xS(10);
849 int text_h = h - fy - BC_OKButton::calculate_h() - yS(5);
850 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
851 file_list->reposition_window(fx, fy, text_w, text_rows);
857 AssetSnapshot::AssetSnapshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
858 : BC_MenuItem(_("Snapshot..."))
860 this->mwindow = mwindow;
861 this->asset_list_menu = asset_list_menu;
864 AssetSnapshot::~AssetSnapshot()
868 SnapshotSubMenu::SnapshotSubMenu(AssetSnapshot *asset_snapshot)
870 this->asset_snapshot = asset_snapshot;
873 SnapshotSubMenu::~SnapshotSubMenu()
877 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
880 this->submenu = submenu;
884 SnapshotMenuItem::~SnapshotMenuItem()
888 int SnapshotMenuItem::handle_event()
890 MWindow *mwindow = submenu->asset_snapshot->mwindow;
891 EDL *edl = mwindow->edl;
892 if( !edl->have_video() ) return 1;
894 Preferences *preferences = mwindow->preferences;
895 char filename[BCTEXTLEN], snapshot_path[BCTEXTLEN];
896 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
897 time_t tt; time(&tt);
898 struct tm tm; localtime_r(&tt,&tm);
899 File::getenv_path(snapshot_path, preferences->snapshot_path);
900 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
901 snapshot_path, _("snap"),
902 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
903 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
904 char *asset_path = FileSystem::basepath(filename);
905 Asset *asset = new Asset(asset_path);
906 delete [] asset_path;
908 int fw = edl->get_w(), fh = edl->get_h();
909 int fcolor_model = edl->session->color_model;
913 asset->format = FILE_PNG;
914 asset->png_use_alpha = 1;
917 asset->format = FILE_JPEG;
918 asset->jpeg_quality = 90;
921 asset->format = FILE_TIFF;
922 asset->tiff_cmodel = 0;
923 asset->tiff_compression = 0;
926 asset->format = FILE_PPM;
931 asset->audio_data = 0;
932 asset->video_data = 1;
933 asset->video_length = 1;
937 int processors = preferences->project_smp + 1;
938 if( processors > 8 ) processors = 8;
939 file.set_processors(processors);
940 int ret = file.open_file(preferences, asset, 0, 1);
942 file.start_video_thread(1, fcolor_model,
943 processors > 1 ? 2 : 1, 0);
944 VFrame ***frames = file.get_video_buffer();
945 VFrame *frame = frames[0][0];
946 TransportCommand command;
947 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
948 command.command = CURRENT_FRAME;
949 command.get_edl()->copy_all(edl);
950 command.change_type = CHANGE_ALL;
951 command.realtime = 0;
953 RenderEngine render_engine(0, preferences, 0, 0);
954 CICache video_cache(preferences);
955 render_engine.set_vcache(&video_cache);
956 render_engine.arm_command(&command);
958 double position = edl->local_session->get_selectionstart(1);
959 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
960 ret = !render_engine.vrender ? 1 :
961 render_engine.vrender->process_buffer(frame, source_position, 0);
963 ret = file.write_video_buffer(1);
967 asset->folder_no = AW_MEDIA_FOLDER;
968 mwindow->edl->assets->append(asset);
969 mwindow->awindow->gui->async_update_assets();
972 eprintf(_("snapshot render failed"));
973 asset->remove_user();
979 AssetGrabshot::AssetGrabshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
980 : BC_MenuItem(_("Grabshot..."))
982 this->mwindow = mwindow;
983 this->asset_list_menu = asset_list_menu;
986 AssetGrabshot::~AssetGrabshot()
990 GrabshotSubMenu::GrabshotSubMenu(AssetGrabshot *asset_grabshot)
992 this->asset_grabshot = asset_grabshot;
995 GrabshotSubMenu::~GrabshotSubMenu()
999 GrabshotMenuItem::GrabshotMenuItem(GrabshotSubMenu *submenu, const char *text, int mode)
1002 this->submenu = submenu;
1007 GrabshotMenuItem::~GrabshotMenuItem()
1012 int GrabshotMenuItem::handle_event()
1015 grab_thread = new GrabshotThread(submenu->asset_grabshot->mwindow);
1016 if( !grab_thread->running() )
1017 grab_thread->start(this);
1021 GrabshotThread::GrabshotThread(MWindow *mwindow)
1024 this->mwindow = mwindow;
1028 GrabshotThread::~GrabshotThread()
1033 void GrabshotThread::start(GrabshotMenuItem *menu_item)
1035 popup = new GrabshotPopup(this, menu_item->mode);
1036 popup->lock_window("GrabshotThread::start");
1037 for( int i=0; i<4; ++i )
1038 edge[i] = new BC_Popup(mwindow->gui, 0,0, 1,1, ORANGE, 1);
1039 mwindow->gui->grab_buttons();
1040 mwindow->gui->grab_cursor();
1041 popup->grab(mwindow->gui);
1042 popup->create_objects();
1043 popup->show_window();
1044 popup->unlock_window();
1049 void GrabshotThread::run()
1051 popup->lock_window("GrabshotThread::run 0");
1054 popup->unlock_window();
1058 popup->lock_window("GrabshotThread::run 1");
1060 mwindow->gui->ungrab_cursor();
1061 mwindow->gui->ungrab_buttons();
1062 popup->ungrab(mwindow->gui);
1063 for( int i=0; i<4; ++i ) delete edge[i];
1064 popup->unlock_window();
1065 delete popup; popup = 0;
1068 GrabshotPopup::GrabshotPopup(GrabshotThread *grab_thread, int mode)
1069 : BC_Popup(grab_thread->mwindow->gui, 0,0, 16,16, -1,1)
1071 this->grab_thread = grab_thread;
1074 grab_color = ORANGE;
1075 x0 = y0 = x1 = y1 = -1;
1076 lx0 = ly0 = lx1 = ly1 = -1;
1078 GrabshotPopup::~GrabshotPopup()
1082 int GrabshotPopup::grab_event(XEvent *event)
1084 int cur_drag = dragging;
1085 switch( event->type ) {
1087 if( cur_drag > 0 ) return 1;
1088 x0 = event->xbutton.x_root;
1089 y0 = event->xbutton.y_root;
1092 if( event->xbutton.button == RIGHT_BUTTON ) break;
1093 if( x0>=get_x() && x0<get_x()+get_w() &&
1094 y0>=get_y() && y0<get_y()+get_h() ) break;
1103 if( cur_drag > 0 ) {
1104 x1 = event->xbutton.x_root;
1105 y1 = event->xbutton.y_root;
1113 int cx = lx0, cy = ly0;
1114 int cw = lx1-lx0, ch = ly1-ly0;
1117 grab_thread->done = 1;
1119 MWindow *mwindow = grab_thread->mwindow;
1120 Preferences *preferences = mwindow->preferences;
1121 char filename[BCTEXTLEN], snapshot_path[BCTEXTLEN];
1122 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
1123 time_t tt; time(&tt);
1124 struct tm tm; localtime_r(&tt,&tm);
1125 File::getenv_path(snapshot_path, preferences->snapshot_path);
1126 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
1127 snapshot_path, _("grab"),
1128 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
1129 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
1130 char *asset_path = FileSystem::basepath(filename);
1131 Asset *asset = new Asset(asset_path);
1132 delete [] asset_path;
1135 asset->format = FILE_PNG;
1136 asset->png_use_alpha = 1;
1139 asset->format = FILE_JPEG;
1140 asset->jpeg_quality = 90;
1143 asset->format = FILE_TIFF;
1144 asset->tiff_cmodel = 0;
1145 asset->tiff_compression = 0;
1148 asset->format = FILE_PPM;
1152 // no odd dimensions
1153 int rw = get_root_w(0), rh = get_root_h(0);
1154 if( cx < 0 ) { cw += cx; cx = 0; }
1155 if( cy < 0 ) { ch += cy; cy = 0; }
1156 if( cx+cw > rw ) cw = rw-cx;
1157 if( cy+ch > rh ) ch = rh-cy;
1158 if( !cw || !ch ) return 1;
1160 VFrame vframe(cw,ch, BC_RGB888);
1161 if( cx+cw < rw ) ++cw;
1162 if( cy+ch < rh ) ++ch;
1163 BC_Capture capture_bitmap(cw,ch, 0);
1164 capture_bitmap.capture_frame(&vframe, cx,cy);
1166 asset->width = vframe.get_w();
1167 asset->height = vframe.get_h();
1168 asset->audio_data = 0;
1169 asset->video_data = 1;
1170 asset->video_length = 1;
1174 int fcolor_model = mwindow->edl->session->color_model;
1175 int processors = preferences->project_smp + 1;
1176 if( processors > 8 ) processors = 8;
1177 file.set_processors(processors);
1178 int ret = file.open_file(preferences, asset, 0, 1);
1180 file.start_video_thread(1, fcolor_model,
1181 processors > 1 ? 2 : 1, 0);
1182 VFrame ***frames = file.get_video_buffer();
1183 VFrame *frame = frames[0][0];
1184 frame->transfer_from(&vframe);
1185 ret = file.write_video_buffer(1);
1189 asset->folder_no = AW_MEDIA_FOLDER;
1190 mwindow->edl->assets->append(asset);
1191 mwindow->awindow->gui->async_update_assets();
1194 eprintf(_("grabshot render failed"));
1195 asset->remove_user();
1201 void GrabshotPopup::update()
1203 set_color(grab_color ^= GREEN);
1204 draw_box(0,0, get_w(),get_h());
1208 void GrabshotPopup::draw_selection(int show)
1211 for( int i=0; i<4; ++i ) hide_window(0);
1216 int nx0 = x0 < x1 ? x0 : x1;
1217 int nx1 = x0 < x1 ? x1 : x0;
1218 int ny0 = y0 < y1 ? y0 : y1;
1219 int ny1 = y0 < y1 ? y1 : y0;
1220 lx0 = nx0; lx1 = nx1; ly0 = ny0; ly1 = ny1;
1223 BC_Popup **edge = grab_thread->edge;
1224 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
1225 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
1226 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
1227 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
1230 for( int i=0; i<4; ++i ) edge[i]->show_window(0);