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
24 #include "audioalsa.h"
26 #include "awindowgui.h"
28 #include "batchrender.h"
29 #include "bcdisplayinfo.h"
30 #include "bcsignals.h"
37 #include "channeldb.h"
38 #include "channelinfo.h"
40 #include "bccmodels.h"
41 #include "commercials.h"
42 #include "cplayback.h"
44 #include "cwindowgui.h"
46 #include "cwindowtool.h"
48 #include "devicedvbinput.inc"
49 #include "dvdcreate.h"
50 #include "editpanel.h"
52 #include "edlsession.h"
54 #include "fileformat.h"
56 #include "filesystem.h"
58 #include "floatautos.h"
59 #include "framecache.h"
61 #include "gwindowgui.h"
62 #include "keyframegui.h"
63 #include "indexfile.h"
65 #include "interlacemodes.h"
67 #include "levelwindowgui.h"
68 #include "levelwindow.h"
69 #include "loadfile.inc"
70 #include "localsession.h"
71 #include "maincursor.h"
72 #include "mainerror.h"
73 #include "mainindexes.h"
75 #include "mainprogress.h"
76 #include "mainsession.h"
80 #include "mwindowgui.h"
82 #include "nestededls.h"
86 #include "playback3d.h"
87 #include "playbackengine.h"
89 #include "pluginserver.h"
90 #include "pluginset.h"
91 #include "preferences.h"
94 #include "recordmonitor.h"
95 #include "recordlabel.h"
96 #include "removefile.h"
98 #include "resourcethread.h"
99 #include "samplescroll.h"
101 #include "sighandler.h"
102 #include "splashgui.h"
103 #include "statusbar.h"
105 #include "threadloader.h"
107 #include "tipwindow.h"
108 #include "trackcanvas.h"
110 #include "tracking.h"
111 #include "trackscroll.h"
113 #include "transition.h"
114 #include "transportque.h"
117 #include "versioninfo.h"
118 #include "videodevice.inc"
119 #include "videowindow.h"
120 #include "vplayback.h"
121 #include "vwindowgui.h"
123 #include "wavecache.h"
126 #include "exportedl.h"
128 #include "defaultformats.h"
129 #include "ntsczones.h"
136 #include <sys/types.h>
137 #include <sys/stat.h>
138 #include <sys/time.h>
139 #include <sys/mman.h>
150 // Hack for libdv to remove glib dependancy
153 // g_log (const char *log_domain,
155 // const char *format,
161 // g_logv (const char *log_domain,
163 // const char *format,
173 ArrayList<PluginServer*>* MWindow::plugindb = 0;
174 Commercials* MWindow::commercials = 0;
180 run_lock = new Mutex("MWindow::run_lock");
181 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
182 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
183 vwindows_lock = new Mutex("MWindow::vwindows_lock");
184 brender_lock = new Mutex("MWindow::brender_lock");
185 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
193 commercial_active = 0;
205 strcpy(cin_lang,"en");
206 channeldb_buz = new ChannelDB;
207 channeldb_v4l2jpeg = new ChannelDB;
211 keyframe_threads = 0;
231 // Need to delete brender temporary here.
234 run_lock->lock("MWindow::~MWindow");
237 //printf("MWindow::~MWindow %d\n", __LINE__);
239 gui->remote_control->deactivate();
242 gui->channel_info->stop();
244 delete create_bd; create_bd = 0;
245 delete create_dvd; create_dvd = 0;
246 delete batch_render; batch_render = 0;
247 delete render; render = 0;
249 if( commercials && !commercials->remove_user() ) commercials = 0;
251 // Save defaults for open plugins
252 plugin_gui_lock->lock("MWindow::~MWindow");
253 for(int i = 0; i < plugin_guis->size(); i++) {
254 plugin_guis->get(i)->hide_gui();
255 delete_plugin(plugin_guis->get(i));
257 plugin_gui_lock->unlock();
258 hide_keyframe_guis();
261 // Give up and go to a movie
262 // cant run valgrind if this is used
264 gui->del_keyboard_listener(
265 (int (BC_WindowBase::*)(BC_WindowBase *))
266 &MWindowGUI::keyboard_listener);
268 // release the hounds
269 if( awindow && awindow->gui ) awindow->gui->close(0);
270 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
271 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
272 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
273 if( twindow && twindow->is_running() ) twindow->close_window();
274 if( wwindow && wwindow->is_running() ) wwindow->close_window();
275 vwindows.remove_all_objects();
277 if( awindow ) awindow->join();
278 if( cwindow ) cwindow->join();
279 if( lwindow ) lwindow->join();
280 if( twindow ) twindow->join();
281 if( wwindow ) wwindow->join();
282 if( gwindow ) gwindow->join();
285 // one at a time, or nouveau chokes
286 #define close_gui(win) if( win ) { \
287 if( win->gui ) win->gui->close(0); \
295 vwindows.remove_all_objects();
300 dead_plugins->remove_all_objects();
301 // must delete theme before destroying plugindb
302 // theme destructor will be deleted by delete_plugins
303 delete theme; theme = 0;
306 keyframe_threads->remove_all_objects();
307 colormodels.remove_all_objects();
308 delete awindow; awindow = 0;
309 delete lwindow; lwindow = 0;
310 delete twindow; twindow = 0;
311 delete wwindow; wwindow = 0;
312 delete gwindow; gwindow = 0;
313 delete cwindow; cwindow = 0;
315 //delete file_server; file_server = 0; // reusable
316 delete mainindexes; mainindexes = 0;
317 delete mainprogress; mainprogress = 0;
318 delete audio_cache; audio_cache = 0; // delete the cache after the assets
319 delete video_cache; video_cache = 0; // delete the cache after the assets
320 delete frame_cache; frame_cache = 0;
321 delete wave_cache; wave_cache = 0;
322 delete plugin_guis; plugin_guis = 0;
323 delete dead_plugins; dead_plugins = 0;
324 delete keyframe_threads; keyframe_threads = 0;
325 delete undo; undo = 0;
326 delete preferences; preferences = 0;
327 delete exportedl; exportedl = 0;
328 delete session; session = 0;
329 delete defaults; defaults = 0;
330 delete assets; assets = 0;
331 delete splash_window; splash_window = 0;
332 if( !edl->Garbage::remove_user() ) edl = 0;
333 delete channeldb_buz;
334 delete channeldb_v4l2jpeg;
335 // This must be last thread to exit
336 delete playback_3d; playback_3d = 0;
337 delete dead_plugin_lock;
338 delete plugin_gui_lock;
339 delete vwindows_lock;
341 delete keyframe_gui_lock;
342 colormodels.remove_all_objects();
343 interlace_project_modes.remove_all_objects();
344 interlace_asset_modes.remove_all_objects();
345 interlace_asset_fixmethods.remove_all_objects();
346 sighandler->terminate();
357 void MWindow::init_error()
359 MainError::init_error(this);
362 void MWindow::finit_error()
364 MainError::finit_error();
367 void MWindow::create_defaults_path(char *string, const char *config_file)
369 // set the .bcast path
372 sprintf(string, "%s/", File::get_config_path());
373 fs.complete_path(string);
374 if(!fs.is_dir(string))
375 fs.create_dir(string);
378 strcat(string, config_file);
380 const char *MWindow::default_std()
382 char buf[BCTEXTLEN], *p = 0;
384 int fd = open(TIMEZONE_NAME, O_RDONLY);
386 int l = read(fd, buf, sizeof(buf)-1);
389 if( buf[l-1] == '\n' ) --l;
395 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
398 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
399 p += strlen(ZONEINFO_STR);
404 for( int i=0; ntsc_zones[i]; ++i ) {
405 if( !strcmp(ntsc_zones[i], p) )
412 for( int i=0; ntsc_zones[i]; ++i ) {
413 if( !strcmp(ntsc_zones[i], p) )
418 //__timezone: Seconds west of UTC. 240sec/deg
419 double tz_deg = -__timezone / 240.;
420 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
421 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
424 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
426 struct formatpresets *fpr;
428 for(fpr = &format_presets[0]; fpr->name; fpr++)
430 if(strcmp(_(fpr->name), preset) == 0)
432 session->audio_channels = fpr->audio_channels;
433 session->audio_tracks = fpr->audio_tracks;
434 session->sample_rate = fpr->sample_rate;
435 session->video_channels = fpr->video_channels;
436 session->video_tracks = fpr->video_tracks;
437 session->frame_rate = fpr->frame_rate;
438 session->output_w = fpr->output_w;
439 session->output_h = fpr->output_h;
440 session->aspect_w = fpr->aspect_w;
441 session->aspect_h = fpr->aspect_h;
442 session->interlace_mode = fpr->interlace_mode;
443 session->color_model = fpr->color_model;
449 const char *MWindow::get_preset_name(int index)
451 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
453 return _(format_presets[index].name);
457 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
459 char path[BCTEXTLEN];
460 // Use user supplied path
462 strcpy(path, config_path);
464 create_defaults_path(path, CONFIG_FILE);
466 defaults = new BC_Hash(path);
471 void MWindow::check_language()
473 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
474 const char *env_lang = getenv("LANGUAGE");
475 if( !env_lang ) env_lang = getenv("LC_ALL");
476 if( !env_lang ) env_lang = getenv("LANG");
478 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
479 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
480 env_lang = curr_lang;
482 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
483 defaults->get("LAST_LANG",last_lang);
484 if( strcmp(env_lang,last_lang)) {
485 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
486 defaults->update("LAST_LANG",env_lang);
487 char plugin_path[BCTEXTLEN];
488 create_defaults_path(plugin_path, PLUGIN_FILE);
489 ::remove(plugin_path);
490 char ladspa_path[BCTEXTLEN];
491 create_defaults_path(ladspa_path, LADSPA_FILE);
492 ::remove(ladspa_path);
495 if( strlen(env_lang) > 1 &&
496 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
497 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
500 strcpy(cin_lang, "en");
503 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
505 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
507 const char *dp = plug_dir;
508 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
509 bp = !*dp && *bp == '/' ? bp+1 : base_path;
515 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
518 FILE *fp = fopen(index_path, "r");
522 char index_line[BCTEXTLEN];
523 int index_version = -1, len = strlen(plugin_dir);
524 if( !fgets(index_line, BCTEXTLEN, fp) ||
525 sscanf(index_line, "%d", &index_version) != 1 ||
526 index_version != PLUGIN_FILE_VERSION ||
527 !fgets(index_line, BCTEXTLEN, fp) ||
528 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
529 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
531 ArrayList<PluginServer*> plugins;
532 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
533 if( index_line[0] == ';' ) continue;
534 if( index_line[0] == '#' ) continue;
535 int type = PLUGIN_TYPE_UNKNOWN;
536 char path[BCTEXTLEN], title[BCTEXTLEN];
538 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
541 PluginServer *server = 0;
543 case PLUGIN_TYPE_BUILTIN:
544 case PLUGIN_TYPE_EXECUTABLE:
545 case PLUGIN_TYPE_LADSPA: {
546 char plugin_path[BCTEXTLEN]; struct stat st;
547 sprintf(plugin_path, "%s/%s", plugin_dir, path);
548 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
551 server = new PluginServer(mwindow, plugin_path, type);
553 case PLUGIN_TYPE_FFMPEG: {
554 server = new_ffmpeg_server(mwindow, path);
557 if( !server ) continue;
558 plugins.append(server);
559 // Create plugin server from index entry
560 server->set_title(title);
561 if( server->read_table(index_line) ) {
568 ret = check_plugin_index(plugins, plugin_dir, ".");
571 add_plugins(plugins);
573 plugins.remove_all_objects();
578 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
579 const char *plug_dir, const char *plug_path)
581 char plugin_path[BCTEXTLEN];
582 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
584 fs.set_filter( "[*.plugin][*.so]" );
585 if( fs.update(plugin_path) )
588 for( int i=0; i<fs.dir_list.total; ++i ) {
589 char fs_path[BCTEXTLEN];
590 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
591 if( fs.is_dir(fs_path) ) {
592 get_plugin_path(plugin_path, plug_dir, fs_path);
593 if( check_plugin_index(plugins, plug_dir, plugin_path) )
596 else if( !plugin_exists(fs_path, plugins) )
603 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
606 plugindb = new ArrayList<PluginServer*>;
608 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
609 create_defaults_path(index_path, PLUGIN_FILE);
610 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
611 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
612 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
613 printf("init plugin index: %s\n", plugin_path);
614 FILE *fp = fopen(index_path,"w");
616 fprintf(stderr,_("MWindow::init_plugins: "
617 "can't create plugin index: %s\n"), index_path);
620 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
621 fprintf(fp, "%s\n", plugin_path);
622 init_plugin_index(mwindow, preferences, fp, plugin_path);
623 init_ffmpeg_index(mwindow, preferences, fp);
625 return load_plugin_index(mwindow, index_path, plugin_path);
628 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
630 char *path = getenv("LADSPA_PATH");
631 char ladspa_path[BCTEXTLEN];
633 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
636 for( int len=0; *path; path+=len ) {
637 char *cp = strchr(path,':');
638 len = !cp ? strlen(path) : cp-path;
639 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
640 memcpy(plugin_path, path, len); plugin_path[len] = 0;
642 char *plugin_dir = FileSystem::basepath(plugin_path);
643 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
644 create_defaults_path(index_path, LADSPA_FILE);
645 cp = index_path + strlen(index_path);
646 for( char *bp=plugin_path; *bp!=0; ++bp )
647 *cp++ = *bp=='/' ? '_' : *bp;
649 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
650 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
651 load_plugin_index(mwindow, index_path, plugin_path);
656 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
657 FILE *fp, const char *plugin_dir)
659 int idx = PLUGIN_IDS;
661 for( int i=0; i<plugindb->size(); ++i ) {
662 PluginServer *server = plugindb->get(i);
663 if( server->dir_idx >= idx )
664 idx = server->dir_idx+1;
667 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
670 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
671 const char *index_path, const char *plugin_dir)
673 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
674 strcpy(plugin_path, path); delete [] path;
675 printf("init ladspa index: %s\n", plugin_dir);
676 FILE *fp = fopen(index_path,"w");
678 fprintf(stderr,_("MWindow::init_ladspa_index: "
679 "can't create plugin index: %s\n"), index_path);
682 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
683 fprintf(fp, "%s\n", plugin_dir);
684 init_plugin_index(mwindow, preferences, fp, plugin_path);
689 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
690 const char *plug_dir, const char *plug_path, int &idx)
692 char plugin_path[BCTEXTLEN];
693 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
695 fs.set_filter( "[*.plugin][*.so]" );
696 int result = fs.update(plugin_path);
697 if( result || !fs.dir_list.total ) return;
700 for( int i=0; i<fs.dir_list.total; ++i ) {
701 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
702 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
703 get_plugin_path(path, plug_dir, fs_path);
704 if( fs.is_dir(fs_path) ) {
705 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
708 if( plugin_exists(path) ) continue;
710 if( stat(fs_path, &st) ) continue;
711 int64_t mtime = st.st_mtime;
712 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
713 result = server.open_plugin(1, preferences, 0, 0);
715 server.write_table(fp, path, vis_id, mtime);
716 server.close_plugin();
718 else if( result == PLUGINSERVER_IS_LAD ) {
721 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
722 ladspa.set_lad_index(lad_index++);
723 result = ladspa.open_plugin(1, preferences, 0, 0);
725 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
726 ladspa.close_plugin();
732 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
734 for( int i=0; i<plugins.size(); ++i )
735 plugindb->append(plugins[i]);
736 plugins.remove_all();
739 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
741 const char *cfg_path = File::get_cindat_path();
742 char msg_path[BCTEXTLEN]; int txt = 0;
744 if( BC_Resources::language[0] ) {
745 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
747 fp = fopen(msg_path, "r");
751 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
753 fp = fopen(msg_path, "r");
756 char text[BCTEXTLEN];
757 char *tp = text, *ep = tp + sizeof(text)-1;
758 char title[BCTEXTLEN];
763 char line[BCTEXTLEN], *cp = line;
764 if( fgets(line,sizeof(line)-1,fp) ) {
765 if( *cp == '#' ) continue;
766 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
769 if( tp > text && *--tp == '\n' ) *tp = 0;
771 tp = !txt ? title : _(title);
772 int idx = plugins.size();
773 while( --idx>=0 && strcmp(plugins[idx]->title, tp) );
775 delete [] plugins[idx]->tip;
776 plugins[idx]->tip = cstrdup(text);
780 if( done > 0 ) break;
782 char *dp = strchr(cp, ':');
784 printf("plugin tips: error on line %d\n", no);
788 while( cp < dp ) *bp++ = *cp++;
793 while( *cp == ' ' || *cp == '\t' ) ++cp;
794 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
799 void MWindow::delete_plugins()
801 plugindb->remove_all_objects();
806 void MWindow::search_plugindb(int do_audio,
811 ArrayList<PluginServer*> &results)
814 for(int i = 0; i < MWindow::plugindb->total; i++)
816 PluginServer *current = MWindow::plugindb->get(i);
818 if(current->audio == do_audio &&
819 current->video == do_video &&
820 (current->realtime == is_realtime || is_realtime < 0) &&
821 current->transition == is_transition &&
822 current->theme == is_theme)
823 results.append(current);
826 // Alphabetize list by title
832 for(int i = 0; i < results.total - 1; i++)
834 PluginServer *value1 = results[i];
835 PluginServer *value2 = results[i + 1];
836 if(strcmp(_(value1->title), _(value2->title)) > 0)
840 results[i + 1] = value1;
846 PluginServer* MWindow::scan_plugindb(char *title,
851 // printf("MWindow::scan_plugindb data_type < 0\n");
855 for(int i = 0; i < plugindb->total; i++)
857 PluginServer *server = plugindb->get(i);
859 !strcasecmp(server->title, title) &&
861 (data_type == TRACK_AUDIO && server->audio) ||
862 (data_type == TRACK_VIDEO && server->video)))
863 return plugindb->get(i);
868 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
870 for( int i=0; i<plugins.size(); ++i )
871 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
875 int MWindow::plugin_exists(char *plugin_path)
877 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
880 void MWindow::init_preferences()
882 preferences = new Preferences;
883 preferences->load_defaults(defaults);
884 session = new MainSession(this);
885 session->load_defaults(defaults);
886 // set x11_host, screens, window_config
887 screens = session->set_default_x11_host();
888 BC_Signals::set_trap_hook(trap_hook, this);
889 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
890 BC_Signals::set_catch_intr(preferences->trap_sigintr);
891 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
892 BC_Trace::enable_locks();
895 BC_Trace::disable_locks();
897 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
898 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
901 void MWindow::clean_indexes()
906 int oldest_item = -1;
908 char string[BCTEXTLEN];
909 char string2[BCTEXTLEN];
911 // Delete extra indexes
912 fs.set_filter("*.idx");
913 fs.complete_path(preferences->index_directory);
914 fs.update(preferences->index_directory);
915 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
917 // Eliminate directories
922 for(int i = 0; i < fs.dir_list.total && !result; i++)
924 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
925 if(fs.is_dir(string))
927 delete fs.dir_list[i];
928 fs.dir_list.remove_number(i);
933 total_excess = fs.dir_list.total - preferences->index_count;
935 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
936 while(total_excess > 0)
939 for(int i = 0; i < fs.dir_list.total; i++)
941 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
943 if(i == 0 || fs.get_date(string) <= oldest)
945 oldest = fs.get_date(string);
953 fs.join_names(string,
954 preferences->index_directory,
955 fs.dir_list[oldest_item]->name);
956 //printf("MWindow::clean_indexes 1 %s\n", string);
958 perror("delete_indexes");
959 delete fs.dir_list[oldest_item];
960 fs.dir_list.remove_number(oldest_item);
962 // Remove table of contents if it exists
963 strcpy(string2, string);
964 char *ptr = strrchr(string2, '.');
967 //printf("MWindow::clean_indexes 2 %s\n", string2);
968 sprintf(ptr, ".toc");
970 sprintf(ptr, ".mkr");
979 void MWindow::init_awindow()
981 awindow = new AWindow(this);
982 awindow->create_objects();
985 void MWindow::init_gwindow()
987 gwindow = new GWindow(this);
988 gwindow->create_objects();
991 void MWindow::init_tipwindow()
993 TipWindow::load_tips(cin_lang);
995 twindow = new TipWindow(this);
999 void MWindow::show_warning(int *do_warning, const char *text)
1001 if( do_warning && !*do_warning ) return;
1003 wwindow = new WWindow(this);
1004 wwindow->show_warning(do_warning, text);
1007 int MWindow::wait_warning()
1009 return wwindow->wait_result();
1012 void MWindow::init_theme()
1017 PluginServer *theme_plugin = 0;
1018 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1019 if( plugindb->get(i)->theme &&
1020 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1021 theme_plugin = plugindb->get(i);
1025 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1026 preferences->theme);
1028 const char *default_theme = _(DEFAULT_THEME);
1029 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1030 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1032 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1033 if( plugindb->get(i)->theme &&
1034 !strcasecmp(default_theme, plugindb->get(i)->title) )
1035 theme_plugin = plugindb->get(i);
1040 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1044 PluginServer *plugin = new PluginServer(*theme_plugin);
1045 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1046 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1047 theme_plugin->title);
1051 theme = plugin->new_theme();
1052 theme->mwindow = this;
1053 strcpy(theme->path, plugin->path);
1056 // Load default images & settings
1057 theme->Theme::initialize();
1058 // Load user images & settings
1059 theme->initialize();
1060 // Create menus with user colors
1061 theme->build_menus();
1064 theme->check_used();
1066 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1069 void MWindow::init_3d()
1071 playback_3d = new Playback3D(this);
1072 playback_3d->create_objects();
1075 void MWindow::init_edl()
1078 edl->create_objects();
1079 fill_preset_defaults(default_standard, edl->session);
1080 edl->load_defaults(defaults);
1081 edl->session->brender_start = edl->session->brender_end = 0;
1082 edl->create_default_tracks();
1083 edl->tracks->update_y_pixels(theme);
1086 void MWindow::init_compositor()
1088 cwindow = new CWindow(this);
1089 cwindow->create_objects();
1092 void MWindow::init_levelwindow()
1094 lwindow = new LevelWindow(this);
1095 lwindow->create_objects();
1098 VWindow *MWindow::get_viewer(int start_it, int idx)
1100 vwindows_lock->lock("MWindow::get_viewer");
1101 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1102 if( !vwindow ) idx = vwindows.size();
1103 while( !vwindow && --idx >= 0 ) {
1104 VWindow *vwin = vwindows[idx];
1105 if( !vwin->is_running() || !vwin->get_edl() )
1109 vwindow = new VWindow(this);
1110 vwindow->load_defaults();
1111 vwindow->create_objects();
1112 vwindows.append(vwindow);
1114 vwindows_lock->unlock();
1115 if( start_it ) vwindow->start();
1119 void MWindow::init_cache()
1121 audio_cache = new CICache(preferences);
1122 video_cache = new CICache(preferences);
1123 frame_cache = new FrameCache;
1124 wave_cache = new WaveCache;
1127 void MWindow::init_channeldb()
1129 channeldb_buz->load("channeldb_buz");
1130 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1133 void MWindow::init_menus()
1135 char string[BCTEXTLEN];
1138 BC_CModels::to_text(string, BC_RGB888);
1139 colormodels.append(new ColormodelItem(string, BC_RGB888));
1140 BC_CModels::to_text(string, BC_RGBA8888);
1141 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1142 // BC_CModels::to_text(string, BC_RGB161616);
1143 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1144 // BC_CModels::to_text(string, BC_RGBA16161616);
1145 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1146 BC_CModels::to_text(string, BC_RGB_FLOAT);
1147 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1148 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1149 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1150 BC_CModels::to_text(string, BC_YUV888);
1151 colormodels.append(new ColormodelItem(string, BC_YUV888));
1152 BC_CModels::to_text(string, BC_YUVA8888);
1153 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1154 // BC_CModels::to_text(string, BC_YUV161616);
1155 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1156 // BC_CModels::to_text(string, BC_YUVA16161616);
1157 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1159 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1160 interlace_project_modes.append(new InterlacemodeItem(string, x));
1162 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1163 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1165 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1166 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1168 // Interlacing Modes
1169 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1171 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1172 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1174 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1175 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1177 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1178 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1180 // Interlacing Fixing Methods
1181 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1182 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1183 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1186 void MWindow::init_indexes()
1188 mainindexes = new MainIndexes(this);
1189 mainindexes->start_loop();
1192 void MWindow::init_gui()
1194 gui = new MWindowGUI(this);
1195 gui->lock_window("MWindow::init_gui");
1196 gui->create_objects();
1197 gui->unlock_window();
1198 gui->load_defaults(defaults);
1201 void MWindow::init_signals()
1203 sighandler = new SigHandler;
1204 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1208 void MWindow::init_render()
1210 render = new Render(this);
1211 create_bd = new CreateBD_Thread(this);
1212 create_dvd = new CreateDVD_Thread(this);
1213 batch_render = new BatchRenderThread(this);
1216 void MWindow::init_exportedl()
1218 exportedl = new ExportEDL(this);
1221 void MWindow::init_brender()
1223 if(preferences->use_brender && !brender)
1225 brender_lock->lock("MWindow::init_brender 1");
1226 brender = new BRender(this);
1227 brender->initialize();
1228 session->brender_end = 0;
1229 brender_lock->unlock();
1232 if(!preferences->use_brender && brender)
1234 brender_lock->lock("MWindow::init_brender 2");
1237 session->brender_end = 0;
1238 brender_lock->unlock();
1244 void MWindow::restart_brender()
1246 //printf("MWindow::restart_brender 1\n");
1247 if( !brender_active || !preferences->use_brender ) return;
1248 if( !brender ) return;
1249 int locked = gui->get_window_lock();
1250 if( locked ) gui->unlock_window();
1251 brender->restart(edl);
1252 if( locked ) gui->lock_window("MWindow::restart_brender");
1255 void MWindow::stop_brender()
1257 if( !brender ) return;
1258 int locked = gui->get_window_lock();
1259 if( locked ) gui->unlock_window();
1261 if( locked ) gui->lock_window("MWindow::stop_brender");
1264 int MWindow::brender_available(int position)
1267 brender_lock->lock("MWindow::brender_available 1");
1268 if(brender && brender_active)
1270 if(brender->map_valid)
1272 brender->map_lock->lock("MWindow::brender_available 2");
1273 if(position < brender->map_size &&
1276 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1277 if(brender->map[position] == BRender::RENDERED)
1280 brender->map_lock->unlock();
1283 brender_lock->unlock();
1287 void MWindow::set_brender_active(int v, int update)
1289 if( !preferences->use_brender ) v = 0;
1291 gui->mainmenu->brender_active->set_checked(v);
1293 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1294 edl->session->brender_end = edl->local_session->get_selectionend(1);
1296 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1297 edl->session->brender_end = edl->tracks->total_video_length();
1302 edl->session->brender_start = edl->session->brender_end = 0;
1306 gui->update_timebar(0);
1307 gui->draw_overlays(1);
1311 int MWindow::has_commercials()
1313 return theme->use_commercials;
1316 void MWindow::init_commercials()
1318 if( !commercials ) {
1319 commercials = new Commercials(this);
1320 commercial_active = 0;
1323 commercials->add_user();
1326 void MWindow::commit_commercial()
1328 if( !commercial_active ) return;
1329 commercial_active = 0;
1330 if( !commercials ) return;
1331 commercials->commitDb();
1334 void MWindow::undo_commercial()
1336 if( !commercial_active ) return;
1337 commercial_active = 0;
1338 if( !commercials ) return;
1339 commercials->undoDb();
1342 int MWindow::put_commercial()
1344 double start = edl->local_session->get_selectionstart();
1345 double end = edl->local_session->get_selectionend();
1346 if( start >= end ) return 0;
1348 const char *errmsg = 0;
1350 Tracks *tracks = edl->tracks;
1353 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1354 if( track->data_type != TRACK_VIDEO ) continue;
1355 if( !track->record ) continue;
1356 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1358 int64_t units_start = track->to_units(start,0);
1359 int64_t units_end = track->to_units(end,0);
1360 Edits *edits = track->edits;
1361 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1362 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1363 if(!edit1 && !edit2) continue; // nothing selected
1364 if(!edit2) { // edit2 beyond end of track
1365 edit2 = edits->last;
1366 units_end = edits->length();
1368 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1369 Indexable *indexable = edit1->get_source();
1370 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1373 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1374 if( track->data_type != TRACK_VIDEO ) continue;
1375 if( !track->record ) continue;
1376 int64_t units_start = track->to_units(start,0);
1377 int64_t units_end = track->to_units(end,0);
1378 Edits *edits = track->edits;
1379 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1380 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1381 if(!edit1 && !edit2) continue; // nothing selected
1382 if(!edit2) { // edit2 beyond end of track
1383 edit2 = edits->last;
1384 units_end = edits->length();
1386 Indexable *indexable = edit1->get_source();
1387 Asset *asset = (Asset *)indexable;
1388 File *file = video_cache->check_out(asset, edl);
1389 if( !file ) { errmsg = _("no file"); break; }
1390 int64_t edit_length = units_end - units_start;
1391 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1392 result = commercials->put_clip(file, edit1->channel,
1393 track->from_units(edit_start), track->from_units(edit_length));
1394 video_cache->check_in(asset);
1395 if( result ) { errmsg = _("db failed"); break; }
1398 char string[BCTEXTLEN];
1399 sprintf(string, _("put_commercial: %s"), errmsg);
1400 MainError::show_error(string);
1407 void MWindow::stop_playback(int wait)
1409 int locked = gui->get_window_lock();
1410 if( locked ) gui->unlock_window();
1412 cwindow->playback_engine->stop_playback();
1414 for(int i = 0; i < vwindows.size(); i++) {
1415 VWindow *vwindow = vwindows[i];
1416 if( !vwindow->is_running() ) continue;
1417 vwindow->playback_engine->stop_playback();
1419 if( locked ) gui->lock_window("MWindow::stop_playback");
1422 int MWindow::load_filenames(ArrayList<char*> *filenames,
1424 int update_filename)
1426 ArrayList<EDL*> new_edls;
1427 ArrayList<Asset*> new_assets;
1428 ArrayList<File*> new_files;
1429 const int debug = 0;
1430 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1433 gui->start_hourglass();
1435 // Need to stop playback since tracking depends on the EDL not getting
1439 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1440 undo->update_undo_before();
1443 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1445 // Define new_edls and new_assets to load
1446 int result = 0, ftype = -1;
1447 for(int i = 0; i < filenames->size(); i++)
1450 File *new_file = new File;
1451 Asset *new_asset = new Asset(filenames->get(i));
1452 EDL *new_edl = new EDL;
1453 char string[BCTEXTLEN];
1455 new_edl->create_objects();
1456 new_edl->copy_session(edl);
1457 new_file->set_program(edl->session->program_no);
1459 sprintf(string, _("Loading %s"), new_asset->path);
1460 gui->show_message(string);
1461 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1463 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1464 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1469 // Convert media file to EDL
1471 // Warn about odd image dimensions
1472 if(new_asset->video_data &&
1473 ((new_asset->width % 2) ||
1474 (new_asset->height % 2)))
1476 char string[BCTEXTLEN];
1477 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1481 MainError::show_error(string);
1484 if(new_asset->program >= 0 &&
1485 edl->session->program_no != new_asset->program)
1487 char string[BCTEXTLEN];
1488 sprintf(string, _("%s's index was built for program number %d\n"
1489 "Playback preference is %d.\n Using program %d."),
1490 new_asset->path, new_asset->program,
1491 edl->session->program_no, new_asset->program);
1492 MainError::show_error(string);
1496 if(load_mode != LOADMODE_RESOURCESONLY)
1498 RecordLabels *labels = edl->session->label_cells ?
1499 new RecordLabels(new_file) : 0;
1500 asset_to_edl(new_edl, new_asset, labels);
1501 new_edls.append(new_edl);
1502 new_asset->Garbage::remove_user();
1508 new_assets.append(new_asset);
1512 // Set filename to nothing for assets since save EDL would overwrite them.
1513 if(load_mode == LOADMODE_REPLACE ||
1514 load_mode == LOADMODE_REPLACE_CONCATENATE)
1517 // Reset timeline position
1518 for(int i = 0; i < TOTAL_PANES; i++)
1520 new_edl->local_session->view_start[i] = 0;
1521 new_edl->local_session->track_start[i] = 0;
1529 case FILE_NOT_FOUND:
1530 sprintf(string, _("Failed to open %s"), new_asset->path);
1531 gui->show_message(string, theme->message_error);
1532 gui->update_default_message();
1536 case FILE_UNRECOGNIZED_CODEC:
1539 { IndexFile indexfile(this, new_asset);
1540 if( !(result = indexfile.open_index()) )
1541 indexfile.close_index();
1544 // Test existing EDLs
1545 for(int j = 0; result && j <= new_edls.total; j++) {
1546 Asset *old_asset = j < new_edls.total ?
1547 new_edls[j]->assets->get_asset(new_asset->path) :
1548 edl->assets->get_asset(new_asset->path);
1550 new_asset->copy_from(old_asset,1);
1558 char string[BCTEXTLEN];
1560 fs.extract_name(string, new_asset->path);
1562 strcat(string, _("'s format couldn't be determined."));
1563 new_asset->audio_data = 1;
1564 new_asset->format = FILE_PCM;
1565 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1566 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1567 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1568 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1569 new_asset->signed_ = defaults->get("SIGNED_", 1);
1570 new_asset->header = defaults->get("HEADER", 0);
1572 FileFormat fwindow(this);
1573 fwindow.create_objects(new_asset, string);
1574 result = fwindow.run_window();
1577 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1578 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1579 defaults->update("AUDIO_BITS", new_asset->bits);
1580 defaults->update("BYTE_ORDER", new_asset->byte_order);
1581 defaults->update("SIGNED_", new_asset->signed_);
1582 defaults->update("HEADER", new_asset->header);
1589 // Recalculate length
1591 new_file = new File;
1592 result = new_file->open_file(preferences, new_asset, 1, 0);
1594 if(load_mode != LOADMODE_RESOURCESONLY)
1596 RecordLabels *labels = edl->session->label_cells ?
1597 new RecordLabels(new_file) : 0;
1598 asset_to_edl(new_edl, new_asset, labels);
1599 new_edls.append(new_edl);
1600 new_asset->Garbage::remove_user();
1606 new_assets.append(new_asset);
1620 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1621 xml_file.read_from_file(filenames->get(i));
1622 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1623 const char *cin_version = 0;
1624 while( !xml_file.read_tag() ) {
1625 if( xml_file.tag.title_is("EDL") ) {
1626 cin_version = xml_file.tag.get_property("VERSION");
1631 if( !cin_version ) {
1632 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1633 char string[BCTEXTLEN];
1634 sprintf(string,_("Unknown %s"), filenames->get(i));
1635 gui->show_message(string);
1639 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1640 char string[BCTEXTLEN];
1641 snprintf(string, sizeof(string),
1642 _("Warning: XML from cinelerra version %s\n"
1643 "Session data may be incompatible."), cin_version);
1644 show_warning(&preferences->warn_version, string);
1646 if(load_mode == LOADMODE_NESTED)
1648 // Load temporary EDL for nesting.
1649 EDL *nested_edl = new EDL;
1650 nested_edl->create_objects();
1651 nested_edl->set_path(filenames->get(i));
1652 nested_edl->load_xml(&xml_file, LOAD_ALL);
1653 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1654 edl_to_nested(new_edl, nested_edl);
1655 nested_edl->Garbage::remove_user();
1659 // Load EDL for pasting
1660 new_edl->load_xml(&xml_file, LOAD_ALL);
1661 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1662 test_plugins(new_edl, filenames->get(i));
1663 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1665 if(load_mode == LOADMODE_REPLACE ||
1666 load_mode == LOADMODE_REPLACE_CONCATENATE)
1668 strcpy(session->filename, filenames->get(i));
1669 strcpy(new_edl->local_session->clip_title,
1672 set_filename(new_edl->local_session->clip_title);
1675 if( load_mode == LOADMODE_RESOURCESONLY ) {
1676 strcpy(new_edl->local_session->clip_title,
1679 time_t t = !stat(filenames->get(i),&st) ?
1680 st.st_mtime : time(&t);
1681 ctime_r(&t, new_edl->local_session->clip_notes);
1685 new_edls.append(new_edl);
1691 // edls are in new_edls
1692 if( result && new_edl ) new_edl->Garbage::remove_user();
1693 // assets are copied
1694 if( new_asset ) new_asset->Garbage::remove_user();
1696 // Store for testing index
1697 new_files.append(new_file);
1700 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1704 gui->reset_default_message();
1705 gui->default_message();
1709 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1712 // Don't back up here.
1715 // For pasting, clear the active region
1716 if(load_mode == LOADMODE_PASTE ||
1717 load_mode == LOADMODE_NESTED)
1719 double start = edl->local_session->get_selectionstart();
1720 double end = edl->local_session->get_selectionend();
1721 if(!EQUIV(start, end))
1724 edl->session->labels_follow_edits,
1725 edl->session->plugins_follow_edits,
1726 edl->session->autos_follow_edits);
1729 paste_edls(&new_edls, load_mode, 0, -1,
1730 edl->session->labels_follow_edits,
1731 edl->session->plugins_follow_edits,
1732 edl->session->autos_follow_edits,
1739 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1741 // Add new assets to EDL and schedule assets for index building.
1742 int got_indexes = 0;
1743 for(int i = 0; i < new_edls.size(); i++)
1745 EDL *new_edl = new_edls[i];
1746 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1748 mainindexes->add_next_asset(0,
1749 new_edl->nested_edls->get(j));
1751 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1756 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1757 for(int i = 0; i < new_assets.size(); i++)
1759 Asset *new_asset = new_assets[i];
1763 for(int j = 0; j < new_files.size(); j++)
1765 new_file = new_files[j];
1766 if(!strcmp(new_file->asset->path,
1774 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1776 edl->assets->update(new_asset);
1778 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1780 // Start examining next batch of index files
1781 if(got_indexes) mainindexes->start_build();
1782 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1785 Track *track = edl->tracks->first;
1788 for(int j = 0; j < track->plugin_set.size(); j++)
1790 PluginSet *plugins = track->plugin_set[j];
1791 Plugin *plugin = plugins->get_first_plugin();
1795 if(load_mode == LOADMODE_REPLACE ||
1796 load_mode == LOADMODE_REPLACE_CONCATENATE)
1798 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1801 show_plugin(plugin);
1805 plugin = (Plugin*)plugin->next;
1809 track = track->next;
1812 // if just opening one new resource in replace mode
1813 if( ftype != FILE_IS_XML &&
1814 ( load_mode == LOADMODE_REPLACE ||
1815 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1817 edl->session->proxy_scale = 1;
1818 edl->session->proxy_use_scaler = 0;
1819 edl->session->proxy_auto_scale = 0;
1820 edl->local_session->preview_start = 0;
1821 edl->local_session->preview_end = edl->tracks->total_playable_length();
1822 edl->local_session->loop_playback = 0;
1823 edl->local_session->set_selectionstart(0);
1824 edl->local_session->set_selectionend(0);
1825 set_brender_active(0, 0);
1830 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
1831 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
1832 ArrayList<Indexable *> orig_idxbls;
1833 for( int i=0; i<new_assets.size(); ++i )
1834 orig_idxbls.append(new_assets.get(i));
1835 for( int i=0; i<new_edls.size(); ++i ) {
1836 EDL *new_edl = new_edls[i];
1837 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
1838 if( track->data_type != TRACK_VIDEO ) continue;
1839 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1840 Indexable *idxbl = (Indexable *)edit->asset;
1841 if( !idxbl ) continue;
1842 if( !idxbl->have_video() ) continue;
1843 if( edit->channel != 0 ) continue; // first layer only
1844 orig_idxbls.append(edit->asset);
1848 gui->unlock_window(); // to update progress bar
1849 render_proxy(orig_idxbls);
1850 gui->lock_window("MWindow::load_filenames");
1853 // need to update undo before project, since mwindow is unlocked & a new load
1854 // can begin here. Should really prevent loading until we're done.
1855 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1856 undo->update_undo_after(_("load"), LOAD_ALL);
1858 for(int i = 0; i < new_edls.size(); i++)
1860 new_edls[i]->remove_user();
1862 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1864 new_edls.remove_all();
1866 for(int i = 0; i < new_assets.size(); i++)
1868 new_assets[i]->Garbage::remove_user();
1871 new_assets.remove_all();
1872 new_files.remove_all_objects();
1875 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1876 if(load_mode == LOADMODE_REPLACE ||
1877 load_mode == LOADMODE_REPLACE_CONCATENATE)
1879 session->changes_made = 0;
1883 session->changes_made = 1;
1886 gui->stop_hourglass();
1889 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1890 update_project(load_mode);
1892 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1897 void MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
1899 Asset *format_asset = new Asset;
1900 format_asset->format = FILE_FFMPEG;
1901 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
1902 ProxyRender proxy_render(this, format_asset);
1903 int new_scale = edl->session->proxy_scale;
1904 int use_scaler = edl->session->proxy_use_scaler;
1906 for( int i=0; i<new_idxbls.size(); ++i ) {
1907 Indexable *orig = new_idxbls.get(i);
1908 Asset *proxy = proxy_render.add_original(orig, new_scale);
1909 if( !proxy ) continue;
1911 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
1912 int got_it = exists && // if proxy exists, and is newer than orig
1913 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
1914 if( got_it ) continue;
1915 proxy_render.add_needed(orig, proxy);
1918 // render needed proxies
1919 int result = proxy_render.create_needed_proxies(new_scale);
1921 add_proxy(use_scaler,
1922 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
1924 format_asset->remove_user();
1927 void MWindow::test_plugins(EDL *new_edl, char *path)
1929 char string[BCTEXTLEN];
1931 // Do a check weather plugins exist
1932 for(Track *track = new_edl->tracks->first; track; track = track->next)
1934 for(int k = 0; k < track->plugin_set.total; k++)
1936 PluginSet *plugin_set = track->plugin_set[k];
1937 for(Plugin *plugin = (Plugin*)plugin_set->first;
1939 plugin = (Plugin*)plugin->next)
1941 if(plugin->plugin_type == PLUGIN_STANDALONE)
1943 // ok we need to find it in plugindb
1944 int plugin_found = 0;
1946 for(int j = 0; j < plugindb->size(); j++)
1948 PluginServer *server = plugindb->get(j);
1950 !strcasecmp(server->title, plugin->title) &&
1951 ((track->data_type == TRACK_AUDIO && server->audio) ||
1952 (track->data_type == TRACK_VIDEO && server->video)) &&
1953 (!server->transition))
1960 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1961 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1962 "effect", plugin->title,
1964 MainError::show_error(string);
1970 for(Edit *edit = (Edit*)track->edits->first;
1972 edit = (Edit*)edit->next)
1974 if (edit->transition)
1976 // ok we need to find transition in plugindb
1978 int transition_found = 0;
1979 for(int j = 0; j < plugindb->size(); j++)
1981 PluginServer *server = plugindb->get(j);
1983 !strcasecmp(server->title, edit->transition->title) &&
1984 ((track->data_type == TRACK_AUDIO && server->audio) ||
1985 (track->data_type == TRACK_VIDEO && server->video)) &&
1986 (server->transition))
1987 transition_found = 1;
1990 if (!transition_found)
1993 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1994 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1995 "transition", edit->transition->title,
1997 MainError::show_error(string);
2005 void MWindow::init_shm()
2007 // Fix shared memory
2008 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
2010 fprintf(fd, "0x7fffffff");
2015 fd = fopen("/proc/sys/kernel/shmmax", "r");
2017 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
2022 fscanf(fd, "%jd", &result);
2025 if(result < 0x7fffffff) {
2026 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
2027 "you probably need to be root, or:\n"
2028 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
2029 "before trying to start cinelerra.\n"
2030 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
2034 void MWindow::create_objects(int want_gui,
2038 const int debug = 0;
2039 if(debug) PRINT_TRACE
2041 // For some reason, init_signals must come after show_splash or the signals won't
2044 if(debug) PRINT_TRACE
2047 if(debug) PRINT_TRACE
2050 if(debug) PRINT_TRACE
2051 default_standard = default_std();
2052 init_defaults(defaults, config_path);
2056 splash_window->operation->update(_("Initializing Plugins"));
2057 init_plugins(this, preferences);
2058 if(debug) PRINT_TRACE
2059 init_ladspa_plugins(this, preferences);
2060 if(debug) PRINT_TRACE
2061 init_plugin_tips(*plugindb, cin_lang);
2063 splash_window->operation->update(_("Initializing GUI"));
2064 if(debug) PRINT_TRACE
2067 if(debug) PRINT_TRACE
2071 splash_window->operation->update(_("Initializing Fonts"));
2072 char string[BCTEXTLEN];
2073 strcpy(string, preferences->plugin_dir);
2074 strcat(string, "/" FONT_SEARCHPATH);
2075 BC_Resources::init_fontconfig(string);
2076 if(debug) PRINT_TRACE
2078 // Initialize before too much else is running
2079 // Preferences & theme are required for building MPEG table of contents
2081 // Default project created here
2083 if(debug) PRINT_TRACE
2086 if(debug) PRINT_TRACE
2091 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2094 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2096 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2097 if(session->show_vwindow)
2098 get_viewer(1, DEFAULT_VWINDOW);
2099 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2102 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2105 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2108 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2111 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2114 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2117 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2122 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2123 mainprogress = new MainProgress(this, gui);
2124 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2125 undo = new MainUndo(this);
2127 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2129 plugin_guis = new ArrayList<PluginServer*>;
2130 dead_plugins = new ArrayList<PluginServer*>;
2131 keyframe_threads = new ArrayList<KeyFrameThread*>;
2133 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2136 session->show_vwindow);
2138 // Show all vwindows
2139 // if(session->show_vwindow) {
2140 // for(int j = 0; j < vwindows.size(); j++) {
2141 // VWindow *vwindow = vwindows[j];
2142 // if( !vwindow->is_running() ) continue;
2143 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2146 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2147 // vwindow->gui->lock_window("MWindow::create_objects 1");
2148 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2149 // vwindow->gui->show_window();
2150 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2151 // vwindow->gui->unlock_window();
2156 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2158 if(session->show_cwindow)
2160 cwindow->gui->lock_window("MWindow::create_objects 1");
2161 cwindow->gui->show_window();
2162 cwindow->gui->unlock_window();
2165 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2166 if(session->show_awindow)
2168 awindow->gui->lock_window("MWindow::create_objects 1");
2169 awindow->gui->show_window();
2170 awindow->gui->unlock_window();
2173 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2174 if(session->show_lwindow)
2176 lwindow->gui->lock_window("MWindow::create_objects 1");
2177 lwindow->gui->show_window();
2178 lwindow->gui->unlock_window();
2181 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2183 (int)timer.get_difference(),
2185 if(session->show_gwindow)
2187 gwindow->gui->lock_window("MWindow::create_objects 1");
2188 gwindow->gui->show_window();
2189 gwindow->gui->unlock_window();
2192 if(debug) PRINT_TRACE
2194 gui->lock_window("MWindow::create_objects 1");
2195 gui->mainmenu->load_defaults(defaults);
2196 gui->mainmenu->update_toggles(0);
2197 gui->update_patchbay();
2198 gui->draw_canvas(0, 0);
2199 gui->draw_cursor(1);
2201 gui->raise_window();
2202 gui->unlock_window();
2204 if(debug) PRINT_TRACE
2206 if(preferences->use_tipwindow)
2208 if(debug) PRINT_TRACE
2210 gui->add_keyboard_listener(
2211 (int (BC_WindowBase::*)(BC_WindowBase *))
2212 &MWindowGUI::keyboard_listener);
2216 if(debug) PRINT_TRACE
2218 BC_WindowBase::get_resources()->vframe_shm = 1;
2222 void MWindow::show_splash()
2224 #include "data/heroine_logo9_png.h"
2225 VFrame *frame = new VFramePng(heroine_logo9_png);
2226 BC_DisplayInfo dpyi;
2227 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2228 int rr = (rw < rh ? rw : rh) / 4;
2229 splash_window = new SplashGUI(frame, rr, rr);
2230 splash_window->create_objects();
2233 void MWindow::hide_splash()
2236 delete splash_window;
2241 void MWindow::start()
2245 // vwindows[DEFAULT_VWINDOW]->start();
2256 playback_3d->start();
2262 run_lock->lock("MWindow::run");
2266 brender_lock->lock("MWindow::run 1");
2267 delete brender; brender = 0;
2268 brender_lock->unlock();
2270 interrupt_indexes();
2276 void MWindow::show_vwindow()
2278 int total_running = 0;
2279 session->show_vwindow = 1;
2281 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2282 // Raise all windows which are visible
2283 for(int j = 0; j < vwindows.size(); j++) {
2284 VWindow *vwindow = vwindows[j];
2285 if( !vwindow->is_running() ) continue;
2286 vwindow->gui->lock_window("MWindow::show_vwindow");
2287 vwindow->gui->show_window(0);
2288 vwindow->gui->raise_window();
2289 vwindow->gui->flush();
2290 vwindow->gui->unlock_window();
2294 // If no windows visible
2297 get_viewer(1, DEFAULT_VWINDOW);
2300 gui->mainmenu->show_vwindow->set_checked(1);
2303 void MWindow::show_awindow()
2305 session->show_awindow = 1;
2306 awindow->gui->lock_window("MWindow::show_awindow");
2307 awindow->gui->show_window();
2308 awindow->gui->raise_window();
2309 awindow->gui->flush();
2310 awindow->gui->unlock_window();
2311 gui->mainmenu->show_awindow->set_checked(1);
2314 char *MWindow::get_cwindow_display()
2316 char *x11_host = screens < 2 || session->window_config == 0 ?
2317 session->a_x11_host : session->b_x11_host;
2318 return *x11_host ? x11_host : 0;
2321 void MWindow::show_cwindow()
2323 session->show_cwindow = 1;
2324 cwindow->show_window();
2325 gui->mainmenu->show_cwindow->set_checked(1);
2328 void MWindow::show_gwindow()
2330 session->show_gwindow = 1;
2332 gwindow->gui->lock_window("MWindow::show_gwindow");
2333 gwindow->gui->show_window();
2334 gwindow->gui->raise_window();
2335 gwindow->gui->flush();
2336 gwindow->gui->unlock_window();
2338 gui->mainmenu->show_gwindow->set_checked(1);
2340 void MWindow::hide_gwindow()
2342 session->show_gwindow = 0;
2344 gwindow->gui->lock_window("MWindow::show_gwindow");
2345 gwindow->gui->hide_window();
2346 gwindow->gui->unlock_window();
2349 void MWindow::show_lwindow()
2351 session->show_lwindow = 1;
2352 lwindow->gui->lock_window("MWindow::show_lwindow");
2353 lwindow->gui->show_window();
2354 lwindow->gui->raise_window();
2355 lwindow->gui->flush();
2356 lwindow->gui->unlock_window();
2357 gui->mainmenu->show_lwindow->set_checked(1);
2360 int MWindow::tile_windows(int window_config)
2362 int need_reload = 0;
2363 int play_config = window_config==0 ? 0 : 1;
2364 edl->session->playback_config->load_defaults(defaults, play_config);
2365 session->default_window_positions(window_config);
2366 if( screens == 1 ) {
2367 gui->default_positions();
2368 sync_parameters(CHANGE_ALL);
2375 void MWindow::toggle_loop_playback()
2377 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2378 set_loop_boundaries();
2381 gui->draw_overlays(1);
2382 sync_parameters(CHANGE_PARAMS);
2385 //void MWindow::set_titles(int value)
2387 // edl->session->show_titles = value;
2388 // trackmovement(edl->local_session->track_start);
2391 void MWindow::set_screens(int value)
2396 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2398 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2399 edl->session->auto_keyframes = value;
2400 gui->mbuttons->edit_panel->keyframe->update(value);
2402 if(lock_mwindow) gui->unlock_window();
2404 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2405 cwindow->gui->edit_panel->keyframe->update(value);
2406 cwindow->gui->flush();
2407 if(lock_cwindow) cwindow->gui->unlock_window();
2410 void MWindow::set_auto_visibility(Autos *autos, int value)
2412 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2413 edl->session->auto_conf->plugins = value;
2414 else if( autos->autoidx >= 0 )
2415 edl->session->auto_conf->autos[autos->autoidx] = value;
2419 gui->update(0, 1, 0, 0, 0, 0, 0);
2420 gui->mainmenu->update_toggles(1);
2421 gui->unlock_window();
2422 gwindow->gui->update_toggles(1);
2423 gui->lock_window("MWindow::set_auto_visibility");
2426 void MWindow::set_keyframe_type(int mode)
2428 gui->lock_window("MWindow::set_keyframe_type");
2429 edl->local_session->floatauto_type = mode;
2430 gui->mainmenu->update_toggles(0);
2431 gui->unlock_window();
2434 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2436 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2437 edl->session->editing_mode = new_editing_mode;
2438 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2439 gui->mbuttons->edit_panel->update();
2440 gui->set_editing_mode(1);
2441 if(lock_mwindow) gui->unlock_window();
2444 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2445 cwindow->gui->edit_panel->update();
2446 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2447 if(lock_cwindow) cwindow->gui->unlock_window();
2451 void MWindow::toggle_editing_mode()
2453 int mode = edl->session->editing_mode;
2454 if( mode == EDITING_ARROW )
2455 set_editing_mode(EDITING_IBEAM, 0, 1);
2457 set_editing_mode(EDITING_ARROW, 0, 1);
2461 void MWindow::set_labels_follow_edits(int value)
2463 gui->lock_window("MWindow::set_labels_follow_edits");
2464 edl->session->labels_follow_edits = value;
2465 gui->mbuttons->edit_panel->locklabels->update(value);
2466 gui->mainmenu->labels_follow_edits->set_checked(value);
2468 gui->unlock_window();
2471 void MWindow::sync_parameters(int change_type)
2473 if( in_destructor ) return;
2475 // Sync engines which are playing back
2476 if(cwindow->playback_engine->is_playing_back)
2478 if(change_type == CHANGE_PARAMS)
2480 // TODO: block keyframes until synchronization is done
2481 cwindow->playback_engine->sync_parameters(edl);
2486 int command = cwindow->playback_engine->command->command;
2487 cwindow->playback_engine->que->send_command(STOP,
2491 // Waiting for tracking to finish would make the restart position more
2492 // accurate but it can't lock the window to stop tracking for some reason.
2493 // Not waiting for tracking gives a faster response but restart position is
2494 // only as accurate as the last tracking update.
2495 cwindow->playback_engine->interrupt_playback(0);
2496 cwindow->playback_engine->que->send_command(command,
2505 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2512 void MWindow::age_caches()
2514 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2516 // preferences->cache_size,
2517 // audio_cache->get_memory_usage(1),
2518 // video_cache->get_memory_usage(1),
2519 // frame_cache->get_memory_usage(),
2520 // wave_cache->get_memory_usage(),
2522 frame_cache->age_cache(512);
2523 wave_cache->age_cache(8192);
2525 int64_t memory_usage;
2526 int64_t prev_memory_usage = 0;
2528 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2529 while( !result && prev_memory_usage !=
2530 (memory_usage=video_cache->get_memory_usage(1)) &&
2531 memory_usage > video_size ) {
2532 video_cache->delete_oldest();
2533 prev_memory_usage = memory_usage;
2536 prev_memory_usage = 0;
2538 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2539 while( !result && prev_memory_usage !=
2540 (memory_usage=audio_cache->get_memory_usage(1)) &&
2541 memory_usage > audio_size ) {
2542 audio_cache->delete_oldest();
2543 prev_memory_usage = memory_usage;
2547 void MWindow::reset_android_remote()
2549 gui->use_android_remote(preferences->android_remote);
2553 void MWindow::show_keyframe_gui(Plugin *plugin)
2555 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2556 // Find existing thread
2557 for(int i = 0; i < keyframe_threads->size(); i++)
2559 if(keyframe_threads->get(i)->plugin == plugin)
2561 keyframe_threads->get(i)->start_window(plugin, 0);
2562 keyframe_gui_lock->unlock();
2567 // Find unused thread
2568 for(int i = 0; i < keyframe_threads->size(); i++)
2570 if(!keyframe_threads->get(i)->plugin)
2572 keyframe_threads->get(i)->start_window(plugin, 0);
2573 keyframe_gui_lock->unlock();
2578 // Create new thread
2579 KeyFrameThread *thread = new KeyFrameThread(this);
2580 keyframe_threads->append(thread);
2581 thread->start_window(plugin, 0);
2583 keyframe_gui_lock->unlock();
2590 void MWindow::show_plugin(Plugin *plugin)
2595 // Remove previously deleted plugin GUIs
2596 dead_plugin_lock->lock("MWindow::show_plugin");
2597 dead_plugins->remove_all_objects();
2598 dead_plugin_lock->unlock();
2600 //printf("MWindow::show_plugin %d\n", __LINE__);
2604 plugin_gui_lock->lock("MWindow::show_plugin");
2605 for(int i = 0; i < plugin_guis->total; i++)
2607 // Pointer comparison
2608 if(plugin_guis->get(i)->plugin == plugin)
2610 plugin_guis->get(i)->raise_window();
2617 //printf("MWindow::show_plugin 1\n");
2618 if( !done && !plugin->track ) {
2619 printf("MWindow::show_plugin track not defined.\n");
2623 PluginServer *server = scan_plugindb(plugin->title,
2624 plugin->track->data_type);
2626 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2627 if(server && server->uses_gui)
2629 PluginServer *gui = new PluginServer(*server);
2630 plugin_guis->append(gui);
2631 // Needs mwindow to do GUI
2632 gui->set_mwindow(this);
2633 gui->open_plugin(0, preferences, edl, plugin);
2638 plugin_gui_lock->unlock();
2639 //printf("MWindow::show_plugin %d\n", __LINE__);
2642 //printf("MWindow::show_plugin 2\n");
2645 void MWindow::hide_plugin(Plugin *plugin, int lock)
2648 // Update the toggle
2649 gui->lock_window("MWindow::hide_plugin");
2650 gui->update(0, 1, 0, 0, 0, 0, 0);
2651 gui->unlock_window();
2653 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2654 for(int i = 0; i < plugin_guis->total; i++)
2656 if(plugin_guis->get(i)->plugin == plugin)
2658 PluginServer *ptr = plugin_guis->get(i);
2659 plugin_guis->remove(ptr);
2660 if(lock) plugin_gui_lock->unlock();
2661 // Last command executed in client side close
2662 // Schedule for deletion
2669 if(lock) plugin_gui_lock->unlock();
2672 void MWindow::delete_plugin(PluginServer *plugin)
2674 dead_plugin_lock->lock("MWindow::delete_plugin");
2675 dead_plugins->append(plugin);
2676 dead_plugin_lock->unlock();
2679 void MWindow::hide_plugins()
2681 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2682 while(plugin_guis->size())
2684 PluginServer *ptr = plugin_guis->get(0);
2685 plugin_guis->remove(ptr);
2686 plugin_gui_lock->unlock();
2687 // Last command executed in client side close
2688 // Schedule for deletion
2691 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2693 plugin_gui_lock->unlock();
2695 hide_keyframe_guis();
2698 void MWindow::hide_keyframe_guis()
2700 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2701 for(int i = 0; i < keyframe_threads->size(); i++)
2703 keyframe_threads->get(i)->close_window();
2705 keyframe_gui_lock->unlock();
2708 void MWindow::hide_keyframe_gui(Plugin *plugin)
2710 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2711 for(int i = 0; i < keyframe_threads->size(); i++)
2713 if(keyframe_threads->get(i)->plugin == plugin)
2715 keyframe_threads->get(i)->close_window();
2719 keyframe_gui_lock->unlock();
2722 void MWindow::update_keyframe_guis()
2724 // Send new configuration to keyframe GUI's
2725 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2726 for(int i = 0; i < keyframe_threads->size(); i++)
2728 KeyFrameThread *ptr = keyframe_threads->get(i);
2729 if(edl->tracks->plugin_exists(ptr->plugin))
2733 ptr->close_window();
2736 keyframe_gui_lock->unlock();
2739 void MWindow::update_plugin_guis(int do_keyframe_guis)
2741 // Send new configuration to plugin GUI's
2742 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2744 for(int i = 0; i < plugin_guis->size(); i++)
2746 PluginServer *ptr = plugin_guis->get(i);
2747 if(edl->tracks->plugin_exists(ptr->plugin))
2751 // Schedule for deletion if no plugin
2752 plugin_guis->remove_number(i);
2761 // Change plugin variable if not visible
2762 Track *track = edl->tracks->first;
2765 for(int i = 0; i < track->plugin_set.size(); i++)
2767 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2771 for(int i = 0; i < plugin_guis->size(); i++)
2773 PluginServer *server = plugin_guis->get(i);
2774 if(server->plugin == plugin)
2781 if(!got_it) plugin->show = 0;
2783 plugin = (Plugin*)plugin->next;
2787 track = track->next;
2790 plugin_gui_lock->unlock();
2793 if(do_keyframe_guis) update_keyframe_guis();
2796 int MWindow::plugin_gui_open(Plugin *plugin)
2799 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2800 for(int i = 0; i < plugin_guis->total; i++)
2802 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2808 plugin_gui_lock->unlock();
2812 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2814 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2815 for(int i = 0; i < plugin_guis->total; i++)
2817 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2819 plugin_guis->get(i)->render_gui(data);
2823 plugin_gui_lock->unlock();
2826 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2828 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2829 for(int i = 0; i < plugin_guis->total; i++)
2831 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2833 plugin_guis->get(i)->render_gui(data, size);
2837 plugin_gui_lock->unlock();
2841 void MWindow::update_plugin_states()
2843 plugin_gui_lock->lock("MWindow::update_plugin_states");
2844 for(int i = 0; i < plugin_guis->total; i++)
2848 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2849 PluginServer *src_plugingui = plugin_guis->get(i);
2851 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2852 for(Track *track = edl->tracks->first;
2854 track = track->next)
2857 j < track->plugin_set.total && !result;
2860 PluginSet *plugin_set = track->plugin_set[j];
2861 for(Plugin *plugin = (Plugin*)plugin_set->first;
2863 plugin = (Plugin*)plugin->next)
2865 if(plugin == src_plugin &&
2866 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2872 // Doesn't exist anymore
2875 hide_plugin(src_plugin, 0);
2879 plugin_gui_lock->unlock();
2883 void MWindow::update_plugin_titles()
2885 for(int i = 0; i < plugin_guis->total; i++)
2887 plugin_guis->get(i)->update_title();
2891 int MWindow::asset_to_edl(EDL *new_edl,
2893 RecordLabels *labels)
2895 const int debug = 0;
2896 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2899 // Keep frame rate, sample rate, and output size unchanged.
2900 // These parameters would revert the project if VWindow displayed an asset
2901 // of different size than the project.
2902 if(new_asset->video_data)
2904 new_edl->session->video_tracks = new_asset->layers;
2907 new_edl->session->video_tracks = 0;
2909 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2915 if(new_asset->audio_data)
2917 new_edl->session->audio_tracks = new_asset->channels;
2920 new_edl->session->audio_tracks = 0;
2921 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2923 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2924 new_edl->create_default_tracks();
2925 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2926 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2930 //printf("MWindow::asset_to_edl 3\n");
2931 new_edl->insert_asset(new_asset,
2936 //printf("MWindow::asset_to_edl 3\n");
2937 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2939 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2940 if(edl->session->cursor_on_frames)
2942 double length = new_edl->tracks->total_length();
2943 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2944 new_edl->tracks->clear(length, edl_length, 1, 1);
2950 char string[BCTEXTLEN];
2952 fs.extract_name(string, new_asset->path);
2953 //printf("MWindow::asset_to_edl 3\n");
2955 strcpy(new_edl->local_session->clip_title, string);
2956 //printf("MWindow::asset_to_edl 4 %s\n", string);
2957 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2962 int MWindow::edl_to_nested(EDL *new_edl,
2966 // Keep frame rate, sample rate, and output size unchanged.
2967 // These parameters would revert the project if VWindow displayed an asset
2968 // of different size than the project.
2972 // Nest all video & audio outputs
2973 new_edl->session->video_tracks = 1;
2974 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2975 new_edl->create_default_tracks();
2979 new_edl->insert_asset(0,
2985 char string[BCTEXTLEN];
2987 fs.extract_name(string, nested_edl->path);
2988 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2990 strcpy(new_edl->local_session->clip_title, string);
2995 // Reset everything after a load.
2996 void MWindow::update_project(int load_mode)
2998 const int debug = 0;
3000 if(debug) PRINT_TRACE
3002 edl->tracks->update_y_pixels(theme);
3004 if(debug) PRINT_TRACE
3006 if(load_mode == LOADMODE_REPLACE ||
3007 load_mode == LOADMODE_REPLACE_CONCATENATE)
3012 gui->update(1, 1, 1, 1, 1, 1, 1);
3013 if(debug) PRINT_TRACE
3014 gui->unlock_window();
3016 cwindow->gui->lock_window("MWindow::update_project 1");
3017 cwindow->update(0, 0, 1, 1, 1);
3018 cwindow->gui->unlock_window();
3020 if(debug) PRINT_TRACE
3022 // Close all the vwindows
3023 if(load_mode == LOADMODE_REPLACE ||
3024 load_mode == LOADMODE_REPLACE_CONCATENATE) {
3025 if(debug) PRINT_TRACE
3026 int first_vwindow = 0;
3027 if(session->show_vwindow) first_vwindow = 1;
3028 // Change visible windows to no source
3029 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3030 VWindow *vwindow = vwindows[i];
3031 if( !vwindow->is_running() ) continue;
3032 vwindow->change_source(-1);
3035 // Close remaining windows
3036 for(int i = first_vwindow; i < vwindows.size(); i++) {
3037 VWindow *vwindow = vwindows[i];
3038 if( !vwindow->is_running() ) continue;
3039 vwindow->close_window();
3041 if(debug) PRINT_TRACE
3043 else if(vwindows.size()) {
3044 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3045 if( vwindow->is_running() ) {
3046 vwindow->gui->lock_window("MWindow::update_project");
3048 vwindow->gui->unlock_window();
3052 if(debug) PRINT_TRACE
3053 cwindow->gui->lock_window("MWindow::update_project 2");
3054 cwindow->gui->timebar->update(0);
3055 cwindow->gui->unlock_window();
3057 if(debug) PRINT_TRACE
3058 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3063 awindow->gui->async_update_assets();
3064 if(debug) PRINT_TRACE
3066 gui->lock_window("MWindow::update_project");
3068 if(debug) PRINT_TRACE
3071 void MWindow::remove_indexfile(Indexable *indexable)
3073 if( !indexable->is_asset ) return;
3074 Asset *asset = (Asset *)indexable;
3076 IndexFile::delete_index(preferences, asset, ".toc");
3077 IndexFile::delete_index(preferences, asset, ".idx");
3078 IndexFile::delete_index(preferences, asset, ".mkr");
3081 void MWindow::rebuild_indices()
3083 for(int i = 0; i < session->drag_assets->total; i++)
3085 Indexable *indexable = session->drag_assets->get(i);
3086 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3087 remove_indexfile(indexable);
3088 // Schedule index build
3089 IndexState *index_state = indexable->index_state;
3090 index_state->index_status = INDEX_NOTTESTED;
3091 if( indexable->is_asset ) {
3092 Asset *asset = (Asset *)indexable;
3093 if( asset->format != FILE_PCM ) {
3094 asset->format = FILE_UNKNOWN;
3095 asset->reset_audio();
3097 asset->reset_video();
3098 // File file; // re-probe the asset
3099 // file.open_file(preferences, asset, 1, 0);
3101 mainindexes->add_next_asset(0, indexable);
3103 mainindexes->start_build();
3107 void MWindow::save_backup()
3111 edl->set_path(session->filename);
3112 char backup_path[BCTEXTLEN];
3113 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3114 File::get_config_path(), BACKUP_FILE);
3115 edl->save_xml(&file, backup_path, 0, 0);
3116 file.terminate_string();
3118 fs.complete_path(backup_path);
3120 if(file.write_to_file(backup_path))
3123 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3124 gui->show_message(string2);
3128 void MWindow::load_backup()
3130 ArrayList<char*> path_list;
3131 path_list.set_array_delete();
3133 char backup_path[BCTEXTLEN];
3134 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3135 File::get_config_path(), BACKUP_FILE);
3137 fs.complete_path(backup_path);
3139 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3140 strcpy(out_path, backup_path);
3142 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3143 edl->local_session->clip_title[0] = 0;
3144 // This is unique to backups since the path of the backup is different than the
3145 // path of the project.
3146 set_filename(edl->path);
3147 path_list.remove_all_objects();
3151 static inline int gcd(int m, int n)
3154 if( m < n ) { r = m; m = n; n = r; }
3155 while( (r = m % n) != 0 ) { m = n; n = r; }
3159 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3162 if(!width || !height) return 1;
3163 if( width == 720 && (height == 480 || height == 576) ) {
3164 w = 4; h = 3; return 0; // for NTSC and PAL
3166 double ar = (double)width / height;
3167 // square-ish pixels
3168 if( EQUIV(ar, 1.0000) ) return 0;
3169 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3170 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3171 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3172 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3173 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3174 int ww = width, hh = height;
3175 // numerator, denominator must be under mx
3176 int mx = 255, n = gcd(ww, hh);
3177 if( n > 1 ) { ww /= n; hh /= n; }
3178 // search near height in case extra/missing lines
3179 if( ww >= mx || hh >= mx ) {
3180 double err = height; // +/- 2 percent height
3181 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3182 int iw = width, ih = height+i;
3183 if( (n=gcd(iw, ih)) > 1 ) {
3184 int u = iw/n; if( u >= mx ) continue;
3185 int v = ih/n; if( v >= mx ) continue;
3186 double r = (double) u/v, er = fabs(ar-r);
3187 if( er >= err ) continue;
3188 err = er; ww = u; hh = v;
3197 void MWindow::reset_caches()
3199 frame_cache->remove_all();
3200 wave_cache->remove_all();
3201 audio_cache->remove_all();
3202 video_cache->remove_all();
3203 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3204 cwindow->playback_engine->audio_cache->remove_all();
3205 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3206 cwindow->playback_engine->video_cache->remove_all();
3208 for(int i = 0; i < vwindows.size(); i++) {
3209 VWindow *vwindow = vwindows[i];
3210 if( !vwindow->is_running() ) continue;
3211 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3212 vwindow->playback_engine->audio_cache->remove_all();
3213 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3214 vwindow->playback_engine->video_cache->remove_all();
3218 void MWindow::remove_asset_from_caches(Asset *asset)
3220 gui->resource_thread->get_video_source(0);
3221 gui->resource_thread->get_audio_source(0);
3222 frame_cache->remove_asset(asset);
3223 wave_cache->remove_asset(asset);
3224 audio_cache->delete_entry(asset);
3225 video_cache->delete_entry(asset);
3226 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3227 cwindow->playback_engine->audio_cache->delete_entry(asset);
3228 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3229 cwindow->playback_engine->video_cache->delete_entry(asset);
3230 for(int i = 0; i < vwindows.size(); i++) {
3231 VWindow *vwindow = vwindows[i];
3232 if( !vwindow->is_running() ) continue;
3233 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3234 vwindow->playback_engine->audio_cache->delete_entry(asset);
3235 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3236 vwindow->playback_engine->video_cache->delete_entry(asset);
3241 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3242 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3244 for(int i = 0; i < drag_assets->total; i++) {
3245 Indexable *indexable = drag_assets->get(i);
3246 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3249 // Remove from VWindow.
3250 for(int i = 0; i < session->drag_clips->total; i++) {
3251 for(int j = 0; j < vwindows.size(); j++) {
3252 VWindow *vwindow = vwindows[j];
3253 if( !vwindow->is_running() ) continue;
3254 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3255 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3256 vwindow->delete_source(1, 1);
3257 vwindow->gui->unlock_window();
3262 for(int i = 0; i < drag_assets->size(); i++) {
3263 for(int j = 0; j < vwindows.size(); j++) {
3264 VWindow *vwindow = vwindows[j];
3265 if( !vwindow->is_running() ) continue;
3266 if(drag_assets->get(i) == vwindow->get_source()) {
3267 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3268 vwindow->delete_source(1, 1);
3269 vwindow->gui->unlock_window();
3274 for(int i = 0; i < drag_assets->size(); i++) {
3275 Indexable *indexable = drag_assets->get(i);
3276 remove_indexfile(indexable);
3279 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3280 if(push_undo) undo->update_undo_before();
3281 if(drag_assets) edl->remove_from_project(drag_assets);
3282 if(drag_clips) edl->remove_from_project(drag_clips);
3283 if(redraw) save_backup();
3284 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3288 gui->lock_window("MWindow::remove_assets_from_project 3");
3289 gui->update(1, 1, 1, 1, 0, 1, 0);
3290 gui->unlock_window();
3292 // Removes from playback here
3293 sync_parameters(CHANGE_ALL);
3296 awindow->gui->async_update_assets();
3299 void MWindow::remove_assets_from_disk()
3302 for(int i = 0; i < session->drag_assets->total; i++)
3304 remove(session->drag_assets->get(i)->path);
3307 remove_assets_from_project(1,
3309 session->drag_assets,
3310 session->drag_clips);
3313 void MWindow::dump_plugins(FILE *fp)
3315 if( !plugindb ) return;
3316 for(int i = 0; i < plugindb->total; i++)
3318 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3319 " synth=%d transition=%d theme=%d %s\n",
3320 plugindb->get(i)->plugin_type,
3321 plugindb->get(i)->audio,
3322 plugindb->get(i)->video,
3323 plugindb->get(i)->realtime,
3324 plugindb->get(i)->multichannel,
3325 plugindb->get(i)->get_synthesis(),
3326 plugindb->get(i)->transition,
3327 plugindb->get(i)->theme,
3328 plugindb->get(i)->title);
3332 void MWindow::dump_edl(FILE *fp)
3338 void MWindow::dump_undo(FILE *fp)
3344 void MWindow::dump_exe(FILE *fp)
3346 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3347 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3349 int ret = -1, n = 100;
3350 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3351 exe_path[len] = 0; strcpy(proc_path, exe_path);
3354 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3357 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3358 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3359 struct tm *tm = localtime(&st.st_mtime);
3361 strftime(mtime, sizeof(mtime), "%F %T", tm);
3362 fprintf(fp,"mtime: %s\n", mtime);
3364 // people hit ctl-c waiting for this
3365 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3366 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3369 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3370 int64_t maxsz = 1024*pagsz;
3371 int64_t size = st.st_size, pos = 0;
3373 while( (bfrsz = size-pos) > 0 ) {
3374 if( bfrsz > maxsz ) bfrsz = maxsz;
3375 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3376 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3377 if( bfr == MAP_FAILED ) break;
3378 sha1.addBytes(bfr, bfrsz);
3383 ret = pos < size ? EIO : 0;
3384 fprintf(fp, "SHA1: ");
3385 uint8_t digest[20]; sha1.computeHash(digest);
3386 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3387 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3388 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3393 void MWindow::trap_hook(FILE *fp, void *vp)
3395 MWindow *mwindow = (MWindow *)vp;
3396 // fprintf(fp, "\nPLUGINS:\n");
3397 // mwindow->dump_plugins(fp);
3398 fprintf(fp, "\nEDL:\n");
3399 mwindow->dump_edl(fp);
3400 fprintf(fp, "\nUNDO:\n");
3401 mwindow->dump_undo(fp);
3402 fprintf(fp, "\nEXE:\n");
3403 mwindow->dump_exe(fp);
3411 int MWindow::save_defaults()
3413 gui->save_defaults(defaults);
3414 edl->save_defaults(defaults);
3415 session->save_defaults(defaults);
3416 preferences->save_defaults(defaults);
3418 for(int i = 0; i < plugin_guis->total; i++)
3420 // Pointer comparison
3421 plugin_guis->get(i)->save_defaults();
3423 awindow->save_defaults(defaults);
3429 int MWindow::run_script(FileXML *script)
3431 int result = 0, result2 = 0;
3432 while(!result && !result2)
3434 result = script->read_tag();
3437 if(script->tag.title_is("new_project"))
3439 // Run new in immediate mode.
3440 // gui->mainmenu->new_project->run_script(script);
3443 if(script->tag.title_is("record"))
3445 // Run record as a thread. It is a terminal command.
3447 // Will read the complete scipt file without letting record read it if not
3453 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3460 // ================================= synchronization
3463 int MWindow::interrupt_indexes()
3465 mainprogress->cancelled = 1;
3466 mainindexes->interrupt_build();
3472 void MWindow::next_time_format()
3474 switch(edl->session->time_format)
3476 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3477 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3478 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3479 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3480 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3481 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3482 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3485 time_format_common();
3488 void MWindow::prev_time_format()
3490 switch(edl->session->time_format)
3492 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3493 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3494 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3495 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3496 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3497 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3498 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3501 time_format_common();
3504 void MWindow::time_format_common()
3506 gui->lock_window("MWindow::next_time_format");
3507 gui->redraw_time_dependancies();
3510 char string[BCTEXTLEN], string2[BCTEXTLEN];
3511 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3512 gui->show_message(string);
3514 gui->unlock_window();
3518 int MWindow::set_filename(const char *filename)
3520 if( filename != session->filename )
3521 strcpy(session->filename, filename);
3522 if( filename != edl->path )
3523 strcpy(edl->path, filename);
3527 if(filename[0] == 0)
3529 gui->set_title(PROGRAM_NAME);
3534 char string[BCTEXTLEN], string2[BCTEXTLEN];
3535 dir.extract_name(string, filename);
3536 sprintf(string2, PROGRAM_NAME ": %s", string);
3537 gui->set_title(string2);
3550 int MWindow::set_loop_boundaries()
3552 double start = edl->local_session->get_selectionstart();
3553 double end = edl->local_session->get_selectionend();
3561 if(edl->tracks->total_length())
3564 end = edl->tracks->total_length();
3571 if(edl->local_session->loop_playback && start != end)
3573 edl->local_session->loop_start = start;
3574 edl->local_session->loop_end = end;
3585 int MWindow::reset_meters()
3587 cwindow->gui->lock_window("MWindow::reset_meters 1");
3588 cwindow->gui->meters->reset_meters();
3589 cwindow->gui->unlock_window();
3591 for(int j = 0; j < vwindows.size(); j++) {
3592 VWindow *vwindow = vwindows[j];
3593 if( !vwindow->is_running() ) continue;
3594 vwindow->gui->lock_window("MWindow::reset_meters 2");
3595 vwindow->gui->meters->reset_meters();
3596 vwindow->gui->unlock_window();
3599 lwindow->gui->lock_window("MWindow::reset_meters 3");
3600 lwindow->gui->panel->reset_meters();
3601 lwindow->gui->unlock_window();
3603 gui->lock_window("MWindow::reset_meters 4");
3604 gui->reset_meters();
3605 gui->unlock_window();
3610 void MWindow::resync_guis()
3614 gui->lock_window("MWindow::resync_guis");
3615 gui->update(1, 1, 1, 1, 1, 1, 0);
3616 gui->unlock_window();
3618 cwindow->gui->lock_window("MWindow::resync_guis");
3619 cwindow->gui->resize_event(cwindow->gui->get_w(),
3620 cwindow->gui->get_h());
3621 int channels = edl->session->audio_channels;
3622 cwindow->gui->meters->set_meters(channels, 1);
3623 cwindow->gui->flush();
3624 cwindow->gui->unlock_window();
3626 for(int i = 0; i < vwindows.size(); i++) {
3627 VWindow *vwindow = vwindows[i];
3628 if( !vwindow->is_running() ) continue;
3629 vwindow->gui->lock_window("MWindow::resync_guis");
3630 vwindow->gui->resize_event(vwindow->gui->get_w(),
3631 vwindow->gui->get_h());
3632 vwindow->gui->meters->set_meters(channels, 1);
3633 vwindow->gui->flush();
3634 vwindow->gui->unlock_window();
3637 lwindow->gui->lock_window("MWindow::resync_guis");
3638 lwindow->gui->panel->set_meters(channels, 1);
3639 lwindow->gui->flush();
3640 lwindow->gui->unlock_window();
3643 if(((edl->session->output_w % 4) ||
3644 (edl->session->output_h % 4)) &&
3645 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3647 MainError::show_error(
3648 _("This project's dimensions are not multiples of 4 so\n"
3649 "it can't be rendered by OpenGL."));
3654 sync_parameters(CHANGE_ALL);
3657 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3659 File *file = new File;
3660 EDLSession *session = edl->session;
3661 double old_framerate = session->frame_rate;
3662 double old_samplerate = session->sample_rate;
3663 int old_auto_keyframes = session->auto_keyframes;
3664 session->auto_keyframes = 0;
3665 int result = file->open_file(preferences, asset, 1, 0);
3666 if( !result && delete_tracks > 0 )
3667 undo->update_undo_before();
3668 int video_layers = asset->get_video_layers();
3669 if( !result && asset->video_data && vstream < video_layers ) {
3670 // try to get asset up to date, may fail
3671 file->select_video_stream(asset, vstream);
3672 // either way use what was/is there.
3673 double framerate = asset->get_frame_rate();
3674 int width = asset->get_w();
3675 int height = asset->get_h();
3676 // must be multiple of 4 for opengl
3677 width = (width+3) & ~3; height = (height+3) & ~3;
3678 int driver = session->playback_config->vconfig->driver;
3679 int color_model = file->get_best_colormodel(asset, driver);
3680 // color_model = BC_CModels::is_yuv(color_model) ?
3681 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3682 // BC_CModels::is_float(color_model) ?
3683 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3684 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3685 // have alpha for now
3686 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3687 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3688 session->color_model = color_model;
3689 session->output_w = width;
3690 session->output_h = height;
3691 session->frame_rate = framerate;
3692 // not, asset->actual_width/actual_height
3693 asset->width = session->output_w;
3694 asset->height = session->output_h;
3695 asset->frame_rate = session->frame_rate;
3696 create_aspect_ratio(session->aspect_w, session->aspect_h,
3697 session->output_w, session->output_h);
3698 Track *track = edl->tracks->first;
3699 for( Track *next_track=0; track; track=next_track ) {
3700 next_track = track->next;
3701 if( track->data_type != TRACK_VIDEO ) continue;
3702 if( delete_tracks ) {
3703 Edit *edit = track->edits->first;
3704 for( Edit *next_edit=0; edit; edit=next_edit ) {
3705 next_edit = edit->next;
3706 if( edit->channel != vstream ||
3707 !edit->asset || !edit->asset->is_asset ||
3708 !asset->equivalent(*edit->asset,1,1,edl) )
3712 if( track->edits->first ) {
3713 track->track_w = edl->session->output_w;
3714 track->track_h = edl->session->output_h;
3716 else if( delete_tracks )
3717 edl->tracks->delete_track(track);
3720 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3722 if( !result && asset->audio_data && asset->channels > 0 ) {
3723 session->sample_rate = asset->get_sample_rate();
3724 int64_t channel_mask = 0;
3725 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
3726 file->get_audio_for_video(vstream, astream, channel_mask);
3727 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3728 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3730 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3731 if( channels < 1 ) channels = 1;
3732 if( channels > 6 ) channels = 6;
3733 session->audio_tracks = session->audio_channels = channels;
3734 switch( channels ) {
3736 session->achannel_positions[0] = 90;
3737 session->achannel_positions[1] = 150;
3738 session->achannel_positions[2] = 30;
3739 session->achannel_positions[3] = 210;
3740 session->achannel_positions[4] = 330;
3741 session->achannel_positions[5] = 270;
3744 session->achannel_positions[0] = 180;
3745 session->achannel_positions[1] = 0;
3748 session->achannel_positions[1] = 90;
3751 if( !channels ) break;
3752 double t = 0, dt = 360./channels;
3753 for( int i=channels; --i>=0; t+=dt )
3754 session->achannel_positions[i] = int(t+0.5);
3757 remap_audio(MWindow::AUDIO_1_TO_1);
3759 if( delete_tracks ) {
3760 Track *track = edl->tracks->first;
3761 for( Track *next_track=0; track; track=next_track ) {
3762 next_track = track->next;
3763 if( track->data_type != TRACK_AUDIO ) continue;
3764 Edit *edit = track->edits->first;
3765 for( Edit *next_edit=0; edit; edit=next_edit ) {
3766 next_edit = edit->next;
3767 if( !((1<<edit->channel) & channel_mask) ||
3768 !edit->asset || !edit->asset->is_asset ||
3769 !asset->equivalent(*edit->asset,1,1,edl) )
3772 if( !track->edits->first )
3773 edl->tracks->delete_track(track);
3777 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3780 session->auto_keyframes = old_auto_keyframes;
3781 if( !result && delete_tracks > 0 ) {
3783 undo->update_undo_after(_("select asset"), LOAD_ALL);
3789 int MWindow::select_asset(int vtrack, int delete_tracks)
3791 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3793 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3794 if( !track ) return 1;
3795 Edit *edit = track->edits->first;
3796 if( !edit ) return 1;
3797 Asset *asset = edit->asset;
3798 if( !asset || !asset->is_asset ) return 1;
3799 return select_asset(asset, edit->channel, 0, delete_tracks);
3802 void MWindow::dump_plugindb(FILE *fp)
3804 if( !plugindb ) return;
3805 for(int i = 0; i < plugindb->total; i++)
3806 plugindb->get(i)->dump(fp);
3809 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
3812 double unit_position = edl->local_session->get_selectionstart(1);
3813 unit_position = patch->track->to_units(unit_position, 0);
3815 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
3816 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3819 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
3822 double unit_position = edl->local_session->get_selectionstart(1);
3823 unit_position = patch->track->to_units(unit_position, 0);
3825 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
3826 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3829 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
3832 double unit_position = edl->local_session->get_selectionstart(1);
3833 unit_position = patch->track->to_units(unit_position, 0);
3835 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
3836 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);