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"
80 #include "recordlabel.inc"
82 #include "sharedlocation.inc"
83 #include "sighandler.inc"
84 #include "splashgui.inc"
87 #include "threadloader.inc"
88 #include "timebar.inc"
90 #include "tipwindow.inc"
92 #include "tracking.inc"
94 #include "transition.inc"
95 #include "transportque.inc"
96 #include "videowindow.inc"
97 #include "vpatchgui.h"
98 #include "vwindow.inc"
99 #include "zwindow.inc"
100 #include "wwindow.inc"
101 #include "wavecache.inc"
103 #define FONT_SEARCHPATH "fonts"
105 // All entry points for commands except for window locking should be here.
106 // This allows scriptability.
108 class MWindow : public Thread
114 // ======================================== initialization commands
115 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 int tile_windows(int window_config);
144 char *get_cwindow_display();
145 void set_screens(int value);
146 int asset_to_edl(EDL *new_edl,
148 RecordLabels *labels = 0);
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 void update_vwindow();
180 // Fit selected time to horizontal display range
181 void fit_selection();
182 // Fit selected autos to the vertical display range
183 void fit_autos(int doall);
184 void change_currentautorange(int autogrouptype, int increment, int changemax);
185 void expand_autos(int changeall, int domin, int domax);
186 void shrink_autos(int changeall, int domin, int domax);
187 // move the window to include the cursor
189 // Search plugindb and put results in argument
190 static void search_plugindb(int do_audio,
195 ArrayList<PluginServer*> &results);
196 // Find the plugin whose title matches title and return it
197 static PluginServer* scan_plugindb(char *title,
199 static void fix_plugin_title(char *title);
200 static int plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins);
201 static int plugin_exists(char *plugin_path);
202 void dump_plugindb(FILE *fp);
203 void stop_playback(int wait);
204 void stop_transport();
206 void queue_mixers(EDL *edl, int command, int wait_tracking,
207 int use_inout, int update_refresh, int toggle_audio, int loop_play);
208 ZWindow *create_mixer(Indexable *indexable);
209 void create_mixers();
210 void refresh_mixers(int dir=1);
212 void close_mixers(int destroy=1);
214 ZWindow *get_mixer(Mixer *&mixer);
215 void del_mixer(ZWindow *zwindow);
216 int mixer_track_active(Track *track);
217 void update_mixer_tracks();
219 int select_zwindow(ZWindow *zwindow);
222 int load_filenames(ArrayList<char*> *filenames,
223 int load_mode = LOADMODE_REPLACE,
224 // Cause the project filename on the top of the window to be updated.
225 // Not wanted for loading backups.
226 int update_filename = 1);
229 // Print out plugins which are referenced in the EDL but not loaded.
230 void test_plugins(EDL *new_edl, char *path);
232 int interrupt_indexes(); // Stop index building
234 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
236 // =========================================== movement
238 void next_time_format();
239 void prev_time_format();
240 void time_format_common();
241 int reposition_timebar(int new_pixel, int new_height);
243 int zoom_in_sample();
244 int zoom_sample(int64_t zoom_sample);
245 void zoom_autos(float min, float max);
246 void zoom_amp(int64_t zoom_amp);
247 void zoom_track(int64_t zoom_track);
249 int move_left(int64_t distance = 0);
250 int move_right(int64_t distance = 0);
251 void move_up(int64_t distance = 0);
252 void move_down(int64_t distance = 0);
253 int find_selection(double position, int scroll_display = 0);
254 void toggle_camera_xyz();
255 void toggle_projector_xyz();
258 // shift_down must be passed by the caller because different windows call
260 int next_label(int shift_down);
261 int prev_label(int shift_down);
262 // seek to edit handles
263 int next_edit_handle(int shift_down);
264 int prev_edit_handle(int shift_down);
266 int nearest_plugin_keyframe(int shift_down, int dir);
267 // offset is pixels to add to track_start
268 void trackmovement(int offset, int pane_number);
269 // view_start is pixels
270 int samplemovement(int64_t view_start, int pane_number);
274 int goto_position(double position);
282 void update_plugins();
283 // Call after every edit operation
286 void show_plugin(Plugin *plugin);
287 void hide_plugin(Plugin *plugin, int lock);
289 void delete_plugin(PluginServer *plugin);
290 // Update plugins with configuration changes.
291 // Called by TrackCanvas::cursor_motion_event.
292 void update_plugin_guis(int do_keyframe_guis = 1);
293 void update_plugin_states();
294 void update_plugin_titles();
295 // Called by Attachmentpoint during playback.
296 // Searches for matching plugin and renders data in it.
297 void render_plugin_gui(void *data, Plugin *plugin);
298 void render_plugin_gui(void *data, int size, Plugin *plugin);
300 // Called from PluginVClient::process_buffer
301 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
303 int plugin_gui_open(Plugin *plugin);
305 void show_keyframe_gui(Plugin *plugin);
306 void hide_keyframe_guis();
307 void hide_keyframe_gui(Plugin *plugin);
308 void update_keyframe_guis();
311 // ============================= editing commands ========================
313 // Map each recordable audio track to the desired pattern
314 void map_audio(int pattern);
315 void remap_audio(int pattern);
321 void add_audio_track_entry(int above, Track *dst);
322 int add_audio_track(int above, Track *dst);
323 void add_clip_to_edl(EDL *edl);
324 void add_video_track_entry(Track *dst = 0);
325 int add_video_track(int above, Track *dst);
326 void add_subttl_track_entry(Track *dst = 0);
327 int add_subttl_track(int above, Track *dst);
330 void asset_to_size();
331 void asset_to_rate();
332 // Entry point for clear operations.
334 // Clears active region in EDL.
335 // If clear_handle, edit boundaries are cleared if the range is 0.
336 // Called by paste, record, menueffects, render, and CWindow drop.
337 void clear(int clear_handle);
339 int clear_labels(double start, double end);
340 void concatenate_tracks();
342 int copy(double start, double end);
344 void blade(double position);
345 void cut(double start, double end, double new_position=-1);
346 // cut edit from current position to handle/label
347 void cut_left_edit();
348 void cut_right_edit();
349 void cut_left_label();
350 void cut_right_label();
352 // Calculate aspect ratio from pixel counts
353 static int create_aspect_ratio(float &w, float &h, int width, int height);
354 // Calculate defaults path
355 static void create_defaults_path(char *string, const char *config_file);
358 void delete_track(Track *track);
359 void delete_tracks();
360 int feather_edits(int64_t feather_samples, int audio, int video);
361 int64_t get_feather(int audio, int video);
362 float get_aspect_ratio();
363 void insert(double position,
368 EDL *parent_edl /* = 0 */);
370 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
371 // into pluginset_highlighted.
372 void insert_effects_canvas(double start,
375 // CWindow calls this to insert multiple effects from
376 // the drag_pluginservers array.
377 void insert_effects_cwindow(Track *dest_track);
379 // Attach new effect to all recordable tracks
380 // single_standalone - attach 1 standalone on the first track and share it with
382 void insert_effect(char *title,
383 SharedLocation *shared_location,
386 int single_standalone);
388 // This is called multiple times by the above functions.
389 // It can't sync parameters.
390 void insert_effect(char *title,
391 SharedLocation *shared_location,
393 PluginSet *plugin_set,
398 void match_output_size(Track *track);
399 // Move edit to new position
400 void move_edits(ArrayList<Edit*> *edits,
403 int behaviour); // behaviour: 0 - old style (cut and insert elswhere), 1- new style - (clear and overwrite elsewere)
404 // Move effect to position
405 void move_effect(Plugin *plugin,
408 void move_effect(Plugin *plugin,
409 PluginSet *plugin_set,
411 void move_plugins_up(PluginSet *plugin_set);
412 void move_plugins_down(PluginSet *plugin_set);
413 void move_track_down(Track *track);
414 void move_tracks_down();
415 void move_track_up(Track *track);
416 void move_tracks_up();
417 void mute_selection();
418 void new_folder(const char *new_folder, int is_clips);
419 void delete_folder(char *folder);
420 // For clipboard commands
422 // For splice and overwrite
423 void overwrite(EDL *source, int all);
424 void splice(EDL *source, int all);
425 int paste(double start, double end, FileXML *file,
426 int edit_labels, int edit_plugins, int edit_autos);
427 int paste_output(int64_t startproject, int64_t endproject,
428 int64_t startsource_sample, int64_t endsource_sample,
429 int64_t startsource_frame, int64_t endsource_frame,
430 Asset *asset, RecordLabels *new_labels);
431 void paste_silence();
433 // Detach single transition
434 void detach_transition(Transition *transition);
435 // Detach all transitions in selection
436 void detach_transitions();
437 // Attach dragged transition
438 void paste_transition();
439 // Attach transition to all edits in selection
440 void paste_transitions(int track_type, char *title);
441 // Attach transition dragged onto CWindow
442 void paste_transition_cwindow(Track *dest_track);
443 // Attach default transition to single edit
444 void paste_audio_transition();
445 void paste_video_transition();
446 void shuffle_edits();
447 void reverse_edits();
449 void set_edit_length(double length);
450 // Set length of single transition
451 void set_transition_length(Transition *transition, double length);
452 // Set length in seconds of all transitions in active range
453 void set_transition_length(double length);
455 void remove_indexfile(Indexable *indexable);
456 void rebuild_indices();
457 // Asset removal from caches
459 void remove_asset_from_caches(Asset *asset);
460 void remove_assets_from_project(int push_undo /* = 0 */,
462 ArrayList<Indexable*> *drag_assets /* mwindow->session->drag_assets */,
463 ArrayList<EDL*> *drag_clips /* mwindow->session->drag_clips */);
464 void remove_assets_from_disk();
465 void resize_track(Track *track, int w, int h);
467 void set_automation_mode(int mode);
468 void set_keyframe_type(int mode);
469 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
470 void set_auto_visibility(Autos *autos, int value);
471 void set_labels_follow_edits(int value);
473 // Update the editing mode
474 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
475 void toggle_editing_mode();
476 void set_inpoint(int is_mwindow);
477 void set_outpoint(int is_mwindow);
478 void unset_inoutpoint(int is_mwindow);
479 void toggle_loop_playback();
480 void trim_selection();
481 // Synchronize EDL settings with all playback engines depending on current
482 // operation. Doesn't redraw anything.
483 void sync_parameters(int change_type = CHANGE_PARAMS);
484 void save_clip(EDL *new_edl, const char *txt);
485 void to_clip(EDL *edl, const char *txt, int all);
486 int toggle_label(int is_mwindow);
487 void undo_entry(BC_WindowBase *calling_window_gui);
488 void redo_entry(BC_WindowBase *calling_window_gui);
489 void save_undo_data();
490 void load_undo_data();
491 int copy_target(const char *path, const char *target);
492 int link_target(const char *real_path, const char *link_path, int relative);
493 void save_project(const char *dir, int save_mode, int overwrite, int reload);
495 int cut_automation();
496 int copy_automation();
497 int paste_automation();
498 void clear_automation();
499 int cut_default_keyframe();
500 int copy_default_keyframe();
501 // Use paste_automation to paste the default keyframe in other position.
502 // Use paste_default_keyframe to replace the default keyframe with whatever is
504 int paste_default_keyframe();
505 int clear_default_keyframe();
507 FloatAuto* get_float_auto(PatchGUI *patch,int idx);
508 IntAuto* get_int_auto(PatchGUI *patch,int idx);
509 PanAuto* get_pan_auto(PatchGUI *patch);
510 PatchGUI *get_patchgui(Track *track);
512 int modify_edithandles();
513 int modify_pluginhandles();
514 void finish_modify_handles();
515 void rescale_proxy(EDL *clip, int orig_scale, int new_scale);
516 void add_proxy(int use_scaler,
517 ArrayList<Indexable*> *orig_assets,
518 ArrayList<Indexable*> *proxy_assets);
519 int render_proxy(ArrayList<Indexable *> &new_idxbls);
520 void beep(double freq, double secs, double gain);
523 int to_proxy(Asset *asset, int new_scale, int new_use_scaler);
524 ProxyBeep *proxy_beep;
526 void dump_plugins(FILE *fp=stdout);
527 void dump_edl(FILE *fp=stdout);
528 void dump_undo(FILE *fp=stdout);
529 void dump_exe(FILE *fp=stdout);
530 static void trap_hook(FILE *fp, void *vp);
532 void reset_android_remote();
534 // Send new EDL to caches
536 int optimize_assets(); // delete unused assets from the cache and assets
538 void select_point(double position);
539 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
542 Playback3D *playback_3d;
543 SplashGUI *splash_window;
549 // CICaches for drawing timeline only
550 CICache *audio_cache, *video_cache;
551 // Frame cache for drawing timeline only.
552 // Cache drawing doesn't wait for file decoding.
553 FrameCache *frame_cache;
554 WaveCache *wave_cache;
555 Preferences *preferences;
556 PreferencesThread *preferences_thread;
557 MainSession *session;
559 MainIndexes *mainindexes;
560 MainProgress *mainprogress;
564 const char *default_standard;
565 static Commercials *commercials;
566 int commercial_active;
567 int has_commercials();
568 // copy of edl created in speed_before, used in speed_after to normalize_speed
572 ArrayList<ColormodelItem*> colormodels;
573 ArrayList<InterlacemodeItem*> interlace_project_modes;
574 ArrayList<InterlacemodeItem*> interlace_asset_modes;
575 ArrayList<InterlacefixmethodItem*> interlace_asset_fixmethods;
580 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
581 int select_asset(int vtrack, int delete_tracks);
583 // Channel DB for playback only. Record channel DB's are in record.C
584 ChannelDB *channeldb_buz;
585 ChannelDB *channeldb_v4l2jpeg;
587 // ====================================== plugins ==============================
589 // Contains file descriptors for all the dlopens
590 static ArrayList<PluginServer*> *plugindb;
591 // Currently visible plugins
592 int64_t plugin_visibility;
593 ArrayList<PluginServer*> *plugin_guis;
594 // GUI Plugins to delete
595 ArrayList<PluginServer*> *dead_plugins;
597 ArrayList<KeyFrameThread*> *keyframe_threads;
599 // Adjust sample position to line up with frames.
600 int fix_timing(int64_t &samples_out,
605 CreateBD_Thread *create_bd;
606 CreateDVD_Thread *create_dvd;
607 BatchRenderThread *batch_render;
610 ExportEDL *exportedl;
620 Mutex *vwindows_lock;
621 ArrayList<VWindow*> vwindows;
623 Mutex *zwindows_lock;
624 ArrayList<ZWindow*> zwindows;
633 void show_warning(int *do_warning, const char *text);
636 LevelWindow *lwindow;
638 // Lock during creation and destruction of GUI
639 Mutex *plugin_gui_lock;
640 Mutex *dead_plugin_lock;
641 Mutex *keyframe_gui_lock;
642 // Lock during creation and destruction of brender so playback doesn't use it.
644 // Initialize shared memory
645 void init_shm(const char *pfn, int64_t min);
646 // Initialize channel DB's for playback
647 void init_channeldb();
649 void init_exportedl();
650 // These three happen synchronously with each other
651 // Make sure this is called after synchronizing EDL's.
653 // Restart brender after testing its existence
654 void restart_brender();
655 // Stops brender after testing its existence
657 // This one happens asynchronously of the others. Used by playback to
658 // see what frame is background rendered.
659 int brender_available(int position);
660 void set_brender_active(int v, int update=1);
661 int put_commercial();
662 void activate_commercial() { commercial_active = 1; }
663 void commit_commercial();
664 void undo_commercial();
665 void cut_commercials();
666 void update_gui(int changed_edl);
667 int paste_subtitle_text(char *text, double start, double end);
671 static void init_defaults(BC_Hash* &defaults, char *config_path);
672 void check_language();
673 const char *default_std();
674 void fill_preset_defaults(const char *preset, EDLSession *session);
675 const char *get_preset_name(int index);
679 void init_tipwindow();
680 // Used by MWindow and RenderFarmClient
681 static void get_plugin_path(char *path, const char *plug_dir, const char *fs_path);
682 static int init_plugins(MWindow *mwindow, Preferences *preferences);
683 static int init_ladspa_plugins(MWindow *mwindow, Preferences *preferences);
684 static void init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang);
685 static int check_plugin_index(ArrayList<PluginServer*> &plugins,
686 const char *plug_dir, const char *plug_path);
687 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
688 FILE *fp, const char *plugin_dir);
689 static int init_ladspa_index(MWindow *mwindow, Preferences *preferences,
690 FILE *fp, const char *plugin_dir);
691 static void scan_plugin_index(MWindow *mwindow, Preferences *preferences,
692 FILE *fp, const char *plug_dir, const char *plug_path, int &idx);
693 static void init_ffmpeg();
694 static void init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
695 static int load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir);
696 static PluginServer *new_ffmpeg_server(MWindow *mwindow, const char *name);
697 static int init_lv2_index(MWindow *mwindow, Preferences *preferences, FILE *fp);
698 static PluginServer *new_lv2_server(MWindow *mwindow, const char *name);
699 static void remove_plugin_index();
701 void init_preferences();
704 void init_compositor();
705 void init_levelwindow();
706 // Called when creating a new viewer to view footage
707 VWindow* get_viewer(int start_it, int idx=-1);
713 void init_playbackcursor();
714 void init_commercials();
715 static void add_plugins(ArrayList<PluginServer*> &plugins);
716 static void delete_plugins();
718 int speed_after(int done);
719 int normalize_speed(EDL *old_edl, EDL *new_edl);
721 void clean_indexes();
722 // TimeBomb timebomb;
723 SigHandler *sighandler;