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
21 #include "aboutprefs.h"
25 #include "audioalsa.h"
27 #include "awindowgui.h"
29 #include "batchrender.h"
30 #include "bcdisplayinfo.h"
31 #include "bcsignals.h"
38 #include "channeldb.h"
39 #include "channelinfo.h"
41 #include "bccmodels.h"
42 #include "commercials.h"
43 #include "cplayback.h"
45 #include "cwindowgui.h"
47 #include "cwindowtool.h"
49 #include "devicedvbinput.inc"
50 #include "dvdcreate.h"
51 #include "editpanel.h"
53 #include "edlsession.h"
55 #include "fileformat.h"
57 #include "filesystem.h"
59 #include "floatautos.h"
60 #include "framecache.h"
62 #include "gwindowgui.h"
63 #include "keyframegui.h"
64 #include "indexfile.h"
66 #include "interlacemodes.h"
68 #include "levelwindowgui.h"
69 #include "levelwindow.h"
70 #include "loadfile.inc"
71 #include "localsession.h"
72 #include "maincursor.h"
73 #include "mainerror.h"
74 #include "mainindexes.h"
76 #include "mainprogress.h"
77 #include "mainsession.h"
81 #include "mwindowgui.h"
83 #include "nestededls.h"
87 #include "playback3d.h"
88 #include "playbackengine.h"
90 #include "pluginserver.h"
91 #include "pluginset.h"
92 #include "preferences.h"
95 #include "recordmonitor.h"
96 #include "recordlabel.h"
97 #include "removefile.h"
99 #include "resourcethread.h"
100 #include "samplescroll.h"
102 #include "sighandler.h"
103 #include "splashgui.h"
104 #include "statusbar.h"
106 #include "threadloader.h"
108 #include "timelinepane.h"
109 #include "tipwindow.h"
110 #include "trackcanvas.h"
112 #include "tracking.h"
113 #include "trackscroll.h"
115 #include "transition.h"
116 #include "transportque.h"
119 #include "versioninfo.h"
120 #include "videodevice.inc"
121 #include "videowindow.h"
122 #include "vplayback.h"
123 #include "vwindowgui.h"
125 #include "wavecache.h"
129 #include "zwindowgui.h"
130 #include "exportedl.h"
132 #include "defaultformats.h"
133 #include "ntsczones.h"
140 #include <sys/types.h>
141 #include <sys/stat.h>
142 #include <sys/time.h>
143 #include <sys/mman.h>
154 // Hack for libdv to remove glib dependancy
157 // g_log (const char *log_domain,
159 // const char *format,
165 // g_logv (const char *log_domain,
167 // const char *format,
177 ArrayList<PluginServer*>* MWindow::plugindb = 0;
178 Commercials* MWindow::commercials = 0;
184 run_lock = new Mutex("MWindow::run_lock");
185 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
186 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
187 vwindows_lock = new Mutex("MWindow::vwindows_lock");
188 zwindows_lock = new Mutex("MWindow::zwindows_lock");
189 brender_lock = new Mutex("MWindow::brender_lock");
190 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
198 commercial_active = 0;
210 strcpy(cin_lang,"en");
211 channeldb_buz = new ChannelDB;
212 channeldb_v4l2jpeg = new ChannelDB;
216 keyframe_threads = 0;
236 // Need to delete brender temporary here.
239 run_lock->lock("MWindow::~MWindow");
241 //printf("MWindow::~MWindow %d\n", __LINE__);
242 gui->remote_control->deactivate();
245 gui->channel_info->stop();
247 delete create_bd; create_bd = 0;
248 delete create_dvd; create_dvd = 0;
249 delete batch_render; batch_render = 0;
250 delete render; render = 0;
252 if( commercials && !commercials->remove_user() ) commercials = 0;
255 // Save defaults for open plugins
256 plugin_gui_lock->lock("MWindow::~MWindow");
257 for(int i = 0; i < plugin_guis->size(); i++) {
258 plugin_guis->get(i)->hide_gui();
259 delete_plugin(plugin_guis->get(i));
261 plugin_gui_lock->unlock();
262 hide_keyframe_guis();
265 // Give up and go to a movie
266 // cant run valgrind if this is used
268 gui->del_keyboard_listener(
269 (int (BC_WindowBase::*)(BC_WindowBase *))
270 &MWindowGUI::keyboard_listener);
272 // release the hounds
273 if( awindow && awindow->gui ) awindow->gui->close(0);
274 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
275 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
276 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
277 if( twindow && twindow->is_running() ) twindow->close_window();
278 if( wwindow && wwindow->is_running() ) wwindow->close_window();
279 vwindows.remove_all_objects();
280 zwindows.remove_all_objects();
282 if( awindow ) awindow->join();
283 if( cwindow ) cwindow->join();
284 if( lwindow ) lwindow->join();
285 if( twindow ) twindow->join();
286 if( wwindow ) wwindow->join();
287 if( gwindow ) gwindow->join();
290 // one at a time, or nouveau chokes
291 #define close_gui(win) if( win ) { \
292 if( win->gui ) win->gui->close(0); \
300 vwindows.remove_all_objects();
301 zwindows.remove_all_objects();
306 dead_plugins->remove_all_objects();
307 // must delete theme before destroying plugindb
308 // theme destructor will be deleted by delete_plugins
309 delete theme; theme = 0;
312 keyframe_threads->remove_all_objects();
313 colormodels.remove_all_objects();
314 delete awindow; awindow = 0;
315 delete lwindow; lwindow = 0;
316 delete twindow; twindow = 0;
317 delete wwindow; wwindow = 0;
318 delete gwindow; gwindow = 0;
319 delete cwindow; cwindow = 0;
321 //delete file_server; file_server = 0; // reusable
322 delete mainindexes; mainindexes = 0;
323 delete mainprogress; mainprogress = 0;
324 delete audio_cache; audio_cache = 0; // delete the cache after the assets
325 delete video_cache; video_cache = 0; // delete the cache after the assets
326 delete frame_cache; frame_cache = 0;
327 delete wave_cache; wave_cache = 0;
328 delete plugin_guis; plugin_guis = 0;
329 delete dead_plugins; dead_plugins = 0;
330 delete keyframe_threads; keyframe_threads = 0;
331 delete undo; undo = 0;
332 delete preferences; preferences = 0;
333 delete exportedl; exportedl = 0;
334 delete session; session = 0;
335 delete defaults; defaults = 0;
336 delete assets; assets = 0;
337 delete splash_window; splash_window = 0;
338 if( !edl->Garbage::remove_user() ) edl = 0;
339 delete channeldb_buz;
340 delete channeldb_v4l2jpeg;
341 // This must be last thread to exit
342 delete playback_3d; playback_3d = 0;
343 delete dead_plugin_lock;
344 delete plugin_gui_lock;
345 delete vwindows_lock;
346 delete zwindows_lock;
348 delete keyframe_gui_lock;
349 colormodels.remove_all_objects();
350 interlace_project_modes.remove_all_objects();
351 interlace_asset_modes.remove_all_objects();
352 interlace_asset_fixmethods.remove_all_objects();
353 sighandler->terminate();
364 void MWindow::init_error()
366 MainError::init_error(this);
369 void MWindow::finit_error()
371 MainError::finit_error();
374 void MWindow::create_defaults_path(char *string, const char *config_file)
376 // set the .bcast path
379 sprintf(string, "%s/", File::get_config_path());
380 fs.complete_path(string);
381 if(!fs.is_dir(string))
382 fs.create_dir(string);
385 strcat(string, config_file);
387 const char *MWindow::default_std()
389 char buf[BCTEXTLEN], *p = 0;
391 int fd = open(TIMEZONE_NAME, O_RDONLY);
393 int l = read(fd, buf, sizeof(buf)-1);
396 if( buf[l-1] == '\n' ) --l;
402 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
405 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
406 p += strlen(ZONEINFO_STR);
411 for( int i=0; ntsc_zones[i]; ++i ) {
412 if( !strcmp(ntsc_zones[i], p) )
419 for( int i=0; ntsc_zones[i]; ++i ) {
420 if( !strcmp(ntsc_zones[i], p) )
425 //__timezone: Seconds west of UTC. 240sec/deg
426 double tz_deg = -__timezone / 240.;
427 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
428 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
431 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
433 struct formatpresets *fpr;
435 for(fpr = &format_presets[0]; fpr->name; fpr++)
437 if(strcmp(_(fpr->name), preset) == 0)
439 session->audio_channels = fpr->audio_channels;
440 session->audio_tracks = fpr->audio_tracks;
441 session->sample_rate = fpr->sample_rate;
442 session->video_channels = fpr->video_channels;
443 session->video_tracks = fpr->video_tracks;
444 session->frame_rate = fpr->frame_rate;
445 session->output_w = fpr->output_w;
446 session->output_h = fpr->output_h;
447 session->aspect_w = fpr->aspect_w;
448 session->aspect_h = fpr->aspect_h;
449 session->interlace_mode = fpr->interlace_mode;
450 session->color_model = fpr->color_model;
456 const char *MWindow::get_preset_name(int index)
458 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
460 return _(format_presets[index].name);
464 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
466 char path[BCTEXTLEN];
467 // Use user supplied path
469 strcpy(path, config_path);
471 create_defaults_path(path, CONFIG_FILE);
473 defaults = new BC_Hash(path);
478 void MWindow::check_language()
480 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
481 const char *env_lang = getenv("LANGUAGE");
482 if( !env_lang ) env_lang = getenv("LC_ALL");
483 if( !env_lang ) env_lang = getenv("LANG");
485 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
486 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
487 env_lang = curr_lang;
489 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
490 defaults->get("LAST_LANG",last_lang);
491 if( strcmp(env_lang,last_lang)) {
492 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
493 defaults->update("LAST_LANG",env_lang);
494 char plugin_path[BCTEXTLEN];
495 create_defaults_path(plugin_path, PLUGIN_FILE);
496 ::remove(plugin_path);
497 char ladspa_path[BCTEXTLEN];
498 create_defaults_path(ladspa_path, LADSPA_FILE);
499 ::remove(ladspa_path);
502 if( strlen(env_lang) > 1 &&
503 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
504 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
507 strcpy(cin_lang, "en");
510 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
512 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
514 const char *dp = plug_dir;
515 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
516 bp = !*dp && *bp == '/' ? bp+1 : base_path;
522 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
525 FILE *fp = fopen(index_path, "r");
529 char index_line[BCTEXTLEN];
530 int index_version = -1, len = strlen(plugin_dir);
531 if( !fgets(index_line, BCTEXTLEN, fp) ||
532 sscanf(index_line, "%d", &index_version) != 1 ||
533 index_version != PLUGIN_FILE_VERSION ||
534 !fgets(index_line, BCTEXTLEN, fp) ||
535 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
536 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
538 ArrayList<PluginServer*> plugins;
539 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
540 if( index_line[0] == ';' ) continue;
541 if( index_line[0] == '#' ) continue;
542 int type = PLUGIN_TYPE_UNKNOWN;
543 char path[BCTEXTLEN], title[BCTEXTLEN];
545 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
548 PluginServer *server = 0;
550 case PLUGIN_TYPE_BUILTIN:
551 case PLUGIN_TYPE_EXECUTABLE:
552 case PLUGIN_TYPE_LADSPA: {
553 char plugin_path[BCTEXTLEN]; struct stat st;
554 sprintf(plugin_path, "%s/%s", plugin_dir, path);
555 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
558 server = new PluginServer(mwindow, plugin_path, type);
560 case PLUGIN_TYPE_FFMPEG: {
561 server = new_ffmpeg_server(mwindow, path);
564 if( !server ) continue;
565 plugins.append(server);
566 // Create plugin server from index entry
567 server->set_title(title);
568 if( server->read_table(index_line) ) {
575 ret = check_plugin_index(plugins, plugin_dir, ".");
578 add_plugins(plugins);
580 plugins.remove_all_objects();
585 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
586 const char *plug_dir, const char *plug_path)
588 char plugin_path[BCTEXTLEN];
589 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
591 fs.set_filter( "[*.plugin][*.so]" );
592 if( fs.update(plugin_path) )
595 for( int i=0; i<fs.dir_list.total; ++i ) {
596 char fs_path[BCTEXTLEN];
597 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
598 if( fs.is_dir(fs_path) ) {
599 get_plugin_path(plugin_path, plug_dir, fs_path);
600 if( check_plugin_index(plugins, plug_dir, plugin_path) )
603 else if( !plugin_exists(fs_path, plugins) )
610 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
613 plugindb = new ArrayList<PluginServer*>;
615 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
616 create_defaults_path(index_path, PLUGIN_FILE);
617 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
618 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
619 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
620 printf("init plugin index: %s\n", plugin_path);
621 FILE *fp = fopen(index_path,"w");
623 fprintf(stderr,_("MWindow::init_plugins: "
624 "can't create plugin index: %s\n"), index_path);
627 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
628 fprintf(fp, "%s\n", plugin_path);
629 init_plugin_index(mwindow, preferences, fp, plugin_path);
630 init_ffmpeg_index(mwindow, preferences, fp);
632 return load_plugin_index(mwindow, index_path, plugin_path);
635 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
637 char *path = getenv("LADSPA_PATH");
638 char ladspa_path[BCTEXTLEN];
640 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
643 for( int len=0; *path; path+=len ) {
644 char *cp = strchr(path,':');
645 len = !cp ? strlen(path) : cp-path;
646 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
647 memcpy(plugin_path, path, len); plugin_path[len] = 0;
649 char *plugin_dir = FileSystem::basepath(plugin_path);
650 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
651 create_defaults_path(index_path, LADSPA_FILE);
652 cp = index_path + strlen(index_path);
653 for( char *bp=plugin_path; *bp!=0; ++bp )
654 *cp++ = *bp=='/' ? '_' : *bp;
656 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
657 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
658 load_plugin_index(mwindow, index_path, plugin_path);
663 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
664 FILE *fp, const char *plugin_dir)
666 int idx = PLUGIN_IDS;
668 for( int i=0; i<plugindb->size(); ++i ) {
669 PluginServer *server = plugindb->get(i);
670 if( server->dir_idx >= idx )
671 idx = server->dir_idx+1;
674 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
677 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
678 const char *index_path, const char *plugin_dir)
680 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
681 strcpy(plugin_path, path); delete [] path;
682 printf("init ladspa index: %s\n", plugin_dir);
683 FILE *fp = fopen(index_path,"w");
685 fprintf(stderr,_("MWindow::init_ladspa_index: "
686 "can't create plugin index: %s\n"), index_path);
689 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
690 fprintf(fp, "%s\n", plugin_dir);
691 init_plugin_index(mwindow, preferences, fp, plugin_path);
696 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
697 const char *plug_dir, const char *plug_path, int &idx)
699 char plugin_path[BCTEXTLEN];
700 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
702 fs.set_filter( "[*.plugin][*.so]" );
703 int result = fs.update(plugin_path);
704 if( result || !fs.dir_list.total ) return;
707 for( int i=0; i<fs.dir_list.total; ++i ) {
708 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
709 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
710 get_plugin_path(path, plug_dir, fs_path);
711 if( fs.is_dir(fs_path) ) {
712 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
715 if( plugin_exists(path) ) continue;
717 if( stat(fs_path, &st) ) continue;
718 int64_t mtime = st.st_mtime;
719 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
720 result = server.open_plugin(1, preferences, 0, 0);
722 server.write_table(fp, path, vis_id, mtime);
723 server.close_plugin();
725 else if( result == PLUGINSERVER_IS_LAD ) {
728 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
729 ladspa.set_lad_index(lad_index++);
730 result = ladspa.open_plugin(1, preferences, 0, 0);
732 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
733 ladspa.close_plugin();
739 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
741 for( int i=0; i<plugins.size(); ++i )
742 plugindb->append(plugins[i]);
743 plugins.remove_all();
746 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
748 const char *cfg_path = File::get_cindat_path();
749 char msg_path[BCTEXTLEN]; int txt = 0;
751 if( BC_Resources::language[0] ) {
752 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
754 fp = fopen(msg_path, "r");
758 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
760 fp = fopen(msg_path, "r");
763 char text[BCTEXTLEN];
764 char *tp = text, *ep = tp + sizeof(text)-1;
765 char title[BCTEXTLEN];
770 char line[BCTEXTLEN], *cp = line;
771 if( fgets(line,sizeof(line)-1,fp) ) {
772 if( *cp == '#' ) continue;
773 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
776 if( tp > text && *--tp == '\n' ) *tp = 0;
778 tp = !txt ? title : _(title);
779 int idx = plugins.size();
780 while( --idx>=0 && strcmp(plugins[idx]->title, tp) );
782 delete [] plugins[idx]->tip;
783 plugins[idx]->tip = cstrdup(text);
787 if( done > 0 ) break;
789 char *dp = strchr(cp, ':');
791 printf("plugin tips: error on line %d\n", no);
795 while( cp < dp ) *bp++ = *cp++;
800 while( *cp == ' ' || *cp == '\t' ) ++cp;
801 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
806 void MWindow::delete_plugins()
808 plugindb->remove_all_objects();
813 void MWindow::search_plugindb(int do_audio,
818 ArrayList<PluginServer*> &results)
821 for(int i = 0; i < MWindow::plugindb->total; i++)
823 PluginServer *current = MWindow::plugindb->get(i);
825 if(current->audio == do_audio &&
826 current->video == do_video &&
827 (current->realtime == is_realtime || is_realtime < 0) &&
828 current->transition == is_transition &&
829 current->theme == is_theme)
830 results.append(current);
833 // Alphabetize list by title
839 for(int i = 0; i < results.total - 1; i++)
841 PluginServer *value1 = results[i];
842 PluginServer *value2 = results[i + 1];
843 if(strcmp(_(value1->title), _(value2->title)) > 0)
847 results[i + 1] = value1;
853 PluginServer* MWindow::scan_plugindb(char *title,
858 // printf("MWindow::scan_plugindb data_type < 0\n");
862 for(int i = 0; i < plugindb->total; i++)
864 PluginServer *server = plugindb->get(i);
866 !strcasecmp(server->title, title) &&
868 (data_type == TRACK_AUDIO && server->audio) ||
869 (data_type == TRACK_VIDEO && server->video)))
870 return plugindb->get(i);
875 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
877 for( int i=0; i<plugins.size(); ++i )
878 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
882 int MWindow::plugin_exists(char *plugin_path)
884 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
887 void MWindow::init_preferences()
889 preferences = new Preferences;
890 preferences->load_defaults(defaults);
891 session = new MainSession(this);
892 session->load_defaults(defaults);
893 // set x11_host, screens, window_config
894 screens = session->set_default_x11_host();
895 BC_Signals::set_trap_hook(trap_hook, this);
896 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
897 BC_Signals::set_catch_intr(preferences->trap_sigintr);
898 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
899 BC_Trace::enable_locks();
902 BC_Trace::disable_locks();
904 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
905 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
906 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
907 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
910 void MWindow::clean_indexes()
915 int oldest_item = -1;
917 char string[BCTEXTLEN];
918 char string2[BCTEXTLEN];
920 // Delete extra indexes
921 fs.set_filter("*.idx");
922 fs.complete_path(preferences->index_directory);
923 fs.update(preferences->index_directory);
924 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
926 // Eliminate directories
931 for(int i = 0; i < fs.dir_list.total && !result; i++)
933 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
934 if(fs.is_dir(string))
936 delete fs.dir_list[i];
937 fs.dir_list.remove_number(i);
942 total_excess = fs.dir_list.total - preferences->index_count;
944 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
945 while(total_excess > 0)
948 for(int i = 0; i < fs.dir_list.total; i++)
950 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
952 if(i == 0 || fs.get_date(string) <= oldest)
954 oldest = fs.get_date(string);
962 fs.join_names(string,
963 preferences->index_directory,
964 fs.dir_list[oldest_item]->name);
965 //printf("MWindow::clean_indexes 1 %s\n", string);
967 perror("delete_indexes");
968 delete fs.dir_list[oldest_item];
969 fs.dir_list.remove_number(oldest_item);
971 // Remove table of contents if it exists
972 strcpy(string2, string);
973 char *ptr = strrchr(string2, '.');
976 //printf("MWindow::clean_indexes 2 %s\n", string2);
977 sprintf(ptr, ".toc");
979 sprintf(ptr, ".mkr");
988 void MWindow::init_awindow()
990 awindow = new AWindow(this);
991 awindow->create_objects();
994 void MWindow::init_gwindow()
996 gwindow = new GWindow(this);
997 gwindow->create_objects();
1000 void MWindow::init_tipwindow()
1002 TipWindow::load_tips(cin_lang);
1004 twindow = new TipWindow(this);
1008 void MWindow::show_warning(int *do_warning, const char *text)
1010 if( do_warning && !*do_warning ) return;
1012 wwindow = new WWindow(this);
1013 wwindow->show_warning(do_warning, text);
1016 int MWindow::wait_warning()
1018 return wwindow->wait_result();
1021 void MWindow::init_theme()
1026 PluginServer *theme_plugin = 0;
1027 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1028 if( plugindb->get(i)->theme &&
1029 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1030 theme_plugin = plugindb->get(i);
1034 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1035 preferences->theme);
1037 const char *default_theme = _(DEFAULT_THEME);
1038 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1039 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1041 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1042 if( plugindb->get(i)->theme &&
1043 !strcasecmp(default_theme, plugindb->get(i)->title) )
1044 theme_plugin = plugindb->get(i);
1049 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1053 PluginServer *plugin = new PluginServer(*theme_plugin);
1054 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1055 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1056 theme_plugin->title);
1060 theme = plugin->new_theme();
1061 theme->mwindow = this;
1062 strcpy(theme->path, plugin->path);
1065 // Load default images & settings
1066 theme->Theme::initialize();
1067 // Load user images & settings
1068 theme->initialize();
1069 // Create menus with user colors
1070 theme->build_menus();
1073 theme->sort_image_sets();
1074 theme->check_used();
1075 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1078 void MWindow::init_3d()
1080 playback_3d = new Playback3D(this);
1081 playback_3d->create_objects();
1084 void MWindow::init_edl()
1087 edl->create_objects();
1088 fill_preset_defaults(default_standard, edl->session);
1089 edl->load_defaults(defaults);
1090 edl->session->brender_start = edl->session->brender_end = 0;
1091 edl->create_default_tracks();
1092 edl->tracks->update_y_pixels(theme);
1095 void MWindow::init_compositor()
1097 cwindow = new CWindow(this);
1098 cwindow->create_objects();
1101 void MWindow::init_levelwindow()
1103 lwindow = new LevelWindow(this);
1104 lwindow->create_objects();
1107 VWindow *MWindow::get_viewer(int start_it, int idx)
1109 vwindows_lock->lock("MWindow::get_viewer");
1110 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1111 if( !vwindow ) idx = vwindows.size();
1112 while( !vwindow && --idx >= 0 ) {
1113 VWindow *vwin = vwindows[idx];
1114 if( !vwin->is_running() || !vwin->get_edl() )
1118 vwindow = new VWindow(this);
1119 vwindow->load_defaults();
1120 vwindow->create_objects();
1121 vwindows.append(vwindow);
1123 vwindows_lock->unlock();
1124 if( start_it ) vwindow->start();
1128 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1130 zwindows_lock->lock("MWindow::get_mixer");
1131 if( !mixer ) mixer = edl->mixers.new_mixer();
1132 ZWindow *zwindow = 0;
1133 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1134 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1136 zwindows.append(zwindow = new ZWindow(this));
1137 zwindow->idx = mixer->idx;
1138 zwindows_lock->unlock();
1142 void MWindow::del_mixer(ZWindow *zwindow)
1144 zwindows_lock->lock("MWindow::del_mixer 0");
1145 edl->mixers.del_mixer(zwindow->idx);
1147 if( session->selected_zwindow >= 0 ) {
1148 int i = zwindows.number_of(zwindow);
1149 if( i >= 0 && i < session->selected_zwindow )
1150 --session->selected_zwindow;
1151 else if( i == session->selected_zwindow )
1152 session->selected_zwindow = -1;
1154 zwindows_lock->unlock();
1155 gui->lock_window("MWindow::del_mixer 1");
1156 gui->update_mixers(0, -1);
1157 gui->unlock_window();
1160 void MWindow::start_mixer()
1163 ZWindow *zwindow = get_mixer(mixer);
1164 const char *title = 0;
1166 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1167 PatchGUI *patchgui = get_patchgui(track);
1168 if( !patchgui || !patchgui->mixer ) continue;
1169 mixer->mixer_ids.append(track->get_mixer_id());
1170 if( !title ) title = track->title;
1173 session->selected_zwindow = -1;
1174 gui->lock_window("MWindow::start_mixer");
1175 gui->update_mixers(0, 0);
1176 gui->unlock_window();
1178 zwindow->set_title(title);
1183 int MWindow::mixer_track_active(Track *track)
1185 int i = session->selected_zwindow;
1186 if( i < 0 || i >= zwindows.size() ) return 0;
1187 ZWindow *zwindow = zwindows[i];
1188 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1189 if( !mixer ) return 0;
1190 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1191 return n >= 0 ? 1 : 0;
1194 void MWindow::update_mixer_tracks()
1196 zwindows_lock->lock("MixPatch::handle_event");
1197 int i = session->selected_zwindow;
1198 if( i >= 0 && i < zwindows.size() ) {
1199 ZWindow *zwindow = zwindows[i];
1200 zwindow->update_mixer_ids();
1202 zwindows_lock->unlock();
1205 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1206 int use_inout, int update_refresh, int toggle_audio)
1208 zwindows_lock->lock("MWindow::queue_mixers");
1209 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1210 ZWindow *zwindow = zwindows[vidx];
1211 if( zwindow->idx < 0 ) continue;
1212 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1213 if( !mixer || !mixer->mixer_ids.size() ) continue;
1215 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1216 if( track->data_type != TRACK_VIDEO ) continue;
1217 int mixer_id = track->get_mixer_id();
1218 k = mixer->mixer_ids.size();
1219 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1221 if( k < 0 ) continue;
1222 EDL *mixer_edl = new EDL(this->edl);
1223 mixer_edl->create_objects();
1224 mixer_edl->copy_all(edl);
1225 mixer_edl->remove_vwindow_edls();
1226 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1227 k = mixer->mixer_ids.size();
1228 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1231 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1234 track->record = track->play = 0;
1236 zwindow->change_source(mixer_edl);
1237 zwindow->issue_command(command,
1238 wait_tracking, use_inout, update_refresh, toggle_audio);
1240 zwindows_lock->unlock();
1243 void MWindow::refresh_mixers()
1245 queue_mixers(edl,CURRENT_FRAME,0,0,1,0);
1248 void MWindow::stop_mixers()
1250 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1251 ZWindow *zwindow = zwindows[vidx];
1252 if( zwindow->idx < 0 ) continue;
1253 zwindow->issue_command(STOP, 0, 0, 0, 0);
1257 void MWindow::close_mixers()
1259 zwindows_lock->lock("MWindow::close_mixers");
1260 for( int i=0; i<zwindows.size(); ++i ) {
1261 ZWindow *zwindow = zwindows[i];
1262 if( zwindow->idx < 0 ) continue;
1263 ZWindowGUI *zgui = zwindow->zgui;
1264 zgui->lock_window("MWindow::select_zwindow 0");
1266 zgui->unlock_window();
1268 zwindows_lock->unlock();
1269 for( int i=0; i<zwindows.size(); ++i ) {
1270 ZWindow *zwindow = zwindows[i];
1271 if( zwindow->idx < 0 ) continue;
1272 zwindow->close_window();
1276 void MWindow::open_mixers()
1278 for( int i=0; i<edl->mixers.size(); ++i ) {
1279 Mixer *mixer = edl->mixers[i];
1280 ZWindow *zwindow = get_mixer(mixer);
1281 zwindow->set_title(mixer->title);
1287 int MWindow::select_zwindow(ZWindow *zwindow)
1289 int ret = 0, n = zwindows.number_of(zwindow);
1290 if( session->selected_zwindow != n ) {
1291 session->selected_zwindow = n;
1292 for( int i=0; i<zwindows.size(); ++i ) {
1293 ZWindow *zwindow = zwindows[i];
1294 if( zwindow->idx < 0 ) continue;
1295 ZWindowGUI *zgui = zwindow->zgui;
1296 zgui->lock_window("MWindow::select_zwindow 0");
1297 zwindow->highlighted = i == n ? 1 : 0;
1298 if( zgui->draw_overlays() )
1299 zgui->canvas->get_canvas()->flash(1);
1300 zgui->unlock_window();
1303 gui->lock_window("MWindow::select_window 1");
1304 gui->update_mixers(0, -1);
1305 gui->unlock_window();
1310 void MWindow::tile_mixers()
1313 for( int i=0; i<zwindows.size(); ++i ) {
1314 ZWindow *zwindow = zwindows[i];
1315 if( zwindow->idx < 0 ) continue;
1319 int zn = ceil(sqrt(nz));
1320 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1321 int y1 = 1, y2 = gui->get_y();
1322 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1323 if( x1 < 0 ) x1 = 0;
1324 if( y1 < 0 ) y1 = 0;
1325 if( x2 > rw ) x2 = rw;
1326 if( y2 > rh ) y2 = rh;
1327 int dx = x2 - x1, dy = y2 - y1;
1329 int lt = BC_DisplayInfo::get_left_border();
1330 int top = BC_DisplayInfo::get_top_border();
1331 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1332 int bh = top + BC_DisplayInfo::get_bottom_border();
1333 int zx = 0, zy = 0; // window origins
1334 int mw = 10+10, mh = 10+10; // canvas margins
1335 int rsz = 0, n = 0, dz = 0;
1336 int ow = edl->session->output_w, oh = edl->session->output_h;
1337 for( int i=0; i<zwindows.size(); ++i ) {
1338 ZWindow *zwindow = zwindows[i];
1339 if( zwindow->idx < 0 ) continue;
1340 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1341 if( rsz < hh ) rsz = hh;
1342 int xx = zx + x1, yy = zy + y1;
1343 int mx = x2 - zw, my = y2 - zh;
1344 if( xx > mx ) xx = mx;
1345 if( yy > my ) yy = my;
1346 xx += lt + dz; yy += top + dz;
1347 zwindow->reposition(xx,yy, ww,hh);
1348 if( zwindow->running() ) {
1349 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1350 gui->lock_window("MWindow::tile_mixers");
1351 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1352 gui->unlock_window();
1356 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1365 void MWindow::init_cache()
1367 audio_cache = new CICache(preferences);
1368 video_cache = new CICache(preferences);
1369 frame_cache = new FrameCache;
1370 wave_cache = new WaveCache;
1373 void MWindow::init_channeldb()
1375 channeldb_buz->load("channeldb_buz");
1376 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1379 void MWindow::init_menus()
1381 char string[BCTEXTLEN];
1384 BC_CModels::to_text(string, BC_RGB888);
1385 colormodels.append(new ColormodelItem(string, BC_RGB888));
1386 BC_CModels::to_text(string, BC_RGBA8888);
1387 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1388 // BC_CModels::to_text(string, BC_RGB161616);
1389 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1390 // BC_CModels::to_text(string, BC_RGBA16161616);
1391 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1392 BC_CModels::to_text(string, BC_RGB_FLOAT);
1393 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1394 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1395 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1396 BC_CModels::to_text(string, BC_YUV888);
1397 colormodels.append(new ColormodelItem(string, BC_YUV888));
1398 BC_CModels::to_text(string, BC_YUVA8888);
1399 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1400 // BC_CModels::to_text(string, BC_YUV161616);
1401 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1402 // BC_CModels::to_text(string, BC_YUVA16161616);
1403 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1405 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1406 interlace_project_modes.append(new InterlacemodeItem(string, x));
1408 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1409 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1411 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1412 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1414 // Interlacing Modes
1415 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1417 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1418 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1420 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1421 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1423 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1424 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1426 // Interlacing Fixing Methods
1427 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1428 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1429 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1432 void MWindow::init_indexes()
1434 mainindexes = new MainIndexes(this);
1435 mainindexes->start_loop();
1438 void MWindow::init_gui()
1440 gui = new MWindowGUI(this);
1441 gui->lock_window("MWindow::init_gui");
1442 gui->create_objects();
1443 gui->unlock_window();
1444 gui->load_defaults(defaults);
1447 void MWindow::init_signals()
1449 sighandler = new SigHandler;
1450 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1454 void MWindow::init_render()
1456 render = new Render(this);
1457 create_bd = new CreateBD_Thread(this);
1458 create_dvd = new CreateDVD_Thread(this);
1459 batch_render = new BatchRenderThread(this);
1462 void MWindow::init_exportedl()
1464 exportedl = new ExportEDL(this);
1467 void MWindow::init_brender()
1469 if(preferences->use_brender && !brender)
1471 brender_lock->lock("MWindow::init_brender 1");
1472 brender = new BRender(this);
1473 brender->initialize();
1474 session->brender_end = 0;
1475 brender_lock->unlock();
1478 if(!preferences->use_brender && brender)
1480 brender_lock->lock("MWindow::init_brender 2");
1483 session->brender_end = 0;
1484 brender_lock->unlock();
1490 void MWindow::restart_brender()
1492 //printf("MWindow::restart_brender 1\n");
1493 if( !brender_active || !preferences->use_brender ) return;
1494 if( !brender ) return;
1495 int locked = gui->get_window_lock();
1496 if( locked ) gui->unlock_window();
1497 brender->restart(edl);
1498 if( locked ) gui->lock_window("MWindow::restart_brender");
1501 void MWindow::stop_brender()
1503 if( !brender ) return;
1504 int locked = gui->get_window_lock();
1505 if( locked ) gui->unlock_window();
1507 if( locked ) gui->lock_window("MWindow::stop_brender");
1510 int MWindow::brender_available(int position)
1513 brender_lock->lock("MWindow::brender_available 1");
1514 if(brender && brender_active)
1516 if(brender->map_valid)
1518 brender->map_lock->lock("MWindow::brender_available 2");
1519 if(position < brender->map_size &&
1522 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1523 if(brender->map[position] == BRender::RENDERED)
1526 brender->map_lock->unlock();
1529 brender_lock->unlock();
1533 void MWindow::set_brender_active(int v, int update)
1535 if( !preferences->use_brender ) v = 0;
1537 gui->mainmenu->brender_active->set_checked(v);
1539 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1540 edl->session->brender_end = edl->local_session->get_selectionend(1);
1542 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1543 edl->session->brender_end = edl->tracks->total_video_length();
1548 edl->session->brender_start = edl->session->brender_end = 0;
1552 gui->update_timebar(0);
1553 gui->draw_overlays(1);
1557 int MWindow::has_commercials()
1559 return theme->use_commercials;
1562 void MWindow::init_commercials()
1564 if( !commercials ) {
1565 commercials = new Commercials(this);
1566 commercial_active = 0;
1569 commercials->add_user();
1572 void MWindow::commit_commercial()
1574 if( !commercial_active ) return;
1575 commercial_active = 0;
1576 if( !commercials ) return;
1577 commercials->commitDb();
1580 void MWindow::undo_commercial()
1582 if( !commercial_active ) return;
1583 commercial_active = 0;
1584 if( !commercials ) return;
1585 commercials->undoDb();
1588 int MWindow::put_commercial()
1590 double start = edl->local_session->get_selectionstart();
1591 double end = edl->local_session->get_selectionend();
1592 if( start >= end ) return 0;
1594 const char *errmsg = 0;
1596 Tracks *tracks = edl->tracks;
1599 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1600 if( track->data_type != TRACK_VIDEO ) continue;
1601 if( !track->record ) continue;
1602 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1604 int64_t units_start = track->to_units(start,0);
1605 int64_t units_end = track->to_units(end,0);
1606 Edits *edits = track->edits;
1607 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1608 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1609 if(!edit1 && !edit2) continue; // nothing selected
1610 if(!edit2) { // edit2 beyond end of track
1611 edit2 = edits->last;
1612 units_end = edits->length();
1614 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1615 Indexable *indexable = edit1->get_source();
1616 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1619 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1620 if( track->data_type != TRACK_VIDEO ) continue;
1621 if( !track->record ) continue;
1622 int64_t units_start = track->to_units(start,0);
1623 int64_t units_end = track->to_units(end,0);
1624 Edits *edits = track->edits;
1625 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1626 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1627 if(!edit1 && !edit2) continue; // nothing selected
1628 if(!edit2) { // edit2 beyond end of track
1629 edit2 = edits->last;
1630 units_end = edits->length();
1632 Indexable *indexable = edit1->get_source();
1633 Asset *asset = (Asset *)indexable;
1634 File *file = video_cache->check_out(asset, edl);
1635 if( !file ) { errmsg = _("no file"); break; }
1636 int64_t edit_length = units_end - units_start;
1637 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1638 result = commercials->put_clip(file, edit1->channel,
1639 track->from_units(edit_start), track->from_units(edit_length));
1640 video_cache->check_in(asset);
1641 if( result ) { errmsg = _("db failed"); break; }
1644 char string[BCTEXTLEN];
1645 sprintf(string, _("put_commercial: %s"), errmsg);
1646 MainError::show_error(string);
1653 void MWindow::stop_playback(int wait)
1655 gui->stop_drawing();
1657 cwindow->stop_playback(wait);
1659 for(int i = 0; i < vwindows.size(); i++) {
1660 VWindow *vwindow = vwindows[i];
1661 if( !vwindow->is_running() ) continue;
1662 vwindow->stop_playback(wait);
1664 for(int i = 0; i < zwindows.size(); i++) {
1665 ZWindow *zwindow = zwindows[i];
1666 if( zwindow->idx < 0 ) continue;
1667 zwindow->stop_playback(wait);
1671 int MWindow::load_filenames(ArrayList<char*> *filenames,
1673 int update_filename)
1675 ArrayList<EDL*> new_edls;
1676 ArrayList<Asset*> new_assets;
1677 ArrayList<File*> new_files;
1678 const int debug = 0;
1679 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1682 gui->start_hourglass();
1684 // Need to stop playback since tracking depends on the EDL not getting
1686 gui->unlock_window();
1688 gui->lock_window("MWindow::load_filenames 0");
1690 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1691 undo->update_undo_before();
1694 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1696 // Define new_edls and new_assets to load
1697 int result = 0, ftype = -1;
1699 for( int i=0; i<filenames->size(); ++i ) {
1701 File *new_file = new File;
1702 Asset *new_asset = new Asset(filenames->get(i));
1703 EDL *new_edl = new EDL;
1704 char string[BCTEXTLEN];
1706 new_edl->create_objects();
1707 new_edl->copy_session(edl);
1708 new_file->set_program(edl->session->program_no);
1710 sprintf(string, _("Loading %s"), new_asset->path);
1711 gui->show_message(string);
1712 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1714 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1715 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1719 // Convert media file to EDL
1721 // Warn about odd image dimensions
1722 if( new_asset->video_data &&
1723 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1724 char string[BCTEXTLEN];
1725 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1726 new_asset->path, new_asset->width, new_asset->height);
1727 MainError::show_error(string);
1730 if( new_asset->program >= 0 &&
1731 edl->session->program_no != new_asset->program ) {
1732 char string[BCTEXTLEN];
1733 sprintf(string, _("%s's index was built for program number %d\n"
1734 "Playback preference is %d.\n Using program %d."),
1735 new_asset->path, new_asset->program,
1736 edl->session->program_no, new_asset->program);
1737 MainError::show_error(string);
1740 if( load_mode != LOADMODE_RESOURCESONLY ) {
1741 RecordLabels *labels = edl->session->label_cells ?
1742 new RecordLabels(new_file) : 0;
1743 asset_to_edl(new_edl, new_asset, labels);
1744 new_edls.append(new_edl);
1745 new_edl->add_user();
1749 new_assets.append(new_asset);
1750 new_asset->add_user();
1753 // Set filename to nothing for assets since save EDL would overwrite them.
1754 if( load_mode == LOADMODE_REPLACE ||
1755 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1757 // Reset timeline position
1758 for( int i=0; i<TOTAL_PANES; ++i ) {
1759 new_edl->local_session->view_start[i] = 0;
1760 new_edl->local_session->track_start[i] = 0;
1768 case FILE_NOT_FOUND:
1769 sprintf(string, _("Failed to open %s"), new_asset->path);
1770 gui->show_message(string, theme->message_error);
1771 gui->update_default_message();
1775 case FILE_UNRECOGNIZED_CODEC: {
1777 { IndexFile indexfile(this, new_asset);
1778 if( !(result = indexfile.open_index()) )
1779 indexfile.close_index(); }
1781 // Test existing EDLs
1782 for( int j=0; result && j<new_edls.total; ++j ) {
1783 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1785 new_asset->copy_from(old_asset,1);
1790 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1792 new_asset->copy_from(old_asset,1);
1799 char string[BCTEXTLEN];
1801 fs.extract_name(string, new_asset->path);
1803 strcat(string, _("'s format couldn't be determined."));
1804 new_asset->audio_data = 1;
1805 new_asset->format = FILE_PCM;
1806 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1807 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1808 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1809 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1810 new_asset->signed_ = defaults->get("SIGNED_", 1);
1811 new_asset->header = defaults->get("HEADER", 0);
1813 FileFormat fwindow(this);
1814 fwindow.create_objects(new_asset, string);
1815 result = fwindow.run_window();
1817 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1818 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1819 defaults->update("AUDIO_BITS", new_asset->bits);
1820 defaults->update("BYTE_ORDER", new_asset->byte_order);
1821 defaults->update("SIGNED_", new_asset->signed_);
1822 defaults->update("HEADER", new_asset->header);
1828 // Recalculate length
1830 new_file = new File;
1831 result = new_file->open_file(preferences, new_asset, 1, 0);
1833 if( load_mode != LOADMODE_RESOURCESONLY ) {
1834 RecordLabels *labels = edl->session->label_cells ?
1835 new RecordLabels(new_file) : 0;
1836 asset_to_edl(new_edl, new_asset, labels);
1837 new_edls.append(new_edl);
1838 new_edl->add_user();
1842 new_assets.append(new_asset);
1843 new_asset->add_user();
1853 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1854 xml_file.read_from_file(filenames->get(i));
1855 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1856 const char *cin_version = 0;
1857 while( !xml_file.read_tag() ) {
1858 if( xml_file.tag.title_is("EDL") ) {
1859 cin_version = xml_file.tag.get_property("VERSION");
1864 if( !cin_version ) {
1865 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1866 char string[BCTEXTLEN];
1867 sprintf(string,_("Unknown %s"), filenames->get(i));
1868 gui->show_message(string);
1872 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1873 char string[BCTEXTLEN];
1874 snprintf(string, sizeof(string),
1875 _("Warning: XML from cinelerra version %s\n"
1876 "Session data may be incompatible."), cin_version);
1877 show_warning(&preferences->warn_version, string);
1879 if( load_mode == LOADMODE_NESTED ) {
1880 // Load temporary EDL for nesting.
1881 EDL *nested_edl = new EDL;
1882 nested_edl->create_objects();
1883 nested_edl->set_path(filenames->get(i));
1884 nested_edl->load_xml(&xml_file, LOAD_ALL);
1885 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1886 edl_to_nested(new_edl, nested_edl);
1887 nested_edl->Garbage::remove_user();
1890 // Load EDL for pasting
1891 new_edl->load_xml(&xml_file, LOAD_ALL);
1892 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1893 test_plugins(new_edl, filenames->get(i));
1894 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1896 if( load_mode == LOADMODE_REPLACE ||
1897 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1898 strcpy(session->filename, filenames->get(i));
1899 strcpy(new_edl->local_session->clip_title,
1902 set_filename(new_edl->local_session->clip_title);
1904 else if( load_mode == LOADMODE_RESOURCESONLY ) {
1905 strcpy(new_edl->local_session->clip_title,
1908 time_t t = !stat(filenames->get(i),&st) ?
1909 st.st_mtime : time(&t);
1910 ctime_r(&t, new_edl->local_session->clip_notes);
1914 new_edls.append(new_edl);
1915 new_edl->add_user();
1920 new_edl->Garbage::remove_user();
1921 new_asset->Garbage::remove_user();
1923 // Store for testing index
1924 new_files.append(new_file);
1927 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1931 gui->reset_default_message();
1932 gui->default_message();
1936 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1939 // Don't back up here.
1942 // For pasting, clear the active region
1943 if(load_mode == LOADMODE_PASTE ||
1944 load_mode == LOADMODE_NESTED)
1946 double start = edl->local_session->get_selectionstart();
1947 double end = edl->local_session->get_selectionend();
1948 if(!EQUIV(start, end))
1951 edl->session->labels_follow_edits,
1952 edl->session->plugins_follow_edits,
1953 edl->session->autos_follow_edits);
1956 paste_edls(&new_edls, load_mode, 0, -1,
1957 edl->session->labels_follow_edits,
1958 edl->session->plugins_follow_edits,
1959 edl->session->autos_follow_edits,
1966 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1968 // Add new assets to EDL and schedule assets for index building.
1969 int got_indexes = 0;
1970 for(int i = 0; i < new_edls.size(); i++)
1972 EDL *new_edl = new_edls[i];
1973 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1975 mainindexes->add_next_asset(0,
1976 new_edl->nested_edls->get(j));
1978 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1983 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1984 for(int i = 0; i < new_assets.size(); i++)
1986 Asset *new_asset = new_assets[i];
1990 for(int j = 0; j < new_files.size(); j++)
1992 new_file = new_files[j];
1993 if(!strcmp(new_file->asset->path,
2001 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2003 edl->assets->update(new_asset);
2005 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2007 // Start examining next batch of index files
2008 if(got_indexes) mainindexes->start_build();
2009 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2012 Track *track = edl->tracks->first;
2015 for(int j = 0; j < track->plugin_set.size(); j++)
2017 PluginSet *plugins = track->plugin_set[j];
2018 Plugin *plugin = plugins->get_first_plugin();
2022 if(load_mode == LOADMODE_REPLACE ||
2023 load_mode == LOADMODE_REPLACE_CONCATENATE)
2025 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2028 show_plugin(plugin);
2032 plugin = (Plugin*)plugin->next;
2036 track = track->next;
2039 // if just opening one new resource in replace mode
2040 if( ftype != FILE_IS_XML &&
2041 ( load_mode == LOADMODE_REPLACE ||
2042 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2044 edl->session->proxy_scale = 1;
2045 edl->session->proxy_use_scaler = 0;
2046 edl->session->proxy_auto_scale = 0;
2047 edl->local_session->preview_start = 0;
2048 edl->local_session->preview_end = 0;
2049 edl->local_session->loop_playback = 0;
2050 edl->local_session->set_selectionstart(0);
2051 edl->local_session->set_selectionend(0);
2052 set_brender_active(0, 0);
2057 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2058 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2059 ArrayList<Indexable *> orig_idxbls;
2060 for( int i=0; i<new_assets.size(); ++i )
2061 orig_idxbls.append(new_assets.get(i));
2062 for( int i=0; i<new_edls.size(); ++i ) {
2063 EDL *new_edl = new_edls[i];
2064 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2065 if( track->data_type != TRACK_VIDEO ) continue;
2066 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2067 Indexable *idxbl = (Indexable *)edit->asset;
2068 if( !idxbl ) continue;
2069 if( !idxbl->have_video() ) continue;
2070 if( edit->channel != 0 ) continue; // first layer only
2071 orig_idxbls.append(edit->asset);
2075 gui->unlock_window(); // to update progress bar
2076 render_proxy(orig_idxbls);
2077 gui->lock_window("MWindow::load_filenames");
2080 // need to update undo before project, since mwindow is unlocked & a new load
2081 // can begin here. Should really prevent loading until we're done.
2082 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2083 undo->update_undo_after(_("load"), LOAD_ALL);
2085 for(int i = 0; i < new_edls.size(); i++)
2087 new_edls[i]->remove_user();
2089 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2091 new_edls.remove_all();
2093 for(int i = 0; i < new_assets.size(); i++)
2095 new_assets[i]->Garbage::remove_user();
2098 new_assets.remove_all();
2099 new_files.remove_all_objects();
2102 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2103 if(load_mode == LOADMODE_REPLACE ||
2104 load_mode == LOADMODE_REPLACE_CONCATENATE)
2106 session->changes_made = 0;
2110 session->changes_made = 1;
2113 gui->stop_hourglass();
2116 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2117 update_project(load_mode);
2119 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2124 void MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2126 Asset *format_asset = new Asset;
2127 format_asset->format = FILE_FFMPEG;
2128 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2129 ProxyRender proxy_render(this, format_asset);
2130 int new_scale = edl->session->proxy_scale;
2131 int use_scaler = edl->session->proxy_use_scaler;
2133 for( int i=0; i<new_idxbls.size(); ++i ) {
2134 Indexable *orig = new_idxbls.get(i);
2135 Asset *proxy = proxy_render.add_original(orig, new_scale);
2136 if( !proxy ) continue;
2138 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2139 int got_it = exists && // if proxy exists, and is newer than orig
2140 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2141 if( got_it ) continue;
2142 proxy_render.add_needed(orig, proxy);
2145 // render needed proxies
2146 int result = proxy_render.create_needed_proxies(new_scale);
2148 add_proxy(use_scaler,
2149 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2151 format_asset->remove_user();
2154 void MWindow::test_plugins(EDL *new_edl, char *path)
2156 char string[BCTEXTLEN];
2158 // Do a check weather plugins exist
2159 for(Track *track = new_edl->tracks->first; track; track = track->next)
2161 for(int k = 0; k < track->plugin_set.total; k++)
2163 PluginSet *plugin_set = track->plugin_set[k];
2164 for(Plugin *plugin = (Plugin*)plugin_set->first;
2166 plugin = (Plugin*)plugin->next)
2168 if(plugin->plugin_type == PLUGIN_STANDALONE)
2170 // ok we need to find it in plugindb
2171 int plugin_found = 0;
2173 for(int j = 0; j < plugindb->size(); j++)
2175 PluginServer *server = plugindb->get(j);
2177 !strcasecmp(server->title, plugin->title) &&
2178 ((track->data_type == TRACK_AUDIO && server->audio) ||
2179 (track->data_type == TRACK_VIDEO && server->video)) &&
2180 (!server->transition))
2187 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2188 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2189 "effect", plugin->title,
2191 MainError::show_error(string);
2197 for(Edit *edit = (Edit*)track->edits->first;
2199 edit = (Edit*)edit->next)
2201 if (edit->transition)
2203 // ok we need to find transition in plugindb
2205 int transition_found = 0;
2206 for(int j = 0; j < plugindb->size(); j++)
2208 PluginServer *server = plugindb->get(j);
2210 !strcasecmp(server->title, edit->transition->title) &&
2211 ((track->data_type == TRACK_AUDIO && server->audio) ||
2212 (track->data_type == TRACK_VIDEO && server->video)) &&
2213 (server->transition))
2214 transition_found = 1;
2217 if (!transition_found)
2220 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2221 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2222 "transition", edit->transition->title,
2224 MainError::show_error(string);
2232 void MWindow::init_shm()
2234 // Fix shared memory
2235 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
2237 fprintf(fd, "0x7fffffff");
2242 fd = fopen("/proc/sys/kernel/shmmax", "r");
2244 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
2249 fscanf(fd, "%jd", &result);
2252 if(result < 0x7fffffff) {
2253 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
2254 "you probably need to be root, or:\n"
2255 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
2256 "before trying to start cinelerra.\n"
2257 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
2261 void MWindow::create_objects(int want_gui,
2265 const int debug = 0;
2266 if(debug) PRINT_TRACE
2268 // For some reason, init_signals must come after show_splash or the signals won't
2271 if(debug) PRINT_TRACE
2274 if(debug) PRINT_TRACE
2277 if(debug) PRINT_TRACE
2278 default_standard = default_std();
2279 init_defaults(defaults, config_path);
2283 splash_window->operation->update(_("Initializing Plugins"));
2284 init_plugins(this, preferences);
2285 if(debug) PRINT_TRACE
2286 init_ladspa_plugins(this, preferences);
2287 if(debug) PRINT_TRACE
2288 init_plugin_tips(*plugindb, cin_lang);
2290 splash_window->operation->update(_("Initializing GUI"));
2291 if(debug) PRINT_TRACE
2294 if(debug) PRINT_TRACE
2298 splash_window->operation->update(_("Initializing Fonts"));
2299 char string[BCTEXTLEN];
2300 strcpy(string, preferences->plugin_dir);
2301 strcat(string, "/" FONT_SEARCHPATH);
2302 BC_Resources::init_fontconfig(string);
2303 if(debug) PRINT_TRACE
2305 // Initialize before too much else is running
2306 // Preferences & theme are required for building MPEG table of contents
2308 // Default project created here
2310 if(debug) PRINT_TRACE
2313 if(debug) PRINT_TRACE
2318 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2321 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2323 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2324 if(session->show_vwindow)
2325 get_viewer(1, DEFAULT_VWINDOW);
2326 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2329 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2332 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2335 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2338 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2341 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2344 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2349 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2350 mainprogress = new MainProgress(this, gui);
2351 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2352 undo = new MainUndo(this);
2354 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2356 plugin_guis = new ArrayList<PluginServer*>;
2357 dead_plugins = new ArrayList<PluginServer*>;
2358 keyframe_threads = new ArrayList<KeyFrameThread*>;
2360 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2363 session->show_vwindow);
2365 // Show all vwindows
2366 // if(session->show_vwindow) {
2367 // for(int j = 0; j < vwindows.size(); j++) {
2368 // VWindow *vwindow = vwindows[j];
2369 // if( !vwindow->is_running() ) continue;
2370 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2373 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2374 // vwindow->gui->lock_window("MWindow::create_objects 1");
2375 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2376 // vwindow->gui->show_window();
2377 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2378 // vwindow->gui->unlock_window();
2383 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2385 if(session->show_cwindow)
2387 cwindow->gui->lock_window("MWindow::create_objects 1");
2388 cwindow->gui->show_window();
2389 cwindow->gui->unlock_window();
2392 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2393 if(session->show_awindow)
2395 awindow->gui->lock_window("MWindow::create_objects 1");
2396 awindow->gui->show_window();
2397 awindow->gui->unlock_window();
2400 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2401 if(session->show_lwindow)
2403 lwindow->gui->lock_window("MWindow::create_objects 1");
2404 lwindow->gui->show_window();
2405 lwindow->gui->unlock_window();
2408 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2410 (int)timer.get_difference(),
2412 if(session->show_gwindow)
2414 gwindow->gui->lock_window("MWindow::create_objects 1");
2415 gwindow->gui->show_window();
2416 gwindow->gui->unlock_window();
2419 if(debug) PRINT_TRACE
2421 gui->lock_window("MWindow::create_objects 1");
2422 gui->mainmenu->load_defaults(defaults);
2423 gui->mainmenu->update_toggles(0);
2424 gui->update_patchbay();
2425 gui->draw_canvas(0, 0);
2426 gui->draw_cursor(1);
2428 gui->raise_window();
2429 gui->unlock_window();
2431 if(debug) PRINT_TRACE
2433 if(preferences->use_tipwindow)
2435 if(debug) PRINT_TRACE
2437 gui->add_keyboard_listener(
2438 (int (BC_WindowBase::*)(BC_WindowBase *))
2439 &MWindowGUI::keyboard_listener);
2443 if(debug) PRINT_TRACE
2445 BC_WindowBase::get_resources()->vframe_shm = 1;
2449 void MWindow::show_splash()
2451 #include "data/heroine_logo9_png.h"
2452 VFrame *frame = new VFramePng(heroine_logo9_png);
2453 BC_DisplayInfo dpyi;
2454 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2455 int rr = (rw < rh ? rw : rh) / 4;
2456 splash_window = new SplashGUI(frame, rr, rr);
2457 splash_window->create_objects();
2460 void MWindow::hide_splash()
2463 delete splash_window;
2468 void MWindow::start()
2472 // vwindows[DEFAULT_VWINDOW]->start();
2483 playback_3d->start();
2489 run_lock->lock("MWindow::run");
2493 brender_lock->lock("MWindow::run 1");
2494 delete brender; brender = 0;
2495 brender_lock->unlock();
2497 interrupt_indexes();
2503 void MWindow::show_vwindow()
2505 int total_running = 0;
2506 session->show_vwindow = 1;
2508 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2509 // Raise all windows which are visible
2510 for(int j = 0; j < vwindows.size(); j++) {
2511 VWindow *vwindow = vwindows[j];
2512 if( !vwindow->is_running() ) continue;
2513 vwindow->gui->lock_window("MWindow::show_vwindow");
2514 vwindow->gui->show_window(0);
2515 vwindow->gui->raise_window();
2516 vwindow->gui->flush();
2517 vwindow->gui->unlock_window();
2521 // If no windows visible
2524 get_viewer(1, DEFAULT_VWINDOW);
2527 gui->mainmenu->show_vwindow->set_checked(1);
2530 void MWindow::show_awindow()
2532 session->show_awindow = 1;
2533 awindow->gui->lock_window("MWindow::show_awindow");
2534 awindow->gui->show_window();
2535 awindow->gui->raise_window();
2536 awindow->gui->flush();
2537 awindow->gui->unlock_window();
2538 gui->mainmenu->show_awindow->set_checked(1);
2541 char *MWindow::get_cwindow_display()
2543 char *x11_host = screens < 2 || session->window_config == 0 ?
2544 session->a_x11_host : session->b_x11_host;
2545 return *x11_host ? x11_host : 0;
2548 void MWindow::show_cwindow()
2550 session->show_cwindow = 1;
2551 cwindow->show_window();
2552 gui->mainmenu->show_cwindow->set_checked(1);
2555 void MWindow::show_gwindow()
2557 session->show_gwindow = 1;
2559 gwindow->gui->lock_window("MWindow::show_gwindow");
2560 gwindow->gui->show_window();
2561 gwindow->gui->raise_window();
2562 gwindow->gui->flush();
2563 gwindow->gui->unlock_window();
2565 gui->mainmenu->show_gwindow->set_checked(1);
2567 void MWindow::hide_gwindow()
2569 session->show_gwindow = 0;
2571 gwindow->gui->lock_window("MWindow::show_gwindow");
2572 gwindow->gui->hide_window();
2573 gwindow->gui->unlock_window();
2576 void MWindow::show_lwindow()
2578 session->show_lwindow = 1;
2579 lwindow->gui->lock_window("MWindow::show_lwindow");
2580 lwindow->gui->show_window();
2581 lwindow->gui->raise_window();
2582 lwindow->gui->flush();
2583 lwindow->gui->unlock_window();
2584 gui->mainmenu->show_lwindow->set_checked(1);
2587 int MWindow::tile_windows(int window_config)
2589 int need_reload = 0;
2590 int play_config = window_config==0 ? 0 : 1;
2591 edl->session->playback_config->load_defaults(defaults, play_config);
2592 session->default_window_positions(window_config);
2593 if( screens == 1 ) {
2594 gui->default_positions();
2595 sync_parameters(CHANGE_ALL);
2602 void MWindow::toggle_loop_playback()
2604 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2605 set_loop_boundaries();
2608 gui->draw_overlays(1);
2609 sync_parameters(CHANGE_PARAMS);
2612 //void MWindow::set_titles(int value)
2614 // edl->session->show_titles = value;
2615 // trackmovement(edl->local_session->track_start);
2618 void MWindow::set_screens(int value)
2623 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2625 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2626 edl->session->auto_keyframes = value;
2627 gui->mbuttons->edit_panel->keyframe->update(value);
2629 if(lock_mwindow) gui->unlock_window();
2631 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2632 cwindow->gui->edit_panel->keyframe->update(value);
2633 cwindow->gui->flush();
2634 if(lock_cwindow) cwindow->gui->unlock_window();
2637 void MWindow::set_auto_visibility(Autos *autos, int value)
2639 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2640 edl->session->auto_conf->plugins = value;
2641 else if( autos->autoidx >= 0 )
2642 edl->session->auto_conf->autos[autos->autoidx] = value;
2646 gui->update(0, 1, 0, 0, 0, 0, 0);
2647 gui->mainmenu->update_toggles(1);
2648 gui->unlock_window();
2649 gwindow->gui->update_toggles(1);
2650 gui->lock_window("MWindow::set_auto_visibility");
2653 void MWindow::set_keyframe_type(int mode)
2655 gui->lock_window("MWindow::set_keyframe_type");
2656 edl->local_session->floatauto_type = mode;
2657 gui->mainmenu->update_toggles(0);
2658 gui->unlock_window();
2661 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2663 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2664 edl->session->editing_mode = new_editing_mode;
2665 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2666 gui->mbuttons->edit_panel->update();
2667 gui->set_editing_mode(1);
2668 if(lock_mwindow) gui->unlock_window();
2671 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2672 cwindow->gui->edit_panel->update();
2673 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2674 if(lock_cwindow) cwindow->gui->unlock_window();
2678 void MWindow::toggle_editing_mode()
2680 int mode = edl->session->editing_mode;
2681 if( mode == EDITING_ARROW )
2682 set_editing_mode(EDITING_IBEAM, 0, 1);
2684 set_editing_mode(EDITING_ARROW, 0, 1);
2688 void MWindow::set_labels_follow_edits(int value)
2690 gui->lock_window("MWindow::set_labels_follow_edits");
2691 edl->session->labels_follow_edits = value;
2692 gui->mbuttons->edit_panel->locklabels->update(value);
2693 gui->mainmenu->labels_follow_edits->set_checked(value);
2695 gui->unlock_window();
2698 void MWindow::sync_parameters(int change_type)
2700 if( in_destructor ) return;
2702 // Sync engines which are playing back
2703 if(cwindow->playback_engine->is_playing_back)
2705 if(change_type == CHANGE_PARAMS)
2707 // TODO: block keyframes until synchronization is done
2708 cwindow->playback_engine->sync_parameters(edl);
2713 int command = cwindow->playback_engine->command->command;
2714 cwindow->playback_engine->que->send_command(STOP,
2718 // Waiting for tracking to finish would make the restart position more
2719 // accurate but it can't lock the window to stop tracking for some reason.
2720 // Not waiting for tracking gives a faster response but restart position is
2721 // only as accurate as the last tracking update.
2722 cwindow->playback_engine->interrupt_playback(0);
2723 cwindow->playback_engine->que->send_command(command,
2732 cwindow->refresh_frame(change_type);
2736 void MWindow::age_caches()
2738 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2740 // preferences->cache_size,
2741 // audio_cache->get_memory_usage(1),
2742 // video_cache->get_memory_usage(1),
2743 // frame_cache->get_memory_usage(),
2744 // wave_cache->get_memory_usage(),
2746 frame_cache->age_cache(512);
2747 wave_cache->age_cache(8192);
2749 int64_t memory_usage;
2750 int64_t prev_memory_usage = 0;
2752 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2753 while( !result && prev_memory_usage !=
2754 (memory_usage=video_cache->get_memory_usage(1)) &&
2755 memory_usage > video_size ) {
2756 video_cache->delete_oldest();
2757 prev_memory_usage = memory_usage;
2760 prev_memory_usage = 0;
2762 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2763 while( !result && prev_memory_usage !=
2764 (memory_usage=audio_cache->get_memory_usage(1)) &&
2765 memory_usage > audio_size ) {
2766 audio_cache->delete_oldest();
2767 prev_memory_usage = memory_usage;
2771 void MWindow::reset_android_remote()
2773 gui->use_android_remote(preferences->android_remote);
2777 void MWindow::show_keyframe_gui(Plugin *plugin)
2779 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2780 // Find existing thread
2781 for(int i = 0; i < keyframe_threads->size(); i++)
2783 if(keyframe_threads->get(i)->plugin == plugin)
2785 keyframe_threads->get(i)->start_window(plugin, 0);
2786 keyframe_gui_lock->unlock();
2791 // Find unused thread
2792 for(int i = 0; i < keyframe_threads->size(); i++)
2794 if(!keyframe_threads->get(i)->plugin)
2796 keyframe_threads->get(i)->start_window(plugin, 0);
2797 keyframe_gui_lock->unlock();
2802 // Create new thread
2803 KeyFrameThread *thread = new KeyFrameThread(this);
2804 keyframe_threads->append(thread);
2805 thread->start_window(plugin, 0);
2807 keyframe_gui_lock->unlock();
2814 void MWindow::show_plugin(Plugin *plugin)
2819 // Remove previously deleted plugin GUIs
2820 dead_plugin_lock->lock("MWindow::show_plugin");
2821 dead_plugins->remove_all_objects();
2822 dead_plugin_lock->unlock();
2824 //printf("MWindow::show_plugin %d\n", __LINE__);
2828 plugin_gui_lock->lock("MWindow::show_plugin");
2829 for(int i = 0; i < plugin_guis->total; i++)
2831 // Pointer comparison
2832 if(plugin_guis->get(i)->plugin == plugin)
2834 plugin_guis->get(i)->raise_window();
2841 //printf("MWindow::show_plugin 1\n");
2842 if( !done && !plugin->track ) {
2843 printf("MWindow::show_plugin track not defined.\n");
2847 PluginServer *server = scan_plugindb(plugin->title,
2848 plugin->track->data_type);
2850 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2851 if(server && server->uses_gui)
2853 PluginServer *gui = new PluginServer(*server);
2854 plugin_guis->append(gui);
2855 // Needs mwindow to do GUI
2856 gui->set_mwindow(this);
2857 gui->open_plugin(0, preferences, edl, plugin);
2862 plugin_gui_lock->unlock();
2863 //printf("MWindow::show_plugin %d\n", __LINE__);
2866 //printf("MWindow::show_plugin 2\n");
2869 void MWindow::hide_plugin(Plugin *plugin, int lock)
2872 // Update the toggle
2873 gui->lock_window("MWindow::hide_plugin");
2874 gui->update(0, 1, 0, 0, 0, 0, 0);
2875 gui->unlock_window();
2877 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2878 for(int i = 0; i < plugin_guis->total; i++)
2880 if(plugin_guis->get(i)->plugin == plugin)
2882 PluginServer *ptr = plugin_guis->get(i);
2883 plugin_guis->remove(ptr);
2884 if(lock) plugin_gui_lock->unlock();
2885 // Last command executed in client side close
2886 // Schedule for deletion
2893 if(lock) plugin_gui_lock->unlock();
2896 void MWindow::delete_plugin(PluginServer *plugin)
2898 dead_plugin_lock->lock("MWindow::delete_plugin");
2899 dead_plugins->append(plugin);
2900 dead_plugin_lock->unlock();
2903 void MWindow::hide_plugins()
2905 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2906 while(plugin_guis->size())
2908 PluginServer *ptr = plugin_guis->get(0);
2909 plugin_guis->remove(ptr);
2910 plugin_gui_lock->unlock();
2911 // Last command executed in client side close
2912 // Schedule for deletion
2915 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2917 plugin_gui_lock->unlock();
2919 hide_keyframe_guis();
2922 void MWindow::hide_keyframe_guis()
2924 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2925 for(int i = 0; i < keyframe_threads->size(); i++)
2927 keyframe_threads->get(i)->close_window();
2929 keyframe_gui_lock->unlock();
2932 void MWindow::hide_keyframe_gui(Plugin *plugin)
2934 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2935 for(int i = 0; i < keyframe_threads->size(); i++)
2937 if(keyframe_threads->get(i)->plugin == plugin)
2939 keyframe_threads->get(i)->close_window();
2943 keyframe_gui_lock->unlock();
2946 void MWindow::update_keyframe_guis()
2948 // Send new configuration to keyframe GUI's
2949 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2950 for(int i = 0; i < keyframe_threads->size(); i++)
2952 KeyFrameThread *ptr = keyframe_threads->get(i);
2953 if(edl->tracks->plugin_exists(ptr->plugin))
2957 ptr->close_window();
2960 keyframe_gui_lock->unlock();
2963 void MWindow::update_plugin_guis(int do_keyframe_guis)
2965 // Send new configuration to plugin GUI's
2966 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2968 for(int i = 0; i < plugin_guis->size(); i++)
2970 PluginServer *ptr = plugin_guis->get(i);
2971 if(edl->tracks->plugin_exists(ptr->plugin))
2975 // Schedule for deletion if no plugin
2976 plugin_guis->remove_number(i);
2985 // Change plugin variable if not visible
2986 Track *track = edl->tracks->first;
2989 for(int i = 0; i < track->plugin_set.size(); i++)
2991 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2995 for(int i = 0; i < plugin_guis->size(); i++)
2997 PluginServer *server = plugin_guis->get(i);
2998 if(server->plugin == plugin)
3005 if(!got_it) plugin->show = 0;
3007 plugin = (Plugin*)plugin->next;
3011 track = track->next;
3014 plugin_gui_lock->unlock();
3017 if(do_keyframe_guis) update_keyframe_guis();
3020 int MWindow::plugin_gui_open(Plugin *plugin)
3023 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3024 for(int i = 0; i < plugin_guis->total; i++)
3026 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3032 plugin_gui_lock->unlock();
3036 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3038 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3039 for(int i = 0; i < plugin_guis->total; i++)
3041 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3043 plugin_guis->get(i)->render_gui(data);
3047 plugin_gui_lock->unlock();
3050 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3052 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3053 for(int i = 0; i < plugin_guis->total; i++)
3055 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3057 plugin_guis->get(i)->render_gui(data, size);
3061 plugin_gui_lock->unlock();
3065 void MWindow::update_plugin_states()
3067 plugin_gui_lock->lock("MWindow::update_plugin_states");
3068 for(int i = 0; i < plugin_guis->total; i++)
3072 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3073 PluginServer *src_plugingui = plugin_guis->get(i);
3075 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3076 for(Track *track = edl->tracks->first;
3078 track = track->next)
3081 j < track->plugin_set.total && !result;
3084 PluginSet *plugin_set = track->plugin_set[j];
3085 for(Plugin *plugin = (Plugin*)plugin_set->first;
3087 plugin = (Plugin*)plugin->next)
3089 if(plugin == src_plugin &&
3090 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3096 // Doesn't exist anymore
3099 hide_plugin(src_plugin, 0);
3103 plugin_gui_lock->unlock();
3107 void MWindow::update_plugin_titles()
3109 for(int i = 0; i < plugin_guis->total; i++)
3111 plugin_guis->get(i)->update_title();
3115 int MWindow::asset_to_edl(EDL *new_edl,
3117 RecordLabels *labels)
3119 const int debug = 0;
3120 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3123 // Keep frame rate, sample rate, and output size unchanged.
3124 // These parameters would revert the project if VWindow displayed an asset
3125 // of different size than the project.
3126 if(new_asset->video_data)
3128 new_edl->session->video_tracks = new_asset->layers;
3131 new_edl->session->video_tracks = 0;
3133 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3139 if(new_asset->audio_data)
3141 new_edl->session->audio_tracks = new_asset->channels;
3144 new_edl->session->audio_tracks = 0;
3145 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3147 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3148 new_edl->create_default_tracks();
3149 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3150 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3154 //printf("MWindow::asset_to_edl 3\n");
3155 new_edl->insert_asset(new_asset,
3160 //printf("MWindow::asset_to_edl 3\n");
3161 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3163 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3164 if(edl->session->cursor_on_frames)
3166 double length = new_edl->tracks->total_length();
3167 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3168 new_edl->tracks->clear(length, edl_length, 1, 1);
3174 char string[BCTEXTLEN];
3176 fs.extract_name(string, new_asset->path);
3177 //printf("MWindow::asset_to_edl 3\n");
3179 strcpy(new_edl->local_session->clip_title, string);
3180 //printf("MWindow::asset_to_edl 4 %s\n", string);
3181 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3186 int MWindow::edl_to_nested(EDL *new_edl,
3190 // Keep frame rate, sample rate, and output size unchanged.
3191 // These parameters would revert the project if VWindow displayed an asset
3192 // of different size than the project.
3196 // Nest all video & audio outputs
3197 new_edl->session->video_tracks = 1;
3198 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
3199 new_edl->create_default_tracks();
3203 new_edl->insert_asset(0,
3209 char string[BCTEXTLEN];
3211 fs.extract_name(string, nested_edl->path);
3212 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
3214 strcpy(new_edl->local_session->clip_title, string);
3219 // Reset everything after a load.
3220 void MWindow::update_project(int load_mode)
3222 const int debug = 0;
3224 if(debug) PRINT_TRACE
3226 edl->tracks->update_y_pixels(theme);
3228 if(debug) PRINT_TRACE
3230 if(load_mode == LOADMODE_REPLACE ||
3231 load_mode == LOADMODE_REPLACE_CONCATENATE)
3236 gui->update(1, 1, 1, 1, 1, 1, 1);
3237 if(debug) PRINT_TRACE
3238 gui->unlock_window();
3240 cwindow->gui->lock_window("MWindow::update_project 1");
3241 cwindow->update(0, 0, 1, 1, 1);
3242 cwindow->gui->unlock_window();
3244 if(debug) PRINT_TRACE
3246 // Close all the vwindows
3247 if( load_mode == LOADMODE_REPLACE ||
3248 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3249 if(debug) PRINT_TRACE
3250 int first_vwindow = 0;
3251 if(session->show_vwindow) first_vwindow = 1;
3252 // Change visible windows to no source
3253 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3254 VWindow *vwindow = vwindows[i];
3255 if( !vwindow->is_running() ) continue;
3256 vwindow->change_source(-1);
3259 // Close remaining windows
3260 for(int i = first_vwindow; i < vwindows.size(); i++) {
3261 VWindow *vwindow = vwindows[i];
3262 if( !vwindow->is_running() ) continue;
3263 vwindow->close_window();
3265 if(debug) PRINT_TRACE
3269 for( int i=0; i<edl->mixers.size(); ++i ) {
3270 Mixer *mixer = edl->mixers[i];
3271 ZWindow *zwindow = get_mixer(mixer);
3272 zwindow->set_title(mixer->title);
3277 if(vwindows.size()) {
3278 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3279 if( vwindow->is_running() ) {
3280 vwindow->gui->lock_window("MWindow::update_project");
3282 vwindow->gui->unlock_window();
3287 if(debug) PRINT_TRACE
3288 cwindow->gui->lock_window("MWindow::update_project 2");
3289 cwindow->gui->timebar->update(0);
3290 cwindow->gui->unlock_window();
3292 if(debug) PRINT_TRACE
3293 cwindow->refresh_frame(CHANGE_ALL);
3295 awindow->gui->async_update_assets();
3296 if(debug) PRINT_TRACE
3298 gui->lock_window("MWindow::update_project");
3299 gui->update_mixers(0, 0);
3301 if(debug) PRINT_TRACE
3304 void MWindow::remove_indexfile(Indexable *indexable)
3306 if( !indexable->is_asset ) return;
3307 Asset *asset = (Asset *)indexable;
3309 IndexFile::delete_index(preferences, asset, ".toc");
3310 IndexFile::delete_index(preferences, asset, ".idx");
3311 IndexFile::delete_index(preferences, asset, ".mkr");
3314 void MWindow::rebuild_indices()
3316 for(int i = 0; i < session->drag_assets->total; i++)
3318 Indexable *indexable = session->drag_assets->get(i);
3319 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3320 remove_indexfile(indexable);
3321 // Schedule index build
3322 IndexState *index_state = indexable->index_state;
3323 index_state->index_status = INDEX_NOTTESTED;
3324 if( indexable->is_asset ) {
3325 Asset *asset = (Asset *)indexable;
3326 if( asset->format != FILE_PCM ) {
3327 asset->format = FILE_UNKNOWN;
3328 asset->reset_audio();
3330 asset->reset_video();
3331 remove_asset_from_caches(asset);
3332 // File file; // re-probe the asset
3333 // file.open_file(preferences, asset, 1, 0);
3335 mainindexes->add_next_asset(0, indexable);
3337 mainindexes->start_build();
3341 void MWindow::save_backup()
3345 edl->set_path(session->filename);
3346 char backup_path[BCTEXTLEN];
3347 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3348 File::get_config_path(), BACKUP_FILE);
3349 edl->save_xml(&file, backup_path, 0, 0);
3350 file.terminate_string();
3352 fs.complete_path(backup_path);
3354 if(file.write_to_file(backup_path))
3357 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3358 gui->show_message(string2);
3362 void MWindow::load_backup()
3364 ArrayList<char*> path_list;
3365 path_list.set_array_delete();
3367 char backup_path[BCTEXTLEN];
3368 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3369 File::get_config_path(), BACKUP_FILE);
3371 fs.complete_path(backup_path);
3373 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3374 strcpy(out_path, backup_path);
3376 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3377 edl->local_session->clip_title[0] = 0;
3378 // This is unique to backups since the path of the backup is different than the
3379 // path of the project.
3380 set_filename(edl->path);
3381 path_list.remove_all_objects();
3385 static inline int gcd(int m, int n)
3388 if( m < n ) { r = m; m = n; n = r; }
3389 while( (r = m % n) != 0 ) { m = n; n = r; }
3393 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3396 if(!width || !height) return 1;
3397 if( width == 720 && (height == 480 || height == 576) ) {
3398 w = 4; h = 3; return 0; // for NTSC and PAL
3400 double ar = (double)width / height;
3401 // square-ish pixels
3402 if( EQUIV(ar, 1.0000) ) return 0;
3403 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3404 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3405 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3406 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3407 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3408 int ww = width, hh = height;
3409 // numerator, denominator must be under mx
3410 int mx = 255, n = gcd(ww, hh);
3411 if( n > 1 ) { ww /= n; hh /= n; }
3412 // search near height in case extra/missing lines
3413 if( ww >= mx || hh >= mx ) {
3414 double err = height; // +/- 2 percent height
3415 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3416 int iw = width, ih = height+i;
3417 if( (n=gcd(iw, ih)) > 1 ) {
3418 int u = iw/n; if( u >= mx ) continue;
3419 int v = ih/n; if( v >= mx ) continue;
3420 double r = (double) u/v, er = fabs(ar-r);
3421 if( er >= err ) continue;
3422 err = er; ww = u; hh = v;
3431 void MWindow::reset_caches()
3433 frame_cache->remove_all();
3434 wave_cache->remove_all();
3435 audio_cache->remove_all();
3436 video_cache->remove_all();
3437 if( cwindow->playback_engine ) {
3438 if( cwindow->playback_engine->audio_cache )
3439 cwindow->playback_engine->audio_cache->remove_all();
3440 if( cwindow->playback_engine->video_cache )
3441 cwindow->playback_engine->video_cache->remove_all();
3443 for(int i = 0; i < vwindows.size(); i++) {
3444 VWindow *vwindow = vwindows[i];
3445 if( !vwindow->is_running() ) continue;
3446 if( !vwindow->playback_engine ) continue;
3447 if( vwindow->playback_engine->audio_cache )
3448 vwindow->playback_engine->audio_cache->remove_all();
3449 if( vwindow->playback_engine->video_cache )
3450 vwindow->playback_engine->video_cache->remove_all();
3454 void MWindow::remove_asset_from_caches(Asset *asset)
3456 frame_cache->remove_asset(asset);
3457 wave_cache->remove_asset(asset);
3458 audio_cache->delete_entry(asset);
3459 video_cache->delete_entry(asset);
3460 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3461 cwindow->playback_engine->audio_cache->delete_entry(asset);
3462 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3463 cwindow->playback_engine->video_cache->delete_entry(asset);
3464 for(int i = 0; i < vwindows.size(); i++) {
3465 VWindow *vwindow = vwindows[i];
3466 if( !vwindow->is_running() ) continue;
3467 if( !vwindow->playback_engine ) continue;
3468 if( vwindow->playback_engine->audio_cache )
3469 vwindow->playback_engine->audio_cache->delete_entry(asset);
3470 if( vwindow->playback_engine->video_cache )
3471 vwindow->playback_engine->video_cache->delete_entry(asset);
3476 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3477 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3479 for(int i = 0; i < drag_assets->total; i++) {
3480 Indexable *indexable = drag_assets->get(i);
3481 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3484 // Remove from VWindow.
3485 for(int i = 0; i < session->drag_clips->total; i++) {
3486 for(int j = 0; j < vwindows.size(); j++) {
3487 VWindow *vwindow = vwindows[j];
3488 if( !vwindow->is_running() ) continue;
3489 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3490 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3491 vwindow->delete_source(1, 1);
3492 vwindow->gui->unlock_window();
3497 for(int i = 0; i < drag_assets->size(); i++) {
3498 for(int j = 0; j < vwindows.size(); j++) {
3499 VWindow *vwindow = vwindows[j];
3500 if( !vwindow->is_running() ) continue;
3501 if(drag_assets->get(i) == vwindow->get_source()) {
3502 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3503 vwindow->delete_source(1, 1);
3504 vwindow->gui->unlock_window();
3509 for(int i = 0; i < drag_assets->size(); i++) {
3510 Indexable *indexable = drag_assets->get(i);
3511 remove_indexfile(indexable);
3514 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3515 if(push_undo) undo->update_undo_before();
3516 if(drag_assets) edl->remove_from_project(drag_assets);
3517 if(drag_clips) edl->remove_from_project(drag_clips);
3518 if(redraw) save_backup();
3519 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3523 gui->lock_window("MWindow::remove_assets_from_project 3");
3524 gui->update(1, 1, 1, 1, 0, 1, 0);
3525 gui->unlock_window();
3527 // Removes from playback here
3528 sync_parameters(CHANGE_ALL);
3531 awindow->gui->async_update_assets();
3534 void MWindow::remove_assets_from_disk()
3537 for(int i = 0; i < session->drag_assets->total; i++)
3539 remove(session->drag_assets->get(i)->path);
3542 remove_assets_from_project(1,
3544 session->drag_assets,
3545 session->drag_clips);
3548 void MWindow::dump_plugins(FILE *fp)
3550 if( !plugindb ) return;
3551 for(int i = 0; i < plugindb->total; i++)
3553 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3554 " synth=%d transition=%d theme=%d %s\n",
3555 plugindb->get(i)->plugin_type,
3556 plugindb->get(i)->audio,
3557 plugindb->get(i)->video,
3558 plugindb->get(i)->realtime,
3559 plugindb->get(i)->multichannel,
3560 plugindb->get(i)->get_synthesis(),
3561 plugindb->get(i)->transition,
3562 plugindb->get(i)->theme,
3563 plugindb->get(i)->title);
3567 void MWindow::dump_edl(FILE *fp)
3573 void MWindow::dump_undo(FILE *fp)
3579 void MWindow::dump_exe(FILE *fp)
3581 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3582 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3584 int ret = -1, n = 100;
3585 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3586 exe_path[len] = 0; strcpy(proc_path, exe_path);
3589 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3592 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3593 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3594 struct tm *tm = localtime(&st.st_mtime);
3596 strftime(mtime, sizeof(mtime), "%F %T", tm);
3597 fprintf(fp,"mtime: %s\n", mtime);
3599 // people hit ctl-c waiting for this
3600 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3601 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3604 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3605 int64_t maxsz = 1024*pagsz;
3606 int64_t size = st.st_size, pos = 0;
3608 while( (bfrsz = size-pos) > 0 ) {
3609 if( bfrsz > maxsz ) bfrsz = maxsz;
3610 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3611 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3612 if( bfr == MAP_FAILED ) break;
3613 sha1.addBytes(bfr, bfrsz);
3618 ret = pos < size ? EIO : 0;
3619 fprintf(fp, "SHA1: ");
3620 uint8_t digest[20]; sha1.computeHash(digest);
3621 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3622 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3623 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3628 void MWindow::trap_hook(FILE *fp, void *vp)
3630 MWindow *mwindow = (MWindow *)vp;
3631 // fprintf(fp, "\nPLUGINS:\n");
3632 // mwindow->dump_plugins(fp);
3633 fprintf(fp, "\nEDL:\n");
3634 mwindow->dump_edl(fp);
3635 fprintf(fp, "\nUNDO:\n");
3636 mwindow->dump_undo(fp);
3637 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
3638 mwindow->dump_exe(fp);
3646 int MWindow::save_defaults()
3648 gui->save_defaults(defaults);
3649 edl->save_defaults(defaults);
3650 session->save_defaults(defaults);
3651 preferences->save_defaults(defaults);
3653 for(int i = 0; i < plugin_guis->total; i++)
3655 // Pointer comparison
3656 plugin_guis->get(i)->save_defaults();
3658 awindow->save_defaults(defaults);
3664 int MWindow::run_script(FileXML *script)
3666 int result = 0, result2 = 0;
3667 while(!result && !result2)
3669 result = script->read_tag();
3672 if(script->tag.title_is("new_project"))
3674 // Run new in immediate mode.
3675 // gui->mainmenu->new_project->run_script(script);
3678 if(script->tag.title_is("record"))
3680 // Run record as a thread. It is a terminal command.
3682 // Will read the complete scipt file without letting record read it if not
3688 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3695 // ================================= synchronization
3698 int MWindow::interrupt_indexes()
3700 mainprogress->cancelled = 1;
3701 mainindexes->interrupt_build();
3707 void MWindow::next_time_format()
3709 switch(edl->session->time_format)
3711 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3712 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3713 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3714 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3715 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3716 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3717 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3720 time_format_common();
3723 void MWindow::prev_time_format()
3725 switch(edl->session->time_format)
3727 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3728 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3729 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3730 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3731 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3732 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3733 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3736 time_format_common();
3739 void MWindow::time_format_common()
3741 gui->lock_window("MWindow::next_time_format");
3742 gui->redraw_time_dependancies();
3745 char string[BCTEXTLEN], string2[BCTEXTLEN];
3746 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3747 gui->show_message(string);
3749 gui->unlock_window();
3753 int MWindow::set_filename(const char *filename)
3755 if( filename != session->filename )
3756 strcpy(session->filename, filename);
3757 if( filename != edl->path )
3758 strcpy(edl->path, filename);
3762 if(filename[0] == 0)
3764 gui->set_title(PROGRAM_NAME);
3769 char string[BCTEXTLEN], string2[BCTEXTLEN];
3770 dir.extract_name(string, filename);
3771 sprintf(string2, PROGRAM_NAME ": %s", string);
3772 gui->set_title(string2);
3785 int MWindow::set_loop_boundaries()
3787 double start = edl->local_session->get_selectionstart();
3788 double end = edl->local_session->get_selectionend();
3796 if(edl->tracks->total_length())
3799 end = edl->tracks->total_length();
3806 if(edl->local_session->loop_playback && start != end)
3808 edl->local_session->loop_start = start;
3809 edl->local_session->loop_end = end;
3820 int MWindow::reset_meters()
3822 cwindow->gui->lock_window("MWindow::reset_meters 1");
3823 cwindow->gui->meters->reset_meters();
3824 cwindow->gui->unlock_window();
3826 for(int j = 0; j < vwindows.size(); j++) {
3827 VWindow *vwindow = vwindows[j];
3828 if( !vwindow->is_running() ) continue;
3829 vwindow->gui->lock_window("MWindow::reset_meters 2");
3830 vwindow->gui->meters->reset_meters();
3831 vwindow->gui->unlock_window();
3834 lwindow->gui->lock_window("MWindow::reset_meters 3");
3835 lwindow->gui->panel->reset_meters();
3836 lwindow->gui->unlock_window();
3838 gui->lock_window("MWindow::reset_meters 4");
3839 gui->reset_meters();
3840 gui->unlock_window();
3845 void MWindow::resync_guis()
3849 gui->lock_window("MWindow::resync_guis");
3850 gui->update(1, 1, 1, 1, 1, 1, 0);
3851 gui->unlock_window();
3853 cwindow->gui->lock_window("MWindow::resync_guis");
3854 cwindow->gui->resize_event(cwindow->gui->get_w(),
3855 cwindow->gui->get_h());
3856 int channels = edl->session->audio_channels;
3857 cwindow->gui->meters->set_meters(channels, 1);
3858 cwindow->gui->flush();
3859 cwindow->gui->unlock_window();
3861 for(int i = 0; i < vwindows.size(); i++) {
3862 VWindow *vwindow = vwindows[i];
3863 if( !vwindow->is_running() ) continue;
3864 vwindow->gui->lock_window("MWindow::resync_guis");
3865 vwindow->gui->resize_event(vwindow->gui->get_w(),
3866 vwindow->gui->get_h());
3867 vwindow->gui->meters->set_meters(channels, 1);
3868 vwindow->gui->flush();
3869 vwindow->gui->unlock_window();
3872 lwindow->gui->lock_window("MWindow::resync_guis");
3873 lwindow->gui->panel->set_meters(channels, 1);
3874 lwindow->gui->flush();
3875 lwindow->gui->unlock_window();
3878 if(((edl->session->output_w % 4) ||
3879 (edl->session->output_h % 4)) &&
3880 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3882 MainError::show_error(
3883 _("This project's dimensions are not multiples of 4 so\n"
3884 "it can't be rendered by OpenGL."));
3889 sync_parameters(CHANGE_ALL);
3892 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3894 File *file = new File;
3895 EDLSession *session = edl->session;
3896 double old_framerate = session->frame_rate;
3897 double old_samplerate = session->sample_rate;
3898 int old_auto_keyframes = session->auto_keyframes;
3899 session->auto_keyframes = 0;
3900 int result = file->open_file(preferences, asset, 1, 0);
3901 if( !result && delete_tracks > 0 )
3902 undo->update_undo_before();
3903 int video_layers = asset->get_video_layers();
3904 if( !result && asset->video_data && vstream < video_layers ) {
3905 // try to get asset up to date, may fail
3906 file->select_video_stream(asset, vstream);
3907 // either way use what was/is there.
3908 double framerate = asset->get_frame_rate();
3909 int width = asset->get_w();
3910 int height = asset->get_h();
3911 // must be multiple of 4 for opengl
3912 width = (width+3) & ~3; height = (height+3) & ~3;
3913 int driver = session->playback_config->vconfig->driver;
3914 int color_model = file->get_best_colormodel(asset, driver);
3915 // color_model = BC_CModels::is_yuv(color_model) ?
3916 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3917 // BC_CModels::is_float(color_model) ?
3918 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3919 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3920 // have alpha for now
3921 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3922 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3923 session->color_model = color_model;
3924 session->output_w = width;
3925 session->output_h = height;
3926 session->frame_rate = framerate;
3927 // not, asset->actual_width/actual_height
3928 asset->width = session->output_w;
3929 asset->height = session->output_h;
3930 asset->frame_rate = session->frame_rate;
3931 create_aspect_ratio(session->aspect_w, session->aspect_h,
3932 session->output_w, session->output_h);
3933 Track *track = edl->tracks->first;
3934 for( Track *next_track=0; track; track=next_track ) {
3935 next_track = track->next;
3936 if( track->data_type != TRACK_VIDEO ) continue;
3937 if( delete_tracks ) {
3938 Edit *edit = track->edits->first;
3939 for( Edit *next_edit=0; edit; edit=next_edit ) {
3940 next_edit = edit->next;
3941 if( edit->channel != vstream ||
3942 !edit->asset || !edit->asset->is_asset ||
3943 !asset->equivalent(*edit->asset,1,1,edl) )
3947 if( track->edits->first ) {
3948 track->track_w = edl->session->output_w;
3949 track->track_h = edl->session->output_h;
3951 else if( delete_tracks )
3952 edl->tracks->delete_track(track);
3955 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3957 if( !result && asset->audio_data && asset->channels > 0 ) {
3958 session->sample_rate = asset->get_sample_rate();
3959 int64_t channel_mask = 0;
3960 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
3961 file->get_audio_for_video(vstream, astream, channel_mask);
3962 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3963 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3965 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3966 if( channels < 1 ) channels = 1;
3967 if( channels > 6 ) channels = 6;
3968 session->audio_tracks = session->audio_channels = channels;
3969 switch( channels ) {
3971 session->achannel_positions[0] = 90;
3972 session->achannel_positions[1] = 150;
3973 session->achannel_positions[2] = 30;
3974 session->achannel_positions[3] = 210;
3975 session->achannel_positions[4] = 330;
3976 session->achannel_positions[5] = 270;
3979 session->achannel_positions[0] = 180;
3980 session->achannel_positions[1] = 0;
3983 session->achannel_positions[1] = 90;
3986 if( !channels ) break;
3987 double t = 0, dt = 360./channels;
3988 for( int i=channels; --i>=0; t+=dt )
3989 session->achannel_positions[i] = int(t+0.5);
3992 remap_audio(MWindow::AUDIO_1_TO_1);
3994 if( delete_tracks ) {
3995 Track *track = edl->tracks->first;
3996 for( Track *next_track=0; track; track=next_track ) {
3997 next_track = track->next;
3998 if( track->data_type != TRACK_AUDIO ) continue;
3999 Edit *edit = track->edits->first;
4000 for( Edit *next_edit=0; edit; edit=next_edit ) {
4001 next_edit = edit->next;
4002 if( !((1<<edit->channel) & channel_mask) ||
4003 !edit->asset || !edit->asset->is_asset ||
4004 !asset->equivalent(*edit->asset,1,1,edl) )
4007 if( !track->edits->first )
4008 edl->tracks->delete_track(track);
4012 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4015 session->auto_keyframes = old_auto_keyframes;
4016 if( !result && delete_tracks > 0 ) {
4018 undo->update_undo_after(_("select asset"), LOAD_ALL);
4024 int MWindow::select_asset(int vtrack, int delete_tracks)
4026 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4028 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4029 if( !track ) return 1;
4030 Edit *edit = track->edits->first;
4031 if( !edit ) return 1;
4032 Asset *asset = edit->asset;
4033 if( !asset || !asset->is_asset ) return 1;
4034 return select_asset(asset, edit->channel, 0, delete_tracks);
4037 void MWindow::dump_plugindb(FILE *fp)
4039 if( !plugindb ) return;
4040 for(int i = 0; i < plugindb->total; i++)
4041 plugindb->get(i)->dump(fp);
4044 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4047 double unit_position = edl->local_session->get_selectionstart(1);
4048 unit_position = patch->track->to_units(unit_position, 0);
4050 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4051 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4054 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4057 double unit_position = edl->local_session->get_selectionstart(1);
4058 unit_position = patch->track->to_units(unit_position, 0);
4060 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4061 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4064 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4067 double unit_position = edl->local_session->get_selectionstart(1);
4068 unit_position = patch->track->to_units(unit_position, 0);
4070 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4071 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4074 PatchGUI *MWindow::get_patchgui(Track *track)
4076 PatchGUI *patchgui = 0;
4077 TimelinePane **panes = gui->pane;
4078 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4079 if( !panes[i] ) continue;
4080 PatchBay *patchbay = panes[i]->patchbay;
4081 if( !patchbay ) continue;
4082 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4083 if( patchbay->patches.values[j]->track == track )
4084 patchgui = patchbay->patches.values[j];