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
23 #include "audioalsa.h"
25 #include "awindowgui.h"
27 #include "batchrender.h"
28 #include "bcdisplayinfo.h"
29 #include "bcsignals.h"
35 #include "channeldb.h"
36 #include "channelinfo.h"
38 #include "bccmodels.h"
39 #include "commercials.h"
40 #include "cplayback.h"
42 #include "cwindowgui.h"
44 #include "cwindowtool.h"
46 #include "devicedvbinput.inc"
47 #include "dvdcreate.h"
48 #include "editpanel.h"
50 #include "edlsession.h"
52 #include "fileformat.h"
54 #include "filesystem.h"
56 #include "framecache.h"
58 #include "gwindowgui.h"
59 #include "keyframegui.h"
60 #include "indexfile.h"
61 #include "interlacemodes.h"
63 #include "levelwindowgui.h"
64 #include "levelwindow.h"
65 #include "loadfile.inc"
66 #include "localsession.h"
67 #include "maincursor.h"
68 #include "mainerror.h"
69 #include "mainindexes.h"
71 #include "mainprogress.h"
72 #include "mainsession.h"
76 #include "mwindowgui.h"
78 #include "nestededls.h"
81 #include "playback3d.h"
82 #include "playbackengine.h"
84 #include "pluginserver.h"
85 #include "pluginset.h"
86 #include "preferences.h"
88 #include "recordmonitor.h"
89 #include "recordlabel.h"
90 #include "removefile.h"
92 #include "resourcethread.h"
93 #include "samplescroll.h"
95 #include "sighandler.h"
96 #include "splashgui.h"
97 #include "statusbar.h"
99 #include "threadloader.h"
101 #include "tipwindow.h"
102 #include "trackcanvas.h"
104 #include "tracking.h"
105 #include "trackscroll.h"
107 #include "transition.h"
108 #include "transportque.h"
110 #include "versioninfo.h"
111 #include "videodevice.inc"
112 #include "videowindow.h"
113 #include "vplayback.h"
114 #include "vwindowgui.h"
116 #include "wavecache.h"
119 #include "exportedl.h"
121 #include "defaultformats.h"
122 #include "ntsczones.h"
129 #include <sys/types.h>
130 #include <sys/stat.h>
131 #include <sys/time.h>
132 #include <sys/mman.h>
143 // Hack for libdv to remove glib dependancy
146 // g_log (const char *log_domain,
148 // const char *format,
154 // g_logv (const char *log_domain,
156 // const char *format,
166 ArrayList<PluginServer*>* MWindow::plugindb = 0;
167 Commercials* MWindow::commercials = 0;
173 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
174 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
175 vwindows_lock = new Mutex("MWindow::vwindows_lock");
176 brender_lock = new Mutex("MWindow::brender_lock");
177 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
185 commercial_active = 0;
196 channeldb_buz = new ChannelDB;
197 channeldb_v4l2jpeg = new ChannelDB;
201 keyframe_threads = 0;
221 // Need to delete brender temporary here.
227 //printf("MWindow::~MWindow %d\n", __LINE__);
229 gui->remote_control->deactivate();
232 gui->channel_info->stop();
234 brender_lock->lock("MWindow::quit");
235 delete brender; brender = 0;
236 brender_lock->unlock();
237 delete create_bd; create_bd = 0;
238 delete create_dvd; create_dvd = 0;
239 delete batch_render; batch_render = 0;
240 delete render; render = 0;
242 if( commercials && !commercials->remove_user() ) commercials = 0;
244 // Save defaults for open plugins
245 plugin_gui_lock->lock("MWindow::~MWindow");
246 for(int i = 0; i < plugin_guis->size(); i++) {
247 plugin_guis->get(i)->hide_gui();
248 delete_plugin(plugin_guis->get(i));
250 plugin_gui_lock->unlock();
251 hide_keyframe_guis();
254 // Give up and go to a movie
255 // cant run valgrind if this is used
257 gui->del_keyboard_listener(
258 (int (BC_WindowBase::*)(BC_WindowBase *))
259 &MWindowGUI::keyboard_listener);
261 // release the hounds
262 if( awindow && awindow->gui ) awindow->gui->close(0);
263 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
264 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
265 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
266 if( twindow && twindow->is_running() ) twindow->close_window();
267 if( wwindow && wwindow->is_running() ) wwindow->close_window();
268 vwindows.remove_all_objects();
270 if( awindow ) awindow->join();
271 if( cwindow ) cwindow->join();
272 if( lwindow ) lwindow->join();
273 if( twindow ) twindow->join();
274 if( wwindow ) wwindow->join();
275 if( gwindow ) gwindow->join();
278 // one at a time, or nouveau chokes
279 #define close_gui(win) if( win ) { \
280 if( win->gui ) win->gui->close(0); \
288 vwindows.remove_all_objects();
293 dead_plugins->remove_all_objects();
296 keyframe_threads->remove_all_objects();
297 colormodels.remove_all_objects();
298 delete awindow; awindow = 0;
299 delete lwindow; lwindow = 0;
300 delete twindow; twindow = 0;
301 delete wwindow; wwindow = 0;
302 delete gwindow; gwindow = 0;
303 delete cwindow; cwindow = 0;
305 //delete file_server; file_server = 0; // reusable
306 delete mainindexes; mainindexes = 0;
307 delete mainprogress; mainprogress = 0;
308 delete audio_cache; audio_cache = 0; // delete the cache after the assets
309 delete video_cache; video_cache = 0; // delete the cache after the assets
310 delete frame_cache; frame_cache = 0;
311 delete wave_cache; wave_cache = 0;
312 delete plugin_guis; plugin_guis = 0;
313 delete dead_plugins; dead_plugins = 0;
314 delete keyframe_threads; keyframe_threads = 0;
315 delete undo; undo = 0;
316 delete preferences; preferences = 0;
317 delete exportedl; exportedl = 0;
318 delete session; session = 0;
319 delete defaults; defaults = 0;
320 delete assets; assets = 0;
321 delete splash_window; splash_window = 0;
322 // delete theme; theme = 0; // deleted by delete_plugins
323 if( !edl->Garbage::remove_user() ) edl = 0;
324 delete channeldb_buz;
325 delete channeldb_v4l2jpeg;
326 // This must be last thread to exit
327 delete playback_3d; playback_3d = 0;
328 delete dead_plugin_lock;
329 delete plugin_gui_lock;
330 delete vwindows_lock;
332 delete keyframe_gui_lock;
333 colormodels.remove_all_objects();
334 interlace_project_modes.remove_all_objects();
335 interlace_asset_modes.remove_all_objects();
336 interlace_asset_fixmethods.remove_all_objects();
337 sighandler->terminate();
342 void MWindow::quit(int unlock)
344 if(unlock) gui->unlock_window();
347 brender_lock->lock("MWindow::quit");
348 delete brender; brender = 0;
349 brender_lock->unlock();
355 if(unlock) gui->lock_window("MWindow::quit");
358 void MWindow::init_error()
360 MainError::init_error(this);
363 void MWindow::finit_error()
365 MainError::finit_error();
368 void MWindow::create_defaults_path(char *string, const char *config_file)
370 // set the .bcast path
373 sprintf(string, "%s/", File::get_config_path());
374 fs.complete_path(string);
375 if(!fs.is_dir(string))
376 fs.create_dir(string);
379 strcat(string, config_file);
381 const char *MWindow::default_std()
383 char buf[BCTEXTLEN], *p = 0;
385 int fd = open(TIMEZONE_NAME, O_RDONLY);
387 int l = read(fd, buf, sizeof(buf)-1);
390 if( buf[l-1] == '\n' ) --l;
396 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
399 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
400 p += strlen(ZONEINFO_STR);
405 for( int i=0; ntsc_zones[i]; ++i ) {
406 if( !strcmp(ntsc_zones[i], p) )
413 for( int i=0; ntsc_zones[i]; ++i ) {
414 if( !strcmp(ntsc_zones[i], p) )
419 //__timezone: Seconds west of UTC. 240sec/deg
420 double tz_deg = -__timezone / 240.;
421 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
422 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
425 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
427 struct formatpresets *fpr;
429 for(fpr = &format_presets[0]; fpr->name; fpr++)
431 if(strcmp(_(fpr->name), preset) == 0)
433 session->audio_channels = fpr->audio_channels;
434 session->audio_tracks = fpr->audio_tracks;
435 session->sample_rate = fpr->sample_rate;
436 session->video_channels = fpr->video_channels;
437 session->video_tracks = fpr->video_tracks;
438 session->frame_rate = fpr->frame_rate;
439 session->output_w = fpr->output_w;
440 session->output_h = fpr->output_h;
441 session->aspect_w = fpr->aspect_w;
442 session->aspect_h = fpr->aspect_h;
443 session->interlace_mode = fpr->interlace_mode;
444 session->color_model = fpr->color_model;
450 const char *MWindow::get_preset_name(int index)
452 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
454 return _(format_presets[index].name);
458 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
460 char path[BCTEXTLEN];
461 // Use user supplied path
463 strcpy(path, config_path);
465 create_defaults_path(path, CONFIG_FILE);
467 defaults = new BC_Hash(path);
471 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
473 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
475 const char *dp = plug_dir;
476 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
477 bp = !*dp && *bp == '/' ? bp+1 : base_path;
483 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
486 FILE *fp = fopen(index_path, "r");
490 char index_line[BCTEXTLEN];
491 int index_version = -1, len = strlen(plugin_dir);
492 if( !fgets(index_line, BCTEXTLEN, fp) ||
493 sscanf(index_line, "%d", &index_version) != 1 ||
494 index_version != PLUGIN_FILE_VERSION ||
495 !fgets(index_line, BCTEXTLEN, fp) ||
496 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
497 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
499 ArrayList<PluginServer*> plugins;
500 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
501 if( index_line[0] == ';' ) continue;
502 if( index_line[0] == '#' ) continue;
503 int type = PLUGIN_TYPE_UNKNOWN;
504 char path[BCTEXTLEN], title[BCTEXTLEN];
506 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
509 PluginServer *server = 0;
511 case PLUGIN_TYPE_BUILTIN:
512 case PLUGIN_TYPE_EXECUTABLE:
513 case PLUGIN_TYPE_LADSPA: {
514 char plugin_path[BCTEXTLEN]; struct stat st;
515 sprintf(plugin_path, "%s/%s", plugin_dir, path);
516 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
519 server = new PluginServer(mwindow, plugin_path, type);
521 case PLUGIN_TYPE_FFMPEG: {
522 server = new_ffmpeg_server(mwindow, path);
525 if( !server ) continue;
526 plugins.append(server);
527 // Create plugin server from index entry
528 server->set_title(title);
529 if( server->read_table(index_line) ) {
536 ret = check_plugin_index(plugins, plugin_dir, ".");
539 add_plugins(plugins);
541 plugins.remove_all_objects();
546 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
547 const char *plug_dir, const char *plug_path)
549 char plugin_path[BCTEXTLEN];
550 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
552 fs.set_filter( "[*.plugin][*.so]" );
553 if( fs.update(plugin_path) )
556 for( int i=0; i<fs.dir_list.total; ++i ) {
557 char fs_path[BCTEXTLEN];
558 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
559 if( fs.is_dir(fs_path) ) {
560 get_plugin_path(plugin_path, plug_dir, fs_path);
561 if( check_plugin_index(plugins, plug_dir, plugin_path) )
564 else if( !plugin_exists(fs_path, plugins) )
571 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
574 plugindb = new ArrayList<PluginServer*>;
576 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
577 create_defaults_path(index_path, PLUGIN_FILE);
578 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
579 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
580 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
581 printf("init plugin index: %s\n", plugin_path);
582 FILE *fp = fopen(index_path,"w");
584 fprintf(stderr,_("MWindow::init_plugins: "
585 "can't create plugin index: %s\n"), index_path);
588 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
589 fprintf(fp, "%s\n", plugin_path);
590 init_plugin_index(mwindow, preferences, fp, plugin_path);
591 init_ffmpeg_index(mwindow, preferences, fp);
593 return load_plugin_index(mwindow, index_path, plugin_path);
596 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
598 char *path = getenv("LADSPA_PATH");
599 char ladspa_path[BCTEXTLEN];
601 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
604 for( int len=0; *path; path+=len ) {
605 char *cp = strchr(path,':');
606 len = !cp ? strlen(path) : cp-path;
607 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
608 memcpy(plugin_path, path, len); plugin_path[len] = 0;
609 char *plugin_dir = FileSystem::basepath(plugin_path);
610 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
611 create_defaults_path(index_path, LADSPA_FILE);
612 cp = index_path + strlen(index_path);
613 for( char *bp=plugin_path; *bp!=0; ++bp )
614 *cp++ = *bp=='/' ? '_' : *bp;
616 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
617 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
618 load_plugin_index(mwindow, index_path, plugin_path);
623 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
624 FILE *fp, const char *plugin_dir)
626 int idx = PLUGIN_IDS;
628 for( int i=0; i<plugindb->size(); ++i ) {
629 PluginServer *server = plugindb->get(i);
630 if( server->dir_idx >= idx )
631 idx = server->dir_idx+1;
634 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
637 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
638 const char *index_path, const char *plugin_dir)
640 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
641 strcpy(plugin_path, path); delete [] path;
642 printf("init ladspa index: %s\n", plugin_dir);
643 FILE *fp = fopen(index_path,"w");
645 fprintf(stderr,_("MWindow::init_ladspa_index: "
646 "can't create plugin index: %s\n"), index_path);
649 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
650 fprintf(fp, "%s\n", plugin_dir);
651 init_plugin_index(mwindow, preferences, fp, plugin_path);
656 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
657 const char *plug_dir, const char *plug_path, int &idx)
659 char plugin_path[BCTEXTLEN];
660 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
662 fs.set_filter( "[*.plugin][*.so]" );
663 int result = fs.update(plugin_path);
664 if( result || !fs.dir_list.total ) return;
667 for( int i=0; i<fs.dir_list.total; ++i ) {
668 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
669 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
670 get_plugin_path(path, plug_dir, fs_path);
671 if( fs.is_dir(fs_path) ) {
672 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
675 if( plugin_exists(path) ) continue;
677 if( stat(fs_path, &st) ) continue;
678 int64_t mtime = st.st_mtime;
679 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
680 result = server.open_plugin(1, preferences, 0, 0);
682 server.write_table(fp, path, vis_id, mtime);
683 server.close_plugin();
685 else if( result == PLUGINSERVER_IS_LAD ) {
688 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
689 ladspa.set_lad_index(lad_index++);
690 result = ladspa.open_plugin(1, preferences, 0, 0);
692 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
693 ladspa.close_plugin();
699 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
701 for( int i=0; i<plugins.size(); ++i )
702 plugindb->append(plugins[i]);
703 plugins.remove_all();
706 void MWindow::delete_plugins()
708 plugindb->remove_all_objects();
713 void MWindow::search_plugindb(int do_audio,
718 ArrayList<PluginServer*> &results)
721 for(int i = 0; i < MWindow::plugindb->total; i++)
723 PluginServer *current = MWindow::plugindb->get(i);
725 if(current->audio == do_audio &&
726 current->video == do_video &&
727 (current->realtime == is_realtime || is_realtime < 0) &&
728 current->transition == is_transition &&
729 current->theme == is_theme)
730 results.append(current);
733 // Alphabetize list by title
739 for(int i = 0; i < results.total - 1; i++)
741 PluginServer *value1 = results[i];
742 PluginServer *value2 = results[i + 1];
743 if(strcmp(_(value1->title), _(value2->title)) > 0)
747 results[i + 1] = value1;
753 PluginServer* MWindow::scan_plugindb(char *title,
758 // printf("MWindow::scan_plugindb data_type < 0\n");
762 for(int i = 0; i < plugindb->total; i++)
764 PluginServer *server = plugindb->get(i);
766 !strcasecmp(server->title, title) &&
768 (data_type == TRACK_AUDIO && server->audio) ||
769 (data_type == TRACK_VIDEO && server->video)))
770 return plugindb->get(i);
775 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
777 for( int i=0; i<plugins.size(); ++i )
778 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
782 int MWindow::plugin_exists(char *plugin_path)
784 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
787 void MWindow::init_preferences()
789 preferences = new Preferences;
790 preferences->load_defaults(defaults);
791 session = new MainSession(this);
792 session->load_defaults(defaults);
793 // set x11_host, screens, window_config
794 screens = session->set_default_x11_host();
795 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
796 BC_Signals::set_trap_hook(trap_hook, this);
797 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
798 BC_Signals::set_catch_intr(preferences->trap_sigintr);
799 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
802 void MWindow::clean_indexes()
807 int oldest_item = -1;
809 char string[BCTEXTLEN];
810 char string2[BCTEXTLEN];
812 // Delete extra indexes
813 fs.set_filter("*.idx");
814 fs.complete_path(preferences->index_directory);
815 fs.update(preferences->index_directory);
816 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
818 // Eliminate directories
823 for(int i = 0; i < fs.dir_list.total && !result; i++)
825 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
826 if(fs.is_dir(string))
828 delete fs.dir_list[i];
829 fs.dir_list.remove_number(i);
834 total_excess = fs.dir_list.total - preferences->index_count;
836 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
837 while(total_excess > 0)
840 for(int i = 0; i < fs.dir_list.total; i++)
842 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
844 if(i == 0 || fs.get_date(string) <= oldest)
846 oldest = fs.get_date(string);
854 fs.join_names(string,
855 preferences->index_directory,
856 fs.dir_list[oldest_item]->name);
857 //printf("MWindow::clean_indexes 1 %s\n", string);
859 perror("delete_indexes");
860 delete fs.dir_list[oldest_item];
861 fs.dir_list.remove_number(oldest_item);
863 // Remove table of contents if it exists
864 strcpy(string2, string);
865 char *ptr = strrchr(string2, '.');
868 //printf("MWindow::clean_indexes 2 %s\n", string2);
869 sprintf(ptr, ".toc");
871 sprintf(ptr, ".mkr");
880 void MWindow::init_awindow()
882 awindow = new AWindow(this);
883 awindow->create_objects();
886 void MWindow::init_gwindow()
888 gwindow = new GWindow(this);
889 gwindow->create_objects();
892 void MWindow::init_tipwindow()
895 twindow = new TipWindow(this);
899 void MWindow::show_warning(int *do_warning, const char *text)
901 if( do_warning && !*do_warning ) return;
903 wwindow = new WWindow(this);
904 wwindow->show_warning(do_warning, text);
907 int MWindow::wait_warning()
909 return wwindow->wait_result();
912 void MWindow::init_theme()
917 PluginServer *theme_plugin = 0;
918 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
919 if( plugindb->get(i)->theme &&
920 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
921 theme_plugin = plugindb->get(i);
925 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
928 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
929 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
931 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
932 if( plugindb->get(i)->theme &&
933 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
934 theme_plugin = plugindb->get(i);
939 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
943 PluginServer *plugin = new PluginServer(*theme_plugin);
944 if( plugin->open_plugin(0, preferences, 0, 0) ) {
945 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
946 theme_plugin->title);
950 theme = plugin->new_theme();
951 theme->mwindow = this;
952 strcpy(theme->path, plugin->path);
955 // Load default images & settings
956 theme->Theme::initialize();
957 // Load user images & settings
959 // Create menus with user colors
960 theme->build_menus();
965 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
968 void MWindow::init_3d()
970 playback_3d = new Playback3D(this);
971 playback_3d->create_objects();
974 void MWindow::init_edl()
977 edl->create_objects();
978 fill_preset_defaults(default_standard, edl->session);
979 edl->load_defaults(defaults);
980 edl->create_default_tracks();
981 edl->tracks->update_y_pixels(theme);
984 void MWindow::init_compositor()
986 cwindow = new CWindow(this);
987 cwindow->create_objects();
990 void MWindow::init_levelwindow()
992 lwindow = new LevelWindow(this);
993 lwindow->create_objects();
996 VWindow *MWindow::get_viewer(int start_it, int idx)
998 vwindows_lock->lock("MWindow::get_viewer");
999 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1000 if( !vwindow ) idx = vwindows.size();
1001 while( !vwindow && --idx >= 0 ) {
1002 VWindow *vwin = vwindows[idx];
1003 if( !vwin->is_running() || !vwin->get_edl() )
1007 vwindow = new VWindow(this);
1008 vwindow->load_defaults();
1009 vwindow->create_objects();
1010 vwindows.append(vwindow);
1012 vwindows_lock->unlock();
1013 if( start_it ) vwindow->start();
1017 void MWindow::init_cache()
1019 audio_cache = new CICache(preferences);
1020 video_cache = new CICache(preferences);
1021 frame_cache = new FrameCache;
1022 wave_cache = new WaveCache;
1025 void MWindow::init_channeldb()
1027 channeldb_buz->load("channeldb_buz");
1028 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1031 void MWindow::init_menus()
1033 char string[BCTEXTLEN];
1036 BC_CModels::to_text(string, BC_RGB888);
1037 colormodels.append(new ColormodelItem(string, BC_RGB888));
1038 BC_CModels::to_text(string, BC_RGBA8888);
1039 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1040 // BC_CModels::to_text(string, BC_RGB161616);
1041 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1042 // BC_CModels::to_text(string, BC_RGBA16161616);
1043 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1044 BC_CModels::to_text(string, BC_RGB_FLOAT);
1045 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1046 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1047 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1048 BC_CModels::to_text(string, BC_YUV888);
1049 colormodels.append(new ColormodelItem(string, BC_YUV888));
1050 BC_CModels::to_text(string, BC_YUVA8888);
1051 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1052 // BC_CModels::to_text(string, BC_YUV161616);
1053 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1054 // BC_CModels::to_text(string, BC_YUVA16161616);
1055 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1057 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1058 interlace_project_modes.append(new InterlacemodeItem(string, x));
1060 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1061 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1063 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1064 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1066 // Interlacing Modes
1067 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1069 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1070 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1072 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1073 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1075 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1076 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1078 // Interlacing Fixing Methods
1079 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
1080 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
1081 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
1084 void MWindow::init_indexes()
1086 mainindexes = new MainIndexes(this);
1087 mainindexes->start_loop();
1090 void MWindow::init_gui()
1092 gui = new MWindowGUI(this);
1093 gui->lock_window("MWindow::init_gui");
1094 gui->create_objects();
1095 gui->unlock_window();
1096 gui->load_defaults(defaults);
1099 void MWindow::init_signals()
1101 sighandler = new SigHandler;
1102 sighandler->initialize();
1106 void MWindow::init_render()
1108 render = new Render(this);
1109 create_bd = new CreateBD_Thread(this);
1110 create_dvd = new CreateDVD_Thread(this);
1111 batch_render = new BatchRenderThread(this);
1114 void MWindow::init_exportedl()
1116 exportedl = new ExportEDL(this);
1119 void MWindow::init_brender()
1121 if(preferences->use_brender && !brender)
1123 brender_lock->lock("MWindow::init_brender 1");
1124 brender = new BRender(this);
1125 brender->initialize();
1126 session->brender_end = 0;
1127 brender_lock->unlock();
1130 if(!preferences->use_brender && brender)
1132 brender_lock->lock("MWindow::init_brender 2");
1135 session->brender_end = 0;
1136 brender_lock->unlock();
1138 if(brender) brender->restart(edl);
1141 void MWindow::restart_brender()
1143 //printf("MWindow::restart_brender 1\n");
1144 if(brender) brender->restart(edl);
1147 void MWindow::stop_brender()
1149 if(brender) brender->stop();
1152 int MWindow::brender_available(int position)
1155 brender_lock->lock("MWindow::brender_available 1");
1158 if(brender->map_valid)
1160 brender->map_lock->lock("MWindow::brender_available 2");
1161 if(position < brender->map_size &&
1164 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1165 if(brender->map[position] == BRender::RENDERED)
1168 brender->map_lock->unlock();
1171 brender_lock->unlock();
1175 void MWindow::set_brender_start()
1177 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1179 gui->draw_overlays(1);
1183 int MWindow::has_commercials()
1185 return theme->use_commercials;
1188 void MWindow::init_commercials()
1190 if( !commercials ) {
1191 commercials = new Commercials(this);
1192 commercial_active = 0;
1195 commercials->add_user();
1198 void MWindow::commit_commercial()
1200 if( !commercial_active ) return;
1201 commercial_active = 0;
1202 if( !commercials ) return;
1203 commercials->commitDb();
1206 void MWindow::undo_commercial()
1208 if( !commercial_active ) return;
1209 commercial_active = 0;
1210 if( !commercials ) return;
1211 commercials->undoDb();
1214 int MWindow::put_commercial()
1216 double start = edl->local_session->get_selectionstart();
1217 double end = edl->local_session->get_selectionend();
1218 if( start >= end ) return 0;
1220 const char *errmsg = 0;
1222 Tracks *tracks = edl->tracks;
1225 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1226 if( track->data_type != TRACK_VIDEO ) continue;
1227 if( !track->record ) continue;
1228 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1230 int64_t units_start = track->to_units(start,0);
1231 int64_t units_end = track->to_units(end,0);
1232 Edits *edits = track->edits;
1233 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1234 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1235 if(!edit1 && !edit2) continue; // nothing selected
1236 if(!edit2) { // edit2 beyond end of track
1237 edit2 = edits->last;
1238 units_end = edits->length();
1240 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1241 Indexable *indexable = edit1->get_source();
1242 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1245 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1246 if( track->data_type != TRACK_VIDEO ) continue;
1247 if( !track->record ) continue;
1248 int64_t units_start = track->to_units(start,0);
1249 int64_t units_end = track->to_units(end,0);
1250 Edits *edits = track->edits;
1251 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1252 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1253 if(!edit1 && !edit2) continue; // nothing selected
1254 if(!edit2) { // edit2 beyond end of track
1255 edit2 = edits->last;
1256 units_end = edits->length();
1258 Indexable *indexable = edit1->get_source();
1259 Asset *asset = (Asset *)indexable;
1260 File *file = video_cache->check_out(asset, edl);
1261 if( !file ) { errmsg = _("no file"); break; }
1262 int64_t edit_length = units_end - units_start;
1263 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1264 result = commercials->put_clip(file, edit1->channel,
1265 track->from_units(edit_start), track->from_units(edit_length));
1266 video_cache->check_in(asset);
1267 if( result ) { errmsg = _("db failed"); break; }
1270 char string[BCTEXTLEN];
1271 sprintf(string, _("put_commercial: %s"), errmsg);
1272 MainError::show_error(string);
1279 void MWindow::stop_playback(int wait)
1281 int locked = gui->get_window_lock();
1282 if( locked ) gui->unlock_window();
1284 cwindow->playback_engine->que->send_command(STOP,
1288 cwindow->playback_engine->interrupt_playback(wait);
1290 for(int i = 0; i < vwindows.size(); i++) {
1291 VWindow *vwindow = vwindows[i];
1292 if( !vwindow->is_running() ) continue;
1293 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1294 vwindow->playback_engine->interrupt_playback(wait);
1296 if( locked ) gui->lock_window("MWindow::stop_playback");
1299 int MWindow::load_filenames(ArrayList<char*> *filenames,
1301 int update_filename)
1303 ArrayList<EDL*> new_edls;
1304 ArrayList<Asset*> new_assets;
1305 ArrayList<File*> new_files;
1306 const int debug = 0;
1307 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1310 gui->start_hourglass();
1312 // Need to stop playback since tracking depends on the EDL not getting
1316 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1317 undo->update_undo_before();
1320 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1322 // Define new_edls and new_assets to load
1323 int result = 0, ftype = -1;
1324 for(int i = 0; i < filenames->size(); i++)
1327 File *new_file = new File;
1328 Asset *new_asset = new Asset(filenames->get(i));
1329 EDL *new_edl = new EDL;
1330 char string[BCTEXTLEN];
1332 new_edl->create_objects();
1333 new_edl->copy_session(edl);
1334 new_file->set_program(edl->session->program_no);
1336 sprintf(string, _("Loading %s"), new_asset->path);
1337 gui->show_message(string);
1338 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1340 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1341 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1346 // Convert media file to EDL
1348 // Warn about odd image dimensions
1349 if(new_asset->video_data &&
1350 ((new_asset->width % 2) ||
1351 (new_asset->height % 2)))
1353 char string[BCTEXTLEN];
1354 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1358 MainError::show_error(string);
1361 if(new_asset->program >= 0 &&
1362 edl->session->program_no != new_asset->program)
1364 char string[BCTEXTLEN];
1365 sprintf(string, _("%s's index was built for program number %d\n"
1366 "Playback preference is %d.\n Using program %d."),
1367 new_asset->path, new_asset->program,
1368 edl->session->program_no, new_asset->program);
1369 MainError::show_error(string);
1373 if(load_mode != LOADMODE_RESOURCESONLY)
1376 RecordLabels *labels = edl->session->label_cells ?
1377 new RecordLabels(new_file) : 0;
1379 asset_to_edl(new_edl, new_asset, labels);
1381 new_edls.append(new_edl);
1383 new_asset->Garbage::remove_user();
1389 new_assets.append(new_asset);
1393 // Set filename to nothing for assets since save EDL would overwrite them.
1394 if(load_mode == LOADMODE_REPLACE ||
1395 load_mode == LOADMODE_REPLACE_CONCATENATE)
1398 // Reset timeline position
1399 for(int i = 0; i < TOTAL_PANES; i++)
1401 new_edl->local_session->view_start[i] = 0;
1402 new_edl->local_session->track_start[i] = 0;
1410 case FILE_NOT_FOUND:
1411 sprintf(string, _("Failed to open %s"), new_asset->path);
1412 gui->show_message(string, theme->message_error);
1416 case FILE_UNRECOGNIZED_CODEC:
1419 IndexFile indexfile(this, new_asset);
1420 result = indexfile.open_index();
1423 indexfile.close_index();
1426 // Test existing EDLs
1427 for(int j = 0; result && j <= new_edls.total; j++) {
1428 Asset *old_asset = j < new_edls.total ?
1429 new_edls[j]->assets->get_asset(new_asset->path) :
1430 edl->assets->get_asset(new_asset->path);
1432 *new_asset = *old_asset;
1440 char string[BCTEXTLEN];
1442 fs.extract_name(string, new_asset->path);
1444 strcat(string, _("'s format couldn't be determined."));
1445 new_asset->audio_data = 1;
1446 new_asset->format = FILE_PCM;
1447 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1448 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1449 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1450 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1451 new_asset->signed_ = defaults->get("SIGNED_", 1);
1452 new_asset->header = defaults->get("HEADER", 0);
1454 FileFormat fwindow(this);
1455 fwindow.create_objects(new_asset, string);
1456 result = fwindow.run_window();
1459 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1460 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1461 defaults->update("AUDIO_BITS", new_asset->bits);
1462 defaults->update("BYTE_ORDER", new_asset->byte_order);
1463 defaults->update("SIGNED_", new_asset->signed_);
1464 defaults->update("HEADER", new_asset->header);
1471 // Recalculate length
1473 new_file = new File;
1474 result = new_file->open_file(preferences, new_asset, 1, 0);
1476 if(load_mode != LOADMODE_RESOURCESONLY)
1478 RecordLabels *labels = edl->session->label_cells ?
1479 new RecordLabels(new_file) : 0;
1480 asset_to_edl(new_edl, new_asset, labels);
1481 new_edls.append(new_edl);
1482 new_asset->Garbage::remove_user();
1488 new_assets.append(new_asset);
1502 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1503 xml_file.read_from_file(filenames->get(i));
1504 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1505 const char *cin_version = 0;
1506 while( !xml_file.read_tag() ) {
1507 if( xml_file.tag.title_is("EDL") ) {
1508 cin_version = xml_file.tag.get_property("VERSION");
1513 if( !cin_version ) {
1514 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1515 char string[BCTEXTLEN];
1516 sprintf(string,_("Unknown %s"), filenames->get(i));
1517 gui->show_message(string);
1521 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1522 char string[BCTEXTLEN];
1523 snprintf(string, sizeof(string),
1524 _("Warning: XML from cinelerra version %s\n"
1525 "Session data may be incompatible."), cin_version);
1526 show_warning(&preferences->warn_version, string);
1528 if(load_mode == LOADMODE_NESTED)
1530 // Load temporary EDL for nesting.
1531 EDL *nested_edl = new EDL;
1532 nested_edl->create_objects();
1533 nested_edl->set_path(filenames->get(i));
1534 nested_edl->load_xml(&xml_file, LOAD_ALL);
1535 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1536 edl_to_nested(new_edl, nested_edl);
1537 nested_edl->Garbage::remove_user();
1541 // Load EDL for pasting
1542 new_edl->load_xml(&xml_file, LOAD_ALL);
1543 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1544 test_plugins(new_edl, filenames->get(i));
1545 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1547 if(load_mode == LOADMODE_REPLACE ||
1548 load_mode == LOADMODE_REPLACE_CONCATENATE)
1550 strcpy(session->filename, filenames->get(i));
1551 strcpy(new_edl->local_session->clip_title,
1554 set_filename(new_edl->local_session->clip_title);
1558 new_edls.append(new_edl);
1564 // edls are in new_edls
1565 if( result && new_edl ) new_edl->Garbage::remove_user();
1566 // assets are copied
1567 if( new_asset ) new_asset->Garbage::remove_user();
1569 // Store for testing index
1570 new_files.append(new_file);
1573 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1576 if(!result) gui->statusbar->default_message();
1584 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1587 // Don't back up here.
1590 // For pasting, clear the active region
1591 if(load_mode == LOADMODE_PASTE ||
1592 load_mode == LOADMODE_NESTED)
1594 double start = edl->local_session->get_selectionstart();
1595 double end = edl->local_session->get_selectionend();
1596 if(!EQUIV(start, end))
1599 edl->session->labels_follow_edits,
1600 edl->session->plugins_follow_edits,
1601 edl->session->autos_follow_edits);
1604 paste_edls(&new_edls,
1608 edl->session->labels_follow_edits,
1609 edl->session->plugins_follow_edits,
1610 edl->session->autos_follow_edits,
1617 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1619 // Add new assets to EDL and schedule assets for index building.
1620 int got_indexes = 0;
1621 for(int i = 0; i < new_edls.size(); i++)
1623 EDL *new_edl = new_edls[i];
1624 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1626 mainindexes->add_next_asset(0,
1627 new_edl->nested_edls->get(j));
1629 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1634 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1635 if(new_assets.size())
1637 for(int i = 0; i < new_assets.size(); i++)
1639 Asset *new_asset = new_assets[i];
1643 for(int j = 0; j < new_files.size(); j++)
1645 new_file = new_files[j];
1646 if(!strcmp(new_file->asset->path,
1654 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1656 edl->assets->update(new_asset);
1662 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1664 // Start examining next batch of index files
1665 if(got_indexes) mainindexes->start_build();
1666 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1669 Track *track = edl->tracks->first;
1672 for(int j = 0; j < track->plugin_set.size(); j++)
1674 PluginSet *plugins = track->plugin_set[j];
1675 Plugin *plugin = plugins->get_first_plugin();
1679 if(load_mode == LOADMODE_REPLACE ||
1680 load_mode == LOADMODE_REPLACE_CONCATENATE)
1682 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1685 show_plugin(plugin);
1693 plugin = (Plugin*)plugin->next;
1697 track = track->next;
1700 // if just opening one new resource in replace mode
1701 if( ftype != FILE_IS_XML &&
1702 ( load_mode == LOADMODE_REPLACE ||
1703 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1705 edl->local_session->preview_start = 0;
1706 edl->local_session->preview_end = edl->tracks->total_playable_length();
1707 edl->local_session->loop_playback = 0;
1708 edl->local_session->set_selectionstart(0);
1709 edl->local_session->set_selectionend(0);
1714 // need to update undo before project, since mwindow is unlocked & a new load
1715 // can begin here. Should really prevent loading until we're done.
1716 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1717 undo->update_undo_after(_("load"), LOAD_ALL);
1719 for(int i = 0; i < new_edls.size(); i++)
1721 new_edls[i]->remove_user();
1723 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1725 new_edls.remove_all();
1727 for(int i = 0; i < new_assets.size(); i++)
1729 new_assets[i]->Garbage::remove_user();
1732 new_assets.remove_all();
1733 new_files.remove_all_objects();
1736 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1737 if(load_mode == LOADMODE_REPLACE ||
1738 load_mode == LOADMODE_REPLACE_CONCATENATE)
1740 session->changes_made = 0;
1744 session->changes_made = 1;
1747 gui->stop_hourglass();
1750 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1751 update_project(load_mode);
1753 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1761 void MWindow::test_plugins(EDL *new_edl, char *path)
1763 char string[BCTEXTLEN];
1765 // Do a check weather plugins exist
1766 for(Track *track = new_edl->tracks->first; track; track = track->next)
1768 for(int k = 0; k < track->plugin_set.total; k++)
1770 PluginSet *plugin_set = track->plugin_set[k];
1771 for(Plugin *plugin = (Plugin*)plugin_set->first;
1773 plugin = (Plugin*)plugin->next)
1775 if(plugin->plugin_type == PLUGIN_STANDALONE)
1777 // ok we need to find it in plugindb
1778 int plugin_found = 0;
1780 for(int j = 0; j < plugindb->size(); j++)
1782 PluginServer *server = plugindb->get(j);
1784 !strcasecmp(server->title, plugin->title) &&
1785 ((track->data_type == TRACK_AUDIO && server->audio) ||
1786 (track->data_type == TRACK_VIDEO && server->video)) &&
1787 (!server->transition))
1794 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1795 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1796 "effect", plugin->title,
1798 MainError::show_error(string);
1804 for(Edit *edit = (Edit*)track->edits->first;
1806 edit = (Edit*)edit->next)
1808 if (edit->transition)
1810 // ok we need to find transition in plugindb
1812 int transition_found = 0;
1813 for(int j = 0; j < plugindb->size(); j++)
1815 PluginServer *server = plugindb->get(j);
1817 !strcasecmp(server->title, edit->transition->title) &&
1818 ((track->data_type == TRACK_AUDIO && server->audio) ||
1819 (track->data_type == TRACK_VIDEO && server->video)) &&
1820 (server->transition))
1821 transition_found = 1;
1824 if (!transition_found)
1827 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1828 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1829 "transition", edit->transition->title,
1831 MainError::show_error(string);
1839 void MWindow::init_shm()
1841 // Fix shared memory
1842 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1844 fprintf(fd, "0x7fffffff");
1849 fd = fopen("/proc/sys/kernel/shmmax", "r");
1851 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1856 fscanf(fd, "%jd", &result);
1859 if(result < 0x7fffffff) {
1860 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1861 "you probably need to be root, or:\n"
1862 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1863 "before trying to start cinelerra.\n"
1864 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1868 void MWindow::create_objects(int want_gui,
1873 const int debug = 0;
1874 if(debug) PRINT_TRACE
1876 // For some reason, init_signals must come after show_splash or the signals won't
1879 if(debug) PRINT_TRACE
1882 if(debug) PRINT_TRACE
1885 if(debug) PRINT_TRACE
1886 default_standard = default_std();
1887 init_defaults(defaults, config_path);
1890 splash_window->operation->update(_("Initializing Plugins"));
1891 init_plugins(this, preferences);
1892 if(debug) PRINT_TRACE
1893 init_ladspa_plugins(this, preferences);
1894 if(debug) PRINT_TRACE
1896 splash_window->operation->update(_("Initializing GUI"));
1897 if(debug) PRINT_TRACE
1900 if(debug) PRINT_TRACE
1904 splash_window->operation->update(_("Initializing Fonts"));
1905 char string[BCTEXTLEN];
1906 strcpy(string, preferences->plugin_dir);
1907 strcat(string, "/" FONT_SEARCHPATH);
1908 BC_Resources::init_fontconfig(string);
1909 if(debug) PRINT_TRACE
1911 // Initialize before too much else is running
1912 // Preferences & theme are required for building MPEG table of contents
1914 // Default project created here
1916 if(debug) PRINT_TRACE
1919 if(debug) PRINT_TRACE
1924 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1926 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1927 if(session->show_vwindow)
1928 get_viewer(1, DEFAULT_VWINDOW);
1929 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1932 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
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());
1940 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1943 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1947 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());
1951 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());
1956 mainprogress = new MainProgress(this, gui);
1957 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1958 undo = new MainUndo(this);
1960 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1962 plugin_guis = new ArrayList<PluginServer*>;
1963 dead_plugins = new ArrayList<PluginServer*>;
1964 keyframe_threads = new ArrayList<KeyFrameThread*>;
1966 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1969 session->show_vwindow);
1971 // Show all vwindows
1972 // if(session->show_vwindow) {
1973 // for(int j = 0; j < vwindows.size(); j++) {
1974 // VWindow *vwindow = vwindows[j];
1975 // if( !vwindow->is_running() ) continue;
1976 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1979 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1980 // vwindow->gui->lock_window("MWindow::create_objects 1");
1981 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1982 // vwindow->gui->show_window();
1983 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1984 // vwindow->gui->unlock_window();
1989 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1991 if(session->show_cwindow)
1993 cwindow->gui->lock_window("MWindow::create_objects 1");
1994 cwindow->gui->show_window();
1995 cwindow->gui->unlock_window();
1998 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1999 if(session->show_awindow)
2001 awindow->gui->lock_window("MWindow::create_objects 1");
2002 awindow->gui->show_window();
2003 awindow->gui->unlock_window();
2006 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2007 if(session->show_lwindow)
2009 lwindow->gui->lock_window("MWindow::create_objects 1");
2010 lwindow->gui->show_window();
2011 lwindow->gui->unlock_window();
2014 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2016 (int)timer.get_difference(),
2018 if(session->show_gwindow)
2020 gwindow->gui->lock_window("MWindow::create_objects 1");
2021 gwindow->gui->show_window();
2022 gwindow->gui->unlock_window();
2025 if(debug) PRINT_TRACE
2027 gui->lock_window("MWindow::create_objects 1");
2028 gui->mainmenu->load_defaults(defaults);
2029 gui->mainmenu->update_toggles(0);
2030 gui->update_patchbay();
2031 gui->draw_canvas(0, 0);
2032 gui->draw_cursor(1);
2034 gui->raise_window();
2035 gui->unlock_window();
2037 if(debug) PRINT_TRACE
2039 if(preferences->use_tipwindow)
2041 if(debug) PRINT_TRACE
2043 gui->add_keyboard_listener(
2044 (int (BC_WindowBase::*)(BC_WindowBase *))
2045 &MWindowGUI::keyboard_listener);
2049 if(debug) PRINT_TRACE
2051 BC_WindowBase::get_resources()->vframe_shm = 1;
2055 void MWindow::show_splash()
2057 #include "data/heroine_logo9_png.h"
2058 VFrame *frame = new VFramePng(heroine_logo9_png);
2059 BC_DisplayInfo dpyi;
2060 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2061 int rr = (rw < rh ? rw : rh) / 4;
2062 splash_window = new SplashGUI(frame, rr, rr);
2063 splash_window->create_objects();
2066 void MWindow::hide_splash()
2069 delete splash_window;
2074 void MWindow::start()
2078 // vwindows[DEFAULT_VWINDOW]->start();
2089 playback_3d->start();
2098 void MWindow::show_vwindow()
2100 int total_running = 0;
2101 session->show_vwindow = 1;
2103 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2104 // Raise all windows which are visible
2105 for(int j = 0; j < vwindows.size(); j++) {
2106 VWindow *vwindow = vwindows[j];
2107 if( !vwindow->is_running() ) continue;
2108 vwindow->gui->lock_window("MWindow::show_vwindow");
2109 vwindow->gui->show_window(0);
2110 vwindow->gui->raise_window();
2111 vwindow->gui->flush();
2112 vwindow->gui->unlock_window();
2116 // If no windows visible
2119 get_viewer(1, DEFAULT_VWINDOW);
2122 gui->mainmenu->show_vwindow->set_checked(1);
2125 void MWindow::show_awindow()
2127 session->show_awindow = 1;
2128 awindow->gui->lock_window("MWindow::show_awindow");
2129 awindow->gui->show_window();
2130 awindow->gui->raise_window();
2131 awindow->gui->flush();
2132 awindow->gui->unlock_window();
2133 gui->mainmenu->show_awindow->set_checked(1);
2136 char *MWindow::get_cwindow_display()
2138 char *x11_host = screens < 2 || session->window_config == 0 ?
2139 session->a_x11_host : session->b_x11_host;
2140 return *x11_host ? x11_host : 0;
2143 void MWindow::show_cwindow()
2145 session->show_cwindow = 1;
2146 cwindow->show_window();
2147 gui->mainmenu->show_cwindow->set_checked(1);
2150 void MWindow::show_gwindow()
2152 session->show_gwindow = 1;
2154 gwindow->gui->lock_window("MWindow::show_gwindow");
2155 gwindow->gui->show_window();
2156 gwindow->gui->raise_window();
2157 gwindow->gui->flush();
2158 gwindow->gui->unlock_window();
2160 gui->mainmenu->show_gwindow->set_checked(1);
2163 void MWindow::show_lwindow()
2165 session->show_lwindow = 1;
2166 lwindow->gui->lock_window("MWindow::show_lwindow");
2167 lwindow->gui->show_window();
2168 lwindow->gui->raise_window();
2169 lwindow->gui->flush();
2170 lwindow->gui->unlock_window();
2171 gui->mainmenu->show_lwindow->set_checked(1);
2174 int MWindow::tile_windows(int window_config)
2176 int need_reload = 0;
2177 int play_config = window_config==0 ? 0 : 1;
2178 edl->session->playback_config->load_defaults(defaults, play_config);
2179 session->default_window_positions(window_config);
2180 if( screens == 1 ) {
2181 gui->default_positions();
2182 sync_parameters(CHANGE_ALL);
2189 void MWindow::toggle_loop_playback()
2191 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2192 set_loop_boundaries();
2195 gui->draw_overlays(1);
2196 sync_parameters(CHANGE_PARAMS);
2199 //void MWindow::set_titles(int value)
2201 // edl->session->show_titles = value;
2202 // trackmovement(edl->local_session->track_start);
2205 void MWindow::set_screens(int value)
2210 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2212 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2213 edl->session->auto_keyframes = value;
2214 gui->mbuttons->edit_panel->keyframe->update(value);
2216 if(lock_mwindow) gui->unlock_window();
2218 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2219 cwindow->gui->edit_panel->keyframe->update(value);
2220 cwindow->gui->flush();
2221 if(lock_cwindow) cwindow->gui->unlock_window();
2224 void MWindow::set_auto_visibility(Autos *autos, int value)
2226 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2227 edl->session->auto_conf->plugins = value;
2228 else if( autos->autoidx >= 0 )
2229 edl->session->auto_conf->autos[autos->autoidx] = value;
2233 gui->update(0, 1, 0, 0, 0, 0, 0);
2234 gui->mainmenu->update_toggles(1);
2235 gui->unlock_window();
2236 gwindow->gui->update_toggles(1);
2237 gui->lock_window("MWindow::set_auto_visibility");
2240 void MWindow::set_keyframe_type(int mode)
2242 gui->lock_window("MWindow::set_keyframe_type");
2243 edl->local_session->floatauto_type = mode;
2244 gui->mainmenu->update_toggles(0);
2245 gui->unlock_window();
2248 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2250 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2251 edl->session->editing_mode = new_editing_mode;
2252 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2253 gui->mbuttons->edit_panel->update();
2254 gui->set_editing_mode(1);
2255 if(lock_mwindow) gui->unlock_window();
2258 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2259 cwindow->gui->edit_panel->update();
2260 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2261 if(lock_cwindow) cwindow->gui->unlock_window();
2265 void MWindow::toggle_editing_mode()
2267 int mode = edl->session->editing_mode;
2268 if( mode == EDITING_ARROW )
2269 set_editing_mode(EDITING_IBEAM, 0, 1);
2271 set_editing_mode(EDITING_ARROW, 0, 1);
2275 void MWindow::set_labels_follow_edits(int value)
2277 gui->lock_window("MWindow::set_labels_follow_edits");
2278 edl->session->labels_follow_edits = value;
2279 gui->mbuttons->edit_panel->locklabels->update(value);
2280 gui->mainmenu->labels_follow_edits->set_checked(value);
2282 gui->unlock_window();
2285 void MWindow::sync_parameters(int change_type)
2287 if( in_destructor ) return;
2289 // Sync engines which are playing back
2290 if(cwindow->playback_engine->is_playing_back)
2292 if(change_type == CHANGE_PARAMS)
2294 // TODO: block keyframes until synchronization is done
2295 cwindow->playback_engine->sync_parameters(edl);
2300 int command = cwindow->playback_engine->command->command;
2301 cwindow->playback_engine->que->send_command(STOP,
2305 // Waiting for tracking to finish would make the restart position more
2306 // accurate but it can't lock the window to stop tracking for some reason.
2307 // Not waiting for tracking gives a faster response but restart position is
2308 // only as accurate as the last tracking update.
2309 cwindow->playback_engine->interrupt_playback(0);
2310 cwindow->playback_engine->que->send_command(command,
2319 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2326 void MWindow::age_caches()
2328 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2330 // preferences->cache_size,
2331 // audio_cache->get_memory_usage(1),
2332 // video_cache->get_memory_usage(1),
2333 // frame_cache->get_memory_usage(),
2334 // wave_cache->get_memory_usage(),
2336 frame_cache->age_cache(512);
2337 wave_cache->age_cache(8192);
2339 int64_t memory_usage;
2340 int64_t prev_memory_usage = 0;
2342 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2343 while( !result && prev_memory_usage !=
2344 (memory_usage=video_cache->get_memory_usage(1)) &&
2345 memory_usage > video_size ) {
2346 video_cache->delete_oldest();
2347 prev_memory_usage = memory_usage;
2350 prev_memory_usage = 0;
2352 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2353 while( !result && prev_memory_usage !=
2354 (memory_usage=audio_cache->get_memory_usage(1)) &&
2355 memory_usage > audio_size ) {
2356 audio_cache->delete_oldest();
2357 prev_memory_usage = memory_usage;
2361 void MWindow::reset_android_remote()
2363 gui->use_android_remote(preferences->android_remote);
2367 void MWindow::show_keyframe_gui(Plugin *plugin)
2369 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2370 // Find existing thread
2371 for(int i = 0; i < keyframe_threads->size(); i++)
2373 if(keyframe_threads->get(i)->plugin == plugin)
2375 keyframe_threads->get(i)->start_window(plugin, 0);
2376 keyframe_gui_lock->unlock();
2381 // Find unused thread
2382 for(int i = 0; i < keyframe_threads->size(); i++)
2384 if(!keyframe_threads->get(i)->plugin)
2386 keyframe_threads->get(i)->start_window(plugin, 0);
2387 keyframe_gui_lock->unlock();
2392 // Create new thread
2393 KeyFrameThread *thread = new KeyFrameThread(this);
2394 keyframe_threads->append(thread);
2395 thread->start_window(plugin, 0);
2397 keyframe_gui_lock->unlock();
2404 void MWindow::show_plugin(Plugin *plugin)
2409 // Remove previously deleted plugin GUIs
2410 dead_plugin_lock->lock("MWindow::show_plugin");
2411 dead_plugins->remove_all_objects();
2412 dead_plugin_lock->unlock();
2414 //printf("MWindow::show_plugin %d\n", __LINE__);
2418 plugin_gui_lock->lock("MWindow::show_plugin");
2419 for(int i = 0; i < plugin_guis->total; i++)
2421 // Pointer comparison
2422 if(plugin_guis->get(i)->plugin == plugin)
2424 plugin_guis->get(i)->raise_window();
2431 //printf("MWindow::show_plugin 1\n");
2436 printf("MWindow::show_plugin track not defined.\n");
2438 PluginServer *server = scan_plugindb(plugin->title,
2439 plugin->track->data_type);
2441 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2442 if(server && server->uses_gui)
2444 PluginServer *gui = new PluginServer(*server);
2445 plugin_guis->append(gui);
2446 // Needs mwindow to do GUI
2447 gui->set_mwindow(this);
2448 gui->open_plugin(0, preferences, edl, plugin);
2453 plugin_gui_lock->unlock();
2454 //printf("MWindow::show_plugin %d\n", __LINE__);
2457 //printf("MWindow::show_plugin 2\n");
2460 void MWindow::hide_plugin(Plugin *plugin, int lock)
2463 // Update the toggle
2464 gui->lock_window("MWindow::hide_plugin");
2465 gui->update(0, 1, 0, 0, 0, 0, 0);
2466 gui->unlock_window();
2468 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2469 for(int i = 0; i < plugin_guis->total; i++)
2471 if(plugin_guis->get(i)->plugin == plugin)
2473 PluginServer *ptr = plugin_guis->get(i);
2474 plugin_guis->remove(ptr);
2475 if(lock) plugin_gui_lock->unlock();
2476 // Last command executed in client side close
2477 // Schedule for deletion
2484 if(lock) plugin_gui_lock->unlock();
2487 void MWindow::delete_plugin(PluginServer *plugin)
2489 dead_plugin_lock->lock("MWindow::delete_plugin");
2490 dead_plugins->append(plugin);
2491 dead_plugin_lock->unlock();
2494 void MWindow::hide_plugins()
2496 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2497 while(plugin_guis->size())
2499 PluginServer *ptr = plugin_guis->get(0);
2500 plugin_guis->remove(ptr);
2501 plugin_gui_lock->unlock();
2502 // Last command executed in client side close
2503 // Schedule for deletion
2506 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2508 plugin_gui_lock->unlock();
2510 hide_keyframe_guis();
2513 void MWindow::hide_keyframe_guis()
2515 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2516 for(int i = 0; i < keyframe_threads->size(); i++)
2518 keyframe_threads->get(i)->close_window();
2520 keyframe_gui_lock->unlock();
2523 void MWindow::hide_keyframe_gui(Plugin *plugin)
2525 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2526 for(int i = 0; i < keyframe_threads->size(); i++)
2528 if(keyframe_threads->get(i)->plugin == plugin)
2530 keyframe_threads->get(i)->close_window();
2534 keyframe_gui_lock->unlock();
2537 void MWindow::update_keyframe_guis()
2539 // Send new configuration to keyframe GUI's
2540 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2541 for(int i = 0; i < keyframe_threads->size(); i++)
2543 KeyFrameThread *ptr = keyframe_threads->get(i);
2544 if(edl->tracks->plugin_exists(ptr->plugin))
2548 ptr->close_window();
2551 keyframe_gui_lock->unlock();
2554 void MWindow::update_plugin_guis(int do_keyframe_guis)
2556 // Send new configuration to plugin GUI's
2557 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2559 for(int i = 0; i < plugin_guis->size(); i++)
2561 PluginServer *ptr = plugin_guis->get(i);
2562 if(edl->tracks->plugin_exists(ptr->plugin))
2566 // Schedule for deletion if no plugin
2567 plugin_guis->remove_number(i);
2576 // Change plugin variable if not visible
2577 Track *track = edl->tracks->first;
2580 for(int i = 0; i < track->plugin_set.size(); i++)
2582 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2586 for(int i = 0; i < plugin_guis->size(); i++)
2588 PluginServer *server = plugin_guis->get(i);
2589 if(server->plugin == plugin)
2596 if(!got_it) plugin->show = 0;
2598 plugin = (Plugin*)plugin->next;
2602 track = track->next;
2605 plugin_gui_lock->unlock();
2608 if(do_keyframe_guis) update_keyframe_guis();
2611 int MWindow::plugin_gui_open(Plugin *plugin)
2614 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2615 for(int i = 0; i < plugin_guis->total; i++)
2617 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2623 plugin_gui_lock->unlock();
2627 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2629 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2630 for(int i = 0; i < plugin_guis->total; i++)
2632 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2634 plugin_guis->get(i)->render_gui(data);
2638 plugin_gui_lock->unlock();
2641 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2643 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2644 for(int i = 0; i < plugin_guis->total; i++)
2646 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2648 plugin_guis->get(i)->render_gui(data, size);
2652 plugin_gui_lock->unlock();
2656 void MWindow::update_plugin_states()
2658 plugin_gui_lock->lock("MWindow::update_plugin_states");
2659 for(int i = 0; i < plugin_guis->total; i++)
2663 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2664 PluginServer *src_plugingui = plugin_guis->get(i);
2666 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2667 for(Track *track = edl->tracks->first;
2669 track = track->next)
2672 j < track->plugin_set.total && !result;
2675 PluginSet *plugin_set = track->plugin_set[j];
2676 for(Plugin *plugin = (Plugin*)plugin_set->first;
2678 plugin = (Plugin*)plugin->next)
2680 if(plugin == src_plugin &&
2681 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2687 // Doesn't exist anymore
2690 hide_plugin(src_plugin, 0);
2694 plugin_gui_lock->unlock();
2698 void MWindow::update_plugin_titles()
2700 for(int i = 0; i < plugin_guis->total; i++)
2702 plugin_guis->get(i)->update_title();
2706 int MWindow::asset_to_edl(EDL *new_edl,
2708 RecordLabels *labels)
2710 const int debug = 0;
2711 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2714 // Keep frame rate, sample rate, and output size unchanged.
2715 // These parameters would revert the project if VWindow displayed an asset
2716 // of different size than the project.
2717 if(new_asset->video_data)
2719 new_edl->session->video_tracks = new_asset->layers;
2722 new_edl->session->video_tracks = 0;
2724 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2730 if(new_asset->audio_data)
2732 new_edl->session->audio_tracks = new_asset->channels;
2735 new_edl->session->audio_tracks = 0;
2736 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2738 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2739 new_edl->create_default_tracks();
2740 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2741 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2745 //printf("MWindow::asset_to_edl 3\n");
2746 new_edl->insert_asset(new_asset,
2751 //printf("MWindow::asset_to_edl 3\n");
2752 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2754 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2755 if(edl->session->cursor_on_frames)
2757 double length = new_edl->tracks->total_length();
2758 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2759 new_edl->tracks->clear(length, edl_length, 1, 1);
2765 char string[BCTEXTLEN];
2767 fs.extract_name(string, new_asset->path);
2768 //printf("MWindow::asset_to_edl 3\n");
2770 strcpy(new_edl->local_session->clip_title, string);
2771 //printf("MWindow::asset_to_edl 4 %s\n", string);
2772 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2777 int MWindow::edl_to_nested(EDL *new_edl,
2781 // Keep frame rate, sample rate, and output size unchanged.
2782 // These parameters would revert the project if VWindow displayed an asset
2783 // of different size than the project.
2787 // Nest all video & audio outputs
2788 new_edl->session->video_tracks = 1;
2789 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2790 new_edl->create_default_tracks();
2794 new_edl->insert_asset(0,
2800 char string[BCTEXTLEN];
2802 fs.extract_name(string, nested_edl->path);
2803 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2805 strcpy(new_edl->local_session->clip_title, string);
2810 // Reset everything after a load.
2811 void MWindow::update_project(int load_mode)
2813 const int debug = 0;
2815 if(debug) PRINT_TRACE
2817 edl->tracks->update_y_pixels(theme);
2819 if(debug) PRINT_TRACE
2821 if(load_mode == LOADMODE_REPLACE ||
2822 load_mode == LOADMODE_REPLACE_CONCATENATE)
2827 gui->update(1, 1, 1, 1, 1, 1, 1);
2828 if(debug) PRINT_TRACE
2829 gui->unlock_window();
2831 cwindow->gui->lock_window("MWindow::update_project 1");
2832 cwindow->update(0, 0, 1, 1, 1);
2833 cwindow->gui->unlock_window();
2835 if(debug) PRINT_TRACE
2837 // Close all the vwindows
2838 if(load_mode == LOADMODE_REPLACE ||
2839 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2840 if(debug) PRINT_TRACE
2841 int first_vwindow = 0;
2842 if(session->show_vwindow) first_vwindow = 1;
2843 // Change visible windows to no source
2844 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2845 VWindow *vwindow = vwindows[i];
2846 if( !vwindow->is_running() ) continue;
2847 vwindow->change_source(-1);
2850 // Close remaining windows
2851 for(int i = first_vwindow; i < vwindows.size(); i++) {
2852 VWindow *vwindow = vwindows[i];
2853 if( !vwindow->is_running() ) continue;
2854 vwindow->close_window();
2856 if(debug) PRINT_TRACE
2858 else if(vwindows.size()) {
2859 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2860 if( vwindow->is_running() ) {
2861 vwindow->gui->lock_window("MWindow::update_project");
2863 vwindow->gui->unlock_window();
2867 if(debug) PRINT_TRACE
2868 cwindow->gui->lock_window("MWindow::update_project 2");
2869 cwindow->gui->timebar->update(0);
2870 cwindow->gui->unlock_window();
2872 if(debug) PRINT_TRACE
2873 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2878 awindow->gui->async_update_assets();
2879 if(debug) PRINT_TRACE
2881 gui->lock_window("MWindow::update_project");
2883 if(debug) PRINT_TRACE
2886 void MWindow::remove_indexfile(Indexable *indexable)
2888 if( !indexable->is_asset ) return;
2889 Asset *asset = (Asset *)indexable;
2891 IndexFile::delete_index(preferences, asset, ".toc");
2892 IndexFile::delete_index(preferences, asset, ".idx");
2893 IndexFile::delete_index(preferences, asset, ".mkr");
2896 void MWindow::rebuild_indices()
2898 for(int i = 0; i < session->drag_assets->total; i++)
2900 Indexable *indexable = session->drag_assets->get(i);
2901 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2902 remove_indexfile(indexable);
2903 // Schedule index build
2904 IndexState *index_state = indexable->index_state;
2905 index_state->index_status = INDEX_NOTTESTED;
2906 if( indexable->is_asset ) {
2907 Asset *asset = (Asset *)indexable;
2908 if( asset->format != FILE_PCM )
2909 asset->reset_audio();
2910 asset->reset_video();
2912 mainindexes->add_next_asset(0, indexable);
2914 mainindexes->start_build();
2918 void MWindow::save_backup()
2922 edl->set_path(session->filename);
2923 char backup_path[BCTEXTLEN];
2924 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2925 File::get_config_path(), BACKUP_FILE);
2926 edl->save_xml(&file, backup_path, 0, 0);
2927 file.terminate_string();
2929 fs.complete_path(backup_path);
2931 if(file.write_to_file(backup_path))
2934 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
2935 gui->show_message(string2);
2939 void MWindow::load_backup()
2941 ArrayList<char*> path_list;
2942 path_list.set_array_delete();
2944 char backup_path[BCTEXTLEN];
2945 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2946 File::get_config_path(), BACKUP_FILE);
2948 fs.complete_path(backup_path);
2950 path_list.append(out_path = new char[strlen(backup_path) + 1]);
2951 strcpy(out_path, backup_path);
2953 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2954 edl->local_session->clip_title[0] = 0;
2955 // This is unique to backups since the path of the backup is different than the
2956 // path of the project.
2957 set_filename(edl->path);
2958 path_list.remove_all_objects();
2962 static inline int gcd(int m, int n)
2965 if( m < n ) { r = m; m = n; n = r; }
2966 while( (r = m % n) != 0 ) { m = n; n = r; }
2970 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2973 if(!width || !height) return 1;
2974 if( width == 720 && (height == 480 || height == 576) ) {
2975 w = 4; h = 3; return 0; // for NTSC and PAL
2977 double ar = (double)width / height;
2978 // square-ish pixels
2979 if( EQUIV(ar, 1.0000) ) return 0;
2980 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2981 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2982 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2983 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2984 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2985 int ww = width, hh = height;
2986 // numerator, denominator must be under mx
2987 int mx = 255, n = gcd(ww, hh);
2988 if( n > 1 ) { ww /= n; hh /= n; }
2989 // search near height in case extra/missing lines
2990 if( ww >= mx || hh >= mx ) {
2991 double err = height; // +/- 2 percent height
2992 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2993 int iw = width, ih = height+i;
2994 if( (n=gcd(iw, ih)) > 1 ) {
2995 int u = iw/n; if( u >= mx ) continue;
2996 int v = ih/n; if( v >= mx ) continue;
2997 double r = (double) u/v, er = fabs(ar-r);
2998 if( er >= err ) continue;
2999 err = er; ww = u; hh = v;
3008 void MWindow::reset_caches()
3010 frame_cache->remove_all();
3011 wave_cache->remove_all();
3012 audio_cache->remove_all();
3013 video_cache->remove_all();
3014 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3015 cwindow->playback_engine->audio_cache->remove_all();
3016 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3017 cwindow->playback_engine->video_cache->remove_all();
3019 for(int i = 0; i < vwindows.size(); i++) {
3020 VWindow *vwindow = vwindows[i];
3021 if( !vwindow->is_running() ) continue;
3022 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3023 vwindow->playback_engine->audio_cache->remove_all();
3024 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3025 vwindow->playback_engine->video_cache->remove_all();
3029 void MWindow::remove_asset_from_caches(Asset *asset)
3031 gui->resource_thread->get_video_source(0);
3032 gui->resource_thread->get_audio_source(0);
3033 frame_cache->remove_asset(asset);
3034 wave_cache->remove_asset(asset);
3035 audio_cache->delete_entry(asset);
3036 video_cache->delete_entry(asset);
3037 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3038 cwindow->playback_engine->audio_cache->delete_entry(asset);
3039 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3040 cwindow->playback_engine->video_cache->delete_entry(asset);
3041 for(int i = 0; i < vwindows.size(); i++) {
3042 VWindow *vwindow = vwindows[i];
3043 if( !vwindow->is_running() ) continue;
3044 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3045 vwindow->playback_engine->audio_cache->delete_entry(asset);
3046 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3047 vwindow->playback_engine->video_cache->delete_entry(asset);
3052 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3053 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3055 for(int i = 0; i < session->drag_assets->total; i++) {
3056 Indexable *indexable = session->drag_assets->get(i);
3057 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3060 // Remove from VWindow.
3061 for(int i = 0; i < session->drag_clips->total; i++) {
3062 for(int j = 0; j < vwindows.size(); j++) {
3063 VWindow *vwindow = vwindows[j];
3064 if( !vwindow->is_running() ) continue;
3065 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3066 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3067 vwindow->delete_source(1, 1);
3068 vwindow->gui->unlock_window();
3073 for(int i = 0; i < session->drag_assets->size(); i++) {
3074 for(int j = 0; j < vwindows.size(); j++) {
3075 VWindow *vwindow = vwindows[j];
3076 if( !vwindow->is_running() ) continue;
3077 if(session->drag_assets->get(i) == vwindow->get_source()) {
3078 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3079 vwindow->delete_source(1, 1);
3080 vwindow->gui->unlock_window();
3085 for(int i = 0; i < session->drag_assets->size(); i++) {
3086 Indexable *indexable = session->drag_assets->get(i);
3087 remove_indexfile(indexable);
3090 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3091 if(push_undo) undo->update_undo_before();
3092 if(drag_assets) edl->remove_from_project(drag_assets);
3093 if(drag_clips) edl->remove_from_project(session->drag_clips);
3094 if(redraw) save_backup();
3095 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3100 gui->lock_window("MWindow::remove_assets_from_project 3");
3108 gui->unlock_window();
3110 // Removes from playback here
3111 sync_parameters(CHANGE_ALL);
3114 awindow->gui->async_update_assets();
3117 void MWindow::remove_assets_from_disk()
3120 for(int i = 0; i < session->drag_assets->total; i++)
3122 remove(session->drag_assets->get(i)->path);
3125 remove_assets_from_project(1,
3127 session->drag_assets,
3128 session->drag_clips);
3131 void MWindow::dump_plugins(FILE *fp)
3133 if( !plugindb ) return;
3134 for(int i = 0; i < plugindb->total; i++)
3136 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3137 " synth=%d transition=%d theme=%d %s\n",
3138 plugindb->get(i)->plugin_type,
3139 plugindb->get(i)->audio,
3140 plugindb->get(i)->video,
3141 plugindb->get(i)->realtime,
3142 plugindb->get(i)->multichannel,
3143 plugindb->get(i)->get_synthesis(),
3144 plugindb->get(i)->transition,
3145 plugindb->get(i)->theme,
3146 plugindb->get(i)->title);
3150 void MWindow::dump_edl(FILE *fp)
3156 void MWindow::dump_undo(FILE *fp)
3162 void MWindow::dump_exe(FILE *fp)
3164 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3165 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3167 int ret = -1, n = 100;
3168 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3169 exe_path[len] = 0; strcpy(proc_path, exe_path);
3172 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3175 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3176 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3177 struct tm *tm = localtime(&st.st_mtime);
3179 strftime(mtime, sizeof(mtime), "%F %T", tm);
3180 fprintf(fp,"mtime: %s\n", mtime);
3182 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3183 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3186 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3187 int64_t maxsz = 1024*pagsz;
3188 int64_t size = st.st_size, pos = 0;
3190 while( (bfrsz = size-pos) > 0 ) {
3191 if( bfrsz > maxsz ) bfrsz = maxsz;
3192 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3193 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3194 if( bfr == MAP_FAILED ) break;
3195 sha1.addBytes(bfr, bfrsz);
3200 ret = pos < size ? EIO : 0;
3201 fprintf(fp, "SHA1: ");
3202 uint8_t digest[20]; sha1.computeHash(digest);
3203 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3204 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3205 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3209 void MWindow::trap_hook(FILE *fp, void *vp)
3211 MWindow *mwindow = (MWindow *)vp;
3212 // fprintf(fp, "\nPLUGINS:\n");
3213 // mwindow->dump_plugins(fp);
3214 fprintf(fp, "\nEDL:\n");
3215 mwindow->dump_edl(fp);
3216 fprintf(fp, "\nUNDO:\n");
3217 mwindow->dump_undo(fp);
3218 fprintf(fp, "\nEXE:\n");
3219 mwindow->dump_exe(fp);
3227 int MWindow::save_defaults()
3229 gui->save_defaults(defaults);
3230 edl->save_defaults(defaults);
3231 session->save_defaults(defaults);
3232 preferences->save_defaults(defaults);
3234 for(int i = 0; i < plugin_guis->total; i++)
3236 // Pointer comparison
3237 plugin_guis->get(i)->save_defaults();
3239 awindow->save_defaults(defaults);
3245 int MWindow::run_script(FileXML *script)
3247 int result = 0, result2 = 0;
3248 while(!result && !result2)
3250 result = script->read_tag();
3253 if(script->tag.title_is("new_project"))
3255 // Run new in immediate mode.
3256 // gui->mainmenu->new_project->run_script(script);
3259 if(script->tag.title_is("record"))
3261 // Run record as a thread. It is a terminal command.
3263 // Will read the complete scipt file without letting record read it if not
3269 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3276 // ================================= synchronization
3279 int MWindow::interrupt_indexes()
3281 mainprogress->cancelled = 1;
3282 mainindexes->interrupt_build();
3288 void MWindow::next_time_format()
3290 switch(edl->session->time_format)
3292 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3293 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3294 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3295 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3296 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3297 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3298 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3301 time_format_common();
3304 void MWindow::prev_time_format()
3306 switch(edl->session->time_format)
3308 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3309 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3310 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3311 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3312 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3313 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3314 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3317 time_format_common();
3320 void MWindow::time_format_common()
3322 gui->lock_window("MWindow::next_time_format");
3323 gui->redraw_time_dependancies();
3326 char string[BCTEXTLEN], string2[BCTEXTLEN];
3327 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3328 gui->show_message(string);
3330 gui->unlock_window();
3334 int MWindow::set_filename(const char *filename)
3336 if( filename != session->filename )
3337 strcpy(session->filename, filename);
3338 if( filename != edl->path )
3339 strcpy(edl->path, filename);
3343 if(filename[0] == 0)
3345 gui->set_title(PROGRAM_NAME);
3350 char string[BCTEXTLEN], string2[BCTEXTLEN];
3351 dir.extract_name(string, filename);
3352 sprintf(string2, PROGRAM_NAME ": %s", string);
3353 gui->set_title(string2);
3366 int MWindow::set_loop_boundaries()
3368 double start = edl->local_session->get_selectionstart();
3369 double end = edl->local_session->get_selectionend();
3377 if(edl->tracks->total_length())
3380 end = edl->tracks->total_length();
3387 if(edl->local_session->loop_playback && start != end)
3389 edl->local_session->loop_start = start;
3390 edl->local_session->loop_end = end;
3401 int MWindow::reset_meters()
3403 cwindow->gui->lock_window("MWindow::reset_meters 1");
3404 cwindow->gui->meters->reset_meters();
3405 cwindow->gui->unlock_window();
3407 for(int j = 0; j < vwindows.size(); j++) {
3408 VWindow *vwindow = vwindows[j];
3409 if( !vwindow->is_running() ) continue;
3410 vwindow->gui->lock_window("MWindow::reset_meters 2");
3411 vwindow->gui->meters->reset_meters();
3412 vwindow->gui->unlock_window();
3415 lwindow->gui->lock_window("MWindow::reset_meters 3");
3416 lwindow->gui->panel->reset_meters();
3417 lwindow->gui->unlock_window();
3419 gui->lock_window("MWindow::reset_meters 4");
3420 gui->reset_meters();
3421 gui->unlock_window();
3426 void MWindow::resync_guis()
3430 gui->lock_window("MWindow::resync_guis");
3431 gui->update(1, 1, 1, 1, 1, 1, 0);
3432 gui->unlock_window();
3434 cwindow->gui->lock_window("MWindow::resync_guis");
3435 cwindow->gui->resize_event(cwindow->gui->get_w(),
3436 cwindow->gui->get_h());
3437 int channels = edl->session->audio_channels;
3438 cwindow->gui->meters->set_meters(channels, 1);
3439 cwindow->gui->flush();
3440 cwindow->gui->unlock_window();
3442 for(int i = 0; i < vwindows.size(); i++) {
3443 VWindow *vwindow = vwindows[i];
3444 if( !vwindow->is_running() ) continue;
3445 vwindow->gui->lock_window("MWindow::resync_guis");
3446 vwindow->gui->resize_event(vwindow->gui->get_w(),
3447 vwindow->gui->get_h());
3448 vwindow->gui->meters->set_meters(channels, 1);
3449 vwindow->gui->flush();
3450 vwindow->gui->unlock_window();
3453 lwindow->gui->lock_window("MWindow::resync_guis");
3454 lwindow->gui->panel->set_meters(channels, 1);
3455 lwindow->gui->flush();
3456 lwindow->gui->unlock_window();
3459 if(((edl->session->output_w % 4) ||
3460 (edl->session->output_h % 4)) &&
3461 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3463 MainError::show_error(
3464 _("This project's dimensions are not multiples of 4 so\n"
3465 "it can't be rendered by OpenGL."));
3470 sync_parameters(CHANGE_ALL);
3473 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3475 File *file = new File;
3476 EDLSession *session = edl->session;
3477 double old_framerate = session->frame_rate;
3478 double old_samplerate = session->sample_rate;
3479 int result = file->open_file(preferences, asset, 1, 0);
3480 if( !result && delete_tracks > 0 )
3481 undo->update_undo_before();
3482 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3483 // try to get asset up to date, may fail
3484 file->select_video_stream(asset, vstream);
3485 // either way use what was/is there.
3486 double framerate = asset->get_frame_rate();
3487 int width = asset->get_w();
3488 int height = asset->get_h();
3489 // must be multiple of 4 for opengl
3490 width = (width+3) & ~3; height = (height+3) & ~3;
3491 int driver = session->playback_config->vconfig->driver;
3492 int color_model = file->get_best_colormodel(asset, driver);
3493 // color_model = BC_CModels::is_yuv(color_model) ?
3494 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3495 // BC_CModels::is_float(color_model) ?
3496 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3497 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3498 // have alpha for now
3499 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3500 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3501 session->color_model = color_model;
3502 session->output_w = width;
3503 session->output_h = height;
3504 session->frame_rate = framerate;
3505 // not, asset->actual_width/actual_height
3506 asset->width = session->output_w;
3507 asset->height = session->output_h;
3508 asset->frame_rate = session->frame_rate;
3509 create_aspect_ratio(session->aspect_w, session->aspect_h,
3510 session->output_w, session->output_h);
3511 Track *track = edl->tracks->first;
3512 for( Track *next_track=0; track; track=next_track ) {
3513 next_track = track->next;
3514 if( track->data_type != TRACK_VIDEO ) continue;
3515 if( delete_tracks ) {
3516 Edit *edit = track->edits->first;
3517 for( Edit *next_edit=0; edit; edit=next_edit ) {
3518 next_edit = edit->next;
3519 if( edit->channel != vstream ||
3520 !edit->asset || !edit->asset->is_asset ||
3521 *asset != *edit->asset )
3525 if( track->edits->first ) {
3526 track->track_w = edl->session->output_w;
3527 track->track_h = edl->session->output_h;
3529 else if( delete_tracks )
3530 edl->tracks->delete_track(track);
3532 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3534 if( !result && asset->audio_data && asset->channels > 0 ) {
3535 session->sample_rate = asset->get_sample_rate();
3536 int64_t channel_mask = 0;
3537 int astrm = !asset->video_data ? -1 :
3538 file->get_audio_for_video(vstream, astream, channel_mask);
3539 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3540 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3542 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3543 if( channels < 1 ) channels = 1;
3544 if( channels > 6 ) channels = 6;
3545 session->audio_tracks = session->audio_channels = channels;
3546 switch( channels ) {
3548 session->achannel_positions[0] = 90;
3549 session->achannel_positions[1] = 150;
3550 session->achannel_positions[2] = 30;
3551 session->achannel_positions[3] = 210;
3552 session->achannel_positions[4] = 330;
3553 session->achannel_positions[5] = 270;
3556 session->achannel_positions[0] = 180;
3557 session->achannel_positions[1] = 0;
3560 session->achannel_positions[1] = 90;
3563 if( !channels ) break;
3564 double t = 0, dt = 360./channels;
3565 for( int i=channels; --i>=0; t+=dt )
3566 session->achannel_positions[i] = int(t+0.5);
3569 remap_audio(MWindow::AUDIO_1_TO_1);
3571 if( delete_tracks ) {
3572 Track *track = edl->tracks->first;
3573 for( Track *next_track=0; track; track=next_track ) {
3574 next_track = track->next;
3575 if( track->data_type != TRACK_AUDIO ) continue;
3576 Edit *edit = track->edits->first;
3577 for( Edit *next_edit=0; edit; edit=next_edit ) {
3578 next_edit = edit->next;
3579 if( !((1<<edit->channel) & channel_mask) ||
3580 !edit->asset || !edit->asset->is_asset ||
3581 *asset != *edit->asset )
3584 if( !track->edits->first )
3585 edl->tracks->delete_track(track);
3589 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3592 if( !result && delete_tracks > 0 ) {
3594 undo->update_undo_after(_("select asset"), LOAD_ALL);
3600 int MWindow::select_asset(int vtrack, int delete_tracks)
3602 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3604 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3605 if( !track ) return 1;
3606 Edit *edit = track->edits->first;
3607 if( !edit ) return 1;
3608 Asset *asset = edit->asset;
3609 if( !asset || !asset->is_asset ) return 1;
3610 return select_asset(asset, edit->channel, 0, delete_tracks);
3613 void MWindow::dump_plugindb(FILE *fp)
3615 if( !plugindb ) return;
3616 for(int i = 0; i < plugindb->total; i++)
3617 plugindb->get(i)->dump(fp);