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 "wavecache.inc"
93 // All entry points for commands except for window locking should be here.
94 // This allows scriptability.
96 class MWindow : public Thread
102 // ======================================== initialization commands
103 void create_objects(int want_gui,
111 int run_script(FileXML *script);
113 int delete_project(int flash = 1);
114 void quit(int unlock);
115 int reload() { return reload_status; }
119 int set_filename(const char *filename);
120 // Total vertical pixels in timeline
121 int get_tracks_height();
122 // Total horizontal pixels in timeline
123 int get_tracks_width();
130 int tile_windows(int window_config);
131 char *get_cwindow_display();
132 // void set_titles(int value);
133 void set_screens(int value);
134 int asset_to_edl(EDL *new_edl,
136 RecordLabels *labels = 0);
137 // Convert nested_edl to a nested EDL in new_edl
138 // suitable for pasting in paste_edls
139 int edl_to_nested(EDL *new_edl,
142 // Entry point to insert assets and insert edls. Called by TrackCanvas
143 // and AssetPopup when assets are dragged in from AWindow.
144 // Takes the drag vectors from MainSession and
145 // pastes either assets or clips depending on which is full.
146 // Returns 1 if the vectors were full
147 int paste_assets(double position, Track *dest_track);
149 // Insert the assets at a point in the EDL. Called by menueffects,
150 // render, and CWindow drop but recording calls paste_edls directly for
152 void load_assets(ArrayList<Indexable*> *new_assets,
155 Track *first_track /* = 0 */,
156 RecordLabels *labels /* = 0 */,
160 int paste_edls(ArrayList<EDL*> *new_edls,
162 Track *first_track /* = 0 */,
163 double current_position /* = -1 */,
167 // Reset everything for a load
168 void update_project(int load_mode);
169 // Fit selected time to horizontal display range
170 void fit_selection();
171 // Fit selected autos to the vertical display range
175 void zoom_autos(float min, float max);
176 // move the window to include the cursor
178 // Search plugindb and put results in argument
179 static void search_plugindb(int do_audio,
184 ArrayList<PluginServer*> &results);
185 // Find the plugin whose title matches title and return it
186 static PluginServer* scan_plugindb(char *title,
188 static int plugin_exists(char *plugin_path);
189 void dump_plugindb(FILE *fp);
190 void stop_playback(int wait=0);
195 int load_filenames(ArrayList<char*> *filenames,
196 int load_mode = LOADMODE_REPLACE,
197 // Cause the project filename on the top of the window to be updated.
198 // Not wanted for loading backups.
199 int update_filename = 1);
201 // Print out plugins which are referenced in the EDL but not loaded.
202 void test_plugins(EDL *new_edl, char *path);
204 int interrupt_indexes(); // Stop index building
206 int redraw_time_dependancies(); // after reconfiguring the time format, sample rate, frame rate
208 // =========================================== movement
210 void next_time_format();
211 void prev_time_format();
212 void time_format_common();
213 int reposition_timebar(int new_pixel, int new_height);
215 int zoom_in_sample();
216 int zoom_sample(int64_t zoom_sample);
217 void zoom_amp(int64_t zoom_amp);
218 void zoom_track(int64_t zoom_track);
220 int move_left(int64_t distance = 0);
221 int move_right(int64_t distance = 0);
222 void move_up(int64_t distance = 0);
223 void move_down(int64_t distance = 0);
226 // shift_down must be passed by the caller because different windows call
228 int next_label(int shift_down);
229 int prev_label(int shift_down);
230 // seek to edit handles
231 int next_edit_handle(int shift_down);
232 int prev_edit_handle(int shift_down);
233 // offset is pixels to add to track_start
234 void trackmovement(int offset, int pane_number);
235 // view_start is pixels
236 int samplemovement(int64_t view_start, int pane_number);
240 int goto_position(double position);
248 void update_plugins();
249 // Call after every edit operation
252 void show_plugin(Plugin *plugin);
253 void hide_plugin(Plugin *plugin, int lock);
255 void delete_plugin(PluginServer *plugin);
256 // Update plugins with configuration changes.
257 // Called by TrackCanvas::cursor_motion_event.
258 void update_plugin_guis(int do_keyframe_guis = 1);
259 void update_plugin_states();
260 void update_plugin_titles();
261 // Called by Attachmentpoint during playback.
262 // Searches for matching plugin and renders data in it.
263 void render_plugin_gui(void *data, Plugin *plugin);
264 void render_plugin_gui(void *data, int size, Plugin *plugin);
266 // Called from PluginVClient::process_buffer
267 // Returns 1 if a GUI for the plugin is open so OpenGL routines can determine if
269 int plugin_gui_open(Plugin *plugin);
271 void show_keyframe_gui(Plugin *plugin);
272 void hide_keyframe_guis();
273 void hide_keyframe_gui(Plugin *plugin);
274 void update_keyframe_guis();
277 // ============================= editing commands ========================
279 // Map each recordable audio track to the desired pattern
280 void map_audio(int pattern);
281 void remap_audio(int pattern);
287 void add_audio_track_entry(int above, Track *dst);
288 int add_audio_track(int above, Track *dst);
289 void add_clip_to_edl(EDL *edl);
290 void add_video_track_entry(Track *dst = 0);
291 int add_video_track(int above, Track *dst);
292 void add_subttl_track_entry(Track *dst = 0);
293 int add_subttl_track(int above, Track *dst);
296 void asset_to_size();
297 void asset_to_rate();
298 // Entry point for clear operations.
300 // Clears active region in EDL.
301 // If clear_handle, edit boundaries are cleared if the range is 0.
302 // Called by paste, record, menueffects, render, and CWindow drop.
303 void clear(int clear_handle);
305 int clear_labels(double start, double end);
306 void concatenate_tracks();
308 int copy(double start, double end);
311 // Calculate aspect ratio from pixel counts
312 static int create_aspect_ratio(float &w, float &h, int width, int height);
313 // Calculate defaults path
314 static void create_defaults_path(char *string, const char *config_file);
316 void delete_folder(char *folder);
317 void delete_inpoint();
318 void delete_outpoint();
321 void delete_track(Track *track);
322 void delete_tracks();
323 int feather_edits(int64_t feather_samples, int audio, int video);
324 int64_t get_feather(int audio, int video);
325 float get_aspect_ratio();
326 void insert(double position,
331 EDL *parent_edl /* = 0 */);
333 // TrackCanvas calls this to insert multiple effects from the drag_pluginservers
334 // into pluginset_highlighted.
335 void insert_effects_canvas(double start,
338 // CWindow calls this to insert multiple effects from
339 // the drag_pluginservers array.
340 void insert_effects_cwindow(Track *dest_track);
342 // Attach new effect to all recordable tracks
343 // single_standalone - attach 1 standalone on the first track and share it with
345 void insert_effect(char *title,
346 SharedLocation *shared_location,
349 int single_standalone);
351 // This is called multiple times by the above functions.
352 // It can't sync parameters.
353 void insert_effect(char *title,
354 SharedLocation *shared_location,
356 PluginSet *plugin_set,
361 void match_output_size(Track *track);
362 // Move edit to new position
363 void move_edits(ArrayList<Edit*> *edits,
366 // Move effect to position
367 void move_effect(Plugin *plugin,
368 PluginSet *plugin_set,
371 void move_plugins_up(PluginSet *plugin_set);
372 void move_plugins_down(PluginSet *plugin_set);
373 void move_track_down(Track *track);
374 void move_tracks_down();
375 void move_track_up(Track *track);
376 void move_tracks_up();
377 void mute_selection();
378 void new_folder(const char *new_folder);
379 void overwrite(EDL *source);
380 // For clipboard commands
382 // For splice and overwrite
383 int paste(double start,
389 int paste_output(int64_t startproject,
391 int64_t startsource_sample,
392 int64_t endsource_sample,
393 int64_t startsource_frame,
394 int64_t endsource_frame,
396 RecordLabels *new_labels);
397 void paste_silence();
399 // Detach single transition
400 void detach_transition(Transition *transition);
401 // Detach all transitions in selection
402 void detach_transitions();
403 // Attach dragged transition
404 void paste_transition();
405 // Attach transition to all edits in selection
406 void paste_transitions(int track_type, char *title);
407 // Attach transition dragged onto CWindow
408 void paste_transition_cwindow(Track *dest_track);
409 // Attach default transition to single edit
410 void paste_audio_transition();
411 void paste_video_transition();
412 void shuffle_edits();
414 void set_edit_length(double length);
415 // Set length of single transition
416 void set_transition_length(Transition *transition, double length);
417 // Set length in seconds of all transitions in active range
418 void set_transition_length(double length);
420 void remove_indexfile(Indexable *indexable);
421 void rebuild_indices();
422 // Asset removal from caches
424 void remove_asset_from_caches(Asset *asset);
425 void remove_assets_from_project(int push_undo = 0);
426 void remove_assets_from_disk();
427 void resize_track(Track *track, int w, int h);
429 void set_automation_mode(int mode);
430 void set_keyframe_type(int mode);
431 void set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow);
432 // Update the editing mode
433 int set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow);
434 void set_inpoint(int is_mwindow);
435 void set_outpoint(int is_mwindow);
436 void splice(EDL *source);
437 void toggle_loop_playback();
438 void trim_selection();
439 // Synchronize EDL settings with all playback engines depending on current
440 // operation. Doesn't redraw anything.
441 void sync_parameters(int change_type = CHANGE_PARAMS);
443 int toggle_label(int is_mwindow);
444 void undo_entry(BC_WindowBase *calling_window_gui);
445 void redo_entry(BC_WindowBase *calling_window_gui);
448 int cut_automation();
449 int copy_automation();
450 int paste_automation();
451 void clear_automation();
452 int cut_default_keyframe();
453 int copy_default_keyframe();
454 // Use paste_automation to paste the default keyframe in other position.
455 // Use paste_default_keyframe to replace the default keyframe with whatever is
457 int paste_default_keyframe();
458 int clear_default_keyframe();
460 int modify_edithandles();
461 int modify_pluginhandles();
462 void finish_modify_handles();
464 void dump_plugins(FILE *fp=stdout);
465 void dump_edl(FILE *fp=stdout);
466 void dump_undo(FILE *fp=stdout);
467 void dump_exe(FILE *fp=stdout);
468 static void trap_hook(FILE *fp, void *vp);
470 void reset_android_remote();
474 // Send new EDL to caches
476 int optimize_assets(); // delete unused assets from the cache and assets
478 void select_point(double position);
479 int set_loop_boundaries(); // toggle loop playback and set boundaries for loop playback
482 Playback3D *playback_3d;
483 SplashGUI *splash_window;
489 // CICaches for drawing timeline only
490 CICache *audio_cache, *video_cache;
491 // Frame cache for drawing timeline only.
492 // Cache drawing doesn't wait for file decoding.
493 FrameCache *frame_cache;
494 WaveCache *wave_cache;
495 Preferences *preferences;
496 PreferencesThread *preferences_thread;
497 MainSession *session;
499 MainIndexes *mainindexes;
500 MainProgress *mainprogress;
502 static Commercials *commercials;
503 int commercial_active;
504 int has_commercials();
507 ArrayList<ColormodelItem*> colormodels;
512 int select_asset(Asset *asset, int vstream, int astream, int delete_tracks);
513 int select_asset(int vtrack, int delete_tracks);
515 // Channel DB for playback only. Record channel DB's are in record.C
516 ChannelDB *channeldb_buz;
517 ChannelDB *channeldb_v4l2jpeg;
519 static FileServer *file_server;
521 // ====================================== plugins ==============================
523 // Contains file descriptors for all the dlopens
524 static ArrayList<PluginServer*> *plugindb;
525 // Currently visible plugins
526 ArrayList<PluginServer*> *plugin_guis;
527 // GUI Plugins to delete
528 ArrayList<PluginServer*> *dead_plugins;
530 ArrayList<KeyFrameThread*> *keyframe_threads;
533 // Adjust sample position to line up with frames.
534 int fix_timing(int64_t &samples_out,
539 CreateDVD_Thread *create_dvd;
540 BatchRenderThread *batch_render;
549 Mutex *vwindows_lock;
550 ArrayList<VWindow*> vwindows;
558 LevelWindow *lwindow;
559 // Lock during creation and destruction of GUI
560 Mutex *plugin_gui_lock;
561 Mutex *dead_plugin_lock;
562 Mutex *keyframe_gui_lock;
563 // Lock during creation and destruction of brender so playback doesn't use it.
566 // Initialize shared memory
568 static void init_fileserver(Preferences *preferences);
570 // Initialize channel DB's for playback
571 void init_channeldb();
573 // These three happen synchronously with each other
574 // Make sure this is called after synchronizing EDL's.
576 // Restart brender after testing its existence
577 void restart_brender();
578 // Stops brender after testing its existence
580 // This one happens asynchronously of the others. Used by playback to
581 // see what frame is background rendered.
582 int brender_available(int position);
583 void set_brender_start();
584 int put_commercial();
585 void activate_commercial() { commercial_active = 1; }
586 void commit_commercial();
587 void undo_commercial();
588 void cut_commercials();
589 int paste_subtitle_text(char *text, double start, double end);
593 static void init_defaults(BC_Hash* &defaults, char *config_path);
597 void init_tipwindow();
598 // Used by MWindow and RenderFarmClient
599 static int init_plugins(MWindow *mwindow, Preferences *preferences);
600 static void init_plugin_index(MWindow *mwindow, Preferences *preferences,
601 FILE *fp, const char *plug_dir, const char *plug_path, int &dir_id);
602 static int load_plugin_index(MWindow *mwindow, char *path);
603 void init_preferences();
606 void init_compositor();
607 void init_levelwindow();
608 // Called when creating a new viewer to view footage
609 VWindow* get_viewer(int start_it, int idx=-1);
615 void init_playbackcursor();
616 void init_commercials();
617 void delete_plugins();
619 void clean_indexes();
620 // TimeBomb timebomb;
621 SigHandler *sighandler;