search fixes, preset fixes, ladspa icon logging, igor pref theme, drag btn rollover
[goodguy/history.git] / cinelerra-5.1 / cinelerra / editpopup.C
index 9dccdd06a85c70df923ea29b5029ac8e5401f578..5c8291a87033695c54628c552f5d32e40f1e1e4a 100644 (file)
  *
  */
 
+#include "asset.h"
+#include "assets.h"
+#include "awindow.h"
+#include "awindowgui.h"
 #include "edit.h"
 #include "editpopup.h"
+#include "cache.h"
+#include "edl.h"
+#include "edlsession.h"
+#include "file.h"
 #include "language.h"
+#include "localsession.h"
+#include "mainerror.h"
 #include "mainsession.h"
 #include "mwindow.h"
 #include "mwindowgui.h"
 #include "plugindialog.h"
+#include "preferences.h"
+#include "renderengine.h"
 #include "resizetrackthread.h"
 #include "track.h"
 #include "tracks.h"
 #include "trackcanvas.h"
-
+#include "transportque.h"
+#include "vframe.h"
+#include "vrender.h"
 
 #include <string.h>
 
 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
- : BC_PopupMenu(0,
-               0,
-               0,
-               "",
-               0)
+ : BC_PopupMenu(0, 0, 0, "", 0)
 {
        this->mwindow = mwindow;
        this->gui = gui;
@@ -57,7 +67,15 @@ void EditPopup::create_objects()
        add_item(new EditPopupDeleteTrack(mwindow, this));
        add_item(new EditPopupAddTrack(mwindow, this));
 //     add_item(new EditPopupTitle(mwindow, this));
+       EditSnapshot *edit_snapshot;
+       SnapshotSubMenu *snapshot_submenu;
+       add_item(edit_snapshot = new EditSnapshot(mwindow, this));
+       edit_snapshot->add_submenu(snapshot_submenu = new SnapshotSubMenu(edit_snapshot));
+       snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("png"),  SNAPSHOT_PNG));
+       snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("jpeg"), SNAPSHOT_JPEG));
+       snapshot_submenu->add_submenuitem(new SnapshotMenuItem(snapshot_submenu, _("tiff"), SNAPSHOT_TIFF));
        resize_option = 0;
+       matchsize_option = 0;
 }
 
 int EditPopup::update(Track *track, Edit *edit)
@@ -103,10 +121,8 @@ EditAttachEffect::~EditAttachEffect()
 int EditAttachEffect::handle_event()
 {
        dialog_thread->start_window(popup->track,
-               0,
-               _(PROGRAM_NAME ": Attach Effect"),
-               0,
-               popup->track->data_type);
+               0, _(PROGRAM_NAME ": Attach Effect"),
+               0, popup->track->data_type);
        return 1;
 }
 
@@ -144,8 +160,6 @@ int EditMoveTrackDown::handle_event()
 }
 
 
-
-
 EditPopupResize::EditPopupResize(MWindow *mwindow, EditPopup *popup)
  : BC_MenuItem(_("Resize track..."))
 {
@@ -165,10 +179,6 @@ int EditPopupResize::handle_event()
 }
 
 
-
-
-
-
 EditPopupMatchSize::EditPopupMatchSize(MWindow *mwindow, EditPopup *popup)
  : BC_MenuItem(_("Match output size"))
 {
@@ -186,11 +196,6 @@ int EditPopupMatchSize::handle_event()
 }
 
 
-
-
-
-
-
 EditPopupDeleteTrack::EditPopupDeleteTrack(MWindow *mwindow, EditPopup *popup)
  : BC_MenuItem(_("Delete track"))
 {
@@ -204,10 +209,6 @@ int EditPopupDeleteTrack::handle_event()
 }
 
 
-
-
-
-
 EditPopupAddTrack::EditPopupAddTrack(MWindow *mwindow, EditPopup *popup)
  : BC_MenuItem(_("Add track"))
 {
@@ -232,10 +233,6 @@ int EditPopupAddTrack::handle_event()
 }
 
 
-
-
-
-
 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
  : BC_MenuItem(_("User title..."))
 {
@@ -345,7 +342,116 @@ int EditPopupTitleText::handle_event()
 
 
 
+EditSnapshot::EditSnapshot(MWindow *mwindow, EditPopup *popup)
+ : BC_MenuItem(_("Snapshot..."))
+{
+       this->mwindow = mwindow;
+       this->popup = popup;
+}
 
+EditSnapshot::~EditSnapshot()
+{
+}
+
+SnapshotSubMenu::SnapshotSubMenu(EditSnapshot *edit_snapshot)
+{
+       this->edit_snapshot = edit_snapshot;
+}
+
+SnapshotSubMenu::~SnapshotSubMenu()
+{
+}
+
+SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
+ : BC_MenuItem(text)
+{
+       this->submenu = submenu;
+       this->mode = mode;
+}
+
+SnapshotMenuItem::~SnapshotMenuItem()
+{
+}
+
+int SnapshotMenuItem::handle_event()
+{
+       MWindow *mwindow = submenu->edit_snapshot->mwindow;
+       EDL *edl = mwindow->edl;
+       if( !edl->have_video() ) return 1;
 
+       Preferences *preferences = mwindow->preferences;
+       char filename[BCTEXTLEN];
+       static const char *exts[] = { "png", "jpg", "tif" };
+       time_t tt;     time(&tt);
+       struct tm tm;  localtime_r(&tt,&tm);
+       sprintf(filename,"%s/snap_%04d%02d%02d-%02d%02d%02d.%s",
+               preferences->snapshot_path,
+               1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
+               tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
+       int fw = edl->get_w(), fh = edl->get_h();
+       int fcolor_model = edl->session->color_model;
 
+       Asset *asset = new Asset(filename);
+       switch( mode ) {
+       case SNAPSHOT_PNG:
+               asset->format = FILE_PNG;
+               asset->png_use_alpha = 1;
+               break;
+       case SNAPSHOT_JPEG:
+               asset->format = FILE_JPEG;
+               asset->jpeg_quality = 90;
+               break;
+       case SNAPSHOT_TIFF:
+               asset->format = FILE_TIFF;
+               asset->tiff_cmodel = 0;
+               asset->tiff_compression = 0;
+               break;
+       }
+       asset->width = fw;
+       asset->height = fh;
+       asset->audio_data = 0;
+       asset->video_data = 1;
+       asset->video_length = 1;
+       asset->layers = 1;
+
+       File file;
+       int processors = preferences->project_smp + 1;
+       if( processors > 8 ) processors = 8;
+       file.set_processors(processors);
+       int ret = file.open_file(preferences, asset, 0, 1);
+       if( !ret ) {
+               file.start_video_thread(1, fcolor_model,
+                       processors > 1 ? 2 : 1, 0);
+               VFrame ***frames = file.get_video_buffer();
+               VFrame *frame = frames[0][0];
+               TransportCommand command;
+               //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
+               command.command = CURRENT_FRAME;
+               command.get_edl()->copy_all(edl);
+               command.change_type = CHANGE_ALL;
+               command.realtime = 0;
+
+               RenderEngine render_engine(0, preferences, 0, 0);
+               CICache video_cache(preferences);
+               render_engine.set_vcache(&video_cache);
+               render_engine.arm_command(&command);
+
+               double position = edl->local_session->get_selectionstart(1);
+               int64_t source_position = (int64_t)(position * edl->get_frame_rate());
+               int ret = render_engine.vrender->process_buffer(frame, source_position, 0);
+               if( !ret )
+                       ret = file.write_video_buffer(1);
+               file.close_file();
+       }
+       if( !ret ) {
+               asset->awindow_folder = AW_MEDIA_FOLDER;
+               mwindow->edl->assets->append(asset);
+               mwindow->awindow->gui->async_update_assets();
+       }
+       else {
+               eprintf("snapshot render failed");
+               asset->remove_user();
+       }
+       return 1;
+}