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;
253 // Need to delete brender temporary here.
256 run_lock->lock("MWindow::~MWindow");
258 //printf("MWindow::~MWindow %d\n", __LINE__);
259 if( wwindow && wwindow->is_running() )
260 wwindow->close_window();
261 if( twindow && twindow->is_running() )
262 twindow->close_window();
263 gui->remote_control->deactivate();
266 gui->channel_info->stop();
269 delete create_bd; create_bd = 0;
270 delete create_dvd; create_dvd = 0;
271 delete shuttle; shuttle = 0;
273 delete wintv; wintv = 0;
276 delete x10tv; x10tv = 0;
278 delete batch_render; batch_render = 0;
279 delete convert_render; convert_render = 0;
280 delete render; render = 0;
281 delete mixers_align; mixers_align = 0;
283 if( commercials && !commercials->remove_user() ) commercials = 0;
285 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
286 // Save defaults for open plugins
287 plugin_gui_lock->lock("MWindow::~MWindow");
288 for(int i = 0; i < plugin_guis->size(); i++) {
289 plugin_guis->get(i)->hide_gui();
290 delete_plugin(plugin_guis->get(i));
292 plugin_gui_lock->unlock();
293 hide_keyframe_guis();
296 // Give up and go to a movie
297 // cant run valgrind if this is used
299 gui->del_keyboard_listener(
300 (int (BC_WindowBase::*)(BC_WindowBase *))
301 &MWindowGUI::keyboard_listener);
303 // release the hounds
304 if( awindow && awindow->gui ) awindow->gui->close(0);
305 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
306 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
307 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
308 vwindows.remove_all_objects();
309 zwindows.remove_all_objects();
311 if( awindow ) awindow->join();
312 if( cwindow ) cwindow->join();
313 if( lwindow ) lwindow->join();
314 if( gwindow ) gwindow->join();
317 // one at a time, or nouveau chokes
318 #define close_gui(win) if( win ) { \
319 if( win->gui ) win->gui->close(0); \
325 vwindows.remove_all_objects();
326 zwindows.remove_all_objects();
331 dead_plugins->remove_all_objects();
332 // must delete theme before destroying plugindb
333 // theme destructor will be deleted by delete_plugins
334 delete theme; theme = 0;
337 keyframe_threads->remove_all_objects();
338 colormodels.remove_all_objects();
339 delete awindow; awindow = 0;
340 delete lwindow; lwindow = 0;
341 delete twindow; twindow = 0;
342 delete wwindow; wwindow = 0;
343 delete gwindow; gwindow = 0;
344 delete cwindow; cwindow = 0;
346 delete mainindexes; mainindexes = 0;
347 delete mainprogress; mainprogress = 0;
348 delete audio_cache; audio_cache = 0; // delete the cache after the assets
349 delete video_cache; video_cache = 0; // delete the cache after the assets
350 delete frame_cache; frame_cache = 0;
351 delete wave_cache; wave_cache = 0;
352 delete plugin_guis; plugin_guis = 0;
353 delete dead_plugins; dead_plugins = 0;
354 delete keyframe_threads; keyframe_threads = 0;
355 delete undo; undo = 0;
356 delete preferences; preferences = 0;
357 delete exportedl; exportedl = 0;
358 delete session; session = 0;
359 delete defaults; defaults = 0;
360 delete assets; assets = 0;
361 delete splash_window; splash_window = 0;
362 if( !edl->Garbage::remove_user() ) edl = 0;
363 delete channeldb_buz;
364 delete channeldb_v4l2jpeg;
365 // This must be last thread to exit
366 delete playback_3d; playback_3d = 0;
367 delete dead_plugin_lock;
368 delete plugin_gui_lock;
369 delete vwindows_lock;
370 delete zwindows_lock;
372 delete keyframe_gui_lock;
373 colormodels.remove_all_objects();
374 interlace_project_modes.remove_all_objects();
375 interlace_asset_modes.remove_all_objects();
376 sighandler->terminate();
387 void MWindow::init_error()
389 MainError::init_error(this);
392 void MWindow::finit_error()
394 MainError::finit_error();
397 void MWindow::create_defaults_path(char *string, const char *config_file)
399 // set the .bcast path
402 sprintf(string, "%s/", File::get_config_path());
403 fs.complete_path(string);
404 if(!fs.is_dir(string))
405 fs.create_dir(string);
408 strcat(string, config_file);
410 const char *MWindow::default_std()
412 char buf[BCTEXTLEN], *p = 0;
414 int fd = open(TIMEZONE_NAME, O_RDONLY);
416 int l = read(fd, buf, sizeof(buf)-1);
419 if( buf[l-1] == '\n' ) --l;
425 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
428 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
429 p += strlen(ZONEINFO_STR);
434 for( int i=0; ntsc_zones[i]; ++i ) {
435 if( !strcmp(ntsc_zones[i], p) )
442 for( int i=0; ntsc_zones[i]; ++i ) {
443 if( !strcmp(ntsc_zones[i], p) )
448 // cin_timezone: Seconds west of UTC. 240sec/deg
449 double tz_deg = -cin_timezone / 240.;
450 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
451 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
454 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
456 struct formatpresets *fpr;
458 for(fpr = &format_presets[0]; fpr->name; fpr++)
460 if(strcmp(_(fpr->name), preset) == 0)
462 session->audio_channels = fpr->audio_channels;
463 session->audio_tracks = fpr->audio_tracks;
464 session->sample_rate = fpr->sample_rate;
465 session->video_channels = fpr->video_channels;
466 session->video_tracks = fpr->video_tracks;
467 session->frame_rate = fpr->frame_rate;
468 session->output_w = fpr->output_w;
469 session->output_h = fpr->output_h;
470 session->aspect_w = fpr->aspect_w;
471 session->aspect_h = fpr->aspect_h;
472 session->interlace_mode = fpr->interlace_mode;
473 session->color_model = fpr->color_model;
479 const char *MWindow::get_preset_name(int index)
481 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
483 return _(format_presets[index].name);
487 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
489 char path[BCTEXTLEN];
490 // Use user supplied path
492 strcpy(path, config_path);
494 create_defaults_path(path, CONFIG_FILE);
497 defaults = new BC_Hash(path);
502 void MWindow::check_language()
504 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
505 const char *env_lang = getenv("LANGUAGE");
506 if( !env_lang ) env_lang = getenv("LC_ALL");
507 if( !env_lang ) env_lang = getenv("LANG");
509 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
510 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
511 env_lang = curr_lang;
513 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
514 defaults->get("LAST_LANG",last_lang);
515 if( strcmp(env_lang,last_lang)) {
516 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
517 defaults->update("LAST_LANG",env_lang);
518 char plugin_path[BCTEXTLEN];
519 create_defaults_path(plugin_path, PLUGIN_FILE);
520 ::remove(plugin_path);
521 char ladspa_path[BCTEXTLEN];
522 create_defaults_path(ladspa_path, LADSPA_FILE);
523 ::remove(ladspa_path);
526 if( strlen(env_lang) > 1 &&
527 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
528 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
531 strcpy(cin_lang, "en");
534 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
536 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
538 const char *dp = plug_dir;
539 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
540 bp = !*dp && *bp == '/' ? bp+1 : base_path;
546 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir)
550 fseek(fp, 0, SEEK_SET);
552 char index_line[BCTEXTLEN];
553 int index_version = -1, len = strlen(plugin_dir);
554 if( !fgets(index_line, BCTEXTLEN, fp) ||
555 sscanf(index_line, "%d", &index_version) != 1 ||
556 index_version != PLUGIN_FILE_VERSION ||
557 !fgets(index_line, BCTEXTLEN, fp) ||
558 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
559 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
561 ArrayList<PluginServer*> plugins;
562 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
563 if( index_line[0] == ';' ) continue;
564 if( index_line[0] == '#' ) continue;
565 int type = PLUGIN_TYPE_UNKNOWN;
566 char path[BCTEXTLEN], title[BCTEXTLEN];
568 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
571 PluginServer *server = 0;
573 case PLUGIN_TYPE_BUILTIN:
574 case PLUGIN_TYPE_EXECUTABLE:
575 case PLUGIN_TYPE_LADSPA: {
576 char plugin_path[BCTEXTLEN]; struct stat st;
577 sprintf(plugin_path, "%s/%s", plugin_dir, path);
578 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
581 server = new PluginServer(mwindow, plugin_path, type);
583 case PLUGIN_TYPE_FFMPEG: {
584 server = new_ffmpeg_server(mwindow, path);
586 case PLUGIN_TYPE_LV2: {
587 server = new_lv2_server(mwindow, path);
590 if( !server ) continue;
591 plugins.append(server);
592 // Create plugin server from index entry
593 server->set_title(title);
594 if( server->read_table(index_line) ) {
600 ret = check_plugin_index(plugins, plugin_dir, ".");
603 add_plugins(plugins);
605 plugins.remove_all_objects();
610 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
611 const char *plug_dir, const char *plug_path)
613 char plugin_path[BCTEXTLEN];
614 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
616 fs.set_filter( "[*.plugin][*.so]" );
617 if( fs.update(plugin_path) )
620 for( int i=0; i<fs.dir_list.total; ++i ) {
621 char fs_path[BCTEXTLEN];
622 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
623 if( fs.is_dir(fs_path) ) {
624 get_plugin_path(plugin_path, plug_dir, fs_path);
625 if( check_plugin_index(plugins, plug_dir, plugin_path) )
628 else if( !plugin_exists(fs_path, plugins) )
635 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
638 plugindb = new ArrayList<PluginServer*>;
640 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
641 create_defaults_path(index_path, PLUGIN_FILE);
642 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
643 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
644 FILE *fp = fopen(index_path,"a+");
646 fprintf(stderr,_("MWindow::init_plugins: "
647 "can't open plugin index: %s\n"), index_path);
650 int fd = fileno(fp), ret = -1;
651 if( !flock(fd, LOCK_EX) ) {
652 fseek(fp, 0, SEEK_SET);
653 ret = load_plugin_index(mwindow, fp, plugin_path);
657 fseek(fp, 0, SEEK_SET);
658 printf("init plugin index: %s\n", plugin_path);
659 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
660 fprintf(fp, "%s\n", plugin_path);
661 init_plugin_index(mwindow, preferences, fp, plugin_path);
662 init_ffmpeg_index(mwindow, preferences, fp);
663 init_lv2_index(mwindow, preferences, fp);
664 fseek(fp, 0, SEEK_SET);
665 ret = load_plugin_index(mwindow, fp, plugin_path);
668 fprintf(stderr,_("MWindow::init_plugins: "
669 "can't %s plugin index: %s\n"),
670 ret>0 ? _("create") : _("lock"), index_path);
676 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
678 char *path = getenv("LADSPA_PATH");
679 char ladspa_path[BCTEXTLEN];
681 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
684 for( int len=0; *path; path+=len ) {
685 char *cp = strchr(path,':');
686 len = !cp ? strlen(path) : cp-path;
687 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
688 memcpy(plugin_path, path, len); plugin_path[len] = 0;
690 char *plugin_dir = FileSystem::basepath(plugin_path);
691 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
692 create_defaults_path(index_path, LADSPA_FILE);
693 cp = index_path + strlen(index_path);
694 for( char *bp=plugin_path; *bp!=0; ++bp )
695 *cp++ = *bp=='/' ? '_' : *bp;
697 FILE *fp = fopen(index_path,"a+");
699 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
700 "can't open ladspa plugin index: %s\n"), index_path);
703 int fd = fileno(fp), ret = -1;
704 if( !flock(fd, LOCK_EX) ) {
705 fseek(fp, 0, SEEK_SET);
706 ret = load_plugin_index(mwindow, fp, plugin_path);
710 fseek(fp, 0, SEEK_SET);
711 init_ladspa_index(mwindow, preferences, fp, plugin_path);
712 fseek(fp, 0, SEEK_SET);
713 ret = load_plugin_index(mwindow, fp, plugin_path);
716 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
717 "can't %s ladspa plugin index: %s\n"),
718 ret>0 ? _("create") : _("lock"), index_path);
725 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
726 FILE *fp, const char *plugin_dir)
728 int idx = PLUGIN_IDS;
730 for( int i=0; i<plugindb->size(); ++i ) {
731 PluginServer *server = plugindb->get(i);
732 if( server->dir_idx >= idx )
733 idx = server->dir_idx+1;
736 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
739 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
740 const char *plug_dir, const char *plug_path, int &idx)
742 char plugin_path[BCTEXTLEN];
743 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
745 fs.set_filter( "[*.plugin][*.so]" );
746 int result = fs.update(plugin_path);
747 if( result || !fs.dir_list.total ) return;
750 for( int i=0; i<fs.dir_list.total; ++i ) {
751 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
752 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
753 get_plugin_path(path, plug_dir, fs_path);
754 if( fs.is_dir(fs_path) ) {
755 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
758 if( plugin_exists(path) ) continue;
760 if( stat(fs_path, &st) ) continue;
761 int64_t mtime = st.st_mtime;
762 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
763 result = server.open_plugin(1, preferences, 0, 0);
765 server.write_table(fp, path, vis_id, mtime);
766 server.close_plugin();
768 else if( result == PLUGINSERVER_IS_LAD ) {
771 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
772 ladspa.set_lad_index(lad_index++);
773 result = ladspa.open_plugin(1, preferences, 0, 0);
775 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
776 ladspa.close_plugin();
782 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
784 for( int i=0; i<plugins.size(); ++i )
785 plugindb->append(plugins[i]);
786 plugins.remove_all();
789 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
791 const char *dat_path = File::get_cindat_path();
792 char msg_path[BCTEXTLEN];
794 if( BC_Resources::language[0] ) {
795 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
797 fp = fopen(msg_path, "r");
800 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
802 fp = fopen(msg_path, "r");
805 char text[BCTEXTLEN];
806 char *tp = text, *ep = tp + sizeof(text)-1;
807 char title[BCTEXTLEN];
812 char line[BCTEXTLEN], *cp = line;
813 if( fgets(line,sizeof(line)-1,fp) ) {
814 if( *cp == '#' ) continue;
815 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
818 if( tp > text && *--tp == '\n' ) *tp = 0;
820 int idx = plugins.size();
821 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
823 delete [] plugins[idx]->tip;
824 plugins[idx]->tip = cstrdup(text);
828 if( done > 0 ) break;
830 char *dp = strchr(cp, ':');
832 printf("plugin tips: error on line %d\n", no);
836 while( cp < dp ) *bp++ = *cp++;
841 while( *cp == ' ' || *cp == '\t' ) ++cp;
842 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
847 void MWindow::delete_plugins()
849 plugindb->remove_all_objects();
854 void MWindow::search_plugindb(int do_audio,
859 ArrayList<PluginServer*> &results)
862 for(int i = 0; i < MWindow::plugindb->total; i++)
864 PluginServer *current = MWindow::plugindb->get(i);
866 if(current->audio == do_audio &&
867 current->video == do_video &&
868 (current->realtime == is_realtime || is_realtime < 0) &&
869 current->transition == is_transition &&
870 current->theme == is_theme)
871 results.append(current);
874 // Alphabetize list by title
880 for(int i = 0; i < results.total - 1; i++)
882 PluginServer *value1 = results[i];
883 PluginServer *value2 = results[i + 1];
884 if(strcmp(_(value1->title), _(value2->title)) > 0)
888 results[i + 1] = value1;
894 PluginServer* MWindow::scan_plugindb(char *title,
899 // printf("MWindow::scan_plugindb data_type < 0\n");
903 for(int i = 0; i < plugindb->total; i++)
905 PluginServer *server = plugindb->get(i);
907 !strcasecmp(server->title, title) &&
909 (data_type == TRACK_AUDIO && server->audio) ||
910 (data_type == TRACK_VIDEO && server->video)))
911 return plugindb->get(i);
916 // repair session files with xlated plugin titles
917 void MWindow::fix_plugin_title(char *title)
919 for(int i = 0; i < plugindb->total; i++) {
920 PluginServer *server = plugindb->get(i);
921 if( !server->title ) continue;
922 const char *server_title = server->title;
923 if( !bstrcasecmp(title, _(server_title)) ) {
924 strcpy(title, server_title);
930 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
932 for( int i=0; i<plugins.size(); ++i )
933 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
937 int MWindow::plugin_exists(char *plugin_path)
939 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
942 void MWindow::remove_plugin_index()
944 char index_path[BCTEXTLEN];
945 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
946 ::remove(index_path);
949 void MWindow::init_preferences()
951 preferences = new Preferences;
952 preferences->load_defaults(defaults);
953 File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
954 session = new MainSession(this);
955 session->load_defaults(defaults);
956 // set x11_host, screens, window_config
957 screens = session->set_default_x11_host();
958 BC_Signals::set_trap_hook(trap_hook, this);
959 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
960 BC_Signals::set_catch_intr(preferences->trap_sigintr);
961 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
962 BC_Trace::enable_locks();
965 BC_Trace::disable_locks();
967 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
968 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
969 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
970 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
973 void MWindow::clean_indexes()
978 int oldest_item = -1;
980 char string[BCTEXTLEN];
981 char string2[BCTEXTLEN];
983 // Delete extra indexes
984 fs.set_filter("*.idx");
985 fs.complete_path(preferences->index_directory);
986 fs.update(preferences->index_directory);
987 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
989 // Eliminate directories
994 for(int i = 0; i < fs.dir_list.total && !result; i++)
996 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
997 if(fs.is_dir(string))
999 delete fs.dir_list[i];
1000 fs.dir_list.remove_number(i);
1005 total_excess = fs.dir_list.total - preferences->index_count;
1007 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
1008 while(total_excess > 0)
1011 for(int i = 0; i < fs.dir_list.total; i++)
1013 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1015 if(i == 0 || fs.get_date(string) <= oldest)
1017 oldest = fs.get_date(string);
1022 if(oldest_item >= 0)
1024 // Remove index file
1025 fs.join_names(string,
1026 preferences->index_directory,
1027 fs.dir_list[oldest_item]->name);
1028 //printf("MWindow::clean_indexes 1 %s\n", string);
1030 perror("delete_indexes");
1031 delete fs.dir_list[oldest_item];
1032 fs.dir_list.remove_number(oldest_item);
1034 // Remove table of contents if it exists
1035 strcpy(string2, string);
1036 char *ptr = strrchr(string2, '.');
1039 //printf("MWindow::clean_indexes 2 %s\n", string2);
1040 sprintf(ptr, ".toc");
1042 sprintf(ptr, ".mkr");
1051 void MWindow::init_awindow()
1053 awindow = new AWindow(this);
1054 awindow->create_objects();
1057 void MWindow::init_gwindow()
1059 gwindow = new GWindow(this);
1060 gwindow->create_objects();
1063 void MWindow::init_tipwindow()
1065 TipWindow::load_tips(cin_lang);
1067 twindow = new TipWindow(this);
1071 void MWindow::show_warning(int *do_warning, const char *text)
1073 if( do_warning && !*do_warning ) return;
1075 wwindow = new WWindow(this);
1076 wwindow->show_warning(do_warning, text);
1079 int MWindow::wait_warning()
1081 return wwindow->wait_result();
1084 void MWindow::init_theme()
1089 PluginServer *theme_plugin = 0;
1090 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1091 if( plugindb->get(i)->theme &&
1092 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1093 theme_plugin = plugindb->get(i);
1097 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1098 preferences->theme);
1100 const char *default_theme = DEFAULT_THEME;
1101 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1102 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1104 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1105 if( plugindb->get(i)->theme &&
1106 !strcasecmp(default_theme, plugindb->get(i)->title) )
1107 theme_plugin = plugindb->get(i);
1112 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1116 PluginServer *plugin = new PluginServer(*theme_plugin);
1117 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1118 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1119 theme_plugin->title);
1123 theme = plugin->new_theme();
1124 theme->mwindow = this;
1125 strcpy(theme->path, plugin->path);
1128 // Load default images & settings
1129 theme->Theme::initialize();
1130 // Load user images & settings
1131 theme->initialize();
1132 // Create menus with user colors
1133 theme->build_menus();
1136 theme->sort_image_sets();
1137 theme->check_used();
1138 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1141 void MWindow::init_3d()
1143 playback_3d = new Playback3D(this);
1144 playback_3d->create_objects();
1147 void MWindow::init_edl()
1150 edl->create_objects();
1151 fill_preset_defaults(default_standard, edl->session);
1152 edl->load_defaults(defaults);
1153 edl->session->brender_start = edl->session->brender_end = 0;
1154 edl->create_default_tracks();
1155 edl->tracks->update_y_pixels(theme);
1158 void MWindow::init_compositor()
1160 cwindow = new CWindow(this);
1161 cwindow->create_objects();
1164 void MWindow::init_levelwindow()
1166 lwindow = new LevelWindow(this);
1167 lwindow->create_objects();
1170 VWindow *MWindow::get_viewer(int start_it, int idx)
1172 vwindows_lock->lock("MWindow::get_viewer");
1173 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1174 if( !vwindow ) idx = vwindows.size();
1175 while( !vwindow && --idx >= 0 ) {
1176 VWindow *vwin = vwindows[idx];
1177 if( !vwin->is_running() || !vwin->get_edl() )
1181 vwindow = new VWindow(this);
1182 vwindow->load_defaults();
1183 vwindow->create_objects();
1184 vwindows.append(vwindow);
1186 vwindows_lock->unlock();
1187 if( start_it ) vwindow->start();
1191 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1193 zwindows_lock->lock("MWindow::get_mixer");
1194 if( !mixer ) mixer = edl->mixers.new_mixer();
1195 ZWindow *zwindow = 0;
1196 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1197 ZWindow *zwdw = zwindows[i];
1198 if( zwdw->running() ) continue;
1199 if( zwdw->idx >= 0 ) continue;
1200 zwindow = zwindows[i];
1203 zwindows.append(zwindow = new ZWindow(this));
1204 zwindow->idx = mixer->idx;
1205 zwindows_lock->unlock();
1209 void MWindow::del_mixer(ZWindow *zwindow)
1211 zwindows_lock->lock("MWindow::del_mixer 0");
1212 edl->mixers.del_mixer(zwindow->idx);
1213 if( session->selected_zwindow >= 0 ) {
1214 int i = zwindows.number_of(zwindow);
1215 if( i >= 0 && i < session->selected_zwindow )
1216 --session->selected_zwindow;
1217 else if( i == session->selected_zwindow )
1218 session->selected_zwindow = -1;
1220 zwindows_lock->unlock();
1221 gui->lock_window("MWindow::del_mixer 1");
1222 gui->update_mixers(0, -1);
1223 gui->unlock_window();
1226 void MWindow::start_mixer()
1229 ZWindow *zwindow = get_mixer(mixer);
1230 const char *title = 0;
1232 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1233 PatchGUI *patchgui = get_patchgui(track);
1234 if( !patchgui || !patchgui->mixer ) continue;
1235 mixer->mixer_ids.append(track->get_mixer_id());
1236 if( !title ) title = track->title;
1239 session->selected_zwindow = -1;
1240 gui->lock_window("MWindow::start_mixer");
1241 gui->update_mixers(0, 0);
1242 gui->unlock_window();
1244 zwindow->set_title(title);
1249 int MWindow::mixer_track_active(Track *track)
1251 int i = session->selected_zwindow;
1252 if( i < 0 || i >= zwindows.size() ) return 0;
1253 ZWindow *zwindow = zwindows[i];
1254 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1255 if( !mixer ) return 0;
1256 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1257 return n >= 0 ? 1 : 0;
1260 void MWindow::update_mixer_tracks()
1262 zwindows_lock->lock("MixPatch::handle_event");
1263 int i = session->selected_zwindow;
1264 if( i >= 0 && i < zwindows.size() ) {
1265 ZWindow *zwindow = zwindows[i];
1266 zwindow->update_mixer_ids();
1268 zwindows_lock->unlock();
1271 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1272 int use_inout, int toggle_audio, int loop_play, float speed)
1274 zwindows_lock->lock("MWindow::handle_mixers");
1275 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1276 ZWindow *zwindow = zwindows[vidx];
1277 if( zwindow->idx < 0 ) continue;
1278 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1279 if( !mixer || !mixer->mixer_ids.size() ) continue;
1281 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1282 if( track->data_type != TRACK_VIDEO ) continue;
1283 int mixer_id = track->get_mixer_id();
1284 k = mixer->mixer_ids.size();
1285 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1287 if( k < 0 ) continue;
1288 EDL *mixer_edl = new EDL(this->edl);
1289 mixer_edl->create_objects();
1290 mixer_edl->copy_all(edl);
1291 mixer_edl->remove_vwindow_edls();
1292 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1293 k = mixer->mixer_ids.size();
1294 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1297 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1300 track->record = track->play = 0;
1302 zwindow->change_source(mixer_edl);
1303 zwindow->handle_mixer(command, 0,
1304 use_inout, toggle_audio, loop_play, speed);
1306 zwindows_lock->unlock();
1309 void MWindow::refresh_mixers(int dir)
1311 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1312 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1315 void MWindow::stop_mixers()
1317 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1318 ZWindow *zwindow = zwindows[vidx];
1319 if( zwindow->idx < 0 ) continue;
1320 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1324 void MWindow::close_mixers(int result)
1326 ArrayList<ZWindow*> closed;
1327 zwindows_lock->lock("MWindow::close_mixers");
1328 for( int i=zwindows.size(); --i>=0; ) {
1329 ZWindow *zwindow = zwindows[i];
1330 if( zwindow->idx < 0 ) continue;
1332 ZWindowGUI *zgui = zwindow->zgui;
1333 zgui->lock_window("MWindow::select_zwindow 0");
1334 zgui->set_done(result);
1335 zgui->unlock_window();
1336 closed.append(zwindow);
1338 zwindows_lock->unlock();
1339 for( int i=0; i<closed.size(); ++i ) {
1340 ZWindow *zwindow = closed[i];
1345 ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
1347 ArrayList<Indexable*> new_assets;
1348 new_assets.append(indexable);
1349 Track *track = edl->tracks->last;
1350 load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
1351 track = !track ? edl->tracks->first : track->next;
1353 ZWindow *zwindow = get_mixer(mixer);
1355 track->play = track->record = 0;
1356 if( track->data_type == TRACK_VIDEO ) {
1357 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1359 mixer->mixer_ids.append(track->get_mixer_id());
1360 track = track->next;
1362 if( indexable->is_asset ) {
1363 char *path = indexable->path;
1364 char *tp = strrchr(path, '/');
1365 if( !tp ) tp = path; else ++tp;
1366 zwindow->set_title(tp);
1369 char *title = ((EDL*)indexable)->local_session->clip_title;
1370 zwindow->set_title(title);
1375 void MWindow::create_mixers(double position)
1377 if( !session->drag_assets->size() &&
1378 !session->drag_clips->size() ) return;
1382 ArrayList<ZWindow *>new_mixers;
1384 for( int i=0; i<session->drag_assets->size(); ++i ) {
1385 Indexable *indexable = session->drag_assets->get(i);
1386 if( !indexable->have_video() ) continue;
1387 ZWindow *zwindow = create_mixer(indexable, position);
1388 new_mixers.append(zwindow);
1390 for( int i=0; i<session->drag_clips->size(); ++i ) {
1391 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1392 if( !indexable->have_video() ) continue;
1393 ZWindow *zwindow = create_mixer(indexable, position);
1394 new_mixers.append(zwindow);
1398 for( int i=0; i<new_mixers.size(); ++i )
1399 new_mixers[i]->start();
1403 undo_after(_("create mixers"), LOAD_ALL);
1405 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1406 sync_parameters(CHANGE_ALL);
1409 void MWindow::open_mixers()
1411 for( int i=0; i<edl->mixers.size(); ++i ) {
1412 Mixer *mixer = edl->mixers[i];
1413 ZWindow *zwindow = get_mixer(mixer);
1414 zwindow->set_title(mixer->title);
1420 int MWindow::select_zwindow(ZWindow *zwindow)
1422 int ret = 0, n = zwindows.number_of(zwindow);
1423 if( session->selected_zwindow != n ) {
1424 session->selected_zwindow = n;
1425 for( int i=0; i<zwindows.size(); ++i ) {
1426 ZWindow *zwindow = zwindows[i];
1427 if( zwindow->idx < 0 ) continue;
1428 ZWindowGUI *zgui = zwindow->zgui;
1429 zgui->lock_window("MWindow::select_zwindow 0");
1430 zwindow->highlighted = i == n ? 1 : 0;
1431 if( zgui->draw_overlays() )
1432 zgui->canvas->get_canvas()->flash(1);
1433 zgui->unlock_window();
1436 gui->lock_window("MWindow::select_window 1");
1437 gui->update_mixers(0, -1);
1438 gui->unlock_window();
1443 void MWindow::tile_mixers()
1446 for( int i=0; i<zwindows.size(); ++i ) {
1447 ZWindow *zwindow = zwindows[i];
1448 if( zwindow->idx < 0 ) continue;
1452 int zn = ceil(sqrt(nz));
1453 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1454 int y1 = 1, y2 = gui->get_y();
1455 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1456 if( x1 < 0 ) x1 = 0;
1457 if( y1 < 0 ) y1 = 0;
1458 if( x2 > rw ) x2 = rw;
1459 if( y2 > rh ) y2 = rh;
1460 int dx = x2 - x1, dy = y2 - y1;
1462 int lt = BC_DisplayInfo::get_left_border();
1463 int top = BC_DisplayInfo::get_top_border();
1464 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1465 int bh = top + BC_DisplayInfo::get_bottom_border();
1466 int zx = 0, zy = 0; // window origins
1467 int mw = xS(10+10), mh = yS(10+10); // canvas margins
1468 int rsz = 0, n = 0, dz = 0;
1469 int ow = edl->session->output_w, oh = edl->session->output_h;
1470 for( int i=0; i<zwindows.size(); ++i ) {
1471 ZWindow *zwindow = zwindows[i];
1472 if( zwindow->idx < 0 ) continue;
1473 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1474 if( rsz < hh ) rsz = hh;
1475 int xx = zx + x1, yy = zy + y1;
1476 int mx = x2 - zw, my = y2 - zh;
1477 if( xx > mx ) xx = mx;
1478 if( yy > my ) yy = my;
1479 xx += lt + xS(dz); yy += top + yS(dz);
1480 zwindow->reposition(xx,yy, ww,hh);
1481 if( zwindow->running() ) {
1482 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1483 gui->lock_window("MWindow::tile_mixers");
1484 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1485 gui->unlock_window();
1489 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1498 void MWindow::init_cache()
1500 audio_cache = new CICache(preferences);
1501 video_cache = new CICache(preferences);
1502 frame_cache = new FrameCache;
1503 wave_cache = new WaveCache;
1506 void MWindow::init_channeldb()
1508 channeldb_buz->load("channeldb_buz");
1509 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1512 void MWindow::init_menus()
1514 char string[BCTEXTLEN];
1517 BC_CModels::to_text(string, BC_RGB888);
1518 colormodels.append(new ColormodelItem(string, BC_RGB888));
1519 BC_CModels::to_text(string, BC_RGBA8888);
1520 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1521 // BC_CModels::to_text(string, BC_RGB161616);
1522 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1523 // BC_CModels::to_text(string, BC_RGBA16161616);
1524 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1525 BC_CModels::to_text(string, BC_RGB_FLOAT);
1526 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1527 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1528 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1529 BC_CModels::to_text(string, BC_YUV888);
1530 colormodels.append(new ColormodelItem(string, BC_YUV888));
1531 BC_CModels::to_text(string, BC_YUVA8888);
1532 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1533 // BC_CModels::to_text(string, BC_YUV161616);
1534 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1535 // BC_CModels::to_text(string, BC_YUVA16161616);
1536 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1538 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1539 interlace_project_modes.append(new InterlacemodeItem(string, x));
1541 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1542 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1544 // Interlacing Modes
1545 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1547 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1548 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1550 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1551 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1553 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1554 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1556 mixers_align = new MixersAlign(this);
1559 void MWindow::init_indexes()
1561 mainindexes = new MainIndexes(this);
1562 mainindexes->start_loop();
1565 void MWindow::init_gui()
1567 gui = new MWindowGUI(this);
1568 gui->create_objects();
1569 gui->load_defaults(defaults);
1572 void MWindow::init_signals()
1574 sighandler = new SigHandler;
1575 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1579 void MWindow::init_render()
1581 render = new Render(this);
1582 create_bd = new CreateBD_Thread(this);
1583 create_dvd = new CreateDVD_Thread(this);
1584 batch_render = new BatchRenderThread(this);
1587 void MWindow::init_exportedl()
1589 exportedl = new ExportEDL(this);
1593 void MWindow::init_shuttle()
1596 int ret = Shuttle::probe();
1598 shuttle = new Shuttle(this);
1599 if( shuttle->read_config_file() > 0 ) {
1600 printf("shuttle: bad config file\n");
1601 delete shuttle; shuttle = 0;
1604 shuttle->start(ret);
1608 void MWindow::init_wintv()
1611 wintv = WinTV::probe(this);
1616 void MWindow::init_x10tv()
1619 x10tv = X10TV::probe(this);
1626 void MWindow::init_brender()
1628 if(preferences->use_brender && !brender)
1630 brender_lock->lock("MWindow::init_brender 1");
1631 brender = new BRender(this);
1632 brender->initialize();
1633 session->brender_end = 0;
1634 brender_lock->unlock();
1637 if(!preferences->use_brender && brender)
1639 brender_lock->lock("MWindow::init_brender 2");
1642 session->brender_end = 0;
1643 brender_lock->unlock();
1649 void MWindow::restart_brender()
1651 //printf("MWindow::restart_brender 1\n");
1652 if( !brender_active || !preferences->use_brender ) return;
1653 if( !brender ) return;
1654 brender->restart(edl);
1657 void MWindow::stop_brender()
1659 if( !brender ) return;
1660 // cannot be holding mwindow->gui display lock
1664 int MWindow::brender_available(int position)
1667 brender_lock->lock("MWindow::brender_available 1");
1668 if(brender && brender_active)
1670 if(brender->map_valid)
1672 brender->map_lock->lock("MWindow::brender_available 2");
1673 if(position < brender->map_size &&
1676 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1677 if(brender->map[position] == BRender::RENDERED)
1680 brender->map_lock->unlock();
1683 brender_lock->unlock();
1687 void MWindow::set_brender_active(int v, int update)
1689 if( !preferences->use_brender ) v = 0;
1691 gui->mainmenu->brender_active->set_checked(v);
1693 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1694 edl->session->brender_end = edl->local_session->get_selectionend(1);
1696 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1697 edl->session->brender_end = edl->tracks->total_video_length();
1702 edl->session->brender_start = edl->session->brender_end = 0;
1703 gui->unlock_window();
1705 gui->lock_window("MWindow::set_brender_active");
1708 gui->update_timebar(0);
1709 gui->draw_overlays(1);
1713 int MWindow::has_commercials()
1715 #ifdef HAVE_COMMERCIAL
1716 return theme->use_commercials;
1722 void MWindow::init_commercials()
1724 #ifdef HAVE_COMMERCIAL
1725 if( !commercials ) {
1726 commercials = new Commercials(this);
1727 commercial_active = 0;
1730 commercials->add_user();
1734 void MWindow::commit_commercial()
1736 #ifdef HAVE_COMMERCIAL
1737 if( !commercial_active ) return;
1738 commercial_active = 0;
1739 if( !commercials ) return;
1740 commercials->commitDb();
1744 void MWindow::undo_commercial()
1746 #ifdef HAVE_COMMERCIAL
1747 if( !commercial_active ) return;
1748 commercial_active = 0;
1749 if( !commercials ) return;
1750 commercials->undoDb();
1754 int MWindow::put_commercial()
1757 #ifdef HAVE_COMMERCIAL
1758 double start = edl->local_session->get_selectionstart();
1759 double end = edl->local_session->get_selectionend();
1760 if( start >= end ) return 0;
1762 const char *errmsg = 0;
1764 Tracks *tracks = edl->tracks;
1766 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1767 if( track->data_type != TRACK_VIDEO ) continue;
1768 if( !track->record ) continue;
1769 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1771 int64_t units_start = track->to_units(start,0);
1772 int64_t units_end = track->to_units(end,0);
1773 Edits *edits = track->edits;
1774 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1775 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1776 if(!edit1 && !edit2) continue; // nothing selected
1777 if(!edit2) { // edit2 beyond end of track
1778 edit2 = edits->last;
1779 units_end = edits->length();
1781 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1782 Indexable *indexable = edit1->get_source();
1783 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1786 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1787 if( track->data_type != TRACK_VIDEO ) continue;
1788 if( !track->record ) continue;
1789 int64_t units_start = track->to_units(start,0);
1790 int64_t units_end = track->to_units(end,0);
1791 Edits *edits = track->edits;
1792 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1793 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1794 if(!edit1 && !edit2) continue; // nothing selected
1795 if(!edit2) { // edit2 beyond end of track
1796 edit2 = edits->last;
1797 units_end = edits->length();
1799 Indexable *indexable = edit1->get_source();
1800 Asset *asset = (Asset *)indexable;
1801 File *file = video_cache->check_out(asset, edl);
1802 if( !file ) { errmsg = _("no file"); break; }
1803 int64_t edit_length = units_end - units_start;
1804 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1805 result = commercials->put_clip(file, edit1->channel,
1806 track->from_units(edit_start), track->from_units(edit_length));
1807 video_cache->check_in(asset);
1808 if( result ) { errmsg = _("db failed"); break; }
1811 char string[BCTEXTLEN];
1812 sprintf(string, _("put_commercial: %s"), errmsg);
1813 MainError::show_error(string);
1821 void MWindow::stop_playback(int wait)
1823 gui->stop_drawing();
1825 cwindow->stop_playback(wait);
1827 for(int i = 0; i < vwindows.size(); i++) {
1828 VWindow *vwindow = vwindows[i];
1829 if( !vwindow->is_running() ) continue;
1830 vwindow->stop_playback(wait);
1832 for(int i = 0; i < zwindows.size(); i++) {
1833 ZWindow *zwindow = zwindows[i];
1834 if( zwindow->idx < 0 ) continue;
1835 zwindow->stop_playback(wait);
1839 void MWindow::stop_transport()
1841 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1844 void MWindow::undo_before(const char *description, void *creator)
1846 undo->update_undo_before(description, creator);
1849 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
1851 undo->update_undo_after(description, load_flags, changes_made);
1854 void MWindow::beep(double freq, double secs, double gain)
1856 if( !beeper ) beeper = new Beeper(this);
1857 beeper->tone(freq, secs, gain);
1860 Beeper::Beeper(MWindow *mwindow)
1863 this->mwindow = mwindow;
1864 audio = new AudioDevice(mwindow);
1878 int64_t bfrsz = BEEP_SAMPLE_RATE;
1879 EDL *edl = mwindow->edl;
1880 EDLSession *session = edl->session;
1881 AudioOutConfig *aconfig = session->playback_config->aconfig;
1882 audio->open_output(aconfig, BEEP_SAMPLE_RATE, bfrsz, channels, 0);
1883 audio->start_playback();
1885 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
1886 const double two_pi = 2*M_PI;
1887 int64_t audio_len = BEEP_SAMPLE_RATE * secs;
1888 const double dt = two_pi * freq/BEEP_SAMPLE_RATE;
1893 while( !interrupted ) {
1894 int len = audio_len - audio_pos;
1895 if( len <= 0 ) break;
1896 if( len > bfrsz ) len = bfrsz;
1898 for( int i=0; i<len; ++i,++k,th+=dt ) {
1899 double t = th - two_pi;
1900 if( t >= 0 ) th = t;
1901 out0[i] = out1[i] = sin(th) * gain;
1903 audio->write_buffer(out, channels, len);
1908 audio->set_last_buffer();
1909 audio->stop_audio(interrupted ? 0 : 1);
1915 void Beeper::start()
1917 if( running() ) return;
1923 void Beeper::stop(int wait)
1925 if( running() && !interrupted ) {
1927 audio->stop_audio(wait);
1932 void Beeper::tone(double freq, double secs, double gain)
1942 int MWindow::load_filenames(ArrayList<char*> *filenames,
1943 int load_mode, int edl_mode, int update_filename)
1945 ArrayList<EDL*> new_edls;
1946 ArrayList<Asset*> new_assets;
1947 ArrayList<File*> new_files;
1950 gui->start_hourglass();
1952 // Need to stop playback since tracking depends on the EDL not getting
1954 gui->unlock_window();
1956 gui->lock_window("MWindow::load_filenames 0");
1959 const int debug = 0;
1960 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1962 // Define new_edls and new_assets to load
1963 int result = 0, ftype = -1;
1965 for( int i=0; i<filenames->size(); ++i ) {
1967 File *new_file = new File;
1968 Asset *new_asset = new Asset(filenames->get(i));
1969 EDL *new_edl = new EDL;
1970 new_edl->create_objects();
1971 new_edl->copy_session(edl, -1);
1972 new_file->set_program(edl->session->program_no);
1974 char string[BCTEXTLEN];
1975 sprintf(string, _("Loading %s"), new_asset->path);
1976 gui->show_message(string);
1978 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1982 // Convert media file to EDL
1984 // Warn about odd image dimensions
1985 if( new_asset->video_data &&
1986 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1987 eprintf(_("%s's resolution is %dx%d.\n"
1988 "Images with odd dimensions may not decode properly."),
1989 new_asset->path, new_asset->width, new_asset->height);
1992 if( new_asset->program >= 0 &&
1993 edl->session->program_no != new_asset->program ) {
1994 eprintf(_("%s's index was built for program number %d\n"
1995 "Playback preference is %d.\n Using program %d."),
1996 new_asset->path, new_asset->program,
1997 edl->session->program_no, new_asset->program);
2000 if( load_mode == LOADMODE_RESOURCESONLY ) {
2001 new_assets.append(new_asset);
2002 new_asset->add_user();
2007 RecordLabels *labels = edl->session->label_cells ?
2008 new RecordLabels(new_file) : 0;
2009 asset_to_edl(new_edl, new_asset, labels);
2010 new_edls.append(new_edl);
2011 new_edl->add_user();
2014 if( load_mode == LOADMODE_REPLACE ||
2015 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2016 // Set filename to nothing for assets since save EDL would overwrite them.
2018 // Reset timeline position
2019 for( int i=0; i<TOTAL_PANES; ++i ) {
2020 new_edl->local_session->view_start[i] = 0;
2021 new_edl->local_session->track_start[i] = 0;
2027 case FILE_NOT_FOUND: {
2028 eprintf(_("Failed to open %s"), new_asset->path);
2029 sprintf(string, _("Failed to open %s"), new_asset->path);
2030 gui->show_message(string, theme->message_error);
2031 gui->update_default_message();
2035 case FILE_UNRECOGNIZED_CODEC: {
2037 { IndexFile indexfile(this, new_asset);
2038 if( !(result = indexfile.open_index()) )
2039 indexfile.close_index(); }
2041 // Test existing EDLs
2042 for( int j=0; result && j<new_edls.total; ++j ) {
2043 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
2045 new_asset->copy_from(old_asset,1);
2050 Asset *old_asset = edl->assets->get_asset(new_asset->path);
2052 new_asset->copy_from(old_asset,1);
2059 new_asset->audio_data = 1;
2060 new_asset->format = FILE_PCM;
2061 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
2062 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
2063 new_asset->bits = defaults->get("AUDIO_BITS", 16);
2064 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
2065 new_asset->signed_ = defaults->get("SIGNED_", 1);
2066 new_asset->header = defaults->get("HEADER", 0);
2069 fs.extract_name(string, new_asset->path);
2070 strcat(string, _("'s format couldn't be determined."));
2071 FileFormat fwindow(this);
2072 fwindow.create_objects(new_asset, string);
2073 result = fwindow.run_window();
2075 defaults->update("AUDIO_CHANNELS", new_asset->channels);
2076 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
2077 defaults->update("AUDIO_BITS", new_asset->bits);
2078 defaults->update("BYTE_ORDER", new_asset->byte_order);
2079 defaults->update("SIGNED_", new_asset->signed_);
2080 defaults->update("HEADER", new_asset->header);
2085 // Recalculate length
2087 new_file = new File;
2088 result = new_file->open_file(preferences, new_asset, 1, 0);
2090 if( load_mode != LOADMODE_RESOURCESONLY ) {
2091 RecordLabels *labels = edl->session->label_cells ?
2092 new RecordLabels(new_file) : 0;
2093 asset_to_edl(new_edl, new_asset, labels);
2094 new_edls.append(new_edl);
2095 new_edl->add_user();
2099 new_assets.append(new_asset);
2100 new_asset->add_user();
2107 const char *filename = filenames->get(i);
2108 if( xml_file.read_from_file(filename, 1) ) {
2109 eprintf(_("Error: unable to open:\n %s"), filename);
2112 const char *cin_version = 0;
2113 while( !xml_file.read_tag() ) {
2114 if( xml_file.tag.title_is("EDL") ) {
2115 cin_version = xml_file.tag.get_property("VERSION");
2120 if( !cin_version ) {
2121 eprintf(_("XML file %s\n not from cinelerra."),filename);
2122 char string[BCTEXTLEN];
2123 sprintf(string,_("Unknown %s"), filename);
2124 gui->show_message(string);
2127 if( strcmp(cin_version, CINELERRA_VERSION) &&
2128 strcmp(cin_version, "Unify") &&
2129 strcmp(cin_version, "5.1") ) {
2130 eprintf(_("Warning: XML from cinelerra version %s\n"
2131 "Session data may be incompatible."), cin_version);
2133 if( new_edl->load_xml(&xml_file, LOAD_ALL) ) {
2134 eprintf(_("Error: unable to load:\n %s"), filename);
2137 test_plugins(new_edl, filename);
2138 int groups = new_edl->regroup(session->group_number);
2139 session->group_number += groups;
2140 switch( edl_mode ) {
2141 case LOADMODE_EDL_CLIP: {
2142 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2143 session->clip_number++);
2144 char string[BCSTRLEN];
2146 ctime_r(&t, string);
2147 snprintf(new_edl->local_session->clip_notes,
2148 sizeof(new_edl->local_session->clip_notes),
2149 +("%sFrom: %s"), string, filename);
2150 switch( load_mode ) {
2151 case LOADMODE_REPLACE:
2152 case LOADMODE_REPLACE_CONCATENATE:
2153 strcpy(session->filename, filename);
2154 if( update_filename ) set_filename(filename);
2159 case LOADMODE_EDL_NESTED: {
2160 EDL *nested_edl = new EDL;
2161 nested_edl->create_objects();
2162 nested_edl->copy_session(edl, -1);
2163 nested_edl->create_nested(new_edl);
2164 nested_edl->set_path(filename);
2165 new_edl->remove_user();
2166 new_edl = nested_edl;
2169 case LOADMODE_EDL_FILEREF: {
2170 result = create_ref(new_asset, new_edl);
2172 new_assets.append(new_asset);
2173 new_asset->add_user();
2174 new_edl->remove_user();
2176 new_edl->create_objects();
2177 new_edl->copy_session(edl, -1);
2178 asset_to_edl(new_edl, new_asset);
2180 new_file = new File;
2181 result = new_file->open_file(preferences, new_asset, 1, 0);
2185 new_edls.append(new_edl);
2186 new_edl->add_user();
2189 eprintf(_("Error: Unable to load xml:\n %s"), new_asset->path);
2193 new_edl->Garbage::remove_user();
2194 new_asset->Garbage::remove_user();
2196 // Store for testing index
2197 new_files.append(new_file);
2200 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2203 gui->reset_default_message();
2204 gui->default_message();
2207 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2210 // Don't back up here.
2211 if( new_edls.size() ) {
2212 // For pasting, clear the active region
2213 if( load_mode == LOADMODE_PASTE ) {
2214 double start = edl->local_session->get_selectionstart();
2215 double end = edl->local_session->get_selectionend();
2216 if(!EQUIV(start, end))
2217 edl->clear(start, end,
2218 edl->session->labels_follow_edits,
2219 edl->session->plugins_follow_edits,
2220 edl->session->autos_follow_edits);
2222 paste_edls(&new_edls, load_mode, 0, -1,
2223 edl->session->labels_follow_edits,
2224 edl->session->plugins_follow_edits,
2225 edl->session->autos_follow_edits,
2228 else if( load_mode == LOADMODE_NEW_TRACKS &&
2229 edl_mode != LOADMODE_EDL_CLIP )
2230 paste_edls(&new_edls, load_mode, 0, -1, 0, 0, 0, 0);
2231 else if( load_mode != LOADMODE_RESOURCESONLY ||
2232 edl_mode == LOADMODE_EDL_CLIP )
2233 paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
2235 paste_edls(&new_edls, LOADMODE_NOTHING, 0, -1, 0, 0, 0, 0);
2239 // Add new assets to EDL and schedule assets for index building.
2240 int got_indexes = 0;
2241 for( int i=0; i<new_edls.size(); ++i ) {
2242 EDL *new_edl = new_edls[i];
2243 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2244 mainindexes->add_indexable(new_edl->nested_edls[j]);
2245 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2251 for( int i=0; i<new_assets.size(); ++i ) {
2252 Asset *new_asset = new_assets[i];
2253 mainindexes->add_indexable(new_asset);
2254 edl->assets->update(new_asset);
2258 // Start examining next batch of index files
2259 if(got_indexes) mainindexes->start_build();
2262 Track *track = edl->tracks->first;
2264 for( int j = 0; j < track->plugin_set.size(); j++ ) {
2265 PluginSet *plugins = track->plugin_set[j];
2266 Plugin *plugin = plugins->get_first_plugin();
2269 if( load_mode == LOADMODE_REPLACE ||
2270 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2271 if( plugin->plugin_type == PLUGIN_STANDALONE &&
2273 show_plugin(plugin);
2277 plugin = (Plugin*)plugin->next;
2281 track = track->next;
2284 // opening new session
2285 if( ( load_mode == LOADMODE_REPLACE ||
2286 load_mode == LOADMODE_REPLACE_CONCATENATE ) &&
2287 (ftype != FILE_IS_XML || edl_mode != LOADMODE_EDL_CLIP) ) {
2289 edl->session->proxy_scale = 1;
2290 edl->session->proxy_disabled_scale = 1;
2291 edl->session->proxy_use_scaler = 0;
2292 edl->session->proxy_auto_scale = 0;
2293 edl->session->proxy_beep = 0;
2294 edl->local_session->preview_start = 0;
2295 edl->local_session->preview_end = -1;
2296 edl->local_session->loop_playback = 0;
2297 edl->local_session->set_selectionstart(0);
2298 edl->local_session->set_selectionend(0);
2299 edl->local_session->unset_inpoint();
2300 edl->local_session-> unset_outpoint();
2301 set_brender_active(0, 0);
2306 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2307 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2308 ArrayList<Indexable *> orig_idxbls;
2309 for( int i=0; i<new_assets.size(); ++i )
2310 orig_idxbls.append(new_assets.get(i));
2311 for( int i=0; i<new_edls.size(); ++i ) {
2312 EDL *new_edl = new_edls[i];
2313 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2314 if( track->data_type != TRACK_VIDEO ) continue;
2315 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2316 Indexable *idxbl = (Indexable *)edit->asset;
2317 if( !idxbl ) continue;
2318 if( !idxbl->have_video() ) continue;
2319 if( edit->channel != 0 ) continue; // first layer only
2320 orig_idxbls.append(edit->asset);
2324 gui->unlock_window(); // to update progress bar
2325 int ret = render_proxy(orig_idxbls);
2326 gui->lock_window("MWindow::load_filenames");
2327 float gain = edl->session->proxy_beep;
2328 if( ret >= 0 && gain > 0 ) {
2330 beep(2000., 1.5, gain);
2332 beep(4000., 0.25, gain);
2336 // need to update undo before project, since mwindow is unlocked & a new load
2337 // can begin here. Should really prevent loading until we're done.
2338 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2339 undo_after(_("load"), LOAD_ALL);
2341 for(int i = 0; i < new_edls.size(); i++)
2343 new_edls[i]->remove_user();
2345 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2347 new_edls.remove_all();
2349 for(int i = 0; i < new_assets.size(); i++)
2351 new_assets[i]->Garbage::remove_user();
2354 new_assets.remove_all();
2355 new_files.remove_all_objects();
2358 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2359 if(load_mode == LOADMODE_REPLACE ||
2360 load_mode == LOADMODE_REPLACE_CONCATENATE)
2362 session->changes_made = 0;
2366 session->changes_made = 1;
2369 gui->stop_hourglass();
2372 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2373 update_project(load_mode);
2375 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2380 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2382 Asset *format_asset = new Asset;
2383 format_asset->format = FILE_FFMPEG;
2384 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2385 int new_scale = edl->session->proxy_scale;
2386 ProxyRender proxy_render(this, format_asset, new_scale);
2388 for( int i=0; i<new_idxbls.size(); ++i ) {
2389 Indexable *orig = new_idxbls.get(i);
2390 Asset *proxy = proxy_render.add_original(orig, new_scale);
2391 if( !proxy ) continue;
2393 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2394 int got_it = exists && // if proxy exists, and is newer than orig
2395 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2396 if( got_it ) continue;
2397 proxy_render.add_needed(orig, proxy);
2400 // render needed proxies
2401 int result = proxy_render.create_needed_proxies(new_scale);
2403 add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2405 format_asset->remove_user();
2406 return !result ? proxy_render.needed_proxies.size() : -1;
2409 int MWindow::enable_proxy()
2412 if( edl->session->proxy_scale == 1 &&
2413 edl->session->proxy_disabled_scale != 1 ) {
2414 int new_scale = edl->session->proxy_disabled_scale;
2415 int new_use_scaler = edl->session->proxy_use_scaler;
2416 Asset *asset = new Asset;
2417 asset->format = FILE_FFMPEG;
2418 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2419 ret = to_proxy(asset, new_scale, new_use_scaler);
2420 asset->remove_user();
2422 float gain = edl->session->proxy_beep;
2423 beep(2000., 1.5, gain);
2425 edl->session->proxy_disabled_scale = 1;
2426 gui->lock_window("MWindow::to_proxy");
2427 update_project(LOADMODE_REPLACE);
2428 gui->unlock_window();
2433 int MWindow::disable_proxy()
2435 if( edl->session->proxy_scale != 1 &&
2436 edl->session->proxy_disabled_scale == 1 ) {
2437 int old_scale = edl->session->proxy_scale, new_scale = 1;
2438 int new_use_scaler = edl->session->proxy_use_scaler;
2439 Asset *asset = new Asset;
2440 asset->format = FILE_FFMPEG;
2441 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2442 to_proxy(asset, new_scale, new_use_scaler);
2443 asset->remove_user();
2444 edl->session->proxy_disabled_scale = old_scale;
2445 gui->lock_window("MWindow::to_proxy");
2446 update_project(LOADMODE_REPLACE);
2447 gui->unlock_window();
2452 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2454 ArrayList<Indexable*> orig_idxbls;
2455 ArrayList<Indexable*> proxy_assets;
2457 edl->Garbage::add_user();
2459 undo_before(_("proxy"), this);
2460 int asset_scale = new_scale == 1 ? 0 :
2461 !new_use_scaler ? 1 : new_scale;
2462 ProxyRender proxy_render(this, asset, asset_scale);
2464 // revert project to original size from current size
2465 // remove all session proxy assets at the at the current proxy_scale
2466 int proxy_scale = edl->session->proxy_scale;
2468 if( proxy_scale > 1 ) {
2469 Asset *orig_asset = edl->assets->first;
2470 for( ; orig_asset; orig_asset=orig_asset->next ) {
2471 char new_path[BCTEXTLEN];
2472 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2473 // test if proxy asset was already added to proxy_assets
2475 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2476 got_it = !strcmp(proxy_assets[i]->path, new_path);
2477 if( got_it ) continue;
2478 Asset *proxy_asset = edl->assets->get_asset(new_path);
2479 if( !proxy_asset ) continue;
2480 // add pointer to existing EDL asset if it exists
2481 // EDL won't delete it unless it's the same pointer.
2482 proxy_assets.append(proxy_asset);
2483 proxy_asset->add_user();
2484 orig_idxbls.append(orig_asset);
2485 orig_asset->add_user();
2487 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2488 EDL *orig_nested = edl->nested_edls[i];
2489 char new_path[BCTEXTLEN];
2490 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2492 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2493 // test if proxy asset was already added to proxy_assets
2495 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2496 got_it = !strcmp(proxy_assets[i]->path, new_path);
2497 if( got_it ) continue;
2498 Asset *proxy_nested = edl->assets->get_asset(new_path);
2499 if( !proxy_nested ) continue;
2500 // add pointer to existing EDL asset if it exists
2501 // EDL won't delete it unless it's the same pointer.
2502 proxy_assets.append(proxy_nested);
2503 proxy_nested->add_user();
2504 orig_idxbls.append(orig_nested);
2505 orig_nested->add_user();
2508 // convert from the proxy assets to the original assets
2509 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2511 // remove the references
2512 for( int i=0; i<proxy_assets.size(); ++i ) {
2513 Asset *proxy = (Asset *) proxy_assets[i];
2514 proxy->width = proxy->actual_width;
2515 proxy->height = proxy->actual_height;
2516 proxy->remove_user();
2517 edl->assets->remove_pointer(proxy);
2518 proxy->remove_user();
2520 proxy_assets.remove_all();
2521 for( int i = 0; i < orig_idxbls.size(); i++ )
2522 orig_idxbls[i]->remove_user();
2523 orig_idxbls.remove_all();
2526 ArrayList<char *> confirm_paths; // test for new files
2527 confirm_paths.set_array_delete();
2529 // convert to new size if not original size
2530 if( new_scale != 1 ) {
2532 Asset *orig = edl->assets->first;
2533 for( ; orig; orig=orig->next ) {
2534 Asset *proxy = proxy_render.add_original(orig, new_scale);
2535 if( !proxy ) continue;
2536 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2537 int got_it = exists && // if proxy exists, and is newer than orig
2538 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2540 if( exists ) // prompt user to overwrite
2541 confirm_paths.append(cstrdup(proxy->path));
2542 proxy_render.add_needed(orig, proxy);
2545 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2546 EDL *orig_nested = edl->nested_edls[i];
2547 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2548 if( !proxy ) continue;
2549 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2550 int got_it = exists && // if proxy exists, and is newer than orig_nested
2551 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2553 if( exists ) // prompt user to overwrite
2554 confirm_paths.append(cstrdup(proxy->path));
2555 proxy_render.add_needed(orig_nested, proxy);
2561 // test for existing files
2562 if( confirm_paths.size() ) {
2563 result = ConfirmSave::test_files(this, &confirm_paths);
2564 confirm_paths.remove_all_objects();
2568 result = proxy_render.create_needed_proxies(new_scale);
2570 if( !result ) // resize project
2571 edl->set_proxy(new_scale, new_use_scaler,
2572 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2574 undo_after(_("proxy"), LOAD_ALL);
2575 edl->Garbage::remove_user();
2578 return !result ? proxy_render.needed_proxies.size() : -1;
2581 void MWindow::test_plugins(EDL *new_edl, const char *path)
2583 char string[BCTEXTLEN];
2585 // Do a check whether plugins exist
2586 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2587 for( int k=0; k<track->plugin_set.total; ++k ) {
2588 PluginSet *plugin_set = track->plugin_set[k];
2589 for( Plugin *plugin = (Plugin*)plugin_set->first;
2590 plugin; plugin = (Plugin*)plugin->next ) {
2591 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2592 // ok we need to find it in plugindb
2593 PluginServer *server =
2594 scan_plugindb(plugin->title, track->data_type);
2595 if( !server || server->transition ) {
2597 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2598 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2599 "effect", _(plugin->title), path);
2600 MainError::show_error(string);
2605 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2606 if( !edit->transition ) continue;
2607 // ok we need to find transition in plugindb
2608 PluginServer *server =
2609 scan_plugindb(edit->transition->title, track->data_type);
2610 if( !server || !server->transition ) {
2612 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2613 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2614 "transition", _(edit->transition->title), path);
2615 MainError::show_error(string);
2622 void MWindow::init_shm(const char *pfn, int64_t min)
2625 // Fix shared memory
2626 FILE *fd = fopen(pfn, "r");
2628 fscanf(fd, "%jd", &result);
2630 if( result >= min ) return;
2633 fd = fopen(pfn, "w");
2635 fprintf(fd, "0x%jx", min);
2638 fd = fopen(pfn, "r");
2640 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2644 fscanf(fd, "%jd", &result);
2646 if( result < min ) {
2647 eprintf(_("MWindow::init_shm: %s is %p.\n"
2648 "you probably need to be root, or:\n"
2649 "as root, run: echo 0x%jx > %s\n"
2650 "before trying to start cinelerra.\n"
2651 "It should be at least 0x%jx for Cinelerra.\n"),
2652 pfn, (void *)result, min, pfn, min);
2656 void MWindow::create_objects(int want_gui,
2660 const int debug = 0;
2661 if(debug) PRINT_TRACE
2663 // For some reason, init_signals must come after show_splash or the signals won't
2666 if(debug) PRINT_TRACE
2669 if(debug) PRINT_TRACE
2672 if(debug) PRINT_TRACE
2673 default_standard = default_std();
2674 init_defaults(defaults, config_path);
2678 splash_window->update_status(_("Initializing Plugins"));
2679 init_plugins(this, preferences);
2680 if(debug) PRINT_TRACE
2681 init_ladspa_plugins(this, preferences);
2682 if(debug) PRINT_TRACE
2683 init_plugin_tips(*plugindb, cin_lang);
2685 splash_window->update_status(_("Initializing GUI"));
2686 if(debug) PRINT_TRACE
2689 if(debug) PRINT_TRACE
2693 splash_window->update_status(_("Initializing Fonts"));
2694 char string[BCTEXTLEN];
2695 strcpy(string, preferences->plugin_dir);
2696 strcat(string, "/" FONT_SEARCHPATH);
2697 BC_Resources::init_fontconfig(string);
2698 if(debug) PRINT_TRACE
2704 // Default project created here
2706 if(debug) PRINT_TRACE
2709 if(debug) PRINT_TRACE
2714 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2717 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2719 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2720 if(session->show_vwindow)
2721 get_viewer(1, DEFAULT_VWINDOW);
2722 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2725 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2728 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2731 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2734 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2737 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2740 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2746 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2747 mainprogress = new MainProgress(this, gui);
2748 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2749 undo = new MainUndo(this);
2751 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2753 plugin_guis = new PluginGUIs(this);
2754 dead_plugins = new ArrayList<PluginServer*>;
2755 keyframe_threads = new ArrayList<KeyFrameThread*>;
2757 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2760 session->show_vwindow);
2762 // Show all vwindows
2763 // if(session->show_vwindow) {
2764 // for(int j = 0; j < vwindows.size(); j++) {
2765 // VWindow *vwindow = vwindows[j];
2766 // if( !vwindow->is_running() ) continue;
2767 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2770 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2771 // vwindow->gui->lock_window("MWindow::create_objects 1");
2772 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2773 // vwindow->gui->show_window();
2774 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2775 // vwindow->gui->unlock_window();
2780 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2782 if(session->show_cwindow)
2784 cwindow->gui->lock_window("MWindow::create_objects 1");
2785 cwindow->gui->show_window();
2786 cwindow->gui->unlock_window();
2789 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2790 if(session->show_awindow)
2792 awindow->gui->lock_window("MWindow::create_objects 1");
2793 awindow->gui->show_window();
2794 awindow->gui->unlock_window();
2797 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2798 if(session->show_lwindow)
2800 lwindow->gui->lock_window("MWindow::create_objects 1");
2801 lwindow->gui->show_window();
2802 lwindow->gui->unlock_window();
2805 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2807 (int)timer.get_difference(),
2809 if(session->show_gwindow)
2811 gwindow->gui->lock_window("MWindow::create_objects 1");
2812 gwindow->gui->show_window();
2813 gwindow->gui->unlock_window();
2816 if(debug) PRINT_TRACE
2818 gui->lock_window("MWindow::create_objects 1");
2819 gui->mainmenu->load_defaults(defaults);
2820 gui->mainmenu->update_toggles(0);
2821 gui->update_patchbay();
2822 gui->draw_canvas(0, 0);
2823 gui->draw_cursor(1);
2825 gui->raise_window();
2826 gui->unlock_window();
2827 cwindow->gui->lock_window("MWindow::create_objects 1");
2828 cwindow->gui->tool_panel->raise_tool();
2829 cwindow->gui->unlock_window();
2830 if(debug) PRINT_TRACE
2832 if(preferences->use_tipwindow)
2834 if(debug) PRINT_TRACE
2836 gui->add_keyboard_listener(
2837 (int (BC_WindowBase::*)(BC_WindowBase *))
2838 &MWindowGUI::keyboard_listener);
2841 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2842 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2843 if(debug) PRINT_TRACE
2845 BC_WindowBase::get_resources()->vframe_shm = 1;
2848 int MWindow::uses_opengl()
2850 if( !playback_3d || !playback_3d->running() ) return 0;
2851 PlaybackConfig *playback_config = edl->session->playback_config;
2852 return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
2855 void MWindow::show_splash()
2857 #include "data/heroine_logo9_png.h"
2858 VFrame *frame = new VFramePng(heroine_logo9_png);
2859 BC_DisplayInfo dpyi;
2860 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2861 int rr = (rw < rh ? rw : rh) / 4;
2862 splash_window = new SplashGUI(frame, rr, rr);
2863 splash_window->create_objects();
2866 void MWindow::hide_splash()
2869 delete splash_window;
2874 void MWindow::start()
2878 // vwindows[DEFAULT_VWINDOW]->start();
2889 playback_3d->start();
2895 run_lock->lock("MWindow::run");
2899 brender_lock->lock("MWindow::run 1");
2900 delete brender; brender = 0;
2901 brender_lock->unlock();
2903 interrupt_indexes();
2909 void MWindow::show_vwindow()
2911 int total_running = 0;
2912 session->show_vwindow = 1;
2914 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2915 // Raise all windows which are visible
2916 for(int j = 0; j < vwindows.size(); j++) {
2917 VWindow *vwindow = vwindows[j];
2918 if( !vwindow->is_running() ) continue;
2919 vwindow->gui->lock_window("MWindow::show_vwindow");
2920 vwindow->gui->show_window(0);
2921 vwindow->gui->raise_window();
2922 vwindow->gui->flush();
2923 vwindow->gui->unlock_window();
2927 // If no windows visible
2930 get_viewer(1, DEFAULT_VWINDOW);
2933 gui->mainmenu->show_vwindow->set_checked(1);
2936 void MWindow::show_awindow()
2938 session->show_awindow = 1;
2939 awindow->gui->lock_window("MWindow::show_awindow");
2940 awindow->gui->show_window();
2941 awindow->gui->raise_window();
2942 awindow->gui->flush();
2943 awindow->gui->unlock_window();
2944 gui->mainmenu->show_awindow->set_checked(1);
2947 char *MWindow::get_cwindow_display()
2949 char *x11_host = screens < 2 || session->window_config == 0 ?
2950 session->a_x11_host : session->b_x11_host;
2951 return *x11_host ? x11_host : 0;
2954 void MWindow::show_cwindow()
2956 session->show_cwindow = 1;
2957 cwindow->show_window();
2958 gui->mainmenu->show_cwindow->set_checked(1);
2961 void MWindow::show_gwindow()
2963 session->show_gwindow = 1;
2965 gwindow->gui->lock_window("MWindow::show_gwindow");
2966 gwindow->gui->show_window();
2967 gwindow->gui->raise_window();
2968 gwindow->gui->flush();
2969 gwindow->gui->unlock_window();
2971 gui->mainmenu->show_gwindow->set_checked(1);
2973 void MWindow::hide_gwindow()
2975 session->show_gwindow = 0;
2977 gwindow->gui->lock_window("MWindow::show_gwindow");
2978 gwindow->gui->hide_window();
2979 gwindow->gui->unlock_window();
2982 void MWindow::show_lwindow()
2984 session->show_lwindow = 1;
2985 lwindow->gui->lock_window("MWindow::show_lwindow");
2986 lwindow->gui->show_window();
2987 lwindow->gui->raise_window();
2988 lwindow->gui->flush();
2989 lwindow->gui->unlock_window();
2990 gui->mainmenu->show_lwindow->set_checked(1);
2993 void MWindow::restore_windows()
2995 if( !session->show_vwindow ) {
2996 for( int i=0, n=vwindows.size(); i<n; ++i ) {
2997 VWindow *vwindow = vwindows[i];
2998 if( !vwindow || !vwindow->is_running() ) continue;
2999 vwindow->gui->lock_window("MWindow::restore_windows");
3000 vwindow->gui->close(1);
3001 vwindow->gui->unlock_window();
3007 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
3008 awindow->gui->lock_window("MWindow::restore_windows");
3009 awindow->gui->close_event();
3010 awindow->gui->unlock_window();
3012 else if( session->show_awindow && awindow->gui->is_hidden() )
3015 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
3016 cwindow->gui->lock_window("MWindow::restore_windows");
3017 cwindow->hide_window();
3018 cwindow->gui->unlock_window();
3020 else if( session->show_cwindow && cwindow->gui->is_hidden() )
3021 cwindow->show_window();
3023 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
3024 gwindow->gui->lock_window("MWindow::restore_windows");
3025 gwindow->gui->close_event();
3026 gwindow->gui->unlock_window();
3028 else if( session->show_gwindow && gwindow->gui->is_hidden() )
3031 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
3032 lwindow->gui->lock_window("MWindow::restore_windows");
3033 lwindow->gui->close_event();
3034 lwindow->gui->unlock_window();
3036 else if( session->show_lwindow && lwindow->gui->is_hidden() )
3042 void MWindow::load_layout(const char *layout)
3044 char path[BCTEXTLEN];
3045 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3046 session->load_file(path);
3048 gui->default_positions();
3052 void MWindow::save_layout(const char *layout)
3054 char path[BCTEXTLEN];
3055 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3056 session->save_file(path);
3059 void MWindow::delete_layout(const char *layout)
3061 char path[BCTEXTLEN];
3062 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3066 int MWindow::tile_windows(int window_config)
3068 int need_reload = 0;
3069 int play_config = window_config==0 ? 0 : 1;
3070 edl->session->playback_config->load_defaults(defaults, play_config);
3071 session->default_window_positions(window_config);
3072 if( screens == 1 ) {
3073 gui->default_positions();
3074 sync_parameters(CHANGE_ALL);
3081 void MWindow::toggle_loop_playback()
3083 edl->local_session->loop_playback = !edl->local_session->loop_playback;
3084 set_loop_boundaries();
3087 gui->draw_overlays(1);
3088 sync_parameters(CHANGE_PARAMS);
3091 void MWindow::set_screens(int value)
3096 void MWindow::set_auto_keyframes(int value)
3098 edl->session->auto_keyframes = value;
3099 gui->mbuttons->edit_panel->keyframe->update(value);
3101 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
3102 cwindow->gui->edit_panel->keyframe->update(value);
3103 cwindow->gui->flush();
3104 cwindow->gui->unlock_window();
3107 void MWindow::set_span_keyframes(int value)
3109 edl->session->span_keyframes = value;
3110 gui->mbuttons->edit_panel->span_keyframe->update(value);
3112 cwindow->gui->lock_window("MWindow::set_span_keyframes");
3113 cwindow->gui->edit_panel->span_keyframe->update(value);
3114 cwindow->gui->flush();
3115 cwindow->gui->unlock_window();
3118 void MWindow::set_auto_visibility(Autos *autos, int value)
3120 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3121 edl->session->auto_conf->plugins = value;
3122 else if( autos->autoidx >= 0 )
3123 edl->session->auto_conf->autos[autos->autoidx] = value;
3127 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3128 gui->mainmenu->update_toggles(1);
3129 gui->unlock_window();
3130 gwindow->gui->update_toggles(1);
3131 gui->lock_window("MWindow::set_auto_visibility");
3134 void MWindow::set_keyframe_type(int mode)
3136 gui->lock_window("MWindow::set_keyframe_type");
3137 edl->local_session->floatauto_type = mode;
3138 gui->mainmenu->update_toggles(0);
3139 gui->unlock_window();
3142 int MWindow::set_editing_mode(int new_editing_mode)
3144 edl->session->editing_mode = new_editing_mode;
3145 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3146 gui->mbuttons->edit_panel->update();
3147 gui->set_editing_mode(1);
3149 cwindow->gui->lock_window("MWindow::set_editing_mode");
3150 cwindow->gui->edit_panel->update();
3151 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3152 cwindow->gui->unlock_window();
3156 void MWindow::toggle_editing_mode()
3158 int mode = edl->session->editing_mode;
3159 if( mode == EDITING_ARROW )
3160 set_editing_mode(EDITING_IBEAM);
3162 set_editing_mode(EDITING_ARROW);
3165 void MWindow::toggle_camera_xyz()
3167 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3168 gwindow->gui->toggle_camera_xyz();
3169 gwindow->gui->unlock_window();
3172 void MWindow::toggle_projector_xyz()
3174 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3175 gwindow->gui->toggle_projector_xyz();
3176 gwindow->gui->unlock_window();
3179 void MWindow::set_labels_follow_edits(int value)
3181 edl->session->labels_follow_edits = value;
3182 gui->mbuttons->edit_panel->locklabels->update(value);
3183 gui->mainmenu->labels_follow_edits->set_checked(value);
3187 void MWindow::sync_parameters(int change_type)
3189 if( in_destructor ) return;
3191 // Sync engines which are playing back
3192 if( cwindow->playback_engine->is_playing_back ) {
3193 if( change_type == CHANGE_PARAMS ) {
3194 // TODO: block keyframes until synchronization is done
3195 cwindow->playback_engine->sync_parameters(edl);
3199 int command = cwindow->playback_engine->command->command;
3200 // Waiting for tracking to finish would make the restart position more
3201 // accurate but it can't lock the window to stop tracking for some reason.
3202 // Not waiting for tracking gives a faster response but restart position is
3203 // only as accurate as the last tracking update.
3204 cwindow->playback_engine->transport_stop(0);
3205 cwindow->playback_engine->next_command->realtime = 1;
3206 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3210 cwindow->refresh_frame(change_type);
3214 void MWindow::age_caches()
3216 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3218 // preferences->cache_size,
3219 // audio_cache->get_memory_usage(1),
3220 // video_cache->get_memory_usage(1),
3221 // frame_cache->get_memory_usage(),
3222 // wave_cache->get_memory_usage(),
3224 frame_cache->age_cache(512);
3225 wave_cache->age_cache(8192);
3227 int64_t memory_usage;
3228 int64_t prev_memory_usage = 0;
3230 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3231 while( !result && prev_memory_usage !=
3232 (memory_usage=video_cache->get_memory_usage(1)) &&
3233 memory_usage > video_size ) {
3234 video_cache->delete_oldest();
3235 prev_memory_usage = memory_usage;
3238 prev_memory_usage = 0;
3240 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3241 while( !result && prev_memory_usage !=
3242 (memory_usage=audio_cache->get_memory_usage(1)) &&
3243 memory_usage > audio_size ) {
3244 audio_cache->delete_oldest();
3245 prev_memory_usage = memory_usage;
3249 void MWindow::reset_android_remote()
3251 gui->use_android_remote(preferences->android_remote);
3255 void MWindow::show_keyframe_gui(Plugin *plugin)
3257 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3258 // Find existing thread
3259 for(int i = 0; i < keyframe_threads->size(); i++)
3261 if(keyframe_threads->get(i)->plugin == plugin)
3263 keyframe_threads->get(i)->start_window(plugin, 0);
3264 keyframe_gui_lock->unlock();
3269 // Find unused thread
3270 for(int i = 0; i < keyframe_threads->size(); i++)
3272 if(!keyframe_threads->get(i)->plugin)
3274 keyframe_threads->get(i)->start_window(plugin, 0);
3275 keyframe_gui_lock->unlock();
3280 // Create new thread
3281 KeyFrameThread *thread = new KeyFrameThread(this);
3282 keyframe_threads->append(thread);
3283 thread->start_window(plugin, 0);
3285 keyframe_gui_lock->unlock();
3289 void MWindow::show_plugin(Plugin *plugin)
3294 // Remove previously deleted plugin GUIs
3295 dead_plugin_lock->lock("MWindow::show_plugin");
3296 dead_plugins->remove_all_objects();
3297 dead_plugin_lock->unlock();
3299 //printf("MWindow::show_plugin %d\n", __LINE__);
3303 plugin_gui_lock->lock("MWindow::show_plugin");
3304 for(int i = 0; i < plugin_guis->total; i++)
3306 // Pointer comparison
3307 if(plugin_guis->get(i)->plugin == plugin)
3309 plugin_guis->get(i)->raise_window();
3316 //printf("MWindow::show_plugin 1\n");
3317 if( !done && !plugin->track ) {
3318 printf("MWindow::show_plugin track not defined.\n");
3322 PluginServer *server = scan_plugindb(plugin->title,
3323 plugin->track->data_type);
3325 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3326 if(server && server->uses_gui)
3328 PluginServer *gui = new PluginServer(*server);
3329 plugin_guis->append(gui);
3330 // Needs mwindow to do GUI
3331 gui->set_mwindow(this);
3332 gui->open_plugin(0, preferences, edl, plugin);
3337 plugin_gui_lock->unlock();
3338 // update show/gui_id
3339 sync_parameters(CHANGE_PARAMS);
3340 //printf("MWindow::show_plugin %d\n", __LINE__);
3343 //printf("MWindow::show_plugin 2\n");
3346 void MWindow::hide_plugin(Plugin *plugin, int lock)
3349 // Update the toggle
3350 gui->lock_window("MWindow::hide_plugin");
3351 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3352 gui->unlock_window();
3354 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3355 for(int i = 0; i < plugin_guis->total; i++)
3357 if(plugin_guis->get(i)->plugin == plugin)
3359 PluginServer *ptr = plugin_guis->get(i);
3360 plugin_guis->remove(ptr);
3361 if(lock) plugin_gui_lock->unlock();
3362 // Last command executed in client side close
3363 // Schedule for deletion
3370 if(lock) plugin_gui_lock->unlock();
3371 // update show/gui_id
3372 sync_parameters(CHANGE_PARAMS);
3375 void MWindow::delete_plugin(PluginServer *plugin)
3377 dead_plugin_lock->lock("MWindow::delete_plugin");
3378 dead_plugins->append(plugin);
3379 dead_plugin_lock->unlock();
3382 void MWindow::hide_plugins()
3384 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3385 while(plugin_guis->size())
3387 PluginServer *ptr = plugin_guis->get(0);
3388 plugin_guis->remove(ptr);
3389 plugin_gui_lock->unlock();
3390 // Last command executed in client side close
3391 // Schedule for deletion
3394 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3396 plugin_gui_lock->unlock();
3398 hide_keyframe_guis();
3401 void MWindow::hide_keyframe_guis()
3403 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3404 for(int i = 0; i < keyframe_threads->size(); i++)
3406 keyframe_threads->get(i)->close_window();
3408 keyframe_gui_lock->unlock();
3411 void MWindow::hide_keyframe_gui(Plugin *plugin)
3413 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3414 for(int i = 0; i < keyframe_threads->size(); i++)
3416 if(keyframe_threads->get(i)->plugin == plugin)
3418 keyframe_threads->get(i)->close_window();
3422 keyframe_gui_lock->unlock();
3425 int MWindow::get_hash_color(Edit *edit)
3427 Indexable *idxbl = edit->asset ?
3428 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3429 if( !idxbl ) return 0;
3430 char path[BCTEXTLEN];
3431 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3432 edl->session->proxy_scale == 1 ||
3433 ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
3434 strcpy(path, idxbl->path);
3435 char *cp = strrchr(path, '/');
3436 cp = !cp ? path : cp+1;
3437 uint8_t *bp = (uint8_t*)cp;
3439 while( *bp ) v += *bp++;
3440 return get_hash_color(v);
3443 int MWindow::get_hash_color(int v)
3445 int hash = 0x303030;
3446 if( v & 0x01 ) hash ^= 0x000040;
3447 if( v & 0x02 ) hash ^= 0x004000;
3448 if( v & 0x04 ) hash ^= 0x400000;
3449 if( v & 0x08 ) hash ^= 0x080000;
3450 if( v & 0x10 ) hash ^= 0x000800;
3451 if( v & 0x20 ) hash ^= 0x000008;
3452 if( v & 0x40 ) hash ^= 0x404040;
3453 if( v & 0x80 ) hash ^= 0x080808;
3457 int MWindow::get_group_color(int v)
3459 int color = 0x606060;
3460 if( v & 0x01 ) color ^= 0x000080;
3461 if( v & 0x02 ) color ^= 0x008000;
3462 if( v & 0x04 ) color ^= 0x800000;
3463 if( v & 0x08 ) color ^= 0x100000;
3464 if( v & 0x10 ) color ^= 0x001000;
3465 if( v & 0x20 ) color ^= 0x000010;
3466 if( v & 0x40 ) color ^= 0x080808;
3467 if( v & 0x80 ) color ^= 0x909090;
3471 int MWindow::get_title_color(Edit *edit)
3473 unsigned color = edit->color & 0xffffff;
3474 unsigned alpha = (~edit->color>>24) & 0xff;
3476 if( edit->group_id )
3477 color = get_group_color(edit->group_id);
3478 else if( preferences->autocolor_assets )
3479 color = get_hash_color(edit);
3484 alpha = session->title_bar_alpha*255;
3485 return color | (~alpha<<24);
3488 void MWindow::update_keyframe_guis()
3490 // Send new configuration to keyframe GUI's
3491 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3492 for(int i = 0; i < keyframe_threads->size(); i++)
3494 KeyFrameThread *ptr = keyframe_threads->get(i);
3495 if(edl->tracks->plugin_exists(ptr->plugin))
3499 ptr->close_window();
3502 keyframe_gui_lock->unlock();
3505 void MWindow::update_plugin_guis(int do_keyframe_guis)
3507 // Send new configuration to plugin GUI's
3508 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3510 for(int i = 0; i < plugin_guis->size(); i++)
3512 PluginServer *ptr = plugin_guis->get(i);
3513 if(edl->tracks->plugin_exists(ptr->plugin))
3517 // Schedule for deletion if no plugin
3518 plugin_guis->remove_number(i);
3527 // Change plugin variable if not visible
3528 Track *track = edl->tracks->first;
3531 for(int i = 0; i < track->plugin_set.size(); i++)
3533 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3537 for(int i = 0; i < plugin_guis->size(); i++)
3539 PluginServer *server = plugin_guis->get(i);
3540 if(server->plugin == plugin)
3547 if(!got_it) plugin->show = 0;
3548 plugin = (Plugin*)plugin->next;
3552 track = track->next;
3555 plugin_gui_lock->unlock();
3558 if(do_keyframe_guis) update_keyframe_guis();
3561 void MWindow::stop_plugin_guis()
3563 // Send new configuration to plugin GUI's
3564 plugin_gui_lock->lock("MWindow::stop_plugin_guis");
3566 for( int i=0; i<plugin_guis->size(); ++i ) {
3567 PluginServer *ptr = plugin_guis->get(i);
3568 if( edl->tracks->plugin_exists(ptr->plugin) ) {
3572 plugin_gui_lock->unlock();
3575 int MWindow::plugin_gui_open(Plugin *plugin)
3577 int gui_id = plugin->gui_id;
3578 if( gui_id < 0 ) return 0;
3579 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3580 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3581 int result = plugin_server ? 1 : 0;
3582 plugin_gui_lock->unlock();
3587 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3589 int gui_id = plugin->gui_id;
3590 if( gui_id < 0 ) return;
3591 plugin_gui_lock->lock("MWindow::render_plugin_gui 0");
3592 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3594 plugin_server->render_gui(data);
3595 plugin_gui_lock->unlock();
3598 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3600 int gui_id = plugin->gui_id;
3601 if( gui_id < 0 ) return;
3602 plugin_gui_lock->lock("MWindow::render_plugin_gui 1");
3603 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3605 plugin_server->render_gui(data, size);
3606 plugin_gui_lock->unlock();
3609 void MWindow::reset_plugin_gui_frames(Plugin *plugin)
3611 int gui_id = plugin->gui_id;
3612 if( gui_id < 0 ) return;
3613 plugin_gui_lock->lock("MWindow::reset_plugin_gui_frames");
3614 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3616 plugin_server->reset_plugin_gui_frames();
3617 plugin_gui_lock->unlock();
3620 void MWindow::render_plugin_gui_frames(PluginClientFrames *frames, Plugin *plugin)
3622 int gui_id = plugin->gui_id;
3623 if( gui_id < 0 ) return;
3624 plugin_gui_lock->lock("MWindow::render_plugin_gui_frames");
3625 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3627 plugin_server->render_plugin_gui_frames(frames);
3628 plugin_gui_lock->unlock();
3631 double MWindow::get_tracking_position()
3633 return edl->local_session->get_selectionstart(1);
3636 int MWindow::get_tracking_direction()
3638 return cwindow->playback_engine->get_direction();
3641 void MWindow::update_plugin_states()
3643 plugin_gui_lock->lock("MWindow::update_plugin_states");
3644 for(int i = 0; i < plugin_guis->total; i++)
3648 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3649 PluginServer *src_plugingui = plugin_guis->get(i);
3651 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3652 for(Track *track = edl->tracks->first;
3654 track = track->next)
3657 j < track->plugin_set.total && !result;
3660 PluginSet *plugin_set = track->plugin_set[j];
3661 for(Plugin *plugin = (Plugin*)plugin_set->first;
3663 plugin = (Plugin*)plugin->next)
3665 if(plugin == src_plugin &&
3666 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3672 // Doesn't exist anymore
3675 hide_plugin(src_plugin, 0);
3679 plugin_gui_lock->unlock();
3683 void MWindow::update_plugin_titles()
3685 for(int i = 0; i < plugin_guis->total; i++)
3687 plugin_guis->get(i)->update_title();
3691 int MWindow::asset_to_edl(EDL *new_edl,
3693 RecordLabels *labels)
3695 const int debug = 0;
3696 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3699 // Keep frame rate, sample rate, and output size unchanged.
3700 // These parameters would revert the project if VWindow displayed an asset
3701 // of different size than the project.
3702 if(new_asset->video_data)
3704 new_edl->session->video_tracks = new_asset->layers;
3707 new_edl->session->video_tracks = 0;
3709 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3715 if(new_asset->audio_data)
3717 new_edl->session->audio_tracks = new_asset->channels;
3720 new_edl->session->audio_tracks = 0;
3721 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3723 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3724 new_edl->create_default_tracks();
3725 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3726 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3730 //printf("MWindow::asset_to_edl 3\n");
3731 new_edl->insert_asset(new_asset,
3736 //printf("MWindow::asset_to_edl 3\n");
3737 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3739 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3740 if(edl->session->cursor_on_frames)
3742 double length = new_edl->tracks->total_length();
3743 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3744 new_edl->tracks->clear(length, edl_length, 1, 1);
3750 char string[BCTEXTLEN];
3752 fs.extract_name(string, new_asset->path);
3753 //printf("MWindow::asset_to_edl 3\n");
3755 strcpy(new_edl->local_session->clip_title, string);
3756 //printf("MWindow::asset_to_edl 4 %s\n", string);
3757 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3759 new_edl->local_session->asset2edl = 1;
3764 // Reset everything after a load.
3765 void MWindow::update_project(int load_mode)
3767 const int debug = 0;
3769 if(debug) PRINT_TRACE
3770 edl->tracks->update_y_pixels(theme);
3771 session->update_clip_number();
3773 if(debug) PRINT_TRACE
3775 if( load_mode == LOADMODE_REPLACE ||
3776 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3777 delete gui->keyvalue_popup;
3778 gui->keyvalue_popup = 0;
3782 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3783 if(debug) PRINT_TRACE
3784 gui->unlock_window();
3787 cwindow->update(0, 0, 1, 1, 1);
3789 if(debug) PRINT_TRACE
3791 // Close all the vwindows
3792 if( load_mode == LOADMODE_REPLACE ||
3793 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3794 if(debug) PRINT_TRACE
3795 int first_vwindow = 0;
3796 if(session->show_vwindow) first_vwindow = 1;
3797 // Change visible windows to no source
3798 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3799 VWindow *vwindow = vwindows[i];
3800 if( !vwindow->is_running() ) continue;
3801 vwindow->change_source(-1);
3804 // Close remaining windows
3805 for(int i = first_vwindow; i < vwindows.size(); i++) {
3806 VWindow *vwindow = vwindows[i];
3807 if( !vwindow->is_running() ) continue;
3808 vwindow->close_window();
3810 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3811 VWindow *vwindow = get_viewer(1, -1);
3812 vwindow->change_source(i);
3814 if(debug) PRINT_TRACE
3818 for( int i=0; i<edl->mixers.size(); ++i ) {
3819 Mixer *mixer = edl->mixers[i];
3820 ZWindow *zwindow = get_mixer(mixer);
3821 zwindow->set_title(mixer->title);
3824 cwindow->gui->canvas->set_zoom(edl, 0);
3828 if(debug) PRINT_TRACE
3829 cwindow->gui->lock_window("MWindow::update_project 2");
3830 cwindow->gui->timebar->update(0);
3831 Track *track = cwindow->calculate_affected_track();
3832 cwindow->mask_track_id = track ? track->get_id() : -1;
3833 cwindow->gui->tool_panel->raise_tool();
3834 cwindow->gui->update_canvas(0);
3835 cwindow->gui->unlock_window();
3837 if(debug) PRINT_TRACE
3838 cwindow->refresh_frame(CHANGE_ALL);
3840 awindow->gui->async_update_assets();
3841 if(debug) PRINT_TRACE
3843 gui->lock_window("MWindow::update_project");
3844 gui->update_mixers(0, 0);
3846 if(debug) PRINT_TRACE
3849 void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
3851 int got_indexes = 0;
3852 for( int i=0; i<new_edl->nested_edls.size(); ++i ) {
3853 EDL *nested_edl = new_edl->nested_edls[i];
3854 mainindexes->add_indexable(nested_edl);
3855 edl->nested_edls.update_index(nested_edl);
3858 for( Asset *asset=new_edl->assets->first; asset; asset=asset->next ) {
3859 mainindexes->add_indexable(asset);
3860 edl->assets->update(asset);
3863 // Start examining next batch of index files
3865 mainindexes->start_build();
3868 gui->lock_window("MWindow::stack_push");
3869 if( stack.size() < 9 ) {
3872 StackItem &item = stack.append();
3874 item.new_edl = new_edl;
3878 if( idxbl && idxbl->is_asset ) {
3880 Asset *asset = (Asset *)idxbl;
3881 if( asset->format == FILE_REF &&
3882 !stat(asset->path, &st) )
3883 item.mtime = st.st_mtime;
3887 strcpy(session->filename, edl->path);
3888 undo = new MainUndo(this);
3889 gui->stack_button->update();
3890 update_project(LOADMODE_REPLACE);
3892 gui->unlock_window();
3895 void MWindow::stack_pop()
3897 if( !stack.size() ) return;
3898 // writes on config_path/backup%d.xml
3900 // already have gui lock
3901 StackItem &item = stack.last();
3902 // session edl replaced, overwrite and save clip data
3903 if( item.new_edl != edl )
3904 item.new_edl->overwrite_clip(edl);
3909 Indexable *idxbl = item.idxbl;
3910 int64_t mtime = item.mtime;
3913 gui->unlock_window();
3914 remove_from_caches(idxbl);
3915 remove_indexfile(idxbl);
3916 mainindexes->add_indexable(idxbl);
3917 mainindexes->start_build();
3918 awindow->gui->async_update_assets();
3919 gui->lock_window("MWindow::stack_pop");
3921 strcpy(session->filename, edl->path);
3922 update_project(LOADMODE_REPLACE);
3923 undo_after(_("open edl"), LOAD_ALL);
3924 gui->stack_button->update();
3925 if( mtime && idxbl && idxbl->is_asset ) {
3927 Asset *asset = (Asset *)idxbl;
3928 if( asset->format == FILE_REF && !stat(asset->path, &st) &&
3929 item.mtime == st.st_mtime ) {
3930 char text[BCTEXTLEN];
3931 snprintf(text, sizeof(text),
3932 _("Warning: Asset not updated: %s"), asset->path);
3933 show_warning(&preferences->warn_stack, text);
3938 void MWindow::clip_to_media()
3940 if( edl->session->proxy_scale != 1 ) {
3941 eprintf("Nesting not allowed when proxy scale != 1");
3945 int clips_total = session->drag_clips->total;
3946 for( int i=0; i<clips_total; ++i ) {
3947 EDL *clip = session->drag_clips->values[i];
3948 time_t dt; time(&dt);
3949 struct tm dtm; localtime_r(&dt, &dtm);
3950 char path[BCTEXTLEN], *cp = path, *ep = cp+sizeof(path)-1;
3951 // path_basename = "Nested_<date>-<time>_<basename>"
3952 cp += snprintf(cp, ep-cp, _("Nested_%02d%02d%02d-%02d%02d%02d_"),
3953 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
3954 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
3955 char *bp = strrchr(clip->local_session->clip_title, '/');
3956 bp = bp ? bp+1 : clip->local_session->clip_title;
3957 cp += snprintf(cp, ep-cp, "%s", bp);
3958 EDL *nested = edl->new_nested_edl(clip, path);
3959 edl->clips.remove(clip);
3960 clip->remove_user();
3961 mainindexes->add_indexable(nested);
3963 undo_after(_("clip2media"), LOAD_ALL);
3964 mainindexes->start_build();
3965 awindow->gui->async_update_assets();
3968 void MWindow::media_to_clip()
3971 int assets_total = session->drag_assets->total;
3972 for( int i=0; i<assets_total; ++i ) {
3973 Indexable *idxbl = session->drag_assets->values[i];
3974 if( idxbl->is_asset ) {
3975 eprintf(_("media is not EDL:\n%s"), idxbl->path);
3978 char clip_title[BCSTRLEN];
3982 sprintf(clip_title, _("Clip %d"), session->clip_number++);
3983 for( int i=0; name_ok && i<edl->clips.size(); ++i ) {
3984 char *title = edl->clips[i]->local_session->clip_title;
3985 if( !strcasecmp(clip_title, title) ) name_ok = 0;
3988 EDL *nested = (EDL *)idxbl;
3989 EDL *clip = edl->add_clip(nested);
3990 strcpy(clip->local_session->clip_title, clip_title);
3991 snprintf(clip->local_session->clip_notes,
3992 sizeof(clip->local_session->clip_notes),
3993 _("From: %s"), nested->path);
3995 undo_after(_("media2clip"), LOAD_ALL);
3996 awindow->gui->async_update_assets();
3999 int MWindow::create_ref(Asset *asset, EDL *ref)
4001 asset->format = FILE_REF;
4002 double secs = ref->tracks->total_length();
4003 int audio_channels = ref->session->audio_channels;
4004 asset->audio_data = audio_channels > 0 ? 1 : 0;
4005 asset->channels = audio_channels;
4006 asset->sample_rate = ref->session->sample_rate;
4007 asset->audio_length = audio_channels > 0 && secs > 0 ?
4008 secs * asset->sample_rate : 0;
4009 strcpy(asset->acodec, _("reference"));
4011 int video_layers = ref->session->video_channels;
4012 asset->video_data = video_layers > 0 ? 1 : 0;
4013 asset->layers = video_layers > 0 ? 1 : 0;
4014 asset->actual_width = ref->session->output_w;
4015 asset->actual_height = ref->session->output_h;
4016 asset->width = asset->actual_width;
4017 asset->height = asset->actual_height;
4018 asset->frame_rate = ref->session->frame_rate;
4019 asset->video_length = video_layers > 0 && secs > 0 ?
4020 secs * asset->frame_rate : 0;
4021 strcpy(asset->vcodec, _("reference"));
4025 void MWindow::update_preferences(Preferences *prefs)
4027 if( prefs != preferences )
4028 preferences->copy_from(prefs);
4029 if( cwindow->playback_engine )
4030 cwindow->playback_engine->preferences->copy_from(prefs);
4031 for(int i = 0; i < vwindows.size(); i++) {
4032 VWindow *vwindow = vwindows[i];
4033 if( !vwindow->is_running() ) continue;
4034 if( vwindow->playback_engine )
4035 vwindow->playback_engine->preferences->copy_from(prefs);
4037 for(int i = 0; i < zwindows.size(); i++) {
4038 ZWindow *zwindow = zwindows[i];
4039 if( !zwindow->is_running() ) continue;
4040 if( zwindow->zgui->playback_engine )
4041 zwindow->zgui->playback_engine->preferences->copy_from(prefs);
4045 void MWindow::update_vwindow()
4047 for( int i=0; i<vwindows.size(); ++i ) {
4048 VWindow *vwindow = vwindows[i];
4049 if( vwindow->is_running() ) {
4050 vwindow->gui->lock_window("MWindow::update_vwindow");
4052 vwindow->gui->unlock_window();
4057 void MWindow::remove_indexfile(Indexable *indexable)
4059 if( !indexable->is_asset ) return;
4060 Asset *asset = (Asset *)indexable;
4062 IndexFile::delete_index(preferences, asset, ".toc");
4063 IndexFile::delete_index(preferences, asset, ".idx");
4064 IndexFile::delete_index(preferences, asset, ".mkr");
4067 void MWindow::rebuild_indices()
4069 for(int i = 0; i < session->drag_assets->total; i++)
4071 Indexable *indexable = session->drag_assets->get(i);
4072 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4073 remove_indexfile(indexable);
4074 // Schedule index build
4075 indexable->index_state->remove_user();
4076 indexable->index_state = new IndexState;
4077 IndexFile::delete_index_files(preferences, indexable);
4078 if( indexable->is_asset ) {
4079 Asset *asset = (Asset *)indexable;
4080 if( asset->format != FILE_PCM ) {
4081 asset->format = FILE_UNKNOWN;
4082 asset->reset_audio();
4084 asset->reset_video();
4085 remove_from_caches(asset);
4086 // File file; // re-probe the asset
4087 // file.open_file(preferences, asset, 1, 0);
4089 mainindexes->add_indexable(indexable);
4091 // still in render engine
4092 sync_parameters(CHANGE_ALL);
4093 awindow->gui->async_update_assets();
4094 mainindexes->start_build();
4098 void MWindow::get_backup_path(char *path, int len)
4100 char *cp = path, *ep = cp + len-1;
4101 cp += snprintf(cp, ep-cp, "%s/", File::get_config_path());
4102 int idx = stack.size();
4103 cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx);
4106 void MWindow::save_backup()
4110 edl->set_path(session->filename);
4112 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
4113 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
4114 File::get_config_path(), BACKUP_FILE1);
4115 get_backup_path(backup_path, sizeof(backup_path));
4116 rename(backup_path, backup_path1);
4117 edl->save_xml(&file, backup_path);
4118 file.terminate_string();
4120 fs.complete_path(backup_path);
4122 if(file.write_to_file(backup_path)) {
4124 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
4125 gui->show_message(string2);
4130 void MWindow::load_backup()
4132 ArrayList<char*> path_list;
4133 path_list.set_array_delete();
4135 char backup_path[BCTEXTLEN];
4136 get_backup_path(backup_path, sizeof(backup_path));
4138 fs.complete_path(backup_path);
4140 path_list.append(out_path = new char[strlen(backup_path) + 1]);
4141 strcpy(out_path, backup_path);
4143 load_filenames(&path_list, LOADMODE_REPLACE, LOADMODE_EDL_CLIP, 0);
4144 edl->local_session->clip_title[0] = 0;
4145 // This is unique to backups since the path of the backup is different than the
4146 // path of the project.
4147 set_filename(edl->path);
4148 path_list.remove_all_objects();
4153 void MWindow::save_undo_data()
4155 if( stack.size() > 0 ) return;
4156 if( !preferences->perpetual_session ) return;
4157 char perpetual_path[BCTEXTLEN];
4158 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4159 File::get_config_path(), PERPETUAL_FILE);
4160 FILE *fp = fopen(perpetual_path,"w");
4166 void MWindow::load_undo_data()
4168 if( stack.size() > 0 ) return;
4169 if( !preferences->perpetual_session ) return;
4170 char perpetual_path[BCTEXTLEN];
4171 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4172 File::get_config_path(), PERPETUAL_FILE);
4173 FILE *fp = fopen(perpetual_path,"r");
4177 undo_after(_("perpetual load"), LOAD_ALL);
4181 void MWindow::remove_undo_data()
4183 if( stack.size() > 0 ) return;
4184 char perpetual_path[BCTEXTLEN];
4185 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4186 File::get_config_path(), PERPETUAL_FILE);
4187 ::remove(perpetual_path);
4190 int MWindow::copy_target(const char *path, const char *target)
4192 int ifd = ::open(path, O_RDONLY);
4194 eprintf("Cannot open asset: %s", path);
4198 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
4201 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
4202 char progress_title[BCTEXTLEN];
4203 sprintf(progress_title, _("Copying: %s\n"), target);
4204 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
4206 int64_t count = 0, len = -1;
4207 int bfrsz = 0x100000;
4208 uint8_t *bfr = new uint8_t[bfrsz];
4209 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
4210 if( len != ::write(ofd, bfr, len) ) {
4211 eprintf("Error writing: %s", target);
4214 if( progress.is_cancelled() ) {
4218 progress.update(count += len, 1);
4223 progress.stop_progress();
4225 eprintf("Error reading: %s", path);
4230 eprintf("Cannot create asset target: %s", target);
4235 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
4237 char target[BCTEXTLEN];
4239 const char *bp = real_path, *cp = bp;
4240 const char *lp = link_path, *np = lp;
4241 char *tp = target, *ep = tp+sizeof(target)-1, lch;
4242 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
4243 if( lch == '/' ) { np = lp; cp = bp; }
4245 while( tp<ep && *np ) {
4246 if( *np++ != '/' ) continue;
4247 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
4249 while( tp<ep && *cp ) *tp++ = *cp++;
4253 strcpy(target, real_path);
4254 if( symlink(target, link_path) ) {
4255 eprintf("Cannot create symlink: %s", link_path);
4261 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
4263 char dir_path[BCTEXTLEN];
4264 strcpy(dir_path, dir);
4266 fs.complete_path(dir_path);
4269 if( !stat(dir_path, &st) ) {
4270 if( !S_ISDIR(st.st_mode) ) {
4271 eprintf("Path exists and is not a directory\n%s", dir_path);
4276 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
4277 eprintf("Cannot create directory\n%s", dir_path);
4281 char *real_dir = realpath(dir_path, 0);
4282 strcpy(dir_path, real_dir);
4285 EDL *save_edl = new EDL;
4286 save_edl->create_objects();
4287 save_edl->copy_all(edl);
4289 char progress_title[BCTEXTLEN];
4290 sprintf(progress_title, _("Saving to %s:\n"), dir);
4291 int total_assets = save_edl->assets->total();
4292 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
4294 Asset *current = save_edl->assets->first;
4295 for( int i=0; !ret && current; ++i, current=NEXT ) {
4296 char *path = current->path;
4297 if( ::stat(path, &st) ) {
4298 eprintf("Asset not found: %s", path);
4301 char *real_path = realpath(path, 0);
4302 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
4303 char link_path[BCTEXTLEN];
4304 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
4306 if( strcmp(real_path, link_path) ) {
4307 if( !::lstat(link_path, &st) ) {
4309 ::remove(link_path);
4315 eprintf("copy/link to self, skippped: %s", path);
4319 if( save_mode == SAVE_PROJECT_COPY ) {
4320 if( copy_target(real_path, link_path) )
4324 link_target(real_path, link_path,
4325 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
4329 strcpy(path, link_path);
4331 if( progress->is_cancelled() ) break;
4332 progress->update(i);
4335 progress->stop_progress();
4338 char *cp = strrchr(dir_path,'/');
4339 char *bp = cp ? cp+1 : dir_path;
4340 char filename[BCTEXTLEN];
4341 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
4342 save_edl->set_path(filename);
4344 save_edl->save_xml(&file, filename);
4345 file.terminate_string();
4347 if( !file.write_to_file(filename) ) {
4348 char string[BCTEXTLEN];
4349 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
4350 gui->lock_window("SaveProject::run 2");
4351 gui->show_message(string);
4352 gui->unlock_window();
4353 gui->mainmenu->add_load(filename);
4356 eprintf(_("Couldn't open %s."), filename);
4358 save_edl->remove_user();
4361 gui->lock_window("MWindow::save_project");
4362 ArrayList<char*> filenames;
4363 filenames.append(filename);
4364 load_filenames(&filenames);
4365 gui->unlock_window();
4370 static inline int gcd(int m, int n)
4373 if( m < n ) { r = m; m = n; n = r; }
4374 while( (r = m % n) != 0 ) { m = n; n = r; }
4378 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4381 if(!width || !height) return 1;
4382 if( width == 720 && (height == 480 || height == 576) ) {
4383 w = 4; h = 3; return 0; // for NTSC and PAL
4385 double ar = (double)width / height;
4386 // square-ish pixels
4387 if( EQUIV(ar, 1.0000) ) return 0;
4388 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4389 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4390 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4391 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4392 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4393 int ww = width, hh = height;
4394 // numerator, denominator must be under mx
4395 int mx = 255, n = gcd(ww, hh);
4396 if( n > 1 ) { ww /= n; hh /= n; }
4397 // search near height in case extra/missing lines
4398 if( ww >= mx || hh >= mx ) {
4399 double err = height; // +/- 2 percent height
4400 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4401 int iw = width, ih = height+i;
4402 if( (n=gcd(iw, ih)) > 1 ) {
4403 int u = iw/n; if( u >= mx ) continue;
4404 int v = ih/n; if( v >= mx ) continue;
4405 double r = (double) u/v, er = fabs(ar-r);
4406 if( er >= err ) continue;
4407 err = er; ww = u; hh = v;
4416 void MWindow::reset_caches()
4418 frame_cache->remove_all();
4419 wave_cache->remove_all();
4420 audio_cache->remove_all();
4421 video_cache->remove_all();
4422 if( cwindow->playback_engine ) {
4423 if( cwindow->playback_engine->audio_cache )
4424 cwindow->playback_engine->audio_cache->remove_all();
4425 if( cwindow->playback_engine->video_cache )
4426 cwindow->playback_engine->video_cache->remove_all();
4428 for(int i = 0; i < vwindows.size(); i++) {
4429 VWindow *vwindow = vwindows[i];
4430 if( !vwindow->is_running() ) continue;
4431 if( !vwindow->playback_engine ) continue;
4432 if( vwindow->playback_engine->audio_cache )
4433 vwindow->playback_engine->audio_cache->remove_all();
4434 if( vwindow->playback_engine->video_cache )
4435 vwindow->playback_engine->video_cache->remove_all();
4439 void MWindow::remove_from_caches(Indexable *idxbl)
4441 frame_cache->remove_item(idxbl);
4442 wave_cache->remove_item(idxbl);
4443 if( gui->render_engine &&
4444 gui->render_engine_id == idxbl->id ) {
4445 delete gui->render_engine;
4446 gui->render_engine = 0;
4448 if( gui->resource_thread->render_engine_id == idxbl->id ) {
4449 gui->resource_thread->render_engine_id = -1;
4450 delete gui->resource_thread->render_engine;
4451 gui->resource_thread->render_engine = 0;
4453 if( !idxbl->is_asset ) return;
4454 Asset *asset = (Asset *)idxbl;
4455 audio_cache->delete_entry(asset);
4456 video_cache->delete_entry(asset);
4457 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4458 cwindow->playback_engine->audio_cache->delete_entry(asset);
4459 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4460 cwindow->playback_engine->video_cache->delete_entry(asset);
4461 for(int i = 0; i < vwindows.size(); i++) {
4462 VWindow *vwindow = vwindows[i];
4463 if( !vwindow->is_running() ) continue;
4464 if( !vwindow->playback_engine ) continue;
4465 if( vwindow->playback_engine->audio_cache )
4466 vwindow->playback_engine->audio_cache->delete_entry(asset);
4467 if( vwindow->playback_engine->video_cache )
4468 vwindow->playback_engine->video_cache->delete_entry(asset);
4470 for(int i = 0; i < zwindows.size(); i++) {
4471 ZWindow *zwindow = zwindows[i];
4472 if( !zwindow->is_running() ) continue;
4473 if( zwindow->zgui->playback_engine->audio_cache )
4474 zwindow->zgui->playback_engine->audio_cache->delete_entry(asset);
4475 if( zwindow->zgui->playback_engine->video_cache )
4476 zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
4480 void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
4481 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4483 awindow->gui->close_view_popup();
4485 // Remove from VWindow.
4487 for(int i = 0; i < drag_clips->total; i++) {
4488 for(int j = 0; j < vwindows.size(); j++) {
4489 VWindow *vwindow = vwindows[j];
4490 if( !vwindow->is_running() ) continue;
4491 if(drag_clips->get(i) == vwindow->get_edl()) {
4492 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4493 vwindow->delete_source(1, 1);
4494 vwindow->gui->unlock_window();
4501 for(int i = 0; i < drag_assets->size(); i++) {
4502 for(int j = 0; j < vwindows.size(); j++) {
4503 VWindow *vwindow = vwindows[j];
4504 if( !vwindow->is_running() ) continue;
4505 if(drag_assets->get(i) == vwindow->get_source()) {
4506 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4507 vwindow->delete_source(1, 1);
4508 vwindow->gui->unlock_window();
4513 for(int i = 0; i < drag_assets->total; i++) {
4514 Indexable *indexable = drag_assets->get(i);
4515 if(indexable->is_asset) remove_from_caches(indexable);
4518 if( delete_indexes ) {
4519 for(int i = 0; i < drag_assets->size(); i++) {
4520 Indexable *indexable = drag_assets->get(i);
4521 remove_indexfile(indexable);
4526 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4527 if(push_undo) undo_before();
4528 if(drag_assets) edl->remove_from_project(drag_assets);
4529 if(drag_clips) edl->remove_from_project(drag_clips);
4530 if(redraw) save_backup();
4531 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4535 gui->lock_window("MWindow::remove_assets_from_project 3");
4536 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4537 gui->unlock_window();
4539 // Removes from playback here
4540 sync_parameters(CHANGE_ALL);
4543 awindow->gui->async_update_assets();
4546 void MWindow::remove_assets_from_disk()
4548 remove_assets_from_project(1, 1, 1,
4549 session->drag_assets, session->drag_clips);
4552 for(int i = 0; i < session->drag_assets->total; i++)
4554 remove(session->drag_assets->get(i)->path);
4558 void MWindow::dump_plugins(FILE *fp)
4560 if( !plugindb ) return;
4561 for(int i = 0; i < plugindb->total; i++)
4563 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4564 " synth=%d transition=%d theme=%d %s\n",
4565 plugindb->get(i)->plugin_type,
4566 plugindb->get(i)->audio,
4567 plugindb->get(i)->video,
4568 plugindb->get(i)->realtime,
4569 plugindb->get(i)->multichannel,
4570 plugindb->get(i)->get_synthesis(),
4571 plugindb->get(i)->transition,
4572 plugindb->get(i)->theme,
4573 plugindb->get(i)->title);
4577 void MWindow::dump_edl(FILE *fp)
4583 void MWindow::dump_undo(FILE *fp)
4589 void MWindow::dump_exe(FILE *fp)
4591 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4592 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4594 int ret = -1, n = 100;
4595 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4596 exe_path[len] = 0; strcpy(proc_path, exe_path);
4599 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4602 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4603 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4604 struct tm *tm = localtime(&st.st_mtime);
4606 strftime(mtime, sizeof(mtime), "%F %T", tm);
4607 fprintf(fp,"mtime: %s\n", mtime);
4609 // people hit ctl-c waiting for this
4610 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4611 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4614 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4615 int64_t maxsz = 1024*pagsz;
4616 int64_t size = st.st_size, pos = 0;
4618 while( (bfrsz = size-pos) > 0 ) {
4619 if( bfrsz > maxsz ) bfrsz = maxsz;
4620 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4621 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4622 if( bfr == MAP_FAILED ) break;
4623 sha1.addBytes(bfr, bfrsz);
4628 ret = pos < size ? EIO : 0;
4629 fprintf(fp, "SHA1: ");
4630 uint8_t digest[20]; sha1.computeHash(digest);
4631 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4632 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4633 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4638 void MWindow::trap_hook(FILE *fp, void *vp)
4640 MWindow *mwindow = (MWindow *)vp;
4641 // fprintf(fp, "\nPLUGINS:\n");
4642 // mwindow->dump_plugins(fp);
4643 fprintf(fp, "\nEDL:\n");
4644 mwindow->dump_edl(fp);
4645 fprintf(fp, "\nUNDO:\n");
4646 mwindow->dump_undo(fp);
4647 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4648 mwindow->dump_exe(fp);
4656 int MWindow::save_defaults()
4658 gui->save_defaults(defaults);
4659 edl->save_defaults(defaults);
4660 session->save_defaults(defaults);
4661 preferences->save_defaults(defaults);
4663 for(int i = 0; i < plugin_guis->total; i++)
4665 // Pointer comparison
4666 plugin_guis->get(i)->save_defaults();
4668 awindow->save_defaults(defaults);
4674 int MWindow::run_script(FileXML *script)
4676 int result = 0, result2 = 0;
4677 while(!result && !result2)
4679 result = script->read_tag();
4682 if(script->tag.title_is("new_project"))
4684 // Run new in immediate mode.
4685 // gui->mainmenu->new_project->run_script(script);
4688 if(script->tag.title_is("record"))
4690 // Run record as a thread. It is a terminal command.
4692 // Will read the complete scipt file without letting record read it if not
4698 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4705 // ================================= synchronization
4708 int MWindow::interrupt_indexes()
4710 mainprogress->cancelled = 1;
4711 mainindexes->interrupt_build();
4717 void MWindow::next_time_format()
4719 switch(edl->session->time_format)
4721 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4722 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4723 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4724 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4725 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4726 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4727 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4730 time_format_common();
4733 void MWindow::prev_time_format()
4735 switch(edl->session->time_format)
4737 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4738 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4739 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4740 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4741 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4742 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4743 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4746 time_format_common();
4749 void MWindow::time_format_common()
4751 gui->lock_window("MWindow::next_time_format");
4752 gui->redraw_time_dependancies();
4755 char string[BCTEXTLEN], string2[BCTEXTLEN];
4756 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4757 gui->show_message(string);
4759 gui->unlock_window();
4763 int MWindow::set_filename(const char *filename)
4765 if( filename != session->filename )
4766 strcpy(session->filename, filename);
4767 if( filename != edl->path )
4768 strcpy(edl->path, filename);
4772 if(filename[0] == 0)
4774 gui->set_title(PROGRAM_NAME);
4779 char string[BCTEXTLEN], string2[BCTEXTLEN];
4780 dir.extract_name(string, filename);
4781 sprintf(string2, PROGRAM_NAME ": %s", string);
4782 gui->set_title(string2);
4795 int MWindow::set_loop_boundaries()
4797 double start = edl->local_session->get_selectionstart();
4798 double end = edl->local_session->get_selectionend();
4806 if(edl->tracks->total_length())
4809 end = edl->tracks->total_length();
4816 if(edl->local_session->loop_playback && start != end)
4818 edl->local_session->loop_start = start;
4819 edl->local_session->loop_end = end;
4830 int MWindow::reset_meters()
4832 cwindow->gui->lock_window("MWindow::reset_meters 1");
4833 cwindow->gui->meters->reset_meters();
4834 cwindow->gui->unlock_window();
4836 for(int j = 0; j < vwindows.size(); j++) {
4837 VWindow *vwindow = vwindows[j];
4838 if( !vwindow->is_running() ) continue;
4839 vwindow->gui->lock_window("MWindow::reset_meters 2");
4840 vwindow->gui->meters->reset_meters();
4841 vwindow->gui->unlock_window();
4844 lwindow->gui->lock_window("MWindow::reset_meters 3");
4845 lwindow->gui->panel->reset_meters();
4846 lwindow->gui->unlock_window();
4848 gui->lock_window("MWindow::reset_meters 4");
4849 gui->reset_meters();
4850 gui->unlock_window();
4855 void MWindow::resync_guis()
4859 gui->lock_window("MWindow::resync_guis");
4860 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4861 gui->unlock_window();
4863 cwindow->gui->lock_window("MWindow::resync_guis");
4864 cwindow->gui->resize_event(cwindow->gui->get_w(),
4865 cwindow->gui->get_h());
4866 int channels = edl->session->audio_channels;
4867 cwindow->gui->meters->set_meters(channels, 1);
4868 cwindow->gui->flush();
4869 cwindow->gui->unlock_window();
4871 for(int i = 0; i < vwindows.size(); i++) {
4872 VWindow *vwindow = vwindows[i];
4873 if( !vwindow->is_running() ) continue;
4874 vwindow->gui->lock_window("MWindow::resync_guis");
4875 vwindow->gui->resize_event(vwindow->gui->get_w(),
4876 vwindow->gui->get_h());
4877 vwindow->gui->meters->set_meters(channels, 1);
4878 vwindow->gui->flush();
4879 vwindow->gui->unlock_window();
4882 lwindow->gui->lock_window("MWindow::resync_guis");
4883 lwindow->gui->panel->set_meters(channels, 1);
4884 lwindow->gui->flush();
4885 lwindow->gui->unlock_window();
4888 if(((edl->session->output_w % 4) ||
4889 (edl->session->output_h % 4)) &&
4890 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4892 MainError::show_error(
4893 _("This project's dimensions are not multiples of 4 so\n"
4894 "it can't be rendered by OpenGL."));
4899 sync_parameters(CHANGE_ALL);
4902 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4904 File *file = new File;
4905 EDLSession *session = edl->session;
4906 double old_framerate = session->frame_rate;
4907 double old_samplerate = session->sample_rate;
4908 int old_auto_keyframes = session->auto_keyframes;
4909 session->auto_keyframes = 0;
4910 int result = file->open_file(preferences, asset, 1, 0);
4911 if( !result && delete_tracks > 0 )
4913 int video_layers = asset->get_video_layers();
4914 if( !result && asset->video_data && vstream < video_layers ) {
4915 // try to get asset up to date, may fail
4916 file->select_video_stream(asset, vstream);
4917 // either way use what was/is there.
4918 double framerate = asset->get_frame_rate();
4919 int width = asset->get_w();
4920 int height = asset->get_h();
4922 // must be multiple of 4 for opengl
4923 width = (width+3) & ~3; height = (height+3) & ~3;
4925 int driver = session->playback_config->vconfig->driver;
4926 int color_model = file->get_best_colormodel(asset, driver);
4927 // color_model = BC_CModels::is_yuv(color_model) ?
4928 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4929 // BC_CModels::is_float(color_model) ?
4930 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4931 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4932 // have alpha for now
4933 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4934 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4935 session->color_model = color_model;
4936 session->output_w = width;
4937 session->output_h = height;
4938 session->frame_rate = framerate;
4939 // not, asset->actual_width/actual_height
4940 asset->width = session->output_w;
4941 asset->height = session->output_h;
4942 asset->frame_rate = session->frame_rate;
4943 create_aspect_ratio(session->aspect_w, session->aspect_h,
4944 session->output_w, session->output_h);
4945 Track *track = edl->tracks->first;
4946 for( Track *next_track=0; track; track=next_track ) {
4947 next_track = track->next;
4948 if( track->data_type != TRACK_VIDEO ) continue;
4949 if( delete_tracks ) {
4950 Edit *edit = track->edits->first;
4951 for( Edit *next_edit=0; edit; edit=next_edit ) {
4952 next_edit = edit->next;
4953 if( edit->channel != vstream ||
4954 !edit->asset || !edit->asset->is_asset ||
4955 !asset->equivalent(*edit->asset,1,1,edl) )
4959 if( track->edits->first ) {
4960 track->track_w = edl->session->output_w;
4961 track->track_h = edl->session->output_h;
4963 else if( delete_tracks )
4964 edl->tracks->delete_track(track);
4967 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4969 if( !result && asset->audio_data && asset->channels > 0 ) {
4970 session->sample_rate = asset->get_sample_rate();
4971 int64_t channel_mask = 0;
4972 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4973 file->get_audio_for_video(vstream, astream, channel_mask);
4974 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4975 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4977 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4978 if( channels < 1 ) channels = 1;
4979 if( channels > 6 ) channels = 6;
4980 session->audio_tracks = session->audio_channels = channels;
4982 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4983 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4984 remap_audio(MWindow::AUDIO_1_TO_1);
4986 if( delete_tracks ) {
4987 Track *track = edl->tracks->first;
4988 for( Track *next_track=0; track; track=next_track ) {
4989 next_track = track->next;
4990 if( track->data_type != TRACK_AUDIO ) continue;
4991 Edit *edit = track->edits->first;
4992 for( Edit *next_edit=0; edit; edit=next_edit ) {
4993 next_edit = edit->next;
4994 if( !((1<<edit->channel) & channel_mask) ||
4995 !edit->asset || !edit->asset->is_asset ||
4996 !asset->equivalent(*edit->asset,1,1,edl) )
4999 if( !track->edits->first )
5000 edl->tracks->delete_track(track);
5004 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
5007 session->auto_keyframes = old_auto_keyframes;
5008 if( !result && delete_tracks > 0 ) {
5010 undo_after(_("select asset"), LOAD_ALL);
5016 int MWindow::select_asset(int vtrack, int delete_tracks)
5018 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
5020 track = edl->tracks->get(vtrack, TRACK_AUDIO);
5021 if( !track ) return 1;
5022 Edit *edit = track->edits->first;
5023 if( !edit ) return 1;
5024 Asset *asset = edit->asset;
5025 if( !asset || !asset->is_asset ) return 1;
5026 return select_asset(asset, edit->channel, 0, delete_tracks);
5029 void MWindow::dump_plugindb(FILE *fp)
5031 if( !plugindb ) return;
5032 for(int i = 0; i < plugindb->total; i++)
5033 plugindb->get(i)->dump(fp);
5036 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
5039 double unit_position = edl->local_session->get_selectionstart(1);
5040 unit_position = patch->track->to_units(unit_position, 0);
5042 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
5043 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5046 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
5049 double unit_position = edl->local_session->get_selectionstart(1);
5050 unit_position = patch->track->to_units(unit_position, 0);
5052 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
5053 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5056 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
5059 double unit_position = edl->local_session->get_selectionstart(1);
5060 unit_position = patch->track->to_units(unit_position, 0);
5062 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
5063 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5066 PatchGUI *MWindow::get_patchgui(Track *track)
5068 PatchGUI *patchgui = 0;
5069 TimelinePane **panes = gui->pane;
5070 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
5071 if( !panes[i] ) continue;
5072 PatchBay *patchbay = panes[i]->patchbay;
5073 if( !patchbay ) continue;
5074 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
5075 if( patchbay->patches.values[j]->track == track )
5076 patchgui = patchbay->patches.values[j];