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 "arraylist.h"
30 #include "audiodevice.inc"
32 #include "awindow.inc"
33 #include "batchrender.inc"
34 #include "bcwindowbase.inc"
35 #include "bdcreate.inc"
36 #include "brender.inc"
38 #include "channel.inc"
39 #include "channeldb.inc"
40 #include "commercials.inc"
41 #include "cwindow.inc"
43 #include "devicedvbinput.inc"
44 #include "devicempeginput.inc"
45 #include "dvdcreate.inc"
48 #include "edlsession.inc"
49 #include "exportedl.inc"
50 #include "filesystem.inc"
51 #include "filexml.inc"
52 #include "framecache.inc"
53 #include "gwindow.inc"
54 #include "indexable.inc"
55 #include "keyframegui.inc"
56 #include "levelwindow.inc"
57 #include "loadmode.inc"
58 #include "mainerror.inc"
59 #include "mainindexes.inc"
60 #include "mainprogress.inc"
61 #include "mainsession.inc"
62 #include "mainundo.inc"
63 #include "maxchannels.h"
65 #include "mwindow.inc"
66 #include "mwindowgui.inc"
68 #include "patchbay.inc"
69 #include "playback3d.inc"
70 #include "playbackengine.inc"
72 #include "pluginfclient.inc"
73 #include "pluginserver.inc"
74 #include "pluginset.inc"
75 #include "preferences.inc"
76 #include "preferencesthread.inc"
78 #include "recordlabel.inc"
80 #include "sharedlocation.inc"
81 #include "sighandler.inc"
82 #include "splashgui.inc"
85 #include "threadloader.inc"
86 #include "timebar.inc"
88 #include "tipwindow.inc"
90 #include "tracking.inc"
92 #include "transition.inc"
93 #include "transportque.inc"
94 #include "videowindow.inc"
95 #include "vwindow.inc"
96 #include "wwindow.inc"
97 #include "wavecache.inc"
99 #define FONT_SEARCHPATH "fonts"
101 // All entry points for commands except for window locking should be here.
102 // This allows scriptability.
104 class MWindow : public Thread
110 // ======================================== initialization commands
111 void create_objects(int want_gui,
119 int run_script(FileXML *script);
121 int delete_project(int flash = 1);
122 void quit(int unlock);
123 int restart() { return restart_status; }
127 int set_filename(const char *filename);
128 // Total vertical pixels in timeline
129 int get_tracks_height();
130 // Total horizontal pixels in timeline
131 int get_tracks_width();
138 int tile_windows(int window_config);
139 char *get_cwindow_display();
140 // void set_titles(int value);
141 void set_screens(int value);
142 int asset_to_edl(EDL *new_edl,
144 RecordLabels *labels = 0);
145 // Convert nested_edl to a nested EDL in new_edl
146 // suitable for pasting in paste_edls
147 int edl_to_nested(EDL *new_edl,
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 int plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins);
199 static int plugin_exists(char *plugin_path);
200 void dump_plugindb(FILE *fp);
201 void stop_playback(int wait=0);
206 int load_filenames(ArrayList<char*> *filenames,
207 int load_mode = LOADMODE_REPLACE,
208 // Cause the project filename on the top of the window to be updated.
209 // Not wanted for loading backups.
210 int update_filename = 1);
213 // Print out plugins which are referenced in the EDL but not loaded.
214 void test_plugins(EDL *new_edl, char *path);
216 int interrupt_indexes(); // Stop index building
218 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
220 // =========================================== movement
222 void next_time_format();
223 void prev_time_format();
224 void time_format_common();
225 int reposition_timebar(int new_pixel, int new_height);
227 int zoom_in_sample();
228 int zoom_sample(int64_t zoom_sample);
229 void zoom_autos(float min, float max);
230 void zoom_amp(int64_t zoom_amp);
231 void zoom_track(int64_t zoom_track);
233 int move_left(int64_t distance = 0);
234 int move_right(int64_t distance = 0);
235 void move_up(int64_t distance = 0);
236 void move_down(int64_t distance = 0);
239 // shift_down must be passed by the caller because different windows call
241 int next_label(int shift_down);
242 int prev_label(int shift_down);
243 // seek to edit handles
244 int next_edit_handle(int shift_down);
245 int prev_edit_handle(int shift_down);
246 // offset is pixels to add to track_start
247 void trackmovement(int offset, int pane_number);
248 // view_start is pixels
249 int samplemovement(int64_t view_start, int pane_number);
253 int goto_position(double position);
261 void update_plugins();
262 // Call after every edit operation
265 void show_plugin(Plugin *plugin);
266 void hide_plugin(Plugin *plugin, int lock);
268 void delete_plugin(PluginServer *plugin);
269 // Update plugins with configuration changes.
270 // Called by TrackCanvas::cursor_motion_event.
271 void update_plugin_guis(int do_keyframe_guis = 1);
272 void update_plugin_states();
273 void update_plugin_titles();
274 // Called by Attachmentpoint during playback.
275 // Searches for matching plugin and renders data in it.
276 void render_plugin_gui(void *data, Plugin *plugin);
277 void render_plugin_gui(void *data, int size, Plugin *plugin);
279 // Called from PluginVClient::process_buffer
280 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
282 int plugin_gui_open(Plugin *plugin);
284 void show_keyframe_gui(Plugin *plugin);
285 void hide_keyframe_guis();
286 void hide_keyframe_gui(Plugin *plugin);
287 void update_keyframe_guis();
290 // ============================= editing commands ========================
292 // Map each recordable audio track to the desired pattern
293 void map_audio(int pattern);
294 void remap_audio(int pattern);
300 void add_audio_track_entry(int above, Track *dst);
301 int add_audio_track(int above, Track *dst);
302 void add_clip_to_edl(EDL *edl);
303 void add_video_track_entry(Track *dst = 0);
304 int add_video_track(int above, Track *dst);
305 void add_subttl_track_entry(Track *dst = 0);
306 int add_subttl_track(int above, Track *dst);
309 void asset_to_size();
310 void asset_to_rate();
311 // Entry point for clear operations.
313 // Clears active region in EDL.
314 // If clear_handle, edit boundaries are cleared if the range is 0.
315 // Called by paste, record, menueffects, render, and CWindow drop.
316 void clear(int clear_handle);
318 int clear_labels(double start, double end);
319 void concatenate_tracks();
321 int copy(double start, double end);
324 // Calculate aspect ratio from pixel counts
325 static int create_aspect_ratio(float &w, float &h, int width, int height);
326 // Calculate defaults path
327 static void create_defaults_path(char *string, const char *config_file);
329 void delete_folder(char *folder);
330 void delete_inpoint();
331 void delete_outpoint();
334 void delete_track(Track *track);
335 void delete_tracks();
336 int feather_edits(int64_t feather_samples, int audio, int video);
337 int64_t get_feather(int audio, int video);
338 float get_aspect_ratio();
339 void insert(double position,
344 EDL *parent_edl /* = 0 */);
346 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
347 // into pluginset_highlighted.
348 void insert_effects_canvas(double start,
351 // CWindow calls this to insert multiple effects from
352 // the drag_pluginservers array.
353 void insert_effects_cwindow(Track *dest_track);
355 // Attach new effect to all recordable tracks
356 // single_standalone - attach 1 standalone on the first track and share it with
358 void insert_effect(char *title,
359 SharedLocation *shared_location,
362 int single_standalone);
364 // This is called multiple times by the above functions.
365 // It can't sync parameters.
366 void insert_effect(char *title,
367 SharedLocation *shared_location,
369 PluginSet *plugin_set,
374 void match_output_size(Track *track);
375 // Move edit to new position
376 void move_edits(ArrayList<Edit*> *edits,
379 int behaviour); // behaviour: 0 - old style (cut and insert elswhere), 1- new style - (clear and overwrite elsewere)
380 // Move effect to position
381 void move_effect(Plugin *plugin,
384 void move_effect(Plugin *plugin,
385 PluginSet *plugin_set,
387 void move_plugins_up(PluginSet *plugin_set);
388 void move_plugins_down(PluginSet *plugin_set);
389 void move_track_down(Track *track);
390 void move_tracks_down();
391 void move_track_up(Track *track);
392 void move_tracks_up();
393 void mute_selection();
394 void new_folder(const char *new_folder);
395 void overwrite(EDL *source);
396 // For clipboard commands
398 // For splice and overwrite
399 int paste(double start,
405 int paste_output(int64_t startproject,
407 int64_t startsource_sample,
408 int64_t endsource_sample,
409 int64_t startsource_frame,
410 int64_t endsource_frame,
412 RecordLabels *new_labels);
413 void paste_silence();
415 // Detach single transition
416 void detach_transition(Transition *transition);
417 // Detach all transitions in selection
418 void detach_transitions();
419 // Attach dragged transition
420 void paste_transition();
421 // Attach transition to all edits in selection
422 void paste_transitions(int track_type, char *title);
423 // Attach transition dragged onto CWindow
424 void paste_transition_cwindow(Track *dest_track);
425 // Attach default transition to single edit
426 void paste_audio_transition();
427 void paste_video_transition();
428 void shuffle_edits();
429 void reverse_edits();
431 void set_edit_length(double length);
432 // Set length of single transition
433 void set_transition_length(Transition *transition, double length);
434 // Set length in seconds of all transitions in active range
435 void set_transition_length(double length);
437 void remove_indexfile(Indexable *indexable);
438 void rebuild_indices();
439 // Asset removal from caches
441 void remove_asset_from_caches(Asset *asset);
442 void remove_assets_from_project(int push_undo /* = 0 */,
444 ArrayList<Indexable*> *drag_assets /* mwindow->session->drag_assets */,
445 ArrayList<EDL*> *drag_clips /* mwindow->session->drag_clips */);
446 void remove_assets_from_disk();
447 void resize_track(Track *track, int w, int h);
449 void set_automation_mode(int mode);
450 void set_keyframe_type(int mode);
451 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
452 void set_auto_visibility(Autos *autos, int value);
453 void set_labels_follow_edits(int value);
455 // Update the editing mode
456 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
457 void toggle_editing_mode();
458 void set_inpoint(int is_mwindow);
459 void set_outpoint(int is_mwindow);
460 void splice(EDL *source);
461 void toggle_loop_playback();
462 void trim_selection();
463 // Synchronize EDL settings with all playback engines depending on current
464 // operation. Doesn't redraw anything.
465 void sync_parameters(int change_type = CHANGE_PARAMS);
467 int toggle_label(int is_mwindow);
468 void undo_entry(BC_WindowBase *calling_window_gui);
469 void redo_entry(BC_WindowBase *calling_window_gui);
472 int cut_automation();
473 int copy_automation();
474 int paste_automation();
475 void clear_automation();
476 int cut_default_keyframe();
477 int copy_default_keyframe();
478 // Use paste_automation to paste the default keyframe in other position.
479 // Use paste_default_keyframe to replace the default keyframe with whatever is
481 int paste_default_keyframe();
482 int clear_default_keyframe();
484 int modify_edithandles();
485 int modify_pluginhandles();
486 void finish_modify_handles();
488 void dump_plugins(FILE *fp=stdout);
489 void dump_edl(FILE *fp=stdout);
490 void dump_undo(FILE *fp=stdout);
491 void dump_exe(FILE *fp=stdout);
492 static void trap_hook(FILE *fp, void *vp);
494 void reset_android_remote();
496 // Send new EDL to caches
498 int optimize_assets(); // delete unused assets from the cache and assets
500 void select_point(double position);
501 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
504 Playback3D *playback_3d;
505 SplashGUI *splash_window;
511 // CICaches for drawing timeline only
512 CICache *audio_cache, *video_cache;
513 // Frame cache for drawing timeline only.
514 // Cache drawing doesn't wait for file decoding.
515 FrameCache *frame_cache;
516 WaveCache *wave_cache;
517 Preferences *preferences;
518 PreferencesThread *preferences_thread;
519 MainSession *session;
521 MainIndexes *mainindexes;
522 MainProgress *mainprogress;
524 const char *default_standard;
525 static Commercials *commercials;
526 int commercial_active;
527 int has_commercials();
530 ArrayList<ColormodelItem*> colormodels;
531 ArrayList<InterlacemodeItem*> interlace_project_modes;
532 ArrayList<InterlacemodeItem*> interlace_asset_modes;
533 ArrayList<InterlacefixmethodItem*> interlace_asset_fixmethods;
538 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
539 int select_asset(int vtrack, int delete_tracks);
541 // Channel DB for playback only. Record channel DB's are in record.C
542 ChannelDB *channeldb_buz;
543 ChannelDB *channeldb_v4l2jpeg;
545 // ====================================== plugins ==============================
547 // Contains file descriptors for all the dlopens
548 static ArrayList<PluginServer*> *plugindb;
549 // Currently visible plugins
550 int64_t plugin_visibility;
551 ArrayList<PluginServer*> *plugin_guis;
552 // GUI Plugins to delete
553 ArrayList<PluginServer*> *dead_plugins;
555 ArrayList<KeyFrameThread*> *keyframe_threads;
557 // Adjust sample position to line up with frames.
558 int fix_timing(int64_t &samples_out,
563 CreateBD_Thread *create_bd;
564 CreateDVD_Thread *create_dvd;
565 BatchRenderThread *batch_render;
568 ExportEDL *exportedl;
578 Mutex *vwindows_lock;
579 ArrayList<VWindow*> vwindows;
588 void show_warning(int *do_warning, const char *text);
591 LevelWindow *lwindow;
592 // Lock during creation and destruction of GUI
593 Mutex *plugin_gui_lock;
594 Mutex *dead_plugin_lock;
595 Mutex *keyframe_gui_lock;
596 // Lock during creation and destruction of brender so playback doesn't use it.
599 // Initialize shared memory
602 // Initialize channel DB's for playback
603 void init_channeldb();
605 void init_exportedl();
606 // These three happen synchronously with each other
607 // Make sure this is called after synchronizing EDL's.
609 // Restart brender after testing its existence
610 void restart_brender();
611 // Stops brender after testing its existence
613 // This one happens asynchronously of the others. Used by playback to
614 // see what frame is background rendered.
615 int brender_available(int position);
616 void set_brender_start();
617 int put_commercial();
618 void activate_commercial() { commercial_active = 1; }
619 void commit_commercial();
620 void undo_commercial();
621 void cut_commercials();
622 int paste_subtitle_text(char *text, double start, double end);
626 static void init_defaults(BC_Hash* &defaults, char *config_path);
627 const char *default_std();
628 void fill_preset_defaults(const char *preset, EDLSession *session);
629 const char *get_preset_name(int index);
633 void init_tipwindow();
634 // Used by MWindow and RenderFarmClient
635 static void get_plugin_path(char *path, const char *plug_dir, const char *fs_path);
636 static int init_plugins(MWindow *mwindow, Preferences *preferences);
637 static int init_ladspa_plugins(MWindow *mwindow, Preferences *preferences);
638 static int check_plugin_index(ArrayList<PluginServer*> &plugins,
639 const char *plug_dir, const char *plug_path);
640 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
641 FILE *fp, const char *plugin_dir);
642 static int init_ladspa_index(MWindow *mwindow, Preferences *preferences,
643 const char *index_path, const char *plugin_dir);
644 static void scan_plugin_index(MWindow *mwindow, Preferences *preferences,
645 FILE *fp, const char *plug_dir, const char *plug_path, int &idx);
646 static void init_ffmpeg();
647 static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
648 static int load_plugin_index(MWindow *mwindow, const char *index_path,
649 const char *plugin_dir);
650 static PluginServer* new_ffmpeg_server(MWindow *mwindow, const char *name);
651 void init_preferences();
654 void init_compositor();
655 void init_levelwindow();
656 // Called when creating a new viewer to view footage
657 VWindow* get_viewer(int start_it, int idx=-1);
663 void init_playbackcursor();
664 void init_commercials();
665 static void add_plugins(ArrayList<PluginServer*> &plugins);
666 static void delete_plugins();
668 void clean_indexes();
669 // TimeBomb timebomb;
670 SigHandler *sighandler;