3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
4 * Copyright (C) 2003-2016 Cinelerra CV contributors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "aboutprefs.h"
26 #include "audioalsa.h"
28 #include "awindowgui.h"
30 #include "batchrender.h"
31 #include "bccmodels.h"
32 #include "bcdisplayinfo.h"
33 #include "bcprogressbox.h"
34 #include "bcsignals.h"
41 #include "channeldb.h"
42 #include "channelinfo.h"
45 #include "commercials.h"
46 #include "confirmsave.h"
48 #include "cplayback.h"
50 #include "cwindowgui.h"
52 #include "cwindowtool.h"
54 #include "devicedvbinput.inc"
55 #include "dvdcreate.h"
56 #include "editpanel.h"
58 #include "edlsession.h"
60 #include "fileformat.h"
62 #include "filesystem.h"
64 #include "floatautos.h"
65 #include "framecache.h"
67 #include "gwindowgui.h"
68 #include "keyframegui.h"
69 #include "indexfile.h"
71 #include "interlacemodes.h"
73 #include "levelwindowgui.h"
74 #include "levelwindow.h"
75 #include "loadfile.inc"
76 #include "localsession.h"
77 #include "maincursor.h"
78 #include "mainerror.h"
79 #include "mainindexes.h"
81 #include "mainprogress.h"
82 #include "mainsession.h"
85 #include "mixersalign.h"
87 #include "mwindowgui.h"
92 #include "playback3d.h"
93 #include "playbackengine.h"
95 #include "pluginserver.h"
96 #include "pluginset.h"
97 #include "preferences.h"
100 #include "recordmonitor.h"
101 #include "recordlabel.h"
102 #include "removefile.h"
104 #include "resourcethread.h"
105 #include "savefile.inc"
106 #include "samplescroll.h"
109 #include "sighandler.h"
110 #include "splashgui.h"
111 #include "statusbar.h"
113 #include "threadloader.h"
115 #include "timelinepane.h"
116 #include "tipwindow.h"
117 #include "trackcanvas.h"
119 #include "tracking.h"
120 #include "trackscroll.h"
122 #include "transition.h"
123 #include "transportque.h"
126 #include "versioninfo.h"
128 #include "videodevice.inc"
129 #include "videowindow.h"
130 #include "vplayback.h"
131 #include "vwindowgui.h"
133 #include "wavecache.h"
139 #include "zwindowgui.h"
140 #include "exportedl.h"
142 #include "defaultformats.h"
143 #include "ntsczones.h"
150 #include <sys/types.h>
151 #include <sys/stat.h>
152 #include <sys/time.h>
153 #include <sys/mman.h>
154 #include <sys/file.h>
165 // Hack for libdv to remove glib dependancy
168 // g_log (const char *log_domain,
170 // const char *format,
176 // g_logv (const char *log_domain,
178 // const char *format,
186 extern long cin_timezone;
188 ArrayList<PluginServer*>* MWindow::plugindb = 0;
189 Commercials* MWindow::commercials = 0;
195 run_lock = new Mutex("MWindow::run_lock");
196 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
197 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
198 vwindows_lock = new Mutex("MWindow::vwindows_lock");
199 zwindows_lock = new Mutex("MWindow::zwindows_lock");
200 brender_lock = new Mutex("MWindow::brender_lock");
201 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
206 undo_command = COMMAND_NONE;
210 commercial_active = 0;
222 strcpy(cin_lang,"en");
223 channeldb_buz = new ChannelDB;
224 channeldb_v4l2jpeg = new ChannelDB;
227 keyframe_threads = 0;
255 // Need to delete brender temporary here.
258 run_lock->lock("MWindow::~MWindow");
260 //printf("MWindow::~MWindow %d\n", __LINE__);
261 if( wwindow && wwindow->is_running() )
262 wwindow->close_window();
263 if( twindow && twindow->is_running() )
264 twindow->close_window();
265 gui->remote_control->deactivate();
268 gui->channel_info->stop();
270 delete beeper; beeper = 0;
271 delete redraw_tracks; redraw_tracks = 0;
272 delete create_bd; create_bd = 0;
273 delete create_dvd; create_dvd = 0;
275 delete shuttle; shuttle = 0;
278 delete wintv; wintv = 0;
281 delete x10tv; x10tv = 0;
283 delete batch_render; batch_render = 0;
284 delete convert_render; convert_render = 0;
285 delete render; render = 0;
286 delete mixers_align; mixers_align = 0;
287 #ifdef HAVE_COMMERCIALS
289 if( commercials && !commercials->remove_user() ) commercials = 0;
292 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
293 // Save defaults for open plugins
294 plugin_gui_lock->lock("MWindow::~MWindow");
295 for(int i = 0; i < plugin_guis->size(); i++) {
296 plugin_guis->get(i)->hide_gui();
297 delete_plugin(plugin_guis->get(i));
299 plugin_gui_lock->unlock();
300 hide_keyframe_guis();
304 // Give up and go to a movie
305 // cant run valgrind if this is used
307 gui->del_keyboard_listener(
308 (int (BC_WindowBase::*)(BC_WindowBase *))
309 &MWindowGUI::keyboard_listener);
312 // release the hounds
313 if( awindow && awindow->gui ) awindow->gui->close(0);
314 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
315 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
316 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
317 vwindows.remove_all_objects();
318 zwindows.remove_all_objects();
320 if( awindow ) awindow->join();
321 if( cwindow ) cwindow->join();
322 if( lwindow ) lwindow->join();
323 if( gwindow ) gwindow->join();
326 // one at a time, or nouveau chokes
327 #define close_gui(win) if( win ) { \
328 if( win->gui ) win->gui->close(0); \
334 vwindows.remove_all_objects();
335 zwindows.remove_all_objects();
339 dead_plugins->remove_all_objects();
340 // must delete theme before destroying plugindb
341 // theme destructor will be deleted by delete_plugins
342 delete theme; theme = 0;
345 keyframe_threads->remove_all_objects();
346 colormodels.remove_all_objects();
347 delete awindow; awindow = 0;
348 delete lwindow; lwindow = 0;
349 delete twindow; twindow = 0;
350 delete wwindow; wwindow = 0;
351 delete gwindow; gwindow = 0;
352 delete cwindow; cwindow = 0;
354 delete mainindexes; mainindexes = 0;
355 delete mainprogress; mainprogress = 0;
356 // delete the caches after the assets
357 if( audio_cache ) { audio_cache->remove_user(); audio_cache = 0; }
358 if( video_cache ) { video_cache->remove_user(); video_cache = 0; }
359 delete frame_cache; frame_cache = 0;
360 delete wave_cache; wave_cache = 0;
361 delete plugin_guis; plugin_guis = 0;
362 delete dead_plugins; dead_plugins = 0;
363 delete keyframe_threads; keyframe_threads = 0;
364 delete undo; undo = 0;
365 delete preferences; preferences = 0;
366 delete exportedl; exportedl = 0;
367 delete session; session = 0;
368 delete defaults; defaults = 0;
369 delete assets; assets = 0;
370 delete splash_window; splash_window = 0;
371 if( !edl->Garbage::remove_user() ) edl = 0;
372 delete channeldb_buz;
373 delete channeldb_v4l2jpeg;
374 // This must be last thread to exit
375 delete playback_3d; playback_3d = 0;
376 delete dead_plugin_lock;
377 delete plugin_gui_lock;
378 delete vwindows_lock;
379 delete zwindows_lock;
381 delete keyframe_gui_lock;
382 colormodels.remove_all_objects();
383 interlace_project_modes.remove_all_objects();
384 interlace_asset_modes.remove_all_objects();
385 sighandler->terminate();
396 void MWindow::init_error()
398 MainError::init_error(this);
401 void MWindow::finit_error()
403 MainError::finit_error();
406 void MWindow::create_defaults_path(char *string, const char *config_file)
408 // set the .bcast path
411 sprintf(string, "%s/", File::get_config_path());
412 fs.complete_path(string);
413 if(!fs.is_dir(string))
414 fs.create_dir(string);
417 strcat(string, config_file);
419 const char *MWindow::default_std()
421 char buf[BCTEXTLEN], *p = 0;
423 int fd = open(TIMEZONE_NAME, O_RDONLY);
425 int l = read(fd, buf, sizeof(buf)-1);
428 if( buf[l-1] == '\n' ) --l;
434 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
437 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
438 p += strlen(ZONEINFO_STR);
443 for( int i=0; ntsc_zones[i]; ++i ) {
444 if( !strcmp(ntsc_zones[i], p) )
451 for( int i=0; ntsc_zones[i]; ++i ) {
452 if( !strcmp(ntsc_zones[i], p) )
457 // cin_timezone: Seconds west of UTC. 240sec/deg
458 double tz_deg = -cin_timezone / 240.;
459 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
460 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
463 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
465 struct formatpresets *fpr;
467 for(fpr = &format_presets[0]; fpr->name; fpr++)
469 if(strcmp(_(fpr->name), preset) == 0)
471 session->audio_channels = fpr->audio_channels;
472 session->audio_tracks = fpr->audio_tracks;
473 session->sample_rate = fpr->sample_rate;
474 session->video_channels = fpr->video_channels;
475 session->video_tracks = fpr->video_tracks;
476 session->frame_rate = fpr->frame_rate;
477 session->output_w = fpr->output_w;
478 session->output_h = fpr->output_h;
479 session->aspect_w = fpr->aspect_w;
480 session->aspect_h = fpr->aspect_h;
481 session->interlace_mode = fpr->interlace_mode;
482 session->color_model = fpr->color_model;
488 const char *MWindow::get_preset_name(int index)
490 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
492 return _(format_presets[index].name);
496 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
498 char path[BCTEXTLEN];
499 // Use user supplied path
501 strcpy(path, config_path);
503 create_defaults_path(path, CONFIG_FILE);
506 defaults = new BC_Hash(path);
511 void MWindow::check_language()
513 char pref_locale[BCSTRLEN];
514 strcpy(pref_locale, DEFAULT_LOCALE);
515 defaults->get("LOCALE",pref_locale);
516 // set LANGUAGE if pref locale != sys
517 if( strcmp(pref_locale, DEFAULT_LOCALE) )
518 setenv("LANGUAGE", pref_locale, 1);
520 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
521 const char *env_lang = getenv("LANGUAGE");
522 if( !env_lang ) env_lang = getenv("LC_ALL");
523 if( !env_lang ) env_lang = getenv("LANG");
525 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
526 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
527 env_lang = curr_lang;
529 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
530 defaults->get("LAST_LANG",last_lang);
531 if( strcmp(env_lang,last_lang)) {
532 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
533 defaults->update("LAST_LANG",env_lang);
534 char plugin_path[BCTEXTLEN];
535 create_defaults_path(plugin_path, PLUGIN_FILE);
536 ::remove(plugin_path);
537 char ladspa_path[BCTEXTLEN];
538 create_defaults_path(ladspa_path, LADSPA_FILE);
539 ::remove(ladspa_path);
542 if( strlen(env_lang) > 1 &&
543 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
544 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
547 strcpy(cin_lang, "en");
550 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
552 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
554 const char *dp = plug_dir;
555 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
556 bp = !*dp && *bp == '/' ? bp+1 : base_path;
563 * @brief Load plugins according to an index file.
565 * @details Builds an ArrayList of plugin servers only if there is no
566 * mismatch for file layout version, index identifier, or timestamp of
567 * the built-in plugins. If OK, add the plugin servers to the global list.
569 * @note If an error is returned the index file needs to be rebuilt, and
570 * then this function must be called again.
571 * There are two types of index files, with the same layout internally.
572 * One called "Cinelerra_plugins" for built-ins, ffmpeg and lv2 .
573 * The other type "ladspa_plugins.index_id" where index_id is either the
574 * path or the $CIN_BUILD identifier if the path is from the running
575 * AppImage itself. If there are multiple ladspa directories in the
576 * path, there will be multiple index files.
578 * @return -1 if file no open, 0 if OK, 1 if error.
580 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir, const char *index_id)
584 fstat (fileno(fp), &st); // don't bother if the file has just been created.
585 if( st.st_size < 4 ) return 1;
588 fseek(fp, 0, SEEK_SET);
590 char index_line[BCTEXTLEN];
591 int index_version = -1, len = strlen(index_id);
592 if( !fgets(index_line, BCTEXTLEN, fp) ||
593 sscanf(index_line, "%d", &index_version) != 1 ||
594 index_version != PLUGIN_FILE_VERSION ||
595 !fgets(index_line, BCTEXTLEN, fp) ||
596 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
597 strncmp(index_line, index_id, len) != 0 ) {
598 // printf("index file mismatch, version %d, index id length %d, expected id %s, file id %s\n", index_version, len, index_id, index_line);
602 ArrayList<PluginServer*> plugins;
603 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
604 if( index_line[0] == ';' ) continue;
605 if( index_line[0] == '#' ) continue;
606 int type = PLUGIN_TYPE_UNKNOWN;
607 char path[BCTEXTLEN], title[BCTEXTLEN];
609 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
610 // printf("PluginServer::scan_table failed for %s\n", index_line);
613 PluginServer *server = 0;
615 case PLUGIN_TYPE_BUILTIN:
616 case PLUGIN_TYPE_EXECUTABLE:
617 case PLUGIN_TYPE_LADSPA: {
618 char plugin_path[BCTEXTLEN]; struct stat st;
619 sprintf(plugin_path, "%s/%s", plugin_dir, path);
620 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
621 // printf("Plugin %s index time %ld, file time %ld\n", plugin_path, mtime, st.st_mtime);
624 server = new PluginServer(mwindow, plugin_path, type);
626 case PLUGIN_TYPE_FFMPEG: {
627 server = new_ffmpeg_server(mwindow, path);
629 case PLUGIN_TYPE_LV2: {
630 server = new_lv2_server(mwindow, path);
633 if( !server ) continue;
634 plugins.append(server);
635 // Create plugin server from index entry
636 server->set_title(title);
637 if( server->read_table(index_line) ) {
638 // printf("server->read_table failed for title %s, %s\n", title, index_line);
644 ret = check_plugin_index(plugins, plugin_dir, ".");
647 add_plugins(plugins);
649 plugins.remove_all_objects();
654 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
655 const char *plug_dir, const char *plug_path)
657 char plugin_path[BCTEXTLEN];
658 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
660 fs.set_filter( "[*.plugin][*.so]" );
661 if( fs.update(plugin_path) )
664 for( int i=0; i<fs.dir_list.total; ++i ) {
665 char fs_path[BCTEXTLEN];
666 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
667 if( fs.is_dir(fs_path) ) {
668 get_plugin_path(plugin_path, plug_dir, fs_path);
669 if( check_plugin_index(plugins, plug_dir, plugin_path) )
672 else if( !plugin_exists(fs_path, plugins) )
679 * @brief Load built-in and LV2 plugins as specified in index file,
680 * rebuild the index file if needed.
681 * @param[in] mwindow: GUI class pointer, will be NULL for batch
682 * rendering or renderfarm client.
683 * @param[in] preferences: Information from cinelerra_rc file.
685 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
688 plugindb = new ArrayList<PluginServer*>;
690 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN], index_id[BCTEXTLEN];
691 create_defaults_path(index_path, PLUGIN_FILE);
692 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
693 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
694 // index_id is 2nd line of the index file, normally full plugin path,
695 // but fixed value if AppImage because the path changes on each run.
696 // And if the second line does not match on the next run the index is rebuilt.
697 if( getenv("APPDIR") && getenv("CINGG_BUILD")) strcpy(index_id, getenv("CINGG_BUILD"));
698 else strcpy(index_id, plugin_path);
699 FILE *fp = fopen(index_path,"a+");
701 fprintf(stderr,_("MWindow::init_plugins: "
702 "can't open plugin index: %s\n"), index_path);
705 int fd = fileno(fp), ret = -1;
706 if( !flock(fd, LOCK_EX) ) {
707 fseek(fp, 0, SEEK_SET);
708 ret = load_plugin_index(mwindow, fp, plugin_path, index_id);
712 fseek(fp, 0, SEEK_SET);
713 printf("build plugin index for: %s\n", plugin_path);
714 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
715 fprintf(fp, "%s\n", index_id);
716 init_plugin_index(mwindow, preferences, fp, plugin_path);
717 init_ffmpeg_index(mwindow, preferences, fp);
718 init_lv2_index(mwindow, preferences, fp);
719 fseek(fp, 0, SEEK_SET);
720 ret = load_plugin_index(mwindow, fp, plugin_path, index_id);
723 fprintf(stderr,_("MWindow::init_plugins: "
724 "can't %s plugin index: %s\n"),
725 ret>0 ? _("create") : _("lock"), index_path);
732 * @brief Load ladspa plugins as specified in index files, for each ladspa
733 * directory keep a separate index file. Rebuild index file(s) if needed.
734 * @param[in] mwindow: GUI class pointer, will be NULL for batch
735 * rendering or renderfarm client.
736 * @param[in] preferences: Information from cinelerra_rc file.
738 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
741 char *path = getenv("LADSPA_PATH");
742 char *appdir = getenv("APPDIR");
743 char ladspa_path[BCTEXTLEN];
744 if( !path ) { // if no env var, use CinGG's own ladspa dir
745 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
748 for( int len=0; *path; path+=len ) {
749 char *cp = strchr(path,':');
750 len = !cp ? strlen(path) : cp-path;
751 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN], index_id[BCTEXTLEN];
752 memcpy(plugin_path, path, len); plugin_path[len] = 0;
754 char *plugin_dir = FileSystem::basepath(plugin_path);
755 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
756 create_defaults_path(index_path, LADSPA_FILE);
757 cp = index_path + strlen(index_path);
758 // If the first part of the plugin_path matches the APPDIR, we are
759 // referring to CinGG's ladspa, replace the path by a fixed ID. APPDIR
760 // only exists if we are running as AppImage (with variable mount points).
761 if( appdir && strncmp(plugin_path, appdir, strlen(appdir)) == 0 )
762 strcpy(index_id, getenv("CINGG_BUILD"));
763 else strcpy(index_id, plugin_path);
765 // Concatenate the path, replacing '/' with '_'.
766 for( char *bp=index_id; *bp!=0; ++bp )
767 *cp++ = *bp=='/' ? '_' : *bp;
769 FILE *fp = fopen(index_path,"a+");
771 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
772 "can't open ladspa plugin index: %s\n"), index_path);
775 int fd = fileno(fp), ret = -1;
776 if( !flock(fd, LOCK_EX) ) {
777 fseek(fp, 0, SEEK_SET);
778 ret = load_plugin_index(mwindow, fp, plugin_path, index_id);
782 fseek(fp, 0, SEEK_SET);
783 printf("build ladspa plugin index for: %s\n", plugin_path);
784 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
785 fprintf(fp, "%s\n", index_id);
786 init_plugin_index(mwindow, preferences, fp, plugin_path);
787 fseek(fp, 0, SEEK_SET);
788 ret = load_plugin_index(mwindow, fp, plugin_path, index_id);
791 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
792 "can't %s ladspa plugin index: %s\n"),
793 ret>0 ? _("create") : _("lock"), index_path);
801 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
802 FILE *fp, const char *plugin_dir)
804 int idx = PLUGIN_IDS;
806 for( int i=0; i<plugindb->size(); ++i ) {
807 PluginServer *server = plugindb->get(i);
808 if( server->dir_idx >= idx )
809 idx = server->dir_idx+1;
812 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
815 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
816 const char *plug_dir, const char *plug_path, int &idx)
818 char plugin_path[BCTEXTLEN];
819 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
821 fs.set_filter( "[*.plugin][*.so][*.dll]" );
822 int result = fs.update(plugin_path);
823 if( result || !fs.dir_list.total ) return;
826 for( int i=0; i<fs.dir_list.total; ++i ) {
827 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
828 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
829 get_plugin_path(path, plug_dir, fs_path);
830 if( fs.is_dir(fs_path) ) { // recursively scan child directory
831 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
834 if( plugin_exists(path) ) continue;
836 if( stat(fs_path, &st) ) continue;
837 int64_t mtime = st.st_mtime;
838 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
839 result = server.open_plugin(1, preferences, 0, 0);
841 server.write_table(fp, path, vis_id, mtime);
842 server.close_plugin();
844 else if( result == PLUGINSERVER_IS_LAD ) {
847 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
848 ladspa.set_lad_index(lad_index++);
849 result = ladspa.open_plugin(1, preferences, 0, 0);
851 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
852 ladspa.close_plugin();
858 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
860 for( int i=0; i<plugins.size(); ++i )
861 plugindb->append(plugins[i]);
862 plugins.remove_all();
865 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
867 const char *dat_path = File::get_cindat_path();
868 char msg_path[BCTEXTLEN];
870 if( BC_Resources::language[0] ) {
871 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
873 fp = fopen(msg_path, "r");
876 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
878 fp = fopen(msg_path, "r");
881 char text[BCTEXTLEN];
882 char *tp = text, *ep = tp + sizeof(text)-1;
883 char title[BCTEXTLEN];
888 char line[BCTEXTLEN], *cp = line;
889 if( fgets(line,sizeof(line)-1,fp) ) {
890 if( *cp == '#' ) continue;
891 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
894 if( tp > text && *--tp == '\n' ) *tp = 0;
896 int idx = plugins.size();
897 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
899 delete [] plugins[idx]->tip;
900 plugins[idx]->tip = cstrdup(text);
904 if( done > 0 ) break;
906 char *dp = strchr(cp, ':');
908 printf("plugin tips: error on line %d\n", no);
912 while( cp < dp ) *bp++ = *cp++;
917 while( *cp == ' ' || *cp == '\t' ) ++cp;
918 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
923 void MWindow::delete_plugins()
925 plugindb->remove_all_objects();
930 void MWindow::search_plugindb(int do_audio,
935 ArrayList<PluginServer*> &results)
938 for(int i = 0; i < MWindow::plugindb->total; i++)
940 PluginServer *current = MWindow::plugindb->get(i);
942 if(current->audio == do_audio &&
943 current->video == do_video &&
944 (current->realtime == is_realtime || is_realtime < 0) &&
945 current->transition == is_transition &&
946 current->theme == is_theme)
947 results.append(current);
950 // Alphabetize list by title
956 for(int i = 0; i < results.total - 1; i++)
958 PluginServer *value1 = results[i];
959 PluginServer *value2 = results[i + 1];
960 if(strcmp(_(value1->title), _(value2->title)) > 0)
964 results[i + 1] = value1;
970 PluginServer* MWindow::scan_plugindb(char *title,
975 // printf("MWindow::scan_plugindb data_type < 0\n");
979 for(int i = 0; i < plugindb->total; i++)
981 PluginServer *server = plugindb->get(i);
983 !strcasecmp(server->title, title) &&
985 (data_type == TRACK_AUDIO && server->audio) ||
986 (data_type == TRACK_VIDEO && server->video)))
987 return plugindb->get(i);
992 // repair session files with xlated plugin titles
993 void MWindow::fix_plugin_title(char *title)
995 for(int i = 0; i < plugindb->total; i++) {
996 PluginServer *server = plugindb->get(i);
997 if( !server->title ) continue;
998 const char *server_title = server->title;
999 if( !bstrcasecmp(title, _(server_title)) ) {
1000 strcpy(title, server_title);
1006 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
1008 for( int i=0; i<plugins.size(); ++i )
1009 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
1013 int MWindow::plugin_exists(char *plugin_path)
1015 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
1018 void MWindow::remove_plugin_index()
1020 char index_path[BCTEXTLEN];
1021 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
1022 ::remove(index_path);
1025 void MWindow::init_preferences()
1027 preferences = new Preferences;
1028 preferences->load_defaults(defaults);
1029 File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
1030 session = new MainSession(this);
1031 session->load_defaults(defaults);
1032 // set x11_host, screens, window_config
1033 screens = session->set_default_x11_host();
1034 BC_Signals::set_trap_hook(trap_hook, this);
1035 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
1036 BC_Signals::set_catch_intr(preferences->trap_sigintr);
1037 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
1038 BC_Trace::enable_locks();
1041 BC_Trace::disable_locks();
1043 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
1044 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
1045 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
1046 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
1049 void MWindow::clean_backups()
1054 int oldest_item = -1;
1055 char string[BCTEXTLEN];
1057 // Delete extra backups
1058 fs.set_filter("backup*.prev_*");
1059 fs.complete_path(preferences->index_directory);
1060 fs.update(preferences->index_directory);
1062 // set to 50 for now
1063 // total_excess = fs.dir_list.total - preferences->index_count;
1064 total_excess = fs.dir_list.total - 50;
1065 printf("Total excess of backups: %i \n", total_excess);
1067 //printf("MWindow::clean_backups 1 %d\n", fs.dir_list.total);
1069 while(total_excess > 0)
1072 for(int i = 0; i < fs.dir_list.total; i++)
1074 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1076 if(i == 0 || fs.get_date(string) <= oldest)
1078 oldest = fs.get_date(string);
1083 if(oldest_item >= 0)
1085 // Remove backup file
1086 fs.join_names(string,
1087 preferences->index_directory,
1088 fs.dir_list[oldest_item]->name);
1089 //printf("MWindow::clean_backups 1 %s\n", string);
1091 perror("delete_backups");
1092 delete fs.dir_list[oldest_item];
1093 fs.dir_list.remove_number(oldest_item);
1101 void MWindow::clean_indexes()
1106 int oldest_item = -1;
1108 char string[BCTEXTLEN];
1109 char string2[BCTEXTLEN];
1111 // Delete extra indexes
1112 fs.set_filter("*.idx");
1113 fs.complete_path(preferences->index_directory);
1114 fs.update(preferences->index_directory);
1115 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
1117 // Eliminate directories
1122 for(int i = 0; i < fs.dir_list.total && !result; i++)
1124 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1125 if(fs.is_dir(string))
1127 delete fs.dir_list[i];
1128 fs.dir_list.remove_number(i);
1133 total_excess = fs.dir_list.total - preferences->index_count;
1135 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
1136 while(total_excess > 0)
1139 for(int i = 0; i < fs.dir_list.total; i++)
1141 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1143 if(i == 0 || fs.get_date(string) <= oldest)
1145 oldest = fs.get_date(string);
1150 if(oldest_item >= 0)
1152 // Remove index file
1153 fs.join_names(string,
1154 preferences->index_directory,
1155 fs.dir_list[oldest_item]->name);
1156 //printf("MWindow::clean_indexes 1 %s\n", string);
1158 perror("delete_indexes");
1159 delete fs.dir_list[oldest_item];
1160 fs.dir_list.remove_number(oldest_item);
1162 // Remove table of contents if it exists
1163 strcpy(string2, string);
1164 char *ptr = strrchr(string2, '.');
1167 //printf("MWindow::clean_indexes 2 %s\n", string2);
1168 sprintf(ptr, ".toc");
1170 sprintf(ptr, ".mkr");
1179 void MWindow::init_awindow()
1181 awindow = new AWindow(this);
1182 awindow->create_objects();
1185 void MWindow::init_gwindow()
1187 gwindow = new GWindow(this);
1188 gwindow->create_objects();
1191 void MWindow::init_tipwindow()
1193 TipWindow::load_tips(cin_lang);
1195 twindow = new TipWindow(this);
1199 void MWindow::show_warning(int *do_warning, const char *text)
1201 if( do_warning && !*do_warning ) return;
1203 wwindow = new WWindow(this);
1204 wwindow->show_warning(do_warning, text);
1207 int MWindow::wait_warning()
1209 return wwindow->wait_result();
1212 void MWindow::init_theme()
1217 PluginServer *theme_plugin = 0;
1218 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1219 if( plugindb->get(i)->theme &&
1220 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1221 theme_plugin = plugindb->get(i);
1225 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1226 preferences->theme);
1228 const char *default_theme = DEFAULT_THEME;
1229 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1230 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1232 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1233 if( plugindb->get(i)->theme &&
1234 !strcasecmp(default_theme, plugindb->get(i)->title) )
1235 theme_plugin = plugindb->get(i);
1240 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1244 PluginServer *plugin = new PluginServer(*theme_plugin);
1245 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1246 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1247 theme_plugin->title);
1251 theme = plugin->new_theme();
1252 theme->mwindow = this;
1253 strcpy(theme->path, plugin->path);
1256 // Load default images & settings
1257 theme->Theme::initialize();
1258 // Load user images & settings
1259 theme->initialize();
1260 // Create menus with user colors
1261 theme->build_menus();
1264 theme->sort_image_sets();
1265 theme->check_used();
1266 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1269 void MWindow::init_3d()
1271 playback_3d = new Playback3D(this);
1272 playback_3d->create_objects();
1275 void MWindow::init_edl()
1278 edl->create_objects();
1279 fill_preset_defaults(default_standard, edl->session);
1280 edl->load_defaults(defaults);
1281 edl->session->brender_start = edl->session->brender_end = 0;
1282 edl->create_default_tracks();
1283 edl->tracks->update_y_pixels(theme);
1286 void MWindow::init_compositor()
1288 cwindow = new CWindow(this);
1289 cwindow->create_objects();
1292 void MWindow::init_levelwindow()
1294 lwindow = new LevelWindow(this);
1295 lwindow->create_objects();
1298 VWindow *MWindow::get_viewer(int start_it, int idx)
1300 vwindows_lock->lock("MWindow::get_viewer");
1301 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1302 if( !vwindow ) idx = vwindows.size();
1303 while( !vwindow && --idx >= 0 ) {
1304 VWindow *vwin = vwindows[idx];
1305 if( !vwin->is_running() || !vwin->get_edl() )
1309 vwindow = new VWindow(this);
1310 vwindow->load_defaults();
1311 vwindow->create_objects();
1312 vwindows.append(vwindow);
1314 vwindows_lock->unlock();
1315 if( start_it ) vwindow->start();
1319 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1321 zwindows_lock->lock("MWindow::get_mixer");
1322 if( !mixer ) mixer = edl->mixers.new_mixer();
1323 ZWindow *zwindow = 0;
1324 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1325 ZWindow *zwdw = zwindows[i];
1326 if( zwdw->running() ) continue;
1327 if( zwdw->idx >= 0 ) continue;
1328 zwindow = zwindows[i];
1331 zwindows.append(zwindow = new ZWindow(this));
1332 zwindow->idx = mixer->idx;
1333 zwindows_lock->unlock();
1337 ZWindow *MWindow::get_mixer(int idx)
1339 ZWindow *zwindow = 0;
1340 zwindows_lock->lock("MWindow::get_mixer");
1341 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1342 ZWindow *zwdw = zwindows[i];
1343 if( !zwdw->running() ) continue;
1344 if( zwdw->idx != idx ) continue;
1345 zwindow = zwindows[i];
1347 zwindows_lock->unlock();
1351 void MWindow::close_mixer(ZWindow *zwindow)
1353 zwindows_lock->lock("MWindow::close_mixer 0");
1354 if( session->selected_zwindow >= 0 ) {
1355 int i = zwindows.number_of(zwindow);
1356 if( i >= 0 && i < session->selected_zwindow )
1357 --session->selected_zwindow;
1358 else if( i == session->selected_zwindow )
1359 session->selected_zwindow = -1;
1361 zwindows_lock->unlock();
1362 gui->lock_window("MWindow::close_mixer 1");
1363 gui->update_mixers(0, -1);
1364 gui->unlock_window();
1367 void MWindow::start_mixer()
1370 ZWindow *zwindow = get_mixer(mixer);
1371 const char *title = 0;
1373 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1374 PatchGUI *patchgui = get_patchgui(track);
1375 if( !patchgui || !patchgui->mixer ) continue;
1376 mixer->mixer_ids.append(track->get_mixer_id());
1377 if( !title ) title = track->title;
1380 session->selected_zwindow = -1;
1381 gui->lock_window("MWindow::start_mixer");
1382 gui->update_mixers(0, 0);
1383 gui->unlock_window();
1385 zwindow->set_title(title);
1390 int MWindow::mixer_track_active(Track *track)
1392 int i = session->selected_zwindow;
1393 if( i < 0 || i >= zwindows.size() ) return 0;
1394 ZWindow *zwindow = zwindows[i];
1395 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1396 if( !mixer ) return 0;
1397 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1398 return n >= 0 ? 1 : 0;
1401 void MWindow::update_mixer_tracks()
1403 zwindows_lock->lock("MixPatch::handle_event");
1404 int i = session->selected_zwindow;
1405 if( i >= 0 && i < zwindows.size() ) {
1406 ZWindow *zwindow = zwindows[i];
1407 zwindow->update_mixer_ids();
1409 zwindows_lock->unlock();
1412 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1413 int use_inout, int toggle_audio, int loop_play, float speed)
1415 zwindows_lock->lock("MWindow::handle_mixers");
1416 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1417 ZWindow *zwindow = zwindows[vidx];
1418 if( zwindow->idx < 0 ) continue;
1419 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1420 if( !mixer || !mixer->mixer_ids.size() ) continue;
1422 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1423 if( track->data_type != TRACK_VIDEO ) continue;
1424 int mixer_id = track->get_mixer_id();
1425 k = mixer->mixer_ids.size();
1426 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1428 if( k < 0 ) continue;
1429 EDL *mixer_edl = new EDL(this->edl);
1430 mixer_edl->create_objects();
1431 mixer_edl->copy_all(edl);
1432 mixer_edl->remove_vwindow_edls();
1433 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1434 k = mixer->mixer_ids.size();
1435 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1438 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1441 track->armed = track->play = 0;
1443 zwindow->change_source(mixer_edl);
1444 zwindow->handle_mixer(command, 0,
1445 use_inout, toggle_audio, loop_play, speed);
1447 zwindows_lock->unlock();
1450 void MWindow::refresh_mixers(int dir)
1452 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1453 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1456 void MWindow::stop_mixers()
1458 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1459 ZWindow *zwindow = zwindows[vidx];
1460 if( zwindow->idx < 0 ) continue;
1461 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1465 void MWindow::close_mixers(int result)
1467 ArrayList<ZWindow*> closed;
1468 zwindows_lock->lock("MWindow::close_mixers");
1469 for( int i=zwindows.size(); --i>=0; ) {
1470 ZWindow *zwindow = zwindows[i];
1471 if( zwindow->idx < 0 ) continue;
1473 ZWindowGUI *zgui = zwindow->zgui;
1474 zgui->lock_window("MWindow::select_zwindow 0");
1475 zgui->set_done(result);
1476 zgui->unlock_window();
1477 closed.append(zwindow);
1479 zwindows_lock->unlock();
1480 for( int i=0; i<closed.size(); ++i ) {
1481 ZWindow *zwindow = closed[i];
1486 ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
1488 ArrayList<Indexable*> new_assets;
1489 new_assets.append(indexable);
1490 Track *track = edl->tracks->last;
1491 load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
1492 track = !track ? edl->tracks->first : track->next;
1494 ZWindow *zwindow = get_mixer(mixer);
1496 track->play = track->armed = 0;
1497 if( track->data_type == TRACK_VIDEO ) {
1498 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1500 mixer->mixer_ids.append(track->get_mixer_id());
1501 track = track->next;
1503 if( indexable->is_asset ) {
1504 char *path = indexable->path;
1505 char *tp = strrchr(path, '/');
1506 if( !tp ) tp = path; else ++tp;
1507 zwindow->set_title(tp);
1510 char *title = ((EDL*)indexable)->local_session->clip_title;
1511 zwindow->set_title(title);
1516 void MWindow::create_mixers(double position)
1518 if( !session->drag_assets->size() &&
1519 !session->drag_clips->size() ) return;
1523 ArrayList<ZWindow *>new_mixers;
1525 for( int i=0; i<session->drag_assets->size(); ++i ) {
1526 Indexable *indexable = session->drag_assets->get(i);
1527 if( !indexable->have_video() ) continue;
1528 ZWindow *zwindow = create_mixer(indexable, position);
1529 new_mixers.append(zwindow);
1531 for( int i=0; i<session->drag_clips->size(); ++i ) {
1532 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1533 if( !indexable->have_video() ) continue;
1534 ZWindow *zwindow = create_mixer(indexable, position);
1535 new_mixers.append(zwindow);
1539 for( int i=0; i<new_mixers.size(); ++i )
1540 new_mixers[i]->start();
1544 undo_after(_("create mixers"), LOAD_ALL);
1546 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1547 sync_parameters(CHANGE_ALL);
1550 void MWindow::open_mixers()
1552 for( int i=0; i<edl->mixers.size(); ++i ) {
1553 Mixer *mixer = edl->mixers[i];
1554 ZWindow *zwindow = get_mixer(mixer);
1555 zwindow->set_title(mixer->title);
1561 int MWindow::select_zwindow(ZWindow *zwindow)
1563 int ret = 0, n = zwindows.number_of(zwindow);
1564 if( session->selected_zwindow != n ) {
1565 session->selected_zwindow = n;
1566 for( int i=0; i<zwindows.size(); ++i ) {
1567 ZWindow *zwindow = zwindows[i];
1568 if( zwindow->idx < 0 ) continue;
1569 ZWindowGUI *zgui = zwindow->zgui;
1570 zgui->lock_window("MWindow::select_zwindow 0");
1571 zwindow->highlighted = i == n ? 1 : 0;
1572 if( zgui->draw_overlays() )
1573 zgui->canvas->get_canvas()->flash(1);
1574 zgui->unlock_window();
1577 gui->lock_window("MWindow::select_window 1");
1578 gui->update_mixers(0, -1);
1579 gui->unlock_window();
1584 void MWindow::tile_mixers()
1586 int x1 = session->tile_mixers_x;
1587 int y1 = session->tile_mixers_y;
1588 int x2 = x1 + session->tile_mixers_w;
1589 int y2 = y1 + session->tile_mixers_h;
1590 tile_mixers(x1, y1, x2, y2);
1593 void MWindow::tile_mixers(int x1, int y1, int x2, int y2)
1595 if( x1 == x2 || y1 == y2 ) {
1596 // use top left quadrent
1597 int sw = gui->get_screen_w(1, -1);
1598 int sh = gui->get_screen_w(1, -1);
1600 x2 = sw/2; y2 = sh/2;
1603 if( x1 > x2 ) { int t = x1; x1 = x2; x2 = t; }
1604 if( y1 > y2 ) { int t = y1; y1 = y2; y2 = t; }
1606 int ow = edl->session->output_w, oh = edl->session->output_h;
1608 for( int i=0; i<zwindows.size(); ++i ) {
1609 ZWindow *zwindow = zwindows[i];
1610 if( zwindow->idx < 0 ) continue;
1614 int lt = BC_DisplayInfo::get_left_border();
1615 int top = BC_DisplayInfo::get_top_border();
1616 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1617 int bh = top + BC_DisplayInfo::get_bottom_border();
1618 int mw = xS(10+10), mh = yS(10+10); // canvas margins
1619 int dx = x2 - x1, dy = y2 - y1;
1620 int64_t sz = dx * dy, best_r = sz;
1621 int bx = 1, by = nz;
1622 for( int nx=1; nx<=nz; ++nx ) {
1623 int ny = ceil((double)nz / nx);
1626 int hh = (ww - mw) * oh / ow + mh;
1628 int64_t za = zw*nx * zh*ny;
1629 int64_t r = sz - za;
1630 if( r < 0 ) continue;
1631 if( r >= best_r ) continue;
1635 for( int ny=1; ny<=nz; ++ny ) {
1636 int nx = ceil((double)nz / ny);
1639 int ww = (hh - mh) * ow / oh + mw;
1641 int64_t za = zw*nx * zh*ny;
1642 int64_t r = sz - za;
1643 if( r < 0 ) continue;
1644 if( r >= best_r ) continue;
1652 ww = (hh - mh) * ow / oh + mw;
1658 hh = (ww - mw) * oh / ow + mh;
1662 int zx = 0, zy = 0; // window origins
1664 for( int i=0; i<zwindows.size(); ++i ) {
1665 ZWindow *zwindow = zwindows[i];
1666 if( zwindow->idx < 0 ) continue;
1667 int xx = zx + x1, yy = zy + y1;
1668 int mx = x2 - zw, my = y2 - zh;
1669 if( xx > mx ) xx = mx;
1670 if( yy > my ) yy = my;
1671 zwindow->reposition(xx,yy, ww,hh);
1672 if( zwindow->running() ) {
1673 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1674 gui->lock_window("MWindow::tile_mixers");
1675 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1676 gui->unlock_window();
1687 void MWindow::set_gang_tracks(int v)
1689 edl->local_session->gang_tracks = v;
1690 sync_parameters(CHANGE_PARAMS);
1691 gui->update(1, 1, 0, 0, 1, 0, 0);
1696 void MWindow::init_cache()
1698 audio_cache = new CICache(preferences);
1699 video_cache = new CICache(preferences);
1700 frame_cache = new FrameCache;
1701 wave_cache = new WaveCache;
1704 void MWindow::init_channeldb()
1706 channeldb_buz->load("channeldb_buz");
1707 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1710 void MWindow::init_menus()
1712 char string[BCTEXTLEN];
1715 BC_CModels::to_text(string, BC_RGB888);
1716 colormodels.append(new ColormodelItem(string, BC_RGB888));
1717 BC_CModels::to_text(string, BC_RGBA8888);
1718 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1719 // BC_CModels::to_text(string, BC_RGB161616);
1720 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1721 // BC_CModels::to_text(string, BC_RGBA16161616);
1722 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1723 BC_CModels::to_text(string, BC_RGB_FLOAT);
1724 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1725 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1726 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1727 BC_CModels::to_text(string, BC_YUV888);
1728 colormodels.append(new ColormodelItem(string, BC_YUV888));
1729 BC_CModels::to_text(string, BC_YUVA8888);
1730 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1731 // BC_CModels::to_text(string, BC_YUV161616);
1732 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1733 // BC_CModels::to_text(string, BC_YUVA16161616);
1734 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1736 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1737 interlace_project_modes.append(new InterlacemodeItem(string, x));
1739 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1740 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1742 // Interlacing Modes
1743 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1745 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1746 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1748 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1749 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1751 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1752 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1754 mixers_align = new MixersAlign(this);
1757 void MWindow::init_indexes()
1759 mainindexes = new MainIndexes(this);
1760 mainindexes->start_loop();
1763 void MWindow::init_gui()
1765 gui = new MWindowGUI(this);
1766 gui->create_objects();
1767 gui->load_defaults(defaults);
1770 void MWindow::init_signals()
1772 sighandler = new SigHandler;
1773 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1777 void MWindow::init_render()
1779 render = new Render(this);
1780 create_bd = new CreateBD_Thread(this);
1781 create_dvd = new CreateDVD_Thread(this);
1782 batch_render = new BatchRenderThread(this);
1785 void MWindow::init_exportedl()
1787 exportedl = new ExportEDL(this);
1791 void MWindow::init_shuttle()
1794 int ret = Shuttle::probe();
1796 shuttle = new Shuttle(this);
1797 if( shuttle->read_config_file() > 0 ) {
1798 printf("shuttle: bad config file\n");
1799 delete shuttle; shuttle = 0;
1802 shuttle->start(ret);
1806 void MWindow::init_wintv()
1809 wintv = WinTV::probe(this);
1814 void MWindow::init_x10tv()
1817 x10tv = X10TV::probe(this);
1824 void MWindow::init_brender()
1826 if(preferences->use_brender && !brender)
1828 brender_lock->lock("MWindow::init_brender 1");
1829 brender = new BRender(this);
1830 brender->initialize();
1831 session->brender_end = 0;
1832 brender_lock->unlock();
1835 if(!preferences->use_brender && brender)
1837 brender_lock->lock("MWindow::init_brender 2");
1840 session->brender_end = 0;
1841 brender_lock->unlock();
1847 void MWindow::restart_brender()
1849 //printf("MWindow::restart_brender 1\n");
1850 if( !brender_active || !preferences->use_brender ) return;
1851 if( !brender ) return;
1852 brender->restart(edl);
1855 void MWindow::stop_brender()
1857 if( !brender ) return;
1858 // cannot be holding mwindow->gui display lock
1862 int MWindow::brender_available(int position)
1865 brender_lock->lock("MWindow::brender_available 1");
1866 if(brender && brender_active)
1868 if(brender->map_valid)
1870 brender->map_lock->lock("MWindow::brender_available 2");
1871 if(position < brender->map_size &&
1874 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1875 if(brender->map[position] == BRender::RENDERED)
1878 brender->map_lock->unlock();
1881 brender_lock->unlock();
1885 void MWindow::set_brender_active(int v, int update)
1887 if( !preferences->use_brender ) v = 0;
1889 gui->mainmenu->brender_active->set_checked(v);
1891 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1892 edl->session->brender_end = edl->local_session->get_selectionend(1);
1894 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1895 edl->session->brender_end = edl->tracks->total_video_length();
1900 edl->session->brender_start = edl->session->brender_end = 0;
1901 gui->unlock_window();
1903 gui->lock_window("MWindow::set_brender_active");
1906 gui->update_timebar(0);
1907 gui->draw_overlays(1);
1911 int MWindow::has_commercials()
1913 #ifdef HAVE_COMMERCIAL
1914 return theme->use_commercials;
1920 void MWindow::init_commercials()
1922 #ifdef HAVE_COMMERCIAL
1923 if( !commercials ) {
1924 commercials = new Commercials(this);
1925 commercial_active = 0;
1928 commercials->add_user();
1932 void MWindow::commit_commercial()
1934 #ifdef HAVE_COMMERCIAL
1935 if( !commercial_active ) return;
1936 commercial_active = 0;
1937 if( !commercials ) return;
1938 commercials->commitDb();
1942 void MWindow::undo_commercial()
1944 #ifdef HAVE_COMMERCIAL
1945 if( !commercial_active ) return;
1946 commercial_active = 0;
1947 if( !commercials ) return;
1948 commercials->undoDb();
1952 int MWindow::put_commercial()
1955 #ifdef HAVE_COMMERCIAL
1956 double start = edl->local_session->get_selectionstart();
1957 double end = edl->local_session->get_selectionend();
1958 if( start >= end ) return 0;
1960 const char *errmsg = 0;
1962 Tracks *tracks = edl->tracks;
1964 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1965 if( track->data_type != TRACK_VIDEO ) continue;
1966 if( !track->armed ) continue;
1967 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1969 int64_t units_start = track->to_units(start,0);
1970 int64_t units_end = track->to_units(end,0);
1971 Edits *edits = track->edits;
1972 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1973 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1974 if(!edit1 && !edit2) continue; // nothing selected
1975 if(!edit2) { // edit2 beyond end of track
1976 edit2 = edits->last;
1977 units_end = edits->length();
1979 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1980 Indexable *indexable = edit1->get_source();
1981 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1984 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1985 if( track->data_type != TRACK_VIDEO ) continue;
1986 if( !track->armed ) continue;
1987 int64_t units_start = track->to_units(start,0);
1988 int64_t units_end = track->to_units(end,0);
1989 Edits *edits = track->edits;
1990 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1991 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1992 if(!edit1 && !edit2) continue; // nothing selected
1993 if(!edit2) { // edit2 beyond end of track
1994 edit2 = edits->last;
1995 units_end = edits->length();
1997 Indexable *indexable = edit1->get_source();
1998 Asset *asset = (Asset *)indexable;
1999 File *file = video_cache->check_out(asset, edl);
2000 if( !file ) { errmsg = _("no file"); break; }
2001 int64_t edit_length = units_end - units_start;
2002 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
2003 result = commercials->put_clip(file, edit1->channel,
2004 track->from_units(edit_start), track->from_units(edit_length));
2005 video_cache->check_in(asset);
2006 if( result ) { errmsg = _("db failed"); break; }
2009 char string[BCTEXTLEN];
2010 sprintf(string, _("put_commercial: %s"), errmsg);
2011 MainError::show_error(string);
2019 void MWindow::stop_playback(int wait)
2021 gui->stop_drawing();
2023 cwindow->stop_playback(wait);
2025 for(int i = 0; i < vwindows.size(); i++) {
2026 VWindow *vwindow = vwindows[i];
2027 if( !vwindow->is_running() ) continue;
2028 vwindow->stop_playback(wait);
2030 for(int i = 0; i < zwindows.size(); i++) {
2031 ZWindow *zwindow = zwindows[i];
2032 if( zwindow->idx < 0 ) continue;
2033 zwindow->stop_playback(wait);
2037 void MWindow::stop_transport()
2039 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
2042 void MWindow::undo_before(const char *description, void *creator)
2044 undo->update_undo_before(description, creator);
2047 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
2049 undo->update_undo_after(description, load_flags, changes_made);
2052 void MWindow::beep(double freq, double secs, double gain)
2054 if( !beeper ) beeper = new Beeper(this);
2055 beeper->tone(freq, secs, gain);
2058 Beeper::Beeper(MWindow *mwindow)
2061 this->mwindow = mwindow;
2062 audio = new AudioDevice(mwindow);
2076 int64_t bfrsz = BEEP_SAMPLE_RATE;
2077 EDL *edl = mwindow->edl;
2078 EDLSession *session = edl->session;
2079 AudioOutConfig *aconfig = session->playback_config->aconfig;
2080 audio->open_output(aconfig, BEEP_SAMPLE_RATE, bfrsz, channels, 0);
2081 audio->start_playback();
2083 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
2084 const double two_pi = 2*M_PI;
2085 int64_t audio_len = BEEP_SAMPLE_RATE * secs;
2086 const double dt = two_pi * freq/BEEP_SAMPLE_RATE;
2091 while( !interrupted ) {
2092 int len = audio_len - audio_pos;
2093 if( len <= 0 ) break;
2094 if( len > bfrsz ) len = bfrsz;
2096 for( int i=0; i<len; ++i,++k,th+=dt ) {
2097 double t = th - two_pi;
2098 if( t >= 0 ) th = t;
2099 out0[i] = out1[i] = sin(th) * gain;
2101 audio->write_buffer(out, channels, len);
2106 audio->set_last_buffer();
2107 audio->stop_audio(interrupted ? 0 : 1);
2113 void Beeper::start()
2115 if( running() ) return;
2121 void Beeper::stop(int wait)
2123 if( running() && !interrupted ) {
2125 audio->stop_audio(wait);
2130 void Beeper::tone(double freq, double secs, double gain)
2140 int MWindow::load_filenames(ArrayList<char*> *filenames,
2141 int load_mode, int edl_mode, int update_filename)
2143 ArrayList<EDL*> new_edls;
2144 ArrayList<Asset*> new_assets;
2145 ArrayList<File*> new_files;
2148 gui->start_hourglass();
2150 // Need to stop playback since tracking depends on the EDL not getting
2152 gui->unlock_window();
2154 gui->lock_window("MWindow::load_filenames 0");
2157 const int debug = 0;
2158 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2160 // Define new_edls and new_assets to load
2161 int result = 0, ftype = -1;
2163 for( int i=0; i<filenames->size(); ++i ) {
2165 File *new_file = new File;
2166 Asset *new_asset = new Asset(filenames->get(i));
2167 EDL *new_edl = new EDL;
2168 new_edl->create_objects();
2169 new_edl->copy_session(edl, -1);
2170 new_file->set_program(edl->session->program_no);
2172 char string[BCTEXTLEN];
2173 sprintf(string, _("Loading %s"), new_asset->path);
2174 gui->show_message(string);
2176 ftype = new_file->open_file(preferences, new_asset, 1, 0);
2180 // Convert media file to EDL
2182 // Warn about odd image dimensions
2183 if( new_asset->video_data &&
2184 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
2185 eprintf(_("%s's resolution is %dx%d.\n"
2186 "Images with odd dimensions may not decode properly."),
2187 new_asset->path, new_asset->width, new_asset->height);
2190 if( new_asset->program >= 0 &&
2191 edl->session->program_no != new_asset->program ) {
2192 eprintf(_("%s's index was built for program number %d\n"
2193 "Playback preference is %d.\n Using program %d."),
2194 new_asset->path, new_asset->program,
2195 edl->session->program_no, new_asset->program);
2198 if( load_mode == LOADMODE_RESOURCESONLY ) {
2199 new_assets.append(new_asset);
2200 new_asset->add_user();
2205 RecordLabels *labels = edl->session->label_cells ?
2206 new RecordLabels(new_file) : 0;
2207 asset_to_edl(new_edl, new_asset, labels);
2208 new_edls.append(new_edl);
2209 new_edl->add_user();
2212 if( load_mode == LOADMODE_REPLACE ||
2213 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2214 // Set filename to nothing for assets since save EDL would overwrite them.
2216 // Reset timeline position
2217 for( int i=0; i<TOTAL_PANES; ++i ) {
2218 new_edl->local_session->view_start[i] = 0;
2219 new_edl->local_session->track_start[i] = 0;
2224 // File is a list and size of listed files don't match
2225 case FILE_SIZE_DONT_MATCH: {
2226 eprintf(_("File sizes don't match"));
2227 sprintf(string, _("File sizes don't match"));
2228 gui->show_message(string, theme->message_error);
2229 gui->update_default_message();
2232 case FILE_NOT_FOUND: {
2233 eprintf(_("Failed to open %s"), new_asset->path);
2234 sprintf(string, _("Failed to open %s"), new_asset->path);
2235 gui->show_message(string, theme->message_error);
2236 gui->update_default_message();
2240 case FILE_UNRECOGNIZED_CODEC: {
2242 { IndexFile indexfile(this, new_asset);
2243 if( !(result = indexfile.open_index()) )
2244 indexfile.close_index(); }
2246 // Test existing EDLs
2247 for( int j=0; result && j<new_edls.total; ++j ) {
2248 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
2250 new_asset->copy_from(old_asset,1);
2255 Asset *old_asset = edl->assets->get_asset(new_asset->path);
2257 new_asset->copy_from(old_asset,1);
2264 new_asset->audio_data = 1;
2265 new_asset->format = FILE_PCM;
2266 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
2267 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
2268 new_asset->bits = defaults->get("AUDIO_BITS", 16);
2269 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
2270 new_asset->signed_ = defaults->get("SIGNED_", 1);
2271 new_asset->header = defaults->get("HEADER", 0);
2274 fs.extract_name(string, new_asset->path);
2275 strcat(string, _("'s format couldn't be determined."));
2276 FileFormat fwindow(this);
2277 fwindow.create_objects(new_asset, string);
2278 result = fwindow.run_window();
2280 defaults->update("AUDIO_CHANNELS", new_asset->channels);
2281 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
2282 defaults->update("AUDIO_BITS", new_asset->bits);
2283 defaults->update("BYTE_ORDER", new_asset->byte_order);
2284 defaults->update("SIGNED_", new_asset->signed_);
2285 defaults->update("HEADER", new_asset->header);
2290 // Recalculate length
2292 new_file = new File;
2293 result = new_file->open_file(preferences, new_asset, 1, 0);
2295 if( load_mode != LOADMODE_RESOURCESONLY ) {
2296 RecordLabels *labels = edl->session->label_cells ?
2297 new RecordLabels(new_file) : 0;
2298 asset_to_edl(new_edl, new_asset, labels);
2299 new_edls.append(new_edl);
2300 new_edl->add_user();
2304 new_assets.append(new_asset);
2305 new_asset->add_user();
2312 const char *filename = filenames->get(i);
2313 if( xml_file.read_from_file(filename, 1) ) {
2314 eprintf(_("Error: unable to open:\n %s"), filename);
2317 const char *cin_version = 0;
2318 while( !xml_file.read_tag() ) {
2319 if( xml_file.tag.title_is("EDL") ) {
2320 cin_version = xml_file.tag.get_property("VERSION");
2325 if( !cin_version ) {
2326 eprintf(_("XML file %s\n not from cinelerra."),filename);
2327 char string[BCTEXTLEN];
2328 sprintf(string,_("Unknown %s"), filename);
2329 gui->show_message(string);
2332 if( strcmp(cin_version, CINELERRA_VERSION) &&
2333 strcmp(cin_version, "Unify") &&
2334 strcmp(cin_version, "5.1") ) {
2335 eprintf(_("Warning: XML from cinelerra version %s\n"
2336 "Session data may be incompatible."), cin_version);
2338 if( new_edl->load_xml(&xml_file, LOAD_ALL) ) {
2339 eprintf(_("Error: unable to load:\n %s"), filename);
2342 test_plugins(new_edl, filename);
2343 int groups = new_edl->regroup(session->group_number);
2344 session->group_number += groups;
2345 switch( edl_mode ) {
2346 case LOADMODE_EDL_CLIP: {
2347 strcpy(new_edl->local_session->clip_title,
2350 time_t t = !stat(filenames->get(i),&st) ?
2351 st.st_mtime : time(&t);
2352 ctime_r(&t, new_edl->local_session->clip_notes);
2353 switch( load_mode ) {
2354 case LOADMODE_REPLACE:
2355 case LOADMODE_REPLACE_CONCATENATE:
2356 strcpy(session->filename, filename);
2357 if( update_filename ) set_filename(filename);
2362 case LOADMODE_EDL_NESTED: {
2363 EDL *nested_edl = new EDL;
2364 nested_edl->create_objects();
2365 nested_edl->copy_session(edl, -1);
2366 nested_edl->create_nested(new_edl);
2367 nested_edl->set_path(filename);
2368 new_edl->remove_user();
2369 new_edl = nested_edl;
2372 case LOADMODE_EDL_FILEREF: {
2373 result = create_ref(new_asset, new_edl);
2375 new_assets.append(new_asset);
2376 new_asset->add_user();
2377 new_edl->remove_user();
2379 new_edl->create_objects();
2380 new_edl->copy_session(edl, -1);
2381 asset_to_edl(new_edl, new_asset);
2383 new_file = new File;
2384 result = new_file->open_file(preferences, new_asset, 1, 0);
2388 new_edls.append(new_edl);
2389 new_edl->add_user();
2392 eprintf(_("Error: Unable to load xml:\n %s"), new_asset->path);
2396 new_edl->Garbage::remove_user();
2397 new_asset->Garbage::remove_user();
2399 // Store for testing index
2400 new_files.append(new_file);
2403 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2406 gui->reset_default_message();
2407 gui->default_message();
2410 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2413 // Don't back up here.
2414 if( new_edls.size() ) {
2415 // For pasting, clear the active region
2416 if( load_mode == LOADMODE_PASTE ) {
2417 double start = edl->local_session->get_selectionstart();
2418 double end = edl->local_session->get_selectionend();
2419 if(!EQUIV(start, end))
2420 edl->clear(start, end,
2421 edl->session->labels_follow_edits,
2422 edl->session->plugins_follow_edits,
2423 edl->session->autos_follow_edits);
2425 paste_edls(&new_edls, load_mode, 0, -1,
2426 edl->session->labels_follow_edits,
2427 edl->session->plugins_follow_edits,
2428 edl->session->autos_follow_edits,
2431 else if( load_mode == LOADMODE_NEW_TRACKS &&
2432 edl_mode != LOADMODE_EDL_CLIP )
2433 paste_edls(&new_edls, load_mode, 0, -1, 0, 0, 0, 0);
2434 else if( load_mode != LOADMODE_RESOURCESONLY ||
2435 edl_mode == LOADMODE_EDL_CLIP )
2436 paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
2438 paste_edls(&new_edls, LOADMODE_NOTHING, 0, -1, 0, 0, 0, 0);
2442 // Add new assets to EDL and schedule assets for index building.
2443 int got_indexes = 0;
2444 for( int i=0; i<new_edls.size(); ++i ) {
2445 EDL *new_edl = new_edls[i];
2446 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2447 mainindexes->add_indexable(new_edl->nested_edls[j]);
2448 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2454 for( int i=0; i<new_assets.size(); ++i ) {
2455 Asset *new_asset = new_assets[i];
2456 mainindexes->add_indexable(new_asset);
2457 edl->assets->update(new_asset);
2461 // Start examining next batch of index files
2462 if(got_indexes) mainindexes->start_build();
2464 // reload renderengine edl or the plugin guis will flip out
2465 sync_parameters(CHANGE_ALL);
2469 // opening new session
2470 if( ( load_mode == LOADMODE_REPLACE ||
2471 load_mode == LOADMODE_REPLACE_CONCATENATE ) &&
2472 (ftype != FILE_IS_XML || edl_mode != LOADMODE_EDL_CLIP) ) {
2474 edl->session->proxy_state = PROXY_INACTIVE;
2475 edl->session->proxy_scale = 1;
2476 edl->session->proxy_disabled_scale = 1;
2477 edl->session->proxy_use_scaler = 0;
2478 edl->session->proxy_auto_scale = 0;
2479 edl->session->proxy_beep = 0;
2480 edl->local_session->preview_start = 0;
2481 edl->local_session->preview_end = -1;
2482 edl->local_session->loop_playback = 0;
2483 edl->local_session->set_selectionstart(0);
2484 edl->local_session->set_selectionend(0);
2485 edl->local_session->unset_inpoint();
2486 edl->local_session-> unset_outpoint();
2487 set_brender_active(0, 0);
2492 if( edl->session->proxy_state != PROXY_INACTIVE && edl->session->proxy_auto_scale &&
2493 load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) {
2494 ArrayList<Indexable *> orig_idxbls;
2495 for( int i=0; i<new_assets.size(); ++i )
2496 orig_idxbls.append(new_assets.get(i));
2497 for( int i=0; i<new_edls.size(); ++i ) {
2498 EDL *new_edl = new_edls[i];
2499 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2500 if( track->data_type != TRACK_VIDEO ) continue;
2501 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2502 Indexable *idxbl = (Indexable *)edit->asset;
2503 if( !idxbl ) continue;
2504 if( !idxbl->have_video() ) continue;
2505 if( edit->channel != 0 ) continue; // first layer only
2506 orig_idxbls.append(edit->asset);
2510 gui->unlock_window(); // to update progress bar
2511 int ret = render_proxy(orig_idxbls);
2512 gui->lock_window("MWindow::load_filenames");
2513 float gain = edl->session->proxy_beep;
2514 if( ret >= 0 && gain > 0 ) {
2516 beep(2000., 1.5, gain);
2518 beep(4000., 0.25, gain);
2522 // need to update undo before project, since mwindow is unlocked & a new load
2523 // can begin here. Should really prevent loading until we're done.
2524 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2525 undo_after(_("load"), LOAD_ALL);
2527 for(int i = 0; i < new_edls.size(); i++)
2529 new_edls[i]->remove_user();
2531 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2533 new_edls.remove_all();
2535 for(int i = 0; i < new_assets.size(); i++)
2537 new_assets[i]->Garbage::remove_user();
2540 new_assets.remove_all();
2541 new_files.remove_all_objects();
2544 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2545 if(load_mode == LOADMODE_REPLACE ||
2546 load_mode == LOADMODE_REPLACE_CONCATENATE)
2548 session->changes_made = 0;
2552 session->changes_made = 1;
2555 gui->stop_hourglass();
2558 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2559 update_project(load_mode);
2561 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2566 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2568 Asset *format_asset = new Asset;
2569 format_asset->format = FILE_FFMPEG;
2570 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2571 int new_scale = edl->session->proxy_scale;
2572 ProxyRender proxy_render(this, format_asset, new_scale);
2574 for( int i=0; i<new_idxbls.size(); ++i ) {
2575 Indexable *orig = new_idxbls.get(i);
2576 Asset *proxy = proxy_render.add_original(orig, new_scale);
2577 if( !proxy ) continue;
2579 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2580 int got_it = exists && // if proxy exists, and is newer than orig
2581 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2582 if( got_it ) continue;
2583 proxy_render.add_needed(orig, proxy);
2586 // render needed proxies
2587 int result = proxy_render.create_needed_proxies(new_scale);
2589 add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2591 format_asset->remove_user();
2592 return !result ? proxy_render.needed_proxies.size() : -1;
2595 int MWindow::enable_proxy()
2598 if( edl->session->proxy_state == PROXY_DISABLED ) {
2599 int new_scale = edl->session->proxy_disabled_scale;
2600 int new_use_scaler = edl->session->proxy_use_scaler;
2601 Asset *asset = new Asset;
2602 asset->format = FILE_FFMPEG;
2603 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2604 ret = to_proxy(asset, new_scale, new_use_scaler);
2605 asset->remove_user();
2607 float gain = edl->session->proxy_beep;
2608 beep(2000., 1.5, gain);
2610 edl->session->proxy_disabled_scale = 1;
2611 edl->session->proxy_state = PROXY_ACTIVE;
2612 gui->lock_window("MWindow::to_proxy");
2613 update_project(LOADMODE_REPLACE);
2614 gui->unlock_window();
2619 int MWindow::disable_proxy()
2621 if( edl->session->proxy_state == PROXY_ACTIVE ) {
2622 int old_scale = edl->session->proxy_scale, new_scale = 0;
2623 int new_use_scaler = edl->session->proxy_use_scaler;
2624 Asset *asset = new Asset;
2625 asset->format = FILE_FFMPEG;
2626 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2627 to_proxy(asset, new_scale, new_use_scaler);
2628 asset->remove_user();
2629 edl->session->proxy_state = PROXY_DISABLED;
2630 edl->session->proxy_disabled_scale = old_scale;
2631 gui->lock_window("MWindow::to_proxy");
2632 update_project(LOADMODE_REPLACE);
2633 gui->unlock_window();
2638 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2640 ArrayList<Indexable*> orig_idxbls;
2641 ArrayList<Indexable*> proxy_assets;
2643 edl->Garbage::add_user();
2645 undo_before(_("proxy"), this);
2646 int asset_scale = !new_scale ? 0 :
2647 !new_use_scaler ? 1 : new_scale;
2648 ProxyRender proxy_render(this, asset, asset_scale);
2650 // revert project to original size from current size
2651 // remove all session proxy assets at the at the current proxy_scale
2652 int proxy_scale = edl->session->proxy_scale;
2654 if( edl->session->proxy_state == PROXY_ACTIVE ) {
2655 Asset *orig_asset = edl->assets->first;
2656 for( ; orig_asset; orig_asset=orig_asset->next ) {
2657 char new_path[BCTEXTLEN];
2658 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2659 // test if proxy asset was already added to proxy_assets
2661 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2662 got_it = !strcmp(proxy_assets[i]->path, new_path);
2663 if( got_it ) continue;
2664 Asset *proxy_asset = edl->assets->get_asset(new_path);
2665 if( !proxy_asset ) continue;
2666 // add pointer to existing EDL asset if it exists
2667 // EDL won't delete it unless it's the same pointer.
2668 proxy_assets.append(proxy_asset);
2669 proxy_asset->add_user();
2670 orig_idxbls.append(orig_asset);
2671 orig_asset->add_user();
2673 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2674 EDL *orig_nested = edl->nested_edls[i];
2675 char new_path[BCTEXTLEN];
2676 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2677 // test if proxy asset was already added to proxy_assets
2679 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2680 got_it = !strcmp(proxy_assets[i]->path, new_path);
2681 if( got_it ) continue;
2682 Asset *proxy_nested = edl->assets->get_asset(new_path);
2683 if( !proxy_nested ) continue;
2684 // add pointer to existing EDL asset if it exists
2685 // EDL won't delete it unless it's the same pointer.
2686 proxy_assets.append(proxy_nested);
2687 proxy_nested->add_user();
2688 orig_idxbls.append(orig_nested);
2689 orig_nested->add_user();
2692 // convert from the proxy assets to the original assets
2693 edl->set_proxy(0, 0, &proxy_assets, &orig_idxbls);
2695 // remove the references
2696 for( int i=0; i<proxy_assets.size(); ++i ) {
2697 Asset *proxy = (Asset *) proxy_assets[i];
2698 proxy->width = proxy->actual_width;
2699 proxy->height = proxy->actual_height;
2700 proxy->remove_user();
2701 edl->assets->remove_pointer(proxy);
2702 proxy->remove_user();
2704 proxy_assets.remove_all();
2705 for( int i = 0; i < orig_idxbls.size(); i++ )
2706 orig_idxbls[i]->remove_user();
2707 orig_idxbls.remove_all();
2710 ArrayList<char *> confirm_paths; // test for new files
2711 confirm_paths.set_array_delete();
2713 // convert to new size if not original size
2716 Asset *orig = edl->assets->first;
2717 for( ; orig; orig=orig->next ) {
2718 Asset *proxy = proxy_render.add_original(orig, new_scale);
2719 if( !proxy ) continue;
2720 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2721 int got_it = exists && // if proxy exists, and is newer than orig
2722 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2724 if( exists ) // prompt user to overwrite
2725 confirm_paths.append(cstrdup(proxy->path));
2726 proxy_render.add_needed(orig, proxy);
2729 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2730 EDL *orig_nested = edl->nested_edls[i];
2731 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2732 if( !proxy ) continue;
2733 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2734 int got_it = exists && // if proxy exists, and is newer than orig_nested
2735 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2737 if( exists ) // prompt user to overwrite
2738 confirm_paths.append(cstrdup(proxy->path));
2739 proxy_render.add_needed(orig_nested, proxy);
2742 edl->session->proxy_state = PROXY_ACTIVE;
2745 edl->session->proxy_state = PROXY_INACTIVE;
2748 // test for existing files
2749 if( confirm_paths.size() ) {
2750 result = ConfirmSave::test_files(this, &confirm_paths);
2751 confirm_paths.remove_all_objects();
2754 if( !result && new_scale )
2755 result = proxy_render.create_needed_proxies(new_scale);
2757 if( !result ) { // resize project
2758 edl->set_proxy(new_scale, new_use_scaler,
2759 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2761 undo_after(_("proxy"), LOAD_ALL);
2762 edl->Garbage::remove_user();
2765 return !result ? proxy_render.needed_proxies.size() : -1;
2768 void MWindow::test_plugins(EDL *new_edl, const char *path)
2770 char string[BCTEXTLEN];
2772 // Do a check whether plugins exist
2773 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2774 for( int k=0; k<track->plugin_set.total; ++k ) {
2775 PluginSet *plugin_set = track->plugin_set[k];
2776 for( Plugin *plugin = (Plugin*)plugin_set->first;
2777 plugin; plugin = (Plugin*)plugin->next ) {
2778 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2779 // ok we need to find it in plugindb
2780 PluginServer *server =
2781 scan_plugindb(plugin->title, track->data_type);
2782 if( !server || server->transition ) {
2784 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2785 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2786 "effect", _(plugin->title), path);
2787 MainError::show_error(string);
2792 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2793 if( !edit->transition ) continue;
2794 // ok we need to find transition in plugindb
2795 PluginServer *server =
2796 scan_plugindb(edit->transition->title, track->data_type);
2797 if( !server || !server->transition ) {
2799 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2800 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2801 "transition", _(edit->transition->title), path);
2802 MainError::show_error(string);
2809 void MWindow::init_shm(const char *pfn, int64_t min)
2812 // Fix shared memory
2813 FILE *fd = fopen(pfn, "r");
2815 fscanf(fd, "%jd", &result);
2817 if( result >= min ) return;
2820 fd = fopen(pfn, "w");
2822 fprintf(fd, "0x%jx", min);
2825 fd = fopen(pfn, "r");
2827 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2831 fscanf(fd, "%jd", &result);
2833 if( result < min ) {
2834 eprintf(_("MWindow::init_shm: %s is %p.\n"
2835 "you probably need to be root, or:\n"
2836 "as root, run: echo 0x%jx > %s\n"
2837 "before trying to start cinelerra.\n"
2838 "It should be at least 0x%jx for Cinelerra.\n"),
2839 pfn, (void *)result, min, pfn, min);
2843 void MWindow::create_objects(int want_gui,
2847 const int debug = 0;
2848 if(debug) PRINT_TRACE
2850 // For some reason, init_signals must come after show_splash or the signals won't
2853 if(debug) PRINT_TRACE
2856 if(debug) PRINT_TRACE
2858 if(debug) PRINT_TRACE
2859 default_standard = default_std();
2860 init_defaults(defaults, config_path);
2865 splash_window->update_status(_("Initializing Plugins"));
2866 init_plugins(this, preferences);
2867 if(debug) PRINT_TRACE
2868 init_ladspa_plugins(this, preferences);
2869 if(debug) PRINT_TRACE
2870 init_plugin_tips(*plugindb, cin_lang);
2872 splash_window->update_status(_("Initializing GUI"));
2873 if(debug) PRINT_TRACE
2876 if(debug) PRINT_TRACE
2880 splash_window->update_status(_("Initializing Fonts"));
2881 char string[BCTEXTLEN];
2882 strcpy(string, preferences->plugin_dir);
2883 strcat(string, "/" FONT_SEARCHPATH);
2884 BC_Resources::init_fontconfig(string);
2885 if(debug) PRINT_TRACE
2891 // Default project created here
2893 if(debug) PRINT_TRACE
2896 if(debug) PRINT_TRACE
2901 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2904 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2906 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2907 if(session->show_vwindow)
2908 get_viewer(1, DEFAULT_VWINDOW);
2909 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2912 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2915 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2918 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2921 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2924 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2927 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2933 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2934 mainprogress = new MainProgress(this, gui);
2935 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2936 undo = new MainUndo(this);
2938 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2940 plugin_guis = new PluginGUIs(this);
2941 dead_plugins = new ArrayList<PluginServer*>;
2942 keyframe_threads = new ArrayList<KeyFrameThread*>;
2944 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2947 session->show_vwindow);
2949 // Show all vwindows
2950 // if(session->show_vwindow) {
2951 // for(int j = 0; j < vwindows.size(); j++) {
2952 // VWindow *vwindow = vwindows[j];
2953 // if( !vwindow->is_running() ) continue;
2954 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2957 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2958 // vwindow->gui->lock_window("MWindow::create_objects 1");
2959 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2960 // vwindow->gui->show_window();
2961 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2962 // vwindow->gui->unlock_window();
2967 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2969 if(session->show_cwindow)
2971 cwindow->gui->lock_window("MWindow::create_objects 1");
2972 cwindow->gui->show_window();
2973 cwindow->gui->unlock_window();
2976 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2977 if(session->show_awindow)
2979 awindow->gui->lock_window("MWindow::create_objects 1");
2980 awindow->gui->show_window();
2981 awindow->gui->unlock_window();
2984 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2985 if(session->show_lwindow)
2987 lwindow->gui->lock_window("MWindow::create_objects 1");
2988 lwindow->gui->show_window();
2989 lwindow->gui->unlock_window();
2992 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2994 (int)timer.get_difference(),
2996 if(session->show_gwindow)
2998 gwindow->gui->lock_window("MWindow::create_objects 1");
2999 gwindow->gui->show_window();
3000 gwindow->gui->unlock_window();
3003 if(debug) PRINT_TRACE
3005 gui->lock_window("MWindow::create_objects 1");
3006 gui->mainmenu->load_defaults(defaults);
3007 gui->mainmenu->update_toggles(0);
3008 gui->update_patchbay();
3009 gui->draw_canvas(0, 0);
3010 gui->draw_cursor(1);
3012 gui->raise_window();
3013 gui->unlock_window();
3014 cwindow->gui->lock_window("MWindow::create_objects 1");
3015 cwindow->gui->tool_panel->raise_tool();
3016 cwindow->gui->unlock_window();
3017 if(debug) PRINT_TRACE
3019 if(preferences->use_tipwindow)
3021 if(debug) PRINT_TRACE
3023 gui->add_keyboard_listener(
3024 (int (BC_WindowBase::*)(BC_WindowBase *))
3025 &MWindowGUI::keyboard_listener);
3028 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
3029 init_shm("/proc/sys/kernel/shmmni", 0x4000);
3030 if(debug) PRINT_TRACE
3032 BC_WindowBase::get_resources()->vframe_shm = 1;
3035 int MWindow::uses_opengl()
3037 if( !playback_3d || !playback_3d->running() ) return 0;
3038 PlaybackConfig *playback_config = edl->session->playback_config;
3039 return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
3042 void MWindow::show_splash()
3044 #include "data/heroine_logo9_png.h"
3045 VFrame *frame = new VFramePng(heroine_logo9_png);
3046 BC_DisplayInfo dpyi;
3047 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
3048 int rr = (rw < rh ? rw : rh) / 4;
3049 splash_window = new SplashGUI(frame, rr, rr);
3050 splash_window->create_objects();
3053 void MWindow::hide_splash()
3056 delete splash_window;
3061 void MWindow::start()
3065 // vwindows[DEFAULT_VWINDOW]->start();
3076 playback_3d->start();
3082 run_lock->lock("MWindow::run");
3086 brender_lock->lock("MWindow::run 1");
3087 delete brender; brender = 0;
3088 brender_lock->unlock();
3090 interrupt_indexes();
3096 void MWindow::show_vwindow(int raise)
3098 int total_running = 0;
3099 session->show_vwindow = 1;
3101 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
3102 // Raise all windows which are visible
3103 for(int j = 0; j < vwindows.size(); j++) {
3104 VWindow *vwindow = vwindows[j];
3105 if( !vwindow->is_running() ) continue;
3107 if( !raise && !vwindow->gui->is_hidden() ) continue;
3108 vwindow->gui->lock_window("MWindow::show_vwindow");
3109 vwindow->gui->show_window(0);
3110 vwindow->gui->raise_window();
3111 vwindow->gui->flush();
3112 vwindow->gui->unlock_window();
3114 // If no windows visible
3115 if( !total_running )
3116 get_viewer(1, DEFAULT_VWINDOW);
3118 gui->mainmenu->show_vwindow->set_checked(1);
3122 void MWindow::hide_vwindow(int raise)
3124 session->show_vwindow = 0;
3125 int total_running = 0;
3127 for(int j = 0; j < vwindows.size(); j++) {
3128 VWindow *vwindow = vwindows[j];
3129 if( !vwindow->is_running() ) continue;
3131 if( !raise && !vwindow->gui->is_hidden() ) continue;
3132 vwindow->gui->lock_window("MWindow::show_vwindow");
3133 vwindow->gui->hide_window(0);
3134 vwindow->gui->unlock_window();
3136 gui->mainmenu->show_vwindow->set_checked(0);
3140 void MWindow::show_awindow()
3142 session->show_awindow = 1;
3143 awindow->gui->lock_window("MWindow::show_awindow");
3144 awindow->gui->show_window();
3145 awindow->gui->raise_window();
3146 awindow->gui->flush();
3147 awindow->gui->unlock_window();
3148 gui->mainmenu->show_awindow->set_checked(1);
3151 void MWindow::hide_awindow()
3153 session->show_awindow = 0;
3155 awindow->gui->lock_window("MWindow::show_awindow");
3156 awindow->gui->hide_window();
3157 awindow->gui->unlock_window();
3158 gui->mainmenu->show_awindow->set_checked(0);
3162 char *MWindow::get_cwindow_display()
3164 char *x11_host = screens < 2 || session->window_config == 0 ?
3165 session->a_x11_host : session->b_x11_host;
3166 return *x11_host ? x11_host : 0;
3169 void MWindow::show_cwindow()
3171 session->show_cwindow = 1;
3172 cwindow->show_window();
3173 cwindow->gui->tool_panel->raise_tool();
3174 gui->mainmenu->show_cwindow->set_checked(1);
3178 void MWindow::hide_cwindow()
3180 session->show_cwindow = 0;
3182 cwindow->gui->lock_window("MWindow::show_cwindow");
3183 cwindow->gui->hide_window();
3184 cwindow->gui->unlock_window();
3185 gui->mainmenu->show_cwindow->set_checked(0);
3189 void MWindow::show_gwindow()
3191 session->show_gwindow = 1;
3193 gwindow->gui->lock_window("MWindow::show_gwindow");
3194 gwindow->gui->show_window();
3195 gwindow->gui->raise_window();
3196 gwindow->gui->flush();
3197 gwindow->gui->unlock_window();
3199 gui->mainmenu->show_gwindow->set_checked(1);
3202 void MWindow::hide_gwindow()
3204 session->show_gwindow = 0;
3206 gwindow->gui->lock_window("MWindow::show_gwindow");
3207 gwindow->gui->hide_window();
3208 gwindow->gui->unlock_window();
3209 gui->mainmenu->show_gwindow->set_checked(0);
3212 void MWindow::show_lwindow()
3214 session->show_lwindow = 1;
3215 lwindow->gui->lock_window("MWindow::show_lwindow");
3216 lwindow->gui->show_window();
3217 lwindow->gui->raise_window();
3218 lwindow->gui->flush();
3219 lwindow->gui->unlock_window();
3220 gui->mainmenu->show_lwindow->set_checked(1);
3223 void MWindow::hide_lwindow()
3225 session->show_lwindow = 0;
3227 lwindow->gui->lock_window("MWindow::show_lwindow");
3228 lwindow->gui->hide_window();
3229 lwindow->gui->unlock_window();
3230 gui->mainmenu->show_lwindow->set_checked(0);
3234 void MWindow::restore_windows()
3236 gui->unlock_window();
3237 if( !session->show_vwindow ) {
3238 for( int i=0, n=vwindows.size(); i<n; ++i ) {
3239 VWindow *vwindow = vwindows[i];
3240 if( !vwindow || !vwindow->is_running() ) continue;
3241 vwindow->gui->lock_window("MWindow::restore_windows");
3242 vwindow->gui->close(1);
3243 vwindow->gui->unlock_window();
3249 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
3250 awindow->gui->lock_window("MWindow::restore_windows");
3251 awindow->gui->close_event();
3252 awindow->gui->unlock_window();
3254 else if( session->show_awindow && awindow->gui->is_hidden() )
3257 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
3258 cwindow->gui->lock_window("MWindow::restore_windows");
3259 cwindow->hide_window();
3260 cwindow->gui->unlock_window();
3262 else if( session->show_cwindow && cwindow->gui->is_hidden() )
3265 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
3266 gwindow->gui->lock_window("MWindow::restore_windows");
3267 gwindow->gui->close_event();
3268 gwindow->gui->unlock_window();
3270 else if( session->show_gwindow && gwindow->gui->is_hidden() )
3273 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
3274 lwindow->gui->lock_window("MWindow::restore_windows");
3275 lwindow->gui->close_event();
3276 lwindow->gui->unlock_window();
3278 else if( session->show_lwindow && lwindow->gui->is_hidden() )
3282 gui->lock_window("MWindow::restore_windows");
3286 void MWindow::load_layout(const char *layout)
3288 char path[BCTEXTLEN];
3289 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3290 session->load_file(path);
3292 gui->default_positions();
3296 void MWindow::save_layout(const char *layout)
3298 char path[BCTEXTLEN];
3299 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3300 session->save_file(path);
3303 void MWindow::delete_layout(const char *layout)
3305 char path[BCTEXTLEN];
3306 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3310 int MWindow::tile_windows(int window_config)
3312 int need_reload = 0;
3313 int play_config = window_config==0 ? 0 : 1;
3314 edl->session->playback_config->load_defaults(defaults, play_config);
3315 session->default_window_positions(window_config);
3316 if( screens == 1 ) {
3317 gui->default_positions();
3318 sync_parameters(CHANGE_ALL);
3325 void MWindow::toggle_loop_playback()
3327 edl->local_session->loop_playback = !edl->local_session->loop_playback;
3328 set_loop_boundaries();
3331 gui->draw_overlays(1);
3332 sync_parameters(CHANGE_PARAMS);
3335 void MWindow::set_screens(int value)
3340 void MWindow::set_auto_keyframes(int value)
3342 edl->session->auto_keyframes = value;
3343 gui->mbuttons->edit_panel->keyframe->update(value);
3345 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
3346 cwindow->gui->flush();
3347 cwindow->gui->unlock_window();
3350 void MWindow::set_span_keyframes(int value)
3352 edl->session->span_keyframes = value;
3353 gui->mbuttons->edit_panel->span_keyframe->update(value);
3355 cwindow->gui->lock_window("MWindow::set_span_keyframes");
3356 cwindow->gui->flush();
3357 cwindow->gui->unlock_window();
3360 void MWindow::set_auto_visibility(Autos *autos, int value)
3362 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3363 edl->session->auto_conf->plugins = value;
3364 else if( autos->autoidx >= 0 )
3365 edl->session->auto_conf->autos[autos->autoidx] = value;
3369 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3370 gui->mainmenu->update_toggles(1);
3371 gui->unlock_window();
3372 gwindow->gui->update_toggles(1);
3373 gui->lock_window("MWindow::set_auto_visibility");
3376 void MWindow::set_keyframe_type(int mode)
3378 gui->lock_window("MWindow::set_keyframe_type");
3379 edl->local_session->floatauto_type = mode;
3380 gui->mainmenu->update_toggles(0);
3381 gui->unlock_window();
3384 int MWindow::set_editing_mode(int new_editing_mode)
3386 edl->session->editing_mode = new_editing_mode;
3387 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3388 gui->mbuttons->edit_panel->update();
3389 gui->set_editing_mode(1);
3391 cwindow->gui->lock_window("MWindow::set_editing_mode");
3392 cwindow->gui->edit_panel->update();
3393 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3394 cwindow->gui->unlock_window();
3398 void MWindow::toggle_editing_mode()
3400 int mode = edl->session->editing_mode;
3401 if( mode == EDITING_ARROW )
3402 set_editing_mode(EDITING_IBEAM);
3404 set_editing_mode(EDITING_ARROW);
3407 void MWindow::toggle_camera_xyz()
3409 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3410 gwindow->gui->toggle_camera_xyz();
3411 gwindow->gui->unlock_window();
3414 void MWindow::toggle_projector_xyz()
3416 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3417 gwindow->gui->toggle_projector_xyz();
3418 gwindow->gui->unlock_window();
3421 void MWindow::set_labels_follow_edits(int value)
3423 edl->session->labels_follow_edits = value;
3424 gui->mbuttons->edit_panel->locklabels->update(value);
3425 gui->mainmenu->labels_follow_edits->set_checked(value);
3429 void MWindow::sync_parameters(int change_type)
3431 if( in_destructor ) return;
3433 // Sync engines which are playing back
3434 if( cwindow->playback_engine->is_playing_back ) {
3435 if( change_type == CHANGE_PARAMS ) {
3436 // TODO: block keyframes until synchronization is done
3437 cwindow->playback_engine->sync_parameters(edl);
3441 int command = cwindow->playback_engine->command->command;
3442 // Waiting for tracking to finish would make the restart position more
3443 // accurate but it can't lock the window to stop tracking for some reason.
3444 // Not waiting for tracking gives a faster response but restart position is
3445 // only as accurate as the last tracking update.
3446 cwindow->playback_engine->transport_stop(0);
3447 cwindow->playback_engine->next_command->realtime = 1;
3448 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3452 cwindow->refresh_frame(change_type);
3456 void MWindow::age_caches()
3458 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3460 // preferences->cache_size,
3461 // audio_cache->get_memory_usage(1),
3462 // video_cache->get_memory_usage(1),
3463 // frame_cache->get_memory_usage(),
3464 // wave_cache->get_memory_usage(),
3466 frame_cache->age_cache(512);
3467 wave_cache->age_cache(8192);
3469 int64_t memory_usage;
3470 int64_t prev_memory_usage = 0;
3472 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3473 while( !result && prev_memory_usage !=
3474 (memory_usage=video_cache->get_memory_usage(1)) &&
3475 memory_usage > video_size ) {
3476 video_cache->delete_oldest();
3477 prev_memory_usage = memory_usage;
3480 prev_memory_usage = 0;
3482 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3483 while( !result && prev_memory_usage !=
3484 (memory_usage=audio_cache->get_memory_usage(1)) &&
3485 memory_usage > audio_size ) {
3486 audio_cache->delete_oldest();
3487 prev_memory_usage = memory_usage;
3491 void MWindow::reset_android_remote()
3493 gui->use_android_remote(preferences->android_remote);
3497 void MWindow::show_keyframe_gui(Plugin *plugin)
3499 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3500 // Find existing thread
3501 for( int i=0; i<keyframe_threads->size(); ++i ) {
3502 int plugin_id = keyframe_threads->get(i)->plugin_id;
3503 if( plugin_id == plugin->orig_id ) {
3504 keyframe_threads->get(i)->start_window(plugin, 0);
3505 keyframe_gui_lock->unlock();
3510 // Find unused thread
3511 for( int i=0; i<keyframe_threads->size(); ++i ) {
3512 if( keyframe_threads->get(i)->plugin_id < 0 ) {
3513 keyframe_threads->get(i)->start_window(plugin, 0);
3514 keyframe_gui_lock->unlock();
3519 // Create new thread
3520 KeyFrameThread *thread = new KeyFrameThread(this);
3521 keyframe_threads->append(thread);
3522 thread->start_window(plugin, 0);
3523 keyframe_gui_lock->unlock();
3527 void MWindow::show_plugin(Plugin *plugin)
3532 // Remove previously deleted plugin GUIs
3533 dead_plugin_lock->lock("MWindow::show_plugin");
3534 dead_plugins->remove_all_objects();
3535 dead_plugin_lock->unlock();
3537 //printf("MWindow::show_plugin %d\n", __LINE__);
3540 plugin_gui_lock->lock("MWindow::show_plugin");
3541 for( int i=0; i<plugin_guis->total; ++i ) {
3542 // Pointer/id comparison
3543 PluginServer *plugin_gui = plugin_guis->get(i);
3544 if( plugin_gui->plugin_id == plugin->orig_id ) {
3545 plugin_gui->raise_window();
3552 //printf("MWindow::show_plugin 1\n");
3553 if( !done && !plugin->track ) {
3554 printf("MWindow::show_plugin track not defined.\n");
3558 PluginServer *server = scan_plugindb(plugin->title,
3559 plugin->track->data_type);
3561 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3562 if(server && server->uses_gui)
3564 PluginServer *gui = new PluginServer(*server);
3565 plugin_guis->append(gui);
3566 // Needs mwindow to do GUI
3567 gui->set_mwindow(this);
3568 gui->open_plugin(0, preferences, edl, plugin);
3573 plugin_gui_lock->unlock();
3574 // update show/gui_id
3575 sync_parameters(CHANGE_PARAMS);
3576 //printf("MWindow::show_plugin %d\n", __LINE__);
3579 //printf("MWindow::show_plugin 2\n");
3582 void MWindow::hide_plugin(Plugin *plugin, int lock)
3585 return hide_plugin(plugin->orig_id, lock);
3588 void MWindow::hide_plugin(int plugin_id, int lock)
3590 // Update the toggle
3591 gui->lock_window("MWindow::hide_plugin");
3592 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3593 gui->unlock_window();
3595 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3596 for( int i=0; i<plugin_guis->total; ++i ) {
3597 PluginServer *plugin_gui = plugin_guis->get(i);
3598 if( plugin_gui->plugin_id == plugin_id ) {
3599 plugin_guis->remove(plugin_gui);
3600 if(lock) plugin_gui_lock->unlock();
3601 // Last command executed in client side close
3602 // Schedule for deletion
3603 plugin_gui->hide_gui();
3604 delete_plugin(plugin_gui);
3609 if(lock) plugin_gui_lock->unlock();
3610 // update show/gui_id
3611 sync_parameters(CHANGE_PARAMS);
3614 void MWindow::delete_plugin(PluginServer *plugin)
3616 dead_plugin_lock->lock("MWindow::delete_plugin");
3617 dead_plugins->append(plugin);
3618 dead_plugin_lock->unlock();
3621 void MWindow::hide_plugins()
3623 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3624 while(plugin_guis->size())
3626 PluginServer *ptr = plugin_guis->get(0);
3627 plugin_guis->remove(ptr);
3628 plugin_gui_lock->unlock();
3629 // Last command executed in client side close
3630 // Schedule for deletion
3633 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3635 plugin_gui_lock->unlock();
3637 hide_keyframe_guis();
3640 void MWindow::hide_keyframe_guis()
3642 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3643 for(int i = 0; i < keyframe_threads->size(); i++)
3645 keyframe_threads->get(i)->close_window();
3647 keyframe_gui_lock->unlock();
3650 void MWindow::hide_keyframe_gui(Plugin *plugin)
3652 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3653 for( int i = 0; i < keyframe_threads->size(); i++) {
3654 KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
3655 if( keyframe_gui->plugin_id == plugin->orig_id ) {
3656 keyframe_gui->close_window();
3660 keyframe_gui_lock->unlock();
3663 int MWindow::get_hash_color(Edit *edit)
3665 Indexable *idxbl = edit->asset ?
3666 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3667 if( !idxbl ) return 0;
3668 char path[BCTEXTLEN];
3669 // map proxy colors to unproxy colors
3670 if( edl->session->proxy_state != PROXY_ACTIVE ||
3671 !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3672 ProxyRender::from_proxy_path(path, (Asset*)idxbl, edl->session->proxy_scale) )
3673 strcpy(path, idxbl->path);
3674 char *cp = strrchr(path, '/');
3675 cp = !cp ? path : cp+1;
3676 uint8_t *bp = (uint8_t*)cp;
3678 while( *bp ) v += *bp++;
3679 return get_hash_color(v);
3682 int MWindow::get_hash_color(int v)
3684 int hash = 0x303030;
3685 if( v & 0x01 ) hash ^= 0x000040;
3686 if( v & 0x02 ) hash ^= 0x004000;
3687 if( v & 0x04 ) hash ^= 0x400000;
3688 if( v & 0x08 ) hash ^= 0x080000;
3689 if( v & 0x10 ) hash ^= 0x000800;
3690 if( v & 0x20 ) hash ^= 0x000008;
3691 if( v & 0x40 ) hash ^= 0x404040;
3692 if( v & 0x80 ) hash ^= 0x080808;
3696 int MWindow::get_group_color(int v)
3698 int color = 0x606060;
3699 if( v & 0x01 ) color ^= 0x000080;
3700 if( v & 0x02 ) color ^= 0x008000;
3701 if( v & 0x04 ) color ^= 0x800000;
3702 if( v & 0x08 ) color ^= 0x100000;
3703 if( v & 0x10 ) color ^= 0x001000;
3704 if( v & 0x20 ) color ^= 0x000010;
3705 if( v & 0x40 ) color ^= 0x080808;
3706 if( v & 0x80 ) color ^= 0x909090;
3710 int MWindow::get_title_color(Edit *edit)
3712 unsigned color = edit->color & 0xffffff;
3713 unsigned alpha = (~edit->color>>24) & 0xff;
3715 if( edit->group_id )
3716 color = get_group_color(edit->group_id);
3717 else if( preferences->autocolor_assets )
3718 color = get_hash_color(edit);
3723 alpha = session->title_bar_alpha*255;
3724 return color | (~alpha<<24);
3727 void MWindow::update_keyframe_guis()
3729 // Send new configuration to keyframe GUI's
3730 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3731 for( int i=0; i<keyframe_threads->size(); ++i ) {
3732 KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
3733 Plugin *plugin = edl->tracks->plugin_exists(keyframe_gui->plugin_id);
3735 keyframe_gui->update_gui(1);
3737 keyframe_gui->close_window();
3739 keyframe_gui_lock->unlock();
3742 void MWindow::update_plugin_guis(int do_keyframe_guis)
3744 // Send new configuration to plugin GUI's
3745 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3747 for( int i=0; i<plugin_guis->size(); ++i ) {
3748 PluginServer *plugin_gui = plugin_guis->get(i);
3749 Plugin *plugin = edl->tracks->plugin_exists(plugin_gui->plugin_id);
3750 if( plugin && plugin->show )
3751 plugin_gui->update_gui();
3753 // Schedule for deletion if no plugin or not shown
3754 plugin_guis->remove_number(i--);
3755 plugin_gui->hide_gui();
3756 delete_plugin(plugin_gui);
3761 // Change plugin variable if not visible
3762 Track *track = edl->tracks->first;
3763 for( ; track; track=track->next ) {
3764 for( int i=0; i < track->plugin_set.size(); ++i ) {
3765 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3766 for( ; plugin; plugin = (Plugin*)plugin->next ) {
3768 for( int i=0; i<plugin_guis->size(); ++i ) {
3769 PluginServer *server = plugin_guis->get(i);
3770 if( server->plugin_id == plugin->orig_id ) {
3775 if( !got_it ) plugin->show = 0;
3780 plugin_gui_lock->unlock();
3781 if( do_keyframe_guis )
3782 update_keyframe_guis();
3785 void MWindow::stop_plugin_guis()
3787 // Send new configuration to plugin GUI's
3788 plugin_gui_lock->lock("MWindow::stop_plugin_guis");
3790 for( int i=0; i<plugin_guis->size(); ++i ) {
3791 PluginServer *plugin_gui = plugin_guis->get(i);
3792 plugin_gui->render_stop();
3794 plugin_gui_lock->unlock();
3797 int MWindow::plugin_gui_open(Plugin *plugin)
3799 int gui_id = plugin->gui_id;
3800 if( gui_id < 0 ) return 0;
3801 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3802 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3803 int result = plugin_server ? 1 : 0;
3804 plugin_gui_lock->unlock();
3809 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3811 int gui_id = plugin->gui_id;
3812 if( gui_id < 0 ) return;
3813 plugin_gui_lock->lock("MWindow::render_plugin_gui 0");
3814 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3816 plugin_server->render_gui(data);
3817 plugin_gui_lock->unlock();
3820 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3822 int gui_id = plugin->gui_id;
3823 if( gui_id < 0 ) return;
3824 plugin_gui_lock->lock("MWindow::render_plugin_gui 1");
3825 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3827 plugin_server->render_gui(data, size);
3828 plugin_gui_lock->unlock();
3831 void MWindow::reset_plugin_gui_frames(Plugin *plugin)
3833 int gui_id = plugin->gui_id;
3834 if( gui_id < 0 ) return;
3835 plugin_gui_lock->lock("MWindow::reset_plugin_gui_frames");
3836 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3838 plugin_server->reset_plugin_gui_frames();
3839 plugin_gui_lock->unlock();
3842 void MWindow::render_plugin_gui_frames(PluginClientFrames *frames, Plugin *plugin)
3844 int gui_id = plugin->gui_id;
3845 if( gui_id < 0 ) return;
3846 plugin_gui_lock->lock("MWindow::render_plugin_gui_frames");
3847 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3849 plugin_server->render_plugin_gui_frames(frames);
3850 plugin_gui_lock->unlock();
3853 double MWindow::get_tracking_position()
3855 return edl->local_session->get_selectionstart(1);
3858 int MWindow::get_tracking_direction()
3860 return cwindow->playback_engine->get_direction();
3863 void MWindow::update_plugin_states()
3865 plugin_gui_lock->lock("MWindow::update_plugin_states");
3866 for( int i=0; i<plugin_guis->total; ++i ) {
3868 PluginServer *src_plugingui = plugin_guis->get(i);
3869 int plugin_id = src_plugingui->plugin_id;
3870 Plugin *src_plugin = edl->tracks->plugin_exists(plugin_id);
3871 // Doesn't exist anymore
3873 hide_plugin(plugin_id, 0);
3877 plugin_gui_lock->unlock();
3881 void MWindow::update_plugin_titles()
3883 for( int i=0; i<plugin_guis->total; ++i )
3884 plugin_guis->get(i)->update_title();
3887 int MWindow::asset_to_edl(EDL *new_edl,
3889 RecordLabels *labels)
3891 const int debug = 0;
3892 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3895 // Keep frame rate, sample rate, and output size unchanged.
3896 // These parameters would revert the project if VWindow displayed an asset
3897 // of different size than the project.
3898 if(new_asset->video_data)
3900 new_edl->session->video_tracks = new_asset->layers;
3903 new_edl->session->video_tracks = 0;
3905 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3911 if(new_asset->audio_data)
3913 new_edl->session->audio_tracks = new_asset->channels;
3916 new_edl->session->audio_tracks = 0;
3917 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3919 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3920 new_edl->create_default_tracks();
3921 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3922 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3926 //printf("MWindow::asset_to_edl 3\n");
3927 new_edl->insert_asset(new_asset,
3932 //printf("MWindow::asset_to_edl 3\n");
3933 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3935 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3936 if(edl->session->cursor_on_frames)
3938 double length = new_edl->tracks->total_length();
3939 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3940 new_edl->tracks->clear(length, edl_length, 1, 1);
3946 char string[BCTEXTLEN];
3948 fs.extract_name(string, new_asset->path);
3949 //printf("MWindow::asset_to_edl 3\n");
3951 strcpy(new_edl->local_session->clip_title, string);
3952 //printf("MWindow::asset_to_edl 4 %s\n", string);
3953 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3955 new_edl->local_session->asset2edl = 1;
3960 // Reset everything after a load.
3961 void MWindow::update_project(int load_mode)
3963 const int debug = 0;
3965 if(debug) PRINT_TRACE
3966 edl->tracks->update_y_pixels(theme);
3967 session->update_clip_number();
3969 if(debug) PRINT_TRACE
3971 if( load_mode == LOADMODE_REPLACE ||
3972 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3973 edl->session->timecode_offset = 0;
3974 gui->close_keyvalue_popup();
3978 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3979 if(debug) PRINT_TRACE
3980 gui->unlock_window();
3983 cwindow->update(0, 0, 1, 1, 1);
3985 if(debug) PRINT_TRACE
3987 // Close all the vwindows
3988 if( load_mode == LOADMODE_REPLACE ||
3989 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3990 if(debug) PRINT_TRACE
3991 int first_vwindow = 0;
3992 if(session->show_vwindow) first_vwindow = 1;
3993 // Change visible windows to no source
3994 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3995 VWindow *vwindow = vwindows[i];
3996 if( !vwindow->is_running() ) continue;
3997 vwindow->change_source(-1);
4000 // Close remaining windows
4001 for(int i = first_vwindow; i < vwindows.size(); i++) {
4002 VWindow *vwindow = vwindows[i];
4003 if( !vwindow->is_running() ) continue;
4004 vwindow->close_window();
4006 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
4007 VWindow *vwindow = get_viewer(1, -1);
4008 vwindow->change_source(i);
4010 if(debug) PRINT_TRACE
4014 for( int i=0; i<edl->mixers.size(); ++i ) {
4015 Mixer *mixer = edl->mixers[i];
4016 if( !mixer->show ) continue;
4017 ZWindow *zwindow = get_mixer(mixer);
4018 zwindow->set_title(mixer->title);
4021 cwindow->gui->canvas->set_zoom(edl, 0);
4025 if(debug) PRINT_TRACE
4026 cwindow->gui->lock_window("MWindow::update_project 2");
4027 cwindow->gui->timebar->update(0);
4028 Track *track = cwindow->calculate_affected_track();
4029 cwindow->mask_track_id = track ? track->get_id() : -1;
4030 cwindow->gui->tool_panel->raise_tool();
4031 cwindow->gui->update_canvas(0);
4032 cwindow->gui->unlock_window();
4034 if(debug) PRINT_TRACE
4035 cwindow->refresh_frame(CHANGE_ALL);
4037 awindow->gui->async_update_assets();
4038 if(debug) PRINT_TRACE
4040 gui->lock_window("MWindow::update_project");
4041 gui->update_mixers(0, 0);
4043 if(debug) PRINT_TRACE
4046 void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
4048 int got_indexes = 0;
4049 for( int i=0; i<new_edl->nested_edls.size(); ++i ) {
4050 EDL *nested_edl = new_edl->nested_edls[i];
4051 mainindexes->add_indexable(nested_edl);
4052 edl->nested_edls.update_index(nested_edl);
4055 for( Asset *asset=new_edl->assets->first; asset; asset=asset->next ) {
4056 mainindexes->add_indexable(asset);
4057 edl->assets->update(asset);
4060 // Start examining next batch of index files
4062 mainindexes->start_build();
4065 gui->lock_window("MWindow::stack_push");
4066 if( stack.size() < 9 ) {
4070 StackItem &item = stack.append();
4072 item.new_edl = new_edl;
4073 item.duration = new_edl->tracks->total_length();
4077 if( idxbl && idxbl->is_asset ) {
4079 Asset *asset = (Asset *)idxbl;
4080 if( asset->format == FILE_REF &&
4081 !stat(asset->path, &st) )
4082 item.mtime = st.st_mtime;
4086 strcpy(session->filename, edl->path);
4087 undo = new MainUndo(this);
4088 gui->stack_button->update();
4089 update_project(LOADMODE_REPLACE);
4091 gui->unlock_window();
4095 void MWindow::stack_pop()
4097 if( !stack.size() ) return;
4098 // writes on config_path/backup%d.xml
4101 // already have gui lock
4102 StackItem &item = stack.last();
4103 // session edl replaced, overwrite and save clip data
4104 if( item.new_edl != edl )
4105 item.new_edl->overwrite_clip(edl);
4106 Indexable *idxbl = item.idxbl;
4107 if( idxbl && idxbl->is_asset && item.mtime ) {
4108 Asset *asset = (Asset *)idxbl;
4109 if( asset->format == FILE_REF ) {
4110 char *path = asset->path;
4112 if( stat(path, &st) || item.mtime == st.st_mtime ) {
4113 int cw = xS(250), ch = yS(150), px, py;
4114 gui->get_pop_cursor(px, py);
4115 px -= cw/2; py -= ch/2;
4116 ConfirmRefWindow confirm(this, path, px, py, cw, ch);
4117 confirm.create_objects();
4118 int result = confirm.run_window();
4121 item.new_edl->save_xml(&file, path);
4122 file.terminate_string();
4123 if(file.write_to_file(path))
4124 eprintf(_("Cant write FileREF: %s"), path);
4135 // resize the indexable edits if the new_edl duration changed
4136 double duration = item.new_edl->tracks->total_length();
4137 double dt = duration - item.duration;
4138 if( fabs(dt) > 1e-4 )
4139 edl->tracks->update_idxbl_length(idxbl->id, dt);
4140 gui->unlock_window();
4141 gui->resource_thread->close_indexable(idxbl);
4142 remove_from_caches(idxbl);
4143 IndexFile::delete_index_files(preferences, idxbl);
4144 mainindexes->add_indexable(idxbl);
4145 mainindexes->start_build();
4146 awindow->gui->async_update_assets();
4147 gui->lock_window("MWindow::stack_pop");
4149 strcpy(session->filename, edl->path);
4150 update_project(LOADMODE_REPLACE);
4151 undo_after(_("open edl"), LOAD_ALL);
4153 gui->stack_button->update();
4156 int MWindow::save(EDL *edl, char *filename, int stat)
4159 edl->save_xml(&file, filename);
4160 file.terminate_string();
4161 if( file.write_to_file(filename) ) {
4162 eprintf(_("Couldn't open %s"), filename);
4166 char string[BCTEXTLEN];
4167 char *filename = stack.size() ?
4168 stack[0].edl->path : session->filename;
4169 sprintf(string, _("\"%s\" %jdC written"),
4170 filename, file.length());
4171 gui->lock_window("SaveAs::run");
4172 gui->show_message(string);
4173 gui->unlock_window();
4178 int MWindow::save(int save_as)
4180 char new_path[BCTEXTLEN]; new_path[0] = 0;
4181 char *path = stack.size() ? stack[0].edl->path : session->filename;
4182 if( save_as || !path[0] ) {
4183 if( ConfirmSave::get_save_path(this, new_path) )
4185 if( stack.size() ) {
4186 strcpy(path, new_path);
4187 set_titlebar(new_path);
4190 set_filename(new_path);
4191 gui->mainmenu->add_load(new_path);
4194 for( int i=stack.size(); --i>=0; ) {
4195 StackItem &item = stack[i];
4196 Indexable *idxbl = item.idxbl;
4197 if( !idxbl ) continue;
4198 if( idxbl->is_asset ) {
4199 Asset *asset = (Asset *)idxbl;
4200 if( asset->format == FILE_REF ) {
4201 if( save(item.new_edl, asset->path, 0) )
4205 else if( item.new_edl != idxbl )
4206 item.new_edl->overwrite_clip((EDL*)idxbl);
4208 EDL *new_edl = stack.size() ? stack[0].edl : edl;
4209 save(new_edl, path, 1);
4213 void MWindow::show_plugins()
4215 for( Track *track=edl->tracks->first; track; track=track->next ) {
4216 for( int i=0; i<track->plugin_set.size(); ++i ) {
4217 PluginSet *plugins = track->plugin_set[i];
4218 Plugin *plugin = plugins->get_first_plugin();
4219 for( ; plugin; plugin=(Plugin*)plugin->next ) {
4220 if( plugin->plugin_type == PLUGIN_STANDALONE &&
4222 show_plugin(plugin);
4228 void MWindow::clip_to_media()
4230 if( edl->session->proxy_scale != 1 ) {
4231 eprintf("Nesting not allowed when proxy scale != 1");
4235 awindow->gui->stop_vicon_drawing();
4236 int clips_total = session->drag_clips->total;
4237 for( int i=0; i<clips_total; ++i ) {
4238 EDL *clip = session->drag_clips->values[i];
4239 time_t dt; time(&dt);
4240 struct tm dtm; localtime_r(&dt, &dtm);
4241 char path[BCTEXTLEN], *cp = path, *ep = cp+sizeof(path)-1;
4242 // path_basename = "Nested_<date>-<time>_<basename>"
4243 cp += snprintf(cp, ep-cp, _("Nested_%02d%02d%02d-%02d%02d%02d_"),
4244 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
4245 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
4246 char *bp = strrchr(clip->local_session->clip_title, '/');
4247 bp = bp ? bp+1 : clip->local_session->clip_title;
4248 cp += snprintf(cp, ep-cp, "%s", bp);
4249 EDL *nested = edl->new_nested_clip(clip, path);
4250 edl->clips.remove(clip);
4251 clip->remove_user();
4252 mainindexes->add_indexable(nested);
4254 undo_after(_("clip2media"), LOAD_ALL);
4255 mainindexes->start_build();
4256 awindow->gui->async_update_assets();
4259 void MWindow::media_to_clip()
4262 int assets_total = session->drag_assets->total;
4263 for( int i=0; i<assets_total; ++i ) {
4264 Indexable *idxbl = session->drag_assets->values[i];
4265 if( idxbl->is_asset ) {
4266 eprintf(_("media is not EDL:\n%s"), idxbl->path);
4269 char clip_title[BCSTRLEN];
4273 sprintf(clip_title, _("Clip %d"), session->clip_number++);
4274 for( int i=0; name_ok && i<edl->clips.size(); ++i ) {
4275 char *title = edl->clips[i]->local_session->clip_title;
4276 if( !strcasecmp(clip_title, title) ) name_ok = 0;
4279 EDL *nested = (EDL *)idxbl;
4280 EDL *clip = edl->add_clip(nested);
4281 strcpy(clip->local_session->clip_title, clip_title);
4282 snprintf(clip->local_session->clip_notes,
4283 sizeof(clip->local_session->clip_notes),
4284 _("From: %s"), nested->path);
4286 undo_after(_("media2clip"), LOAD_ALL);
4287 awindow->gui->async_update_assets();
4290 int MWindow::create_ref(Asset *asset, EDL *ref)
4292 asset->format = FILE_REF;
4293 double secs = ref->tracks->total_length();
4294 int audio_channels = ref->session->audio_channels;
4295 asset->audio_data = audio_channels > 0 ? 1 : 0;
4296 asset->channels = audio_channels;
4297 asset->sample_rate = ref->session->sample_rate;
4298 asset->audio_length = audio_channels > 0 && secs > 0 ?
4299 secs * asset->sample_rate : 0;
4300 strcpy(asset->acodec, _("reference"));
4302 int video_layers = ref->session->video_channels;
4303 asset->video_data = video_layers > 0 ? 1 : 0;
4304 asset->layers = video_layers > 0 ? 1 : 0;
4305 asset->actual_width = ref->session->output_w;
4306 asset->actual_height = ref->session->output_h;
4307 asset->width = asset->actual_width;
4308 asset->height = asset->actual_height;
4309 asset->frame_rate = ref->session->frame_rate;
4310 asset->video_length = video_layers > 0 && secs > 0 ?
4311 secs * asset->frame_rate : 0;
4312 strcpy(asset->vcodec, _("reference"));
4316 void MWindow::update_preferences(Preferences *prefs)
4318 if( prefs != preferences )
4319 preferences->copy_from(prefs);
4320 if( cwindow->playback_engine )
4321 cwindow->playback_engine->update_preferences(prefs);
4322 for(int i = 0; i < vwindows.size(); i++) {
4323 VWindow *vwindow = vwindows[i];
4324 if( !vwindow->is_running() ) continue;
4325 if( vwindow->playback_engine )
4326 vwindow->playback_engine->update_preferences(prefs);
4328 for(int i = 0; i < zwindows.size(); i++) {
4329 ZWindow *zwindow = zwindows[i];
4330 if( !zwindow->is_running() ) continue;
4331 if( zwindow->zgui->playback_engine )
4332 zwindow->zgui->playback_engine->update_preferences(prefs);
4336 void MWindow::update_vwindow()
4338 for( int i=0; i<vwindows.size(); ++i ) {
4339 VWindow *vwindow = vwindows[i];
4340 if( vwindow->is_running() ) {
4341 vwindow->gui->lock_window("MWindow::update_vwindow");
4343 vwindow->gui->unlock_window();
4348 void MWindow::remove_indexfile(Indexable *indexable)
4350 if( !indexable->is_asset ) return;
4352 IndexFile::delete_index_files(preferences, indexable);
4355 void MWindow::rebuild_indices()
4357 for(int i = 0; i < session->drag_assets->total; i++)
4359 Indexable *indexable = session->drag_assets->get(i);
4360 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4361 remove_indexfile(indexable);
4362 // Schedule index build
4363 indexable->index_state->remove_user();
4364 indexable->index_state = new IndexState;
4365 IndexFile::delete_index_files(preferences, indexable);
4366 if( indexable->is_asset ) {
4367 Asset *asset = (Asset *)indexable;
4368 if( asset->format != FILE_PCM ) {
4369 asset->format = FILE_UNKNOWN;
4370 asset->reset_audio();
4372 asset->reset_video();
4373 remove_from_caches(asset);
4374 // File file; // re-probe the asset
4375 // file.open_file(preferences, asset, 1, 0);
4377 mainindexes->add_indexable(indexable);
4379 // still in render engine
4380 sync_parameters(CHANGE_ALL);
4381 awindow->gui->async_update_assets();
4382 mainindexes->start_build();
4386 void MWindow::get_backup_path(char *path, int len)
4388 char *cp = path, *ep = cp + len-1;
4389 cp += snprintf(cp, ep-cp, "%s/", File::get_config_path());
4390 int idx = stack.size();
4391 cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx);
4394 void MWindow::create_timestamped_copy_from_previous_backup(char *previouspath)
4396 if (previouspath == NULL) return;
4397 char backup_path[BCTEXTLEN];
4399 time_t now = time(NULL);
4400 struct tm* currenttime = localtime(&now);
4401 snprintf(backup_path, sizeof(backup_path),
4402 "%s/%s_%d%.2d%.2d_%.2d%.2d%.2d",
4403 File::get_config_path(), BACKUP_FILE1,
4404 currenttime->tm_year + 1900,
4405 currenttime->tm_mon + 1,
4406 currenttime->tm_mday,
4407 currenttime->tm_hour,
4408 currenttime->tm_min,
4409 currenttime->tm_sec);
4410 rename(previouspath, backup_path);
4413 void MWindow::save_backup()
4417 edl->set_path(session->filename);
4419 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
4420 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
4421 File::get_config_path(), BACKUP_FILE1);
4422 get_backup_path(backup_path, sizeof(backup_path));
4423 if( preferences->ongoing_backups )
4424 create_timestamped_copy_from_previous_backup(backup_path1);
4425 rename(backup_path, backup_path1);
4426 edl->save_xml(&file, backup_path);
4427 file.terminate_string();
4429 fs.complete_path(backup_path);
4431 if(file.write_to_file(backup_path)) {
4433 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
4434 gui->show_message(string2);
4439 void MWindow::load_backup()
4441 ArrayList<char*> path_list;
4442 path_list.set_array_delete();
4444 char backup_path[BCTEXTLEN];
4445 get_backup_path(backup_path, sizeof(backup_path));
4447 fs.complete_path(backup_path);
4449 path_list.append(out_path = new char[strlen(backup_path) + 1]);
4450 strcpy(out_path, backup_path);
4452 load_filenames(&path_list, LOADMODE_REPLACE, LOADMODE_EDL_CLIP, 0);
4453 edl->local_session->clip_title[0] = 0;
4454 // This is unique to backups since the path of the backup is different than the
4455 // path of the project.
4456 set_filename(edl->path);
4457 path_list.remove_all_objects();
4462 void MWindow::save_undo_data()
4464 if( stack.size() > 0 ) return;
4465 if( !preferences->perpetual_session ) return;
4466 char perpetual_path[BCTEXTLEN];
4467 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4468 File::get_config_path(), PERPETUAL_FILE);
4469 FILE *fp = fopen(perpetual_path,"w");
4475 void MWindow::load_undo_data()
4477 if( stack.size() > 0 ) return;
4478 if( !preferences->perpetual_session ) return;
4479 char perpetual_path[BCTEXTLEN];
4480 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4481 File::get_config_path(), PERPETUAL_FILE);
4482 FILE *fp = fopen(perpetual_path,"r");
4486 undo_after(_("perpetual load"), LOAD_ALL);
4490 void MWindow::remove_undo_data()
4492 if( stack.size() > 0 ) return;
4493 char perpetual_path[BCTEXTLEN];
4494 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4495 File::get_config_path(), PERPETUAL_FILE);
4496 ::remove(perpetual_path);
4499 int MWindow::copy_target(const char *path, const char *target)
4501 int ifd = ::open(path, O_RDONLY);
4503 eprintf("Cannot open asset: %s", path);
4507 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
4510 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
4511 char progress_title[BCTEXTLEN];
4512 sprintf(progress_title, _("Copying: %s\n"), target);
4513 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
4515 int64_t count = 0, len = -1;
4516 int bfrsz = 0x100000;
4517 uint8_t *bfr = new uint8_t[bfrsz];
4518 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
4519 if( len != ::write(ofd, bfr, len) ) {
4520 eprintf("Error writing: %s", target);
4523 if( progress.is_cancelled() ) {
4527 progress.update(count += len, 1);
4532 progress.stop_progress();
4534 eprintf("Error reading: %s", path);
4539 eprintf("Cannot create asset target: %s", target);
4544 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
4546 char target[BCTEXTLEN];
4548 const char *bp = real_path, *cp = bp;
4549 const char *lp = link_path, *np = lp;
4550 char *tp = target, *ep = tp+sizeof(target)-1, lch;
4551 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
4552 if( lch == '/' ) { np = lp; cp = bp; }
4554 while( tp<ep && *np ) {
4555 if( *np++ != '/' ) continue;
4556 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
4558 while( tp<ep && *cp ) *tp++ = *cp++;
4562 strcpy(target, real_path);
4563 if( symlink(target, link_path) ) {
4564 eprintf("Cannot create symlink: %s", link_path);
4570 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
4572 char dir_path[BCTEXTLEN];
4573 strcpy(dir_path, dir);
4575 fs.complete_path(dir_path);
4578 if( !stat(dir_path, &st) ) {
4579 if( !S_ISDIR(st.st_mode) ) {
4580 eprintf("Path exists and is not a directory\n%s", dir_path);
4585 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
4586 eprintf("Cannot create directory\n%s", dir_path);
4590 char *real_dir = realpath(dir_path, 0);
4591 strcpy(dir_path, real_dir);
4594 EDL *save_edl = new EDL;
4595 save_edl->create_objects();
4596 save_edl->copy_all(edl);
4598 char progress_title[BCTEXTLEN];
4599 sprintf(progress_title, _("Saving to %s:\n"), dir);
4600 int total_assets = save_edl->assets->total();
4601 gui->lock_window("MWindow::save_project");
4602 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
4603 gui->unlock_window();
4606 Asset *current = save_edl->assets->first;
4607 for( int i=0; !ret && current; ++i, current=NEXT ) {
4608 char *path = current->path;
4609 if( ::stat(path, &st) ) {
4610 eprintf("Asset not found: %s", path);
4613 char *real_path = realpath(path, 0);
4614 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
4615 char link_path[BCTEXTLEN];
4616 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
4618 if( strcmp(real_path, link_path) ) {
4619 if( !::lstat(link_path, &st) ) {
4621 ::remove(link_path);
4627 eprintf("copy/link to self, skippped: %s", path);
4631 if( save_mode == SAVE_PROJECT_COPY ) {
4632 if( copy_target(real_path, link_path) )
4636 link_target(real_path, link_path,
4637 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
4641 strcpy(path, link_path);
4643 if( progress->is_cancelled() ) break;
4644 progress->update(i);
4647 progress->stop_progress();
4650 char *cp = strrchr(dir_path,'/');
4651 char *bp = cp ? cp+1 : dir_path;
4652 char filename[BCTEXTLEN];
4653 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
4654 save_edl->set_path(filename);
4656 save_edl->save_xml(&file, filename);
4657 file.terminate_string();
4659 if( !file.write_to_file(filename) ) {
4660 char string[BCTEXTLEN];
4661 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
4662 gui->lock_window("SaveProject::run 2");
4663 gui->show_message(string);
4664 gui->unlock_window();
4665 gui->mainmenu->add_load(filename);
4668 eprintf(_("Couldn't open %s."), filename);
4670 save_edl->remove_user();
4673 gui->lock_window("MWindow::save_project");
4674 ArrayList<char*> filenames;
4675 filenames.append(filename);
4676 load_filenames(&filenames);
4677 gui->unlock_window();
4682 static inline int gcd(int m, int n)
4685 if( m < n ) { r = m; m = n; n = r; }
4686 while( (r = m % n) != 0 ) { m = n; n = r; }
4690 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4695 if(!width || !height) return 1;
4696 if( width == 720 && (height == 480 || height == 576) ) {
4697 w = 4; h = 3; return 0; // for NTSC and PAL
4700 ar = (double)width / height;
4701 // square-ish pixels
4702 if( EQUIV(ar, 1.0000) ) return 0;
4703 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4704 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4705 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4706 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4707 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4708 if( EQUIV(ar, 2.37037) ) { w = 64; h = 27; return 0; }
4710 int ww = width, hh = height;
4711 // numerator, denominator must be under mx
4712 int mx = 255, n = gcd(ww, hh);
4713 if( n > 1 ) { ww /= n; hh /= n; }
4714 // search near height in case extra/missing lines
4715 if( ww >= mx || hh >= mx ) {
4716 double err = height; // +/- 2 percent height
4717 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4718 int iw = width, ih = height+i;
4719 if( (n=gcd(iw, ih)) > 1 ) {
4720 int u = iw/n; if( u >= mx ) continue;
4721 int v = ih/n; if( v >= mx ) continue;
4722 double r = (double) u/v, er = fabs(ar-r);
4723 if( er >= err ) continue;
4724 err = er; ww = u; hh = v;
4733 void MWindow::reset_caches(int locked)
4735 if( locked ) gui->unlock_window();
4736 awindow->gui->stop_vicon_drawing(1);
4737 if( cwindow->playback_engine )
4738 cwindow->playback_engine->create_cache();
4739 for(int i = 0; i < vwindows.size(); i++) {
4740 VWindow *vwindow = vwindows[i];
4741 if( !vwindow->is_running() ) continue;
4742 if( !vwindow->playback_engine ) continue;
4743 vwindow->playback_engine->create_cache();
4745 gui->lock_window("MWindow::reset_caches");
4746 frame_cache->remove_all();
4747 wave_cache->remove_all();
4748 audio_cache->remove_all();
4749 video_cache->remove_all();
4750 if( !locked ) gui->unlock_window();
4753 void MWindow::remove_from_caches(Indexable *idxbl)
4755 awindow->gui->stop_vicon_drawing(1);
4756 frame_cache->remove_item(idxbl);
4757 wave_cache->remove_item(idxbl);
4758 if( gui->render_engine &&
4759 gui->render_engine_id == idxbl->id ) {
4760 delete gui->render_engine;
4761 gui->render_engine = 0;
4763 gui->resource_thread->close_indexable(idxbl);
4764 if( !idxbl->is_asset ) return;
4765 Asset *asset = (Asset *)idxbl;
4766 audio_cache->delete_entry(asset);
4767 video_cache->delete_entry(asset);
4768 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4769 cwindow->playback_engine->audio_cache->delete_entry(asset);
4770 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4771 cwindow->playback_engine->video_cache->delete_entry(asset);
4772 for(int i = 0; i < vwindows.size(); i++) {
4773 VWindow *vwindow = vwindows[i];
4774 if( !vwindow->is_running() ) continue;
4775 if( !vwindow->playback_engine ) continue;
4776 if( vwindow->playback_engine->audio_cache )
4777 vwindow->playback_engine->audio_cache->delete_entry(asset);
4778 if( vwindow->playback_engine->video_cache )
4779 vwindow->playback_engine->video_cache->delete_entry(asset);
4781 for(int i = 0; i < zwindows.size(); i++) {
4782 ZWindow *zwindow = zwindows[i];
4783 if( !zwindow->is_running() ) continue;
4784 if( zwindow->zgui->playback_engine->audio_cache )
4785 zwindow->zgui->playback_engine->audio_cache->delete_entry(asset);
4786 if( zwindow->zgui->playback_engine->video_cache )
4787 zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
4789 awindow->gui->start_vicon_drawing();
4792 void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
4793 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4795 awindow->gui->stop_vicon_drawing(1);
4797 // Remove from VWindow.
4799 for(int i = 0; i < drag_clips->total; i++) {
4800 for(int j = 0; j < vwindows.size(); j++) {
4801 VWindow *vwindow = vwindows[j];
4802 if( !vwindow->is_running() ) continue;
4803 if(drag_clips->get(i) == vwindow->get_edl()) {
4804 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4805 vwindow->delete_source(1, 1);
4806 vwindow->gui->unlock_window();
4813 for(int i = 0; i < drag_assets->size(); i++) {
4814 for(int j = 0; j < vwindows.size(); j++) {
4815 VWindow *vwindow = vwindows[j];
4816 if( !vwindow->is_running() ) continue;
4817 if(drag_assets->get(i) == vwindow->get_source()) {
4818 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4819 vwindow->delete_source(1, 1);
4820 vwindow->gui->unlock_window();
4825 for(int i = 0; i < drag_assets->total; i++) {
4826 Indexable *indexable = drag_assets->get(i);
4827 if(indexable->is_asset) remove_from_caches(indexable);
4830 if( delete_indexes ) {
4831 for(int i = 0; i < drag_assets->size(); i++) {
4832 Indexable *indexable = drag_assets->get(i);
4833 remove_indexfile(indexable);
4838 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4839 if(push_undo) undo_before();
4840 if(drag_assets) edl->remove_from_project(drag_assets);
4841 if(drag_clips) edl->remove_from_project(drag_clips);
4842 if(redraw) save_backup();
4843 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4847 gui->lock_window("MWindow::remove_assets_from_project 3");
4848 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4849 gui->unlock_window();
4851 // Removes from playback here
4852 sync_parameters(CHANGE_ALL);
4855 awindow->gui->async_update_assets();
4858 void MWindow::remove_assets_from_disk()
4860 remove_assets_from_project(1, 1, 1,
4861 session->drag_assets, session->drag_clips);
4864 for(int i = 0; i < session->drag_assets->total; i++)
4866 remove(session->drag_assets->get(i)->path);
4870 void MWindow::dump_plugins(FILE *fp)
4872 if( !plugindb ) return;
4873 for(int i = 0; i < plugindb->total; i++)
4875 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4876 " synth=%d transition=%d theme=%d %s\n",
4877 plugindb->get(i)->plugin_type,
4878 plugindb->get(i)->audio,
4879 plugindb->get(i)->video,
4880 plugindb->get(i)->realtime,
4881 plugindb->get(i)->multichannel,
4882 plugindb->get(i)->get_synthesis(),
4883 plugindb->get(i)->transition,
4884 plugindb->get(i)->theme,
4885 plugindb->get(i)->title);
4889 void MWindow::dump_edl(FILE *fp)
4895 void MWindow::dump_undo(FILE *fp)
4901 void MWindow::dump_exe(FILE *fp)
4903 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4904 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4906 int ret = -1, n = 100;
4907 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4908 exe_path[len] = 0; strcpy(proc_path, exe_path);
4911 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4914 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4915 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4916 struct tm *tm = localtime(&st.st_mtime);
4918 strftime(mtime, sizeof(mtime), "%F %T", tm);
4919 fprintf(fp,"mtime: %s\n", mtime);
4921 // people hit ctl-c waiting for this
4922 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4923 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4926 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4927 int64_t maxsz = 1024*pagsz;
4928 int64_t size = st.st_size, pos = 0;
4930 while( (bfrsz = size-pos) > 0 ) {
4931 if( bfrsz > maxsz ) bfrsz = maxsz;
4932 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4933 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4934 if( bfr == MAP_FAILED ) break;
4935 sha1.addBytes(bfr, bfrsz);
4940 ret = pos < size ? EIO : 0;
4941 fprintf(fp, "SHA1: ");
4942 uint8_t digest[20]; sha1.computeHash(digest);
4943 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4944 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4945 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4950 void MWindow::dump_caches(FILE *fp)
4952 fprintf(fp, "audio cache: ");
4953 audio_cache->dump(fp);
4954 fprintf(fp, "video cache: ");
4955 video_cache->dump(fp);
4958 void MWindow::trap_hook(FILE *fp, void *vp)
4960 MWindow *mwindow = (MWindow *)vp;
4961 // fprintf(fp, "\nPLUGINS:\n");
4962 // mwindow->dump_plugins(fp);
4963 fprintf(fp, "\nEDL:\n");
4964 mwindow->dump_edl(fp);
4965 fprintf(fp, "\nUNDO:\n");
4966 mwindow->dump_undo(fp);
4967 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4968 mwindow->dump_exe(fp);
4969 fprintf(fp, "\nCACHES:\n");
4970 mwindow->dump_caches(fp);
4978 int MWindow::save_defaults()
4980 gui->save_defaults(defaults);
4981 edl->save_defaults(defaults);
4982 session->save_defaults(defaults);
4983 preferences->save_defaults(defaults);
4985 for(int i = 0; i < plugin_guis->total; i++)
4987 // Pointer comparison
4988 plugin_guis->get(i)->save_defaults();
4990 awindow->save_defaults(defaults);
4996 int MWindow::run_script(FileXML *script)
4998 int result = 0, result2 = 0;
4999 while(!result && !result2)
5001 result = script->read_tag();
5004 if(script->tag.title_is("new_project"))
5006 // Run new in immediate mode.
5007 // gui->mainmenu->new_project->run_script(script);
5010 if(script->tag.title_is("record"))
5012 // Run record as a thread. It is a terminal command.
5014 // Will read the complete scipt file without letting record read it if not
5020 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
5027 // ================================= synchronization
5030 int MWindow::interrupt_indexes()
5032 mainprogress->cancelled = 1;
5033 mainindexes->interrupt_build();
5039 void MWindow::next_time_format()
5041 switch( edl->session->time_format ) {
5042 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
5043 case TIME_HMSF: edl->session->time_format = TIME_TIMECODE; break;
5044 case TIME_TIMECODE: edl->session->time_format = TIME_FRAMES; break;
5045 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES; break;
5046 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
5047 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SECONDS; break;
5048 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
5049 case TIME_FEET_FRAMES: edl->session->time_format = TIME_HMS; break;
5051 time_format_common();
5054 void MWindow::prev_time_format()
5056 switch( edl->session->time_format ) {
5057 case TIME_HMS: edl->session->time_format = TIME_FEET_FRAMES; break;
5058 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
5059 case TIME_TIMECODE: edl->session->time_format = TIME_HMSF; break;
5060 case TIME_FRAMES: edl->session->time_format = TIME_TIMECODE; break;
5061 case TIME_SAMPLES: edl->session->time_format = TIME_FRAMES; break;
5062 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
5063 case TIME_SECONDS: edl->session->time_format = TIME_SAMPLES_HEX; break;
5064 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
5067 time_format_common();
5070 void MWindow::time_format_common()
5072 gui->lock_window("MWindow::next_time_format");
5073 gui->redraw_time_dependancies();
5076 char string[BCTEXTLEN], string2[BCTEXTLEN];
5077 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
5078 gui->show_message(string);
5080 gui->unlock_window();
5084 int MWindow::set_filename(const char *filename)
5086 if( filename != session->filename )
5087 strcpy(session->filename, filename);
5088 if( filename != edl->path )
5089 strcpy(edl->path, filename);
5090 return set_titlebar(filename);
5093 int MWindow::set_titlebar(const char *filename)
5095 if( !gui ) return 0;
5098 char string[BCTEXTLEN], string2[BCTEXTLEN];
5099 dir.extract_name(string, filename);
5100 sprintf(string2, PROGRAM_NAME ": %s", string);
5101 gui->set_title(string2);
5104 gui->set_title(PROGRAM_NAME);
5109 int MWindow::set_loop_boundaries()
5111 double start = edl->local_session->get_selectionstart();
5112 double end = edl->local_session->get_selectionend();
5120 if(edl->tracks->total_length())
5123 end = edl->tracks->total_length();
5130 if(edl->local_session->loop_playback && start != end)
5132 edl->local_session->loop_start = start;
5133 edl->local_session->loop_end = end;
5144 int MWindow::reset_meters()
5146 cwindow->gui->lock_window("MWindow::reset_meters 1");
5147 cwindow->gui->meters->reset_meters();
5148 cwindow->gui->unlock_window();
5150 for(int j = 0; j < vwindows.size(); j++) {
5151 VWindow *vwindow = vwindows[j];
5152 if( !vwindow->is_running() ) continue;
5153 vwindow->gui->lock_window("MWindow::reset_meters 2");
5154 vwindow->gui->meters->reset_meters();
5155 vwindow->gui->unlock_window();
5158 lwindow->gui->lock_window("MWindow::reset_meters 3");
5159 lwindow->gui->panel->reset_meters();
5160 lwindow->gui->unlock_window();
5162 gui->lock_window("MWindow::reset_meters 4");
5163 gui->reset_meters();
5164 gui->unlock_window();
5169 void MWindow::resync_guis()
5173 gui->lock_window("MWindow::resync_guis");
5174 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
5175 gui->unlock_window();
5177 cwindow->gui->lock_window("MWindow::resync_guis");
5178 cwindow->gui->resize_event(cwindow->gui->get_w(),
5179 cwindow->gui->get_h());
5180 int channels = edl->session->audio_channels;
5181 cwindow->gui->meters->set_meters(channels, 1);
5182 cwindow->gui->flush();
5183 cwindow->gui->unlock_window();
5185 for(int i = 0; i < vwindows.size(); i++) {
5186 VWindow *vwindow = vwindows[i];
5187 if( !vwindow->is_running() ) continue;
5188 vwindow->gui->lock_window("MWindow::resync_guis");
5189 vwindow->gui->resize_event(vwindow->gui->get_w(),
5190 vwindow->gui->get_h());
5191 vwindow->gui->meters->set_meters(channels, 1);
5192 vwindow->gui->flush();
5193 vwindow->gui->unlock_window();
5196 lwindow->gui->lock_window("MWindow::resync_guis");
5197 lwindow->gui->panel->set_meters(channels, 1);
5198 lwindow->gui->flush();
5199 lwindow->gui->unlock_window();
5202 if(((edl->session->output_w % 4) ||
5203 (edl->session->output_h % 4)) &&
5204 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
5206 MainError::show_error(
5207 _("This project's dimensions are not multiples of 4 so\n"
5208 "it can't be rendered by OpenGL."));
5213 sync_parameters(CHANGE_ALL);
5216 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
5218 File *file = new File;
5219 EDLSession *session = edl->session;
5220 double old_framerate = session->frame_rate;
5221 double old_samplerate = session->sample_rate;
5222 int old_auto_keyframes = session->auto_keyframes;
5223 session->auto_keyframes = 0;
5224 int result = file->open_file(preferences, asset, 1, 0);
5225 if( !result && delete_tracks > 0 )
5227 int video_layers = asset->get_video_layers();
5228 if( !result && asset->video_data && vstream < video_layers ) {
5229 // try to get asset up to date, may fail
5230 file->select_video_stream(asset, vstream);
5231 // either way use what was/is there.
5232 double framerate = asset->get_frame_rate();
5233 int width = asset->get_w();
5234 int height = asset->get_h();
5236 // must be multiple of 4 for opengl
5237 width = (width+3) & ~3; height = (height+3) & ~3;
5239 int driver = session->playback_config->vconfig->driver;
5240 int color_model = file->get_best_colormodel(asset, driver);
5241 // color_model = BC_CModels::is_yuv(color_model) ?
5242 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
5243 // BC_CModels::is_float(color_model) ?
5244 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
5245 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
5246 // have alpha for now
5247 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
5248 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
5249 session->color_model = color_model;
5250 session->output_w = width;
5251 session->output_h = height;
5252 session->frame_rate = framerate;
5253 session->interlace_mode = asset->interlace_mode;
5254 // not, asset->actual_width/actual_height
5255 asset->width = session->output_w;
5256 asset->height = session->output_h;
5257 asset->frame_rate = session->frame_rate;
5259 create_aspect_ratio(session->aspect_w, session->aspect_h,
5260 session->output_w, session->output_h);
5261 float ar = asset->aspect_ratio;
5263 //printf ("Aspect ratio from asset: %f \n", ar);
5264 if( EQUIV(ar, 1.3333) ) { session->aspect_w = 4; session->aspect_h = 3; }
5265 if( EQUIV(ar, 1.7777) ) { session->aspect_w = 16; session->aspect_h = 9; }
5266 if( EQUIV(ar, 2.1111) ) { session->aspect_w = 19; session->aspect_h = 9; }
5267 if( EQUIV(ar, 2.2222) ) { session->aspect_w = 20; session->aspect_h = 9; }
5268 if( EQUIV(ar, 2.3333) ) { session->aspect_w = 21; session->aspect_h = 9; }
5269 if( EQUIV(ar, 2.370370) ) { session->aspect_w = 64; session->aspect_h = 27; }
5273 Track *track = edl->tracks->first;
5274 for( Track *next_track=0; track; track=next_track ) {
5275 next_track = track->next;
5276 if( track->data_type != TRACK_VIDEO ) continue;
5277 if( delete_tracks ) {
5278 Edit *edit = track->edits->first;
5279 for( Edit *next_edit=0; edit; edit=next_edit ) {
5280 next_edit = edit->next;
5281 if( edit->channel != vstream ||
5282 !edit->asset || !edit->asset->is_asset ||
5283 !asset->equivalent(*edit->asset,1,1,edl) )
5287 if( track->edits->first ) {
5288 track->track_w = edl->session->output_w;
5289 track->track_h = edl->session->output_h;
5291 else if( delete_tracks )
5292 edl->tracks->delete_track(track, 0);
5295 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
5297 if( !result && asset->audio_data && asset->channels > 0 ) {
5298 session->sample_rate = asset->get_sample_rate();
5299 int64_t channel_mask = 0;
5300 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
5301 file->get_audio_for_video(vstream, astream, channel_mask);
5302 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
5303 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
5305 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
5306 if( channels < 1 ) channels = 1;
5307 if( channels > MAXCHANNELS ) channels = MAXCHANNELS;
5308 session->audio_tracks = session->audio_channels = channels;
5310 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
5311 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
5312 remap_audio(MWindow::AUDIO_1_TO_1);
5314 if( delete_tracks ) {
5315 Track *track = edl->tracks->first;
5316 for( Track *next_track=0; track; track=next_track ) {
5317 next_track = track->next;
5318 if( track->data_type != TRACK_AUDIO ) continue;
5319 Edit *edit = track->edits->first;
5320 for( Edit *next_edit=0; edit; edit=next_edit ) {
5321 next_edit = edit->next;
5322 if( !((1<<edit->channel) & channel_mask) ||
5323 !edit->asset || !edit->asset->is_asset ||
5324 !asset->equivalent(*edit->asset,1,1,edl) )
5327 if( !track->edits->first )
5328 edl->tracks->delete_track(track, 0);
5332 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
5335 session->auto_keyframes = old_auto_keyframes;
5336 if( !result && delete_tracks > 0 ) {
5338 undo_after(_("select asset"), LOAD_ALL);
5344 int MWindow::select_asset(int vtrack, int delete_tracks)
5346 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
5348 track = edl->tracks->get(vtrack, TRACK_AUDIO);
5349 if( !track ) return 1;
5350 Edit *edit = track->edits->first;
5351 if( !edit ) return 1;
5352 Asset *asset = edit->asset;
5353 if( !asset || !asset->is_asset ) return 1;
5354 return select_asset(asset, edit->channel, 0, delete_tracks);
5357 void MWindow::dump_plugindb(FILE *fp)
5359 if( !plugindb ) return;
5360 for(int i = 0; i < plugindb->total; i++)
5361 plugindb->get(i)->dump(fp);
5364 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
5367 double unit_position = edl->local_session->get_selectionstart(1);
5368 unit_position = patch->track->to_units(unit_position, 0);
5370 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
5371 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5374 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
5377 double unit_position = edl->local_session->get_selectionstart(1);
5378 unit_position = patch->track->to_units(unit_position, 0);
5380 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
5381 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5384 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
5387 double unit_position = edl->local_session->get_selectionstart(1);
5388 unit_position = patch->track->to_units(unit_position, 0);
5390 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
5391 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5394 PatchGUI *MWindow::get_patchgui(Track *track)
5396 PatchGUI *patchgui = 0;
5397 TimelinePane **panes = gui->pane;
5398 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
5399 if( !panes[i] ) continue;
5400 PatchBay *patchbay = panes[i]->patchbay;
5401 if( !patchbay ) continue;
5402 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
5403 if( patchbay->patches.values[j]->track == track )
5404 patchgui = patchbay->patches.values[j];
5410 int MWindow::get_cpus(int out_w, int out_h)
5412 if( !out_w ) out_w = edl->session->output_w;
5413 if( !out_h ) out_h = edl->session->output_h;
5414 int cpus = out_w*out_h/0x80000 + 1;
5415 if( cpus > preferences->processors )
5416 cpus = preferences->processors;
5419 int MWindow::get_cpus()
5421 return get_cpus(edl->session->output_w, edl->session->output_h);
5424 void MWindow::draw_trackmovement()
5426 if( !redraw_tracks )
5427 redraw_tracks = new DrawTrackMovement(this);
5428 redraw_tracks->start();
5431 DrawTrackMovement::DrawTrackMovement(MWindow *mwindow)
5434 this->mwindow = mwindow;
5436 DrawTrackMovement::~DrawTrackMovement()
5441 void DrawTrackMovement::run()
5443 mwindow->gui->lock_window("DrawTrackMovement::run");
5444 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
5445 mwindow->gui->draw_trackmovement();
5446 mwindow->gui->unlock_window();
5450 ConfirmRefWindow::ConfirmRefWindow(MWindow *mwindow, char *path,
5451 int px, int py, int cw, int ch)
5452 : BC_Window(_(PROGRAM_NAME ": Confirm update"), px, py, cw, ch, cw, ch)
5454 this->mwindow = mwindow;
5456 // *** CONTEXT_HELP ***
5457 context_help_set_keyword("File by Reference");
5460 ConfirmRefWindow::~ConfirmRefWindow()
5464 void ConfirmRefWindow::create_objects()
5466 lock_window("ConfirmRefWindow::create_objects()");
5467 int x = xS(10), y = yS(10), pad = yS(5);
5469 add_subwindow(title = new BC_Title(x, y, _("FileREF not updated:")));
5470 y += title->get_h() + pad;
5471 BC_TextBox *text_box;
5472 add_subwindow(text_box = new BC_TextBox(x,y, get_w()-2*x, 1, path));
5473 y += text_box->get_h() + 2*pad;
5474 add_subwindow(title = new BC_Title(x, y, _("Save file ref changes?")));
5475 add_subwindow(new BC_OKButton(this));
5476 add_subwindow(new BC_CancelButton(this));