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 "brender.inc"
36 #include "channel.inc"
37 #include "channeldb.inc"
38 #include "commercials.inc"
39 #include "cwindow.inc"
41 #include "devicedvbinput.inc"
42 #include "devicempeginput.inc"
45 #include "fileserver.inc"
46 #include "filesystem.inc"
47 #include "filexml.inc"
48 #include "framecache.inc"
49 #include "gwindow.inc"
50 #include "indexable.inc"
51 #include "keyframegui.inc"
52 #include "levelwindow.inc"
53 #include "loadmode.inc"
54 #include "mainerror.inc"
55 #include "mainindexes.inc"
56 #include "mainprogress.inc"
57 #include "mainsession.inc"
58 #include "mainundo.inc"
59 #include "maxchannels.h"
61 #include "mwindow.inc"
62 #include "mwindowgui.inc"
64 #include "patchbay.inc"
65 #include "playback3d.inc"
66 #include "playbackengine.inc"
68 #include "pluginserver.inc"
69 #include "pluginset.inc"
70 #include "preferences.inc"
71 #include "preferencesthread.inc"
73 #include "recordlabel.inc"
75 #include "sharedlocation.inc"
76 #include "sighandler.inc"
77 #include "splashgui.inc"
80 #include "threadloader.inc"
81 #include "timebar.inc"
83 #include "tipwindow.inc"
85 #include "tracking.inc"
87 #include "transition.inc"
88 #include "transportque.inc"
89 #include "videowindow.inc"
90 #include "vwindow.inc"
91 #include "wwindow.inc"
92 #include "wavecache.inc"
94 // All entry points for commands except for window locking should be here.
95 // This allows scriptability.
97 class MWindow : public Thread
103 // ======================================== initialization commands
104 void create_objects(int want_gui,
112 int run_script(FileXML *script);
114 int delete_project(int flash = 1);
115 void quit(int unlock);
116 int reload() { return reload_status; }
120 int set_filename(const char *filename);
121 // Total vertical pixels in timeline
122 int get_tracks_height();
123 // Total horizontal pixels in timeline
124 int get_tracks_width();
131 int tile_windows(int window_config);
132 char *get_cwindow_display();
133 // void set_titles(int value);
134 void set_screens(int value);
135 int asset_to_edl(EDL *new_edl,
137 RecordLabels *labels = 0);
138 // Convert nested_edl to a nested EDL in new_edl
139 // suitable for pasting in paste_edls
140 int edl_to_nested(EDL *new_edl,
143 // Entry point to insert assets and insert edls. Called by TrackCanvas
144 // and AssetPopup when assets are dragged in from AWindow.
145 // Takes the drag vectors from MainSession and
146 // pastes either assets or clips depending on which is full.
147 // Returns 1 if the vectors were full
148 int paste_assets(double position, Track *dest_track);
150 // Insert the assets at a point in the EDL. Called by menueffects,
151 // render, and CWindow drop but recording calls paste_edls directly for
153 void load_assets(ArrayList<Indexable*> *new_assets,
156 Track *first_track /* = 0 */,
157 RecordLabels *labels /* = 0 */,
161 int paste_edls(ArrayList<EDL*> *new_edls,
163 Track *first_track /* = 0 */,
164 double current_position /* = -1 */,
168 // Reset everything for a load
169 void update_project(int load_mode);
170 // Fit selected time to horizontal display range
171 void fit_selection();
172 // Fit selected autos to the vertical display range
176 void zoom_autos(float min, float max);
177 // move the window to include the cursor
179 // Search plugindb and put results in argument
180 static void search_plugindb(int do_audio,
185 ArrayList<PluginServer*> &results);
186 // Find the plugin whose title matches title and return it
187 static PluginServer* scan_plugindb(char *title,
189 static int plugin_exists(char *plugin_path);
190 void dump_plugindb(FILE *fp);
191 void stop_playback(int wait=0);
196 int load_filenames(ArrayList<char*> *filenames,
197 int load_mode = LOADMODE_REPLACE,
198 // Cause the project filename on the top of the window to be updated.
199 // Not wanted for loading backups.
200 int update_filename = 1);
202 // Print out plugins which are referenced in the EDL but not loaded.
203 void test_plugins(EDL *new_edl, char *path);
205 int interrupt_indexes(); // Stop index building
207 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
209 // =========================================== movement
211 void next_time_format();
212 void prev_time_format();
213 void time_format_common();
214 int reposition_timebar(int new_pixel, int new_height);
216 int zoom_in_sample();
217 int zoom_sample(int64_t zoom_sample);
218 void zoom_amp(int64_t zoom_amp);
219 void zoom_track(int64_t zoom_track);
221 int move_left(int64_t distance = 0);
222 int move_right(int64_t distance = 0);
223 void move_up(int64_t distance = 0);
224 void move_down(int64_t distance = 0);
227 // shift_down must be passed by the caller because different windows call
229 int next_label(int shift_down);
230 int prev_label(int shift_down);
231 // seek to edit handles
232 int next_edit_handle(int shift_down);
233 int prev_edit_handle(int shift_down);
234 // offset is pixels to add to track_start
235 void trackmovement(int offset, int pane_number);
236 // view_start is pixels
237 int samplemovement(int64_t view_start, int pane_number);
241 int goto_position(double position);
249 void update_plugins();
250 // Call after every edit operation
253 void show_plugin(Plugin *plugin);
254 void hide_plugin(Plugin *plugin, int lock);
256 void delete_plugin(PluginServer *plugin);
257 // Update plugins with configuration changes.
258 // Called by TrackCanvas::cursor_motion_event.
259 void update_plugin_guis(int do_keyframe_guis = 1);
260 void update_plugin_states();
261 void update_plugin_titles();
262 // Called by Attachmentpoint during playback.
263 // Searches for matching plugin and renders data in it.
264 void render_plugin_gui(void *data, Plugin *plugin);
265 void render_plugin_gui(void *data, int size, Plugin *plugin);
267 // Called from PluginVClient::process_buffer
268 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
270 int plugin_gui_open(Plugin *plugin);
272 void show_keyframe_gui(Plugin *plugin);
273 void hide_keyframe_guis();
274 void hide_keyframe_gui(Plugin *plugin);
275 void update_keyframe_guis();
278 // ============================= editing commands ========================
280 // Map each recordable audio track to the desired pattern
281 void map_audio(int pattern);
282 void remap_audio(int pattern);
288 void add_audio_track_entry(int above, Track *dst);
289 int add_audio_track(int above, Track *dst);
290 void add_clip_to_edl(EDL *edl);
291 void add_video_track_entry(Track *dst = 0);
292 int add_video_track(int above, Track *dst);
293 void add_subttl_track_entry(Track *dst = 0);
294 int add_subttl_track(int above, Track *dst);
297 void asset_to_size();
298 void asset_to_rate();
299 // Entry point for clear operations.
301 // Clears active region in EDL.
302 // If clear_handle, edit boundaries are cleared if the range is 0.
303 // Called by paste, record, menueffects, render, and CWindow drop.
304 void clear(int clear_handle);
306 int clear_labels(double start, double end);
307 void concatenate_tracks();
309 int copy(double start, double end);
312 // Calculate aspect ratio from pixel counts
313 static int create_aspect_ratio(float &w, float &h, int width, int height);
314 // Calculate defaults path
315 static void create_defaults_path(char *string, const char *config_file);
317 void delete_folder(char *folder);
318 void delete_inpoint();
319 void delete_outpoint();
322 void delete_track(Track *track);
323 void delete_tracks();
324 int feather_edits(int64_t feather_samples, int audio, int video);
325 int64_t get_feather(int audio, int video);
326 float get_aspect_ratio();
327 void insert(double position,
332 EDL *parent_edl /* = 0 */);
334 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
335 // into pluginset_highlighted.
336 void insert_effects_canvas(double start,
339 // CWindow calls this to insert multiple effects from
340 // the drag_pluginservers array.
341 void insert_effects_cwindow(Track *dest_track);
343 // Attach new effect to all recordable tracks
344 // single_standalone - attach 1 standalone on the first track and share it with
346 void insert_effect(char *title,
347 SharedLocation *shared_location,
350 int single_standalone);
352 // This is called multiple times by the above functions.
353 // It can't sync parameters.
354 void insert_effect(char *title,
355 SharedLocation *shared_location,
357 PluginSet *plugin_set,
362 void match_output_size(Track *track);
363 // Move edit to new position
364 void move_edits(ArrayList<Edit*> *edits,
367 // Move effect to position
368 void move_effect(Plugin *plugin,
369 PluginSet *plugin_set,
372 void move_plugins_up(PluginSet *plugin_set);
373 void move_plugins_down(PluginSet *plugin_set);
374 void move_track_down(Track *track);
375 void move_tracks_down();
376 void move_track_up(Track *track);
377 void move_tracks_up();
378 void mute_selection();
379 void new_folder(const char *new_folder);
380 void overwrite(EDL *source);
381 // For clipboard commands
383 // For splice and overwrite
384 int paste(double start,
390 int paste_output(int64_t startproject,
392 int64_t startsource_sample,
393 int64_t endsource_sample,
394 int64_t startsource_frame,
395 int64_t endsource_frame,
397 RecordLabels *new_labels);
398 void paste_silence();
400 // Detach single transition
401 void detach_transition(Transition *transition);
402 // Detach all transitions in selection
403 void detach_transitions();
404 // Attach dragged transition
405 void paste_transition();
406 // Attach transition to all edits in selection
407 void paste_transitions(int track_type, char *title);
408 // Attach transition dragged onto CWindow
409 void paste_transition_cwindow(Track *dest_track);
410 // Attach default transition to single edit
411 void paste_audio_transition();
412 void paste_video_transition();
413 void shuffle_edits();
415 void set_edit_length(double length);
416 // Set length of single transition
417 void set_transition_length(Transition *transition, double length);
418 // Set length in seconds of all transitions in active range
419 void set_transition_length(double length);
421 void remove_indexfile(Indexable *indexable);
422 void rebuild_indices();
423 // Asset removal from caches
425 void remove_asset_from_caches(Asset *asset);
426 void remove_assets_from_project(int push_undo = 0);
427 void remove_assets_from_disk();
428 void resize_track(Track *track, int w, int h);
430 void set_automation_mode(int mode);
431 void set_keyframe_type(int mode);
432 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
433 // Update the editing mode
434 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
435 void set_inpoint(int is_mwindow);
436 void set_outpoint(int is_mwindow);
437 void splice(EDL *source);
438 void toggle_loop_playback();
439 void trim_selection();
440 // Synchronize EDL settings with all playback engines depending on current
441 // operation. Doesn't redraw anything.
442 void sync_parameters(int change_type = CHANGE_PARAMS);
444 int toggle_label(int is_mwindow);
445 void undo_entry(BC_WindowBase *calling_window_gui);
446 void redo_entry(BC_WindowBase *calling_window_gui);
449 int cut_automation();
450 int copy_automation();
451 int paste_automation();
452 void clear_automation();
453 int cut_default_keyframe();
454 int copy_default_keyframe();
455 // Use paste_automation to paste the default keyframe in other position.
456 // Use paste_default_keyframe to replace the default keyframe with whatever is
458 int paste_default_keyframe();
459 int clear_default_keyframe();
461 int modify_edithandles();
462 int modify_pluginhandles();
463 void finish_modify_handles();
465 void dump_plugins(FILE *fp=stdout);
466 void dump_edl(FILE *fp=stdout);
467 void dump_undo(FILE *fp=stdout);
468 void dump_exe(FILE *fp=stdout);
469 static void trap_hook(FILE *fp, void *vp);
471 void reset_android_remote();
475 // Send new EDL to caches
477 int optimize_assets(); // delete unused assets from the cache and assets
479 void select_point(double position);
480 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
483 Playback3D *playback_3d;
484 SplashGUI *splash_window;
490 // CICaches for drawing timeline only
491 CICache *audio_cache, *video_cache;
492 // Frame cache for drawing timeline only.
493 // Cache drawing doesn't wait for file decoding.
494 FrameCache *frame_cache;
495 WaveCache *wave_cache;
496 Preferences *preferences;
497 PreferencesThread *preferences_thread;
498 MainSession *session;
500 MainIndexes *mainindexes;
501 MainProgress *mainprogress;
503 static Commercials *commercials;
504 int commercial_active;
505 int has_commercials();
508 ArrayList<ColormodelItem*> colormodels;
513 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
514 int select_asset(int vtrack, int delete_tracks);
516 // Channel DB for playback only. Record channel DB's are in record.C
517 ChannelDB *channeldb_buz;
518 ChannelDB *channeldb_v4l2jpeg;
520 static FileServer *file_server;
522 // ====================================== plugins ==============================
524 // Contains file descriptors for all the dlopens
525 static ArrayList<PluginServer*> *plugindb;
526 // Currently visible plugins
527 ArrayList<PluginServer*> *plugin_guis;
528 // GUI Plugins to delete
529 ArrayList<PluginServer*> *dead_plugins;
531 ArrayList<KeyFrameThread*> *keyframe_threads;
534 // Adjust sample position to line up with frames.
535 int fix_timing(int64_t &samples_out,
540 CreateDVD_Thread *create_dvd;
541 BatchRenderThread *batch_render;
550 Mutex *vwindows_lock;
551 ArrayList<VWindow*> vwindows;
560 void show_warning(int *do_warning, const char *text);
562 LevelWindow *lwindow;
563 // Lock during creation and destruction of GUI
564 Mutex *plugin_gui_lock;
565 Mutex *dead_plugin_lock;
566 Mutex *keyframe_gui_lock;
567 // Lock during creation and destruction of brender so playback doesn't use it.
570 // Initialize shared memory
572 static void init_fileserver(Preferences *preferences);
574 // Initialize channel DB's for playback
575 void init_channeldb();
577 // These three happen synchronously with each other
578 // Make sure this is called after synchronizing EDL's.
580 // Restart brender after testing its existence
581 void restart_brender();
582 // Stops brender after testing its existence
584 // This one happens asynchronously of the others. Used by playback to
585 // see what frame is background rendered.
586 int brender_available(int position);
587 void set_brender_start();
588 int put_commercial();
589 void activate_commercial() { commercial_active = 1; }
590 void commit_commercial();
591 void undo_commercial();
592 void cut_commercials();
593 int paste_subtitle_text(char *text, double start, double end);
597 static void init_defaults(BC_Hash* &defaults, char *config_path);
601 void init_tipwindow();
602 // Used by MWindow and RenderFarmClient
603 static int init_plugins(MWindow *mwindow, Preferences *preferences);
604 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
605 FILE *fp, const char *plug_dir, const char *plug_path, int &dir_id);
606 static int load_plugin_index(MWindow *mwindow, char *path);
607 void init_preferences();
610 void init_compositor();
611 void init_levelwindow();
612 // Called when creating a new viewer to view footage
613 VWindow* get_viewer(int start_it, int idx=-1);
619 void init_playbackcursor();
620 void init_commercials();
621 void delete_plugins();
623 void clean_indexes();
624 // TimeBomb timebomb;
625 SigHandler *sighandler;