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 "wwindow.inc"
99 #include "wavecache.inc"
101 #define FONT_SEARCHPATH "fonts"
103 // All entry points for commands except for window locking should be here.
104 // This allows scriptability.
106 class MWindow : public Thread
112 // ======================================== initialization commands
113 void create_objects(int want_gui,
121 int run_script(FileXML *script);
123 int delete_project(int flash = 1);
125 int restart() { return restart_status; }
129 int set_filename(const char *filename);
130 // Total vertical pixels in timeline
131 int get_tracks_height();
132 // Total horizontal pixels in timeline
133 int get_tracks_width();
141 int tile_windows(int window_config);
142 char *get_cwindow_display();
143 // void set_titles(int value);
144 void set_screens(int value);
145 int asset_to_edl(EDL *new_edl,
147 RecordLabels *labels = 0);
148 // Convert nested_edl to a nested EDL in new_edl
149 // suitable for pasting in paste_edls
150 int edl_to_nested(EDL *new_edl,
153 // Entry point to insert assets and insert edls. Called by TrackCanvas
154 // and AssetPopup when assets are dragged in from AWindow.
155 // Takes the drag vectors from MainSession and
156 // pastes either assets or clips depending on which is full.
157 // Returns 1 if the vectors were full
158 int paste_assets(double position, Track *dest_track, int overwrite);
160 // Insert the assets at a point in the EDL. Called by menueffects,
161 // render, and CWindow drop but recording calls paste_edls directly for
163 void load_assets(ArrayList<Indexable*> *new_assets,
166 Track *first_track /* = 0 */,
167 RecordLabels *labels /* = 0 */,
172 int paste_edls(ArrayList<EDL*> *new_edls,
174 Track *first_track /* = 0 */,
175 double current_position /* = -1 */,
180 // Reset everything for a load
181 void update_project(int load_mode);
182 // Fit selected time to horizontal display range
183 void fit_selection();
184 // Fit selected autos to the vertical display range
185 void fit_autos(int doall);
186 void change_currentautorange(int autogrouptype, int increment, int changemax);
187 void expand_autos(int changeall, int domin, int domax);
188 void shrink_autos(int changeall, int domin, int domax);
189 // move the window to include the cursor
191 // Search plugindb and put results in argument
192 static void search_plugindb(int do_audio,
197 ArrayList<PluginServer*> &results);
198 // Find the plugin whose title matches title and return it
199 static PluginServer* scan_plugindb(char *title,
201 static int plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins);
202 static int plugin_exists(char *plugin_path);
203 void dump_plugindb(FILE *fp);
204 void stop_playback(int wait=0);
209 int load_filenames(ArrayList<char*> *filenames,
210 int load_mode = LOADMODE_REPLACE,
211 // Cause the project filename on the top of the window to be updated.
212 // Not wanted for loading backups.
213 int update_filename = 1);
216 // Print out plugins which are referenced in the EDL but not loaded.
217 void test_plugins(EDL *new_edl, char *path);
219 int interrupt_indexes(); // Stop index building
221 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
223 // =========================================== movement
225 void next_time_format();
226 void prev_time_format();
227 void time_format_common();
228 int reposition_timebar(int new_pixel, int new_height);
230 int zoom_in_sample();
231 int zoom_sample(int64_t zoom_sample);
232 void zoom_autos(float min, float max);
233 void zoom_amp(int64_t zoom_amp);
234 void zoom_track(int64_t zoom_track);
236 int move_left(int64_t distance = 0);
237 int move_right(int64_t distance = 0);
238 void move_up(int64_t distance = 0);
239 void move_down(int64_t distance = 0);
242 // shift_down must be passed by the caller because different windows call
244 int next_label(int shift_down);
245 int prev_label(int shift_down);
246 // seek to edit handles
247 int next_edit_handle(int shift_down);
248 int prev_edit_handle(int shift_down);
249 // offset is pixels to add to track_start
250 void trackmovement(int offset, int pane_number);
251 // view_start is pixels
252 int samplemovement(int64_t view_start, int pane_number);
256 int goto_position(double position);
264 void update_plugins();
265 // Call after every edit operation
268 void show_plugin(Plugin *plugin);
269 void hide_plugin(Plugin *plugin, int lock);
271 void delete_plugin(PluginServer *plugin);
272 // Update plugins with configuration changes.
273 // Called by TrackCanvas::cursor_motion_event.
274 void update_plugin_guis(int do_keyframe_guis = 1);
275 void update_plugin_states();
276 void update_plugin_titles();
277 // Called by Attachmentpoint during playback.
278 // Searches for matching plugin and renders data in it.
279 void render_plugin_gui(void *data, Plugin *plugin);
280 void render_plugin_gui(void *data, int size, Plugin *plugin);
282 // Called from PluginVClient::process_buffer
283 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
285 int plugin_gui_open(Plugin *plugin);
287 void show_keyframe_gui(Plugin *plugin);
288 void hide_keyframe_guis();
289 void hide_keyframe_gui(Plugin *plugin);
290 void update_keyframe_guis();
293 // ============================= editing commands ========================
295 // Map each recordable audio track to the desired pattern
296 void map_audio(int pattern);
297 void remap_audio(int pattern);
303 void add_audio_track_entry(int above, Track *dst);
304 int add_audio_track(int above, Track *dst);
305 void add_clip_to_edl(EDL *edl);
306 void add_video_track_entry(Track *dst = 0);
307 int add_video_track(int above, Track *dst);
308 void add_subttl_track_entry(Track *dst = 0);
309 int add_subttl_track(int above, Track *dst);
312 void asset_to_size();
313 void asset_to_rate();
314 // Entry point for clear operations.
316 // Clears active region in EDL.
317 // If clear_handle, edit boundaries are cleared if the range is 0.
318 // Called by paste, record, menueffects, render, and CWindow drop.
319 void clear(int clear_handle);
321 int clear_labels(double start, double end);
322 void concatenate_tracks();
324 int copy(double start, double end);
327 // Calculate aspect ratio from pixel counts
328 static int create_aspect_ratio(float &w, float &h, int width, int height);
329 // Calculate defaults path
330 static void create_defaults_path(char *string, const char *config_file);
332 void delete_folder(char *folder);
333 void delete_inpoint();
334 void delete_outpoint();
337 void delete_track(Track *track);
338 void delete_tracks();
339 int feather_edits(int64_t feather_samples, int audio, int video);
340 int64_t get_feather(int audio, int video);
341 float get_aspect_ratio();
342 void insert(double position,
347 EDL *parent_edl /* = 0 */);
349 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
350 // into pluginset_highlighted.
351 void insert_effects_canvas(double start,
354 // CWindow calls this to insert multiple effects from
355 // the drag_pluginservers array.
356 void insert_effects_cwindow(Track *dest_track);
358 // Attach new effect to all recordable tracks
359 // single_standalone - attach 1 standalone on the first track and share it with
361 void insert_effect(char *title,
362 SharedLocation *shared_location,
365 int single_standalone);
367 // This is called multiple times by the above functions.
368 // It can't sync parameters.
369 void insert_effect(char *title,
370 SharedLocation *shared_location,
372 PluginSet *plugin_set,
377 void match_output_size(Track *track);
378 // Move edit to new position
379 void move_edits(ArrayList<Edit*> *edits,
382 int behaviour); // behaviour: 0 - old style (cut and insert elswhere), 1- new style - (clear and overwrite elsewere)
383 // Move effect to position
384 void move_effect(Plugin *plugin,
387 void move_effect(Plugin *plugin,
388 PluginSet *plugin_set,
390 void move_plugins_up(PluginSet *plugin_set);
391 void move_plugins_down(PluginSet *plugin_set);
392 void move_track_down(Track *track);
393 void move_tracks_down();
394 void move_track_up(Track *track);
395 void move_tracks_up();
396 void mute_selection();
397 void new_folder(const char *new_folder);
398 void overwrite(EDL *source);
399 // For clipboard commands
401 // For splice and overwrite
402 int paste(double start,
408 int paste_output(int64_t startproject,
410 int64_t startsource_sample,
411 int64_t endsource_sample,
412 int64_t startsource_frame,
413 int64_t endsource_frame,
415 RecordLabels *new_labels);
416 void paste_silence();
418 // Detach single transition
419 void detach_transition(Transition *transition);
420 // Detach all transitions in selection
421 void detach_transitions();
422 // Attach dragged transition
423 void paste_transition();
424 // Attach transition to all edits in selection
425 void paste_transitions(int track_type, char *title);
426 // Attach transition dragged onto CWindow
427 void paste_transition_cwindow(Track *dest_track);
428 // Attach default transition to single edit
429 void paste_audio_transition();
430 void paste_video_transition();
431 void shuffle_edits();
432 void reverse_edits();
434 void set_edit_length(double length);
435 // Set length of single transition
436 void set_transition_length(Transition *transition, double length);
437 // Set length in seconds of all transitions in active range
438 void set_transition_length(double length);
440 void remove_indexfile(Indexable *indexable);
441 void rebuild_indices();
442 // Asset removal from caches
444 void remove_asset_from_caches(Asset *asset);
445 void remove_assets_from_project(int push_undo /* = 0 */,
447 ArrayList<Indexable*> *drag_assets /* mwindow->session->drag_assets */,
448 ArrayList<EDL*> *drag_clips /* mwindow->session->drag_clips */);
449 void remove_assets_from_disk();
450 void resize_track(Track *track, int w, int h);
452 void set_automation_mode(int mode);
453 void set_keyframe_type(int mode);
454 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
455 void set_auto_visibility(Autos *autos, int value);
456 void set_labels_follow_edits(int value);
458 // Update the editing mode
459 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
460 void toggle_editing_mode();
461 void set_inpoint(int is_mwindow);
462 void set_outpoint(int is_mwindow);
463 void splice(EDL *source);
464 void toggle_loop_playback();
465 void trim_selection();
466 // Synchronize EDL settings with all playback engines depending on current
467 // operation. Doesn't redraw anything.
468 void sync_parameters(int change_type = CHANGE_PARAMS);
470 int toggle_label(int is_mwindow);
471 void undo_entry(BC_WindowBase *calling_window_gui);
472 void redo_entry(BC_WindowBase *calling_window_gui);
475 int cut_automation();
476 int copy_automation();
477 int paste_automation();
478 void clear_automation();
479 int cut_default_keyframe();
480 int copy_default_keyframe();
481 // Use paste_automation to paste the default keyframe in other position.
482 // Use paste_default_keyframe to replace the default keyframe with whatever is
484 int paste_default_keyframe();
485 int clear_default_keyframe();
487 FloatAuto* get_float_auto(PatchGUI *patch,int idx);
488 IntAuto* get_int_auto(PatchGUI *patch,int idx);
489 PanAuto* get_pan_auto(PatchGUI *patch);
491 int modify_edithandles();
492 int modify_pluginhandles();
493 void finish_modify_handles();
495 void dump_plugins(FILE *fp=stdout);
496 void dump_edl(FILE *fp=stdout);
497 void dump_undo(FILE *fp=stdout);
498 void dump_exe(FILE *fp=stdout);
499 static void trap_hook(FILE *fp, void *vp);
501 void reset_android_remote();
503 // Send new EDL to caches
505 int optimize_assets(); // delete unused assets from the cache and assets
507 void select_point(double position);
508 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
511 Playback3D *playback_3d;
512 SplashGUI *splash_window;
518 // CICaches for drawing timeline only
519 CICache *audio_cache, *video_cache;
520 // Frame cache for drawing timeline only.
521 // Cache drawing doesn't wait for file decoding.
522 FrameCache *frame_cache;
523 WaveCache *wave_cache;
524 Preferences *preferences;
525 PreferencesThread *preferences_thread;
526 MainSession *session;
528 MainIndexes *mainindexes;
529 MainProgress *mainprogress;
531 const char *default_standard;
532 static Commercials *commercials;
533 int commercial_active;
534 int has_commercials();
537 ArrayList<ColormodelItem*> colormodels;
538 ArrayList<InterlacemodeItem*> interlace_project_modes;
539 ArrayList<InterlacemodeItem*> interlace_asset_modes;
540 ArrayList<InterlacefixmethodItem*> interlace_asset_fixmethods;
545 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
546 int select_asset(int vtrack, int delete_tracks);
548 // Channel DB for playback only. Record channel DB's are in record.C
549 ChannelDB *channeldb_buz;
550 ChannelDB *channeldb_v4l2jpeg;
552 // ====================================== plugins ==============================
554 // Contains file descriptors for all the dlopens
555 static ArrayList<PluginServer*> *plugindb;
556 // Currently visible plugins
557 int64_t plugin_visibility;
558 ArrayList<PluginServer*> *plugin_guis;
559 // GUI Plugins to delete
560 ArrayList<PluginServer*> *dead_plugins;
562 ArrayList<KeyFrameThread*> *keyframe_threads;
564 // Adjust sample position to line up with frames.
565 int fix_timing(int64_t &samples_out,
570 CreateBD_Thread *create_bd;
571 CreateDVD_Thread *create_dvd;
572 BatchRenderThread *batch_render;
575 ExportEDL *exportedl;
585 Mutex *vwindows_lock;
586 ArrayList<VWindow*> vwindows;
595 void show_warning(int *do_warning, const char *text);
598 LevelWindow *lwindow;
600 // Lock during creation and destruction of GUI
601 Mutex *plugin_gui_lock;
602 Mutex *dead_plugin_lock;
603 Mutex *keyframe_gui_lock;
604 // Lock during creation and destruction of brender so playback doesn't use it.
607 // Initialize shared memory
610 // Initialize channel DB's for playback
611 void init_channeldb();
613 void init_exportedl();
614 // These three happen synchronously with each other
615 // Make sure this is called after synchronizing EDL's.
617 // Restart brender after testing its existence
618 void restart_brender();
619 // Stops brender after testing its existence
621 // This one happens asynchronously of the others. Used by playback to
622 // see what frame is background rendered.
623 int brender_available(int position);
624 void set_brender_range();
625 int put_commercial();
626 void activate_commercial() { commercial_active = 1; }
627 void commit_commercial();
628 void undo_commercial();
629 void cut_commercials();
630 int paste_subtitle_text(char *text, double start, double end);
634 static void init_defaults(BC_Hash* &defaults, char *config_path);
635 void check_language();
636 const char *default_std();
637 void fill_preset_defaults(const char *preset, EDLSession *session);
638 const char *get_preset_name(int index);
642 void init_tipwindow();
643 // Used by MWindow and RenderFarmClient
644 static void get_plugin_path(char *path, const char *plug_dir, const char *fs_path);
645 static int init_plugins(MWindow *mwindow, Preferences *preferences);
646 static int init_ladspa_plugins(MWindow *mwindow, Preferences *preferences);
647 static int check_plugin_index(ArrayList<PluginServer*> &plugins,
648 const char *plug_dir, const char *plug_path);
649 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
650 FILE *fp, const char *plugin_dir);
651 static int init_ladspa_index(MWindow *mwindow, Preferences *preferences,
652 const char *index_path, const char *plugin_dir);
653 static void scan_plugin_index(MWindow *mwindow, Preferences *preferences,
654 FILE *fp, const char *plug_dir, const char *plug_path, int &idx);
655 static void init_ffmpeg();
656 static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
657 static int load_plugin_index(MWindow *mwindow, const char *index_path,
658 const char *plugin_dir);
659 static PluginServer* new_ffmpeg_server(MWindow *mwindow, const char *name);
660 void init_preferences();
663 void init_compositor();
664 void init_levelwindow();
665 // Called when creating a new viewer to view footage
666 VWindow* get_viewer(int start_it, int idx=-1);
672 void init_playbackcursor();
673 void init_commercials();
674 static void add_plugins(ArrayList<PluginServer*> &plugins);
675 static void delete_plugins();
677 void clean_indexes();
678 // TimeBomb timebomb;
679 SigHandler *sighandler;