3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "aboutprefs.h"
25 #include "audioalsa.h"
27 #include "awindowgui.h"
29 #include "batchrender.h"
30 #include "bcdisplayinfo.h"
31 #include "bcprogressbox.h"
32 #include "bcsignals.h"
39 #include "channeldb.h"
40 #include "channelinfo.h"
43 #include "bccmodels.h"
44 #include "commercials.h"
45 #include "confirmsave.h"
46 #include "cplayback.h"
48 #include "cwindowgui.h"
50 #include "cwindowtool.h"
52 #include "devicedvbinput.inc"
53 #include "dvdcreate.h"
54 #include "editpanel.h"
56 #include "edlsession.h"
58 #include "fileformat.h"
60 #include "filesystem.h"
62 #include "floatautos.h"
63 #include "framecache.h"
65 #include "gwindowgui.h"
66 #include "keyframegui.h"
67 #include "indexfile.h"
69 #include "interlacemodes.h"
71 #include "levelwindowgui.h"
72 #include "levelwindow.h"
73 #include "loadfile.inc"
74 #include "localsession.h"
75 #include "maincursor.h"
76 #include "mainerror.h"
77 #include "mainindexes.h"
79 #include "mainprogress.h"
80 #include "mainsession.h"
83 #include "mixersalign.h"
85 #include "mwindowgui.h"
90 #include "playback3d.h"
91 #include "playbackengine.h"
93 #include "pluginserver.h"
94 #include "pluginset.h"
95 #include "preferences.h"
98 #include "recordmonitor.h"
99 #include "recordlabel.h"
100 #include "removefile.h"
102 #include "resourcethread.h"
103 #include "savefile.inc"
104 #include "samplescroll.h"
107 #include "sighandler.h"
108 #include "splashgui.h"
109 #include "statusbar.h"
111 #include "threadloader.h"
113 #include "timelinepane.h"
114 #include "tipwindow.h"
115 #include "trackcanvas.h"
117 #include "tracking.h"
118 #include "trackscroll.h"
120 #include "transition.h"
121 #include "transportque.h"
124 #include "versioninfo.h"
126 #include "videodevice.inc"
127 #include "videowindow.h"
128 #include "vplayback.h"
129 #include "vwindowgui.h"
131 #include "wavecache.h"
135 #include "zwindowgui.h"
136 #include "exportedl.h"
138 #include "defaultformats.h"
139 #include "ntsczones.h"
146 #include <sys/types.h>
147 #include <sys/stat.h>
148 #include <sys/time.h>
149 #include <sys/mman.h>
150 #include <sys/file.h>
161 // Hack for libdv to remove glib dependancy
164 // g_log (const char *log_domain,
166 // const char *format,
172 // g_logv (const char *log_domain,
174 // const char *format,
183 extern long cin_timezone;
185 ArrayList<PluginServer*>* MWindow::plugindb = 0;
186 Commercials* MWindow::commercials = 0;
192 run_lock = new Mutex("MWindow::run_lock");
193 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
194 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
195 vwindows_lock = new Mutex("MWindow::vwindows_lock");
196 zwindows_lock = new Mutex("MWindow::zwindows_lock");
197 brender_lock = new Mutex("MWindow::brender_lock");
198 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
203 undo_command = COMMAND_NONE;
207 commercial_active = 0;
219 strcpy(cin_lang,"en");
220 channeldb_buz = new ChannelDB;
221 channeldb_v4l2jpeg = new ChannelDB;
224 keyframe_threads = 0;
248 // Need to delete brender temporary here.
251 run_lock->lock("MWindow::~MWindow");
253 //printf("MWindow::~MWindow %d\n", __LINE__);
254 if( wwindow && wwindow->is_running() )
255 wwindow->close_window();
256 if( twindow && twindow->is_running() )
257 twindow->close_window();
258 gui->remote_control->deactivate();
261 gui->channel_info->stop();
264 delete create_bd; create_bd = 0;
265 delete create_dvd; create_dvd = 0;
266 delete shuttle; shuttle = 0;
267 delete batch_render; batch_render = 0;
268 delete render; render = 0;
269 delete mixers_align; mixers_align = 0;
271 if( commercials && !commercials->remove_user() ) commercials = 0;
273 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
274 // Save defaults for open plugins
275 plugin_gui_lock->lock("MWindow::~MWindow");
276 for(int i = 0; i < plugin_guis->size(); i++) {
277 plugin_guis->get(i)->hide_gui();
278 delete_plugin(plugin_guis->get(i));
280 plugin_gui_lock->unlock();
281 hide_keyframe_guis();
284 // Give up and go to a movie
285 // cant run valgrind if this is used
287 gui->del_keyboard_listener(
288 (int (BC_WindowBase::*)(BC_WindowBase *))
289 &MWindowGUI::keyboard_listener);
291 // release the hounds
292 if( awindow && awindow->gui ) awindow->gui->close(0);
293 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
294 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
295 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
296 vwindows.remove_all_objects();
297 zwindows.remove_all_objects();
299 if( awindow ) awindow->join();
300 if( cwindow ) cwindow->join();
301 if( lwindow ) lwindow->join();
302 if( gwindow ) gwindow->join();
305 // one at a time, or nouveau chokes
306 #define close_gui(win) if( win ) { \
307 if( win->gui ) win->gui->close(0); \
313 vwindows.remove_all_objects();
314 zwindows.remove_all_objects();
319 dead_plugins->remove_all_objects();
320 // must delete theme before destroying plugindb
321 // theme destructor will be deleted by delete_plugins
322 delete theme; theme = 0;
325 keyframe_threads->remove_all_objects();
326 colormodels.remove_all_objects();
327 delete awindow; awindow = 0;
328 delete lwindow; lwindow = 0;
329 delete twindow; twindow = 0;
330 delete wwindow; wwindow = 0;
331 delete gwindow; gwindow = 0;
332 delete cwindow; cwindow = 0;
334 delete mainindexes; mainindexes = 0;
335 delete mainprogress; mainprogress = 0;
336 delete audio_cache; audio_cache = 0; // delete the cache after the assets
337 delete video_cache; video_cache = 0; // delete the cache after the assets
338 delete frame_cache; frame_cache = 0;
339 delete wave_cache; wave_cache = 0;
340 delete plugin_guis; plugin_guis = 0;
341 delete dead_plugins; dead_plugins = 0;
342 delete keyframe_threads; keyframe_threads = 0;
343 delete undo; undo = 0;
344 delete preferences; preferences = 0;
345 delete exportedl; exportedl = 0;
346 delete session; session = 0;
347 delete defaults; defaults = 0;
348 delete assets; assets = 0;
349 delete splash_window; splash_window = 0;
350 if( !edl->Garbage::remove_user() ) edl = 0;
351 delete channeldb_buz;
352 delete channeldb_v4l2jpeg;
353 // This must be last thread to exit
354 delete playback_3d; playback_3d = 0;
355 delete dead_plugin_lock;
356 delete plugin_gui_lock;
357 delete vwindows_lock;
358 delete zwindows_lock;
360 delete keyframe_gui_lock;
361 colormodels.remove_all_objects();
362 interlace_project_modes.remove_all_objects();
363 interlace_asset_modes.remove_all_objects();
364 sighandler->terminate();
375 void MWindow::init_error()
377 MainError::init_error(this);
380 void MWindow::finit_error()
382 MainError::finit_error();
385 void MWindow::create_defaults_path(char *string, const char *config_file)
387 // set the .bcast path
390 sprintf(string, "%s/", File::get_config_path());
391 fs.complete_path(string);
392 if(!fs.is_dir(string))
393 fs.create_dir(string);
396 strcat(string, config_file);
398 const char *MWindow::default_std()
400 char buf[BCTEXTLEN], *p = 0;
402 int fd = open(TIMEZONE_NAME, O_RDONLY);
404 int l = read(fd, buf, sizeof(buf)-1);
407 if( buf[l-1] == '\n' ) --l;
413 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
416 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
417 p += strlen(ZONEINFO_STR);
422 for( int i=0; ntsc_zones[i]; ++i ) {
423 if( !strcmp(ntsc_zones[i], p) )
430 for( int i=0; ntsc_zones[i]; ++i ) {
431 if( !strcmp(ntsc_zones[i], p) )
436 // cin_timezone: Seconds west of UTC. 240sec/deg
437 double tz_deg = -cin_timezone / 240.;
438 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
439 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
442 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
444 struct formatpresets *fpr;
446 for(fpr = &format_presets[0]; fpr->name; fpr++)
448 if(strcmp(_(fpr->name), preset) == 0)
450 session->audio_channels = fpr->audio_channels;
451 session->audio_tracks = fpr->audio_tracks;
452 session->sample_rate = fpr->sample_rate;
453 session->video_channels = fpr->video_channels;
454 session->video_tracks = fpr->video_tracks;
455 session->frame_rate = fpr->frame_rate;
456 session->output_w = fpr->output_w;
457 session->output_h = fpr->output_h;
458 session->aspect_w = fpr->aspect_w;
459 session->aspect_h = fpr->aspect_h;
460 session->interlace_mode = fpr->interlace_mode;
461 session->color_model = fpr->color_model;
467 const char *MWindow::get_preset_name(int index)
469 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
471 return _(format_presets[index].name);
475 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
477 char path[BCTEXTLEN];
478 // Use user supplied path
480 strcpy(path, config_path);
482 create_defaults_path(path, CONFIG_FILE);
485 defaults = new BC_Hash(path);
490 void MWindow::check_language()
492 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
493 const char *env_lang = getenv("LANGUAGE");
494 if( !env_lang ) env_lang = getenv("LC_ALL");
495 if( !env_lang ) env_lang = getenv("LANG");
497 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
498 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
499 env_lang = curr_lang;
501 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
502 defaults->get("LAST_LANG",last_lang);
503 if( strcmp(env_lang,last_lang)) {
504 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
505 defaults->update("LAST_LANG",env_lang);
506 char plugin_path[BCTEXTLEN];
507 create_defaults_path(plugin_path, PLUGIN_FILE);
508 ::remove(plugin_path);
509 char ladspa_path[BCTEXTLEN];
510 create_defaults_path(ladspa_path, LADSPA_FILE);
511 ::remove(ladspa_path);
514 if( strlen(env_lang) > 1 &&
515 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
516 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
519 strcpy(cin_lang, "en");
522 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
524 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
526 const char *dp = plug_dir;
527 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
528 bp = !*dp && *bp == '/' ? bp+1 : base_path;
534 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir)
538 fseek(fp, 0, SEEK_SET);
540 char index_line[BCTEXTLEN];
541 int index_version = -1, len = strlen(plugin_dir);
542 if( !fgets(index_line, BCTEXTLEN, fp) ||
543 sscanf(index_line, "%d", &index_version) != 1 ||
544 index_version != PLUGIN_FILE_VERSION ||
545 !fgets(index_line, BCTEXTLEN, fp) ||
546 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
547 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
549 ArrayList<PluginServer*> plugins;
550 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
551 if( index_line[0] == ';' ) continue;
552 if( index_line[0] == '#' ) continue;
553 int type = PLUGIN_TYPE_UNKNOWN;
554 char path[BCTEXTLEN], title[BCTEXTLEN];
556 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
559 PluginServer *server = 0;
561 case PLUGIN_TYPE_BUILTIN:
562 case PLUGIN_TYPE_EXECUTABLE:
563 case PLUGIN_TYPE_LADSPA: {
564 char plugin_path[BCTEXTLEN]; struct stat st;
565 sprintf(plugin_path, "%s/%s", plugin_dir, path);
566 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
569 server = new PluginServer(mwindow, plugin_path, type);
571 case PLUGIN_TYPE_FFMPEG: {
572 server = new_ffmpeg_server(mwindow, path);
574 case PLUGIN_TYPE_LV2: {
575 server = new_lv2_server(mwindow, path);
578 if( !server ) continue;
579 plugins.append(server);
580 // Create plugin server from index entry
581 server->set_title(title);
582 if( server->read_table(index_line) ) {
588 ret = check_plugin_index(plugins, plugin_dir, ".");
591 add_plugins(plugins);
593 plugins.remove_all_objects();
598 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
599 const char *plug_dir, const char *plug_path)
601 char plugin_path[BCTEXTLEN];
602 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
604 fs.set_filter( "[*.plugin][*.so]" );
605 if( fs.update(plugin_path) )
608 for( int i=0; i<fs.dir_list.total; ++i ) {
609 char fs_path[BCTEXTLEN];
610 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
611 if( fs.is_dir(fs_path) ) {
612 get_plugin_path(plugin_path, plug_dir, fs_path);
613 if( check_plugin_index(plugins, plug_dir, plugin_path) )
616 else if( !plugin_exists(fs_path, plugins) )
623 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
626 plugindb = new ArrayList<PluginServer*>;
628 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
629 create_defaults_path(index_path, PLUGIN_FILE);
630 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
631 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
632 FILE *fp = fopen(index_path,"a+");
634 fprintf(stderr,_("MWindow::init_plugins: "
635 "can't open plugin index: %s\n"), index_path);
638 int fd = fileno(fp), ret = -1;
639 if( !flock(fd, LOCK_EX) ) {
640 fseek(fp, 0, SEEK_SET);
641 ret = load_plugin_index(mwindow, fp, plugin_path);
645 fseek(fp, 0, SEEK_SET);
646 printf("init plugin index: %s\n", plugin_path);
647 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
648 fprintf(fp, "%s\n", plugin_path);
649 init_plugin_index(mwindow, preferences, fp, plugin_path);
650 init_ffmpeg_index(mwindow, preferences, fp);
651 init_lv2_index(mwindow, preferences, fp);
652 fseek(fp, 0, SEEK_SET);
653 ret = load_plugin_index(mwindow, fp, plugin_path);
656 fprintf(stderr,_("MWindow::init_plugins: "
657 "can't %s plugin index: %s\n"),
658 ret>0 ? _("create") : _("lock"), index_path);
664 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
666 char *path = getenv("LADSPA_PATH");
667 char ladspa_path[BCTEXTLEN];
669 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
672 for( int len=0; *path; path+=len ) {
673 char *cp = strchr(path,':');
674 len = !cp ? strlen(path) : cp-path;
675 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
676 memcpy(plugin_path, path, len); plugin_path[len] = 0;
678 char *plugin_dir = FileSystem::basepath(plugin_path);
679 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
680 create_defaults_path(index_path, LADSPA_FILE);
681 cp = index_path + strlen(index_path);
682 for( char *bp=plugin_path; *bp!=0; ++bp )
683 *cp++ = *bp=='/' ? '_' : *bp;
685 FILE *fp = fopen(index_path,"a+");
687 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
688 "can't open ladspa plugin index: %s\n"), index_path);
691 int fd = fileno(fp), ret = -1;
692 if( !flock(fd, LOCK_EX) ) {
693 fseek(fp, 0, SEEK_SET);
694 ret = load_plugin_index(mwindow, fp, plugin_path);
698 fseek(fp, 0, SEEK_SET);
699 init_ladspa_index(mwindow, preferences, fp, plugin_path);
700 fseek(fp, 0, SEEK_SET);
701 ret = load_plugin_index(mwindow, fp, plugin_path);
704 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
705 "can't %s ladspa plugin index: %s\n"),
706 ret>0 ? _("create") : _("lock"), index_path);
713 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
714 FILE *fp, const char *plugin_dir)
716 int idx = PLUGIN_IDS;
718 for( int i=0; i<plugindb->size(); ++i ) {
719 PluginServer *server = plugindb->get(i);
720 if( server->dir_idx >= idx )
721 idx = server->dir_idx+1;
724 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
727 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
728 const char *plug_dir, const char *plug_path, int &idx)
730 char plugin_path[BCTEXTLEN];
731 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
733 fs.set_filter( "[*.plugin][*.so]" );
734 int result = fs.update(plugin_path);
735 if( result || !fs.dir_list.total ) return;
738 for( int i=0; i<fs.dir_list.total; ++i ) {
739 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
740 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
741 get_plugin_path(path, plug_dir, fs_path);
742 if( fs.is_dir(fs_path) ) {
743 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
746 if( plugin_exists(path) ) continue;
748 if( stat(fs_path, &st) ) continue;
749 int64_t mtime = st.st_mtime;
750 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
751 result = server.open_plugin(1, preferences, 0, 0);
753 server.write_table(fp, path, vis_id, mtime);
754 server.close_plugin();
756 else if( result == PLUGINSERVER_IS_LAD ) {
759 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
760 ladspa.set_lad_index(lad_index++);
761 result = ladspa.open_plugin(1, preferences, 0, 0);
763 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
764 ladspa.close_plugin();
770 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
772 for( int i=0; i<plugins.size(); ++i )
773 plugindb->append(plugins[i]);
774 plugins.remove_all();
777 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
779 const char *dat_path = File::get_cindat_path();
780 char msg_path[BCTEXTLEN];
782 if( BC_Resources::language[0] ) {
783 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
785 fp = fopen(msg_path, "r");
788 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
790 fp = fopen(msg_path, "r");
793 char text[BCTEXTLEN];
794 char *tp = text, *ep = tp + sizeof(text)-1;
795 char title[BCTEXTLEN];
800 char line[BCTEXTLEN], *cp = line;
801 if( fgets(line,sizeof(line)-1,fp) ) {
802 if( *cp == '#' ) continue;
803 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
806 if( tp > text && *--tp == '\n' ) *tp = 0;
808 int idx = plugins.size();
809 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
811 delete [] plugins[idx]->tip;
812 plugins[idx]->tip = cstrdup(text);
816 if( done > 0 ) break;
818 char *dp = strchr(cp, ':');
820 printf("plugin tips: error on line %d\n", no);
824 while( cp < dp ) *bp++ = *cp++;
829 while( *cp == ' ' || *cp == '\t' ) ++cp;
830 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
835 void MWindow::delete_plugins()
837 plugindb->remove_all_objects();
842 void MWindow::search_plugindb(int do_audio,
847 ArrayList<PluginServer*> &results)
850 for(int i = 0; i < MWindow::plugindb->total; i++)
852 PluginServer *current = MWindow::plugindb->get(i);
854 if(current->audio == do_audio &&
855 current->video == do_video &&
856 (current->realtime == is_realtime || is_realtime < 0) &&
857 current->transition == is_transition &&
858 current->theme == is_theme)
859 results.append(current);
862 // Alphabetize list by title
868 for(int i = 0; i < results.total - 1; i++)
870 PluginServer *value1 = results[i];
871 PluginServer *value2 = results[i + 1];
872 if(strcmp(_(value1->title), _(value2->title)) > 0)
876 results[i + 1] = value1;
882 PluginServer* MWindow::scan_plugindb(char *title,
887 // printf("MWindow::scan_plugindb data_type < 0\n");
891 for(int i = 0; i < plugindb->total; i++)
893 PluginServer *server = plugindb->get(i);
895 !strcasecmp(server->title, title) &&
897 (data_type == TRACK_AUDIO && server->audio) ||
898 (data_type == TRACK_VIDEO && server->video)))
899 return plugindb->get(i);
904 // repair session files with xlated plugin titles
905 void MWindow::fix_plugin_title(char *title)
907 for(int i = 0; i < plugindb->total; i++) {
908 PluginServer *server = plugindb->get(i);
909 if( !server->title ) continue;
910 const char *server_title = server->title;
911 if( !bstrcasecmp(title, _(server_title)) ) {
912 strcpy(title, server_title);
918 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
920 for( int i=0; i<plugins.size(); ++i )
921 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
925 int MWindow::plugin_exists(char *plugin_path)
927 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
930 void MWindow::remove_plugin_index()
932 char index_path[BCTEXTLEN];
933 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
934 ::remove(index_path);
937 void MWindow::init_preferences()
939 preferences = new Preferences;
940 preferences->load_defaults(defaults);
941 File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
942 session = new MainSession(this);
943 session->load_defaults(defaults);
944 // set x11_host, screens, window_config
945 screens = session->set_default_x11_host();
946 BC_Signals::set_trap_hook(trap_hook, this);
947 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
948 BC_Signals::set_catch_intr(preferences->trap_sigintr);
949 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
950 BC_Trace::enable_locks();
953 BC_Trace::disable_locks();
955 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
956 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
957 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
958 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
961 void MWindow::clean_indexes()
966 int oldest_item = -1;
968 char string[BCTEXTLEN];
969 char string2[BCTEXTLEN];
971 // Delete extra indexes
972 fs.set_filter("*.idx");
973 fs.complete_path(preferences->index_directory);
974 fs.update(preferences->index_directory);
975 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
977 // Eliminate directories
982 for(int i = 0; i < fs.dir_list.total && !result; i++)
984 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
985 if(fs.is_dir(string))
987 delete fs.dir_list[i];
988 fs.dir_list.remove_number(i);
993 total_excess = fs.dir_list.total - preferences->index_count;
995 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
996 while(total_excess > 0)
999 for(int i = 0; i < fs.dir_list.total; i++)
1001 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1003 if(i == 0 || fs.get_date(string) <= oldest)
1005 oldest = fs.get_date(string);
1010 if(oldest_item >= 0)
1012 // Remove index file
1013 fs.join_names(string,
1014 preferences->index_directory,
1015 fs.dir_list[oldest_item]->name);
1016 //printf("MWindow::clean_indexes 1 %s\n", string);
1018 perror("delete_indexes");
1019 delete fs.dir_list[oldest_item];
1020 fs.dir_list.remove_number(oldest_item);
1022 // Remove table of contents if it exists
1023 strcpy(string2, string);
1024 char *ptr = strrchr(string2, '.');
1027 //printf("MWindow::clean_indexes 2 %s\n", string2);
1028 sprintf(ptr, ".toc");
1030 sprintf(ptr, ".mkr");
1039 void MWindow::init_awindow()
1041 awindow = new AWindow(this);
1042 awindow->create_objects();
1045 void MWindow::init_gwindow()
1047 gwindow = new GWindow(this);
1048 gwindow->create_objects();
1051 void MWindow::init_tipwindow()
1053 TipWindow::load_tips(cin_lang);
1055 twindow = new TipWindow(this);
1059 void MWindow::show_warning(int *do_warning, const char *text)
1061 if( do_warning && !*do_warning ) return;
1063 wwindow = new WWindow(this);
1064 wwindow->show_warning(do_warning, text);
1067 int MWindow::wait_warning()
1069 return wwindow->wait_result();
1072 void MWindow::init_theme()
1077 PluginServer *theme_plugin = 0;
1078 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1079 if( plugindb->get(i)->theme &&
1080 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1081 theme_plugin = plugindb->get(i);
1085 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1086 preferences->theme);
1088 const char *default_theme = DEFAULT_THEME;
1089 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1090 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1092 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1093 if( plugindb->get(i)->theme &&
1094 !strcasecmp(default_theme, plugindb->get(i)->title) )
1095 theme_plugin = plugindb->get(i);
1100 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1104 PluginServer *plugin = new PluginServer(*theme_plugin);
1105 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1106 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1107 theme_plugin->title);
1111 theme = plugin->new_theme();
1112 theme->mwindow = this;
1113 strcpy(theme->path, plugin->path);
1116 // Load default images & settings
1117 theme->Theme::initialize();
1118 // Load user images & settings
1119 theme->initialize();
1120 // Create menus with user colors
1121 theme->build_menus();
1124 theme->sort_image_sets();
1125 theme->check_used();
1126 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1129 void MWindow::init_3d()
1131 playback_3d = new Playback3D(this);
1132 playback_3d->create_objects();
1135 void MWindow::init_edl()
1138 edl->create_objects();
1139 fill_preset_defaults(default_standard, edl->session);
1140 edl->load_defaults(defaults);
1141 edl->session->brender_start = edl->session->brender_end = 0;
1142 edl->create_default_tracks();
1143 edl->tracks->update_y_pixels(theme);
1146 void MWindow::init_compositor()
1148 cwindow = new CWindow(this);
1149 cwindow->create_objects();
1152 void MWindow::init_levelwindow()
1154 lwindow = new LevelWindow(this);
1155 lwindow->create_objects();
1158 VWindow *MWindow::get_viewer(int start_it, int idx)
1160 vwindows_lock->lock("MWindow::get_viewer");
1161 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1162 if( !vwindow ) idx = vwindows.size();
1163 while( !vwindow && --idx >= 0 ) {
1164 VWindow *vwin = vwindows[idx];
1165 if( !vwin->is_running() || !vwin->get_edl() )
1169 vwindow = new VWindow(this);
1170 vwindow->load_defaults();
1171 vwindow->create_objects();
1172 vwindows.append(vwindow);
1174 vwindows_lock->unlock();
1175 if( start_it ) vwindow->start();
1179 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1181 zwindows_lock->lock("MWindow::get_mixer");
1182 if( !mixer ) mixer = edl->mixers.new_mixer();
1183 ZWindow *zwindow = 0;
1184 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1185 ZWindow *zwdw = zwindows[i];
1186 if( zwdw->running() ) continue;
1187 if( zwdw->idx >= 0 ) continue;
1188 zwindow = zwindows[i];
1191 zwindows.append(zwindow = new ZWindow(this));
1192 zwindow->idx = mixer->idx;
1193 zwindows_lock->unlock();
1197 void MWindow::del_mixer(ZWindow *zwindow)
1199 zwindows_lock->lock("MWindow::del_mixer 0");
1200 edl->mixers.del_mixer(zwindow->idx);
1201 if( session->selected_zwindow >= 0 ) {
1202 int i = zwindows.number_of(zwindow);
1203 if( i >= 0 && i < session->selected_zwindow )
1204 --session->selected_zwindow;
1205 else if( i == session->selected_zwindow )
1206 session->selected_zwindow = -1;
1208 zwindows_lock->unlock();
1209 gui->lock_window("MWindow::del_mixer 1");
1210 gui->update_mixers(0, -1);
1211 gui->unlock_window();
1214 void MWindow::start_mixer()
1217 ZWindow *zwindow = get_mixer(mixer);
1218 const char *title = 0;
1220 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1221 PatchGUI *patchgui = get_patchgui(track);
1222 if( !patchgui || !patchgui->mixer ) continue;
1223 mixer->mixer_ids.append(track->get_mixer_id());
1224 if( !title ) title = track->title;
1227 session->selected_zwindow = -1;
1228 gui->lock_window("MWindow::start_mixer");
1229 gui->update_mixers(0, 0);
1230 gui->unlock_window();
1232 zwindow->set_title(title);
1237 int MWindow::mixer_track_active(Track *track)
1239 int i = session->selected_zwindow;
1240 if( i < 0 || i >= zwindows.size() ) return 0;
1241 ZWindow *zwindow = zwindows[i];
1242 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1243 if( !mixer ) return 0;
1244 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1245 return n >= 0 ? 1 : 0;
1248 void MWindow::update_mixer_tracks()
1250 zwindows_lock->lock("MixPatch::handle_event");
1251 int i = session->selected_zwindow;
1252 if( i >= 0 && i < zwindows.size() ) {
1253 ZWindow *zwindow = zwindows[i];
1254 zwindow->update_mixer_ids();
1256 zwindows_lock->unlock();
1259 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1260 int use_inout, int toggle_audio, int loop_play, float speed)
1262 zwindows_lock->lock("MWindow::handle_mixers");
1263 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1264 ZWindow *zwindow = zwindows[vidx];
1265 if( zwindow->idx < 0 ) continue;
1266 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1267 if( !mixer || !mixer->mixer_ids.size() ) continue;
1269 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1270 if( track->data_type != TRACK_VIDEO ) continue;
1271 int mixer_id = track->get_mixer_id();
1272 k = mixer->mixer_ids.size();
1273 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1275 if( k < 0 ) continue;
1276 EDL *mixer_edl = new EDL(this->edl);
1277 mixer_edl->create_objects();
1278 mixer_edl->copy_all(edl);
1279 mixer_edl->remove_vwindow_edls();
1280 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1281 k = mixer->mixer_ids.size();
1282 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1285 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1288 track->record = track->play = 0;
1290 zwindow->change_source(mixer_edl);
1291 zwindow->handle_mixer(command, 0,
1292 use_inout, toggle_audio, loop_play, speed);
1294 zwindows_lock->unlock();
1297 void MWindow::refresh_mixers(int dir)
1299 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1300 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1303 void MWindow::stop_mixers()
1305 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1306 ZWindow *zwindow = zwindows[vidx];
1307 if( zwindow->idx < 0 ) continue;
1308 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1312 void MWindow::close_mixers(int destroy)
1314 ArrayList<ZWindow*> closed;
1315 zwindows_lock->lock("MWindow::close_mixers");
1316 for( int i=zwindows.size(); --i>=0; ) {
1317 ZWindow *zwindow = zwindows[i];
1318 if( zwindow->idx < 0 ) continue;
1320 zwindow->destroy = destroy;
1321 ZWindowGUI *zgui = zwindow->zgui;
1322 zgui->lock_window("MWindow::select_zwindow 0");
1324 zgui->unlock_window();
1325 closed.append(zwindow);
1327 zwindows_lock->unlock();
1328 for( int i=0; i<closed.size(); ++i ) {
1329 ZWindow *zwindow = closed[i];
1334 ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
1336 ArrayList<Indexable*> new_assets;
1337 new_assets.append(indexable);
1338 Track *track = edl->tracks->last;
1339 load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
1340 track = !track ? edl->tracks->first : track->next;
1342 ZWindow *zwindow = get_mixer(mixer);
1344 track->play = track->record = 0;
1345 if( track->data_type == TRACK_VIDEO ) {
1346 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1348 mixer->mixer_ids.append(track->get_mixer_id());
1349 track = track->next;
1351 if( indexable->is_asset ) {
1352 char *path = indexable->path;
1353 char *tp = strrchr(path, '/');
1354 if( !tp ) tp = path; else ++tp;
1355 zwindow->set_title(tp);
1358 char *title = ((EDL*)indexable)->local_session->clip_title;
1359 zwindow->set_title(title);
1364 void MWindow::create_mixers(double position)
1366 if( !session->drag_assets->size() &&
1367 !session->drag_clips->size() ) return;
1371 ArrayList<ZWindow *>new_mixers;
1373 for( int i=0; i<session->drag_assets->size(); ++i ) {
1374 Indexable *indexable = session->drag_assets->get(i);
1375 if( !indexable->have_video() ) continue;
1376 ZWindow *zwindow = create_mixer(indexable, position);
1377 new_mixers.append(zwindow);
1379 for( int i=0; i<session->drag_clips->size(); ++i ) {
1380 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1381 if( !indexable->have_video() ) continue;
1382 ZWindow *zwindow = create_mixer(indexable, position);
1383 new_mixers.append(zwindow);
1387 for( int i=0; i<new_mixers.size(); ++i )
1388 new_mixers[i]->start();
1392 undo_after(_("create mixers"), LOAD_ALL);
1394 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1395 sync_parameters(CHANGE_ALL);
1398 void MWindow::open_mixers()
1400 for( int i=0; i<edl->mixers.size(); ++i ) {
1401 Mixer *mixer = edl->mixers[i];
1402 ZWindow *zwindow = get_mixer(mixer);
1403 zwindow->set_title(mixer->title);
1409 int MWindow::select_zwindow(ZWindow *zwindow)
1411 int ret = 0, n = zwindows.number_of(zwindow);
1412 if( session->selected_zwindow != n ) {
1413 session->selected_zwindow = n;
1414 for( int i=0; i<zwindows.size(); ++i ) {
1415 ZWindow *zwindow = zwindows[i];
1416 if( zwindow->idx < 0 ) continue;
1417 ZWindowGUI *zgui = zwindow->zgui;
1418 zgui->lock_window("MWindow::select_zwindow 0");
1419 zwindow->highlighted = i == n ? 1 : 0;
1420 if( zgui->draw_overlays() )
1421 zgui->canvas->get_canvas()->flash(1);
1422 zgui->unlock_window();
1425 gui->lock_window("MWindow::select_window 1");
1426 gui->update_mixers(0, -1);
1427 gui->unlock_window();
1432 void MWindow::tile_mixers()
1435 for( int i=0; i<zwindows.size(); ++i ) {
1436 ZWindow *zwindow = zwindows[i];
1437 if( zwindow->idx < 0 ) continue;
1441 int zn = ceil(sqrt(nz));
1442 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1443 int y1 = 1, y2 = gui->get_y();
1444 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1445 if( x1 < 0 ) x1 = 0;
1446 if( y1 < 0 ) y1 = 0;
1447 if( x2 > rw ) x2 = rw;
1448 if( y2 > rh ) y2 = rh;
1449 int dx = x2 - x1, dy = y2 - y1;
1451 int lt = BC_DisplayInfo::get_left_border();
1452 int top = BC_DisplayInfo::get_top_border();
1453 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1454 int bh = top + BC_DisplayInfo::get_bottom_border();
1455 int zx = 0, zy = 0; // window origins
1456 int mw = 10+10, mh = 10+10; // canvas margins
1457 int rsz = 0, n = 0, dz = 0;
1458 int ow = edl->session->output_w, oh = edl->session->output_h;
1459 for( int i=0; i<zwindows.size(); ++i ) {
1460 ZWindow *zwindow = zwindows[i];
1461 if( zwindow->idx < 0 ) continue;
1462 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1463 if( rsz < hh ) rsz = hh;
1464 int xx = zx + x1, yy = zy + y1;
1465 int mx = x2 - zw, my = y2 - zh;
1466 if( xx > mx ) xx = mx;
1467 if( yy > my ) yy = my;
1468 xx += lt + dz; yy += top + dz;
1469 zwindow->reposition(xx,yy, ww,hh);
1470 if( zwindow->running() ) {
1471 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1472 gui->lock_window("MWindow::tile_mixers");
1473 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1474 gui->unlock_window();
1478 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1487 void MWindow::init_cache()
1489 audio_cache = new CICache(preferences);
1490 video_cache = new CICache(preferences);
1491 frame_cache = new FrameCache;
1492 wave_cache = new WaveCache;
1495 void MWindow::init_channeldb()
1497 channeldb_buz->load("channeldb_buz");
1498 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1501 void MWindow::init_menus()
1503 char string[BCTEXTLEN];
1506 BC_CModels::to_text(string, BC_RGB888);
1507 colormodels.append(new ColormodelItem(string, BC_RGB888));
1508 BC_CModels::to_text(string, BC_RGBA8888);
1509 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1510 // BC_CModels::to_text(string, BC_RGB161616);
1511 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1512 // BC_CModels::to_text(string, BC_RGBA16161616);
1513 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1514 BC_CModels::to_text(string, BC_RGB_FLOAT);
1515 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1516 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1517 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1518 BC_CModels::to_text(string, BC_YUV888);
1519 colormodels.append(new ColormodelItem(string, BC_YUV888));
1520 BC_CModels::to_text(string, BC_YUVA8888);
1521 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1522 // BC_CModels::to_text(string, BC_YUV161616);
1523 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1524 // BC_CModels::to_text(string, BC_YUVA16161616);
1525 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1527 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1528 interlace_project_modes.append(new InterlacemodeItem(string, x));
1530 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1531 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1533 // Interlacing Modes
1534 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1536 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1537 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1539 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1540 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1542 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1543 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1545 mixers_align = new MixersAlign(this);
1548 void MWindow::init_indexes()
1550 mainindexes = new MainIndexes(this);
1551 mainindexes->start_loop();
1554 void MWindow::init_gui()
1556 gui = new MWindowGUI(this);
1557 gui->create_objects();
1558 gui->load_defaults(defaults);
1561 void MWindow::init_signals()
1563 sighandler = new SigHandler;
1564 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1568 void MWindow::init_render()
1570 render = new Render(this);
1571 create_bd = new CreateBD_Thread(this);
1572 create_dvd = new CreateDVD_Thread(this);
1573 batch_render = new BatchRenderThread(this);
1576 void MWindow::init_exportedl()
1578 exportedl = new ExportEDL(this);
1581 void MWindow::init_shuttle()
1584 int ret = Shuttle::probe();
1586 shuttle = new Shuttle(this);
1587 if( shuttle->read_config_file() > 0 ) {
1588 printf("shuttle: bad config file\n");
1589 delete shuttle; shuttle = 0;
1592 shuttle->start(ret);
1597 void MWindow::init_brender()
1599 if(preferences->use_brender && !brender)
1601 brender_lock->lock("MWindow::init_brender 1");
1602 brender = new BRender(this);
1603 brender->initialize();
1604 session->brender_end = 0;
1605 brender_lock->unlock();
1608 if(!preferences->use_brender && brender)
1610 brender_lock->lock("MWindow::init_brender 2");
1613 session->brender_end = 0;
1614 brender_lock->unlock();
1620 void MWindow::restart_brender()
1622 //printf("MWindow::restart_brender 1\n");
1623 if( !brender_active || !preferences->use_brender ) return;
1624 if( !brender ) return;
1625 brender->restart(edl);
1628 void MWindow::stop_brender()
1630 if( !brender ) return;
1631 // cannot be holding mwindow->gui display lock
1635 int MWindow::brender_available(int position)
1638 brender_lock->lock("MWindow::brender_available 1");
1639 if(brender && brender_active)
1641 if(brender->map_valid)
1643 brender->map_lock->lock("MWindow::brender_available 2");
1644 if(position < brender->map_size &&
1647 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1648 if(brender->map[position] == BRender::RENDERED)
1651 brender->map_lock->unlock();
1654 brender_lock->unlock();
1658 void MWindow::set_brender_active(int v, int update)
1660 if( !preferences->use_brender ) v = 0;
1662 gui->mainmenu->brender_active->set_checked(v);
1664 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1665 edl->session->brender_end = edl->local_session->get_selectionend(1);
1667 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1668 edl->session->brender_end = edl->tracks->total_video_length();
1673 edl->session->brender_start = edl->session->brender_end = 0;
1674 gui->unlock_window();
1676 gui->lock_window("MWindow::set_brender_active");
1679 gui->update_timebar(0);
1680 gui->draw_overlays(1);
1684 int MWindow::has_commercials()
1686 #ifdef HAVE_COMMERCIAL
1687 return theme->use_commercials;
1693 void MWindow::init_commercials()
1695 #ifdef HAVE_COMMERCIAL
1696 if( !commercials ) {
1697 commercials = new Commercials(this);
1698 commercial_active = 0;
1701 commercials->add_user();
1705 void MWindow::commit_commercial()
1707 #ifdef HAVE_COMMERCIAL
1708 if( !commercial_active ) return;
1709 commercial_active = 0;
1710 if( !commercials ) return;
1711 commercials->commitDb();
1715 void MWindow::undo_commercial()
1717 #ifdef HAVE_COMMERCIAL
1718 if( !commercial_active ) return;
1719 commercial_active = 0;
1720 if( !commercials ) return;
1721 commercials->undoDb();
1725 int MWindow::put_commercial()
1728 #ifdef HAVE_COMMERCIAL
1729 double start = edl->local_session->get_selectionstart();
1730 double end = edl->local_session->get_selectionend();
1731 if( start >= end ) return 0;
1733 const char *errmsg = 0;
1735 Tracks *tracks = edl->tracks;
1737 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1738 if( track->data_type != TRACK_VIDEO ) continue;
1739 if( !track->record ) continue;
1740 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1742 int64_t units_start = track->to_units(start,0);
1743 int64_t units_end = track->to_units(end,0);
1744 Edits *edits = track->edits;
1745 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1746 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1747 if(!edit1 && !edit2) continue; // nothing selected
1748 if(!edit2) { // edit2 beyond end of track
1749 edit2 = edits->last;
1750 units_end = edits->length();
1752 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1753 Indexable *indexable = edit1->get_source();
1754 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1757 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1758 if( track->data_type != TRACK_VIDEO ) continue;
1759 if( !track->record ) continue;
1760 int64_t units_start = track->to_units(start,0);
1761 int64_t units_end = track->to_units(end,0);
1762 Edits *edits = track->edits;
1763 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1764 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1765 if(!edit1 && !edit2) continue; // nothing selected
1766 if(!edit2) { // edit2 beyond end of track
1767 edit2 = edits->last;
1768 units_end = edits->length();
1770 Indexable *indexable = edit1->get_source();
1771 Asset *asset = (Asset *)indexable;
1772 File *file = video_cache->check_out(asset, edl);
1773 if( !file ) { errmsg = _("no file"); break; }
1774 int64_t edit_length = units_end - units_start;
1775 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1776 result = commercials->put_clip(file, edit1->channel,
1777 track->from_units(edit_start), track->from_units(edit_length));
1778 video_cache->check_in(asset);
1779 if( result ) { errmsg = _("db failed"); break; }
1782 char string[BCTEXTLEN];
1783 sprintf(string, _("put_commercial: %s"), errmsg);
1784 MainError::show_error(string);
1792 void MWindow::stop_playback(int wait)
1794 gui->stop_drawing();
1796 cwindow->stop_playback(wait);
1798 for(int i = 0; i < vwindows.size(); i++) {
1799 VWindow *vwindow = vwindows[i];
1800 if( !vwindow->is_running() ) continue;
1801 vwindow->stop_playback(wait);
1803 for(int i = 0; i < zwindows.size(); i++) {
1804 ZWindow *zwindow = zwindows[i];
1805 if( zwindow->idx < 0 ) continue;
1806 zwindow->stop_playback(wait);
1810 void MWindow::stop_transport()
1812 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1815 void MWindow::undo_before(const char *description, void *creator)
1817 undo->update_undo_before(description, creator);
1820 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
1822 undo->update_undo_after(description, load_flags, changes_made);
1825 void MWindow::beep(double freq, double secs, double gain)
1827 if( !proxy_beep ) proxy_beep = new ProxyBeep(this);
1828 proxy_beep->tone(freq, secs, gain);
1831 int MWindow::load_filenames(ArrayList<char*> *filenames,
1833 int update_filename)
1835 ArrayList<EDL*> new_edls;
1836 ArrayList<Asset*> new_assets;
1837 ArrayList<File*> new_files;
1838 const int debug = 0;
1839 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1842 gui->start_hourglass();
1844 // Need to stop playback since tracking depends on the EDL not getting
1846 gui->unlock_window();
1848 gui->lock_window("MWindow::load_filenames 0");
1850 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1854 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1856 // Define new_edls and new_assets to load
1857 int result = 0, ftype = -1;
1859 for( int i=0; i<filenames->size(); ++i ) {
1861 File *new_file = new File;
1862 Asset *new_asset = new Asset(filenames->get(i));
1863 EDL *new_edl = new EDL;
1864 char string[BCTEXTLEN];
1866 new_edl->create_objects();
1867 new_edl->copy_session(edl, -1);
1868 new_file->set_program(edl->session->program_no);
1870 sprintf(string, _("Loading %s"), new_asset->path);
1871 gui->show_message(string);
1873 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1877 // Convert media file to EDL
1879 // Warn about odd image dimensions
1880 if( new_asset->video_data &&
1881 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1882 char string[BCTEXTLEN];
1883 sprintf(string, _("%s's resolution is %dx%d.\n"
1884 "Images with odd dimensions may not decode properly."),
1885 new_asset->path, new_asset->width, new_asset->height);
1886 MainError::show_error(string);
1889 if( new_asset->program >= 0 &&
1890 edl->session->program_no != new_asset->program ) {
1891 char string[BCTEXTLEN];
1892 sprintf(string, _("%s's index was built for program number %d\n"
1893 "Playback preference is %d.\n Using program %d."),
1894 new_asset->path, new_asset->program,
1895 edl->session->program_no, new_asset->program);
1896 MainError::show_error(string);
1899 if( load_mode != LOADMODE_RESOURCESONLY ) {
1900 RecordLabels *labels = edl->session->label_cells ?
1901 new RecordLabels(new_file) : 0;
1902 asset_to_edl(new_edl, new_asset, labels);
1903 new_edls.append(new_edl);
1904 new_edl->add_user();
1908 new_assets.append(new_asset);
1909 new_asset->add_user();
1912 // Set filename to nothing for assets since save EDL would overwrite them.
1913 if( load_mode == LOADMODE_REPLACE ||
1914 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1916 // Reset timeline position
1917 for( int i=0; i<TOTAL_PANES; ++i ) {
1918 new_edl->local_session->view_start[i] = 0;
1919 new_edl->local_session->track_start[i] = 0;
1927 case FILE_NOT_FOUND:
1928 sprintf(string, _("Failed to open %s"), new_asset->path);
1929 gui->show_message(string, theme->message_error);
1930 gui->update_default_message();
1934 case FILE_UNRECOGNIZED_CODEC: {
1936 { IndexFile indexfile(this, new_asset);
1937 if( !(result = indexfile.open_index()) )
1938 indexfile.close_index(); }
1940 // Test existing EDLs
1941 for( int j=0; result && j<new_edls.total; ++j ) {
1942 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1944 new_asset->copy_from(old_asset,1);
1949 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1951 new_asset->copy_from(old_asset,1);
1958 char string[BCTEXTLEN];
1960 fs.extract_name(string, new_asset->path);
1962 strcat(string, _("'s format couldn't be determined."));
1963 new_asset->audio_data = 1;
1964 new_asset->format = FILE_PCM;
1965 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1966 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1967 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1968 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1969 new_asset->signed_ = defaults->get("SIGNED_", 1);
1970 new_asset->header = defaults->get("HEADER", 0);
1972 FileFormat fwindow(this);
1973 fwindow.create_objects(new_asset, string);
1974 result = fwindow.run_window();
1976 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1977 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1978 defaults->update("AUDIO_BITS", new_asset->bits);
1979 defaults->update("BYTE_ORDER", new_asset->byte_order);
1980 defaults->update("SIGNED_", new_asset->signed_);
1981 defaults->update("HEADER", new_asset->header);
1987 // Recalculate length
1989 new_file = new File;
1990 result = new_file->open_file(preferences, new_asset, 1, 0);
1992 if( load_mode != LOADMODE_RESOURCESONLY ) {
1993 RecordLabels *labels = edl->session->label_cells ?
1994 new RecordLabels(new_file) : 0;
1995 asset_to_edl(new_edl, new_asset, labels);
1996 new_edls.append(new_edl);
1997 new_edl->add_user();
2001 new_assets.append(new_asset);
2002 new_asset->add_user();
2012 xml_file.read_from_file(filenames->get(i));
2013 const char *cin_version = 0;
2014 while( !xml_file.read_tag() ) {
2015 if( xml_file.tag.title_is("EDL") ) {
2016 cin_version = xml_file.tag.get_property("VERSION");
2021 if( !cin_version ) {
2022 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
2023 char string[BCTEXTLEN];
2024 sprintf(string,_("Unknown %s"), filenames->get(i));
2025 gui->show_message(string);
2029 if( strcmp(cin_version, CINELERRA_VERSION) &&
2030 strcmp(cin_version, "Unify") &&
2031 strcmp(cin_version, "5.1") ) {
2032 char string[BCTEXTLEN];
2033 snprintf(string, sizeof(string),
2034 _("Warning: XML from cinelerra version %s\n"
2035 "Session data may be incompatible."), cin_version);
2036 show_warning(&preferences->warn_version, string);
2038 if( load_mode == LOADMODE_NESTED ) {
2039 // Load temporary EDL for nesting.
2040 EDL *nested_edl = new EDL;
2041 nested_edl->create_objects();
2042 nested_edl->load_xml(&xml_file, LOAD_ALL);
2043 int groups = nested_edl->regroup(session->group_number);
2044 session->group_number += groups;
2045 new_edl->create_nested(nested_edl);
2046 new_edl->set_path(filenames->get(i));
2047 nested_edl->Garbage::remove_user();
2050 // Load EDL for pasting
2051 new_edl->load_xml(&xml_file, LOAD_ALL);
2052 int groups = new_edl->regroup(session->group_number);
2053 session->group_number += groups;
2054 test_plugins(new_edl, filenames->get(i));
2056 if( load_mode == LOADMODE_REPLACE ||
2057 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2058 strcpy(session->filename, filenames->get(i));
2059 strcpy(new_edl->local_session->clip_title,
2062 set_filename(new_edl->local_session->clip_title);
2064 else if( load_mode == LOADMODE_RESOURCESONLY ) {
2065 strcpy(new_edl->local_session->clip_title,
2068 time_t t = !stat(filenames->get(i),&st) ?
2069 st.st_mtime : time(&t);
2070 ctime_r(&t, new_edl->local_session->clip_notes);
2074 new_edls.append(new_edl);
2075 new_edl->add_user();
2080 new_edl->Garbage::remove_user();
2081 new_asset->Garbage::remove_user();
2083 // Store for testing index
2084 new_files.append(new_file);
2087 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2091 gui->reset_default_message();
2092 gui->default_message();
2096 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2099 // Don't back up here.
2100 if( new_edls.size() ) {
2101 // For pasting, clear the active region
2102 if( load_mode == LOADMODE_PASTE ||
2103 load_mode == LOADMODE_NESTED ) {
2104 double start = edl->local_session->get_selectionstart();
2105 double end = edl->local_session->get_selectionend();
2106 if(!EQUIV(start, end))
2107 edl->clear(start, end,
2108 edl->session->labels_follow_edits,
2109 edl->session->plugins_follow_edits,
2110 edl->session->autos_follow_edits);
2112 paste_edls(&new_edls, load_mode, 0, -1,
2113 edl->session->labels_follow_edits,
2114 edl->session->plugins_follow_edits,
2115 edl->session->autos_follow_edits,
2119 paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
2122 // Add new assets to EDL and schedule assets for index building.
2123 int got_indexes = 0;
2124 for( int i=0; i<new_edls.size(); ++i ) {
2125 EDL *new_edl = new_edls[i];
2126 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2127 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2128 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2134 for( int i=0; i<new_assets.size(); ++i ) {
2135 Asset *new_asset = new_assets[i];
2139 for( int j=0; j<new_files.size(); ++j ) {
2140 new_file = new_files[j];
2141 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2147 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2148 edl->assets->update(new_asset);
2152 // Start examining next batch of index files
2153 if(got_indexes) mainindexes->start_build();
2156 Track *track = edl->tracks->first;
2158 for( int j = 0; j < track->plugin_set.size(); j++ ) {
2159 PluginSet *plugins = track->plugin_set[j];
2160 Plugin *plugin = plugins->get_first_plugin();
2163 if( load_mode == LOADMODE_REPLACE ||
2164 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2165 if( plugin->plugin_type == PLUGIN_STANDALONE &&
2167 show_plugin(plugin);
2171 plugin = (Plugin*)plugin->next;
2175 track = track->next;
2178 // if just opening one new resource in replace mode
2179 if( ftype != FILE_IS_XML &&
2180 ( load_mode == LOADMODE_REPLACE ||
2181 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2183 edl->session->proxy_scale = 1;
2184 edl->session->proxy_disabled_scale = 1;
2185 edl->session->proxy_use_scaler = 0;
2186 edl->session->proxy_auto_scale = 0;
2187 edl->session->proxy_beep = 0;
2188 edl->local_session->preview_start = 0;
2189 edl->local_session->preview_end = -1;
2190 edl->local_session->loop_playback = 0;
2191 edl->local_session->set_selectionstart(0);
2192 edl->local_session->set_selectionend(0);
2193 edl->local_session->unset_inpoint();
2194 edl->local_session-> unset_outpoint();
2195 set_brender_active(0, 0);
2200 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2201 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2202 ArrayList<Indexable *> orig_idxbls;
2203 for( int i=0; i<new_assets.size(); ++i )
2204 orig_idxbls.append(new_assets.get(i));
2205 for( int i=0; i<new_edls.size(); ++i ) {
2206 EDL *new_edl = new_edls[i];
2207 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2208 if( track->data_type != TRACK_VIDEO ) continue;
2209 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2210 Indexable *idxbl = (Indexable *)edit->asset;
2211 if( !idxbl ) continue;
2212 if( !idxbl->have_video() ) continue;
2213 if( edit->channel != 0 ) continue; // first layer only
2214 orig_idxbls.append(edit->asset);
2218 gui->unlock_window(); // to update progress bar
2219 int ret = render_proxy(orig_idxbls);
2220 gui->lock_window("MWindow::load_filenames");
2221 if( ret >= 0 && edl->session->proxy_beep ) {
2223 beep(2000., 1.5, 0.5);
2225 beep(4000., 0.25, 0.5);
2229 // need to update undo before project, since mwindow is unlocked & a new load
2230 // can begin here. Should really prevent loading until we're done.
2231 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2232 undo_after(_("load"), LOAD_ALL);
2234 for(int i = 0; i < new_edls.size(); i++)
2236 new_edls[i]->remove_user();
2238 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2240 new_edls.remove_all();
2242 for(int i = 0; i < new_assets.size(); i++)
2244 new_assets[i]->Garbage::remove_user();
2247 new_assets.remove_all();
2248 new_files.remove_all_objects();
2251 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2252 if(load_mode == LOADMODE_REPLACE ||
2253 load_mode == LOADMODE_REPLACE_CONCATENATE)
2255 session->changes_made = 0;
2259 session->changes_made = 1;
2262 gui->stop_hourglass();
2265 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2266 update_project(load_mode);
2268 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2273 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2275 Asset *format_asset = new Asset;
2276 format_asset->format = FILE_FFMPEG;
2277 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2278 ProxyRender proxy_render(this, format_asset);
2279 int new_scale = edl->session->proxy_scale;
2280 int use_scaler = edl->session->proxy_use_scaler;
2282 for( int i=0; i<new_idxbls.size(); ++i ) {
2283 Indexable *orig = new_idxbls.get(i);
2284 Asset *proxy = proxy_render.add_original(orig, new_scale);
2285 if( !proxy ) continue;
2287 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2288 int got_it = exists && // if proxy exists, and is newer than orig
2289 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2290 if( got_it ) continue;
2291 proxy_render.add_needed(orig, proxy);
2294 // render needed proxies
2295 int result = proxy_render.create_needed_proxies(new_scale);
2297 add_proxy(use_scaler,
2298 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2300 format_asset->remove_user();
2301 return !result ? proxy_render.needed_proxies.size() : -1;
2304 int MWindow::enable_proxy()
2307 if( edl->session->proxy_scale == 1 &&
2308 edl->session->proxy_disabled_scale != 1 ) {
2309 int new_scale = edl->session->proxy_disabled_scale;
2310 int new_use_scaler = edl->session->proxy_use_scaler;
2311 edl->session->proxy_disabled_scale = 1;
2312 Asset *asset = new Asset;
2313 asset->format = FILE_FFMPEG;
2314 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2315 ret = to_proxy(asset, new_scale, new_use_scaler);
2316 asset->remove_user();
2318 beep(2000., 1.5, 0.5);
2323 int MWindow::disable_proxy()
2325 if( edl->session->proxy_scale != 1 &&
2326 edl->session->proxy_disabled_scale == 1 ) {
2328 int new_use_scaler = edl->session->proxy_use_scaler;
2329 edl->session->proxy_disabled_scale = edl->session->proxy_scale;
2330 Asset *asset = new Asset;
2331 asset->format = FILE_FFMPEG;
2332 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2333 to_proxy(asset, new_scale, new_use_scaler);
2334 asset->remove_user();
2339 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2341 ArrayList<Indexable*> orig_idxbls;
2342 ArrayList<Indexable*> proxy_assets;
2344 edl->Garbage::add_user();
2346 undo_before(_("proxy"), this);
2347 ProxyRender proxy_render(this, asset);
2349 // revert project to original size from current size
2350 // remove all session proxy assets at the at the current proxy_scale
2351 int proxy_scale = edl->session->proxy_scale;
2353 if( proxy_scale > 1 ) {
2354 Asset *orig_asset = edl->assets->first;
2355 for( ; orig_asset; orig_asset=orig_asset->next ) {
2356 char new_path[BCTEXTLEN];
2357 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2358 // test if proxy asset was already added to proxy_assets
2360 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2361 got_it = !strcmp(proxy_assets[i]->path, new_path);
2362 if( got_it ) continue;
2363 Asset *proxy_asset = edl->assets->get_asset(new_path);
2364 if( !proxy_asset ) continue;
2365 // add pointer to existing EDL asset if it exists
2366 // EDL won't delete it unless it's the same pointer.
2367 proxy_assets.append(proxy_asset);
2368 proxy_asset->add_user();
2369 orig_idxbls.append(orig_asset);
2370 orig_asset->add_user();
2372 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2373 EDL *orig_nested = edl->nested_edls[i];
2374 char new_path[BCTEXTLEN];
2375 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2377 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2378 // test if proxy asset was already added to proxy_assets
2380 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2381 got_it = !strcmp(proxy_assets[i]->path, new_path);
2382 if( got_it ) continue;
2383 Asset *proxy_nested = edl->assets->get_asset(new_path);
2384 if( !proxy_nested ) continue;
2385 // add pointer to existing EDL asset if it exists
2386 // EDL won't delete it unless it's the same pointer.
2387 proxy_assets.append(proxy_nested);
2388 proxy_nested->add_user();
2389 orig_idxbls.append(orig_nested);
2390 orig_nested->add_user();
2393 // convert from the proxy assets to the original assets
2394 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2396 // remove the references
2397 for( int i=0; i<proxy_assets.size(); ++i ) {
2398 Asset *proxy = (Asset *) proxy_assets[i];
2399 proxy->width = proxy->actual_width;
2400 proxy->height = proxy->actual_height;
2401 proxy->remove_user();
2402 edl->assets->remove_pointer(proxy);
2403 proxy->remove_user();
2405 proxy_assets.remove_all();
2406 for( int i = 0; i < orig_idxbls.size(); i++ )
2407 orig_idxbls[i]->remove_user();
2408 orig_idxbls.remove_all();
2411 ArrayList<char *> confirm_paths; // test for new files
2412 confirm_paths.set_array_delete();
2414 // convert to new size if not original size
2415 if( new_scale != 1 ) {
2417 Asset *orig = edl->assets->first;
2418 for( ; orig; orig=orig->next ) {
2419 Asset *proxy = proxy_render.add_original(orig, new_scale);
2420 if( !proxy ) continue;
2421 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2422 int got_it = exists && // if proxy exists, and is newer than orig
2423 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2425 if( exists ) // prompt user to overwrite
2426 confirm_paths.append(cstrdup(proxy->path));
2427 proxy_render.add_needed(orig, proxy);
2430 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2431 EDL *orig_nested = edl->nested_edls[i];
2432 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2433 if( !proxy ) continue;
2434 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2435 int got_it = exists && // if proxy exists, and is newer than orig_nested
2436 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2438 if( exists ) // prompt user to overwrite
2439 confirm_paths.append(cstrdup(proxy->path));
2440 proxy_render.add_needed(orig_nested, proxy);
2446 // test for existing files
2447 if( confirm_paths.size() ) {
2448 result = ConfirmSave::test_files(this, &confirm_paths);
2449 confirm_paths.remove_all_objects();
2453 result = proxy_render.create_needed_proxies(new_scale);
2455 if( !result ) // resize project
2456 edl->set_proxy(new_scale, new_use_scaler,
2457 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2459 undo_after(_("proxy"), LOAD_ALL);
2460 edl->Garbage::remove_user();
2463 gui->lock_window("MWindow::to_proxy");
2464 update_project(LOADMODE_REPLACE);
2465 gui->unlock_window();
2467 return !result ? proxy_render.needed_proxies.size() : -1;
2470 void MWindow::test_plugins(EDL *new_edl, char *path)
2472 char string[BCTEXTLEN];
2474 // Do a check whether plugins exist
2475 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2476 for( int k=0; k<track->plugin_set.total; ++k ) {
2477 PluginSet *plugin_set = track->plugin_set[k];
2478 for( Plugin *plugin = (Plugin*)plugin_set->first;
2479 plugin; plugin = (Plugin*)plugin->next ) {
2480 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2481 // ok we need to find it in plugindb
2482 PluginServer *server =
2483 scan_plugindb(plugin->title, track->data_type);
2484 if( !server || server->transition ) {
2486 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2487 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2488 "effect", _(plugin->title), path);
2489 MainError::show_error(string);
2494 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2495 if( !edit->transition ) continue;
2496 // ok we need to find transition in plugindb
2497 PluginServer *server =
2498 scan_plugindb(edit->transition->title, track->data_type);
2499 if( !server || !server->transition ) {
2501 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2502 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2503 "transition", _(edit->transition->title), path);
2504 MainError::show_error(string);
2511 void MWindow::init_shm(const char *pfn, int64_t min)
2514 // Fix shared memory
2515 FILE *fd = fopen(pfn, "r");
2517 fscanf(fd, "%jd", &result);
2519 if( result >= min ) return;
2522 fd = fopen(pfn, "w");
2524 fprintf(fd, "0x%jx", min);
2527 fd = fopen(pfn, "r");
2529 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2533 fscanf(fd, "%jd", &result);
2535 if( result < min ) {
2536 eprintf(_("MWindow::init_shm: %s is %p.\n"
2537 "you probably need to be root, or:\n"
2538 "as root, run: echo 0x%jx > %s\n"
2539 "before trying to start cinelerra.\n"
2540 "It should be at least 0x%jx for Cinelerra.\n"),
2541 pfn, (void *)result, min, pfn, min);
2545 void MWindow::create_objects(int want_gui,
2549 const int debug = 0;
2550 if(debug) PRINT_TRACE
2552 // For some reason, init_signals must come after show_splash or the signals won't
2555 if(debug) PRINT_TRACE
2558 if(debug) PRINT_TRACE
2561 if(debug) PRINT_TRACE
2562 default_standard = default_std();
2563 init_defaults(defaults, config_path);
2567 splash_window->update_status(_("Initializing Plugins"));
2568 init_plugins(this, preferences);
2569 if(debug) PRINT_TRACE
2570 init_ladspa_plugins(this, preferences);
2571 if(debug) PRINT_TRACE
2572 init_plugin_tips(*plugindb, cin_lang);
2574 splash_window->update_status(_("Initializing GUI"));
2575 if(debug) PRINT_TRACE
2578 if(debug) PRINT_TRACE
2582 splash_window->update_status(_("Initializing Fonts"));
2583 char string[BCTEXTLEN];
2584 strcpy(string, preferences->plugin_dir);
2585 strcat(string, "/" FONT_SEARCHPATH);
2586 BC_Resources::init_fontconfig(string);
2587 if(debug) PRINT_TRACE
2589 // Default project created here
2591 if(debug) PRINT_TRACE
2594 if(debug) PRINT_TRACE
2599 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2602 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2604 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2605 if(session->show_vwindow)
2606 get_viewer(1, DEFAULT_VWINDOW);
2607 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2610 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2613 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2616 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
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());
2631 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2632 mainprogress = new MainProgress(this, gui);
2633 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2634 undo = new MainUndo(this);
2636 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2638 plugin_guis = new ArrayList<PluginServer*>;
2639 dead_plugins = new ArrayList<PluginServer*>;
2640 keyframe_threads = new ArrayList<KeyFrameThread*>;
2642 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2645 session->show_vwindow);
2647 // Show all vwindows
2648 // if(session->show_vwindow) {
2649 // for(int j = 0; j < vwindows.size(); j++) {
2650 // VWindow *vwindow = vwindows[j];
2651 // if( !vwindow->is_running() ) continue;
2652 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2655 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2656 // vwindow->gui->lock_window("MWindow::create_objects 1");
2657 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2658 // vwindow->gui->show_window();
2659 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2660 // vwindow->gui->unlock_window();
2665 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2667 if(session->show_cwindow)
2669 cwindow->gui->lock_window("MWindow::create_objects 1");
2670 cwindow->gui->show_window();
2671 cwindow->gui->unlock_window();
2674 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2675 if(session->show_awindow)
2677 awindow->gui->lock_window("MWindow::create_objects 1");
2678 awindow->gui->show_window();
2679 awindow->gui->unlock_window();
2682 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2683 if(session->show_lwindow)
2685 lwindow->gui->lock_window("MWindow::create_objects 1");
2686 lwindow->gui->show_window();
2687 lwindow->gui->unlock_window();
2690 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2692 (int)timer.get_difference(),
2694 if(session->show_gwindow)
2696 gwindow->gui->lock_window("MWindow::create_objects 1");
2697 gwindow->gui->show_window();
2698 gwindow->gui->unlock_window();
2701 if(debug) PRINT_TRACE
2703 gui->lock_window("MWindow::create_objects 1");
2704 gui->mainmenu->load_defaults(defaults);
2705 gui->mainmenu->update_toggles(0);
2706 gui->update_patchbay();
2707 gui->draw_canvas(0, 0);
2708 gui->draw_cursor(1);
2710 gui->raise_window();
2711 gui->unlock_window();
2712 cwindow->gui->lock_window("MWindow::create_objects 1");
2713 cwindow->gui->tool_panel->raise_tool();
2714 cwindow->gui->unlock_window();
2715 if(debug) PRINT_TRACE
2717 if(preferences->use_tipwindow)
2719 if(debug) PRINT_TRACE
2721 gui->add_keyboard_listener(
2722 (int (BC_WindowBase::*)(BC_WindowBase *))
2723 &MWindowGUI::keyboard_listener);
2726 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2727 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2728 if(debug) PRINT_TRACE
2730 BC_WindowBase::get_resources()->vframe_shm = 1;
2733 int MWindow::uses_opengl()
2735 if( !playback_3d || !playback_3d->running() ) return 0;
2736 PlaybackConfig *playback_config = edl->session->playback_config;
2737 return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
2740 void MWindow::show_splash()
2742 #include "data/heroine_logo9_png.h"
2743 VFrame *frame = new VFramePng(heroine_logo9_png);
2744 BC_DisplayInfo dpyi;
2745 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2746 int rr = (rw < rh ? rw : rh) / 4;
2747 splash_window = new SplashGUI(frame, rr, rr);
2748 splash_window->create_objects();
2751 void MWindow::hide_splash()
2754 delete splash_window;
2759 void MWindow::start()
2763 // vwindows[DEFAULT_VWINDOW]->start();
2774 playback_3d->start();
2780 run_lock->lock("MWindow::run");
2784 brender_lock->lock("MWindow::run 1");
2785 delete brender; brender = 0;
2786 brender_lock->unlock();
2788 interrupt_indexes();
2794 void MWindow::show_vwindow()
2796 int total_running = 0;
2797 session->show_vwindow = 1;
2799 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2800 // Raise all windows which are visible
2801 for(int j = 0; j < vwindows.size(); j++) {
2802 VWindow *vwindow = vwindows[j];
2803 if( !vwindow->is_running() ) continue;
2804 vwindow->gui->lock_window("MWindow::show_vwindow");
2805 vwindow->gui->show_window(0);
2806 vwindow->gui->raise_window();
2807 vwindow->gui->flush();
2808 vwindow->gui->unlock_window();
2812 // If no windows visible
2815 get_viewer(1, DEFAULT_VWINDOW);
2818 gui->mainmenu->show_vwindow->set_checked(1);
2821 void MWindow::show_awindow()
2823 session->show_awindow = 1;
2824 awindow->gui->lock_window("MWindow::show_awindow");
2825 awindow->gui->show_window();
2826 awindow->gui->raise_window();
2827 awindow->gui->flush();
2828 awindow->gui->unlock_window();
2829 gui->mainmenu->show_awindow->set_checked(1);
2832 char *MWindow::get_cwindow_display()
2834 char *x11_host = screens < 2 || session->window_config == 0 ?
2835 session->a_x11_host : session->b_x11_host;
2836 return *x11_host ? x11_host : 0;
2839 void MWindow::show_cwindow()
2841 session->show_cwindow = 1;
2842 cwindow->show_window();
2843 gui->mainmenu->show_cwindow->set_checked(1);
2846 void MWindow::show_gwindow()
2848 session->show_gwindow = 1;
2850 gwindow->gui->lock_window("MWindow::show_gwindow");
2851 gwindow->gui->show_window();
2852 gwindow->gui->raise_window();
2853 gwindow->gui->flush();
2854 gwindow->gui->unlock_window();
2856 gui->mainmenu->show_gwindow->set_checked(1);
2858 void MWindow::hide_gwindow()
2860 session->show_gwindow = 0;
2862 gwindow->gui->lock_window("MWindow::show_gwindow");
2863 gwindow->gui->hide_window();
2864 gwindow->gui->unlock_window();
2867 void MWindow::show_lwindow()
2869 session->show_lwindow = 1;
2870 lwindow->gui->lock_window("MWindow::show_lwindow");
2871 lwindow->gui->show_window();
2872 lwindow->gui->raise_window();
2873 lwindow->gui->flush();
2874 lwindow->gui->unlock_window();
2875 gui->mainmenu->show_lwindow->set_checked(1);
2878 void MWindow::restore_windows()
2880 if( !session->show_vwindow ) {
2881 for( int i=0, n=vwindows.size(); i<n; ++i ) {
2882 VWindow *vwindow = vwindows[i];
2883 if( !vwindow || !vwindow->is_running() ) continue;
2884 vwindow->gui->lock_window("MWindow::restore_windows");
2885 vwindow->gui->close(1);
2886 vwindow->gui->unlock_window();
2892 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
2893 awindow->gui->lock_window("MWindow::restore_windows");
2894 awindow->gui->close_event();
2895 awindow->gui->unlock_window();
2897 else if( session->show_awindow && awindow->gui->is_hidden() )
2900 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
2901 cwindow->gui->lock_window("MWindow::restore_windows");
2902 cwindow->hide_window();
2903 cwindow->gui->unlock_window();
2905 else if( session->show_cwindow && cwindow->gui->is_hidden() )
2906 cwindow->show_window();
2908 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
2909 gwindow->gui->lock_window("MWindow::restore_windows");
2910 gwindow->gui->close_event();
2911 gwindow->gui->unlock_window();
2913 else if( session->show_gwindow && gwindow->gui->is_hidden() )
2916 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
2917 lwindow->gui->lock_window("MWindow::restore_windows");
2918 lwindow->gui->close_event();
2919 lwindow->gui->unlock_window();
2921 else if( session->show_lwindow && lwindow->gui->is_hidden() )
2927 void MWindow::load_layout(const char *layout)
2929 char path[BCTEXTLEN];
2930 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
2931 session->load_file(path);
2933 gui->default_positions();
2937 void MWindow::save_layout(const char *layout)
2939 char path[BCTEXTLEN];
2940 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
2941 session->save_file(path);
2944 void MWindow::delete_layout(const char *layout)
2946 char path[BCTEXTLEN];
2947 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
2951 int MWindow::tile_windows(int window_config)
2953 int need_reload = 0;
2954 int play_config = window_config==0 ? 0 : 1;
2955 edl->session->playback_config->load_defaults(defaults, play_config);
2956 session->default_window_positions(window_config);
2957 if( screens == 1 ) {
2958 gui->default_positions();
2959 sync_parameters(CHANGE_ALL);
2966 void MWindow::toggle_loop_playback()
2968 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2969 set_loop_boundaries();
2972 gui->draw_overlays(1);
2973 sync_parameters(CHANGE_PARAMS);
2976 void MWindow::set_screens(int value)
2981 void MWindow::set_auto_keyframes(int value)
2983 edl->session->auto_keyframes = value;
2984 gui->mbuttons->edit_panel->keyframe->update(value);
2986 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2987 cwindow->gui->edit_panel->keyframe->update(value);
2988 cwindow->gui->flush();
2989 cwindow->gui->unlock_window();
2992 void MWindow::set_auto_visibility(Autos *autos, int value)
2994 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2995 edl->session->auto_conf->plugins = value;
2996 else if( autos->autoidx >= 0 )
2997 edl->session->auto_conf->autos[autos->autoidx] = value;
3001 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3002 gui->mainmenu->update_toggles(1);
3003 gui->unlock_window();
3004 gwindow->gui->update_toggles(1);
3005 gui->lock_window("MWindow::set_auto_visibility");
3008 void MWindow::set_keyframe_type(int mode)
3010 gui->lock_window("MWindow::set_keyframe_type");
3011 edl->local_session->floatauto_type = mode;
3012 gui->mainmenu->update_toggles(0);
3013 gui->unlock_window();
3016 int MWindow::set_editing_mode(int new_editing_mode)
3018 edl->session->editing_mode = new_editing_mode;
3019 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3020 gui->mbuttons->edit_panel->update();
3021 gui->set_editing_mode(1);
3023 cwindow->gui->lock_window("MWindow::set_editing_mode");
3024 cwindow->gui->edit_panel->update();
3025 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3026 cwindow->gui->unlock_window();
3030 void MWindow::toggle_editing_mode()
3032 int mode = edl->session->editing_mode;
3033 if( mode == EDITING_ARROW )
3034 set_editing_mode(EDITING_IBEAM);
3036 set_editing_mode(EDITING_ARROW);
3039 void MWindow::toggle_camera_xyz()
3041 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3042 gwindow->gui->toggle_camera_xyz();
3043 gwindow->gui->unlock_window();
3046 void MWindow::toggle_projector_xyz()
3048 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3049 gwindow->gui->toggle_projector_xyz();
3050 gwindow->gui->unlock_window();
3053 void MWindow::set_labels_follow_edits(int value)
3055 edl->session->labels_follow_edits = value;
3056 gui->mbuttons->edit_panel->locklabels->update(value);
3057 gui->mainmenu->labels_follow_edits->set_checked(value);
3061 void MWindow::sync_parameters(int change_type)
3063 if( in_destructor ) return;
3065 // Sync engines which are playing back
3066 if( cwindow->playback_engine->is_playing_back ) {
3067 if( change_type == CHANGE_PARAMS ) {
3068 // TODO: block keyframes until synchronization is done
3069 cwindow->playback_engine->sync_parameters(edl);
3073 int command = cwindow->playback_engine->command->command;
3074 // Waiting for tracking to finish would make the restart position more
3075 // accurate but it can't lock the window to stop tracking for some reason.
3076 // Not waiting for tracking gives a faster response but restart position is
3077 // only as accurate as the last tracking update.
3078 cwindow->playback_engine->transport_stop(0);
3079 cwindow->playback_engine->next_command->realtime = 1;
3080 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3084 cwindow->refresh_frame(change_type);
3088 void MWindow::age_caches()
3090 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3092 // preferences->cache_size,
3093 // audio_cache->get_memory_usage(1),
3094 // video_cache->get_memory_usage(1),
3095 // frame_cache->get_memory_usage(),
3096 // wave_cache->get_memory_usage(),
3098 frame_cache->age_cache(512);
3099 wave_cache->age_cache(8192);
3101 int64_t memory_usage;
3102 int64_t prev_memory_usage = 0;
3104 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3105 while( !result && prev_memory_usage !=
3106 (memory_usage=video_cache->get_memory_usage(1)) &&
3107 memory_usage > video_size ) {
3108 video_cache->delete_oldest();
3109 prev_memory_usage = memory_usage;
3112 prev_memory_usage = 0;
3114 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3115 while( !result && prev_memory_usage !=
3116 (memory_usage=audio_cache->get_memory_usage(1)) &&
3117 memory_usage > audio_size ) {
3118 audio_cache->delete_oldest();
3119 prev_memory_usage = memory_usage;
3123 void MWindow::reset_android_remote()
3125 gui->use_android_remote(preferences->android_remote);
3129 void MWindow::show_keyframe_gui(Plugin *plugin)
3131 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3132 // Find existing thread
3133 for(int i = 0; i < keyframe_threads->size(); i++)
3135 if(keyframe_threads->get(i)->plugin == plugin)
3137 keyframe_threads->get(i)->start_window(plugin, 0);
3138 keyframe_gui_lock->unlock();
3143 // Find unused thread
3144 for(int i = 0; i < keyframe_threads->size(); i++)
3146 if(!keyframe_threads->get(i)->plugin)
3148 keyframe_threads->get(i)->start_window(plugin, 0);
3149 keyframe_gui_lock->unlock();
3154 // Create new thread
3155 KeyFrameThread *thread = new KeyFrameThread(this);
3156 keyframe_threads->append(thread);
3157 thread->start_window(plugin, 0);
3159 keyframe_gui_lock->unlock();
3166 void MWindow::show_plugin(Plugin *plugin)
3171 // Remove previously deleted plugin GUIs
3172 dead_plugin_lock->lock("MWindow::show_plugin");
3173 dead_plugins->remove_all_objects();
3174 dead_plugin_lock->unlock();
3176 //printf("MWindow::show_plugin %d\n", __LINE__);
3180 plugin_gui_lock->lock("MWindow::show_plugin");
3181 for(int i = 0; i < plugin_guis->total; i++)
3183 // Pointer comparison
3184 if(plugin_guis->get(i)->plugin == plugin)
3186 plugin_guis->get(i)->raise_window();
3193 //printf("MWindow::show_plugin 1\n");
3194 if( !done && !plugin->track ) {
3195 printf("MWindow::show_plugin track not defined.\n");
3199 PluginServer *server = scan_plugindb(plugin->title,
3200 plugin->track->data_type);
3202 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3203 if(server && server->uses_gui)
3205 PluginServer *gui = new PluginServer(*server);
3206 plugin_guis->append(gui);
3207 // Needs mwindow to do GUI
3208 gui->set_mwindow(this);
3209 gui->open_plugin(0, preferences, edl, plugin);
3214 plugin_gui_lock->unlock();
3215 //printf("MWindow::show_plugin %d\n", __LINE__);
3218 //printf("MWindow::show_plugin 2\n");
3221 void MWindow::hide_plugin(Plugin *plugin, int lock)
3224 // Update the toggle
3225 gui->lock_window("MWindow::hide_plugin");
3226 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3227 gui->unlock_window();
3229 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3230 for(int i = 0; i < plugin_guis->total; i++)
3232 if(plugin_guis->get(i)->plugin == plugin)
3234 PluginServer *ptr = plugin_guis->get(i);
3235 plugin_guis->remove(ptr);
3236 if(lock) plugin_gui_lock->unlock();
3237 // Last command executed in client side close
3238 // Schedule for deletion
3245 if(lock) plugin_gui_lock->unlock();
3248 void MWindow::delete_plugin(PluginServer *plugin)
3250 dead_plugin_lock->lock("MWindow::delete_plugin");
3251 dead_plugins->append(plugin);
3252 dead_plugin_lock->unlock();
3255 void MWindow::hide_plugins()
3257 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3258 while(plugin_guis->size())
3260 PluginServer *ptr = plugin_guis->get(0);
3261 plugin_guis->remove(ptr);
3262 plugin_gui_lock->unlock();
3263 // Last command executed in client side close
3264 // Schedule for deletion
3267 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3269 plugin_gui_lock->unlock();
3271 hide_keyframe_guis();
3274 void MWindow::hide_keyframe_guis()
3276 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3277 for(int i = 0; i < keyframe_threads->size(); i++)
3279 keyframe_threads->get(i)->close_window();
3281 keyframe_gui_lock->unlock();
3284 void MWindow::hide_keyframe_gui(Plugin *plugin)
3286 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3287 for(int i = 0; i < keyframe_threads->size(); i++)
3289 if(keyframe_threads->get(i)->plugin == plugin)
3291 keyframe_threads->get(i)->close_window();
3295 keyframe_gui_lock->unlock();
3298 int MWindow::get_hash_color(Edit *edit)
3300 Indexable *idxbl = edit->asset ?
3301 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3302 if( !idxbl ) return 0;
3303 char path[BCTEXTLEN];
3304 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3305 edl->session->proxy_scale == 1 ||
3306 ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
3307 strcpy(path, idxbl->path);
3308 char *cp = strrchr(path, '/');
3309 cp = !cp ? path : cp+1;
3310 uint8_t *bp = (uint8_t*)cp;
3312 while( *bp ) v += *bp++;
3313 return get_hash_color(v);
3316 int MWindow::get_hash_color(int v)
3318 int hash = 0x303030;
3319 if( v & 0x01 ) hash ^= 0x000040;
3320 if( v & 0x02 ) hash ^= 0x004000;
3321 if( v & 0x04 ) hash ^= 0x400000;
3322 if( v & 0x08 ) hash ^= 0x080000;
3323 if( v & 0x10 ) hash ^= 0x000800;
3324 if( v & 0x20 ) hash ^= 0x000008;
3325 if( v & 0x40 ) hash ^= 0x404040;
3326 if( v & 0x80 ) hash ^= 0x080808;
3330 int MWindow::get_group_color(int v)
3332 int color = 0x606060;
3333 if( v & 0x01 ) color ^= 0x000080;
3334 if( v & 0x02 ) color ^= 0x008000;
3335 if( v & 0x04 ) color ^= 0x800000;
3336 if( v & 0x08 ) color ^= 0x100000;
3337 if( v & 0x10 ) color ^= 0x001000;
3338 if( v & 0x20 ) color ^= 0x000010;
3339 if( v & 0x40 ) color ^= 0x080808;
3340 if( v & 0x80 ) color ^= 0x909090;
3344 int MWindow::get_title_color(Edit *edit)
3346 unsigned color = edit->color & 0xffffff;
3347 unsigned alpha = (~edit->color>>24) & 0xff;
3349 if( edit->group_id )
3350 color = get_group_color(edit->group_id);
3351 else if( preferences->autocolor_assets )
3352 color = get_hash_color(edit);
3357 alpha = session->title_bar_alpha*255;
3358 return color | (~alpha<<24);
3361 void MWindow::update_keyframe_guis()
3363 // Send new configuration to keyframe GUI's
3364 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3365 for(int i = 0; i < keyframe_threads->size(); i++)
3367 KeyFrameThread *ptr = keyframe_threads->get(i);
3368 if(edl->tracks->plugin_exists(ptr->plugin))
3372 ptr->close_window();
3375 keyframe_gui_lock->unlock();
3378 void MWindow::update_plugin_guis(int do_keyframe_guis)
3380 // Send new configuration to plugin GUI's
3381 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3383 for(int i = 0; i < plugin_guis->size(); i++)
3385 PluginServer *ptr = plugin_guis->get(i);
3386 if(edl->tracks->plugin_exists(ptr->plugin))
3390 // Schedule for deletion if no plugin
3391 plugin_guis->remove_number(i);
3400 // Change plugin variable if not visible
3401 Track *track = edl->tracks->first;
3404 for(int i = 0; i < track->plugin_set.size(); i++)
3406 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3410 for(int i = 0; i < plugin_guis->size(); i++)
3412 PluginServer *server = plugin_guis->get(i);
3413 if(server->plugin == plugin)
3420 if(!got_it) plugin->show = 0;
3422 plugin = (Plugin*)plugin->next;
3426 track = track->next;
3429 plugin_gui_lock->unlock();
3432 if(do_keyframe_guis) update_keyframe_guis();
3435 int MWindow::plugin_gui_open(Plugin *plugin)
3438 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3439 for(int i = 0; i < plugin_guis->total; i++)
3441 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3447 plugin_gui_lock->unlock();
3451 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3453 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3454 for(int i = 0; i < plugin_guis->total; i++)
3456 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3458 plugin_guis->get(i)->render_gui(data);
3462 plugin_gui_lock->unlock();
3465 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3467 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3468 for(int i = 0; i < plugin_guis->total; i++)
3470 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3472 plugin_guis->get(i)->render_gui(data, size);
3476 plugin_gui_lock->unlock();
3480 void MWindow::update_plugin_states()
3482 plugin_gui_lock->lock("MWindow::update_plugin_states");
3483 for(int i = 0; i < plugin_guis->total; i++)
3487 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3488 PluginServer *src_plugingui = plugin_guis->get(i);
3490 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3491 for(Track *track = edl->tracks->first;
3493 track = track->next)
3496 j < track->plugin_set.total && !result;
3499 PluginSet *plugin_set = track->plugin_set[j];
3500 for(Plugin *plugin = (Plugin*)plugin_set->first;
3502 plugin = (Plugin*)plugin->next)
3504 if(plugin == src_plugin &&
3505 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3511 // Doesn't exist anymore
3514 hide_plugin(src_plugin, 0);
3518 plugin_gui_lock->unlock();
3522 void MWindow::update_plugin_titles()
3524 for(int i = 0; i < plugin_guis->total; i++)
3526 plugin_guis->get(i)->update_title();
3530 int MWindow::asset_to_edl(EDL *new_edl,
3532 RecordLabels *labels)
3534 const int debug = 0;
3535 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3538 // Keep frame rate, sample rate, and output size unchanged.
3539 // These parameters would revert the project if VWindow displayed an asset
3540 // of different size than the project.
3541 if(new_asset->video_data)
3543 new_edl->session->video_tracks = new_asset->layers;
3546 new_edl->session->video_tracks = 0;
3548 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3554 if(new_asset->audio_data)
3556 new_edl->session->audio_tracks = new_asset->channels;
3559 new_edl->session->audio_tracks = 0;
3560 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3562 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3563 new_edl->create_default_tracks();
3564 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3565 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3569 //printf("MWindow::asset_to_edl 3\n");
3570 new_edl->insert_asset(new_asset,
3575 //printf("MWindow::asset_to_edl 3\n");
3576 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3578 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3579 if(edl->session->cursor_on_frames)
3581 double length = new_edl->tracks->total_length();
3582 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3583 new_edl->tracks->clear(length, edl_length, 1, 1);
3589 char string[BCTEXTLEN];
3591 fs.extract_name(string, new_asset->path);
3592 //printf("MWindow::asset_to_edl 3\n");
3594 strcpy(new_edl->local_session->clip_title, string);
3595 //printf("MWindow::asset_to_edl 4 %s\n", string);
3596 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3598 new_edl->local_session->asset2edl = 1;
3603 // Reset everything after a load.
3604 void MWindow::update_project(int load_mode)
3606 const int debug = 0;
3608 if(debug) PRINT_TRACE
3609 edl->tracks->update_y_pixels(theme);
3610 session->update_clip_number();
3612 if(debug) PRINT_TRACE
3614 if( load_mode == LOADMODE_REPLACE ||
3615 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3616 delete gui->keyvalue_popup;
3617 gui->keyvalue_popup = 0;
3621 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3622 if(debug) PRINT_TRACE
3623 gui->unlock_window();
3626 cwindow->update(0, 0, 1, 1, 1);
3628 if(debug) PRINT_TRACE
3630 // Close all the vwindows
3631 if( load_mode == LOADMODE_REPLACE ||
3632 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3633 if(debug) PRINT_TRACE
3634 int first_vwindow = 0;
3635 if(session->show_vwindow) first_vwindow = 1;
3636 // Change visible windows to no source
3637 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3638 VWindow *vwindow = vwindows[i];
3639 if( !vwindow->is_running() ) continue;
3640 vwindow->change_source(-1);
3643 // Close remaining windows
3644 for(int i = first_vwindow; i < vwindows.size(); i++) {
3645 VWindow *vwindow = vwindows[i];
3646 if( !vwindow->is_running() ) continue;
3647 vwindow->close_window();
3649 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3650 VWindow *vwindow = get_viewer(1, -1);
3651 vwindow->change_source(i);
3653 if(debug) PRINT_TRACE
3657 for( int i=0; i<edl->mixers.size(); ++i ) {
3658 Mixer *mixer = edl->mixers[i];
3659 ZWindow *zwindow = get_mixer(mixer);
3660 zwindow->set_title(mixer->title);
3666 if(debug) PRINT_TRACE
3667 cwindow->gui->lock_window("MWindow::update_project 2");
3668 cwindow->gui->timebar->update(0);
3669 Track *track = cwindow->calculate_affected_track();
3670 cwindow->mask_track_id = track ? track->get_id() : -1;
3671 cwindow->gui->tool_panel->raise_tool();
3672 cwindow->gui->unlock_window();
3674 if(debug) PRINT_TRACE
3675 cwindow->refresh_frame(CHANGE_ALL);
3677 awindow->gui->async_update_assets();
3678 if(debug) PRINT_TRACE
3680 gui->lock_window("MWindow::update_project");
3681 gui->update_mixers(0, 0);
3683 if(debug) PRINT_TRACE
3686 void MWindow::update_vwindow()
3688 for( int i=0; i<vwindows.size(); ++i ) {
3689 VWindow *vwindow = vwindows[i];
3690 if( vwindow->is_running() ) {
3691 vwindow->gui->lock_window("MWindow::update_vwindow");
3693 vwindow->gui->unlock_window();
3698 void MWindow::remove_indexfile(Indexable *indexable)
3700 if( !indexable->is_asset ) return;
3701 Asset *asset = (Asset *)indexable;
3703 IndexFile::delete_index(preferences, asset, ".toc");
3704 IndexFile::delete_index(preferences, asset, ".idx");
3705 IndexFile::delete_index(preferences, asset, ".mkr");
3708 void MWindow::rebuild_indices()
3710 for(int i = 0; i < session->drag_assets->total; i++)
3712 Indexable *indexable = session->drag_assets->get(i);
3713 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3714 remove_indexfile(indexable);
3715 // Schedule index build
3716 IndexState *index_state = indexable->index_state;
3717 index_state->index_status = INDEX_NOTTESTED;
3718 if( indexable->is_asset ) {
3719 Asset *asset = (Asset *)indexable;
3720 if( asset->format != FILE_PCM ) {
3721 asset->format = FILE_UNKNOWN;
3722 asset->reset_audio();
3724 asset->reset_video();
3725 remove_asset_from_caches(asset);
3726 // File file; // re-probe the asset
3727 // file.open_file(preferences, asset, 1, 0);
3729 mainindexes->add_next_asset(0, indexable);
3731 mainindexes->start_build();
3735 void MWindow::save_backup()
3739 edl->set_path(session->filename);
3740 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3741 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3742 File::get_config_path(), BACKUP_FILE);
3743 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3744 File::get_config_path(), BACKUP_FILE1);
3745 rename(backup_path, backup_path1);
3746 edl->save_xml(&file, backup_path);
3747 file.terminate_string();
3749 fs.complete_path(backup_path);
3751 if(file.write_to_file(backup_path))
3754 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3755 gui->show_message(string2);
3759 void MWindow::load_backup()
3761 ArrayList<char*> path_list;
3762 path_list.set_array_delete();
3764 char backup_path[BCTEXTLEN];
3765 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3766 File::get_config_path(), BACKUP_FILE);
3768 fs.complete_path(backup_path);
3770 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3771 strcpy(out_path, backup_path);
3773 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3774 edl->local_session->clip_title[0] = 0;
3775 // This is unique to backups since the path of the backup is different than the
3776 // path of the project.
3777 set_filename(edl->path);
3778 path_list.remove_all_objects();
3783 void MWindow::save_undo_data()
3786 undo_after(_("perpetual session"), LOAD_ALL);
3787 char perpetual_path[BCTEXTLEN];
3788 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3789 File::get_config_path(), PERPETUAL_FILE);
3790 FILE *fp = fopen(perpetual_path,"w");
3796 void MWindow::load_undo_data()
3798 char perpetual_path[BCTEXTLEN];
3799 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3800 File::get_config_path(), PERPETUAL_FILE);
3801 FILE *fp = fopen(perpetual_path,"r");
3808 int MWindow::copy_target(const char *path, const char *target)
3810 int ifd = ::open(path, O_RDONLY);
3812 eprintf("Cannot open asset: %s", path);
3816 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
3819 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
3820 char progress_title[BCTEXTLEN];
3821 sprintf(progress_title, _("Copying: %s\n"), target);
3822 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
3824 int64_t count = 0, len = -1;
3825 int bfrsz = 0x100000;
3826 uint8_t *bfr = new uint8_t[bfrsz];
3827 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
3828 if( len != ::write(ofd, bfr, len) ) {
3829 eprintf("Error writing: %s", target);
3832 if( progress.is_cancelled() ) {
3836 progress.update(count += len, 1);
3841 progress.stop_progress();
3843 eprintf("Error reading: %s", path);
3848 eprintf("Cannot create asset target: %s", target);
3853 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
3855 char target[BCTEXTLEN];
3857 const char *bp = real_path, *cp = bp;
3858 const char *lp = link_path, *np = lp;
3859 char *tp = target, *ep = tp+sizeof(target)-1, lch;
3860 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
3861 if( lch == '/' ) { np = lp; cp = bp; }
3863 while( tp<ep && *np ) {
3864 if( *np++ != '/' ) continue;
3865 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
3867 while( tp<ep && *cp ) *tp++ = *cp++;
3871 strcpy(target, real_path);
3872 if( symlink(target, link_path) ) {
3873 eprintf("Cannot create symlink: %s", link_path);
3879 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
3881 char dir_path[BCTEXTLEN];
3882 strcpy(dir_path, dir);
3884 fs.complete_path(dir_path);
3887 if( !stat(dir_path, &st) ) {
3888 if( !S_ISDIR(st.st_mode) ) {
3889 eprintf("Path exists and is not a directory\n%s", dir_path);
3894 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
3895 eprintf("Cannot create directory\n%s", dir_path);
3899 char *real_dir = realpath(dir_path, 0);
3900 strcpy(dir_path, real_dir);
3903 EDL *save_edl = new EDL;
3904 save_edl->create_objects();
3905 save_edl->copy_all(edl);
3907 char progress_title[BCTEXTLEN];
3908 sprintf(progress_title, _("Saving to %s:\n"), dir);
3909 int total_assets = save_edl->assets->total();
3910 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
3912 Asset *current = save_edl->assets->first;
3913 for( int i=0; !ret && current; ++i, current=NEXT ) {
3914 char *path = current->path;
3915 if( ::stat(path, &st) ) {
3916 eprintf("Asset not found: %s", path);
3919 char *real_path = realpath(path, 0);
3920 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
3921 char link_path[BCTEXTLEN];
3922 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
3924 if( strcmp(real_path, link_path) ) {
3925 if( !::lstat(link_path, &st) ) {
3927 ::remove(link_path);
3933 eprintf("copy/link to self, skippped: %s", path);
3937 if( save_mode == SAVE_PROJECT_COPY ) {
3938 if( copy_target(real_path, link_path) )
3942 link_target(real_path, link_path,
3943 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
3947 strcpy(path, link_path);
3949 if( progress->is_cancelled() ) break;
3950 progress->update(i);
3953 progress->stop_progress();
3956 char *cp = strrchr(dir_path,'/');
3957 char *bp = cp ? cp+1 : dir_path;
3958 char filename[BCTEXTLEN];
3959 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
3960 save_edl->set_path(filename);
3962 save_edl->save_xml(&file, filename);
3963 file.terminate_string();
3965 if( !file.write_to_file(filename) ) {
3966 char string[BCTEXTLEN];
3967 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
3968 gui->lock_window("SaveProject::run 2");
3969 gui->show_message(string);
3970 gui->unlock_window();
3971 gui->mainmenu->add_load(filename);
3974 eprintf(_("Couldn't open %s."), filename);
3976 save_edl->remove_user();
3979 gui->lock_window("MWindow::save_project");
3980 ArrayList<char*> filenames;
3981 filenames.append(filename);
3982 load_filenames(&filenames, LOADMODE_REPLACE);
3983 gui->unlock_window();
3988 static inline int gcd(int m, int n)
3991 if( m < n ) { r = m; m = n; n = r; }
3992 while( (r = m % n) != 0 ) { m = n; n = r; }
3996 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3999 if(!width || !height) return 1;
4000 if( width == 720 && (height == 480 || height == 576) ) {
4001 w = 4; h = 3; return 0; // for NTSC and PAL
4003 double ar = (double)width / height;
4004 // square-ish pixels
4005 if( EQUIV(ar, 1.0000) ) return 0;
4006 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4007 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4008 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4009 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4010 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4011 int ww = width, hh = height;
4012 // numerator, denominator must be under mx
4013 int mx = 255, n = gcd(ww, hh);
4014 if( n > 1 ) { ww /= n; hh /= n; }
4015 // search near height in case extra/missing lines
4016 if( ww >= mx || hh >= mx ) {
4017 double err = height; // +/- 2 percent height
4018 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4019 int iw = width, ih = height+i;
4020 if( (n=gcd(iw, ih)) > 1 ) {
4021 int u = iw/n; if( u >= mx ) continue;
4022 int v = ih/n; if( v >= mx ) continue;
4023 double r = (double) u/v, er = fabs(ar-r);
4024 if( er >= err ) continue;
4025 err = er; ww = u; hh = v;
4034 void MWindow::reset_caches()
4036 frame_cache->remove_all();
4037 wave_cache->remove_all();
4038 audio_cache->remove_all();
4039 video_cache->remove_all();
4040 if( cwindow->playback_engine ) {
4041 if( cwindow->playback_engine->audio_cache )
4042 cwindow->playback_engine->audio_cache->remove_all();
4043 if( cwindow->playback_engine->video_cache )
4044 cwindow->playback_engine->video_cache->remove_all();
4046 for(int i = 0; i < vwindows.size(); i++) {
4047 VWindow *vwindow = vwindows[i];
4048 if( !vwindow->is_running() ) continue;
4049 if( !vwindow->playback_engine ) continue;
4050 if( vwindow->playback_engine->audio_cache )
4051 vwindow->playback_engine->audio_cache->remove_all();
4052 if( vwindow->playback_engine->video_cache )
4053 vwindow->playback_engine->video_cache->remove_all();
4057 void MWindow::remove_asset_from_caches(Asset *asset)
4059 frame_cache->remove_asset(asset);
4060 wave_cache->remove_asset(asset);
4061 audio_cache->delete_entry(asset);
4062 video_cache->delete_entry(asset);
4063 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4064 cwindow->playback_engine->audio_cache->delete_entry(asset);
4065 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4066 cwindow->playback_engine->video_cache->delete_entry(asset);
4067 for(int i = 0; i < vwindows.size(); i++) {
4068 VWindow *vwindow = vwindows[i];
4069 if( !vwindow->is_running() ) continue;
4070 if( !vwindow->playback_engine ) continue;
4071 if( vwindow->playback_engine->audio_cache )
4072 vwindow->playback_engine->audio_cache->delete_entry(asset);
4073 if( vwindow->playback_engine->video_cache )
4074 vwindow->playback_engine->video_cache->delete_entry(asset);
4079 void MWindow::remove_assets_from_project(int push_undo, int redraw,
4080 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4082 awindow->gui->close_view_popup();
4084 for(int i = 0; i < drag_assets->total; i++) {
4085 Indexable *indexable = drag_assets->get(i);
4086 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
4089 // Remove from VWindow.
4090 for(int i = 0; i < session->drag_clips->total; i++) {
4091 for(int j = 0; j < vwindows.size(); j++) {
4092 VWindow *vwindow = vwindows[j];
4093 if( !vwindow->is_running() ) continue;
4094 if(session->drag_clips->get(i) == vwindow->get_edl()) {
4095 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4096 vwindow->delete_source(1, 1);
4097 vwindow->gui->unlock_window();
4102 for(int i = 0; i < drag_assets->size(); i++) {
4103 for(int j = 0; j < vwindows.size(); j++) {
4104 VWindow *vwindow = vwindows[j];
4105 if( !vwindow->is_running() ) continue;
4106 if(drag_assets->get(i) == vwindow->get_source()) {
4107 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4108 vwindow->delete_source(1, 1);
4109 vwindow->gui->unlock_window();
4114 for(int i = 0; i < drag_assets->size(); i++) {
4115 Indexable *indexable = drag_assets->get(i);
4116 remove_indexfile(indexable);
4119 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4120 if(push_undo) undo_before();
4121 if(drag_assets) edl->remove_from_project(drag_assets);
4122 if(drag_clips) edl->remove_from_project(drag_clips);
4123 if(redraw) save_backup();
4124 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4128 gui->lock_window("MWindow::remove_assets_from_project 3");
4129 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4130 gui->unlock_window();
4132 // Removes from playback here
4133 sync_parameters(CHANGE_ALL);
4136 awindow->gui->async_update_assets();
4139 void MWindow::remove_assets_from_disk()
4141 remove_assets_from_project(1,
4143 session->drag_assets,
4144 session->drag_clips);
4147 for(int i = 0; i < session->drag_assets->total; i++)
4149 remove(session->drag_assets->get(i)->path);
4153 void MWindow::dump_plugins(FILE *fp)
4155 if( !plugindb ) return;
4156 for(int i = 0; i < plugindb->total; i++)
4158 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4159 " synth=%d transition=%d theme=%d %s\n",
4160 plugindb->get(i)->plugin_type,
4161 plugindb->get(i)->audio,
4162 plugindb->get(i)->video,
4163 plugindb->get(i)->realtime,
4164 plugindb->get(i)->multichannel,
4165 plugindb->get(i)->get_synthesis(),
4166 plugindb->get(i)->transition,
4167 plugindb->get(i)->theme,
4168 plugindb->get(i)->title);
4172 void MWindow::dump_edl(FILE *fp)
4178 void MWindow::dump_undo(FILE *fp)
4184 void MWindow::dump_exe(FILE *fp)
4186 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4187 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4189 int ret = -1, n = 100;
4190 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4191 exe_path[len] = 0; strcpy(proc_path, exe_path);
4194 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4197 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4198 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4199 struct tm *tm = localtime(&st.st_mtime);
4201 strftime(mtime, sizeof(mtime), "%F %T", tm);
4202 fprintf(fp,"mtime: %s\n", mtime);
4204 // people hit ctl-c waiting for this
4205 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4206 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4209 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4210 int64_t maxsz = 1024*pagsz;
4211 int64_t size = st.st_size, pos = 0;
4213 while( (bfrsz = size-pos) > 0 ) {
4214 if( bfrsz > maxsz ) bfrsz = maxsz;
4215 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4216 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4217 if( bfr == MAP_FAILED ) break;
4218 sha1.addBytes(bfr, bfrsz);
4223 ret = pos < size ? EIO : 0;
4224 fprintf(fp, "SHA1: ");
4225 uint8_t digest[20]; sha1.computeHash(digest);
4226 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4227 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4228 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4233 void MWindow::trap_hook(FILE *fp, void *vp)
4235 MWindow *mwindow = (MWindow *)vp;
4236 // fprintf(fp, "\nPLUGINS:\n");
4237 // mwindow->dump_plugins(fp);
4238 fprintf(fp, "\nEDL:\n");
4239 mwindow->dump_edl(fp);
4240 fprintf(fp, "\nUNDO:\n");
4241 mwindow->dump_undo(fp);
4242 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4243 mwindow->dump_exe(fp);
4251 int MWindow::save_defaults()
4253 gui->save_defaults(defaults);
4254 edl->save_defaults(defaults);
4255 session->save_defaults(defaults);
4256 preferences->save_defaults(defaults);
4258 for(int i = 0; i < plugin_guis->total; i++)
4260 // Pointer comparison
4261 plugin_guis->get(i)->save_defaults();
4263 awindow->save_defaults(defaults);
4269 int MWindow::run_script(FileXML *script)
4271 int result = 0, result2 = 0;
4272 while(!result && !result2)
4274 result = script->read_tag();
4277 if(script->tag.title_is("new_project"))
4279 // Run new in immediate mode.
4280 // gui->mainmenu->new_project->run_script(script);
4283 if(script->tag.title_is("record"))
4285 // Run record as a thread. It is a terminal command.
4287 // Will read the complete scipt file without letting record read it if not
4293 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4300 // ================================= synchronization
4303 int MWindow::interrupt_indexes()
4305 mainprogress->cancelled = 1;
4306 mainindexes->interrupt_build();
4312 void MWindow::next_time_format()
4314 switch(edl->session->time_format)
4316 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4317 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4318 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4319 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4320 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4321 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4322 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4325 time_format_common();
4328 void MWindow::prev_time_format()
4330 switch(edl->session->time_format)
4332 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4333 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4334 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4335 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4336 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4337 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4338 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4341 time_format_common();
4344 void MWindow::time_format_common()
4346 gui->lock_window("MWindow::next_time_format");
4347 gui->redraw_time_dependancies();
4350 char string[BCTEXTLEN], string2[BCTEXTLEN];
4351 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4352 gui->show_message(string);
4354 gui->unlock_window();
4358 int MWindow::set_filename(const char *filename)
4360 if( filename != session->filename )
4361 strcpy(session->filename, filename);
4362 if( filename != edl->path )
4363 strcpy(edl->path, filename);
4367 if(filename[0] == 0)
4369 gui->set_title(PROGRAM_NAME);
4374 char string[BCTEXTLEN], string2[BCTEXTLEN];
4375 dir.extract_name(string, filename);
4376 sprintf(string2, PROGRAM_NAME ": %s", string);
4377 gui->set_title(string2);
4390 int MWindow::set_loop_boundaries()
4392 double start = edl->local_session->get_selectionstart();
4393 double end = edl->local_session->get_selectionend();
4401 if(edl->tracks->total_length())
4404 end = edl->tracks->total_length();
4411 if(edl->local_session->loop_playback && start != end)
4413 edl->local_session->loop_start = start;
4414 edl->local_session->loop_end = end;
4425 int MWindow::reset_meters()
4427 cwindow->gui->lock_window("MWindow::reset_meters 1");
4428 cwindow->gui->meters->reset_meters();
4429 cwindow->gui->unlock_window();
4431 for(int j = 0; j < vwindows.size(); j++) {
4432 VWindow *vwindow = vwindows[j];
4433 if( !vwindow->is_running() ) continue;
4434 vwindow->gui->lock_window("MWindow::reset_meters 2");
4435 vwindow->gui->meters->reset_meters();
4436 vwindow->gui->unlock_window();
4439 lwindow->gui->lock_window("MWindow::reset_meters 3");
4440 lwindow->gui->panel->reset_meters();
4441 lwindow->gui->unlock_window();
4443 gui->lock_window("MWindow::reset_meters 4");
4444 gui->reset_meters();
4445 gui->unlock_window();
4450 void MWindow::resync_guis()
4454 gui->lock_window("MWindow::resync_guis");
4455 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4456 gui->unlock_window();
4458 cwindow->gui->lock_window("MWindow::resync_guis");
4459 cwindow->gui->resize_event(cwindow->gui->get_w(),
4460 cwindow->gui->get_h());
4461 int channels = edl->session->audio_channels;
4462 cwindow->gui->meters->set_meters(channels, 1);
4463 cwindow->gui->flush();
4464 cwindow->gui->unlock_window();
4466 for(int i = 0; i < vwindows.size(); i++) {
4467 VWindow *vwindow = vwindows[i];
4468 if( !vwindow->is_running() ) continue;
4469 vwindow->gui->lock_window("MWindow::resync_guis");
4470 vwindow->gui->resize_event(vwindow->gui->get_w(),
4471 vwindow->gui->get_h());
4472 vwindow->gui->meters->set_meters(channels, 1);
4473 vwindow->gui->flush();
4474 vwindow->gui->unlock_window();
4477 lwindow->gui->lock_window("MWindow::resync_guis");
4478 lwindow->gui->panel->set_meters(channels, 1);
4479 lwindow->gui->flush();
4480 lwindow->gui->unlock_window();
4483 if(((edl->session->output_w % 4) ||
4484 (edl->session->output_h % 4)) &&
4485 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4487 MainError::show_error(
4488 _("This project's dimensions are not multiples of 4 so\n"
4489 "it can't be rendered by OpenGL."));
4494 sync_parameters(CHANGE_ALL);
4497 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4499 File *file = new File;
4500 EDLSession *session = edl->session;
4501 double old_framerate = session->frame_rate;
4502 double old_samplerate = session->sample_rate;
4503 int old_auto_keyframes = session->auto_keyframes;
4504 session->auto_keyframes = 0;
4505 int result = file->open_file(preferences, asset, 1, 0);
4506 if( !result && delete_tracks > 0 )
4508 int video_layers = asset->get_video_layers();
4509 if( !result && asset->video_data && vstream < video_layers ) {
4510 // try to get asset up to date, may fail
4511 file->select_video_stream(asset, vstream);
4512 // either way use what was/is there.
4513 double framerate = asset->get_frame_rate();
4514 int width = asset->get_w();
4515 int height = asset->get_h();
4516 // must be multiple of 4 for opengl
4517 width = (width+3) & ~3; height = (height+3) & ~3;
4518 int driver = session->playback_config->vconfig->driver;
4519 int color_model = file->get_best_colormodel(asset, driver);
4520 // color_model = BC_CModels::is_yuv(color_model) ?
4521 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4522 // BC_CModels::is_float(color_model) ?
4523 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4524 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4525 // have alpha for now
4526 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4527 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4528 session->color_model = color_model;
4529 session->output_w = width;
4530 session->output_h = height;
4531 session->frame_rate = framerate;
4532 // not, asset->actual_width/actual_height
4533 asset->width = session->output_w;
4534 asset->height = session->output_h;
4535 asset->frame_rate = session->frame_rate;
4536 create_aspect_ratio(session->aspect_w, session->aspect_h,
4537 session->output_w, session->output_h);
4538 Track *track = edl->tracks->first;
4539 for( Track *next_track=0; track; track=next_track ) {
4540 next_track = track->next;
4541 if( track->data_type != TRACK_VIDEO ) continue;
4542 if( delete_tracks ) {
4543 Edit *edit = track->edits->first;
4544 for( Edit *next_edit=0; edit; edit=next_edit ) {
4545 next_edit = edit->next;
4546 if( edit->channel != vstream ||
4547 !edit->asset || !edit->asset->is_asset ||
4548 !asset->equivalent(*edit->asset,1,1,edl) )
4552 if( track->edits->first ) {
4553 track->track_w = edl->session->output_w;
4554 track->track_h = edl->session->output_h;
4556 else if( delete_tracks )
4557 edl->tracks->delete_track(track);
4560 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4562 if( !result && asset->audio_data && asset->channels > 0 ) {
4563 session->sample_rate = asset->get_sample_rate();
4564 int64_t channel_mask = 0;
4565 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4566 file->get_audio_for_video(vstream, astream, channel_mask);
4567 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4568 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4570 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4571 if( channels < 1 ) channels = 1;
4572 if( channels > 6 ) channels = 6;
4573 session->audio_tracks = session->audio_channels = channels;
4575 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4576 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4577 remap_audio(MWindow::AUDIO_1_TO_1);
4579 if( delete_tracks ) {
4580 Track *track = edl->tracks->first;
4581 for( Track *next_track=0; track; track=next_track ) {
4582 next_track = track->next;
4583 if( track->data_type != TRACK_AUDIO ) continue;
4584 Edit *edit = track->edits->first;
4585 for( Edit *next_edit=0; edit; edit=next_edit ) {
4586 next_edit = edit->next;
4587 if( !((1<<edit->channel) & channel_mask) ||
4588 !edit->asset || !edit->asset->is_asset ||
4589 !asset->equivalent(*edit->asset,1,1,edl) )
4592 if( !track->edits->first )
4593 edl->tracks->delete_track(track);
4597 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4600 session->auto_keyframes = old_auto_keyframes;
4601 if( !result && delete_tracks > 0 ) {
4603 undo_after(_("select asset"), LOAD_ALL);
4609 int MWindow::select_asset(int vtrack, int delete_tracks)
4611 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4613 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4614 if( !track ) return 1;
4615 Edit *edit = track->edits->first;
4616 if( !edit ) return 1;
4617 Asset *asset = edit->asset;
4618 if( !asset || !asset->is_asset ) return 1;
4619 return select_asset(asset, edit->channel, 0, delete_tracks);
4622 void MWindow::dump_plugindb(FILE *fp)
4624 if( !plugindb ) return;
4625 for(int i = 0; i < plugindb->total; i++)
4626 plugindb->get(i)->dump(fp);
4629 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4632 double unit_position = edl->local_session->get_selectionstart(1);
4633 unit_position = patch->track->to_units(unit_position, 0);
4635 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4636 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4639 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4642 double unit_position = edl->local_session->get_selectionstart(1);
4643 unit_position = patch->track->to_units(unit_position, 0);
4645 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4646 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4649 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4652 double unit_position = edl->local_session->get_selectionstart(1);
4653 unit_position = patch->track->to_units(unit_position, 0);
4655 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4656 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4659 PatchGUI *MWindow::get_patchgui(Track *track)
4661 PatchGUI *patchgui = 0;
4662 TimelinePane **panes = gui->pane;
4663 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4664 if( !panes[i] ) continue;
4665 PatchBay *patchbay = panes[i]->patchbay;
4666 if( !patchbay ) continue;
4667 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4668 if( patchbay->patches.values[j]->track == track )
4669 patchgui = patchbay->patches.values[j];