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()
583 lock_window("AssetCopyWindow::create_objects");
585 int x = 10, y = 10, pad = 5;
586 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
587 y += title->get_h() + pad;
588 int text_w = get_w() - x - 10;
589 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
590 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
591 char *text = copy_dialog->text;
592 int len = strlen(text) + BCTEXTLEN;
593 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
594 file_list->create_objects();
596 add_subwindow(new BC_OKButton(this));
601 int AssetCopyWindow::resize_event(int w, int h)
603 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
604 int text_w = w - fx - 10;
605 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
606 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
607 file_list->reposition_window(fx, fy, text_w, text_rows);
611 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
612 : BC_MenuItem(_("Paste file list"))
614 this->mwindow = mwindow;
618 AssetListPaste::~AssetListPaste()
623 int AssetListPaste::handle_event()
626 paste_dialog = new AssetPasteDialog(this);
628 paste_dialog->close_window();
630 gui->get_abs_cursor(cur_x, cur_y, 0);
631 paste_dialog->start(cur_x, cur_y);
635 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
642 AssetPasteDialog::~AssetPasteDialog()
647 BC_Window* AssetPasteDialog::new_gui()
649 paste_window = new AssetPasteWindow(this);
650 paste_window->create_objects();
654 void AssetPasteDialog::handle_done_event(int result)
657 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
658 ArrayList<char*> path_list;
659 path_list.set_array_delete();
661 for( const char *cp=bp; cp<ep && *cp; ) {
662 const char *dp = strchr(cp, '\n');
664 char path[BCTEXTLEN], *pp = path;
665 int len = sizeof(path)-1;
666 while( --len>0 && cp<dp ) *pp++ = *cp++;
669 if( !strlen(path) ) continue;
670 path_list.append(cstrdup(path));
672 if( !path_list.size() ) return;
674 MWindow *mwindow = paste->mwindow;
675 mwindow->interrupt_indexes();
676 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
677 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
678 mwindow->gui->unlock_window();
679 path_list.remove_all_objects();
680 mwindow->save_backup();
681 mwindow->restart_brender();
682 mwindow->session->changes_made = 1;
685 void AssetPasteDialog::handle_close_event(int result)
690 void AssetPasteDialog::start(int x, int y)
692 this->x = x; this->y = y;
693 BC_DialogThread::start();
696 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
697 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
698 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
699 500, 200, 500, 200, 1, 0, 1)
701 this->paste_dialog = paste_dialog;
704 AssetPasteWindow::~AssetPasteWindow()
708 void AssetPasteWindow::create_objects()
710 lock_window("AssetPasteWindow::create_objects()");
712 int x = 10, y = 10, pad = 5;
713 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
714 y += title->get_h() + pad;
715 int text_w = get_w() - x - 10;
716 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
717 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
718 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
719 file_list->create_objects();
720 add_subwindow(new BC_OKButton(this));
721 add_subwindow(new BC_CancelButton(this));
726 int AssetPasteWindow::resize_event(int w, int h)
728 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
729 int text_w = w - fx - 10;
730 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
731 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
732 file_list->reposition_window(fx, fy, text_w, text_rows);
738 AssetSnapshot::AssetSnapshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
739 : BC_MenuItem(_("Snapshot..."))
741 this->mwindow = mwindow;
742 this->asset_list_menu = asset_list_menu;
745 AssetSnapshot::~AssetSnapshot()
749 SnapshotSubMenu::SnapshotSubMenu(AssetSnapshot *asset_snapshot)
751 this->asset_snapshot = asset_snapshot;
754 SnapshotSubMenu::~SnapshotSubMenu()
758 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
761 this->submenu = submenu;
765 SnapshotMenuItem::~SnapshotMenuItem()
769 int SnapshotMenuItem::handle_event()
771 MWindow *mwindow = submenu->asset_snapshot->mwindow;
772 EDL *edl = mwindow->edl;
773 if( !edl->have_video() ) return 1;
775 Preferences *preferences = mwindow->preferences;
776 char filename[BCTEXTLEN];
777 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
778 time_t tt; time(&tt);
779 struct tm tm; localtime_r(&tt,&tm);
780 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
781 preferences->snapshot_path, _("snap"),
782 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
783 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
784 char *asset_path = FileSystem::basepath(filename);
785 Asset *asset = new Asset(asset_path);
786 delete [] asset_path;
788 int fw = edl->get_w(), fh = edl->get_h();
789 int fcolor_model = edl->session->color_model;
793 asset->format = FILE_PNG;
794 asset->png_use_alpha = 1;
797 asset->format = FILE_JPEG;
798 asset->jpeg_quality = 90;
801 asset->format = FILE_TIFF;
802 asset->tiff_cmodel = 0;
803 asset->tiff_compression = 0;
806 asset->format = FILE_PPM;
811 asset->audio_data = 0;
812 asset->video_data = 1;
813 asset->video_length = 1;
817 int processors = preferences->project_smp + 1;
818 if( processors > 8 ) processors = 8;
819 file.set_processors(processors);
820 int ret = file.open_file(preferences, asset, 0, 1);
822 file.start_video_thread(1, fcolor_model,
823 processors > 1 ? 2 : 1, 0);
824 VFrame ***frames = file.get_video_buffer();
825 VFrame *frame = frames[0][0];
826 TransportCommand command;
827 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
828 command.command = CURRENT_FRAME;
829 command.get_edl()->copy_all(edl);
830 command.change_type = CHANGE_ALL;
831 command.realtime = 0;
833 RenderEngine render_engine(0, preferences, 0, 0);
834 CICache video_cache(preferences);
835 render_engine.set_vcache(&video_cache);
836 render_engine.arm_command(&command);
838 double position = edl->local_session->get_selectionstart(1);
839 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
840 ret = !render_engine.vrender ? 1 :
841 render_engine.vrender->process_buffer(frame, source_position, 0);
843 ret = file.write_video_buffer(1);
847 asset->awindow_folder = AW_MEDIA_FOLDER;
848 mwindow->edl->assets->append(asset);
849 mwindow->awindow->gui->async_update_assets();
852 eprintf(_("snapshot render failed"));
853 asset->remove_user();
859 AssetGrabshot::AssetGrabshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
860 : BC_MenuItem(_("Grabshot..."))
862 this->mwindow = mwindow;
863 this->asset_list_menu = asset_list_menu;
866 AssetGrabshot::~AssetGrabshot()
870 GrabshotSubMenu::GrabshotSubMenu(AssetGrabshot *asset_grabshot)
872 this->asset_grabshot = asset_grabshot;
875 GrabshotSubMenu::~GrabshotSubMenu()
879 GrabshotMenuItem::GrabshotMenuItem(GrabshotSubMenu *submenu, const char *text, int mode)
882 this->submenu = submenu;
887 GrabshotMenuItem::~GrabshotMenuItem()
892 int GrabshotMenuItem::handle_event()
895 grab_thread = new GrabshotThread(submenu->asset_grabshot->mwindow);
896 if( !grab_thread->running() )
897 grab_thread->start(this);
901 GrabshotThread::GrabshotThread(MWindow *mwindow)
904 this->mwindow = mwindow;
908 GrabshotThread::~GrabshotThread()
913 void GrabshotThread::start(GrabshotMenuItem *menu_item)
915 popup = new GrabshotPopup(this, menu_item->mode);
916 popup->lock_window("GrabshotThread::start");
917 for( int i=0; i<4; ++i )
918 edge[i] = new BC_Popup(mwindow->gui, 0,0, 1,1, ORANGE, 1);
919 mwindow->gui->grab_buttons();
920 mwindow->gui->grab_cursor();
921 popup->grab(mwindow->gui);
922 popup->create_objects();
923 popup->show_window();
924 popup->unlock_window();
929 void GrabshotThread::run()
931 popup->lock_window("GrabshotThread::run 0");
934 popup->unlock_window();
938 popup->lock_window("GrabshotThread::run 1");
940 mwindow->gui->ungrab_cursor();
941 mwindow->gui->ungrab_buttons();
942 popup->ungrab(mwindow->gui);
943 for( int i=0; i<4; ++i ) delete edge[i];
944 popup->unlock_window();
945 delete popup; popup = 0;
948 GrabshotPopup::GrabshotPopup(GrabshotThread *grab_thread, int mode)
949 : BC_Popup(grab_thread->mwindow->gui, 0,0, 16,16, -1,1)
951 this->grab_thread = grab_thread;
955 x0 = y0 = x1 = y1 = -1;
956 lx0 = ly0 = lx1 = ly1 = -1;
958 GrabshotPopup::~GrabshotPopup()
962 int GrabshotPopup::grab_event(XEvent *event)
964 int cur_drag = dragging;
965 switch( event->type ) {
967 if( cur_drag > 0 ) return 1;
968 x0 = event->xbutton.x_root;
969 y0 = event->xbutton.y_root;
972 if( event->xbutton.button == RIGHT_BUTTON ) break;
973 if( x0>=get_x() && x0<get_x()+get_w() &&
974 y0>=get_y() && y0<get_y()+get_h() ) break;
984 x1 = event->xbutton.x_root;
985 y1 = event->xbutton.y_root;
993 int cx = lx0, cy = ly0;
994 int cw = lx1-lx0, ch = ly1-ly0;
997 grab_thread->done = 1;
999 MWindow *mwindow = grab_thread->mwindow;
1000 Preferences *preferences = mwindow->preferences;
1001 char filename[BCTEXTLEN];
1002 static const char *exts[] = { "png", "jpg", "tif", "ppm" };
1003 time_t tt; time(&tt);
1004 struct tm tm; localtime_r(&tt,&tm);
1005 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
1006 preferences->snapshot_path, _("grab"),
1007 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
1008 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
1009 char *asset_path = FileSystem::basepath(filename);
1010 Asset *asset = new Asset(asset_path);
1011 delete [] asset_path;
1014 asset->format = FILE_PNG;
1015 asset->png_use_alpha = 1;
1018 asset->format = FILE_JPEG;
1019 asset->jpeg_quality = 90;
1022 asset->format = FILE_TIFF;
1023 asset->tiff_cmodel = 0;
1024 asset->tiff_compression = 0;
1027 asset->format = FILE_PPM;
1031 // no odd dimensions
1032 int rw = get_root_w(0), rh = get_root_h(0);
1033 if( cx < 0 ) { cw += cx; cx = 0; }
1034 if( cy < 0 ) { ch += cy; cy = 0; }
1035 if( cx+cw > rw ) cw = rw-cx;
1036 if( cy+ch > rh ) ch = rh-cy;
1037 if( !cw || !ch ) return 1;
1039 VFrame vframe(cw,ch, BC_RGB888);
1040 if( cx+cw < rw ) ++cw;
1041 if( cy+ch < rh ) ++ch;
1042 BC_Capture capture_bitmap(cw,ch, 0);
1043 capture_bitmap.capture_frame(&vframe, cx,cy);
1045 asset->width = vframe.get_w();
1046 asset->height = vframe.get_h();
1047 asset->audio_data = 0;
1048 asset->video_data = 1;
1049 asset->video_length = 1;
1053 int fcolor_model = mwindow->edl->session->color_model;
1054 int processors = preferences->project_smp + 1;
1055 if( processors > 8 ) processors = 8;
1056 file.set_processors(processors);
1057 int ret = file.open_file(preferences, asset, 0, 1);
1059 file.start_video_thread(1, fcolor_model,
1060 processors > 1 ? 2 : 1, 0);
1061 VFrame ***frames = file.get_video_buffer();
1062 VFrame *frame = frames[0][0];
1063 frame->transfer_from(&vframe);
1064 ret = file.write_video_buffer(1);
1068 asset->awindow_folder = AW_MEDIA_FOLDER;
1069 mwindow->edl->assets->append(asset);
1070 mwindow->awindow->gui->async_update_assets();
1073 eprintf(_("grabshot render failed"));
1074 asset->remove_user();
1080 void GrabshotPopup::update()
1082 set_color(grab_color ^= GREEN);
1083 draw_box(0,0, get_w(),get_h());
1087 void GrabshotPopup::draw_selection(int show)
1090 for( int i=0; i<4; ++i ) hide_window(0);
1095 int nx0 = x0 < x1 ? x0 : x1;
1096 int nx1 = x0 < x1 ? x1 : x0;
1097 int ny0 = y0 < y1 ? y0 : y1;
1098 int ny1 = y0 < y1 ? y1 : y0;
1099 lx0 = nx0; lx1 = nx1; ly0 = ny0; ly1 = ny1;
1102 BC_Popup **edge = grab_thread->edge;
1103 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
1104 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
1105 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
1106 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
1109 for( int i=0; i<4; ++i ) edge[i]->show_window(0);