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);
150 // Entry point to insert assets and insert edls. Called by TrackCanvas
151 // and AssetPopup when assets are dragged in from AWindow.
152 // Takes the drag vectors from MainSession and
153 // pastes either assets or clips depending on which is full.
154 // Returns 1 if the vectors were full
155 int paste_assets(double position, Track *dest_track, int overwrite);
157 // Insert the assets at a point in the EDL. Called by menueffects,
158 // render, and CWindow drop but recording calls paste_edls directly for
160 void load_assets(ArrayList<Indexable*> *new_assets,
163 Track *first_track /* = 0 */,
164 RecordLabels *labels /* = 0 */,
169 int paste_edls(ArrayList<EDL*> *new_edls,
171 Track *first_track /* = 0 */,
172 double current_position /* = -1 */,
177 // Reset everything for a load
178 void update_project(int load_mode);
179 // Fit selected time to horizontal display range
180 void fit_selection();
181 // Fit selected autos to the vertical display range
182 void fit_autos(int doall);
183 void change_currentautorange(int autogrouptype, int increment, int changemax);
184 void expand_autos(int changeall, int domin, int domax);
185 void shrink_autos(int changeall, int domin, int domax);
186 // move the window to include the cursor
188 // Search plugindb and put results in argument
189 static void search_plugindb(int do_audio,
194 ArrayList<PluginServer*> &results);
195 // Find the plugin whose title matches title and return it
196 static PluginServer* scan_plugindb(char *title,
198 static void fix_plugin_title(char *title);
199 static int plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins);
200 static int plugin_exists(char *plugin_path);
201 void dump_plugindb(FILE *fp);
202 void stop_playback(int wait);
203 void stop_transport();
205 void queue_mixers(EDL *edl, int command, int wait_tracking,
206 int use_inout, int update_refresh, int toggle_audio, int loop_play);
207 ZWindow *create_mixer(Indexable *indexable);
208 void create_mixers();
209 void refresh_mixers(int dir=1);
213 ZWindow *get_mixer(Mixer *&mixer);
214 void del_mixer(ZWindow *zwindow);
215 int mixer_track_active(Track *track);
216 void update_mixer_tracks();
218 int select_zwindow(ZWindow *zwindow);
221 int load_filenames(ArrayList<char*> *filenames,
222 int load_mode = LOADMODE_REPLACE,
223 // Cause the project filename on the top of the window to be updated.
224 // Not wanted for loading backups.
225 int update_filename = 1);
228 // Print out plugins which are referenced in the EDL but not loaded.
229 void test_plugins(EDL *new_edl, char *path);
231 int interrupt_indexes(); // Stop index building
233 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
235 // =========================================== movement
237 void next_time_format();
238 void prev_time_format();
239 void time_format_common();
240 int reposition_timebar(int new_pixel, int new_height);
242 int zoom_in_sample();
243 int zoom_sample(int64_t zoom_sample);
244 void zoom_autos(float min, float max);
245 void zoom_amp(int64_t zoom_amp);
246 void zoom_track(int64_t zoom_track);
248 int move_left(int64_t distance = 0);
249 int move_right(int64_t distance = 0);
250 void move_up(int64_t distance = 0);
251 void move_down(int64_t distance = 0);
252 int find_selection(double position, int scroll_display = 0);
255 // shift_down must be passed by the caller because different windows call
257 int next_label(int shift_down);
258 int prev_label(int shift_down);
259 // seek to edit handles
260 int next_edit_handle(int shift_down);
261 int prev_edit_handle(int shift_down);
263 int nearest_plugin_keyframe(int shift_down, int dir);
264 // offset is pixels to add to track_start
265 void trackmovement(int offset, int pane_number);
266 // view_start is pixels
267 int samplemovement(int64_t view_start, int pane_number);
271 int goto_position(double position);
279 void update_plugins();
280 // Call after every edit operation
283 void show_plugin(Plugin *plugin);
284 void hide_plugin(Plugin *plugin, int lock);
286 void delete_plugin(PluginServer *plugin);
287 // Update plugins with configuration changes.
288 // Called by TrackCanvas::cursor_motion_event.
289 void update_plugin_guis(int do_keyframe_guis = 1);
290 void update_plugin_states();
291 void update_plugin_titles();
292 // Called by Attachmentpoint during playback.
293 // Searches for matching plugin and renders data in it.
294 void render_plugin_gui(void *data, Plugin *plugin);
295 void render_plugin_gui(void *data, int size, Plugin *plugin);
297 // Called from PluginVClient::process_buffer
298 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
300 int plugin_gui_open(Plugin *plugin);
302 void show_keyframe_gui(Plugin *plugin);
303 void hide_keyframe_guis();
304 void hide_keyframe_gui(Plugin *plugin);
305 void update_keyframe_guis();
308 // ============================= editing commands ========================
310 // Map each recordable audio track to the desired pattern
311 void map_audio(int pattern);
312 void remap_audio(int pattern);
318 void add_audio_track_entry(int above, Track *dst);
319 int add_audio_track(int above, Track *dst);
320 void add_clip_to_edl(EDL *edl);
321 void add_video_track_entry(Track *dst = 0);
322 int add_video_track(int above, Track *dst);
323 void add_subttl_track_entry(Track *dst = 0);
324 int add_subttl_track(int above, Track *dst);
327 void asset_to_size();
328 void asset_to_rate();
329 // Entry point for clear operations.
331 // Clears active region in EDL.
332 // If clear_handle, edit boundaries are cleared if the range is 0.
333 // Called by paste, record, menueffects, render, and CWindow drop.
334 void clear(int clear_handle);
336 int clear_labels(double start, double end);
337 void concatenate_tracks();
339 int copy(double start, double end);
341 void blade(double position);
342 void cut(double start, double end, double new_position=-1);
343 // cut edit from current position to handle/label
344 void cut_left_edit();
345 void cut_right_edit();
346 void cut_left_label();
347 void cut_right_label();
349 // Calculate aspect ratio from pixel counts
350 static int create_aspect_ratio(float &w, float &h, int width, int height);
351 // Calculate defaults path
352 static void create_defaults_path(char *string, const char *config_file);
354 void delete_folder(char *folder);
357 void delete_track(Track *track);
358 void delete_tracks();
359 int feather_edits(int64_t feather_samples, int audio, int video);
360 int64_t get_feather(int audio, int video);
361 float get_aspect_ratio();
362 void insert(double position,
367 EDL *parent_edl /* = 0 */);
369 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
370 // into pluginset_highlighted.
371 void insert_effects_canvas(double start,
374 // CWindow calls this to insert multiple effects from
375 // the drag_pluginservers array.
376 void insert_effects_cwindow(Track *dest_track);
378 // Attach new effect to all recordable tracks
379 // single_standalone - attach 1 standalone on the first track and share it with
381 void insert_effect(char *title,
382 SharedLocation *shared_location,
385 int single_standalone);
387 // This is called multiple times by the above functions.
388 // It can't sync parameters.
389 void insert_effect(char *title,
390 SharedLocation *shared_location,
392 PluginSet *plugin_set,
397 void match_output_size(Track *track);
398 // Move edit to new position
399 void move_edits(ArrayList<Edit*> *edits,
402 int behaviour); // behaviour: 0 - old style (cut and insert elswhere), 1- new style - (clear and overwrite elsewere)
403 // Move effect to position
404 void move_effect(Plugin *plugin,
407 void move_effect(Plugin *plugin,
408 PluginSet *plugin_set,
410 void move_plugins_up(PluginSet *plugin_set);
411 void move_plugins_down(PluginSet *plugin_set);
412 void move_track_down(Track *track);
413 void move_tracks_down();
414 void move_track_up(Track *track);
415 void move_tracks_up();
416 void mute_selection();
417 void new_folder(const char *new_folder);
418 // For clipboard commands
420 // For splice and overwrite
421 void overwrite(EDL *source, int all);
422 void splice(EDL *source, int all);
423 int paste(double start, double end, FileXML *file,
424 int edit_labels, int edit_plugins, int edit_autos);
425 int paste_output(int64_t startproject, int64_t endproject,
426 int64_t startsource_sample, int64_t endsource_sample,
427 int64_t startsource_frame, int64_t endsource_frame,
428 Asset *asset, RecordLabels *new_labels);
429 void paste_silence();
431 // Detach single transition
432 void detach_transition(Transition *transition);
433 // Detach all transitions in selection
434 void detach_transitions();
435 // Attach dragged transition
436 void paste_transition();
437 // Attach transition to all edits in selection
438 void paste_transitions(int track_type, char *title);
439 // Attach transition dragged onto CWindow
440 void paste_transition_cwindow(Track *dest_track);
441 // Attach default transition to single edit
442 void paste_audio_transition();
443 void paste_video_transition();
444 void shuffle_edits();
445 void reverse_edits();
447 void set_edit_length(double length);
448 // Set length of single transition
449 void set_transition_length(Transition *transition, double length);
450 // Set length in seconds of all transitions in active range
451 void set_transition_length(double length);
453 void remove_indexfile(Indexable *indexable);
454 void rebuild_indices();
455 // Asset removal from caches
457 void remove_asset_from_caches(Asset *asset);
458 void remove_assets_from_project(int push_undo /* = 0 */,
460 ArrayList<Indexable*> *drag_assets /* mwindow->session->drag_assets */,
461 ArrayList<EDL*> *drag_clips /* mwindow->session->drag_clips */);
462 void remove_assets_from_disk();
463 void resize_track(Track *track, int w, int h);
465 void set_automation_mode(int mode);
466 void set_keyframe_type(int mode);
467 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
468 void set_auto_visibility(Autos *autos, int value);
469 void set_labels_follow_edits(int value);
471 // Update the editing mode
472 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
473 void toggle_editing_mode();
474 void set_inpoint(int is_mwindow);
475 void set_outpoint(int is_mwindow);
476 void unset_inoutpoint(int is_mwindow);
477 void toggle_loop_playback();
478 void trim_selection();
479 // Synchronize EDL settings with all playback engines depending on current
480 // operation. Doesn't redraw anything.
481 void sync_parameters(int change_type = CHANGE_PARAMS);
482 void save_clip(EDL *new_edl, const char *txt);
483 void to_clip(EDL *edl, const char *txt, int all);
484 int toggle_label(int is_mwindow);
485 void undo_entry(BC_WindowBase *calling_window_gui);
486 void redo_entry(BC_WindowBase *calling_window_gui);
487 void save_undo_data();
488 void load_undo_data();
490 int cut_automation();
491 int copy_automation();
492 int paste_automation();
493 void clear_automation();
494 int cut_default_keyframe();
495 int copy_default_keyframe();
496 // Use paste_automation to paste the default keyframe in other position.
497 // Use paste_default_keyframe to replace the default keyframe with whatever is
499 int paste_default_keyframe();
500 int clear_default_keyframe();
502 FloatAuto* get_float_auto(PatchGUI *patch,int idx);
503 IntAuto* get_int_auto(PatchGUI *patch,int idx);
504 PanAuto* get_pan_auto(PatchGUI *patch);
505 PatchGUI *get_patchgui(Track *track);
507 int modify_edithandles();
508 int modify_pluginhandles();
509 void finish_modify_handles();
510 void set_proxy(int use_scaler, int new_scale, int auto_scale,
511 ArrayList<Indexable*> *orig_assets,
512 ArrayList<Indexable*> *proxy_assets);
513 void add_proxy(int use_scaler,
514 ArrayList<Indexable*> *orig_assets,
515 ArrayList<Indexable*> *proxy_assets);
516 void render_proxy(ArrayList<Indexable *> &new_idxbls);
518 void dump_plugins(FILE *fp=stdout);
519 void dump_edl(FILE *fp=stdout);
520 void dump_undo(FILE *fp=stdout);
521 void dump_exe(FILE *fp=stdout);
522 static void trap_hook(FILE *fp, void *vp);
524 void reset_android_remote();
526 // Send new EDL to caches
528 int optimize_assets(); // delete unused assets from the cache and assets
530 void select_point(double position);
531 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
534 Playback3D *playback_3d;
535 SplashGUI *splash_window;
541 // CICaches for drawing timeline only
542 CICache *audio_cache, *video_cache;
543 // Frame cache for drawing timeline only.
544 // Cache drawing doesn't wait for file decoding.
545 FrameCache *frame_cache;
546 WaveCache *wave_cache;
547 Preferences *preferences;
548 PreferencesThread *preferences_thread;
549 MainSession *session;
551 MainIndexes *mainindexes;
552 MainProgress *mainprogress;
556 const char *default_standard;
557 static Commercials *commercials;
558 int commercial_active;
559 int has_commercials();
560 // copy of edl created in speed_before, used in speed_after to normalize_speed
564 ArrayList<ColormodelItem*> colormodels;
565 ArrayList<InterlacemodeItem*> interlace_project_modes;
566 ArrayList<InterlacemodeItem*> interlace_asset_modes;
567 ArrayList<InterlacefixmethodItem*> interlace_asset_fixmethods;
572 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
573 int select_asset(int vtrack, int delete_tracks);
575 // Channel DB for playback only. Record channel DB's are in record.C
576 ChannelDB *channeldb_buz;
577 ChannelDB *channeldb_v4l2jpeg;
579 // ====================================== plugins ==============================
581 // Contains file descriptors for all the dlopens
582 static ArrayList<PluginServer*> *plugindb;
583 // Currently visible plugins
584 int64_t plugin_visibility;
585 ArrayList<PluginServer*> *plugin_guis;
586 // GUI Plugins to delete
587 ArrayList<PluginServer*> *dead_plugins;
589 ArrayList<KeyFrameThread*> *keyframe_threads;
591 // Adjust sample position to line up with frames.
592 int fix_timing(int64_t &samples_out,
597 CreateBD_Thread *create_bd;
598 CreateDVD_Thread *create_dvd;
599 BatchRenderThread *batch_render;
602 ExportEDL *exportedl;
612 Mutex *vwindows_lock;
613 ArrayList<VWindow*> vwindows;
615 Mutex *zwindows_lock;
616 ArrayList<ZWindow*> zwindows;
625 void show_warning(int *do_warning, const char *text);
628 LevelWindow *lwindow;
630 // Lock during creation and destruction of GUI
631 Mutex *plugin_gui_lock;
632 Mutex *dead_plugin_lock;
633 Mutex *keyframe_gui_lock;
634 // Lock during creation and destruction of brender so playback doesn't use it.
637 // Initialize shared memory
638 void init_shm(const char *pfn, int64_t min);
640 // Initialize channel DB's for playback
641 void init_channeldb();
643 void init_exportedl();
644 // These three happen synchronously with each other
645 // Make sure this is called after synchronizing EDL's.
647 // Restart brender after testing its existence
648 void restart_brender();
649 // Stops brender after testing its existence
651 // This one happens asynchronously of the others. Used by playback to
652 // see what frame is background rendered.
653 int brender_available(int position);
654 void set_brender_active(int v, int update=1);
655 int put_commercial();
656 void activate_commercial() { commercial_active = 1; }
657 void commit_commercial();
658 void undo_commercial();
659 void cut_commercials();
660 void update_gui(int changed_edl);
661 int paste_subtitle_text(char *text, double start, double end);
665 static void init_defaults(BC_Hash* &defaults, char *config_path);
666 void check_language();
667 const char *default_std();
668 void fill_preset_defaults(const char *preset, EDLSession *session);
669 const char *get_preset_name(int index);
673 void init_tipwindow();
674 // Used by MWindow and RenderFarmClient
675 static void get_plugin_path(char *path, const char *plug_dir, const char *fs_path);
676 static int init_plugins(MWindow *mwindow, Preferences *preferences);
677 static int init_ladspa_plugins(MWindow *mwindow, Preferences *preferences);
678 static void init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang);
679 static int check_plugin_index(ArrayList<PluginServer*> &plugins,
680 const char *plug_dir, const char *plug_path);
681 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
682 FILE *fp, const char *plugin_dir);
683 static int init_ladspa_index(MWindow *mwindow, Preferences *preferences,
684 const char *index_path, const char *plugin_dir);
685 static void scan_plugin_index(MWindow *mwindow, Preferences *preferences,
686 FILE *fp, const char *plug_dir, const char *plug_path, int &idx);
687 static void init_ffmpeg();
688 static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
689 static int load_plugin_index(MWindow *mwindow, const char *index_path,
690 const char *plugin_dir);
691 static PluginServer* new_ffmpeg_server(MWindow *mwindow, const char *name);
692 void init_preferences();
695 void init_compositor();
696 void init_levelwindow();
697 // Called when creating a new viewer to view footage
698 VWindow* get_viewer(int start_it, int idx=-1);
704 void init_playbackcursor();
705 void init_commercials();
706 static void add_plugins(ArrayList<PluginServer*> &plugins);
707 static void delete_plugins();
709 int speed_after(int done);
710 int normalize_speed(EDL *old_edl, EDL *new_edl);
712 void clean_indexes();
713 // TimeBomb timebomb;
714 SigHandler *sighandler;