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"
106 #include "sighandler.h"
107 #include "splashgui.h"
108 #include "statusbar.h"
110 #include "threadloader.h"
112 #include "timelinepane.h"
113 #include "tipwindow.h"
114 #include "trackcanvas.h"
116 #include "tracking.h"
117 #include "trackscroll.h"
119 #include "transition.h"
120 #include "transportque.h"
123 #include "versioninfo.h"
125 #include "videodevice.inc"
126 #include "videowindow.h"
127 #include "vplayback.h"
128 #include "vwindowgui.h"
130 #include "wavecache.h"
134 #include "zwindowgui.h"
135 #include "exportedl.h"
137 #include "defaultformats.h"
138 #include "ntsczones.h"
145 #include <sys/types.h>
146 #include <sys/stat.h>
147 #include <sys/time.h>
148 #include <sys/mman.h>
149 #include <sys/file.h>
160 // Hack for libdv to remove glib dependancy
163 // g_log (const char *log_domain,
165 // const char *format,
171 // g_logv (const char *log_domain,
173 // const char *format,
182 extern long cin_timezone;
184 ArrayList<PluginServer*>* MWindow::plugindb = 0;
185 Commercials* MWindow::commercials = 0;
191 run_lock = new Mutex("MWindow::run_lock");
192 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
193 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
194 vwindows_lock = new Mutex("MWindow::vwindows_lock");
195 zwindows_lock = new Mutex("MWindow::zwindows_lock");
196 brender_lock = new Mutex("MWindow::brender_lock");
197 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
202 undo_command = COMMAND_NONE;
206 commercial_active = 0;
218 strcpy(cin_lang,"en");
219 channeldb_buz = new ChannelDB;
220 channeldb_v4l2jpeg = new ChannelDB;
223 keyframe_threads = 0;
246 // Need to delete brender temporary here.
249 run_lock->lock("MWindow::~MWindow");
251 //printf("MWindow::~MWindow %d\n", __LINE__);
252 if( wwindow && wwindow->is_running() )
253 wwindow->close_window();
254 if( twindow && twindow->is_running() )
255 twindow->close_window();
256 gui->remote_control->deactivate();
259 gui->channel_info->stop();
262 delete create_bd; create_bd = 0;
263 delete create_dvd; create_dvd = 0;
264 delete shuttle; shuttle = 0;
265 delete batch_render; batch_render = 0;
266 delete render; render = 0;
268 if( commercials && !commercials->remove_user() ) commercials = 0;
270 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
271 // Save defaults for open plugins
272 plugin_gui_lock->lock("MWindow::~MWindow");
273 for(int i = 0; i < plugin_guis->size(); i++) {
274 plugin_guis->get(i)->hide_gui();
275 delete_plugin(plugin_guis->get(i));
277 plugin_gui_lock->unlock();
278 hide_keyframe_guis();
281 // Give up and go to a movie
282 // cant run valgrind if this is used
284 gui->del_keyboard_listener(
285 (int (BC_WindowBase::*)(BC_WindowBase *))
286 &MWindowGUI::keyboard_listener);
288 // release the hounds
289 if( awindow && awindow->gui ) awindow->gui->close(0);
290 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
291 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
292 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
293 vwindows.remove_all_objects();
294 zwindows.remove_all_objects();
296 if( awindow ) awindow->join();
297 if( cwindow ) cwindow->join();
298 if( lwindow ) lwindow->join();
299 if( gwindow ) gwindow->join();
302 // one at a time, or nouveau chokes
303 #define close_gui(win) if( win ) { \
304 if( win->gui ) win->gui->close(0); \
310 vwindows.remove_all_objects();
311 zwindows.remove_all_objects();
316 dead_plugins->remove_all_objects();
317 // must delete theme before destroying plugindb
318 // theme destructor will be deleted by delete_plugins
319 delete theme; theme = 0;
322 keyframe_threads->remove_all_objects();
323 colormodels.remove_all_objects();
324 delete awindow; awindow = 0;
325 delete lwindow; lwindow = 0;
326 delete twindow; twindow = 0;
327 delete wwindow; wwindow = 0;
328 delete gwindow; gwindow = 0;
329 delete cwindow; cwindow = 0;
331 delete mainindexes; mainindexes = 0;
332 delete mainprogress; mainprogress = 0;
333 delete audio_cache; audio_cache = 0; // delete the cache after the assets
334 delete video_cache; video_cache = 0; // delete the cache after the assets
335 delete frame_cache; frame_cache = 0;
336 delete wave_cache; wave_cache = 0;
337 delete plugin_guis; plugin_guis = 0;
338 delete dead_plugins; dead_plugins = 0;
339 delete keyframe_threads; keyframe_threads = 0;
340 delete undo; undo = 0;
341 delete preferences; preferences = 0;
342 delete exportedl; exportedl = 0;
343 delete session; session = 0;
344 delete defaults; defaults = 0;
345 delete assets; assets = 0;
346 delete splash_window; splash_window = 0;
347 if( !edl->Garbage::remove_user() ) edl = 0;
348 delete channeldb_buz;
349 delete channeldb_v4l2jpeg;
350 // This must be last thread to exit
351 delete playback_3d; playback_3d = 0;
352 delete dead_plugin_lock;
353 delete plugin_gui_lock;
354 delete vwindows_lock;
355 delete zwindows_lock;
357 delete keyframe_gui_lock;
358 colormodels.remove_all_objects();
359 interlace_project_modes.remove_all_objects();
360 interlace_asset_modes.remove_all_objects();
361 interlace_asset_fixmethods.remove_all_objects();
362 sighandler->terminate();
373 void MWindow::init_error()
375 MainError::init_error(this);
378 void MWindow::finit_error()
380 MainError::finit_error();
383 void MWindow::create_defaults_path(char *string, const char *config_file)
385 // set the .bcast path
388 sprintf(string, "%s/", File::get_config_path());
389 fs.complete_path(string);
390 if(!fs.is_dir(string))
391 fs.create_dir(string);
394 strcat(string, config_file);
396 const char *MWindow::default_std()
398 char buf[BCTEXTLEN], *p = 0;
400 int fd = open(TIMEZONE_NAME, O_RDONLY);
402 int l = read(fd, buf, sizeof(buf)-1);
405 if( buf[l-1] == '\n' ) --l;
411 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
414 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
415 p += strlen(ZONEINFO_STR);
420 for( int i=0; ntsc_zones[i]; ++i ) {
421 if( !strcmp(ntsc_zones[i], p) )
428 for( int i=0; ntsc_zones[i]; ++i ) {
429 if( !strcmp(ntsc_zones[i], p) )
434 // cin_timezone: Seconds west of UTC. 240sec/deg
435 double tz_deg = -cin_timezone / 240.;
436 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
437 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
440 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
442 struct formatpresets *fpr;
444 for(fpr = &format_presets[0]; fpr->name; fpr++)
446 if(strcmp(_(fpr->name), preset) == 0)
448 session->audio_channels = fpr->audio_channels;
449 session->audio_tracks = fpr->audio_tracks;
450 session->sample_rate = fpr->sample_rate;
451 session->video_channels = fpr->video_channels;
452 session->video_tracks = fpr->video_tracks;
453 session->frame_rate = fpr->frame_rate;
454 session->output_w = fpr->output_w;
455 session->output_h = fpr->output_h;
456 session->aspect_w = fpr->aspect_w;
457 session->aspect_h = fpr->aspect_h;
458 session->interlace_mode = fpr->interlace_mode;
459 session->color_model = fpr->color_model;
465 const char *MWindow::get_preset_name(int index)
467 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
469 return _(format_presets[index].name);
473 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
475 char path[BCTEXTLEN];
476 // Use user supplied path
478 strcpy(path, config_path);
480 create_defaults_path(path, CONFIG_FILE);
483 defaults = new BC_Hash(path);
488 void MWindow::check_language()
490 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
491 const char *env_lang = getenv("LANGUAGE");
492 if( !env_lang ) env_lang = getenv("LC_ALL");
493 if( !env_lang ) env_lang = getenv("LANG");
495 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
496 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
497 env_lang = curr_lang;
499 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
500 defaults->get("LAST_LANG",last_lang);
501 if( strcmp(env_lang,last_lang)) {
502 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
503 defaults->update("LAST_LANG",env_lang);
504 char plugin_path[BCTEXTLEN];
505 create_defaults_path(plugin_path, PLUGIN_FILE);
506 ::remove(plugin_path);
507 char ladspa_path[BCTEXTLEN];
508 create_defaults_path(ladspa_path, LADSPA_FILE);
509 ::remove(ladspa_path);
512 if( strlen(env_lang) > 1 &&
513 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
514 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
517 strcpy(cin_lang, "en");
520 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
522 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
524 const char *dp = plug_dir;
525 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
526 bp = !*dp && *bp == '/' ? bp+1 : base_path;
532 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir)
536 fseek(fp, 0, SEEK_SET);
538 char index_line[BCTEXTLEN];
539 int index_version = -1, len = strlen(plugin_dir);
540 if( !fgets(index_line, BCTEXTLEN, fp) ||
541 sscanf(index_line, "%d", &index_version) != 1 ||
542 index_version != PLUGIN_FILE_VERSION ||
543 !fgets(index_line, BCTEXTLEN, fp) ||
544 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
545 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
547 ArrayList<PluginServer*> plugins;
548 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
549 if( index_line[0] == ';' ) continue;
550 if( index_line[0] == '#' ) continue;
551 int type = PLUGIN_TYPE_UNKNOWN;
552 char path[BCTEXTLEN], title[BCTEXTLEN];
554 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
557 PluginServer *server = 0;
559 case PLUGIN_TYPE_BUILTIN:
560 case PLUGIN_TYPE_EXECUTABLE:
561 case PLUGIN_TYPE_LADSPA: {
562 char plugin_path[BCTEXTLEN]; struct stat st;
563 sprintf(plugin_path, "%s/%s", plugin_dir, path);
564 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
567 server = new PluginServer(mwindow, plugin_path, type);
569 case PLUGIN_TYPE_FFMPEG: {
570 server = new_ffmpeg_server(mwindow, path);
572 case PLUGIN_TYPE_LV2: {
573 server = new_lv2_server(mwindow, path);
576 if( !server ) continue;
577 plugins.append(server);
578 // Create plugin server from index entry
579 server->set_title(title);
580 if( server->read_table(index_line) ) {
586 ret = check_plugin_index(plugins, plugin_dir, ".");
589 add_plugins(plugins);
591 plugins.remove_all_objects();
596 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
597 const char *plug_dir, const char *plug_path)
599 char plugin_path[BCTEXTLEN];
600 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
602 fs.set_filter( "[*.plugin][*.so]" );
603 if( fs.update(plugin_path) )
606 for( int i=0; i<fs.dir_list.total; ++i ) {
607 char fs_path[BCTEXTLEN];
608 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
609 if( fs.is_dir(fs_path) ) {
610 get_plugin_path(plugin_path, plug_dir, fs_path);
611 if( check_plugin_index(plugins, plug_dir, plugin_path) )
614 else if( !plugin_exists(fs_path, plugins) )
621 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
624 plugindb = new ArrayList<PluginServer*>;
626 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
627 create_defaults_path(index_path, PLUGIN_FILE);
628 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
629 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
630 FILE *fp = fopen(index_path,"a+");
632 fprintf(stderr,_("MWindow::init_plugins: "
633 "can't open plugin index: %s\n"), index_path);
636 int fd = fileno(fp), ret = -1;
637 if( !flock(fd, LOCK_EX) ) {
638 fseek(fp, 0, SEEK_SET);
639 ret = load_plugin_index(mwindow, fp, plugin_path);
643 fseek(fp, 0, SEEK_SET);
644 printf("init plugin index: %s\n", plugin_path);
645 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
646 fprintf(fp, "%s\n", plugin_path);
647 init_plugin_index(mwindow, preferences, fp, plugin_path);
648 init_ffmpeg_index(mwindow, preferences, fp);
649 init_lv2_index(mwindow, preferences, fp);
650 fseek(fp, 0, SEEK_SET);
651 ret = load_plugin_index(mwindow, fp, plugin_path);
654 fprintf(stderr,_("MWindow::init_plugins: "
655 "can't %s plugin index: %s\n"),
656 ret>0 ? _("create") : _("lock"), index_path);
662 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
664 char *path = getenv("LADSPA_PATH");
665 char ladspa_path[BCTEXTLEN];
667 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
670 for( int len=0; *path; path+=len ) {
671 char *cp = strchr(path,':');
672 len = !cp ? strlen(path) : cp-path;
673 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
674 memcpy(plugin_path, path, len); plugin_path[len] = 0;
676 char *plugin_dir = FileSystem::basepath(plugin_path);
677 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
678 create_defaults_path(index_path, LADSPA_FILE);
679 cp = index_path + strlen(index_path);
680 for( char *bp=plugin_path; *bp!=0; ++bp )
681 *cp++ = *bp=='/' ? '_' : *bp;
683 FILE *fp = fopen(index_path,"a+");
685 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
686 "can't open ladspa plugin index: %s\n"), index_path);
689 int fd = fileno(fp), ret = -1;
690 if( !flock(fd, LOCK_EX) ) {
691 fseek(fp, 0, SEEK_SET);
692 ret = load_plugin_index(mwindow, fp, plugin_path);
696 fseek(fp, 0, SEEK_SET);
697 init_ladspa_index(mwindow, preferences, fp, plugin_path);
698 fseek(fp, 0, SEEK_SET);
699 ret = load_plugin_index(mwindow, fp, plugin_path);
702 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
703 "can't %s ladspa plugin index: %s\n"),
704 ret>0 ? _("create") : _("lock"), index_path);
711 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
712 FILE *fp, const char *plugin_dir)
714 int idx = PLUGIN_IDS;
716 for( int i=0; i<plugindb->size(); ++i ) {
717 PluginServer *server = plugindb->get(i);
718 if( server->dir_idx >= idx )
719 idx = server->dir_idx+1;
722 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
725 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
726 const char *plug_dir, const char *plug_path, int &idx)
728 char plugin_path[BCTEXTLEN];
729 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
731 fs.set_filter( "[*.plugin][*.so]" );
732 int result = fs.update(plugin_path);
733 if( result || !fs.dir_list.total ) return;
736 for( int i=0; i<fs.dir_list.total; ++i ) {
737 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
738 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
739 get_plugin_path(path, plug_dir, fs_path);
740 if( fs.is_dir(fs_path) ) {
741 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
744 if( plugin_exists(path) ) continue;
746 if( stat(fs_path, &st) ) continue;
747 int64_t mtime = st.st_mtime;
748 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
749 result = server.open_plugin(1, preferences, 0, 0);
751 server.write_table(fp, path, vis_id, mtime);
752 server.close_plugin();
754 else if( result == PLUGINSERVER_IS_LAD ) {
757 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
758 ladspa.set_lad_index(lad_index++);
759 result = ladspa.open_plugin(1, preferences, 0, 0);
761 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
762 ladspa.close_plugin();
768 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
770 for( int i=0; i<plugins.size(); ++i )
771 plugindb->append(plugins[i]);
772 plugins.remove_all();
775 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
777 const char *dat_path = File::get_cindat_path();
778 char msg_path[BCTEXTLEN];
780 if( BC_Resources::language[0] ) {
781 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
783 fp = fopen(msg_path, "r");
786 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
788 fp = fopen(msg_path, "r");
791 char text[BCTEXTLEN];
792 char *tp = text, *ep = tp + sizeof(text)-1;
793 char title[BCTEXTLEN];
798 char line[BCTEXTLEN], *cp = line;
799 if( fgets(line,sizeof(line)-1,fp) ) {
800 if( *cp == '#' ) continue;
801 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
804 if( tp > text && *--tp == '\n' ) *tp = 0;
806 int idx = plugins.size();
807 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
809 delete [] plugins[idx]->tip;
810 plugins[idx]->tip = cstrdup(text);
814 if( done > 0 ) break;
816 char *dp = strchr(cp, ':');
818 printf("plugin tips: error on line %d\n", no);
822 while( cp < dp ) *bp++ = *cp++;
827 while( *cp == ' ' || *cp == '\t' ) ++cp;
828 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
833 void MWindow::delete_plugins()
835 plugindb->remove_all_objects();
840 void MWindow::search_plugindb(int do_audio,
845 ArrayList<PluginServer*> &results)
848 for(int i = 0; i < MWindow::plugindb->total; i++)
850 PluginServer *current = MWindow::plugindb->get(i);
852 if(current->audio == do_audio &&
853 current->video == do_video &&
854 (current->realtime == is_realtime || is_realtime < 0) &&
855 current->transition == is_transition &&
856 current->theme == is_theme)
857 results.append(current);
860 // Alphabetize list by title
866 for(int i = 0; i < results.total - 1; i++)
868 PluginServer *value1 = results[i];
869 PluginServer *value2 = results[i + 1];
870 if(strcmp(_(value1->title), _(value2->title)) > 0)
874 results[i + 1] = value1;
880 PluginServer* MWindow::scan_plugindb(char *title,
885 // printf("MWindow::scan_plugindb data_type < 0\n");
889 for(int i = 0; i < plugindb->total; i++)
891 PluginServer *server = plugindb->get(i);
893 !strcasecmp(server->title, title) &&
895 (data_type == TRACK_AUDIO && server->audio) ||
896 (data_type == TRACK_VIDEO && server->video)))
897 return plugindb->get(i);
902 // repair session files with xlated plugin titles
903 void MWindow::fix_plugin_title(char *title)
905 for(int i = 0; i < plugindb->total; i++) {
906 PluginServer *server = plugindb->get(i);
907 if( !server->title ) continue;
908 const char *server_title = server->title;
909 if( !bstrcasecmp(title, _(server_title)) ) {
910 strcpy(title, server_title);
916 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
918 for( int i=0; i<plugins.size(); ++i )
919 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
923 int MWindow::plugin_exists(char *plugin_path)
925 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
928 void MWindow::remove_plugin_index()
930 char index_path[BCTEXTLEN];
931 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
932 ::remove(index_path);
935 void MWindow::init_preferences()
937 preferences = new Preferences;
938 preferences->load_defaults(defaults);
939 const char *lv2_path = getenv("LV2_PATH");
940 if( lv2_path && strcmp(lv2_path, preferences->lv2_path) ) {
941 strncpy(preferences->lv2_path, lv2_path, sizeof(preferences->lv2_path));
942 remove_plugin_index();
944 else if( !lv2_path && preferences->lv2_path[0] ) {
945 File::setenv_path("LV2_PATH",preferences->lv2_path, 0);
947 session = new MainSession(this);
948 session->load_defaults(defaults);
949 // set x11_host, screens, window_config
950 screens = session->set_default_x11_host();
951 BC_Signals::set_trap_hook(trap_hook, this);
952 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
953 BC_Signals::set_catch_intr(preferences->trap_sigintr);
954 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
955 BC_Trace::enable_locks();
958 BC_Trace::disable_locks();
960 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
961 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
962 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
963 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
966 void MWindow::clean_indexes()
971 int oldest_item = -1;
973 char string[BCTEXTLEN];
974 char string2[BCTEXTLEN];
976 // Delete extra indexes
977 fs.set_filter("*.idx");
978 fs.complete_path(preferences->index_directory);
979 fs.update(preferences->index_directory);
980 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
982 // Eliminate directories
987 for(int i = 0; i < fs.dir_list.total && !result; i++)
989 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
990 if(fs.is_dir(string))
992 delete fs.dir_list[i];
993 fs.dir_list.remove_number(i);
998 total_excess = fs.dir_list.total - preferences->index_count;
1000 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
1001 while(total_excess > 0)
1004 for(int i = 0; i < fs.dir_list.total; i++)
1006 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1008 if(i == 0 || fs.get_date(string) <= oldest)
1010 oldest = fs.get_date(string);
1015 if(oldest_item >= 0)
1017 // Remove index file
1018 fs.join_names(string,
1019 preferences->index_directory,
1020 fs.dir_list[oldest_item]->name);
1021 //printf("MWindow::clean_indexes 1 %s\n", string);
1023 perror("delete_indexes");
1024 delete fs.dir_list[oldest_item];
1025 fs.dir_list.remove_number(oldest_item);
1027 // Remove table of contents if it exists
1028 strcpy(string2, string);
1029 char *ptr = strrchr(string2, '.');
1032 //printf("MWindow::clean_indexes 2 %s\n", string2);
1033 sprintf(ptr, ".toc");
1035 sprintf(ptr, ".mkr");
1044 void MWindow::init_awindow()
1046 awindow = new AWindow(this);
1047 awindow->create_objects();
1050 void MWindow::init_gwindow()
1052 gwindow = new GWindow(this);
1053 gwindow->create_objects();
1056 void MWindow::init_tipwindow()
1058 TipWindow::load_tips(cin_lang);
1060 twindow = new TipWindow(this);
1064 void MWindow::show_warning(int *do_warning, const char *text)
1066 if( do_warning && !*do_warning ) return;
1068 wwindow = new WWindow(this);
1069 wwindow->show_warning(do_warning, text);
1072 int MWindow::wait_warning()
1074 return wwindow->wait_result();
1077 void MWindow::init_theme()
1082 PluginServer *theme_plugin = 0;
1083 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1084 if( plugindb->get(i)->theme &&
1085 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1086 theme_plugin = plugindb->get(i);
1090 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1091 preferences->theme);
1093 const char *default_theme = DEFAULT_THEME;
1094 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1095 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1097 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1098 if( plugindb->get(i)->theme &&
1099 !strcasecmp(default_theme, plugindb->get(i)->title) )
1100 theme_plugin = plugindb->get(i);
1105 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1109 PluginServer *plugin = new PluginServer(*theme_plugin);
1110 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1111 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1112 theme_plugin->title);
1116 theme = plugin->new_theme();
1117 theme->mwindow = this;
1118 strcpy(theme->path, plugin->path);
1121 // Load default images & settings
1122 theme->Theme::initialize();
1123 // Load user images & settings
1124 theme->initialize();
1125 // Create menus with user colors
1126 theme->build_menus();
1129 theme->sort_image_sets();
1130 theme->check_used();
1131 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1134 void MWindow::init_3d()
1136 playback_3d = new Playback3D(this);
1137 playback_3d->create_objects();
1140 void MWindow::init_edl()
1143 edl->create_objects();
1144 fill_preset_defaults(default_standard, edl->session);
1145 edl->load_defaults(defaults);
1146 edl->session->brender_start = edl->session->brender_end = 0;
1147 edl->create_default_tracks();
1148 edl->tracks->update_y_pixels(theme);
1151 void MWindow::init_compositor()
1153 cwindow = new CWindow(this);
1154 cwindow->create_objects();
1157 void MWindow::init_levelwindow()
1159 lwindow = new LevelWindow(this);
1160 lwindow->create_objects();
1163 VWindow *MWindow::get_viewer(int start_it, int idx)
1165 vwindows_lock->lock("MWindow::get_viewer");
1166 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1167 if( !vwindow ) idx = vwindows.size();
1168 while( !vwindow && --idx >= 0 ) {
1169 VWindow *vwin = vwindows[idx];
1170 if( !vwin->is_running() || !vwin->get_edl() )
1174 vwindow = new VWindow(this);
1175 vwindow->load_defaults();
1176 vwindow->create_objects();
1177 vwindows.append(vwindow);
1179 vwindows_lock->unlock();
1180 if( start_it ) vwindow->start();
1184 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1186 zwindows_lock->lock("MWindow::get_mixer");
1187 if( !mixer ) mixer = edl->mixers.new_mixer();
1188 ZWindow *zwindow = 0;
1189 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1190 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1192 zwindows.append(zwindow = new ZWindow(this));
1193 zwindow->idx = mixer->idx;
1194 zwindows_lock->unlock();
1198 void MWindow::del_mixer(ZWindow *zwindow)
1200 zwindows_lock->lock("MWindow::del_mixer 0");
1201 edl->mixers.del_mixer(zwindow->idx);
1202 if( session->selected_zwindow >= 0 ) {
1203 int i = zwindows.number_of(zwindow);
1204 if( i >= 0 && i < session->selected_zwindow )
1205 --session->selected_zwindow;
1206 else if( i == session->selected_zwindow )
1207 session->selected_zwindow = -1;
1209 zwindows_lock->unlock();
1210 gui->lock_window("MWindow::del_mixer 1");
1211 gui->update_mixers(0, -1);
1212 gui->unlock_window();
1215 void MWindow::start_mixer()
1218 ZWindow *zwindow = get_mixer(mixer);
1219 const char *title = 0;
1221 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1222 PatchGUI *patchgui = get_patchgui(track);
1223 if( !patchgui || !patchgui->mixer ) continue;
1224 mixer->mixer_ids.append(track->get_mixer_id());
1225 if( !title ) title = track->title;
1228 session->selected_zwindow = -1;
1229 gui->lock_window("MWindow::start_mixer");
1230 gui->update_mixers(0, 0);
1231 gui->unlock_window();
1233 zwindow->set_title(title);
1238 int MWindow::mixer_track_active(Track *track)
1240 int i = session->selected_zwindow;
1241 if( i < 0 || i >= zwindows.size() ) return 0;
1242 ZWindow *zwindow = zwindows[i];
1243 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1244 if( !mixer ) return 0;
1245 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1246 return n >= 0 ? 1 : 0;
1249 void MWindow::update_mixer_tracks()
1251 zwindows_lock->lock("MixPatch::handle_event");
1252 int i = session->selected_zwindow;
1253 if( i >= 0 && i < zwindows.size() ) {
1254 ZWindow *zwindow = zwindows[i];
1255 zwindow->update_mixer_ids();
1257 zwindows_lock->unlock();
1260 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1261 int use_inout, int toggle_audio, int loop_play, float speed)
1263 zwindows_lock->lock("MWindow::handle_mixers");
1264 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1265 ZWindow *zwindow = zwindows[vidx];
1266 if( zwindow->idx < 0 ) continue;
1267 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1268 if( !mixer || !mixer->mixer_ids.size() ) continue;
1270 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1271 if( track->data_type != TRACK_VIDEO ) continue;
1272 int mixer_id = track->get_mixer_id();
1273 k = mixer->mixer_ids.size();
1274 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1276 if( k < 0 ) continue;
1277 EDL *mixer_edl = new EDL(this->edl);
1278 mixer_edl->create_objects();
1279 mixer_edl->copy_all(edl);
1280 mixer_edl->remove_vwindow_edls();
1281 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1282 k = mixer->mixer_ids.size();
1283 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1286 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1289 track->record = track->play = 0;
1291 zwindow->change_source(mixer_edl);
1292 zwindow->handle_mixer(command, 0,
1293 use_inout, toggle_audio, loop_play, speed);
1295 zwindows_lock->unlock();
1298 void MWindow::refresh_mixers(int dir)
1300 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1301 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1304 void MWindow::stop_mixers()
1306 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1307 ZWindow *zwindow = zwindows[vidx];
1308 if( zwindow->idx < 0 ) continue;
1309 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1313 void MWindow::close_mixers(int destroy)
1315 ArrayList<ZWindow*> closed;
1316 zwindows_lock->lock("MWindow::close_mixers");
1317 for( int i=zwindows.size(); --i>=0; ) {
1318 ZWindow *zwindow = zwindows[i];
1319 if( zwindow->idx < 0 ) continue;
1320 zwindow->destroy = destroy;
1321 ZWindowGUI *zgui = zwindow->zgui;
1322 zgui->lock_window("MWindow::select_zwindow 0");
1324 zgui->unlock_window();
1325 closed.append(zwindow);
1327 zwindows_lock->unlock();
1328 for( int i=0; i<closed.size(); ++i ) {
1329 ZWindow *zwindow = closed[i];
1334 ZWindow *MWindow::create_mixer(Indexable *indexable)
1336 ArrayList<Indexable*> new_assets;
1337 new_assets.append(indexable);
1338 Track *track = edl->tracks->last;
1339 load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
1340 track = !track ? edl->tracks->first : track->next;
1342 ZWindow *zwindow = get_mixer(mixer);
1344 track->play = track->record = 0;
1345 if( track->data_type == TRACK_VIDEO ) {
1346 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1348 mixer->mixer_ids.append(track->get_mixer_id());
1349 track = track->next;
1351 if( indexable->is_asset ) {
1352 char *path = indexable->path;
1353 char *tp = strrchr(path, '/');
1354 if( !tp ) tp = path; else ++tp;
1355 zwindow->set_title(tp);
1358 char *title = ((EDL*)indexable)->local_session->clip_title;
1359 zwindow->set_title(title);
1364 void MWindow::create_mixers()
1366 if( !session->drag_assets->size() &&
1367 !session->drag_clips->size() ) return;
1371 ArrayList<ZWindow *>new_mixers;
1373 for( int i=0; i<session->drag_assets->size(); ++i ) {
1374 Indexable *indexable = session->drag_assets->get(i);
1375 if( !indexable->have_video() ) continue;
1376 ZWindow *zwindow = create_mixer(indexable);
1377 new_mixers.append(zwindow);
1379 for( int i=0; i<session->drag_clips->size(); ++i ) {
1380 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1381 if( !indexable->have_video() ) continue;
1382 ZWindow *zwindow = create_mixer(indexable);
1383 new_mixers.append(zwindow);
1387 for( int i=0; i<new_mixers.size(); ++i )
1388 new_mixers[i]->start();
1392 undo_after(_("create mixers"), LOAD_ALL);
1394 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1395 sync_parameters(CHANGE_ALL);
1398 void MWindow::open_mixers()
1400 for( int i=0; i<edl->mixers.size(); ++i ) {
1401 Mixer *mixer = edl->mixers[i];
1402 ZWindow *zwindow = get_mixer(mixer);
1403 zwindow->set_title(mixer->title);
1409 int MWindow::select_zwindow(ZWindow *zwindow)
1411 int ret = 0, n = zwindows.number_of(zwindow);
1412 if( session->selected_zwindow != n ) {
1413 session->selected_zwindow = n;
1414 for( int i=0; i<zwindows.size(); ++i ) {
1415 ZWindow *zwindow = zwindows[i];
1416 if( zwindow->idx < 0 ) continue;
1417 ZWindowGUI *zgui = zwindow->zgui;
1418 zgui->lock_window("MWindow::select_zwindow 0");
1419 zwindow->highlighted = i == n ? 1 : 0;
1420 if( zgui->draw_overlays() )
1421 zgui->canvas->get_canvas()->flash(1);
1422 zgui->unlock_window();
1425 gui->lock_window("MWindow::select_window 1");
1426 gui->update_mixers(0, -1);
1427 gui->unlock_window();
1432 void MWindow::tile_mixers()
1435 for( int i=0; i<zwindows.size(); ++i ) {
1436 ZWindow *zwindow = zwindows[i];
1437 if( zwindow->idx < 0 ) continue;
1441 int zn = ceil(sqrt(nz));
1442 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1443 int y1 = 1, y2 = gui->get_y();
1444 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1445 if( x1 < 0 ) x1 = 0;
1446 if( y1 < 0 ) y1 = 0;
1447 if( x2 > rw ) x2 = rw;
1448 if( y2 > rh ) y2 = rh;
1449 int dx = x2 - x1, dy = y2 - y1;
1451 int lt = BC_DisplayInfo::get_left_border();
1452 int top = BC_DisplayInfo::get_top_border();
1453 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1454 int bh = top + BC_DisplayInfo::get_bottom_border();
1455 int zx = 0, zy = 0; // window origins
1456 int mw = 10+10, mh = 10+10; // canvas margins
1457 int rsz = 0, n = 0, dz = 0;
1458 int ow = edl->session->output_w, oh = edl->session->output_h;
1459 for( int i=0; i<zwindows.size(); ++i ) {
1460 ZWindow *zwindow = zwindows[i];
1461 if( zwindow->idx < 0 ) continue;
1462 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1463 if( rsz < hh ) rsz = hh;
1464 int xx = zx + x1, yy = zy + y1;
1465 int mx = x2 - zw, my = y2 - zh;
1466 if( xx > mx ) xx = mx;
1467 if( yy > my ) yy = my;
1468 xx += lt + dz; yy += top + dz;
1469 zwindow->reposition(xx,yy, ww,hh);
1470 if( zwindow->running() ) {
1471 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1472 gui->lock_window("MWindow::tile_mixers");
1473 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1474 gui->unlock_window();
1478 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1487 void MWindow::init_cache()
1489 audio_cache = new CICache(preferences);
1490 video_cache = new CICache(preferences);
1491 frame_cache = new FrameCache;
1492 wave_cache = new WaveCache;
1495 void MWindow::init_channeldb()
1497 channeldb_buz->load("channeldb_buz");
1498 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1501 void MWindow::init_menus()
1503 char string[BCTEXTLEN];
1506 BC_CModels::to_text(string, BC_RGB888);
1507 colormodels.append(new ColormodelItem(string, BC_RGB888));
1508 BC_CModels::to_text(string, BC_RGBA8888);
1509 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1510 // BC_CModels::to_text(string, BC_RGB161616);
1511 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1512 // BC_CModels::to_text(string, BC_RGBA16161616);
1513 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1514 BC_CModels::to_text(string, BC_RGB_FLOAT);
1515 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1516 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1517 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1518 BC_CModels::to_text(string, BC_YUV888);
1519 colormodels.append(new ColormodelItem(string, BC_YUV888));
1520 BC_CModels::to_text(string, BC_YUVA8888);
1521 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1522 // BC_CModels::to_text(string, BC_YUV161616);
1523 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1524 // BC_CModels::to_text(string, BC_YUVA16161616);
1525 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1527 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1528 interlace_project_modes.append(new InterlacemodeItem(string, x));
1530 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1531 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1533 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1534 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1536 // Interlacing Modes
1537 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1539 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1540 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1542 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1543 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1545 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1546 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1548 // Interlacing Fixing Methods
1549 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1550 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1551 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1554 void MWindow::init_indexes()
1556 mainindexes = new MainIndexes(this);
1557 mainindexes->start_loop();
1560 void MWindow::init_gui()
1562 gui = new MWindowGUI(this);
1563 gui->create_objects();
1564 gui->load_defaults(defaults);
1567 void MWindow::init_signals()
1569 sighandler = new SigHandler;
1570 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1574 void MWindow::init_render()
1576 render = new Render(this);
1577 create_bd = new CreateBD_Thread(this);
1578 create_dvd = new CreateDVD_Thread(this);
1579 batch_render = new BatchRenderThread(this);
1582 void MWindow::init_exportedl()
1584 exportedl = new ExportEDL(this);
1587 void MWindow::init_shuttle()
1590 int ret = Shuttle::probe();
1592 shuttle = new Shuttle(this);
1593 if( shuttle->read_config_file() > 0 ) {
1594 printf("shuttle: bad config file\n");
1595 delete shuttle; shuttle = 0;
1598 shuttle->start(ret);
1603 void MWindow::init_brender()
1605 if(preferences->use_brender && !brender)
1607 brender_lock->lock("MWindow::init_brender 1");
1608 brender = new BRender(this);
1609 brender->initialize();
1610 session->brender_end = 0;
1611 brender_lock->unlock();
1614 if(!preferences->use_brender && brender)
1616 brender_lock->lock("MWindow::init_brender 2");
1619 session->brender_end = 0;
1620 brender_lock->unlock();
1626 void MWindow::restart_brender()
1628 //printf("MWindow::restart_brender 1\n");
1629 if( !brender_active || !preferences->use_brender ) return;
1630 if( !brender ) return;
1631 brender->restart(edl);
1634 void MWindow::stop_brender()
1636 if( !brender ) return;
1637 // cannot be holding mwindow->gui display lock
1641 int MWindow::brender_available(int position)
1644 brender_lock->lock("MWindow::brender_available 1");
1645 if(brender && brender_active)
1647 if(brender->map_valid)
1649 brender->map_lock->lock("MWindow::brender_available 2");
1650 if(position < brender->map_size &&
1653 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1654 if(brender->map[position] == BRender::RENDERED)
1657 brender->map_lock->unlock();
1660 brender_lock->unlock();
1664 void MWindow::set_brender_active(int v, int update)
1666 if( !preferences->use_brender ) v = 0;
1668 gui->mainmenu->brender_active->set_checked(v);
1670 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1671 edl->session->brender_end = edl->local_session->get_selectionend(1);
1673 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1674 edl->session->brender_end = edl->tracks->total_video_length();
1679 edl->session->brender_start = edl->session->brender_end = 0;
1680 gui->unlock_window();
1682 gui->lock_window("MWindow::set_brender_active");
1685 gui->update_timebar(0);
1686 gui->draw_overlays(1);
1690 int MWindow::has_commercials()
1692 #ifdef HAVE_COMMERCIAL
1693 return theme->use_commercials;
1699 void MWindow::init_commercials()
1701 #ifdef HAVE_COMMERCIAL
1702 if( !commercials ) {
1703 commercials = new Commercials(this);
1704 commercial_active = 0;
1707 commercials->add_user();
1711 void MWindow::commit_commercial()
1713 #ifdef HAVE_COMMERCIAL
1714 if( !commercial_active ) return;
1715 commercial_active = 0;
1716 if( !commercials ) return;
1717 commercials->commitDb();
1721 void MWindow::undo_commercial()
1723 #ifdef HAVE_COMMERCIAL
1724 if( !commercial_active ) return;
1725 commercial_active = 0;
1726 if( !commercials ) return;
1727 commercials->undoDb();
1731 int MWindow::put_commercial()
1734 #ifdef HAVE_COMMERCIAL
1735 double start = edl->local_session->get_selectionstart();
1736 double end = edl->local_session->get_selectionend();
1737 if( start >= end ) return 0;
1739 const char *errmsg = 0;
1741 Tracks *tracks = edl->tracks;
1743 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1744 if( track->data_type != TRACK_VIDEO ) continue;
1745 if( !track->record ) continue;
1746 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1748 int64_t units_start = track->to_units(start,0);
1749 int64_t units_end = track->to_units(end,0);
1750 Edits *edits = track->edits;
1751 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1752 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1753 if(!edit1 && !edit2) continue; // nothing selected
1754 if(!edit2) { // edit2 beyond end of track
1755 edit2 = edits->last;
1756 units_end = edits->length();
1758 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1759 Indexable *indexable = edit1->get_source();
1760 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1763 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1764 if( track->data_type != TRACK_VIDEO ) continue;
1765 if( !track->record ) continue;
1766 int64_t units_start = track->to_units(start,0);
1767 int64_t units_end = track->to_units(end,0);
1768 Edits *edits = track->edits;
1769 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1770 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1771 if(!edit1 && !edit2) continue; // nothing selected
1772 if(!edit2) { // edit2 beyond end of track
1773 edit2 = edits->last;
1774 units_end = edits->length();
1776 Indexable *indexable = edit1->get_source();
1777 Asset *asset = (Asset *)indexable;
1778 File *file = video_cache->check_out(asset, edl);
1779 if( !file ) { errmsg = _("no file"); break; }
1780 int64_t edit_length = units_end - units_start;
1781 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1782 result = commercials->put_clip(file, edit1->channel,
1783 track->from_units(edit_start), track->from_units(edit_length));
1784 video_cache->check_in(asset);
1785 if( result ) { errmsg = _("db failed"); break; }
1788 char string[BCTEXTLEN];
1789 sprintf(string, _("put_commercial: %s"), errmsg);
1790 MainError::show_error(string);
1798 void MWindow::stop_playback(int wait)
1800 gui->stop_drawing();
1802 cwindow->stop_playback(wait);
1804 for(int i = 0; i < vwindows.size(); i++) {
1805 VWindow *vwindow = vwindows[i];
1806 if( !vwindow->is_running() ) continue;
1807 vwindow->stop_playback(wait);
1809 for(int i = 0; i < zwindows.size(); i++) {
1810 ZWindow *zwindow = zwindows[i];
1811 if( zwindow->idx < 0 ) continue;
1812 zwindow->stop_playback(wait);
1816 void MWindow::stop_transport()
1818 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1821 void MWindow::undo_before(const char *description, void *creator)
1823 undo->update_undo_before(description, creator);
1826 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
1828 undo->update_undo_after(description, load_flags, changes_made);
1831 void MWindow::beep(double freq, double secs, double gain)
1833 if( !proxy_beep ) proxy_beep = new ProxyBeep(this);
1834 proxy_beep->tone(freq, secs, gain);
1837 int MWindow::load_filenames(ArrayList<char*> *filenames,
1839 int update_filename)
1841 ArrayList<EDL*> new_edls;
1842 ArrayList<Asset*> new_assets;
1843 ArrayList<File*> new_files;
1844 const int debug = 0;
1845 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1848 gui->start_hourglass();
1850 // Need to stop playback since tracking depends on the EDL not getting
1852 gui->unlock_window();
1854 gui->lock_window("MWindow::load_filenames 0");
1856 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1860 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1862 // Define new_edls and new_assets to load
1863 int result = 0, ftype = -1;
1865 for( int i=0; i<filenames->size(); ++i ) {
1867 File *new_file = new File;
1868 Asset *new_asset = new Asset(filenames->get(i));
1869 EDL *new_edl = new EDL;
1870 char string[BCTEXTLEN];
1872 new_edl->create_objects();
1873 new_edl->copy_session(edl, -1);
1874 new_file->set_program(edl->session->program_no);
1876 sprintf(string, _("Loading %s"), new_asset->path);
1877 gui->show_message(string);
1878 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1880 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1881 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1885 // Convert media file to EDL
1887 // Warn about odd image dimensions
1888 if( new_asset->video_data &&
1889 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1890 char string[BCTEXTLEN];
1891 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1892 new_asset->path, new_asset->width, new_asset->height);
1893 MainError::show_error(string);
1896 if( new_asset->program >= 0 &&
1897 edl->session->program_no != new_asset->program ) {
1898 char string[BCTEXTLEN];
1899 sprintf(string, _("%s's index was built for program number %d\n"
1900 "Playback preference is %d.\n Using program %d."),
1901 new_asset->path, new_asset->program,
1902 edl->session->program_no, new_asset->program);
1903 MainError::show_error(string);
1906 if( load_mode != LOADMODE_RESOURCESONLY ) {
1907 RecordLabels *labels = edl->session->label_cells ?
1908 new RecordLabels(new_file) : 0;
1909 asset_to_edl(new_edl, new_asset, labels);
1910 new_edls.append(new_edl);
1911 new_edl->add_user();
1915 new_assets.append(new_asset);
1916 new_asset->add_user();
1919 // Set filename to nothing for assets since save EDL would overwrite them.
1920 if( load_mode == LOADMODE_REPLACE ||
1921 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1923 // Reset timeline position
1924 for( int i=0; i<TOTAL_PANES; ++i ) {
1925 new_edl->local_session->view_start[i] = 0;
1926 new_edl->local_session->track_start[i] = 0;
1934 case FILE_NOT_FOUND:
1935 sprintf(string, _("Failed to open %s"), new_asset->path);
1936 gui->show_message(string, theme->message_error);
1937 gui->update_default_message();
1941 case FILE_UNRECOGNIZED_CODEC: {
1943 { IndexFile indexfile(this, new_asset);
1944 if( !(result = indexfile.open_index()) )
1945 indexfile.close_index(); }
1947 // Test existing EDLs
1948 for( int j=0; result && j<new_edls.total; ++j ) {
1949 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1951 new_asset->copy_from(old_asset,1);
1956 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1958 new_asset->copy_from(old_asset,1);
1965 char string[BCTEXTLEN];
1967 fs.extract_name(string, new_asset->path);
1969 strcat(string, _("'s format couldn't be determined."));
1970 new_asset->audio_data = 1;
1971 new_asset->format = FILE_PCM;
1972 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1973 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1974 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1975 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1976 new_asset->signed_ = defaults->get("SIGNED_", 1);
1977 new_asset->header = defaults->get("HEADER", 0);
1979 FileFormat fwindow(this);
1980 fwindow.create_objects(new_asset, string);
1981 result = fwindow.run_window();
1983 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1984 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1985 defaults->update("AUDIO_BITS", new_asset->bits);
1986 defaults->update("BYTE_ORDER", new_asset->byte_order);
1987 defaults->update("SIGNED_", new_asset->signed_);
1988 defaults->update("HEADER", new_asset->header);
1994 // Recalculate length
1996 new_file = new File;
1997 result = new_file->open_file(preferences, new_asset, 1, 0);
1999 if( load_mode != LOADMODE_RESOURCESONLY ) {
2000 RecordLabels *labels = edl->session->label_cells ?
2001 new RecordLabels(new_file) : 0;
2002 asset_to_edl(new_edl, new_asset, labels);
2003 new_edls.append(new_edl);
2004 new_edl->add_user();
2008 new_assets.append(new_asset);
2009 new_asset->add_user();
2019 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2020 xml_file.read_from_file(filenames->get(i));
2021 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2022 const char *cin_version = 0;
2023 while( !xml_file.read_tag() ) {
2024 if( xml_file.tag.title_is("EDL") ) {
2025 cin_version = xml_file.tag.get_property("VERSION");
2030 if( !cin_version ) {
2031 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
2032 char string[BCTEXTLEN];
2033 sprintf(string,_("Unknown %s"), filenames->get(i));
2034 gui->show_message(string);
2038 if( strcmp(cin_version, CINELERRA_VERSION) &&
2039 strcmp(cin_version, "Unify") &&
2040 strcmp(cin_version, "5.1") ) {
2041 char string[BCTEXTLEN];
2042 snprintf(string, sizeof(string),
2043 _("Warning: XML from cinelerra version %s\n"
2044 "Session data may be incompatible."), cin_version);
2045 show_warning(&preferences->warn_version, string);
2047 if( load_mode == LOADMODE_NESTED ) {
2048 // Load temporary EDL for nesting.
2049 EDL *nested_edl = new EDL;
2050 nested_edl->create_objects();
2051 nested_edl->load_xml(&xml_file, LOAD_ALL);
2052 int groups = nested_edl->regroup(session->group_number);
2053 session->group_number += groups;
2054 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
2055 new_edl->create_nested(nested_edl);
2056 new_edl->set_path(filenames->get(i));
2057 nested_edl->Garbage::remove_user();
2060 // Load EDL for pasting
2061 new_edl->load_xml(&xml_file, LOAD_ALL);
2062 int groups = new_edl->regroup(session->group_number);
2063 session->group_number += groups;
2064 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2065 test_plugins(new_edl, filenames->get(i));
2066 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2068 if( load_mode == LOADMODE_REPLACE ||
2069 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2070 strcpy(session->filename, filenames->get(i));
2071 strcpy(new_edl->local_session->clip_title,
2074 set_filename(new_edl->local_session->clip_title);
2076 else if( load_mode == LOADMODE_RESOURCESONLY ) {
2077 strcpy(new_edl->local_session->clip_title,
2080 time_t t = !stat(filenames->get(i),&st) ?
2081 st.st_mtime : time(&t);
2082 ctime_r(&t, new_edl->local_session->clip_notes);
2086 new_edls.append(new_edl);
2087 new_edl->add_user();
2092 new_edl->Garbage::remove_user();
2093 new_asset->Garbage::remove_user();
2095 // Store for testing index
2096 new_files.append(new_file);
2099 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2103 gui->reset_default_message();
2104 gui->default_message();
2108 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2111 // Don't back up here.
2114 // For pasting, clear the active region
2115 if(load_mode == LOADMODE_PASTE ||
2116 load_mode == LOADMODE_NESTED)
2118 double start = edl->local_session->get_selectionstart();
2119 double end = edl->local_session->get_selectionend();
2120 if(!EQUIV(start, end))
2123 edl->session->labels_follow_edits,
2124 edl->session->plugins_follow_edits,
2125 edl->session->autos_follow_edits);
2128 paste_edls(&new_edls, load_mode, 0, -1,
2129 edl->session->labels_follow_edits,
2130 edl->session->plugins_follow_edits,
2131 edl->session->autos_follow_edits,
2138 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2140 // Add new assets to EDL and schedule assets for index building.
2141 int got_indexes = 0;
2142 for( int i=0; i<new_edls.size(); ++i ) {
2143 EDL *new_edl = new_edls[i];
2144 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2145 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2146 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2152 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2153 for( int i=0; i<new_assets.size(); ++i ) {
2154 Asset *new_asset = new_assets[i];
2158 for( int j=0; j<new_files.size(); ++j ) {
2159 new_file = new_files[j];
2160 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2166 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2167 edl->assets->update(new_asset);
2170 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2172 // Start examining next batch of index files
2173 if(got_indexes) mainindexes->start_build();
2174 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2177 Track *track = edl->tracks->first;
2180 for(int j = 0; j < track->plugin_set.size(); j++)
2182 PluginSet *plugins = track->plugin_set[j];
2183 Plugin *plugin = plugins->get_first_plugin();
2187 if(load_mode == LOADMODE_REPLACE ||
2188 load_mode == LOADMODE_REPLACE_CONCATENATE)
2190 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2193 show_plugin(plugin);
2197 plugin = (Plugin*)plugin->next;
2201 track = track->next;
2204 // if just opening one new resource in replace mode
2205 if( ftype != FILE_IS_XML &&
2206 ( load_mode == LOADMODE_REPLACE ||
2207 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2209 edl->session->proxy_scale = 1;
2210 edl->session->proxy_disabled_scale = 1;
2211 edl->session->proxy_use_scaler = 0;
2212 edl->session->proxy_auto_scale = 0;
2213 edl->session->proxy_beep = 0;
2214 edl->local_session->preview_start = 0;
2215 edl->local_session->preview_end = -1;
2216 edl->local_session->loop_playback = 0;
2217 edl->local_session->set_selectionstart(0);
2218 edl->local_session->set_selectionend(0);
2219 set_brender_active(0, 0);
2224 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2225 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2226 ArrayList<Indexable *> orig_idxbls;
2227 for( int i=0; i<new_assets.size(); ++i )
2228 orig_idxbls.append(new_assets.get(i));
2229 for( int i=0; i<new_edls.size(); ++i ) {
2230 EDL *new_edl = new_edls[i];
2231 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2232 if( track->data_type != TRACK_VIDEO ) continue;
2233 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2234 Indexable *idxbl = (Indexable *)edit->asset;
2235 if( !idxbl ) continue;
2236 if( !idxbl->have_video() ) continue;
2237 if( edit->channel != 0 ) continue; // first layer only
2238 orig_idxbls.append(edit->asset);
2242 gui->unlock_window(); // to update progress bar
2243 int ret = render_proxy(orig_idxbls);
2244 gui->lock_window("MWindow::load_filenames");
2245 if( ret >= 0 && edl->session->proxy_beep ) {
2247 beep(2000., 1.5, 0.5);
2249 beep(4000., 0.25, 0.5);
2253 // need to update undo before project, since mwindow is unlocked & a new load
2254 // can begin here. Should really prevent loading until we're done.
2255 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2256 undo_after(_("load"), LOAD_ALL);
2258 for(int i = 0; i < new_edls.size(); i++)
2260 new_edls[i]->remove_user();
2262 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2264 new_edls.remove_all();
2266 for(int i = 0; i < new_assets.size(); i++)
2268 new_assets[i]->Garbage::remove_user();
2271 new_assets.remove_all();
2272 new_files.remove_all_objects();
2275 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2276 if(load_mode == LOADMODE_REPLACE ||
2277 load_mode == LOADMODE_REPLACE_CONCATENATE)
2279 session->changes_made = 0;
2283 session->changes_made = 1;
2286 gui->stop_hourglass();
2289 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2290 update_project(load_mode);
2292 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2297 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2299 Asset *format_asset = new Asset;
2300 format_asset->format = FILE_FFMPEG;
2301 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2302 ProxyRender proxy_render(this, format_asset);
2303 int new_scale = edl->session->proxy_scale;
2304 int use_scaler = edl->session->proxy_use_scaler;
2306 for( int i=0; i<new_idxbls.size(); ++i ) {
2307 Indexable *orig = new_idxbls.get(i);
2308 Asset *proxy = proxy_render.add_original(orig, new_scale);
2309 if( !proxy ) continue;
2311 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2312 int got_it = exists && // if proxy exists, and is newer than orig
2313 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2314 if( got_it ) continue;
2315 proxy_render.add_needed(orig, proxy);
2318 // render needed proxies
2319 int result = proxy_render.create_needed_proxies(new_scale);
2321 add_proxy(use_scaler,
2322 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2324 format_asset->remove_user();
2325 return !result ? proxy_render.needed_proxies.size() : -1;
2328 int MWindow::enable_proxy()
2331 if( edl->session->proxy_scale == 1 &&
2332 edl->session->proxy_disabled_scale != 1 ) {
2333 int new_scale = edl->session->proxy_disabled_scale;
2334 int new_use_scaler = edl->session->proxy_use_scaler;
2335 edl->session->proxy_disabled_scale = 1;
2336 Asset *asset = new Asset;
2337 asset->format = FILE_FFMPEG;
2338 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2339 ret = to_proxy(asset, new_scale, new_use_scaler);
2340 asset->remove_user();
2342 beep(2000., 1.5, 0.5);
2347 int MWindow::disable_proxy()
2349 if( edl->session->proxy_scale != 1 &&
2350 edl->session->proxy_disabled_scale == 1 ) {
2352 int new_use_scaler = edl->session->proxy_use_scaler;
2353 edl->session->proxy_disabled_scale = edl->session->proxy_scale;
2354 Asset *asset = new Asset;
2355 asset->format = FILE_FFMPEG;
2356 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2357 to_proxy(asset, new_scale, new_use_scaler);
2358 asset->remove_user();
2363 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2365 ArrayList<Indexable*> orig_idxbls;
2366 ArrayList<Indexable*> proxy_assets;
2368 edl->Garbage::add_user();
2370 undo_before(_("proxy"), this);
2371 ProxyRender proxy_render(this, asset);
2373 // revert project to original size from current size
2374 // remove all session proxy assets at the at the current proxy_scale
2375 int proxy_scale = edl->session->proxy_scale;
2377 if( proxy_scale > 1 ) {
2378 Asset *orig_asset = edl->assets->first;
2379 for( ; orig_asset; orig_asset=orig_asset->next ) {
2380 char new_path[BCTEXTLEN];
2381 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2382 // test if proxy asset was already added to proxy_assets
2384 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2385 got_it = !strcmp(proxy_assets[i]->path, new_path);
2386 if( got_it ) continue;
2387 Asset *proxy_asset = edl->assets->get_asset(new_path);
2388 if( !proxy_asset ) continue;
2389 // add pointer to existing EDL asset if it exists
2390 // EDL won't delete it unless it's the same pointer.
2391 proxy_assets.append(proxy_asset);
2392 proxy_asset->add_user();
2393 orig_idxbls.append(orig_asset);
2394 orig_asset->add_user();
2396 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2397 EDL *orig_nested = edl->nested_edls[i];
2398 char new_path[BCTEXTLEN];
2399 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2401 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2402 // test if proxy asset was already added to proxy_assets
2404 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2405 got_it = !strcmp(proxy_assets[i]->path, new_path);
2406 if( got_it ) continue;
2407 Asset *proxy_nested = edl->assets->get_asset(new_path);
2408 if( !proxy_nested ) continue;
2409 // add pointer to existing EDL asset if it exists
2410 // EDL won't delete it unless it's the same pointer.
2411 proxy_assets.append(proxy_nested);
2412 proxy_nested->add_user();
2413 orig_idxbls.append(orig_nested);
2414 orig_nested->add_user();
2417 // convert from the proxy assets to the original assets
2418 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2420 // remove the references
2421 for( int i=0; i<proxy_assets.size(); ++i ) {
2422 Asset *proxy = (Asset *) proxy_assets[i];
2423 proxy->width = proxy->actual_width;
2424 proxy->height = proxy->actual_height;
2425 proxy->remove_user();
2426 edl->assets->remove_pointer(proxy);
2427 proxy->remove_user();
2429 proxy_assets.remove_all();
2430 for( int i = 0; i < orig_idxbls.size(); i++ )
2431 orig_idxbls[i]->remove_user();
2432 orig_idxbls.remove_all();
2435 ArrayList<char *> confirm_paths; // test for new files
2436 confirm_paths.set_array_delete();
2438 // convert to new size if not original size
2439 if( new_scale != 1 ) {
2441 Asset *orig = edl->assets->first;
2442 for( ; orig; orig=orig->next ) {
2443 Asset *proxy = proxy_render.add_original(orig, new_scale);
2444 if( !proxy ) continue;
2445 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2446 int got_it = exists && // if proxy exists, and is newer than orig
2447 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2449 if( exists ) // prompt user to overwrite
2450 confirm_paths.append(cstrdup(proxy->path));
2451 proxy_render.add_needed(orig, proxy);
2454 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2455 EDL *orig_nested = edl->nested_edls[i];
2456 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2457 if( !proxy ) continue;
2458 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2459 int got_it = exists && // if proxy exists, and is newer than orig_nested
2460 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2462 if( exists ) // prompt user to overwrite
2463 confirm_paths.append(cstrdup(proxy->path));
2464 proxy_render.add_needed(orig_nested, proxy);
2470 // test for existing files
2471 if( confirm_paths.size() ) {
2472 result = ConfirmSave::test_files(this, &confirm_paths);
2473 confirm_paths.remove_all_objects();
2477 result = proxy_render.create_needed_proxies(new_scale);
2479 if( !result ) // resize project
2480 edl->set_proxy(new_scale, new_use_scaler,
2481 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2483 undo_after(_("proxy"), LOAD_ALL);
2484 edl->Garbage::remove_user();
2487 gui->lock_window("MWindow::to_proxy");
2488 update_project(LOADMODE_REPLACE);
2489 gui->unlock_window();
2491 return !result ? proxy_render.needed_proxies.size() : -1;
2494 void MWindow::test_plugins(EDL *new_edl, char *path)
2496 char string[BCTEXTLEN];
2498 // Do a check whether plugins exist
2499 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2500 for( int k=0; k<track->plugin_set.total; ++k ) {
2501 PluginSet *plugin_set = track->plugin_set[k];
2502 for( Plugin *plugin = (Plugin*)plugin_set->first;
2503 plugin; plugin = (Plugin*)plugin->next ) {
2504 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2505 // ok we need to find it in plugindb
2506 PluginServer *server =
2507 scan_plugindb(plugin->title, track->data_type);
2508 if( !server || server->transition ) {
2510 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2511 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2512 "effect", _(plugin->title), path);
2513 MainError::show_error(string);
2518 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2519 if( !edit->transition ) continue;
2520 // ok we need to find transition in plugindb
2521 PluginServer *server =
2522 scan_plugindb(edit->transition->title, track->data_type);
2523 if( !server || !server->transition ) {
2525 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2526 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2527 "transition", _(edit->transition->title), path);
2528 MainError::show_error(string);
2535 void MWindow::init_shm(const char *pfn, int64_t min)
2538 // Fix shared memory
2539 FILE *fd = fopen(pfn, "r");
2541 fscanf(fd, "%jd", &result);
2543 if( result >= min ) return;
2546 fd = fopen(pfn, "w");
2548 fprintf(fd, "0x%jx", min);
2551 fd = fopen(pfn, "r");
2553 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2557 fscanf(fd, "%jd", &result);
2559 if( result < min ) {
2560 eprintf(_("MWindow::init_shm: %s is %p.\n"
2561 "you probably need to be root, or:\n"
2562 "as root, run: echo 0x%jx > %s\n"
2563 "before trying to start cinelerra.\n"
2564 "It should be at least 0x%jx for Cinelerra.\n"),
2565 pfn, (void *)result, min, pfn, min);
2569 void MWindow::create_objects(int want_gui,
2573 const int debug = 0;
2574 if(debug) PRINT_TRACE
2576 // For some reason, init_signals must come after show_splash or the signals won't
2579 if(debug) PRINT_TRACE
2582 if(debug) PRINT_TRACE
2585 if(debug) PRINT_TRACE
2586 default_standard = default_std();
2587 init_defaults(defaults, config_path);
2591 splash_window->update_status(_("Initializing Plugins"));
2592 init_plugins(this, preferences);
2593 if(debug) PRINT_TRACE
2594 init_ladspa_plugins(this, preferences);
2595 if(debug) PRINT_TRACE
2596 init_plugin_tips(*plugindb, cin_lang);
2598 splash_window->update_status(_("Initializing GUI"));
2599 if(debug) PRINT_TRACE
2602 if(debug) PRINT_TRACE
2606 splash_window->update_status(_("Initializing Fonts"));
2607 char string[BCTEXTLEN];
2608 strcpy(string, preferences->plugin_dir);
2609 strcat(string, "/" FONT_SEARCHPATH);
2610 BC_Resources::init_fontconfig(string);
2611 if(debug) PRINT_TRACE
2613 // Default project created here
2615 if(debug) PRINT_TRACE
2618 if(debug) PRINT_TRACE
2623 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2626 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2628 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2629 if(session->show_vwindow)
2630 get_viewer(1, DEFAULT_VWINDOW);
2631 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2634 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2637 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2640 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2643 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2646 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2649 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2655 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2656 mainprogress = new MainProgress(this, gui);
2657 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2658 undo = new MainUndo(this);
2660 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2662 plugin_guis = new ArrayList<PluginServer*>;
2663 dead_plugins = new ArrayList<PluginServer*>;
2664 keyframe_threads = new ArrayList<KeyFrameThread*>;
2666 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2669 session->show_vwindow);
2671 // Show all vwindows
2672 // if(session->show_vwindow) {
2673 // for(int j = 0; j < vwindows.size(); j++) {
2674 // VWindow *vwindow = vwindows[j];
2675 // if( !vwindow->is_running() ) continue;
2676 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2679 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2680 // vwindow->gui->lock_window("MWindow::create_objects 1");
2681 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2682 // vwindow->gui->show_window();
2683 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2684 // vwindow->gui->unlock_window();
2689 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2691 if(session->show_cwindow)
2693 cwindow->gui->lock_window("MWindow::create_objects 1");
2694 cwindow->gui->show_window();
2695 cwindow->gui->unlock_window();
2698 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2699 if(session->show_awindow)
2701 awindow->gui->lock_window("MWindow::create_objects 1");
2702 awindow->gui->show_window();
2703 awindow->gui->unlock_window();
2706 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2707 if(session->show_lwindow)
2709 lwindow->gui->lock_window("MWindow::create_objects 1");
2710 lwindow->gui->show_window();
2711 lwindow->gui->unlock_window();
2714 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2716 (int)timer.get_difference(),
2718 if(session->show_gwindow)
2720 gwindow->gui->lock_window("MWindow::create_objects 1");
2721 gwindow->gui->show_window();
2722 gwindow->gui->unlock_window();
2725 if(debug) PRINT_TRACE
2727 gui->lock_window("MWindow::create_objects 1");
2728 gui->mainmenu->load_defaults(defaults);
2729 gui->mainmenu->update_toggles(0);
2730 gui->update_patchbay();
2731 gui->draw_canvas(0, 0);
2732 gui->draw_cursor(1);
2734 gui->raise_window();
2735 gui->unlock_window();
2737 if(debug) PRINT_TRACE
2739 if(preferences->use_tipwindow)
2741 if(debug) PRINT_TRACE
2743 gui->add_keyboard_listener(
2744 (int (BC_WindowBase::*)(BC_WindowBase *))
2745 &MWindowGUI::keyboard_listener);
2748 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2749 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2750 if(debug) PRINT_TRACE
2752 BC_WindowBase::get_resources()->vframe_shm = 1;
2756 void MWindow::show_splash()
2758 #include "data/heroine_logo9_png.h"
2759 VFrame *frame = new VFramePng(heroine_logo9_png);
2760 BC_DisplayInfo dpyi;
2761 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2762 int rr = (rw < rh ? rw : rh) / 4;
2763 splash_window = new SplashGUI(frame, rr, rr);
2764 splash_window->create_objects();
2767 void MWindow::hide_splash()
2770 delete splash_window;
2775 void MWindow::start()
2779 // vwindows[DEFAULT_VWINDOW]->start();
2790 playback_3d->start();
2796 run_lock->lock("MWindow::run");
2800 brender_lock->lock("MWindow::run 1");
2801 delete brender; brender = 0;
2802 brender_lock->unlock();
2804 interrupt_indexes();
2810 void MWindow::show_vwindow()
2812 int total_running = 0;
2813 session->show_vwindow = 1;
2815 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2816 // Raise all windows which are visible
2817 for(int j = 0; j < vwindows.size(); j++) {
2818 VWindow *vwindow = vwindows[j];
2819 if( !vwindow->is_running() ) continue;
2820 vwindow->gui->lock_window("MWindow::show_vwindow");
2821 vwindow->gui->show_window(0);
2822 vwindow->gui->raise_window();
2823 vwindow->gui->flush();
2824 vwindow->gui->unlock_window();
2828 // If no windows visible
2831 get_viewer(1, DEFAULT_VWINDOW);
2834 gui->mainmenu->show_vwindow->set_checked(1);
2837 void MWindow::show_awindow()
2839 session->show_awindow = 1;
2840 awindow->gui->lock_window("MWindow::show_awindow");
2841 awindow->gui->show_window();
2842 awindow->gui->raise_window();
2843 awindow->gui->flush();
2844 awindow->gui->unlock_window();
2845 gui->mainmenu->show_awindow->set_checked(1);
2848 char *MWindow::get_cwindow_display()
2850 char *x11_host = screens < 2 || session->window_config == 0 ?
2851 session->a_x11_host : session->b_x11_host;
2852 return *x11_host ? x11_host : 0;
2855 void MWindow::show_cwindow()
2857 session->show_cwindow = 1;
2858 cwindow->show_window();
2859 gui->mainmenu->show_cwindow->set_checked(1);
2862 void MWindow::show_gwindow()
2864 session->show_gwindow = 1;
2866 gwindow->gui->lock_window("MWindow::show_gwindow");
2867 gwindow->gui->show_window();
2868 gwindow->gui->raise_window();
2869 gwindow->gui->flush();
2870 gwindow->gui->unlock_window();
2872 gui->mainmenu->show_gwindow->set_checked(1);
2874 void MWindow::hide_gwindow()
2876 session->show_gwindow = 0;
2878 gwindow->gui->lock_window("MWindow::show_gwindow");
2879 gwindow->gui->hide_window();
2880 gwindow->gui->unlock_window();
2883 void MWindow::show_lwindow()
2885 session->show_lwindow = 1;
2886 lwindow->gui->lock_window("MWindow::show_lwindow");
2887 lwindow->gui->show_window();
2888 lwindow->gui->raise_window();
2889 lwindow->gui->flush();
2890 lwindow->gui->unlock_window();
2891 gui->mainmenu->show_lwindow->set_checked(1);
2894 void MWindow::restore_windows()
2896 if( !session->show_vwindow ) {
2897 for( int i=0, n=vwindows.size(); i<n; ++i ) {
2898 VWindow *vwindow = vwindows[i];
2899 if( !vwindow || !vwindow->is_running() ) continue;
2900 vwindow->gui->lock_window("MWindow::restore_windows");
2901 vwindow->gui->close(1);
2902 vwindow->gui->unlock_window();
2908 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
2909 awindow->gui->lock_window("MWindow::restore_windows");
2910 awindow->gui->close_event();
2911 awindow->gui->unlock_window();
2913 else if( session->show_awindow && awindow->gui->is_hidden() )
2916 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
2917 cwindow->gui->lock_window("MWindow::restore_windows");
2918 cwindow->hide_window();
2919 cwindow->gui->unlock_window();
2921 else if( session->show_cwindow && cwindow->gui->is_hidden() )
2922 cwindow->show_window();
2924 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
2925 gwindow->gui->lock_window("MWindow::restore_windows");
2926 gwindow->gui->close_event();
2927 gwindow->gui->unlock_window();
2929 else if( session->show_gwindow && gwindow->gui->is_hidden() )
2932 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
2933 lwindow->gui->lock_window("MWindow::restore_windows");
2934 lwindow->gui->close_event();
2935 lwindow->gui->unlock_window();
2937 else if( session->show_lwindow && lwindow->gui->is_hidden() )
2943 void MWindow::save_layout(int no)
2945 char layout_path[BCTEXTLEN];
2946 snprintf(layout_path, sizeof(layout_path), "%s/" LAYOUT_FILE,
2947 File::get_config_path(), no);
2948 session->save_file(layout_path);
2951 void MWindow::load_layout(int no)
2953 char layout_path[BCTEXTLEN];
2954 snprintf(layout_path, sizeof(layout_path), "%s/" LAYOUT_FILE,
2955 File::get_config_path(), no);
2956 session->load_file(layout_path);
2958 gui->default_positions();
2962 int MWindow::tile_windows(int window_config)
2964 int need_reload = 0;
2965 int play_config = window_config==0 ? 0 : 1;
2966 edl->session->playback_config->load_defaults(defaults, play_config);
2967 session->default_window_positions(window_config);
2968 if( screens == 1 ) {
2969 gui->default_positions();
2970 sync_parameters(CHANGE_ALL);
2977 void MWindow::toggle_loop_playback()
2979 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2980 set_loop_boundaries();
2983 gui->draw_overlays(1);
2984 sync_parameters(CHANGE_PARAMS);
2987 void MWindow::set_screens(int value)
2992 void MWindow::set_auto_keyframes(int value)
2994 edl->session->auto_keyframes = value;
2995 gui->mbuttons->edit_panel->keyframe->update(value);
2997 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2998 cwindow->gui->edit_panel->keyframe->update(value);
2999 cwindow->gui->flush();
3000 cwindow->gui->unlock_window();
3003 void MWindow::set_auto_visibility(Autos *autos, int value)
3005 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3006 edl->session->auto_conf->plugins = value;
3007 else if( autos->autoidx >= 0 )
3008 edl->session->auto_conf->autos[autos->autoidx] = value;
3012 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3013 gui->mainmenu->update_toggles(1);
3014 gui->unlock_window();
3015 gwindow->gui->update_toggles(1);
3016 gui->lock_window("MWindow::set_auto_visibility");
3019 void MWindow::set_keyframe_type(int mode)
3021 gui->lock_window("MWindow::set_keyframe_type");
3022 edl->local_session->floatauto_type = mode;
3023 gui->mainmenu->update_toggles(0);
3024 gui->unlock_window();
3027 int MWindow::set_editing_mode(int new_editing_mode)
3029 edl->session->editing_mode = new_editing_mode;
3030 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3031 gui->mbuttons->edit_panel->update();
3032 gui->set_editing_mode(1);
3034 cwindow->gui->lock_window("MWindow::set_editing_mode");
3035 cwindow->gui->edit_panel->update();
3036 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3037 cwindow->gui->unlock_window();
3041 void MWindow::toggle_editing_mode()
3043 int mode = edl->session->editing_mode;
3044 if( mode == EDITING_ARROW )
3045 set_editing_mode(EDITING_IBEAM);
3047 set_editing_mode(EDITING_ARROW);
3050 void MWindow::toggle_camera_xyz()
3052 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3053 gwindow->gui->toggle_camera_xyz();
3054 gwindow->gui->unlock_window();
3057 void MWindow::toggle_projector_xyz()
3059 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3060 gwindow->gui->toggle_projector_xyz();
3061 gwindow->gui->unlock_window();
3064 void MWindow::set_labels_follow_edits(int value)
3066 edl->session->labels_follow_edits = value;
3067 gui->mbuttons->edit_panel->locklabels->update(value);
3068 gui->mainmenu->labels_follow_edits->set_checked(value);
3072 void MWindow::sync_parameters(int change_type)
3074 if( in_destructor ) return;
3076 // Sync engines which are playing back
3077 if( cwindow->playback_engine->is_playing_back ) {
3078 if( change_type == CHANGE_PARAMS ) {
3079 // TODO: block keyframes until synchronization is done
3080 cwindow->playback_engine->sync_parameters(edl);
3084 int command = cwindow->playback_engine->command->command;
3085 // Waiting for tracking to finish would make the restart position more
3086 // accurate but it can't lock the window to stop tracking for some reason.
3087 // Not waiting for tracking gives a faster response but restart position is
3088 // only as accurate as the last tracking update.
3089 cwindow->playback_engine->transport_stop(0);
3090 cwindow->playback_engine->next_command->realtime = 1;
3091 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3095 cwindow->refresh_frame(change_type);
3099 void MWindow::age_caches()
3101 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3103 // preferences->cache_size,
3104 // audio_cache->get_memory_usage(1),
3105 // video_cache->get_memory_usage(1),
3106 // frame_cache->get_memory_usage(),
3107 // wave_cache->get_memory_usage(),
3109 frame_cache->age_cache(512);
3110 wave_cache->age_cache(8192);
3112 int64_t memory_usage;
3113 int64_t prev_memory_usage = 0;
3115 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3116 while( !result && prev_memory_usage !=
3117 (memory_usage=video_cache->get_memory_usage(1)) &&
3118 memory_usage > video_size ) {
3119 video_cache->delete_oldest();
3120 prev_memory_usage = memory_usage;
3123 prev_memory_usage = 0;
3125 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3126 while( !result && prev_memory_usage !=
3127 (memory_usage=audio_cache->get_memory_usage(1)) &&
3128 memory_usage > audio_size ) {
3129 audio_cache->delete_oldest();
3130 prev_memory_usage = memory_usage;
3134 void MWindow::reset_android_remote()
3136 gui->use_android_remote(preferences->android_remote);
3140 void MWindow::show_keyframe_gui(Plugin *plugin)
3142 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3143 // Find existing thread
3144 for(int i = 0; i < keyframe_threads->size(); i++)
3146 if(keyframe_threads->get(i)->plugin == plugin)
3148 keyframe_threads->get(i)->start_window(plugin, 0);
3149 keyframe_gui_lock->unlock();
3154 // Find unused thread
3155 for(int i = 0; i < keyframe_threads->size(); i++)
3157 if(!keyframe_threads->get(i)->plugin)
3159 keyframe_threads->get(i)->start_window(plugin, 0);
3160 keyframe_gui_lock->unlock();
3165 // Create new thread
3166 KeyFrameThread *thread = new KeyFrameThread(this);
3167 keyframe_threads->append(thread);
3168 thread->start_window(plugin, 0);
3170 keyframe_gui_lock->unlock();
3177 void MWindow::show_plugin(Plugin *plugin)
3182 // Remove previously deleted plugin GUIs
3183 dead_plugin_lock->lock("MWindow::show_plugin");
3184 dead_plugins->remove_all_objects();
3185 dead_plugin_lock->unlock();
3187 //printf("MWindow::show_plugin %d\n", __LINE__);
3191 plugin_gui_lock->lock("MWindow::show_plugin");
3192 for(int i = 0; i < plugin_guis->total; i++)
3194 // Pointer comparison
3195 if(plugin_guis->get(i)->plugin == plugin)
3197 plugin_guis->get(i)->raise_window();
3204 //printf("MWindow::show_plugin 1\n");
3205 if( !done && !plugin->track ) {
3206 printf("MWindow::show_plugin track not defined.\n");
3210 PluginServer *server = scan_plugindb(plugin->title,
3211 plugin->track->data_type);
3213 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3214 if(server && server->uses_gui)
3216 PluginServer *gui = new PluginServer(*server);
3217 plugin_guis->append(gui);
3218 // Needs mwindow to do GUI
3219 gui->set_mwindow(this);
3220 gui->open_plugin(0, preferences, edl, plugin);
3225 plugin_gui_lock->unlock();
3226 //printf("MWindow::show_plugin %d\n", __LINE__);
3229 //printf("MWindow::show_plugin 2\n");
3232 void MWindow::hide_plugin(Plugin *plugin, int lock)
3235 // Update the toggle
3236 gui->lock_window("MWindow::hide_plugin");
3237 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3238 gui->unlock_window();
3240 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3241 for(int i = 0; i < plugin_guis->total; i++)
3243 if(plugin_guis->get(i)->plugin == plugin)
3245 PluginServer *ptr = plugin_guis->get(i);
3246 plugin_guis->remove(ptr);
3247 if(lock) plugin_gui_lock->unlock();
3248 // Last command executed in client side close
3249 // Schedule for deletion
3256 if(lock) plugin_gui_lock->unlock();
3259 void MWindow::delete_plugin(PluginServer *plugin)
3261 dead_plugin_lock->lock("MWindow::delete_plugin");
3262 dead_plugins->append(plugin);
3263 dead_plugin_lock->unlock();
3266 void MWindow::hide_plugins()
3268 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3269 while(plugin_guis->size())
3271 PluginServer *ptr = plugin_guis->get(0);
3272 plugin_guis->remove(ptr);
3273 plugin_gui_lock->unlock();
3274 // Last command executed in client side close
3275 // Schedule for deletion
3278 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3280 plugin_gui_lock->unlock();
3282 hide_keyframe_guis();
3285 void MWindow::hide_keyframe_guis()
3287 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3288 for(int i = 0; i < keyframe_threads->size(); i++)
3290 keyframe_threads->get(i)->close_window();
3292 keyframe_gui_lock->unlock();
3295 void MWindow::hide_keyframe_gui(Plugin *plugin)
3297 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3298 for(int i = 0; i < keyframe_threads->size(); i++)
3300 if(keyframe_threads->get(i)->plugin == plugin)
3302 keyframe_threads->get(i)->close_window();
3306 keyframe_gui_lock->unlock();
3309 int MWindow::get_hash_color(Edit *edit)
3311 Indexable *idxbl = edit->asset ?
3312 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3313 if( !idxbl ) return 0;
3314 char path[BCTEXTLEN];
3315 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3316 edl->session->proxy_scale == 1 ||
3317 ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
3318 strcpy(path, idxbl->path);
3319 char *cp = strrchr(path, '/');
3320 cp = !cp ? path : cp+1;
3321 uint8_t *bp = (uint8_t*)cp;
3323 while( *bp ) v += *bp++;
3324 return get_hash_color(v);
3327 int MWindow::get_hash_color(int v)
3329 int hash = 0x303030;
3330 if( v & 0x01 ) hash ^= 0x000040;
3331 if( v & 0x02 ) hash ^= 0x004000;
3332 if( v & 0x04 ) hash ^= 0x400000;
3333 if( v & 0x08 ) hash ^= 0x080000;
3334 if( v & 0x10 ) hash ^= 0x000800;
3335 if( v & 0x20 ) hash ^= 0x000008;
3336 if( v & 0x40 ) hash ^= 0x404040;
3337 if( v & 0x80 ) hash ^= 0x080808;
3341 int MWindow::get_group_color(int v)
3343 int color = 0x606060;
3344 if( v & 0x01 ) color ^= 0x000080;
3345 if( v & 0x02 ) color ^= 0x008000;
3346 if( v & 0x04 ) color ^= 0x800000;
3347 if( v & 0x08 ) color ^= 0x100000;
3348 if( v & 0x10 ) color ^= 0x001000;
3349 if( v & 0x20 ) color ^= 0x000010;
3350 if( v & 0x40 ) color ^= 0x080808;
3351 if( v & 0x80 ) color ^= 0x909090;
3355 int MWindow::get_title_color(Edit *edit)
3357 unsigned color = edit->color & 0xffffff;
3358 unsigned alpha = (~edit->color>>24) & 0xff;
3360 if( edit->group_id )
3361 color = get_group_color(edit->group_id);
3362 else if( preferences->autocolor_assets )
3363 color = get_hash_color(edit);
3368 alpha = session->title_bar_alpha*255;
3369 return color | (~alpha<<24);
3372 void MWindow::update_keyframe_guis()
3374 // Send new configuration to keyframe GUI's
3375 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3376 for(int i = 0; i < keyframe_threads->size(); i++)
3378 KeyFrameThread *ptr = keyframe_threads->get(i);
3379 if(edl->tracks->plugin_exists(ptr->plugin))
3383 ptr->close_window();
3386 keyframe_gui_lock->unlock();
3389 void MWindow::update_plugin_guis(int do_keyframe_guis)
3391 // Send new configuration to plugin GUI's
3392 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3394 for(int i = 0; i < plugin_guis->size(); i++)
3396 PluginServer *ptr = plugin_guis->get(i);
3397 if(edl->tracks->plugin_exists(ptr->plugin))
3401 // Schedule for deletion if no plugin
3402 plugin_guis->remove_number(i);
3411 // Change plugin variable if not visible
3412 Track *track = edl->tracks->first;
3415 for(int i = 0; i < track->plugin_set.size(); i++)
3417 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3421 for(int i = 0; i < plugin_guis->size(); i++)
3423 PluginServer *server = plugin_guis->get(i);
3424 if(server->plugin == plugin)
3431 if(!got_it) plugin->show = 0;
3433 plugin = (Plugin*)plugin->next;
3437 track = track->next;
3440 plugin_gui_lock->unlock();
3443 if(do_keyframe_guis) update_keyframe_guis();
3446 int MWindow::plugin_gui_open(Plugin *plugin)
3449 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3450 for(int i = 0; i < plugin_guis->total; i++)
3452 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3458 plugin_gui_lock->unlock();
3462 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3464 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3465 for(int i = 0; i < plugin_guis->total; i++)
3467 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3469 plugin_guis->get(i)->render_gui(data);
3473 plugin_gui_lock->unlock();
3476 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3478 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3479 for(int i = 0; i < plugin_guis->total; i++)
3481 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3483 plugin_guis->get(i)->render_gui(data, size);
3487 plugin_gui_lock->unlock();
3491 void MWindow::update_plugin_states()
3493 plugin_gui_lock->lock("MWindow::update_plugin_states");
3494 for(int i = 0; i < plugin_guis->total; i++)
3498 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3499 PluginServer *src_plugingui = plugin_guis->get(i);
3501 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3502 for(Track *track = edl->tracks->first;
3504 track = track->next)
3507 j < track->plugin_set.total && !result;
3510 PluginSet *plugin_set = track->plugin_set[j];
3511 for(Plugin *plugin = (Plugin*)plugin_set->first;
3513 plugin = (Plugin*)plugin->next)
3515 if(plugin == src_plugin &&
3516 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3522 // Doesn't exist anymore
3525 hide_plugin(src_plugin, 0);
3529 plugin_gui_lock->unlock();
3533 void MWindow::update_plugin_titles()
3535 for(int i = 0; i < plugin_guis->total; i++)
3537 plugin_guis->get(i)->update_title();
3541 int MWindow::asset_to_edl(EDL *new_edl,
3543 RecordLabels *labels)
3545 const int debug = 0;
3546 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3549 // Keep frame rate, sample rate, and output size unchanged.
3550 // These parameters would revert the project if VWindow displayed an asset
3551 // of different size than the project.
3552 if(new_asset->video_data)
3554 new_edl->session->video_tracks = new_asset->layers;
3557 new_edl->session->video_tracks = 0;
3559 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3565 if(new_asset->audio_data)
3567 new_edl->session->audio_tracks = new_asset->channels;
3570 new_edl->session->audio_tracks = 0;
3571 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3573 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3574 new_edl->create_default_tracks();
3575 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3576 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3580 //printf("MWindow::asset_to_edl 3\n");
3581 new_edl->insert_asset(new_asset,
3586 //printf("MWindow::asset_to_edl 3\n");
3587 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3589 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3590 if(edl->session->cursor_on_frames)
3592 double length = new_edl->tracks->total_length();
3593 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3594 new_edl->tracks->clear(length, edl_length, 1, 1);
3600 char string[BCTEXTLEN];
3602 fs.extract_name(string, new_asset->path);
3603 //printf("MWindow::asset_to_edl 3\n");
3605 strcpy(new_edl->local_session->clip_title, string);
3606 //printf("MWindow::asset_to_edl 4 %s\n", string);
3607 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3613 // Reset everything after a load.
3614 void MWindow::update_project(int load_mode)
3616 const int debug = 0;
3618 if(debug) PRINT_TRACE
3619 edl->tracks->update_y_pixels(theme);
3620 session->update_clip_number();
3622 if(debug) PRINT_TRACE
3624 if( load_mode == LOADMODE_REPLACE ||
3625 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3626 delete gui->keyvalue_popup;
3627 gui->keyvalue_popup = 0;
3631 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3632 if(debug) PRINT_TRACE
3633 gui->unlock_window();
3636 cwindow->gui->lock_window("MWindow::update_project 1");
3637 cwindow->update(0, 0, 1, 1, 1);
3638 cwindow->gui->unlock_window();
3640 if(debug) PRINT_TRACE
3642 // Close all the vwindows
3643 if( load_mode == LOADMODE_REPLACE ||
3644 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3645 if(debug) PRINT_TRACE
3646 int first_vwindow = 0;
3647 if(session->show_vwindow) first_vwindow = 1;
3648 // Change visible windows to no source
3649 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3650 VWindow *vwindow = vwindows[i];
3651 if( !vwindow->is_running() ) continue;
3652 vwindow->change_source(-1);
3655 // Close remaining windows
3656 for(int i = first_vwindow; i < vwindows.size(); i++) {
3657 VWindow *vwindow = vwindows[i];
3658 if( !vwindow->is_running() ) continue;
3659 vwindow->close_window();
3661 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3662 VWindow *vwindow = get_viewer(1, -1);
3663 vwindow->change_source(i);
3665 if(debug) PRINT_TRACE
3669 for( int i=0; i<edl->mixers.size(); ++i ) {
3670 Mixer *mixer = edl->mixers[i];
3671 ZWindow *zwindow = get_mixer(mixer);
3672 zwindow->set_title(mixer->title);
3678 if(debug) PRINT_TRACE
3679 cwindow->gui->lock_window("MWindow::update_project 2");
3680 cwindow->gui->timebar->update(0);
3681 cwindow->gui->unlock_window();
3683 if(debug) PRINT_TRACE
3684 cwindow->refresh_frame(CHANGE_ALL);
3686 awindow->gui->async_update_assets();
3687 if(debug) PRINT_TRACE
3689 gui->lock_window("MWindow::update_project");
3690 gui->update_mixers(0, 0);
3692 if(debug) PRINT_TRACE
3695 void MWindow::update_vwindow()
3697 for( int i=0; i<vwindows.size(); ++i ) {
3698 VWindow *vwindow = vwindows[i];
3699 if( vwindow->is_running() ) {
3700 vwindow->gui->lock_window("MWindow::update_vwindow");
3702 vwindow->gui->unlock_window();
3707 void MWindow::remove_indexfile(Indexable *indexable)
3709 if( !indexable->is_asset ) return;
3710 Asset *asset = (Asset *)indexable;
3712 IndexFile::delete_index(preferences, asset, ".toc");
3713 IndexFile::delete_index(preferences, asset, ".idx");
3714 IndexFile::delete_index(preferences, asset, ".mkr");
3717 void MWindow::rebuild_indices()
3719 for(int i = 0; i < session->drag_assets->total; i++)
3721 Indexable *indexable = session->drag_assets->get(i);
3722 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3723 remove_indexfile(indexable);
3724 // Schedule index build
3725 IndexState *index_state = indexable->index_state;
3726 index_state->index_status = INDEX_NOTTESTED;
3727 if( indexable->is_asset ) {
3728 Asset *asset = (Asset *)indexable;
3729 if( asset->format != FILE_PCM ) {
3730 asset->format = FILE_UNKNOWN;
3731 asset->reset_audio();
3733 asset->reset_video();
3734 remove_asset_from_caches(asset);
3735 // File file; // re-probe the asset
3736 // file.open_file(preferences, asset, 1, 0);
3738 mainindexes->add_next_asset(0, indexable);
3740 mainindexes->start_build();
3744 void MWindow::save_backup()
3748 edl->set_path(session->filename);
3749 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3750 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3751 File::get_config_path(), BACKUP_FILE);
3752 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3753 File::get_config_path(), BACKUP_FILE1);
3754 rename(backup_path, backup_path1);
3755 edl->save_xml(&file, backup_path);
3756 file.terminate_string();
3758 fs.complete_path(backup_path);
3760 if(file.write_to_file(backup_path))
3763 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3764 gui->show_message(string2);
3768 void MWindow::load_backup()
3770 ArrayList<char*> path_list;
3771 path_list.set_array_delete();
3773 char backup_path[BCTEXTLEN];
3774 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3775 File::get_config_path(), BACKUP_FILE);
3777 fs.complete_path(backup_path);
3779 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3780 strcpy(out_path, backup_path);
3782 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3783 edl->local_session->clip_title[0] = 0;
3784 // This is unique to backups since the path of the backup is different than the
3785 // path of the project.
3786 set_filename(edl->path);
3787 path_list.remove_all_objects();
3792 void MWindow::save_undo_data()
3795 undo_after(_("perpetual session"), LOAD_ALL);
3796 char perpetual_path[BCTEXTLEN];
3797 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3798 File::get_config_path(), PERPETUAL_FILE);
3799 FILE *fp = fopen(perpetual_path,"w");
3805 void MWindow::load_undo_data()
3807 char perpetual_path[BCTEXTLEN];
3808 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3809 File::get_config_path(), PERPETUAL_FILE);
3810 FILE *fp = fopen(perpetual_path,"r");
3817 int MWindow::copy_target(const char *path, const char *target)
3819 int ifd = ::open(path, O_RDONLY);
3821 eprintf("Cannot open asset: %s", path);
3825 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
3828 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
3829 char progress_title[BCTEXTLEN];
3830 sprintf(progress_title, _("Copying: %s\n"), target);
3831 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
3833 int64_t count = 0, len = -1;
3834 int bfrsz = 0x100000;
3835 uint8_t *bfr = new uint8_t[bfrsz];
3836 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
3837 if( len != ::write(ofd, bfr, len) ) {
3838 eprintf("Error writing: %s", target);
3841 if( progress.is_cancelled() ) {
3845 progress.update(count += len, 1);
3850 progress.stop_progress();
3852 eprintf("Error reading: %s", path);
3857 eprintf("Cannot create asset target: %s", target);
3862 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
3864 char target[BCTEXTLEN];
3866 const char *bp = real_path, *cp = bp;
3867 const char *lp = link_path, *np = lp;
3868 char *tp = target, *ep = tp+sizeof(target)-1, lch;
3869 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
3870 if( lch == '/' ) { np = lp; cp = bp; }
3872 while( tp<ep && *np ) {
3873 if( *np++ != '/' ) continue;
3874 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
3876 while( tp<ep && *cp ) *tp++ = *cp++;
3880 strcpy(target, real_path);
3881 if( symlink(target, link_path) ) {
3882 eprintf("Cannot create symlink: %s", link_path);
3888 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
3890 char dir_path[BCTEXTLEN];
3891 strcpy(dir_path, dir);
3893 fs.complete_path(dir_path);
3896 if( !stat(dir_path, &st) ) {
3897 if( !S_ISDIR(st.st_mode) ) {
3898 eprintf("Path exists and is not a directory\n%s", dir_path);
3903 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
3904 eprintf("Cannot create directory\n%s", dir_path);
3908 char *real_dir = realpath(dir_path, 0);
3909 strcpy(dir_path, real_dir);
3912 EDL *save_edl = new EDL;
3913 save_edl->create_objects();
3914 save_edl->copy_all(edl);
3916 char progress_title[BCTEXTLEN];
3917 sprintf(progress_title, _("Saving to %s:\n"), dir);
3918 int total_assets = save_edl->assets->total();
3919 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
3921 Asset *current = save_edl->assets->first;
3922 for( int i=0; !ret && current; ++i, current=NEXT ) {
3923 char *path = current->path;
3924 if( ::stat(path, &st) ) {
3925 eprintf("Asset not found: %s", path);
3928 char *real_path = realpath(path, 0);
3929 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
3930 char link_path[BCTEXTLEN];
3931 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
3933 if( strcmp(real_path, link_path) ) {
3934 if( !::lstat(link_path, &st) ) {
3936 ::remove(link_path);
3942 eprintf("copy/link to self, skippped: %s", path);
3946 if( save_mode == SAVE_PROJECT_COPY ) {
3947 if( copy_target(real_path, link_path) )
3951 link_target(real_path, link_path,
3952 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
3956 strcpy(path, link_path);
3958 if( progress->is_cancelled() ) break;
3959 progress->update(i);
3962 progress->stop_progress();
3965 char *cp = strrchr(dir_path,'/');
3966 char *bp = cp ? cp+1 : dir_path;
3967 char filename[BCTEXTLEN];
3968 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
3969 save_edl->set_path(filename);
3971 save_edl->save_xml(&file, filename);
3972 file.terminate_string();
3974 if( !file.write_to_file(filename) ) {
3975 char string[BCTEXTLEN];
3976 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
3977 gui->lock_window("SaveProject::run 2");
3978 gui->show_message(string);
3979 gui->unlock_window();
3980 gui->mainmenu->add_load(filename);
3983 eprintf(_("Couldn't open %s."), filename);
3985 save_edl->remove_user();
3988 gui->lock_window("MWindow::save_project");
3989 ArrayList<char*> filenames;
3990 filenames.append(filename);
3991 load_filenames(&filenames, LOADMODE_REPLACE);
3992 gui->unlock_window();
3997 static inline int gcd(int m, int n)
4000 if( m < n ) { r = m; m = n; n = r; }
4001 while( (r = m % n) != 0 ) { m = n; n = r; }
4005 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4008 if(!width || !height) return 1;
4009 if( width == 720 && (height == 480 || height == 576) ) {
4010 w = 4; h = 3; return 0; // for NTSC and PAL
4012 double ar = (double)width / height;
4013 // square-ish pixels
4014 if( EQUIV(ar, 1.0000) ) return 0;
4015 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4016 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4017 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4018 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4019 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4020 int ww = width, hh = height;
4021 // numerator, denominator must be under mx
4022 int mx = 255, n = gcd(ww, hh);
4023 if( n > 1 ) { ww /= n; hh /= n; }
4024 // search near height in case extra/missing lines
4025 if( ww >= mx || hh >= mx ) {
4026 double err = height; // +/- 2 percent height
4027 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4028 int iw = width, ih = height+i;
4029 if( (n=gcd(iw, ih)) > 1 ) {
4030 int u = iw/n; if( u >= mx ) continue;
4031 int v = ih/n; if( v >= mx ) continue;
4032 double r = (double) u/v, er = fabs(ar-r);
4033 if( er >= err ) continue;
4034 err = er; ww = u; hh = v;
4043 void MWindow::reset_caches()
4045 frame_cache->remove_all();
4046 wave_cache->remove_all();
4047 audio_cache->remove_all();
4048 video_cache->remove_all();
4049 if( cwindow->playback_engine ) {
4050 if( cwindow->playback_engine->audio_cache )
4051 cwindow->playback_engine->audio_cache->remove_all();
4052 if( cwindow->playback_engine->video_cache )
4053 cwindow->playback_engine->video_cache->remove_all();
4055 for(int i = 0; i < vwindows.size(); i++) {
4056 VWindow *vwindow = vwindows[i];
4057 if( !vwindow->is_running() ) continue;
4058 if( !vwindow->playback_engine ) continue;
4059 if( vwindow->playback_engine->audio_cache )
4060 vwindow->playback_engine->audio_cache->remove_all();
4061 if( vwindow->playback_engine->video_cache )
4062 vwindow->playback_engine->video_cache->remove_all();
4066 void MWindow::remove_asset_from_caches(Asset *asset)
4068 frame_cache->remove_asset(asset);
4069 wave_cache->remove_asset(asset);
4070 audio_cache->delete_entry(asset);
4071 video_cache->delete_entry(asset);
4072 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4073 cwindow->playback_engine->audio_cache->delete_entry(asset);
4074 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4075 cwindow->playback_engine->video_cache->delete_entry(asset);
4076 for(int i = 0; i < vwindows.size(); i++) {
4077 VWindow *vwindow = vwindows[i];
4078 if( !vwindow->is_running() ) continue;
4079 if( !vwindow->playback_engine ) continue;
4080 if( vwindow->playback_engine->audio_cache )
4081 vwindow->playback_engine->audio_cache->delete_entry(asset);
4082 if( vwindow->playback_engine->video_cache )
4083 vwindow->playback_engine->video_cache->delete_entry(asset);
4088 void MWindow::remove_assets_from_project(int push_undo, int redraw,
4089 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4091 awindow->gui->close_view_popup();
4093 for(int i = 0; i < drag_assets->total; i++) {
4094 Indexable *indexable = drag_assets->get(i);
4095 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
4098 // Remove from VWindow.
4099 for(int i = 0; i < session->drag_clips->total; i++) {
4100 for(int j = 0; j < vwindows.size(); j++) {
4101 VWindow *vwindow = vwindows[j];
4102 if( !vwindow->is_running() ) continue;
4103 if(session->drag_clips->get(i) == vwindow->get_edl()) {
4104 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4105 vwindow->delete_source(1, 1);
4106 vwindow->gui->unlock_window();
4111 for(int i = 0; i < drag_assets->size(); i++) {
4112 for(int j = 0; j < vwindows.size(); j++) {
4113 VWindow *vwindow = vwindows[j];
4114 if( !vwindow->is_running() ) continue;
4115 if(drag_assets->get(i) == vwindow->get_source()) {
4116 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4117 vwindow->delete_source(1, 1);
4118 vwindow->gui->unlock_window();
4123 for(int i = 0; i < drag_assets->size(); i++) {
4124 Indexable *indexable = drag_assets->get(i);
4125 remove_indexfile(indexable);
4128 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4129 if(push_undo) undo_before();
4130 if(drag_assets) edl->remove_from_project(drag_assets);
4131 if(drag_clips) edl->remove_from_project(drag_clips);
4132 if(redraw) save_backup();
4133 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4137 gui->lock_window("MWindow::remove_assets_from_project 3");
4138 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4139 gui->unlock_window();
4141 // Removes from playback here
4142 sync_parameters(CHANGE_ALL);
4145 awindow->gui->async_update_assets();
4148 void MWindow::remove_assets_from_disk()
4150 remove_assets_from_project(1,
4152 session->drag_assets,
4153 session->drag_clips);
4156 for(int i = 0; i < session->drag_assets->total; i++)
4158 remove(session->drag_assets->get(i)->path);
4162 void MWindow::dump_plugins(FILE *fp)
4164 if( !plugindb ) return;
4165 for(int i = 0; i < plugindb->total; i++)
4167 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4168 " synth=%d transition=%d theme=%d %s\n",
4169 plugindb->get(i)->plugin_type,
4170 plugindb->get(i)->audio,
4171 plugindb->get(i)->video,
4172 plugindb->get(i)->realtime,
4173 plugindb->get(i)->multichannel,
4174 plugindb->get(i)->get_synthesis(),
4175 plugindb->get(i)->transition,
4176 plugindb->get(i)->theme,
4177 plugindb->get(i)->title);
4181 void MWindow::dump_edl(FILE *fp)
4187 void MWindow::dump_undo(FILE *fp)
4193 void MWindow::dump_exe(FILE *fp)
4195 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4196 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4198 int ret = -1, n = 100;
4199 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4200 exe_path[len] = 0; strcpy(proc_path, exe_path);
4203 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4206 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4207 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4208 struct tm *tm = localtime(&st.st_mtime);
4210 strftime(mtime, sizeof(mtime), "%F %T", tm);
4211 fprintf(fp,"mtime: %s\n", mtime);
4213 // people hit ctl-c waiting for this
4214 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4215 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4218 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4219 int64_t maxsz = 1024*pagsz;
4220 int64_t size = st.st_size, pos = 0;
4222 while( (bfrsz = size-pos) > 0 ) {
4223 if( bfrsz > maxsz ) bfrsz = maxsz;
4224 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4225 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4226 if( bfr == MAP_FAILED ) break;
4227 sha1.addBytes(bfr, bfrsz);
4232 ret = pos < size ? EIO : 0;
4233 fprintf(fp, "SHA1: ");
4234 uint8_t digest[20]; sha1.computeHash(digest);
4235 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4236 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4237 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4242 void MWindow::trap_hook(FILE *fp, void *vp)
4244 MWindow *mwindow = (MWindow *)vp;
4245 // fprintf(fp, "\nPLUGINS:\n");
4246 // mwindow->dump_plugins(fp);
4247 fprintf(fp, "\nEDL:\n");
4248 mwindow->dump_edl(fp);
4249 fprintf(fp, "\nUNDO:\n");
4250 mwindow->dump_undo(fp);
4251 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4252 mwindow->dump_exe(fp);
4260 int MWindow::save_defaults()
4262 gui->save_defaults(defaults);
4263 edl->save_defaults(defaults);
4264 session->save_defaults(defaults);
4265 preferences->save_defaults(defaults);
4267 for(int i = 0; i < plugin_guis->total; i++)
4269 // Pointer comparison
4270 plugin_guis->get(i)->save_defaults();
4272 awindow->save_defaults(defaults);
4278 int MWindow::run_script(FileXML *script)
4280 int result = 0, result2 = 0;
4281 while(!result && !result2)
4283 result = script->read_tag();
4286 if(script->tag.title_is("new_project"))
4288 // Run new in immediate mode.
4289 // gui->mainmenu->new_project->run_script(script);
4292 if(script->tag.title_is("record"))
4294 // Run record as a thread. It is a terminal command.
4296 // Will read the complete scipt file without letting record read it if not
4302 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4309 // ================================= synchronization
4312 int MWindow::interrupt_indexes()
4314 mainprogress->cancelled = 1;
4315 mainindexes->interrupt_build();
4321 void MWindow::next_time_format()
4323 switch(edl->session->time_format)
4325 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4326 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4327 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4328 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4329 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4330 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4331 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4334 time_format_common();
4337 void MWindow::prev_time_format()
4339 switch(edl->session->time_format)
4341 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4342 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4343 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4344 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4345 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4346 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4347 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4350 time_format_common();
4353 void MWindow::time_format_common()
4355 gui->lock_window("MWindow::next_time_format");
4356 gui->redraw_time_dependancies();
4359 char string[BCTEXTLEN], string2[BCTEXTLEN];
4360 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4361 gui->show_message(string);
4363 gui->unlock_window();
4367 int MWindow::set_filename(const char *filename)
4369 if( filename != session->filename )
4370 strcpy(session->filename, filename);
4371 if( filename != edl->path )
4372 strcpy(edl->path, filename);
4376 if(filename[0] == 0)
4378 gui->set_title(PROGRAM_NAME);
4383 char string[BCTEXTLEN], string2[BCTEXTLEN];
4384 dir.extract_name(string, filename);
4385 sprintf(string2, PROGRAM_NAME ": %s", string);
4386 gui->set_title(string2);
4399 int MWindow::set_loop_boundaries()
4401 double start = edl->local_session->get_selectionstart();
4402 double end = edl->local_session->get_selectionend();
4410 if(edl->tracks->total_length())
4413 end = edl->tracks->total_length();
4420 if(edl->local_session->loop_playback && start != end)
4422 edl->local_session->loop_start = start;
4423 edl->local_session->loop_end = end;
4434 int MWindow::reset_meters()
4436 cwindow->gui->lock_window("MWindow::reset_meters 1");
4437 cwindow->gui->meters->reset_meters();
4438 cwindow->gui->unlock_window();
4440 for(int j = 0; j < vwindows.size(); j++) {
4441 VWindow *vwindow = vwindows[j];
4442 if( !vwindow->is_running() ) continue;
4443 vwindow->gui->lock_window("MWindow::reset_meters 2");
4444 vwindow->gui->meters->reset_meters();
4445 vwindow->gui->unlock_window();
4448 lwindow->gui->lock_window("MWindow::reset_meters 3");
4449 lwindow->gui->panel->reset_meters();
4450 lwindow->gui->unlock_window();
4452 gui->lock_window("MWindow::reset_meters 4");
4453 gui->reset_meters();
4454 gui->unlock_window();
4459 void MWindow::resync_guis()
4463 gui->lock_window("MWindow::resync_guis");
4464 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4465 gui->unlock_window();
4467 cwindow->gui->lock_window("MWindow::resync_guis");
4468 cwindow->gui->resize_event(cwindow->gui->get_w(),
4469 cwindow->gui->get_h());
4470 int channels = edl->session->audio_channels;
4471 cwindow->gui->meters->set_meters(channels, 1);
4472 cwindow->gui->flush();
4473 cwindow->gui->unlock_window();
4475 for(int i = 0; i < vwindows.size(); i++) {
4476 VWindow *vwindow = vwindows[i];
4477 if( !vwindow->is_running() ) continue;
4478 vwindow->gui->lock_window("MWindow::resync_guis");
4479 vwindow->gui->resize_event(vwindow->gui->get_w(),
4480 vwindow->gui->get_h());
4481 vwindow->gui->meters->set_meters(channels, 1);
4482 vwindow->gui->flush();
4483 vwindow->gui->unlock_window();
4486 lwindow->gui->lock_window("MWindow::resync_guis");
4487 lwindow->gui->panel->set_meters(channels, 1);
4488 lwindow->gui->flush();
4489 lwindow->gui->unlock_window();
4492 if(((edl->session->output_w % 4) ||
4493 (edl->session->output_h % 4)) &&
4494 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4496 MainError::show_error(
4497 _("This project's dimensions are not multiples of 4 so\n"
4498 "it can't be rendered by OpenGL."));
4503 sync_parameters(CHANGE_ALL);
4506 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4508 File *file = new File;
4509 EDLSession *session = edl->session;
4510 double old_framerate = session->frame_rate;
4511 double old_samplerate = session->sample_rate;
4512 int old_auto_keyframes = session->auto_keyframes;
4513 session->auto_keyframes = 0;
4514 int result = file->open_file(preferences, asset, 1, 0);
4515 if( !result && delete_tracks > 0 )
4517 int video_layers = asset->get_video_layers();
4518 if( !result && asset->video_data && vstream < video_layers ) {
4519 // try to get asset up to date, may fail
4520 file->select_video_stream(asset, vstream);
4521 // either way use what was/is there.
4522 double framerate = asset->get_frame_rate();
4523 int width = asset->get_w();
4524 int height = asset->get_h();
4525 // must be multiple of 4 for opengl
4526 width = (width+3) & ~3; height = (height+3) & ~3;
4527 int driver = session->playback_config->vconfig->driver;
4528 int color_model = file->get_best_colormodel(asset, driver);
4529 // color_model = BC_CModels::is_yuv(color_model) ?
4530 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4531 // BC_CModels::is_float(color_model) ?
4532 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4533 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4534 // have alpha for now
4535 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4536 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4537 session->color_model = color_model;
4538 session->output_w = width;
4539 session->output_h = height;
4540 session->frame_rate = framerate;
4541 // not, asset->actual_width/actual_height
4542 asset->width = session->output_w;
4543 asset->height = session->output_h;
4544 asset->frame_rate = session->frame_rate;
4545 create_aspect_ratio(session->aspect_w, session->aspect_h,
4546 session->output_w, session->output_h);
4547 Track *track = edl->tracks->first;
4548 for( Track *next_track=0; track; track=next_track ) {
4549 next_track = track->next;
4550 if( track->data_type != TRACK_VIDEO ) continue;
4551 if( delete_tracks ) {
4552 Edit *edit = track->edits->first;
4553 for( Edit *next_edit=0; edit; edit=next_edit ) {
4554 next_edit = edit->next;
4555 if( edit->channel != vstream ||
4556 !edit->asset || !edit->asset->is_asset ||
4557 !asset->equivalent(*edit->asset,1,1,edl) )
4561 if( track->edits->first ) {
4562 track->track_w = edl->session->output_w;
4563 track->track_h = edl->session->output_h;
4565 else if( delete_tracks )
4566 edl->tracks->delete_track(track);
4569 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4571 if( !result && asset->audio_data && asset->channels > 0 ) {
4572 session->sample_rate = asset->get_sample_rate();
4573 int64_t channel_mask = 0;
4574 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4575 file->get_audio_for_video(vstream, astream, channel_mask);
4576 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4577 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4579 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4580 if( channels < 1 ) channels = 1;
4581 if( channels > 6 ) channels = 6;
4582 session->audio_tracks = session->audio_channels = channels;
4584 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4585 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4586 remap_audio(MWindow::AUDIO_1_TO_1);
4588 if( delete_tracks ) {
4589 Track *track = edl->tracks->first;
4590 for( Track *next_track=0; track; track=next_track ) {
4591 next_track = track->next;
4592 if( track->data_type != TRACK_AUDIO ) continue;
4593 Edit *edit = track->edits->first;
4594 for( Edit *next_edit=0; edit; edit=next_edit ) {
4595 next_edit = edit->next;
4596 if( !((1<<edit->channel) & channel_mask) ||
4597 !edit->asset || !edit->asset->is_asset ||
4598 !asset->equivalent(*edit->asset,1,1,edl) )
4601 if( !track->edits->first )
4602 edl->tracks->delete_track(track);
4606 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4609 session->auto_keyframes = old_auto_keyframes;
4610 if( !result && delete_tracks > 0 ) {
4612 undo_after(_("select asset"), LOAD_ALL);
4618 int MWindow::select_asset(int vtrack, int delete_tracks)
4620 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4622 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4623 if( !track ) return 1;
4624 Edit *edit = track->edits->first;
4625 if( !edit ) return 1;
4626 Asset *asset = edit->asset;
4627 if( !asset || !asset->is_asset ) return 1;
4628 return select_asset(asset, edit->channel, 0, delete_tracks);
4631 void MWindow::dump_plugindb(FILE *fp)
4633 if( !plugindb ) return;
4634 for(int i = 0; i < plugindb->total; i++)
4635 plugindb->get(i)->dump(fp);
4638 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4641 double unit_position = edl->local_session->get_selectionstart(1);
4642 unit_position = patch->track->to_units(unit_position, 0);
4644 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4645 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4648 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4651 double unit_position = edl->local_session->get_selectionstart(1);
4652 unit_position = patch->track->to_units(unit_position, 0);
4654 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4655 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4658 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4661 double unit_position = edl->local_session->get_selectionstart(1);
4662 unit_position = patch->track->to_units(unit_position, 0);
4664 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4665 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4668 PatchGUI *MWindow::get_patchgui(Track *track)
4670 PatchGUI *patchgui = 0;
4671 TimelinePane **panes = gui->pane;
4672 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4673 if( !panes[i] ) continue;
4674 PatchBay *patchbay = panes[i]->patchbay;
4675 if( !patchbay ) continue;
4676 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4677 if( patchbay->patches.values[j]->track == track )
4678 patchgui = patchbay->patches.values[j];