3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "aboutprefs.h"
25 #include "audioalsa.h"
27 #include "awindowgui.h"
29 #include "batchrender.h"
30 #include "bcdisplayinfo.h"
31 #include "bcprogressbox.h"
32 #include "bcsignals.h"
39 #include "channeldb.h"
40 #include "channelinfo.h"
43 #include "bccmodels.h"
44 #include "commercials.h"
45 #include "confirmsave.h"
46 #include "cplayback.h"
48 #include "cwindowgui.h"
50 #include "cwindowtool.h"
52 #include "devicedvbinput.inc"
53 #include "dvdcreate.h"
54 #include "editpanel.h"
56 #include "edlsession.h"
58 #include "fileformat.h"
60 #include "filesystem.h"
62 #include "floatautos.h"
63 #include "framecache.h"
65 #include "gwindowgui.h"
66 #include "keyframegui.h"
67 #include "indexfile.h"
69 #include "interlacemodes.h"
71 #include "levelwindowgui.h"
72 #include "levelwindow.h"
73 #include "loadfile.inc"
74 #include "localsession.h"
75 #include "maincursor.h"
76 #include "mainerror.h"
77 #include "mainindexes.h"
79 #include "mainprogress.h"
80 #include "mainsession.h"
84 #include "mwindowgui.h"
89 #include "playback3d.h"
90 #include "playbackengine.h"
92 #include "pluginserver.h"
93 #include "pluginset.h"
94 #include "preferences.h"
97 #include "recordmonitor.h"
98 #include "recordlabel.h"
99 #include "removefile.h"
101 #include "resourcethread.h"
102 #include "savefile.inc"
103 #include "samplescroll.h"
106 #include "sighandler.h"
107 #include "splashgui.h"
108 #include "statusbar.h"
110 #include "threadloader.h"
112 #include "timelinepane.h"
113 #include "tipwindow.h"
114 #include "trackcanvas.h"
116 #include "tracking.h"
117 #include "trackscroll.h"
119 #include "transition.h"
120 #include "transportque.h"
123 #include "versioninfo.h"
125 #include "videodevice.inc"
126 #include "videowindow.h"
127 #include "vplayback.h"
128 #include "vwindowgui.h"
130 #include "wavecache.h"
134 #include "zwindowgui.h"
135 #include "exportedl.h"
137 #include "defaultformats.h"
138 #include "ntsczones.h"
145 #include <sys/types.h>
146 #include <sys/stat.h>
147 #include <sys/time.h>
148 #include <sys/mman.h>
149 #include <sys/file.h>
160 // Hack for libdv to remove glib dependancy
163 // g_log (const char *log_domain,
165 // const char *format,
171 // g_logv (const char *log_domain,
173 // const char *format,
182 extern long cin_timezone;
184 ArrayList<PluginServer*>* MWindow::plugindb = 0;
185 Commercials* MWindow::commercials = 0;
191 run_lock = new Mutex("MWindow::run_lock");
192 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
193 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
194 vwindows_lock = new Mutex("MWindow::vwindows_lock");
195 zwindows_lock = new Mutex("MWindow::zwindows_lock");
196 brender_lock = new Mutex("MWindow::brender_lock");
197 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
202 undo_command = COMMAND_NONE;
206 commercial_active = 0;
218 strcpy(cin_lang,"en");
219 channeldb_buz = new ChannelDB;
220 channeldb_v4l2jpeg = new ChannelDB;
223 keyframe_threads = 0;
246 // Need to delete brender temporary here.
249 run_lock->lock("MWindow::~MWindow");
251 //printf("MWindow::~MWindow %d\n", __LINE__);
252 gui->remote_control->deactivate();
255 gui->channel_info->stop();
258 delete create_bd; create_bd = 0;
259 delete create_dvd; create_dvd = 0;
260 delete shuttle; shuttle = 0;
261 delete batch_render; batch_render = 0;
262 delete render; render = 0;
264 if( commercials && !commercials->remove_user() ) commercials = 0;
266 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
267 // Save defaults for open plugins
268 plugin_gui_lock->lock("MWindow::~MWindow");
269 for(int i = 0; i < plugin_guis->size(); i++) {
270 plugin_guis->get(i)->hide_gui();
271 delete_plugin(plugin_guis->get(i));
273 plugin_gui_lock->unlock();
274 hide_keyframe_guis();
277 // Give up and go to a movie
278 // cant run valgrind if this is used
280 gui->del_keyboard_listener(
281 (int (BC_WindowBase::*)(BC_WindowBase *))
282 &MWindowGUI::keyboard_listener);
284 // release the hounds
285 if( awindow && awindow->gui ) awindow->gui->close(0);
286 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
287 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
288 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
289 if( twindow && twindow->is_running() ) twindow->close_window();
290 if( wwindow && wwindow->is_running() ) wwindow->close_window();
291 vwindows.remove_all_objects();
292 zwindows.remove_all_objects();
294 if( awindow ) awindow->join();
295 if( cwindow ) cwindow->join();
296 if( lwindow ) lwindow->join();
297 if( twindow ) twindow->join();
298 if( wwindow ) wwindow->join();
299 if( gwindow ) gwindow->join();
302 // one at a time, or nouveau chokes
303 #define close_gui(win) if( win ) { \
304 if( win->gui ) win->gui->close(0); \
312 vwindows.remove_all_objects();
313 zwindows.remove_all_objects();
318 dead_plugins->remove_all_objects();
319 // must delete theme before destroying plugindb
320 // theme destructor will be deleted by delete_plugins
321 delete theme; theme = 0;
324 keyframe_threads->remove_all_objects();
325 colormodels.remove_all_objects();
326 delete awindow; awindow = 0;
327 delete lwindow; lwindow = 0;
328 delete twindow; twindow = 0;
329 delete wwindow; wwindow = 0;
330 delete gwindow; gwindow = 0;
331 delete cwindow; cwindow = 0;
333 delete mainindexes; mainindexes = 0;
334 delete mainprogress; mainprogress = 0;
335 delete audio_cache; audio_cache = 0; // delete the cache after the assets
336 delete video_cache; video_cache = 0; // delete the cache after the assets
337 delete frame_cache; frame_cache = 0;
338 delete wave_cache; wave_cache = 0;
339 delete plugin_guis; plugin_guis = 0;
340 delete dead_plugins; dead_plugins = 0;
341 delete keyframe_threads; keyframe_threads = 0;
342 delete undo; undo = 0;
343 delete preferences; preferences = 0;
344 delete exportedl; exportedl = 0;
345 delete session; session = 0;
346 delete defaults; defaults = 0;
347 delete assets; assets = 0;
348 delete splash_window; splash_window = 0;
349 if( !edl->Garbage::remove_user() ) edl = 0;
350 delete channeldb_buz;
351 delete channeldb_v4l2jpeg;
352 // This must be last thread to exit
353 delete playback_3d; playback_3d = 0;
354 delete dead_plugin_lock;
355 delete plugin_gui_lock;
356 delete vwindows_lock;
357 delete zwindows_lock;
359 delete keyframe_gui_lock;
360 colormodels.remove_all_objects();
361 interlace_project_modes.remove_all_objects();
362 interlace_asset_modes.remove_all_objects();
363 interlace_asset_fixmethods.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 const char *lv2_path = getenv("LV2_PATH");
942 if( lv2_path && strcmp(lv2_path, preferences->lv2_path) ) {
943 strncpy(preferences->lv2_path, lv2_path, sizeof(preferences->lv2_path));
944 remove_plugin_index();
946 else if( !lv2_path && preferences->lv2_path[0] ) {
947 File::setenv_path("LV2_PATH",preferences->lv2_path, 0);
949 session = new MainSession(this);
950 session->load_defaults(defaults);
951 // set x11_host, screens, window_config
952 screens = session->set_default_x11_host();
953 BC_Signals::set_trap_hook(trap_hook, this);
954 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
955 BC_Signals::set_catch_intr(preferences->trap_sigintr);
956 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
957 BC_Trace::enable_locks();
960 BC_Trace::disable_locks();
962 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
963 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
964 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
965 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
968 void MWindow::clean_indexes()
973 int oldest_item = -1;
975 char string[BCTEXTLEN];
976 char string2[BCTEXTLEN];
978 // Delete extra indexes
979 fs.set_filter("*.idx");
980 fs.complete_path(preferences->index_directory);
981 fs.update(preferences->index_directory);
982 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
984 // Eliminate directories
989 for(int i = 0; i < fs.dir_list.total && !result; i++)
991 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
992 if(fs.is_dir(string))
994 delete fs.dir_list[i];
995 fs.dir_list.remove_number(i);
1000 total_excess = fs.dir_list.total - preferences->index_count;
1002 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
1003 while(total_excess > 0)
1006 for(int i = 0; i < fs.dir_list.total; i++)
1008 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1010 if(i == 0 || fs.get_date(string) <= oldest)
1012 oldest = fs.get_date(string);
1017 if(oldest_item >= 0)
1019 // Remove index file
1020 fs.join_names(string,
1021 preferences->index_directory,
1022 fs.dir_list[oldest_item]->name);
1023 //printf("MWindow::clean_indexes 1 %s\n", string);
1025 perror("delete_indexes");
1026 delete fs.dir_list[oldest_item];
1027 fs.dir_list.remove_number(oldest_item);
1029 // Remove table of contents if it exists
1030 strcpy(string2, string);
1031 char *ptr = strrchr(string2, '.');
1034 //printf("MWindow::clean_indexes 2 %s\n", string2);
1035 sprintf(ptr, ".toc");
1037 sprintf(ptr, ".mkr");
1046 void MWindow::init_awindow()
1048 awindow = new AWindow(this);
1049 awindow->create_objects();
1052 void MWindow::init_gwindow()
1054 gwindow = new GWindow(this);
1055 gwindow->create_objects();
1058 void MWindow::init_tipwindow()
1060 TipWindow::load_tips(cin_lang);
1062 twindow = new TipWindow(this);
1066 void MWindow::show_warning(int *do_warning, const char *text)
1068 if( do_warning && !*do_warning ) return;
1070 wwindow = new WWindow(this);
1071 wwindow->show_warning(do_warning, text);
1074 int MWindow::wait_warning()
1076 return wwindow->wait_result();
1079 void MWindow::init_theme()
1084 PluginServer *theme_plugin = 0;
1085 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1086 if( plugindb->get(i)->theme &&
1087 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1088 theme_plugin = plugindb->get(i);
1092 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1093 preferences->theme);
1095 const char *default_theme = DEFAULT_THEME;
1096 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1097 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1099 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1100 if( plugindb->get(i)->theme &&
1101 !strcasecmp(default_theme, plugindb->get(i)->title) )
1102 theme_plugin = plugindb->get(i);
1107 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1111 PluginServer *plugin = new PluginServer(*theme_plugin);
1112 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1113 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1114 theme_plugin->title);
1118 theme = plugin->new_theme();
1119 theme->mwindow = this;
1120 strcpy(theme->path, plugin->path);
1123 // Load default images & settings
1124 theme->Theme::initialize();
1125 // Load user images & settings
1126 theme->initialize();
1127 // Create menus with user colors
1128 theme->build_menus();
1131 theme->sort_image_sets();
1132 theme->check_used();
1133 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1136 void MWindow::init_3d()
1138 playback_3d = new Playback3D(this);
1139 playback_3d->create_objects();
1142 void MWindow::init_edl()
1145 edl->create_objects();
1146 fill_preset_defaults(default_standard, edl->session);
1147 edl->load_defaults(defaults);
1148 edl->session->brender_start = edl->session->brender_end = 0;
1149 edl->create_default_tracks();
1150 edl->tracks->update_y_pixels(theme);
1153 void MWindow::init_compositor()
1155 cwindow = new CWindow(this);
1156 cwindow->create_objects();
1159 void MWindow::init_levelwindow()
1161 lwindow = new LevelWindow(this);
1162 lwindow->create_objects();
1165 VWindow *MWindow::get_viewer(int start_it, int idx)
1167 vwindows_lock->lock("MWindow::get_viewer");
1168 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1169 if( !vwindow ) idx = vwindows.size();
1170 while( !vwindow && --idx >= 0 ) {
1171 VWindow *vwin = vwindows[idx];
1172 if( !vwin->is_running() || !vwin->get_edl() )
1176 vwindow = new VWindow(this);
1177 vwindow->load_defaults();
1178 vwindow->create_objects();
1179 vwindows.append(vwindow);
1181 vwindows_lock->unlock();
1182 if( start_it ) vwindow->start();
1186 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1188 zwindows_lock->lock("MWindow::get_mixer");
1189 if( !mixer ) mixer = edl->mixers.new_mixer();
1190 ZWindow *zwindow = 0;
1191 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1192 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1194 zwindows.append(zwindow = new ZWindow(this));
1195 zwindow->idx = mixer->idx;
1196 zwindows_lock->unlock();
1200 void MWindow::del_mixer(ZWindow *zwindow)
1202 zwindows_lock->lock("MWindow::del_mixer 0");
1203 edl->mixers.del_mixer(zwindow->idx);
1204 if( session->selected_zwindow >= 0 ) {
1205 int i = zwindows.number_of(zwindow);
1206 if( i >= 0 && i < session->selected_zwindow )
1207 --session->selected_zwindow;
1208 else if( i == session->selected_zwindow )
1209 session->selected_zwindow = -1;
1211 zwindows_lock->unlock();
1212 gui->lock_window("MWindow::del_mixer 1");
1213 gui->update_mixers(0, -1);
1214 gui->unlock_window();
1217 void MWindow::start_mixer()
1220 ZWindow *zwindow = get_mixer(mixer);
1221 const char *title = 0;
1223 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1224 PatchGUI *patchgui = get_patchgui(track);
1225 if( !patchgui || !patchgui->mixer ) continue;
1226 mixer->mixer_ids.append(track->get_mixer_id());
1227 if( !title ) title = track->title;
1230 session->selected_zwindow = -1;
1231 gui->lock_window("MWindow::start_mixer");
1232 gui->update_mixers(0, 0);
1233 gui->unlock_window();
1235 zwindow->set_title(title);
1240 int MWindow::mixer_track_active(Track *track)
1242 int i = session->selected_zwindow;
1243 if( i < 0 || i >= zwindows.size() ) return 0;
1244 ZWindow *zwindow = zwindows[i];
1245 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1246 if( !mixer ) return 0;
1247 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1248 return n >= 0 ? 1 : 0;
1251 void MWindow::update_mixer_tracks()
1253 zwindows_lock->lock("MixPatch::handle_event");
1254 int i = session->selected_zwindow;
1255 if( i >= 0 && i < zwindows.size() ) {
1256 ZWindow *zwindow = zwindows[i];
1257 zwindow->update_mixer_ids();
1259 zwindows_lock->unlock();
1262 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1263 int use_inout, int update_refresh, int toggle_audio, int loop_play)
1265 zwindows_lock->lock("MWindow::queue_mixers");
1266 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1267 ZWindow *zwindow = zwindows[vidx];
1268 if( zwindow->idx < 0 ) continue;
1269 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1270 if( !mixer || !mixer->mixer_ids.size() ) continue;
1272 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1273 if( track->data_type != TRACK_VIDEO ) continue;
1274 int mixer_id = track->get_mixer_id();
1275 k = mixer->mixer_ids.size();
1276 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1278 if( k < 0 ) continue;
1279 EDL *mixer_edl = new EDL(this->edl);
1280 mixer_edl->create_objects();
1281 mixer_edl->copy_all(edl);
1282 mixer_edl->remove_vwindow_edls();
1283 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1284 k = mixer->mixer_ids.size();
1285 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1288 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1291 track->record = track->play = 0;
1293 zwindow->change_source(mixer_edl);
1294 zwindow->issue_command(command,
1295 wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
1297 zwindows_lock->unlock();
1300 void MWindow::refresh_mixers(int dir)
1302 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1303 queue_mixers(edl,command,0,0,1,0,0);
1306 void MWindow::stop_mixers()
1308 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1309 ZWindow *zwindow = zwindows[vidx];
1310 if( zwindow->idx < 0 ) continue;
1311 zwindow->issue_command(STOP, 0, 0, 0, 0, 0);
1315 void MWindow::close_mixers(int destroy)
1317 ArrayList<ZWindow*> closed;
1318 zwindows_lock->lock("MWindow::close_mixers");
1319 for( int i=zwindows.size(); --i>=0; ) {
1320 ZWindow *zwindow = zwindows[i];
1321 if( zwindow->idx < 0 ) continue;
1322 zwindow->destroy = destroy;
1323 ZWindowGUI *zgui = zwindow->zgui;
1324 zgui->lock_window("MWindow::select_zwindow 0");
1326 zgui->unlock_window();
1327 closed.append(zwindow);
1329 zwindows_lock->unlock();
1330 for( int i=0; i<closed.size(); ++i ) {
1331 ZWindow *zwindow = closed[i];
1336 ZWindow *MWindow::create_mixer(Indexable *indexable)
1338 ArrayList<Indexable*> new_assets;
1339 new_assets.append(indexable);
1340 Track *track = edl->tracks->last;
1341 load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
1342 track = !track ? edl->tracks->first : track->next;
1344 ZWindow *zwindow = get_mixer(mixer);
1346 track->play = track->record = 0;
1347 if( track->data_type == TRACK_VIDEO ) {
1348 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1350 mixer->mixer_ids.append(track->get_mixer_id());
1351 track = track->next;
1353 if( indexable->is_asset ) {
1354 char *path = indexable->path;
1355 char *tp = strrchr(path, '/');
1356 if( !tp ) tp = path; else ++tp;
1357 zwindow->set_title(tp);
1360 char *title = ((EDL*)indexable)->local_session->clip_title;
1361 zwindow->set_title(title);
1366 void MWindow::create_mixers()
1368 if( !session->drag_assets->size() &&
1369 !session->drag_clips->size() ) return;
1373 ArrayList<ZWindow *>new_mixers;
1375 for( int i=0; i<session->drag_assets->size(); ++i ) {
1376 Indexable *indexable = session->drag_assets->get(i);
1377 if( !indexable->have_video() ) continue;
1378 ZWindow *zwindow = create_mixer(indexable);
1379 new_mixers.append(zwindow);
1381 for( int i=0; i<session->drag_clips->size(); ++i ) {
1382 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1383 if( !indexable->have_video() ) continue;
1384 ZWindow *zwindow = create_mixer(indexable);
1385 new_mixers.append(zwindow);
1389 for( int i=0; i<new_mixers.size(); ++i )
1390 new_mixers[i]->start();
1394 undo_after(_("create mixers"), LOAD_ALL);
1396 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1397 sync_parameters(CHANGE_ALL);
1400 void MWindow::open_mixers()
1402 for( int i=0; i<edl->mixers.size(); ++i ) {
1403 Mixer *mixer = edl->mixers[i];
1404 ZWindow *zwindow = get_mixer(mixer);
1405 zwindow->set_title(mixer->title);
1411 int MWindow::select_zwindow(ZWindow *zwindow)
1413 int ret = 0, n = zwindows.number_of(zwindow);
1414 if( session->selected_zwindow != n ) {
1415 session->selected_zwindow = n;
1416 for( int i=0; i<zwindows.size(); ++i ) {
1417 ZWindow *zwindow = zwindows[i];
1418 if( zwindow->idx < 0 ) continue;
1419 ZWindowGUI *zgui = zwindow->zgui;
1420 zgui->lock_window("MWindow::select_zwindow 0");
1421 zwindow->highlighted = i == n ? 1 : 0;
1422 if( zgui->draw_overlays() )
1423 zgui->canvas->get_canvas()->flash(1);
1424 zgui->unlock_window();
1427 gui->lock_window("MWindow::select_window 1");
1428 gui->update_mixers(0, -1);
1429 gui->unlock_window();
1434 void MWindow::tile_mixers()
1437 for( int i=0; i<zwindows.size(); ++i ) {
1438 ZWindow *zwindow = zwindows[i];
1439 if( zwindow->idx < 0 ) continue;
1443 int zn = ceil(sqrt(nz));
1444 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1445 int y1 = 1, y2 = gui->get_y();
1446 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1447 if( x1 < 0 ) x1 = 0;
1448 if( y1 < 0 ) y1 = 0;
1449 if( x2 > rw ) x2 = rw;
1450 if( y2 > rh ) y2 = rh;
1451 int dx = x2 - x1, dy = y2 - y1;
1453 int lt = BC_DisplayInfo::get_left_border();
1454 int top = BC_DisplayInfo::get_top_border();
1455 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1456 int bh = top + BC_DisplayInfo::get_bottom_border();
1457 int zx = 0, zy = 0; // window origins
1458 int mw = 10+10, mh = 10+10; // canvas margins
1459 int rsz = 0, n = 0, dz = 0;
1460 int ow = edl->session->output_w, oh = edl->session->output_h;
1461 for( int i=0; i<zwindows.size(); ++i ) {
1462 ZWindow *zwindow = zwindows[i];
1463 if( zwindow->idx < 0 ) continue;
1464 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1465 if( rsz < hh ) rsz = hh;
1466 int xx = zx + x1, yy = zy + y1;
1467 int mx = x2 - zw, my = y2 - zh;
1468 if( xx > mx ) xx = mx;
1469 if( yy > my ) yy = my;
1470 xx += lt + dz; yy += top + dz;
1471 zwindow->reposition(xx,yy, ww,hh);
1472 if( zwindow->running() ) {
1473 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1474 gui->lock_window("MWindow::tile_mixers");
1475 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1476 gui->unlock_window();
1480 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1489 void MWindow::init_cache()
1491 audio_cache = new CICache(preferences);
1492 video_cache = new CICache(preferences);
1493 frame_cache = new FrameCache;
1494 wave_cache = new WaveCache;
1497 void MWindow::init_channeldb()
1499 channeldb_buz->load("channeldb_buz");
1500 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1503 void MWindow::init_menus()
1505 char string[BCTEXTLEN];
1508 BC_CModels::to_text(string, BC_RGB888);
1509 colormodels.append(new ColormodelItem(string, BC_RGB888));
1510 BC_CModels::to_text(string, BC_RGBA8888);
1511 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1512 // BC_CModels::to_text(string, BC_RGB161616);
1513 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1514 // BC_CModels::to_text(string, BC_RGBA16161616);
1515 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1516 BC_CModels::to_text(string, BC_RGB_FLOAT);
1517 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1518 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1519 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1520 BC_CModels::to_text(string, BC_YUV888);
1521 colormodels.append(new ColormodelItem(string, BC_YUV888));
1522 BC_CModels::to_text(string, BC_YUVA8888);
1523 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1524 // BC_CModels::to_text(string, BC_YUV161616);
1525 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1526 // BC_CModels::to_text(string, BC_YUVA16161616);
1527 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1529 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1530 interlace_project_modes.append(new InterlacemodeItem(string, x));
1532 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1533 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1535 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1536 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1538 // Interlacing Modes
1539 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1541 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1542 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1544 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1545 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1547 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1548 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1550 // Interlacing Fixing Methods
1551 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1552 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1553 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1556 void MWindow::init_indexes()
1558 mainindexes = new MainIndexes(this);
1559 mainindexes->start_loop();
1562 void MWindow::init_gui()
1564 gui = new MWindowGUI(this);
1565 gui->create_objects();
1566 gui->load_defaults(defaults);
1569 void MWindow::init_signals()
1571 sighandler = new SigHandler;
1572 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1576 void MWindow::init_render()
1578 render = new Render(this);
1579 create_bd = new CreateBD_Thread(this);
1580 create_dvd = new CreateDVD_Thread(this);
1581 batch_render = new BatchRenderThread(this);
1584 void MWindow::init_exportedl()
1586 exportedl = new ExportEDL(this);
1589 void MWindow::init_shuttle()
1592 const char *dev_name = Shuttle::probe();
1594 shuttle = new Shuttle(this);
1595 shuttle->start(dev_name);
1600 void MWindow::init_brender()
1602 if(preferences->use_brender && !brender)
1604 brender_lock->lock("MWindow::init_brender 1");
1605 brender = new BRender(this);
1606 brender->initialize();
1607 session->brender_end = 0;
1608 brender_lock->unlock();
1611 if(!preferences->use_brender && brender)
1613 brender_lock->lock("MWindow::init_brender 2");
1616 session->brender_end = 0;
1617 brender_lock->unlock();
1623 void MWindow::restart_brender()
1625 //printf("MWindow::restart_brender 1\n");
1626 if( !brender_active || !preferences->use_brender ) return;
1627 if( !brender ) return;
1628 brender->restart(edl);
1631 void MWindow::stop_brender()
1633 if( !brender ) return;
1634 // cannot be holding mwindow->gui display lock
1638 int MWindow::brender_available(int position)
1641 brender_lock->lock("MWindow::brender_available 1");
1642 if(brender && brender_active)
1644 if(brender->map_valid)
1646 brender->map_lock->lock("MWindow::brender_available 2");
1647 if(position < brender->map_size &&
1650 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1651 if(brender->map[position] == BRender::RENDERED)
1654 brender->map_lock->unlock();
1657 brender_lock->unlock();
1661 void MWindow::set_brender_active(int v, int update)
1663 if( !preferences->use_brender ) v = 0;
1665 gui->mainmenu->brender_active->set_checked(v);
1667 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1668 edl->session->brender_end = edl->local_session->get_selectionend(1);
1670 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1671 edl->session->brender_end = edl->tracks->total_video_length();
1676 edl->session->brender_start = edl->session->brender_end = 0;
1677 gui->unlock_window();
1679 gui->lock_window("MWindow::set_brender_active");
1682 gui->update_timebar(0);
1683 gui->draw_overlays(1);
1687 int MWindow::has_commercials()
1689 #ifdef HAVE_COMMERCIAL
1690 return theme->use_commercials;
1696 void MWindow::init_commercials()
1698 #ifdef HAVE_COMMERCIAL
1699 if( !commercials ) {
1700 commercials = new Commercials(this);
1701 commercial_active = 0;
1704 commercials->add_user();
1708 void MWindow::commit_commercial()
1710 #ifdef HAVE_COMMERCIAL
1711 if( !commercial_active ) return;
1712 commercial_active = 0;
1713 if( !commercials ) return;
1714 commercials->commitDb();
1718 void MWindow::undo_commercial()
1720 #ifdef HAVE_COMMERCIAL
1721 if( !commercial_active ) return;
1722 commercial_active = 0;
1723 if( !commercials ) return;
1724 commercials->undoDb();
1728 int MWindow::put_commercial()
1731 #ifdef HAVE_COMMERCIAL
1732 double start = edl->local_session->get_selectionstart();
1733 double end = edl->local_session->get_selectionend();
1734 if( start >= end ) return 0;
1736 const char *errmsg = 0;
1738 Tracks *tracks = edl->tracks;
1740 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1741 if( track->data_type != TRACK_VIDEO ) continue;
1742 if( !track->record ) continue;
1743 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1745 int64_t units_start = track->to_units(start,0);
1746 int64_t units_end = track->to_units(end,0);
1747 Edits *edits = track->edits;
1748 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1749 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1750 if(!edit1 && !edit2) continue; // nothing selected
1751 if(!edit2) { // edit2 beyond end of track
1752 edit2 = edits->last;
1753 units_end = edits->length();
1755 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1756 Indexable *indexable = edit1->get_source();
1757 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1760 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1761 if( track->data_type != TRACK_VIDEO ) continue;
1762 if( !track->record ) continue;
1763 int64_t units_start = track->to_units(start,0);
1764 int64_t units_end = track->to_units(end,0);
1765 Edits *edits = track->edits;
1766 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1767 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1768 if(!edit1 && !edit2) continue; // nothing selected
1769 if(!edit2) { // edit2 beyond end of track
1770 edit2 = edits->last;
1771 units_end = edits->length();
1773 Indexable *indexable = edit1->get_source();
1774 Asset *asset = (Asset *)indexable;
1775 File *file = video_cache->check_out(asset, edl);
1776 if( !file ) { errmsg = _("no file"); break; }
1777 int64_t edit_length = units_end - units_start;
1778 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1779 result = commercials->put_clip(file, edit1->channel,
1780 track->from_units(edit_start), track->from_units(edit_length));
1781 video_cache->check_in(asset);
1782 if( result ) { errmsg = _("db failed"); break; }
1785 char string[BCTEXTLEN];
1786 sprintf(string, _("put_commercial: %s"), errmsg);
1787 MainError::show_error(string);
1795 void MWindow::stop_playback(int wait)
1797 gui->stop_drawing();
1799 cwindow->stop_playback(wait);
1801 for(int i = 0; i < vwindows.size(); i++) {
1802 VWindow *vwindow = vwindows[i];
1803 if( !vwindow->is_running() ) continue;
1804 vwindow->stop_playback(wait);
1806 for(int i = 0; i < zwindows.size(); i++) {
1807 ZWindow *zwindow = zwindows[i];
1808 if( zwindow->idx < 0 ) continue;
1809 zwindow->stop_playback(wait);
1813 void MWindow::stop_transport()
1815 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1818 void MWindow::undo_before(const char *description, void *creator)
1820 if( cwindow->playback_engine->is_playing_back ) {
1821 undo_command = cwindow->playback_engine->command->command;
1822 cwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1823 gui->unlock_window();
1824 cwindow->playback_engine->interrupt_playback(1);
1825 gui->lock_window(description);
1827 undo->update_undo_before(description, creator);
1830 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
1832 if( undo_command != COMMAND_NONE ) {
1833 cwindow->playback_engine->que->send_command(undo_command, CHANGE_NONE, edl, 1, 0);
1834 undo_command = COMMAND_NONE;
1837 undo->update_undo_after(description, load_flags, changes_made);
1840 void MWindow::beep(double freq, double secs, double gain)
1842 if( !proxy_beep ) proxy_beep = new ProxyBeep(this);
1843 proxy_beep->tone(freq, secs, gain);
1846 int MWindow::load_filenames(ArrayList<char*> *filenames,
1848 int update_filename)
1850 ArrayList<EDL*> new_edls;
1851 ArrayList<Asset*> new_assets;
1852 ArrayList<File*> new_files;
1853 const int debug = 0;
1854 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1857 gui->start_hourglass();
1859 // Need to stop playback since tracking depends on the EDL not getting
1861 gui->unlock_window();
1863 gui->lock_window("MWindow::load_filenames 0");
1865 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1869 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1871 // Define new_edls and new_assets to load
1872 int result = 0, ftype = -1;
1874 for( int i=0; i<filenames->size(); ++i ) {
1876 File *new_file = new File;
1877 Asset *new_asset = new Asset(filenames->get(i));
1878 EDL *new_edl = new EDL;
1879 char string[BCTEXTLEN];
1881 new_edl->create_objects();
1882 new_edl->copy_session(edl, -1);
1883 new_file->set_program(edl->session->program_no);
1885 sprintf(string, _("Loading %s"), new_asset->path);
1886 gui->show_message(string);
1887 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1889 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1890 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1894 // Convert media file to EDL
1896 // Warn about odd image dimensions
1897 if( new_asset->video_data &&
1898 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1899 char string[BCTEXTLEN];
1900 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1901 new_asset->path, new_asset->width, new_asset->height);
1902 MainError::show_error(string);
1905 if( new_asset->program >= 0 &&
1906 edl->session->program_no != new_asset->program ) {
1907 char string[BCTEXTLEN];
1908 sprintf(string, _("%s's index was built for program number %d\n"
1909 "Playback preference is %d.\n Using program %d."),
1910 new_asset->path, new_asset->program,
1911 edl->session->program_no, new_asset->program);
1912 MainError::show_error(string);
1915 if( load_mode != LOADMODE_RESOURCESONLY ) {
1916 RecordLabels *labels = edl->session->label_cells ?
1917 new RecordLabels(new_file) : 0;
1918 asset_to_edl(new_edl, new_asset, labels);
1919 new_edls.append(new_edl);
1920 new_edl->add_user();
1924 new_assets.append(new_asset);
1925 new_asset->add_user();
1928 // Set filename to nothing for assets since save EDL would overwrite them.
1929 if( load_mode == LOADMODE_REPLACE ||
1930 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1932 // Reset timeline position
1933 for( int i=0; i<TOTAL_PANES; ++i ) {
1934 new_edl->local_session->view_start[i] = 0;
1935 new_edl->local_session->track_start[i] = 0;
1943 case FILE_NOT_FOUND:
1944 sprintf(string, _("Failed to open %s"), new_asset->path);
1945 gui->show_message(string, theme->message_error);
1946 gui->update_default_message();
1950 case FILE_UNRECOGNIZED_CODEC: {
1952 { IndexFile indexfile(this, new_asset);
1953 if( !(result = indexfile.open_index()) )
1954 indexfile.close_index(); }
1956 // Test existing EDLs
1957 for( int j=0; result && j<new_edls.total; ++j ) {
1958 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1960 new_asset->copy_from(old_asset,1);
1965 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1967 new_asset->copy_from(old_asset,1);
1974 char string[BCTEXTLEN];
1976 fs.extract_name(string, new_asset->path);
1978 strcat(string, _("'s format couldn't be determined."));
1979 new_asset->audio_data = 1;
1980 new_asset->format = FILE_PCM;
1981 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1982 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1983 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1984 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1985 new_asset->signed_ = defaults->get("SIGNED_", 1);
1986 new_asset->header = defaults->get("HEADER", 0);
1988 FileFormat fwindow(this);
1989 fwindow.create_objects(new_asset, string);
1990 result = fwindow.run_window();
1992 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1993 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1994 defaults->update("AUDIO_BITS", new_asset->bits);
1995 defaults->update("BYTE_ORDER", new_asset->byte_order);
1996 defaults->update("SIGNED_", new_asset->signed_);
1997 defaults->update("HEADER", new_asset->header);
2003 // Recalculate length
2005 new_file = new File;
2006 result = new_file->open_file(preferences, new_asset, 1, 0);
2008 if( load_mode != LOADMODE_RESOURCESONLY ) {
2009 RecordLabels *labels = edl->session->label_cells ?
2010 new RecordLabels(new_file) : 0;
2011 asset_to_edl(new_edl, new_asset, labels);
2012 new_edls.append(new_edl);
2013 new_edl->add_user();
2017 new_assets.append(new_asset);
2018 new_asset->add_user();
2028 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2029 xml_file.read_from_file(filenames->get(i));
2030 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2031 const char *cin_version = 0;
2032 while( !xml_file.read_tag() ) {
2033 if( xml_file.tag.title_is("EDL") ) {
2034 cin_version = xml_file.tag.get_property("VERSION");
2039 if( !cin_version ) {
2040 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
2041 char string[BCTEXTLEN];
2042 sprintf(string,_("Unknown %s"), filenames->get(i));
2043 gui->show_message(string);
2047 if( strcmp(cin_version, CINELERRA_VERSION) &&
2048 strcmp(cin_version, "Unify") &&
2049 strcmp(cin_version, "5.1") ) {
2050 char string[BCTEXTLEN];
2051 snprintf(string, sizeof(string),
2052 _("Warning: XML from cinelerra version %s\n"
2053 "Session data may be incompatible."), cin_version);
2054 show_warning(&preferences->warn_version, string);
2056 if( load_mode == LOADMODE_NESTED ) {
2057 // Load temporary EDL for nesting.
2058 EDL *nested_edl = new EDL;
2059 nested_edl->create_objects();
2060 nested_edl->load_xml(&xml_file, LOAD_ALL);
2061 int groups = nested_edl->regroup(session->group_number);
2062 session->group_number += groups;
2063 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
2064 new_edl->create_nested(nested_edl);
2065 new_edl->set_path(filenames->get(i));
2066 nested_edl->Garbage::remove_user();
2069 // Load EDL for pasting
2070 new_edl->load_xml(&xml_file, LOAD_ALL);
2071 int groups = new_edl->regroup(session->group_number);
2072 session->group_number += groups;
2073 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2074 test_plugins(new_edl, filenames->get(i));
2075 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2077 if( load_mode == LOADMODE_REPLACE ||
2078 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2079 strcpy(session->filename, filenames->get(i));
2080 strcpy(new_edl->local_session->clip_title,
2083 set_filename(new_edl->local_session->clip_title);
2085 else if( load_mode == LOADMODE_RESOURCESONLY ) {
2086 strcpy(new_edl->local_session->clip_title,
2089 time_t t = !stat(filenames->get(i),&st) ?
2090 st.st_mtime : time(&t);
2091 ctime_r(&t, new_edl->local_session->clip_notes);
2095 new_edls.append(new_edl);
2096 new_edl->add_user();
2101 new_edl->Garbage::remove_user();
2102 new_asset->Garbage::remove_user();
2104 // Store for testing index
2105 new_files.append(new_file);
2108 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2112 gui->reset_default_message();
2113 gui->default_message();
2117 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2120 // Don't back up here.
2123 // For pasting, clear the active region
2124 if(load_mode == LOADMODE_PASTE ||
2125 load_mode == LOADMODE_NESTED)
2127 double start = edl->local_session->get_selectionstart();
2128 double end = edl->local_session->get_selectionend();
2129 if(!EQUIV(start, end))
2132 edl->session->labels_follow_edits,
2133 edl->session->plugins_follow_edits,
2134 edl->session->autos_follow_edits);
2137 paste_edls(&new_edls, load_mode, 0, -1,
2138 edl->session->labels_follow_edits,
2139 edl->session->plugins_follow_edits,
2140 edl->session->autos_follow_edits,
2147 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2149 // Add new assets to EDL and schedule assets for index building.
2150 int got_indexes = 0;
2151 for( int i=0; i<new_edls.size(); ++i ) {
2152 EDL *new_edl = new_edls[i];
2153 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2154 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2155 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2161 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2162 for( int i=0; i<new_assets.size(); ++i ) {
2163 Asset *new_asset = new_assets[i];
2167 for( int j=0; j<new_files.size(); ++j ) {
2168 new_file = new_files[j];
2169 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2175 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2176 edl->assets->update(new_asset);
2179 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2181 // Start examining next batch of index files
2182 if(got_indexes) mainindexes->start_build();
2183 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2186 Track *track = edl->tracks->first;
2189 for(int j = 0; j < track->plugin_set.size(); j++)
2191 PluginSet *plugins = track->plugin_set[j];
2192 Plugin *plugin = plugins->get_first_plugin();
2196 if(load_mode == LOADMODE_REPLACE ||
2197 load_mode == LOADMODE_REPLACE_CONCATENATE)
2199 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2202 show_plugin(plugin);
2206 plugin = (Plugin*)plugin->next;
2210 track = track->next;
2213 // if just opening one new resource in replace mode
2214 if( ftype != FILE_IS_XML &&
2215 ( load_mode == LOADMODE_REPLACE ||
2216 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2218 edl->session->proxy_scale = 1;
2219 edl->session->proxy_disabled_scale = 1;
2220 edl->session->proxy_use_scaler = 0;
2221 edl->session->proxy_auto_scale = 0;
2222 edl->session->proxy_beep = 0;
2223 edl->local_session->preview_start = 0;
2224 edl->local_session->preview_end = -1;
2225 edl->local_session->loop_playback = 0;
2226 edl->local_session->set_selectionstart(0);
2227 edl->local_session->set_selectionend(0);
2228 set_brender_active(0, 0);
2233 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2234 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2235 ArrayList<Indexable *> orig_idxbls;
2236 for( int i=0; i<new_assets.size(); ++i )
2237 orig_idxbls.append(new_assets.get(i));
2238 for( int i=0; i<new_edls.size(); ++i ) {
2239 EDL *new_edl = new_edls[i];
2240 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2241 if( track->data_type != TRACK_VIDEO ) continue;
2242 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2243 Indexable *idxbl = (Indexable *)edit->asset;
2244 if( !idxbl ) continue;
2245 if( !idxbl->have_video() ) continue;
2246 if( edit->channel != 0 ) continue; // first layer only
2247 orig_idxbls.append(edit->asset);
2251 gui->unlock_window(); // to update progress bar
2252 int ret = render_proxy(orig_idxbls);
2253 gui->lock_window("MWindow::load_filenames");
2254 if( ret >= 0 && edl->session->proxy_beep ) {
2256 beep(2000., 1.5, 0.5);
2258 beep(4000., 0.25, 0.5);
2262 // need to update undo before project, since mwindow is unlocked & a new load
2263 // can begin here. Should really prevent loading until we're done.
2264 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2265 undo_after(_("load"), LOAD_ALL);
2267 for(int i = 0; i < new_edls.size(); i++)
2269 new_edls[i]->remove_user();
2271 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2273 new_edls.remove_all();
2275 for(int i = 0; i < new_assets.size(); i++)
2277 new_assets[i]->Garbage::remove_user();
2280 new_assets.remove_all();
2281 new_files.remove_all_objects();
2284 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2285 if(load_mode == LOADMODE_REPLACE ||
2286 load_mode == LOADMODE_REPLACE_CONCATENATE)
2288 session->changes_made = 0;
2292 session->changes_made = 1;
2295 gui->stop_hourglass();
2298 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2299 update_project(load_mode);
2301 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2306 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2308 Asset *format_asset = new Asset;
2309 format_asset->format = FILE_FFMPEG;
2310 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2311 ProxyRender proxy_render(this, format_asset);
2312 int new_scale = edl->session->proxy_scale;
2313 int use_scaler = edl->session->proxy_use_scaler;
2315 for( int i=0; i<new_idxbls.size(); ++i ) {
2316 Indexable *orig = new_idxbls.get(i);
2317 Asset *proxy = proxy_render.add_original(orig, new_scale);
2318 if( !proxy ) continue;
2320 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2321 int got_it = exists && // if proxy exists, and is newer than orig
2322 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2323 if( got_it ) continue;
2324 proxy_render.add_needed(orig, proxy);
2327 // render needed proxies
2328 int result = proxy_render.create_needed_proxies(new_scale);
2330 add_proxy(use_scaler,
2331 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2333 format_asset->remove_user();
2334 return !result ? proxy_render.needed_proxies.size() : -1;
2337 int MWindow::enable_proxy()
2340 if( edl->session->proxy_scale == 1 &&
2341 edl->session->proxy_disabled_scale != 1 ) {
2342 int new_scale = edl->session->proxy_disabled_scale;
2343 int new_use_scaler = edl->session->proxy_use_scaler;
2344 edl->session->proxy_disabled_scale = 1;
2345 Asset *asset = new Asset;
2346 asset->format = FILE_FFMPEG;
2347 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2348 ret = to_proxy(asset, new_scale, new_use_scaler);
2349 asset->remove_user();
2351 beep(2000., 1.5, 0.5);
2356 int MWindow::disable_proxy()
2358 if( edl->session->proxy_scale != 1 &&
2359 edl->session->proxy_disabled_scale == 1 ) {
2361 int new_use_scaler = edl->session->proxy_use_scaler;
2362 edl->session->proxy_disabled_scale = edl->session->proxy_scale;
2363 Asset *asset = new Asset;
2364 asset->format = FILE_FFMPEG;
2365 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2366 to_proxy(asset, new_scale, new_use_scaler);
2367 asset->remove_user();
2372 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2374 ArrayList<Indexable*> orig_idxbls;
2375 ArrayList<Indexable*> proxy_assets;
2377 edl->Garbage::add_user();
2379 undo_before(_("proxy"), this);
2380 ProxyRender proxy_render(this, asset);
2382 // revert project to original size from current size
2383 // remove all session proxy assets at the at the current proxy_scale
2384 int proxy_scale = edl->session->proxy_scale;
2386 if( proxy_scale > 1 ) {
2387 Asset *orig_asset = edl->assets->first;
2388 for( ; orig_asset; orig_asset=orig_asset->next ) {
2389 char new_path[BCTEXTLEN];
2390 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2391 // test if proxy asset was already added to proxy_assets
2393 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2394 got_it = !strcmp(proxy_assets[i]->path, new_path);
2395 if( got_it ) continue;
2396 Asset *proxy_asset = edl->assets->get_asset(new_path);
2397 if( !proxy_asset ) continue;
2398 // add pointer to existing EDL asset if it exists
2399 // EDL won't delete it unless it's the same pointer.
2400 proxy_assets.append(proxy_asset);
2401 proxy_asset->add_user();
2402 orig_idxbls.append(orig_asset);
2403 orig_asset->add_user();
2405 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2406 EDL *orig_nested = edl->nested_edls[i];
2407 char new_path[BCTEXTLEN];
2408 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2410 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2411 // test if proxy asset was already added to proxy_assets
2413 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2414 got_it = !strcmp(proxy_assets[i]->path, new_path);
2415 if( got_it ) continue;
2416 Asset *proxy_nested = edl->assets->get_asset(new_path);
2417 if( !proxy_nested ) continue;
2418 // add pointer to existing EDL asset if it exists
2419 // EDL won't delete it unless it's the same pointer.
2420 proxy_assets.append(proxy_nested);
2421 proxy_nested->add_user();
2422 orig_idxbls.append(orig_nested);
2423 orig_nested->add_user();
2426 // convert from the proxy assets to the original assets
2427 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2429 // remove the references
2430 for( int i=0; i<proxy_assets.size(); ++i ) {
2431 Asset *proxy = (Asset *) proxy_assets[i];
2432 proxy->width = proxy->actual_width;
2433 proxy->height = proxy->actual_height;
2434 proxy->remove_user();
2435 edl->assets->remove_pointer(proxy);
2436 proxy->remove_user();
2438 proxy_assets.remove_all();
2439 for( int i = 0; i < orig_idxbls.size(); i++ )
2440 orig_idxbls[i]->remove_user();
2441 orig_idxbls.remove_all();
2444 ArrayList<char *> confirm_paths; // test for new files
2445 confirm_paths.set_array_delete();
2447 // convert to new size if not original size
2448 if( new_scale != 1 ) {
2450 Asset *orig = edl->assets->first;
2451 for( ; orig; orig=orig->next ) {
2452 Asset *proxy = proxy_render.add_original(orig, new_scale);
2453 if( !proxy ) continue;
2454 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2455 int got_it = exists && // if proxy exists, and is newer than orig
2456 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2458 if( exists ) // prompt user to overwrite
2459 confirm_paths.append(cstrdup(proxy->path));
2460 proxy_render.add_needed(orig, proxy);
2463 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2464 EDL *orig_nested = edl->nested_edls[i];
2465 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2466 if( !proxy ) continue;
2467 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2468 int got_it = exists && // if proxy exists, and is newer than orig_nested
2469 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2471 if( exists ) // prompt user to overwrite
2472 confirm_paths.append(cstrdup(proxy->path));
2473 proxy_render.add_needed(orig_nested, proxy);
2479 // test for existing files
2480 if( confirm_paths.size() ) {
2481 result = ConfirmSave::test_files(this, &confirm_paths);
2482 confirm_paths.remove_all_objects();
2486 result = proxy_render.create_needed_proxies(new_scale);
2488 if( !result ) // resize project
2489 edl->set_proxy(new_scale, new_use_scaler,
2490 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2492 undo_after(_("proxy"), LOAD_ALL);
2493 edl->Garbage::remove_user();
2496 gui->lock_window("MWindow::to_proxy");
2497 update_project(LOADMODE_REPLACE);
2498 gui->unlock_window();
2500 return !result ? proxy_render.needed_proxies.size() : -1;
2503 void MWindow::test_plugins(EDL *new_edl, char *path)
2505 char string[BCTEXTLEN];
2507 // Do a check whether plugins exist
2508 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2509 for( int k=0; k<track->plugin_set.total; ++k ) {
2510 PluginSet *plugin_set = track->plugin_set[k];
2511 for( Plugin *plugin = (Plugin*)plugin_set->first;
2512 plugin; plugin = (Plugin*)plugin->next ) {
2513 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2514 // ok we need to find it in plugindb
2515 PluginServer *server =
2516 scan_plugindb(plugin->title, track->data_type);
2517 if( !server || server->transition ) {
2519 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2520 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2521 "effect", _(plugin->title), path);
2522 MainError::show_error(string);
2527 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2528 if( !edit->transition ) continue;
2529 // ok we need to find transition in plugindb
2530 PluginServer *server =
2531 scan_plugindb(edit->transition->title, track->data_type);
2532 if( !server || !server->transition ) {
2534 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2535 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2536 "transition", _(edit->transition->title), path);
2537 MainError::show_error(string);
2544 void MWindow::init_shm(const char *pfn, int64_t min)
2547 // Fix shared memory
2548 FILE *fd = fopen(pfn, "r");
2550 fscanf(fd, "%jd", &result);
2552 if( result >= min ) return;
2555 fd = fopen(pfn, "w");
2557 fprintf(fd, "0x%jx", min);
2560 fd = fopen(pfn, "r");
2562 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2566 fscanf(fd, "%jd", &result);
2568 if( result < min ) {
2569 eprintf(_("MWindow::init_shm: %s is %p.\n"
2570 "you probably need to be root, or:\n"
2571 "as root, run: echo 0x%jx > %s\n"
2572 "before trying to start cinelerra.\n"
2573 "It should be at least 0x%jx for Cinelerra.\n"),
2574 pfn, (void *)result, min, pfn, min);
2578 void MWindow::create_objects(int want_gui,
2582 const int debug = 0;
2583 if(debug) PRINT_TRACE
2585 // For some reason, init_signals must come after show_splash or the signals won't
2588 if(debug) PRINT_TRACE
2591 if(debug) PRINT_TRACE
2594 if(debug) PRINT_TRACE
2595 default_standard = default_std();
2596 init_defaults(defaults, config_path);
2600 splash_window->update_status(_("Initializing Plugins"));
2601 init_plugins(this, preferences);
2602 if(debug) PRINT_TRACE
2603 init_ladspa_plugins(this, preferences);
2604 if(debug) PRINT_TRACE
2605 init_plugin_tips(*plugindb, cin_lang);
2607 splash_window->update_status(_("Initializing GUI"));
2608 if(debug) PRINT_TRACE
2611 if(debug) PRINT_TRACE
2615 splash_window->update_status(_("Initializing Fonts"));
2616 char string[BCTEXTLEN];
2617 strcpy(string, preferences->plugin_dir);
2618 strcat(string, "/" FONT_SEARCHPATH);
2619 BC_Resources::init_fontconfig(string);
2620 if(debug) PRINT_TRACE
2622 // Default project created here
2624 if(debug) PRINT_TRACE
2627 if(debug) PRINT_TRACE
2632 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2635 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2637 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2638 if(session->show_vwindow)
2639 get_viewer(1, DEFAULT_VWINDOW);
2640 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2643 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2646 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2649 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2652 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2655 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2658 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2664 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2665 mainprogress = new MainProgress(this, gui);
2666 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2667 undo = new MainUndo(this);
2669 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2671 plugin_guis = new ArrayList<PluginServer*>;
2672 dead_plugins = new ArrayList<PluginServer*>;
2673 keyframe_threads = new ArrayList<KeyFrameThread*>;
2675 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2678 session->show_vwindow);
2680 // Show all vwindows
2681 // if(session->show_vwindow) {
2682 // for(int j = 0; j < vwindows.size(); j++) {
2683 // VWindow *vwindow = vwindows[j];
2684 // if( !vwindow->is_running() ) continue;
2685 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2688 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2689 // vwindow->gui->lock_window("MWindow::create_objects 1");
2690 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2691 // vwindow->gui->show_window();
2692 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2693 // vwindow->gui->unlock_window();
2698 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2700 if(session->show_cwindow)
2702 cwindow->gui->lock_window("MWindow::create_objects 1");
2703 cwindow->gui->show_window();
2704 cwindow->gui->unlock_window();
2707 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2708 if(session->show_awindow)
2710 awindow->gui->lock_window("MWindow::create_objects 1");
2711 awindow->gui->show_window();
2712 awindow->gui->unlock_window();
2715 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2716 if(session->show_lwindow)
2718 lwindow->gui->lock_window("MWindow::create_objects 1");
2719 lwindow->gui->show_window();
2720 lwindow->gui->unlock_window();
2723 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2725 (int)timer.get_difference(),
2727 if(session->show_gwindow)
2729 gwindow->gui->lock_window("MWindow::create_objects 1");
2730 gwindow->gui->show_window();
2731 gwindow->gui->unlock_window();
2734 if(debug) PRINT_TRACE
2736 gui->lock_window("MWindow::create_objects 1");
2737 gui->mainmenu->load_defaults(defaults);
2738 gui->mainmenu->update_toggles(0);
2739 gui->update_patchbay();
2740 gui->draw_canvas(0, 0);
2741 gui->draw_cursor(1);
2743 gui->raise_window();
2744 gui->unlock_window();
2746 if(debug) PRINT_TRACE
2748 if(preferences->use_tipwindow)
2750 if(debug) PRINT_TRACE
2752 gui->add_keyboard_listener(
2753 (int (BC_WindowBase::*)(BC_WindowBase *))
2754 &MWindowGUI::keyboard_listener);
2757 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2758 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2759 if(debug) PRINT_TRACE
2761 BC_WindowBase::get_resources()->vframe_shm = 1;
2765 void MWindow::show_splash()
2767 #include "data/heroine_logo9_png.h"
2768 VFrame *frame = new VFramePng(heroine_logo9_png);
2769 BC_DisplayInfo dpyi;
2770 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2771 int rr = (rw < rh ? rw : rh) / 4;
2772 splash_window = new SplashGUI(frame, rr, rr);
2773 splash_window->create_objects();
2776 void MWindow::hide_splash()
2779 delete splash_window;
2784 void MWindow::start()
2788 // vwindows[DEFAULT_VWINDOW]->start();
2799 playback_3d->start();
2805 run_lock->lock("MWindow::run");
2809 brender_lock->lock("MWindow::run 1");
2810 delete brender; brender = 0;
2811 brender_lock->unlock();
2813 interrupt_indexes();
2819 void MWindow::show_vwindow()
2821 int total_running = 0;
2822 session->show_vwindow = 1;
2824 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2825 // Raise all windows which are visible
2826 for(int j = 0; j < vwindows.size(); j++) {
2827 VWindow *vwindow = vwindows[j];
2828 if( !vwindow->is_running() ) continue;
2829 vwindow->gui->lock_window("MWindow::show_vwindow");
2830 vwindow->gui->show_window(0);
2831 vwindow->gui->raise_window();
2832 vwindow->gui->flush();
2833 vwindow->gui->unlock_window();
2837 // If no windows visible
2840 get_viewer(1, DEFAULT_VWINDOW);
2843 gui->mainmenu->show_vwindow->set_checked(1);
2846 void MWindow::show_awindow()
2848 session->show_awindow = 1;
2849 awindow->gui->lock_window("MWindow::show_awindow");
2850 awindow->gui->show_window();
2851 awindow->gui->raise_window();
2852 awindow->gui->flush();
2853 awindow->gui->unlock_window();
2854 gui->mainmenu->show_awindow->set_checked(1);
2857 char *MWindow::get_cwindow_display()
2859 char *x11_host = screens < 2 || session->window_config == 0 ?
2860 session->a_x11_host : session->b_x11_host;
2861 return *x11_host ? x11_host : 0;
2864 void MWindow::show_cwindow()
2866 session->show_cwindow = 1;
2867 cwindow->show_window();
2868 gui->mainmenu->show_cwindow->set_checked(1);
2871 void MWindow::show_gwindow()
2873 session->show_gwindow = 1;
2875 gwindow->gui->lock_window("MWindow::show_gwindow");
2876 gwindow->gui->show_window();
2877 gwindow->gui->raise_window();
2878 gwindow->gui->flush();
2879 gwindow->gui->unlock_window();
2881 gui->mainmenu->show_gwindow->set_checked(1);
2883 void MWindow::hide_gwindow()
2885 session->show_gwindow = 0;
2887 gwindow->gui->lock_window("MWindow::show_gwindow");
2888 gwindow->gui->hide_window();
2889 gwindow->gui->unlock_window();
2892 void MWindow::show_lwindow()
2894 session->show_lwindow = 1;
2895 lwindow->gui->lock_window("MWindow::show_lwindow");
2896 lwindow->gui->show_window();
2897 lwindow->gui->raise_window();
2898 lwindow->gui->flush();
2899 lwindow->gui->unlock_window();
2900 gui->mainmenu->show_lwindow->set_checked(1);
2903 void MWindow::restore_windows()
2905 if( !session->show_vwindow ) {
2906 for( int i=0, n=vwindows.size(); i<n; ++i ) {
2907 VWindow *vwindow = vwindows[i];
2908 if( !vwindow || !vwindow->is_running() ) continue;
2909 vwindow->gui->lock_window("MWindow::restore_windows");
2910 vwindow->gui->close(1);
2911 vwindow->gui->unlock_window();
2917 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
2918 awindow->gui->lock_window("MWindow::restore_windows");
2919 awindow->gui->close_event();
2920 awindow->gui->unlock_window();
2922 else if( session->show_awindow && awindow->gui->is_hidden() )
2925 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
2926 cwindow->gui->lock_window("MWindow::restore_windows");
2927 cwindow->hide_window();
2928 cwindow->gui->unlock_window();
2930 else if( session->show_cwindow && cwindow->gui->is_hidden() )
2931 cwindow->show_window();
2933 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
2934 gwindow->gui->lock_window("MWindow::restore_windows");
2935 gwindow->gui->close_event();
2936 gwindow->gui->unlock_window();
2938 else if( session->show_gwindow && gwindow->gui->is_hidden() )
2941 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
2942 lwindow->gui->lock_window("MWindow::restore_windows");
2943 lwindow->gui->close_event();
2944 lwindow->gui->unlock_window();
2946 else if( session->show_lwindow && lwindow->gui->is_hidden() )
2952 void MWindow::save_layout(int no)
2954 char layout_path[BCTEXTLEN];
2955 snprintf(layout_path, sizeof(layout_path), "%s/" LAYOUT_FILE,
2956 File::get_config_path(), no);
2957 session->save_file(layout_path);
2960 void MWindow::load_layout(int no)
2962 char layout_path[BCTEXTLEN];
2963 snprintf(layout_path, sizeof(layout_path), "%s/" LAYOUT_FILE,
2964 File::get_config_path(), no);
2965 session->load_file(layout_path);
2967 gui->default_positions();
2971 int MWindow::tile_windows(int window_config)
2973 int need_reload = 0;
2974 int play_config = window_config==0 ? 0 : 1;
2975 edl->session->playback_config->load_defaults(defaults, play_config);
2976 session->default_window_positions(window_config);
2977 if( screens == 1 ) {
2978 gui->default_positions();
2979 sync_parameters(CHANGE_ALL);
2986 void MWindow::toggle_loop_playback()
2988 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2989 set_loop_boundaries();
2992 gui->draw_overlays(1);
2993 sync_parameters(CHANGE_PARAMS);
2996 void MWindow::set_screens(int value)
3001 void MWindow::set_auto_keyframes(int value)
3003 edl->session->auto_keyframes = value;
3004 gui->mbuttons->edit_panel->keyframe->update(value);
3006 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
3007 cwindow->gui->edit_panel->keyframe->update(value);
3008 cwindow->gui->flush();
3009 cwindow->gui->unlock_window();
3012 void MWindow::set_auto_visibility(Autos *autos, int value)
3014 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3015 edl->session->auto_conf->plugins = value;
3016 else if( autos->autoidx >= 0 )
3017 edl->session->auto_conf->autos[autos->autoidx] = value;
3021 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3022 gui->mainmenu->update_toggles(1);
3023 gui->unlock_window();
3024 gwindow->gui->update_toggles(1);
3025 gui->lock_window("MWindow::set_auto_visibility");
3028 void MWindow::set_keyframe_type(int mode)
3030 gui->lock_window("MWindow::set_keyframe_type");
3031 edl->local_session->floatauto_type = mode;
3032 gui->mainmenu->update_toggles(0);
3033 gui->unlock_window();
3036 int MWindow::set_editing_mode(int new_editing_mode)
3038 edl->session->editing_mode = new_editing_mode;
3039 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3040 gui->mbuttons->edit_panel->update();
3041 gui->set_editing_mode(1);
3043 cwindow->gui->lock_window("MWindow::set_editing_mode");
3044 cwindow->gui->edit_panel->update();
3045 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3046 cwindow->gui->unlock_window();
3050 void MWindow::toggle_editing_mode()
3052 int mode = edl->session->editing_mode;
3053 if( mode == EDITING_ARROW )
3054 set_editing_mode(EDITING_IBEAM);
3056 set_editing_mode(EDITING_ARROW);
3059 void MWindow::toggle_camera_xyz()
3061 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3062 gwindow->gui->toggle_camera_xyz();
3063 gwindow->gui->unlock_window();
3066 void MWindow::toggle_projector_xyz()
3068 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3069 gwindow->gui->toggle_projector_xyz();
3070 gwindow->gui->unlock_window();
3073 void MWindow::set_labels_follow_edits(int value)
3075 edl->session->labels_follow_edits = value;
3076 gui->mbuttons->edit_panel->locklabels->update(value);
3077 gui->mainmenu->labels_follow_edits->set_checked(value);
3081 void MWindow::sync_parameters(int change_type)
3083 if( in_destructor ) return;
3085 // Sync engines which are playing back
3086 if(cwindow->playback_engine->is_playing_back)
3088 if(change_type == CHANGE_PARAMS)
3090 // TODO: block keyframes until synchronization is done
3091 cwindow->playback_engine->sync_parameters(edl);
3096 int command = cwindow->playback_engine->command->command;
3097 cwindow->playback_engine->que->send_command(STOP,
3101 // Waiting for tracking to finish would make the restart position more
3102 // accurate but it can't lock the window to stop tracking for some reason.
3103 // Not waiting for tracking gives a faster response but restart position is
3104 // only as accurate as the last tracking update.
3105 cwindow->playback_engine->interrupt_playback(0);
3106 cwindow->playback_engine->que->send_command(command,
3115 cwindow->refresh_frame(change_type);
3119 void MWindow::age_caches()
3121 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3123 // preferences->cache_size,
3124 // audio_cache->get_memory_usage(1),
3125 // video_cache->get_memory_usage(1),
3126 // frame_cache->get_memory_usage(),
3127 // wave_cache->get_memory_usage(),
3129 frame_cache->age_cache(512);
3130 wave_cache->age_cache(8192);
3132 int64_t memory_usage;
3133 int64_t prev_memory_usage = 0;
3135 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3136 while( !result && prev_memory_usage !=
3137 (memory_usage=video_cache->get_memory_usage(1)) &&
3138 memory_usage > video_size ) {
3139 video_cache->delete_oldest();
3140 prev_memory_usage = memory_usage;
3143 prev_memory_usage = 0;
3145 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3146 while( !result && prev_memory_usage !=
3147 (memory_usage=audio_cache->get_memory_usage(1)) &&
3148 memory_usage > audio_size ) {
3149 audio_cache->delete_oldest();
3150 prev_memory_usage = memory_usage;
3154 void MWindow::reset_android_remote()
3156 gui->use_android_remote(preferences->android_remote);
3160 void MWindow::show_keyframe_gui(Plugin *plugin)
3162 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3163 // Find existing thread
3164 for(int i = 0; i < keyframe_threads->size(); i++)
3166 if(keyframe_threads->get(i)->plugin == plugin)
3168 keyframe_threads->get(i)->start_window(plugin, 0);
3169 keyframe_gui_lock->unlock();
3174 // Find unused thread
3175 for(int i = 0; i < keyframe_threads->size(); i++)
3177 if(!keyframe_threads->get(i)->plugin)
3179 keyframe_threads->get(i)->start_window(plugin, 0);
3180 keyframe_gui_lock->unlock();
3185 // Create new thread
3186 KeyFrameThread *thread = new KeyFrameThread(this);
3187 keyframe_threads->append(thread);
3188 thread->start_window(plugin, 0);
3190 keyframe_gui_lock->unlock();
3197 void MWindow::show_plugin(Plugin *plugin)
3202 // Remove previously deleted plugin GUIs
3203 dead_plugin_lock->lock("MWindow::show_plugin");
3204 dead_plugins->remove_all_objects();
3205 dead_plugin_lock->unlock();
3207 //printf("MWindow::show_plugin %d\n", __LINE__);
3211 plugin_gui_lock->lock("MWindow::show_plugin");
3212 for(int i = 0; i < plugin_guis->total; i++)
3214 // Pointer comparison
3215 if(plugin_guis->get(i)->plugin == plugin)
3217 plugin_guis->get(i)->raise_window();
3224 //printf("MWindow::show_plugin 1\n");
3225 if( !done && !plugin->track ) {
3226 printf("MWindow::show_plugin track not defined.\n");
3230 PluginServer *server = scan_plugindb(plugin->title,
3231 plugin->track->data_type);
3233 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3234 if(server && server->uses_gui)
3236 PluginServer *gui = new PluginServer(*server);
3237 plugin_guis->append(gui);
3238 // Needs mwindow to do GUI
3239 gui->set_mwindow(this);
3240 gui->open_plugin(0, preferences, edl, plugin);
3245 plugin_gui_lock->unlock();
3246 //printf("MWindow::show_plugin %d\n", __LINE__);
3249 //printf("MWindow::show_plugin 2\n");
3252 void MWindow::hide_plugin(Plugin *plugin, int lock)
3255 // Update the toggle
3256 gui->lock_window("MWindow::hide_plugin");
3257 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3258 gui->unlock_window();
3260 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3261 for(int i = 0; i < plugin_guis->total; i++)
3263 if(plugin_guis->get(i)->plugin == plugin)
3265 PluginServer *ptr = plugin_guis->get(i);
3266 plugin_guis->remove(ptr);
3267 if(lock) plugin_gui_lock->unlock();
3268 // Last command executed in client side close
3269 // Schedule for deletion
3276 if(lock) plugin_gui_lock->unlock();
3279 void MWindow::delete_plugin(PluginServer *plugin)
3281 dead_plugin_lock->lock("MWindow::delete_plugin");
3282 dead_plugins->append(plugin);
3283 dead_plugin_lock->unlock();
3286 void MWindow::hide_plugins()
3288 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3289 while(plugin_guis->size())
3291 PluginServer *ptr = plugin_guis->get(0);
3292 plugin_guis->remove(ptr);
3293 plugin_gui_lock->unlock();
3294 // Last command executed in client side close
3295 // Schedule for deletion
3298 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3300 plugin_gui_lock->unlock();
3302 hide_keyframe_guis();
3305 void MWindow::hide_keyframe_guis()
3307 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3308 for(int i = 0; i < keyframe_threads->size(); i++)
3310 keyframe_threads->get(i)->close_window();
3312 keyframe_gui_lock->unlock();
3315 void MWindow::hide_keyframe_gui(Plugin *plugin)
3317 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3318 for(int i = 0; i < keyframe_threads->size(); i++)
3320 if(keyframe_threads->get(i)->plugin == plugin)
3322 keyframe_threads->get(i)->close_window();
3326 keyframe_gui_lock->unlock();
3329 int MWindow::get_hash_color(Edit *edit)
3331 Indexable *idxbl = edit->asset ?
3332 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3333 if( !idxbl ) return 0;
3334 char path[BCTEXTLEN];
3335 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3336 edl->session->proxy_scale == 1 ||
3337 ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
3338 strcpy(path, idxbl->path);
3339 char *cp = strrchr(path, '/');
3340 cp = !cp ? path : cp+1;
3341 uint8_t *bp = (uint8_t*)cp;
3343 while( *bp ) v += *bp++;
3344 return get_hash_color(v);
3347 int MWindow::get_hash_color(int v)
3349 int hash = 0x303030;
3350 if( v & 0x01 ) hash ^= 0x000040;
3351 if( v & 0x02 ) hash ^= 0x004000;
3352 if( v & 0x04 ) hash ^= 0x400000;
3353 if( v & 0x08 ) hash ^= 0x080000;
3354 if( v & 0x10 ) hash ^= 0x000800;
3355 if( v & 0x20 ) hash ^= 0x000008;
3356 if( v & 0x40 ) hash ^= 0x404040;
3357 if( v & 0x80 ) hash ^= 0x080808;
3361 int MWindow::get_group_color(int v)
3363 int color = 0x606060;
3364 if( v & 0x01 ) color ^= 0x000080;
3365 if( v & 0x02 ) color ^= 0x008000;
3366 if( v & 0x04 ) color ^= 0x800000;
3367 if( v & 0x08 ) color ^= 0x100000;
3368 if( v & 0x10 ) color ^= 0x001000;
3369 if( v & 0x20 ) color ^= 0x000010;
3370 if( v & 0x40 ) color ^= 0x080808;
3371 if( v & 0x80 ) color ^= 0x909090;
3375 int MWindow::get_title_color(Edit *edit)
3377 unsigned color = edit->color & 0xffffff;
3378 unsigned alpha = (~edit->color>>24) & 0xff;
3380 if( edit->group_id )
3381 color = get_group_color(edit->group_id);
3382 else if( preferences->autocolor_assets )
3383 color = get_hash_color(edit);
3388 alpha = session->title_bar_alpha*255;
3389 return color | (~alpha<<24);
3392 void MWindow::update_keyframe_guis()
3394 // Send new configuration to keyframe GUI's
3395 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3396 for(int i = 0; i < keyframe_threads->size(); i++)
3398 KeyFrameThread *ptr = keyframe_threads->get(i);
3399 if(edl->tracks->plugin_exists(ptr->plugin))
3403 ptr->close_window();
3406 keyframe_gui_lock->unlock();
3409 void MWindow::update_plugin_guis(int do_keyframe_guis)
3411 // Send new configuration to plugin GUI's
3412 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3414 for(int i = 0; i < plugin_guis->size(); i++)
3416 PluginServer *ptr = plugin_guis->get(i);
3417 if(edl->tracks->plugin_exists(ptr->plugin))
3421 // Schedule for deletion if no plugin
3422 plugin_guis->remove_number(i);
3431 // Change plugin variable if not visible
3432 Track *track = edl->tracks->first;
3435 for(int i = 0; i < track->plugin_set.size(); i++)
3437 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3441 for(int i = 0; i < plugin_guis->size(); i++)
3443 PluginServer *server = plugin_guis->get(i);
3444 if(server->plugin == plugin)
3451 if(!got_it) plugin->show = 0;
3453 plugin = (Plugin*)plugin->next;
3457 track = track->next;
3460 plugin_gui_lock->unlock();
3463 if(do_keyframe_guis) update_keyframe_guis();
3466 int MWindow::plugin_gui_open(Plugin *plugin)
3469 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3470 for(int i = 0; i < plugin_guis->total; i++)
3472 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3478 plugin_gui_lock->unlock();
3482 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3484 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3485 for(int i = 0; i < plugin_guis->total; i++)
3487 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3489 plugin_guis->get(i)->render_gui(data);
3493 plugin_gui_lock->unlock();
3496 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3498 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3499 for(int i = 0; i < plugin_guis->total; i++)
3501 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3503 plugin_guis->get(i)->render_gui(data, size);
3507 plugin_gui_lock->unlock();
3511 void MWindow::update_plugin_states()
3513 plugin_gui_lock->lock("MWindow::update_plugin_states");
3514 for(int i = 0; i < plugin_guis->total; i++)
3518 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3519 PluginServer *src_plugingui = plugin_guis->get(i);
3521 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3522 for(Track *track = edl->tracks->first;
3524 track = track->next)
3527 j < track->plugin_set.total && !result;
3530 PluginSet *plugin_set = track->plugin_set[j];
3531 for(Plugin *plugin = (Plugin*)plugin_set->first;
3533 plugin = (Plugin*)plugin->next)
3535 if(plugin == src_plugin &&
3536 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3542 // Doesn't exist anymore
3545 hide_plugin(src_plugin, 0);
3549 plugin_gui_lock->unlock();
3553 void MWindow::update_plugin_titles()
3555 for(int i = 0; i < plugin_guis->total; i++)
3557 plugin_guis->get(i)->update_title();
3561 int MWindow::asset_to_edl(EDL *new_edl,
3563 RecordLabels *labels)
3565 const int debug = 0;
3566 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3569 // Keep frame rate, sample rate, and output size unchanged.
3570 // These parameters would revert the project if VWindow displayed an asset
3571 // of different size than the project.
3572 if(new_asset->video_data)
3574 new_edl->session->video_tracks = new_asset->layers;
3577 new_edl->session->video_tracks = 0;
3579 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3585 if(new_asset->audio_data)
3587 new_edl->session->audio_tracks = new_asset->channels;
3590 new_edl->session->audio_tracks = 0;
3591 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3593 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3594 new_edl->create_default_tracks();
3595 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3596 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3600 //printf("MWindow::asset_to_edl 3\n");
3601 new_edl->insert_asset(new_asset,
3606 //printf("MWindow::asset_to_edl 3\n");
3607 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3609 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3610 if(edl->session->cursor_on_frames)
3612 double length = new_edl->tracks->total_length();
3613 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3614 new_edl->tracks->clear(length, edl_length, 1, 1);
3620 char string[BCTEXTLEN];
3622 fs.extract_name(string, new_asset->path);
3623 //printf("MWindow::asset_to_edl 3\n");
3625 strcpy(new_edl->local_session->clip_title, string);
3626 //printf("MWindow::asset_to_edl 4 %s\n", string);
3627 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3633 // Reset everything after a load.
3634 void MWindow::update_project(int load_mode)
3636 const int debug = 0;
3638 if(debug) PRINT_TRACE
3639 edl->tracks->update_y_pixels(theme);
3640 session->update_clip_number();
3642 if(debug) PRINT_TRACE
3644 if( load_mode == LOADMODE_REPLACE ||
3645 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3646 delete gui->keyvalue_popup;
3647 gui->keyvalue_popup = 0;
3651 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3652 if(debug) PRINT_TRACE
3653 gui->unlock_window();
3656 cwindow->gui->lock_window("MWindow::update_project 1");
3657 cwindow->update(0, 0, 1, 1, 1);
3658 cwindow->gui->unlock_window();
3660 if(debug) PRINT_TRACE
3662 // Close all the vwindows
3663 if( load_mode == LOADMODE_REPLACE ||
3664 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3665 if(debug) PRINT_TRACE
3666 int first_vwindow = 0;
3667 if(session->show_vwindow) first_vwindow = 1;
3668 // Change visible windows to no source
3669 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3670 VWindow *vwindow = vwindows[i];
3671 if( !vwindow->is_running() ) continue;
3672 vwindow->change_source(-1);
3675 // Close remaining windows
3676 for(int i = first_vwindow; i < vwindows.size(); i++) {
3677 VWindow *vwindow = vwindows[i];
3678 if( !vwindow->is_running() ) continue;
3679 vwindow->close_window();
3681 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3682 VWindow *vwindow = get_viewer(1, -1);
3683 vwindow->change_source(i);
3685 if(debug) PRINT_TRACE
3689 for( int i=0; i<edl->mixers.size(); ++i ) {
3690 Mixer *mixer = edl->mixers[i];
3691 ZWindow *zwindow = get_mixer(mixer);
3692 zwindow->set_title(mixer->title);
3698 if(debug) PRINT_TRACE
3699 cwindow->gui->lock_window("MWindow::update_project 2");
3700 cwindow->gui->timebar->update(0);
3701 cwindow->gui->unlock_window();
3703 if(debug) PRINT_TRACE
3704 cwindow->refresh_frame(CHANGE_ALL);
3706 awindow->gui->async_update_assets();
3707 if(debug) PRINT_TRACE
3709 gui->lock_window("MWindow::update_project");
3710 gui->update_mixers(0, 0);
3712 if(debug) PRINT_TRACE
3715 void MWindow::update_vwindow()
3717 for( int i=0; i<vwindows.size(); ++i ) {
3718 VWindow *vwindow = vwindows[i];
3719 if( vwindow->is_running() ) {
3720 vwindow->gui->lock_window("MWindow::update_vwindow");
3722 vwindow->gui->unlock_window();
3727 void MWindow::remove_indexfile(Indexable *indexable)
3729 if( !indexable->is_asset ) return;
3730 Asset *asset = (Asset *)indexable;
3732 IndexFile::delete_index(preferences, asset, ".toc");
3733 IndexFile::delete_index(preferences, asset, ".idx");
3734 IndexFile::delete_index(preferences, asset, ".mkr");
3737 void MWindow::rebuild_indices()
3739 for(int i = 0; i < session->drag_assets->total; i++)
3741 Indexable *indexable = session->drag_assets->get(i);
3742 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3743 remove_indexfile(indexable);
3744 // Schedule index build
3745 IndexState *index_state = indexable->index_state;
3746 index_state->index_status = INDEX_NOTTESTED;
3747 if( indexable->is_asset ) {
3748 Asset *asset = (Asset *)indexable;
3749 if( asset->format != FILE_PCM ) {
3750 asset->format = FILE_UNKNOWN;
3751 asset->reset_audio();
3753 asset->reset_video();
3754 remove_asset_from_caches(asset);
3755 // File file; // re-probe the asset
3756 // file.open_file(preferences, asset, 1, 0);
3758 mainindexes->add_next_asset(0, indexable);
3760 mainindexes->start_build();
3764 void MWindow::save_backup()
3768 edl->set_path(session->filename);
3769 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3770 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3771 File::get_config_path(), BACKUP_FILE);
3772 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3773 File::get_config_path(), BACKUP_FILE1);
3774 rename(backup_path, backup_path1);
3775 edl->save_xml(&file, backup_path);
3776 file.terminate_string();
3778 fs.complete_path(backup_path);
3780 if(file.write_to_file(backup_path))
3783 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3784 gui->show_message(string2);
3788 void MWindow::load_backup()
3790 ArrayList<char*> path_list;
3791 path_list.set_array_delete();
3793 char backup_path[BCTEXTLEN];
3794 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3795 File::get_config_path(), BACKUP_FILE);
3797 fs.complete_path(backup_path);
3799 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3800 strcpy(out_path, backup_path);
3802 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3803 edl->local_session->clip_title[0] = 0;
3804 // This is unique to backups since the path of the backup is different than the
3805 // path of the project.
3806 set_filename(edl->path);
3807 path_list.remove_all_objects();
3812 void MWindow::save_undo_data()
3815 undo_after(_("perpetual session"), LOAD_ALL);
3816 char perpetual_path[BCTEXTLEN];
3817 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3818 File::get_config_path(), PERPETUAL_FILE);
3819 FILE *fp = fopen(perpetual_path,"w");
3825 void MWindow::load_undo_data()
3827 char perpetual_path[BCTEXTLEN];
3828 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3829 File::get_config_path(), PERPETUAL_FILE);
3830 FILE *fp = fopen(perpetual_path,"r");
3837 int MWindow::copy_target(const char *path, const char *target)
3839 int ifd = ::open(path, O_RDONLY);
3841 eprintf("Cannot open asset: %s", path);
3845 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
3848 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
3849 char progress_title[BCTEXTLEN];
3850 sprintf(progress_title, _("Copying: %s\n"), target);
3851 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
3853 int64_t count = 0, len = -1;
3854 int bfrsz = 0x100000;
3855 uint8_t *bfr = new uint8_t[bfrsz];
3856 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
3857 if( len != ::write(ofd, bfr, len) ) {
3858 eprintf("Error writing: %s", target);
3861 if( progress.is_cancelled() ) {
3865 progress.update(count += len, 1);
3870 progress.stop_progress();
3872 eprintf("Error reading: %s", path);
3877 eprintf("Cannot create asset target: %s", target);
3882 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
3884 char target[BCTEXTLEN];
3886 const char *bp = real_path, *cp = bp;
3887 const char *lp = link_path, *np = lp;
3888 char *tp = target, *ep = tp+sizeof(target)-1, lch;
3889 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
3890 if( lch == '/' ) { np = lp; cp = bp; }
3892 while( tp<ep && *np ) {
3893 if( *np++ != '/' ) continue;
3894 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
3896 while( tp<ep && *cp ) *tp++ = *cp++;
3900 strcpy(target, real_path);
3901 if( symlink(target, link_path) ) {
3902 eprintf("Cannot create symlink: %s", link_path);
3908 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
3910 char dir_path[BCTEXTLEN];
3911 strcpy(dir_path, dir);
3913 fs.complete_path(dir_path);
3916 if( !stat(dir_path, &st) ) {
3917 if( !S_ISDIR(st.st_mode) ) {
3918 eprintf("Path exists and is not a directory\n%s", dir_path);
3923 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
3924 eprintf("Cannot create directory\n%s", dir_path);
3928 char *real_dir = realpath(dir_path, 0);
3929 strcpy(dir_path, real_dir);
3932 EDL *save_edl = new EDL;
3933 save_edl->create_objects();
3934 save_edl->copy_all(edl);
3936 char progress_title[BCTEXTLEN];
3937 sprintf(progress_title, _("Saving to %s:\n"), dir);
3938 int total_assets = save_edl->assets->total();
3939 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
3941 Asset *current = save_edl->assets->first;
3942 for( int i=0; !ret && current; ++i, current=NEXT ) {
3943 char *path = current->path;
3944 if( ::stat(path, &st) ) {
3945 eprintf("Asset not found: %s", path);
3948 char *real_path = realpath(path, 0);
3949 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
3950 char link_path[BCTEXTLEN];
3951 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
3953 if( strcmp(real_path, link_path) ) {
3954 if( !::lstat(link_path, &st) ) {
3956 ::remove(link_path);
3962 eprintf("copy/link to self, skippped: %s", path);
3966 if( save_mode == SAVE_PROJECT_COPY ) {
3967 if( copy_target(real_path, link_path) )
3971 link_target(real_path, link_path,
3972 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
3976 strcpy(path, link_path);
3978 if( progress->is_cancelled() ) break;
3979 progress->update(i);
3982 progress->stop_progress();
3985 char *cp = strrchr(dir_path,'/');
3986 char *bp = cp ? cp+1 : dir_path;
3987 char filename[BCTEXTLEN];
3988 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
3989 save_edl->set_path(filename);
3991 save_edl->save_xml(&file, filename);
3992 file.terminate_string();
3994 if( !file.write_to_file(filename) ) {
3995 char string[BCTEXTLEN];
3996 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
3997 gui->lock_window("SaveProject::run 2");
3998 gui->show_message(string);
3999 gui->unlock_window();
4000 gui->mainmenu->add_load(filename);
4003 eprintf(_("Couldn't open %s."), filename);
4005 save_edl->remove_user();
4008 gui->lock_window("MWindow::save_project");
4009 ArrayList<char*> filenames;
4010 filenames.append(filename);
4011 load_filenames(&filenames, LOADMODE_REPLACE);
4012 gui->unlock_window();
4017 static inline int gcd(int m, int n)
4020 if( m < n ) { r = m; m = n; n = r; }
4021 while( (r = m % n) != 0 ) { m = n; n = r; }
4025 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4028 if(!width || !height) return 1;
4029 if( width == 720 && (height == 480 || height == 576) ) {
4030 w = 4; h = 3; return 0; // for NTSC and PAL
4032 double ar = (double)width / height;
4033 // square-ish pixels
4034 if( EQUIV(ar, 1.0000) ) return 0;
4035 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4036 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4037 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4038 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4039 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4040 int ww = width, hh = height;
4041 // numerator, denominator must be under mx
4042 int mx = 255, n = gcd(ww, hh);
4043 if( n > 1 ) { ww /= n; hh /= n; }
4044 // search near height in case extra/missing lines
4045 if( ww >= mx || hh >= mx ) {
4046 double err = height; // +/- 2 percent height
4047 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4048 int iw = width, ih = height+i;
4049 if( (n=gcd(iw, ih)) > 1 ) {
4050 int u = iw/n; if( u >= mx ) continue;
4051 int v = ih/n; if( v >= mx ) continue;
4052 double r = (double) u/v, er = fabs(ar-r);
4053 if( er >= err ) continue;
4054 err = er; ww = u; hh = v;
4063 void MWindow::reset_caches()
4065 frame_cache->remove_all();
4066 wave_cache->remove_all();
4067 audio_cache->remove_all();
4068 video_cache->remove_all();
4069 if( cwindow->playback_engine ) {
4070 if( cwindow->playback_engine->audio_cache )
4071 cwindow->playback_engine->audio_cache->remove_all();
4072 if( cwindow->playback_engine->video_cache )
4073 cwindow->playback_engine->video_cache->remove_all();
4075 for(int i = 0; i < vwindows.size(); i++) {
4076 VWindow *vwindow = vwindows[i];
4077 if( !vwindow->is_running() ) continue;
4078 if( !vwindow->playback_engine ) continue;
4079 if( vwindow->playback_engine->audio_cache )
4080 vwindow->playback_engine->audio_cache->remove_all();
4081 if( vwindow->playback_engine->video_cache )
4082 vwindow->playback_engine->video_cache->remove_all();
4086 void MWindow::remove_asset_from_caches(Asset *asset)
4088 frame_cache->remove_asset(asset);
4089 wave_cache->remove_asset(asset);
4090 audio_cache->delete_entry(asset);
4091 video_cache->delete_entry(asset);
4092 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4093 cwindow->playback_engine->audio_cache->delete_entry(asset);
4094 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4095 cwindow->playback_engine->video_cache->delete_entry(asset);
4096 for(int i = 0; i < vwindows.size(); i++) {
4097 VWindow *vwindow = vwindows[i];
4098 if( !vwindow->is_running() ) continue;
4099 if( !vwindow->playback_engine ) continue;
4100 if( vwindow->playback_engine->audio_cache )
4101 vwindow->playback_engine->audio_cache->delete_entry(asset);
4102 if( vwindow->playback_engine->video_cache )
4103 vwindow->playback_engine->video_cache->delete_entry(asset);
4108 void MWindow::remove_assets_from_project(int push_undo, int redraw,
4109 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4111 awindow->gui->close_view_popup();
4113 for(int i = 0; i < drag_assets->total; i++) {
4114 Indexable *indexable = drag_assets->get(i);
4115 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
4118 // Remove from VWindow.
4119 for(int i = 0; i < session->drag_clips->total; i++) {
4120 for(int j = 0; j < vwindows.size(); j++) {
4121 VWindow *vwindow = vwindows[j];
4122 if( !vwindow->is_running() ) continue;
4123 if(session->drag_clips->get(i) == vwindow->get_edl()) {
4124 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4125 vwindow->delete_source(1, 1);
4126 vwindow->gui->unlock_window();
4131 for(int i = 0; i < drag_assets->size(); i++) {
4132 for(int j = 0; j < vwindows.size(); j++) {
4133 VWindow *vwindow = vwindows[j];
4134 if( !vwindow->is_running() ) continue;
4135 if(drag_assets->get(i) == vwindow->get_source()) {
4136 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4137 vwindow->delete_source(1, 1);
4138 vwindow->gui->unlock_window();
4143 for(int i = 0; i < drag_assets->size(); i++) {
4144 Indexable *indexable = drag_assets->get(i);
4145 remove_indexfile(indexable);
4148 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4149 if(push_undo) undo_before();
4150 if(drag_assets) edl->remove_from_project(drag_assets);
4151 if(drag_clips) edl->remove_from_project(drag_clips);
4152 if(redraw) save_backup();
4153 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4157 gui->lock_window("MWindow::remove_assets_from_project 3");
4158 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4159 gui->unlock_window();
4161 // Removes from playback here
4162 sync_parameters(CHANGE_ALL);
4165 awindow->gui->async_update_assets();
4168 void MWindow::remove_assets_from_disk()
4170 remove_assets_from_project(1,
4172 session->drag_assets,
4173 session->drag_clips);
4176 for(int i = 0; i < session->drag_assets->total; i++)
4178 remove(session->drag_assets->get(i)->path);
4182 void MWindow::dump_plugins(FILE *fp)
4184 if( !plugindb ) return;
4185 for(int i = 0; i < plugindb->total; i++)
4187 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4188 " synth=%d transition=%d theme=%d %s\n",
4189 plugindb->get(i)->plugin_type,
4190 plugindb->get(i)->audio,
4191 plugindb->get(i)->video,
4192 plugindb->get(i)->realtime,
4193 plugindb->get(i)->multichannel,
4194 plugindb->get(i)->get_synthesis(),
4195 plugindb->get(i)->transition,
4196 plugindb->get(i)->theme,
4197 plugindb->get(i)->title);
4201 void MWindow::dump_edl(FILE *fp)
4207 void MWindow::dump_undo(FILE *fp)
4213 void MWindow::dump_exe(FILE *fp)
4215 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4216 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4218 int ret = -1, n = 100;
4219 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4220 exe_path[len] = 0; strcpy(proc_path, exe_path);
4223 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4226 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4227 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4228 struct tm *tm = localtime(&st.st_mtime);
4230 strftime(mtime, sizeof(mtime), "%F %T", tm);
4231 fprintf(fp,"mtime: %s\n", mtime);
4233 // people hit ctl-c waiting for this
4234 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4235 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4238 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4239 int64_t maxsz = 1024*pagsz;
4240 int64_t size = st.st_size, pos = 0;
4242 while( (bfrsz = size-pos) > 0 ) {
4243 if( bfrsz > maxsz ) bfrsz = maxsz;
4244 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4245 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4246 if( bfr == MAP_FAILED ) break;
4247 sha1.addBytes(bfr, bfrsz);
4252 ret = pos < size ? EIO : 0;
4253 fprintf(fp, "SHA1: ");
4254 uint8_t digest[20]; sha1.computeHash(digest);
4255 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4256 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4257 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4262 void MWindow::trap_hook(FILE *fp, void *vp)
4264 MWindow *mwindow = (MWindow *)vp;
4265 // fprintf(fp, "\nPLUGINS:\n");
4266 // mwindow->dump_plugins(fp);
4267 fprintf(fp, "\nEDL:\n");
4268 mwindow->dump_edl(fp);
4269 fprintf(fp, "\nUNDO:\n");
4270 mwindow->dump_undo(fp);
4271 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4272 mwindow->dump_exe(fp);
4280 int MWindow::save_defaults()
4282 gui->save_defaults(defaults);
4283 edl->save_defaults(defaults);
4284 session->save_defaults(defaults);
4285 preferences->save_defaults(defaults);
4287 for(int i = 0; i < plugin_guis->total; i++)
4289 // Pointer comparison
4290 plugin_guis->get(i)->save_defaults();
4292 awindow->save_defaults(defaults);
4298 int MWindow::run_script(FileXML *script)
4300 int result = 0, result2 = 0;
4301 while(!result && !result2)
4303 result = script->read_tag();
4306 if(script->tag.title_is("new_project"))
4308 // Run new in immediate mode.
4309 // gui->mainmenu->new_project->run_script(script);
4312 if(script->tag.title_is("record"))
4314 // Run record as a thread. It is a terminal command.
4316 // Will read the complete scipt file without letting record read it if not
4322 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4329 // ================================= synchronization
4332 int MWindow::interrupt_indexes()
4334 mainprogress->cancelled = 1;
4335 mainindexes->interrupt_build();
4341 void MWindow::next_time_format()
4343 switch(edl->session->time_format)
4345 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4346 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4347 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4348 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4349 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4350 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4351 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4354 time_format_common();
4357 void MWindow::prev_time_format()
4359 switch(edl->session->time_format)
4361 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4362 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4363 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4364 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4365 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4366 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4367 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4370 time_format_common();
4373 void MWindow::time_format_common()
4375 gui->lock_window("MWindow::next_time_format");
4376 gui->redraw_time_dependancies();
4379 char string[BCTEXTLEN], string2[BCTEXTLEN];
4380 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4381 gui->show_message(string);
4383 gui->unlock_window();
4387 int MWindow::set_filename(const char *filename)
4389 if( filename != session->filename )
4390 strcpy(session->filename, filename);
4391 if( filename != edl->path )
4392 strcpy(edl->path, filename);
4396 if(filename[0] == 0)
4398 gui->set_title(PROGRAM_NAME);
4403 char string[BCTEXTLEN], string2[BCTEXTLEN];
4404 dir.extract_name(string, filename);
4405 sprintf(string2, PROGRAM_NAME ": %s", string);
4406 gui->set_title(string2);
4419 int MWindow::set_loop_boundaries()
4421 double start = edl->local_session->get_selectionstart();
4422 double end = edl->local_session->get_selectionend();
4430 if(edl->tracks->total_length())
4433 end = edl->tracks->total_length();
4440 if(edl->local_session->loop_playback && start != end)
4442 edl->local_session->loop_start = start;
4443 edl->local_session->loop_end = end;
4454 int MWindow::reset_meters()
4456 cwindow->gui->lock_window("MWindow::reset_meters 1");
4457 cwindow->gui->meters->reset_meters();
4458 cwindow->gui->unlock_window();
4460 for(int j = 0; j < vwindows.size(); j++) {
4461 VWindow *vwindow = vwindows[j];
4462 if( !vwindow->is_running() ) continue;
4463 vwindow->gui->lock_window("MWindow::reset_meters 2");
4464 vwindow->gui->meters->reset_meters();
4465 vwindow->gui->unlock_window();
4468 lwindow->gui->lock_window("MWindow::reset_meters 3");
4469 lwindow->gui->panel->reset_meters();
4470 lwindow->gui->unlock_window();
4472 gui->lock_window("MWindow::reset_meters 4");
4473 gui->reset_meters();
4474 gui->unlock_window();
4479 void MWindow::resync_guis()
4483 gui->lock_window("MWindow::resync_guis");
4484 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4485 gui->unlock_window();
4487 cwindow->gui->lock_window("MWindow::resync_guis");
4488 cwindow->gui->resize_event(cwindow->gui->get_w(),
4489 cwindow->gui->get_h());
4490 int channels = edl->session->audio_channels;
4491 cwindow->gui->meters->set_meters(channels, 1);
4492 cwindow->gui->flush();
4493 cwindow->gui->unlock_window();
4495 for(int i = 0; i < vwindows.size(); i++) {
4496 VWindow *vwindow = vwindows[i];
4497 if( !vwindow->is_running() ) continue;
4498 vwindow->gui->lock_window("MWindow::resync_guis");
4499 vwindow->gui->resize_event(vwindow->gui->get_w(),
4500 vwindow->gui->get_h());
4501 vwindow->gui->meters->set_meters(channels, 1);
4502 vwindow->gui->flush();
4503 vwindow->gui->unlock_window();
4506 lwindow->gui->lock_window("MWindow::resync_guis");
4507 lwindow->gui->panel->set_meters(channels, 1);
4508 lwindow->gui->flush();
4509 lwindow->gui->unlock_window();
4512 if(((edl->session->output_w % 4) ||
4513 (edl->session->output_h % 4)) &&
4514 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4516 MainError::show_error(
4517 _("This project's dimensions are not multiples of 4 so\n"
4518 "it can't be rendered by OpenGL."));
4523 sync_parameters(CHANGE_ALL);
4526 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4528 File *file = new File;
4529 EDLSession *session = edl->session;
4530 double old_framerate = session->frame_rate;
4531 double old_samplerate = session->sample_rate;
4532 int old_auto_keyframes = session->auto_keyframes;
4533 session->auto_keyframes = 0;
4534 int result = file->open_file(preferences, asset, 1, 0);
4535 if( !result && delete_tracks > 0 )
4537 int video_layers = asset->get_video_layers();
4538 if( !result && asset->video_data && vstream < video_layers ) {
4539 // try to get asset up to date, may fail
4540 file->select_video_stream(asset, vstream);
4541 // either way use what was/is there.
4542 double framerate = asset->get_frame_rate();
4543 int width = asset->get_w();
4544 int height = asset->get_h();
4545 // must be multiple of 4 for opengl
4546 width = (width+3) & ~3; height = (height+3) & ~3;
4547 int driver = session->playback_config->vconfig->driver;
4548 int color_model = file->get_best_colormodel(asset, driver);
4549 // color_model = BC_CModels::is_yuv(color_model) ?
4550 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4551 // BC_CModels::is_float(color_model) ?
4552 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4553 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4554 // have alpha for now
4555 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4556 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4557 session->color_model = color_model;
4558 session->output_w = width;
4559 session->output_h = height;
4560 session->frame_rate = framerate;
4561 // not, asset->actual_width/actual_height
4562 asset->width = session->output_w;
4563 asset->height = session->output_h;
4564 asset->frame_rate = session->frame_rate;
4565 create_aspect_ratio(session->aspect_w, session->aspect_h,
4566 session->output_w, session->output_h);
4567 Track *track = edl->tracks->first;
4568 for( Track *next_track=0; track; track=next_track ) {
4569 next_track = track->next;
4570 if( track->data_type != TRACK_VIDEO ) continue;
4571 if( delete_tracks ) {
4572 Edit *edit = track->edits->first;
4573 for( Edit *next_edit=0; edit; edit=next_edit ) {
4574 next_edit = edit->next;
4575 if( edit->channel != vstream ||
4576 !edit->asset || !edit->asset->is_asset ||
4577 !asset->equivalent(*edit->asset,1,1,edl) )
4581 if( track->edits->first ) {
4582 track->track_w = edl->session->output_w;
4583 track->track_h = edl->session->output_h;
4585 else if( delete_tracks )
4586 edl->tracks->delete_track(track);
4589 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4591 if( !result && asset->audio_data && asset->channels > 0 ) {
4592 session->sample_rate = asset->get_sample_rate();
4593 int64_t channel_mask = 0;
4594 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4595 file->get_audio_for_video(vstream, astream, channel_mask);
4596 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4597 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4599 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4600 if( channels < 1 ) channels = 1;
4601 if( channels > 6 ) channels = 6;
4602 session->audio_tracks = session->audio_channels = channels;
4604 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4605 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4606 remap_audio(MWindow::AUDIO_1_TO_1);
4608 if( delete_tracks ) {
4609 Track *track = edl->tracks->first;
4610 for( Track *next_track=0; track; track=next_track ) {
4611 next_track = track->next;
4612 if( track->data_type != TRACK_AUDIO ) continue;
4613 Edit *edit = track->edits->first;
4614 for( Edit *next_edit=0; edit; edit=next_edit ) {
4615 next_edit = edit->next;
4616 if( !((1<<edit->channel) & channel_mask) ||
4617 !edit->asset || !edit->asset->is_asset ||
4618 !asset->equivalent(*edit->asset,1,1,edl) )
4621 if( !track->edits->first )
4622 edl->tracks->delete_track(track);
4626 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4629 session->auto_keyframes = old_auto_keyframes;
4630 if( !result && delete_tracks > 0 ) {
4632 undo_after(_("select asset"), LOAD_ALL);
4638 int MWindow::select_asset(int vtrack, int delete_tracks)
4640 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4642 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4643 if( !track ) return 1;
4644 Edit *edit = track->edits->first;
4645 if( !edit ) return 1;
4646 Asset *asset = edit->asset;
4647 if( !asset || !asset->is_asset ) return 1;
4648 return select_asset(asset, edit->channel, 0, delete_tracks);
4651 void MWindow::dump_plugindb(FILE *fp)
4653 if( !plugindb ) return;
4654 for(int i = 0; i < plugindb->total; i++)
4655 plugindb->get(i)->dump(fp);
4658 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4661 double unit_position = edl->local_session->get_selectionstart(1);
4662 unit_position = patch->track->to_units(unit_position, 0);
4664 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4665 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4668 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4671 double unit_position = edl->local_session->get_selectionstart(1);
4672 unit_position = patch->track->to_units(unit_position, 0);
4674 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4675 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4678 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4681 double unit_position = edl->local_session->get_selectionstart(1);
4682 unit_position = patch->track->to_units(unit_position, 0);
4684 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4685 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4688 PatchGUI *MWindow::get_patchgui(Track *track)
4690 PatchGUI *patchgui = 0;
4691 TimelinePane **panes = gui->pane;
4692 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4693 if( !panes[i] ) continue;
4694 PatchBay *patchbay = panes[i]->patchbay;
4695 if( !patchbay ) continue;
4696 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4697 if( patchbay->patches.values[j]->track == track )
4698 patchgui = patchbay->patches.values[j];