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 int MWindow::wait_warning()
907 return wwindow->wait_result();
910 void MWindow::init_theme()
915 PluginServer *theme_plugin = 0;
916 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
917 if( plugindb->get(i)->theme &&
918 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
919 theme_plugin = plugindb->get(i);
923 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
926 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
927 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
929 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
930 if( plugindb->get(i)->theme &&
931 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
932 theme_plugin = plugindb->get(i);
937 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
941 PluginServer *plugin = new PluginServer(*theme_plugin);
942 if( plugin->open_plugin(0, preferences, 0, 0) ) {
943 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
944 theme_plugin->title);
948 theme = plugin->new_theme();
949 theme->mwindow = this;
950 strcpy(theme->path, plugin->path);
953 // Load default images & settings
954 theme->Theme::initialize();
955 // Load user images & settings
957 // Create menus with user colors
958 theme->build_menus();
963 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
966 void MWindow::init_3d()
968 playback_3d = new Playback3D(this);
969 playback_3d->create_objects();
972 void MWindow::init_edl()
975 edl->create_objects();
976 fill_preset_defaults(default_standard, edl->session);
977 edl->load_defaults(defaults);
978 edl->create_default_tracks();
979 edl->tracks->update_y_pixels(theme);
982 void MWindow::init_compositor()
984 cwindow = new CWindow(this);
985 cwindow->create_objects();
988 void MWindow::init_levelwindow()
990 lwindow = new LevelWindow(this);
991 lwindow->create_objects();
994 VWindow *MWindow::get_viewer(int start_it, int idx)
996 vwindows_lock->lock("MWindow::get_viewer");
997 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
998 if( !vwindow ) idx = vwindows.size();
999 while( !vwindow && --idx >= 0 ) {
1000 VWindow *vwin = vwindows[idx];
1001 if( !vwin->is_running() || !vwin->get_edl() )
1005 vwindow = new VWindow(this);
1006 vwindow->load_defaults();
1007 vwindow->create_objects();
1008 vwindows.append(vwindow);
1010 vwindows_lock->unlock();
1011 if( start_it ) vwindow->start();
1015 void MWindow::init_cache()
1017 audio_cache = new CICache(preferences);
1018 video_cache = new CICache(preferences);
1019 frame_cache = new FrameCache;
1020 wave_cache = new WaveCache;
1023 void MWindow::init_channeldb()
1025 channeldb_buz->load("channeldb_buz");
1026 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1029 void MWindow::init_menus()
1031 char string[BCTEXTLEN];
1034 BC_CModels::to_text(string, BC_RGB888);
1035 colormodels.append(new ColormodelItem(string, BC_RGB888));
1036 BC_CModels::to_text(string, BC_RGBA8888);
1037 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1038 // BC_CModels::to_text(string, BC_RGB161616);
1039 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1040 // BC_CModels::to_text(string, BC_RGBA16161616);
1041 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1042 BC_CModels::to_text(string, BC_RGB_FLOAT);
1043 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1044 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1045 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1046 BC_CModels::to_text(string, BC_YUV888);
1047 colormodels.append(new ColormodelItem(string, BC_YUV888));
1048 BC_CModels::to_text(string, BC_YUVA8888);
1049 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1050 // BC_CModels::to_text(string, BC_YUV161616);
1051 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1052 // BC_CModels::to_text(string, BC_YUVA16161616);
1053 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1055 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1056 interlace_project_modes.append(new InterlacemodeItem(string, x));
1058 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1059 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1061 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1062 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1064 // Interlacing Modes
1065 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1067 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1068 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1070 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1071 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1073 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1074 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1076 // Interlacing Fixing Methods
1077 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
1078 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
1079 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
1082 void MWindow::init_indexes()
1084 mainindexes = new MainIndexes(this);
1085 mainindexes->start_loop();
1088 void MWindow::init_gui()
1090 gui = new MWindowGUI(this);
1091 gui->lock_window("MWindow::init_gui");
1092 gui->create_objects();
1093 gui->unlock_window();
1094 gui->load_defaults(defaults);
1097 void MWindow::init_signals()
1099 sighandler = new SigHandler;
1100 sighandler->initialize();
1104 void MWindow::init_render()
1106 render = new Render(this);
1107 create_bd = new CreateBD_Thread(this);
1108 create_dvd = new CreateDVD_Thread(this);
1109 batch_render = new BatchRenderThread(this);
1112 void MWindow::init_exportedl()
1114 exportedl = new ExportEDL(this);
1117 void MWindow::init_brender()
1119 if(preferences->use_brender && !brender)
1121 brender_lock->lock("MWindow::init_brender 1");
1122 brender = new BRender(this);
1123 brender->initialize();
1124 session->brender_end = 0;
1125 brender_lock->unlock();
1128 if(!preferences->use_brender && brender)
1130 brender_lock->lock("MWindow::init_brender 2");
1133 session->brender_end = 0;
1134 brender_lock->unlock();
1136 if(brender) brender->restart(edl);
1139 void MWindow::restart_brender()
1141 //printf("MWindow::restart_brender 1\n");
1142 if(brender) brender->restart(edl);
1145 void MWindow::stop_brender()
1147 if(brender) brender->stop();
1150 int MWindow::brender_available(int position)
1153 brender_lock->lock("MWindow::brender_available 1");
1156 if(brender->map_valid)
1158 brender->map_lock->lock("MWindow::brender_available 2");
1159 if(position < brender->map_size &&
1162 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1163 if(brender->map[position] == BRender::RENDERED)
1166 brender->map_lock->unlock();
1169 brender_lock->unlock();
1173 void MWindow::set_brender_start()
1175 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1177 gui->draw_overlays(1);
1181 int MWindow::has_commercials()
1183 return theme->use_commercials;
1186 void MWindow::init_commercials()
1188 if( !commercials ) {
1189 commercials = new Commercials(this);
1190 commercial_active = 0;
1193 commercials->add_user();
1196 void MWindow::commit_commercial()
1198 if( !commercial_active ) return;
1199 commercial_active = 0;
1200 if( !commercials ) return;
1201 commercials->commitDb();
1204 void MWindow::undo_commercial()
1206 if( !commercial_active ) return;
1207 commercial_active = 0;
1208 if( !commercials ) return;
1209 commercials->undoDb();
1212 int MWindow::put_commercial()
1214 double start = edl->local_session->get_selectionstart();
1215 double end = edl->local_session->get_selectionend();
1216 if( start >= end ) return 0;
1218 const char *errmsg = 0;
1220 Tracks *tracks = edl->tracks;
1223 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1224 if( track->data_type != TRACK_VIDEO ) continue;
1225 if( !track->record ) continue;
1226 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1228 int64_t units_start = track->to_units(start,0);
1229 int64_t units_end = track->to_units(end,0);
1230 Edits *edits = track->edits;
1231 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1232 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1233 if(!edit1 && !edit2) continue; // nothing selected
1234 if(!edit2) { // edit2 beyond end of track
1235 edit2 = edits->last;
1236 units_end = edits->length();
1238 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1239 Indexable *indexable = edit1->get_source();
1240 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1243 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1244 if( track->data_type != TRACK_VIDEO ) continue;
1245 if( !track->record ) continue;
1246 int64_t units_start = track->to_units(start,0);
1247 int64_t units_end = track->to_units(end,0);
1248 Edits *edits = track->edits;
1249 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1250 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1251 if(!edit1 && !edit2) continue; // nothing selected
1252 if(!edit2) { // edit2 beyond end of track
1253 edit2 = edits->last;
1254 units_end = edits->length();
1256 Indexable *indexable = edit1->get_source();
1257 Asset *asset = (Asset *)indexable;
1258 File *file = video_cache->check_out(asset, edl);
1259 if( !file ) { errmsg = _("no file"); break; }
1260 int64_t edit_length = units_end - units_start;
1261 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1262 result = commercials->put_clip(file, edit1->channel,
1263 track->from_units(edit_start), track->from_units(edit_length));
1264 video_cache->check_in(asset);
1265 if( result ) { errmsg = _("db failed"); break; }
1268 char string[BCTEXTLEN];
1269 sprintf(string, _("put_commercial: %s"), errmsg);
1270 MainError::show_error(string);
1277 void MWindow::stop_playback(int wait)
1279 int locked = gui->get_window_lock();
1280 if( locked ) gui->unlock_window();
1282 cwindow->playback_engine->que->send_command(STOP,
1286 cwindow->playback_engine->interrupt_playback(wait);
1288 for(int i = 0; i < vwindows.size(); i++) {
1289 VWindow *vwindow = vwindows[i];
1290 if( !vwindow->is_running() ) continue;
1291 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1292 vwindow->playback_engine->interrupt_playback(wait);
1294 if( locked ) gui->lock_window("MWindow::stop_playback");
1297 int MWindow::load_filenames(ArrayList<char*> *filenames,
1299 int update_filename)
1301 ArrayList<EDL*> new_edls;
1302 ArrayList<Asset*> new_assets;
1303 ArrayList<File*> new_files;
1304 const int debug = 0;
1305 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1308 gui->start_hourglass();
1310 // Need to stop playback since tracking depends on the EDL not getting
1314 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1315 undo->update_undo_before();
1318 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1320 // Define new_edls and new_assets to load
1321 int result = 0, ftype = -1;
1322 for(int i = 0; i < filenames->size(); i++)
1325 File *new_file = new File;
1326 Asset *new_asset = new Asset(filenames->get(i));
1327 EDL *new_edl = new EDL;
1328 char string[BCTEXTLEN];
1330 new_edl->create_objects();
1331 new_edl->copy_session(edl);
1332 new_file->set_program(edl->session->program_no);
1334 sprintf(string, _("Loading %s"), new_asset->path);
1335 gui->show_message(string);
1336 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1338 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1339 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1344 // Convert media file to EDL
1346 // Warn about odd image dimensions
1347 if(new_asset->video_data &&
1348 ((new_asset->width % 2) ||
1349 (new_asset->height % 2)))
1351 char string[BCTEXTLEN];
1352 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1356 MainError::show_error(string);
1359 if(new_asset->program >= 0 &&
1360 edl->session->program_no != new_asset->program)
1362 char string[BCTEXTLEN];
1363 sprintf(string, _("%s's index was built for program number %d\n"
1364 "Playback preference is %d.\n Using program %d."),
1365 new_asset->path, new_asset->program,
1366 edl->session->program_no, new_asset->program);
1367 MainError::show_error(string);
1371 if(load_mode != LOADMODE_RESOURCESONLY)
1374 RecordLabels *labels = edl->session->label_cells ?
1375 new RecordLabels(new_file) : 0;
1377 asset_to_edl(new_edl, new_asset, labels);
1379 new_edls.append(new_edl);
1381 new_asset->Garbage::remove_user();
1387 new_assets.append(new_asset);
1391 // Set filename to nothing for assets since save EDL would overwrite them.
1392 if(load_mode == LOADMODE_REPLACE ||
1393 load_mode == LOADMODE_REPLACE_CONCATENATE)
1396 // Reset timeline position
1397 for(int i = 0; i < TOTAL_PANES; i++)
1399 new_edl->local_session->view_start[i] = 0;
1400 new_edl->local_session->track_start[i] = 0;
1408 case FILE_NOT_FOUND:
1409 sprintf(string, _("Failed to open %s"), new_asset->path);
1410 gui->show_message(string, theme->message_error);
1414 case FILE_UNRECOGNIZED_CODEC:
1417 IndexFile indexfile(this, new_asset);
1418 result = indexfile.open_index();
1421 indexfile.close_index();
1424 // Test existing EDLs
1425 for(int j = 0; result && j <= new_edls.total; j++) {
1426 Asset *old_asset = j < new_edls.total ?
1427 new_edls[j]->assets->get_asset(new_asset->path) :
1428 edl->assets->get_asset(new_asset->path);
1430 *new_asset = *old_asset;
1438 char string[BCTEXTLEN];
1440 fs.extract_name(string, new_asset->path);
1442 strcat(string, _("'s format couldn't be determined."));
1443 new_asset->audio_data = 1;
1444 new_asset->format = FILE_PCM;
1445 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1446 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1447 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1448 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1449 new_asset->signed_ = defaults->get("SIGNED_", 1);
1450 new_asset->header = defaults->get("HEADER", 0);
1452 FileFormat fwindow(this);
1453 fwindow.create_objects(new_asset, string);
1454 result = fwindow.run_window();
1457 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1458 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1459 defaults->update("AUDIO_BITS", new_asset->bits);
1460 defaults->update("BYTE_ORDER", new_asset->byte_order);
1461 defaults->update("SIGNED_", new_asset->signed_);
1462 defaults->update("HEADER", new_asset->header);
1469 // Recalculate length
1471 new_file = new File;
1472 result = new_file->open_file(preferences, new_asset, 1, 0);
1474 if(load_mode != LOADMODE_RESOURCESONLY)
1476 RecordLabels *labels = edl->session->label_cells ?
1477 new RecordLabels(new_file) : 0;
1478 asset_to_edl(new_edl, new_asset, labels);
1479 new_edls.append(new_edl);
1480 new_asset->Garbage::remove_user();
1486 new_assets.append(new_asset);
1500 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1501 xml_file.read_from_file(filenames->get(i));
1502 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1504 if(load_mode == LOADMODE_NESTED)
1506 // Load temporary EDL for nesting.
1507 EDL *nested_edl = new EDL;
1508 nested_edl->create_objects();
1509 nested_edl->set_path(filenames->get(i));
1510 nested_edl->load_xml(&xml_file, LOAD_ALL);
1511 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1512 edl_to_nested(new_edl, nested_edl);
1513 nested_edl->Garbage::remove_user();
1517 // Load EDL for pasting
1518 new_edl->load_xml(&xml_file, LOAD_ALL);
1519 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1520 test_plugins(new_edl, filenames->get(i));
1521 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1523 if(load_mode == LOADMODE_REPLACE ||
1524 load_mode == LOADMODE_REPLACE_CONCATENATE)
1526 strcpy(session->filename, filenames->get(i));
1527 strcpy(new_edl->local_session->clip_title,
1530 set_filename(new_edl->local_session->clip_title);
1534 new_edls.append(new_edl);
1540 // edls are in new_edls
1541 if( result && new_edl ) new_edl->Garbage::remove_user();
1542 // assets are copied
1543 if( new_asset ) new_asset->Garbage::remove_user();
1545 // Store for testing index
1546 new_files.append(new_file);
1549 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1552 if(!result) gui->statusbar->default_message();
1560 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1563 // Don't back up here.
1566 // For pasting, clear the active region
1567 if(load_mode == LOADMODE_PASTE ||
1568 load_mode == LOADMODE_NESTED)
1570 double start = edl->local_session->get_selectionstart();
1571 double end = edl->local_session->get_selectionend();
1572 if(!EQUIV(start, end))
1575 edl->session->labels_follow_edits,
1576 edl->session->plugins_follow_edits,
1577 edl->session->autos_follow_edits);
1580 paste_edls(&new_edls,
1584 edl->session->labels_follow_edits,
1585 edl->session->plugins_follow_edits,
1586 edl->session->autos_follow_edits,
1593 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1595 // Add new assets to EDL and schedule assets for index building.
1596 int got_indexes = 0;
1597 for(int i = 0; i < new_edls.size(); i++)
1599 EDL *new_edl = new_edls[i];
1600 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1602 mainindexes->add_next_asset(0,
1603 new_edl->nested_edls->get(j));
1605 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1610 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1611 if(new_assets.size())
1613 for(int i = 0; i < new_assets.size(); i++)
1615 Asset *new_asset = new_assets[i];
1619 for(int j = 0; j < new_files.size(); j++)
1621 new_file = new_files[j];
1622 if(!strcmp(new_file->asset->path,
1630 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1632 edl->assets->update(new_asset);
1638 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1640 // Start examining next batch of index files
1641 if(got_indexes) mainindexes->start_build();
1642 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1645 Track *track = edl->tracks->first;
1648 for(int j = 0; j < track->plugin_set.size(); j++)
1650 PluginSet *plugins = track->plugin_set[j];
1651 Plugin *plugin = plugins->get_first_plugin();
1655 if(load_mode == LOADMODE_REPLACE ||
1656 load_mode == LOADMODE_REPLACE_CONCATENATE)
1658 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1661 show_plugin(plugin);
1669 plugin = (Plugin*)plugin->next;
1673 track = track->next;
1676 // if just opening one new resource in replace mode
1677 if( ftype != FILE_IS_XML &&
1678 ( load_mode == LOADMODE_REPLACE ||
1679 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1681 edl->local_session->preview_start = 0;
1682 edl->local_session->preview_end = edl->tracks->total_playable_length();
1683 edl->local_session->loop_playback = 0;
1684 edl->local_session->set_selectionstart(0);
1685 edl->local_session->set_selectionend(0);
1690 // need to update undo before project, since mwindow is unlocked & a new load
1691 // can begin here. Should really prevent loading until we're done.
1692 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1693 undo->update_undo_after(_("load"), LOAD_ALL);
1695 for(int i = 0; i < new_edls.size(); i++)
1697 new_edls[i]->remove_user();
1699 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1701 new_edls.remove_all();
1703 for(int i = 0; i < new_assets.size(); i++)
1705 new_assets[i]->Garbage::remove_user();
1708 new_assets.remove_all();
1709 new_files.remove_all_objects();
1712 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1713 if(load_mode == LOADMODE_REPLACE ||
1714 load_mode == LOADMODE_REPLACE_CONCATENATE)
1716 session->changes_made = 0;
1720 session->changes_made = 1;
1723 gui->stop_hourglass();
1726 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1727 update_project(load_mode);
1729 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1737 void MWindow::test_plugins(EDL *new_edl, char *path)
1739 char string[BCTEXTLEN];
1741 // Do a check weather plugins exist
1742 for(Track *track = new_edl->tracks->first; track; track = track->next)
1744 for(int k = 0; k < track->plugin_set.total; k++)
1746 PluginSet *plugin_set = track->plugin_set[k];
1747 for(Plugin *plugin = (Plugin*)plugin_set->first;
1749 plugin = (Plugin*)plugin->next)
1751 if(plugin->plugin_type == PLUGIN_STANDALONE)
1753 // ok we need to find it in plugindb
1754 int plugin_found = 0;
1756 for(int j = 0; j < plugindb->size(); j++)
1758 PluginServer *server = plugindb->get(j);
1760 !strcasecmp(server->title, plugin->title) &&
1761 ((track->data_type == TRACK_AUDIO && server->audio) ||
1762 (track->data_type == TRACK_VIDEO && server->video)) &&
1763 (!server->transition))
1770 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1771 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1772 "effect", plugin->title,
1774 MainError::show_error(string);
1780 for(Edit *edit = (Edit*)track->edits->first;
1782 edit = (Edit*)edit->next)
1784 if (edit->transition)
1786 // ok we need to find transition in plugindb
1788 int transition_found = 0;
1789 for(int j = 0; j < plugindb->size(); j++)
1791 PluginServer *server = plugindb->get(j);
1793 !strcasecmp(server->title, edit->transition->title) &&
1794 ((track->data_type == TRACK_AUDIO && server->audio) ||
1795 (track->data_type == TRACK_VIDEO && server->video)) &&
1796 (server->transition))
1797 transition_found = 1;
1800 if (!transition_found)
1803 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1804 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1805 "transition", edit->transition->title,
1807 MainError::show_error(string);
1815 void MWindow::init_shm()
1817 // Fix shared memory
1818 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1820 fprintf(fd, "0x7fffffff");
1825 fd = fopen("/proc/sys/kernel/shmmax", "r");
1827 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1832 fscanf(fd, "%jd", &result);
1835 if(result < 0x7fffffff) {
1836 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1837 "you probably need to be root, or:\n"
1838 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1839 "before trying to start cinelerra.\n"
1840 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1844 void MWindow::create_objects(int want_gui,
1849 const int debug = 0;
1850 if(debug) PRINT_TRACE
1852 // For some reason, init_signals must come after show_splash or the signals won't
1855 if(debug) PRINT_TRACE
1858 if(debug) PRINT_TRACE
1861 if(debug) PRINT_TRACE
1862 default_standard = default_std();
1863 init_defaults(defaults, config_path);
1866 splash_window->operation->update(_("Initializing Plugins"));
1867 init_plugins(this, preferences);
1868 if(debug) PRINT_TRACE
1869 init_ladspa_plugins(this, preferences);
1870 if(debug) PRINT_TRACE
1872 splash_window->operation->update(_("Initializing GUI"));
1873 if(debug) PRINT_TRACE
1876 if(debug) PRINT_TRACE
1880 splash_window->operation->update(_("Initializing Fonts"));
1881 char string[BCTEXTLEN];
1882 strcpy(string, preferences->plugin_dir);
1883 strcat(string, "/" FONT_SEARCHPATH);
1884 BC_Resources::init_fontconfig(string);
1885 if(debug) PRINT_TRACE
1887 // Initialize before too much else is running
1888 // Preferences & theme are required for building MPEG table of contents
1890 // Default project created here
1892 if(debug) PRINT_TRACE
1895 if(debug) PRINT_TRACE
1900 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1902 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1903 if(session->show_vwindow)
1904 get_viewer(1, DEFAULT_VWINDOW);
1905 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1908 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());
1916 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1919 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1923 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1925 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1927 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1931 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1932 mainprogress = new MainProgress(this, gui);
1933 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1934 undo = new MainUndo(this);
1936 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1938 plugin_guis = new ArrayList<PluginServer*>;
1939 dead_plugins = new ArrayList<PluginServer*>;
1940 keyframe_threads = new ArrayList<KeyFrameThread*>;
1942 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1945 session->show_vwindow);
1947 // Show all vwindows
1948 // if(session->show_vwindow) {
1949 // for(int j = 0; j < vwindows.size(); j++) {
1950 // VWindow *vwindow = vwindows[j];
1951 // if( !vwindow->is_running() ) continue;
1952 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1955 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1956 // vwindow->gui->lock_window("MWindow::create_objects 1");
1957 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1958 // vwindow->gui->show_window();
1959 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1960 // vwindow->gui->unlock_window();
1965 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1967 if(session->show_cwindow)
1969 cwindow->gui->lock_window("MWindow::create_objects 1");
1970 cwindow->gui->show_window();
1971 cwindow->gui->unlock_window();
1974 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1975 if(session->show_awindow)
1977 awindow->gui->lock_window("MWindow::create_objects 1");
1978 awindow->gui->show_window();
1979 awindow->gui->unlock_window();
1982 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1983 if(session->show_lwindow)
1985 lwindow->gui->lock_window("MWindow::create_objects 1");
1986 lwindow->gui->show_window();
1987 lwindow->gui->unlock_window();
1990 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1992 (int)timer.get_difference(),
1994 if(session->show_gwindow)
1996 gwindow->gui->lock_window("MWindow::create_objects 1");
1997 gwindow->gui->show_window();
1998 gwindow->gui->unlock_window();
2001 if(debug) PRINT_TRACE
2003 gui->lock_window("MWindow::create_objects 1");
2004 gui->mainmenu->load_defaults(defaults);
2005 gui->mainmenu->update_toggles(0);
2006 gui->update_patchbay();
2007 gui->draw_canvas(0, 0);
2008 gui->draw_cursor(1);
2010 gui->raise_window();
2011 gui->unlock_window();
2013 if(debug) PRINT_TRACE
2015 if(preferences->use_tipwindow)
2017 if(debug) PRINT_TRACE
2019 gui->add_keyboard_listener(
2020 (int (BC_WindowBase::*)(BC_WindowBase *))
2021 &MWindowGUI::keyboard_listener);
2025 if(debug) PRINT_TRACE
2027 BC_WindowBase::get_resources()->vframe_shm = 1;
2031 void MWindow::show_splash()
2033 #include "data/heroine_logo9_png.h"
2034 VFrame *frame = new VFramePng(heroine_logo9_png);
2035 BC_DisplayInfo dpyi;
2036 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2037 int rr = (rw < rh ? rw : rh) / 4;
2038 splash_window = new SplashGUI(frame, rr, rr);
2039 splash_window->create_objects();
2042 void MWindow::hide_splash()
2045 delete splash_window;
2050 void MWindow::start()
2054 // vwindows[DEFAULT_VWINDOW]->start();
2065 playback_3d->start();
2074 void MWindow::show_vwindow()
2076 int total_running = 0;
2077 session->show_vwindow = 1;
2079 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2080 // Raise all windows which are visible
2081 for(int j = 0; j < vwindows.size(); j++) {
2082 VWindow *vwindow = vwindows[j];
2083 if( !vwindow->is_running() ) continue;
2084 vwindow->gui->lock_window("MWindow::show_vwindow");
2085 vwindow->gui->show_window(0);
2086 vwindow->gui->raise_window();
2087 vwindow->gui->flush();
2088 vwindow->gui->unlock_window();
2092 // If no windows visible
2095 get_viewer(1, DEFAULT_VWINDOW);
2098 gui->mainmenu->show_vwindow->set_checked(1);
2101 void MWindow::show_awindow()
2103 session->show_awindow = 1;
2104 awindow->gui->lock_window("MWindow::show_awindow");
2105 awindow->gui->show_window();
2106 awindow->gui->raise_window();
2107 awindow->gui->flush();
2108 awindow->gui->unlock_window();
2109 gui->mainmenu->show_awindow->set_checked(1);
2112 char *MWindow::get_cwindow_display()
2114 char *x11_host = screens < 2 || session->window_config == 0 ?
2115 session->a_x11_host : session->b_x11_host;
2116 return *x11_host ? x11_host : 0;
2119 void MWindow::show_cwindow()
2121 session->show_cwindow = 1;
2122 cwindow->show_window();
2123 gui->mainmenu->show_cwindow->set_checked(1);
2126 void MWindow::show_gwindow()
2128 session->show_gwindow = 1;
2130 gwindow->gui->lock_window("MWindow::show_gwindow");
2131 gwindow->gui->show_window();
2132 gwindow->gui->raise_window();
2133 gwindow->gui->flush();
2134 gwindow->gui->unlock_window();
2136 gui->mainmenu->show_gwindow->set_checked(1);
2139 void MWindow::show_lwindow()
2141 session->show_lwindow = 1;
2142 lwindow->gui->lock_window("MWindow::show_lwindow");
2143 lwindow->gui->show_window();
2144 lwindow->gui->raise_window();
2145 lwindow->gui->flush();
2146 lwindow->gui->unlock_window();
2147 gui->mainmenu->show_lwindow->set_checked(1);
2150 int MWindow::tile_windows(int window_config)
2152 int need_reload = 0;
2153 int play_config = window_config==0 ? 0 : 1;
2154 edl->session->playback_config->load_defaults(defaults, play_config);
2155 session->default_window_positions(window_config);
2156 if( screens == 1 ) {
2157 gui->default_positions();
2158 sync_parameters(CHANGE_ALL);
2165 void MWindow::toggle_loop_playback()
2167 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2168 set_loop_boundaries();
2171 gui->draw_overlays(1);
2172 sync_parameters(CHANGE_PARAMS);
2175 //void MWindow::set_titles(int value)
2177 // edl->session->show_titles = value;
2178 // trackmovement(edl->local_session->track_start);
2181 void MWindow::set_screens(int value)
2186 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2188 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2189 edl->session->auto_keyframes = value;
2190 gui->mbuttons->edit_panel->keyframe->update(value);
2192 if(lock_mwindow) gui->unlock_window();
2194 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2195 cwindow->gui->edit_panel->keyframe->update(value);
2196 cwindow->gui->flush();
2197 if(lock_cwindow) cwindow->gui->unlock_window();
2200 void MWindow::set_keyframe_type(int mode)
2202 gui->lock_window("MWindow::set_keyframe_type");
2203 edl->local_session->floatauto_type = mode;
2204 gui->mainmenu->update_toggles(0);
2205 gui->unlock_window();
2208 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2210 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2211 edl->session->editing_mode = new_editing_mode;
2212 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2213 gui->mbuttons->edit_panel->update();
2214 gui->set_editing_mode(1);
2215 if(lock_mwindow) gui->unlock_window();
2218 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2219 cwindow->gui->edit_panel->update();
2220 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2221 if(lock_cwindow) cwindow->gui->unlock_window();
2225 void MWindow::toggle_editing_mode()
2227 int mode = edl->session->editing_mode;
2228 if( mode == EDITING_ARROW )
2229 set_editing_mode(EDITING_IBEAM, 0, 1);
2231 set_editing_mode(EDITING_ARROW, 0, 1);
2235 void MWindow::set_labels_follow_edits(int value)
2237 gui->lock_window("MWindow::set_labels_follow_edits");
2238 edl->session->labels_follow_edits = value;
2239 gui->mbuttons->edit_panel->locklabels->update(value);
2240 gui->mainmenu->labels_follow_edits->set_checked(value);
2242 gui->unlock_window();
2245 void MWindow::sync_parameters(int change_type)
2247 if( in_destructor ) return;
2249 // Sync engines which are playing back
2250 if(cwindow->playback_engine->is_playing_back)
2252 if(change_type == CHANGE_PARAMS)
2254 // TODO: block keyframes until synchronization is done
2255 cwindow->playback_engine->sync_parameters(edl);
2260 int command = cwindow->playback_engine->command->command;
2261 cwindow->playback_engine->que->send_command(STOP,
2265 // Waiting for tracking to finish would make the restart position more
2266 // accurate but it can't lock the window to stop tracking for some reason.
2267 // Not waiting for tracking gives a faster response but restart position is
2268 // only as accurate as the last tracking update.
2269 cwindow->playback_engine->interrupt_playback(0);
2270 cwindow->playback_engine->que->send_command(command,
2279 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2286 void MWindow::age_caches()
2288 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2290 // preferences->cache_size,
2291 // audio_cache->get_memory_usage(1),
2292 // video_cache->get_memory_usage(1),
2293 // frame_cache->get_memory_usage(),
2294 // wave_cache->get_memory_usage(),
2296 frame_cache->age_cache(512);
2297 wave_cache->age_cache(8192);
2299 int64_t memory_usage;
2300 int64_t prev_memory_usage = 0;
2302 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2303 while( !result && prev_memory_usage !=
2304 (memory_usage=video_cache->get_memory_usage(1)) &&
2305 memory_usage > video_size ) {
2306 video_cache->delete_oldest();
2307 prev_memory_usage = memory_usage;
2310 prev_memory_usage = 0;
2312 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2313 while( !result && prev_memory_usage !=
2314 (memory_usage=audio_cache->get_memory_usage(1)) &&
2315 memory_usage > audio_size ) {
2316 audio_cache->delete_oldest();
2317 prev_memory_usage = memory_usage;
2321 void MWindow::reset_android_remote()
2323 gui->use_android_remote(preferences->android_remote);
2327 void MWindow::show_keyframe_gui(Plugin *plugin)
2329 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2330 // Find existing thread
2331 for(int i = 0; i < keyframe_threads->size(); i++)
2333 if(keyframe_threads->get(i)->plugin == plugin)
2335 keyframe_threads->get(i)->start_window(plugin, 0);
2336 keyframe_gui_lock->unlock();
2341 // Find unused thread
2342 for(int i = 0; i < keyframe_threads->size(); i++)
2344 if(!keyframe_threads->get(i)->plugin)
2346 keyframe_threads->get(i)->start_window(plugin, 0);
2347 keyframe_gui_lock->unlock();
2352 // Create new thread
2353 KeyFrameThread *thread = new KeyFrameThread(this);
2354 keyframe_threads->append(thread);
2355 thread->start_window(plugin, 0);
2357 keyframe_gui_lock->unlock();
2364 void MWindow::show_plugin(Plugin *plugin)
2369 // Remove previously deleted plugin GUIs
2370 dead_plugin_lock->lock("MWindow::show_plugin");
2371 dead_plugins->remove_all_objects();
2372 dead_plugin_lock->unlock();
2374 //printf("MWindow::show_plugin %d\n", __LINE__);
2378 plugin_gui_lock->lock("MWindow::show_plugin");
2379 for(int i = 0; i < plugin_guis->total; i++)
2381 // Pointer comparison
2382 if(plugin_guis->get(i)->plugin == plugin)
2384 plugin_guis->get(i)->raise_window();
2391 //printf("MWindow::show_plugin 1\n");
2396 printf("MWindow::show_plugin track not defined.\n");
2398 PluginServer *server = scan_plugindb(plugin->title,
2399 plugin->track->data_type);
2401 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2402 if(server && server->uses_gui)
2404 PluginServer *gui = new PluginServer(*server);
2405 plugin_guis->append(gui);
2406 // Needs mwindow to do GUI
2407 gui->set_mwindow(this);
2408 gui->open_plugin(0, preferences, edl, plugin);
2413 plugin_gui_lock->unlock();
2414 //printf("MWindow::show_plugin %d\n", __LINE__);
2417 //printf("MWindow::show_plugin 2\n");
2420 void MWindow::hide_plugin(Plugin *plugin, int lock)
2423 // Update the toggle
2424 gui->lock_window("MWindow::hide_plugin");
2425 gui->update(0, 1, 0, 0, 0, 0, 0);
2426 gui->unlock_window();
2428 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2429 for(int i = 0; i < plugin_guis->total; i++)
2431 if(plugin_guis->get(i)->plugin == plugin)
2433 PluginServer *ptr = plugin_guis->get(i);
2434 plugin_guis->remove(ptr);
2435 if(lock) plugin_gui_lock->unlock();
2436 // Last command executed in client side close
2437 // Schedule for deletion
2444 if(lock) plugin_gui_lock->unlock();
2447 void MWindow::delete_plugin(PluginServer *plugin)
2449 dead_plugin_lock->lock("MWindow::delete_plugin");
2450 dead_plugins->append(plugin);
2451 dead_plugin_lock->unlock();
2454 void MWindow::hide_plugins()
2456 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2457 while(plugin_guis->size())
2459 PluginServer *ptr = plugin_guis->get(0);
2460 plugin_guis->remove(ptr);
2461 plugin_gui_lock->unlock();
2462 // Last command executed in client side close
2463 // Schedule for deletion
2466 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2468 plugin_gui_lock->unlock();
2470 hide_keyframe_guis();
2473 void MWindow::hide_keyframe_guis()
2475 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2476 for(int i = 0; i < keyframe_threads->size(); i++)
2478 keyframe_threads->get(i)->close_window();
2480 keyframe_gui_lock->unlock();
2483 void MWindow::hide_keyframe_gui(Plugin *plugin)
2485 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2486 for(int i = 0; i < keyframe_threads->size(); i++)
2488 if(keyframe_threads->get(i)->plugin == plugin)
2490 keyframe_threads->get(i)->close_window();
2494 keyframe_gui_lock->unlock();
2497 void MWindow::update_keyframe_guis()
2499 // Send new configuration to keyframe GUI's
2500 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2501 for(int i = 0; i < keyframe_threads->size(); i++)
2503 KeyFrameThread *ptr = keyframe_threads->get(i);
2504 if(edl->tracks->plugin_exists(ptr->plugin))
2508 ptr->close_window();
2511 keyframe_gui_lock->unlock();
2514 void MWindow::update_plugin_guis(int do_keyframe_guis)
2516 // Send new configuration to plugin GUI's
2517 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2519 for(int i = 0; i < plugin_guis->size(); i++)
2521 PluginServer *ptr = plugin_guis->get(i);
2522 if(edl->tracks->plugin_exists(ptr->plugin))
2526 // Schedule for deletion if no plugin
2527 plugin_guis->remove_number(i);
2536 // Change plugin variable if not visible
2537 Track *track = edl->tracks->first;
2540 for(int i = 0; i < track->plugin_set.size(); i++)
2542 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2546 for(int i = 0; i < plugin_guis->size(); i++)
2548 PluginServer *server = plugin_guis->get(i);
2549 if(server->plugin == plugin)
2556 if(!got_it) plugin->show = 0;
2558 plugin = (Plugin*)plugin->next;
2562 track = track->next;
2565 plugin_gui_lock->unlock();
2568 if(do_keyframe_guis) update_keyframe_guis();
2571 int MWindow::plugin_gui_open(Plugin *plugin)
2574 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2575 for(int i = 0; i < plugin_guis->total; i++)
2577 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2583 plugin_gui_lock->unlock();
2587 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2589 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2590 for(int i = 0; i < plugin_guis->total; i++)
2592 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2594 plugin_guis->get(i)->render_gui(data);
2598 plugin_gui_lock->unlock();
2601 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2603 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2604 for(int i = 0; i < plugin_guis->total; i++)
2606 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2608 plugin_guis->get(i)->render_gui(data, size);
2612 plugin_gui_lock->unlock();
2616 void MWindow::update_plugin_states()
2618 plugin_gui_lock->lock("MWindow::update_plugin_states");
2619 for(int i = 0; i < plugin_guis->total; i++)
2623 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2624 PluginServer *src_plugingui = plugin_guis->get(i);
2626 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2627 for(Track *track = edl->tracks->first;
2629 track = track->next)
2632 j < track->plugin_set.total && !result;
2635 PluginSet *plugin_set = track->plugin_set[j];
2636 for(Plugin *plugin = (Plugin*)plugin_set->first;
2638 plugin = (Plugin*)plugin->next)
2640 if(plugin == src_plugin &&
2641 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2647 // Doesn't exist anymore
2650 hide_plugin(src_plugin, 0);
2654 plugin_gui_lock->unlock();
2658 void MWindow::update_plugin_titles()
2660 for(int i = 0; i < plugin_guis->total; i++)
2662 plugin_guis->get(i)->update_title();
2666 int MWindow::asset_to_edl(EDL *new_edl,
2668 RecordLabels *labels)
2670 const int debug = 0;
2671 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2674 // Keep frame rate, sample rate, and output size unchanged.
2675 // These parameters would revert the project if VWindow displayed an asset
2676 // of different size than the project.
2677 if(new_asset->video_data)
2679 new_edl->session->video_tracks = new_asset->layers;
2682 new_edl->session->video_tracks = 0;
2684 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2690 if(new_asset->audio_data)
2692 new_edl->session->audio_tracks = new_asset->channels;
2695 new_edl->session->audio_tracks = 0;
2696 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2698 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2699 new_edl->create_default_tracks();
2700 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2701 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2705 //printf("MWindow::asset_to_edl 3\n");
2706 new_edl->insert_asset(new_asset,
2711 //printf("MWindow::asset_to_edl 3\n");
2712 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2714 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2715 if(edl->session->cursor_on_frames)
2717 double length = new_edl->tracks->total_length();
2718 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2719 new_edl->tracks->clear(length, edl_length, 1, 1);
2725 char string[BCTEXTLEN];
2727 fs.extract_name(string, new_asset->path);
2728 //printf("MWindow::asset_to_edl 3\n");
2730 strcpy(new_edl->local_session->clip_title, string);
2731 //printf("MWindow::asset_to_edl 4 %s\n", string);
2732 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2737 int MWindow::edl_to_nested(EDL *new_edl,
2741 // Keep frame rate, sample rate, and output size unchanged.
2742 // These parameters would revert the project if VWindow displayed an asset
2743 // of different size than the project.
2747 // Nest all video & audio outputs
2748 new_edl->session->video_tracks = 1;
2749 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2750 new_edl->create_default_tracks();
2754 new_edl->insert_asset(0,
2760 char string[BCTEXTLEN];
2762 fs.extract_name(string, nested_edl->path);
2763 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2765 strcpy(new_edl->local_session->clip_title, string);
2770 // Reset everything after a load.
2771 void MWindow::update_project(int load_mode)
2773 const int debug = 0;
2775 if(debug) PRINT_TRACE
2777 edl->tracks->update_y_pixels(theme);
2779 if(debug) PRINT_TRACE
2781 if(load_mode == LOADMODE_REPLACE ||
2782 load_mode == LOADMODE_REPLACE_CONCATENATE)
2787 gui->update(1, 1, 1, 1, 1, 1, 1);
2788 if(debug) PRINT_TRACE
2789 gui->unlock_window();
2791 cwindow->gui->lock_window("MWindow::update_project 1");
2792 cwindow->update(0, 0, 1, 1, 1);
2793 cwindow->gui->unlock_window();
2795 if(debug) PRINT_TRACE
2797 // Close all the vwindows
2798 if(load_mode == LOADMODE_REPLACE ||
2799 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2800 if(debug) PRINT_TRACE
2801 int first_vwindow = 0;
2802 if(session->show_vwindow) first_vwindow = 1;
2803 // Change visible windows to no source
2804 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2805 VWindow *vwindow = vwindows[i];
2806 if( !vwindow->is_running() ) continue;
2807 vwindow->change_source(-1);
2810 // Close remaining windows
2811 for(int i = first_vwindow; i < vwindows.size(); i++) {
2812 VWindow *vwindow = vwindows[i];
2813 if( !vwindow->is_running() ) continue;
2814 vwindow->close_window();
2816 if(debug) PRINT_TRACE
2818 else if(vwindows.size()) {
2819 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2820 if( vwindow->is_running() ) {
2821 vwindow->gui->lock_window("MWindow::update_project");
2823 vwindow->gui->unlock_window();
2827 if(debug) PRINT_TRACE
2828 cwindow->gui->lock_window("MWindow::update_project 2");
2829 cwindow->gui->timebar->update(0);
2830 cwindow->gui->unlock_window();
2832 if(debug) PRINT_TRACE
2833 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2838 awindow->gui->async_update_assets();
2839 if(debug) PRINT_TRACE
2841 gui->lock_window("MWindow::update_project");
2843 if(debug) PRINT_TRACE
2846 void MWindow::remove_indexfile(Indexable *indexable)
2848 if( !indexable->is_asset ) return;
2849 Asset *asset = (Asset *)indexable;
2851 IndexFile::delete_index(preferences, asset, ".toc");
2852 IndexFile::delete_index(preferences, asset, ".idx");
2853 IndexFile::delete_index(preferences, asset, ".mkr");
2856 void MWindow::rebuild_indices()
2858 for(int i = 0; i < session->drag_assets->total; i++)
2860 Indexable *indexable = session->drag_assets->get(i);
2861 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2862 remove_indexfile(indexable);
2863 // Schedule index build
2864 IndexState *index_state = indexable->index_state;
2865 index_state->index_status = INDEX_NOTTESTED;
2866 if( indexable->is_asset ) {
2867 Asset *asset = (Asset *)indexable;
2868 if( asset->format != FILE_PCM )
2869 asset->reset_audio();
2870 asset->reset_video();
2872 mainindexes->add_next_asset(0, indexable);
2874 mainindexes->start_build();
2878 void MWindow::save_backup()
2882 edl->set_path(session->filename);
2883 char backup_path[BCTEXTLEN];
2884 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2885 File::get_config_path(), BACKUP_FILE);
2886 edl->save_xml(&file, backup_path, 0, 0);
2887 file.terminate_string();
2889 fs.complete_path(backup_path);
2891 if(file.write_to_file(backup_path))
2894 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
2895 gui->show_message(string2);
2899 void MWindow::load_backup()
2901 ArrayList<char*> path_list;
2902 path_list.set_array_delete();
2904 char backup_path[BCTEXTLEN];
2905 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2906 File::get_config_path(), BACKUP_FILE);
2908 fs.complete_path(backup_path);
2910 path_list.append(out_path = new char[strlen(backup_path) + 1]);
2911 strcpy(out_path, backup_path);
2913 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2914 edl->local_session->clip_title[0] = 0;
2915 // This is unique to backups since the path of the backup is different than the
2916 // path of the project.
2917 set_filename(edl->path);
2918 path_list.remove_all_objects();
2922 static inline int gcd(int m, int n)
2925 if( m < n ) { r = m; m = n; n = r; }
2926 while( (r = m % n) != 0 ) { m = n; n = r; }
2930 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2933 if(!width || !height) return 1;
2934 if( width == 720 && (height == 480 || height == 576) ) {
2935 w = 4; h = 3; return 0; // for NTSC and PAL
2937 double ar = (double)width / height;
2938 // square-ish pixels
2939 if( EQUIV(ar, 1.0000) ) return 0;
2940 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2941 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2942 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2943 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2944 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2945 int ww = width, hh = height;
2946 // numerator, denominator must be under mx
2947 int mx = 255, n = gcd(ww, hh);
2948 if( n > 1 ) { ww /= n; hh /= n; }
2949 // search near height in case extra/missing lines
2950 if( ww >= mx || hh >= mx ) {
2951 double err = height; // +/- 2 percent height
2952 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2953 int iw = width, ih = height+i;
2954 if( (n=gcd(iw, ih)) > 1 ) {
2955 int u = iw/n; if( u >= mx ) continue;
2956 int v = ih/n; if( v >= mx ) continue;
2957 double r = (double) u/v, er = fabs(ar-r);
2958 if( er >= err ) continue;
2959 err = er; ww = u; hh = v;
2968 void MWindow::reset_caches()
2970 frame_cache->remove_all();
2971 wave_cache->remove_all();
2972 audio_cache->remove_all();
2973 video_cache->remove_all();
2974 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2975 cwindow->playback_engine->audio_cache->remove_all();
2976 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2977 cwindow->playback_engine->video_cache->remove_all();
2979 for(int i = 0; i < vwindows.size(); i++) {
2980 VWindow *vwindow = vwindows[i];
2981 if( !vwindow->is_running() ) continue;
2982 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2983 vwindow->playback_engine->audio_cache->remove_all();
2984 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2985 vwindow->playback_engine->video_cache->remove_all();
2989 void MWindow::remove_asset_from_caches(Asset *asset)
2991 gui->resource_thread->get_video_source(0);
2992 gui->resource_thread->get_audio_source(0);
2993 frame_cache->remove_asset(asset);
2994 wave_cache->remove_asset(asset);
2995 audio_cache->delete_entry(asset);
2996 video_cache->delete_entry(asset);
2997 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2998 cwindow->playback_engine->audio_cache->delete_entry(asset);
2999 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3000 cwindow->playback_engine->video_cache->delete_entry(asset);
3001 for(int i = 0; i < vwindows.size(); i++) {
3002 VWindow *vwindow = vwindows[i];
3003 if( !vwindow->is_running() ) continue;
3004 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3005 vwindow->playback_engine->audio_cache->delete_entry(asset);
3006 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3007 vwindow->playback_engine->video_cache->delete_entry(asset);
3012 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3013 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3015 for(int i = 0; i < session->drag_assets->total; i++) {
3016 Indexable *indexable = session->drag_assets->get(i);
3017 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3020 // Remove from VWindow.
3021 for(int i = 0; i < session->drag_clips->total; i++) {
3022 for(int j = 0; j < vwindows.size(); j++) {
3023 VWindow *vwindow = vwindows[j];
3024 if( !vwindow->is_running() ) continue;
3025 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3026 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3027 vwindow->delete_source(1, 1);
3028 vwindow->gui->unlock_window();
3033 for(int i = 0; i < session->drag_assets->size(); i++) {
3034 for(int j = 0; j < vwindows.size(); j++) {
3035 VWindow *vwindow = vwindows[j];
3036 if( !vwindow->is_running() ) continue;
3037 if(session->drag_assets->get(i) == vwindow->get_source()) {
3038 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3039 vwindow->delete_source(1, 1);
3040 vwindow->gui->unlock_window();
3045 for(int i = 0; i < session->drag_assets->size(); i++) {
3046 Indexable *indexable = session->drag_assets->get(i);
3047 remove_indexfile(indexable);
3050 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3051 if(push_undo) undo->update_undo_before();
3052 if(drag_assets) edl->remove_from_project(drag_assets);
3053 if(drag_clips) edl->remove_from_project(session->drag_clips);
3054 if(redraw) save_backup();
3055 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3060 gui->lock_window("MWindow::remove_assets_from_project 3");
3068 gui->unlock_window();
3070 // Removes from playback here
3071 sync_parameters(CHANGE_ALL);
3074 awindow->gui->async_update_assets();
3077 void MWindow::remove_assets_from_disk()
3080 for(int i = 0; i < session->drag_assets->total; i++)
3082 remove(session->drag_assets->get(i)->path);
3085 remove_assets_from_project(1,
3087 session->drag_assets,
3088 session->drag_clips);
3091 void MWindow::dump_plugins(FILE *fp)
3093 if( !plugindb ) return;
3094 for(int i = 0; i < plugindb->total; i++)
3096 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3097 " synth=%d transition=%d theme=%d %s\n",
3098 plugindb->get(i)->plugin_type,
3099 plugindb->get(i)->audio,
3100 plugindb->get(i)->video,
3101 plugindb->get(i)->realtime,
3102 plugindb->get(i)->multichannel,
3103 plugindb->get(i)->get_synthesis(),
3104 plugindb->get(i)->transition,
3105 plugindb->get(i)->theme,
3106 plugindb->get(i)->title);
3110 void MWindow::dump_edl(FILE *fp)
3116 void MWindow::dump_undo(FILE *fp)
3122 void MWindow::dump_exe(FILE *fp)
3124 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3125 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3126 int ret = readlink(proc_path, exe_path, sizeof(exe_path));
3127 if( ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3130 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3131 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
3132 int fd = open(exe_path,O_RDONLY+O_NONBLOCK);
3133 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3136 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3137 int64_t maxsz = 1024*pagsz;
3138 int64_t size = st.st_size, pos = 0;
3140 while( (bfrsz = size-pos) > 0 ) {
3141 if( bfrsz > maxsz ) bfrsz = maxsz;
3142 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3143 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3144 if( bfr == MAP_FAILED ) break;
3145 sha1.addBytes(bfr, bfrsz);
3150 ret = pos < size ? EIO : 0;
3151 fprintf(fp, "SHA1: ");
3152 uint8_t digest[20]; sha1.computeHash(digest);
3153 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3154 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3155 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3159 void MWindow::trap_hook(FILE *fp, void *vp)
3161 MWindow *mwindow = (MWindow *)vp;
3162 // fprintf(fp, "\nPLUGINS:\n");
3163 // mwindow->dump_plugins(fp);
3164 fprintf(fp, "\nEDL:\n");
3165 mwindow->dump_edl(fp);
3166 fprintf(fp, "\nUNDO:\n");
3167 mwindow->dump_undo(fp);
3168 fprintf(fp, "\nEXE:\n");
3169 mwindow->dump_exe(fp);
3177 int MWindow::save_defaults()
3179 gui->save_defaults(defaults);
3180 edl->save_defaults(defaults);
3181 session->save_defaults(defaults);
3182 preferences->save_defaults(defaults);
3184 for(int i = 0; i < plugin_guis->total; i++)
3186 // Pointer comparison
3187 plugin_guis->get(i)->save_defaults();
3189 awindow->save_defaults(defaults);
3195 int MWindow::run_script(FileXML *script)
3197 int result = 0, result2 = 0;
3198 while(!result && !result2)
3200 result = script->read_tag();
3203 if(script->tag.title_is("new_project"))
3205 // Run new in immediate mode.
3206 // gui->mainmenu->new_project->run_script(script);
3209 if(script->tag.title_is("record"))
3211 // Run record as a thread. It is a terminal command.
3213 // Will read the complete scipt file without letting record read it if not
3219 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3226 // ================================= synchronization
3229 int MWindow::interrupt_indexes()
3231 mainprogress->cancelled = 1;
3232 mainindexes->interrupt_build();
3238 void MWindow::next_time_format()
3240 switch(edl->session->time_format)
3242 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3243 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3244 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3245 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3246 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3247 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3248 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3251 time_format_common();
3254 void MWindow::prev_time_format()
3256 switch(edl->session->time_format)
3258 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3259 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3260 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3261 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3262 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3263 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3264 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3267 time_format_common();
3270 void MWindow::time_format_common()
3272 gui->lock_window("MWindow::next_time_format");
3273 gui->redraw_time_dependancies();
3276 char string[BCTEXTLEN], string2[BCTEXTLEN];
3277 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3278 gui->show_message(string);
3280 gui->unlock_window();
3284 int MWindow::set_filename(const char *filename)
3286 if( filename != session->filename )
3287 strcpy(session->filename, filename);
3288 if( filename != edl->path )
3289 strcpy(edl->path, filename);
3293 if(filename[0] == 0)
3295 gui->set_title(PROGRAM_NAME);
3300 char string[BCTEXTLEN], string2[BCTEXTLEN];
3301 dir.extract_name(string, filename);
3302 sprintf(string2, PROGRAM_NAME ": %s", string);
3303 gui->set_title(string2);
3316 int MWindow::set_loop_boundaries()
3318 double start = edl->local_session->get_selectionstart();
3319 double end = edl->local_session->get_selectionend();
3327 if(edl->tracks->total_length())
3330 end = edl->tracks->total_length();
3337 if(edl->local_session->loop_playback && start != end)
3339 edl->local_session->loop_start = start;
3340 edl->local_session->loop_end = end;
3351 int MWindow::reset_meters()
3353 cwindow->gui->lock_window("MWindow::reset_meters 1");
3354 cwindow->gui->meters->reset_meters();
3355 cwindow->gui->unlock_window();
3357 for(int j = 0; j < vwindows.size(); j++) {
3358 VWindow *vwindow = vwindows[j];
3359 if( !vwindow->is_running() ) continue;
3360 vwindow->gui->lock_window("MWindow::reset_meters 2");
3361 vwindow->gui->meters->reset_meters();
3362 vwindow->gui->unlock_window();
3365 lwindow->gui->lock_window("MWindow::reset_meters 3");
3366 lwindow->gui->panel->reset_meters();
3367 lwindow->gui->unlock_window();
3369 gui->lock_window("MWindow::reset_meters 4");
3370 gui->reset_meters();
3371 gui->unlock_window();
3376 void MWindow::resync_guis()
3380 gui->lock_window("MWindow::resync_guis");
3381 gui->update(1, 1, 1, 1, 1, 1, 0);
3382 gui->unlock_window();
3384 cwindow->gui->lock_window("MWindow::resync_guis");
3385 cwindow->gui->resize_event(cwindow->gui->get_w(),
3386 cwindow->gui->get_h());
3387 int channels = edl->session->audio_channels;
3388 cwindow->gui->meters->set_meters(channels, 1);
3389 cwindow->gui->flush();
3390 cwindow->gui->unlock_window();
3392 for(int i = 0; i < vwindows.size(); i++) {
3393 VWindow *vwindow = vwindows[i];
3394 if( !vwindow->is_running() ) continue;
3395 vwindow->gui->lock_window("MWindow::resync_guis");
3396 vwindow->gui->resize_event(vwindow->gui->get_w(),
3397 vwindow->gui->get_h());
3398 vwindow->gui->meters->set_meters(channels, 1);
3399 vwindow->gui->flush();
3400 vwindow->gui->unlock_window();
3403 lwindow->gui->lock_window("MWindow::resync_guis");
3404 lwindow->gui->panel->set_meters(channels, 1);
3405 lwindow->gui->flush();
3406 lwindow->gui->unlock_window();
3409 if(((edl->session->output_w % 4) ||
3410 (edl->session->output_h % 4)) &&
3411 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3413 MainError::show_error(
3414 _("This project's dimensions are not multiples of 4 so\n"
3415 "it can't be rendered by OpenGL."));
3420 sync_parameters(CHANGE_ALL);
3423 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3425 File *file = new File;
3426 EDLSession *session = edl->session;
3427 double old_framerate = session->frame_rate;
3428 double old_samplerate = session->sample_rate;
3429 int result = file->open_file(preferences, asset, 1, 0);
3430 if( !result && delete_tracks > 0 )
3431 undo->update_undo_before();
3432 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3433 // try to get asset up to date, may fail
3434 file->select_video_stream(asset, vstream);
3435 // either way use what was/is there.
3436 double framerate = asset->get_frame_rate();
3437 int width = asset->get_w();
3438 int height = asset->get_h();
3439 // must be multiple of 4 for opengl
3440 width = (width+3) & ~3; height = (height+3) & ~3;
3441 int driver = session->playback_config->vconfig->driver;
3442 int color_model = file->get_best_colormodel(asset, driver);
3443 // color_model = BC_CModels::is_yuv(color_model) ?
3444 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3445 // BC_CModels::is_float(color_model) ?
3446 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3447 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3448 // have alpha for now
3449 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3450 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3451 session->color_model = color_model;
3452 session->output_w = width;
3453 session->output_h = height;
3454 session->frame_rate = framerate;
3455 // not, asset->actual_width/actual_height
3456 asset->width = session->output_w;
3457 asset->height = session->output_h;
3458 asset->frame_rate = session->frame_rate;
3459 create_aspect_ratio(session->aspect_w, session->aspect_h,
3460 session->output_w, session->output_h);
3461 Track *track = edl->tracks->first;
3462 for( Track *next_track=0; track; track=next_track ) {
3463 next_track = track->next;
3464 if( track->data_type != TRACK_VIDEO ) continue;
3465 if( delete_tracks ) {
3466 Edit *edit = track->edits->first;
3467 for( Edit *next_edit=0; edit; edit=next_edit ) {
3468 next_edit = edit->next;
3469 if( edit->channel != vstream ||
3470 !edit->asset || !edit->asset->is_asset ||
3471 *asset != *edit->asset )
3475 if( track->edits->first ) {
3476 track->track_w = edl->session->output_w;
3477 track->track_h = edl->session->output_h;
3479 else if( delete_tracks )
3480 edl->tracks->delete_track(track);
3482 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3484 if( !result && asset->audio_data && asset->channels > 0 ) {
3485 session->sample_rate = asset->get_sample_rate();
3486 int64_t channel_mask = 0;
3487 int astrm = !asset->video_data ? -1 :
3488 file->get_audio_for_video(vstream, astream, channel_mask);
3489 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3490 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3492 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3493 if( channels < 1 ) channels = 1;
3494 if( channels > 6 ) channels = 6;
3495 session->audio_tracks = session->audio_channels = channels;
3496 switch( channels ) {
3498 session->achannel_positions[0] = 90;
3499 session->achannel_positions[1] = 150;
3500 session->achannel_positions[2] = 30;
3501 session->achannel_positions[3] = 210;
3502 session->achannel_positions[4] = 330;
3503 session->achannel_positions[5] = 270;
3506 session->achannel_positions[0] = 180;
3507 session->achannel_positions[1] = 0;
3510 session->achannel_positions[1] = 90;
3513 if( !channels ) break;
3514 double t = 0, dt = 360./channels;
3515 for( int i=channels; --i>=0; t+=dt )
3516 session->achannel_positions[i] = int(t+0.5);
3519 remap_audio(MWindow::AUDIO_1_TO_1);
3521 if( delete_tracks ) {
3522 Track *track = edl->tracks->first;
3523 for( Track *next_track=0; track; track=next_track ) {
3524 next_track = track->next;
3525 if( track->data_type != TRACK_AUDIO ) continue;
3526 Edit *edit = track->edits->first;
3527 for( Edit *next_edit=0; edit; edit=next_edit ) {
3528 next_edit = edit->next;
3529 if( !((1<<edit->channel) & channel_mask) ||
3530 !edit->asset || !edit->asset->is_asset ||
3531 *asset != *edit->asset )
3534 if( !track->edits->first )
3535 edl->tracks->delete_track(track);
3539 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3542 if( !result && delete_tracks > 0 ) {
3544 undo->update_undo_after(_("select asset"), LOAD_ALL);
3550 int MWindow::select_asset(int vtrack, int delete_tracks)
3552 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3554 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3555 if( !track ) return 1;
3556 Edit *edit = track->edits->first;
3557 if( !edit ) return 1;
3558 Asset *asset = edit->asset;
3559 if( !asset || !asset->is_asset ) return 1;
3560 return select_asset(asset, edit->channel, 0, delete_tracks);
3563 void MWindow::dump_plugindb(FILE *fp)
3565 if( !plugindb ) return;
3566 for(int i = 0; i < plugindb->total; i++)
3567 plugindb->get(i)->dump(fp);