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