3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "aboutprefs.h"
25 #include "audioalsa.h"
27 #include "awindowgui.h"
29 #include "batchrender.h"
30 #include "bccmodels.h"
31 #include "bcdisplayinfo.h"
32 #include "bcprogressbox.h"
33 #include "bcsignals.h"
40 #include "channeldb.h"
41 #include "channelinfo.h"
44 #include "commercials.h"
45 #include "confirmsave.h"
47 #include "cplayback.h"
49 #include "cwindowgui.h"
51 #include "cwindowtool.h"
53 #include "devicedvbinput.inc"
54 #include "dvdcreate.h"
55 #include "editpanel.h"
57 #include "edlsession.h"
59 #include "fileformat.h"
61 #include "filesystem.h"
63 #include "floatautos.h"
64 #include "framecache.h"
66 #include "gwindowgui.h"
67 #include "keyframegui.h"
68 #include "indexfile.h"
70 #include "interlacemodes.h"
72 #include "levelwindowgui.h"
73 #include "levelwindow.h"
74 #include "loadfile.inc"
75 #include "localsession.h"
76 #include "maincursor.h"
77 #include "mainerror.h"
78 #include "mainindexes.h"
80 #include "mainprogress.h"
81 #include "mainsession.h"
84 #include "mixersalign.h"
86 #include "mwindowgui.h"
91 #include "playback3d.h"
92 #include "playbackengine.h"
94 #include "pluginserver.h"
95 #include "pluginset.h"
96 #include "preferences.h"
99 #include "recordmonitor.h"
100 #include "recordlabel.h"
101 #include "removefile.h"
103 #include "resourcethread.h"
104 #include "savefile.inc"
105 #include "samplescroll.h"
108 #include "sighandler.h"
109 #include "splashgui.h"
110 #include "statusbar.h"
112 #include "threadloader.h"
114 #include "timelinepane.h"
115 #include "tipwindow.h"
116 #include "trackcanvas.h"
118 #include "tracking.h"
119 #include "trackscroll.h"
121 #include "transition.h"
122 #include "transportque.h"
125 #include "versioninfo.h"
127 #include "videodevice.inc"
128 #include "videowindow.h"
129 #include "vplayback.h"
130 #include "vwindowgui.h"
132 #include "wavecache.h"
138 #include "zwindowgui.h"
139 #include "exportedl.h"
141 #include "defaultformats.h"
142 #include "ntsczones.h"
149 #include <sys/types.h>
150 #include <sys/stat.h>
151 #include <sys/time.h>
152 #include <sys/mman.h>
153 #include <sys/file.h>
164 // Hack for libdv to remove glib dependancy
167 // g_log (const char *log_domain,
169 // const char *format,
175 // g_logv (const char *log_domain,
177 // const char *format,
185 extern long cin_timezone;
187 ArrayList<PluginServer*>* MWindow::plugindb = 0;
188 Commercials* MWindow::commercials = 0;
194 run_lock = new Mutex("MWindow::run_lock");
195 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
196 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
197 vwindows_lock = new Mutex("MWindow::vwindows_lock");
198 zwindows_lock = new Mutex("MWindow::zwindows_lock");
199 brender_lock = new Mutex("MWindow::brender_lock");
200 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
205 undo_command = COMMAND_NONE;
209 commercial_active = 0;
221 strcpy(cin_lang,"en");
222 channeldb_buz = new ChannelDB;
223 channeldb_v4l2jpeg = new ChannelDB;
226 keyframe_threads = 0;
254 // Need to delete brender temporary here.
257 run_lock->lock("MWindow::~MWindow");
259 //printf("MWindow::~MWindow %d\n", __LINE__);
260 if( wwindow && wwindow->is_running() )
261 wwindow->close_window();
262 if( twindow && twindow->is_running() )
263 twindow->close_window();
264 gui->remote_control->deactivate();
267 gui->channel_info->stop();
269 delete beeper; beeper = 0;
270 delete redraw_tracks; redraw_tracks = 0;
271 delete create_bd; create_bd = 0;
272 delete create_dvd; create_dvd = 0;
274 delete shuttle; shuttle = 0;
277 delete wintv; wintv = 0;
280 delete x10tv; x10tv = 0;
282 delete batch_render; batch_render = 0;
283 delete convert_render; convert_render = 0;
284 delete render; render = 0;
285 delete mixers_align; mixers_align = 0;
286 #ifdef HAVE_COMMERCIALS
288 if( commercials && !commercials->remove_user() ) commercials = 0;
291 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
292 // Save defaults for open plugins
293 plugin_gui_lock->lock("MWindow::~MWindow");
294 for(int i = 0; i < plugin_guis->size(); i++) {
295 plugin_guis->get(i)->hide_gui();
296 delete_plugin(plugin_guis->get(i));
298 plugin_gui_lock->unlock();
299 hide_keyframe_guis();
303 // Give up and go to a movie
304 // cant run valgrind if this is used
306 gui->del_keyboard_listener(
307 (int (BC_WindowBase::*)(BC_WindowBase *))
308 &MWindowGUI::keyboard_listener);
311 // release the hounds
312 if( awindow && awindow->gui ) awindow->gui->close(0);
313 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
314 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
315 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
316 vwindows.remove_all_objects();
317 zwindows.remove_all_objects();
319 if( awindow ) awindow->join();
320 if( cwindow ) cwindow->join();
321 if( lwindow ) lwindow->join();
322 if( gwindow ) gwindow->join();
325 // one at a time, or nouveau chokes
326 #define close_gui(win) if( win ) { \
327 if( win->gui ) win->gui->close(0); \
333 vwindows.remove_all_objects();
334 zwindows.remove_all_objects();
338 dead_plugins->remove_all_objects();
339 // must delete theme before destroying plugindb
340 // theme destructor will be deleted by delete_plugins
341 delete theme; theme = 0;
344 keyframe_threads->remove_all_objects();
345 colormodels.remove_all_objects();
346 delete awindow; awindow = 0;
347 delete lwindow; lwindow = 0;
348 delete twindow; twindow = 0;
349 delete wwindow; wwindow = 0;
350 delete gwindow; gwindow = 0;
351 delete cwindow; cwindow = 0;
353 delete mainindexes; mainindexes = 0;
354 delete mainprogress; mainprogress = 0;
355 // delete the caches after the assets
356 if( audio_cache ) { audio_cache->remove_user(); audio_cache = 0; }
357 if( video_cache ) { video_cache->remove_user(); video_cache = 0; }
358 delete frame_cache; frame_cache = 0;
359 delete wave_cache; wave_cache = 0;
360 delete plugin_guis; plugin_guis = 0;
361 delete dead_plugins; dead_plugins = 0;
362 delete keyframe_threads; keyframe_threads = 0;
363 delete undo; undo = 0;
364 delete preferences; preferences = 0;
365 delete exportedl; exportedl = 0;
366 delete session; session = 0;
367 delete defaults; defaults = 0;
368 delete assets; assets = 0;
369 delete splash_window; splash_window = 0;
370 if( !edl->Garbage::remove_user() ) edl = 0;
371 delete channeldb_buz;
372 delete channeldb_v4l2jpeg;
373 // This must be last thread to exit
374 delete playback_3d; playback_3d = 0;
375 delete dead_plugin_lock;
376 delete plugin_gui_lock;
377 delete vwindows_lock;
378 delete zwindows_lock;
380 delete keyframe_gui_lock;
381 colormodels.remove_all_objects();
382 interlace_project_modes.remove_all_objects();
383 interlace_asset_modes.remove_all_objects();
384 sighandler->terminate();
395 void MWindow::init_error()
397 MainError::init_error(this);
400 void MWindow::finit_error()
402 MainError::finit_error();
405 void MWindow::create_defaults_path(char *string, const char *config_file)
407 // set the .bcast path
410 sprintf(string, "%s/", File::get_config_path());
411 fs.complete_path(string);
412 if(!fs.is_dir(string))
413 fs.create_dir(string);
416 strcat(string, config_file);
418 const char *MWindow::default_std()
420 char buf[BCTEXTLEN], *p = 0;
422 int fd = open(TIMEZONE_NAME, O_RDONLY);
424 int l = read(fd, buf, sizeof(buf)-1);
427 if( buf[l-1] == '\n' ) --l;
433 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
436 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
437 p += strlen(ZONEINFO_STR);
442 for( int i=0; ntsc_zones[i]; ++i ) {
443 if( !strcmp(ntsc_zones[i], p) )
450 for( int i=0; ntsc_zones[i]; ++i ) {
451 if( !strcmp(ntsc_zones[i], p) )
456 // cin_timezone: Seconds west of UTC. 240sec/deg
457 double tz_deg = -cin_timezone / 240.;
458 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
459 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
462 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
464 struct formatpresets *fpr;
466 for(fpr = &format_presets[0]; fpr->name; fpr++)
468 if(strcmp(_(fpr->name), preset) == 0)
470 session->audio_channels = fpr->audio_channels;
471 session->audio_tracks = fpr->audio_tracks;
472 session->sample_rate = fpr->sample_rate;
473 session->video_channels = fpr->video_channels;
474 session->video_tracks = fpr->video_tracks;
475 session->frame_rate = fpr->frame_rate;
476 session->output_w = fpr->output_w;
477 session->output_h = fpr->output_h;
478 session->aspect_w = fpr->aspect_w;
479 session->aspect_h = fpr->aspect_h;
480 session->interlace_mode = fpr->interlace_mode;
481 session->color_model = fpr->color_model;
487 const char *MWindow::get_preset_name(int index)
489 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
491 return _(format_presets[index].name);
495 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
497 char path[BCTEXTLEN];
498 // Use user supplied path
500 strcpy(path, config_path);
502 create_defaults_path(path, CONFIG_FILE);
505 defaults = new BC_Hash(path);
510 void MWindow::check_language()
512 char pref_locale[BCSTRLEN];
513 strcpy(pref_locale, DEFAULT_LOCALE);
514 defaults->get("LOCALE",pref_locale);
515 // set LANGUAGE if pref locale != sys
516 if( strcmp(pref_locale, DEFAULT_LOCALE) )
517 setenv("LANGUAGE", pref_locale, 1);
519 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
520 const char *env_lang = getenv("LANGUAGE");
521 if( !env_lang ) env_lang = getenv("LC_ALL");
522 if( !env_lang ) env_lang = getenv("LANG");
524 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
525 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
526 env_lang = curr_lang;
528 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
529 defaults->get("LAST_LANG",last_lang);
530 if( strcmp(env_lang,last_lang)) {
531 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
532 defaults->update("LAST_LANG",env_lang);
533 char plugin_path[BCTEXTLEN];
534 create_defaults_path(plugin_path, PLUGIN_FILE);
535 ::remove(plugin_path);
536 char ladspa_path[BCTEXTLEN];
537 create_defaults_path(ladspa_path, LADSPA_FILE);
538 ::remove(ladspa_path);
541 if( strlen(env_lang) > 1 &&
542 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
543 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
546 strcpy(cin_lang, "en");
549 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
551 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
553 const char *dp = plug_dir;
554 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
555 bp = !*dp && *bp == '/' ? bp+1 : base_path;
562 * @brief Load plugins according to an index file.
564 * @details Builds an ArrayList of plugin servers only if there is no
565 * mismatch for file layout version, index identifier, or timestamp of
566 * the built-in plugins. If OK, add the plugin servers to the global list.
568 * @note If an error is returned the index file needs to be rebuilt, and
569 * then this function must be called again.
570 * There are two types of index files, with the same layout internally.
571 * One called "Cinelerra_plugins" for built-ins, ffmpeg and lv2 .
572 * The other type "ladspa_plugins.index_id" where index_id is either the
573 * path or the $CIN_BUILD identifier if the path is from the running
574 * AppImage itself. If there are multiple ladspa directories in the
575 * path, there will be multiple index files.
577 * @return -1 if file no open, 0 if OK, 1 if error.
579 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir, const char *index_id)
583 fstat (fileno(fp), &st); // don't bother if the file has just been created.
584 if( st.st_size < 4 ) return 1;
587 fseek(fp, 0, SEEK_SET);
589 char index_line[BCTEXTLEN];
590 int index_version = -1, len = strlen(index_id);
591 if( !fgets(index_line, BCTEXTLEN, fp) ||
592 sscanf(index_line, "%d", &index_version) != 1 ||
593 index_version != PLUGIN_FILE_VERSION ||
594 !fgets(index_line, BCTEXTLEN, fp) ||
595 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
596 strncmp(index_line, index_id, len) != 0 ) {
597 // printf("index file mismatch, version %d, index id length %d, expected id %s, file id %s\n", index_version, len, index_id, index_line);
601 ArrayList<PluginServer*> plugins;
602 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
603 if( index_line[0] == ';' ) continue;
604 if( index_line[0] == '#' ) continue;
605 int type = PLUGIN_TYPE_UNKNOWN;
606 char path[BCTEXTLEN], title[BCTEXTLEN];
608 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
609 // printf("PluginServer::scan_table failed for %s\n", index_line);
612 PluginServer *server = 0;
614 case PLUGIN_TYPE_BUILTIN:
615 case PLUGIN_TYPE_EXECUTABLE:
616 case PLUGIN_TYPE_LADSPA: {
617 char plugin_path[BCTEXTLEN]; struct stat st;
618 sprintf(plugin_path, "%s/%s", plugin_dir, path);
619 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
620 // printf("Plugin %s index time %ld, file time %ld\n", plugin_path, mtime, st.st_mtime);
623 server = new PluginServer(mwindow, plugin_path, type);
625 case PLUGIN_TYPE_FFMPEG: {
626 server = new_ffmpeg_server(mwindow, path);
628 case PLUGIN_TYPE_LV2: {
629 server = new_lv2_server(mwindow, path);
632 if( !server ) continue;
633 plugins.append(server);
634 // Create plugin server from index entry
635 server->set_title(title);
636 if( server->read_table(index_line) ) {
637 // printf("server->read_table failed for title %s, %s\n", title, index_line);
643 ret = check_plugin_index(plugins, plugin_dir, ".");
646 add_plugins(plugins);
648 plugins.remove_all_objects();
653 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
654 const char *plug_dir, const char *plug_path)
656 char plugin_path[BCTEXTLEN];
657 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
659 fs.set_filter( "[*.plugin][*.so]" );
660 if( fs.update(plugin_path) )
663 for( int i=0; i<fs.dir_list.total; ++i ) {
664 char fs_path[BCTEXTLEN];
665 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
666 if( fs.is_dir(fs_path) ) {
667 get_plugin_path(plugin_path, plug_dir, fs_path);
668 if( check_plugin_index(plugins, plug_dir, plugin_path) )
671 else if( !plugin_exists(fs_path, plugins) )
678 * @brief Load built-in and LV2 plugins as specified in index file,
679 * rebuild the index file if needed.
680 * @param[in] mwindow: GUI class pointer, will be NULL for batch
681 * rendering or renderfarm client.
682 * @param[in] preferences: Information from cinelerra_rc file.
684 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
687 plugindb = new ArrayList<PluginServer*>;
689 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN], index_id[BCTEXTLEN];
690 create_defaults_path(index_path, PLUGIN_FILE);
691 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
692 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
693 // index_id is 2nd line of the index file, normally full plugin path,
694 // but fixed value if AppImage because the path changes on each run.
695 // And if the second line does not match on the next run the index is rebuilt.
696 if( getenv("APPDIR") && getenv("CINGG_BUILD")) strcpy(index_id, getenv("CINGG_BUILD"));
697 else strcpy(index_id, plugin_path);
698 FILE *fp = fopen(index_path,"a+");
700 fprintf(stderr,_("MWindow::init_plugins: "
701 "can't open plugin index: %s\n"), index_path);
704 int fd = fileno(fp), ret = -1;
705 if( !flock(fd, LOCK_EX) ) {
706 fseek(fp, 0, SEEK_SET);
707 ret = load_plugin_index(mwindow, fp, plugin_path, index_id);
711 fseek(fp, 0, SEEK_SET);
712 printf("build plugin index for: %s\n", plugin_path);
713 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
714 fprintf(fp, "%s\n", index_id);
715 init_plugin_index(mwindow, preferences, fp, plugin_path);
716 init_ffmpeg_index(mwindow, preferences, fp);
717 init_lv2_index(mwindow, preferences, fp);
718 fseek(fp, 0, SEEK_SET);
719 ret = load_plugin_index(mwindow, fp, plugin_path, index_id);
722 fprintf(stderr,_("MWindow::init_plugins: "
723 "can't %s plugin index: %s\n"),
724 ret>0 ? _("create") : _("lock"), index_path);
731 * @brief Load ladspa plugins as specified in index files, for each ladspa
732 * directory keep a separate index file. Rebuild index file(s) if needed.
733 * @param[in] mwindow: GUI class pointer, will be NULL for batch
734 * rendering or renderfarm client.
735 * @param[in] preferences: Information from cinelerra_rc file.
737 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
740 char *path = getenv("LADSPA_PATH");
741 char *appdir = getenv("APPDIR");
742 char ladspa_path[BCTEXTLEN];
743 if( !path ) { // if no env var, use CinGG's own ladspa dir
744 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
747 for( int len=0; *path; path+=len ) {
748 char *cp = strchr(path,':');
749 len = !cp ? strlen(path) : cp-path;
750 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN], index_id[BCTEXTLEN];
751 memcpy(plugin_path, path, len); plugin_path[len] = 0;
753 char *plugin_dir = FileSystem::basepath(plugin_path);
754 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
755 create_defaults_path(index_path, LADSPA_FILE);
756 cp = index_path + strlen(index_path);
757 // If the first part of the plugin_path matches the APPDIR, we are
758 // referring to CinGG's ladspa, replace the path by a fixed ID. APPDIR
759 // only exists if we are running as AppImage (with variable mount points).
760 if( appdir && strncmp(plugin_path, appdir, strlen(appdir)) == 0 )
761 strcpy(index_id, getenv("CINGG_BUILD"));
762 else strcpy(index_id, plugin_path);
764 // Concatenate the path, replacing '/' with '_'.
765 for( char *bp=index_id; *bp!=0; ++bp )
766 *cp++ = *bp=='/' ? '_' : *bp;
768 FILE *fp = fopen(index_path,"a+");
770 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
771 "can't open ladspa plugin index: %s\n"), index_path);
774 int fd = fileno(fp), ret = -1;
775 if( !flock(fd, LOCK_EX) ) {
776 fseek(fp, 0, SEEK_SET);
777 ret = load_plugin_index(mwindow, fp, plugin_path, index_id);
781 fseek(fp, 0, SEEK_SET);
782 printf("build ladspa plugin index for: %s\n", plugin_path);
783 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
784 fprintf(fp, "%s\n", index_id);
785 init_plugin_index(mwindow, preferences, fp, plugin_path);
786 fseek(fp, 0, SEEK_SET);
787 ret = load_plugin_index(mwindow, fp, plugin_path, index_id);
790 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
791 "can't %s ladspa plugin index: %s\n"),
792 ret>0 ? _("create") : _("lock"), index_path);
800 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
801 FILE *fp, const char *plugin_dir)
803 int idx = PLUGIN_IDS;
805 for( int i=0; i<plugindb->size(); ++i ) {
806 PluginServer *server = plugindb->get(i);
807 if( server->dir_idx >= idx )
808 idx = server->dir_idx+1;
811 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
814 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
815 const char *plug_dir, const char *plug_path, int &idx)
817 char plugin_path[BCTEXTLEN];
818 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
820 fs.set_filter( "[*.plugin][*.so][*.dll]" );
821 int result = fs.update(plugin_path);
822 if( result || !fs.dir_list.total ) return;
825 for( int i=0; i<fs.dir_list.total; ++i ) {
826 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
827 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
828 get_plugin_path(path, plug_dir, fs_path);
829 if( fs.is_dir(fs_path) ) { // recursively scan child directory
830 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
833 if( plugin_exists(path) ) continue;
835 if( stat(fs_path, &st) ) continue;
836 int64_t mtime = st.st_mtime;
837 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
838 result = server.open_plugin(1, preferences, 0, 0);
840 server.write_table(fp, path, vis_id, mtime);
841 server.close_plugin();
843 else if( result == PLUGINSERVER_IS_LAD ) {
846 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
847 ladspa.set_lad_index(lad_index++);
848 result = ladspa.open_plugin(1, preferences, 0, 0);
850 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
851 ladspa.close_plugin();
857 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
859 for( int i=0; i<plugins.size(); ++i )
860 plugindb->append(plugins[i]);
861 plugins.remove_all();
864 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
866 const char *dat_path = File::get_cindat_path();
867 char msg_path[BCTEXTLEN];
869 if( BC_Resources::language[0] ) {
870 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
872 fp = fopen(msg_path, "r");
875 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
877 fp = fopen(msg_path, "r");
880 char text[BCTEXTLEN];
881 char *tp = text, *ep = tp + sizeof(text)-1;
882 char title[BCTEXTLEN];
887 char line[BCTEXTLEN], *cp = line;
888 if( fgets(line,sizeof(line)-1,fp) ) {
889 if( *cp == '#' ) continue;
890 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
893 if( tp > text && *--tp == '\n' ) *tp = 0;
895 int idx = plugins.size();
896 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
898 delete [] plugins[idx]->tip;
899 plugins[idx]->tip = cstrdup(text);
903 if( done > 0 ) break;
905 char *dp = strchr(cp, ':');
907 printf("plugin tips: error on line %d\n", no);
911 while( cp < dp ) *bp++ = *cp++;
916 while( *cp == ' ' || *cp == '\t' ) ++cp;
917 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
922 void MWindow::delete_plugins()
924 plugindb->remove_all_objects();
929 void MWindow::search_plugindb(int do_audio,
934 ArrayList<PluginServer*> &results)
937 for(int i = 0; i < MWindow::plugindb->total; i++)
939 PluginServer *current = MWindow::plugindb->get(i);
941 if(current->audio == do_audio &&
942 current->video == do_video &&
943 (current->realtime == is_realtime || is_realtime < 0) &&
944 current->transition == is_transition &&
945 current->theme == is_theme)
946 results.append(current);
949 // Alphabetize list by title
955 for(int i = 0; i < results.total - 1; i++)
957 PluginServer *value1 = results[i];
958 PluginServer *value2 = results[i + 1];
959 if(strcmp(_(value1->title), _(value2->title)) > 0)
963 results[i + 1] = value1;
969 PluginServer* MWindow::scan_plugindb(char *title,
974 // printf("MWindow::scan_plugindb data_type < 0\n");
978 for(int i = 0; i < plugindb->total; i++)
980 PluginServer *server = plugindb->get(i);
982 !strcasecmp(server->title, title) &&
984 (data_type == TRACK_AUDIO && server->audio) ||
985 (data_type == TRACK_VIDEO && server->video)))
986 return plugindb->get(i);
991 // repair session files with xlated plugin titles
992 void MWindow::fix_plugin_title(char *title)
994 for(int i = 0; i < plugindb->total; i++) {
995 PluginServer *server = plugindb->get(i);
996 if( !server->title ) continue;
997 const char *server_title = server->title;
998 if( !bstrcasecmp(title, _(server_title)) ) {
999 strcpy(title, server_title);
1005 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
1007 for( int i=0; i<plugins.size(); ++i )
1008 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
1012 int MWindow::plugin_exists(char *plugin_path)
1014 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
1017 void MWindow::remove_plugin_index()
1019 char index_path[BCTEXTLEN];
1020 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
1021 ::remove(index_path);
1024 void MWindow::init_preferences()
1026 preferences = new Preferences;
1027 preferences->load_defaults(defaults);
1028 File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
1029 session = new MainSession(this);
1030 session->load_defaults(defaults);
1031 // set x11_host, screens, window_config
1032 screens = session->set_default_x11_host();
1033 BC_Signals::set_trap_hook(trap_hook, this);
1034 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
1035 BC_Signals::set_catch_intr(preferences->trap_sigintr);
1036 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
1037 BC_Trace::enable_locks();
1040 BC_Trace::disable_locks();
1042 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
1043 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
1044 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
1045 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
1048 void MWindow::clean_backups()
1053 int oldest_item = -1;
1054 char string[BCTEXTLEN];
1056 // Delete extra backups
1057 fs.set_filter("backup*.prev_*");
1058 fs.complete_path(preferences->index_directory);
1059 fs.update(preferences->index_directory);
1061 // set to 50 for now
1062 // total_excess = fs.dir_list.total - preferences->index_count;
1063 total_excess = fs.dir_list.total - 50;
1064 printf("Total excess of backups: %i \n", total_excess);
1066 //printf("MWindow::clean_backups 1 %d\n", fs.dir_list.total);
1068 while(total_excess > 0)
1071 for(int i = 0; i < fs.dir_list.total; i++)
1073 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1075 if(i == 0 || fs.get_date(string) <= oldest)
1077 oldest = fs.get_date(string);
1082 if(oldest_item >= 0)
1084 // Remove backup file
1085 fs.join_names(string,
1086 preferences->index_directory,
1087 fs.dir_list[oldest_item]->name);
1088 //printf("MWindow::clean_backups 1 %s\n", string);
1090 perror("delete_backups");
1091 delete fs.dir_list[oldest_item];
1092 fs.dir_list.remove_number(oldest_item);
1100 void MWindow::clean_indexes()
1105 int oldest_item = -1;
1107 char string[BCTEXTLEN];
1108 char string2[BCTEXTLEN];
1110 // Delete extra indexes
1111 fs.set_filter("*.idx");
1112 fs.complete_path(preferences->index_directory);
1113 fs.update(preferences->index_directory);
1114 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
1116 // Eliminate directories
1121 for(int i = 0; i < fs.dir_list.total && !result; i++)
1123 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1124 if(fs.is_dir(string))
1126 delete fs.dir_list[i];
1127 fs.dir_list.remove_number(i);
1132 total_excess = fs.dir_list.total - preferences->index_count;
1134 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
1135 while(total_excess > 0)
1138 for(int i = 0; i < fs.dir_list.total; i++)
1140 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1142 if(i == 0 || fs.get_date(string) <= oldest)
1144 oldest = fs.get_date(string);
1149 if(oldest_item >= 0)
1151 // Remove index file
1152 fs.join_names(string,
1153 preferences->index_directory,
1154 fs.dir_list[oldest_item]->name);
1155 //printf("MWindow::clean_indexes 1 %s\n", string);
1157 perror("delete_indexes");
1158 delete fs.dir_list[oldest_item];
1159 fs.dir_list.remove_number(oldest_item);
1161 // Remove table of contents if it exists
1162 strcpy(string2, string);
1163 char *ptr = strrchr(string2, '.');
1166 //printf("MWindow::clean_indexes 2 %s\n", string2);
1167 sprintf(ptr, ".toc");
1169 sprintf(ptr, ".mkr");
1178 void MWindow::init_awindow()
1180 awindow = new AWindow(this);
1181 awindow->create_objects();
1184 void MWindow::init_gwindow()
1186 gwindow = new GWindow(this);
1187 gwindow->create_objects();
1190 void MWindow::init_tipwindow()
1192 TipWindow::load_tips(cin_lang);
1194 twindow = new TipWindow(this);
1198 void MWindow::show_warning(int *do_warning, const char *text)
1200 if( do_warning && !*do_warning ) return;
1202 wwindow = new WWindow(this);
1203 wwindow->show_warning(do_warning, text);
1206 int MWindow::wait_warning()
1208 return wwindow->wait_result();
1211 void MWindow::init_theme()
1216 PluginServer *theme_plugin = 0;
1217 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1218 if( plugindb->get(i)->theme &&
1219 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1220 theme_plugin = plugindb->get(i);
1224 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1225 preferences->theme);
1227 const char *default_theme = DEFAULT_THEME;
1228 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1229 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1231 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1232 if( plugindb->get(i)->theme &&
1233 !strcasecmp(default_theme, plugindb->get(i)->title) )
1234 theme_plugin = plugindb->get(i);
1239 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1243 PluginServer *plugin = new PluginServer(*theme_plugin);
1244 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1245 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1246 theme_plugin->title);
1250 theme = plugin->new_theme();
1251 theme->mwindow = this;
1252 strcpy(theme->path, plugin->path);
1255 // Load default images & settings
1256 theme->Theme::initialize();
1257 // Load user images & settings
1258 theme->initialize();
1259 // Create menus with user colors
1260 theme->build_menus();
1263 theme->sort_image_sets();
1264 theme->check_used();
1265 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1268 void MWindow::init_3d()
1270 playback_3d = new Playback3D(this);
1271 playback_3d->create_objects();
1274 void MWindow::init_edl()
1277 edl->create_objects();
1278 fill_preset_defaults(default_standard, edl->session);
1279 edl->load_defaults(defaults);
1280 edl->session->brender_start = edl->session->brender_end = 0;
1281 edl->create_default_tracks();
1282 edl->tracks->update_y_pixels(theme);
1285 void MWindow::init_compositor()
1287 cwindow = new CWindow(this);
1288 cwindow->create_objects();
1291 void MWindow::init_levelwindow()
1293 lwindow = new LevelWindow(this);
1294 lwindow->create_objects();
1297 VWindow *MWindow::get_viewer(int start_it, int idx)
1299 vwindows_lock->lock("MWindow::get_viewer");
1300 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1301 if( !vwindow ) idx = vwindows.size();
1302 while( !vwindow && --idx >= 0 ) {
1303 VWindow *vwin = vwindows[idx];
1304 if( !vwin->is_running() || !vwin->get_edl() )
1308 vwindow = new VWindow(this);
1309 vwindow->load_defaults();
1310 vwindow->create_objects();
1311 vwindows.append(vwindow);
1313 vwindows_lock->unlock();
1314 if( start_it ) vwindow->start();
1318 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1320 zwindows_lock->lock("MWindow::get_mixer");
1321 if( !mixer ) mixer = edl->mixers.new_mixer();
1322 ZWindow *zwindow = 0;
1323 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1324 ZWindow *zwdw = zwindows[i];
1325 if( zwdw->running() ) continue;
1326 if( zwdw->idx >= 0 ) continue;
1327 zwindow = zwindows[i];
1330 zwindows.append(zwindow = new ZWindow(this));
1331 zwindow->idx = mixer->idx;
1332 zwindows_lock->unlock();
1336 ZWindow *MWindow::get_mixer(int idx)
1338 ZWindow *zwindow = 0;
1339 zwindows_lock->lock("MWindow::get_mixer");
1340 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1341 ZWindow *zwdw = zwindows[i];
1342 if( !zwdw->running() ) continue;
1343 if( zwdw->idx != idx ) continue;
1344 zwindow = zwindows[i];
1346 zwindows_lock->unlock();
1350 void MWindow::close_mixer(ZWindow *zwindow)
1352 zwindows_lock->lock("MWindow::close_mixer 0");
1353 if( session->selected_zwindow >= 0 ) {
1354 int i = zwindows.number_of(zwindow);
1355 if( i >= 0 && i < session->selected_zwindow )
1356 --session->selected_zwindow;
1357 else if( i == session->selected_zwindow )
1358 session->selected_zwindow = -1;
1360 zwindows_lock->unlock();
1361 gui->lock_window("MWindow::close_mixer 1");
1362 gui->update_mixers(0, -1);
1363 gui->unlock_window();
1366 void MWindow::start_mixer()
1369 ZWindow *zwindow = get_mixer(mixer);
1370 const char *title = 0;
1372 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1373 PatchGUI *patchgui = get_patchgui(track);
1374 if( !patchgui || !patchgui->mixer ) continue;
1375 mixer->mixer_ids.append(track->get_mixer_id());
1376 if( !title ) title = track->title;
1379 session->selected_zwindow = -1;
1380 gui->lock_window("MWindow::start_mixer");
1381 gui->update_mixers(0, 0);
1382 gui->unlock_window();
1384 zwindow->set_title(title);
1389 int MWindow::mixer_track_active(Track *track)
1391 int i = session->selected_zwindow;
1392 if( i < 0 || i >= zwindows.size() ) return 0;
1393 ZWindow *zwindow = zwindows[i];
1394 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1395 if( !mixer ) return 0;
1396 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1397 return n >= 0 ? 1 : 0;
1400 void MWindow::update_mixer_tracks()
1402 zwindows_lock->lock("MixPatch::handle_event");
1403 int i = session->selected_zwindow;
1404 if( i >= 0 && i < zwindows.size() ) {
1405 ZWindow *zwindow = zwindows[i];
1406 zwindow->update_mixer_ids();
1408 zwindows_lock->unlock();
1411 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1412 int use_inout, int toggle_audio, int loop_play, float speed)
1414 zwindows_lock->lock("MWindow::handle_mixers");
1415 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1416 ZWindow *zwindow = zwindows[vidx];
1417 if( zwindow->idx < 0 ) continue;
1418 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1419 if( !mixer || !mixer->mixer_ids.size() ) continue;
1421 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1422 if( track->data_type != TRACK_VIDEO ) continue;
1423 int mixer_id = track->get_mixer_id();
1424 k = mixer->mixer_ids.size();
1425 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1427 if( k < 0 ) continue;
1428 EDL *mixer_edl = new EDL(this->edl);
1429 mixer_edl->create_objects();
1430 mixer_edl->copy_all(edl);
1431 mixer_edl->remove_vwindow_edls();
1432 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1433 k = mixer->mixer_ids.size();
1434 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1437 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1440 track->armed = track->play = 0;
1442 zwindow->change_source(mixer_edl);
1443 zwindow->handle_mixer(command, 0,
1444 use_inout, toggle_audio, loop_play, speed);
1446 zwindows_lock->unlock();
1449 void MWindow::refresh_mixers(int dir)
1451 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1452 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1455 void MWindow::stop_mixers()
1457 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1458 ZWindow *zwindow = zwindows[vidx];
1459 if( zwindow->idx < 0 ) continue;
1460 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1464 void MWindow::close_mixers(int result)
1466 ArrayList<ZWindow*> closed;
1467 zwindows_lock->lock("MWindow::close_mixers");
1468 for( int i=zwindows.size(); --i>=0; ) {
1469 ZWindow *zwindow = zwindows[i];
1470 if( zwindow->idx < 0 ) continue;
1472 ZWindowGUI *zgui = zwindow->zgui;
1473 zgui->lock_window("MWindow::select_zwindow 0");
1474 zgui->set_done(result);
1475 zgui->unlock_window();
1476 closed.append(zwindow);
1478 zwindows_lock->unlock();
1479 for( int i=0; i<closed.size(); ++i ) {
1480 ZWindow *zwindow = closed[i];
1485 ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
1487 ArrayList<Indexable*> new_assets;
1488 new_assets.append(indexable);
1489 Track *track = edl->tracks->last;
1490 load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
1491 track = !track ? edl->tracks->first : track->next;
1493 ZWindow *zwindow = get_mixer(mixer);
1495 track->play = track->armed = 0;
1496 if( track->data_type == TRACK_VIDEO ) {
1497 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1499 mixer->mixer_ids.append(track->get_mixer_id());
1500 track = track->next;
1502 if( indexable->is_asset ) {
1503 char *path = indexable->path;
1504 char *tp = strrchr(path, '/');
1505 if( !tp ) tp = path; else ++tp;
1506 zwindow->set_title(tp);
1509 char *title = ((EDL*)indexable)->local_session->clip_title;
1510 zwindow->set_title(title);
1515 void MWindow::create_mixers(double position)
1517 if( !session->drag_assets->size() &&
1518 !session->drag_clips->size() ) return;
1522 ArrayList<ZWindow *>new_mixers;
1524 for( int i=0; i<session->drag_assets->size(); ++i ) {
1525 Indexable *indexable = session->drag_assets->get(i);
1526 if( !indexable->have_video() ) continue;
1527 ZWindow *zwindow = create_mixer(indexable, position);
1528 new_mixers.append(zwindow);
1530 for( int i=0; i<session->drag_clips->size(); ++i ) {
1531 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1532 if( !indexable->have_video() ) continue;
1533 ZWindow *zwindow = create_mixer(indexable, position);
1534 new_mixers.append(zwindow);
1538 for( int i=0; i<new_mixers.size(); ++i )
1539 new_mixers[i]->start();
1543 undo_after(_("create mixers"), LOAD_ALL);
1545 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1546 sync_parameters(CHANGE_ALL);
1549 void MWindow::open_mixers()
1551 for( int i=0; i<edl->mixers.size(); ++i ) {
1552 Mixer *mixer = edl->mixers[i];
1553 ZWindow *zwindow = get_mixer(mixer);
1554 zwindow->set_title(mixer->title);
1560 int MWindow::select_zwindow(ZWindow *zwindow)
1562 int ret = 0, n = zwindows.number_of(zwindow);
1563 if( session->selected_zwindow != n ) {
1564 session->selected_zwindow = n;
1565 for( int i=0; i<zwindows.size(); ++i ) {
1566 ZWindow *zwindow = zwindows[i];
1567 if( zwindow->idx < 0 ) continue;
1568 ZWindowGUI *zgui = zwindow->zgui;
1569 zgui->lock_window("MWindow::select_zwindow 0");
1570 zwindow->highlighted = i == n ? 1 : 0;
1571 if( zgui->draw_overlays() )
1572 zgui->canvas->get_canvas()->flash(1);
1573 zgui->unlock_window();
1576 gui->lock_window("MWindow::select_window 1");
1577 gui->update_mixers(0, -1);
1578 gui->unlock_window();
1583 void MWindow::tile_mixers()
1585 int x1 = session->tile_mixers_x;
1586 int y1 = session->tile_mixers_y;
1587 int x2 = x1 + session->tile_mixers_w;
1588 int y2 = y1 + session->tile_mixers_h;
1589 tile_mixers(x1, y1, x2, y2);
1592 void MWindow::tile_mixers(int x1, int y1, int x2, int y2)
1594 if( x1 == x2 || y1 == y2 ) {
1595 // use top left quadrent
1596 int sw = gui->get_screen_w(1, -1);
1597 int sh = gui->get_screen_w(1, -1);
1599 x2 = sw/2; y2 = sh/2;
1602 if( x1 > x2 ) { int t = x1; x1 = x2; x2 = t; }
1603 if( y1 > y2 ) { int t = y1; y1 = y2; y2 = t; }
1605 int ow = edl->session->output_w, oh = edl->session->output_h;
1607 for( int i=0; i<zwindows.size(); ++i ) {
1608 ZWindow *zwindow = zwindows[i];
1609 if( zwindow->idx < 0 ) continue;
1613 int lt = BC_DisplayInfo::get_left_border();
1614 int top = BC_DisplayInfo::get_top_border();
1615 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1616 int bh = top + BC_DisplayInfo::get_bottom_border();
1617 int mw = xS(10+10), mh = yS(10+10); // canvas margins
1618 int dx = x2 - x1, dy = y2 - y1;
1619 int64_t sz = dx * dy, best_r = sz;
1620 int bx = 1, by = nz;
1621 for( int nx=1; nx<=nz; ++nx ) {
1622 int ny = ceil((double)nz / nx);
1625 int hh = (ww - mw) * oh / ow + mh;
1627 int64_t za = zw*nx * zh*ny;
1628 int64_t r = sz - za;
1629 if( r < 0 ) continue;
1630 if( r >= best_r ) continue;
1634 for( int ny=1; ny<=nz; ++ny ) {
1635 int nx = ceil((double)nz / ny);
1638 int ww = (hh - mh) * ow / oh + mw;
1640 int64_t za = zw*nx * zh*ny;
1641 int64_t r = sz - za;
1642 if( r < 0 ) continue;
1643 if( r >= best_r ) continue;
1651 ww = (hh - mh) * ow / oh + mw;
1657 hh = (ww - mw) * oh / ow + mh;
1661 int zx = 0, zy = 0; // window origins
1663 for( int i=0; i<zwindows.size(); ++i ) {
1664 ZWindow *zwindow = zwindows[i];
1665 if( zwindow->idx < 0 ) continue;
1666 int xx = zx + x1, yy = zy + y1;
1667 int mx = x2 - zw, my = y2 - zh;
1668 if( xx > mx ) xx = mx;
1669 if( yy > my ) yy = my;
1670 zwindow->reposition(xx,yy, ww,hh);
1671 if( zwindow->running() ) {
1672 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1673 gui->lock_window("MWindow::tile_mixers");
1674 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1675 gui->unlock_window();
1686 void MWindow::set_gang_tracks(int v)
1688 edl->local_session->gang_tracks = v;
1689 sync_parameters(CHANGE_PARAMS);
1690 gui->update(1, 1, 0, 0, 1, 0, 0);
1695 void MWindow::init_cache()
1697 audio_cache = new CICache(preferences);
1698 video_cache = new CICache(preferences);
1699 frame_cache = new FrameCache;
1700 wave_cache = new WaveCache;
1703 void MWindow::init_channeldb()
1705 channeldb_buz->load("channeldb_buz");
1706 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1709 void MWindow::init_menus()
1711 char string[BCTEXTLEN];
1714 BC_CModels::to_text(string, BC_RGB888);
1715 colormodels.append(new ColormodelItem(string, BC_RGB888));
1716 BC_CModels::to_text(string, BC_RGBA8888);
1717 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1718 // BC_CModels::to_text(string, BC_RGB161616);
1719 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1720 // BC_CModels::to_text(string, BC_RGBA16161616);
1721 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1722 BC_CModels::to_text(string, BC_RGB_FLOAT);
1723 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1724 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1725 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1726 BC_CModels::to_text(string, BC_YUV888);
1727 colormodels.append(new ColormodelItem(string, BC_YUV888));
1728 BC_CModels::to_text(string, BC_YUVA8888);
1729 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1730 // BC_CModels::to_text(string, BC_YUV161616);
1731 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1732 // BC_CModels::to_text(string, BC_YUVA16161616);
1733 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1735 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1736 interlace_project_modes.append(new InterlacemodeItem(string, x));
1738 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1739 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1741 // Interlacing Modes
1742 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1744 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1745 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1747 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1748 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1750 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1751 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1753 mixers_align = new MixersAlign(this);
1756 void MWindow::init_indexes()
1758 mainindexes = new MainIndexes(this);
1759 mainindexes->start_loop();
1762 void MWindow::init_gui()
1764 gui = new MWindowGUI(this);
1765 gui->create_objects();
1766 gui->load_defaults(defaults);
1769 void MWindow::init_signals()
1771 sighandler = new SigHandler;
1772 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1776 void MWindow::init_render()
1778 render = new Render(this);
1779 create_bd = new CreateBD_Thread(this);
1780 create_dvd = new CreateDVD_Thread(this);
1781 batch_render = new BatchRenderThread(this);
1784 void MWindow::init_exportedl()
1786 exportedl = new ExportEDL(this);
1790 void MWindow::init_shuttle()
1793 int ret = Shuttle::probe();
1795 shuttle = new Shuttle(this);
1796 if( shuttle->read_config_file() > 0 ) {
1797 printf("shuttle: bad config file\n");
1798 delete shuttle; shuttle = 0;
1801 shuttle->start(ret);
1805 void MWindow::init_wintv()
1808 wintv = WinTV::probe(this);
1813 void MWindow::init_x10tv()
1816 x10tv = X10TV::probe(this);
1823 void MWindow::init_brender()
1825 if(preferences->use_brender && !brender)
1827 brender_lock->lock("MWindow::init_brender 1");
1828 brender = new BRender(this);
1829 brender->initialize();
1830 session->brender_end = 0;
1831 brender_lock->unlock();
1834 if(!preferences->use_brender && brender)
1836 brender_lock->lock("MWindow::init_brender 2");
1839 session->brender_end = 0;
1840 brender_lock->unlock();
1846 void MWindow::restart_brender()
1848 //printf("MWindow::restart_brender 1\n");
1849 if( !brender_active || !preferences->use_brender ) return;
1850 if( !brender ) return;
1851 brender->restart(edl);
1854 void MWindow::stop_brender()
1856 if( !brender ) return;
1857 // cannot be holding mwindow->gui display lock
1861 int MWindow::brender_available(int position)
1864 brender_lock->lock("MWindow::brender_available 1");
1865 if(brender && brender_active)
1867 if(brender->map_valid)
1869 brender->map_lock->lock("MWindow::brender_available 2");
1870 if(position < brender->map_size &&
1873 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1874 if(brender->map[position] == BRender::RENDERED)
1877 brender->map_lock->unlock();
1880 brender_lock->unlock();
1884 void MWindow::set_brender_active(int v, int update)
1886 if( !preferences->use_brender ) v = 0;
1888 gui->mainmenu->brender_active->set_checked(v);
1890 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1891 edl->session->brender_end = edl->local_session->get_selectionend(1);
1893 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1894 edl->session->brender_end = edl->tracks->total_video_length();
1899 edl->session->brender_start = edl->session->brender_end = 0;
1900 gui->unlock_window();
1902 gui->lock_window("MWindow::set_brender_active");
1905 gui->update_timebar(0);
1906 gui->draw_overlays(1);
1910 int MWindow::has_commercials()
1912 #ifdef HAVE_COMMERCIAL
1913 return theme->use_commercials;
1919 void MWindow::init_commercials()
1921 #ifdef HAVE_COMMERCIAL
1922 if( !commercials ) {
1923 commercials = new Commercials(this);
1924 commercial_active = 0;
1927 commercials->add_user();
1931 void MWindow::commit_commercial()
1933 #ifdef HAVE_COMMERCIAL
1934 if( !commercial_active ) return;
1935 commercial_active = 0;
1936 if( !commercials ) return;
1937 commercials->commitDb();
1941 void MWindow::undo_commercial()
1943 #ifdef HAVE_COMMERCIAL
1944 if( !commercial_active ) return;
1945 commercial_active = 0;
1946 if( !commercials ) return;
1947 commercials->undoDb();
1951 int MWindow::put_commercial()
1954 #ifdef HAVE_COMMERCIAL
1955 double start = edl->local_session->get_selectionstart();
1956 double end = edl->local_session->get_selectionend();
1957 if( start >= end ) return 0;
1959 const char *errmsg = 0;
1961 Tracks *tracks = edl->tracks;
1963 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1964 if( track->data_type != TRACK_VIDEO ) continue;
1965 if( !track->armed ) continue;
1966 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1968 int64_t units_start = track->to_units(start,0);
1969 int64_t units_end = track->to_units(end,0);
1970 Edits *edits = track->edits;
1971 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1972 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1973 if(!edit1 && !edit2) continue; // nothing selected
1974 if(!edit2) { // edit2 beyond end of track
1975 edit2 = edits->last;
1976 units_end = edits->length();
1978 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1979 Indexable *indexable = edit1->get_source();
1980 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1983 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1984 if( track->data_type != TRACK_VIDEO ) continue;
1985 if( !track->armed ) continue;
1986 int64_t units_start = track->to_units(start,0);
1987 int64_t units_end = track->to_units(end,0);
1988 Edits *edits = track->edits;
1989 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1990 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1991 if(!edit1 && !edit2) continue; // nothing selected
1992 if(!edit2) { // edit2 beyond end of track
1993 edit2 = edits->last;
1994 units_end = edits->length();
1996 Indexable *indexable = edit1->get_source();
1997 Asset *asset = (Asset *)indexable;
1998 File *file = video_cache->check_out(asset, edl);
1999 if( !file ) { errmsg = _("no file"); break; }
2000 int64_t edit_length = units_end - units_start;
2001 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
2002 result = commercials->put_clip(file, edit1->channel,
2003 track->from_units(edit_start), track->from_units(edit_length));
2004 video_cache->check_in(asset);
2005 if( result ) { errmsg = _("db failed"); break; }
2008 char string[BCTEXTLEN];
2009 sprintf(string, _("put_commercial: %s"), errmsg);
2010 MainError::show_error(string);
2018 void MWindow::stop_playback(int wait)
2020 gui->stop_drawing();
2022 cwindow->stop_playback(wait);
2024 for(int i = 0; i < vwindows.size(); i++) {
2025 VWindow *vwindow = vwindows[i];
2026 if( !vwindow->is_running() ) continue;
2027 vwindow->stop_playback(wait);
2029 for(int i = 0; i < zwindows.size(); i++) {
2030 ZWindow *zwindow = zwindows[i];
2031 if( zwindow->idx < 0 ) continue;
2032 zwindow->stop_playback(wait);
2036 void MWindow::stop_transport()
2038 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
2041 void MWindow::undo_before(const char *description, void *creator)
2043 undo->update_undo_before(description, creator);
2046 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
2048 undo->update_undo_after(description, load_flags, changes_made);
2051 void MWindow::beep(double freq, double secs, double gain)
2053 if( !beeper ) beeper = new Beeper(this);
2054 beeper->tone(freq, secs, gain);
2057 Beeper::Beeper(MWindow *mwindow)
2060 this->mwindow = mwindow;
2061 audio = new AudioDevice(mwindow);
2075 int64_t bfrsz = BEEP_SAMPLE_RATE;
2076 EDL *edl = mwindow->edl;
2077 EDLSession *session = edl->session;
2078 AudioOutConfig *aconfig = session->playback_config->aconfig;
2079 audio->open_output(aconfig, BEEP_SAMPLE_RATE, bfrsz, channels, 0);
2080 audio->start_playback();
2082 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
2083 const double two_pi = 2*M_PI;
2084 int64_t audio_len = BEEP_SAMPLE_RATE * secs;
2085 const double dt = two_pi * freq/BEEP_SAMPLE_RATE;
2090 while( !interrupted ) {
2091 int len = audio_len - audio_pos;
2092 if( len <= 0 ) break;
2093 if( len > bfrsz ) len = bfrsz;
2095 for( int i=0; i<len; ++i,++k,th+=dt ) {
2096 double t = th - two_pi;
2097 if( t >= 0 ) th = t;
2098 out0[i] = out1[i] = sin(th) * gain;
2100 audio->write_buffer(out, channels, len);
2105 audio->set_last_buffer();
2106 audio->stop_audio(interrupted ? 0 : 1);
2112 void Beeper::start()
2114 if( running() ) return;
2120 void Beeper::stop(int wait)
2122 if( running() && !interrupted ) {
2124 audio->stop_audio(wait);
2129 void Beeper::tone(double freq, double secs, double gain)
2139 int MWindow::load_filenames(ArrayList<char*> *filenames,
2140 int load_mode, int edl_mode, int update_filename)
2142 ArrayList<EDL*> new_edls;
2143 ArrayList<Asset*> new_assets;
2144 ArrayList<File*> new_files;
2147 gui->start_hourglass();
2149 // Need to stop playback since tracking depends on the EDL not getting
2151 gui->unlock_window();
2153 gui->lock_window("MWindow::load_filenames 0");
2156 const int debug = 0;
2157 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2159 // Define new_edls and new_assets to load
2160 int result = 0, ftype = -1;
2162 for( int i=0; i<filenames->size(); ++i ) {
2164 File *new_file = new File;
2165 Asset *new_asset = new Asset(filenames->get(i));
2166 EDL *new_edl = new EDL;
2167 new_edl->create_objects();
2168 new_edl->copy_session(edl, -1);
2169 new_file->set_program(edl->session->program_no);
2171 char string[BCTEXTLEN];
2172 sprintf(string, _("Loading %s"), new_asset->path);
2173 gui->show_message(string);
2175 ftype = new_file->open_file(preferences, new_asset, 1, 0);
2179 // Convert media file to EDL
2181 // Warn about odd image dimensions
2182 if( new_asset->video_data &&
2183 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
2184 eprintf(_("%s's resolution is %dx%d.\n"
2185 "Images with odd dimensions may not decode properly."),
2186 new_asset->path, new_asset->width, new_asset->height);
2189 if( new_asset->program >= 0 &&
2190 edl->session->program_no != new_asset->program ) {
2191 eprintf(_("%s's index was built for program number %d\n"
2192 "Playback preference is %d.\n Using program %d."),
2193 new_asset->path, new_asset->program,
2194 edl->session->program_no, new_asset->program);
2197 if( load_mode == LOADMODE_RESOURCESONLY ) {
2198 new_assets.append(new_asset);
2199 new_asset->add_user();
2204 RecordLabels *labels = edl->session->label_cells ?
2205 new RecordLabels(new_file) : 0;
2206 asset_to_edl(new_edl, new_asset, labels);
2207 new_edls.append(new_edl);
2208 new_edl->add_user();
2211 if( load_mode == LOADMODE_REPLACE ||
2212 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2213 // Set filename to nothing for assets since save EDL would overwrite them.
2215 // Reset timeline position
2216 for( int i=0; i<TOTAL_PANES; ++i ) {
2217 new_edl->local_session->view_start[i] = 0;
2218 new_edl->local_session->track_start[i] = 0;
2224 case FILE_NOT_FOUND: {
2225 eprintf(_("Failed to open %s"), new_asset->path);
2226 sprintf(string, _("Failed to open %s"), new_asset->path);
2227 gui->show_message(string, theme->message_error);
2228 gui->update_default_message();
2232 case FILE_UNRECOGNIZED_CODEC: {
2234 { IndexFile indexfile(this, new_asset);
2235 if( !(result = indexfile.open_index()) )
2236 indexfile.close_index(); }
2238 // Test existing EDLs
2239 for( int j=0; result && j<new_edls.total; ++j ) {
2240 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
2242 new_asset->copy_from(old_asset,1);
2247 Asset *old_asset = edl->assets->get_asset(new_asset->path);
2249 new_asset->copy_from(old_asset,1);
2256 new_asset->audio_data = 1;
2257 new_asset->format = FILE_PCM;
2258 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
2259 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
2260 new_asset->bits = defaults->get("AUDIO_BITS", 16);
2261 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
2262 new_asset->signed_ = defaults->get("SIGNED_", 1);
2263 new_asset->header = defaults->get("HEADER", 0);
2266 fs.extract_name(string, new_asset->path);
2267 strcat(string, _("'s format couldn't be determined."));
2268 FileFormat fwindow(this);
2269 fwindow.create_objects(new_asset, string);
2270 result = fwindow.run_window();
2272 defaults->update("AUDIO_CHANNELS", new_asset->channels);
2273 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
2274 defaults->update("AUDIO_BITS", new_asset->bits);
2275 defaults->update("BYTE_ORDER", new_asset->byte_order);
2276 defaults->update("SIGNED_", new_asset->signed_);
2277 defaults->update("HEADER", new_asset->header);
2282 // Recalculate length
2284 new_file = new File;
2285 result = new_file->open_file(preferences, new_asset, 1, 0);
2287 if( load_mode != LOADMODE_RESOURCESONLY ) {
2288 RecordLabels *labels = edl->session->label_cells ?
2289 new RecordLabels(new_file) : 0;
2290 asset_to_edl(new_edl, new_asset, labels);
2291 new_edls.append(new_edl);
2292 new_edl->add_user();
2296 new_assets.append(new_asset);
2297 new_asset->add_user();
2304 const char *filename = filenames->get(i);
2305 if( xml_file.read_from_file(filename, 1) ) {
2306 eprintf(_("Error: unable to open:\n %s"), filename);
2309 const char *cin_version = 0;
2310 while( !xml_file.read_tag() ) {
2311 if( xml_file.tag.title_is("EDL") ) {
2312 cin_version = xml_file.tag.get_property("VERSION");
2317 if( !cin_version ) {
2318 eprintf(_("XML file %s\n not from cinelerra."),filename);
2319 char string[BCTEXTLEN];
2320 sprintf(string,_("Unknown %s"), filename);
2321 gui->show_message(string);
2324 if( strcmp(cin_version, CINELERRA_VERSION) &&
2325 strcmp(cin_version, "Unify") &&
2326 strcmp(cin_version, "5.1") ) {
2327 eprintf(_("Warning: XML from cinelerra version %s\n"
2328 "Session data may be incompatible."), cin_version);
2330 if( new_edl->load_xml(&xml_file, LOAD_ALL) ) {
2331 eprintf(_("Error: unable to load:\n %s"), filename);
2334 test_plugins(new_edl, filename);
2335 int groups = new_edl->regroup(session->group_number);
2336 session->group_number += groups;
2337 switch( edl_mode ) {
2338 case LOADMODE_EDL_CLIP: {
2339 strcpy(new_edl->local_session->clip_title,
2342 time_t t = !stat(filenames->get(i),&st) ?
2343 st.st_mtime : time(&t);
2344 ctime_r(&t, new_edl->local_session->clip_notes);
2345 switch( load_mode ) {
2346 case LOADMODE_REPLACE:
2347 case LOADMODE_REPLACE_CONCATENATE:
2348 strcpy(session->filename, filename);
2349 if( update_filename ) set_filename(filename);
2354 case LOADMODE_EDL_NESTED: {
2355 EDL *nested_edl = new EDL;
2356 nested_edl->create_objects();
2357 nested_edl->copy_session(edl, -1);
2358 nested_edl->create_nested(new_edl);
2359 nested_edl->set_path(filename);
2360 new_edl->remove_user();
2361 new_edl = nested_edl;
2364 case LOADMODE_EDL_FILEREF: {
2365 result = create_ref(new_asset, new_edl);
2367 new_assets.append(new_asset);
2368 new_asset->add_user();
2369 new_edl->remove_user();
2371 new_edl->create_objects();
2372 new_edl->copy_session(edl, -1);
2373 asset_to_edl(new_edl, new_asset);
2375 new_file = new File;
2376 result = new_file->open_file(preferences, new_asset, 1, 0);
2380 new_edls.append(new_edl);
2381 new_edl->add_user();
2384 eprintf(_("Error: Unable to load xml:\n %s"), new_asset->path);
2388 new_edl->Garbage::remove_user();
2389 new_asset->Garbage::remove_user();
2391 // Store for testing index
2392 new_files.append(new_file);
2395 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2398 gui->reset_default_message();
2399 gui->default_message();
2402 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2405 // Don't back up here.
2406 if( new_edls.size() ) {
2407 // For pasting, clear the active region
2408 if( load_mode == LOADMODE_PASTE ) {
2409 double start = edl->local_session->get_selectionstart();
2410 double end = edl->local_session->get_selectionend();
2411 if(!EQUIV(start, end))
2412 edl->clear(start, end,
2413 edl->session->labels_follow_edits,
2414 edl->session->plugins_follow_edits,
2415 edl->session->autos_follow_edits);
2417 paste_edls(&new_edls, load_mode, 0, -1,
2418 edl->session->labels_follow_edits,
2419 edl->session->plugins_follow_edits,
2420 edl->session->autos_follow_edits,
2423 else if( load_mode == LOADMODE_NEW_TRACKS &&
2424 edl_mode != LOADMODE_EDL_CLIP )
2425 paste_edls(&new_edls, load_mode, 0, -1, 0, 0, 0, 0);
2426 else if( load_mode != LOADMODE_RESOURCESONLY ||
2427 edl_mode == LOADMODE_EDL_CLIP )
2428 paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
2430 paste_edls(&new_edls, LOADMODE_NOTHING, 0, -1, 0, 0, 0, 0);
2434 // Add new assets to EDL and schedule assets for index building.
2435 int got_indexes = 0;
2436 for( int i=0; i<new_edls.size(); ++i ) {
2437 EDL *new_edl = new_edls[i];
2438 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2439 mainindexes->add_indexable(new_edl->nested_edls[j]);
2440 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2446 for( int i=0; i<new_assets.size(); ++i ) {
2447 Asset *new_asset = new_assets[i];
2448 mainindexes->add_indexable(new_asset);
2449 edl->assets->update(new_asset);
2453 // Start examining next batch of index files
2454 if(got_indexes) mainindexes->start_build();
2456 // reload renderengine edl or the plugin guis will flip out
2457 sync_parameters(CHANGE_ALL);
2461 // opening new session
2462 if( ( load_mode == LOADMODE_REPLACE ||
2463 load_mode == LOADMODE_REPLACE_CONCATENATE ) &&
2464 (ftype != FILE_IS_XML || edl_mode != LOADMODE_EDL_CLIP) ) {
2466 edl->session->proxy_state = PROXY_INACTIVE;
2467 edl->session->proxy_scale = 1;
2468 edl->session->proxy_disabled_scale = 1;
2469 edl->session->proxy_use_scaler = 0;
2470 edl->session->proxy_auto_scale = 0;
2471 edl->session->proxy_beep = 0;
2472 edl->local_session->preview_start = 0;
2473 edl->local_session->preview_end = -1;
2474 edl->local_session->loop_playback = 0;
2475 edl->local_session->set_selectionstart(0);
2476 edl->local_session->set_selectionend(0);
2477 edl->local_session->unset_inpoint();
2478 edl->local_session-> unset_outpoint();
2479 set_brender_active(0, 0);
2484 if( edl->session->proxy_state != PROXY_INACTIVE && edl->session->proxy_auto_scale &&
2485 load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) {
2486 ArrayList<Indexable *> orig_idxbls;
2487 for( int i=0; i<new_assets.size(); ++i )
2488 orig_idxbls.append(new_assets.get(i));
2489 for( int i=0; i<new_edls.size(); ++i ) {
2490 EDL *new_edl = new_edls[i];
2491 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2492 if( track->data_type != TRACK_VIDEO ) continue;
2493 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2494 Indexable *idxbl = (Indexable *)edit->asset;
2495 if( !idxbl ) continue;
2496 if( !idxbl->have_video() ) continue;
2497 if( edit->channel != 0 ) continue; // first layer only
2498 orig_idxbls.append(edit->asset);
2502 gui->unlock_window(); // to update progress bar
2503 int ret = render_proxy(orig_idxbls);
2504 gui->lock_window("MWindow::load_filenames");
2505 float gain = edl->session->proxy_beep;
2506 if( ret >= 0 && gain > 0 ) {
2508 beep(2000., 1.5, gain);
2510 beep(4000., 0.25, gain);
2514 // need to update undo before project, since mwindow is unlocked & a new load
2515 // can begin here. Should really prevent loading until we're done.
2516 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2517 undo_after(_("load"), LOAD_ALL);
2519 for(int i = 0; i < new_edls.size(); i++)
2521 new_edls[i]->remove_user();
2523 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2525 new_edls.remove_all();
2527 for(int i = 0; i < new_assets.size(); i++)
2529 new_assets[i]->Garbage::remove_user();
2532 new_assets.remove_all();
2533 new_files.remove_all_objects();
2536 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2537 if(load_mode == LOADMODE_REPLACE ||
2538 load_mode == LOADMODE_REPLACE_CONCATENATE)
2540 session->changes_made = 0;
2544 session->changes_made = 1;
2547 gui->stop_hourglass();
2550 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2551 update_project(load_mode);
2553 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2558 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2560 Asset *format_asset = new Asset;
2561 format_asset->format = FILE_FFMPEG;
2562 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2563 int new_scale = edl->session->proxy_scale;
2564 ProxyRender proxy_render(this, format_asset, new_scale);
2566 for( int i=0; i<new_idxbls.size(); ++i ) {
2567 Indexable *orig = new_idxbls.get(i);
2568 Asset *proxy = proxy_render.add_original(orig, new_scale);
2569 if( !proxy ) continue;
2571 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2572 int got_it = exists && // if proxy exists, and is newer than orig
2573 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2574 if( got_it ) continue;
2575 proxy_render.add_needed(orig, proxy);
2578 // render needed proxies
2579 int result = proxy_render.create_needed_proxies(new_scale);
2581 add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2583 format_asset->remove_user();
2584 return !result ? proxy_render.needed_proxies.size() : -1;
2587 int MWindow::enable_proxy()
2590 if( edl->session->proxy_state == PROXY_DISABLED ) {
2591 int new_scale = edl->session->proxy_disabled_scale;
2592 int new_use_scaler = edl->session->proxy_use_scaler;
2593 Asset *asset = new Asset;
2594 asset->format = FILE_FFMPEG;
2595 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2596 ret = to_proxy(asset, new_scale, new_use_scaler);
2597 asset->remove_user();
2599 float gain = edl->session->proxy_beep;
2600 beep(2000., 1.5, gain);
2602 edl->session->proxy_disabled_scale = 1;
2603 edl->session->proxy_state = PROXY_ACTIVE;
2604 gui->lock_window("MWindow::to_proxy");
2605 update_project(LOADMODE_REPLACE);
2606 gui->unlock_window();
2611 int MWindow::disable_proxy()
2613 if( edl->session->proxy_state == PROXY_ACTIVE ) {
2614 int old_scale = edl->session->proxy_scale, new_scale = 0;
2615 int new_use_scaler = edl->session->proxy_use_scaler;
2616 Asset *asset = new Asset;
2617 asset->format = FILE_FFMPEG;
2618 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2619 to_proxy(asset, new_scale, new_use_scaler);
2620 asset->remove_user();
2621 edl->session->proxy_state = PROXY_DISABLED;
2622 edl->session->proxy_disabled_scale = old_scale;
2623 gui->lock_window("MWindow::to_proxy");
2624 update_project(LOADMODE_REPLACE);
2625 gui->unlock_window();
2630 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2632 ArrayList<Indexable*> orig_idxbls;
2633 ArrayList<Indexable*> proxy_assets;
2635 edl->Garbage::add_user();
2637 undo_before(_("proxy"), this);
2638 int asset_scale = !new_scale ? 0 :
2639 !new_use_scaler ? 1 : new_scale;
2640 ProxyRender proxy_render(this, asset, asset_scale);
2642 // revert project to original size from current size
2643 // remove all session proxy assets at the at the current proxy_scale
2644 int proxy_scale = edl->session->proxy_scale;
2646 if( edl->session->proxy_state == PROXY_ACTIVE ) {
2647 Asset *orig_asset = edl->assets->first;
2648 for( ; orig_asset; orig_asset=orig_asset->next ) {
2649 char new_path[BCTEXTLEN];
2650 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2651 // test if proxy asset was already added to proxy_assets
2653 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2654 got_it = !strcmp(proxy_assets[i]->path, new_path);
2655 if( got_it ) continue;
2656 Asset *proxy_asset = edl->assets->get_asset(new_path);
2657 if( !proxy_asset ) continue;
2658 // add pointer to existing EDL asset if it exists
2659 // EDL won't delete it unless it's the same pointer.
2660 proxy_assets.append(proxy_asset);
2661 proxy_asset->add_user();
2662 orig_idxbls.append(orig_asset);
2663 orig_asset->add_user();
2665 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2666 EDL *orig_nested = edl->nested_edls[i];
2667 char new_path[BCTEXTLEN];
2668 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2669 // test if proxy asset was already added to proxy_assets
2671 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2672 got_it = !strcmp(proxy_assets[i]->path, new_path);
2673 if( got_it ) continue;
2674 Asset *proxy_nested = edl->assets->get_asset(new_path);
2675 if( !proxy_nested ) continue;
2676 // add pointer to existing EDL asset if it exists
2677 // EDL won't delete it unless it's the same pointer.
2678 proxy_assets.append(proxy_nested);
2679 proxy_nested->add_user();
2680 orig_idxbls.append(orig_nested);
2681 orig_nested->add_user();
2684 // convert from the proxy assets to the original assets
2685 edl->set_proxy(0, 0, &proxy_assets, &orig_idxbls);
2687 // remove the references
2688 for( int i=0; i<proxy_assets.size(); ++i ) {
2689 Asset *proxy = (Asset *) proxy_assets[i];
2690 proxy->width = proxy->actual_width;
2691 proxy->height = proxy->actual_height;
2692 proxy->remove_user();
2693 edl->assets->remove_pointer(proxy);
2694 proxy->remove_user();
2696 proxy_assets.remove_all();
2697 for( int i = 0; i < orig_idxbls.size(); i++ )
2698 orig_idxbls[i]->remove_user();
2699 orig_idxbls.remove_all();
2702 ArrayList<char *> confirm_paths; // test for new files
2703 confirm_paths.set_array_delete();
2705 // convert to new size if not original size
2708 Asset *orig = edl->assets->first;
2709 for( ; orig; orig=orig->next ) {
2710 Asset *proxy = proxy_render.add_original(orig, new_scale);
2711 if( !proxy ) continue;
2712 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2713 int got_it = exists && // if proxy exists, and is newer than orig
2714 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2716 if( exists ) // prompt user to overwrite
2717 confirm_paths.append(cstrdup(proxy->path));
2718 proxy_render.add_needed(orig, proxy);
2721 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2722 EDL *orig_nested = edl->nested_edls[i];
2723 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2724 if( !proxy ) continue;
2725 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2726 int got_it = exists && // if proxy exists, and is newer than orig_nested
2727 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2729 if( exists ) // prompt user to overwrite
2730 confirm_paths.append(cstrdup(proxy->path));
2731 proxy_render.add_needed(orig_nested, proxy);
2734 edl->session->proxy_state = PROXY_ACTIVE;
2737 edl->session->proxy_state = PROXY_INACTIVE;
2740 // test for existing files
2741 if( confirm_paths.size() ) {
2742 result = ConfirmSave::test_files(this, &confirm_paths);
2743 confirm_paths.remove_all_objects();
2746 if( !result && new_scale )
2747 result = proxy_render.create_needed_proxies(new_scale);
2749 if( !result ) { // resize project
2750 edl->set_proxy(new_scale, new_use_scaler,
2751 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2753 undo_after(_("proxy"), LOAD_ALL);
2754 edl->Garbage::remove_user();
2757 return !result ? proxy_render.needed_proxies.size() : -1;
2760 void MWindow::test_plugins(EDL *new_edl, const char *path)
2762 char string[BCTEXTLEN];
2764 // Do a check whether plugins exist
2765 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2766 for( int k=0; k<track->plugin_set.total; ++k ) {
2767 PluginSet *plugin_set = track->plugin_set[k];
2768 for( Plugin *plugin = (Plugin*)plugin_set->first;
2769 plugin; plugin = (Plugin*)plugin->next ) {
2770 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2771 // ok we need to find it in plugindb
2772 PluginServer *server =
2773 scan_plugindb(plugin->title, track->data_type);
2774 if( !server || server->transition ) {
2776 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2777 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2778 "effect", _(plugin->title), path);
2779 MainError::show_error(string);
2784 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2785 if( !edit->transition ) continue;
2786 // ok we need to find transition in plugindb
2787 PluginServer *server =
2788 scan_plugindb(edit->transition->title, track->data_type);
2789 if( !server || !server->transition ) {
2791 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2792 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2793 "transition", _(edit->transition->title), path);
2794 MainError::show_error(string);
2801 void MWindow::init_shm(const char *pfn, int64_t min)
2804 // Fix shared memory
2805 FILE *fd = fopen(pfn, "r");
2807 fscanf(fd, "%jd", &result);
2809 if( result >= min ) return;
2812 fd = fopen(pfn, "w");
2814 fprintf(fd, "0x%jx", min);
2817 fd = fopen(pfn, "r");
2819 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2823 fscanf(fd, "%jd", &result);
2825 if( result < min ) {
2826 eprintf(_("MWindow::init_shm: %s is %p.\n"
2827 "you probably need to be root, or:\n"
2828 "as root, run: echo 0x%jx > %s\n"
2829 "before trying to start cinelerra.\n"
2830 "It should be at least 0x%jx for Cinelerra.\n"),
2831 pfn, (void *)result, min, pfn, min);
2835 void MWindow::create_objects(int want_gui,
2839 const int debug = 0;
2840 if(debug) PRINT_TRACE
2842 // For some reason, init_signals must come after show_splash or the signals won't
2845 if(debug) PRINT_TRACE
2848 if(debug) PRINT_TRACE
2850 if(debug) PRINT_TRACE
2851 default_standard = default_std();
2852 init_defaults(defaults, config_path);
2857 splash_window->update_status(_("Initializing Plugins"));
2858 init_plugins(this, preferences);
2859 if(debug) PRINT_TRACE
2860 init_ladspa_plugins(this, preferences);
2861 if(debug) PRINT_TRACE
2862 init_plugin_tips(*plugindb, cin_lang);
2864 splash_window->update_status(_("Initializing GUI"));
2865 if(debug) PRINT_TRACE
2868 if(debug) PRINT_TRACE
2872 splash_window->update_status(_("Initializing Fonts"));
2873 char string[BCTEXTLEN];
2874 strcpy(string, preferences->plugin_dir);
2875 strcat(string, "/" FONT_SEARCHPATH);
2876 BC_Resources::init_fontconfig(string);
2877 if(debug) PRINT_TRACE
2883 // Default project created here
2885 if(debug) PRINT_TRACE
2888 if(debug) PRINT_TRACE
2893 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2896 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2898 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2899 if(session->show_vwindow)
2900 get_viewer(1, DEFAULT_VWINDOW);
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());
2907 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2910 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2913 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2916 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2919 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2925 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2926 mainprogress = new MainProgress(this, gui);
2927 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2928 undo = new MainUndo(this);
2930 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2932 plugin_guis = new PluginGUIs(this);
2933 dead_plugins = new ArrayList<PluginServer*>;
2934 keyframe_threads = new ArrayList<KeyFrameThread*>;
2936 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2939 session->show_vwindow);
2941 // Show all vwindows
2942 // if(session->show_vwindow) {
2943 // for(int j = 0; j < vwindows.size(); j++) {
2944 // VWindow *vwindow = vwindows[j];
2945 // if( !vwindow->is_running() ) continue;
2946 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2949 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2950 // vwindow->gui->lock_window("MWindow::create_objects 1");
2951 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2952 // vwindow->gui->show_window();
2953 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2954 // vwindow->gui->unlock_window();
2959 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2961 if(session->show_cwindow)
2963 cwindow->gui->lock_window("MWindow::create_objects 1");
2964 cwindow->gui->show_window();
2965 cwindow->gui->unlock_window();
2968 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2969 if(session->show_awindow)
2971 awindow->gui->lock_window("MWindow::create_objects 1");
2972 awindow->gui->show_window();
2973 awindow->gui->unlock_window();
2976 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2977 if(session->show_lwindow)
2979 lwindow->gui->lock_window("MWindow::create_objects 1");
2980 lwindow->gui->show_window();
2981 lwindow->gui->unlock_window();
2984 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2986 (int)timer.get_difference(),
2988 if(session->show_gwindow)
2990 gwindow->gui->lock_window("MWindow::create_objects 1");
2991 gwindow->gui->show_window();
2992 gwindow->gui->unlock_window();
2995 if(debug) PRINT_TRACE
2997 gui->lock_window("MWindow::create_objects 1");
2998 gui->mainmenu->load_defaults(defaults);
2999 gui->mainmenu->update_toggles(0);
3000 gui->update_patchbay();
3001 gui->draw_canvas(0, 0);
3002 gui->draw_cursor(1);
3004 gui->raise_window();
3005 gui->unlock_window();
3006 cwindow->gui->lock_window("MWindow::create_objects 1");
3007 cwindow->gui->tool_panel->raise_tool();
3008 cwindow->gui->unlock_window();
3009 if(debug) PRINT_TRACE
3011 if(preferences->use_tipwindow)
3013 if(debug) PRINT_TRACE
3015 gui->add_keyboard_listener(
3016 (int (BC_WindowBase::*)(BC_WindowBase *))
3017 &MWindowGUI::keyboard_listener);
3020 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
3021 init_shm("/proc/sys/kernel/shmmni", 0x4000);
3022 if(debug) PRINT_TRACE
3024 BC_WindowBase::get_resources()->vframe_shm = 1;
3027 int MWindow::uses_opengl()
3029 if( !playback_3d || !playback_3d->running() ) return 0;
3030 PlaybackConfig *playback_config = edl->session->playback_config;
3031 return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
3034 void MWindow::show_splash()
3036 #include "data/heroine_logo9_png.h"
3037 VFrame *frame = new VFramePng(heroine_logo9_png);
3038 BC_DisplayInfo dpyi;
3039 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
3040 int rr = (rw < rh ? rw : rh) / 4;
3041 splash_window = new SplashGUI(frame, rr, rr);
3042 splash_window->create_objects();
3045 void MWindow::hide_splash()
3048 delete splash_window;
3053 void MWindow::start()
3057 // vwindows[DEFAULT_VWINDOW]->start();
3068 playback_3d->start();
3074 run_lock->lock("MWindow::run");
3078 brender_lock->lock("MWindow::run 1");
3079 delete brender; brender = 0;
3080 brender_lock->unlock();
3082 interrupt_indexes();
3088 void MWindow::show_vwindow(int raise)
3090 int total_running = 0;
3091 session->show_vwindow = 1;
3093 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
3094 // Raise all windows which are visible
3095 for(int j = 0; j < vwindows.size(); j++) {
3096 VWindow *vwindow = vwindows[j];
3097 if( !vwindow->is_running() ) continue;
3099 if( !raise && !vwindow->gui->is_hidden() ) continue;
3100 vwindow->gui->lock_window("MWindow::show_vwindow");
3101 vwindow->gui->show_window(0);
3102 vwindow->gui->raise_window();
3103 vwindow->gui->flush();
3104 vwindow->gui->unlock_window();
3106 // If no windows visible
3107 if( !total_running )
3108 get_viewer(1, DEFAULT_VWINDOW);
3110 gui->mainmenu->show_vwindow->set_checked(1);
3114 void MWindow::hide_vwindow(int raise)
3116 session->show_vwindow = 0;
3117 int total_running = 0;
3119 for(int j = 0; j < vwindows.size(); j++) {
3120 VWindow *vwindow = vwindows[j];
3121 if( !vwindow->is_running() ) continue;
3123 if( !raise && !vwindow->gui->is_hidden() ) continue;
3124 vwindow->gui->lock_window("MWindow::show_vwindow");
3125 vwindow->gui->hide_window(0);
3126 vwindow->gui->unlock_window();
3128 gui->mainmenu->show_vwindow->set_checked(0);
3132 void MWindow::show_awindow()
3134 session->show_awindow = 1;
3135 awindow->gui->lock_window("MWindow::show_awindow");
3136 awindow->gui->show_window();
3137 awindow->gui->raise_window();
3138 awindow->gui->flush();
3139 awindow->gui->unlock_window();
3140 gui->mainmenu->show_awindow->set_checked(1);
3143 void MWindow::hide_awindow()
3145 session->show_awindow = 0;
3147 awindow->gui->lock_window("MWindow::show_awindow");
3148 awindow->gui->hide_window();
3149 awindow->gui->unlock_window();
3150 gui->mainmenu->show_awindow->set_checked(0);
3154 char *MWindow::get_cwindow_display()
3156 char *x11_host = screens < 2 || session->window_config == 0 ?
3157 session->a_x11_host : session->b_x11_host;
3158 return *x11_host ? x11_host : 0;
3161 void MWindow::show_cwindow()
3163 session->show_cwindow = 1;
3164 cwindow->show_window();
3165 cwindow->gui->tool_panel->raise_tool();
3166 gui->mainmenu->show_cwindow->set_checked(1);
3170 void MWindow::hide_cwindow()
3172 session->show_cwindow = 0;
3174 cwindow->gui->lock_window("MWindow::show_cwindow");
3175 cwindow->gui->hide_window();
3176 cwindow->gui->unlock_window();
3177 gui->mainmenu->show_cwindow->set_checked(0);
3181 void MWindow::show_gwindow()
3183 session->show_gwindow = 1;
3185 gwindow->gui->lock_window("MWindow::show_gwindow");
3186 gwindow->gui->show_window();
3187 gwindow->gui->raise_window();
3188 gwindow->gui->flush();
3189 gwindow->gui->unlock_window();
3191 gui->mainmenu->show_gwindow->set_checked(1);
3194 void MWindow::hide_gwindow()
3196 session->show_gwindow = 0;
3198 gwindow->gui->lock_window("MWindow::show_gwindow");
3199 gwindow->gui->hide_window();
3200 gwindow->gui->unlock_window();
3201 gui->mainmenu->show_gwindow->set_checked(0);
3204 void MWindow::show_lwindow()
3206 session->show_lwindow = 1;
3207 lwindow->gui->lock_window("MWindow::show_lwindow");
3208 lwindow->gui->show_window();
3209 lwindow->gui->raise_window();
3210 lwindow->gui->flush();
3211 lwindow->gui->unlock_window();
3212 gui->mainmenu->show_lwindow->set_checked(1);
3215 void MWindow::hide_lwindow()
3217 session->show_lwindow = 0;
3219 lwindow->gui->lock_window("MWindow::show_lwindow");
3220 lwindow->gui->hide_window();
3221 lwindow->gui->unlock_window();
3222 gui->mainmenu->show_lwindow->set_checked(0);
3226 void MWindow::restore_windows()
3228 gui->unlock_window();
3229 if( !session->show_vwindow ) {
3230 for( int i=0, n=vwindows.size(); i<n; ++i ) {
3231 VWindow *vwindow = vwindows[i];
3232 if( !vwindow || !vwindow->is_running() ) continue;
3233 vwindow->gui->lock_window("MWindow::restore_windows");
3234 vwindow->gui->close(1);
3235 vwindow->gui->unlock_window();
3241 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
3242 awindow->gui->lock_window("MWindow::restore_windows");
3243 awindow->gui->close_event();
3244 awindow->gui->unlock_window();
3246 else if( session->show_awindow && awindow->gui->is_hidden() )
3249 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
3250 cwindow->gui->lock_window("MWindow::restore_windows");
3251 cwindow->hide_window();
3252 cwindow->gui->unlock_window();
3254 else if( session->show_cwindow && cwindow->gui->is_hidden() )
3257 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
3258 gwindow->gui->lock_window("MWindow::restore_windows");
3259 gwindow->gui->close_event();
3260 gwindow->gui->unlock_window();
3262 else if( session->show_gwindow && gwindow->gui->is_hidden() )
3265 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
3266 lwindow->gui->lock_window("MWindow::restore_windows");
3267 lwindow->gui->close_event();
3268 lwindow->gui->unlock_window();
3270 else if( session->show_lwindow && lwindow->gui->is_hidden() )
3274 gui->lock_window("MWindow::restore_windows");
3278 void MWindow::load_layout(const char *layout)
3280 char path[BCTEXTLEN];
3281 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3282 session->load_file(path);
3284 gui->default_positions();
3288 void MWindow::save_layout(const char *layout)
3290 char path[BCTEXTLEN];
3291 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3292 session->save_file(path);
3295 void MWindow::delete_layout(const char *layout)
3297 char path[BCTEXTLEN];
3298 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3302 int MWindow::tile_windows(int window_config)
3304 int need_reload = 0;
3305 int play_config = window_config==0 ? 0 : 1;
3306 edl->session->playback_config->load_defaults(defaults, play_config);
3307 session->default_window_positions(window_config);
3308 if( screens == 1 ) {
3309 gui->default_positions();
3310 sync_parameters(CHANGE_ALL);
3317 void MWindow::toggle_loop_playback()
3319 edl->local_session->loop_playback = !edl->local_session->loop_playback;
3320 set_loop_boundaries();
3323 gui->draw_overlays(1);
3324 sync_parameters(CHANGE_PARAMS);
3327 void MWindow::set_screens(int value)
3332 void MWindow::set_auto_keyframes(int value)
3334 edl->session->auto_keyframes = value;
3335 gui->mbuttons->edit_panel->keyframe->update(value);
3337 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
3338 cwindow->gui->flush();
3339 cwindow->gui->unlock_window();
3342 void MWindow::set_span_keyframes(int value)
3344 edl->session->span_keyframes = value;
3345 gui->mbuttons->edit_panel->span_keyframe->update(value);
3347 cwindow->gui->lock_window("MWindow::set_span_keyframes");
3348 cwindow->gui->flush();
3349 cwindow->gui->unlock_window();
3352 void MWindow::set_auto_visibility(Autos *autos, int value)
3354 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3355 edl->session->auto_conf->plugins = value;
3356 else if( autos->autoidx >= 0 )
3357 edl->session->auto_conf->autos[autos->autoidx] = value;
3361 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3362 gui->mainmenu->update_toggles(1);
3363 gui->unlock_window();
3364 gwindow->gui->update_toggles(1);
3365 gui->lock_window("MWindow::set_auto_visibility");
3368 void MWindow::set_keyframe_type(int mode)
3370 gui->lock_window("MWindow::set_keyframe_type");
3371 edl->local_session->floatauto_type = mode;
3372 gui->mainmenu->update_toggles(0);
3373 gui->unlock_window();
3376 int MWindow::set_editing_mode(int new_editing_mode)
3378 edl->session->editing_mode = new_editing_mode;
3379 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3380 gui->mbuttons->edit_panel->update();
3381 gui->set_editing_mode(1);
3383 cwindow->gui->lock_window("MWindow::set_editing_mode");
3384 cwindow->gui->edit_panel->update();
3385 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3386 cwindow->gui->unlock_window();
3390 void MWindow::toggle_editing_mode()
3392 int mode = edl->session->editing_mode;
3393 if( mode == EDITING_ARROW )
3394 set_editing_mode(EDITING_IBEAM);
3396 set_editing_mode(EDITING_ARROW);
3399 void MWindow::toggle_camera_xyz()
3401 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3402 gwindow->gui->toggle_camera_xyz();
3403 gwindow->gui->unlock_window();
3406 void MWindow::toggle_projector_xyz()
3408 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3409 gwindow->gui->toggle_projector_xyz();
3410 gwindow->gui->unlock_window();
3413 void MWindow::set_labels_follow_edits(int value)
3415 edl->session->labels_follow_edits = value;
3416 gui->mbuttons->edit_panel->locklabels->update(value);
3417 gui->mainmenu->labels_follow_edits->set_checked(value);
3421 void MWindow::sync_parameters(int change_type)
3423 if( in_destructor ) return;
3425 // Sync engines which are playing back
3426 if( cwindow->playback_engine->is_playing_back ) {
3427 if( change_type == CHANGE_PARAMS ) {
3428 // TODO: block keyframes until synchronization is done
3429 cwindow->playback_engine->sync_parameters(edl);
3433 int command = cwindow->playback_engine->command->command;
3434 // Waiting for tracking to finish would make the restart position more
3435 // accurate but it can't lock the window to stop tracking for some reason.
3436 // Not waiting for tracking gives a faster response but restart position is
3437 // only as accurate as the last tracking update.
3438 cwindow->playback_engine->transport_stop(0);
3439 cwindow->playback_engine->next_command->realtime = 1;
3440 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3444 cwindow->refresh_frame(change_type);
3448 void MWindow::age_caches()
3450 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3452 // preferences->cache_size,
3453 // audio_cache->get_memory_usage(1),
3454 // video_cache->get_memory_usage(1),
3455 // frame_cache->get_memory_usage(),
3456 // wave_cache->get_memory_usage(),
3458 frame_cache->age_cache(512);
3459 wave_cache->age_cache(8192);
3461 int64_t memory_usage;
3462 int64_t prev_memory_usage = 0;
3464 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3465 while( !result && prev_memory_usage !=
3466 (memory_usage=video_cache->get_memory_usage(1)) &&
3467 memory_usage > video_size ) {
3468 video_cache->delete_oldest();
3469 prev_memory_usage = memory_usage;
3472 prev_memory_usage = 0;
3474 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3475 while( !result && prev_memory_usage !=
3476 (memory_usage=audio_cache->get_memory_usage(1)) &&
3477 memory_usage > audio_size ) {
3478 audio_cache->delete_oldest();
3479 prev_memory_usage = memory_usage;
3483 void MWindow::reset_android_remote()
3485 gui->use_android_remote(preferences->android_remote);
3489 void MWindow::show_keyframe_gui(Plugin *plugin)
3491 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3492 // Find existing thread
3493 for( int i=0; i<keyframe_threads->size(); ++i ) {
3494 int plugin_id = keyframe_threads->get(i)->plugin_id;
3495 if( plugin_id == plugin->orig_id ) {
3496 keyframe_threads->get(i)->start_window(plugin, 0);
3497 keyframe_gui_lock->unlock();
3502 // Find unused thread
3503 for( int i=0; i<keyframe_threads->size(); ++i ) {
3504 if( keyframe_threads->get(i)->plugin_id < 0 ) {
3505 keyframe_threads->get(i)->start_window(plugin, 0);
3506 keyframe_gui_lock->unlock();
3511 // Create new thread
3512 KeyFrameThread *thread = new KeyFrameThread(this);
3513 keyframe_threads->append(thread);
3514 thread->start_window(plugin, 0);
3515 keyframe_gui_lock->unlock();
3519 void MWindow::show_plugin(Plugin *plugin)
3524 // Remove previously deleted plugin GUIs
3525 dead_plugin_lock->lock("MWindow::show_plugin");
3526 dead_plugins->remove_all_objects();
3527 dead_plugin_lock->unlock();
3529 //printf("MWindow::show_plugin %d\n", __LINE__);
3532 plugin_gui_lock->lock("MWindow::show_plugin");
3533 for( int i=0; i<plugin_guis->total; ++i ) {
3534 // Pointer/id comparison
3535 PluginServer *plugin_gui = plugin_guis->get(i);
3536 if( plugin_gui->plugin_id == plugin->orig_id ) {
3537 plugin_gui->raise_window();
3544 //printf("MWindow::show_plugin 1\n");
3545 if( !done && !plugin->track ) {
3546 printf("MWindow::show_plugin track not defined.\n");
3550 PluginServer *server = scan_plugindb(plugin->title,
3551 plugin->track->data_type);
3553 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3554 if(server && server->uses_gui)
3556 PluginServer *gui = new PluginServer(*server);
3557 plugin_guis->append(gui);
3558 // Needs mwindow to do GUI
3559 gui->set_mwindow(this);
3560 gui->open_plugin(0, preferences, edl, plugin);
3565 plugin_gui_lock->unlock();
3566 // update show/gui_id
3567 sync_parameters(CHANGE_PARAMS);
3568 //printf("MWindow::show_plugin %d\n", __LINE__);
3571 //printf("MWindow::show_plugin 2\n");
3574 void MWindow::hide_plugin(Plugin *plugin, int lock)
3577 return hide_plugin(plugin->orig_id, lock);
3580 void MWindow::hide_plugin(int plugin_id, int lock)
3582 // Update the toggle
3583 gui->lock_window("MWindow::hide_plugin");
3584 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3585 gui->unlock_window();
3587 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3588 for( int i=0; i<plugin_guis->total; ++i ) {
3589 PluginServer *plugin_gui = plugin_guis->get(i);
3590 if( plugin_gui->plugin_id == plugin_id ) {
3591 plugin_guis->remove(plugin_gui);
3592 if(lock) plugin_gui_lock->unlock();
3593 // Last command executed in client side close
3594 // Schedule for deletion
3595 plugin_gui->hide_gui();
3596 delete_plugin(plugin_gui);
3601 if(lock) plugin_gui_lock->unlock();
3602 // update show/gui_id
3603 sync_parameters(CHANGE_PARAMS);
3606 void MWindow::delete_plugin(PluginServer *plugin)
3608 dead_plugin_lock->lock("MWindow::delete_plugin");
3609 dead_plugins->append(plugin);
3610 dead_plugin_lock->unlock();
3613 void MWindow::hide_plugins()
3615 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3616 while(plugin_guis->size())
3618 PluginServer *ptr = plugin_guis->get(0);
3619 plugin_guis->remove(ptr);
3620 plugin_gui_lock->unlock();
3621 // Last command executed in client side close
3622 // Schedule for deletion
3625 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3627 plugin_gui_lock->unlock();
3629 hide_keyframe_guis();
3632 void MWindow::hide_keyframe_guis()
3634 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3635 for(int i = 0; i < keyframe_threads->size(); i++)
3637 keyframe_threads->get(i)->close_window();
3639 keyframe_gui_lock->unlock();
3642 void MWindow::hide_keyframe_gui(Plugin *plugin)
3644 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3645 for( int i = 0; i < keyframe_threads->size(); i++) {
3646 KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
3647 if( keyframe_gui->plugin_id == plugin->orig_id ) {
3648 keyframe_gui->close_window();
3652 keyframe_gui_lock->unlock();
3655 int MWindow::get_hash_color(Edit *edit)
3657 Indexable *idxbl = edit->asset ?
3658 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3659 if( !idxbl ) return 0;
3660 char path[BCTEXTLEN];
3661 // map proxy colors to unproxy colors
3662 if( edl->session->proxy_state != PROXY_ACTIVE ||
3663 !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3664 ProxyRender::from_proxy_path(path, (Asset*)idxbl, edl->session->proxy_scale) )
3665 strcpy(path, idxbl->path);
3666 char *cp = strrchr(path, '/');
3667 cp = !cp ? path : cp+1;
3668 uint8_t *bp = (uint8_t*)cp;
3670 while( *bp ) v += *bp++;
3671 return get_hash_color(v);
3674 int MWindow::get_hash_color(int v)
3676 int hash = 0x303030;
3677 if( v & 0x01 ) hash ^= 0x000040;
3678 if( v & 0x02 ) hash ^= 0x004000;
3679 if( v & 0x04 ) hash ^= 0x400000;
3680 if( v & 0x08 ) hash ^= 0x080000;
3681 if( v & 0x10 ) hash ^= 0x000800;
3682 if( v & 0x20 ) hash ^= 0x000008;
3683 if( v & 0x40 ) hash ^= 0x404040;
3684 if( v & 0x80 ) hash ^= 0x080808;
3688 int MWindow::get_group_color(int v)
3690 int color = 0x606060;
3691 if( v & 0x01 ) color ^= 0x000080;
3692 if( v & 0x02 ) color ^= 0x008000;
3693 if( v & 0x04 ) color ^= 0x800000;
3694 if( v & 0x08 ) color ^= 0x100000;
3695 if( v & 0x10 ) color ^= 0x001000;
3696 if( v & 0x20 ) color ^= 0x000010;
3697 if( v & 0x40 ) color ^= 0x080808;
3698 if( v & 0x80 ) color ^= 0x909090;
3702 int MWindow::get_title_color(Edit *edit)
3704 unsigned color = edit->color & 0xffffff;
3705 unsigned alpha = (~edit->color>>24) & 0xff;
3707 if( edit->group_id )
3708 color = get_group_color(edit->group_id);
3709 else if( preferences->autocolor_assets )
3710 color = get_hash_color(edit);
3715 alpha = session->title_bar_alpha*255;
3716 return color | (~alpha<<24);
3719 void MWindow::update_keyframe_guis()
3721 // Send new configuration to keyframe GUI's
3722 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3723 for( int i=0; i<keyframe_threads->size(); ++i ) {
3724 KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
3725 Plugin *plugin = edl->tracks->plugin_exists(keyframe_gui->plugin_id);
3727 keyframe_gui->update_gui(1);
3729 keyframe_gui->close_window();
3731 keyframe_gui_lock->unlock();
3734 void MWindow::update_plugin_guis(int do_keyframe_guis)
3736 // Send new configuration to plugin GUI's
3737 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3739 for( int i=0; i<plugin_guis->size(); ++i ) {
3740 PluginServer *plugin_gui = plugin_guis->get(i);
3741 Plugin *plugin = edl->tracks->plugin_exists(plugin_gui->plugin_id);
3742 if( plugin && plugin->show )
3743 plugin_gui->update_gui();
3745 // Schedule for deletion if no plugin or not shown
3746 plugin_guis->remove_number(i--);
3747 plugin_gui->hide_gui();
3748 delete_plugin(plugin_gui);
3753 // Change plugin variable if not visible
3754 Track *track = edl->tracks->first;
3755 for( ; track; track=track->next ) {
3756 for( int i=0; i < track->plugin_set.size(); ++i ) {
3757 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3758 for( ; plugin; plugin = (Plugin*)plugin->next ) {
3760 for( int i=0; i<plugin_guis->size(); ++i ) {
3761 PluginServer *server = plugin_guis->get(i);
3762 if( server->plugin_id == plugin->orig_id ) {
3767 if( !got_it ) plugin->show = 0;
3772 plugin_gui_lock->unlock();
3773 if( do_keyframe_guis )
3774 update_keyframe_guis();
3777 void MWindow::stop_plugin_guis()
3779 // Send new configuration to plugin GUI's
3780 plugin_gui_lock->lock("MWindow::stop_plugin_guis");
3782 for( int i=0; i<plugin_guis->size(); ++i ) {
3783 PluginServer *plugin_gui = plugin_guis->get(i);
3784 plugin_gui->render_stop();
3786 plugin_gui_lock->unlock();
3789 int MWindow::plugin_gui_open(Plugin *plugin)
3791 int gui_id = plugin->gui_id;
3792 if( gui_id < 0 ) return 0;
3793 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3794 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3795 int result = plugin_server ? 1 : 0;
3796 plugin_gui_lock->unlock();
3801 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3803 int gui_id = plugin->gui_id;
3804 if( gui_id < 0 ) return;
3805 plugin_gui_lock->lock("MWindow::render_plugin_gui 0");
3806 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3808 plugin_server->render_gui(data);
3809 plugin_gui_lock->unlock();
3812 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3814 int gui_id = plugin->gui_id;
3815 if( gui_id < 0 ) return;
3816 plugin_gui_lock->lock("MWindow::render_plugin_gui 1");
3817 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3819 plugin_server->render_gui(data, size);
3820 plugin_gui_lock->unlock();
3823 void MWindow::reset_plugin_gui_frames(Plugin *plugin)
3825 int gui_id = plugin->gui_id;
3826 if( gui_id < 0 ) return;
3827 plugin_gui_lock->lock("MWindow::reset_plugin_gui_frames");
3828 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3830 plugin_server->reset_plugin_gui_frames();
3831 plugin_gui_lock->unlock();
3834 void MWindow::render_plugin_gui_frames(PluginClientFrames *frames, Plugin *plugin)
3836 int gui_id = plugin->gui_id;
3837 if( gui_id < 0 ) return;
3838 plugin_gui_lock->lock("MWindow::render_plugin_gui_frames");
3839 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3841 plugin_server->render_plugin_gui_frames(frames);
3842 plugin_gui_lock->unlock();
3845 double MWindow::get_tracking_position()
3847 return edl->local_session->get_selectionstart(1);
3850 int MWindow::get_tracking_direction()
3852 return cwindow->playback_engine->get_direction();
3855 void MWindow::update_plugin_states()
3857 plugin_gui_lock->lock("MWindow::update_plugin_states");
3858 for( int i=0; i<plugin_guis->total; ++i ) {
3860 PluginServer *src_plugingui = plugin_guis->get(i);
3861 int plugin_id = src_plugingui->plugin_id;
3862 Plugin *src_plugin = edl->tracks->plugin_exists(plugin_id);
3863 // Doesn't exist anymore
3865 hide_plugin(plugin_id, 0);
3869 plugin_gui_lock->unlock();
3873 void MWindow::update_plugin_titles()
3875 for( int i=0; i<plugin_guis->total; ++i )
3876 plugin_guis->get(i)->update_title();
3879 int MWindow::asset_to_edl(EDL *new_edl,
3881 RecordLabels *labels)
3883 const int debug = 0;
3884 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3887 // Keep frame rate, sample rate, and output size unchanged.
3888 // These parameters would revert the project if VWindow displayed an asset
3889 // of different size than the project.
3890 if(new_asset->video_data)
3892 new_edl->session->video_tracks = new_asset->layers;
3895 new_edl->session->video_tracks = 0;
3897 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3903 if(new_asset->audio_data)
3905 new_edl->session->audio_tracks = new_asset->channels;
3908 new_edl->session->audio_tracks = 0;
3909 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3911 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3912 new_edl->create_default_tracks();
3913 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3914 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3918 //printf("MWindow::asset_to_edl 3\n");
3919 new_edl->insert_asset(new_asset,
3924 //printf("MWindow::asset_to_edl 3\n");
3925 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3927 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3928 if(edl->session->cursor_on_frames)
3930 double length = new_edl->tracks->total_length();
3931 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3932 new_edl->tracks->clear(length, edl_length, 1, 1);
3938 char string[BCTEXTLEN];
3940 fs.extract_name(string, new_asset->path);
3941 //printf("MWindow::asset_to_edl 3\n");
3943 strcpy(new_edl->local_session->clip_title, string);
3944 //printf("MWindow::asset_to_edl 4 %s\n", string);
3945 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3947 new_edl->local_session->asset2edl = 1;
3952 // Reset everything after a load.
3953 void MWindow::update_project(int load_mode)
3955 const int debug = 0;
3957 if(debug) PRINT_TRACE
3958 edl->tracks->update_y_pixels(theme);
3959 session->update_clip_number();
3961 if(debug) PRINT_TRACE
3963 if( load_mode == LOADMODE_REPLACE ||
3964 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3965 edl->session->timecode_offset = 0;
3966 gui->close_keyvalue_popup();
3970 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3971 if(debug) PRINT_TRACE
3972 gui->unlock_window();
3975 cwindow->update(0, 0, 1, 1, 1);
3977 if(debug) PRINT_TRACE
3979 // Close all the vwindows
3980 if( load_mode == LOADMODE_REPLACE ||
3981 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3982 if(debug) PRINT_TRACE
3983 int first_vwindow = 0;
3984 if(session->show_vwindow) first_vwindow = 1;
3985 // Change visible windows to no source
3986 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3987 VWindow *vwindow = vwindows[i];
3988 if( !vwindow->is_running() ) continue;
3989 vwindow->change_source(-1);
3992 // Close remaining windows
3993 for(int i = first_vwindow; i < vwindows.size(); i++) {
3994 VWindow *vwindow = vwindows[i];
3995 if( !vwindow->is_running() ) continue;
3996 vwindow->close_window();
3998 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3999 VWindow *vwindow = get_viewer(1, -1);
4000 vwindow->change_source(i);
4002 if(debug) PRINT_TRACE
4006 for( int i=0; i<edl->mixers.size(); ++i ) {
4007 Mixer *mixer = edl->mixers[i];
4008 if( !mixer->show ) continue;
4009 ZWindow *zwindow = get_mixer(mixer);
4010 zwindow->set_title(mixer->title);
4013 cwindow->gui->canvas->set_zoom(edl, 0);
4017 if(debug) PRINT_TRACE
4018 cwindow->gui->lock_window("MWindow::update_project 2");
4019 cwindow->gui->timebar->update(0);
4020 Track *track = cwindow->calculate_affected_track();
4021 cwindow->mask_track_id = track ? track->get_id() : -1;
4022 cwindow->gui->tool_panel->raise_tool();
4023 cwindow->gui->update_canvas(0);
4024 cwindow->gui->unlock_window();
4026 if(debug) PRINT_TRACE
4027 cwindow->refresh_frame(CHANGE_ALL);
4029 awindow->gui->async_update_assets();
4030 if(debug) PRINT_TRACE
4032 gui->lock_window("MWindow::update_project");
4033 gui->update_mixers(0, 0);
4035 if(debug) PRINT_TRACE
4038 void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
4040 int got_indexes = 0;
4041 for( int i=0; i<new_edl->nested_edls.size(); ++i ) {
4042 EDL *nested_edl = new_edl->nested_edls[i];
4043 mainindexes->add_indexable(nested_edl);
4044 edl->nested_edls.update_index(nested_edl);
4047 for( Asset *asset=new_edl->assets->first; asset; asset=asset->next ) {
4048 mainindexes->add_indexable(asset);
4049 edl->assets->update(asset);
4052 // Start examining next batch of index files
4054 mainindexes->start_build();
4057 gui->lock_window("MWindow::stack_push");
4058 if( stack.size() < 9 ) {
4062 StackItem &item = stack.append();
4064 item.new_edl = new_edl;
4065 item.duration = new_edl->tracks->total_length();
4069 if( idxbl && idxbl->is_asset ) {
4071 Asset *asset = (Asset *)idxbl;
4072 if( asset->format == FILE_REF &&
4073 !stat(asset->path, &st) )
4074 item.mtime = st.st_mtime;
4078 strcpy(session->filename, edl->path);
4079 undo = new MainUndo(this);
4080 gui->stack_button->update();
4081 update_project(LOADMODE_REPLACE);
4083 gui->unlock_window();
4087 void MWindow::stack_pop()
4089 if( !stack.size() ) return;
4090 // writes on config_path/backup%d.xml
4093 // already have gui lock
4094 StackItem &item = stack.last();
4095 // session edl replaced, overwrite and save clip data
4096 if( item.new_edl != edl )
4097 item.new_edl->overwrite_clip(edl);
4098 Indexable *idxbl = item.idxbl;
4099 if( idxbl && idxbl->is_asset && item.mtime ) {
4100 Asset *asset = (Asset *)idxbl;
4101 if( asset->format == FILE_REF ) {
4102 char *path = asset->path;
4104 if( stat(path, &st) || item.mtime == st.st_mtime ) {
4105 int cw = xS(250), ch = yS(150), px, py;
4106 gui->get_pop_cursor(px, py);
4107 px -= cw/2; py -= ch/2;
4108 ConfirmRefWindow confirm(this, path, px, py, cw, ch);
4109 confirm.create_objects();
4110 int result = confirm.run_window();
4113 item.new_edl->save_xml(&file, path);
4114 file.terminate_string();
4115 if(file.write_to_file(path))
4116 eprintf(_("Cant write FileREF: %s"), path);
4127 // resize the indexable edits if the new_edl duration changed
4128 double duration = item.new_edl->tracks->total_length();
4129 double dt = duration - item.duration;
4130 if( fabs(dt) > 1e-4 )
4131 edl->tracks->update_idxbl_length(idxbl->id, dt);
4132 gui->unlock_window();
4133 gui->resource_thread->close_indexable(idxbl);
4134 remove_from_caches(idxbl);
4135 IndexFile::delete_index_files(preferences, idxbl);
4136 mainindexes->add_indexable(idxbl);
4137 mainindexes->start_build();
4138 awindow->gui->async_update_assets();
4139 gui->lock_window("MWindow::stack_pop");
4141 strcpy(session->filename, edl->path);
4142 update_project(LOADMODE_REPLACE);
4143 undo_after(_("open edl"), LOAD_ALL);
4145 gui->stack_button->update();
4148 int MWindow::save(EDL *edl, char *filename, int stat)
4151 edl->save_xml(&file, filename);
4152 file.terminate_string();
4153 if( file.write_to_file(filename) ) {
4154 eprintf(_("Couldn't open %s"), filename);
4158 char string[BCTEXTLEN];
4159 char *filename = stack.size() ?
4160 stack[0].edl->path : session->filename;
4161 sprintf(string, _("\"%s\" %jdC written"),
4162 filename, file.length());
4163 gui->lock_window("SaveAs::run");
4164 gui->show_message(string);
4165 gui->unlock_window();
4170 int MWindow::save(int save_as)
4172 char new_path[BCTEXTLEN]; new_path[0] = 0;
4173 char *path = stack.size() ? stack[0].edl->path : session->filename;
4174 if( save_as || !path[0] ) {
4175 if( ConfirmSave::get_save_path(this, new_path) )
4177 if( stack.size() ) {
4178 strcpy(path, new_path);
4179 set_titlebar(new_path);
4182 set_filename(new_path);
4183 gui->mainmenu->add_load(new_path);
4186 for( int i=stack.size(); --i>=0; ) {
4187 StackItem &item = stack[i];
4188 Indexable *idxbl = item.idxbl;
4189 if( !idxbl ) continue;
4190 if( idxbl->is_asset ) {
4191 Asset *asset = (Asset *)idxbl;
4192 if( asset->format == FILE_REF ) {
4193 if( save(item.new_edl, asset->path, 0) )
4197 else if( item.new_edl != idxbl )
4198 item.new_edl->overwrite_clip((EDL*)idxbl);
4200 EDL *new_edl = stack.size() ? stack[0].edl : edl;
4201 save(new_edl, path, 1);
4205 void MWindow::show_plugins()
4207 for( Track *track=edl->tracks->first; track; track=track->next ) {
4208 for( int i=0; i<track->plugin_set.size(); ++i ) {
4209 PluginSet *plugins = track->plugin_set[i];
4210 Plugin *plugin = plugins->get_first_plugin();
4211 for( ; plugin; plugin=(Plugin*)plugin->next ) {
4212 if( plugin->plugin_type == PLUGIN_STANDALONE &&
4214 show_plugin(plugin);
4220 void MWindow::clip_to_media()
4222 if( edl->session->proxy_scale != 1 ) {
4223 eprintf("Nesting not allowed when proxy scale != 1");
4227 awindow->gui->stop_vicon_drawing();
4228 int clips_total = session->drag_clips->total;
4229 for( int i=0; i<clips_total; ++i ) {
4230 EDL *clip = session->drag_clips->values[i];
4231 time_t dt; time(&dt);
4232 struct tm dtm; localtime_r(&dt, &dtm);
4233 char path[BCTEXTLEN], *cp = path, *ep = cp+sizeof(path)-1;
4234 // path_basename = "Nested_<date>-<time>_<basename>"
4235 cp += snprintf(cp, ep-cp, _("Nested_%02d%02d%02d-%02d%02d%02d_"),
4236 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
4237 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
4238 char *bp = strrchr(clip->local_session->clip_title, '/');
4239 bp = bp ? bp+1 : clip->local_session->clip_title;
4240 cp += snprintf(cp, ep-cp, "%s", bp);
4241 EDL *nested = edl->new_nested_clip(clip, path);
4242 edl->clips.remove(clip);
4243 clip->remove_user();
4244 mainindexes->add_indexable(nested);
4246 undo_after(_("clip2media"), LOAD_ALL);
4247 mainindexes->start_build();
4248 awindow->gui->async_update_assets();
4251 void MWindow::media_to_clip()
4254 int assets_total = session->drag_assets->total;
4255 for( int i=0; i<assets_total; ++i ) {
4256 Indexable *idxbl = session->drag_assets->values[i];
4257 if( idxbl->is_asset ) {
4258 eprintf(_("media is not EDL:\n%s"), idxbl->path);
4261 char clip_title[BCSTRLEN];
4265 sprintf(clip_title, _("Clip %d"), session->clip_number++);
4266 for( int i=0; name_ok && i<edl->clips.size(); ++i ) {
4267 char *title = edl->clips[i]->local_session->clip_title;
4268 if( !strcasecmp(clip_title, title) ) name_ok = 0;
4271 EDL *nested = (EDL *)idxbl;
4272 EDL *clip = edl->add_clip(nested);
4273 strcpy(clip->local_session->clip_title, clip_title);
4274 snprintf(clip->local_session->clip_notes,
4275 sizeof(clip->local_session->clip_notes),
4276 _("From: %s"), nested->path);
4278 undo_after(_("media2clip"), LOAD_ALL);
4279 awindow->gui->async_update_assets();
4282 int MWindow::create_ref(Asset *asset, EDL *ref)
4284 asset->format = FILE_REF;
4285 double secs = ref->tracks->total_length();
4286 int audio_channels = ref->session->audio_channels;
4287 asset->audio_data = audio_channels > 0 ? 1 : 0;
4288 asset->channels = audio_channels;
4289 asset->sample_rate = ref->session->sample_rate;
4290 asset->audio_length = audio_channels > 0 && secs > 0 ?
4291 secs * asset->sample_rate : 0;
4292 strcpy(asset->acodec, _("reference"));
4294 int video_layers = ref->session->video_channels;
4295 asset->video_data = video_layers > 0 ? 1 : 0;
4296 asset->layers = video_layers > 0 ? 1 : 0;
4297 asset->actual_width = ref->session->output_w;
4298 asset->actual_height = ref->session->output_h;
4299 asset->width = asset->actual_width;
4300 asset->height = asset->actual_height;
4301 asset->frame_rate = ref->session->frame_rate;
4302 asset->video_length = video_layers > 0 && secs > 0 ?
4303 secs * asset->frame_rate : 0;
4304 strcpy(asset->vcodec, _("reference"));
4308 void MWindow::update_preferences(Preferences *prefs)
4310 if( prefs != preferences )
4311 preferences->copy_from(prefs);
4312 if( cwindow->playback_engine )
4313 cwindow->playback_engine->update_preferences(prefs);
4314 for(int i = 0; i < vwindows.size(); i++) {
4315 VWindow *vwindow = vwindows[i];
4316 if( !vwindow->is_running() ) continue;
4317 if( vwindow->playback_engine )
4318 vwindow->playback_engine->update_preferences(prefs);
4320 for(int i = 0; i < zwindows.size(); i++) {
4321 ZWindow *zwindow = zwindows[i];
4322 if( !zwindow->is_running() ) continue;
4323 if( zwindow->zgui->playback_engine )
4324 zwindow->zgui->playback_engine->update_preferences(prefs);
4328 void MWindow::update_vwindow()
4330 for( int i=0; i<vwindows.size(); ++i ) {
4331 VWindow *vwindow = vwindows[i];
4332 if( vwindow->is_running() ) {
4333 vwindow->gui->lock_window("MWindow::update_vwindow");
4335 vwindow->gui->unlock_window();
4340 void MWindow::remove_indexfile(Indexable *indexable)
4342 if( !indexable->is_asset ) return;
4344 IndexFile::delete_index_files(preferences, indexable);
4347 void MWindow::rebuild_indices()
4349 for(int i = 0; i < session->drag_assets->total; i++)
4351 Indexable *indexable = session->drag_assets->get(i);
4352 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4353 remove_indexfile(indexable);
4354 // Schedule index build
4355 indexable->index_state->remove_user();
4356 indexable->index_state = new IndexState;
4357 IndexFile::delete_index_files(preferences, indexable);
4358 if( indexable->is_asset ) {
4359 Asset *asset = (Asset *)indexable;
4360 if( asset->format != FILE_PCM ) {
4361 asset->format = FILE_UNKNOWN;
4362 asset->reset_audio();
4364 asset->reset_video();
4365 remove_from_caches(asset);
4366 // File file; // re-probe the asset
4367 // file.open_file(preferences, asset, 1, 0);
4369 mainindexes->add_indexable(indexable);
4371 // still in render engine
4372 sync_parameters(CHANGE_ALL);
4373 awindow->gui->async_update_assets();
4374 mainindexes->start_build();
4378 void MWindow::get_backup_path(char *path, int len)
4380 char *cp = path, *ep = cp + len-1;
4381 cp += snprintf(cp, ep-cp, "%s/", File::get_config_path());
4382 int idx = stack.size();
4383 cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx);
4386 void MWindow::create_timestamped_copy_from_previous_backup(char *previouspath)
4388 if (previouspath == NULL) return;
4389 char backup_path[BCTEXTLEN];
4391 time_t now = time(NULL);
4392 struct tm* currenttime = localtime(&now);
4393 snprintf(backup_path, sizeof(backup_path),
4394 "%s/%s_%d%.2d%.2d_%.2d%.2d%.2d",
4395 File::get_config_path(), BACKUP_FILE1,
4396 currenttime->tm_year + 1900,
4397 currenttime->tm_mon + 1,
4398 currenttime->tm_mday,
4399 currenttime->tm_hour,
4400 currenttime->tm_min,
4401 currenttime->tm_sec);
4402 rename(previouspath, backup_path);
4405 void MWindow::save_backup()
4409 edl->set_path(session->filename);
4411 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
4412 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
4413 File::get_config_path(), BACKUP_FILE1);
4414 get_backup_path(backup_path, sizeof(backup_path));
4415 if( preferences->ongoing_backups )
4416 create_timestamped_copy_from_previous_backup(backup_path1);
4417 rename(backup_path, backup_path1);
4418 edl->save_xml(&file, backup_path);
4419 file.terminate_string();
4421 fs.complete_path(backup_path);
4423 if(file.write_to_file(backup_path)) {
4425 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
4426 gui->show_message(string2);
4431 void MWindow::load_backup()
4433 ArrayList<char*> path_list;
4434 path_list.set_array_delete();
4436 char backup_path[BCTEXTLEN];
4437 get_backup_path(backup_path, sizeof(backup_path));
4439 fs.complete_path(backup_path);
4441 path_list.append(out_path = new char[strlen(backup_path) + 1]);
4442 strcpy(out_path, backup_path);
4444 load_filenames(&path_list, LOADMODE_REPLACE, LOADMODE_EDL_CLIP, 0);
4445 edl->local_session->clip_title[0] = 0;
4446 // This is unique to backups since the path of the backup is different than the
4447 // path of the project.
4448 set_filename(edl->path);
4449 path_list.remove_all_objects();
4454 void MWindow::save_undo_data()
4456 if( stack.size() > 0 ) return;
4457 if( !preferences->perpetual_session ) return;
4458 char perpetual_path[BCTEXTLEN];
4459 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4460 File::get_config_path(), PERPETUAL_FILE);
4461 FILE *fp = fopen(perpetual_path,"w");
4467 void MWindow::load_undo_data()
4469 if( stack.size() > 0 ) return;
4470 if( !preferences->perpetual_session ) return;
4471 char perpetual_path[BCTEXTLEN];
4472 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4473 File::get_config_path(), PERPETUAL_FILE);
4474 FILE *fp = fopen(perpetual_path,"r");
4478 undo_after(_("perpetual load"), LOAD_ALL);
4482 void MWindow::remove_undo_data()
4484 if( stack.size() > 0 ) return;
4485 char perpetual_path[BCTEXTLEN];
4486 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4487 File::get_config_path(), PERPETUAL_FILE);
4488 ::remove(perpetual_path);
4491 int MWindow::copy_target(const char *path, const char *target)
4493 int ifd = ::open(path, O_RDONLY);
4495 eprintf("Cannot open asset: %s", path);
4499 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
4502 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
4503 char progress_title[BCTEXTLEN];
4504 sprintf(progress_title, _("Copying: %s\n"), target);
4505 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
4507 int64_t count = 0, len = -1;
4508 int bfrsz = 0x100000;
4509 uint8_t *bfr = new uint8_t[bfrsz];
4510 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
4511 if( len != ::write(ofd, bfr, len) ) {
4512 eprintf("Error writing: %s", target);
4515 if( progress.is_cancelled() ) {
4519 progress.update(count += len, 1);
4524 progress.stop_progress();
4526 eprintf("Error reading: %s", path);
4531 eprintf("Cannot create asset target: %s", target);
4536 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
4538 char target[BCTEXTLEN];
4540 const char *bp = real_path, *cp = bp;
4541 const char *lp = link_path, *np = lp;
4542 char *tp = target, *ep = tp+sizeof(target)-1, lch;
4543 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
4544 if( lch == '/' ) { np = lp; cp = bp; }
4546 while( tp<ep && *np ) {
4547 if( *np++ != '/' ) continue;
4548 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
4550 while( tp<ep && *cp ) *tp++ = *cp++;
4554 strcpy(target, real_path);
4555 if( symlink(target, link_path) ) {
4556 eprintf("Cannot create symlink: %s", link_path);
4562 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
4564 char dir_path[BCTEXTLEN];
4565 strcpy(dir_path, dir);
4567 fs.complete_path(dir_path);
4570 if( !stat(dir_path, &st) ) {
4571 if( !S_ISDIR(st.st_mode) ) {
4572 eprintf("Path exists and is not a directory\n%s", dir_path);
4577 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
4578 eprintf("Cannot create directory\n%s", dir_path);
4582 char *real_dir = realpath(dir_path, 0);
4583 strcpy(dir_path, real_dir);
4586 EDL *save_edl = new EDL;
4587 save_edl->create_objects();
4588 save_edl->copy_all(edl);
4590 char progress_title[BCTEXTLEN];
4591 sprintf(progress_title, _("Saving to %s:\n"), dir);
4592 int total_assets = save_edl->assets->total();
4593 gui->lock_window("MWindow::save_project");
4594 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
4595 gui->unlock_window();
4598 Asset *current = save_edl->assets->first;
4599 for( int i=0; !ret && current; ++i, current=NEXT ) {
4600 char *path = current->path;
4601 if( ::stat(path, &st) ) {
4602 eprintf("Asset not found: %s", path);
4605 char *real_path = realpath(path, 0);
4606 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
4607 char link_path[BCTEXTLEN];
4608 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
4610 if( strcmp(real_path, link_path) ) {
4611 if( !::lstat(link_path, &st) ) {
4613 ::remove(link_path);
4619 eprintf("copy/link to self, skippped: %s", path);
4623 if( save_mode == SAVE_PROJECT_COPY ) {
4624 if( copy_target(real_path, link_path) )
4628 link_target(real_path, link_path,
4629 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
4633 strcpy(path, link_path);
4635 if( progress->is_cancelled() ) break;
4636 progress->update(i);
4639 progress->stop_progress();
4642 char *cp = strrchr(dir_path,'/');
4643 char *bp = cp ? cp+1 : dir_path;
4644 char filename[BCTEXTLEN];
4645 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
4646 save_edl->set_path(filename);
4648 save_edl->save_xml(&file, filename);
4649 file.terminate_string();
4651 if( !file.write_to_file(filename) ) {
4652 char string[BCTEXTLEN];
4653 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
4654 gui->lock_window("SaveProject::run 2");
4655 gui->show_message(string);
4656 gui->unlock_window();
4657 gui->mainmenu->add_load(filename);
4660 eprintf(_("Couldn't open %s."), filename);
4662 save_edl->remove_user();
4665 gui->lock_window("MWindow::save_project");
4666 ArrayList<char*> filenames;
4667 filenames.append(filename);
4668 load_filenames(&filenames);
4669 gui->unlock_window();
4674 static inline int gcd(int m, int n)
4677 if( m < n ) { r = m; m = n; n = r; }
4678 while( (r = m % n) != 0 ) { m = n; n = r; }
4682 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4687 if(!width || !height) return 1;
4688 if( width == 720 && (height == 480 || height == 576) ) {
4689 w = 4; h = 3; return 0; // for NTSC and PAL
4692 ar = (double)width / height;
4693 // square-ish pixels
4694 if( EQUIV(ar, 1.0000) ) return 0;
4695 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4696 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4697 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4698 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4699 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4700 if( EQUIV(ar, 2.37037) ) { w = 64; h = 27; return 0; }
4702 int ww = width, hh = height;
4703 // numerator, denominator must be under mx
4704 int mx = 255, n = gcd(ww, hh);
4705 if( n > 1 ) { ww /= n; hh /= n; }
4706 // search near height in case extra/missing lines
4707 if( ww >= mx || hh >= mx ) {
4708 double err = height; // +/- 2 percent height
4709 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4710 int iw = width, ih = height+i;
4711 if( (n=gcd(iw, ih)) > 1 ) {
4712 int u = iw/n; if( u >= mx ) continue;
4713 int v = ih/n; if( v >= mx ) continue;
4714 double r = (double) u/v, er = fabs(ar-r);
4715 if( er >= err ) continue;
4716 err = er; ww = u; hh = v;
4725 void MWindow::reset_caches(int locked)
4727 if( locked ) gui->unlock_window();
4728 awindow->gui->stop_vicon_drawing(1);
4729 if( cwindow->playback_engine )
4730 cwindow->playback_engine->create_cache();
4731 for(int i = 0; i < vwindows.size(); i++) {
4732 VWindow *vwindow = vwindows[i];
4733 if( !vwindow->is_running() ) continue;
4734 if( !vwindow->playback_engine ) continue;
4735 vwindow->playback_engine->create_cache();
4737 gui->lock_window("MWindow::reset_caches");
4738 frame_cache->remove_all();
4739 wave_cache->remove_all();
4740 audio_cache->remove_all();
4741 video_cache->remove_all();
4742 if( !locked ) gui->unlock_window();
4745 void MWindow::remove_from_caches(Indexable *idxbl)
4747 awindow->gui->stop_vicon_drawing(1);
4748 frame_cache->remove_item(idxbl);
4749 wave_cache->remove_item(idxbl);
4750 if( gui->render_engine &&
4751 gui->render_engine_id == idxbl->id ) {
4752 delete gui->render_engine;
4753 gui->render_engine = 0;
4755 gui->resource_thread->close_indexable(idxbl);
4756 if( !idxbl->is_asset ) return;
4757 Asset *asset = (Asset *)idxbl;
4758 audio_cache->delete_entry(asset);
4759 video_cache->delete_entry(asset);
4760 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4761 cwindow->playback_engine->audio_cache->delete_entry(asset);
4762 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4763 cwindow->playback_engine->video_cache->delete_entry(asset);
4764 for(int i = 0; i < vwindows.size(); i++) {
4765 VWindow *vwindow = vwindows[i];
4766 if( !vwindow->is_running() ) continue;
4767 if( !vwindow->playback_engine ) continue;
4768 if( vwindow->playback_engine->audio_cache )
4769 vwindow->playback_engine->audio_cache->delete_entry(asset);
4770 if( vwindow->playback_engine->video_cache )
4771 vwindow->playback_engine->video_cache->delete_entry(asset);
4773 for(int i = 0; i < zwindows.size(); i++) {
4774 ZWindow *zwindow = zwindows[i];
4775 if( !zwindow->is_running() ) continue;
4776 if( zwindow->zgui->playback_engine->audio_cache )
4777 zwindow->zgui->playback_engine->audio_cache->delete_entry(asset);
4778 if( zwindow->zgui->playback_engine->video_cache )
4779 zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
4781 awindow->gui->start_vicon_drawing();
4784 void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
4785 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4787 awindow->gui->stop_vicon_drawing(1);
4789 // Remove from VWindow.
4791 for(int i = 0; i < drag_clips->total; i++) {
4792 for(int j = 0; j < vwindows.size(); j++) {
4793 VWindow *vwindow = vwindows[j];
4794 if( !vwindow->is_running() ) continue;
4795 if(drag_clips->get(i) == vwindow->get_edl()) {
4796 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4797 vwindow->delete_source(1, 1);
4798 vwindow->gui->unlock_window();
4805 for(int i = 0; i < drag_assets->size(); i++) {
4806 for(int j = 0; j < vwindows.size(); j++) {
4807 VWindow *vwindow = vwindows[j];
4808 if( !vwindow->is_running() ) continue;
4809 if(drag_assets->get(i) == vwindow->get_source()) {
4810 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4811 vwindow->delete_source(1, 1);
4812 vwindow->gui->unlock_window();
4817 for(int i = 0; i < drag_assets->total; i++) {
4818 Indexable *indexable = drag_assets->get(i);
4819 if(indexable->is_asset) remove_from_caches(indexable);
4822 if( delete_indexes ) {
4823 for(int i = 0; i < drag_assets->size(); i++) {
4824 Indexable *indexable = drag_assets->get(i);
4825 remove_indexfile(indexable);
4830 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4831 if(push_undo) undo_before();
4832 if(drag_assets) edl->remove_from_project(drag_assets);
4833 if(drag_clips) edl->remove_from_project(drag_clips);
4834 if(redraw) save_backup();
4835 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4839 gui->lock_window("MWindow::remove_assets_from_project 3");
4840 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4841 gui->unlock_window();
4843 // Removes from playback here
4844 sync_parameters(CHANGE_ALL);
4847 awindow->gui->async_update_assets();
4850 void MWindow::remove_assets_from_disk()
4852 remove_assets_from_project(1, 1, 1,
4853 session->drag_assets, session->drag_clips);
4856 for(int i = 0; i < session->drag_assets->total; i++)
4858 remove(session->drag_assets->get(i)->path);
4862 void MWindow::dump_plugins(FILE *fp)
4864 if( !plugindb ) return;
4865 for(int i = 0; i < plugindb->total; i++)
4867 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4868 " synth=%d transition=%d theme=%d %s\n",
4869 plugindb->get(i)->plugin_type,
4870 plugindb->get(i)->audio,
4871 plugindb->get(i)->video,
4872 plugindb->get(i)->realtime,
4873 plugindb->get(i)->multichannel,
4874 plugindb->get(i)->get_synthesis(),
4875 plugindb->get(i)->transition,
4876 plugindb->get(i)->theme,
4877 plugindb->get(i)->title);
4881 void MWindow::dump_edl(FILE *fp)
4887 void MWindow::dump_undo(FILE *fp)
4893 void MWindow::dump_exe(FILE *fp)
4895 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4896 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4898 int ret = -1, n = 100;
4899 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4900 exe_path[len] = 0; strcpy(proc_path, exe_path);
4903 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4906 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4907 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4908 struct tm *tm = localtime(&st.st_mtime);
4910 strftime(mtime, sizeof(mtime), "%F %T", tm);
4911 fprintf(fp,"mtime: %s\n", mtime);
4913 // people hit ctl-c waiting for this
4914 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4915 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4918 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4919 int64_t maxsz = 1024*pagsz;
4920 int64_t size = st.st_size, pos = 0;
4922 while( (bfrsz = size-pos) > 0 ) {
4923 if( bfrsz > maxsz ) bfrsz = maxsz;
4924 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4925 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4926 if( bfr == MAP_FAILED ) break;
4927 sha1.addBytes(bfr, bfrsz);
4932 ret = pos < size ? EIO : 0;
4933 fprintf(fp, "SHA1: ");
4934 uint8_t digest[20]; sha1.computeHash(digest);
4935 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4936 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4937 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4942 void MWindow::dump_caches(FILE *fp)
4944 fprintf(fp, "audio cache: ");
4945 audio_cache->dump(fp);
4946 fprintf(fp, "video cache: ");
4947 video_cache->dump(fp);
4950 void MWindow::trap_hook(FILE *fp, void *vp)
4952 MWindow *mwindow = (MWindow *)vp;
4953 // fprintf(fp, "\nPLUGINS:\n");
4954 // mwindow->dump_plugins(fp);
4955 fprintf(fp, "\nEDL:\n");
4956 mwindow->dump_edl(fp);
4957 fprintf(fp, "\nUNDO:\n");
4958 mwindow->dump_undo(fp);
4959 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4960 mwindow->dump_exe(fp);
4961 fprintf(fp, "\nCACHES:\n");
4962 mwindow->dump_caches(fp);
4970 int MWindow::save_defaults()
4972 gui->save_defaults(defaults);
4973 edl->save_defaults(defaults);
4974 session->save_defaults(defaults);
4975 preferences->save_defaults(defaults);
4977 for(int i = 0; i < plugin_guis->total; i++)
4979 // Pointer comparison
4980 plugin_guis->get(i)->save_defaults();
4982 awindow->save_defaults(defaults);
4988 int MWindow::run_script(FileXML *script)
4990 int result = 0, result2 = 0;
4991 while(!result && !result2)
4993 result = script->read_tag();
4996 if(script->tag.title_is("new_project"))
4998 // Run new in immediate mode.
4999 // gui->mainmenu->new_project->run_script(script);
5002 if(script->tag.title_is("record"))
5004 // Run record as a thread. It is a terminal command.
5006 // Will read the complete scipt file without letting record read it if not
5012 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
5019 // ================================= synchronization
5022 int MWindow::interrupt_indexes()
5024 mainprogress->cancelled = 1;
5025 mainindexes->interrupt_build();
5031 void MWindow::next_time_format()
5033 switch( edl->session->time_format ) {
5034 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
5035 case TIME_HMSF: edl->session->time_format = TIME_TIMECODE; break;
5036 case TIME_TIMECODE: edl->session->time_format = TIME_FRAMES; break;
5037 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES; break;
5038 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
5039 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SECONDS; break;
5040 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
5041 case TIME_FEET_FRAMES: edl->session->time_format = TIME_HMS; break;
5043 time_format_common();
5046 void MWindow::prev_time_format()
5048 switch( edl->session->time_format ) {
5049 case TIME_HMS: edl->session->time_format = TIME_FEET_FRAMES; break;
5050 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
5051 case TIME_TIMECODE: edl->session->time_format = TIME_HMSF; break;
5052 case TIME_FRAMES: edl->session->time_format = TIME_TIMECODE; break;
5053 case TIME_SAMPLES: edl->session->time_format = TIME_FRAMES; break;
5054 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
5055 case TIME_SECONDS: edl->session->time_format = TIME_SAMPLES_HEX; break;
5056 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
5059 time_format_common();
5062 void MWindow::time_format_common()
5064 gui->lock_window("MWindow::next_time_format");
5065 gui->redraw_time_dependancies();
5068 char string[BCTEXTLEN], string2[BCTEXTLEN];
5069 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
5070 gui->show_message(string);
5072 gui->unlock_window();
5076 int MWindow::set_filename(const char *filename)
5078 if( filename != session->filename )
5079 strcpy(session->filename, filename);
5080 if( filename != edl->path )
5081 strcpy(edl->path, filename);
5082 return set_titlebar(filename);
5085 int MWindow::set_titlebar(const char *filename)
5087 if( !gui ) return 0;
5090 char string[BCTEXTLEN], string2[BCTEXTLEN];
5091 dir.extract_name(string, filename);
5092 sprintf(string2, PROGRAM_NAME ": %s", string);
5093 gui->set_title(string2);
5096 gui->set_title(PROGRAM_NAME);
5101 int MWindow::set_loop_boundaries()
5103 double start = edl->local_session->get_selectionstart();
5104 double end = edl->local_session->get_selectionend();
5112 if(edl->tracks->total_length())
5115 end = edl->tracks->total_length();
5122 if(edl->local_session->loop_playback && start != end)
5124 edl->local_session->loop_start = start;
5125 edl->local_session->loop_end = end;
5136 int MWindow::reset_meters()
5138 cwindow->gui->lock_window("MWindow::reset_meters 1");
5139 cwindow->gui->meters->reset_meters();
5140 cwindow->gui->unlock_window();
5142 for(int j = 0; j < vwindows.size(); j++) {
5143 VWindow *vwindow = vwindows[j];
5144 if( !vwindow->is_running() ) continue;
5145 vwindow->gui->lock_window("MWindow::reset_meters 2");
5146 vwindow->gui->meters->reset_meters();
5147 vwindow->gui->unlock_window();
5150 lwindow->gui->lock_window("MWindow::reset_meters 3");
5151 lwindow->gui->panel->reset_meters();
5152 lwindow->gui->unlock_window();
5154 gui->lock_window("MWindow::reset_meters 4");
5155 gui->reset_meters();
5156 gui->unlock_window();
5161 void MWindow::resync_guis()
5165 gui->lock_window("MWindow::resync_guis");
5166 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
5167 gui->unlock_window();
5169 cwindow->gui->lock_window("MWindow::resync_guis");
5170 cwindow->gui->resize_event(cwindow->gui->get_w(),
5171 cwindow->gui->get_h());
5172 int channels = edl->session->audio_channels;
5173 cwindow->gui->meters->set_meters(channels, 1);
5174 cwindow->gui->flush();
5175 cwindow->gui->unlock_window();
5177 for(int i = 0; i < vwindows.size(); i++) {
5178 VWindow *vwindow = vwindows[i];
5179 if( !vwindow->is_running() ) continue;
5180 vwindow->gui->lock_window("MWindow::resync_guis");
5181 vwindow->gui->resize_event(vwindow->gui->get_w(),
5182 vwindow->gui->get_h());
5183 vwindow->gui->meters->set_meters(channels, 1);
5184 vwindow->gui->flush();
5185 vwindow->gui->unlock_window();
5188 lwindow->gui->lock_window("MWindow::resync_guis");
5189 lwindow->gui->panel->set_meters(channels, 1);
5190 lwindow->gui->flush();
5191 lwindow->gui->unlock_window();
5194 if(((edl->session->output_w % 4) ||
5195 (edl->session->output_h % 4)) &&
5196 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
5198 MainError::show_error(
5199 _("This project's dimensions are not multiples of 4 so\n"
5200 "it can't be rendered by OpenGL."));
5205 sync_parameters(CHANGE_ALL);
5208 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
5210 File *file = new File;
5211 EDLSession *session = edl->session;
5212 double old_framerate = session->frame_rate;
5213 double old_samplerate = session->sample_rate;
5214 int old_auto_keyframes = session->auto_keyframes;
5215 session->auto_keyframes = 0;
5216 int result = file->open_file(preferences, asset, 1, 0);
5217 if( !result && delete_tracks > 0 )
5219 int video_layers = asset->get_video_layers();
5220 if( !result && asset->video_data && vstream < video_layers ) {
5221 // try to get asset up to date, may fail
5222 file->select_video_stream(asset, vstream);
5223 // either way use what was/is there.
5224 double framerate = asset->get_frame_rate();
5225 int width = asset->get_w();
5226 int height = asset->get_h();
5228 // must be multiple of 4 for opengl
5229 width = (width+3) & ~3; height = (height+3) & ~3;
5231 int driver = session->playback_config->vconfig->driver;
5232 int color_model = file->get_best_colormodel(asset, driver);
5233 // color_model = BC_CModels::is_yuv(color_model) ?
5234 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
5235 // BC_CModels::is_float(color_model) ?
5236 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
5237 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
5238 // have alpha for now
5239 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
5240 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
5241 session->color_model = color_model;
5242 session->output_w = width;
5243 session->output_h = height;
5244 session->frame_rate = framerate;
5245 session->interlace_mode = asset->interlace_mode;
5246 // not, asset->actual_width/actual_height
5247 asset->width = session->output_w;
5248 asset->height = session->output_h;
5249 asset->frame_rate = session->frame_rate;
5251 create_aspect_ratio(session->aspect_w, session->aspect_h,
5252 session->output_w, session->output_h);
5253 float ar = asset->aspect_ratio;
5255 //printf ("Aspect ratio from asset: %f \n", ar);
5256 if( EQUIV(ar, 1.3333) ) { session->aspect_w = 4; session->aspect_h = 3; }
5257 if( EQUIV(ar, 1.7777) ) { session->aspect_w = 16; session->aspect_h = 9; }
5258 if( EQUIV(ar, 2.1111) ) { session->aspect_w = 19; session->aspect_h = 9; }
5259 if( EQUIV(ar, 2.2222) ) { session->aspect_w = 20; session->aspect_h = 9; }
5260 if( EQUIV(ar, 2.3333) ) { session->aspect_w = 21; session->aspect_h = 9; }
5261 if( EQUIV(ar, 2.370370) ) { session->aspect_w = 64; session->aspect_h = 27; }
5265 Track *track = edl->tracks->first;
5266 for( Track *next_track=0; track; track=next_track ) {
5267 next_track = track->next;
5268 if( track->data_type != TRACK_VIDEO ) continue;
5269 if( delete_tracks ) {
5270 Edit *edit = track->edits->first;
5271 for( Edit *next_edit=0; edit; edit=next_edit ) {
5272 next_edit = edit->next;
5273 if( edit->channel != vstream ||
5274 !edit->asset || !edit->asset->is_asset ||
5275 !asset->equivalent(*edit->asset,1,1,edl) )
5279 if( track->edits->first ) {
5280 track->track_w = edl->session->output_w;
5281 track->track_h = edl->session->output_h;
5283 else if( delete_tracks )
5284 edl->tracks->delete_track(track, 0);
5287 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
5289 if( !result && asset->audio_data && asset->channels > 0 ) {
5290 session->sample_rate = asset->get_sample_rate();
5291 int64_t channel_mask = 0;
5292 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
5293 file->get_audio_for_video(vstream, astream, channel_mask);
5294 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
5295 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
5297 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
5298 if( channels < 1 ) channels = 1;
5299 if( channels > 6 ) channels = 6;
5300 session->audio_tracks = session->audio_channels = channels;
5302 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
5303 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
5304 remap_audio(MWindow::AUDIO_1_TO_1);
5306 if( delete_tracks ) {
5307 Track *track = edl->tracks->first;
5308 for( Track *next_track=0; track; track=next_track ) {
5309 next_track = track->next;
5310 if( track->data_type != TRACK_AUDIO ) continue;
5311 Edit *edit = track->edits->first;
5312 for( Edit *next_edit=0; edit; edit=next_edit ) {
5313 next_edit = edit->next;
5314 if( !((1<<edit->channel) & channel_mask) ||
5315 !edit->asset || !edit->asset->is_asset ||
5316 !asset->equivalent(*edit->asset,1,1,edl) )
5319 if( !track->edits->first )
5320 edl->tracks->delete_track(track, 0);
5324 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
5327 session->auto_keyframes = old_auto_keyframes;
5328 if( !result && delete_tracks > 0 ) {
5330 undo_after(_("select asset"), LOAD_ALL);
5336 int MWindow::select_asset(int vtrack, int delete_tracks)
5338 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
5340 track = edl->tracks->get(vtrack, TRACK_AUDIO);
5341 if( !track ) return 1;
5342 Edit *edit = track->edits->first;
5343 if( !edit ) return 1;
5344 Asset *asset = edit->asset;
5345 if( !asset || !asset->is_asset ) return 1;
5346 return select_asset(asset, edit->channel, 0, delete_tracks);
5349 void MWindow::dump_plugindb(FILE *fp)
5351 if( !plugindb ) return;
5352 for(int i = 0; i < plugindb->total; i++)
5353 plugindb->get(i)->dump(fp);
5356 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
5359 double unit_position = edl->local_session->get_selectionstart(1);
5360 unit_position = patch->track->to_units(unit_position, 0);
5362 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
5363 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5366 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
5369 double unit_position = edl->local_session->get_selectionstart(1);
5370 unit_position = patch->track->to_units(unit_position, 0);
5372 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
5373 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5376 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
5379 double unit_position = edl->local_session->get_selectionstart(1);
5380 unit_position = patch->track->to_units(unit_position, 0);
5382 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
5383 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5386 PatchGUI *MWindow::get_patchgui(Track *track)
5388 PatchGUI *patchgui = 0;
5389 TimelinePane **panes = gui->pane;
5390 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
5391 if( !panes[i] ) continue;
5392 PatchBay *patchbay = panes[i]->patchbay;
5393 if( !patchbay ) continue;
5394 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
5395 if( patchbay->patches.values[j]->track == track )
5396 patchgui = patchbay->patches.values[j];
5402 int MWindow::get_cpus(int out_w, int out_h)
5404 if( !out_w ) out_w = edl->session->output_w;
5405 if( !out_h ) out_h = edl->session->output_h;
5406 int cpus = out_w*out_h/0x80000 + 1;
5407 if( cpus > preferences->processors )
5408 cpus = preferences->processors;
5411 int MWindow::get_cpus()
5413 return get_cpus(edl->session->output_w, edl->session->output_h);
5416 void MWindow::draw_trackmovement()
5418 if( !redraw_tracks )
5419 redraw_tracks = new DrawTrackMovement(this);
5420 redraw_tracks->start();
5423 DrawTrackMovement::DrawTrackMovement(MWindow *mwindow)
5426 this->mwindow = mwindow;
5428 DrawTrackMovement::~DrawTrackMovement()
5433 void DrawTrackMovement::run()
5435 mwindow->gui->lock_window("DrawTrackMovement::run");
5436 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
5437 mwindow->gui->draw_trackmovement();
5438 mwindow->gui->unlock_window();
5442 ConfirmRefWindow::ConfirmRefWindow(MWindow *mwindow, char *path,
5443 int px, int py, int cw, int ch)
5444 : BC_Window(_(PROGRAM_NAME ": Confirm update"), px, py, cw, ch, cw, ch)
5446 this->mwindow = mwindow;
5448 // *** CONTEXT_HELP ***
5449 context_help_set_keyword("File by Reference");
5452 ConfirmRefWindow::~ConfirmRefWindow()
5456 void ConfirmRefWindow::create_objects()
5458 lock_window("ConfirmRefWindow::create_objects()");
5459 int x = xS(10), y = yS(10), pad = yS(5);
5461 add_subwindow(title = new BC_Title(x, y, _("FileREF not updated:")));
5462 y += title->get_h() + pad;
5463 BC_TextBox *text_box;
5464 add_subwindow(text_box = new BC_TextBox(x,y, get_w()-2*x, 1, path));
5465 y += text_box->get_h() + 2*pad;
5466 add_subwindow(title = new BC_Title(x, y, _("Save file ref changes?")));
5467 add_subwindow(new BC_OKButton(this));
5468 add_subwindow(new BC_CancelButton(this));