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(menu_item = new BC_MenuItem(_("Sort...")));
80 menu_item->add_submenu(submenu = new BC_SubMenu());
81 submenu->add_submenuitem(new AssetPopupSortNames(mwindow, this));
82 submenu->add_submenuitem(new AssetPopupSortTimes(mwindow, this));
83 add_item(index = new AssetPopupBuildIndex(mwindow, this));
84 add_item(view = new AssetPopupView(mwindow, this));
85 add_item(view_window = new AssetPopupViewWindow(mwindow, this));
86 add_item(mixer = new AssetPopupMixer(mwindow, this));
87 add_item(new AssetPopupPaste(mwindow, this));
88 add_item(menu_item = new BC_MenuItem(_("Match...")));
89 menu_item->add_submenu(submenu = new BC_SubMenu());
90 submenu->add_submenuitem(new AssetMatchSize(mwindow, this));
91 submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
92 submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
93 add_item(menu_item = new BC_MenuItem(_("Remove...")));
94 menu_item->add_submenu(submenu = new BC_SubMenu());
95 submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
96 submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
99 void AssetPopup::paste_assets()
101 // Collect items into the drag vectors for temporary storage
102 gui->lock_window("AssetPopup::paste_assets");
103 mwindow->gui->lock_window("AssetPopup::paste_assets");
104 mwindow->cwindow->gui->lock_window("AssetPopup::paste_assets");
106 int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
107 gui->collect_assets(proxy);
108 mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
109 mwindow->edl->tracks->first, 0); // do not overwrite
110 mwindow->session->clear_drag_proxy();
112 gui->unlock_window();
113 mwindow->gui->unlock_window();
114 mwindow->cwindow->gui->unlock_window();
117 void AssetPopup::match_size()
119 // Collect items into the drag vectors for temporary storage
120 gui->collect_assets();
121 mwindow->gui->lock_window("AssetPopup::match_size");
122 mwindow->asset_to_size();
123 mwindow->gui->unlock_window();
126 void AssetPopup::match_rate()
128 // Collect items into the drag vectors for temporary storage
129 gui->collect_assets();
130 mwindow->gui->lock_window("AssetPopup::match_rate");
131 mwindow->asset_to_rate();
132 mwindow->gui->unlock_window();
135 void AssetPopup::match_all()
137 // Collect items into the drag vectors for temporary storage
138 gui->collect_assets();
139 mwindow->gui->lock_window("AssetPopup::match_rate");
140 mwindow->asset_to_all();
141 mwindow->gui->unlock_window();
144 int AssetPopup::update()
147 int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
148 gui->collect_assets(proxy);
153 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
154 : BC_MenuItem(_("Info..."))
156 this->mwindow = mwindow;
160 AssetPopupInfo::~AssetPopupInfo()
164 int AssetPopupInfo::handle_event()
167 popup->gui->get_abs_cursor(cur_x, cur_y);
168 int n = mwindow->session->drag_assets->size();
170 for( int i=0; i<n; ++i ) {
171 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
172 asset_edit->edit_asset(
173 mwindow->session->drag_assets->values[i], cur_x-30*i, cur_y-30*i);
176 else if( mwindow->session->drag_clips->size() ) {
177 popup->gui->awindow->clip_edit->edit_clip(
178 mwindow->session->drag_clips->values[0], cur_x, cur_y);
184 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
185 : BC_MenuItem(_("Rebuild index"))
187 this->mwindow = mwindow;
191 AssetPopupBuildIndex::~AssetPopupBuildIndex()
195 int AssetPopupBuildIndex::handle_event()
197 //printf("AssetPopupBuildIndex::handle_event 1\n");
198 mwindow->rebuild_indices();
203 AssetPopupSortNames::AssetPopupSortNames(MWindow *mwindow, AssetPopup *popup)
204 : BC_MenuItem(_("Sort names"))
206 this->mwindow = mwindow;
210 AssetPopupSortNames::~AssetPopupSortNames()
214 int AssetPopupSortNames::handle_event()
216 mwindow->awindow->gui->sort_assets(0);
220 AssetPopupSortTimes::AssetPopupSortTimes(MWindow *mwindow, AssetPopup *popup)
221 : BC_MenuItem(_("Sort times"))
223 this->mwindow = mwindow;
227 AssetPopupSortTimes::~AssetPopupSortTimes()
231 int AssetPopupSortTimes::handle_event()
233 mwindow->awindow->gui->sort_assets(1);
238 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
239 : BC_MenuItem(_("View"))
241 this->mwindow = mwindow;
245 AssetPopupView::~AssetPopupView()
249 int AssetPopupView::handle_event()
251 VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
253 if( mwindow->session->drag_assets->total )
254 vwindow->change_source(
255 mwindow->session->drag_assets->values[0]);
257 if( mwindow->session->drag_clips->total )
258 vwindow->change_source(
259 mwindow->session->drag_clips->values[0]);
265 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
266 : BC_MenuItem(_("View in new window"))
268 this->mwindow = mwindow;
272 AssetPopupViewWindow::~AssetPopupViewWindow()
276 int AssetPopupViewWindow::handle_event()
278 for( int i=0; i<mwindow->session->drag_assets->size(); ++i ) {
279 VWindow *vwindow = mwindow->get_viewer(1);
280 vwindow->gui->lock_window("AssetPopupView::handle_event 1");
281 vwindow->change_source(mwindow->session->drag_assets->get(i));
282 vwindow->gui->unlock_window();
284 for( int i=0; i<mwindow->session->drag_clips->size(); ++i ) {
285 VWindow *vwindow = mwindow->get_viewer(1);
286 vwindow->gui->lock_window("AssetPopupView::handle_event 2");
287 vwindow->change_source(mwindow->session->drag_clips->get(i));
288 vwindow->gui->unlock_window();
293 AssetPopupMixer::AssetPopupMixer(MWindow *mwindow, AssetPopup *popup)
294 : BC_MenuItem(_("Open Mixers"))
296 this->mwindow = mwindow;
300 AssetPopupMixer::~AssetPopupMixer()
304 int AssetPopupMixer::handle_event()
306 mwindow->gui->lock_window("AssetPopupMixer::handle_event");
307 mwindow->create_mixers();
308 mwindow->gui->unlock_window();
312 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
313 : BC_MenuItem(_("Paste"))
315 this->mwindow = mwindow;
319 AssetPopupPaste::~AssetPopupPaste()
323 int AssetPopupPaste::handle_event()
325 popup->paste_assets();
330 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
331 : BC_MenuItem(_("Match project size"))
333 this->mwindow = mwindow;
337 int AssetMatchSize::handle_event()
343 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
344 : BC_MenuItem(_("Match frame rate"))
346 this->mwindow = mwindow;
350 int AssetMatchRate::handle_event()
356 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
357 : BC_MenuItem(_("Match all"))
359 this->mwindow = mwindow;
363 int AssetMatchAll::handle_event()
370 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
371 : BC_MenuItem(_("Remove from project"))
373 this->mwindow = mwindow;
377 AssetPopupProjectRemove::~AssetPopupProjectRemove()
381 int AssetPopupProjectRemove::handle_event()
383 mwindow->remove_assets_from_project(1, 1,
384 mwindow->session->drag_assets,
385 mwindow->session->drag_clips);
390 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
391 : BC_MenuItem(_("Remove from disk"))
393 this->mwindow = mwindow;
398 AssetPopupDiskRemove::~AssetPopupDiskRemove()
402 int AssetPopupDiskRemove::handle_event()
404 mwindow->awindow->asset_remove->start();
409 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
410 : BC_PopupMenu(0, 0, 0, "", 0)
412 this->mwindow = mwindow;
416 AssetListMenu::~AssetListMenu()
418 if( !shots_displayed ) {
419 delete asset_snapshot;
420 delete asset_grabshot;
424 void AssetListMenu::create_objects()
426 add_item(load_file = new AssetPopupLoadFile(mwindow, gui));
427 add_item(format = new AWindowListFormat(mwindow, gui));
428 add_item(new AWindowListSort(mwindow, gui));
429 add_item(new AssetListCopy(mwindow, gui));
430 add_item(new AssetListPaste(mwindow, gui));
431 SnapshotSubMenu *snapshot_submenu;
432 add_item(asset_snapshot = new AssetSnapshot(mwindow, this));
433 asset_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(asset_snapshot));
434 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"), SNAPSHOT_PNG));
435 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
436 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
437 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("ppm"), SNAPSHOT_PPM));
438 GrabshotSubMenu *grabshot_submenu;
439 add_item(asset_grabshot = new AssetGrabshot(mwindow, this));
440 asset_grabshot->add_submenu(grabshot_submenu = new GrabshotSubMenu(asset_grabshot));
441 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("png"), GRABSHOT_PNG));
442 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("jpeg"), GRABSHOT_JPEG));
443 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("tiff"), GRABSHOT_TIFF));
444 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("ppm"), GRABSHOT_PPM));
445 update_titles(shots_displayed = 1);
448 AssetPopupLoadFile::AssetPopupLoadFile(MWindow *mwindow, AWindowGUI *gui)
449 : BC_MenuItem(_("Load files..."), "o", 'o')
451 this->mwindow = mwindow;
455 AssetPopupLoadFile::~AssetPopupLoadFile()
459 int AssetPopupLoadFile::handle_event()
461 mwindow->gui->mainmenu->load_file->thread->start();
465 void AssetListMenu::update_titles(int shots)
468 if( shots && !shots_displayed ) {
470 add_item(asset_snapshot);
471 add_item(asset_grabshot);
473 else if( !shots && shots_displayed ) {
475 remove_item(asset_snapshot);
476 remove_item(asset_grabshot);
480 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
481 : BC_MenuItem(_("Copy file list"))
483 this->mwindow = mwindow;
487 AssetListCopy::~AssetListCopy()
492 int AssetListCopy::handle_event()
495 MWindowGUI *gui = mwindow->gui;
496 gui->lock_window("AssetListCopy::handle_event");
497 mwindow->awindow->gui->collect_assets();
498 int n = mwindow->session->drag_assets->total;
499 for( int i=0; i<n; ++i ) {
500 Indexable *indexable = mwindow->session->drag_assets->values[i];
501 const char *path = indexable->path;
502 if( !*path ) continue;
503 len += strlen(path) + 1;
505 char *text = new char[len+1], *cp = text;
506 for( int i=0; i<n; ++i ) {
507 Indexable *indexable = mwindow->session->drag_assets->values[i];
508 const char *path = indexable->path;
509 if( !*path ) continue;
510 cp += sprintf(cp, "%s\n", path);
514 gui->get_abs_cursor(cur_x, cur_y, 0);
515 gui->unlock_window();
519 copy_dialog = new AssetCopyDialog(this);
520 copy_dialog->start(text, cur_x, cur_y);
523 eprintf(_("Nothing selected"));
529 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
536 void AssetCopyDialog::start(char *text, int x, int y)
540 this->x = x; this->y = y;
541 BC_DialogThread::start();
544 AssetCopyDialog::~AssetCopyDialog()
549 BC_Window* AssetCopyDialog::new_gui()
551 BC_DisplayInfo display_info;
553 copy_window = new AssetCopyWindow(this);
554 copy_window->create_objects();
558 void AssetCopyDialog::handle_done_event(int result)
560 delete [] text; text = 0;
563 void AssetCopyDialog::handle_close_event(int result)
569 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
570 : BC_Window(_(PROGRAM_NAME ": Copy File List"),
571 copy_dialog->x - 500/2, copy_dialog->y - 200/2,
572 500, 200, 500, 200, 1, 0, 1)
574 this->copy_dialog = copy_dialog;
577 AssetCopyWindow::~AssetCopyWindow()
581 void AssetCopyWindow::create_objects()
584 int x = 10, y = 10, pad = 5;
585 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
586 y += title->get_h() + pad;
587 int text_w = get_w() - x - 10;
588 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
589 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
590 char *text = copy_dialog->text;
591 int len = strlen(text) + BCTEXTLEN;
592 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
593 file_list->create_objects();
595 add_subwindow(new BC_OKButton(this));
599 int AssetCopyWindow::resize_event(int w, int h)
601 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
602 int text_w = w - fx - 10;
603 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
604 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
605 file_list->reposition_window(fx, fy, text_w, text_rows);
609 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
610 : BC_MenuItem(_("Paste file list"))
612 this->mwindow = mwindow;
616 AssetListPaste::~AssetListPaste()
621 int AssetListPaste::handle_event()
624 paste_dialog = new AssetPasteDialog(this);
626 paste_dialog->close_window();
628 gui->get_abs_cursor(cur_x, cur_y, 0);
629 paste_dialog->start(cur_x, cur_y);
633 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
640 AssetPasteDialog::~AssetPasteDialog()
645 BC_Window* AssetPasteDialog::new_gui()
647 paste_window = new AssetPasteWindow(this);
648 paste_window->create_objects();
652 void AssetPasteDialog::handle_done_event(int result)
655 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
656 ArrayList<char*> path_list;
657 path_list.set_array_delete();
659 for( const char *cp=bp; cp<ep && *cp; ) {
660 const char *dp = strchr(cp, '\n');
662 char path[BCTEXTLEN], *pp = path;
663 int len = sizeof(path)-1;
664 while( --len>0 && cp<dp ) *pp++ = *cp++;
667 if( !strlen(path) ) continue;
668 path_list.append(cstrdup(path));
670 if( !path_list.size() ) return;
672 MWindow *mwindow = paste->mwindow;
673 mwindow->interrupt_indexes();
674 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
675 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
676 mwindow->gui->unlock_window();
677 path_list.remove_all_objects();
678 mwindow->save_backup();
679 mwindow->restart_brender();
680 mwindow->session->changes_made = 1;
683 void AssetPasteDialog::handle_close_event(int result)
688 void AssetPasteDialog::start(int x, int y)
690 this->x = x; this->y = y;
691 BC_DialogThread::start();
694 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
695 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
696 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
697 500, 200, 500, 200, 1, 0, 1)
699 this->paste_dialog = paste_dialog;
702 AssetPasteWindow::~AssetPasteWindow()
706 void AssetPasteWindow::create_objects()
709 int x = 10, y = 10, pad = 5;
710 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
711 y += title->get_h() + pad;
712 int text_w = get_w() - x - 10;
713 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
714 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
715 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
716 file_list->create_objects();
717 add_subwindow(new BC_OKButton(this));
718 add_subwindow(new BC_CancelButton(this));
722 int AssetPasteWindow::resize_event(int w, int h)
724 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
725 int text_w = w - fx - 10;
726 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
727 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
728 file_list->reposition_window(fx, fy, text_w, text_rows);
734 AssetSnapshot::AssetSnapshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
735 : BC_MenuItem(_("Snapshot..."))
737 this->mwindow = mwindow;
738 this->asset_list_menu = asset_list_menu;
741 AssetSnapshot::~AssetSnapshot()
745 SnapshotSubMenu::SnapshotSubMenu(AssetSnapshot *asset_snapshot)
747 this->asset_snapshot = asset_snapshot;
750 SnapshotSubMenu::~SnapshotSubMenu()
754 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
757 this->submenu = submenu;
761 SnapshotMenuItem::~SnapshotMenuItem()
765 int SnapshotMenuItem::handle_event()
767 MWindow *mwindow = submenu->asset_snapshot->mwindow;
768 EDL *edl = mwindow->edl;
769 if( !edl->have_video() ) return 1;
771 Preferences *preferences = mwindow->preferences;
772 char filename[BCTEXTLEN];
773 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
774 time_t tt; time(&tt);
775 struct tm tm; localtime_r(&tt,&tm);
776 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
777 preferences->snapshot_path, _("snap"),
778 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
779 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
780 char *asset_path = FileSystem::basepath(filename);
781 Asset *asset = new Asset(asset_path);
782 delete [] asset_path;
784 int fw = edl->get_w(), fh = edl->get_h();
785 int fcolor_model = edl->session->color_model;
789 asset->format = FILE_PNG;
790 asset->png_use_alpha = 1;
793 asset->format = FILE_JPEG;
794 asset->jpeg_quality = 90;
797 asset->format = FILE_TIFF;
798 asset->tiff_cmodel = 0;
799 asset->tiff_compression = 0;
802 asset->format = FILE_PPM;
807 asset->audio_data = 0;
808 asset->video_data = 1;
809 asset->video_length = 1;
813 int processors = preferences->project_smp + 1;
814 if( processors > 8 ) processors = 8;
815 file.set_processors(processors);
816 int ret = file.open_file(preferences, asset, 0, 1);
818 file.start_video_thread(1, fcolor_model,
819 processors > 1 ? 2 : 1, 0);
820 VFrame ***frames = file.get_video_buffer();
821 VFrame *frame = frames[0][0];
822 TransportCommand command;
823 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
824 command.command = CURRENT_FRAME;
825 command.get_edl()->copy_all(edl);
826 command.change_type = CHANGE_ALL;
827 command.realtime = 0;
829 RenderEngine render_engine(0, preferences, 0, 0);
830 CICache video_cache(preferences);
831 render_engine.set_vcache(&video_cache);
832 render_engine.arm_command(&command);
834 double position = edl->local_session->get_selectionstart(1);
835 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
836 ret = !render_engine.vrender ? 1 :
837 render_engine.vrender->process_buffer(frame, source_position, 0);
839 ret = file.write_video_buffer(1);
843 asset->awindow_folder = AW_MEDIA_FOLDER;
844 mwindow->edl->assets->append(asset);
845 mwindow->awindow->gui->async_update_assets();
848 eprintf(_("snapshot render failed"));
849 asset->remove_user();
855 AssetGrabshot::AssetGrabshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
856 : BC_MenuItem(_("Grabshot..."))
858 this->mwindow = mwindow;
859 this->asset_list_menu = asset_list_menu;
862 AssetGrabshot::~AssetGrabshot()
866 GrabshotSubMenu::GrabshotSubMenu(AssetGrabshot *asset_grabshot)
868 this->asset_grabshot = asset_grabshot;
871 GrabshotSubMenu::~GrabshotSubMenu()
875 GrabshotMenuItem::GrabshotMenuItem(GrabshotSubMenu *submenu, const char *text, int mode)
878 this->submenu = submenu;
883 GrabshotMenuItem::~GrabshotMenuItem()
888 int GrabshotMenuItem::handle_event()
891 grab_thread = new GrabshotThread(submenu->asset_grabshot->mwindow);
892 if( !grab_thread->running() )
893 grab_thread->start(this);
897 GrabshotThread::GrabshotThread(MWindow *mwindow)
900 this->mwindow = mwindow;
904 GrabshotThread::~GrabshotThread()
909 void GrabshotThread::start(GrabshotMenuItem *menu_item)
911 popup = new GrabshotPopup(this, menu_item->mode);
912 popup->lock_window("GrabshotThread::start");
913 for( int i=0; i<4; ++i )
914 edge[i] = new BC_Popup(mwindow->gui, 0,0, 1,1, ORANGE, 1);
915 mwindow->gui->grab_buttons();
916 mwindow->gui->grab_cursor();
917 popup->grab(mwindow->gui);
918 popup->create_objects();
919 popup->show_window();
920 popup->unlock_window();
925 void GrabshotThread::run()
927 popup->lock_window("GrabshotThread::run 0");
930 popup->unlock_window();
934 popup->lock_window("GrabshotThread::run 1");
936 mwindow->gui->ungrab_cursor();
937 mwindow->gui->ungrab_buttons();
938 popup->ungrab(mwindow->gui);
939 for( int i=0; i<4; ++i ) delete edge[i];
940 popup->unlock_window();
941 delete popup; popup = 0;
944 GrabshotPopup::GrabshotPopup(GrabshotThread *grab_thread, int mode)
945 : BC_Popup(grab_thread->mwindow->gui, 0,0, 16,16, -1,1)
947 this->grab_thread = grab_thread;
951 x0 = y0 = x1 = y1 = -1;
952 lx0 = ly0 = lx1 = ly1 = -1;
954 GrabshotPopup::~GrabshotPopup()
958 int GrabshotPopup::grab_event(XEvent *event)
960 int cur_drag = dragging;
961 switch( event->type ) {
963 if( cur_drag > 0 ) return 1;
964 x0 = event->xbutton.x_root;
965 y0 = event->xbutton.y_root;
968 if( event->xbutton.button == RIGHT_BUTTON ) break;
969 if( x0>=get_x() && x0<get_x()+get_w() &&
970 y0>=get_y() && y0<get_y()+get_h() ) break;
980 x1 = event->xbutton.x_root;
981 y1 = event->xbutton.y_root;
989 int cx = lx0, cy = ly0;
990 int cw = lx1-lx0, ch = ly1-ly0;
993 grab_thread->done = 1;
995 MWindow *mwindow = grab_thread->mwindow;
996 Preferences *preferences = mwindow->preferences;
997 char filename[BCTEXTLEN];
998 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
999 time_t tt; time(&tt);
1000 struct tm tm; localtime_r(&tt,&tm);
1001 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
1002 preferences->snapshot_path, _("grab"),
1003 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
1004 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
1005 char *asset_path = FileSystem::basepath(filename);
1006 Asset *asset = new Asset(asset_path);
1007 delete [] asset_path;
1010 asset->format = FILE_PNG;
1011 asset->png_use_alpha = 1;
1014 asset->format = FILE_JPEG;
1015 asset->jpeg_quality = 90;
1018 asset->format = FILE_TIFF;
1019 asset->tiff_cmodel = 0;
1020 asset->tiff_compression = 0;
1023 asset->format = FILE_PPM;
1027 // no odd dimensions
1028 int rw = get_root_w(0), rh = get_root_h(0);
1029 if( cx < 0 ) { cw += cx; cx = 0; }
1030 if( cy < 0 ) { ch += cy; cy = 0; }
1031 if( cx+cw > rw ) cw = rw-cx;
1032 if( cy+ch > rh ) ch = rh-cy;
1033 if( !cw || !ch ) return 1;
1035 VFrame vframe(cw,ch, BC_RGB888);
1036 if( cx+cw < rw ) ++cw;
1037 if( cy+ch < rh ) ++ch;
1038 BC_Capture capture_bitmap(cw,ch, 0);
1039 capture_bitmap.capture_frame(&vframe, cx,cy);
1041 asset->width = vframe.get_w();
1042 asset->height = vframe.get_h();
1043 asset->audio_data = 0;
1044 asset->video_data = 1;
1045 asset->video_length = 1;
1049 int fcolor_model = mwindow->edl->session->color_model;
1050 int processors = preferences->project_smp + 1;
1051 if( processors > 8 ) processors = 8;
1052 file.set_processors(processors);
1053 int ret = file.open_file(preferences, asset, 0, 1);
1055 file.start_video_thread(1, fcolor_model,
1056 processors > 1 ? 2 : 1, 0);
1057 VFrame ***frames = file.get_video_buffer();
1058 VFrame *frame = frames[0][0];
1059 frame->transfer_from(&vframe);
1060 ret = file.write_video_buffer(1);
1064 asset->awindow_folder = AW_MEDIA_FOLDER;
1065 mwindow->edl->assets->append(asset);
1066 mwindow->awindow->gui->async_update_assets();
1069 eprintf(_("grabshot render failed"));
1070 asset->remove_user();
1076 void GrabshotPopup::update()
1078 set_color(grab_color ^= GREEN);
1079 draw_box(0,0, get_w(),get_h());
1083 void GrabshotPopup::draw_selection(int show)
1086 for( int i=0; i<4; ++i ) hide_window(0);
1091 int nx0 = x0 < x1 ? x0 : x1;
1092 int nx1 = x0 < x1 ? x1 : x0;
1093 int ny0 = y0 < y1 ? y0 : y1;
1094 int ny1 = y0 < y1 ? y1 : y0;
1095 lx0 = nx0; lx1 = nx1; ly0 = ny0; ly1 = ny1;
1098 BC_Popup **edge = grab_thread->edge;
1099 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
1100 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
1101 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
1102 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
1105 for( int i=0; i<4; ++i ) edge[i]->show_window(0);