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_span_keyframes(int value)
2994 edl->session->span_keyframes = value;
2995 gui->mbuttons->edit_panel->span_keyframe->update(value);
2997 cwindow->gui->lock_window("MWindow::set_span_keyframes");
2998 cwindow->gui->edit_panel->span_keyframe->update(value);
2999 cwindow->gui->flush();
3000 cwindow->gui->unlock_window();
3003 void MWindow::set_auto_visibility(Autos *autos, int value)
3005 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3006 edl->session->auto_conf->plugins = value;
3007 else if( autos->autoidx >= 0 )
3008 edl->session->auto_conf->autos[autos->autoidx] = value;
3012 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3013 gui->mainmenu->update_toggles(1);
3014 gui->unlock_window();
3015 gwindow->gui->update_toggles(1);
3016 gui->lock_window("MWindow::set_auto_visibility");
3019 void MWindow::set_keyframe_type(int mode)
3021 gui->lock_window("MWindow::set_keyframe_type");
3022 edl->local_session->floatauto_type = mode;
3023 gui->mainmenu->update_toggles(0);
3024 gui->unlock_window();
3027 int MWindow::set_editing_mode(int new_editing_mode)
3029 edl->session->editing_mode = new_editing_mode;
3030 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3031 gui->mbuttons->edit_panel->update();
3032 gui->set_editing_mode(1);
3034 cwindow->gui->lock_window("MWindow::set_editing_mode");
3035 cwindow->gui->edit_panel->update();
3036 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3037 cwindow->gui->unlock_window();
3041 void MWindow::toggle_editing_mode()
3043 int mode = edl->session->editing_mode;
3044 if( mode == EDITING_ARROW )
3045 set_editing_mode(EDITING_IBEAM);
3047 set_editing_mode(EDITING_ARROW);
3050 void MWindow::toggle_camera_xyz()
3052 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3053 gwindow->gui->toggle_camera_xyz();
3054 gwindow->gui->unlock_window();
3057 void MWindow::toggle_projector_xyz()
3059 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3060 gwindow->gui->toggle_projector_xyz();
3061 gwindow->gui->unlock_window();
3064 void MWindow::set_labels_follow_edits(int value)
3066 edl->session->labels_follow_edits = value;
3067 gui->mbuttons->edit_panel->locklabels->update(value);
3068 gui->mainmenu->labels_follow_edits->set_checked(value);
3072 void MWindow::sync_parameters(int change_type)
3074 if( in_destructor ) return;
3076 // Sync engines which are playing back
3077 if( cwindow->playback_engine->is_playing_back ) {
3078 if( change_type == CHANGE_PARAMS ) {
3079 // TODO: block keyframes until synchronization is done
3080 cwindow->playback_engine->sync_parameters(edl);
3084 int command = cwindow->playback_engine->command->command;
3085 // Waiting for tracking to finish would make the restart position more
3086 // accurate but it can't lock the window to stop tracking for some reason.
3087 // Not waiting for tracking gives a faster response but restart position is
3088 // only as accurate as the last tracking update.
3089 cwindow->playback_engine->transport_stop(0);
3090 cwindow->playback_engine->next_command->realtime = 1;
3091 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3095 cwindow->refresh_frame(change_type);
3099 void MWindow::age_caches()
3101 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3103 // preferences->cache_size,
3104 // audio_cache->get_memory_usage(1),
3105 // video_cache->get_memory_usage(1),
3106 // frame_cache->get_memory_usage(),
3107 // wave_cache->get_memory_usage(),
3109 frame_cache->age_cache(512);
3110 wave_cache->age_cache(8192);
3112 int64_t memory_usage;
3113 int64_t prev_memory_usage = 0;
3115 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3116 while( !result && prev_memory_usage !=
3117 (memory_usage=video_cache->get_memory_usage(1)) &&
3118 memory_usage > video_size ) {
3119 video_cache->delete_oldest();
3120 prev_memory_usage = memory_usage;
3123 prev_memory_usage = 0;
3125 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3126 while( !result && prev_memory_usage !=
3127 (memory_usage=audio_cache->get_memory_usage(1)) &&
3128 memory_usage > audio_size ) {
3129 audio_cache->delete_oldest();
3130 prev_memory_usage = memory_usage;
3134 void MWindow::reset_android_remote()
3136 gui->use_android_remote(preferences->android_remote);
3140 void MWindow::show_keyframe_gui(Plugin *plugin)
3142 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3143 // Find existing thread
3144 for(int i = 0; i < keyframe_threads->size(); i++)
3146 if(keyframe_threads->get(i)->plugin == plugin)
3148 keyframe_threads->get(i)->start_window(plugin, 0);
3149 keyframe_gui_lock->unlock();
3154 // Find unused thread
3155 for(int i = 0; i < keyframe_threads->size(); i++)
3157 if(!keyframe_threads->get(i)->plugin)
3159 keyframe_threads->get(i)->start_window(plugin, 0);
3160 keyframe_gui_lock->unlock();
3165 // Create new thread
3166 KeyFrameThread *thread = new KeyFrameThread(this);
3167 keyframe_threads->append(thread);
3168 thread->start_window(plugin, 0);
3170 keyframe_gui_lock->unlock();
3177 void MWindow::show_plugin(Plugin *plugin)
3182 // Remove previously deleted plugin GUIs
3183 dead_plugin_lock->lock("MWindow::show_plugin");
3184 dead_plugins->remove_all_objects();
3185 dead_plugin_lock->unlock();
3187 //printf("MWindow::show_plugin %d\n", __LINE__);
3191 plugin_gui_lock->lock("MWindow::show_plugin");
3192 for(int i = 0; i < plugin_guis->total; i++)
3194 // Pointer comparison
3195 if(plugin_guis->get(i)->plugin == plugin)
3197 plugin_guis->get(i)->raise_window();
3204 //printf("MWindow::show_plugin 1\n");
3205 if( !done && !plugin->track ) {
3206 printf("MWindow::show_plugin track not defined.\n");
3210 PluginServer *server = scan_plugindb(plugin->title,
3211 plugin->track->data_type);
3213 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3214 if(server && server->uses_gui)
3216 PluginServer *gui = new PluginServer(*server);
3217 plugin_guis->append(gui);
3218 // Needs mwindow to do GUI
3219 gui->set_mwindow(this);
3220 gui->open_plugin(0, preferences, edl, plugin);
3225 plugin_gui_lock->unlock();
3226 //printf("MWindow::show_plugin %d\n", __LINE__);
3229 //printf("MWindow::show_plugin 2\n");
3232 void MWindow::hide_plugin(Plugin *plugin, int lock)
3235 // Update the toggle
3236 gui->lock_window("MWindow::hide_plugin");
3237 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3238 gui->unlock_window();
3240 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3241 for(int i = 0; i < plugin_guis->total; i++)
3243 if(plugin_guis->get(i)->plugin == plugin)
3245 PluginServer *ptr = plugin_guis->get(i);
3246 plugin_guis->remove(ptr);
3247 if(lock) plugin_gui_lock->unlock();
3248 // Last command executed in client side close
3249 // Schedule for deletion
3256 if(lock) plugin_gui_lock->unlock();
3259 void MWindow::delete_plugin(PluginServer *plugin)
3261 dead_plugin_lock->lock("MWindow::delete_plugin");
3262 dead_plugins->append(plugin);
3263 dead_plugin_lock->unlock();
3266 void MWindow::hide_plugins()
3268 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3269 while(plugin_guis->size())
3271 PluginServer *ptr = plugin_guis->get(0);
3272 plugin_guis->remove(ptr);
3273 plugin_gui_lock->unlock();
3274 // Last command executed in client side close
3275 // Schedule for deletion
3278 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3280 plugin_gui_lock->unlock();
3282 hide_keyframe_guis();
3285 void MWindow::hide_keyframe_guis()
3287 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3288 for(int i = 0; i < keyframe_threads->size(); i++)
3290 keyframe_threads->get(i)->close_window();
3292 keyframe_gui_lock->unlock();
3295 void MWindow::hide_keyframe_gui(Plugin *plugin)
3297 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3298 for(int i = 0; i < keyframe_threads->size(); i++)
3300 if(keyframe_threads->get(i)->plugin == plugin)
3302 keyframe_threads->get(i)->close_window();
3306 keyframe_gui_lock->unlock();
3309 int MWindow::get_hash_color(Edit *edit)
3311 Indexable *idxbl = edit->asset ?
3312 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3313 if( !idxbl ) return 0;
3314 char path[BCTEXTLEN];
3315 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3316 edl->session->proxy_scale == 1 ||
3317 ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
3318 strcpy(path, idxbl->path);
3319 char *cp = strrchr(path, '/');
3320 cp = !cp ? path : cp+1;
3321 uint8_t *bp = (uint8_t*)cp;
3323 while( *bp ) v += *bp++;
3324 return get_hash_color(v);
3327 int MWindow::get_hash_color(int v)
3329 int hash = 0x303030;
3330 if( v & 0x01 ) hash ^= 0x000040;
3331 if( v & 0x02 ) hash ^= 0x004000;
3332 if( v & 0x04 ) hash ^= 0x400000;
3333 if( v & 0x08 ) hash ^= 0x080000;
3334 if( v & 0x10 ) hash ^= 0x000800;
3335 if( v & 0x20 ) hash ^= 0x000008;
3336 if( v & 0x40 ) hash ^= 0x404040;
3337 if( v & 0x80 ) hash ^= 0x080808;
3341 int MWindow::get_group_color(int v)
3343 int color = 0x606060;
3344 if( v & 0x01 ) color ^= 0x000080;
3345 if( v & 0x02 ) color ^= 0x008000;
3346 if( v & 0x04 ) color ^= 0x800000;
3347 if( v & 0x08 ) color ^= 0x100000;
3348 if( v & 0x10 ) color ^= 0x001000;
3349 if( v & 0x20 ) color ^= 0x000010;
3350 if( v & 0x40 ) color ^= 0x080808;
3351 if( v & 0x80 ) color ^= 0x909090;
3355 int MWindow::get_title_color(Edit *edit)
3357 unsigned color = edit->color & 0xffffff;
3358 unsigned alpha = (~edit->color>>24) & 0xff;
3360 if( edit->group_id )
3361 color = get_group_color(edit->group_id);
3362 else if( preferences->autocolor_assets )
3363 color = get_hash_color(edit);
3368 alpha = session->title_bar_alpha*255;
3369 return color | (~alpha<<24);
3372 void MWindow::update_keyframe_guis()
3374 // Send new configuration to keyframe GUI's
3375 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3376 for(int i = 0; i < keyframe_threads->size(); i++)
3378 KeyFrameThread *ptr = keyframe_threads->get(i);
3379 if(edl->tracks->plugin_exists(ptr->plugin))
3383 ptr->close_window();
3386 keyframe_gui_lock->unlock();
3389 void MWindow::update_plugin_guis(int do_keyframe_guis)
3391 // Send new configuration to plugin GUI's
3392 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3394 for(int i = 0; i < plugin_guis->size(); i++)
3396 PluginServer *ptr = plugin_guis->get(i);
3397 if(edl->tracks->plugin_exists(ptr->plugin))
3401 // Schedule for deletion if no plugin
3402 plugin_guis->remove_number(i);
3411 // Change plugin variable if not visible
3412 Track *track = edl->tracks->first;
3415 for(int i = 0; i < track->plugin_set.size(); i++)
3417 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3421 for(int i = 0; i < plugin_guis->size(); i++)
3423 PluginServer *server = plugin_guis->get(i);
3424 if(server->plugin == plugin)
3431 if(!got_it) plugin->show = 0;
3433 plugin = (Plugin*)plugin->next;
3437 track = track->next;
3440 plugin_gui_lock->unlock();
3443 if(do_keyframe_guis) update_keyframe_guis();
3446 int MWindow::plugin_gui_open(Plugin *plugin)
3449 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3450 for(int i = 0; i < plugin_guis->total; i++)
3452 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3458 plugin_gui_lock->unlock();
3462 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3464 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3465 for(int i = 0; i < plugin_guis->total; i++)
3467 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3469 plugin_guis->get(i)->render_gui(data);
3473 plugin_gui_lock->unlock();
3476 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3478 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3479 for(int i = 0; i < plugin_guis->total; i++)
3481 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3483 plugin_guis->get(i)->render_gui(data, size);
3487 plugin_gui_lock->unlock();
3491 void MWindow::update_plugin_states()
3493 plugin_gui_lock->lock("MWindow::update_plugin_states");
3494 for(int i = 0; i < plugin_guis->total; i++)
3498 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3499 PluginServer *src_plugingui = plugin_guis->get(i);
3501 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3502 for(Track *track = edl->tracks->first;
3504 track = track->next)
3507 j < track->plugin_set.total && !result;
3510 PluginSet *plugin_set = track->plugin_set[j];
3511 for(Plugin *plugin = (Plugin*)plugin_set->first;
3513 plugin = (Plugin*)plugin->next)
3515 if(plugin == src_plugin &&
3516 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3522 // Doesn't exist anymore
3525 hide_plugin(src_plugin, 0);
3529 plugin_gui_lock->unlock();
3533 void MWindow::update_plugin_titles()
3535 for(int i = 0; i < plugin_guis->total; i++)
3537 plugin_guis->get(i)->update_title();
3541 int MWindow::asset_to_edl(EDL *new_edl,
3543 RecordLabels *labels)
3545 const int debug = 0;
3546 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3549 // Keep frame rate, sample rate, and output size unchanged.
3550 // These parameters would revert the project if VWindow displayed an asset
3551 // of different size than the project.
3552 if(new_asset->video_data)
3554 new_edl->session->video_tracks = new_asset->layers;
3557 new_edl->session->video_tracks = 0;
3559 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3565 if(new_asset->audio_data)
3567 new_edl->session->audio_tracks = new_asset->channels;
3570 new_edl->session->audio_tracks = 0;
3571 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3573 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3574 new_edl->create_default_tracks();
3575 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3576 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3580 //printf("MWindow::asset_to_edl 3\n");
3581 new_edl->insert_asset(new_asset,
3586 //printf("MWindow::asset_to_edl 3\n");
3587 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3589 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3590 if(edl->session->cursor_on_frames)
3592 double length = new_edl->tracks->total_length();
3593 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3594 new_edl->tracks->clear(length, edl_length, 1, 1);
3600 char string[BCTEXTLEN];
3602 fs.extract_name(string, new_asset->path);
3603 //printf("MWindow::asset_to_edl 3\n");
3605 strcpy(new_edl->local_session->clip_title, string);
3606 //printf("MWindow::asset_to_edl 4 %s\n", string);
3607 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3609 new_edl->local_session->asset2edl = 1;
3614 // Reset everything after a load.
3615 void MWindow::update_project(int load_mode)
3617 const int debug = 0;
3619 if(debug) PRINT_TRACE
3620 edl->tracks->update_y_pixels(theme);
3621 session->update_clip_number();
3623 if(debug) PRINT_TRACE
3625 if( load_mode == LOADMODE_REPLACE ||
3626 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3627 delete gui->keyvalue_popup;
3628 gui->keyvalue_popup = 0;
3632 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3633 if(debug) PRINT_TRACE
3634 gui->unlock_window();
3637 cwindow->update(0, 0, 1, 1, 1);
3639 if(debug) PRINT_TRACE
3641 // Close all the vwindows
3642 if( load_mode == LOADMODE_REPLACE ||
3643 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3644 if(debug) PRINT_TRACE
3645 int first_vwindow = 0;
3646 if(session->show_vwindow) first_vwindow = 1;
3647 // Change visible windows to no source
3648 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3649 VWindow *vwindow = vwindows[i];
3650 if( !vwindow->is_running() ) continue;
3651 vwindow->change_source(-1);
3654 // Close remaining windows
3655 for(int i = first_vwindow; i < vwindows.size(); i++) {
3656 VWindow *vwindow = vwindows[i];
3657 if( !vwindow->is_running() ) continue;
3658 vwindow->close_window();
3660 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3661 VWindow *vwindow = get_viewer(1, -1);
3662 vwindow->change_source(i);
3664 if(debug) PRINT_TRACE
3668 for( int i=0; i<edl->mixers.size(); ++i ) {
3669 Mixer *mixer = edl->mixers[i];
3670 ZWindow *zwindow = get_mixer(mixer);
3671 zwindow->set_title(mixer->title);
3677 if(debug) PRINT_TRACE
3678 cwindow->gui->lock_window("MWindow::update_project 2");
3679 cwindow->gui->timebar->update(0);
3680 Track *track = cwindow->calculate_affected_track();
3681 cwindow->mask_track_id = track ? track->get_id() : -1;
3682 cwindow->gui->tool_panel->raise_tool();
3683 cwindow->gui->unlock_window();
3685 if(debug) PRINT_TRACE
3686 cwindow->refresh_frame(CHANGE_ALL);
3688 awindow->gui->async_update_assets();
3689 if(debug) PRINT_TRACE
3691 gui->lock_window("MWindow::update_project");
3692 gui->update_mixers(0, 0);
3694 if(debug) PRINT_TRACE
3697 void MWindow::update_vwindow()
3699 for( int i=0; i<vwindows.size(); ++i ) {
3700 VWindow *vwindow = vwindows[i];
3701 if( vwindow->is_running() ) {
3702 vwindow->gui->lock_window("MWindow::update_vwindow");
3704 vwindow->gui->unlock_window();
3709 void MWindow::remove_indexfile(Indexable *indexable)
3711 if( !indexable->is_asset ) return;
3712 Asset *asset = (Asset *)indexable;
3714 IndexFile::delete_index(preferences, asset, ".toc");
3715 IndexFile::delete_index(preferences, asset, ".idx");
3716 IndexFile::delete_index(preferences, asset, ".mkr");
3719 void MWindow::rebuild_indices()
3721 for(int i = 0; i < session->drag_assets->total; i++)
3723 Indexable *indexable = session->drag_assets->get(i);
3724 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3725 remove_indexfile(indexable);
3726 // Schedule index build
3727 IndexState *index_state = indexable->index_state;
3728 index_state->index_status = INDEX_NOTTESTED;
3729 if( indexable->is_asset ) {
3730 Asset *asset = (Asset *)indexable;
3731 if( asset->format != FILE_PCM ) {
3732 asset->format = FILE_UNKNOWN;
3733 asset->reset_audio();
3735 asset->reset_video();
3736 remove_asset_from_caches(asset);
3737 // File file; // re-probe the asset
3738 // file.open_file(preferences, asset, 1, 0);
3740 mainindexes->add_next_asset(0, indexable);
3742 mainindexes->start_build();
3746 void MWindow::save_backup()
3750 edl->set_path(session->filename);
3751 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3752 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3753 File::get_config_path(), BACKUP_FILE);
3754 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3755 File::get_config_path(), BACKUP_FILE1);
3756 rename(backup_path, backup_path1);
3757 edl->save_xml(&file, backup_path);
3758 file.terminate_string();
3760 fs.complete_path(backup_path);
3762 if(file.write_to_file(backup_path))
3765 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3766 gui->show_message(string2);
3770 void MWindow::load_backup()
3772 ArrayList<char*> path_list;
3773 path_list.set_array_delete();
3775 char backup_path[BCTEXTLEN];
3776 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3777 File::get_config_path(), BACKUP_FILE);
3779 fs.complete_path(backup_path);
3781 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3782 strcpy(out_path, backup_path);
3784 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3785 edl->local_session->clip_title[0] = 0;
3786 // This is unique to backups since the path of the backup is different than the
3787 // path of the project.
3788 set_filename(edl->path);
3789 path_list.remove_all_objects();
3794 void MWindow::save_undo_data()
3797 undo_after(_("perpetual session"), LOAD_ALL);
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,"w");
3807 void MWindow::load_undo_data()
3809 char perpetual_path[BCTEXTLEN];
3810 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3811 File::get_config_path(), PERPETUAL_FILE);
3812 FILE *fp = fopen(perpetual_path,"r");
3819 int MWindow::copy_target(const char *path, const char *target)
3821 int ifd = ::open(path, O_RDONLY);
3823 eprintf("Cannot open asset: %s", path);
3827 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
3830 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
3831 char progress_title[BCTEXTLEN];
3832 sprintf(progress_title, _("Copying: %s\n"), target);
3833 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
3835 int64_t count = 0, len = -1;
3836 int bfrsz = 0x100000;
3837 uint8_t *bfr = new uint8_t[bfrsz];
3838 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
3839 if( len != ::write(ofd, bfr, len) ) {
3840 eprintf("Error writing: %s", target);
3843 if( progress.is_cancelled() ) {
3847 progress.update(count += len, 1);
3852 progress.stop_progress();
3854 eprintf("Error reading: %s", path);
3859 eprintf("Cannot create asset target: %s", target);
3864 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
3866 char target[BCTEXTLEN];
3868 const char *bp = real_path, *cp = bp;
3869 const char *lp = link_path, *np = lp;
3870 char *tp = target, *ep = tp+sizeof(target)-1, lch;
3871 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
3872 if( lch == '/' ) { np = lp; cp = bp; }
3874 while( tp<ep && *np ) {
3875 if( *np++ != '/' ) continue;
3876 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
3878 while( tp<ep && *cp ) *tp++ = *cp++;
3882 strcpy(target, real_path);
3883 if( symlink(target, link_path) ) {
3884 eprintf("Cannot create symlink: %s", link_path);
3890 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
3892 char dir_path[BCTEXTLEN];
3893 strcpy(dir_path, dir);
3895 fs.complete_path(dir_path);
3898 if( !stat(dir_path, &st) ) {
3899 if( !S_ISDIR(st.st_mode) ) {
3900 eprintf("Path exists and is not a directory\n%s", dir_path);
3905 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
3906 eprintf("Cannot create directory\n%s", dir_path);
3910 char *real_dir = realpath(dir_path, 0);
3911 strcpy(dir_path, real_dir);
3914 EDL *save_edl = new EDL;
3915 save_edl->create_objects();
3916 save_edl->copy_all(edl);
3918 char progress_title[BCTEXTLEN];
3919 sprintf(progress_title, _("Saving to %s:\n"), dir);
3920 int total_assets = save_edl->assets->total();
3921 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
3923 Asset *current = save_edl->assets->first;
3924 for( int i=0; !ret && current; ++i, current=NEXT ) {
3925 char *path = current->path;
3926 if( ::stat(path, &st) ) {
3927 eprintf("Asset not found: %s", path);
3930 char *real_path = realpath(path, 0);
3931 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
3932 char link_path[BCTEXTLEN];
3933 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
3935 if( strcmp(real_path, link_path) ) {
3936 if( !::lstat(link_path, &st) ) {
3938 ::remove(link_path);
3944 eprintf("copy/link to self, skippped: %s", path);
3948 if( save_mode == SAVE_PROJECT_COPY ) {
3949 if( copy_target(real_path, link_path) )
3953 link_target(real_path, link_path,
3954 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
3958 strcpy(path, link_path);
3960 if( progress->is_cancelled() ) break;
3961 progress->update(i);
3964 progress->stop_progress();
3967 char *cp = strrchr(dir_path,'/');
3968 char *bp = cp ? cp+1 : dir_path;
3969 char filename[BCTEXTLEN];
3970 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
3971 save_edl->set_path(filename);
3973 save_edl->save_xml(&file, filename);
3974 file.terminate_string();
3976 if( !file.write_to_file(filename) ) {
3977 char string[BCTEXTLEN];
3978 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
3979 gui->lock_window("SaveProject::run 2");
3980 gui->show_message(string);
3981 gui->unlock_window();
3982 gui->mainmenu->add_load(filename);
3985 eprintf(_("Couldn't open %s."), filename);
3987 save_edl->remove_user();
3990 gui->lock_window("MWindow::save_project");
3991 ArrayList<char*> filenames;
3992 filenames.append(filename);
3993 load_filenames(&filenames, LOADMODE_REPLACE);
3994 gui->unlock_window();
3999 static inline int gcd(int m, int n)
4002 if( m < n ) { r = m; m = n; n = r; }
4003 while( (r = m % n) != 0 ) { m = n; n = r; }
4007 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4010 if(!width || !height) return 1;
4011 if( width == 720 && (height == 480 || height == 576) ) {
4012 w = 4; h = 3; return 0; // for NTSC and PAL
4014 double ar = (double)width / height;
4015 // square-ish pixels
4016 if( EQUIV(ar, 1.0000) ) return 0;
4017 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4018 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4019 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4020 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4021 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4022 int ww = width, hh = height;
4023 // numerator, denominator must be under mx
4024 int mx = 255, n = gcd(ww, hh);
4025 if( n > 1 ) { ww /= n; hh /= n; }
4026 // search near height in case extra/missing lines
4027 if( ww >= mx || hh >= mx ) {
4028 double err = height; // +/- 2 percent height
4029 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4030 int iw = width, ih = height+i;
4031 if( (n=gcd(iw, ih)) > 1 ) {
4032 int u = iw/n; if( u >= mx ) continue;
4033 int v = ih/n; if( v >= mx ) continue;
4034 double r = (double) u/v, er = fabs(ar-r);
4035 if( er >= err ) continue;
4036 err = er; ww = u; hh = v;
4045 void MWindow::reset_caches()
4047 frame_cache->remove_all();
4048 wave_cache->remove_all();
4049 audio_cache->remove_all();
4050 video_cache->remove_all();
4051 if( cwindow->playback_engine ) {
4052 if( cwindow->playback_engine->audio_cache )
4053 cwindow->playback_engine->audio_cache->remove_all();
4054 if( cwindow->playback_engine->video_cache )
4055 cwindow->playback_engine->video_cache->remove_all();
4057 for(int i = 0; i < vwindows.size(); i++) {
4058 VWindow *vwindow = vwindows[i];
4059 if( !vwindow->is_running() ) continue;
4060 if( !vwindow->playback_engine ) continue;
4061 if( vwindow->playback_engine->audio_cache )
4062 vwindow->playback_engine->audio_cache->remove_all();
4063 if( vwindow->playback_engine->video_cache )
4064 vwindow->playback_engine->video_cache->remove_all();
4068 void MWindow::remove_asset_from_caches(Asset *asset)
4070 frame_cache->remove_asset(asset);
4071 wave_cache->remove_asset(asset);
4072 audio_cache->delete_entry(asset);
4073 video_cache->delete_entry(asset);
4074 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4075 cwindow->playback_engine->audio_cache->delete_entry(asset);
4076 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4077 cwindow->playback_engine->video_cache->delete_entry(asset);
4078 for(int i = 0; i < vwindows.size(); i++) {
4079 VWindow *vwindow = vwindows[i];
4080 if( !vwindow->is_running() ) continue;
4081 if( !vwindow->playback_engine ) continue;
4082 if( vwindow->playback_engine->audio_cache )
4083 vwindow->playback_engine->audio_cache->delete_entry(asset);
4084 if( vwindow->playback_engine->video_cache )
4085 vwindow->playback_engine->video_cache->delete_entry(asset);
4090 void MWindow::remove_assets_from_project(int push_undo, int redraw,
4091 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4093 awindow->gui->close_view_popup();
4095 for(int i = 0; i < drag_assets->total; i++) {
4096 Indexable *indexable = drag_assets->get(i);
4097 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
4100 // Remove from VWindow.
4101 for(int i = 0; i < session->drag_clips->total; i++) {
4102 for(int j = 0; j < vwindows.size(); j++) {
4103 VWindow *vwindow = vwindows[j];
4104 if( !vwindow->is_running() ) continue;
4105 if(session->drag_clips->get(i) == vwindow->get_edl()) {
4106 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4107 vwindow->delete_source(1, 1);
4108 vwindow->gui->unlock_window();
4113 for(int i = 0; i < drag_assets->size(); i++) {
4114 for(int j = 0; j < vwindows.size(); j++) {
4115 VWindow *vwindow = vwindows[j];
4116 if( !vwindow->is_running() ) continue;
4117 if(drag_assets->get(i) == vwindow->get_source()) {
4118 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4119 vwindow->delete_source(1, 1);
4120 vwindow->gui->unlock_window();
4125 for(int i = 0; i < drag_assets->size(); i++) {
4126 Indexable *indexable = drag_assets->get(i);
4127 remove_indexfile(indexable);
4130 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4131 if(push_undo) undo_before();
4132 if(drag_assets) edl->remove_from_project(drag_assets);
4133 if(drag_clips) edl->remove_from_project(drag_clips);
4134 if(redraw) save_backup();
4135 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4139 gui->lock_window("MWindow::remove_assets_from_project 3");
4140 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4141 gui->unlock_window();
4143 // Removes from playback here
4144 sync_parameters(CHANGE_ALL);
4147 awindow->gui->async_update_assets();
4150 void MWindow::remove_assets_from_disk()
4152 remove_assets_from_project(1,
4154 session->drag_assets,
4155 session->drag_clips);
4158 for(int i = 0; i < session->drag_assets->total; i++)
4160 remove(session->drag_assets->get(i)->path);
4164 void MWindow::dump_plugins(FILE *fp)
4166 if( !plugindb ) return;
4167 for(int i = 0; i < plugindb->total; i++)
4169 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4170 " synth=%d transition=%d theme=%d %s\n",
4171 plugindb->get(i)->plugin_type,
4172 plugindb->get(i)->audio,
4173 plugindb->get(i)->video,
4174 plugindb->get(i)->realtime,
4175 plugindb->get(i)->multichannel,
4176 plugindb->get(i)->get_synthesis(),
4177 plugindb->get(i)->transition,
4178 plugindb->get(i)->theme,
4179 plugindb->get(i)->title);
4183 void MWindow::dump_edl(FILE *fp)
4189 void MWindow::dump_undo(FILE *fp)
4195 void MWindow::dump_exe(FILE *fp)
4197 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4198 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4200 int ret = -1, n = 100;
4201 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4202 exe_path[len] = 0; strcpy(proc_path, exe_path);
4205 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4208 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4209 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4210 struct tm *tm = localtime(&st.st_mtime);
4212 strftime(mtime, sizeof(mtime), "%F %T", tm);
4213 fprintf(fp,"mtime: %s\n", mtime);
4215 // people hit ctl-c waiting for this
4216 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4217 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4220 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4221 int64_t maxsz = 1024*pagsz;
4222 int64_t size = st.st_size, pos = 0;
4224 while( (bfrsz = size-pos) > 0 ) {
4225 if( bfrsz > maxsz ) bfrsz = maxsz;
4226 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4227 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4228 if( bfr == MAP_FAILED ) break;
4229 sha1.addBytes(bfr, bfrsz);
4234 ret = pos < size ? EIO : 0;
4235 fprintf(fp, "SHA1: ");
4236 uint8_t digest[20]; sha1.computeHash(digest);
4237 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4238 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4239 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4244 void MWindow::trap_hook(FILE *fp, void *vp)
4246 MWindow *mwindow = (MWindow *)vp;
4247 // fprintf(fp, "\nPLUGINS:\n");
4248 // mwindow->dump_plugins(fp);
4249 fprintf(fp, "\nEDL:\n");
4250 mwindow->dump_edl(fp);
4251 fprintf(fp, "\nUNDO:\n");
4252 mwindow->dump_undo(fp);
4253 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4254 mwindow->dump_exe(fp);
4262 int MWindow::save_defaults()
4264 gui->save_defaults(defaults);
4265 edl->save_defaults(defaults);
4266 session->save_defaults(defaults);
4267 preferences->save_defaults(defaults);
4269 for(int i = 0; i < plugin_guis->total; i++)
4271 // Pointer comparison
4272 plugin_guis->get(i)->save_defaults();
4274 awindow->save_defaults(defaults);
4280 int MWindow::run_script(FileXML *script)
4282 int result = 0, result2 = 0;
4283 while(!result && !result2)
4285 result = script->read_tag();
4288 if(script->tag.title_is("new_project"))
4290 // Run new in immediate mode.
4291 // gui->mainmenu->new_project->run_script(script);
4294 if(script->tag.title_is("record"))
4296 // Run record as a thread. It is a terminal command.
4298 // Will read the complete scipt file without letting record read it if not
4304 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4311 // ================================= synchronization
4314 int MWindow::interrupt_indexes()
4316 mainprogress->cancelled = 1;
4317 mainindexes->interrupt_build();
4323 void MWindow::next_time_format()
4325 switch(edl->session->time_format)
4327 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4328 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4329 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4330 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4331 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4332 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4333 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4336 time_format_common();
4339 void MWindow::prev_time_format()
4341 switch(edl->session->time_format)
4343 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4344 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4345 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4346 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4347 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4348 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4349 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4352 time_format_common();
4355 void MWindow::time_format_common()
4357 gui->lock_window("MWindow::next_time_format");
4358 gui->redraw_time_dependancies();
4361 char string[BCTEXTLEN], string2[BCTEXTLEN];
4362 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4363 gui->show_message(string);
4365 gui->unlock_window();
4369 int MWindow::set_filename(const char *filename)
4371 if( filename != session->filename )
4372 strcpy(session->filename, filename);
4373 if( filename != edl->path )
4374 strcpy(edl->path, filename);
4378 if(filename[0] == 0)
4380 gui->set_title(PROGRAM_NAME);
4385 char string[BCTEXTLEN], string2[BCTEXTLEN];
4386 dir.extract_name(string, filename);
4387 sprintf(string2, PROGRAM_NAME ": %s", string);
4388 gui->set_title(string2);
4401 int MWindow::set_loop_boundaries()
4403 double start = edl->local_session->get_selectionstart();
4404 double end = edl->local_session->get_selectionend();
4412 if(edl->tracks->total_length())
4415 end = edl->tracks->total_length();
4422 if(edl->local_session->loop_playback && start != end)
4424 edl->local_session->loop_start = start;
4425 edl->local_session->loop_end = end;
4436 int MWindow::reset_meters()
4438 cwindow->gui->lock_window("MWindow::reset_meters 1");
4439 cwindow->gui->meters->reset_meters();
4440 cwindow->gui->unlock_window();
4442 for(int j = 0; j < vwindows.size(); j++) {
4443 VWindow *vwindow = vwindows[j];
4444 if( !vwindow->is_running() ) continue;
4445 vwindow->gui->lock_window("MWindow::reset_meters 2");
4446 vwindow->gui->meters->reset_meters();
4447 vwindow->gui->unlock_window();
4450 lwindow->gui->lock_window("MWindow::reset_meters 3");
4451 lwindow->gui->panel->reset_meters();
4452 lwindow->gui->unlock_window();
4454 gui->lock_window("MWindow::reset_meters 4");
4455 gui->reset_meters();
4456 gui->unlock_window();
4461 void MWindow::resync_guis()
4465 gui->lock_window("MWindow::resync_guis");
4466 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4467 gui->unlock_window();
4469 cwindow->gui->lock_window("MWindow::resync_guis");
4470 cwindow->gui->resize_event(cwindow->gui->get_w(),
4471 cwindow->gui->get_h());
4472 int channels = edl->session->audio_channels;
4473 cwindow->gui->meters->set_meters(channels, 1);
4474 cwindow->gui->flush();
4475 cwindow->gui->unlock_window();
4477 for(int i = 0; i < vwindows.size(); i++) {
4478 VWindow *vwindow = vwindows[i];
4479 if( !vwindow->is_running() ) continue;
4480 vwindow->gui->lock_window("MWindow::resync_guis");
4481 vwindow->gui->resize_event(vwindow->gui->get_w(),
4482 vwindow->gui->get_h());
4483 vwindow->gui->meters->set_meters(channels, 1);
4484 vwindow->gui->flush();
4485 vwindow->gui->unlock_window();
4488 lwindow->gui->lock_window("MWindow::resync_guis");
4489 lwindow->gui->panel->set_meters(channels, 1);
4490 lwindow->gui->flush();
4491 lwindow->gui->unlock_window();
4494 if(((edl->session->output_w % 4) ||
4495 (edl->session->output_h % 4)) &&
4496 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4498 MainError::show_error(
4499 _("This project's dimensions are not multiples of 4 so\n"
4500 "it can't be rendered by OpenGL."));
4505 sync_parameters(CHANGE_ALL);
4508 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4510 File *file = new File;
4511 EDLSession *session = edl->session;
4512 double old_framerate = session->frame_rate;
4513 double old_samplerate = session->sample_rate;
4514 int old_auto_keyframes = session->auto_keyframes;
4515 session->auto_keyframes = 0;
4516 int result = file->open_file(preferences, asset, 1, 0);
4517 if( !result && delete_tracks > 0 )
4519 int video_layers = asset->get_video_layers();
4520 if( !result && asset->video_data && vstream < video_layers ) {
4521 // try to get asset up to date, may fail
4522 file->select_video_stream(asset, vstream);
4523 // either way use what was/is there.
4524 double framerate = asset->get_frame_rate();
4525 int width = asset->get_w();
4526 int height = asset->get_h();
4527 // must be multiple of 4 for opengl
4528 width = (width+3) & ~3; height = (height+3) & ~3;
4529 int driver = session->playback_config->vconfig->driver;
4530 int color_model = file->get_best_colormodel(asset, driver);
4531 // color_model = BC_CModels::is_yuv(color_model) ?
4532 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4533 // BC_CModels::is_float(color_model) ?
4534 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4535 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4536 // have alpha for now
4537 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4538 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4539 session->color_model = color_model;
4540 session->output_w = width;
4541 session->output_h = height;
4542 session->frame_rate = framerate;
4543 // not, asset->actual_width/actual_height
4544 asset->width = session->output_w;
4545 asset->height = session->output_h;
4546 asset->frame_rate = session->frame_rate;
4547 create_aspect_ratio(session->aspect_w, session->aspect_h,
4548 session->output_w, session->output_h);
4549 Track *track = edl->tracks->first;
4550 for( Track *next_track=0; track; track=next_track ) {
4551 next_track = track->next;
4552 if( track->data_type != TRACK_VIDEO ) continue;
4553 if( delete_tracks ) {
4554 Edit *edit = track->edits->first;
4555 for( Edit *next_edit=0; edit; edit=next_edit ) {
4556 next_edit = edit->next;
4557 if( edit->channel != vstream ||
4558 !edit->asset || !edit->asset->is_asset ||
4559 !asset->equivalent(*edit->asset,1,1,edl) )
4563 if( track->edits->first ) {
4564 track->track_w = edl->session->output_w;
4565 track->track_h = edl->session->output_h;
4567 else if( delete_tracks )
4568 edl->tracks->delete_track(track);
4571 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4573 if( !result && asset->audio_data && asset->channels > 0 ) {
4574 session->sample_rate = asset->get_sample_rate();
4575 int64_t channel_mask = 0;
4576 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4577 file->get_audio_for_video(vstream, astream, channel_mask);
4578 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4579 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4581 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4582 if( channels < 1 ) channels = 1;
4583 if( channels > 6 ) channels = 6;
4584 session->audio_tracks = session->audio_channels = channels;
4586 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4587 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4588 remap_audio(MWindow::AUDIO_1_TO_1);
4590 if( delete_tracks ) {
4591 Track *track = edl->tracks->first;
4592 for( Track *next_track=0; track; track=next_track ) {
4593 next_track = track->next;
4594 if( track->data_type != TRACK_AUDIO ) continue;
4595 Edit *edit = track->edits->first;
4596 for( Edit *next_edit=0; edit; edit=next_edit ) {
4597 next_edit = edit->next;
4598 if( !((1<<edit->channel) & channel_mask) ||
4599 !edit->asset || !edit->asset->is_asset ||
4600 !asset->equivalent(*edit->asset,1,1,edl) )
4603 if( !track->edits->first )
4604 edl->tracks->delete_track(track);
4608 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4611 session->auto_keyframes = old_auto_keyframes;
4612 if( !result && delete_tracks > 0 ) {
4614 undo_after(_("select asset"), LOAD_ALL);
4620 int MWindow::select_asset(int vtrack, int delete_tracks)
4622 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4624 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4625 if( !track ) return 1;
4626 Edit *edit = track->edits->first;
4627 if( !edit ) return 1;
4628 Asset *asset = edit->asset;
4629 if( !asset || !asset->is_asset ) return 1;
4630 return select_asset(asset, edit->channel, 0, delete_tracks);
4633 void MWindow::dump_plugindb(FILE *fp)
4635 if( !plugindb ) return;
4636 for(int i = 0; i < plugindb->total; i++)
4637 plugindb->get(i)->dump(fp);
4640 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4643 double unit_position = edl->local_session->get_selectionstart(1);
4644 unit_position = patch->track->to_units(unit_position, 0);
4646 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4647 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4650 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4653 double unit_position = edl->local_session->get_selectionstart(1);
4654 unit_position = patch->track->to_units(unit_position, 0);
4656 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4657 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4660 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4663 double unit_position = edl->local_session->get_selectionstart(1);
4664 unit_position = patch->track->to_units(unit_position, 0);
4666 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4667 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4670 PatchGUI *MWindow::get_patchgui(Track *track)
4672 PatchGUI *patchgui = 0;
4673 TimelinePane **panes = gui->pane;
4674 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4675 if( !panes[i] ) continue;
4676 PatchBay *patchbay = panes[i]->patchbay;
4677 if( !patchbay ) continue;
4678 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4679 if( patchbay->patches.values[j]->track == track )
4680 patchgui = patchbay->patches.values[j];