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"
37 #include "channeldb.h"
38 #include "channelinfo.h"
40 #include "bccmodels.h"
41 #include "commercials.h"
42 #include "cplayback.h"
44 #include "cwindowgui.h"
46 #include "cwindowtool.h"
48 #include "devicedvbinput.inc"
49 #include "dvdcreate.h"
50 #include "editpanel.h"
52 #include "edlsession.h"
54 #include "fileformat.h"
56 #include "filesystem.h"
58 #include "floatautos.h"
59 #include "framecache.h"
61 #include "gwindowgui.h"
62 #include "keyframegui.h"
63 #include "indexfile.h"
65 #include "interlacemodes.h"
67 #include "levelwindowgui.h"
68 #include "levelwindow.h"
69 #include "loadfile.inc"
70 #include "localsession.h"
71 #include "maincursor.h"
72 #include "mainerror.h"
73 #include "mainindexes.h"
75 #include "mainprogress.h"
76 #include "mainsession.h"
80 #include "mwindowgui.h"
82 #include "nestededls.h"
86 #include "playback3d.h"
87 #include "playbackengine.h"
89 #include "pluginserver.h"
90 #include "pluginset.h"
91 #include "preferences.h"
93 #include "recordmonitor.h"
94 #include "recordlabel.h"
95 #include "removefile.h"
97 #include "resourcethread.h"
98 #include "samplescroll.h"
100 #include "sighandler.h"
101 #include "splashgui.h"
102 #include "statusbar.h"
104 #include "threadloader.h"
106 #include "tipwindow.h"
107 #include "trackcanvas.h"
109 #include "tracking.h"
110 #include "trackscroll.h"
112 #include "transition.h"
113 #include "transportque.h"
116 #include "versioninfo.h"
117 #include "videodevice.inc"
118 #include "videowindow.h"
119 #include "vplayback.h"
120 #include "vwindowgui.h"
122 #include "wavecache.h"
125 #include "exportedl.h"
127 #include "defaultformats.h"
128 #include "ntsczones.h"
135 #include <sys/types.h>
136 #include <sys/stat.h>
137 #include <sys/time.h>
138 #include <sys/mman.h>
149 // Hack for libdv to remove glib dependancy
152 // g_log (const char *log_domain,
154 // const char *format,
160 // g_logv (const char *log_domain,
162 // const char *format,
172 ArrayList<PluginServer*>* MWindow::plugindb = 0;
173 Commercials* MWindow::commercials = 0;
179 run_lock = new Mutex("MWindow::run_lock");
180 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
181 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
182 vwindows_lock = new Mutex("MWindow::vwindows_lock");
183 brender_lock = new Mutex("MWindow::brender_lock");
184 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
192 commercial_active = 0;
203 channeldb_buz = new ChannelDB;
204 channeldb_v4l2jpeg = new ChannelDB;
208 keyframe_threads = 0;
228 // Need to delete brender temporary here.
231 run_lock->lock("MWindow::~MWindow");
233 //printf("MWindow::~MWindow %d\n", __LINE__);
235 gui->remote_control->deactivate();
238 gui->channel_info->stop();
240 delete create_bd; create_bd = 0;
241 delete create_dvd; create_dvd = 0;
242 delete batch_render; batch_render = 0;
243 delete render; render = 0;
245 if( commercials && !commercials->remove_user() ) commercials = 0;
247 // Save defaults for open plugins
248 plugin_gui_lock->lock("MWindow::~MWindow");
249 for(int i = 0; i < plugin_guis->size(); i++) {
250 plugin_guis->get(i)->hide_gui();
251 delete_plugin(plugin_guis->get(i));
253 plugin_gui_lock->unlock();
254 hide_keyframe_guis();
257 // Give up and go to a movie
258 // cant run valgrind if this is used
260 gui->del_keyboard_listener(
261 (int (BC_WindowBase::*)(BC_WindowBase *))
262 &MWindowGUI::keyboard_listener);
264 // release the hounds
265 if( awindow && awindow->gui ) awindow->gui->close(0);
266 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
267 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
268 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
269 if( twindow && twindow->is_running() ) twindow->close_window();
270 if( wwindow && wwindow->is_running() ) wwindow->close_window();
271 vwindows.remove_all_objects();
273 if( awindow ) awindow->join();
274 if( cwindow ) cwindow->join();
275 if( lwindow ) lwindow->join();
276 if( twindow ) twindow->join();
277 if( wwindow ) wwindow->join();
278 if( gwindow ) gwindow->join();
281 // one at a time, or nouveau chokes
282 #define close_gui(win) if( win ) { \
283 if( win->gui ) win->gui->close(0); \
291 vwindows.remove_all_objects();
296 dead_plugins->remove_all_objects();
299 keyframe_threads->remove_all_objects();
300 colormodels.remove_all_objects();
301 delete awindow; awindow = 0;
302 delete lwindow; lwindow = 0;
303 delete twindow; twindow = 0;
304 delete wwindow; wwindow = 0;
305 delete gwindow; gwindow = 0;
306 delete cwindow; cwindow = 0;
308 //delete file_server; file_server = 0; // reusable
309 delete mainindexes; mainindexes = 0;
310 delete mainprogress; mainprogress = 0;
311 delete audio_cache; audio_cache = 0; // delete the cache after the assets
312 delete video_cache; video_cache = 0; // delete the cache after the assets
313 delete frame_cache; frame_cache = 0;
314 delete wave_cache; wave_cache = 0;
315 delete plugin_guis; plugin_guis = 0;
316 delete dead_plugins; dead_plugins = 0;
317 delete keyframe_threads; keyframe_threads = 0;
318 delete undo; undo = 0;
319 delete preferences; preferences = 0;
320 delete exportedl; exportedl = 0;
321 delete session; session = 0;
322 delete defaults; defaults = 0;
323 delete assets; assets = 0;
324 delete splash_window; splash_window = 0;
325 // delete theme; theme = 0; // deleted by delete_plugins
326 if( !edl->Garbage::remove_user() ) edl = 0;
327 delete channeldb_buz;
328 delete channeldb_v4l2jpeg;
329 // This must be last thread to exit
330 delete playback_3d; playback_3d = 0;
331 delete dead_plugin_lock;
332 delete plugin_gui_lock;
333 delete vwindows_lock;
335 delete keyframe_gui_lock;
336 colormodels.remove_all_objects();
337 interlace_project_modes.remove_all_objects();
338 interlace_asset_modes.remove_all_objects();
339 interlace_asset_fixmethods.remove_all_objects();
340 sighandler->terminate();
351 void MWindow::init_error()
353 MainError::init_error(this);
356 void MWindow::finit_error()
358 MainError::finit_error();
361 void MWindow::create_defaults_path(char *string, const char *config_file)
363 // set the .bcast path
366 sprintf(string, "%s/", File::get_config_path());
367 fs.complete_path(string);
368 if(!fs.is_dir(string))
369 fs.create_dir(string);
372 strcat(string, config_file);
374 const char *MWindow::default_std()
376 char buf[BCTEXTLEN], *p = 0;
378 int fd = open(TIMEZONE_NAME, O_RDONLY);
380 int l = read(fd, buf, sizeof(buf)-1);
383 if( buf[l-1] == '\n' ) --l;
389 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
392 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
393 p += strlen(ZONEINFO_STR);
398 for( int i=0; ntsc_zones[i]; ++i ) {
399 if( !strcmp(ntsc_zones[i], p) )
406 for( int i=0; ntsc_zones[i]; ++i ) {
407 if( !strcmp(ntsc_zones[i], p) )
412 //__timezone: Seconds west of UTC. 240sec/deg
413 double tz_deg = -__timezone / 240.;
414 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
415 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
418 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
420 struct formatpresets *fpr;
422 for(fpr = &format_presets[0]; fpr->name; fpr++)
424 if(strcmp(_(fpr->name), preset) == 0)
426 session->audio_channels = fpr->audio_channels;
427 session->audio_tracks = fpr->audio_tracks;
428 session->sample_rate = fpr->sample_rate;
429 session->video_channels = fpr->video_channels;
430 session->video_tracks = fpr->video_tracks;
431 session->frame_rate = fpr->frame_rate;
432 session->output_w = fpr->output_w;
433 session->output_h = fpr->output_h;
434 session->aspect_w = fpr->aspect_w;
435 session->aspect_h = fpr->aspect_h;
436 session->interlace_mode = fpr->interlace_mode;
437 session->color_model = fpr->color_model;
443 const char *MWindow::get_preset_name(int index)
445 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
447 return _(format_presets[index].name);
451 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
453 char path[BCTEXTLEN];
454 // Use user supplied path
456 strcpy(path, config_path);
458 create_defaults_path(path, CONFIG_FILE);
460 defaults = new BC_Hash(path);
465 void MWindow::check_language()
467 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
468 const char *env_lang = getenv("LANGUAGE");
469 if( !env_lang ) env_lang = getenv("LANG");
471 snprintf(curr_lang, sizeof(curr_lang), "%s-%s.%s",
472 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
473 env_lang = curr_lang;
475 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
476 defaults->get("LAST_LANG",last_lang);
477 if( strcmp(env_lang,last_lang)) {
478 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
479 defaults->update("LAST_LANG",env_lang);
480 char plugin_path[BCTEXTLEN];
481 create_defaults_path(plugin_path, PLUGIN_FILE);
482 ::remove(plugin_path);
483 char ladspa_path[BCTEXTLEN];
484 create_defaults_path(ladspa_path, LADSPA_FILE);
485 ::remove(ladspa_path);
490 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
492 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
494 const char *dp = plug_dir;
495 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
496 bp = !*dp && *bp == '/' ? bp+1 : base_path;
502 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
505 FILE *fp = fopen(index_path, "r");
509 char index_line[BCTEXTLEN];
510 int index_version = -1, len = strlen(plugin_dir);
511 if( !fgets(index_line, BCTEXTLEN, fp) ||
512 sscanf(index_line, "%d", &index_version) != 1 ||
513 index_version != PLUGIN_FILE_VERSION ||
514 !fgets(index_line, BCTEXTLEN, fp) ||
515 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
516 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
518 ArrayList<PluginServer*> plugins;
519 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
520 if( index_line[0] == ';' ) continue;
521 if( index_line[0] == '#' ) continue;
522 int type = PLUGIN_TYPE_UNKNOWN;
523 char path[BCTEXTLEN], title[BCTEXTLEN];
525 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
528 PluginServer *server = 0;
530 case PLUGIN_TYPE_BUILTIN:
531 case PLUGIN_TYPE_EXECUTABLE:
532 case PLUGIN_TYPE_LADSPA: {
533 char plugin_path[BCTEXTLEN]; struct stat st;
534 sprintf(plugin_path, "%s/%s", plugin_dir, path);
535 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
538 server = new PluginServer(mwindow, plugin_path, type);
540 case PLUGIN_TYPE_FFMPEG: {
541 server = new_ffmpeg_server(mwindow, path);
544 if( !server ) continue;
545 plugins.append(server);
546 // Create plugin server from index entry
547 server->set_title(title);
548 if( server->read_table(index_line) ) {
555 ret = check_plugin_index(plugins, plugin_dir, ".");
558 add_plugins(plugins);
560 plugins.remove_all_objects();
565 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
566 const char *plug_dir, const char *plug_path)
568 char plugin_path[BCTEXTLEN];
569 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
571 fs.set_filter( "[*.plugin][*.so]" );
572 if( fs.update(plugin_path) )
575 for( int i=0; i<fs.dir_list.total; ++i ) {
576 char fs_path[BCTEXTLEN];
577 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
578 if( fs.is_dir(fs_path) ) {
579 get_plugin_path(plugin_path, plug_dir, fs_path);
580 if( check_plugin_index(plugins, plug_dir, plugin_path) )
583 else if( !plugin_exists(fs_path, plugins) )
590 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
593 plugindb = new ArrayList<PluginServer*>;
595 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
596 create_defaults_path(index_path, PLUGIN_FILE);
597 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
598 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
599 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
600 printf("init plugin index: %s\n", plugin_path);
601 FILE *fp = fopen(index_path,"w");
603 fprintf(stderr,_("MWindow::init_plugins: "
604 "can't create plugin index: %s\n"), index_path);
607 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
608 fprintf(fp, "%s\n", plugin_path);
609 init_plugin_index(mwindow, preferences, fp, plugin_path);
610 init_ffmpeg_index(mwindow, preferences, fp);
612 return load_plugin_index(mwindow, index_path, plugin_path);
615 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
617 char *path = getenv("LADSPA_PATH");
618 char ladspa_path[BCTEXTLEN];
620 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
623 for( int len=0; *path; path+=len ) {
624 char *cp = strchr(path,':');
625 len = !cp ? strlen(path) : cp-path;
626 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
627 memcpy(plugin_path, path, len); plugin_path[len] = 0;
629 char *plugin_dir = FileSystem::basepath(plugin_path);
630 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
631 create_defaults_path(index_path, LADSPA_FILE);
632 cp = index_path + strlen(index_path);
633 for( char *bp=plugin_path; *bp!=0; ++bp )
634 *cp++ = *bp=='/' ? '_' : *bp;
636 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
637 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
638 load_plugin_index(mwindow, index_path, plugin_path);
643 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
644 FILE *fp, const char *plugin_dir)
646 int idx = PLUGIN_IDS;
648 for( int i=0; i<plugindb->size(); ++i ) {
649 PluginServer *server = plugindb->get(i);
650 if( server->dir_idx >= idx )
651 idx = server->dir_idx+1;
654 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
657 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
658 const char *index_path, const char *plugin_dir)
660 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
661 strcpy(plugin_path, path); delete [] path;
662 printf("init ladspa index: %s\n", plugin_dir);
663 FILE *fp = fopen(index_path,"w");
665 fprintf(stderr,_("MWindow::init_ladspa_index: "
666 "can't create plugin index: %s\n"), index_path);
669 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
670 fprintf(fp, "%s\n", plugin_dir);
671 init_plugin_index(mwindow, preferences, fp, plugin_path);
676 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
677 const char *plug_dir, const char *plug_path, int &idx)
679 char plugin_path[BCTEXTLEN];
680 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
682 fs.set_filter( "[*.plugin][*.so]" );
683 int result = fs.update(plugin_path);
684 if( result || !fs.dir_list.total ) return;
687 for( int i=0; i<fs.dir_list.total; ++i ) {
688 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
689 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
690 get_plugin_path(path, plug_dir, fs_path);
691 if( fs.is_dir(fs_path) ) {
692 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
695 if( plugin_exists(path) ) continue;
697 if( stat(fs_path, &st) ) continue;
698 int64_t mtime = st.st_mtime;
699 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
700 result = server.open_plugin(1, preferences, 0, 0);
702 server.write_table(fp, path, vis_id, mtime);
703 server.close_plugin();
705 else if( result == PLUGINSERVER_IS_LAD ) {
708 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
709 ladspa.set_lad_index(lad_index++);
710 result = ladspa.open_plugin(1, preferences, 0, 0);
712 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
713 ladspa.close_plugin();
719 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
721 for( int i=0; i<plugins.size(); ++i )
722 plugindb->append(plugins[i]);
723 plugins.remove_all();
726 void MWindow::delete_plugins()
728 plugindb->remove_all_objects();
733 void MWindow::search_plugindb(int do_audio,
738 ArrayList<PluginServer*> &results)
741 for(int i = 0; i < MWindow::plugindb->total; i++)
743 PluginServer *current = MWindow::plugindb->get(i);
745 if(current->audio == do_audio &&
746 current->video == do_video &&
747 (current->realtime == is_realtime || is_realtime < 0) &&
748 current->transition == is_transition &&
749 current->theme == is_theme)
750 results.append(current);
753 // Alphabetize list by title
759 for(int i = 0; i < results.total - 1; i++)
761 PluginServer *value1 = results[i];
762 PluginServer *value2 = results[i + 1];
763 if(strcmp(_(value1->title), _(value2->title)) > 0)
767 results[i + 1] = value1;
773 PluginServer* MWindow::scan_plugindb(char *title,
778 // printf("MWindow::scan_plugindb data_type < 0\n");
782 for(int i = 0; i < plugindb->total; i++)
784 PluginServer *server = plugindb->get(i);
786 !strcasecmp(server->title, title) &&
788 (data_type == TRACK_AUDIO && server->audio) ||
789 (data_type == TRACK_VIDEO && server->video)))
790 return plugindb->get(i);
795 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
797 for( int i=0; i<plugins.size(); ++i )
798 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
802 int MWindow::plugin_exists(char *plugin_path)
804 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
807 void MWindow::init_preferences()
809 preferences = new Preferences;
810 preferences->load_defaults(defaults);
811 session = new MainSession(this);
812 session->load_defaults(defaults);
813 // set x11_host, screens, window_config
814 screens = session->set_default_x11_host();
815 BC_Signals::set_trap_hook(trap_hook, this);
816 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
817 BC_Signals::set_catch_intr(preferences->trap_sigintr);
818 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
819 BC_Trace::enable_locks();
822 BC_Trace::disable_locks();
824 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
825 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
828 void MWindow::clean_indexes()
833 int oldest_item = -1;
835 char string[BCTEXTLEN];
836 char string2[BCTEXTLEN];
838 // Delete extra indexes
839 fs.set_filter("*.idx");
840 fs.complete_path(preferences->index_directory);
841 fs.update(preferences->index_directory);
842 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
844 // Eliminate directories
849 for(int i = 0; i < fs.dir_list.total && !result; i++)
851 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
852 if(fs.is_dir(string))
854 delete fs.dir_list[i];
855 fs.dir_list.remove_number(i);
860 total_excess = fs.dir_list.total - preferences->index_count;
862 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
863 while(total_excess > 0)
866 for(int i = 0; i < fs.dir_list.total; i++)
868 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
870 if(i == 0 || fs.get_date(string) <= oldest)
872 oldest = fs.get_date(string);
880 fs.join_names(string,
881 preferences->index_directory,
882 fs.dir_list[oldest_item]->name);
883 //printf("MWindow::clean_indexes 1 %s\n", string);
885 perror("delete_indexes");
886 delete fs.dir_list[oldest_item];
887 fs.dir_list.remove_number(oldest_item);
889 // Remove table of contents if it exists
890 strcpy(string2, string);
891 char *ptr = strrchr(string2, '.');
894 //printf("MWindow::clean_indexes 2 %s\n", string2);
895 sprintf(ptr, ".toc");
897 sprintf(ptr, ".mkr");
906 void MWindow::init_awindow()
908 awindow = new AWindow(this);
909 awindow->create_objects();
912 void MWindow::init_gwindow()
914 gwindow = new GWindow(this);
915 gwindow->create_objects();
918 void MWindow::init_tipwindow()
921 twindow = new TipWindow(this);
925 void MWindow::show_warning(int *do_warning, const char *text)
927 if( do_warning && !*do_warning ) return;
929 wwindow = new WWindow(this);
930 wwindow->show_warning(do_warning, text);
933 int MWindow::wait_warning()
935 return wwindow->wait_result();
938 void MWindow::init_theme()
943 PluginServer *theme_plugin = 0;
944 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
945 if( plugindb->get(i)->theme &&
946 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
947 theme_plugin = plugindb->get(i);
951 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
954 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
955 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
957 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
958 if( plugindb->get(i)->theme &&
959 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
960 theme_plugin = plugindb->get(i);
965 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
969 PluginServer *plugin = new PluginServer(*theme_plugin);
970 if( plugin->open_plugin(0, preferences, 0, 0) ) {
971 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
972 theme_plugin->title);
976 theme = plugin->new_theme();
977 theme->mwindow = this;
978 strcpy(theme->path, plugin->path);
981 // Load default images & settings
982 theme->Theme::initialize();
983 // Load user images & settings
985 // Create menus with user colors
986 theme->build_menus();
991 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
994 void MWindow::init_3d()
996 playback_3d = new Playback3D(this);
997 playback_3d->create_objects();
1000 void MWindow::init_edl()
1003 edl->create_objects();
1004 fill_preset_defaults(default_standard, edl->session);
1005 edl->load_defaults(defaults);
1006 edl->create_default_tracks();
1007 edl->tracks->update_y_pixels(theme);
1010 void MWindow::init_compositor()
1012 cwindow = new CWindow(this);
1013 cwindow->create_objects();
1016 void MWindow::init_levelwindow()
1018 lwindow = new LevelWindow(this);
1019 lwindow->create_objects();
1022 VWindow *MWindow::get_viewer(int start_it, int idx)
1024 vwindows_lock->lock("MWindow::get_viewer");
1025 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1026 if( !vwindow ) idx = vwindows.size();
1027 while( !vwindow && --idx >= 0 ) {
1028 VWindow *vwin = vwindows[idx];
1029 if( !vwin->is_running() || !vwin->get_edl() )
1033 vwindow = new VWindow(this);
1034 vwindow->load_defaults();
1035 vwindow->create_objects();
1036 vwindows.append(vwindow);
1038 vwindows_lock->unlock();
1039 if( start_it ) vwindow->start();
1043 void MWindow::init_cache()
1045 audio_cache = new CICache(preferences);
1046 video_cache = new CICache(preferences);
1047 frame_cache = new FrameCache;
1048 wave_cache = new WaveCache;
1051 void MWindow::init_channeldb()
1053 channeldb_buz->load("channeldb_buz");
1054 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1057 void MWindow::init_menus()
1059 char string[BCTEXTLEN];
1062 BC_CModels::to_text(string, BC_RGB888);
1063 colormodels.append(new ColormodelItem(string, BC_RGB888));
1064 BC_CModels::to_text(string, BC_RGBA8888);
1065 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1066 // BC_CModels::to_text(string, BC_RGB161616);
1067 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1068 // BC_CModels::to_text(string, BC_RGBA16161616);
1069 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1070 BC_CModels::to_text(string, BC_RGB_FLOAT);
1071 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1072 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1073 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1074 BC_CModels::to_text(string, BC_YUV888);
1075 colormodels.append(new ColormodelItem(string, BC_YUV888));
1076 BC_CModels::to_text(string, BC_YUVA8888);
1077 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1078 // BC_CModels::to_text(string, BC_YUV161616);
1079 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1080 // BC_CModels::to_text(string, BC_YUVA16161616);
1081 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1083 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1084 interlace_project_modes.append(new InterlacemodeItem(string, x));
1086 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1087 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1089 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1090 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1092 // Interlacing Modes
1093 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1095 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1096 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1098 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1099 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1101 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1102 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1104 // Interlacing Fixing Methods
1105 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1106 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1107 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1110 void MWindow::init_indexes()
1112 mainindexes = new MainIndexes(this);
1113 mainindexes->start_loop();
1116 void MWindow::init_gui()
1118 gui = new MWindowGUI(this);
1119 gui->lock_window("MWindow::init_gui");
1120 gui->create_objects();
1121 gui->unlock_window();
1122 gui->load_defaults(defaults);
1125 void MWindow::init_signals()
1127 sighandler = new SigHandler;
1128 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1132 void MWindow::init_render()
1134 render = new Render(this);
1135 create_bd = new CreateBD_Thread(this);
1136 create_dvd = new CreateDVD_Thread(this);
1137 batch_render = new BatchRenderThread(this);
1140 void MWindow::init_exportedl()
1142 exportedl = new ExportEDL(this);
1145 void MWindow::init_brender()
1147 if(preferences->use_brender && !brender)
1149 brender_lock->lock("MWindow::init_brender 1");
1150 brender = new BRender(this);
1151 brender->initialize();
1152 session->brender_end = 0;
1153 brender_lock->unlock();
1156 if(!preferences->use_brender && brender)
1158 brender_lock->lock("MWindow::init_brender 2");
1161 session->brender_end = 0;
1162 brender_lock->unlock();
1164 if(brender) brender->restart(edl);
1167 void MWindow::restart_brender()
1169 //printf("MWindow::restart_brender 1\n");
1170 if(brender) brender->restart(edl);
1173 void MWindow::stop_brender()
1175 if(brender) brender->stop();
1178 int MWindow::brender_available(int position)
1181 brender_lock->lock("MWindow::brender_available 1");
1184 if(brender->map_valid)
1186 brender->map_lock->lock("MWindow::brender_available 2");
1187 if(position < brender->map_size &&
1190 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1191 if(brender->map[position] == BRender::RENDERED)
1194 brender->map_lock->unlock();
1197 brender_lock->unlock();
1201 void MWindow::set_brender_range()
1203 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1204 edl->session->brender_end = edl->local_session->get_selectionend(1);
1206 if(EQUIV(edl->session->brender_end, edl->session->brender_start))
1208 edl->session->brender_end = edl->tracks->total_video_length();
1212 gui->draw_overlays(1);
1216 int MWindow::has_commercials()
1218 return theme->use_commercials;
1221 void MWindow::init_commercials()
1223 if( !commercials ) {
1224 commercials = new Commercials(this);
1225 commercial_active = 0;
1228 commercials->add_user();
1231 void MWindow::commit_commercial()
1233 if( !commercial_active ) return;
1234 commercial_active = 0;
1235 if( !commercials ) return;
1236 commercials->commitDb();
1239 void MWindow::undo_commercial()
1241 if( !commercial_active ) return;
1242 commercial_active = 0;
1243 if( !commercials ) return;
1244 commercials->undoDb();
1247 int MWindow::put_commercial()
1249 double start = edl->local_session->get_selectionstart();
1250 double end = edl->local_session->get_selectionend();
1251 if( start >= end ) return 0;
1253 const char *errmsg = 0;
1255 Tracks *tracks = edl->tracks;
1258 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1259 if( track->data_type != TRACK_VIDEO ) continue;
1260 if( !track->record ) continue;
1261 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1263 int64_t units_start = track->to_units(start,0);
1264 int64_t units_end = track->to_units(end,0);
1265 Edits *edits = track->edits;
1266 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1267 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1268 if(!edit1 && !edit2) continue; // nothing selected
1269 if(!edit2) { // edit2 beyond end of track
1270 edit2 = edits->last;
1271 units_end = edits->length();
1273 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1274 Indexable *indexable = edit1->get_source();
1275 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1278 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1279 if( track->data_type != TRACK_VIDEO ) continue;
1280 if( !track->record ) continue;
1281 int64_t units_start = track->to_units(start,0);
1282 int64_t units_end = track->to_units(end,0);
1283 Edits *edits = track->edits;
1284 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1285 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1286 if(!edit1 && !edit2) continue; // nothing selected
1287 if(!edit2) { // edit2 beyond end of track
1288 edit2 = edits->last;
1289 units_end = edits->length();
1291 Indexable *indexable = edit1->get_source();
1292 Asset *asset = (Asset *)indexable;
1293 File *file = video_cache->check_out(asset, edl);
1294 if( !file ) { errmsg = _("no file"); break; }
1295 int64_t edit_length = units_end - units_start;
1296 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1297 result = commercials->put_clip(file, edit1->channel,
1298 track->from_units(edit_start), track->from_units(edit_length));
1299 video_cache->check_in(asset);
1300 if( result ) { errmsg = _("db failed"); break; }
1303 char string[BCTEXTLEN];
1304 sprintf(string, _("put_commercial: %s"), errmsg);
1305 MainError::show_error(string);
1312 void MWindow::stop_playback(int wait)
1314 int locked = gui->get_window_lock();
1315 if( locked ) gui->unlock_window();
1317 cwindow->playback_engine->que->send_command(STOP,
1321 cwindow->playback_engine->interrupt_playback(wait);
1323 for(int i = 0; i < vwindows.size(); i++) {
1324 VWindow *vwindow = vwindows[i];
1325 if( !vwindow->is_running() ) continue;
1326 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1327 vwindow->playback_engine->interrupt_playback(wait);
1329 if( locked ) gui->lock_window("MWindow::stop_playback");
1332 int MWindow::load_filenames(ArrayList<char*> *filenames,
1334 int update_filename)
1336 ArrayList<EDL*> new_edls;
1337 ArrayList<Asset*> new_assets;
1338 ArrayList<File*> new_files;
1339 const int debug = 0;
1340 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1343 gui->start_hourglass();
1345 // Need to stop playback since tracking depends on the EDL not getting
1349 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1350 undo->update_undo_before();
1353 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1355 // Define new_edls and new_assets to load
1356 int result = 0, ftype = -1;
1357 for(int i = 0; i < filenames->size(); i++)
1360 File *new_file = new File;
1361 Asset *new_asset = new Asset(filenames->get(i));
1362 EDL *new_edl = new EDL;
1363 char string[BCTEXTLEN];
1365 new_edl->create_objects();
1366 new_edl->copy_session(edl);
1367 new_file->set_program(edl->session->program_no);
1369 sprintf(string, _("Loading %s"), new_asset->path);
1370 gui->show_message(string);
1371 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1373 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1374 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1379 // Convert media file to EDL
1381 // Warn about odd image dimensions
1382 if(new_asset->video_data &&
1383 ((new_asset->width % 2) ||
1384 (new_asset->height % 2)))
1386 char string[BCTEXTLEN];
1387 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1391 MainError::show_error(string);
1394 if(new_asset->program >= 0 &&
1395 edl->session->program_no != new_asset->program)
1397 char string[BCTEXTLEN];
1398 sprintf(string, _("%s's index was built for program number %d\n"
1399 "Playback preference is %d.\n Using program %d."),
1400 new_asset->path, new_asset->program,
1401 edl->session->program_no, new_asset->program);
1402 MainError::show_error(string);
1406 if(load_mode != LOADMODE_RESOURCESONLY)
1409 RecordLabels *labels = edl->session->label_cells ?
1410 new RecordLabels(new_file) : 0;
1412 asset_to_edl(new_edl, new_asset, labels);
1414 new_edls.append(new_edl);
1416 new_asset->Garbage::remove_user();
1422 new_assets.append(new_asset);
1426 // Set filename to nothing for assets since save EDL would overwrite them.
1427 if(load_mode == LOADMODE_REPLACE ||
1428 load_mode == LOADMODE_REPLACE_CONCATENATE)
1431 // Reset timeline position
1432 for(int i = 0; i < TOTAL_PANES; i++)
1434 new_edl->local_session->view_start[i] = 0;
1435 new_edl->local_session->track_start[i] = 0;
1443 case FILE_NOT_FOUND:
1444 sprintf(string, _("Failed to open %s"), new_asset->path);
1445 gui->show_message(string, theme->message_error);
1449 case FILE_UNRECOGNIZED_CODEC:
1452 IndexFile indexfile(this, new_asset);
1453 result = indexfile.open_index();
1456 indexfile.close_index();
1459 // Test existing EDLs
1460 for(int j = 0; result && j <= new_edls.total; j++) {
1461 Asset *old_asset = j < new_edls.total ?
1462 new_edls[j]->assets->get_asset(new_asset->path) :
1463 edl->assets->get_asset(new_asset->path);
1465 *new_asset = *old_asset;
1473 char string[BCTEXTLEN];
1475 fs.extract_name(string, new_asset->path);
1477 strcat(string, _("'s format couldn't be determined."));
1478 new_asset->audio_data = 1;
1479 new_asset->format = FILE_PCM;
1480 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1481 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1482 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1483 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1484 new_asset->signed_ = defaults->get("SIGNED_", 1);
1485 new_asset->header = defaults->get("HEADER", 0);
1487 FileFormat fwindow(this);
1488 fwindow.create_objects(new_asset, string);
1489 result = fwindow.run_window();
1492 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1493 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1494 defaults->update("AUDIO_BITS", new_asset->bits);
1495 defaults->update("BYTE_ORDER", new_asset->byte_order);
1496 defaults->update("SIGNED_", new_asset->signed_);
1497 defaults->update("HEADER", new_asset->header);
1504 // Recalculate length
1506 new_file = new File;
1507 result = new_file->open_file(preferences, new_asset, 1, 0);
1509 if(load_mode != LOADMODE_RESOURCESONLY)
1511 RecordLabels *labels = edl->session->label_cells ?
1512 new RecordLabels(new_file) : 0;
1513 asset_to_edl(new_edl, new_asset, labels);
1514 new_edls.append(new_edl);
1515 new_asset->Garbage::remove_user();
1521 new_assets.append(new_asset);
1535 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1536 xml_file.read_from_file(filenames->get(i));
1537 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1538 const char *cin_version = 0;
1539 while( !xml_file.read_tag() ) {
1540 if( xml_file.tag.title_is("EDL") ) {
1541 cin_version = xml_file.tag.get_property("VERSION");
1546 if( !cin_version ) {
1547 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1548 char string[BCTEXTLEN];
1549 sprintf(string,_("Unknown %s"), filenames->get(i));
1550 gui->show_message(string);
1554 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1555 char string[BCTEXTLEN];
1556 snprintf(string, sizeof(string),
1557 _("Warning: XML from cinelerra version %s\n"
1558 "Session data may be incompatible."), cin_version);
1559 show_warning(&preferences->warn_version, string);
1561 if(load_mode == LOADMODE_NESTED)
1563 // Load temporary EDL for nesting.
1564 EDL *nested_edl = new EDL;
1565 nested_edl->create_objects();
1566 nested_edl->set_path(filenames->get(i));
1567 nested_edl->load_xml(&xml_file, LOAD_ALL);
1568 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1569 edl_to_nested(new_edl, nested_edl);
1570 nested_edl->Garbage::remove_user();
1574 // Load EDL for pasting
1575 new_edl->load_xml(&xml_file, LOAD_ALL);
1576 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1577 test_plugins(new_edl, filenames->get(i));
1578 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1580 if(load_mode == LOADMODE_REPLACE ||
1581 load_mode == LOADMODE_REPLACE_CONCATENATE)
1583 strcpy(session->filename, filenames->get(i));
1584 strcpy(new_edl->local_session->clip_title,
1587 set_filename(new_edl->local_session->clip_title);
1591 new_edls.append(new_edl);
1597 // edls are in new_edls
1598 if( result && new_edl ) new_edl->Garbage::remove_user();
1599 // assets are copied
1600 if( new_asset ) new_asset->Garbage::remove_user();
1602 // Store for testing index
1603 new_files.append(new_file);
1606 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1609 if(!result) gui->statusbar->default_message();
1617 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1620 // Don't back up here.
1623 // For pasting, clear the active region
1624 if(load_mode == LOADMODE_PASTE ||
1625 load_mode == LOADMODE_NESTED)
1627 double start = edl->local_session->get_selectionstart();
1628 double end = edl->local_session->get_selectionend();
1629 if(!EQUIV(start, end))
1632 edl->session->labels_follow_edits,
1633 edl->session->plugins_follow_edits,
1634 edl->session->autos_follow_edits);
1637 paste_edls(&new_edls,
1641 edl->session->labels_follow_edits,
1642 edl->session->plugins_follow_edits,
1643 edl->session->autos_follow_edits,
1650 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1652 // Add new assets to EDL and schedule assets for index building.
1653 int got_indexes = 0;
1654 for(int i = 0; i < new_edls.size(); i++)
1656 EDL *new_edl = new_edls[i];
1657 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1659 mainindexes->add_next_asset(0,
1660 new_edl->nested_edls->get(j));
1662 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1667 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1668 if(new_assets.size())
1670 for(int i = 0; i < new_assets.size(); i++)
1672 Asset *new_asset = new_assets[i];
1676 for(int j = 0; j < new_files.size(); j++)
1678 new_file = new_files[j];
1679 if(!strcmp(new_file->asset->path,
1687 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1689 edl->assets->update(new_asset);
1695 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1697 // Start examining next batch of index files
1698 if(got_indexes) mainindexes->start_build();
1699 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1702 Track *track = edl->tracks->first;
1705 for(int j = 0; j < track->plugin_set.size(); j++)
1707 PluginSet *plugins = track->plugin_set[j];
1708 Plugin *plugin = plugins->get_first_plugin();
1712 if(load_mode == LOADMODE_REPLACE ||
1713 load_mode == LOADMODE_REPLACE_CONCATENATE)
1715 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1718 show_plugin(plugin);
1726 plugin = (Plugin*)plugin->next;
1730 track = track->next;
1733 // if just opening one new resource in replace mode
1734 if( ftype != FILE_IS_XML &&
1735 ( load_mode == LOADMODE_REPLACE ||
1736 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1738 edl->local_session->preview_start = 0;
1739 edl->local_session->preview_end = edl->tracks->total_playable_length();
1740 edl->local_session->loop_playback = 0;
1741 edl->local_session->set_selectionstart(0);
1742 edl->local_session->set_selectionend(0);
1747 // need to update undo before project, since mwindow is unlocked & a new load
1748 // can begin here. Should really prevent loading until we're done.
1749 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1750 undo->update_undo_after(_("load"), LOAD_ALL);
1752 for(int i = 0; i < new_edls.size(); i++)
1754 new_edls[i]->remove_user();
1756 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1758 new_edls.remove_all();
1760 for(int i = 0; i < new_assets.size(); i++)
1762 new_assets[i]->Garbage::remove_user();
1765 new_assets.remove_all();
1766 new_files.remove_all_objects();
1769 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1770 if(load_mode == LOADMODE_REPLACE ||
1771 load_mode == LOADMODE_REPLACE_CONCATENATE)
1773 session->changes_made = 0;
1777 session->changes_made = 1;
1780 gui->stop_hourglass();
1783 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1784 update_project(load_mode);
1786 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1794 void MWindow::test_plugins(EDL *new_edl, char *path)
1796 char string[BCTEXTLEN];
1798 // Do a check weather plugins exist
1799 for(Track *track = new_edl->tracks->first; track; track = track->next)
1801 for(int k = 0; k < track->plugin_set.total; k++)
1803 PluginSet *plugin_set = track->plugin_set[k];
1804 for(Plugin *plugin = (Plugin*)plugin_set->first;
1806 plugin = (Plugin*)plugin->next)
1808 if(plugin->plugin_type == PLUGIN_STANDALONE)
1810 // ok we need to find it in plugindb
1811 int plugin_found = 0;
1813 for(int j = 0; j < plugindb->size(); j++)
1815 PluginServer *server = plugindb->get(j);
1817 !strcasecmp(server->title, plugin->title) &&
1818 ((track->data_type == TRACK_AUDIO && server->audio) ||
1819 (track->data_type == TRACK_VIDEO && server->video)) &&
1820 (!server->transition))
1827 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1828 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1829 "effect", plugin->title,
1831 MainError::show_error(string);
1837 for(Edit *edit = (Edit*)track->edits->first;
1839 edit = (Edit*)edit->next)
1841 if (edit->transition)
1843 // ok we need to find transition in plugindb
1845 int transition_found = 0;
1846 for(int j = 0; j < plugindb->size(); j++)
1848 PluginServer *server = plugindb->get(j);
1850 !strcasecmp(server->title, edit->transition->title) &&
1851 ((track->data_type == TRACK_AUDIO && server->audio) ||
1852 (track->data_type == TRACK_VIDEO && server->video)) &&
1853 (server->transition))
1854 transition_found = 1;
1857 if (!transition_found)
1860 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1861 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1862 "transition", edit->transition->title,
1864 MainError::show_error(string);
1872 void MWindow::init_shm()
1874 // Fix shared memory
1875 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1877 fprintf(fd, "0x7fffffff");
1882 fd = fopen("/proc/sys/kernel/shmmax", "r");
1884 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1889 fscanf(fd, "%jd", &result);
1892 if(result < 0x7fffffff) {
1893 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1894 "you probably need to be root, or:\n"
1895 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1896 "before trying to start cinelerra.\n"
1897 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1901 void MWindow::create_objects(int want_gui,
1906 const int debug = 0;
1907 if(debug) PRINT_TRACE
1909 // For some reason, init_signals must come after show_splash or the signals won't
1912 if(debug) PRINT_TRACE
1915 if(debug) PRINT_TRACE
1918 if(debug) PRINT_TRACE
1919 default_standard = default_std();
1920 init_defaults(defaults, config_path);
1924 splash_window->operation->update(_("Initializing Plugins"));
1925 init_plugins(this, preferences);
1926 if(debug) PRINT_TRACE
1927 init_ladspa_plugins(this, preferences);
1928 if(debug) PRINT_TRACE
1930 splash_window->operation->update(_("Initializing GUI"));
1931 if(debug) PRINT_TRACE
1934 if(debug) PRINT_TRACE
1938 splash_window->operation->update(_("Initializing Fonts"));
1939 char string[BCTEXTLEN];
1940 strcpy(string, preferences->plugin_dir);
1941 strcat(string, "/" FONT_SEARCHPATH);
1942 BC_Resources::init_fontconfig(string);
1943 if(debug) PRINT_TRACE
1945 // Initialize before too much else is running
1946 // Preferences & theme are required for building MPEG table of contents
1948 // Default project created here
1950 if(debug) PRINT_TRACE
1953 if(debug) PRINT_TRACE
1958 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1960 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1961 if(session->show_vwindow)
1962 get_viewer(1, DEFAULT_VWINDOW);
1963 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1966 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1969 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1972 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1974 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1977 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1981 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1983 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1985 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1989 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1990 mainprogress = new MainProgress(this, gui);
1991 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1992 undo = new MainUndo(this);
1994 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1996 plugin_guis = new ArrayList<PluginServer*>;
1997 dead_plugins = new ArrayList<PluginServer*>;
1998 keyframe_threads = new ArrayList<KeyFrameThread*>;
2000 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2003 session->show_vwindow);
2005 // Show all vwindows
2006 // if(session->show_vwindow) {
2007 // for(int j = 0; j < vwindows.size(); j++) {
2008 // VWindow *vwindow = vwindows[j];
2009 // if( !vwindow->is_running() ) continue;
2010 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2013 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2014 // vwindow->gui->lock_window("MWindow::create_objects 1");
2015 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2016 // vwindow->gui->show_window();
2017 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2018 // vwindow->gui->unlock_window();
2023 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2025 if(session->show_cwindow)
2027 cwindow->gui->lock_window("MWindow::create_objects 1");
2028 cwindow->gui->show_window();
2029 cwindow->gui->unlock_window();
2032 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2033 if(session->show_awindow)
2035 awindow->gui->lock_window("MWindow::create_objects 1");
2036 awindow->gui->show_window();
2037 awindow->gui->unlock_window();
2040 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2041 if(session->show_lwindow)
2043 lwindow->gui->lock_window("MWindow::create_objects 1");
2044 lwindow->gui->show_window();
2045 lwindow->gui->unlock_window();
2048 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2050 (int)timer.get_difference(),
2052 if(session->show_gwindow)
2054 gwindow->gui->lock_window("MWindow::create_objects 1");
2055 gwindow->gui->show_window();
2056 gwindow->gui->unlock_window();
2059 if(debug) PRINT_TRACE
2061 gui->lock_window("MWindow::create_objects 1");
2062 gui->mainmenu->load_defaults(defaults);
2063 gui->mainmenu->update_toggles(0);
2064 gui->update_patchbay();
2065 gui->draw_canvas(0, 0);
2066 gui->draw_cursor(1);
2068 gui->raise_window();
2069 gui->unlock_window();
2071 if(debug) PRINT_TRACE
2073 if(preferences->use_tipwindow)
2075 if(debug) PRINT_TRACE
2077 gui->add_keyboard_listener(
2078 (int (BC_WindowBase::*)(BC_WindowBase *))
2079 &MWindowGUI::keyboard_listener);
2083 if(debug) PRINT_TRACE
2085 BC_WindowBase::get_resources()->vframe_shm = 1;
2089 void MWindow::show_splash()
2091 #include "data/heroine_logo9_png.h"
2092 VFrame *frame = new VFramePng(heroine_logo9_png);
2093 BC_DisplayInfo dpyi;
2094 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2095 int rr = (rw < rh ? rw : rh) / 4;
2096 splash_window = new SplashGUI(frame, rr, rr);
2097 splash_window->create_objects();
2100 void MWindow::hide_splash()
2103 delete splash_window;
2108 void MWindow::start()
2112 // vwindows[DEFAULT_VWINDOW]->start();
2123 playback_3d->start();
2129 run_lock->lock("MWindow::run");
2133 brender_lock->lock("MWindow::run 1");
2134 delete brender; brender = 0;
2135 brender_lock->unlock();
2137 interrupt_indexes();
2143 void MWindow::show_vwindow()
2145 int total_running = 0;
2146 session->show_vwindow = 1;
2148 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2149 // Raise all windows which are visible
2150 for(int j = 0; j < vwindows.size(); j++) {
2151 VWindow *vwindow = vwindows[j];
2152 if( !vwindow->is_running() ) continue;
2153 vwindow->gui->lock_window("MWindow::show_vwindow");
2154 vwindow->gui->show_window(0);
2155 vwindow->gui->raise_window();
2156 vwindow->gui->flush();
2157 vwindow->gui->unlock_window();
2161 // If no windows visible
2164 get_viewer(1, DEFAULT_VWINDOW);
2167 gui->mainmenu->show_vwindow->set_checked(1);
2170 void MWindow::show_awindow()
2172 session->show_awindow = 1;
2173 awindow->gui->lock_window("MWindow::show_awindow");
2174 awindow->gui->show_window();
2175 awindow->gui->raise_window();
2176 awindow->gui->flush();
2177 awindow->gui->unlock_window();
2178 gui->mainmenu->show_awindow->set_checked(1);
2181 char *MWindow::get_cwindow_display()
2183 char *x11_host = screens < 2 || session->window_config == 0 ?
2184 session->a_x11_host : session->b_x11_host;
2185 return *x11_host ? x11_host : 0;
2188 void MWindow::show_cwindow()
2190 session->show_cwindow = 1;
2191 cwindow->show_window();
2192 gui->mainmenu->show_cwindow->set_checked(1);
2195 void MWindow::show_gwindow()
2197 session->show_gwindow = 1;
2199 gwindow->gui->lock_window("MWindow::show_gwindow");
2200 gwindow->gui->show_window();
2201 gwindow->gui->raise_window();
2202 gwindow->gui->flush();
2203 gwindow->gui->unlock_window();
2205 gui->mainmenu->show_gwindow->set_checked(1);
2207 void MWindow::hide_gwindow()
2209 session->show_gwindow = 0;
2211 gwindow->gui->lock_window("MWindow::show_gwindow");
2212 gwindow->gui->hide_window();
2213 gwindow->gui->unlock_window();
2216 void MWindow::show_lwindow()
2218 session->show_lwindow = 1;
2219 lwindow->gui->lock_window("MWindow::show_lwindow");
2220 lwindow->gui->show_window();
2221 lwindow->gui->raise_window();
2222 lwindow->gui->flush();
2223 lwindow->gui->unlock_window();
2224 gui->mainmenu->show_lwindow->set_checked(1);
2227 int MWindow::tile_windows(int window_config)
2229 int need_reload = 0;
2230 int play_config = window_config==0 ? 0 : 1;
2231 edl->session->playback_config->load_defaults(defaults, play_config);
2232 session->default_window_positions(window_config);
2233 if( screens == 1 ) {
2234 gui->default_positions();
2235 sync_parameters(CHANGE_ALL);
2242 void MWindow::toggle_loop_playback()
2244 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2245 set_loop_boundaries();
2248 gui->draw_overlays(1);
2249 sync_parameters(CHANGE_PARAMS);
2252 //void MWindow::set_titles(int value)
2254 // edl->session->show_titles = value;
2255 // trackmovement(edl->local_session->track_start);
2258 void MWindow::set_screens(int value)
2263 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2265 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2266 edl->session->auto_keyframes = value;
2267 gui->mbuttons->edit_panel->keyframe->update(value);
2269 if(lock_mwindow) gui->unlock_window();
2271 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2272 cwindow->gui->edit_panel->keyframe->update(value);
2273 cwindow->gui->flush();
2274 if(lock_cwindow) cwindow->gui->unlock_window();
2277 void MWindow::set_auto_visibility(Autos *autos, int value)
2279 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2280 edl->session->auto_conf->plugins = value;
2281 else if( autos->autoidx >= 0 )
2282 edl->session->auto_conf->autos[autos->autoidx] = value;
2286 gui->update(0, 1, 0, 0, 0, 0, 0);
2287 gui->mainmenu->update_toggles(1);
2288 gui->unlock_window();
2289 gwindow->gui->update_toggles(1);
2290 gui->lock_window("MWindow::set_auto_visibility");
2293 void MWindow::set_keyframe_type(int mode)
2295 gui->lock_window("MWindow::set_keyframe_type");
2296 edl->local_session->floatauto_type = mode;
2297 gui->mainmenu->update_toggles(0);
2298 gui->unlock_window();
2301 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2303 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2304 edl->session->editing_mode = new_editing_mode;
2305 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2306 gui->mbuttons->edit_panel->update();
2307 gui->set_editing_mode(1);
2308 if(lock_mwindow) gui->unlock_window();
2311 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2312 cwindow->gui->edit_panel->update();
2313 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2314 if(lock_cwindow) cwindow->gui->unlock_window();
2318 void MWindow::toggle_editing_mode()
2320 int mode = edl->session->editing_mode;
2321 if( mode == EDITING_ARROW )
2322 set_editing_mode(EDITING_IBEAM, 0, 1);
2324 set_editing_mode(EDITING_ARROW, 0, 1);
2328 void MWindow::set_labels_follow_edits(int value)
2330 gui->lock_window("MWindow::set_labels_follow_edits");
2331 edl->session->labels_follow_edits = value;
2332 gui->mbuttons->edit_panel->locklabels->update(value);
2333 gui->mainmenu->labels_follow_edits->set_checked(value);
2335 gui->unlock_window();
2338 void MWindow::sync_parameters(int change_type)
2340 if( in_destructor ) return;
2342 // Sync engines which are playing back
2343 if(cwindow->playback_engine->is_playing_back)
2345 if(change_type == CHANGE_PARAMS)
2347 // TODO: block keyframes until synchronization is done
2348 cwindow->playback_engine->sync_parameters(edl);
2353 int command = cwindow->playback_engine->command->command;
2354 cwindow->playback_engine->que->send_command(STOP,
2358 // Waiting for tracking to finish would make the restart position more
2359 // accurate but it can't lock the window to stop tracking for some reason.
2360 // Not waiting for tracking gives a faster response but restart position is
2361 // only as accurate as the last tracking update.
2362 cwindow->playback_engine->interrupt_playback(0);
2363 cwindow->playback_engine->que->send_command(command,
2372 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2379 void MWindow::age_caches()
2381 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2383 // preferences->cache_size,
2384 // audio_cache->get_memory_usage(1),
2385 // video_cache->get_memory_usage(1),
2386 // frame_cache->get_memory_usage(),
2387 // wave_cache->get_memory_usage(),
2389 frame_cache->age_cache(512);
2390 wave_cache->age_cache(8192);
2392 int64_t memory_usage;
2393 int64_t prev_memory_usage = 0;
2395 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2396 while( !result && prev_memory_usage !=
2397 (memory_usage=video_cache->get_memory_usage(1)) &&
2398 memory_usage > video_size ) {
2399 video_cache->delete_oldest();
2400 prev_memory_usage = memory_usage;
2403 prev_memory_usage = 0;
2405 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2406 while( !result && prev_memory_usage !=
2407 (memory_usage=audio_cache->get_memory_usage(1)) &&
2408 memory_usage > audio_size ) {
2409 audio_cache->delete_oldest();
2410 prev_memory_usage = memory_usage;
2414 void MWindow::reset_android_remote()
2416 gui->use_android_remote(preferences->android_remote);
2420 void MWindow::show_keyframe_gui(Plugin *plugin)
2422 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2423 // Find existing thread
2424 for(int i = 0; i < keyframe_threads->size(); i++)
2426 if(keyframe_threads->get(i)->plugin == plugin)
2428 keyframe_threads->get(i)->start_window(plugin, 0);
2429 keyframe_gui_lock->unlock();
2434 // Find unused thread
2435 for(int i = 0; i < keyframe_threads->size(); i++)
2437 if(!keyframe_threads->get(i)->plugin)
2439 keyframe_threads->get(i)->start_window(plugin, 0);
2440 keyframe_gui_lock->unlock();
2445 // Create new thread
2446 KeyFrameThread *thread = new KeyFrameThread(this);
2447 keyframe_threads->append(thread);
2448 thread->start_window(plugin, 0);
2450 keyframe_gui_lock->unlock();
2457 void MWindow::show_plugin(Plugin *plugin)
2462 // Remove previously deleted plugin GUIs
2463 dead_plugin_lock->lock("MWindow::show_plugin");
2464 dead_plugins->remove_all_objects();
2465 dead_plugin_lock->unlock();
2467 //printf("MWindow::show_plugin %d\n", __LINE__);
2471 plugin_gui_lock->lock("MWindow::show_plugin");
2472 for(int i = 0; i < plugin_guis->total; i++)
2474 // Pointer comparison
2475 if(plugin_guis->get(i)->plugin == plugin)
2477 plugin_guis->get(i)->raise_window();
2484 //printf("MWindow::show_plugin 1\n");
2489 printf("MWindow::show_plugin track not defined.\n");
2491 PluginServer *server = scan_plugindb(plugin->title,
2492 plugin->track->data_type);
2494 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2495 if(server && server->uses_gui)
2497 PluginServer *gui = new PluginServer(*server);
2498 plugin_guis->append(gui);
2499 // Needs mwindow to do GUI
2500 gui->set_mwindow(this);
2501 gui->open_plugin(0, preferences, edl, plugin);
2506 plugin_gui_lock->unlock();
2507 //printf("MWindow::show_plugin %d\n", __LINE__);
2510 //printf("MWindow::show_plugin 2\n");
2513 void MWindow::hide_plugin(Plugin *plugin, int lock)
2516 // Update the toggle
2517 gui->lock_window("MWindow::hide_plugin");
2518 gui->update(0, 1, 0, 0, 0, 0, 0);
2519 gui->unlock_window();
2521 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2522 for(int i = 0; i < plugin_guis->total; i++)
2524 if(plugin_guis->get(i)->plugin == plugin)
2526 PluginServer *ptr = plugin_guis->get(i);
2527 plugin_guis->remove(ptr);
2528 if(lock) plugin_gui_lock->unlock();
2529 // Last command executed in client side close
2530 // Schedule for deletion
2537 if(lock) plugin_gui_lock->unlock();
2540 void MWindow::delete_plugin(PluginServer *plugin)
2542 dead_plugin_lock->lock("MWindow::delete_plugin");
2543 dead_plugins->append(plugin);
2544 dead_plugin_lock->unlock();
2547 void MWindow::hide_plugins()
2549 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2550 while(plugin_guis->size())
2552 PluginServer *ptr = plugin_guis->get(0);
2553 plugin_guis->remove(ptr);
2554 plugin_gui_lock->unlock();
2555 // Last command executed in client side close
2556 // Schedule for deletion
2559 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2561 plugin_gui_lock->unlock();
2563 hide_keyframe_guis();
2566 void MWindow::hide_keyframe_guis()
2568 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2569 for(int i = 0; i < keyframe_threads->size(); i++)
2571 keyframe_threads->get(i)->close_window();
2573 keyframe_gui_lock->unlock();
2576 void MWindow::hide_keyframe_gui(Plugin *plugin)
2578 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2579 for(int i = 0; i < keyframe_threads->size(); i++)
2581 if(keyframe_threads->get(i)->plugin == plugin)
2583 keyframe_threads->get(i)->close_window();
2587 keyframe_gui_lock->unlock();
2590 void MWindow::update_keyframe_guis()
2592 // Send new configuration to keyframe GUI's
2593 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2594 for(int i = 0; i < keyframe_threads->size(); i++)
2596 KeyFrameThread *ptr = keyframe_threads->get(i);
2597 if(edl->tracks->plugin_exists(ptr->plugin))
2601 ptr->close_window();
2604 keyframe_gui_lock->unlock();
2607 void MWindow::update_plugin_guis(int do_keyframe_guis)
2609 // Send new configuration to plugin GUI's
2610 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2612 for(int i = 0; i < plugin_guis->size(); i++)
2614 PluginServer *ptr = plugin_guis->get(i);
2615 if(edl->tracks->plugin_exists(ptr->plugin))
2619 // Schedule for deletion if no plugin
2620 plugin_guis->remove_number(i);
2629 // Change plugin variable if not visible
2630 Track *track = edl->tracks->first;
2633 for(int i = 0; i < track->plugin_set.size(); i++)
2635 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2639 for(int i = 0; i < plugin_guis->size(); i++)
2641 PluginServer *server = plugin_guis->get(i);
2642 if(server->plugin == plugin)
2649 if(!got_it) plugin->show = 0;
2651 plugin = (Plugin*)plugin->next;
2655 track = track->next;
2658 plugin_gui_lock->unlock();
2661 if(do_keyframe_guis) update_keyframe_guis();
2664 int MWindow::plugin_gui_open(Plugin *plugin)
2667 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2668 for(int i = 0; i < plugin_guis->total; i++)
2670 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2676 plugin_gui_lock->unlock();
2680 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2682 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2683 for(int i = 0; i < plugin_guis->total; i++)
2685 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2687 plugin_guis->get(i)->render_gui(data);
2691 plugin_gui_lock->unlock();
2694 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2696 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2697 for(int i = 0; i < plugin_guis->total; i++)
2699 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2701 plugin_guis->get(i)->render_gui(data, size);
2705 plugin_gui_lock->unlock();
2709 void MWindow::update_plugin_states()
2711 plugin_gui_lock->lock("MWindow::update_plugin_states");
2712 for(int i = 0; i < plugin_guis->total; i++)
2716 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2717 PluginServer *src_plugingui = plugin_guis->get(i);
2719 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2720 for(Track *track = edl->tracks->first;
2722 track = track->next)
2725 j < track->plugin_set.total && !result;
2728 PluginSet *plugin_set = track->plugin_set[j];
2729 for(Plugin *plugin = (Plugin*)plugin_set->first;
2731 plugin = (Plugin*)plugin->next)
2733 if(plugin == src_plugin &&
2734 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2740 // Doesn't exist anymore
2743 hide_plugin(src_plugin, 0);
2747 plugin_gui_lock->unlock();
2751 void MWindow::update_plugin_titles()
2753 for(int i = 0; i < plugin_guis->total; i++)
2755 plugin_guis->get(i)->update_title();
2759 int MWindow::asset_to_edl(EDL *new_edl,
2761 RecordLabels *labels)
2763 const int debug = 0;
2764 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2767 // Keep frame rate, sample rate, and output size unchanged.
2768 // These parameters would revert the project if VWindow displayed an asset
2769 // of different size than the project.
2770 if(new_asset->video_data)
2772 new_edl->session->video_tracks = new_asset->layers;
2775 new_edl->session->video_tracks = 0;
2777 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2783 if(new_asset->audio_data)
2785 new_edl->session->audio_tracks = new_asset->channels;
2788 new_edl->session->audio_tracks = 0;
2789 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2791 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2792 new_edl->create_default_tracks();
2793 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2794 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2798 //printf("MWindow::asset_to_edl 3\n");
2799 new_edl->insert_asset(new_asset,
2804 //printf("MWindow::asset_to_edl 3\n");
2805 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2807 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2808 if(edl->session->cursor_on_frames)
2810 double length = new_edl->tracks->total_length();
2811 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2812 new_edl->tracks->clear(length, edl_length, 1, 1);
2818 char string[BCTEXTLEN];
2820 fs.extract_name(string, new_asset->path);
2821 //printf("MWindow::asset_to_edl 3\n");
2823 strcpy(new_edl->local_session->clip_title, string);
2824 //printf("MWindow::asset_to_edl 4 %s\n", string);
2825 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2830 int MWindow::edl_to_nested(EDL *new_edl,
2834 // Keep frame rate, sample rate, and output size unchanged.
2835 // These parameters would revert the project if VWindow displayed an asset
2836 // of different size than the project.
2840 // Nest all video & audio outputs
2841 new_edl->session->video_tracks = 1;
2842 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2843 new_edl->create_default_tracks();
2847 new_edl->insert_asset(0,
2853 char string[BCTEXTLEN];
2855 fs.extract_name(string, nested_edl->path);
2856 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2858 strcpy(new_edl->local_session->clip_title, string);
2863 // Reset everything after a load.
2864 void MWindow::update_project(int load_mode)
2866 const int debug = 0;
2868 if(debug) PRINT_TRACE
2870 edl->tracks->update_y_pixels(theme);
2872 if(debug) PRINT_TRACE
2874 if(load_mode == LOADMODE_REPLACE ||
2875 load_mode == LOADMODE_REPLACE_CONCATENATE)
2880 gui->update(1, 1, 1, 1, 1, 1, 1);
2881 if(debug) PRINT_TRACE
2882 gui->unlock_window();
2884 cwindow->gui->lock_window("MWindow::update_project 1");
2885 cwindow->update(0, 0, 1, 1, 1);
2886 cwindow->gui->unlock_window();
2888 if(debug) PRINT_TRACE
2890 // Close all the vwindows
2891 if(load_mode == LOADMODE_REPLACE ||
2892 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2893 if(debug) PRINT_TRACE
2894 int first_vwindow = 0;
2895 if(session->show_vwindow) first_vwindow = 1;
2896 // Change visible windows to no source
2897 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2898 VWindow *vwindow = vwindows[i];
2899 if( !vwindow->is_running() ) continue;
2900 vwindow->change_source(-1);
2903 // Close remaining windows
2904 for(int i = first_vwindow; i < vwindows.size(); i++) {
2905 VWindow *vwindow = vwindows[i];
2906 if( !vwindow->is_running() ) continue;
2907 vwindow->close_window();
2909 if(debug) PRINT_TRACE
2911 else if(vwindows.size()) {
2912 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2913 if( vwindow->is_running() ) {
2914 vwindow->gui->lock_window("MWindow::update_project");
2916 vwindow->gui->unlock_window();
2920 if(debug) PRINT_TRACE
2921 cwindow->gui->lock_window("MWindow::update_project 2");
2922 cwindow->gui->timebar->update(0);
2923 cwindow->gui->unlock_window();
2925 if(debug) PRINT_TRACE
2926 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2931 awindow->gui->async_update_assets();
2932 if(debug) PRINT_TRACE
2934 gui->lock_window("MWindow::update_project");
2936 if(debug) PRINT_TRACE
2939 void MWindow::remove_indexfile(Indexable *indexable)
2941 if( !indexable->is_asset ) return;
2942 Asset *asset = (Asset *)indexable;
2944 IndexFile::delete_index(preferences, asset, ".toc");
2945 IndexFile::delete_index(preferences, asset, ".idx");
2946 IndexFile::delete_index(preferences, asset, ".mkr");
2949 void MWindow::rebuild_indices()
2951 for(int i = 0; i < session->drag_assets->total; i++)
2953 Indexable *indexable = session->drag_assets->get(i);
2954 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2955 remove_indexfile(indexable);
2956 // Schedule index build
2957 IndexState *index_state = indexable->index_state;
2958 index_state->index_status = INDEX_NOTTESTED;
2959 if( indexable->is_asset ) {
2960 Asset *asset = (Asset *)indexable;
2961 if( asset->format != FILE_PCM )
2962 asset->reset_audio();
2963 asset->reset_video();
2965 mainindexes->add_next_asset(0, indexable);
2967 mainindexes->start_build();
2971 void MWindow::save_backup()
2975 edl->set_path(session->filename);
2976 char backup_path[BCTEXTLEN];
2977 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2978 File::get_config_path(), BACKUP_FILE);
2979 edl->save_xml(&file, backup_path, 0, 0);
2980 file.terminate_string();
2982 fs.complete_path(backup_path);
2984 if(file.write_to_file(backup_path))
2987 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
2988 gui->show_message(string2);
2992 void MWindow::load_backup()
2994 ArrayList<char*> path_list;
2995 path_list.set_array_delete();
2997 char backup_path[BCTEXTLEN];
2998 snprintf(backup_path, sizeof(backup_path), "%s/%s",
2999 File::get_config_path(), BACKUP_FILE);
3001 fs.complete_path(backup_path);
3003 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3004 strcpy(out_path, backup_path);
3006 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3007 edl->local_session->clip_title[0] = 0;
3008 // This is unique to backups since the path of the backup is different than the
3009 // path of the project.
3010 set_filename(edl->path);
3011 path_list.remove_all_objects();
3015 static inline int gcd(int m, int n)
3018 if( m < n ) { r = m; m = n; n = r; }
3019 while( (r = m % n) != 0 ) { m = n; n = r; }
3023 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3026 if(!width || !height) return 1;
3027 if( width == 720 && (height == 480 || height == 576) ) {
3028 w = 4; h = 3; return 0; // for NTSC and PAL
3030 double ar = (double)width / height;
3031 // square-ish pixels
3032 if( EQUIV(ar, 1.0000) ) return 0;
3033 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3034 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3035 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3036 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3037 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3038 int ww = width, hh = height;
3039 // numerator, denominator must be under mx
3040 int mx = 255, n = gcd(ww, hh);
3041 if( n > 1 ) { ww /= n; hh /= n; }
3042 // search near height in case extra/missing lines
3043 if( ww >= mx || hh >= mx ) {
3044 double err = height; // +/- 2 percent height
3045 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3046 int iw = width, ih = height+i;
3047 if( (n=gcd(iw, ih)) > 1 ) {
3048 int u = iw/n; if( u >= mx ) continue;
3049 int v = ih/n; if( v >= mx ) continue;
3050 double r = (double) u/v, er = fabs(ar-r);
3051 if( er >= err ) continue;
3052 err = er; ww = u; hh = v;
3061 void MWindow::reset_caches()
3063 frame_cache->remove_all();
3064 wave_cache->remove_all();
3065 audio_cache->remove_all();
3066 video_cache->remove_all();
3067 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3068 cwindow->playback_engine->audio_cache->remove_all();
3069 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3070 cwindow->playback_engine->video_cache->remove_all();
3072 for(int i = 0; i < vwindows.size(); i++) {
3073 VWindow *vwindow = vwindows[i];
3074 if( !vwindow->is_running() ) continue;
3075 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3076 vwindow->playback_engine->audio_cache->remove_all();
3077 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3078 vwindow->playback_engine->video_cache->remove_all();
3082 void MWindow::remove_asset_from_caches(Asset *asset)
3084 gui->resource_thread->get_video_source(0);
3085 gui->resource_thread->get_audio_source(0);
3086 frame_cache->remove_asset(asset);
3087 wave_cache->remove_asset(asset);
3088 audio_cache->delete_entry(asset);
3089 video_cache->delete_entry(asset);
3090 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3091 cwindow->playback_engine->audio_cache->delete_entry(asset);
3092 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3093 cwindow->playback_engine->video_cache->delete_entry(asset);
3094 for(int i = 0; i < vwindows.size(); i++) {
3095 VWindow *vwindow = vwindows[i];
3096 if( !vwindow->is_running() ) continue;
3097 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
3098 vwindow->playback_engine->audio_cache->delete_entry(asset);
3099 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
3100 vwindow->playback_engine->video_cache->delete_entry(asset);
3105 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3106 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3108 for(int i = 0; i < session->drag_assets->total; i++) {
3109 Indexable *indexable = session->drag_assets->get(i);
3110 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3113 // Remove from VWindow.
3114 for(int i = 0; i < session->drag_clips->total; i++) {
3115 for(int j = 0; j < vwindows.size(); j++) {
3116 VWindow *vwindow = vwindows[j];
3117 if( !vwindow->is_running() ) continue;
3118 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3119 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3120 vwindow->delete_source(1, 1);
3121 vwindow->gui->unlock_window();
3126 for(int i = 0; i < session->drag_assets->size(); i++) {
3127 for(int j = 0; j < vwindows.size(); j++) {
3128 VWindow *vwindow = vwindows[j];
3129 if( !vwindow->is_running() ) continue;
3130 if(session->drag_assets->get(i) == vwindow->get_source()) {
3131 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3132 vwindow->delete_source(1, 1);
3133 vwindow->gui->unlock_window();
3138 for(int i = 0; i < session->drag_assets->size(); i++) {
3139 Indexable *indexable = session->drag_assets->get(i);
3140 remove_indexfile(indexable);
3143 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3144 if(push_undo) undo->update_undo_before();
3145 if(drag_assets) edl->remove_from_project(drag_assets);
3146 if(drag_clips) edl->remove_from_project(session->drag_clips);
3147 if(redraw) save_backup();
3148 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3153 gui->lock_window("MWindow::remove_assets_from_project 3");
3161 gui->unlock_window();
3163 // Removes from playback here
3164 sync_parameters(CHANGE_ALL);
3167 awindow->gui->async_update_assets();
3170 void MWindow::remove_assets_from_disk()
3173 for(int i = 0; i < session->drag_assets->total; i++)
3175 remove(session->drag_assets->get(i)->path);
3178 remove_assets_from_project(1,
3180 session->drag_assets,
3181 session->drag_clips);
3184 void MWindow::dump_plugins(FILE *fp)
3186 if( !plugindb ) return;
3187 for(int i = 0; i < plugindb->total; i++)
3189 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3190 " synth=%d transition=%d theme=%d %s\n",
3191 plugindb->get(i)->plugin_type,
3192 plugindb->get(i)->audio,
3193 plugindb->get(i)->video,
3194 plugindb->get(i)->realtime,
3195 plugindb->get(i)->multichannel,
3196 plugindb->get(i)->get_synthesis(),
3197 plugindb->get(i)->transition,
3198 plugindb->get(i)->theme,
3199 plugindb->get(i)->title);
3203 void MWindow::dump_edl(FILE *fp)
3209 void MWindow::dump_undo(FILE *fp)
3215 void MWindow::dump_exe(FILE *fp)
3217 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3218 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3220 int ret = -1, n = 100;
3221 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3222 exe_path[len] = 0; strcpy(proc_path, exe_path);
3225 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3228 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3229 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3230 struct tm *tm = localtime(&st.st_mtime);
3232 strftime(mtime, sizeof(mtime), "%F %T", tm);
3233 fprintf(fp,"mtime: %s\n", mtime);
3235 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3236 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3239 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3240 int64_t maxsz = 1024*pagsz;
3241 int64_t size = st.st_size, pos = 0;
3243 while( (bfrsz = size-pos) > 0 ) {
3244 if( bfrsz > maxsz ) bfrsz = maxsz;
3245 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3246 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3247 if( bfr == MAP_FAILED ) break;
3248 sha1.addBytes(bfr, bfrsz);
3253 ret = pos < size ? EIO : 0;
3254 fprintf(fp, "SHA1: ");
3255 uint8_t digest[20]; sha1.computeHash(digest);
3256 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3257 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3258 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3262 void MWindow::trap_hook(FILE *fp, void *vp)
3264 MWindow *mwindow = (MWindow *)vp;
3265 // fprintf(fp, "\nPLUGINS:\n");
3266 // mwindow->dump_plugins(fp);
3267 fprintf(fp, "\nEDL:\n");
3268 mwindow->dump_edl(fp);
3269 fprintf(fp, "\nUNDO:\n");
3270 mwindow->dump_undo(fp);
3271 fprintf(fp, "\nEXE:\n");
3272 mwindow->dump_exe(fp);
3280 int MWindow::save_defaults()
3282 gui->save_defaults(defaults);
3283 edl->save_defaults(defaults);
3284 session->save_defaults(defaults);
3285 preferences->save_defaults(defaults);
3287 for(int i = 0; i < plugin_guis->total; i++)
3289 // Pointer comparison
3290 plugin_guis->get(i)->save_defaults();
3292 awindow->save_defaults(defaults);
3298 int MWindow::run_script(FileXML *script)
3300 int result = 0, result2 = 0;
3301 while(!result && !result2)
3303 result = script->read_tag();
3306 if(script->tag.title_is("new_project"))
3308 // Run new in immediate mode.
3309 // gui->mainmenu->new_project->run_script(script);
3312 if(script->tag.title_is("record"))
3314 // Run record as a thread. It is a terminal command.
3316 // Will read the complete scipt file without letting record read it if not
3322 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3329 // ================================= synchronization
3332 int MWindow::interrupt_indexes()
3334 mainprogress->cancelled = 1;
3335 mainindexes->interrupt_build();
3341 void MWindow::next_time_format()
3343 switch(edl->session->time_format)
3345 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3346 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3347 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3348 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3349 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3350 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3351 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3354 time_format_common();
3357 void MWindow::prev_time_format()
3359 switch(edl->session->time_format)
3361 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3362 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3363 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3364 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3365 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3366 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3367 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3370 time_format_common();
3373 void MWindow::time_format_common()
3375 gui->lock_window("MWindow::next_time_format");
3376 gui->redraw_time_dependancies();
3379 char string[BCTEXTLEN], string2[BCTEXTLEN];
3380 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3381 gui->show_message(string);
3383 gui->unlock_window();
3387 int MWindow::set_filename(const char *filename)
3389 if( filename != session->filename )
3390 strcpy(session->filename, filename);
3391 if( filename != edl->path )
3392 strcpy(edl->path, filename);
3396 if(filename[0] == 0)
3398 gui->set_title(PROGRAM_NAME);
3403 char string[BCTEXTLEN], string2[BCTEXTLEN];
3404 dir.extract_name(string, filename);
3405 sprintf(string2, PROGRAM_NAME ": %s", string);
3406 gui->set_title(string2);
3419 int MWindow::set_loop_boundaries()
3421 double start = edl->local_session->get_selectionstart();
3422 double end = edl->local_session->get_selectionend();
3430 if(edl->tracks->total_length())
3433 end = edl->tracks->total_length();
3440 if(edl->local_session->loop_playback && start != end)
3442 edl->local_session->loop_start = start;
3443 edl->local_session->loop_end = end;
3454 int MWindow::reset_meters()
3456 cwindow->gui->lock_window("MWindow::reset_meters 1");
3457 cwindow->gui->meters->reset_meters();
3458 cwindow->gui->unlock_window();
3460 for(int j = 0; j < vwindows.size(); j++) {
3461 VWindow *vwindow = vwindows[j];
3462 if( !vwindow->is_running() ) continue;
3463 vwindow->gui->lock_window("MWindow::reset_meters 2");
3464 vwindow->gui->meters->reset_meters();
3465 vwindow->gui->unlock_window();
3468 lwindow->gui->lock_window("MWindow::reset_meters 3");
3469 lwindow->gui->panel->reset_meters();
3470 lwindow->gui->unlock_window();
3472 gui->lock_window("MWindow::reset_meters 4");
3473 gui->reset_meters();
3474 gui->unlock_window();
3479 void MWindow::resync_guis()
3483 gui->lock_window("MWindow::resync_guis");
3484 gui->update(1, 1, 1, 1, 1, 1, 0);
3485 gui->unlock_window();
3487 cwindow->gui->lock_window("MWindow::resync_guis");
3488 cwindow->gui->resize_event(cwindow->gui->get_w(),
3489 cwindow->gui->get_h());
3490 int channels = edl->session->audio_channels;
3491 cwindow->gui->meters->set_meters(channels, 1);
3492 cwindow->gui->flush();
3493 cwindow->gui->unlock_window();
3495 for(int i = 0; i < vwindows.size(); i++) {
3496 VWindow *vwindow = vwindows[i];
3497 if( !vwindow->is_running() ) continue;
3498 vwindow->gui->lock_window("MWindow::resync_guis");
3499 vwindow->gui->resize_event(vwindow->gui->get_w(),
3500 vwindow->gui->get_h());
3501 vwindow->gui->meters->set_meters(channels, 1);
3502 vwindow->gui->flush();
3503 vwindow->gui->unlock_window();
3506 lwindow->gui->lock_window("MWindow::resync_guis");
3507 lwindow->gui->panel->set_meters(channels, 1);
3508 lwindow->gui->flush();
3509 lwindow->gui->unlock_window();
3512 if(((edl->session->output_w % 4) ||
3513 (edl->session->output_h % 4)) &&
3514 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3516 MainError::show_error(
3517 _("This project's dimensions are not multiples of 4 so\n"
3518 "it can't be rendered by OpenGL."));
3523 sync_parameters(CHANGE_ALL);
3526 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3528 File *file = new File;
3529 EDLSession *session = edl->session;
3530 double old_framerate = session->frame_rate;
3531 double old_samplerate = session->sample_rate;
3532 int old_auto_keyframes = session->auto_keyframes;
3533 session->auto_keyframes = 0;
3534 int result = file->open_file(preferences, asset, 1, 0);
3535 if( !result && delete_tracks > 0 )
3536 undo->update_undo_before();
3537 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3538 // try to get asset up to date, may fail
3539 file->select_video_stream(asset, vstream);
3540 // either way use what was/is there.
3541 double framerate = asset->get_frame_rate();
3542 int width = asset->get_w();
3543 int height = asset->get_h();
3544 // must be multiple of 4 for opengl
3545 width = (width+3) & ~3; height = (height+3) & ~3;
3546 int driver = session->playback_config->vconfig->driver;
3547 int color_model = file->get_best_colormodel(asset, driver);
3548 // color_model = BC_CModels::is_yuv(color_model) ?
3549 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3550 // BC_CModels::is_float(color_model) ?
3551 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3552 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3553 // have alpha for now
3554 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3555 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3556 session->color_model = color_model;
3557 session->output_w = width;
3558 session->output_h = height;
3559 session->frame_rate = framerate;
3560 // not, asset->actual_width/actual_height
3561 asset->width = session->output_w;
3562 asset->height = session->output_h;
3563 asset->frame_rate = session->frame_rate;
3564 create_aspect_ratio(session->aspect_w, session->aspect_h,
3565 session->output_w, session->output_h);
3566 Track *track = edl->tracks->first;
3567 for( Track *next_track=0; track; track=next_track ) {
3568 next_track = track->next;
3569 if( track->data_type != TRACK_VIDEO ) continue;
3570 if( delete_tracks ) {
3571 Edit *edit = track->edits->first;
3572 for( Edit *next_edit=0; edit; edit=next_edit ) {
3573 next_edit = edit->next;
3574 if( edit->channel != vstream ||
3575 !edit->asset || !edit->asset->is_asset ||
3576 !asset->equivalent(*edit->asset,1,1,edl) )
3580 if( track->edits->first ) {
3581 track->track_w = edl->session->output_w;
3582 track->track_h = edl->session->output_h;
3584 else if( delete_tracks )
3585 edl->tracks->delete_track(track);
3587 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3589 if( !result && asset->audio_data && asset->channels > 0 ) {
3590 session->sample_rate = asset->get_sample_rate();
3591 int64_t channel_mask = 0;
3592 int astrm = !asset->video_data ? -1 :
3593 file->get_audio_for_video(vstream, astream, channel_mask);
3594 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3595 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3597 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3598 if( channels < 1 ) channels = 1;
3599 if( channels > 6 ) channels = 6;
3600 session->audio_tracks = session->audio_channels = channels;
3601 switch( channels ) {
3603 session->achannel_positions[0] = 90;
3604 session->achannel_positions[1] = 150;
3605 session->achannel_positions[2] = 30;
3606 session->achannel_positions[3] = 210;
3607 session->achannel_positions[4] = 330;
3608 session->achannel_positions[5] = 270;
3611 session->achannel_positions[0] = 180;
3612 session->achannel_positions[1] = 0;
3615 session->achannel_positions[1] = 90;
3618 if( !channels ) break;
3619 double t = 0, dt = 360./channels;
3620 for( int i=channels; --i>=0; t+=dt )
3621 session->achannel_positions[i] = int(t+0.5);
3624 remap_audio(MWindow::AUDIO_1_TO_1);
3626 if( delete_tracks ) {
3627 Track *track = edl->tracks->first;
3628 for( Track *next_track=0; track; track=next_track ) {
3629 next_track = track->next;
3630 if( track->data_type != TRACK_AUDIO ) continue;
3631 Edit *edit = track->edits->first;
3632 for( Edit *next_edit=0; edit; edit=next_edit ) {
3633 next_edit = edit->next;
3634 if( !((1<<edit->channel) & channel_mask) ||
3635 !edit->asset || !edit->asset->is_asset ||
3636 !asset->equivalent(*edit->asset,1,1,edl) )
3639 if( !track->edits->first )
3640 edl->tracks->delete_track(track);
3644 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3647 session->auto_keyframes = old_auto_keyframes;
3648 if( !result && delete_tracks > 0 ) {
3650 undo->update_undo_after(_("select asset"), LOAD_ALL);
3656 int MWindow::select_asset(int vtrack, int delete_tracks)
3658 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3660 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3661 if( !track ) return 1;
3662 Edit *edit = track->edits->first;
3663 if( !edit ) return 1;
3664 Asset *asset = edit->asset;
3665 if( !asset || !asset->is_asset ) return 1;
3666 return select_asset(asset, edit->channel, 0, delete_tracks);
3669 void MWindow::dump_plugindb(FILE *fp)
3671 if( !plugindb ) return;
3672 for(int i = 0; i < plugindb->total; i++)
3673 plugindb->get(i)->dump(fp);
3676 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
3679 double unit_position = edl->local_session->get_selectionstart(1);
3680 unit_position = patch->track->to_units(unit_position, 0);
3682 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
3683 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3686 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
3689 double unit_position = edl->local_session->get_selectionstart(1);
3690 unit_position = patch->track->to_units(unit_position, 0);
3692 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
3693 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
3696 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
3699 double unit_position = edl->local_session->get_selectionstart(1);
3700 unit_position = patch->track->to_units(unit_position, 0);
3702 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
3703 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);