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 "bcprogressbox.h"
32 #include "bcsignals.h"
39 #include "channeldb.h"
40 #include "channelinfo.h"
43 #include "bccmodels.h"
44 #include "commercials.h"
45 #include "confirmsave.h"
46 #include "cplayback.h"
48 #include "cwindowgui.h"
50 #include "cwindowtool.h"
52 #include "devicedvbinput.inc"
53 #include "dvdcreate.h"
54 #include "editpanel.h"
56 #include "edlsession.h"
58 #include "fileformat.h"
60 #include "filesystem.h"
62 #include "floatautos.h"
63 #include "framecache.h"
65 #include "gwindowgui.h"
66 #include "keyframegui.h"
67 #include "indexfile.h"
69 #include "interlacemodes.h"
71 #include "levelwindowgui.h"
72 #include "levelwindow.h"
73 #include "loadfile.inc"
74 #include "localsession.h"
75 #include "maincursor.h"
76 #include "mainerror.h"
77 #include "mainindexes.h"
79 #include "mainprogress.h"
80 #include "mainsession.h"
84 #include "mwindowgui.h"
89 #include "playback3d.h"
90 #include "playbackengine.h"
92 #include "pluginserver.h"
93 #include "pluginset.h"
94 #include "preferences.h"
97 #include "recordmonitor.h"
98 #include "recordlabel.h"
99 #include "removefile.h"
101 #include "resourcethread.h"
102 #include "savefile.inc"
103 #include "samplescroll.h"
105 #include "sighandler.h"
106 #include "splashgui.h"
107 #include "statusbar.h"
109 #include "threadloader.h"
111 #include "timelinepane.h"
112 #include "tipwindow.h"
113 #include "trackcanvas.h"
115 #include "tracking.h"
116 #include "trackscroll.h"
118 #include "transition.h"
119 #include "transportque.h"
122 #include "versioninfo.h"
123 #include "videodevice.inc"
124 #include "videowindow.h"
125 #include "vplayback.h"
126 #include "vwindowgui.h"
128 #include "wavecache.h"
132 #include "zwindowgui.h"
133 #include "exportedl.h"
135 #include "defaultformats.h"
136 #include "ntsczones.h"
143 #include <sys/types.h>
144 #include <sys/stat.h>
145 #include <sys/time.h>
146 #include <sys/mman.h>
147 #include <sys/file.h>
158 // Hack for libdv to remove glib dependancy
161 // g_log (const char *log_domain,
163 // const char *format,
169 // g_logv (const char *log_domain,
171 // const char *format,
180 extern long cin_timezone;
182 ArrayList<PluginServer*>* MWindow::plugindb = 0;
183 Commercials* MWindow::commercials = 0;
189 run_lock = new Mutex("MWindow::run_lock");
190 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
191 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
192 vwindows_lock = new Mutex("MWindow::vwindows_lock");
193 zwindows_lock = new Mutex("MWindow::zwindows_lock");
194 brender_lock = new Mutex("MWindow::brender_lock");
195 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
203 commercial_active = 0;
215 strcpy(cin_lang,"en");
216 channeldb_buz = new ChannelDB;
217 channeldb_v4l2jpeg = new ChannelDB;
220 keyframe_threads = 0;
242 // Need to delete brender temporary here.
245 run_lock->lock("MWindow::~MWindow");
247 //printf("MWindow::~MWindow %d\n", __LINE__);
248 gui->remote_control->deactivate();
251 gui->channel_info->stop();
254 delete create_bd; create_bd = 0;
255 delete create_dvd; create_dvd = 0;
256 delete batch_render; batch_render = 0;
257 delete render; render = 0;
259 if( commercials && !commercials->remove_user() ) commercials = 0;
261 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
262 // Save defaults for open plugins
263 plugin_gui_lock->lock("MWindow::~MWindow");
264 for(int i = 0; i < plugin_guis->size(); i++) {
265 plugin_guis->get(i)->hide_gui();
266 delete_plugin(plugin_guis->get(i));
268 plugin_gui_lock->unlock();
269 hide_keyframe_guis();
272 // Give up and go to a movie
273 // cant run valgrind if this is used
275 gui->del_keyboard_listener(
276 (int (BC_WindowBase::*)(BC_WindowBase *))
277 &MWindowGUI::keyboard_listener);
279 // release the hounds
280 if( awindow && awindow->gui ) awindow->gui->close(0);
281 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
282 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
283 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
284 if( twindow && twindow->is_running() ) twindow->close_window();
285 if( wwindow && wwindow->is_running() ) wwindow->close_window();
286 vwindows.remove_all_objects();
287 zwindows.remove_all_objects();
289 if( awindow ) awindow->join();
290 if( cwindow ) cwindow->join();
291 if( lwindow ) lwindow->join();
292 if( twindow ) twindow->join();
293 if( wwindow ) wwindow->join();
294 if( gwindow ) gwindow->join();
297 // one at a time, or nouveau chokes
298 #define close_gui(win) if( win ) { \
299 if( win->gui ) win->gui->close(0); \
307 vwindows.remove_all_objects();
308 zwindows.remove_all_objects();
313 dead_plugins->remove_all_objects();
314 // must delete theme before destroying plugindb
315 // theme destructor will be deleted by delete_plugins
316 delete theme; theme = 0;
319 keyframe_threads->remove_all_objects();
320 colormodels.remove_all_objects();
321 delete awindow; awindow = 0;
322 delete lwindow; lwindow = 0;
323 delete twindow; twindow = 0;
324 delete wwindow; wwindow = 0;
325 delete gwindow; gwindow = 0;
326 delete cwindow; cwindow = 0;
328 delete mainindexes; mainindexes = 0;
329 delete mainprogress; mainprogress = 0;
330 delete audio_cache; audio_cache = 0; // delete the cache after the assets
331 delete video_cache; video_cache = 0; // delete the cache after the assets
332 delete frame_cache; frame_cache = 0;
333 delete wave_cache; wave_cache = 0;
334 delete plugin_guis; plugin_guis = 0;
335 delete dead_plugins; dead_plugins = 0;
336 delete keyframe_threads; keyframe_threads = 0;
337 delete undo; undo = 0;
338 delete preferences; preferences = 0;
339 delete exportedl; exportedl = 0;
340 delete session; session = 0;
341 delete defaults; defaults = 0;
342 delete assets; assets = 0;
343 delete splash_window; splash_window = 0;
344 if( !edl->Garbage::remove_user() ) edl = 0;
345 delete channeldb_buz;
346 delete channeldb_v4l2jpeg;
347 // This must be last thread to exit
348 delete playback_3d; playback_3d = 0;
349 delete dead_plugin_lock;
350 delete plugin_gui_lock;
351 delete vwindows_lock;
352 delete zwindows_lock;
354 delete keyframe_gui_lock;
355 colormodels.remove_all_objects();
356 interlace_project_modes.remove_all_objects();
357 interlace_asset_modes.remove_all_objects();
358 interlace_asset_fixmethods.remove_all_objects();
359 sighandler->terminate();
370 void MWindow::init_error()
372 MainError::init_error(this);
375 void MWindow::finit_error()
377 MainError::finit_error();
380 void MWindow::create_defaults_path(char *string, const char *config_file)
382 // set the .bcast path
385 sprintf(string, "%s/", File::get_config_path());
386 fs.complete_path(string);
387 if(!fs.is_dir(string))
388 fs.create_dir(string);
391 strcat(string, config_file);
393 const char *MWindow::default_std()
395 char buf[BCTEXTLEN], *p = 0;
397 int fd = open(TIMEZONE_NAME, O_RDONLY);
399 int l = read(fd, buf, sizeof(buf)-1);
402 if( buf[l-1] == '\n' ) --l;
408 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
411 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
412 p += strlen(ZONEINFO_STR);
417 for( int i=0; ntsc_zones[i]; ++i ) {
418 if( !strcmp(ntsc_zones[i], p) )
425 for( int i=0; ntsc_zones[i]; ++i ) {
426 if( !strcmp(ntsc_zones[i], p) )
431 // cin_timezone: Seconds west of UTC. 240sec/deg
432 double tz_deg = -cin_timezone / 240.;
433 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
434 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
437 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
439 struct formatpresets *fpr;
441 for(fpr = &format_presets[0]; fpr->name; fpr++)
443 if(strcmp(_(fpr->name), preset) == 0)
445 session->audio_channels = fpr->audio_channels;
446 session->audio_tracks = fpr->audio_tracks;
447 session->sample_rate = fpr->sample_rate;
448 session->video_channels = fpr->video_channels;
449 session->video_tracks = fpr->video_tracks;
450 session->frame_rate = fpr->frame_rate;
451 session->output_w = fpr->output_w;
452 session->output_h = fpr->output_h;
453 session->aspect_w = fpr->aspect_w;
454 session->aspect_h = fpr->aspect_h;
455 session->interlace_mode = fpr->interlace_mode;
456 session->color_model = fpr->color_model;
462 const char *MWindow::get_preset_name(int index)
464 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
466 return _(format_presets[index].name);
470 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
472 char path[BCTEXTLEN];
473 // Use user supplied path
475 strcpy(path, config_path);
477 create_defaults_path(path, CONFIG_FILE);
480 defaults = new BC_Hash(path);
485 void MWindow::check_language()
487 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
488 const char *env_lang = getenv("LANGUAGE");
489 if( !env_lang ) env_lang = getenv("LC_ALL");
490 if( !env_lang ) env_lang = getenv("LANG");
492 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
493 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
494 env_lang = curr_lang;
496 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
497 defaults->get("LAST_LANG",last_lang);
498 if( strcmp(env_lang,last_lang)) {
499 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
500 defaults->update("LAST_LANG",env_lang);
501 char plugin_path[BCTEXTLEN];
502 create_defaults_path(plugin_path, PLUGIN_FILE);
503 ::remove(plugin_path);
504 char ladspa_path[BCTEXTLEN];
505 create_defaults_path(ladspa_path, LADSPA_FILE);
506 ::remove(ladspa_path);
509 if( strlen(env_lang) > 1 &&
510 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
511 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
514 strcpy(cin_lang, "en");
517 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
519 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
521 const char *dp = plug_dir;
522 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
523 bp = !*dp && *bp == '/' ? bp+1 : base_path;
529 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir)
533 fseek(fp, 0, SEEK_SET);
535 char index_line[BCTEXTLEN];
536 int index_version = -1, len = strlen(plugin_dir);
537 if( !fgets(index_line, BCTEXTLEN, fp) ||
538 sscanf(index_line, "%d", &index_version) != 1 ||
539 index_version != PLUGIN_FILE_VERSION ||
540 !fgets(index_line, BCTEXTLEN, fp) ||
541 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
542 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
544 ArrayList<PluginServer*> plugins;
545 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
546 if( index_line[0] == ';' ) continue;
547 if( index_line[0] == '#' ) continue;
548 int type = PLUGIN_TYPE_UNKNOWN;
549 char path[BCTEXTLEN], title[BCTEXTLEN];
551 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
554 PluginServer *server = 0;
556 case PLUGIN_TYPE_BUILTIN:
557 case PLUGIN_TYPE_EXECUTABLE:
558 case PLUGIN_TYPE_LADSPA: {
559 char plugin_path[BCTEXTLEN]; struct stat st;
560 sprintf(plugin_path, "%s/%s", plugin_dir, path);
561 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
564 server = new PluginServer(mwindow, plugin_path, type);
566 case PLUGIN_TYPE_FFMPEG: {
567 server = new_ffmpeg_server(mwindow, path);
569 case PLUGIN_TYPE_LV2: {
570 server = new_lv2_server(mwindow, path);
573 if( !server ) continue;
574 plugins.append(server);
575 // Create plugin server from index entry
576 server->set_title(title);
577 if( server->read_table(index_line) ) {
583 ret = check_plugin_index(plugins, plugin_dir, ".");
586 add_plugins(plugins);
588 plugins.remove_all_objects();
593 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
594 const char *plug_dir, const char *plug_path)
596 char plugin_path[BCTEXTLEN];
597 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
599 fs.set_filter( "[*.plugin][*.so]" );
600 if( fs.update(plugin_path) )
603 for( int i=0; i<fs.dir_list.total; ++i ) {
604 char fs_path[BCTEXTLEN];
605 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
606 if( fs.is_dir(fs_path) ) {
607 get_plugin_path(plugin_path, plug_dir, fs_path);
608 if( check_plugin_index(plugins, plug_dir, plugin_path) )
611 else if( !plugin_exists(fs_path, plugins) )
618 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
621 plugindb = new ArrayList<PluginServer*>;
623 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
624 create_defaults_path(index_path, PLUGIN_FILE);
625 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
626 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
627 FILE *fp = fopen(index_path,"a+");
629 fprintf(stderr,_("MWindow::init_plugins: "
630 "can't open plugin index: %s\n"), index_path);
633 int fd = fileno(fp), ret = -1;
634 if( !flock(fd, LOCK_EX) ) {
635 fseek(fp, 0, SEEK_SET);
636 ret = load_plugin_index(mwindow, fp, plugin_path);
640 fseek(fp, 0, SEEK_SET);
641 printf("init plugin index: %s\n", plugin_path);
642 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
643 fprintf(fp, "%s\n", plugin_path);
644 init_plugin_index(mwindow, preferences, fp, plugin_path);
645 init_ffmpeg_index(mwindow, preferences, fp);
646 init_lv2_index(mwindow, preferences, fp);
647 fseek(fp, 0, SEEK_SET);
648 ret = load_plugin_index(mwindow, fp, plugin_path);
651 fprintf(stderr,_("MWindow::init_plugins: "
652 "can't %s plugin index: %s\n"),
653 ret>0 ? _("create") : _("lock"), index_path);
659 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
661 char *path = getenv("LADSPA_PATH");
662 char ladspa_path[BCTEXTLEN];
664 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
667 for( int len=0; *path; path+=len ) {
668 char *cp = strchr(path,':');
669 len = !cp ? strlen(path) : cp-path;
670 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
671 memcpy(plugin_path, path, len); plugin_path[len] = 0;
673 char *plugin_dir = FileSystem::basepath(plugin_path);
674 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
675 create_defaults_path(index_path, LADSPA_FILE);
676 cp = index_path + strlen(index_path);
677 for( char *bp=plugin_path; *bp!=0; ++bp )
678 *cp++ = *bp=='/' ? '_' : *bp;
680 FILE *fp = fopen(index_path,"a+");
682 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
683 "can't open ladspa plugin index: %s\n"), index_path);
686 int fd = fileno(fp), ret = -1;
687 if( !flock(fd, LOCK_EX) ) {
688 fseek(fp, 0, SEEK_SET);
689 ret = load_plugin_index(mwindow, fp, plugin_path);
693 fseek(fp, 0, SEEK_SET);
694 init_ladspa_index(mwindow, preferences, fp, plugin_path);
695 fseek(fp, 0, SEEK_SET);
696 ret = load_plugin_index(mwindow, fp, plugin_path);
699 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
700 "can't %s ladspa plugin index: %s\n"),
701 ret>0 ? _("create") : _("lock"), index_path);
708 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
709 FILE *fp, const char *plugin_dir)
711 int idx = PLUGIN_IDS;
713 for( int i=0; i<plugindb->size(); ++i ) {
714 PluginServer *server = plugindb->get(i);
715 if( server->dir_idx >= idx )
716 idx = server->dir_idx+1;
719 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
722 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
723 const char *plug_dir, const char *plug_path, int &idx)
725 char plugin_path[BCTEXTLEN];
726 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
728 fs.set_filter( "[*.plugin][*.so]" );
729 int result = fs.update(plugin_path);
730 if( result || !fs.dir_list.total ) return;
733 for( int i=0; i<fs.dir_list.total; ++i ) {
734 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
735 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
736 get_plugin_path(path, plug_dir, fs_path);
737 if( fs.is_dir(fs_path) ) {
738 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
741 if( plugin_exists(path) ) continue;
743 if( stat(fs_path, &st) ) continue;
744 int64_t mtime = st.st_mtime;
745 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
746 result = server.open_plugin(1, preferences, 0, 0);
748 server.write_table(fp, path, vis_id, mtime);
749 server.close_plugin();
751 else if( result == PLUGINSERVER_IS_LAD ) {
754 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
755 ladspa.set_lad_index(lad_index++);
756 result = ladspa.open_plugin(1, preferences, 0, 0);
758 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
759 ladspa.close_plugin();
765 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
767 for( int i=0; i<plugins.size(); ++i )
768 plugindb->append(plugins[i]);
769 plugins.remove_all();
772 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
774 const char *dat_path = File::get_cindat_path();
775 char msg_path[BCTEXTLEN];
777 if( BC_Resources::language[0] ) {
778 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
780 fp = fopen(msg_path, "r");
783 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
785 fp = fopen(msg_path, "r");
788 char text[BCTEXTLEN];
789 char *tp = text, *ep = tp + sizeof(text)-1;
790 char title[BCTEXTLEN];
795 char line[BCTEXTLEN], *cp = line;
796 if( fgets(line,sizeof(line)-1,fp) ) {
797 if( *cp == '#' ) continue;
798 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
801 if( tp > text && *--tp == '\n' ) *tp = 0;
803 int idx = plugins.size();
804 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
806 delete [] plugins[idx]->tip;
807 plugins[idx]->tip = cstrdup(text);
811 if( done > 0 ) break;
813 char *dp = strchr(cp, ':');
815 printf("plugin tips: error on line %d\n", no);
819 while( cp < dp ) *bp++ = *cp++;
824 while( *cp == ' ' || *cp == '\t' ) ++cp;
825 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
830 void MWindow::delete_plugins()
832 plugindb->remove_all_objects();
837 void MWindow::search_plugindb(int do_audio,
842 ArrayList<PluginServer*> &results)
845 for(int i = 0; i < MWindow::plugindb->total; i++)
847 PluginServer *current = MWindow::plugindb->get(i);
849 if(current->audio == do_audio &&
850 current->video == do_video &&
851 (current->realtime == is_realtime || is_realtime < 0) &&
852 current->transition == is_transition &&
853 current->theme == is_theme)
854 results.append(current);
857 // Alphabetize list by title
863 for(int i = 0; i < results.total - 1; i++)
865 PluginServer *value1 = results[i];
866 PluginServer *value2 = results[i + 1];
867 if(strcmp(_(value1->title), _(value2->title)) > 0)
871 results[i + 1] = value1;
877 PluginServer* MWindow::scan_plugindb(char *title,
882 // printf("MWindow::scan_plugindb data_type < 0\n");
886 for(int i = 0; i < plugindb->total; i++)
888 PluginServer *server = plugindb->get(i);
890 !strcasecmp(server->title, title) &&
892 (data_type == TRACK_AUDIO && server->audio) ||
893 (data_type == TRACK_VIDEO && server->video)))
894 return plugindb->get(i);
899 // repair session files with xlated plugin titles
900 void MWindow::fix_plugin_title(char *title)
902 for(int i = 0; i < plugindb->total; i++) {
903 PluginServer *server = plugindb->get(i);
904 if( !server->title ) continue;
905 const char *server_title = server->title;
906 if( !bstrcasecmp(title, _(server_title)) ) {
907 strcpy(title, server_title);
913 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
915 for( int i=0; i<plugins.size(); ++i )
916 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
920 int MWindow::plugin_exists(char *plugin_path)
922 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
925 void MWindow::remove_plugin_index()
927 char index_path[BCTEXTLEN];
928 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
929 ::remove(index_path);
932 void MWindow::init_preferences()
934 preferences = new Preferences;
935 preferences->load_defaults(defaults);
936 const char *lv2_path = getenv("LV2_PATH");
937 if( lv2_path && strcmp(lv2_path, preferences->lv2_path) ) {
938 strncpy(preferences->lv2_path, lv2_path, sizeof(preferences->lv2_path));
939 remove_plugin_index();
941 else if( !lv2_path && preferences->lv2_path[0] ) {
942 File::setenv_path("LV2_PATH",preferences->lv2_path, 0);
944 session = new MainSession(this);
945 session->load_defaults(defaults);
946 // set x11_host, screens, window_config
947 screens = session->set_default_x11_host();
948 BC_Signals::set_trap_hook(trap_hook, this);
949 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
950 BC_Signals::set_catch_intr(preferences->trap_sigintr);
951 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
952 BC_Trace::enable_locks();
955 BC_Trace::disable_locks();
957 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
958 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
959 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
960 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
963 void MWindow::clean_indexes()
968 int oldest_item = -1;
970 char string[BCTEXTLEN];
971 char string2[BCTEXTLEN];
973 // Delete extra indexes
974 fs.set_filter("*.idx");
975 fs.complete_path(preferences->index_directory);
976 fs.update(preferences->index_directory);
977 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
979 // Eliminate directories
984 for(int i = 0; i < fs.dir_list.total && !result; i++)
986 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
987 if(fs.is_dir(string))
989 delete fs.dir_list[i];
990 fs.dir_list.remove_number(i);
995 total_excess = fs.dir_list.total - preferences->index_count;
997 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
998 while(total_excess > 0)
1001 for(int i = 0; i < fs.dir_list.total; i++)
1003 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1005 if(i == 0 || fs.get_date(string) <= oldest)
1007 oldest = fs.get_date(string);
1012 if(oldest_item >= 0)
1014 // Remove index file
1015 fs.join_names(string,
1016 preferences->index_directory,
1017 fs.dir_list[oldest_item]->name);
1018 //printf("MWindow::clean_indexes 1 %s\n", string);
1020 perror("delete_indexes");
1021 delete fs.dir_list[oldest_item];
1022 fs.dir_list.remove_number(oldest_item);
1024 // Remove table of contents if it exists
1025 strcpy(string2, string);
1026 char *ptr = strrchr(string2, '.');
1029 //printf("MWindow::clean_indexes 2 %s\n", string2);
1030 sprintf(ptr, ".toc");
1032 sprintf(ptr, ".mkr");
1041 void MWindow::init_awindow()
1043 awindow = new AWindow(this);
1044 awindow->create_objects();
1047 void MWindow::init_gwindow()
1049 gwindow = new GWindow(this);
1050 gwindow->create_objects();
1053 void MWindow::init_tipwindow()
1055 TipWindow::load_tips(cin_lang);
1057 twindow = new TipWindow(this);
1061 void MWindow::show_warning(int *do_warning, const char *text)
1063 if( do_warning && !*do_warning ) return;
1065 wwindow = new WWindow(this);
1066 wwindow->show_warning(do_warning, text);
1069 int MWindow::wait_warning()
1071 return wwindow->wait_result();
1074 void MWindow::init_theme()
1079 PluginServer *theme_plugin = 0;
1080 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1081 if( plugindb->get(i)->theme &&
1082 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1083 theme_plugin = plugindb->get(i);
1087 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1088 preferences->theme);
1090 const char *default_theme = DEFAULT_THEME;
1091 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1092 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1094 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1095 if( plugindb->get(i)->theme &&
1096 !strcasecmp(default_theme, plugindb->get(i)->title) )
1097 theme_plugin = plugindb->get(i);
1102 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1106 PluginServer *plugin = new PluginServer(*theme_plugin);
1107 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1108 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1109 theme_plugin->title);
1113 theme = plugin->new_theme();
1114 theme->mwindow = this;
1115 strcpy(theme->path, plugin->path);
1118 // Load default images & settings
1119 theme->Theme::initialize();
1120 // Load user images & settings
1121 theme->initialize();
1122 // Create menus with user colors
1123 theme->build_menus();
1126 theme->sort_image_sets();
1127 theme->check_used();
1128 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1131 void MWindow::init_3d()
1133 playback_3d = new Playback3D(this);
1134 playback_3d->create_objects();
1137 void MWindow::init_edl()
1140 edl->create_objects();
1141 fill_preset_defaults(default_standard, edl->session);
1142 edl->load_defaults(defaults);
1143 edl->session->brender_start = edl->session->brender_end = 0;
1144 edl->create_default_tracks();
1145 edl->tracks->update_y_pixels(theme);
1148 void MWindow::init_compositor()
1150 cwindow = new CWindow(this);
1151 cwindow->create_objects();
1154 void MWindow::init_levelwindow()
1156 lwindow = new LevelWindow(this);
1157 lwindow->create_objects();
1160 VWindow *MWindow::get_viewer(int start_it, int idx)
1162 vwindows_lock->lock("MWindow::get_viewer");
1163 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1164 if( !vwindow ) idx = vwindows.size();
1165 while( !vwindow && --idx >= 0 ) {
1166 VWindow *vwin = vwindows[idx];
1167 if( !vwin->is_running() || !vwin->get_edl() )
1171 vwindow = new VWindow(this);
1172 vwindow->load_defaults();
1173 vwindow->create_objects();
1174 vwindows.append(vwindow);
1176 vwindows_lock->unlock();
1177 if( start_it ) vwindow->start();
1181 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1183 zwindows_lock->lock("MWindow::get_mixer");
1184 if( !mixer ) mixer = edl->mixers.new_mixer();
1185 ZWindow *zwindow = 0;
1186 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1187 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1189 zwindows.append(zwindow = new ZWindow(this));
1190 zwindow->idx = mixer->idx;
1191 zwindows_lock->unlock();
1195 void MWindow::del_mixer(ZWindow *zwindow)
1197 zwindows_lock->lock("MWindow::del_mixer 0");
1198 edl->mixers.del_mixer(zwindow->idx);
1199 if( session->selected_zwindow >= 0 ) {
1200 int i = zwindows.number_of(zwindow);
1201 if( i >= 0 && i < session->selected_zwindow )
1202 --session->selected_zwindow;
1203 else if( i == session->selected_zwindow )
1204 session->selected_zwindow = -1;
1206 zwindows_lock->unlock();
1207 gui->lock_window("MWindow::del_mixer 1");
1208 gui->update_mixers(0, -1);
1209 gui->unlock_window();
1212 void MWindow::start_mixer()
1215 ZWindow *zwindow = get_mixer(mixer);
1216 const char *title = 0;
1218 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1219 PatchGUI *patchgui = get_patchgui(track);
1220 if( !patchgui || !patchgui->mixer ) continue;
1221 mixer->mixer_ids.append(track->get_mixer_id());
1222 if( !title ) title = track->title;
1225 session->selected_zwindow = -1;
1226 gui->lock_window("MWindow::start_mixer");
1227 gui->update_mixers(0, 0);
1228 gui->unlock_window();
1230 zwindow->set_title(title);
1235 int MWindow::mixer_track_active(Track *track)
1237 int i = session->selected_zwindow;
1238 if( i < 0 || i >= zwindows.size() ) return 0;
1239 ZWindow *zwindow = zwindows[i];
1240 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1241 if( !mixer ) return 0;
1242 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1243 return n >= 0 ? 1 : 0;
1246 void MWindow::update_mixer_tracks()
1248 zwindows_lock->lock("MixPatch::handle_event");
1249 int i = session->selected_zwindow;
1250 if( i >= 0 && i < zwindows.size() ) {
1251 ZWindow *zwindow = zwindows[i];
1252 zwindow->update_mixer_ids();
1254 zwindows_lock->unlock();
1257 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1258 int use_inout, int update_refresh, int toggle_audio, int loop_play)
1260 zwindows_lock->lock("MWindow::queue_mixers");
1261 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1262 ZWindow *zwindow = zwindows[vidx];
1263 if( zwindow->idx < 0 ) continue;
1264 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1265 if( !mixer || !mixer->mixer_ids.size() ) continue;
1267 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1268 if( track->data_type != TRACK_VIDEO ) continue;
1269 int mixer_id = track->get_mixer_id();
1270 k = mixer->mixer_ids.size();
1271 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1273 if( k < 0 ) continue;
1274 EDL *mixer_edl = new EDL(this->edl);
1275 mixer_edl->create_objects();
1276 mixer_edl->copy_all(edl);
1277 mixer_edl->remove_vwindow_edls();
1278 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1279 k = mixer->mixer_ids.size();
1280 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1283 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1286 track->record = track->play = 0;
1288 zwindow->change_source(mixer_edl);
1289 zwindow->issue_command(command,
1290 wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
1292 zwindows_lock->unlock();
1295 void MWindow::refresh_mixers(int dir)
1297 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1298 queue_mixers(edl,command,0,0,1,0,0);
1301 void MWindow::stop_mixers()
1303 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1304 ZWindow *zwindow = zwindows[vidx];
1305 if( zwindow->idx < 0 ) continue;
1306 zwindow->issue_command(STOP, 0, 0, 0, 0, 0);
1310 void MWindow::close_mixers(int destroy)
1312 ArrayList<ZWindow*> closed;
1313 zwindows_lock->lock("MWindow::close_mixers");
1314 for( int i=zwindows.size(); --i>=0; ) {
1315 ZWindow *zwindow = zwindows[i];
1316 if( zwindow->idx < 0 ) continue;
1317 zwindow->destroy = destroy;
1318 ZWindowGUI *zgui = zwindow->zgui;
1319 zgui->lock_window("MWindow::select_zwindow 0");
1321 zgui->unlock_window();
1322 closed.append(zwindow);
1324 zwindows_lock->unlock();
1325 for( int i=0; i<closed.size(); ++i ) {
1326 ZWindow *zwindow = closed[i];
1331 ZWindow *MWindow::create_mixer(Indexable *indexable)
1333 ArrayList<Indexable*> new_assets;
1334 new_assets.append(indexable);
1335 Track *track = edl->tracks->last;
1336 load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
1337 track = !track ? edl->tracks->first : track->next;
1339 ZWindow *zwindow = get_mixer(mixer);
1341 track->play = track->record = 0;
1342 if( track->data_type == TRACK_VIDEO ) {
1343 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1345 mixer->mixer_ids.append(track->get_mixer_id());
1346 track = track->next;
1348 if( indexable->is_asset ) {
1349 char *path = indexable->path;
1350 char *tp = strrchr(path, '/');
1351 if( !tp ) tp = path; else ++tp;
1352 zwindow->set_title(tp);
1355 char *title = ((EDL*)indexable)->local_session->clip_title;
1356 zwindow->set_title(title);
1361 void MWindow::create_mixers()
1363 if( !session->drag_assets->size() &&
1364 !session->drag_clips->size() ) return;
1365 undo->update_undo_before();
1368 ArrayList<ZWindow *>new_mixers;
1370 for( int i=0; i<session->drag_assets->size(); ++i ) {
1371 Indexable *indexable = session->drag_assets->get(i);
1372 if( !indexable->have_video() ) continue;
1373 ZWindow *zwindow = create_mixer(indexable);
1374 new_mixers.append(zwindow);
1376 for( int i=0; i<session->drag_clips->size(); ++i ) {
1377 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1378 if( !indexable->have_video() ) continue;
1379 ZWindow *zwindow = create_mixer(indexable);
1380 new_mixers.append(zwindow);
1384 for( int i=0; i<new_mixers.size(); ++i )
1385 new_mixers[i]->start();
1389 undo->update_undo_after(_("create mixers"), LOAD_ALL);
1391 gui->update(1, 2, 1, 1, 1, 1, 0);
1392 sync_parameters(CHANGE_ALL);
1395 void MWindow::open_mixers()
1397 for( int i=0; i<edl->mixers.size(); ++i ) {
1398 Mixer *mixer = edl->mixers[i];
1399 ZWindow *zwindow = get_mixer(mixer);
1400 zwindow->set_title(mixer->title);
1406 int MWindow::select_zwindow(ZWindow *zwindow)
1408 int ret = 0, n = zwindows.number_of(zwindow);
1409 if( session->selected_zwindow != n ) {
1410 session->selected_zwindow = n;
1411 for( int i=0; i<zwindows.size(); ++i ) {
1412 ZWindow *zwindow = zwindows[i];
1413 if( zwindow->idx < 0 ) continue;
1414 ZWindowGUI *zgui = zwindow->zgui;
1415 zgui->lock_window("MWindow::select_zwindow 0");
1416 zwindow->highlighted = i == n ? 1 : 0;
1417 if( zgui->draw_overlays() )
1418 zgui->canvas->get_canvas()->flash(1);
1419 zgui->unlock_window();
1422 gui->lock_window("MWindow::select_window 1");
1423 gui->update_mixers(0, -1);
1424 gui->unlock_window();
1429 void MWindow::tile_mixers()
1432 for( int i=0; i<zwindows.size(); ++i ) {
1433 ZWindow *zwindow = zwindows[i];
1434 if( zwindow->idx < 0 ) continue;
1438 int zn = ceil(sqrt(nz));
1439 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1440 int y1 = 1, y2 = gui->get_y();
1441 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1442 if( x1 < 0 ) x1 = 0;
1443 if( y1 < 0 ) y1 = 0;
1444 if( x2 > rw ) x2 = rw;
1445 if( y2 > rh ) y2 = rh;
1446 int dx = x2 - x1, dy = y2 - y1;
1448 int lt = BC_DisplayInfo::get_left_border();
1449 int top = BC_DisplayInfo::get_top_border();
1450 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1451 int bh = top + BC_DisplayInfo::get_bottom_border();
1452 int zx = 0, zy = 0; // window origins
1453 int mw = 10+10, mh = 10+10; // canvas margins
1454 int rsz = 0, n = 0, dz = 0;
1455 int ow = edl->session->output_w, oh = edl->session->output_h;
1456 for( int i=0; i<zwindows.size(); ++i ) {
1457 ZWindow *zwindow = zwindows[i];
1458 if( zwindow->idx < 0 ) continue;
1459 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1460 if( rsz < hh ) rsz = hh;
1461 int xx = zx + x1, yy = zy + y1;
1462 int mx = x2 - zw, my = y2 - zh;
1463 if( xx > mx ) xx = mx;
1464 if( yy > my ) yy = my;
1465 xx += lt + dz; yy += top + dz;
1466 zwindow->reposition(xx,yy, ww,hh);
1467 if( zwindow->running() ) {
1468 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1469 gui->lock_window("MWindow::tile_mixers");
1470 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1471 gui->unlock_window();
1475 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1484 void MWindow::init_cache()
1486 audio_cache = new CICache(preferences);
1487 video_cache = new CICache(preferences);
1488 frame_cache = new FrameCache;
1489 wave_cache = new WaveCache;
1492 void MWindow::init_channeldb()
1494 channeldb_buz->load("channeldb_buz");
1495 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1498 void MWindow::init_menus()
1500 char string[BCTEXTLEN];
1503 BC_CModels::to_text(string, BC_RGB888);
1504 colormodels.append(new ColormodelItem(string, BC_RGB888));
1505 BC_CModels::to_text(string, BC_RGBA8888);
1506 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1507 // BC_CModels::to_text(string, BC_RGB161616);
1508 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1509 // BC_CModels::to_text(string, BC_RGBA16161616);
1510 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1511 BC_CModels::to_text(string, BC_RGB_FLOAT);
1512 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1513 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1514 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1515 BC_CModels::to_text(string, BC_YUV888);
1516 colormodels.append(new ColormodelItem(string, BC_YUV888));
1517 BC_CModels::to_text(string, BC_YUVA8888);
1518 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1519 // BC_CModels::to_text(string, BC_YUV161616);
1520 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1521 // BC_CModels::to_text(string, BC_YUVA16161616);
1522 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1524 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1525 interlace_project_modes.append(new InterlacemodeItem(string, x));
1527 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1528 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1530 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1531 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1533 // Interlacing Modes
1534 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1536 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1537 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1539 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1540 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1542 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1543 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1545 // Interlacing Fixing Methods
1546 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1547 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1548 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1551 void MWindow::init_indexes()
1553 mainindexes = new MainIndexes(this);
1554 mainindexes->start_loop();
1557 void MWindow::init_gui()
1559 gui = new MWindowGUI(this);
1560 gui->create_objects();
1561 gui->load_defaults(defaults);
1564 void MWindow::init_signals()
1566 sighandler = new SigHandler;
1567 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1571 void MWindow::init_render()
1573 render = new Render(this);
1574 create_bd = new CreateBD_Thread(this);
1575 create_dvd = new CreateDVD_Thread(this);
1576 batch_render = new BatchRenderThread(this);
1579 void MWindow::init_exportedl()
1581 exportedl = new ExportEDL(this);
1584 void MWindow::init_brender()
1586 if(preferences->use_brender && !brender)
1588 brender_lock->lock("MWindow::init_brender 1");
1589 brender = new BRender(this);
1590 brender->initialize();
1591 session->brender_end = 0;
1592 brender_lock->unlock();
1595 if(!preferences->use_brender && brender)
1597 brender_lock->lock("MWindow::init_brender 2");
1600 session->brender_end = 0;
1601 brender_lock->unlock();
1607 void MWindow::restart_brender()
1609 //printf("MWindow::restart_brender 1\n");
1610 if( !brender_active || !preferences->use_brender ) return;
1611 if( !brender ) return;
1612 brender->restart(edl);
1615 void MWindow::stop_brender()
1617 if( !brender ) return;
1618 // cannot be holding mwindow->gui display lock
1622 int MWindow::brender_available(int position)
1625 brender_lock->lock("MWindow::brender_available 1");
1626 if(brender && brender_active)
1628 if(brender->map_valid)
1630 brender->map_lock->lock("MWindow::brender_available 2");
1631 if(position < brender->map_size &&
1634 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1635 if(brender->map[position] == BRender::RENDERED)
1638 brender->map_lock->unlock();
1641 brender_lock->unlock();
1645 void MWindow::set_brender_active(int v, int update)
1647 if( !preferences->use_brender ) v = 0;
1649 gui->mainmenu->brender_active->set_checked(v);
1651 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1652 edl->session->brender_end = edl->local_session->get_selectionend(1);
1654 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1655 edl->session->brender_end = edl->tracks->total_video_length();
1660 edl->session->brender_start = edl->session->brender_end = 0;
1661 gui->unlock_window();
1663 gui->lock_window("MWindow::set_brender_active");
1666 gui->update_timebar(0);
1667 gui->draw_overlays(1);
1671 int MWindow::has_commercials()
1673 #ifdef HAVE_COMMERCIAL
1674 return theme->use_commercials;
1680 void MWindow::init_commercials()
1682 #ifdef HAVE_COMMERCIAL
1683 if( !commercials ) {
1684 commercials = new Commercials(this);
1685 commercial_active = 0;
1688 commercials->add_user();
1692 void MWindow::commit_commercial()
1694 #ifdef HAVE_COMMERCIAL
1695 if( !commercial_active ) return;
1696 commercial_active = 0;
1697 if( !commercials ) return;
1698 commercials->commitDb();
1702 void MWindow::undo_commercial()
1704 #ifdef HAVE_COMMERCIAL
1705 if( !commercial_active ) return;
1706 commercial_active = 0;
1707 if( !commercials ) return;
1708 commercials->undoDb();
1712 int MWindow::put_commercial()
1715 #ifdef HAVE_COMMERCIAL
1716 double start = edl->local_session->get_selectionstart();
1717 double end = edl->local_session->get_selectionend();
1718 if( start >= end ) return 0;
1720 const char *errmsg = 0;
1722 Tracks *tracks = edl->tracks;
1724 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1725 if( track->data_type != TRACK_VIDEO ) continue;
1726 if( !track->record ) continue;
1727 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1729 int64_t units_start = track->to_units(start,0);
1730 int64_t units_end = track->to_units(end,0);
1731 Edits *edits = track->edits;
1732 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1733 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1734 if(!edit1 && !edit2) continue; // nothing selected
1735 if(!edit2) { // edit2 beyond end of track
1736 edit2 = edits->last;
1737 units_end = edits->length();
1739 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1740 Indexable *indexable = edit1->get_source();
1741 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1744 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1745 if( track->data_type != TRACK_VIDEO ) continue;
1746 if( !track->record ) continue;
1747 int64_t units_start = track->to_units(start,0);
1748 int64_t units_end = track->to_units(end,0);
1749 Edits *edits = track->edits;
1750 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1751 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1752 if(!edit1 && !edit2) continue; // nothing selected
1753 if(!edit2) { // edit2 beyond end of track
1754 edit2 = edits->last;
1755 units_end = edits->length();
1757 Indexable *indexable = edit1->get_source();
1758 Asset *asset = (Asset *)indexable;
1759 File *file = video_cache->check_out(asset, edl);
1760 if( !file ) { errmsg = _("no file"); break; }
1761 int64_t edit_length = units_end - units_start;
1762 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1763 result = commercials->put_clip(file, edit1->channel,
1764 track->from_units(edit_start), track->from_units(edit_length));
1765 video_cache->check_in(asset);
1766 if( result ) { errmsg = _("db failed"); break; }
1769 char string[BCTEXTLEN];
1770 sprintf(string, _("put_commercial: %s"), errmsg);
1771 MainError::show_error(string);
1779 void MWindow::stop_playback(int wait)
1781 gui->stop_drawing();
1783 cwindow->stop_playback(wait);
1785 for(int i = 0; i < vwindows.size(); i++) {
1786 VWindow *vwindow = vwindows[i];
1787 if( !vwindow->is_running() ) continue;
1788 vwindow->stop_playback(wait);
1790 for(int i = 0; i < zwindows.size(); i++) {
1791 ZWindow *zwindow = zwindows[i];
1792 if( zwindow->idx < 0 ) continue;
1793 zwindow->stop_playback(wait);
1797 void MWindow::stop_transport()
1799 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1802 void MWindow::beep(double freq, double secs, double gain)
1804 if( !proxy_beep ) proxy_beep = new ProxyBeep(this);
1805 proxy_beep->tone(freq, secs, gain);
1808 int MWindow::load_filenames(ArrayList<char*> *filenames,
1810 int update_filename)
1812 ArrayList<EDL*> new_edls;
1813 ArrayList<Asset*> new_assets;
1814 ArrayList<File*> new_files;
1815 const int debug = 0;
1816 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1819 gui->start_hourglass();
1821 // Need to stop playback since tracking depends on the EDL not getting
1823 gui->unlock_window();
1825 gui->lock_window("MWindow::load_filenames 0");
1827 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1828 undo->update_undo_before();
1831 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1833 // Define new_edls and new_assets to load
1834 int result = 0, ftype = -1;
1836 for( int i=0; i<filenames->size(); ++i ) {
1838 File *new_file = new File;
1839 Asset *new_asset = new Asset(filenames->get(i));
1840 EDL *new_edl = new EDL;
1841 char string[BCTEXTLEN];
1843 new_edl->create_objects();
1844 new_edl->copy_session(edl, -1);
1845 new_file->set_program(edl->session->program_no);
1847 sprintf(string, _("Loading %s"), new_asset->path);
1848 gui->show_message(string);
1849 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1851 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1852 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1856 // Convert media file to EDL
1858 // Warn about odd image dimensions
1859 if( new_asset->video_data &&
1860 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1861 char string[BCTEXTLEN];
1862 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1863 new_asset->path, new_asset->width, new_asset->height);
1864 MainError::show_error(string);
1867 if( new_asset->program >= 0 &&
1868 edl->session->program_no != new_asset->program ) {
1869 char string[BCTEXTLEN];
1870 sprintf(string, _("%s's index was built for program number %d\n"
1871 "Playback preference is %d.\n Using program %d."),
1872 new_asset->path, new_asset->program,
1873 edl->session->program_no, new_asset->program);
1874 MainError::show_error(string);
1877 if( load_mode != LOADMODE_RESOURCESONLY ) {
1878 RecordLabels *labels = edl->session->label_cells ?
1879 new RecordLabels(new_file) : 0;
1880 asset_to_edl(new_edl, new_asset, labels);
1881 new_edls.append(new_edl);
1882 new_edl->add_user();
1886 new_assets.append(new_asset);
1887 new_asset->add_user();
1890 // Set filename to nothing for assets since save EDL would overwrite them.
1891 if( load_mode == LOADMODE_REPLACE ||
1892 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1894 // Reset timeline position
1895 for( int i=0; i<TOTAL_PANES; ++i ) {
1896 new_edl->local_session->view_start[i] = 0;
1897 new_edl->local_session->track_start[i] = 0;
1905 case FILE_NOT_FOUND:
1906 sprintf(string, _("Failed to open %s"), new_asset->path);
1907 gui->show_message(string, theme->message_error);
1908 gui->update_default_message();
1912 case FILE_UNRECOGNIZED_CODEC: {
1914 { IndexFile indexfile(this, new_asset);
1915 if( !(result = indexfile.open_index()) )
1916 indexfile.close_index(); }
1918 // Test existing EDLs
1919 for( int j=0; result && j<new_edls.total; ++j ) {
1920 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1922 new_asset->copy_from(old_asset,1);
1927 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1929 new_asset->copy_from(old_asset,1);
1936 char string[BCTEXTLEN];
1938 fs.extract_name(string, new_asset->path);
1940 strcat(string, _("'s format couldn't be determined."));
1941 new_asset->audio_data = 1;
1942 new_asset->format = FILE_PCM;
1943 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1944 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1945 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1946 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1947 new_asset->signed_ = defaults->get("SIGNED_", 1);
1948 new_asset->header = defaults->get("HEADER", 0);
1950 FileFormat fwindow(this);
1951 fwindow.create_objects(new_asset, string);
1952 result = fwindow.run_window();
1954 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1955 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1956 defaults->update("AUDIO_BITS", new_asset->bits);
1957 defaults->update("BYTE_ORDER", new_asset->byte_order);
1958 defaults->update("SIGNED_", new_asset->signed_);
1959 defaults->update("HEADER", new_asset->header);
1965 // Recalculate length
1967 new_file = new File;
1968 result = new_file->open_file(preferences, new_asset, 1, 0);
1970 if( load_mode != LOADMODE_RESOURCESONLY ) {
1971 RecordLabels *labels = edl->session->label_cells ?
1972 new RecordLabels(new_file) : 0;
1973 asset_to_edl(new_edl, new_asset, labels);
1974 new_edls.append(new_edl);
1975 new_edl->add_user();
1979 new_assets.append(new_asset);
1980 new_asset->add_user();
1990 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1991 xml_file.read_from_file(filenames->get(i));
1992 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1993 const char *cin_version = 0;
1994 while( !xml_file.read_tag() ) {
1995 if( xml_file.tag.title_is("EDL") ) {
1996 cin_version = xml_file.tag.get_property("VERSION");
2001 if( !cin_version ) {
2002 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
2003 char string[BCTEXTLEN];
2004 sprintf(string,_("Unknown %s"), filenames->get(i));
2005 gui->show_message(string);
2009 if( strcmp(cin_version, CINELERRA_VERSION) &&
2010 strcmp(cin_version, "Unify") &&
2011 strcmp(cin_version, "5.1") ) {
2012 char string[BCTEXTLEN];
2013 snprintf(string, sizeof(string),
2014 _("Warning: XML from cinelerra version %s\n"
2015 "Session data may be incompatible."), cin_version);
2016 show_warning(&preferences->warn_version, string);
2018 if( load_mode == LOADMODE_NESTED ) {
2019 // Load temporary EDL for nesting.
2020 EDL *nested_edl = new EDL;
2021 nested_edl->create_objects();
2022 nested_edl->load_xml(&xml_file, LOAD_ALL);
2023 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
2024 new_edl->create_nested(nested_edl);
2025 new_edl->set_path(filenames->get(i));
2026 nested_edl->Garbage::remove_user();
2029 // Load EDL for pasting
2030 new_edl->load_xml(&xml_file, LOAD_ALL);
2031 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2032 test_plugins(new_edl, filenames->get(i));
2033 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2035 if( load_mode == LOADMODE_REPLACE ||
2036 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2037 strcpy(session->filename, filenames->get(i));
2038 strcpy(new_edl->local_session->clip_title,
2041 set_filename(new_edl->local_session->clip_title);
2043 else if( load_mode == LOADMODE_RESOURCESONLY ) {
2044 strcpy(new_edl->local_session->clip_title,
2047 time_t t = !stat(filenames->get(i),&st) ?
2048 st.st_mtime : time(&t);
2049 ctime_r(&t, new_edl->local_session->clip_notes);
2053 new_edls.append(new_edl);
2054 new_edl->add_user();
2059 new_edl->Garbage::remove_user();
2060 new_asset->Garbage::remove_user();
2062 // Store for testing index
2063 new_files.append(new_file);
2066 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2070 gui->reset_default_message();
2071 gui->default_message();
2075 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2078 // Don't back up here.
2081 // For pasting, clear the active region
2082 if(load_mode == LOADMODE_PASTE ||
2083 load_mode == LOADMODE_NESTED)
2085 double start = edl->local_session->get_selectionstart();
2086 double end = edl->local_session->get_selectionend();
2087 if(!EQUIV(start, end))
2090 edl->session->labels_follow_edits,
2091 edl->session->plugins_follow_edits,
2092 edl->session->autos_follow_edits);
2095 paste_edls(&new_edls, load_mode, 0, -1,
2096 edl->session->labels_follow_edits,
2097 edl->session->plugins_follow_edits,
2098 edl->session->autos_follow_edits,
2105 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2107 // Add new assets to EDL and schedule assets for index building.
2108 int got_indexes = 0;
2109 for( int i=0; i<new_edls.size(); ++i ) {
2110 EDL *new_edl = new_edls[i];
2111 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2112 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2113 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2119 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2120 for( int i=0; i<new_assets.size(); ++i ) {
2121 Asset *new_asset = new_assets[i];
2125 for( int j=0; j<new_files.size(); ++j ) {
2126 new_file = new_files[j];
2127 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2133 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2134 edl->assets->update(new_asset);
2137 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2139 // Start examining next batch of index files
2140 if(got_indexes) mainindexes->start_build();
2141 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2144 Track *track = edl->tracks->first;
2147 for(int j = 0; j < track->plugin_set.size(); j++)
2149 PluginSet *plugins = track->plugin_set[j];
2150 Plugin *plugin = plugins->get_first_plugin();
2154 if(load_mode == LOADMODE_REPLACE ||
2155 load_mode == LOADMODE_REPLACE_CONCATENATE)
2157 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2160 show_plugin(plugin);
2164 plugin = (Plugin*)plugin->next;
2168 track = track->next;
2171 // if just opening one new resource in replace mode
2172 if( ftype != FILE_IS_XML &&
2173 ( load_mode == LOADMODE_REPLACE ||
2174 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2176 edl->session->proxy_scale = 1;
2177 edl->session->proxy_disabled_scale = 1;
2178 edl->session->proxy_use_scaler = 0;
2179 edl->session->proxy_auto_scale = 0;
2180 edl->session->proxy_beep = 0;
2181 edl->local_session->preview_start = 0;
2182 edl->local_session->preview_end = -1;
2183 edl->local_session->loop_playback = 0;
2184 edl->local_session->set_selectionstart(0);
2185 edl->local_session->set_selectionend(0);
2186 set_brender_active(0, 0);
2191 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2192 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2193 ArrayList<Indexable *> orig_idxbls;
2194 for( int i=0; i<new_assets.size(); ++i )
2195 orig_idxbls.append(new_assets.get(i));
2196 for( int i=0; i<new_edls.size(); ++i ) {
2197 EDL *new_edl = new_edls[i];
2198 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2199 if( track->data_type != TRACK_VIDEO ) continue;
2200 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2201 Indexable *idxbl = (Indexable *)edit->asset;
2202 if( !idxbl ) continue;
2203 if( !idxbl->have_video() ) continue;
2204 if( edit->channel != 0 ) continue; // first layer only
2205 orig_idxbls.append(edit->asset);
2209 gui->unlock_window(); // to update progress bar
2210 int ret = render_proxy(orig_idxbls);
2211 gui->lock_window("MWindow::load_filenames");
2212 if( ret >= 0 && edl->session->proxy_beep ) {
2214 beep(2000., 1.5, 0.5);
2216 beep(4000., 0.25, 0.5);
2220 // need to update undo before project, since mwindow is unlocked & a new load
2221 // can begin here. Should really prevent loading until we're done.
2222 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2223 undo->update_undo_after(_("load"), LOAD_ALL);
2225 for(int i = 0; i < new_edls.size(); i++)
2227 new_edls[i]->remove_user();
2229 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2231 new_edls.remove_all();
2233 for(int i = 0; i < new_assets.size(); i++)
2235 new_assets[i]->Garbage::remove_user();
2238 new_assets.remove_all();
2239 new_files.remove_all_objects();
2242 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2243 if(load_mode == LOADMODE_REPLACE ||
2244 load_mode == LOADMODE_REPLACE_CONCATENATE)
2246 session->changes_made = 0;
2250 session->changes_made = 1;
2253 gui->stop_hourglass();
2256 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2257 update_project(load_mode);
2259 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2264 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2266 Asset *format_asset = new Asset;
2267 format_asset->format = FILE_FFMPEG;
2268 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2269 ProxyRender proxy_render(this, format_asset);
2270 int new_scale = edl->session->proxy_scale;
2271 int use_scaler = edl->session->proxy_use_scaler;
2273 for( int i=0; i<new_idxbls.size(); ++i ) {
2274 Indexable *orig = new_idxbls.get(i);
2275 Asset *proxy = proxy_render.add_original(orig, new_scale);
2276 if( !proxy ) continue;
2278 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2279 int got_it = exists && // if proxy exists, and is newer than orig
2280 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2281 if( got_it ) continue;
2282 proxy_render.add_needed(orig, proxy);
2285 // render needed proxies
2286 int result = proxy_render.create_needed_proxies(new_scale);
2288 add_proxy(use_scaler,
2289 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2291 format_asset->remove_user();
2292 return !result ? proxy_render.needed_proxies.size() : -1;
2295 int MWindow::enable_proxy()
2298 if( edl->session->proxy_scale == 1 &&
2299 edl->session->proxy_disabled_scale != 1 ) {
2300 int new_scale = edl->session->proxy_disabled_scale;
2301 int new_use_scaler = edl->session->proxy_use_scaler;
2302 edl->session->proxy_disabled_scale = 1;
2303 Asset *asset = new Asset;
2304 asset->format = FILE_FFMPEG;
2305 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2306 ret = to_proxy(asset, new_scale, new_use_scaler);
2307 asset->remove_user();
2309 beep(2000., 1.5, 0.5);
2314 int MWindow::disable_proxy()
2316 if( edl->session->proxy_scale != 1 &&
2317 edl->session->proxy_disabled_scale == 1 ) {
2319 int new_use_scaler = edl->session->proxy_use_scaler;
2320 edl->session->proxy_disabled_scale = edl->session->proxy_scale;
2321 Asset *asset = new Asset;
2322 asset->format = FILE_FFMPEG;
2323 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2324 to_proxy(asset, new_scale, new_use_scaler);
2325 asset->remove_user();
2330 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2332 ArrayList<Indexable*> orig_idxbls;
2333 ArrayList<Indexable*> proxy_assets;
2335 edl->Garbage::add_user();
2337 undo->update_undo_before(_("proxy"), this);
2338 ProxyRender proxy_render(this, asset);
2340 // revert project to original size from current size
2341 // remove all session proxy assets at the at the current proxy_scale
2342 int proxy_scale = edl->session->proxy_scale;
2344 if( proxy_scale > 1 ) {
2345 Asset *orig_asset = edl->assets->first;
2346 for( ; orig_asset; orig_asset=orig_asset->next ) {
2347 char new_path[BCTEXTLEN];
2348 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2349 // test if proxy asset was already added to proxy_assets
2351 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2352 got_it = !strcmp(proxy_assets[i]->path, new_path);
2353 if( got_it ) continue;
2354 Asset *proxy_asset = edl->assets->get_asset(new_path);
2355 if( !proxy_asset ) continue;
2356 // add pointer to existing EDL asset if it exists
2357 // EDL won't delete it unless it's the same pointer.
2358 proxy_assets.append(proxy_asset);
2359 proxy_asset->add_user();
2360 orig_idxbls.append(orig_asset);
2361 orig_asset->add_user();
2363 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2364 EDL *orig_nested = edl->nested_edls[i];
2365 char new_path[BCTEXTLEN];
2366 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2368 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2369 // test if proxy asset was already added to proxy_assets
2371 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2372 got_it = !strcmp(proxy_assets[i]->path, new_path);
2373 if( got_it ) continue;
2374 Asset *proxy_nested = edl->assets->get_asset(new_path);
2375 if( !proxy_nested ) continue;
2376 // add pointer to existing EDL asset if it exists
2377 // EDL won't delete it unless it's the same pointer.
2378 proxy_assets.append(proxy_nested);
2379 proxy_nested->add_user();
2380 orig_idxbls.append(orig_nested);
2381 orig_nested->add_user();
2384 // convert from the proxy assets to the original assets
2385 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2387 // remove the references
2388 for( int i=0; i<proxy_assets.size(); ++i ) {
2389 Asset *proxy = (Asset *) proxy_assets[i];
2390 proxy->width = proxy->actual_width;
2391 proxy->height = proxy->actual_height;
2392 proxy->remove_user();
2393 edl->assets->remove_pointer(proxy);
2394 proxy->remove_user();
2396 proxy_assets.remove_all();
2397 for( int i = 0; i < orig_idxbls.size(); i++ )
2398 orig_idxbls[i]->remove_user();
2399 orig_idxbls.remove_all();
2402 ArrayList<char *> confirm_paths; // test for new files
2403 confirm_paths.set_array_delete();
2405 // convert to new size if not original size
2406 if( new_scale != 1 ) {
2408 Asset *orig = edl->assets->first;
2409 for( ; orig; orig=orig->next ) {
2410 Asset *proxy = proxy_render.add_original(orig, new_scale);
2411 if( !proxy ) continue;
2412 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2413 int got_it = exists && // if proxy exists, and is newer than orig
2414 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2416 if( exists ) // prompt user to overwrite
2417 confirm_paths.append(cstrdup(proxy->path));
2418 proxy_render.add_needed(orig, proxy);
2421 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2422 EDL *orig_nested = edl->nested_edls[i];
2423 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2424 if( !proxy ) continue;
2425 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2426 int got_it = exists && // if proxy exists, and is newer than orig_nested
2427 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2429 if( exists ) // prompt user to overwrite
2430 confirm_paths.append(cstrdup(proxy->path));
2431 proxy_render.add_needed(orig_nested, proxy);
2437 // test for existing files
2438 if( confirm_paths.size() ) {
2439 result = ConfirmSave::test_files(this, &confirm_paths);
2440 confirm_paths.remove_all_objects();
2444 result = proxy_render.create_needed_proxies(new_scale);
2446 if( !result ) // resize project
2447 edl->set_proxy(new_scale, new_use_scaler,
2448 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2450 undo->update_undo_after(_("proxy"), LOAD_ALL);
2451 edl->Garbage::remove_user();
2454 gui->lock_window("MWindow::to_proxy");
2455 update_project(LOADMODE_REPLACE);
2456 gui->unlock_window();
2458 return !result ? proxy_render.needed_proxies.size() : -1;
2461 void MWindow::test_plugins(EDL *new_edl, char *path)
2463 char string[BCTEXTLEN];
2465 // Do a check whether plugins exist
2466 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2467 for( int k=0; k<track->plugin_set.total; ++k ) {
2468 PluginSet *plugin_set = track->plugin_set[k];
2469 for( Plugin *plugin = (Plugin*)plugin_set->first;
2470 plugin; plugin = (Plugin*)plugin->next ) {
2471 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2472 // ok we need to find it in plugindb
2473 PluginServer *server =
2474 scan_plugindb(plugin->title, track->data_type);
2475 if( !server || server->transition ) {
2477 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2478 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2479 "effect", _(plugin->title), path);
2480 MainError::show_error(string);
2485 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2486 if( !edit->transition ) continue;
2487 // ok we need to find transition in plugindb
2488 PluginServer *server =
2489 scan_plugindb(edit->transition->title, track->data_type);
2490 if( !server || !server->transition ) {
2492 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2493 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2494 "transition", _(edit->transition->title), path);
2495 MainError::show_error(string);
2502 void MWindow::init_shm(const char *pfn, int64_t min)
2505 // Fix shared memory
2506 FILE *fd = fopen(pfn, "r");
2508 fscanf(fd, "%jd", &result);
2510 if( result >= min ) return;
2513 fd = fopen(pfn, "w");
2515 fprintf(fd, "0x%jx", min);
2518 fd = fopen(pfn, "r");
2520 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2524 fscanf(fd, "%jd", &result);
2526 if( result < min ) {
2527 eprintf(_("MWindow::init_shm: %s is %p.\n"
2528 "you probably need to be root, or:\n"
2529 "as root, run: echo 0x%jx > %s\n"
2530 "before trying to start cinelerra.\n"
2531 "It should be at least 0x%jx for Cinelerra.\n"),
2532 pfn, (void *)result, min, pfn, min);
2536 void MWindow::create_objects(int want_gui,
2540 const int debug = 0;
2541 if(debug) PRINT_TRACE
2543 // For some reason, init_signals must come after show_splash or the signals won't
2546 if(debug) PRINT_TRACE
2549 if(debug) PRINT_TRACE
2552 if(debug) PRINT_TRACE
2553 default_standard = default_std();
2554 init_defaults(defaults, config_path);
2558 splash_window->update_status(_("Initializing Plugins"));
2559 init_plugins(this, preferences);
2560 if(debug) PRINT_TRACE
2561 init_ladspa_plugins(this, preferences);
2562 if(debug) PRINT_TRACE
2563 init_plugin_tips(*plugindb, cin_lang);
2565 splash_window->update_status(_("Initializing GUI"));
2566 if(debug) PRINT_TRACE
2569 if(debug) PRINT_TRACE
2573 splash_window->update_status(_("Initializing Fonts"));
2574 char string[BCTEXTLEN];
2575 strcpy(string, preferences->plugin_dir);
2576 strcat(string, "/" FONT_SEARCHPATH);
2577 BC_Resources::init_fontconfig(string);
2578 if(debug) PRINT_TRACE
2580 // Default project created here
2582 if(debug) PRINT_TRACE
2585 if(debug) PRINT_TRACE
2590 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2593 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2595 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2596 if(session->show_vwindow)
2597 get_viewer(1, DEFAULT_VWINDOW);
2598 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2601 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2604 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2607 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2610 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2613 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2616 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2621 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2622 mainprogress = new MainProgress(this, gui);
2623 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2624 undo = new MainUndo(this);
2626 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2628 plugin_guis = new ArrayList<PluginServer*>;
2629 dead_plugins = new ArrayList<PluginServer*>;
2630 keyframe_threads = new ArrayList<KeyFrameThread*>;
2632 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2635 session->show_vwindow);
2637 // Show all vwindows
2638 // if(session->show_vwindow) {
2639 // for(int j = 0; j < vwindows.size(); j++) {
2640 // VWindow *vwindow = vwindows[j];
2641 // if( !vwindow->is_running() ) continue;
2642 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2645 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2646 // vwindow->gui->lock_window("MWindow::create_objects 1");
2647 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2648 // vwindow->gui->show_window();
2649 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2650 // vwindow->gui->unlock_window();
2655 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2657 if(session->show_cwindow)
2659 cwindow->gui->lock_window("MWindow::create_objects 1");
2660 cwindow->gui->show_window();
2661 cwindow->gui->unlock_window();
2664 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2665 if(session->show_awindow)
2667 awindow->gui->lock_window("MWindow::create_objects 1");
2668 awindow->gui->show_window();
2669 awindow->gui->unlock_window();
2672 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2673 if(session->show_lwindow)
2675 lwindow->gui->lock_window("MWindow::create_objects 1");
2676 lwindow->gui->show_window();
2677 lwindow->gui->unlock_window();
2680 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2682 (int)timer.get_difference(),
2684 if(session->show_gwindow)
2686 gwindow->gui->lock_window("MWindow::create_objects 1");
2687 gwindow->gui->show_window();
2688 gwindow->gui->unlock_window();
2691 if(debug) PRINT_TRACE
2693 gui->lock_window("MWindow::create_objects 1");
2694 gui->mainmenu->load_defaults(defaults);
2695 gui->mainmenu->update_toggles(0);
2696 gui->update_patchbay();
2697 gui->draw_canvas(0, 0);
2698 gui->draw_cursor(1);
2700 gui->raise_window();
2701 gui->unlock_window();
2703 if(debug) PRINT_TRACE
2705 if(preferences->use_tipwindow)
2707 if(debug) PRINT_TRACE
2709 gui->add_keyboard_listener(
2710 (int (BC_WindowBase::*)(BC_WindowBase *))
2711 &MWindowGUI::keyboard_listener);
2714 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2715 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2716 if(debug) PRINT_TRACE
2718 BC_WindowBase::get_resources()->vframe_shm = 1;
2722 void MWindow::show_splash()
2724 #include "data/heroine_logo9_png.h"
2725 VFrame *frame = new VFramePng(heroine_logo9_png);
2726 BC_DisplayInfo dpyi;
2727 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2728 int rr = (rw < rh ? rw : rh) / 4;
2729 splash_window = new SplashGUI(frame, rr, rr);
2730 splash_window->create_objects();
2733 void MWindow::hide_splash()
2736 delete splash_window;
2741 void MWindow::start()
2745 // vwindows[DEFAULT_VWINDOW]->start();
2756 playback_3d->start();
2762 run_lock->lock("MWindow::run");
2766 brender_lock->lock("MWindow::run 1");
2767 delete brender; brender = 0;
2768 brender_lock->unlock();
2770 interrupt_indexes();
2776 void MWindow::show_vwindow()
2778 int total_running = 0;
2779 session->show_vwindow = 1;
2781 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2782 // Raise all windows which are visible
2783 for(int j = 0; j < vwindows.size(); j++) {
2784 VWindow *vwindow = vwindows[j];
2785 if( !vwindow->is_running() ) continue;
2786 vwindow->gui->lock_window("MWindow::show_vwindow");
2787 vwindow->gui->show_window(0);
2788 vwindow->gui->raise_window();
2789 vwindow->gui->flush();
2790 vwindow->gui->unlock_window();
2794 // If no windows visible
2797 get_viewer(1, DEFAULT_VWINDOW);
2800 gui->mainmenu->show_vwindow->set_checked(1);
2803 void MWindow::show_awindow()
2805 session->show_awindow = 1;
2806 awindow->gui->lock_window("MWindow::show_awindow");
2807 awindow->gui->show_window();
2808 awindow->gui->raise_window();
2809 awindow->gui->flush();
2810 awindow->gui->unlock_window();
2811 gui->mainmenu->show_awindow->set_checked(1);
2814 char *MWindow::get_cwindow_display()
2816 char *x11_host = screens < 2 || session->window_config == 0 ?
2817 session->a_x11_host : session->b_x11_host;
2818 return *x11_host ? x11_host : 0;
2821 void MWindow::show_cwindow()
2823 session->show_cwindow = 1;
2824 cwindow->show_window();
2825 gui->mainmenu->show_cwindow->set_checked(1);
2828 void MWindow::show_gwindow()
2830 session->show_gwindow = 1;
2832 gwindow->gui->lock_window("MWindow::show_gwindow");
2833 gwindow->gui->show_window();
2834 gwindow->gui->raise_window();
2835 gwindow->gui->flush();
2836 gwindow->gui->unlock_window();
2838 gui->mainmenu->show_gwindow->set_checked(1);
2840 void MWindow::hide_gwindow()
2842 session->show_gwindow = 0;
2844 gwindow->gui->lock_window("MWindow::show_gwindow");
2845 gwindow->gui->hide_window();
2846 gwindow->gui->unlock_window();
2849 void MWindow::show_lwindow()
2851 session->show_lwindow = 1;
2852 lwindow->gui->lock_window("MWindow::show_lwindow");
2853 lwindow->gui->show_window();
2854 lwindow->gui->raise_window();
2855 lwindow->gui->flush();
2856 lwindow->gui->unlock_window();
2857 gui->mainmenu->show_lwindow->set_checked(1);
2860 void MWindow::restore_windows()
2862 if( !session->show_vwindow ) {
2863 for( int i=0, n=vwindows.size(); i<n; ++i ) {
2864 VWindow *vwindow = vwindows[i];
2865 if( !vwindow || !vwindow->is_running() ) continue;
2866 vwindow->gui->lock_window("MWindow::restore_windows");
2867 vwindow->gui->close(1);
2868 vwindow->gui->unlock_window();
2874 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
2875 awindow->gui->lock_window("MWindow::restore_windows");
2876 awindow->gui->close_event();
2877 awindow->gui->unlock_window();
2879 else if( session->show_awindow && awindow->gui->is_hidden() )
2882 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
2883 cwindow->gui->lock_window("MWindow::restore_windows");
2884 cwindow->hide_window();
2885 cwindow->gui->unlock_window();
2887 else if( session->show_cwindow && cwindow->gui->is_hidden() )
2888 cwindow->show_window();
2890 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
2891 gwindow->gui->lock_window("MWindow::restore_windows");
2892 gwindow->gui->close_event();
2893 gwindow->gui->unlock_window();
2895 else if( session->show_gwindow && gwindow->gui->is_hidden() )
2898 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
2899 lwindow->gui->lock_window("MWindow::restore_windows");
2900 lwindow->gui->close_event();
2901 lwindow->gui->unlock_window();
2903 else if( session->show_lwindow && lwindow->gui->is_hidden() )
2909 void MWindow::save_layout(int no)
2911 char layout_path[BCTEXTLEN];
2912 snprintf(layout_path, sizeof(layout_path), "%s/" LAYOUT_FILE,
2913 File::get_config_path(), no);
2914 session->save_file(layout_path);
2917 void MWindow::load_layout(int no)
2919 char layout_path[BCTEXTLEN];
2920 snprintf(layout_path, sizeof(layout_path), "%s/" LAYOUT_FILE,
2921 File::get_config_path(), no);
2922 session->load_file(layout_path);
2924 gui->default_positions();
2928 int MWindow::tile_windows(int window_config)
2930 int need_reload = 0;
2931 int play_config = window_config==0 ? 0 : 1;
2932 edl->session->playback_config->load_defaults(defaults, play_config);
2933 session->default_window_positions(window_config);
2934 if( screens == 1 ) {
2935 gui->default_positions();
2936 sync_parameters(CHANGE_ALL);
2943 void MWindow::toggle_loop_playback()
2945 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2946 set_loop_boundaries();
2949 gui->draw_overlays(1);
2950 sync_parameters(CHANGE_PARAMS);
2953 void MWindow::set_screens(int value)
2958 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2960 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2961 edl->session->auto_keyframes = value;
2962 gui->mbuttons->edit_panel->keyframe->update(value);
2964 if(lock_mwindow) gui->unlock_window();
2966 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2967 cwindow->gui->edit_panel->keyframe->update(value);
2968 cwindow->gui->flush();
2969 if(lock_cwindow) cwindow->gui->unlock_window();
2972 void MWindow::set_auto_visibility(Autos *autos, int value)
2974 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2975 edl->session->auto_conf->plugins = value;
2976 else if( autos->autoidx >= 0 )
2977 edl->session->auto_conf->autos[autos->autoidx] = value;
2981 gui->update(0, 1, 0, 0, 0, 0, 0);
2982 gui->mainmenu->update_toggles(1);
2983 gui->unlock_window();
2984 gwindow->gui->update_toggles(1);
2985 gui->lock_window("MWindow::set_auto_visibility");
2988 void MWindow::set_keyframe_type(int mode)
2990 gui->lock_window("MWindow::set_keyframe_type");
2991 edl->local_session->floatauto_type = mode;
2992 gui->mainmenu->update_toggles(0);
2993 gui->unlock_window();
2996 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2998 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2999 edl->session->editing_mode = new_editing_mode;
3000 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3001 gui->mbuttons->edit_panel->update();
3002 gui->set_editing_mode(1);
3003 if(lock_mwindow) gui->unlock_window();
3006 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
3007 cwindow->gui->edit_panel->update();
3008 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3009 if(lock_cwindow) cwindow->gui->unlock_window();
3013 void MWindow::toggle_editing_mode()
3015 int mode = edl->session->editing_mode;
3016 if( mode == EDITING_ARROW )
3017 set_editing_mode(EDITING_IBEAM, 0, 1);
3019 set_editing_mode(EDITING_ARROW, 0, 1);
3022 void MWindow::toggle_camera_xyz()
3024 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3025 gwindow->gui->toggle_camera_xyz();
3026 gwindow->gui->unlock_window();
3029 void MWindow::toggle_projector_xyz()
3031 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3032 gwindow->gui->toggle_projector_xyz();
3033 gwindow->gui->unlock_window();
3036 void MWindow::set_labels_follow_edits(int value)
3038 gui->lock_window("MWindow::set_labels_follow_edits");
3039 edl->session->labels_follow_edits = value;
3040 gui->mbuttons->edit_panel->locklabels->update(value);
3041 gui->mainmenu->labels_follow_edits->set_checked(value);
3043 gui->unlock_window();
3046 void MWindow::sync_parameters(int change_type)
3048 if( in_destructor ) return;
3050 // Sync engines which are playing back
3051 if(cwindow->playback_engine->is_playing_back)
3053 if(change_type == CHANGE_PARAMS)
3055 // TODO: block keyframes until synchronization is done
3056 cwindow->playback_engine->sync_parameters(edl);
3061 int command = cwindow->playback_engine->command->command;
3062 cwindow->playback_engine->que->send_command(STOP,
3066 // Waiting for tracking to finish would make the restart position more
3067 // accurate but it can't lock the window to stop tracking for some reason.
3068 // Not waiting for tracking gives a faster response but restart position is
3069 // only as accurate as the last tracking update.
3070 cwindow->playback_engine->interrupt_playback(0);
3071 cwindow->playback_engine->que->send_command(command,
3080 cwindow->refresh_frame(change_type);
3084 void MWindow::age_caches()
3086 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3088 // preferences->cache_size,
3089 // audio_cache->get_memory_usage(1),
3090 // video_cache->get_memory_usage(1),
3091 // frame_cache->get_memory_usage(),
3092 // wave_cache->get_memory_usage(),
3094 frame_cache->age_cache(512);
3095 wave_cache->age_cache(8192);
3097 int64_t memory_usage;
3098 int64_t prev_memory_usage = 0;
3100 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3101 while( !result && prev_memory_usage !=
3102 (memory_usage=video_cache->get_memory_usage(1)) &&
3103 memory_usage > video_size ) {
3104 video_cache->delete_oldest();
3105 prev_memory_usage = memory_usage;
3108 prev_memory_usage = 0;
3110 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3111 while( !result && prev_memory_usage !=
3112 (memory_usage=audio_cache->get_memory_usage(1)) &&
3113 memory_usage > audio_size ) {
3114 audio_cache->delete_oldest();
3115 prev_memory_usage = memory_usage;
3119 void MWindow::reset_android_remote()
3121 gui->use_android_remote(preferences->android_remote);
3125 void MWindow::show_keyframe_gui(Plugin *plugin)
3127 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3128 // Find existing thread
3129 for(int i = 0; i < keyframe_threads->size(); i++)
3131 if(keyframe_threads->get(i)->plugin == plugin)
3133 keyframe_threads->get(i)->start_window(plugin, 0);
3134 keyframe_gui_lock->unlock();
3139 // Find unused thread
3140 for(int i = 0; i < keyframe_threads->size(); i++)
3142 if(!keyframe_threads->get(i)->plugin)
3144 keyframe_threads->get(i)->start_window(plugin, 0);
3145 keyframe_gui_lock->unlock();
3150 // Create new thread
3151 KeyFrameThread *thread = new KeyFrameThread(this);
3152 keyframe_threads->append(thread);
3153 thread->start_window(plugin, 0);
3155 keyframe_gui_lock->unlock();
3162 void MWindow::show_plugin(Plugin *plugin)
3167 // Remove previously deleted plugin GUIs
3168 dead_plugin_lock->lock("MWindow::show_plugin");
3169 dead_plugins->remove_all_objects();
3170 dead_plugin_lock->unlock();
3172 //printf("MWindow::show_plugin %d\n", __LINE__);
3176 plugin_gui_lock->lock("MWindow::show_plugin");
3177 for(int i = 0; i < plugin_guis->total; i++)
3179 // Pointer comparison
3180 if(plugin_guis->get(i)->plugin == plugin)
3182 plugin_guis->get(i)->raise_window();
3189 //printf("MWindow::show_plugin 1\n");
3190 if( !done && !plugin->track ) {
3191 printf("MWindow::show_plugin track not defined.\n");
3195 PluginServer *server = scan_plugindb(plugin->title,
3196 plugin->track->data_type);
3198 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3199 if(server && server->uses_gui)
3201 PluginServer *gui = new PluginServer(*server);
3202 plugin_guis->append(gui);
3203 // Needs mwindow to do GUI
3204 gui->set_mwindow(this);
3205 gui->open_plugin(0, preferences, edl, plugin);
3210 plugin_gui_lock->unlock();
3211 //printf("MWindow::show_plugin %d\n", __LINE__);
3214 //printf("MWindow::show_plugin 2\n");
3217 void MWindow::hide_plugin(Plugin *plugin, int lock)
3220 // Update the toggle
3221 gui->lock_window("MWindow::hide_plugin");
3222 gui->update(0, 1, 0, 0, 0, 0, 0);
3223 gui->unlock_window();
3225 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3226 for(int i = 0; i < plugin_guis->total; i++)
3228 if(plugin_guis->get(i)->plugin == plugin)
3230 PluginServer *ptr = plugin_guis->get(i);
3231 plugin_guis->remove(ptr);
3232 if(lock) plugin_gui_lock->unlock();
3233 // Last command executed in client side close
3234 // Schedule for deletion
3241 if(lock) plugin_gui_lock->unlock();
3244 void MWindow::delete_plugin(PluginServer *plugin)
3246 dead_plugin_lock->lock("MWindow::delete_plugin");
3247 dead_plugins->append(plugin);
3248 dead_plugin_lock->unlock();
3251 void MWindow::hide_plugins()
3253 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3254 while(plugin_guis->size())
3256 PluginServer *ptr = plugin_guis->get(0);
3257 plugin_guis->remove(ptr);
3258 plugin_gui_lock->unlock();
3259 // Last command executed in client side close
3260 // Schedule for deletion
3263 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3265 plugin_gui_lock->unlock();
3267 hide_keyframe_guis();
3270 void MWindow::hide_keyframe_guis()
3272 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3273 for(int i = 0; i < keyframe_threads->size(); i++)
3275 keyframe_threads->get(i)->close_window();
3277 keyframe_gui_lock->unlock();
3280 void MWindow::hide_keyframe_gui(Plugin *plugin)
3282 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3283 for(int i = 0; i < keyframe_threads->size(); i++)
3285 if(keyframe_threads->get(i)->plugin == plugin)
3287 keyframe_threads->get(i)->close_window();
3291 keyframe_gui_lock->unlock();
3294 void MWindow::update_keyframe_guis()
3296 // Send new configuration to keyframe GUI's
3297 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3298 for(int i = 0; i < keyframe_threads->size(); i++)
3300 KeyFrameThread *ptr = keyframe_threads->get(i);
3301 if(edl->tracks->plugin_exists(ptr->plugin))
3305 ptr->close_window();
3308 keyframe_gui_lock->unlock();
3311 void MWindow::update_plugin_guis(int do_keyframe_guis)
3313 // Send new configuration to plugin GUI's
3314 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3316 for(int i = 0; i < plugin_guis->size(); i++)
3318 PluginServer *ptr = plugin_guis->get(i);
3319 if(edl->tracks->plugin_exists(ptr->plugin))
3323 // Schedule for deletion if no plugin
3324 plugin_guis->remove_number(i);
3333 // Change plugin variable if not visible
3334 Track *track = edl->tracks->first;
3337 for(int i = 0; i < track->plugin_set.size(); i++)
3339 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3343 for(int i = 0; i < plugin_guis->size(); i++)
3345 PluginServer *server = plugin_guis->get(i);
3346 if(server->plugin == plugin)
3353 if(!got_it) plugin->show = 0;
3355 plugin = (Plugin*)plugin->next;
3359 track = track->next;
3362 plugin_gui_lock->unlock();
3365 if(do_keyframe_guis) update_keyframe_guis();
3368 int MWindow::plugin_gui_open(Plugin *plugin)
3371 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3372 for(int i = 0; i < plugin_guis->total; i++)
3374 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3380 plugin_gui_lock->unlock();
3384 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3386 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3387 for(int i = 0; i < plugin_guis->total; i++)
3389 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3391 plugin_guis->get(i)->render_gui(data);
3395 plugin_gui_lock->unlock();
3398 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3400 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3401 for(int i = 0; i < plugin_guis->total; i++)
3403 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3405 plugin_guis->get(i)->render_gui(data, size);
3409 plugin_gui_lock->unlock();
3413 void MWindow::update_plugin_states()
3415 plugin_gui_lock->lock("MWindow::update_plugin_states");
3416 for(int i = 0; i < plugin_guis->total; i++)
3420 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3421 PluginServer *src_plugingui = plugin_guis->get(i);
3423 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3424 for(Track *track = edl->tracks->first;
3426 track = track->next)
3429 j < track->plugin_set.total && !result;
3432 PluginSet *plugin_set = track->plugin_set[j];
3433 for(Plugin *plugin = (Plugin*)plugin_set->first;
3435 plugin = (Plugin*)plugin->next)
3437 if(plugin == src_plugin &&
3438 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3444 // Doesn't exist anymore
3447 hide_plugin(src_plugin, 0);
3451 plugin_gui_lock->unlock();
3455 void MWindow::update_plugin_titles()
3457 for(int i = 0; i < plugin_guis->total; i++)
3459 plugin_guis->get(i)->update_title();
3463 int MWindow::asset_to_edl(EDL *new_edl,
3465 RecordLabels *labels)
3467 const int debug = 0;
3468 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3471 // Keep frame rate, sample rate, and output size unchanged.
3472 // These parameters would revert the project if VWindow displayed an asset
3473 // of different size than the project.
3474 if(new_asset->video_data)
3476 new_edl->session->video_tracks = new_asset->layers;
3479 new_edl->session->video_tracks = 0;
3481 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3487 if(new_asset->audio_data)
3489 new_edl->session->audio_tracks = new_asset->channels;
3492 new_edl->session->audio_tracks = 0;
3493 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3495 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3496 new_edl->create_default_tracks();
3497 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3498 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3502 //printf("MWindow::asset_to_edl 3\n");
3503 new_edl->insert_asset(new_asset,
3508 //printf("MWindow::asset_to_edl 3\n");
3509 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3511 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3512 if(edl->session->cursor_on_frames)
3514 double length = new_edl->tracks->total_length();
3515 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3516 new_edl->tracks->clear(length, edl_length, 1, 1);
3522 char string[BCTEXTLEN];
3524 fs.extract_name(string, new_asset->path);
3525 //printf("MWindow::asset_to_edl 3\n");
3527 strcpy(new_edl->local_session->clip_title, string);
3528 //printf("MWindow::asset_to_edl 4 %s\n", string);
3529 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3535 // Reset everything after a load.
3536 void MWindow::update_project(int load_mode)
3538 const int debug = 0;
3540 if(debug) PRINT_TRACE
3541 edl->tracks->update_y_pixels(theme);
3542 session->update_clip_number();
3544 if(debug) PRINT_TRACE
3546 if( load_mode == LOADMODE_REPLACE ||
3547 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3548 delete gui->keyvalue_popup;
3549 gui->keyvalue_popup = 0;
3553 gui->update(1, 1, 1, 1, 1, 1, 1);
3554 if(debug) PRINT_TRACE
3555 gui->unlock_window();
3558 cwindow->gui->lock_window("MWindow::update_project 1");
3559 cwindow->update(0, 0, 1, 1, 1);
3560 cwindow->gui->unlock_window();
3562 if(debug) PRINT_TRACE
3564 // Close all the vwindows
3565 if( load_mode == LOADMODE_REPLACE ||
3566 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3567 if(debug) PRINT_TRACE
3568 int first_vwindow = 0;
3569 if(session->show_vwindow) first_vwindow = 1;
3570 // Change visible windows to no source
3571 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3572 VWindow *vwindow = vwindows[i];
3573 if( !vwindow->is_running() ) continue;
3574 vwindow->change_source(-1);
3577 // Close remaining windows
3578 for(int i = first_vwindow; i < vwindows.size(); i++) {
3579 VWindow *vwindow = vwindows[i];
3580 if( !vwindow->is_running() ) continue;
3581 vwindow->close_window();
3583 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3584 VWindow *vwindow = get_viewer(1, -1);
3585 vwindow->change_source(i);
3587 if(debug) PRINT_TRACE
3591 for( int i=0; i<edl->mixers.size(); ++i ) {
3592 Mixer *mixer = edl->mixers[i];
3593 ZWindow *zwindow = get_mixer(mixer);
3594 zwindow->set_title(mixer->title);
3600 if(debug) PRINT_TRACE
3601 cwindow->gui->lock_window("MWindow::update_project 2");
3602 cwindow->gui->timebar->update(0);
3603 cwindow->gui->unlock_window();
3605 if(debug) PRINT_TRACE
3606 cwindow->refresh_frame(CHANGE_ALL);
3608 awindow->gui->async_update_assets();
3609 if(debug) PRINT_TRACE
3611 gui->lock_window("MWindow::update_project");
3612 gui->update_mixers(0, 0);
3614 if(debug) PRINT_TRACE
3617 void MWindow::update_vwindow()
3619 for( int i=0; i<vwindows.size(); ++i ) {
3620 VWindow *vwindow = vwindows[i];
3621 if( vwindow->is_running() ) {
3622 vwindow->gui->lock_window("MWindow::update_vwindow");
3624 vwindow->gui->unlock_window();
3629 void MWindow::remove_indexfile(Indexable *indexable)
3631 if( !indexable->is_asset ) return;
3632 Asset *asset = (Asset *)indexable;
3634 IndexFile::delete_index(preferences, asset, ".toc");
3635 IndexFile::delete_index(preferences, asset, ".idx");
3636 IndexFile::delete_index(preferences, asset, ".mkr");
3639 void MWindow::rebuild_indices()
3641 for(int i = 0; i < session->drag_assets->total; i++)
3643 Indexable *indexable = session->drag_assets->get(i);
3644 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3645 remove_indexfile(indexable);
3646 // Schedule index build
3647 IndexState *index_state = indexable->index_state;
3648 index_state->index_status = INDEX_NOTTESTED;
3649 if( indexable->is_asset ) {
3650 Asset *asset = (Asset *)indexable;
3651 if( asset->format != FILE_PCM ) {
3652 asset->format = FILE_UNKNOWN;
3653 asset->reset_audio();
3655 asset->reset_video();
3656 remove_asset_from_caches(asset);
3657 // File file; // re-probe the asset
3658 // file.open_file(preferences, asset, 1, 0);
3660 mainindexes->add_next_asset(0, indexable);
3662 mainindexes->start_build();
3666 void MWindow::save_backup()
3670 edl->set_path(session->filename);
3671 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3672 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3673 File::get_config_path(), BACKUP_FILE);
3674 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3675 File::get_config_path(), BACKUP_FILE1);
3676 rename(backup_path, backup_path1);
3677 edl->save_xml(&file, backup_path);
3678 file.terminate_string();
3680 fs.complete_path(backup_path);
3682 if(file.write_to_file(backup_path))
3685 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3686 gui->show_message(string2);
3690 void MWindow::load_backup()
3692 ArrayList<char*> path_list;
3693 path_list.set_array_delete();
3695 char backup_path[BCTEXTLEN];
3696 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3697 File::get_config_path(), BACKUP_FILE);
3699 fs.complete_path(backup_path);
3701 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3702 strcpy(out_path, backup_path);
3704 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3705 edl->local_session->clip_title[0] = 0;
3706 // This is unique to backups since the path of the backup is different than the
3707 // path of the project.
3708 set_filename(edl->path);
3709 path_list.remove_all_objects();
3714 void MWindow::save_undo_data()
3716 undo->update_undo_before();
3717 undo->update_undo_after(_("perpetual session"), LOAD_ALL);
3718 char perpetual_path[BCTEXTLEN];
3719 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3720 File::get_config_path(), PERPETUAL_FILE);
3721 FILE *fp = fopen(perpetual_path,"w");
3727 void MWindow::load_undo_data()
3729 char perpetual_path[BCTEXTLEN];
3730 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3731 File::get_config_path(), PERPETUAL_FILE);
3732 FILE *fp = fopen(perpetual_path,"r");
3739 int MWindow::copy_target(const char *path, const char *target)
3741 int ifd = ::open(path, O_RDONLY);
3743 eprintf("Cannot open asset: %s", path);
3747 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
3750 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
3751 char progress_title[BCTEXTLEN];
3752 sprintf(progress_title, _("Copying: %s\n"), target);
3753 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
3755 int64_t count = 0, len = -1;
3756 int bfrsz = 0x100000;
3757 uint8_t *bfr = new uint8_t[bfrsz];
3758 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
3759 if( len != ::write(ofd, bfr, len) ) {
3760 eprintf("Error writing: %s", target);
3763 if( progress.is_cancelled() ) {
3767 progress.update(count += len, 1);
3772 progress.stop_progress();
3774 eprintf("Error reading: %s", path);
3779 eprintf("Cannot create asset target: %s", target);
3784 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
3786 char target[BCTEXTLEN];
3788 const char *bp = real_path, *cp = bp;
3789 const char *lp = link_path, *np = lp;
3790 char *tp = target, *ep = tp+sizeof(target)-1, lch;
3791 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
3792 if( lch == '/' ) { np = lp; cp = bp; }
3794 while( tp<ep && *np ) {
3795 if( *np++ != '/' ) continue;
3796 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
3798 while( tp<ep && *cp ) *tp++ = *cp++;
3802 strcpy(target, real_path);
3803 if( symlink(target, link_path) ) {
3804 eprintf("Cannot create symlink: %s", link_path);
3810 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
3812 char dir_path[BCTEXTLEN];
3813 strcpy(dir_path, dir);
3815 fs.complete_path(dir_path);
3818 if( !stat(dir_path, &st) ) {
3819 if( !S_ISDIR(st.st_mode) ) {
3820 eprintf("Path exists and is not a directory\n%s", dir_path);
3825 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
3826 eprintf("Cannot create directory\n%s", dir_path);
3830 char *real_dir = realpath(dir_path, 0);
3831 strcpy(dir_path, real_dir);
3834 EDL *save_edl = new EDL;
3835 save_edl->create_objects();
3836 save_edl->copy_all(edl);
3838 char progress_title[BCTEXTLEN];
3839 sprintf(progress_title, _("Saving to %s:\n"), dir);
3840 int total_assets = save_edl->assets->total();
3841 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
3843 Asset *current = save_edl->assets->first;
3844 for( int i=0; !ret && current; ++i, current=NEXT ) {
3845 char *path = current->path;
3846 if( ::stat(path, &st) ) {
3847 eprintf("Asset not found: %s", path);
3850 char *real_path = realpath(path, 0);
3851 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
3852 char link_path[BCTEXTLEN];
3853 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
3855 if( strcmp(real_path, link_path) ) {
3856 if( !::lstat(link_path, &st) ) {
3858 ::remove(link_path);
3864 eprintf("copy/link to self, skippped: %s", path);
3868 if( save_mode == SAVE_PROJECT_COPY ) {
3869 if( copy_target(real_path, link_path) )
3873 link_target(real_path, link_path,
3874 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
3878 strcpy(path, link_path);
3880 if( progress->is_cancelled() ) break;
3881 progress->update(i);
3884 progress->stop_progress();
3887 char *cp = strrchr(dir_path,'/');
3888 char *bp = cp ? cp+1 : dir_path;
3889 char filename[BCTEXTLEN];
3890 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
3891 save_edl->set_path(filename);
3893 save_edl->save_xml(&file, filename);
3894 file.terminate_string();
3896 if( !file.write_to_file(filename) ) {
3897 char string[BCTEXTLEN];
3898 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
3899 gui->lock_window("SaveProject::run 2");
3900 gui->show_message(string);
3901 gui->unlock_window();
3902 gui->mainmenu->add_load(filename);
3905 eprintf(_("Couldn't open %s."), filename);
3907 save_edl->remove_user();
3910 gui->lock_window("MWindow::save_project");
3911 ArrayList<char*> filenames;
3912 filenames.append(filename);
3913 load_filenames(&filenames, LOADMODE_REPLACE);
3914 gui->unlock_window();
3919 static inline int gcd(int m, int n)
3922 if( m < n ) { r = m; m = n; n = r; }
3923 while( (r = m % n) != 0 ) { m = n; n = r; }
3927 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3930 if(!width || !height) return 1;
3931 if( width == 720 && (height == 480 || height == 576) ) {
3932 w = 4; h = 3; return 0; // for NTSC and PAL
3934 double ar = (double)width / height;
3935 // square-ish pixels
3936 if( EQUIV(ar, 1.0000) ) return 0;
3937 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3938 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3939 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3940 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3941 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3942 int ww = width, hh = height;
3943 // numerator, denominator must be under mx
3944 int mx = 255, n = gcd(ww, hh);
3945 if( n > 1 ) { ww /= n; hh /= n; }
3946 // search near height in case extra/missing lines
3947 if( ww >= mx || hh >= mx ) {
3948 double err = height; // +/- 2 percent height
3949 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3950 int iw = width, ih = height+i;
3951 if( (n=gcd(iw, ih)) > 1 ) {
3952 int u = iw/n; if( u >= mx ) continue;
3953 int v = ih/n; if( v >= mx ) continue;
3954 double r = (double) u/v, er = fabs(ar-r);
3955 if( er >= err ) continue;
3956 err = er; ww = u; hh = v;
3965 void MWindow::reset_caches()
3967 frame_cache->remove_all();
3968 wave_cache->remove_all();
3969 audio_cache->remove_all();
3970 video_cache->remove_all();
3971 if( cwindow->playback_engine ) {
3972 if( cwindow->playback_engine->audio_cache )
3973 cwindow->playback_engine->audio_cache->remove_all();
3974 if( cwindow->playback_engine->video_cache )
3975 cwindow->playback_engine->video_cache->remove_all();
3977 for(int i = 0; i < vwindows.size(); i++) {
3978 VWindow *vwindow = vwindows[i];
3979 if( !vwindow->is_running() ) continue;
3980 if( !vwindow->playback_engine ) continue;
3981 if( vwindow->playback_engine->audio_cache )
3982 vwindow->playback_engine->audio_cache->remove_all();
3983 if( vwindow->playback_engine->video_cache )
3984 vwindow->playback_engine->video_cache->remove_all();
3988 void MWindow::remove_asset_from_caches(Asset *asset)
3990 frame_cache->remove_asset(asset);
3991 wave_cache->remove_asset(asset);
3992 audio_cache->delete_entry(asset);
3993 video_cache->delete_entry(asset);
3994 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3995 cwindow->playback_engine->audio_cache->delete_entry(asset);
3996 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3997 cwindow->playback_engine->video_cache->delete_entry(asset);
3998 for(int i = 0; i < vwindows.size(); i++) {
3999 VWindow *vwindow = vwindows[i];
4000 if( !vwindow->is_running() ) continue;
4001 if( !vwindow->playback_engine ) continue;
4002 if( vwindow->playback_engine->audio_cache )
4003 vwindow->playback_engine->audio_cache->delete_entry(asset);
4004 if( vwindow->playback_engine->video_cache )
4005 vwindow->playback_engine->video_cache->delete_entry(asset);
4010 void MWindow::remove_assets_from_project(int push_undo, int redraw,
4011 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4013 for(int i = 0; i < drag_assets->total; i++) {
4014 Indexable *indexable = drag_assets->get(i);
4015 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
4018 // Remove from VWindow.
4019 for(int i = 0; i < session->drag_clips->total; i++) {
4020 for(int j = 0; j < vwindows.size(); j++) {
4021 VWindow *vwindow = vwindows[j];
4022 if( !vwindow->is_running() ) continue;
4023 if(session->drag_clips->get(i) == vwindow->get_edl()) {
4024 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4025 vwindow->delete_source(1, 1);
4026 vwindow->gui->unlock_window();
4031 for(int i = 0; i < drag_assets->size(); i++) {
4032 for(int j = 0; j < vwindows.size(); j++) {
4033 VWindow *vwindow = vwindows[j];
4034 if( !vwindow->is_running() ) continue;
4035 if(drag_assets->get(i) == vwindow->get_source()) {
4036 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4037 vwindow->delete_source(1, 1);
4038 vwindow->gui->unlock_window();
4043 for(int i = 0; i < drag_assets->size(); i++) {
4044 Indexable *indexable = drag_assets->get(i);
4045 remove_indexfile(indexable);
4048 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4049 if(push_undo) undo->update_undo_before();
4050 if(drag_assets) edl->remove_from_project(drag_assets);
4051 if(drag_clips) edl->remove_from_project(drag_clips);
4052 if(redraw) save_backup();
4053 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
4057 gui->lock_window("MWindow::remove_assets_from_project 3");
4058 gui->update(1, 1, 1, 1, 0, 1, 0);
4059 gui->unlock_window();
4061 // Removes from playback here
4062 sync_parameters(CHANGE_ALL);
4065 awindow->gui->async_update_assets();
4068 void MWindow::remove_assets_from_disk()
4071 for(int i = 0; i < session->drag_assets->total; i++)
4073 remove(session->drag_assets->get(i)->path);
4076 remove_assets_from_project(1,
4078 session->drag_assets,
4079 session->drag_clips);
4082 void MWindow::dump_plugins(FILE *fp)
4084 if( !plugindb ) return;
4085 for(int i = 0; i < plugindb->total; i++)
4087 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4088 " synth=%d transition=%d theme=%d %s\n",
4089 plugindb->get(i)->plugin_type,
4090 plugindb->get(i)->audio,
4091 plugindb->get(i)->video,
4092 plugindb->get(i)->realtime,
4093 plugindb->get(i)->multichannel,
4094 plugindb->get(i)->get_synthesis(),
4095 plugindb->get(i)->transition,
4096 plugindb->get(i)->theme,
4097 plugindb->get(i)->title);
4101 void MWindow::dump_edl(FILE *fp)
4107 void MWindow::dump_undo(FILE *fp)
4113 void MWindow::dump_exe(FILE *fp)
4115 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4116 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4118 int ret = -1, n = 100;
4119 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4120 exe_path[len] = 0; strcpy(proc_path, exe_path);
4123 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4126 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4127 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4128 struct tm *tm = localtime(&st.st_mtime);
4130 strftime(mtime, sizeof(mtime), "%F %T", tm);
4131 fprintf(fp,"mtime: %s\n", mtime);
4133 // people hit ctl-c waiting for this
4134 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4135 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4138 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4139 int64_t maxsz = 1024*pagsz;
4140 int64_t size = st.st_size, pos = 0;
4142 while( (bfrsz = size-pos) > 0 ) {
4143 if( bfrsz > maxsz ) bfrsz = maxsz;
4144 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4145 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4146 if( bfr == MAP_FAILED ) break;
4147 sha1.addBytes(bfr, bfrsz);
4152 ret = pos < size ? EIO : 0;
4153 fprintf(fp, "SHA1: ");
4154 uint8_t digest[20]; sha1.computeHash(digest);
4155 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4156 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4157 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4162 void MWindow::trap_hook(FILE *fp, void *vp)
4164 MWindow *mwindow = (MWindow *)vp;
4165 // fprintf(fp, "\nPLUGINS:\n");
4166 // mwindow->dump_plugins(fp);
4167 fprintf(fp, "\nEDL:\n");
4168 mwindow->dump_edl(fp);
4169 fprintf(fp, "\nUNDO:\n");
4170 mwindow->dump_undo(fp);
4171 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4172 mwindow->dump_exe(fp);
4180 int MWindow::save_defaults()
4182 gui->save_defaults(defaults);
4183 edl->save_defaults(defaults);
4184 session->save_defaults(defaults);
4185 preferences->save_defaults(defaults);
4187 for(int i = 0; i < plugin_guis->total; i++)
4189 // Pointer comparison
4190 plugin_guis->get(i)->save_defaults();
4192 awindow->save_defaults(defaults);
4198 int MWindow::run_script(FileXML *script)
4200 int result = 0, result2 = 0;
4201 while(!result && !result2)
4203 result = script->read_tag();
4206 if(script->tag.title_is("new_project"))
4208 // Run new in immediate mode.
4209 // gui->mainmenu->new_project->run_script(script);
4212 if(script->tag.title_is("record"))
4214 // Run record as a thread. It is a terminal command.
4216 // Will read the complete scipt file without letting record read it if not
4222 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4229 // ================================= synchronization
4232 int MWindow::interrupt_indexes()
4234 mainprogress->cancelled = 1;
4235 mainindexes->interrupt_build();
4241 void MWindow::next_time_format()
4243 switch(edl->session->time_format)
4245 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4246 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4247 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4248 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4249 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4250 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4251 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4254 time_format_common();
4257 void MWindow::prev_time_format()
4259 switch(edl->session->time_format)
4261 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4262 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4263 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4264 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4265 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4266 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4267 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4270 time_format_common();
4273 void MWindow::time_format_common()
4275 gui->lock_window("MWindow::next_time_format");
4276 gui->redraw_time_dependancies();
4279 char string[BCTEXTLEN], string2[BCTEXTLEN];
4280 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4281 gui->show_message(string);
4283 gui->unlock_window();
4287 int MWindow::set_filename(const char *filename)
4289 if( filename != session->filename )
4290 strcpy(session->filename, filename);
4291 if( filename != edl->path )
4292 strcpy(edl->path, filename);
4296 if(filename[0] == 0)
4298 gui->set_title(PROGRAM_NAME);
4303 char string[BCTEXTLEN], string2[BCTEXTLEN];
4304 dir.extract_name(string, filename);
4305 sprintf(string2, PROGRAM_NAME ": %s", string);
4306 gui->set_title(string2);
4319 int MWindow::set_loop_boundaries()
4321 double start = edl->local_session->get_selectionstart();
4322 double end = edl->local_session->get_selectionend();
4330 if(edl->tracks->total_length())
4333 end = edl->tracks->total_length();
4340 if(edl->local_session->loop_playback && start != end)
4342 edl->local_session->loop_start = start;
4343 edl->local_session->loop_end = end;
4354 int MWindow::reset_meters()
4356 cwindow->gui->lock_window("MWindow::reset_meters 1");
4357 cwindow->gui->meters->reset_meters();
4358 cwindow->gui->unlock_window();
4360 for(int j = 0; j < vwindows.size(); j++) {
4361 VWindow *vwindow = vwindows[j];
4362 if( !vwindow->is_running() ) continue;
4363 vwindow->gui->lock_window("MWindow::reset_meters 2");
4364 vwindow->gui->meters->reset_meters();
4365 vwindow->gui->unlock_window();
4368 lwindow->gui->lock_window("MWindow::reset_meters 3");
4369 lwindow->gui->panel->reset_meters();
4370 lwindow->gui->unlock_window();
4372 gui->lock_window("MWindow::reset_meters 4");
4373 gui->reset_meters();
4374 gui->unlock_window();
4379 void MWindow::resync_guis()
4383 gui->lock_window("MWindow::resync_guis");
4384 gui->update(1, 1, 1, 1, 1, 1, 0);
4385 gui->unlock_window();
4387 cwindow->gui->lock_window("MWindow::resync_guis");
4388 cwindow->gui->resize_event(cwindow->gui->get_w(),
4389 cwindow->gui->get_h());
4390 int channels = edl->session->audio_channels;
4391 cwindow->gui->meters->set_meters(channels, 1);
4392 cwindow->gui->flush();
4393 cwindow->gui->unlock_window();
4395 for(int i = 0; i < vwindows.size(); i++) {
4396 VWindow *vwindow = vwindows[i];
4397 if( !vwindow->is_running() ) continue;
4398 vwindow->gui->lock_window("MWindow::resync_guis");
4399 vwindow->gui->resize_event(vwindow->gui->get_w(),
4400 vwindow->gui->get_h());
4401 vwindow->gui->meters->set_meters(channels, 1);
4402 vwindow->gui->flush();
4403 vwindow->gui->unlock_window();
4406 lwindow->gui->lock_window("MWindow::resync_guis");
4407 lwindow->gui->panel->set_meters(channels, 1);
4408 lwindow->gui->flush();
4409 lwindow->gui->unlock_window();
4412 if(((edl->session->output_w % 4) ||
4413 (edl->session->output_h % 4)) &&
4414 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4416 MainError::show_error(
4417 _("This project's dimensions are not multiples of 4 so\n"
4418 "it can't be rendered by OpenGL."));
4423 sync_parameters(CHANGE_ALL);
4426 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4428 File *file = new File;
4429 EDLSession *session = edl->session;
4430 double old_framerate = session->frame_rate;
4431 double old_samplerate = session->sample_rate;
4432 int old_auto_keyframes = session->auto_keyframes;
4433 session->auto_keyframes = 0;
4434 int result = file->open_file(preferences, asset, 1, 0);
4435 if( !result && delete_tracks > 0 )
4436 undo->update_undo_before();
4437 int video_layers = asset->get_video_layers();
4438 if( !result && asset->video_data && vstream < video_layers ) {
4439 // try to get asset up to date, may fail
4440 file->select_video_stream(asset, vstream);
4441 // either way use what was/is there.
4442 double framerate = asset->get_frame_rate();
4443 int width = asset->get_w();
4444 int height = asset->get_h();
4445 // must be multiple of 4 for opengl
4446 width = (width+3) & ~3; height = (height+3) & ~3;
4447 int driver = session->playback_config->vconfig->driver;
4448 int color_model = file->get_best_colormodel(asset, driver);
4449 // color_model = BC_CModels::is_yuv(color_model) ?
4450 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4451 // BC_CModels::is_float(color_model) ?
4452 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4453 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4454 // have alpha for now
4455 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4456 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4457 session->color_model = color_model;
4458 session->output_w = width;
4459 session->output_h = height;
4460 session->frame_rate = framerate;
4461 // not, asset->actual_width/actual_height
4462 asset->width = session->output_w;
4463 asset->height = session->output_h;
4464 asset->frame_rate = session->frame_rate;
4465 create_aspect_ratio(session->aspect_w, session->aspect_h,
4466 session->output_w, session->output_h);
4467 Track *track = edl->tracks->first;
4468 for( Track *next_track=0; track; track=next_track ) {
4469 next_track = track->next;
4470 if( track->data_type != TRACK_VIDEO ) continue;
4471 if( delete_tracks ) {
4472 Edit *edit = track->edits->first;
4473 for( Edit *next_edit=0; edit; edit=next_edit ) {
4474 next_edit = edit->next;
4475 if( edit->channel != vstream ||
4476 !edit->asset || !edit->asset->is_asset ||
4477 !asset->equivalent(*edit->asset,1,1,edl) )
4481 if( track->edits->first ) {
4482 track->track_w = edl->session->output_w;
4483 track->track_h = edl->session->output_h;
4485 else if( delete_tracks )
4486 edl->tracks->delete_track(track);
4489 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4491 if( !result && asset->audio_data && asset->channels > 0 ) {
4492 session->sample_rate = asset->get_sample_rate();
4493 int64_t channel_mask = 0;
4494 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4495 file->get_audio_for_video(vstream, astream, channel_mask);
4496 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4497 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4499 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4500 if( channels < 1 ) channels = 1;
4501 if( channels > 6 ) channels = 6;
4502 session->audio_tracks = session->audio_channels = channels;
4504 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4505 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4506 remap_audio(MWindow::AUDIO_1_TO_1);
4508 if( delete_tracks ) {
4509 Track *track = edl->tracks->first;
4510 for( Track *next_track=0; track; track=next_track ) {
4511 next_track = track->next;
4512 if( track->data_type != TRACK_AUDIO ) continue;
4513 Edit *edit = track->edits->first;
4514 for( Edit *next_edit=0; edit; edit=next_edit ) {
4515 next_edit = edit->next;
4516 if( !((1<<edit->channel) & channel_mask) ||
4517 !edit->asset || !edit->asset->is_asset ||
4518 !asset->equivalent(*edit->asset,1,1,edl) )
4521 if( !track->edits->first )
4522 edl->tracks->delete_track(track);
4526 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4529 session->auto_keyframes = old_auto_keyframes;
4530 if( !result && delete_tracks > 0 ) {
4532 undo->update_undo_after(_("select asset"), LOAD_ALL);
4538 int MWindow::select_asset(int vtrack, int delete_tracks)
4540 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4542 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4543 if( !track ) return 1;
4544 Edit *edit = track->edits->first;
4545 if( !edit ) return 1;
4546 Asset *asset = edit->asset;
4547 if( !asset || !asset->is_asset ) return 1;
4548 return select_asset(asset, edit->channel, 0, delete_tracks);
4551 void MWindow::dump_plugindb(FILE *fp)
4553 if( !plugindb ) return;
4554 for(int i = 0; i < plugindb->total; i++)
4555 plugindb->get(i)->dump(fp);
4558 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4561 double unit_position = edl->local_session->get_selectionstart(1);
4562 unit_position = patch->track->to_units(unit_position, 0);
4564 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4565 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4568 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4571 double unit_position = edl->local_session->get_selectionstart(1);
4572 unit_position = patch->track->to_units(unit_position, 0);
4574 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4575 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4578 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4581 double unit_position = edl->local_session->get_selectionstart(1);
4582 unit_position = patch->track->to_units(unit_position, 0);
4584 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4585 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4588 PatchGUI *MWindow::get_patchgui(Track *track)
4590 PatchGUI *patchgui = 0;
4591 TimelinePane **panes = gui->pane;
4592 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4593 if( !panes[i] ) continue;
4594 PatchBay *patchbay = panes[i]->patchbay;
4595 if( !patchbay ) continue;
4596 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4597 if( patchbay->patches.values[j]->track == track )
4598 patchgui = patchbay->patches.values[j];