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::delete_plugins()
738 plugindb->remove_all_objects();
743 void MWindow::search_plugindb(int do_audio,
748 ArrayList<PluginServer*> &results)
751 for(int i = 0; i < MWindow::plugindb->total; i++)
753 PluginServer *current = MWindow::plugindb->get(i);
755 if(current->audio == do_audio &&
756 current->video == do_video &&
757 (current->realtime == is_realtime || is_realtime < 0) &&
758 current->transition == is_transition &&
759 current->theme == is_theme)
760 results.append(current);
763 // Alphabetize list by title
769 for(int i = 0; i < results.total - 1; i++)
771 PluginServer *value1 = results[i];
772 PluginServer *value2 = results[i + 1];
773 if(strcmp(_(value1->title), _(value2->title)) > 0)
777 results[i + 1] = value1;
783 PluginServer* MWindow::scan_plugindb(char *title,
788 // printf("MWindow::scan_plugindb data_type < 0\n");
792 for(int i = 0; i < plugindb->total; i++)
794 PluginServer *server = plugindb->get(i);
796 !strcasecmp(server->title, title) &&
798 (data_type == TRACK_AUDIO && server->audio) ||
799 (data_type == TRACK_VIDEO && server->video)))
800 return plugindb->get(i);
805 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
807 for( int i=0; i<plugins.size(); ++i )
808 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
812 int MWindow::plugin_exists(char *plugin_path)
814 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
817 void MWindow::init_preferences()
819 preferences = new Preferences;
820 preferences->load_defaults(defaults);
821 session = new MainSession(this);
822 session->load_defaults(defaults);
823 // set x11_host, screens, window_config
824 screens = session->set_default_x11_host();
825 BC_Signals::set_trap_hook(trap_hook, this);
826 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
827 BC_Signals::set_catch_intr(preferences->trap_sigintr);
828 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
829 BC_Trace::enable_locks();
832 BC_Trace::disable_locks();
834 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
835 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
838 void MWindow::clean_indexes()
843 int oldest_item = -1;
845 char string[BCTEXTLEN];
846 char string2[BCTEXTLEN];
848 // Delete extra indexes
849 fs.set_filter("*.idx");
850 fs.complete_path(preferences->index_directory);
851 fs.update(preferences->index_directory);
852 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
854 // Eliminate directories
859 for(int i = 0; i < fs.dir_list.total && !result; i++)
861 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
862 if(fs.is_dir(string))
864 delete fs.dir_list[i];
865 fs.dir_list.remove_number(i);
870 total_excess = fs.dir_list.total - preferences->index_count;
872 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
873 while(total_excess > 0)
876 for(int i = 0; i < fs.dir_list.total; i++)
878 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
880 if(i == 0 || fs.get_date(string) <= oldest)
882 oldest = fs.get_date(string);
890 fs.join_names(string,
891 preferences->index_directory,
892 fs.dir_list[oldest_item]->name);
893 //printf("MWindow::clean_indexes 1 %s\n", string);
895 perror("delete_indexes");
896 delete fs.dir_list[oldest_item];
897 fs.dir_list.remove_number(oldest_item);
899 // Remove table of contents if it exists
900 strcpy(string2, string);
901 char *ptr = strrchr(string2, '.');
904 //printf("MWindow::clean_indexes 2 %s\n", string2);
905 sprintf(ptr, ".toc");
907 sprintf(ptr, ".mkr");
916 void MWindow::init_awindow()
918 awindow = new AWindow(this);
919 awindow->create_objects();
922 void MWindow::init_gwindow()
924 gwindow = new GWindow(this);
925 gwindow->create_objects();
928 void MWindow::init_tipwindow()
930 TipWindow::load_tips(cin_lang);
932 twindow = new TipWindow(this);
936 void MWindow::show_warning(int *do_warning, const char *text)
938 if( do_warning && !*do_warning ) return;
940 wwindow = new WWindow(this);
941 wwindow->show_warning(do_warning, text);
944 int MWindow::wait_warning()
946 return wwindow->wait_result();
949 void MWindow::init_theme()
954 PluginServer *theme_plugin = 0;
955 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
956 if( plugindb->get(i)->theme &&
957 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
958 theme_plugin = plugindb->get(i);
962 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
965 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
966 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
968 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
969 if( plugindb->get(i)->theme &&
970 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
971 theme_plugin = plugindb->get(i);
976 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
980 PluginServer *plugin = new PluginServer(*theme_plugin);
981 if( plugin->open_plugin(0, preferences, 0, 0) ) {
982 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
983 theme_plugin->title);
987 theme = plugin->new_theme();
988 theme->mwindow = this;
989 strcpy(theme->path, plugin->path);
992 // Load default images & settings
993 theme->Theme::initialize();
994 // Load user images & settings
996 // Create menus with user colors
997 theme->build_menus();
1000 theme->check_used();
1002 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1005 void MWindow::init_3d()
1007 playback_3d = new Playback3D(this);
1008 playback_3d->create_objects();
1011 void MWindow::init_edl()
1014 edl->create_objects();
1015 fill_preset_defaults(default_standard, edl->session);
1016 edl->load_defaults(defaults);
1017 edl->session->brender_start = edl->session->brender_end = 0;
1018 edl->create_default_tracks();
1019 edl->tracks->update_y_pixels(theme);
1022 void MWindow::init_compositor()
1024 cwindow = new CWindow(this);
1025 cwindow->create_objects();
1028 void MWindow::init_levelwindow()
1030 lwindow = new LevelWindow(this);
1031 lwindow->create_objects();
1034 VWindow *MWindow::get_viewer(int start_it, int idx)
1036 vwindows_lock->lock("MWindow::get_viewer");
1037 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1038 if( !vwindow ) idx = vwindows.size();
1039 while( !vwindow && --idx >= 0 ) {
1040 VWindow *vwin = vwindows[idx];
1041 if( !vwin->is_running() || !vwin->get_edl() )
1045 vwindow = new VWindow(this);
1046 vwindow->load_defaults();
1047 vwindow->create_objects();
1048 vwindows.append(vwindow);
1050 vwindows_lock->unlock();
1051 if( start_it ) vwindow->start();
1055 void MWindow::init_cache()
1057 audio_cache = new CICache(preferences);
1058 video_cache = new CICache(preferences);
1059 frame_cache = new FrameCache;
1060 wave_cache = new WaveCache;
1063 void MWindow::init_channeldb()
1065 channeldb_buz->load("channeldb_buz");
1066 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1069 void MWindow::init_menus()
1071 char string[BCTEXTLEN];
1074 BC_CModels::to_text(string, BC_RGB888);
1075 colormodels.append(new ColormodelItem(string, BC_RGB888));
1076 BC_CModels::to_text(string, BC_RGBA8888);
1077 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1078 // BC_CModels::to_text(string, BC_RGB161616);
1079 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1080 // BC_CModels::to_text(string, BC_RGBA16161616);
1081 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1082 BC_CModels::to_text(string, BC_RGB_FLOAT);
1083 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1084 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1085 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1086 BC_CModels::to_text(string, BC_YUV888);
1087 colormodels.append(new ColormodelItem(string, BC_YUV888));
1088 BC_CModels::to_text(string, BC_YUVA8888);
1089 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1090 // BC_CModels::to_text(string, BC_YUV161616);
1091 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1092 // BC_CModels::to_text(string, BC_YUVA16161616);
1093 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1095 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1096 interlace_project_modes.append(new InterlacemodeItem(string, x));
1098 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1099 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1101 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1102 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1104 // Interlacing Modes
1105 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1107 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1108 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1110 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1111 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1113 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1114 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1116 // Interlacing Fixing Methods
1117 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1118 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1119 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1122 void MWindow::init_indexes()
1124 mainindexes = new MainIndexes(this);
1125 mainindexes->start_loop();
1128 void MWindow::init_gui()
1130 gui = new MWindowGUI(this);
1131 gui->lock_window("MWindow::init_gui");
1132 gui->create_objects();
1133 gui->unlock_window();
1134 gui->load_defaults(defaults);
1137 void MWindow::init_signals()
1139 sighandler = new SigHandler;
1140 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1144 void MWindow::init_render()
1146 render = new Render(this);
1147 create_bd = new CreateBD_Thread(this);
1148 create_dvd = new CreateDVD_Thread(this);
1149 batch_render = new BatchRenderThread(this);
1152 void MWindow::init_exportedl()
1154 exportedl = new ExportEDL(this);
1157 void MWindow::init_brender()
1159 if(preferences->use_brender && !brender)
1161 brender_lock->lock("MWindow::init_brender 1");
1162 brender = new BRender(this);
1163 brender->initialize();
1164 session->brender_end = 0;
1165 brender_lock->unlock();
1168 if(!preferences->use_brender && brender)
1170 brender_lock->lock("MWindow::init_brender 2");
1173 session->brender_end = 0;
1174 brender_lock->unlock();
1180 void MWindow::restart_brender()
1182 //printf("MWindow::restart_brender 1\n");
1183 if( !brender_active || !preferences->use_brender ) return;
1184 if( !brender ) return;
1185 int locked = gui->get_window_lock();
1186 if( locked ) gui->unlock_window();
1187 brender->restart(edl);
1188 if( locked ) gui->lock_window("MWindow::restart_brender");
1191 void MWindow::stop_brender()
1193 if( !brender ) return;
1194 int locked = gui->get_window_lock();
1195 if( locked ) gui->unlock_window();
1197 if( locked ) gui->lock_window("MWindow::stop_brender");
1200 int MWindow::brender_available(int position)
1203 brender_lock->lock("MWindow::brender_available 1");
1204 if(brender && brender_active)
1206 if(brender->map_valid)
1208 brender->map_lock->lock("MWindow::brender_available 2");
1209 if(position < brender->map_size &&
1212 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1213 if(brender->map[position] == BRender::RENDERED)
1216 brender->map_lock->unlock();
1219 brender_lock->unlock();
1223 void MWindow::set_brender_active(int v, int update)
1225 if( !preferences->use_brender ) v = 0;
1227 gui->mainmenu->brender_active->set_checked(v);
1229 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1230 edl->session->brender_end = edl->local_session->get_selectionend(1);
1232 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1233 edl->session->brender_end = edl->tracks->total_video_length();
1238 edl->session->brender_start = edl->session->brender_end = 0;
1242 gui->update_timebar(0);
1243 gui->draw_overlays(1);
1247 int MWindow::has_commercials()
1249 return theme->use_commercials;
1252 void MWindow::init_commercials()
1254 if( !commercials ) {
1255 commercials = new Commercials(this);
1256 commercial_active = 0;
1259 commercials->add_user();
1262 void MWindow::commit_commercial()
1264 if( !commercial_active ) return;
1265 commercial_active = 0;
1266 if( !commercials ) return;
1267 commercials->commitDb();
1270 void MWindow::undo_commercial()
1272 if( !commercial_active ) return;
1273 commercial_active = 0;
1274 if( !commercials ) return;
1275 commercials->undoDb();
1278 int MWindow::put_commercial()
1280 double start = edl->local_session->get_selectionstart();
1281 double end = edl->local_session->get_selectionend();
1282 if( start >= end ) return 0;
1284 const char *errmsg = 0;
1286 Tracks *tracks = edl->tracks;
1289 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1290 if( track->data_type != TRACK_VIDEO ) continue;
1291 if( !track->record ) continue;
1292 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1294 int64_t units_start = track->to_units(start,0);
1295 int64_t units_end = track->to_units(end,0);
1296 Edits *edits = track->edits;
1297 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1298 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1299 if(!edit1 && !edit2) continue; // nothing selected
1300 if(!edit2) { // edit2 beyond end of track
1301 edit2 = edits->last;
1302 units_end = edits->length();
1304 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1305 Indexable *indexable = edit1->get_source();
1306 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1309 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1310 if( track->data_type != TRACK_VIDEO ) continue;
1311 if( !track->record ) continue;
1312 int64_t units_start = track->to_units(start,0);
1313 int64_t units_end = track->to_units(end,0);
1314 Edits *edits = track->edits;
1315 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1316 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1317 if(!edit1 && !edit2) continue; // nothing selected
1318 if(!edit2) { // edit2 beyond end of track
1319 edit2 = edits->last;
1320 units_end = edits->length();
1322 Indexable *indexable = edit1->get_source();
1323 Asset *asset = (Asset *)indexable;
1324 File *file = video_cache->check_out(asset, edl);
1325 if( !file ) { errmsg = _("no file"); break; }
1326 int64_t edit_length = units_end - units_start;
1327 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1328 result = commercials->put_clip(file, edit1->channel,
1329 track->from_units(edit_start), track->from_units(edit_length));
1330 video_cache->check_in(asset);
1331 if( result ) { errmsg = _("db failed"); break; }
1334 char string[BCTEXTLEN];
1335 sprintf(string, _("put_commercial: %s"), errmsg);
1336 MainError::show_error(string);
1343 void MWindow::stop_playback(int wait)
1345 int locked = gui->get_window_lock();
1346 if( locked ) gui->unlock_window();
1348 cwindow->playback_engine->stop_playback();
1350 for(int i = 0; i < vwindows.size(); i++) {
1351 VWindow *vwindow = vwindows[i];
1352 if( !vwindow->is_running() ) continue;
1353 vwindow->playback_engine->stop_playback();
1355 if( locked ) gui->lock_window("MWindow::stop_playback");
1358 int MWindow::load_filenames(ArrayList<char*> *filenames,
1360 int update_filename)
1362 ArrayList<EDL*> new_edls;
1363 ArrayList<Asset*> new_assets;
1364 ArrayList<File*> new_files;
1365 const int debug = 0;
1366 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1369 gui->start_hourglass();
1371 // Need to stop playback since tracking depends on the EDL not getting
1375 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1376 undo->update_undo_before();
1379 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1381 // Define new_edls and new_assets to load
1382 int result = 0, ftype = -1;
1383 for(int i = 0; i < filenames->size(); i++)
1386 File *new_file = new File;
1387 Asset *new_asset = new Asset(filenames->get(i));
1388 EDL *new_edl = new EDL;
1389 char string[BCTEXTLEN];
1391 new_edl->create_objects();
1392 new_edl->copy_session(edl);
1393 new_file->set_program(edl->session->program_no);
1395 sprintf(string, _("Loading %s"), new_asset->path);
1396 gui->show_message(string);
1397 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1399 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1400 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1405 // Convert media file to EDL
1407 // Warn about odd image dimensions
1408 if(new_asset->video_data &&
1409 ((new_asset->width % 2) ||
1410 (new_asset->height % 2)))
1412 char string[BCTEXTLEN];
1413 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1417 MainError::show_error(string);
1420 if(new_asset->program >= 0 &&
1421 edl->session->program_no != new_asset->program)
1423 char string[BCTEXTLEN];
1424 sprintf(string, _("%s's index was built for program number %d\n"
1425 "Playback preference is %d.\n Using program %d."),
1426 new_asset->path, new_asset->program,
1427 edl->session->program_no, new_asset->program);
1428 MainError::show_error(string);
1432 if(load_mode != LOADMODE_RESOURCESONLY)
1435 RecordLabels *labels = edl->session->label_cells ?
1436 new RecordLabels(new_file) : 0;
1438 asset_to_edl(new_edl, new_asset, labels);
1440 new_edls.append(new_edl);
1442 new_asset->Garbage::remove_user();
1448 new_assets.append(new_asset);
1452 // Set filename to nothing for assets since save EDL would overwrite them.
1453 if(load_mode == LOADMODE_REPLACE ||
1454 load_mode == LOADMODE_REPLACE_CONCATENATE)
1457 // Reset timeline position
1458 for(int i = 0; i < TOTAL_PANES; i++)
1460 new_edl->local_session->view_start[i] = 0;
1461 new_edl->local_session->track_start[i] = 0;
1469 case FILE_NOT_FOUND:
1470 sprintf(string, _("Failed to open %s"), new_asset->path);
1471 gui->show_message(string, theme->message_error);
1475 case FILE_UNRECOGNIZED_CODEC:
1478 { IndexFile indexfile(this, new_asset);
1479 if( !(result = indexfile.open_index()) )
1480 indexfile.close_index();
1483 // Test existing EDLs
1484 for(int j = 0; result && j <= new_edls.total; j++) {
1485 Asset *old_asset = j < new_edls.total ?
1486 new_edls[j]->assets->get_asset(new_asset->path) :
1487 edl->assets->get_asset(new_asset->path);
1489 new_asset->copy_from(old_asset,1);
1497 char string[BCTEXTLEN];
1499 fs.extract_name(string, new_asset->path);
1501 strcat(string, _("'s format couldn't be determined."));
1502 new_asset->audio_data = 1;
1503 new_asset->format = FILE_PCM;
1504 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1505 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1506 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1507 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1508 new_asset->signed_ = defaults->get("SIGNED_", 1);
1509 new_asset->header = defaults->get("HEADER", 0);
1511 FileFormat fwindow(this);
1512 fwindow.create_objects(new_asset, string);
1513 result = fwindow.run_window();
1516 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1517 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1518 defaults->update("AUDIO_BITS", new_asset->bits);
1519 defaults->update("BYTE_ORDER", new_asset->byte_order);
1520 defaults->update("SIGNED_", new_asset->signed_);
1521 defaults->update("HEADER", new_asset->header);
1528 // Recalculate length
1530 new_file = new File;
1531 result = new_file->open_file(preferences, new_asset, 1, 0);
1533 if(load_mode != LOADMODE_RESOURCESONLY)
1535 RecordLabels *labels = edl->session->label_cells ?
1536 new RecordLabels(new_file) : 0;
1537 asset_to_edl(new_edl, new_asset, labels);
1538 new_edls.append(new_edl);
1539 new_asset->Garbage::remove_user();
1545 new_assets.append(new_asset);
1559 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1560 xml_file.read_from_file(filenames->get(i));
1561 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1562 const char *cin_version = 0;
1563 while( !xml_file.read_tag() ) {
1564 if( xml_file.tag.title_is("EDL") ) {
1565 cin_version = xml_file.tag.get_property("VERSION");
1570 if( !cin_version ) {
1571 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1572 char string[BCTEXTLEN];
1573 sprintf(string,_("Unknown %s"), filenames->get(i));
1574 gui->show_message(string);
1578 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1579 char string[BCTEXTLEN];
1580 snprintf(string, sizeof(string),
1581 _("Warning: XML from cinelerra version %s\n"
1582 "Session data may be incompatible."), cin_version);
1583 show_warning(&preferences->warn_version, string);
1585 if(load_mode == LOADMODE_NESTED)
1587 // Load temporary EDL for nesting.
1588 EDL *nested_edl = new EDL;
1589 nested_edl->create_objects();
1590 nested_edl->set_path(filenames->get(i));
1591 nested_edl->load_xml(&xml_file, LOAD_ALL);
1592 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1593 edl_to_nested(new_edl, nested_edl);
1594 nested_edl->Garbage::remove_user();
1598 // Load EDL for pasting
1599 new_edl->load_xml(&xml_file, LOAD_ALL);
1600 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1601 test_plugins(new_edl, filenames->get(i));
1602 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1604 if(load_mode == LOADMODE_REPLACE ||
1605 load_mode == LOADMODE_REPLACE_CONCATENATE)
1607 strcpy(session->filename, filenames->get(i));
1608 strcpy(new_edl->local_session->clip_title,
1611 set_filename(new_edl->local_session->clip_title);
1615 new_edls.append(new_edl);
1621 // edls are in new_edls
1622 if( result && new_edl ) new_edl->Garbage::remove_user();
1623 // assets are copied
1624 if( new_asset ) new_asset->Garbage::remove_user();
1626 // Store for testing index
1627 new_files.append(new_file);
1630 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1633 if(!result) gui->statusbar->default_message();
1641 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1644 // Don't back up here.
1647 // For pasting, clear the active region
1648 if(load_mode == LOADMODE_PASTE ||
1649 load_mode == LOADMODE_NESTED)
1651 double start = edl->local_session->get_selectionstart();
1652 double end = edl->local_session->get_selectionend();
1653 if(!EQUIV(start, end))
1656 edl->session->labels_follow_edits,
1657 edl->session->plugins_follow_edits,
1658 edl->session->autos_follow_edits);
1661 paste_edls(&new_edls,
1665 edl->session->labels_follow_edits,
1666 edl->session->plugins_follow_edits,
1667 edl->session->autos_follow_edits,
1674 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1676 // Add new assets to EDL and schedule assets for index building.
1677 int got_indexes = 0;
1678 for(int i = 0; i < new_edls.size(); i++)
1680 EDL *new_edl = new_edls[i];
1681 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1683 mainindexes->add_next_asset(0,
1684 new_edl->nested_edls->get(j));
1686 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1691 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1692 if(new_assets.size())
1694 for(int i = 0; i < new_assets.size(); i++)
1696 Asset *new_asset = new_assets[i];
1700 for(int j = 0; j < new_files.size(); j++)
1702 new_file = new_files[j];
1703 if(!strcmp(new_file->asset->path,
1711 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1713 edl->assets->update(new_asset);
1719 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1721 // Start examining next batch of index files
1722 if(got_indexes) mainindexes->start_build();
1723 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1726 Track *track = edl->tracks->first;
1729 for(int j = 0; j < track->plugin_set.size(); j++)
1731 PluginSet *plugins = track->plugin_set[j];
1732 Plugin *plugin = plugins->get_first_plugin();
1736 if(load_mode == LOADMODE_REPLACE ||
1737 load_mode == LOADMODE_REPLACE_CONCATENATE)
1739 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1742 show_plugin(plugin);
1750 plugin = (Plugin*)plugin->next;
1754 track = track->next;
1757 // if just opening one new resource in replace mode
1758 if( ftype != FILE_IS_XML &&
1759 ( load_mode == LOADMODE_REPLACE ||
1760 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1762 edl->local_session->preview_start = 0;
1763 edl->local_session->preview_end = edl->tracks->total_playable_length();
1764 edl->local_session->loop_playback = 0;
1765 edl->local_session->set_selectionstart(0);
1766 edl->local_session->set_selectionend(0);
1767 set_brender_active(0, 0);
1772 // need to update undo before project, since mwindow is unlocked & a new load
1773 // can begin here. Should really prevent loading until we're done.
1774 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1775 undo->update_undo_after(_("load"), LOAD_ALL);
1777 for(int i = 0; i < new_edls.size(); i++)
1779 new_edls[i]->remove_user();
1781 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1783 new_edls.remove_all();
1785 for(int i = 0; i < new_assets.size(); i++)
1787 new_assets[i]->Garbage::remove_user();
1790 new_assets.remove_all();
1791 new_files.remove_all_objects();
1794 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1795 if(load_mode == LOADMODE_REPLACE ||
1796 load_mode == LOADMODE_REPLACE_CONCATENATE)
1798 session->changes_made = 0;
1802 session->changes_made = 1;
1805 gui->stop_hourglass();
1808 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1809 update_project(load_mode);
1811 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1819 void MWindow::test_plugins(EDL *new_edl, char *path)
1821 char string[BCTEXTLEN];
1823 // Do a check weather plugins exist
1824 for(Track *track = new_edl->tracks->first; track; track = track->next)
1826 for(int k = 0; k < track->plugin_set.total; k++)
1828 PluginSet *plugin_set = track->plugin_set[k];
1829 for(Plugin *plugin = (Plugin*)plugin_set->first;
1831 plugin = (Plugin*)plugin->next)
1833 if(plugin->plugin_type == PLUGIN_STANDALONE)
1835 // ok we need to find it in plugindb
1836 int plugin_found = 0;
1838 for(int j = 0; j < plugindb->size(); j++)
1840 PluginServer *server = plugindb->get(j);
1842 !strcasecmp(server->title, plugin->title) &&
1843 ((track->data_type == TRACK_AUDIO && server->audio) ||
1844 (track->data_type == TRACK_VIDEO && server->video)) &&
1845 (!server->transition))
1852 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1853 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1854 "effect", plugin->title,
1856 MainError::show_error(string);
1862 for(Edit *edit = (Edit*)track->edits->first;
1864 edit = (Edit*)edit->next)
1866 if (edit->transition)
1868 // ok we need to find transition in plugindb
1870 int transition_found = 0;
1871 for(int j = 0; j < plugindb->size(); j++)
1873 PluginServer *server = plugindb->get(j);
1875 !strcasecmp(server->title, edit->transition->title) &&
1876 ((track->data_type == TRACK_AUDIO && server->audio) ||
1877 (track->data_type == TRACK_VIDEO && server->video)) &&
1878 (server->transition))
1879 transition_found = 1;
1882 if (!transition_found)
1885 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1886 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1887 "transition", edit->transition->title,
1889 MainError::show_error(string);
1897 void MWindow::init_shm()
1899 // Fix shared memory
1900 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1902 fprintf(fd, "0x7fffffff");
1907 fd = fopen("/proc/sys/kernel/shmmax", "r");
1909 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1914 fscanf(fd, "%jd", &result);
1917 if(result < 0x7fffffff) {
1918 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1919 "you probably need to be root, or:\n"
1920 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1921 "before trying to start cinelerra.\n"
1922 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1926 void MWindow::create_objects(int want_gui,
1931 const int debug = 0;
1932 if(debug) PRINT_TRACE
1934 // For some reason, init_signals must come after show_splash or the signals won't
1937 if(debug) PRINT_TRACE
1940 if(debug) PRINT_TRACE
1943 if(debug) PRINT_TRACE
1944 default_standard = default_std();
1945 init_defaults(defaults, config_path);
1949 splash_window->operation->update(_("Initializing Plugins"));
1950 init_plugins(this, preferences);
1951 if(debug) PRINT_TRACE
1952 init_ladspa_plugins(this, preferences);
1953 if(debug) PRINT_TRACE
1955 splash_window->operation->update(_("Initializing GUI"));
1956 if(debug) PRINT_TRACE
1959 if(debug) PRINT_TRACE
1963 splash_window->operation->update(_("Initializing Fonts"));
1964 char string[BCTEXTLEN];
1965 strcpy(string, preferences->plugin_dir);
1966 strcat(string, "/" FONT_SEARCHPATH);
1967 BC_Resources::init_fontconfig(string);
1968 if(debug) PRINT_TRACE
1970 // Initialize before too much else is running
1971 // Preferences & theme are required for building MPEG table of contents
1973 // Default project created here
1975 if(debug) PRINT_TRACE
1978 if(debug) PRINT_TRACE
1983 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1985 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1986 if(session->show_vwindow)
1987 get_viewer(1, DEFAULT_VWINDOW);
1988 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1991 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1994 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1997 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1999 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2002 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2006 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2008 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2010 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2014 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2015 mainprogress = new MainProgress(this, gui);
2016 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2017 undo = new MainUndo(this);
2019 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2021 plugin_guis = new ArrayList<PluginServer*>;
2022 dead_plugins = new ArrayList<PluginServer*>;
2023 keyframe_threads = new ArrayList<KeyFrameThread*>;
2025 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2028 session->show_vwindow);
2030 // Show all vwindows
2031 // if(session->show_vwindow) {
2032 // for(int j = 0; j < vwindows.size(); j++) {
2033 // VWindow *vwindow = vwindows[j];
2034 // if( !vwindow->is_running() ) continue;
2035 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2038 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2039 // vwindow->gui->lock_window("MWindow::create_objects 1");
2040 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2041 // vwindow->gui->show_window();
2042 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2043 // vwindow->gui->unlock_window();
2048 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2050 if(session->show_cwindow)
2052 cwindow->gui->lock_window("MWindow::create_objects 1");
2053 cwindow->gui->show_window();
2054 cwindow->gui->unlock_window();
2057 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2058 if(session->show_awindow)
2060 awindow->gui->lock_window("MWindow::create_objects 1");
2061 awindow->gui->show_window();
2062 awindow->gui->unlock_window();
2065 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2066 if(session->show_lwindow)
2068 lwindow->gui->lock_window("MWindow::create_objects 1");
2069 lwindow->gui->show_window();
2070 lwindow->gui->unlock_window();
2073 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2075 (int)timer.get_difference(),
2077 if(session->show_gwindow)
2079 gwindow->gui->lock_window("MWindow::create_objects 1");
2080 gwindow->gui->show_window();
2081 gwindow->gui->unlock_window();
2084 if(debug) PRINT_TRACE
2086 gui->lock_window("MWindow::create_objects 1");
2087 gui->mainmenu->load_defaults(defaults);
2088 gui->mainmenu->update_toggles(0);
2089 gui->update_patchbay();
2090 gui->draw_canvas(0, 0);
2091 gui->draw_cursor(1);
2093 gui->raise_window();
2094 gui->unlock_window();
2096 if(debug) PRINT_TRACE
2098 if(preferences->use_tipwindow)
2100 if(debug) PRINT_TRACE
2102 gui->add_keyboard_listener(
2103 (int (BC_WindowBase::*)(BC_WindowBase *))
2104 &MWindowGUI::keyboard_listener);
2108 if(debug) PRINT_TRACE
2110 BC_WindowBase::get_resources()->vframe_shm = 1;
2114 void MWindow::show_splash()
2116 #include "data/heroine_logo9_png.h"
2117 VFrame *frame = new VFramePng(heroine_logo9_png);
2118 BC_DisplayInfo dpyi;
2119 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2120 int rr = (rw < rh ? rw : rh) / 4;
2121 splash_window = new SplashGUI(frame, rr, rr);
2122 splash_window->create_objects();
2125 void MWindow::hide_splash()
2128 delete splash_window;
2133 void MWindow::start()
2137 // vwindows[DEFAULT_VWINDOW]->start();
2148 playback_3d->start();
2154 run_lock->lock("MWindow::run");
2158 brender_lock->lock("MWindow::run 1");
2159 delete brender; brender = 0;
2160 brender_lock->unlock();
2162 interrupt_indexes();
2168 void MWindow::show_vwindow()
2170 int total_running = 0;
2171 session->show_vwindow = 1;
2173 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2174 // Raise all windows which are visible
2175 for(int j = 0; j < vwindows.size(); j++) {
2176 VWindow *vwindow = vwindows[j];
2177 if( !vwindow->is_running() ) continue;
2178 vwindow->gui->lock_window("MWindow::show_vwindow");
2179 vwindow->gui->show_window(0);
2180 vwindow->gui->raise_window();
2181 vwindow->gui->flush();
2182 vwindow->gui->unlock_window();
2186 // If no windows visible
2189 get_viewer(1, DEFAULT_VWINDOW);
2192 gui->mainmenu->show_vwindow->set_checked(1);
2195 void MWindow::show_awindow()
2197 session->show_awindow = 1;
2198 awindow->gui->lock_window("MWindow::show_awindow");
2199 awindow->gui->show_window();
2200 awindow->gui->raise_window();
2201 awindow->gui->flush();
2202 awindow->gui->unlock_window();
2203 gui->mainmenu->show_awindow->set_checked(1);
2206 char *MWindow::get_cwindow_display()
2208 char *x11_host = screens < 2 || session->window_config == 0 ?
2209 session->a_x11_host : session->b_x11_host;
2210 return *x11_host ? x11_host : 0;
2213 void MWindow::show_cwindow()
2215 session->show_cwindow = 1;
2216 cwindow->show_window();
2217 gui->mainmenu->show_cwindow->set_checked(1);
2220 void MWindow::show_gwindow()
2222 session->show_gwindow = 1;
2224 gwindow->gui->lock_window("MWindow::show_gwindow");
2225 gwindow->gui->show_window();
2226 gwindow->gui->raise_window();
2227 gwindow->gui->flush();
2228 gwindow->gui->unlock_window();
2230 gui->mainmenu->show_gwindow->set_checked(1);
2232 void MWindow::hide_gwindow()
2234 session->show_gwindow = 0;
2236 gwindow->gui->lock_window("MWindow::show_gwindow");
2237 gwindow->gui->hide_window();
2238 gwindow->gui->unlock_window();
2241 void MWindow::show_lwindow()
2243 session->show_lwindow = 1;
2244 lwindow->gui->lock_window("MWindow::show_lwindow");
2245 lwindow->gui->show_window();
2246 lwindow->gui->raise_window();
2247 lwindow->gui->flush();
2248 lwindow->gui->unlock_window();
2249 gui->mainmenu->show_lwindow->set_checked(1);
2252 int MWindow::tile_windows(int window_config)
2254 int need_reload = 0;
2255 int play_config = window_config==0 ? 0 : 1;
2256 edl->session->playback_config->load_defaults(defaults, play_config);
2257 session->default_window_positions(window_config);
2258 if( screens == 1 ) {
2259 gui->default_positions();
2260 sync_parameters(CHANGE_ALL);
2267 void MWindow::toggle_loop_playback()
2269 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2270 set_loop_boundaries();
2273 gui->draw_overlays(1);
2274 sync_parameters(CHANGE_PARAMS);
2277 //void MWindow::set_titles(int value)
2279 // edl->session->show_titles = value;
2280 // trackmovement(edl->local_session->track_start);
2283 void MWindow::set_screens(int value)
2288 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2290 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2291 edl->session->auto_keyframes = value;
2292 gui->mbuttons->edit_panel->keyframe->update(value);
2294 if(lock_mwindow) gui->unlock_window();
2296 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2297 cwindow->gui->edit_panel->keyframe->update(value);
2298 cwindow->gui->flush();
2299 if(lock_cwindow) cwindow->gui->unlock_window();
2302 void MWindow::set_auto_visibility(Autos *autos, int value)
2304 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2305 edl->session->auto_conf->plugins = value;
2306 else if( autos->autoidx >= 0 )
2307 edl->session->auto_conf->autos[autos->autoidx] = value;
2311 gui->update(0, 1, 0, 0, 0, 0, 0);
2312 gui->mainmenu->update_toggles(1);
2313 gui->unlock_window();
2314 gwindow->gui->update_toggles(1);
2315 gui->lock_window("MWindow::set_auto_visibility");
2318 void MWindow::set_keyframe_type(int mode)
2320 gui->lock_window("MWindow::set_keyframe_type");
2321 edl->local_session->floatauto_type = mode;
2322 gui->mainmenu->update_toggles(0);
2323 gui->unlock_window();
2326 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2328 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2329 edl->session->editing_mode = new_editing_mode;
2330 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2331 gui->mbuttons->edit_panel->update();
2332 gui->set_editing_mode(1);
2333 if(lock_mwindow) gui->unlock_window();
2336 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2337 cwindow->gui->edit_panel->update();
2338 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2339 if(lock_cwindow) cwindow->gui->unlock_window();
2343 void MWindow::toggle_editing_mode()
2345 int mode = edl->session->editing_mode;
2346 if( mode == EDITING_ARROW )
2347 set_editing_mode(EDITING_IBEAM, 0, 1);
2349 set_editing_mode(EDITING_ARROW, 0, 1);
2353 void MWindow::set_labels_follow_edits(int value)
2355 gui->lock_window("MWindow::set_labels_follow_edits");
2356 edl->session->labels_follow_edits = value;
2357 gui->mbuttons->edit_panel->locklabels->update(value);
2358 gui->mainmenu->labels_follow_edits->set_checked(value);
2360 gui->unlock_window();
2363 void MWindow::sync_parameters(int change_type)
2365 if( in_destructor ) return;
2367 // Sync engines which are playing back
2368 if(cwindow->playback_engine->is_playing_back)
2370 if(change_type == CHANGE_PARAMS)
2372 // TODO: block keyframes until synchronization is done
2373 cwindow->playback_engine->sync_parameters(edl);
2378 int command = cwindow->playback_engine->command->command;
2379 cwindow->playback_engine->que->send_command(STOP,
2383 // Waiting for tracking to finish would make the restart position more
2384 // accurate but it can't lock the window to stop tracking for some reason.
2385 // Not waiting for tracking gives a faster response but restart position is
2386 // only as accurate as the last tracking update.
2387 cwindow->playback_engine->interrupt_playback(0);
2388 cwindow->playback_engine->que->send_command(command,
2397 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2404 void MWindow::age_caches()
2406 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2408 // preferences->cache_size,
2409 // audio_cache->get_memory_usage(1),
2410 // video_cache->get_memory_usage(1),
2411 // frame_cache->get_memory_usage(),
2412 // wave_cache->get_memory_usage(),
2414 frame_cache->age_cache(512);
2415 wave_cache->age_cache(8192);
2417 int64_t memory_usage;
2418 int64_t prev_memory_usage = 0;
2420 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2421 while( !result && prev_memory_usage !=
2422 (memory_usage=video_cache->get_memory_usage(1)) &&
2423 memory_usage > video_size ) {
2424 video_cache->delete_oldest();
2425 prev_memory_usage = memory_usage;
2428 prev_memory_usage = 0;
2430 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2431 while( !result && prev_memory_usage !=
2432 (memory_usage=audio_cache->get_memory_usage(1)) &&
2433 memory_usage > audio_size ) {
2434 audio_cache->delete_oldest();
2435 prev_memory_usage = memory_usage;
2439 void MWindow::reset_android_remote()
2441 gui->use_android_remote(preferences->android_remote);
2445 void MWindow::show_keyframe_gui(Plugin *plugin)
2447 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2448 // Find existing thread
2449 for(int i = 0; i < keyframe_threads->size(); i++)
2451 if(keyframe_threads->get(i)->plugin == plugin)
2453 keyframe_threads->get(i)->start_window(plugin, 0);
2454 keyframe_gui_lock->unlock();
2459 // Find unused thread
2460 for(int i = 0; i < keyframe_threads->size(); i++)
2462 if(!keyframe_threads->get(i)->plugin)
2464 keyframe_threads->get(i)->start_window(plugin, 0);
2465 keyframe_gui_lock->unlock();
2470 // Create new thread
2471 KeyFrameThread *thread = new KeyFrameThread(this);
2472 keyframe_threads->append(thread);
2473 thread->start_window(plugin, 0);
2475 keyframe_gui_lock->unlock();
2482 void MWindow::show_plugin(Plugin *plugin)
2487 // Remove previously deleted plugin GUIs
2488 dead_plugin_lock->lock("MWindow::show_plugin");
2489 dead_plugins->remove_all_objects();
2490 dead_plugin_lock->unlock();
2492 //printf("MWindow::show_plugin %d\n", __LINE__);
2496 plugin_gui_lock->lock("MWindow::show_plugin");
2497 for(int i = 0; i < plugin_guis->total; i++)
2499 // Pointer comparison
2500 if(plugin_guis->get(i)->plugin == plugin)
2502 plugin_guis->get(i)->raise_window();
2509 //printf("MWindow::show_plugin 1\n");
2514 printf("MWindow::show_plugin track not defined.\n");
2516 PluginServer *server = scan_plugindb(plugin->title,
2517 plugin->track->data_type);
2519 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2520 if(server && server->uses_gui)
2522 PluginServer *gui = new PluginServer(*server);
2523 plugin_guis->append(gui);
2524 // Needs mwindow to do GUI
2525 gui->set_mwindow(this);
2526 gui->open_plugin(0, preferences, edl, plugin);
2531 plugin_gui_lock->unlock();
2532 //printf("MWindow::show_plugin %d\n", __LINE__);
2535 //printf("MWindow::show_plugin 2\n");
2538 void MWindow::hide_plugin(Plugin *plugin, int lock)
2541 // Update the toggle
2542 gui->lock_window("MWindow::hide_plugin");
2543 gui->update(0, 1, 0, 0, 0, 0, 0);
2544 gui->unlock_window();
2546 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2547 for(int i = 0; i < plugin_guis->total; i++)
2549 if(plugin_guis->get(i)->plugin == plugin)
2551 PluginServer *ptr = plugin_guis->get(i);
2552 plugin_guis->remove(ptr);
2553 if(lock) plugin_gui_lock->unlock();
2554 // Last command executed in client side close
2555 // Schedule for deletion
2562 if(lock) plugin_gui_lock->unlock();
2565 void MWindow::delete_plugin(PluginServer *plugin)
2567 dead_plugin_lock->lock("MWindow::delete_plugin");
2568 dead_plugins->append(plugin);
2569 dead_plugin_lock->unlock();
2572 void MWindow::hide_plugins()
2574 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2575 while(plugin_guis->size())
2577 PluginServer *ptr = plugin_guis->get(0);
2578 plugin_guis->remove(ptr);
2579 plugin_gui_lock->unlock();
2580 // Last command executed in client side close
2581 // Schedule for deletion
2584 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2586 plugin_gui_lock->unlock();
2588 hide_keyframe_guis();
2591 void MWindow::hide_keyframe_guis()
2593 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2594 for(int i = 0; i < keyframe_threads->size(); i++)
2596 keyframe_threads->get(i)->close_window();
2598 keyframe_gui_lock->unlock();
2601 void MWindow::hide_keyframe_gui(Plugin *plugin)
2603 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2604 for(int i = 0; i < keyframe_threads->size(); i++)
2606 if(keyframe_threads->get(i)->plugin == plugin)
2608 keyframe_threads->get(i)->close_window();
2612 keyframe_gui_lock->unlock();
2615 void MWindow::update_keyframe_guis()
2617 // Send new configuration to keyframe GUI's
2618 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2619 for(int i = 0; i < keyframe_threads->size(); i++)
2621 KeyFrameThread *ptr = keyframe_threads->get(i);
2622 if(edl->tracks->plugin_exists(ptr->plugin))
2626 ptr->close_window();
2629 keyframe_gui_lock->unlock();
2632 void MWindow::update_plugin_guis(int do_keyframe_guis)
2634 // Send new configuration to plugin GUI's
2635 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2637 for(int i = 0; i < plugin_guis->size(); i++)
2639 PluginServer *ptr = plugin_guis->get(i);
2640 if(edl->tracks->plugin_exists(ptr->plugin))
2644 // Schedule for deletion if no plugin
2645 plugin_guis->remove_number(i);
2654 // Change plugin variable if not visible
2655 Track *track = edl->tracks->first;
2658 for(int i = 0; i < track->plugin_set.size(); i++)
2660 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2664 for(int i = 0; i < plugin_guis->size(); i++)
2666 PluginServer *server = plugin_guis->get(i);
2667 if(server->plugin == plugin)
2674 if(!got_it) plugin->show = 0;
2676 plugin = (Plugin*)plugin->next;
2680 track = track->next;
2683 plugin_gui_lock->unlock();
2686 if(do_keyframe_guis) update_keyframe_guis();
2689 int MWindow::plugin_gui_open(Plugin *plugin)
2692 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2693 for(int i = 0; i < plugin_guis->total; i++)
2695 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2701 plugin_gui_lock->unlock();
2705 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2707 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2708 for(int i = 0; i < plugin_guis->total; i++)
2710 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2712 plugin_guis->get(i)->render_gui(data);
2716 plugin_gui_lock->unlock();
2719 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2721 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2722 for(int i = 0; i < plugin_guis->total; i++)
2724 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2726 plugin_guis->get(i)->render_gui(data, size);
2730 plugin_gui_lock->unlock();
2734 void MWindow::update_plugin_states()
2736 plugin_gui_lock->lock("MWindow::update_plugin_states");
2737 for(int i = 0; i < plugin_guis->total; i++)
2741 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2742 PluginServer *src_plugingui = plugin_guis->get(i);
2744 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2745 for(Track *track = edl->tracks->first;
2747 track = track->next)
2750 j < track->plugin_set.total && !result;
2753 PluginSet *plugin_set = track->plugin_set[j];
2754 for(Plugin *plugin = (Plugin*)plugin_set->first;
2756 plugin = (Plugin*)plugin->next)
2758 if(plugin == src_plugin &&
2759 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2765 // Doesn't exist anymore
2768 hide_plugin(src_plugin, 0);
2772 plugin_gui_lock->unlock();
2776 void MWindow::update_plugin_titles()
2778 for(int i = 0; i < plugin_guis->total; i++)
2780 plugin_guis->get(i)->update_title();
2784 int MWindow::asset_to_edl(EDL *new_edl,
2786 RecordLabels *labels)
2788 const int debug = 0;
2789 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2792 // Keep frame rate, sample rate, and output size unchanged.
2793 // These parameters would revert the project if VWindow displayed an asset
2794 // of different size than the project.
2795 if(new_asset->video_data)
2797 new_edl->session->video_tracks = new_asset->layers;
2800 new_edl->session->video_tracks = 0;
2802 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2808 if(new_asset->audio_data)
2810 new_edl->session->audio_tracks = new_asset->channels;
2813 new_edl->session->audio_tracks = 0;
2814 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2816 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2817 new_edl->create_default_tracks();
2818 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2819 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2823 //printf("MWindow::asset_to_edl 3\n");
2824 new_edl->insert_asset(new_asset,
2829 //printf("MWindow::asset_to_edl 3\n");
2830 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2832 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2833 if(edl->session->cursor_on_frames)
2835 double length = new_edl->tracks->total_length();
2836 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2837 new_edl->tracks->clear(length, edl_length, 1, 1);
2843 char string[BCTEXTLEN];
2845 fs.extract_name(string, new_asset->path);
2846 //printf("MWindow::asset_to_edl 3\n");
2848 strcpy(new_edl->local_session->clip_title, string);
2849 //printf("MWindow::asset_to_edl 4 %s\n", string);
2850 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2855 int MWindow::edl_to_nested(EDL *new_edl,
2859 // Keep frame rate, sample rate, and output size unchanged.
2860 // These parameters would revert the project if VWindow displayed an asset
2861 // of different size than the project.
2865 // Nest all video & audio outputs
2866 new_edl->session->video_tracks = 1;
2867 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2868 new_edl->create_default_tracks();
2872 new_edl->insert_asset(0,
2878 char string[BCTEXTLEN];
2880 fs.extract_name(string, nested_edl->path);
2881 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2883 strcpy(new_edl->local_session->clip_title, string);
2888 // Reset everything after a load.
2889 void MWindow::update_project(int load_mode)
2891 const int debug = 0;
2893 if(debug) PRINT_TRACE
2895 edl->tracks->update_y_pixels(theme);
2897 if(debug) PRINT_TRACE
2899 if(load_mode == LOADMODE_REPLACE ||
2900 load_mode == LOADMODE_REPLACE_CONCATENATE)
2905 gui->update(1, 1, 1, 1, 1, 1, 1);
2906 if(debug) PRINT_TRACE
2907 gui->unlock_window();
2909 cwindow->gui->lock_window("MWindow::update_project 1");
2910 cwindow->update(0, 0, 1, 1, 1);
2911 cwindow->gui->unlock_window();
2913 if(debug) PRINT_TRACE
2915 // Close all the vwindows
2916 if(load_mode == LOADMODE_REPLACE ||
2917 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2918 if(debug) PRINT_TRACE
2919 int first_vwindow = 0;
2920 if(session->show_vwindow) first_vwindow = 1;
2921 // Change visible windows to no source
2922 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2923 VWindow *vwindow = vwindows[i];
2924 if( !vwindow->is_running() ) continue;
2925 vwindow->change_source(-1);
2928 // Close remaining windows
2929 for(int i = first_vwindow; i < vwindows.size(); i++) {
2930 VWindow *vwindow = vwindows[i];
2931 if( !vwindow->is_running() ) continue;
2932 vwindow->close_window();
2934 if(debug) PRINT_TRACE
2936 else if(vwindows.size()) {
2937 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2938 if( vwindow->is_running() ) {
2939 vwindow->gui->lock_window("MWindow::update_project");
2941 vwindow->gui->unlock_window();
2945 if(debug) PRINT_TRACE
2946 cwindow->gui->lock_window("MWindow::update_project 2");
2947 cwindow->gui->timebar->update(0);
2948 cwindow->gui->unlock_window();
2950 if(debug) PRINT_TRACE
2951 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2956 awindow->gui->async_update_assets();
2957 if(debug) PRINT_TRACE
2959 gui->lock_window("MWindow::update_project");
2961 if(debug) PRINT_TRACE
2964 void MWindow::remove_indexfile(Indexable *indexable)
2966 if( !indexable->is_asset ) return;
2967 Asset *asset = (Asset *)indexable;
2969 IndexFile::delete_index(preferences, asset, ".toc");
2970 IndexFile::delete_index(preferences, asset, ".idx");
2971 IndexFile::delete_index(preferences, asset, ".mkr");
2974 void MWindow::rebuild_indices()
2976 for(int i = 0; i < session->drag_assets->total; i++)
2978 Indexable *indexable = session->drag_assets->get(i);
2979 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2980 remove_indexfile(indexable);
2981 // Schedule index build
2982 IndexState *index_state = indexable->index_state;
2983 index_state->index_status = INDEX_NOTTESTED;
2984 if( indexable->is_asset ) {
2985 Asset *asset = (Asset *)indexable;
2986 if( asset->format != FILE_PCM )
2987 asset->reset_audio();
2988 asset->reset_video();
2990 mainindexes->add_next_asset(0, indexable);
2992 mainindexes->start_build();
2996 void MWindow::save_backup()
3000 edl->set_path(session->filename);
3001 char backup_path[BCTEXTLEN];
3002 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3003 File::get_config_path(), BACKUP_FILE);
3004 edl->save_xml(&file, backup_path, 0, 0);
3005 file.terminate_string();
3007 fs.complete_path(backup_path);
3009 if(file.write_to_file(backup_path))
3012 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3013 gui->show_message(string2);
3017 void MWindow::load_backup()
3019 ArrayList<char*> path_list;
3020 path_list.set_array_delete();
3022 char backup_path[BCTEXTLEN];
3023 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3024 File::get_config_path(), BACKUP_FILE);
3026 fs.complete_path(backup_path);
3028 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3029 strcpy(out_path, backup_path);
3031 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3032 edl->local_session->clip_title[0] = 0;
3033 // This is unique to backups since the path of the backup is different than the
3034 // path of the project.
3035 set_filename(edl->path);
3036 path_list.remove_all_objects();
3040 static inline int gcd(int m, int n)
3043 if( m < n ) { r = m; m = n; n = r; }
3044 while( (r = m % n) != 0 ) { m = n; n = r; }
3048 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3051 if(!width || !height) return 1;
3052 if( width == 720 && (height == 480 || height == 576) ) {
3053 w = 4; h = 3; return 0; // for NTSC and PAL
3055 double ar = (double)width / height;
3056 // square-ish pixels
3057 if( EQUIV(ar, 1.0000) ) return 0;
3058 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3059 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3060 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3061 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3062 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3063 int ww = width, hh = height;
3064 // numerator, denominator must be under mx
3065 int mx = 255, n = gcd(ww, hh);
3066 if( n > 1 ) { ww /= n; hh /= n; }
3067 // search near height in case extra/missing lines
3068 if( ww >= mx || hh >= mx ) {
3069 double err = height; // +/- 2 percent height
3070 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3071 int iw = width, ih = height+i;
3072 if( (n=gcd(iw, ih)) > 1 ) {
3073 int u = iw/n; if( u >= mx ) continue;
3074 int v = ih/n; if( v >= mx ) continue;
3075 double r = (double) u/v, er = fabs(ar-r);
3076 if( er >= err ) continue;
3077 err = er; ww = u; hh = v;
3086 void MWindow::reset_caches()
3088 frame_cache->remove_all();
3089 wave_cache->remove_all();
3090 audio_cache->remove_all();
3091 video_cache->remove_all();
3092 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3093 cwindow->playback_engine->audio_cache->remove_all();
3094 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3095 cwindow->playback_engine->video_cache->remove_all();
3097 for(int i = 0; i < vwindows.size(); i++) {
3098 VWindow *vwindow = vwindows[i];
3099 if( !vwindow->is_running() ) continue;
3100 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3101 vwindow->playback_engine->audio_cache->remove_all();
3102 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3103 vwindow->playback_engine->video_cache->remove_all();
3107 void MWindow::remove_asset_from_caches(Asset *asset)
3109 gui->resource_thread->get_video_source(0);
3110 gui->resource_thread->get_audio_source(0);
3111 frame_cache->remove_asset(asset);
3112 wave_cache->remove_asset(asset);
3113 audio_cache->delete_entry(asset);
3114 video_cache->delete_entry(asset);
3115 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3116 cwindow->playback_engine->audio_cache->delete_entry(asset);
3117 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3118 cwindow->playback_engine->video_cache->delete_entry(asset);
3119 for(int i = 0; i < vwindows.size(); i++) {
3120 VWindow *vwindow = vwindows[i];
3121 if( !vwindow->is_running() ) continue;
3122 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3123 vwindow->playback_engine->audio_cache->delete_entry(asset);
3124 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3125 vwindow->playback_engine->video_cache->delete_entry(asset);
3130 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3131 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3133 for(int i = 0; i < session->drag_assets->total; i++) {
3134 Indexable *indexable = session->drag_assets->get(i);
3135 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3138 // Remove from VWindow.
3139 for(int i = 0; i < session->drag_clips->total; i++) {
3140 for(int j = 0; j < vwindows.size(); j++) {
3141 VWindow *vwindow = vwindows[j];
3142 if( !vwindow->is_running() ) continue;
3143 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3144 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3145 vwindow->delete_source(1, 1);
3146 vwindow->gui->unlock_window();
3151 for(int i = 0; i < session->drag_assets->size(); i++) {
3152 for(int j = 0; j < vwindows.size(); j++) {
3153 VWindow *vwindow = vwindows[j];
3154 if( !vwindow->is_running() ) continue;
3155 if(session->drag_assets->get(i) == vwindow->get_source()) {
3156 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3157 vwindow->delete_source(1, 1);
3158 vwindow->gui->unlock_window();
3163 for(int i = 0; i < session->drag_assets->size(); i++) {
3164 Indexable *indexable = session->drag_assets->get(i);
3165 remove_indexfile(indexable);
3168 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3169 if(push_undo) undo->update_undo_before();
3170 if(drag_assets) edl->remove_from_project(drag_assets);
3171 if(drag_clips) edl->remove_from_project(session->drag_clips);
3172 if(redraw) save_backup();
3173 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3178 gui->lock_window("MWindow::remove_assets_from_project 3");
3186 gui->unlock_window();
3188 // Removes from playback here
3189 sync_parameters(CHANGE_ALL);
3192 awindow->gui->async_update_assets();
3195 void MWindow::remove_assets_from_disk()
3198 for(int i = 0; i < session->drag_assets->total; i++)
3200 remove(session->drag_assets->get(i)->path);
3203 remove_assets_from_project(1,
3205 session->drag_assets,
3206 session->drag_clips);
3209 void MWindow::dump_plugins(FILE *fp)
3211 if( !plugindb ) return;
3212 for(int i = 0; i < plugindb->total; i++)
3214 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3215 " synth=%d transition=%d theme=%d %s\n",
3216 plugindb->get(i)->plugin_type,
3217 plugindb->get(i)->audio,
3218 plugindb->get(i)->video,
3219 plugindb->get(i)->realtime,
3220 plugindb->get(i)->multichannel,
3221 plugindb->get(i)->get_synthesis(),
3222 plugindb->get(i)->transition,
3223 plugindb->get(i)->theme,
3224 plugindb->get(i)->title);
3228 void MWindow::dump_edl(FILE *fp)
3234 void MWindow::dump_undo(FILE *fp)
3240 void MWindow::dump_exe(FILE *fp)
3242 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3243 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3245 int ret = -1, n = 100;
3246 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3247 exe_path[len] = 0; strcpy(proc_path, exe_path);
3250 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3253 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3254 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3255 struct tm *tm = localtime(&st.st_mtime);
3257 strftime(mtime, sizeof(mtime), "%F %T", tm);
3258 fprintf(fp,"mtime: %s\n", mtime);
3260 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3261 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3264 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3265 int64_t maxsz = 1024*pagsz;
3266 int64_t size = st.st_size, pos = 0;
3268 while( (bfrsz = size-pos) > 0 ) {
3269 if( bfrsz > maxsz ) bfrsz = maxsz;
3270 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3271 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3272 if( bfr == MAP_FAILED ) break;
3273 sha1.addBytes(bfr, bfrsz);
3278 ret = pos < size ? EIO : 0;
3279 fprintf(fp, "SHA1: ");
3280 uint8_t digest[20]; sha1.computeHash(digest);
3281 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3282 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3283 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3287 void MWindow::trap_hook(FILE *fp, void *vp)
3289 MWindow *mwindow = (MWindow *)vp;
3290 // fprintf(fp, "\nPLUGINS:\n");
3291 // mwindow->dump_plugins(fp);
3292 fprintf(fp, "\nEDL:\n");
3293 mwindow->dump_edl(fp);
3294 fprintf(fp, "\nUNDO:\n");
3295 mwindow->dump_undo(fp);
3296 fprintf(fp, "\nEXE:\n");
3297 mwindow->dump_exe(fp);
3305 int MWindow::save_defaults()
3307 gui->save_defaults(defaults);
3308 edl->save_defaults(defaults);
3309 session->save_defaults(defaults);
3310 preferences->save_defaults(defaults);
3312 for(int i = 0; i < plugin_guis->total; i++)
3314 // Pointer comparison
3315 plugin_guis->get(i)->save_defaults();
3317 awindow->save_defaults(defaults);
3323 int MWindow::run_script(FileXML *script)
3325 int result = 0, result2 = 0;
3326 while(!result && !result2)
3328 result = script->read_tag();
3331 if(script->tag.title_is("new_project"))
3333 // Run new in immediate mode.
3334 // gui->mainmenu->new_project->run_script(script);
3337 if(script->tag.title_is("record"))
3339 // Run record as a thread. It is a terminal command.
3341 // Will read the complete scipt file without letting record read it if not
3347 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3354 // ================================= synchronization
3357 int MWindow::interrupt_indexes()
3359 mainprogress->cancelled = 1;
3360 mainindexes->interrupt_build();
3366 void MWindow::next_time_format()
3368 switch(edl->session->time_format)
3370 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3371 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3372 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3373 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3374 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3375 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3376 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3379 time_format_common();
3382 void MWindow::prev_time_format()
3384 switch(edl->session->time_format)
3386 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3387 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3388 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3389 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3390 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3391 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3392 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3395 time_format_common();
3398 void MWindow::time_format_common()
3400 gui->lock_window("MWindow::next_time_format");
3401 gui->redraw_time_dependancies();
3404 char string[BCTEXTLEN], string2[BCTEXTLEN];
3405 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3406 gui->show_message(string);
3408 gui->unlock_window();
3412 int MWindow::set_filename(const char *filename)
3414 if( filename != session->filename )
3415 strcpy(session->filename, filename);
3416 if( filename != edl->path )
3417 strcpy(edl->path, filename);
3421 if(filename[0] == 0)
3423 gui->set_title(PROGRAM_NAME);
3428 char string[BCTEXTLEN], string2[BCTEXTLEN];
3429 dir.extract_name(string, filename);
3430 sprintf(string2, PROGRAM_NAME ": %s", string);
3431 gui->set_title(string2);
3444 int MWindow::set_loop_boundaries()
3446 double start = edl->local_session->get_selectionstart();
3447 double end = edl->local_session->get_selectionend();
3455 if(edl->tracks->total_length())
3458 end = edl->tracks->total_length();
3465 if(edl->local_session->loop_playback && start != end)
3467 edl->local_session->loop_start = start;
3468 edl->local_session->loop_end = end;
3479 int MWindow::reset_meters()
3481 cwindow->gui->lock_window("MWindow::reset_meters 1");
3482 cwindow->gui->meters->reset_meters();
3483 cwindow->gui->unlock_window();
3485 for(int j = 0; j < vwindows.size(); j++) {
3486 VWindow *vwindow = vwindows[j];
3487 if( !vwindow->is_running() ) continue;
3488 vwindow->gui->lock_window("MWindow::reset_meters 2");
3489 vwindow->gui->meters->reset_meters();
3490 vwindow->gui->unlock_window();
3493 lwindow->gui->lock_window("MWindow::reset_meters 3");
3494 lwindow->gui->panel->reset_meters();
3495 lwindow->gui->unlock_window();
3497 gui->lock_window("MWindow::reset_meters 4");
3498 gui->reset_meters();
3499 gui->unlock_window();
3504 void MWindow::resync_guis()
3508 gui->lock_window("MWindow::resync_guis");
3509 gui->update(1, 1, 1, 1, 1, 1, 0);
3510 gui->unlock_window();
3512 cwindow->gui->lock_window("MWindow::resync_guis");
3513 cwindow->gui->resize_event(cwindow->gui->get_w(),
3514 cwindow->gui->get_h());
3515 int channels = edl->session->audio_channels;
3516 cwindow->gui->meters->set_meters(channels, 1);
3517 cwindow->gui->flush();
3518 cwindow->gui->unlock_window();
3520 for(int i = 0; i < vwindows.size(); i++) {
3521 VWindow *vwindow = vwindows[i];
3522 if( !vwindow->is_running() ) continue;
3523 vwindow->gui->lock_window("MWindow::resync_guis");
3524 vwindow->gui->resize_event(vwindow->gui->get_w(),
3525 vwindow->gui->get_h());
3526 vwindow->gui->meters->set_meters(channels, 1);
3527 vwindow->gui->flush();
3528 vwindow->gui->unlock_window();
3531 lwindow->gui->lock_window("MWindow::resync_guis");
3532 lwindow->gui->panel->set_meters(channels, 1);
3533 lwindow->gui->flush();
3534 lwindow->gui->unlock_window();
3537 if(((edl->session->output_w % 4) ||
3538 (edl->session->output_h % 4)) &&
3539 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3541 MainError::show_error(
3542 _("This project's dimensions are not multiples of 4 so\n"
3543 "it can't be rendered by OpenGL."));
3548 sync_parameters(CHANGE_ALL);
3551 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3553 File *file = new File;
3554 EDLSession *session = edl->session;
3555 double old_framerate = session->frame_rate;
3556 double old_samplerate = session->sample_rate;
3557 int old_auto_keyframes = session->auto_keyframes;
3558 session->auto_keyframes = 0;
3559 int result = file->open_file(preferences, asset, 1, 0);
3560 if( !result && delete_tracks > 0 )
3561 undo->update_undo_before();
3562 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3563 // try to get asset up to date, may fail
3564 file->select_video_stream(asset, vstream);
3565 // either way use what was/is there.
3566 double framerate = asset->get_frame_rate();
3567 int width = asset->get_w();
3568 int height = asset->get_h();
3569 // must be multiple of 4 for opengl
3570 width = (width+3) & ~3; height = (height+3) & ~3;
3571 int driver = session->playback_config->vconfig->driver;
3572 int color_model = file->get_best_colormodel(asset, driver);
3573 // color_model = BC_CModels::is_yuv(color_model) ?
3574 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3575 // BC_CModels::is_float(color_model) ?
3576 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3577 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3578 // have alpha for now
3579 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3580 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3581 session->color_model = color_model;
3582 session->output_w = width;
3583 session->output_h = height;
3584 session->frame_rate = framerate;
3585 // not, asset->actual_width/actual_height
3586 asset->width = session->output_w;
3587 asset->height = session->output_h;
3588 asset->frame_rate = session->frame_rate;
3589 create_aspect_ratio(session->aspect_w, session->aspect_h,
3590 session->output_w, session->output_h);
3591 Track *track = edl->tracks->first;
3592 for( Track *next_track=0; track; track=next_track ) {
3593 next_track = track->next;
3594 if( track->data_type != TRACK_VIDEO ) continue;
3595 if( delete_tracks ) {
3596 Edit *edit = track->edits->first;
3597 for( Edit *next_edit=0; edit; edit=next_edit ) {
3598 next_edit = edit->next;
3599 if( edit->channel != vstream ||
3600 !edit->asset || !edit->asset->is_asset ||
3601 !asset->equivalent(*edit->asset,1,1,edl) )
3605 if( track->edits->first ) {
3606 track->track_w = edl->session->output_w;
3607 track->track_h = edl->session->output_h;
3609 else if( delete_tracks )
3610 edl->tracks->delete_track(track);
3613 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3615 if( !result && asset->audio_data && asset->channels > 0 ) {
3616 session->sample_rate = asset->get_sample_rate();
3617 int64_t channel_mask = 0;
3618 int astrm = !asset->video_data ? -1 :
3619 file->get_audio_for_video(vstream, astream, channel_mask);
3620 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3621 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3623 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3624 if( channels < 1 ) channels = 1;
3625 if( channels > 6 ) channels = 6;
3626 session->audio_tracks = session->audio_channels = channels;
3627 switch( channels ) {
3629 session->achannel_positions[0] = 90;
3630 session->achannel_positions[1] = 150;
3631 session->achannel_positions[2] = 30;
3632 session->achannel_positions[3] = 210;
3633 session->achannel_positions[4] = 330;
3634 session->achannel_positions[5] = 270;
3637 session->achannel_positions[0] = 180;
3638 session->achannel_positions[1] = 0;
3641 session->achannel_positions[1] = 90;
3644 if( !channels ) break;
3645 double t = 0, dt = 360./channels;
3646 for( int i=channels; --i>=0; t+=dt )
3647 session->achannel_positions[i] = int(t+0.5);
3650 remap_audio(MWindow::AUDIO_1_TO_1);
3652 if( delete_tracks ) {
3653 Track *track = edl->tracks->first;
3654 for( Track *next_track=0; track; track=next_track ) {
3655 next_track = track->next;
3656 if( track->data_type != TRACK_AUDIO ) continue;
3657 Edit *edit = track->edits->first;
3658 for( Edit *next_edit=0; edit; edit=next_edit ) {
3659 next_edit = edit->next;
3660 if( !((1<<edit->channel) & channel_mask) ||
3661 !edit->asset || !edit->asset->is_asset ||
3662 !asset->equivalent(*edit->asset,1,1,edl) )
3665 if( !track->edits->first )
3666 edl->tracks->delete_track(track);
3670 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3673 session->auto_keyframes = old_auto_keyframes;
3674 if( !result && delete_tracks > 0 ) {
3676 undo->update_undo_after(_("select asset"), LOAD_ALL);
3682 int MWindow::select_asset(int vtrack, int delete_tracks)
3684 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3686 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3687 if( !track ) return 1;
3688 Edit *edit = track->edits->first;
3689 if( !edit ) return 1;
3690 Asset *asset = edit->asset;
3691 if( !asset || !asset->is_asset ) return 1;
3692 return select_asset(asset, edit->channel, 0, delete_tracks);
3695 void MWindow::dump_plugindb(FILE *fp)
3697 if( !plugindb ) return;
3698 for(int i = 0; i < plugindb->total; i++)
3699 plugindb->get(i)->dump(fp);
3702 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
3705 double unit_position = edl->local_session->get_selectionstart(1);
3706 unit_position = patch->track->to_units(unit_position, 0);
3708 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
3709 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3712 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
3715 double unit_position = edl->local_session->get_selectionstart(1);
3716 unit_position = patch->track->to_units(unit_position, 0);
3718 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
3719 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3722 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
3725 double unit_position = edl->local_session->get_selectionstart(1);
3726 unit_position = patch->track->to_units(unit_position, 0);
3728 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
3729 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);