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(new AssetPopupSort(mwindow, this));
80 add_item(index = new AssetPopupBuildIndex(mwindow, this));
81 add_item(view = new AssetPopupView(mwindow, this));
82 add_item(view_window = new AssetPopupViewWindow(mwindow, this));
83 add_item(mixer = new AssetPopupMixer(mwindow, this));
84 add_item(new AssetPopupPaste(mwindow, this));
85 add_item(menu_item = new BC_MenuItem(_("Match...")));
86 menu_item->add_submenu(submenu = new BC_SubMenu());
87 submenu->add_submenuitem(new AssetMatchSize(mwindow, this));
88 submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
89 submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
90 add_item(menu_item = new BC_MenuItem(_("Remove...")));
91 menu_item->add_submenu(submenu = new BC_SubMenu());
92 submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
93 submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
96 void AssetPopup::paste_assets()
98 // Collect items into the drag vectors for temporary storage
99 gui->lock_window("AssetPopup::paste_assets");
100 mwindow->gui->lock_window("AssetPopup::paste_assets");
101 mwindow->cwindow->gui->lock_window("AssetPopup::paste_assets");
103 int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
104 gui->collect_assets(proxy);
105 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
106 mwindow->edl->tracks->first, 0); // do not overwrite
108 gui->unlock_window();
109 mwindow->gui->unlock_window();
110 mwindow->cwindow->gui->unlock_window();
113 void AssetPopup::match_size()
115 // Collect items into the drag vectors for temporary storage
116 gui->collect_assets();
117 mwindow->gui->lock_window("AssetPopup::match_size");
118 mwindow->asset_to_size();
119 mwindow->gui->unlock_window();
122 void AssetPopup::match_rate()
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_rate();
128 mwindow->gui->unlock_window();
131 void AssetPopup::match_all()
133 // Collect items into the drag vectors for temporary storage
134 gui->collect_assets();
135 mwindow->gui->lock_window("AssetPopup::match_rate");
136 mwindow->asset_to_all();
137 mwindow->gui->unlock_window();
140 int AssetPopup::update()
143 int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
144 gui->collect_assets(proxy);
149 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
150 : BC_MenuItem(_("Info..."))
152 this->mwindow = mwindow;
156 AssetPopupInfo::~AssetPopupInfo()
160 int AssetPopupInfo::handle_event()
163 popup->gui->get_abs_cursor(cur_x, cur_y);
164 int n = mwindow->session->drag_assets->size();
166 for( int i=0; i<n; ++i ) {
167 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
168 asset_edit->edit_asset(
169 mwindow->session->drag_assets->values[i], cur_x-30*i, cur_y-30*i);
172 else if( mwindow->session->drag_clips->size() ) {
173 popup->gui->awindow->clip_edit->edit_clip(
174 mwindow->session->drag_clips->values[0], cur_x, cur_y);
180 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
181 : BC_MenuItem(_("Rebuild index"))
183 this->mwindow = mwindow;
187 AssetPopupBuildIndex::~AssetPopupBuildIndex()
191 int AssetPopupBuildIndex::handle_event()
193 //printf("AssetPopupBuildIndex::handle_event 1\n");
194 mwindow->rebuild_indices();
199 AssetPopupSort::AssetPopupSort(MWindow *mwindow, AssetPopup *popup)
200 : BC_MenuItem(_("Sort"))
202 this->mwindow = mwindow;
206 AssetPopupSort::~AssetPopupSort()
210 int AssetPopupSort::handle_event()
212 mwindow->awindow->gui->sort_assets();
217 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
218 : BC_MenuItem(_("View"))
220 this->mwindow = mwindow;
224 AssetPopupView::~AssetPopupView()
228 int AssetPopupView::handle_event()
230 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
232 if( mwindow->session->drag_assets->total )
233 vwindow->change_source(
234 mwindow->session->drag_assets->values[0]);
236 if( mwindow->session->drag_clips->total )
237 vwindow->change_source(
238 mwindow->session->drag_clips->values[0]);
244 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
245 : BC_MenuItem(_("View in new window"))
247 this->mwindow = mwindow;
251 AssetPopupViewWindow::~AssetPopupViewWindow()
255 int AssetPopupViewWindow::handle_event()
257 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
258 VWindow *vwindow = mwindow->get_viewer(1);
259 vwindow->gui->lock_window("AssetPopupView::handle_event 1");
260 vwindow->change_source(mwindow->session->drag_assets->get(i));
261 vwindow->gui->unlock_window();
263 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
264 VWindow *vwindow = mwindow->get_viewer(1);
265 vwindow->gui->lock_window("AssetPopupView::handle_event 2");
266 vwindow->change_source(mwindow->session->drag_clips->get(i));
267 vwindow->gui->unlock_window();
272 AssetPopupMixer::AssetPopupMixer(MWindow *mwindow, AssetPopup *popup)
273 : BC_MenuItem(_("Open Mixers"))
275 this->mwindow = mwindow;
279 AssetPopupMixer::~AssetPopupMixer()
283 int AssetPopupMixer::handle_event()
285 mwindow->gui->lock_window("AssetPopupMixer::handle_event");
286 mwindow->create_mixers();
287 mwindow->gui->unlock_window();
291 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
292 : BC_MenuItem(_("Paste"))
294 this->mwindow = mwindow;
298 AssetPopupPaste::~AssetPopupPaste()
302 int AssetPopupPaste::handle_event()
304 popup->paste_assets();
309 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
310 : BC_MenuItem(_("Match project size"))
312 this->mwindow = mwindow;
316 int AssetMatchSize::handle_event()
322 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
323 : BC_MenuItem(_("Match frame rate"))
325 this->mwindow = mwindow;
329 int AssetMatchRate::handle_event()
335 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
336 : BC_MenuItem(_("Match all"))
338 this->mwindow = mwindow;
342 int AssetMatchAll::handle_event()
349 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
350 : BC_MenuItem(_("Remove from project"))
352 this->mwindow = mwindow;
356 AssetPopupProjectRemove::~AssetPopupProjectRemove()
360 int AssetPopupProjectRemove::handle_event()
362 popup->gui->unlock_window();
363 mwindow->remove_assets_from_project(1, 1,
364 mwindow->session->drag_assets,
365 mwindow->session->drag_clips);
366 popup->gui->lock_window("AssetPopupProjectRemove::handle_event");
371 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
372 : BC_MenuItem(_("Remove from disk"))
374 this->mwindow = mwindow;
379 AssetPopupDiskRemove::~AssetPopupDiskRemove()
383 int AssetPopupDiskRemove::handle_event()
385 mwindow->awindow->asset_remove->start();
390 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
391 : BC_PopupMenu(0, 0, 0, "", 0)
393 this->mwindow = mwindow;
397 AssetListMenu::~AssetListMenu()
399 if( !shots_displayed ) {
400 delete asset_snapshot;
401 delete asset_grabshot;
405 void AssetListMenu::create_objects()
407 add_item(load_file = new AssetPopupLoadFile(mwindow, gui));
408 add_item(format = new AWindowListFormat(mwindow, gui));
409 add_item(select_used = new AssetSelectUsed(mwindow, gui));
411 select_used->add_submenu(submenu = new BC_SubMenu());
412 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("All"), SELECT_ALL));
413 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("Used"), SELECT_USED));
414 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("Unused"), SELECT_UNUSED));
415 submenu->add_submenuitem(new AssetSelectUsedItem(select_used, _("None"), SELECT_NONE));
416 add_item(new AWindowListSort(mwindow, gui));
417 add_item(new AssetListCopy(mwindow, gui));
418 add_item(new AssetListPaste(mwindow, gui));
419 SnapshotSubMenu *snapshot_submenu;
420 add_item(asset_snapshot = new AssetSnapshot(mwindow, this));
421 asset_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(asset_snapshot));
422 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"), SNAPSHOT_PNG));
423 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
424 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
425 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("ppm"), SNAPSHOT_PPM));
426 GrabshotSubMenu *grabshot_submenu;
427 add_item(asset_grabshot = new AssetGrabshot(mwindow, this));
428 asset_grabshot->add_submenu(grabshot_submenu = new GrabshotSubMenu(asset_grabshot));
429 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("png"), GRABSHOT_PNG));
430 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("jpeg"), GRABSHOT_JPEG));
431 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("tiff"), GRABSHOT_TIFF));
432 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("ppm"), GRABSHOT_PPM));
433 update_titles(shots_displayed = 1);
436 AssetPopupLoadFile::AssetPopupLoadFile(MWindow *mwindow, AWindowGUI *gui)
437 : BC_MenuItem(_("Load files..."), "o", 'o')
439 this->mwindow = mwindow;
443 AssetPopupLoadFile::~AssetPopupLoadFile()
447 int AssetPopupLoadFile::handle_event()
449 mwindow->gui->mainmenu->load_file->thread->start();
453 void AssetListMenu::update_titles(int shots)
456 if( shots && !shots_displayed ) {
458 add_item(asset_snapshot);
459 add_item(asset_grabshot);
461 else if( !shots && shots_displayed ) {
463 remove_item(asset_snapshot);
464 remove_item(asset_grabshot);
468 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
469 : BC_MenuItem(_("Copy file list"))
471 this->mwindow = mwindow;
475 AssetListCopy::~AssetListCopy()
480 int AssetListCopy::handle_event()
483 MWindowGUI *gui = mwindow->gui;
484 gui->lock_window("AssetListCopy::handle_event");
485 mwindow->awindow->gui->collect_assets();
486 int n = mwindow->session->drag_assets->total;
487 for( int i=0; i<n; ++i ) {
488 Indexable *indexable = mwindow->session->drag_assets->values[i];
489 const char *path = indexable->path;
490 if( !*path ) continue;
491 len += strlen(path) + 1;
493 char *text = new char[len+1], *cp = text;
494 for( int i=0; i<n; ++i ) {
495 Indexable *indexable = mwindow->session->drag_assets->values[i];
496 const char *path = indexable->path;
497 if( !*path ) continue;
498 cp += sprintf(cp, "%s\n", path);
502 gui->get_abs_cursor(cur_x, cur_y, 0);
503 gui->unlock_window();
507 copy_dialog = new AssetCopyDialog(this);
508 copy_dialog->start(text, cur_x, cur_y);
511 eprintf(_("Nothing selected"));
517 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
524 void AssetCopyDialog::start(char *text, int x, int y)
528 this->x = x; this->y = y;
529 BC_DialogThread::start();
532 AssetCopyDialog::~AssetCopyDialog()
537 BC_Window* AssetCopyDialog::new_gui()
539 BC_DisplayInfo display_info;
541 copy_window = new AssetCopyWindow(this);
542 copy_window->create_objects();
546 void AssetCopyDialog::handle_done_event(int result)
548 delete [] text; text = 0;
551 void AssetCopyDialog::handle_close_event(int result)
557 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
558 : BC_Window(_(PROGRAM_NAME ": Copy File List"),
559 copy_dialog->x - 500/2, copy_dialog->y - 200/2,
560 500, 200, 500, 200, 1, 0, 1)
562 this->copy_dialog = copy_dialog;
565 AssetCopyWindow::~AssetCopyWindow()
569 void AssetCopyWindow::create_objects()
571 lock_window("AssetCopyWindow::create_objects");
573 int x = 10, y = 10, pad = 5;
574 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
575 y += title->get_h() + pad;
576 int text_w = get_w() - x - 10;
577 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
578 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
579 char *text = copy_dialog->text;
580 int len = strlen(text) + BCTEXTLEN;
581 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
582 file_list->create_objects();
584 add_subwindow(new BC_OKButton(this));
589 int AssetCopyWindow::resize_event(int w, int h)
591 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
592 int text_w = w - fx - 10;
593 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
594 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
595 file_list->reposition_window(fx, fy, text_w, text_rows);
599 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
600 : BC_MenuItem(_("Paste file list"))
602 this->mwindow = mwindow;
606 AssetListPaste::~AssetListPaste()
611 int AssetListPaste::handle_event()
614 paste_dialog = new AssetPasteDialog(this);
616 paste_dialog->close_window();
618 gui->get_abs_cursor(cur_x, cur_y, 0);
619 paste_dialog->start(cur_x, cur_y);
623 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
630 AssetPasteDialog::~AssetPasteDialog()
635 BC_Window* AssetPasteDialog::new_gui()
637 paste_window = new AssetPasteWindow(this);
638 paste_window->create_objects();
642 void AssetPasteDialog::handle_done_event(int result)
645 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
646 ArrayList<char*> path_list;
647 path_list.set_array_delete();
649 for( const char *cp=bp; cp<ep && *cp; ) {
650 const char *dp = strchr(cp, '\n');
652 char path[BCTEXTLEN], *pp = path;
653 int len = sizeof(path)-1;
654 while( --len>0 && cp<dp ) *pp++ = *cp++;
657 if( !strlen(path) ) continue;
658 path_list.append(cstrdup(path));
660 if( !path_list.size() ) return;
662 MWindow *mwindow = paste->mwindow;
663 mwindow->interrupt_indexes();
664 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
665 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
666 mwindow->gui->unlock_window();
667 path_list.remove_all_objects();
668 mwindow->save_backup();
669 mwindow->restart_brender();
670 mwindow->session->changes_made = 1;
673 void AssetPasteDialog::handle_close_event(int result)
678 void AssetPasteDialog::start(int x, int y)
680 this->x = x; this->y = y;
681 BC_DialogThread::start();
684 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
685 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
686 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
687 500, 200, 500, 200, 1, 0, 1)
689 this->paste_dialog = paste_dialog;
692 AssetPasteWindow::~AssetPasteWindow()
696 void AssetPasteWindow::create_objects()
698 lock_window("AssetPasteWindow::create_objects()");
700 int x = 10, y = 10, pad = 5;
701 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
702 y += title->get_h() + pad;
703 int text_w = get_w() - x - 10;
704 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
705 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
706 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
707 file_list->create_objects();
708 add_subwindow(new BC_OKButton(this));
709 add_subwindow(new BC_CancelButton(this));
714 int AssetPasteWindow::resize_event(int w, int h)
716 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
717 int text_w = w - fx - 10;
718 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
719 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
720 file_list->reposition_window(fx, fy, text_w, text_rows);
726 AssetSnapshot::AssetSnapshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
727 : BC_MenuItem(_("Snapshot..."))
729 this->mwindow = mwindow;
730 this->asset_list_menu = asset_list_menu;
733 AssetSnapshot::~AssetSnapshot()
737 SnapshotSubMenu::SnapshotSubMenu(AssetSnapshot *asset_snapshot)
739 this->asset_snapshot = asset_snapshot;
742 SnapshotSubMenu::~SnapshotSubMenu()
746 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
749 this->submenu = submenu;
753 SnapshotMenuItem::~SnapshotMenuItem()
757 int SnapshotMenuItem::handle_event()
759 MWindow *mwindow = submenu->asset_snapshot->mwindow;
760 EDL *edl = mwindow->edl;
761 if( !edl->have_video() ) return 1;
763 Preferences *preferences = mwindow->preferences;
764 char filename[BCTEXTLEN];
765 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
766 time_t tt; time(&tt);
767 struct tm tm; localtime_r(&tt,&tm);
768 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
769 preferences->snapshot_path, _("snap"),
770 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
771 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
772 char *asset_path = FileSystem::basepath(filename);
773 Asset *asset = new Asset(asset_path);
774 delete [] asset_path;
776 int fw = edl->get_w(), fh = edl->get_h();
777 int fcolor_model = edl->session->color_model;
781 asset->format = FILE_PNG;
782 asset->png_use_alpha = 1;
785 asset->format = FILE_JPEG;
786 asset->jpeg_quality = 90;
789 asset->format = FILE_TIFF;
790 asset->tiff_cmodel = 0;
791 asset->tiff_compression = 0;
794 asset->format = FILE_PPM;
799 asset->audio_data = 0;
800 asset->video_data = 1;
801 asset->video_length = 1;
805 int processors = preferences->project_smp + 1;
806 if( processors > 8 ) processors = 8;
807 file.set_processors(processors);
808 int ret = file.open_file(preferences, asset, 0, 1);
810 file.start_video_thread(1, fcolor_model,
811 processors > 1 ? 2 : 1, 0);
812 VFrame ***frames = file.get_video_buffer();
813 VFrame *frame = frames[0][0];
814 TransportCommand command;
815 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
816 command.command = CURRENT_FRAME;
817 command.get_edl()->copy_all(edl);
818 command.change_type = CHANGE_ALL;
819 command.realtime = 0;
821 RenderEngine render_engine(0, preferences, 0, 0);
822 CICache video_cache(preferences);
823 render_engine.set_vcache(&video_cache);
824 render_engine.arm_command(&command);
826 double position = edl->local_session->get_selectionstart(1);
827 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
828 ret = !render_engine.vrender ? 1 :
829 render_engine.vrender->process_buffer(frame, source_position, 0);
831 ret = file.write_video_buffer(1);
835 asset->folder_no = AW_MEDIA_FOLDER;
836 mwindow->edl->assets->append(asset);
837 mwindow->awindow->gui->async_update_assets();
840 eprintf(_("snapshot render failed"));
841 asset->remove_user();
847 AssetGrabshot::AssetGrabshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
848 : BC_MenuItem(_("Grabshot..."))
850 this->mwindow = mwindow;
851 this->asset_list_menu = asset_list_menu;
854 AssetGrabshot::~AssetGrabshot()
858 GrabshotSubMenu::GrabshotSubMenu(AssetGrabshot *asset_grabshot)
860 this->asset_grabshot = asset_grabshot;
863 GrabshotSubMenu::~GrabshotSubMenu()
867 GrabshotMenuItem::GrabshotMenuItem(GrabshotSubMenu *submenu, const char *text, int mode)
870 this->submenu = submenu;
875 GrabshotMenuItem::~GrabshotMenuItem()
880 int GrabshotMenuItem::handle_event()
883 grab_thread = new GrabshotThread(submenu->asset_grabshot->mwindow);
884 if( !grab_thread->running() )
885 grab_thread->start(this);
889 GrabshotThread::GrabshotThread(MWindow *mwindow)
892 this->mwindow = mwindow;
896 GrabshotThread::~GrabshotThread()
901 void GrabshotThread::start(GrabshotMenuItem *menu_item)
903 popup = new GrabshotPopup(this, menu_item->mode);
904 popup->lock_window("GrabshotThread::start");
905 for( int i=0; i<4; ++i )
906 edge[i] = new BC_Popup(mwindow->gui, 0,0, 1,1, ORANGE, 1);
907 mwindow->gui->grab_buttons();
908 mwindow->gui->grab_cursor();
909 popup->grab(mwindow->gui);
910 popup->create_objects();
911 popup->show_window();
912 popup->unlock_window();
917 void GrabshotThread::run()
919 popup->lock_window("GrabshotThread::run 0");
922 popup->unlock_window();
926 popup->lock_window("GrabshotThread::run 1");
928 mwindow->gui->ungrab_cursor();
929 mwindow->gui->ungrab_buttons();
930 popup->ungrab(mwindow->gui);
931 for( int i=0; i<4; ++i ) delete edge[i];
932 popup->unlock_window();
933 delete popup; popup = 0;
936 GrabshotPopup::GrabshotPopup(GrabshotThread *grab_thread, int mode)
937 : BC_Popup(grab_thread->mwindow->gui, 0,0, 16,16, -1,1)
939 this->grab_thread = grab_thread;
943 x0 = y0 = x1 = y1 = -1;
944 lx0 = ly0 = lx1 = ly1 = -1;
946 GrabshotPopup::~GrabshotPopup()
950 int GrabshotPopup::grab_event(XEvent *event)
952 int cur_drag = dragging;
953 switch( event->type ) {
955 if( cur_drag > 0 ) return 1;
956 x0 = event->xbutton.x_root;
957 y0 = event->xbutton.y_root;
960 if( event->xbutton.button == RIGHT_BUTTON ) break;
961 if( x0>=get_x() && x0<get_x()+get_w() &&
962 y0>=get_y() && y0<get_y()+get_h() ) break;
972 x1 = event->xbutton.x_root;
973 y1 = event->xbutton.y_root;
981 int cx = lx0, cy = ly0;
982 int cw = lx1-lx0, ch = ly1-ly0;
985 grab_thread->done = 1;
987 MWindow *mwindow = grab_thread->mwindow;
988 Preferences *preferences = mwindow->preferences;
989 char filename[BCTEXTLEN];
990 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
991 time_t tt; time(&tt);
992 struct tm tm; localtime_r(&tt,&tm);
993 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
994 preferences->snapshot_path, _("grab"),
995 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
996 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
997 char *asset_path = FileSystem::basepath(filename);
998 Asset *asset = new Asset(asset_path);
999 delete [] asset_path;
1002 asset->format = FILE_PNG;
1003 asset->png_use_alpha = 1;
1006 asset->format = FILE_JPEG;
1007 asset->jpeg_quality = 90;
1010 asset->format = FILE_TIFF;
1011 asset->tiff_cmodel = 0;
1012 asset->tiff_compression = 0;
1015 asset->format = FILE_PPM;
1019 // no odd dimensions
1020 int rw = get_root_w(0), rh = get_root_h(0);
1021 if( cx < 0 ) { cw += cx; cx = 0; }
1022 if( cy < 0 ) { ch += cy; cy = 0; }
1023 if( cx+cw > rw ) cw = rw-cx;
1024 if( cy+ch > rh ) ch = rh-cy;
1025 if( !cw || !ch ) return 1;
1027 VFrame vframe(cw,ch, BC_RGB888);
1028 if( cx+cw < rw ) ++cw;
1029 if( cy+ch < rh ) ++ch;
1030 BC_Capture capture_bitmap(cw,ch, 0);
1031 capture_bitmap.capture_frame(&vframe, cx,cy);
1033 asset->width = vframe.get_w();
1034 asset->height = vframe.get_h();
1035 asset->audio_data = 0;
1036 asset->video_data = 1;
1037 asset->video_length = 1;
1041 int fcolor_model = mwindow->edl->session->color_model;
1042 int processors = preferences->project_smp + 1;
1043 if( processors > 8 ) processors = 8;
1044 file.set_processors(processors);
1045 int ret = file.open_file(preferences, asset, 0, 1);
1047 file.start_video_thread(1, fcolor_model,
1048 processors > 1 ? 2 : 1, 0);
1049 VFrame ***frames = file.get_video_buffer();
1050 VFrame *frame = frames[0][0];
1051 frame->transfer_from(&vframe);
1052 ret = file.write_video_buffer(1);
1056 asset->folder_no = AW_MEDIA_FOLDER;
1057 mwindow->edl->assets->append(asset);
1058 mwindow->awindow->gui->async_update_assets();
1061 eprintf(_("grabshot render failed"));
1062 asset->remove_user();
1068 void GrabshotPopup::update()
1070 set_color(grab_color ^= GREEN);
1071 draw_box(0,0, get_w(),get_h());
1075 void GrabshotPopup::draw_selection(int show)
1078 for( int i=0; i<4; ++i ) hide_window(0);
1083 int nx0 = x0 < x1 ? x0 : x1;
1084 int nx1 = x0 < x1 ? x1 : x0;
1085 int ny0 = y0 < y1 ? y0 : y1;
1086 int ny1 = y0 < y1 ? y1 : y0;
1087 lx0 = nx0; lx1 = nx1; ly0 = ny0; ly1 = ny1;
1090 BC_Popup **edge = grab_thread->edge;
1091 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
1092 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
1093 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
1094 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
1097 for( int i=0; i<4; ++i ) edge[i]->show_window(0);