add LastFrame plugin, add bld_scripts
[goodguy/history.git] / cinelerra-5.0 / cinelerra / mwindow.h
1 /*
2  * CINELERRA
3  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  * 
19  */
20
21 #ifndef MWINDOW_H
22 #define MWINDOW_H
23
24 #include <stdio.h>
25 #include <stdint.h>
26
27 #include "arraylist.h"
28 #include "asset.inc"
29 #include "assets.inc"
30 #include "audiodevice.inc"
31 #include "awindow.inc"
32 #include "batchrender.inc"
33 #include "bcwindowbase.inc"
34 #include "bdcreate.inc"
35 #include "brender.inc"
36 #include "cache.inc"
37 #include "channel.inc"
38 #include "channeldb.inc"
39 #include "commercials.inc"
40 #include "cwindow.inc"
41 #include "bchash.inc"
42 #include "devicedvbinput.inc"
43 #include "devicempeginput.inc"
44 #include "dvdcreate.inc"
45 #include "edit.inc"
46 #include "edl.inc"
47 #include "fileserver.inc"
48 #include "filesystem.inc"
49 #include "filexml.inc"
50 #include "framecache.inc"
51 #include "gwindow.inc"
52 #include "indexable.inc"
53 #include "keyframegui.inc"
54 #include "levelwindow.inc"
55 #include "loadmode.inc"
56 #include "mainerror.inc"
57 #include "mainindexes.inc"
58 #include "mainprogress.inc"
59 #include "mainsession.inc"
60 #include "mainundo.inc"
61 #include "maxchannels.h"
62 #include "mutex.inc"
63 #include "mwindow.inc"
64 #include "mwindowgui.inc"
65 #include "new.inc"
66 #include "patchbay.inc"
67 #include "playback3d.inc"
68 #include "playbackengine.inc"
69 #include "plugin.inc"
70 #include "pluginfclient.inc"
71 #include "pluginserver.inc"
72 #include "pluginset.inc"
73 #include "preferences.inc"
74 #include "preferencesthread.inc"
75 #include "record.inc"
76 #include "recordlabel.inc"
77 #include "render.inc"
78 #include "sharedlocation.inc"
79 #include "sighandler.inc"
80 #include "splashgui.inc"
81 #include "theme.inc"
82 #include "thread.h"
83 #include "threadloader.inc"
84 #include "timebar.inc"
85 #include "timebomb.h"
86 #include "tipwindow.inc"
87 #include "track.inc"
88 #include "tracking.inc"
89 #include "tracks.inc"
90 #include "transition.inc"
91 #include "transportque.inc"
92 #include "videowindow.inc"
93 #include "vwindow.inc"
94 #include "wwindow.inc"
95 #include "wavecache.inc"
96
97 // All entry points for commands except for window locking should be here.
98 // This allows scriptability.
99
100 class MWindow : public Thread
101 {
102 public:
103         MWindow();
104         ~MWindow();
105
106 // ======================================== initialization commands
107         void create_objects(int want_gui, 
108                 int want_new,
109                 char *config_path);
110         void show_splash();
111         void hide_splash();
112         void start();
113         void run();
114
115         int run_script(FileXML *script);
116         int new_project();
117         int delete_project(int flash = 1);
118         void quit(int unlock);
119         int reload() { return reload_status; }
120
121         int load_defaults();
122         int save_defaults();
123         int set_filename(const char *filename);
124 // Total vertical pixels in timeline
125         int get_tracks_height();
126 // Total horizontal pixels in timeline
127         int get_tracks_width();
128 // Show windows
129         void show_vwindow();
130         void show_awindow();
131         void show_lwindow();
132         void show_cwindow();
133         void show_gwindow();
134         int tile_windows(int window_config);
135         char *get_cwindow_display();
136 //      void set_titles(int value);
137         void set_screens(int value);
138         int asset_to_edl(EDL *new_edl, 
139                 Asset *new_asset, 
140                 RecordLabels *labels = 0);
141 // Convert nested_edl to a nested EDL in new_edl 
142 // suitable for pasting in paste_edls
143         int edl_to_nested(EDL *new_edl, 
144                 EDL *nested_edl);
145
146 // Entry point to insert assets and insert edls.  Called by TrackCanvas 
147 // and AssetPopup when assets are dragged in from AWindow.
148 // Takes the drag vectors from MainSession and
149 // pastes either assets or clips depending on which is full.
150 // Returns 1 if the vectors were full
151         int paste_assets(double position, Track *dest_track);
152         
153 // Insert the assets at a point in the EDL.  Called by menueffects,
154 // render, and CWindow drop but recording calls paste_edls directly for
155 // labels.
156         void load_assets(ArrayList<Indexable*> *new_assets, 
157                 double position, 
158                 int load_mode,
159                 Track *first_track /* = 0 */,
160                 RecordLabels *labels /* = 0 */,
161                 int edit_labels,
162                 int edit_plugins,
163                 int edit_autos);
164         int paste_edls(ArrayList<EDL*> *new_edls, 
165                 int load_mode, 
166                 Track *first_track /* = 0 */,
167                 double current_position /* = -1 */,
168                 int edit_labels,
169                 int edit_plugins,
170                 int edit_autos);
171 // Reset everything for a load
172         void update_project(int load_mode);
173 // Fit selected time to horizontal display range
174         void fit_selection();
175 // Fit selected autos to the vertical display range
176         void fit_autos();
177         void expand_autos();
178         void shrink_autos();
179         void zoom_autos(float min, float max);
180 // move the window to include the cursor
181         void find_cursor();
182 // Search plugindb and put results in argument
183         static void search_plugindb(int do_audio, 
184                 int do_video, 
185                 int is_realtime, 
186                 int is_transition,
187                 int is_theme,
188                 ArrayList<PluginServer*> &results);
189 // Find the plugin whose title matches title and return it
190         static PluginServer* scan_plugindb(char *title,
191                 int data_type);
192         static int plugin_exists(char *plugin_path);
193         void dump_plugindb(FILE *fp);
194         void stop_playback(int wait=0);
195
196
197
198         
199         int load_filenames(ArrayList<char*> *filenames, 
200                 int load_mode = LOADMODE_REPLACE,
201 // Cause the project filename on the top of the window to be updated.
202 // Not wanted for loading backups.
203                 int update_filename = 1);
204
205 // Print out plugins which are referenced in the EDL but not loaded.
206         void test_plugins(EDL *new_edl, char *path);
207
208         int interrupt_indexes();  // Stop index building
209
210         int redraw_time_dependancies();     // after reconfiguring the time format, sample rate, frame rate
211
212 // =========================================== movement
213
214         void next_time_format();
215         void prev_time_format();
216         void time_format_common();
217         int reposition_timebar(int new_pixel, int new_height);
218         int expand_sample();
219         int zoom_in_sample();
220         int zoom_sample(int64_t zoom_sample);
221         void zoom_amp(int64_t zoom_amp);
222         void zoom_track(int64_t zoom_track);
223         int fit_sample();
224         int move_left(int64_t distance = 0);
225         int move_right(int64_t distance = 0);
226         void move_up(int64_t distance = 0);
227         void move_down(int64_t distance = 0);
228
229 // seek to labels
230 // shift_down must be passed by the caller because different windows call
231 // into this
232         int next_label(int shift_down);   
233         int prev_label(int shift_down);
234 // seek to edit handles
235         int next_edit_handle(int shift_down);
236         int prev_edit_handle(int shift_down);  
237 // offset is pixels to add to track_start
238         void trackmovement(int offset, int pane_number);
239 // view_start is pixels
240         int samplemovement(int64_t view_start, int pane_number);     
241         void select_all();
242         int goto_start();
243         int goto_end();
244         int goto_position(double position);
245         int expand_y();
246         int zoom_in_y();
247         int expand_t();
248         int zoom_in_t();
249         void split_x();
250         void split_y();
251         void crop_video();
252         void update_plugins();
253 // Call after every edit operation
254         void save_backup();
255         void load_backup();
256         void show_plugin(Plugin *plugin);
257         void hide_plugin(Plugin *plugin, int lock);
258         void hide_plugins();
259         void delete_plugin(PluginServer *plugin);
260 // Update plugins with configuration changes.
261 // Called by TrackCanvas::cursor_motion_event.
262         void update_plugin_guis(int do_keyframe_guis = 1);
263         void update_plugin_states();
264         void update_plugin_titles();
265 // Called by Attachmentpoint during playback.
266 // Searches for matching plugin and renders data in it.
267         void render_plugin_gui(void *data, Plugin *plugin);
268         void render_plugin_gui(void *data, int size, Plugin *plugin);
269
270 // Called from PluginVClient::process_buffer
271 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
272 // they can run.
273         int plugin_gui_open(Plugin *plugin);
274
275         void show_keyframe_gui(Plugin *plugin);
276         void hide_keyframe_guis();
277         void hide_keyframe_gui(Plugin *plugin);
278         void update_keyframe_guis();
279
280
281 // ============================= editing commands ========================
282
283 // Map each recordable audio track to the desired pattern
284         void map_audio(int pattern);
285         void remap_audio(int pattern);
286         enum
287         {
288                 AUDIO_5_1_TO_2,
289                 AUDIO_1_TO_1
290         };
291         void add_audio_track_entry(int above, Track *dst);
292         int add_audio_track(int above, Track *dst);
293         void add_clip_to_edl(EDL *edl);
294         void add_video_track_entry(Track *dst = 0);
295         int add_video_track(int above, Track *dst);
296         void add_subttl_track_entry(Track *dst = 0);
297         int add_subttl_track(int above, Track *dst);
298
299         void asset_to_all();
300         void asset_to_size();
301         void asset_to_rate();
302 // Entry point for clear operations.
303         void clear_entry();
304 // Clears active region in EDL.
305 // If clear_handle, edit boundaries are cleared if the range is 0.
306 // Called by paste, record, menueffects, render, and CWindow drop.
307         void clear(int clear_handle);
308         void clear_labels();
309         int clear_labels(double start, double end);
310         void concatenate_tracks();
311         void copy();
312         int copy(double start, double end);
313         void cut();
314
315 // Calculate aspect ratio from pixel counts
316         static int create_aspect_ratio(float &w, float &h, int width, int height);
317 // Calculate defaults path
318         static void create_defaults_path(char *string, const char *config_file);
319
320         void delete_folder(char *folder);
321         void delete_inpoint();
322         void delete_outpoint();    
323
324         void delete_track();
325         void delete_track(Track *track);
326         void delete_tracks();
327         int feather_edits(int64_t feather_samples, int audio, int video);
328         int64_t get_feather(int audio, int video);
329         float get_aspect_ratio();
330         void insert(double position, 
331                 FileXML *file,
332                 int edit_labels,
333                 int edit_plugins,
334                 int edit_autos,
335                 EDL *parent_edl /* = 0 */);
336
337 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
338 // into pluginset_highlighted.
339         void insert_effects_canvas(double start,
340                 double length);
341
342 // CWindow calls this to insert multiple effects from 
343 // the drag_pluginservers array.
344         void insert_effects_cwindow(Track *dest_track);
345
346 // Attach new effect to all recordable tracks
347 // single_standalone - attach 1 standalone on the first track and share it with
348 // other tracks
349         void insert_effect(char *title, 
350                 SharedLocation *shared_location, 
351                 int data_type,
352                 int plugin_type,
353                 int single_standalone);
354
355 // This is called multiple times by the above functions.
356 // It can't sync parameters.
357         void insert_effect(char *title, 
358                 SharedLocation *shared_location, 
359                 Track *track,
360                 PluginSet *plugin_set,
361                 double start,
362                 double length,
363                 int plugin_type);
364
365         void match_output_size(Track *track);
366 // Move edit to new position
367         void move_edits(ArrayList<Edit*> *edits,
368                 Track *track,
369                 double position);
370 // Move effect to position
371         void move_effect(Plugin *plugin,
372                 PluginSet *plugin_set,
373                 Track *track,
374                 int64_t position);
375         void move_plugins_up(PluginSet *plugin_set);
376         void move_plugins_down(PluginSet *plugin_set);
377         void move_track_down(Track *track);
378         void move_tracks_down();
379         void move_track_up(Track *track);
380         void move_tracks_up();
381         void mute_selection();
382         void new_folder(const char *new_folder);
383         void overwrite(EDL *source);
384 // For clipboard commands
385         void paste();
386 // For splice and overwrite
387         int paste(double start, 
388                 double end, 
389                 FileXML *file,
390                 int edit_labels,
391                 int edit_plugins,
392                 int edit_autos);
393         int paste_output(int64_t startproject, 
394                                 int64_t endproject, 
395                                 int64_t startsource_sample, 
396                                 int64_t endsource_sample, 
397                                 int64_t startsource_frame,
398                                 int64_t endsource_frame,
399                                 Asset *asset, 
400                                 RecordLabels *new_labels);
401         void paste_silence();
402
403 // Detach single transition
404         void detach_transition(Transition *transition);
405 // Detach all transitions in selection
406         void detach_transitions();
407 // Attach dragged transition
408         void paste_transition();
409 // Attach transition to all edits in selection
410         void paste_transitions(int track_type, char *title);
411 // Attach transition dragged onto CWindow
412         void paste_transition_cwindow(Track *dest_track);
413 // Attach default transition to single edit
414         void paste_audio_transition();
415         void paste_video_transition();
416         void shuffle_edits();
417         void align_edits();
418         void set_edit_length(double length);
419 // Set length of single transition
420         void set_transition_length(Transition *transition, double length);
421 // Set length in seconds of all transitions in active range
422         void set_transition_length(double length);
423         
424         void remove_indexfile(Indexable *indexable);
425         void rebuild_indices();
426 // Asset removal from caches
427         void reset_caches();
428         void remove_asset_from_caches(Asset *asset);
429         void remove_assets_from_project(int push_undo = 0);
430         void remove_assets_from_disk();
431         void resize_track(Track *track, int w, int h);
432         
433         void set_automation_mode(int mode);
434         void set_keyframe_type(int mode);
435         void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
436 // Update the editing mode
437         int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
438         void set_inpoint(int is_mwindow);
439         void set_outpoint(int is_mwindow);
440         void splice(EDL *source);
441         void toggle_loop_playback();
442         void trim_selection();
443 // Synchronize EDL settings with all playback engines depending on current 
444 // operation.  Doesn't redraw anything.
445         void sync_parameters(int change_type = CHANGE_PARAMS);
446         void to_clip();
447         int toggle_label(int is_mwindow);
448         void undo_entry(BC_WindowBase *calling_window_gui);
449         void redo_entry(BC_WindowBase *calling_window_gui);
450
451
452         int cut_automation();
453         int copy_automation();
454         int paste_automation();
455         void clear_automation();
456         int cut_default_keyframe();
457         int copy_default_keyframe();
458 // Use paste_automation to paste the default keyframe in other position.
459 // Use paste_default_keyframe to replace the default keyframe with whatever is
460 // in the clipboard.
461         int paste_default_keyframe();
462         int clear_default_keyframe();
463
464         int modify_edithandles();
465         int modify_pluginhandles();
466         void finish_modify_handles();
467
468         void dump_plugins(FILE *fp=stdout);
469         void dump_edl(FILE *fp=stdout);
470         void dump_undo(FILE *fp=stdout);
471         void dump_exe(FILE *fp=stdout);
472         static void trap_hook(FILE *fp, void *vp);
473         
474         void reset_android_remote();
475         
476         
477
478 // Send new EDL to caches
479         void age_caches();
480         int optimize_assets();            // delete unused assets from the cache and assets
481
482         void select_point(double position);
483         int set_loop_boundaries();         // toggle loop playback and set boundaries for loop playback
484
485
486         Playback3D *playback_3d;
487         SplashGUI *splash_window;
488         
489 // Main undo stack
490         MainUndo *undo;
491         BC_Hash *defaults;
492         Assets *assets;
493 // CICaches for drawing timeline only
494         CICache *audio_cache, *video_cache;
495 // Frame cache for drawing timeline only.
496 // Cache drawing doesn't wait for file decoding.
497         FrameCache *frame_cache;
498         WaveCache *wave_cache;
499         Preferences *preferences;
500         PreferencesThread *preferences_thread;
501         MainSession *session;
502         Theme *theme;
503         MainIndexes *mainindexes;
504         MainProgress *mainprogress;
505         BRender *brender;
506         static Commercials *commercials;
507         int commercial_active;
508         int has_commercials();
509
510 // Menu items
511         ArrayList<ColormodelItem*> colormodels;
512
513         int reset_meters();
514         void resync_guis();
515
516         int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
517         int select_asset(int vtrack, int delete_tracks);
518
519 // Channel DB for playback only.  Record channel DB's are in record.C
520         ChannelDB *channeldb_buz;
521         ChannelDB *channeldb_v4l2jpeg;
522
523         static FileServer *file_server;
524
525 // ====================================== plugins ==============================
526
527 // Contains file descriptors for all the dlopens
528         static ArrayList<PluginServer*> *plugindb;
529 // Currently visible plugins
530         int64_t plugin_visibility;
531         ArrayList<PluginServer*> *plugin_guis;
532 // GUI Plugins to delete
533         ArrayList<PluginServer*> *dead_plugins;
534 // Keyframe editors
535         ArrayList<KeyFrameThread*> *keyframe_threads;
536
537 // Adjust sample position to line up with frames.
538         int fix_timing(int64_t &samples_out, 
539                 int64_t &frames_out, 
540                 int64_t samples_in);
541
542
543         CreateBD_Thread *create_bd;
544         CreateDVD_Thread *create_dvd;
545         BatchRenderThread *batch_render;
546         Render *render;
547 // Master edl
548         EDL *edl;
549 // Main Window GUI
550         MWindowGUI *gui;
551 // Compositor
552         CWindow *cwindow;
553 // Viewer
554         Mutex *vwindows_lock;
555         ArrayList<VWindow*> vwindows;
556 // Asset manager
557         AWindow *awindow;
558 // Automation window
559         GWindow *gwindow;
560 // Tip of the day
561         TipWindow *twindow;
562 // Warning window
563         WWindow *wwindow;
564         void show_warning(int *do_warning, const char *text);
565 // Levels
566         LevelWindow *lwindow;
567 // Lock during creation and destruction of GUI
568         Mutex *plugin_gui_lock;
569         Mutex *dead_plugin_lock;
570         Mutex *keyframe_gui_lock;
571 // Lock during creation and destruction of brender so playback doesn't use it.
572         Mutex *brender_lock;
573
574 // Initialize shared memory
575         void init_shm();
576         static void init_fileserver(Preferences *preferences);
577
578 // Initialize channel DB's for playback
579         void init_channeldb();
580         void init_render();
581 // These three happen synchronously with each other
582 // Make sure this is called after synchronizing EDL's.
583         void init_brender();
584 // Restart brender after testing its existence
585         void restart_brender();
586 // Stops brender after testing its existence
587         void stop_brender();
588 // This one happens asynchronously of the others.  Used by playback to
589 // see what frame is background rendered.
590         int brender_available(int position);
591         void set_brender_start();
592         int put_commercial();
593         void activate_commercial() { commercial_active = 1; }
594         void commit_commercial();
595         void undo_commercial();
596         void cut_commercials();
597         int paste_subtitle_text(char *text, double start, double end);
598
599         void init_error();
600         void finit_error();
601         static void init_defaults(BC_Hash* &defaults, char *config_path);
602         void init_edl();
603         void init_awindow();
604         void init_gwindow();
605         void init_tipwindow();
606 // Used by MWindow and RenderFarmClient
607         static int init_plugins(MWindow *mwindow, Preferences *preferences);
608         static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
609                 FILE *fp, const char *plug_dir, const char *plug_path, int &dir_id);
610         static void init_ffmpeg();
611         static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
612         static int load_plugin_index(MWindow *mwindow, char *path);
613         static PluginServer* new_ffmpeg_server(MWindow *mwindow, const char *name);
614         void init_preferences();
615         void init_signals();
616         void init_theme();
617         void init_compositor();
618         void init_levelwindow();
619 // Called when creating a new viewer to view footage
620         VWindow* get_viewer(int start_it, int idx=-1);
621         void init_cache();
622         void init_menus();
623         void init_indexes();
624         void init_gui();
625         void init_3d();
626         void init_playbackcursor();
627         void init_commercials();
628         void delete_plugins();
629 // 
630         void clean_indexes();
631 //      TimeBomb timebomb;
632         SigHandler *sighandler;
633         int reload_status;
634         int screens;
635         int in_destructor;
636 };
637
638 #endif