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