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"
31 #include "awindow.inc"
32 #include "batchrender.inc"
33 #include "bcwindowbase.inc"
34 #include "bdcreate.inc"
35 #include "brender.inc"
37 #include "channel.inc"
38 #include "channeldb.inc"
39 #include "commercials.inc"
40 #include "cwindow.inc"
42 #include "devicedvbinput.inc"
43 #include "devicempeginput.inc"
44 #include "dvdcreate.inc"
47 #include "edlsession.inc"
48 #include "exportedl.inc"
49 #include "filesystem.inc"
50 #include "filexml.inc"
51 #include "framecache.inc"
52 #include "gwindow.inc"
53 #include "indexable.inc"
54 #include "keyframegui.inc"
55 #include "levelwindow.inc"
56 #include "loadmode.inc"
57 #include "mainerror.inc"
58 #include "mainindexes.inc"
59 #include "mainprogress.inc"
60 #include "mainsession.inc"
61 #include "mainundo.inc"
62 #include "maxchannels.h"
64 #include "mwindow.inc"
65 #include "mwindowgui.inc"
67 #include "patchbay.inc"
68 #include "playback3d.inc"
69 #include "playbackengine.inc"
71 #include "pluginfclient.inc"
72 #include "pluginserver.inc"
73 #include "pluginset.inc"
74 #include "preferences.inc"
75 #include "preferencesthread.inc"
77 #include "recordlabel.inc"
79 #include "sharedlocation.inc"
80 #include "sighandler.inc"
81 #include "splashgui.inc"
84 #include "threadloader.inc"
85 #include "timebar.inc"
87 #include "tipwindow.inc"
89 #include "tracking.inc"
91 #include "transition.inc"
92 #include "transportque.inc"
93 #include "videowindow.inc"
94 #include "vwindow.inc"
95 #include "wwindow.inc"
96 #include "wavecache.inc"
98 #define FONT_SEARCHPATH "fonts"
100 // All entry points for commands except for window locking should be here.
101 // This allows scriptability.
103 class MWindow : public Thread
109 // ======================================== initialization commands
110 void create_objects(int want_gui,
118 int run_script(FileXML *script);
120 int delete_project(int flash = 1);
121 void quit(int unlock);
122 int restart() { return restart_status; }
126 int set_filename(const char *filename);
127 // Total vertical pixels in timeline
128 int get_tracks_height();
129 // Total horizontal pixels in timeline
130 int get_tracks_width();
137 int tile_windows(int window_config);
138 char *get_cwindow_display();
139 // void set_titles(int value);
140 void set_screens(int value);
141 int asset_to_edl(EDL *new_edl,
143 RecordLabels *labels = 0);
144 // Convert nested_edl to a nested EDL in new_edl
145 // suitable for pasting in paste_edls
146 int edl_to_nested(EDL *new_edl,
149 // Entry point to insert assets and insert edls. Called by TrackCanvas
150 // and AssetPopup when assets are dragged in from AWindow.
151 // Takes the drag vectors from MainSession and
152 // pastes either assets or clips depending on which is full.
153 // Returns 1 if the vectors were full
154 int paste_assets(double position, Track *dest_track, int overwrite);
156 // Insert the assets at a point in the EDL. Called by menueffects,
157 // render, and CWindow drop but recording calls paste_edls directly for
159 void load_assets(ArrayList<Indexable*> *new_assets,
162 Track *first_track /* = 0 */,
163 RecordLabels *labels /* = 0 */,
168 int paste_edls(ArrayList<EDL*> *new_edls,
170 Track *first_track /* = 0 */,
171 double current_position /* = -1 */,
176 // Reset everything for a load
177 void update_project(int load_mode);
178 // Fit selected time to horizontal display range
179 void fit_selection();
180 // Fit selected autos to the vertical display range
181 void fit_autos(int doall);
182 void change_currentautorange(int autogrouptype, int increment, int changemax);
183 void expand_autos(int changeall, int domin, int domax);
184 void shrink_autos(int changeall, int domin, int domax);
185 // move the window to include the cursor
187 // Search plugindb and put results in argument
188 static void search_plugindb(int do_audio,
193 ArrayList<PluginServer*> &results);
194 // Find the plugin whose title matches title and return it
195 static PluginServer* scan_plugindb(char *title,
197 static int plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins);
198 static int plugin_exists(char *plugin_path);
199 void dump_plugindb(FILE *fp);
200 void stop_playback(int wait=0);
205 int load_filenames(ArrayList<char*> *filenames,
206 int load_mode = LOADMODE_REPLACE,
207 // Cause the project filename on the top of the window to be updated.
208 // Not wanted for loading backups.
209 int update_filename = 1);
212 // Print out plugins which are referenced in the EDL but not loaded.
213 void test_plugins(EDL *new_edl, char *path);
215 int interrupt_indexes(); // Stop index building
217 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
219 // =========================================== movement
221 void next_time_format();
222 void prev_time_format();
223 void time_format_common();
224 int reposition_timebar(int new_pixel, int new_height);
226 int zoom_in_sample();
227 int zoom_sample(int64_t zoom_sample);
228 void zoom_autos(float min, float max);
229 void zoom_amp(int64_t zoom_amp);
230 void zoom_track(int64_t zoom_track);
232 int move_left(int64_t distance = 0);
233 int move_right(int64_t distance = 0);
234 void move_up(int64_t distance = 0);
235 void move_down(int64_t distance = 0);
238 // shift_down must be passed by the caller because different windows call
240 int next_label(int shift_down);
241 int prev_label(int shift_down);
242 // seek to edit handles
243 int next_edit_handle(int shift_down);
244 int prev_edit_handle(int shift_down);
245 // offset is pixels to add to track_start
246 void trackmovement(int offset, int pane_number);
247 // view_start is pixels
248 int samplemovement(int64_t view_start, int pane_number);
252 int goto_position(double position);
260 void update_plugins();
261 // Call after every edit operation
264 void show_plugin(Plugin *plugin);
265 void hide_plugin(Plugin *plugin, int lock);
267 void delete_plugin(PluginServer *plugin);
268 // Update plugins with configuration changes.
269 // Called by TrackCanvas::cursor_motion_event.
270 void update_plugin_guis(int do_keyframe_guis = 1);
271 void update_plugin_states();
272 void update_plugin_titles();
273 // Called by Attachmentpoint during playback.
274 // Searches for matching plugin and renders data in it.
275 void render_plugin_gui(void *data, Plugin *plugin);
276 void render_plugin_gui(void *data, int size, Plugin *plugin);
278 // Called from PluginVClient::process_buffer
279 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
281 int plugin_gui_open(Plugin *plugin);
283 void show_keyframe_gui(Plugin *plugin);
284 void hide_keyframe_guis();
285 void hide_keyframe_gui(Plugin *plugin);
286 void update_keyframe_guis();
289 // ============================= editing commands ========================
291 // Map each recordable audio track to the desired pattern
292 void map_audio(int pattern);
293 void remap_audio(int pattern);
299 void add_audio_track_entry(int above, Track *dst);
300 int add_audio_track(int above, Track *dst);
301 void add_clip_to_edl(EDL *edl);
302 void add_video_track_entry(Track *dst = 0);
303 int add_video_track(int above, Track *dst);
304 void add_subttl_track_entry(Track *dst = 0);
305 int add_subttl_track(int above, Track *dst);
308 void asset_to_size();
309 void asset_to_rate();
310 // Entry point for clear operations.
312 // Clears active region in EDL.
313 // If clear_handle, edit boundaries are cleared if the range is 0.
314 // Called by paste, record, menueffects, render, and CWindow drop.
315 void clear(int clear_handle);
317 int clear_labels(double start, double end);
318 void concatenate_tracks();
320 int copy(double start, double end);
323 // Calculate aspect ratio from pixel counts
324 static int create_aspect_ratio(float &w, float &h, int width, int height);
325 // Calculate defaults path
326 static void create_defaults_path(char *string, const char *config_file);
328 void delete_folder(char *folder);
329 void delete_inpoint();
330 void delete_outpoint();
333 void delete_track(Track *track);
334 void delete_tracks();
335 int feather_edits(int64_t feather_samples, int audio, int video);
336 int64_t get_feather(int audio, int video);
337 float get_aspect_ratio();
338 void insert(double position,
343 EDL *parent_edl /* = 0 */);
345 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
346 // into pluginset_highlighted.
347 void insert_effects_canvas(double start,
350 // CWindow calls this to insert multiple effects from
351 // the drag_pluginservers array.
352 void insert_effects_cwindow(Track *dest_track);
354 // Attach new effect to all recordable tracks
355 // single_standalone - attach 1 standalone on the first track and share it with
357 void insert_effect(char *title,
358 SharedLocation *shared_location,
361 int single_standalone);
363 // This is called multiple times by the above functions.
364 // It can't sync parameters.
365 void insert_effect(char *title,
366 SharedLocation *shared_location,
368 PluginSet *plugin_set,
373 void match_output_size(Track *track);
374 // Move edit to new position
375 void move_edits(ArrayList<Edit*> *edits,
378 int behaviour); // behaviour: 0 - old style (cut and insert elswhere), 1- new style - (clear and overwrite elsewere)
379 // Move effect to position
380 void move_effect(Plugin *plugin,
383 void move_effect(Plugin *plugin,
384 PluginSet *plugin_set,
386 void move_plugins_up(PluginSet *plugin_set);
387 void move_plugins_down(PluginSet *plugin_set);
388 void move_track_down(Track *track);
389 void move_tracks_down();
390 void move_track_up(Track *track);
391 void move_tracks_up();
392 void mute_selection();
393 void new_folder(const char *new_folder);
394 void overwrite(EDL *source);
395 // For clipboard commands
397 // For splice and overwrite
398 int paste(double start,
404 int paste_output(int64_t startproject,
406 int64_t startsource_sample,
407 int64_t endsource_sample,
408 int64_t startsource_frame,
409 int64_t endsource_frame,
411 RecordLabels *new_labels);
412 void paste_silence();
414 // Detach single transition
415 void detach_transition(Transition *transition);
416 // Detach all transitions in selection
417 void detach_transitions();
418 // Attach dragged transition
419 void paste_transition();
420 // Attach transition to all edits in selection
421 void paste_transitions(int track_type, char *title);
422 // Attach transition dragged onto CWindow
423 void paste_transition_cwindow(Track *dest_track);
424 // Attach default transition to single edit
425 void paste_audio_transition();
426 void paste_video_transition();
427 void shuffle_edits();
428 void reverse_edits();
430 void set_edit_length(double length);
431 // Set length of single transition
432 void set_transition_length(Transition *transition, double length);
433 // Set length in seconds of all transitions in active range
434 void set_transition_length(double length);
436 void remove_indexfile(Indexable *indexable);
437 void rebuild_indices();
438 // Asset removal from caches
440 void remove_asset_from_caches(Asset *asset);
441 void remove_assets_from_project(int push_undo /* = 0 */,
443 ArrayList<Indexable*> *drag_assets /* mwindow->session->drag_assets */,
444 ArrayList<EDL*> *drag_clips /* mwindow->session->drag_clips */);
445 void remove_assets_from_disk();
446 void resize_track(Track *track, int w, int h);
448 void set_automation_mode(int mode);
449 void set_keyframe_type(int mode);
450 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
451 void set_labels_follow_edits(int value);
453 // Update the editing mode
454 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
455 void toggle_editing_mode();
456 void set_inpoint(int is_mwindow);
457 void set_outpoint(int is_mwindow);
458 void splice(EDL *source);
459 void toggle_loop_playback();
460 void trim_selection();
461 // Synchronize EDL settings with all playback engines depending on current
462 // operation. Doesn't redraw anything.
463 void sync_parameters(int change_type = CHANGE_PARAMS);
465 int toggle_label(int is_mwindow);
466 void undo_entry(BC_WindowBase *calling_window_gui);
467 void redo_entry(BC_WindowBase *calling_window_gui);
470 int cut_automation();
471 int copy_automation();
472 int paste_automation();
473 void clear_automation();
474 int cut_default_keyframe();
475 int copy_default_keyframe();
476 // Use paste_automation to paste the default keyframe in other position.
477 // Use paste_default_keyframe to replace the default keyframe with whatever is
479 int paste_default_keyframe();
480 int clear_default_keyframe();
482 int modify_edithandles();
483 int modify_pluginhandles();
484 void finish_modify_handles();
486 void dump_plugins(FILE *fp=stdout);
487 void dump_edl(FILE *fp=stdout);
488 void dump_undo(FILE *fp=stdout);
489 void dump_exe(FILE *fp=stdout);
490 static void trap_hook(FILE *fp, void *vp);
492 void reset_android_remote();
494 // Send new EDL to caches
496 int optimize_assets(); // delete unused assets from the cache and assets
498 void select_point(double position);
499 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
502 Playback3D *playback_3d;
503 SplashGUI *splash_window;
509 // CICaches for drawing timeline only
510 CICache *audio_cache, *video_cache;
511 // Frame cache for drawing timeline only.
512 // Cache drawing doesn't wait for file decoding.
513 FrameCache *frame_cache;
514 WaveCache *wave_cache;
515 Preferences *preferences;
516 PreferencesThread *preferences_thread;
517 MainSession *session;
519 MainIndexes *mainindexes;
520 MainProgress *mainprogress;
522 const char *default_standard;
523 static Commercials *commercials;
524 int commercial_active;
525 int has_commercials();
528 ArrayList<ColormodelItem*> colormodels;
529 ArrayList<InterlacemodeItem*> interlace_project_modes;
530 ArrayList<InterlacemodeItem*> interlace_asset_modes;
531 ArrayList<InterlacefixmethodItem*> interlace_asset_fixmethods;
536 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
537 int select_asset(int vtrack, int delete_tracks);
539 // Channel DB for playback only. Record channel DB's are in record.C
540 ChannelDB *channeldb_buz;
541 ChannelDB *channeldb_v4l2jpeg;
543 // ====================================== plugins ==============================
545 // Contains file descriptors for all the dlopens
546 static ArrayList<PluginServer*> *plugindb;
547 // Currently visible plugins
548 int64_t plugin_visibility;
549 ArrayList<PluginServer*> *plugin_guis;
550 // GUI Plugins to delete
551 ArrayList<PluginServer*> *dead_plugins;
553 ArrayList<KeyFrameThread*> *keyframe_threads;
555 // Adjust sample position to line up with frames.
556 int fix_timing(int64_t &samples_out,
561 CreateBD_Thread *create_bd;
562 CreateDVD_Thread *create_dvd;
563 BatchRenderThread *batch_render;
566 ExportEDL *exportedl;
576 Mutex *vwindows_lock;
577 ArrayList<VWindow*> vwindows;
586 void show_warning(int *do_warning, const char *text);
588 LevelWindow *lwindow;
589 // Lock during creation and destruction of GUI
590 Mutex *plugin_gui_lock;
591 Mutex *dead_plugin_lock;
592 Mutex *keyframe_gui_lock;
593 // Lock during creation and destruction of brender so playback doesn't use it.
596 // Initialize shared memory
599 // Initialize channel DB's for playback
600 void init_channeldb();
602 void init_exportedl();
603 // These three happen synchronously with each other
604 // Make sure this is called after synchronizing EDL's.
606 // Restart brender after testing its existence
607 void restart_brender();
608 // Stops brender after testing its existence
610 // This one happens asynchronously of the others. Used by playback to
611 // see what frame is background rendered.
612 int brender_available(int position);
613 void set_brender_start();
614 int put_commercial();
615 void activate_commercial() { commercial_active = 1; }
616 void commit_commercial();
617 void undo_commercial();
618 void cut_commercials();
619 int paste_subtitle_text(char *text, double start, double end);
623 static void init_defaults(BC_Hash* &defaults, char *config_path);
624 const char *default_std();
625 void fill_preset_defaults(const char *preset, EDLSession *session);
626 const char *get_preset_name(int index);
630 void init_tipwindow();
631 // Used by MWindow and RenderFarmClient
632 static void get_plugin_path(char *path, const char *plug_dir, const char *fs_path);
633 static int init_plugins(MWindow *mwindow, Preferences *preferences);
634 static int init_ladspa_plugins(MWindow *mwindow, Preferences *preferences);
635 static int check_plugin_index(ArrayList<PluginServer*> &plugins,
636 const char *plug_dir, const char *plug_path);
637 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
638 FILE *fp, const char *plugin_dir);
639 static int init_ladspa_index(MWindow *mwindow, Preferences *preferences,
640 const char *index_path, const char *plugin_dir);
641 static void scan_plugin_index(MWindow *mwindow, Preferences *preferences,
642 FILE *fp, const char *plug_dir, const char *plug_path, int &idx);
643 static void init_ffmpeg();
644 static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
645 static int load_plugin_index(MWindow *mwindow, const char *index_path,
646 const char *plugin_dir);
647 static PluginServer* new_ffmpeg_server(MWindow *mwindow, const char *name);
648 void init_preferences();
651 void init_compositor();
652 void init_levelwindow();
653 // Called when creating a new viewer to view footage
654 VWindow* get_viewer(int start_it, int idx=-1);
660 void init_playbackcursor();
661 void init_commercials();
662 static void add_plugins(ArrayList<PluginServer*> &plugins);
663 static void delete_plugins();
665 void clean_indexes();
666 // TimeBomb timebomb;
667 SigHandler *sighandler;