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;
239 if( commercials && !commercials->remove_user() ) commercials = 0;
241 // Save defaults for open plugins
242 plugin_gui_lock->lock("MWindow::~MWindow");
243 for(int i = 0; i < plugin_guis->size(); i++) {
244 plugin_guis->get(i)->hide_gui();
245 delete_plugin(plugin_guis->get(i));
247 plugin_gui_lock->unlock();
248 hide_keyframe_guis();
251 // Give up and go to a movie
252 // cant run valgrind if this is used
254 gui->del_keyboard_listener(
255 (int (BC_WindowBase::*)(BC_WindowBase *))
256 &MWindowGUI::keyboard_listener);
258 // release the hounds
259 if( awindow && awindow->gui ) awindow->gui->close(0);
260 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
261 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
262 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
263 if( twindow && twindow->is_running() ) twindow->close_window();
264 if( wwindow && wwindow->is_running() ) wwindow->close_window();
265 vwindows.remove_all_objects();
267 if( awindow ) awindow->join();
268 if( cwindow ) cwindow->join();
269 if( lwindow ) lwindow->join();
270 if( twindow ) twindow->join();
271 if( wwindow ) wwindow->join();
272 if( gwindow ) gwindow->join();
275 // one at a time, or nouveau chokes
276 #define close_gui(win) if( win ) { \
277 if( win->gui ) win->gui->close(0); \
285 vwindows.remove_all_objects();
290 dead_plugins->remove_all_objects();
293 keyframe_threads->remove_all_objects();
294 colormodels.remove_all_objects();
296 delete render; render = 0;
297 delete awindow; awindow = 0;
298 delete lwindow; lwindow = 0;
299 delete twindow; twindow = 0;
300 delete wwindow; wwindow = 0;
301 delete gwindow; gwindow = 0;
302 // must be last or nouveau chokes
303 delete cwindow; cwindow = 0;
304 //delete file_server; file_server = 0; // reusable
305 delete mainindexes; mainindexes = 0;
306 delete mainprogress; mainprogress = 0;
307 delete audio_cache; audio_cache = 0; // delete the cache after the assets
308 delete video_cache; video_cache = 0; // delete the cache after the assets
309 delete frame_cache; frame_cache = 0;
310 delete wave_cache; wave_cache = 0;
311 delete plugin_guis; plugin_guis = 0;
312 delete dead_plugins; dead_plugins = 0;
313 delete keyframe_threads; keyframe_threads = 0;
314 delete undo; undo = 0;
315 delete preferences; preferences = 0;
316 delete exportedl; exportedl = 0;
317 delete session; session = 0;
318 delete defaults; defaults = 0;
319 delete assets; assets = 0;
320 delete splash_window; splash_window = 0;
321 // delete theme; theme = 0; // deleted by delete_plugins
322 if( !edl->Garbage::remove_user() ) edl = 0;
323 delete channeldb_buz;
324 delete channeldb_v4l2jpeg;
325 // This must be last thread to exit
326 delete playback_3d; playback_3d = 0;
327 delete dead_plugin_lock;
328 delete plugin_gui_lock;
329 delete vwindows_lock;
331 delete keyframe_gui_lock;
332 colormodels.remove_all_objects();
333 interlace_project_modes.remove_all_objects();
334 interlace_asset_modes.remove_all_objects();
335 interlace_asset_fixmethods.remove_all_objects();
336 sighandler->terminate();
341 void MWindow::quit(int unlock)
344 if(unlock) gui->unlock_window();
346 brender_lock->lock("MWindow::quit");
347 delete brender; brender = 0;
348 brender_lock->unlock();
354 if(unlock) gui->lock_window("MWindow::quit");
357 void MWindow::init_error()
359 MainError::init_error(this);
362 void MWindow::finit_error()
364 MainError::finit_error();
367 void MWindow::create_defaults_path(char *string, const char *config_file)
369 // set the .bcast path
372 sprintf(string, "%s/", File::get_config_path());
373 fs.complete_path(string);
374 if(!fs.is_dir(string))
375 fs.create_dir(string);
378 strcat(string, config_file);
380 const char *MWindow::default_std()
382 char buf[BCTEXTLEN], *p = 0;
384 int fd = open(TIMEZONE_NAME, O_RDONLY);
386 int l = read(fd, buf, sizeof(buf)-1);
389 if( buf[l-1] == '\n' ) --l;
395 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
398 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
399 p += strlen(ZONEINFO_STR);
404 for( int i=0; ntsc_zones[i]; ++i ) {
405 if( !strcmp(ntsc_zones[i], p) )
412 for( int i=0; ntsc_zones[i]; ++i ) {
413 if( !strcmp(ntsc_zones[i], p) )
418 //__timezone: Seconds west of UTC. 240sec/deg
419 double tz_deg = -__timezone / 240.;
420 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
421 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
424 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
426 struct formatpresets *fpr;
428 for(fpr = &format_presets[0]; fpr->name; fpr++)
430 if(strcmp(_(fpr->name), preset) == 0)
432 session->audio_channels = fpr->audio_channels;
433 session->audio_tracks = fpr->audio_tracks;
434 session->sample_rate = fpr->sample_rate;
435 session->video_channels = fpr->video_channels;
436 session->video_tracks = fpr->video_tracks;
437 session->frame_rate = fpr->frame_rate;
438 session->output_w = fpr->output_w;
439 session->output_h = fpr->output_h;
440 session->aspect_w = fpr->aspect_w;
441 session->aspect_h = fpr->aspect_h;
442 session->interlace_mode = fpr->interlace_mode;
443 session->color_model = fpr->color_model;
449 const char *MWindow::get_preset_name(int index)
451 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
453 return _(format_presets[index].name);
457 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
459 char path[BCTEXTLEN];
460 // Use user supplied path
462 strcpy(path, config_path);
464 create_defaults_path(path, CONFIG_FILE);
466 defaults = new BC_Hash(path);
470 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
472 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
474 const char *dp = plug_dir;
475 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
476 bp = !*dp && *bp == '/' ? bp+1 : base_path;
482 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
485 FILE *fp = fopen(index_path, "r");
489 char index_line[BCTEXTLEN];
490 int index_version = -1, len = strlen(plugin_dir);
491 if( !fgets(index_line, BCTEXTLEN, fp) ||
492 sscanf(index_line, "%d", &index_version) != 1 ||
493 index_version != PLUGIN_FILE_VERSION ||
494 !fgets(index_line, BCTEXTLEN, fp) ||
495 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
496 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
498 ArrayList<PluginServer*> plugins;
499 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
500 if( index_line[0] == ';' ) continue;
501 if( index_line[0] == '#' ) continue;
502 int type = PLUGIN_TYPE_UNKNOWN;
503 char path[BCTEXTLEN], title[BCTEXTLEN];
505 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
508 PluginServer *server = 0;
510 case PLUGIN_TYPE_BUILTIN:
511 case PLUGIN_TYPE_EXECUTABLE:
512 case PLUGIN_TYPE_LADSPA: {
513 char plugin_path[BCTEXTLEN]; struct stat st;
514 sprintf(plugin_path, "%s/%s", plugin_dir, path);
515 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
518 server = new PluginServer(mwindow, plugin_path, type);
520 case PLUGIN_TYPE_FFMPEG: {
521 server = new_ffmpeg_server(mwindow, path);
524 if( !server ) continue;
525 plugins.append(server);
526 // Create plugin server from index entry
527 server->set_title(title);
528 if( server->read_table(index_line) ) {
535 ret = check_plugin_index(plugins, plugin_dir, ".");
538 add_plugins(plugins);
540 plugins.remove_all_objects();
545 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
546 const char *plug_dir, const char *plug_path)
548 char plugin_path[BCTEXTLEN];
549 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
551 fs.set_filter( "[*.plugin][*.so]" );
552 if( fs.update(plugin_path) )
555 for( int i=0; i<fs.dir_list.total; ++i ) {
556 char fs_path[BCTEXTLEN];
557 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
558 if( fs.is_dir(fs_path) ) {
559 get_plugin_path(plugin_path, plug_dir, fs_path);
560 if( check_plugin_index(plugins, plug_dir, plugin_path) )
563 else if( !plugin_exists(fs_path, plugins) )
570 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
573 plugindb = new ArrayList<PluginServer*>;
575 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
576 create_defaults_path(index_path, PLUGIN_FILE);
577 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
578 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
579 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
580 printf("init plugin index: %s\n", plugin_path);
581 FILE *fp = fopen(index_path,"w");
583 fprintf(stderr,_("MWindow::init_plugins: "
584 "can't create plugin index: %s\n"), index_path);
587 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
588 fprintf(fp, "%s\n", plugin_path);
589 init_plugin_index(mwindow, preferences, fp, plugin_path);
590 init_ffmpeg_index(mwindow, preferences, fp);
592 return load_plugin_index(mwindow, index_path, plugin_path);
595 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
597 char *path = getenv("LADSPA_PATH");
598 char ladspa_path[BCTEXTLEN];
600 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
603 for( int len=0; *path; path+=len ) {
604 char *cp = strchr(path,':');
605 len = !cp ? strlen(path) : cp-path;
606 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
607 memcpy(plugin_path, path, len); plugin_path[len] = 0;
608 char *plugin_dir = FileSystem::basepath(plugin_path);
609 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
610 create_defaults_path(index_path, LADSPA_FILE);
611 cp = index_path + strlen(index_path);
612 for( char *bp=plugin_path; *bp!=0; ++bp )
613 *cp++ = *bp=='/' ? '_' : *bp;
615 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
616 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
617 load_plugin_index(mwindow, index_path, plugin_path);
622 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
623 FILE *fp, const char *plugin_dir)
625 int idx = PLUGIN_IDS;
627 for( int i=0; i<plugindb->size(); ++i ) {
628 PluginServer *server = plugindb->get(i);
629 if( server->dir_idx >= idx )
630 idx = server->dir_idx+1;
633 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
636 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
637 const char *index_path, const char *plugin_dir)
639 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
640 strcpy(plugin_path, path); delete [] path;
641 printf("init ladspa index: %s\n", plugin_dir);
642 FILE *fp = fopen(index_path,"w");
644 fprintf(stderr,_("MWindow::init_ladspa_index: "
645 "can't create plugin index: %s\n"), index_path);
648 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
649 fprintf(fp, "%s\n", plugin_dir);
650 init_plugin_index(mwindow, preferences, fp, plugin_path);
655 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
656 const char *plug_dir, const char *plug_path, int &idx)
658 char plugin_path[BCTEXTLEN];
659 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
661 fs.set_filter( "[*.plugin][*.so]" );
662 int result = fs.update(plugin_path);
663 if( result || !fs.dir_list.total ) return;
666 for( int i=0; i<fs.dir_list.total; ++i ) {
667 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
668 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
669 get_plugin_path(path, plug_dir, fs_path);
670 if( fs.is_dir(fs_path) ) {
671 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
674 if( plugin_exists(path) ) continue;
676 if( stat(fs_path, &st) ) continue;
677 int64_t mtime = st.st_mtime;
678 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
679 result = server.open_plugin(1, preferences, 0, 0);
681 server.write_table(fp, path, vis_id, mtime);
682 server.close_plugin();
684 else if( result == PLUGINSERVER_IS_LAD ) {
687 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
688 ladspa.set_lad_index(lad_index++);
689 result = ladspa.open_plugin(1, preferences, 0, 0);
691 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
692 ladspa.close_plugin();
698 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
700 for( int i=0; i<plugins.size(); ++i )
701 plugindb->append(plugins[i]);
702 plugins.remove_all();
705 void MWindow::delete_plugins()
707 plugindb->remove_all_objects();
712 void MWindow::search_plugindb(int do_audio,
717 ArrayList<PluginServer*> &results)
720 for(int i = 0; i < MWindow::plugindb->total; i++)
722 PluginServer *current = MWindow::plugindb->get(i);
724 if(current->audio == do_audio &&
725 current->video == do_video &&
726 (current->realtime == is_realtime || is_realtime < 0) &&
727 current->transition == is_transition &&
728 current->theme == is_theme)
729 results.append(current);
732 // Alphabetize list by title
738 for(int i = 0; i < results.total - 1; i++)
740 PluginServer *value1 = results[i];
741 PluginServer *value2 = results[i + 1];
742 if(strcmp(_(value1->title), _(value2->title)) > 0)
746 results[i + 1] = value1;
752 PluginServer* MWindow::scan_plugindb(char *title,
757 // printf("MWindow::scan_plugindb data_type < 0\n");
761 for(int i = 0; i < plugindb->total; i++)
763 PluginServer *server = plugindb->get(i);
765 !strcasecmp(server->title, title) &&
767 (data_type == TRACK_AUDIO && server->audio) ||
768 (data_type == TRACK_VIDEO && server->video)))
769 return plugindb->get(i);
774 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
776 for( int i=0; i<plugins.size(); ++i )
777 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
781 int MWindow::plugin_exists(char *plugin_path)
783 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
786 void MWindow::init_preferences()
788 preferences = new Preferences;
789 preferences->load_defaults(defaults);
790 session = new MainSession(this);
791 session->load_defaults(defaults);
792 // set x11_host, screens, window_config
793 screens = session->set_default_x11_host();
794 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
795 BC_Signals::set_trap_hook(trap_hook, this);
796 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
797 BC_Signals::set_catch_intr(preferences->trap_sigintr);
800 void MWindow::clean_indexes()
805 int oldest_item = -1;
807 char string[BCTEXTLEN];
808 char string2[BCTEXTLEN];
810 // Delete extra indexes
811 fs.set_filter("*.idx");
812 fs.complete_path(preferences->index_directory);
813 fs.update(preferences->index_directory);
814 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
816 // Eliminate directories
821 for(int i = 0; i < fs.dir_list.total && !result; i++)
823 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
824 if(fs.is_dir(string))
826 delete fs.dir_list[i];
827 fs.dir_list.remove_number(i);
832 total_excess = fs.dir_list.total - preferences->index_count;
834 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
835 while(total_excess > 0)
838 for(int i = 0; i < fs.dir_list.total; i++)
840 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
842 if(i == 0 || fs.get_date(string) <= oldest)
844 oldest = fs.get_date(string);
852 fs.join_names(string,
853 preferences->index_directory,
854 fs.dir_list[oldest_item]->name);
855 //printf("MWindow::clean_indexes 1 %s\n", string);
857 perror("delete_indexes");
858 delete fs.dir_list[oldest_item];
859 fs.dir_list.remove_number(oldest_item);
861 // Remove table of contents if it exists
862 strcpy(string2, string);
863 char *ptr = strrchr(string2, '.');
866 //printf("MWindow::clean_indexes 2 %s\n", string2);
867 sprintf(ptr, ".toc");
869 sprintf(ptr, ".mkr");
878 void MWindow::init_awindow()
880 awindow = new AWindow(this);
881 awindow->create_objects();
884 void MWindow::init_gwindow()
886 gwindow = new GWindow(this);
887 gwindow->create_objects();
890 void MWindow::init_tipwindow()
893 twindow = new TipWindow(this);
897 void MWindow::show_warning(int *do_warning, const char *text)
899 if( do_warning && !*do_warning ) return;
901 wwindow = new WWindow(this);
902 wwindow->show_warning(do_warning, text);
905 void MWindow::init_theme()
910 PluginServer *theme_plugin = 0;
911 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
912 if( plugindb->get(i)->theme &&
913 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
914 theme_plugin = plugindb->get(i);
918 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
921 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
922 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
924 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
925 if( plugindb->get(i)->theme &&
926 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
927 theme_plugin = plugindb->get(i);
932 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
936 PluginServer *plugin = new PluginServer(*theme_plugin);
937 if( plugin->open_plugin(0, preferences, 0, 0) ) {
938 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
939 theme_plugin->title);
943 theme = plugin->new_theme();
944 theme->mwindow = this;
945 strcpy(theme->path, plugin->path);
948 // Load default images & settings
949 theme->Theme::initialize();
950 // Load user images & settings
952 // Create menus with user colors
953 theme->build_menus();
958 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
961 void MWindow::init_3d()
963 playback_3d = new Playback3D(this);
964 playback_3d->create_objects();
967 void MWindow::init_edl()
970 edl->create_objects();
971 fill_preset_defaults(default_standard, edl->session);
972 edl->load_defaults(defaults);
973 edl->create_default_tracks();
974 edl->tracks->update_y_pixels(theme);
977 void MWindow::init_compositor()
979 cwindow = new CWindow(this);
980 cwindow->create_objects();
983 void MWindow::init_levelwindow()
985 lwindow = new LevelWindow(this);
986 lwindow->create_objects();
989 VWindow *MWindow::get_viewer(int start_it, int idx)
991 vwindows_lock->lock("MWindow::get_viewer");
992 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
993 if( !vwindow ) idx = vwindows.size();
994 while( !vwindow && --idx >= 0 ) {
995 VWindow *vwin = vwindows[idx];
996 if( !vwin->is_running() || !vwin->get_edl() )
1000 vwindow = new VWindow(this);
1001 vwindow->load_defaults();
1002 vwindow->create_objects();
1003 vwindows.append(vwindow);
1005 vwindows_lock->unlock();
1006 if( start_it ) vwindow->start();
1010 void MWindow::init_cache()
1012 audio_cache = new CICache(preferences);
1013 video_cache = new CICache(preferences);
1014 frame_cache = new FrameCache;
1015 wave_cache = new WaveCache;
1018 void MWindow::init_channeldb()
1020 channeldb_buz->load("channeldb_buz");
1021 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1024 void MWindow::init_menus()
1026 char string[BCTEXTLEN];
1029 BC_CModels::to_text(string, BC_RGB888);
1030 colormodels.append(new ColormodelItem(string, BC_RGB888));
1031 BC_CModels::to_text(string, BC_RGBA8888);
1032 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1033 // BC_CModels::to_text(string, BC_RGB161616);
1034 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1035 // BC_CModels::to_text(string, BC_RGBA16161616);
1036 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1037 BC_CModels::to_text(string, BC_RGB_FLOAT);
1038 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1039 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1040 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1041 BC_CModels::to_text(string, BC_YUV888);
1042 colormodels.append(new ColormodelItem(string, BC_YUV888));
1043 BC_CModels::to_text(string, BC_YUVA8888);
1044 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1045 // BC_CModels::to_text(string, BC_YUV161616);
1046 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1047 // BC_CModels::to_text(string, BC_YUVA16161616);
1048 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1050 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1051 interlace_project_modes.append(new InterlacemodeItem(string, x));
1053 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1054 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1056 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1057 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1059 // Interlacing Modes
1060 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1062 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1063 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1065 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1066 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1068 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1069 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1071 // Interlacing Fixing Methods
1072 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
1073 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
1074 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
1077 void MWindow::init_indexes()
1079 mainindexes = new MainIndexes(this);
1080 mainindexes->start_loop();
1083 void MWindow::init_gui()
1085 gui = new MWindowGUI(this);
1086 gui->lock_window("MWindow::init_gui");
1087 gui->create_objects();
1088 gui->unlock_window();
1089 gui->load_defaults(defaults);
1092 void MWindow::init_signals()
1094 sighandler = new SigHandler;
1095 sighandler->initialize();
1099 void MWindow::init_render()
1101 render = new Render(this);
1102 create_bd = new CreateBD_Thread(this);
1103 create_dvd = new CreateDVD_Thread(this);
1104 batch_render = new BatchRenderThread(this);
1107 void MWindow::init_exportedl()
1109 exportedl = new ExportEDL(this);
1112 void MWindow::init_brender()
1114 if(preferences->use_brender && !brender)
1116 brender_lock->lock("MWindow::init_brender 1");
1117 brender = new BRender(this);
1118 brender->initialize();
1119 session->brender_end = 0;
1120 brender_lock->unlock();
1123 if(!preferences->use_brender && brender)
1125 brender_lock->lock("MWindow::init_brender 2");
1128 session->brender_end = 0;
1129 brender_lock->unlock();
1131 if(brender) brender->restart(edl);
1134 void MWindow::restart_brender()
1136 //printf("MWindow::restart_brender 1\n");
1137 if(brender) brender->restart(edl);
1140 void MWindow::stop_brender()
1142 if(brender) brender->stop();
1145 int MWindow::brender_available(int position)
1148 brender_lock->lock("MWindow::brender_available 1");
1151 if(brender->map_valid)
1153 brender->map_lock->lock("MWindow::brender_available 2");
1154 if(position < brender->map_size &&
1157 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1158 if(brender->map[position] == BRender::RENDERED)
1161 brender->map_lock->unlock();
1164 brender_lock->unlock();
1168 void MWindow::set_brender_start()
1170 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1172 gui->draw_overlays(1);
1176 int MWindow::has_commercials()
1178 return theme->use_commercials;
1181 void MWindow::init_commercials()
1183 if( !commercials ) {
1184 commercials = new Commercials(this);
1185 commercial_active = 0;
1188 commercials->add_user();
1191 void MWindow::commit_commercial()
1193 if( !commercial_active ) return;
1194 commercial_active = 0;
1195 if( !commercials ) return;
1196 commercials->commitDb();
1199 void MWindow::undo_commercial()
1201 if( !commercial_active ) return;
1202 commercial_active = 0;
1203 if( !commercials ) return;
1204 commercials->undoDb();
1207 int MWindow::put_commercial()
1209 double start = edl->local_session->get_selectionstart();
1210 double end = edl->local_session->get_selectionend();
1211 if( start >= end ) return 0;
1213 const char *errmsg = 0;
1215 Tracks *tracks = edl->tracks;
1218 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1219 if( track->data_type != TRACK_VIDEO ) continue;
1220 if( !track->record ) continue;
1221 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1223 int64_t units_start = track->to_units(start,0);
1224 int64_t units_end = track->to_units(end,0);
1225 Edits *edits = track->edits;
1226 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1227 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1228 if(!edit1 && !edit2) continue; // nothing selected
1229 if(!edit2) { // edit2 beyond end of track
1230 edit2 = edits->last;
1231 units_end = edits->length();
1233 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1234 Indexable *indexable = edit1->get_source();
1235 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1238 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1239 if( track->data_type != TRACK_VIDEO ) continue;
1240 if( !track->record ) continue;
1241 int64_t units_start = track->to_units(start,0);
1242 int64_t units_end = track->to_units(end,0);
1243 Edits *edits = track->edits;
1244 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1245 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1246 if(!edit1 && !edit2) continue; // nothing selected
1247 if(!edit2) { // edit2 beyond end of track
1248 edit2 = edits->last;
1249 units_end = edits->length();
1251 Indexable *indexable = edit1->get_source();
1252 Asset *asset = (Asset *)indexable;
1253 File *file = video_cache->check_out(asset, edl);
1254 if( !file ) { errmsg = _("no file"); break; }
1255 int64_t edit_length = units_end - units_start;
1256 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1257 result = commercials->put_clip(file, edit1->channel,
1258 track->from_units(edit_start), track->from_units(edit_length));
1259 video_cache->check_in(asset);
1260 if( result ) { errmsg = _("db failed"); break; }
1263 char string[BCTEXTLEN];
1264 sprintf(string, _("put_commercial: %s"), errmsg);
1265 MainError::show_error(string);
1272 void MWindow::stop_playback(int wait)
1274 int locked = gui->get_window_lock();
1275 if( locked ) gui->unlock_window();
1277 cwindow->playback_engine->que->send_command(STOP,
1281 cwindow->playback_engine->interrupt_playback(wait);
1283 for(int i = 0; i < vwindows.size(); i++) {
1284 VWindow *vwindow = vwindows[i];
1285 if( !vwindow->is_running() ) continue;
1286 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1287 vwindow->playback_engine->interrupt_playback(wait);
1289 if( locked ) gui->lock_window("MWindow::stop_playback");
1292 int MWindow::load_filenames(ArrayList<char*> *filenames,
1294 int update_filename)
1296 ArrayList<EDL*> new_edls;
1297 ArrayList<Asset*> new_assets;
1298 ArrayList<File*> new_files;
1299 const int debug = 0;
1300 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1303 gui->start_hourglass();
1305 // Need to stop playback since tracking depends on the EDL not getting
1309 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1310 undo->update_undo_before();
1313 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1315 // Define new_edls and new_assets to load
1316 int result = 0, ftype = -1;
1317 for(int i = 0; i < filenames->size(); i++)
1320 File *new_file = new File;
1321 Asset *new_asset = new Asset(filenames->get(i));
1322 EDL *new_edl = new EDL;
1323 char string[BCTEXTLEN];
1325 new_edl->create_objects();
1326 new_edl->copy_session(edl);
1327 new_file->set_program(edl->session->program_no);
1329 sprintf(string, _("Loading %s"), new_asset->path);
1330 gui->show_message(string);
1331 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1333 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1334 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1339 // Convert media file to EDL
1341 // Warn about odd image dimensions
1342 if(new_asset->video_data &&
1343 ((new_asset->width % 2) ||
1344 (new_asset->height % 2)))
1346 char string[BCTEXTLEN];
1347 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1351 MainError::show_error(string);
1354 if(new_asset->program >= 0 &&
1355 edl->session->program_no != new_asset->program)
1357 char string[BCTEXTLEN];
1358 sprintf(string, _("%s's index was built for program number %d\n"
1359 "Playback preference is %d.\n Using program %d."),
1360 new_asset->path, new_asset->program,
1361 edl->session->program_no, new_asset->program);
1362 MainError::show_error(string);
1366 if(load_mode != LOADMODE_RESOURCESONLY)
1369 RecordLabels *labels = edl->session->label_cells ?
1370 new RecordLabels(new_file) : 0;
1372 asset_to_edl(new_edl, new_asset, labels);
1374 new_edls.append(new_edl);
1376 new_asset->Garbage::remove_user();
1382 new_assets.append(new_asset);
1386 // Set filename to nothing for assets since save EDL would overwrite them.
1387 if(load_mode == LOADMODE_REPLACE ||
1388 load_mode == LOADMODE_REPLACE_CONCATENATE)
1391 // Reset timeline position
1392 for(int i = 0; i < TOTAL_PANES; i++)
1394 new_edl->local_session->view_start[i] = 0;
1395 new_edl->local_session->track_start[i] = 0;
1403 case FILE_NOT_FOUND:
1404 sprintf(string, _("Failed to open %s"), new_asset->path);
1405 gui->show_message(string, theme->message_error);
1409 case FILE_UNRECOGNIZED_CODEC:
1412 IndexFile indexfile(this, new_asset);
1413 result = indexfile.open_index();
1416 indexfile.close_index();
1419 // Test existing EDLs
1420 for(int j = 0; result && j <= new_edls.total; j++) {
1421 Asset *old_asset = j < new_edls.total ?
1422 new_edls[j]->assets->get_asset(new_asset->path) :
1423 edl->assets->get_asset(new_asset->path);
1425 *new_asset = *old_asset;
1433 char string[BCTEXTLEN];
1435 fs.extract_name(string, new_asset->path);
1437 strcat(string, _("'s format couldn't be determined."));
1438 new_asset->audio_data = 1;
1439 new_asset->format = FILE_PCM;
1440 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1441 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1442 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1443 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1444 new_asset->signed_ = defaults->get("SIGNED_", 1);
1445 new_asset->header = defaults->get("HEADER", 0);
1447 FileFormat fwindow(this);
1448 fwindow.create_objects(new_asset, string);
1449 result = fwindow.run_window();
1452 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1453 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1454 defaults->update("AUDIO_BITS", new_asset->bits);
1455 defaults->update("BYTE_ORDER", new_asset->byte_order);
1456 defaults->update("SIGNED_", new_asset->signed_);
1457 defaults->update("HEADER", new_asset->header);
1464 // Recalculate length
1466 new_file = new File;
1467 result = new_file->open_file(preferences, new_asset, 1, 0);
1469 if(load_mode != LOADMODE_RESOURCESONLY)
1471 RecordLabels *labels = edl->session->label_cells ?
1472 new RecordLabels(new_file) : 0;
1473 asset_to_edl(new_edl, new_asset, labels);
1474 new_edls.append(new_edl);
1475 new_asset->Garbage::remove_user();
1481 new_assets.append(new_asset);
1495 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1496 xml_file.read_from_file(filenames->get(i));
1497 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1499 if(load_mode == LOADMODE_NESTED)
1501 // Load temporary EDL for nesting.
1502 EDL *nested_edl = new EDL;
1503 nested_edl->create_objects();
1504 nested_edl->set_path(filenames->get(i));
1505 nested_edl->load_xml(&xml_file, LOAD_ALL);
1506 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1507 edl_to_nested(new_edl, nested_edl);
1508 nested_edl->Garbage::remove_user();
1512 // Load EDL for pasting
1513 new_edl->load_xml(&xml_file, LOAD_ALL);
1514 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1515 test_plugins(new_edl, filenames->get(i));
1516 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1518 if(load_mode == LOADMODE_REPLACE ||
1519 load_mode == LOADMODE_REPLACE_CONCATENATE)
1521 strcpy(session->filename, filenames->get(i));
1522 strcpy(new_edl->local_session->clip_title,
1525 set_filename(new_edl->local_session->clip_title);
1529 new_edls.append(new_edl);
1535 // edls are in new_edls
1536 if( result && new_edl ) new_edl->Garbage::remove_user();
1537 // assets are copied
1538 if( new_asset ) new_asset->Garbage::remove_user();
1540 // Store for testing index
1541 new_files.append(new_file);
1544 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1547 if(!result) gui->statusbar->default_message();
1555 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1558 // Don't back up here.
1561 // For pasting, clear the active region
1562 if(load_mode == LOADMODE_PASTE ||
1563 load_mode == LOADMODE_NESTED)
1565 double start = edl->local_session->get_selectionstart();
1566 double end = edl->local_session->get_selectionend();
1567 if(!EQUIV(start, end))
1570 edl->session->labels_follow_edits,
1571 edl->session->plugins_follow_edits,
1572 edl->session->autos_follow_edits);
1575 paste_edls(&new_edls,
1579 edl->session->labels_follow_edits,
1580 edl->session->plugins_follow_edits,
1581 edl->session->autos_follow_edits,
1588 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1590 // Add new assets to EDL and schedule assets for index building.
1591 int got_indexes = 0;
1592 for(int i = 0; i < new_edls.size(); i++)
1594 EDL *new_edl = new_edls[i];
1595 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1597 mainindexes->add_next_asset(0,
1598 new_edl->nested_edls->get(j));
1600 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1605 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1606 if(new_assets.size())
1608 for(int i = 0; i < new_assets.size(); i++)
1610 Asset *new_asset = new_assets[i];
1614 for(int j = 0; j < new_files.size(); j++)
1616 new_file = new_files[j];
1617 if(!strcmp(new_file->asset->path,
1625 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1627 edl->assets->update(new_asset);
1633 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1635 // Start examining next batch of index files
1636 if(got_indexes) mainindexes->start_build();
1637 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1640 Track *track = edl->tracks->first;
1643 for(int j = 0; j < track->plugin_set.size(); j++)
1645 PluginSet *plugins = track->plugin_set[j];
1646 Plugin *plugin = plugins->get_first_plugin();
1650 if(load_mode == LOADMODE_REPLACE ||
1651 load_mode == LOADMODE_REPLACE_CONCATENATE)
1653 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1656 show_plugin(plugin);
1664 plugin = (Plugin*)plugin->next;
1668 track = track->next;
1671 // if just opening one new resource in replace mode
1672 if( ftype != FILE_IS_XML &&
1673 ( load_mode == LOADMODE_REPLACE ||
1674 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1676 edl->local_session->preview_start = 0;
1677 edl->local_session->preview_end = edl->tracks->total_playable_length();
1678 edl->local_session->loop_playback = 0;
1679 edl->local_session->set_selectionstart(0);
1680 edl->local_session->set_selectionend(0);
1685 // need to update undo before project, since mwindow is unlocked & a new load
1686 // can begin here. Should really prevent loading until we're done.
1687 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1688 undo->update_undo_after(_("load"), LOAD_ALL);
1690 for(int i = 0; i < new_edls.size(); i++)
1692 new_edls[i]->remove_user();
1694 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1696 new_edls.remove_all();
1698 for(int i = 0; i < new_assets.size(); i++)
1700 new_assets[i]->Garbage::remove_user();
1703 new_assets.remove_all();
1704 new_files.remove_all_objects();
1707 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1708 if(load_mode == LOADMODE_REPLACE ||
1709 load_mode == LOADMODE_REPLACE_CONCATENATE)
1711 session->changes_made = 0;
1715 session->changes_made = 1;
1718 gui->stop_hourglass();
1721 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1722 update_project(load_mode);
1724 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1732 void MWindow::test_plugins(EDL *new_edl, char *path)
1734 char string[BCTEXTLEN];
1736 // Do a check weather plugins exist
1737 for(Track *track = new_edl->tracks->first; track; track = track->next)
1739 for(int k = 0; k < track->plugin_set.total; k++)
1741 PluginSet *plugin_set = track->plugin_set[k];
1742 for(Plugin *plugin = (Plugin*)plugin_set->first;
1744 plugin = (Plugin*)plugin->next)
1746 if(plugin->plugin_type == PLUGIN_STANDALONE)
1748 // ok we need to find it in plugindb
1749 int plugin_found = 0;
1751 for(int j = 0; j < plugindb->size(); j++)
1753 PluginServer *server = plugindb->get(j);
1755 !strcasecmp(server->title, plugin->title) &&
1756 ((track->data_type == TRACK_AUDIO && server->audio) ||
1757 (track->data_type == TRACK_VIDEO && server->video)) &&
1758 (!server->transition))
1765 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1766 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1767 "effect", plugin->title,
1769 MainError::show_error(string);
1775 for(Edit *edit = (Edit*)track->edits->first;
1777 edit = (Edit*)edit->next)
1779 if (edit->transition)
1781 // ok we need to find transition in plugindb
1783 int transition_found = 0;
1784 for(int j = 0; j < plugindb->size(); j++)
1786 PluginServer *server = plugindb->get(j);
1788 !strcasecmp(server->title, edit->transition->title) &&
1789 ((track->data_type == TRACK_AUDIO && server->audio) ||
1790 (track->data_type == TRACK_VIDEO && server->video)) &&
1791 (server->transition))
1792 transition_found = 1;
1795 if (!transition_found)
1798 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1799 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1800 "transition", edit->transition->title,
1802 MainError::show_error(string);
1810 void MWindow::init_shm()
1812 // Fix shared memory
1813 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1815 fprintf(fd, "0x7fffffff");
1820 fd = fopen("/proc/sys/kernel/shmmax", "r");
1822 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1827 fscanf(fd, "%jd", &result);
1830 if(result < 0x7fffffff) {
1831 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1832 "you probably need to be root, or:\n"
1833 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1834 "before trying to start cinelerra.\n"
1835 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1839 void MWindow::create_objects(int want_gui,
1844 const int debug = 0;
1845 if(debug) PRINT_TRACE
1847 // For some reason, init_signals must come after show_splash or the signals won't
1850 if(debug) PRINT_TRACE
1853 if(debug) PRINT_TRACE
1856 if(debug) PRINT_TRACE
1857 default_standard = default_std();
1858 init_defaults(defaults, config_path);
1861 splash_window->operation->update(_("Initializing Plugins"));
1862 init_plugins(this, preferences);
1863 if(debug) PRINT_TRACE
1864 init_ladspa_plugins(this, preferences);
1865 if(debug) PRINT_TRACE
1867 splash_window->operation->update(_("Initializing GUI"));
1868 if(debug) PRINT_TRACE
1871 if(debug) PRINT_TRACE
1875 splash_window->operation->update(_("Initializing Fonts"));
1876 char string[BCTEXTLEN];
1877 strcpy(string, preferences->plugin_dir);
1878 strcat(string, "/" FONT_SEARCHPATH);
1879 BC_Resources::init_fontconfig(string);
1880 if(debug) PRINT_TRACE
1882 // Initialize before too much else is running
1883 // Preferences & theme are required for building MPEG table of contents
1885 // Default project created here
1887 if(debug) PRINT_TRACE
1890 if(debug) PRINT_TRACE
1895 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1897 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1898 if(session->show_vwindow)
1899 get_viewer(1, DEFAULT_VWINDOW);
1900 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1903 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1906 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1909 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1911 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1914 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());
1920 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());
1926 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1927 mainprogress = new MainProgress(this, gui);
1928 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1929 undo = new MainUndo(this);
1931 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1933 plugin_guis = new ArrayList<PluginServer*>;
1934 dead_plugins = new ArrayList<PluginServer*>;
1935 keyframe_threads = new ArrayList<KeyFrameThread*>;
1937 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1940 session->show_vwindow);
1942 // Show all vwindows
1943 // if(session->show_vwindow) {
1944 // for(int j = 0; j < vwindows.size(); j++) {
1945 // VWindow *vwindow = vwindows[j];
1946 // if( !vwindow->is_running() ) continue;
1947 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1950 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1951 // vwindow->gui->lock_window("MWindow::create_objects 1");
1952 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1953 // vwindow->gui->show_window();
1954 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1955 // vwindow->gui->unlock_window();
1960 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1962 if(session->show_cwindow)
1964 cwindow->gui->lock_window("MWindow::create_objects 1");
1965 cwindow->gui->show_window();
1966 cwindow->gui->unlock_window();
1969 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1970 if(session->show_awindow)
1972 awindow->gui->lock_window("MWindow::create_objects 1");
1973 awindow->gui->show_window();
1974 awindow->gui->unlock_window();
1977 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1978 if(session->show_lwindow)
1980 lwindow->gui->lock_window("MWindow::create_objects 1");
1981 lwindow->gui->show_window();
1982 lwindow->gui->unlock_window();
1985 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1987 (int)timer.get_difference(),
1989 if(session->show_gwindow)
1991 gwindow->gui->lock_window("MWindow::create_objects 1");
1992 gwindow->gui->show_window();
1993 gwindow->gui->unlock_window();
1996 if(debug) PRINT_TRACE
1998 gui->lock_window("MWindow::create_objects 1");
1999 gui->mainmenu->load_defaults(defaults);
2000 gui->mainmenu->update_toggles(0);
2001 gui->update_patchbay();
2002 gui->draw_canvas(0, 0);
2003 gui->draw_cursor(1);
2005 gui->raise_window();
2006 gui->unlock_window();
2008 if(debug) PRINT_TRACE
2010 if(preferences->use_tipwindow)
2012 if(debug) PRINT_TRACE
2014 gui->add_keyboard_listener(
2015 (int (BC_WindowBase::*)(BC_WindowBase *))
2016 &MWindowGUI::keyboard_listener);
2020 if(debug) PRINT_TRACE
2022 BC_WindowBase::get_resources()->vframe_shm = 1;
2026 void MWindow::show_splash()
2028 #include "data/heroine_logo9_png.h"
2029 VFrame *frame = new VFramePng(heroine_logo9_png);
2030 BC_DisplayInfo dpyi;
2031 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2032 int rr = (rw < rh ? rw : rh) / 4;
2033 splash_window = new SplashGUI(frame, rr, rr);
2034 splash_window->create_objects();
2037 void MWindow::hide_splash()
2040 delete splash_window;
2045 void MWindow::start()
2049 // vwindows[DEFAULT_VWINDOW]->start();
2060 playback_3d->start();
2069 void MWindow::show_vwindow()
2071 int total_running = 0;
2072 session->show_vwindow = 1;
2074 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2075 // Raise all windows which are visible
2076 for(int j = 0; j < vwindows.size(); j++) {
2077 VWindow *vwindow = vwindows[j];
2078 if( !vwindow->is_running() ) continue;
2079 vwindow->gui->lock_window("MWindow::show_vwindow");
2080 vwindow->gui->show_window(0);
2081 vwindow->gui->raise_window();
2082 vwindow->gui->flush();
2083 vwindow->gui->unlock_window();
2087 // If no windows visible
2090 get_viewer(1, DEFAULT_VWINDOW);
2093 gui->mainmenu->show_vwindow->set_checked(1);
2096 void MWindow::show_awindow()
2098 session->show_awindow = 1;
2099 awindow->gui->lock_window("MWindow::show_awindow");
2100 awindow->gui->show_window();
2101 awindow->gui->raise_window();
2102 awindow->gui->flush();
2103 awindow->gui->unlock_window();
2104 gui->mainmenu->show_awindow->set_checked(1);
2107 char *MWindow::get_cwindow_display()
2109 char *x11_host = screens < 2 || session->window_config == 0 ?
2110 session->a_x11_host : session->b_x11_host;
2111 return *x11_host ? x11_host : 0;
2114 void MWindow::show_cwindow()
2116 session->show_cwindow = 1;
2117 cwindow->show_window();
2118 gui->mainmenu->show_cwindow->set_checked(1);
2121 void MWindow::show_gwindow()
2123 session->show_gwindow = 1;
2125 gwindow->gui->lock_window("MWindow::show_gwindow");
2126 gwindow->gui->show_window();
2127 gwindow->gui->raise_window();
2128 gwindow->gui->flush();
2129 gwindow->gui->unlock_window();
2131 gui->mainmenu->show_gwindow->set_checked(1);
2134 void MWindow::show_lwindow()
2136 session->show_lwindow = 1;
2137 lwindow->gui->lock_window("MWindow::show_lwindow");
2138 lwindow->gui->show_window();
2139 lwindow->gui->raise_window();
2140 lwindow->gui->flush();
2141 lwindow->gui->unlock_window();
2142 gui->mainmenu->show_lwindow->set_checked(1);
2145 int MWindow::tile_windows(int window_config)
2147 int need_reload = 0;
2148 int play_config = window_config==0 ? 0 : 1;
2149 edl->session->playback_config->load_defaults(defaults, play_config);
2150 session->default_window_positions(window_config);
2151 if( screens == 1 ) {
2152 gui->default_positions();
2153 sync_parameters(CHANGE_ALL);
2160 void MWindow::toggle_loop_playback()
2162 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2163 set_loop_boundaries();
2166 gui->draw_overlays(1);
2167 sync_parameters(CHANGE_PARAMS);
2170 //void MWindow::set_titles(int value)
2172 // edl->session->show_titles = value;
2173 // trackmovement(edl->local_session->track_start);
2176 void MWindow::set_screens(int value)
2181 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2183 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2184 edl->session->auto_keyframes = value;
2185 gui->mbuttons->edit_panel->keyframe->update(value);
2187 if(lock_mwindow) gui->unlock_window();
2189 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2190 cwindow->gui->edit_panel->keyframe->update(value);
2191 cwindow->gui->flush();
2192 if(lock_cwindow) cwindow->gui->unlock_window();
2195 void MWindow::set_keyframe_type(int mode)
2197 gui->lock_window("MWindow::set_keyframe_type");
2198 edl->local_session->floatauto_type = mode;
2199 gui->mainmenu->update_toggles(0);
2200 gui->unlock_window();
2203 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2205 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2206 edl->session->editing_mode = new_editing_mode;
2207 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2208 gui->mbuttons->edit_panel->update();
2209 gui->set_editing_mode(1);
2210 if(lock_mwindow) gui->unlock_window();
2213 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2214 cwindow->gui->edit_panel->update();
2215 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2216 if(lock_cwindow) cwindow->gui->unlock_window();
2220 void MWindow::toggle_editing_mode()
2222 int mode = edl->session->editing_mode;
2223 if( mode == EDITING_ARROW )
2224 set_editing_mode(EDITING_IBEAM, 0, 1);
2226 set_editing_mode(EDITING_ARROW, 0, 1);
2230 void MWindow::set_labels_follow_edits(int value)
2232 gui->lock_window("MWindow::set_labels_follow_edits");
2233 edl->session->labels_follow_edits = value;
2234 gui->mbuttons->edit_panel->locklabels->update(value);
2235 gui->mainmenu->labels_follow_edits->set_checked(value);
2237 gui->unlock_window();
2240 void MWindow::sync_parameters(int change_type)
2242 if( in_destructor ) return;
2244 // Sync engines which are playing back
2245 if(cwindow->playback_engine->is_playing_back)
2247 if(change_type == CHANGE_PARAMS)
2249 // TODO: block keyframes until synchronization is done
2250 cwindow->playback_engine->sync_parameters(edl);
2255 int command = cwindow->playback_engine->command->command;
2256 cwindow->playback_engine->que->send_command(STOP,
2260 // Waiting for tracking to finish would make the restart position more
2261 // accurate but it can't lock the window to stop tracking for some reason.
2262 // Not waiting for tracking gives a faster response but restart position is
2263 // only as accurate as the last tracking update.
2264 cwindow->playback_engine->interrupt_playback(0);
2265 cwindow->playback_engine->que->send_command(command,
2274 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2281 void MWindow::age_caches()
2283 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2285 // preferences->cache_size,
2286 // audio_cache->get_memory_usage(1),
2287 // video_cache->get_memory_usage(1),
2288 // frame_cache->get_memory_usage(),
2289 // wave_cache->get_memory_usage(),
2291 frame_cache->age_cache(512);
2292 wave_cache->age_cache(8192);
2294 int64_t memory_usage;
2295 int64_t prev_memory_usage = 0;
2297 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2298 while( !result && prev_memory_usage !=
2299 (memory_usage=video_cache->get_memory_usage(1)) &&
2300 memory_usage > video_size ) {
2301 video_cache->delete_oldest();
2302 prev_memory_usage = memory_usage;
2305 prev_memory_usage = 0;
2307 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2308 while( !result && prev_memory_usage !=
2309 (memory_usage=audio_cache->get_memory_usage(1)) &&
2310 memory_usage > audio_size ) {
2311 audio_cache->delete_oldest();
2312 prev_memory_usage = memory_usage;
2316 void MWindow::reset_android_remote()
2318 gui->use_android_remote(preferences->android_remote);
2322 void MWindow::show_keyframe_gui(Plugin *plugin)
2324 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2325 // Find existing thread
2326 for(int i = 0; i < keyframe_threads->size(); i++)
2328 if(keyframe_threads->get(i)->plugin == plugin)
2330 keyframe_threads->get(i)->start_window(plugin, 0);
2331 keyframe_gui_lock->unlock();
2336 // Find unused thread
2337 for(int i = 0; i < keyframe_threads->size(); i++)
2339 if(!keyframe_threads->get(i)->plugin)
2341 keyframe_threads->get(i)->start_window(plugin, 0);
2342 keyframe_gui_lock->unlock();
2347 // Create new thread
2348 KeyFrameThread *thread = new KeyFrameThread(this);
2349 keyframe_threads->append(thread);
2350 thread->start_window(plugin, 0);
2352 keyframe_gui_lock->unlock();
2359 void MWindow::show_plugin(Plugin *plugin)
2364 // Remove previously deleted plugin GUIs
2365 dead_plugin_lock->lock("MWindow::show_plugin");
2366 dead_plugins->remove_all_objects();
2367 dead_plugin_lock->unlock();
2369 //printf("MWindow::show_plugin %d\n", __LINE__);
2373 plugin_gui_lock->lock("MWindow::show_plugin");
2374 for(int i = 0; i < plugin_guis->total; i++)
2376 // Pointer comparison
2377 if(plugin_guis->get(i)->plugin == plugin)
2379 plugin_guis->get(i)->raise_window();
2386 //printf("MWindow::show_plugin 1\n");
2391 printf("MWindow::show_plugin track not defined.\n");
2393 PluginServer *server = scan_plugindb(plugin->title,
2394 plugin->track->data_type);
2396 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2397 if(server && server->uses_gui)
2399 PluginServer *gui = new PluginServer(*server);
2400 plugin_guis->append(gui);
2401 // Needs mwindow to do GUI
2402 gui->set_mwindow(this);
2403 gui->open_plugin(0, preferences, edl, plugin);
2408 plugin_gui_lock->unlock();
2409 //printf("MWindow::show_plugin %d\n", __LINE__);
2412 //printf("MWindow::show_plugin 2\n");
2415 void MWindow::hide_plugin(Plugin *plugin, int lock)
2418 // Update the toggle
2419 gui->lock_window("MWindow::hide_plugin");
2420 gui->update(0, 1, 0, 0, 0, 0, 0);
2421 gui->unlock_window();
2423 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2424 for(int i = 0; i < plugin_guis->total; i++)
2426 if(plugin_guis->get(i)->plugin == plugin)
2428 PluginServer *ptr = plugin_guis->get(i);
2429 plugin_guis->remove(ptr);
2430 if(lock) plugin_gui_lock->unlock();
2431 // Last command executed in client side close
2432 // Schedule for deletion
2439 if(lock) plugin_gui_lock->unlock();
2442 void MWindow::delete_plugin(PluginServer *plugin)
2444 dead_plugin_lock->lock("MWindow::delete_plugin");
2445 dead_plugins->append(plugin);
2446 dead_plugin_lock->unlock();
2449 void MWindow::hide_plugins()
2451 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2452 while(plugin_guis->size())
2454 PluginServer *ptr = plugin_guis->get(0);
2455 plugin_guis->remove(ptr);
2456 plugin_gui_lock->unlock();
2457 // Last command executed in client side close
2458 // Schedule for deletion
2461 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2463 plugin_gui_lock->unlock();
2465 hide_keyframe_guis();
2468 void MWindow::hide_keyframe_guis()
2470 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2471 for(int i = 0; i < keyframe_threads->size(); i++)
2473 keyframe_threads->get(i)->close_window();
2475 keyframe_gui_lock->unlock();
2478 void MWindow::hide_keyframe_gui(Plugin *plugin)
2480 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2481 for(int i = 0; i < keyframe_threads->size(); i++)
2483 if(keyframe_threads->get(i)->plugin == plugin)
2485 keyframe_threads->get(i)->close_window();
2489 keyframe_gui_lock->unlock();
2492 void MWindow::update_keyframe_guis()
2494 // Send new configuration to keyframe GUI's
2495 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2496 for(int i = 0; i < keyframe_threads->size(); i++)
2498 KeyFrameThread *ptr = keyframe_threads->get(i);
2499 if(edl->tracks->plugin_exists(ptr->plugin))
2503 ptr->close_window();
2506 keyframe_gui_lock->unlock();
2509 void MWindow::update_plugin_guis(int do_keyframe_guis)
2511 // Send new configuration to plugin GUI's
2512 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2514 for(int i = 0; i < plugin_guis->size(); i++)
2516 PluginServer *ptr = plugin_guis->get(i);
2517 if(edl->tracks->plugin_exists(ptr->plugin))
2521 // Schedule for deletion if no plugin
2522 plugin_guis->remove_number(i);
2531 // Change plugin variable if not visible
2532 Track *track = edl->tracks->first;
2535 for(int i = 0; i < track->plugin_set.size(); i++)
2537 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2541 for(int i = 0; i < plugin_guis->size(); i++)
2543 PluginServer *server = plugin_guis->get(i);
2544 if(server->plugin == plugin)
2551 if(!got_it) plugin->show = 0;
2553 plugin = (Plugin*)plugin->next;
2557 track = track->next;
2560 plugin_gui_lock->unlock();
2563 if(do_keyframe_guis) update_keyframe_guis();
2566 int MWindow::plugin_gui_open(Plugin *plugin)
2569 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2570 for(int i = 0; i < plugin_guis->total; i++)
2572 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2578 plugin_gui_lock->unlock();
2582 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2584 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2585 for(int i = 0; i < plugin_guis->total; i++)
2587 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2589 plugin_guis->get(i)->render_gui(data);
2593 plugin_gui_lock->unlock();
2596 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2598 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2599 for(int i = 0; i < plugin_guis->total; i++)
2601 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2603 plugin_guis->get(i)->render_gui(data, size);
2607 plugin_gui_lock->unlock();
2611 void MWindow::update_plugin_states()
2613 plugin_gui_lock->lock("MWindow::update_plugin_states");
2614 for(int i = 0; i < plugin_guis->total; i++)
2618 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2619 PluginServer *src_plugingui = plugin_guis->get(i);
2621 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2622 for(Track *track = edl->tracks->first;
2624 track = track->next)
2627 j < track->plugin_set.total && !result;
2630 PluginSet *plugin_set = track->plugin_set[j];
2631 for(Plugin *plugin = (Plugin*)plugin_set->first;
2633 plugin = (Plugin*)plugin->next)
2635 if(plugin == src_plugin &&
2636 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2642 // Doesn't exist anymore
2645 hide_plugin(src_plugin, 0);
2649 plugin_gui_lock->unlock();
2653 void MWindow::update_plugin_titles()
2655 for(int i = 0; i < plugin_guis->total; i++)
2657 plugin_guis->get(i)->update_title();
2661 int MWindow::asset_to_edl(EDL *new_edl,
2663 RecordLabels *labels)
2665 const int debug = 0;
2666 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2669 // Keep frame rate, sample rate, and output size unchanged.
2670 // These parameters would revert the project if VWindow displayed an asset
2671 // of different size than the project.
2672 if(new_asset->video_data)
2674 new_edl->session->video_tracks = new_asset->layers;
2677 new_edl->session->video_tracks = 0;
2679 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2685 if(new_asset->audio_data)
2687 new_edl->session->audio_tracks = new_asset->channels;
2690 new_edl->session->audio_tracks = 0;
2691 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2693 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2694 new_edl->create_default_tracks();
2695 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2696 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2700 //printf("MWindow::asset_to_edl 3\n");
2701 new_edl->insert_asset(new_asset,
2706 //printf("MWindow::asset_to_edl 3\n");
2707 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2709 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2710 if(edl->session->cursor_on_frames)
2712 double length = new_edl->tracks->total_length();
2713 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2714 new_edl->tracks->clear(length, edl_length, 1, 1);
2720 char string[BCTEXTLEN];
2722 fs.extract_name(string, new_asset->path);
2723 //printf("MWindow::asset_to_edl 3\n");
2725 strcpy(new_edl->local_session->clip_title, string);
2726 //printf("MWindow::asset_to_edl 4 %s\n", string);
2727 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2732 int MWindow::edl_to_nested(EDL *new_edl,
2736 // Keep frame rate, sample rate, and output size unchanged.
2737 // These parameters would revert the project if VWindow displayed an asset
2738 // of different size than the project.
2742 // Nest all video & audio outputs
2743 new_edl->session->video_tracks = 1;
2744 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2745 new_edl->create_default_tracks();
2749 new_edl->insert_asset(0,
2755 char string[BCTEXTLEN];
2757 fs.extract_name(string, nested_edl->path);
2758 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2760 strcpy(new_edl->local_session->clip_title, string);
2765 // Reset everything after a load.
2766 void MWindow::update_project(int load_mode)
2768 const int debug = 0;
2770 if(debug) PRINT_TRACE
2772 edl->tracks->update_y_pixels(theme);
2774 if(debug) PRINT_TRACE
2776 if(load_mode == LOADMODE_REPLACE ||
2777 load_mode == LOADMODE_REPLACE_CONCATENATE)
2782 gui->update(1, 1, 1, 1, 1, 1, 1);
2783 if(debug) PRINT_TRACE
2784 gui->unlock_window();
2786 cwindow->gui->lock_window("MWindow::update_project 1");
2787 cwindow->update(0, 0, 1, 1, 1);
2788 cwindow->gui->unlock_window();
2790 if(debug) PRINT_TRACE
2792 // Close all the vwindows
2793 if(load_mode == LOADMODE_REPLACE ||
2794 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2795 if(debug) PRINT_TRACE
2796 int first_vwindow = 0;
2797 if(session->show_vwindow) first_vwindow = 1;
2798 // Change visible windows to no source
2799 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2800 VWindow *vwindow = vwindows[i];
2801 if( !vwindow->is_running() ) continue;
2802 vwindow->change_source(-1);
2805 // Close remaining windows
2806 for(int i = first_vwindow; i < vwindows.size(); i++) {
2807 VWindow *vwindow = vwindows[i];
2808 if( !vwindow->is_running() ) continue;
2809 vwindow->close_window();
2811 if(debug) PRINT_TRACE
2813 else if(vwindows.size()) {
2814 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2815 if( vwindow->is_running() ) {
2816 vwindow->gui->lock_window("MWindow::update_project");
2818 vwindow->gui->unlock_window();
2822 if(debug) PRINT_TRACE
2823 cwindow->gui->lock_window("MWindow::update_project 2");
2824 cwindow->gui->timebar->update(0);
2825 cwindow->gui->unlock_window();
2827 if(debug) PRINT_TRACE
2828 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2833 awindow->gui->async_update_assets();
2834 if(debug) PRINT_TRACE
2836 gui->lock_window("MWindow::update_project");
2838 if(debug) PRINT_TRACE
2841 void MWindow::remove_indexfile(Indexable *indexable)
2843 if( !indexable->is_asset ) return;
2844 Asset *asset = (Asset *)indexable;
2846 IndexFile::delete_index(preferences, asset, ".toc");
2847 IndexFile::delete_index(preferences, asset, ".idx");
2848 IndexFile::delete_index(preferences, asset, ".mkr");
2851 void MWindow::rebuild_indices()
2853 for(int i = 0; i < session->drag_assets->total; i++)
2855 Indexable *indexable = session->drag_assets->get(i);
2856 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2857 remove_indexfile(indexable);
2858 // Schedule index build
2859 IndexState *index_state = indexable->index_state;
2860 index_state->index_status = INDEX_NOTTESTED;
2861 if( indexable->is_asset ) {
2862 Asset *asset = (Asset *)indexable;
2863 if( asset->format != FILE_PCM )
2864 asset->reset_audio();
2865 asset->reset_video();
2867 mainindexes->add_next_asset(0, indexable);
2869 mainindexes->start_build();
2873 void MWindow::save_backup()
2877 edl->set_path(session->filename);
2878 char backup_path[BCTEXTLEN];
2879 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2880 File::get_config_path(), BACKUP_FILE);
2881 edl->save_xml(&file, backup_path, 0, 0);
2882 file.terminate_string();
2884 fs.complete_path(backup_path);
2886 if(file.write_to_file(backup_path))
2889 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
2890 gui->show_message(string2);
2894 void MWindow::load_backup()
2896 ArrayList<char*> path_list;
2897 path_list.set_array_delete();
2899 char backup_path[BCTEXTLEN];
2900 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2901 File::get_config_path(), BACKUP_FILE);
2903 fs.complete_path(backup_path);
2905 path_list.append(out_path = new char[strlen(backup_path) + 1]);
2906 strcpy(out_path, backup_path);
2908 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2909 edl->local_session->clip_title[0] = 0;
2910 // This is unique to backups since the path of the backup is different than the
2911 // path of the project.
2912 set_filename(edl->path);
2913 path_list.remove_all_objects();
2917 static inline int gcd(int m, int n)
2920 if( m < n ) { r = m; m = n; n = r; }
2921 while( (r = m % n) != 0 ) { m = n; n = r; }
2925 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2928 if(!width || !height) return 1;
2929 if( width == 720 && (height == 480 || height == 576) ) {
2930 w = 4; h = 3; return 0; // for NTSC and PAL
2932 double ar = (double)width / height;
2933 // square-ish pixels
2934 if( EQUIV(ar, 1.0000) ) return 0;
2935 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2936 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2937 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2938 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2939 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2940 int ww = width, hh = height;
2941 // numerator, denominator must be under mx
2942 int mx = 255, n = gcd(ww, hh);
2943 if( n > 1 ) { ww /= n; hh /= n; }
2944 // search near height in case extra/missing lines
2945 if( ww >= mx || hh >= mx ) {
2946 double err = height; // +/- 2 percent height
2947 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2948 int iw = width, ih = height+i;
2949 if( (n=gcd(iw, ih)) > 1 ) {
2950 int u = iw/n; if( u >= mx ) continue;
2951 int v = ih/n; if( v >= mx ) continue;
2952 double r = (double) u/v, er = fabs(ar-r);
2953 if( er >= err ) continue;
2954 err = er; ww = u; hh = v;
2963 void MWindow::reset_caches()
2965 frame_cache->remove_all();
2966 wave_cache->remove_all();
2967 audio_cache->remove_all();
2968 video_cache->remove_all();
2969 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2970 cwindow->playback_engine->audio_cache->remove_all();
2971 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2972 cwindow->playback_engine->video_cache->remove_all();
2974 for(int i = 0; i < vwindows.size(); i++) {
2975 VWindow *vwindow = vwindows[i];
2976 if( !vwindow->is_running() ) continue;
2977 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2978 vwindow->playback_engine->audio_cache->remove_all();
2979 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2980 vwindow->playback_engine->video_cache->remove_all();
2984 void MWindow::remove_asset_from_caches(Asset *asset)
2986 gui->resource_thread->get_video_source(0);
2987 gui->resource_thread->get_audio_source(0);
2988 frame_cache->remove_asset(asset);
2989 wave_cache->remove_asset(asset);
2990 audio_cache->delete_entry(asset);
2991 video_cache->delete_entry(asset);
2992 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2993 cwindow->playback_engine->audio_cache->delete_entry(asset);
2994 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2995 cwindow->playback_engine->video_cache->delete_entry(asset);
2996 for(int i = 0; i < vwindows.size(); i++) {
2997 VWindow *vwindow = vwindows[i];
2998 if( !vwindow->is_running() ) continue;
2999 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3000 vwindow->playback_engine->audio_cache->delete_entry(asset);
3001 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3002 vwindow->playback_engine->video_cache->delete_entry(asset);
3007 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3008 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3010 for(int i = 0; i < session->drag_assets->total; i++) {
3011 Indexable *indexable = session->drag_assets->get(i);
3012 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3015 // Remove from VWindow.
3016 for(int i = 0; i < session->drag_clips->total; i++) {
3017 for(int j = 0; j < vwindows.size(); j++) {
3018 VWindow *vwindow = vwindows[j];
3019 if( !vwindow->is_running() ) continue;
3020 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3021 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3022 vwindow->delete_source(1, 1);
3023 vwindow->gui->unlock_window();
3028 for(int i = 0; i < session->drag_assets->size(); i++) {
3029 for(int j = 0; j < vwindows.size(); j++) {
3030 VWindow *vwindow = vwindows[j];
3031 if( !vwindow->is_running() ) continue;
3032 if(session->drag_assets->get(i) == vwindow->get_source()) {
3033 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3034 vwindow->delete_source(1, 1);
3035 vwindow->gui->unlock_window();
3040 for(int i = 0; i < session->drag_assets->size(); i++) {
3041 Indexable *indexable = session->drag_assets->get(i);
3042 remove_indexfile(indexable);
3045 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3046 if(push_undo) undo->update_undo_before();
3047 if(drag_assets) edl->remove_from_project(drag_assets);
3048 if(drag_clips) edl->remove_from_project(session->drag_clips);
3049 if(redraw) save_backup();
3050 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3055 gui->lock_window("MWindow::remove_assets_from_project 3");
3063 gui->unlock_window();
3065 // Removes from playback here
3066 sync_parameters(CHANGE_ALL);
3069 awindow->gui->async_update_assets();
3072 void MWindow::remove_assets_from_disk()
3075 for(int i = 0; i < session->drag_assets->total; i++)
3077 remove(session->drag_assets->get(i)->path);
3080 remove_assets_from_project(1,
3082 session->drag_assets,
3083 session->drag_clips);
3086 void MWindow::dump_plugins(FILE *fp)
3088 if( !plugindb ) return;
3089 for(int i = 0; i < plugindb->total; i++)
3091 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3092 " synth=%d transition=%d theme=%d %s\n",
3093 plugindb->get(i)->plugin_type,
3094 plugindb->get(i)->audio,
3095 plugindb->get(i)->video,
3096 plugindb->get(i)->realtime,
3097 plugindb->get(i)->multichannel,
3098 plugindb->get(i)->get_synthesis(),
3099 plugindb->get(i)->transition,
3100 plugindb->get(i)->theme,
3101 plugindb->get(i)->title);
3105 void MWindow::dump_edl(FILE *fp)
3111 void MWindow::dump_undo(FILE *fp)
3117 void MWindow::dump_exe(FILE *fp)
3119 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3120 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3121 int ret = readlink(proc_path, exe_path, sizeof(exe_path));
3122 if( ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3125 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3126 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
3127 int fd = open(exe_path,O_RDONLY+O_NONBLOCK);
3128 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3131 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3132 int64_t maxsz = 1024*pagsz;
3133 int64_t size = st.st_size, pos = 0;
3135 while( (bfrsz = size-pos) > 0 ) {
3136 if( bfrsz > maxsz ) bfrsz = maxsz;
3137 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3138 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3139 if( bfr == MAP_FAILED ) break;
3140 sha1.addBytes(bfr, bfrsz);
3145 ret = pos < size ? EIO : 0;
3146 fprintf(fp, "SHA1: ");
3147 uint8_t digest[20]; sha1.computeHash(digest);
3148 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3149 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3150 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3154 void MWindow::trap_hook(FILE *fp, void *vp)
3156 MWindow *mwindow = (MWindow *)vp;
3157 // fprintf(fp, "\nPLUGINS:\n");
3158 // mwindow->dump_plugins(fp);
3159 fprintf(fp, "\nEDL:\n");
3160 mwindow->dump_edl(fp);
3161 fprintf(fp, "\nUNDO:\n");
3162 mwindow->dump_undo(fp);
3163 fprintf(fp, "\nEXE:\n");
3164 mwindow->dump_exe(fp);
3172 int MWindow::save_defaults()
3174 gui->save_defaults(defaults);
3175 edl->save_defaults(defaults);
3176 session->save_defaults(defaults);
3177 preferences->save_defaults(defaults);
3179 for(int i = 0; i < plugin_guis->total; i++)
3181 // Pointer comparison
3182 plugin_guis->get(i)->save_defaults();
3184 awindow->save_defaults(defaults);
3190 int MWindow::run_script(FileXML *script)
3192 int result = 0, result2 = 0;
3193 while(!result && !result2)
3195 result = script->read_tag();
3198 if(script->tag.title_is("new_project"))
3200 // Run new in immediate mode.
3201 // gui->mainmenu->new_project->run_script(script);
3204 if(script->tag.title_is("record"))
3206 // Run record as a thread. It is a terminal command.
3208 // Will read the complete scipt file without letting record read it if not
3214 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3221 // ================================= synchronization
3224 int MWindow::interrupt_indexes()
3226 mainprogress->cancelled = 1;
3227 mainindexes->interrupt_build();
3233 void MWindow::next_time_format()
3235 switch(edl->session->time_format)
3237 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3238 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3239 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3240 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3241 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3242 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3243 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3246 time_format_common();
3249 void MWindow::prev_time_format()
3251 switch(edl->session->time_format)
3253 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3254 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3255 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3256 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3257 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3258 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3259 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3262 time_format_common();
3265 void MWindow::time_format_common()
3267 gui->lock_window("MWindow::next_time_format");
3268 gui->redraw_time_dependancies();
3271 char string[BCTEXTLEN], string2[BCTEXTLEN];
3272 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3273 gui->show_message(string);
3275 gui->unlock_window();
3279 int MWindow::set_filename(const char *filename)
3281 if( filename != session->filename )
3282 strcpy(session->filename, filename);
3283 if( filename != edl->path )
3284 strcpy(edl->path, filename);
3288 if(filename[0] == 0)
3290 gui->set_title(PROGRAM_NAME);
3295 char string[BCTEXTLEN], string2[BCTEXTLEN];
3296 dir.extract_name(string, filename);
3297 sprintf(string2, PROGRAM_NAME ": %s", string);
3298 gui->set_title(string2);
3311 int MWindow::set_loop_boundaries()
3313 double start = edl->local_session->get_selectionstart();
3314 double end = edl->local_session->get_selectionend();
3322 if(edl->tracks->total_length())
3325 end = edl->tracks->total_length();
3332 if(edl->local_session->loop_playback && start != end)
3334 edl->local_session->loop_start = start;
3335 edl->local_session->loop_end = end;
3346 int MWindow::reset_meters()
3348 cwindow->gui->lock_window("MWindow::reset_meters 1");
3349 cwindow->gui->meters->reset_meters();
3350 cwindow->gui->unlock_window();
3352 for(int j = 0; j < vwindows.size(); j++) {
3353 VWindow *vwindow = vwindows[j];
3354 if( !vwindow->is_running() ) continue;
3355 vwindow->gui->lock_window("MWindow::reset_meters 2");
3356 vwindow->gui->meters->reset_meters();
3357 vwindow->gui->unlock_window();
3360 lwindow->gui->lock_window("MWindow::reset_meters 3");
3361 lwindow->gui->panel->reset_meters();
3362 lwindow->gui->unlock_window();
3364 gui->lock_window("MWindow::reset_meters 4");
3365 gui->reset_meters();
3366 gui->unlock_window();
3371 void MWindow::resync_guis()
3375 gui->lock_window("MWindow::resync_guis");
3376 gui->update(1, 1, 1, 1, 1, 1, 0);
3377 gui->unlock_window();
3379 cwindow->gui->lock_window("MWindow::resync_guis");
3380 cwindow->gui->resize_event(cwindow->gui->get_w(),
3381 cwindow->gui->get_h());
3382 int channels = edl->session->audio_channels;
3383 cwindow->gui->meters->set_meters(channels, 1);
3384 cwindow->gui->flush();
3385 cwindow->gui->unlock_window();
3387 for(int i = 0; i < vwindows.size(); i++) {
3388 VWindow *vwindow = vwindows[i];
3389 if( !vwindow->is_running() ) continue;
3390 vwindow->gui->lock_window("MWindow::resync_guis");
3391 vwindow->gui->resize_event(vwindow->gui->get_w(),
3392 vwindow->gui->get_h());
3393 vwindow->gui->meters->set_meters(channels, 1);
3394 vwindow->gui->flush();
3395 vwindow->gui->unlock_window();
3398 lwindow->gui->lock_window("MWindow::resync_guis");
3399 lwindow->gui->panel->set_meters(channels, 1);
3400 lwindow->gui->flush();
3401 lwindow->gui->unlock_window();
3404 if(((edl->session->output_w % 4) ||
3405 (edl->session->output_h % 4)) &&
3406 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3408 MainError::show_error(
3409 _("This project's dimensions are not multiples of 4 so\n"
3410 "it can't be rendered by OpenGL."));
3415 sync_parameters(CHANGE_ALL);
3418 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3420 File *file = new File;
3421 EDLSession *session = edl->session;
3422 double old_framerate = session->frame_rate;
3423 double old_samplerate = session->sample_rate;
3424 int result = file->open_file(preferences, asset, 1, 0);
3425 if( !result && delete_tracks > 0 )
3426 undo->update_undo_before();
3427 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3428 // try to get asset up to date, may fail
3429 file->select_video_stream(asset, vstream);
3430 // either way use what was/is there.
3431 double framerate = asset->get_frame_rate();
3432 int width = asset->get_w();
3433 int height = asset->get_h();
3434 // must be multiple of 4 for opengl
3435 width = (width+3) & ~3; height = (height+3) & ~3;
3436 int driver = session->playback_config->vconfig->driver;
3437 int color_model = file->get_best_colormodel(asset, driver);
3438 // color_model = BC_CModels::is_yuv(color_model) ?
3439 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3440 // BC_CModels::is_float(color_model) ?
3441 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3442 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3443 // have alpha for now
3444 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3445 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3446 session->color_model = color_model;
3447 session->output_w = width;
3448 session->output_h = height;
3449 session->frame_rate = framerate;
3450 // not, asset->actual_width/actual_height
3451 asset->width = session->output_w;
3452 asset->height = session->output_h;
3453 asset->frame_rate = session->frame_rate;
3454 create_aspect_ratio(session->aspect_w, session->aspect_h,
3455 session->output_w, session->output_h);
3456 Track *track = edl->tracks->first;
3457 for( Track *next_track=0; track; track=next_track ) {
3458 next_track = track->next;
3459 if( track->data_type != TRACK_VIDEO ) continue;
3460 if( delete_tracks ) {
3461 Edit *edit = track->edits->first;
3462 for( Edit *next_edit=0; edit; edit=next_edit ) {
3463 next_edit = edit->next;
3464 if( edit->channel != vstream ||
3465 !edit->asset || !edit->asset->is_asset ||
3466 *asset != *edit->asset )
3470 if( track->edits->first ) {
3471 track->track_w = edl->session->output_w;
3472 track->track_h = edl->session->output_h;
3474 else if( delete_tracks )
3475 edl->tracks->delete_track(track);
3477 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3479 if( !result && asset->audio_data && asset->channels > 0 ) {
3480 session->sample_rate = asset->get_sample_rate();
3481 int64_t channel_mask = 0;
3482 int astrm = !asset->video_data ? -1 :
3483 file->get_audio_for_video(vstream, astream, channel_mask);
3484 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3485 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3487 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3488 if( channels < 1 ) channels = 1;
3489 if( channels > 6 ) channels = 6;
3490 session->audio_tracks = session->audio_channels = channels;
3491 switch( channels ) {
3493 session->achannel_positions[0] = 90;
3494 session->achannel_positions[1] = 150;
3495 session->achannel_positions[2] = 30;
3496 session->achannel_positions[3] = 210;
3497 session->achannel_positions[4] = 330;
3498 session->achannel_positions[5] = 270;
3501 session->achannel_positions[0] = 180;
3502 session->achannel_positions[1] = 0;
3505 session->achannel_positions[1] = 90;
3508 if( !channels ) break;
3509 double t = 0, dt = 360./channels;
3510 for( int i=channels; --i>=0; t+=dt )
3511 session->achannel_positions[i] = int(t+0.5);
3514 remap_audio(MWindow::AUDIO_1_TO_1);
3516 if( delete_tracks ) {
3517 Track *track = edl->tracks->first;
3518 for( Track *next_track=0; track; track=next_track ) {
3519 next_track = track->next;
3520 if( track->data_type != TRACK_AUDIO ) continue;
3521 Edit *edit = track->edits->first;
3522 for( Edit *next_edit=0; edit; edit=next_edit ) {
3523 next_edit = edit->next;
3524 if( !((1<<edit->channel) & channel_mask) ||
3525 !edit->asset || !edit->asset->is_asset ||
3526 *asset != *edit->asset )
3529 if( !track->edits->first )
3530 edl->tracks->delete_track(track);
3534 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3537 if( !result && delete_tracks > 0 ) {
3539 undo->update_undo_after(_("select asset"), LOAD_ALL);
3545 int MWindow::select_asset(int vtrack, int delete_tracks)
3547 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3549 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3550 if( !track ) return 1;
3551 Edit *edit = track->edits->first;
3552 if( !edit ) return 1;
3553 Asset *asset = edit->asset;
3554 if( !asset || !asset->is_asset ) return 1;
3555 return select_asset(asset, edit->channel, 0, delete_tracks);
3558 void MWindow::dump_plugindb(FILE *fp)
3560 if( !plugindb ) return;
3561 for(int i = 0; i < plugindb->total; i++)
3562 plugindb->get(i)->dump(fp);