search fixes, preset fixes, ladspa icon logging, igor pref theme, drag btn rollover
[goodguy/history.git] / cinelerra-5.1 / cinelerra / editpopup.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "asset.h"
23 #include "assets.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "edit.h"
27 #include "editpopup.h"
28 #include "cache.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "file.h"
32 #include "language.h"
33 #include "localsession.h"
34 #include "mainerror.h"
35 #include "mainsession.h"
36 #include "mwindow.h"
37 #include "mwindowgui.h"
38 #include "plugindialog.h"
39 #include "preferences.h"
40 #include "renderengine.h"
41 #include "resizetrackthread.h"
42 #include "track.h"
43 #include "tracks.h"
44 #include "trackcanvas.h"
45 #include "transportque.h"
46 #include "vframe.h"
47 #include "vrender.h"
48
49 #include <string.h>
50
51 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
52  : BC_PopupMenu(0, 0, 0, "", 0)
53 {
54         this->mwindow = mwindow;
55         this->gui = gui;
56 }
57
58 EditPopup::~EditPopup()
59 {
60 }
61
62 void EditPopup::create_objects()
63 {
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));
77         resize_option = 0;
78         matchsize_option = 0;
79 }
80
81 int EditPopup::update(Track *track, Edit *edit)
82 {
83         this->edit = edit;
84         this->track = track;
85
86         if(track->data_type == TRACK_VIDEO && !resize_option)
87         {
88                 add_item(resize_option = new EditPopupResize(mwindow, this));
89                 add_item(matchsize_option = new EditPopupMatchSize(mwindow, this));
90         }
91         else
92         if(track->data_type == TRACK_AUDIO && resize_option)
93         {
94                 del_item(resize_option);     resize_option = 0;
95                 del_item(matchsize_option);  matchsize_option = 0;
96         }
97         return 0;
98 }
99
100
101
102
103
104
105
106
107
108 EditAttachEffect::EditAttachEffect(MWindow *mwindow, EditPopup *popup)
109  : BC_MenuItem(_("Attach effect..."))
110 {
111         this->mwindow = mwindow;
112         this->popup = popup;
113         dialog_thread = new PluginDialogThread(mwindow);
114 }
115
116 EditAttachEffect::~EditAttachEffect()
117 {
118         delete dialog_thread;
119 }
120
121 int EditAttachEffect::handle_event()
122 {
123         dialog_thread->start_window(popup->track,
124                 0, _(PROGRAM_NAME ": Attach Effect"),
125                 0, popup->track->data_type);
126         return 1;
127 }
128
129
130 EditMoveTrackUp::EditMoveTrackUp(MWindow *mwindow, EditPopup *popup)
131  : BC_MenuItem(_("Move up"))
132 {
133         this->mwindow = mwindow;
134         this->popup = popup;
135 }
136 EditMoveTrackUp::~EditMoveTrackUp()
137 {
138 }
139 int EditMoveTrackUp::handle_event()
140 {
141         mwindow->move_track_up(popup->track);
142         return 1;
143 }
144
145
146
147 EditMoveTrackDown::EditMoveTrackDown(MWindow *mwindow, EditPopup *popup)
148  : BC_MenuItem(_("Move down"))
149 {
150         this->mwindow = mwindow;
151         this->popup = popup;
152 }
153 EditMoveTrackDown::~EditMoveTrackDown()
154 {
155 }
156 int EditMoveTrackDown::handle_event()
157 {
158         mwindow->move_track_down(popup->track);
159         return 1;
160 }
161
162
163 EditPopupResize::EditPopupResize(MWindow *mwindow, EditPopup *popup)
164  : BC_MenuItem(_("Resize track..."))
165 {
166         this->mwindow = mwindow;
167         this->popup = popup;
168         dialog_thread = new ResizeTrackThread(mwindow);
169 }
170 EditPopupResize::~EditPopupResize()
171 {
172         delete dialog_thread;
173 }
174
175 int EditPopupResize::handle_event()
176 {
177         dialog_thread->start_window(popup->track);
178         return 1;
179 }
180
181
182 EditPopupMatchSize::EditPopupMatchSize(MWindow *mwindow, EditPopup *popup)
183  : BC_MenuItem(_("Match output size"))
184 {
185         this->mwindow = mwindow;
186         this->popup = popup;
187 }
188 EditPopupMatchSize::~EditPopupMatchSize()
189 {
190 }
191
192 int EditPopupMatchSize::handle_event()
193 {
194         mwindow->match_output_size(popup->track);
195         return 1;
196 }
197
198
199 EditPopupDeleteTrack::EditPopupDeleteTrack(MWindow *mwindow, EditPopup *popup)
200  : BC_MenuItem(_("Delete track"))
201 {
202         this->mwindow = mwindow;
203         this->popup = popup;
204 }
205 int EditPopupDeleteTrack::handle_event()
206 {
207         mwindow->delete_track(popup->track);
208         return 1;
209 }
210
211
212 EditPopupAddTrack::EditPopupAddTrack(MWindow *mwindow, EditPopup *popup)
213  : BC_MenuItem(_("Add track"))
214 {
215         this->mwindow = mwindow;
216         this->popup = popup;
217 }
218
219 int EditPopupAddTrack::handle_event()
220 {
221         switch( popup->track->data_type ) {
222         case TRACK_AUDIO:
223                 mwindow->add_audio_track_entry(1, popup->track);
224                 break;
225         case TRACK_VIDEO:
226                 mwindow->add_video_track_entry(popup->track);
227                 break;
228         case TRACK_SUBTITLE:
229                 mwindow->add_subttl_track_entry(popup->track);
230                 break;
231         }
232         return 1;
233 }
234
235
236 EditPopupTitle::EditPopupTitle(MWindow *mwindow, EditPopup *popup)
237  : BC_MenuItem(_("User title..."))
238 {
239         this->mwindow = mwindow;
240         this->popup = popup;
241         window = 0;
242 }
243
244 EditPopupTitle::~EditPopupTitle()
245 {
246         delete popup;
247 }
248
249 int EditPopupTitle::handle_event()
250 {
251         int result;
252
253         Track *trc = mwindow->session->track_highlighted;
254
255         if (trc && trc->record)
256         {
257                 Edit *edt = mwindow->session->edit_highlighted;
258                 if(!edt) return 1;
259
260                 window = new EditPopupTitleWindow (mwindow, popup);
261                 window->create_objects();
262                 result = window->run_window();
263
264
265                 if(!result && edt)
266                 {
267                         strcpy(edt->user_title, window->title_text->get_text());
268                 }
269
270                 delete window;
271                 window = 0;
272         }
273
274         return 1;
275 }
276
277
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,
282         300,
283         100,
284         300,
285         100,
286         0,
287         0,
288         1)
289 {
290         this->mwindow = mwindow;
291         this->popup = popup;
292         this->edt = this->mwindow->session->edit_highlighted;
293         if(this->edt)
294         {
295                 strcpy(new_text, this->edt->user_title);
296         }
297 }
298
299 EditPopupTitleWindow::~EditPopupTitleWindow()
300 {
301 }
302
303 int EditPopupTitleWindow::close_event()
304 {
305         set_done(1);
306         return 1;
307 }
308
309 void EditPopupTitleWindow::create_objects()
310 {
311         int x = 5;
312         int y = 10;
313
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));
319
320
321         show_window();
322         flush();
323 }
324
325
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 : ""))
329 {
330         this->window = window;
331         this->mwindow = mwindow;
332 }
333
334 EditPopupTitleText::~EditPopupTitleText()
335 {
336 }
337
338 int EditPopupTitleText::handle_event()
339 {
340         return 1;
341 }
342
343
344
345 EditSnapshot::EditSnapshot(MWindow *mwindow, EditPopup *popup)
346  : BC_MenuItem(_("Snapshot..."))
347 {
348         this->mwindow = mwindow;
349         this->popup = popup;
350 }
351
352 EditSnapshot::~EditSnapshot()
353 {
354 }
355
356 SnapshotSubMenu::SnapshotSubMenu(EditSnapshot *edit_snapshot)
357 {
358         this->edit_snapshot = edit_snapshot;
359 }
360
361 SnapshotSubMenu::~SnapshotSubMenu()
362 {
363 }
364
365 SnapshotMenuItem::SnapshotMenuItem(SnapshotSubMenu *submenu, const char *text, int mode)
366  : BC_MenuItem(text)
367 {
368         this->submenu = submenu;
369         this->mode = mode;
370 }
371
372 SnapshotMenuItem::~SnapshotMenuItem()
373 {
374 }
375
376 int SnapshotMenuItem::handle_event()
377 {
378         MWindow *mwindow = submenu->edit_snapshot->mwindow;
379         EDL *edl = mwindow->edl;
380         if( !edl->have_video() ) return 1;
381
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;
393
394         Asset *asset = new Asset(filename);
395         switch( mode ) {
396         case SNAPSHOT_PNG:
397                 asset->format = FILE_PNG;
398                 asset->png_use_alpha = 1;
399                 break;
400         case SNAPSHOT_JPEG:
401                 asset->format = FILE_JPEG;
402                 asset->jpeg_quality = 90;
403                 break;
404         case SNAPSHOT_TIFF:
405                 asset->format = FILE_TIFF;
406                 asset->tiff_cmodel = 0;
407                 asset->tiff_compression = 0;
408                 break;
409         }
410         asset->width = fw;
411         asset->height = fh;
412         asset->audio_data = 0;
413         asset->video_data = 1;
414         asset->video_length = 1;
415         asset->layers = 1;
416
417         File file;
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);
422         if( !ret ) {
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;
433
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);
438
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);
442                 if( !ret )
443                         ret = file.write_video_buffer(1);
444                 file.close_file();
445         }
446         if( !ret ) {
447                 asset->awindow_folder = AW_MEDIA_FOLDER;
448                 mwindow->edl->assets->append(asset);
449                 mwindow->awindow->gui->async_update_assets();
450         }
451         else {
452                 eprintf("snapshot render failed");
453                 asset->remove_user();
454         }
455         return 1;
456 }
457