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 ArrayList<ZWindow *>new_mixers;
305 mwindow->select_zwindow(0);
306 for( int i=0; i<mwindow->session->drag_assets->total; ++i ) {
307 Indexable *indexable = mwindow->session->drag_assets->values[i];
308 ArrayList<Indexable*> new_assets;
309 new_assets.append(indexable);
310 Track *track = mwindow->edl->tracks->last;
311 mwindow->load_assets(&new_assets, -1, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
312 track = !track ? mwindow->edl->tracks->first : track->next;
314 ZWindow *zwindow = mwindow->get_mixer(mixer);
316 track->play = track->record = 0;
317 if( track->data_type == TRACK_VIDEO ) {
318 sprintf(track->title, _("Mixer %d"), zwindow->idx);
320 mixer->mixer_ids.append(track->get_mixer_id());
323 char *path = indexable->path;
324 char *tp = strrchr(path, '/');
325 if( !tp ) tp = path; else ++tp;
326 zwindow->set_title(tp);
327 new_mixers.append(zwindow);
330 mwindow->tile_mixers();
331 for( int i=0; i<new_mixers.size(); ++i )
332 new_mixers[i]->start();
334 mwindow->refresh_mixers();
335 mwindow->resync_guis();
339 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
340 : BC_MenuItem(_("Paste"))
342 this->mwindow = mwindow;
346 AssetPopupPaste::~AssetPopupPaste()
350 int AssetPopupPaste::handle_event()
352 popup->paste_assets();
357 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
358 : BC_MenuItem(_("Match project size"))
360 this->mwindow = mwindow;
364 int AssetMatchSize::handle_event()
370 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
371 : BC_MenuItem(_("Match frame rate"))
373 this->mwindow = mwindow;
377 int AssetMatchRate::handle_event()
383 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
384 : BC_MenuItem(_("Match all"))
386 this->mwindow = mwindow;
390 int AssetMatchAll::handle_event()
397 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
398 : BC_MenuItem(_("Remove from project"))
400 this->mwindow = mwindow;
404 AssetPopupProjectRemove::~AssetPopupProjectRemove()
408 int AssetPopupProjectRemove::handle_event()
410 mwindow->remove_assets_from_project(1, 1,
411 mwindow->session->drag_assets,
412 mwindow->session->drag_clips);
417 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
418 : BC_MenuItem(_("Remove from disk"))
420 this->mwindow = mwindow;
425 AssetPopupDiskRemove::~AssetPopupDiskRemove()
429 int AssetPopupDiskRemove::handle_event()
431 mwindow->awindow->asset_remove->start();
436 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
437 : BC_PopupMenu(0, 0, 0, "", 0)
439 this->mwindow = mwindow;
443 AssetListMenu::~AssetListMenu()
445 if( !shots_displayed ) {
446 delete asset_snapshot;
447 delete asset_grabshot;
451 void AssetListMenu::create_objects()
453 add_item(format = new AWindowListFormat(mwindow, gui));
454 add_item(new AWindowListSort(mwindow, gui));
455 add_item(new AssetListCopy(mwindow, gui));
456 add_item(new AssetListPaste(mwindow, gui));
457 SnapshotSubMenu *snapshot_submenu;
458 add_item(asset_snapshot = new AssetSnapshot(mwindow, this));
459 asset_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(asset_snapshot));
460 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"), SNAPSHOT_PNG));
461 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
462 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
463 GrabshotSubMenu *grabshot_submenu;
464 add_item(asset_grabshot = new AssetGrabshot(mwindow, this));
465 asset_grabshot->add_submenu(grabshot_submenu = new GrabshotSubMenu(asset_grabshot));
466 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("png"), GRABSHOT_PNG));
467 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("jpeg"), GRABSHOT_JPEG));
468 grabshot_submenu->add_submenuitem(new GrabshotMenuItem(grabshot_submenu, _("tiff"), GRABSHOT_TIFF));
469 update_titles(shots_displayed = 1);
472 void AssetListMenu::update_titles(int shots)
475 if( shots && !shots_displayed ) {
477 add_item(asset_snapshot);
478 add_item(asset_grabshot);
480 else if( !shots && shots_displayed ) {
482 remove_item(asset_snapshot);
483 remove_item(asset_grabshot);
487 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
488 : BC_MenuItem(_("Copy file list"))
490 this->mwindow = mwindow;
494 AssetListCopy::~AssetListCopy()
499 int AssetListCopy::handle_event()
502 MWindowGUI *gui = mwindow->gui;
503 gui->lock_window("AssetListCopy::handle_event");
504 mwindow->awindow->gui->collect_assets();
505 int n = mwindow->session->drag_assets->total;
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 len += strlen(path) + 1;
512 char *text = new char[len+1], *cp = text;
513 for( int i=0; i<n; ++i ) {
514 Indexable *indexable = mwindow->session->drag_assets->values[i];
515 const char *path = indexable->path;
516 if( !*path ) continue;
517 cp += sprintf(cp, "%s\n", path);
521 gui->get_abs_cursor(cur_x, cur_y, 0);
522 gui->unlock_window();
526 copy_dialog = new AssetCopyDialog(this);
527 copy_dialog->start(text, cur_x, cur_y);
530 eprintf(_("Nothing selected"));
536 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
543 void AssetCopyDialog::start(char *text, int x, int y)
547 this->x = x; this->y = y;
548 BC_DialogThread::start();
551 AssetCopyDialog::~AssetCopyDialog()
556 BC_Window* AssetCopyDialog::new_gui()
558 BC_DisplayInfo display_info;
560 copy_window = new AssetCopyWindow(this);
561 copy_window->create_objects();
565 void AssetCopyDialog::handle_done_event(int result)
567 delete [] text; text = 0;
570 void AssetCopyDialog::handle_close_event(int result)
576 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
577 : BC_Window(_(PROGRAM_NAME ": Copy File List"),
578 copy_dialog->x - 500/2, copy_dialog->y - 200/2,
579 500, 200, 500, 200, 1, 0, 1)
581 this->copy_dialog = copy_dialog;
584 AssetCopyWindow::~AssetCopyWindow()
588 void AssetCopyWindow::create_objects()
591 int x = 10, y = 10, pad = 5;
592 add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
593 y += title->get_h() + pad;
594 int text_w = get_w() - x - 10;
595 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
596 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
597 char *text = copy_dialog->text;
598 int len = strlen(text) + BCTEXTLEN;
599 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
600 file_list->create_objects();
602 add_subwindow(new BC_OKButton(this));
606 int AssetCopyWindow::resize_event(int w, int h)
608 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
609 int text_w = w - fx - 10;
610 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
611 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
612 file_list->reposition_window(fx, fy, text_w, text_rows);
616 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
617 : BC_MenuItem(_("Paste file list"))
619 this->mwindow = mwindow;
623 AssetListPaste::~AssetListPaste()
628 int AssetListPaste::handle_event()
631 paste_dialog = new AssetPasteDialog(this);
633 paste_dialog->close_window();
635 gui->get_abs_cursor(cur_x, cur_y, 0);
636 paste_dialog->start(cur_x, cur_y);
640 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
647 AssetPasteDialog::~AssetPasteDialog()
652 BC_Window* AssetPasteDialog::new_gui()
654 paste_window = new AssetPasteWindow(this);
655 paste_window->create_objects();
659 void AssetPasteDialog::handle_done_event(int result)
662 const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
663 ArrayList<char*> path_list;
664 path_list.set_array_delete();
666 for( const char *cp=bp; cp<ep && *cp; ) {
667 const char *dp = strchr(cp, '\n');
669 char path[BCTEXTLEN], *pp = path;
670 int len = sizeof(path)-1;
671 while( --len>0 && cp<dp ) *pp++ = *cp++;
674 if( !strlen(path) ) continue;
675 path_list.append(cstrdup(path));
677 if( !path_list.size() ) return;
679 MWindow *mwindow = paste->mwindow;
680 mwindow->interrupt_indexes();
681 mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
682 result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
683 mwindow->gui->unlock_window();
684 path_list.remove_all_objects();
685 mwindow->save_backup();
686 mwindow->restart_brender();
687 mwindow->session->changes_made = 1;
690 void AssetPasteDialog::handle_close_event(int result)
695 void AssetPasteDialog::start(int x, int y)
697 this->x = x; this->y = y;
698 BC_DialogThread::start();
701 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
702 : BC_Window(_(PROGRAM_NAME ": Paste File List"),
703 paste_dialog->x - 500/2, paste_dialog->y - 200/2,
704 500, 200, 500, 200, 1, 0, 1)
706 this->paste_dialog = paste_dialog;
709 AssetPasteWindow::~AssetPasteWindow()
713 void AssetPasteWindow::create_objects()
716 int x = 10, y = 10, pad = 5;
717 add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
718 y += title->get_h() + pad;
719 int text_w = get_w() - x - 10;
720 int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
721 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
722 file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
723 file_list->create_objects();
724 add_subwindow(new BC_OKButton(this));
725 add_subwindow(new BC_CancelButton(this));
729 int AssetPasteWindow::resize_event(int w, int h)
731 int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
732 int text_w = w - fx - 10;
733 int text_h = h - fy - BC_OKButton::calculate_h() - pad;
734 int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
735 file_list->reposition_window(fx, fy, text_w, text_rows);
741 AssetSnapshot::AssetSnapshot(MWindow *mwindow, AssetListMenu *asset_list_menu)
742 : BC_MenuItem(_("Snapshot..."))
744 this->mwindow = mwindow;
745 this->asset_list_menu = asset_list_menu;
748 AssetSnapshot::~AssetSnapshot()
752 SnapshotSubMenu::SnapshotSubMenu(AssetSnapshot *asset_snapshot)
754 this->asset_snapshot = asset_snapshot;
757 SnapshotSubMenu::~SnapshotSubMenu()
761 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
764 this->submenu = submenu;
768 SnapshotMenuItem::~SnapshotMenuItem()
772 int SnapshotMenuItem::handle_event()
774 MWindow *mwindow = submenu->asset_snapshot->mwindow;
775 EDL *edl = mwindow->edl;
776 if( !edl->have_video() ) return 1;
778 Preferences *preferences = mwindow->preferences;
779 char filename[BCTEXTLEN];
780 static const char *exts[] = { "png", "jpg", "tif" };
781 time_t tt; time(&tt);
782 struct tm tm; localtime_r(&tt,&tm);
783 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
784 preferences->snapshot_path, _("snap"),
785 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
786 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
787 int fw = edl->get_w(), fh = edl->get_h();
788 int fcolor_model = edl->session->color_model;
790 Asset *asset = new Asset(filename);
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;
808 asset->audio_data = 0;
809 asset->video_data = 1;
810 asset->video_length = 1;
814 int processors = preferences->project_smp + 1;
815 if( processors > 8 ) processors = 8;
816 file.set_processors(processors);
817 int ret = file.open_file(preferences, asset, 0, 1);
819 file.start_video_thread(1, fcolor_model,
820 processors > 1 ? 2 : 1, 0);
821 VFrame ***frames = file.get_video_buffer();
822 VFrame *frame = frames[0][0];
823 TransportCommand command;
824 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
825 command.command = CURRENT_FRAME;
826 command.get_edl()->copy_all(edl);
827 command.change_type = CHANGE_ALL;
828 command.realtime = 0;
830 RenderEngine render_engine(0, preferences, 0, 0);
831 CICache video_cache(preferences);
832 render_engine.set_vcache(&video_cache);
833 render_engine.arm_command(&command);
835 double position = edl->local_session->get_selectionstart(1);
836 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
837 ret = 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;
994 MWindow *mwindow = grab_thread->mwindow;
995 Preferences *preferences = mwindow->preferences;
996 char filename[BCTEXTLEN];
997 static const char *exts[] = { "png", "jpg", "tif" };
998 time_t tt; time(&tt);
999 struct tm tm; localtime_r(&tt,&tm);
1000 snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
1001 preferences->snapshot_path, _("grab"),
1002 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
1003 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
1005 Asset *asset = new Asset(filename);
1008 asset->format = FILE_PNG;
1009 asset->png_use_alpha = 1;
1012 asset->format = FILE_JPEG;
1013 asset->jpeg_quality = 90;
1016 asset->format = FILE_TIFF;
1017 asset->tiff_cmodel = 0;
1018 asset->tiff_compression = 0;
1021 // no odd dimensions
1022 int rw = get_root_w(0), rh = get_root_h(0);
1023 if( cx < 0 ) { cw += cx; cx = 0; }
1024 if( cy < 0 ) { ch += cy; cy = 0; }
1025 if( cx+cw > rw ) cw = rw-cx;
1026 if( cy+ch > rh ) ch = rh-cy;
1027 VFrame vframe(cw,ch, BC_RGB888);
1028 if( cx+cw < rw ) ++cw;
1029 if( cy+ch < rh ) ++ch;
1030 BC_Capture capture_bitmap(cw,ch, 0);
1031 capture_bitmap.capture_frame(&vframe, cx,cy);
1033 asset->width = vframe.get_w();
1034 asset->height = vframe.get_h();
1035 asset->audio_data = 0;
1036 asset->video_data = 1;
1037 asset->video_length = 1;
1041 int fcolor_model = mwindow->edl->session->color_model;
1042 int processors = preferences->project_smp + 1;
1043 if( processors > 8 ) processors = 8;
1044 file.set_processors(processors);
1045 int ret = file.open_file(preferences, asset, 0, 1);
1047 file.start_video_thread(1, fcolor_model,
1048 processors > 1 ? 2 : 1, 0);
1049 VFrame ***frames = file.get_video_buffer();
1050 VFrame *frame = frames[0][0];
1051 frame->transfer_from(&vframe);
1052 ret = file.write_video_buffer(1);
1056 asset->awindow_folder = AW_MEDIA_FOLDER;
1057 mwindow->edl->assets->append(asset);
1058 mwindow->awindow->gui->async_update_assets();
1061 eprintf(_("grabshot render failed"));
1062 asset->remove_user();
1065 grab_thread->done = 1;
1069 void GrabshotPopup::update()
1071 set_color(grab_color ^= GREEN);
1072 draw_box(0,0, get_w(),get_h());
1076 void GrabshotPopup::draw_selection(int show)
1079 for( int i=0; i<4; ++i ) hide_window(0);
1084 int nx0 = x0 < x1 ? x0 : x1;
1085 int nx1 = x0 < x1 ? x1 : x0;
1086 int ny0 = y0 < y1 ? y0 : y1;
1087 int ny1 = y0 < y1 ? y1 : y0;
1088 lx0 = nx0; lx1 = nx1; ly0 = ny0; ly1 = ny1;
1091 BC_Popup **edge = grab_thread->edge;
1092 edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
1093 edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
1094 edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
1095 edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
1098 for( int i=0; i<4; ++i ) edge[i]->show_window(0);