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 "tipwindow.h"
109 #include "trackcanvas.h"
111 #include "tracking.h"
112 #include "trackscroll.h"
114 #include "transition.h"
115 #include "transportque.h"
118 #include "versioninfo.h"
119 #include "videodevice.inc"
120 #include "videowindow.h"
121 #include "vplayback.h"
122 #include "vwindowgui.h"
124 #include "wavecache.h"
127 #include "exportedl.h"
129 #include "defaultformats.h"
130 #include "ntsczones.h"
137 #include <sys/types.h>
138 #include <sys/stat.h>
139 #include <sys/time.h>
140 #include <sys/mman.h>
151 // Hack for libdv to remove glib dependancy
154 // g_log (const char *log_domain,
156 // const char *format,
162 // g_logv (const char *log_domain,
164 // const char *format,
174 ArrayList<PluginServer*>* MWindow::plugindb = 0;
175 Commercials* MWindow::commercials = 0;
181 run_lock = new Mutex("MWindow::run_lock");
182 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
183 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
184 vwindows_lock = new Mutex("MWindow::vwindows_lock");
185 brender_lock = new Mutex("MWindow::brender_lock");
186 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
194 commercial_active = 0;
206 strcpy(cin_lang,"en");
207 channeldb_buz = new ChannelDB;
208 channeldb_v4l2jpeg = new ChannelDB;
212 keyframe_threads = 0;
232 // Need to delete brender temporary here.
235 run_lock->lock("MWindow::~MWindow");
238 //printf("MWindow::~MWindow %d\n", __LINE__);
240 gui->remote_control->deactivate();
243 gui->channel_info->stop();
245 delete create_bd; create_bd = 0;
246 delete create_dvd; create_dvd = 0;
247 delete batch_render; batch_render = 0;
248 delete render; render = 0;
250 if( commercials && !commercials->remove_user() ) commercials = 0;
252 // Save defaults for open plugins
253 plugin_gui_lock->lock("MWindow::~MWindow");
254 for(int i = 0; i < plugin_guis->size(); i++) {
255 plugin_guis->get(i)->hide_gui();
256 delete_plugin(plugin_guis->get(i));
258 plugin_gui_lock->unlock();
259 hide_keyframe_guis();
262 // Give up and go to a movie
263 // cant run valgrind if this is used
265 gui->del_keyboard_listener(
266 (int (BC_WindowBase::*)(BC_WindowBase *))
267 &MWindowGUI::keyboard_listener);
269 // release the hounds
270 if( awindow && awindow->gui ) awindow->gui->close(0);
271 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
272 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
273 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
274 if( twindow && twindow->is_running() ) twindow->close_window();
275 if( wwindow && wwindow->is_running() ) wwindow->close_window();
276 vwindows.remove_all_objects();
278 if( awindow ) awindow->join();
279 if( cwindow ) cwindow->join();
280 if( lwindow ) lwindow->join();
281 if( twindow ) twindow->join();
282 if( wwindow ) wwindow->join();
283 if( gwindow ) gwindow->join();
286 // one at a time, or nouveau chokes
287 #define close_gui(win) if( win ) { \
288 if( win->gui ) win->gui->close(0); \
296 vwindows.remove_all_objects();
301 dead_plugins->remove_all_objects();
302 // must delete theme before destroying plugindb
303 // theme destructor will be deleted by delete_plugins
304 delete theme; theme = 0;
307 keyframe_threads->remove_all_objects();
308 colormodels.remove_all_objects();
309 delete awindow; awindow = 0;
310 delete lwindow; lwindow = 0;
311 delete twindow; twindow = 0;
312 delete wwindow; wwindow = 0;
313 delete gwindow; gwindow = 0;
314 delete cwindow; cwindow = 0;
316 //delete file_server; file_server = 0; // reusable
317 delete mainindexes; mainindexes = 0;
318 delete mainprogress; mainprogress = 0;
319 delete audio_cache; audio_cache = 0; // delete the cache after the assets
320 delete video_cache; video_cache = 0; // delete the cache after the assets
321 delete frame_cache; frame_cache = 0;
322 delete wave_cache; wave_cache = 0;
323 delete plugin_guis; plugin_guis = 0;
324 delete dead_plugins; dead_plugins = 0;
325 delete keyframe_threads; keyframe_threads = 0;
326 delete undo; undo = 0;
327 delete preferences; preferences = 0;
328 delete exportedl; exportedl = 0;
329 delete session; session = 0;
330 delete defaults; defaults = 0;
331 delete assets; assets = 0;
332 delete splash_window; splash_window = 0;
333 if( !edl->Garbage::remove_user() ) edl = 0;
334 delete channeldb_buz;
335 delete channeldb_v4l2jpeg;
336 // This must be last thread to exit
337 delete playback_3d; playback_3d = 0;
338 delete dead_plugin_lock;
339 delete plugin_gui_lock;
340 delete vwindows_lock;
342 delete keyframe_gui_lock;
343 colormodels.remove_all_objects();
344 interlace_project_modes.remove_all_objects();
345 interlace_asset_modes.remove_all_objects();
346 interlace_asset_fixmethods.remove_all_objects();
347 sighandler->terminate();
358 void MWindow::init_error()
360 MainError::init_error(this);
363 void MWindow::finit_error()
365 MainError::finit_error();
368 void MWindow::create_defaults_path(char *string, const char *config_file)
370 // set the .bcast path
373 sprintf(string, "%s/", File::get_config_path());
374 fs.complete_path(string);
375 if(!fs.is_dir(string))
376 fs.create_dir(string);
379 strcat(string, config_file);
381 const char *MWindow::default_std()
383 char buf[BCTEXTLEN], *p = 0;
385 int fd = open(TIMEZONE_NAME, O_RDONLY);
387 int l = read(fd, buf, sizeof(buf)-1);
390 if( buf[l-1] == '\n' ) --l;
396 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
399 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
400 p += strlen(ZONEINFO_STR);
405 for( int i=0; ntsc_zones[i]; ++i ) {
406 if( !strcmp(ntsc_zones[i], p) )
413 for( int i=0; ntsc_zones[i]; ++i ) {
414 if( !strcmp(ntsc_zones[i], p) )
419 //__timezone: Seconds west of UTC. 240sec/deg
420 double tz_deg = -__timezone / 240.;
421 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
422 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
425 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
427 struct formatpresets *fpr;
429 for(fpr = &format_presets[0]; fpr->name; fpr++)
431 if(strcmp(_(fpr->name), preset) == 0)
433 session->audio_channels = fpr->audio_channels;
434 session->audio_tracks = fpr->audio_tracks;
435 session->sample_rate = fpr->sample_rate;
436 session->video_channels = fpr->video_channels;
437 session->video_tracks = fpr->video_tracks;
438 session->frame_rate = fpr->frame_rate;
439 session->output_w = fpr->output_w;
440 session->output_h = fpr->output_h;
441 session->aspect_w = fpr->aspect_w;
442 session->aspect_h = fpr->aspect_h;
443 session->interlace_mode = fpr->interlace_mode;
444 session->color_model = fpr->color_model;
450 const char *MWindow::get_preset_name(int index)
452 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
454 return _(format_presets[index].name);
458 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
460 char path[BCTEXTLEN];
461 // Use user supplied path
463 strcpy(path, config_path);
465 create_defaults_path(path, CONFIG_FILE);
467 defaults = new BC_Hash(path);
472 void MWindow::check_language()
474 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
475 const char *env_lang = getenv("LANGUAGE");
476 if( !env_lang ) env_lang = getenv("LC_ALL");
477 if( !env_lang ) env_lang = getenv("LANG");
479 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
480 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
481 env_lang = curr_lang;
483 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
484 defaults->get("LAST_LANG",last_lang);
485 if( strcmp(env_lang,last_lang)) {
486 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
487 defaults->update("LAST_LANG",env_lang);
488 char plugin_path[BCTEXTLEN];
489 create_defaults_path(plugin_path, PLUGIN_FILE);
490 ::remove(plugin_path);
491 char ladspa_path[BCTEXTLEN];
492 create_defaults_path(ladspa_path, LADSPA_FILE);
493 ::remove(ladspa_path);
496 if( strlen(env_lang) > 1 &&
497 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
498 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
501 strcpy(cin_lang, "en");
504 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
506 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
508 const char *dp = plug_dir;
509 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
510 bp = !*dp && *bp == '/' ? bp+1 : base_path;
516 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
519 FILE *fp = fopen(index_path, "r");
523 char index_line[BCTEXTLEN];
524 int index_version = -1, len = strlen(plugin_dir);
525 if( !fgets(index_line, BCTEXTLEN, fp) ||
526 sscanf(index_line, "%d", &index_version) != 1 ||
527 index_version != PLUGIN_FILE_VERSION ||
528 !fgets(index_line, BCTEXTLEN, fp) ||
529 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
530 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
532 ArrayList<PluginServer*> plugins;
533 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
534 if( index_line[0] == ';' ) continue;
535 if( index_line[0] == '#' ) continue;
536 int type = PLUGIN_TYPE_UNKNOWN;
537 char path[BCTEXTLEN], title[BCTEXTLEN];
539 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
542 PluginServer *server = 0;
544 case PLUGIN_TYPE_BUILTIN:
545 case PLUGIN_TYPE_EXECUTABLE:
546 case PLUGIN_TYPE_LADSPA: {
547 char plugin_path[BCTEXTLEN]; struct stat st;
548 sprintf(plugin_path, "%s/%s", plugin_dir, path);
549 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
552 server = new PluginServer(mwindow, plugin_path, type);
554 case PLUGIN_TYPE_FFMPEG: {
555 server = new_ffmpeg_server(mwindow, path);
558 if( !server ) continue;
559 plugins.append(server);
560 // Create plugin server from index entry
561 server->set_title(title);
562 if( server->read_table(index_line) ) {
569 ret = check_plugin_index(plugins, plugin_dir, ".");
572 add_plugins(plugins);
574 plugins.remove_all_objects();
579 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
580 const char *plug_dir, const char *plug_path)
582 char plugin_path[BCTEXTLEN];
583 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
585 fs.set_filter( "[*.plugin][*.so]" );
586 if( fs.update(plugin_path) )
589 for( int i=0; i<fs.dir_list.total; ++i ) {
590 char fs_path[BCTEXTLEN];
591 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
592 if( fs.is_dir(fs_path) ) {
593 get_plugin_path(plugin_path, plug_dir, fs_path);
594 if( check_plugin_index(plugins, plug_dir, plugin_path) )
597 else if( !plugin_exists(fs_path, plugins) )
604 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
607 plugindb = new ArrayList<PluginServer*>;
609 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
610 create_defaults_path(index_path, PLUGIN_FILE);
611 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
612 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
613 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
614 printf("init plugin index: %s\n", plugin_path);
615 FILE *fp = fopen(index_path,"w");
617 fprintf(stderr,_("MWindow::init_plugins: "
618 "can't create plugin index: %s\n"), index_path);
621 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
622 fprintf(fp, "%s\n", plugin_path);
623 init_plugin_index(mwindow, preferences, fp, plugin_path);
624 init_ffmpeg_index(mwindow, preferences, fp);
626 return load_plugin_index(mwindow, index_path, plugin_path);
629 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
631 char *path = getenv("LADSPA_PATH");
632 char ladspa_path[BCTEXTLEN];
634 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
637 for( int len=0; *path; path+=len ) {
638 char *cp = strchr(path,':');
639 len = !cp ? strlen(path) : cp-path;
640 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
641 memcpy(plugin_path, path, len); plugin_path[len] = 0;
643 char *plugin_dir = FileSystem::basepath(plugin_path);
644 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
645 create_defaults_path(index_path, LADSPA_FILE);
646 cp = index_path + strlen(index_path);
647 for( char *bp=plugin_path; *bp!=0; ++bp )
648 *cp++ = *bp=='/' ? '_' : *bp;
650 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
651 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
652 load_plugin_index(mwindow, index_path, plugin_path);
657 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
658 FILE *fp, const char *plugin_dir)
660 int idx = PLUGIN_IDS;
662 for( int i=0; i<plugindb->size(); ++i ) {
663 PluginServer *server = plugindb->get(i);
664 if( server->dir_idx >= idx )
665 idx = server->dir_idx+1;
668 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
671 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
672 const char *index_path, const char *plugin_dir)
674 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
675 strcpy(plugin_path, path); delete [] path;
676 printf("init ladspa index: %s\n", plugin_dir);
677 FILE *fp = fopen(index_path,"w");
679 fprintf(stderr,_("MWindow::init_ladspa_index: "
680 "can't create plugin index: %s\n"), index_path);
683 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
684 fprintf(fp, "%s\n", plugin_dir);
685 init_plugin_index(mwindow, preferences, fp, plugin_path);
690 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
691 const char *plug_dir, const char *plug_path, int &idx)
693 char plugin_path[BCTEXTLEN];
694 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
696 fs.set_filter( "[*.plugin][*.so]" );
697 int result = fs.update(plugin_path);
698 if( result || !fs.dir_list.total ) return;
701 for( int i=0; i<fs.dir_list.total; ++i ) {
702 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
703 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
704 get_plugin_path(path, plug_dir, fs_path);
705 if( fs.is_dir(fs_path) ) {
706 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
709 if( plugin_exists(path) ) continue;
711 if( stat(fs_path, &st) ) continue;
712 int64_t mtime = st.st_mtime;
713 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
714 result = server.open_plugin(1, preferences, 0, 0);
716 server.write_table(fp, path, vis_id, mtime);
717 server.close_plugin();
719 else if( result == PLUGINSERVER_IS_LAD ) {
722 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
723 ladspa.set_lad_index(lad_index++);
724 result = ladspa.open_plugin(1, preferences, 0, 0);
726 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
727 ladspa.close_plugin();
733 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
735 for( int i=0; i<plugins.size(); ++i )
736 plugindb->append(plugins[i]);
737 plugins.remove_all();
740 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
742 const char *cfg_path = File::get_cindat_path();
743 char msg_path[BCTEXTLEN]; int txt = 0;
745 if( BC_Resources::language[0] ) {
746 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
748 fp = fopen(msg_path, "r");
752 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
754 fp = fopen(msg_path, "r");
757 char text[BCTEXTLEN];
758 char *tp = text, *ep = tp + sizeof(text)-1;
759 char title[BCTEXTLEN];
764 char line[BCTEXTLEN], *cp = line;
765 if( fgets(line,sizeof(line)-1,fp) ) {
766 if( *cp == '#' ) continue;
767 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
770 if( tp > text && *--tp == '\n' ) *tp = 0;
772 tp = !txt ? title : _(title);
773 int idx = plugins.size();
774 while( --idx>=0 && strcmp(plugins[idx]->title, tp) );
776 delete [] plugins[idx]->tip;
777 plugins[idx]->tip = cstrdup(text);
781 if( done > 0 ) break;
783 char *dp = strchr(cp, ':');
785 printf("plugin tips: error on line %d\n", no);
789 while( cp < dp ) *bp++ = *cp++;
794 while( *cp == ' ' || *cp == '\t' ) ++cp;
795 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
800 void MWindow::delete_plugins()
802 plugindb->remove_all_objects();
807 void MWindow::search_plugindb(int do_audio,
812 ArrayList<PluginServer*> &results)
815 for(int i = 0; i < MWindow::plugindb->total; i++)
817 PluginServer *current = MWindow::plugindb->get(i);
819 if(current->audio == do_audio &&
820 current->video == do_video &&
821 (current->realtime == is_realtime || is_realtime < 0) &&
822 current->transition == is_transition &&
823 current->theme == is_theme)
824 results.append(current);
827 // Alphabetize list by title
833 for(int i = 0; i < results.total - 1; i++)
835 PluginServer *value1 = results[i];
836 PluginServer *value2 = results[i + 1];
837 if(strcmp(_(value1->title), _(value2->title)) > 0)
841 results[i + 1] = value1;
847 PluginServer* MWindow::scan_plugindb(char *title,
852 // printf("MWindow::scan_plugindb data_type < 0\n");
856 for(int i = 0; i < plugindb->total; i++)
858 PluginServer *server = plugindb->get(i);
860 !strcasecmp(server->title, title) &&
862 (data_type == TRACK_AUDIO && server->audio) ||
863 (data_type == TRACK_VIDEO && server->video)))
864 return plugindb->get(i);
869 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
871 for( int i=0; i<plugins.size(); ++i )
872 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
876 int MWindow::plugin_exists(char *plugin_path)
878 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
881 void MWindow::init_preferences()
883 preferences = new Preferences;
884 preferences->load_defaults(defaults);
885 session = new MainSession(this);
886 session->load_defaults(defaults);
887 // set x11_host, screens, window_config
888 screens = session->set_default_x11_host();
889 BC_Signals::set_trap_hook(trap_hook, this);
890 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
891 BC_Signals::set_catch_intr(preferences->trap_sigintr);
892 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
893 BC_Trace::enable_locks();
896 BC_Trace::disable_locks();
898 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
899 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
900 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
903 void MWindow::clean_indexes()
908 int oldest_item = -1;
910 char string[BCTEXTLEN];
911 char string2[BCTEXTLEN];
913 // Delete extra indexes
914 fs.set_filter("*.idx");
915 fs.complete_path(preferences->index_directory);
916 fs.update(preferences->index_directory);
917 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
919 // Eliminate directories
924 for(int i = 0; i < fs.dir_list.total && !result; i++)
926 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
927 if(fs.is_dir(string))
929 delete fs.dir_list[i];
930 fs.dir_list.remove_number(i);
935 total_excess = fs.dir_list.total - preferences->index_count;
937 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
938 while(total_excess > 0)
941 for(int i = 0; i < fs.dir_list.total; i++)
943 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
945 if(i == 0 || fs.get_date(string) <= oldest)
947 oldest = fs.get_date(string);
955 fs.join_names(string,
956 preferences->index_directory,
957 fs.dir_list[oldest_item]->name);
958 //printf("MWindow::clean_indexes 1 %s\n", string);
960 perror("delete_indexes");
961 delete fs.dir_list[oldest_item];
962 fs.dir_list.remove_number(oldest_item);
964 // Remove table of contents if it exists
965 strcpy(string2, string);
966 char *ptr = strrchr(string2, '.');
969 //printf("MWindow::clean_indexes 2 %s\n", string2);
970 sprintf(ptr, ".toc");
972 sprintf(ptr, ".mkr");
981 void MWindow::init_awindow()
983 awindow = new AWindow(this);
984 awindow->create_objects();
987 void MWindow::init_gwindow()
989 gwindow = new GWindow(this);
990 gwindow->create_objects();
993 void MWindow::init_tipwindow()
995 TipWindow::load_tips(cin_lang);
997 twindow = new TipWindow(this);
1001 void MWindow::show_warning(int *do_warning, const char *text)
1003 if( do_warning && !*do_warning ) return;
1005 wwindow = new WWindow(this);
1006 wwindow->show_warning(do_warning, text);
1009 int MWindow::wait_warning()
1011 return wwindow->wait_result();
1014 void MWindow::init_theme()
1019 PluginServer *theme_plugin = 0;
1020 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1021 if( plugindb->get(i)->theme &&
1022 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1023 theme_plugin = plugindb->get(i);
1027 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1028 preferences->theme);
1030 const char *default_theme = _(DEFAULT_THEME);
1031 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1032 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1034 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1035 if( plugindb->get(i)->theme &&
1036 !strcasecmp(default_theme, plugindb->get(i)->title) )
1037 theme_plugin = plugindb->get(i);
1042 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1046 PluginServer *plugin = new PluginServer(*theme_plugin);
1047 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1048 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1049 theme_plugin->title);
1053 theme = plugin->new_theme();
1054 theme->mwindow = this;
1055 strcpy(theme->path, plugin->path);
1058 // Load default images & settings
1059 theme->Theme::initialize();
1060 // Load user images & settings
1061 theme->initialize();
1062 // Create menus with user colors
1063 theme->build_menus();
1066 theme->check_used();
1068 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1071 void MWindow::init_3d()
1073 playback_3d = new Playback3D(this);
1074 playback_3d->create_objects();
1077 void MWindow::init_edl()
1080 edl->create_objects();
1081 fill_preset_defaults(default_standard, edl->session);
1082 edl->load_defaults(defaults);
1083 edl->session->brender_start = edl->session->brender_end = 0;
1084 edl->create_default_tracks();
1085 edl->tracks->update_y_pixels(theme);
1088 void MWindow::init_compositor()
1090 cwindow = new CWindow(this);
1091 cwindow->create_objects();
1094 void MWindow::init_levelwindow()
1096 lwindow = new LevelWindow(this);
1097 lwindow->create_objects();
1100 VWindow *MWindow::get_viewer(int start_it, int idx)
1102 vwindows_lock->lock("MWindow::get_viewer");
1103 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1104 if( !vwindow ) idx = vwindows.size();
1105 while( !vwindow && --idx >= 0 ) {
1106 VWindow *vwin = vwindows[idx];
1107 if( !vwin->is_running() || !vwin->get_edl() )
1111 vwindow = new VWindow(this);
1112 vwindow->load_defaults();
1113 vwindow->create_objects();
1114 vwindows.append(vwindow);
1116 vwindows_lock->unlock();
1117 if( start_it ) vwindow->start();
1121 void MWindow::init_cache()
1123 audio_cache = new CICache(preferences);
1124 video_cache = new CICache(preferences);
1125 frame_cache = new FrameCache;
1126 wave_cache = new WaveCache;
1129 void MWindow::init_channeldb()
1131 channeldb_buz->load("channeldb_buz");
1132 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1135 void MWindow::init_menus()
1137 char string[BCTEXTLEN];
1140 BC_CModels::to_text(string, BC_RGB888);
1141 colormodels.append(new ColormodelItem(string, BC_RGB888));
1142 BC_CModels::to_text(string, BC_RGBA8888);
1143 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1144 // BC_CModels::to_text(string, BC_RGB161616);
1145 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1146 // BC_CModels::to_text(string, BC_RGBA16161616);
1147 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1148 BC_CModels::to_text(string, BC_RGB_FLOAT);
1149 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1150 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1151 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1152 BC_CModels::to_text(string, BC_YUV888);
1153 colormodels.append(new ColormodelItem(string, BC_YUV888));
1154 BC_CModels::to_text(string, BC_YUVA8888);
1155 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1156 // BC_CModels::to_text(string, BC_YUV161616);
1157 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1158 // BC_CModels::to_text(string, BC_YUVA16161616);
1159 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1161 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1162 interlace_project_modes.append(new InterlacemodeItem(string, x));
1164 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1165 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1167 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1168 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1170 // Interlacing Modes
1171 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1173 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1174 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1176 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1177 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1179 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1180 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1182 // Interlacing Fixing Methods
1183 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1184 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1185 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1188 void MWindow::init_indexes()
1190 mainindexes = new MainIndexes(this);
1191 mainindexes->start_loop();
1194 void MWindow::init_gui()
1196 gui = new MWindowGUI(this);
1197 gui->lock_window("MWindow::init_gui");
1198 gui->create_objects();
1199 gui->unlock_window();
1200 gui->load_defaults(defaults);
1203 void MWindow::init_signals()
1205 sighandler = new SigHandler;
1206 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1210 void MWindow::init_render()
1212 render = new Render(this);
1213 create_bd = new CreateBD_Thread(this);
1214 create_dvd = new CreateDVD_Thread(this);
1215 batch_render = new BatchRenderThread(this);
1218 void MWindow::init_exportedl()
1220 exportedl = new ExportEDL(this);
1223 void MWindow::init_brender()
1225 if(preferences->use_brender && !brender)
1227 brender_lock->lock("MWindow::init_brender 1");
1228 brender = new BRender(this);
1229 brender->initialize();
1230 session->brender_end = 0;
1231 brender_lock->unlock();
1234 if(!preferences->use_brender && brender)
1236 brender_lock->lock("MWindow::init_brender 2");
1239 session->brender_end = 0;
1240 brender_lock->unlock();
1246 void MWindow::restart_brender()
1248 //printf("MWindow::restart_brender 1\n");
1249 if( !brender_active || !preferences->use_brender ) return;
1250 if( !brender ) return;
1251 int locked = gui->get_window_lock();
1252 if( locked ) gui->unlock_window();
1253 brender->restart(edl);
1254 if( locked ) gui->lock_window("MWindow::restart_brender");
1257 void MWindow::stop_brender()
1259 if( !brender ) return;
1260 int locked = gui->get_window_lock();
1261 if( locked ) gui->unlock_window();
1263 if( locked ) gui->lock_window("MWindow::stop_brender");
1266 int MWindow::brender_available(int position)
1269 brender_lock->lock("MWindow::brender_available 1");
1270 if(brender && brender_active)
1272 if(brender->map_valid)
1274 brender->map_lock->lock("MWindow::brender_available 2");
1275 if(position < brender->map_size &&
1278 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1279 if(brender->map[position] == BRender::RENDERED)
1282 brender->map_lock->unlock();
1285 brender_lock->unlock();
1289 void MWindow::set_brender_active(int v, int update)
1291 if( !preferences->use_brender ) v = 0;
1293 gui->mainmenu->brender_active->set_checked(v);
1295 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1296 edl->session->brender_end = edl->local_session->get_selectionend(1);
1298 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1299 edl->session->brender_end = edl->tracks->total_video_length();
1304 edl->session->brender_start = edl->session->brender_end = 0;
1308 gui->update_timebar(0);
1309 gui->draw_overlays(1);
1313 int MWindow::has_commercials()
1315 return theme->use_commercials;
1318 void MWindow::init_commercials()
1320 if( !commercials ) {
1321 commercials = new Commercials(this);
1322 commercial_active = 0;
1325 commercials->add_user();
1328 void MWindow::commit_commercial()
1330 if( !commercial_active ) return;
1331 commercial_active = 0;
1332 if( !commercials ) return;
1333 commercials->commitDb();
1336 void MWindow::undo_commercial()
1338 if( !commercial_active ) return;
1339 commercial_active = 0;
1340 if( !commercials ) return;
1341 commercials->undoDb();
1344 int MWindow::put_commercial()
1346 double start = edl->local_session->get_selectionstart();
1347 double end = edl->local_session->get_selectionend();
1348 if( start >= end ) return 0;
1350 const char *errmsg = 0;
1352 Tracks *tracks = edl->tracks;
1355 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1356 if( track->data_type != TRACK_VIDEO ) continue;
1357 if( !track->record ) continue;
1358 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1360 int64_t units_start = track->to_units(start,0);
1361 int64_t units_end = track->to_units(end,0);
1362 Edits *edits = track->edits;
1363 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1364 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1365 if(!edit1 && !edit2) continue; // nothing selected
1366 if(!edit2) { // edit2 beyond end of track
1367 edit2 = edits->last;
1368 units_end = edits->length();
1370 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1371 Indexable *indexable = edit1->get_source();
1372 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1375 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1376 if( track->data_type != TRACK_VIDEO ) continue;
1377 if( !track->record ) continue;
1378 int64_t units_start = track->to_units(start,0);
1379 int64_t units_end = track->to_units(end,0);
1380 Edits *edits = track->edits;
1381 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1382 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1383 if(!edit1 && !edit2) continue; // nothing selected
1384 if(!edit2) { // edit2 beyond end of track
1385 edit2 = edits->last;
1386 units_end = edits->length();
1388 Indexable *indexable = edit1->get_source();
1389 Asset *asset = (Asset *)indexable;
1390 File *file = video_cache->check_out(asset, edl);
1391 if( !file ) { errmsg = _("no file"); break; }
1392 int64_t edit_length = units_end - units_start;
1393 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1394 result = commercials->put_clip(file, edit1->channel,
1395 track->from_units(edit_start), track->from_units(edit_length));
1396 video_cache->check_in(asset);
1397 if( result ) { errmsg = _("db failed"); break; }
1400 char string[BCTEXTLEN];
1401 sprintf(string, _("put_commercial: %s"), errmsg);
1402 MainError::show_error(string);
1409 void MWindow::stop_playback(int wait)
1411 int locked = gui->get_window_lock();
1412 if( locked ) gui->unlock_window();
1414 cwindow->playback_engine->stop_playback();
1416 for(int i = 0; i < vwindows.size(); i++) {
1417 VWindow *vwindow = vwindows[i];
1418 if( !vwindow->is_running() ) continue;
1419 vwindow->playback_engine->stop_playback();
1421 if( locked ) gui->lock_window("MWindow::stop_playback");
1424 int MWindow::load_filenames(ArrayList<char*> *filenames,
1426 int update_filename)
1428 ArrayList<EDL*> new_edls;
1429 ArrayList<Asset*> new_assets;
1430 ArrayList<File*> new_files;
1431 const int debug = 0;
1432 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1435 gui->start_hourglass();
1437 // Need to stop playback since tracking depends on the EDL not getting
1441 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1442 undo->update_undo_before();
1445 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1447 // Define new_edls and new_assets to load
1448 int result = 0, ftype = -1;
1449 for(int i = 0; i < filenames->size(); i++)
1452 File *new_file = new File;
1453 Asset *new_asset = new Asset(filenames->get(i));
1454 EDL *new_edl = new EDL;
1455 char string[BCTEXTLEN];
1457 new_edl->create_objects();
1458 new_edl->copy_session(edl);
1459 new_file->set_program(edl->session->program_no);
1461 sprintf(string, _("Loading %s"), new_asset->path);
1462 gui->show_message(string);
1463 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1465 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1466 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1471 // Convert media file to EDL
1473 // Warn about odd image dimensions
1474 if(new_asset->video_data &&
1475 ((new_asset->width % 2) ||
1476 (new_asset->height % 2)))
1478 char string[BCTEXTLEN];
1479 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1483 MainError::show_error(string);
1486 if(new_asset->program >= 0 &&
1487 edl->session->program_no != new_asset->program)
1489 char string[BCTEXTLEN];
1490 sprintf(string, _("%s's index was built for program number %d\n"
1491 "Playback preference is %d.\n Using program %d."),
1492 new_asset->path, new_asset->program,
1493 edl->session->program_no, new_asset->program);
1494 MainError::show_error(string);
1498 if(load_mode != LOADMODE_RESOURCESONLY)
1500 RecordLabels *labels = edl->session->label_cells ?
1501 new RecordLabels(new_file) : 0;
1502 asset_to_edl(new_edl, new_asset, labels);
1503 new_edls.append(new_edl);
1504 new_asset->Garbage::remove_user();
1510 new_assets.append(new_asset);
1514 // Set filename to nothing for assets since save EDL would overwrite them.
1515 if(load_mode == LOADMODE_REPLACE ||
1516 load_mode == LOADMODE_REPLACE_CONCATENATE)
1519 // Reset timeline position
1520 for(int i = 0; i < TOTAL_PANES; i++)
1522 new_edl->local_session->view_start[i] = 0;
1523 new_edl->local_session->track_start[i] = 0;
1531 case FILE_NOT_FOUND:
1532 sprintf(string, _("Failed to open %s"), new_asset->path);
1533 gui->show_message(string, theme->message_error);
1534 gui->update_default_message();
1538 case FILE_UNRECOGNIZED_CODEC:
1541 { IndexFile indexfile(this, new_asset);
1542 if( !(result = indexfile.open_index()) )
1543 indexfile.close_index();
1546 // Test existing EDLs
1547 for(int j = 0; result && j <= new_edls.total; j++) {
1548 Asset *old_asset = j < new_edls.total ?
1549 new_edls[j]->assets->get_asset(new_asset->path) :
1550 edl->assets->get_asset(new_asset->path);
1552 new_asset->copy_from(old_asset,1);
1560 char string[BCTEXTLEN];
1562 fs.extract_name(string, new_asset->path);
1564 strcat(string, _("'s format couldn't be determined."));
1565 new_asset->audio_data = 1;
1566 new_asset->format = FILE_PCM;
1567 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1568 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1569 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1570 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1571 new_asset->signed_ = defaults->get("SIGNED_", 1);
1572 new_asset->header = defaults->get("HEADER", 0);
1574 FileFormat fwindow(this);
1575 fwindow.create_objects(new_asset, string);
1576 result = fwindow.run_window();
1579 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1580 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1581 defaults->update("AUDIO_BITS", new_asset->bits);
1582 defaults->update("BYTE_ORDER", new_asset->byte_order);
1583 defaults->update("SIGNED_", new_asset->signed_);
1584 defaults->update("HEADER", new_asset->header);
1591 // Recalculate length
1593 new_file = new File;
1594 result = new_file->open_file(preferences, new_asset, 1, 0);
1596 if(load_mode != LOADMODE_RESOURCESONLY)
1598 RecordLabels *labels = edl->session->label_cells ?
1599 new RecordLabels(new_file) : 0;
1600 asset_to_edl(new_edl, new_asset, labels);
1601 new_edls.append(new_edl);
1602 new_asset->Garbage::remove_user();
1608 new_assets.append(new_asset);
1622 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1623 xml_file.read_from_file(filenames->get(i));
1624 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1625 const char *cin_version = 0;
1626 while( !xml_file.read_tag() ) {
1627 if( xml_file.tag.title_is("EDL") ) {
1628 cin_version = xml_file.tag.get_property("VERSION");
1633 if( !cin_version ) {
1634 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1635 char string[BCTEXTLEN];
1636 sprintf(string,_("Unknown %s"), filenames->get(i));
1637 gui->show_message(string);
1641 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1642 char string[BCTEXTLEN];
1643 snprintf(string, sizeof(string),
1644 _("Warning: XML from cinelerra version %s\n"
1645 "Session data may be incompatible."), cin_version);
1646 show_warning(&preferences->warn_version, string);
1648 if(load_mode == LOADMODE_NESTED)
1650 // Load temporary EDL for nesting.
1651 EDL *nested_edl = new EDL;
1652 nested_edl->create_objects();
1653 nested_edl->set_path(filenames->get(i));
1654 nested_edl->load_xml(&xml_file, LOAD_ALL);
1655 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1656 edl_to_nested(new_edl, nested_edl);
1657 nested_edl->Garbage::remove_user();
1661 // Load EDL for pasting
1662 new_edl->load_xml(&xml_file, LOAD_ALL);
1663 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1664 test_plugins(new_edl, filenames->get(i));
1665 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1667 if(load_mode == LOADMODE_REPLACE ||
1668 load_mode == LOADMODE_REPLACE_CONCATENATE)
1670 strcpy(session->filename, filenames->get(i));
1671 strcpy(new_edl->local_session->clip_title,
1674 set_filename(new_edl->local_session->clip_title);
1677 if( load_mode == LOADMODE_RESOURCESONLY ) {
1678 strcpy(new_edl->local_session->clip_title,
1681 time_t t = !stat(filenames->get(i),&st) ?
1682 st.st_mtime : time(&t);
1683 ctime_r(&t, new_edl->local_session->clip_notes);
1687 new_edls.append(new_edl);
1693 // edls are in new_edls
1694 if( result && new_edl ) new_edl->Garbage::remove_user();
1695 // assets are copied
1696 if( new_asset ) new_asset->Garbage::remove_user();
1698 // Store for testing index
1699 new_files.append(new_file);
1702 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1706 gui->reset_default_message();
1707 gui->default_message();
1711 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1714 // Don't back up here.
1717 // For pasting, clear the active region
1718 if(load_mode == LOADMODE_PASTE ||
1719 load_mode == LOADMODE_NESTED)
1721 double start = edl->local_session->get_selectionstart();
1722 double end = edl->local_session->get_selectionend();
1723 if(!EQUIV(start, end))
1726 edl->session->labels_follow_edits,
1727 edl->session->plugins_follow_edits,
1728 edl->session->autos_follow_edits);
1731 paste_edls(&new_edls, load_mode, 0, -1,
1732 edl->session->labels_follow_edits,
1733 edl->session->plugins_follow_edits,
1734 edl->session->autos_follow_edits,
1741 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1743 // Add new assets to EDL and schedule assets for index building.
1744 int got_indexes = 0;
1745 for(int i = 0; i < new_edls.size(); i++)
1747 EDL *new_edl = new_edls[i];
1748 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1750 mainindexes->add_next_asset(0,
1751 new_edl->nested_edls->get(j));
1753 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1758 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1759 for(int i = 0; i < new_assets.size(); i++)
1761 Asset *new_asset = new_assets[i];
1765 for(int j = 0; j < new_files.size(); j++)
1767 new_file = new_files[j];
1768 if(!strcmp(new_file->asset->path,
1776 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1778 edl->assets->update(new_asset);
1780 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1782 // Start examining next batch of index files
1783 if(got_indexes) mainindexes->start_build();
1784 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1787 Track *track = edl->tracks->first;
1790 for(int j = 0; j < track->plugin_set.size(); j++)
1792 PluginSet *plugins = track->plugin_set[j];
1793 Plugin *plugin = plugins->get_first_plugin();
1797 if(load_mode == LOADMODE_REPLACE ||
1798 load_mode == LOADMODE_REPLACE_CONCATENATE)
1800 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1803 show_plugin(plugin);
1807 plugin = (Plugin*)plugin->next;
1811 track = track->next;
1814 // if just opening one new resource in replace mode
1815 if( ftype != FILE_IS_XML &&
1816 ( load_mode == LOADMODE_REPLACE ||
1817 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1819 edl->session->proxy_scale = 1;
1820 edl->session->proxy_use_scaler = 0;
1821 edl->session->proxy_auto_scale = 0;
1822 edl->local_session->preview_start = 0;
1823 edl->local_session->preview_end = edl->tracks->total_playable_length();
1824 edl->local_session->loop_playback = 0;
1825 edl->local_session->set_selectionstart(0);
1826 edl->local_session->set_selectionend(0);
1827 set_brender_active(0, 0);
1832 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
1833 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
1834 ArrayList<Indexable *> orig_idxbls;
1835 for( int i=0; i<new_assets.size(); ++i )
1836 orig_idxbls.append(new_assets.get(i));
1837 for( int i=0; i<new_edls.size(); ++i ) {
1838 EDL *new_edl = new_edls[i];
1839 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
1840 if( track->data_type != TRACK_VIDEO ) continue;
1841 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1842 Indexable *idxbl = (Indexable *)edit->asset;
1843 if( !idxbl ) continue;
1844 if( !idxbl->have_video() ) continue;
1845 if( edit->channel != 0 ) continue; // first layer only
1846 orig_idxbls.append(edit->asset);
1850 gui->unlock_window(); // to update progress bar
1851 render_proxy(orig_idxbls);
1852 gui->lock_window("MWindow::load_filenames");
1855 // need to update undo before project, since mwindow is unlocked & a new load
1856 // can begin here. Should really prevent loading until we're done.
1857 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1858 undo->update_undo_after(_("load"), LOAD_ALL);
1860 for(int i = 0; i < new_edls.size(); i++)
1862 new_edls[i]->remove_user();
1864 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1866 new_edls.remove_all();
1868 for(int i = 0; i < new_assets.size(); i++)
1870 new_assets[i]->Garbage::remove_user();
1873 new_assets.remove_all();
1874 new_files.remove_all_objects();
1877 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1878 if(load_mode == LOADMODE_REPLACE ||
1879 load_mode == LOADMODE_REPLACE_CONCATENATE)
1881 session->changes_made = 0;
1885 session->changes_made = 1;
1888 gui->stop_hourglass();
1891 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1892 update_project(load_mode);
1894 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1899 void MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
1901 Asset *format_asset = new Asset;
1902 format_asset->format = FILE_FFMPEG;
1903 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
1904 ProxyRender proxy_render(this, format_asset);
1905 int new_scale = edl->session->proxy_scale;
1906 int use_scaler = edl->session->proxy_use_scaler;
1908 for( int i=0; i<new_idxbls.size(); ++i ) {
1909 Indexable *orig = new_idxbls.get(i);
1910 Asset *proxy = proxy_render.add_original(orig, new_scale);
1911 if( !proxy ) continue;
1913 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
1914 int got_it = exists && // if proxy exists, and is newer than orig
1915 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
1916 if( got_it ) continue;
1917 proxy_render.add_needed(orig, proxy);
1920 // render needed proxies
1921 int result = proxy_render.create_needed_proxies(new_scale);
1923 add_proxy(use_scaler,
1924 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
1926 format_asset->remove_user();
1929 void MWindow::test_plugins(EDL *new_edl, char *path)
1931 char string[BCTEXTLEN];
1933 // Do a check weather plugins exist
1934 for(Track *track = new_edl->tracks->first; track; track = track->next)
1936 for(int k = 0; k < track->plugin_set.total; k++)
1938 PluginSet *plugin_set = track->plugin_set[k];
1939 for(Plugin *plugin = (Plugin*)plugin_set->first;
1941 plugin = (Plugin*)plugin->next)
1943 if(plugin->plugin_type == PLUGIN_STANDALONE)
1945 // ok we need to find it in plugindb
1946 int plugin_found = 0;
1948 for(int j = 0; j < plugindb->size(); j++)
1950 PluginServer *server = plugindb->get(j);
1952 !strcasecmp(server->title, plugin->title) &&
1953 ((track->data_type == TRACK_AUDIO && server->audio) ||
1954 (track->data_type == TRACK_VIDEO && server->video)) &&
1955 (!server->transition))
1962 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1963 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1964 "effect", plugin->title,
1966 MainError::show_error(string);
1972 for(Edit *edit = (Edit*)track->edits->first;
1974 edit = (Edit*)edit->next)
1976 if (edit->transition)
1978 // ok we need to find transition in plugindb
1980 int transition_found = 0;
1981 for(int j = 0; j < plugindb->size(); j++)
1983 PluginServer *server = plugindb->get(j);
1985 !strcasecmp(server->title, edit->transition->title) &&
1986 ((track->data_type == TRACK_AUDIO && server->audio) ||
1987 (track->data_type == TRACK_VIDEO && server->video)) &&
1988 (server->transition))
1989 transition_found = 1;
1992 if (!transition_found)
1995 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1996 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1997 "transition", edit->transition->title,
1999 MainError::show_error(string);
2007 void MWindow::init_shm()
2009 // Fix shared memory
2010 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
2012 fprintf(fd, "0x7fffffff");
2017 fd = fopen("/proc/sys/kernel/shmmax", "r");
2019 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
2024 fscanf(fd, "%jd", &result);
2027 if(result < 0x7fffffff) {
2028 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
2029 "you probably need to be root, or:\n"
2030 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
2031 "before trying to start cinelerra.\n"
2032 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
2036 void MWindow::create_objects(int want_gui,
2040 const int debug = 0;
2041 if(debug) PRINT_TRACE
2043 // For some reason, init_signals must come after show_splash or the signals won't
2046 if(debug) PRINT_TRACE
2049 if(debug) PRINT_TRACE
2052 if(debug) PRINT_TRACE
2053 default_standard = default_std();
2054 init_defaults(defaults, config_path);
2058 splash_window->operation->update(_("Initializing Plugins"));
2059 init_plugins(this, preferences);
2060 if(debug) PRINT_TRACE
2061 init_ladspa_plugins(this, preferences);
2062 if(debug) PRINT_TRACE
2063 init_plugin_tips(*plugindb, cin_lang);
2065 splash_window->operation->update(_("Initializing GUI"));
2066 if(debug) PRINT_TRACE
2069 if(debug) PRINT_TRACE
2073 splash_window->operation->update(_("Initializing Fonts"));
2074 char string[BCTEXTLEN];
2075 strcpy(string, preferences->plugin_dir);
2076 strcat(string, "/" FONT_SEARCHPATH);
2077 BC_Resources::init_fontconfig(string);
2078 if(debug) PRINT_TRACE
2080 // Initialize before too much else is running
2081 // Preferences & theme are required for building MPEG table of contents
2083 // Default project created here
2085 if(debug) PRINT_TRACE
2088 if(debug) PRINT_TRACE
2093 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2096 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2098 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2099 if(session->show_vwindow)
2100 get_viewer(1, DEFAULT_VWINDOW);
2101 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2104 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2107 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2110 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2113 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2116 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2119 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2124 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2125 mainprogress = new MainProgress(this, gui);
2126 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2127 undo = new MainUndo(this);
2129 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2131 plugin_guis = new ArrayList<PluginServer*>;
2132 dead_plugins = new ArrayList<PluginServer*>;
2133 keyframe_threads = new ArrayList<KeyFrameThread*>;
2135 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2138 session->show_vwindow);
2140 // Show all vwindows
2141 // if(session->show_vwindow) {
2142 // for(int j = 0; j < vwindows.size(); j++) {
2143 // VWindow *vwindow = vwindows[j];
2144 // if( !vwindow->is_running() ) continue;
2145 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2148 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2149 // vwindow->gui->lock_window("MWindow::create_objects 1");
2150 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2151 // vwindow->gui->show_window();
2152 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2153 // vwindow->gui->unlock_window();
2158 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2160 if(session->show_cwindow)
2162 cwindow->gui->lock_window("MWindow::create_objects 1");
2163 cwindow->gui->show_window();
2164 cwindow->gui->unlock_window();
2167 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2168 if(session->show_awindow)
2170 awindow->gui->lock_window("MWindow::create_objects 1");
2171 awindow->gui->show_window();
2172 awindow->gui->unlock_window();
2175 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2176 if(session->show_lwindow)
2178 lwindow->gui->lock_window("MWindow::create_objects 1");
2179 lwindow->gui->show_window();
2180 lwindow->gui->unlock_window();
2183 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2185 (int)timer.get_difference(),
2187 if(session->show_gwindow)
2189 gwindow->gui->lock_window("MWindow::create_objects 1");
2190 gwindow->gui->show_window();
2191 gwindow->gui->unlock_window();
2194 if(debug) PRINT_TRACE
2196 gui->lock_window("MWindow::create_objects 1");
2197 gui->mainmenu->load_defaults(defaults);
2198 gui->mainmenu->update_toggles(0);
2199 gui->update_patchbay();
2200 gui->draw_canvas(0, 0);
2201 gui->draw_cursor(1);
2203 gui->raise_window();
2204 gui->unlock_window();
2206 if(debug) PRINT_TRACE
2208 if(preferences->use_tipwindow)
2210 if(debug) PRINT_TRACE
2212 gui->add_keyboard_listener(
2213 (int (BC_WindowBase::*)(BC_WindowBase *))
2214 &MWindowGUI::keyboard_listener);
2218 if(debug) PRINT_TRACE
2220 BC_WindowBase::get_resources()->vframe_shm = 1;
2224 void MWindow::show_splash()
2226 #include "data/heroine_logo9_png.h"
2227 VFrame *frame = new VFramePng(heroine_logo9_png);
2228 BC_DisplayInfo dpyi;
2229 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2230 int rr = (rw < rh ? rw : rh) / 4;
2231 splash_window = new SplashGUI(frame, rr, rr);
2232 splash_window->create_objects();
2235 void MWindow::hide_splash()
2238 delete splash_window;
2243 void MWindow::start()
2247 // vwindows[DEFAULT_VWINDOW]->start();
2258 playback_3d->start();
2264 run_lock->lock("MWindow::run");
2268 brender_lock->lock("MWindow::run 1");
2269 delete brender; brender = 0;
2270 brender_lock->unlock();
2272 interrupt_indexes();
2278 void MWindow::show_vwindow()
2280 int total_running = 0;
2281 session->show_vwindow = 1;
2283 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2284 // Raise all windows which are visible
2285 for(int j = 0; j < vwindows.size(); j++) {
2286 VWindow *vwindow = vwindows[j];
2287 if( !vwindow->is_running() ) continue;
2288 vwindow->gui->lock_window("MWindow::show_vwindow");
2289 vwindow->gui->show_window(0);
2290 vwindow->gui->raise_window();
2291 vwindow->gui->flush();
2292 vwindow->gui->unlock_window();
2296 // If no windows visible
2299 get_viewer(1, DEFAULT_VWINDOW);
2302 gui->mainmenu->show_vwindow->set_checked(1);
2305 void MWindow::show_awindow()
2307 session->show_awindow = 1;
2308 awindow->gui->lock_window("MWindow::show_awindow");
2309 awindow->gui->show_window();
2310 awindow->gui->raise_window();
2311 awindow->gui->flush();
2312 awindow->gui->unlock_window();
2313 gui->mainmenu->show_awindow->set_checked(1);
2316 char *MWindow::get_cwindow_display()
2318 char *x11_host = screens < 2 || session->window_config == 0 ?
2319 session->a_x11_host : session->b_x11_host;
2320 return *x11_host ? x11_host : 0;
2323 void MWindow::show_cwindow()
2325 session->show_cwindow = 1;
2326 cwindow->show_window();
2327 gui->mainmenu->show_cwindow->set_checked(1);
2330 void MWindow::show_gwindow()
2332 session->show_gwindow = 1;
2334 gwindow->gui->lock_window("MWindow::show_gwindow");
2335 gwindow->gui->show_window();
2336 gwindow->gui->raise_window();
2337 gwindow->gui->flush();
2338 gwindow->gui->unlock_window();
2340 gui->mainmenu->show_gwindow->set_checked(1);
2342 void MWindow::hide_gwindow()
2344 session->show_gwindow = 0;
2346 gwindow->gui->lock_window("MWindow::show_gwindow");
2347 gwindow->gui->hide_window();
2348 gwindow->gui->unlock_window();
2351 void MWindow::show_lwindow()
2353 session->show_lwindow = 1;
2354 lwindow->gui->lock_window("MWindow::show_lwindow");
2355 lwindow->gui->show_window();
2356 lwindow->gui->raise_window();
2357 lwindow->gui->flush();
2358 lwindow->gui->unlock_window();
2359 gui->mainmenu->show_lwindow->set_checked(1);
2362 int MWindow::tile_windows(int window_config)
2364 int need_reload = 0;
2365 int play_config = window_config==0 ? 0 : 1;
2366 edl->session->playback_config->load_defaults(defaults, play_config);
2367 session->default_window_positions(window_config);
2368 if( screens == 1 ) {
2369 gui->default_positions();
2370 sync_parameters(CHANGE_ALL);
2377 void MWindow::toggle_loop_playback()
2379 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2380 set_loop_boundaries();
2383 gui->draw_overlays(1);
2384 sync_parameters(CHANGE_PARAMS);
2387 //void MWindow::set_titles(int value)
2389 // edl->session->show_titles = value;
2390 // trackmovement(edl->local_session->track_start);
2393 void MWindow::set_screens(int value)
2398 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2400 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2401 edl->session->auto_keyframes = value;
2402 gui->mbuttons->edit_panel->keyframe->update(value);
2404 if(lock_mwindow) gui->unlock_window();
2406 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2407 cwindow->gui->edit_panel->keyframe->update(value);
2408 cwindow->gui->flush();
2409 if(lock_cwindow) cwindow->gui->unlock_window();
2412 void MWindow::set_auto_visibility(Autos *autos, int value)
2414 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2415 edl->session->auto_conf->plugins = value;
2416 else if( autos->autoidx >= 0 )
2417 edl->session->auto_conf->autos[autos->autoidx] = value;
2421 gui->update(0, 1, 0, 0, 0, 0, 0);
2422 gui->mainmenu->update_toggles(1);
2423 gui->unlock_window();
2424 gwindow->gui->update_toggles(1);
2425 gui->lock_window("MWindow::set_auto_visibility");
2428 void MWindow::set_keyframe_type(int mode)
2430 gui->lock_window("MWindow::set_keyframe_type");
2431 edl->local_session->floatauto_type = mode;
2432 gui->mainmenu->update_toggles(0);
2433 gui->unlock_window();
2436 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2438 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2439 edl->session->editing_mode = new_editing_mode;
2440 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2441 gui->mbuttons->edit_panel->update();
2442 gui->set_editing_mode(1);
2443 if(lock_mwindow) gui->unlock_window();
2446 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2447 cwindow->gui->edit_panel->update();
2448 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2449 if(lock_cwindow) cwindow->gui->unlock_window();
2453 void MWindow::toggle_editing_mode()
2455 int mode = edl->session->editing_mode;
2456 if( mode == EDITING_ARROW )
2457 set_editing_mode(EDITING_IBEAM, 0, 1);
2459 set_editing_mode(EDITING_ARROW, 0, 1);
2463 void MWindow::set_labels_follow_edits(int value)
2465 gui->lock_window("MWindow::set_labels_follow_edits");
2466 edl->session->labels_follow_edits = value;
2467 gui->mbuttons->edit_panel->locklabels->update(value);
2468 gui->mainmenu->labels_follow_edits->set_checked(value);
2470 gui->unlock_window();
2473 void MWindow::sync_parameters(int change_type)
2475 if( in_destructor ) return;
2477 // Sync engines which are playing back
2478 if(cwindow->playback_engine->is_playing_back)
2480 if(change_type == CHANGE_PARAMS)
2482 // TODO: block keyframes until synchronization is done
2483 cwindow->playback_engine->sync_parameters(edl);
2488 int command = cwindow->playback_engine->command->command;
2489 cwindow->playback_engine->que->send_command(STOP,
2493 // Waiting for tracking to finish would make the restart position more
2494 // accurate but it can't lock the window to stop tracking for some reason.
2495 // Not waiting for tracking gives a faster response but restart position is
2496 // only as accurate as the last tracking update.
2497 cwindow->playback_engine->interrupt_playback(0);
2498 cwindow->playback_engine->que->send_command(command,
2507 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2514 void MWindow::age_caches()
2516 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2518 // preferences->cache_size,
2519 // audio_cache->get_memory_usage(1),
2520 // video_cache->get_memory_usage(1),
2521 // frame_cache->get_memory_usage(),
2522 // wave_cache->get_memory_usage(),
2524 frame_cache->age_cache(512);
2525 wave_cache->age_cache(8192);
2527 int64_t memory_usage;
2528 int64_t prev_memory_usage = 0;
2530 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2531 while( !result && prev_memory_usage !=
2532 (memory_usage=video_cache->get_memory_usage(1)) &&
2533 memory_usage > video_size ) {
2534 video_cache->delete_oldest();
2535 prev_memory_usage = memory_usage;
2538 prev_memory_usage = 0;
2540 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2541 while( !result && prev_memory_usage !=
2542 (memory_usage=audio_cache->get_memory_usage(1)) &&
2543 memory_usage > audio_size ) {
2544 audio_cache->delete_oldest();
2545 prev_memory_usage = memory_usage;
2549 void MWindow::reset_android_remote()
2551 gui->use_android_remote(preferences->android_remote);
2555 void MWindow::show_keyframe_gui(Plugin *plugin)
2557 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2558 // Find existing thread
2559 for(int i = 0; i < keyframe_threads->size(); i++)
2561 if(keyframe_threads->get(i)->plugin == plugin)
2563 keyframe_threads->get(i)->start_window(plugin, 0);
2564 keyframe_gui_lock->unlock();
2569 // Find unused thread
2570 for(int i = 0; i < keyframe_threads->size(); i++)
2572 if(!keyframe_threads->get(i)->plugin)
2574 keyframe_threads->get(i)->start_window(plugin, 0);
2575 keyframe_gui_lock->unlock();
2580 // Create new thread
2581 KeyFrameThread *thread = new KeyFrameThread(this);
2582 keyframe_threads->append(thread);
2583 thread->start_window(plugin, 0);
2585 keyframe_gui_lock->unlock();
2592 void MWindow::show_plugin(Plugin *plugin)
2597 // Remove previously deleted plugin GUIs
2598 dead_plugin_lock->lock("MWindow::show_plugin");
2599 dead_plugins->remove_all_objects();
2600 dead_plugin_lock->unlock();
2602 //printf("MWindow::show_plugin %d\n", __LINE__);
2606 plugin_gui_lock->lock("MWindow::show_plugin");
2607 for(int i = 0; i < plugin_guis->total; i++)
2609 // Pointer comparison
2610 if(plugin_guis->get(i)->plugin == plugin)
2612 plugin_guis->get(i)->raise_window();
2619 //printf("MWindow::show_plugin 1\n");
2620 if( !done && !plugin->track ) {
2621 printf("MWindow::show_plugin track not defined.\n");
2625 PluginServer *server = scan_plugindb(plugin->title,
2626 plugin->track->data_type);
2628 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2629 if(server && server->uses_gui)
2631 PluginServer *gui = new PluginServer(*server);
2632 plugin_guis->append(gui);
2633 // Needs mwindow to do GUI
2634 gui->set_mwindow(this);
2635 gui->open_plugin(0, preferences, edl, plugin);
2640 plugin_gui_lock->unlock();
2641 //printf("MWindow::show_plugin %d\n", __LINE__);
2644 //printf("MWindow::show_plugin 2\n");
2647 void MWindow::hide_plugin(Plugin *plugin, int lock)
2650 // Update the toggle
2651 gui->lock_window("MWindow::hide_plugin");
2652 gui->update(0, 1, 0, 0, 0, 0, 0);
2653 gui->unlock_window();
2655 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2656 for(int i = 0; i < plugin_guis->total; i++)
2658 if(plugin_guis->get(i)->plugin == plugin)
2660 PluginServer *ptr = plugin_guis->get(i);
2661 plugin_guis->remove(ptr);
2662 if(lock) plugin_gui_lock->unlock();
2663 // Last command executed in client side close
2664 // Schedule for deletion
2671 if(lock) plugin_gui_lock->unlock();
2674 void MWindow::delete_plugin(PluginServer *plugin)
2676 dead_plugin_lock->lock("MWindow::delete_plugin");
2677 dead_plugins->append(plugin);
2678 dead_plugin_lock->unlock();
2681 void MWindow::hide_plugins()
2683 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2684 while(plugin_guis->size())
2686 PluginServer *ptr = plugin_guis->get(0);
2687 plugin_guis->remove(ptr);
2688 plugin_gui_lock->unlock();
2689 // Last command executed in client side close
2690 // Schedule for deletion
2693 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2695 plugin_gui_lock->unlock();
2697 hide_keyframe_guis();
2700 void MWindow::hide_keyframe_guis()
2702 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2703 for(int i = 0; i < keyframe_threads->size(); i++)
2705 keyframe_threads->get(i)->close_window();
2707 keyframe_gui_lock->unlock();
2710 void MWindow::hide_keyframe_gui(Plugin *plugin)
2712 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2713 for(int i = 0; i < keyframe_threads->size(); i++)
2715 if(keyframe_threads->get(i)->plugin == plugin)
2717 keyframe_threads->get(i)->close_window();
2721 keyframe_gui_lock->unlock();
2724 void MWindow::update_keyframe_guis()
2726 // Send new configuration to keyframe GUI's
2727 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2728 for(int i = 0; i < keyframe_threads->size(); i++)
2730 KeyFrameThread *ptr = keyframe_threads->get(i);
2731 if(edl->tracks->plugin_exists(ptr->plugin))
2735 ptr->close_window();
2738 keyframe_gui_lock->unlock();
2741 void MWindow::update_plugin_guis(int do_keyframe_guis)
2743 // Send new configuration to plugin GUI's
2744 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2746 for(int i = 0; i < plugin_guis->size(); i++)
2748 PluginServer *ptr = plugin_guis->get(i);
2749 if(edl->tracks->plugin_exists(ptr->plugin))
2753 // Schedule for deletion if no plugin
2754 plugin_guis->remove_number(i);
2763 // Change plugin variable if not visible
2764 Track *track = edl->tracks->first;
2767 for(int i = 0; i < track->plugin_set.size(); i++)
2769 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2773 for(int i = 0; i < plugin_guis->size(); i++)
2775 PluginServer *server = plugin_guis->get(i);
2776 if(server->plugin == plugin)
2783 if(!got_it) plugin->show = 0;
2785 plugin = (Plugin*)plugin->next;
2789 track = track->next;
2792 plugin_gui_lock->unlock();
2795 if(do_keyframe_guis) update_keyframe_guis();
2798 int MWindow::plugin_gui_open(Plugin *plugin)
2801 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2802 for(int i = 0; i < plugin_guis->total; i++)
2804 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2810 plugin_gui_lock->unlock();
2814 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2816 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2817 for(int i = 0; i < plugin_guis->total; i++)
2819 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2821 plugin_guis->get(i)->render_gui(data);
2825 plugin_gui_lock->unlock();
2828 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2830 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2831 for(int i = 0; i < plugin_guis->total; i++)
2833 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2835 plugin_guis->get(i)->render_gui(data, size);
2839 plugin_gui_lock->unlock();
2843 void MWindow::update_plugin_states()
2845 plugin_gui_lock->lock("MWindow::update_plugin_states");
2846 for(int i = 0; i < plugin_guis->total; i++)
2850 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2851 PluginServer *src_plugingui = plugin_guis->get(i);
2853 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2854 for(Track *track = edl->tracks->first;
2856 track = track->next)
2859 j < track->plugin_set.total && !result;
2862 PluginSet *plugin_set = track->plugin_set[j];
2863 for(Plugin *plugin = (Plugin*)plugin_set->first;
2865 plugin = (Plugin*)plugin->next)
2867 if(plugin == src_plugin &&
2868 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2874 // Doesn't exist anymore
2877 hide_plugin(src_plugin, 0);
2881 plugin_gui_lock->unlock();
2885 void MWindow::update_plugin_titles()
2887 for(int i = 0; i < plugin_guis->total; i++)
2889 plugin_guis->get(i)->update_title();
2893 int MWindow::asset_to_edl(EDL *new_edl,
2895 RecordLabels *labels)
2897 const int debug = 0;
2898 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2901 // Keep frame rate, sample rate, and output size unchanged.
2902 // These parameters would revert the project if VWindow displayed an asset
2903 // of different size than the project.
2904 if(new_asset->video_data)
2906 new_edl->session->video_tracks = new_asset->layers;
2909 new_edl->session->video_tracks = 0;
2911 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2917 if(new_asset->audio_data)
2919 new_edl->session->audio_tracks = new_asset->channels;
2922 new_edl->session->audio_tracks = 0;
2923 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2925 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2926 new_edl->create_default_tracks();
2927 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2928 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2932 //printf("MWindow::asset_to_edl 3\n");
2933 new_edl->insert_asset(new_asset,
2938 //printf("MWindow::asset_to_edl 3\n");
2939 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2941 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2942 if(edl->session->cursor_on_frames)
2944 double length = new_edl->tracks->total_length();
2945 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2946 new_edl->tracks->clear(length, edl_length, 1, 1);
2952 char string[BCTEXTLEN];
2954 fs.extract_name(string, new_asset->path);
2955 //printf("MWindow::asset_to_edl 3\n");
2957 strcpy(new_edl->local_session->clip_title, string);
2958 //printf("MWindow::asset_to_edl 4 %s\n", string);
2959 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2964 int MWindow::edl_to_nested(EDL *new_edl,
2968 // Keep frame rate, sample rate, and output size unchanged.
2969 // These parameters would revert the project if VWindow displayed an asset
2970 // of different size than the project.
2974 // Nest all video & audio outputs
2975 new_edl->session->video_tracks = 1;
2976 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2977 new_edl->create_default_tracks();
2981 new_edl->insert_asset(0,
2987 char string[BCTEXTLEN];
2989 fs.extract_name(string, nested_edl->path);
2990 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2992 strcpy(new_edl->local_session->clip_title, string);
2997 // Reset everything after a load.
2998 void MWindow::update_project(int load_mode)
3000 const int debug = 0;
3002 if(debug) PRINT_TRACE
3004 edl->tracks->update_y_pixels(theme);
3006 if(debug) PRINT_TRACE
3008 if(load_mode == LOADMODE_REPLACE ||
3009 load_mode == LOADMODE_REPLACE_CONCATENATE)
3014 gui->update(1, 1, 1, 1, 1, 1, 1);
3015 if(debug) PRINT_TRACE
3016 gui->unlock_window();
3018 cwindow->gui->lock_window("MWindow::update_project 1");
3019 cwindow->update(0, 0, 1, 1, 1);
3020 cwindow->gui->unlock_window();
3022 if(debug) PRINT_TRACE
3024 // Close all the vwindows
3025 if(load_mode == LOADMODE_REPLACE ||
3026 load_mode == LOADMODE_REPLACE_CONCATENATE) {
3027 if(debug) PRINT_TRACE
3028 int first_vwindow = 0;
3029 if(session->show_vwindow) first_vwindow = 1;
3030 // Change visible windows to no source
3031 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3032 VWindow *vwindow = vwindows[i];
3033 if( !vwindow->is_running() ) continue;
3034 vwindow->change_source(-1);
3037 // Close remaining windows
3038 for(int i = first_vwindow; i < vwindows.size(); i++) {
3039 VWindow *vwindow = vwindows[i];
3040 if( !vwindow->is_running() ) continue;
3041 vwindow->close_window();
3043 if(debug) PRINT_TRACE
3045 else if(vwindows.size()) {
3046 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3047 if( vwindow->is_running() ) {
3048 vwindow->gui->lock_window("MWindow::update_project");
3050 vwindow->gui->unlock_window();
3054 if(debug) PRINT_TRACE
3055 cwindow->gui->lock_window("MWindow::update_project 2");
3056 cwindow->gui->timebar->update(0);
3057 cwindow->gui->unlock_window();
3059 if(debug) PRINT_TRACE
3060 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3065 awindow->gui->async_update_assets();
3066 if(debug) PRINT_TRACE
3068 gui->lock_window("MWindow::update_project");
3070 if(debug) PRINT_TRACE
3073 void MWindow::remove_indexfile(Indexable *indexable)
3075 if( !indexable->is_asset ) return;
3076 Asset *asset = (Asset *)indexable;
3078 IndexFile::delete_index(preferences, asset, ".toc");
3079 IndexFile::delete_index(preferences, asset, ".idx");
3080 IndexFile::delete_index(preferences, asset, ".mkr");
3083 void MWindow::rebuild_indices()
3085 for(int i = 0; i < session->drag_assets->total; i++)
3087 Indexable *indexable = session->drag_assets->get(i);
3088 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3089 remove_indexfile(indexable);
3090 // Schedule index build
3091 IndexState *index_state = indexable->index_state;
3092 index_state->index_status = INDEX_NOTTESTED;
3093 if( indexable->is_asset ) {
3094 Asset *asset = (Asset *)indexable;
3095 if( asset->format != FILE_PCM ) {
3096 asset->format = FILE_UNKNOWN;
3097 asset->reset_audio();
3099 asset->reset_video();
3100 // File file; // re-probe the asset
3101 // file.open_file(preferences, asset, 1, 0);
3103 mainindexes->add_next_asset(0, indexable);
3105 mainindexes->start_build();
3109 void MWindow::save_backup()
3113 edl->set_path(session->filename);
3114 char backup_path[BCTEXTLEN];
3115 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3116 File::get_config_path(), BACKUP_FILE);
3117 edl->save_xml(&file, backup_path, 0, 0);
3118 file.terminate_string();
3120 fs.complete_path(backup_path);
3122 if(file.write_to_file(backup_path))
3125 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3126 gui->show_message(string2);
3130 void MWindow::load_backup()
3132 ArrayList<char*> path_list;
3133 path_list.set_array_delete();
3135 char backup_path[BCTEXTLEN];
3136 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3137 File::get_config_path(), BACKUP_FILE);
3139 fs.complete_path(backup_path);
3141 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3142 strcpy(out_path, backup_path);
3144 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3145 edl->local_session->clip_title[0] = 0;
3146 // This is unique to backups since the path of the backup is different than the
3147 // path of the project.
3148 set_filename(edl->path);
3149 path_list.remove_all_objects();
3153 static inline int gcd(int m, int n)
3156 if( m < n ) { r = m; m = n; n = r; }
3157 while( (r = m % n) != 0 ) { m = n; n = r; }
3161 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3164 if(!width || !height) return 1;
3165 if( width == 720 && (height == 480 || height == 576) ) {
3166 w = 4; h = 3; return 0; // for NTSC and PAL
3168 double ar = (double)width / height;
3169 // square-ish pixels
3170 if( EQUIV(ar, 1.0000) ) return 0;
3171 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3172 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3173 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3174 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3175 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3176 int ww = width, hh = height;
3177 // numerator, denominator must be under mx
3178 int mx = 255, n = gcd(ww, hh);
3179 if( n > 1 ) { ww /= n; hh /= n; }
3180 // search near height in case extra/missing lines
3181 if( ww >= mx || hh >= mx ) {
3182 double err = height; // +/- 2 percent height
3183 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3184 int iw = width, ih = height+i;
3185 if( (n=gcd(iw, ih)) > 1 ) {
3186 int u = iw/n; if( u >= mx ) continue;
3187 int v = ih/n; if( v >= mx ) continue;
3188 double r = (double) u/v, er = fabs(ar-r);
3189 if( er >= err ) continue;
3190 err = er; ww = u; hh = v;
3199 void MWindow::reset_caches()
3201 frame_cache->remove_all();
3202 wave_cache->remove_all();
3203 audio_cache->remove_all();
3204 video_cache->remove_all();
3205 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3206 cwindow->playback_engine->audio_cache->remove_all();
3207 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3208 cwindow->playback_engine->video_cache->remove_all();
3210 for(int i = 0; i < vwindows.size(); i++) {
3211 VWindow *vwindow = vwindows[i];
3212 if( !vwindow->is_running() ) continue;
3213 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3214 vwindow->playback_engine->audio_cache->remove_all();
3215 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3216 vwindow->playback_engine->video_cache->remove_all();
3220 void MWindow::remove_asset_from_caches(Asset *asset)
3222 gui->resource_thread->get_video_source(0);
3223 gui->resource_thread->get_audio_source(0);
3224 frame_cache->remove_asset(asset);
3225 wave_cache->remove_asset(asset);
3226 audio_cache->delete_entry(asset);
3227 video_cache->delete_entry(asset);
3228 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3229 cwindow->playback_engine->audio_cache->delete_entry(asset);
3230 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3231 cwindow->playback_engine->video_cache->delete_entry(asset);
3232 for(int i = 0; i < vwindows.size(); i++) {
3233 VWindow *vwindow = vwindows[i];
3234 if( !vwindow->is_running() ) continue;
3235 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3236 vwindow->playback_engine->audio_cache->delete_entry(asset);
3237 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3238 vwindow->playback_engine->video_cache->delete_entry(asset);
3243 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3244 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3246 for(int i = 0; i < drag_assets->total; i++) {
3247 Indexable *indexable = drag_assets->get(i);
3248 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3251 // Remove from VWindow.
3252 for(int i = 0; i < session->drag_clips->total; i++) {
3253 for(int j = 0; j < vwindows.size(); j++) {
3254 VWindow *vwindow = vwindows[j];
3255 if( !vwindow->is_running() ) continue;
3256 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3257 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3258 vwindow->delete_source(1, 1);
3259 vwindow->gui->unlock_window();
3264 for(int i = 0; i < drag_assets->size(); i++) {
3265 for(int j = 0; j < vwindows.size(); j++) {
3266 VWindow *vwindow = vwindows[j];
3267 if( !vwindow->is_running() ) continue;
3268 if(drag_assets->get(i) == vwindow->get_source()) {
3269 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3270 vwindow->delete_source(1, 1);
3271 vwindow->gui->unlock_window();
3276 for(int i = 0; i < drag_assets->size(); i++) {
3277 Indexable *indexable = drag_assets->get(i);
3278 remove_indexfile(indexable);
3281 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3282 if(push_undo) undo->update_undo_before();
3283 if(drag_assets) edl->remove_from_project(drag_assets);
3284 if(drag_clips) edl->remove_from_project(drag_clips);
3285 if(redraw) save_backup();
3286 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3290 gui->lock_window("MWindow::remove_assets_from_project 3");
3291 gui->update(1, 1, 1, 1, 0, 1, 0);
3292 gui->unlock_window();
3294 // Removes from playback here
3295 sync_parameters(CHANGE_ALL);
3298 awindow->gui->async_update_assets();
3301 void MWindow::remove_assets_from_disk()
3304 for(int i = 0; i < session->drag_assets->total; i++)
3306 remove(session->drag_assets->get(i)->path);
3309 remove_assets_from_project(1,
3311 session->drag_assets,
3312 session->drag_clips);
3315 void MWindow::dump_plugins(FILE *fp)
3317 if( !plugindb ) return;
3318 for(int i = 0; i < plugindb->total; i++)
3320 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3321 " synth=%d transition=%d theme=%d %s\n",
3322 plugindb->get(i)->plugin_type,
3323 plugindb->get(i)->audio,
3324 plugindb->get(i)->video,
3325 plugindb->get(i)->realtime,
3326 plugindb->get(i)->multichannel,
3327 plugindb->get(i)->get_synthesis(),
3328 plugindb->get(i)->transition,
3329 plugindb->get(i)->theme,
3330 plugindb->get(i)->title);
3334 void MWindow::dump_edl(FILE *fp)
3340 void MWindow::dump_undo(FILE *fp)
3346 void MWindow::dump_exe(FILE *fp)
3348 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3349 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3351 int ret = -1, n = 100;
3352 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3353 exe_path[len] = 0; strcpy(proc_path, exe_path);
3356 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3359 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3360 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3361 struct tm *tm = localtime(&st.st_mtime);
3363 strftime(mtime, sizeof(mtime), "%F %T", tm);
3364 fprintf(fp,"mtime: %s\n", mtime);
3366 // people hit ctl-c waiting for this
3367 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3368 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3371 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3372 int64_t maxsz = 1024*pagsz;
3373 int64_t size = st.st_size, pos = 0;
3375 while( (bfrsz = size-pos) > 0 ) {
3376 if( bfrsz > maxsz ) bfrsz = maxsz;
3377 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3378 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3379 if( bfr == MAP_FAILED ) break;
3380 sha1.addBytes(bfr, bfrsz);
3385 ret = pos < size ? EIO : 0;
3386 fprintf(fp, "SHA1: ");
3387 uint8_t digest[20]; sha1.computeHash(digest);
3388 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3389 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3390 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3395 void MWindow::trap_hook(FILE *fp, void *vp)
3397 MWindow *mwindow = (MWindow *)vp;
3398 // fprintf(fp, "\nPLUGINS:\n");
3399 // mwindow->dump_plugins(fp);
3400 fprintf(fp, "\nEDL:\n");
3401 mwindow->dump_edl(fp);
3402 fprintf(fp, "\nUNDO:\n");
3403 mwindow->dump_undo(fp);
3404 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
3405 mwindow->dump_exe(fp);
3413 int MWindow::save_defaults()
3415 gui->save_defaults(defaults);
3416 edl->save_defaults(defaults);
3417 session->save_defaults(defaults);
3418 preferences->save_defaults(defaults);
3420 for(int i = 0; i < plugin_guis->total; i++)
3422 // Pointer comparison
3423 plugin_guis->get(i)->save_defaults();
3425 awindow->save_defaults(defaults);
3431 int MWindow::run_script(FileXML *script)
3433 int result = 0, result2 = 0;
3434 while(!result && !result2)
3436 result = script->read_tag();
3439 if(script->tag.title_is("new_project"))
3441 // Run new in immediate mode.
3442 // gui->mainmenu->new_project->run_script(script);
3445 if(script->tag.title_is("record"))
3447 // Run record as a thread. It is a terminal command.
3449 // Will read the complete scipt file without letting record read it if not
3455 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3462 // ================================= synchronization
3465 int MWindow::interrupt_indexes()
3467 mainprogress->cancelled = 1;
3468 mainindexes->interrupt_build();
3474 void MWindow::next_time_format()
3476 switch(edl->session->time_format)
3478 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3479 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3480 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3481 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3482 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3483 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3484 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3487 time_format_common();
3490 void MWindow::prev_time_format()
3492 switch(edl->session->time_format)
3494 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3495 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3496 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3497 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3498 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3499 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3500 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3503 time_format_common();
3506 void MWindow::time_format_common()
3508 gui->lock_window("MWindow::next_time_format");
3509 gui->redraw_time_dependancies();
3512 char string[BCTEXTLEN], string2[BCTEXTLEN];
3513 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3514 gui->show_message(string);
3516 gui->unlock_window();
3520 int MWindow::set_filename(const char *filename)
3522 if( filename != session->filename )
3523 strcpy(session->filename, filename);
3524 if( filename != edl->path )
3525 strcpy(edl->path, filename);
3529 if(filename[0] == 0)
3531 gui->set_title(PROGRAM_NAME);
3536 char string[BCTEXTLEN], string2[BCTEXTLEN];
3537 dir.extract_name(string, filename);
3538 sprintf(string2, PROGRAM_NAME ": %s", string);
3539 gui->set_title(string2);
3552 int MWindow::set_loop_boundaries()
3554 double start = edl->local_session->get_selectionstart();
3555 double end = edl->local_session->get_selectionend();
3563 if(edl->tracks->total_length())
3566 end = edl->tracks->total_length();
3573 if(edl->local_session->loop_playback && start != end)
3575 edl->local_session->loop_start = start;
3576 edl->local_session->loop_end = end;
3587 int MWindow::reset_meters()
3589 cwindow->gui->lock_window("MWindow::reset_meters 1");
3590 cwindow->gui->meters->reset_meters();
3591 cwindow->gui->unlock_window();
3593 for(int j = 0; j < vwindows.size(); j++) {
3594 VWindow *vwindow = vwindows[j];
3595 if( !vwindow->is_running() ) continue;
3596 vwindow->gui->lock_window("MWindow::reset_meters 2");
3597 vwindow->gui->meters->reset_meters();
3598 vwindow->gui->unlock_window();
3601 lwindow->gui->lock_window("MWindow::reset_meters 3");
3602 lwindow->gui->panel->reset_meters();
3603 lwindow->gui->unlock_window();
3605 gui->lock_window("MWindow::reset_meters 4");
3606 gui->reset_meters();
3607 gui->unlock_window();
3612 void MWindow::resync_guis()
3616 gui->lock_window("MWindow::resync_guis");
3617 gui->update(1, 1, 1, 1, 1, 1, 0);
3618 gui->unlock_window();
3620 cwindow->gui->lock_window("MWindow::resync_guis");
3621 cwindow->gui->resize_event(cwindow->gui->get_w(),
3622 cwindow->gui->get_h());
3623 int channels = edl->session->audio_channels;
3624 cwindow->gui->meters->set_meters(channels, 1);
3625 cwindow->gui->flush();
3626 cwindow->gui->unlock_window();
3628 for(int i = 0; i < vwindows.size(); i++) {
3629 VWindow *vwindow = vwindows[i];
3630 if( !vwindow->is_running() ) continue;
3631 vwindow->gui->lock_window("MWindow::resync_guis");
3632 vwindow->gui->resize_event(vwindow->gui->get_w(),
3633 vwindow->gui->get_h());
3634 vwindow->gui->meters->set_meters(channels, 1);
3635 vwindow->gui->flush();
3636 vwindow->gui->unlock_window();
3639 lwindow->gui->lock_window("MWindow::resync_guis");
3640 lwindow->gui->panel->set_meters(channels, 1);
3641 lwindow->gui->flush();
3642 lwindow->gui->unlock_window();
3645 if(((edl->session->output_w % 4) ||
3646 (edl->session->output_h % 4)) &&
3647 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3649 MainError::show_error(
3650 _("This project's dimensions are not multiples of 4 so\n"
3651 "it can't be rendered by OpenGL."));
3656 sync_parameters(CHANGE_ALL);
3659 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3661 File *file = new File;
3662 EDLSession *session = edl->session;
3663 double old_framerate = session->frame_rate;
3664 double old_samplerate = session->sample_rate;
3665 int old_auto_keyframes = session->auto_keyframes;
3666 session->auto_keyframes = 0;
3667 int result = file->open_file(preferences, asset, 1, 0);
3668 if( !result && delete_tracks > 0 )
3669 undo->update_undo_before();
3670 int video_layers = asset->get_video_layers();
3671 if( !result && asset->video_data && vstream < video_layers ) {
3672 // try to get asset up to date, may fail
3673 file->select_video_stream(asset, vstream);
3674 // either way use what was/is there.
3675 double framerate = asset->get_frame_rate();
3676 int width = asset->get_w();
3677 int height = asset->get_h();
3678 // must be multiple of 4 for opengl
3679 width = (width+3) & ~3; height = (height+3) & ~3;
3680 int driver = session->playback_config->vconfig->driver;
3681 int color_model = file->get_best_colormodel(asset, driver);
3682 // color_model = BC_CModels::is_yuv(color_model) ?
3683 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3684 // BC_CModels::is_float(color_model) ?
3685 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3686 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3687 // have alpha for now
3688 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3689 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3690 session->color_model = color_model;
3691 session->output_w = width;
3692 session->output_h = height;
3693 session->frame_rate = framerate;
3694 // not, asset->actual_width/actual_height
3695 asset->width = session->output_w;
3696 asset->height = session->output_h;
3697 asset->frame_rate = session->frame_rate;
3698 create_aspect_ratio(session->aspect_w, session->aspect_h,
3699 session->output_w, session->output_h);
3700 Track *track = edl->tracks->first;
3701 for( Track *next_track=0; track; track=next_track ) {
3702 next_track = track->next;
3703 if( track->data_type != TRACK_VIDEO ) continue;
3704 if( delete_tracks ) {
3705 Edit *edit = track->edits->first;
3706 for( Edit *next_edit=0; edit; edit=next_edit ) {
3707 next_edit = edit->next;
3708 if( edit->channel != vstream ||
3709 !edit->asset || !edit->asset->is_asset ||
3710 !asset->equivalent(*edit->asset,1,1,edl) )
3714 if( track->edits->first ) {
3715 track->track_w = edl->session->output_w;
3716 track->track_h = edl->session->output_h;
3718 else if( delete_tracks )
3719 edl->tracks->delete_track(track);
3722 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3724 if( !result && asset->audio_data && asset->channels > 0 ) {
3725 session->sample_rate = asset->get_sample_rate();
3726 int64_t channel_mask = 0;
3727 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
3728 file->get_audio_for_video(vstream, astream, channel_mask);
3729 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3730 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3732 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3733 if( channels < 1 ) channels = 1;
3734 if( channels > 6 ) channels = 6;
3735 session->audio_tracks = session->audio_channels = channels;
3736 switch( channels ) {
3738 session->achannel_positions[0] = 90;
3739 session->achannel_positions[1] = 150;
3740 session->achannel_positions[2] = 30;
3741 session->achannel_positions[3] = 210;
3742 session->achannel_positions[4] = 330;
3743 session->achannel_positions[5] = 270;
3746 session->achannel_positions[0] = 180;
3747 session->achannel_positions[1] = 0;
3750 session->achannel_positions[1] = 90;
3753 if( !channels ) break;
3754 double t = 0, dt = 360./channels;
3755 for( int i=channels; --i>=0; t+=dt )
3756 session->achannel_positions[i] = int(t+0.5);
3759 remap_audio(MWindow::AUDIO_1_TO_1);
3761 if( delete_tracks ) {
3762 Track *track = edl->tracks->first;
3763 for( Track *next_track=0; track; track=next_track ) {
3764 next_track = track->next;
3765 if( track->data_type != TRACK_AUDIO ) continue;
3766 Edit *edit = track->edits->first;
3767 for( Edit *next_edit=0; edit; edit=next_edit ) {
3768 next_edit = edit->next;
3769 if( !((1<<edit->channel) & channel_mask) ||
3770 !edit->asset || !edit->asset->is_asset ||
3771 !asset->equivalent(*edit->asset,1,1,edl) )
3774 if( !track->edits->first )
3775 edl->tracks->delete_track(track);
3779 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3782 session->auto_keyframes = old_auto_keyframes;
3783 if( !result && delete_tracks > 0 ) {
3785 undo->update_undo_after(_("select asset"), LOAD_ALL);
3791 int MWindow::select_asset(int vtrack, int delete_tracks)
3793 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3795 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3796 if( !track ) return 1;
3797 Edit *edit = track->edits->first;
3798 if( !edit ) return 1;
3799 Asset *asset = edit->asset;
3800 if( !asset || !asset->is_asset ) return 1;
3801 return select_asset(asset, edit->channel, 0, delete_tracks);
3804 void MWindow::dump_plugindb(FILE *fp)
3806 if( !plugindb ) return;
3807 for(int i = 0; i < plugindb->total; i++)
3808 plugindb->get(i)->dump(fp);
3811 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
3814 double unit_position = edl->local_session->get_selectionstart(1);
3815 unit_position = patch->track->to_units(unit_position, 0);
3817 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
3818 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3821 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
3824 double unit_position = edl->local_session->get_selectionstart(1);
3825 unit_position = patch->track->to_units(unit_position, 0);
3827 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
3828 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3831 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
3834 double unit_position = edl->local_session->get_selectionstart(1);
3835 unit_position = patch->track->to_units(unit_position, 0);
3837 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
3838 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);