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"
43 #include "localsession.h"
44 #include "mainerror.h"
45 #include "mainindexes.h"
47 #include "mainsession.h"
49 #include "mwindowgui.h"
50 #include "preferences.h"
51 #include "renderengine.h"
53 #include "transportque.h"
57 #include "vwindowgui.h"
61 AssetPopup::AssetPopup(MWindow *mwindow, AWindowGUI *gui)
62 : BC_PopupMenu(0, 0, 0, "", 0)
64 this->mwindow = mwindow;
68 AssetPopup::~AssetPopup()
72 void AssetPopup::create_objects()
74 BC_MenuItem *menu_item;
76 add_item(info = new AssetPopupInfo(mwindow, this));
77 add_item(format = new AWindowListFormat(mwindow, gui));
78 add_item(menu_item = new BC_MenuItem(_("Sort...")));
79 menu_item->add_submenu(submenu = new BC_SubMenu());
80 submenu->add_submenuitem(new AssetPopupSortNames(mwindow, this));
81 submenu->add_submenuitem(new AssetPopupSortTimes(mwindow, this));
82 add_item(index = new AssetPopupBuildIndex(mwindow, this));
83 add_item(view = new AssetPopupView(mwindow, this));
84 add_item(view_window = new AssetPopupViewWindow(mwindow, this));
85 add_item(mixer = new AssetPopupMixer(mwindow, this));
86 add_item(new AssetPopupPaste(mwindow, this));
87 add_item(menu_item = new BC_MenuItem(_("Match...")));
88 menu_item->add_submenu(submenu = new BC_SubMenu());
89 submenu->add_submenuitem(new AssetMatchSize(mwindow, this));
90 submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
91 submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
92 add_item(menu_item = new BC_MenuItem(_("Remove...")));
93 menu_item->add_submenu(submenu = new BC_SubMenu());
94 submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
95 submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
98 void AssetPopup::paste_assets()
100 // Collect items into the drag vectors for temporary storage
101 gui->lock_window("AssetPopup::paste_assets");
102 mwindow->gui->lock_window("AssetPopup::paste_assets");
103 mwindow->cwindow->gui->lock_window("AssetPopup::paste_assets");
105 int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
106 gui->collect_assets(proxy);
107 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
108 mwindow->edl->tracks->first, 0); // do not overwrite
109 mwindow->session->clear_drag_proxy();
111 gui->unlock_window();
112 mwindow->gui->unlock_window();
113 mwindow->cwindow->gui->unlock_window();
116 void AssetPopup::match_size()
118 // Collect items into the drag vectors for temporary storage
119 gui->collect_assets();
120 mwindow->gui->lock_window("AssetPopup::match_size");
121 mwindow->asset_to_size();
122 mwindow->gui->unlock_window();
125 void AssetPopup::match_rate()
127 // Collect items into the drag vectors for temporary storage
128 gui->collect_assets();
129 mwindow->gui->lock_window("AssetPopup::match_rate");
130 mwindow->asset_to_rate();
131 mwindow->gui->unlock_window();
134 void AssetPopup::match_all()
136 // Collect items into the drag vectors for temporary storage
137 gui->collect_assets();
138 mwindow->gui->lock_window("AssetPopup::match_rate");
139 mwindow->asset_to_all();
140 mwindow->gui->unlock_window();
143 int AssetPopup::update()
146 int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
147 gui->collect_assets(proxy);
152 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
153 : BC_MenuItem(_("Info..."))
155 this->mwindow = mwindow;
159 AssetPopupInfo::~AssetPopupInfo()
163 int AssetPopupInfo::handle_event()
166 popup->gui->get_abs_cursor(cur_x, cur_y);
167 int n = mwindow->session->drag_assets->size();
169 for( int i=0; i<n; ++i ) {
170 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
171 asset_edit->edit_asset(
172 mwindow->session->drag_assets->values[i], cur_x-30*i, cur_y-30*i);
175 else if( mwindow->session->drag_clips->size() ) {
176 popup->gui->awindow->clip_edit->edit_clip(
177 mwindow->session->drag_clips->values[0], cur_x, cur_y);
183 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
184 : BC_MenuItem(_("Rebuild index"))
186 this->mwindow = mwindow;
190 AssetPopupBuildIndex::~AssetPopupBuildIndex()
194 int AssetPopupBuildIndex::handle_event()
196 //printf("AssetPopupBuildIndex::handle_event 1\n");
197 mwindow->rebuild_indices();
202 AssetPopupSortNames::AssetPopupSortNames(MWindow *mwindow, AssetPopup *popup)
203 : BC_MenuItem(_("Sort names"))
205 this->mwindow = mwindow;
209 AssetPopupSortNames::~AssetPopupSortNames()
213 int AssetPopupSortNames::handle_event()
215 mwindow->awindow->gui->sort_assets(0);
219 AssetPopupSortTimes::AssetPopupSortTimes(MWindow *mwindow, AssetPopup *popup)
220 : BC_MenuItem(_("Sort times"))
222 this->mwindow = mwindow;
226 AssetPopupSortTimes::~AssetPopupSortTimes()
230 int AssetPopupSortTimes::handle_event()
232 mwindow->awindow->gui->sort_assets(1);
237 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
238 : BC_MenuItem(_("View"))
240 this->mwindow = mwindow;
244 AssetPopupView::~AssetPopupView()
248 int AssetPopupView::handle_event()
250 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
252 if( mwindow->session->drag_assets->total )
253 vwindow->change_source(
254 mwindow->session->drag_assets->values[0]);
256 if( mwindow->session->drag_clips->total )
257 vwindow->change_source(
258 mwindow->session->drag_clips->values[0]);
264 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
265 : BC_MenuItem(_("View in new window"))
267 this->mwindow = mwindow;
271 AssetPopupViewWindow::~AssetPopupViewWindow()
275 int AssetPopupViewWindow::handle_event()
277 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
278 VWindow *vwindow = mwindow->get_viewer(1);
279 vwindow->gui->lock_window("AssetPopupView::handle_event 1");
280 vwindow->change_source(mwindow->session->drag_assets->get(i));
281 vwindow->gui->unlock_window();
283 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
284 VWindow *vwindow = mwindow->get_viewer(1);
285 vwindow->gui->lock_window("AssetPopupView::handle_event 2");
286 vwindow->change_source(mwindow->session->drag_clips->get(i));
287 vwindow->gui->unlock_window();
292 AssetPopupMixer::AssetPopupMixer(MWindow *mwindow, AssetPopup *popup)
293 : BC_MenuItem(_("Open Mixers"))
295 this->mwindow = mwindow;
299 AssetPopupMixer::~AssetPopupMixer()
303 int AssetPopupMixer::handle_event()
305 mwindow->gui->lock_window("AssetPopupMixer::handle_event");
306 mwindow->create_mixers();
307 mwindow->gui->unlock_window();
311 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
312 : BC_MenuItem(_("Paste"))
314 this->mwindow = mwindow;
318 AssetPopupPaste::~AssetPopupPaste()
322 int AssetPopupPaste::handle_event()
324 popup->paste_assets();
329 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
330 : BC_MenuItem(_("Match project size"))
332 this->mwindow = mwindow;
336 int AssetMatchSize::handle_event()
342 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
343 : BC_MenuItem(_("Match frame rate"))
345 this->mwindow = mwindow;
349 int AssetMatchRate::handle_event()
355 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
356 : BC_MenuItem(_("Match all"))
358 this->mwindow = mwindow;
362 int AssetMatchAll::handle_event()
369 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
370 : BC_MenuItem(_("Remove from project"))
372 this->mwindow = mwindow;
376 AssetPopupProjectRemove::~AssetPopupProjectRemove()
380 int AssetPopupProjectRemove::handle_event()
382 mwindow->remove_assets_from_project(1, 1,
383 mwindow->session->drag_assets,
384 mwindow->session->drag_clips);
389 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
390 : BC_MenuItem(_("Remove from disk"))
392 this->mwindow = mwindow;
397 AssetPopupDiskRemove::~AssetPopupDiskRemove()
401 int AssetPopupDiskRemove::handle_event()
403 mwindow->awindow->asset_remove->start();
408 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
409 : BC_PopupMenu(0, 0, 0, "", 0)
411 this->mwindow = mwindow;
415 AssetListMenu::~AssetListMenu()
417 if( !shots_displayed ) {
418 delete asset_snapshot;
419 delete asset_grabshot;
423 void AssetListMenu::create_objects()
425 add_item(load_file = new AssetPopupLoadFile(mwindow, gui));
426 add_item(format = new AWindowListFormat(mwindow, gui));
427 add_item(new AWindowListSort(mwindow, gui));
428 add_item(new AssetListCopy(mwindow, gui));
429 add_item(new AssetListPaste(mwindow, gui));
430 SnapshotSubMenu *snapshot_submenu;
431 add_item(asset_snapshot = new AssetSnapshot(mwindow, this));
432 asset_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(asset_snapshot));
433 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"), SNAPSHOT_PNG));
434 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
435 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
436 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("ppm"), SNAPSHOT_PPM));
437 GrabshotSubMenu *grabshot_submenu;
438 add_item(asset_grabshot = new AssetGrabshot(mwindow, this));
439 asset_grabshot->add_submenu(grabshot_submenu = new GrabshotSubMenu(asset_grabshot));
440 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("png"), GRABSHOT_PNG));
441 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("jpeg"), GRABSHOT_JPEG));
442 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("tiff"), GRABSHOT_TIFF));
443 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("ppm"), GRABSHOT_PPM));
444 update_titles(shots_displayed = 1);
447 AssetPopupLoadFile::AssetPopupLoadFile(MWindow *mwindow, AWindowGUI *gui)
448 : BC_MenuItem(_("Load files..."), "o", 'o')
450 this->mwindow = mwindow;
454 AssetPopupLoadFile::~AssetPopupLoadFile()
458 int AssetPopupLoadFile::handle_event()
460 mwindow->gui->mainmenu->load_file->thread->start();
464 void AssetListMenu::update_titles(int shots)
467 if( shots && !shots_displayed ) {
469 add_item(asset_snapshot);
470 add_item(asset_grabshot);
472 else if( !shots && shots_displayed ) {
474 remove_item(asset_snapshot);
475 remove_item(asset_grabshot);
479 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
480 : BC_MenuItem(_("Copy file list"))
482 this->mwindow = mwindow;
486 AssetListCopy::~AssetListCopy()
491 int AssetListCopy::handle_event()
494 MWindowGUI *gui = mwindow->gui;
495 gui->lock_window("AssetListCopy::handle_event");
496 mwindow->awindow->gui->collect_assets();
497 int n = mwindow->session->drag_assets->total;
498 for( int i=0; i<n; ++i ) {
499 Indexable *indexable = mwindow->session->drag_assets->values[i];
500 const char *path = indexable->path;
501 if( !*path ) continue;
502 len += strlen(path) + 1;
504 char *text = new char[len+1], *cp = text;
505 for( int i=0; i<n; ++i ) {
506 Indexable *indexable = mwindow->session->drag_assets->values[i];
507 const char *path = indexable->path;
508 if( !*path ) continue;
509 cp += sprintf(cp, "%s\n", path);
513 gui->get_abs_cursor(cur_x, cur_y, 0);
514 gui->unlock_window();
518 copy_dialog = new AssetCopyDialog(this);
519 copy_dialog->start(text, cur_x, cur_y);
522 eprintf(_("Nothing selected"));
528 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
535 void AssetCopyDialog::start(char *text, int x, int y)
539 this->x = x; this->y = y;
540 BC_DialogThread::start();
543 AssetCopyDialog::~AssetCopyDialog()
548 BC_Window* AssetCopyDialog::new_gui()
550 BC_DisplayInfo display_info;
552 copy_window = new AssetCopyWindow(this);
553 copy_window->create_objects();
557 void AssetCopyDialog::handle_done_event(int result)
559 delete [] text; text = 0;
562 void AssetCopyDialog::handle_close_event(int result)
568 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
569 : BC_Window(_(PROGRAM_NAME ": Copy File List"),
570 copy_dialog->x - 500/2, copy_dialog->y - 200/2,
571 500, 200, 500, 200, 1, 0, 1)
573 this->copy_dialog = copy_dialog;
576 AssetCopyWindow::~AssetCopyWindow()
580 void AssetCopyWindow::create_objects()
583 int x = 10, y = 10, pad = 5;
584 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
585 y += title->get_h() + pad;
586 int text_w = get_w() - x - 10;
587 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
588 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
589 char *text = copy_dialog->text;
590 int len = strlen(text) + BCTEXTLEN;
591 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
592 file_list->create_objects();
594 add_subwindow(new BC_OKButton(this));
598 int AssetCopyWindow::resize_event(int w, int h)
600 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
601 int text_w = w - fx - 10;
602 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
603 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
604 file_list->reposition_window(fx, fy, text_w, text_rows);
608 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
609 : BC_MenuItem(_("Paste file list"))
611 this->mwindow = mwindow;
615 AssetListPaste::~AssetListPaste()
620 int AssetListPaste::handle_event()
623 paste_dialog = new AssetPasteDialog(this);
625 paste_dialog->close_window();
627 gui->get_abs_cursor(cur_x, cur_y, 0);
628 paste_dialog->start(cur_x, cur_y);
632 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
639 AssetPasteDialog::~AssetPasteDialog()
644 BC_Window* AssetPasteDialog::new_gui()
646 paste_window = new AssetPasteWindow(this);
647 paste_window->create_objects();
651 void AssetPasteDialog::handle_done_event(int result)
654 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
655 ArrayList<char*> path_list;
656 path_list.set_array_delete();
658 for( const char *cp=bp; cp<ep && *cp; ) {
659 const char *dp = strchr(cp, '\n');
661 char path[BCTEXTLEN], *pp = path;
662 int len = sizeof(path)-1;
663 while( --len>0 && cp<dp ) *pp++ = *cp++;
666 if( !strlen(path) ) continue;
667 path_list.append(cstrdup(path));
669 if( !path_list.size() ) return;
671 MWindow *mwindow = paste->mwindow;
672 mwindow->interrupt_indexes();
673 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
674 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
675 mwindow->gui->unlock_window();
676 path_list.remove_all_objects();
677 mwindow->save_backup();
678 mwindow->restart_brender();
679 mwindow->session->changes_made = 1;
682 void AssetPasteDialog::handle_close_event(int result)
687 void AssetPasteDialog::start(int x, int y)
689 this->x = x; this->y = y;
690 BC_DialogThread::start();
693 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
694 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
695 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
696 500, 200, 500, 200, 1, 0, 1)
698 this->paste_dialog = paste_dialog;
701 AssetPasteWindow::~AssetPasteWindow()
705 void AssetPasteWindow::create_objects()
708 int x = 10, y = 10, pad = 5;
709 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
710 y += title->get_h() + pad;
711 int text_w = get_w() - x - 10;
712 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
713 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
714 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
715 file_list->create_objects();
716 add_subwindow(new BC_OKButton(this));
717 add_subwindow(new BC_CancelButton(this));
721 int AssetPasteWindow::resize_event(int w, int h)
723 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
724 int text_w = w - fx - 10;
725 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
726 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
727 file_list->reposition_window(fx, fy, text_w, text_rows);
733 AssetSnapshot::AssetSnapshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
734 : BC_MenuItem(_("Snapshot..."))
736 this->mwindow = mwindow;
737 this->asset_list_menu = asset_list_menu;
740 AssetSnapshot::~AssetSnapshot()
744 SnapshotSubMenu::SnapshotSubMenu(AssetSnapshot *asset_snapshot)
746 this->asset_snapshot = asset_snapshot;
749 SnapshotSubMenu::~SnapshotSubMenu()
753 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
756 this->submenu = submenu;
760 SnapshotMenuItem::~SnapshotMenuItem()
764 int SnapshotMenuItem::handle_event()
766 MWindow *mwindow = submenu->asset_snapshot->mwindow;
767 EDL *edl = mwindow->edl;
768 if( !edl->have_video() ) return 1;
770 Preferences *preferences = mwindow->preferences;
771 char filename[BCTEXTLEN];
772 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
773 time_t tt; time(&tt);
774 struct tm tm; localtime_r(&tt,&tm);
775 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
776 preferences->snapshot_path, _("snap"),
777 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
778 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
779 int fw = edl->get_w(), fh = edl->get_h();
780 int fcolor_model = edl->session->color_model;
782 Asset *asset = new Asset(filename);
785 asset->format = FILE_PNG;
786 asset->png_use_alpha = 1;
789 asset->format = FILE_JPEG;
790 asset->jpeg_quality = 90;
793 asset->format = FILE_TIFF;
794 asset->tiff_cmodel = 0;
795 asset->tiff_compression = 0;
798 asset->format = FILE_PPM;
803 asset->audio_data = 0;
804 asset->video_data = 1;
805 asset->video_length = 1;
809 int processors = preferences->project_smp + 1;
810 if( processors > 8 ) processors = 8;
811 file.set_processors(processors);
812 int ret = file.open_file(preferences, asset, 0, 1);
814 file.start_video_thread(1, fcolor_model,
815 processors > 1 ? 2 : 1, 0);
816 VFrame ***frames = file.get_video_buffer();
817 VFrame *frame = frames[0][0];
818 TransportCommand command;
819 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
820 command.command = CURRENT_FRAME;
821 command.get_edl()->copy_all(edl);
822 command.change_type = CHANGE_ALL;
823 command.realtime = 0;
825 RenderEngine render_engine(0, preferences, 0, 0);
826 CICache video_cache(preferences);
827 render_engine.set_vcache(&video_cache);
828 render_engine.arm_command(&command);
830 double position = edl->local_session->get_selectionstart(1);
831 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
832 ret = !render_engine.vrender ? 1 :
833 render_engine.vrender->process_buffer(frame, source_position, 0);
835 ret = file.write_video_buffer(1);
839 asset->awindow_folder = AW_MEDIA_FOLDER;
840 mwindow->edl->assets->append(asset);
841 mwindow->awindow->gui->async_update_assets();
844 eprintf(_("snapshot render failed"));
845 asset->remove_user();
851 AssetGrabshot::AssetGrabshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
852 : BC_MenuItem(_("Grabshot..."))
854 this->mwindow = mwindow;
855 this->asset_list_menu = asset_list_menu;
858 AssetGrabshot::~AssetGrabshot()
862 GrabshotSubMenu::GrabshotSubMenu(AssetGrabshot *asset_grabshot)
864 this->asset_grabshot = asset_grabshot;
867 GrabshotSubMenu::~GrabshotSubMenu()
871 GrabshotMenuItem::GrabshotMenuItem(GrabshotSubMenu *submenu, const char *text, int mode)
874 this->submenu = submenu;
879 GrabshotMenuItem::~GrabshotMenuItem()
884 int GrabshotMenuItem::handle_event()
887 grab_thread = new GrabshotThread(submenu->asset_grabshot->mwindow);
888 if( !grab_thread->running() )
889 grab_thread->start(this);
893 GrabshotThread::GrabshotThread(MWindow *mwindow)
896 this->mwindow = mwindow;
900 GrabshotThread::~GrabshotThread()
905 void GrabshotThread::start(GrabshotMenuItem *menu_item)
907 popup = new GrabshotPopup(this, menu_item->mode);
908 popup->lock_window("GrabshotThread::start");
909 for( int i=0; i<4; ++i )
910 edge[i] = new BC_Popup(mwindow->gui, 0,0, 1,1, ORANGE, 1);
911 mwindow->gui->grab_buttons();
912 mwindow->gui->grab_cursor();
913 popup->grab(mwindow->gui);
914 popup->create_objects();
915 popup->show_window();
916 popup->unlock_window();
921 void GrabshotThread::run()
923 popup->lock_window("GrabshotThread::run 0");
926 popup->unlock_window();
930 popup->lock_window("GrabshotThread::run 1");
932 mwindow->gui->ungrab_cursor();
933 mwindow->gui->ungrab_buttons();
934 popup->ungrab(mwindow->gui);
935 for( int i=0; i<4; ++i ) delete edge[i];
936 popup->unlock_window();
937 delete popup; popup = 0;
940 GrabshotPopup::GrabshotPopup(GrabshotThread *grab_thread, int mode)
941 : BC_Popup(grab_thread->mwindow->gui, 0,0, 16,16, -1,1)
943 this->grab_thread = grab_thread;
947 x0 = y0 = x1 = y1 = -1;
948 lx0 = ly0 = lx1 = ly1 = -1;
950 GrabshotPopup::~GrabshotPopup()
954 int GrabshotPopup::grab_event(XEvent *event)
956 int cur_drag = dragging;
957 switch( event->type ) {
959 if( cur_drag > 0 ) return 1;
960 x0 = event->xbutton.x_root;
961 y0 = event->xbutton.y_root;
964 if( event->xbutton.button == RIGHT_BUTTON ) break;
965 if( x0>=get_x() && x0<get_x()+get_w() &&
966 y0>=get_y() && y0<get_y()+get_h() ) break;
976 x1 = event->xbutton.x_root;
977 y1 = event->xbutton.y_root;
985 int cx = lx0, cy = ly0;
986 int cw = lx1-lx0, ch = ly1-ly0;
989 grab_thread->done = 1;
991 MWindow *mwindow = grab_thread->mwindow;
992 Preferences *preferences = mwindow->preferences;
993 char filename[BCTEXTLEN];
994 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
995 time_t tt; time(&tt);
996 struct tm tm; localtime_r(&tt,&tm);
997 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
998 preferences->snapshot_path, _("grab"),
999 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
1000 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
1002 Asset *asset = new Asset(filename);
1005 asset->format = FILE_PNG;
1006 asset->png_use_alpha = 1;
1009 asset->format = FILE_JPEG;
1010 asset->jpeg_quality = 90;
1013 asset->format = FILE_TIFF;
1014 asset->tiff_cmodel = 0;
1015 asset->tiff_compression = 0;
1018 asset->format = FILE_PPM;
1022 // no odd dimensions
1023 int rw = get_root_w(0), rh = get_root_h(0);
1024 if( cx < 0 ) { cw += cx; cx = 0; }
1025 if( cy < 0 ) { ch += cy; cy = 0; }
1026 if( cx+cw > rw ) cw = rw-cx;
1027 if( cy+ch > rh ) ch = rh-cy;
1028 if( !cw || !ch ) return 1;
1030 VFrame vframe(cw,ch, BC_RGB888);
1031 if( cx+cw < rw ) ++cw;
1032 if( cy+ch < rh ) ++ch;
1033 BC_Capture capture_bitmap(cw,ch, 0);
1034 capture_bitmap.capture_frame(&vframe, cx,cy);
1036 asset->width = vframe.get_w();
1037 asset->height = vframe.get_h();
1038 asset->audio_data = 0;
1039 asset->video_data = 1;
1040 asset->video_length = 1;
1044 int fcolor_model = mwindow->edl->session->color_model;
1045 int processors = preferences->project_smp + 1;
1046 if( processors > 8 ) processors = 8;
1047 file.set_processors(processors);
1048 int ret = file.open_file(preferences, asset, 0, 1);
1050 file.start_video_thread(1, fcolor_model,
1051 processors > 1 ? 2 : 1, 0);
1052 VFrame ***frames = file.get_video_buffer();
1053 VFrame *frame = frames[0][0];
1054 frame->transfer_from(&vframe);
1055 ret = file.write_video_buffer(1);
1059 asset->awindow_folder = AW_MEDIA_FOLDER;
1060 mwindow->edl->assets->append(asset);
1061 mwindow->awindow->gui->async_update_assets();
1064 eprintf(_("grabshot render failed"));
1065 asset->remove_user();
1071 void GrabshotPopup::update()
1073 set_color(grab_color ^= GREEN);
1074 draw_box(0,0, get_w(),get_h());
1078 void GrabshotPopup::draw_selection(int show)
1081 for( int i=0; i<4; ++i ) hide_window(0);
1086 int nx0 = x0 < x1 ? x0 : x1;
1087 int nx1 = x0 < x1 ? x1 : x0;
1088 int ny0 = y0 < y1 ? y0 : y1;
1089 int ny1 = y0 < y1 ? y1 : y0;
1090 lx0 = nx0; lx1 = nx1; ly0 = ny0; ly1 = ny1;
1093 BC_Popup **edge = grab_thread->edge;
1094 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
1095 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
1096 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
1097 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
1100 for( int i=0; i<4; ++i ) edge[i]->show_window(0);