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 gui->collect_assets();
104 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
105 mwindow->edl->tracks->first, 0); // do not overwrite
107 gui->unlock_window();
108 mwindow->gui->unlock_window();
109 mwindow->cwindow->gui->unlock_window();
112 void AssetPopup::match_size()
114 // Collect items into the drag vectors for temporary storage
115 gui->collect_assets();
116 mwindow->gui->lock_window("AssetPopup::match_size");
117 mwindow->asset_to_size();
118 mwindow->gui->unlock_window();
121 void AssetPopup::match_rate()
123 // Collect items into the drag vectors for temporary storage
124 gui->collect_assets();
125 mwindow->gui->lock_window("AssetPopup::match_rate");
126 mwindow->asset_to_rate();
127 mwindow->gui->unlock_window();
130 void AssetPopup::match_all()
132 // Collect items into the drag vectors for temporary storage
133 gui->collect_assets();
134 mwindow->gui->lock_window("AssetPopup::match_rate");
135 mwindow->asset_to_all();
136 mwindow->gui->unlock_window();
139 int AssetPopup::update()
142 gui->collect_assets();
147 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
148 : BC_MenuItem(_("Info..."))
150 this->mwindow = mwindow;
154 AssetPopupInfo::~AssetPopupInfo()
158 int AssetPopupInfo::handle_event()
161 popup->gui->get_abs_cursor(cur_x, cur_y);
162 int n = mwindow->session->drag_assets->size();
164 for( int i=0; i<n; ++i ) {
165 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
166 asset_edit->edit_asset(
167 mwindow->session->drag_assets->values[i], cur_x-30*i, cur_y-30*i);
170 else if( mwindow->session->drag_clips->size() ) {
171 popup->gui->awindow->clip_edit->edit_clip(
172 mwindow->session->drag_clips->values[0], cur_x, cur_y);
178 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
179 : BC_MenuItem(_("Rebuild index"))
181 this->mwindow = mwindow;
185 AssetPopupBuildIndex::~AssetPopupBuildIndex()
189 int AssetPopupBuildIndex::handle_event()
191 //printf("AssetPopupBuildIndex::handle_event 1\n");
192 mwindow->rebuild_indices();
197 AssetPopupSort::AssetPopupSort(MWindow *mwindow, AssetPopup *popup)
198 : BC_MenuItem(_("Sort"))
200 this->mwindow = mwindow;
204 AssetPopupSort::~AssetPopupSort()
208 int AssetPopupSort::handle_event()
210 mwindow->awindow->gui->sort_assets();
215 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
216 : BC_MenuItem(_("View"))
218 this->mwindow = mwindow;
222 AssetPopupView::~AssetPopupView()
226 int AssetPopupView::handle_event()
228 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
230 if( mwindow->session->drag_assets->total )
231 vwindow->change_source(
232 mwindow->session->drag_assets->values[0]);
234 if( mwindow->session->drag_clips->total )
235 vwindow->change_source(
236 mwindow->session->drag_clips->values[0]);
242 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
243 : BC_MenuItem(_("View in new window"))
245 this->mwindow = mwindow;
249 AssetPopupViewWindow::~AssetPopupViewWindow()
253 int AssetPopupViewWindow::handle_event()
255 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
256 VWindow *vwindow = mwindow->get_viewer(1);
257 vwindow->gui->lock_window("AssetPopupView::handle_event 1");
258 vwindow->change_source(mwindow->session->drag_assets->get(i));
259 vwindow->gui->unlock_window();
261 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
262 VWindow *vwindow = mwindow->get_viewer(1);
263 vwindow->gui->lock_window("AssetPopupView::handle_event 2");
264 vwindow->change_source(mwindow->session->drag_clips->get(i));
265 vwindow->gui->unlock_window();
270 AssetPopupMixer::AssetPopupMixer(MWindow *mwindow, AssetPopup *popup)
271 : BC_MenuItem(_("Open Mixers"))
273 this->mwindow = mwindow;
277 AssetPopupMixer::~AssetPopupMixer()
281 int AssetPopupMixer::handle_event()
283 mwindow->gui->lock_window("AssetPopupMixer::handle_event");
284 mwindow->create_mixers();
285 mwindow->gui->unlock_window();
289 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
290 : BC_MenuItem(_("Paste"))
292 this->mwindow = mwindow;
296 AssetPopupPaste::~AssetPopupPaste()
300 int AssetPopupPaste::handle_event()
302 popup->paste_assets();
307 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
308 : BC_MenuItem(_("Match project size"))
310 this->mwindow = mwindow;
314 int AssetMatchSize::handle_event()
320 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
321 : BC_MenuItem(_("Match frame rate"))
323 this->mwindow = mwindow;
327 int AssetMatchRate::handle_event()
333 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
334 : BC_MenuItem(_("Match all"))
336 this->mwindow = mwindow;
340 int AssetMatchAll::handle_event()
347 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
348 : BC_MenuItem(_("Remove from project"))
350 this->mwindow = mwindow;
354 AssetPopupProjectRemove::~AssetPopupProjectRemove()
358 int AssetPopupProjectRemove::handle_event()
360 mwindow->remove_assets_from_project(1, 1,
361 mwindow->session->drag_assets,
362 mwindow->session->drag_clips);
367 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
368 : BC_MenuItem(_("Remove from disk"))
370 this->mwindow = mwindow;
375 AssetPopupDiskRemove::~AssetPopupDiskRemove()
379 int AssetPopupDiskRemove::handle_event()
381 mwindow->awindow->asset_remove->start();
386 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
387 : BC_PopupMenu(0, 0, 0, "", 0)
389 this->mwindow = mwindow;
393 AssetListMenu::~AssetListMenu()
395 if( !shots_displayed ) {
396 delete asset_snapshot;
397 delete asset_grabshot;
401 void AssetListMenu::create_objects()
403 add_item(load_file = new AssetPopupLoadFile(mwindow, gui));
404 add_item(format = new AWindowListFormat(mwindow, gui));
405 add_item(new AWindowListSort(mwindow, gui));
406 add_item(new AssetListCopy(mwindow, gui));
407 add_item(new AssetListPaste(mwindow, gui));
408 SnapshotSubMenu *snapshot_submenu;
409 add_item(asset_snapshot = new AssetSnapshot(mwindow, this));
410 asset_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(asset_snapshot));
411 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"), SNAPSHOT_PNG));
412 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
413 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
414 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("ppm"), SNAPSHOT_PPM));
415 GrabshotSubMenu *grabshot_submenu;
416 add_item(asset_grabshot = new AssetGrabshot(mwindow, this));
417 asset_grabshot->add_submenu(grabshot_submenu = new GrabshotSubMenu(asset_grabshot));
418 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("png"), GRABSHOT_PNG));
419 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("jpeg"), GRABSHOT_JPEG));
420 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("tiff"), GRABSHOT_TIFF));
421 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("ppm"), GRABSHOT_PPM));
422 update_titles(shots_displayed = 1);
425 AssetPopupLoadFile::AssetPopupLoadFile(MWindow *mwindow, AWindowGUI *gui)
426 : BC_MenuItem(_("Load files..."), "o", 'o')
428 this->mwindow = mwindow;
432 AssetPopupLoadFile::~AssetPopupLoadFile()
436 int AssetPopupLoadFile::handle_event()
438 mwindow->gui->mainmenu->load_file->thread->start();
442 void AssetListMenu::update_titles(int shots)
445 if( shots && !shots_displayed ) {
447 add_item(asset_snapshot);
448 add_item(asset_grabshot);
450 else if( !shots && shots_displayed ) {
452 remove_item(asset_snapshot);
453 remove_item(asset_grabshot);
457 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
458 : BC_MenuItem(_("Copy file list"))
460 this->mwindow = mwindow;
464 AssetListCopy::~AssetListCopy()
469 int AssetListCopy::handle_event()
472 MWindowGUI *gui = mwindow->gui;
473 gui->lock_window("AssetListCopy::handle_event");
474 mwindow->awindow->gui->collect_assets();
475 int n = mwindow->session->drag_assets->total;
476 for( int i=0; i<n; ++i ) {
477 Indexable *indexable = mwindow->session->drag_assets->values[i];
478 const char *path = indexable->path;
479 if( !*path ) continue;
480 len += strlen(path) + 1;
482 char *text = new char[len+1], *cp = text;
483 for( int i=0; i<n; ++i ) {
484 Indexable *indexable = mwindow->session->drag_assets->values[i];
485 const char *path = indexable->path;
486 if( !*path ) continue;
487 cp += sprintf(cp, "%s\n", path);
491 gui->get_abs_cursor(cur_x, cur_y, 0);
492 gui->unlock_window();
496 copy_dialog = new AssetCopyDialog(this);
497 copy_dialog->start(text, cur_x, cur_y);
500 eprintf(_("Nothing selected"));
506 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
513 void AssetCopyDialog::start(char *text, int x, int y)
517 this->x = x; this->y = y;
518 BC_DialogThread::start();
521 AssetCopyDialog::~AssetCopyDialog()
526 BC_Window* AssetCopyDialog::new_gui()
528 BC_DisplayInfo display_info;
530 copy_window = new AssetCopyWindow(this);
531 copy_window->create_objects();
535 void AssetCopyDialog::handle_done_event(int result)
537 delete [] text; text = 0;
540 void AssetCopyDialog::handle_close_event(int result)
546 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
547 : BC_Window(_(PROGRAM_NAME ": Copy File List"),
548 copy_dialog->x - 500/2, copy_dialog->y - 200/2,
549 500, 200, 500, 200, 1, 0, 1)
551 this->copy_dialog = copy_dialog;
554 AssetCopyWindow::~AssetCopyWindow()
558 void AssetCopyWindow::create_objects()
560 lock_window("AssetCopyWindow::create_objects");
562 int x = 10, y = 10, pad = 5;
563 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
564 y += title->get_h() + pad;
565 int text_w = get_w() - x - 10;
566 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
567 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
568 char *text = copy_dialog->text;
569 int len = strlen(text) + BCTEXTLEN;
570 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
571 file_list->create_objects();
573 add_subwindow(new BC_OKButton(this));
578 int AssetCopyWindow::resize_event(int w, int h)
580 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
581 int text_w = w - fx - 10;
582 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
583 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
584 file_list->reposition_window(fx, fy, text_w, text_rows);
588 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
589 : BC_MenuItem(_("Paste file list"))
591 this->mwindow = mwindow;
595 AssetListPaste::~AssetListPaste()
600 int AssetListPaste::handle_event()
603 paste_dialog = new AssetPasteDialog(this);
605 paste_dialog->close_window();
607 gui->get_abs_cursor(cur_x, cur_y, 0);
608 paste_dialog->start(cur_x, cur_y);
612 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
619 AssetPasteDialog::~AssetPasteDialog()
624 BC_Window* AssetPasteDialog::new_gui()
626 paste_window = new AssetPasteWindow(this);
627 paste_window->create_objects();
631 void AssetPasteDialog::handle_done_event(int result)
634 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
635 ArrayList<char*> path_list;
636 path_list.set_array_delete();
638 for( const char *cp=bp; cp<ep && *cp; ) {
639 const char *dp = strchr(cp, '\n');
641 char path[BCTEXTLEN], *pp = path;
642 int len = sizeof(path)-1;
643 while( --len>0 && cp<dp ) *pp++ = *cp++;
646 if( !strlen(path) ) continue;
647 path_list.append(cstrdup(path));
649 if( !path_list.size() ) return;
651 MWindow *mwindow = paste->mwindow;
652 mwindow->interrupt_indexes();
653 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
654 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
655 mwindow->gui->unlock_window();
656 path_list.remove_all_objects();
657 mwindow->save_backup();
658 mwindow->restart_brender();
659 mwindow->session->changes_made = 1;
662 void AssetPasteDialog::handle_close_event(int result)
667 void AssetPasteDialog::start(int x, int y)
669 this->x = x; this->y = y;
670 BC_DialogThread::start();
673 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
674 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
675 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
676 500, 200, 500, 200, 1, 0, 1)
678 this->paste_dialog = paste_dialog;
681 AssetPasteWindow::~AssetPasteWindow()
685 void AssetPasteWindow::create_objects()
687 lock_window("AssetPasteWindow::create_objects()");
689 int x = 10, y = 10, pad = 5;
690 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
691 y += title->get_h() + pad;
692 int text_w = get_w() - x - 10;
693 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
694 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
695 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
696 file_list->create_objects();
697 add_subwindow(new BC_OKButton(this));
698 add_subwindow(new BC_CancelButton(this));
703 int AssetPasteWindow::resize_event(int w, int h)
705 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
706 int text_w = w - fx - 10;
707 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
708 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
709 file_list->reposition_window(fx, fy, text_w, text_rows);
715 AssetSnapshot::AssetSnapshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
716 : BC_MenuItem(_("Snapshot..."))
718 this->mwindow = mwindow;
719 this->asset_list_menu = asset_list_menu;
722 AssetSnapshot::~AssetSnapshot()
726 SnapshotSubMenu::SnapshotSubMenu(AssetSnapshot *asset_snapshot)
728 this->asset_snapshot = asset_snapshot;
731 SnapshotSubMenu::~SnapshotSubMenu()
735 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
738 this->submenu = submenu;
742 SnapshotMenuItem::~SnapshotMenuItem()
746 int SnapshotMenuItem::handle_event()
748 MWindow *mwindow = submenu->asset_snapshot->mwindow;
749 EDL *edl = mwindow->edl;
750 if( !edl->have_video() ) return 1;
752 Preferences *preferences = mwindow->preferences;
753 char filename[BCTEXTLEN];
754 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
755 time_t tt; time(&tt);
756 struct tm tm; localtime_r(&tt,&tm);
757 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
758 preferences->snapshot_path, _("snap"),
759 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
760 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
761 char *asset_path = FileSystem::basepath(filename);
762 Asset *asset = new Asset(asset_path);
763 delete [] asset_path;
765 int fw = edl->get_w(), fh = edl->get_h();
766 int fcolor_model = edl->session->color_model;
770 asset->format = FILE_PNG;
771 asset->png_use_alpha = 1;
774 asset->format = FILE_JPEG;
775 asset->jpeg_quality = 90;
778 asset->format = FILE_TIFF;
779 asset->tiff_cmodel = 0;
780 asset->tiff_compression = 0;
783 asset->format = FILE_PPM;
788 asset->audio_data = 0;
789 asset->video_data = 1;
790 asset->video_length = 1;
794 int processors = preferences->project_smp + 1;
795 if( processors > 8 ) processors = 8;
796 file.set_processors(processors);
797 int ret = file.open_file(preferences, asset, 0, 1);
799 file.start_video_thread(1, fcolor_model,
800 processors > 1 ? 2 : 1, 0);
801 VFrame ***frames = file.get_video_buffer();
802 VFrame *frame = frames[0][0];
803 TransportCommand command;
804 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
805 command.command = CURRENT_FRAME;
806 command.get_edl()->copy_all(edl);
807 command.change_type = CHANGE_ALL;
808 command.realtime = 0;
810 RenderEngine render_engine(0, preferences, 0, 0);
811 CICache video_cache(preferences);
812 render_engine.set_vcache(&video_cache);
813 render_engine.arm_command(&command);
815 double position = edl->local_session->get_selectionstart(1);
816 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
817 ret = !render_engine.vrender ? 1 :
818 render_engine.vrender->process_buffer(frame, source_position, 0);
820 ret = file.write_video_buffer(1);
824 asset->awindow_folder = AW_MEDIA_FOLDER;
825 mwindow->edl->assets->append(asset);
826 mwindow->awindow->gui->async_update_assets();
829 eprintf(_("snapshot render failed"));
830 asset->remove_user();
836 AssetGrabshot::AssetGrabshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
837 : BC_MenuItem(_("Grabshot..."))
839 this->mwindow = mwindow;
840 this->asset_list_menu = asset_list_menu;
843 AssetGrabshot::~AssetGrabshot()
847 GrabshotSubMenu::GrabshotSubMenu(AssetGrabshot *asset_grabshot)
849 this->asset_grabshot = asset_grabshot;
852 GrabshotSubMenu::~GrabshotSubMenu()
856 GrabshotMenuItem::GrabshotMenuItem(GrabshotSubMenu *submenu, const char *text, int mode)
859 this->submenu = submenu;
864 GrabshotMenuItem::~GrabshotMenuItem()
869 int GrabshotMenuItem::handle_event()
872 grab_thread = new GrabshotThread(submenu->asset_grabshot->mwindow);
873 if( !grab_thread->running() )
874 grab_thread->start(this);
878 GrabshotThread::GrabshotThread(MWindow *mwindow)
881 this->mwindow = mwindow;
885 GrabshotThread::~GrabshotThread()
890 void GrabshotThread::start(GrabshotMenuItem *menu_item)
892 popup = new GrabshotPopup(this, menu_item->mode);
893 popup->lock_window("GrabshotThread::start");
894 for( int i=0; i<4; ++i )
895 edge[i] = new BC_Popup(mwindow->gui, 0,0, 1,1, ORANGE, 1);
896 mwindow->gui->grab_buttons();
897 mwindow->gui->grab_cursor();
898 popup->grab(mwindow->gui);
899 popup->create_objects();
900 popup->show_window();
901 popup->unlock_window();
906 void GrabshotThread::run()
908 popup->lock_window("GrabshotThread::run 0");
911 popup->unlock_window();
915 popup->lock_window("GrabshotThread::run 1");
917 mwindow->gui->ungrab_cursor();
918 mwindow->gui->ungrab_buttons();
919 popup->ungrab(mwindow->gui);
920 for( int i=0; i<4; ++i ) delete edge[i];
921 popup->unlock_window();
922 delete popup; popup = 0;
925 GrabshotPopup::GrabshotPopup(GrabshotThread *grab_thread, int mode)
926 : BC_Popup(grab_thread->mwindow->gui, 0,0, 16,16, -1,1)
928 this->grab_thread = grab_thread;
932 x0 = y0 = x1 = y1 = -1;
933 lx0 = ly0 = lx1 = ly1 = -1;
935 GrabshotPopup::~GrabshotPopup()
939 int GrabshotPopup::grab_event(XEvent *event)
941 int cur_drag = dragging;
942 switch( event->type ) {
944 if( cur_drag > 0 ) return 1;
945 x0 = event->xbutton.x_root;
946 y0 = event->xbutton.y_root;
949 if( event->xbutton.button == RIGHT_BUTTON ) break;
950 if( x0>=get_x() && x0<get_x()+get_w() &&
951 y0>=get_y() && y0<get_y()+get_h() ) break;
961 x1 = event->xbutton.x_root;
962 y1 = event->xbutton.y_root;
970 int cx = lx0, cy = ly0;
971 int cw = lx1-lx0, ch = ly1-ly0;
974 grab_thread->done = 1;
976 MWindow *mwindow = grab_thread->mwindow;
977 Preferences *preferences = mwindow->preferences;
978 char filename[BCTEXTLEN];
979 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
980 time_t tt; time(&tt);
981 struct tm tm; localtime_r(&tt,&tm);
982 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
983 preferences->snapshot_path, _("grab"),
984 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
985 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
986 char *asset_path = FileSystem::basepath(filename);
987 Asset *asset = new Asset(asset_path);
988 delete [] asset_path;
991 asset->format = FILE_PNG;
992 asset->png_use_alpha = 1;
995 asset->format = FILE_JPEG;
996 asset->jpeg_quality = 90;
999 asset->format = FILE_TIFF;
1000 asset->tiff_cmodel = 0;
1001 asset->tiff_compression = 0;
1004 asset->format = FILE_PPM;
1008 // no odd dimensions
1009 int rw = get_root_w(0), rh = get_root_h(0);
1010 if( cx < 0 ) { cw += cx; cx = 0; }
1011 if( cy < 0 ) { ch += cy; cy = 0; }
1012 if( cx+cw > rw ) cw = rw-cx;
1013 if( cy+ch > rh ) ch = rh-cy;
1014 if( !cw || !ch ) return 1;
1016 VFrame vframe(cw,ch, BC_RGB888);
1017 if( cx+cw < rw ) ++cw;
1018 if( cy+ch < rh ) ++ch;
1019 BC_Capture capture_bitmap(cw,ch, 0);
1020 capture_bitmap.capture_frame(&vframe, cx,cy);
1022 asset->width = vframe.get_w();
1023 asset->height = vframe.get_h();
1024 asset->audio_data = 0;
1025 asset->video_data = 1;
1026 asset->video_length = 1;
1030 int fcolor_model = mwindow->edl->session->color_model;
1031 int processors = preferences->project_smp + 1;
1032 if( processors > 8 ) processors = 8;
1033 file.set_processors(processors);
1034 int ret = file.open_file(preferences, asset, 0, 1);
1036 file.start_video_thread(1, fcolor_model,
1037 processors > 1 ? 2 : 1, 0);
1038 VFrame ***frames = file.get_video_buffer();
1039 VFrame *frame = frames[0][0];
1040 frame->transfer_from(&vframe);
1041 ret = file.write_video_buffer(1);
1045 asset->awindow_folder = AW_MEDIA_FOLDER;
1046 mwindow->edl->assets->append(asset);
1047 mwindow->awindow->gui->async_update_assets();
1050 eprintf(_("grabshot render failed"));
1051 asset->remove_user();
1057 void GrabshotPopup::update()
1059 set_color(grab_color ^= GREEN);
1060 draw_box(0,0, get_w(),get_h());
1064 void GrabshotPopup::draw_selection(int show)
1067 for( int i=0; i<4; ++i ) hide_window(0);
1072 int nx0 = x0 < x1 ? x0 : x1;
1073 int nx1 = x0 < x1 ? x1 : x0;
1074 int ny0 = y0 < y1 ? y0 : y1;
1075 int ny1 = y0 < y1 ? y1 : y0;
1076 lx0 = nx0; lx1 = nx1; ly0 = ny0; ly1 = ny1;
1079 BC_Popup **edge = grab_thread->edge;
1080 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
1081 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
1082 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
1083 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
1086 for( int i=0; i<4; ++i ) edge[i]->show_window(0);