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