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"
93 #include "recordmonitor.h"
94 #include "recordlabel.h"
95 #include "removefile.h"
97 #include "resourcethread.h"
98 #include "samplescroll.h"
100 #include "sighandler.h"
101 #include "splashgui.h"
102 #include "statusbar.h"
104 #include "threadloader.h"
106 #include "tipwindow.h"
107 #include "trackcanvas.h"
109 #include "tracking.h"
110 #include "trackscroll.h"
112 #include "transition.h"
113 #include "transportque.h"
116 #include "versioninfo.h"
117 #include "videodevice.inc"
118 #include "videowindow.h"
119 #include "vplayback.h"
120 #include "vwindowgui.h"
122 #include "wavecache.h"
125 #include "exportedl.h"
127 #include "defaultformats.h"
128 #include "ntsczones.h"
135 #include <sys/types.h>
136 #include <sys/stat.h>
137 #include <sys/time.h>
138 #include <sys/mman.h>
149 // Hack for libdv to remove glib dependancy
152 // g_log (const char *log_domain,
154 // const char *format,
160 // g_logv (const char *log_domain,
162 // const char *format,
172 ArrayList<PluginServer*>* MWindow::plugindb = 0;
173 Commercials* MWindow::commercials = 0;
179 run_lock = new Mutex("MWindow::run_lock");
180 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
181 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
182 vwindows_lock = new Mutex("MWindow::vwindows_lock");
183 brender_lock = new Mutex("MWindow::brender_lock");
184 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
192 commercial_active = 0;
204 strcpy(cin_lang,"en");
205 channeldb_buz = new ChannelDB;
206 channeldb_v4l2jpeg = new ChannelDB;
210 keyframe_threads = 0;
230 // Need to delete brender temporary here.
233 run_lock->lock("MWindow::~MWindow");
236 //printf("MWindow::~MWindow %d\n", __LINE__);
238 gui->remote_control->deactivate();
241 gui->channel_info->stop();
243 delete create_bd; create_bd = 0;
244 delete create_dvd; create_dvd = 0;
245 delete batch_render; batch_render = 0;
246 delete render; render = 0;
248 if( commercials && !commercials->remove_user() ) commercials = 0;
250 // Save defaults for open plugins
251 plugin_gui_lock->lock("MWindow::~MWindow");
252 for(int i = 0; i < plugin_guis->size(); i++) {
253 plugin_guis->get(i)->hide_gui();
254 delete_plugin(plugin_guis->get(i));
256 plugin_gui_lock->unlock();
257 hide_keyframe_guis();
260 // Give up and go to a movie
261 // cant run valgrind if this is used
263 gui->del_keyboard_listener(
264 (int (BC_WindowBase::*)(BC_WindowBase *))
265 &MWindowGUI::keyboard_listener);
267 // release the hounds
268 if( awindow && awindow->gui ) awindow->gui->close(0);
269 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
270 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
271 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
272 if( twindow && twindow->is_running() ) twindow->close_window();
273 if( wwindow && wwindow->is_running() ) wwindow->close_window();
274 vwindows.remove_all_objects();
276 if( awindow ) awindow->join();
277 if( cwindow ) cwindow->join();
278 if( lwindow ) lwindow->join();
279 if( twindow ) twindow->join();
280 if( wwindow ) wwindow->join();
281 if( gwindow ) gwindow->join();
284 // one at a time, or nouveau chokes
285 #define close_gui(win) if( win ) { \
286 if( win->gui ) win->gui->close(0); \
294 vwindows.remove_all_objects();
299 dead_plugins->remove_all_objects();
302 keyframe_threads->remove_all_objects();
303 colormodels.remove_all_objects();
304 delete awindow; awindow = 0;
305 delete lwindow; lwindow = 0;
306 delete twindow; twindow = 0;
307 delete wwindow; wwindow = 0;
308 delete gwindow; gwindow = 0;
309 delete cwindow; cwindow = 0;
311 //delete file_server; file_server = 0; // reusable
312 delete mainindexes; mainindexes = 0;
313 delete mainprogress; mainprogress = 0;
314 delete audio_cache; audio_cache = 0; // delete the cache after the assets
315 delete video_cache; video_cache = 0; // delete the cache after the assets
316 delete frame_cache; frame_cache = 0;
317 delete wave_cache; wave_cache = 0;
318 delete plugin_guis; plugin_guis = 0;
319 delete dead_plugins; dead_plugins = 0;
320 delete keyframe_threads; keyframe_threads = 0;
321 delete undo; undo = 0;
322 delete preferences; preferences = 0;
323 delete exportedl; exportedl = 0;
324 delete session; session = 0;
325 delete defaults; defaults = 0;
326 delete assets; assets = 0;
327 delete splash_window; splash_window = 0;
328 // delete theme; theme = 0; // deleted by delete_plugins
329 if( !edl->Garbage::remove_user() ) edl = 0;
330 delete channeldb_buz;
331 delete channeldb_v4l2jpeg;
332 // This must be last thread to exit
333 delete playback_3d; playback_3d = 0;
334 delete dead_plugin_lock;
335 delete plugin_gui_lock;
336 delete vwindows_lock;
338 delete keyframe_gui_lock;
339 colormodels.remove_all_objects();
340 interlace_project_modes.remove_all_objects();
341 interlace_asset_modes.remove_all_objects();
342 interlace_asset_fixmethods.remove_all_objects();
343 sighandler->terminate();
354 void MWindow::init_error()
356 MainError::init_error(this);
359 void MWindow::finit_error()
361 MainError::finit_error();
364 void MWindow::create_defaults_path(char *string, const char *config_file)
366 // set the .bcast path
369 sprintf(string, "%s/", File::get_config_path());
370 fs.complete_path(string);
371 if(!fs.is_dir(string))
372 fs.create_dir(string);
375 strcat(string, config_file);
377 const char *MWindow::default_std()
379 char buf[BCTEXTLEN], *p = 0;
381 int fd = open(TIMEZONE_NAME, O_RDONLY);
383 int l = read(fd, buf, sizeof(buf)-1);
386 if( buf[l-1] == '\n' ) --l;
392 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
395 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
396 p += strlen(ZONEINFO_STR);
401 for( int i=0; ntsc_zones[i]; ++i ) {
402 if( !strcmp(ntsc_zones[i], p) )
409 for( int i=0; ntsc_zones[i]; ++i ) {
410 if( !strcmp(ntsc_zones[i], p) )
415 //__timezone: Seconds west of UTC. 240sec/deg
416 double tz_deg = -__timezone / 240.;
417 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
418 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
421 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
423 struct formatpresets *fpr;
425 for(fpr = &format_presets[0]; fpr->name; fpr++)
427 if(strcmp(_(fpr->name), preset) == 0)
429 session->audio_channels = fpr->audio_channels;
430 session->audio_tracks = fpr->audio_tracks;
431 session->sample_rate = fpr->sample_rate;
432 session->video_channels = fpr->video_channels;
433 session->video_tracks = fpr->video_tracks;
434 session->frame_rate = fpr->frame_rate;
435 session->output_w = fpr->output_w;
436 session->output_h = fpr->output_h;
437 session->aspect_w = fpr->aspect_w;
438 session->aspect_h = fpr->aspect_h;
439 session->interlace_mode = fpr->interlace_mode;
440 session->color_model = fpr->color_model;
446 const char *MWindow::get_preset_name(int index)
448 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
450 return _(format_presets[index].name);
454 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
456 char path[BCTEXTLEN];
457 // Use user supplied path
459 strcpy(path, config_path);
461 create_defaults_path(path, CONFIG_FILE);
463 defaults = new BC_Hash(path);
468 void MWindow::check_language()
470 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
471 const char *env_lang = getenv("LANGUAGE");
472 if( !env_lang ) env_lang = getenv("LC_ALL");
473 if( !env_lang ) env_lang = getenv("LANG");
475 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
476 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
477 env_lang = curr_lang;
479 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
480 defaults->get("LAST_LANG",last_lang);
481 if( strcmp(env_lang,last_lang)) {
482 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
483 defaults->update("LAST_LANG",env_lang);
484 char plugin_path[BCTEXTLEN];
485 create_defaults_path(plugin_path, PLUGIN_FILE);
486 ::remove(plugin_path);
487 char ladspa_path[BCTEXTLEN];
488 create_defaults_path(ladspa_path, LADSPA_FILE);
489 ::remove(ladspa_path);
492 if( strlen(env_lang) > 1 &&
493 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
494 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
497 strcpy(cin_lang, "en");
500 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
502 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
504 const char *dp = plug_dir;
505 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
506 bp = !*dp && *bp == '/' ? bp+1 : base_path;
512 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
515 FILE *fp = fopen(index_path, "r");
519 char index_line[BCTEXTLEN];
520 int index_version = -1, len = strlen(plugin_dir);
521 if( !fgets(index_line, BCTEXTLEN, fp) ||
522 sscanf(index_line, "%d", &index_version) != 1 ||
523 index_version != PLUGIN_FILE_VERSION ||
524 !fgets(index_line, BCTEXTLEN, fp) ||
525 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
526 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
528 ArrayList<PluginServer*> plugins;
529 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
530 if( index_line[0] == ';' ) continue;
531 if( index_line[0] == '#' ) continue;
532 int type = PLUGIN_TYPE_UNKNOWN;
533 char path[BCTEXTLEN], title[BCTEXTLEN];
535 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
538 PluginServer *server = 0;
540 case PLUGIN_TYPE_BUILTIN:
541 case PLUGIN_TYPE_EXECUTABLE:
542 case PLUGIN_TYPE_LADSPA: {
543 char plugin_path[BCTEXTLEN]; struct stat st;
544 sprintf(plugin_path, "%s/%s", plugin_dir, path);
545 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
548 server = new PluginServer(mwindow, plugin_path, type);
550 case PLUGIN_TYPE_FFMPEG: {
551 server = new_ffmpeg_server(mwindow, path);
554 if( !server ) continue;
555 plugins.append(server);
556 // Create plugin server from index entry
557 server->set_title(title);
558 if( server->read_table(index_line) ) {
565 ret = check_plugin_index(plugins, plugin_dir, ".");
568 add_plugins(plugins);
570 plugins.remove_all_objects();
575 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
576 const char *plug_dir, const char *plug_path)
578 char plugin_path[BCTEXTLEN];
579 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
581 fs.set_filter( "[*.plugin][*.so]" );
582 if( fs.update(plugin_path) )
585 for( int i=0; i<fs.dir_list.total; ++i ) {
586 char fs_path[BCTEXTLEN];
587 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
588 if( fs.is_dir(fs_path) ) {
589 get_plugin_path(plugin_path, plug_dir, fs_path);
590 if( check_plugin_index(plugins, plug_dir, plugin_path) )
593 else if( !plugin_exists(fs_path, plugins) )
600 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
603 plugindb = new ArrayList<PluginServer*>;
605 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
606 create_defaults_path(index_path, PLUGIN_FILE);
607 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
608 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
609 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
610 printf("init plugin index: %s\n", plugin_path);
611 FILE *fp = fopen(index_path,"w");
613 fprintf(stderr,_("MWindow::init_plugins: "
614 "can't create plugin index: %s\n"), index_path);
617 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
618 fprintf(fp, "%s\n", plugin_path);
619 init_plugin_index(mwindow, preferences, fp, plugin_path);
620 init_ffmpeg_index(mwindow, preferences, fp);
622 return load_plugin_index(mwindow, index_path, plugin_path);
625 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
627 char *path = getenv("LADSPA_PATH");
628 char ladspa_path[BCTEXTLEN];
630 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
633 for( int len=0; *path; path+=len ) {
634 char *cp = strchr(path,':');
635 len = !cp ? strlen(path) : cp-path;
636 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
637 memcpy(plugin_path, path, len); plugin_path[len] = 0;
639 char *plugin_dir = FileSystem::basepath(plugin_path);
640 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
641 create_defaults_path(index_path, LADSPA_FILE);
642 cp = index_path + strlen(index_path);
643 for( char *bp=plugin_path; *bp!=0; ++bp )
644 *cp++ = *bp=='/' ? '_' : *bp;
646 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
647 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
648 load_plugin_index(mwindow, index_path, plugin_path);
653 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
654 FILE *fp, const char *plugin_dir)
656 int idx = PLUGIN_IDS;
658 for( int i=0; i<plugindb->size(); ++i ) {
659 PluginServer *server = plugindb->get(i);
660 if( server->dir_idx >= idx )
661 idx = server->dir_idx+1;
664 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
667 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
668 const char *index_path, const char *plugin_dir)
670 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
671 strcpy(plugin_path, path); delete [] path;
672 printf("init ladspa index: %s\n", plugin_dir);
673 FILE *fp = fopen(index_path,"w");
675 fprintf(stderr,_("MWindow::init_ladspa_index: "
676 "can't create plugin index: %s\n"), index_path);
679 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
680 fprintf(fp, "%s\n", plugin_dir);
681 init_plugin_index(mwindow, preferences, fp, plugin_path);
686 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
687 const char *plug_dir, const char *plug_path, int &idx)
689 char plugin_path[BCTEXTLEN];
690 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
692 fs.set_filter( "[*.plugin][*.so]" );
693 int result = fs.update(plugin_path);
694 if( result || !fs.dir_list.total ) return;
697 for( int i=0; i<fs.dir_list.total; ++i ) {
698 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
699 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
700 get_plugin_path(path, plug_dir, fs_path);
701 if( fs.is_dir(fs_path) ) {
702 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
705 if( plugin_exists(path) ) continue;
707 if( stat(fs_path, &st) ) continue;
708 int64_t mtime = st.st_mtime;
709 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
710 result = server.open_plugin(1, preferences, 0, 0);
712 server.write_table(fp, path, vis_id, mtime);
713 server.close_plugin();
715 else if( result == PLUGINSERVER_IS_LAD ) {
718 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
719 ladspa.set_lad_index(lad_index++);
720 result = ladspa.open_plugin(1, preferences, 0, 0);
722 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
723 ladspa.close_plugin();
729 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
731 for( int i=0; i<plugins.size(); ++i )
732 plugindb->append(plugins[i]);
733 plugins.remove_all();
736 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins)
738 const char *cfg_path = File::get_cindat_path();
739 char msg_path[BCTEXTLEN]; int txt = 0;
741 if( BC_Resources::language[0] ) {
742 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
743 cfg_path, BC_Resources::language);
744 fp = fopen(msg_path, "r");
748 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
750 fp = fopen(msg_path, "r");
753 char text[BCTEXTLEN];
754 char *tp = text, *ep = tp + sizeof(text)-1;
755 char title[BCTEXTLEN];
760 char line[BCTEXTLEN], *cp = line;
761 if( fgets(line,sizeof(line)-1,fp) ) {
762 if( *cp == '#' ) continue;
763 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
766 if( tp > text && *--tp == '\n' ) *tp = 0;
768 tp = !txt ? title : _(title);
769 int idx = plugins.size();
770 while( --idx>=0 && strcmp(plugins[idx]->title, tp) );
772 delete [] plugins[idx]->tip;
773 plugins[idx]->tip = cstrdup(text);
777 if( done > 0 ) break;
779 char *dp = strchr(cp, ':');
781 printf("plugin tips: error on line %d\n", no);
785 while( cp < dp ) *bp++ = *cp++;
790 while( *cp == ' ' || *cp == '\t' ) ++cp;
791 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
796 void MWindow::delete_plugins()
798 plugindb->remove_all_objects();
803 void MWindow::search_plugindb(int do_audio,
808 ArrayList<PluginServer*> &results)
811 for(int i = 0; i < MWindow::plugindb->total; i++)
813 PluginServer *current = MWindow::plugindb->get(i);
815 if(current->audio == do_audio &&
816 current->video == do_video &&
817 (current->realtime == is_realtime || is_realtime < 0) &&
818 current->transition == is_transition &&
819 current->theme == is_theme)
820 results.append(current);
823 // Alphabetize list by title
829 for(int i = 0; i < results.total - 1; i++)
831 PluginServer *value1 = results[i];
832 PluginServer *value2 = results[i + 1];
833 if(strcmp(_(value1->title), _(value2->title)) > 0)
837 results[i + 1] = value1;
843 PluginServer* MWindow::scan_plugindb(char *title,
848 // printf("MWindow::scan_plugindb data_type < 0\n");
852 for(int i = 0; i < plugindb->total; i++)
854 PluginServer *server = plugindb->get(i);
856 !strcasecmp(server->title, title) &&
858 (data_type == TRACK_AUDIO && server->audio) ||
859 (data_type == TRACK_VIDEO && server->video)))
860 return plugindb->get(i);
865 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
867 for( int i=0; i<plugins.size(); ++i )
868 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
872 int MWindow::plugin_exists(char *plugin_path)
874 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
877 void MWindow::init_preferences()
879 preferences = new Preferences;
880 preferences->load_defaults(defaults);
881 session = new MainSession(this);
882 session->load_defaults(defaults);
883 // set x11_host, screens, window_config
884 screens = session->set_default_x11_host();
885 BC_Signals::set_trap_hook(trap_hook, this);
886 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
887 BC_Signals::set_catch_intr(preferences->trap_sigintr);
888 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
889 BC_Trace::enable_locks();
892 BC_Trace::disable_locks();
894 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
895 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
898 void MWindow::clean_indexes()
903 int oldest_item = -1;
905 char string[BCTEXTLEN];
906 char string2[BCTEXTLEN];
908 // Delete extra indexes
909 fs.set_filter("*.idx");
910 fs.complete_path(preferences->index_directory);
911 fs.update(preferences->index_directory);
912 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
914 // Eliminate directories
919 for(int i = 0; i < fs.dir_list.total && !result; i++)
921 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
922 if(fs.is_dir(string))
924 delete fs.dir_list[i];
925 fs.dir_list.remove_number(i);
930 total_excess = fs.dir_list.total - preferences->index_count;
932 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
933 while(total_excess > 0)
936 for(int i = 0; i < fs.dir_list.total; i++)
938 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
940 if(i == 0 || fs.get_date(string) <= oldest)
942 oldest = fs.get_date(string);
950 fs.join_names(string,
951 preferences->index_directory,
952 fs.dir_list[oldest_item]->name);
953 //printf("MWindow::clean_indexes 1 %s\n", string);
955 perror("delete_indexes");
956 delete fs.dir_list[oldest_item];
957 fs.dir_list.remove_number(oldest_item);
959 // Remove table of contents if it exists
960 strcpy(string2, string);
961 char *ptr = strrchr(string2, '.');
964 //printf("MWindow::clean_indexes 2 %s\n", string2);
965 sprintf(ptr, ".toc");
967 sprintf(ptr, ".mkr");
976 void MWindow::init_awindow()
978 awindow = new AWindow(this);
979 awindow->create_objects();
982 void MWindow::init_gwindow()
984 gwindow = new GWindow(this);
985 gwindow->create_objects();
988 void MWindow::init_tipwindow()
990 TipWindow::load_tips(cin_lang);
992 twindow = new TipWindow(this);
996 void MWindow::show_warning(int *do_warning, const char *text)
998 if( do_warning && !*do_warning ) return;
1000 wwindow = new WWindow(this);
1001 wwindow->show_warning(do_warning, text);
1004 int MWindow::wait_warning()
1006 return wwindow->wait_result();
1009 void MWindow::init_theme()
1014 PluginServer *theme_plugin = 0;
1015 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1016 if( plugindb->get(i)->theme &&
1017 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1018 theme_plugin = plugindb->get(i);
1022 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1023 preferences->theme);
1025 const char *default_theme = _(DEFAULT_THEME);
1026 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1027 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1029 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1030 if( plugindb->get(i)->theme &&
1031 !strcasecmp(default_theme, plugindb->get(i)->title) )
1032 theme_plugin = plugindb->get(i);
1037 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1041 PluginServer *plugin = new PluginServer(*theme_plugin);
1042 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1043 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1044 theme_plugin->title);
1048 theme = plugin->new_theme();
1049 theme->mwindow = this;
1050 strcpy(theme->path, plugin->path);
1053 // Load default images & settings
1054 theme->Theme::initialize();
1055 // Load user images & settings
1056 theme->initialize();
1057 // Create menus with user colors
1058 theme->build_menus();
1061 theme->check_used();
1063 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1066 void MWindow::init_3d()
1068 playback_3d = new Playback3D(this);
1069 playback_3d->create_objects();
1072 void MWindow::init_edl()
1075 edl->create_objects();
1076 fill_preset_defaults(default_standard, edl->session);
1077 edl->load_defaults(defaults);
1078 edl->session->brender_start = edl->session->brender_end = 0;
1079 edl->create_default_tracks();
1080 edl->tracks->update_y_pixels(theme);
1083 void MWindow::init_compositor()
1085 cwindow = new CWindow(this);
1086 cwindow->create_objects();
1089 void MWindow::init_levelwindow()
1091 lwindow = new LevelWindow(this);
1092 lwindow->create_objects();
1095 VWindow *MWindow::get_viewer(int start_it, int idx)
1097 vwindows_lock->lock("MWindow::get_viewer");
1098 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1099 if( !vwindow ) idx = vwindows.size();
1100 while( !vwindow && --idx >= 0 ) {
1101 VWindow *vwin = vwindows[idx];
1102 if( !vwin->is_running() || !vwin->get_edl() )
1106 vwindow = new VWindow(this);
1107 vwindow->load_defaults();
1108 vwindow->create_objects();
1109 vwindows.append(vwindow);
1111 vwindows_lock->unlock();
1112 if( start_it ) vwindow->start();
1116 void MWindow::init_cache()
1118 audio_cache = new CICache(preferences);
1119 video_cache = new CICache(preferences);
1120 frame_cache = new FrameCache;
1121 wave_cache = new WaveCache;
1124 void MWindow::init_channeldb()
1126 channeldb_buz->load("channeldb_buz");
1127 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1130 void MWindow::init_menus()
1132 char string[BCTEXTLEN];
1135 BC_CModels::to_text(string, BC_RGB888);
1136 colormodels.append(new ColormodelItem(string, BC_RGB888));
1137 BC_CModels::to_text(string, BC_RGBA8888);
1138 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1139 // BC_CModels::to_text(string, BC_RGB161616);
1140 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1141 // BC_CModels::to_text(string, BC_RGBA16161616);
1142 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1143 BC_CModels::to_text(string, BC_RGB_FLOAT);
1144 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1145 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1146 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1147 BC_CModels::to_text(string, BC_YUV888);
1148 colormodels.append(new ColormodelItem(string, BC_YUV888));
1149 BC_CModels::to_text(string, BC_YUVA8888);
1150 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1151 // BC_CModels::to_text(string, BC_YUV161616);
1152 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1153 // BC_CModels::to_text(string, BC_YUVA16161616);
1154 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1156 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1157 interlace_project_modes.append(new InterlacemodeItem(string, x));
1159 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1160 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1162 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1163 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1165 // Interlacing Modes
1166 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1168 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1169 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1171 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1172 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1174 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1175 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1177 // Interlacing Fixing Methods
1178 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1179 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1180 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1183 void MWindow::init_indexes()
1185 mainindexes = new MainIndexes(this);
1186 mainindexes->start_loop();
1189 void MWindow::init_gui()
1191 gui = new MWindowGUI(this);
1192 gui->lock_window("MWindow::init_gui");
1193 gui->create_objects();
1194 gui->unlock_window();
1195 gui->load_defaults(defaults);
1198 void MWindow::init_signals()
1200 sighandler = new SigHandler;
1201 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1205 void MWindow::init_render()
1207 render = new Render(this);
1208 create_bd = new CreateBD_Thread(this);
1209 create_dvd = new CreateDVD_Thread(this);
1210 batch_render = new BatchRenderThread(this);
1213 void MWindow::init_exportedl()
1215 exportedl = new ExportEDL(this);
1218 void MWindow::init_brender()
1220 if(preferences->use_brender && !brender)
1222 brender_lock->lock("MWindow::init_brender 1");
1223 brender = new BRender(this);
1224 brender->initialize();
1225 session->brender_end = 0;
1226 brender_lock->unlock();
1229 if(!preferences->use_brender && brender)
1231 brender_lock->lock("MWindow::init_brender 2");
1234 session->brender_end = 0;
1235 brender_lock->unlock();
1241 void MWindow::restart_brender()
1243 //printf("MWindow::restart_brender 1\n");
1244 if( !brender_active || !preferences->use_brender ) return;
1245 if( !brender ) return;
1246 int locked = gui->get_window_lock();
1247 if( locked ) gui->unlock_window();
1248 brender->restart(edl);
1249 if( locked ) gui->lock_window("MWindow::restart_brender");
1252 void MWindow::stop_brender()
1254 if( !brender ) return;
1255 int locked = gui->get_window_lock();
1256 if( locked ) gui->unlock_window();
1258 if( locked ) gui->lock_window("MWindow::stop_brender");
1261 int MWindow::brender_available(int position)
1264 brender_lock->lock("MWindow::brender_available 1");
1265 if(brender && brender_active)
1267 if(brender->map_valid)
1269 brender->map_lock->lock("MWindow::brender_available 2");
1270 if(position < brender->map_size &&
1273 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1274 if(brender->map[position] == BRender::RENDERED)
1277 brender->map_lock->unlock();
1280 brender_lock->unlock();
1284 void MWindow::set_brender_active(int v, int update)
1286 if( !preferences->use_brender ) v = 0;
1288 gui->mainmenu->brender_active->set_checked(v);
1290 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1291 edl->session->brender_end = edl->local_session->get_selectionend(1);
1293 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1294 edl->session->brender_end = edl->tracks->total_video_length();
1299 edl->session->brender_start = edl->session->brender_end = 0;
1303 gui->update_timebar(0);
1304 gui->draw_overlays(1);
1308 int MWindow::has_commercials()
1310 return theme->use_commercials;
1313 void MWindow::init_commercials()
1315 if( !commercials ) {
1316 commercials = new Commercials(this);
1317 commercial_active = 0;
1320 commercials->add_user();
1323 void MWindow::commit_commercial()
1325 if( !commercial_active ) return;
1326 commercial_active = 0;
1327 if( !commercials ) return;
1328 commercials->commitDb();
1331 void MWindow::undo_commercial()
1333 if( !commercial_active ) return;
1334 commercial_active = 0;
1335 if( !commercials ) return;
1336 commercials->undoDb();
1339 int MWindow::put_commercial()
1341 double start = edl->local_session->get_selectionstart();
1342 double end = edl->local_session->get_selectionend();
1343 if( start >= end ) return 0;
1345 const char *errmsg = 0;
1347 Tracks *tracks = edl->tracks;
1350 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1351 if( track->data_type != TRACK_VIDEO ) continue;
1352 if( !track->record ) continue;
1353 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1355 int64_t units_start = track->to_units(start,0);
1356 int64_t units_end = track->to_units(end,0);
1357 Edits *edits = track->edits;
1358 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1359 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1360 if(!edit1 && !edit2) continue; // nothing selected
1361 if(!edit2) { // edit2 beyond end of track
1362 edit2 = edits->last;
1363 units_end = edits->length();
1365 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1366 Indexable *indexable = edit1->get_source();
1367 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1370 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1371 if( track->data_type != TRACK_VIDEO ) continue;
1372 if( !track->record ) continue;
1373 int64_t units_start = track->to_units(start,0);
1374 int64_t units_end = track->to_units(end,0);
1375 Edits *edits = track->edits;
1376 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1377 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1378 if(!edit1 && !edit2) continue; // nothing selected
1379 if(!edit2) { // edit2 beyond end of track
1380 edit2 = edits->last;
1381 units_end = edits->length();
1383 Indexable *indexable = edit1->get_source();
1384 Asset *asset = (Asset *)indexable;
1385 File *file = video_cache->check_out(asset, edl);
1386 if( !file ) { errmsg = _("no file"); break; }
1387 int64_t edit_length = units_end - units_start;
1388 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1389 result = commercials->put_clip(file, edit1->channel,
1390 track->from_units(edit_start), track->from_units(edit_length));
1391 video_cache->check_in(asset);
1392 if( result ) { errmsg = _("db failed"); break; }
1395 char string[BCTEXTLEN];
1396 sprintf(string, _("put_commercial: %s"), errmsg);
1397 MainError::show_error(string);
1404 void MWindow::stop_playback(int wait)
1406 int locked = gui->get_window_lock();
1407 if( locked ) gui->unlock_window();
1409 cwindow->playback_engine->stop_playback();
1411 for(int i = 0; i < vwindows.size(); i++) {
1412 VWindow *vwindow = vwindows[i];
1413 if( !vwindow->is_running() ) continue;
1414 vwindow->playback_engine->stop_playback();
1416 if( locked ) gui->lock_window("MWindow::stop_playback");
1419 int MWindow::load_filenames(ArrayList<char*> *filenames,
1421 int update_filename)
1423 ArrayList<EDL*> new_edls;
1424 ArrayList<Asset*> new_assets;
1425 ArrayList<File*> new_files;
1426 const int debug = 0;
1427 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1430 gui->start_hourglass();
1432 // Need to stop playback since tracking depends on the EDL not getting
1436 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1437 undo->update_undo_before();
1440 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1442 // Define new_edls and new_assets to load
1443 int result = 0, ftype = -1;
1444 for(int i = 0; i < filenames->size(); i++)
1447 File *new_file = new File;
1448 Asset *new_asset = new Asset(filenames->get(i));
1449 EDL *new_edl = new EDL;
1450 char string[BCTEXTLEN];
1452 new_edl->create_objects();
1453 new_edl->copy_session(edl);
1454 new_file->set_program(edl->session->program_no);
1456 sprintf(string, _("Loading %s"), new_asset->path);
1457 gui->show_message(string);
1458 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1460 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1461 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1466 // Convert media file to EDL
1468 // Warn about odd image dimensions
1469 if(new_asset->video_data &&
1470 ((new_asset->width % 2) ||
1471 (new_asset->height % 2)))
1473 char string[BCTEXTLEN];
1474 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1478 MainError::show_error(string);
1481 if(new_asset->program >= 0 &&
1482 edl->session->program_no != new_asset->program)
1484 char string[BCTEXTLEN];
1485 sprintf(string, _("%s's index was built for program number %d\n"
1486 "Playback preference is %d.\n Using program %d."),
1487 new_asset->path, new_asset->program,
1488 edl->session->program_no, new_asset->program);
1489 MainError::show_error(string);
1493 if(load_mode != LOADMODE_RESOURCESONLY)
1496 RecordLabels *labels = edl->session->label_cells ?
1497 new RecordLabels(new_file) : 0;
1499 asset_to_edl(new_edl, new_asset, labels);
1501 new_edls.append(new_edl);
1503 new_asset->Garbage::remove_user();
1509 new_assets.append(new_asset);
1513 // Set filename to nothing for assets since save EDL would overwrite them.
1514 if(load_mode == LOADMODE_REPLACE ||
1515 load_mode == LOADMODE_REPLACE_CONCATENATE)
1518 // Reset timeline position
1519 for(int i = 0; i < TOTAL_PANES; i++)
1521 new_edl->local_session->view_start[i] = 0;
1522 new_edl->local_session->track_start[i] = 0;
1530 case FILE_NOT_FOUND:
1531 sprintf(string, _("Failed to open %s"), new_asset->path);
1532 gui->show_message(string, theme->message_error);
1533 gui->update_default_message();
1537 case FILE_UNRECOGNIZED_CODEC:
1540 { IndexFile indexfile(this, new_asset);
1541 if( !(result = indexfile.open_index()) )
1542 indexfile.close_index();
1545 // Test existing EDLs
1546 for(int j = 0; result && j <= new_edls.total; j++) {
1547 Asset *old_asset = j < new_edls.total ?
1548 new_edls[j]->assets->get_asset(new_asset->path) :
1549 edl->assets->get_asset(new_asset->path);
1551 new_asset->copy_from(old_asset,1);
1559 char string[BCTEXTLEN];
1561 fs.extract_name(string, new_asset->path);
1563 strcat(string, _("'s format couldn't be determined."));
1564 new_asset->audio_data = 1;
1565 new_asset->format = FILE_PCM;
1566 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1567 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1568 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1569 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1570 new_asset->signed_ = defaults->get("SIGNED_", 1);
1571 new_asset->header = defaults->get("HEADER", 0);
1573 FileFormat fwindow(this);
1574 fwindow.create_objects(new_asset, string);
1575 result = fwindow.run_window();
1578 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1579 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1580 defaults->update("AUDIO_BITS", new_asset->bits);
1581 defaults->update("BYTE_ORDER", new_asset->byte_order);
1582 defaults->update("SIGNED_", new_asset->signed_);
1583 defaults->update("HEADER", new_asset->header);
1590 // Recalculate length
1592 new_file = new File;
1593 result = new_file->open_file(preferences, new_asset, 1, 0);
1595 if(load_mode != LOADMODE_RESOURCESONLY)
1597 RecordLabels *labels = edl->session->label_cells ?
1598 new RecordLabels(new_file) : 0;
1599 asset_to_edl(new_edl, new_asset, labels);
1600 new_edls.append(new_edl);
1601 new_asset->Garbage::remove_user();
1607 new_assets.append(new_asset);
1621 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1622 xml_file.read_from_file(filenames->get(i));
1623 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1624 const char *cin_version = 0;
1625 while( !xml_file.read_tag() ) {
1626 if( xml_file.tag.title_is("EDL") ) {
1627 cin_version = xml_file.tag.get_property("VERSION");
1632 if( !cin_version ) {
1633 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1634 char string[BCTEXTLEN];
1635 sprintf(string,_("Unknown %s"), filenames->get(i));
1636 gui->show_message(string);
1640 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1641 char string[BCTEXTLEN];
1642 snprintf(string, sizeof(string),
1643 _("Warning: XML from cinelerra version %s\n"
1644 "Session data may be incompatible."), cin_version);
1645 show_warning(&preferences->warn_version, string);
1647 if(load_mode == LOADMODE_NESTED)
1649 // Load temporary EDL for nesting.
1650 EDL *nested_edl = new EDL;
1651 nested_edl->create_objects();
1652 nested_edl->set_path(filenames->get(i));
1653 nested_edl->load_xml(&xml_file, LOAD_ALL);
1654 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1655 edl_to_nested(new_edl, nested_edl);
1656 nested_edl->Garbage::remove_user();
1660 // Load EDL for pasting
1661 new_edl->load_xml(&xml_file, LOAD_ALL);
1662 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1663 test_plugins(new_edl, filenames->get(i));
1664 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1666 if(load_mode == LOADMODE_REPLACE ||
1667 load_mode == LOADMODE_REPLACE_CONCATENATE)
1669 strcpy(session->filename, filenames->get(i));
1670 strcpy(new_edl->local_session->clip_title,
1673 set_filename(new_edl->local_session->clip_title);
1676 if( load_mode == LOADMODE_RESOURCESONLY ) {
1677 strcpy(new_edl->local_session->clip_title,
1680 time_t t = !stat(filenames->get(i),&st) ?
1681 st.st_mtime : time(&t);
1682 ctime_r(&t, new_edl->local_session->clip_notes);
1686 new_edls.append(new_edl);
1692 // edls are in new_edls
1693 if( result && new_edl ) new_edl->Garbage::remove_user();
1694 // assets are copied
1695 if( new_asset ) new_asset->Garbage::remove_user();
1697 // Store for testing index
1698 new_files.append(new_file);
1701 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1705 gui->reset_default_message();
1706 gui->default_message();
1710 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1713 // Don't back up here.
1716 // For pasting, clear the active region
1717 if(load_mode == LOADMODE_PASTE ||
1718 load_mode == LOADMODE_NESTED)
1720 double start = edl->local_session->get_selectionstart();
1721 double end = edl->local_session->get_selectionend();
1722 if(!EQUIV(start, end))
1725 edl->session->labels_follow_edits,
1726 edl->session->plugins_follow_edits,
1727 edl->session->autos_follow_edits);
1730 paste_edls(&new_edls, load_mode, 0, -1,
1731 edl->session->labels_follow_edits,
1732 edl->session->plugins_follow_edits,
1733 edl->session->autos_follow_edits,
1740 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1742 // Add new assets to EDL and schedule assets for index building.
1743 int got_indexes = 0;
1744 for(int i = 0; i < new_edls.size(); i++)
1746 EDL *new_edl = new_edls[i];
1747 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1749 mainindexes->add_next_asset(0,
1750 new_edl->nested_edls->get(j));
1752 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1757 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1758 for(int i = 0; i < new_assets.size(); i++)
1760 Asset *new_asset = new_assets[i];
1764 for(int j = 0; j < new_files.size(); j++)
1766 new_file = new_files[j];
1767 if(!strcmp(new_file->asset->path,
1775 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1777 edl->assets->update(new_asset);
1779 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1781 // Start examining next batch of index files
1782 if(got_indexes) mainindexes->start_build();
1783 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1786 Track *track = edl->tracks->first;
1789 for(int j = 0; j < track->plugin_set.size(); j++)
1791 PluginSet *plugins = track->plugin_set[j];
1792 Plugin *plugin = plugins->get_first_plugin();
1796 if(load_mode == LOADMODE_REPLACE ||
1797 load_mode == LOADMODE_REPLACE_CONCATENATE)
1799 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1802 show_plugin(plugin);
1810 plugin = (Plugin*)plugin->next;
1814 track = track->next;
1817 // if just opening one new resource in replace mode
1818 if( ftype != FILE_IS_XML &&
1819 ( load_mode == LOADMODE_REPLACE ||
1820 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1822 edl->local_session->preview_start = 0;
1823 edl->local_session->preview_end = edl->tracks->total_playable_length();
1824 edl->local_session->loop_playback = 0;
1825 edl->local_session->set_selectionstart(0);
1826 edl->local_session->set_selectionend(0);
1827 set_brender_active(0, 0);
1832 // need to update undo before project, since mwindow is unlocked & a new load
1833 // can begin here. Should really prevent loading until we're done.
1834 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1835 undo->update_undo_after(_("load"), LOAD_ALL);
1837 for(int i = 0; i < new_edls.size(); i++)
1839 new_edls[i]->remove_user();
1841 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1843 new_edls.remove_all();
1845 for(int i = 0; i < new_assets.size(); i++)
1847 new_assets[i]->Garbage::remove_user();
1850 new_assets.remove_all();
1851 new_files.remove_all_objects();
1854 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1855 if(load_mode == LOADMODE_REPLACE ||
1856 load_mode == LOADMODE_REPLACE_CONCATENATE)
1858 session->changes_made = 0;
1862 session->changes_made = 1;
1865 gui->stop_hourglass();
1868 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1869 update_project(load_mode);
1871 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1879 void MWindow::test_plugins(EDL *new_edl, char *path)
1881 char string[BCTEXTLEN];
1883 // Do a check weather plugins exist
1884 for(Track *track = new_edl->tracks->first; track; track = track->next)
1886 for(int k = 0; k < track->plugin_set.total; k++)
1888 PluginSet *plugin_set = track->plugin_set[k];
1889 for(Plugin *plugin = (Plugin*)plugin_set->first;
1891 plugin = (Plugin*)plugin->next)
1893 if(plugin->plugin_type == PLUGIN_STANDALONE)
1895 // ok we need to find it in plugindb
1896 int plugin_found = 0;
1898 for(int j = 0; j < plugindb->size(); j++)
1900 PluginServer *server = plugindb->get(j);
1902 !strcasecmp(server->title, plugin->title) &&
1903 ((track->data_type == TRACK_AUDIO && server->audio) ||
1904 (track->data_type == TRACK_VIDEO && server->video)) &&
1905 (!server->transition))
1912 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1913 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1914 "effect", plugin->title,
1916 MainError::show_error(string);
1922 for(Edit *edit = (Edit*)track->edits->first;
1924 edit = (Edit*)edit->next)
1926 if (edit->transition)
1928 // ok we need to find transition in plugindb
1930 int transition_found = 0;
1931 for(int j = 0; j < plugindb->size(); j++)
1933 PluginServer *server = plugindb->get(j);
1935 !strcasecmp(server->title, edit->transition->title) &&
1936 ((track->data_type == TRACK_AUDIO && server->audio) ||
1937 (track->data_type == TRACK_VIDEO && server->video)) &&
1938 (server->transition))
1939 transition_found = 1;
1942 if (!transition_found)
1945 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1946 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1947 "transition", edit->transition->title,
1949 MainError::show_error(string);
1957 void MWindow::init_shm()
1959 // Fix shared memory
1960 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1962 fprintf(fd, "0x7fffffff");
1967 fd = fopen("/proc/sys/kernel/shmmax", "r");
1969 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1974 fscanf(fd, "%jd", &result);
1977 if(result < 0x7fffffff) {
1978 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1979 "you probably need to be root, or:\n"
1980 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1981 "before trying to start cinelerra.\n"
1982 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1986 void MWindow::create_objects(int want_gui,
1991 const int debug = 0;
1992 if(debug) PRINT_TRACE
1994 // For some reason, init_signals must come after show_splash or the signals won't
1997 if(debug) PRINT_TRACE
2000 if(debug) PRINT_TRACE
2003 if(debug) PRINT_TRACE
2004 default_standard = default_std();
2005 init_defaults(defaults, config_path);
2009 splash_window->operation->update(_("Initializing Plugins"));
2010 init_plugins(this, preferences);
2011 if(debug) PRINT_TRACE
2012 init_ladspa_plugins(this, preferences);
2013 if(debug) PRINT_TRACE
2014 init_plugin_tips(*plugindb);
2016 splash_window->operation->update(_("Initializing GUI"));
2017 if(debug) PRINT_TRACE
2020 if(debug) PRINT_TRACE
2024 splash_window->operation->update(_("Initializing Fonts"));
2025 char string[BCTEXTLEN];
2026 strcpy(string, preferences->plugin_dir);
2027 strcat(string, "/" FONT_SEARCHPATH);
2028 BC_Resources::init_fontconfig(string);
2029 if(debug) PRINT_TRACE
2031 // Initialize before too much else is running
2032 // Preferences & theme are required for building MPEG table of contents
2034 // Default project created here
2036 if(debug) PRINT_TRACE
2039 if(debug) PRINT_TRACE
2044 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2047 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2049 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2050 if(session->show_vwindow)
2051 get_viewer(1, DEFAULT_VWINDOW);
2052 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2055 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2058 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2061 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2064 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2067 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2070 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2075 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2076 mainprogress = new MainProgress(this, gui);
2077 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2078 undo = new MainUndo(this);
2080 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2082 plugin_guis = new ArrayList<PluginServer*>;
2083 dead_plugins = new ArrayList<PluginServer*>;
2084 keyframe_threads = new ArrayList<KeyFrameThread*>;
2086 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2089 session->show_vwindow);
2091 // Show all vwindows
2092 // if(session->show_vwindow) {
2093 // for(int j = 0; j < vwindows.size(); j++) {
2094 // VWindow *vwindow = vwindows[j];
2095 // if( !vwindow->is_running() ) continue;
2096 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2099 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2100 // vwindow->gui->lock_window("MWindow::create_objects 1");
2101 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2102 // vwindow->gui->show_window();
2103 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2104 // vwindow->gui->unlock_window();
2109 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2111 if(session->show_cwindow)
2113 cwindow->gui->lock_window("MWindow::create_objects 1");
2114 cwindow->gui->show_window();
2115 cwindow->gui->unlock_window();
2118 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2119 if(session->show_awindow)
2121 awindow->gui->lock_window("MWindow::create_objects 1");
2122 awindow->gui->show_window();
2123 awindow->gui->unlock_window();
2126 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2127 if(session->show_lwindow)
2129 lwindow->gui->lock_window("MWindow::create_objects 1");
2130 lwindow->gui->show_window();
2131 lwindow->gui->unlock_window();
2134 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2136 (int)timer.get_difference(),
2138 if(session->show_gwindow)
2140 gwindow->gui->lock_window("MWindow::create_objects 1");
2141 gwindow->gui->show_window();
2142 gwindow->gui->unlock_window();
2145 if(debug) PRINT_TRACE
2147 gui->lock_window("MWindow::create_objects 1");
2148 gui->mainmenu->load_defaults(defaults);
2149 gui->mainmenu->update_toggles(0);
2150 gui->update_patchbay();
2151 gui->draw_canvas(0, 0);
2152 gui->draw_cursor(1);
2154 gui->raise_window();
2155 gui->unlock_window();
2157 if(debug) PRINT_TRACE
2159 if(preferences->use_tipwindow)
2161 if(debug) PRINT_TRACE
2163 gui->add_keyboard_listener(
2164 (int (BC_WindowBase::*)(BC_WindowBase *))
2165 &MWindowGUI::keyboard_listener);
2169 if(debug) PRINT_TRACE
2171 BC_WindowBase::get_resources()->vframe_shm = 1;
2175 void MWindow::show_splash()
2177 #include "data/heroine_logo9_png.h"
2178 VFrame *frame = new VFramePng(heroine_logo9_png);
2179 BC_DisplayInfo dpyi;
2180 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2181 int rr = (rw < rh ? rw : rh) / 4;
2182 splash_window = new SplashGUI(frame, rr, rr);
2183 splash_window->create_objects();
2186 void MWindow::hide_splash()
2189 delete splash_window;
2194 void MWindow::start()
2198 // vwindows[DEFAULT_VWINDOW]->start();
2209 playback_3d->start();
2215 run_lock->lock("MWindow::run");
2219 brender_lock->lock("MWindow::run 1");
2220 delete brender; brender = 0;
2221 brender_lock->unlock();
2223 interrupt_indexes();
2229 void MWindow::show_vwindow()
2231 int total_running = 0;
2232 session->show_vwindow = 1;
2234 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2235 // Raise all windows which are visible
2236 for(int j = 0; j < vwindows.size(); j++) {
2237 VWindow *vwindow = vwindows[j];
2238 if( !vwindow->is_running() ) continue;
2239 vwindow->gui->lock_window("MWindow::show_vwindow");
2240 vwindow->gui->show_window(0);
2241 vwindow->gui->raise_window();
2242 vwindow->gui->flush();
2243 vwindow->gui->unlock_window();
2247 // If no windows visible
2250 get_viewer(1, DEFAULT_VWINDOW);
2253 gui->mainmenu->show_vwindow->set_checked(1);
2256 void MWindow::show_awindow()
2258 session->show_awindow = 1;
2259 awindow->gui->lock_window("MWindow::show_awindow");
2260 awindow->gui->show_window();
2261 awindow->gui->raise_window();
2262 awindow->gui->flush();
2263 awindow->gui->unlock_window();
2264 gui->mainmenu->show_awindow->set_checked(1);
2267 char *MWindow::get_cwindow_display()
2269 char *x11_host = screens < 2 || session->window_config == 0 ?
2270 session->a_x11_host : session->b_x11_host;
2271 return *x11_host ? x11_host : 0;
2274 void MWindow::show_cwindow()
2276 session->show_cwindow = 1;
2277 cwindow->show_window();
2278 gui->mainmenu->show_cwindow->set_checked(1);
2281 void MWindow::show_gwindow()
2283 session->show_gwindow = 1;
2285 gwindow->gui->lock_window("MWindow::show_gwindow");
2286 gwindow->gui->show_window();
2287 gwindow->gui->raise_window();
2288 gwindow->gui->flush();
2289 gwindow->gui->unlock_window();
2291 gui->mainmenu->show_gwindow->set_checked(1);
2293 void MWindow::hide_gwindow()
2295 session->show_gwindow = 0;
2297 gwindow->gui->lock_window("MWindow::show_gwindow");
2298 gwindow->gui->hide_window();
2299 gwindow->gui->unlock_window();
2302 void MWindow::show_lwindow()
2304 session->show_lwindow = 1;
2305 lwindow->gui->lock_window("MWindow::show_lwindow");
2306 lwindow->gui->show_window();
2307 lwindow->gui->raise_window();
2308 lwindow->gui->flush();
2309 lwindow->gui->unlock_window();
2310 gui->mainmenu->show_lwindow->set_checked(1);
2313 int MWindow::tile_windows(int window_config)
2315 int need_reload = 0;
2316 int play_config = window_config==0 ? 0 : 1;
2317 edl->session->playback_config->load_defaults(defaults, play_config);
2318 session->default_window_positions(window_config);
2319 if( screens == 1 ) {
2320 gui->default_positions();
2321 sync_parameters(CHANGE_ALL);
2328 void MWindow::toggle_loop_playback()
2330 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2331 set_loop_boundaries();
2334 gui->draw_overlays(1);
2335 sync_parameters(CHANGE_PARAMS);
2338 //void MWindow::set_titles(int value)
2340 // edl->session->show_titles = value;
2341 // trackmovement(edl->local_session->track_start);
2344 void MWindow::set_screens(int value)
2349 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2351 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2352 edl->session->auto_keyframes = value;
2353 gui->mbuttons->edit_panel->keyframe->update(value);
2355 if(lock_mwindow) gui->unlock_window();
2357 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2358 cwindow->gui->edit_panel->keyframe->update(value);
2359 cwindow->gui->flush();
2360 if(lock_cwindow) cwindow->gui->unlock_window();
2363 void MWindow::set_auto_visibility(Autos *autos, int value)
2365 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2366 edl->session->auto_conf->plugins = value;
2367 else if( autos->autoidx >= 0 )
2368 edl->session->auto_conf->autos[autos->autoidx] = value;
2372 gui->update(0, 1, 0, 0, 0, 0, 0);
2373 gui->mainmenu->update_toggles(1);
2374 gui->unlock_window();
2375 gwindow->gui->update_toggles(1);
2376 gui->lock_window("MWindow::set_auto_visibility");
2379 void MWindow::set_keyframe_type(int mode)
2381 gui->lock_window("MWindow::set_keyframe_type");
2382 edl->local_session->floatauto_type = mode;
2383 gui->mainmenu->update_toggles(0);
2384 gui->unlock_window();
2387 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2389 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2390 edl->session->editing_mode = new_editing_mode;
2391 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2392 gui->mbuttons->edit_panel->update();
2393 gui->set_editing_mode(1);
2394 if(lock_mwindow) gui->unlock_window();
2397 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2398 cwindow->gui->edit_panel->update();
2399 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2400 if(lock_cwindow) cwindow->gui->unlock_window();
2404 void MWindow::toggle_editing_mode()
2406 int mode = edl->session->editing_mode;
2407 if( mode == EDITING_ARROW )
2408 set_editing_mode(EDITING_IBEAM, 0, 1);
2410 set_editing_mode(EDITING_ARROW, 0, 1);
2414 void MWindow::set_labels_follow_edits(int value)
2416 gui->lock_window("MWindow::set_labels_follow_edits");
2417 edl->session->labels_follow_edits = value;
2418 gui->mbuttons->edit_panel->locklabels->update(value);
2419 gui->mainmenu->labels_follow_edits->set_checked(value);
2421 gui->unlock_window();
2424 void MWindow::sync_parameters(int change_type)
2426 if( in_destructor ) return;
2428 // Sync engines which are playing back
2429 if(cwindow->playback_engine->is_playing_back)
2431 if(change_type == CHANGE_PARAMS)
2433 // TODO: block keyframes until synchronization is done
2434 cwindow->playback_engine->sync_parameters(edl);
2439 int command = cwindow->playback_engine->command->command;
2440 cwindow->playback_engine->que->send_command(STOP,
2444 // Waiting for tracking to finish would make the restart position more
2445 // accurate but it can't lock the window to stop tracking for some reason.
2446 // Not waiting for tracking gives a faster response but restart position is
2447 // only as accurate as the last tracking update.
2448 cwindow->playback_engine->interrupt_playback(0);
2449 cwindow->playback_engine->que->send_command(command,
2458 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2465 void MWindow::age_caches()
2467 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2469 // preferences->cache_size,
2470 // audio_cache->get_memory_usage(1),
2471 // video_cache->get_memory_usage(1),
2472 // frame_cache->get_memory_usage(),
2473 // wave_cache->get_memory_usage(),
2475 frame_cache->age_cache(512);
2476 wave_cache->age_cache(8192);
2478 int64_t memory_usage;
2479 int64_t prev_memory_usage = 0;
2481 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2482 while( !result && prev_memory_usage !=
2483 (memory_usage=video_cache->get_memory_usage(1)) &&
2484 memory_usage > video_size ) {
2485 video_cache->delete_oldest();
2486 prev_memory_usage = memory_usage;
2489 prev_memory_usage = 0;
2491 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2492 while( !result && prev_memory_usage !=
2493 (memory_usage=audio_cache->get_memory_usage(1)) &&
2494 memory_usage > audio_size ) {
2495 audio_cache->delete_oldest();
2496 prev_memory_usage = memory_usage;
2500 void MWindow::reset_android_remote()
2502 gui->use_android_remote(preferences->android_remote);
2506 void MWindow::show_keyframe_gui(Plugin *plugin)
2508 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2509 // Find existing thread
2510 for(int i = 0; i < keyframe_threads->size(); i++)
2512 if(keyframe_threads->get(i)->plugin == plugin)
2514 keyframe_threads->get(i)->start_window(plugin, 0);
2515 keyframe_gui_lock->unlock();
2520 // Find unused thread
2521 for(int i = 0; i < keyframe_threads->size(); i++)
2523 if(!keyframe_threads->get(i)->plugin)
2525 keyframe_threads->get(i)->start_window(plugin, 0);
2526 keyframe_gui_lock->unlock();
2531 // Create new thread
2532 KeyFrameThread *thread = new KeyFrameThread(this);
2533 keyframe_threads->append(thread);
2534 thread->start_window(plugin, 0);
2536 keyframe_gui_lock->unlock();
2543 void MWindow::show_plugin(Plugin *plugin)
2548 // Remove previously deleted plugin GUIs
2549 dead_plugin_lock->lock("MWindow::show_plugin");
2550 dead_plugins->remove_all_objects();
2551 dead_plugin_lock->unlock();
2553 //printf("MWindow::show_plugin %d\n", __LINE__);
2557 plugin_gui_lock->lock("MWindow::show_plugin");
2558 for(int i = 0; i < plugin_guis->total; i++)
2560 // Pointer comparison
2561 if(plugin_guis->get(i)->plugin == plugin)
2563 plugin_guis->get(i)->raise_window();
2570 //printf("MWindow::show_plugin 1\n");
2575 printf("MWindow::show_plugin track not defined.\n");
2577 PluginServer *server = scan_plugindb(plugin->title,
2578 plugin->track->data_type);
2580 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2581 if(server && server->uses_gui)
2583 PluginServer *gui = new PluginServer(*server);
2584 plugin_guis->append(gui);
2585 // Needs mwindow to do GUI
2586 gui->set_mwindow(this);
2587 gui->open_plugin(0, preferences, edl, plugin);
2592 plugin_gui_lock->unlock();
2593 //printf("MWindow::show_plugin %d\n", __LINE__);
2596 //printf("MWindow::show_plugin 2\n");
2599 void MWindow::hide_plugin(Plugin *plugin, int lock)
2602 // Update the toggle
2603 gui->lock_window("MWindow::hide_plugin");
2604 gui->update(0, 1, 0, 0, 0, 0, 0);
2605 gui->unlock_window();
2607 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2608 for(int i = 0; i < plugin_guis->total; i++)
2610 if(plugin_guis->get(i)->plugin == plugin)
2612 PluginServer *ptr = plugin_guis->get(i);
2613 plugin_guis->remove(ptr);
2614 if(lock) plugin_gui_lock->unlock();
2615 // Last command executed in client side close
2616 // Schedule for deletion
2623 if(lock) plugin_gui_lock->unlock();
2626 void MWindow::delete_plugin(PluginServer *plugin)
2628 dead_plugin_lock->lock("MWindow::delete_plugin");
2629 dead_plugins->append(plugin);
2630 dead_plugin_lock->unlock();
2633 void MWindow::hide_plugins()
2635 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2636 while(plugin_guis->size())
2638 PluginServer *ptr = plugin_guis->get(0);
2639 plugin_guis->remove(ptr);
2640 plugin_gui_lock->unlock();
2641 // Last command executed in client side close
2642 // Schedule for deletion
2645 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2647 plugin_gui_lock->unlock();
2649 hide_keyframe_guis();
2652 void MWindow::hide_keyframe_guis()
2654 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2655 for(int i = 0; i < keyframe_threads->size(); i++)
2657 keyframe_threads->get(i)->close_window();
2659 keyframe_gui_lock->unlock();
2662 void MWindow::hide_keyframe_gui(Plugin *plugin)
2664 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2665 for(int i = 0; i < keyframe_threads->size(); i++)
2667 if(keyframe_threads->get(i)->plugin == plugin)
2669 keyframe_threads->get(i)->close_window();
2673 keyframe_gui_lock->unlock();
2676 void MWindow::update_keyframe_guis()
2678 // Send new configuration to keyframe GUI's
2679 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2680 for(int i = 0; i < keyframe_threads->size(); i++)
2682 KeyFrameThread *ptr = keyframe_threads->get(i);
2683 if(edl->tracks->plugin_exists(ptr->plugin))
2687 ptr->close_window();
2690 keyframe_gui_lock->unlock();
2693 void MWindow::update_plugin_guis(int do_keyframe_guis)
2695 // Send new configuration to plugin GUI's
2696 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2698 for(int i = 0; i < plugin_guis->size(); i++)
2700 PluginServer *ptr = plugin_guis->get(i);
2701 if(edl->tracks->plugin_exists(ptr->plugin))
2705 // Schedule for deletion if no plugin
2706 plugin_guis->remove_number(i);
2715 // Change plugin variable if not visible
2716 Track *track = edl->tracks->first;
2719 for(int i = 0; i < track->plugin_set.size(); i++)
2721 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2725 for(int i = 0; i < plugin_guis->size(); i++)
2727 PluginServer *server = plugin_guis->get(i);
2728 if(server->plugin == plugin)
2735 if(!got_it) plugin->show = 0;
2737 plugin = (Plugin*)plugin->next;
2741 track = track->next;
2744 plugin_gui_lock->unlock();
2747 if(do_keyframe_guis) update_keyframe_guis();
2750 int MWindow::plugin_gui_open(Plugin *plugin)
2753 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2754 for(int i = 0; i < plugin_guis->total; i++)
2756 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2762 plugin_gui_lock->unlock();
2766 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2768 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2769 for(int i = 0; i < plugin_guis->total; i++)
2771 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2773 plugin_guis->get(i)->render_gui(data);
2777 plugin_gui_lock->unlock();
2780 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2782 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2783 for(int i = 0; i < plugin_guis->total; i++)
2785 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2787 plugin_guis->get(i)->render_gui(data, size);
2791 plugin_gui_lock->unlock();
2795 void MWindow::update_plugin_states()
2797 plugin_gui_lock->lock("MWindow::update_plugin_states");
2798 for(int i = 0; i < plugin_guis->total; i++)
2802 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2803 PluginServer *src_plugingui = plugin_guis->get(i);
2805 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2806 for(Track *track = edl->tracks->first;
2808 track = track->next)
2811 j < track->plugin_set.total && !result;
2814 PluginSet *plugin_set = track->plugin_set[j];
2815 for(Plugin *plugin = (Plugin*)plugin_set->first;
2817 plugin = (Plugin*)plugin->next)
2819 if(plugin == src_plugin &&
2820 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2826 // Doesn't exist anymore
2829 hide_plugin(src_plugin, 0);
2833 plugin_gui_lock->unlock();
2837 void MWindow::update_plugin_titles()
2839 for(int i = 0; i < plugin_guis->total; i++)
2841 plugin_guis->get(i)->update_title();
2845 int MWindow::asset_to_edl(EDL *new_edl,
2847 RecordLabels *labels)
2849 const int debug = 0;
2850 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2853 // Keep frame rate, sample rate, and output size unchanged.
2854 // These parameters would revert the project if VWindow displayed an asset
2855 // of different size than the project.
2856 if(new_asset->video_data)
2858 new_edl->session->video_tracks = new_asset->layers;
2861 new_edl->session->video_tracks = 0;
2863 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2869 if(new_asset->audio_data)
2871 new_edl->session->audio_tracks = new_asset->channels;
2874 new_edl->session->audio_tracks = 0;
2875 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2877 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2878 new_edl->create_default_tracks();
2879 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2880 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2884 //printf("MWindow::asset_to_edl 3\n");
2885 new_edl->insert_asset(new_asset,
2890 //printf("MWindow::asset_to_edl 3\n");
2891 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2893 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2894 if(edl->session->cursor_on_frames)
2896 double length = new_edl->tracks->total_length();
2897 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2898 new_edl->tracks->clear(length, edl_length, 1, 1);
2904 char string[BCTEXTLEN];
2906 fs.extract_name(string, new_asset->path);
2907 //printf("MWindow::asset_to_edl 3\n");
2909 strcpy(new_edl->local_session->clip_title, string);
2910 //printf("MWindow::asset_to_edl 4 %s\n", string);
2911 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2916 int MWindow::edl_to_nested(EDL *new_edl,
2920 // Keep frame rate, sample rate, and output size unchanged.
2921 // These parameters would revert the project if VWindow displayed an asset
2922 // of different size than the project.
2926 // Nest all video & audio outputs
2927 new_edl->session->video_tracks = 1;
2928 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2929 new_edl->create_default_tracks();
2933 new_edl->insert_asset(0,
2939 char string[BCTEXTLEN];
2941 fs.extract_name(string, nested_edl->path);
2942 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2944 strcpy(new_edl->local_session->clip_title, string);
2949 // Reset everything after a load.
2950 void MWindow::update_project(int load_mode)
2952 const int debug = 0;
2954 if(debug) PRINT_TRACE
2956 edl->tracks->update_y_pixels(theme);
2958 if(debug) PRINT_TRACE
2960 if(load_mode == LOADMODE_REPLACE ||
2961 load_mode == LOADMODE_REPLACE_CONCATENATE)
2966 gui->update(1, 1, 1, 1, 1, 1, 1);
2967 if(debug) PRINT_TRACE
2968 gui->unlock_window();
2970 cwindow->gui->lock_window("MWindow::update_project 1");
2971 cwindow->update(0, 0, 1, 1, 1);
2972 cwindow->gui->unlock_window();
2974 if(debug) PRINT_TRACE
2976 // Close all the vwindows
2977 if(load_mode == LOADMODE_REPLACE ||
2978 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2979 if(debug) PRINT_TRACE
2980 int first_vwindow = 0;
2981 if(session->show_vwindow) first_vwindow = 1;
2982 // Change visible windows to no source
2983 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2984 VWindow *vwindow = vwindows[i];
2985 if( !vwindow->is_running() ) continue;
2986 vwindow->change_source(-1);
2989 // Close remaining windows
2990 for(int i = first_vwindow; i < vwindows.size(); i++) {
2991 VWindow *vwindow = vwindows[i];
2992 if( !vwindow->is_running() ) continue;
2993 vwindow->close_window();
2995 if(debug) PRINT_TRACE
2997 else if(vwindows.size()) {
2998 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2999 if( vwindow->is_running() ) {
3000 vwindow->gui->lock_window("MWindow::update_project");
3002 vwindow->gui->unlock_window();
3006 if(debug) PRINT_TRACE
3007 cwindow->gui->lock_window("MWindow::update_project 2");
3008 cwindow->gui->timebar->update(0);
3009 cwindow->gui->unlock_window();
3011 if(debug) PRINT_TRACE
3012 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3017 awindow->gui->async_update_assets();
3018 if(debug) PRINT_TRACE
3020 gui->lock_window("MWindow::update_project");
3022 if(debug) PRINT_TRACE
3025 void MWindow::remove_indexfile(Indexable *indexable)
3027 if( !indexable->is_asset ) return;
3028 Asset *asset = (Asset *)indexable;
3030 IndexFile::delete_index(preferences, asset, ".toc");
3031 IndexFile::delete_index(preferences, asset, ".idx");
3032 IndexFile::delete_index(preferences, asset, ".mkr");
3035 void MWindow::rebuild_indices()
3037 for(int i = 0; i < session->drag_assets->total; i++)
3039 Indexable *indexable = session->drag_assets->get(i);
3040 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3041 remove_indexfile(indexable);
3042 // Schedule index build
3043 IndexState *index_state = indexable->index_state;
3044 index_state->index_status = INDEX_NOTTESTED;
3045 if( indexable->is_asset ) {
3046 Asset *asset = (Asset *)indexable;
3047 if( asset->format != FILE_PCM ) {
3048 asset->format = FILE_UNKNOWN;
3049 asset->reset_audio();
3051 asset->reset_video();
3052 // File file; // re-probe the asset
3053 // file.open_file(preferences, asset, 1, 0);
3055 mainindexes->add_next_asset(0, indexable);
3057 mainindexes->start_build();
3061 void MWindow::save_backup()
3065 edl->set_path(session->filename);
3066 char backup_path[BCTEXTLEN];
3067 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3068 File::get_config_path(), BACKUP_FILE);
3069 edl->save_xml(&file, backup_path, 0, 0);
3070 file.terminate_string();
3072 fs.complete_path(backup_path);
3074 if(file.write_to_file(backup_path))
3077 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3078 gui->show_message(string2);
3082 void MWindow::load_backup()
3084 ArrayList<char*> path_list;
3085 path_list.set_array_delete();
3087 char backup_path[BCTEXTLEN];
3088 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3089 File::get_config_path(), BACKUP_FILE);
3091 fs.complete_path(backup_path);
3093 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3094 strcpy(out_path, backup_path);
3096 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3097 edl->local_session->clip_title[0] = 0;
3098 // This is unique to backups since the path of the backup is different than the
3099 // path of the project.
3100 set_filename(edl->path);
3101 path_list.remove_all_objects();
3105 static inline int gcd(int m, int n)
3108 if( m < n ) { r = m; m = n; n = r; }
3109 while( (r = m % n) != 0 ) { m = n; n = r; }
3113 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3116 if(!width || !height) return 1;
3117 if( width == 720 && (height == 480 || height == 576) ) {
3118 w = 4; h = 3; return 0; // for NTSC and PAL
3120 double ar = (double)width / height;
3121 // square-ish pixels
3122 if( EQUIV(ar, 1.0000) ) return 0;
3123 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3124 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3125 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3126 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3127 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3128 int ww = width, hh = height;
3129 // numerator, denominator must be under mx
3130 int mx = 255, n = gcd(ww, hh);
3131 if( n > 1 ) { ww /= n; hh /= n; }
3132 // search near height in case extra/missing lines
3133 if( ww >= mx || hh >= mx ) {
3134 double err = height; // +/- 2 percent height
3135 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3136 int iw = width, ih = height+i;
3137 if( (n=gcd(iw, ih)) > 1 ) {
3138 int u = iw/n; if( u >= mx ) continue;
3139 int v = ih/n; if( v >= mx ) continue;
3140 double r = (double) u/v, er = fabs(ar-r);
3141 if( er >= err ) continue;
3142 err = er; ww = u; hh = v;
3151 void MWindow::reset_caches()
3153 frame_cache->remove_all();
3154 wave_cache->remove_all();
3155 audio_cache->remove_all();
3156 video_cache->remove_all();
3157 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3158 cwindow->playback_engine->audio_cache->remove_all();
3159 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3160 cwindow->playback_engine->video_cache->remove_all();
3162 for(int i = 0; i < vwindows.size(); i++) {
3163 VWindow *vwindow = vwindows[i];
3164 if( !vwindow->is_running() ) continue;
3165 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3166 vwindow->playback_engine->audio_cache->remove_all();
3167 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3168 vwindow->playback_engine->video_cache->remove_all();
3172 void MWindow::remove_asset_from_caches(Asset *asset)
3174 gui->resource_thread->get_video_source(0);
3175 gui->resource_thread->get_audio_source(0);
3176 frame_cache->remove_asset(asset);
3177 wave_cache->remove_asset(asset);
3178 audio_cache->delete_entry(asset);
3179 video_cache->delete_entry(asset);
3180 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3181 cwindow->playback_engine->audio_cache->delete_entry(asset);
3182 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3183 cwindow->playback_engine->video_cache->delete_entry(asset);
3184 for(int i = 0; i < vwindows.size(); i++) {
3185 VWindow *vwindow = vwindows[i];
3186 if( !vwindow->is_running() ) continue;
3187 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3188 vwindow->playback_engine->audio_cache->delete_entry(asset);
3189 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3190 vwindow->playback_engine->video_cache->delete_entry(asset);
3195 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3196 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3198 for(int i = 0; i < drag_assets->total; i++) {
3199 Indexable *indexable = drag_assets->get(i);
3200 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3203 // Remove from VWindow.
3204 for(int i = 0; i < session->drag_clips->total; i++) {
3205 for(int j = 0; j < vwindows.size(); j++) {
3206 VWindow *vwindow = vwindows[j];
3207 if( !vwindow->is_running() ) continue;
3208 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3209 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3210 vwindow->delete_source(1, 1);
3211 vwindow->gui->unlock_window();
3216 for(int i = 0; i < drag_assets->size(); i++) {
3217 for(int j = 0; j < vwindows.size(); j++) {
3218 VWindow *vwindow = vwindows[j];
3219 if( !vwindow->is_running() ) continue;
3220 if(drag_assets->get(i) == vwindow->get_source()) {
3221 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3222 vwindow->delete_source(1, 1);
3223 vwindow->gui->unlock_window();
3228 for(int i = 0; i < drag_assets->size(); i++) {
3229 Indexable *indexable = drag_assets->get(i);
3230 remove_indexfile(indexable);
3233 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3234 if(push_undo) undo->update_undo_before();
3235 if(drag_assets) edl->remove_from_project(drag_assets);
3236 if(drag_clips) edl->remove_from_project(drag_clips);
3237 if(redraw) save_backup();
3238 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3242 gui->lock_window("MWindow::remove_assets_from_project 3");
3243 gui->update(1, 1, 1, 1, 0, 1, 0);
3244 gui->unlock_window();
3246 // Removes from playback here
3247 sync_parameters(CHANGE_ALL);
3250 awindow->gui->async_update_assets();
3253 void MWindow::remove_assets_from_disk()
3256 for(int i = 0; i < session->drag_assets->total; i++)
3258 remove(session->drag_assets->get(i)->path);
3261 remove_assets_from_project(1,
3263 session->drag_assets,
3264 session->drag_clips);
3267 void MWindow::dump_plugins(FILE *fp)
3269 if( !plugindb ) return;
3270 for(int i = 0; i < plugindb->total; i++)
3272 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3273 " synth=%d transition=%d theme=%d %s\n",
3274 plugindb->get(i)->plugin_type,
3275 plugindb->get(i)->audio,
3276 plugindb->get(i)->video,
3277 plugindb->get(i)->realtime,
3278 plugindb->get(i)->multichannel,
3279 plugindb->get(i)->get_synthesis(),
3280 plugindb->get(i)->transition,
3281 plugindb->get(i)->theme,
3282 plugindb->get(i)->title);
3286 void MWindow::dump_edl(FILE *fp)
3292 void MWindow::dump_undo(FILE *fp)
3298 void MWindow::dump_exe(FILE *fp)
3300 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3301 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3303 int ret = -1, n = 100;
3304 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3305 exe_path[len] = 0; strcpy(proc_path, exe_path);
3308 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3311 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3312 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3313 struct tm *tm = localtime(&st.st_mtime);
3315 strftime(mtime, sizeof(mtime), "%F %T", tm);
3316 fprintf(fp,"mtime: %s\n", mtime);
3318 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3319 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3322 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3323 int64_t maxsz = 1024*pagsz;
3324 int64_t size = st.st_size, pos = 0;
3326 while( (bfrsz = size-pos) > 0 ) {
3327 if( bfrsz > maxsz ) bfrsz = maxsz;
3328 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3329 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3330 if( bfr == MAP_FAILED ) break;
3331 sha1.addBytes(bfr, bfrsz);
3336 ret = pos < size ? EIO : 0;
3337 fprintf(fp, "SHA1: ");
3338 uint8_t digest[20]; sha1.computeHash(digest);
3339 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3340 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3341 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3345 void MWindow::trap_hook(FILE *fp, void *vp)
3347 MWindow *mwindow = (MWindow *)vp;
3348 // fprintf(fp, "\nPLUGINS:\n");
3349 // mwindow->dump_plugins(fp);
3350 fprintf(fp, "\nEDL:\n");
3351 mwindow->dump_edl(fp);
3352 fprintf(fp, "\nUNDO:\n");
3353 mwindow->dump_undo(fp);
3354 fprintf(fp, "\nEXE:\n");
3355 mwindow->dump_exe(fp);
3363 int MWindow::save_defaults()
3365 gui->save_defaults(defaults);
3366 edl->save_defaults(defaults);
3367 session->save_defaults(defaults);
3368 preferences->save_defaults(defaults);
3370 for(int i = 0; i < plugin_guis->total; i++)
3372 // Pointer comparison
3373 plugin_guis->get(i)->save_defaults();
3375 awindow->save_defaults(defaults);
3381 int MWindow::run_script(FileXML *script)
3383 int result = 0, result2 = 0;
3384 while(!result && !result2)
3386 result = script->read_tag();
3389 if(script->tag.title_is("new_project"))
3391 // Run new in immediate mode.
3392 // gui->mainmenu->new_project->run_script(script);
3395 if(script->tag.title_is("record"))
3397 // Run record as a thread. It is a terminal command.
3399 // Will read the complete scipt file without letting record read it if not
3405 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3412 // ================================= synchronization
3415 int MWindow::interrupt_indexes()
3417 mainprogress->cancelled = 1;
3418 mainindexes->interrupt_build();
3424 void MWindow::next_time_format()
3426 switch(edl->session->time_format)
3428 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3429 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3430 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3431 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3432 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3433 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3434 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3437 time_format_common();
3440 void MWindow::prev_time_format()
3442 switch(edl->session->time_format)
3444 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3445 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3446 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3447 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3448 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3449 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3450 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3453 time_format_common();
3456 void MWindow::time_format_common()
3458 gui->lock_window("MWindow::next_time_format");
3459 gui->redraw_time_dependancies();
3462 char string[BCTEXTLEN], string2[BCTEXTLEN];
3463 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3464 gui->show_message(string);
3466 gui->unlock_window();
3470 int MWindow::set_filename(const char *filename)
3472 if( filename != session->filename )
3473 strcpy(session->filename, filename);
3474 if( filename != edl->path )
3475 strcpy(edl->path, filename);
3479 if(filename[0] == 0)
3481 gui->set_title(PROGRAM_NAME);
3486 char string[BCTEXTLEN], string2[BCTEXTLEN];
3487 dir.extract_name(string, filename);
3488 sprintf(string2, PROGRAM_NAME ": %s", string);
3489 gui->set_title(string2);
3502 int MWindow::set_loop_boundaries()
3504 double start = edl->local_session->get_selectionstart();
3505 double end = edl->local_session->get_selectionend();
3513 if(edl->tracks->total_length())
3516 end = edl->tracks->total_length();
3523 if(edl->local_session->loop_playback && start != end)
3525 edl->local_session->loop_start = start;
3526 edl->local_session->loop_end = end;
3537 int MWindow::reset_meters()
3539 cwindow->gui->lock_window("MWindow::reset_meters 1");
3540 cwindow->gui->meters->reset_meters();
3541 cwindow->gui->unlock_window();
3543 for(int j = 0; j < vwindows.size(); j++) {
3544 VWindow *vwindow = vwindows[j];
3545 if( !vwindow->is_running() ) continue;
3546 vwindow->gui->lock_window("MWindow::reset_meters 2");
3547 vwindow->gui->meters->reset_meters();
3548 vwindow->gui->unlock_window();
3551 lwindow->gui->lock_window("MWindow::reset_meters 3");
3552 lwindow->gui->panel->reset_meters();
3553 lwindow->gui->unlock_window();
3555 gui->lock_window("MWindow::reset_meters 4");
3556 gui->reset_meters();
3557 gui->unlock_window();
3562 void MWindow::resync_guis()
3566 gui->lock_window("MWindow::resync_guis");
3567 gui->update(1, 1, 1, 1, 1, 1, 0);
3568 gui->unlock_window();
3570 cwindow->gui->lock_window("MWindow::resync_guis");
3571 cwindow->gui->resize_event(cwindow->gui->get_w(),
3572 cwindow->gui->get_h());
3573 int channels = edl->session->audio_channels;
3574 cwindow->gui->meters->set_meters(channels, 1);
3575 cwindow->gui->flush();
3576 cwindow->gui->unlock_window();
3578 for(int i = 0; i < vwindows.size(); i++) {
3579 VWindow *vwindow = vwindows[i];
3580 if( !vwindow->is_running() ) continue;
3581 vwindow->gui->lock_window("MWindow::resync_guis");
3582 vwindow->gui->resize_event(vwindow->gui->get_w(),
3583 vwindow->gui->get_h());
3584 vwindow->gui->meters->set_meters(channels, 1);
3585 vwindow->gui->flush();
3586 vwindow->gui->unlock_window();
3589 lwindow->gui->lock_window("MWindow::resync_guis");
3590 lwindow->gui->panel->set_meters(channels, 1);
3591 lwindow->gui->flush();
3592 lwindow->gui->unlock_window();
3595 if(((edl->session->output_w % 4) ||
3596 (edl->session->output_h % 4)) &&
3597 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3599 MainError::show_error(
3600 _("This project's dimensions are not multiples of 4 so\n"
3601 "it can't be rendered by OpenGL."));
3606 sync_parameters(CHANGE_ALL);
3609 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3611 File *file = new File;
3612 EDLSession *session = edl->session;
3613 double old_framerate = session->frame_rate;
3614 double old_samplerate = session->sample_rate;
3615 int old_auto_keyframes = session->auto_keyframes;
3616 session->auto_keyframes = 0;
3617 int result = file->open_file(preferences, asset, 1, 0);
3618 if( !result && delete_tracks > 0 )
3619 undo->update_undo_before();
3620 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3621 // try to get asset up to date, may fail
3622 file->select_video_stream(asset, vstream);
3623 // either way use what was/is there.
3624 double framerate = asset->get_frame_rate();
3625 int width = asset->get_w();
3626 int height = asset->get_h();
3627 // must be multiple of 4 for opengl
3628 width = (width+3) & ~3; height = (height+3) & ~3;
3629 int driver = session->playback_config->vconfig->driver;
3630 int color_model = file->get_best_colormodel(asset, driver);
3631 // color_model = BC_CModels::is_yuv(color_model) ?
3632 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3633 // BC_CModels::is_float(color_model) ?
3634 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3635 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3636 // have alpha for now
3637 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3638 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3639 session->color_model = color_model;
3640 session->output_w = width;
3641 session->output_h = height;
3642 session->frame_rate = framerate;
3643 // not, asset->actual_width/actual_height
3644 asset->width = session->output_w;
3645 asset->height = session->output_h;
3646 asset->frame_rate = session->frame_rate;
3647 create_aspect_ratio(session->aspect_w, session->aspect_h,
3648 session->output_w, session->output_h);
3649 Track *track = edl->tracks->first;
3650 for( Track *next_track=0; track; track=next_track ) {
3651 next_track = track->next;
3652 if( track->data_type != TRACK_VIDEO ) continue;
3653 if( delete_tracks ) {
3654 Edit *edit = track->edits->first;
3655 for( Edit *next_edit=0; edit; edit=next_edit ) {
3656 next_edit = edit->next;
3657 if( edit->channel != vstream ||
3658 !edit->asset || !edit->asset->is_asset ||
3659 !asset->equivalent(*edit->asset,1,1,edl) )
3663 if( track->edits->first ) {
3664 track->track_w = edl->session->output_w;
3665 track->track_h = edl->session->output_h;
3667 else if( delete_tracks )
3668 edl->tracks->delete_track(track);
3671 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3673 if( !result && asset->audio_data && asset->channels > 0 ) {
3674 session->sample_rate = asset->get_sample_rate();
3675 int64_t channel_mask = 0;
3676 int astrm = !asset->video_data ? -1 :
3677 file->get_audio_for_video(vstream, astream, channel_mask);
3678 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3679 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3681 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3682 if( channels < 1 ) channels = 1;
3683 if( channels > 6 ) channels = 6;
3684 session->audio_tracks = session->audio_channels = channels;
3685 switch( channels ) {
3687 session->achannel_positions[0] = 90;
3688 session->achannel_positions[1] = 150;
3689 session->achannel_positions[2] = 30;
3690 session->achannel_positions[3] = 210;
3691 session->achannel_positions[4] = 330;
3692 session->achannel_positions[5] = 270;
3695 session->achannel_positions[0] = 180;
3696 session->achannel_positions[1] = 0;
3699 session->achannel_positions[1] = 90;
3702 if( !channels ) break;
3703 double t = 0, dt = 360./channels;
3704 for( int i=channels; --i>=0; t+=dt )
3705 session->achannel_positions[i] = int(t+0.5);
3708 remap_audio(MWindow::AUDIO_1_TO_1);
3710 if( delete_tracks ) {
3711 Track *track = edl->tracks->first;
3712 for( Track *next_track=0; track; track=next_track ) {
3713 next_track = track->next;
3714 if( track->data_type != TRACK_AUDIO ) continue;
3715 Edit *edit = track->edits->first;
3716 for( Edit *next_edit=0; edit; edit=next_edit ) {
3717 next_edit = edit->next;
3718 if( !((1<<edit->channel) & channel_mask) ||
3719 !edit->asset || !edit->asset->is_asset ||
3720 !asset->equivalent(*edit->asset,1,1,edl) )
3723 if( !track->edits->first )
3724 edl->tracks->delete_track(track);
3728 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3731 session->auto_keyframes = old_auto_keyframes;
3732 if( !result && delete_tracks > 0 ) {
3734 undo->update_undo_after(_("select asset"), LOAD_ALL);
3740 int MWindow::select_asset(int vtrack, int delete_tracks)
3742 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3744 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3745 if( !track ) return 1;
3746 Edit *edit = track->edits->first;
3747 if( !edit ) return 1;
3748 Asset *asset = edit->asset;
3749 if( !asset || !asset->is_asset ) return 1;
3750 return select_asset(asset, edit->channel, 0, delete_tracks);
3753 void MWindow::dump_plugindb(FILE *fp)
3755 if( !plugindb ) return;
3756 for(int i = 0; i < plugindb->total; i++)
3757 plugindb->get(i)->dump(fp);
3760 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
3763 double unit_position = edl->local_session->get_selectionstart(1);
3764 unit_position = patch->track->to_units(unit_position, 0);
3766 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
3767 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3770 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
3773 double unit_position = edl->local_session->get_selectionstart(1);
3774 unit_position = patch->track->to_units(unit_position, 0);
3776 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
3777 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3780 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
3783 double unit_position = edl->local_session->get_selectionstart(1);
3784 unit_position = patch->track->to_units(unit_position, 0);
3786 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
3787 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);