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 "bccmodels.h"
31 #include "bcdisplayinfo.h"
32 #include "bcprogressbox.h"
33 #include "bcsignals.h"
40 #include "channeldb.h"
41 #include "channelinfo.h"
44 #include "commercials.h"
45 #include "confirmsave.h"
47 #include "cplayback.h"
49 #include "cwindowgui.h"
51 #include "cwindowtool.h"
53 #include "devicedvbinput.inc"
54 #include "dvdcreate.h"
55 #include "editpanel.h"
57 #include "edlsession.h"
59 #include "fileformat.h"
61 #include "filesystem.h"
63 #include "floatautos.h"
64 #include "framecache.h"
66 #include "gwindowgui.h"
67 #include "keyframegui.h"
68 #include "indexfile.h"
70 #include "interlacemodes.h"
72 #include "levelwindowgui.h"
73 #include "levelwindow.h"
74 #include "loadfile.inc"
75 #include "localsession.h"
76 #include "maincursor.h"
77 #include "mainerror.h"
78 #include "mainindexes.h"
80 #include "mainprogress.h"
81 #include "mainsession.h"
84 #include "mixersalign.h"
86 #include "mwindowgui.h"
91 #include "playback3d.h"
92 #include "playbackengine.h"
94 #include "pluginserver.h"
95 #include "pluginset.h"
96 #include "preferences.h"
99 #include "recordmonitor.h"
100 #include "recordlabel.h"
101 #include "removefile.h"
103 #include "resourcethread.h"
104 #include "savefile.inc"
105 #include "samplescroll.h"
108 #include "sighandler.h"
109 #include "splashgui.h"
110 #include "statusbar.h"
112 #include "threadloader.h"
114 #include "timelinepane.h"
115 #include "tipwindow.h"
116 #include "trackcanvas.h"
118 #include "tracking.h"
119 #include "trackscroll.h"
121 #include "transition.h"
122 #include "transportque.h"
125 #include "versioninfo.h"
127 #include "videodevice.inc"
128 #include "videowindow.h"
129 #include "vplayback.h"
130 #include "vwindowgui.h"
132 #include "wavecache.h"
136 #include "zwindowgui.h"
137 #include "exportedl.h"
139 #include "defaultformats.h"
140 #include "ntsczones.h"
147 #include <sys/types.h>
148 #include <sys/stat.h>
149 #include <sys/time.h>
150 #include <sys/mman.h>
151 #include <sys/file.h>
162 // Hack for libdv to remove glib dependancy
165 // g_log (const char *log_domain,
167 // const char *format,
173 // g_logv (const char *log_domain,
175 // const char *format,
184 extern long cin_timezone;
186 ArrayList<PluginServer*>* MWindow::plugindb = 0;
187 Commercials* MWindow::commercials = 0;
193 run_lock = new Mutex("MWindow::run_lock");
194 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
195 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
196 vwindows_lock = new Mutex("MWindow::vwindows_lock");
197 zwindows_lock = new Mutex("MWindow::zwindows_lock");
198 brender_lock = new Mutex("MWindow::brender_lock");
199 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
204 undo_command = COMMAND_NONE;
208 commercial_active = 0;
220 strcpy(cin_lang,"en");
221 channeldb_buz = new ChannelDB;
222 channeldb_v4l2jpeg = new ChannelDB;
225 keyframe_threads = 0;
250 // Need to delete brender temporary here.
253 run_lock->lock("MWindow::~MWindow");
255 //printf("MWindow::~MWindow %d\n", __LINE__);
256 if( wwindow && wwindow->is_running() )
257 wwindow->close_window();
258 if( twindow && twindow->is_running() )
259 twindow->close_window();
260 gui->remote_control->deactivate();
263 gui->channel_info->stop();
266 delete create_bd; create_bd = 0;
267 delete create_dvd; create_dvd = 0;
268 delete shuttle; shuttle = 0;
269 delete batch_render; batch_render = 0;
270 delete convert_render; convert_render = 0;
271 delete render; render = 0;
272 delete mixers_align; mixers_align = 0;
274 if( commercials && !commercials->remove_user() ) commercials = 0;
276 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
277 // Save defaults for open plugins
278 plugin_gui_lock->lock("MWindow::~MWindow");
279 for(int i = 0; i < plugin_guis->size(); i++) {
280 plugin_guis->get(i)->hide_gui();
281 delete_plugin(plugin_guis->get(i));
283 plugin_gui_lock->unlock();
284 hide_keyframe_guis();
287 // Give up and go to a movie
288 // cant run valgrind if this is used
290 gui->del_keyboard_listener(
291 (int (BC_WindowBase::*)(BC_WindowBase *))
292 &MWindowGUI::keyboard_listener);
294 // release the hounds
295 if( awindow && awindow->gui ) awindow->gui->close(0);
296 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
297 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
298 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
299 vwindows.remove_all_objects();
300 zwindows.remove_all_objects();
302 if( awindow ) awindow->join();
303 if( cwindow ) cwindow->join();
304 if( lwindow ) lwindow->join();
305 if( gwindow ) gwindow->join();
308 // one at a time, or nouveau chokes
309 #define close_gui(win) if( win ) { \
310 if( win->gui ) win->gui->close(0); \
316 vwindows.remove_all_objects();
317 zwindows.remove_all_objects();
322 dead_plugins->remove_all_objects();
323 // must delete theme before destroying plugindb
324 // theme destructor will be deleted by delete_plugins
325 delete theme; theme = 0;
328 keyframe_threads->remove_all_objects();
329 colormodels.remove_all_objects();
330 delete awindow; awindow = 0;
331 delete lwindow; lwindow = 0;
332 delete twindow; twindow = 0;
333 delete wwindow; wwindow = 0;
334 delete gwindow; gwindow = 0;
335 delete cwindow; cwindow = 0;
337 delete mainindexes; mainindexes = 0;
338 delete mainprogress; mainprogress = 0;
339 delete audio_cache; audio_cache = 0; // delete the cache after the assets
340 delete video_cache; video_cache = 0; // delete the cache after the assets
341 delete frame_cache; frame_cache = 0;
342 delete wave_cache; wave_cache = 0;
343 delete plugin_guis; plugin_guis = 0;
344 delete dead_plugins; dead_plugins = 0;
345 delete keyframe_threads; keyframe_threads = 0;
346 delete undo; undo = 0;
347 delete preferences; preferences = 0;
348 delete exportedl; exportedl = 0;
349 delete session; session = 0;
350 delete defaults; defaults = 0;
351 delete assets; assets = 0;
352 delete splash_window; splash_window = 0;
353 if( !edl->Garbage::remove_user() ) edl = 0;
354 delete channeldb_buz;
355 delete channeldb_v4l2jpeg;
356 // This must be last thread to exit
357 delete playback_3d; playback_3d = 0;
358 delete dead_plugin_lock;
359 delete plugin_gui_lock;
360 delete vwindows_lock;
361 delete zwindows_lock;
363 delete keyframe_gui_lock;
364 colormodels.remove_all_objects();
365 interlace_project_modes.remove_all_objects();
366 interlace_asset_modes.remove_all_objects();
367 sighandler->terminate();
378 void MWindow::init_error()
380 MainError::init_error(this);
383 void MWindow::finit_error()
385 MainError::finit_error();
388 void MWindow::create_defaults_path(char *string, const char *config_file)
390 // set the .bcast path
393 sprintf(string, "%s/", File::get_config_path());
394 fs.complete_path(string);
395 if(!fs.is_dir(string))
396 fs.create_dir(string);
399 strcat(string, config_file);
401 const char *MWindow::default_std()
403 char buf[BCTEXTLEN], *p = 0;
405 int fd = open(TIMEZONE_NAME, O_RDONLY);
407 int l = read(fd, buf, sizeof(buf)-1);
410 if( buf[l-1] == '\n' ) --l;
416 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
419 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
420 p += strlen(ZONEINFO_STR);
425 for( int i=0; ntsc_zones[i]; ++i ) {
426 if( !strcmp(ntsc_zones[i], p) )
433 for( int i=0; ntsc_zones[i]; ++i ) {
434 if( !strcmp(ntsc_zones[i], p) )
439 // cin_timezone: Seconds west of UTC. 240sec/deg
440 double tz_deg = -cin_timezone / 240.;
441 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
442 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
445 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
447 struct formatpresets *fpr;
449 for(fpr = &format_presets[0]; fpr->name; fpr++)
451 if(strcmp(_(fpr->name), preset) == 0)
453 session->audio_channels = fpr->audio_channels;
454 session->audio_tracks = fpr->audio_tracks;
455 session->sample_rate = fpr->sample_rate;
456 session->video_channels = fpr->video_channels;
457 session->video_tracks = fpr->video_tracks;
458 session->frame_rate = fpr->frame_rate;
459 session->output_w = fpr->output_w;
460 session->output_h = fpr->output_h;
461 session->aspect_w = fpr->aspect_w;
462 session->aspect_h = fpr->aspect_h;
463 session->interlace_mode = fpr->interlace_mode;
464 session->color_model = fpr->color_model;
470 const char *MWindow::get_preset_name(int index)
472 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
474 return _(format_presets[index].name);
478 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
480 char path[BCTEXTLEN];
481 // Use user supplied path
483 strcpy(path, config_path);
485 create_defaults_path(path, CONFIG_FILE);
488 defaults = new BC_Hash(path);
493 void MWindow::check_language()
495 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
496 const char *env_lang = getenv("LANGUAGE");
497 if( !env_lang ) env_lang = getenv("LC_ALL");
498 if( !env_lang ) env_lang = getenv("LANG");
500 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
501 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
502 env_lang = curr_lang;
504 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
505 defaults->get("LAST_LANG",last_lang);
506 if( strcmp(env_lang,last_lang)) {
507 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
508 defaults->update("LAST_LANG",env_lang);
509 char plugin_path[BCTEXTLEN];
510 create_defaults_path(plugin_path, PLUGIN_FILE);
511 ::remove(plugin_path);
512 char ladspa_path[BCTEXTLEN];
513 create_defaults_path(ladspa_path, LADSPA_FILE);
514 ::remove(ladspa_path);
517 if( strlen(env_lang) > 1 &&
518 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
519 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
522 strcpy(cin_lang, "en");
525 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
527 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
529 const char *dp = plug_dir;
530 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
531 bp = !*dp && *bp == '/' ? bp+1 : base_path;
537 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir)
541 fseek(fp, 0, SEEK_SET);
543 char index_line[BCTEXTLEN];
544 int index_version = -1, len = strlen(plugin_dir);
545 if( !fgets(index_line, BCTEXTLEN, fp) ||
546 sscanf(index_line, "%d", &index_version) != 1 ||
547 index_version != PLUGIN_FILE_VERSION ||
548 !fgets(index_line, BCTEXTLEN, fp) ||
549 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
550 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
552 ArrayList<PluginServer*> plugins;
553 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
554 if( index_line[0] == ';' ) continue;
555 if( index_line[0] == '#' ) continue;
556 int type = PLUGIN_TYPE_UNKNOWN;
557 char path[BCTEXTLEN], title[BCTEXTLEN];
559 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
562 PluginServer *server = 0;
564 case PLUGIN_TYPE_BUILTIN:
565 case PLUGIN_TYPE_EXECUTABLE:
566 case PLUGIN_TYPE_LADSPA: {
567 char plugin_path[BCTEXTLEN]; struct stat st;
568 sprintf(plugin_path, "%s/%s", plugin_dir, path);
569 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
572 server = new PluginServer(mwindow, plugin_path, type);
574 case PLUGIN_TYPE_FFMPEG: {
575 server = new_ffmpeg_server(mwindow, path);
577 case PLUGIN_TYPE_LV2: {
578 server = new_lv2_server(mwindow, path);
581 if( !server ) continue;
582 plugins.append(server);
583 // Create plugin server from index entry
584 server->set_title(title);
585 if( server->read_table(index_line) ) {
591 ret = check_plugin_index(plugins, plugin_dir, ".");
594 add_plugins(plugins);
596 plugins.remove_all_objects();
601 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
602 const char *plug_dir, const char *plug_path)
604 char plugin_path[BCTEXTLEN];
605 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
607 fs.set_filter( "[*.plugin][*.so]" );
608 if( fs.update(plugin_path) )
611 for( int i=0; i<fs.dir_list.total; ++i ) {
612 char fs_path[BCTEXTLEN];
613 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
614 if( fs.is_dir(fs_path) ) {
615 get_plugin_path(plugin_path, plug_dir, fs_path);
616 if( check_plugin_index(plugins, plug_dir, plugin_path) )
619 else if( !plugin_exists(fs_path, plugins) )
626 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
629 plugindb = new ArrayList<PluginServer*>;
631 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
632 create_defaults_path(index_path, PLUGIN_FILE);
633 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
634 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
635 FILE *fp = fopen(index_path,"a+");
637 fprintf(stderr,_("MWindow::init_plugins: "
638 "can't open plugin index: %s\n"), index_path);
641 int fd = fileno(fp), ret = -1;
642 if( !flock(fd, LOCK_EX) ) {
643 fseek(fp, 0, SEEK_SET);
644 ret = load_plugin_index(mwindow, fp, plugin_path);
648 fseek(fp, 0, SEEK_SET);
649 printf("init plugin index: %s\n", plugin_path);
650 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
651 fprintf(fp, "%s\n", plugin_path);
652 init_plugin_index(mwindow, preferences, fp, plugin_path);
653 init_ffmpeg_index(mwindow, preferences, fp);
654 init_lv2_index(mwindow, preferences, fp);
655 fseek(fp, 0, SEEK_SET);
656 ret = load_plugin_index(mwindow, fp, plugin_path);
659 fprintf(stderr,_("MWindow::init_plugins: "
660 "can't %s plugin index: %s\n"),
661 ret>0 ? _("create") : _("lock"), index_path);
667 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
669 char *path = getenv("LADSPA_PATH");
670 char ladspa_path[BCTEXTLEN];
672 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
675 for( int len=0; *path; path+=len ) {
676 char *cp = strchr(path,':');
677 len = !cp ? strlen(path) : cp-path;
678 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
679 memcpy(plugin_path, path, len); plugin_path[len] = 0;
681 char *plugin_dir = FileSystem::basepath(plugin_path);
682 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
683 create_defaults_path(index_path, LADSPA_FILE);
684 cp = index_path + strlen(index_path);
685 for( char *bp=plugin_path; *bp!=0; ++bp )
686 *cp++ = *bp=='/' ? '_' : *bp;
688 FILE *fp = fopen(index_path,"a+");
690 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
691 "can't open ladspa plugin index: %s\n"), index_path);
694 int fd = fileno(fp), ret = -1;
695 if( !flock(fd, LOCK_EX) ) {
696 fseek(fp, 0, SEEK_SET);
697 ret = load_plugin_index(mwindow, fp, plugin_path);
701 fseek(fp, 0, SEEK_SET);
702 init_ladspa_index(mwindow, preferences, fp, plugin_path);
703 fseek(fp, 0, SEEK_SET);
704 ret = load_plugin_index(mwindow, fp, plugin_path);
707 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
708 "can't %s ladspa plugin index: %s\n"),
709 ret>0 ? _("create") : _("lock"), index_path);
716 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
717 FILE *fp, const char *plugin_dir)
719 int idx = PLUGIN_IDS;
721 for( int i=0; i<plugindb->size(); ++i ) {
722 PluginServer *server = plugindb->get(i);
723 if( server->dir_idx >= idx )
724 idx = server->dir_idx+1;
727 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
730 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
731 const char *plug_dir, const char *plug_path, int &idx)
733 char plugin_path[BCTEXTLEN];
734 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
736 fs.set_filter( "[*.plugin][*.so]" );
737 int result = fs.update(plugin_path);
738 if( result || !fs.dir_list.total ) return;
741 for( int i=0; i<fs.dir_list.total; ++i ) {
742 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
743 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
744 get_plugin_path(path, plug_dir, fs_path);
745 if( fs.is_dir(fs_path) ) {
746 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
749 if( plugin_exists(path) ) continue;
751 if( stat(fs_path, &st) ) continue;
752 int64_t mtime = st.st_mtime;
753 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
754 result = server.open_plugin(1, preferences, 0, 0);
756 server.write_table(fp, path, vis_id, mtime);
757 server.close_plugin();
759 else if( result == PLUGINSERVER_IS_LAD ) {
762 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
763 ladspa.set_lad_index(lad_index++);
764 result = ladspa.open_plugin(1, preferences, 0, 0);
766 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
767 ladspa.close_plugin();
773 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
775 for( int i=0; i<plugins.size(); ++i )
776 plugindb->append(plugins[i]);
777 plugins.remove_all();
780 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
782 const char *dat_path = File::get_cindat_path();
783 char msg_path[BCTEXTLEN];
785 if( BC_Resources::language[0] ) {
786 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
788 fp = fopen(msg_path, "r");
791 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
793 fp = fopen(msg_path, "r");
796 char text[BCTEXTLEN];
797 char *tp = text, *ep = tp + sizeof(text)-1;
798 char title[BCTEXTLEN];
803 char line[BCTEXTLEN], *cp = line;
804 if( fgets(line,sizeof(line)-1,fp) ) {
805 if( *cp == '#' ) continue;
806 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
809 if( tp > text && *--tp == '\n' ) *tp = 0;
811 int idx = plugins.size();
812 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
814 delete [] plugins[idx]->tip;
815 plugins[idx]->tip = cstrdup(text);
819 if( done > 0 ) break;
821 char *dp = strchr(cp, ':');
823 printf("plugin tips: error on line %d\n", no);
827 while( cp < dp ) *bp++ = *cp++;
832 while( *cp == ' ' || *cp == '\t' ) ++cp;
833 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
838 void MWindow::delete_plugins()
840 plugindb->remove_all_objects();
845 void MWindow::search_plugindb(int do_audio,
850 ArrayList<PluginServer*> &results)
853 for(int i = 0; i < MWindow::plugindb->total; i++)
855 PluginServer *current = MWindow::plugindb->get(i);
857 if(current->audio == do_audio &&
858 current->video == do_video &&
859 (current->realtime == is_realtime || is_realtime < 0) &&
860 current->transition == is_transition &&
861 current->theme == is_theme)
862 results.append(current);
865 // Alphabetize list by title
871 for(int i = 0; i < results.total - 1; i++)
873 PluginServer *value1 = results[i];
874 PluginServer *value2 = results[i + 1];
875 if(strcmp(_(value1->title), _(value2->title)) > 0)
879 results[i + 1] = value1;
885 PluginServer* MWindow::scan_plugindb(char *title,
890 // printf("MWindow::scan_plugindb data_type < 0\n");
894 for(int i = 0; i < plugindb->total; i++)
896 PluginServer *server = plugindb->get(i);
898 !strcasecmp(server->title, title) &&
900 (data_type == TRACK_AUDIO && server->audio) ||
901 (data_type == TRACK_VIDEO && server->video)))
902 return plugindb->get(i);
907 // repair session files with xlated plugin titles
908 void MWindow::fix_plugin_title(char *title)
910 for(int i = 0; i < plugindb->total; i++) {
911 PluginServer *server = plugindb->get(i);
912 if( !server->title ) continue;
913 const char *server_title = server->title;
914 if( !bstrcasecmp(title, _(server_title)) ) {
915 strcpy(title, server_title);
921 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
923 for( int i=0; i<plugins.size(); ++i )
924 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
928 int MWindow::plugin_exists(char *plugin_path)
930 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
933 void MWindow::remove_plugin_index()
935 char index_path[BCTEXTLEN];
936 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
937 ::remove(index_path);
940 void MWindow::init_preferences()
942 preferences = new Preferences;
943 preferences->load_defaults(defaults);
944 File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
945 session = new MainSession(this);
946 session->load_defaults(defaults);
947 // set x11_host, screens, window_config
948 screens = session->set_default_x11_host();
949 BC_Signals::set_trap_hook(trap_hook, this);
950 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
951 BC_Signals::set_catch_intr(preferences->trap_sigintr);
952 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
953 BC_Trace::enable_locks();
956 BC_Trace::disable_locks();
958 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
959 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
960 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
961 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
964 void MWindow::clean_indexes()
969 int oldest_item = -1;
971 char string[BCTEXTLEN];
972 char string2[BCTEXTLEN];
974 // Delete extra indexes
975 fs.set_filter("*.idx");
976 fs.complete_path(preferences->index_directory);
977 fs.update(preferences->index_directory);
978 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
980 // Eliminate directories
985 for(int i = 0; i < fs.dir_list.total && !result; i++)
987 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
988 if(fs.is_dir(string))
990 delete fs.dir_list[i];
991 fs.dir_list.remove_number(i);
996 total_excess = fs.dir_list.total - preferences->index_count;
998 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
999 while(total_excess > 0)
1002 for(int i = 0; i < fs.dir_list.total; i++)
1004 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1006 if(i == 0 || fs.get_date(string) <= oldest)
1008 oldest = fs.get_date(string);
1013 if(oldest_item >= 0)
1015 // Remove index file
1016 fs.join_names(string,
1017 preferences->index_directory,
1018 fs.dir_list[oldest_item]->name);
1019 //printf("MWindow::clean_indexes 1 %s\n", string);
1021 perror("delete_indexes");
1022 delete fs.dir_list[oldest_item];
1023 fs.dir_list.remove_number(oldest_item);
1025 // Remove table of contents if it exists
1026 strcpy(string2, string);
1027 char *ptr = strrchr(string2, '.');
1030 //printf("MWindow::clean_indexes 2 %s\n", string2);
1031 sprintf(ptr, ".toc");
1033 sprintf(ptr, ".mkr");
1042 void MWindow::init_awindow()
1044 awindow = new AWindow(this);
1045 awindow->create_objects();
1048 void MWindow::init_gwindow()
1050 gwindow = new GWindow(this);
1051 gwindow->create_objects();
1054 void MWindow::init_tipwindow()
1056 TipWindow::load_tips(cin_lang);
1058 twindow = new TipWindow(this);
1062 void MWindow::show_warning(int *do_warning, const char *text)
1064 if( do_warning && !*do_warning ) return;
1066 wwindow = new WWindow(this);
1067 wwindow->show_warning(do_warning, text);
1070 int MWindow::wait_warning()
1072 return wwindow->wait_result();
1075 void MWindow::init_theme()
1080 PluginServer *theme_plugin = 0;
1081 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1082 if( plugindb->get(i)->theme &&
1083 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1084 theme_plugin = plugindb->get(i);
1088 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1089 preferences->theme);
1091 const char *default_theme = DEFAULT_THEME;
1092 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1093 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1095 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1096 if( plugindb->get(i)->theme &&
1097 !strcasecmp(default_theme, plugindb->get(i)->title) )
1098 theme_plugin = plugindb->get(i);
1103 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1107 PluginServer *plugin = new PluginServer(*theme_plugin);
1108 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1109 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1110 theme_plugin->title);
1114 theme = plugin->new_theme();
1115 theme->mwindow = this;
1116 strcpy(theme->path, plugin->path);
1119 // Load default images & settings
1120 theme->Theme::initialize();
1121 // Load user images & settings
1122 theme->initialize();
1123 // Create menus with user colors
1124 theme->build_menus();
1127 theme->sort_image_sets();
1128 theme->check_used();
1129 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1132 void MWindow::init_3d()
1134 playback_3d = new Playback3D(this);
1135 playback_3d->create_objects();
1138 void MWindow::init_edl()
1141 edl->create_objects();
1142 fill_preset_defaults(default_standard, edl->session);
1143 edl->load_defaults(defaults);
1144 edl->session->brender_start = edl->session->brender_end = 0;
1145 edl->create_default_tracks();
1146 edl->tracks->update_y_pixels(theme);
1149 void MWindow::init_compositor()
1151 cwindow = new CWindow(this);
1152 cwindow->create_objects();
1155 void MWindow::init_levelwindow()
1157 lwindow = new LevelWindow(this);
1158 lwindow->create_objects();
1161 VWindow *MWindow::get_viewer(int start_it, int idx)
1163 vwindows_lock->lock("MWindow::get_viewer");
1164 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1165 if( !vwindow ) idx = vwindows.size();
1166 while( !vwindow && --idx >= 0 ) {
1167 VWindow *vwin = vwindows[idx];
1168 if( !vwin->is_running() || !vwin->get_edl() )
1172 vwindow = new VWindow(this);
1173 vwindow->load_defaults();
1174 vwindow->create_objects();
1175 vwindows.append(vwindow);
1177 vwindows_lock->unlock();
1178 if( start_it ) vwindow->start();
1182 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1184 zwindows_lock->lock("MWindow::get_mixer");
1185 if( !mixer ) mixer = edl->mixers.new_mixer();
1186 ZWindow *zwindow = 0;
1187 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1188 ZWindow *zwdw = zwindows[i];
1189 if( zwdw->running() ) continue;
1190 if( zwdw->idx >= 0 ) continue;
1191 zwindow = zwindows[i];
1194 zwindows.append(zwindow = new ZWindow(this));
1195 zwindow->idx = mixer->idx;
1196 zwindows_lock->unlock();
1200 void MWindow::del_mixer(ZWindow *zwindow)
1202 zwindows_lock->lock("MWindow::del_mixer 0");
1203 edl->mixers.del_mixer(zwindow->idx);
1204 if( session->selected_zwindow >= 0 ) {
1205 int i = zwindows.number_of(zwindow);
1206 if( i >= 0 && i < session->selected_zwindow )
1207 --session->selected_zwindow;
1208 else if( i == session->selected_zwindow )
1209 session->selected_zwindow = -1;
1211 zwindows_lock->unlock();
1212 gui->lock_window("MWindow::del_mixer 1");
1213 gui->update_mixers(0, -1);
1214 gui->unlock_window();
1217 void MWindow::start_mixer()
1220 ZWindow *zwindow = get_mixer(mixer);
1221 const char *title = 0;
1223 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1224 PatchGUI *patchgui = get_patchgui(track);
1225 if( !patchgui || !patchgui->mixer ) continue;
1226 mixer->mixer_ids.append(track->get_mixer_id());
1227 if( !title ) title = track->title;
1230 session->selected_zwindow = -1;
1231 gui->lock_window("MWindow::start_mixer");
1232 gui->update_mixers(0, 0);
1233 gui->unlock_window();
1235 zwindow->set_title(title);
1240 int MWindow::mixer_track_active(Track *track)
1242 int i = session->selected_zwindow;
1243 if( i < 0 || i >= zwindows.size() ) return 0;
1244 ZWindow *zwindow = zwindows[i];
1245 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1246 if( !mixer ) return 0;
1247 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1248 return n >= 0 ? 1 : 0;
1251 void MWindow::update_mixer_tracks()
1253 zwindows_lock->lock("MixPatch::handle_event");
1254 int i = session->selected_zwindow;
1255 if( i >= 0 && i < zwindows.size() ) {
1256 ZWindow *zwindow = zwindows[i];
1257 zwindow->update_mixer_ids();
1259 zwindows_lock->unlock();
1262 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1263 int use_inout, int toggle_audio, int loop_play, float speed)
1265 zwindows_lock->lock("MWindow::handle_mixers");
1266 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1267 ZWindow *zwindow = zwindows[vidx];
1268 if( zwindow->idx < 0 ) continue;
1269 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1270 if( !mixer || !mixer->mixer_ids.size() ) continue;
1272 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1273 if( track->data_type != TRACK_VIDEO ) continue;
1274 int mixer_id = track->get_mixer_id();
1275 k = mixer->mixer_ids.size();
1276 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1278 if( k < 0 ) continue;
1279 EDL *mixer_edl = new EDL(this->edl);
1280 mixer_edl->create_objects();
1281 mixer_edl->copy_all(edl);
1282 mixer_edl->remove_vwindow_edls();
1283 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1284 k = mixer->mixer_ids.size();
1285 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1288 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1291 track->record = track->play = 0;
1293 zwindow->change_source(mixer_edl);
1294 zwindow->handle_mixer(command, 0,
1295 use_inout, toggle_audio, loop_play, speed);
1297 zwindows_lock->unlock();
1300 void MWindow::refresh_mixers(int dir)
1302 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1303 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1306 void MWindow::stop_mixers()
1308 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1309 ZWindow *zwindow = zwindows[vidx];
1310 if( zwindow->idx < 0 ) continue;
1311 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1315 void MWindow::close_mixers(int destroy)
1317 ArrayList<ZWindow*> closed;
1318 zwindows_lock->lock("MWindow::close_mixers");
1319 for( int i=zwindows.size(); --i>=0; ) {
1320 ZWindow *zwindow = zwindows[i];
1321 if( zwindow->idx < 0 ) continue;
1323 zwindow->destroy = destroy;
1324 ZWindowGUI *zgui = zwindow->zgui;
1325 zgui->lock_window("MWindow::select_zwindow 0");
1327 zgui->unlock_window();
1328 closed.append(zwindow);
1330 zwindows_lock->unlock();
1331 for( int i=0; i<closed.size(); ++i ) {
1332 ZWindow *zwindow = closed[i];
1337 ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
1339 ArrayList<Indexable*> new_assets;
1340 new_assets.append(indexable);
1341 Track *track = edl->tracks->last;
1342 load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
1343 track = !track ? edl->tracks->first : track->next;
1345 ZWindow *zwindow = get_mixer(mixer);
1347 track->play = track->record = 0;
1348 if( track->data_type == TRACK_VIDEO ) {
1349 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1351 mixer->mixer_ids.append(track->get_mixer_id());
1352 track = track->next;
1354 if( indexable->is_asset ) {
1355 char *path = indexable->path;
1356 char *tp = strrchr(path, '/');
1357 if( !tp ) tp = path; else ++tp;
1358 zwindow->set_title(tp);
1361 char *title = ((EDL*)indexable)->local_session->clip_title;
1362 zwindow->set_title(title);
1367 void MWindow::create_mixers(double position)
1369 if( !session->drag_assets->size() &&
1370 !session->drag_clips->size() ) return;
1374 ArrayList<ZWindow *>new_mixers;
1376 for( int i=0; i<session->drag_assets->size(); ++i ) {
1377 Indexable *indexable = session->drag_assets->get(i);
1378 if( !indexable->have_video() ) continue;
1379 ZWindow *zwindow = create_mixer(indexable, position);
1380 new_mixers.append(zwindow);
1382 for( int i=0; i<session->drag_clips->size(); ++i ) {
1383 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1384 if( !indexable->have_video() ) continue;
1385 ZWindow *zwindow = create_mixer(indexable, position);
1386 new_mixers.append(zwindow);
1390 for( int i=0; i<new_mixers.size(); ++i )
1391 new_mixers[i]->start();
1395 undo_after(_("create mixers"), LOAD_ALL);
1397 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1398 sync_parameters(CHANGE_ALL);
1401 void MWindow::open_mixers()
1403 for( int i=0; i<edl->mixers.size(); ++i ) {
1404 Mixer *mixer = edl->mixers[i];
1405 ZWindow *zwindow = get_mixer(mixer);
1406 zwindow->set_title(mixer->title);
1412 int MWindow::select_zwindow(ZWindow *zwindow)
1414 int ret = 0, n = zwindows.number_of(zwindow);
1415 if( session->selected_zwindow != n ) {
1416 session->selected_zwindow = n;
1417 for( int i=0; i<zwindows.size(); ++i ) {
1418 ZWindow *zwindow = zwindows[i];
1419 if( zwindow->idx < 0 ) continue;
1420 ZWindowGUI *zgui = zwindow->zgui;
1421 zgui->lock_window("MWindow::select_zwindow 0");
1422 zwindow->highlighted = i == n ? 1 : 0;
1423 if( zgui->draw_overlays() )
1424 zgui->canvas->get_canvas()->flash(1);
1425 zgui->unlock_window();
1428 gui->lock_window("MWindow::select_window 1");
1429 gui->update_mixers(0, -1);
1430 gui->unlock_window();
1435 void MWindow::tile_mixers()
1438 for( int i=0; i<zwindows.size(); ++i ) {
1439 ZWindow *zwindow = zwindows[i];
1440 if( zwindow->idx < 0 ) continue;
1444 int zn = ceil(sqrt(nz));
1445 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1446 int y1 = 1, y2 = gui->get_y();
1447 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1448 if( x1 < 0 ) x1 = 0;
1449 if( y1 < 0 ) y1 = 0;
1450 if( x2 > rw ) x2 = rw;
1451 if( y2 > rh ) y2 = rh;
1452 int dx = x2 - x1, dy = y2 - y1;
1454 int lt = BC_DisplayInfo::get_left_border();
1455 int top = BC_DisplayInfo::get_top_border();
1456 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1457 int bh = top + BC_DisplayInfo::get_bottom_border();
1458 int zx = 0, zy = 0; // window origins
1459 int mw = xS(10+10), mh = yS(10+10); // canvas margins
1460 int rsz = 0, n = 0, dz = 0;
1461 int ow = edl->session->output_w, oh = edl->session->output_h;
1462 for( int i=0; i<zwindows.size(); ++i ) {
1463 ZWindow *zwindow = zwindows[i];
1464 if( zwindow->idx < 0 ) continue;
1465 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1466 if( rsz < hh ) rsz = hh;
1467 int xx = zx + x1, yy = zy + y1;
1468 int mx = x2 - zw, my = y2 - zh;
1469 if( xx > mx ) xx = mx;
1470 if( yy > my ) yy = my;
1471 xx += lt + xS(dz); yy += top + yS(dz);
1472 zwindow->reposition(xx,yy, ww,hh);
1473 if( zwindow->running() ) {
1474 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1475 gui->lock_window("MWindow::tile_mixers");
1476 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1477 gui->unlock_window();
1481 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1490 void MWindow::init_cache()
1492 audio_cache = new CICache(preferences);
1493 video_cache = new CICache(preferences);
1494 frame_cache = new FrameCache;
1495 wave_cache = new WaveCache;
1498 void MWindow::init_channeldb()
1500 channeldb_buz->load("channeldb_buz");
1501 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1504 void MWindow::init_menus()
1506 char string[BCTEXTLEN];
1509 BC_CModels::to_text(string, BC_RGB888);
1510 colormodels.append(new ColormodelItem(string, BC_RGB888));
1511 BC_CModels::to_text(string, BC_RGBA8888);
1512 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1513 // BC_CModels::to_text(string, BC_RGB161616);
1514 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1515 // BC_CModels::to_text(string, BC_RGBA16161616);
1516 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1517 BC_CModels::to_text(string, BC_RGB_FLOAT);
1518 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1519 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1520 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1521 BC_CModels::to_text(string, BC_YUV888);
1522 colormodels.append(new ColormodelItem(string, BC_YUV888));
1523 BC_CModels::to_text(string, BC_YUVA8888);
1524 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1525 // BC_CModels::to_text(string, BC_YUV161616);
1526 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1527 // BC_CModels::to_text(string, BC_YUVA16161616);
1528 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1530 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1531 interlace_project_modes.append(new InterlacemodeItem(string, x));
1533 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1534 interlace_asset_modes.append(new InterlacemodeItem(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 mixers_align = new MixersAlign(this);
1551 void MWindow::init_indexes()
1553 mainindexes = new MainIndexes(this);
1554 mainindexes->start_loop();
1557 void MWindow::init_gui()
1559 gui = new MWindowGUI(this);
1560 gui->create_objects();
1561 gui->load_defaults(defaults);
1564 void MWindow::init_signals()
1566 sighandler = new SigHandler;
1567 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1571 void MWindow::init_render()
1573 render = new Render(this);
1574 create_bd = new CreateBD_Thread(this);
1575 create_dvd = new CreateDVD_Thread(this);
1576 batch_render = new BatchRenderThread(this);
1579 void MWindow::init_exportedl()
1581 exportedl = new ExportEDL(this);
1584 void MWindow::init_shuttle()
1587 int ret = Shuttle::probe();
1589 shuttle = new Shuttle(this);
1590 if( shuttle->read_config_file() > 0 ) {
1591 printf("shuttle: bad config file\n");
1592 delete shuttle; shuttle = 0;
1595 shuttle->start(ret);
1600 void MWindow::init_brender()
1602 if(preferences->use_brender && !brender)
1604 brender_lock->lock("MWindow::init_brender 1");
1605 brender = new BRender(this);
1606 brender->initialize();
1607 session->brender_end = 0;
1608 brender_lock->unlock();
1611 if(!preferences->use_brender && brender)
1613 brender_lock->lock("MWindow::init_brender 2");
1616 session->brender_end = 0;
1617 brender_lock->unlock();
1623 void MWindow::restart_brender()
1625 //printf("MWindow::restart_brender 1\n");
1626 if( !brender_active || !preferences->use_brender ) return;
1627 if( !brender ) return;
1628 brender->restart(edl);
1631 void MWindow::stop_brender()
1633 if( !brender ) return;
1634 // cannot be holding mwindow->gui display lock
1638 int MWindow::brender_available(int position)
1641 brender_lock->lock("MWindow::brender_available 1");
1642 if(brender && brender_active)
1644 if(brender->map_valid)
1646 brender->map_lock->lock("MWindow::brender_available 2");
1647 if(position < brender->map_size &&
1650 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1651 if(brender->map[position] == BRender::RENDERED)
1654 brender->map_lock->unlock();
1657 brender_lock->unlock();
1661 void MWindow::set_brender_active(int v, int update)
1663 if( !preferences->use_brender ) v = 0;
1665 gui->mainmenu->brender_active->set_checked(v);
1667 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1668 edl->session->brender_end = edl->local_session->get_selectionend(1);
1670 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1671 edl->session->brender_end = edl->tracks->total_video_length();
1676 edl->session->brender_start = edl->session->brender_end = 0;
1677 gui->unlock_window();
1679 gui->lock_window("MWindow::set_brender_active");
1682 gui->update_timebar(0);
1683 gui->draw_overlays(1);
1687 int MWindow::has_commercials()
1689 #ifdef HAVE_COMMERCIAL
1690 return theme->use_commercials;
1696 void MWindow::init_commercials()
1698 #ifdef HAVE_COMMERCIAL
1699 if( !commercials ) {
1700 commercials = new Commercials(this);
1701 commercial_active = 0;
1704 commercials->add_user();
1708 void MWindow::commit_commercial()
1710 #ifdef HAVE_COMMERCIAL
1711 if( !commercial_active ) return;
1712 commercial_active = 0;
1713 if( !commercials ) return;
1714 commercials->commitDb();
1718 void MWindow::undo_commercial()
1720 #ifdef HAVE_COMMERCIAL
1721 if( !commercial_active ) return;
1722 commercial_active = 0;
1723 if( !commercials ) return;
1724 commercials->undoDb();
1728 int MWindow::put_commercial()
1731 #ifdef HAVE_COMMERCIAL
1732 double start = edl->local_session->get_selectionstart();
1733 double end = edl->local_session->get_selectionend();
1734 if( start >= end ) return 0;
1736 const char *errmsg = 0;
1738 Tracks *tracks = edl->tracks;
1740 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1741 if( track->data_type != TRACK_VIDEO ) continue;
1742 if( !track->record ) continue;
1743 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1745 int64_t units_start = track->to_units(start,0);
1746 int64_t units_end = track->to_units(end,0);
1747 Edits *edits = track->edits;
1748 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1749 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1750 if(!edit1 && !edit2) continue; // nothing selected
1751 if(!edit2) { // edit2 beyond end of track
1752 edit2 = edits->last;
1753 units_end = edits->length();
1755 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1756 Indexable *indexable = edit1->get_source();
1757 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1760 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1761 if( track->data_type != TRACK_VIDEO ) continue;
1762 if( !track->record ) continue;
1763 int64_t units_start = track->to_units(start,0);
1764 int64_t units_end = track->to_units(end,0);
1765 Edits *edits = track->edits;
1766 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1767 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1768 if(!edit1 && !edit2) continue; // nothing selected
1769 if(!edit2) { // edit2 beyond end of track
1770 edit2 = edits->last;
1771 units_end = edits->length();
1773 Indexable *indexable = edit1->get_source();
1774 Asset *asset = (Asset *)indexable;
1775 File *file = video_cache->check_out(asset, edl);
1776 if( !file ) { errmsg = _("no file"); break; }
1777 int64_t edit_length = units_end - units_start;
1778 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1779 result = commercials->put_clip(file, edit1->channel,
1780 track->from_units(edit_start), track->from_units(edit_length));
1781 video_cache->check_in(asset);
1782 if( result ) { errmsg = _("db failed"); break; }
1785 char string[BCTEXTLEN];
1786 sprintf(string, _("put_commercial: %s"), errmsg);
1787 MainError::show_error(string);
1795 void MWindow::stop_playback(int wait)
1797 gui->stop_drawing();
1799 cwindow->stop_playback(wait);
1801 for(int i = 0; i < vwindows.size(); i++) {
1802 VWindow *vwindow = vwindows[i];
1803 if( !vwindow->is_running() ) continue;
1804 vwindow->stop_playback(wait);
1806 for(int i = 0; i < zwindows.size(); i++) {
1807 ZWindow *zwindow = zwindows[i];
1808 if( zwindow->idx < 0 ) continue;
1809 zwindow->stop_playback(wait);
1813 void MWindow::stop_transport()
1815 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1818 void MWindow::undo_before(const char *description, void *creator)
1820 undo->update_undo_before(description, creator);
1823 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
1825 undo->update_undo_after(description, load_flags, changes_made);
1828 void MWindow::beep(double freq, double secs, double gain)
1830 if( !proxy_beep ) proxy_beep = new ProxyBeep(this);
1831 proxy_beep->tone(freq, secs, gain);
1834 int MWindow::load_filenames(ArrayList<char*> *filenames,
1836 int update_filename)
1838 ArrayList<EDL*> new_edls;
1839 ArrayList<Asset*> new_assets;
1840 ArrayList<File*> new_files;
1841 const int debug = 0;
1842 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1845 gui->start_hourglass();
1847 // Need to stop playback since tracking depends on the EDL not getting
1849 gui->unlock_window();
1851 gui->lock_window("MWindow::load_filenames 0");
1853 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1857 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1859 // Define new_edls and new_assets to load
1860 int result = 0, ftype = -1;
1862 for( int i=0; i<filenames->size(); ++i ) {
1864 File *new_file = new File;
1865 Asset *new_asset = new Asset(filenames->get(i));
1866 EDL *new_edl = new EDL;
1867 char string[BCTEXTLEN];
1869 new_edl->create_objects();
1870 new_edl->copy_session(edl, -1);
1871 new_file->set_program(edl->session->program_no);
1873 sprintf(string, _("Loading %s"), new_asset->path);
1874 gui->show_message(string);
1876 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1880 // Convert media file to EDL
1882 // Warn about odd image dimensions
1883 if( new_asset->video_data &&
1884 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1885 char string[BCTEXTLEN];
1886 sprintf(string, _("%s's resolution is %dx%d.\n"
1887 "Images with odd dimensions may not decode properly."),
1888 new_asset->path, new_asset->width, new_asset->height);
1889 MainError::show_error(string);
1892 if( new_asset->program >= 0 &&
1893 edl->session->program_no != new_asset->program ) {
1894 char string[BCTEXTLEN];
1895 sprintf(string, _("%s's index was built for program number %d\n"
1896 "Playback preference is %d.\n Using program %d."),
1897 new_asset->path, new_asset->program,
1898 edl->session->program_no, new_asset->program);
1899 MainError::show_error(string);
1902 if( load_mode != LOADMODE_RESOURCESONLY ) {
1903 RecordLabels *labels = edl->session->label_cells ?
1904 new RecordLabels(new_file) : 0;
1905 asset_to_edl(new_edl, new_asset, labels);
1906 new_edls.append(new_edl);
1907 new_edl->add_user();
1911 new_assets.append(new_asset);
1912 new_asset->add_user();
1915 // Set filename to nothing for assets since save EDL would overwrite them.
1916 if( load_mode == LOADMODE_REPLACE ||
1917 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1919 // Reset timeline position
1920 for( int i=0; i<TOTAL_PANES; ++i ) {
1921 new_edl->local_session->view_start[i] = 0;
1922 new_edl->local_session->track_start[i] = 0;
1930 case FILE_NOT_FOUND:
1931 sprintf(string, _("Failed to open %s"), new_asset->path);
1932 gui->show_message(string, theme->message_error);
1933 gui->update_default_message();
1937 case FILE_UNRECOGNIZED_CODEC: {
1939 { IndexFile indexfile(this, new_asset);
1940 if( !(result = indexfile.open_index()) )
1941 indexfile.close_index(); }
1943 // Test existing EDLs
1944 for( int j=0; result && j<new_edls.total; ++j ) {
1945 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1947 new_asset->copy_from(old_asset,1);
1952 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1954 new_asset->copy_from(old_asset,1);
1961 char string[BCTEXTLEN];
1963 fs.extract_name(string, new_asset->path);
1965 strcat(string, _("'s format couldn't be determined."));
1966 new_asset->audio_data = 1;
1967 new_asset->format = FILE_PCM;
1968 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1969 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1970 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1971 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1972 new_asset->signed_ = defaults->get("SIGNED_", 1);
1973 new_asset->header = defaults->get("HEADER", 0);
1975 FileFormat fwindow(this);
1976 fwindow.create_objects(new_asset, string);
1977 result = fwindow.run_window();
1979 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1980 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1981 defaults->update("AUDIO_BITS", new_asset->bits);
1982 defaults->update("BYTE_ORDER", new_asset->byte_order);
1983 defaults->update("SIGNED_", new_asset->signed_);
1984 defaults->update("HEADER", new_asset->header);
1990 // Recalculate length
1992 new_file = new File;
1993 result = new_file->open_file(preferences, new_asset, 1, 0);
1995 if( load_mode != LOADMODE_RESOURCESONLY ) {
1996 RecordLabels *labels = edl->session->label_cells ?
1997 new RecordLabels(new_file) : 0;
1998 asset_to_edl(new_edl, new_asset, labels);
1999 new_edls.append(new_edl);
2000 new_edl->add_user();
2004 new_assets.append(new_asset);
2005 new_asset->add_user();
2015 xml_file.read_from_file(filenames->get(i));
2016 const char *cin_version = 0;
2017 while( !xml_file.read_tag() ) {
2018 if( xml_file.tag.title_is("EDL") ) {
2019 cin_version = xml_file.tag.get_property("VERSION");
2024 if( !cin_version ) {
2025 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
2026 char string[BCTEXTLEN];
2027 sprintf(string,_("Unknown %s"), filenames->get(i));
2028 gui->show_message(string);
2032 if( strcmp(cin_version, CINELERRA_VERSION) &&
2033 strcmp(cin_version, "Unify") &&
2034 strcmp(cin_version, "5.1") ) {
2035 char string[BCTEXTLEN];
2036 snprintf(string, sizeof(string),
2037 _("Warning: XML from cinelerra version %s\n"
2038 "Session data may be incompatible."), cin_version);
2039 show_warning(&preferences->warn_version, string);
2041 if( load_mode == LOADMODE_NESTED ) {
2042 // Load temporary EDL for nesting.
2043 EDL *nested_edl = new EDL;
2044 nested_edl->create_objects();
2045 nested_edl->load_xml(&xml_file, LOAD_ALL);
2046 int groups = nested_edl->regroup(session->group_number);
2047 session->group_number += groups;
2048 new_edl->create_nested(nested_edl);
2049 new_edl->set_path(filenames->get(i));
2050 nested_edl->Garbage::remove_user();
2053 // Load EDL for pasting
2054 new_edl->load_xml(&xml_file, LOAD_ALL);
2055 int groups = new_edl->regroup(session->group_number);
2056 session->group_number += groups;
2057 test_plugins(new_edl, filenames->get(i));
2059 if( load_mode == LOADMODE_REPLACE ||
2060 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2061 strcpy(session->filename, filenames->get(i));
2062 strcpy(new_edl->local_session->clip_title,
2065 set_filename(new_edl->local_session->clip_title);
2067 else if( load_mode == LOADMODE_RESOURCESONLY ) {
2068 strcpy(new_edl->local_session->clip_title,
2071 time_t t = !stat(filenames->get(i),&st) ?
2072 st.st_mtime : time(&t);
2073 ctime_r(&t, new_edl->local_session->clip_notes);
2077 new_edls.append(new_edl);
2078 new_edl->add_user();
2083 new_edl->Garbage::remove_user();
2084 new_asset->Garbage::remove_user();
2086 // Store for testing index
2087 new_files.append(new_file);
2090 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2094 gui->reset_default_message();
2095 gui->default_message();
2099 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2102 // Don't back up here.
2103 if( new_edls.size() ) {
2104 // For pasting, clear the active region
2105 if( load_mode == LOADMODE_PASTE ||
2106 load_mode == LOADMODE_NESTED ) {
2107 double start = edl->local_session->get_selectionstart();
2108 double end = edl->local_session->get_selectionend();
2109 if(!EQUIV(start, end))
2110 edl->clear(start, end,
2111 edl->session->labels_follow_edits,
2112 edl->session->plugins_follow_edits,
2113 edl->session->autos_follow_edits);
2115 paste_edls(&new_edls, load_mode, 0, -1,
2116 edl->session->labels_follow_edits,
2117 edl->session->plugins_follow_edits,
2118 edl->session->autos_follow_edits,
2122 paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
2125 // Add new assets to EDL and schedule assets for index building.
2126 int got_indexes = 0;
2127 for( int i=0; i<new_edls.size(); ++i ) {
2128 EDL *new_edl = new_edls[i];
2129 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2130 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2131 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2137 for( int i=0; i<new_assets.size(); ++i ) {
2138 Asset *new_asset = new_assets[i];
2142 for( int j=0; j<new_files.size(); ++j ) {
2143 new_file = new_files[j];
2144 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2150 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2151 edl->assets->update(new_asset);
2155 // Start examining next batch of index files
2156 if(got_indexes) mainindexes->start_build();
2159 Track *track = edl->tracks->first;
2161 for( int j = 0; j < track->plugin_set.size(); j++ ) {
2162 PluginSet *plugins = track->plugin_set[j];
2163 Plugin *plugin = plugins->get_first_plugin();
2166 if( load_mode == LOADMODE_REPLACE ||
2167 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2168 if( plugin->plugin_type == PLUGIN_STANDALONE &&
2170 show_plugin(plugin);
2174 plugin = (Plugin*)plugin->next;
2178 track = track->next;
2181 // if just opening one new resource in replace mode
2182 if( ftype != FILE_IS_XML &&
2183 ( load_mode == LOADMODE_REPLACE ||
2184 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2186 edl->session->proxy_scale = 1;
2187 edl->session->proxy_disabled_scale = 1;
2188 edl->session->proxy_use_scaler = 0;
2189 edl->session->proxy_auto_scale = 0;
2190 edl->session->proxy_beep = 0;
2191 edl->local_session->preview_start = 0;
2192 edl->local_session->preview_end = -1;
2193 edl->local_session->loop_playback = 0;
2194 edl->local_session->set_selectionstart(0);
2195 edl->local_session->set_selectionend(0);
2196 edl->local_session->unset_inpoint();
2197 edl->local_session-> unset_outpoint();
2198 set_brender_active(0, 0);
2203 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2204 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2205 ArrayList<Indexable *> orig_idxbls;
2206 for( int i=0; i<new_assets.size(); ++i )
2207 orig_idxbls.append(new_assets.get(i));
2208 for( int i=0; i<new_edls.size(); ++i ) {
2209 EDL *new_edl = new_edls[i];
2210 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2211 if( track->data_type != TRACK_VIDEO ) continue;
2212 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2213 Indexable *idxbl = (Indexable *)edit->asset;
2214 if( !idxbl ) continue;
2215 if( !idxbl->have_video() ) continue;
2216 if( edit->channel != 0 ) continue; // first layer only
2217 orig_idxbls.append(edit->asset);
2221 gui->unlock_window(); // to update progress bar
2222 int ret = render_proxy(orig_idxbls);
2223 gui->lock_window("MWindow::load_filenames");
2224 if( ret >= 0 && edl->session->proxy_beep ) {
2226 beep(2000., 1.5, 0.5);
2228 beep(4000., 0.25, 0.5);
2232 // need to update undo before project, since mwindow is unlocked & a new load
2233 // can begin here. Should really prevent loading until we're done.
2234 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2235 undo_after(_("load"), LOAD_ALL);
2237 for(int i = 0; i < new_edls.size(); i++)
2239 new_edls[i]->remove_user();
2241 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2243 new_edls.remove_all();
2245 for(int i = 0; i < new_assets.size(); i++)
2247 new_assets[i]->Garbage::remove_user();
2250 new_assets.remove_all();
2251 new_files.remove_all_objects();
2254 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2255 if(load_mode == LOADMODE_REPLACE ||
2256 load_mode == LOADMODE_REPLACE_CONCATENATE)
2258 session->changes_made = 0;
2262 session->changes_made = 1;
2265 gui->stop_hourglass();
2268 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2269 update_project(load_mode);
2271 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2276 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2278 Asset *format_asset = new Asset;
2279 format_asset->format = FILE_FFMPEG;
2280 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2281 int new_scale = edl->session->proxy_scale;
2282 ProxyRender proxy_render(this, format_asset, new_scale);
2284 for( int i=0; i<new_idxbls.size(); ++i ) {
2285 Indexable *orig = new_idxbls.get(i);
2286 Asset *proxy = proxy_render.add_original(orig, new_scale);
2287 if( !proxy ) continue;
2289 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2290 int got_it = exists && // if proxy exists, and is newer than orig
2291 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2292 if( got_it ) continue;
2293 proxy_render.add_needed(orig, proxy);
2296 // render needed proxies
2297 int result = proxy_render.create_needed_proxies(new_scale);
2299 add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2301 format_asset->remove_user();
2302 return !result ? proxy_render.needed_proxies.size() : -1;
2305 int MWindow::enable_proxy()
2308 if( edl->session->proxy_scale == 1 &&
2309 edl->session->proxy_disabled_scale != 1 ) {
2310 int new_scale = edl->session->proxy_disabled_scale;
2311 int new_use_scaler = edl->session->proxy_use_scaler;
2312 edl->session->proxy_disabled_scale = 1;
2313 Asset *asset = new Asset;
2314 asset->format = FILE_FFMPEG;
2315 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2316 ret = to_proxy(asset, new_scale, new_use_scaler);
2317 asset->remove_user();
2319 beep(2000., 1.5, 0.5);
2324 int MWindow::disable_proxy()
2326 if( edl->session->proxy_scale != 1 &&
2327 edl->session->proxy_disabled_scale == 1 ) {
2329 int new_use_scaler = edl->session->proxy_use_scaler;
2330 edl->session->proxy_disabled_scale = edl->session->proxy_scale;
2331 Asset *asset = new Asset;
2332 asset->format = FILE_FFMPEG;
2333 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2334 to_proxy(asset, new_scale, new_use_scaler);
2335 asset->remove_user();
2340 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2342 ArrayList<Indexable*> orig_idxbls;
2343 ArrayList<Indexable*> proxy_assets;
2345 edl->Garbage::add_user();
2347 undo_before(_("proxy"), this);
2348 int asset_scale = new_scale == 1 ? 0 :
2349 !new_use_scaler ? 1 : new_scale;
2350 ProxyRender proxy_render(this, asset, asset_scale);
2352 // revert project to original size from current size
2353 // remove all session proxy assets at the at the current proxy_scale
2354 int proxy_scale = edl->session->proxy_scale;
2356 if( proxy_scale > 1 ) {
2357 Asset *orig_asset = edl->assets->first;
2358 for( ; orig_asset; orig_asset=orig_asset->next ) {
2359 char new_path[BCTEXTLEN];
2360 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2361 // test if proxy asset was already added to proxy_assets
2363 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2364 got_it = !strcmp(proxy_assets[i]->path, new_path);
2365 if( got_it ) continue;
2366 Asset *proxy_asset = edl->assets->get_asset(new_path);
2367 if( !proxy_asset ) continue;
2368 // add pointer to existing EDL asset if it exists
2369 // EDL won't delete it unless it's the same pointer.
2370 proxy_assets.append(proxy_asset);
2371 proxy_asset->add_user();
2372 orig_idxbls.append(orig_asset);
2373 orig_asset->add_user();
2375 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2376 EDL *orig_nested = edl->nested_edls[i];
2377 char new_path[BCTEXTLEN];
2378 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2380 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2381 // test if proxy asset was already added to proxy_assets
2383 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2384 got_it = !strcmp(proxy_assets[i]->path, new_path);
2385 if( got_it ) continue;
2386 Asset *proxy_nested = edl->assets->get_asset(new_path);
2387 if( !proxy_nested ) continue;
2388 // add pointer to existing EDL asset if it exists
2389 // EDL won't delete it unless it's the same pointer.
2390 proxy_assets.append(proxy_nested);
2391 proxy_nested->add_user();
2392 orig_idxbls.append(orig_nested);
2393 orig_nested->add_user();
2396 // convert from the proxy assets to the original assets
2397 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2399 // remove the references
2400 for( int i=0; i<proxy_assets.size(); ++i ) {
2401 Asset *proxy = (Asset *) proxy_assets[i];
2402 proxy->width = proxy->actual_width;
2403 proxy->height = proxy->actual_height;
2404 proxy->remove_user();
2405 edl->assets->remove_pointer(proxy);
2406 proxy->remove_user();
2408 proxy_assets.remove_all();
2409 for( int i = 0; i < orig_idxbls.size(); i++ )
2410 orig_idxbls[i]->remove_user();
2411 orig_idxbls.remove_all();
2414 ArrayList<char *> confirm_paths; // test for new files
2415 confirm_paths.set_array_delete();
2417 // convert to new size if not original size
2418 if( new_scale != 1 ) {
2420 Asset *orig = edl->assets->first;
2421 for( ; orig; orig=orig->next ) {
2422 Asset *proxy = proxy_render.add_original(orig, new_scale);
2423 if( !proxy ) continue;
2424 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2425 int got_it = exists && // if proxy exists, and is newer than orig
2426 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2428 if( exists ) // prompt user to overwrite
2429 confirm_paths.append(cstrdup(proxy->path));
2430 proxy_render.add_needed(orig, proxy);
2433 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2434 EDL *orig_nested = edl->nested_edls[i];
2435 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2436 if( !proxy ) continue;
2437 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2438 int got_it = exists && // if proxy exists, and is newer than orig_nested
2439 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2441 if( exists ) // prompt user to overwrite
2442 confirm_paths.append(cstrdup(proxy->path));
2443 proxy_render.add_needed(orig_nested, proxy);
2449 // test for existing files
2450 if( confirm_paths.size() ) {
2451 result = ConfirmSave::test_files(this, &confirm_paths);
2452 confirm_paths.remove_all_objects();
2456 result = proxy_render.create_needed_proxies(new_scale);
2458 if( !result ) // resize project
2459 edl->set_proxy(new_scale, new_use_scaler,
2460 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2462 undo_after(_("proxy"), LOAD_ALL);
2463 edl->Garbage::remove_user();
2466 gui->lock_window("MWindow::to_proxy");
2467 update_project(LOADMODE_REPLACE);
2468 gui->unlock_window();
2470 return !result ? proxy_render.needed_proxies.size() : -1;
2473 void MWindow::test_plugins(EDL *new_edl, char *path)
2475 char string[BCTEXTLEN];
2477 // Do a check whether plugins exist
2478 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2479 for( int k=0; k<track->plugin_set.total; ++k ) {
2480 PluginSet *plugin_set = track->plugin_set[k];
2481 for( Plugin *plugin = (Plugin*)plugin_set->first;
2482 plugin; plugin = (Plugin*)plugin->next ) {
2483 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2484 // ok we need to find it in plugindb
2485 PluginServer *server =
2486 scan_plugindb(plugin->title, track->data_type);
2487 if( !server || server->transition ) {
2489 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2490 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2491 "effect", _(plugin->title), path);
2492 MainError::show_error(string);
2497 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2498 if( !edit->transition ) continue;
2499 // ok we need to find transition in plugindb
2500 PluginServer *server =
2501 scan_plugindb(edit->transition->title, track->data_type);
2502 if( !server || !server->transition ) {
2504 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2505 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2506 "transition", _(edit->transition->title), path);
2507 MainError::show_error(string);
2514 void MWindow::init_shm(const char *pfn, int64_t min)
2517 // Fix shared memory
2518 FILE *fd = fopen(pfn, "r");
2520 fscanf(fd, "%jd", &result);
2522 if( result >= min ) return;
2525 fd = fopen(pfn, "w");
2527 fprintf(fd, "0x%jx", min);
2530 fd = fopen(pfn, "r");
2532 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2536 fscanf(fd, "%jd", &result);
2538 if( result < min ) {
2539 eprintf(_("MWindow::init_shm: %s is %p.\n"
2540 "you probably need to be root, or:\n"
2541 "as root, run: echo 0x%jx > %s\n"
2542 "before trying to start cinelerra.\n"
2543 "It should be at least 0x%jx for Cinelerra.\n"),
2544 pfn, (void *)result, min, pfn, min);
2548 void MWindow::create_objects(int want_gui,
2552 const int debug = 0;
2553 if(debug) PRINT_TRACE
2555 // For some reason, init_signals must come after show_splash or the signals won't
2558 if(debug) PRINT_TRACE
2561 if(debug) PRINT_TRACE
2564 if(debug) PRINT_TRACE
2565 default_standard = default_std();
2566 init_defaults(defaults, config_path);
2570 splash_window->update_status(_("Initializing Plugins"));
2571 init_plugins(this, preferences);
2572 if(debug) PRINT_TRACE
2573 init_ladspa_plugins(this, preferences);
2574 if(debug) PRINT_TRACE
2575 init_plugin_tips(*plugindb, cin_lang);
2577 splash_window->update_status(_("Initializing GUI"));
2578 if(debug) PRINT_TRACE
2581 if(debug) PRINT_TRACE
2585 splash_window->update_status(_("Initializing Fonts"));
2586 char string[BCTEXTLEN];
2587 strcpy(string, preferences->plugin_dir);
2588 strcat(string, "/" FONT_SEARCHPATH);
2589 BC_Resources::init_fontconfig(string);
2590 if(debug) PRINT_TRACE
2592 // Default project created here
2594 if(debug) PRINT_TRACE
2597 if(debug) PRINT_TRACE
2602 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2605 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2607 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2608 if(session->show_vwindow)
2609 get_viewer(1, DEFAULT_VWINDOW);
2610 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2613 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2616 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2619 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2622 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2625 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2628 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());
2635 mainprogress = new MainProgress(this, gui);
2636 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2637 undo = new MainUndo(this);
2639 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2641 plugin_guis = new PluginGUIs(this);
2642 dead_plugins = new ArrayList<PluginServer*>;
2643 keyframe_threads = new ArrayList<KeyFrameThread*>;
2645 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2648 session->show_vwindow);
2650 // Show all vwindows
2651 // if(session->show_vwindow) {
2652 // for(int j = 0; j < vwindows.size(); j++) {
2653 // VWindow *vwindow = vwindows[j];
2654 // if( !vwindow->is_running() ) continue;
2655 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2658 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2659 // vwindow->gui->lock_window("MWindow::create_objects 1");
2660 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2661 // vwindow->gui->show_window();
2662 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2663 // vwindow->gui->unlock_window();
2668 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2670 if(session->show_cwindow)
2672 cwindow->gui->lock_window("MWindow::create_objects 1");
2673 cwindow->gui->show_window();
2674 cwindow->gui->unlock_window();
2677 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2678 if(session->show_awindow)
2680 awindow->gui->lock_window("MWindow::create_objects 1");
2681 awindow->gui->show_window();
2682 awindow->gui->unlock_window();
2685 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2686 if(session->show_lwindow)
2688 lwindow->gui->lock_window("MWindow::create_objects 1");
2689 lwindow->gui->show_window();
2690 lwindow->gui->unlock_window();
2693 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2695 (int)timer.get_difference(),
2697 if(session->show_gwindow)
2699 gwindow->gui->lock_window("MWindow::create_objects 1");
2700 gwindow->gui->show_window();
2701 gwindow->gui->unlock_window();
2704 if(debug) PRINT_TRACE
2706 gui->lock_window("MWindow::create_objects 1");
2707 gui->mainmenu->load_defaults(defaults);
2708 gui->mainmenu->update_toggles(0);
2709 gui->update_patchbay();
2710 gui->draw_canvas(0, 0);
2711 gui->draw_cursor(1);
2713 gui->raise_window();
2714 gui->unlock_window();
2715 cwindow->gui->lock_window("MWindow::create_objects 1");
2716 cwindow->gui->tool_panel->raise_tool();
2717 cwindow->gui->unlock_window();
2718 if(debug) PRINT_TRACE
2720 if(preferences->use_tipwindow)
2722 if(debug) PRINT_TRACE
2724 gui->add_keyboard_listener(
2725 (int (BC_WindowBase::*)(BC_WindowBase *))
2726 &MWindowGUI::keyboard_listener);
2729 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2730 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2731 if(debug) PRINT_TRACE
2733 BC_WindowBase::get_resources()->vframe_shm = 1;
2736 int MWindow::uses_opengl()
2738 if( !playback_3d || !playback_3d->running() ) return 0;
2739 PlaybackConfig *playback_config = edl->session->playback_config;
2740 return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
2743 void MWindow::show_splash()
2745 #include "data/heroine_logo9_png.h"
2746 VFrame *frame = new VFramePng(heroine_logo9_png);
2747 BC_DisplayInfo dpyi;
2748 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2749 int rr = (rw < rh ? rw : rh) / 4;
2750 splash_window = new SplashGUI(frame, rr, rr);
2751 splash_window->create_objects();
2754 void MWindow::hide_splash()
2757 delete splash_window;
2762 void MWindow::start()
2766 // vwindows[DEFAULT_VWINDOW]->start();
2777 playback_3d->start();
2783 run_lock->lock("MWindow::run");
2787 brender_lock->lock("MWindow::run 1");
2788 delete brender; brender = 0;
2789 brender_lock->unlock();
2791 interrupt_indexes();
2797 void MWindow::show_vwindow()
2799 int total_running = 0;
2800 session->show_vwindow = 1;
2802 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2803 // Raise all windows which are visible
2804 for(int j = 0; j < vwindows.size(); j++) {
2805 VWindow *vwindow = vwindows[j];
2806 if( !vwindow->is_running() ) continue;
2807 vwindow->gui->lock_window("MWindow::show_vwindow");
2808 vwindow->gui->show_window(0);
2809 vwindow->gui->raise_window();
2810 vwindow->gui->flush();
2811 vwindow->gui->unlock_window();
2815 // If no windows visible
2818 get_viewer(1, DEFAULT_VWINDOW);
2821 gui->mainmenu->show_vwindow->set_checked(1);
2824 void MWindow::show_awindow()
2826 session->show_awindow = 1;
2827 awindow->gui->lock_window("MWindow::show_awindow");
2828 awindow->gui->show_window();
2829 awindow->gui->raise_window();
2830 awindow->gui->flush();
2831 awindow->gui->unlock_window();
2832 gui->mainmenu->show_awindow->set_checked(1);
2835 char *MWindow::get_cwindow_display()
2837 char *x11_host = screens < 2 || session->window_config == 0 ?
2838 session->a_x11_host : session->b_x11_host;
2839 return *x11_host ? x11_host : 0;
2842 void MWindow::show_cwindow()
2844 session->show_cwindow = 1;
2845 cwindow->show_window();
2846 gui->mainmenu->show_cwindow->set_checked(1);
2849 void MWindow::show_gwindow()
2851 session->show_gwindow = 1;
2853 gwindow->gui->lock_window("MWindow::show_gwindow");
2854 gwindow->gui->show_window();
2855 gwindow->gui->raise_window();
2856 gwindow->gui->flush();
2857 gwindow->gui->unlock_window();
2859 gui->mainmenu->show_gwindow->set_checked(1);
2861 void MWindow::hide_gwindow()
2863 session->show_gwindow = 0;
2865 gwindow->gui->lock_window("MWindow::show_gwindow");
2866 gwindow->gui->hide_window();
2867 gwindow->gui->unlock_window();
2870 void MWindow::show_lwindow()
2872 session->show_lwindow = 1;
2873 lwindow->gui->lock_window("MWindow::show_lwindow");
2874 lwindow->gui->show_window();
2875 lwindow->gui->raise_window();
2876 lwindow->gui->flush();
2877 lwindow->gui->unlock_window();
2878 gui->mainmenu->show_lwindow->set_checked(1);
2881 void MWindow::restore_windows()
2883 if( !session->show_vwindow ) {
2884 for( int i=0, n=vwindows.size(); i<n; ++i ) {
2885 VWindow *vwindow = vwindows[i];
2886 if( !vwindow || !vwindow->is_running() ) continue;
2887 vwindow->gui->lock_window("MWindow::restore_windows");
2888 vwindow->gui->close(1);
2889 vwindow->gui->unlock_window();
2895 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
2896 awindow->gui->lock_window("MWindow::restore_windows");
2897 awindow->gui->close_event();
2898 awindow->gui->unlock_window();
2900 else if( session->show_awindow && awindow->gui->is_hidden() )
2903 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
2904 cwindow->gui->lock_window("MWindow::restore_windows");
2905 cwindow->hide_window();
2906 cwindow->gui->unlock_window();
2908 else if( session->show_cwindow && cwindow->gui->is_hidden() )
2909 cwindow->show_window();
2911 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
2912 gwindow->gui->lock_window("MWindow::restore_windows");
2913 gwindow->gui->close_event();
2914 gwindow->gui->unlock_window();
2916 else if( session->show_gwindow && gwindow->gui->is_hidden() )
2919 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
2920 lwindow->gui->lock_window("MWindow::restore_windows");
2921 lwindow->gui->close_event();
2922 lwindow->gui->unlock_window();
2924 else if( session->show_lwindow && lwindow->gui->is_hidden() )
2930 void MWindow::load_layout(const char *layout)
2932 char path[BCTEXTLEN];
2933 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
2934 session->load_file(path);
2936 gui->default_positions();
2940 void MWindow::save_layout(const char *layout)
2942 char path[BCTEXTLEN];
2943 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
2944 session->save_file(path);
2947 void MWindow::delete_layout(const char *layout)
2949 char path[BCTEXTLEN];
2950 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
2954 int MWindow::tile_windows(int window_config)
2956 int need_reload = 0;
2957 int play_config = window_config==0 ? 0 : 1;
2958 edl->session->playback_config->load_defaults(defaults, play_config);
2959 session->default_window_positions(window_config);
2960 if( screens == 1 ) {
2961 gui->default_positions();
2962 sync_parameters(CHANGE_ALL);
2969 void MWindow::toggle_loop_playback()
2971 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2972 set_loop_boundaries();
2975 gui->draw_overlays(1);
2976 sync_parameters(CHANGE_PARAMS);
2979 void MWindow::set_screens(int value)
2984 void MWindow::set_auto_keyframes(int value)
2986 edl->session->auto_keyframes = value;
2987 gui->mbuttons->edit_panel->keyframe->update(value);
2989 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2990 cwindow->gui->edit_panel->keyframe->update(value);
2991 cwindow->gui->flush();
2992 cwindow->gui->unlock_window();
2995 void MWindow::set_span_keyframes(int value)
2997 edl->session->span_keyframes = value;
2998 gui->mbuttons->edit_panel->span_keyframe->update(value);
3000 cwindow->gui->lock_window("MWindow::set_span_keyframes");
3001 cwindow->gui->edit_panel->span_keyframe->update(value);
3002 cwindow->gui->flush();
3003 cwindow->gui->unlock_window();
3006 void MWindow::set_auto_visibility(Autos *autos, int value)
3008 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3009 edl->session->auto_conf->plugins = value;
3010 else if( autos->autoidx >= 0 )
3011 edl->session->auto_conf->autos[autos->autoidx] = value;
3015 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3016 gui->mainmenu->update_toggles(1);
3017 gui->unlock_window();
3018 gwindow->gui->update_toggles(1);
3019 gui->lock_window("MWindow::set_auto_visibility");
3022 void MWindow::set_keyframe_type(int mode)
3024 gui->lock_window("MWindow::set_keyframe_type");
3025 edl->local_session->floatauto_type = mode;
3026 gui->mainmenu->update_toggles(0);
3027 gui->unlock_window();
3030 int MWindow::set_editing_mode(int new_editing_mode)
3032 edl->session->editing_mode = new_editing_mode;
3033 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3034 gui->mbuttons->edit_panel->update();
3035 gui->set_editing_mode(1);
3037 cwindow->gui->lock_window("MWindow::set_editing_mode");
3038 cwindow->gui->edit_panel->update();
3039 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3040 cwindow->gui->unlock_window();
3044 void MWindow::toggle_editing_mode()
3046 int mode = edl->session->editing_mode;
3047 if( mode == EDITING_ARROW )
3048 set_editing_mode(EDITING_IBEAM);
3050 set_editing_mode(EDITING_ARROW);
3053 void MWindow::toggle_camera_xyz()
3055 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3056 gwindow->gui->toggle_camera_xyz();
3057 gwindow->gui->unlock_window();
3060 void MWindow::toggle_projector_xyz()
3062 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3063 gwindow->gui->toggle_projector_xyz();
3064 gwindow->gui->unlock_window();
3067 void MWindow::set_labels_follow_edits(int value)
3069 edl->session->labels_follow_edits = value;
3070 gui->mbuttons->edit_panel->locklabels->update(value);
3071 gui->mainmenu->labels_follow_edits->set_checked(value);
3075 void MWindow::sync_parameters(int change_type)
3077 if( in_destructor ) return;
3079 // Sync engines which are playing back
3080 if( cwindow->playback_engine->is_playing_back ) {
3081 if( change_type == CHANGE_PARAMS ) {
3082 // TODO: block keyframes until synchronization is done
3083 cwindow->playback_engine->sync_parameters(edl);
3087 int command = cwindow->playback_engine->command->command;
3088 // Waiting for tracking to finish would make the restart position more
3089 // accurate but it can't lock the window to stop tracking for some reason.
3090 // Not waiting for tracking gives a faster response but restart position is
3091 // only as accurate as the last tracking update.
3092 cwindow->playback_engine->transport_stop(0);
3093 cwindow->playback_engine->next_command->realtime = 1;
3094 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3098 cwindow->refresh_frame(change_type);
3102 void MWindow::age_caches()
3104 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3106 // preferences->cache_size,
3107 // audio_cache->get_memory_usage(1),
3108 // video_cache->get_memory_usage(1),
3109 // frame_cache->get_memory_usage(),
3110 // wave_cache->get_memory_usage(),
3112 frame_cache->age_cache(512);
3113 wave_cache->age_cache(8192);
3115 int64_t memory_usage;
3116 int64_t prev_memory_usage = 0;
3118 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3119 while( !result && prev_memory_usage !=
3120 (memory_usage=video_cache->get_memory_usage(1)) &&
3121 memory_usage > video_size ) {
3122 video_cache->delete_oldest();
3123 prev_memory_usage = memory_usage;
3126 prev_memory_usage = 0;
3128 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3129 while( !result && prev_memory_usage !=
3130 (memory_usage=audio_cache->get_memory_usage(1)) &&
3131 memory_usage > audio_size ) {
3132 audio_cache->delete_oldest();
3133 prev_memory_usage = memory_usage;
3137 void MWindow::reset_android_remote()
3139 gui->use_android_remote(preferences->android_remote);
3143 void MWindow::show_keyframe_gui(Plugin *plugin)
3145 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3146 // Find existing thread
3147 for(int i = 0; i < keyframe_threads->size(); i++)
3149 if(keyframe_threads->get(i)->plugin == plugin)
3151 keyframe_threads->get(i)->start_window(plugin, 0);
3152 keyframe_gui_lock->unlock();
3157 // Find unused thread
3158 for(int i = 0; i < keyframe_threads->size(); i++)
3160 if(!keyframe_threads->get(i)->plugin)
3162 keyframe_threads->get(i)->start_window(plugin, 0);
3163 keyframe_gui_lock->unlock();
3168 // Create new thread
3169 KeyFrameThread *thread = new KeyFrameThread(this);
3170 keyframe_threads->append(thread);
3171 thread->start_window(plugin, 0);
3173 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 // update show/gui_id
3227 sync_parameters(CHANGE_PARAMS);
3228 //printf("MWindow::show_plugin %d\n", __LINE__);
3231 //printf("MWindow::show_plugin 2\n");
3234 void MWindow::hide_plugin(Plugin *plugin, int lock)
3237 // Update the toggle
3238 gui->lock_window("MWindow::hide_plugin");
3239 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3240 gui->unlock_window();
3242 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3243 for(int i = 0; i < plugin_guis->total; i++)
3245 if(plugin_guis->get(i)->plugin == plugin)
3247 PluginServer *ptr = plugin_guis->get(i);
3248 plugin_guis->remove(ptr);
3249 if(lock) plugin_gui_lock->unlock();
3250 // Last command executed in client side close
3251 // Schedule for deletion
3258 if(lock) plugin_gui_lock->unlock();
3259 // update show/gui_id
3260 sync_parameters(CHANGE_PARAMS);
3263 void MWindow::delete_plugin(PluginServer *plugin)
3265 dead_plugin_lock->lock("MWindow::delete_plugin");
3266 dead_plugins->append(plugin);
3267 dead_plugin_lock->unlock();
3270 void MWindow::hide_plugins()
3272 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3273 while(plugin_guis->size())
3275 PluginServer *ptr = plugin_guis->get(0);
3276 plugin_guis->remove(ptr);
3277 plugin_gui_lock->unlock();
3278 // Last command executed in client side close
3279 // Schedule for deletion
3282 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3284 plugin_gui_lock->unlock();
3286 hide_keyframe_guis();
3289 void MWindow::hide_keyframe_guis()
3291 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3292 for(int i = 0; i < keyframe_threads->size(); i++)
3294 keyframe_threads->get(i)->close_window();
3296 keyframe_gui_lock->unlock();
3299 void MWindow::hide_keyframe_gui(Plugin *plugin)
3301 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3302 for(int i = 0; i < keyframe_threads->size(); i++)
3304 if(keyframe_threads->get(i)->plugin == plugin)
3306 keyframe_threads->get(i)->close_window();
3310 keyframe_gui_lock->unlock();
3313 int MWindow::get_hash_color(Edit *edit)
3315 Indexable *idxbl = edit->asset ?
3316 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3317 if( !idxbl ) return 0;
3318 char path[BCTEXTLEN];
3319 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3320 edl->session->proxy_scale == 1 ||
3321 ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
3322 strcpy(path, idxbl->path);
3323 char *cp = strrchr(path, '/');
3324 cp = !cp ? path : cp+1;
3325 uint8_t *bp = (uint8_t*)cp;
3327 while( *bp ) v += *bp++;
3328 return get_hash_color(v);
3331 int MWindow::get_hash_color(int v)
3333 int hash = 0x303030;
3334 if( v & 0x01 ) hash ^= 0x000040;
3335 if( v & 0x02 ) hash ^= 0x004000;
3336 if( v & 0x04 ) hash ^= 0x400000;
3337 if( v & 0x08 ) hash ^= 0x080000;
3338 if( v & 0x10 ) hash ^= 0x000800;
3339 if( v & 0x20 ) hash ^= 0x000008;
3340 if( v & 0x40 ) hash ^= 0x404040;
3341 if( v & 0x80 ) hash ^= 0x080808;
3345 int MWindow::get_group_color(int v)
3347 int color = 0x606060;
3348 if( v & 0x01 ) color ^= 0x000080;
3349 if( v & 0x02 ) color ^= 0x008000;
3350 if( v & 0x04 ) color ^= 0x800000;
3351 if( v & 0x08 ) color ^= 0x100000;
3352 if( v & 0x10 ) color ^= 0x001000;
3353 if( v & 0x20 ) color ^= 0x000010;
3354 if( v & 0x40 ) color ^= 0x080808;
3355 if( v & 0x80 ) color ^= 0x909090;
3359 int MWindow::get_title_color(Edit *edit)
3361 unsigned color = edit->color & 0xffffff;
3362 unsigned alpha = (~edit->color>>24) & 0xff;
3364 if( edit->group_id )
3365 color = get_group_color(edit->group_id);
3366 else if( preferences->autocolor_assets )
3367 color = get_hash_color(edit);
3372 alpha = session->title_bar_alpha*255;
3373 return color | (~alpha<<24);
3376 void MWindow::update_keyframe_guis()
3378 // Send new configuration to keyframe GUI's
3379 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3380 for(int i = 0; i < keyframe_threads->size(); i++)
3382 KeyFrameThread *ptr = keyframe_threads->get(i);
3383 if(edl->tracks->plugin_exists(ptr->plugin))
3387 ptr->close_window();
3390 keyframe_gui_lock->unlock();
3393 void MWindow::update_plugin_guis(int do_keyframe_guis)
3395 // Send new configuration to plugin GUI's
3396 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3398 for(int i = 0; i < plugin_guis->size(); i++)
3400 PluginServer *ptr = plugin_guis->get(i);
3401 if(edl->tracks->plugin_exists(ptr->plugin))
3405 // Schedule for deletion if no plugin
3406 plugin_guis->remove_number(i);
3415 // Change plugin variable if not visible
3416 Track *track = edl->tracks->first;
3419 for(int i = 0; i < track->plugin_set.size(); i++)
3421 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3425 for(int i = 0; i < plugin_guis->size(); i++)
3427 PluginServer *server = plugin_guis->get(i);
3428 if(server->plugin == plugin)
3435 if(!got_it) plugin->show = 0;
3436 plugin = (Plugin*)plugin->next;
3440 track = track->next;
3443 plugin_gui_lock->unlock();
3446 if(do_keyframe_guis) update_keyframe_guis();
3449 void MWindow::stop_plugin_guis()
3451 // Send new configuration to plugin GUI's
3452 plugin_gui_lock->lock("MWindow::stop_plugin_guis");
3454 for( int i=0; i<plugin_guis->size(); ++i ) {
3455 PluginServer *ptr = plugin_guis->get(i);
3456 if( edl->tracks->plugin_exists(ptr->plugin) ) {
3460 plugin_gui_lock->unlock();
3463 int MWindow::plugin_gui_open(Plugin *plugin)
3465 int gui_id = plugin->gui_id;
3466 if( gui_id < 0 ) return 0;
3467 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3468 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3469 int result = plugin_server ? 1 : 0;
3470 plugin_gui_lock->unlock();
3475 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3477 int gui_id = plugin->gui_id;
3478 if( gui_id < 0 ) return;
3479 plugin_gui_lock->lock("MWindow::render_plugin_gui 0");
3480 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3482 plugin_server->render_gui(data);
3483 plugin_gui_lock->unlock();
3486 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3488 int gui_id = plugin->gui_id;
3489 if( gui_id < 0 ) return;
3490 plugin_gui_lock->lock("MWindow::render_plugin_gui 1");
3491 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3493 plugin_server->render_gui(data, size);
3494 plugin_gui_lock->unlock();
3497 void MWindow::reset_plugin_gui_frames(Plugin *plugin)
3499 int gui_id = plugin->gui_id;
3500 if( gui_id < 0 ) return;
3501 plugin_gui_lock->lock("MWindow::reset_plugin_gui_frames");
3502 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3504 plugin_server->reset_plugin_gui_frames();
3505 plugin_gui_lock->unlock();
3508 void MWindow::render_plugin_gui_frames(PluginClientFrames *frames, Plugin *plugin)
3510 int gui_id = plugin->gui_id;
3511 if( gui_id < 0 ) return;
3512 plugin_gui_lock->lock("MWindow::render_plugin_gui_frames");
3513 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3515 plugin_server->render_plugin_gui_frames(frames);
3516 plugin_gui_lock->unlock();
3519 double MWindow::get_tracking_position()
3521 return edl->local_session->get_selectionstart(1);
3524 int MWindow::get_tracking_direction()
3526 return cwindow->playback_engine->get_direction();
3529 void MWindow::update_plugin_states()
3531 plugin_gui_lock->lock("MWindow::update_plugin_states");
3532 for(int i = 0; i < plugin_guis->total; i++)
3536 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3537 PluginServer *src_plugingui = plugin_guis->get(i);
3539 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3540 for(Track *track = edl->tracks->first;
3542 track = track->next)
3545 j < track->plugin_set.total && !result;
3548 PluginSet *plugin_set = track->plugin_set[j];
3549 for(Plugin *plugin = (Plugin*)plugin_set->first;
3551 plugin = (Plugin*)plugin->next)
3553 if(plugin == src_plugin &&
3554 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3560 // Doesn't exist anymore
3563 hide_plugin(src_plugin, 0);
3567 plugin_gui_lock->unlock();
3571 void MWindow::update_plugin_titles()
3573 for(int i = 0; i < plugin_guis->total; i++)
3575 plugin_guis->get(i)->update_title();
3579 int MWindow::asset_to_edl(EDL *new_edl,
3581 RecordLabels *labels)
3583 const int debug = 0;
3584 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3587 // Keep frame rate, sample rate, and output size unchanged.
3588 // These parameters would revert the project if VWindow displayed an asset
3589 // of different size than the project.
3590 if(new_asset->video_data)
3592 new_edl->session->video_tracks = new_asset->layers;
3595 new_edl->session->video_tracks = 0;
3597 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3603 if(new_asset->audio_data)
3605 new_edl->session->audio_tracks = new_asset->channels;
3608 new_edl->session->audio_tracks = 0;
3609 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3611 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3612 new_edl->create_default_tracks();
3613 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3614 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3618 //printf("MWindow::asset_to_edl 3\n");
3619 new_edl->insert_asset(new_asset,
3624 //printf("MWindow::asset_to_edl 3\n");
3625 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3627 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3628 if(edl->session->cursor_on_frames)
3630 double length = new_edl->tracks->total_length();
3631 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3632 new_edl->tracks->clear(length, edl_length, 1, 1);
3638 char string[BCTEXTLEN];
3640 fs.extract_name(string, new_asset->path);
3641 //printf("MWindow::asset_to_edl 3\n");
3643 strcpy(new_edl->local_session->clip_title, string);
3644 //printf("MWindow::asset_to_edl 4 %s\n", string);
3645 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3647 new_edl->local_session->asset2edl = 1;
3652 // Reset everything after a load.
3653 void MWindow::update_project(int load_mode)
3655 const int debug = 0;
3657 if(debug) PRINT_TRACE
3658 edl->tracks->update_y_pixels(theme);
3659 session->update_clip_number();
3661 if(debug) PRINT_TRACE
3663 if( load_mode == LOADMODE_REPLACE ||
3664 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3665 delete gui->keyvalue_popup;
3666 gui->keyvalue_popup = 0;
3670 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3671 if(debug) PRINT_TRACE
3672 gui->unlock_window();
3675 cwindow->update(0, 0, 1, 1, 1);
3677 if(debug) PRINT_TRACE
3679 // Close all the vwindows
3680 if( load_mode == LOADMODE_REPLACE ||
3681 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3682 if(debug) PRINT_TRACE
3683 int first_vwindow = 0;
3684 if(session->show_vwindow) first_vwindow = 1;
3685 // Change visible windows to no source
3686 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3687 VWindow *vwindow = vwindows[i];
3688 if( !vwindow->is_running() ) continue;
3689 vwindow->change_source(-1);
3692 // Close remaining windows
3693 for(int i = first_vwindow; i < vwindows.size(); i++) {
3694 VWindow *vwindow = vwindows[i];
3695 if( !vwindow->is_running() ) continue;
3696 vwindow->close_window();
3698 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3699 VWindow *vwindow = get_viewer(1, -1);
3700 vwindow->change_source(i);
3702 if(debug) PRINT_TRACE
3706 for( int i=0; i<edl->mixers.size(); ++i ) {
3707 Mixer *mixer = edl->mixers[i];
3708 ZWindow *zwindow = get_mixer(mixer);
3709 zwindow->set_title(mixer->title);
3712 cwindow->gui->canvas->set_zoom(edl, 0);
3716 if(debug) PRINT_TRACE
3717 cwindow->gui->lock_window("MWindow::update_project 2");
3718 cwindow->gui->timebar->update(0);
3719 Track *track = cwindow->calculate_affected_track();
3720 cwindow->mask_track_id = track ? track->get_id() : -1;
3721 cwindow->gui->tool_panel->raise_tool();
3722 cwindow->gui->update_canvas(0);
3723 cwindow->gui->unlock_window();
3725 if(debug) PRINT_TRACE
3726 cwindow->refresh_frame(CHANGE_ALL);
3728 awindow->gui->async_update_assets();
3729 if(debug) PRINT_TRACE
3731 gui->lock_window("MWindow::update_project");
3732 gui->update_mixers(0, 0);
3734 if(debug) PRINT_TRACE
3737 void MWindow::update_preferences(Preferences *prefs)
3739 if( prefs != preferences )
3740 preferences->copy_from(prefs);
3741 if( cwindow->playback_engine )
3742 cwindow->playback_engine->preferences->copy_from(prefs);
3743 for(int i = 0; i < vwindows.size(); i++) {
3744 VWindow *vwindow = vwindows[i];
3745 if( !vwindow->is_running() ) continue;
3746 if( vwindow->playback_engine )
3747 vwindow->playback_engine->preferences->copy_from(prefs);
3749 for(int i = 0; i < zwindows.size(); i++) {
3750 ZWindow *zwindow = zwindows[i];
3751 if( !zwindow->is_running() ) continue;
3752 if( zwindow->zgui->playback_engine )
3753 zwindow->zgui->playback_engine->preferences->copy_from(prefs);
3757 void MWindow::update_vwindow()
3759 for( int i=0; i<vwindows.size(); ++i ) {
3760 VWindow *vwindow = vwindows[i];
3761 if( vwindow->is_running() ) {
3762 vwindow->gui->lock_window("MWindow::update_vwindow");
3764 vwindow->gui->unlock_window();
3769 void MWindow::remove_indexfile(Indexable *indexable)
3771 if( !indexable->is_asset ) return;
3772 Asset *asset = (Asset *)indexable;
3774 IndexFile::delete_index(preferences, asset, ".toc");
3775 IndexFile::delete_index(preferences, asset, ".idx");
3776 IndexFile::delete_index(preferences, asset, ".mkr");
3779 void MWindow::rebuild_indices()
3781 for(int i = 0; i < session->drag_assets->total; i++)
3783 Indexable *indexable = session->drag_assets->get(i);
3784 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3785 remove_indexfile(indexable);
3786 // Schedule index build
3787 indexable->index_state->remove_user();
3788 indexable->index_state = new IndexState;
3789 IndexFile::delete_index_files(preferences, indexable);
3790 if( indexable->is_asset ) {
3791 Asset *asset = (Asset *)indexable;
3792 if( asset->format != FILE_PCM ) {
3793 asset->format = FILE_UNKNOWN;
3794 asset->reset_audio();
3796 asset->reset_video();
3797 remove_asset_from_caches(asset);
3798 // File file; // re-probe the asset
3799 // file.open_file(preferences, asset, 1, 0);
3801 mainindexes->add_next_asset(0, indexable);
3803 // still in render engine
3804 sync_parameters(CHANGE_ALL);
3805 awindow->gui->async_update_assets();
3806 mainindexes->start_build();
3810 void MWindow::save_backup()
3814 edl->set_path(session->filename);
3815 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3816 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3817 File::get_config_path(), BACKUP_FILE);
3818 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3819 File::get_config_path(), BACKUP_FILE1);
3820 rename(backup_path, backup_path1);
3821 edl->save_xml(&file, backup_path);
3822 file.terminate_string();
3824 fs.complete_path(backup_path);
3826 if(file.write_to_file(backup_path))
3829 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3830 gui->show_message(string2);
3834 void MWindow::load_backup()
3836 ArrayList<char*> path_list;
3837 path_list.set_array_delete();
3839 char backup_path[BCTEXTLEN];
3840 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3841 File::get_config_path(), BACKUP_FILE);
3843 fs.complete_path(backup_path);
3845 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3846 strcpy(out_path, backup_path);
3848 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3849 edl->local_session->clip_title[0] = 0;
3850 // This is unique to backups since the path of the backup is different than the
3851 // path of the project.
3852 set_filename(edl->path);
3853 path_list.remove_all_objects();
3858 void MWindow::save_undo_data()
3861 undo_after(_("perpetual session"), LOAD_ALL);
3862 char perpetual_path[BCTEXTLEN];
3863 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3864 File::get_config_path(), PERPETUAL_FILE);
3865 FILE *fp = fopen(perpetual_path,"w");
3871 void MWindow::load_undo_data()
3873 char perpetual_path[BCTEXTLEN];
3874 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3875 File::get_config_path(), PERPETUAL_FILE);
3876 FILE *fp = fopen(perpetual_path,"r");
3883 int MWindow::copy_target(const char *path, const char *target)
3885 int ifd = ::open(path, O_RDONLY);
3887 eprintf("Cannot open asset: %s", path);
3891 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
3894 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
3895 char progress_title[BCTEXTLEN];
3896 sprintf(progress_title, _("Copying: %s\n"), target);
3897 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
3899 int64_t count = 0, len = -1;
3900 int bfrsz = 0x100000;
3901 uint8_t *bfr = new uint8_t[bfrsz];
3902 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
3903 if( len != ::write(ofd, bfr, len) ) {
3904 eprintf("Error writing: %s", target);
3907 if( progress.is_cancelled() ) {
3911 progress.update(count += len, 1);
3916 progress.stop_progress();
3918 eprintf("Error reading: %s", path);
3923 eprintf("Cannot create asset target: %s", target);
3928 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
3930 char target[BCTEXTLEN];
3932 const char *bp = real_path, *cp = bp;
3933 const char *lp = link_path, *np = lp;
3934 char *tp = target, *ep = tp+sizeof(target)-1, lch;
3935 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
3936 if( lch == '/' ) { np = lp; cp = bp; }
3938 while( tp<ep && *np ) {
3939 if( *np++ != '/' ) continue;
3940 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
3942 while( tp<ep && *cp ) *tp++ = *cp++;
3946 strcpy(target, real_path);
3947 if( symlink(target, link_path) ) {
3948 eprintf("Cannot create symlink: %s", link_path);
3954 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
3956 char dir_path[BCTEXTLEN];
3957 strcpy(dir_path, dir);
3959 fs.complete_path(dir_path);
3962 if( !stat(dir_path, &st) ) {
3963 if( !S_ISDIR(st.st_mode) ) {
3964 eprintf("Path exists and is not a directory\n%s", dir_path);
3969 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
3970 eprintf("Cannot create directory\n%s", dir_path);
3974 char *real_dir = realpath(dir_path, 0);
3975 strcpy(dir_path, real_dir);
3978 EDL *save_edl = new EDL;
3979 save_edl->create_objects();
3980 save_edl->copy_all(edl);
3982 char progress_title[BCTEXTLEN];
3983 sprintf(progress_title, _("Saving to %s:\n"), dir);
3984 int total_assets = save_edl->assets->total();
3985 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
3987 Asset *current = save_edl->assets->first;
3988 for( int i=0; !ret && current; ++i, current=NEXT ) {
3989 char *path = current->path;
3990 if( ::stat(path, &st) ) {
3991 eprintf("Asset not found: %s", path);
3994 char *real_path = realpath(path, 0);
3995 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
3996 char link_path[BCTEXTLEN];
3997 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
3999 if( strcmp(real_path, link_path) ) {
4000 if( !::lstat(link_path, &st) ) {
4002 ::remove(link_path);
4008 eprintf("copy/link to self, skippped: %s", path);
4012 if( save_mode == SAVE_PROJECT_COPY ) {
4013 if( copy_target(real_path, link_path) )
4017 link_target(real_path, link_path,
4018 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
4022 strcpy(path, link_path);
4024 if( progress->is_cancelled() ) break;
4025 progress->update(i);
4028 progress->stop_progress();
4031 char *cp = strrchr(dir_path,'/');
4032 char *bp = cp ? cp+1 : dir_path;
4033 char filename[BCTEXTLEN];
4034 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
4035 save_edl->set_path(filename);
4037 save_edl->save_xml(&file, filename);
4038 file.terminate_string();
4040 if( !file.write_to_file(filename) ) {
4041 char string[BCTEXTLEN];
4042 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
4043 gui->lock_window("SaveProject::run 2");
4044 gui->show_message(string);
4045 gui->unlock_window();
4046 gui->mainmenu->add_load(filename);
4049 eprintf(_("Couldn't open %s."), filename);
4051 save_edl->remove_user();
4054 gui->lock_window("MWindow::save_project");
4055 ArrayList<char*> filenames;
4056 filenames.append(filename);
4057 load_filenames(&filenames, LOADMODE_REPLACE);
4058 gui->unlock_window();
4063 static inline int gcd(int m, int n)
4066 if( m < n ) { r = m; m = n; n = r; }
4067 while( (r = m % n) != 0 ) { m = n; n = r; }
4071 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4074 if(!width || !height) return 1;
4075 if( width == 720 && (height == 480 || height == 576) ) {
4076 w = 4; h = 3; return 0; // for NTSC and PAL
4078 double ar = (double)width / height;
4079 // square-ish pixels
4080 if( EQUIV(ar, 1.0000) ) return 0;
4081 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4082 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4083 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4084 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4085 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4086 int ww = width, hh = height;
4087 // numerator, denominator must be under mx
4088 int mx = 255, n = gcd(ww, hh);
4089 if( n > 1 ) { ww /= n; hh /= n; }
4090 // search near height in case extra/missing lines
4091 if( ww >= mx || hh >= mx ) {
4092 double err = height; // +/- 2 percent height
4093 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4094 int iw = width, ih = height+i;
4095 if( (n=gcd(iw, ih)) > 1 ) {
4096 int u = iw/n; if( u >= mx ) continue;
4097 int v = ih/n; if( v >= mx ) continue;
4098 double r = (double) u/v, er = fabs(ar-r);
4099 if( er >= err ) continue;
4100 err = er; ww = u; hh = v;
4109 void MWindow::reset_caches()
4111 frame_cache->remove_all();
4112 wave_cache->remove_all();
4113 audio_cache->remove_all();
4114 video_cache->remove_all();
4115 if( cwindow->playback_engine ) {
4116 if( cwindow->playback_engine->audio_cache )
4117 cwindow->playback_engine->audio_cache->remove_all();
4118 if( cwindow->playback_engine->video_cache )
4119 cwindow->playback_engine->video_cache->remove_all();
4121 for(int i = 0; i < vwindows.size(); i++) {
4122 VWindow *vwindow = vwindows[i];
4123 if( !vwindow->is_running() ) continue;
4124 if( !vwindow->playback_engine ) continue;
4125 if( vwindow->playback_engine->audio_cache )
4126 vwindow->playback_engine->audio_cache->remove_all();
4127 if( vwindow->playback_engine->video_cache )
4128 vwindow->playback_engine->video_cache->remove_all();
4132 void MWindow::remove_asset_from_caches(Asset *asset)
4134 frame_cache->remove_asset(asset);
4135 wave_cache->remove_asset(asset);
4136 audio_cache->delete_entry(asset);
4137 video_cache->delete_entry(asset);
4138 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4139 cwindow->playback_engine->audio_cache->delete_entry(asset);
4140 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4141 cwindow->playback_engine->video_cache->delete_entry(asset);
4142 for(int i = 0; i < vwindows.size(); i++) {
4143 VWindow *vwindow = vwindows[i];
4144 if( !vwindow->is_running() ) continue;
4145 if( !vwindow->playback_engine ) continue;
4146 if( vwindow->playback_engine->audio_cache )
4147 vwindow->playback_engine->audio_cache->delete_entry(asset);
4148 if( vwindow->playback_engine->video_cache )
4149 vwindow->playback_engine->video_cache->delete_entry(asset);
4151 for(int i = 0; i < zwindows.size(); i++) {
4152 ZWindow *zwindow = zwindows[i];
4153 if( !zwindow->is_running() ) continue;
4154 if( zwindow->zgui->playback_engine->audio_cache )
4155 zwindow->zgui->playback_engine->audio_cache->delete_entry(asset);
4156 if( zwindow->zgui->playback_engine->video_cache )
4157 zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
4161 void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
4162 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4164 awindow->gui->close_view_popup();
4166 // Remove from VWindow.
4168 for(int i = 0; i < drag_clips->total; i++) {
4169 for(int j = 0; j < vwindows.size(); j++) {
4170 VWindow *vwindow = vwindows[j];
4171 if( !vwindow->is_running() ) continue;
4172 if(drag_clips->get(i) == vwindow->get_edl()) {
4173 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4174 vwindow->delete_source(1, 1);
4175 vwindow->gui->unlock_window();
4182 for(int i = 0; i < drag_assets->size(); i++) {
4183 for(int j = 0; j < vwindows.size(); j++) {
4184 VWindow *vwindow = vwindows[j];
4185 if( !vwindow->is_running() ) continue;
4186 if(drag_assets->get(i) == vwindow->get_source()) {
4187 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4188 vwindow->delete_source(1, 1);
4189 vwindow->gui->unlock_window();
4194 for(int i = 0; i < drag_assets->total; i++) {
4195 Indexable *indexable = drag_assets->get(i);
4196 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
4199 if( delete_indexes ) {
4200 for(int i = 0; i < drag_assets->size(); i++) {
4201 Indexable *indexable = drag_assets->get(i);
4202 remove_indexfile(indexable);
4207 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4208 if(push_undo) undo_before();
4209 if(drag_assets) edl->remove_from_project(drag_assets);
4210 if(drag_clips) edl->remove_from_project(drag_clips);
4211 if(redraw) save_backup();
4212 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4216 gui->lock_window("MWindow::remove_assets_from_project 3");
4217 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4218 gui->unlock_window();
4220 // Removes from playback here
4221 sync_parameters(CHANGE_ALL);
4224 awindow->gui->async_update_assets();
4227 void MWindow::remove_assets_from_disk()
4229 remove_assets_from_project(1, 1, 1,
4230 session->drag_assets, session->drag_clips);
4233 for(int i = 0; i < session->drag_assets->total; i++)
4235 remove(session->drag_assets->get(i)->path);
4239 void MWindow::dump_plugins(FILE *fp)
4241 if( !plugindb ) return;
4242 for(int i = 0; i < plugindb->total; i++)
4244 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4245 " synth=%d transition=%d theme=%d %s\n",
4246 plugindb->get(i)->plugin_type,
4247 plugindb->get(i)->audio,
4248 plugindb->get(i)->video,
4249 plugindb->get(i)->realtime,
4250 plugindb->get(i)->multichannel,
4251 plugindb->get(i)->get_synthesis(),
4252 plugindb->get(i)->transition,
4253 plugindb->get(i)->theme,
4254 plugindb->get(i)->title);
4258 void MWindow::dump_edl(FILE *fp)
4264 void MWindow::dump_undo(FILE *fp)
4270 void MWindow::dump_exe(FILE *fp)
4272 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4273 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4275 int ret = -1, n = 100;
4276 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4277 exe_path[len] = 0; strcpy(proc_path, exe_path);
4280 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4283 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4284 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4285 struct tm *tm = localtime(&st.st_mtime);
4287 strftime(mtime, sizeof(mtime), "%F %T", tm);
4288 fprintf(fp,"mtime: %s\n", mtime);
4290 // people hit ctl-c waiting for this
4291 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4292 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4295 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4296 int64_t maxsz = 1024*pagsz;
4297 int64_t size = st.st_size, pos = 0;
4299 while( (bfrsz = size-pos) > 0 ) {
4300 if( bfrsz > maxsz ) bfrsz = maxsz;
4301 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4302 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4303 if( bfr == MAP_FAILED ) break;
4304 sha1.addBytes(bfr, bfrsz);
4309 ret = pos < size ? EIO : 0;
4310 fprintf(fp, "SHA1: ");
4311 uint8_t digest[20]; sha1.computeHash(digest);
4312 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4313 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4314 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4319 void MWindow::trap_hook(FILE *fp, void *vp)
4321 MWindow *mwindow = (MWindow *)vp;
4322 // fprintf(fp, "\nPLUGINS:\n");
4323 // mwindow->dump_plugins(fp);
4324 fprintf(fp, "\nEDL:\n");
4325 mwindow->dump_edl(fp);
4326 fprintf(fp, "\nUNDO:\n");
4327 mwindow->dump_undo(fp);
4328 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4329 mwindow->dump_exe(fp);
4337 int MWindow::save_defaults()
4339 gui->save_defaults(defaults);
4340 edl->save_defaults(defaults);
4341 session->save_defaults(defaults);
4342 preferences->save_defaults(defaults);
4344 for(int i = 0; i < plugin_guis->total; i++)
4346 // Pointer comparison
4347 plugin_guis->get(i)->save_defaults();
4349 awindow->save_defaults(defaults);
4355 int MWindow::run_script(FileXML *script)
4357 int result = 0, result2 = 0;
4358 while(!result && !result2)
4360 result = script->read_tag();
4363 if(script->tag.title_is("new_project"))
4365 // Run new in immediate mode.
4366 // gui->mainmenu->new_project->run_script(script);
4369 if(script->tag.title_is("record"))
4371 // Run record as a thread. It is a terminal command.
4373 // Will read the complete scipt file without letting record read it if not
4379 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4386 // ================================= synchronization
4389 int MWindow::interrupt_indexes()
4391 mainprogress->cancelled = 1;
4392 mainindexes->interrupt_build();
4398 void MWindow::next_time_format()
4400 switch(edl->session->time_format)
4402 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4403 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4404 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4405 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4406 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4407 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4408 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4411 time_format_common();
4414 void MWindow::prev_time_format()
4416 switch(edl->session->time_format)
4418 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4419 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4420 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4421 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4422 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4423 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4424 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4427 time_format_common();
4430 void MWindow::time_format_common()
4432 gui->lock_window("MWindow::next_time_format");
4433 gui->redraw_time_dependancies();
4436 char string[BCTEXTLEN], string2[BCTEXTLEN];
4437 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4438 gui->show_message(string);
4440 gui->unlock_window();
4444 int MWindow::set_filename(const char *filename)
4446 if( filename != session->filename )
4447 strcpy(session->filename, filename);
4448 if( filename != edl->path )
4449 strcpy(edl->path, filename);
4453 if(filename[0] == 0)
4455 gui->set_title(PROGRAM_NAME);
4460 char string[BCTEXTLEN], string2[BCTEXTLEN];
4461 dir.extract_name(string, filename);
4462 sprintf(string2, PROGRAM_NAME ": %s", string);
4463 gui->set_title(string2);
4476 int MWindow::set_loop_boundaries()
4478 double start = edl->local_session->get_selectionstart();
4479 double end = edl->local_session->get_selectionend();
4487 if(edl->tracks->total_length())
4490 end = edl->tracks->total_length();
4497 if(edl->local_session->loop_playback && start != end)
4499 edl->local_session->loop_start = start;
4500 edl->local_session->loop_end = end;
4511 int MWindow::reset_meters()
4513 cwindow->gui->lock_window("MWindow::reset_meters 1");
4514 cwindow->gui->meters->reset_meters();
4515 cwindow->gui->unlock_window();
4517 for(int j = 0; j < vwindows.size(); j++) {
4518 VWindow *vwindow = vwindows[j];
4519 if( !vwindow->is_running() ) continue;
4520 vwindow->gui->lock_window("MWindow::reset_meters 2");
4521 vwindow->gui->meters->reset_meters();
4522 vwindow->gui->unlock_window();
4525 lwindow->gui->lock_window("MWindow::reset_meters 3");
4526 lwindow->gui->panel->reset_meters();
4527 lwindow->gui->unlock_window();
4529 gui->lock_window("MWindow::reset_meters 4");
4530 gui->reset_meters();
4531 gui->unlock_window();
4536 void MWindow::resync_guis()
4540 gui->lock_window("MWindow::resync_guis");
4541 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4542 gui->unlock_window();
4544 cwindow->gui->lock_window("MWindow::resync_guis");
4545 cwindow->gui->resize_event(cwindow->gui->get_w(),
4546 cwindow->gui->get_h());
4547 int channels = edl->session->audio_channels;
4548 cwindow->gui->meters->set_meters(channels, 1);
4549 cwindow->gui->flush();
4550 cwindow->gui->unlock_window();
4552 for(int i = 0; i < vwindows.size(); i++) {
4553 VWindow *vwindow = vwindows[i];
4554 if( !vwindow->is_running() ) continue;
4555 vwindow->gui->lock_window("MWindow::resync_guis");
4556 vwindow->gui->resize_event(vwindow->gui->get_w(),
4557 vwindow->gui->get_h());
4558 vwindow->gui->meters->set_meters(channels, 1);
4559 vwindow->gui->flush();
4560 vwindow->gui->unlock_window();
4563 lwindow->gui->lock_window("MWindow::resync_guis");
4564 lwindow->gui->panel->set_meters(channels, 1);
4565 lwindow->gui->flush();
4566 lwindow->gui->unlock_window();
4569 if(((edl->session->output_w % 4) ||
4570 (edl->session->output_h % 4)) &&
4571 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4573 MainError::show_error(
4574 _("This project's dimensions are not multiples of 4 so\n"
4575 "it can't be rendered by OpenGL."));
4580 sync_parameters(CHANGE_ALL);
4583 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4585 File *file = new File;
4586 EDLSession *session = edl->session;
4587 double old_framerate = session->frame_rate;
4588 double old_samplerate = session->sample_rate;
4589 int old_auto_keyframes = session->auto_keyframes;
4590 session->auto_keyframes = 0;
4591 int result = file->open_file(preferences, asset, 1, 0);
4592 if( !result && delete_tracks > 0 )
4594 int video_layers = asset->get_video_layers();
4595 if( !result && asset->video_data && vstream < video_layers ) {
4596 // try to get asset up to date, may fail
4597 file->select_video_stream(asset, vstream);
4598 // either way use what was/is there.
4599 double framerate = asset->get_frame_rate();
4600 int width = asset->get_w();
4601 int height = asset->get_h();
4603 // must be multiple of 4 for opengl
4604 width = (width+3) & ~3; height = (height+3) & ~3;
4606 int driver = session->playback_config->vconfig->driver;
4607 int color_model = file->get_best_colormodel(asset, driver);
4608 // color_model = BC_CModels::is_yuv(color_model) ?
4609 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4610 // BC_CModels::is_float(color_model) ?
4611 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4612 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4613 // have alpha for now
4614 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4615 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4616 session->color_model = color_model;
4617 session->output_w = width;
4618 session->output_h = height;
4619 session->frame_rate = framerate;
4620 // not, asset->actual_width/actual_height
4621 asset->width = session->output_w;
4622 asset->height = session->output_h;
4623 asset->frame_rate = session->frame_rate;
4624 create_aspect_ratio(session->aspect_w, session->aspect_h,
4625 session->output_w, session->output_h);
4626 Track *track = edl->tracks->first;
4627 for( Track *next_track=0; track; track=next_track ) {
4628 next_track = track->next;
4629 if( track->data_type != TRACK_VIDEO ) continue;
4630 if( delete_tracks ) {
4631 Edit *edit = track->edits->first;
4632 for( Edit *next_edit=0; edit; edit=next_edit ) {
4633 next_edit = edit->next;
4634 if( edit->channel != vstream ||
4635 !edit->asset || !edit->asset->is_asset ||
4636 !asset->equivalent(*edit->asset,1,1,edl) )
4640 if( track->edits->first ) {
4641 track->track_w = edl->session->output_w;
4642 track->track_h = edl->session->output_h;
4644 else if( delete_tracks )
4645 edl->tracks->delete_track(track);
4648 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4650 if( !result && asset->audio_data && asset->channels > 0 ) {
4651 session->sample_rate = asset->get_sample_rate();
4652 int64_t channel_mask = 0;
4653 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4654 file->get_audio_for_video(vstream, astream, channel_mask);
4655 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4656 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4658 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4659 if( channels < 1 ) channels = 1;
4660 if( channels > 6 ) channels = 6;
4661 session->audio_tracks = session->audio_channels = channels;
4663 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4664 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4665 remap_audio(MWindow::AUDIO_1_TO_1);
4667 if( delete_tracks ) {
4668 Track *track = edl->tracks->first;
4669 for( Track *next_track=0; track; track=next_track ) {
4670 next_track = track->next;
4671 if( track->data_type != TRACK_AUDIO ) continue;
4672 Edit *edit = track->edits->first;
4673 for( Edit *next_edit=0; edit; edit=next_edit ) {
4674 next_edit = edit->next;
4675 if( !((1<<edit->channel) & channel_mask) ||
4676 !edit->asset || !edit->asset->is_asset ||
4677 !asset->equivalent(*edit->asset,1,1,edl) )
4680 if( !track->edits->first )
4681 edl->tracks->delete_track(track);
4685 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4688 session->auto_keyframes = old_auto_keyframes;
4689 if( !result && delete_tracks > 0 ) {
4691 undo_after(_("select asset"), LOAD_ALL);
4697 int MWindow::select_asset(int vtrack, int delete_tracks)
4699 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4701 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4702 if( !track ) return 1;
4703 Edit *edit = track->edits->first;
4704 if( !edit ) return 1;
4705 Asset *asset = edit->asset;
4706 if( !asset || !asset->is_asset ) return 1;
4707 return select_asset(asset, edit->channel, 0, delete_tracks);
4710 void MWindow::dump_plugindb(FILE *fp)
4712 if( !plugindb ) return;
4713 for(int i = 0; i < plugindb->total; i++)
4714 plugindb->get(i)->dump(fp);
4717 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4720 double unit_position = edl->local_session->get_selectionstart(1);
4721 unit_position = patch->track->to_units(unit_position, 0);
4723 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4724 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4727 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4730 double unit_position = edl->local_session->get_selectionstart(1);
4731 unit_position = patch->track->to_units(unit_position, 0);
4733 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4734 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4737 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4740 double unit_position = edl->local_session->get_selectionstart(1);
4741 unit_position = patch->track->to_units(unit_position, 0);
4743 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4744 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4747 PatchGUI *MWindow::get_patchgui(Track *track)
4749 PatchGUI *patchgui = 0;
4750 TimelinePane **panes = gui->pane;
4751 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4752 if( !panes[i] ) continue;
4753 PatchBay *patchbay = panes[i]->patchbay;
4754 if( !patchbay ) continue;
4755 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4756 if( patchbay->patches.values[j]->track == track )
4757 patchgui = patchbay->patches.values[j];