3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "aboutprefs.h"
25 #include "audioalsa.h"
27 #include "awindowgui.h"
29 #include "batchrender.h"
30 #include "bccmodels.h"
31 #include "bcdisplayinfo.h"
32 #include "bcprogressbox.h"
33 #include "bcsignals.h"
40 #include "channeldb.h"
41 #include "channelinfo.h"
44 #include "commercials.h"
45 #include "confirmsave.h"
47 #include "cplayback.h"
49 #include "cwindowgui.h"
51 #include "cwindowtool.h"
53 #include "devicedvbinput.inc"
54 #include "dvdcreate.h"
55 #include "editpanel.h"
57 #include "edlsession.h"
59 #include "fileformat.h"
61 #include "filesystem.h"
63 #include "floatautos.h"
64 #include "framecache.h"
66 #include "gwindowgui.h"
67 #include "keyframegui.h"
68 #include "indexfile.h"
70 #include "interlacemodes.h"
72 #include "levelwindowgui.h"
73 #include "levelwindow.h"
74 #include "loadfile.inc"
75 #include "localsession.h"
76 #include "maincursor.h"
77 #include "mainerror.h"
78 #include "mainindexes.h"
80 #include "mainprogress.h"
81 #include "mainsession.h"
84 #include "mixersalign.h"
86 #include "mwindowgui.h"
91 #include "playback3d.h"
92 #include "playbackengine.h"
94 #include "pluginserver.h"
95 #include "pluginset.h"
96 #include "preferences.h"
99 #include "recordmonitor.h"
100 #include "recordlabel.h"
101 #include "removefile.h"
103 #include "resourcethread.h"
104 #include "savefile.inc"
105 #include "samplescroll.h"
108 #include "sighandler.h"
109 #include "splashgui.h"
110 #include "statusbar.h"
112 #include "threadloader.h"
114 #include "timelinepane.h"
115 #include "tipwindow.h"
116 #include "trackcanvas.h"
118 #include "tracking.h"
119 #include "trackscroll.h"
121 #include "transition.h"
122 #include "transportque.h"
125 #include "versioninfo.h"
127 #include "videodevice.inc"
128 #include "videowindow.h"
129 #include "vplayback.h"
130 #include "vwindowgui.h"
132 #include "wavecache.h"
138 #include "zwindowgui.h"
139 #include "exportedl.h"
141 #include "defaultformats.h"
142 #include "ntsczones.h"
149 #include <sys/types.h>
150 #include <sys/stat.h>
151 #include <sys/time.h>
152 #include <sys/mman.h>
153 #include <sys/file.h>
164 // Hack for libdv to remove glib dependancy
167 // g_log (const char *log_domain,
169 // const char *format,
175 // g_logv (const char *log_domain,
177 // const char *format,
185 extern long cin_timezone;
187 ArrayList<PluginServer*>* MWindow::plugindb = 0;
188 Commercials* MWindow::commercials = 0;
194 run_lock = new Mutex("MWindow::run_lock");
195 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
196 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
197 vwindows_lock = new Mutex("MWindow::vwindows_lock");
198 zwindows_lock = new Mutex("MWindow::zwindows_lock");
199 brender_lock = new Mutex("MWindow::brender_lock");
200 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
205 undo_command = COMMAND_NONE;
209 commercial_active = 0;
221 strcpy(cin_lang,"en");
222 channeldb_buz = new ChannelDB;
223 channeldb_v4l2jpeg = new ChannelDB;
226 keyframe_threads = 0;
253 // Need to delete brender temporary here.
256 run_lock->lock("MWindow::~MWindow");
258 //printf("MWindow::~MWindow %d\n", __LINE__);
259 if( wwindow && wwindow->is_running() )
260 wwindow->close_window();
261 if( twindow && twindow->is_running() )
262 twindow->close_window();
263 gui->remote_control->deactivate();
266 gui->channel_info->stop();
269 delete create_bd; create_bd = 0;
270 delete create_dvd; create_dvd = 0;
272 delete shuttle; shuttle = 0;
275 delete wintv; wintv = 0;
278 delete x10tv; x10tv = 0;
280 delete batch_render; batch_render = 0;
281 delete convert_render; convert_render = 0;
282 delete render; render = 0;
283 delete mixers_align; mixers_align = 0;
285 if( commercials && !commercials->remove_user() ) commercials = 0;
287 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
288 // Save defaults for open plugins
289 plugin_gui_lock->lock("MWindow::~MWindow");
290 for(int i = 0; i < plugin_guis->size(); i++) {
291 plugin_guis->get(i)->hide_gui();
292 delete_plugin(plugin_guis->get(i));
294 plugin_gui_lock->unlock();
295 hide_keyframe_guis();
298 // Give up and go to a movie
299 // cant run valgrind if this is used
301 gui->del_keyboard_listener(
302 (int (BC_WindowBase::*)(BC_WindowBase *))
303 &MWindowGUI::keyboard_listener);
305 // release the hounds
306 if( awindow && awindow->gui ) awindow->gui->close(0);
307 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
308 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
309 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
310 vwindows.remove_all_objects();
311 zwindows.remove_all_objects();
313 if( awindow ) awindow->join();
314 if( cwindow ) cwindow->join();
315 if( lwindow ) lwindow->join();
316 if( gwindow ) gwindow->join();
319 // one at a time, or nouveau chokes
320 #define close_gui(win) if( win ) { \
321 if( win->gui ) win->gui->close(0); \
327 vwindows.remove_all_objects();
328 zwindows.remove_all_objects();
333 dead_plugins->remove_all_objects();
334 // must delete theme before destroying plugindb
335 // theme destructor will be deleted by delete_plugins
336 delete theme; theme = 0;
339 keyframe_threads->remove_all_objects();
340 colormodels.remove_all_objects();
341 delete awindow; awindow = 0;
342 delete lwindow; lwindow = 0;
343 delete twindow; twindow = 0;
344 delete wwindow; wwindow = 0;
345 delete gwindow; gwindow = 0;
346 delete cwindow; cwindow = 0;
348 delete mainindexes; mainindexes = 0;
349 delete mainprogress; mainprogress = 0;
350 delete audio_cache; audio_cache = 0; // delete the cache after the assets
351 delete video_cache; video_cache = 0; // delete the cache after the assets
352 delete frame_cache; frame_cache = 0;
353 delete wave_cache; wave_cache = 0;
354 delete plugin_guis; plugin_guis = 0;
355 delete dead_plugins; dead_plugins = 0;
356 delete keyframe_threads; keyframe_threads = 0;
357 delete undo; undo = 0;
358 delete preferences; preferences = 0;
359 delete exportedl; exportedl = 0;
360 delete session; session = 0;
361 delete defaults; defaults = 0;
362 delete assets; assets = 0;
363 delete splash_window; splash_window = 0;
364 if( !edl->Garbage::remove_user() ) edl = 0;
365 delete channeldb_buz;
366 delete channeldb_v4l2jpeg;
367 // This must be last thread to exit
368 delete playback_3d; playback_3d = 0;
369 delete dead_plugin_lock;
370 delete plugin_gui_lock;
371 delete vwindows_lock;
372 delete zwindows_lock;
374 delete keyframe_gui_lock;
375 colormodels.remove_all_objects();
376 interlace_project_modes.remove_all_objects();
377 interlace_asset_modes.remove_all_objects();
378 sighandler->terminate();
389 void MWindow::init_error()
391 MainError::init_error(this);
394 void MWindow::finit_error()
396 MainError::finit_error();
399 void MWindow::create_defaults_path(char *string, const char *config_file)
401 // set the .bcast path
404 sprintf(string, "%s/", File::get_config_path());
405 fs.complete_path(string);
406 if(!fs.is_dir(string))
407 fs.create_dir(string);
410 strcat(string, config_file);
412 const char *MWindow::default_std()
414 char buf[BCTEXTLEN], *p = 0;
416 int fd = open(TIMEZONE_NAME, O_RDONLY);
418 int l = read(fd, buf, sizeof(buf)-1);
421 if( buf[l-1] == '\n' ) --l;
427 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
430 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
431 p += strlen(ZONEINFO_STR);
436 for( int i=0; ntsc_zones[i]; ++i ) {
437 if( !strcmp(ntsc_zones[i], p) )
444 for( int i=0; ntsc_zones[i]; ++i ) {
445 if( !strcmp(ntsc_zones[i], p) )
450 // cin_timezone: Seconds west of UTC. 240sec/deg
451 double tz_deg = -cin_timezone / 240.;
452 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
453 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
456 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
458 struct formatpresets *fpr;
460 for(fpr = &format_presets[0]; fpr->name; fpr++)
462 if(strcmp(_(fpr->name), preset) == 0)
464 session->audio_channels = fpr->audio_channels;
465 session->audio_tracks = fpr->audio_tracks;
466 session->sample_rate = fpr->sample_rate;
467 session->video_channels = fpr->video_channels;
468 session->video_tracks = fpr->video_tracks;
469 session->frame_rate = fpr->frame_rate;
470 session->output_w = fpr->output_w;
471 session->output_h = fpr->output_h;
472 session->aspect_w = fpr->aspect_w;
473 session->aspect_h = fpr->aspect_h;
474 session->interlace_mode = fpr->interlace_mode;
475 session->color_model = fpr->color_model;
481 const char *MWindow::get_preset_name(int index)
483 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
485 return _(format_presets[index].name);
489 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
491 char path[BCTEXTLEN];
492 // Use user supplied path
494 strcpy(path, config_path);
496 create_defaults_path(path, CONFIG_FILE);
499 defaults = new BC_Hash(path);
504 void MWindow::check_language()
506 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
507 const char *env_lang = getenv("LANGUAGE");
508 if( !env_lang ) env_lang = getenv("LC_ALL");
509 if( !env_lang ) env_lang = getenv("LANG");
511 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
512 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
513 env_lang = curr_lang;
515 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
516 defaults->get("LAST_LANG",last_lang);
517 if( strcmp(env_lang,last_lang)) {
518 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
519 defaults->update("LAST_LANG",env_lang);
520 char plugin_path[BCTEXTLEN];
521 create_defaults_path(plugin_path, PLUGIN_FILE);
522 ::remove(plugin_path);
523 char ladspa_path[BCTEXTLEN];
524 create_defaults_path(ladspa_path, LADSPA_FILE);
525 ::remove(ladspa_path);
528 if( strlen(env_lang) > 1 &&
529 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
530 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
533 strcpy(cin_lang, "en");
536 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
538 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
540 const char *dp = plug_dir;
541 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
542 bp = !*dp && *bp == '/' ? bp+1 : base_path;
548 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir)
552 fseek(fp, 0, SEEK_SET);
554 char index_line[BCTEXTLEN];
555 int index_version = -1, len = strlen(plugin_dir);
556 if( !fgets(index_line, BCTEXTLEN, fp) ||
557 sscanf(index_line, "%d", &index_version) != 1 ||
558 index_version != PLUGIN_FILE_VERSION ||
559 !fgets(index_line, BCTEXTLEN, fp) ||
560 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
561 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
563 ArrayList<PluginServer*> plugins;
564 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
565 if( index_line[0] == ';' ) continue;
566 if( index_line[0] == '#' ) continue;
567 int type = PLUGIN_TYPE_UNKNOWN;
568 char path[BCTEXTLEN], title[BCTEXTLEN];
570 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
573 PluginServer *server = 0;
575 case PLUGIN_TYPE_BUILTIN:
576 case PLUGIN_TYPE_EXECUTABLE:
577 case PLUGIN_TYPE_LADSPA: {
578 char plugin_path[BCTEXTLEN]; struct stat st;
579 sprintf(plugin_path, "%s/%s", plugin_dir, path);
580 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
583 server = new PluginServer(mwindow, plugin_path, type);
585 case PLUGIN_TYPE_FFMPEG: {
586 server = new_ffmpeg_server(mwindow, path);
588 case PLUGIN_TYPE_LV2: {
589 server = new_lv2_server(mwindow, path);
592 if( !server ) continue;
593 plugins.append(server);
594 // Create plugin server from index entry
595 server->set_title(title);
596 if( server->read_table(index_line) ) {
602 ret = check_plugin_index(plugins, plugin_dir, ".");
605 add_plugins(plugins);
607 plugins.remove_all_objects();
612 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
613 const char *plug_dir, const char *plug_path)
615 char plugin_path[BCTEXTLEN];
616 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
618 fs.set_filter( "[*.plugin][*.so]" );
619 if( fs.update(plugin_path) )
622 for( int i=0; i<fs.dir_list.total; ++i ) {
623 char fs_path[BCTEXTLEN];
624 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
625 if( fs.is_dir(fs_path) ) {
626 get_plugin_path(plugin_path, plug_dir, fs_path);
627 if( check_plugin_index(plugins, plug_dir, plugin_path) )
630 else if( !plugin_exists(fs_path, plugins) )
637 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
640 plugindb = new ArrayList<PluginServer*>;
642 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
643 create_defaults_path(index_path, PLUGIN_FILE);
644 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
645 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
646 FILE *fp = fopen(index_path,"a+");
648 fprintf(stderr,_("MWindow::init_plugins: "
649 "can't open plugin index: %s\n"), index_path);
652 int fd = fileno(fp), ret = -1;
653 if( !flock(fd, LOCK_EX) ) {
654 fseek(fp, 0, SEEK_SET);
655 ret = load_plugin_index(mwindow, fp, plugin_path);
659 fseek(fp, 0, SEEK_SET);
660 printf("init plugin index: %s\n", plugin_path);
661 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
662 fprintf(fp, "%s\n", plugin_path);
663 init_plugin_index(mwindow, preferences, fp, plugin_path);
664 init_ffmpeg_index(mwindow, preferences, fp);
665 init_lv2_index(mwindow, preferences, fp);
666 fseek(fp, 0, SEEK_SET);
667 ret = load_plugin_index(mwindow, fp, plugin_path);
670 fprintf(stderr,_("MWindow::init_plugins: "
671 "can't %s plugin index: %s\n"),
672 ret>0 ? _("create") : _("lock"), index_path);
678 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
681 char *path = getenv("LADSPA_PATH");
682 char ladspa_path[BCTEXTLEN];
684 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
687 for( int len=0; *path; path+=len ) {
688 char *cp = strchr(path,':');
689 len = !cp ? strlen(path) : cp-path;
690 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
691 memcpy(plugin_path, path, len); plugin_path[len] = 0;
693 char *plugin_dir = FileSystem::basepath(plugin_path);
694 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
695 create_defaults_path(index_path, LADSPA_FILE);
696 cp = index_path + strlen(index_path);
697 for( char *bp=plugin_path; *bp!=0; ++bp )
698 *cp++ = *bp=='/' ? '_' : *bp;
700 FILE *fp = fopen(index_path,"a+");
702 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
703 "can't open ladspa plugin index: %s\n"), index_path);
706 int fd = fileno(fp), ret = -1;
707 if( !flock(fd, LOCK_EX) ) {
708 fseek(fp, 0, SEEK_SET);
709 ret = load_plugin_index(mwindow, fp, plugin_path);
713 fseek(fp, 0, SEEK_SET);
714 init_ladspa_index(mwindow, preferences, fp, plugin_path);
715 fseek(fp, 0, SEEK_SET);
716 ret = load_plugin_index(mwindow, fp, plugin_path);
719 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
720 "can't %s ladspa plugin index: %s\n"),
721 ret>0 ? _("create") : _("lock"), index_path);
729 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
730 FILE *fp, const char *plugin_dir)
732 int idx = PLUGIN_IDS;
734 for( int i=0; i<plugindb->size(); ++i ) {
735 PluginServer *server = plugindb->get(i);
736 if( server->dir_idx >= idx )
737 idx = server->dir_idx+1;
740 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
743 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
744 const char *plug_dir, const char *plug_path, int &idx)
746 char plugin_path[BCTEXTLEN];
747 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
749 fs.set_filter( "[*.plugin][*.so][*.dll]" );
750 int result = fs.update(plugin_path);
751 if( result || !fs.dir_list.total ) return;
754 for( int i=0; i<fs.dir_list.total; ++i ) {
755 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
756 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
757 get_plugin_path(path, plug_dir, fs_path);
758 if( fs.is_dir(fs_path) ) {
759 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
762 if( plugin_exists(path) ) continue;
764 if( stat(fs_path, &st) ) continue;
765 int64_t mtime = st.st_mtime;
766 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
767 result = server.open_plugin(1, preferences, 0, 0);
769 server.write_table(fp, path, vis_id, mtime);
770 server.close_plugin();
772 else if( result == PLUGINSERVER_IS_LAD ) {
775 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
776 ladspa.set_lad_index(lad_index++);
777 result = ladspa.open_plugin(1, preferences, 0, 0);
779 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
780 ladspa.close_plugin();
786 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
788 for( int i=0; i<plugins.size(); ++i )
789 plugindb->append(plugins[i]);
790 plugins.remove_all();
793 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
795 const char *dat_path = File::get_cindat_path();
796 char msg_path[BCTEXTLEN];
798 if( BC_Resources::language[0] ) {
799 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
801 fp = fopen(msg_path, "r");
804 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
806 fp = fopen(msg_path, "r");
809 char text[BCTEXTLEN];
810 char *tp = text, *ep = tp + sizeof(text)-1;
811 char title[BCTEXTLEN];
816 char line[BCTEXTLEN], *cp = line;
817 if( fgets(line,sizeof(line)-1,fp) ) {
818 if( *cp == '#' ) continue;
819 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
822 if( tp > text && *--tp == '\n' ) *tp = 0;
824 int idx = plugins.size();
825 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
827 delete [] plugins[idx]->tip;
828 plugins[idx]->tip = cstrdup(text);
832 if( done > 0 ) break;
834 char *dp = strchr(cp, ':');
836 printf("plugin tips: error on line %d\n", no);
840 while( cp < dp ) *bp++ = *cp++;
845 while( *cp == ' ' || *cp == '\t' ) ++cp;
846 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
851 void MWindow::delete_plugins()
853 plugindb->remove_all_objects();
858 void MWindow::search_plugindb(int do_audio,
863 ArrayList<PluginServer*> &results)
866 for(int i = 0; i < MWindow::plugindb->total; i++)
868 PluginServer *current = MWindow::plugindb->get(i);
870 if(current->audio == do_audio &&
871 current->video == do_video &&
872 (current->realtime == is_realtime || is_realtime < 0) &&
873 current->transition == is_transition &&
874 current->theme == is_theme)
875 results.append(current);
878 // Alphabetize list by title
884 for(int i = 0; i < results.total - 1; i++)
886 PluginServer *value1 = results[i];
887 PluginServer *value2 = results[i + 1];
888 if(strcmp(_(value1->title), _(value2->title)) > 0)
892 results[i + 1] = value1;
898 PluginServer* MWindow::scan_plugindb(char *title,
903 // printf("MWindow::scan_plugindb data_type < 0\n");
907 for(int i = 0; i < plugindb->total; i++)
909 PluginServer *server = plugindb->get(i);
911 !strcasecmp(server->title, title) &&
913 (data_type == TRACK_AUDIO && server->audio) ||
914 (data_type == TRACK_VIDEO && server->video)))
915 return plugindb->get(i);
920 // repair session files with xlated plugin titles
921 void MWindow::fix_plugin_title(char *title)
923 for(int i = 0; i < plugindb->total; i++) {
924 PluginServer *server = plugindb->get(i);
925 if( !server->title ) continue;
926 const char *server_title = server->title;
927 if( !bstrcasecmp(title, _(server_title)) ) {
928 strcpy(title, server_title);
934 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
936 for( int i=0; i<plugins.size(); ++i )
937 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
941 int MWindow::plugin_exists(char *plugin_path)
943 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
946 void MWindow::remove_plugin_index()
948 char index_path[BCTEXTLEN];
949 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
950 ::remove(index_path);
953 void MWindow::init_preferences()
955 preferences = new Preferences;
956 preferences->load_defaults(defaults);
957 File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
958 session = new MainSession(this);
959 session->load_defaults(defaults);
960 // set x11_host, screens, window_config
961 screens = session->set_default_x11_host();
962 BC_Signals::set_trap_hook(trap_hook, this);
963 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
964 BC_Signals::set_catch_intr(preferences->trap_sigintr);
965 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
966 BC_Trace::enable_locks();
969 BC_Trace::disable_locks();
971 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
972 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
973 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
974 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
977 void MWindow::clean_indexes()
982 int oldest_item = -1;
984 char string[BCTEXTLEN];
985 char string2[BCTEXTLEN];
987 // Delete extra indexes
988 fs.set_filter("*.idx");
989 fs.complete_path(preferences->index_directory);
990 fs.update(preferences->index_directory);
991 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
993 // Eliminate directories
998 for(int i = 0; i < fs.dir_list.total && !result; i++)
1000 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1001 if(fs.is_dir(string))
1003 delete fs.dir_list[i];
1004 fs.dir_list.remove_number(i);
1009 total_excess = fs.dir_list.total - preferences->index_count;
1011 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
1012 while(total_excess > 0)
1015 for(int i = 0; i < fs.dir_list.total; i++)
1017 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1019 if(i == 0 || fs.get_date(string) <= oldest)
1021 oldest = fs.get_date(string);
1026 if(oldest_item >= 0)
1028 // Remove index file
1029 fs.join_names(string,
1030 preferences->index_directory,
1031 fs.dir_list[oldest_item]->name);
1032 //printf("MWindow::clean_indexes 1 %s\n", string);
1034 perror("delete_indexes");
1035 delete fs.dir_list[oldest_item];
1036 fs.dir_list.remove_number(oldest_item);
1038 // Remove table of contents if it exists
1039 strcpy(string2, string);
1040 char *ptr = strrchr(string2, '.');
1043 //printf("MWindow::clean_indexes 2 %s\n", string2);
1044 sprintf(ptr, ".toc");
1046 sprintf(ptr, ".mkr");
1055 void MWindow::init_awindow()
1057 awindow = new AWindow(this);
1058 awindow->create_objects();
1061 void MWindow::init_gwindow()
1063 gwindow = new GWindow(this);
1064 gwindow->create_objects();
1067 void MWindow::init_tipwindow()
1069 TipWindow::load_tips(cin_lang);
1071 twindow = new TipWindow(this);
1075 void MWindow::show_warning(int *do_warning, const char *text)
1077 if( do_warning && !*do_warning ) return;
1079 wwindow = new WWindow(this);
1080 wwindow->show_warning(do_warning, text);
1083 int MWindow::wait_warning()
1085 return wwindow->wait_result();
1088 void MWindow::init_theme()
1093 PluginServer *theme_plugin = 0;
1094 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1095 if( plugindb->get(i)->theme &&
1096 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1097 theme_plugin = plugindb->get(i);
1101 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1102 preferences->theme);
1104 const char *default_theme = DEFAULT_THEME;
1105 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1106 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1108 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1109 if( plugindb->get(i)->theme &&
1110 !strcasecmp(default_theme, plugindb->get(i)->title) )
1111 theme_plugin = plugindb->get(i);
1116 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1120 PluginServer *plugin = new PluginServer(*theme_plugin);
1121 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1122 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1123 theme_plugin->title);
1127 theme = plugin->new_theme();
1128 theme->mwindow = this;
1129 strcpy(theme->path, plugin->path);
1132 // Load default images & settings
1133 theme->Theme::initialize();
1134 // Load user images & settings
1135 theme->initialize();
1136 // Create menus with user colors
1137 theme->build_menus();
1140 theme->sort_image_sets();
1141 theme->check_used();
1142 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1145 void MWindow::init_3d()
1147 playback_3d = new Playback3D(this);
1148 playback_3d->create_objects();
1151 void MWindow::init_edl()
1154 edl->create_objects();
1155 fill_preset_defaults(default_standard, edl->session);
1156 edl->load_defaults(defaults);
1157 edl->session->brender_start = edl->session->brender_end = 0;
1158 edl->create_default_tracks();
1159 edl->tracks->update_y_pixels(theme);
1162 void MWindow::init_compositor()
1164 cwindow = new CWindow(this);
1165 cwindow->create_objects();
1168 void MWindow::init_levelwindow()
1170 lwindow = new LevelWindow(this);
1171 lwindow->create_objects();
1174 VWindow *MWindow::get_viewer(int start_it, int idx)
1176 vwindows_lock->lock("MWindow::get_viewer");
1177 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1178 if( !vwindow ) idx = vwindows.size();
1179 while( !vwindow && --idx >= 0 ) {
1180 VWindow *vwin = vwindows[idx];
1181 if( !vwin->is_running() || !vwin->get_edl() )
1185 vwindow = new VWindow(this);
1186 vwindow->load_defaults();
1187 vwindow->create_objects();
1188 vwindows.append(vwindow);
1190 vwindows_lock->unlock();
1191 if( start_it ) vwindow->start();
1195 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1197 zwindows_lock->lock("MWindow::get_mixer");
1198 if( !mixer ) mixer = edl->mixers.new_mixer();
1199 ZWindow *zwindow = 0;
1200 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1201 ZWindow *zwdw = zwindows[i];
1202 if( zwdw->running() ) continue;
1203 if( zwdw->idx >= 0 ) continue;
1204 zwindow = zwindows[i];
1207 zwindows.append(zwindow = new ZWindow(this));
1208 zwindow->idx = mixer->idx;
1209 zwindows_lock->unlock();
1213 void MWindow::del_mixer(ZWindow *zwindow)
1215 zwindows_lock->lock("MWindow::del_mixer 0");
1216 edl->mixers.del_mixer(zwindow->idx);
1217 if( session->selected_zwindow >= 0 ) {
1218 int i = zwindows.number_of(zwindow);
1219 if( i >= 0 && i < session->selected_zwindow )
1220 --session->selected_zwindow;
1221 else if( i == session->selected_zwindow )
1222 session->selected_zwindow = -1;
1224 zwindows_lock->unlock();
1225 gui->lock_window("MWindow::del_mixer 1");
1226 gui->update_mixers(0, -1);
1227 gui->unlock_window();
1230 void MWindow::start_mixer()
1233 ZWindow *zwindow = get_mixer(mixer);
1234 const char *title = 0;
1236 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1237 PatchGUI *patchgui = get_patchgui(track);
1238 if( !patchgui || !patchgui->mixer ) continue;
1239 mixer->mixer_ids.append(track->get_mixer_id());
1240 if( !title ) title = track->title;
1243 session->selected_zwindow = -1;
1244 gui->lock_window("MWindow::start_mixer");
1245 gui->update_mixers(0, 0);
1246 gui->unlock_window();
1248 zwindow->set_title(title);
1253 int MWindow::mixer_track_active(Track *track)
1255 int i = session->selected_zwindow;
1256 if( i < 0 || i >= zwindows.size() ) return 0;
1257 ZWindow *zwindow = zwindows[i];
1258 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1259 if( !mixer ) return 0;
1260 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1261 return n >= 0 ? 1 : 0;
1264 void MWindow::update_mixer_tracks()
1266 zwindows_lock->lock("MixPatch::handle_event");
1267 int i = session->selected_zwindow;
1268 if( i >= 0 && i < zwindows.size() ) {
1269 ZWindow *zwindow = zwindows[i];
1270 zwindow->update_mixer_ids();
1272 zwindows_lock->unlock();
1275 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1276 int use_inout, int toggle_audio, int loop_play, float speed)
1278 zwindows_lock->lock("MWindow::handle_mixers");
1279 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1280 ZWindow *zwindow = zwindows[vidx];
1281 if( zwindow->idx < 0 ) continue;
1282 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1283 if( !mixer || !mixer->mixer_ids.size() ) continue;
1285 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1286 if( track->data_type != TRACK_VIDEO ) continue;
1287 int mixer_id = track->get_mixer_id();
1288 k = mixer->mixer_ids.size();
1289 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1291 if( k < 0 ) continue;
1292 EDL *mixer_edl = new EDL(this->edl);
1293 mixer_edl->create_objects();
1294 mixer_edl->copy_all(edl);
1295 mixer_edl->remove_vwindow_edls();
1296 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1297 k = mixer->mixer_ids.size();
1298 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1301 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1304 track->record = track->play = 0;
1306 zwindow->change_source(mixer_edl);
1307 zwindow->handle_mixer(command, 0,
1308 use_inout, toggle_audio, loop_play, speed);
1310 zwindows_lock->unlock();
1313 void MWindow::refresh_mixers(int dir)
1315 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1316 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1319 void MWindow::stop_mixers()
1321 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1322 ZWindow *zwindow = zwindows[vidx];
1323 if( zwindow->idx < 0 ) continue;
1324 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1328 void MWindow::close_mixers(int result)
1330 ArrayList<ZWindow*> closed;
1331 zwindows_lock->lock("MWindow::close_mixers");
1332 for( int i=zwindows.size(); --i>=0; ) {
1333 ZWindow *zwindow = zwindows[i];
1334 if( zwindow->idx < 0 ) continue;
1336 ZWindowGUI *zgui = zwindow->zgui;
1337 zgui->lock_window("MWindow::select_zwindow 0");
1338 zgui->set_done(result);
1339 zgui->unlock_window();
1340 closed.append(zwindow);
1342 zwindows_lock->unlock();
1343 for( int i=0; i<closed.size(); ++i ) {
1344 ZWindow *zwindow = closed[i];
1349 ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
1351 ArrayList<Indexable*> new_assets;
1352 new_assets.append(indexable);
1353 Track *track = edl->tracks->last;
1354 load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
1355 track = !track ? edl->tracks->first : track->next;
1357 ZWindow *zwindow = get_mixer(mixer);
1359 track->play = track->record = 0;
1360 if( track->data_type == TRACK_VIDEO ) {
1361 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1363 mixer->mixer_ids.append(track->get_mixer_id());
1364 track = track->next;
1366 if( indexable->is_asset ) {
1367 char *path = indexable->path;
1368 char *tp = strrchr(path, '/');
1369 if( !tp ) tp = path; else ++tp;
1370 zwindow->set_title(tp);
1373 char *title = ((EDL*)indexable)->local_session->clip_title;
1374 zwindow->set_title(title);
1379 void MWindow::create_mixers(double position)
1381 if( !session->drag_assets->size() &&
1382 !session->drag_clips->size() ) return;
1386 ArrayList<ZWindow *>new_mixers;
1388 for( int i=0; i<session->drag_assets->size(); ++i ) {
1389 Indexable *indexable = session->drag_assets->get(i);
1390 if( !indexable->have_video() ) continue;
1391 ZWindow *zwindow = create_mixer(indexable, position);
1392 new_mixers.append(zwindow);
1394 for( int i=0; i<session->drag_clips->size(); ++i ) {
1395 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1396 if( !indexable->have_video() ) continue;
1397 ZWindow *zwindow = create_mixer(indexable, position);
1398 new_mixers.append(zwindow);
1402 for( int i=0; i<new_mixers.size(); ++i )
1403 new_mixers[i]->start();
1407 undo_after(_("create mixers"), LOAD_ALL);
1409 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1410 sync_parameters(CHANGE_ALL);
1413 void MWindow::open_mixers()
1415 for( int i=0; i<edl->mixers.size(); ++i ) {
1416 Mixer *mixer = edl->mixers[i];
1417 ZWindow *zwindow = get_mixer(mixer);
1418 zwindow->set_title(mixer->title);
1424 int MWindow::select_zwindow(ZWindow *zwindow)
1426 int ret = 0, n = zwindows.number_of(zwindow);
1427 if( session->selected_zwindow != n ) {
1428 session->selected_zwindow = n;
1429 for( int i=0; i<zwindows.size(); ++i ) {
1430 ZWindow *zwindow = zwindows[i];
1431 if( zwindow->idx < 0 ) continue;
1432 ZWindowGUI *zgui = zwindow->zgui;
1433 zgui->lock_window("MWindow::select_zwindow 0");
1434 zwindow->highlighted = i == n ? 1 : 0;
1435 if( zgui->draw_overlays() )
1436 zgui->canvas->get_canvas()->flash(1);
1437 zgui->unlock_window();
1440 gui->lock_window("MWindow::select_window 1");
1441 gui->update_mixers(0, -1);
1442 gui->unlock_window();
1447 void MWindow::tile_mixers()
1450 for( int i=0; i<zwindows.size(); ++i ) {
1451 ZWindow *zwindow = zwindows[i];
1452 if( zwindow->idx < 0 ) continue;
1456 int zn = ceil(sqrt(nz));
1457 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1458 int y1 = 1, y2 = gui->get_y();
1459 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1460 if( x1 < 0 ) x1 = 0;
1461 if( y1 < 0 ) y1 = 0;
1462 if( x2 > rw ) x2 = rw;
1463 if( y2 > rh ) y2 = rh;
1464 int dx = x2 - x1, dy = y2 - y1;
1466 int lt = BC_DisplayInfo::get_left_border();
1467 int top = BC_DisplayInfo::get_top_border();
1468 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1469 int bh = top + BC_DisplayInfo::get_bottom_border();
1470 int zx = 0, zy = 0; // window origins
1471 int mw = xS(10+10), mh = yS(10+10); // canvas margins
1472 int rsz = 0, n = 0, dz = 0;
1473 int ow = edl->session->output_w, oh = edl->session->output_h;
1474 for( int i=0; i<zwindows.size(); ++i ) {
1475 ZWindow *zwindow = zwindows[i];
1476 if( zwindow->idx < 0 ) continue;
1477 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1478 if( rsz < hh ) rsz = hh;
1479 int xx = zx + x1, yy = zy + y1;
1480 int mx = x2 - zw, my = y2 - zh;
1481 if( xx > mx ) xx = mx;
1482 if( yy > my ) yy = my;
1483 xx += lt + xS(dz); yy += top + yS(dz);
1484 zwindow->reposition(xx,yy, ww,hh);
1485 if( zwindow->running() ) {
1486 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1487 gui->lock_window("MWindow::tile_mixers");
1488 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1489 gui->unlock_window();
1493 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1502 void MWindow::init_cache()
1504 audio_cache = new CICache(preferences);
1505 video_cache = new CICache(preferences);
1506 frame_cache = new FrameCache;
1507 wave_cache = new WaveCache;
1510 void MWindow::init_channeldb()
1512 channeldb_buz->load("channeldb_buz");
1513 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1516 void MWindow::init_menus()
1518 char string[BCTEXTLEN];
1521 BC_CModels::to_text(string, BC_RGB888);
1522 colormodels.append(new ColormodelItem(string, BC_RGB888));
1523 BC_CModels::to_text(string, BC_RGBA8888);
1524 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1525 // BC_CModels::to_text(string, BC_RGB161616);
1526 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1527 // BC_CModels::to_text(string, BC_RGBA16161616);
1528 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1529 BC_CModels::to_text(string, BC_RGB_FLOAT);
1530 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1531 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1532 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1533 BC_CModels::to_text(string, BC_YUV888);
1534 colormodels.append(new ColormodelItem(string, BC_YUV888));
1535 BC_CModels::to_text(string, BC_YUVA8888);
1536 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1537 // BC_CModels::to_text(string, BC_YUV161616);
1538 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1539 // BC_CModels::to_text(string, BC_YUVA16161616);
1540 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1542 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1543 interlace_project_modes.append(new InterlacemodeItem(string, x));
1545 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1546 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1548 // Interlacing Modes
1549 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1551 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1552 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1554 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1555 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1557 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1558 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1560 mixers_align = new MixersAlign(this);
1563 void MWindow::init_indexes()
1565 mainindexes = new MainIndexes(this);
1566 mainindexes->start_loop();
1569 void MWindow::init_gui()
1571 gui = new MWindowGUI(this);
1572 gui->create_objects();
1573 gui->load_defaults(defaults);
1576 void MWindow::init_signals()
1578 sighandler = new SigHandler;
1579 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1583 void MWindow::init_render()
1585 render = new Render(this);
1586 create_bd = new CreateBD_Thread(this);
1587 create_dvd = new CreateDVD_Thread(this);
1588 batch_render = new BatchRenderThread(this);
1591 void MWindow::init_exportedl()
1593 exportedl = new ExportEDL(this);
1597 void MWindow::init_shuttle()
1600 int ret = Shuttle::probe();
1602 shuttle = new Shuttle(this);
1603 if( shuttle->read_config_file() > 0 ) {
1604 printf("shuttle: bad config file\n");
1605 delete shuttle; shuttle = 0;
1608 shuttle->start(ret);
1612 void MWindow::init_wintv()
1615 wintv = WinTV::probe(this);
1620 void MWindow::init_x10tv()
1623 x10tv = X10TV::probe(this);
1630 void MWindow::init_brender()
1632 if(preferences->use_brender && !brender)
1634 brender_lock->lock("MWindow::init_brender 1");
1635 brender = new BRender(this);
1636 brender->initialize();
1637 session->brender_end = 0;
1638 brender_lock->unlock();
1641 if(!preferences->use_brender && brender)
1643 brender_lock->lock("MWindow::init_brender 2");
1646 session->brender_end = 0;
1647 brender_lock->unlock();
1653 void MWindow::restart_brender()
1655 //printf("MWindow::restart_brender 1\n");
1656 if( !brender_active || !preferences->use_brender ) return;
1657 if( !brender ) return;
1658 brender->restart(edl);
1661 void MWindow::stop_brender()
1663 if( !brender ) return;
1664 // cannot be holding mwindow->gui display lock
1668 int MWindow::brender_available(int position)
1671 brender_lock->lock("MWindow::brender_available 1");
1672 if(brender && brender_active)
1674 if(brender->map_valid)
1676 brender->map_lock->lock("MWindow::brender_available 2");
1677 if(position < brender->map_size &&
1680 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1681 if(brender->map[position] == BRender::RENDERED)
1684 brender->map_lock->unlock();
1687 brender_lock->unlock();
1691 void MWindow::set_brender_active(int v, int update)
1693 if( !preferences->use_brender ) v = 0;
1695 gui->mainmenu->brender_active->set_checked(v);
1697 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1698 edl->session->brender_end = edl->local_session->get_selectionend(1);
1700 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1701 edl->session->brender_end = edl->tracks->total_video_length();
1706 edl->session->brender_start = edl->session->brender_end = 0;
1707 gui->unlock_window();
1709 gui->lock_window("MWindow::set_brender_active");
1712 gui->update_timebar(0);
1713 gui->draw_overlays(1);
1717 int MWindow::has_commercials()
1719 #ifdef HAVE_COMMERCIAL
1720 return theme->use_commercials;
1726 void MWindow::init_commercials()
1728 #ifdef HAVE_COMMERCIAL
1729 if( !commercials ) {
1730 commercials = new Commercials(this);
1731 commercial_active = 0;
1734 commercials->add_user();
1738 void MWindow::commit_commercial()
1740 #ifdef HAVE_COMMERCIAL
1741 if( !commercial_active ) return;
1742 commercial_active = 0;
1743 if( !commercials ) return;
1744 commercials->commitDb();
1748 void MWindow::undo_commercial()
1750 #ifdef HAVE_COMMERCIAL
1751 if( !commercial_active ) return;
1752 commercial_active = 0;
1753 if( !commercials ) return;
1754 commercials->undoDb();
1758 int MWindow::put_commercial()
1761 #ifdef HAVE_COMMERCIAL
1762 double start = edl->local_session->get_selectionstart();
1763 double end = edl->local_session->get_selectionend();
1764 if( start >= end ) return 0;
1766 const char *errmsg = 0;
1768 Tracks *tracks = edl->tracks;
1770 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1771 if( track->data_type != TRACK_VIDEO ) continue;
1772 if( !track->record ) continue;
1773 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1775 int64_t units_start = track->to_units(start,0);
1776 int64_t units_end = track->to_units(end,0);
1777 Edits *edits = track->edits;
1778 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1779 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1780 if(!edit1 && !edit2) continue; // nothing selected
1781 if(!edit2) { // edit2 beyond end of track
1782 edit2 = edits->last;
1783 units_end = edits->length();
1785 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1786 Indexable *indexable = edit1->get_source();
1787 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1790 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1791 if( track->data_type != TRACK_VIDEO ) continue;
1792 if( !track->record ) continue;
1793 int64_t units_start = track->to_units(start,0);
1794 int64_t units_end = track->to_units(end,0);
1795 Edits *edits = track->edits;
1796 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1797 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1798 if(!edit1 && !edit2) continue; // nothing selected
1799 if(!edit2) { // edit2 beyond end of track
1800 edit2 = edits->last;
1801 units_end = edits->length();
1803 Indexable *indexable = edit1->get_source();
1804 Asset *asset = (Asset *)indexable;
1805 File *file = video_cache->check_out(asset, edl);
1806 if( !file ) { errmsg = _("no file"); break; }
1807 int64_t edit_length = units_end - units_start;
1808 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1809 result = commercials->put_clip(file, edit1->channel,
1810 track->from_units(edit_start), track->from_units(edit_length));
1811 video_cache->check_in(asset);
1812 if( result ) { errmsg = _("db failed"); break; }
1815 char string[BCTEXTLEN];
1816 sprintf(string, _("put_commercial: %s"), errmsg);
1817 MainError::show_error(string);
1825 void MWindow::stop_playback(int wait)
1827 gui->stop_drawing();
1829 cwindow->stop_playback(wait);
1831 for(int i = 0; i < vwindows.size(); i++) {
1832 VWindow *vwindow = vwindows[i];
1833 if( !vwindow->is_running() ) continue;
1834 vwindow->stop_playback(wait);
1836 for(int i = 0; i < zwindows.size(); i++) {
1837 ZWindow *zwindow = zwindows[i];
1838 if( zwindow->idx < 0 ) continue;
1839 zwindow->stop_playback(wait);
1843 void MWindow::stop_transport()
1845 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1848 void MWindow::undo_before(const char *description, void *creator)
1850 undo->update_undo_before(description, creator);
1853 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
1855 undo->update_undo_after(description, load_flags, changes_made);
1858 void MWindow::beep(double freq, double secs, double gain)
1860 if( !beeper ) beeper = new Beeper(this);
1861 beeper->tone(freq, secs, gain);
1864 Beeper::Beeper(MWindow *mwindow)
1867 this->mwindow = mwindow;
1868 audio = new AudioDevice(mwindow);
1882 int64_t bfrsz = BEEP_SAMPLE_RATE;
1883 EDL *edl = mwindow->edl;
1884 EDLSession *session = edl->session;
1885 AudioOutConfig *aconfig = session->playback_config->aconfig;
1886 audio->open_output(aconfig, BEEP_SAMPLE_RATE, bfrsz, channels, 0);
1887 audio->start_playback();
1889 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
1890 const double two_pi = 2*M_PI;
1891 int64_t audio_len = BEEP_SAMPLE_RATE * secs;
1892 const double dt = two_pi * freq/BEEP_SAMPLE_RATE;
1897 while( !interrupted ) {
1898 int len = audio_len - audio_pos;
1899 if( len <= 0 ) break;
1900 if( len > bfrsz ) len = bfrsz;
1902 for( int i=0; i<len; ++i,++k,th+=dt ) {
1903 double t = th - two_pi;
1904 if( t >= 0 ) th = t;
1905 out0[i] = out1[i] = sin(th) * gain;
1907 audio->write_buffer(out, channels, len);
1912 audio->set_last_buffer();
1913 audio->stop_audio(interrupted ? 0 : 1);
1919 void Beeper::start()
1921 if( running() ) return;
1927 void Beeper::stop(int wait)
1929 if( running() && !interrupted ) {
1931 audio->stop_audio(wait);
1936 void Beeper::tone(double freq, double secs, double gain)
1946 int MWindow::load_filenames(ArrayList<char*> *filenames,
1947 int load_mode, int edl_mode, int update_filename)
1949 ArrayList<EDL*> new_edls;
1950 ArrayList<Asset*> new_assets;
1951 ArrayList<File*> new_files;
1954 gui->start_hourglass();
1956 // Need to stop playback since tracking depends on the EDL not getting
1958 gui->unlock_window();
1960 gui->lock_window("MWindow::load_filenames 0");
1963 const int debug = 0;
1964 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1966 // Define new_edls and new_assets to load
1967 int result = 0, ftype = -1;
1969 for( int i=0; i<filenames->size(); ++i ) {
1971 File *new_file = new File;
1972 Asset *new_asset = new Asset(filenames->get(i));
1973 EDL *new_edl = new EDL;
1974 new_edl->create_objects();
1975 new_edl->copy_session(edl, -1);
1976 new_file->set_program(edl->session->program_no);
1978 char string[BCTEXTLEN];
1979 sprintf(string, _("Loading %s"), new_asset->path);
1980 gui->show_message(string);
1982 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1986 // Convert media file to EDL
1988 // Warn about odd image dimensions
1989 if( new_asset->video_data &&
1990 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1991 eprintf(_("%s's resolution is %dx%d.\n"
1992 "Images with odd dimensions may not decode properly."),
1993 new_asset->path, new_asset->width, new_asset->height);
1996 if( new_asset->program >= 0 &&
1997 edl->session->program_no != new_asset->program ) {
1998 eprintf(_("%s's index was built for program number %d\n"
1999 "Playback preference is %d.\n Using program %d."),
2000 new_asset->path, new_asset->program,
2001 edl->session->program_no, new_asset->program);
2004 if( load_mode == LOADMODE_RESOURCESONLY ) {
2005 new_assets.append(new_asset);
2006 new_asset->add_user();
2011 RecordLabels *labels = edl->session->label_cells ?
2012 new RecordLabels(new_file) : 0;
2013 asset_to_edl(new_edl, new_asset, labels);
2014 new_edls.append(new_edl);
2015 new_edl->add_user();
2018 if( load_mode == LOADMODE_REPLACE ||
2019 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2020 // Set filename to nothing for assets since save EDL would overwrite them.
2022 // Reset timeline position
2023 for( int i=0; i<TOTAL_PANES; ++i ) {
2024 new_edl->local_session->view_start[i] = 0;
2025 new_edl->local_session->track_start[i] = 0;
2031 case FILE_NOT_FOUND: {
2032 eprintf(_("Failed to open %s"), new_asset->path);
2033 sprintf(string, _("Failed to open %s"), new_asset->path);
2034 gui->show_message(string, theme->message_error);
2035 gui->update_default_message();
2039 case FILE_UNRECOGNIZED_CODEC: {
2041 { IndexFile indexfile(this, new_asset);
2042 if( !(result = indexfile.open_index()) )
2043 indexfile.close_index(); }
2045 // Test existing EDLs
2046 for( int j=0; result && j<new_edls.total; ++j ) {
2047 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
2049 new_asset->copy_from(old_asset,1);
2054 Asset *old_asset = edl->assets->get_asset(new_asset->path);
2056 new_asset->copy_from(old_asset,1);
2063 new_asset->audio_data = 1;
2064 new_asset->format = FILE_PCM;
2065 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
2066 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
2067 new_asset->bits = defaults->get("AUDIO_BITS", 16);
2068 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
2069 new_asset->signed_ = defaults->get("SIGNED_", 1);
2070 new_asset->header = defaults->get("HEADER", 0);
2073 fs.extract_name(string, new_asset->path);
2074 strcat(string, _("'s format couldn't be determined."));
2075 FileFormat fwindow(this);
2076 fwindow.create_objects(new_asset, string);
2077 result = fwindow.run_window();
2079 defaults->update("AUDIO_CHANNELS", new_asset->channels);
2080 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
2081 defaults->update("AUDIO_BITS", new_asset->bits);
2082 defaults->update("BYTE_ORDER", new_asset->byte_order);
2083 defaults->update("SIGNED_", new_asset->signed_);
2084 defaults->update("HEADER", new_asset->header);
2089 // Recalculate length
2091 new_file = new File;
2092 result = new_file->open_file(preferences, new_asset, 1, 0);
2094 if( load_mode != LOADMODE_RESOURCESONLY ) {
2095 RecordLabels *labels = edl->session->label_cells ?
2096 new RecordLabels(new_file) : 0;
2097 asset_to_edl(new_edl, new_asset, labels);
2098 new_edls.append(new_edl);
2099 new_edl->add_user();
2103 new_assets.append(new_asset);
2104 new_asset->add_user();
2111 const char *filename = filenames->get(i);
2112 if( xml_file.read_from_file(filename, 1) ) {
2113 eprintf(_("Error: unable to open:\n %s"), filename);
2116 const char *cin_version = 0;
2117 while( !xml_file.read_tag() ) {
2118 if( xml_file.tag.title_is("EDL") ) {
2119 cin_version = xml_file.tag.get_property("VERSION");
2124 if( !cin_version ) {
2125 eprintf(_("XML file %s\n not from cinelerra."),filename);
2126 char string[BCTEXTLEN];
2127 sprintf(string,_("Unknown %s"), filename);
2128 gui->show_message(string);
2131 if( strcmp(cin_version, CINELERRA_VERSION) &&
2132 strcmp(cin_version, "Unify") &&
2133 strcmp(cin_version, "5.1") ) {
2134 eprintf(_("Warning: XML from cinelerra version %s\n"
2135 "Session data may be incompatible."), cin_version);
2137 if( new_edl->load_xml(&xml_file, LOAD_ALL) ) {
2138 eprintf(_("Error: unable to load:\n %s"), filename);
2141 test_plugins(new_edl, filename);
2142 int groups = new_edl->regroup(session->group_number);
2143 session->group_number += groups;
2144 switch( edl_mode ) {
2145 case LOADMODE_EDL_CLIP: {
2146 strcpy(new_edl->local_session->clip_title,
2149 time_t t = !stat(filenames->get(i),&st) ?
2150 st.st_mtime : time(&t);
2151 ctime_r(&t, new_edl->local_session->clip_notes);
2152 switch( load_mode ) {
2153 case LOADMODE_REPLACE:
2154 case LOADMODE_REPLACE_CONCATENATE:
2155 strcpy(session->filename, filename);
2156 if( update_filename ) set_filename(filename);
2161 case LOADMODE_EDL_NESTED: {
2162 EDL *nested_edl = new EDL;
2163 nested_edl->create_objects();
2164 nested_edl->copy_session(edl, -1);
2165 nested_edl->create_nested(new_edl);
2166 nested_edl->set_path(filename);
2167 new_edl->remove_user();
2168 new_edl = nested_edl;
2171 case LOADMODE_EDL_FILEREF: {
2172 result = create_ref(new_asset, new_edl);
2174 new_assets.append(new_asset);
2175 new_asset->add_user();
2176 new_edl->remove_user();
2178 new_edl->create_objects();
2179 new_edl->copy_session(edl, -1);
2180 asset_to_edl(new_edl, new_asset);
2182 new_file = new File;
2183 result = new_file->open_file(preferences, new_asset, 1, 0);
2187 new_edls.append(new_edl);
2188 new_edl->add_user();
2191 eprintf(_("Error: Unable to load xml:\n %s"), new_asset->path);
2195 new_edl->Garbage::remove_user();
2196 new_asset->Garbage::remove_user();
2198 // Store for testing index
2199 new_files.append(new_file);
2202 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2205 gui->reset_default_message();
2206 gui->default_message();
2209 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2212 // Don't back up here.
2213 if( new_edls.size() ) {
2214 // For pasting, clear the active region
2215 if( load_mode == LOADMODE_PASTE ) {
2216 double start = edl->local_session->get_selectionstart();
2217 double end = edl->local_session->get_selectionend();
2218 if(!EQUIV(start, end))
2219 edl->clear(start, end,
2220 edl->session->labels_follow_edits,
2221 edl->session->plugins_follow_edits,
2222 edl->session->autos_follow_edits);
2224 paste_edls(&new_edls, load_mode, 0, -1,
2225 edl->session->labels_follow_edits,
2226 edl->session->plugins_follow_edits,
2227 edl->session->autos_follow_edits,
2230 else if( load_mode == LOADMODE_NEW_TRACKS &&
2231 edl_mode != LOADMODE_EDL_CLIP )
2232 paste_edls(&new_edls, load_mode, 0, -1, 0, 0, 0, 0);
2233 else if( load_mode != LOADMODE_RESOURCESONLY ||
2234 edl_mode == LOADMODE_EDL_CLIP )
2235 paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
2237 paste_edls(&new_edls, LOADMODE_NOTHING, 0, -1, 0, 0, 0, 0);
2241 // Add new assets to EDL and schedule assets for index building.
2242 int got_indexes = 0;
2243 for( int i=0; i<new_edls.size(); ++i ) {
2244 EDL *new_edl = new_edls[i];
2245 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2246 mainindexes->add_indexable(new_edl->nested_edls[j]);
2247 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2253 for( int i=0; i<new_assets.size(); ++i ) {
2254 Asset *new_asset = new_assets[i];
2255 mainindexes->add_indexable(new_asset);
2256 edl->assets->update(new_asset);
2260 // Start examining next batch of index files
2261 if(got_indexes) mainindexes->start_build();
2266 // opening new session
2267 if( ( load_mode == LOADMODE_REPLACE ||
2268 load_mode == LOADMODE_REPLACE_CONCATENATE ) &&
2269 (ftype != FILE_IS_XML || edl_mode != LOADMODE_EDL_CLIP) ) {
2271 edl->session->proxy_scale = 1;
2272 edl->session->proxy_disabled_scale = 1;
2273 edl->session->proxy_use_scaler = 0;
2274 edl->session->proxy_auto_scale = 0;
2275 edl->session->proxy_beep = 0;
2276 edl->local_session->preview_start = 0;
2277 edl->local_session->preview_end = -1;
2278 edl->local_session->loop_playback = 0;
2279 edl->local_session->set_selectionstart(0);
2280 edl->local_session->set_selectionend(0);
2281 edl->local_session->unset_inpoint();
2282 edl->local_session-> unset_outpoint();
2283 set_brender_active(0, 0);
2288 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2289 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2290 ArrayList<Indexable *> orig_idxbls;
2291 for( int i=0; i<new_assets.size(); ++i )
2292 orig_idxbls.append(new_assets.get(i));
2293 for( int i=0; i<new_edls.size(); ++i ) {
2294 EDL *new_edl = new_edls[i];
2295 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2296 if( track->data_type != TRACK_VIDEO ) continue;
2297 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2298 Indexable *idxbl = (Indexable *)edit->asset;
2299 if( !idxbl ) continue;
2300 if( !idxbl->have_video() ) continue;
2301 if( edit->channel != 0 ) continue; // first layer only
2302 orig_idxbls.append(edit->asset);
2306 gui->unlock_window(); // to update progress bar
2307 int ret = render_proxy(orig_idxbls);
2308 gui->lock_window("MWindow::load_filenames");
2309 float gain = edl->session->proxy_beep;
2310 if( ret >= 0 && gain > 0 ) {
2312 beep(2000., 1.5, gain);
2314 beep(4000., 0.25, gain);
2318 // need to update undo before project, since mwindow is unlocked & a new load
2319 // can begin here. Should really prevent loading until we're done.
2320 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2321 undo_after(_("load"), LOAD_ALL);
2323 for(int i = 0; i < new_edls.size(); i++)
2325 new_edls[i]->remove_user();
2327 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2329 new_edls.remove_all();
2331 for(int i = 0; i < new_assets.size(); i++)
2333 new_assets[i]->Garbage::remove_user();
2336 new_assets.remove_all();
2337 new_files.remove_all_objects();
2340 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2341 if(load_mode == LOADMODE_REPLACE ||
2342 load_mode == LOADMODE_REPLACE_CONCATENATE)
2344 session->changes_made = 0;
2348 session->changes_made = 1;
2351 gui->stop_hourglass();
2354 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2355 update_project(load_mode);
2357 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2362 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2364 Asset *format_asset = new Asset;
2365 format_asset->format = FILE_FFMPEG;
2366 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2367 int new_scale = edl->session->proxy_scale;
2368 ProxyRender proxy_render(this, format_asset, new_scale);
2370 for( int i=0; i<new_idxbls.size(); ++i ) {
2371 Indexable *orig = new_idxbls.get(i);
2372 Asset *proxy = proxy_render.add_original(orig, new_scale);
2373 if( !proxy ) continue;
2375 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2376 int got_it = exists && // if proxy exists, and is newer than orig
2377 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2378 if( got_it ) continue;
2379 proxy_render.add_needed(orig, proxy);
2382 // render needed proxies
2383 int result = proxy_render.create_needed_proxies(new_scale);
2385 add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2387 format_asset->remove_user();
2388 return !result ? proxy_render.needed_proxies.size() : -1;
2391 int MWindow::enable_proxy()
2394 if( edl->session->proxy_scale == 1 &&
2395 edl->session->proxy_disabled_scale != 1 ) {
2396 int new_scale = edl->session->proxy_disabled_scale;
2397 int new_use_scaler = edl->session->proxy_use_scaler;
2398 Asset *asset = new Asset;
2399 asset->format = FILE_FFMPEG;
2400 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2401 ret = to_proxy(asset, new_scale, new_use_scaler);
2402 asset->remove_user();
2404 float gain = edl->session->proxy_beep;
2405 beep(2000., 1.5, gain);
2407 edl->session->proxy_disabled_scale = 1;
2408 gui->lock_window("MWindow::to_proxy");
2409 update_project(LOADMODE_REPLACE);
2410 gui->unlock_window();
2415 int MWindow::disable_proxy()
2417 if( edl->session->proxy_scale != 1 &&
2418 edl->session->proxy_disabled_scale == 1 ) {
2419 int old_scale = edl->session->proxy_scale, new_scale = 1;
2420 int new_use_scaler = edl->session->proxy_use_scaler;
2421 Asset *asset = new Asset;
2422 asset->format = FILE_FFMPEG;
2423 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2424 to_proxy(asset, new_scale, new_use_scaler);
2425 asset->remove_user();
2426 edl->session->proxy_disabled_scale = old_scale;
2427 gui->lock_window("MWindow::to_proxy");
2428 update_project(LOADMODE_REPLACE);
2429 gui->unlock_window();
2434 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2436 ArrayList<Indexable*> orig_idxbls;
2437 ArrayList<Indexable*> proxy_assets;
2439 edl->Garbage::add_user();
2441 undo_before(_("proxy"), this);
2442 int asset_scale = new_scale == 1 ? 0 :
2443 !new_use_scaler ? 1 : new_scale;
2444 ProxyRender proxy_render(this, asset, asset_scale);
2446 // revert project to original size from current size
2447 // remove all session proxy assets at the at the current proxy_scale
2448 int proxy_scale = edl->session->proxy_scale;
2450 if( proxy_scale > 1 ) {
2451 Asset *orig_asset = edl->assets->first;
2452 for( ; orig_asset; orig_asset=orig_asset->next ) {
2453 char new_path[BCTEXTLEN];
2454 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2455 // test if proxy asset was already added to proxy_assets
2457 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2458 got_it = !strcmp(proxy_assets[i]->path, new_path);
2459 if( got_it ) continue;
2460 Asset *proxy_asset = edl->assets->get_asset(new_path);
2461 if( !proxy_asset ) continue;
2462 // add pointer to existing EDL asset if it exists
2463 // EDL won't delete it unless it's the same pointer.
2464 proxy_assets.append(proxy_asset);
2465 proxy_asset->add_user();
2466 orig_idxbls.append(orig_asset);
2467 orig_asset->add_user();
2469 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2470 EDL *orig_nested = edl->nested_edls[i];
2471 char new_path[BCTEXTLEN];
2472 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2474 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2475 // test if proxy asset was already added to proxy_assets
2477 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2478 got_it = !strcmp(proxy_assets[i]->path, new_path);
2479 if( got_it ) continue;
2480 Asset *proxy_nested = edl->assets->get_asset(new_path);
2481 if( !proxy_nested ) continue;
2482 // add pointer to existing EDL asset if it exists
2483 // EDL won't delete it unless it's the same pointer.
2484 proxy_assets.append(proxy_nested);
2485 proxy_nested->add_user();
2486 orig_idxbls.append(orig_nested);
2487 orig_nested->add_user();
2490 // convert from the proxy assets to the original assets
2491 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2493 // remove the references
2494 for( int i=0; i<proxy_assets.size(); ++i ) {
2495 Asset *proxy = (Asset *) proxy_assets[i];
2496 proxy->width = proxy->actual_width;
2497 proxy->height = proxy->actual_height;
2498 proxy->remove_user();
2499 edl->assets->remove_pointer(proxy);
2500 proxy->remove_user();
2502 proxy_assets.remove_all();
2503 for( int i = 0; i < orig_idxbls.size(); i++ )
2504 orig_idxbls[i]->remove_user();
2505 orig_idxbls.remove_all();
2508 ArrayList<char *> confirm_paths; // test for new files
2509 confirm_paths.set_array_delete();
2511 // convert to new size if not original size
2512 if( new_scale != 1 ) {
2514 Asset *orig = edl->assets->first;
2515 for( ; orig; orig=orig->next ) {
2516 Asset *proxy = proxy_render.add_original(orig, new_scale);
2517 if( !proxy ) continue;
2518 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2519 int got_it = exists && // if proxy exists, and is newer than orig
2520 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2522 if( exists ) // prompt user to overwrite
2523 confirm_paths.append(cstrdup(proxy->path));
2524 proxy_render.add_needed(orig, proxy);
2527 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2528 EDL *orig_nested = edl->nested_edls[i];
2529 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2530 if( !proxy ) continue;
2531 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2532 int got_it = exists && // if proxy exists, and is newer than orig_nested
2533 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2535 if( exists ) // prompt user to overwrite
2536 confirm_paths.append(cstrdup(proxy->path));
2537 proxy_render.add_needed(orig_nested, proxy);
2543 // test for existing files
2544 if( confirm_paths.size() ) {
2545 result = ConfirmSave::test_files(this, &confirm_paths);
2546 confirm_paths.remove_all_objects();
2550 result = proxy_render.create_needed_proxies(new_scale);
2552 if( !result ) // resize project
2553 edl->set_proxy(new_scale, new_use_scaler,
2554 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2556 undo_after(_("proxy"), LOAD_ALL);
2557 edl->Garbage::remove_user();
2560 return !result ? proxy_render.needed_proxies.size() : -1;
2563 void MWindow::test_plugins(EDL *new_edl, const char *path)
2565 char string[BCTEXTLEN];
2567 // Do a check whether plugins exist
2568 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2569 for( int k=0; k<track->plugin_set.total; ++k ) {
2570 PluginSet *plugin_set = track->plugin_set[k];
2571 for( Plugin *plugin = (Plugin*)plugin_set->first;
2572 plugin; plugin = (Plugin*)plugin->next ) {
2573 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2574 // ok we need to find it in plugindb
2575 PluginServer *server =
2576 scan_plugindb(plugin->title, track->data_type);
2577 if( !server || server->transition ) {
2579 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2580 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2581 "effect", _(plugin->title), path);
2582 MainError::show_error(string);
2587 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2588 if( !edit->transition ) continue;
2589 // ok we need to find transition in plugindb
2590 PluginServer *server =
2591 scan_plugindb(edit->transition->title, track->data_type);
2592 if( !server || !server->transition ) {
2594 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2595 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2596 "transition", _(edit->transition->title), path);
2597 MainError::show_error(string);
2604 void MWindow::init_shm(const char *pfn, int64_t min)
2607 // Fix shared memory
2608 FILE *fd = fopen(pfn, "r");
2610 fscanf(fd, "%jd", &result);
2612 if( result >= min ) return;
2615 fd = fopen(pfn, "w");
2617 fprintf(fd, "0x%jx", min);
2620 fd = fopen(pfn, "r");
2622 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2626 fscanf(fd, "%jd", &result);
2628 if( result < min ) {
2629 eprintf(_("MWindow::init_shm: %s is %p.\n"
2630 "you probably need to be root, or:\n"
2631 "as root, run: echo 0x%jx > %s\n"
2632 "before trying to start cinelerra.\n"
2633 "It should be at least 0x%jx for Cinelerra.\n"),
2634 pfn, (void *)result, min, pfn, min);
2638 void MWindow::create_objects(int want_gui,
2642 const int debug = 0;
2643 if(debug) PRINT_TRACE
2645 // For some reason, init_signals must come after show_splash or the signals won't
2648 if(debug) PRINT_TRACE
2651 if(debug) PRINT_TRACE
2654 if(debug) PRINT_TRACE
2655 default_standard = default_std();
2656 init_defaults(defaults, config_path);
2660 splash_window->update_status(_("Initializing Plugins"));
2661 init_plugins(this, preferences);
2662 if(debug) PRINT_TRACE
2663 init_ladspa_plugins(this, preferences);
2664 if(debug) PRINT_TRACE
2665 init_plugin_tips(*plugindb, cin_lang);
2667 splash_window->update_status(_("Initializing GUI"));
2668 if(debug) PRINT_TRACE
2671 if(debug) PRINT_TRACE
2675 splash_window->update_status(_("Initializing Fonts"));
2676 char string[BCTEXTLEN];
2677 strcpy(string, preferences->plugin_dir);
2678 strcat(string, "/" FONT_SEARCHPATH);
2679 BC_Resources::init_fontconfig(string);
2680 if(debug) PRINT_TRACE
2686 // Default project created here
2688 if(debug) PRINT_TRACE
2691 if(debug) PRINT_TRACE
2696 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2699 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2701 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2702 if(session->show_vwindow)
2703 get_viewer(1, DEFAULT_VWINDOW);
2704 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2707 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2710 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2713 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2716 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2719 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2722 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2728 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2729 mainprogress = new MainProgress(this, gui);
2730 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2731 undo = new MainUndo(this);
2733 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2735 plugin_guis = new PluginGUIs(this);
2736 dead_plugins = new ArrayList<PluginServer*>;
2737 keyframe_threads = new ArrayList<KeyFrameThread*>;
2739 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2742 session->show_vwindow);
2744 // Show all vwindows
2745 // if(session->show_vwindow) {
2746 // for(int j = 0; j < vwindows.size(); j++) {
2747 // VWindow *vwindow = vwindows[j];
2748 // if( !vwindow->is_running() ) continue;
2749 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2752 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2753 // vwindow->gui->lock_window("MWindow::create_objects 1");
2754 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2755 // vwindow->gui->show_window();
2756 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2757 // vwindow->gui->unlock_window();
2762 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2764 if(session->show_cwindow)
2766 cwindow->gui->lock_window("MWindow::create_objects 1");
2767 cwindow->gui->show_window();
2768 cwindow->gui->unlock_window();
2771 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2772 if(session->show_awindow)
2774 awindow->gui->lock_window("MWindow::create_objects 1");
2775 awindow->gui->show_window();
2776 awindow->gui->unlock_window();
2779 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2780 if(session->show_lwindow)
2782 lwindow->gui->lock_window("MWindow::create_objects 1");
2783 lwindow->gui->show_window();
2784 lwindow->gui->unlock_window();
2787 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2789 (int)timer.get_difference(),
2791 if(session->show_gwindow)
2793 gwindow->gui->lock_window("MWindow::create_objects 1");
2794 gwindow->gui->show_window();
2795 gwindow->gui->unlock_window();
2798 if(debug) PRINT_TRACE
2800 gui->lock_window("MWindow::create_objects 1");
2801 gui->mainmenu->load_defaults(defaults);
2802 gui->mainmenu->update_toggles(0);
2803 gui->update_patchbay();
2804 gui->draw_canvas(0, 0);
2805 gui->draw_cursor(1);
2807 gui->raise_window();
2808 gui->unlock_window();
2809 cwindow->gui->lock_window("MWindow::create_objects 1");
2810 cwindow->gui->tool_panel->raise_tool();
2811 cwindow->gui->unlock_window();
2812 if(debug) PRINT_TRACE
2814 if(preferences->use_tipwindow)
2816 if(debug) PRINT_TRACE
2818 gui->add_keyboard_listener(
2819 (int (BC_WindowBase::*)(BC_WindowBase *))
2820 &MWindowGUI::keyboard_listener);
2823 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2824 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2825 if(debug) PRINT_TRACE
2827 BC_WindowBase::get_resources()->vframe_shm = 1;
2830 int MWindow::uses_opengl()
2832 if( !playback_3d || !playback_3d->running() ) return 0;
2833 PlaybackConfig *playback_config = edl->session->playback_config;
2834 return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
2837 void MWindow::show_splash()
2839 #include "data/heroine_logo9_png.h"
2840 VFrame *frame = new VFramePng(heroine_logo9_png);
2841 BC_DisplayInfo dpyi;
2842 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2843 int rr = (rw < rh ? rw : rh) / 4;
2844 splash_window = new SplashGUI(frame, rr, rr);
2845 splash_window->create_objects();
2848 void MWindow::hide_splash()
2851 delete splash_window;
2856 void MWindow::start()
2860 // vwindows[DEFAULT_VWINDOW]->start();
2871 playback_3d->start();
2877 run_lock->lock("MWindow::run");
2881 brender_lock->lock("MWindow::run 1");
2882 delete brender; brender = 0;
2883 brender_lock->unlock();
2885 interrupt_indexes();
2891 void MWindow::show_vwindow()
2893 int total_running = 0;
2894 session->show_vwindow = 1;
2896 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2897 // Raise all windows which are visible
2898 for(int j = 0; j < vwindows.size(); j++) {
2899 VWindow *vwindow = vwindows[j];
2900 if( !vwindow->is_running() ) continue;
2901 vwindow->gui->lock_window("MWindow::show_vwindow");
2902 vwindow->gui->show_window(0);
2903 vwindow->gui->raise_window();
2904 vwindow->gui->flush();
2905 vwindow->gui->unlock_window();
2909 // If no windows visible
2912 get_viewer(1, DEFAULT_VWINDOW);
2915 gui->mainmenu->show_vwindow->set_checked(1);
2918 void MWindow::show_awindow()
2920 session->show_awindow = 1;
2921 awindow->gui->lock_window("MWindow::show_awindow");
2922 awindow->gui->show_window();
2923 awindow->gui->raise_window();
2924 awindow->gui->flush();
2925 awindow->gui->unlock_window();
2926 gui->mainmenu->show_awindow->set_checked(1);
2929 char *MWindow::get_cwindow_display()
2931 char *x11_host = screens < 2 || session->window_config == 0 ?
2932 session->a_x11_host : session->b_x11_host;
2933 return *x11_host ? x11_host : 0;
2936 void MWindow::show_cwindow()
2938 session->show_cwindow = 1;
2939 cwindow->show_window();
2940 gui->mainmenu->show_cwindow->set_checked(1);
2943 void MWindow::show_gwindow()
2945 session->show_gwindow = 1;
2947 gwindow->gui->lock_window("MWindow::show_gwindow");
2948 gwindow->gui->show_window();
2949 gwindow->gui->raise_window();
2950 gwindow->gui->flush();
2951 gwindow->gui->unlock_window();
2953 gui->mainmenu->show_gwindow->set_checked(1);
2955 void MWindow::hide_gwindow()
2957 session->show_gwindow = 0;
2959 gwindow->gui->lock_window("MWindow::show_gwindow");
2960 gwindow->gui->hide_window();
2961 gwindow->gui->unlock_window();
2964 void MWindow::show_lwindow()
2966 session->show_lwindow = 1;
2967 lwindow->gui->lock_window("MWindow::show_lwindow");
2968 lwindow->gui->show_window();
2969 lwindow->gui->raise_window();
2970 lwindow->gui->flush();
2971 lwindow->gui->unlock_window();
2972 gui->mainmenu->show_lwindow->set_checked(1);
2975 void MWindow::restore_windows()
2977 if( !session->show_vwindow ) {
2978 for( int i=0, n=vwindows.size(); i<n; ++i ) {
2979 VWindow *vwindow = vwindows[i];
2980 if( !vwindow || !vwindow->is_running() ) continue;
2981 vwindow->gui->lock_window("MWindow::restore_windows");
2982 vwindow->gui->close(1);
2983 vwindow->gui->unlock_window();
2989 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
2990 awindow->gui->lock_window("MWindow::restore_windows");
2991 awindow->gui->close_event();
2992 awindow->gui->unlock_window();
2994 else if( session->show_awindow && awindow->gui->is_hidden() )
2997 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
2998 cwindow->gui->lock_window("MWindow::restore_windows");
2999 cwindow->hide_window();
3000 cwindow->gui->unlock_window();
3002 else if( session->show_cwindow && cwindow->gui->is_hidden() )
3003 cwindow->show_window();
3005 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
3006 gwindow->gui->lock_window("MWindow::restore_windows");
3007 gwindow->gui->close_event();
3008 gwindow->gui->unlock_window();
3010 else if( session->show_gwindow && gwindow->gui->is_hidden() )
3013 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
3014 lwindow->gui->lock_window("MWindow::restore_windows");
3015 lwindow->gui->close_event();
3016 lwindow->gui->unlock_window();
3018 else if( session->show_lwindow && lwindow->gui->is_hidden() )
3024 void MWindow::load_layout(const char *layout)
3026 char path[BCTEXTLEN];
3027 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3028 session->load_file(path);
3030 gui->default_positions();
3034 void MWindow::save_layout(const char *layout)
3036 char path[BCTEXTLEN];
3037 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3038 session->save_file(path);
3041 void MWindow::delete_layout(const char *layout)
3043 char path[BCTEXTLEN];
3044 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3048 int MWindow::tile_windows(int window_config)
3050 int need_reload = 0;
3051 int play_config = window_config==0 ? 0 : 1;
3052 edl->session->playback_config->load_defaults(defaults, play_config);
3053 session->default_window_positions(window_config);
3054 if( screens == 1 ) {
3055 gui->default_positions();
3056 sync_parameters(CHANGE_ALL);
3063 void MWindow::toggle_loop_playback()
3065 edl->local_session->loop_playback = !edl->local_session->loop_playback;
3066 set_loop_boundaries();
3069 gui->draw_overlays(1);
3070 sync_parameters(CHANGE_PARAMS);
3073 void MWindow::set_screens(int value)
3078 void MWindow::set_auto_keyframes(int value)
3080 edl->session->auto_keyframes = value;
3081 gui->mbuttons->edit_panel->keyframe->update(value);
3083 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
3084 cwindow->gui->flush();
3085 cwindow->gui->unlock_window();
3088 void MWindow::set_span_keyframes(int value)
3090 edl->session->span_keyframes = value;
3091 gui->mbuttons->edit_panel->span_keyframe->update(value);
3093 cwindow->gui->lock_window("MWindow::set_span_keyframes");
3094 cwindow->gui->flush();
3095 cwindow->gui->unlock_window();
3098 void MWindow::set_auto_visibility(Autos *autos, int value)
3100 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3101 edl->session->auto_conf->plugins = value;
3102 else if( autos->autoidx >= 0 )
3103 edl->session->auto_conf->autos[autos->autoidx] = value;
3107 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3108 gui->mainmenu->update_toggles(1);
3109 gui->unlock_window();
3110 gwindow->gui->update_toggles(1);
3111 gui->lock_window("MWindow::set_auto_visibility");
3114 void MWindow::set_keyframe_type(int mode)
3116 gui->lock_window("MWindow::set_keyframe_type");
3117 edl->local_session->floatauto_type = mode;
3118 gui->mainmenu->update_toggles(0);
3119 gui->unlock_window();
3122 int MWindow::set_editing_mode(int new_editing_mode)
3124 edl->session->editing_mode = new_editing_mode;
3125 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3126 gui->mbuttons->edit_panel->update();
3127 gui->set_editing_mode(1);
3129 cwindow->gui->lock_window("MWindow::set_editing_mode");
3130 cwindow->gui->edit_panel->update();
3131 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3132 cwindow->gui->unlock_window();
3136 void MWindow::toggle_editing_mode()
3138 int mode = edl->session->editing_mode;
3139 if( mode == EDITING_ARROW )
3140 set_editing_mode(EDITING_IBEAM);
3142 set_editing_mode(EDITING_ARROW);
3145 void MWindow::toggle_camera_xyz()
3147 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3148 gwindow->gui->toggle_camera_xyz();
3149 gwindow->gui->unlock_window();
3152 void MWindow::toggle_projector_xyz()
3154 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3155 gwindow->gui->toggle_projector_xyz();
3156 gwindow->gui->unlock_window();
3159 void MWindow::set_labels_follow_edits(int value)
3161 edl->session->labels_follow_edits = value;
3162 gui->mbuttons->edit_panel->locklabels->update(value);
3163 gui->mainmenu->labels_follow_edits->set_checked(value);
3167 void MWindow::sync_parameters(int change_type)
3169 if( in_destructor ) return;
3171 // Sync engines which are playing back
3172 if( cwindow->playback_engine->is_playing_back ) {
3173 if( change_type == CHANGE_PARAMS ) {
3174 // TODO: block keyframes until synchronization is done
3175 cwindow->playback_engine->sync_parameters(edl);
3179 int command = cwindow->playback_engine->command->command;
3180 // Waiting for tracking to finish would make the restart position more
3181 // accurate but it can't lock the window to stop tracking for some reason.
3182 // Not waiting for tracking gives a faster response but restart position is
3183 // only as accurate as the last tracking update.
3184 cwindow->playback_engine->transport_stop(0);
3185 cwindow->playback_engine->next_command->realtime = 1;
3186 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3190 cwindow->refresh_frame(change_type);
3194 void MWindow::age_caches()
3196 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3198 // preferences->cache_size,
3199 // audio_cache->get_memory_usage(1),
3200 // video_cache->get_memory_usage(1),
3201 // frame_cache->get_memory_usage(),
3202 // wave_cache->get_memory_usage(),
3204 frame_cache->age_cache(512);
3205 wave_cache->age_cache(8192);
3207 int64_t memory_usage;
3208 int64_t prev_memory_usage = 0;
3210 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3211 while( !result && prev_memory_usage !=
3212 (memory_usage=video_cache->get_memory_usage(1)) &&
3213 memory_usage > video_size ) {
3214 video_cache->delete_oldest();
3215 prev_memory_usage = memory_usage;
3218 prev_memory_usage = 0;
3220 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3221 while( !result && prev_memory_usage !=
3222 (memory_usage=audio_cache->get_memory_usage(1)) &&
3223 memory_usage > audio_size ) {
3224 audio_cache->delete_oldest();
3225 prev_memory_usage = memory_usage;
3229 void MWindow::reset_android_remote()
3231 gui->use_android_remote(preferences->android_remote);
3235 void MWindow::show_keyframe_gui(Plugin *plugin)
3237 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3238 // Find existing thread
3239 for( int i=0; i<keyframe_threads->size(); ++i ) {
3240 int plugin_id = keyframe_threads->get(i)->plugin_id;
3241 if( plugin_id == plugin->orig_id ) {
3242 keyframe_threads->get(i)->start_window(plugin, 0);
3243 keyframe_gui_lock->unlock();
3248 // Find unused thread
3249 for( int i=0; i<keyframe_threads->size(); ++i ) {
3250 if( keyframe_threads->get(i)->plugin_id < 0 ) {
3251 keyframe_threads->get(i)->start_window(plugin, 0);
3252 keyframe_gui_lock->unlock();
3257 // Create new thread
3258 KeyFrameThread *thread = new KeyFrameThread(this);
3259 keyframe_threads->append(thread);
3260 thread->start_window(plugin, 0);
3261 keyframe_gui_lock->unlock();
3265 void MWindow::show_plugin(Plugin *plugin)
3270 // Remove previously deleted plugin GUIs
3271 dead_plugin_lock->lock("MWindow::show_plugin");
3272 dead_plugins->remove_all_objects();
3273 dead_plugin_lock->unlock();
3275 //printf("MWindow::show_plugin %d\n", __LINE__);
3278 plugin_gui_lock->lock("MWindow::show_plugin");
3279 for( int i=0; i<plugin_guis->total; ++i ) {
3280 // Pointer/id comparison
3281 PluginServer *plugin_gui = plugin_guis->get(i);
3282 if( plugin_gui->plugin_id == plugin->orig_id ) {
3283 plugin_gui->raise_window();
3290 //printf("MWindow::show_plugin 1\n");
3291 if( !done && !plugin->track ) {
3292 printf("MWindow::show_plugin track not defined.\n");
3296 PluginServer *server = scan_plugindb(plugin->title,
3297 plugin->track->data_type);
3299 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3300 if(server && server->uses_gui)
3302 PluginServer *gui = new PluginServer(*server);
3303 plugin_guis->append(gui);
3304 // Needs mwindow to do GUI
3305 gui->set_mwindow(this);
3306 gui->open_plugin(0, preferences, edl, plugin);
3311 plugin_gui_lock->unlock();
3312 // update show/gui_id
3313 sync_parameters(CHANGE_PARAMS);
3314 //printf("MWindow::show_plugin %d\n", __LINE__);
3317 //printf("MWindow::show_plugin 2\n");
3320 void MWindow::hide_plugin(Plugin *plugin, int lock)
3323 return hide_plugin(plugin->orig_id, lock);
3326 void MWindow::hide_plugin(int plugin_id, int lock)
3328 // Update the toggle
3329 gui->lock_window("MWindow::hide_plugin");
3330 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3331 gui->unlock_window();
3333 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3334 for( int i=0; i<plugin_guis->total; ++i ) {
3335 PluginServer *plugin_gui = plugin_guis->get(i);
3336 if( plugin_gui->plugin_id == plugin_id ) {
3337 plugin_guis->remove(plugin_gui);
3338 if(lock) plugin_gui_lock->unlock();
3339 // Last command executed in client side close
3340 // Schedule for deletion
3341 plugin_gui->hide_gui();
3342 delete_plugin(plugin_gui);
3347 if(lock) plugin_gui_lock->unlock();
3348 // update show/gui_id
3349 sync_parameters(CHANGE_PARAMS);
3352 void MWindow::delete_plugin(PluginServer *plugin)
3354 dead_plugin_lock->lock("MWindow::delete_plugin");
3355 dead_plugins->append(plugin);
3356 dead_plugin_lock->unlock();
3359 void MWindow::hide_plugins()
3361 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3362 while(plugin_guis->size())
3364 PluginServer *ptr = plugin_guis->get(0);
3365 plugin_guis->remove(ptr);
3366 plugin_gui_lock->unlock();
3367 // Last command executed in client side close
3368 // Schedule for deletion
3371 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3373 plugin_gui_lock->unlock();
3375 hide_keyframe_guis();
3378 void MWindow::hide_keyframe_guis()
3380 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3381 for(int i = 0; i < keyframe_threads->size(); i++)
3383 keyframe_threads->get(i)->close_window();
3385 keyframe_gui_lock->unlock();
3388 void MWindow::hide_keyframe_gui(Plugin *plugin)
3390 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3391 for( int i = 0; i < keyframe_threads->size(); i++) {
3392 KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
3393 if( keyframe_gui->plugin_id == plugin->orig_id ) {
3394 keyframe_gui->close_window();
3398 keyframe_gui_lock->unlock();
3401 int MWindow::get_hash_color(Edit *edit)
3403 Indexable *idxbl = edit->asset ?
3404 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3405 if( !idxbl ) return 0;
3406 char path[BCTEXTLEN];
3407 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3408 edl->session->proxy_scale == 1 ||
3409 ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
3410 strcpy(path, idxbl->path);
3411 char *cp = strrchr(path, '/');
3412 cp = !cp ? path : cp+1;
3413 uint8_t *bp = (uint8_t*)cp;
3415 while( *bp ) v += *bp++;
3416 return get_hash_color(v);
3419 int MWindow::get_hash_color(int v)
3421 int hash = 0x303030;
3422 if( v & 0x01 ) hash ^= 0x000040;
3423 if( v & 0x02 ) hash ^= 0x004000;
3424 if( v & 0x04 ) hash ^= 0x400000;
3425 if( v & 0x08 ) hash ^= 0x080000;
3426 if( v & 0x10 ) hash ^= 0x000800;
3427 if( v & 0x20 ) hash ^= 0x000008;
3428 if( v & 0x40 ) hash ^= 0x404040;
3429 if( v & 0x80 ) hash ^= 0x080808;
3433 int MWindow::get_group_color(int v)
3435 int color = 0x606060;
3436 if( v & 0x01 ) color ^= 0x000080;
3437 if( v & 0x02 ) color ^= 0x008000;
3438 if( v & 0x04 ) color ^= 0x800000;
3439 if( v & 0x08 ) color ^= 0x100000;
3440 if( v & 0x10 ) color ^= 0x001000;
3441 if( v & 0x20 ) color ^= 0x000010;
3442 if( v & 0x40 ) color ^= 0x080808;
3443 if( v & 0x80 ) color ^= 0x909090;
3447 int MWindow::get_title_color(Edit *edit)
3449 unsigned color = edit->color & 0xffffff;
3450 unsigned alpha = (~edit->color>>24) & 0xff;
3452 if( edit->group_id )
3453 color = get_group_color(edit->group_id);
3454 else if( preferences->autocolor_assets )
3455 color = get_hash_color(edit);
3460 alpha = session->title_bar_alpha*255;
3461 return color | (~alpha<<24);
3464 void MWindow::update_keyframe_guis()
3466 // Send new configuration to keyframe GUI's
3467 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3468 for( int i=0; i<keyframe_threads->size(); ++i ) {
3469 KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
3470 Plugin *plugin = edl->tracks->plugin_exists(keyframe_gui->plugin_id);
3472 keyframe_gui->update_gui(1);
3474 keyframe_gui->close_window();
3476 keyframe_gui_lock->unlock();
3479 void MWindow::update_plugin_guis(int do_keyframe_guis)
3481 // Send new configuration to plugin GUI's
3482 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3484 for( int i=0; i<plugin_guis->size(); ++i ) {
3485 PluginServer *plugin_gui = plugin_guis->get(i);
3486 Plugin *plugin = edl->tracks->plugin_exists(plugin_gui->plugin_id);
3487 if( plugin && plugin->show )
3488 plugin_gui->update_gui();
3490 // Schedule for deletion if no plugin or not shown
3491 plugin_guis->remove_number(i--);
3492 plugin_gui->hide_gui();
3493 delete_plugin(plugin_gui);
3498 // Change plugin variable if not visible
3499 Track *track = edl->tracks->first;
3500 for( ; track; track=track->next ) {
3501 for( int i=0; i < track->plugin_set.size(); ++i ) {
3502 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3503 for( ; plugin; plugin = (Plugin*)plugin->next ) {
3505 for( int i=0; i<plugin_guis->size(); ++i ) {
3506 PluginServer *server = plugin_guis->get(i);
3507 if( server->plugin_id == plugin->orig_id ) {
3512 if( !got_it ) plugin->show = 0;
3517 plugin_gui_lock->unlock();
3518 if( do_keyframe_guis )
3519 update_keyframe_guis();
3522 void MWindow::stop_plugin_guis()
3524 // Send new configuration to plugin GUI's
3525 plugin_gui_lock->lock("MWindow::stop_plugin_guis");
3527 for( int i=0; i<plugin_guis->size(); ++i ) {
3528 PluginServer *plugin_gui = plugin_guis->get(i);
3529 plugin_gui->render_stop();
3531 plugin_gui_lock->unlock();
3534 int MWindow::plugin_gui_open(Plugin *plugin)
3536 int gui_id = plugin->gui_id;
3537 if( gui_id < 0 ) return 0;
3538 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3539 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3540 int result = plugin_server ? 1 : 0;
3541 plugin_gui_lock->unlock();
3546 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3548 int gui_id = plugin->gui_id;
3549 if( gui_id < 0 ) return;
3550 plugin_gui_lock->lock("MWindow::render_plugin_gui 0");
3551 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3553 plugin_server->render_gui(data);
3554 plugin_gui_lock->unlock();
3557 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3559 int gui_id = plugin->gui_id;
3560 if( gui_id < 0 ) return;
3561 plugin_gui_lock->lock("MWindow::render_plugin_gui 1");
3562 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3564 plugin_server->render_gui(data, size);
3565 plugin_gui_lock->unlock();
3568 void MWindow::reset_plugin_gui_frames(Plugin *plugin)
3570 int gui_id = plugin->gui_id;
3571 if( gui_id < 0 ) return;
3572 plugin_gui_lock->lock("MWindow::reset_plugin_gui_frames");
3573 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3575 plugin_server->reset_plugin_gui_frames();
3576 plugin_gui_lock->unlock();
3579 void MWindow::render_plugin_gui_frames(PluginClientFrames *frames, Plugin *plugin)
3581 int gui_id = plugin->gui_id;
3582 if( gui_id < 0 ) return;
3583 plugin_gui_lock->lock("MWindow::render_plugin_gui_frames");
3584 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3586 plugin_server->render_plugin_gui_frames(frames);
3587 plugin_gui_lock->unlock();
3590 double MWindow::get_tracking_position()
3592 return edl->local_session->get_selectionstart(1);
3595 int MWindow::get_tracking_direction()
3597 return cwindow->playback_engine->get_direction();
3600 void MWindow::update_plugin_states()
3602 plugin_gui_lock->lock("MWindow::update_plugin_states");
3603 for( int i=0; i<plugin_guis->total; ++i ) {
3605 PluginServer *src_plugingui = plugin_guis->get(i);
3606 int plugin_id = src_plugingui->plugin_id;
3607 Plugin *src_plugin = edl->tracks->plugin_exists(plugin_id);
3608 // Doesn't exist anymore
3610 hide_plugin(plugin_id, 0);
3614 plugin_gui_lock->unlock();
3618 void MWindow::update_plugin_titles()
3620 for( int i=0; i<plugin_guis->total; ++i )
3621 plugin_guis->get(i)->update_title();
3624 int MWindow::asset_to_edl(EDL *new_edl,
3626 RecordLabels *labels)
3628 const int debug = 0;
3629 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3632 // Keep frame rate, sample rate, and output size unchanged.
3633 // These parameters would revert the project if VWindow displayed an asset
3634 // of different size than the project.
3635 if(new_asset->video_data)
3637 new_edl->session->video_tracks = new_asset->layers;
3640 new_edl->session->video_tracks = 0;
3642 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3648 if(new_asset->audio_data)
3650 new_edl->session->audio_tracks = new_asset->channels;
3653 new_edl->session->audio_tracks = 0;
3654 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3656 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3657 new_edl->create_default_tracks();
3658 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3659 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3663 //printf("MWindow::asset_to_edl 3\n");
3664 new_edl->insert_asset(new_asset,
3669 //printf("MWindow::asset_to_edl 3\n");
3670 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3672 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3673 if(edl->session->cursor_on_frames)
3675 double length = new_edl->tracks->total_length();
3676 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3677 new_edl->tracks->clear(length, edl_length, 1, 1);
3683 char string[BCTEXTLEN];
3685 fs.extract_name(string, new_asset->path);
3686 //printf("MWindow::asset_to_edl 3\n");
3688 strcpy(new_edl->local_session->clip_title, string);
3689 //printf("MWindow::asset_to_edl 4 %s\n", string);
3690 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3692 new_edl->local_session->asset2edl = 1;
3697 // Reset everything after a load.
3698 void MWindow::update_project(int load_mode)
3700 const int debug = 0;
3702 if(debug) PRINT_TRACE
3703 edl->tracks->update_y_pixels(theme);
3704 session->update_clip_number();
3706 if(debug) PRINT_TRACE
3708 if( load_mode == LOADMODE_REPLACE ||
3709 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3710 delete gui->keyvalue_popup;
3711 gui->keyvalue_popup = 0;
3715 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3716 if(debug) PRINT_TRACE
3717 gui->unlock_window();
3720 cwindow->update(0, 0, 1, 1, 1);
3722 if(debug) PRINT_TRACE
3724 // Close all the vwindows
3725 if( load_mode == LOADMODE_REPLACE ||
3726 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3727 if(debug) PRINT_TRACE
3728 int first_vwindow = 0;
3729 if(session->show_vwindow) first_vwindow = 1;
3730 // Change visible windows to no source
3731 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3732 VWindow *vwindow = vwindows[i];
3733 if( !vwindow->is_running() ) continue;
3734 vwindow->change_source(-1);
3737 // Close remaining windows
3738 for(int i = first_vwindow; i < vwindows.size(); i++) {
3739 VWindow *vwindow = vwindows[i];
3740 if( !vwindow->is_running() ) continue;
3741 vwindow->close_window();
3743 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3744 VWindow *vwindow = get_viewer(1, -1);
3745 vwindow->change_source(i);
3747 if(debug) PRINT_TRACE
3751 for( int i=0; i<edl->mixers.size(); ++i ) {
3752 Mixer *mixer = edl->mixers[i];
3753 ZWindow *zwindow = get_mixer(mixer);
3754 zwindow->set_title(mixer->title);
3757 cwindow->gui->canvas->set_zoom(edl, 0);
3761 if(debug) PRINT_TRACE
3762 cwindow->gui->lock_window("MWindow::update_project 2");
3763 cwindow->gui->timebar->update(0);
3764 Track *track = cwindow->calculate_affected_track();
3765 cwindow->mask_track_id = track ? track->get_id() : -1;
3766 cwindow->gui->tool_panel->raise_tool();
3767 cwindow->gui->update_canvas(0);
3768 cwindow->gui->unlock_window();
3770 if(debug) PRINT_TRACE
3771 cwindow->refresh_frame(CHANGE_ALL);
3773 awindow->gui->async_update_assets();
3774 if(debug) PRINT_TRACE
3776 gui->lock_window("MWindow::update_project");
3777 gui->update_mixers(0, 0);
3779 if(debug) PRINT_TRACE
3782 void MWindow::stack_push(EDL *new_edl, Indexable *idxbl, Edit *edit)
3784 int got_indexes = 0;
3785 for( int i=0; i<new_edl->nested_edls.size(); ++i ) {
3786 EDL *nested_edl = new_edl->nested_edls[i];
3787 mainindexes->add_indexable(nested_edl);
3788 edl->nested_edls.update_index(nested_edl);
3791 for( Asset *asset=new_edl->assets->first; asset; asset=asset->next ) {
3792 mainindexes->add_indexable(asset);
3793 edl->assets->update(asset);
3796 // Start examining next batch of index files
3798 mainindexes->start_build();
3801 gui->lock_window("MWindow::stack_push");
3802 if( stack.size() < 9 ) {
3806 StackItem &item = stack.append();
3809 item.new_edl = new_edl;
3810 item.duration = new_edl->tracks->total_length();
3814 if( idxbl && idxbl->is_asset ) {
3816 Asset *asset = (Asset *)idxbl;
3817 if( asset->format == FILE_REF &&
3818 !stat(asset->path, &st) )
3819 item.mtime = st.st_mtime;
3823 strcpy(session->filename, edl->path);
3824 undo = new MainUndo(this);
3825 gui->stack_button->update();
3826 update_project(LOADMODE_REPLACE);
3828 gui->unlock_window();
3832 void MWindow::stack_pop()
3834 if( !stack.size() ) return;
3835 // writes on config_path/backup%d.xml
3838 // already have gui lock
3839 StackItem &item = stack.last();
3840 // session edl replaced, overwrite and save clip data
3841 if( item.new_edl != edl )
3842 item.new_edl->overwrite_clip(edl);
3843 Edit *edit = item.edit;
3844 // resize the referring edit if the edl duration changed
3846 double duration = item.new_edl->tracks->total_length();
3847 double dt = duration - item.duration;
3848 if( fabs(dt) > 1e-4 ) {
3849 int64_t du = edit->track->to_units(dt,0);
3850 if( (edit->length+=du) < 0 )
3858 Indexable *idxbl = item.idxbl;
3859 int64_t mtime = item.mtime;
3862 gui->unlock_window();
3863 gui->resource_thread->close_indexable(idxbl);
3864 remove_from_caches(idxbl);
3865 remove_indexfile(idxbl);
3866 mainindexes->add_indexable(idxbl);
3867 mainindexes->start_build();
3868 awindow->gui->async_update_assets();
3869 gui->lock_window("MWindow::stack_pop");
3871 strcpy(session->filename, edl->path);
3872 update_project(LOADMODE_REPLACE);
3873 undo_after(_("open edl"), LOAD_ALL);
3875 gui->stack_button->update();
3876 if( mtime && idxbl && idxbl->is_asset ) {
3878 Asset *asset = (Asset *)idxbl;
3879 if( asset->format == FILE_REF && !stat(asset->path, &st) &&
3880 item.mtime == st.st_mtime ) {
3881 char text[BCTEXTLEN];
3882 snprintf(text, sizeof(text),
3883 _("Warning: Asset not updated: %s"), asset->path);
3884 show_warning(&preferences->warn_stack, text);
3889 int MWindow::save(EDL *edl, char *filename, int stat)
3892 edl->save_xml(&file, filename);
3893 file.terminate_string();
3894 if( file.write_to_file(filename) ) {
3895 eprintf(_("Couldn't open %s"), filename);
3899 char string[BCTEXTLEN];
3900 char *filename = stack.size() ?
3901 stack[0].edl->path : session->filename;
3902 sprintf(string, _("\"%s\" %jdC written"),
3903 filename, file.length());
3904 gui->lock_window("SaveAs::run");
3905 gui->show_message(string);
3906 gui->unlock_window();
3911 int MWindow::save(int save_as)
3913 char new_path[BCTEXTLEN]; new_path[0] = 0;
3914 char *path = stack.size() ? stack[0].edl->path : session->filename;
3915 if( save_as || !path[0] ) {
3916 if( ConfirmSave::get_save_path(this, new_path) )
3918 if( stack.size() ) {
3919 strcpy(path, new_path);
3920 set_titlebar(new_path);
3923 set_filename(new_path);
3924 gui->mainmenu->add_load(new_path);
3927 for( int i=stack.size(); --i>=0; ) {
3928 StackItem &item = stack[i];
3929 Indexable *idxbl = item.idxbl;
3930 if( idxbl->is_asset ) {
3931 Asset *asset = (Asset *)idxbl;
3932 if( asset->format == FILE_REF ) {
3933 if( save(item.new_edl, asset->path, 0) )
3937 else if( item.new_edl != item.idxbl )
3938 item.new_edl->overwrite_clip((EDL*)item.idxbl);
3940 EDL *new_edl = stack.size() ? stack[0].edl : edl;
3941 save(new_edl, path, 1);
3945 void MWindow::show_plugins()
3947 for( Track *track=edl->tracks->first; track; track=track->next ) {
3948 for( int i=0; i<track->plugin_set.size(); ++i ) {
3949 PluginSet *plugins = track->plugin_set[i];
3950 Plugin *plugin = plugins->get_first_plugin();
3951 for( ; plugin; plugin=(Plugin*)plugin->next ) {
3952 if( plugin->plugin_type == PLUGIN_STANDALONE &&
3954 show_plugin(plugin);
3960 void MWindow::clip_to_media()
3962 if( edl->session->proxy_scale != 1 ) {
3963 eprintf("Nesting not allowed when proxy scale != 1");
3967 awindow->gui->stop_vicon_drawing();
3968 int clips_total = session->drag_clips->total;
3969 for( int i=0; i<clips_total; ++i ) {
3970 EDL *clip = session->drag_clips->values[i];
3971 time_t dt; time(&dt);
3972 struct tm dtm; localtime_r(&dt, &dtm);
3973 char path[BCTEXTLEN], *cp = path, *ep = cp+sizeof(path)-1;
3974 // path_basename = "Nested_<date>-<time>_<basename>"
3975 cp += snprintf(cp, ep-cp, _("Nested_%02d%02d%02d-%02d%02d%02d_"),
3976 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
3977 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
3978 char *bp = strrchr(clip->local_session->clip_title, '/');
3979 bp = bp ? bp+1 : clip->local_session->clip_title;
3980 cp += snprintf(cp, ep-cp, "%s", bp);
3981 EDL *nested = edl->new_nested_edl(clip, path);
3982 edl->clips.remove(clip);
3983 clip->remove_user();
3984 mainindexes->add_indexable(nested);
3986 undo_after(_("clip2media"), LOAD_ALL);
3987 mainindexes->start_build();
3988 awindow->gui->async_update_assets();
3991 void MWindow::media_to_clip()
3994 int assets_total = session->drag_assets->total;
3995 for( int i=0; i<assets_total; ++i ) {
3996 Indexable *idxbl = session->drag_assets->values[i];
3997 if( idxbl->is_asset ) {
3998 eprintf(_("media is not EDL:\n%s"), idxbl->path);
4001 char clip_title[BCSTRLEN];
4005 sprintf(clip_title, _("Clip %d"), session->clip_number++);
4006 for( int i=0; name_ok && i<edl->clips.size(); ++i ) {
4007 char *title = edl->clips[i]->local_session->clip_title;
4008 if( !strcasecmp(clip_title, title) ) name_ok = 0;
4011 EDL *nested = (EDL *)idxbl;
4012 EDL *clip = edl->add_clip(nested);
4013 strcpy(clip->local_session->clip_title, clip_title);
4014 snprintf(clip->local_session->clip_notes,
4015 sizeof(clip->local_session->clip_notes),
4016 _("From: %s"), nested->path);
4018 undo_after(_("media2clip"), LOAD_ALL);
4019 awindow->gui->async_update_assets();
4022 int MWindow::create_ref(Asset *asset, EDL *ref)
4024 asset->format = FILE_REF;
4025 double secs = ref->tracks->total_length();
4026 int audio_channels = ref->session->audio_channels;
4027 asset->audio_data = audio_channels > 0 ? 1 : 0;
4028 asset->channels = audio_channels;
4029 asset->sample_rate = ref->session->sample_rate;
4030 asset->audio_length = audio_channels > 0 && secs > 0 ?
4031 secs * asset->sample_rate : 0;
4032 strcpy(asset->acodec, _("reference"));
4034 int video_layers = ref->session->video_channels;
4035 asset->video_data = video_layers > 0 ? 1 : 0;
4036 asset->layers = video_layers > 0 ? 1 : 0;
4037 asset->actual_width = ref->session->output_w;
4038 asset->actual_height = ref->session->output_h;
4039 asset->width = asset->actual_width;
4040 asset->height = asset->actual_height;
4041 asset->frame_rate = ref->session->frame_rate;
4042 asset->video_length = video_layers > 0 && secs > 0 ?
4043 secs * asset->frame_rate : 0;
4044 strcpy(asset->vcodec, _("reference"));
4048 void MWindow::update_preferences(Preferences *prefs)
4050 if( prefs != preferences )
4051 preferences->copy_from(prefs);
4052 if( cwindow->playback_engine )
4053 cwindow->playback_engine->preferences->copy_from(prefs);
4054 for(int i = 0; i < vwindows.size(); i++) {
4055 VWindow *vwindow = vwindows[i];
4056 if( !vwindow->is_running() ) continue;
4057 if( vwindow->playback_engine )
4058 vwindow->playback_engine->preferences->copy_from(prefs);
4060 for(int i = 0; i < zwindows.size(); i++) {
4061 ZWindow *zwindow = zwindows[i];
4062 if( !zwindow->is_running() ) continue;
4063 if( zwindow->zgui->playback_engine )
4064 zwindow->zgui->playback_engine->preferences->copy_from(prefs);
4068 void MWindow::update_vwindow()
4070 for( int i=0; i<vwindows.size(); ++i ) {
4071 VWindow *vwindow = vwindows[i];
4072 if( vwindow->is_running() ) {
4073 vwindow->gui->lock_window("MWindow::update_vwindow");
4075 vwindow->gui->unlock_window();
4080 void MWindow::remove_indexfile(Indexable *indexable)
4082 if( !indexable->is_asset ) return;
4083 Asset *asset = (Asset *)indexable;
4085 IndexFile::delete_index(preferences, asset, ".toc");
4086 IndexFile::delete_index(preferences, asset, ".idx");
4087 IndexFile::delete_index(preferences, asset, ".mkr");
4090 void MWindow::rebuild_indices()
4092 for(int i = 0; i < session->drag_assets->total; i++)
4094 Indexable *indexable = session->drag_assets->get(i);
4095 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4096 remove_indexfile(indexable);
4097 // Schedule index build
4098 indexable->index_state->remove_user();
4099 indexable->index_state = new IndexState;
4100 IndexFile::delete_index_files(preferences, indexable);
4101 if( indexable->is_asset ) {
4102 Asset *asset = (Asset *)indexable;
4103 if( asset->format != FILE_PCM ) {
4104 asset->format = FILE_UNKNOWN;
4105 asset->reset_audio();
4107 asset->reset_video();
4108 remove_from_caches(asset);
4109 // File file; // re-probe the asset
4110 // file.open_file(preferences, asset, 1, 0);
4112 mainindexes->add_indexable(indexable);
4114 // still in render engine
4115 sync_parameters(CHANGE_ALL);
4116 awindow->gui->async_update_assets();
4117 mainindexes->start_build();
4121 void MWindow::get_backup_path(char *path, int len)
4123 char *cp = path, *ep = cp + len-1;
4124 cp += snprintf(cp, ep-cp, "%s/", File::get_config_path());
4125 int idx = stack.size();
4126 cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx);
4129 void MWindow::save_backup()
4133 edl->set_path(session->filename);
4135 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
4136 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
4137 File::get_config_path(), BACKUP_FILE1);
4138 get_backup_path(backup_path, sizeof(backup_path));
4139 rename(backup_path, backup_path1);
4140 edl->save_xml(&file, backup_path);
4141 file.terminate_string();
4143 fs.complete_path(backup_path);
4145 if(file.write_to_file(backup_path)) {
4147 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
4148 gui->show_message(string2);
4153 void MWindow::load_backup()
4155 ArrayList<char*> path_list;
4156 path_list.set_array_delete();
4158 char backup_path[BCTEXTLEN];
4159 get_backup_path(backup_path, sizeof(backup_path));
4161 fs.complete_path(backup_path);
4163 path_list.append(out_path = new char[strlen(backup_path) + 1]);
4164 strcpy(out_path, backup_path);
4166 load_filenames(&path_list, LOADMODE_REPLACE, LOADMODE_EDL_CLIP, 0);
4167 edl->local_session->clip_title[0] = 0;
4168 // This is unique to backups since the path of the backup is different than the
4169 // path of the project.
4170 set_filename(edl->path);
4171 path_list.remove_all_objects();
4176 void MWindow::save_undo_data()
4178 if( stack.size() > 0 ) return;
4179 if( !preferences->perpetual_session ) return;
4180 char perpetual_path[BCTEXTLEN];
4181 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4182 File::get_config_path(), PERPETUAL_FILE);
4183 FILE *fp = fopen(perpetual_path,"w");
4189 void MWindow::load_undo_data()
4191 if( stack.size() > 0 ) return;
4192 if( !preferences->perpetual_session ) return;
4193 char perpetual_path[BCTEXTLEN];
4194 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4195 File::get_config_path(), PERPETUAL_FILE);
4196 FILE *fp = fopen(perpetual_path,"r");
4200 undo_after(_("perpetual load"), LOAD_ALL);
4204 void MWindow::remove_undo_data()
4206 if( stack.size() > 0 ) return;
4207 char perpetual_path[BCTEXTLEN];
4208 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4209 File::get_config_path(), PERPETUAL_FILE);
4210 ::remove(perpetual_path);
4213 int MWindow::copy_target(const char *path, const char *target)
4215 int ifd = ::open(path, O_RDONLY);
4217 eprintf("Cannot open asset: %s", path);
4221 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
4224 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
4225 char progress_title[BCTEXTLEN];
4226 sprintf(progress_title, _("Copying: %s\n"), target);
4227 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
4229 int64_t count = 0, len = -1;
4230 int bfrsz = 0x100000;
4231 uint8_t *bfr = new uint8_t[bfrsz];
4232 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
4233 if( len != ::write(ofd, bfr, len) ) {
4234 eprintf("Error writing: %s", target);
4237 if( progress.is_cancelled() ) {
4241 progress.update(count += len, 1);
4246 progress.stop_progress();
4248 eprintf("Error reading: %s", path);
4253 eprintf("Cannot create asset target: %s", target);
4258 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
4260 char target[BCTEXTLEN];
4262 const char *bp = real_path, *cp = bp;
4263 const char *lp = link_path, *np = lp;
4264 char *tp = target, *ep = tp+sizeof(target)-1, lch;
4265 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
4266 if( lch == '/' ) { np = lp; cp = bp; }
4268 while( tp<ep && *np ) {
4269 if( *np++ != '/' ) continue;
4270 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
4272 while( tp<ep && *cp ) *tp++ = *cp++;
4276 strcpy(target, real_path);
4277 if( symlink(target, link_path) ) {
4278 eprintf("Cannot create symlink: %s", link_path);
4284 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
4286 char dir_path[BCTEXTLEN];
4287 strcpy(dir_path, dir);
4289 fs.complete_path(dir_path);
4292 if( !stat(dir_path, &st) ) {
4293 if( !S_ISDIR(st.st_mode) ) {
4294 eprintf("Path exists and is not a directory\n%s", dir_path);
4299 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
4300 eprintf("Cannot create directory\n%s", dir_path);
4304 char *real_dir = realpath(dir_path, 0);
4305 strcpy(dir_path, real_dir);
4308 EDL *save_edl = new EDL;
4309 save_edl->create_objects();
4310 save_edl->copy_all(edl);
4312 char progress_title[BCTEXTLEN];
4313 sprintf(progress_title, _("Saving to %s:\n"), dir);
4314 int total_assets = save_edl->assets->total();
4315 gui->lock_window("MWindow::save_project");
4316 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
4317 gui->unlock_window();
4320 Asset *current = save_edl->assets->first;
4321 for( int i=0; !ret && current; ++i, current=NEXT ) {
4322 char *path = current->path;
4323 if( ::stat(path, &st) ) {
4324 eprintf("Asset not found: %s", path);
4327 char *real_path = realpath(path, 0);
4328 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
4329 char link_path[BCTEXTLEN];
4330 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
4332 if( strcmp(real_path, link_path) ) {
4333 if( !::lstat(link_path, &st) ) {
4335 ::remove(link_path);
4341 eprintf("copy/link to self, skippped: %s", path);
4345 if( save_mode == SAVE_PROJECT_COPY ) {
4346 if( copy_target(real_path, link_path) )
4350 link_target(real_path, link_path,
4351 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
4355 strcpy(path, link_path);
4357 if( progress->is_cancelled() ) break;
4358 progress->update(i);
4361 progress->stop_progress();
4364 char *cp = strrchr(dir_path,'/');
4365 char *bp = cp ? cp+1 : dir_path;
4366 char filename[BCTEXTLEN];
4367 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
4368 save_edl->set_path(filename);
4370 save_edl->save_xml(&file, filename);
4371 file.terminate_string();
4373 if( !file.write_to_file(filename) ) {
4374 char string[BCTEXTLEN];
4375 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
4376 gui->lock_window("SaveProject::run 2");
4377 gui->show_message(string);
4378 gui->unlock_window();
4379 gui->mainmenu->add_load(filename);
4382 eprintf(_("Couldn't open %s."), filename);
4384 save_edl->remove_user();
4387 gui->lock_window("MWindow::save_project");
4388 ArrayList<char*> filenames;
4389 filenames.append(filename);
4390 load_filenames(&filenames);
4391 gui->unlock_window();
4396 static inline int gcd(int m, int n)
4399 if( m < n ) { r = m; m = n; n = r; }
4400 while( (r = m % n) != 0 ) { m = n; n = r; }
4404 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4407 if(!width || !height) return 1;
4408 if( width == 720 && (height == 480 || height == 576) ) {
4409 w = 4; h = 3; return 0; // for NTSC and PAL
4411 double ar = (double)width / height;
4412 // square-ish pixels
4413 if( EQUIV(ar, 1.0000) ) return 0;
4414 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4415 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4416 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4417 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4418 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4419 int ww = width, hh = height;
4420 // numerator, denominator must be under mx
4421 int mx = 255, n = gcd(ww, hh);
4422 if( n > 1 ) { ww /= n; hh /= n; }
4423 // search near height in case extra/missing lines
4424 if( ww >= mx || hh >= mx ) {
4425 double err = height; // +/- 2 percent height
4426 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4427 int iw = width, ih = height+i;
4428 if( (n=gcd(iw, ih)) > 1 ) {
4429 int u = iw/n; if( u >= mx ) continue;
4430 int v = ih/n; if( v >= mx ) continue;
4431 double r = (double) u/v, er = fabs(ar-r);
4432 if( er >= err ) continue;
4433 err = er; ww = u; hh = v;
4442 void MWindow::reset_caches()
4444 frame_cache->remove_all();
4445 wave_cache->remove_all();
4446 audio_cache->remove_all();
4447 video_cache->remove_all();
4448 if( cwindow->playback_engine ) {
4449 if( cwindow->playback_engine->audio_cache )
4450 cwindow->playback_engine->audio_cache->remove_all();
4451 if( cwindow->playback_engine->video_cache )
4452 cwindow->playback_engine->video_cache->remove_all();
4454 for(int i = 0; i < vwindows.size(); i++) {
4455 VWindow *vwindow = vwindows[i];
4456 if( !vwindow->is_running() ) continue;
4457 if( !vwindow->playback_engine ) continue;
4458 if( vwindow->playback_engine->audio_cache )
4459 vwindow->playback_engine->audio_cache->remove_all();
4460 if( vwindow->playback_engine->video_cache )
4461 vwindow->playback_engine->video_cache->remove_all();
4465 void MWindow::remove_from_caches(Indexable *idxbl)
4467 frame_cache->remove_item(idxbl);
4468 wave_cache->remove_item(idxbl);
4469 if( gui->render_engine &&
4470 gui->render_engine_id == idxbl->id ) {
4471 delete gui->render_engine;
4472 gui->render_engine = 0;
4474 gui->resource_thread->close_indexable(idxbl);
4475 if( !idxbl->is_asset ) return;
4476 Asset *asset = (Asset *)idxbl;
4477 audio_cache->delete_entry(asset);
4478 video_cache->delete_entry(asset);
4479 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4480 cwindow->playback_engine->audio_cache->delete_entry(asset);
4481 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4482 cwindow->playback_engine->video_cache->delete_entry(asset);
4483 for(int i = 0; i < vwindows.size(); i++) {
4484 VWindow *vwindow = vwindows[i];
4485 if( !vwindow->is_running() ) continue;
4486 if( !vwindow->playback_engine ) continue;
4487 if( vwindow->playback_engine->audio_cache )
4488 vwindow->playback_engine->audio_cache->delete_entry(asset);
4489 if( vwindow->playback_engine->video_cache )
4490 vwindow->playback_engine->video_cache->delete_entry(asset);
4492 for(int i = 0; i < zwindows.size(); i++) {
4493 ZWindow *zwindow = zwindows[i];
4494 if( !zwindow->is_running() ) continue;
4495 if( zwindow->zgui->playback_engine->audio_cache )
4496 zwindow->zgui->playback_engine->audio_cache->delete_entry(asset);
4497 if( zwindow->zgui->playback_engine->video_cache )
4498 zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
4502 void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
4503 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4505 awindow->gui->close_view_popup();
4507 // Remove from VWindow.
4509 for(int i = 0; i < drag_clips->total; i++) {
4510 for(int j = 0; j < vwindows.size(); j++) {
4511 VWindow *vwindow = vwindows[j];
4512 if( !vwindow->is_running() ) continue;
4513 if(drag_clips->get(i) == vwindow->get_edl()) {
4514 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4515 vwindow->delete_source(1, 1);
4516 vwindow->gui->unlock_window();
4523 for(int i = 0; i < drag_assets->size(); i++) {
4524 for(int j = 0; j < vwindows.size(); j++) {
4525 VWindow *vwindow = vwindows[j];
4526 if( !vwindow->is_running() ) continue;
4527 if(drag_assets->get(i) == vwindow->get_source()) {
4528 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4529 vwindow->delete_source(1, 1);
4530 vwindow->gui->unlock_window();
4535 for(int i = 0; i < drag_assets->total; i++) {
4536 Indexable *indexable = drag_assets->get(i);
4537 if(indexable->is_asset) remove_from_caches(indexable);
4540 if( delete_indexes ) {
4541 for(int i = 0; i < drag_assets->size(); i++) {
4542 Indexable *indexable = drag_assets->get(i);
4543 remove_indexfile(indexable);
4548 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4549 if(push_undo) undo_before();
4550 if(drag_assets) edl->remove_from_project(drag_assets);
4551 if(drag_clips) edl->remove_from_project(drag_clips);
4552 if(redraw) save_backup();
4553 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4557 gui->lock_window("MWindow::remove_assets_from_project 3");
4558 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4559 gui->unlock_window();
4561 // Removes from playback here
4562 sync_parameters(CHANGE_ALL);
4565 awindow->gui->async_update_assets();
4568 void MWindow::remove_assets_from_disk()
4570 remove_assets_from_project(1, 1, 1,
4571 session->drag_assets, session->drag_clips);
4574 for(int i = 0; i < session->drag_assets->total; i++)
4576 remove(session->drag_assets->get(i)->path);
4580 void MWindow::dump_plugins(FILE *fp)
4582 if( !plugindb ) return;
4583 for(int i = 0; i < plugindb->total; i++)
4585 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4586 " synth=%d transition=%d theme=%d %s\n",
4587 plugindb->get(i)->plugin_type,
4588 plugindb->get(i)->audio,
4589 plugindb->get(i)->video,
4590 plugindb->get(i)->realtime,
4591 plugindb->get(i)->multichannel,
4592 plugindb->get(i)->get_synthesis(),
4593 plugindb->get(i)->transition,
4594 plugindb->get(i)->theme,
4595 plugindb->get(i)->title);
4599 void MWindow::dump_edl(FILE *fp)
4605 void MWindow::dump_undo(FILE *fp)
4611 void MWindow::dump_exe(FILE *fp)
4613 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4614 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4616 int ret = -1, n = 100;
4617 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4618 exe_path[len] = 0; strcpy(proc_path, exe_path);
4621 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4624 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4625 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4626 struct tm *tm = localtime(&st.st_mtime);
4628 strftime(mtime, sizeof(mtime), "%F %T", tm);
4629 fprintf(fp,"mtime: %s\n", mtime);
4631 // people hit ctl-c waiting for this
4632 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4633 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4636 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4637 int64_t maxsz = 1024*pagsz;
4638 int64_t size = st.st_size, pos = 0;
4640 while( (bfrsz = size-pos) > 0 ) {
4641 if( bfrsz > maxsz ) bfrsz = maxsz;
4642 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4643 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4644 if( bfr == MAP_FAILED ) break;
4645 sha1.addBytes(bfr, bfrsz);
4650 ret = pos < size ? EIO : 0;
4651 fprintf(fp, "SHA1: ");
4652 uint8_t digest[20]; sha1.computeHash(digest);
4653 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4654 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4655 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4660 void MWindow::dump_caches(FILE *fp)
4662 fprintf(fp, "audio cache: ");
4663 audio_cache->dump(fp);
4664 fprintf(fp, "video cache: ");
4665 video_cache->dump(fp);
4668 void MWindow::trap_hook(FILE *fp, void *vp)
4670 MWindow *mwindow = (MWindow *)vp;
4671 // fprintf(fp, "\nPLUGINS:\n");
4672 // mwindow->dump_plugins(fp);
4673 fprintf(fp, "\nEDL:\n");
4674 mwindow->dump_edl(fp);
4675 fprintf(fp, "\nUNDO:\n");
4676 mwindow->dump_undo(fp);
4677 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4678 mwindow->dump_exe(fp);
4679 fprintf(fp, "\nCACHES:\n");
4680 mwindow->dump_caches(fp);
4688 int MWindow::save_defaults()
4690 gui->save_defaults(defaults);
4691 edl->save_defaults(defaults);
4692 session->save_defaults(defaults);
4693 preferences->save_defaults(defaults);
4695 for(int i = 0; i < plugin_guis->total; i++)
4697 // Pointer comparison
4698 plugin_guis->get(i)->save_defaults();
4700 awindow->save_defaults(defaults);
4706 int MWindow::run_script(FileXML *script)
4708 int result = 0, result2 = 0;
4709 while(!result && !result2)
4711 result = script->read_tag();
4714 if(script->tag.title_is("new_project"))
4716 // Run new in immediate mode.
4717 // gui->mainmenu->new_project->run_script(script);
4720 if(script->tag.title_is("record"))
4722 // Run record as a thread. It is a terminal command.
4724 // Will read the complete scipt file without letting record read it if not
4730 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4737 // ================================= synchronization
4740 int MWindow::interrupt_indexes()
4742 mainprogress->cancelled = 1;
4743 mainindexes->interrupt_build();
4749 void MWindow::next_time_format()
4751 switch(edl->session->time_format)
4753 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4754 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4755 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4756 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4757 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4758 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4759 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4762 time_format_common();
4765 void MWindow::prev_time_format()
4767 switch(edl->session->time_format)
4769 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4770 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4771 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4772 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4773 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4774 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4775 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4778 time_format_common();
4781 void MWindow::time_format_common()
4783 gui->lock_window("MWindow::next_time_format");
4784 gui->redraw_time_dependancies();
4787 char string[BCTEXTLEN], string2[BCTEXTLEN];
4788 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4789 gui->show_message(string);
4791 gui->unlock_window();
4795 int MWindow::set_filename(const char *filename)
4797 if( filename != session->filename )
4798 strcpy(session->filename, filename);
4799 if( filename != edl->path )
4800 strcpy(edl->path, filename);
4801 return set_titlebar(filename);
4804 int MWindow::set_titlebar(const char *filename)
4806 if( !gui ) return 0;
4809 char string[BCTEXTLEN], string2[BCTEXTLEN];
4810 dir.extract_name(string, filename);
4811 sprintf(string2, PROGRAM_NAME ": %s", string);
4812 gui->set_title(string2);
4815 gui->set_title(PROGRAM_NAME);
4820 int MWindow::set_loop_boundaries()
4822 double start = edl->local_session->get_selectionstart();
4823 double end = edl->local_session->get_selectionend();
4831 if(edl->tracks->total_length())
4834 end = edl->tracks->total_length();
4841 if(edl->local_session->loop_playback && start != end)
4843 edl->local_session->loop_start = start;
4844 edl->local_session->loop_end = end;
4855 int MWindow::reset_meters()
4857 cwindow->gui->lock_window("MWindow::reset_meters 1");
4858 cwindow->gui->meters->reset_meters();
4859 cwindow->gui->unlock_window();
4861 for(int j = 0; j < vwindows.size(); j++) {
4862 VWindow *vwindow = vwindows[j];
4863 if( !vwindow->is_running() ) continue;
4864 vwindow->gui->lock_window("MWindow::reset_meters 2");
4865 vwindow->gui->meters->reset_meters();
4866 vwindow->gui->unlock_window();
4869 lwindow->gui->lock_window("MWindow::reset_meters 3");
4870 lwindow->gui->panel->reset_meters();
4871 lwindow->gui->unlock_window();
4873 gui->lock_window("MWindow::reset_meters 4");
4874 gui->reset_meters();
4875 gui->unlock_window();
4880 void MWindow::resync_guis()
4884 gui->lock_window("MWindow::resync_guis");
4885 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4886 gui->unlock_window();
4888 cwindow->gui->lock_window("MWindow::resync_guis");
4889 cwindow->gui->resize_event(cwindow->gui->get_w(),
4890 cwindow->gui->get_h());
4891 int channels = edl->session->audio_channels;
4892 cwindow->gui->meters->set_meters(channels, 1);
4893 cwindow->gui->flush();
4894 cwindow->gui->unlock_window();
4896 for(int i = 0; i < vwindows.size(); i++) {
4897 VWindow *vwindow = vwindows[i];
4898 if( !vwindow->is_running() ) continue;
4899 vwindow->gui->lock_window("MWindow::resync_guis");
4900 vwindow->gui->resize_event(vwindow->gui->get_w(),
4901 vwindow->gui->get_h());
4902 vwindow->gui->meters->set_meters(channels, 1);
4903 vwindow->gui->flush();
4904 vwindow->gui->unlock_window();
4907 lwindow->gui->lock_window("MWindow::resync_guis");
4908 lwindow->gui->panel->set_meters(channels, 1);
4909 lwindow->gui->flush();
4910 lwindow->gui->unlock_window();
4913 if(((edl->session->output_w % 4) ||
4914 (edl->session->output_h % 4)) &&
4915 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4917 MainError::show_error(
4918 _("This project's dimensions are not multiples of 4 so\n"
4919 "it can't be rendered by OpenGL."));
4924 sync_parameters(CHANGE_ALL);
4927 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4929 File *file = new File;
4930 EDLSession *session = edl->session;
4931 double old_framerate = session->frame_rate;
4932 double old_samplerate = session->sample_rate;
4933 int old_auto_keyframes = session->auto_keyframes;
4934 session->auto_keyframes = 0;
4935 int result = file->open_file(preferences, asset, 1, 0);
4936 if( !result && delete_tracks > 0 )
4938 int video_layers = asset->get_video_layers();
4939 if( !result && asset->video_data && vstream < video_layers ) {
4940 // try to get asset up to date, may fail
4941 file->select_video_stream(asset, vstream);
4942 // either way use what was/is there.
4943 double framerate = asset->get_frame_rate();
4944 int width = asset->get_w();
4945 int height = asset->get_h();
4947 // must be multiple of 4 for opengl
4948 width = (width+3) & ~3; height = (height+3) & ~3;
4950 int driver = session->playback_config->vconfig->driver;
4951 int color_model = file->get_best_colormodel(asset, driver);
4952 // color_model = BC_CModels::is_yuv(color_model) ?
4953 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4954 // BC_CModels::is_float(color_model) ?
4955 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4956 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4957 // have alpha for now
4958 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4959 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4960 session->color_model = color_model;
4961 session->output_w = width;
4962 session->output_h = height;
4963 session->frame_rate = framerate;
4964 // not, asset->actual_width/actual_height
4965 asset->width = session->output_w;
4966 asset->height = session->output_h;
4967 asset->frame_rate = session->frame_rate;
4968 create_aspect_ratio(session->aspect_w, session->aspect_h,
4969 session->output_w, session->output_h);
4970 Track *track = edl->tracks->first;
4971 for( Track *next_track=0; track; track=next_track ) {
4972 next_track = track->next;
4973 if( track->data_type != TRACK_VIDEO ) continue;
4974 if( delete_tracks ) {
4975 Edit *edit = track->edits->first;
4976 for( Edit *next_edit=0; edit; edit=next_edit ) {
4977 next_edit = edit->next;
4978 if( edit->channel != vstream ||
4979 !edit->asset || !edit->asset->is_asset ||
4980 !asset->equivalent(*edit->asset,1,1,edl) )
4984 if( track->edits->first ) {
4985 track->track_w = edl->session->output_w;
4986 track->track_h = edl->session->output_h;
4988 else if( delete_tracks )
4989 edl->tracks->delete_track(track);
4992 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4994 if( !result && asset->audio_data && asset->channels > 0 ) {
4995 session->sample_rate = asset->get_sample_rate();
4996 int64_t channel_mask = 0;
4997 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4998 file->get_audio_for_video(vstream, astream, channel_mask);
4999 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
5000 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
5002 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
5003 if( channels < 1 ) channels = 1;
5004 if( channels > 6 ) channels = 6;
5005 session->audio_tracks = session->audio_channels = channels;
5007 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
5008 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
5009 remap_audio(MWindow::AUDIO_1_TO_1);
5011 if( delete_tracks ) {
5012 Track *track = edl->tracks->first;
5013 for( Track *next_track=0; track; track=next_track ) {
5014 next_track = track->next;
5015 if( track->data_type != TRACK_AUDIO ) continue;
5016 Edit *edit = track->edits->first;
5017 for( Edit *next_edit=0; edit; edit=next_edit ) {
5018 next_edit = edit->next;
5019 if( !((1<<edit->channel) & channel_mask) ||
5020 !edit->asset || !edit->asset->is_asset ||
5021 !asset->equivalent(*edit->asset,1,1,edl) )
5024 if( !track->edits->first )
5025 edl->tracks->delete_track(track);
5029 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
5032 session->auto_keyframes = old_auto_keyframes;
5033 if( !result && delete_tracks > 0 ) {
5035 undo_after(_("select asset"), LOAD_ALL);
5041 int MWindow::select_asset(int vtrack, int delete_tracks)
5043 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
5045 track = edl->tracks->get(vtrack, TRACK_AUDIO);
5046 if( !track ) return 1;
5047 Edit *edit = track->edits->first;
5048 if( !edit ) return 1;
5049 Asset *asset = edit->asset;
5050 if( !asset || !asset->is_asset ) return 1;
5051 return select_asset(asset, edit->channel, 0, delete_tracks);
5054 void MWindow::dump_plugindb(FILE *fp)
5056 if( !plugindb ) return;
5057 for(int i = 0; i < plugindb->total; i++)
5058 plugindb->get(i)->dump(fp);
5061 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
5064 double unit_position = edl->local_session->get_selectionstart(1);
5065 unit_position = patch->track->to_units(unit_position, 0);
5067 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
5068 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5071 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
5074 double unit_position = edl->local_session->get_selectionstart(1);
5075 unit_position = patch->track->to_units(unit_position, 0);
5077 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
5078 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5081 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
5084 double unit_position = edl->local_session->get_selectionstart(1);
5085 unit_position = patch->track->to_units(unit_position, 0);
5087 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
5088 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5091 PatchGUI *MWindow::get_patchgui(Track *track)
5093 PatchGUI *patchgui = 0;
5094 TimelinePane **panes = gui->pane;
5095 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
5096 if( !panes[i] ) continue;
5097 PatchBay *patchbay = panes[i]->patchbay;
5098 if( !patchbay ) continue;
5099 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
5100 if( patchbay->patches.values[j]->track == track )
5101 patchgui = patchbay->patches.values[j];
5107 int MWindow::get_cpus(int out_w, int out_h)
5109 if( !out_w ) out_w = edl->session->output_w;
5110 if( !out_h ) out_h = edl->session->output_h;
5111 int cpus = out_w*out_h/0x80000 + 1;
5112 if( cpus > preferences->processors )
5113 cpus = preferences->processors;
5116 int MWindow::get_cpus()
5118 return get_cpus(edl->session->output_w, edl->session->output_h);