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;
203 channeldb_buz = new ChannelDB;
204 channeldb_v4l2jpeg = new ChannelDB;
208 keyframe_threads = 0;
228 // Need to delete brender temporary here.
231 run_lock->lock("MWindow::~MWindow");
233 //printf("MWindow::~MWindow %d\n", __LINE__);
235 gui->remote_control->deactivate();
238 gui->channel_info->stop();
240 delete create_bd; create_bd = 0;
241 delete create_dvd; create_dvd = 0;
242 delete batch_render; batch_render = 0;
243 delete render; render = 0;
245 if( commercials && !commercials->remove_user() ) commercials = 0;
247 // Save defaults for open plugins
248 plugin_gui_lock->lock("MWindow::~MWindow");
249 for(int i = 0; i < plugin_guis->size(); i++) {
250 plugin_guis->get(i)->hide_gui();
251 delete_plugin(plugin_guis->get(i));
253 plugin_gui_lock->unlock();
254 hide_keyframe_guis();
257 // Give up and go to a movie
258 // cant run valgrind if this is used
260 gui->del_keyboard_listener(
261 (int (BC_WindowBase::*)(BC_WindowBase *))
262 &MWindowGUI::keyboard_listener);
264 // release the hounds
265 if( awindow && awindow->gui ) awindow->gui->close(0);
266 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
267 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
268 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
269 if( twindow && twindow->is_running() ) twindow->close_window();
270 if( wwindow && wwindow->is_running() ) wwindow->close_window();
271 vwindows.remove_all_objects();
273 if( awindow ) awindow->join();
274 if( cwindow ) cwindow->join();
275 if( lwindow ) lwindow->join();
276 if( twindow ) twindow->join();
277 if( wwindow ) wwindow->join();
278 if( gwindow ) gwindow->join();
281 // one at a time, or nouveau chokes
282 #define close_gui(win) if( win ) { \
283 if( win->gui ) win->gui->close(0); \
291 vwindows.remove_all_objects();
296 dead_plugins->remove_all_objects();
299 keyframe_threads->remove_all_objects();
300 colormodels.remove_all_objects();
301 delete awindow; awindow = 0;
302 delete lwindow; lwindow = 0;
303 delete twindow; twindow = 0;
304 delete wwindow; wwindow = 0;
305 delete gwindow; gwindow = 0;
306 delete cwindow; cwindow = 0;
308 //delete file_server; file_server = 0; // reusable
309 delete mainindexes; mainindexes = 0;
310 delete mainprogress; mainprogress = 0;
311 delete audio_cache; audio_cache = 0; // delete the cache after the assets
312 delete video_cache; video_cache = 0; // delete the cache after the assets
313 delete frame_cache; frame_cache = 0;
314 delete wave_cache; wave_cache = 0;
315 delete plugin_guis; plugin_guis = 0;
316 delete dead_plugins; dead_plugins = 0;
317 delete keyframe_threads; keyframe_threads = 0;
318 delete undo; undo = 0;
319 delete preferences; preferences = 0;
320 delete exportedl; exportedl = 0;
321 delete session; session = 0;
322 delete defaults; defaults = 0;
323 delete assets; assets = 0;
324 delete splash_window; splash_window = 0;
325 // delete theme; theme = 0; // deleted by delete_plugins
326 if( !edl->Garbage::remove_user() ) edl = 0;
327 delete channeldb_buz;
328 delete channeldb_v4l2jpeg;
329 // This must be last thread to exit
330 delete playback_3d; playback_3d = 0;
331 delete dead_plugin_lock;
332 delete plugin_gui_lock;
333 delete vwindows_lock;
335 delete keyframe_gui_lock;
336 colormodels.remove_all_objects();
337 interlace_project_modes.remove_all_objects();
338 interlace_asset_modes.remove_all_objects();
339 interlace_asset_fixmethods.remove_all_objects();
340 sighandler->terminate();
351 void MWindow::init_error()
353 MainError::init_error(this);
356 void MWindow::finit_error()
358 MainError::finit_error();
361 void MWindow::create_defaults_path(char *string, const char *config_file)
363 // set the .bcast path
366 sprintf(string, "%s/", File::get_config_path());
367 fs.complete_path(string);
368 if(!fs.is_dir(string))
369 fs.create_dir(string);
372 strcat(string, config_file);
374 const char *MWindow::default_std()
376 char buf[BCTEXTLEN], *p = 0;
378 int fd = open(TIMEZONE_NAME, O_RDONLY);
380 int l = read(fd, buf, sizeof(buf)-1);
383 if( buf[l-1] == '\n' ) --l;
389 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
392 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
393 p += strlen(ZONEINFO_STR);
398 for( int i=0; ntsc_zones[i]; ++i ) {
399 if( !strcmp(ntsc_zones[i], p) )
406 for( int i=0; ntsc_zones[i]; ++i ) {
407 if( !strcmp(ntsc_zones[i], p) )
412 //__timezone: Seconds west of UTC. 240sec/deg
413 double tz_deg = -__timezone / 240.;
414 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
415 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
418 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
420 struct formatpresets *fpr;
422 for(fpr = &format_presets[0]; fpr->name; fpr++)
424 if(strcmp(_(fpr->name), preset) == 0)
426 session->audio_channels = fpr->audio_channels;
427 session->audio_tracks = fpr->audio_tracks;
428 session->sample_rate = fpr->sample_rate;
429 session->video_channels = fpr->video_channels;
430 session->video_tracks = fpr->video_tracks;
431 session->frame_rate = fpr->frame_rate;
432 session->output_w = fpr->output_w;
433 session->output_h = fpr->output_h;
434 session->aspect_w = fpr->aspect_w;
435 session->aspect_h = fpr->aspect_h;
436 session->interlace_mode = fpr->interlace_mode;
437 session->color_model = fpr->color_model;
443 const char *MWindow::get_preset_name(int index)
445 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
447 return _(format_presets[index].name);
451 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
453 char path[BCTEXTLEN];
454 // Use user supplied path
456 strcpy(path, config_path);
458 create_defaults_path(path, CONFIG_FILE);
460 defaults = new BC_Hash(path);
464 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
466 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
468 const char *dp = plug_dir;
469 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
470 bp = !*dp && *bp == '/' ? bp+1 : base_path;
476 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
479 FILE *fp = fopen(index_path, "r");
483 char index_line[BCTEXTLEN];
484 int index_version = -1, len = strlen(plugin_dir);
485 if( !fgets(index_line, BCTEXTLEN, fp) ||
486 sscanf(index_line, "%d", &index_version) != 1 ||
487 index_version != PLUGIN_FILE_VERSION ||
488 !fgets(index_line, BCTEXTLEN, fp) ||
489 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
490 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
492 ArrayList<PluginServer*> plugins;
493 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
494 if( index_line[0] == ';' ) continue;
495 if( index_line[0] == '#' ) continue;
496 int type = PLUGIN_TYPE_UNKNOWN;
497 char path[BCTEXTLEN], title[BCTEXTLEN];
499 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
502 PluginServer *server = 0;
504 case PLUGIN_TYPE_BUILTIN:
505 case PLUGIN_TYPE_EXECUTABLE:
506 case PLUGIN_TYPE_LADSPA: {
507 char plugin_path[BCTEXTLEN]; struct stat st;
508 sprintf(plugin_path, "%s/%s", plugin_dir, path);
509 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
512 server = new PluginServer(mwindow, plugin_path, type);
514 case PLUGIN_TYPE_FFMPEG: {
515 server = new_ffmpeg_server(mwindow, path);
518 if( !server ) continue;
519 plugins.append(server);
520 // Create plugin server from index entry
521 server->set_title(title);
522 if( server->read_table(index_line) ) {
529 ret = check_plugin_index(plugins, plugin_dir, ".");
532 add_plugins(plugins);
534 plugins.remove_all_objects();
539 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
540 const char *plug_dir, const char *plug_path)
542 char plugin_path[BCTEXTLEN];
543 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
545 fs.set_filter( "[*.plugin][*.so]" );
546 if( fs.update(plugin_path) )
549 for( int i=0; i<fs.dir_list.total; ++i ) {
550 char fs_path[BCTEXTLEN];
551 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
552 if( fs.is_dir(fs_path) ) {
553 get_plugin_path(plugin_path, plug_dir, fs_path);
554 if( check_plugin_index(plugins, plug_dir, plugin_path) )
557 else if( !plugin_exists(fs_path, plugins) )
564 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
567 plugindb = new ArrayList<PluginServer*>;
569 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
570 create_defaults_path(index_path, PLUGIN_FILE);
571 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
572 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
573 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
574 printf("init plugin index: %s\n", plugin_path);
575 FILE *fp = fopen(index_path,"w");
577 fprintf(stderr,_("MWindow::init_plugins: "
578 "can't create plugin index: %s\n"), index_path);
581 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
582 fprintf(fp, "%s\n", plugin_path);
583 init_plugin_index(mwindow, preferences, fp, plugin_path);
584 init_ffmpeg_index(mwindow, preferences, fp);
586 return load_plugin_index(mwindow, index_path, plugin_path);
589 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
591 char *path = getenv("LADSPA_PATH");
592 char ladspa_path[BCTEXTLEN];
594 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
597 for( int len=0; *path; path+=len ) {
598 char *cp = strchr(path,':');
599 len = !cp ? strlen(path) : cp-path;
600 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
601 memcpy(plugin_path, path, len); plugin_path[len] = 0;
603 char *plugin_dir = FileSystem::basepath(plugin_path);
604 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
605 create_defaults_path(index_path, LADSPA_FILE);
606 cp = index_path + strlen(index_path);
607 for( char *bp=plugin_path; *bp!=0; ++bp )
608 *cp++ = *bp=='/' ? '_' : *bp;
610 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
611 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
612 load_plugin_index(mwindow, index_path, plugin_path);
617 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
618 FILE *fp, const char *plugin_dir)
620 int idx = PLUGIN_IDS;
622 for( int i=0; i<plugindb->size(); ++i ) {
623 PluginServer *server = plugindb->get(i);
624 if( server->dir_idx >= idx )
625 idx = server->dir_idx+1;
628 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
631 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
632 const char *index_path, const char *plugin_dir)
634 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
635 strcpy(plugin_path, path); delete [] path;
636 printf("init ladspa index: %s\n", plugin_dir);
637 FILE *fp = fopen(index_path,"w");
639 fprintf(stderr,_("MWindow::init_ladspa_index: "
640 "can't create plugin index: %s\n"), index_path);
643 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
644 fprintf(fp, "%s\n", plugin_dir);
645 init_plugin_index(mwindow, preferences, fp, plugin_path);
650 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
651 const char *plug_dir, const char *plug_path, int &idx)
653 char plugin_path[BCTEXTLEN];
654 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
656 fs.set_filter( "[*.plugin][*.so]" );
657 int result = fs.update(plugin_path);
658 if( result || !fs.dir_list.total ) return;
661 for( int i=0; i<fs.dir_list.total; ++i ) {
662 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
663 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
664 get_plugin_path(path, plug_dir, fs_path);
665 if( fs.is_dir(fs_path) ) {
666 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
669 if( plugin_exists(path) ) continue;
671 if( stat(fs_path, &st) ) continue;
672 int64_t mtime = st.st_mtime;
673 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
674 result = server.open_plugin(1, preferences, 0, 0);
676 server.write_table(fp, path, vis_id, mtime);
677 server.close_plugin();
679 else if( result == PLUGINSERVER_IS_LAD ) {
682 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
683 ladspa.set_lad_index(lad_index++);
684 result = ladspa.open_plugin(1, preferences, 0, 0);
686 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
687 ladspa.close_plugin();
693 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
695 for( int i=0; i<plugins.size(); ++i )
696 plugindb->append(plugins[i]);
697 plugins.remove_all();
700 void MWindow::delete_plugins()
702 plugindb->remove_all_objects();
707 void MWindow::search_plugindb(int do_audio,
712 ArrayList<PluginServer*> &results)
715 for(int i = 0; i < MWindow::plugindb->total; i++)
717 PluginServer *current = MWindow::plugindb->get(i);
719 if(current->audio == do_audio &&
720 current->video == do_video &&
721 (current->realtime == is_realtime || is_realtime < 0) &&
722 current->transition == is_transition &&
723 current->theme == is_theme)
724 results.append(current);
727 // Alphabetize list by title
733 for(int i = 0; i < results.total - 1; i++)
735 PluginServer *value1 = results[i];
736 PluginServer *value2 = results[i + 1];
737 if(strcmp(_(value1->title), _(value2->title)) > 0)
741 results[i + 1] = value1;
747 PluginServer* MWindow::scan_plugindb(char *title,
752 // printf("MWindow::scan_plugindb data_type < 0\n");
756 for(int i = 0; i < plugindb->total; i++)
758 PluginServer *server = plugindb->get(i);
760 !strcasecmp(server->title, title) &&
762 (data_type == TRACK_AUDIO && server->audio) ||
763 (data_type == TRACK_VIDEO && server->video)))
764 return plugindb->get(i);
769 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
771 for( int i=0; i<plugins.size(); ++i )
772 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
776 int MWindow::plugin_exists(char *plugin_path)
778 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
781 void MWindow::init_preferences()
783 preferences = new Preferences;
784 preferences->load_defaults(defaults);
785 session = new MainSession(this);
786 session->load_defaults(defaults);
787 // set x11_host, screens, window_config
788 screens = session->set_default_x11_host();
789 BC_Signals::set_trap_hook(trap_hook, this);
790 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
791 BC_Signals::set_catch_intr(preferences->trap_sigintr);
792 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
793 BC_Trace::enable_locks();
796 BC_Trace::disable_locks();
798 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
801 void MWindow::clean_indexes()
806 int oldest_item = -1;
808 char string[BCTEXTLEN];
809 char string2[BCTEXTLEN];
811 // Delete extra indexes
812 fs.set_filter("*.idx");
813 fs.complete_path(preferences->index_directory);
814 fs.update(preferences->index_directory);
815 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
817 // Eliminate directories
822 for(int i = 0; i < fs.dir_list.total && !result; i++)
824 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
825 if(fs.is_dir(string))
827 delete fs.dir_list[i];
828 fs.dir_list.remove_number(i);
833 total_excess = fs.dir_list.total - preferences->index_count;
835 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
836 while(total_excess > 0)
839 for(int i = 0; i < fs.dir_list.total; i++)
841 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
843 if(i == 0 || fs.get_date(string) <= oldest)
845 oldest = fs.get_date(string);
853 fs.join_names(string,
854 preferences->index_directory,
855 fs.dir_list[oldest_item]->name);
856 //printf("MWindow::clean_indexes 1 %s\n", string);
858 perror("delete_indexes");
859 delete fs.dir_list[oldest_item];
860 fs.dir_list.remove_number(oldest_item);
862 // Remove table of contents if it exists
863 strcpy(string2, string);
864 char *ptr = strrchr(string2, '.');
867 //printf("MWindow::clean_indexes 2 %s\n", string2);
868 sprintf(ptr, ".toc");
870 sprintf(ptr, ".mkr");
879 void MWindow::init_awindow()
881 awindow = new AWindow(this);
882 awindow->create_objects();
885 void MWindow::init_gwindow()
887 gwindow = new GWindow(this);
888 gwindow->create_objects();
891 void MWindow::init_tipwindow()
894 twindow = new TipWindow(this);
898 void MWindow::show_warning(int *do_warning, const char *text)
900 if( do_warning && !*do_warning ) return;
902 wwindow = new WWindow(this);
903 wwindow->show_warning(do_warning, text);
906 int MWindow::wait_warning()
908 return wwindow->wait_result();
911 void MWindow::init_theme()
916 PluginServer *theme_plugin = 0;
917 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
918 if( plugindb->get(i)->theme &&
919 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
920 theme_plugin = plugindb->get(i);
924 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
927 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
928 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
930 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
931 if( plugindb->get(i)->theme &&
932 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
933 theme_plugin = plugindb->get(i);
938 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
942 PluginServer *plugin = new PluginServer(*theme_plugin);
943 if( plugin->open_plugin(0, preferences, 0, 0) ) {
944 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
945 theme_plugin->title);
949 theme = plugin->new_theme();
950 theme->mwindow = this;
951 strcpy(theme->path, plugin->path);
954 // Load default images & settings
955 theme->Theme::initialize();
956 // Load user images & settings
958 // Create menus with user colors
959 theme->build_menus();
964 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
967 void MWindow::init_3d()
969 playback_3d = new Playback3D(this);
970 playback_3d->create_objects();
973 void MWindow::init_edl()
976 edl->create_objects();
977 fill_preset_defaults(default_standard, edl->session);
978 edl->load_defaults(defaults);
979 edl->create_default_tracks();
980 edl->tracks->update_y_pixels(theme);
983 void MWindow::init_compositor()
985 cwindow = new CWindow(this);
986 cwindow->create_objects();
989 void MWindow::init_levelwindow()
991 lwindow = new LevelWindow(this);
992 lwindow->create_objects();
995 VWindow *MWindow::get_viewer(int start_it, int idx)
997 vwindows_lock->lock("MWindow::get_viewer");
998 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
999 if( !vwindow ) idx = vwindows.size();
1000 while( !vwindow && --idx >= 0 ) {
1001 VWindow *vwin = vwindows[idx];
1002 if( !vwin->is_running() || !vwin->get_edl() )
1006 vwindow = new VWindow(this);
1007 vwindow->load_defaults();
1008 vwindow->create_objects();
1009 vwindows.append(vwindow);
1011 vwindows_lock->unlock();
1012 if( start_it ) vwindow->start();
1016 void MWindow::init_cache()
1018 audio_cache = new CICache(preferences);
1019 video_cache = new CICache(preferences);
1020 frame_cache = new FrameCache;
1021 wave_cache = new WaveCache;
1024 void MWindow::init_channeldb()
1026 channeldb_buz->load("channeldb_buz");
1027 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1030 void MWindow::init_menus()
1032 char string[BCTEXTLEN];
1035 BC_CModels::to_text(string, BC_RGB888);
1036 colormodels.append(new ColormodelItem(string, BC_RGB888));
1037 BC_CModels::to_text(string, BC_RGBA8888);
1038 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1039 // BC_CModels::to_text(string, BC_RGB161616);
1040 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1041 // BC_CModels::to_text(string, BC_RGBA16161616);
1042 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1043 BC_CModels::to_text(string, BC_RGB_FLOAT);
1044 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1045 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1046 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1047 BC_CModels::to_text(string, BC_YUV888);
1048 colormodels.append(new ColormodelItem(string, BC_YUV888));
1049 BC_CModels::to_text(string, BC_YUVA8888);
1050 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1051 // BC_CModels::to_text(string, BC_YUV161616);
1052 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1053 // BC_CModels::to_text(string, BC_YUVA16161616);
1054 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1056 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1057 interlace_project_modes.append(new InterlacemodeItem(string, x));
1059 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1060 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1062 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1063 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1065 // Interlacing Modes
1066 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1068 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1069 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1071 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1072 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1074 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1075 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1077 // Interlacing Fixing Methods
1078 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1079 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1080 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1083 void MWindow::init_indexes()
1085 mainindexes = new MainIndexes(this);
1086 mainindexes->start_loop();
1089 void MWindow::init_gui()
1091 gui = new MWindowGUI(this);
1092 gui->lock_window("MWindow::init_gui");
1093 gui->create_objects();
1094 gui->unlock_window();
1095 gui->load_defaults(defaults);
1098 void MWindow::init_signals()
1100 sighandler = new SigHandler;
1101 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1105 void MWindow::init_render()
1107 render = new Render(this);
1108 create_bd = new CreateBD_Thread(this);
1109 create_dvd = new CreateDVD_Thread(this);
1110 batch_render = new BatchRenderThread(this);
1113 void MWindow::init_exportedl()
1115 exportedl = new ExportEDL(this);
1118 void MWindow::init_brender()
1120 if(preferences->use_brender && !brender)
1122 brender_lock->lock("MWindow::init_brender 1");
1123 brender = new BRender(this);
1124 brender->initialize();
1125 session->brender_end = 0;
1126 brender_lock->unlock();
1129 if(!preferences->use_brender && brender)
1131 brender_lock->lock("MWindow::init_brender 2");
1134 session->brender_end = 0;
1135 brender_lock->unlock();
1137 if(brender) brender->restart(edl);
1140 void MWindow::restart_brender()
1142 //printf("MWindow::restart_brender 1\n");
1143 if(brender) brender->restart(edl);
1146 void MWindow::stop_brender()
1148 if(brender) brender->stop();
1151 int MWindow::brender_available(int position)
1154 brender_lock->lock("MWindow::brender_available 1");
1157 if(brender->map_valid)
1159 brender->map_lock->lock("MWindow::brender_available 2");
1160 if(position < brender->map_size &&
1163 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1164 if(brender->map[position] == BRender::RENDERED)
1167 brender->map_lock->unlock();
1170 brender_lock->unlock();
1174 void MWindow::set_brender_range()
1176 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1177 edl->session->brender_end = edl->local_session->get_selectionend(1);
1179 if(EQUIV(edl->session->brender_end, edl->session->brender_start))
1181 edl->session->brender_end = edl->tracks->total_video_length();
1185 gui->draw_overlays(1);
1189 int MWindow::has_commercials()
1191 return theme->use_commercials;
1194 void MWindow::init_commercials()
1196 if( !commercials ) {
1197 commercials = new Commercials(this);
1198 commercial_active = 0;
1201 commercials->add_user();
1204 void MWindow::commit_commercial()
1206 if( !commercial_active ) return;
1207 commercial_active = 0;
1208 if( !commercials ) return;
1209 commercials->commitDb();
1212 void MWindow::undo_commercial()
1214 if( !commercial_active ) return;
1215 commercial_active = 0;
1216 if( !commercials ) return;
1217 commercials->undoDb();
1220 int MWindow::put_commercial()
1222 double start = edl->local_session->get_selectionstart();
1223 double end = edl->local_session->get_selectionend();
1224 if( start >= end ) return 0;
1226 const char *errmsg = 0;
1228 Tracks *tracks = edl->tracks;
1231 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1232 if( track->data_type != TRACK_VIDEO ) continue;
1233 if( !track->record ) continue;
1234 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1236 int64_t units_start = track->to_units(start,0);
1237 int64_t units_end = track->to_units(end,0);
1238 Edits *edits = track->edits;
1239 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1240 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1241 if(!edit1 && !edit2) continue; // nothing selected
1242 if(!edit2) { // edit2 beyond end of track
1243 edit2 = edits->last;
1244 units_end = edits->length();
1246 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1247 Indexable *indexable = edit1->get_source();
1248 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1251 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1252 if( track->data_type != TRACK_VIDEO ) continue;
1253 if( !track->record ) continue;
1254 int64_t units_start = track->to_units(start,0);
1255 int64_t units_end = track->to_units(end,0);
1256 Edits *edits = track->edits;
1257 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1258 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1259 if(!edit1 && !edit2) continue; // nothing selected
1260 if(!edit2) { // edit2 beyond end of track
1261 edit2 = edits->last;
1262 units_end = edits->length();
1264 Indexable *indexable = edit1->get_source();
1265 Asset *asset = (Asset *)indexable;
1266 File *file = video_cache->check_out(asset, edl);
1267 if( !file ) { errmsg = _("no file"); break; }
1268 int64_t edit_length = units_end - units_start;
1269 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1270 result = commercials->put_clip(file, edit1->channel,
1271 track->from_units(edit_start), track->from_units(edit_length));
1272 video_cache->check_in(asset);
1273 if( result ) { errmsg = _("db failed"); break; }
1276 char string[BCTEXTLEN];
1277 sprintf(string, _("put_commercial: %s"), errmsg);
1278 MainError::show_error(string);
1285 void MWindow::stop_playback(int wait)
1287 int locked = gui->get_window_lock();
1288 if( locked ) gui->unlock_window();
1290 cwindow->playback_engine->que->send_command(STOP,
1294 cwindow->playback_engine->interrupt_playback(wait);
1296 for(int i = 0; i < vwindows.size(); i++) {
1297 VWindow *vwindow = vwindows[i];
1298 if( !vwindow->is_running() ) continue;
1299 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1300 vwindow->playback_engine->interrupt_playback(wait);
1302 if( locked ) gui->lock_window("MWindow::stop_playback");
1305 int MWindow::load_filenames(ArrayList<char*> *filenames,
1307 int update_filename)
1309 ArrayList<EDL*> new_edls;
1310 ArrayList<Asset*> new_assets;
1311 ArrayList<File*> new_files;
1312 const int debug = 0;
1313 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1316 gui->start_hourglass();
1318 // Need to stop playback since tracking depends on the EDL not getting
1322 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1323 undo->update_undo_before();
1326 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1328 // Define new_edls and new_assets to load
1329 int result = 0, ftype = -1;
1330 for(int i = 0; i < filenames->size(); i++)
1333 File *new_file = new File;
1334 Asset *new_asset = new Asset(filenames->get(i));
1335 EDL *new_edl = new EDL;
1336 char string[BCTEXTLEN];
1338 new_edl->create_objects();
1339 new_edl->copy_session(edl);
1340 new_file->set_program(edl->session->program_no);
1342 sprintf(string, _("Loading %s"), new_asset->path);
1343 gui->show_message(string);
1344 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1346 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1347 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1352 // Convert media file to EDL
1354 // Warn about odd image dimensions
1355 if(new_asset->video_data &&
1356 ((new_asset->width % 2) ||
1357 (new_asset->height % 2)))
1359 char string[BCTEXTLEN];
1360 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1364 MainError::show_error(string);
1367 if(new_asset->program >= 0 &&
1368 edl->session->program_no != new_asset->program)
1370 char string[BCTEXTLEN];
1371 sprintf(string, _("%s's index was built for program number %d\n"
1372 "Playback preference is %d.\n Using program %d."),
1373 new_asset->path, new_asset->program,
1374 edl->session->program_no, new_asset->program);
1375 MainError::show_error(string);
1379 if(load_mode != LOADMODE_RESOURCESONLY)
1382 RecordLabels *labels = edl->session->label_cells ?
1383 new RecordLabels(new_file) : 0;
1385 asset_to_edl(new_edl, new_asset, labels);
1387 new_edls.append(new_edl);
1389 new_asset->Garbage::remove_user();
1395 new_assets.append(new_asset);
1399 // Set filename to nothing for assets since save EDL would overwrite them.
1400 if(load_mode == LOADMODE_REPLACE ||
1401 load_mode == LOADMODE_REPLACE_CONCATENATE)
1404 // Reset timeline position
1405 for(int i = 0; i < TOTAL_PANES; i++)
1407 new_edl->local_session->view_start[i] = 0;
1408 new_edl->local_session->track_start[i] = 0;
1416 case FILE_NOT_FOUND:
1417 sprintf(string, _("Failed to open %s"), new_asset->path);
1418 gui->show_message(string, theme->message_error);
1422 case FILE_UNRECOGNIZED_CODEC:
1425 IndexFile indexfile(this, new_asset);
1426 result = indexfile.open_index();
1429 indexfile.close_index();
1432 // Test existing EDLs
1433 for(int j = 0; result && j <= new_edls.total; j++) {
1434 Asset *old_asset = j < new_edls.total ?
1435 new_edls[j]->assets->get_asset(new_asset->path) :
1436 edl->assets->get_asset(new_asset->path);
1438 *new_asset = *old_asset;
1446 char string[BCTEXTLEN];
1448 fs.extract_name(string, new_asset->path);
1450 strcat(string, _("'s format couldn't be determined."));
1451 new_asset->audio_data = 1;
1452 new_asset->format = FILE_PCM;
1453 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1454 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1455 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1456 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1457 new_asset->signed_ = defaults->get("SIGNED_", 1);
1458 new_asset->header = defaults->get("HEADER", 0);
1460 FileFormat fwindow(this);
1461 fwindow.create_objects(new_asset, string);
1462 result = fwindow.run_window();
1465 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1466 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1467 defaults->update("AUDIO_BITS", new_asset->bits);
1468 defaults->update("BYTE_ORDER", new_asset->byte_order);
1469 defaults->update("SIGNED_", new_asset->signed_);
1470 defaults->update("HEADER", new_asset->header);
1477 // Recalculate length
1479 new_file = new File;
1480 result = new_file->open_file(preferences, new_asset, 1, 0);
1482 if(load_mode != LOADMODE_RESOURCESONLY)
1484 RecordLabels *labels = edl->session->label_cells ?
1485 new RecordLabels(new_file) : 0;
1486 asset_to_edl(new_edl, new_asset, labels);
1487 new_edls.append(new_edl);
1488 new_asset->Garbage::remove_user();
1494 new_assets.append(new_asset);
1508 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1509 xml_file.read_from_file(filenames->get(i));
1510 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1511 const char *cin_version = 0;
1512 while( !xml_file.read_tag() ) {
1513 if( xml_file.tag.title_is("EDL") ) {
1514 cin_version = xml_file.tag.get_property("VERSION");
1519 if( !cin_version ) {
1520 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1521 char string[BCTEXTLEN];
1522 sprintf(string,_("Unknown %s"), filenames->get(i));
1523 gui->show_message(string);
1527 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1528 char string[BCTEXTLEN];
1529 snprintf(string, sizeof(string),
1530 _("Warning: XML from cinelerra version %s\n"
1531 "Session data may be incompatible."), cin_version);
1532 show_warning(&preferences->warn_version, string);
1534 if(load_mode == LOADMODE_NESTED)
1536 // Load temporary EDL for nesting.
1537 EDL *nested_edl = new EDL;
1538 nested_edl->create_objects();
1539 nested_edl->set_path(filenames->get(i));
1540 nested_edl->load_xml(&xml_file, LOAD_ALL);
1541 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1542 edl_to_nested(new_edl, nested_edl);
1543 nested_edl->Garbage::remove_user();
1547 // Load EDL for pasting
1548 new_edl->load_xml(&xml_file, LOAD_ALL);
1549 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1550 test_plugins(new_edl, filenames->get(i));
1551 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1553 if(load_mode == LOADMODE_REPLACE ||
1554 load_mode == LOADMODE_REPLACE_CONCATENATE)
1556 strcpy(session->filename, filenames->get(i));
1557 strcpy(new_edl->local_session->clip_title,
1560 set_filename(new_edl->local_session->clip_title);
1564 new_edls.append(new_edl);
1570 // edls are in new_edls
1571 if( result && new_edl ) new_edl->Garbage::remove_user();
1572 // assets are copied
1573 if( new_asset ) new_asset->Garbage::remove_user();
1575 // Store for testing index
1576 new_files.append(new_file);
1579 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1582 if(!result) gui->statusbar->default_message();
1590 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1593 // Don't back up here.
1596 // For pasting, clear the active region
1597 if(load_mode == LOADMODE_PASTE ||
1598 load_mode == LOADMODE_NESTED)
1600 double start = edl->local_session->get_selectionstart();
1601 double end = edl->local_session->get_selectionend();
1602 if(!EQUIV(start, end))
1605 edl->session->labels_follow_edits,
1606 edl->session->plugins_follow_edits,
1607 edl->session->autos_follow_edits);
1610 paste_edls(&new_edls,
1614 edl->session->labels_follow_edits,
1615 edl->session->plugins_follow_edits,
1616 edl->session->autos_follow_edits,
1623 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1625 // Add new assets to EDL and schedule assets for index building.
1626 int got_indexes = 0;
1627 for(int i = 0; i < new_edls.size(); i++)
1629 EDL *new_edl = new_edls[i];
1630 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1632 mainindexes->add_next_asset(0,
1633 new_edl->nested_edls->get(j));
1635 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1640 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1641 if(new_assets.size())
1643 for(int i = 0; i < new_assets.size(); i++)
1645 Asset *new_asset = new_assets[i];
1649 for(int j = 0; j < new_files.size(); j++)
1651 new_file = new_files[j];
1652 if(!strcmp(new_file->asset->path,
1660 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1662 edl->assets->update(new_asset);
1668 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1670 // Start examining next batch of index files
1671 if(got_indexes) mainindexes->start_build();
1672 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1675 Track *track = edl->tracks->first;
1678 for(int j = 0; j < track->plugin_set.size(); j++)
1680 PluginSet *plugins = track->plugin_set[j];
1681 Plugin *plugin = plugins->get_first_plugin();
1685 if(load_mode == LOADMODE_REPLACE ||
1686 load_mode == LOADMODE_REPLACE_CONCATENATE)
1688 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1691 show_plugin(plugin);
1699 plugin = (Plugin*)plugin->next;
1703 track = track->next;
1706 // if just opening one new resource in replace mode
1707 if( ftype != FILE_IS_XML &&
1708 ( load_mode == LOADMODE_REPLACE ||
1709 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1711 edl->local_session->preview_start = 0;
1712 edl->local_session->preview_end = edl->tracks->total_playable_length();
1713 edl->local_session->loop_playback = 0;
1714 edl->local_session->set_selectionstart(0);
1715 edl->local_session->set_selectionend(0);
1720 // need to update undo before project, since mwindow is unlocked & a new load
1721 // can begin here. Should really prevent loading until we're done.
1722 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1723 undo->update_undo_after(_("load"), LOAD_ALL);
1725 for(int i = 0; i < new_edls.size(); i++)
1727 new_edls[i]->remove_user();
1729 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1731 new_edls.remove_all();
1733 for(int i = 0; i < new_assets.size(); i++)
1735 new_assets[i]->Garbage::remove_user();
1738 new_assets.remove_all();
1739 new_files.remove_all_objects();
1742 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1743 if(load_mode == LOADMODE_REPLACE ||
1744 load_mode == LOADMODE_REPLACE_CONCATENATE)
1746 session->changes_made = 0;
1750 session->changes_made = 1;
1753 gui->stop_hourglass();
1756 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1757 update_project(load_mode);
1759 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1767 void MWindow::test_plugins(EDL *new_edl, char *path)
1769 char string[BCTEXTLEN];
1771 // Do a check weather plugins exist
1772 for(Track *track = new_edl->tracks->first; track; track = track->next)
1774 for(int k = 0; k < track->plugin_set.total; k++)
1776 PluginSet *plugin_set = track->plugin_set[k];
1777 for(Plugin *plugin = (Plugin*)plugin_set->first;
1779 plugin = (Plugin*)plugin->next)
1781 if(plugin->plugin_type == PLUGIN_STANDALONE)
1783 // ok we need to find it in plugindb
1784 int plugin_found = 0;
1786 for(int j = 0; j < plugindb->size(); j++)
1788 PluginServer *server = plugindb->get(j);
1790 !strcasecmp(server->title, plugin->title) &&
1791 ((track->data_type == TRACK_AUDIO && server->audio) ||
1792 (track->data_type == TRACK_VIDEO && server->video)) &&
1793 (!server->transition))
1800 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1801 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1802 "effect", plugin->title,
1804 MainError::show_error(string);
1810 for(Edit *edit = (Edit*)track->edits->first;
1812 edit = (Edit*)edit->next)
1814 if (edit->transition)
1816 // ok we need to find transition in plugindb
1818 int transition_found = 0;
1819 for(int j = 0; j < plugindb->size(); j++)
1821 PluginServer *server = plugindb->get(j);
1823 !strcasecmp(server->title, edit->transition->title) &&
1824 ((track->data_type == TRACK_AUDIO && server->audio) ||
1825 (track->data_type == TRACK_VIDEO && server->video)) &&
1826 (server->transition))
1827 transition_found = 1;
1830 if (!transition_found)
1833 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1834 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1835 "transition", edit->transition->title,
1837 MainError::show_error(string);
1845 void MWindow::init_shm()
1847 // Fix shared memory
1848 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1850 fprintf(fd, "0x7fffffff");
1855 fd = fopen("/proc/sys/kernel/shmmax", "r");
1857 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1862 fscanf(fd, "%jd", &result);
1865 if(result < 0x7fffffff) {
1866 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1867 "you probably need to be root, or:\n"
1868 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1869 "before trying to start cinelerra.\n"
1870 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1874 void MWindow::create_objects(int want_gui,
1879 const int debug = 0;
1880 if(debug) PRINT_TRACE
1882 // For some reason, init_signals must come after show_splash or the signals won't
1885 if(debug) PRINT_TRACE
1888 if(debug) PRINT_TRACE
1891 if(debug) PRINT_TRACE
1892 default_standard = default_std();
1893 init_defaults(defaults, config_path);
1896 splash_window->operation->update(_("Initializing Plugins"));
1897 init_plugins(this, preferences);
1898 if(debug) PRINT_TRACE
1899 init_ladspa_plugins(this, preferences);
1900 if(debug) PRINT_TRACE
1902 splash_window->operation->update(_("Initializing GUI"));
1903 if(debug) PRINT_TRACE
1906 if(debug) PRINT_TRACE
1910 splash_window->operation->update(_("Initializing Fonts"));
1911 char string[BCTEXTLEN];
1912 strcpy(string, preferences->plugin_dir);
1913 strcat(string, "/" FONT_SEARCHPATH);
1914 BC_Resources::init_fontconfig(string);
1915 if(debug) PRINT_TRACE
1917 // Initialize before too much else is running
1918 // Preferences & theme are required for building MPEG table of contents
1920 // Default project created here
1922 if(debug) PRINT_TRACE
1925 if(debug) PRINT_TRACE
1930 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1932 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1933 if(session->show_vwindow)
1934 get_viewer(1, DEFAULT_VWINDOW);
1935 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1938 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1941 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1944 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1946 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1949 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1953 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1955 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1957 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1961 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1962 mainprogress = new MainProgress(this, gui);
1963 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1964 undo = new MainUndo(this);
1966 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1968 plugin_guis = new ArrayList<PluginServer*>;
1969 dead_plugins = new ArrayList<PluginServer*>;
1970 keyframe_threads = new ArrayList<KeyFrameThread*>;
1972 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1975 session->show_vwindow);
1977 // Show all vwindows
1978 // if(session->show_vwindow) {
1979 // for(int j = 0; j < vwindows.size(); j++) {
1980 // VWindow *vwindow = vwindows[j];
1981 // if( !vwindow->is_running() ) continue;
1982 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1985 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1986 // vwindow->gui->lock_window("MWindow::create_objects 1");
1987 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1988 // vwindow->gui->show_window();
1989 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1990 // vwindow->gui->unlock_window();
1995 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1997 if(session->show_cwindow)
1999 cwindow->gui->lock_window("MWindow::create_objects 1");
2000 cwindow->gui->show_window();
2001 cwindow->gui->unlock_window();
2004 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2005 if(session->show_awindow)
2007 awindow->gui->lock_window("MWindow::create_objects 1");
2008 awindow->gui->show_window();
2009 awindow->gui->unlock_window();
2012 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2013 if(session->show_lwindow)
2015 lwindow->gui->lock_window("MWindow::create_objects 1");
2016 lwindow->gui->show_window();
2017 lwindow->gui->unlock_window();
2020 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2022 (int)timer.get_difference(),
2024 if(session->show_gwindow)
2026 gwindow->gui->lock_window("MWindow::create_objects 1");
2027 gwindow->gui->show_window();
2028 gwindow->gui->unlock_window();
2031 if(debug) PRINT_TRACE
2033 gui->lock_window("MWindow::create_objects 1");
2034 gui->mainmenu->load_defaults(defaults);
2035 gui->mainmenu->update_toggles(0);
2036 gui->update_patchbay();
2037 gui->draw_canvas(0, 0);
2038 gui->draw_cursor(1);
2040 gui->raise_window();
2041 gui->unlock_window();
2043 if(debug) PRINT_TRACE
2045 if(preferences->use_tipwindow)
2047 if(debug) PRINT_TRACE
2049 gui->add_keyboard_listener(
2050 (int (BC_WindowBase::*)(BC_WindowBase *))
2051 &MWindowGUI::keyboard_listener);
2055 if(debug) PRINT_TRACE
2057 BC_WindowBase::get_resources()->vframe_shm = 1;
2061 void MWindow::show_splash()
2063 #include "data/heroine_logo9_png.h"
2064 VFrame *frame = new VFramePng(heroine_logo9_png);
2065 BC_DisplayInfo dpyi;
2066 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2067 int rr = (rw < rh ? rw : rh) / 4;
2068 splash_window = new SplashGUI(frame, rr, rr);
2069 splash_window->create_objects();
2072 void MWindow::hide_splash()
2075 delete splash_window;
2080 void MWindow::start()
2084 // vwindows[DEFAULT_VWINDOW]->start();
2095 playback_3d->start();
2101 run_lock->lock("MWindow::run");
2105 brender_lock->lock("MWindow::run 1");
2106 delete brender; brender = 0;
2107 brender_lock->unlock();
2109 interrupt_indexes();
2115 void MWindow::show_vwindow()
2117 int total_running = 0;
2118 session->show_vwindow = 1;
2120 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2121 // Raise all windows which are visible
2122 for(int j = 0; j < vwindows.size(); j++) {
2123 VWindow *vwindow = vwindows[j];
2124 if( !vwindow->is_running() ) continue;
2125 vwindow->gui->lock_window("MWindow::show_vwindow");
2126 vwindow->gui->show_window(0);
2127 vwindow->gui->raise_window();
2128 vwindow->gui->flush();
2129 vwindow->gui->unlock_window();
2133 // If no windows visible
2136 get_viewer(1, DEFAULT_VWINDOW);
2139 gui->mainmenu->show_vwindow->set_checked(1);
2142 void MWindow::show_awindow()
2144 session->show_awindow = 1;
2145 awindow->gui->lock_window("MWindow::show_awindow");
2146 awindow->gui->show_window();
2147 awindow->gui->raise_window();
2148 awindow->gui->flush();
2149 awindow->gui->unlock_window();
2150 gui->mainmenu->show_awindow->set_checked(1);
2153 char *MWindow::get_cwindow_display()
2155 char *x11_host = screens < 2 || session->window_config == 0 ?
2156 session->a_x11_host : session->b_x11_host;
2157 return *x11_host ? x11_host : 0;
2160 void MWindow::show_cwindow()
2162 session->show_cwindow = 1;
2163 cwindow->show_window();
2164 gui->mainmenu->show_cwindow->set_checked(1);
2167 void MWindow::show_gwindow()
2169 session->show_gwindow = 1;
2171 gwindow->gui->lock_window("MWindow::show_gwindow");
2172 gwindow->gui->show_window();
2173 gwindow->gui->raise_window();
2174 gwindow->gui->flush();
2175 gwindow->gui->unlock_window();
2177 gui->mainmenu->show_gwindow->set_checked(1);
2179 void MWindow::hide_gwindow()
2181 session->show_gwindow = 0;
2183 gwindow->gui->lock_window("MWindow::show_gwindow");
2184 gwindow->gui->hide_window();
2185 gwindow->gui->unlock_window();
2188 void MWindow::show_lwindow()
2190 session->show_lwindow = 1;
2191 lwindow->gui->lock_window("MWindow::show_lwindow");
2192 lwindow->gui->show_window();
2193 lwindow->gui->raise_window();
2194 lwindow->gui->flush();
2195 lwindow->gui->unlock_window();
2196 gui->mainmenu->show_lwindow->set_checked(1);
2199 int MWindow::tile_windows(int window_config)
2201 int need_reload = 0;
2202 int play_config = window_config==0 ? 0 : 1;
2203 edl->session->playback_config->load_defaults(defaults, play_config);
2204 session->default_window_positions(window_config);
2205 if( screens == 1 ) {
2206 gui->default_positions();
2207 sync_parameters(CHANGE_ALL);
2214 void MWindow::toggle_loop_playback()
2216 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2217 set_loop_boundaries();
2220 gui->draw_overlays(1);
2221 sync_parameters(CHANGE_PARAMS);
2224 //void MWindow::set_titles(int value)
2226 // edl->session->show_titles = value;
2227 // trackmovement(edl->local_session->track_start);
2230 void MWindow::set_screens(int value)
2235 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2237 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2238 edl->session->auto_keyframes = value;
2239 gui->mbuttons->edit_panel->keyframe->update(value);
2241 if(lock_mwindow) gui->unlock_window();
2243 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2244 cwindow->gui->edit_panel->keyframe->update(value);
2245 cwindow->gui->flush();
2246 if(lock_cwindow) cwindow->gui->unlock_window();
2249 void MWindow::set_auto_visibility(Autos *autos, int value)
2251 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2252 edl->session->auto_conf->plugins = value;
2253 else if( autos->autoidx >= 0 )
2254 edl->session->auto_conf->autos[autos->autoidx] = value;
2258 gui->update(0, 1, 0, 0, 0, 0, 0);
2259 gui->mainmenu->update_toggles(1);
2260 gui->unlock_window();
2261 gwindow->gui->update_toggles(1);
2262 gui->lock_window("MWindow::set_auto_visibility");
2265 void MWindow::set_keyframe_type(int mode)
2267 gui->lock_window("MWindow::set_keyframe_type");
2268 edl->local_session->floatauto_type = mode;
2269 gui->mainmenu->update_toggles(0);
2270 gui->unlock_window();
2273 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2275 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2276 edl->session->editing_mode = new_editing_mode;
2277 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2278 gui->mbuttons->edit_panel->update();
2279 gui->set_editing_mode(1);
2280 if(lock_mwindow) gui->unlock_window();
2283 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2284 cwindow->gui->edit_panel->update();
2285 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2286 if(lock_cwindow) cwindow->gui->unlock_window();
2290 void MWindow::toggle_editing_mode()
2292 int mode = edl->session->editing_mode;
2293 if( mode == EDITING_ARROW )
2294 set_editing_mode(EDITING_IBEAM, 0, 1);
2296 set_editing_mode(EDITING_ARROW, 0, 1);
2300 void MWindow::set_labels_follow_edits(int value)
2302 gui->lock_window("MWindow::set_labels_follow_edits");
2303 edl->session->labels_follow_edits = value;
2304 gui->mbuttons->edit_panel->locklabels->update(value);
2305 gui->mainmenu->labels_follow_edits->set_checked(value);
2307 gui->unlock_window();
2310 void MWindow::sync_parameters(int change_type)
2312 if( in_destructor ) return;
2314 // Sync engines which are playing back
2315 if(cwindow->playback_engine->is_playing_back)
2317 if(change_type == CHANGE_PARAMS)
2319 // TODO: block keyframes until synchronization is done
2320 cwindow->playback_engine->sync_parameters(edl);
2325 int command = cwindow->playback_engine->command->command;
2326 cwindow->playback_engine->que->send_command(STOP,
2330 // Waiting for tracking to finish would make the restart position more
2331 // accurate but it can't lock the window to stop tracking for some reason.
2332 // Not waiting for tracking gives a faster response but restart position is
2333 // only as accurate as the last tracking update.
2334 cwindow->playback_engine->interrupt_playback(0);
2335 cwindow->playback_engine->que->send_command(command,
2344 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2351 void MWindow::age_caches()
2353 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2355 // preferences->cache_size,
2356 // audio_cache->get_memory_usage(1),
2357 // video_cache->get_memory_usage(1),
2358 // frame_cache->get_memory_usage(),
2359 // wave_cache->get_memory_usage(),
2361 frame_cache->age_cache(512);
2362 wave_cache->age_cache(8192);
2364 int64_t memory_usage;
2365 int64_t prev_memory_usage = 0;
2367 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2368 while( !result && prev_memory_usage !=
2369 (memory_usage=video_cache->get_memory_usage(1)) &&
2370 memory_usage > video_size ) {
2371 video_cache->delete_oldest();
2372 prev_memory_usage = memory_usage;
2375 prev_memory_usage = 0;
2377 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2378 while( !result && prev_memory_usage !=
2379 (memory_usage=audio_cache->get_memory_usage(1)) &&
2380 memory_usage > audio_size ) {
2381 audio_cache->delete_oldest();
2382 prev_memory_usage = memory_usage;
2386 void MWindow::reset_android_remote()
2388 gui->use_android_remote(preferences->android_remote);
2392 void MWindow::show_keyframe_gui(Plugin *plugin)
2394 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2395 // Find existing thread
2396 for(int i = 0; i < keyframe_threads->size(); i++)
2398 if(keyframe_threads->get(i)->plugin == plugin)
2400 keyframe_threads->get(i)->start_window(plugin, 0);
2401 keyframe_gui_lock->unlock();
2406 // Find unused thread
2407 for(int i = 0; i < keyframe_threads->size(); i++)
2409 if(!keyframe_threads->get(i)->plugin)
2411 keyframe_threads->get(i)->start_window(plugin, 0);
2412 keyframe_gui_lock->unlock();
2417 // Create new thread
2418 KeyFrameThread *thread = new KeyFrameThread(this);
2419 keyframe_threads->append(thread);
2420 thread->start_window(plugin, 0);
2422 keyframe_gui_lock->unlock();
2429 void MWindow::show_plugin(Plugin *plugin)
2434 // Remove previously deleted plugin GUIs
2435 dead_plugin_lock->lock("MWindow::show_plugin");
2436 dead_plugins->remove_all_objects();
2437 dead_plugin_lock->unlock();
2439 //printf("MWindow::show_plugin %d\n", __LINE__);
2443 plugin_gui_lock->lock("MWindow::show_plugin");
2444 for(int i = 0; i < plugin_guis->total; i++)
2446 // Pointer comparison
2447 if(plugin_guis->get(i)->plugin == plugin)
2449 plugin_guis->get(i)->raise_window();
2456 //printf("MWindow::show_plugin 1\n");
2461 printf("MWindow::show_plugin track not defined.\n");
2463 PluginServer *server = scan_plugindb(plugin->title,
2464 plugin->track->data_type);
2466 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2467 if(server && server->uses_gui)
2469 PluginServer *gui = new PluginServer(*server);
2470 plugin_guis->append(gui);
2471 // Needs mwindow to do GUI
2472 gui->set_mwindow(this);
2473 gui->open_plugin(0, preferences, edl, plugin);
2478 plugin_gui_lock->unlock();
2479 //printf("MWindow::show_plugin %d\n", __LINE__);
2482 //printf("MWindow::show_plugin 2\n");
2485 void MWindow::hide_plugin(Plugin *plugin, int lock)
2488 // Update the toggle
2489 gui->lock_window("MWindow::hide_plugin");
2490 gui->update(0, 1, 0, 0, 0, 0, 0);
2491 gui->unlock_window();
2493 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2494 for(int i = 0; i < plugin_guis->total; i++)
2496 if(plugin_guis->get(i)->plugin == plugin)
2498 PluginServer *ptr = plugin_guis->get(i);
2499 plugin_guis->remove(ptr);
2500 if(lock) plugin_gui_lock->unlock();
2501 // Last command executed in client side close
2502 // Schedule for deletion
2509 if(lock) plugin_gui_lock->unlock();
2512 void MWindow::delete_plugin(PluginServer *plugin)
2514 dead_plugin_lock->lock("MWindow::delete_plugin");
2515 dead_plugins->append(plugin);
2516 dead_plugin_lock->unlock();
2519 void MWindow::hide_plugins()
2521 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2522 while(plugin_guis->size())
2524 PluginServer *ptr = plugin_guis->get(0);
2525 plugin_guis->remove(ptr);
2526 plugin_gui_lock->unlock();
2527 // Last command executed in client side close
2528 // Schedule for deletion
2531 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2533 plugin_gui_lock->unlock();
2535 hide_keyframe_guis();
2538 void MWindow::hide_keyframe_guis()
2540 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2541 for(int i = 0; i < keyframe_threads->size(); i++)
2543 keyframe_threads->get(i)->close_window();
2545 keyframe_gui_lock->unlock();
2548 void MWindow::hide_keyframe_gui(Plugin *plugin)
2550 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2551 for(int i = 0; i < keyframe_threads->size(); i++)
2553 if(keyframe_threads->get(i)->plugin == plugin)
2555 keyframe_threads->get(i)->close_window();
2559 keyframe_gui_lock->unlock();
2562 void MWindow::update_keyframe_guis()
2564 // Send new configuration to keyframe GUI's
2565 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2566 for(int i = 0; i < keyframe_threads->size(); i++)
2568 KeyFrameThread *ptr = keyframe_threads->get(i);
2569 if(edl->tracks->plugin_exists(ptr->plugin))
2573 ptr->close_window();
2576 keyframe_gui_lock->unlock();
2579 void MWindow::update_plugin_guis(int do_keyframe_guis)
2581 // Send new configuration to plugin GUI's
2582 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2584 for(int i = 0; i < plugin_guis->size(); i++)
2586 PluginServer *ptr = plugin_guis->get(i);
2587 if(edl->tracks->plugin_exists(ptr->plugin))
2591 // Schedule for deletion if no plugin
2592 plugin_guis->remove_number(i);
2601 // Change plugin variable if not visible
2602 Track *track = edl->tracks->first;
2605 for(int i = 0; i < track->plugin_set.size(); i++)
2607 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2611 for(int i = 0; i < plugin_guis->size(); i++)
2613 PluginServer *server = plugin_guis->get(i);
2614 if(server->plugin == plugin)
2621 if(!got_it) plugin->show = 0;
2623 plugin = (Plugin*)plugin->next;
2627 track = track->next;
2630 plugin_gui_lock->unlock();
2633 if(do_keyframe_guis) update_keyframe_guis();
2636 int MWindow::plugin_gui_open(Plugin *plugin)
2639 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2640 for(int i = 0; i < plugin_guis->total; i++)
2642 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2648 plugin_gui_lock->unlock();
2652 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2654 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2655 for(int i = 0; i < plugin_guis->total; i++)
2657 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2659 plugin_guis->get(i)->render_gui(data);
2663 plugin_gui_lock->unlock();
2666 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2668 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2669 for(int i = 0; i < plugin_guis->total; i++)
2671 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2673 plugin_guis->get(i)->render_gui(data, size);
2677 plugin_gui_lock->unlock();
2681 void MWindow::update_plugin_states()
2683 plugin_gui_lock->lock("MWindow::update_plugin_states");
2684 for(int i = 0; i < plugin_guis->total; i++)
2688 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2689 PluginServer *src_plugingui = plugin_guis->get(i);
2691 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2692 for(Track *track = edl->tracks->first;
2694 track = track->next)
2697 j < track->plugin_set.total && !result;
2700 PluginSet *plugin_set = track->plugin_set[j];
2701 for(Plugin *plugin = (Plugin*)plugin_set->first;
2703 plugin = (Plugin*)plugin->next)
2705 if(plugin == src_plugin &&
2706 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2712 // Doesn't exist anymore
2715 hide_plugin(src_plugin, 0);
2719 plugin_gui_lock->unlock();
2723 void MWindow::update_plugin_titles()
2725 for(int i = 0; i < plugin_guis->total; i++)
2727 plugin_guis->get(i)->update_title();
2731 int MWindow::asset_to_edl(EDL *new_edl,
2733 RecordLabels *labels)
2735 const int debug = 0;
2736 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2739 // Keep frame rate, sample rate, and output size unchanged.
2740 // These parameters would revert the project if VWindow displayed an asset
2741 // of different size than the project.
2742 if(new_asset->video_data)
2744 new_edl->session->video_tracks = new_asset->layers;
2747 new_edl->session->video_tracks = 0;
2749 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2755 if(new_asset->audio_data)
2757 new_edl->session->audio_tracks = new_asset->channels;
2760 new_edl->session->audio_tracks = 0;
2761 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2763 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2764 new_edl->create_default_tracks();
2765 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2766 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2770 //printf("MWindow::asset_to_edl 3\n");
2771 new_edl->insert_asset(new_asset,
2776 //printf("MWindow::asset_to_edl 3\n");
2777 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2779 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2780 if(edl->session->cursor_on_frames)
2782 double length = new_edl->tracks->total_length();
2783 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2784 new_edl->tracks->clear(length, edl_length, 1, 1);
2790 char string[BCTEXTLEN];
2792 fs.extract_name(string, new_asset->path);
2793 //printf("MWindow::asset_to_edl 3\n");
2795 strcpy(new_edl->local_session->clip_title, string);
2796 //printf("MWindow::asset_to_edl 4 %s\n", string);
2797 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2802 int MWindow::edl_to_nested(EDL *new_edl,
2806 // Keep frame rate, sample rate, and output size unchanged.
2807 // These parameters would revert the project if VWindow displayed an asset
2808 // of different size than the project.
2812 // Nest all video & audio outputs
2813 new_edl->session->video_tracks = 1;
2814 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2815 new_edl->create_default_tracks();
2819 new_edl->insert_asset(0,
2825 char string[BCTEXTLEN];
2827 fs.extract_name(string, nested_edl->path);
2828 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2830 strcpy(new_edl->local_session->clip_title, string);
2835 // Reset everything after a load.
2836 void MWindow::update_project(int load_mode)
2838 const int debug = 0;
2840 if(debug) PRINT_TRACE
2842 edl->tracks->update_y_pixels(theme);
2844 if(debug) PRINT_TRACE
2846 if(load_mode == LOADMODE_REPLACE ||
2847 load_mode == LOADMODE_REPLACE_CONCATENATE)
2852 gui->update(1, 1, 1, 1, 1, 1, 1);
2853 if(debug) PRINT_TRACE
2854 gui->unlock_window();
2856 cwindow->gui->lock_window("MWindow::update_project 1");
2857 cwindow->update(0, 0, 1, 1, 1);
2858 cwindow->gui->unlock_window();
2860 if(debug) PRINT_TRACE
2862 // Close all the vwindows
2863 if(load_mode == LOADMODE_REPLACE ||
2864 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2865 if(debug) PRINT_TRACE
2866 int first_vwindow = 0;
2867 if(session->show_vwindow) first_vwindow = 1;
2868 // Change visible windows to no source
2869 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2870 VWindow *vwindow = vwindows[i];
2871 if( !vwindow->is_running() ) continue;
2872 vwindow->change_source(-1);
2875 // Close remaining windows
2876 for(int i = first_vwindow; i < vwindows.size(); i++) {
2877 VWindow *vwindow = vwindows[i];
2878 if( !vwindow->is_running() ) continue;
2879 vwindow->close_window();
2881 if(debug) PRINT_TRACE
2883 else if(vwindows.size()) {
2884 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2885 if( vwindow->is_running() ) {
2886 vwindow->gui->lock_window("MWindow::update_project");
2888 vwindow->gui->unlock_window();
2892 if(debug) PRINT_TRACE
2893 cwindow->gui->lock_window("MWindow::update_project 2");
2894 cwindow->gui->timebar->update(0);
2895 cwindow->gui->unlock_window();
2897 if(debug) PRINT_TRACE
2898 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2903 awindow->gui->async_update_assets();
2904 if(debug) PRINT_TRACE
2906 gui->lock_window("MWindow::update_project");
2908 if(debug) PRINT_TRACE
2911 void MWindow::remove_indexfile(Indexable *indexable)
2913 if( !indexable->is_asset ) return;
2914 Asset *asset = (Asset *)indexable;
2916 IndexFile::delete_index(preferences, asset, ".toc");
2917 IndexFile::delete_index(preferences, asset, ".idx");
2918 IndexFile::delete_index(preferences, asset, ".mkr");
2921 void MWindow::rebuild_indices()
2923 for(int i = 0; i < session->drag_assets->total; i++)
2925 Indexable *indexable = session->drag_assets->get(i);
2926 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2927 remove_indexfile(indexable);
2928 // Schedule index build
2929 IndexState *index_state = indexable->index_state;
2930 index_state->index_status = INDEX_NOTTESTED;
2931 if( indexable->is_asset ) {
2932 Asset *asset = (Asset *)indexable;
2933 if( asset->format != FILE_PCM )
2934 asset->reset_audio();
2935 asset->reset_video();
2937 mainindexes->add_next_asset(0, indexable);
2939 mainindexes->start_build();
2943 void MWindow::save_backup()
2947 edl->set_path(session->filename);
2948 char backup_path[BCTEXTLEN];
2949 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2950 File::get_config_path(), BACKUP_FILE);
2951 edl->save_xml(&file, backup_path, 0, 0);
2952 file.terminate_string();
2954 fs.complete_path(backup_path);
2956 if(file.write_to_file(backup_path))
2959 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
2960 gui->show_message(string2);
2964 void MWindow::load_backup()
2966 ArrayList<char*> path_list;
2967 path_list.set_array_delete();
2969 char backup_path[BCTEXTLEN];
2970 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2971 File::get_config_path(), BACKUP_FILE);
2973 fs.complete_path(backup_path);
2975 path_list.append(out_path = new char[strlen(backup_path) + 1]);
2976 strcpy(out_path, backup_path);
2978 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2979 edl->local_session->clip_title[0] = 0;
2980 // This is unique to backups since the path of the backup is different than the
2981 // path of the project.
2982 set_filename(edl->path);
2983 path_list.remove_all_objects();
2987 static inline int gcd(int m, int n)
2990 if( m < n ) { r = m; m = n; n = r; }
2991 while( (r = m % n) != 0 ) { m = n; n = r; }
2995 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2998 if(!width || !height) return 1;
2999 if( width == 720 && (height == 480 || height == 576) ) {
3000 w = 4; h = 3; return 0; // for NTSC and PAL
3002 double ar = (double)width / height;
3003 // square-ish pixels
3004 if( EQUIV(ar, 1.0000) ) return 0;
3005 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3006 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3007 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3008 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3009 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3010 int ww = width, hh = height;
3011 // numerator, denominator must be under mx
3012 int mx = 255, n = gcd(ww, hh);
3013 if( n > 1 ) { ww /= n; hh /= n; }
3014 // search near height in case extra/missing lines
3015 if( ww >= mx || hh >= mx ) {
3016 double err = height; // +/- 2 percent height
3017 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3018 int iw = width, ih = height+i;
3019 if( (n=gcd(iw, ih)) > 1 ) {
3020 int u = iw/n; if( u >= mx ) continue;
3021 int v = ih/n; if( v >= mx ) continue;
3022 double r = (double) u/v, er = fabs(ar-r);
3023 if( er >= err ) continue;
3024 err = er; ww = u; hh = v;
3033 void MWindow::reset_caches()
3035 frame_cache->remove_all();
3036 wave_cache->remove_all();
3037 audio_cache->remove_all();
3038 video_cache->remove_all();
3039 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3040 cwindow->playback_engine->audio_cache->remove_all();
3041 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3042 cwindow->playback_engine->video_cache->remove_all();
3044 for(int i = 0; i < vwindows.size(); i++) {
3045 VWindow *vwindow = vwindows[i];
3046 if( !vwindow->is_running() ) continue;
3047 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3048 vwindow->playback_engine->audio_cache->remove_all();
3049 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3050 vwindow->playback_engine->video_cache->remove_all();
3054 void MWindow::remove_asset_from_caches(Asset *asset)
3056 gui->resource_thread->get_video_source(0);
3057 gui->resource_thread->get_audio_source(0);
3058 frame_cache->remove_asset(asset);
3059 wave_cache->remove_asset(asset);
3060 audio_cache->delete_entry(asset);
3061 video_cache->delete_entry(asset);
3062 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3063 cwindow->playback_engine->audio_cache->delete_entry(asset);
3064 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3065 cwindow->playback_engine->video_cache->delete_entry(asset);
3066 for(int i = 0; i < vwindows.size(); i++) {
3067 VWindow *vwindow = vwindows[i];
3068 if( !vwindow->is_running() ) continue;
3069 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3070 vwindow->playback_engine->audio_cache->delete_entry(asset);
3071 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3072 vwindow->playback_engine->video_cache->delete_entry(asset);
3077 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3078 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3080 for(int i = 0; i < session->drag_assets->total; i++) {
3081 Indexable *indexable = session->drag_assets->get(i);
3082 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3085 // Remove from VWindow.
3086 for(int i = 0; i < session->drag_clips->total; i++) {
3087 for(int j = 0; j < vwindows.size(); j++) {
3088 VWindow *vwindow = vwindows[j];
3089 if( !vwindow->is_running() ) continue;
3090 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3091 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3092 vwindow->delete_source(1, 1);
3093 vwindow->gui->unlock_window();
3098 for(int i = 0; i < session->drag_assets->size(); i++) {
3099 for(int j = 0; j < vwindows.size(); j++) {
3100 VWindow *vwindow = vwindows[j];
3101 if( !vwindow->is_running() ) continue;
3102 if(session->drag_assets->get(i) == vwindow->get_source()) {
3103 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3104 vwindow->delete_source(1, 1);
3105 vwindow->gui->unlock_window();
3110 for(int i = 0; i < session->drag_assets->size(); i++) {
3111 Indexable *indexable = session->drag_assets->get(i);
3112 remove_indexfile(indexable);
3115 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3116 if(push_undo) undo->update_undo_before();
3117 if(drag_assets) edl->remove_from_project(drag_assets);
3118 if(drag_clips) edl->remove_from_project(session->drag_clips);
3119 if(redraw) save_backup();
3120 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3125 gui->lock_window("MWindow::remove_assets_from_project 3");
3133 gui->unlock_window();
3135 // Removes from playback here
3136 sync_parameters(CHANGE_ALL);
3139 awindow->gui->async_update_assets();
3142 void MWindow::remove_assets_from_disk()
3145 for(int i = 0; i < session->drag_assets->total; i++)
3147 remove(session->drag_assets->get(i)->path);
3150 remove_assets_from_project(1,
3152 session->drag_assets,
3153 session->drag_clips);
3156 void MWindow::dump_plugins(FILE *fp)
3158 if( !plugindb ) return;
3159 for(int i = 0; i < plugindb->total; i++)
3161 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3162 " synth=%d transition=%d theme=%d %s\n",
3163 plugindb->get(i)->plugin_type,
3164 plugindb->get(i)->audio,
3165 plugindb->get(i)->video,
3166 plugindb->get(i)->realtime,
3167 plugindb->get(i)->multichannel,
3168 plugindb->get(i)->get_synthesis(),
3169 plugindb->get(i)->transition,
3170 plugindb->get(i)->theme,
3171 plugindb->get(i)->title);
3175 void MWindow::dump_edl(FILE *fp)
3181 void MWindow::dump_undo(FILE *fp)
3187 void MWindow::dump_exe(FILE *fp)
3189 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3190 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3192 int ret = -1, n = 100;
3193 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3194 exe_path[len] = 0; strcpy(proc_path, exe_path);
3197 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3200 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3201 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3202 struct tm *tm = localtime(&st.st_mtime);
3204 strftime(mtime, sizeof(mtime), "%F %T", tm);
3205 fprintf(fp,"mtime: %s\n", mtime);
3207 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3208 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3211 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3212 int64_t maxsz = 1024*pagsz;
3213 int64_t size = st.st_size, pos = 0;
3215 while( (bfrsz = size-pos) > 0 ) {
3216 if( bfrsz > maxsz ) bfrsz = maxsz;
3217 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3218 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3219 if( bfr == MAP_FAILED ) break;
3220 sha1.addBytes(bfr, bfrsz);
3225 ret = pos < size ? EIO : 0;
3226 fprintf(fp, "SHA1: ");
3227 uint8_t digest[20]; sha1.computeHash(digest);
3228 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3229 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3230 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3234 void MWindow::trap_hook(FILE *fp, void *vp)
3236 MWindow *mwindow = (MWindow *)vp;
3237 // fprintf(fp, "\nPLUGINS:\n");
3238 // mwindow->dump_plugins(fp);
3239 fprintf(fp, "\nEDL:\n");
3240 mwindow->dump_edl(fp);
3241 fprintf(fp, "\nUNDO:\n");
3242 mwindow->dump_undo(fp);
3243 fprintf(fp, "\nEXE:\n");
3244 mwindow->dump_exe(fp);
3252 int MWindow::save_defaults()
3254 gui->save_defaults(defaults);
3255 edl->save_defaults(defaults);
3256 session->save_defaults(defaults);
3257 preferences->save_defaults(defaults);
3259 for(int i = 0; i < plugin_guis->total; i++)
3261 // Pointer comparison
3262 plugin_guis->get(i)->save_defaults();
3264 awindow->save_defaults(defaults);
3270 int MWindow::run_script(FileXML *script)
3272 int result = 0, result2 = 0;
3273 while(!result && !result2)
3275 result = script->read_tag();
3278 if(script->tag.title_is("new_project"))
3280 // Run new in immediate mode.
3281 // gui->mainmenu->new_project->run_script(script);
3284 if(script->tag.title_is("record"))
3286 // Run record as a thread. It is a terminal command.
3288 // Will read the complete scipt file without letting record read it if not
3294 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3301 // ================================= synchronization
3304 int MWindow::interrupt_indexes()
3306 mainprogress->cancelled = 1;
3307 mainindexes->interrupt_build();
3313 void MWindow::next_time_format()
3315 switch(edl->session->time_format)
3317 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3318 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3319 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3320 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3321 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3322 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3323 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3326 time_format_common();
3329 void MWindow::prev_time_format()
3331 switch(edl->session->time_format)
3333 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3334 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3335 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3336 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3337 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3338 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3339 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3342 time_format_common();
3345 void MWindow::time_format_common()
3347 gui->lock_window("MWindow::next_time_format");
3348 gui->redraw_time_dependancies();
3351 char string[BCTEXTLEN], string2[BCTEXTLEN];
3352 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3353 gui->show_message(string);
3355 gui->unlock_window();
3359 int MWindow::set_filename(const char *filename)
3361 if( filename != session->filename )
3362 strcpy(session->filename, filename);
3363 if( filename != edl->path )
3364 strcpy(edl->path, filename);
3368 if(filename[0] == 0)
3370 gui->set_title(PROGRAM_NAME);
3375 char string[BCTEXTLEN], string2[BCTEXTLEN];
3376 dir.extract_name(string, filename);
3377 sprintf(string2, PROGRAM_NAME ": %s", string);
3378 gui->set_title(string2);
3391 int MWindow::set_loop_boundaries()
3393 double start = edl->local_session->get_selectionstart();
3394 double end = edl->local_session->get_selectionend();
3402 if(edl->tracks->total_length())
3405 end = edl->tracks->total_length();
3412 if(edl->local_session->loop_playback && start != end)
3414 edl->local_session->loop_start = start;
3415 edl->local_session->loop_end = end;
3426 int MWindow::reset_meters()
3428 cwindow->gui->lock_window("MWindow::reset_meters 1");
3429 cwindow->gui->meters->reset_meters();
3430 cwindow->gui->unlock_window();
3432 for(int j = 0; j < vwindows.size(); j++) {
3433 VWindow *vwindow = vwindows[j];
3434 if( !vwindow->is_running() ) continue;
3435 vwindow->gui->lock_window("MWindow::reset_meters 2");
3436 vwindow->gui->meters->reset_meters();
3437 vwindow->gui->unlock_window();
3440 lwindow->gui->lock_window("MWindow::reset_meters 3");
3441 lwindow->gui->panel->reset_meters();
3442 lwindow->gui->unlock_window();
3444 gui->lock_window("MWindow::reset_meters 4");
3445 gui->reset_meters();
3446 gui->unlock_window();
3451 void MWindow::resync_guis()
3455 gui->lock_window("MWindow::resync_guis");
3456 gui->update(1, 1, 1, 1, 1, 1, 0);
3457 gui->unlock_window();
3459 cwindow->gui->lock_window("MWindow::resync_guis");
3460 cwindow->gui->resize_event(cwindow->gui->get_w(),
3461 cwindow->gui->get_h());
3462 int channels = edl->session->audio_channels;
3463 cwindow->gui->meters->set_meters(channels, 1);
3464 cwindow->gui->flush();
3465 cwindow->gui->unlock_window();
3467 for(int i = 0; i < vwindows.size(); i++) {
3468 VWindow *vwindow = vwindows[i];
3469 if( !vwindow->is_running() ) continue;
3470 vwindow->gui->lock_window("MWindow::resync_guis");
3471 vwindow->gui->resize_event(vwindow->gui->get_w(),
3472 vwindow->gui->get_h());
3473 vwindow->gui->meters->set_meters(channels, 1);
3474 vwindow->gui->flush();
3475 vwindow->gui->unlock_window();
3478 lwindow->gui->lock_window("MWindow::resync_guis");
3479 lwindow->gui->panel->set_meters(channels, 1);
3480 lwindow->gui->flush();
3481 lwindow->gui->unlock_window();
3484 if(((edl->session->output_w % 4) ||
3485 (edl->session->output_h % 4)) &&
3486 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3488 MainError::show_error(
3489 _("This project's dimensions are not multiples of 4 so\n"
3490 "it can't be rendered by OpenGL."));
3495 sync_parameters(CHANGE_ALL);
3498 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3500 File *file = new File;
3501 EDLSession *session = edl->session;
3502 double old_framerate = session->frame_rate;
3503 double old_samplerate = session->sample_rate;
3504 int old_auto_keyframes = session->auto_keyframes;
3505 session->auto_keyframes = 0;
3506 int result = file->open_file(preferences, asset, 1, 0);
3507 if( !result && delete_tracks > 0 )
3508 undo->update_undo_before();
3509 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3510 // try to get asset up to date, may fail
3511 file->select_video_stream(asset, vstream);
3512 // either way use what was/is there.
3513 double framerate = asset->get_frame_rate();
3514 int width = asset->get_w();
3515 int height = asset->get_h();
3516 // must be multiple of 4 for opengl
3517 width = (width+3) & ~3; height = (height+3) & ~3;
3518 int driver = session->playback_config->vconfig->driver;
3519 int color_model = file->get_best_colormodel(asset, driver);
3520 // color_model = BC_CModels::is_yuv(color_model) ?
3521 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3522 // BC_CModels::is_float(color_model) ?
3523 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3524 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3525 // have alpha for now
3526 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3527 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3528 session->color_model = color_model;
3529 session->output_w = width;
3530 session->output_h = height;
3531 session->frame_rate = framerate;
3532 // not, asset->actual_width/actual_height
3533 asset->width = session->output_w;
3534 asset->height = session->output_h;
3535 asset->frame_rate = session->frame_rate;
3536 create_aspect_ratio(session->aspect_w, session->aspect_h,
3537 session->output_w, session->output_h);
3538 Track *track = edl->tracks->first;
3539 for( Track *next_track=0; track; track=next_track ) {
3540 next_track = track->next;
3541 if( track->data_type != TRACK_VIDEO ) continue;
3542 if( delete_tracks ) {
3543 Edit *edit = track->edits->first;
3544 for( Edit *next_edit=0; edit; edit=next_edit ) {
3545 next_edit = edit->next;
3546 if( edit->channel != vstream ||
3547 !edit->asset || !edit->asset->is_asset ||
3548 !asset->equivalent(*edit->asset,1,1,edl) )
3552 if( track->edits->first ) {
3553 track->track_w = edl->session->output_w;
3554 track->track_h = edl->session->output_h;
3556 else if( delete_tracks )
3557 edl->tracks->delete_track(track);
3559 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3561 if( !result && asset->audio_data && asset->channels > 0 ) {
3562 session->sample_rate = asset->get_sample_rate();
3563 int64_t channel_mask = 0;
3564 int astrm = !asset->video_data ? -1 :
3565 file->get_audio_for_video(vstream, astream, channel_mask);
3566 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3567 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3569 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3570 if( channels < 1 ) channels = 1;
3571 if( channels > 6 ) channels = 6;
3572 session->audio_tracks = session->audio_channels = channels;
3573 switch( channels ) {
3575 session->achannel_positions[0] = 90;
3576 session->achannel_positions[1] = 150;
3577 session->achannel_positions[2] = 30;
3578 session->achannel_positions[3] = 210;
3579 session->achannel_positions[4] = 330;
3580 session->achannel_positions[5] = 270;
3583 session->achannel_positions[0] = 180;
3584 session->achannel_positions[1] = 0;
3587 session->achannel_positions[1] = 90;
3590 if( !channels ) break;
3591 double t = 0, dt = 360./channels;
3592 for( int i=channels; --i>=0; t+=dt )
3593 session->achannel_positions[i] = int(t+0.5);
3596 remap_audio(MWindow::AUDIO_1_TO_1);
3598 if( delete_tracks ) {
3599 Track *track = edl->tracks->first;
3600 for( Track *next_track=0; track; track=next_track ) {
3601 next_track = track->next;
3602 if( track->data_type != TRACK_AUDIO ) continue;
3603 Edit *edit = track->edits->first;
3604 for( Edit *next_edit=0; edit; edit=next_edit ) {
3605 next_edit = edit->next;
3606 if( !((1<<edit->channel) & channel_mask) ||
3607 !edit->asset || !edit->asset->is_asset ||
3608 !asset->equivalent(*edit->asset,1,1,edl) )
3611 if( !track->edits->first )
3612 edl->tracks->delete_track(track);
3616 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3619 session->auto_keyframes = old_auto_keyframes;
3620 if( !result && delete_tracks > 0 ) {
3622 undo->update_undo_after(_("select asset"), LOAD_ALL);
3628 int MWindow::select_asset(int vtrack, int delete_tracks)
3630 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3632 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3633 if( !track ) return 1;
3634 Edit *edit = track->edits->first;
3635 if( !edit ) return 1;
3636 Asset *asset = edit->asset;
3637 if( !asset || !asset->is_asset ) return 1;
3638 return select_asset(asset, edit->channel, 0, delete_tracks);
3641 void MWindow::dump_plugindb(FILE *fp)
3643 if( !plugindb ) return;
3644 for(int i = 0; i < plugindb->total; i++)
3645 plugindb->get(i)->dump(fp);
3648 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
3651 double unit_position = edl->local_session->get_selectionstart(1);
3652 unit_position = patch->track->to_units(unit_position, 0);
3654 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
3655 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3658 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
3661 double unit_position = edl->local_session->get_selectionstart(1);
3662 unit_position = patch->track->to_units(unit_position, 0);
3664 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
3665 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3668 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
3671 double unit_position = edl->local_session->get_selectionstart(1);
3672 unit_position = patch->track->to_units(unit_position, 0);
3674 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
3675 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);