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;
909 void MWindow::clean_indexes()
914 int oldest_item = -1;
916 char string[BCTEXTLEN];
917 char string2[BCTEXTLEN];
919 // Delete extra indexes
920 fs.set_filter("*.idx");
921 fs.complete_path(preferences->index_directory);
922 fs.update(preferences->index_directory);
923 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
925 // Eliminate directories
930 for(int i = 0; i < fs.dir_list.total && !result; i++)
932 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
933 if(fs.is_dir(string))
935 delete fs.dir_list[i];
936 fs.dir_list.remove_number(i);
941 total_excess = fs.dir_list.total - preferences->index_count;
943 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
944 while(total_excess > 0)
947 for(int i = 0; i < fs.dir_list.total; i++)
949 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
951 if(i == 0 || fs.get_date(string) <= oldest)
953 oldest = fs.get_date(string);
961 fs.join_names(string,
962 preferences->index_directory,
963 fs.dir_list[oldest_item]->name);
964 //printf("MWindow::clean_indexes 1 %s\n", string);
966 perror("delete_indexes");
967 delete fs.dir_list[oldest_item];
968 fs.dir_list.remove_number(oldest_item);
970 // Remove table of contents if it exists
971 strcpy(string2, string);
972 char *ptr = strrchr(string2, '.');
975 //printf("MWindow::clean_indexes 2 %s\n", string2);
976 sprintf(ptr, ".toc");
978 sprintf(ptr, ".mkr");
987 void MWindow::init_awindow()
989 awindow = new AWindow(this);
990 awindow->create_objects();
993 void MWindow::init_gwindow()
995 gwindow = new GWindow(this);
996 gwindow->create_objects();
999 void MWindow::init_tipwindow()
1001 TipWindow::load_tips(cin_lang);
1003 twindow = new TipWindow(this);
1007 void MWindow::show_warning(int *do_warning, const char *text)
1009 if( do_warning && !*do_warning ) return;
1011 wwindow = new WWindow(this);
1012 wwindow->show_warning(do_warning, text);
1015 int MWindow::wait_warning()
1017 return wwindow->wait_result();
1020 void MWindow::init_theme()
1025 PluginServer *theme_plugin = 0;
1026 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1027 if( plugindb->get(i)->theme &&
1028 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1029 theme_plugin = plugindb->get(i);
1033 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1034 preferences->theme);
1036 const char *default_theme = _(DEFAULT_THEME);
1037 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1038 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1040 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1041 if( plugindb->get(i)->theme &&
1042 !strcasecmp(default_theme, plugindb->get(i)->title) )
1043 theme_plugin = plugindb->get(i);
1048 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1052 PluginServer *plugin = new PluginServer(*theme_plugin);
1053 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1054 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1055 theme_plugin->title);
1059 theme = plugin->new_theme();
1060 theme->mwindow = this;
1061 strcpy(theme->path, plugin->path);
1064 // Load default images & settings
1065 theme->Theme::initialize();
1066 // Load user images & settings
1067 theme->initialize();
1068 // Create menus with user colors
1069 theme->build_menus();
1072 theme->sort_image_sets();
1073 theme->check_used();
1074 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1077 void MWindow::init_3d()
1079 playback_3d = new Playback3D(this);
1080 playback_3d->create_objects();
1083 void MWindow::init_edl()
1086 edl->create_objects();
1087 fill_preset_defaults(default_standard, edl->session);
1088 edl->load_defaults(defaults);
1089 edl->session->brender_start = edl->session->brender_end = 0;
1090 edl->create_default_tracks();
1091 edl->tracks->update_y_pixels(theme);
1094 void MWindow::init_compositor()
1096 cwindow = new CWindow(this);
1097 cwindow->create_objects();
1100 void MWindow::init_levelwindow()
1102 lwindow = new LevelWindow(this);
1103 lwindow->create_objects();
1106 VWindow *MWindow::get_viewer(int start_it, int idx)
1108 vwindows_lock->lock("MWindow::get_viewer");
1109 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1110 if( !vwindow ) idx = vwindows.size();
1111 while( !vwindow && --idx >= 0 ) {
1112 VWindow *vwin = vwindows[idx];
1113 if( !vwin->is_running() || !vwin->get_edl() )
1117 vwindow = new VWindow(this);
1118 vwindow->load_defaults();
1119 vwindow->create_objects();
1120 vwindows.append(vwindow);
1122 vwindows_lock->unlock();
1123 if( start_it ) vwindow->start();
1127 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1129 zwindows_lock->lock("MWindow::get_mixer");
1130 if( !mixer ) mixer = edl->mixers.new_mixer();
1131 ZWindow *zwindow = 0;
1132 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1133 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1135 zwindows.append(zwindow = new ZWindow(this));
1136 zwindow->idx = mixer->idx;
1137 zwindows_lock->unlock();
1141 void MWindow::del_mixer(ZWindow *zwindow)
1143 zwindows_lock->lock("MWindow::del_mixer 0");
1144 edl->mixers.del_mixer(zwindow->idx);
1146 if( session->selected_zwindow >= 0 ) {
1147 int i = zwindows.number_of(zwindow);
1148 if( i >= 0 && i < session->selected_zwindow )
1149 --session->selected_zwindow;
1150 else if( i == session->selected_zwindow )
1151 session->selected_zwindow = -1;
1153 zwindows_lock->unlock();
1154 gui->lock_window("MWindow::del_mixer 1");
1155 gui->update_mixers(0, -1);
1156 gui->unlock_window();
1159 void MWindow::start_mixer()
1162 ZWindow *zwindow = get_mixer(mixer);
1163 const char *title = 0;
1165 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1166 PatchGUI *patchgui = get_patchgui(track);
1167 if( !patchgui || !patchgui->mixer ) continue;
1168 mixer->mixer_ids.append(track->get_mixer_id());
1169 if( !title ) title = track->title;
1172 session->selected_zwindow = -1;
1173 gui->lock_window("MWindow::start_mixer");
1174 gui->update_mixers(0, 0);
1175 gui->unlock_window();
1177 zwindow->set_title(title);
1182 int MWindow::mixer_track_active(Track *track)
1184 int i = session->selected_zwindow;
1185 if( i < 0 || i >= zwindows.size() ) return 0;
1186 ZWindow *zwindow = zwindows[i];
1187 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1188 if( !mixer ) return 0;
1189 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1190 return n >= 0 ? 1 : 0;
1193 void MWindow::update_mixer_tracks()
1195 zwindows_lock->lock("MixPatch::handle_event");
1196 int i = session->selected_zwindow;
1197 if( i >= 0 && i < zwindows.size() ) {
1198 ZWindow *zwindow = zwindows[i];
1199 zwindow->update_mixer_ids();
1201 zwindows_lock->unlock();
1204 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1205 int use_inout, int update_refresh, int toggle_audio)
1207 zwindows_lock->lock("MWindow::queue_mixers");
1208 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1209 ZWindow *zwindow = zwindows[vidx];
1210 if( zwindow->idx < 0 ) continue;
1211 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1212 if( !mixer || !mixer->mixer_ids.size() ) continue;
1214 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1215 if( track->data_type != TRACK_VIDEO ) continue;
1216 int mixer_id = track->get_mixer_id();
1217 k = mixer->mixer_ids.size();
1218 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1220 if( k < 0 ) continue;
1221 EDL *mixer_edl = new EDL(this->edl);
1222 mixer_edl->create_objects();
1223 mixer_edl->copy_all(edl);
1224 mixer_edl->remove_vwindow_edls();
1225 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1226 k = mixer->mixer_ids.size();
1227 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1230 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1233 track->record = track->play = 0;
1235 zwindow->change_source(mixer_edl);
1236 zwindow->issue_command(command,
1237 wait_tracking, use_inout, update_refresh, toggle_audio);
1239 zwindows_lock->unlock();
1242 void MWindow::refresh_mixers()
1244 queue_mixers(edl,CURRENT_FRAME,0,0,1,0);
1247 void MWindow::stop_mixers()
1249 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1250 ZWindow *zwindow = zwindows[vidx];
1251 if( zwindow->idx < 0 ) continue;
1252 zwindow->issue_command(STOP, 0, 0, 0, 0);
1256 void MWindow::close_mixers()
1258 zwindows_lock->lock("MWindow::close_mixers");
1259 for( int i=0; i<zwindows.size(); ++i ) {
1260 ZWindow *zwindow = zwindows[i];
1261 if( zwindow->idx < 0 ) continue;
1262 ZWindowGUI *zgui = zwindow->zgui;
1263 zgui->lock_window("MWindow::select_zwindow 0");
1265 zgui->unlock_window();
1267 zwindows_lock->unlock();
1268 for( int i=0; i<zwindows.size(); ++i ) {
1269 ZWindow *zwindow = zwindows[i];
1270 if( zwindow->idx < 0 ) continue;
1271 zwindow->close_window();
1275 void MWindow::open_mixers()
1277 for( int i=0; i<edl->mixers.size(); ++i ) {
1278 Mixer *mixer = edl->mixers[i];
1279 ZWindow *zwindow = get_mixer(mixer);
1280 zwindow->set_title(mixer->title);
1286 int MWindow::select_zwindow(ZWindow *zwindow)
1288 int ret = 0, n = zwindows.number_of(zwindow);
1289 if( session->selected_zwindow != n ) {
1290 session->selected_zwindow = n;
1291 for( int i=0; i<zwindows.size(); ++i ) {
1292 ZWindow *zwindow = zwindows[i];
1293 if( zwindow->idx < 0 ) continue;
1294 ZWindowGUI *zgui = zwindow->zgui;
1295 zgui->lock_window("MWindow::select_zwindow 0");
1296 zwindow->highlighted = i == n ? 1 : 0;
1297 if( zgui->draw_overlays() )
1298 zgui->canvas->get_canvas()->flash(1);
1299 zgui->unlock_window();
1302 gui->lock_window("MWindow::select_window 1");
1303 gui->update_mixers(0, -1);
1304 gui->unlock_window();
1309 void MWindow::tile_mixers()
1312 for( int i=0; i<zwindows.size(); ++i ) {
1313 ZWindow *zwindow = zwindows[i];
1314 if( zwindow->idx < 0 ) continue;
1318 int zn = ceil(sqrt(nz));
1319 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1320 int y1 = 1, y2 = gui->get_y();
1321 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1322 if( x1 < 0 ) x1 = 0;
1323 if( y1 < 0 ) y1 = 0;
1324 if( x2 > rw ) x2 = rw;
1325 if( y2 > rh ) y2 = rh;
1326 int dx = x2 - x1, dy = y2 - y1;
1328 int lt = BC_DisplayInfo::get_left_border();
1329 int top = BC_DisplayInfo::get_top_border();
1330 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1331 int bh = top + BC_DisplayInfo::get_bottom_border();
1332 int zx = 0, zy = 0; // window origins
1333 int mw = 10+10, mh = 10+10; // canvas margins
1334 int rsz = 0, n = 0, dz = 0;
1335 int ow = edl->session->output_w, oh = edl->session->output_h;
1336 for( int i=0; i<zwindows.size(); ++i ) {
1337 ZWindow *zwindow = zwindows[i];
1338 if( zwindow->idx < 0 ) continue;
1339 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1340 if( rsz < hh ) rsz = hh;
1341 int xx = zx + x1, yy = zy + y1;
1342 int mx = x2 - zw, my = y2 - zh;
1343 if( xx > mx ) xx = mx;
1344 if( yy > my ) yy = my;
1345 xx += lt + dz; yy += top + dz;
1346 zwindow->reposition(xx,yy, ww,hh);
1347 if( zwindow->running() ) {
1348 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1349 gui->lock_window("MWindow::tile_mixers");
1350 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1351 gui->unlock_window();
1355 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1364 void MWindow::init_cache()
1366 audio_cache = new CICache(preferences);
1367 video_cache = new CICache(preferences);
1368 frame_cache = new FrameCache;
1369 wave_cache = new WaveCache;
1372 void MWindow::init_channeldb()
1374 channeldb_buz->load("channeldb_buz");
1375 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1378 void MWindow::init_menus()
1380 char string[BCTEXTLEN];
1383 BC_CModels::to_text(string, BC_RGB888);
1384 colormodels.append(new ColormodelItem(string, BC_RGB888));
1385 BC_CModels::to_text(string, BC_RGBA8888);
1386 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1387 // BC_CModels::to_text(string, BC_RGB161616);
1388 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1389 // BC_CModels::to_text(string, BC_RGBA16161616);
1390 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1391 BC_CModels::to_text(string, BC_RGB_FLOAT);
1392 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1393 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1394 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1395 BC_CModels::to_text(string, BC_YUV888);
1396 colormodels.append(new ColormodelItem(string, BC_YUV888));
1397 BC_CModels::to_text(string, BC_YUVA8888);
1398 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1399 // BC_CModels::to_text(string, BC_YUV161616);
1400 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1401 // BC_CModels::to_text(string, BC_YUVA16161616);
1402 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1404 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1405 interlace_project_modes.append(new InterlacemodeItem(string, x));
1407 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1408 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1410 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1411 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1413 // Interlacing Modes
1414 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1416 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1417 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1419 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1420 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1422 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1423 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1425 // Interlacing Fixing Methods
1426 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1427 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1428 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1431 void MWindow::init_indexes()
1433 mainindexes = new MainIndexes(this);
1434 mainindexes->start_loop();
1437 void MWindow::init_gui()
1439 gui = new MWindowGUI(this);
1440 gui->lock_window("MWindow::init_gui");
1441 gui->create_objects();
1442 gui->unlock_window();
1443 gui->load_defaults(defaults);
1446 void MWindow::init_signals()
1448 sighandler = new SigHandler;
1449 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1453 void MWindow::init_render()
1455 render = new Render(this);
1456 create_bd = new CreateBD_Thread(this);
1457 create_dvd = new CreateDVD_Thread(this);
1458 batch_render = new BatchRenderThread(this);
1461 void MWindow::init_exportedl()
1463 exportedl = new ExportEDL(this);
1466 void MWindow::init_brender()
1468 if(preferences->use_brender && !brender)
1470 brender_lock->lock("MWindow::init_brender 1");
1471 brender = new BRender(this);
1472 brender->initialize();
1473 session->brender_end = 0;
1474 brender_lock->unlock();
1477 if(!preferences->use_brender && brender)
1479 brender_lock->lock("MWindow::init_brender 2");
1482 session->brender_end = 0;
1483 brender_lock->unlock();
1489 void MWindow::restart_brender()
1491 //printf("MWindow::restart_brender 1\n");
1492 if( !brender_active || !preferences->use_brender ) return;
1493 if( !brender ) return;
1494 int locked = gui->get_window_lock();
1495 if( locked ) gui->unlock_window();
1496 brender->restart(edl);
1497 if( locked ) gui->lock_window("MWindow::restart_brender");
1500 void MWindow::stop_brender()
1502 if( !brender ) return;
1503 int locked = gui->get_window_lock();
1504 if( locked ) gui->unlock_window();
1506 if( locked ) gui->lock_window("MWindow::stop_brender");
1509 int MWindow::brender_available(int position)
1512 brender_lock->lock("MWindow::brender_available 1");
1513 if(brender && brender_active)
1515 if(brender->map_valid)
1517 brender->map_lock->lock("MWindow::brender_available 2");
1518 if(position < brender->map_size &&
1521 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1522 if(brender->map[position] == BRender::RENDERED)
1525 brender->map_lock->unlock();
1528 brender_lock->unlock();
1532 void MWindow::set_brender_active(int v, int update)
1534 if( !preferences->use_brender ) v = 0;
1536 gui->mainmenu->brender_active->set_checked(v);
1538 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1539 edl->session->brender_end = edl->local_session->get_selectionend(1);
1541 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1542 edl->session->brender_end = edl->tracks->total_video_length();
1547 edl->session->brender_start = edl->session->brender_end = 0;
1551 gui->update_timebar(0);
1552 gui->draw_overlays(1);
1556 int MWindow::has_commercials()
1558 return theme->use_commercials;
1561 void MWindow::init_commercials()
1563 if( !commercials ) {
1564 commercials = new Commercials(this);
1565 commercial_active = 0;
1568 commercials->add_user();
1571 void MWindow::commit_commercial()
1573 if( !commercial_active ) return;
1574 commercial_active = 0;
1575 if( !commercials ) return;
1576 commercials->commitDb();
1579 void MWindow::undo_commercial()
1581 if( !commercial_active ) return;
1582 commercial_active = 0;
1583 if( !commercials ) return;
1584 commercials->undoDb();
1587 int MWindow::put_commercial()
1589 double start = edl->local_session->get_selectionstart();
1590 double end = edl->local_session->get_selectionend();
1591 if( start >= end ) return 0;
1593 const char *errmsg = 0;
1595 Tracks *tracks = edl->tracks;
1598 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1599 if( track->data_type != TRACK_VIDEO ) continue;
1600 if( !track->record ) continue;
1601 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1603 int64_t units_start = track->to_units(start,0);
1604 int64_t units_end = track->to_units(end,0);
1605 Edits *edits = track->edits;
1606 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1607 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1608 if(!edit1 && !edit2) continue; // nothing selected
1609 if(!edit2) { // edit2 beyond end of track
1610 edit2 = edits->last;
1611 units_end = edits->length();
1613 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1614 Indexable *indexable = edit1->get_source();
1615 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1618 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1619 if( track->data_type != TRACK_VIDEO ) continue;
1620 if( !track->record ) continue;
1621 int64_t units_start = track->to_units(start,0);
1622 int64_t units_end = track->to_units(end,0);
1623 Edits *edits = track->edits;
1624 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1625 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1626 if(!edit1 && !edit2) continue; // nothing selected
1627 if(!edit2) { // edit2 beyond end of track
1628 edit2 = edits->last;
1629 units_end = edits->length();
1631 Indexable *indexable = edit1->get_source();
1632 Asset *asset = (Asset *)indexable;
1633 File *file = video_cache->check_out(asset, edl);
1634 if( !file ) { errmsg = _("no file"); break; }
1635 int64_t edit_length = units_end - units_start;
1636 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1637 result = commercials->put_clip(file, edit1->channel,
1638 track->from_units(edit_start), track->from_units(edit_length));
1639 video_cache->check_in(asset);
1640 if( result ) { errmsg = _("db failed"); break; }
1643 char string[BCTEXTLEN];
1644 sprintf(string, _("put_commercial: %s"), errmsg);
1645 MainError::show_error(string);
1652 void MWindow::stop_playback(int wait)
1654 gui->stop_drawing();
1656 cwindow->stop_playback(wait);
1658 for(int i = 0; i < vwindows.size(); i++) {
1659 VWindow *vwindow = vwindows[i];
1660 if( !vwindow->is_running() ) continue;
1661 vwindow->stop_playback(wait);
1663 for(int i = 0; i < zwindows.size(); i++) {
1664 ZWindow *zwindow = zwindows[i];
1665 if( zwindow->idx < 0 ) continue;
1666 zwindow->stop_playback(wait);
1670 int MWindow::load_filenames(ArrayList<char*> *filenames,
1672 int update_filename)
1674 ArrayList<EDL*> new_edls;
1675 ArrayList<Asset*> new_assets;
1676 ArrayList<File*> new_files;
1677 const int debug = 0;
1678 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1681 gui->start_hourglass();
1683 // Need to stop playback since tracking depends on the EDL not getting
1685 gui->unlock_window();
1687 gui->lock_window("MWindow::load_filenames 0");
1689 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1690 undo->update_undo_before();
1693 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1695 // Define new_edls and new_assets to load
1696 int result = 0, ftype = -1;
1697 for(int i = 0; i < filenames->size(); i++)
1700 File *new_file = new File;
1701 Asset *new_asset = new Asset(filenames->get(i));
1702 EDL *new_edl = new EDL;
1703 char string[BCTEXTLEN];
1705 new_edl->create_objects();
1706 new_edl->copy_session(edl);
1707 new_file->set_program(edl->session->program_no);
1709 sprintf(string, _("Loading %s"), new_asset->path);
1710 gui->show_message(string);
1711 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1713 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1714 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) ||
1724 (new_asset->height % 2)))
1726 char string[BCTEXTLEN];
1727 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1731 MainError::show_error(string);
1734 if(new_asset->program >= 0 &&
1735 edl->session->program_no != new_asset->program)
1737 char string[BCTEXTLEN];
1738 sprintf(string, _("%s's index was built for program number %d\n"
1739 "Playback preference is %d.\n Using program %d."),
1740 new_asset->path, new_asset->program,
1741 edl->session->program_no, new_asset->program);
1742 MainError::show_error(string);
1746 if(load_mode != LOADMODE_RESOURCESONLY)
1748 RecordLabels *labels = edl->session->label_cells ?
1749 new RecordLabels(new_file) : 0;
1750 asset_to_edl(new_edl, new_asset, labels);
1751 new_edls.append(new_edl);
1752 new_asset->Garbage::remove_user();
1758 new_assets.append(new_asset);
1762 // Set filename to nothing for assets since save EDL would overwrite them.
1763 if(load_mode == LOADMODE_REPLACE ||
1764 load_mode == LOADMODE_REPLACE_CONCATENATE)
1767 // Reset timeline position
1768 for(int i = 0; i < TOTAL_PANES; i++)
1770 new_edl->local_session->view_start[i] = 0;
1771 new_edl->local_session->track_start[i] = 0;
1779 case FILE_NOT_FOUND:
1780 sprintf(string, _("Failed to open %s"), new_asset->path);
1781 gui->show_message(string, theme->message_error);
1782 gui->update_default_message();
1786 case FILE_UNRECOGNIZED_CODEC:
1789 { IndexFile indexfile(this, new_asset);
1790 if( !(result = indexfile.open_index()) )
1791 indexfile.close_index();
1794 // Test existing EDLs
1795 for(int j = 0; result && j <= new_edls.total; j++) {
1796 Asset *old_asset = j < new_edls.total ?
1797 new_edls[j]->assets->get_asset(new_asset->path) :
1798 edl->assets->get_asset(new_asset->path);
1800 new_asset->copy_from(old_asset,1);
1808 char string[BCTEXTLEN];
1810 fs.extract_name(string, new_asset->path);
1812 strcat(string, _("'s format couldn't be determined."));
1813 new_asset->audio_data = 1;
1814 new_asset->format = FILE_PCM;
1815 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1816 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1817 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1818 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1819 new_asset->signed_ = defaults->get("SIGNED_", 1);
1820 new_asset->header = defaults->get("HEADER", 0);
1822 FileFormat fwindow(this);
1823 fwindow.create_objects(new_asset, string);
1824 result = fwindow.run_window();
1827 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1828 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1829 defaults->update("AUDIO_BITS", new_asset->bits);
1830 defaults->update("BYTE_ORDER", new_asset->byte_order);
1831 defaults->update("SIGNED_", new_asset->signed_);
1832 defaults->update("HEADER", new_asset->header);
1839 // Recalculate length
1841 new_file = new File;
1842 result = new_file->open_file(preferences, new_asset, 1, 0);
1844 if(load_mode != LOADMODE_RESOURCESONLY)
1846 RecordLabels *labels = edl->session->label_cells ?
1847 new RecordLabels(new_file) : 0;
1848 asset_to_edl(new_edl, new_asset, labels);
1849 new_edls.append(new_edl);
1850 new_asset->Garbage::remove_user();
1856 new_assets.append(new_asset);
1870 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1871 xml_file.read_from_file(filenames->get(i));
1872 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1873 const char *cin_version = 0;
1874 while( !xml_file.read_tag() ) {
1875 if( xml_file.tag.title_is("EDL") ) {
1876 cin_version = xml_file.tag.get_property("VERSION");
1881 if( !cin_version ) {
1882 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1883 char string[BCTEXTLEN];
1884 sprintf(string,_("Unknown %s"), filenames->get(i));
1885 gui->show_message(string);
1889 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1890 char string[BCTEXTLEN];
1891 snprintf(string, sizeof(string),
1892 _("Warning: XML from cinelerra version %s\n"
1893 "Session data may be incompatible."), cin_version);
1894 show_warning(&preferences->warn_version, string);
1896 if(load_mode == LOADMODE_NESTED)
1898 // Load temporary EDL for nesting.
1899 EDL *nested_edl = new EDL;
1900 nested_edl->create_objects();
1901 nested_edl->set_path(filenames->get(i));
1902 nested_edl->load_xml(&xml_file, LOAD_ALL);
1903 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1904 edl_to_nested(new_edl, nested_edl);
1905 nested_edl->Garbage::remove_user();
1909 // Load EDL for pasting
1910 new_edl->load_xml(&xml_file, LOAD_ALL);
1911 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1912 test_plugins(new_edl, filenames->get(i));
1913 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1915 if(load_mode == LOADMODE_REPLACE ||
1916 load_mode == LOADMODE_REPLACE_CONCATENATE)
1918 strcpy(session->filename, filenames->get(i));
1919 strcpy(new_edl->local_session->clip_title,
1922 set_filename(new_edl->local_session->clip_title);
1925 if( load_mode == LOADMODE_RESOURCESONLY ) {
1926 strcpy(new_edl->local_session->clip_title,
1929 time_t t = !stat(filenames->get(i),&st) ?
1930 st.st_mtime : time(&t);
1931 ctime_r(&t, new_edl->local_session->clip_notes);
1935 new_edls.append(new_edl);
1941 // edls are in new_edls
1942 if( result && new_edl ) new_edl->Garbage::remove_user();
1943 // assets are copied
1944 if( new_asset ) new_asset->Garbage::remove_user();
1946 // Store for testing index
1947 new_files.append(new_file);
1950 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1954 gui->reset_default_message();
1955 gui->default_message();
1959 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1962 // Don't back up here.
1965 // For pasting, clear the active region
1966 if(load_mode == LOADMODE_PASTE ||
1967 load_mode == LOADMODE_NESTED)
1969 double start = edl->local_session->get_selectionstart();
1970 double end = edl->local_session->get_selectionend();
1971 if(!EQUIV(start, end))
1974 edl->session->labels_follow_edits,
1975 edl->session->plugins_follow_edits,
1976 edl->session->autos_follow_edits);
1979 paste_edls(&new_edls, load_mode, 0, -1,
1980 edl->session->labels_follow_edits,
1981 edl->session->plugins_follow_edits,
1982 edl->session->autos_follow_edits,
1989 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1991 // Add new assets to EDL and schedule assets for index building.
1992 int got_indexes = 0;
1993 for(int i = 0; i < new_edls.size(); i++)
1995 EDL *new_edl = new_edls[i];
1996 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1998 mainindexes->add_next_asset(0,
1999 new_edl->nested_edls->get(j));
2001 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
2006 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2007 for(int i = 0; i < new_assets.size(); i++)
2009 Asset *new_asset = new_assets[i];
2013 for(int j = 0; j < new_files.size(); j++)
2015 new_file = new_files[j];
2016 if(!strcmp(new_file->asset->path,
2024 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2026 edl->assets->update(new_asset);
2028 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2030 // Start examining next batch of index files
2031 if(got_indexes) mainindexes->start_build();
2032 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2035 Track *track = edl->tracks->first;
2038 for(int j = 0; j < track->plugin_set.size(); j++)
2040 PluginSet *plugins = track->plugin_set[j];
2041 Plugin *plugin = plugins->get_first_plugin();
2045 if(load_mode == LOADMODE_REPLACE ||
2046 load_mode == LOADMODE_REPLACE_CONCATENATE)
2048 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2051 show_plugin(plugin);
2055 plugin = (Plugin*)plugin->next;
2059 track = track->next;
2062 // if just opening one new resource in replace mode
2063 if( ftype != FILE_IS_XML &&
2064 ( load_mode == LOADMODE_REPLACE ||
2065 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2067 edl->session->proxy_scale = 1;
2068 edl->session->proxy_use_scaler = 0;
2069 edl->session->proxy_auto_scale = 0;
2070 edl->local_session->preview_start = 0;
2071 edl->local_session->preview_end = edl->tracks->total_length();
2072 edl->local_session->loop_playback = 0;
2073 edl->local_session->set_selectionstart(0);
2074 edl->local_session->set_selectionend(0);
2075 set_brender_active(0, 0);
2080 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2081 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2082 ArrayList<Indexable *> orig_idxbls;
2083 for( int i=0; i<new_assets.size(); ++i )
2084 orig_idxbls.append(new_assets.get(i));
2085 for( int i=0; i<new_edls.size(); ++i ) {
2086 EDL *new_edl = new_edls[i];
2087 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2088 if( track->data_type != TRACK_VIDEO ) continue;
2089 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2090 Indexable *idxbl = (Indexable *)edit->asset;
2091 if( !idxbl ) continue;
2092 if( !idxbl->have_video() ) continue;
2093 if( edit->channel != 0 ) continue; // first layer only
2094 orig_idxbls.append(edit->asset);
2098 gui->unlock_window(); // to update progress bar
2099 render_proxy(orig_idxbls);
2100 gui->lock_window("MWindow::load_filenames");
2103 // need to update undo before project, since mwindow is unlocked & a new load
2104 // can begin here. Should really prevent loading until we're done.
2105 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2106 undo->update_undo_after(_("load"), LOAD_ALL);
2108 for(int i = 0; i < new_edls.size(); i++)
2110 new_edls[i]->remove_user();
2112 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2114 new_edls.remove_all();
2116 for(int i = 0; i < new_assets.size(); i++)
2118 new_assets[i]->Garbage::remove_user();
2121 new_assets.remove_all();
2122 new_files.remove_all_objects();
2125 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2126 if(load_mode == LOADMODE_REPLACE ||
2127 load_mode == LOADMODE_REPLACE_CONCATENATE)
2129 session->changes_made = 0;
2133 session->changes_made = 1;
2136 gui->stop_hourglass();
2139 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2140 update_project(load_mode);
2142 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2147 void MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2149 Asset *format_asset = new Asset;
2150 format_asset->format = FILE_FFMPEG;
2151 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2152 ProxyRender proxy_render(this, format_asset);
2153 int new_scale = edl->session->proxy_scale;
2154 int use_scaler = edl->session->proxy_use_scaler;
2156 for( int i=0; i<new_idxbls.size(); ++i ) {
2157 Indexable *orig = new_idxbls.get(i);
2158 Asset *proxy = proxy_render.add_original(orig, new_scale);
2159 if( !proxy ) continue;
2161 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2162 int got_it = exists && // if proxy exists, and is newer than orig
2163 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2164 if( got_it ) continue;
2165 proxy_render.add_needed(orig, proxy);
2168 // render needed proxies
2169 int result = proxy_render.create_needed_proxies(new_scale);
2171 add_proxy(use_scaler,
2172 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2174 format_asset->remove_user();
2177 void MWindow::test_plugins(EDL *new_edl, char *path)
2179 char string[BCTEXTLEN];
2181 // Do a check weather plugins exist
2182 for(Track *track = new_edl->tracks->first; track; track = track->next)
2184 for(int k = 0; k < track->plugin_set.total; k++)
2186 PluginSet *plugin_set = track->plugin_set[k];
2187 for(Plugin *plugin = (Plugin*)plugin_set->first;
2189 plugin = (Plugin*)plugin->next)
2191 if(plugin->plugin_type == PLUGIN_STANDALONE)
2193 // ok we need to find it in plugindb
2194 int plugin_found = 0;
2196 for(int j = 0; j < plugindb->size(); j++)
2198 PluginServer *server = plugindb->get(j);
2200 !strcasecmp(server->title, plugin->title) &&
2201 ((track->data_type == TRACK_AUDIO && server->audio) ||
2202 (track->data_type == TRACK_VIDEO && server->video)) &&
2203 (!server->transition))
2210 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2211 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2212 "effect", plugin->title,
2214 MainError::show_error(string);
2220 for(Edit *edit = (Edit*)track->edits->first;
2222 edit = (Edit*)edit->next)
2224 if (edit->transition)
2226 // ok we need to find transition in plugindb
2228 int transition_found = 0;
2229 for(int j = 0; j < plugindb->size(); j++)
2231 PluginServer *server = plugindb->get(j);
2233 !strcasecmp(server->title, edit->transition->title) &&
2234 ((track->data_type == TRACK_AUDIO && server->audio) ||
2235 (track->data_type == TRACK_VIDEO && server->video)) &&
2236 (server->transition))
2237 transition_found = 1;
2240 if (!transition_found)
2243 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2244 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2245 "transition", edit->transition->title,
2247 MainError::show_error(string);
2255 void MWindow::init_shm()
2257 // Fix shared memory
2258 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
2260 fprintf(fd, "0x7fffffff");
2265 fd = fopen("/proc/sys/kernel/shmmax", "r");
2267 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
2272 fscanf(fd, "%jd", &result);
2275 if(result < 0x7fffffff) {
2276 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
2277 "you probably need to be root, or:\n"
2278 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
2279 "before trying to start cinelerra.\n"
2280 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
2284 void MWindow::create_objects(int want_gui,
2288 const int debug = 0;
2289 if(debug) PRINT_TRACE
2291 // For some reason, init_signals must come after show_splash or the signals won't
2294 if(debug) PRINT_TRACE
2297 if(debug) PRINT_TRACE
2300 if(debug) PRINT_TRACE
2301 default_standard = default_std();
2302 init_defaults(defaults, config_path);
2306 splash_window->operation->update(_("Initializing Plugins"));
2307 init_plugins(this, preferences);
2308 if(debug) PRINT_TRACE
2309 init_ladspa_plugins(this, preferences);
2310 if(debug) PRINT_TRACE
2311 init_plugin_tips(*plugindb, cin_lang);
2313 splash_window->operation->update(_("Initializing GUI"));
2314 if(debug) PRINT_TRACE
2317 if(debug) PRINT_TRACE
2321 splash_window->operation->update(_("Initializing Fonts"));
2322 char string[BCTEXTLEN];
2323 strcpy(string, preferences->plugin_dir);
2324 strcat(string, "/" FONT_SEARCHPATH);
2325 BC_Resources::init_fontconfig(string);
2326 if(debug) PRINT_TRACE
2328 // Initialize before too much else is running
2329 // Preferences & theme are required for building MPEG table of contents
2331 // Default project created here
2333 if(debug) PRINT_TRACE
2336 if(debug) PRINT_TRACE
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());
2346 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2347 if(session->show_vwindow)
2348 get_viewer(1, DEFAULT_VWINDOW);
2349 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2352 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2355 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2358 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2361 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2364 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2367 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2372 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2373 mainprogress = new MainProgress(this, gui);
2374 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2375 undo = new MainUndo(this);
2377 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2379 plugin_guis = new ArrayList<PluginServer*>;
2380 dead_plugins = new ArrayList<PluginServer*>;
2381 keyframe_threads = new ArrayList<KeyFrameThread*>;
2383 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2386 session->show_vwindow);
2388 // Show all vwindows
2389 // if(session->show_vwindow) {
2390 // for(int j = 0; j < vwindows.size(); j++) {
2391 // VWindow *vwindow = vwindows[j];
2392 // if( !vwindow->is_running() ) continue;
2393 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2396 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2397 // vwindow->gui->lock_window("MWindow::create_objects 1");
2398 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2399 // vwindow->gui->show_window();
2400 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2401 // vwindow->gui->unlock_window();
2406 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2408 if(session->show_cwindow)
2410 cwindow->gui->lock_window("MWindow::create_objects 1");
2411 cwindow->gui->show_window();
2412 cwindow->gui->unlock_window();
2415 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2416 if(session->show_awindow)
2418 awindow->gui->lock_window("MWindow::create_objects 1");
2419 awindow->gui->show_window();
2420 awindow->gui->unlock_window();
2423 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2424 if(session->show_lwindow)
2426 lwindow->gui->lock_window("MWindow::create_objects 1");
2427 lwindow->gui->show_window();
2428 lwindow->gui->unlock_window();
2431 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2433 (int)timer.get_difference(),
2435 if(session->show_gwindow)
2437 gwindow->gui->lock_window("MWindow::create_objects 1");
2438 gwindow->gui->show_window();
2439 gwindow->gui->unlock_window();
2442 if(debug) PRINT_TRACE
2444 gui->lock_window("MWindow::create_objects 1");
2445 gui->mainmenu->load_defaults(defaults);
2446 gui->mainmenu->update_toggles(0);
2447 gui->update_patchbay();
2448 gui->draw_canvas(0, 0);
2449 gui->draw_cursor(1);
2451 gui->raise_window();
2452 gui->unlock_window();
2454 if(debug) PRINT_TRACE
2456 if(preferences->use_tipwindow)
2458 if(debug) PRINT_TRACE
2460 gui->add_keyboard_listener(
2461 (int (BC_WindowBase::*)(BC_WindowBase *))
2462 &MWindowGUI::keyboard_listener);
2466 if(debug) PRINT_TRACE
2468 BC_WindowBase::get_resources()->vframe_shm = 1;
2472 void MWindow::show_splash()
2474 #include "data/heroine_logo9_png.h"
2475 VFrame *frame = new VFramePng(heroine_logo9_png);
2476 BC_DisplayInfo dpyi;
2477 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2478 int rr = (rw < rh ? rw : rh) / 4;
2479 splash_window = new SplashGUI(frame, rr, rr);
2480 splash_window->create_objects();
2483 void MWindow::hide_splash()
2486 delete splash_window;
2491 void MWindow::start()
2495 // vwindows[DEFAULT_VWINDOW]->start();
2506 playback_3d->start();
2512 run_lock->lock("MWindow::run");
2516 brender_lock->lock("MWindow::run 1");
2517 delete brender; brender = 0;
2518 brender_lock->unlock();
2520 interrupt_indexes();
2526 void MWindow::show_vwindow()
2528 int total_running = 0;
2529 session->show_vwindow = 1;
2531 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2532 // Raise all windows which are visible
2533 for(int j = 0; j < vwindows.size(); j++) {
2534 VWindow *vwindow = vwindows[j];
2535 if( !vwindow->is_running() ) continue;
2536 vwindow->gui->lock_window("MWindow::show_vwindow");
2537 vwindow->gui->show_window(0);
2538 vwindow->gui->raise_window();
2539 vwindow->gui->flush();
2540 vwindow->gui->unlock_window();
2544 // If no windows visible
2547 get_viewer(1, DEFAULT_VWINDOW);
2550 gui->mainmenu->show_vwindow->set_checked(1);
2553 void MWindow::show_awindow()
2555 session->show_awindow = 1;
2556 awindow->gui->lock_window("MWindow::show_awindow");
2557 awindow->gui->show_window();
2558 awindow->gui->raise_window();
2559 awindow->gui->flush();
2560 awindow->gui->unlock_window();
2561 gui->mainmenu->show_awindow->set_checked(1);
2564 char *MWindow::get_cwindow_display()
2566 char *x11_host = screens < 2 || session->window_config == 0 ?
2567 session->a_x11_host : session->b_x11_host;
2568 return *x11_host ? x11_host : 0;
2571 void MWindow::show_cwindow()
2573 session->show_cwindow = 1;
2574 cwindow->show_window();
2575 gui->mainmenu->show_cwindow->set_checked(1);
2578 void MWindow::show_gwindow()
2580 session->show_gwindow = 1;
2582 gwindow->gui->lock_window("MWindow::show_gwindow");
2583 gwindow->gui->show_window();
2584 gwindow->gui->raise_window();
2585 gwindow->gui->flush();
2586 gwindow->gui->unlock_window();
2588 gui->mainmenu->show_gwindow->set_checked(1);
2590 void MWindow::hide_gwindow()
2592 session->show_gwindow = 0;
2594 gwindow->gui->lock_window("MWindow::show_gwindow");
2595 gwindow->gui->hide_window();
2596 gwindow->gui->unlock_window();
2599 void MWindow::show_lwindow()
2601 session->show_lwindow = 1;
2602 lwindow->gui->lock_window("MWindow::show_lwindow");
2603 lwindow->gui->show_window();
2604 lwindow->gui->raise_window();
2605 lwindow->gui->flush();
2606 lwindow->gui->unlock_window();
2607 gui->mainmenu->show_lwindow->set_checked(1);
2610 int MWindow::tile_windows(int window_config)
2612 int need_reload = 0;
2613 int play_config = window_config==0 ? 0 : 1;
2614 edl->session->playback_config->load_defaults(defaults, play_config);
2615 session->default_window_positions(window_config);
2616 if( screens == 1 ) {
2617 gui->default_positions();
2618 sync_parameters(CHANGE_ALL);
2625 void MWindow::toggle_loop_playback()
2627 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2628 set_loop_boundaries();
2631 gui->draw_overlays(1);
2632 sync_parameters(CHANGE_PARAMS);
2635 //void MWindow::set_titles(int value)
2637 // edl->session->show_titles = value;
2638 // trackmovement(edl->local_session->track_start);
2641 void MWindow::set_screens(int value)
2646 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2648 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2649 edl->session->auto_keyframes = value;
2650 gui->mbuttons->edit_panel->keyframe->update(value);
2652 if(lock_mwindow) gui->unlock_window();
2654 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2655 cwindow->gui->edit_panel->keyframe->update(value);
2656 cwindow->gui->flush();
2657 if(lock_cwindow) cwindow->gui->unlock_window();
2660 void MWindow::set_auto_visibility(Autos *autos, int value)
2662 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2663 edl->session->auto_conf->plugins = value;
2664 else if( autos->autoidx >= 0 )
2665 edl->session->auto_conf->autos[autos->autoidx] = value;
2669 gui->update(0, 1, 0, 0, 0, 0, 0);
2670 gui->mainmenu->update_toggles(1);
2671 gui->unlock_window();
2672 gwindow->gui->update_toggles(1);
2673 gui->lock_window("MWindow::set_auto_visibility");
2676 void MWindow::set_keyframe_type(int mode)
2678 gui->lock_window("MWindow::set_keyframe_type");
2679 edl->local_session->floatauto_type = mode;
2680 gui->mainmenu->update_toggles(0);
2681 gui->unlock_window();
2684 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2686 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2687 edl->session->editing_mode = new_editing_mode;
2688 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2689 gui->mbuttons->edit_panel->update();
2690 gui->set_editing_mode(1);
2691 if(lock_mwindow) gui->unlock_window();
2694 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2695 cwindow->gui->edit_panel->update();
2696 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2697 if(lock_cwindow) cwindow->gui->unlock_window();
2701 void MWindow::toggle_editing_mode()
2703 int mode = edl->session->editing_mode;
2704 if( mode == EDITING_ARROW )
2705 set_editing_mode(EDITING_IBEAM, 0, 1);
2707 set_editing_mode(EDITING_ARROW, 0, 1);
2711 void MWindow::set_labels_follow_edits(int value)
2713 gui->lock_window("MWindow::set_labels_follow_edits");
2714 edl->session->labels_follow_edits = value;
2715 gui->mbuttons->edit_panel->locklabels->update(value);
2716 gui->mainmenu->labels_follow_edits->set_checked(value);
2718 gui->unlock_window();
2721 void MWindow::sync_parameters(int change_type)
2723 if( in_destructor ) return;
2725 // Sync engines which are playing back
2726 if(cwindow->playback_engine->is_playing_back)
2728 if(change_type == CHANGE_PARAMS)
2730 // TODO: block keyframes until synchronization is done
2731 cwindow->playback_engine->sync_parameters(edl);
2736 int command = cwindow->playback_engine->command->command;
2737 cwindow->playback_engine->que->send_command(STOP,
2741 // Waiting for tracking to finish would make the restart position more
2742 // accurate but it can't lock the window to stop tracking for some reason.
2743 // Not waiting for tracking gives a faster response but restart position is
2744 // only as accurate as the last tracking update.
2745 cwindow->playback_engine->interrupt_playback(0);
2746 cwindow->playback_engine->que->send_command(command,
2755 cwindow->refresh_frame(change_type);
2759 void MWindow::age_caches()
2761 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2763 // preferences->cache_size,
2764 // audio_cache->get_memory_usage(1),
2765 // video_cache->get_memory_usage(1),
2766 // frame_cache->get_memory_usage(),
2767 // wave_cache->get_memory_usage(),
2769 frame_cache->age_cache(512);
2770 wave_cache->age_cache(8192);
2772 int64_t memory_usage;
2773 int64_t prev_memory_usage = 0;
2775 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2776 while( !result && prev_memory_usage !=
2777 (memory_usage=video_cache->get_memory_usage(1)) &&
2778 memory_usage > video_size ) {
2779 video_cache->delete_oldest();
2780 prev_memory_usage = memory_usage;
2783 prev_memory_usage = 0;
2785 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2786 while( !result && prev_memory_usage !=
2787 (memory_usage=audio_cache->get_memory_usage(1)) &&
2788 memory_usage > audio_size ) {
2789 audio_cache->delete_oldest();
2790 prev_memory_usage = memory_usage;
2794 void MWindow::reset_android_remote()
2796 gui->use_android_remote(preferences->android_remote);
2800 void MWindow::show_keyframe_gui(Plugin *plugin)
2802 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2803 // Find existing thread
2804 for(int i = 0; i < keyframe_threads->size(); i++)
2806 if(keyframe_threads->get(i)->plugin == plugin)
2808 keyframe_threads->get(i)->start_window(plugin, 0);
2809 keyframe_gui_lock->unlock();
2814 // Find unused thread
2815 for(int i = 0; i < keyframe_threads->size(); i++)
2817 if(!keyframe_threads->get(i)->plugin)
2819 keyframe_threads->get(i)->start_window(plugin, 0);
2820 keyframe_gui_lock->unlock();
2825 // Create new thread
2826 KeyFrameThread *thread = new KeyFrameThread(this);
2827 keyframe_threads->append(thread);
2828 thread->start_window(plugin, 0);
2830 keyframe_gui_lock->unlock();
2837 void MWindow::show_plugin(Plugin *plugin)
2842 // Remove previously deleted plugin GUIs
2843 dead_plugin_lock->lock("MWindow::show_plugin");
2844 dead_plugins->remove_all_objects();
2845 dead_plugin_lock->unlock();
2847 //printf("MWindow::show_plugin %d\n", __LINE__);
2851 plugin_gui_lock->lock("MWindow::show_plugin");
2852 for(int i = 0; i < plugin_guis->total; i++)
2854 // Pointer comparison
2855 if(plugin_guis->get(i)->plugin == plugin)
2857 plugin_guis->get(i)->raise_window();
2864 //printf("MWindow::show_plugin 1\n");
2865 if( !done && !plugin->track ) {
2866 printf("MWindow::show_plugin track not defined.\n");
2870 PluginServer *server = scan_plugindb(plugin->title,
2871 plugin->track->data_type);
2873 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2874 if(server && server->uses_gui)
2876 PluginServer *gui = new PluginServer(*server);
2877 plugin_guis->append(gui);
2878 // Needs mwindow to do GUI
2879 gui->set_mwindow(this);
2880 gui->open_plugin(0, preferences, edl, plugin);
2885 plugin_gui_lock->unlock();
2886 //printf("MWindow::show_plugin %d\n", __LINE__);
2889 //printf("MWindow::show_plugin 2\n");
2892 void MWindow::hide_plugin(Plugin *plugin, int lock)
2895 // Update the toggle
2896 gui->lock_window("MWindow::hide_plugin");
2897 gui->update(0, 1, 0, 0, 0, 0, 0);
2898 gui->unlock_window();
2900 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2901 for(int i = 0; i < plugin_guis->total; i++)
2903 if(plugin_guis->get(i)->plugin == plugin)
2905 PluginServer *ptr = plugin_guis->get(i);
2906 plugin_guis->remove(ptr);
2907 if(lock) plugin_gui_lock->unlock();
2908 // Last command executed in client side close
2909 // Schedule for deletion
2916 if(lock) plugin_gui_lock->unlock();
2919 void MWindow::delete_plugin(PluginServer *plugin)
2921 dead_plugin_lock->lock("MWindow::delete_plugin");
2922 dead_plugins->append(plugin);
2923 dead_plugin_lock->unlock();
2926 void MWindow::hide_plugins()
2928 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2929 while(plugin_guis->size())
2931 PluginServer *ptr = plugin_guis->get(0);
2932 plugin_guis->remove(ptr);
2933 plugin_gui_lock->unlock();
2934 // Last command executed in client side close
2935 // Schedule for deletion
2938 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2940 plugin_gui_lock->unlock();
2942 hide_keyframe_guis();
2945 void MWindow::hide_keyframe_guis()
2947 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2948 for(int i = 0; i < keyframe_threads->size(); i++)
2950 keyframe_threads->get(i)->close_window();
2952 keyframe_gui_lock->unlock();
2955 void MWindow::hide_keyframe_gui(Plugin *plugin)
2957 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2958 for(int i = 0; i < keyframe_threads->size(); i++)
2960 if(keyframe_threads->get(i)->plugin == plugin)
2962 keyframe_threads->get(i)->close_window();
2966 keyframe_gui_lock->unlock();
2969 void MWindow::update_keyframe_guis()
2971 // Send new configuration to keyframe GUI's
2972 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2973 for(int i = 0; i < keyframe_threads->size(); i++)
2975 KeyFrameThread *ptr = keyframe_threads->get(i);
2976 if(edl->tracks->plugin_exists(ptr->plugin))
2980 ptr->close_window();
2983 keyframe_gui_lock->unlock();
2986 void MWindow::update_plugin_guis(int do_keyframe_guis)
2988 // Send new configuration to plugin GUI's
2989 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2991 for(int i = 0; i < plugin_guis->size(); i++)
2993 PluginServer *ptr = plugin_guis->get(i);
2994 if(edl->tracks->plugin_exists(ptr->plugin))
2998 // Schedule for deletion if no plugin
2999 plugin_guis->remove_number(i);
3008 // Change plugin variable if not visible
3009 Track *track = edl->tracks->first;
3012 for(int i = 0; i < track->plugin_set.size(); i++)
3014 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3018 for(int i = 0; i < plugin_guis->size(); i++)
3020 PluginServer *server = plugin_guis->get(i);
3021 if(server->plugin == plugin)
3028 if(!got_it) plugin->show = 0;
3030 plugin = (Plugin*)plugin->next;
3034 track = track->next;
3037 plugin_gui_lock->unlock();
3040 if(do_keyframe_guis) update_keyframe_guis();
3043 int MWindow::plugin_gui_open(Plugin *plugin)
3046 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3047 for(int i = 0; i < plugin_guis->total; i++)
3049 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3055 plugin_gui_lock->unlock();
3059 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3061 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3062 for(int i = 0; i < plugin_guis->total; i++)
3064 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3066 plugin_guis->get(i)->render_gui(data);
3070 plugin_gui_lock->unlock();
3073 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3075 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3076 for(int i = 0; i < plugin_guis->total; i++)
3078 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3080 plugin_guis->get(i)->render_gui(data, size);
3084 plugin_gui_lock->unlock();
3088 void MWindow::update_plugin_states()
3090 plugin_gui_lock->lock("MWindow::update_plugin_states");
3091 for(int i = 0; i < plugin_guis->total; i++)
3095 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3096 PluginServer *src_plugingui = plugin_guis->get(i);
3098 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3099 for(Track *track = edl->tracks->first;
3101 track = track->next)
3104 j < track->plugin_set.total && !result;
3107 PluginSet *plugin_set = track->plugin_set[j];
3108 for(Plugin *plugin = (Plugin*)plugin_set->first;
3110 plugin = (Plugin*)plugin->next)
3112 if(plugin == src_plugin &&
3113 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3119 // Doesn't exist anymore
3122 hide_plugin(src_plugin, 0);
3126 plugin_gui_lock->unlock();
3130 void MWindow::update_plugin_titles()
3132 for(int i = 0; i < plugin_guis->total; i++)
3134 plugin_guis->get(i)->update_title();
3138 int MWindow::asset_to_edl(EDL *new_edl,
3140 RecordLabels *labels)
3142 const int debug = 0;
3143 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3146 // Keep frame rate, sample rate, and output size unchanged.
3147 // These parameters would revert the project if VWindow displayed an asset
3148 // of different size than the project.
3149 if(new_asset->video_data)
3151 new_edl->session->video_tracks = new_asset->layers;
3154 new_edl->session->video_tracks = 0;
3156 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3162 if(new_asset->audio_data)
3164 new_edl->session->audio_tracks = new_asset->channels;
3167 new_edl->session->audio_tracks = 0;
3168 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3170 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3171 new_edl->create_default_tracks();
3172 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3173 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3177 //printf("MWindow::asset_to_edl 3\n");
3178 new_edl->insert_asset(new_asset,
3183 //printf("MWindow::asset_to_edl 3\n");
3184 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3186 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3187 if(edl->session->cursor_on_frames)
3189 double length = new_edl->tracks->total_length();
3190 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3191 new_edl->tracks->clear(length, edl_length, 1, 1);
3197 char string[BCTEXTLEN];
3199 fs.extract_name(string, new_asset->path);
3200 //printf("MWindow::asset_to_edl 3\n");
3202 strcpy(new_edl->local_session->clip_title, string);
3203 //printf("MWindow::asset_to_edl 4 %s\n", string);
3204 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3209 int MWindow::edl_to_nested(EDL *new_edl,
3213 // Keep frame rate, sample rate, and output size unchanged.
3214 // These parameters would revert the project if VWindow displayed an asset
3215 // of different size than the project.
3219 // Nest all video & audio outputs
3220 new_edl->session->video_tracks = 1;
3221 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
3222 new_edl->create_default_tracks();
3226 new_edl->insert_asset(0,
3232 char string[BCTEXTLEN];
3234 fs.extract_name(string, nested_edl->path);
3235 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
3237 strcpy(new_edl->local_session->clip_title, string);
3242 // Reset everything after a load.
3243 void MWindow::update_project(int load_mode)
3245 const int debug = 0;
3247 if(debug) PRINT_TRACE
3249 edl->tracks->update_y_pixels(theme);
3251 if(debug) PRINT_TRACE
3253 if(load_mode == LOADMODE_REPLACE ||
3254 load_mode == LOADMODE_REPLACE_CONCATENATE)
3259 gui->update(1, 1, 1, 1, 1, 1, 1);
3260 if(debug) PRINT_TRACE
3261 gui->unlock_window();
3263 cwindow->gui->lock_window("MWindow::update_project 1");
3264 cwindow->update(0, 0, 1, 1, 1);
3265 cwindow->gui->unlock_window();
3267 if(debug) PRINT_TRACE
3269 // Close all the vwindows
3270 if( load_mode == LOADMODE_REPLACE ||
3271 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3272 if(debug) PRINT_TRACE
3273 int first_vwindow = 0;
3274 if(session->show_vwindow) first_vwindow = 1;
3275 // Change visible windows to no source
3276 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3277 VWindow *vwindow = vwindows[i];
3278 if( !vwindow->is_running() ) continue;
3279 vwindow->change_source(-1);
3282 // Close remaining windows
3283 for(int i = first_vwindow; i < vwindows.size(); i++) {
3284 VWindow *vwindow = vwindows[i];
3285 if( !vwindow->is_running() ) continue;
3286 vwindow->close_window();
3288 if(debug) PRINT_TRACE
3292 for( int i=0; i<edl->mixers.size(); ++i ) {
3293 Mixer *mixer = edl->mixers[i];
3294 ZWindow *zwindow = get_mixer(mixer);
3295 zwindow->set_title(mixer->title);
3300 if(vwindows.size()) {
3301 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3302 if( vwindow->is_running() ) {
3303 vwindow->gui->lock_window("MWindow::update_project");
3305 vwindow->gui->unlock_window();
3310 if(debug) PRINT_TRACE
3311 cwindow->gui->lock_window("MWindow::update_project 2");
3312 cwindow->gui->timebar->update(0);
3313 cwindow->gui->unlock_window();
3315 if(debug) PRINT_TRACE
3316 cwindow->refresh_frame(CHANGE_ALL);
3318 awindow->gui->async_update_assets();
3319 if(debug) PRINT_TRACE
3321 gui->lock_window("MWindow::update_project");
3322 gui->update_mixers(0, 0);
3324 if(debug) PRINT_TRACE
3327 void MWindow::remove_indexfile(Indexable *indexable)
3329 if( !indexable->is_asset ) return;
3330 Asset *asset = (Asset *)indexable;
3332 IndexFile::delete_index(preferences, asset, ".toc");
3333 IndexFile::delete_index(preferences, asset, ".idx");
3334 IndexFile::delete_index(preferences, asset, ".mkr");
3337 void MWindow::rebuild_indices()
3339 for(int i = 0; i < session->drag_assets->total; i++)
3341 Indexable *indexable = session->drag_assets->get(i);
3342 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3343 remove_indexfile(indexable);
3344 // Schedule index build
3345 IndexState *index_state = indexable->index_state;
3346 index_state->index_status = INDEX_NOTTESTED;
3347 if( indexable->is_asset ) {
3348 Asset *asset = (Asset *)indexable;
3349 if( asset->format != FILE_PCM ) {
3350 asset->format = FILE_UNKNOWN;
3351 asset->reset_audio();
3353 asset->reset_video();
3354 // File file; // re-probe the asset
3355 // file.open_file(preferences, asset, 1, 0);
3357 mainindexes->add_next_asset(0, indexable);
3359 mainindexes->start_build();
3363 void MWindow::save_backup()
3367 edl->set_path(session->filename);
3368 char backup_path[BCTEXTLEN];
3369 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3370 File::get_config_path(), BACKUP_FILE);
3371 edl->save_xml(&file, backup_path, 0, 0);
3372 file.terminate_string();
3374 fs.complete_path(backup_path);
3376 if(file.write_to_file(backup_path))
3379 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3380 gui->show_message(string2);
3384 void MWindow::load_backup()
3386 ArrayList<char*> path_list;
3387 path_list.set_array_delete();
3389 char backup_path[BCTEXTLEN];
3390 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3391 File::get_config_path(), BACKUP_FILE);
3393 fs.complete_path(backup_path);
3395 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3396 strcpy(out_path, backup_path);
3398 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3399 edl->local_session->clip_title[0] = 0;
3400 // This is unique to backups since the path of the backup is different than the
3401 // path of the project.
3402 set_filename(edl->path);
3403 path_list.remove_all_objects();
3407 static inline int gcd(int m, int n)
3410 if( m < n ) { r = m; m = n; n = r; }
3411 while( (r = m % n) != 0 ) { m = n; n = r; }
3415 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3418 if(!width || !height) return 1;
3419 if( width == 720 && (height == 480 || height == 576) ) {
3420 w = 4; h = 3; return 0; // for NTSC and PAL
3422 double ar = (double)width / height;
3423 // square-ish pixels
3424 if( EQUIV(ar, 1.0000) ) return 0;
3425 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3426 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3427 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3428 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3429 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3430 int ww = width, hh = height;
3431 // numerator, denominator must be under mx
3432 int mx = 255, n = gcd(ww, hh);
3433 if( n > 1 ) { ww /= n; hh /= n; }
3434 // search near height in case extra/missing lines
3435 if( ww >= mx || hh >= mx ) {
3436 double err = height; // +/- 2 percent height
3437 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3438 int iw = width, ih = height+i;
3439 if( (n=gcd(iw, ih)) > 1 ) {
3440 int u = iw/n; if( u >= mx ) continue;
3441 int v = ih/n; if( v >= mx ) continue;
3442 double r = (double) u/v, er = fabs(ar-r);
3443 if( er >= err ) continue;
3444 err = er; ww = u; hh = v;
3453 void MWindow::reset_caches()
3455 frame_cache->remove_all();
3456 wave_cache->remove_all();
3457 audio_cache->remove_all();
3458 video_cache->remove_all();
3459 if( cwindow->playback_engine ) {
3460 if( cwindow->playback_engine->audio_cache )
3461 cwindow->playback_engine->audio_cache->remove_all();
3462 if( cwindow->playback_engine->video_cache )
3463 cwindow->playback_engine->video_cache->remove_all();
3465 for(int i = 0; i < vwindows.size(); i++) {
3466 VWindow *vwindow = vwindows[i];
3467 if( !vwindow->is_running() ) continue;
3468 if( !vwindow->playback_engine ) continue;
3469 if( vwindow->playback_engine->audio_cache )
3470 vwindow->playback_engine->audio_cache->remove_all();
3471 if( vwindow->playback_engine->video_cache )
3472 vwindow->playback_engine->video_cache->remove_all();
3476 void MWindow::remove_asset_from_caches(Asset *asset)
3478 frame_cache->remove_asset(asset);
3479 wave_cache->remove_asset(asset);
3480 audio_cache->delete_entry(asset);
3481 video_cache->delete_entry(asset);
3482 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3483 cwindow->playback_engine->audio_cache->delete_entry(asset);
3484 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3485 cwindow->playback_engine->video_cache->delete_entry(asset);
3486 for(int i = 0; i < vwindows.size(); i++) {
3487 VWindow *vwindow = vwindows[i];
3488 if( !vwindow->is_running() ) continue;
3489 if( !vwindow->playback_engine ) continue;
3490 if( vwindow->playback_engine->audio_cache )
3491 vwindow->playback_engine->audio_cache->delete_entry(asset);
3492 if( vwindow->playback_engine->video_cache )
3493 vwindow->playback_engine->video_cache->delete_entry(asset);
3498 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3499 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3501 for(int i = 0; i < drag_assets->total; i++) {
3502 Indexable *indexable = drag_assets->get(i);
3503 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3506 // Remove from VWindow.
3507 for(int i = 0; i < session->drag_clips->total; i++) {
3508 for(int j = 0; j < vwindows.size(); j++) {
3509 VWindow *vwindow = vwindows[j];
3510 if( !vwindow->is_running() ) continue;
3511 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3512 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3513 vwindow->delete_source(1, 1);
3514 vwindow->gui->unlock_window();
3519 for(int i = 0; i < drag_assets->size(); i++) {
3520 for(int j = 0; j < vwindows.size(); j++) {
3521 VWindow *vwindow = vwindows[j];
3522 if( !vwindow->is_running() ) continue;
3523 if(drag_assets->get(i) == vwindow->get_source()) {
3524 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3525 vwindow->delete_source(1, 1);
3526 vwindow->gui->unlock_window();
3531 for(int i = 0; i < drag_assets->size(); i++) {
3532 Indexable *indexable = drag_assets->get(i);
3533 remove_indexfile(indexable);
3536 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3537 if(push_undo) undo->update_undo_before();
3538 if(drag_assets) edl->remove_from_project(drag_assets);
3539 if(drag_clips) edl->remove_from_project(drag_clips);
3540 if(redraw) save_backup();
3541 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3545 gui->lock_window("MWindow::remove_assets_from_project 3");
3546 gui->update(1, 1, 1, 1, 0, 1, 0);
3547 gui->unlock_window();
3549 // Removes from playback here
3550 sync_parameters(CHANGE_ALL);
3553 awindow->gui->async_update_assets();
3556 void MWindow::remove_assets_from_disk()
3559 for(int i = 0; i < session->drag_assets->total; i++)
3561 remove(session->drag_assets->get(i)->path);
3564 remove_assets_from_project(1,
3566 session->drag_assets,
3567 session->drag_clips);
3570 void MWindow::dump_plugins(FILE *fp)
3572 if( !plugindb ) return;
3573 for(int i = 0; i < plugindb->total; i++)
3575 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3576 " synth=%d transition=%d theme=%d %s\n",
3577 plugindb->get(i)->plugin_type,
3578 plugindb->get(i)->audio,
3579 plugindb->get(i)->video,
3580 plugindb->get(i)->realtime,
3581 plugindb->get(i)->multichannel,
3582 plugindb->get(i)->get_synthesis(),
3583 plugindb->get(i)->transition,
3584 plugindb->get(i)->theme,
3585 plugindb->get(i)->title);
3589 void MWindow::dump_edl(FILE *fp)
3595 void MWindow::dump_undo(FILE *fp)
3601 void MWindow::dump_exe(FILE *fp)
3603 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3604 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3606 int ret = -1, n = 100;
3607 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3608 exe_path[len] = 0; strcpy(proc_path, exe_path);
3611 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3614 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3615 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3616 struct tm *tm = localtime(&st.st_mtime);
3618 strftime(mtime, sizeof(mtime), "%F %T", tm);
3619 fprintf(fp,"mtime: %s\n", mtime);
3621 // people hit ctl-c waiting for this
3622 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3623 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3626 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3627 int64_t maxsz = 1024*pagsz;
3628 int64_t size = st.st_size, pos = 0;
3630 while( (bfrsz = size-pos) > 0 ) {
3631 if( bfrsz > maxsz ) bfrsz = maxsz;
3632 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3633 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3634 if( bfr == MAP_FAILED ) break;
3635 sha1.addBytes(bfr, bfrsz);
3640 ret = pos < size ? EIO : 0;
3641 fprintf(fp, "SHA1: ");
3642 uint8_t digest[20]; sha1.computeHash(digest);
3643 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3644 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3645 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3650 void MWindow::trap_hook(FILE *fp, void *vp)
3652 MWindow *mwindow = (MWindow *)vp;
3653 // fprintf(fp, "\nPLUGINS:\n");
3654 // mwindow->dump_plugins(fp);
3655 fprintf(fp, "\nEDL:\n");
3656 mwindow->dump_edl(fp);
3657 fprintf(fp, "\nUNDO:\n");
3658 mwindow->dump_undo(fp);
3659 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
3660 mwindow->dump_exe(fp);
3668 int MWindow::save_defaults()
3670 gui->save_defaults(defaults);
3671 edl->save_defaults(defaults);
3672 session->save_defaults(defaults);
3673 preferences->save_defaults(defaults);
3675 for(int i = 0; i < plugin_guis->total; i++)
3677 // Pointer comparison
3678 plugin_guis->get(i)->save_defaults();
3680 awindow->save_defaults(defaults);
3686 int MWindow::run_script(FileXML *script)
3688 int result = 0, result2 = 0;
3689 while(!result && !result2)
3691 result = script->read_tag();
3694 if(script->tag.title_is("new_project"))
3696 // Run new in immediate mode.
3697 // gui->mainmenu->new_project->run_script(script);
3700 if(script->tag.title_is("record"))
3702 // Run record as a thread. It is a terminal command.
3704 // Will read the complete scipt file without letting record read it if not
3710 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3717 // ================================= synchronization
3720 int MWindow::interrupt_indexes()
3722 mainprogress->cancelled = 1;
3723 mainindexes->interrupt_build();
3729 void MWindow::next_time_format()
3731 switch(edl->session->time_format)
3733 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3734 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3735 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3736 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3737 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3738 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3739 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3742 time_format_common();
3745 void MWindow::prev_time_format()
3747 switch(edl->session->time_format)
3749 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3750 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3751 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3752 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3753 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3754 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3755 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3758 time_format_common();
3761 void MWindow::time_format_common()
3763 gui->lock_window("MWindow::next_time_format");
3764 gui->redraw_time_dependancies();
3767 char string[BCTEXTLEN], string2[BCTEXTLEN];
3768 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3769 gui->show_message(string);
3771 gui->unlock_window();
3775 int MWindow::set_filename(const char *filename)
3777 if( filename != session->filename )
3778 strcpy(session->filename, filename);
3779 if( filename != edl->path )
3780 strcpy(edl->path, filename);
3784 if(filename[0] == 0)
3786 gui->set_title(PROGRAM_NAME);
3791 char string[BCTEXTLEN], string2[BCTEXTLEN];
3792 dir.extract_name(string, filename);
3793 sprintf(string2, PROGRAM_NAME ": %s", string);
3794 gui->set_title(string2);
3807 int MWindow::set_loop_boundaries()
3809 double start = edl->local_session->get_selectionstart();
3810 double end = edl->local_session->get_selectionend();
3818 if(edl->tracks->total_length())
3821 end = edl->tracks->total_length();
3828 if(edl->local_session->loop_playback && start != end)
3830 edl->local_session->loop_start = start;
3831 edl->local_session->loop_end = end;
3842 int MWindow::reset_meters()
3844 cwindow->gui->lock_window("MWindow::reset_meters 1");
3845 cwindow->gui->meters->reset_meters();
3846 cwindow->gui->unlock_window();
3848 for(int j = 0; j < vwindows.size(); j++) {
3849 VWindow *vwindow = vwindows[j];
3850 if( !vwindow->is_running() ) continue;
3851 vwindow->gui->lock_window("MWindow::reset_meters 2");
3852 vwindow->gui->meters->reset_meters();
3853 vwindow->gui->unlock_window();
3856 lwindow->gui->lock_window("MWindow::reset_meters 3");
3857 lwindow->gui->panel->reset_meters();
3858 lwindow->gui->unlock_window();
3860 gui->lock_window("MWindow::reset_meters 4");
3861 gui->reset_meters();
3862 gui->unlock_window();
3867 void MWindow::resync_guis()
3871 gui->lock_window("MWindow::resync_guis");
3872 gui->update(1, 1, 1, 1, 1, 1, 0);
3873 gui->unlock_window();
3875 cwindow->gui->lock_window("MWindow::resync_guis");
3876 cwindow->gui->resize_event(cwindow->gui->get_w(),
3877 cwindow->gui->get_h());
3878 int channels = edl->session->audio_channels;
3879 cwindow->gui->meters->set_meters(channels, 1);
3880 cwindow->gui->flush();
3881 cwindow->gui->unlock_window();
3883 for(int i = 0; i < vwindows.size(); i++) {
3884 VWindow *vwindow = vwindows[i];
3885 if( !vwindow->is_running() ) continue;
3886 vwindow->gui->lock_window("MWindow::resync_guis");
3887 vwindow->gui->resize_event(vwindow->gui->get_w(),
3888 vwindow->gui->get_h());
3889 vwindow->gui->meters->set_meters(channels, 1);
3890 vwindow->gui->flush();
3891 vwindow->gui->unlock_window();
3894 lwindow->gui->lock_window("MWindow::resync_guis");
3895 lwindow->gui->panel->set_meters(channels, 1);
3896 lwindow->gui->flush();
3897 lwindow->gui->unlock_window();
3900 if(((edl->session->output_w % 4) ||
3901 (edl->session->output_h % 4)) &&
3902 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3904 MainError::show_error(
3905 _("This project's dimensions are not multiples of 4 so\n"
3906 "it can't be rendered by OpenGL."));
3911 sync_parameters(CHANGE_ALL);
3914 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3916 File *file = new File;
3917 EDLSession *session = edl->session;
3918 double old_framerate = session->frame_rate;
3919 double old_samplerate = session->sample_rate;
3920 int old_auto_keyframes = session->auto_keyframes;
3921 session->auto_keyframes = 0;
3922 int result = file->open_file(preferences, asset, 1, 0);
3923 if( !result && delete_tracks > 0 )
3924 undo->update_undo_before();
3925 int video_layers = asset->get_video_layers();
3926 if( !result && asset->video_data && vstream < video_layers ) {
3927 // try to get asset up to date, may fail
3928 file->select_video_stream(asset, vstream);
3929 // either way use what was/is there.
3930 double framerate = asset->get_frame_rate();
3931 int width = asset->get_w();
3932 int height = asset->get_h();
3933 // must be multiple of 4 for opengl
3934 width = (width+3) & ~3; height = (height+3) & ~3;
3935 int driver = session->playback_config->vconfig->driver;
3936 int color_model = file->get_best_colormodel(asset, driver);
3937 // color_model = BC_CModels::is_yuv(color_model) ?
3938 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3939 // BC_CModels::is_float(color_model) ?
3940 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3941 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3942 // have alpha for now
3943 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3944 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3945 session->color_model = color_model;
3946 session->output_w = width;
3947 session->output_h = height;
3948 session->frame_rate = framerate;
3949 // not, asset->actual_width/actual_height
3950 asset->width = session->output_w;
3951 asset->height = session->output_h;
3952 asset->frame_rate = session->frame_rate;
3953 create_aspect_ratio(session->aspect_w, session->aspect_h,
3954 session->output_w, session->output_h);
3955 Track *track = edl->tracks->first;
3956 for( Track *next_track=0; track; track=next_track ) {
3957 next_track = track->next;
3958 if( track->data_type != TRACK_VIDEO ) continue;
3959 if( delete_tracks ) {
3960 Edit *edit = track->edits->first;
3961 for( Edit *next_edit=0; edit; edit=next_edit ) {
3962 next_edit = edit->next;
3963 if( edit->channel != vstream ||
3964 !edit->asset || !edit->asset->is_asset ||
3965 !asset->equivalent(*edit->asset,1,1,edl) )
3969 if( track->edits->first ) {
3970 track->track_w = edl->session->output_w;
3971 track->track_h = edl->session->output_h;
3973 else if( delete_tracks )
3974 edl->tracks->delete_track(track);
3977 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3979 if( !result && asset->audio_data && asset->channels > 0 ) {
3980 session->sample_rate = asset->get_sample_rate();
3981 int64_t channel_mask = 0;
3982 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
3983 file->get_audio_for_video(vstream, astream, channel_mask);
3984 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3985 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3987 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3988 if( channels < 1 ) channels = 1;
3989 if( channels > 6 ) channels = 6;
3990 session->audio_tracks = session->audio_channels = channels;
3991 switch( channels ) {
3993 session->achannel_positions[0] = 90;
3994 session->achannel_positions[1] = 150;
3995 session->achannel_positions[2] = 30;
3996 session->achannel_positions[3] = 210;
3997 session->achannel_positions[4] = 330;
3998 session->achannel_positions[5] = 270;
4001 session->achannel_positions[0] = 180;
4002 session->achannel_positions[1] = 0;
4005 session->achannel_positions[1] = 90;
4008 if( !channels ) break;
4009 double t = 0, dt = 360./channels;
4010 for( int i=channels; --i>=0; t+=dt )
4011 session->achannel_positions[i] = int(t+0.5);
4014 remap_audio(MWindow::AUDIO_1_TO_1);
4016 if( delete_tracks ) {
4017 Track *track = edl->tracks->first;
4018 for( Track *next_track=0; track; track=next_track ) {
4019 next_track = track->next;
4020 if( track->data_type != TRACK_AUDIO ) continue;
4021 Edit *edit = track->edits->first;
4022 for( Edit *next_edit=0; edit; edit=next_edit ) {
4023 next_edit = edit->next;
4024 if( !((1<<edit->channel) & channel_mask) ||
4025 !edit->asset || !edit->asset->is_asset ||
4026 !asset->equivalent(*edit->asset,1,1,edl) )
4029 if( !track->edits->first )
4030 edl->tracks->delete_track(track);
4034 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4037 session->auto_keyframes = old_auto_keyframes;
4038 if( !result && delete_tracks > 0 ) {
4040 undo->update_undo_after(_("select asset"), LOAD_ALL);
4046 int MWindow::select_asset(int vtrack, int delete_tracks)
4048 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4050 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4051 if( !track ) return 1;
4052 Edit *edit = track->edits->first;
4053 if( !edit ) return 1;
4054 Asset *asset = edit->asset;
4055 if( !asset || !asset->is_asset ) return 1;
4056 return select_asset(asset, edit->channel, 0, delete_tracks);
4059 void MWindow::dump_plugindb(FILE *fp)
4061 if( !plugindb ) return;
4062 for(int i = 0; i < plugindb->total; i++)
4063 plugindb->get(i)->dump(fp);
4066 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4069 double unit_position = edl->local_session->get_selectionstart(1);
4070 unit_position = patch->track->to_units(unit_position, 0);
4072 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4073 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4076 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4079 double unit_position = edl->local_session->get_selectionstart(1);
4080 unit_position = patch->track->to_units(unit_position, 0);
4082 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4083 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4086 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4089 double unit_position = edl->local_session->get_selectionstart(1);
4090 unit_position = patch->track->to_units(unit_position, 0);
4092 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4093 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4096 PatchGUI *MWindow::get_patchgui(Track *track)
4098 PatchGUI *patchgui = 0;
4099 TimelinePane **panes = gui->pane;
4100 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4101 if( !panes[i] ) continue;
4102 PatchBay *patchbay = panes[i]->patchbay;
4103 if( !patchbay ) continue;
4104 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4105 if( patchbay->patches.values[j]->track == track )
4106 patchgui = patchbay->patches.values[j];