4 * Copyright (C) 2008 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
25 #include "awindowgui.h"
27 #include "editpopup.h"
30 #include "edlsession.h"
33 #include "localsession.h"
34 #include "mainerror.h"
35 #include "mainsession.h"
37 #include "mwindowgui.h"
38 #include "plugindialog.h"
39 #include "preferences.h"
40 #include "renderengine.h"
41 #include "resizetrackthread.h"
44 #include "trackcanvas.h"
45 #include "transportque.h"
51 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
52 : BC_PopupMenu(0, 0, 0, "", 0)
54 this->mwindow = mwindow;
58 EditPopup::~EditPopup()
62 void EditPopup::create_objects()
64 add_item(new EditAttachEffect(mwindow, this));
65 add_item(new EditMoveTrackUp(mwindow, this));
66 add_item(new EditMoveTrackDown(mwindow, this));
67 add_item(new EditPopupDeleteTrack(mwindow, this));
68 add_item(new EditPopupAddTrack(mwindow, this));
69 // add_item(new EditPopupTitle(mwindow, this));
70 EditSnapshot *edit_snapshot;
71 SnapshotSubMenu *snapshot_submenu;
72 add_item(edit_snapshot = new EditSnapshot(mwindow, this));
73 edit_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(edit_snapshot));
74 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"), SNAPSHOT_PNG));
75 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
76 snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
81 int EditPopup::update(Track *track, Edit *edit)
86 if(track->data_type == TRACK_VIDEO && !resize_option)
88 add_item(resize_option = new EditPopupResize(mwindow, this));
89 add_item(matchsize_option = new EditPopupMatchSize(mwindow, this));
92 if(track->data_type == TRACK_AUDIO && resize_option)
94 del_item(resize_option); resize_option = 0;
95 del_item(matchsize_option); matchsize_option = 0;
108 EditAttachEffect::EditAttachEffect(MWindow *mwindow, EditPopup *popup)
109 : BC_MenuItem(_("Attach effect..."))
111 this->mwindow = mwindow;
113 dialog_thread = new PluginDialogThread(mwindow);
116 EditAttachEffect::~EditAttachEffect()
118 delete dialog_thread;
121 int EditAttachEffect::handle_event()
123 dialog_thread->start_window(popup->track,
124 0, _(PROGRAM_NAME ": Attach Effect"),
125 0, popup->track->data_type);
130 EditMoveTrackUp::EditMoveTrackUp(MWindow *mwindow, EditPopup *popup)
131 : BC_MenuItem(_("Move up"))
133 this->mwindow = mwindow;
136 EditMoveTrackUp::~EditMoveTrackUp()
139 int EditMoveTrackUp::handle_event()
141 mwindow->move_track_up(popup->track);
147 EditMoveTrackDown::EditMoveTrackDown(MWindow *mwindow, EditPopup *popup)
148 : BC_MenuItem(_("Move down"))
150 this->mwindow = mwindow;
153 EditMoveTrackDown::~EditMoveTrackDown()
156 int EditMoveTrackDown::handle_event()
158 mwindow->move_track_down(popup->track);
163 EditPopupResize::EditPopupResize(MWindow *mwindow, EditPopup *popup)
164 : BC_MenuItem(_("Resize track..."))
166 this->mwindow = mwindow;
168 dialog_thread = new ResizeTrackThread(mwindow);
170 EditPopupResize::~EditPopupResize()
172 delete dialog_thread;
175 int EditPopupResize::handle_event()
177 dialog_thread->start_window(popup->track);
182 EditPopupMatchSize::EditPopupMatchSize(MWindow *mwindow, EditPopup *popup)
183 : BC_MenuItem(_("Match output size"))
185 this->mwindow = mwindow;
188 EditPopupMatchSize::~EditPopupMatchSize()
192 int EditPopupMatchSize::handle_event()
194 mwindow->match_output_size(popup->track);
199 EditPopupDeleteTrack::EditPopupDeleteTrack(MWindow *mwindow, EditPopup *popup)
200 : BC_MenuItem(_("Delete track"))
202 this->mwindow = mwindow;
205 int EditPopupDeleteTrack::handle_event()
207 mwindow->delete_track(popup->track);
212 EditPopupAddTrack::EditPopupAddTrack(MWindow *mwindow, EditPopup *popup)
213 : BC_MenuItem(_("Add track"))
215 this->mwindow = mwindow;
219 int EditPopupAddTrack::handle_event()
221 switch( popup->track->data_type ) {
223 mwindow->add_audio_track_entry(1, popup->track);
226 mwindow->add_video_track_entry(popup->track);
229 mwindow->add_subttl_track_entry(popup->track);
236 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
237 : BC_MenuItem(_("User title..."))
239 this->mwindow = mwindow;
244 EditPopupTitle::~EditPopupTitle()
249 int EditPopupTitle::handle_event()
253 Track *trc = mwindow->session->track_highlighted;
255 if (trc && trc->record)
257 Edit *edt = mwindow->session->edit_highlighted;
260 window = new EditPopupTitleWindow (mwindow, popup);
261 window->create_objects();
262 result = window->run_window();
267 strcpy(edt->user_title, window->title_text->get_text());
278 EditPopupTitleWindow::EditPopupTitleWindow (MWindow *mwindow, EditPopup *popup)
279 : BC_Window (_(PROGRAM_NAME ": Set edit title"),
280 mwindow->gui->get_abs_cursor_x(0) - 400 / 2,
281 mwindow->gui->get_abs_cursor_y(0) - 500 / 2,
290 this->mwindow = mwindow;
292 this->edt = this->mwindow->session->edit_highlighted;
295 strcpy(new_text, this->edt->user_title);
299 EditPopupTitleWindow::~EditPopupTitleWindow()
303 int EditPopupTitleWindow::close_event()
309 void EditPopupTitleWindow::create_objects()
314 add_subwindow (new BC_Title (x, y, _("User title")));
315 add_subwindow (title_text = new EditPopupTitleText (this,
316 mwindow, x, y + 20));
317 add_tool(new BC_OKButton(this));
318 add_tool(new BC_CancelButton(this));
326 EditPopupTitleText::EditPopupTitleText (EditPopupTitleWindow *window,
327 MWindow *mwindow, int x, int y)
328 : BC_TextBox(x, y, 250, 1, (char*)(window->edt ? window->edt->user_title : ""))
330 this->window = window;
331 this->mwindow = mwindow;
334 EditPopupTitleText::~EditPopupTitleText()
338 int EditPopupTitleText::handle_event()
345 EditSnapshot::EditSnapshot(MWindow *mwindow, EditPopup *popup)
346 : BC_MenuItem(_("Snapshot..."))
348 this->mwindow = mwindow;
352 EditSnapshot::~EditSnapshot()
356 SnapshotSubMenu::SnapshotSubMenu(EditSnapshot *edit_snapshot)
358 this->edit_snapshot = edit_snapshot;
361 SnapshotSubMenu::~SnapshotSubMenu()
365 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
368 this->submenu = submenu;
372 SnapshotMenuItem::~SnapshotMenuItem()
376 int SnapshotMenuItem::handle_event()
378 MWindow *mwindow = submenu->edit_snapshot->mwindow;
379 EDL *edl = mwindow->edl;
380 if( !edl->have_video() ) return 1;
382 Preferences *preferences = mwindow->preferences;
383 char filename[BCTEXTLEN];
384 static const char *exts[] = { "png", "jpg", "tif" };
385 time_t tt; time(&tt);
386 struct tm tm; localtime_r(&tt,&tm);
387 sprintf(filename,"%s/snap_%04d%02d%02d-%02d%02d%02d.%s",
388 preferences->snapshot_path,
389 1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
390 tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
391 int fw = edl->get_w(), fh = edl->get_h();
392 int fcolor_model = edl->session->color_model;
394 Asset *asset = new Asset(filename);
397 asset->format = FILE_PNG;
398 asset->png_use_alpha = 1;
401 asset->format = FILE_JPEG;
402 asset->jpeg_quality = 90;
405 asset->format = FILE_TIFF;
406 asset->tiff_cmodel = 0;
407 asset->tiff_compression = 0;
412 asset->audio_data = 0;
413 asset->video_data = 1;
414 asset->video_length = 1;
418 int processors = preferences->project_smp + 1;
419 if( processors > 8 ) processors = 8;
420 file.set_processors(processors);
421 int ret = file.open_file(preferences, asset, 0, 1);
423 file.start_video_thread(1, fcolor_model,
424 processors > 1 ? 2 : 1, 0);
425 VFrame ***frames = file.get_video_buffer();
426 VFrame *frame = frames[0][0];
427 TransportCommand command;
428 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
429 command.command = CURRENT_FRAME;
430 command.get_edl()->copy_all(edl);
431 command.change_type = CHANGE_ALL;
432 command.realtime = 0;
434 RenderEngine render_engine(0, preferences, 0, 0);
435 CICache video_cache(preferences);
436 render_engine.set_vcache(&video_cache);
437 render_engine.arm_command(&command);
439 double position = edl->local_session->get_selectionstart(1);
440 int64_t source_position = (int64_t)(position * edl->get_frame_rate());
441 int ret = render_engine.vrender->process_buffer(frame, source_position, 0);
443 ret = file.write_video_buffer(1);
447 asset->awindow_folder = AW_MEDIA_FOLDER;
448 mwindow->edl->assets->append(asset);
449 mwindow->awindow->gui->async_update_assets();
452 eprintf("snapshot render failed");
453 asset->remove_user();