3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "aboutprefs.h"
25 #include "audioalsa.h"
27 #include "awindowgui.h"
29 #include "batchrender.h"
30 #include "bccmodels.h"
31 #include "bcdisplayinfo.h"
32 #include "bcprogressbox.h"
33 #include "bcsignals.h"
40 #include "channeldb.h"
41 #include "channelinfo.h"
44 #include "commercials.h"
45 #include "confirmsave.h"
47 #include "cplayback.h"
49 #include "cwindowgui.h"
51 #include "cwindowtool.h"
53 #include "devicedvbinput.inc"
54 #include "dvdcreate.h"
55 #include "editpanel.h"
57 #include "edlsession.h"
59 #include "fileformat.h"
61 #include "filesystem.h"
63 #include "floatautos.h"
64 #include "framecache.h"
66 #include "gwindowgui.h"
67 #include "keyframegui.h"
68 #include "indexfile.h"
70 #include "interlacemodes.h"
72 #include "levelwindowgui.h"
73 #include "levelwindow.h"
74 #include "loadfile.inc"
75 #include "localsession.h"
76 #include "maincursor.h"
77 #include "mainerror.h"
78 #include "mainindexes.h"
80 #include "mainprogress.h"
81 #include "mainsession.h"
84 #include "mixersalign.h"
86 #include "mwindowgui.h"
91 #include "playback3d.h"
92 #include "playbackengine.h"
94 #include "pluginserver.h"
95 #include "pluginset.h"
96 #include "preferences.h"
99 #include "recordmonitor.h"
100 #include "recordlabel.h"
101 #include "removefile.h"
103 #include "resourcethread.h"
104 #include "savefile.inc"
105 #include "samplescroll.h"
108 #include "sighandler.h"
109 #include "splashgui.h"
110 #include "statusbar.h"
112 #include "threadloader.h"
114 #include "timelinepane.h"
115 #include "tipwindow.h"
116 #include "trackcanvas.h"
118 #include "tracking.h"
119 #include "trackscroll.h"
121 #include "transition.h"
122 #include "transportque.h"
125 #include "versioninfo.h"
127 #include "videodevice.inc"
128 #include "videowindow.h"
129 #include "vplayback.h"
130 #include "vwindowgui.h"
132 #include "wavecache.h"
138 #include "zwindowgui.h"
139 #include "exportedl.h"
141 #include "defaultformats.h"
142 #include "ntsczones.h"
149 #include <sys/types.h>
150 #include <sys/stat.h>
151 #include <sys/time.h>
152 #include <sys/mman.h>
153 #include <sys/file.h>
164 // Hack for libdv to remove glib dependancy
167 // g_log (const char *log_domain,
169 // const char *format,
175 // g_logv (const char *log_domain,
177 // const char *format,
185 extern long cin_timezone;
187 ArrayList<PluginServer*>* MWindow::plugindb = 0;
188 Commercials* MWindow::commercials = 0;
194 run_lock = new Mutex("MWindow::run_lock");
195 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
196 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
197 vwindows_lock = new Mutex("MWindow::vwindows_lock");
198 zwindows_lock = new Mutex("MWindow::zwindows_lock");
199 brender_lock = new Mutex("MWindow::brender_lock");
200 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
205 undo_command = COMMAND_NONE;
209 commercial_active = 0;
221 strcpy(cin_lang,"en");
222 channeldb_buz = new ChannelDB;
223 channeldb_v4l2jpeg = new ChannelDB;
226 keyframe_threads = 0;
254 // Need to delete brender temporary here.
257 run_lock->lock("MWindow::~MWindow");
259 //printf("MWindow::~MWindow %d\n", __LINE__);
260 if( wwindow && wwindow->is_running() )
261 wwindow->close_window();
262 if( twindow && twindow->is_running() )
263 twindow->close_window();
264 gui->remote_control->deactivate();
267 gui->channel_info->stop();
269 delete beeper; beeper = 0;
270 delete redraw_tracks; redraw_tracks = 0;
271 delete create_bd; create_bd = 0;
272 delete create_dvd; create_dvd = 0;
274 delete shuttle; shuttle = 0;
277 delete wintv; wintv = 0;
280 delete x10tv; x10tv = 0;
282 delete batch_render; batch_render = 0;
283 delete convert_render; convert_render = 0;
284 delete render; render = 0;
285 delete mixers_align; mixers_align = 0;
287 if( commercials && !commercials->remove_user() ) commercials = 0;
289 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
290 // Save defaults for open plugins
291 plugin_gui_lock->lock("MWindow::~MWindow");
292 for(int i = 0; i < plugin_guis->size(); i++) {
293 plugin_guis->get(i)->hide_gui();
294 delete_plugin(plugin_guis->get(i));
296 plugin_gui_lock->unlock();
297 hide_keyframe_guis();
300 // Give up and go to a movie
301 // cant run valgrind if this is used
303 gui->del_keyboard_listener(
304 (int (BC_WindowBase::*)(BC_WindowBase *))
305 &MWindowGUI::keyboard_listener);
308 // release the hounds
309 if( awindow && awindow->gui ) awindow->gui->close(0);
310 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
311 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
312 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
313 vwindows.remove_all_objects();
314 zwindows.remove_all_objects();
316 if( awindow ) awindow->join();
317 if( cwindow ) cwindow->join();
318 if( lwindow ) lwindow->join();
319 if( gwindow ) gwindow->join();
322 // one at a time, or nouveau chokes
323 #define close_gui(win) if( win ) { \
324 if( win->gui ) win->gui->close(0); \
330 vwindows.remove_all_objects();
331 zwindows.remove_all_objects();
335 dead_plugins->remove_all_objects();
336 // must delete theme before destroying plugindb
337 // theme destructor will be deleted by delete_plugins
338 delete theme; theme = 0;
341 keyframe_threads->remove_all_objects();
342 colormodels.remove_all_objects();
343 delete awindow; awindow = 0;
344 delete lwindow; lwindow = 0;
345 delete twindow; twindow = 0;
346 delete wwindow; wwindow = 0;
347 delete gwindow; gwindow = 0;
348 delete cwindow; cwindow = 0;
350 delete mainindexes; mainindexes = 0;
351 delete mainprogress; mainprogress = 0;
352 // delete the caches after the assets
353 if( audio_cache ) { audio_cache->remove_user(); audio_cache = 0; }
354 if( video_cache ) { video_cache->remove_user(); video_cache = 0; }
355 delete frame_cache; frame_cache = 0;
356 delete wave_cache; wave_cache = 0;
357 delete plugin_guis; plugin_guis = 0;
358 delete dead_plugins; dead_plugins = 0;
359 delete keyframe_threads; keyframe_threads = 0;
360 delete undo; undo = 0;
361 delete preferences; preferences = 0;
362 delete exportedl; exportedl = 0;
363 delete session; session = 0;
364 delete defaults; defaults = 0;
365 delete assets; assets = 0;
366 delete splash_window; splash_window = 0;
367 if( !edl->Garbage::remove_user() ) edl = 0;
368 delete channeldb_buz;
369 delete channeldb_v4l2jpeg;
370 // This must be last thread to exit
371 delete playback_3d; playback_3d = 0;
372 delete dead_plugin_lock;
373 delete plugin_gui_lock;
374 delete vwindows_lock;
375 delete zwindows_lock;
377 delete keyframe_gui_lock;
378 colormodels.remove_all_objects();
379 interlace_project_modes.remove_all_objects();
380 interlace_asset_modes.remove_all_objects();
381 sighandler->terminate();
392 void MWindow::init_error()
394 MainError::init_error(this);
397 void MWindow::finit_error()
399 MainError::finit_error();
402 void MWindow::create_defaults_path(char *string, const char *config_file)
404 // set the .bcast path
407 sprintf(string, "%s/", File::get_config_path());
408 fs.complete_path(string);
409 if(!fs.is_dir(string))
410 fs.create_dir(string);
413 strcat(string, config_file);
415 const char *MWindow::default_std()
417 char buf[BCTEXTLEN], *p = 0;
419 int fd = open(TIMEZONE_NAME, O_RDONLY);
421 int l = read(fd, buf, sizeof(buf)-1);
424 if( buf[l-1] == '\n' ) --l;
430 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
433 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
434 p += strlen(ZONEINFO_STR);
439 for( int i=0; ntsc_zones[i]; ++i ) {
440 if( !strcmp(ntsc_zones[i], p) )
447 for( int i=0; ntsc_zones[i]; ++i ) {
448 if( !strcmp(ntsc_zones[i], p) )
453 // cin_timezone: Seconds west of UTC. 240sec/deg
454 double tz_deg = -cin_timezone / 240.;
455 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
456 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
459 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
461 struct formatpresets *fpr;
463 for(fpr = &format_presets[0]; fpr->name; fpr++)
465 if(strcmp(_(fpr->name), preset) == 0)
467 session->audio_channels = fpr->audio_channels;
468 session->audio_tracks = fpr->audio_tracks;
469 session->sample_rate = fpr->sample_rate;
470 session->video_channels = fpr->video_channels;
471 session->video_tracks = fpr->video_tracks;
472 session->frame_rate = fpr->frame_rate;
473 session->output_w = fpr->output_w;
474 session->output_h = fpr->output_h;
475 session->aspect_w = fpr->aspect_w;
476 session->aspect_h = fpr->aspect_h;
477 session->interlace_mode = fpr->interlace_mode;
478 session->color_model = fpr->color_model;
484 const char *MWindow::get_preset_name(int index)
486 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
488 return _(format_presets[index].name);
492 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
494 char path[BCTEXTLEN];
495 // Use user supplied path
497 strcpy(path, config_path);
499 create_defaults_path(path, CONFIG_FILE);
502 defaults = new BC_Hash(path);
507 void MWindow::check_language()
509 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
510 const char *env_lang = getenv("LANGUAGE");
511 if( !env_lang ) env_lang = getenv("LC_ALL");
512 if( !env_lang ) env_lang = getenv("LANG");
514 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
515 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
516 env_lang = curr_lang;
518 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
519 defaults->get("LAST_LANG",last_lang);
520 if( strcmp(env_lang,last_lang)) {
521 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
522 defaults->update("LAST_LANG",env_lang);
523 char plugin_path[BCTEXTLEN];
524 create_defaults_path(plugin_path, PLUGIN_FILE);
525 ::remove(plugin_path);
526 char ladspa_path[BCTEXTLEN];
527 create_defaults_path(ladspa_path, LADSPA_FILE);
528 ::remove(ladspa_path);
531 if( strlen(env_lang) > 1 &&
532 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
533 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
536 strcpy(cin_lang, "en");
539 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
541 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
543 const char *dp = plug_dir;
544 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
545 bp = !*dp && *bp == '/' ? bp+1 : base_path;
551 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir)
555 fseek(fp, 0, SEEK_SET);
557 char index_line[BCTEXTLEN];
558 int index_version = -1, len = strlen(plugin_dir);
559 if( !fgets(index_line, BCTEXTLEN, fp) ||
560 sscanf(index_line, "%d", &index_version) != 1 ||
561 index_version != PLUGIN_FILE_VERSION ||
562 !fgets(index_line, BCTEXTLEN, fp) ||
563 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
564 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
566 ArrayList<PluginServer*> plugins;
567 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
568 if( index_line[0] == ';' ) continue;
569 if( index_line[0] == '#' ) continue;
570 int type = PLUGIN_TYPE_UNKNOWN;
571 char path[BCTEXTLEN], title[BCTEXTLEN];
573 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
576 PluginServer *server = 0;
578 case PLUGIN_TYPE_BUILTIN:
579 case PLUGIN_TYPE_EXECUTABLE:
580 case PLUGIN_TYPE_LADSPA: {
581 char plugin_path[BCTEXTLEN]; struct stat st;
582 sprintf(plugin_path, "%s/%s", plugin_dir, path);
583 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
586 server = new PluginServer(mwindow, plugin_path, type);
588 case PLUGIN_TYPE_FFMPEG: {
589 server = new_ffmpeg_server(mwindow, path);
591 case PLUGIN_TYPE_LV2: {
592 server = new_lv2_server(mwindow, path);
595 if( !server ) continue;
596 plugins.append(server);
597 // Create plugin server from index entry
598 server->set_title(title);
599 if( server->read_table(index_line) ) {
605 ret = check_plugin_index(plugins, plugin_dir, ".");
608 add_plugins(plugins);
610 plugins.remove_all_objects();
615 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
616 const char *plug_dir, const char *plug_path)
618 char plugin_path[BCTEXTLEN];
619 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
621 fs.set_filter( "[*.plugin][*.so]" );
622 if( fs.update(plugin_path) )
625 for( int i=0; i<fs.dir_list.total; ++i ) {
626 char fs_path[BCTEXTLEN];
627 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
628 if( fs.is_dir(fs_path) ) {
629 get_plugin_path(plugin_path, plug_dir, fs_path);
630 if( check_plugin_index(plugins, plug_dir, plugin_path) )
633 else if( !plugin_exists(fs_path, plugins) )
640 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
643 plugindb = new ArrayList<PluginServer*>;
645 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
646 create_defaults_path(index_path, PLUGIN_FILE);
647 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
648 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
649 FILE *fp = fopen(index_path,"a+");
651 fprintf(stderr,_("MWindow::init_plugins: "
652 "can't open plugin index: %s\n"), index_path);
655 int fd = fileno(fp), ret = -1;
656 if( !flock(fd, LOCK_EX) ) {
657 fseek(fp, 0, SEEK_SET);
658 ret = load_plugin_index(mwindow, fp, plugin_path);
662 fseek(fp, 0, SEEK_SET);
663 printf("init plugin index: %s\n", plugin_path);
664 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
665 fprintf(fp, "%s\n", plugin_path);
666 init_plugin_index(mwindow, preferences, fp, plugin_path);
667 init_ffmpeg_index(mwindow, preferences, fp);
668 init_lv2_index(mwindow, preferences, fp);
669 fseek(fp, 0, SEEK_SET);
670 ret = load_plugin_index(mwindow, fp, plugin_path);
673 fprintf(stderr,_("MWindow::init_plugins: "
674 "can't %s plugin index: %s\n"),
675 ret>0 ? _("create") : _("lock"), index_path);
681 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
684 char *path = getenv("LADSPA_PATH");
685 char ladspa_path[BCTEXTLEN];
687 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
690 for( int len=0; *path; path+=len ) {
691 char *cp = strchr(path,':');
692 len = !cp ? strlen(path) : cp-path;
693 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
694 memcpy(plugin_path, path, len); plugin_path[len] = 0;
696 char *plugin_dir = FileSystem::basepath(plugin_path);
697 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
698 create_defaults_path(index_path, LADSPA_FILE);
699 cp = index_path + strlen(index_path);
700 for( char *bp=plugin_path; *bp!=0; ++bp )
701 *cp++ = *bp=='/' ? '_' : *bp;
703 FILE *fp = fopen(index_path,"a+");
705 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
706 "can't open ladspa plugin index: %s\n"), index_path);
709 int fd = fileno(fp), ret = -1;
710 if( !flock(fd, LOCK_EX) ) {
711 fseek(fp, 0, SEEK_SET);
712 ret = load_plugin_index(mwindow, fp, plugin_path);
716 fseek(fp, 0, SEEK_SET);
717 init_ladspa_index(mwindow, preferences, fp, plugin_path);
718 fseek(fp, 0, SEEK_SET);
719 ret = load_plugin_index(mwindow, fp, plugin_path);
722 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
723 "can't %s ladspa plugin index: %s\n"),
724 ret>0 ? _("create") : _("lock"), index_path);
732 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
733 FILE *fp, const char *plugin_dir)
735 int idx = PLUGIN_IDS;
737 for( int i=0; i<plugindb->size(); ++i ) {
738 PluginServer *server = plugindb->get(i);
739 if( server->dir_idx >= idx )
740 idx = server->dir_idx+1;
743 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
746 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
747 const char *plug_dir, const char *plug_path, int &idx)
749 char plugin_path[BCTEXTLEN];
750 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
752 fs.set_filter( "[*.plugin][*.so][*.dll]" );
753 int result = fs.update(plugin_path);
754 if( result || !fs.dir_list.total ) return;
757 for( int i=0; i<fs.dir_list.total; ++i ) {
758 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
759 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
760 get_plugin_path(path, plug_dir, fs_path);
761 if( fs.is_dir(fs_path) ) {
762 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
765 if( plugin_exists(path) ) continue;
767 if( stat(fs_path, &st) ) continue;
768 int64_t mtime = st.st_mtime;
769 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
770 result = server.open_plugin(1, preferences, 0, 0);
772 server.write_table(fp, path, vis_id, mtime);
773 server.close_plugin();
775 else if( result == PLUGINSERVER_IS_LAD ) {
778 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
779 ladspa.set_lad_index(lad_index++);
780 result = ladspa.open_plugin(1, preferences, 0, 0);
782 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
783 ladspa.close_plugin();
789 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
791 for( int i=0; i<plugins.size(); ++i )
792 plugindb->append(plugins[i]);
793 plugins.remove_all();
796 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
798 const char *dat_path = File::get_cindat_path();
799 char msg_path[BCTEXTLEN];
801 if( BC_Resources::language[0] ) {
802 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
804 fp = fopen(msg_path, "r");
807 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
809 fp = fopen(msg_path, "r");
812 char text[BCTEXTLEN];
813 char *tp = text, *ep = tp + sizeof(text)-1;
814 char title[BCTEXTLEN];
819 char line[BCTEXTLEN], *cp = line;
820 if( fgets(line,sizeof(line)-1,fp) ) {
821 if( *cp == '#' ) continue;
822 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
825 if( tp > text && *--tp == '\n' ) *tp = 0;
827 int idx = plugins.size();
828 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
830 delete [] plugins[idx]->tip;
831 plugins[idx]->tip = cstrdup(text);
835 if( done > 0 ) break;
837 char *dp = strchr(cp, ':');
839 printf("plugin tips: error on line %d\n", no);
843 while( cp < dp ) *bp++ = *cp++;
848 while( *cp == ' ' || *cp == '\t' ) ++cp;
849 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
854 void MWindow::delete_plugins()
856 plugindb->remove_all_objects();
861 void MWindow::search_plugindb(int do_audio,
866 ArrayList<PluginServer*> &results)
869 for(int i = 0; i < MWindow::plugindb->total; i++)
871 PluginServer *current = MWindow::plugindb->get(i);
873 if(current->audio == do_audio &&
874 current->video == do_video &&
875 (current->realtime == is_realtime || is_realtime < 0) &&
876 current->transition == is_transition &&
877 current->theme == is_theme)
878 results.append(current);
881 // Alphabetize list by title
887 for(int i = 0; i < results.total - 1; i++)
889 PluginServer *value1 = results[i];
890 PluginServer *value2 = results[i + 1];
891 if(strcmp(_(value1->title), _(value2->title)) > 0)
895 results[i + 1] = value1;
901 PluginServer* MWindow::scan_plugindb(char *title,
906 // printf("MWindow::scan_plugindb data_type < 0\n");
910 for(int i = 0; i < plugindb->total; i++)
912 PluginServer *server = plugindb->get(i);
914 !strcasecmp(server->title, title) &&
916 (data_type == TRACK_AUDIO && server->audio) ||
917 (data_type == TRACK_VIDEO && server->video)))
918 return plugindb->get(i);
923 // repair session files with xlated plugin titles
924 void MWindow::fix_plugin_title(char *title)
926 for(int i = 0; i < plugindb->total; i++) {
927 PluginServer *server = plugindb->get(i);
928 if( !server->title ) continue;
929 const char *server_title = server->title;
930 if( !bstrcasecmp(title, _(server_title)) ) {
931 strcpy(title, server_title);
937 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
939 for( int i=0; i<plugins.size(); ++i )
940 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
944 int MWindow::plugin_exists(char *plugin_path)
946 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
949 void MWindow::remove_plugin_index()
951 char index_path[BCTEXTLEN];
952 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
953 ::remove(index_path);
956 void MWindow::init_preferences()
958 preferences = new Preferences;
959 preferences->load_defaults(defaults);
960 File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
961 session = new MainSession(this);
962 session->load_defaults(defaults);
963 // set x11_host, screens, window_config
964 screens = session->set_default_x11_host();
965 BC_Signals::set_trap_hook(trap_hook, this);
966 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
967 BC_Signals::set_catch_intr(preferences->trap_sigintr);
968 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
969 BC_Trace::enable_locks();
972 BC_Trace::disable_locks();
974 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
975 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
976 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
977 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
980 void MWindow::clean_indexes()
985 int oldest_item = -1;
987 char string[BCTEXTLEN];
988 char string2[BCTEXTLEN];
990 // Delete extra indexes
991 fs.set_filter("*.idx");
992 fs.complete_path(preferences->index_directory);
993 fs.update(preferences->index_directory);
994 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
996 // Eliminate directories
1001 for(int i = 0; i < fs.dir_list.total && !result; i++)
1003 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1004 if(fs.is_dir(string))
1006 delete fs.dir_list[i];
1007 fs.dir_list.remove_number(i);
1012 total_excess = fs.dir_list.total - preferences->index_count;
1014 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
1015 while(total_excess > 0)
1018 for(int i = 0; i < fs.dir_list.total; i++)
1020 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1022 if(i == 0 || fs.get_date(string) <= oldest)
1024 oldest = fs.get_date(string);
1029 if(oldest_item >= 0)
1031 // Remove index file
1032 fs.join_names(string,
1033 preferences->index_directory,
1034 fs.dir_list[oldest_item]->name);
1035 //printf("MWindow::clean_indexes 1 %s\n", string);
1037 perror("delete_indexes");
1038 delete fs.dir_list[oldest_item];
1039 fs.dir_list.remove_number(oldest_item);
1041 // Remove table of contents if it exists
1042 strcpy(string2, string);
1043 char *ptr = strrchr(string2, '.');
1046 //printf("MWindow::clean_indexes 2 %s\n", string2);
1047 sprintf(ptr, ".toc");
1049 sprintf(ptr, ".mkr");
1058 void MWindow::init_awindow()
1060 awindow = new AWindow(this);
1061 awindow->create_objects();
1064 void MWindow::init_gwindow()
1066 gwindow = new GWindow(this);
1067 gwindow->create_objects();
1070 void MWindow::init_tipwindow()
1072 TipWindow::load_tips(cin_lang);
1074 twindow = new TipWindow(this);
1078 void MWindow::show_warning(int *do_warning, const char *text)
1080 if( do_warning && !*do_warning ) return;
1082 wwindow = new WWindow(this);
1083 wwindow->show_warning(do_warning, text);
1086 int MWindow::wait_warning()
1088 return wwindow->wait_result();
1091 void MWindow::init_theme()
1096 PluginServer *theme_plugin = 0;
1097 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1098 if( plugindb->get(i)->theme &&
1099 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1100 theme_plugin = plugindb->get(i);
1104 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1105 preferences->theme);
1107 const char *default_theme = DEFAULT_THEME;
1108 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1109 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1111 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1112 if( plugindb->get(i)->theme &&
1113 !strcasecmp(default_theme, plugindb->get(i)->title) )
1114 theme_plugin = plugindb->get(i);
1119 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1123 PluginServer *plugin = new PluginServer(*theme_plugin);
1124 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1125 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1126 theme_plugin->title);
1130 theme = plugin->new_theme();
1131 theme->mwindow = this;
1132 strcpy(theme->path, plugin->path);
1135 // Load default images & settings
1136 theme->Theme::initialize();
1137 // Load user images & settings
1138 theme->initialize();
1139 // Create menus with user colors
1140 theme->build_menus();
1143 theme->sort_image_sets();
1144 theme->check_used();
1145 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1148 void MWindow::init_3d()
1150 playback_3d = new Playback3D(this);
1151 playback_3d->create_objects();
1154 void MWindow::init_edl()
1157 edl->create_objects();
1158 fill_preset_defaults(default_standard, edl->session);
1159 edl->load_defaults(defaults);
1160 edl->session->brender_start = edl->session->brender_end = 0;
1161 edl->create_default_tracks();
1162 edl->tracks->update_y_pixels(theme);
1165 void MWindow::init_compositor()
1167 cwindow = new CWindow(this);
1168 cwindow->create_objects();
1171 void MWindow::init_levelwindow()
1173 lwindow = new LevelWindow(this);
1174 lwindow->create_objects();
1177 VWindow *MWindow::get_viewer(int start_it, int idx)
1179 vwindows_lock->lock("MWindow::get_viewer");
1180 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1181 if( !vwindow ) idx = vwindows.size();
1182 while( !vwindow && --idx >= 0 ) {
1183 VWindow *vwin = vwindows[idx];
1184 if( !vwin->is_running() || !vwin->get_edl() )
1188 vwindow = new VWindow(this);
1189 vwindow->load_defaults();
1190 vwindow->create_objects();
1191 vwindows.append(vwindow);
1193 vwindows_lock->unlock();
1194 if( start_it ) vwindow->start();
1198 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1200 zwindows_lock->lock("MWindow::get_mixer");
1201 if( !mixer ) mixer = edl->mixers.new_mixer();
1202 ZWindow *zwindow = 0;
1203 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1204 ZWindow *zwdw = zwindows[i];
1205 if( zwdw->running() ) continue;
1206 if( zwdw->idx >= 0 ) continue;
1207 zwindow = zwindows[i];
1210 zwindows.append(zwindow = new ZWindow(this));
1211 zwindow->idx = mixer->idx;
1212 zwindows_lock->unlock();
1216 ZWindow *MWindow::get_mixer(int idx)
1218 ZWindow *zwindow = 0;
1219 zwindows_lock->lock("MWindow::get_mixer");
1220 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1221 ZWindow *zwdw = zwindows[i];
1222 if( !zwdw->running() ) continue;
1223 if( zwdw->idx != idx ) continue;
1224 zwindow = zwindows[i];
1226 zwindows_lock->unlock();
1230 void MWindow::close_mixer(ZWindow *zwindow)
1232 zwindows_lock->lock("MWindow::close_mixer 0");
1233 if( session->selected_zwindow >= 0 ) {
1234 int i = zwindows.number_of(zwindow);
1235 if( i >= 0 && i < session->selected_zwindow )
1236 --session->selected_zwindow;
1237 else if( i == session->selected_zwindow )
1238 session->selected_zwindow = -1;
1240 zwindows_lock->unlock();
1241 gui->lock_window("MWindow::close_mixer 1");
1242 gui->update_mixers(0, -1);
1243 gui->unlock_window();
1246 void MWindow::start_mixer()
1249 ZWindow *zwindow = get_mixer(mixer);
1250 const char *title = 0;
1252 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1253 PatchGUI *patchgui = get_patchgui(track);
1254 if( !patchgui || !patchgui->mixer ) continue;
1255 mixer->mixer_ids.append(track->get_mixer_id());
1256 if( !title ) title = track->title;
1259 session->selected_zwindow = -1;
1260 gui->lock_window("MWindow::start_mixer");
1261 gui->update_mixers(0, 0);
1262 gui->unlock_window();
1264 zwindow->set_title(title);
1269 int MWindow::mixer_track_active(Track *track)
1271 int i = session->selected_zwindow;
1272 if( i < 0 || i >= zwindows.size() ) return 0;
1273 ZWindow *zwindow = zwindows[i];
1274 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1275 if( !mixer ) return 0;
1276 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1277 return n >= 0 ? 1 : 0;
1280 void MWindow::update_mixer_tracks()
1282 zwindows_lock->lock("MixPatch::handle_event");
1283 int i = session->selected_zwindow;
1284 if( i >= 0 && i < zwindows.size() ) {
1285 ZWindow *zwindow = zwindows[i];
1286 zwindow->update_mixer_ids();
1288 zwindows_lock->unlock();
1291 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1292 int use_inout, int toggle_audio, int loop_play, float speed)
1294 zwindows_lock->lock("MWindow::handle_mixers");
1295 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1296 ZWindow *zwindow = zwindows[vidx];
1297 if( zwindow->idx < 0 ) continue;
1298 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1299 if( !mixer || !mixer->mixer_ids.size() ) continue;
1301 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1302 if( track->data_type != TRACK_VIDEO ) continue;
1303 int mixer_id = track->get_mixer_id();
1304 k = mixer->mixer_ids.size();
1305 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1307 if( k < 0 ) continue;
1308 EDL *mixer_edl = new EDL(this->edl);
1309 mixer_edl->create_objects();
1310 mixer_edl->copy_all(edl);
1311 mixer_edl->remove_vwindow_edls();
1312 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1313 k = mixer->mixer_ids.size();
1314 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1317 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1320 track->armed = track->play = 0;
1322 zwindow->change_source(mixer_edl);
1323 zwindow->handle_mixer(command, 0,
1324 use_inout, toggle_audio, loop_play, speed);
1326 zwindows_lock->unlock();
1329 void MWindow::refresh_mixers(int dir)
1331 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1332 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1335 void MWindow::stop_mixers()
1337 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1338 ZWindow *zwindow = zwindows[vidx];
1339 if( zwindow->idx < 0 ) continue;
1340 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1344 void MWindow::close_mixers(int result)
1346 ArrayList<ZWindow*> closed;
1347 zwindows_lock->lock("MWindow::close_mixers");
1348 for( int i=zwindows.size(); --i>=0; ) {
1349 ZWindow *zwindow = zwindows[i];
1350 if( zwindow->idx < 0 ) continue;
1352 ZWindowGUI *zgui = zwindow->zgui;
1353 zgui->lock_window("MWindow::select_zwindow 0");
1354 zgui->set_done(result);
1355 zgui->unlock_window();
1356 closed.append(zwindow);
1358 zwindows_lock->unlock();
1359 for( int i=0; i<closed.size(); ++i ) {
1360 ZWindow *zwindow = closed[i];
1365 ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
1367 ArrayList<Indexable*> new_assets;
1368 new_assets.append(indexable);
1369 Track *track = edl->tracks->last;
1370 load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
1371 track = !track ? edl->tracks->first : track->next;
1373 ZWindow *zwindow = get_mixer(mixer);
1375 track->play = track->armed = 0;
1376 if( track->data_type == TRACK_VIDEO ) {
1377 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1379 mixer->mixer_ids.append(track->get_mixer_id());
1380 track = track->next;
1382 if( indexable->is_asset ) {
1383 char *path = indexable->path;
1384 char *tp = strrchr(path, '/');
1385 if( !tp ) tp = path; else ++tp;
1386 zwindow->set_title(tp);
1389 char *title = ((EDL*)indexable)->local_session->clip_title;
1390 zwindow->set_title(title);
1395 void MWindow::create_mixers(double position)
1397 if( !session->drag_assets->size() &&
1398 !session->drag_clips->size() ) return;
1402 ArrayList<ZWindow *>new_mixers;
1404 for( int i=0; i<session->drag_assets->size(); ++i ) {
1405 Indexable *indexable = session->drag_assets->get(i);
1406 if( !indexable->have_video() ) continue;
1407 ZWindow *zwindow = create_mixer(indexable, position);
1408 new_mixers.append(zwindow);
1410 for( int i=0; i<session->drag_clips->size(); ++i ) {
1411 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1412 if( !indexable->have_video() ) continue;
1413 ZWindow *zwindow = create_mixer(indexable, position);
1414 new_mixers.append(zwindow);
1418 for( int i=0; i<new_mixers.size(); ++i )
1419 new_mixers[i]->start();
1423 undo_after(_("create mixers"), LOAD_ALL);
1425 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1426 sync_parameters(CHANGE_ALL);
1429 void MWindow::open_mixers()
1431 for( int i=0; i<edl->mixers.size(); ++i ) {
1432 Mixer *mixer = edl->mixers[i];
1433 ZWindow *zwindow = get_mixer(mixer);
1434 zwindow->set_title(mixer->title);
1440 int MWindow::select_zwindow(ZWindow *zwindow)
1442 int ret = 0, n = zwindows.number_of(zwindow);
1443 if( session->selected_zwindow != n ) {
1444 session->selected_zwindow = n;
1445 for( int i=0; i<zwindows.size(); ++i ) {
1446 ZWindow *zwindow = zwindows[i];
1447 if( zwindow->idx < 0 ) continue;
1448 ZWindowGUI *zgui = zwindow->zgui;
1449 zgui->lock_window("MWindow::select_zwindow 0");
1450 zwindow->highlighted = i == n ? 1 : 0;
1451 if( zgui->draw_overlays() )
1452 zgui->canvas->get_canvas()->flash(1);
1453 zgui->unlock_window();
1456 gui->lock_window("MWindow::select_window 1");
1457 gui->update_mixers(0, -1);
1458 gui->unlock_window();
1463 void MWindow::tile_mixers()
1466 for( int i=0; i<zwindows.size(); ++i ) {
1467 ZWindow *zwindow = zwindows[i];
1468 if( zwindow->idx < 0 ) continue;
1472 int zn = ceil(sqrt(nz));
1473 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1474 int y1 = 1, y2 = gui->get_y();
1475 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1476 if( x1 < 0 ) x1 = 0;
1477 if( y1 < 0 ) y1 = 0;
1478 if( x2 > rw ) x2 = rw;
1479 if( y2 > rh ) y2 = rh;
1480 int dx = x2 - x1, dy = y2 - y1;
1482 int lt = BC_DisplayInfo::get_left_border();
1483 int top = BC_DisplayInfo::get_top_border();
1484 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1485 int bh = top + BC_DisplayInfo::get_bottom_border();
1486 int zx = 0, zy = 0; // window origins
1487 int mw = xS(10+10), mh = yS(10+10); // canvas margins
1488 int rsz = 0, n = 0, dz = 0;
1489 int ow = edl->session->output_w, oh = edl->session->output_h;
1490 for( int i=0; i<zwindows.size(); ++i ) {
1491 ZWindow *zwindow = zwindows[i];
1492 if( zwindow->idx < 0 ) continue;
1493 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1494 if( rsz < hh ) rsz = hh;
1495 int xx = zx + x1, yy = zy + y1;
1496 int mx = x2 - zw, my = y2 - zh;
1497 if( xx > mx ) xx = mx;
1498 if( yy > my ) yy = my;
1499 xx += lt + xS(dz); yy += top + yS(dz);
1500 zwindow->reposition(xx,yy, ww,hh);
1501 if( zwindow->running() ) {
1502 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1503 gui->lock_window("MWindow::tile_mixers");
1504 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1505 gui->unlock_window();
1509 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1518 void MWindow::set_gang_tracks(int v)
1520 edl->session->gang_tracks = v;
1521 gui->update(1, 1, 0, 0, 1, 0, 0);
1526 void MWindow::init_cache()
1528 audio_cache = new CICache(preferences);
1529 video_cache = new CICache(preferences);
1530 frame_cache = new FrameCache;
1531 wave_cache = new WaveCache;
1534 void MWindow::init_channeldb()
1536 channeldb_buz->load("channeldb_buz");
1537 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1540 void MWindow::init_menus()
1542 char string[BCTEXTLEN];
1545 BC_CModels::to_text(string, BC_RGB888);
1546 colormodels.append(new ColormodelItem(string, BC_RGB888));
1547 BC_CModels::to_text(string, BC_RGBA8888);
1548 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1549 // BC_CModels::to_text(string, BC_RGB161616);
1550 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1551 // BC_CModels::to_text(string, BC_RGBA16161616);
1552 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1553 BC_CModels::to_text(string, BC_RGB_FLOAT);
1554 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1555 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1556 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1557 BC_CModels::to_text(string, BC_YUV888);
1558 colormodels.append(new ColormodelItem(string, BC_YUV888));
1559 BC_CModels::to_text(string, BC_YUVA8888);
1560 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1561 // BC_CModels::to_text(string, BC_YUV161616);
1562 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1563 // BC_CModels::to_text(string, BC_YUVA16161616);
1564 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1566 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1567 interlace_project_modes.append(new InterlacemodeItem(string, x));
1569 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1570 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1572 // Interlacing Modes
1573 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1575 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1576 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1578 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1579 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1581 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1582 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1584 mixers_align = new MixersAlign(this);
1587 void MWindow::init_indexes()
1589 mainindexes = new MainIndexes(this);
1590 mainindexes->start_loop();
1593 void MWindow::init_gui()
1595 gui = new MWindowGUI(this);
1596 gui->create_objects();
1597 gui->load_defaults(defaults);
1600 void MWindow::init_signals()
1602 sighandler = new SigHandler;
1603 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1607 void MWindow::init_render()
1609 render = new Render(this);
1610 create_bd = new CreateBD_Thread(this);
1611 create_dvd = new CreateDVD_Thread(this);
1612 batch_render = new BatchRenderThread(this);
1615 void MWindow::init_exportedl()
1617 exportedl = new ExportEDL(this);
1621 void MWindow::init_shuttle()
1624 int ret = Shuttle::probe();
1626 shuttle = new Shuttle(this);
1627 if( shuttle->read_config_file() > 0 ) {
1628 printf("shuttle: bad config file\n");
1629 delete shuttle; shuttle = 0;
1632 shuttle->start(ret);
1636 void MWindow::init_wintv()
1639 wintv = WinTV::probe(this);
1644 void MWindow::init_x10tv()
1647 x10tv = X10TV::probe(this);
1654 void MWindow::init_brender()
1656 if(preferences->use_brender && !brender)
1658 brender_lock->lock("MWindow::init_brender 1");
1659 brender = new BRender(this);
1660 brender->initialize();
1661 session->brender_end = 0;
1662 brender_lock->unlock();
1665 if(!preferences->use_brender && brender)
1667 brender_lock->lock("MWindow::init_brender 2");
1670 session->brender_end = 0;
1671 brender_lock->unlock();
1677 void MWindow::restart_brender()
1679 //printf("MWindow::restart_brender 1\n");
1680 if( !brender_active || !preferences->use_brender ) return;
1681 if( !brender ) return;
1682 brender->restart(edl);
1685 void MWindow::stop_brender()
1687 if( !brender ) return;
1688 // cannot be holding mwindow->gui display lock
1692 int MWindow::brender_available(int position)
1695 brender_lock->lock("MWindow::brender_available 1");
1696 if(brender && brender_active)
1698 if(brender->map_valid)
1700 brender->map_lock->lock("MWindow::brender_available 2");
1701 if(position < brender->map_size &&
1704 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1705 if(brender->map[position] == BRender::RENDERED)
1708 brender->map_lock->unlock();
1711 brender_lock->unlock();
1715 void MWindow::set_brender_active(int v, int update)
1717 if( !preferences->use_brender ) v = 0;
1719 gui->mainmenu->brender_active->set_checked(v);
1721 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1722 edl->session->brender_end = edl->local_session->get_selectionend(1);
1724 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1725 edl->session->brender_end = edl->tracks->total_video_length();
1730 edl->session->brender_start = edl->session->brender_end = 0;
1731 gui->unlock_window();
1733 gui->lock_window("MWindow::set_brender_active");
1736 gui->update_timebar(0);
1737 gui->draw_overlays(1);
1741 int MWindow::has_commercials()
1743 #ifdef HAVE_COMMERCIAL
1744 return theme->use_commercials;
1750 void MWindow::init_commercials()
1752 #ifdef HAVE_COMMERCIAL
1753 if( !commercials ) {
1754 commercials = new Commercials(this);
1755 commercial_active = 0;
1758 commercials->add_user();
1762 void MWindow::commit_commercial()
1764 #ifdef HAVE_COMMERCIAL
1765 if( !commercial_active ) return;
1766 commercial_active = 0;
1767 if( !commercials ) return;
1768 commercials->commitDb();
1772 void MWindow::undo_commercial()
1774 #ifdef HAVE_COMMERCIAL
1775 if( !commercial_active ) return;
1776 commercial_active = 0;
1777 if( !commercials ) return;
1778 commercials->undoDb();
1782 int MWindow::put_commercial()
1785 #ifdef HAVE_COMMERCIAL
1786 double start = edl->local_session->get_selectionstart();
1787 double end = edl->local_session->get_selectionend();
1788 if( start >= end ) return 0;
1790 const char *errmsg = 0;
1792 Tracks *tracks = edl->tracks;
1794 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1795 if( track->data_type != TRACK_VIDEO ) continue;
1796 if( !track->armed ) continue;
1797 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1799 int64_t units_start = track->to_units(start,0);
1800 int64_t units_end = track->to_units(end,0);
1801 Edits *edits = track->edits;
1802 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1803 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1804 if(!edit1 && !edit2) continue; // nothing selected
1805 if(!edit2) { // edit2 beyond end of track
1806 edit2 = edits->last;
1807 units_end = edits->length();
1809 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1810 Indexable *indexable = edit1->get_source();
1811 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1814 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1815 if( track->data_type != TRACK_VIDEO ) continue;
1816 if( !track->armed ) continue;
1817 int64_t units_start = track->to_units(start,0);
1818 int64_t units_end = track->to_units(end,0);
1819 Edits *edits = track->edits;
1820 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1821 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1822 if(!edit1 && !edit2) continue; // nothing selected
1823 if(!edit2) { // edit2 beyond end of track
1824 edit2 = edits->last;
1825 units_end = edits->length();
1827 Indexable *indexable = edit1->get_source();
1828 Asset *asset = (Asset *)indexable;
1829 File *file = video_cache->check_out(asset, edl);
1830 if( !file ) { errmsg = _("no file"); break; }
1831 int64_t edit_length = units_end - units_start;
1832 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1833 result = commercials->put_clip(file, edit1->channel,
1834 track->from_units(edit_start), track->from_units(edit_length));
1835 video_cache->check_in(asset);
1836 if( result ) { errmsg = _("db failed"); break; }
1839 char string[BCTEXTLEN];
1840 sprintf(string, _("put_commercial: %s"), errmsg);
1841 MainError::show_error(string);
1849 void MWindow::stop_playback(int wait)
1851 gui->stop_drawing();
1853 cwindow->stop_playback(wait);
1855 for(int i = 0; i < vwindows.size(); i++) {
1856 VWindow *vwindow = vwindows[i];
1857 if( !vwindow->is_running() ) continue;
1858 vwindow->stop_playback(wait);
1860 for(int i = 0; i < zwindows.size(); i++) {
1861 ZWindow *zwindow = zwindows[i];
1862 if( zwindow->idx < 0 ) continue;
1863 zwindow->stop_playback(wait);
1867 void MWindow::stop_transport()
1869 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1872 void MWindow::undo_before(const char *description, void *creator)
1874 undo->update_undo_before(description, creator);
1877 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
1879 undo->update_undo_after(description, load_flags, changes_made);
1882 void MWindow::beep(double freq, double secs, double gain)
1884 if( !beeper ) beeper = new Beeper(this);
1885 beeper->tone(freq, secs, gain);
1888 Beeper::Beeper(MWindow *mwindow)
1891 this->mwindow = mwindow;
1892 audio = new AudioDevice(mwindow);
1906 int64_t bfrsz = BEEP_SAMPLE_RATE;
1907 EDL *edl = mwindow->edl;
1908 EDLSession *session = edl->session;
1909 AudioOutConfig *aconfig = session->playback_config->aconfig;
1910 audio->open_output(aconfig, BEEP_SAMPLE_RATE, bfrsz, channels, 0);
1911 audio->start_playback();
1913 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
1914 const double two_pi = 2*M_PI;
1915 int64_t audio_len = BEEP_SAMPLE_RATE * secs;
1916 const double dt = two_pi * freq/BEEP_SAMPLE_RATE;
1921 while( !interrupted ) {
1922 int len = audio_len - audio_pos;
1923 if( len <= 0 ) break;
1924 if( len > bfrsz ) len = bfrsz;
1926 for( int i=0; i<len; ++i,++k,th+=dt ) {
1927 double t = th - two_pi;
1928 if( t >= 0 ) th = t;
1929 out0[i] = out1[i] = sin(th) * gain;
1931 audio->write_buffer(out, channels, len);
1936 audio->set_last_buffer();
1937 audio->stop_audio(interrupted ? 0 : 1);
1943 void Beeper::start()
1945 if( running() ) return;
1951 void Beeper::stop(int wait)
1953 if( running() && !interrupted ) {
1955 audio->stop_audio(wait);
1960 void Beeper::tone(double freq, double secs, double gain)
1970 int MWindow::load_filenames(ArrayList<char*> *filenames,
1971 int load_mode, int edl_mode, int update_filename)
1973 ArrayList<EDL*> new_edls;
1974 ArrayList<Asset*> new_assets;
1975 ArrayList<File*> new_files;
1978 gui->start_hourglass();
1980 // Need to stop playback since tracking depends on the EDL not getting
1982 gui->unlock_window();
1984 gui->lock_window("MWindow::load_filenames 0");
1987 const int debug = 0;
1988 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1990 // Define new_edls and new_assets to load
1991 int result = 0, ftype = -1;
1993 for( int i=0; i<filenames->size(); ++i ) {
1995 File *new_file = new File;
1996 Asset *new_asset = new Asset(filenames->get(i));
1997 EDL *new_edl = new EDL;
1998 new_edl->create_objects();
1999 new_edl->copy_session(edl, -1);
2000 new_file->set_program(edl->session->program_no);
2002 char string[BCTEXTLEN];
2003 sprintf(string, _("Loading %s"), new_asset->path);
2004 gui->show_message(string);
2006 ftype = new_file->open_file(preferences, new_asset, 1, 0);
2010 // Convert media file to EDL
2012 // Warn about odd image dimensions
2013 if( new_asset->video_data &&
2014 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
2015 eprintf(_("%s's resolution is %dx%d.\n"
2016 "Images with odd dimensions may not decode properly."),
2017 new_asset->path, new_asset->width, new_asset->height);
2020 if( new_asset->program >= 0 &&
2021 edl->session->program_no != new_asset->program ) {
2022 eprintf(_("%s's index was built for program number %d\n"
2023 "Playback preference is %d.\n Using program %d."),
2024 new_asset->path, new_asset->program,
2025 edl->session->program_no, new_asset->program);
2028 if( load_mode == LOADMODE_RESOURCESONLY ) {
2029 new_assets.append(new_asset);
2030 new_asset->add_user();
2035 RecordLabels *labels = edl->session->label_cells ?
2036 new RecordLabels(new_file) : 0;
2037 asset_to_edl(new_edl, new_asset, labels);
2038 new_edls.append(new_edl);
2039 new_edl->add_user();
2042 if( load_mode == LOADMODE_REPLACE ||
2043 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2044 // Set filename to nothing for assets since save EDL would overwrite them.
2046 // Reset timeline position
2047 for( int i=0; i<TOTAL_PANES; ++i ) {
2048 new_edl->local_session->view_start[i] = 0;
2049 new_edl->local_session->track_start[i] = 0;
2055 case FILE_NOT_FOUND: {
2056 eprintf(_("Failed to open %s"), new_asset->path);
2057 sprintf(string, _("Failed to open %s"), new_asset->path);
2058 gui->show_message(string, theme->message_error);
2059 gui->update_default_message();
2063 case FILE_UNRECOGNIZED_CODEC: {
2065 { IndexFile indexfile(this, new_asset);
2066 if( !(result = indexfile.open_index()) )
2067 indexfile.close_index(); }
2069 // Test existing EDLs
2070 for( int j=0; result && j<new_edls.total; ++j ) {
2071 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
2073 new_asset->copy_from(old_asset,1);
2078 Asset *old_asset = edl->assets->get_asset(new_asset->path);
2080 new_asset->copy_from(old_asset,1);
2087 new_asset->audio_data = 1;
2088 new_asset->format = FILE_PCM;
2089 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
2090 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
2091 new_asset->bits = defaults->get("AUDIO_BITS", 16);
2092 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
2093 new_asset->signed_ = defaults->get("SIGNED_", 1);
2094 new_asset->header = defaults->get("HEADER", 0);
2097 fs.extract_name(string, new_asset->path);
2098 strcat(string, _("'s format couldn't be determined."));
2099 FileFormat fwindow(this);
2100 fwindow.create_objects(new_asset, string);
2101 result = fwindow.run_window();
2103 defaults->update("AUDIO_CHANNELS", new_asset->channels);
2104 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
2105 defaults->update("AUDIO_BITS", new_asset->bits);
2106 defaults->update("BYTE_ORDER", new_asset->byte_order);
2107 defaults->update("SIGNED_", new_asset->signed_);
2108 defaults->update("HEADER", new_asset->header);
2113 // Recalculate length
2115 new_file = new File;
2116 result = new_file->open_file(preferences, new_asset, 1, 0);
2118 if( load_mode != LOADMODE_RESOURCESONLY ) {
2119 RecordLabels *labels = edl->session->label_cells ?
2120 new RecordLabels(new_file) : 0;
2121 asset_to_edl(new_edl, new_asset, labels);
2122 new_edls.append(new_edl);
2123 new_edl->add_user();
2127 new_assets.append(new_asset);
2128 new_asset->add_user();
2135 const char *filename = filenames->get(i);
2136 if( xml_file.read_from_file(filename, 1) ) {
2137 eprintf(_("Error: unable to open:\n %s"), filename);
2140 const char *cin_version = 0;
2141 while( !xml_file.read_tag() ) {
2142 if( xml_file.tag.title_is("EDL") ) {
2143 cin_version = xml_file.tag.get_property("VERSION");
2148 if( !cin_version ) {
2149 eprintf(_("XML file %s\n not from cinelerra."),filename);
2150 char string[BCTEXTLEN];
2151 sprintf(string,_("Unknown %s"), filename);
2152 gui->show_message(string);
2155 if( strcmp(cin_version, CINELERRA_VERSION) &&
2156 strcmp(cin_version, "Unify") &&
2157 strcmp(cin_version, "5.1") ) {
2158 eprintf(_("Warning: XML from cinelerra version %s\n"
2159 "Session data may be incompatible."), cin_version);
2161 if( new_edl->load_xml(&xml_file, LOAD_ALL) ) {
2162 eprintf(_("Error: unable to load:\n %s"), filename);
2165 test_plugins(new_edl, filename);
2166 int groups = new_edl->regroup(session->group_number);
2167 session->group_number += groups;
2168 switch( edl_mode ) {
2169 case LOADMODE_EDL_CLIP: {
2170 strcpy(new_edl->local_session->clip_title,
2173 time_t t = !stat(filenames->get(i),&st) ?
2174 st.st_mtime : time(&t);
2175 ctime_r(&t, new_edl->local_session->clip_notes);
2176 switch( load_mode ) {
2177 case LOADMODE_REPLACE:
2178 case LOADMODE_REPLACE_CONCATENATE:
2179 strcpy(session->filename, filename);
2180 if( update_filename ) set_filename(filename);
2185 case LOADMODE_EDL_NESTED: {
2186 EDL *nested_edl = new EDL;
2187 nested_edl->create_objects();
2188 nested_edl->copy_session(edl, -1);
2189 nested_edl->create_nested(new_edl);
2190 nested_edl->set_path(filename);
2191 new_edl->remove_user();
2192 new_edl = nested_edl;
2195 case LOADMODE_EDL_FILEREF: {
2196 result = create_ref(new_asset, new_edl);
2198 new_assets.append(new_asset);
2199 new_asset->add_user();
2200 new_edl->remove_user();
2202 new_edl->create_objects();
2203 new_edl->copy_session(edl, -1);
2204 asset_to_edl(new_edl, new_asset);
2206 new_file = new File;
2207 result = new_file->open_file(preferences, new_asset, 1, 0);
2211 new_edls.append(new_edl);
2212 new_edl->add_user();
2215 eprintf(_("Error: Unable to load xml:\n %s"), new_asset->path);
2219 new_edl->Garbage::remove_user();
2220 new_asset->Garbage::remove_user();
2222 // Store for testing index
2223 new_files.append(new_file);
2226 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2229 gui->reset_default_message();
2230 gui->default_message();
2233 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2236 // Don't back up here.
2237 if( new_edls.size() ) {
2238 // For pasting, clear the active region
2239 if( load_mode == LOADMODE_PASTE ) {
2240 double start = edl->local_session->get_selectionstart();
2241 double end = edl->local_session->get_selectionend();
2242 if(!EQUIV(start, end))
2243 edl->clear(start, end,
2244 edl->session->labels_follow_edits,
2245 edl->session->plugins_follow_edits,
2246 edl->session->autos_follow_edits);
2248 paste_edls(&new_edls, load_mode, 0, -1,
2249 edl->session->labels_follow_edits,
2250 edl->session->plugins_follow_edits,
2251 edl->session->autos_follow_edits,
2254 else if( load_mode == LOADMODE_NEW_TRACKS &&
2255 edl_mode != LOADMODE_EDL_CLIP )
2256 paste_edls(&new_edls, load_mode, 0, -1, 0, 0, 0, 0);
2257 else if( load_mode != LOADMODE_RESOURCESONLY ||
2258 edl_mode == LOADMODE_EDL_CLIP )
2259 paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
2261 paste_edls(&new_edls, LOADMODE_NOTHING, 0, -1, 0, 0, 0, 0);
2265 // Add new assets to EDL and schedule assets for index building.
2266 int got_indexes = 0;
2267 for( int i=0; i<new_edls.size(); ++i ) {
2268 EDL *new_edl = new_edls[i];
2269 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2270 mainindexes->add_indexable(new_edl->nested_edls[j]);
2271 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2277 for( int i=0; i<new_assets.size(); ++i ) {
2278 Asset *new_asset = new_assets[i];
2279 mainindexes->add_indexable(new_asset);
2280 edl->assets->update(new_asset);
2284 // Start examining next batch of index files
2285 if(got_indexes) mainindexes->start_build();
2287 // reload renderengine edl or the plugin guis will flip out
2288 sync_parameters(CHANGE_ALL);
2292 // opening new session
2293 if( ( load_mode == LOADMODE_REPLACE ||
2294 load_mode == LOADMODE_REPLACE_CONCATENATE ) &&
2295 (ftype != FILE_IS_XML || edl_mode != LOADMODE_EDL_CLIP) ) {
2297 edl->session->proxy_scale = 1;
2298 edl->session->proxy_disabled_scale = 1;
2299 edl->session->proxy_use_scaler = 0;
2300 edl->session->proxy_auto_scale = 0;
2301 edl->session->proxy_beep = 0;
2302 edl->local_session->preview_start = 0;
2303 edl->local_session->preview_end = -1;
2304 edl->local_session->loop_playback = 0;
2305 edl->local_session->set_selectionstart(0);
2306 edl->local_session->set_selectionend(0);
2307 edl->local_session->unset_inpoint();
2308 edl->local_session-> unset_outpoint();
2309 set_brender_active(0, 0);
2314 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2315 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2316 ArrayList<Indexable *> orig_idxbls;
2317 for( int i=0; i<new_assets.size(); ++i )
2318 orig_idxbls.append(new_assets.get(i));
2319 for( int i=0; i<new_edls.size(); ++i ) {
2320 EDL *new_edl = new_edls[i];
2321 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2322 if( track->data_type != TRACK_VIDEO ) continue;
2323 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2324 Indexable *idxbl = (Indexable *)edit->asset;
2325 if( !idxbl ) continue;
2326 if( !idxbl->have_video() ) continue;
2327 if( edit->channel != 0 ) continue; // first layer only
2328 orig_idxbls.append(edit->asset);
2332 gui->unlock_window(); // to update progress bar
2333 int ret = render_proxy(orig_idxbls);
2334 gui->lock_window("MWindow::load_filenames");
2335 float gain = edl->session->proxy_beep;
2336 if( ret >= 0 && gain > 0 ) {
2338 beep(2000., 1.5, gain);
2340 beep(4000., 0.25, gain);
2344 // need to update undo before project, since mwindow is unlocked & a new load
2345 // can begin here. Should really prevent loading until we're done.
2346 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2347 undo_after(_("load"), LOAD_ALL);
2349 for(int i = 0; i < new_edls.size(); i++)
2351 new_edls[i]->remove_user();
2353 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2355 new_edls.remove_all();
2357 for(int i = 0; i < new_assets.size(); i++)
2359 new_assets[i]->Garbage::remove_user();
2362 new_assets.remove_all();
2363 new_files.remove_all_objects();
2366 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2367 if(load_mode == LOADMODE_REPLACE ||
2368 load_mode == LOADMODE_REPLACE_CONCATENATE)
2370 session->changes_made = 0;
2374 session->changes_made = 1;
2377 gui->stop_hourglass();
2380 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2381 update_project(load_mode);
2383 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2388 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2390 Asset *format_asset = new Asset;
2391 format_asset->format = FILE_FFMPEG;
2392 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2393 int new_scale = edl->session->proxy_scale;
2394 ProxyRender proxy_render(this, format_asset, new_scale);
2396 for( int i=0; i<new_idxbls.size(); ++i ) {
2397 Indexable *orig = new_idxbls.get(i);
2398 Asset *proxy = proxy_render.add_original(orig, new_scale);
2399 if( !proxy ) continue;
2401 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2402 int got_it = exists && // if proxy exists, and is newer than orig
2403 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2404 if( got_it ) continue;
2405 proxy_render.add_needed(orig, proxy);
2408 // render needed proxies
2409 int result = proxy_render.create_needed_proxies(new_scale);
2411 add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2413 format_asset->remove_user();
2414 return !result ? proxy_render.needed_proxies.size() : -1;
2417 int MWindow::enable_proxy()
2420 if( edl->session->proxy_scale == 1 &&
2421 edl->session->proxy_disabled_scale != 1 ) {
2422 int new_scale = edl->session->proxy_disabled_scale;
2423 int new_use_scaler = edl->session->proxy_use_scaler;
2424 Asset *asset = new Asset;
2425 asset->format = FILE_FFMPEG;
2426 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2427 ret = to_proxy(asset, new_scale, new_use_scaler);
2428 asset->remove_user();
2430 float gain = edl->session->proxy_beep;
2431 beep(2000., 1.5, gain);
2433 edl->session->proxy_disabled_scale = 1;
2434 gui->lock_window("MWindow::to_proxy");
2435 update_project(LOADMODE_REPLACE);
2436 gui->unlock_window();
2441 int MWindow::disable_proxy()
2443 if( edl->session->proxy_scale != 1 &&
2444 edl->session->proxy_disabled_scale == 1 ) {
2445 int old_scale = edl->session->proxy_scale, new_scale = 1;
2446 int new_use_scaler = edl->session->proxy_use_scaler;
2447 Asset *asset = new Asset;
2448 asset->format = FILE_FFMPEG;
2449 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2450 to_proxy(asset, new_scale, new_use_scaler);
2451 asset->remove_user();
2452 edl->session->proxy_disabled_scale = old_scale;
2453 gui->lock_window("MWindow::to_proxy");
2454 update_project(LOADMODE_REPLACE);
2455 gui->unlock_window();
2460 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2462 ArrayList<Indexable*> orig_idxbls;
2463 ArrayList<Indexable*> proxy_assets;
2465 edl->Garbage::add_user();
2467 undo_before(_("proxy"), this);
2468 int asset_scale = new_scale == 1 ? 0 :
2469 !new_use_scaler ? 1 : new_scale;
2470 ProxyRender proxy_render(this, asset, asset_scale);
2472 // revert project to original size from current size
2473 // remove all session proxy assets at the at the current proxy_scale
2474 int proxy_scale = edl->session->proxy_scale;
2476 if( proxy_scale > 1 ) {
2477 Asset *orig_asset = edl->assets->first;
2478 for( ; orig_asset; orig_asset=orig_asset->next ) {
2479 char new_path[BCTEXTLEN];
2480 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2481 // test if proxy asset was already added to proxy_assets
2483 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2484 got_it = !strcmp(proxy_assets[i]->path, new_path);
2485 if( got_it ) continue;
2486 Asset *proxy_asset = edl->assets->get_asset(new_path);
2487 if( !proxy_asset ) continue;
2488 // add pointer to existing EDL asset if it exists
2489 // EDL won't delete it unless it's the same pointer.
2490 proxy_assets.append(proxy_asset);
2491 proxy_asset->add_user();
2492 orig_idxbls.append(orig_asset);
2493 orig_asset->add_user();
2495 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2496 EDL *orig_nested = edl->nested_edls[i];
2497 char new_path[BCTEXTLEN];
2498 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2499 // test if proxy asset was already added to proxy_assets
2501 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2502 got_it = !strcmp(proxy_assets[i]->path, new_path);
2503 if( got_it ) continue;
2504 Asset *proxy_nested = edl->assets->get_asset(new_path);
2505 if( !proxy_nested ) continue;
2506 // add pointer to existing EDL asset if it exists
2507 // EDL won't delete it unless it's the same pointer.
2508 proxy_assets.append(proxy_nested);
2509 proxy_nested->add_user();
2510 orig_idxbls.append(orig_nested);
2511 orig_nested->add_user();
2514 // convert from the proxy assets to the original assets
2515 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2517 // remove the references
2518 for( int i=0; i<proxy_assets.size(); ++i ) {
2519 Asset *proxy = (Asset *) proxy_assets[i];
2520 proxy->width = proxy->actual_width;
2521 proxy->height = proxy->actual_height;
2522 proxy->remove_user();
2523 edl->assets->remove_pointer(proxy);
2524 proxy->remove_user();
2526 proxy_assets.remove_all();
2527 for( int i = 0; i < orig_idxbls.size(); i++ )
2528 orig_idxbls[i]->remove_user();
2529 orig_idxbls.remove_all();
2532 ArrayList<char *> confirm_paths; // test for new files
2533 confirm_paths.set_array_delete();
2535 // convert to new size if not original size
2536 if( new_scale != 1 ) {
2538 Asset *orig = edl->assets->first;
2539 for( ; orig; orig=orig->next ) {
2540 Asset *proxy = proxy_render.add_original(orig, new_scale);
2541 if( !proxy ) continue;
2542 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2543 int got_it = exists && // if proxy exists, and is newer than orig
2544 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2546 if( exists ) // prompt user to overwrite
2547 confirm_paths.append(cstrdup(proxy->path));
2548 proxy_render.add_needed(orig, proxy);
2551 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2552 EDL *orig_nested = edl->nested_edls[i];
2553 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2554 if( !proxy ) continue;
2555 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2556 int got_it = exists && // if proxy exists, and is newer than orig_nested
2557 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2559 if( exists ) // prompt user to overwrite
2560 confirm_paths.append(cstrdup(proxy->path));
2561 proxy_render.add_needed(orig_nested, proxy);
2567 // test for existing files
2568 if( confirm_paths.size() ) {
2569 result = ConfirmSave::test_files(this, &confirm_paths);
2570 confirm_paths.remove_all_objects();
2574 result = proxy_render.create_needed_proxies(new_scale);
2576 if( !result ) // resize project
2577 edl->set_proxy(new_scale, new_use_scaler,
2578 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2580 undo_after(_("proxy"), LOAD_ALL);
2581 edl->Garbage::remove_user();
2584 return !result ? proxy_render.needed_proxies.size() : -1;
2587 void MWindow::test_plugins(EDL *new_edl, const char *path)
2589 char string[BCTEXTLEN];
2591 // Do a check whether plugins exist
2592 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2593 for( int k=0; k<track->plugin_set.total; ++k ) {
2594 PluginSet *plugin_set = track->plugin_set[k];
2595 for( Plugin *plugin = (Plugin*)plugin_set->first;
2596 plugin; plugin = (Plugin*)plugin->next ) {
2597 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2598 // ok we need to find it in plugindb
2599 PluginServer *server =
2600 scan_plugindb(plugin->title, track->data_type);
2601 if( !server || server->transition ) {
2603 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2604 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2605 "effect", _(plugin->title), path);
2606 MainError::show_error(string);
2611 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2612 if( !edit->transition ) continue;
2613 // ok we need to find transition in plugindb
2614 PluginServer *server =
2615 scan_plugindb(edit->transition->title, track->data_type);
2616 if( !server || !server->transition ) {
2618 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2619 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2620 "transition", _(edit->transition->title), path);
2621 MainError::show_error(string);
2628 void MWindow::init_shm(const char *pfn, int64_t min)
2631 // Fix shared memory
2632 FILE *fd = fopen(pfn, "r");
2634 fscanf(fd, "%jd", &result);
2636 if( result >= min ) return;
2639 fd = fopen(pfn, "w");
2641 fprintf(fd, "0x%jx", min);
2644 fd = fopen(pfn, "r");
2646 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2650 fscanf(fd, "%jd", &result);
2652 if( result < min ) {
2653 eprintf(_("MWindow::init_shm: %s is %p.\n"
2654 "you probably need to be root, or:\n"
2655 "as root, run: echo 0x%jx > %s\n"
2656 "before trying to start cinelerra.\n"
2657 "It should be at least 0x%jx for Cinelerra.\n"),
2658 pfn, (void *)result, min, pfn, min);
2662 void MWindow::create_objects(int want_gui,
2666 const int debug = 0;
2667 if(debug) PRINT_TRACE
2669 // For some reason, init_signals must come after show_splash or the signals won't
2672 if(debug) PRINT_TRACE
2675 if(debug) PRINT_TRACE
2678 if(debug) PRINT_TRACE
2679 default_standard = default_std();
2680 init_defaults(defaults, config_path);
2684 splash_window->update_status(_("Initializing Plugins"));
2685 init_plugins(this, preferences);
2686 if(debug) PRINT_TRACE
2687 init_ladspa_plugins(this, preferences);
2688 if(debug) PRINT_TRACE
2689 init_plugin_tips(*plugindb, cin_lang);
2691 splash_window->update_status(_("Initializing GUI"));
2692 if(debug) PRINT_TRACE
2695 if(debug) PRINT_TRACE
2699 splash_window->update_status(_("Initializing Fonts"));
2700 char string[BCTEXTLEN];
2701 strcpy(string, preferences->plugin_dir);
2702 strcat(string, "/" FONT_SEARCHPATH);
2703 BC_Resources::init_fontconfig(string);
2704 if(debug) PRINT_TRACE
2710 // Default project created here
2712 if(debug) PRINT_TRACE
2715 if(debug) PRINT_TRACE
2720 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2723 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2725 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2726 if(session->show_vwindow)
2727 get_viewer(1, DEFAULT_VWINDOW);
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());
2743 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());
2752 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2753 mainprogress = new MainProgress(this, gui);
2754 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2755 undo = new MainUndo(this);
2757 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2759 plugin_guis = new PluginGUIs(this);
2760 dead_plugins = new ArrayList<PluginServer*>;
2761 keyframe_threads = new ArrayList<KeyFrameThread*>;
2763 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2766 session->show_vwindow);
2768 // Show all vwindows
2769 // if(session->show_vwindow) {
2770 // for(int j = 0; j < vwindows.size(); j++) {
2771 // VWindow *vwindow = vwindows[j];
2772 // if( !vwindow->is_running() ) continue;
2773 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2776 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2777 // vwindow->gui->lock_window("MWindow::create_objects 1");
2778 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2779 // vwindow->gui->show_window();
2780 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2781 // vwindow->gui->unlock_window();
2786 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2788 if(session->show_cwindow)
2790 cwindow->gui->lock_window("MWindow::create_objects 1");
2791 cwindow->gui->show_window();
2792 cwindow->gui->unlock_window();
2795 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2796 if(session->show_awindow)
2798 awindow->gui->lock_window("MWindow::create_objects 1");
2799 awindow->gui->show_window();
2800 awindow->gui->unlock_window();
2803 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2804 if(session->show_lwindow)
2806 lwindow->gui->lock_window("MWindow::create_objects 1");
2807 lwindow->gui->show_window();
2808 lwindow->gui->unlock_window();
2811 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2813 (int)timer.get_difference(),
2815 if(session->show_gwindow)
2817 gwindow->gui->lock_window("MWindow::create_objects 1");
2818 gwindow->gui->show_window();
2819 gwindow->gui->unlock_window();
2822 if(debug) PRINT_TRACE
2824 gui->lock_window("MWindow::create_objects 1");
2825 gui->mainmenu->load_defaults(defaults);
2826 gui->mainmenu->update_toggles(0);
2827 gui->update_patchbay();
2828 gui->draw_canvas(0, 0);
2829 gui->draw_cursor(1);
2831 gui->raise_window();
2832 gui->unlock_window();
2833 cwindow->gui->lock_window("MWindow::create_objects 1");
2834 cwindow->gui->tool_panel->raise_tool();
2835 cwindow->gui->unlock_window();
2836 if(debug) PRINT_TRACE
2838 if(preferences->use_tipwindow)
2840 if(debug) PRINT_TRACE
2842 gui->add_keyboard_listener(
2843 (int (BC_WindowBase::*)(BC_WindowBase *))
2844 &MWindowGUI::keyboard_listener);
2847 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2848 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2849 if(debug) PRINT_TRACE
2851 BC_WindowBase::get_resources()->vframe_shm = 1;
2854 int MWindow::uses_opengl()
2856 if( !playback_3d || !playback_3d->running() ) return 0;
2857 PlaybackConfig *playback_config = edl->session->playback_config;
2858 return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
2861 void MWindow::show_splash()
2863 #include "data/heroine_logo9_png.h"
2864 VFrame *frame = new VFramePng(heroine_logo9_png);
2865 BC_DisplayInfo dpyi;
2866 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2867 int rr = (rw < rh ? rw : rh) / 4;
2868 splash_window = new SplashGUI(frame, rr, rr);
2869 splash_window->create_objects();
2872 void MWindow::hide_splash()
2875 delete splash_window;
2880 void MWindow::start()
2884 // vwindows[DEFAULT_VWINDOW]->start();
2895 playback_3d->start();
2901 run_lock->lock("MWindow::run");
2905 brender_lock->lock("MWindow::run 1");
2906 delete brender; brender = 0;
2907 brender_lock->unlock();
2909 interrupt_indexes();
2915 void MWindow::show_vwindow()
2917 int total_running = 0;
2918 session->show_vwindow = 1;
2920 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2921 // Raise all windows which are visible
2922 for(int j = 0; j < vwindows.size(); j++) {
2923 VWindow *vwindow = vwindows[j];
2924 if( !vwindow->is_running() ) continue;
2925 vwindow->gui->lock_window("MWindow::show_vwindow");
2926 vwindow->gui->show_window(0);
2927 vwindow->gui->raise_window();
2928 vwindow->gui->flush();
2929 vwindow->gui->unlock_window();
2933 // If no windows visible
2936 get_viewer(1, DEFAULT_VWINDOW);
2939 gui->mainmenu->show_vwindow->set_checked(1);
2942 void MWindow::show_awindow()
2944 session->show_awindow = 1;
2945 awindow->gui->lock_window("MWindow::show_awindow");
2946 awindow->gui->show_window();
2947 awindow->gui->raise_window();
2948 awindow->gui->flush();
2949 awindow->gui->unlock_window();
2950 gui->mainmenu->show_awindow->set_checked(1);
2953 char *MWindow::get_cwindow_display()
2955 char *x11_host = screens < 2 || session->window_config == 0 ?
2956 session->a_x11_host : session->b_x11_host;
2957 return *x11_host ? x11_host : 0;
2960 void MWindow::show_cwindow()
2962 session->show_cwindow = 1;
2963 cwindow->show_window();
2964 gui->mainmenu->show_cwindow->set_checked(1);
2967 void MWindow::show_gwindow()
2969 session->show_gwindow = 1;
2971 gwindow->gui->lock_window("MWindow::show_gwindow");
2972 gwindow->gui->show_window();
2973 gwindow->gui->raise_window();
2974 gwindow->gui->flush();
2975 gwindow->gui->unlock_window();
2977 gui->mainmenu->show_gwindow->set_checked(1);
2979 void MWindow::hide_gwindow()
2981 session->show_gwindow = 0;
2983 gwindow->gui->lock_window("MWindow::show_gwindow");
2984 gwindow->gui->hide_window();
2985 gwindow->gui->unlock_window();
2988 void MWindow::show_lwindow()
2990 session->show_lwindow = 1;
2991 lwindow->gui->lock_window("MWindow::show_lwindow");
2992 lwindow->gui->show_window();
2993 lwindow->gui->raise_window();
2994 lwindow->gui->flush();
2995 lwindow->gui->unlock_window();
2996 gui->mainmenu->show_lwindow->set_checked(1);
2999 void MWindow::restore_windows()
3001 gui->unlock_window();
3002 if( !session->show_vwindow ) {
3003 for( int i=0, n=vwindows.size(); i<n; ++i ) {
3004 VWindow *vwindow = vwindows[i];
3005 if( !vwindow || !vwindow->is_running() ) continue;
3006 vwindow->gui->lock_window("MWindow::restore_windows");
3007 vwindow->gui->close(1);
3008 vwindow->gui->unlock_window();
3014 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
3015 awindow->gui->lock_window("MWindow::restore_windows");
3016 awindow->gui->close_event();
3017 awindow->gui->unlock_window();
3019 else if( session->show_awindow && awindow->gui->is_hidden() )
3022 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
3023 cwindow->gui->lock_window("MWindow::restore_windows");
3024 cwindow->hide_window();
3025 cwindow->gui->unlock_window();
3027 else if( session->show_cwindow && cwindow->gui->is_hidden() )
3028 cwindow->show_window();
3030 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
3031 gwindow->gui->lock_window("MWindow::restore_windows");
3032 gwindow->gui->close_event();
3033 gwindow->gui->unlock_window();
3035 else if( session->show_gwindow && gwindow->gui->is_hidden() )
3038 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
3039 lwindow->gui->lock_window("MWindow::restore_windows");
3040 lwindow->gui->close_event();
3041 lwindow->gui->unlock_window();
3043 else if( session->show_lwindow && lwindow->gui->is_hidden() )
3046 gui->lock_window("MWindow::restore_windows");
3050 void MWindow::load_layout(const char *layout)
3052 char path[BCTEXTLEN];
3053 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3054 session->load_file(path);
3056 gui->default_positions();
3060 void MWindow::save_layout(const char *layout)
3062 char path[BCTEXTLEN];
3063 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3064 session->save_file(path);
3067 void MWindow::delete_layout(const char *layout)
3069 char path[BCTEXTLEN];
3070 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3074 int MWindow::tile_windows(int window_config)
3076 int need_reload = 0;
3077 int play_config = window_config==0 ? 0 : 1;
3078 edl->session->playback_config->load_defaults(defaults, play_config);
3079 session->default_window_positions(window_config);
3080 if( screens == 1 ) {
3081 gui->default_positions();
3082 sync_parameters(CHANGE_ALL);
3089 void MWindow::toggle_loop_playback()
3091 edl->local_session->loop_playback = !edl->local_session->loop_playback;
3092 set_loop_boundaries();
3095 gui->draw_overlays(1);
3096 sync_parameters(CHANGE_PARAMS);
3099 void MWindow::set_screens(int value)
3104 void MWindow::set_auto_keyframes(int value)
3106 edl->session->auto_keyframes = value;
3107 gui->mbuttons->edit_panel->keyframe->update(value);
3109 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
3110 cwindow->gui->flush();
3111 cwindow->gui->unlock_window();
3114 void MWindow::set_span_keyframes(int value)
3116 edl->session->span_keyframes = value;
3117 gui->mbuttons->edit_panel->span_keyframe->update(value);
3119 cwindow->gui->lock_window("MWindow::set_span_keyframes");
3120 cwindow->gui->flush();
3121 cwindow->gui->unlock_window();
3124 void MWindow::set_auto_visibility(Autos *autos, int value)
3126 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3127 edl->session->auto_conf->plugins = value;
3128 else if( autos->autoidx >= 0 )
3129 edl->session->auto_conf->autos[autos->autoidx] = value;
3133 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3134 gui->mainmenu->update_toggles(1);
3135 gui->unlock_window();
3136 gwindow->gui->update_toggles(1);
3137 gui->lock_window("MWindow::set_auto_visibility");
3140 void MWindow::set_keyframe_type(int mode)
3142 gui->lock_window("MWindow::set_keyframe_type");
3143 edl->local_session->floatauto_type = mode;
3144 gui->mainmenu->update_toggles(0);
3145 gui->unlock_window();
3148 int MWindow::set_editing_mode(int new_editing_mode)
3150 edl->session->editing_mode = new_editing_mode;
3151 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3152 gui->mbuttons->edit_panel->update();
3153 gui->set_editing_mode(1);
3155 cwindow->gui->lock_window("MWindow::set_editing_mode");
3156 cwindow->gui->edit_panel->update();
3157 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3158 cwindow->gui->unlock_window();
3162 void MWindow::toggle_editing_mode()
3164 int mode = edl->session->editing_mode;
3165 if( mode == EDITING_ARROW )
3166 set_editing_mode(EDITING_IBEAM);
3168 set_editing_mode(EDITING_ARROW);
3171 void MWindow::toggle_camera_xyz()
3173 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3174 gwindow->gui->toggle_camera_xyz();
3175 gwindow->gui->unlock_window();
3178 void MWindow::toggle_projector_xyz()
3180 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3181 gwindow->gui->toggle_projector_xyz();
3182 gwindow->gui->unlock_window();
3185 void MWindow::set_labels_follow_edits(int value)
3187 edl->session->labels_follow_edits = value;
3188 gui->mbuttons->edit_panel->locklabels->update(value);
3189 gui->mainmenu->labels_follow_edits->set_checked(value);
3193 void MWindow::sync_parameters(int change_type)
3195 if( in_destructor ) return;
3197 // Sync engines which are playing back
3198 if( cwindow->playback_engine->is_playing_back ) {
3199 if( change_type == CHANGE_PARAMS ) {
3200 // TODO: block keyframes until synchronization is done
3201 cwindow->playback_engine->sync_parameters(edl);
3205 int command = cwindow->playback_engine->command->command;
3206 // Waiting for tracking to finish would make the restart position more
3207 // accurate but it can't lock the window to stop tracking for some reason.
3208 // Not waiting for tracking gives a faster response but restart position is
3209 // only as accurate as the last tracking update.
3210 cwindow->playback_engine->transport_stop(0);
3211 cwindow->playback_engine->next_command->realtime = 1;
3212 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3216 cwindow->refresh_frame(change_type);
3220 void MWindow::age_caches()
3222 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3224 // preferences->cache_size,
3225 // audio_cache->get_memory_usage(1),
3226 // video_cache->get_memory_usage(1),
3227 // frame_cache->get_memory_usage(),
3228 // wave_cache->get_memory_usage(),
3230 frame_cache->age_cache(512);
3231 wave_cache->age_cache(8192);
3233 int64_t memory_usage;
3234 int64_t prev_memory_usage = 0;
3236 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3237 while( !result && prev_memory_usage !=
3238 (memory_usage=video_cache->get_memory_usage(1)) &&
3239 memory_usage > video_size ) {
3240 video_cache->delete_oldest();
3241 prev_memory_usage = memory_usage;
3244 prev_memory_usage = 0;
3246 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3247 while( !result && prev_memory_usage !=
3248 (memory_usage=audio_cache->get_memory_usage(1)) &&
3249 memory_usage > audio_size ) {
3250 audio_cache->delete_oldest();
3251 prev_memory_usage = memory_usage;
3255 void MWindow::reset_android_remote()
3257 gui->use_android_remote(preferences->android_remote);
3261 void MWindow::show_keyframe_gui(Plugin *plugin)
3263 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3264 // Find existing thread
3265 for( int i=0; i<keyframe_threads->size(); ++i ) {
3266 int plugin_id = keyframe_threads->get(i)->plugin_id;
3267 if( plugin_id == plugin->orig_id ) {
3268 keyframe_threads->get(i)->start_window(plugin, 0);
3269 keyframe_gui_lock->unlock();
3274 // Find unused thread
3275 for( int i=0; i<keyframe_threads->size(); ++i ) {
3276 if( keyframe_threads->get(i)->plugin_id < 0 ) {
3277 keyframe_threads->get(i)->start_window(plugin, 0);
3278 keyframe_gui_lock->unlock();
3283 // Create new thread
3284 KeyFrameThread *thread = new KeyFrameThread(this);
3285 keyframe_threads->append(thread);
3286 thread->start_window(plugin, 0);
3287 keyframe_gui_lock->unlock();
3291 void MWindow::show_plugin(Plugin *plugin)
3296 // Remove previously deleted plugin GUIs
3297 dead_plugin_lock->lock("MWindow::show_plugin");
3298 dead_plugins->remove_all_objects();
3299 dead_plugin_lock->unlock();
3301 //printf("MWindow::show_plugin %d\n", __LINE__);
3304 plugin_gui_lock->lock("MWindow::show_plugin");
3305 for( int i=0; i<plugin_guis->total; ++i ) {
3306 // Pointer/id comparison
3307 PluginServer *plugin_gui = plugin_guis->get(i);
3308 if( plugin_gui->plugin_id == plugin->orig_id ) {
3309 plugin_gui->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 return hide_plugin(plugin->orig_id, lock);
3352 void MWindow::hide_plugin(int plugin_id, int lock)
3354 // Update the toggle
3355 gui->lock_window("MWindow::hide_plugin");
3356 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3357 gui->unlock_window();
3359 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3360 for( int i=0; i<plugin_guis->total; ++i ) {
3361 PluginServer *plugin_gui = plugin_guis->get(i);
3362 if( plugin_gui->plugin_id == plugin_id ) {
3363 plugin_guis->remove(plugin_gui);
3364 if(lock) plugin_gui_lock->unlock();
3365 // Last command executed in client side close
3366 // Schedule for deletion
3367 plugin_gui->hide_gui();
3368 delete_plugin(plugin_gui);
3373 if(lock) plugin_gui_lock->unlock();
3374 // update show/gui_id
3375 sync_parameters(CHANGE_PARAMS);
3378 void MWindow::delete_plugin(PluginServer *plugin)
3380 dead_plugin_lock->lock("MWindow::delete_plugin");
3381 dead_plugins->append(plugin);
3382 dead_plugin_lock->unlock();
3385 void MWindow::hide_plugins()
3387 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3388 while(plugin_guis->size())
3390 PluginServer *ptr = plugin_guis->get(0);
3391 plugin_guis->remove(ptr);
3392 plugin_gui_lock->unlock();
3393 // Last command executed in client side close
3394 // Schedule for deletion
3397 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3399 plugin_gui_lock->unlock();
3401 hide_keyframe_guis();
3404 void MWindow::hide_keyframe_guis()
3406 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3407 for(int i = 0; i < keyframe_threads->size(); i++)
3409 keyframe_threads->get(i)->close_window();
3411 keyframe_gui_lock->unlock();
3414 void MWindow::hide_keyframe_gui(Plugin *plugin)
3416 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3417 for( int i = 0; i < keyframe_threads->size(); i++) {
3418 KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
3419 if( keyframe_gui->plugin_id == plugin->orig_id ) {
3420 keyframe_gui->close_window();
3424 keyframe_gui_lock->unlock();
3427 int MWindow::get_hash_color(Edit *edit)
3429 Indexable *idxbl = edit->asset ?
3430 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3431 if( !idxbl ) return 0;
3432 char path[BCTEXTLEN];
3433 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3434 edl->session->proxy_scale == 1 ||
3435 ProxyRender::from_proxy_path(path, (Asset*)idxbl, edl->session->proxy_scale) )
3436 strcpy(path, idxbl->path);
3437 char *cp = strrchr(path, '/');
3438 cp = !cp ? path : cp+1;
3439 uint8_t *bp = (uint8_t*)cp;
3441 while( *bp ) v += *bp++;
3442 return get_hash_color(v);
3445 int MWindow::get_hash_color(int v)
3447 int hash = 0x303030;
3448 if( v & 0x01 ) hash ^= 0x000040;
3449 if( v & 0x02 ) hash ^= 0x004000;
3450 if( v & 0x04 ) hash ^= 0x400000;
3451 if( v & 0x08 ) hash ^= 0x080000;
3452 if( v & 0x10 ) hash ^= 0x000800;
3453 if( v & 0x20 ) hash ^= 0x000008;
3454 if( v & 0x40 ) hash ^= 0x404040;
3455 if( v & 0x80 ) hash ^= 0x080808;
3459 int MWindow::get_group_color(int v)
3461 int color = 0x606060;
3462 if( v & 0x01 ) color ^= 0x000080;
3463 if( v & 0x02 ) color ^= 0x008000;
3464 if( v & 0x04 ) color ^= 0x800000;
3465 if( v & 0x08 ) color ^= 0x100000;
3466 if( v & 0x10 ) color ^= 0x001000;
3467 if( v & 0x20 ) color ^= 0x000010;
3468 if( v & 0x40 ) color ^= 0x080808;
3469 if( v & 0x80 ) color ^= 0x909090;
3473 int MWindow::get_title_color(Edit *edit)
3475 unsigned color = edit->color & 0xffffff;
3476 unsigned alpha = (~edit->color>>24) & 0xff;
3478 if( edit->group_id )
3479 color = get_group_color(edit->group_id);
3480 else if( preferences->autocolor_assets )
3481 color = get_hash_color(edit);
3486 alpha = session->title_bar_alpha*255;
3487 return color | (~alpha<<24);
3490 void MWindow::update_keyframe_guis()
3492 // Send new configuration to keyframe GUI's
3493 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3494 for( int i=0; i<keyframe_threads->size(); ++i ) {
3495 KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
3496 Plugin *plugin = edl->tracks->plugin_exists(keyframe_gui->plugin_id);
3498 keyframe_gui->update_gui(1);
3500 keyframe_gui->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 ) {
3511 PluginServer *plugin_gui = plugin_guis->get(i);
3512 Plugin *plugin = edl->tracks->plugin_exists(plugin_gui->plugin_id);
3513 if( plugin && plugin->show )
3514 plugin_gui->update_gui();
3516 // Schedule for deletion if no plugin or not shown
3517 plugin_guis->remove_number(i--);
3518 plugin_gui->hide_gui();
3519 delete_plugin(plugin_gui);
3524 // Change plugin variable if not visible
3525 Track *track = edl->tracks->first;
3526 for( ; track; track=track->next ) {
3527 for( int i=0; i < track->plugin_set.size(); ++i ) {
3528 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3529 for( ; plugin; plugin = (Plugin*)plugin->next ) {
3531 for( int i=0; i<plugin_guis->size(); ++i ) {
3532 PluginServer *server = plugin_guis->get(i);
3533 if( server->plugin_id == plugin->orig_id ) {
3538 if( !got_it ) plugin->show = 0;
3543 plugin_gui_lock->unlock();
3544 if( do_keyframe_guis )
3545 update_keyframe_guis();
3548 void MWindow::stop_plugin_guis()
3550 // Send new configuration to plugin GUI's
3551 plugin_gui_lock->lock("MWindow::stop_plugin_guis");
3553 for( int i=0; i<plugin_guis->size(); ++i ) {
3554 PluginServer *plugin_gui = plugin_guis->get(i);
3555 plugin_gui->render_stop();
3557 plugin_gui_lock->unlock();
3560 int MWindow::plugin_gui_open(Plugin *plugin)
3562 int gui_id = plugin->gui_id;
3563 if( gui_id < 0 ) return 0;
3564 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3565 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3566 int result = plugin_server ? 1 : 0;
3567 plugin_gui_lock->unlock();
3572 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3574 int gui_id = plugin->gui_id;
3575 if( gui_id < 0 ) return;
3576 plugin_gui_lock->lock("MWindow::render_plugin_gui 0");
3577 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3579 plugin_server->render_gui(data);
3580 plugin_gui_lock->unlock();
3583 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3585 int gui_id = plugin->gui_id;
3586 if( gui_id < 0 ) return;
3587 plugin_gui_lock->lock("MWindow::render_plugin_gui 1");
3588 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3590 plugin_server->render_gui(data, size);
3591 plugin_gui_lock->unlock();
3594 void MWindow::reset_plugin_gui_frames(Plugin *plugin)
3596 int gui_id = plugin->gui_id;
3597 if( gui_id < 0 ) return;
3598 plugin_gui_lock->lock("MWindow::reset_plugin_gui_frames");
3599 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3601 plugin_server->reset_plugin_gui_frames();
3602 plugin_gui_lock->unlock();
3605 void MWindow::render_plugin_gui_frames(PluginClientFrames *frames, Plugin *plugin)
3607 int gui_id = plugin->gui_id;
3608 if( gui_id < 0 ) return;
3609 plugin_gui_lock->lock("MWindow::render_plugin_gui_frames");
3610 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3612 plugin_server->render_plugin_gui_frames(frames);
3613 plugin_gui_lock->unlock();
3616 double MWindow::get_tracking_position()
3618 return edl->local_session->get_selectionstart(1);
3621 int MWindow::get_tracking_direction()
3623 return cwindow->playback_engine->get_direction();
3626 void MWindow::update_plugin_states()
3628 plugin_gui_lock->lock("MWindow::update_plugin_states");
3629 for( int i=0; i<plugin_guis->total; ++i ) {
3631 PluginServer *src_plugingui = plugin_guis->get(i);
3632 int plugin_id = src_plugingui->plugin_id;
3633 Plugin *src_plugin = edl->tracks->plugin_exists(plugin_id);
3634 // Doesn't exist anymore
3636 hide_plugin(plugin_id, 0);
3640 plugin_gui_lock->unlock();
3644 void MWindow::update_plugin_titles()
3646 for( int i=0; i<plugin_guis->total; ++i )
3647 plugin_guis->get(i)->update_title();
3650 int MWindow::asset_to_edl(EDL *new_edl,
3652 RecordLabels *labels)
3654 const int debug = 0;
3655 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3658 // Keep frame rate, sample rate, and output size unchanged.
3659 // These parameters would revert the project if VWindow displayed an asset
3660 // of different size than the project.
3661 if(new_asset->video_data)
3663 new_edl->session->video_tracks = new_asset->layers;
3666 new_edl->session->video_tracks = 0;
3668 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3674 if(new_asset->audio_data)
3676 new_edl->session->audio_tracks = new_asset->channels;
3679 new_edl->session->audio_tracks = 0;
3680 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3682 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3683 new_edl->create_default_tracks();
3684 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3685 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3689 //printf("MWindow::asset_to_edl 3\n");
3690 new_edl->insert_asset(new_asset,
3695 //printf("MWindow::asset_to_edl 3\n");
3696 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3698 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3699 if(edl->session->cursor_on_frames)
3701 double length = new_edl->tracks->total_length();
3702 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3703 new_edl->tracks->clear(length, edl_length, 1, 1);
3709 char string[BCTEXTLEN];
3711 fs.extract_name(string, new_asset->path);
3712 //printf("MWindow::asset_to_edl 3\n");
3714 strcpy(new_edl->local_session->clip_title, string);
3715 //printf("MWindow::asset_to_edl 4 %s\n", string);
3716 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3718 new_edl->local_session->asset2edl = 1;
3723 // Reset everything after a load.
3724 void MWindow::update_project(int load_mode)
3726 const int debug = 0;
3728 if(debug) PRINT_TRACE
3729 edl->tracks->update_y_pixels(theme);
3730 session->update_clip_number();
3732 if(debug) PRINT_TRACE
3734 if( load_mode == LOADMODE_REPLACE ||
3735 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3736 edl->session->timecode_offset = 0;
3737 delete gui->keyvalue_popup;
3738 gui->keyvalue_popup = 0;
3742 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3743 if(debug) PRINT_TRACE
3744 gui->unlock_window();
3747 cwindow->update(0, 0, 1, 1, 1);
3749 if(debug) PRINT_TRACE
3751 // Close all the vwindows
3752 if( load_mode == LOADMODE_REPLACE ||
3753 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3754 if(debug) PRINT_TRACE
3755 int first_vwindow = 0;
3756 if(session->show_vwindow) first_vwindow = 1;
3757 // Change visible windows to no source
3758 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3759 VWindow *vwindow = vwindows[i];
3760 if( !vwindow->is_running() ) continue;
3761 vwindow->change_source(-1);
3764 // Close remaining windows
3765 for(int i = first_vwindow; i < vwindows.size(); i++) {
3766 VWindow *vwindow = vwindows[i];
3767 if( !vwindow->is_running() ) continue;
3768 vwindow->close_window();
3770 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3771 VWindow *vwindow = get_viewer(1, -1);
3772 vwindow->change_source(i);
3774 if(debug) PRINT_TRACE
3778 for( int i=0; i<edl->mixers.size(); ++i ) {
3779 Mixer *mixer = edl->mixers[i];
3780 if( !mixer->show ) continue;
3781 ZWindow *zwindow = get_mixer(mixer);
3782 zwindow->set_title(mixer->title);
3785 cwindow->gui->canvas->set_zoom(edl, 0);
3789 if(debug) PRINT_TRACE
3790 cwindow->gui->lock_window("MWindow::update_project 2");
3791 cwindow->gui->timebar->update(0);
3792 Track *track = cwindow->calculate_affected_track();
3793 cwindow->mask_track_id = track ? track->get_id() : -1;
3794 cwindow->gui->tool_panel->raise_tool();
3795 cwindow->gui->update_canvas(0);
3796 cwindow->gui->unlock_window();
3798 if(debug) PRINT_TRACE
3799 cwindow->refresh_frame(CHANGE_ALL);
3801 awindow->gui->async_update_assets();
3802 if(debug) PRINT_TRACE
3804 gui->lock_window("MWindow::update_project");
3805 gui->update_mixers(0, 0);
3807 if(debug) PRINT_TRACE
3810 void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
3812 int got_indexes = 0;
3813 for( int i=0; i<new_edl->nested_edls.size(); ++i ) {
3814 EDL *nested_edl = new_edl->nested_edls[i];
3815 mainindexes->add_indexable(nested_edl);
3816 edl->nested_edls.update_index(nested_edl);
3819 for( Asset *asset=new_edl->assets->first; asset; asset=asset->next ) {
3820 mainindexes->add_indexable(asset);
3821 edl->assets->update(asset);
3824 // Start examining next batch of index files
3826 mainindexes->start_build();
3829 gui->lock_window("MWindow::stack_push");
3830 if( stack.size() < 9 ) {
3834 StackItem &item = stack.append();
3836 item.new_edl = new_edl;
3837 item.duration = new_edl->tracks->total_length();
3841 if( idxbl && idxbl->is_asset ) {
3843 Asset *asset = (Asset *)idxbl;
3844 if( asset->format == FILE_REF &&
3845 !stat(asset->path, &st) )
3846 item.mtime = st.st_mtime;
3850 strcpy(session->filename, edl->path);
3851 undo = new MainUndo(this);
3852 gui->stack_button->update();
3853 update_project(LOADMODE_REPLACE);
3855 gui->unlock_window();
3859 void MWindow::stack_pop()
3861 if( !stack.size() ) return;
3862 // writes on config_path/backup%d.xml
3865 // already have gui lock
3866 StackItem &item = stack.last();
3867 // session edl replaced, overwrite and save clip data
3868 if( item.new_edl != edl )
3869 item.new_edl->overwrite_clip(edl);
3870 Indexable *idxbl = item.idxbl;
3871 if( idxbl && idxbl->is_asset && item.mtime ) {
3872 Asset *asset = (Asset *)idxbl;
3873 if( asset->format == FILE_REF ) {
3874 char *path = asset->path;
3876 if( stat(path, &st) || item.mtime == st.st_mtime ) {
3877 int cw = xS(250), ch = yS(150), px, py;
3878 gui->get_pop_cursor(px, py);
3879 px -= cw/2; py -= ch/2;
3880 ConfirmRefWindow confirm(this, path, px, py, cw, ch);
3881 confirm.create_objects();
3882 int result = confirm.run_window();
3885 item.new_edl->save_xml(&file, path);
3886 file.terminate_string();
3887 if(file.write_to_file(path))
3888 eprintf(_("Cant write FileREF: %s"), path);
3899 // resize the indexable edits if the new_edl duration changed
3900 double duration = item.new_edl->tracks->total_length();
3901 double dt = duration - item.duration;
3902 if( fabs(dt) > 1e-4 )
3903 edl->tracks->update_idxbl_length(idxbl->id, dt);
3904 gui->unlock_window();
3905 gui->resource_thread->close_indexable(idxbl);
3906 remove_from_caches(idxbl);
3907 IndexFile::delete_index_files(preferences, idxbl);
3908 mainindexes->add_indexable(idxbl);
3909 mainindexes->start_build();
3910 awindow->gui->async_update_assets();
3911 gui->lock_window("MWindow::stack_pop");
3913 strcpy(session->filename, edl->path);
3914 update_project(LOADMODE_REPLACE);
3915 undo_after(_("open edl"), LOAD_ALL);
3917 gui->stack_button->update();
3920 int MWindow::save(EDL *edl, char *filename, int stat)
3923 edl->save_xml(&file, filename);
3924 file.terminate_string();
3925 if( file.write_to_file(filename) ) {
3926 eprintf(_("Couldn't open %s"), filename);
3930 char string[BCTEXTLEN];
3931 char *filename = stack.size() ?
3932 stack[0].edl->path : session->filename;
3933 sprintf(string, _("\"%s\" %jdC written"),
3934 filename, file.length());
3935 gui->lock_window("SaveAs::run");
3936 gui->show_message(string);
3937 gui->unlock_window();
3942 int MWindow::save(int save_as)
3944 char new_path[BCTEXTLEN]; new_path[0] = 0;
3945 char *path = stack.size() ? stack[0].edl->path : session->filename;
3946 if( save_as || !path[0] ) {
3947 if( ConfirmSave::get_save_path(this, new_path) )
3949 if( stack.size() ) {
3950 strcpy(path, new_path);
3951 set_titlebar(new_path);
3954 set_filename(new_path);
3955 gui->mainmenu->add_load(new_path);
3958 for( int i=stack.size(); --i>=0; ) {
3959 StackItem &item = stack[i];
3960 Indexable *idxbl = item.idxbl;
3961 if( !idxbl ) continue;
3962 if( idxbl->is_asset ) {
3963 Asset *asset = (Asset *)idxbl;
3964 if( asset->format == FILE_REF ) {
3965 if( save(item.new_edl, asset->path, 0) )
3969 else if( item.new_edl != idxbl )
3970 item.new_edl->overwrite_clip((EDL*)idxbl);
3972 EDL *new_edl = stack.size() ? stack[0].edl : edl;
3973 save(new_edl, path, 1);
3977 void MWindow::show_plugins()
3979 for( Track *track=edl->tracks->first; track; track=track->next ) {
3980 for( int i=0; i<track->plugin_set.size(); ++i ) {
3981 PluginSet *plugins = track->plugin_set[i];
3982 Plugin *plugin = plugins->get_first_plugin();
3983 for( ; plugin; plugin=(Plugin*)plugin->next ) {
3984 if( plugin->plugin_type == PLUGIN_STANDALONE &&
3986 show_plugin(plugin);
3992 void MWindow::clip_to_media()
3994 if( edl->session->proxy_scale != 1 ) {
3995 eprintf("Nesting not allowed when proxy scale != 1");
3999 awindow->gui->stop_vicon_drawing();
4000 int clips_total = session->drag_clips->total;
4001 for( int i=0; i<clips_total; ++i ) {
4002 EDL *clip = session->drag_clips->values[i];
4003 time_t dt; time(&dt);
4004 struct tm dtm; localtime_r(&dt, &dtm);
4005 char path[BCTEXTLEN], *cp = path, *ep = cp+sizeof(path)-1;
4006 // path_basename = "Nested_<date>-<time>_<basename>"
4007 cp += snprintf(cp, ep-cp, _("Nested_%02d%02d%02d-%02d%02d%02d_"),
4008 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
4009 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
4010 char *bp = strrchr(clip->local_session->clip_title, '/');
4011 bp = bp ? bp+1 : clip->local_session->clip_title;
4012 cp += snprintf(cp, ep-cp, "%s", bp);
4013 EDL *nested = edl->new_nested_clip(clip, path);
4014 edl->clips.remove(clip);
4015 clip->remove_user();
4016 mainindexes->add_indexable(nested);
4018 undo_after(_("clip2media"), LOAD_ALL);
4019 mainindexes->start_build();
4020 awindow->gui->async_update_assets();
4023 void MWindow::media_to_clip()
4026 int assets_total = session->drag_assets->total;
4027 for( int i=0; i<assets_total; ++i ) {
4028 Indexable *idxbl = session->drag_assets->values[i];
4029 if( idxbl->is_asset ) {
4030 eprintf(_("media is not EDL:\n%s"), idxbl->path);
4033 char clip_title[BCSTRLEN];
4037 sprintf(clip_title, _("Clip %d"), session->clip_number++);
4038 for( int i=0; name_ok && i<edl->clips.size(); ++i ) {
4039 char *title = edl->clips[i]->local_session->clip_title;
4040 if( !strcasecmp(clip_title, title) ) name_ok = 0;
4043 EDL *nested = (EDL *)idxbl;
4044 EDL *clip = edl->add_clip(nested);
4045 strcpy(clip->local_session->clip_title, clip_title);
4046 snprintf(clip->local_session->clip_notes,
4047 sizeof(clip->local_session->clip_notes),
4048 _("From: %s"), nested->path);
4050 undo_after(_("media2clip"), LOAD_ALL);
4051 awindow->gui->async_update_assets();
4054 int MWindow::create_ref(Asset *asset, EDL *ref)
4056 asset->format = FILE_REF;
4057 double secs = ref->tracks->total_length();
4058 int audio_channels = ref->session->audio_channels;
4059 asset->audio_data = audio_channels > 0 ? 1 : 0;
4060 asset->channels = audio_channels;
4061 asset->sample_rate = ref->session->sample_rate;
4062 asset->audio_length = audio_channels > 0 && secs > 0 ?
4063 secs * asset->sample_rate : 0;
4064 strcpy(asset->acodec, _("reference"));
4066 int video_layers = ref->session->video_channels;
4067 asset->video_data = video_layers > 0 ? 1 : 0;
4068 asset->layers = video_layers > 0 ? 1 : 0;
4069 asset->actual_width = ref->session->output_w;
4070 asset->actual_height = ref->session->output_h;
4071 asset->width = asset->actual_width;
4072 asset->height = asset->actual_height;
4073 asset->frame_rate = ref->session->frame_rate;
4074 asset->video_length = video_layers > 0 && secs > 0 ?
4075 secs * asset->frame_rate : 0;
4076 strcpy(asset->vcodec, _("reference"));
4080 void MWindow::update_preferences(Preferences *prefs)
4082 if( prefs != preferences )
4083 preferences->copy_from(prefs);
4084 if( cwindow->playback_engine )
4085 cwindow->playback_engine->preferences->copy_from(prefs);
4086 for(int i = 0; i < vwindows.size(); i++) {
4087 VWindow *vwindow = vwindows[i];
4088 if( !vwindow->is_running() ) continue;
4089 if( vwindow->playback_engine )
4090 vwindow->playback_engine->preferences->copy_from(prefs);
4092 for(int i = 0; i < zwindows.size(); i++) {
4093 ZWindow *zwindow = zwindows[i];
4094 if( !zwindow->is_running() ) continue;
4095 if( zwindow->zgui->playback_engine )
4096 zwindow->zgui->playback_engine->preferences->copy_from(prefs);
4100 void MWindow::update_vwindow()
4102 for( int i=0; i<vwindows.size(); ++i ) {
4103 VWindow *vwindow = vwindows[i];
4104 if( vwindow->is_running() ) {
4105 vwindow->gui->lock_window("MWindow::update_vwindow");
4107 vwindow->gui->unlock_window();
4112 void MWindow::remove_indexfile(Indexable *indexable)
4114 if( !indexable->is_asset ) return;
4116 IndexFile::delete_index_files(preferences, indexable);
4119 void MWindow::rebuild_indices()
4121 for(int i = 0; i < session->drag_assets->total; i++)
4123 Indexable *indexable = session->drag_assets->get(i);
4124 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4125 remove_indexfile(indexable);
4126 // Schedule index build
4127 indexable->index_state->remove_user();
4128 indexable->index_state = new IndexState;
4129 IndexFile::delete_index_files(preferences, indexable);
4130 if( indexable->is_asset ) {
4131 Asset *asset = (Asset *)indexable;
4132 if( asset->format != FILE_PCM ) {
4133 asset->format = FILE_UNKNOWN;
4134 asset->reset_audio();
4136 asset->reset_video();
4137 remove_from_caches(asset);
4138 // File file; // re-probe the asset
4139 // file.open_file(preferences, asset, 1, 0);
4141 mainindexes->add_indexable(indexable);
4143 // still in render engine
4144 sync_parameters(CHANGE_ALL);
4145 awindow->gui->async_update_assets();
4146 mainindexes->start_build();
4150 void MWindow::get_backup_path(char *path, int len)
4152 char *cp = path, *ep = cp + len-1;
4153 cp += snprintf(cp, ep-cp, "%s/", File::get_config_path());
4154 int idx = stack.size();
4155 cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx);
4158 void MWindow::save_backup()
4162 edl->set_path(session->filename);
4164 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
4165 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
4166 File::get_config_path(), BACKUP_FILE1);
4167 get_backup_path(backup_path, sizeof(backup_path));
4168 rename(backup_path, backup_path1);
4169 edl->save_xml(&file, backup_path);
4170 file.terminate_string();
4172 fs.complete_path(backup_path);
4174 if(file.write_to_file(backup_path)) {
4176 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
4177 gui->show_message(string2);
4182 void MWindow::load_backup()
4184 ArrayList<char*> path_list;
4185 path_list.set_array_delete();
4187 char backup_path[BCTEXTLEN];
4188 get_backup_path(backup_path, sizeof(backup_path));
4190 fs.complete_path(backup_path);
4192 path_list.append(out_path = new char[strlen(backup_path) + 1]);
4193 strcpy(out_path, backup_path);
4195 load_filenames(&path_list, LOADMODE_REPLACE, LOADMODE_EDL_CLIP, 0);
4196 edl->local_session->clip_title[0] = 0;
4197 // This is unique to backups since the path of the backup is different than the
4198 // path of the project.
4199 set_filename(edl->path);
4200 path_list.remove_all_objects();
4205 void MWindow::save_undo_data()
4207 if( stack.size() > 0 ) return;
4208 if( !preferences->perpetual_session ) return;
4209 char perpetual_path[BCTEXTLEN];
4210 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4211 File::get_config_path(), PERPETUAL_FILE);
4212 FILE *fp = fopen(perpetual_path,"w");
4218 void MWindow::load_undo_data()
4220 if( stack.size() > 0 ) return;
4221 if( !preferences->perpetual_session ) return;
4222 char perpetual_path[BCTEXTLEN];
4223 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4224 File::get_config_path(), PERPETUAL_FILE);
4225 FILE *fp = fopen(perpetual_path,"r");
4229 undo_after(_("perpetual load"), LOAD_ALL);
4233 void MWindow::remove_undo_data()
4235 if( stack.size() > 0 ) return;
4236 char perpetual_path[BCTEXTLEN];
4237 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4238 File::get_config_path(), PERPETUAL_FILE);
4239 ::remove(perpetual_path);
4242 int MWindow::copy_target(const char *path, const char *target)
4244 int ifd = ::open(path, O_RDONLY);
4246 eprintf("Cannot open asset: %s", path);
4250 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
4253 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
4254 char progress_title[BCTEXTLEN];
4255 sprintf(progress_title, _("Copying: %s\n"), target);
4256 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
4258 int64_t count = 0, len = -1;
4259 int bfrsz = 0x100000;
4260 uint8_t *bfr = new uint8_t[bfrsz];
4261 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
4262 if( len != ::write(ofd, bfr, len) ) {
4263 eprintf("Error writing: %s", target);
4266 if( progress.is_cancelled() ) {
4270 progress.update(count += len, 1);
4275 progress.stop_progress();
4277 eprintf("Error reading: %s", path);
4282 eprintf("Cannot create asset target: %s", target);
4287 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
4289 char target[BCTEXTLEN];
4291 const char *bp = real_path, *cp = bp;
4292 const char *lp = link_path, *np = lp;
4293 char *tp = target, *ep = tp+sizeof(target)-1, lch;
4294 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
4295 if( lch == '/' ) { np = lp; cp = bp; }
4297 while( tp<ep && *np ) {
4298 if( *np++ != '/' ) continue;
4299 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
4301 while( tp<ep && *cp ) *tp++ = *cp++;
4305 strcpy(target, real_path);
4306 if( symlink(target, link_path) ) {
4307 eprintf("Cannot create symlink: %s", link_path);
4313 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
4315 char dir_path[BCTEXTLEN];
4316 strcpy(dir_path, dir);
4318 fs.complete_path(dir_path);
4321 if( !stat(dir_path, &st) ) {
4322 if( !S_ISDIR(st.st_mode) ) {
4323 eprintf("Path exists and is not a directory\n%s", dir_path);
4328 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
4329 eprintf("Cannot create directory\n%s", dir_path);
4333 char *real_dir = realpath(dir_path, 0);
4334 strcpy(dir_path, real_dir);
4337 EDL *save_edl = new EDL;
4338 save_edl->create_objects();
4339 save_edl->copy_all(edl);
4341 char progress_title[BCTEXTLEN];
4342 sprintf(progress_title, _("Saving to %s:\n"), dir);
4343 int total_assets = save_edl->assets->total();
4344 gui->lock_window("MWindow::save_project");
4345 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
4346 gui->unlock_window();
4349 Asset *current = save_edl->assets->first;
4350 for( int i=0; !ret && current; ++i, current=NEXT ) {
4351 char *path = current->path;
4352 if( ::stat(path, &st) ) {
4353 eprintf("Asset not found: %s", path);
4356 char *real_path = realpath(path, 0);
4357 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
4358 char link_path[BCTEXTLEN];
4359 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
4361 if( strcmp(real_path, link_path) ) {
4362 if( !::lstat(link_path, &st) ) {
4364 ::remove(link_path);
4370 eprintf("copy/link to self, skippped: %s", path);
4374 if( save_mode == SAVE_PROJECT_COPY ) {
4375 if( copy_target(real_path, link_path) )
4379 link_target(real_path, link_path,
4380 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
4384 strcpy(path, link_path);
4386 if( progress->is_cancelled() ) break;
4387 progress->update(i);
4390 progress->stop_progress();
4393 char *cp = strrchr(dir_path,'/');
4394 char *bp = cp ? cp+1 : dir_path;
4395 char filename[BCTEXTLEN];
4396 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
4397 save_edl->set_path(filename);
4399 save_edl->save_xml(&file, filename);
4400 file.terminate_string();
4402 if( !file.write_to_file(filename) ) {
4403 char string[BCTEXTLEN];
4404 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
4405 gui->lock_window("SaveProject::run 2");
4406 gui->show_message(string);
4407 gui->unlock_window();
4408 gui->mainmenu->add_load(filename);
4411 eprintf(_("Couldn't open %s."), filename);
4413 save_edl->remove_user();
4416 gui->lock_window("MWindow::save_project");
4417 ArrayList<char*> filenames;
4418 filenames.append(filename);
4419 load_filenames(&filenames);
4420 gui->unlock_window();
4425 static inline int gcd(int m, int n)
4428 if( m < n ) { r = m; m = n; n = r; }
4429 while( (r = m % n) != 0 ) { m = n; n = r; }
4433 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4436 if(!width || !height) return 1;
4437 if( width == 720 && (height == 480 || height == 576) ) {
4438 w = 4; h = 3; return 0; // for NTSC and PAL
4440 double ar = (double)width / height;
4441 // square-ish pixels
4442 if( EQUIV(ar, 1.0000) ) return 0;
4443 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4444 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4445 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4446 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4447 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4448 int ww = width, hh = height;
4449 // numerator, denominator must be under mx
4450 int mx = 255, n = gcd(ww, hh);
4451 if( n > 1 ) { ww /= n; hh /= n; }
4452 // search near height in case extra/missing lines
4453 if( ww >= mx || hh >= mx ) {
4454 double err = height; // +/- 2 percent height
4455 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4456 int iw = width, ih = height+i;
4457 if( (n=gcd(iw, ih)) > 1 ) {
4458 int u = iw/n; if( u >= mx ) continue;
4459 int v = ih/n; if( v >= mx ) continue;
4460 double r = (double) u/v, er = fabs(ar-r);
4461 if( er >= err ) continue;
4462 err = er; ww = u; hh = v;
4471 void MWindow::reset_caches()
4473 int locked = gui->get_window_lock();
4474 if( locked ) gui->unlock_window();
4475 awindow->gui->stop_vicon_drawing(1);
4476 frame_cache->remove_all();
4477 wave_cache->remove_all();
4478 audio_cache->remove_all();
4479 video_cache->remove_all();
4480 if( cwindow->playback_engine ) {
4481 if( cwindow->playback_engine->audio_cache )
4482 cwindow->playback_engine->audio_cache->remove_all();
4483 if( cwindow->playback_engine->video_cache )
4484 cwindow->playback_engine->video_cache->remove_all();
4486 for(int i = 0; i < vwindows.size(); i++) {
4487 VWindow *vwindow = vwindows[i];
4488 if( !vwindow->is_running() ) continue;
4489 if( !vwindow->playback_engine ) continue;
4490 if( vwindow->playback_engine->audio_cache )
4491 vwindow->playback_engine->audio_cache->remove_all();
4492 if( vwindow->playback_engine->video_cache )
4493 vwindow->playback_engine->video_cache->remove_all();
4495 if( locked ) gui->lock_window("MWindow::reset_caches");
4498 void MWindow::remove_from_caches(Indexable *idxbl)
4500 awindow->gui->stop_vicon_drawing(1);
4501 frame_cache->remove_item(idxbl);
4502 wave_cache->remove_item(idxbl);
4503 if( gui->render_engine &&
4504 gui->render_engine_id == idxbl->id ) {
4505 delete gui->render_engine;
4506 gui->render_engine = 0;
4508 gui->resource_thread->close_indexable(idxbl);
4509 if( !idxbl->is_asset ) return;
4510 Asset *asset = (Asset *)idxbl;
4511 audio_cache->delete_entry(asset);
4512 video_cache->delete_entry(asset);
4513 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4514 cwindow->playback_engine->audio_cache->delete_entry(asset);
4515 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4516 cwindow->playback_engine->video_cache->delete_entry(asset);
4517 for(int i = 0; i < vwindows.size(); i++) {
4518 VWindow *vwindow = vwindows[i];
4519 if( !vwindow->is_running() ) continue;
4520 if( !vwindow->playback_engine ) continue;
4521 if( vwindow->playback_engine->audio_cache )
4522 vwindow->playback_engine->audio_cache->delete_entry(asset);
4523 if( vwindow->playback_engine->video_cache )
4524 vwindow->playback_engine->video_cache->delete_entry(asset);
4526 for(int i = 0; i < zwindows.size(); i++) {
4527 ZWindow *zwindow = zwindows[i];
4528 if( !zwindow->is_running() ) continue;
4529 if( zwindow->zgui->playback_engine->audio_cache )
4530 zwindow->zgui->playback_engine->audio_cache->delete_entry(asset);
4531 if( zwindow->zgui->playback_engine->video_cache )
4532 zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
4534 awindow->gui->start_vicon_drawing();
4537 void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
4538 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4540 awindow->gui->stop_vicon_drawing(1);
4542 // Remove from VWindow.
4544 for(int i = 0; i < drag_clips->total; i++) {
4545 for(int j = 0; j < vwindows.size(); j++) {
4546 VWindow *vwindow = vwindows[j];
4547 if( !vwindow->is_running() ) continue;
4548 if(drag_clips->get(i) == vwindow->get_edl()) {
4549 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4550 vwindow->delete_source(1, 1);
4551 vwindow->gui->unlock_window();
4558 for(int i = 0; i < drag_assets->size(); i++) {
4559 for(int j = 0; j < vwindows.size(); j++) {
4560 VWindow *vwindow = vwindows[j];
4561 if( !vwindow->is_running() ) continue;
4562 if(drag_assets->get(i) == vwindow->get_source()) {
4563 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4564 vwindow->delete_source(1, 1);
4565 vwindow->gui->unlock_window();
4570 for(int i = 0; i < drag_assets->total; i++) {
4571 Indexable *indexable = drag_assets->get(i);
4572 if(indexable->is_asset) remove_from_caches(indexable);
4575 if( delete_indexes ) {
4576 for(int i = 0; i < drag_assets->size(); i++) {
4577 Indexable *indexable = drag_assets->get(i);
4578 remove_indexfile(indexable);
4583 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4584 if(push_undo) undo_before();
4585 if(drag_assets) edl->remove_from_project(drag_assets);
4586 if(drag_clips) edl->remove_from_project(drag_clips);
4587 if(redraw) save_backup();
4588 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4592 gui->lock_window("MWindow::remove_assets_from_project 3");
4593 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4594 gui->unlock_window();
4596 // Removes from playback here
4597 sync_parameters(CHANGE_ALL);
4600 awindow->gui->async_update_assets();
4603 void MWindow::remove_assets_from_disk()
4605 remove_assets_from_project(1, 1, 1,
4606 session->drag_assets, session->drag_clips);
4609 for(int i = 0; i < session->drag_assets->total; i++)
4611 remove(session->drag_assets->get(i)->path);
4615 void MWindow::dump_plugins(FILE *fp)
4617 if( !plugindb ) return;
4618 for(int i = 0; i < plugindb->total; i++)
4620 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4621 " synth=%d transition=%d theme=%d %s\n",
4622 plugindb->get(i)->plugin_type,
4623 plugindb->get(i)->audio,
4624 plugindb->get(i)->video,
4625 plugindb->get(i)->realtime,
4626 plugindb->get(i)->multichannel,
4627 plugindb->get(i)->get_synthesis(),
4628 plugindb->get(i)->transition,
4629 plugindb->get(i)->theme,
4630 plugindb->get(i)->title);
4634 void MWindow::dump_edl(FILE *fp)
4640 void MWindow::dump_undo(FILE *fp)
4646 void MWindow::dump_exe(FILE *fp)
4648 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4649 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4651 int ret = -1, n = 100;
4652 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4653 exe_path[len] = 0; strcpy(proc_path, exe_path);
4656 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4659 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4660 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4661 struct tm *tm = localtime(&st.st_mtime);
4663 strftime(mtime, sizeof(mtime), "%F %T", tm);
4664 fprintf(fp,"mtime: %s\n", mtime);
4666 // people hit ctl-c waiting for this
4667 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4668 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4671 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4672 int64_t maxsz = 1024*pagsz;
4673 int64_t size = st.st_size, pos = 0;
4675 while( (bfrsz = size-pos) > 0 ) {
4676 if( bfrsz > maxsz ) bfrsz = maxsz;
4677 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4678 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4679 if( bfr == MAP_FAILED ) break;
4680 sha1.addBytes(bfr, bfrsz);
4685 ret = pos < size ? EIO : 0;
4686 fprintf(fp, "SHA1: ");
4687 uint8_t digest[20]; sha1.computeHash(digest);
4688 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4689 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4690 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4695 void MWindow::dump_caches(FILE *fp)
4697 fprintf(fp, "audio cache: ");
4698 audio_cache->dump(fp);
4699 fprintf(fp, "video cache: ");
4700 video_cache->dump(fp);
4703 void MWindow::trap_hook(FILE *fp, void *vp)
4705 MWindow *mwindow = (MWindow *)vp;
4706 // fprintf(fp, "\nPLUGINS:\n");
4707 // mwindow->dump_plugins(fp);
4708 fprintf(fp, "\nEDL:\n");
4709 mwindow->dump_edl(fp);
4710 fprintf(fp, "\nUNDO:\n");
4711 mwindow->dump_undo(fp);
4712 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4713 mwindow->dump_exe(fp);
4714 fprintf(fp, "\nCACHES:\n");
4715 mwindow->dump_caches(fp);
4723 int MWindow::save_defaults()
4725 gui->save_defaults(defaults);
4726 edl->save_defaults(defaults);
4727 session->save_defaults(defaults);
4728 preferences->save_defaults(defaults);
4730 for(int i = 0; i < plugin_guis->total; i++)
4732 // Pointer comparison
4733 plugin_guis->get(i)->save_defaults();
4735 awindow->save_defaults(defaults);
4741 int MWindow::run_script(FileXML *script)
4743 int result = 0, result2 = 0;
4744 while(!result && !result2)
4746 result = script->read_tag();
4749 if(script->tag.title_is("new_project"))
4751 // Run new in immediate mode.
4752 // gui->mainmenu->new_project->run_script(script);
4755 if(script->tag.title_is("record"))
4757 // Run record as a thread. It is a terminal command.
4759 // Will read the complete scipt file without letting record read it if not
4765 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4772 // ================================= synchronization
4775 int MWindow::interrupt_indexes()
4777 mainprogress->cancelled = 1;
4778 mainindexes->interrupt_build();
4784 void MWindow::next_time_format()
4786 switch( edl->session->time_format ) {
4787 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4788 case TIME_HMSF: edl->session->time_format = TIME_TIMECODE; break;
4789 case TIME_TIMECODE: edl->session->time_format = TIME_FRAMES; break;
4790 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES; break;
4791 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4792 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SECONDS; break;
4793 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4794 case TIME_FEET_FRAMES: edl->session->time_format = TIME_HMS; break;
4796 time_format_common();
4799 void MWindow::prev_time_format()
4801 switch( edl->session->time_format ) {
4802 case TIME_HMS: edl->session->time_format = TIME_FEET_FRAMES; break;
4803 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4804 case TIME_TIMECODE: edl->session->time_format = TIME_HMSF; break;
4805 case TIME_FRAMES: edl->session->time_format = TIME_TIMECODE; break;
4806 case TIME_SAMPLES: edl->session->time_format = TIME_FRAMES; break;
4807 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4808 case TIME_SECONDS: edl->session->time_format = TIME_SAMPLES_HEX; break;
4809 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4812 time_format_common();
4815 void MWindow::time_format_common()
4817 gui->lock_window("MWindow::next_time_format");
4818 gui->redraw_time_dependancies();
4821 char string[BCTEXTLEN], string2[BCTEXTLEN];
4822 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4823 gui->show_message(string);
4825 gui->unlock_window();
4829 int MWindow::set_filename(const char *filename)
4831 if( filename != session->filename )
4832 strcpy(session->filename, filename);
4833 if( filename != edl->path )
4834 strcpy(edl->path, filename);
4835 return set_titlebar(filename);
4838 int MWindow::set_titlebar(const char *filename)
4840 if( !gui ) return 0;
4843 char string[BCTEXTLEN], string2[BCTEXTLEN];
4844 dir.extract_name(string, filename);
4845 sprintf(string2, PROGRAM_NAME ": %s", string);
4846 gui->set_title(string2);
4849 gui->set_title(PROGRAM_NAME);
4854 int MWindow::set_loop_boundaries()
4856 double start = edl->local_session->get_selectionstart();
4857 double end = edl->local_session->get_selectionend();
4865 if(edl->tracks->total_length())
4868 end = edl->tracks->total_length();
4875 if(edl->local_session->loop_playback && start != end)
4877 edl->local_session->loop_start = start;
4878 edl->local_session->loop_end = end;
4889 int MWindow::reset_meters()
4891 cwindow->gui->lock_window("MWindow::reset_meters 1");
4892 cwindow->gui->meters->reset_meters();
4893 cwindow->gui->unlock_window();
4895 for(int j = 0; j < vwindows.size(); j++) {
4896 VWindow *vwindow = vwindows[j];
4897 if( !vwindow->is_running() ) continue;
4898 vwindow->gui->lock_window("MWindow::reset_meters 2");
4899 vwindow->gui->meters->reset_meters();
4900 vwindow->gui->unlock_window();
4903 lwindow->gui->lock_window("MWindow::reset_meters 3");
4904 lwindow->gui->panel->reset_meters();
4905 lwindow->gui->unlock_window();
4907 gui->lock_window("MWindow::reset_meters 4");
4908 gui->reset_meters();
4909 gui->unlock_window();
4914 void MWindow::resync_guis()
4918 gui->lock_window("MWindow::resync_guis");
4919 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4920 gui->unlock_window();
4922 cwindow->gui->lock_window("MWindow::resync_guis");
4923 cwindow->gui->resize_event(cwindow->gui->get_w(),
4924 cwindow->gui->get_h());
4925 int channels = edl->session->audio_channels;
4926 cwindow->gui->meters->set_meters(channels, 1);
4927 cwindow->gui->flush();
4928 cwindow->gui->unlock_window();
4930 for(int i = 0; i < vwindows.size(); i++) {
4931 VWindow *vwindow = vwindows[i];
4932 if( !vwindow->is_running() ) continue;
4933 vwindow->gui->lock_window("MWindow::resync_guis");
4934 vwindow->gui->resize_event(vwindow->gui->get_w(),
4935 vwindow->gui->get_h());
4936 vwindow->gui->meters->set_meters(channels, 1);
4937 vwindow->gui->flush();
4938 vwindow->gui->unlock_window();
4941 lwindow->gui->lock_window("MWindow::resync_guis");
4942 lwindow->gui->panel->set_meters(channels, 1);
4943 lwindow->gui->flush();
4944 lwindow->gui->unlock_window();
4947 if(((edl->session->output_w % 4) ||
4948 (edl->session->output_h % 4)) &&
4949 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4951 MainError::show_error(
4952 _("This project's dimensions are not multiples of 4 so\n"
4953 "it can't be rendered by OpenGL."));
4958 sync_parameters(CHANGE_ALL);
4961 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4963 File *file = new File;
4964 EDLSession *session = edl->session;
4965 double old_framerate = session->frame_rate;
4966 double old_samplerate = session->sample_rate;
4967 int old_auto_keyframes = session->auto_keyframes;
4968 session->auto_keyframes = 0;
4969 int result = file->open_file(preferences, asset, 1, 0);
4970 if( !result && delete_tracks > 0 )
4972 int video_layers = asset->get_video_layers();
4973 if( !result && asset->video_data && vstream < video_layers ) {
4974 // try to get asset up to date, may fail
4975 file->select_video_stream(asset, vstream);
4976 // either way use what was/is there.
4977 double framerate = asset->get_frame_rate();
4978 int width = asset->get_w();
4979 int height = asset->get_h();
4981 // must be multiple of 4 for opengl
4982 width = (width+3) & ~3; height = (height+3) & ~3;
4984 int driver = session->playback_config->vconfig->driver;
4985 int color_model = file->get_best_colormodel(asset, driver);
4986 // color_model = BC_CModels::is_yuv(color_model) ?
4987 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4988 // BC_CModels::is_float(color_model) ?
4989 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4990 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4991 // have alpha for now
4992 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4993 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4994 session->color_model = color_model;
4995 session->output_w = width;
4996 session->output_h = height;
4997 session->frame_rate = framerate;
4998 // not, asset->actual_width/actual_height
4999 asset->width = session->output_w;
5000 asset->height = session->output_h;
5001 asset->frame_rate = session->frame_rate;
5002 create_aspect_ratio(session->aspect_w, session->aspect_h,
5003 session->output_w, session->output_h);
5004 Track *track = edl->tracks->first;
5005 for( Track *next_track=0; track; track=next_track ) {
5006 next_track = track->next;
5007 if( track->data_type != TRACK_VIDEO ) continue;
5008 if( delete_tracks ) {
5009 Edit *edit = track->edits->first;
5010 for( Edit *next_edit=0; edit; edit=next_edit ) {
5011 next_edit = edit->next;
5012 if( edit->channel != vstream ||
5013 !edit->asset || !edit->asset->is_asset ||
5014 !asset->equivalent(*edit->asset,1,1,edl) )
5018 if( track->edits->first ) {
5019 track->track_w = edl->session->output_w;
5020 track->track_h = edl->session->output_h;
5022 else if( delete_tracks )
5023 edl->tracks->delete_track(track, 0);
5026 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
5028 if( !result && asset->audio_data && asset->channels > 0 ) {
5029 session->sample_rate = asset->get_sample_rate();
5030 int64_t channel_mask = 0;
5031 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
5032 file->get_audio_for_video(vstream, astream, channel_mask);
5033 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
5034 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
5036 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
5037 if( channels < 1 ) channels = 1;
5038 if( channels > 6 ) channels = 6;
5039 session->audio_tracks = session->audio_channels = channels;
5041 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
5042 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
5043 remap_audio(MWindow::AUDIO_1_TO_1);
5045 if( delete_tracks ) {
5046 Track *track = edl->tracks->first;
5047 for( Track *next_track=0; track; track=next_track ) {
5048 next_track = track->next;
5049 if( track->data_type != TRACK_AUDIO ) continue;
5050 Edit *edit = track->edits->first;
5051 for( Edit *next_edit=0; edit; edit=next_edit ) {
5052 next_edit = edit->next;
5053 if( !((1<<edit->channel) & channel_mask) ||
5054 !edit->asset || !edit->asset->is_asset ||
5055 !asset->equivalent(*edit->asset,1,1,edl) )
5058 if( !track->edits->first )
5059 edl->tracks->delete_track(track, 0);
5063 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
5066 session->auto_keyframes = old_auto_keyframes;
5067 if( !result && delete_tracks > 0 ) {
5069 undo_after(_("select asset"), LOAD_ALL);
5075 int MWindow::select_asset(int vtrack, int delete_tracks)
5077 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
5079 track = edl->tracks->get(vtrack, TRACK_AUDIO);
5080 if( !track ) return 1;
5081 Edit *edit = track->edits->first;
5082 if( !edit ) return 1;
5083 Asset *asset = edit->asset;
5084 if( !asset || !asset->is_asset ) return 1;
5085 return select_asset(asset, edit->channel, 0, delete_tracks);
5088 void MWindow::dump_plugindb(FILE *fp)
5090 if( !plugindb ) return;
5091 for(int i = 0; i < plugindb->total; i++)
5092 plugindb->get(i)->dump(fp);
5095 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
5098 double unit_position = edl->local_session->get_selectionstart(1);
5099 unit_position = patch->track->to_units(unit_position, 0);
5101 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
5102 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5105 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
5108 double unit_position = edl->local_session->get_selectionstart(1);
5109 unit_position = patch->track->to_units(unit_position, 0);
5111 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
5112 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5115 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
5118 double unit_position = edl->local_session->get_selectionstart(1);
5119 unit_position = patch->track->to_units(unit_position, 0);
5121 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
5122 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5125 PatchGUI *MWindow::get_patchgui(Track *track)
5127 PatchGUI *patchgui = 0;
5128 TimelinePane **panes = gui->pane;
5129 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
5130 if( !panes[i] ) continue;
5131 PatchBay *patchbay = panes[i]->patchbay;
5132 if( !patchbay ) continue;
5133 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
5134 if( patchbay->patches.values[j]->track == track )
5135 patchgui = patchbay->patches.values[j];
5141 int MWindow::get_cpus(int out_w, int out_h)
5143 if( !out_w ) out_w = edl->session->output_w;
5144 if( !out_h ) out_h = edl->session->output_h;
5145 int cpus = out_w*out_h/0x80000 + 1;
5146 if( cpus > preferences->processors )
5147 cpus = preferences->processors;
5150 int MWindow::get_cpus()
5152 return get_cpus(edl->session->output_w, edl->session->output_h);
5155 void MWindow::draw_trackmovement()
5157 if( !redraw_tracks )
5158 redraw_tracks = new DrawTrackMovement(this);
5159 redraw_tracks->start();
5162 DrawTrackMovement::DrawTrackMovement(MWindow *mwindow)
5165 this->mwindow = mwindow;
5167 DrawTrackMovement::~DrawTrackMovement()
5172 void DrawTrackMovement::run()
5174 mwindow->gui->lock_window("DrawTrackMovement::run");
5175 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
5176 mwindow->gui->draw_trackmovement();
5177 mwindow->gui->unlock_window();
5181 ConfirmRefWindow::ConfirmRefWindow(MWindow *mwindow, char *path,
5182 int px, int py, int cw, int ch)
5183 : BC_Window(_(PROGRAM_NAME ": Confirm update"), px, py, cw, ch, cw, ch)
5185 this->mwindow = mwindow;
5189 ConfirmRefWindow::~ConfirmRefWindow()
5193 void ConfirmRefWindow::create_objects()
5195 lock_window("ConfirmRefWindow::create_objects()");
5196 int x = xS(10), y = yS(10), pad = yS(5);
5198 add_subwindow(title = new BC_Title(x, y, _("FileREF not updated:")));
5199 y += title->get_h() + pad;
5200 BC_TextBox *text_box;
5201 add_subwindow(text_box = new BC_TextBox(x,y, get_w()-2*x, 1, path));
5202 y += text_box->get_h() + 2*pad;
5203 add_subwindow(title = new BC_Title(x, y, _("Save file ref changes?")));
5204 add_subwindow(new BC_OKButton(this));
5205 add_subwindow(new BC_CancelButton(this));