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 "filesystem.inc"
48 #include "filexml.inc"
49 #include "framecache.inc"
50 #include "gwindow.inc"
51 #include "indexable.inc"
52 #include "keyframegui.inc"
53 #include "levelwindow.inc"
54 #include "loadmode.inc"
55 #include "mainerror.inc"
56 #include "mainindexes.inc"
57 #include "mainprogress.inc"
58 #include "mainsession.inc"
59 #include "mainundo.inc"
60 #include "maxchannels.h"
62 #include "mwindow.inc"
63 #include "mwindowgui.inc"
65 #include "patchbay.inc"
66 #include "playback3d.inc"
67 #include "playbackengine.inc"
69 #include "pluginfclient.inc"
70 #include "pluginserver.inc"
71 #include "pluginset.inc"
72 #include "preferences.inc"
73 #include "preferencesthread.inc"
75 #include "recordlabel.inc"
77 #include "sharedlocation.inc"
78 #include "sighandler.inc"
79 #include "splashgui.inc"
82 #include "threadloader.inc"
83 #include "timebar.inc"
85 #include "tipwindow.inc"
87 #include "tracking.inc"
89 #include "transition.inc"
90 #include "transportque.inc"
91 #include "videowindow.inc"
92 #include "vwindow.inc"
93 #include "wwindow.inc"
94 #include "wavecache.inc"
96 // All entry points for commands except for window locking should be here.
97 // This allows scriptability.
99 class MWindow : public Thread
105 // ======================================== initialization commands
106 void create_objects(int want_gui,
114 int run_script(FileXML *script);
116 int delete_project(int flash = 1);
117 void quit(int unlock);
118 int restart() { return restart_status; }
122 int set_filename(const char *filename);
123 // Total vertical pixels in timeline
124 int get_tracks_height();
125 // Total horizontal pixels in timeline
126 int get_tracks_width();
133 int tile_windows(int window_config);
134 char *get_cwindow_display();
135 // void set_titles(int value);
136 void set_screens(int value);
137 int asset_to_edl(EDL *new_edl,
139 RecordLabels *labels = 0);
140 // Convert nested_edl to a nested EDL in new_edl
141 // suitable for pasting in paste_edls
142 int edl_to_nested(EDL *new_edl,
145 // Entry point to insert assets and insert edls. Called by TrackCanvas
146 // and AssetPopup when assets are dragged in from AWindow.
147 // Takes the drag vectors from MainSession and
148 // pastes either assets or clips depending on which is full.
149 // Returns 1 if the vectors were full
150 int paste_assets(double position, Track *dest_track);
152 // Insert the assets at a point in the EDL. Called by menueffects,
153 // render, and CWindow drop but recording calls paste_edls directly for
155 void load_assets(ArrayList<Indexable*> *new_assets,
158 Track *first_track /* = 0 */,
159 RecordLabels *labels /* = 0 */,
163 int paste_edls(ArrayList<EDL*> *new_edls,
165 Track *first_track /* = 0 */,
166 double current_position /* = -1 */,
170 // Reset everything for a load
171 void update_project(int load_mode);
172 // Fit selected time to horizontal display range
173 void fit_selection();
174 // Fit selected autos to the vertical display range
178 void zoom_autos(float min, float max);
179 // move the window to include the cursor
181 // Search plugindb and put results in argument
182 static void search_plugindb(int do_audio,
187 ArrayList<PluginServer*> &results);
188 // Find the plugin whose title matches title and return it
189 static PluginServer* scan_plugindb(char *title,
191 static int plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins);
192 static int plugin_exists(char *plugin_path);
193 void dump_plugindb(FILE *fp);
194 void stop_playback(int wait=0);
199 int load_filenames(ArrayList<char*> *filenames,
200 int load_mode = LOADMODE_REPLACE,
201 // Cause the project filename on the top of the window to be updated.
202 // Not wanted for loading backups.
203 int update_filename = 1);
205 // Print out plugins which are referenced in the EDL but not loaded.
206 void test_plugins(EDL *new_edl, char *path);
208 int interrupt_indexes(); // Stop index building
210 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
212 // =========================================== movement
214 void next_time_format();
215 void prev_time_format();
216 void time_format_common();
217 int reposition_timebar(int new_pixel, int new_height);
219 int zoom_in_sample();
220 int zoom_sample(int64_t zoom_sample);
221 void zoom_amp(int64_t zoom_amp);
222 void zoom_track(int64_t zoom_track);
224 int move_left(int64_t distance = 0);
225 int move_right(int64_t distance = 0);
226 void move_up(int64_t distance = 0);
227 void move_down(int64_t distance = 0);
230 // shift_down must be passed by the caller because different windows call
232 int next_label(int shift_down);
233 int prev_label(int shift_down);
234 // seek to edit handles
235 int next_edit_handle(int shift_down);
236 int prev_edit_handle(int shift_down);
237 // offset is pixels to add to track_start
238 void trackmovement(int offset, int pane_number);
239 // view_start is pixels
240 int samplemovement(int64_t view_start, int pane_number);
244 int goto_position(double position);
252 void update_plugins();
253 // Call after every edit operation
256 void show_plugin(Plugin *plugin);
257 void hide_plugin(Plugin *plugin, int lock);
259 void delete_plugin(PluginServer *plugin);
260 // Update plugins with configuration changes.
261 // Called by TrackCanvas::cursor_motion_event.
262 void update_plugin_guis(int do_keyframe_guis = 1);
263 void update_plugin_states();
264 void update_plugin_titles();
265 // Called by Attachmentpoint during playback.
266 // Searches for matching plugin and renders data in it.
267 void render_plugin_gui(void *data, Plugin *plugin);
268 void render_plugin_gui(void *data, int size, Plugin *plugin);
270 // Called from PluginVClient::process_buffer
271 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
273 int plugin_gui_open(Plugin *plugin);
275 void show_keyframe_gui(Plugin *plugin);
276 void hide_keyframe_guis();
277 void hide_keyframe_gui(Plugin *plugin);
278 void update_keyframe_guis();
281 // ============================= editing commands ========================
283 // Map each recordable audio track to the desired pattern
284 void map_audio(int pattern);
285 void remap_audio(int pattern);
291 void add_audio_track_entry(int above, Track *dst);
292 int add_audio_track(int above, Track *dst);
293 void add_clip_to_edl(EDL *edl);
294 void add_video_track_entry(Track *dst = 0);
295 int add_video_track(int above, Track *dst);
296 void add_subttl_track_entry(Track *dst = 0);
297 int add_subttl_track(int above, Track *dst);
300 void asset_to_size();
301 void asset_to_rate();
302 // Entry point for clear operations.
304 // Clears active region in EDL.
305 // If clear_handle, edit boundaries are cleared if the range is 0.
306 // Called by paste, record, menueffects, render, and CWindow drop.
307 void clear(int clear_handle);
309 int clear_labels(double start, double end);
310 void concatenate_tracks();
312 int copy(double start, double end);
315 // Calculate aspect ratio from pixel counts
316 static int create_aspect_ratio(float &w, float &h, int width, int height);
317 // Calculate defaults path
318 static void create_defaults_path(char *string, const char *config_file);
320 void delete_folder(char *folder);
321 void delete_inpoint();
322 void delete_outpoint();
325 void delete_track(Track *track);
326 void delete_tracks();
327 int feather_edits(int64_t feather_samples, int audio, int video);
328 int64_t get_feather(int audio, int video);
329 float get_aspect_ratio();
330 void insert(double position,
335 EDL *parent_edl /* = 0 */);
337 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
338 // into pluginset_highlighted.
339 void insert_effects_canvas(double start,
342 // CWindow calls this to insert multiple effects from
343 // the drag_pluginservers array.
344 void insert_effects_cwindow(Track *dest_track);
346 // Attach new effect to all recordable tracks
347 // single_standalone - attach 1 standalone on the first track and share it with
349 void insert_effect(char *title,
350 SharedLocation *shared_location,
353 int single_standalone);
355 // This is called multiple times by the above functions.
356 // It can't sync parameters.
357 void insert_effect(char *title,
358 SharedLocation *shared_location,
360 PluginSet *plugin_set,
365 void match_output_size(Track *track);
366 // Move edit to new position
367 void move_edits(ArrayList<Edit*> *edits,
370 // Move effect to position
371 void move_effect(Plugin *plugin,
372 PluginSet *plugin_set,
375 void move_plugins_up(PluginSet *plugin_set);
376 void move_plugins_down(PluginSet *plugin_set);
377 void move_track_down(Track *track);
378 void move_tracks_down();
379 void move_track_up(Track *track);
380 void move_tracks_up();
381 void mute_selection();
382 void new_folder(const char *new_folder);
383 void overwrite(EDL *source);
384 // For clipboard commands
386 // For splice and overwrite
387 int paste(double start,
393 int paste_output(int64_t startproject,
395 int64_t startsource_sample,
396 int64_t endsource_sample,
397 int64_t startsource_frame,
398 int64_t endsource_frame,
400 RecordLabels *new_labels);
401 void paste_silence();
403 // Detach single transition
404 void detach_transition(Transition *transition);
405 // Detach all transitions in selection
406 void detach_transitions();
407 // Attach dragged transition
408 void paste_transition();
409 // Attach transition to all edits in selection
410 void paste_transitions(int track_type, char *title);
411 // Attach transition dragged onto CWindow
412 void paste_transition_cwindow(Track *dest_track);
413 // Attach default transition to single edit
414 void paste_audio_transition();
415 void paste_video_transition();
416 void shuffle_edits();
417 void reverse_edits();
419 void set_edit_length(double length);
420 // Set length of single transition
421 void set_transition_length(Transition *transition, double length);
422 // Set length in seconds of all transitions in active range
423 void set_transition_length(double length);
425 void remove_indexfile(Indexable *indexable);
426 void rebuild_indices();
427 // Asset removal from caches
429 void remove_asset_from_caches(Asset *asset);
430 void remove_assets_from_project(int push_undo /* = 0 */,
432 ArrayList<Indexable*> *drag_assets /* mwindow->session->drag_assets */,
433 ArrayList<EDL*> *drag_clips /* mwindow->session->drag_clips */);
434 void remove_assets_from_disk();
435 void resize_track(Track *track, int w, int h);
437 void set_automation_mode(int mode);
438 void set_keyframe_type(int mode);
439 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
440 // Update the editing mode
441 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
442 void set_inpoint(int is_mwindow);
443 void set_outpoint(int is_mwindow);
444 void splice(EDL *source);
445 void toggle_loop_playback();
446 void trim_selection();
447 // Synchronize EDL settings with all playback engines depending on current
448 // operation. Doesn't redraw anything.
449 void sync_parameters(int change_type = CHANGE_PARAMS);
451 int toggle_label(int is_mwindow);
452 void undo_entry(BC_WindowBase *calling_window_gui);
453 void redo_entry(BC_WindowBase *calling_window_gui);
456 int cut_automation();
457 int copy_automation();
458 int paste_automation();
459 void clear_automation();
460 int cut_default_keyframe();
461 int copy_default_keyframe();
462 // Use paste_automation to paste the default keyframe in other position.
463 // Use paste_default_keyframe to replace the default keyframe with whatever is
465 int paste_default_keyframe();
466 int clear_default_keyframe();
468 int modify_edithandles();
469 int modify_pluginhandles();
470 void finish_modify_handles();
472 void dump_plugins(FILE *fp=stdout);
473 void dump_edl(FILE *fp=stdout);
474 void dump_undo(FILE *fp=stdout);
475 void dump_exe(FILE *fp=stdout);
476 static void trap_hook(FILE *fp, void *vp);
478 void reset_android_remote();
480 // Send new EDL to caches
482 int optimize_assets(); // delete unused assets from the cache and assets
484 void select_point(double position);
485 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
488 Playback3D *playback_3d;
489 SplashGUI *splash_window;
495 // CICaches for drawing timeline only
496 CICache *audio_cache, *video_cache;
497 // Frame cache for drawing timeline only.
498 // Cache drawing doesn't wait for file decoding.
499 FrameCache *frame_cache;
500 WaveCache *wave_cache;
501 Preferences *preferences;
502 PreferencesThread *preferences_thread;
503 MainSession *session;
505 MainIndexes *mainindexes;
506 MainProgress *mainprogress;
508 static Commercials *commercials;
509 int commercial_active;
510 int has_commercials();
513 ArrayList<ColormodelItem*> colormodels;
518 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
519 int select_asset(int vtrack, int delete_tracks);
521 // Channel DB for playback only. Record channel DB's are in record.C
522 ChannelDB *channeldb_buz;
523 ChannelDB *channeldb_v4l2jpeg;
525 // ====================================== plugins ==============================
527 // Contains file descriptors for all the dlopens
528 static ArrayList<PluginServer*> *plugindb;
529 // Currently visible plugins
530 int64_t plugin_visibility;
531 ArrayList<PluginServer*> *plugin_guis;
532 // GUI Plugins to delete
533 ArrayList<PluginServer*> *dead_plugins;
535 ArrayList<KeyFrameThread*> *keyframe_threads;
537 // Adjust sample position to line up with frames.
538 int fix_timing(int64_t &samples_out,
543 CreateBD_Thread *create_bd;
544 CreateDVD_Thread *create_dvd;
545 BatchRenderThread *batch_render;
554 Mutex *vwindows_lock;
555 ArrayList<VWindow*> vwindows;
564 void show_warning(int *do_warning, const char *text);
566 LevelWindow *lwindow;
567 // Lock during creation and destruction of GUI
568 Mutex *plugin_gui_lock;
569 Mutex *dead_plugin_lock;
570 Mutex *keyframe_gui_lock;
571 // Lock during creation and destruction of brender so playback doesn't use it.
574 // Initialize shared memory
577 // Initialize channel DB's for playback
578 void init_channeldb();
580 // These three happen synchronously with each other
581 // Make sure this is called after synchronizing EDL's.
583 // Restart brender after testing its existence
584 void restart_brender();
585 // Stops brender after testing its existence
587 // This one happens asynchronously of the others. Used by playback to
588 // see what frame is background rendered.
589 int brender_available(int position);
590 void set_brender_start();
591 int put_commercial();
592 void activate_commercial() { commercial_active = 1; }
593 void commit_commercial();
594 void undo_commercial();
595 void cut_commercials();
596 int paste_subtitle_text(char *text, double start, double end);
600 static void init_defaults(BC_Hash* &defaults, char *config_path);
604 void init_tipwindow();
605 // Used by MWindow and RenderFarmClient
606 static void get_plugin_path(char *path, const char *plug_dir, const char *fs_path);
607 static int init_plugins(MWindow *mwindow, Preferences *preferences);
608 static int init_ladspa_plugins(MWindow *mwindow, Preferences *preferences);
609 static int check_plugin_index(ArrayList<PluginServer*> &plugins,
610 const char *plug_dir, const char *plug_path);
611 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
612 FILE *fp, const char *plugin_dir);
613 static int init_ladspa_index(MWindow *mwindow, Preferences *preferences,
614 const char *index_path, const char *plugin_dir);
615 static void scan_plugin_index(MWindow *mwindow, Preferences *preferences,
616 FILE *fp, const char *plug_dir, const char *plug_path, int &idx);
617 static void init_ffmpeg();
618 static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
619 static int load_plugin_index(MWindow *mwindow, const char *index_path,
620 const char *plugin_dir);
621 static PluginServer* new_ffmpeg_server(MWindow *mwindow, const char *name);
622 void init_preferences();
625 void init_compositor();
626 void init_levelwindow();
627 // Called when creating a new viewer to view footage
628 VWindow* get_viewer(int start_it, int idx=-1);
634 void init_playbackcursor();
635 void init_commercials();
636 static void add_plugins(ArrayList<PluginServer*> &plugins);
637 static void delete_plugins();
639 void clean_indexes();
640 // TimeBomb timebomb;
641 SigHandler *sighandler;