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
24 #include "audioalsa.h"
26 #include "awindowgui.h"
28 #include "batchrender.h"
29 #include "bcdisplayinfo.h"
30 #include "bcsignals.h"
36 #include "channeldb.h"
37 #include "channelinfo.h"
39 #include "bccmodels.h"
40 #include "commercials.h"
41 #include "cplayback.h"
43 #include "cwindowgui.h"
45 #include "cwindowtool.h"
47 #include "devicedvbinput.inc"
48 #include "dvdcreate.h"
49 #include "editpanel.h"
51 #include "edlsession.h"
53 #include "fileformat.h"
55 #include "filesystem.h"
57 #include "floatautos.h"
58 #include "framecache.h"
60 #include "gwindowgui.h"
61 #include "keyframegui.h"
62 #include "indexfile.h"
64 #include "interlacemodes.h"
66 #include "levelwindowgui.h"
67 #include "levelwindow.h"
68 #include "loadfile.inc"
69 #include "localsession.h"
70 #include "maincursor.h"
71 #include "mainerror.h"
72 #include "mainindexes.h"
74 #include "mainprogress.h"
75 #include "mainsession.h"
79 #include "mwindowgui.h"
81 #include "nestededls.h"
85 #include "playback3d.h"
86 #include "playbackengine.h"
88 #include "pluginserver.h"
89 #include "pluginset.h"
90 #include "preferences.h"
92 #include "recordmonitor.h"
93 #include "recordlabel.h"
94 #include "removefile.h"
96 #include "resourcethread.h"
97 #include "samplescroll.h"
99 #include "sighandler.h"
100 #include "splashgui.h"
101 #include "statusbar.h"
103 #include "threadloader.h"
105 #include "tipwindow.h"
106 #include "trackcanvas.h"
108 #include "tracking.h"
109 #include "trackscroll.h"
111 #include "transition.h"
112 #include "transportque.h"
115 #include "versioninfo.h"
116 #include "videodevice.inc"
117 #include "videowindow.h"
118 #include "vplayback.h"
119 #include "vwindowgui.h"
121 #include "wavecache.h"
124 #include "exportedl.h"
126 #include "defaultformats.h"
127 #include "ntsczones.h"
134 #include <sys/types.h>
135 #include <sys/stat.h>
136 #include <sys/time.h>
137 #include <sys/mman.h>
148 // Hack for libdv to remove glib dependancy
151 // g_log (const char *log_domain,
153 // const char *format,
159 // g_logv (const char *log_domain,
161 // const char *format,
171 ArrayList<PluginServer*>* MWindow::plugindb = 0;
172 Commercials* MWindow::commercials = 0;
178 run_lock = new Mutex("MWindow::run_lock");
179 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
180 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
181 vwindows_lock = new Mutex("MWindow::vwindows_lock");
182 brender_lock = new Mutex("MWindow::brender_lock");
183 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
191 commercial_active = 0;
202 channeldb_buz = new ChannelDB;
203 channeldb_v4l2jpeg = new ChannelDB;
207 keyframe_threads = 0;
227 // Need to delete brender temporary here.
230 run_lock->lock("MWindow::~MWindow");
232 //printf("MWindow::~MWindow %d\n", __LINE__);
234 gui->remote_control->deactivate();
237 gui->channel_info->stop();
239 delete create_bd; create_bd = 0;
240 delete create_dvd; create_dvd = 0;
241 delete batch_render; batch_render = 0;
242 delete render; render = 0;
244 if( commercials && !commercials->remove_user() ) commercials = 0;
246 // Save defaults for open plugins
247 plugin_gui_lock->lock("MWindow::~MWindow");
248 for(int i = 0; i < plugin_guis->size(); i++) {
249 plugin_guis->get(i)->hide_gui();
250 delete_plugin(plugin_guis->get(i));
252 plugin_gui_lock->unlock();
253 hide_keyframe_guis();
256 // Give up and go to a movie
257 // cant run valgrind if this is used
259 gui->del_keyboard_listener(
260 (int (BC_WindowBase::*)(BC_WindowBase *))
261 &MWindowGUI::keyboard_listener);
263 // release the hounds
264 if( awindow && awindow->gui ) awindow->gui->close(0);
265 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
266 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
267 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
268 if( twindow && twindow->is_running() ) twindow->close_window();
269 if( wwindow && wwindow->is_running() ) wwindow->close_window();
270 vwindows.remove_all_objects();
272 if( awindow ) awindow->join();
273 if( cwindow ) cwindow->join();
274 if( lwindow ) lwindow->join();
275 if( twindow ) twindow->join();
276 if( wwindow ) wwindow->join();
277 if( gwindow ) gwindow->join();
280 // one at a time, or nouveau chokes
281 #define close_gui(win) if( win ) { \
282 if( win->gui ) win->gui->close(0); \
290 vwindows.remove_all_objects();
295 dead_plugins->remove_all_objects();
298 keyframe_threads->remove_all_objects();
299 colormodels.remove_all_objects();
300 delete awindow; awindow = 0;
301 delete lwindow; lwindow = 0;
302 delete twindow; twindow = 0;
303 delete wwindow; wwindow = 0;
304 delete gwindow; gwindow = 0;
305 delete cwindow; cwindow = 0;
307 //delete file_server; file_server = 0; // reusable
308 delete mainindexes; mainindexes = 0;
309 delete mainprogress; mainprogress = 0;
310 delete audio_cache; audio_cache = 0; // delete the cache after the assets
311 delete video_cache; video_cache = 0; // delete the cache after the assets
312 delete frame_cache; frame_cache = 0;
313 delete wave_cache; wave_cache = 0;
314 delete plugin_guis; plugin_guis = 0;
315 delete dead_plugins; dead_plugins = 0;
316 delete keyframe_threads; keyframe_threads = 0;
317 delete undo; undo = 0;
318 delete preferences; preferences = 0;
319 delete exportedl; exportedl = 0;
320 delete session; session = 0;
321 delete defaults; defaults = 0;
322 delete assets; assets = 0;
323 delete splash_window; splash_window = 0;
324 // delete theme; theme = 0; // deleted by delete_plugins
325 if( !edl->Garbage::remove_user() ) edl = 0;
326 delete channeldb_buz;
327 delete channeldb_v4l2jpeg;
328 // This must be last thread to exit
329 delete playback_3d; playback_3d = 0;
330 delete dead_plugin_lock;
331 delete plugin_gui_lock;
332 delete vwindows_lock;
334 delete keyframe_gui_lock;
335 colormodels.remove_all_objects();
336 interlace_project_modes.remove_all_objects();
337 interlace_asset_modes.remove_all_objects();
338 interlace_asset_fixmethods.remove_all_objects();
339 sighandler->terminate();
350 void MWindow::init_error()
352 MainError::init_error(this);
355 void MWindow::finit_error()
357 MainError::finit_error();
360 void MWindow::create_defaults_path(char *string, const char *config_file)
362 // set the .bcast path
365 sprintf(string, "%s/", File::get_config_path());
366 fs.complete_path(string);
367 if(!fs.is_dir(string))
368 fs.create_dir(string);
371 strcat(string, config_file);
373 const char *MWindow::default_std()
375 char buf[BCTEXTLEN], *p = 0;
377 int fd = open(TIMEZONE_NAME, O_RDONLY);
379 int l = read(fd, buf, sizeof(buf)-1);
382 if( buf[l-1] == '\n' ) --l;
388 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
391 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
392 p += strlen(ZONEINFO_STR);
397 for( int i=0; ntsc_zones[i]; ++i ) {
398 if( !strcmp(ntsc_zones[i], p) )
405 for( int i=0; ntsc_zones[i]; ++i ) {
406 if( !strcmp(ntsc_zones[i], p) )
411 //__timezone: Seconds west of UTC. 240sec/deg
412 double tz_deg = -__timezone / 240.;
413 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
414 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
417 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
419 struct formatpresets *fpr;
421 for(fpr = &format_presets[0]; fpr->name; fpr++)
423 if(strcmp(_(fpr->name), preset) == 0)
425 session->audio_channels = fpr->audio_channels;
426 session->audio_tracks = fpr->audio_tracks;
427 session->sample_rate = fpr->sample_rate;
428 session->video_channels = fpr->video_channels;
429 session->video_tracks = fpr->video_tracks;
430 session->frame_rate = fpr->frame_rate;
431 session->output_w = fpr->output_w;
432 session->output_h = fpr->output_h;
433 session->aspect_w = fpr->aspect_w;
434 session->aspect_h = fpr->aspect_h;
435 session->interlace_mode = fpr->interlace_mode;
436 session->color_model = fpr->color_model;
442 const char *MWindow::get_preset_name(int index)
444 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
446 return _(format_presets[index].name);
450 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
452 char path[BCTEXTLEN];
453 // Use user supplied path
455 strcpy(path, config_path);
457 create_defaults_path(path, CONFIG_FILE);
459 defaults = new BC_Hash(path);
463 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
465 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
467 const char *dp = plug_dir;
468 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
469 bp = !*dp && *bp == '/' ? bp+1 : base_path;
475 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
478 FILE *fp = fopen(index_path, "r");
482 char index_line[BCTEXTLEN];
483 int index_version = -1, len = strlen(plugin_dir);
484 if( !fgets(index_line, BCTEXTLEN, fp) ||
485 sscanf(index_line, "%d", &index_version) != 1 ||
486 index_version != PLUGIN_FILE_VERSION ||
487 !fgets(index_line, BCTEXTLEN, fp) ||
488 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
489 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
491 ArrayList<PluginServer*> plugins;
492 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
493 if( index_line[0] == ';' ) continue;
494 if( index_line[0] == '#' ) continue;
495 int type = PLUGIN_TYPE_UNKNOWN;
496 char path[BCTEXTLEN], title[BCTEXTLEN];
498 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
501 PluginServer *server = 0;
503 case PLUGIN_TYPE_BUILTIN:
504 case PLUGIN_TYPE_EXECUTABLE:
505 case PLUGIN_TYPE_LADSPA: {
506 char plugin_path[BCTEXTLEN]; struct stat st;
507 sprintf(plugin_path, "%s/%s", plugin_dir, path);
508 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
511 server = new PluginServer(mwindow, plugin_path, type);
513 case PLUGIN_TYPE_FFMPEG: {
514 server = new_ffmpeg_server(mwindow, path);
517 if( !server ) continue;
518 plugins.append(server);
519 // Create plugin server from index entry
520 server->set_title(title);
521 if( server->read_table(index_line) ) {
528 ret = check_plugin_index(plugins, plugin_dir, ".");
531 add_plugins(plugins);
533 plugins.remove_all_objects();
538 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
539 const char *plug_dir, const char *plug_path)
541 char plugin_path[BCTEXTLEN];
542 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
544 fs.set_filter( "[*.plugin][*.so]" );
545 if( fs.update(plugin_path) )
548 for( int i=0; i<fs.dir_list.total; ++i ) {
549 char fs_path[BCTEXTLEN];
550 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
551 if( fs.is_dir(fs_path) ) {
552 get_plugin_path(plugin_path, plug_dir, fs_path);
553 if( check_plugin_index(plugins, plug_dir, plugin_path) )
556 else if( !plugin_exists(fs_path, plugins) )
563 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
566 plugindb = new ArrayList<PluginServer*>;
568 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
569 create_defaults_path(index_path, PLUGIN_FILE);
570 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
571 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
572 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
573 printf("init plugin index: %s\n", plugin_path);
574 FILE *fp = fopen(index_path,"w");
576 fprintf(stderr,_("MWindow::init_plugins: "
577 "can't create plugin index: %s\n"), index_path);
580 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
581 fprintf(fp, "%s\n", plugin_path);
582 init_plugin_index(mwindow, preferences, fp, plugin_path);
583 init_ffmpeg_index(mwindow, preferences, fp);
585 return load_plugin_index(mwindow, index_path, plugin_path);
588 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
590 char *path = getenv("LADSPA_PATH");
591 char ladspa_path[BCTEXTLEN];
593 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
596 for( int len=0; *path; path+=len ) {
597 char *cp = strchr(path,':');
598 len = !cp ? strlen(path) : cp-path;
599 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
600 memcpy(plugin_path, path, len); plugin_path[len] = 0;
601 char *plugin_dir = FileSystem::basepath(plugin_path);
602 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
603 create_defaults_path(index_path, LADSPA_FILE);
604 cp = index_path + strlen(index_path);
605 for( char *bp=plugin_path; *bp!=0; ++bp )
606 *cp++ = *bp=='/' ? '_' : *bp;
608 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
609 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
610 load_plugin_index(mwindow, index_path, plugin_path);
615 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
616 FILE *fp, const char *plugin_dir)
618 int idx = PLUGIN_IDS;
620 for( int i=0; i<plugindb->size(); ++i ) {
621 PluginServer *server = plugindb->get(i);
622 if( server->dir_idx >= idx )
623 idx = server->dir_idx+1;
626 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
629 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
630 const char *index_path, const char *plugin_dir)
632 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
633 strcpy(plugin_path, path); delete [] path;
634 printf("init ladspa index: %s\n", plugin_dir);
635 FILE *fp = fopen(index_path,"w");
637 fprintf(stderr,_("MWindow::init_ladspa_index: "
638 "can't create plugin index: %s\n"), index_path);
641 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
642 fprintf(fp, "%s\n", plugin_dir);
643 init_plugin_index(mwindow, preferences, fp, plugin_path);
648 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
649 const char *plug_dir, const char *plug_path, int &idx)
651 char plugin_path[BCTEXTLEN];
652 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
654 fs.set_filter( "[*.plugin][*.so]" );
655 int result = fs.update(plugin_path);
656 if( result || !fs.dir_list.total ) return;
659 for( int i=0; i<fs.dir_list.total; ++i ) {
660 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
661 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
662 get_plugin_path(path, plug_dir, fs_path);
663 if( fs.is_dir(fs_path) ) {
664 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
667 if( plugin_exists(path) ) continue;
669 if( stat(fs_path, &st) ) continue;
670 int64_t mtime = st.st_mtime;
671 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
672 result = server.open_plugin(1, preferences, 0, 0);
674 server.write_table(fp, path, vis_id, mtime);
675 server.close_plugin();
677 else if( result == PLUGINSERVER_IS_LAD ) {
680 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
681 ladspa.set_lad_index(lad_index++);
682 result = ladspa.open_plugin(1, preferences, 0, 0);
684 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
685 ladspa.close_plugin();
691 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
693 for( int i=0; i<plugins.size(); ++i )
694 plugindb->append(plugins[i]);
695 plugins.remove_all();
698 void MWindow::delete_plugins()
700 plugindb->remove_all_objects();
705 void MWindow::search_plugindb(int do_audio,
710 ArrayList<PluginServer*> &results)
713 for(int i = 0; i < MWindow::plugindb->total; i++)
715 PluginServer *current = MWindow::plugindb->get(i);
717 if(current->audio == do_audio &&
718 current->video == do_video &&
719 (current->realtime == is_realtime || is_realtime < 0) &&
720 current->transition == is_transition &&
721 current->theme == is_theme)
722 results.append(current);
725 // Alphabetize list by title
731 for(int i = 0; i < results.total - 1; i++)
733 PluginServer *value1 = results[i];
734 PluginServer *value2 = results[i + 1];
735 if(strcmp(_(value1->title), _(value2->title)) > 0)
739 results[i + 1] = value1;
745 PluginServer* MWindow::scan_plugindb(char *title,
750 // printf("MWindow::scan_plugindb data_type < 0\n");
754 for(int i = 0; i < plugindb->total; i++)
756 PluginServer *server = plugindb->get(i);
758 !strcasecmp(server->title, title) &&
760 (data_type == TRACK_AUDIO && server->audio) ||
761 (data_type == TRACK_VIDEO && server->video)))
762 return plugindb->get(i);
767 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
769 for( int i=0; i<plugins.size(); ++i )
770 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
774 int MWindow::plugin_exists(char *plugin_path)
776 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
779 void MWindow::init_preferences()
781 preferences = new Preferences;
782 preferences->load_defaults(defaults);
783 session = new MainSession(this);
784 session->load_defaults(defaults);
785 // set x11_host, screens, window_config
786 screens = session->set_default_x11_host();
787 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
788 BC_Signals::set_trap_hook(trap_hook, this);
789 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
790 BC_Signals::set_catch_intr(preferences->trap_sigintr);
791 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
794 void MWindow::clean_indexes()
799 int oldest_item = -1;
801 char string[BCTEXTLEN];
802 char string2[BCTEXTLEN];
804 // Delete extra indexes
805 fs.set_filter("*.idx");
806 fs.complete_path(preferences->index_directory);
807 fs.update(preferences->index_directory);
808 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
810 // Eliminate directories
815 for(int i = 0; i < fs.dir_list.total && !result; i++)
817 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
818 if(fs.is_dir(string))
820 delete fs.dir_list[i];
821 fs.dir_list.remove_number(i);
826 total_excess = fs.dir_list.total - preferences->index_count;
828 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
829 while(total_excess > 0)
832 for(int i = 0; i < fs.dir_list.total; i++)
834 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
836 if(i == 0 || fs.get_date(string) <= oldest)
838 oldest = fs.get_date(string);
846 fs.join_names(string,
847 preferences->index_directory,
848 fs.dir_list[oldest_item]->name);
849 //printf("MWindow::clean_indexes 1 %s\n", string);
851 perror("delete_indexes");
852 delete fs.dir_list[oldest_item];
853 fs.dir_list.remove_number(oldest_item);
855 // Remove table of contents if it exists
856 strcpy(string2, string);
857 char *ptr = strrchr(string2, '.');
860 //printf("MWindow::clean_indexes 2 %s\n", string2);
861 sprintf(ptr, ".toc");
863 sprintf(ptr, ".mkr");
872 void MWindow::init_awindow()
874 awindow = new AWindow(this);
875 awindow->create_objects();
878 void MWindow::init_gwindow()
880 gwindow = new GWindow(this);
881 gwindow->create_objects();
884 void MWindow::init_tipwindow()
887 twindow = new TipWindow(this);
891 void MWindow::show_warning(int *do_warning, const char *text)
893 if( do_warning && !*do_warning ) return;
895 wwindow = new WWindow(this);
896 wwindow->show_warning(do_warning, text);
899 int MWindow::wait_warning()
901 return wwindow->wait_result();
904 void MWindow::init_theme()
909 PluginServer *theme_plugin = 0;
910 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
911 if( plugindb->get(i)->theme &&
912 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
913 theme_plugin = plugindb->get(i);
917 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
920 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
921 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
923 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
924 if( plugindb->get(i)->theme &&
925 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
926 theme_plugin = plugindb->get(i);
931 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
935 PluginServer *plugin = new PluginServer(*theme_plugin);
936 if( plugin->open_plugin(0, preferences, 0, 0) ) {
937 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
938 theme_plugin->title);
942 theme = plugin->new_theme();
943 theme->mwindow = this;
944 strcpy(theme->path, plugin->path);
947 // Load default images & settings
948 theme->Theme::initialize();
949 // Load user images & settings
951 // Create menus with user colors
952 theme->build_menus();
957 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
960 void MWindow::init_3d()
962 playback_3d = new Playback3D(this);
963 playback_3d->create_objects();
966 void MWindow::init_edl()
969 edl->create_objects();
970 fill_preset_defaults(default_standard, edl->session);
971 edl->load_defaults(defaults);
972 edl->create_default_tracks();
973 edl->tracks->update_y_pixels(theme);
976 void MWindow::init_compositor()
978 cwindow = new CWindow(this);
979 cwindow->create_objects();
982 void MWindow::init_levelwindow()
984 lwindow = new LevelWindow(this);
985 lwindow->create_objects();
988 VWindow *MWindow::get_viewer(int start_it, int idx)
990 vwindows_lock->lock("MWindow::get_viewer");
991 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
992 if( !vwindow ) idx = vwindows.size();
993 while( !vwindow && --idx >= 0 ) {
994 VWindow *vwin = vwindows[idx];
995 if( !vwin->is_running() || !vwin->get_edl() )
999 vwindow = new VWindow(this);
1000 vwindow->load_defaults();
1001 vwindow->create_objects();
1002 vwindows.append(vwindow);
1004 vwindows_lock->unlock();
1005 if( start_it ) vwindow->start();
1009 void MWindow::init_cache()
1011 audio_cache = new CICache(preferences);
1012 video_cache = new CICache(preferences);
1013 frame_cache = new FrameCache;
1014 wave_cache = new WaveCache;
1017 void MWindow::init_channeldb()
1019 channeldb_buz->load("channeldb_buz");
1020 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1023 void MWindow::init_menus()
1025 char string[BCTEXTLEN];
1028 BC_CModels::to_text(string, BC_RGB888);
1029 colormodels.append(new ColormodelItem(string, BC_RGB888));
1030 BC_CModels::to_text(string, BC_RGBA8888);
1031 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1032 // BC_CModels::to_text(string, BC_RGB161616);
1033 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1034 // BC_CModels::to_text(string, BC_RGBA16161616);
1035 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1036 BC_CModels::to_text(string, BC_RGB_FLOAT);
1037 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1038 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1039 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1040 BC_CModels::to_text(string, BC_YUV888);
1041 colormodels.append(new ColormodelItem(string, BC_YUV888));
1042 BC_CModels::to_text(string, BC_YUVA8888);
1043 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1044 // BC_CModels::to_text(string, BC_YUV161616);
1045 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1046 // BC_CModels::to_text(string, BC_YUVA16161616);
1047 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1049 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1050 interlace_project_modes.append(new InterlacemodeItem(string, x));
1052 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1053 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1055 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1056 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1058 // Interlacing Modes
1059 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1061 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1062 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1064 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1065 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1067 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1068 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1070 // Interlacing Fixing Methods
1071 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1072 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1073 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1076 void MWindow::init_indexes()
1078 mainindexes = new MainIndexes(this);
1079 mainindexes->start_loop();
1082 void MWindow::init_gui()
1084 gui = new MWindowGUI(this);
1085 gui->lock_window("MWindow::init_gui");
1086 gui->create_objects();
1087 gui->unlock_window();
1088 gui->load_defaults(defaults);
1091 void MWindow::init_signals()
1093 sighandler = new SigHandler;
1094 sighandler->initialize();
1098 void MWindow::init_render()
1100 render = new Render(this);
1101 create_bd = new CreateBD_Thread(this);
1102 create_dvd = new CreateDVD_Thread(this);
1103 batch_render = new BatchRenderThread(this);
1106 void MWindow::init_exportedl()
1108 exportedl = new ExportEDL(this);
1111 void MWindow::init_brender()
1113 if(preferences->use_brender && !brender)
1115 brender_lock->lock("MWindow::init_brender 1");
1116 brender = new BRender(this);
1117 brender->initialize();
1118 session->brender_end = 0;
1119 brender_lock->unlock();
1122 if(!preferences->use_brender && brender)
1124 brender_lock->lock("MWindow::init_brender 2");
1127 session->brender_end = 0;
1128 brender_lock->unlock();
1130 if(brender) brender->restart(edl);
1133 void MWindow::restart_brender()
1135 //printf("MWindow::restart_brender 1\n");
1136 if(brender) brender->restart(edl);
1139 void MWindow::stop_brender()
1141 if(brender) brender->stop();
1144 int MWindow::brender_available(int position)
1147 brender_lock->lock("MWindow::brender_available 1");
1150 if(brender->map_valid)
1152 brender->map_lock->lock("MWindow::brender_available 2");
1153 if(position < brender->map_size &&
1156 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1157 if(brender->map[position] == BRender::RENDERED)
1160 brender->map_lock->unlock();
1163 brender_lock->unlock();
1167 void MWindow::set_brender_start()
1169 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1171 gui->draw_overlays(1);
1175 int MWindow::has_commercials()
1177 return theme->use_commercials;
1180 void MWindow::init_commercials()
1182 if( !commercials ) {
1183 commercials = new Commercials(this);
1184 commercial_active = 0;
1187 commercials->add_user();
1190 void MWindow::commit_commercial()
1192 if( !commercial_active ) return;
1193 commercial_active = 0;
1194 if( !commercials ) return;
1195 commercials->commitDb();
1198 void MWindow::undo_commercial()
1200 if( !commercial_active ) return;
1201 commercial_active = 0;
1202 if( !commercials ) return;
1203 commercials->undoDb();
1206 int MWindow::put_commercial()
1208 double start = edl->local_session->get_selectionstart();
1209 double end = edl->local_session->get_selectionend();
1210 if( start >= end ) return 0;
1212 const char *errmsg = 0;
1214 Tracks *tracks = edl->tracks;
1217 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1218 if( track->data_type != TRACK_VIDEO ) continue;
1219 if( !track->record ) continue;
1220 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1222 int64_t units_start = track->to_units(start,0);
1223 int64_t units_end = track->to_units(end,0);
1224 Edits *edits = track->edits;
1225 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1226 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1227 if(!edit1 && !edit2) continue; // nothing selected
1228 if(!edit2) { // edit2 beyond end of track
1229 edit2 = edits->last;
1230 units_end = edits->length();
1232 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1233 Indexable *indexable = edit1->get_source();
1234 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1237 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1238 if( track->data_type != TRACK_VIDEO ) continue;
1239 if( !track->record ) continue;
1240 int64_t units_start = track->to_units(start,0);
1241 int64_t units_end = track->to_units(end,0);
1242 Edits *edits = track->edits;
1243 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1244 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1245 if(!edit1 && !edit2) continue; // nothing selected
1246 if(!edit2) { // edit2 beyond end of track
1247 edit2 = edits->last;
1248 units_end = edits->length();
1250 Indexable *indexable = edit1->get_source();
1251 Asset *asset = (Asset *)indexable;
1252 File *file = video_cache->check_out(asset, edl);
1253 if( !file ) { errmsg = _("no file"); break; }
1254 int64_t edit_length = units_end - units_start;
1255 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1256 result = commercials->put_clip(file, edit1->channel,
1257 track->from_units(edit_start), track->from_units(edit_length));
1258 video_cache->check_in(asset);
1259 if( result ) { errmsg = _("db failed"); break; }
1262 char string[BCTEXTLEN];
1263 sprintf(string, _("put_commercial: %s"), errmsg);
1264 MainError::show_error(string);
1271 void MWindow::stop_playback(int wait)
1273 int locked = gui->get_window_lock();
1274 if( locked ) gui->unlock_window();
1276 cwindow->playback_engine->que->send_command(STOP,
1280 cwindow->playback_engine->interrupt_playback(wait);
1282 for(int i = 0; i < vwindows.size(); i++) {
1283 VWindow *vwindow = vwindows[i];
1284 if( !vwindow->is_running() ) continue;
1285 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1286 vwindow->playback_engine->interrupt_playback(wait);
1288 if( locked ) gui->lock_window("MWindow::stop_playback");
1291 int MWindow::load_filenames(ArrayList<char*> *filenames,
1293 int update_filename)
1295 ArrayList<EDL*> new_edls;
1296 ArrayList<Asset*> new_assets;
1297 ArrayList<File*> new_files;
1298 const int debug = 0;
1299 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1302 gui->start_hourglass();
1304 // Need to stop playback since tracking depends on the EDL not getting
1308 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1309 undo->update_undo_before();
1312 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1314 // Define new_edls and new_assets to load
1315 int result = 0, ftype = -1;
1316 for(int i = 0; i < filenames->size(); i++)
1319 File *new_file = new File;
1320 Asset *new_asset = new Asset(filenames->get(i));
1321 EDL *new_edl = new EDL;
1322 char string[BCTEXTLEN];
1324 new_edl->create_objects();
1325 new_edl->copy_session(edl);
1326 new_file->set_program(edl->session->program_no);
1328 sprintf(string, _("Loading %s"), new_asset->path);
1329 gui->show_message(string);
1330 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1332 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1333 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1338 // Convert media file to EDL
1340 // Warn about odd image dimensions
1341 if(new_asset->video_data &&
1342 ((new_asset->width % 2) ||
1343 (new_asset->height % 2)))
1345 char string[BCTEXTLEN];
1346 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1350 MainError::show_error(string);
1353 if(new_asset->program >= 0 &&
1354 edl->session->program_no != new_asset->program)
1356 char string[BCTEXTLEN];
1357 sprintf(string, _("%s's index was built for program number %d\n"
1358 "Playback preference is %d.\n Using program %d."),
1359 new_asset->path, new_asset->program,
1360 edl->session->program_no, new_asset->program);
1361 MainError::show_error(string);
1365 if(load_mode != LOADMODE_RESOURCESONLY)
1368 RecordLabels *labels = edl->session->label_cells ?
1369 new RecordLabels(new_file) : 0;
1371 asset_to_edl(new_edl, new_asset, labels);
1373 new_edls.append(new_edl);
1375 new_asset->Garbage::remove_user();
1381 new_assets.append(new_asset);
1385 // Set filename to nothing for assets since save EDL would overwrite them.
1386 if(load_mode == LOADMODE_REPLACE ||
1387 load_mode == LOADMODE_REPLACE_CONCATENATE)
1390 // Reset timeline position
1391 for(int i = 0; i < TOTAL_PANES; i++)
1393 new_edl->local_session->view_start[i] = 0;
1394 new_edl->local_session->track_start[i] = 0;
1402 case FILE_NOT_FOUND:
1403 sprintf(string, _("Failed to open %s"), new_asset->path);
1404 gui->show_message(string, theme->message_error);
1408 case FILE_UNRECOGNIZED_CODEC:
1411 IndexFile indexfile(this, new_asset);
1412 result = indexfile.open_index();
1415 indexfile.close_index();
1418 // Test existing EDLs
1419 for(int j = 0; result && j <= new_edls.total; j++) {
1420 Asset *old_asset = j < new_edls.total ?
1421 new_edls[j]->assets->get_asset(new_asset->path) :
1422 edl->assets->get_asset(new_asset->path);
1424 *new_asset = *old_asset;
1432 char string[BCTEXTLEN];
1434 fs.extract_name(string, new_asset->path);
1436 strcat(string, _("'s format couldn't be determined."));
1437 new_asset->audio_data = 1;
1438 new_asset->format = FILE_PCM;
1439 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1440 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1441 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1442 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1443 new_asset->signed_ = defaults->get("SIGNED_", 1);
1444 new_asset->header = defaults->get("HEADER", 0);
1446 FileFormat fwindow(this);
1447 fwindow.create_objects(new_asset, string);
1448 result = fwindow.run_window();
1451 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1452 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1453 defaults->update("AUDIO_BITS", new_asset->bits);
1454 defaults->update("BYTE_ORDER", new_asset->byte_order);
1455 defaults->update("SIGNED_", new_asset->signed_);
1456 defaults->update("HEADER", new_asset->header);
1463 // Recalculate length
1465 new_file = new File;
1466 result = new_file->open_file(preferences, new_asset, 1, 0);
1468 if(load_mode != LOADMODE_RESOURCESONLY)
1470 RecordLabels *labels = edl->session->label_cells ?
1471 new RecordLabels(new_file) : 0;
1472 asset_to_edl(new_edl, new_asset, labels);
1473 new_edls.append(new_edl);
1474 new_asset->Garbage::remove_user();
1480 new_assets.append(new_asset);
1494 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1495 xml_file.read_from_file(filenames->get(i));
1496 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1497 const char *cin_version = 0;
1498 while( !xml_file.read_tag() ) {
1499 if( xml_file.tag.title_is("EDL") ) {
1500 cin_version = xml_file.tag.get_property("VERSION");
1505 if( !cin_version ) {
1506 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1507 char string[BCTEXTLEN];
1508 sprintf(string,_("Unknown %s"), filenames->get(i));
1509 gui->show_message(string);
1513 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1514 char string[BCTEXTLEN];
1515 snprintf(string, sizeof(string),
1516 _("Warning: XML from cinelerra version %s\n"
1517 "Session data may be incompatible."), cin_version);
1518 show_warning(&preferences->warn_version, string);
1520 if(load_mode == LOADMODE_NESTED)
1522 // Load temporary EDL for nesting.
1523 EDL *nested_edl = new EDL;
1524 nested_edl->create_objects();
1525 nested_edl->set_path(filenames->get(i));
1526 nested_edl->load_xml(&xml_file, LOAD_ALL);
1527 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1528 edl_to_nested(new_edl, nested_edl);
1529 nested_edl->Garbage::remove_user();
1533 // Load EDL for pasting
1534 new_edl->load_xml(&xml_file, LOAD_ALL);
1535 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1536 test_plugins(new_edl, filenames->get(i));
1537 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1539 if(load_mode == LOADMODE_REPLACE ||
1540 load_mode == LOADMODE_REPLACE_CONCATENATE)
1542 strcpy(session->filename, filenames->get(i));
1543 strcpy(new_edl->local_session->clip_title,
1546 set_filename(new_edl->local_session->clip_title);
1550 new_edls.append(new_edl);
1556 // edls are in new_edls
1557 if( result && new_edl ) new_edl->Garbage::remove_user();
1558 // assets are copied
1559 if( new_asset ) new_asset->Garbage::remove_user();
1561 // Store for testing index
1562 new_files.append(new_file);
1565 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1568 if(!result) gui->statusbar->default_message();
1576 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1579 // Don't back up here.
1582 // For pasting, clear the active region
1583 if(load_mode == LOADMODE_PASTE ||
1584 load_mode == LOADMODE_NESTED)
1586 double start = edl->local_session->get_selectionstart();
1587 double end = edl->local_session->get_selectionend();
1588 if(!EQUIV(start, end))
1591 edl->session->labels_follow_edits,
1592 edl->session->plugins_follow_edits,
1593 edl->session->autos_follow_edits);
1596 paste_edls(&new_edls,
1600 edl->session->labels_follow_edits,
1601 edl->session->plugins_follow_edits,
1602 edl->session->autos_follow_edits,
1609 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1611 // Add new assets to EDL and schedule assets for index building.
1612 int got_indexes = 0;
1613 for(int i = 0; i < new_edls.size(); i++)
1615 EDL *new_edl = new_edls[i];
1616 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1618 mainindexes->add_next_asset(0,
1619 new_edl->nested_edls->get(j));
1621 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1626 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1627 if(new_assets.size())
1629 for(int i = 0; i < new_assets.size(); i++)
1631 Asset *new_asset = new_assets[i];
1635 for(int j = 0; j < new_files.size(); j++)
1637 new_file = new_files[j];
1638 if(!strcmp(new_file->asset->path,
1646 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1648 edl->assets->update(new_asset);
1654 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1656 // Start examining next batch of index files
1657 if(got_indexes) mainindexes->start_build();
1658 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1661 Track *track = edl->tracks->first;
1664 for(int j = 0; j < track->plugin_set.size(); j++)
1666 PluginSet *plugins = track->plugin_set[j];
1667 Plugin *plugin = plugins->get_first_plugin();
1671 if(load_mode == LOADMODE_REPLACE ||
1672 load_mode == LOADMODE_REPLACE_CONCATENATE)
1674 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1677 show_plugin(plugin);
1685 plugin = (Plugin*)plugin->next;
1689 track = track->next;
1692 // if just opening one new resource in replace mode
1693 if( ftype != FILE_IS_XML &&
1694 ( load_mode == LOADMODE_REPLACE ||
1695 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1697 edl->local_session->preview_start = 0;
1698 edl->local_session->preview_end = edl->tracks->total_playable_length();
1699 edl->local_session->loop_playback = 0;
1700 edl->local_session->set_selectionstart(0);
1701 edl->local_session->set_selectionend(0);
1706 // need to update undo before project, since mwindow is unlocked & a new load
1707 // can begin here. Should really prevent loading until we're done.
1708 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1709 undo->update_undo_after(_("load"), LOAD_ALL);
1711 for(int i = 0; i < new_edls.size(); i++)
1713 new_edls[i]->remove_user();
1715 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1717 new_edls.remove_all();
1719 for(int i = 0; i < new_assets.size(); i++)
1721 new_assets[i]->Garbage::remove_user();
1724 new_assets.remove_all();
1725 new_files.remove_all_objects();
1728 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1729 if(load_mode == LOADMODE_REPLACE ||
1730 load_mode == LOADMODE_REPLACE_CONCATENATE)
1732 session->changes_made = 0;
1736 session->changes_made = 1;
1739 gui->stop_hourglass();
1742 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1743 update_project(load_mode);
1745 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1753 void MWindow::test_plugins(EDL *new_edl, char *path)
1755 char string[BCTEXTLEN];
1757 // Do a check weather plugins exist
1758 for(Track *track = new_edl->tracks->first; track; track = track->next)
1760 for(int k = 0; k < track->plugin_set.total; k++)
1762 PluginSet *plugin_set = track->plugin_set[k];
1763 for(Plugin *plugin = (Plugin*)plugin_set->first;
1765 plugin = (Plugin*)plugin->next)
1767 if(plugin->plugin_type == PLUGIN_STANDALONE)
1769 // ok we need to find it in plugindb
1770 int plugin_found = 0;
1772 for(int j = 0; j < plugindb->size(); j++)
1774 PluginServer *server = plugindb->get(j);
1776 !strcasecmp(server->title, plugin->title) &&
1777 ((track->data_type == TRACK_AUDIO && server->audio) ||
1778 (track->data_type == TRACK_VIDEO && server->video)) &&
1779 (!server->transition))
1786 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1787 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1788 "effect", plugin->title,
1790 MainError::show_error(string);
1796 for(Edit *edit = (Edit*)track->edits->first;
1798 edit = (Edit*)edit->next)
1800 if (edit->transition)
1802 // ok we need to find transition in plugindb
1804 int transition_found = 0;
1805 for(int j = 0; j < plugindb->size(); j++)
1807 PluginServer *server = plugindb->get(j);
1809 !strcasecmp(server->title, edit->transition->title) &&
1810 ((track->data_type == TRACK_AUDIO && server->audio) ||
1811 (track->data_type == TRACK_VIDEO && server->video)) &&
1812 (server->transition))
1813 transition_found = 1;
1816 if (!transition_found)
1819 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1820 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1821 "transition", edit->transition->title,
1823 MainError::show_error(string);
1831 void MWindow::init_shm()
1833 // Fix shared memory
1834 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1836 fprintf(fd, "0x7fffffff");
1841 fd = fopen("/proc/sys/kernel/shmmax", "r");
1843 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1848 fscanf(fd, "%jd", &result);
1851 if(result < 0x7fffffff) {
1852 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1853 "you probably need to be root, or:\n"
1854 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1855 "before trying to start cinelerra.\n"
1856 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1860 void MWindow::create_objects(int want_gui,
1865 const int debug = 0;
1866 if(debug) PRINT_TRACE
1868 // For some reason, init_signals must come after show_splash or the signals won't
1871 if(debug) PRINT_TRACE
1874 if(debug) PRINT_TRACE
1877 if(debug) PRINT_TRACE
1878 default_standard = default_std();
1879 init_defaults(defaults, config_path);
1882 splash_window->operation->update(_("Initializing Plugins"));
1883 init_plugins(this, preferences);
1884 if(debug) PRINT_TRACE
1885 init_ladspa_plugins(this, preferences);
1886 if(debug) PRINT_TRACE
1888 splash_window->operation->update(_("Initializing GUI"));
1889 if(debug) PRINT_TRACE
1892 if(debug) PRINT_TRACE
1896 splash_window->operation->update(_("Initializing Fonts"));
1897 char string[BCTEXTLEN];
1898 strcpy(string, preferences->plugin_dir);
1899 strcat(string, "/" FONT_SEARCHPATH);
1900 BC_Resources::init_fontconfig(string);
1901 if(debug) PRINT_TRACE
1903 // Initialize before too much else is running
1904 // Preferences & theme are required for building MPEG table of contents
1906 // Default project created here
1908 if(debug) PRINT_TRACE
1911 if(debug) PRINT_TRACE
1916 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1918 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1919 if(session->show_vwindow)
1920 get_viewer(1, DEFAULT_VWINDOW);
1921 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1924 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1927 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1930 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1932 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1935 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1939 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1941 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1943 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1947 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1948 mainprogress = new MainProgress(this, gui);
1949 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1950 undo = new MainUndo(this);
1952 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1954 plugin_guis = new ArrayList<PluginServer*>;
1955 dead_plugins = new ArrayList<PluginServer*>;
1956 keyframe_threads = new ArrayList<KeyFrameThread*>;
1958 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1961 session->show_vwindow);
1963 // Show all vwindows
1964 // if(session->show_vwindow) {
1965 // for(int j = 0; j < vwindows.size(); j++) {
1966 // VWindow *vwindow = vwindows[j];
1967 // if( !vwindow->is_running() ) continue;
1968 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1971 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1972 // vwindow->gui->lock_window("MWindow::create_objects 1");
1973 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1974 // vwindow->gui->show_window();
1975 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1976 // vwindow->gui->unlock_window();
1981 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1983 if(session->show_cwindow)
1985 cwindow->gui->lock_window("MWindow::create_objects 1");
1986 cwindow->gui->show_window();
1987 cwindow->gui->unlock_window();
1990 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1991 if(session->show_awindow)
1993 awindow->gui->lock_window("MWindow::create_objects 1");
1994 awindow->gui->show_window();
1995 awindow->gui->unlock_window();
1998 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1999 if(session->show_lwindow)
2001 lwindow->gui->lock_window("MWindow::create_objects 1");
2002 lwindow->gui->show_window();
2003 lwindow->gui->unlock_window();
2006 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2008 (int)timer.get_difference(),
2010 if(session->show_gwindow)
2012 gwindow->gui->lock_window("MWindow::create_objects 1");
2013 gwindow->gui->show_window();
2014 gwindow->gui->unlock_window();
2017 if(debug) PRINT_TRACE
2019 gui->lock_window("MWindow::create_objects 1");
2020 gui->mainmenu->load_defaults(defaults);
2021 gui->mainmenu->update_toggles(0);
2022 gui->update_patchbay();
2023 gui->draw_canvas(0, 0);
2024 gui->draw_cursor(1);
2026 gui->raise_window();
2027 gui->unlock_window();
2029 if(debug) PRINT_TRACE
2031 if(preferences->use_tipwindow)
2033 if(debug) PRINT_TRACE
2035 gui->add_keyboard_listener(
2036 (int (BC_WindowBase::*)(BC_WindowBase *))
2037 &MWindowGUI::keyboard_listener);
2041 if(debug) PRINT_TRACE
2043 BC_WindowBase::get_resources()->vframe_shm = 1;
2047 void MWindow::show_splash()
2049 #include "data/heroine_logo9_png.h"
2050 VFrame *frame = new VFramePng(heroine_logo9_png);
2051 BC_DisplayInfo dpyi;
2052 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2053 int rr = (rw < rh ? rw : rh) / 4;
2054 splash_window = new SplashGUI(frame, rr, rr);
2055 splash_window->create_objects();
2058 void MWindow::hide_splash()
2061 delete splash_window;
2066 void MWindow::start()
2070 // vwindows[DEFAULT_VWINDOW]->start();
2081 playback_3d->start();
2087 run_lock->lock("MWindow::run");
2091 brender_lock->lock("MWindow::run 1");
2092 delete brender; brender = 0;
2093 brender_lock->unlock();
2095 interrupt_indexes();
2101 void MWindow::show_vwindow()
2103 int total_running = 0;
2104 session->show_vwindow = 1;
2106 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2107 // Raise all windows which are visible
2108 for(int j = 0; j < vwindows.size(); j++) {
2109 VWindow *vwindow = vwindows[j];
2110 if( !vwindow->is_running() ) continue;
2111 vwindow->gui->lock_window("MWindow::show_vwindow");
2112 vwindow->gui->show_window(0);
2113 vwindow->gui->raise_window();
2114 vwindow->gui->flush();
2115 vwindow->gui->unlock_window();
2119 // If no windows visible
2122 get_viewer(1, DEFAULT_VWINDOW);
2125 gui->mainmenu->show_vwindow->set_checked(1);
2128 void MWindow::show_awindow()
2130 session->show_awindow = 1;
2131 awindow->gui->lock_window("MWindow::show_awindow");
2132 awindow->gui->show_window();
2133 awindow->gui->raise_window();
2134 awindow->gui->flush();
2135 awindow->gui->unlock_window();
2136 gui->mainmenu->show_awindow->set_checked(1);
2139 char *MWindow::get_cwindow_display()
2141 char *x11_host = screens < 2 || session->window_config == 0 ?
2142 session->a_x11_host : session->b_x11_host;
2143 return *x11_host ? x11_host : 0;
2146 void MWindow::show_cwindow()
2148 session->show_cwindow = 1;
2149 cwindow->show_window();
2150 gui->mainmenu->show_cwindow->set_checked(1);
2153 void MWindow::show_gwindow()
2155 session->show_gwindow = 1;
2157 gwindow->gui->lock_window("MWindow::show_gwindow");
2158 gwindow->gui->show_window();
2159 gwindow->gui->raise_window();
2160 gwindow->gui->flush();
2161 gwindow->gui->unlock_window();
2163 gui->mainmenu->show_gwindow->set_checked(1);
2165 void MWindow::hide_gwindow()
2167 session->show_gwindow = 0;
2169 gwindow->gui->lock_window("MWindow::show_gwindow");
2170 gwindow->gui->hide_window();
2171 gwindow->gui->unlock_window();
2174 void MWindow::show_lwindow()
2176 session->show_lwindow = 1;
2177 lwindow->gui->lock_window("MWindow::show_lwindow");
2178 lwindow->gui->show_window();
2179 lwindow->gui->raise_window();
2180 lwindow->gui->flush();
2181 lwindow->gui->unlock_window();
2182 gui->mainmenu->show_lwindow->set_checked(1);
2185 int MWindow::tile_windows(int window_config)
2187 int need_reload = 0;
2188 int play_config = window_config==0 ? 0 : 1;
2189 edl->session->playback_config->load_defaults(defaults, play_config);
2190 session->default_window_positions(window_config);
2191 if( screens == 1 ) {
2192 gui->default_positions();
2193 sync_parameters(CHANGE_ALL);
2200 void MWindow::toggle_loop_playback()
2202 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2203 set_loop_boundaries();
2206 gui->draw_overlays(1);
2207 sync_parameters(CHANGE_PARAMS);
2210 //void MWindow::set_titles(int value)
2212 // edl->session->show_titles = value;
2213 // trackmovement(edl->local_session->track_start);
2216 void MWindow::set_screens(int value)
2221 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2223 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2224 edl->session->auto_keyframes = value;
2225 gui->mbuttons->edit_panel->keyframe->update(value);
2227 if(lock_mwindow) gui->unlock_window();
2229 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2230 cwindow->gui->edit_panel->keyframe->update(value);
2231 cwindow->gui->flush();
2232 if(lock_cwindow) cwindow->gui->unlock_window();
2235 void MWindow::set_auto_visibility(Autos *autos, int value)
2237 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2238 edl->session->auto_conf->plugins = value;
2239 else if( autos->autoidx >= 0 )
2240 edl->session->auto_conf->autos[autos->autoidx] = value;
2244 gui->update(0, 1, 0, 0, 0, 0, 0);
2245 gui->mainmenu->update_toggles(1);
2246 gui->unlock_window();
2247 gwindow->gui->update_toggles(1);
2248 gui->lock_window("MWindow::set_auto_visibility");
2251 void MWindow::set_keyframe_type(int mode)
2253 gui->lock_window("MWindow::set_keyframe_type");
2254 edl->local_session->floatauto_type = mode;
2255 gui->mainmenu->update_toggles(0);
2256 gui->unlock_window();
2259 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2261 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2262 edl->session->editing_mode = new_editing_mode;
2263 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2264 gui->mbuttons->edit_panel->update();
2265 gui->set_editing_mode(1);
2266 if(lock_mwindow) gui->unlock_window();
2269 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2270 cwindow->gui->edit_panel->update();
2271 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2272 if(lock_cwindow) cwindow->gui->unlock_window();
2276 void MWindow::toggle_editing_mode()
2278 int mode = edl->session->editing_mode;
2279 if( mode == EDITING_ARROW )
2280 set_editing_mode(EDITING_IBEAM, 0, 1);
2282 set_editing_mode(EDITING_ARROW, 0, 1);
2286 void MWindow::set_labels_follow_edits(int value)
2288 gui->lock_window("MWindow::set_labels_follow_edits");
2289 edl->session->labels_follow_edits = value;
2290 gui->mbuttons->edit_panel->locklabels->update(value);
2291 gui->mainmenu->labels_follow_edits->set_checked(value);
2293 gui->unlock_window();
2296 void MWindow::sync_parameters(int change_type)
2298 if( in_destructor ) return;
2300 // Sync engines which are playing back
2301 if(cwindow->playback_engine->is_playing_back)
2303 if(change_type == CHANGE_PARAMS)
2305 // TODO: block keyframes until synchronization is done
2306 cwindow->playback_engine->sync_parameters(edl);
2311 int command = cwindow->playback_engine->command->command;
2312 cwindow->playback_engine->que->send_command(STOP,
2316 // Waiting for tracking to finish would make the restart position more
2317 // accurate but it can't lock the window to stop tracking for some reason.
2318 // Not waiting for tracking gives a faster response but restart position is
2319 // only as accurate as the last tracking update.
2320 cwindow->playback_engine->interrupt_playback(0);
2321 cwindow->playback_engine->que->send_command(command,
2330 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2337 void MWindow::age_caches()
2339 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2341 // preferences->cache_size,
2342 // audio_cache->get_memory_usage(1),
2343 // video_cache->get_memory_usage(1),
2344 // frame_cache->get_memory_usage(),
2345 // wave_cache->get_memory_usage(),
2347 frame_cache->age_cache(512);
2348 wave_cache->age_cache(8192);
2350 int64_t memory_usage;
2351 int64_t prev_memory_usage = 0;
2353 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2354 while( !result && prev_memory_usage !=
2355 (memory_usage=video_cache->get_memory_usage(1)) &&
2356 memory_usage > video_size ) {
2357 video_cache->delete_oldest();
2358 prev_memory_usage = memory_usage;
2361 prev_memory_usage = 0;
2363 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2364 while( !result && prev_memory_usage !=
2365 (memory_usage=audio_cache->get_memory_usage(1)) &&
2366 memory_usage > audio_size ) {
2367 audio_cache->delete_oldest();
2368 prev_memory_usage = memory_usage;
2372 void MWindow::reset_android_remote()
2374 gui->use_android_remote(preferences->android_remote);
2378 void MWindow::show_keyframe_gui(Plugin *plugin)
2380 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2381 // Find existing thread
2382 for(int i = 0; i < keyframe_threads->size(); i++)
2384 if(keyframe_threads->get(i)->plugin == plugin)
2386 keyframe_threads->get(i)->start_window(plugin, 0);
2387 keyframe_gui_lock->unlock();
2392 // Find unused thread
2393 for(int i = 0; i < keyframe_threads->size(); i++)
2395 if(!keyframe_threads->get(i)->plugin)
2397 keyframe_threads->get(i)->start_window(plugin, 0);
2398 keyframe_gui_lock->unlock();
2403 // Create new thread
2404 KeyFrameThread *thread = new KeyFrameThread(this);
2405 keyframe_threads->append(thread);
2406 thread->start_window(plugin, 0);
2408 keyframe_gui_lock->unlock();
2415 void MWindow::show_plugin(Plugin *plugin)
2420 // Remove previously deleted plugin GUIs
2421 dead_plugin_lock->lock("MWindow::show_plugin");
2422 dead_plugins->remove_all_objects();
2423 dead_plugin_lock->unlock();
2425 //printf("MWindow::show_plugin %d\n", __LINE__);
2429 plugin_gui_lock->lock("MWindow::show_plugin");
2430 for(int i = 0; i < plugin_guis->total; i++)
2432 // Pointer comparison
2433 if(plugin_guis->get(i)->plugin == plugin)
2435 plugin_guis->get(i)->raise_window();
2442 //printf("MWindow::show_plugin 1\n");
2447 printf("MWindow::show_plugin track not defined.\n");
2449 PluginServer *server = scan_plugindb(plugin->title,
2450 plugin->track->data_type);
2452 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2453 if(server && server->uses_gui)
2455 PluginServer *gui = new PluginServer(*server);
2456 plugin_guis->append(gui);
2457 // Needs mwindow to do GUI
2458 gui->set_mwindow(this);
2459 gui->open_plugin(0, preferences, edl, plugin);
2464 plugin_gui_lock->unlock();
2465 //printf("MWindow::show_plugin %d\n", __LINE__);
2468 //printf("MWindow::show_plugin 2\n");
2471 void MWindow::hide_plugin(Plugin *plugin, int lock)
2474 // Update the toggle
2475 gui->lock_window("MWindow::hide_plugin");
2476 gui->update(0, 1, 0, 0, 0, 0, 0);
2477 gui->unlock_window();
2479 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2480 for(int i = 0; i < plugin_guis->total; i++)
2482 if(plugin_guis->get(i)->plugin == plugin)
2484 PluginServer *ptr = plugin_guis->get(i);
2485 plugin_guis->remove(ptr);
2486 if(lock) plugin_gui_lock->unlock();
2487 // Last command executed in client side close
2488 // Schedule for deletion
2495 if(lock) plugin_gui_lock->unlock();
2498 void MWindow::delete_plugin(PluginServer *plugin)
2500 dead_plugin_lock->lock("MWindow::delete_plugin");
2501 dead_plugins->append(plugin);
2502 dead_plugin_lock->unlock();
2505 void MWindow::hide_plugins()
2507 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2508 while(plugin_guis->size())
2510 PluginServer *ptr = plugin_guis->get(0);
2511 plugin_guis->remove(ptr);
2512 plugin_gui_lock->unlock();
2513 // Last command executed in client side close
2514 // Schedule for deletion
2517 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2519 plugin_gui_lock->unlock();
2521 hide_keyframe_guis();
2524 void MWindow::hide_keyframe_guis()
2526 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2527 for(int i = 0; i < keyframe_threads->size(); i++)
2529 keyframe_threads->get(i)->close_window();
2531 keyframe_gui_lock->unlock();
2534 void MWindow::hide_keyframe_gui(Plugin *plugin)
2536 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2537 for(int i = 0; i < keyframe_threads->size(); i++)
2539 if(keyframe_threads->get(i)->plugin == plugin)
2541 keyframe_threads->get(i)->close_window();
2545 keyframe_gui_lock->unlock();
2548 void MWindow::update_keyframe_guis()
2550 // Send new configuration to keyframe GUI's
2551 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2552 for(int i = 0; i < keyframe_threads->size(); i++)
2554 KeyFrameThread *ptr = keyframe_threads->get(i);
2555 if(edl->tracks->plugin_exists(ptr->plugin))
2559 ptr->close_window();
2562 keyframe_gui_lock->unlock();
2565 void MWindow::update_plugin_guis(int do_keyframe_guis)
2567 // Send new configuration to plugin GUI's
2568 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2570 for(int i = 0; i < plugin_guis->size(); i++)
2572 PluginServer *ptr = plugin_guis->get(i);
2573 if(edl->tracks->plugin_exists(ptr->plugin))
2577 // Schedule for deletion if no plugin
2578 plugin_guis->remove_number(i);
2587 // Change plugin variable if not visible
2588 Track *track = edl->tracks->first;
2591 for(int i = 0; i < track->plugin_set.size(); i++)
2593 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2597 for(int i = 0; i < plugin_guis->size(); i++)
2599 PluginServer *server = plugin_guis->get(i);
2600 if(server->plugin == plugin)
2607 if(!got_it) plugin->show = 0;
2609 plugin = (Plugin*)plugin->next;
2613 track = track->next;
2616 plugin_gui_lock->unlock();
2619 if(do_keyframe_guis) update_keyframe_guis();
2622 int MWindow::plugin_gui_open(Plugin *plugin)
2625 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2626 for(int i = 0; i < plugin_guis->total; i++)
2628 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2634 plugin_gui_lock->unlock();
2638 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2640 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2641 for(int i = 0; i < plugin_guis->total; i++)
2643 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2645 plugin_guis->get(i)->render_gui(data);
2649 plugin_gui_lock->unlock();
2652 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2654 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2655 for(int i = 0; i < plugin_guis->total; i++)
2657 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2659 plugin_guis->get(i)->render_gui(data, size);
2663 plugin_gui_lock->unlock();
2667 void MWindow::update_plugin_states()
2669 plugin_gui_lock->lock("MWindow::update_plugin_states");
2670 for(int i = 0; i < plugin_guis->total; i++)
2674 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2675 PluginServer *src_plugingui = plugin_guis->get(i);
2677 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2678 for(Track *track = edl->tracks->first;
2680 track = track->next)
2683 j < track->plugin_set.total && !result;
2686 PluginSet *plugin_set = track->plugin_set[j];
2687 for(Plugin *plugin = (Plugin*)plugin_set->first;
2689 plugin = (Plugin*)plugin->next)
2691 if(plugin == src_plugin &&
2692 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2698 // Doesn't exist anymore
2701 hide_plugin(src_plugin, 0);
2705 plugin_gui_lock->unlock();
2709 void MWindow::update_plugin_titles()
2711 for(int i = 0; i < plugin_guis->total; i++)
2713 plugin_guis->get(i)->update_title();
2717 int MWindow::asset_to_edl(EDL *new_edl,
2719 RecordLabels *labels)
2721 const int debug = 0;
2722 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2725 // Keep frame rate, sample rate, and output size unchanged.
2726 // These parameters would revert the project if VWindow displayed an asset
2727 // of different size than the project.
2728 if(new_asset->video_data)
2730 new_edl->session->video_tracks = new_asset->layers;
2733 new_edl->session->video_tracks = 0;
2735 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2741 if(new_asset->audio_data)
2743 new_edl->session->audio_tracks = new_asset->channels;
2746 new_edl->session->audio_tracks = 0;
2747 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2749 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2750 new_edl->create_default_tracks();
2751 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2752 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2756 //printf("MWindow::asset_to_edl 3\n");
2757 new_edl->insert_asset(new_asset,
2762 //printf("MWindow::asset_to_edl 3\n");
2763 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2765 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2766 if(edl->session->cursor_on_frames)
2768 double length = new_edl->tracks->total_length();
2769 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2770 new_edl->tracks->clear(length, edl_length, 1, 1);
2776 char string[BCTEXTLEN];
2778 fs.extract_name(string, new_asset->path);
2779 //printf("MWindow::asset_to_edl 3\n");
2781 strcpy(new_edl->local_session->clip_title, string);
2782 //printf("MWindow::asset_to_edl 4 %s\n", string);
2783 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2788 int MWindow::edl_to_nested(EDL *new_edl,
2792 // Keep frame rate, sample rate, and output size unchanged.
2793 // These parameters would revert the project if VWindow displayed an asset
2794 // of different size than the project.
2798 // Nest all video & audio outputs
2799 new_edl->session->video_tracks = 1;
2800 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2801 new_edl->create_default_tracks();
2805 new_edl->insert_asset(0,
2811 char string[BCTEXTLEN];
2813 fs.extract_name(string, nested_edl->path);
2814 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2816 strcpy(new_edl->local_session->clip_title, string);
2821 // Reset everything after a load.
2822 void MWindow::update_project(int load_mode)
2824 const int debug = 0;
2826 if(debug) PRINT_TRACE
2828 edl->tracks->update_y_pixels(theme);
2830 if(debug) PRINT_TRACE
2832 if(load_mode == LOADMODE_REPLACE ||
2833 load_mode == LOADMODE_REPLACE_CONCATENATE)
2838 gui->update(1, 1, 1, 1, 1, 1, 1);
2839 if(debug) PRINT_TRACE
2840 gui->unlock_window();
2842 cwindow->gui->lock_window("MWindow::update_project 1");
2843 cwindow->update(0, 0, 1, 1, 1);
2844 cwindow->gui->unlock_window();
2846 if(debug) PRINT_TRACE
2848 // Close all the vwindows
2849 if(load_mode == LOADMODE_REPLACE ||
2850 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2851 if(debug) PRINT_TRACE
2852 int first_vwindow = 0;
2853 if(session->show_vwindow) first_vwindow = 1;
2854 // Change visible windows to no source
2855 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2856 VWindow *vwindow = vwindows[i];
2857 if( !vwindow->is_running() ) continue;
2858 vwindow->change_source(-1);
2861 // Close remaining windows
2862 for(int i = first_vwindow; i < vwindows.size(); i++) {
2863 VWindow *vwindow = vwindows[i];
2864 if( !vwindow->is_running() ) continue;
2865 vwindow->close_window();
2867 if(debug) PRINT_TRACE
2869 else if(vwindows.size()) {
2870 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2871 if( vwindow->is_running() ) {
2872 vwindow->gui->lock_window("MWindow::update_project");
2874 vwindow->gui->unlock_window();
2878 if(debug) PRINT_TRACE
2879 cwindow->gui->lock_window("MWindow::update_project 2");
2880 cwindow->gui->timebar->update(0);
2881 cwindow->gui->unlock_window();
2883 if(debug) PRINT_TRACE
2884 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2889 awindow->gui->async_update_assets();
2890 if(debug) PRINT_TRACE
2892 gui->lock_window("MWindow::update_project");
2894 if(debug) PRINT_TRACE
2897 void MWindow::remove_indexfile(Indexable *indexable)
2899 if( !indexable->is_asset ) return;
2900 Asset *asset = (Asset *)indexable;
2902 IndexFile::delete_index(preferences, asset, ".toc");
2903 IndexFile::delete_index(preferences, asset, ".idx");
2904 IndexFile::delete_index(preferences, asset, ".mkr");
2907 void MWindow::rebuild_indices()
2909 for(int i = 0; i < session->drag_assets->total; i++)
2911 Indexable *indexable = session->drag_assets->get(i);
2912 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2913 remove_indexfile(indexable);
2914 // Schedule index build
2915 IndexState *index_state = indexable->index_state;
2916 index_state->index_status = INDEX_NOTTESTED;
2917 if( indexable->is_asset ) {
2918 Asset *asset = (Asset *)indexable;
2919 if( asset->format != FILE_PCM )
2920 asset->reset_audio();
2921 asset->reset_video();
2923 mainindexes->add_next_asset(0, indexable);
2925 mainindexes->start_build();
2929 void MWindow::save_backup()
2933 edl->set_path(session->filename);
2934 char backup_path[BCTEXTLEN];
2935 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2936 File::get_config_path(), BACKUP_FILE);
2937 edl->save_xml(&file, backup_path, 0, 0);
2938 file.terminate_string();
2940 fs.complete_path(backup_path);
2942 if(file.write_to_file(backup_path))
2945 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
2946 gui->show_message(string2);
2950 void MWindow::load_backup()
2952 ArrayList<char*> path_list;
2953 path_list.set_array_delete();
2955 char backup_path[BCTEXTLEN];
2956 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2957 File::get_config_path(), BACKUP_FILE);
2959 fs.complete_path(backup_path);
2961 path_list.append(out_path = new char[strlen(backup_path) + 1]);
2962 strcpy(out_path, backup_path);
2964 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2965 edl->local_session->clip_title[0] = 0;
2966 // This is unique to backups since the path of the backup is different than the
2967 // path of the project.
2968 set_filename(edl->path);
2969 path_list.remove_all_objects();
2973 static inline int gcd(int m, int n)
2976 if( m < n ) { r = m; m = n; n = r; }
2977 while( (r = m % n) != 0 ) { m = n; n = r; }
2981 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2984 if(!width || !height) return 1;
2985 if( width == 720 && (height == 480 || height == 576) ) {
2986 w = 4; h = 3; return 0; // for NTSC and PAL
2988 double ar = (double)width / height;
2989 // square-ish pixels
2990 if( EQUIV(ar, 1.0000) ) return 0;
2991 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2992 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2993 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2994 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2995 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2996 int ww = width, hh = height;
2997 // numerator, denominator must be under mx
2998 int mx = 255, n = gcd(ww, hh);
2999 if( n > 1 ) { ww /= n; hh /= n; }
3000 // search near height in case extra/missing lines
3001 if( ww >= mx || hh >= mx ) {
3002 double err = height; // +/- 2 percent height
3003 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3004 int iw = width, ih = height+i;
3005 if( (n=gcd(iw, ih)) > 1 ) {
3006 int u = iw/n; if( u >= mx ) continue;
3007 int v = ih/n; if( v >= mx ) continue;
3008 double r = (double) u/v, er = fabs(ar-r);
3009 if( er >= err ) continue;
3010 err = er; ww = u; hh = v;
3019 void MWindow::reset_caches()
3021 frame_cache->remove_all();
3022 wave_cache->remove_all();
3023 audio_cache->remove_all();
3024 video_cache->remove_all();
3025 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3026 cwindow->playback_engine->audio_cache->remove_all();
3027 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3028 cwindow->playback_engine->video_cache->remove_all();
3030 for(int i = 0; i < vwindows.size(); i++) {
3031 VWindow *vwindow = vwindows[i];
3032 if( !vwindow->is_running() ) continue;
3033 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3034 vwindow->playback_engine->audio_cache->remove_all();
3035 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3036 vwindow->playback_engine->video_cache->remove_all();
3040 void MWindow::remove_asset_from_caches(Asset *asset)
3042 gui->resource_thread->get_video_source(0);
3043 gui->resource_thread->get_audio_source(0);
3044 frame_cache->remove_asset(asset);
3045 wave_cache->remove_asset(asset);
3046 audio_cache->delete_entry(asset);
3047 video_cache->delete_entry(asset);
3048 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3049 cwindow->playback_engine->audio_cache->delete_entry(asset);
3050 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3051 cwindow->playback_engine->video_cache->delete_entry(asset);
3052 for(int i = 0; i < vwindows.size(); i++) {
3053 VWindow *vwindow = vwindows[i];
3054 if( !vwindow->is_running() ) continue;
3055 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3056 vwindow->playback_engine->audio_cache->delete_entry(asset);
3057 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3058 vwindow->playback_engine->video_cache->delete_entry(asset);
3063 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3064 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3066 for(int i = 0; i < session->drag_assets->total; i++) {
3067 Indexable *indexable = session->drag_assets->get(i);
3068 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3071 // Remove from VWindow.
3072 for(int i = 0; i < session->drag_clips->total; i++) {
3073 for(int j = 0; j < vwindows.size(); j++) {
3074 VWindow *vwindow = vwindows[j];
3075 if( !vwindow->is_running() ) continue;
3076 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3077 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3078 vwindow->delete_source(1, 1);
3079 vwindow->gui->unlock_window();
3084 for(int i = 0; i < session->drag_assets->size(); i++) {
3085 for(int j = 0; j < vwindows.size(); j++) {
3086 VWindow *vwindow = vwindows[j];
3087 if( !vwindow->is_running() ) continue;
3088 if(session->drag_assets->get(i) == vwindow->get_source()) {
3089 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3090 vwindow->delete_source(1, 1);
3091 vwindow->gui->unlock_window();
3096 for(int i = 0; i < session->drag_assets->size(); i++) {
3097 Indexable *indexable = session->drag_assets->get(i);
3098 remove_indexfile(indexable);
3101 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3102 if(push_undo) undo->update_undo_before();
3103 if(drag_assets) edl->remove_from_project(drag_assets);
3104 if(drag_clips) edl->remove_from_project(session->drag_clips);
3105 if(redraw) save_backup();
3106 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3111 gui->lock_window("MWindow::remove_assets_from_project 3");
3119 gui->unlock_window();
3121 // Removes from playback here
3122 sync_parameters(CHANGE_ALL);
3125 awindow->gui->async_update_assets();
3128 void MWindow::remove_assets_from_disk()
3131 for(int i = 0; i < session->drag_assets->total; i++)
3133 remove(session->drag_assets->get(i)->path);
3136 remove_assets_from_project(1,
3138 session->drag_assets,
3139 session->drag_clips);
3142 void MWindow::dump_plugins(FILE *fp)
3144 if( !plugindb ) return;
3145 for(int i = 0; i < plugindb->total; i++)
3147 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3148 " synth=%d transition=%d theme=%d %s\n",
3149 plugindb->get(i)->plugin_type,
3150 plugindb->get(i)->audio,
3151 plugindb->get(i)->video,
3152 plugindb->get(i)->realtime,
3153 plugindb->get(i)->multichannel,
3154 plugindb->get(i)->get_synthesis(),
3155 plugindb->get(i)->transition,
3156 plugindb->get(i)->theme,
3157 plugindb->get(i)->title);
3161 void MWindow::dump_edl(FILE *fp)
3167 void MWindow::dump_undo(FILE *fp)
3173 void MWindow::dump_exe(FILE *fp)
3175 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3176 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3178 int ret = -1, n = 100;
3179 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3180 exe_path[len] = 0; strcpy(proc_path, exe_path);
3183 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3186 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3187 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3188 struct tm *tm = localtime(&st.st_mtime);
3190 strftime(mtime, sizeof(mtime), "%F %T", tm);
3191 fprintf(fp,"mtime: %s\n", mtime);
3193 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3194 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3197 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3198 int64_t maxsz = 1024*pagsz;
3199 int64_t size = st.st_size, pos = 0;
3201 while( (bfrsz = size-pos) > 0 ) {
3202 if( bfrsz > maxsz ) bfrsz = maxsz;
3203 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3204 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3205 if( bfr == MAP_FAILED ) break;
3206 sha1.addBytes(bfr, bfrsz);
3211 ret = pos < size ? EIO : 0;
3212 fprintf(fp, "SHA1: ");
3213 uint8_t digest[20]; sha1.computeHash(digest);
3214 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3215 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3216 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3220 void MWindow::trap_hook(FILE *fp, void *vp)
3222 MWindow *mwindow = (MWindow *)vp;
3223 // fprintf(fp, "\nPLUGINS:\n");
3224 // mwindow->dump_plugins(fp);
3225 fprintf(fp, "\nEDL:\n");
3226 mwindow->dump_edl(fp);
3227 fprintf(fp, "\nUNDO:\n");
3228 mwindow->dump_undo(fp);
3229 fprintf(fp, "\nEXE:\n");
3230 mwindow->dump_exe(fp);
3238 int MWindow::save_defaults()
3240 gui->save_defaults(defaults);
3241 edl->save_defaults(defaults);
3242 session->save_defaults(defaults);
3243 preferences->save_defaults(defaults);
3245 for(int i = 0; i < plugin_guis->total; i++)
3247 // Pointer comparison
3248 plugin_guis->get(i)->save_defaults();
3250 awindow->save_defaults(defaults);
3256 int MWindow::run_script(FileXML *script)
3258 int result = 0, result2 = 0;
3259 while(!result && !result2)
3261 result = script->read_tag();
3264 if(script->tag.title_is("new_project"))
3266 // Run new in immediate mode.
3267 // gui->mainmenu->new_project->run_script(script);
3270 if(script->tag.title_is("record"))
3272 // Run record as a thread. It is a terminal command.
3274 // Will read the complete scipt file without letting record read it if not
3280 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3287 // ================================= synchronization
3290 int MWindow::interrupt_indexes()
3292 mainprogress->cancelled = 1;
3293 mainindexes->interrupt_build();
3299 void MWindow::next_time_format()
3301 switch(edl->session->time_format)
3303 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3304 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3305 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3306 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3307 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3308 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3309 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3312 time_format_common();
3315 void MWindow::prev_time_format()
3317 switch(edl->session->time_format)
3319 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3320 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3321 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3322 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3323 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3324 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3325 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3328 time_format_common();
3331 void MWindow::time_format_common()
3333 gui->lock_window("MWindow::next_time_format");
3334 gui->redraw_time_dependancies();
3337 char string[BCTEXTLEN], string2[BCTEXTLEN];
3338 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3339 gui->show_message(string);
3341 gui->unlock_window();
3345 int MWindow::set_filename(const char *filename)
3347 if( filename != session->filename )
3348 strcpy(session->filename, filename);
3349 if( filename != edl->path )
3350 strcpy(edl->path, filename);
3354 if(filename[0] == 0)
3356 gui->set_title(PROGRAM_NAME);
3361 char string[BCTEXTLEN], string2[BCTEXTLEN];
3362 dir.extract_name(string, filename);
3363 sprintf(string2, PROGRAM_NAME ": %s", string);
3364 gui->set_title(string2);
3377 int MWindow::set_loop_boundaries()
3379 double start = edl->local_session->get_selectionstart();
3380 double end = edl->local_session->get_selectionend();
3388 if(edl->tracks->total_length())
3391 end = edl->tracks->total_length();
3398 if(edl->local_session->loop_playback && start != end)
3400 edl->local_session->loop_start = start;
3401 edl->local_session->loop_end = end;
3412 int MWindow::reset_meters()
3414 cwindow->gui->lock_window("MWindow::reset_meters 1");
3415 cwindow->gui->meters->reset_meters();
3416 cwindow->gui->unlock_window();
3418 for(int j = 0; j < vwindows.size(); j++) {
3419 VWindow *vwindow = vwindows[j];
3420 if( !vwindow->is_running() ) continue;
3421 vwindow->gui->lock_window("MWindow::reset_meters 2");
3422 vwindow->gui->meters->reset_meters();
3423 vwindow->gui->unlock_window();
3426 lwindow->gui->lock_window("MWindow::reset_meters 3");
3427 lwindow->gui->panel->reset_meters();
3428 lwindow->gui->unlock_window();
3430 gui->lock_window("MWindow::reset_meters 4");
3431 gui->reset_meters();
3432 gui->unlock_window();
3437 void MWindow::resync_guis()
3441 gui->lock_window("MWindow::resync_guis");
3442 gui->update(1, 1, 1, 1, 1, 1, 0);
3443 gui->unlock_window();
3445 cwindow->gui->lock_window("MWindow::resync_guis");
3446 cwindow->gui->resize_event(cwindow->gui->get_w(),
3447 cwindow->gui->get_h());
3448 int channels = edl->session->audio_channels;
3449 cwindow->gui->meters->set_meters(channels, 1);
3450 cwindow->gui->flush();
3451 cwindow->gui->unlock_window();
3453 for(int i = 0; i < vwindows.size(); i++) {
3454 VWindow *vwindow = vwindows[i];
3455 if( !vwindow->is_running() ) continue;
3456 vwindow->gui->lock_window("MWindow::resync_guis");
3457 vwindow->gui->resize_event(vwindow->gui->get_w(),
3458 vwindow->gui->get_h());
3459 vwindow->gui->meters->set_meters(channels, 1);
3460 vwindow->gui->flush();
3461 vwindow->gui->unlock_window();
3464 lwindow->gui->lock_window("MWindow::resync_guis");
3465 lwindow->gui->panel->set_meters(channels, 1);
3466 lwindow->gui->flush();
3467 lwindow->gui->unlock_window();
3470 if(((edl->session->output_w % 4) ||
3471 (edl->session->output_h % 4)) &&
3472 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3474 MainError::show_error(
3475 _("This project's dimensions are not multiples of 4 so\n"
3476 "it can't be rendered by OpenGL."));
3481 sync_parameters(CHANGE_ALL);
3484 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3486 File *file = new File;
3487 EDLSession *session = edl->session;
3488 double old_framerate = session->frame_rate;
3489 double old_samplerate = session->sample_rate;
3490 int old_auto_keyframes = session->auto_keyframes;
3491 session->auto_keyframes = 0;
3492 int result = file->open_file(preferences, asset, 1, 0);
3493 if( !result && delete_tracks > 0 )
3494 undo->update_undo_before();
3495 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3496 // try to get asset up to date, may fail
3497 file->select_video_stream(asset, vstream);
3498 // either way use what was/is there.
3499 double framerate = asset->get_frame_rate();
3500 int width = asset->get_w();
3501 int height = asset->get_h();
3502 // must be multiple of 4 for opengl
3503 width = (width+3) & ~3; height = (height+3) & ~3;
3504 int driver = session->playback_config->vconfig->driver;
3505 int color_model = file->get_best_colormodel(asset, driver);
3506 // color_model = BC_CModels::is_yuv(color_model) ?
3507 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3508 // BC_CModels::is_float(color_model) ?
3509 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3510 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3511 // have alpha for now
3512 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3513 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3514 session->color_model = color_model;
3515 session->output_w = width;
3516 session->output_h = height;
3517 session->frame_rate = framerate;
3518 // not, asset->actual_width/actual_height
3519 asset->width = session->output_w;
3520 asset->height = session->output_h;
3521 asset->frame_rate = session->frame_rate;
3522 create_aspect_ratio(session->aspect_w, session->aspect_h,
3523 session->output_w, session->output_h);
3524 Track *track = edl->tracks->first;
3525 for( Track *next_track=0; track; track=next_track ) {
3526 next_track = track->next;
3527 if( track->data_type != TRACK_VIDEO ) continue;
3528 if( delete_tracks ) {
3529 Edit *edit = track->edits->first;
3530 for( Edit *next_edit=0; edit; edit=next_edit ) {
3531 next_edit = edit->next;
3532 if( edit->channel != vstream ||
3533 !edit->asset || !edit->asset->is_asset ||
3534 *asset != *edit->asset )
3538 if( track->edits->first ) {
3539 track->track_w = edl->session->output_w;
3540 track->track_h = edl->session->output_h;
3542 else if( delete_tracks )
3543 edl->tracks->delete_track(track);
3545 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3547 if( !result && asset->audio_data && asset->channels > 0 ) {
3548 session->sample_rate = asset->get_sample_rate();
3549 int64_t channel_mask = 0;
3550 int astrm = !asset->video_data ? -1 :
3551 file->get_audio_for_video(vstream, astream, channel_mask);
3552 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3553 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3555 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3556 if( channels < 1 ) channels = 1;
3557 if( channels > 6 ) channels = 6;
3558 session->audio_tracks = session->audio_channels = channels;
3559 switch( channels ) {
3561 session->achannel_positions[0] = 90;
3562 session->achannel_positions[1] = 150;
3563 session->achannel_positions[2] = 30;
3564 session->achannel_positions[3] = 210;
3565 session->achannel_positions[4] = 330;
3566 session->achannel_positions[5] = 270;
3569 session->achannel_positions[0] = 180;
3570 session->achannel_positions[1] = 0;
3573 session->achannel_positions[1] = 90;
3576 if( !channels ) break;
3577 double t = 0, dt = 360./channels;
3578 for( int i=channels; --i>=0; t+=dt )
3579 session->achannel_positions[i] = int(t+0.5);
3582 remap_audio(MWindow::AUDIO_1_TO_1);
3584 if( delete_tracks ) {
3585 Track *track = edl->tracks->first;
3586 for( Track *next_track=0; track; track=next_track ) {
3587 next_track = track->next;
3588 if( track->data_type != TRACK_AUDIO ) continue;
3589 Edit *edit = track->edits->first;
3590 for( Edit *next_edit=0; edit; edit=next_edit ) {
3591 next_edit = edit->next;
3592 if( !((1<<edit->channel) & channel_mask) ||
3593 !edit->asset || !edit->asset->is_asset ||
3594 *asset != *edit->asset )
3597 if( !track->edits->first )
3598 edl->tracks->delete_track(track);
3602 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3605 session->auto_keyframes = old_auto_keyframes;
3606 if( !result && delete_tracks > 0 ) {
3608 undo->update_undo_after(_("select asset"), LOAD_ALL);
3614 int MWindow::select_asset(int vtrack, int delete_tracks)
3616 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3618 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3619 if( !track ) return 1;
3620 Edit *edit = track->edits->first;
3621 if( !edit ) return 1;
3622 Asset *asset = edit->asset;
3623 if( !asset || !asset->is_asset ) return 1;
3624 return select_asset(asset, edit->channel, 0, delete_tracks);
3627 void MWindow::dump_plugindb(FILE *fp)
3629 if( !plugindb ) return;
3630 for(int i = 0; i < plugindb->total; i++)
3631 plugindb->get(i)->dump(fp);
3634 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
3637 double unit_position = edl->local_session->get_selectionstart(1);
3638 unit_position = patch->track->to_units(unit_position, 0);
3640 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
3641 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3644 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
3647 double unit_position = edl->local_session->get_selectionstart(1);
3648 unit_position = patch->track->to_units(unit_position, 0);
3650 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
3651 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3654 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
3657 double unit_position = edl->local_session->get_selectionstart(1);
3658 unit_position = patch->track->to_units(unit_position, 0);
3660 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
3661 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);