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"
24 #include "awindowgui.h"
26 #include "batchrender.h"
27 #include "bcdisplayinfo.h"
28 #include "bcsignals.h"
34 #include "channeldb.h"
35 #include "channelinfo.h"
37 #include "bccmodels.h"
38 #include "commercials.h"
39 #include "cplayback.h"
41 #include "cwindowgui.h"
43 #include "cwindowtool.h"
45 #include "devicedvbinput.inc"
46 #include "dvdcreate.h"
47 #include "editpanel.h"
49 #include "edlsession.h"
51 #include "fileformat.h"
53 #include "filesystem.h"
55 #include "framecache.h"
57 #include "gwindowgui.h"
58 #include "keyframegui.h"
59 #include "indexfile.h"
60 #include "interlacemodes.h"
62 #include "levelwindowgui.h"
63 #include "levelwindow.h"
64 #include "loadfile.inc"
65 #include "localsession.h"
66 #include "maincursor.h"
67 #include "mainerror.h"
68 #include "mainindexes.h"
70 #include "mainprogress.h"
71 #include "mainsession.h"
75 #include "mwindowgui.h"
77 #include "nestededls.h"
80 #include "playback3d.h"
81 #include "playbackengine.h"
83 #include "pluginserver.h"
84 #include "pluginset.h"
85 #include "preferences.h"
87 #include "recordmonitor.h"
88 #include "recordlabel.h"
89 #include "removefile.h"
91 #include "resourcethread.h"
92 #include "samplescroll.h"
94 #include "sighandler.h"
95 #include "splashgui.h"
96 #include "statusbar.h"
98 #include "threadloader.h"
100 #include "tipwindow.h"
101 #include "trackcanvas.h"
103 #include "tracking.h"
104 #include "trackscroll.h"
106 #include "transition.h"
107 #include "transportque.h"
109 #include "videodevice.inc"
110 #include "videowindow.h"
111 #include "vplayback.h"
112 #include "vwindowgui.h"
114 #include "wavecache.h"
117 #include "exportedl.h"
119 #include "defaultformats.h"
120 #include "ntsczones.h"
127 #include <sys/types.h>
128 #include <sys/stat.h>
129 #include <sys/time.h>
130 #include <sys/mman.h>
141 // Hack for libdv to remove glib dependancy
144 // g_log (const char *log_domain,
146 // const char *format,
152 // g_logv (const char *log_domain,
154 // const char *format,
164 ArrayList<PluginServer*>* MWindow::plugindb = 0;
165 Commercials* MWindow::commercials = 0;
171 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
172 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
173 vwindows_lock = new Mutex("MWindow::vwindows_lock");
174 brender_lock = new Mutex("MWindow::brender_lock");
175 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
183 commercial_active = 0;
194 channeldb_buz = new ChannelDB;
195 channeldb_v4l2jpeg = new ChannelDB;
199 keyframe_threads = 0;
219 // Need to delete brender temporary here.
225 //printf("MWindow::~MWindow %d\n", __LINE__);
227 gui->remote_control->deactivate();
230 gui->channel_info->stop();
232 brender_lock->lock("MWindow::quit");
233 delete brender; brender = 0;
234 brender_lock->unlock();
235 delete create_bd; create_bd = 0;
236 delete create_dvd; create_dvd = 0;
237 delete batch_render; batch_render = 0;
238 delete render; render = 0;
240 if( commercials && !commercials->remove_user() ) commercials = 0;
242 // Save defaults for open plugins
243 plugin_gui_lock->lock("MWindow::~MWindow");
244 for(int i = 0; i < plugin_guis->size(); i++) {
245 plugin_guis->get(i)->hide_gui();
246 delete_plugin(plugin_guis->get(i));
248 plugin_gui_lock->unlock();
249 hide_keyframe_guis();
252 // Give up and go to a movie
253 // cant run valgrind if this is used
255 gui->del_keyboard_listener(
256 (int (BC_WindowBase::*)(BC_WindowBase *))
257 &MWindowGUI::keyboard_listener);
259 // release the hounds
260 if( awindow && awindow->gui ) awindow->gui->close(0);
261 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
262 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
263 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
264 if( twindow && twindow->is_running() ) twindow->close_window();
265 if( wwindow && wwindow->is_running() ) wwindow->close_window();
266 vwindows.remove_all_objects();
268 if( awindow ) awindow->join();
269 if( cwindow ) cwindow->join();
270 if( lwindow ) lwindow->join();
271 if( twindow ) twindow->join();
272 if( wwindow ) wwindow->join();
273 if( gwindow ) gwindow->join();
276 // one at a time, or nouveau chokes
277 #define close_gui(win) if( win ) { \
278 if( win->gui ) win->gui->close(0); \
286 vwindows.remove_all_objects();
291 dead_plugins->remove_all_objects();
294 keyframe_threads->remove_all_objects();
295 colormodels.remove_all_objects();
296 delete awindow; awindow = 0;
297 delete lwindow; lwindow = 0;
298 delete twindow; twindow = 0;
299 delete wwindow; wwindow = 0;
300 delete gwindow; gwindow = 0;
301 delete cwindow; cwindow = 0;
303 //delete file_server; file_server = 0; // reusable
304 delete mainindexes; mainindexes = 0;
305 delete mainprogress; mainprogress = 0;
306 delete audio_cache; audio_cache = 0; // delete the cache after the assets
307 delete video_cache; video_cache = 0; // delete the cache after the assets
308 delete frame_cache; frame_cache = 0;
309 delete wave_cache; wave_cache = 0;
310 delete plugin_guis; plugin_guis = 0;
311 delete dead_plugins; dead_plugins = 0;
312 delete keyframe_threads; keyframe_threads = 0;
313 delete undo; undo = 0;
314 delete preferences; preferences = 0;
315 delete exportedl; exportedl = 0;
316 delete session; session = 0;
317 delete defaults; defaults = 0;
318 delete assets; assets = 0;
319 delete splash_window; splash_window = 0;
320 // delete theme; theme = 0; // deleted by delete_plugins
321 if( !edl->Garbage::remove_user() ) edl = 0;
322 delete channeldb_buz;
323 delete channeldb_v4l2jpeg;
324 // This must be last thread to exit
325 delete playback_3d; playback_3d = 0;
326 delete dead_plugin_lock;
327 delete plugin_gui_lock;
328 delete vwindows_lock;
330 delete keyframe_gui_lock;
331 colormodels.remove_all_objects();
332 interlace_project_modes.remove_all_objects();
333 interlace_asset_modes.remove_all_objects();
334 interlace_asset_fixmethods.remove_all_objects();
335 sighandler->terminate();
340 void MWindow::quit(int unlock)
342 if(unlock) gui->unlock_window();
345 brender_lock->lock("MWindow::quit");
346 delete brender; brender = 0;
347 brender_lock->unlock();
353 if(unlock) gui->lock_window("MWindow::quit");
356 void MWindow::init_error()
358 MainError::init_error(this);
361 void MWindow::finit_error()
363 MainError::finit_error();
366 void MWindow::create_defaults_path(char *string, const char *config_file)
368 // set the .bcast path
371 sprintf(string, "%s/", File::get_config_path());
372 fs.complete_path(string);
373 if(!fs.is_dir(string))
374 fs.create_dir(string);
377 strcat(string, config_file);
379 const char *MWindow::default_std()
381 char buf[BCTEXTLEN], *p = 0;
383 int fd = open(TIMEZONE_NAME, O_RDONLY);
385 int l = read(fd, buf, sizeof(buf)-1);
388 if( buf[l-1] == '\n' ) --l;
394 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
397 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
398 p += strlen(ZONEINFO_STR);
403 for( int i=0; ntsc_zones[i]; ++i ) {
404 if( !strcmp(ntsc_zones[i], p) )
411 for( int i=0; ntsc_zones[i]; ++i ) {
412 if( !strcmp(ntsc_zones[i], p) )
417 //__timezone: Seconds west of UTC. 240sec/deg
418 double tz_deg = -__timezone / 240.;
419 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
420 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
423 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
425 struct formatpresets *fpr;
427 for(fpr = &format_presets[0]; fpr->name; fpr++)
429 if(strcmp(_(fpr->name), preset) == 0)
431 session->audio_channels = fpr->audio_channels;
432 session->audio_tracks = fpr->audio_tracks;
433 session->sample_rate = fpr->sample_rate;
434 session->video_channels = fpr->video_channels;
435 session->video_tracks = fpr->video_tracks;
436 session->frame_rate = fpr->frame_rate;
437 session->output_w = fpr->output_w;
438 session->output_h = fpr->output_h;
439 session->aspect_w = fpr->aspect_w;
440 session->aspect_h = fpr->aspect_h;
441 session->interlace_mode = fpr->interlace_mode;
442 session->color_model = fpr->color_model;
448 const char *MWindow::get_preset_name(int index)
450 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
452 return _(format_presets[index].name);
456 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
458 char path[BCTEXTLEN];
459 // Use user supplied path
461 strcpy(path, config_path);
463 create_defaults_path(path, CONFIG_FILE);
465 defaults = new BC_Hash(path);
469 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
471 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
473 const char *dp = plug_dir;
474 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
475 bp = !*dp && *bp == '/' ? bp+1 : base_path;
481 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
484 FILE *fp = fopen(index_path, "r");
488 char index_line[BCTEXTLEN];
489 int index_version = -1, len = strlen(plugin_dir);
490 if( !fgets(index_line, BCTEXTLEN, fp) ||
491 sscanf(index_line, "%d", &index_version) != 1 ||
492 index_version != PLUGIN_FILE_VERSION ||
493 !fgets(index_line, BCTEXTLEN, fp) ||
494 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
495 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
497 ArrayList<PluginServer*> plugins;
498 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
499 if( index_line[0] == ';' ) continue;
500 if( index_line[0] == '#' ) continue;
501 int type = PLUGIN_TYPE_UNKNOWN;
502 char path[BCTEXTLEN], title[BCTEXTLEN];
504 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
507 PluginServer *server = 0;
509 case PLUGIN_TYPE_BUILTIN:
510 case PLUGIN_TYPE_EXECUTABLE:
511 case PLUGIN_TYPE_LADSPA: {
512 char plugin_path[BCTEXTLEN]; struct stat st;
513 sprintf(plugin_path, "%s/%s", plugin_dir, path);
514 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
517 server = new PluginServer(mwindow, plugin_path, type);
519 case PLUGIN_TYPE_FFMPEG: {
520 server = new_ffmpeg_server(mwindow, path);
523 if( !server ) continue;
524 plugins.append(server);
525 // Create plugin server from index entry
526 server->set_title(title);
527 if( server->read_table(index_line) ) {
534 ret = check_plugin_index(plugins, plugin_dir, ".");
537 add_plugins(plugins);
539 plugins.remove_all_objects();
544 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
545 const char *plug_dir, const char *plug_path)
547 char plugin_path[BCTEXTLEN];
548 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
550 fs.set_filter( "[*.plugin][*.so]" );
551 if( fs.update(plugin_path) )
554 for( int i=0; i<fs.dir_list.total; ++i ) {
555 char fs_path[BCTEXTLEN];
556 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
557 if( fs.is_dir(fs_path) ) {
558 get_plugin_path(plugin_path, plug_dir, fs_path);
559 if( check_plugin_index(plugins, plug_dir, plugin_path) )
562 else if( !plugin_exists(fs_path, plugins) )
569 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
572 plugindb = new ArrayList<PluginServer*>;
574 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
575 create_defaults_path(index_path, PLUGIN_FILE);
576 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
577 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
578 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
579 printf("init plugin index: %s\n", plugin_path);
580 FILE *fp = fopen(index_path,"w");
582 fprintf(stderr,_("MWindow::init_plugins: "
583 "can't create plugin index: %s\n"), index_path);
586 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
587 fprintf(fp, "%s\n", plugin_path);
588 init_plugin_index(mwindow, preferences, fp, plugin_path);
589 init_ffmpeg_index(mwindow, preferences, fp);
591 return load_plugin_index(mwindow, index_path, plugin_path);
594 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
596 char *path = getenv("LADSPA_PATH");
597 char ladspa_path[BCTEXTLEN];
599 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
602 for( int len=0; *path; path+=len ) {
603 char *cp = strchr(path,':');
604 len = !cp ? strlen(path) : cp-path;
605 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
606 memcpy(plugin_path, path, len); plugin_path[len] = 0;
607 char *plugin_dir = FileSystem::basepath(plugin_path);
608 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
609 create_defaults_path(index_path, LADSPA_FILE);
610 cp = index_path + strlen(index_path);
611 for( char *bp=plugin_path; *bp!=0; ++bp )
612 *cp++ = *bp=='/' ? '_' : *bp;
614 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
615 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
616 load_plugin_index(mwindow, index_path, plugin_path);
621 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
622 FILE *fp, const char *plugin_dir)
624 int idx = PLUGIN_IDS;
626 for( int i=0; i<plugindb->size(); ++i ) {
627 PluginServer *server = plugindb->get(i);
628 if( server->dir_idx >= idx )
629 idx = server->dir_idx+1;
632 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
635 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
636 const char *index_path, const char *plugin_dir)
638 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
639 strcpy(plugin_path, path); delete [] path;
640 printf("init ladspa index: %s\n", plugin_dir);
641 FILE *fp = fopen(index_path,"w");
643 fprintf(stderr,_("MWindow::init_ladspa_index: "
644 "can't create plugin index: %s\n"), index_path);
647 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
648 fprintf(fp, "%s\n", plugin_dir);
649 init_plugin_index(mwindow, preferences, fp, plugin_path);
654 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
655 const char *plug_dir, const char *plug_path, int &idx)
657 char plugin_path[BCTEXTLEN];
658 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
660 fs.set_filter( "[*.plugin][*.so]" );
661 int result = fs.update(plugin_path);
662 if( result || !fs.dir_list.total ) return;
665 for( int i=0; i<fs.dir_list.total; ++i ) {
666 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
667 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
668 get_plugin_path(path, plug_dir, fs_path);
669 if( fs.is_dir(fs_path) ) {
670 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
673 if( plugin_exists(path) ) continue;
675 if( stat(fs_path, &st) ) continue;
676 int64_t mtime = st.st_mtime;
677 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
678 result = server.open_plugin(1, preferences, 0, 0);
680 server.write_table(fp, path, vis_id, mtime);
681 server.close_plugin();
683 else if( result == PLUGINSERVER_IS_LAD ) {
686 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
687 ladspa.set_lad_index(lad_index++);
688 result = ladspa.open_plugin(1, preferences, 0, 0);
690 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
691 ladspa.close_plugin();
697 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
699 for( int i=0; i<plugins.size(); ++i )
700 plugindb->append(plugins[i]);
701 plugins.remove_all();
704 void MWindow::delete_plugins()
706 plugindb->remove_all_objects();
711 void MWindow::search_plugindb(int do_audio,
716 ArrayList<PluginServer*> &results)
719 for(int i = 0; i < MWindow::plugindb->total; i++)
721 PluginServer *current = MWindow::plugindb->get(i);
723 if(current->audio == do_audio &&
724 current->video == do_video &&
725 (current->realtime == is_realtime || is_realtime < 0) &&
726 current->transition == is_transition &&
727 current->theme == is_theme)
728 results.append(current);
731 // Alphabetize list by title
737 for(int i = 0; i < results.total - 1; i++)
739 PluginServer *value1 = results[i];
740 PluginServer *value2 = results[i + 1];
741 if(strcmp(_(value1->title), _(value2->title)) > 0)
745 results[i + 1] = value1;
751 PluginServer* MWindow::scan_plugindb(char *title,
756 // printf("MWindow::scan_plugindb data_type < 0\n");
760 for(int i = 0; i < plugindb->total; i++)
762 PluginServer *server = plugindb->get(i);
764 !strcasecmp(server->title, title) &&
766 (data_type == TRACK_AUDIO && server->audio) ||
767 (data_type == TRACK_VIDEO && server->video)))
768 return plugindb->get(i);
773 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
775 for( int i=0; i<plugins.size(); ++i )
776 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
780 int MWindow::plugin_exists(char *plugin_path)
782 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
785 void MWindow::init_preferences()
787 preferences = new Preferences;
788 preferences->load_defaults(defaults);
789 session = new MainSession(this);
790 session->load_defaults(defaults);
791 // set x11_host, screens, window_config
792 screens = session->set_default_x11_host();
793 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
794 BC_Signals::set_trap_hook(trap_hook, this);
795 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
796 BC_Signals::set_catch_intr(preferences->trap_sigintr);
799 void MWindow::clean_indexes()
804 int oldest_item = -1;
806 char string[BCTEXTLEN];
807 char string2[BCTEXTLEN];
809 // Delete extra indexes
810 fs.set_filter("*.idx");
811 fs.complete_path(preferences->index_directory);
812 fs.update(preferences->index_directory);
813 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
815 // Eliminate directories
820 for(int i = 0; i < fs.dir_list.total && !result; i++)
822 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
823 if(fs.is_dir(string))
825 delete fs.dir_list[i];
826 fs.dir_list.remove_number(i);
831 total_excess = fs.dir_list.total - preferences->index_count;
833 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
834 while(total_excess > 0)
837 for(int i = 0; i < fs.dir_list.total; i++)
839 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
841 if(i == 0 || fs.get_date(string) <= oldest)
843 oldest = fs.get_date(string);
851 fs.join_names(string,
852 preferences->index_directory,
853 fs.dir_list[oldest_item]->name);
854 //printf("MWindow::clean_indexes 1 %s\n", string);
856 perror("delete_indexes");
857 delete fs.dir_list[oldest_item];
858 fs.dir_list.remove_number(oldest_item);
860 // Remove table of contents if it exists
861 strcpy(string2, string);
862 char *ptr = strrchr(string2, '.');
865 //printf("MWindow::clean_indexes 2 %s\n", string2);
866 sprintf(ptr, ".toc");
868 sprintf(ptr, ".mkr");
877 void MWindow::init_awindow()
879 awindow = new AWindow(this);
880 awindow->create_objects();
883 void MWindow::init_gwindow()
885 gwindow = new GWindow(this);
886 gwindow->create_objects();
889 void MWindow::init_tipwindow()
892 twindow = new TipWindow(this);
896 void MWindow::show_warning(int *do_warning, const char *text)
898 if( do_warning && !*do_warning ) return;
900 wwindow = new WWindow(this);
901 wwindow->show_warning(do_warning, text);
904 int MWindow::wait_warning()
906 return wwindow->wait_result();
909 void MWindow::init_theme()
914 PluginServer *theme_plugin = 0;
915 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
916 if( plugindb->get(i)->theme &&
917 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
918 theme_plugin = plugindb->get(i);
922 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
925 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
926 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
928 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
929 if( plugindb->get(i)->theme &&
930 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
931 theme_plugin = plugindb->get(i);
936 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
940 PluginServer *plugin = new PluginServer(*theme_plugin);
941 if( plugin->open_plugin(0, preferences, 0, 0) ) {
942 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
943 theme_plugin->title);
947 theme = plugin->new_theme();
948 theme->mwindow = this;
949 strcpy(theme->path, plugin->path);
952 // Load default images & settings
953 theme->Theme::initialize();
954 // Load user images & settings
956 // Create menus with user colors
957 theme->build_menus();
962 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
965 void MWindow::init_3d()
967 playback_3d = new Playback3D(this);
968 playback_3d->create_objects();
971 void MWindow::init_edl()
974 edl->create_objects();
975 fill_preset_defaults(default_standard, edl->session);
976 edl->load_defaults(defaults);
977 edl->create_default_tracks();
978 edl->tracks->update_y_pixels(theme);
981 void MWindow::init_compositor()
983 cwindow = new CWindow(this);
984 cwindow->create_objects();
987 void MWindow::init_levelwindow()
989 lwindow = new LevelWindow(this);
990 lwindow->create_objects();
993 VWindow *MWindow::get_viewer(int start_it, int idx)
995 vwindows_lock->lock("MWindow::get_viewer");
996 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
997 if( !vwindow ) idx = vwindows.size();
998 while( !vwindow && --idx >= 0 ) {
999 VWindow *vwin = vwindows[idx];
1000 if( !vwin->is_running() || !vwin->get_edl() )
1004 vwindow = new VWindow(this);
1005 vwindow->load_defaults();
1006 vwindow->create_objects();
1007 vwindows.append(vwindow);
1009 vwindows_lock->unlock();
1010 if( start_it ) vwindow->start();
1014 void MWindow::init_cache()
1016 audio_cache = new CICache(preferences);
1017 video_cache = new CICache(preferences);
1018 frame_cache = new FrameCache;
1019 wave_cache = new WaveCache;
1022 void MWindow::init_channeldb()
1024 channeldb_buz->load("channeldb_buz");
1025 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1028 void MWindow::init_menus()
1030 char string[BCTEXTLEN];
1033 BC_CModels::to_text(string, BC_RGB888);
1034 colormodels.append(new ColormodelItem(string, BC_RGB888));
1035 BC_CModels::to_text(string, BC_RGBA8888);
1036 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1037 // BC_CModels::to_text(string, BC_RGB161616);
1038 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1039 // BC_CModels::to_text(string, BC_RGBA16161616);
1040 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1041 BC_CModels::to_text(string, BC_RGB_FLOAT);
1042 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1043 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1044 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1045 BC_CModels::to_text(string, BC_YUV888);
1046 colormodels.append(new ColormodelItem(string, BC_YUV888));
1047 BC_CModels::to_text(string, BC_YUVA8888);
1048 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1049 // BC_CModels::to_text(string, BC_YUV161616);
1050 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1051 // BC_CModels::to_text(string, BC_YUVA16161616);
1052 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1054 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1055 interlace_project_modes.append(new InterlacemodeItem(string, x));
1057 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1058 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1060 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1061 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1063 // Interlacing Modes
1064 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1066 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1067 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1069 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1070 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1072 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1073 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1075 // Interlacing Fixing Methods
1076 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
1077 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
1078 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
1081 void MWindow::init_indexes()
1083 mainindexes = new MainIndexes(this);
1084 mainindexes->start_loop();
1087 void MWindow::init_gui()
1089 gui = new MWindowGUI(this);
1090 gui->lock_window("MWindow::init_gui");
1091 gui->create_objects();
1092 gui->unlock_window();
1093 gui->load_defaults(defaults);
1096 void MWindow::init_signals()
1098 sighandler = new SigHandler;
1099 sighandler->initialize();
1103 void MWindow::init_render()
1105 render = new Render(this);
1106 create_bd = new CreateBD_Thread(this);
1107 create_dvd = new CreateDVD_Thread(this);
1108 batch_render = new BatchRenderThread(this);
1111 void MWindow::init_exportedl()
1113 exportedl = new ExportEDL(this);
1116 void MWindow::init_brender()
1118 if(preferences->use_brender && !brender)
1120 brender_lock->lock("MWindow::init_brender 1");
1121 brender = new BRender(this);
1122 brender->initialize();
1123 session->brender_end = 0;
1124 brender_lock->unlock();
1127 if(!preferences->use_brender && brender)
1129 brender_lock->lock("MWindow::init_brender 2");
1132 session->brender_end = 0;
1133 brender_lock->unlock();
1135 if(brender) brender->restart(edl);
1138 void MWindow::restart_brender()
1140 //printf("MWindow::restart_brender 1\n");
1141 if(brender) brender->restart(edl);
1144 void MWindow::stop_brender()
1146 if(brender) brender->stop();
1149 int MWindow::brender_available(int position)
1152 brender_lock->lock("MWindow::brender_available 1");
1155 if(brender->map_valid)
1157 brender->map_lock->lock("MWindow::brender_available 2");
1158 if(position < brender->map_size &&
1161 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1162 if(brender->map[position] == BRender::RENDERED)
1165 brender->map_lock->unlock();
1168 brender_lock->unlock();
1172 void MWindow::set_brender_start()
1174 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1176 gui->draw_overlays(1);
1180 int MWindow::has_commercials()
1182 return theme->use_commercials;
1185 void MWindow::init_commercials()
1187 if( !commercials ) {
1188 commercials = new Commercials(this);
1189 commercial_active = 0;
1192 commercials->add_user();
1195 void MWindow::commit_commercial()
1197 if( !commercial_active ) return;
1198 commercial_active = 0;
1199 if( !commercials ) return;
1200 commercials->commitDb();
1203 void MWindow::undo_commercial()
1205 if( !commercial_active ) return;
1206 commercial_active = 0;
1207 if( !commercials ) return;
1208 commercials->undoDb();
1211 int MWindow::put_commercial()
1213 double start = edl->local_session->get_selectionstart();
1214 double end = edl->local_session->get_selectionend();
1215 if( start >= end ) return 0;
1217 const char *errmsg = 0;
1219 Tracks *tracks = edl->tracks;
1222 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1223 if( track->data_type != TRACK_VIDEO ) continue;
1224 if( !track->record ) continue;
1225 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1227 int64_t units_start = track->to_units(start,0);
1228 int64_t units_end = track->to_units(end,0);
1229 Edits *edits = track->edits;
1230 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1231 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1232 if(!edit1 && !edit2) continue; // nothing selected
1233 if(!edit2) { // edit2 beyond end of track
1234 edit2 = edits->last;
1235 units_end = edits->length();
1237 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1238 Indexable *indexable = edit1->get_source();
1239 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1242 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1243 if( track->data_type != TRACK_VIDEO ) continue;
1244 if( !track->record ) continue;
1245 int64_t units_start = track->to_units(start,0);
1246 int64_t units_end = track->to_units(end,0);
1247 Edits *edits = track->edits;
1248 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1249 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1250 if(!edit1 && !edit2) continue; // nothing selected
1251 if(!edit2) { // edit2 beyond end of track
1252 edit2 = edits->last;
1253 units_end = edits->length();
1255 Indexable *indexable = edit1->get_source();
1256 Asset *asset = (Asset *)indexable;
1257 File *file = video_cache->check_out(asset, edl);
1258 if( !file ) { errmsg = _("no file"); break; }
1259 int64_t edit_length = units_end - units_start;
1260 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1261 result = commercials->put_clip(file, edit1->channel,
1262 track->from_units(edit_start), track->from_units(edit_length));
1263 video_cache->check_in(asset);
1264 if( result ) { errmsg = _("db failed"); break; }
1267 char string[BCTEXTLEN];
1268 sprintf(string, _("put_commercial: %s"), errmsg);
1269 MainError::show_error(string);
1276 void MWindow::stop_playback(int wait)
1278 int locked = gui->get_window_lock();
1279 if( locked ) gui->unlock_window();
1281 cwindow->playback_engine->que->send_command(STOP,
1285 cwindow->playback_engine->interrupt_playback(wait);
1287 for(int i = 0; i < vwindows.size(); i++) {
1288 VWindow *vwindow = vwindows[i];
1289 if( !vwindow->is_running() ) continue;
1290 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1291 vwindow->playback_engine->interrupt_playback(wait);
1293 if( locked ) gui->lock_window("MWindow::stop_playback");
1296 int MWindow::load_filenames(ArrayList<char*> *filenames,
1298 int update_filename)
1300 ArrayList<EDL*> new_edls;
1301 ArrayList<Asset*> new_assets;
1302 ArrayList<File*> new_files;
1303 const int debug = 0;
1304 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1307 gui->start_hourglass();
1309 // Need to stop playback since tracking depends on the EDL not getting
1313 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1314 undo->update_undo_before();
1317 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1319 // Define new_edls and new_assets to load
1320 int result = 0, ftype = -1;
1321 for(int i = 0; i < filenames->size(); i++)
1324 File *new_file = new File;
1325 Asset *new_asset = new Asset(filenames->get(i));
1326 EDL *new_edl = new EDL;
1327 char string[BCTEXTLEN];
1329 new_edl->create_objects();
1330 new_edl->copy_session(edl);
1331 new_file->set_program(edl->session->program_no);
1333 sprintf(string, _("Loading %s"), new_asset->path);
1334 gui->show_message(string);
1335 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1337 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1338 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1343 // Convert media file to EDL
1345 // Warn about odd image dimensions
1346 if(new_asset->video_data &&
1347 ((new_asset->width % 2) ||
1348 (new_asset->height % 2)))
1350 char string[BCTEXTLEN];
1351 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1355 MainError::show_error(string);
1358 if(new_asset->program >= 0 &&
1359 edl->session->program_no != new_asset->program)
1361 char string[BCTEXTLEN];
1362 sprintf(string, _("%s's index was built for program number %d\n"
1363 "Playback preference is %d.\n Using program %d."),
1364 new_asset->path, new_asset->program,
1365 edl->session->program_no, new_asset->program);
1366 MainError::show_error(string);
1370 if(load_mode != LOADMODE_RESOURCESONLY)
1373 RecordLabels *labels = edl->session->label_cells ?
1374 new RecordLabels(new_file) : 0;
1376 asset_to_edl(new_edl, new_asset, labels);
1378 new_edls.append(new_edl);
1380 new_asset->Garbage::remove_user();
1386 new_assets.append(new_asset);
1390 // Set filename to nothing for assets since save EDL would overwrite them.
1391 if(load_mode == LOADMODE_REPLACE ||
1392 load_mode == LOADMODE_REPLACE_CONCATENATE)
1395 // Reset timeline position
1396 for(int i = 0; i < TOTAL_PANES; i++)
1398 new_edl->local_session->view_start[i] = 0;
1399 new_edl->local_session->track_start[i] = 0;
1407 case FILE_NOT_FOUND:
1408 sprintf(string, _("Failed to open %s"), new_asset->path);
1409 gui->show_message(string, theme->message_error);
1413 case FILE_UNRECOGNIZED_CODEC:
1416 IndexFile indexfile(this, new_asset);
1417 result = indexfile.open_index();
1420 indexfile.close_index();
1423 // Test existing EDLs
1424 for(int j = 0; result && j <= new_edls.total; j++) {
1425 Asset *old_asset = j < new_edls.total ?
1426 new_edls[j]->assets->get_asset(new_asset->path) :
1427 edl->assets->get_asset(new_asset->path);
1429 *new_asset = *old_asset;
1437 char string[BCTEXTLEN];
1439 fs.extract_name(string, new_asset->path);
1441 strcat(string, _("'s format couldn't be determined."));
1442 new_asset->audio_data = 1;
1443 new_asset->format = FILE_PCM;
1444 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1445 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1446 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1447 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1448 new_asset->signed_ = defaults->get("SIGNED_", 1);
1449 new_asset->header = defaults->get("HEADER", 0);
1451 FileFormat fwindow(this);
1452 fwindow.create_objects(new_asset, string);
1453 result = fwindow.run_window();
1456 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1457 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1458 defaults->update("AUDIO_BITS", new_asset->bits);
1459 defaults->update("BYTE_ORDER", new_asset->byte_order);
1460 defaults->update("SIGNED_", new_asset->signed_);
1461 defaults->update("HEADER", new_asset->header);
1468 // Recalculate length
1470 new_file = new File;
1471 result = new_file->open_file(preferences, new_asset, 1, 0);
1473 if(load_mode != LOADMODE_RESOURCESONLY)
1475 RecordLabels *labels = edl->session->label_cells ?
1476 new RecordLabels(new_file) : 0;
1477 asset_to_edl(new_edl, new_asset, labels);
1478 new_edls.append(new_edl);
1479 new_asset->Garbage::remove_user();
1485 new_assets.append(new_asset);
1499 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1500 xml_file.read_from_file(filenames->get(i));
1501 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1503 if(load_mode == LOADMODE_NESTED)
1505 // Load temporary EDL for nesting.
1506 EDL *nested_edl = new EDL;
1507 nested_edl->create_objects();
1508 nested_edl->set_path(filenames->get(i));
1509 nested_edl->load_xml(&xml_file, LOAD_ALL);
1510 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1511 edl_to_nested(new_edl, nested_edl);
1512 nested_edl->Garbage::remove_user();
1516 // Load EDL for pasting
1517 new_edl->load_xml(&xml_file, LOAD_ALL);
1518 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1519 test_plugins(new_edl, filenames->get(i));
1520 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1522 if(load_mode == LOADMODE_REPLACE ||
1523 load_mode == LOADMODE_REPLACE_CONCATENATE)
1525 strcpy(session->filename, filenames->get(i));
1526 strcpy(new_edl->local_session->clip_title,
1529 set_filename(new_edl->local_session->clip_title);
1533 new_edls.append(new_edl);
1539 // edls are in new_edls
1540 if( result && new_edl ) new_edl->Garbage::remove_user();
1541 // assets are copied
1542 if( new_asset ) new_asset->Garbage::remove_user();
1544 // Store for testing index
1545 new_files.append(new_file);
1548 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1551 if(!result) gui->statusbar->default_message();
1559 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1562 // Don't back up here.
1565 // For pasting, clear the active region
1566 if(load_mode == LOADMODE_PASTE ||
1567 load_mode == LOADMODE_NESTED)
1569 double start = edl->local_session->get_selectionstart();
1570 double end = edl->local_session->get_selectionend();
1571 if(!EQUIV(start, end))
1574 edl->session->labels_follow_edits,
1575 edl->session->plugins_follow_edits,
1576 edl->session->autos_follow_edits);
1579 paste_edls(&new_edls,
1583 edl->session->labels_follow_edits,
1584 edl->session->plugins_follow_edits,
1585 edl->session->autos_follow_edits,
1592 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1594 // Add new assets to EDL and schedule assets for index building.
1595 int got_indexes = 0;
1596 for(int i = 0; i < new_edls.size(); i++)
1598 EDL *new_edl = new_edls[i];
1599 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1601 mainindexes->add_next_asset(0,
1602 new_edl->nested_edls->get(j));
1604 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1609 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1610 if(new_assets.size())
1612 for(int i = 0; i < new_assets.size(); i++)
1614 Asset *new_asset = new_assets[i];
1618 for(int j = 0; j < new_files.size(); j++)
1620 new_file = new_files[j];
1621 if(!strcmp(new_file->asset->path,
1629 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1631 edl->assets->update(new_asset);
1637 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1639 // Start examining next batch of index files
1640 if(got_indexes) mainindexes->start_build();
1641 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1644 Track *track = edl->tracks->first;
1647 for(int j = 0; j < track->plugin_set.size(); j++)
1649 PluginSet *plugins = track->plugin_set[j];
1650 Plugin *plugin = plugins->get_first_plugin();
1654 if(load_mode == LOADMODE_REPLACE ||
1655 load_mode == LOADMODE_REPLACE_CONCATENATE)
1657 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1660 show_plugin(plugin);
1668 plugin = (Plugin*)plugin->next;
1672 track = track->next;
1675 // if just opening one new resource in replace mode
1676 if( ftype != FILE_IS_XML &&
1677 ( load_mode == LOADMODE_REPLACE ||
1678 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1680 edl->local_session->preview_start = 0;
1681 edl->local_session->preview_end = edl->tracks->total_playable_length();
1682 edl->local_session->loop_playback = 0;
1683 edl->local_session->set_selectionstart(0);
1684 edl->local_session->set_selectionend(0);
1689 // need to update undo before project, since mwindow is unlocked & a new load
1690 // can begin here. Should really prevent loading until we're done.
1691 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1692 undo->update_undo_after(_("load"), LOAD_ALL);
1694 for(int i = 0; i < new_edls.size(); i++)
1696 new_edls[i]->remove_user();
1698 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1700 new_edls.remove_all();
1702 for(int i = 0; i < new_assets.size(); i++)
1704 new_assets[i]->Garbage::remove_user();
1707 new_assets.remove_all();
1708 new_files.remove_all_objects();
1711 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1712 if(load_mode == LOADMODE_REPLACE ||
1713 load_mode == LOADMODE_REPLACE_CONCATENATE)
1715 session->changes_made = 0;
1719 session->changes_made = 1;
1722 gui->stop_hourglass();
1725 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1726 update_project(load_mode);
1728 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1736 void MWindow::test_plugins(EDL *new_edl, char *path)
1738 char string[BCTEXTLEN];
1740 // Do a check weather plugins exist
1741 for(Track *track = new_edl->tracks->first; track; track = track->next)
1743 for(int k = 0; k < track->plugin_set.total; k++)
1745 PluginSet *plugin_set = track->plugin_set[k];
1746 for(Plugin *plugin = (Plugin*)plugin_set->first;
1748 plugin = (Plugin*)plugin->next)
1750 if(plugin->plugin_type == PLUGIN_STANDALONE)
1752 // ok we need to find it in plugindb
1753 int plugin_found = 0;
1755 for(int j = 0; j < plugindb->size(); j++)
1757 PluginServer *server = plugindb->get(j);
1759 !strcasecmp(server->title, plugin->title) &&
1760 ((track->data_type == TRACK_AUDIO && server->audio) ||
1761 (track->data_type == TRACK_VIDEO && server->video)) &&
1762 (!server->transition))
1769 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1770 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1771 "effect", plugin->title,
1773 MainError::show_error(string);
1779 for(Edit *edit = (Edit*)track->edits->first;
1781 edit = (Edit*)edit->next)
1783 if (edit->transition)
1785 // ok we need to find transition in plugindb
1787 int transition_found = 0;
1788 for(int j = 0; j < plugindb->size(); j++)
1790 PluginServer *server = plugindb->get(j);
1792 !strcasecmp(server->title, edit->transition->title) &&
1793 ((track->data_type == TRACK_AUDIO && server->audio) ||
1794 (track->data_type == TRACK_VIDEO && server->video)) &&
1795 (server->transition))
1796 transition_found = 1;
1799 if (!transition_found)
1802 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1803 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1804 "transition", edit->transition->title,
1806 MainError::show_error(string);
1814 void MWindow::init_shm()
1816 // Fix shared memory
1817 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1819 fprintf(fd, "0x7fffffff");
1824 fd = fopen("/proc/sys/kernel/shmmax", "r");
1826 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1831 fscanf(fd, "%jd", &result);
1834 if(result < 0x7fffffff) {
1835 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1836 "you probably need to be root, or:\n"
1837 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1838 "before trying to start cinelerra.\n"
1839 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1843 void MWindow::create_objects(int want_gui,
1848 const int debug = 0;
1849 if(debug) PRINT_TRACE
1851 // For some reason, init_signals must come after show_splash or the signals won't
1854 if(debug) PRINT_TRACE
1857 if(debug) PRINT_TRACE
1860 if(debug) PRINT_TRACE
1861 default_standard = default_std();
1862 init_defaults(defaults, config_path);
1865 splash_window->operation->update(_("Initializing Plugins"));
1866 init_plugins(this, preferences);
1867 if(debug) PRINT_TRACE
1868 init_ladspa_plugins(this, preferences);
1869 if(debug) PRINT_TRACE
1871 splash_window->operation->update(_("Initializing GUI"));
1872 if(debug) PRINT_TRACE
1875 if(debug) PRINT_TRACE
1879 splash_window->operation->update(_("Initializing Fonts"));
1880 char string[BCTEXTLEN];
1881 strcpy(string, preferences->plugin_dir);
1882 strcat(string, "/" FONT_SEARCHPATH);
1883 BC_Resources::init_fontconfig(string);
1884 if(debug) PRINT_TRACE
1886 // Initialize before too much else is running
1887 // Preferences & theme are required for building MPEG table of contents
1889 // Default project created here
1891 if(debug) PRINT_TRACE
1894 if(debug) PRINT_TRACE
1899 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1901 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1902 if(session->show_vwindow)
1903 get_viewer(1, DEFAULT_VWINDOW);
1904 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1907 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1910 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1913 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1915 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1918 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1922 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1924 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1926 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1930 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1931 mainprogress = new MainProgress(this, gui);
1932 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1933 undo = new MainUndo(this);
1935 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1937 plugin_guis = new ArrayList<PluginServer*>;
1938 dead_plugins = new ArrayList<PluginServer*>;
1939 keyframe_threads = new ArrayList<KeyFrameThread*>;
1941 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1944 session->show_vwindow);
1946 // Show all vwindows
1947 // if(session->show_vwindow) {
1948 // for(int j = 0; j < vwindows.size(); j++) {
1949 // VWindow *vwindow = vwindows[j];
1950 // if( !vwindow->is_running() ) continue;
1951 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1954 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1955 // vwindow->gui->lock_window("MWindow::create_objects 1");
1956 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1957 // vwindow->gui->show_window();
1958 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1959 // vwindow->gui->unlock_window();
1964 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1966 if(session->show_cwindow)
1968 cwindow->gui->lock_window("MWindow::create_objects 1");
1969 cwindow->gui->show_window();
1970 cwindow->gui->unlock_window();
1973 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1974 if(session->show_awindow)
1976 awindow->gui->lock_window("MWindow::create_objects 1");
1977 awindow->gui->show_window();
1978 awindow->gui->unlock_window();
1981 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1982 if(session->show_lwindow)
1984 lwindow->gui->lock_window("MWindow::create_objects 1");
1985 lwindow->gui->show_window();
1986 lwindow->gui->unlock_window();
1989 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1991 (int)timer.get_difference(),
1993 if(session->show_gwindow)
1995 gwindow->gui->lock_window("MWindow::create_objects 1");
1996 gwindow->gui->show_window();
1997 gwindow->gui->unlock_window();
2000 if(debug) PRINT_TRACE
2002 gui->lock_window("MWindow::create_objects 1");
2003 gui->mainmenu->load_defaults(defaults);
2004 gui->mainmenu->update_toggles(0);
2005 gui->update_patchbay();
2006 gui->draw_canvas(0, 0);
2007 gui->draw_cursor(1);
2009 gui->raise_window();
2010 gui->unlock_window();
2012 if(debug) PRINT_TRACE
2014 if(preferences->use_tipwindow)
2016 if(debug) PRINT_TRACE
2018 gui->add_keyboard_listener(
2019 (int (BC_WindowBase::*)(BC_WindowBase *))
2020 &MWindowGUI::keyboard_listener);
2024 if(debug) PRINT_TRACE
2026 BC_WindowBase::get_resources()->vframe_shm = 1;
2030 void MWindow::show_splash()
2032 #include "data/heroine_logo9_png.h"
2033 VFrame *frame = new VFramePng(heroine_logo9_png);
2034 BC_DisplayInfo dpyi;
2035 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2036 int rr = (rw < rh ? rw : rh) / 4;
2037 splash_window = new SplashGUI(frame, rr, rr);
2038 splash_window->create_objects();
2041 void MWindow::hide_splash()
2044 delete splash_window;
2049 void MWindow::start()
2053 // vwindows[DEFAULT_VWINDOW]->start();
2064 playback_3d->start();
2073 void MWindow::show_vwindow()
2075 int total_running = 0;
2076 session->show_vwindow = 1;
2078 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2079 // Raise all windows which are visible
2080 for(int j = 0; j < vwindows.size(); j++) {
2081 VWindow *vwindow = vwindows[j];
2082 if( !vwindow->is_running() ) continue;
2083 vwindow->gui->lock_window("MWindow::show_vwindow");
2084 vwindow->gui->show_window(0);
2085 vwindow->gui->raise_window();
2086 vwindow->gui->flush();
2087 vwindow->gui->unlock_window();
2091 // If no windows visible
2094 get_viewer(1, DEFAULT_VWINDOW);
2097 gui->mainmenu->show_vwindow->set_checked(1);
2100 void MWindow::show_awindow()
2102 session->show_awindow = 1;
2103 awindow->gui->lock_window("MWindow::show_awindow");
2104 awindow->gui->show_window();
2105 awindow->gui->raise_window();
2106 awindow->gui->flush();
2107 awindow->gui->unlock_window();
2108 gui->mainmenu->show_awindow->set_checked(1);
2111 char *MWindow::get_cwindow_display()
2113 char *x11_host = screens < 2 || session->window_config == 0 ?
2114 session->a_x11_host : session->b_x11_host;
2115 return *x11_host ? x11_host : 0;
2118 void MWindow::show_cwindow()
2120 session->show_cwindow = 1;
2121 cwindow->show_window();
2122 gui->mainmenu->show_cwindow->set_checked(1);
2125 void MWindow::show_gwindow()
2127 session->show_gwindow = 1;
2129 gwindow->gui->lock_window("MWindow::show_gwindow");
2130 gwindow->gui->show_window();
2131 gwindow->gui->raise_window();
2132 gwindow->gui->flush();
2133 gwindow->gui->unlock_window();
2135 gui->mainmenu->show_gwindow->set_checked(1);
2138 void MWindow::show_lwindow()
2140 session->show_lwindow = 1;
2141 lwindow->gui->lock_window("MWindow::show_lwindow");
2142 lwindow->gui->show_window();
2143 lwindow->gui->raise_window();
2144 lwindow->gui->flush();
2145 lwindow->gui->unlock_window();
2146 gui->mainmenu->show_lwindow->set_checked(1);
2149 int MWindow::tile_windows(int window_config)
2151 int need_reload = 0;
2152 int play_config = window_config==0 ? 0 : 1;
2153 edl->session->playback_config->load_defaults(defaults, play_config);
2154 session->default_window_positions(window_config);
2155 if( screens == 1 ) {
2156 gui->default_positions();
2157 sync_parameters(CHANGE_ALL);
2164 void MWindow::toggle_loop_playback()
2166 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2167 set_loop_boundaries();
2170 gui->draw_overlays(1);
2171 sync_parameters(CHANGE_PARAMS);
2174 //void MWindow::set_titles(int value)
2176 // edl->session->show_titles = value;
2177 // trackmovement(edl->local_session->track_start);
2180 void MWindow::set_screens(int value)
2185 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2187 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2188 edl->session->auto_keyframes = value;
2189 gui->mbuttons->edit_panel->keyframe->update(value);
2191 if(lock_mwindow) gui->unlock_window();
2193 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2194 cwindow->gui->edit_panel->keyframe->update(value);
2195 cwindow->gui->flush();
2196 if(lock_cwindow) cwindow->gui->unlock_window();
2199 void MWindow::set_keyframe_type(int mode)
2201 gui->lock_window("MWindow::set_keyframe_type");
2202 edl->local_session->floatauto_type = mode;
2203 gui->mainmenu->update_toggles(0);
2204 gui->unlock_window();
2207 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2209 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2210 edl->session->editing_mode = new_editing_mode;
2211 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2212 gui->mbuttons->edit_panel->update();
2213 gui->set_editing_mode(1);
2214 if(lock_mwindow) gui->unlock_window();
2217 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2218 cwindow->gui->edit_panel->update();
2219 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2220 if(lock_cwindow) cwindow->gui->unlock_window();
2224 void MWindow::toggle_editing_mode()
2226 int mode = edl->session->editing_mode;
2227 if( mode == EDITING_ARROW )
2228 set_editing_mode(EDITING_IBEAM, 0, 1);
2230 set_editing_mode(EDITING_ARROW, 0, 1);
2234 void MWindow::set_labels_follow_edits(int value)
2236 gui->lock_window("MWindow::set_labels_follow_edits");
2237 edl->session->labels_follow_edits = value;
2238 gui->mbuttons->edit_panel->locklabels->update(value);
2239 gui->mainmenu->labels_follow_edits->set_checked(value);
2241 gui->unlock_window();
2244 void MWindow::sync_parameters(int change_type)
2246 if( in_destructor ) return;
2248 // Sync engines which are playing back
2249 if(cwindow->playback_engine->is_playing_back)
2251 if(change_type == CHANGE_PARAMS)
2253 // TODO: block keyframes until synchronization is done
2254 cwindow->playback_engine->sync_parameters(edl);
2259 int command = cwindow->playback_engine->command->command;
2260 cwindow->playback_engine->que->send_command(STOP,
2264 // Waiting for tracking to finish would make the restart position more
2265 // accurate but it can't lock the window to stop tracking for some reason.
2266 // Not waiting for tracking gives a faster response but restart position is
2267 // only as accurate as the last tracking update.
2268 cwindow->playback_engine->interrupt_playback(0);
2269 cwindow->playback_engine->que->send_command(command,
2278 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2285 void MWindow::age_caches()
2287 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2289 // preferences->cache_size,
2290 // audio_cache->get_memory_usage(1),
2291 // video_cache->get_memory_usage(1),
2292 // frame_cache->get_memory_usage(),
2293 // wave_cache->get_memory_usage(),
2295 frame_cache->age_cache(512);
2296 wave_cache->age_cache(8192);
2298 int64_t memory_usage;
2299 int64_t prev_memory_usage = 0;
2301 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2302 while( !result && prev_memory_usage !=
2303 (memory_usage=video_cache->get_memory_usage(1)) &&
2304 memory_usage > video_size ) {
2305 video_cache->delete_oldest();
2306 prev_memory_usage = memory_usage;
2309 prev_memory_usage = 0;
2311 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2312 while( !result && prev_memory_usage !=
2313 (memory_usage=audio_cache->get_memory_usage(1)) &&
2314 memory_usage > audio_size ) {
2315 audio_cache->delete_oldest();
2316 prev_memory_usage = memory_usage;
2320 void MWindow::reset_android_remote()
2322 gui->use_android_remote(preferences->android_remote);
2326 void MWindow::show_keyframe_gui(Plugin *plugin)
2328 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2329 // Find existing thread
2330 for(int i = 0; i < keyframe_threads->size(); i++)
2332 if(keyframe_threads->get(i)->plugin == plugin)
2334 keyframe_threads->get(i)->start_window(plugin, 0);
2335 keyframe_gui_lock->unlock();
2340 // Find unused thread
2341 for(int i = 0; i < keyframe_threads->size(); i++)
2343 if(!keyframe_threads->get(i)->plugin)
2345 keyframe_threads->get(i)->start_window(plugin, 0);
2346 keyframe_gui_lock->unlock();
2351 // Create new thread
2352 KeyFrameThread *thread = new KeyFrameThread(this);
2353 keyframe_threads->append(thread);
2354 thread->start_window(plugin, 0);
2356 keyframe_gui_lock->unlock();
2363 void MWindow::show_plugin(Plugin *plugin)
2368 // Remove previously deleted plugin GUIs
2369 dead_plugin_lock->lock("MWindow::show_plugin");
2370 dead_plugins->remove_all_objects();
2371 dead_plugin_lock->unlock();
2373 //printf("MWindow::show_plugin %d\n", __LINE__);
2377 plugin_gui_lock->lock("MWindow::show_plugin");
2378 for(int i = 0; i < plugin_guis->total; i++)
2380 // Pointer comparison
2381 if(plugin_guis->get(i)->plugin == plugin)
2383 plugin_guis->get(i)->raise_window();
2390 //printf("MWindow::show_plugin 1\n");
2395 printf("MWindow::show_plugin track not defined.\n");
2397 PluginServer *server = scan_plugindb(plugin->title,
2398 plugin->track->data_type);
2400 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2401 if(server && server->uses_gui)
2403 PluginServer *gui = new PluginServer(*server);
2404 plugin_guis->append(gui);
2405 // Needs mwindow to do GUI
2406 gui->set_mwindow(this);
2407 gui->open_plugin(0, preferences, edl, plugin);
2412 plugin_gui_lock->unlock();
2413 //printf("MWindow::show_plugin %d\n", __LINE__);
2416 //printf("MWindow::show_plugin 2\n");
2419 void MWindow::hide_plugin(Plugin *plugin, int lock)
2422 // Update the toggle
2423 gui->lock_window("MWindow::hide_plugin");
2424 gui->update(0, 1, 0, 0, 0, 0, 0);
2425 gui->unlock_window();
2427 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2428 for(int i = 0; i < plugin_guis->total; i++)
2430 if(plugin_guis->get(i)->plugin == plugin)
2432 PluginServer *ptr = plugin_guis->get(i);
2433 plugin_guis->remove(ptr);
2434 if(lock) plugin_gui_lock->unlock();
2435 // Last command executed in client side close
2436 // Schedule for deletion
2443 if(lock) plugin_gui_lock->unlock();
2446 void MWindow::delete_plugin(PluginServer *plugin)
2448 dead_plugin_lock->lock("MWindow::delete_plugin");
2449 dead_plugins->append(plugin);
2450 dead_plugin_lock->unlock();
2453 void MWindow::hide_plugins()
2455 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2456 while(plugin_guis->size())
2458 PluginServer *ptr = plugin_guis->get(0);
2459 plugin_guis->remove(ptr);
2460 plugin_gui_lock->unlock();
2461 // Last command executed in client side close
2462 // Schedule for deletion
2465 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2467 plugin_gui_lock->unlock();
2469 hide_keyframe_guis();
2472 void MWindow::hide_keyframe_guis()
2474 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2475 for(int i = 0; i < keyframe_threads->size(); i++)
2477 keyframe_threads->get(i)->close_window();
2479 keyframe_gui_lock->unlock();
2482 void MWindow::hide_keyframe_gui(Plugin *plugin)
2484 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2485 for(int i = 0; i < keyframe_threads->size(); i++)
2487 if(keyframe_threads->get(i)->plugin == plugin)
2489 keyframe_threads->get(i)->close_window();
2493 keyframe_gui_lock->unlock();
2496 void MWindow::update_keyframe_guis()
2498 // Send new configuration to keyframe GUI's
2499 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2500 for(int i = 0; i < keyframe_threads->size(); i++)
2502 KeyFrameThread *ptr = keyframe_threads->get(i);
2503 if(edl->tracks->plugin_exists(ptr->plugin))
2507 ptr->close_window();
2510 keyframe_gui_lock->unlock();
2513 void MWindow::update_plugin_guis(int do_keyframe_guis)
2515 // Send new configuration to plugin GUI's
2516 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2518 for(int i = 0; i < plugin_guis->size(); i++)
2520 PluginServer *ptr = plugin_guis->get(i);
2521 if(edl->tracks->plugin_exists(ptr->plugin))
2525 // Schedule for deletion if no plugin
2526 plugin_guis->remove_number(i);
2535 // Change plugin variable if not visible
2536 Track *track = edl->tracks->first;
2539 for(int i = 0; i < track->plugin_set.size(); i++)
2541 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2545 for(int i = 0; i < plugin_guis->size(); i++)
2547 PluginServer *server = plugin_guis->get(i);
2548 if(server->plugin == plugin)
2555 if(!got_it) plugin->show = 0;
2557 plugin = (Plugin*)plugin->next;
2561 track = track->next;
2564 plugin_gui_lock->unlock();
2567 if(do_keyframe_guis) update_keyframe_guis();
2570 int MWindow::plugin_gui_open(Plugin *plugin)
2573 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2574 for(int i = 0; i < plugin_guis->total; i++)
2576 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2582 plugin_gui_lock->unlock();
2586 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2588 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2589 for(int i = 0; i < plugin_guis->total; i++)
2591 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2593 plugin_guis->get(i)->render_gui(data);
2597 plugin_gui_lock->unlock();
2600 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2602 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2603 for(int i = 0; i < plugin_guis->total; i++)
2605 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2607 plugin_guis->get(i)->render_gui(data, size);
2611 plugin_gui_lock->unlock();
2615 void MWindow::update_plugin_states()
2617 plugin_gui_lock->lock("MWindow::update_plugin_states");
2618 for(int i = 0; i < plugin_guis->total; i++)
2622 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2623 PluginServer *src_plugingui = plugin_guis->get(i);
2625 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2626 for(Track *track = edl->tracks->first;
2628 track = track->next)
2631 j < track->plugin_set.total && !result;
2634 PluginSet *plugin_set = track->plugin_set[j];
2635 for(Plugin *plugin = (Plugin*)plugin_set->first;
2637 plugin = (Plugin*)plugin->next)
2639 if(plugin == src_plugin &&
2640 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2646 // Doesn't exist anymore
2649 hide_plugin(src_plugin, 0);
2653 plugin_gui_lock->unlock();
2657 void MWindow::update_plugin_titles()
2659 for(int i = 0; i < plugin_guis->total; i++)
2661 plugin_guis->get(i)->update_title();
2665 int MWindow::asset_to_edl(EDL *new_edl,
2667 RecordLabels *labels)
2669 const int debug = 0;
2670 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2673 // Keep frame rate, sample rate, and output size unchanged.
2674 // These parameters would revert the project if VWindow displayed an asset
2675 // of different size than the project.
2676 if(new_asset->video_data)
2678 new_edl->session->video_tracks = new_asset->layers;
2681 new_edl->session->video_tracks = 0;
2683 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2689 if(new_asset->audio_data)
2691 new_edl->session->audio_tracks = new_asset->channels;
2694 new_edl->session->audio_tracks = 0;
2695 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2697 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2698 new_edl->create_default_tracks();
2699 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2700 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2704 //printf("MWindow::asset_to_edl 3\n");
2705 new_edl->insert_asset(new_asset,
2710 //printf("MWindow::asset_to_edl 3\n");
2711 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2713 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2714 if(edl->session->cursor_on_frames)
2716 double length = new_edl->tracks->total_length();
2717 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2718 new_edl->tracks->clear(length, edl_length, 1, 1);
2724 char string[BCTEXTLEN];
2726 fs.extract_name(string, new_asset->path);
2727 //printf("MWindow::asset_to_edl 3\n");
2729 strcpy(new_edl->local_session->clip_title, string);
2730 //printf("MWindow::asset_to_edl 4 %s\n", string);
2731 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2736 int MWindow::edl_to_nested(EDL *new_edl,
2740 // Keep frame rate, sample rate, and output size unchanged.
2741 // These parameters would revert the project if VWindow displayed an asset
2742 // of different size than the project.
2746 // Nest all video & audio outputs
2747 new_edl->session->video_tracks = 1;
2748 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2749 new_edl->create_default_tracks();
2753 new_edl->insert_asset(0,
2759 char string[BCTEXTLEN];
2761 fs.extract_name(string, nested_edl->path);
2762 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2764 strcpy(new_edl->local_session->clip_title, string);
2769 // Reset everything after a load.
2770 void MWindow::update_project(int load_mode)
2772 const int debug = 0;
2774 if(debug) PRINT_TRACE
2776 edl->tracks->update_y_pixels(theme);
2778 if(debug) PRINT_TRACE
2780 if(load_mode == LOADMODE_REPLACE ||
2781 load_mode == LOADMODE_REPLACE_CONCATENATE)
2786 gui->update(1, 1, 1, 1, 1, 1, 1);
2787 if(debug) PRINT_TRACE
2788 gui->unlock_window();
2790 cwindow->gui->lock_window("MWindow::update_project 1");
2791 cwindow->update(0, 0, 1, 1, 1);
2792 cwindow->gui->unlock_window();
2794 if(debug) PRINT_TRACE
2796 // Close all the vwindows
2797 if(load_mode == LOADMODE_REPLACE ||
2798 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2799 if(debug) PRINT_TRACE
2800 int first_vwindow = 0;
2801 if(session->show_vwindow) first_vwindow = 1;
2802 // Change visible windows to no source
2803 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2804 VWindow *vwindow = vwindows[i];
2805 if( !vwindow->is_running() ) continue;
2806 vwindow->change_source(-1);
2809 // Close remaining windows
2810 for(int i = first_vwindow; i < vwindows.size(); i++) {
2811 VWindow *vwindow = vwindows[i];
2812 if( !vwindow->is_running() ) continue;
2813 vwindow->close_window();
2815 if(debug) PRINT_TRACE
2817 else if(vwindows.size()) {
2818 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2819 if( vwindow->is_running() ) {
2820 vwindow->gui->lock_window("MWindow::update_project");
2822 vwindow->gui->unlock_window();
2826 if(debug) PRINT_TRACE
2827 cwindow->gui->lock_window("MWindow::update_project 2");
2828 cwindow->gui->timebar->update(0);
2829 cwindow->gui->unlock_window();
2831 if(debug) PRINT_TRACE
2832 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2837 awindow->gui->async_update_assets();
2838 if(debug) PRINT_TRACE
2840 gui->lock_window("MWindow::update_project");
2842 if(debug) PRINT_TRACE
2845 void MWindow::remove_indexfile(Indexable *indexable)
2847 if( !indexable->is_asset ) return;
2848 Asset *asset = (Asset *)indexable;
2850 IndexFile::delete_index(preferences, asset, ".toc");
2851 IndexFile::delete_index(preferences, asset, ".idx");
2852 IndexFile::delete_index(preferences, asset, ".mkr");
2855 void MWindow::rebuild_indices()
2857 for(int i = 0; i < session->drag_assets->total; i++)
2859 Indexable *indexable = session->drag_assets->get(i);
2860 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2861 remove_indexfile(indexable);
2862 // Schedule index build
2863 IndexState *index_state = indexable->index_state;
2864 index_state->index_status = INDEX_NOTTESTED;
2865 if( indexable->is_asset ) {
2866 Asset *asset = (Asset *)indexable;
2867 if( asset->format != FILE_PCM )
2868 asset->reset_audio();
2869 asset->reset_video();
2871 mainindexes->add_next_asset(0, indexable);
2873 mainindexes->start_build();
2877 void MWindow::save_backup()
2881 edl->set_path(session->filename);
2882 char backup_path[BCTEXTLEN];
2883 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2884 File::get_config_path(), BACKUP_FILE);
2885 edl->save_xml(&file, backup_path, 0, 0);
2886 file.terminate_string();
2888 fs.complete_path(backup_path);
2890 if(file.write_to_file(backup_path))
2893 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
2894 gui->show_message(string2);
2898 void MWindow::load_backup()
2900 ArrayList<char*> path_list;
2901 path_list.set_array_delete();
2903 char backup_path[BCTEXTLEN];
2904 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2905 File::get_config_path(), BACKUP_FILE);
2907 fs.complete_path(backup_path);
2909 path_list.append(out_path = new char[strlen(backup_path) + 1]);
2910 strcpy(out_path, backup_path);
2912 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2913 edl->local_session->clip_title[0] = 0;
2914 // This is unique to backups since the path of the backup is different than the
2915 // path of the project.
2916 set_filename(edl->path);
2917 path_list.remove_all_objects();
2921 static inline int gcd(int m, int n)
2924 if( m < n ) { r = m; m = n; n = r; }
2925 while( (r = m % n) != 0 ) { m = n; n = r; }
2929 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2932 if(!width || !height) return 1;
2933 if( width == 720 && (height == 480 || height == 576) ) {
2934 w = 4; h = 3; return 0; // for NTSC and PAL
2936 double ar = (double)width / height;
2937 // square-ish pixels
2938 if( EQUIV(ar, 1.0000) ) return 0;
2939 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2940 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2941 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2942 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2943 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2944 int ww = width, hh = height;
2945 // numerator, denominator must be under mx
2946 int mx = 255, n = gcd(ww, hh);
2947 if( n > 1 ) { ww /= n; hh /= n; }
2948 // search near height in case extra/missing lines
2949 if( ww >= mx || hh >= mx ) {
2950 double err = height; // +/- 2 percent height
2951 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2952 int iw = width, ih = height+i;
2953 if( (n=gcd(iw, ih)) > 1 ) {
2954 int u = iw/n; if( u >= mx ) continue;
2955 int v = ih/n; if( v >= mx ) continue;
2956 double r = (double) u/v, er = fabs(ar-r);
2957 if( er >= err ) continue;
2958 err = er; ww = u; hh = v;
2967 void MWindow::reset_caches()
2969 frame_cache->remove_all();
2970 wave_cache->remove_all();
2971 audio_cache->remove_all();
2972 video_cache->remove_all();
2973 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2974 cwindow->playback_engine->audio_cache->remove_all();
2975 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2976 cwindow->playback_engine->video_cache->remove_all();
2978 for(int i = 0; i < vwindows.size(); i++) {
2979 VWindow *vwindow = vwindows[i];
2980 if( !vwindow->is_running() ) continue;
2981 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2982 vwindow->playback_engine->audio_cache->remove_all();
2983 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2984 vwindow->playback_engine->video_cache->remove_all();
2988 void MWindow::remove_asset_from_caches(Asset *asset)
2990 gui->resource_thread->get_video_source(0);
2991 gui->resource_thread->get_audio_source(0);
2992 frame_cache->remove_asset(asset);
2993 wave_cache->remove_asset(asset);
2994 audio_cache->delete_entry(asset);
2995 video_cache->delete_entry(asset);
2996 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2997 cwindow->playback_engine->audio_cache->delete_entry(asset);
2998 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2999 cwindow->playback_engine->video_cache->delete_entry(asset);
3000 for(int i = 0; i < vwindows.size(); i++) {
3001 VWindow *vwindow = vwindows[i];
3002 if( !vwindow->is_running() ) continue;
3003 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3004 vwindow->playback_engine->audio_cache->delete_entry(asset);
3005 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3006 vwindow->playback_engine->video_cache->delete_entry(asset);
3011 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3012 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3014 for(int i = 0; i < session->drag_assets->total; i++) {
3015 Indexable *indexable = session->drag_assets->get(i);
3016 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3019 // Remove from VWindow.
3020 for(int i = 0; i < session->drag_clips->total; i++) {
3021 for(int j = 0; j < vwindows.size(); j++) {
3022 VWindow *vwindow = vwindows[j];
3023 if( !vwindow->is_running() ) continue;
3024 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3025 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3026 vwindow->delete_source(1, 1);
3027 vwindow->gui->unlock_window();
3032 for(int i = 0; i < session->drag_assets->size(); i++) {
3033 for(int j = 0; j < vwindows.size(); j++) {
3034 VWindow *vwindow = vwindows[j];
3035 if( !vwindow->is_running() ) continue;
3036 if(session->drag_assets->get(i) == vwindow->get_source()) {
3037 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3038 vwindow->delete_source(1, 1);
3039 vwindow->gui->unlock_window();
3044 for(int i = 0; i < session->drag_assets->size(); i++) {
3045 Indexable *indexable = session->drag_assets->get(i);
3046 remove_indexfile(indexable);
3049 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3050 if(push_undo) undo->update_undo_before();
3051 if(drag_assets) edl->remove_from_project(drag_assets);
3052 if(drag_clips) edl->remove_from_project(session->drag_clips);
3053 if(redraw) save_backup();
3054 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3059 gui->lock_window("MWindow::remove_assets_from_project 3");
3067 gui->unlock_window();
3069 // Removes from playback here
3070 sync_parameters(CHANGE_ALL);
3073 awindow->gui->async_update_assets();
3076 void MWindow::remove_assets_from_disk()
3079 for(int i = 0; i < session->drag_assets->total; i++)
3081 remove(session->drag_assets->get(i)->path);
3084 remove_assets_from_project(1,
3086 session->drag_assets,
3087 session->drag_clips);
3090 void MWindow::dump_plugins(FILE *fp)
3092 if( !plugindb ) return;
3093 for(int i = 0; i < plugindb->total; i++)
3095 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3096 " synth=%d transition=%d theme=%d %s\n",
3097 plugindb->get(i)->plugin_type,
3098 plugindb->get(i)->audio,
3099 plugindb->get(i)->video,
3100 plugindb->get(i)->realtime,
3101 plugindb->get(i)->multichannel,
3102 plugindb->get(i)->get_synthesis(),
3103 plugindb->get(i)->transition,
3104 plugindb->get(i)->theme,
3105 plugindb->get(i)->title);
3109 void MWindow::dump_edl(FILE *fp)
3115 void MWindow::dump_undo(FILE *fp)
3121 void MWindow::dump_exe(FILE *fp)
3123 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3124 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3125 int ret = readlink(proc_path, exe_path, sizeof(exe_path));
3126 if( ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3129 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3130 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
3131 int fd = open(exe_path,O_RDONLY+O_NONBLOCK);
3132 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3135 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3136 int64_t maxsz = 1024*pagsz;
3137 int64_t size = st.st_size, pos = 0;
3139 while( (bfrsz = size-pos) > 0 ) {
3140 if( bfrsz > maxsz ) bfrsz = maxsz;
3141 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3142 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3143 if( bfr == MAP_FAILED ) break;
3144 sha1.addBytes(bfr, bfrsz);
3149 ret = pos < size ? EIO : 0;
3150 fprintf(fp, "SHA1: ");
3151 uint8_t digest[20]; sha1.computeHash(digest);
3152 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3153 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3154 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3158 void MWindow::trap_hook(FILE *fp, void *vp)
3160 MWindow *mwindow = (MWindow *)vp;
3161 // fprintf(fp, "\nPLUGINS:\n");
3162 // mwindow->dump_plugins(fp);
3163 fprintf(fp, "\nEDL:\n");
3164 mwindow->dump_edl(fp);
3165 fprintf(fp, "\nUNDO:\n");
3166 mwindow->dump_undo(fp);
3167 fprintf(fp, "\nEXE:\n");
3168 mwindow->dump_exe(fp);
3176 int MWindow::save_defaults()
3178 gui->save_defaults(defaults);
3179 edl->save_defaults(defaults);
3180 session->save_defaults(defaults);
3181 preferences->save_defaults(defaults);
3183 for(int i = 0; i < plugin_guis->total; i++)
3185 // Pointer comparison
3186 plugin_guis->get(i)->save_defaults();
3188 awindow->save_defaults(defaults);
3194 int MWindow::run_script(FileXML *script)
3196 int result = 0, result2 = 0;
3197 while(!result && !result2)
3199 result = script->read_tag();
3202 if(script->tag.title_is("new_project"))
3204 // Run new in immediate mode.
3205 // gui->mainmenu->new_project->run_script(script);
3208 if(script->tag.title_is("record"))
3210 // Run record as a thread. It is a terminal command.
3212 // Will read the complete scipt file without letting record read it if not
3218 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3225 // ================================= synchronization
3228 int MWindow::interrupt_indexes()
3230 mainprogress->cancelled = 1;
3231 mainindexes->interrupt_build();
3237 void MWindow::next_time_format()
3239 switch(edl->session->time_format)
3241 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3242 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3243 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3244 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3245 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3246 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3247 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3250 time_format_common();
3253 void MWindow::prev_time_format()
3255 switch(edl->session->time_format)
3257 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3258 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3259 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3260 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3261 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3262 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3263 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3266 time_format_common();
3269 void MWindow::time_format_common()
3271 gui->lock_window("MWindow::next_time_format");
3272 gui->redraw_time_dependancies();
3275 char string[BCTEXTLEN], string2[BCTEXTLEN];
3276 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3277 gui->show_message(string);
3279 gui->unlock_window();
3283 int MWindow::set_filename(const char *filename)
3285 if( filename != session->filename )
3286 strcpy(session->filename, filename);
3287 if( filename != edl->path )
3288 strcpy(edl->path, filename);
3292 if(filename[0] == 0)
3294 gui->set_title(PROGRAM_NAME);
3299 char string[BCTEXTLEN], string2[BCTEXTLEN];
3300 dir.extract_name(string, filename);
3301 sprintf(string2, PROGRAM_NAME ": %s", string);
3302 gui->set_title(string2);
3315 int MWindow::set_loop_boundaries()
3317 double start = edl->local_session->get_selectionstart();
3318 double end = edl->local_session->get_selectionend();
3326 if(edl->tracks->total_length())
3329 end = edl->tracks->total_length();
3336 if(edl->local_session->loop_playback && start != end)
3338 edl->local_session->loop_start = start;
3339 edl->local_session->loop_end = end;
3350 int MWindow::reset_meters()
3352 cwindow->gui->lock_window("MWindow::reset_meters 1");
3353 cwindow->gui->meters->reset_meters();
3354 cwindow->gui->unlock_window();
3356 for(int j = 0; j < vwindows.size(); j++) {
3357 VWindow *vwindow = vwindows[j];
3358 if( !vwindow->is_running() ) continue;
3359 vwindow->gui->lock_window("MWindow::reset_meters 2");
3360 vwindow->gui->meters->reset_meters();
3361 vwindow->gui->unlock_window();
3364 lwindow->gui->lock_window("MWindow::reset_meters 3");
3365 lwindow->gui->panel->reset_meters();
3366 lwindow->gui->unlock_window();
3368 gui->lock_window("MWindow::reset_meters 4");
3369 gui->reset_meters();
3370 gui->unlock_window();
3375 void MWindow::resync_guis()
3379 gui->lock_window("MWindow::resync_guis");
3380 gui->update(1, 1, 1, 1, 1, 1, 0);
3381 gui->unlock_window();
3383 cwindow->gui->lock_window("MWindow::resync_guis");
3384 cwindow->gui->resize_event(cwindow->gui->get_w(),
3385 cwindow->gui->get_h());
3386 int channels = edl->session->audio_channels;
3387 cwindow->gui->meters->set_meters(channels, 1);
3388 cwindow->gui->flush();
3389 cwindow->gui->unlock_window();
3391 for(int i = 0; i < vwindows.size(); i++) {
3392 VWindow *vwindow = vwindows[i];
3393 if( !vwindow->is_running() ) continue;
3394 vwindow->gui->lock_window("MWindow::resync_guis");
3395 vwindow->gui->resize_event(vwindow->gui->get_w(),
3396 vwindow->gui->get_h());
3397 vwindow->gui->meters->set_meters(channels, 1);
3398 vwindow->gui->flush();
3399 vwindow->gui->unlock_window();
3402 lwindow->gui->lock_window("MWindow::resync_guis");
3403 lwindow->gui->panel->set_meters(channels, 1);
3404 lwindow->gui->flush();
3405 lwindow->gui->unlock_window();
3408 if(((edl->session->output_w % 4) ||
3409 (edl->session->output_h % 4)) &&
3410 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3412 MainError::show_error(
3413 _("This project's dimensions are not multiples of 4 so\n"
3414 "it can't be rendered by OpenGL."));
3419 sync_parameters(CHANGE_ALL);
3422 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3424 File *file = new File;
3425 EDLSession *session = edl->session;
3426 double old_framerate = session->frame_rate;
3427 double old_samplerate = session->sample_rate;
3428 int result = file->open_file(preferences, asset, 1, 0);
3429 if( !result && delete_tracks > 0 )
3430 undo->update_undo_before();
3431 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3432 // try to get asset up to date, may fail
3433 file->select_video_stream(asset, vstream);
3434 // either way use what was/is there.
3435 double framerate = asset->get_frame_rate();
3436 int width = asset->get_w();
3437 int height = asset->get_h();
3438 // must be multiple of 4 for opengl
3439 width = (width+3) & ~3; height = (height+3) & ~3;
3440 int driver = session->playback_config->vconfig->driver;
3441 int color_model = file->get_best_colormodel(asset, driver);
3442 // color_model = BC_CModels::is_yuv(color_model) ?
3443 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3444 // BC_CModels::is_float(color_model) ?
3445 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3446 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3447 // have alpha for now
3448 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3449 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3450 session->color_model = color_model;
3451 session->output_w = width;
3452 session->output_h = height;
3453 session->frame_rate = framerate;
3454 // not, asset->actual_width/actual_height
3455 asset->width = session->output_w;
3456 asset->height = session->output_h;
3457 asset->frame_rate = session->frame_rate;
3458 create_aspect_ratio(session->aspect_w, session->aspect_h,
3459 session->output_w, session->output_h);
3460 Track *track = edl->tracks->first;
3461 for( Track *next_track=0; track; track=next_track ) {
3462 next_track = track->next;
3463 if( track->data_type != TRACK_VIDEO ) continue;
3464 if( delete_tracks ) {
3465 Edit *edit = track->edits->first;
3466 for( Edit *next_edit=0; edit; edit=next_edit ) {
3467 next_edit = edit->next;
3468 if( edit->channel != vstream ||
3469 !edit->asset || !edit->asset->is_asset ||
3470 *asset != *edit->asset )
3474 if( track->edits->first ) {
3475 track->track_w = edl->session->output_w;
3476 track->track_h = edl->session->output_h;
3478 else if( delete_tracks )
3479 edl->tracks->delete_track(track);
3481 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3483 if( !result && asset->audio_data && asset->channels > 0 ) {
3484 session->sample_rate = asset->get_sample_rate();
3485 int64_t channel_mask = 0;
3486 int astrm = !asset->video_data ? -1 :
3487 file->get_audio_for_video(vstream, astream, channel_mask);
3488 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3489 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3491 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3492 if( channels < 1 ) channels = 1;
3493 if( channels > 6 ) channels = 6;
3494 session->audio_tracks = session->audio_channels = channels;
3495 switch( channels ) {
3497 session->achannel_positions[0] = 90;
3498 session->achannel_positions[1] = 150;
3499 session->achannel_positions[2] = 30;
3500 session->achannel_positions[3] = 210;
3501 session->achannel_positions[4] = 330;
3502 session->achannel_positions[5] = 270;
3505 session->achannel_positions[0] = 180;
3506 session->achannel_positions[1] = 0;
3509 session->achannel_positions[1] = 90;
3512 if( !channels ) break;
3513 double t = 0, dt = 360./channels;
3514 for( int i=channels; --i>=0; t+=dt )
3515 session->achannel_positions[i] = int(t+0.5);
3518 remap_audio(MWindow::AUDIO_1_TO_1);
3520 if( delete_tracks ) {
3521 Track *track = edl->tracks->first;
3522 for( Track *next_track=0; track; track=next_track ) {
3523 next_track = track->next;
3524 if( track->data_type != TRACK_AUDIO ) continue;
3525 Edit *edit = track->edits->first;
3526 for( Edit *next_edit=0; edit; edit=next_edit ) {
3527 next_edit = edit->next;
3528 if( !((1<<edit->channel) & channel_mask) ||
3529 !edit->asset || !edit->asset->is_asset ||
3530 *asset != *edit->asset )
3533 if( !track->edits->first )
3534 edl->tracks->delete_track(track);
3538 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3541 if( !result && delete_tracks > 0 ) {
3543 undo->update_undo_after(_("select asset"), LOAD_ALL);
3549 int MWindow::select_asset(int vtrack, int delete_tracks)
3551 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3553 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3554 if( !track ) return 1;
3555 Edit *edit = track->edits->first;
3556 if( !edit ) return 1;
3557 Asset *asset = edit->asset;
3558 if( !asset || !asset->is_asset ) return 1;
3559 return select_asset(asset, edit->channel, 0, delete_tracks);
3562 void MWindow::dump_plugindb(FILE *fp)
3564 if( !plugindb ) return;
3565 for(int i = 0; i < plugindb->total; i++)
3566 plugindb->get(i)->dump(fp);