3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
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.
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.
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
27 #include "apatchgui.h"
28 #include "arraylist.h"
31 #include "audiodevice.inc"
33 #include "awindow.inc"
34 #include "batchrender.inc"
35 #include "bcwindowbase.inc"
36 #include "bdcreate.inc"
37 #include "brender.inc"
39 #include "channel.inc"
40 #include "channeldb.inc"
41 #include "commercials.inc"
42 #include "cwindow.inc"
44 #include "devicedvbinput.inc"
45 #include "devicempeginput.inc"
46 #include "dvdcreate.inc"
49 #include "edlsession.inc"
50 #include "exportedl.inc"
51 #include "filesystem.inc"
52 #include "filexml.inc"
53 #include "framecache.inc"
54 #include "gwindow.inc"
55 #include "indexable.inc"
56 #include "keyframegui.inc"
57 #include "levelwindow.inc"
58 #include "loadmode.inc"
59 #include "mainerror.inc"
60 #include "mainindexes.inc"
61 #include "mainprogress.inc"
62 #include "mainsession.inc"
63 #include "mainundo.inc"
64 #include "maxchannels.h"
66 #include "mwindow.inc"
67 #include "mwindowgui.inc"
69 #include "patchbay.inc"
70 #include "playback3d.inc"
71 #include "playbackengine.inc"
73 #include "pluginfclient.inc"
74 #include "pluginserver.inc"
75 #include "pluginset.inc"
76 #include "preferences.inc"
77 #include "preferencesthread.inc"
79 #include "recordlabel.inc"
81 #include "sharedlocation.inc"
82 #include "sighandler.inc"
83 #include "splashgui.inc"
86 #include "threadloader.inc"
87 #include "timebar.inc"
89 #include "tipwindow.inc"
91 #include "tracking.inc"
93 #include "transition.inc"
94 #include "transportque.inc"
95 #include "videowindow.inc"
96 #include "vpatchgui.h"
97 #include "vwindow.inc"
98 #include "zwindow.inc"
99 #include "wwindow.inc"
100 #include "wavecache.inc"
102 #define FONT_SEARCHPATH "fonts"
104 // All entry points for commands except for window locking should be here.
105 // This allows scriptability.
107 class MWindow : public Thread
113 // ======================================== initialization commands
114 void create_objects(int want_gui,
122 int run_script(FileXML *script);
124 int delete_project(int flash = 1);
126 int restart() { return restart_status; }
130 int set_filename(const char *filename);
131 // Total vertical pixels in timeline
132 int get_tracks_height();
133 // Total horizontal pixels in timeline
134 int get_tracks_width();
142 int tile_windows(int window_config);
143 char *get_cwindow_display();
144 // void set_titles(int value);
145 void set_screens(int value);
146 int asset_to_edl(EDL *new_edl,
148 RecordLabels *labels = 0);
149 // Convert nested_edl to a nested EDL in new_edl
150 // suitable for pasting in paste_edls
151 int edl_to_nested(EDL *new_edl,
154 // Entry point to insert assets and insert edls. Called by TrackCanvas
155 // and AssetPopup when assets are dragged in from AWindow.
156 // Takes the drag vectors from MainSession and
157 // pastes either assets or clips depending on which is full.
158 // Returns 1 if the vectors were full
159 int paste_assets(double position, Track *dest_track, int overwrite);
161 // Insert the assets at a point in the EDL. Called by menueffects,
162 // render, and CWindow drop but recording calls paste_edls directly for
164 void load_assets(ArrayList<Indexable*> *new_assets,
167 Track *first_track /* = 0 */,
168 RecordLabels *labels /* = 0 */,
173 int paste_edls(ArrayList<EDL*> *new_edls,
175 Track *first_track /* = 0 */,
176 double current_position /* = -1 */,
181 // Reset everything for a load
182 void update_project(int load_mode);
183 // Fit selected time to horizontal display range
184 void fit_selection();
185 // Fit selected autos to the vertical display range
186 void fit_autos(int doall);
187 void change_currentautorange(int autogrouptype, int increment, int changemax);
188 void expand_autos(int changeall, int domin, int domax);
189 void shrink_autos(int changeall, int domin, int domax);
190 // move the window to include the cursor
192 // Search plugindb and put results in argument
193 static void search_plugindb(int do_audio,
198 ArrayList<PluginServer*> &results);
199 // Find the plugin whose title matches title and return it
200 static PluginServer* scan_plugindb(char *title,
202 static int plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins);
203 static int plugin_exists(char *plugin_path);
204 void dump_plugindb(FILE *fp);
205 void stop_playback(int wait=0);
207 void queue_mixers(EDL *edl, int command, int wait_tracking,
208 int use_inout, int update_refresh, int toggle_audio);
210 ZWindow *get_mixer(Mixer *&mixer);
211 void del_mixer(ZWindow *zwindow);
212 int mixer_track_active(Track *track);
213 void update_mixer_tracks();
215 int select_zwindow(ZWindow *zwindow);
217 int load_filenames(ArrayList<char*> *filenames,
218 int load_mode = LOADMODE_REPLACE,
219 // Cause the project filename on the top of the window to be updated.
220 // Not wanted for loading backups.
221 int update_filename = 1);
224 // Print out plugins which are referenced in the EDL but not loaded.
225 void test_plugins(EDL *new_edl, char *path);
227 int interrupt_indexes(); // Stop index building
229 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
231 // =========================================== movement
233 void next_time_format();
234 void prev_time_format();
235 void time_format_common();
236 int reposition_timebar(int new_pixel, int new_height);
238 int zoom_in_sample();
239 int zoom_sample(int64_t zoom_sample);
240 void zoom_autos(float min, float max);
241 void zoom_amp(int64_t zoom_amp);
242 void zoom_track(int64_t zoom_track);
244 int move_left(int64_t distance = 0);
245 int move_right(int64_t distance = 0);
246 void move_up(int64_t distance = 0);
247 void move_down(int64_t distance = 0);
250 // shift_down must be passed by the caller because different windows call
252 int next_label(int shift_down);
253 int prev_label(int shift_down);
254 // seek to edit handles
255 int next_edit_handle(int shift_down);
256 int prev_edit_handle(int shift_down);
257 // offset is pixels to add to track_start
258 void trackmovement(int offset, int pane_number);
259 // view_start is pixels
260 int samplemovement(int64_t view_start, int pane_number);
264 int goto_position(double position);
272 void update_plugins();
273 // Call after every edit operation
276 void show_plugin(Plugin *plugin);
277 void hide_plugin(Plugin *plugin, int lock);
279 void delete_plugin(PluginServer *plugin);
280 // Update plugins with configuration changes.
281 // Called by TrackCanvas::cursor_motion_event.
282 void update_plugin_guis(int do_keyframe_guis = 1);
283 void update_plugin_states();
284 void update_plugin_titles();
285 // Called by Attachmentpoint during playback.
286 // Searches for matching plugin and renders data in it.
287 void render_plugin_gui(void *data, Plugin *plugin);
288 void render_plugin_gui(void *data, int size, Plugin *plugin);
290 // Called from PluginVClient::process_buffer
291 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
293 int plugin_gui_open(Plugin *plugin);
295 void show_keyframe_gui(Plugin *plugin);
296 void hide_keyframe_guis();
297 void hide_keyframe_gui(Plugin *plugin);
298 void update_keyframe_guis();
301 // ============================= editing commands ========================
303 // Map each recordable audio track to the desired pattern
304 void map_audio(int pattern);
305 void remap_audio(int pattern);
311 void add_audio_track_entry(int above, Track *dst);
312 int add_audio_track(int above, Track *dst);
313 void add_clip_to_edl(EDL *edl);
314 void add_video_track_entry(Track *dst = 0);
315 int add_video_track(int above, Track *dst);
316 void add_subttl_track_entry(Track *dst = 0);
317 int add_subttl_track(int above, Track *dst);
320 void asset_to_size();
321 void asset_to_rate();
322 // Entry point for clear operations.
324 // Clears active region in EDL.
325 // If clear_handle, edit boundaries are cleared if the range is 0.
326 // Called by paste, record, menueffects, render, and CWindow drop.
327 void clear(int clear_handle, int deglitch);
329 int clear_labels(double start, double end);
330 void concatenate_tracks();
332 int copy(double start, double end);
334 void blade(double position);
335 void cut(double start, double end, double new_position=-1);
336 // snap off edit from current position to handle/label
337 void snap_left_edit();
338 void snap_right_edit();
339 void snap_left_label();
340 void snap_right_label();
342 // Calculate aspect ratio from pixel counts
343 static int create_aspect_ratio(float &w, float &h, int width, int height);
344 // Calculate defaults path
345 static void create_defaults_path(char *string, const char *config_file);
347 void delete_folder(char *folder);
348 void delete_inpoint();
349 void delete_outpoint();
352 void delete_track(Track *track);
353 void delete_tracks();
354 int feather_edits(int64_t feather_samples, int audio, int video);
355 int64_t get_feather(int audio, int video);
356 float get_aspect_ratio();
357 void insert(double position,
362 EDL *parent_edl /* = 0 */);
364 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
365 // into pluginset_highlighted.
366 void insert_effects_canvas(double start,
369 // CWindow calls this to insert multiple effects from
370 // the drag_pluginservers array.
371 void insert_effects_cwindow(Track *dest_track);
373 // Attach new effect to all recordable tracks
374 // single_standalone - attach 1 standalone on the first track and share it with
376 void insert_effect(char *title,
377 SharedLocation *shared_location,
380 int single_standalone);
382 // This is called multiple times by the above functions.
383 // It can't sync parameters.
384 void insert_effect(char *title,
385 SharedLocation *shared_location,
387 PluginSet *plugin_set,
392 void match_output_size(Track *track);
393 // Move edit to new position
394 void move_edits(ArrayList<Edit*> *edits,
397 int behaviour); // behaviour: 0 - old style (cut and insert elswhere), 1- new style - (clear and overwrite elsewere)
398 // Move effect to position
399 void move_effect(Plugin *plugin,
402 void move_effect(Plugin *plugin,
403 PluginSet *plugin_set,
405 void move_plugins_up(PluginSet *plugin_set);
406 void move_plugins_down(PluginSet *plugin_set);
407 void move_track_down(Track *track);
408 void move_tracks_down();
409 void move_track_up(Track *track);
410 void move_tracks_up();
411 void mute_selection();
412 void new_folder(const char *new_folder);
413 void overwrite(EDL *source);
414 // For clipboard commands
416 // For splice and overwrite
417 int paste(double start,
423 int paste_output(int64_t startproject,
425 int64_t startsource_sample,
426 int64_t endsource_sample,
427 int64_t startsource_frame,
428 int64_t endsource_frame,
430 RecordLabels *new_labels);
431 void paste_silence();
433 // Detach single transition
434 void detach_transition(Transition *transition);
435 // Detach all transitions in selection
436 void detach_transitions();
437 // Attach dragged transition
438 void paste_transition();
439 // Attach transition to all edits in selection
440 void paste_transitions(int track_type, char *title);
441 // Attach transition dragged onto CWindow
442 void paste_transition_cwindow(Track *dest_track);
443 // Attach default transition to single edit
444 void paste_audio_transition();
445 void paste_video_transition();
446 void shuffle_edits();
447 void reverse_edits();
449 void set_edit_length(double length);
450 // Set length of single transition
451 void set_transition_length(Transition *transition, double length);
452 // Set length in seconds of all transitions in active range
453 void set_transition_length(double length);
455 void remove_indexfile(Indexable *indexable);
456 void rebuild_indices();
457 // Asset removal from caches
459 void remove_asset_from_caches(Asset *asset);
460 void remove_assets_from_project(int push_undo /* = 0 */,
462 ArrayList<Indexable*> *drag_assets /* mwindow->session->drag_assets */,
463 ArrayList<EDL*> *drag_clips /* mwindow->session->drag_clips */);
464 void remove_assets_from_disk();
465 void resize_track(Track *track, int w, int h);
467 void set_automation_mode(int mode);
468 void set_keyframe_type(int mode);
469 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
470 void set_auto_visibility(Autos *autos, int value);
471 void set_labels_follow_edits(int value);
473 // Update the editing mode
474 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
475 void toggle_editing_mode();
476 void set_inpoint(int is_mwindow);
477 void set_outpoint(int is_mwindow);
478 void splice(EDL *source);
479 void toggle_loop_playback();
480 void trim_selection();
481 // Synchronize EDL settings with all playback engines depending on current
482 // operation. Doesn't redraw anything.
483 void sync_parameters(int change_type = CHANGE_PARAMS);
484 void save_clip(EDL *new_edl, const char *txt);
485 void to_clip(EDL *edl, const char *txt);
486 int toggle_label(int is_mwindow);
487 void undo_entry(BC_WindowBase *calling_window_gui);
488 void redo_entry(BC_WindowBase *calling_window_gui);
491 int cut_automation();
492 int copy_automation();
493 int paste_automation();
494 void clear_automation();
495 int cut_default_keyframe();
496 int copy_default_keyframe();
497 // Use paste_automation to paste the default keyframe in other position.
498 // Use paste_default_keyframe to replace the default keyframe with whatever is
500 int paste_default_keyframe();
501 int clear_default_keyframe();
503 FloatAuto* get_float_auto(PatchGUI *patch,int idx);
504 IntAuto* get_int_auto(PatchGUI *patch,int idx);
505 PanAuto* get_pan_auto(PatchGUI *patch);
506 PatchGUI *get_patchgui(Track *track);
508 int modify_edithandles();
509 int modify_pluginhandles();
510 void finish_modify_handles();
511 void set_proxy(int use_scaler, int new_scale, int auto_scale,
512 ArrayList<Indexable*> *orig_assets,
513 ArrayList<Indexable*> *proxy_assets);
514 void add_proxy(int use_scaler,
515 ArrayList<Indexable*> *orig_assets,
516 ArrayList<Indexable*> *proxy_assets);
517 void render_proxy(ArrayList<Indexable *> &new_idxbls);
519 void dump_plugins(FILE *fp=stdout);
520 void dump_edl(FILE *fp=stdout);
521 void dump_undo(FILE *fp=stdout);
522 void dump_exe(FILE *fp=stdout);
523 static void trap_hook(FILE *fp, void *vp);
525 void reset_android_remote();
527 // Send new EDL to caches
529 int optimize_assets(); // delete unused assets from the cache and assets
531 void select_point(double position);
532 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
535 Playback3D *playback_3d;
536 SplashGUI *splash_window;
542 // CICaches for drawing timeline only
543 CICache *audio_cache, *video_cache;
544 // Frame cache for drawing timeline only.
545 // Cache drawing doesn't wait for file decoding.
546 FrameCache *frame_cache;
547 WaveCache *wave_cache;
548 Preferences *preferences;
549 PreferencesThread *preferences_thread;
550 MainSession *session;
552 MainIndexes *mainindexes;
553 MainProgress *mainprogress;
557 const char *default_standard;
558 static Commercials *commercials;
559 int commercial_active;
560 int has_commercials();
563 ArrayList<ColormodelItem*> colormodels;
564 ArrayList<InterlacemodeItem*> interlace_project_modes;
565 ArrayList<InterlacemodeItem*> interlace_asset_modes;
566 ArrayList<InterlacefixmethodItem*> interlace_asset_fixmethods;
571 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
572 int select_asset(int vtrack, int delete_tracks);
574 // Channel DB for playback only. Record channel DB's are in record.C
575 ChannelDB *channeldb_buz;
576 ChannelDB *channeldb_v4l2jpeg;
578 // ====================================== plugins ==============================
580 // Contains file descriptors for all the dlopens
581 static ArrayList<PluginServer*> *plugindb;
582 // Currently visible plugins
583 int64_t plugin_visibility;
584 ArrayList<PluginServer*> *plugin_guis;
585 // GUI Plugins to delete
586 ArrayList<PluginServer*> *dead_plugins;
588 ArrayList<KeyFrameThread*> *keyframe_threads;
590 // Adjust sample position to line up with frames.
591 int fix_timing(int64_t &samples_out,
596 CreateBD_Thread *create_bd;
597 CreateDVD_Thread *create_dvd;
598 BatchRenderThread *batch_render;
601 ExportEDL *exportedl;
611 Mutex *vwindows_lock;
612 ArrayList<VWindow*> vwindows;
614 Mutex *zwindows_lock;
615 ArrayList<ZWindow*> zwindows;
624 void show_warning(int *do_warning, const char *text);
627 LevelWindow *lwindow;
629 // Lock during creation and destruction of GUI
630 Mutex *plugin_gui_lock;
631 Mutex *dead_plugin_lock;
632 Mutex *keyframe_gui_lock;
633 // Lock during creation and destruction of brender so playback doesn't use it.
636 // Initialize shared memory
639 // Initialize channel DB's for playback
640 void init_channeldb();
642 void init_exportedl();
643 // These three happen synchronously with each other
644 // Make sure this is called after synchronizing EDL's.
646 // Restart brender after testing its existence
647 void restart_brender();
648 // Stops brender after testing its existence
650 // This one happens asynchronously of the others. Used by playback to
651 // see what frame is background rendered.
652 int brender_available(int position);
653 void set_brender_active(int v, int update=1);
654 int put_commercial();
655 void activate_commercial() { commercial_active = 1; }
656 void commit_commercial();
657 void undo_commercial();
658 void cut_commercials();
659 int paste_subtitle_text(char *text, double start, double end);
663 static void init_defaults(BC_Hash* &defaults, char *config_path);
664 void check_language();
665 const char *default_std();
666 void fill_preset_defaults(const char *preset, EDLSession *session);
667 const char *get_preset_name(int index);
671 void init_tipwindow();
672 // Used by MWindow and RenderFarmClient
673 static void get_plugin_path(char *path, const char *plug_dir, const char *fs_path);
674 static int init_plugins(MWindow *mwindow, Preferences *preferences);
675 static int init_ladspa_plugins(MWindow *mwindow, Preferences *preferences);
676 static void init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang);
677 static int check_plugin_index(ArrayList<PluginServer*> &plugins,
678 const char *plug_dir, const char *plug_path);
679 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
680 FILE *fp, const char *plugin_dir);
681 static int init_ladspa_index(MWindow *mwindow, Preferences *preferences,
682 const char *index_path, const char *plugin_dir);
683 static void scan_plugin_index(MWindow *mwindow, Preferences *preferences,
684 FILE *fp, const char *plug_dir, const char *plug_path, int &idx);
685 static void init_ffmpeg();
686 static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
687 static int load_plugin_index(MWindow *mwindow, const char *index_path,
688 const char *plugin_dir);
689 static PluginServer* new_ffmpeg_server(MWindow *mwindow, const char *name);
690 void init_preferences();
693 void init_compositor();
694 void init_levelwindow();
695 // Called when creating a new viewer to view footage
696 VWindow* get_viewer(int start_it, int idx=-1);
702 void init_playbackcursor();
703 void init_commercials();
704 static void add_plugins(ArrayList<PluginServer*> &plugins);
705 static void delete_plugins();
707 void clean_indexes();
708 // TimeBomb timebomb;
709 SigHandler *sighandler;