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"
42 #include "localsession.h"
43 #include "mainerror.h"
44 #include "mainindexes.h"
45 #include "mainsession.h"
47 #include "mwindowgui.h"
48 #include "preferences.h"
49 #include "renderengine.h"
51 #include "transportque.h"
55 #include "vwindowgui.h"
59 AssetPopup::AssetPopup(MWindow *mwindow, AWindowGUI *gui)
60 : BC_PopupMenu(0, 0, 0, "", 0)
62 this->mwindow = mwindow;
66 AssetPopup::~AssetPopup()
70 void AssetPopup::create_objects()
72 BC_MenuItem *menu_item;
74 add_item(info = new AssetPopupInfo(mwindow, this));
75 add_item(format = new AWindowListFormat(mwindow, gui));
76 add_item(menu_item = new BC_MenuItem(_("Sort...")));
77 menu_item->add_submenu(submenu = new BC_SubMenu());
78 submenu->add_submenuitem(new AssetPopupSortNames(mwindow, this));
79 submenu->add_submenuitem(new AssetPopupSortTimes(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,
106 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 gui->collect_assets();
148 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
149 : BC_MenuItem(_("Info..."))
151 this->mwindow = mwindow;
155 AssetPopupInfo::~AssetPopupInfo()
159 int AssetPopupInfo::handle_event()
162 popup->gui->get_abs_cursor(cur_x, cur_y);
163 if( mwindow->session->drag_assets->size() ) {
164 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
165 asset_edit->edit_asset(
166 mwindow->session->drag_assets->values[0], cur_x, cur_y);
168 else if( mwindow->session->drag_clips->size() ) {
169 popup->gui->awindow->clip_edit->edit_clip(
170 mwindow->session->drag_clips->values[0], cur_x, cur_y);
176 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
177 : BC_MenuItem(_("Rebuild index"))
179 this->mwindow = mwindow;
183 AssetPopupBuildIndex::~AssetPopupBuildIndex()
187 int AssetPopupBuildIndex::handle_event()
189 //printf("AssetPopupBuildIndex::handle_event 1\n");
190 mwindow->rebuild_indices();
195 AssetPopupSortNames::AssetPopupSortNames(MWindow *mwindow, AssetPopup *popup)
196 : BC_MenuItem(_("Sort names"))
198 this->mwindow = mwindow;
202 AssetPopupSortNames::~AssetPopupSortNames()
206 int AssetPopupSortNames::handle_event()
208 mwindow->awindow->gui->sort_assets(0);
212 AssetPopupSortTimes::AssetPopupSortTimes(MWindow *mwindow, AssetPopup *popup)
213 : BC_MenuItem(_("Sort times"))
215 this->mwindow = mwindow;
219 AssetPopupSortTimes::~AssetPopupSortTimes()
223 int AssetPopupSortTimes::handle_event()
225 mwindow->awindow->gui->sort_assets(1);
230 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
231 : BC_MenuItem(_("View"))
233 this->mwindow = mwindow;
237 AssetPopupView::~AssetPopupView()
241 int AssetPopupView::handle_event()
243 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
244 vwindow->gui->lock_window("AssetPopupView::handle_event");
246 if( mwindow->session->drag_assets->total )
247 vwindow->change_source(
248 mwindow->session->drag_assets->values[0]);
250 if( mwindow->session->drag_clips->total )
251 vwindow->change_source(
252 mwindow->session->drag_clips->values[0]);
254 vwindow->gui->unlock_window();
259 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
260 : BC_MenuItem(_("View in new window"))
262 this->mwindow = mwindow;
266 AssetPopupViewWindow::~AssetPopupViewWindow()
270 int AssetPopupViewWindow::handle_event()
272 // Find window with nothing
273 VWindow *vwindow = mwindow->get_viewer(1);
275 // TODO: create new vwindow or change current vwindow
276 vwindow->gui->lock_window("AssetPopupView::handle_event");
278 if( mwindow->session->drag_assets->total )
279 vwindow->change_source(
280 mwindow->session->drag_assets->values[0]);
282 if( mwindow->session->drag_clips->total )
283 vwindow->change_source(
284 mwindow->session->drag_clips->values[0]);
286 vwindow->gui->unlock_window();
290 AssetPopupMixer::AssetPopupMixer(MWindow *mwindow, AssetPopup *popup)
291 : BC_MenuItem(_("Open Mixers"))
293 this->mwindow = mwindow;
297 AssetPopupMixer::~AssetPopupMixer()
301 int AssetPopupMixer::handle_event()
303 mwindow->gui->lock_window("AssetPopupMixer::handle_event");
304 mwindow->create_mixers();
305 mwindow->gui->unlock_window();
309 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
310 : BC_MenuItem(_("Paste"))
312 this->mwindow = mwindow;
316 AssetPopupPaste::~AssetPopupPaste()
320 int AssetPopupPaste::handle_event()
322 popup->paste_assets();
327 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
328 : BC_MenuItem(_("Match project size"))
330 this->mwindow = mwindow;
334 int AssetMatchSize::handle_event()
340 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
341 : BC_MenuItem(_("Match frame rate"))
343 this->mwindow = mwindow;
347 int AssetMatchRate::handle_event()
353 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
354 : BC_MenuItem(_("Match all"))
356 this->mwindow = mwindow;
360 int AssetMatchAll::handle_event()
367 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
368 : BC_MenuItem(_("Remove from project"))
370 this->mwindow = mwindow;
374 AssetPopupProjectRemove::~AssetPopupProjectRemove()
378 int AssetPopupProjectRemove::handle_event()
380 mwindow->remove_assets_from_project(1, 1,
381 mwindow->session->drag_assets,
382 mwindow->session->drag_clips);
387 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
388 : BC_MenuItem(_("Remove from disk"))
390 this->mwindow = mwindow;
395 AssetPopupDiskRemove::~AssetPopupDiskRemove()
399 int AssetPopupDiskRemove::handle_event()
401 mwindow->awindow->asset_remove->start();
406 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
407 : BC_PopupMenu(0, 0, 0, "", 0)
409 this->mwindow = mwindow;
413 AssetListMenu::~AssetListMenu()
415 if( !shots_displayed ) {
416 delete asset_snapshot;
417 delete asset_grabshot;
421 void AssetListMenu::create_objects()
423 add_item(format = new AWindowListFormat(mwindow, gui));
424 add_item(new AWindowListSort(mwindow, gui));
425 add_item(new AssetListCopy(mwindow, gui));
426 add_item(new AssetListPaste(mwindow, gui));
427 SnapshotSubMenu *snapshot_submenu;
428 add_item(asset_snapshot = new AssetSnapshot(mwindow, this));
429 asset_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(asset_snapshot));
430 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"), SNAPSHOT_PNG));
431 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
432 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
433 GrabshotSubMenu *grabshot_submenu;
434 add_item(asset_grabshot = new AssetGrabshot(mwindow, this));
435 asset_grabshot->add_submenu(grabshot_submenu = new GrabshotSubMenu(asset_grabshot));
436 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("png"), GRABSHOT_PNG));
437 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("jpeg"), GRABSHOT_JPEG));
438 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("tiff"), GRABSHOT_TIFF));
439 update_titles(shots_displayed = 1);
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()
561 int x = 10, y = 10, pad = 5;
562 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
563 y += title->get_h() + pad;
564 int text_w = get_w() - x - 10;
565 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
566 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
567 char *text = copy_dialog->text;
568 int len = strlen(text) + BCTEXTLEN;
569 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
570 file_list->create_objects();
572 add_subwindow(new BC_OKButton(this));
576 int AssetCopyWindow::resize_event(int w, int h)
578 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
579 int text_w = w - fx - 10;
580 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
581 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
582 file_list->reposition_window(fx, fy, text_w, text_rows);
586 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
587 : BC_MenuItem(_("Paste file list"))
589 this->mwindow = mwindow;
593 AssetListPaste::~AssetListPaste()
598 int AssetListPaste::handle_event()
601 paste_dialog = new AssetPasteDialog(this);
603 paste_dialog->close_window();
605 gui->get_abs_cursor(cur_x, cur_y, 0);
606 paste_dialog->start(cur_x, cur_y);
610 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
617 AssetPasteDialog::~AssetPasteDialog()
622 BC_Window* AssetPasteDialog::new_gui()
624 paste_window = new AssetPasteWindow(this);
625 paste_window->create_objects();
629 void AssetPasteDialog::handle_done_event(int result)
632 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
633 ArrayList<char*> path_list;
634 path_list.set_array_delete();
636 for( const char *cp=bp; cp<ep && *cp; ) {
637 const char *dp = strchr(cp, '\n');
639 char path[BCTEXTLEN], *pp = path;
640 int len = sizeof(path)-1;
641 while( --len>0 && cp<dp ) *pp++ = *cp++;
644 if( !strlen(path) ) continue;
645 path_list.append(cstrdup(path));
647 if( !path_list.size() ) return;
649 MWindow *mwindow = paste->mwindow;
650 mwindow->interrupt_indexes();
651 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
652 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
653 mwindow->gui->unlock_window();
654 path_list.remove_all_objects();
655 mwindow->save_backup();
656 mwindow->restart_brender();
657 mwindow->session->changes_made = 1;
660 void AssetPasteDialog::handle_close_event(int result)
665 void AssetPasteDialog::start(int x, int y)
667 this->x = x; this->y = y;
668 BC_DialogThread::start();
671 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
672 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
673 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
674 500, 200, 500, 200, 1, 0, 1)
676 this->paste_dialog = paste_dialog;
679 AssetPasteWindow::~AssetPasteWindow()
683 void AssetPasteWindow::create_objects()
686 int x = 10, y = 10, pad = 5;
687 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
688 y += title->get_h() + pad;
689 int text_w = get_w() - x - 10;
690 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
691 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
692 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
693 file_list->create_objects();
694 add_subwindow(new BC_OKButton(this));
695 add_subwindow(new BC_CancelButton(this));
699 int AssetPasteWindow::resize_event(int w, int h)
701 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
702 int text_w = w - fx - 10;
703 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
704 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
705 file_list->reposition_window(fx, fy, text_w, text_rows);
711 AssetSnapshot::AssetSnapshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
712 : BC_MenuItem(_("Snapshot..."))
714 this->mwindow = mwindow;
715 this->asset_list_menu = asset_list_menu;
718 AssetSnapshot::~AssetSnapshot()
722 SnapshotSubMenu::SnapshotSubMenu(AssetSnapshot *asset_snapshot)
724 this->asset_snapshot = asset_snapshot;
727 SnapshotSubMenu::~SnapshotSubMenu()
731 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
734 this->submenu = submenu;
738 SnapshotMenuItem::~SnapshotMenuItem()
742 int SnapshotMenuItem::handle_event()
744 MWindow *mwindow = submenu->asset_snapshot->mwindow;
745 EDL *edl = mwindow->edl;
746 if( !edl->have_video() ) return 1;
748 Preferences *preferences = mwindow->preferences;
749 char filename[BCTEXTLEN];
750 static const char *exts[] = { "png", "jpg", "tif" };
751 time_t tt; time(&tt);
752 struct tm tm; localtime_r(&tt,&tm);
753 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
754 preferences->snapshot_path, _("snap"),
755 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
756 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
757 int fw = edl->get_w(), fh = edl->get_h();
758 int fcolor_model = edl->session->color_model;
760 Asset *asset = new Asset(filename);
763 asset->format = FILE_PNG;
764 asset->png_use_alpha = 1;
767 asset->format = FILE_JPEG;
768 asset->jpeg_quality = 90;
771 asset->format = FILE_TIFF;
772 asset->tiff_cmodel = 0;
773 asset->tiff_compression = 0;
778 asset->audio_data = 0;
779 asset->video_data = 1;
780 asset->video_length = 1;
784 int processors = preferences->project_smp + 1;
785 if( processors > 8 ) processors = 8;
786 file.set_processors(processors);
787 int ret = file.open_file(preferences, asset, 0, 1);
789 file.start_video_thread(1, fcolor_model,
790 processors > 1 ? 2 : 1, 0);
791 VFrame ***frames = file.get_video_buffer();
792 VFrame *frame = frames[0][0];
793 TransportCommand command;
794 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
795 command.command = CURRENT_FRAME;
796 command.get_edl()->copy_all(edl);
797 command.change_type = CHANGE_ALL;
798 command.realtime = 0;
800 RenderEngine render_engine(0, preferences, 0, 0);
801 CICache video_cache(preferences);
802 render_engine.set_vcache(&video_cache);
803 render_engine.arm_command(&command);
805 double position = edl->local_session->get_selectionstart(1);
806 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
807 ret = render_engine.vrender->process_buffer(frame, source_position, 0);
809 ret = file.write_video_buffer(1);
813 asset->awindow_folder = AW_MEDIA_FOLDER;
814 mwindow->edl->assets->append(asset);
815 mwindow->awindow->gui->async_update_assets();
818 eprintf(_("snapshot render failed"));
819 asset->remove_user();
825 AssetGrabshot::AssetGrabshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
826 : BC_MenuItem(_("Grabshot..."))
828 this->mwindow = mwindow;
829 this->asset_list_menu = asset_list_menu;
832 AssetGrabshot::~AssetGrabshot()
836 GrabshotSubMenu::GrabshotSubMenu(AssetGrabshot *asset_grabshot)
838 this->asset_grabshot = asset_grabshot;
841 GrabshotSubMenu::~GrabshotSubMenu()
845 GrabshotMenuItem::GrabshotMenuItem(GrabshotSubMenu *submenu, const char *text, int mode)
848 this->submenu = submenu;
853 GrabshotMenuItem::~GrabshotMenuItem()
858 int GrabshotMenuItem::handle_event()
861 grab_thread = new GrabshotThread(submenu->asset_grabshot->mwindow);
862 if( !grab_thread->running() )
863 grab_thread->start(this);
867 GrabshotThread::GrabshotThread(MWindow *mwindow)
870 this->mwindow = mwindow;
874 GrabshotThread::~GrabshotThread()
879 void GrabshotThread::start(GrabshotMenuItem *menu_item)
881 popup = new GrabshotPopup(this, menu_item->mode);
882 popup->lock_window("GrabshotThread::start");
883 for( int i=0; i<4; ++i )
884 edge[i] = new BC_Popup(mwindow->gui, 0,0, 1,1, ORANGE, 1);
885 mwindow->gui->grab_buttons();
886 mwindow->gui->grab_cursor();
887 popup->grab(mwindow->gui);
888 popup->create_objects();
889 popup->show_window();
890 popup->unlock_window();
895 void GrabshotThread::run()
897 popup->lock_window("GrabshotThread::run 0");
900 popup->unlock_window();
904 popup->lock_window("GrabshotThread::run 1");
906 mwindow->gui->ungrab_cursor();
907 mwindow->gui->ungrab_buttons();
908 popup->ungrab(mwindow->gui);
909 for( int i=0; i<4; ++i ) delete edge[i];
910 popup->unlock_window();
911 delete popup; popup = 0;
914 GrabshotPopup::GrabshotPopup(GrabshotThread *grab_thread, int mode)
915 : BC_Popup(grab_thread->mwindow->gui, 0,0, 16,16, -1,1)
917 this->grab_thread = grab_thread;
921 x0 = y0 = x1 = y1 = -1;
922 lx0 = ly0 = lx1 = ly1 = -1;
924 GrabshotPopup::~GrabshotPopup()
928 int GrabshotPopup::grab_event(XEvent *event)
930 int cur_drag = dragging;
931 switch( event->type ) {
933 if( cur_drag > 0 ) return 1;
934 x0 = event->xbutton.x_root;
935 y0 = event->xbutton.y_root;
938 if( event->xbutton.button == RIGHT_BUTTON ) break;
939 if( x0>=get_x() && x0<get_x()+get_w() &&
940 y0>=get_y() && y0<get_y()+get_h() ) break;
950 x1 = event->xbutton.x_root;
951 y1 = event->xbutton.y_root;
959 int cx = lx0, cy = ly0;
960 int cw = lx1-lx0, ch = ly1-ly0;
964 MWindow *mwindow = grab_thread->mwindow;
965 Preferences *preferences = mwindow->preferences;
966 char filename[BCTEXTLEN];
967 static const char *exts[] = { "png", "jpg", "tif" };
968 time_t tt; time(&tt);
969 struct tm tm; localtime_r(&tt,&tm);
970 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
971 preferences->snapshot_path, _("grab"),
972 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
973 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
975 Asset *asset = new Asset(filename);
978 asset->format = FILE_PNG;
979 asset->png_use_alpha = 1;
982 asset->format = FILE_JPEG;
983 asset->jpeg_quality = 90;
986 asset->format = FILE_TIFF;
987 asset->tiff_cmodel = 0;
988 asset->tiff_compression = 0;
992 int rw = get_root_w(0), rh = get_root_h(0);
993 if( cx < 0 ) { cw += cx; cx = 0; }
994 if( cy < 0 ) { ch += cy; cy = 0; }
995 if( cx+cw > rw ) cw = rw-cx;
996 if( cy+ch > rh ) ch = rh-cy;
997 VFrame vframe(cw,ch, BC_RGB888);
998 if( cx+cw < rw ) ++cw;
999 if( cy+ch < rh ) ++ch;
1000 BC_Capture capture_bitmap(cw,ch, 0);
1001 capture_bitmap.capture_frame(&vframe, cx,cy);
1003 asset->width = vframe.get_w();
1004 asset->height = vframe.get_h();
1005 asset->audio_data = 0;
1006 asset->video_data = 1;
1007 asset->video_length = 1;
1011 int fcolor_model = mwindow->edl->session->color_model;
1012 int processors = preferences->project_smp + 1;
1013 if( processors > 8 ) processors = 8;
1014 file.set_processors(processors);
1015 int ret = file.open_file(preferences, asset, 0, 1);
1017 file.start_video_thread(1, fcolor_model,
1018 processors > 1 ? 2 : 1, 0);
1019 VFrame ***frames = file.get_video_buffer();
1020 VFrame *frame = frames[0][0];
1021 frame->transfer_from(&vframe);
1022 ret = file.write_video_buffer(1);
1026 asset->awindow_folder = AW_MEDIA_FOLDER;
1027 mwindow->edl->assets->append(asset);
1028 mwindow->awindow->gui->async_update_assets();
1031 eprintf(_("grabshot render failed"));
1032 asset->remove_user();
1035 grab_thread->done = 1;
1039 void GrabshotPopup::update()
1041 set_color(grab_color ^= GREEN);
1042 draw_box(0,0, get_w(),get_h());
1046 void GrabshotPopup::draw_selection(int show)
1049 for( int i=0; i<4; ++i ) hide_window(0);
1054 int nx0 = x0 < x1 ? x0 : x1;
1055 int nx1 = x0 < x1 ? x1 : x0;
1056 int ny0 = y0 < y1 ? y0 : y1;
1057 int ny1 = y0 < y1 ? y1 : y0;
1058 lx0 = nx0; lx1 = nx1; ly0 = ny0; ly1 = ny1;
1061 BC_Popup **edge = grab_thread->edge;
1062 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
1063 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
1064 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
1065 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
1068 for( int i=0; i<4; ++i ) edge[i]->show_window(0);