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