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", BCASTDIR);
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 get_exe_path(ladspa_path);
601 strcat(ladspa_path, "/ladspa");
604 for( int len=0; *path; path+=len ) {
605 char *cp = strchr(path,':');
606 len = !cp ? strlen(path) : cp-path;
607 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
608 memcpy(plugin_path, path, len); plugin_path[len] = 0;
609 char *plugin_dir = FileSystem::basepath(plugin_path);
610 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
611 create_defaults_path(index_path, LADSPA_FILE);
612 cp = index_path + strlen(index_path);
613 for( char *bp=plugin_path; *bp!=0; ++bp )
614 *cp++ = *bp=='/' ? '_' : *bp;
616 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
617 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
618 load_plugin_index(mwindow, index_path, plugin_path);
623 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
624 FILE *fp, const char *plugin_dir)
626 int idx = PLUGIN_IDS;
628 for( int i=0; i<plugindb->size(); ++i ) {
629 PluginServer *server = plugindb->get(i);
630 if( server->dir_idx >= idx )
631 idx = server->dir_idx+1;
634 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
637 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
638 const char *index_path, const char *plugin_dir)
640 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
641 strcpy(plugin_path, path); delete [] path;
642 printf("init ladspa index: %s\n", plugin_dir);
643 FILE *fp = fopen(index_path,"w");
645 fprintf(stderr,_("MWindow::init_ladspa_index: "
646 "can't create plugin index: %s\n"), index_path);
649 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
650 fprintf(fp, "%s\n", plugin_dir);
651 init_plugin_index(mwindow, preferences, fp, plugin_path);
656 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
657 const char *plug_dir, const char *plug_path, int &idx)
659 char plugin_path[BCTEXTLEN];
660 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
662 fs.set_filter( "[*.plugin][*.so]" );
663 int result = fs.update(plugin_path);
664 if( result || !fs.dir_list.total ) return;
667 for( int i=0; i<fs.dir_list.total; ++i ) {
668 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
669 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
670 get_plugin_path(path, plug_dir, fs_path);
671 if( fs.is_dir(fs_path) ) {
672 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
675 if( plugin_exists(path) ) continue;
677 if( stat(fs_path, &st) ) continue;
678 int64_t mtime = st.st_mtime;
679 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
680 result = server.open_plugin(1, preferences, 0, 0);
682 server.write_table(fp, path, vis_id, mtime);
683 server.close_plugin();
685 else if( result == PLUGINSERVER_IS_LAD ) {
688 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
689 ladspa.set_lad_index(lad_index++);
690 result = ladspa.open_plugin(1, preferences, 0, 0);
692 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
693 ladspa.close_plugin();
699 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
701 for( int i=0; i<plugins.size(); ++i )
702 plugindb->append(plugins[i]);
703 plugins.remove_all();
706 void MWindow::delete_plugins()
708 plugindb->remove_all_objects();
713 void MWindow::search_plugindb(int do_audio,
718 ArrayList<PluginServer*> &results)
721 for(int i = 0; i < MWindow::plugindb->total; i++)
723 PluginServer *current = MWindow::plugindb->get(i);
725 if(current->audio == do_audio &&
726 current->video == do_video &&
727 (current->realtime == is_realtime || is_realtime < 0) &&
728 current->transition == is_transition &&
729 current->theme == is_theme)
730 results.append(current);
733 // Alphabetize list by title
739 for(int i = 0; i < results.total - 1; i++)
741 PluginServer *value1 = results[i];
742 PluginServer *value2 = results[i + 1];
743 if(strcmp(_(value1->title), _(value2->title)) > 0)
747 results[i + 1] = value1;
753 PluginServer* MWindow::scan_plugindb(char *title,
758 // printf("MWindow::scan_plugindb data_type < 0\n");
762 for(int i = 0; i < plugindb->total; i++)
764 PluginServer *server = plugindb->get(i);
766 !strcasecmp(server->title, title) &&
768 (data_type == TRACK_AUDIO && server->audio) ||
769 (data_type == TRACK_VIDEO && server->video)))
770 return plugindb->get(i);
775 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
777 for( int i=0; i<plugins.size(); ++i )
778 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
782 int MWindow::plugin_exists(char *plugin_path)
784 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
787 void MWindow::init_preferences()
789 preferences = new Preferences;
790 preferences->load_defaults(defaults);
791 session = new MainSession(this);
792 session->load_defaults(defaults);
793 // set x11_host, screens, window_config
794 screens = session->set_default_x11_host();
795 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
796 BC_Signals::set_trap_hook(trap_hook, this);
797 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
798 BC_Signals::set_catch_intr(preferences->trap_sigintr);
801 void MWindow::clean_indexes()
806 int oldest_item = -1;
808 char string[BCTEXTLEN];
809 char string2[BCTEXTLEN];
811 // Delete extra indexes
812 fs.set_filter("*.idx");
813 fs.complete_path(preferences->index_directory);
814 fs.update(preferences->index_directory);
815 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
817 // Eliminate directories
822 for(int i = 0; i < fs.dir_list.total && !result; i++)
824 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
825 if(fs.is_dir(string))
827 delete fs.dir_list[i];
828 fs.dir_list.remove_number(i);
833 total_excess = fs.dir_list.total - preferences->index_count;
835 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
836 while(total_excess > 0)
839 for(int i = 0; i < fs.dir_list.total; i++)
841 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
843 if(i == 0 || fs.get_date(string) <= oldest)
845 oldest = fs.get_date(string);
853 fs.join_names(string,
854 preferences->index_directory,
855 fs.dir_list[oldest_item]->name);
856 //printf("MWindow::clean_indexes 1 %s\n", string);
858 perror("delete_indexes");
859 delete fs.dir_list[oldest_item];
860 fs.dir_list.remove_number(oldest_item);
862 // Remove table of contents if it exists
863 strcpy(string2, string);
864 char *ptr = strrchr(string2, '.');
867 //printf("MWindow::clean_indexes 2 %s\n", string2);
868 sprintf(ptr, ".toc");
870 sprintf(ptr, ".mkr");
879 void MWindow::init_awindow()
881 awindow = new AWindow(this);
882 awindow->create_objects();
885 void MWindow::init_gwindow()
887 gwindow = new GWindow(this);
888 gwindow->create_objects();
891 void MWindow::init_tipwindow()
894 twindow = new TipWindow(this);
898 void MWindow::show_warning(int *do_warning, const char *text)
900 if( do_warning && !*do_warning ) return;
902 wwindow = new WWindow(this);
903 wwindow->show_warning(do_warning, text);
906 void MWindow::init_theme()
911 PluginServer *theme_plugin = 0;
912 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
913 if( plugindb->get(i)->theme &&
914 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
915 theme_plugin = plugindb->get(i);
919 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
922 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
923 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
925 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
926 if( plugindb->get(i)->theme &&
927 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
928 theme_plugin = plugindb->get(i);
933 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
937 PluginServer *plugin = new PluginServer(*theme_plugin);
938 if( plugin->open_plugin(0, preferences, 0, 0) ) {
939 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
940 theme_plugin->title);
944 theme = plugin->new_theme();
945 theme->mwindow = this;
946 strcpy(theme->path, plugin->path);
949 // Load default images & settings
950 theme->Theme::initialize();
951 // Load user images & settings
953 // Create menus with user colors
954 theme->build_menus();
959 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
962 void MWindow::init_3d()
964 playback_3d = new Playback3D(this);
965 playback_3d->create_objects();
968 void MWindow::init_edl()
971 edl->create_objects();
972 fill_preset_defaults(default_standard, edl->session);
973 edl->load_defaults(defaults);
974 edl->create_default_tracks();
975 edl->tracks->update_y_pixels(theme);
978 void MWindow::init_compositor()
980 cwindow = new CWindow(this);
981 cwindow->create_objects();
984 void MWindow::init_levelwindow()
986 lwindow = new LevelWindow(this);
987 lwindow->create_objects();
990 VWindow *MWindow::get_viewer(int start_it, int idx)
992 vwindows_lock->lock("MWindow::get_viewer");
993 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
994 if( !vwindow ) idx = vwindows.size();
995 while( !vwindow && --idx >= 0 ) {
996 VWindow *vwin = vwindows[idx];
997 if( !vwin->is_running() || !vwin->get_edl() )
1001 vwindow = new VWindow(this);
1002 vwindow->load_defaults();
1003 vwindow->create_objects();
1004 vwindows.append(vwindow);
1006 vwindows_lock->unlock();
1007 if( start_it ) vwindow->start();
1011 void MWindow::init_cache()
1013 audio_cache = new CICache(preferences);
1014 video_cache = new CICache(preferences);
1015 frame_cache = new FrameCache;
1016 wave_cache = new WaveCache;
1019 void MWindow::init_channeldb()
1021 channeldb_buz->load("channeldb_buz");
1022 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1025 void MWindow::init_menus()
1027 char string[BCTEXTLEN];
1030 BC_CModels::to_text(string, BC_RGB888);
1031 colormodels.append(new ColormodelItem(string, BC_RGB888));
1032 BC_CModels::to_text(string, BC_RGBA8888);
1033 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1034 // BC_CModels::to_text(string, BC_RGB161616);
1035 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1036 // BC_CModels::to_text(string, BC_RGBA16161616);
1037 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1038 BC_CModels::to_text(string, BC_RGB_FLOAT);
1039 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1040 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1041 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1042 BC_CModels::to_text(string, BC_YUV888);
1043 colormodels.append(new ColormodelItem(string, BC_YUV888));
1044 BC_CModels::to_text(string, BC_YUVA8888);
1045 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1046 // BC_CModels::to_text(string, BC_YUV161616);
1047 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1048 // BC_CModels::to_text(string, BC_YUVA16161616);
1049 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1051 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1052 interlace_project_modes.append(new InterlacemodeItem(string, x));
1054 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1055 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1057 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1058 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1060 // Interlacing Modes
1061 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1063 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1064 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1066 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1067 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1069 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1070 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1072 // Interlacing Fixing Methods
1073 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
1074 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
1075 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
1078 void MWindow::init_indexes()
1080 mainindexes = new MainIndexes(this);
1081 mainindexes->start_loop();
1084 void MWindow::init_gui()
1086 gui = new MWindowGUI(this);
1087 gui->lock_window("MWindow::init_gui");
1088 gui->create_objects();
1089 gui->unlock_window();
1090 gui->load_defaults(defaults);
1093 void MWindow::init_signals()
1095 sighandler = new SigHandler;
1096 sighandler->initialize();
1100 void MWindow::init_render()
1102 render = new Render(this);
1103 create_bd = new CreateBD_Thread(this);
1104 create_dvd = new CreateDVD_Thread(this);
1105 batch_render = new BatchRenderThread(this);
1108 void MWindow::init_exportedl()
1110 exportedl = new ExportEDL(this);
1113 void MWindow::init_brender()
1115 if(preferences->use_brender && !brender)
1117 brender_lock->lock("MWindow::init_brender 1");
1118 brender = new BRender(this);
1119 brender->initialize();
1120 session->brender_end = 0;
1121 brender_lock->unlock();
1124 if(!preferences->use_brender && brender)
1126 brender_lock->lock("MWindow::init_brender 2");
1129 session->brender_end = 0;
1130 brender_lock->unlock();
1132 if(brender) brender->restart(edl);
1135 void MWindow::restart_brender()
1137 //printf("MWindow::restart_brender 1\n");
1138 if(brender) brender->restart(edl);
1141 void MWindow::stop_brender()
1143 if(brender) brender->stop();
1146 int MWindow::brender_available(int position)
1149 brender_lock->lock("MWindow::brender_available 1");
1152 if(brender->map_valid)
1154 brender->map_lock->lock("MWindow::brender_available 2");
1155 if(position < brender->map_size &&
1158 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1159 if(brender->map[position] == BRender::RENDERED)
1162 brender->map_lock->unlock();
1165 brender_lock->unlock();
1169 void MWindow::set_brender_start()
1171 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1173 gui->draw_overlays(1);
1177 int MWindow::has_commercials()
1179 return theme->use_commercials;
1182 void MWindow::init_commercials()
1184 if( !commercials ) {
1185 commercials = new Commercials(this);
1186 commercial_active = 0;
1189 commercials->add_user();
1192 void MWindow::commit_commercial()
1194 if( !commercial_active ) return;
1195 commercial_active = 0;
1196 if( !commercials ) return;
1197 commercials->commitDb();
1200 void MWindow::undo_commercial()
1202 if( !commercial_active ) return;
1203 commercial_active = 0;
1204 if( !commercials ) return;
1205 commercials->undoDb();
1208 int MWindow::put_commercial()
1210 double start = edl->local_session->get_selectionstart();
1211 double end = edl->local_session->get_selectionend();
1212 if( start >= end ) return 0;
1214 const char *errmsg = 0;
1216 Tracks *tracks = edl->tracks;
1219 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1220 if( track->data_type != TRACK_VIDEO ) continue;
1221 if( !track->record ) continue;
1222 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1224 int64_t units_start = track->to_units(start,0);
1225 int64_t units_end = track->to_units(end,0);
1226 Edits *edits = track->edits;
1227 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1228 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1229 if(!edit1 && !edit2) continue; // nothing selected
1230 if(!edit2) { // edit2 beyond end of track
1231 edit2 = edits->last;
1232 units_end = edits->length();
1234 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1235 Indexable *indexable = edit1->get_source();
1236 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1239 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1240 if( track->data_type != TRACK_VIDEO ) continue;
1241 if( !track->record ) continue;
1242 int64_t units_start = track->to_units(start,0);
1243 int64_t units_end = track->to_units(end,0);
1244 Edits *edits = track->edits;
1245 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1246 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1247 if(!edit1 && !edit2) continue; // nothing selected
1248 if(!edit2) { // edit2 beyond end of track
1249 edit2 = edits->last;
1250 units_end = edits->length();
1252 Indexable *indexable = edit1->get_source();
1253 Asset *asset = (Asset *)indexable;
1254 File *file = video_cache->check_out(asset, edl);
1255 if( !file ) { errmsg = _("no file"); break; }
1256 int64_t edit_length = units_end - units_start;
1257 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1258 result = commercials->put_clip(file, edit1->channel,
1259 track->from_units(edit_start), track->from_units(edit_length));
1260 video_cache->check_in(asset);
1261 if( result ) { errmsg = _("db failed"); break; }
1264 char string[BCTEXTLEN];
1265 sprintf(string, _("put_commercial: %s"), errmsg);
1266 MainError::show_error(string);
1273 void MWindow::stop_playback(int wait)
1275 int locked = gui->get_window_lock();
1276 if( locked ) gui->unlock_window();
1278 cwindow->playback_engine->que->send_command(STOP,
1282 cwindow->playback_engine->interrupt_playback(wait);
1284 for(int i = 0; i < vwindows.size(); i++) {
1285 VWindow *vwindow = vwindows[i];
1286 if( !vwindow->is_running() ) continue;
1287 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1288 vwindow->playback_engine->interrupt_playback(wait);
1290 if( locked ) gui->lock_window("MWindow::stop_playback");
1293 int MWindow::load_filenames(ArrayList<char*> *filenames,
1295 int update_filename)
1297 ArrayList<EDL*> new_edls;
1298 ArrayList<Asset*> new_assets;
1299 ArrayList<File*> new_files;
1300 const int debug = 0;
1301 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1304 gui->start_hourglass();
1306 // Need to stop playback since tracking depends on the EDL not getting
1310 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1311 undo->update_undo_before();
1314 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1316 // Define new_edls and new_assets to load
1317 int result = 0, ftype = -1;
1318 for(int i = 0; i < filenames->size(); i++)
1321 File *new_file = new File;
1322 Asset *new_asset = new Asset(filenames->get(i));
1323 EDL *new_edl = new EDL;
1324 char string[BCTEXTLEN];
1326 new_edl->create_objects();
1327 new_edl->copy_session(edl);
1328 new_file->set_program(edl->session->program_no);
1330 sprintf(string, _("Loading %s"), new_asset->path);
1331 gui->show_message(string);
1332 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1334 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1335 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1340 // Convert media file to EDL
1342 // Warn about odd image dimensions
1343 if(new_asset->video_data &&
1344 ((new_asset->width % 2) ||
1345 (new_asset->height % 2)))
1347 char string[BCTEXTLEN];
1348 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1352 MainError::show_error(string);
1355 if(new_asset->program >= 0 &&
1356 edl->session->program_no != new_asset->program)
1358 char string[BCTEXTLEN];
1359 sprintf(string, _("%s's index was built for program number %d\n"
1360 "Playback preference is %d.\n Using program %d."),
1361 new_asset->path, new_asset->program,
1362 edl->session->program_no, new_asset->program);
1363 MainError::show_error(string);
1367 if(load_mode != LOADMODE_RESOURCESONLY)
1370 RecordLabels *labels = edl->session->label_cells ?
1371 new RecordLabels(new_file) : 0;
1373 asset_to_edl(new_edl, new_asset, labels);
1375 new_edls.append(new_edl);
1377 new_asset->Garbage::remove_user();
1383 new_assets.append(new_asset);
1387 // Set filename to nothing for assets since save EDL would overwrite them.
1388 if(load_mode == LOADMODE_REPLACE ||
1389 load_mode == LOADMODE_REPLACE_CONCATENATE)
1392 // Reset timeline position
1393 for(int i = 0; i < TOTAL_PANES; i++)
1395 new_edl->local_session->view_start[i] = 0;
1396 new_edl->local_session->track_start[i] = 0;
1404 case FILE_NOT_FOUND:
1405 sprintf(string, _("Failed to open %s"), new_asset->path);
1406 gui->show_message(string, theme->message_error);
1410 case FILE_UNRECOGNIZED_CODEC:
1413 IndexFile indexfile(this, new_asset);
1414 result = indexfile.open_index();
1417 indexfile.close_index();
1420 // Test existing EDLs
1421 for(int j = 0; result && j <= new_edls.total; j++) {
1422 Asset *old_asset = j < new_edls.total ?
1423 new_edls[j]->assets->get_asset(new_asset->path) :
1424 edl->assets->get_asset(new_asset->path);
1426 *new_asset = *old_asset;
1434 char string[BCTEXTLEN];
1436 fs.extract_name(string, new_asset->path);
1438 strcat(string, _("'s format couldn't be determined."));
1439 new_asset->audio_data = 1;
1440 new_asset->format = FILE_PCM;
1441 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1442 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1443 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1444 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1445 new_asset->signed_ = defaults->get("SIGNED_", 1);
1446 new_asset->header = defaults->get("HEADER", 0);
1448 FileFormat fwindow(this);
1449 fwindow.create_objects(new_asset, string);
1450 result = fwindow.run_window();
1453 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1454 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1455 defaults->update("AUDIO_BITS", new_asset->bits);
1456 defaults->update("BYTE_ORDER", new_asset->byte_order);
1457 defaults->update("SIGNED_", new_asset->signed_);
1458 defaults->update("HEADER", new_asset->header);
1465 // Recalculate length
1467 new_file = new File;
1468 result = new_file->open_file(preferences, new_asset, 1, 0);
1470 if(load_mode != LOADMODE_RESOURCESONLY)
1472 RecordLabels *labels = edl->session->label_cells ?
1473 new RecordLabels(new_file) : 0;
1474 asset_to_edl(new_edl, new_asset, labels);
1475 new_edls.append(new_edl);
1476 new_asset->Garbage::remove_user();
1482 new_assets.append(new_asset);
1496 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1497 xml_file.read_from_file(filenames->get(i));
1498 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1500 if(load_mode == LOADMODE_NESTED)
1502 // Load temporary EDL for nesting.
1503 EDL *nested_edl = new EDL;
1504 nested_edl->create_objects();
1505 nested_edl->set_path(filenames->get(i));
1506 nested_edl->load_xml(&xml_file, LOAD_ALL);
1507 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1508 edl_to_nested(new_edl, nested_edl);
1509 nested_edl->Garbage::remove_user();
1513 // Load EDL for pasting
1514 new_edl->load_xml(&xml_file, LOAD_ALL);
1515 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1516 test_plugins(new_edl, filenames->get(i));
1517 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1519 if(load_mode == LOADMODE_REPLACE ||
1520 load_mode == LOADMODE_REPLACE_CONCATENATE)
1522 strcpy(session->filename, filenames->get(i));
1523 strcpy(new_edl->local_session->clip_title,
1526 set_filename(new_edl->local_session->clip_title);
1530 new_edls.append(new_edl);
1536 // edls are in new_edls
1537 if( result && new_edl ) new_edl->Garbage::remove_user();
1538 // assets are copied
1539 if( new_asset ) new_asset->Garbage::remove_user();
1541 // Store for testing index
1542 new_files.append(new_file);
1545 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1548 if(!result) gui->statusbar->default_message();
1556 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1559 // Don't back up here.
1562 // For pasting, clear the active region
1563 if(load_mode == LOADMODE_PASTE ||
1564 load_mode == LOADMODE_NESTED)
1566 double start = edl->local_session->get_selectionstart();
1567 double end = edl->local_session->get_selectionend();
1568 if(!EQUIV(start, end))
1571 edl->session->labels_follow_edits,
1572 edl->session->plugins_follow_edits,
1573 edl->session->autos_follow_edits);
1576 paste_edls(&new_edls,
1580 edl->session->labels_follow_edits,
1581 edl->session->plugins_follow_edits,
1582 edl->session->autos_follow_edits,
1589 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1591 // Add new assets to EDL and schedule assets for index building.
1592 int got_indexes = 0;
1593 for(int i = 0; i < new_edls.size(); i++)
1595 EDL *new_edl = new_edls[i];
1596 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1598 mainindexes->add_next_asset(0,
1599 new_edl->nested_edls->get(j));
1601 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1606 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1607 if(new_assets.size())
1609 for(int i = 0; i < new_assets.size(); i++)
1611 Asset *new_asset = new_assets[i];
1615 for(int j = 0; j < new_files.size(); j++)
1617 new_file = new_files[j];
1618 if(!strcmp(new_file->asset->path,
1626 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1628 edl->assets->update(new_asset);
1634 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1636 // Start examining next batch of index files
1637 if(got_indexes) mainindexes->start_build();
1638 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1641 Track *track = edl->tracks->first;
1644 for(int j = 0; j < track->plugin_set.size(); j++)
1646 PluginSet *plugins = track->plugin_set[j];
1647 Plugin *plugin = plugins->get_first_plugin();
1651 if(load_mode == LOADMODE_REPLACE ||
1652 load_mode == LOADMODE_REPLACE_CONCATENATE)
1654 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1657 show_plugin(plugin);
1665 plugin = (Plugin*)plugin->next;
1669 track = track->next;
1672 // if just opening one new resource in replace mode
1673 if( ftype != FILE_IS_XML &&
1674 ( load_mode == LOADMODE_REPLACE ||
1675 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1677 edl->local_session->preview_start = 0;
1678 edl->local_session->preview_end = edl->tracks->total_playable_length();
1679 edl->local_session->loop_playback = 0;
1680 edl->local_session->set_selectionstart(0);
1681 edl->local_session->set_selectionend(0);
1686 // need to update undo before project, since mwindow is unlocked & a new load
1687 // can begin here. Should really prevent loading until we're done.
1688 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1689 undo->update_undo_after(_("load"), LOAD_ALL);
1691 for(int i = 0; i < new_edls.size(); i++)
1693 new_edls[i]->remove_user();
1695 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1697 new_edls.remove_all();
1699 for(int i = 0; i < new_assets.size(); i++)
1701 new_assets[i]->Garbage::remove_user();
1704 new_assets.remove_all();
1705 new_files.remove_all_objects();
1708 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1709 if(load_mode == LOADMODE_REPLACE ||
1710 load_mode == LOADMODE_REPLACE_CONCATENATE)
1712 session->changes_made = 0;
1716 session->changes_made = 1;
1719 gui->stop_hourglass();
1722 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1723 update_project(load_mode);
1725 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1733 void MWindow::test_plugins(EDL *new_edl, char *path)
1735 char string[BCTEXTLEN];
1737 // Do a check weather plugins exist
1738 for(Track *track = new_edl->tracks->first; track; track = track->next)
1740 for(int k = 0; k < track->plugin_set.total; k++)
1742 PluginSet *plugin_set = track->plugin_set[k];
1743 for(Plugin *plugin = (Plugin*)plugin_set->first;
1745 plugin = (Plugin*)plugin->next)
1747 if(plugin->plugin_type == PLUGIN_STANDALONE)
1749 // ok we need to find it in plugindb
1750 int plugin_found = 0;
1752 for(int j = 0; j < plugindb->size(); j++)
1754 PluginServer *server = plugindb->get(j);
1756 !strcasecmp(server->title, plugin->title) &&
1757 ((track->data_type == TRACK_AUDIO && server->audio) ||
1758 (track->data_type == TRACK_VIDEO && server->video)) &&
1759 (!server->transition))
1766 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1767 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1768 "effect", plugin->title,
1770 MainError::show_error(string);
1776 for(Edit *edit = (Edit*)track->edits->first;
1778 edit = (Edit*)edit->next)
1780 if (edit->transition)
1782 // ok we need to find transition in plugindb
1784 int transition_found = 0;
1785 for(int j = 0; j < plugindb->size(); j++)
1787 PluginServer *server = plugindb->get(j);
1789 !strcasecmp(server->title, edit->transition->title) &&
1790 ((track->data_type == TRACK_AUDIO && server->audio) ||
1791 (track->data_type == TRACK_VIDEO && server->video)) &&
1792 (server->transition))
1793 transition_found = 1;
1796 if (!transition_found)
1799 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1800 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1801 "transition", edit->transition->title,
1803 MainError::show_error(string);
1811 void MWindow::init_shm()
1813 // Fix shared memory
1814 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1816 fprintf(fd, "0x7fffffff");
1821 fd = fopen("/proc/sys/kernel/shmmax", "r");
1823 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1828 fscanf(fd, "%jd", &result);
1831 if(result < 0x7fffffff) {
1832 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1833 "you probably need to be root, or:\n"
1834 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1835 "before trying to start cinelerra.\n"
1836 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1840 void MWindow::create_objects(int want_gui,
1845 const int debug = 0;
1846 if(debug) PRINT_TRACE
1848 // For some reason, init_signals must come after show_splash or the signals won't
1851 if(debug) PRINT_TRACE
1854 if(debug) PRINT_TRACE
1857 if(debug) PRINT_TRACE
1858 default_standard = default_std();
1859 init_defaults(defaults, config_path);
1862 splash_window->operation->update(_("Initializing Plugins"));
1863 init_plugins(this, preferences);
1864 if(debug) PRINT_TRACE
1865 init_ladspa_plugins(this, preferences);
1866 if(debug) PRINT_TRACE
1868 splash_window->operation->update(_("Initializing GUI"));
1869 if(debug) PRINT_TRACE
1872 if(debug) PRINT_TRACE
1876 splash_window->operation->update(_("Initializing Fonts"));
1877 char string[BCTEXTLEN];
1878 strcpy(string, preferences->plugin_dir);
1879 strcat(string, "/" FONT_SEARCHPATH);
1880 BC_Resources::init_fontconfig(string);
1881 if(debug) PRINT_TRACE
1883 // Initialize before too much else is running
1884 // Preferences & theme are required for building MPEG table of contents
1886 // Default project created here
1888 if(debug) PRINT_TRACE
1891 if(debug) PRINT_TRACE
1896 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1898 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1899 if(session->show_vwindow)
1900 get_viewer(1, DEFAULT_VWINDOW);
1901 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1904 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1907 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1910 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1912 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1915 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1919 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1921 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());
1927 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1928 mainprogress = new MainProgress(this, gui);
1929 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1930 undo = new MainUndo(this);
1932 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1934 plugin_guis = new ArrayList<PluginServer*>;
1935 dead_plugins = new ArrayList<PluginServer*>;
1936 keyframe_threads = new ArrayList<KeyFrameThread*>;
1938 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1941 session->show_vwindow);
1943 // Show all vwindows
1944 // if(session->show_vwindow) {
1945 // for(int j = 0; j < vwindows.size(); j++) {
1946 // VWindow *vwindow = vwindows[j];
1947 // if( !vwindow->is_running() ) continue;
1948 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1951 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1952 // vwindow->gui->lock_window("MWindow::create_objects 1");
1953 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1954 // vwindow->gui->show_window();
1955 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1956 // vwindow->gui->unlock_window();
1961 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1963 if(session->show_cwindow)
1965 cwindow->gui->lock_window("MWindow::create_objects 1");
1966 cwindow->gui->show_window();
1967 cwindow->gui->unlock_window();
1970 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1971 if(session->show_awindow)
1973 awindow->gui->lock_window("MWindow::create_objects 1");
1974 awindow->gui->show_window();
1975 awindow->gui->unlock_window();
1978 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1979 if(session->show_lwindow)
1981 lwindow->gui->lock_window("MWindow::create_objects 1");
1982 lwindow->gui->show_window();
1983 lwindow->gui->unlock_window();
1986 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1988 (int)timer.get_difference(),
1990 if(session->show_gwindow)
1992 gwindow->gui->lock_window("MWindow::create_objects 1");
1993 gwindow->gui->show_window();
1994 gwindow->gui->unlock_window();
1997 if(debug) PRINT_TRACE
1999 gui->lock_window("MWindow::create_objects 1");
2000 gui->mainmenu->load_defaults(defaults);
2001 gui->mainmenu->update_toggles(0);
2002 gui->update_patchbay();
2003 gui->draw_canvas(0, 0);
2004 gui->draw_cursor(1);
2006 gui->raise_window();
2007 gui->unlock_window();
2009 if(debug) PRINT_TRACE
2011 if(preferences->use_tipwindow)
2013 if(debug) PRINT_TRACE
2015 gui->add_keyboard_listener(
2016 (int (BC_WindowBase::*)(BC_WindowBase *))
2017 &MWindowGUI::keyboard_listener);
2021 if(debug) PRINT_TRACE
2023 BC_WindowBase::get_resources()->vframe_shm = 1;
2027 void MWindow::show_splash()
2029 #include "data/heroine_logo9_png.h"
2030 VFrame *frame = new VFramePng(heroine_logo9_png);
2031 BC_DisplayInfo dpyi;
2032 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2033 int rr = (rw < rh ? rw : rh) / 4;
2034 splash_window = new SplashGUI(frame, rr, rr);
2035 splash_window->create_objects();
2038 void MWindow::hide_splash()
2041 delete splash_window;
2046 void MWindow::start()
2050 // vwindows[DEFAULT_VWINDOW]->start();
2061 playback_3d->start();
2070 void MWindow::show_vwindow()
2072 int total_running = 0;
2073 session->show_vwindow = 1;
2075 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2076 // Raise all windows which are visible
2077 for(int j = 0; j < vwindows.size(); j++) {
2078 VWindow *vwindow = vwindows[j];
2079 if( !vwindow->is_running() ) continue;
2080 vwindow->gui->lock_window("MWindow::show_vwindow");
2081 vwindow->gui->show_window(0);
2082 vwindow->gui->raise_window();
2083 vwindow->gui->flush();
2084 vwindow->gui->unlock_window();
2088 // If no windows visible
2091 get_viewer(1, DEFAULT_VWINDOW);
2094 gui->mainmenu->show_vwindow->set_checked(1);
2097 void MWindow::show_awindow()
2099 session->show_awindow = 1;
2100 awindow->gui->lock_window("MWindow::show_awindow");
2101 awindow->gui->show_window();
2102 awindow->gui->raise_window();
2103 awindow->gui->flush();
2104 awindow->gui->unlock_window();
2105 gui->mainmenu->show_awindow->set_checked(1);
2108 char *MWindow::get_cwindow_display()
2110 char *x11_host = screens < 2 || session->window_config == 0 ?
2111 session->a_x11_host : session->b_x11_host;
2112 return *x11_host ? x11_host : 0;
2115 void MWindow::show_cwindow()
2117 session->show_cwindow = 1;
2118 cwindow->show_window();
2119 gui->mainmenu->show_cwindow->set_checked(1);
2122 void MWindow::show_gwindow()
2124 session->show_gwindow = 1;
2126 gwindow->gui->lock_window("MWindow::show_gwindow");
2127 gwindow->gui->show_window();
2128 gwindow->gui->raise_window();
2129 gwindow->gui->flush();
2130 gwindow->gui->unlock_window();
2132 gui->mainmenu->show_gwindow->set_checked(1);
2135 void MWindow::show_lwindow()
2137 session->show_lwindow = 1;
2138 lwindow->gui->lock_window("MWindow::show_lwindow");
2139 lwindow->gui->show_window();
2140 lwindow->gui->raise_window();
2141 lwindow->gui->flush();
2142 lwindow->gui->unlock_window();
2143 gui->mainmenu->show_lwindow->set_checked(1);
2146 int MWindow::tile_windows(int window_config)
2148 int need_reload = 0;
2149 int play_config = window_config==0 ? 0 : 1;
2150 edl->session->playback_config->load_defaults(defaults, play_config);
2151 session->default_window_positions(window_config);
2152 if( screens == 1 ) {
2153 gui->default_positions();
2154 sync_parameters(CHANGE_ALL);
2161 void MWindow::toggle_loop_playback()
2163 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2164 set_loop_boundaries();
2167 gui->draw_overlays(1);
2168 sync_parameters(CHANGE_PARAMS);
2171 //void MWindow::set_titles(int value)
2173 // edl->session->show_titles = value;
2174 // trackmovement(edl->local_session->track_start);
2177 void MWindow::set_screens(int value)
2182 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2184 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2185 edl->session->auto_keyframes = value;
2186 gui->mbuttons->edit_panel->keyframe->update(value);
2188 if(lock_mwindow) gui->unlock_window();
2190 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2191 cwindow->gui->edit_panel->keyframe->update(value);
2192 cwindow->gui->flush();
2193 if(lock_cwindow) cwindow->gui->unlock_window();
2196 void MWindow::set_keyframe_type(int mode)
2198 gui->lock_window("MWindow::set_keyframe_type");
2199 edl->local_session->floatauto_type = mode;
2200 gui->mainmenu->update_toggles(0);
2201 gui->unlock_window();
2204 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2206 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2207 edl->session->editing_mode = new_editing_mode;
2208 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2209 gui->mbuttons->edit_panel->update();
2210 gui->set_editing_mode(1);
2211 if(lock_mwindow) gui->unlock_window();
2214 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2215 cwindow->gui->edit_panel->update();
2216 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2217 if(lock_cwindow) cwindow->gui->unlock_window();
2221 void MWindow::toggle_editing_mode()
2223 int mode = edl->session->editing_mode;
2224 if( mode == EDITING_ARROW )
2225 set_editing_mode(EDITING_IBEAM, 0, 1);
2227 set_editing_mode(EDITING_ARROW, 0, 1);
2231 void MWindow::set_labels_follow_edits(int value)
2233 gui->lock_window("MWindow::set_labels_follow_edits");
2234 edl->session->labels_follow_edits = value;
2235 gui->mbuttons->edit_panel->locklabels->update(value);
2236 gui->mainmenu->labels_follow_edits->set_checked(value);
2238 gui->unlock_window();
2241 void MWindow::sync_parameters(int change_type)
2243 if( in_destructor ) return;
2245 // Sync engines which are playing back
2246 if(cwindow->playback_engine->is_playing_back)
2248 if(change_type == CHANGE_PARAMS)
2250 // TODO: block keyframes until synchronization is done
2251 cwindow->playback_engine->sync_parameters(edl);
2256 int command = cwindow->playback_engine->command->command;
2257 cwindow->playback_engine->que->send_command(STOP,
2261 // Waiting for tracking to finish would make the restart position more
2262 // accurate but it can't lock the window to stop tracking for some reason.
2263 // Not waiting for tracking gives a faster response but restart position is
2264 // only as accurate as the last tracking update.
2265 cwindow->playback_engine->interrupt_playback(0);
2266 cwindow->playback_engine->que->send_command(command,
2275 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2282 void MWindow::age_caches()
2284 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2286 // preferences->cache_size,
2287 // audio_cache->get_memory_usage(1),
2288 // video_cache->get_memory_usage(1),
2289 // frame_cache->get_memory_usage(),
2290 // wave_cache->get_memory_usage(),
2292 frame_cache->age_cache(512);
2293 wave_cache->age_cache(8192);
2295 int64_t memory_usage;
2296 int64_t prev_memory_usage = 0;
2298 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2299 while( !result && prev_memory_usage !=
2300 (memory_usage=video_cache->get_memory_usage(1)) &&
2301 memory_usage > video_size ) {
2302 video_cache->delete_oldest();
2303 prev_memory_usage = memory_usage;
2306 prev_memory_usage = 0;
2308 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2309 while( !result && prev_memory_usage !=
2310 (memory_usage=audio_cache->get_memory_usage(1)) &&
2311 memory_usage > audio_size ) {
2312 audio_cache->delete_oldest();
2313 prev_memory_usage = memory_usage;
2317 void MWindow::reset_android_remote()
2319 gui->use_android_remote(preferences->android_remote);
2323 void MWindow::show_keyframe_gui(Plugin *plugin)
2325 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2326 // Find existing thread
2327 for(int i = 0; i < keyframe_threads->size(); i++)
2329 if(keyframe_threads->get(i)->plugin == plugin)
2331 keyframe_threads->get(i)->start_window(plugin, 0);
2332 keyframe_gui_lock->unlock();
2337 // Find unused thread
2338 for(int i = 0; i < keyframe_threads->size(); i++)
2340 if(!keyframe_threads->get(i)->plugin)
2342 keyframe_threads->get(i)->start_window(plugin, 0);
2343 keyframe_gui_lock->unlock();
2348 // Create new thread
2349 KeyFrameThread *thread = new KeyFrameThread(this);
2350 keyframe_threads->append(thread);
2351 thread->start_window(plugin, 0);
2353 keyframe_gui_lock->unlock();
2360 void MWindow::show_plugin(Plugin *plugin)
2365 // Remove previously deleted plugin GUIs
2366 dead_plugin_lock->lock("MWindow::show_plugin");
2367 dead_plugins->remove_all_objects();
2368 dead_plugin_lock->unlock();
2370 //printf("MWindow::show_plugin %d\n", __LINE__);
2374 plugin_gui_lock->lock("MWindow::show_plugin");
2375 for(int i = 0; i < plugin_guis->total; i++)
2377 // Pointer comparison
2378 if(plugin_guis->get(i)->plugin == plugin)
2380 plugin_guis->get(i)->raise_window();
2387 //printf("MWindow::show_plugin 1\n");
2392 printf("MWindow::show_plugin track not defined.\n");
2394 PluginServer *server = scan_plugindb(plugin->title,
2395 plugin->track->data_type);
2397 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2398 if(server && server->uses_gui)
2400 PluginServer *gui = new PluginServer(*server);
2401 plugin_guis->append(gui);
2402 // Needs mwindow to do GUI
2403 gui->set_mwindow(this);
2404 gui->open_plugin(0, preferences, edl, plugin);
2409 plugin_gui_lock->unlock();
2410 //printf("MWindow::show_plugin %d\n", __LINE__);
2413 //printf("MWindow::show_plugin 2\n");
2416 void MWindow::hide_plugin(Plugin *plugin, int lock)
2419 // Update the toggle
2420 gui->lock_window("MWindow::hide_plugin");
2421 gui->update(0, 1, 0, 0, 0, 0, 0);
2422 gui->unlock_window();
2424 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2425 for(int i = 0; i < plugin_guis->total; i++)
2427 if(plugin_guis->get(i)->plugin == plugin)
2429 PluginServer *ptr = plugin_guis->get(i);
2430 plugin_guis->remove(ptr);
2431 if(lock) plugin_gui_lock->unlock();
2432 // Last command executed in client side close
2433 // Schedule for deletion
2440 if(lock) plugin_gui_lock->unlock();
2443 void MWindow::delete_plugin(PluginServer *plugin)
2445 dead_plugin_lock->lock("MWindow::delete_plugin");
2446 dead_plugins->append(plugin);
2447 dead_plugin_lock->unlock();
2450 void MWindow::hide_plugins()
2452 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2453 while(plugin_guis->size())
2455 PluginServer *ptr = plugin_guis->get(0);
2456 plugin_guis->remove(ptr);
2457 plugin_gui_lock->unlock();
2458 // Last command executed in client side close
2459 // Schedule for deletion
2462 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2464 plugin_gui_lock->unlock();
2466 hide_keyframe_guis();
2469 void MWindow::hide_keyframe_guis()
2471 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2472 for(int i = 0; i < keyframe_threads->size(); i++)
2474 keyframe_threads->get(i)->close_window();
2476 keyframe_gui_lock->unlock();
2479 void MWindow::hide_keyframe_gui(Plugin *plugin)
2481 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2482 for(int i = 0; i < keyframe_threads->size(); i++)
2484 if(keyframe_threads->get(i)->plugin == plugin)
2486 keyframe_threads->get(i)->close_window();
2490 keyframe_gui_lock->unlock();
2493 void MWindow::update_keyframe_guis()
2495 // Send new configuration to keyframe GUI's
2496 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2497 for(int i = 0; i < keyframe_threads->size(); i++)
2499 KeyFrameThread *ptr = keyframe_threads->get(i);
2500 if(edl->tracks->plugin_exists(ptr->plugin))
2504 ptr->close_window();
2507 keyframe_gui_lock->unlock();
2510 void MWindow::update_plugin_guis(int do_keyframe_guis)
2512 // Send new configuration to plugin GUI's
2513 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2515 for(int i = 0; i < plugin_guis->size(); i++)
2517 PluginServer *ptr = plugin_guis->get(i);
2518 if(edl->tracks->plugin_exists(ptr->plugin))
2522 // Schedule for deletion if no plugin
2523 plugin_guis->remove_number(i);
2532 // Change plugin variable if not visible
2533 Track *track = edl->tracks->first;
2536 for(int i = 0; i < track->plugin_set.size(); i++)
2538 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2542 for(int i = 0; i < plugin_guis->size(); i++)
2544 PluginServer *server = plugin_guis->get(i);
2545 if(server->plugin == plugin)
2552 if(!got_it) plugin->show = 0;
2554 plugin = (Plugin*)plugin->next;
2558 track = track->next;
2561 plugin_gui_lock->unlock();
2564 if(do_keyframe_guis) update_keyframe_guis();
2567 int MWindow::plugin_gui_open(Plugin *plugin)
2570 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2571 for(int i = 0; i < plugin_guis->total; i++)
2573 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2579 plugin_gui_lock->unlock();
2583 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2585 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2586 for(int i = 0; i < plugin_guis->total; i++)
2588 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2590 plugin_guis->get(i)->render_gui(data);
2594 plugin_gui_lock->unlock();
2597 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2599 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2600 for(int i = 0; i < plugin_guis->total; i++)
2602 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2604 plugin_guis->get(i)->render_gui(data, size);
2608 plugin_gui_lock->unlock();
2612 void MWindow::update_plugin_states()
2614 plugin_gui_lock->lock("MWindow::update_plugin_states");
2615 for(int i = 0; i < plugin_guis->total; i++)
2619 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2620 PluginServer *src_plugingui = plugin_guis->get(i);
2622 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2623 for(Track *track = edl->tracks->first;
2625 track = track->next)
2628 j < track->plugin_set.total && !result;
2631 PluginSet *plugin_set = track->plugin_set[j];
2632 for(Plugin *plugin = (Plugin*)plugin_set->first;
2634 plugin = (Plugin*)plugin->next)
2636 if(plugin == src_plugin &&
2637 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2643 // Doesn't exist anymore
2646 hide_plugin(src_plugin, 0);
2650 plugin_gui_lock->unlock();
2654 void MWindow::update_plugin_titles()
2656 for(int i = 0; i < plugin_guis->total; i++)
2658 plugin_guis->get(i)->update_title();
2662 int MWindow::asset_to_edl(EDL *new_edl,
2664 RecordLabels *labels)
2666 const int debug = 0;
2667 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2670 // Keep frame rate, sample rate, and output size unchanged.
2671 // These parameters would revert the project if VWindow displayed an asset
2672 // of different size than the project.
2673 if(new_asset->video_data)
2675 new_edl->session->video_tracks = new_asset->layers;
2678 new_edl->session->video_tracks = 0;
2680 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2686 if(new_asset->audio_data)
2688 new_edl->session->audio_tracks = new_asset->channels;
2691 new_edl->session->audio_tracks = 0;
2692 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2694 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2695 new_edl->create_default_tracks();
2696 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2697 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2701 //printf("MWindow::asset_to_edl 3\n");
2702 new_edl->insert_asset(new_asset,
2707 //printf("MWindow::asset_to_edl 3\n");
2708 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2710 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2711 if(edl->session->cursor_on_frames)
2713 double length = new_edl->tracks->total_length();
2714 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2715 new_edl->tracks->clear(length, edl_length, 1, 1);
2721 char string[BCTEXTLEN];
2723 fs.extract_name(string, new_asset->path);
2724 //printf("MWindow::asset_to_edl 3\n");
2726 strcpy(new_edl->local_session->clip_title, string);
2727 //printf("MWindow::asset_to_edl 4 %s\n", string);
2728 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2733 int MWindow::edl_to_nested(EDL *new_edl,
2737 // Keep frame rate, sample rate, and output size unchanged.
2738 // These parameters would revert the project if VWindow displayed an asset
2739 // of different size than the project.
2743 // Nest all video & audio outputs
2744 new_edl->session->video_tracks = 1;
2745 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2746 new_edl->create_default_tracks();
2750 new_edl->insert_asset(0,
2756 char string[BCTEXTLEN];
2758 fs.extract_name(string, nested_edl->path);
2759 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2761 strcpy(new_edl->local_session->clip_title, string);
2766 // Reset everything after a load.
2767 void MWindow::update_project(int load_mode)
2769 const int debug = 0;
2771 if(debug) PRINT_TRACE
2773 edl->tracks->update_y_pixels(theme);
2775 if(debug) PRINT_TRACE
2777 if(load_mode == LOADMODE_REPLACE ||
2778 load_mode == LOADMODE_REPLACE_CONCATENATE)
2783 gui->update(1, 1, 1, 1, 1, 1, 1);
2784 if(debug) PRINT_TRACE
2785 gui->unlock_window();
2787 cwindow->gui->lock_window("MWindow::update_project 1");
2788 cwindow->update(0, 0, 1, 1, 1);
2789 cwindow->gui->unlock_window();
2791 if(debug) PRINT_TRACE
2793 // Close all the vwindows
2794 if(load_mode == LOADMODE_REPLACE ||
2795 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2796 if(debug) PRINT_TRACE
2797 int first_vwindow = 0;
2798 if(session->show_vwindow) first_vwindow = 1;
2799 // Change visible windows to no source
2800 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2801 VWindow *vwindow = vwindows[i];
2802 if( !vwindow->is_running() ) continue;
2803 vwindow->change_source(-1);
2806 // Close remaining windows
2807 for(int i = first_vwindow; i < vwindows.size(); i++) {
2808 VWindow *vwindow = vwindows[i];
2809 if( !vwindow->is_running() ) continue;
2810 vwindow->close_window();
2812 if(debug) PRINT_TRACE
2814 else if(vwindows.size()) {
2815 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2816 if( vwindow->is_running() ) {
2817 vwindow->gui->lock_window("MWindow::update_project");
2819 vwindow->gui->unlock_window();
2823 if(debug) PRINT_TRACE
2824 cwindow->gui->lock_window("MWindow::update_project 2");
2825 cwindow->gui->timebar->update(0);
2826 cwindow->gui->unlock_window();
2828 if(debug) PRINT_TRACE
2829 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2834 awindow->gui->async_update_assets();
2835 if(debug) PRINT_TRACE
2837 gui->lock_window("MWindow::update_project");
2839 if(debug) PRINT_TRACE
2842 void MWindow::remove_indexfile(Indexable *indexable)
2844 if( !indexable->is_asset ) return;
2845 Asset *asset = (Asset *)indexable;
2847 IndexFile::delete_index(preferences, asset, ".toc");
2848 IndexFile::delete_index(preferences, asset, ".idx");
2849 IndexFile::delete_index(preferences, asset, ".mkr");
2852 void MWindow::rebuild_indices()
2854 for(int i = 0; i < session->drag_assets->total; i++)
2856 Indexable *indexable = session->drag_assets->get(i);
2857 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2858 remove_indexfile(indexable);
2859 // Schedule index build
2860 IndexState *index_state = indexable->index_state;
2861 index_state->index_status = INDEX_NOTTESTED;
2862 if( indexable->is_asset ) {
2863 Asset *asset = (Asset *)indexable;
2864 if( asset->format != FILE_PCM )
2865 asset->reset_audio();
2866 asset->reset_video();
2868 mainindexes->add_next_asset(0, indexable);
2870 mainindexes->start_build();
2874 void MWindow::save_backup()
2878 edl->set_path(session->filename);
2879 edl->save_xml(&file, BACKUP_PATH, 0, 0);
2880 file.terminate_string();
2881 char path[BCTEXTLEN];
2883 strcpy(path, BACKUP_PATH);
2884 fs.complete_path(path);
2886 if(file.write_to_file(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 string[BCTEXTLEN];
2900 strcpy(string, BACKUP_PATH);
2902 fs.complete_path(string);
2904 path_list.append(out_path = new char[strlen(string) + 1]);
2905 strcpy(out_path, string);
2907 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2908 edl->local_session->clip_title[0] = 0;
2909 // This is unique to backups since the path of the backup is different than the
2910 // path of the project.
2911 set_filename(edl->path);
2912 path_list.remove_all_objects();
2916 static inline int gcd(int m, int n)
2919 if( m < n ) { r = m; m = n; n = r; }
2920 while( (r = m % n) != 0 ) { m = n; n = r; }
2924 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2927 if(!width || !height) return 1;
2928 double ar = (double)width / height;
2929 // square-ish pixels
2930 if( EQUIV(ar, 1.0000) ) return 0;
2931 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2932 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2933 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2934 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2935 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2936 int ww = width, hh = height;
2937 // numerator, denominator must be under mx
2938 int mx = 255, n = gcd(ww, hh);
2939 if( n > 1 ) { ww /= n; hh /= n; }
2940 // search near height in case extra/missing lines
2941 if( ww >= mx || hh >= mx ) {
2942 double err = height; // +/- 2 percent height
2943 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2944 int iw = width, ih = height+i;
2945 if( (n=gcd(iw, ih)) > 1 ) {
2946 int u = iw/n; if( u >= mx ) continue;
2947 int v = ih/n; if( v >= mx ) continue;
2948 double r = (double) u/v, er = fabs(ar-r);
2949 if( er >= err ) continue;
2950 err = er; ww = u; hh = v;
2959 void MWindow::reset_caches()
2961 frame_cache->remove_all();
2962 wave_cache->remove_all();
2963 audio_cache->remove_all();
2964 video_cache->remove_all();
2965 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2966 cwindow->playback_engine->audio_cache->remove_all();
2967 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2968 cwindow->playback_engine->video_cache->remove_all();
2970 for(int i = 0; i < vwindows.size(); i++) {
2971 VWindow *vwindow = vwindows[i];
2972 if( !vwindow->is_running() ) continue;
2973 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2974 vwindow->playback_engine->audio_cache->remove_all();
2975 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2976 vwindow->playback_engine->video_cache->remove_all();
2980 void MWindow::remove_asset_from_caches(Asset *asset)
2982 gui->resource_thread->get_video_source(0);
2983 gui->resource_thread->get_audio_source(0);
2984 frame_cache->remove_asset(asset);
2985 wave_cache->remove_asset(asset);
2986 audio_cache->delete_entry(asset);
2987 video_cache->delete_entry(asset);
2988 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2989 cwindow->playback_engine->audio_cache->delete_entry(asset);
2990 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2991 cwindow->playback_engine->video_cache->delete_entry(asset);
2992 for(int i = 0; i < vwindows.size(); i++) {
2993 VWindow *vwindow = vwindows[i];
2994 if( !vwindow->is_running() ) continue;
2995 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2996 vwindow->playback_engine->audio_cache->delete_entry(asset);
2997 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2998 vwindow->playback_engine->video_cache->delete_entry(asset);
3003 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3004 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3006 for(int i = 0; i < session->drag_assets->total; i++) {
3007 Indexable *indexable = session->drag_assets->get(i);
3008 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3011 // Remove from VWindow.
3012 for(int i = 0; i < session->drag_clips->total; i++) {
3013 for(int j = 0; j < vwindows.size(); j++) {
3014 VWindow *vwindow = vwindows[j];
3015 if( !vwindow->is_running() ) continue;
3016 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3017 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3018 vwindow->delete_source(1, 1);
3019 vwindow->gui->unlock_window();
3024 for(int i = 0; i < session->drag_assets->size(); i++) {
3025 for(int j = 0; j < vwindows.size(); j++) {
3026 VWindow *vwindow = vwindows[j];
3027 if( !vwindow->is_running() ) continue;
3028 if(session->drag_assets->get(i) == vwindow->get_source()) {
3029 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3030 vwindow->delete_source(1, 1);
3031 vwindow->gui->unlock_window();
3036 for(int i = 0; i < session->drag_assets->size(); i++) {
3037 Indexable *indexable = session->drag_assets->get(i);
3038 remove_indexfile(indexable);
3041 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3042 if(push_undo) undo->update_undo_before();
3043 if(drag_assets) edl->remove_from_project(drag_assets);
3044 if(drag_clips) edl->remove_from_project(session->drag_clips);
3045 if(redraw) save_backup();
3046 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3051 gui->lock_window("MWindow::remove_assets_from_project 3");
3059 gui->unlock_window();
3061 // Removes from playback here
3062 sync_parameters(CHANGE_ALL);
3065 awindow->gui->async_update_assets();
3068 void MWindow::remove_assets_from_disk()
3071 for(int i = 0; i < session->drag_assets->total; i++)
3073 remove(session->drag_assets->get(i)->path);
3076 remove_assets_from_project(1,
3078 session->drag_assets,
3079 session->drag_clips);
3082 void MWindow::dump_plugins(FILE *fp)
3084 if( !plugindb ) return;
3085 for(int i = 0; i < plugindb->total; i++)
3087 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3088 " synth=%d transition=%d theme=%d %s\n",
3089 plugindb->get(i)->plugin_type,
3090 plugindb->get(i)->audio,
3091 plugindb->get(i)->video,
3092 plugindb->get(i)->realtime,
3093 plugindb->get(i)->multichannel,
3094 plugindb->get(i)->get_synthesis(),
3095 plugindb->get(i)->transition,
3096 plugindb->get(i)->theme,
3097 plugindb->get(i)->title);
3101 void MWindow::dump_edl(FILE *fp)
3107 void MWindow::dump_undo(FILE *fp)
3113 void MWindow::dump_exe(FILE *fp)
3115 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3116 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3117 int ret = readlink(proc_path, exe_path, sizeof(exe_path));
3118 if( ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3121 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3122 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
3123 int fd = open(exe_path,O_RDONLY+O_NONBLOCK);
3124 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3127 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3128 int64_t maxsz = 1024*pagsz;
3129 int64_t size = st.st_size, pos = 0;
3131 while( (bfrsz = size-pos) > 0 ) {
3132 if( bfrsz > maxsz ) bfrsz = maxsz;
3133 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3134 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3135 if( bfr == MAP_FAILED ) break;
3136 sha1.addBytes(bfr, bfrsz);
3141 ret = pos < size ? EIO : 0;
3142 fprintf(fp, "SHA1: ");
3143 uint8_t digest[20]; sha1.computeHash(digest);
3144 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3145 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3146 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3150 void MWindow::trap_hook(FILE *fp, void *vp)
3152 MWindow *mwindow = (MWindow *)vp;
3153 // fprintf(fp, "\nPLUGINS:\n");
3154 // mwindow->dump_plugins(fp);
3155 fprintf(fp, "\nEDL:\n");
3156 mwindow->dump_edl(fp);
3157 fprintf(fp, "\nUNDO:\n");
3158 mwindow->dump_undo(fp);
3159 fprintf(fp, "\nEXE:\n");
3160 mwindow->dump_exe(fp);
3168 int MWindow::save_defaults()
3170 gui->save_defaults(defaults);
3171 edl->save_defaults(defaults);
3172 session->save_defaults(defaults);
3173 preferences->save_defaults(defaults);
3175 for(int i = 0; i < plugin_guis->total; i++)
3177 // Pointer comparison
3178 plugin_guis->get(i)->save_defaults();
3180 awindow->save_defaults(defaults);
3186 int MWindow::run_script(FileXML *script)
3188 int result = 0, result2 = 0;
3189 while(!result && !result2)
3191 result = script->read_tag();
3194 if(script->tag.title_is("new_project"))
3196 // Run new in immediate mode.
3197 // gui->mainmenu->new_project->run_script(script);
3200 if(script->tag.title_is("record"))
3202 // Run record as a thread. It is a terminal command.
3204 // Will read the complete scipt file without letting record read it if not
3210 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3217 // ================================= synchronization
3220 int MWindow::interrupt_indexes()
3222 mainprogress->cancelled = 1;
3223 mainindexes->interrupt_build();
3229 void MWindow::next_time_format()
3231 switch(edl->session->time_format)
3233 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3234 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3235 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3236 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3237 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3238 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3239 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3242 time_format_common();
3245 void MWindow::prev_time_format()
3247 switch(edl->session->time_format)
3249 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3250 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3251 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3252 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3253 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3254 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3255 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3258 time_format_common();
3261 void MWindow::time_format_common()
3263 gui->lock_window("MWindow::next_time_format");
3264 gui->redraw_time_dependancies();
3267 char string[BCTEXTLEN], string2[BCTEXTLEN];
3268 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3269 gui->show_message(string);
3271 gui->unlock_window();
3275 int MWindow::set_filename(const char *filename)
3277 if( filename != session->filename )
3278 strcpy(session->filename, filename);
3279 if( filename != edl->path )
3280 strcpy(edl->path, filename);
3284 if(filename[0] == 0)
3286 gui->set_title(PROGRAM_NAME);
3291 char string[BCTEXTLEN], string2[BCTEXTLEN];
3292 dir.extract_name(string, filename);
3293 sprintf(string2, PROGRAM_NAME ": %s", string);
3294 gui->set_title(string2);
3307 int MWindow::set_loop_boundaries()
3309 double start = edl->local_session->get_selectionstart();
3310 double end = edl->local_session->get_selectionend();
3318 if(edl->tracks->total_length())
3321 end = edl->tracks->total_length();
3328 if(edl->local_session->loop_playback && start != end)
3330 edl->local_session->loop_start = start;
3331 edl->local_session->loop_end = end;
3342 int MWindow::reset_meters()
3344 cwindow->gui->lock_window("MWindow::reset_meters 1");
3345 cwindow->gui->meters->reset_meters();
3346 cwindow->gui->unlock_window();
3348 for(int j = 0; j < vwindows.size(); j++) {
3349 VWindow *vwindow = vwindows[j];
3350 if( !vwindow->is_running() ) continue;
3351 vwindow->gui->lock_window("MWindow::reset_meters 2");
3352 vwindow->gui->meters->reset_meters();
3353 vwindow->gui->unlock_window();
3356 lwindow->gui->lock_window("MWindow::reset_meters 3");
3357 lwindow->gui->panel->reset_meters();
3358 lwindow->gui->unlock_window();
3360 gui->lock_window("MWindow::reset_meters 4");
3361 gui->reset_meters();
3362 gui->unlock_window();
3367 void MWindow::resync_guis()
3371 gui->lock_window("MWindow::resync_guis");
3372 gui->update(1, 1, 1, 1, 1, 1, 0);
3373 gui->unlock_window();
3375 cwindow->gui->lock_window("MWindow::resync_guis");
3376 cwindow->gui->resize_event(cwindow->gui->get_w(),
3377 cwindow->gui->get_h());
3378 int channels = edl->session->audio_channels;
3379 cwindow->gui->meters->set_meters(channels, 1);
3380 cwindow->gui->flush();
3381 cwindow->gui->unlock_window();
3383 for(int i = 0; i < vwindows.size(); i++) {
3384 VWindow *vwindow = vwindows[i];
3385 if( !vwindow->is_running() ) continue;
3386 vwindow->gui->lock_window("MWindow::resync_guis");
3387 vwindow->gui->resize_event(vwindow->gui->get_w(),
3388 vwindow->gui->get_h());
3389 vwindow->gui->meters->set_meters(channels, 1);
3390 vwindow->gui->flush();
3391 vwindow->gui->unlock_window();
3394 lwindow->gui->lock_window("MWindow::resync_guis");
3395 lwindow->gui->panel->set_meters(channels, 1);
3396 lwindow->gui->flush();
3397 lwindow->gui->unlock_window();
3400 if(((edl->session->output_w % 4) ||
3401 (edl->session->output_h % 4)) &&
3402 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3404 MainError::show_error(
3405 _("This project's dimensions are not multiples of 4 so\n"
3406 "it can't be rendered by OpenGL."));
3411 sync_parameters(CHANGE_ALL);
3414 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3416 File *file = new File;
3417 EDLSession *session = edl->session;
3418 double old_framerate = session->frame_rate;
3419 double old_samplerate = session->sample_rate;
3420 int result = file->open_file(preferences, asset, 1, 0);
3421 if( !result && delete_tracks > 0 )
3422 undo->update_undo_before();
3423 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3424 // try to get asset up to date, may fail
3425 file->select_video_stream(asset, vstream);
3426 // either way use what was/is there.
3427 double framerate = asset->get_frame_rate();
3428 int width = asset->get_w();
3429 int height = asset->get_h();
3430 // must be multiple of 4 for opengl
3431 width = (width+3) & ~3; height = (height+3) & ~3;
3432 int driver = session->playback_config->vconfig->driver;
3433 int color_model = file->get_best_colormodel(asset, driver);
3434 // color_model = BC_CModels::is_yuv(color_model) ?
3435 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3436 // BC_CModels::is_float(color_model) ?
3437 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3438 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3439 // have alpha for now
3440 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3441 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3442 session->color_model = color_model;
3443 session->output_w = width;
3444 session->output_h = height;
3445 session->frame_rate = framerate;
3446 // not, asset->actual_width/actual_height
3447 asset->width = session->output_w;
3448 asset->height = session->output_h;
3449 asset->frame_rate = session->frame_rate;
3450 create_aspect_ratio(session->aspect_w, session->aspect_h,
3451 session->output_w, session->output_h);
3452 Track *track = edl->tracks->first;
3453 for( Track *next_track=0; track; track=next_track ) {
3454 next_track = track->next;
3455 if( track->data_type != TRACK_VIDEO ) continue;
3456 if( delete_tracks ) {
3457 Edit *edit = track->edits->first;
3458 for( Edit *next_edit=0; edit; edit=next_edit ) {
3459 next_edit = edit->next;
3460 if( edit->channel != vstream ||
3461 !edit->asset || !edit->asset->is_asset ||
3462 *asset != *edit->asset )
3466 if( track->edits->first ) {
3467 track->track_w = edl->session->output_w;
3468 track->track_h = edl->session->output_h;
3470 else if( delete_tracks )
3471 edl->tracks->delete_track(track);
3473 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3475 if( !result && asset->audio_data && asset->channels > 0 ) {
3476 session->sample_rate = asset->get_sample_rate();
3477 int64_t channel_mask = 0;
3478 int astrm = !asset->video_data ? -1 :
3479 file->get_audio_for_video(vstream, astream, channel_mask);
3480 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3481 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3483 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3484 if( channels < 1 ) channels = 1;
3485 if( channels > 6 ) channels = 6;
3486 session->audio_tracks = session->audio_channels = channels;
3487 switch( channels ) {
3489 session->achannel_positions[0] = 90;
3490 session->achannel_positions[1] = 150;
3491 session->achannel_positions[2] = 30;
3492 session->achannel_positions[3] = 210;
3493 session->achannel_positions[4] = 330;
3494 session->achannel_positions[5] = 270;
3497 session->achannel_positions[0] = 180;
3498 session->achannel_positions[1] = 0;
3501 session->achannel_positions[1] = 90;
3504 if( !channels ) break;
3505 double t = 0, dt = 360./channels;
3506 for( int i=channels; --i>=0; t+=dt )
3507 session->achannel_positions[i] = int(t+0.5);
3510 remap_audio(MWindow::AUDIO_1_TO_1);
3512 if( delete_tracks ) {
3513 Track *track = edl->tracks->first;
3514 for( Track *next_track=0; track; track=next_track ) {
3515 next_track = track->next;
3516 if( track->data_type != TRACK_AUDIO ) continue;
3517 Edit *edit = track->edits->first;
3518 for( Edit *next_edit=0; edit; edit=next_edit ) {
3519 next_edit = edit->next;
3520 if( !((1<<edit->channel) & channel_mask) ||
3521 !edit->asset || !edit->asset->is_asset ||
3522 *asset != *edit->asset )
3525 if( !track->edits->first )
3526 edl->tracks->delete_track(track);
3530 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3533 if( !result && delete_tracks > 0 ) {
3535 undo->update_undo_after(_("select asset"), LOAD_ALL);
3541 int MWindow::select_asset(int vtrack, int delete_tracks)
3543 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3545 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3546 if( !track ) return 1;
3547 Edit *edit = track->edits->first;
3548 if( !edit ) return 1;
3549 Asset *asset = edit->asset;
3550 if( !asset || !asset->is_asset ) return 1;
3551 return select_asset(asset, edit->channel, 0, delete_tracks);
3554 void MWindow::dump_plugindb(FILE *fp)
3556 if( !plugindb ) return;
3557 for(int i = 0; i < plugindb->total; i++)
3558 plugindb->get(i)->dump(fp);