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