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
21 #include "aboutprefs.h"
25 #include "audioalsa.h"
27 #include "awindowgui.h"
29 #include "batchrender.h"
30 #include "bcdisplayinfo.h"
31 #include "bcsignals.h"
38 #include "channeldb.h"
39 #include "channelinfo.h"
42 #include "bccmodels.h"
43 #include "commercials.h"
44 #include "confirmsave.h"
45 #include "cplayback.h"
47 #include "cwindowgui.h"
49 #include "cwindowtool.h"
51 #include "devicedvbinput.inc"
52 #include "dvdcreate.h"
53 #include "editpanel.h"
55 #include "edlsession.h"
57 #include "fileformat.h"
59 #include "filesystem.h"
61 #include "floatautos.h"
62 #include "framecache.h"
64 #include "gwindowgui.h"
65 #include "keyframegui.h"
66 #include "indexfile.h"
68 #include "interlacemodes.h"
70 #include "levelwindowgui.h"
71 #include "levelwindow.h"
72 #include "loadfile.inc"
73 #include "localsession.h"
74 #include "maincursor.h"
75 #include "mainerror.h"
76 #include "mainindexes.h"
78 #include "mainprogress.h"
79 #include "mainsession.h"
83 #include "mwindowgui.h"
88 #include "playback3d.h"
89 #include "playbackengine.h"
91 #include "pluginserver.h"
92 #include "pluginset.h"
93 #include "preferences.h"
96 #include "recordmonitor.h"
97 #include "recordlabel.h"
98 #include "removefile.h"
100 #include "resourcethread.h"
101 #include "samplescroll.h"
103 #include "sighandler.h"
104 #include "splashgui.h"
105 #include "statusbar.h"
107 #include "threadloader.h"
109 #include "timelinepane.h"
110 #include "tipwindow.h"
111 #include "trackcanvas.h"
113 #include "tracking.h"
114 #include "trackscroll.h"
116 #include "transition.h"
117 #include "transportque.h"
120 #include "versioninfo.h"
121 #include "videodevice.inc"
122 #include "videowindow.h"
123 #include "vplayback.h"
124 #include "vwindowgui.h"
126 #include "wavecache.h"
130 #include "zwindowgui.h"
131 #include "exportedl.h"
133 #include "defaultformats.h"
134 #include "ntsczones.h"
141 #include <sys/types.h>
142 #include <sys/stat.h>
143 #include <sys/time.h>
144 #include <sys/mman.h>
155 // Hack for libdv to remove glib dependancy
158 // g_log (const char *log_domain,
160 // const char *format,
166 // g_logv (const char *log_domain,
168 // const char *format,
177 extern long cin_timezone;
179 ArrayList<PluginServer*>* MWindow::plugindb = 0;
180 Commercials* MWindow::commercials = 0;
186 run_lock = new Mutex("MWindow::run_lock");
187 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
188 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
189 vwindows_lock = new Mutex("MWindow::vwindows_lock");
190 zwindows_lock = new Mutex("MWindow::zwindows_lock");
191 brender_lock = new Mutex("MWindow::brender_lock");
192 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
200 commercial_active = 0;
212 strcpy(cin_lang,"en");
213 channeldb_buz = new ChannelDB;
214 channeldb_v4l2jpeg = new ChannelDB;
217 keyframe_threads = 0;
239 // Need to delete brender temporary here.
242 run_lock->lock("MWindow::~MWindow");
244 //printf("MWindow::~MWindow %d\n", __LINE__);
245 gui->remote_control->deactivate();
248 gui->channel_info->stop();
251 delete create_bd; create_bd = 0;
252 delete create_dvd; create_dvd = 0;
253 delete batch_render; batch_render = 0;
254 delete render; render = 0;
256 if( commercials && !commercials->remove_user() ) commercials = 0;
258 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
259 // Save defaults for open plugins
260 plugin_gui_lock->lock("MWindow::~MWindow");
261 for(int i = 0; i < plugin_guis->size(); i++) {
262 plugin_guis->get(i)->hide_gui();
263 delete_plugin(plugin_guis->get(i));
265 plugin_gui_lock->unlock();
266 hide_keyframe_guis();
269 // Give up and go to a movie
270 // cant run valgrind if this is used
272 gui->del_keyboard_listener(
273 (int (BC_WindowBase::*)(BC_WindowBase *))
274 &MWindowGUI::keyboard_listener);
276 // release the hounds
277 if( awindow && awindow->gui ) awindow->gui->close(0);
278 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
279 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
280 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
281 if( twindow && twindow->is_running() ) twindow->close_window();
282 if( wwindow && wwindow->is_running() ) wwindow->close_window();
283 vwindows.remove_all_objects();
284 zwindows.remove_all_objects();
286 if( awindow ) awindow->join();
287 if( cwindow ) cwindow->join();
288 if( lwindow ) lwindow->join();
289 if( twindow ) twindow->join();
290 if( wwindow ) wwindow->join();
291 if( gwindow ) gwindow->join();
294 // one at a time, or nouveau chokes
295 #define close_gui(win) if( win ) { \
296 if( win->gui ) win->gui->close(0); \
304 vwindows.remove_all_objects();
305 zwindows.remove_all_objects();
310 dead_plugins->remove_all_objects();
311 // must delete theme before destroying plugindb
312 // theme destructor will be deleted by delete_plugins
313 delete theme; theme = 0;
316 keyframe_threads->remove_all_objects();
317 colormodels.remove_all_objects();
318 delete awindow; awindow = 0;
319 delete lwindow; lwindow = 0;
320 delete twindow; twindow = 0;
321 delete wwindow; wwindow = 0;
322 delete gwindow; gwindow = 0;
323 delete cwindow; cwindow = 0;
325 delete mainindexes; mainindexes = 0;
326 delete mainprogress; mainprogress = 0;
327 delete audio_cache; audio_cache = 0; // delete the cache after the assets
328 delete video_cache; video_cache = 0; // delete the cache after the assets
329 delete frame_cache; frame_cache = 0;
330 delete wave_cache; wave_cache = 0;
331 delete plugin_guis; plugin_guis = 0;
332 delete dead_plugins; dead_plugins = 0;
333 delete keyframe_threads; keyframe_threads = 0;
334 delete undo; undo = 0;
335 delete preferences; preferences = 0;
336 delete exportedl; exportedl = 0;
337 delete session; session = 0;
338 delete defaults; defaults = 0;
339 delete assets; assets = 0;
340 delete splash_window; splash_window = 0;
341 if( !edl->Garbage::remove_user() ) edl = 0;
342 delete channeldb_buz;
343 delete channeldb_v4l2jpeg;
344 // This must be last thread to exit
345 delete playback_3d; playback_3d = 0;
346 delete dead_plugin_lock;
347 delete plugin_gui_lock;
348 delete vwindows_lock;
349 delete zwindows_lock;
351 delete keyframe_gui_lock;
352 colormodels.remove_all_objects();
353 interlace_project_modes.remove_all_objects();
354 interlace_asset_modes.remove_all_objects();
355 interlace_asset_fixmethods.remove_all_objects();
356 sighandler->terminate();
367 void MWindow::init_error()
369 MainError::init_error(this);
372 void MWindow::finit_error()
374 MainError::finit_error();
377 void MWindow::create_defaults_path(char *string, const char *config_file)
379 // set the .bcast path
382 sprintf(string, "%s/", File::get_config_path());
383 fs.complete_path(string);
384 if(!fs.is_dir(string))
385 fs.create_dir(string);
388 strcat(string, config_file);
390 const char *MWindow::default_std()
392 char buf[BCTEXTLEN], *p = 0;
394 int fd = open(TIMEZONE_NAME, O_RDONLY);
396 int l = read(fd, buf, sizeof(buf)-1);
399 if( buf[l-1] == '\n' ) --l;
405 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
408 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
409 p += strlen(ZONEINFO_STR);
414 for( int i=0; ntsc_zones[i]; ++i ) {
415 if( !strcmp(ntsc_zones[i], p) )
422 for( int i=0; ntsc_zones[i]; ++i ) {
423 if( !strcmp(ntsc_zones[i], p) )
428 // cin_timezone: Seconds west of UTC. 240sec/deg
429 double tz_deg = -cin_timezone / 240.;
430 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
431 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
434 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
436 struct formatpresets *fpr;
438 for(fpr = &format_presets[0]; fpr->name; fpr++)
440 if(strcmp(_(fpr->name), preset) == 0)
442 session->audio_channels = fpr->audio_channels;
443 session->audio_tracks = fpr->audio_tracks;
444 session->sample_rate = fpr->sample_rate;
445 session->video_channels = fpr->video_channels;
446 session->video_tracks = fpr->video_tracks;
447 session->frame_rate = fpr->frame_rate;
448 session->output_w = fpr->output_w;
449 session->output_h = fpr->output_h;
450 session->aspect_w = fpr->aspect_w;
451 session->aspect_h = fpr->aspect_h;
452 session->interlace_mode = fpr->interlace_mode;
453 session->color_model = fpr->color_model;
459 const char *MWindow::get_preset_name(int index)
461 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
463 return _(format_presets[index].name);
467 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
469 char path[BCTEXTLEN];
470 // Use user supplied path
472 strcpy(path, config_path);
474 create_defaults_path(path, CONFIG_FILE);
477 defaults = new BC_Hash(path);
482 void MWindow::check_language()
484 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
485 const char *env_lang = getenv("LANGUAGE");
486 if( !env_lang ) env_lang = getenv("LC_ALL");
487 if( !env_lang ) env_lang = getenv("LANG");
489 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
490 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
491 env_lang = curr_lang;
493 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
494 defaults->get("LAST_LANG",last_lang);
495 if( strcmp(env_lang,last_lang)) {
496 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
497 defaults->update("LAST_LANG",env_lang);
498 char plugin_path[BCTEXTLEN];
499 create_defaults_path(plugin_path, PLUGIN_FILE);
500 ::remove(plugin_path);
501 char ladspa_path[BCTEXTLEN];
502 create_defaults_path(ladspa_path, LADSPA_FILE);
503 ::remove(ladspa_path);
506 if( strlen(env_lang) > 1 &&
507 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
508 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
511 strcpy(cin_lang, "en");
514 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
516 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
518 const char *dp = plug_dir;
519 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
520 bp = !*dp && *bp == '/' ? bp+1 : base_path;
526 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
529 FILE *fp = fopen(index_path, "r");
533 char index_line[BCTEXTLEN];
534 int index_version = -1, len = strlen(plugin_dir);
535 if( !fgets(index_line, BCTEXTLEN, fp) ||
536 sscanf(index_line, "%d", &index_version) != 1 ||
537 index_version != PLUGIN_FILE_VERSION ||
538 !fgets(index_line, BCTEXTLEN, fp) ||
539 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
540 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
542 ArrayList<PluginServer*> plugins;
543 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
544 if( index_line[0] == ';' ) continue;
545 if( index_line[0] == '#' ) continue;
546 int type = PLUGIN_TYPE_UNKNOWN;
547 char path[BCTEXTLEN], title[BCTEXTLEN];
549 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
552 PluginServer *server = 0;
554 case PLUGIN_TYPE_BUILTIN:
555 case PLUGIN_TYPE_EXECUTABLE:
556 case PLUGIN_TYPE_LADSPA: {
557 char plugin_path[BCTEXTLEN]; struct stat st;
558 sprintf(plugin_path, "%s/%s", plugin_dir, path);
559 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
562 server = new PluginServer(mwindow, plugin_path, type);
564 case PLUGIN_TYPE_FFMPEG: {
565 server = new_ffmpeg_server(mwindow, path);
567 case PLUGIN_TYPE_LV2: {
568 server = new_lv2_server(mwindow, path);
571 if( !server ) continue;
572 plugins.append(server);
573 // Create plugin server from index entry
574 server->set_title(title);
575 if( server->read_table(index_line) ) {
582 ret = check_plugin_index(plugins, plugin_dir, ".");
585 add_plugins(plugins);
587 plugins.remove_all_objects();
592 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
593 const char *plug_dir, const char *plug_path)
595 char plugin_path[BCTEXTLEN];
596 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
598 fs.set_filter( "[*.plugin][*.so]" );
599 if( fs.update(plugin_path) )
602 for( int i=0; i<fs.dir_list.total; ++i ) {
603 char fs_path[BCTEXTLEN];
604 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
605 if( fs.is_dir(fs_path) ) {
606 get_plugin_path(plugin_path, plug_dir, fs_path);
607 if( check_plugin_index(plugins, plug_dir, plugin_path) )
610 else if( !plugin_exists(fs_path, plugins) )
617 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
620 plugindb = new ArrayList<PluginServer*>;
622 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
623 create_defaults_path(index_path, PLUGIN_FILE);
624 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
625 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
626 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
627 printf("init plugin index: %s\n", plugin_path);
628 FILE *fp = fopen(index_path,"w");
630 fprintf(stderr,_("MWindow::init_plugins: "
631 "can't create plugin index: %s\n"), index_path);
634 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
635 fprintf(fp, "%s\n", plugin_path);
636 init_plugin_index(mwindow, preferences, fp, plugin_path);
637 init_ffmpeg_index(mwindow, preferences, fp);
638 init_lv2_index(mwindow, preferences, fp);
640 return load_plugin_index(mwindow, index_path, plugin_path);
643 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
645 char *path = getenv("LADSPA_PATH");
646 char ladspa_path[BCTEXTLEN];
648 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
651 for( int len=0; *path; path+=len ) {
652 char *cp = strchr(path,':');
653 len = !cp ? strlen(path) : cp-path;
654 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
655 memcpy(plugin_path, path, len); plugin_path[len] = 0;
657 char *plugin_dir = FileSystem::basepath(plugin_path);
658 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
659 create_defaults_path(index_path, LADSPA_FILE);
660 cp = index_path + strlen(index_path);
661 for( char *bp=plugin_path; *bp!=0; ++bp )
662 *cp++ = *bp=='/' ? '_' : *bp;
664 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
665 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
666 load_plugin_index(mwindow, index_path, plugin_path);
671 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
672 FILE *fp, const char *plugin_dir)
674 int idx = PLUGIN_IDS;
676 for( int i=0; i<plugindb->size(); ++i ) {
677 PluginServer *server = plugindb->get(i);
678 if( server->dir_idx >= idx )
679 idx = server->dir_idx+1;
682 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
685 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
686 const char *plug_dir, const char *plug_path, int &idx)
688 char plugin_path[BCTEXTLEN];
689 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
691 fs.set_filter( "[*.plugin][*.so]" );
692 int result = fs.update(plugin_path);
693 if( result || !fs.dir_list.total ) return;
696 for( int i=0; i<fs.dir_list.total; ++i ) {
697 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
698 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
699 get_plugin_path(path, plug_dir, fs_path);
700 if( fs.is_dir(fs_path) ) {
701 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
704 if( plugin_exists(path) ) continue;
706 if( stat(fs_path, &st) ) continue;
707 int64_t mtime = st.st_mtime;
708 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
709 result = server.open_plugin(1, preferences, 0, 0);
711 server.write_table(fp, path, vis_id, mtime);
712 server.close_plugin();
714 else if( result == PLUGINSERVER_IS_LAD ) {
717 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
718 ladspa.set_lad_index(lad_index++);
719 result = ladspa.open_plugin(1, preferences, 0, 0);
721 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
722 ladspa.close_plugin();
728 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
730 for( int i=0; i<plugins.size(); ++i )
731 plugindb->append(plugins[i]);
732 plugins.remove_all();
735 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
737 const char *dat_path = File::get_cindat_path();
738 char msg_path[BCTEXTLEN];
740 if( BC_Resources::language[0] ) {
741 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
743 fp = fopen(msg_path, "r");
746 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
748 fp = fopen(msg_path, "r");
751 char text[BCTEXTLEN];
752 char *tp = text, *ep = tp + sizeof(text)-1;
753 char title[BCTEXTLEN];
758 char line[BCTEXTLEN], *cp = line;
759 if( fgets(line,sizeof(line)-1,fp) ) {
760 if( *cp == '#' ) continue;
761 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
764 if( tp > text && *--tp == '\n' ) *tp = 0;
766 int idx = plugins.size();
767 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
769 delete [] plugins[idx]->tip;
770 plugins[idx]->tip = cstrdup(text);
774 if( done > 0 ) break;
776 char *dp = strchr(cp, ':');
778 printf("plugin tips: error on line %d\n", no);
782 while( cp < dp ) *bp++ = *cp++;
787 while( *cp == ' ' || *cp == '\t' ) ++cp;
788 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
793 void MWindow::delete_plugins()
795 plugindb->remove_all_objects();
800 void MWindow::search_plugindb(int do_audio,
805 ArrayList<PluginServer*> &results)
808 for(int i = 0; i < MWindow::plugindb->total; i++)
810 PluginServer *current = MWindow::plugindb->get(i);
812 if(current->audio == do_audio &&
813 current->video == do_video &&
814 (current->realtime == is_realtime || is_realtime < 0) &&
815 current->transition == is_transition &&
816 current->theme == is_theme)
817 results.append(current);
820 // Alphabetize list by title
826 for(int i = 0; i < results.total - 1; i++)
828 PluginServer *value1 = results[i];
829 PluginServer *value2 = results[i + 1];
830 if(strcmp(_(value1->title), _(value2->title)) > 0)
834 results[i + 1] = value1;
840 PluginServer* MWindow::scan_plugindb(char *title,
845 // printf("MWindow::scan_plugindb data_type < 0\n");
849 for(int i = 0; i < plugindb->total; i++)
851 PluginServer *server = plugindb->get(i);
853 !strcasecmp(server->title, title) &&
855 (data_type == TRACK_AUDIO && server->audio) ||
856 (data_type == TRACK_VIDEO && server->video)))
857 return plugindb->get(i);
862 // repair session files with xlated plugin titles
863 void MWindow::fix_plugin_title(char *title)
865 for(int i = 0; i < plugindb->total; i++) {
866 PluginServer *server = plugindb->get(i);
867 if( !server->title ) continue;
868 const char *server_title = server->title;
869 if( !bstrcasecmp(title, _(server_title)) ) {
870 strcpy(title, server_title);
876 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
878 for( int i=0; i<plugins.size(); ++i )
879 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
883 int MWindow::plugin_exists(char *plugin_path)
885 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
888 void MWindow::remove_plugin_index()
890 char index_path[BCTEXTLEN];
891 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
892 ::remove(index_path);
895 void MWindow::init_preferences()
897 preferences = new Preferences;
898 preferences->load_defaults(defaults);
899 const char *lv2_path = getenv("LV2_PATH");
900 if( lv2_path && strcmp(lv2_path, preferences->lv2_path) ) {
901 strncpy(preferences->lv2_path, lv2_path, sizeof(preferences->lv2_path));
902 remove_plugin_index();
904 else if( !lv2_path && preferences->lv2_path[0] ) {
905 File::setenv_path("LV2_PATH",preferences->lv2_path, 0);
907 session = new MainSession(this);
908 session->load_defaults(defaults);
909 // set x11_host, screens, window_config
910 screens = session->set_default_x11_host();
911 BC_Signals::set_trap_hook(trap_hook, this);
912 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
913 BC_Signals::set_catch_intr(preferences->trap_sigintr);
914 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
915 BC_Trace::enable_locks();
918 BC_Trace::disable_locks();
920 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
921 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
922 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
923 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
926 void MWindow::clean_indexes()
931 int oldest_item = -1;
933 char string[BCTEXTLEN];
934 char string2[BCTEXTLEN];
936 // Delete extra indexes
937 fs.set_filter("*.idx");
938 fs.complete_path(preferences->index_directory);
939 fs.update(preferences->index_directory);
940 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
942 // Eliminate directories
947 for(int i = 0; i < fs.dir_list.total && !result; i++)
949 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
950 if(fs.is_dir(string))
952 delete fs.dir_list[i];
953 fs.dir_list.remove_number(i);
958 total_excess = fs.dir_list.total - preferences->index_count;
960 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
961 while(total_excess > 0)
964 for(int i = 0; i < fs.dir_list.total; i++)
966 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
968 if(i == 0 || fs.get_date(string) <= oldest)
970 oldest = fs.get_date(string);
978 fs.join_names(string,
979 preferences->index_directory,
980 fs.dir_list[oldest_item]->name);
981 //printf("MWindow::clean_indexes 1 %s\n", string);
983 perror("delete_indexes");
984 delete fs.dir_list[oldest_item];
985 fs.dir_list.remove_number(oldest_item);
987 // Remove table of contents if it exists
988 strcpy(string2, string);
989 char *ptr = strrchr(string2, '.');
992 //printf("MWindow::clean_indexes 2 %s\n", string2);
993 sprintf(ptr, ".toc");
995 sprintf(ptr, ".mkr");
1004 void MWindow::init_awindow()
1006 awindow = new AWindow(this);
1007 awindow->create_objects();
1010 void MWindow::init_gwindow()
1012 gwindow = new GWindow(this);
1013 gwindow->create_objects();
1016 void MWindow::init_tipwindow()
1018 TipWindow::load_tips(cin_lang);
1020 twindow = new TipWindow(this);
1024 void MWindow::show_warning(int *do_warning, const char *text)
1026 if( do_warning && !*do_warning ) return;
1028 wwindow = new WWindow(this);
1029 wwindow->show_warning(do_warning, text);
1032 int MWindow::wait_warning()
1034 return wwindow->wait_result();
1037 void MWindow::init_theme()
1042 PluginServer *theme_plugin = 0;
1043 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1044 if( plugindb->get(i)->theme &&
1045 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1046 theme_plugin = plugindb->get(i);
1050 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1051 preferences->theme);
1053 const char *default_theme = DEFAULT_THEME;
1054 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1055 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1057 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1058 if( plugindb->get(i)->theme &&
1059 !strcasecmp(default_theme, plugindb->get(i)->title) )
1060 theme_plugin = plugindb->get(i);
1065 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1069 PluginServer *plugin = new PluginServer(*theme_plugin);
1070 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1071 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1072 theme_plugin->title);
1076 theme = plugin->new_theme();
1077 theme->mwindow = this;
1078 strcpy(theme->path, plugin->path);
1081 // Load default images & settings
1082 theme->Theme::initialize();
1083 // Load user images & settings
1084 theme->initialize();
1085 // Create menus with user colors
1086 theme->build_menus();
1089 theme->sort_image_sets();
1090 theme->check_used();
1091 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1094 void MWindow::init_3d()
1096 playback_3d = new Playback3D(this);
1097 playback_3d->create_objects();
1100 void MWindow::init_edl()
1103 edl->create_objects();
1104 fill_preset_defaults(default_standard, edl->session);
1105 edl->load_defaults(defaults);
1106 edl->session->brender_start = edl->session->brender_end = 0;
1107 edl->create_default_tracks();
1108 edl->tracks->update_y_pixels(theme);
1111 void MWindow::init_compositor()
1113 cwindow = new CWindow(this);
1114 cwindow->create_objects();
1117 void MWindow::init_levelwindow()
1119 lwindow = new LevelWindow(this);
1120 lwindow->create_objects();
1123 VWindow *MWindow::get_viewer(int start_it, int idx)
1125 vwindows_lock->lock("MWindow::get_viewer");
1126 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1127 if( !vwindow ) idx = vwindows.size();
1128 while( !vwindow && --idx >= 0 ) {
1129 VWindow *vwin = vwindows[idx];
1130 if( !vwin->is_running() || !vwin->get_edl() )
1134 vwindow = new VWindow(this);
1135 vwindow->load_defaults();
1136 vwindow->create_objects();
1137 vwindows.append(vwindow);
1139 vwindows_lock->unlock();
1140 if( start_it ) vwindow->start();
1144 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1146 zwindows_lock->lock("MWindow::get_mixer");
1147 if( !mixer ) mixer = edl->mixers.new_mixer();
1148 ZWindow *zwindow = 0;
1149 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1150 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1152 zwindows.append(zwindow = new ZWindow(this));
1153 zwindow->idx = mixer->idx;
1154 zwindows_lock->unlock();
1158 void MWindow::del_mixer(ZWindow *zwindow)
1160 zwindows_lock->lock("MWindow::del_mixer 0");
1161 edl->mixers.del_mixer(zwindow->idx);
1162 if( session->selected_zwindow >= 0 ) {
1163 int i = zwindows.number_of(zwindow);
1164 if( i >= 0 && i < session->selected_zwindow )
1165 --session->selected_zwindow;
1166 else if( i == session->selected_zwindow )
1167 session->selected_zwindow = -1;
1169 zwindows_lock->unlock();
1170 gui->lock_window("MWindow::del_mixer 1");
1171 gui->update_mixers(0, -1);
1172 gui->unlock_window();
1175 void MWindow::start_mixer()
1178 ZWindow *zwindow = get_mixer(mixer);
1179 const char *title = 0;
1181 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1182 PatchGUI *patchgui = get_patchgui(track);
1183 if( !patchgui || !patchgui->mixer ) continue;
1184 mixer->mixer_ids.append(track->get_mixer_id());
1185 if( !title ) title = track->title;
1188 session->selected_zwindow = -1;
1189 gui->lock_window("MWindow::start_mixer");
1190 gui->update_mixers(0, 0);
1191 gui->unlock_window();
1193 zwindow->set_title(title);
1198 int MWindow::mixer_track_active(Track *track)
1200 int i = session->selected_zwindow;
1201 if( i < 0 || i >= zwindows.size() ) return 0;
1202 ZWindow *zwindow = zwindows[i];
1203 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1204 if( !mixer ) return 0;
1205 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1206 return n >= 0 ? 1 : 0;
1209 void MWindow::update_mixer_tracks()
1211 zwindows_lock->lock("MixPatch::handle_event");
1212 int i = session->selected_zwindow;
1213 if( i >= 0 && i < zwindows.size() ) {
1214 ZWindow *zwindow = zwindows[i];
1215 zwindow->update_mixer_ids();
1217 zwindows_lock->unlock();
1220 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1221 int use_inout, int update_refresh, int toggle_audio, int loop_play)
1223 zwindows_lock->lock("MWindow::queue_mixers");
1224 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1225 ZWindow *zwindow = zwindows[vidx];
1226 if( zwindow->idx < 0 ) continue;
1227 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1228 if( !mixer || !mixer->mixer_ids.size() ) continue;
1230 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1231 if( track->data_type != TRACK_VIDEO ) continue;
1232 int mixer_id = track->get_mixer_id();
1233 k = mixer->mixer_ids.size();
1234 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1236 if( k < 0 ) continue;
1237 EDL *mixer_edl = new EDL(this->edl);
1238 mixer_edl->create_objects();
1239 mixer_edl->copy_all(edl);
1240 mixer_edl->remove_vwindow_edls();
1241 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1242 k = mixer->mixer_ids.size();
1243 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1246 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1249 track->record = track->play = 0;
1251 zwindow->change_source(mixer_edl);
1252 zwindow->issue_command(command,
1253 wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
1255 zwindows_lock->unlock();
1258 void MWindow::refresh_mixers(int dir)
1260 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1261 queue_mixers(edl,command,0,0,1,0,0);
1264 void MWindow::stop_mixers()
1266 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1267 ZWindow *zwindow = zwindows[vidx];
1268 if( zwindow->idx < 0 ) continue;
1269 zwindow->issue_command(STOP, 0, 0, 0, 0, 0);
1273 void MWindow::close_mixers(int destroy)
1275 zwindows_lock->lock("MWindow::close_mixers");
1276 for( int i=zwindows.size(); --i>=0; ) {
1277 ZWindow *zwindow = zwindows[i];
1278 if( zwindow->idx < 0 ) continue;
1279 zwindow->destroy = destroy;
1280 ZWindowGUI *zgui = zwindow->zgui;
1281 zgui->lock_window("MWindow::select_zwindow 0");
1283 zgui->unlock_window();
1285 zwindows_lock->unlock();
1286 for( int i=0; i<zwindows.size(); ++i ) {
1287 ZWindow *zwindow = zwindows[i];
1288 if( zwindow->idx < 0 ) continue;
1289 zwindow->close_window();
1293 ZWindow *MWindow::create_mixer(Indexable *indexable)
1295 ArrayList<Indexable*> new_assets;
1296 new_assets.append(indexable);
1297 Track *track = edl->tracks->last;
1298 load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
1299 track = !track ? edl->tracks->first : track->next;
1301 ZWindow *zwindow = get_mixer(mixer);
1303 track->play = track->record = 0;
1304 if( track->data_type == TRACK_VIDEO ) {
1305 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1307 mixer->mixer_ids.append(track->get_mixer_id());
1308 track = track->next;
1310 if( indexable->is_asset ) {
1311 char *path = indexable->path;
1312 char *tp = strrchr(path, '/');
1313 if( !tp ) tp = path; else ++tp;
1314 zwindow->set_title(tp);
1317 char *title = ((EDL*)indexable)->local_session->clip_title;
1318 zwindow->set_title(title);
1323 void MWindow::create_mixers()
1325 if( !session->drag_assets->size() &&
1326 !session->drag_clips->size() ) return;
1327 undo->update_undo_before();
1330 ArrayList<ZWindow *>new_mixers;
1332 for( int i=0; i<session->drag_assets->size(); ++i ) {
1333 Indexable *indexable = session->drag_assets->get(i);
1334 if( !indexable->have_video() ) continue;
1335 ZWindow *zwindow = create_mixer(indexable);
1336 new_mixers.append(zwindow);
1338 for( int i=0; i<session->drag_clips->size(); ++i ) {
1339 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1340 if( !indexable->have_video() ) continue;
1341 ZWindow *zwindow = create_mixer(indexable);
1342 new_mixers.append(zwindow);
1346 for( int i=0; i<new_mixers.size(); ++i )
1347 new_mixers[i]->start();
1351 undo->update_undo_after(_("create mixers"), LOAD_ALL);
1353 gui->update(1, 2, 1, 1, 1, 1, 0);
1354 sync_parameters(CHANGE_ALL);
1357 void MWindow::open_mixers()
1359 for( int i=0; i<edl->mixers.size(); ++i ) {
1360 Mixer *mixer = edl->mixers[i];
1361 ZWindow *zwindow = get_mixer(mixer);
1362 zwindow->set_title(mixer->title);
1368 int MWindow::select_zwindow(ZWindow *zwindow)
1370 int ret = 0, n = zwindows.number_of(zwindow);
1371 if( session->selected_zwindow != n ) {
1372 session->selected_zwindow = n;
1373 for( int i=0; i<zwindows.size(); ++i ) {
1374 ZWindow *zwindow = zwindows[i];
1375 if( zwindow->idx < 0 ) continue;
1376 ZWindowGUI *zgui = zwindow->zgui;
1377 zgui->lock_window("MWindow::select_zwindow 0");
1378 zwindow->highlighted = i == n ? 1 : 0;
1379 if( zgui->draw_overlays() )
1380 zgui->canvas->get_canvas()->flash(1);
1381 zgui->unlock_window();
1384 gui->lock_window("MWindow::select_window 1");
1385 gui->update_mixers(0, -1);
1386 gui->unlock_window();
1391 void MWindow::tile_mixers()
1394 for( int i=0; i<zwindows.size(); ++i ) {
1395 ZWindow *zwindow = zwindows[i];
1396 if( zwindow->idx < 0 ) continue;
1400 int zn = ceil(sqrt(nz));
1401 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1402 int y1 = 1, y2 = gui->get_y();
1403 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1404 if( x1 < 0 ) x1 = 0;
1405 if( y1 < 0 ) y1 = 0;
1406 if( x2 > rw ) x2 = rw;
1407 if( y2 > rh ) y2 = rh;
1408 int dx = x2 - x1, dy = y2 - y1;
1410 int lt = BC_DisplayInfo::get_left_border();
1411 int top = BC_DisplayInfo::get_top_border();
1412 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1413 int bh = top + BC_DisplayInfo::get_bottom_border();
1414 int zx = 0, zy = 0; // window origins
1415 int mw = 10+10, mh = 10+10; // canvas margins
1416 int rsz = 0, n = 0, dz = 0;
1417 int ow = edl->session->output_w, oh = edl->session->output_h;
1418 for( int i=0; i<zwindows.size(); ++i ) {
1419 ZWindow *zwindow = zwindows[i];
1420 if( zwindow->idx < 0 ) continue;
1421 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1422 if( rsz < hh ) rsz = hh;
1423 int xx = zx + x1, yy = zy + y1;
1424 int mx = x2 - zw, my = y2 - zh;
1425 if( xx > mx ) xx = mx;
1426 if( yy > my ) yy = my;
1427 xx += lt + dz; yy += top + dz;
1428 zwindow->reposition(xx,yy, ww,hh);
1429 if( zwindow->running() ) {
1430 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1431 gui->lock_window("MWindow::tile_mixers");
1432 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1433 gui->unlock_window();
1437 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1446 void MWindow::init_cache()
1448 audio_cache = new CICache(preferences);
1449 video_cache = new CICache(preferences);
1450 frame_cache = new FrameCache;
1451 wave_cache = new WaveCache;
1454 void MWindow::init_channeldb()
1456 channeldb_buz->load("channeldb_buz");
1457 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1460 void MWindow::init_menus()
1462 char string[BCTEXTLEN];
1465 BC_CModels::to_text(string, BC_RGB888);
1466 colormodels.append(new ColormodelItem(string, BC_RGB888));
1467 BC_CModels::to_text(string, BC_RGBA8888);
1468 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1469 // BC_CModels::to_text(string, BC_RGB161616);
1470 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1471 // BC_CModels::to_text(string, BC_RGBA16161616);
1472 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1473 BC_CModels::to_text(string, BC_RGB_FLOAT);
1474 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1475 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1476 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1477 BC_CModels::to_text(string, BC_YUV888);
1478 colormodels.append(new ColormodelItem(string, BC_YUV888));
1479 BC_CModels::to_text(string, BC_YUVA8888);
1480 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1481 // BC_CModels::to_text(string, BC_YUV161616);
1482 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1483 // BC_CModels::to_text(string, BC_YUVA16161616);
1484 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1486 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1487 interlace_project_modes.append(new InterlacemodeItem(string, x));
1489 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1490 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1492 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1493 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1495 // Interlacing Modes
1496 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1498 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1499 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1501 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1502 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1504 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1505 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1507 // Interlacing Fixing Methods
1508 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1509 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1510 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1513 void MWindow::init_indexes()
1515 mainindexes = new MainIndexes(this);
1516 mainindexes->start_loop();
1519 void MWindow::init_gui()
1521 gui = new MWindowGUI(this);
1522 gui->lock_window("MWindow::init_gui");
1523 gui->create_objects();
1524 gui->unlock_window();
1525 gui->load_defaults(defaults);
1528 void MWindow::init_signals()
1530 sighandler = new SigHandler;
1531 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1535 void MWindow::init_render()
1537 render = new Render(this);
1538 create_bd = new CreateBD_Thread(this);
1539 create_dvd = new CreateDVD_Thread(this);
1540 batch_render = new BatchRenderThread(this);
1543 void MWindow::init_exportedl()
1545 exportedl = new ExportEDL(this);
1548 void MWindow::init_brender()
1550 if(preferences->use_brender && !brender)
1552 brender_lock->lock("MWindow::init_brender 1");
1553 brender = new BRender(this);
1554 brender->initialize();
1555 session->brender_end = 0;
1556 brender_lock->unlock();
1559 if(!preferences->use_brender && brender)
1561 brender_lock->lock("MWindow::init_brender 2");
1564 session->brender_end = 0;
1565 brender_lock->unlock();
1571 void MWindow::restart_brender()
1573 //printf("MWindow::restart_brender 1\n");
1574 if( !brender_active || !preferences->use_brender ) return;
1575 if( !brender ) return;
1576 brender->restart(edl);
1579 void MWindow::stop_brender()
1581 if( !brender ) return;
1582 // cannot be holding mwindow->gui display lock
1586 int MWindow::brender_available(int position)
1589 brender_lock->lock("MWindow::brender_available 1");
1590 if(brender && brender_active)
1592 if(brender->map_valid)
1594 brender->map_lock->lock("MWindow::brender_available 2");
1595 if(position < brender->map_size &&
1598 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1599 if(brender->map[position] == BRender::RENDERED)
1602 brender->map_lock->unlock();
1605 brender_lock->unlock();
1609 void MWindow::set_brender_active(int v, int update)
1611 if( !preferences->use_brender ) v = 0;
1613 gui->mainmenu->brender_active->set_checked(v);
1615 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1616 edl->session->brender_end = edl->local_session->get_selectionend(1);
1618 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1619 edl->session->brender_end = edl->tracks->total_video_length();
1624 edl->session->brender_start = edl->session->brender_end = 0;
1625 gui->unlock_window();
1627 gui->lock_window("MWindow::set_brender_active");
1630 gui->update_timebar(0);
1631 gui->draw_overlays(1);
1635 int MWindow::has_commercials()
1637 #ifdef HAVE_COMMERCIAL
1638 return theme->use_commercials;
1644 void MWindow::init_commercials()
1646 #ifdef HAVE_COMMERCIAL
1647 if( !commercials ) {
1648 commercials = new Commercials(this);
1649 commercial_active = 0;
1652 commercials->add_user();
1656 void MWindow::commit_commercial()
1658 #ifdef HAVE_COMMERCIAL
1659 if( !commercial_active ) return;
1660 commercial_active = 0;
1661 if( !commercials ) return;
1662 commercials->commitDb();
1666 void MWindow::undo_commercial()
1668 #ifdef HAVE_COMMERCIAL
1669 if( !commercial_active ) return;
1670 commercial_active = 0;
1671 if( !commercials ) return;
1672 commercials->undoDb();
1676 int MWindow::put_commercial()
1679 #ifdef HAVE_COMMERCIAL
1680 double start = edl->local_session->get_selectionstart();
1681 double end = edl->local_session->get_selectionend();
1682 if( start >= end ) return 0;
1684 const char *errmsg = 0;
1686 Tracks *tracks = edl->tracks;
1688 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1689 if( track->data_type != TRACK_VIDEO ) continue;
1690 if( !track->record ) continue;
1691 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1693 int64_t units_start = track->to_units(start,0);
1694 int64_t units_end = track->to_units(end,0);
1695 Edits *edits = track->edits;
1696 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1697 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1698 if(!edit1 && !edit2) continue; // nothing selected
1699 if(!edit2) { // edit2 beyond end of track
1700 edit2 = edits->last;
1701 units_end = edits->length();
1703 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1704 Indexable *indexable = edit1->get_source();
1705 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1708 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1709 if( track->data_type != TRACK_VIDEO ) continue;
1710 if( !track->record ) continue;
1711 int64_t units_start = track->to_units(start,0);
1712 int64_t units_end = track->to_units(end,0);
1713 Edits *edits = track->edits;
1714 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1715 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1716 if(!edit1 && !edit2) continue; // nothing selected
1717 if(!edit2) { // edit2 beyond end of track
1718 edit2 = edits->last;
1719 units_end = edits->length();
1721 Indexable *indexable = edit1->get_source();
1722 Asset *asset = (Asset *)indexable;
1723 File *file = video_cache->check_out(asset, edl);
1724 if( !file ) { errmsg = _("no file"); break; }
1725 int64_t edit_length = units_end - units_start;
1726 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1727 result = commercials->put_clip(file, edit1->channel,
1728 track->from_units(edit_start), track->from_units(edit_length));
1729 video_cache->check_in(asset);
1730 if( result ) { errmsg = _("db failed"); break; }
1733 char string[BCTEXTLEN];
1734 sprintf(string, _("put_commercial: %s"), errmsg);
1735 MainError::show_error(string);
1743 void MWindow::stop_playback(int wait)
1745 gui->stop_drawing();
1747 cwindow->stop_playback(wait);
1749 for(int i = 0; i < vwindows.size(); i++) {
1750 VWindow *vwindow = vwindows[i];
1751 if( !vwindow->is_running() ) continue;
1752 vwindow->stop_playback(wait);
1754 for(int i = 0; i < zwindows.size(); i++) {
1755 ZWindow *zwindow = zwindows[i];
1756 if( zwindow->idx < 0 ) continue;
1757 zwindow->stop_playback(wait);
1761 void MWindow::stop_transport()
1763 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1766 void MWindow::beep(double freq, double secs, double gain)
1768 if( !proxy_beep ) proxy_beep = new ProxyBeep(this);
1769 proxy_beep->tone(freq, secs, gain);
1772 int MWindow::load_filenames(ArrayList<char*> *filenames,
1774 int update_filename)
1776 ArrayList<EDL*> new_edls;
1777 ArrayList<Asset*> new_assets;
1778 ArrayList<File*> new_files;
1779 const int debug = 0;
1780 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1783 gui->start_hourglass();
1785 // Need to stop playback since tracking depends on the EDL not getting
1787 gui->unlock_window();
1789 gui->lock_window("MWindow::load_filenames 0");
1791 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1792 undo->update_undo_before();
1795 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1797 // Define new_edls and new_assets to load
1798 int result = 0, ftype = -1;
1800 for( int i=0; i<filenames->size(); ++i ) {
1802 File *new_file = new File;
1803 Asset *new_asset = new Asset(filenames->get(i));
1804 EDL *new_edl = new EDL;
1805 char string[BCTEXTLEN];
1807 new_edl->create_objects();
1808 new_edl->copy_session(edl);
1809 new_file->set_program(edl->session->program_no);
1811 sprintf(string, _("Loading %s"), new_asset->path);
1812 gui->show_message(string);
1813 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1815 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1816 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1820 // Convert media file to EDL
1822 // Warn about odd image dimensions
1823 if( new_asset->video_data &&
1824 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1825 char string[BCTEXTLEN];
1826 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1827 new_asset->path, new_asset->width, new_asset->height);
1828 MainError::show_error(string);
1831 if( new_asset->program >= 0 &&
1832 edl->session->program_no != new_asset->program ) {
1833 char string[BCTEXTLEN];
1834 sprintf(string, _("%s's index was built for program number %d\n"
1835 "Playback preference is %d.\n Using program %d."),
1836 new_asset->path, new_asset->program,
1837 edl->session->program_no, new_asset->program);
1838 MainError::show_error(string);
1841 if( load_mode != LOADMODE_RESOURCESONLY ) {
1842 RecordLabels *labels = edl->session->label_cells ?
1843 new RecordLabels(new_file) : 0;
1844 asset_to_edl(new_edl, new_asset, labels);
1845 new_edls.append(new_edl);
1846 new_edl->add_user();
1850 new_assets.append(new_asset);
1851 new_asset->add_user();
1854 // Set filename to nothing for assets since save EDL would overwrite them.
1855 if( load_mode == LOADMODE_REPLACE ||
1856 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1858 // Reset timeline position
1859 for( int i=0; i<TOTAL_PANES; ++i ) {
1860 new_edl->local_session->view_start[i] = 0;
1861 new_edl->local_session->track_start[i] = 0;
1869 case FILE_NOT_FOUND:
1870 sprintf(string, _("Failed to open %s"), new_asset->path);
1871 gui->show_message(string, theme->message_error);
1872 gui->update_default_message();
1876 case FILE_UNRECOGNIZED_CODEC: {
1878 { IndexFile indexfile(this, new_asset);
1879 if( !(result = indexfile.open_index()) )
1880 indexfile.close_index(); }
1882 // Test existing EDLs
1883 for( int j=0; result && j<new_edls.total; ++j ) {
1884 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1886 new_asset->copy_from(old_asset,1);
1891 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1893 new_asset->copy_from(old_asset,1);
1900 char string[BCTEXTLEN];
1902 fs.extract_name(string, new_asset->path);
1904 strcat(string, _("'s format couldn't be determined."));
1905 new_asset->audio_data = 1;
1906 new_asset->format = FILE_PCM;
1907 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1908 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1909 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1910 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1911 new_asset->signed_ = defaults->get("SIGNED_", 1);
1912 new_asset->header = defaults->get("HEADER", 0);
1914 FileFormat fwindow(this);
1915 fwindow.create_objects(new_asset, string);
1916 result = fwindow.run_window();
1918 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1919 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1920 defaults->update("AUDIO_BITS", new_asset->bits);
1921 defaults->update("BYTE_ORDER", new_asset->byte_order);
1922 defaults->update("SIGNED_", new_asset->signed_);
1923 defaults->update("HEADER", new_asset->header);
1929 // Recalculate length
1931 new_file = new File;
1932 result = new_file->open_file(preferences, new_asset, 1, 0);
1934 if( load_mode != LOADMODE_RESOURCESONLY ) {
1935 RecordLabels *labels = edl->session->label_cells ?
1936 new RecordLabels(new_file) : 0;
1937 asset_to_edl(new_edl, new_asset, labels);
1938 new_edls.append(new_edl);
1939 new_edl->add_user();
1943 new_assets.append(new_asset);
1944 new_asset->add_user();
1954 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1955 xml_file.read_from_file(filenames->get(i));
1956 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1957 const char *cin_version = 0;
1958 while( !xml_file.read_tag() ) {
1959 if( xml_file.tag.title_is("EDL") ) {
1960 cin_version = xml_file.tag.get_property("VERSION");
1965 if( !cin_version ) {
1966 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1967 char string[BCTEXTLEN];
1968 sprintf(string,_("Unknown %s"), filenames->get(i));
1969 gui->show_message(string);
1973 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1974 char string[BCTEXTLEN];
1975 snprintf(string, sizeof(string),
1976 _("Warning: XML from cinelerra version %s\n"
1977 "Session data may be incompatible."), cin_version);
1978 show_warning(&preferences->warn_version, string);
1980 if( load_mode == LOADMODE_NESTED ) {
1981 // Load temporary EDL for nesting.
1982 EDL *nested_edl = new EDL;
1983 nested_edl->create_objects();
1984 nested_edl->load_xml(&xml_file, LOAD_ALL);
1985 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1986 new_edl->create_nested(nested_edl);
1987 new_edl->set_path(filenames->get(i));
1988 nested_edl->Garbage::remove_user();
1991 // Load EDL for pasting
1992 new_edl->load_xml(&xml_file, LOAD_ALL);
1993 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1994 test_plugins(new_edl, filenames->get(i));
1995 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1997 if( load_mode == LOADMODE_REPLACE ||
1998 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1999 strcpy(session->filename, filenames->get(i));
2000 strcpy(new_edl->local_session->clip_title,
2003 set_filename(new_edl->local_session->clip_title);
2005 else if( load_mode == LOADMODE_RESOURCESONLY ) {
2006 strcpy(new_edl->local_session->clip_title,
2009 time_t t = !stat(filenames->get(i),&st) ?
2010 st.st_mtime : time(&t);
2011 ctime_r(&t, new_edl->local_session->clip_notes);
2015 new_edls.append(new_edl);
2016 new_edl->add_user();
2021 new_edl->Garbage::remove_user();
2022 new_asset->Garbage::remove_user();
2024 // Store for testing index
2025 new_files.append(new_file);
2028 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2032 gui->reset_default_message();
2033 gui->default_message();
2037 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2040 // Don't back up here.
2043 // For pasting, clear the active region
2044 if(load_mode == LOADMODE_PASTE ||
2045 load_mode == LOADMODE_NESTED)
2047 double start = edl->local_session->get_selectionstart();
2048 double end = edl->local_session->get_selectionend();
2049 if(!EQUIV(start, end))
2052 edl->session->labels_follow_edits,
2053 edl->session->plugins_follow_edits,
2054 edl->session->autos_follow_edits);
2057 paste_edls(&new_edls, load_mode, 0, -1,
2058 edl->session->labels_follow_edits,
2059 edl->session->plugins_follow_edits,
2060 edl->session->autos_follow_edits,
2067 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2069 // Add new assets to EDL and schedule assets for index building.
2070 int got_indexes = 0;
2071 for( int i=0; i<new_edls.size(); ++i ) {
2072 EDL *new_edl = new_edls[i];
2073 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2074 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2075 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2081 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2082 for( int i=0; i<new_assets.size(); ++i ) {
2083 Asset *new_asset = new_assets[i];
2087 for( int j=0; j<new_files.size(); ++j ) {
2088 new_file = new_files[j];
2089 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2095 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2096 edl->assets->update(new_asset);
2099 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2101 // Start examining next batch of index files
2102 if(got_indexes) mainindexes->start_build();
2103 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2106 Track *track = edl->tracks->first;
2109 for(int j = 0; j < track->plugin_set.size(); j++)
2111 PluginSet *plugins = track->plugin_set[j];
2112 Plugin *plugin = plugins->get_first_plugin();
2116 if(load_mode == LOADMODE_REPLACE ||
2117 load_mode == LOADMODE_REPLACE_CONCATENATE)
2119 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2122 show_plugin(plugin);
2126 plugin = (Plugin*)plugin->next;
2130 track = track->next;
2133 // if just opening one new resource in replace mode
2134 if( ftype != FILE_IS_XML &&
2135 ( load_mode == LOADMODE_REPLACE ||
2136 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2138 edl->session->proxy_scale = 1;
2139 edl->session->proxy_disabled_scale = 1;
2140 edl->session->proxy_use_scaler = 0;
2141 edl->session->proxy_auto_scale = 0;
2142 edl->session->proxy_beep = 0;
2143 edl->local_session->preview_start = 0;
2144 edl->local_session->preview_end = 0;
2145 edl->local_session->loop_playback = 0;
2146 edl->local_session->set_selectionstart(0);
2147 edl->local_session->set_selectionend(0);
2148 set_brender_active(0, 0);
2153 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2154 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2155 ArrayList<Indexable *> orig_idxbls;
2156 for( int i=0; i<new_assets.size(); ++i )
2157 orig_idxbls.append(new_assets.get(i));
2158 for( int i=0; i<new_edls.size(); ++i ) {
2159 EDL *new_edl = new_edls[i];
2160 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2161 if( track->data_type != TRACK_VIDEO ) continue;
2162 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2163 Indexable *idxbl = (Indexable *)edit->asset;
2164 if( !idxbl ) continue;
2165 if( !idxbl->have_video() ) continue;
2166 if( edit->channel != 0 ) continue; // first layer only
2167 orig_idxbls.append(edit->asset);
2171 gui->unlock_window(); // to update progress bar
2172 int ret = render_proxy(orig_idxbls);
2173 gui->lock_window("MWindow::load_filenames");
2174 if( ret >= 0 && edl->session->proxy_beep ) {
2176 beep(2000., 1.5, 0.5);
2178 beep(4000., 0.25, 0.5);
2182 // need to update undo before project, since mwindow is unlocked & a new load
2183 // can begin here. Should really prevent loading until we're done.
2184 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2185 undo->update_undo_after(_("load"), LOAD_ALL);
2187 for(int i = 0; i < new_edls.size(); i++)
2189 new_edls[i]->remove_user();
2191 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2193 new_edls.remove_all();
2195 for(int i = 0; i < new_assets.size(); i++)
2197 new_assets[i]->Garbage::remove_user();
2200 new_assets.remove_all();
2201 new_files.remove_all_objects();
2204 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2205 if(load_mode == LOADMODE_REPLACE ||
2206 load_mode == LOADMODE_REPLACE_CONCATENATE)
2208 session->changes_made = 0;
2212 session->changes_made = 1;
2215 gui->stop_hourglass();
2218 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2219 update_project(load_mode);
2221 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2226 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2228 Asset *format_asset = new Asset;
2229 format_asset->format = FILE_FFMPEG;
2230 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2231 ProxyRender proxy_render(this, format_asset);
2232 int new_scale = edl->session->proxy_scale;
2233 int use_scaler = edl->session->proxy_use_scaler;
2235 for( int i=0; i<new_idxbls.size(); ++i ) {
2236 Indexable *orig = new_idxbls.get(i);
2237 Asset *proxy = proxy_render.add_original(orig, new_scale);
2238 if( !proxy ) continue;
2240 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2241 int got_it = exists && // if proxy exists, and is newer than orig
2242 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2243 if( got_it ) continue;
2244 proxy_render.add_needed(orig, proxy);
2247 // render needed proxies
2248 int result = proxy_render.create_needed_proxies(new_scale);
2250 add_proxy(use_scaler,
2251 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2253 format_asset->remove_user();
2254 return !result ? proxy_render.needed_proxies.size() : -1;
2257 int MWindow::enable_proxy()
2259 if( edl->session->proxy_scale == 1 &&
2260 edl->session->proxy_disabled_scale != 1 ) {
2261 int new_scale = edl->session->proxy_disabled_scale;
2262 edl->session->proxy_disabled_scale = 1;
2263 Asset *asset = new Asset;
2264 asset->format = FILE_FFMPEG;
2265 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2266 to_proxy(asset, new_scale);
2267 asset->remove_user();
2272 int MWindow::disable_proxy()
2274 if( edl->session->proxy_scale != 1 &&
2275 edl->session->proxy_disabled_scale == 1 ) {
2276 edl->session->proxy_disabled_scale = edl->session->proxy_scale;
2277 Asset *asset = new Asset;
2278 asset->format = FILE_FFMPEG;
2279 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2281 asset->remove_user();
2286 int MWindow::to_proxy(Asset *asset, int new_scale)
2288 ArrayList<Indexable*> orig_idxbls;
2289 ArrayList<Indexable*> proxy_assets;
2291 edl->Garbage::add_user();
2293 undo->update_undo_before(_("proxy"), this);
2294 ProxyRender proxy_render(this, asset);
2296 // revert project to original size from current size
2297 // remove all session proxy assets at the at the current proxy_scale
2298 int proxy_scale = edl->session->proxy_scale;
2299 int proxy_use_scaler = edl->session->proxy_use_scaler;
2301 if( proxy_scale > 1 ) {
2302 Asset *orig_asset = edl->assets->first;
2303 for( ; orig_asset; orig_asset=orig_asset->next ) {
2304 char new_path[BCTEXTLEN];
2305 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2306 // test if proxy asset was already added to proxy_assets
2308 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2309 got_it = !strcmp(proxy_assets[i]->path, new_path);
2310 if( got_it ) continue;
2311 Asset *proxy_asset = edl->assets->get_asset(new_path);
2312 if( !proxy_asset ) continue;
2313 // add pointer to existing EDL asset if it exists
2314 // EDL won't delete it unless it's the same pointer.
2315 proxy_assets.append(proxy_asset);
2316 proxy_asset->add_user();
2317 orig_idxbls.append(orig_asset);
2318 orig_asset->add_user();
2320 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2321 EDL *orig_nested = edl->nested_edls[i];
2322 char new_path[BCTEXTLEN];
2323 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2325 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2326 // test if proxy asset was already added to proxy_assets
2328 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2329 got_it = !strcmp(proxy_assets[i]->path, new_path);
2330 if( got_it ) continue;
2331 Asset *proxy_nested = edl->assets->get_asset(new_path);
2332 if( !proxy_nested ) continue;
2333 // add pointer to existing EDL asset if it exists
2334 // EDL won't delete it unless it's the same pointer.
2335 proxy_assets.append(proxy_nested);
2336 proxy_nested->add_user();
2337 orig_idxbls.append(orig_nested);
2338 orig_nested->add_user();
2341 // convert from the proxy assets to the original assets
2342 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2344 // remove the references
2345 for( int i=0; i<proxy_assets.size(); ++i ) {
2346 Asset *proxy = (Asset *) proxy_assets[i];
2347 proxy->width = proxy->actual_width;
2348 proxy->height = proxy->actual_height;
2349 proxy->remove_user();
2350 edl->assets->remove_pointer(proxy);
2351 proxy->remove_user();
2353 proxy_assets.remove_all();
2354 for( int i = 0; i < orig_idxbls.size(); i++ )
2355 orig_idxbls[i]->remove_user();
2356 orig_idxbls.remove_all();
2359 ArrayList<char *> confirm_paths; // test for new files
2360 confirm_paths.set_array_delete();
2362 // convert to new size if not original size
2363 if( new_scale != 1 ) {
2365 Asset *orig = edl->assets->first;
2366 for( ; orig; orig=orig->next ) {
2367 Asset *proxy = proxy_render.add_original(orig, new_scale);
2368 if( !proxy ) continue;
2369 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2370 int got_it = exists && // if proxy exists, and is newer than orig
2371 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2373 if( exists ) // prompt user to overwrite
2374 confirm_paths.append(cstrdup(proxy->path));
2375 proxy_render.add_needed(orig, proxy);
2378 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2379 EDL *orig_nested = edl->nested_edls[i];
2380 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2381 if( !proxy ) continue;
2382 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2383 int got_it = exists && // if proxy exists, and is newer than orig_nested
2384 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2386 if( exists ) // prompt user to overwrite
2387 confirm_paths.append(cstrdup(proxy->path));
2388 proxy_render.add_needed(orig_nested, proxy);
2394 // test for existing files
2395 if( confirm_paths.size() ) {
2396 result = ConfirmSave::test_files(this, &confirm_paths);
2397 confirm_paths.remove_all_objects();
2401 result = proxy_render.create_needed_proxies(new_scale);
2403 if( !result ) // resize project
2404 edl->set_proxy(new_scale, proxy_use_scaler,
2405 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2407 undo->update_undo_after(_("proxy"), LOAD_ALL);
2408 edl->Garbage::remove_user();
2411 gui->lock_window("MWindow::to_proxy");
2412 update_project(LOADMODE_REPLACE);
2413 gui->unlock_window();
2415 return !result ? proxy_render.needed_proxies.size() : -1;
2418 void MWindow::test_plugins(EDL *new_edl, char *path)
2420 char string[BCTEXTLEN];
2422 // Do a check whether plugins exist
2423 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2424 for( int k=0; k<track->plugin_set.total; ++k ) {
2425 PluginSet *plugin_set = track->plugin_set[k];
2426 for( Plugin *plugin = (Plugin*)plugin_set->first;
2427 plugin; plugin = (Plugin*)plugin->next ) {
2428 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2429 // ok we need to find it in plugindb
2430 PluginServer *server =
2431 scan_plugindb(plugin->title, track->data_type);
2432 if( !server || server->transition ) {
2434 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2435 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2436 "effect", _(plugin->title), path);
2437 MainError::show_error(string);
2442 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2443 if( !edit->transition ) continue;
2444 // ok we need to find transition in plugindb
2445 PluginServer *server =
2446 scan_plugindb(edit->transition->title, track->data_type);
2447 if( !server || !server->transition ) {
2449 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2450 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2451 "transition", _(edit->transition->title), path);
2452 MainError::show_error(string);
2459 void MWindow::init_shm(const char *pfn, int64_t min)
2462 // Fix shared memory
2463 FILE *fd = fopen(pfn, "r");
2465 fscanf(fd, "%jd", &result);
2467 if( result >= min ) return;
2470 fd = fopen(pfn, "w");
2472 fprintf(fd, "0x%jx", min);
2475 fd = fopen(pfn, "r");
2477 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2481 fscanf(fd, "%jd", &result);
2483 if( result < min ) {
2484 eprintf(_("MWindow::init_shm: %s is %p.\n"
2485 "you probably need to be root, or:\n"
2486 "as root, run: echo 0x%jx > %s\n"
2487 "before trying to start cinelerra.\n"
2488 "It should be at least 0x%jx for Cinelerra.\n"),
2489 pfn, (void *)result, min, pfn, min);
2493 void MWindow::create_objects(int want_gui,
2497 const int debug = 0;
2498 if(debug) PRINT_TRACE
2500 // For some reason, init_signals must come after show_splash or the signals won't
2503 if(debug) PRINT_TRACE
2506 if(debug) PRINT_TRACE
2509 if(debug) PRINT_TRACE
2510 default_standard = default_std();
2511 init_defaults(defaults, config_path);
2515 splash_window->operation->update(_("Initializing Plugins"));
2516 init_plugins(this, preferences);
2517 if(debug) PRINT_TRACE
2518 init_ladspa_plugins(this, preferences);
2519 if(debug) PRINT_TRACE
2520 init_plugin_tips(*plugindb, cin_lang);
2522 splash_window->operation->update(_("Initializing GUI"));
2523 if(debug) PRINT_TRACE
2526 if(debug) PRINT_TRACE
2530 splash_window->operation->update(_("Initializing Fonts"));
2531 char string[BCTEXTLEN];
2532 strcpy(string, preferences->plugin_dir);
2533 strcat(string, "/" FONT_SEARCHPATH);
2534 BC_Resources::init_fontconfig(string);
2535 if(debug) PRINT_TRACE
2537 // Default project created here
2539 if(debug) PRINT_TRACE
2542 if(debug) PRINT_TRACE
2547 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2550 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2552 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2553 if(session->show_vwindow)
2554 get_viewer(1, DEFAULT_VWINDOW);
2555 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2558 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2561 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2564 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2567 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2570 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2573 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2578 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2579 mainprogress = new MainProgress(this, gui);
2580 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2581 undo = new MainUndo(this);
2583 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2585 plugin_guis = new ArrayList<PluginServer*>;
2586 dead_plugins = new ArrayList<PluginServer*>;
2587 keyframe_threads = new ArrayList<KeyFrameThread*>;
2589 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2592 session->show_vwindow);
2594 // Show all vwindows
2595 // if(session->show_vwindow) {
2596 // for(int j = 0; j < vwindows.size(); j++) {
2597 // VWindow *vwindow = vwindows[j];
2598 // if( !vwindow->is_running() ) continue;
2599 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2602 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2603 // vwindow->gui->lock_window("MWindow::create_objects 1");
2604 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2605 // vwindow->gui->show_window();
2606 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2607 // vwindow->gui->unlock_window();
2612 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2614 if(session->show_cwindow)
2616 cwindow->gui->lock_window("MWindow::create_objects 1");
2617 cwindow->gui->show_window();
2618 cwindow->gui->unlock_window();
2621 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2622 if(session->show_awindow)
2624 awindow->gui->lock_window("MWindow::create_objects 1");
2625 awindow->gui->show_window();
2626 awindow->gui->unlock_window();
2629 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2630 if(session->show_lwindow)
2632 lwindow->gui->lock_window("MWindow::create_objects 1");
2633 lwindow->gui->show_window();
2634 lwindow->gui->unlock_window();
2637 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2639 (int)timer.get_difference(),
2641 if(session->show_gwindow)
2643 gwindow->gui->lock_window("MWindow::create_objects 1");
2644 gwindow->gui->show_window();
2645 gwindow->gui->unlock_window();
2648 if(debug) PRINT_TRACE
2650 gui->lock_window("MWindow::create_objects 1");
2651 gui->mainmenu->load_defaults(defaults);
2652 gui->mainmenu->update_toggles(0);
2653 gui->update_patchbay();
2654 gui->draw_canvas(0, 0);
2655 gui->draw_cursor(1);
2657 gui->raise_window();
2658 gui->unlock_window();
2660 if(debug) PRINT_TRACE
2662 if(preferences->use_tipwindow)
2664 if(debug) PRINT_TRACE
2666 gui->add_keyboard_listener(
2667 (int (BC_WindowBase::*)(BC_WindowBase *))
2668 &MWindowGUI::keyboard_listener);
2671 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2672 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2673 if(debug) PRINT_TRACE
2675 BC_WindowBase::get_resources()->vframe_shm = 1;
2679 void MWindow::show_splash()
2681 #include "data/heroine_logo9_png.h"
2682 VFrame *frame = new VFramePng(heroine_logo9_png);
2683 BC_DisplayInfo dpyi;
2684 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2685 int rr = (rw < rh ? rw : rh) / 4;
2686 splash_window = new SplashGUI(frame, rr, rr);
2687 splash_window->create_objects();
2690 void MWindow::hide_splash()
2693 delete splash_window;
2698 void MWindow::start()
2702 // vwindows[DEFAULT_VWINDOW]->start();
2713 playback_3d->start();
2719 run_lock->lock("MWindow::run");
2723 brender_lock->lock("MWindow::run 1");
2724 delete brender; brender = 0;
2725 brender_lock->unlock();
2727 interrupt_indexes();
2733 void MWindow::show_vwindow()
2735 int total_running = 0;
2736 session->show_vwindow = 1;
2738 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2739 // Raise all windows which are visible
2740 for(int j = 0; j < vwindows.size(); j++) {
2741 VWindow *vwindow = vwindows[j];
2742 if( !vwindow->is_running() ) continue;
2743 vwindow->gui->lock_window("MWindow::show_vwindow");
2744 vwindow->gui->show_window(0);
2745 vwindow->gui->raise_window();
2746 vwindow->gui->flush();
2747 vwindow->gui->unlock_window();
2751 // If no windows visible
2754 get_viewer(1, DEFAULT_VWINDOW);
2757 gui->mainmenu->show_vwindow->set_checked(1);
2760 void MWindow::show_awindow()
2762 session->show_awindow = 1;
2763 awindow->gui->lock_window("MWindow::show_awindow");
2764 awindow->gui->show_window();
2765 awindow->gui->raise_window();
2766 awindow->gui->flush();
2767 awindow->gui->unlock_window();
2768 gui->mainmenu->show_awindow->set_checked(1);
2771 char *MWindow::get_cwindow_display()
2773 char *x11_host = screens < 2 || session->window_config == 0 ?
2774 session->a_x11_host : session->b_x11_host;
2775 return *x11_host ? x11_host : 0;
2778 void MWindow::show_cwindow()
2780 session->show_cwindow = 1;
2781 cwindow->show_window();
2782 gui->mainmenu->show_cwindow->set_checked(1);
2785 void MWindow::show_gwindow()
2787 session->show_gwindow = 1;
2789 gwindow->gui->lock_window("MWindow::show_gwindow");
2790 gwindow->gui->show_window();
2791 gwindow->gui->raise_window();
2792 gwindow->gui->flush();
2793 gwindow->gui->unlock_window();
2795 gui->mainmenu->show_gwindow->set_checked(1);
2797 void MWindow::hide_gwindow()
2799 session->show_gwindow = 0;
2801 gwindow->gui->lock_window("MWindow::show_gwindow");
2802 gwindow->gui->hide_window();
2803 gwindow->gui->unlock_window();
2806 void MWindow::show_lwindow()
2808 session->show_lwindow = 1;
2809 lwindow->gui->lock_window("MWindow::show_lwindow");
2810 lwindow->gui->show_window();
2811 lwindow->gui->raise_window();
2812 lwindow->gui->flush();
2813 lwindow->gui->unlock_window();
2814 gui->mainmenu->show_lwindow->set_checked(1);
2817 int MWindow::tile_windows(int window_config)
2819 int need_reload = 0;
2820 int play_config = window_config==0 ? 0 : 1;
2821 edl->session->playback_config->load_defaults(defaults, play_config);
2822 session->default_window_positions(window_config);
2823 if( screens == 1 ) {
2824 gui->default_positions();
2825 sync_parameters(CHANGE_ALL);
2832 void MWindow::toggle_loop_playback()
2834 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2835 set_loop_boundaries();
2838 gui->draw_overlays(1);
2839 sync_parameters(CHANGE_PARAMS);
2842 //void MWindow::set_titles(int value)
2844 // edl->session->show_titles = value;
2845 // trackmovement(edl->local_session->track_start);
2848 void MWindow::set_screens(int value)
2853 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2855 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2856 edl->session->auto_keyframes = value;
2857 gui->mbuttons->edit_panel->keyframe->update(value);
2859 if(lock_mwindow) gui->unlock_window();
2861 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2862 cwindow->gui->edit_panel->keyframe->update(value);
2863 cwindow->gui->flush();
2864 if(lock_cwindow) cwindow->gui->unlock_window();
2867 void MWindow::set_auto_visibility(Autos *autos, int value)
2869 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2870 edl->session->auto_conf->plugins = value;
2871 else if( autos->autoidx >= 0 )
2872 edl->session->auto_conf->autos[autos->autoidx] = value;
2876 gui->update(0, 1, 0, 0, 0, 0, 0);
2877 gui->mainmenu->update_toggles(1);
2878 gui->unlock_window();
2879 gwindow->gui->update_toggles(1);
2880 gui->lock_window("MWindow::set_auto_visibility");
2883 void MWindow::set_keyframe_type(int mode)
2885 gui->lock_window("MWindow::set_keyframe_type");
2886 edl->local_session->floatauto_type = mode;
2887 gui->mainmenu->update_toggles(0);
2888 gui->unlock_window();
2891 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2893 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2894 edl->session->editing_mode = new_editing_mode;
2895 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2896 gui->mbuttons->edit_panel->update();
2897 gui->set_editing_mode(1);
2898 if(lock_mwindow) gui->unlock_window();
2901 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2902 cwindow->gui->edit_panel->update();
2903 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2904 if(lock_cwindow) cwindow->gui->unlock_window();
2908 void MWindow::toggle_editing_mode()
2910 int mode = edl->session->editing_mode;
2911 if( mode == EDITING_ARROW )
2912 set_editing_mode(EDITING_IBEAM, 0, 1);
2914 set_editing_mode(EDITING_ARROW, 0, 1);
2918 void MWindow::set_labels_follow_edits(int value)
2920 gui->lock_window("MWindow::set_labels_follow_edits");
2921 edl->session->labels_follow_edits = value;
2922 gui->mbuttons->edit_panel->locklabels->update(value);
2923 gui->mainmenu->labels_follow_edits->set_checked(value);
2925 gui->unlock_window();
2928 void MWindow::sync_parameters(int change_type)
2930 if( in_destructor ) return;
2932 // Sync engines which are playing back
2933 if(cwindow->playback_engine->is_playing_back)
2935 if(change_type == CHANGE_PARAMS)
2937 // TODO: block keyframes until synchronization is done
2938 cwindow->playback_engine->sync_parameters(edl);
2943 int command = cwindow->playback_engine->command->command;
2944 cwindow->playback_engine->que->send_command(STOP,
2948 // Waiting for tracking to finish would make the restart position more
2949 // accurate but it can't lock the window to stop tracking for some reason.
2950 // Not waiting for tracking gives a faster response but restart position is
2951 // only as accurate as the last tracking update.
2952 cwindow->playback_engine->interrupt_playback(0);
2953 cwindow->playback_engine->que->send_command(command,
2962 cwindow->refresh_frame(change_type);
2966 void MWindow::age_caches()
2968 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2970 // preferences->cache_size,
2971 // audio_cache->get_memory_usage(1),
2972 // video_cache->get_memory_usage(1),
2973 // frame_cache->get_memory_usage(),
2974 // wave_cache->get_memory_usage(),
2976 frame_cache->age_cache(512);
2977 wave_cache->age_cache(8192);
2979 int64_t memory_usage;
2980 int64_t prev_memory_usage = 0;
2982 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2983 while( !result && prev_memory_usage !=
2984 (memory_usage=video_cache->get_memory_usage(1)) &&
2985 memory_usage > video_size ) {
2986 video_cache->delete_oldest();
2987 prev_memory_usage = memory_usage;
2990 prev_memory_usage = 0;
2992 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2993 while( !result && prev_memory_usage !=
2994 (memory_usage=audio_cache->get_memory_usage(1)) &&
2995 memory_usage > audio_size ) {
2996 audio_cache->delete_oldest();
2997 prev_memory_usage = memory_usage;
3001 void MWindow::reset_android_remote()
3003 gui->use_android_remote(preferences->android_remote);
3007 void MWindow::show_keyframe_gui(Plugin *plugin)
3009 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3010 // Find existing thread
3011 for(int i = 0; i < keyframe_threads->size(); i++)
3013 if(keyframe_threads->get(i)->plugin == plugin)
3015 keyframe_threads->get(i)->start_window(plugin, 0);
3016 keyframe_gui_lock->unlock();
3021 // Find unused thread
3022 for(int i = 0; i < keyframe_threads->size(); i++)
3024 if(!keyframe_threads->get(i)->plugin)
3026 keyframe_threads->get(i)->start_window(plugin, 0);
3027 keyframe_gui_lock->unlock();
3032 // Create new thread
3033 KeyFrameThread *thread = new KeyFrameThread(this);
3034 keyframe_threads->append(thread);
3035 thread->start_window(plugin, 0);
3037 keyframe_gui_lock->unlock();
3044 void MWindow::show_plugin(Plugin *plugin)
3049 // Remove previously deleted plugin GUIs
3050 dead_plugin_lock->lock("MWindow::show_plugin");
3051 dead_plugins->remove_all_objects();
3052 dead_plugin_lock->unlock();
3054 //printf("MWindow::show_plugin %d\n", __LINE__);
3058 plugin_gui_lock->lock("MWindow::show_plugin");
3059 for(int i = 0; i < plugin_guis->total; i++)
3061 // Pointer comparison
3062 if(plugin_guis->get(i)->plugin == plugin)
3064 plugin_guis->get(i)->raise_window();
3071 //printf("MWindow::show_plugin 1\n");
3072 if( !done && !plugin->track ) {
3073 printf("MWindow::show_plugin track not defined.\n");
3077 PluginServer *server = scan_plugindb(plugin->title,
3078 plugin->track->data_type);
3080 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3081 if(server && server->uses_gui)
3083 PluginServer *gui = new PluginServer(*server);
3084 plugin_guis->append(gui);
3085 // Needs mwindow to do GUI
3086 gui->set_mwindow(this);
3087 gui->open_plugin(0, preferences, edl, plugin);
3092 plugin_gui_lock->unlock();
3093 //printf("MWindow::show_plugin %d\n", __LINE__);
3096 //printf("MWindow::show_plugin 2\n");
3099 void MWindow::hide_plugin(Plugin *plugin, int lock)
3102 // Update the toggle
3103 gui->lock_window("MWindow::hide_plugin");
3104 gui->update(0, 1, 0, 0, 0, 0, 0);
3105 gui->unlock_window();
3107 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3108 for(int i = 0; i < plugin_guis->total; i++)
3110 if(plugin_guis->get(i)->plugin == plugin)
3112 PluginServer *ptr = plugin_guis->get(i);
3113 plugin_guis->remove(ptr);
3114 if(lock) plugin_gui_lock->unlock();
3115 // Last command executed in client side close
3116 // Schedule for deletion
3123 if(lock) plugin_gui_lock->unlock();
3126 void MWindow::delete_plugin(PluginServer *plugin)
3128 dead_plugin_lock->lock("MWindow::delete_plugin");
3129 dead_plugins->append(plugin);
3130 dead_plugin_lock->unlock();
3133 void MWindow::hide_plugins()
3135 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3136 while(plugin_guis->size())
3138 PluginServer *ptr = plugin_guis->get(0);
3139 plugin_guis->remove(ptr);
3140 plugin_gui_lock->unlock();
3141 // Last command executed in client side close
3142 // Schedule for deletion
3145 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3147 plugin_gui_lock->unlock();
3149 hide_keyframe_guis();
3152 void MWindow::hide_keyframe_guis()
3154 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3155 for(int i = 0; i < keyframe_threads->size(); i++)
3157 keyframe_threads->get(i)->close_window();
3159 keyframe_gui_lock->unlock();
3162 void MWindow::hide_keyframe_gui(Plugin *plugin)
3164 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3165 for(int i = 0; i < keyframe_threads->size(); i++)
3167 if(keyframe_threads->get(i)->plugin == plugin)
3169 keyframe_threads->get(i)->close_window();
3173 keyframe_gui_lock->unlock();
3176 void MWindow::update_keyframe_guis()
3178 // Send new configuration to keyframe GUI's
3179 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3180 for(int i = 0; i < keyframe_threads->size(); i++)
3182 KeyFrameThread *ptr = keyframe_threads->get(i);
3183 if(edl->tracks->plugin_exists(ptr->plugin))
3187 ptr->close_window();
3190 keyframe_gui_lock->unlock();
3193 void MWindow::update_plugin_guis(int do_keyframe_guis)
3195 // Send new configuration to plugin GUI's
3196 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3198 for(int i = 0; i < plugin_guis->size(); i++)
3200 PluginServer *ptr = plugin_guis->get(i);
3201 if(edl->tracks->plugin_exists(ptr->plugin))
3205 // Schedule for deletion if no plugin
3206 plugin_guis->remove_number(i);
3215 // Change plugin variable if not visible
3216 Track *track = edl->tracks->first;
3219 for(int i = 0; i < track->plugin_set.size(); i++)
3221 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3225 for(int i = 0; i < plugin_guis->size(); i++)
3227 PluginServer *server = plugin_guis->get(i);
3228 if(server->plugin == plugin)
3235 if(!got_it) plugin->show = 0;
3237 plugin = (Plugin*)plugin->next;
3241 track = track->next;
3244 plugin_gui_lock->unlock();
3247 if(do_keyframe_guis) update_keyframe_guis();
3250 int MWindow::plugin_gui_open(Plugin *plugin)
3253 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3254 for(int i = 0; i < plugin_guis->total; i++)
3256 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3262 plugin_gui_lock->unlock();
3266 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3268 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3269 for(int i = 0; i < plugin_guis->total; i++)
3271 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3273 plugin_guis->get(i)->render_gui(data);
3277 plugin_gui_lock->unlock();
3280 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3282 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3283 for(int i = 0; i < plugin_guis->total; i++)
3285 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3287 plugin_guis->get(i)->render_gui(data, size);
3291 plugin_gui_lock->unlock();
3295 void MWindow::update_plugin_states()
3297 plugin_gui_lock->lock("MWindow::update_plugin_states");
3298 for(int i = 0; i < plugin_guis->total; i++)
3302 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3303 PluginServer *src_plugingui = plugin_guis->get(i);
3305 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3306 for(Track *track = edl->tracks->first;
3308 track = track->next)
3311 j < track->plugin_set.total && !result;
3314 PluginSet *plugin_set = track->plugin_set[j];
3315 for(Plugin *plugin = (Plugin*)plugin_set->first;
3317 plugin = (Plugin*)plugin->next)
3319 if(plugin == src_plugin &&
3320 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3326 // Doesn't exist anymore
3329 hide_plugin(src_plugin, 0);
3333 plugin_gui_lock->unlock();
3337 void MWindow::update_plugin_titles()
3339 for(int i = 0; i < plugin_guis->total; i++)
3341 plugin_guis->get(i)->update_title();
3345 int MWindow::asset_to_edl(EDL *new_edl,
3347 RecordLabels *labels)
3349 const int debug = 0;
3350 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3353 // Keep frame rate, sample rate, and output size unchanged.
3354 // These parameters would revert the project if VWindow displayed an asset
3355 // of different size than the project.
3356 if(new_asset->video_data)
3358 new_edl->session->video_tracks = new_asset->layers;
3361 new_edl->session->video_tracks = 0;
3363 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3369 if(new_asset->audio_data)
3371 new_edl->session->audio_tracks = new_asset->channels;
3374 new_edl->session->audio_tracks = 0;
3375 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3377 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3378 new_edl->create_default_tracks();
3379 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3380 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3384 //printf("MWindow::asset_to_edl 3\n");
3385 new_edl->insert_asset(new_asset,
3390 //printf("MWindow::asset_to_edl 3\n");
3391 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3393 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3394 if(edl->session->cursor_on_frames)
3396 double length = new_edl->tracks->total_length();
3397 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3398 new_edl->tracks->clear(length, edl_length, 1, 1);
3404 char string[BCTEXTLEN];
3406 fs.extract_name(string, new_asset->path);
3407 //printf("MWindow::asset_to_edl 3\n");
3409 strcpy(new_edl->local_session->clip_title, string);
3410 //printf("MWindow::asset_to_edl 4 %s\n", string);
3411 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3417 // Reset everything after a load.
3418 void MWindow::update_project(int load_mode)
3420 const int debug = 0;
3422 if(debug) PRINT_TRACE
3423 edl->tracks->update_y_pixels(theme);
3425 if(debug) PRINT_TRACE
3427 if(load_mode == LOADMODE_REPLACE ||
3428 load_mode == LOADMODE_REPLACE_CONCATENATE)
3433 gui->update(1, 1, 1, 1, 1, 1, 1);
3434 if(debug) PRINT_TRACE
3435 gui->unlock_window();
3438 cwindow->gui->lock_window("MWindow::update_project 1");
3439 cwindow->update(0, 0, 1, 1, 1);
3440 cwindow->gui->unlock_window();
3442 if(debug) PRINT_TRACE
3444 // Close all the vwindows
3445 if( load_mode == LOADMODE_REPLACE ||
3446 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3447 if(debug) PRINT_TRACE
3448 int first_vwindow = 0;
3449 if(session->show_vwindow) first_vwindow = 1;
3450 // Change visible windows to no source
3451 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3452 VWindow *vwindow = vwindows[i];
3453 if( !vwindow->is_running() ) continue;
3454 vwindow->change_source(-1);
3457 // Close remaining windows
3458 for(int i = first_vwindow; i < vwindows.size(); i++) {
3459 VWindow *vwindow = vwindows[i];
3460 if( !vwindow->is_running() ) continue;
3461 vwindow->close_window();
3463 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3464 VWindow *vwindow = get_viewer(1, -1);
3465 vwindow->change_source(i);
3467 if(debug) PRINT_TRACE
3471 for( int i=0; i<edl->mixers.size(); ++i ) {
3472 Mixer *mixer = edl->mixers[i];
3473 ZWindow *zwindow = get_mixer(mixer);
3474 zwindow->set_title(mixer->title);
3479 if(vwindows.size()) {
3480 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3481 if( vwindow->is_running() ) {
3482 vwindow->gui->lock_window("MWindow::update_project");
3484 vwindow->gui->unlock_window();
3489 if(debug) PRINT_TRACE
3490 cwindow->gui->lock_window("MWindow::update_project 2");
3491 cwindow->gui->timebar->update(0);
3492 cwindow->gui->unlock_window();
3494 if(debug) PRINT_TRACE
3495 cwindow->refresh_frame(CHANGE_ALL);
3497 awindow->gui->async_update_assets();
3498 if(debug) PRINT_TRACE
3500 gui->lock_window("MWindow::update_project");
3501 gui->update_mixers(0, 0);
3503 if(debug) PRINT_TRACE
3506 void MWindow::remove_indexfile(Indexable *indexable)
3508 if( !indexable->is_asset ) return;
3509 Asset *asset = (Asset *)indexable;
3511 IndexFile::delete_index(preferences, asset, ".toc");
3512 IndexFile::delete_index(preferences, asset, ".idx");
3513 IndexFile::delete_index(preferences, asset, ".mkr");
3516 void MWindow::rebuild_indices()
3518 for(int i = 0; i < session->drag_assets->total; i++)
3520 Indexable *indexable = session->drag_assets->get(i);
3521 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3522 remove_indexfile(indexable);
3523 // Schedule index build
3524 IndexState *index_state = indexable->index_state;
3525 index_state->index_status = INDEX_NOTTESTED;
3526 if( indexable->is_asset ) {
3527 Asset *asset = (Asset *)indexable;
3528 if( asset->format != FILE_PCM ) {
3529 asset->format = FILE_UNKNOWN;
3530 asset->reset_audio();
3532 asset->reset_video();
3533 remove_asset_from_caches(asset);
3534 // File file; // re-probe the asset
3535 // file.open_file(preferences, asset, 1, 0);
3537 mainindexes->add_next_asset(0, indexable);
3539 mainindexes->start_build();
3543 void MWindow::save_backup()
3547 edl->set_path(session->filename);
3548 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3549 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3550 File::get_config_path(), BACKUP_FILE);
3551 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3552 File::get_config_path(), BACKUP_FILE1);
3553 rename(backup_path, backup_path1);
3554 edl->save_xml(&file, backup_path);
3555 file.terminate_string();
3557 fs.complete_path(backup_path);
3559 if(file.write_to_file(backup_path))
3562 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3563 gui->show_message(string2);
3567 void MWindow::load_backup()
3569 ArrayList<char*> path_list;
3570 path_list.set_array_delete();
3572 char backup_path[BCTEXTLEN];
3573 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3574 File::get_config_path(), BACKUP_FILE);
3576 fs.complete_path(backup_path);
3578 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3579 strcpy(out_path, backup_path);
3581 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3582 edl->local_session->clip_title[0] = 0;
3583 // This is unique to backups since the path of the backup is different than the
3584 // path of the project.
3585 set_filename(edl->path);
3586 path_list.remove_all_objects();
3591 void MWindow::save_undo_data()
3593 char perpetual_path[BCTEXTLEN];
3594 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3595 File::get_config_path(), PERPETUAL_FILE);
3596 FILE *fp = fopen(perpetual_path,"w");
3602 void MWindow::load_undo_data()
3604 char perpetual_path[BCTEXTLEN];
3605 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3606 File::get_config_path(), PERPETUAL_FILE);
3607 FILE *fp = fopen(perpetual_path,"r");
3613 static inline int gcd(int m, int n)
3616 if( m < n ) { r = m; m = n; n = r; }
3617 while( (r = m % n) != 0 ) { m = n; n = r; }
3621 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3624 if(!width || !height) return 1;
3625 if( width == 720 && (height == 480 || height == 576) ) {
3626 w = 4; h = 3; return 0; // for NTSC and PAL
3628 double ar = (double)width / height;
3629 // square-ish pixels
3630 if( EQUIV(ar, 1.0000) ) return 0;
3631 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3632 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3633 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3634 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3635 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3636 int ww = width, hh = height;
3637 // numerator, denominator must be under mx
3638 int mx = 255, n = gcd(ww, hh);
3639 if( n > 1 ) { ww /= n; hh /= n; }
3640 // search near height in case extra/missing lines
3641 if( ww >= mx || hh >= mx ) {
3642 double err = height; // +/- 2 percent height
3643 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3644 int iw = width, ih = height+i;
3645 if( (n=gcd(iw, ih)) > 1 ) {
3646 int u = iw/n; if( u >= mx ) continue;
3647 int v = ih/n; if( v >= mx ) continue;
3648 double r = (double) u/v, er = fabs(ar-r);
3649 if( er >= err ) continue;
3650 err = er; ww = u; hh = v;
3659 void MWindow::reset_caches()
3661 frame_cache->remove_all();
3662 wave_cache->remove_all();
3663 audio_cache->remove_all();
3664 video_cache->remove_all();
3665 if( cwindow->playback_engine ) {
3666 if( cwindow->playback_engine->audio_cache )
3667 cwindow->playback_engine->audio_cache->remove_all();
3668 if( cwindow->playback_engine->video_cache )
3669 cwindow->playback_engine->video_cache->remove_all();
3671 for(int i = 0; i < vwindows.size(); i++) {
3672 VWindow *vwindow = vwindows[i];
3673 if( !vwindow->is_running() ) continue;
3674 if( !vwindow->playback_engine ) continue;
3675 if( vwindow->playback_engine->audio_cache )
3676 vwindow->playback_engine->audio_cache->remove_all();
3677 if( vwindow->playback_engine->video_cache )
3678 vwindow->playback_engine->video_cache->remove_all();
3682 void MWindow::remove_asset_from_caches(Asset *asset)
3684 frame_cache->remove_asset(asset);
3685 wave_cache->remove_asset(asset);
3686 audio_cache->delete_entry(asset);
3687 video_cache->delete_entry(asset);
3688 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3689 cwindow->playback_engine->audio_cache->delete_entry(asset);
3690 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3691 cwindow->playback_engine->video_cache->delete_entry(asset);
3692 for(int i = 0; i < vwindows.size(); i++) {
3693 VWindow *vwindow = vwindows[i];
3694 if( !vwindow->is_running() ) continue;
3695 if( !vwindow->playback_engine ) continue;
3696 if( vwindow->playback_engine->audio_cache )
3697 vwindow->playback_engine->audio_cache->delete_entry(asset);
3698 if( vwindow->playback_engine->video_cache )
3699 vwindow->playback_engine->video_cache->delete_entry(asset);
3704 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3705 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3707 for(int i = 0; i < drag_assets->total; i++) {
3708 Indexable *indexable = drag_assets->get(i);
3709 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3712 // Remove from VWindow.
3713 for(int i = 0; i < session->drag_clips->total; i++) {
3714 for(int j = 0; j < vwindows.size(); j++) {
3715 VWindow *vwindow = vwindows[j];
3716 if( !vwindow->is_running() ) continue;
3717 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3718 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3719 vwindow->delete_source(1, 1);
3720 vwindow->gui->unlock_window();
3725 for(int i = 0; i < drag_assets->size(); i++) {
3726 for(int j = 0; j < vwindows.size(); j++) {
3727 VWindow *vwindow = vwindows[j];
3728 if( !vwindow->is_running() ) continue;
3729 if(drag_assets->get(i) == vwindow->get_source()) {
3730 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3731 vwindow->delete_source(1, 1);
3732 vwindow->gui->unlock_window();
3737 for(int i = 0; i < drag_assets->size(); i++) {
3738 Indexable *indexable = drag_assets->get(i);
3739 remove_indexfile(indexable);
3742 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3743 if(push_undo) undo->update_undo_before();
3744 if(drag_assets) edl->remove_from_project(drag_assets);
3745 if(drag_clips) edl->remove_from_project(drag_clips);
3746 if(redraw) save_backup();
3747 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3751 gui->lock_window("MWindow::remove_assets_from_project 3");
3752 gui->update(1, 1, 1, 1, 0, 1, 0);
3753 gui->unlock_window();
3755 // Removes from playback here
3756 sync_parameters(CHANGE_ALL);
3759 awindow->gui->async_update_assets();
3762 void MWindow::remove_assets_from_disk()
3765 for(int i = 0; i < session->drag_assets->total; i++)
3767 remove(session->drag_assets->get(i)->path);
3770 remove_assets_from_project(1,
3772 session->drag_assets,
3773 session->drag_clips);
3776 void MWindow::dump_plugins(FILE *fp)
3778 if( !plugindb ) return;
3779 for(int i = 0; i < plugindb->total; i++)
3781 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3782 " synth=%d transition=%d theme=%d %s\n",
3783 plugindb->get(i)->plugin_type,
3784 plugindb->get(i)->audio,
3785 plugindb->get(i)->video,
3786 plugindb->get(i)->realtime,
3787 plugindb->get(i)->multichannel,
3788 plugindb->get(i)->get_synthesis(),
3789 plugindb->get(i)->transition,
3790 plugindb->get(i)->theme,
3791 plugindb->get(i)->title);
3795 void MWindow::dump_edl(FILE *fp)
3801 void MWindow::dump_undo(FILE *fp)
3807 void MWindow::dump_exe(FILE *fp)
3809 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3810 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3812 int ret = -1, n = 100;
3813 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3814 exe_path[len] = 0; strcpy(proc_path, exe_path);
3817 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3820 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3821 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3822 struct tm *tm = localtime(&st.st_mtime);
3824 strftime(mtime, sizeof(mtime), "%F %T", tm);
3825 fprintf(fp,"mtime: %s\n", mtime);
3827 // people hit ctl-c waiting for this
3828 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3829 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3832 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3833 int64_t maxsz = 1024*pagsz;
3834 int64_t size = st.st_size, pos = 0;
3836 while( (bfrsz = size-pos) > 0 ) {
3837 if( bfrsz > maxsz ) bfrsz = maxsz;
3838 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3839 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3840 if( bfr == MAP_FAILED ) break;
3841 sha1.addBytes(bfr, bfrsz);
3846 ret = pos < size ? EIO : 0;
3847 fprintf(fp, "SHA1: ");
3848 uint8_t digest[20]; sha1.computeHash(digest);
3849 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3850 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3851 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3856 void MWindow::trap_hook(FILE *fp, void *vp)
3858 MWindow *mwindow = (MWindow *)vp;
3859 // fprintf(fp, "\nPLUGINS:\n");
3860 // mwindow->dump_plugins(fp);
3861 fprintf(fp, "\nEDL:\n");
3862 mwindow->dump_edl(fp);
3863 fprintf(fp, "\nUNDO:\n");
3864 mwindow->dump_undo(fp);
3865 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
3866 mwindow->dump_exe(fp);
3874 int MWindow::save_defaults()
3876 gui->save_defaults(defaults);
3877 edl->save_defaults(defaults);
3878 session->save_defaults(defaults);
3879 preferences->save_defaults(defaults);
3881 for(int i = 0; i < plugin_guis->total; i++)
3883 // Pointer comparison
3884 plugin_guis->get(i)->save_defaults();
3886 awindow->save_defaults(defaults);
3892 int MWindow::run_script(FileXML *script)
3894 int result = 0, result2 = 0;
3895 while(!result && !result2)
3897 result = script->read_tag();
3900 if(script->tag.title_is("new_project"))
3902 // Run new in immediate mode.
3903 // gui->mainmenu->new_project->run_script(script);
3906 if(script->tag.title_is("record"))
3908 // Run record as a thread. It is a terminal command.
3910 // Will read the complete scipt file without letting record read it if not
3916 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3923 // ================================= synchronization
3926 int MWindow::interrupt_indexes()
3928 mainprogress->cancelled = 1;
3929 mainindexes->interrupt_build();
3935 void MWindow::next_time_format()
3937 switch(edl->session->time_format)
3939 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3940 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3941 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3942 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3943 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3944 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3945 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3948 time_format_common();
3951 void MWindow::prev_time_format()
3953 switch(edl->session->time_format)
3955 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3956 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3957 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3958 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3959 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3960 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3961 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3964 time_format_common();
3967 void MWindow::time_format_common()
3969 gui->lock_window("MWindow::next_time_format");
3970 gui->redraw_time_dependancies();
3973 char string[BCTEXTLEN], string2[BCTEXTLEN];
3974 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3975 gui->show_message(string);
3977 gui->unlock_window();
3981 int MWindow::set_filename(const char *filename)
3983 if( filename != session->filename )
3984 strcpy(session->filename, filename);
3985 if( filename != edl->path )
3986 strcpy(edl->path, filename);
3990 if(filename[0] == 0)
3992 gui->set_title(PROGRAM_NAME);
3997 char string[BCTEXTLEN], string2[BCTEXTLEN];
3998 dir.extract_name(string, filename);
3999 sprintf(string2, PROGRAM_NAME ": %s", string);
4000 gui->set_title(string2);
4013 int MWindow::set_loop_boundaries()
4015 double start = edl->local_session->get_selectionstart();
4016 double end = edl->local_session->get_selectionend();
4024 if(edl->tracks->total_length())
4027 end = edl->tracks->total_length();
4034 if(edl->local_session->loop_playback && start != end)
4036 edl->local_session->loop_start = start;
4037 edl->local_session->loop_end = end;
4048 int MWindow::reset_meters()
4050 cwindow->gui->lock_window("MWindow::reset_meters 1");
4051 cwindow->gui->meters->reset_meters();
4052 cwindow->gui->unlock_window();
4054 for(int j = 0; j < vwindows.size(); j++) {
4055 VWindow *vwindow = vwindows[j];
4056 if( !vwindow->is_running() ) continue;
4057 vwindow->gui->lock_window("MWindow::reset_meters 2");
4058 vwindow->gui->meters->reset_meters();
4059 vwindow->gui->unlock_window();
4062 lwindow->gui->lock_window("MWindow::reset_meters 3");
4063 lwindow->gui->panel->reset_meters();
4064 lwindow->gui->unlock_window();
4066 gui->lock_window("MWindow::reset_meters 4");
4067 gui->reset_meters();
4068 gui->unlock_window();
4073 void MWindow::resync_guis()
4077 gui->lock_window("MWindow::resync_guis");
4078 gui->update(1, 1, 1, 1, 1, 1, 0);
4079 gui->unlock_window();
4081 cwindow->gui->lock_window("MWindow::resync_guis");
4082 cwindow->gui->resize_event(cwindow->gui->get_w(),
4083 cwindow->gui->get_h());
4084 int channels = edl->session->audio_channels;
4085 cwindow->gui->meters->set_meters(channels, 1);
4086 cwindow->gui->flush();
4087 cwindow->gui->unlock_window();
4089 for(int i = 0; i < vwindows.size(); i++) {
4090 VWindow *vwindow = vwindows[i];
4091 if( !vwindow->is_running() ) continue;
4092 vwindow->gui->lock_window("MWindow::resync_guis");
4093 vwindow->gui->resize_event(vwindow->gui->get_w(),
4094 vwindow->gui->get_h());
4095 vwindow->gui->meters->set_meters(channels, 1);
4096 vwindow->gui->flush();
4097 vwindow->gui->unlock_window();
4100 lwindow->gui->lock_window("MWindow::resync_guis");
4101 lwindow->gui->panel->set_meters(channels, 1);
4102 lwindow->gui->flush();
4103 lwindow->gui->unlock_window();
4106 if(((edl->session->output_w % 4) ||
4107 (edl->session->output_h % 4)) &&
4108 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4110 MainError::show_error(
4111 _("This project's dimensions are not multiples of 4 so\n"
4112 "it can't be rendered by OpenGL."));
4117 sync_parameters(CHANGE_ALL);
4120 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4122 File *file = new File;
4123 EDLSession *session = edl->session;
4124 double old_framerate = session->frame_rate;
4125 double old_samplerate = session->sample_rate;
4126 int old_auto_keyframes = session->auto_keyframes;
4127 session->auto_keyframes = 0;
4128 int result = file->open_file(preferences, asset, 1, 0);
4129 if( !result && delete_tracks > 0 )
4130 undo->update_undo_before();
4131 int video_layers = asset->get_video_layers();
4132 if( !result && asset->video_data && vstream < video_layers ) {
4133 // try to get asset up to date, may fail
4134 file->select_video_stream(asset, vstream);
4135 // either way use what was/is there.
4136 double framerate = asset->get_frame_rate();
4137 int width = asset->get_w();
4138 int height = asset->get_h();
4139 // must be multiple of 4 for opengl
4140 width = (width+3) & ~3; height = (height+3) & ~3;
4141 int driver = session->playback_config->vconfig->driver;
4142 int color_model = file->get_best_colormodel(asset, driver);
4143 // color_model = BC_CModels::is_yuv(color_model) ?
4144 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4145 // BC_CModels::is_float(color_model) ?
4146 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4147 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4148 // have alpha for now
4149 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4150 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4151 session->color_model = color_model;
4152 session->output_w = width;
4153 session->output_h = height;
4154 session->frame_rate = framerate;
4155 // not, asset->actual_width/actual_height
4156 asset->width = session->output_w;
4157 asset->height = session->output_h;
4158 asset->frame_rate = session->frame_rate;
4159 create_aspect_ratio(session->aspect_w, session->aspect_h,
4160 session->output_w, session->output_h);
4161 Track *track = edl->tracks->first;
4162 for( Track *next_track=0; track; track=next_track ) {
4163 next_track = track->next;
4164 if( track->data_type != TRACK_VIDEO ) continue;
4165 if( delete_tracks ) {
4166 Edit *edit = track->edits->first;
4167 for( Edit *next_edit=0; edit; edit=next_edit ) {
4168 next_edit = edit->next;
4169 if( edit->channel != vstream ||
4170 !edit->asset || !edit->asset->is_asset ||
4171 !asset->equivalent(*edit->asset,1,1,edl) )
4175 if( track->edits->first ) {
4176 track->track_w = edl->session->output_w;
4177 track->track_h = edl->session->output_h;
4179 else if( delete_tracks )
4180 edl->tracks->delete_track(track);
4183 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4185 if( !result && asset->audio_data && asset->channels > 0 ) {
4186 session->sample_rate = asset->get_sample_rate();
4187 int64_t channel_mask = 0;
4188 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4189 file->get_audio_for_video(vstream, astream, channel_mask);
4190 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4191 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4193 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4194 if( channels < 1 ) channels = 1;
4195 if( channels > 6 ) channels = 6;
4196 session->audio_tracks = session->audio_channels = channels;
4198 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4199 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4200 remap_audio(MWindow::AUDIO_1_TO_1);
4202 if( delete_tracks ) {
4203 Track *track = edl->tracks->first;
4204 for( Track *next_track=0; track; track=next_track ) {
4205 next_track = track->next;
4206 if( track->data_type != TRACK_AUDIO ) continue;
4207 Edit *edit = track->edits->first;
4208 for( Edit *next_edit=0; edit; edit=next_edit ) {
4209 next_edit = edit->next;
4210 if( !((1<<edit->channel) & channel_mask) ||
4211 !edit->asset || !edit->asset->is_asset ||
4212 !asset->equivalent(*edit->asset,1,1,edl) )
4215 if( !track->edits->first )
4216 edl->tracks->delete_track(track);
4220 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4223 session->auto_keyframes = old_auto_keyframes;
4224 if( !result && delete_tracks > 0 ) {
4226 undo->update_undo_after(_("select asset"), LOAD_ALL);
4232 int MWindow::select_asset(int vtrack, int delete_tracks)
4234 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4236 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4237 if( !track ) return 1;
4238 Edit *edit = track->edits->first;
4239 if( !edit ) return 1;
4240 Asset *asset = edit->asset;
4241 if( !asset || !asset->is_asset ) return 1;
4242 return select_asset(asset, edit->channel, 0, delete_tracks);
4245 void MWindow::dump_plugindb(FILE *fp)
4247 if( !plugindb ) return;
4248 for(int i = 0; i < plugindb->total; i++)
4249 plugindb->get(i)->dump(fp);
4252 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4255 double unit_position = edl->local_session->get_selectionstart(1);
4256 unit_position = patch->track->to_units(unit_position, 0);
4258 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4259 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4262 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4265 double unit_position = edl->local_session->get_selectionstart(1);
4266 unit_position = patch->track->to_units(unit_position, 0);
4268 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4269 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4272 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4275 double unit_position = edl->local_session->get_selectionstart(1);
4276 unit_position = patch->track->to_units(unit_position, 0);
4278 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4279 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4282 PatchGUI *MWindow::get_patchgui(Track *track)
4284 PatchGUI *patchgui = 0;
4285 TimelinePane **panes = gui->pane;
4286 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4287 if( !panes[i] ) continue;
4288 PatchBay *patchbay = panes[i]->patchbay;
4289 if( !patchbay ) continue;
4290 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4291 if( patchbay->patches.values[j]->track == track )
4292 patchgui = patchbay->patches.values[j];