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