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"
65 #include "mixersalign.inc"
67 #include "mwindow.inc"
68 #include "mwindowgui.inc"
70 #include "patchbay.inc"
71 #include "playback3d.inc"
72 #include "playbackengine.inc"
74 #include "pluginfclient.inc"
75 #include "pluginserver.inc"
76 #include "pluginset.inc"
77 #include "preferences.inc"
78 #include "preferencesthread.inc"
81 #include "recordlabel.inc"
83 #include "sharedlocation.inc"
84 #include "sighandler.inc"
85 #include "splashgui.inc"
86 #include "shuttle.inc"
89 #include "threadloader.inc"
90 #include "timebar.inc"
91 #include "tipwindow.inc"
93 #include "tracking.inc"
95 #include "transition.inc"
96 #include "transportque.inc"
97 #include "videowindow.inc"
98 #include "vpatchgui.h"
99 #include "vwindow.inc"
100 #include "zwindow.inc"
101 #include "wwindow.inc"
102 #include "wavecache.inc"
104 #define FONT_SEARCHPATH "fonts"
107 class MWindow : public Thread
113 // ======================================== initialization commands
114 void create_objects(int want_gui,
123 int run_script(FileXML *script);
125 int delete_project(int flash = 1);
127 int restart() { return restart_status; }
131 int set_filename(const char *filename);
132 // Total vertical pixels in timeline
133 int get_tracks_height();
134 // Total horizontal pixels in timeline
135 int get_tracks_width();
143 void restore_windows();
144 void load_layout(const char *layout);
145 void save_layout(const char *layout);
146 void delete_layout(const char *layout);
147 int tile_windows(int window_config);
148 char *get_cwindow_display();
149 void set_screens(int value);
150 int asset_to_edl(EDL *new_edl,
152 RecordLabels *labels = 0);
154 // Entry point to insert assets and insert edls. Called by TrackCanvas
155 // and AssetPopup when assets are dragged in from AWindow.
156 // Takes the drag vectors from MainSession and
157 // pastes either assets or clips depending on which is full.
158 // Returns 1 if the vectors were full
159 int paste_assets(double position, Track *dest_track, int overwrite);
161 // Insert the assets at a point in the EDL. Called by menueffects,
162 // render, and CWindow drop but recording calls paste_edls directly for
164 void load_assets(ArrayList<Indexable*> *new_assets,
167 Track *first_track /* = 0 */,
168 RecordLabels *labels /* = 0 */,
173 int paste_edls(ArrayList<EDL*> *new_edls,
175 Track *first_track /* = 0 */,
176 double current_position /* = -1 */,
181 // Reset everything for a load
182 void update_project(int load_mode);
183 void update_vwindow();
184 // Fit selected time to horizontal display range
185 void fit_selection();
186 // Fit selected autos to the vertical display range
187 void fit_autos(int all);
188 void change_currentautorange(int autogrouptype, int increment, int changemax);
189 void expand_autos(int changeall, int domin, int domax);
190 void shrink_autos(int changeall, int domin, int domax);
191 // move the window to include the cursor
193 // Search plugindb and put results in argument
194 static void search_plugindb(int do_audio,
199 ArrayList<PluginServer*> &results);
200 // Find the plugin whose title matches title and return it
201 static PluginServer* scan_plugindb(char *title,
203 static void fix_plugin_title(char *title);
204 static int plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins);
205 static int plugin_exists(char *plugin_path);
206 void dump_plugindb(FILE *fp);
207 void stop_playback(int wait);
208 void stop_transport();
209 void undo_before(const char *description = "", void *creator = 0);
210 void undo_after(const char *description, uint32_t load_flags, int changes_made = 1);
212 void handle_mixers(EDL *edl, int command, int wait_tracking,
213 int use_inout, int toggle_audio, int loop_play, float speed);
214 ZWindow *create_mixer(Indexable *indexable, double position);
215 void create_mixers(double position = 0);
216 void refresh_mixers(int dir=1);
218 void close_mixers(int destroy=1);
220 ZWindow *get_mixer(Mixer *&mixer);
221 void del_mixer(ZWindow *zwindow);
222 int mixer_track_active(Track *track);
223 void update_mixer_tracks();
225 int select_zwindow(ZWindow *zwindow);
227 int load_filenames(ArrayList<char*> *filenames,
228 int load_mode = LOADMODE_REPLACE,
229 // Cause the project filename on the top of the window to be updated.
230 // Not wanted for loading backups.
231 int update_filename = 1);
234 // Print out plugins which are referenced in the EDL but not loaded.
235 void test_plugins(EDL *new_edl, char *path);
237 int interrupt_indexes(); // Stop index building
239 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
241 // =========================================== movement
243 void next_time_format();
244 void prev_time_format();
245 void time_format_common();
246 int reposition_timebar(int new_pixel, int new_height);
248 int zoom_in_sample();
249 int zoom_sample(int64_t zoom_sample);
250 void zoom_autos(float min, float max);
251 void zoom_amp(int64_t zoom_amp);
252 void zoom_track(int64_t zoom_track);
254 int move_left(int64_t distance = 0);
255 int move_right(int64_t distance = 0);
256 void move_up(int64_t distance = 0);
257 void move_down(int64_t distance = 0);
258 int find_selection(double position, int scroll_display = 0);
259 void toggle_camera_xyz();
260 void toggle_projector_xyz();
261 double get_position();
262 void set_position(double position);
265 // shift_down must be passed by the caller because different windows call
267 int next_label(int shift_down);
268 int prev_label(int shift_down);
269 // seek to edit handles
270 int next_edit_handle(int shift_down);
271 int prev_edit_handle(int shift_down);
273 int nearest_plugin_keyframe(int shift_down, int dir);
274 // offset is pixels to add to track_start
275 void trackmovement(int offset, int pane_number);
276 // view_start is pixels
277 int samplemovement(int64_t view_start, int pane_number);
281 int goto_position(double position);
288 void crop_video(int mode);
289 void update_plugins();
290 // Call after every edit operation
293 void show_plugin(Plugin *plugin);
294 void hide_plugin(Plugin *plugin, int lock);
296 void delete_plugin(PluginServer *plugin);
297 // Update plugins with configuration changes.
298 // Called by TrackCanvas::cursor_motion_event.
299 void update_plugin_guis(int do_keyframe_guis = 1);
300 void update_plugin_states();
301 void update_plugin_titles();
302 // Called by Attachmentpoint during playback.
303 // Searches for matching plugin and renders data in it.
304 void render_plugin_gui(void *data, Plugin *plugin);
305 void render_plugin_gui(void *data, int size, Plugin *plugin);
307 // Called from PluginVClient::process_buffer
308 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
310 int plugin_gui_open(Plugin *plugin);
312 void show_keyframe_gui(Plugin *plugin);
313 void hide_keyframe_guis();
314 void hide_keyframe_gui(Plugin *plugin);
315 void update_keyframe_guis();
316 int get_hash_color(Edit *edit);
317 int get_hash_color(int v);
318 int get_group_color(int v);
319 int get_title_color(Edit *edit);
321 // ============================= editing commands ========================
323 // Map each recordable audio track to the desired pattern
324 void map_audio(int pattern);
325 void remap_audio(int pattern);
331 void add_audio_track_entry(int above, Track *dst);
332 int add_audio_track(int above, Track *dst);
333 void add_clip_to_edl(EDL *edl);
334 void add_video_track_entry(Track *dst = 0);
335 int add_video_track(int above, Track *dst);
336 void add_subttl_track_entry(Track *dst = 0);
337 int add_subttl_track(int above, Track *dst);
340 void asset_to_size();
341 void asset_to_rate();
342 // Entry point for clear operations.
344 // Clears active region in EDL.
345 // If clear_handle, edit boundaries are cleared if the range is 0.
346 // Called by paste, record, menueffects, render, and CWindow drop.
347 void clear(int clear_handle);
349 int clear_labels(double start, double end);
350 void clear_hard_edges();
351 int clear_hard_edges(double start, double end);
353 void concatenate_tracks();
354 int copy_flags(int copy_flags=COPY_CLIPBOARD);
356 int copy(double start, double end);
358 void blade(double position);
359 void cut(double start, double end, double new_position=-1);
360 // cut edit from current position to handle/label
361 void cut_left_edit();
362 void cut_right_edit();
363 void cut_left_label();
364 void cut_right_label();
366 // Calculate aspect ratio from pixel counts
367 static int create_aspect_ratio(float &w, float &h, int width, int height);
368 // Calculate defaults path
369 static void create_defaults_path(char *string, const char *config_file);
371 void delete_track(Track *track);
372 void delete_tracks();
373 int feather_edits(int64_t feather_samples, int audio, int video);
374 int64_t get_feather(int audio, int video);
375 float get_aspect_ratio();
376 void insert(double position, FileXML *file,
377 int edit_labels, int edit_plugins, int edit_autos,
378 EDL *parent_edl, Track *first_track, int overwrite);
380 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
381 // into pluginset_highlighted.
382 void insert_effects_canvas(double start, double length);
384 // CWindow calls this to insert multiple effects from
385 // the drag_pluginservers array.
386 void insert_effects_cwindow(Track *dest_track);
388 // Attach new effect to all recordable tracks
389 // single_standalone - attach 1 standalone on the first track and share it with
391 void insert_effect(char *title,
392 SharedLocation *shared_location,
393 int data_type, int plugin_type, int single_standalone);
395 // This is called multiple times by the above functions.
396 // It can't sync parameters.
397 void insert_effect(char *title,
398 SharedLocation *shared_location,
399 Track *track, PluginSet *plugin_set,
400 double start, double length, int plugin_type);
402 void match_output_size(Track *track);
403 void delete_edit(Edit *edit, const char *msg, int collapse=0);
404 void delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse=0);
405 void delete_edits(int collapse=0);
406 void cut_selected_edits(int collapse, int packed);
407 // Move edit to new position
408 void move_edits(ArrayList<Edit*> *edits, Track *track, double position,
409 int mode); // mode: 0 - mute and overwrite, 1 - cut and paste
410 void selected_edits_to_clipboard(int packed);
411 void paste_clipboard(Track *first_track, double position, int overwrite,
412 int edit_edits, int edit_labels, int edit_autos, int edit_plugins);
413 void move_group(EDL *group, Track *first_track, double position, int overwrite);
414 // Move effect to position
415 void move_effect(Plugin *plugin, Track *track, int64_t position);
416 void move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position);
417 void move_plugins_up(PluginSet *plugin_set);
418 void move_plugins_down(PluginSet *plugin_set);
419 void move_track_down(Track *track);
420 void move_tracks_down();
421 void move_track_up(Track *track);
422 void move_tracks_up();
423 void mute_selection();
424 void new_folder(const char *new_folder, int is_clips);
425 void delete_folder(char *folder);
426 // For clipboard commands
428 void paste(double start, Track *first_track, int clear_selection, int overwrite);
429 // For splice and overwrite
430 void overwrite(EDL *source, int all);
431 void splice(EDL *source, int all);
432 int paste(double start, double end, FileXML *file,
433 int edit_labels, int edit_plugins, int edit_autos,
434 Track *first_track, int overwrite);
435 int paste_output(int64_t startproject, int64_t endproject,
436 int64_t startsource_sample, int64_t endsource_sample,
437 int64_t startsource_frame, int64_t endsource_frame,
438 Asset *asset, RecordLabels *new_labels);
439 void paste_silence();
441 // Detach single transition
442 void detach_transition(Transition *transition);
443 // Detach all transitions in selection
444 void detach_transitions();
445 // Attach dragged transition
446 void paste_transition();
447 // Attach transition to all edits in selection
448 void paste_transitions(int track_type, char *title);
449 // Attach transition dragged onto CWindow
450 void paste_transition_cwindow(Track *dest_track);
451 // Attach default transition to single edit
452 void paste_audio_transition();
453 void paste_video_transition();
454 void shuffle_edits();
455 void reverse_edits();
457 void set_edit_length(double length);
458 // Set length of single transition
459 void set_transition_length(Transition *transition, double length);
460 // Set length in seconds of all transitions in active range
461 void set_transition_length(double length);
463 void remove_indexfile(Indexable *indexable);
464 void rebuild_indices();
465 // Asset removal from caches
467 void remove_asset_from_caches(Asset *asset);
468 void remove_assets_from_project(int push_undo /* = 0 */,
470 ArrayList<Indexable*> *drag_assets /* mwindow->session->drag_assets */,
471 ArrayList<EDL*> *drag_clips /* mwindow->session->drag_clips */);
472 void remove_assets_from_disk();
473 void resize_track(Track *track, int w, int h);
475 void set_automation_mode(int mode);
476 void set_keyframe_type(int mode);
477 void set_auto_keyframes(int value);
478 void set_span_keyframes(int value);
479 void set_auto_visibility(Autos *autos, int value);
480 void set_labels_follow_edits(int value);
482 // Update the editing mode
483 int set_editing_mode(int new_editing_mode);
484 void toggle_editing_mode();
487 void unset_inoutpoint();
488 void toggle_loop_playback();
489 void trim_selection();
490 // Synchronize EDL settings with all playback engines depending on current
491 // operation. Doesn't redraw anything.
492 void sync_parameters(int change_type = CHANGE_PARAMS);
493 void save_clip(EDL *new_edl, const char *txt);
494 void to_clip(EDL *edl, const char *txt, int all);
496 void undo_entry(BC_WindowBase *calling_window_gui);
497 void redo_entry(BC_WindowBase *calling_window_gui);
498 void save_undo_data();
499 void load_undo_data();
500 int copy_target(const char *path, const char *target);
501 int link_target(const char *real_path, const char *link_path, int relative);
502 void save_project(const char *dir, int save_mode, int overwrite, int reload);
504 int cut_automation();
505 int copy_automation();
506 int paste_automation();
507 void clear_automation();
508 int cut_default_keyframe();
509 int copy_default_keyframe();
510 // Use paste_automation to paste the default keyframe in other position.
511 // Use paste_default_keyframe to replace the default keyframe with whatever is
513 int paste_default_keyframe();
514 int clear_default_keyframe();
516 FloatAuto* get_float_auto(PatchGUI *patch,int idx);
517 IntAuto* get_int_auto(PatchGUI *patch,int idx);
518 PanAuto* get_pan_auto(PatchGUI *patch);
519 PatchGUI *get_patchgui(Track *track);
521 int modify_edithandles();
522 int modify_pluginhandles();
523 void finish_modify_handles();
524 void rescale_proxy(EDL *clip, int orig_scale, int new_scale);
525 void add_proxy(int use_scaler,
526 ArrayList<Indexable*> *orig_assets,
527 ArrayList<Indexable*> *proxy_assets);
528 int render_proxy(ArrayList<Indexable *> &new_idxbls);
529 void beep(double freq, double secs, double gain);
532 int to_proxy(Asset *asset, int new_scale, int new_use_scaler);
533 ProxyBeep *proxy_beep;
535 void dump_plugins(FILE *fp=stdout);
536 void dump_edl(FILE *fp=stdout);
537 void dump_undo(FILE *fp=stdout);
538 void dump_exe(FILE *fp=stdout);
539 static void trap_hook(FILE *fp, void *vp);
541 void reset_android_remote();
543 // Send new EDL to caches
545 int optimize_assets(); // delete unused assets from the cache and assets
547 void select_point(double position);
548 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
551 Playback3D *playback_3d;
552 SplashGUI *splash_window;
560 // CICaches for drawing timeline only
561 CICache *audio_cache, *video_cache;
562 // Frame cache for drawing timeline only.
563 // Cache drawing doesn't wait for file decoding.
564 FrameCache *frame_cache;
565 WaveCache *wave_cache;
566 Preferences *preferences;
567 PreferencesThread *preferences_thread;
568 MainSession *session;
570 MainIndexes *mainindexes;
571 MainProgress *mainprogress;
575 const char *default_standard;
576 static Commercials *commercials;
577 int commercial_active;
578 int has_commercials();
579 // copy of edl created in speed_before, used in speed_after to normalize_speed
583 ArrayList<ColormodelItem*> colormodels;
584 ArrayList<InterlacemodeItem*> interlace_project_modes;
585 ArrayList<InterlacemodeItem*> interlace_asset_modes;
590 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
591 int select_asset(int vtrack, int delete_tracks);
593 // Channel DB for playback only. Record channel DB's are in record.C
594 ChannelDB *channeldb_buz;
595 ChannelDB *channeldb_v4l2jpeg;
597 // ====================================== plugins ==============================
599 // Contains file descriptors for all the dlopens
600 static ArrayList<PluginServer*> *plugindb;
601 // Currently visible plugins
602 int64_t plugin_visibility;
603 ArrayList<PluginServer*> *plugin_guis;
604 // GUI Plugins to delete
605 ArrayList<PluginServer*> *dead_plugins;
607 ArrayList<KeyFrameThread*> *keyframe_threads;
609 // Adjust sample position to line up with frames.
610 int fix_timing(int64_t &samples_out,
615 CreateBD_Thread *create_bd;
616 CreateDVD_Thread *create_dvd;
617 BatchRenderThread *batch_render;
620 ExportEDL *exportedl;
630 Mutex *vwindows_lock;
631 ArrayList<VWindow*> vwindows;
633 Mutex *zwindows_lock;
634 ArrayList<ZWindow*> zwindows;
635 MixersAlign *mixers_align;
645 void show_warning(int *do_warning, const char *text);
648 LevelWindow *lwindow;
650 // Lock during creation and destruction of GUI
651 Mutex *plugin_gui_lock;
652 Mutex *dead_plugin_lock;
653 Mutex *keyframe_gui_lock;
654 // Lock during creation and destruction of brender so playback doesn't use it.
656 // Initialize shared memory
657 void init_shm(const char *pfn, int64_t min);
658 // Initialize channel DB's for playback
659 void init_channeldb();
661 void init_exportedl();
662 // These three happen synchronously with each other
663 // Make sure this is called after synchronizing EDL's.
665 // Restart brender after testing its existence
666 void restart_brender();
667 // Stops brender after testing its existence
669 // This one happens asynchronously of the others. Used by playback to
670 // see what frame is background rendered.
671 int brender_available(int position);
672 void set_brender_active(int v, int update=1);
673 int put_commercial();
674 void activate_commercial() { commercial_active = 1; }
675 void commit_commercial();
676 void undo_commercial();
677 void cut_commercials();
678 void update_gui(int changed_edl);
679 int paste_subtitle_text(char *text, double start, double end);
683 static void init_defaults(BC_Hash* &defaults, char *config_path);
684 void check_language();
685 const char *default_std();
686 void fill_preset_defaults(const char *preset, EDLSession *session);
687 const char *get_preset_name(int index);
691 void init_tipwindow();
692 // Used by MWindow and RenderFarmClient
693 static void get_plugin_path(char *path, const char *plug_dir, const char *fs_path);
694 static int init_plugins(MWindow *mwindow, Preferences *preferences);
695 static int init_ladspa_plugins(MWindow *mwindow, Preferences *preferences);
696 static void init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang);
697 static int check_plugin_index(ArrayList<PluginServer*> &plugins,
698 const char *plug_dir, const char *plug_path);
699 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
700 FILE *fp, const char *plugin_dir);
701 static int init_ladspa_index(MWindow *mwindow, Preferences *preferences,
702 FILE *fp, const char *plugin_dir);
703 static void scan_plugin_index(MWindow *mwindow, Preferences *preferences,
704 FILE *fp, const char *plug_dir, const char *plug_path, int &idx);
705 static void init_ffmpeg();
706 static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
707 static int load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir);
708 static PluginServer *new_ffmpeg_server(MWindow *mwindow, const char *name);
709 static int init_lv2_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
710 static PluginServer *new_lv2_server(MWindow *mwindow, const char *name);
711 static void remove_plugin_index();
713 void init_preferences();
717 void init_compositor();
718 void init_levelwindow();
719 // Called when creating a new viewer to view footage
720 VWindow* get_viewer(int start_it, int idx=-1);
726 void init_playbackcursor();
727 void init_commercials();
728 static void add_plugins(ArrayList<PluginServer*> &plugins);
729 static void delete_plugins();
731 int speed_after(int done);
732 int normalize_speed(EDL *old_edl, EDL *new_edl);
734 void clean_indexes();
735 // TimeBomb timebomb;
736 SigHandler *sighandler;