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"
137 #include "zwindowgui.h"
138 #include "exportedl.h"
140 #include "defaultformats.h"
141 #include "ntsczones.h"
148 #include <sys/types.h>
149 #include <sys/stat.h>
150 #include <sys/time.h>
151 #include <sys/mman.h>
152 #include <sys/file.h>
163 // Hack for libdv to remove glib dependancy
166 // g_log (const char *log_domain,
168 // const char *format,
174 // g_logv (const char *log_domain,
176 // const char *format,
184 extern long cin_timezone;
186 ArrayList<PluginServer*>* MWindow::plugindb = 0;
187 Commercials* MWindow::commercials = 0;
193 run_lock = new Mutex("MWindow::run_lock");
194 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
195 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
196 vwindows_lock = new Mutex("MWindow::vwindows_lock");
197 zwindows_lock = new Mutex("MWindow::zwindows_lock");
198 brender_lock = new Mutex("MWindow::brender_lock");
199 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
204 undo_command = COMMAND_NONE;
208 commercial_active = 0;
220 strcpy(cin_lang,"en");
221 channeldb_buz = new ChannelDB;
222 channeldb_v4l2jpeg = new ChannelDB;
225 keyframe_threads = 0;
251 // Need to delete brender temporary here.
254 run_lock->lock("MWindow::~MWindow");
256 //printf("MWindow::~MWindow %d\n", __LINE__);
257 if( wwindow && wwindow->is_running() )
258 wwindow->close_window();
259 if( twindow && twindow->is_running() )
260 twindow->close_window();
261 gui->remote_control->deactivate();
264 gui->channel_info->stop();
267 delete create_bd; create_bd = 0;
268 delete create_dvd; create_dvd = 0;
269 delete shuttle; shuttle = 0;
271 delete wintv; wintv = 0;
273 delete batch_render; batch_render = 0;
274 delete convert_render; convert_render = 0;
275 delete render; render = 0;
276 delete mixers_align; mixers_align = 0;
278 if( commercials && !commercials->remove_user() ) commercials = 0;
280 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
281 // Save defaults for open plugins
282 plugin_gui_lock->lock("MWindow::~MWindow");
283 for(int i = 0; i < plugin_guis->size(); i++) {
284 plugin_guis->get(i)->hide_gui();
285 delete_plugin(plugin_guis->get(i));
287 plugin_gui_lock->unlock();
288 hide_keyframe_guis();
291 // Give up and go to a movie
292 // cant run valgrind if this is used
294 gui->del_keyboard_listener(
295 (int (BC_WindowBase::*)(BC_WindowBase *))
296 &MWindowGUI::keyboard_listener);
298 // release the hounds
299 if( awindow && awindow->gui ) awindow->gui->close(0);
300 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
301 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
302 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
303 vwindows.remove_all_objects();
304 zwindows.remove_all_objects();
306 if( awindow ) awindow->join();
307 if( cwindow ) cwindow->join();
308 if( lwindow ) lwindow->join();
309 if( gwindow ) gwindow->join();
312 // one at a time, or nouveau chokes
313 #define close_gui(win) if( win ) { \
314 if( win->gui ) win->gui->close(0); \
320 vwindows.remove_all_objects();
321 zwindows.remove_all_objects();
326 dead_plugins->remove_all_objects();
327 // must delete theme before destroying plugindb
328 // theme destructor will be deleted by delete_plugins
329 delete theme; theme = 0;
332 keyframe_threads->remove_all_objects();
333 colormodels.remove_all_objects();
334 delete awindow; awindow = 0;
335 delete lwindow; lwindow = 0;
336 delete twindow; twindow = 0;
337 delete wwindow; wwindow = 0;
338 delete gwindow; gwindow = 0;
339 delete cwindow; cwindow = 0;
341 delete mainindexes; mainindexes = 0;
342 delete mainprogress; mainprogress = 0;
343 delete audio_cache; audio_cache = 0; // delete the cache after the assets
344 delete video_cache; video_cache = 0; // delete the cache after the assets
345 delete frame_cache; frame_cache = 0;
346 delete wave_cache; wave_cache = 0;
347 delete plugin_guis; plugin_guis = 0;
348 delete dead_plugins; dead_plugins = 0;
349 delete keyframe_threads; keyframe_threads = 0;
350 delete undo; undo = 0;
351 delete preferences; preferences = 0;
352 delete exportedl; exportedl = 0;
353 delete session; session = 0;
354 delete defaults; defaults = 0;
355 delete assets; assets = 0;
356 delete splash_window; splash_window = 0;
357 if( !edl->Garbage::remove_user() ) edl = 0;
358 delete channeldb_buz;
359 delete channeldb_v4l2jpeg;
360 // This must be last thread to exit
361 delete playback_3d; playback_3d = 0;
362 delete dead_plugin_lock;
363 delete plugin_gui_lock;
364 delete vwindows_lock;
365 delete zwindows_lock;
367 delete keyframe_gui_lock;
368 colormodels.remove_all_objects();
369 interlace_project_modes.remove_all_objects();
370 interlace_asset_modes.remove_all_objects();
371 sighandler->terminate();
382 void MWindow::init_error()
384 MainError::init_error(this);
387 void MWindow::finit_error()
389 MainError::finit_error();
392 void MWindow::create_defaults_path(char *string, const char *config_file)
394 // set the .bcast path
397 sprintf(string, "%s/", File::get_config_path());
398 fs.complete_path(string);
399 if(!fs.is_dir(string))
400 fs.create_dir(string);
403 strcat(string, config_file);
405 const char *MWindow::default_std()
407 char buf[BCTEXTLEN], *p = 0;
409 int fd = open(TIMEZONE_NAME, O_RDONLY);
411 int l = read(fd, buf, sizeof(buf)-1);
414 if( buf[l-1] == '\n' ) --l;
420 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
423 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
424 p += strlen(ZONEINFO_STR);
429 for( int i=0; ntsc_zones[i]; ++i ) {
430 if( !strcmp(ntsc_zones[i], p) )
437 for( int i=0; ntsc_zones[i]; ++i ) {
438 if( !strcmp(ntsc_zones[i], p) )
443 // cin_timezone: Seconds west of UTC. 240sec/deg
444 double tz_deg = -cin_timezone / 240.;
445 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
446 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
449 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
451 struct formatpresets *fpr;
453 for(fpr = &format_presets[0]; fpr->name; fpr++)
455 if(strcmp(_(fpr->name), preset) == 0)
457 session->audio_channels = fpr->audio_channels;
458 session->audio_tracks = fpr->audio_tracks;
459 session->sample_rate = fpr->sample_rate;
460 session->video_channels = fpr->video_channels;
461 session->video_tracks = fpr->video_tracks;
462 session->frame_rate = fpr->frame_rate;
463 session->output_w = fpr->output_w;
464 session->output_h = fpr->output_h;
465 session->aspect_w = fpr->aspect_w;
466 session->aspect_h = fpr->aspect_h;
467 session->interlace_mode = fpr->interlace_mode;
468 session->color_model = fpr->color_model;
474 const char *MWindow::get_preset_name(int index)
476 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
478 return _(format_presets[index].name);
482 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
484 char path[BCTEXTLEN];
485 // Use user supplied path
487 strcpy(path, config_path);
489 create_defaults_path(path, CONFIG_FILE);
492 defaults = new BC_Hash(path);
497 void MWindow::check_language()
499 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
500 const char *env_lang = getenv("LANGUAGE");
501 if( !env_lang ) env_lang = getenv("LC_ALL");
502 if( !env_lang ) env_lang = getenv("LANG");
504 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
505 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
506 env_lang = curr_lang;
508 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
509 defaults->get("LAST_LANG",last_lang);
510 if( strcmp(env_lang,last_lang)) {
511 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
512 defaults->update("LAST_LANG",env_lang);
513 char plugin_path[BCTEXTLEN];
514 create_defaults_path(plugin_path, PLUGIN_FILE);
515 ::remove(plugin_path);
516 char ladspa_path[BCTEXTLEN];
517 create_defaults_path(ladspa_path, LADSPA_FILE);
518 ::remove(ladspa_path);
521 if( strlen(env_lang) > 1 &&
522 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
523 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
526 strcpy(cin_lang, "en");
529 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
531 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
533 const char *dp = plug_dir;
534 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
535 bp = !*dp && *bp == '/' ? bp+1 : base_path;
541 int MWindow::load_plugin_index(MWindow *mwindow, FILE *fp, const char *plugin_dir)
545 fseek(fp, 0, SEEK_SET);
547 char index_line[BCTEXTLEN];
548 int index_version = -1, len = strlen(plugin_dir);
549 if( !fgets(index_line, BCTEXTLEN, fp) ||
550 sscanf(index_line, "%d", &index_version) != 1 ||
551 index_version != PLUGIN_FILE_VERSION ||
552 !fgets(index_line, BCTEXTLEN, fp) ||
553 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
554 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
556 ArrayList<PluginServer*> plugins;
557 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
558 if( index_line[0] == ';' ) continue;
559 if( index_line[0] == '#' ) continue;
560 int type = PLUGIN_TYPE_UNKNOWN;
561 char path[BCTEXTLEN], title[BCTEXTLEN];
563 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
566 PluginServer *server = 0;
568 case PLUGIN_TYPE_BUILTIN:
569 case PLUGIN_TYPE_EXECUTABLE:
570 case PLUGIN_TYPE_LADSPA: {
571 char plugin_path[BCTEXTLEN]; struct stat st;
572 sprintf(plugin_path, "%s/%s", plugin_dir, path);
573 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
576 server = new PluginServer(mwindow, plugin_path, type);
578 case PLUGIN_TYPE_FFMPEG: {
579 server = new_ffmpeg_server(mwindow, path);
581 case PLUGIN_TYPE_LV2: {
582 server = new_lv2_server(mwindow, path);
585 if( !server ) continue;
586 plugins.append(server);
587 // Create plugin server from index entry
588 server->set_title(title);
589 if( server->read_table(index_line) ) {
595 ret = check_plugin_index(plugins, plugin_dir, ".");
598 add_plugins(plugins);
600 plugins.remove_all_objects();
605 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
606 const char *plug_dir, const char *plug_path)
608 char plugin_path[BCTEXTLEN];
609 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
611 fs.set_filter( "[*.plugin][*.so]" );
612 if( fs.update(plugin_path) )
615 for( int i=0; i<fs.dir_list.total; ++i ) {
616 char fs_path[BCTEXTLEN];
617 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
618 if( fs.is_dir(fs_path) ) {
619 get_plugin_path(plugin_path, plug_dir, fs_path);
620 if( check_plugin_index(plugins, plug_dir, plugin_path) )
623 else if( !plugin_exists(fs_path, plugins) )
630 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
633 plugindb = new ArrayList<PluginServer*>;
635 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
636 create_defaults_path(index_path, PLUGIN_FILE);
637 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
638 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
639 FILE *fp = fopen(index_path,"a+");
641 fprintf(stderr,_("MWindow::init_plugins: "
642 "can't open plugin index: %s\n"), index_path);
645 int fd = fileno(fp), ret = -1;
646 if( !flock(fd, LOCK_EX) ) {
647 fseek(fp, 0, SEEK_SET);
648 ret = load_plugin_index(mwindow, fp, plugin_path);
652 fseek(fp, 0, SEEK_SET);
653 printf("init plugin index: %s\n", plugin_path);
654 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
655 fprintf(fp, "%s\n", plugin_path);
656 init_plugin_index(mwindow, preferences, fp, plugin_path);
657 init_ffmpeg_index(mwindow, preferences, fp);
658 init_lv2_index(mwindow, preferences, fp);
659 fseek(fp, 0, SEEK_SET);
660 ret = load_plugin_index(mwindow, fp, plugin_path);
663 fprintf(stderr,_("MWindow::init_plugins: "
664 "can't %s plugin index: %s\n"),
665 ret>0 ? _("create") : _("lock"), index_path);
671 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
673 char *path = getenv("LADSPA_PATH");
674 char ladspa_path[BCTEXTLEN];
676 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
679 for( int len=0; *path; path+=len ) {
680 char *cp = strchr(path,':');
681 len = !cp ? strlen(path) : cp-path;
682 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
683 memcpy(plugin_path, path, len); plugin_path[len] = 0;
685 char *plugin_dir = FileSystem::basepath(plugin_path);
686 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
687 create_defaults_path(index_path, LADSPA_FILE);
688 cp = index_path + strlen(index_path);
689 for( char *bp=plugin_path; *bp!=0; ++bp )
690 *cp++ = *bp=='/' ? '_' : *bp;
692 FILE *fp = fopen(index_path,"a+");
694 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
695 "can't open ladspa plugin index: %s\n"), index_path);
698 int fd = fileno(fp), ret = -1;
699 if( !flock(fd, LOCK_EX) ) {
700 fseek(fp, 0, SEEK_SET);
701 ret = load_plugin_index(mwindow, fp, plugin_path);
705 fseek(fp, 0, SEEK_SET);
706 init_ladspa_index(mwindow, preferences, fp, plugin_path);
707 fseek(fp, 0, SEEK_SET);
708 ret = load_plugin_index(mwindow, fp, plugin_path);
711 fprintf(stderr,_("MWindow::init_ladspa_plugins: "
712 "can't %s ladspa plugin index: %s\n"),
713 ret>0 ? _("create") : _("lock"), index_path);
720 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
721 FILE *fp, const char *plugin_dir)
723 int idx = PLUGIN_IDS;
725 for( int i=0; i<plugindb->size(); ++i ) {
726 PluginServer *server = plugindb->get(i);
727 if( server->dir_idx >= idx )
728 idx = server->dir_idx+1;
731 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
734 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
735 const char *plug_dir, const char *plug_path, int &idx)
737 char plugin_path[BCTEXTLEN];
738 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
740 fs.set_filter( "[*.plugin][*.so]" );
741 int result = fs.update(plugin_path);
742 if( result || !fs.dir_list.total ) return;
745 for( int i=0; i<fs.dir_list.total; ++i ) {
746 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
747 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
748 get_plugin_path(path, plug_dir, fs_path);
749 if( fs.is_dir(fs_path) ) {
750 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
753 if( plugin_exists(path) ) continue;
755 if( stat(fs_path, &st) ) continue;
756 int64_t mtime = st.st_mtime;
757 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
758 result = server.open_plugin(1, preferences, 0, 0);
760 server.write_table(fp, path, vis_id, mtime);
761 server.close_plugin();
763 else if( result == PLUGINSERVER_IS_LAD ) {
766 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
767 ladspa.set_lad_index(lad_index++);
768 result = ladspa.open_plugin(1, preferences, 0, 0);
770 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
771 ladspa.close_plugin();
777 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
779 for( int i=0; i<plugins.size(); ++i )
780 plugindb->append(plugins[i]);
781 plugins.remove_all();
784 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
786 const char *dat_path = File::get_cindat_path();
787 char msg_path[BCTEXTLEN];
789 if( BC_Resources::language[0] ) {
790 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
792 fp = fopen(msg_path, "r");
795 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
797 fp = fopen(msg_path, "r");
800 char text[BCTEXTLEN];
801 char *tp = text, *ep = tp + sizeof(text)-1;
802 char title[BCTEXTLEN];
807 char line[BCTEXTLEN], *cp = line;
808 if( fgets(line,sizeof(line)-1,fp) ) {
809 if( *cp == '#' ) continue;
810 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
813 if( tp > text && *--tp == '\n' ) *tp = 0;
815 int idx = plugins.size();
816 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
818 delete [] plugins[idx]->tip;
819 plugins[idx]->tip = cstrdup(text);
823 if( done > 0 ) break;
825 char *dp = strchr(cp, ':');
827 printf("plugin tips: error on line %d\n", no);
831 while( cp < dp ) *bp++ = *cp++;
836 while( *cp == ' ' || *cp == '\t' ) ++cp;
837 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
842 void MWindow::delete_plugins()
844 plugindb->remove_all_objects();
849 void MWindow::search_plugindb(int do_audio,
854 ArrayList<PluginServer*> &results)
857 for(int i = 0; i < MWindow::plugindb->total; i++)
859 PluginServer *current = MWindow::plugindb->get(i);
861 if(current->audio == do_audio &&
862 current->video == do_video &&
863 (current->realtime == is_realtime || is_realtime < 0) &&
864 current->transition == is_transition &&
865 current->theme == is_theme)
866 results.append(current);
869 // Alphabetize list by title
875 for(int i = 0; i < results.total - 1; i++)
877 PluginServer *value1 = results[i];
878 PluginServer *value2 = results[i + 1];
879 if(strcmp(_(value1->title), _(value2->title)) > 0)
883 results[i + 1] = value1;
889 PluginServer* MWindow::scan_plugindb(char *title,
894 // printf("MWindow::scan_plugindb data_type < 0\n");
898 for(int i = 0; i < plugindb->total; i++)
900 PluginServer *server = plugindb->get(i);
902 !strcasecmp(server->title, title) &&
904 (data_type == TRACK_AUDIO && server->audio) ||
905 (data_type == TRACK_VIDEO && server->video)))
906 return plugindb->get(i);
911 // repair session files with xlated plugin titles
912 void MWindow::fix_plugin_title(char *title)
914 for(int i = 0; i < plugindb->total; i++) {
915 PluginServer *server = plugindb->get(i);
916 if( !server->title ) continue;
917 const char *server_title = server->title;
918 if( !bstrcasecmp(title, _(server_title)) ) {
919 strcpy(title, server_title);
925 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
927 for( int i=0; i<plugins.size(); ++i )
928 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
932 int MWindow::plugin_exists(char *plugin_path)
934 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
937 void MWindow::remove_plugin_index()
939 char index_path[BCTEXTLEN];
940 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
941 ::remove(index_path);
944 void MWindow::init_preferences()
946 preferences = new Preferences;
947 preferences->load_defaults(defaults);
948 File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
949 session = new MainSession(this);
950 session->load_defaults(defaults);
951 // set x11_host, screens, window_config
952 screens = session->set_default_x11_host();
953 BC_Signals::set_trap_hook(trap_hook, this);
954 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
955 BC_Signals::set_catch_intr(preferences->trap_sigintr);
956 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
957 BC_Trace::enable_locks();
960 BC_Trace::disable_locks();
962 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
963 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
964 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
965 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
968 void MWindow::clean_indexes()
973 int oldest_item = -1;
975 char string[BCTEXTLEN];
976 char string2[BCTEXTLEN];
978 // Delete extra indexes
979 fs.set_filter("*.idx");
980 fs.complete_path(preferences->index_directory);
981 fs.update(preferences->index_directory);
982 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
984 // Eliminate directories
989 for(int i = 0; i < fs.dir_list.total && !result; i++)
991 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
992 if(fs.is_dir(string))
994 delete fs.dir_list[i];
995 fs.dir_list.remove_number(i);
1000 total_excess = fs.dir_list.total - preferences->index_count;
1002 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
1003 while(total_excess > 0)
1006 for(int i = 0; i < fs.dir_list.total; i++)
1008 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
1010 if(i == 0 || fs.get_date(string) <= oldest)
1012 oldest = fs.get_date(string);
1017 if(oldest_item >= 0)
1019 // Remove index file
1020 fs.join_names(string,
1021 preferences->index_directory,
1022 fs.dir_list[oldest_item]->name);
1023 //printf("MWindow::clean_indexes 1 %s\n", string);
1025 perror("delete_indexes");
1026 delete fs.dir_list[oldest_item];
1027 fs.dir_list.remove_number(oldest_item);
1029 // Remove table of contents if it exists
1030 strcpy(string2, string);
1031 char *ptr = strrchr(string2, '.');
1034 //printf("MWindow::clean_indexes 2 %s\n", string2);
1035 sprintf(ptr, ".toc");
1037 sprintf(ptr, ".mkr");
1046 void MWindow::init_awindow()
1048 awindow = new AWindow(this);
1049 awindow->create_objects();
1052 void MWindow::init_gwindow()
1054 gwindow = new GWindow(this);
1055 gwindow->create_objects();
1058 void MWindow::init_tipwindow()
1060 TipWindow::load_tips(cin_lang);
1062 twindow = new TipWindow(this);
1066 void MWindow::show_warning(int *do_warning, const char *text)
1068 if( do_warning && !*do_warning ) return;
1070 wwindow = new WWindow(this);
1071 wwindow->show_warning(do_warning, text);
1074 int MWindow::wait_warning()
1076 return wwindow->wait_result();
1079 void MWindow::init_theme()
1084 PluginServer *theme_plugin = 0;
1085 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1086 if( plugindb->get(i)->theme &&
1087 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1088 theme_plugin = plugindb->get(i);
1092 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1093 preferences->theme);
1095 const char *default_theme = DEFAULT_THEME;
1096 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1097 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1099 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1100 if( plugindb->get(i)->theme &&
1101 !strcasecmp(default_theme, plugindb->get(i)->title) )
1102 theme_plugin = plugindb->get(i);
1107 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1111 PluginServer *plugin = new PluginServer(*theme_plugin);
1112 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1113 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1114 theme_plugin->title);
1118 theme = plugin->new_theme();
1119 theme->mwindow = this;
1120 strcpy(theme->path, plugin->path);
1123 // Load default images & settings
1124 theme->Theme::initialize();
1125 // Load user images & settings
1126 theme->initialize();
1127 // Create menus with user colors
1128 theme->build_menus();
1131 theme->sort_image_sets();
1132 theme->check_used();
1133 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1136 void MWindow::init_3d()
1138 playback_3d = new Playback3D(this);
1139 playback_3d->create_objects();
1142 void MWindow::init_edl()
1145 edl->create_objects();
1146 fill_preset_defaults(default_standard, edl->session);
1147 edl->load_defaults(defaults);
1148 edl->session->brender_start = edl->session->brender_end = 0;
1149 edl->create_default_tracks();
1150 edl->tracks->update_y_pixels(theme);
1153 void MWindow::init_compositor()
1155 cwindow = new CWindow(this);
1156 cwindow->create_objects();
1159 void MWindow::init_levelwindow()
1161 lwindow = new LevelWindow(this);
1162 lwindow->create_objects();
1165 VWindow *MWindow::get_viewer(int start_it, int idx)
1167 vwindows_lock->lock("MWindow::get_viewer");
1168 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1169 if( !vwindow ) idx = vwindows.size();
1170 while( !vwindow && --idx >= 0 ) {
1171 VWindow *vwin = vwindows[idx];
1172 if( !vwin->is_running() || !vwin->get_edl() )
1176 vwindow = new VWindow(this);
1177 vwindow->load_defaults();
1178 vwindow->create_objects();
1179 vwindows.append(vwindow);
1181 vwindows_lock->unlock();
1182 if( start_it ) vwindow->start();
1186 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1188 zwindows_lock->lock("MWindow::get_mixer");
1189 if( !mixer ) mixer = edl->mixers.new_mixer();
1190 ZWindow *zwindow = 0;
1191 for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
1192 ZWindow *zwdw = zwindows[i];
1193 if( zwdw->running() ) continue;
1194 if( zwdw->idx >= 0 ) continue;
1195 zwindow = zwindows[i];
1198 zwindows.append(zwindow = new ZWindow(this));
1199 zwindow->idx = mixer->idx;
1200 zwindows_lock->unlock();
1204 void MWindow::del_mixer(ZWindow *zwindow)
1206 zwindows_lock->lock("MWindow::del_mixer 0");
1207 edl->mixers.del_mixer(zwindow->idx);
1208 if( session->selected_zwindow >= 0 ) {
1209 int i = zwindows.number_of(zwindow);
1210 if( i >= 0 && i < session->selected_zwindow )
1211 --session->selected_zwindow;
1212 else if( i == session->selected_zwindow )
1213 session->selected_zwindow = -1;
1215 zwindows_lock->unlock();
1216 gui->lock_window("MWindow::del_mixer 1");
1217 gui->update_mixers(0, -1);
1218 gui->unlock_window();
1221 void MWindow::start_mixer()
1224 ZWindow *zwindow = get_mixer(mixer);
1225 const char *title = 0;
1227 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1228 PatchGUI *patchgui = get_patchgui(track);
1229 if( !patchgui || !patchgui->mixer ) continue;
1230 mixer->mixer_ids.append(track->get_mixer_id());
1231 if( !title ) title = track->title;
1234 session->selected_zwindow = -1;
1235 gui->lock_window("MWindow::start_mixer");
1236 gui->update_mixers(0, 0);
1237 gui->unlock_window();
1239 zwindow->set_title(title);
1244 int MWindow::mixer_track_active(Track *track)
1246 int i = session->selected_zwindow;
1247 if( i < 0 || i >= zwindows.size() ) return 0;
1248 ZWindow *zwindow = zwindows[i];
1249 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1250 if( !mixer ) return 0;
1251 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1252 return n >= 0 ? 1 : 0;
1255 void MWindow::update_mixer_tracks()
1257 zwindows_lock->lock("MixPatch::handle_event");
1258 int i = session->selected_zwindow;
1259 if( i >= 0 && i < zwindows.size() ) {
1260 ZWindow *zwindow = zwindows[i];
1261 zwindow->update_mixer_ids();
1263 zwindows_lock->unlock();
1266 void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
1267 int use_inout, int toggle_audio, int loop_play, float speed)
1269 zwindows_lock->lock("MWindow::handle_mixers");
1270 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1271 ZWindow *zwindow = zwindows[vidx];
1272 if( zwindow->idx < 0 ) continue;
1273 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1274 if( !mixer || !mixer->mixer_ids.size() ) continue;
1276 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1277 if( track->data_type != TRACK_VIDEO ) continue;
1278 int mixer_id = track->get_mixer_id();
1279 k = mixer->mixer_ids.size();
1280 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1282 if( k < 0 ) continue;
1283 EDL *mixer_edl = new EDL(this->edl);
1284 mixer_edl->create_objects();
1285 mixer_edl->copy_all(edl);
1286 mixer_edl->remove_vwindow_edls();
1287 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1288 k = mixer->mixer_ids.size();
1289 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1292 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1295 track->record = track->play = 0;
1297 zwindow->change_source(mixer_edl);
1298 zwindow->handle_mixer(command, 0,
1299 use_inout, toggle_audio, loop_play, speed);
1301 zwindows_lock->unlock();
1304 void MWindow::refresh_mixers(int dir)
1306 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1307 handle_mixers(edl, command, 0, 0, 0, 0, 0);
1310 void MWindow::stop_mixers()
1312 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1313 ZWindow *zwindow = zwindows[vidx];
1314 if( zwindow->idx < 0 ) continue;
1315 zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
1319 void MWindow::close_mixers(int result)
1321 ArrayList<ZWindow*> closed;
1322 zwindows_lock->lock("MWindow::close_mixers");
1323 for( int i=zwindows.size(); --i>=0; ) {
1324 ZWindow *zwindow = zwindows[i];
1325 if( zwindow->idx < 0 ) continue;
1327 ZWindowGUI *zgui = zwindow->zgui;
1328 zgui->lock_window("MWindow::select_zwindow 0");
1329 zgui->set_done(result);
1330 zgui->unlock_window();
1331 closed.append(zwindow);
1333 zwindows_lock->unlock();
1334 for( int i=0; i<closed.size(); ++i ) {
1335 ZWindow *zwindow = closed[i];
1340 ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
1342 ArrayList<Indexable*> new_assets;
1343 new_assets.append(indexable);
1344 Track *track = edl->tracks->last;
1345 load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
1346 track = !track ? edl->tracks->first : track->next;
1348 ZWindow *zwindow = get_mixer(mixer);
1350 track->play = track->record = 0;
1351 if( track->data_type == TRACK_VIDEO ) {
1352 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1354 mixer->mixer_ids.append(track->get_mixer_id());
1355 track = track->next;
1357 if( indexable->is_asset ) {
1358 char *path = indexable->path;
1359 char *tp = strrchr(path, '/');
1360 if( !tp ) tp = path; else ++tp;
1361 zwindow->set_title(tp);
1364 char *title = ((EDL*)indexable)->local_session->clip_title;
1365 zwindow->set_title(title);
1370 void MWindow::create_mixers(double position)
1372 if( !session->drag_assets->size() &&
1373 !session->drag_clips->size() ) return;
1377 ArrayList<ZWindow *>new_mixers;
1379 for( int i=0; i<session->drag_assets->size(); ++i ) {
1380 Indexable *indexable = session->drag_assets->get(i);
1381 if( !indexable->have_video() ) continue;
1382 ZWindow *zwindow = create_mixer(indexable, position);
1383 new_mixers.append(zwindow);
1385 for( int i=0; i<session->drag_clips->size(); ++i ) {
1386 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1387 if( !indexable->have_video() ) continue;
1388 ZWindow *zwindow = create_mixer(indexable, position);
1389 new_mixers.append(zwindow);
1393 for( int i=0; i<new_mixers.size(); ++i )
1394 new_mixers[i]->start();
1398 undo_after(_("create mixers"), LOAD_ALL);
1400 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1401 sync_parameters(CHANGE_ALL);
1404 void MWindow::open_mixers()
1406 for( int i=0; i<edl->mixers.size(); ++i ) {
1407 Mixer *mixer = edl->mixers[i];
1408 ZWindow *zwindow = get_mixer(mixer);
1409 zwindow->set_title(mixer->title);
1415 int MWindow::select_zwindow(ZWindow *zwindow)
1417 int ret = 0, n = zwindows.number_of(zwindow);
1418 if( session->selected_zwindow != n ) {
1419 session->selected_zwindow = n;
1420 for( int i=0; i<zwindows.size(); ++i ) {
1421 ZWindow *zwindow = zwindows[i];
1422 if( zwindow->idx < 0 ) continue;
1423 ZWindowGUI *zgui = zwindow->zgui;
1424 zgui->lock_window("MWindow::select_zwindow 0");
1425 zwindow->highlighted = i == n ? 1 : 0;
1426 if( zgui->draw_overlays() )
1427 zgui->canvas->get_canvas()->flash(1);
1428 zgui->unlock_window();
1431 gui->lock_window("MWindow::select_window 1");
1432 gui->update_mixers(0, -1);
1433 gui->unlock_window();
1438 void MWindow::tile_mixers()
1441 for( int i=0; i<zwindows.size(); ++i ) {
1442 ZWindow *zwindow = zwindows[i];
1443 if( zwindow->idx < 0 ) continue;
1447 int zn = ceil(sqrt(nz));
1448 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1449 int y1 = 1, y2 = gui->get_y();
1450 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1451 if( x1 < 0 ) x1 = 0;
1452 if( y1 < 0 ) y1 = 0;
1453 if( x2 > rw ) x2 = rw;
1454 if( y2 > rh ) y2 = rh;
1455 int dx = x2 - x1, dy = y2 - y1;
1457 int lt = BC_DisplayInfo::get_left_border();
1458 int top = BC_DisplayInfo::get_top_border();
1459 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1460 int bh = top + BC_DisplayInfo::get_bottom_border();
1461 int zx = 0, zy = 0; // window origins
1462 int mw = xS(10+10), mh = yS(10+10); // canvas margins
1463 int rsz = 0, n = 0, dz = 0;
1464 int ow = edl->session->output_w, oh = edl->session->output_h;
1465 for( int i=0; i<zwindows.size(); ++i ) {
1466 ZWindow *zwindow = zwindows[i];
1467 if( zwindow->idx < 0 ) continue;
1468 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1469 if( rsz < hh ) rsz = hh;
1470 int xx = zx + x1, yy = zy + y1;
1471 int mx = x2 - zw, my = y2 - zh;
1472 if( xx > mx ) xx = mx;
1473 if( yy > my ) yy = my;
1474 xx += lt + xS(dz); yy += top + yS(dz);
1475 zwindow->reposition(xx,yy, ww,hh);
1476 if( zwindow->running() ) {
1477 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1478 gui->lock_window("MWindow::tile_mixers");
1479 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1480 gui->unlock_window();
1484 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1493 void MWindow::init_cache()
1495 audio_cache = new CICache(preferences);
1496 video_cache = new CICache(preferences);
1497 frame_cache = new FrameCache;
1498 wave_cache = new WaveCache;
1501 void MWindow::init_channeldb()
1503 channeldb_buz->load("channeldb_buz");
1504 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1507 void MWindow::init_menus()
1509 char string[BCTEXTLEN];
1512 BC_CModels::to_text(string, BC_RGB888);
1513 colormodels.append(new ColormodelItem(string, BC_RGB888));
1514 BC_CModels::to_text(string, BC_RGBA8888);
1515 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1516 // BC_CModels::to_text(string, BC_RGB161616);
1517 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1518 // BC_CModels::to_text(string, BC_RGBA16161616);
1519 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1520 BC_CModels::to_text(string, BC_RGB_FLOAT);
1521 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1522 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1523 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1524 BC_CModels::to_text(string, BC_YUV888);
1525 colormodels.append(new ColormodelItem(string, BC_YUV888));
1526 BC_CModels::to_text(string, BC_YUVA8888);
1527 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1528 // BC_CModels::to_text(string, BC_YUV161616);
1529 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1530 // BC_CModels::to_text(string, BC_YUVA16161616);
1531 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1533 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1534 interlace_project_modes.append(new InterlacemodeItem(string, x));
1536 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1537 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1539 // Interlacing Modes
1540 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1542 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1543 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1545 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1546 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1548 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1549 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1551 mixers_align = new MixersAlign(this);
1554 void MWindow::init_indexes()
1556 mainindexes = new MainIndexes(this);
1557 mainindexes->start_loop();
1560 void MWindow::init_gui()
1562 gui = new MWindowGUI(this);
1563 gui->create_objects();
1564 gui->load_defaults(defaults);
1567 void MWindow::init_signals()
1569 sighandler = new SigHandler;
1570 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1574 void MWindow::init_render()
1576 render = new Render(this);
1577 create_bd = new CreateBD_Thread(this);
1578 create_dvd = new CreateDVD_Thread(this);
1579 batch_render = new BatchRenderThread(this);
1582 void MWindow::init_exportedl()
1584 exportedl = new ExportEDL(this);
1588 void MWindow::init_shuttle()
1591 int ret = Shuttle::probe();
1593 shuttle = new Shuttle(this);
1594 if( shuttle->read_config_file() > 0 ) {
1595 printf("shuttle: bad config file\n");
1596 delete shuttle; shuttle = 0;
1599 shuttle->start(ret);
1603 void MWindow::init_wintv()
1606 wintv = WinTV::probe(this);
1613 void MWindow::init_brender()
1615 if(preferences->use_brender && !brender)
1617 brender_lock->lock("MWindow::init_brender 1");
1618 brender = new BRender(this);
1619 brender->initialize();
1620 session->brender_end = 0;
1621 brender_lock->unlock();
1624 if(!preferences->use_brender && brender)
1626 brender_lock->lock("MWindow::init_brender 2");
1629 session->brender_end = 0;
1630 brender_lock->unlock();
1636 void MWindow::restart_brender()
1638 //printf("MWindow::restart_brender 1\n");
1639 if( !brender_active || !preferences->use_brender ) return;
1640 if( !brender ) return;
1641 brender->restart(edl);
1644 void MWindow::stop_brender()
1646 if( !brender ) return;
1647 // cannot be holding mwindow->gui display lock
1651 int MWindow::brender_available(int position)
1654 brender_lock->lock("MWindow::brender_available 1");
1655 if(brender && brender_active)
1657 if(brender->map_valid)
1659 brender->map_lock->lock("MWindow::brender_available 2");
1660 if(position < brender->map_size &&
1663 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1664 if(brender->map[position] == BRender::RENDERED)
1667 brender->map_lock->unlock();
1670 brender_lock->unlock();
1674 void MWindow::set_brender_active(int v, int update)
1676 if( !preferences->use_brender ) v = 0;
1678 gui->mainmenu->brender_active->set_checked(v);
1680 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1681 edl->session->brender_end = edl->local_session->get_selectionend(1);
1683 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1684 edl->session->brender_end = edl->tracks->total_video_length();
1689 edl->session->brender_start = edl->session->brender_end = 0;
1690 gui->unlock_window();
1692 gui->lock_window("MWindow::set_brender_active");
1695 gui->update_timebar(0);
1696 gui->draw_overlays(1);
1700 int MWindow::has_commercials()
1702 #ifdef HAVE_COMMERCIAL
1703 return theme->use_commercials;
1709 void MWindow::init_commercials()
1711 #ifdef HAVE_COMMERCIAL
1712 if( !commercials ) {
1713 commercials = new Commercials(this);
1714 commercial_active = 0;
1717 commercials->add_user();
1721 void MWindow::commit_commercial()
1723 #ifdef HAVE_COMMERCIAL
1724 if( !commercial_active ) return;
1725 commercial_active = 0;
1726 if( !commercials ) return;
1727 commercials->commitDb();
1731 void MWindow::undo_commercial()
1733 #ifdef HAVE_COMMERCIAL
1734 if( !commercial_active ) return;
1735 commercial_active = 0;
1736 if( !commercials ) return;
1737 commercials->undoDb();
1741 int MWindow::put_commercial()
1744 #ifdef HAVE_COMMERCIAL
1745 double start = edl->local_session->get_selectionstart();
1746 double end = edl->local_session->get_selectionend();
1747 if( start >= end ) return 0;
1749 const char *errmsg = 0;
1751 Tracks *tracks = edl->tracks;
1753 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1754 if( track->data_type != TRACK_VIDEO ) continue;
1755 if( !track->record ) continue;
1756 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1758 int64_t units_start = track->to_units(start,0);
1759 int64_t units_end = track->to_units(end,0);
1760 Edits *edits = track->edits;
1761 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1762 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1763 if(!edit1 && !edit2) continue; // nothing selected
1764 if(!edit2) { // edit2 beyond end of track
1765 edit2 = edits->last;
1766 units_end = edits->length();
1768 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1769 Indexable *indexable = edit1->get_source();
1770 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1773 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1774 if( track->data_type != TRACK_VIDEO ) continue;
1775 if( !track->record ) continue;
1776 int64_t units_start = track->to_units(start,0);
1777 int64_t units_end = track->to_units(end,0);
1778 Edits *edits = track->edits;
1779 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1780 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1781 if(!edit1 && !edit2) continue; // nothing selected
1782 if(!edit2) { // edit2 beyond end of track
1783 edit2 = edits->last;
1784 units_end = edits->length();
1786 Indexable *indexable = edit1->get_source();
1787 Asset *asset = (Asset *)indexable;
1788 File *file = video_cache->check_out(asset, edl);
1789 if( !file ) { errmsg = _("no file"); break; }
1790 int64_t edit_length = units_end - units_start;
1791 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1792 result = commercials->put_clip(file, edit1->channel,
1793 track->from_units(edit_start), track->from_units(edit_length));
1794 video_cache->check_in(asset);
1795 if( result ) { errmsg = _("db failed"); break; }
1798 char string[BCTEXTLEN];
1799 sprintf(string, _("put_commercial: %s"), errmsg);
1800 MainError::show_error(string);
1808 void MWindow::stop_playback(int wait)
1810 gui->stop_drawing();
1812 cwindow->stop_playback(wait);
1814 for(int i = 0; i < vwindows.size(); i++) {
1815 VWindow *vwindow = vwindows[i];
1816 if( !vwindow->is_running() ) continue;
1817 vwindow->stop_playback(wait);
1819 for(int i = 0; i < zwindows.size(); i++) {
1820 ZWindow *zwindow = zwindows[i];
1821 if( zwindow->idx < 0 ) continue;
1822 zwindow->stop_playback(wait);
1826 void MWindow::stop_transport()
1828 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1831 void MWindow::undo_before(const char *description, void *creator)
1833 undo->update_undo_before(description, creator);
1836 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
1838 undo->update_undo_after(description, load_flags, changes_made);
1841 void MWindow::beep(double freq, double secs, double gain)
1843 if( !beeper ) beeper = new Beeper(this);
1844 beeper->tone(freq, secs, gain);
1847 Beeper::Beeper(MWindow *mwindow)
1850 this->mwindow = mwindow;
1851 audio = new AudioDevice(mwindow);
1865 int64_t bfrsz = BEEP_SAMPLE_RATE;
1866 EDL *edl = mwindow->edl;
1867 EDLSession *session = edl->session;
1868 AudioOutConfig *aconfig = session->playback_config->aconfig;
1869 audio->open_output(aconfig, BEEP_SAMPLE_RATE, bfrsz, channels, 0);
1870 audio->start_playback();
1872 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
1873 const double two_pi = 2*M_PI;
1874 int64_t audio_len = BEEP_SAMPLE_RATE * secs;
1875 const double dt = two_pi * freq/BEEP_SAMPLE_RATE;
1880 while( !interrupted ) {
1881 int len = audio_len - audio_pos;
1882 if( len <= 0 ) break;
1883 if( len > bfrsz ) len = bfrsz;
1885 for( int i=0; i<len; ++i,++k,th+=dt ) {
1886 double t = th - two_pi;
1887 if( t >= 0 ) th = t;
1888 out0[i] = out1[i] = sin(th) * gain;
1890 audio->write_buffer(out, channels, len);
1895 audio->set_last_buffer();
1896 audio->stop_audio(interrupted ? 0 : 1);
1902 void Beeper::start()
1904 if( running() ) return;
1910 void Beeper::stop(int wait)
1912 if( running() && !interrupted ) {
1914 audio->stop_audio(wait);
1919 void Beeper::tone(double freq, double secs, double gain)
1929 int MWindow::load_filenames(ArrayList<char*> *filenames,
1930 int load_mode, int edl_mode, int update_filename)
1932 ArrayList<EDL*> new_edls;
1933 ArrayList<Asset*> new_assets;
1934 ArrayList<File*> new_files;
1937 gui->start_hourglass();
1939 // Need to stop playback since tracking depends on the EDL not getting
1941 gui->unlock_window();
1943 gui->lock_window("MWindow::load_filenames 0");
1946 const int debug = 0;
1947 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1949 // Define new_edls and new_assets to load
1950 int result = 0, ftype = -1;
1952 for( int i=0; i<filenames->size(); ++i ) {
1954 File *new_file = new File;
1955 Asset *new_asset = new Asset(filenames->get(i));
1956 EDL *new_edl = new EDL;
1957 new_edl->create_objects();
1958 new_edl->copy_session(edl, -1);
1959 new_file->set_program(edl->session->program_no);
1961 char string[BCTEXTLEN];
1962 sprintf(string, _("Loading %s"), new_asset->path);
1963 gui->show_message(string);
1965 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1969 // Convert media file to EDL
1971 // Warn about odd image dimensions
1972 if( new_asset->video_data &&
1973 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1974 eprintf(_("%s's resolution is %dx%d.\n"
1975 "Images with odd dimensions may not decode properly."),
1976 new_asset->path, new_asset->width, new_asset->height);
1979 if( new_asset->program >= 0 &&
1980 edl->session->program_no != new_asset->program ) {
1981 eprintf(_("%s's index was built for program number %d\n"
1982 "Playback preference is %d.\n Using program %d."),
1983 new_asset->path, new_asset->program,
1984 edl->session->program_no, new_asset->program);
1987 if( load_mode == LOADMODE_RESOURCESONLY ) {
1988 new_assets.append(new_asset);
1989 new_asset->add_user();
1994 RecordLabels *labels = edl->session->label_cells ?
1995 new RecordLabels(new_file) : 0;
1996 asset_to_edl(new_edl, new_asset, labels);
1997 new_edls.append(new_edl);
1998 new_edl->add_user();
2001 if( load_mode == LOADMODE_REPLACE ||
2002 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2003 // Set filename to nothing for assets since save EDL would overwrite them.
2005 // Reset timeline position
2006 for( int i=0; i<TOTAL_PANES; ++i ) {
2007 new_edl->local_session->view_start[i] = 0;
2008 new_edl->local_session->track_start[i] = 0;
2014 case FILE_NOT_FOUND: {
2015 eprintf(_("Failed to open %s"), new_asset->path);
2016 sprintf(string, _("Failed to open %s"), new_asset->path);
2017 gui->show_message(string, theme->message_error);
2018 gui->update_default_message();
2022 case FILE_UNRECOGNIZED_CODEC: {
2024 { IndexFile indexfile(this, new_asset);
2025 if( !(result = indexfile.open_index()) )
2026 indexfile.close_index(); }
2028 // Test existing EDLs
2029 for( int j=0; result && j<new_edls.total; ++j ) {
2030 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
2032 new_asset->copy_from(old_asset,1);
2037 Asset *old_asset = edl->assets->get_asset(new_asset->path);
2039 new_asset->copy_from(old_asset,1);
2046 new_asset->audio_data = 1;
2047 new_asset->format = FILE_PCM;
2048 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
2049 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
2050 new_asset->bits = defaults->get("AUDIO_BITS", 16);
2051 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
2052 new_asset->signed_ = defaults->get("SIGNED_", 1);
2053 new_asset->header = defaults->get("HEADER", 0);
2056 fs.extract_name(string, new_asset->path);
2057 strcat(string, _("'s format couldn't be determined."));
2058 FileFormat fwindow(this);
2059 fwindow.create_objects(new_asset, string);
2060 result = fwindow.run_window();
2062 defaults->update("AUDIO_CHANNELS", new_asset->channels);
2063 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
2064 defaults->update("AUDIO_BITS", new_asset->bits);
2065 defaults->update("BYTE_ORDER", new_asset->byte_order);
2066 defaults->update("SIGNED_", new_asset->signed_);
2067 defaults->update("HEADER", new_asset->header);
2072 // Recalculate length
2074 new_file = new File;
2075 result = new_file->open_file(preferences, new_asset, 1, 0);
2077 if( load_mode != LOADMODE_RESOURCESONLY ) {
2078 RecordLabels *labels = edl->session->label_cells ?
2079 new RecordLabels(new_file) : 0;
2080 asset_to_edl(new_edl, new_asset, labels);
2081 new_edls.append(new_edl);
2082 new_edl->add_user();
2086 new_assets.append(new_asset);
2087 new_asset->add_user();
2094 const char *filename = filenames->get(i);
2095 if( xml_file.read_from_file(filename, 1) ) {
2096 eprintf(_("Error: unable to open:\n %s"), filename);
2099 const char *cin_version = 0;
2100 while( !xml_file.read_tag() ) {
2101 if( xml_file.tag.title_is("EDL") ) {
2102 cin_version = xml_file.tag.get_property("VERSION");
2107 if( !cin_version ) {
2108 eprintf(_("XML file %s\n not from cinelerra."),filename);
2109 char string[BCTEXTLEN];
2110 sprintf(string,_("Unknown %s"), filename);
2111 gui->show_message(string);
2114 if( strcmp(cin_version, CINELERRA_VERSION) &&
2115 strcmp(cin_version, "Unify") &&
2116 strcmp(cin_version, "5.1") ) {
2117 eprintf(_("Warning: XML from cinelerra version %s\n"
2118 "Session data may be incompatible."), cin_version);
2120 if( new_edl->load_xml(&xml_file, LOAD_ALL) ) {
2121 eprintf(_("Error: unable to load:\n %s"), filename);
2124 test_plugins(new_edl, filename);
2125 int groups = new_edl->regroup(session->group_number);
2126 session->group_number += groups;
2127 switch( edl_mode ) {
2128 case LOADMODE_EDL_CLIP: {
2129 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2130 session->clip_number++);
2131 char string[BCSTRLEN];
2133 ctime_r(&t, string);
2134 snprintf(new_edl->local_session->clip_notes,
2135 sizeof(new_edl->local_session->clip_notes),
2136 +("%sFrom: %s"), string, filename);
2137 switch( load_mode ) {
2138 case LOADMODE_REPLACE:
2139 case LOADMODE_REPLACE_CONCATENATE:
2140 strcpy(session->filename, filename);
2141 if( update_filename ) set_filename(filename);
2146 case LOADMODE_EDL_NESTED: {
2147 EDL *nested_edl = new EDL;
2148 nested_edl->create_objects();
2149 nested_edl->copy_session(edl, -1);
2150 nested_edl->create_nested(new_edl);
2151 nested_edl->set_path(filename);
2152 new_edl->remove_user();
2153 new_edl = nested_edl;
2156 case LOADMODE_EDL_FILEREF: {
2157 result = create_ref(new_asset, new_edl);
2159 new_assets.append(new_asset);
2160 new_asset->add_user();
2161 new_edl->remove_user();
2163 new_edl->create_objects();
2164 new_edl->copy_session(edl, -1);
2165 asset_to_edl(new_edl, new_asset);
2167 new_file = new File;
2168 result = new_file->open_file(preferences, new_asset, 1, 0);
2172 new_edls.append(new_edl);
2173 new_edl->add_user();
2176 eprintf(_("Error: Unable to load xml:\n %s"), new_asset->path);
2180 new_edl->Garbage::remove_user();
2181 new_asset->Garbage::remove_user();
2183 // Store for testing index
2184 new_files.append(new_file);
2187 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2190 gui->reset_default_message();
2191 gui->default_message();
2194 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2197 // Don't back up here.
2198 if( new_edls.size() ) {
2199 // For pasting, clear the active region
2200 if( load_mode == LOADMODE_PASTE ) {
2201 double start = edl->local_session->get_selectionstart();
2202 double end = edl->local_session->get_selectionend();
2203 if(!EQUIV(start, end))
2204 edl->clear(start, end,
2205 edl->session->labels_follow_edits,
2206 edl->session->plugins_follow_edits,
2207 edl->session->autos_follow_edits);
2209 paste_edls(&new_edls, load_mode, 0, -1,
2210 edl->session->labels_follow_edits,
2211 edl->session->plugins_follow_edits,
2212 edl->session->autos_follow_edits,
2215 else if( load_mode == LOADMODE_NEW_TRACKS &&
2216 edl_mode != LOADMODE_EDL_CLIP )
2217 paste_edls(&new_edls, load_mode, 0, -1, 0, 0, 0, 0);
2218 else if( load_mode != LOADMODE_RESOURCESONLY ||
2219 edl_mode == LOADMODE_EDL_CLIP )
2220 paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
2222 paste_edls(&new_edls, LOADMODE_NOTHING, 0, -1, 0, 0, 0, 0);
2226 // Add new assets to EDL and schedule assets for index building.
2227 int got_indexes = 0;
2228 for( int i=0; i<new_edls.size(); ++i ) {
2229 EDL *new_edl = new_edls[i];
2230 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2231 mainindexes->add_indexable(new_edl->nested_edls[j]);
2232 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2238 for( int i=0; i<new_assets.size(); ++i ) {
2239 Asset *new_asset = new_assets[i];
2240 mainindexes->add_indexable(new_asset);
2241 edl->assets->update(new_asset);
2245 // Start examining next batch of index files
2246 if(got_indexes) mainindexes->start_build();
2249 Track *track = edl->tracks->first;
2251 for( int j = 0; j < track->plugin_set.size(); j++ ) {
2252 PluginSet *plugins = track->plugin_set[j];
2253 Plugin *plugin = plugins->get_first_plugin();
2256 if( load_mode == LOADMODE_REPLACE ||
2257 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
2258 if( plugin->plugin_type == PLUGIN_STANDALONE &&
2260 show_plugin(plugin);
2264 plugin = (Plugin*)plugin->next;
2268 track = track->next;
2271 // opening new session
2272 if( ( load_mode == LOADMODE_REPLACE ||
2273 load_mode == LOADMODE_REPLACE_CONCATENATE ) &&
2274 (ftype != FILE_IS_XML || edl_mode != LOADMODE_EDL_CLIP) ) {
2276 edl->session->proxy_scale = 1;
2277 edl->session->proxy_disabled_scale = 1;
2278 edl->session->proxy_use_scaler = 0;
2279 edl->session->proxy_auto_scale = 0;
2280 edl->session->proxy_beep = 0;
2281 edl->local_session->preview_start = 0;
2282 edl->local_session->preview_end = -1;
2283 edl->local_session->loop_playback = 0;
2284 edl->local_session->set_selectionstart(0);
2285 edl->local_session->set_selectionend(0);
2286 edl->local_session->unset_inpoint();
2287 edl->local_session-> unset_outpoint();
2288 set_brender_active(0, 0);
2293 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2294 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2295 ArrayList<Indexable *> orig_idxbls;
2296 for( int i=0; i<new_assets.size(); ++i )
2297 orig_idxbls.append(new_assets.get(i));
2298 for( int i=0; i<new_edls.size(); ++i ) {
2299 EDL *new_edl = new_edls[i];
2300 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2301 if( track->data_type != TRACK_VIDEO ) continue;
2302 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2303 Indexable *idxbl = (Indexable *)edit->asset;
2304 if( !idxbl ) continue;
2305 if( !idxbl->have_video() ) continue;
2306 if( edit->channel != 0 ) continue; // first layer only
2307 orig_idxbls.append(edit->asset);
2311 gui->unlock_window(); // to update progress bar
2312 int ret = render_proxy(orig_idxbls);
2313 gui->lock_window("MWindow::load_filenames");
2314 float gain = edl->session->proxy_beep;
2315 if( ret >= 0 && gain > 0 ) {
2317 beep(2000., 1.5, gain);
2319 beep(4000., 0.25, gain);
2323 // need to update undo before project, since mwindow is unlocked & a new load
2324 // can begin here. Should really prevent loading until we're done.
2325 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2326 undo_after(_("load"), LOAD_ALL);
2328 for(int i = 0; i < new_edls.size(); i++)
2330 new_edls[i]->remove_user();
2332 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2334 new_edls.remove_all();
2336 for(int i = 0; i < new_assets.size(); i++)
2338 new_assets[i]->Garbage::remove_user();
2341 new_assets.remove_all();
2342 new_files.remove_all_objects();
2345 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2346 if(load_mode == LOADMODE_REPLACE ||
2347 load_mode == LOADMODE_REPLACE_CONCATENATE)
2349 session->changes_made = 0;
2353 session->changes_made = 1;
2356 gui->stop_hourglass();
2359 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2360 update_project(load_mode);
2362 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2367 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2369 Asset *format_asset = new Asset;
2370 format_asset->format = FILE_FFMPEG;
2371 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2372 int new_scale = edl->session->proxy_scale;
2373 ProxyRender proxy_render(this, format_asset, new_scale);
2375 for( int i=0; i<new_idxbls.size(); ++i ) {
2376 Indexable *orig = new_idxbls.get(i);
2377 Asset *proxy = proxy_render.add_original(orig, new_scale);
2378 if( !proxy ) continue;
2380 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2381 int got_it = exists && // if proxy exists, and is newer than orig
2382 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2383 if( got_it ) continue;
2384 proxy_render.add_needed(orig, proxy);
2387 // render needed proxies
2388 int result = proxy_render.create_needed_proxies(new_scale);
2390 add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2392 format_asset->remove_user();
2393 return !result ? proxy_render.needed_proxies.size() : -1;
2396 int MWindow::enable_proxy()
2399 if( edl->session->proxy_scale == 1 &&
2400 edl->session->proxy_disabled_scale != 1 ) {
2401 int new_scale = edl->session->proxy_disabled_scale;
2402 int new_use_scaler = edl->session->proxy_use_scaler;
2403 Asset *asset = new Asset;
2404 asset->format = FILE_FFMPEG;
2405 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2406 ret = to_proxy(asset, new_scale, new_use_scaler);
2407 asset->remove_user();
2409 float gain = edl->session->proxy_beep;
2410 beep(2000., 1.5, gain);
2412 edl->session->proxy_disabled_scale = 1;
2413 gui->lock_window("MWindow::to_proxy");
2414 update_project(LOADMODE_REPLACE);
2415 gui->unlock_window();
2420 int MWindow::disable_proxy()
2422 if( edl->session->proxy_scale != 1 &&
2423 edl->session->proxy_disabled_scale == 1 ) {
2424 int old_scale = edl->session->proxy_scale, new_scale = 1;
2425 int new_use_scaler = edl->session->proxy_use_scaler;
2426 Asset *asset = new Asset;
2427 asset->format = FILE_FFMPEG;
2428 asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2429 to_proxy(asset, new_scale, new_use_scaler);
2430 asset->remove_user();
2431 edl->session->proxy_disabled_scale = old_scale;
2432 gui->lock_window("MWindow::to_proxy");
2433 update_project(LOADMODE_REPLACE);
2434 gui->unlock_window();
2439 int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
2441 ArrayList<Indexable*> orig_idxbls;
2442 ArrayList<Indexable*> proxy_assets;
2444 edl->Garbage::add_user();
2446 undo_before(_("proxy"), this);
2447 int asset_scale = new_scale == 1 ? 0 :
2448 !new_use_scaler ? 1 : new_scale;
2449 ProxyRender proxy_render(this, asset, asset_scale);
2451 // revert project to original size from current size
2452 // remove all session proxy assets at the at the current proxy_scale
2453 int proxy_scale = edl->session->proxy_scale;
2455 if( proxy_scale > 1 ) {
2456 Asset *orig_asset = edl->assets->first;
2457 for( ; orig_asset; orig_asset=orig_asset->next ) {
2458 char new_path[BCTEXTLEN];
2459 proxy_render.to_proxy_path(new_path, orig_asset, proxy_scale);
2460 // test if proxy asset was already added to proxy_assets
2462 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2463 got_it = !strcmp(proxy_assets[i]->path, new_path);
2464 if( got_it ) continue;
2465 Asset *proxy_asset = edl->assets->get_asset(new_path);
2466 if( !proxy_asset ) continue;
2467 // add pointer to existing EDL asset if it exists
2468 // EDL won't delete it unless it's the same pointer.
2469 proxy_assets.append(proxy_asset);
2470 proxy_asset->add_user();
2471 orig_idxbls.append(orig_asset);
2472 orig_asset->add_user();
2474 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2475 EDL *orig_nested = edl->nested_edls[i];
2476 char new_path[BCTEXTLEN];
2477 if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
2479 proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
2480 // test if proxy asset was already added to proxy_assets
2482 for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
2483 got_it = !strcmp(proxy_assets[i]->path, new_path);
2484 if( got_it ) continue;
2485 Asset *proxy_nested = edl->assets->get_asset(new_path);
2486 if( !proxy_nested ) continue;
2487 // add pointer to existing EDL asset if it exists
2488 // EDL won't delete it unless it's the same pointer.
2489 proxy_assets.append(proxy_nested);
2490 proxy_nested->add_user();
2491 orig_idxbls.append(orig_nested);
2492 orig_nested->add_user();
2495 // convert from the proxy assets to the original assets
2496 edl->set_proxy(1, 0, &proxy_assets, &orig_idxbls);
2498 // remove the references
2499 for( int i=0; i<proxy_assets.size(); ++i ) {
2500 Asset *proxy = (Asset *) proxy_assets[i];
2501 proxy->width = proxy->actual_width;
2502 proxy->height = proxy->actual_height;
2503 proxy->remove_user();
2504 edl->assets->remove_pointer(proxy);
2505 proxy->remove_user();
2507 proxy_assets.remove_all();
2508 for( int i = 0; i < orig_idxbls.size(); i++ )
2509 orig_idxbls[i]->remove_user();
2510 orig_idxbls.remove_all();
2513 ArrayList<char *> confirm_paths; // test for new files
2514 confirm_paths.set_array_delete();
2516 // convert to new size if not original size
2517 if( new_scale != 1 ) {
2519 Asset *orig = edl->assets->first;
2520 for( ; orig; orig=orig->next ) {
2521 Asset *proxy = proxy_render.add_original(orig, new_scale);
2522 if( !proxy ) continue;
2523 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2524 int got_it = exists && // if proxy exists, and is newer than orig
2525 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2527 if( exists ) // prompt user to overwrite
2528 confirm_paths.append(cstrdup(proxy->path));
2529 proxy_render.add_needed(orig, proxy);
2532 for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
2533 EDL *orig_nested = edl->nested_edls[i];
2534 Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
2535 if( !proxy ) continue;
2536 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2537 int got_it = exists && // if proxy exists, and is newer than orig_nested
2538 fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
2540 if( exists ) // prompt user to overwrite
2541 confirm_paths.append(cstrdup(proxy->path));
2542 proxy_render.add_needed(orig_nested, proxy);
2548 // test for existing files
2549 if( confirm_paths.size() ) {
2550 result = ConfirmSave::test_files(this, &confirm_paths);
2551 confirm_paths.remove_all_objects();
2555 result = proxy_render.create_needed_proxies(new_scale);
2557 if( !result ) // resize project
2558 edl->set_proxy(new_scale, new_use_scaler,
2559 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2561 undo_after(_("proxy"), LOAD_ALL);
2562 edl->Garbage::remove_user();
2565 return !result ? proxy_render.needed_proxies.size() : -1;
2568 void MWindow::test_plugins(EDL *new_edl, const char *path)
2570 char string[BCTEXTLEN];
2572 // Do a check whether plugins exist
2573 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2574 for( int k=0; k<track->plugin_set.total; ++k ) {
2575 PluginSet *plugin_set = track->plugin_set[k];
2576 for( Plugin *plugin = (Plugin*)plugin_set->first;
2577 plugin; plugin = (Plugin*)plugin->next ) {
2578 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2579 // ok we need to find it in plugindb
2580 PluginServer *server =
2581 scan_plugindb(plugin->title, track->data_type);
2582 if( !server || server->transition ) {
2584 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2585 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2586 "effect", _(plugin->title), path);
2587 MainError::show_error(string);
2592 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2593 if( !edit->transition ) continue;
2594 // ok we need to find transition in plugindb
2595 PluginServer *server =
2596 scan_plugindb(edit->transition->title, track->data_type);
2597 if( !server || !server->transition ) {
2599 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2600 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2601 "transition", _(edit->transition->title), path);
2602 MainError::show_error(string);
2609 void MWindow::init_shm(const char *pfn, int64_t min)
2612 // Fix shared memory
2613 FILE *fd = fopen(pfn, "r");
2615 fscanf(fd, "%jd", &result);
2617 if( result >= min ) return;
2620 fd = fopen(pfn, "w");
2622 fprintf(fd, "0x%jx", min);
2625 fd = fopen(pfn, "r");
2627 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2631 fscanf(fd, "%jd", &result);
2633 if( result < min ) {
2634 eprintf(_("MWindow::init_shm: %s is %p.\n"
2635 "you probably need to be root, or:\n"
2636 "as root, run: echo 0x%jx > %s\n"
2637 "before trying to start cinelerra.\n"
2638 "It should be at least 0x%jx for Cinelerra.\n"),
2639 pfn, (void *)result, min, pfn, min);
2643 void MWindow::create_objects(int want_gui,
2647 const int debug = 0;
2648 if(debug) PRINT_TRACE
2650 // For some reason, init_signals must come after show_splash or the signals won't
2653 if(debug) PRINT_TRACE
2656 if(debug) PRINT_TRACE
2659 if(debug) PRINT_TRACE
2660 default_standard = default_std();
2661 init_defaults(defaults, config_path);
2665 splash_window->update_status(_("Initializing Plugins"));
2666 init_plugins(this, preferences);
2667 if(debug) PRINT_TRACE
2668 init_ladspa_plugins(this, preferences);
2669 if(debug) PRINT_TRACE
2670 init_plugin_tips(*plugindb, cin_lang);
2672 splash_window->update_status(_("Initializing GUI"));
2673 if(debug) PRINT_TRACE
2676 if(debug) PRINT_TRACE
2680 splash_window->update_status(_("Initializing Fonts"));
2681 char string[BCTEXTLEN];
2682 strcpy(string, preferences->plugin_dir);
2683 strcat(string, "/" FONT_SEARCHPATH);
2684 BC_Resources::init_fontconfig(string);
2685 if(debug) PRINT_TRACE
2688 // Default project created here
2690 if(debug) PRINT_TRACE
2693 if(debug) PRINT_TRACE
2698 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2701 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2703 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2704 if(session->show_vwindow)
2705 get_viewer(1, DEFAULT_VWINDOW);
2706 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2709 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2712 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2715 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2718 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2721 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2724 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2730 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2731 mainprogress = new MainProgress(this, gui);
2732 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2733 undo = new MainUndo(this);
2735 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2737 plugin_guis = new PluginGUIs(this);
2738 dead_plugins = new ArrayList<PluginServer*>;
2739 keyframe_threads = new ArrayList<KeyFrameThread*>;
2741 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2744 session->show_vwindow);
2746 // Show all vwindows
2747 // if(session->show_vwindow) {
2748 // for(int j = 0; j < vwindows.size(); j++) {
2749 // VWindow *vwindow = vwindows[j];
2750 // if( !vwindow->is_running() ) continue;
2751 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2754 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2755 // vwindow->gui->lock_window("MWindow::create_objects 1");
2756 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2757 // vwindow->gui->show_window();
2758 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2759 // vwindow->gui->unlock_window();
2764 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2766 if(session->show_cwindow)
2768 cwindow->gui->lock_window("MWindow::create_objects 1");
2769 cwindow->gui->show_window();
2770 cwindow->gui->unlock_window();
2773 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2774 if(session->show_awindow)
2776 awindow->gui->lock_window("MWindow::create_objects 1");
2777 awindow->gui->show_window();
2778 awindow->gui->unlock_window();
2781 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2782 if(session->show_lwindow)
2784 lwindow->gui->lock_window("MWindow::create_objects 1");
2785 lwindow->gui->show_window();
2786 lwindow->gui->unlock_window();
2789 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2791 (int)timer.get_difference(),
2793 if(session->show_gwindow)
2795 gwindow->gui->lock_window("MWindow::create_objects 1");
2796 gwindow->gui->show_window();
2797 gwindow->gui->unlock_window();
2800 if(debug) PRINT_TRACE
2802 gui->lock_window("MWindow::create_objects 1");
2803 gui->mainmenu->load_defaults(defaults);
2804 gui->mainmenu->update_toggles(0);
2805 gui->update_patchbay();
2806 gui->draw_canvas(0, 0);
2807 gui->draw_cursor(1);
2809 gui->raise_window();
2810 gui->unlock_window();
2811 cwindow->gui->lock_window("MWindow::create_objects 1");
2812 cwindow->gui->tool_panel->raise_tool();
2813 cwindow->gui->unlock_window();
2814 if(debug) PRINT_TRACE
2816 if(preferences->use_tipwindow)
2818 if(debug) PRINT_TRACE
2820 gui->add_keyboard_listener(
2821 (int (BC_WindowBase::*)(BC_WindowBase *))
2822 &MWindowGUI::keyboard_listener);
2825 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2826 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2827 if(debug) PRINT_TRACE
2829 BC_WindowBase::get_resources()->vframe_shm = 1;
2832 int MWindow::uses_opengl()
2834 if( !playback_3d || !playback_3d->running() ) return 0;
2835 PlaybackConfig *playback_config = edl->session->playback_config;
2836 return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
2839 void MWindow::show_splash()
2841 #include "data/heroine_logo9_png.h"
2842 VFrame *frame = new VFramePng(heroine_logo9_png);
2843 BC_DisplayInfo dpyi;
2844 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2845 int rr = (rw < rh ? rw : rh) / 4;
2846 splash_window = new SplashGUI(frame, rr, rr);
2847 splash_window->create_objects();
2850 void MWindow::hide_splash()
2853 delete splash_window;
2858 void MWindow::start()
2862 // vwindows[DEFAULT_VWINDOW]->start();
2873 playback_3d->start();
2879 run_lock->lock("MWindow::run");
2883 brender_lock->lock("MWindow::run 1");
2884 delete brender; brender = 0;
2885 brender_lock->unlock();
2887 interrupt_indexes();
2893 void MWindow::show_vwindow()
2895 int total_running = 0;
2896 session->show_vwindow = 1;
2898 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2899 // Raise all windows which are visible
2900 for(int j = 0; j < vwindows.size(); j++) {
2901 VWindow *vwindow = vwindows[j];
2902 if( !vwindow->is_running() ) continue;
2903 vwindow->gui->lock_window("MWindow::show_vwindow");
2904 vwindow->gui->show_window(0);
2905 vwindow->gui->raise_window();
2906 vwindow->gui->flush();
2907 vwindow->gui->unlock_window();
2911 // If no windows visible
2914 get_viewer(1, DEFAULT_VWINDOW);
2917 gui->mainmenu->show_vwindow->set_checked(1);
2920 void MWindow::show_awindow()
2922 session->show_awindow = 1;
2923 awindow->gui->lock_window("MWindow::show_awindow");
2924 awindow->gui->show_window();
2925 awindow->gui->raise_window();
2926 awindow->gui->flush();
2927 awindow->gui->unlock_window();
2928 gui->mainmenu->show_awindow->set_checked(1);
2931 char *MWindow::get_cwindow_display()
2933 char *x11_host = screens < 2 || session->window_config == 0 ?
2934 session->a_x11_host : session->b_x11_host;
2935 return *x11_host ? x11_host : 0;
2938 void MWindow::show_cwindow()
2940 session->show_cwindow = 1;
2941 cwindow->show_window();
2942 gui->mainmenu->show_cwindow->set_checked(1);
2945 void MWindow::show_gwindow()
2947 session->show_gwindow = 1;
2949 gwindow->gui->lock_window("MWindow::show_gwindow");
2950 gwindow->gui->show_window();
2951 gwindow->gui->raise_window();
2952 gwindow->gui->flush();
2953 gwindow->gui->unlock_window();
2955 gui->mainmenu->show_gwindow->set_checked(1);
2957 void MWindow::hide_gwindow()
2959 session->show_gwindow = 0;
2961 gwindow->gui->lock_window("MWindow::show_gwindow");
2962 gwindow->gui->hide_window();
2963 gwindow->gui->unlock_window();
2966 void MWindow::show_lwindow()
2968 session->show_lwindow = 1;
2969 lwindow->gui->lock_window("MWindow::show_lwindow");
2970 lwindow->gui->show_window();
2971 lwindow->gui->raise_window();
2972 lwindow->gui->flush();
2973 lwindow->gui->unlock_window();
2974 gui->mainmenu->show_lwindow->set_checked(1);
2977 void MWindow::restore_windows()
2979 if( !session->show_vwindow ) {
2980 for( int i=0, n=vwindows.size(); i<n; ++i ) {
2981 VWindow *vwindow = vwindows[i];
2982 if( !vwindow || !vwindow->is_running() ) continue;
2983 vwindow->gui->lock_window("MWindow::restore_windows");
2984 vwindow->gui->close(1);
2985 vwindow->gui->unlock_window();
2991 if( !session->show_awindow && !awindow->gui->is_hidden() ) {
2992 awindow->gui->lock_window("MWindow::restore_windows");
2993 awindow->gui->close_event();
2994 awindow->gui->unlock_window();
2996 else if( session->show_awindow && awindow->gui->is_hidden() )
2999 if( !session->show_cwindow && !cwindow->gui->is_hidden() ) {
3000 cwindow->gui->lock_window("MWindow::restore_windows");
3001 cwindow->hide_window();
3002 cwindow->gui->unlock_window();
3004 else if( session->show_cwindow && cwindow->gui->is_hidden() )
3005 cwindow->show_window();
3007 if( !session->show_gwindow && !gwindow->gui->is_hidden() ) {
3008 gwindow->gui->lock_window("MWindow::restore_windows");
3009 gwindow->gui->close_event();
3010 gwindow->gui->unlock_window();
3012 else if( session->show_gwindow && gwindow->gui->is_hidden() )
3015 if( !session->show_lwindow && !lwindow->gui->is_hidden() ) {
3016 lwindow->gui->lock_window("MWindow::restore_windows");
3017 lwindow->gui->close_event();
3018 lwindow->gui->unlock_window();
3020 else if( session->show_lwindow && lwindow->gui->is_hidden() )
3026 void MWindow::load_layout(const char *layout)
3028 char path[BCTEXTLEN];
3029 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3030 session->load_file(path);
3032 gui->default_positions();
3036 void MWindow::save_layout(const char *layout)
3038 char path[BCTEXTLEN];
3039 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3040 session->save_file(path);
3043 void MWindow::delete_layout(const char *layout)
3045 char path[BCTEXTLEN];
3046 snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
3050 int MWindow::tile_windows(int window_config)
3052 int need_reload = 0;
3053 int play_config = window_config==0 ? 0 : 1;
3054 edl->session->playback_config->load_defaults(defaults, play_config);
3055 session->default_window_positions(window_config);
3056 if( screens == 1 ) {
3057 gui->default_positions();
3058 sync_parameters(CHANGE_ALL);
3065 void MWindow::toggle_loop_playback()
3067 edl->local_session->loop_playback = !edl->local_session->loop_playback;
3068 set_loop_boundaries();
3071 gui->draw_overlays(1);
3072 sync_parameters(CHANGE_PARAMS);
3075 void MWindow::set_screens(int value)
3080 void MWindow::set_auto_keyframes(int value)
3082 edl->session->auto_keyframes = value;
3083 gui->mbuttons->edit_panel->keyframe->update(value);
3085 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
3086 cwindow->gui->edit_panel->keyframe->update(value);
3087 cwindow->gui->flush();
3088 cwindow->gui->unlock_window();
3091 void MWindow::set_span_keyframes(int value)
3093 edl->session->span_keyframes = value;
3094 gui->mbuttons->edit_panel->span_keyframe->update(value);
3096 cwindow->gui->lock_window("MWindow::set_span_keyframes");
3097 cwindow->gui->edit_panel->span_keyframe->update(value);
3098 cwindow->gui->flush();
3099 cwindow->gui->unlock_window();
3102 void MWindow::set_auto_visibility(Autos *autos, int value)
3104 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
3105 edl->session->auto_conf->plugins = value;
3106 else if( autos->autoidx >= 0 )
3107 edl->session->auto_conf->autos[autos->autoidx] = value;
3111 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3112 gui->mainmenu->update_toggles(1);
3113 gui->unlock_window();
3114 gwindow->gui->update_toggles(1);
3115 gui->lock_window("MWindow::set_auto_visibility");
3118 void MWindow::set_keyframe_type(int mode)
3120 gui->lock_window("MWindow::set_keyframe_type");
3121 edl->local_session->floatauto_type = mode;
3122 gui->mainmenu->update_toggles(0);
3123 gui->unlock_window();
3126 int MWindow::set_editing_mode(int new_editing_mode)
3128 edl->session->editing_mode = new_editing_mode;
3129 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
3130 gui->mbuttons->edit_panel->update();
3131 gui->set_editing_mode(1);
3133 cwindow->gui->lock_window("MWindow::set_editing_mode");
3134 cwindow->gui->edit_panel->update();
3135 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
3136 cwindow->gui->unlock_window();
3140 void MWindow::toggle_editing_mode()
3142 int mode = edl->session->editing_mode;
3143 if( mode == EDITING_ARROW )
3144 set_editing_mode(EDITING_IBEAM);
3146 set_editing_mode(EDITING_ARROW);
3149 void MWindow::toggle_camera_xyz()
3151 gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
3152 gwindow->gui->toggle_camera_xyz();
3153 gwindow->gui->unlock_window();
3156 void MWindow::toggle_projector_xyz()
3158 gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
3159 gwindow->gui->toggle_projector_xyz();
3160 gwindow->gui->unlock_window();
3163 void MWindow::set_labels_follow_edits(int value)
3165 edl->session->labels_follow_edits = value;
3166 gui->mbuttons->edit_panel->locklabels->update(value);
3167 gui->mainmenu->labels_follow_edits->set_checked(value);
3171 void MWindow::sync_parameters(int change_type)
3173 if( in_destructor ) return;
3175 // Sync engines which are playing back
3176 if( cwindow->playback_engine->is_playing_back ) {
3177 if( change_type == CHANGE_PARAMS ) {
3178 // TODO: block keyframes until synchronization is done
3179 cwindow->playback_engine->sync_parameters(edl);
3183 int command = cwindow->playback_engine->command->command;
3184 // Waiting for tracking to finish would make the restart position more
3185 // accurate but it can't lock the window to stop tracking for some reason.
3186 // Not waiting for tracking gives a faster response but restart position is
3187 // only as accurate as the last tracking update.
3188 cwindow->playback_engine->transport_stop(0);
3189 cwindow->playback_engine->next_command->realtime = 1;
3190 cwindow->playback_engine->transport_command(command, change_type, edl, 0);
3194 cwindow->refresh_frame(change_type);
3198 void MWindow::age_caches()
3200 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
3202 // preferences->cache_size,
3203 // audio_cache->get_memory_usage(1),
3204 // video_cache->get_memory_usage(1),
3205 // frame_cache->get_memory_usage(),
3206 // wave_cache->get_memory_usage(),
3208 frame_cache->age_cache(512);
3209 wave_cache->age_cache(8192);
3211 int64_t memory_usage;
3212 int64_t prev_memory_usage = 0;
3214 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
3215 while( !result && prev_memory_usage !=
3216 (memory_usage=video_cache->get_memory_usage(1)) &&
3217 memory_usage > video_size ) {
3218 video_cache->delete_oldest();
3219 prev_memory_usage = memory_usage;
3222 prev_memory_usage = 0;
3224 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
3225 while( !result && prev_memory_usage !=
3226 (memory_usage=audio_cache->get_memory_usage(1)) &&
3227 memory_usage > audio_size ) {
3228 audio_cache->delete_oldest();
3229 prev_memory_usage = memory_usage;
3233 void MWindow::reset_android_remote()
3235 gui->use_android_remote(preferences->android_remote);
3239 void MWindow::show_keyframe_gui(Plugin *plugin)
3241 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
3242 // Find existing thread
3243 for(int i = 0; i < keyframe_threads->size(); i++)
3245 if(keyframe_threads->get(i)->plugin == plugin)
3247 keyframe_threads->get(i)->start_window(plugin, 0);
3248 keyframe_gui_lock->unlock();
3253 // Find unused thread
3254 for(int i = 0; i < keyframe_threads->size(); i++)
3256 if(!keyframe_threads->get(i)->plugin)
3258 keyframe_threads->get(i)->start_window(plugin, 0);
3259 keyframe_gui_lock->unlock();
3264 // Create new thread
3265 KeyFrameThread *thread = new KeyFrameThread(this);
3266 keyframe_threads->append(thread);
3267 thread->start_window(plugin, 0);
3269 keyframe_gui_lock->unlock();
3273 void MWindow::show_plugin(Plugin *plugin)
3278 // Remove previously deleted plugin GUIs
3279 dead_plugin_lock->lock("MWindow::show_plugin");
3280 dead_plugins->remove_all_objects();
3281 dead_plugin_lock->unlock();
3283 //printf("MWindow::show_plugin %d\n", __LINE__);
3287 plugin_gui_lock->lock("MWindow::show_plugin");
3288 for(int i = 0; i < plugin_guis->total; i++)
3290 // Pointer comparison
3291 if(plugin_guis->get(i)->plugin == plugin)
3293 plugin_guis->get(i)->raise_window();
3300 //printf("MWindow::show_plugin 1\n");
3301 if( !done && !plugin->track ) {
3302 printf("MWindow::show_plugin track not defined.\n");
3306 PluginServer *server = scan_plugindb(plugin->title,
3307 plugin->track->data_type);
3309 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
3310 if(server && server->uses_gui)
3312 PluginServer *gui = new PluginServer(*server);
3313 plugin_guis->append(gui);
3314 // Needs mwindow to do GUI
3315 gui->set_mwindow(this);
3316 gui->open_plugin(0, preferences, edl, plugin);
3321 plugin_gui_lock->unlock();
3322 // update show/gui_id
3323 sync_parameters(CHANGE_PARAMS);
3324 //printf("MWindow::show_plugin %d\n", __LINE__);
3327 //printf("MWindow::show_plugin 2\n");
3330 void MWindow::hide_plugin(Plugin *plugin, int lock)
3333 // Update the toggle
3334 gui->lock_window("MWindow::hide_plugin");
3335 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
3336 gui->unlock_window();
3338 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
3339 for(int i = 0; i < plugin_guis->total; i++)
3341 if(plugin_guis->get(i)->plugin == plugin)
3343 PluginServer *ptr = plugin_guis->get(i);
3344 plugin_guis->remove(ptr);
3345 if(lock) plugin_gui_lock->unlock();
3346 // Last command executed in client side close
3347 // Schedule for deletion
3354 if(lock) plugin_gui_lock->unlock();
3355 // update show/gui_id
3356 sync_parameters(CHANGE_PARAMS);
3359 void MWindow::delete_plugin(PluginServer *plugin)
3361 dead_plugin_lock->lock("MWindow::delete_plugin");
3362 dead_plugins->append(plugin);
3363 dead_plugin_lock->unlock();
3366 void MWindow::hide_plugins()
3368 plugin_gui_lock->lock("MWindow::hide_plugins 1");
3369 while(plugin_guis->size())
3371 PluginServer *ptr = plugin_guis->get(0);
3372 plugin_guis->remove(ptr);
3373 plugin_gui_lock->unlock();
3374 // Last command executed in client side close
3375 // Schedule for deletion
3378 plugin_gui_lock->lock("MWindow::hide_plugins 2");
3380 plugin_gui_lock->unlock();
3382 hide_keyframe_guis();
3385 void MWindow::hide_keyframe_guis()
3387 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
3388 for(int i = 0; i < keyframe_threads->size(); i++)
3390 keyframe_threads->get(i)->close_window();
3392 keyframe_gui_lock->unlock();
3395 void MWindow::hide_keyframe_gui(Plugin *plugin)
3397 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3398 for(int i = 0; i < keyframe_threads->size(); i++)
3400 if(keyframe_threads->get(i)->plugin == plugin)
3402 keyframe_threads->get(i)->close_window();
3406 keyframe_gui_lock->unlock();
3409 int MWindow::get_hash_color(Edit *edit)
3411 Indexable *idxbl = edit->asset ?
3412 (Indexable*)edit->asset : (Indexable*)edit->nested_edl;
3413 if( !idxbl ) return 0;
3414 char path[BCTEXTLEN];
3415 if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
3416 edl->session->proxy_scale == 1 ||
3417 ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
3418 strcpy(path, idxbl->path);
3419 char *cp = strrchr(path, '/');
3420 cp = !cp ? path : cp+1;
3421 uint8_t *bp = (uint8_t*)cp;
3423 while( *bp ) v += *bp++;
3424 return get_hash_color(v);
3427 int MWindow::get_hash_color(int v)
3429 int hash = 0x303030;
3430 if( v & 0x01 ) hash ^= 0x000040;
3431 if( v & 0x02 ) hash ^= 0x004000;
3432 if( v & 0x04 ) hash ^= 0x400000;
3433 if( v & 0x08 ) hash ^= 0x080000;
3434 if( v & 0x10 ) hash ^= 0x000800;
3435 if( v & 0x20 ) hash ^= 0x000008;
3436 if( v & 0x40 ) hash ^= 0x404040;
3437 if( v & 0x80 ) hash ^= 0x080808;
3441 int MWindow::get_group_color(int v)
3443 int color = 0x606060;
3444 if( v & 0x01 ) color ^= 0x000080;
3445 if( v & 0x02 ) color ^= 0x008000;
3446 if( v & 0x04 ) color ^= 0x800000;
3447 if( v & 0x08 ) color ^= 0x100000;
3448 if( v & 0x10 ) color ^= 0x001000;
3449 if( v & 0x20 ) color ^= 0x000010;
3450 if( v & 0x40 ) color ^= 0x080808;
3451 if( v & 0x80 ) color ^= 0x909090;
3455 int MWindow::get_title_color(Edit *edit)
3457 unsigned color = edit->color & 0xffffff;
3458 unsigned alpha = (~edit->color>>24) & 0xff;
3460 if( edit->group_id )
3461 color = get_group_color(edit->group_id);
3462 else if( preferences->autocolor_assets )
3463 color = get_hash_color(edit);
3468 alpha = session->title_bar_alpha*255;
3469 return color | (~alpha<<24);
3472 void MWindow::update_keyframe_guis()
3474 // Send new configuration to keyframe GUI's
3475 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3476 for(int i = 0; i < keyframe_threads->size(); i++)
3478 KeyFrameThread *ptr = keyframe_threads->get(i);
3479 if(edl->tracks->plugin_exists(ptr->plugin))
3483 ptr->close_window();
3486 keyframe_gui_lock->unlock();
3489 void MWindow::update_plugin_guis(int do_keyframe_guis)
3491 // Send new configuration to plugin GUI's
3492 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3494 for(int i = 0; i < plugin_guis->size(); i++)
3496 PluginServer *ptr = plugin_guis->get(i);
3497 if(edl->tracks->plugin_exists(ptr->plugin))
3501 // Schedule for deletion if no plugin
3502 plugin_guis->remove_number(i);
3511 // Change plugin variable if not visible
3512 Track *track = edl->tracks->first;
3515 for(int i = 0; i < track->plugin_set.size(); i++)
3517 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3521 for(int i = 0; i < plugin_guis->size(); i++)
3523 PluginServer *server = plugin_guis->get(i);
3524 if(server->plugin == plugin)
3531 if(!got_it) plugin->show = 0;
3532 plugin = (Plugin*)plugin->next;
3536 track = track->next;
3539 plugin_gui_lock->unlock();
3542 if(do_keyframe_guis) update_keyframe_guis();
3545 void MWindow::stop_plugin_guis()
3547 // Send new configuration to plugin GUI's
3548 plugin_gui_lock->lock("MWindow::stop_plugin_guis");
3550 for( int i=0; i<plugin_guis->size(); ++i ) {
3551 PluginServer *ptr = plugin_guis->get(i);
3552 if( edl->tracks->plugin_exists(ptr->plugin) ) {
3556 plugin_gui_lock->unlock();
3559 int MWindow::plugin_gui_open(Plugin *plugin)
3561 int gui_id = plugin->gui_id;
3562 if( gui_id < 0 ) return 0;
3563 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3564 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3565 int result = plugin_server ? 1 : 0;
3566 plugin_gui_lock->unlock();
3571 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3573 int gui_id = plugin->gui_id;
3574 if( gui_id < 0 ) return;
3575 plugin_gui_lock->lock("MWindow::render_plugin_gui 0");
3576 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3578 plugin_server->render_gui(data);
3579 plugin_gui_lock->unlock();
3582 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3584 int gui_id = plugin->gui_id;
3585 if( gui_id < 0 ) return;
3586 plugin_gui_lock->lock("MWindow::render_plugin_gui 1");
3587 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3589 plugin_server->render_gui(data, size);
3590 plugin_gui_lock->unlock();
3593 void MWindow::reset_plugin_gui_frames(Plugin *plugin)
3595 int gui_id = plugin->gui_id;
3596 if( gui_id < 0 ) return;
3597 plugin_gui_lock->lock("MWindow::reset_plugin_gui_frames");
3598 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3600 plugin_server->reset_plugin_gui_frames();
3601 plugin_gui_lock->unlock();
3604 void MWindow::render_plugin_gui_frames(PluginClientFrames *frames, Plugin *plugin)
3606 int gui_id = plugin->gui_id;
3607 if( gui_id < 0 ) return;
3608 plugin_gui_lock->lock("MWindow::render_plugin_gui_frames");
3609 PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
3611 plugin_server->render_plugin_gui_frames(frames);
3612 plugin_gui_lock->unlock();
3615 double MWindow::get_tracking_position()
3617 return edl->local_session->get_selectionstart(1);
3620 int MWindow::get_tracking_direction()
3622 return cwindow->playback_engine->get_direction();
3625 void MWindow::update_plugin_states()
3627 plugin_gui_lock->lock("MWindow::update_plugin_states");
3628 for(int i = 0; i < plugin_guis->total; i++)
3632 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3633 PluginServer *src_plugingui = plugin_guis->get(i);
3635 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3636 for(Track *track = edl->tracks->first;
3638 track = track->next)
3641 j < track->plugin_set.total && !result;
3644 PluginSet *plugin_set = track->plugin_set[j];
3645 for(Plugin *plugin = (Plugin*)plugin_set->first;
3647 plugin = (Plugin*)plugin->next)
3649 if(plugin == src_plugin &&
3650 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3656 // Doesn't exist anymore
3659 hide_plugin(src_plugin, 0);
3663 plugin_gui_lock->unlock();
3667 void MWindow::update_plugin_titles()
3669 for(int i = 0; i < plugin_guis->total; i++)
3671 plugin_guis->get(i)->update_title();
3675 int MWindow::asset_to_edl(EDL *new_edl,
3677 RecordLabels *labels)
3679 const int debug = 0;
3680 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3683 // Keep frame rate, sample rate, and output size unchanged.
3684 // These parameters would revert the project if VWindow displayed an asset
3685 // of different size than the project.
3686 if(new_asset->video_data)
3688 new_edl->session->video_tracks = new_asset->layers;
3691 new_edl->session->video_tracks = 0;
3693 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3699 if(new_asset->audio_data)
3701 new_edl->session->audio_tracks = new_asset->channels;
3704 new_edl->session->audio_tracks = 0;
3705 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3707 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3708 new_edl->create_default_tracks();
3709 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3710 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3714 //printf("MWindow::asset_to_edl 3\n");
3715 new_edl->insert_asset(new_asset,
3720 //printf("MWindow::asset_to_edl 3\n");
3721 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3723 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3724 if(edl->session->cursor_on_frames)
3726 double length = new_edl->tracks->total_length();
3727 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3728 new_edl->tracks->clear(length, edl_length, 1, 1);
3734 char string[BCTEXTLEN];
3736 fs.extract_name(string, new_asset->path);
3737 //printf("MWindow::asset_to_edl 3\n");
3739 strcpy(new_edl->local_session->clip_title, string);
3740 //printf("MWindow::asset_to_edl 4 %s\n", string);
3741 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3743 new_edl->local_session->asset2edl = 1;
3748 // Reset everything after a load.
3749 void MWindow::update_project(int load_mode)
3751 const int debug = 0;
3753 if(debug) PRINT_TRACE
3754 edl->tracks->update_y_pixels(theme);
3755 session->update_clip_number();
3757 if(debug) PRINT_TRACE
3759 if( load_mode == LOADMODE_REPLACE ||
3760 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3761 delete gui->keyvalue_popup;
3762 gui->keyvalue_popup = 0;
3766 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 1);
3767 if(debug) PRINT_TRACE
3768 gui->unlock_window();
3771 cwindow->update(0, 0, 1, 1, 1);
3773 if(debug) PRINT_TRACE
3775 // Close all the vwindows
3776 if( load_mode == LOADMODE_REPLACE ||
3777 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3778 if(debug) PRINT_TRACE
3779 int first_vwindow = 0;
3780 if(session->show_vwindow) first_vwindow = 1;
3781 // Change visible windows to no source
3782 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3783 VWindow *vwindow = vwindows[i];
3784 if( !vwindow->is_running() ) continue;
3785 vwindow->change_source(-1);
3788 // Close remaining windows
3789 for(int i = first_vwindow; i < vwindows.size(); i++) {
3790 VWindow *vwindow = vwindows[i];
3791 if( !vwindow->is_running() ) continue;
3792 vwindow->close_window();
3794 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3795 VWindow *vwindow = get_viewer(1, -1);
3796 vwindow->change_source(i);
3798 if(debug) PRINT_TRACE
3802 for( int i=0; i<edl->mixers.size(); ++i ) {
3803 Mixer *mixer = edl->mixers[i];
3804 ZWindow *zwindow = get_mixer(mixer);
3805 zwindow->set_title(mixer->title);
3808 cwindow->gui->canvas->set_zoom(edl, 0);
3812 if(debug) PRINT_TRACE
3813 cwindow->gui->lock_window("MWindow::update_project 2");
3814 cwindow->gui->timebar->update(0);
3815 Track *track = cwindow->calculate_affected_track();
3816 cwindow->mask_track_id = track ? track->get_id() : -1;
3817 cwindow->gui->tool_panel->raise_tool();
3818 cwindow->gui->update_canvas(0);
3819 cwindow->gui->unlock_window();
3821 if(debug) PRINT_TRACE
3822 cwindow->refresh_frame(CHANGE_ALL);
3824 awindow->gui->async_update_assets();
3825 if(debug) PRINT_TRACE
3827 gui->lock_window("MWindow::update_project");
3828 gui->update_mixers(0, 0);
3830 if(debug) PRINT_TRACE
3833 void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
3835 int got_indexes = 0;
3836 for( int i=0; i<new_edl->nested_edls.size(); ++i ) {
3837 EDL *nested_edl = new_edl->nested_edls[i];
3838 mainindexes->add_indexable(nested_edl);
3839 edl->nested_edls.update_index(nested_edl);
3842 for( Asset *asset=new_edl->assets->first; asset; asset=asset->next ) {
3843 mainindexes->add_indexable(asset);
3844 edl->assets->update(asset);
3847 // Start examining next batch of index files
3849 mainindexes->start_build();
3852 gui->lock_window("MWindow::stack_push");
3853 if( stack.size() < 9 ) {
3856 StackItem &item = stack.append();
3858 item.new_edl = new_edl;
3862 if( idxbl && idxbl->is_asset ) {
3864 Asset *asset = (Asset *)idxbl;
3865 if( asset->format == FILE_REF &&
3866 !stat(asset->path, &st) )
3867 item.mtime = st.st_mtime;
3871 strcpy(session->filename, edl->path);
3872 undo = new MainUndo(this);
3873 gui->stack_button->update();
3874 update_project(LOADMODE_REPLACE);
3876 gui->unlock_window();
3879 void MWindow::stack_pop()
3881 if( !stack.size() ) return;
3882 // writes on config_path/backup%d.xml
3884 // already have gui lock
3885 StackItem &item = stack.last();
3886 // session edl replaced, overwrite and save clip data
3887 if( item.new_edl != edl )
3888 item.new_edl->overwrite_clip(edl);
3893 Indexable *idxbl = item.idxbl;
3894 int64_t mtime = item.mtime;
3897 gui->unlock_window();
3898 remove_from_caches(idxbl);
3899 remove_indexfile(idxbl);
3900 mainindexes->add_indexable(idxbl);
3901 mainindexes->start_build();
3902 awindow->gui->async_update_assets();
3903 gui->lock_window("MWindow::stack_pop");
3905 strcpy(session->filename, edl->path);
3906 update_project(LOADMODE_REPLACE);
3907 undo_after(_("open edl"), LOAD_ALL);
3908 gui->stack_button->update();
3909 if( mtime && idxbl && idxbl->is_asset ) {
3911 Asset *asset = (Asset *)idxbl;
3912 if( asset->format == FILE_REF && !stat(asset->path, &st) &&
3913 item.mtime == st.st_mtime ) {
3914 char text[BCTEXTLEN];
3915 snprintf(text, sizeof(text),
3916 _("Warning: Asset not updated: %s"), asset->path);
3917 show_warning(&preferences->warn_stack, text);
3922 void MWindow::clip_to_media()
3924 if( edl->session->proxy_scale != 1 ) {
3925 eprintf("Nesting not allowed when proxy scale != 1");
3929 int clips_total = session->drag_clips->total;
3930 for( int i=0; i<clips_total; ++i ) {
3931 EDL *clip = session->drag_clips->values[i];
3932 time_t dt; time(&dt);
3933 struct tm dtm; localtime_r(&dt, &dtm);
3934 char path[BCTEXTLEN], *cp = path, *ep = cp+sizeof(path)-1;
3935 // path_basename = "Nested_<date>-<time>_<basename>"
3936 cp += snprintf(cp, ep-cp, _("Nested_%02d%02d%02d-%02d%02d%02d_"),
3937 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
3938 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
3939 char *bp = strrchr(clip->local_session->clip_title, '/');
3940 bp = bp ? bp+1 : clip->local_session->clip_title;
3941 cp += snprintf(cp, ep-cp, "%s", bp);
3942 EDL *nested = edl->new_nested_edl(clip, path);
3943 edl->clips.remove(clip);
3944 clip->remove_user();
3945 mainindexes->add_indexable(nested);
3947 undo_after(_("clip2media"), LOAD_ALL);
3948 mainindexes->start_build();
3949 awindow->gui->async_update_assets();
3952 void MWindow::media_to_clip()
3955 int assets_total = session->drag_assets->total;
3956 for( int i=0; i<assets_total; ++i ) {
3957 Indexable *idxbl = session->drag_assets->values[i];
3958 if( idxbl->is_asset ) {
3959 eprintf(_("media is not EDL:\n%s"), idxbl->path);
3962 char clip_title[BCSTRLEN];
3966 sprintf(clip_title, _("Clip %d"), session->clip_number++);
3967 for( int i=0; name_ok && i<edl->clips.size(); ++i ) {
3968 char *title = edl->clips[i]->local_session->clip_title;
3969 if( !strcasecmp(clip_title, title) ) name_ok = 0;
3972 EDL *nested = (EDL *)idxbl;
3973 EDL *clip = edl->add_clip(nested);
3974 strcpy(clip->local_session->clip_title, clip_title);
3975 snprintf(clip->local_session->clip_notes,
3976 sizeof(clip->local_session->clip_notes),
3977 _("From: %s"), nested->path);
3979 undo_after(_("media2clip"), LOAD_ALL);
3980 awindow->gui->async_update_assets();
3983 int MWindow::create_ref(Asset *asset, EDL *ref)
3985 asset->format = FILE_REF;
3986 double secs = ref->tracks->total_length();
3987 int audio_channels = ref->session->audio_channels;
3988 asset->audio_data = audio_channels > 0 ? 1 : 0;
3989 asset->channels = audio_channels;
3990 asset->sample_rate = ref->session->sample_rate;
3991 asset->audio_length = audio_channels > 0 && secs > 0 ?
3992 secs * asset->sample_rate : 0;
3993 strcpy(asset->acodec, _("reference"));
3995 int video_layers = ref->session->video_channels;
3996 asset->video_data = video_layers > 0 ? 1 : 0;
3997 asset->layers = video_layers > 0 ? 1 : 0;
3998 asset->actual_width = ref->session->output_w;
3999 asset->actual_height = ref->session->output_h;
4000 asset->width = asset->actual_width;
4001 asset->height = asset->actual_height;
4002 asset->frame_rate = ref->session->frame_rate;
4003 asset->video_length = video_layers > 0 && secs > 0 ?
4004 secs * asset->frame_rate : 0;
4005 strcpy(asset->vcodec, _("reference"));
4009 void MWindow::update_preferences(Preferences *prefs)
4011 if( prefs != preferences )
4012 preferences->copy_from(prefs);
4013 if( cwindow->playback_engine )
4014 cwindow->playback_engine->preferences->copy_from(prefs);
4015 for(int i = 0; i < vwindows.size(); i++) {
4016 VWindow *vwindow = vwindows[i];
4017 if( !vwindow->is_running() ) continue;
4018 if( vwindow->playback_engine )
4019 vwindow->playback_engine->preferences->copy_from(prefs);
4021 for(int i = 0; i < zwindows.size(); i++) {
4022 ZWindow *zwindow = zwindows[i];
4023 if( !zwindow->is_running() ) continue;
4024 if( zwindow->zgui->playback_engine )
4025 zwindow->zgui->playback_engine->preferences->copy_from(prefs);
4029 void MWindow::update_vwindow()
4031 for( int i=0; i<vwindows.size(); ++i ) {
4032 VWindow *vwindow = vwindows[i];
4033 if( vwindow->is_running() ) {
4034 vwindow->gui->lock_window("MWindow::update_vwindow");
4036 vwindow->gui->unlock_window();
4041 void MWindow::remove_indexfile(Indexable *indexable)
4043 if( !indexable->is_asset ) return;
4044 Asset *asset = (Asset *)indexable;
4046 IndexFile::delete_index(preferences, asset, ".toc");
4047 IndexFile::delete_index(preferences, asset, ".idx");
4048 IndexFile::delete_index(preferences, asset, ".mkr");
4051 void MWindow::rebuild_indices()
4053 for(int i = 0; i < session->drag_assets->total; i++)
4055 Indexable *indexable = session->drag_assets->get(i);
4056 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4057 remove_indexfile(indexable);
4058 // Schedule index build
4059 indexable->index_state->remove_user();
4060 indexable->index_state = new IndexState;
4061 IndexFile::delete_index_files(preferences, indexable);
4062 if( indexable->is_asset ) {
4063 Asset *asset = (Asset *)indexable;
4064 if( asset->format != FILE_PCM ) {
4065 asset->format = FILE_UNKNOWN;
4066 asset->reset_audio();
4068 asset->reset_video();
4069 remove_from_caches(asset);
4070 // File file; // re-probe the asset
4071 // file.open_file(preferences, asset, 1, 0);
4073 mainindexes->add_indexable(indexable);
4075 // still in render engine
4076 sync_parameters(CHANGE_ALL);
4077 awindow->gui->async_update_assets();
4078 mainindexes->start_build();
4082 void MWindow::get_backup_path(char *path, int len)
4084 char *cp = path, *ep = cp + len-1;
4085 cp += snprintf(cp, ep-cp, "%s/", File::get_config_path());
4086 int idx = stack.size();
4087 cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx);
4090 void MWindow::save_backup()
4094 edl->set_path(session->filename);
4096 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
4097 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
4098 File::get_config_path(), BACKUP_FILE1);
4099 get_backup_path(backup_path, sizeof(backup_path));
4100 rename(backup_path, backup_path1);
4101 edl->save_xml(&file, backup_path);
4102 file.terminate_string();
4104 fs.complete_path(backup_path);
4106 if(file.write_to_file(backup_path)) {
4108 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
4109 gui->show_message(string2);
4113 void MWindow::load_backup()
4115 ArrayList<char*> path_list;
4116 path_list.set_array_delete();
4118 char backup_path[BCTEXTLEN];
4119 get_backup_path(backup_path, sizeof(backup_path));
4121 fs.complete_path(backup_path);
4123 path_list.append(out_path = new char[strlen(backup_path) + 1]);
4124 strcpy(out_path, backup_path);
4126 load_filenames(&path_list, LOADMODE_REPLACE, LOADMODE_EDL_CLIP, 0);
4127 edl->local_session->clip_title[0] = 0;
4128 // This is unique to backups since the path of the backup is different than the
4129 // path of the project.
4130 set_filename(edl->path);
4131 path_list.remove_all_objects();
4136 void MWindow::save_undo_data()
4139 undo_after(_("perpetual session"), LOAD_ALL);
4140 char perpetual_path[BCTEXTLEN];
4141 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4142 File::get_config_path(), PERPETUAL_FILE);
4143 FILE *fp = fopen(perpetual_path,"w");
4149 void MWindow::load_undo_data()
4151 char perpetual_path[BCTEXTLEN];
4152 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
4153 File::get_config_path(), PERPETUAL_FILE);
4154 FILE *fp = fopen(perpetual_path,"r");
4161 int MWindow::copy_target(const char *path, const char *target)
4163 int ifd = ::open(path, O_RDONLY);
4165 eprintf("Cannot open asset: %s", path);
4169 int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
4172 int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
4173 char progress_title[BCTEXTLEN];
4174 sprintf(progress_title, _("Copying: %s\n"), target);
4175 BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
4177 int64_t count = 0, len = -1;
4178 int bfrsz = 0x100000;
4179 uint8_t *bfr = new uint8_t[bfrsz];
4180 while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
4181 if( len != ::write(ofd, bfr, len) ) {
4182 eprintf("Error writing: %s", target);
4185 if( progress.is_cancelled() ) {
4189 progress.update(count += len, 1);
4194 progress.stop_progress();
4196 eprintf("Error reading: %s", path);
4201 eprintf("Cannot create asset target: %s", target);
4206 int MWindow::link_target(const char *real_path, const char *link_path, int relative)
4208 char target[BCTEXTLEN];
4210 const char *bp = real_path, *cp = bp;
4211 const char *lp = link_path, *np = lp;
4212 char *tp = target, *ep = tp+sizeof(target)-1, lch;
4213 while( *lp && *bp && (lch=*lp++) == *bp++ ) {
4214 if( lch == '/' ) { np = lp; cp = bp; }
4216 while( tp<ep && *np ) {
4217 if( *np++ != '/' ) continue;
4218 *tp++ = '.'; *tp++ = '.'; *tp++ = '/';
4220 while( tp<ep && *cp ) *tp++ = *cp++;
4224 strcpy(target, real_path);
4225 if( symlink(target, link_path) ) {
4226 eprintf("Cannot create symlink: %s", link_path);
4232 void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
4234 char dir_path[BCTEXTLEN];
4235 strcpy(dir_path, dir);
4237 fs.complete_path(dir_path);
4240 if( !stat(dir_path, &st) ) {
4241 if( !S_ISDIR(st.st_mode) ) {
4242 eprintf("Path exists and is not a directory\n%s", dir_path);
4247 if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
4248 eprintf("Cannot create directory\n%s", dir_path);
4252 char *real_dir = realpath(dir_path, 0);
4253 strcpy(dir_path, real_dir);
4256 EDL *save_edl = new EDL;
4257 save_edl->create_objects();
4258 save_edl->copy_all(edl);
4260 char progress_title[BCTEXTLEN];
4261 sprintf(progress_title, _("Saving to %s:\n"), dir);
4262 int total_assets = save_edl->assets->total();
4263 MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
4265 Asset *current = save_edl->assets->first;
4266 for( int i=0; !ret && current; ++i, current=NEXT ) {
4267 char *path = current->path;
4268 if( ::stat(path, &st) ) {
4269 eprintf("Asset not found: %s", path);
4272 char *real_path = realpath(path, 0);
4273 const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
4274 char link_path[BCTEXTLEN];
4275 snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
4277 if( strcmp(real_path, link_path) ) {
4278 if( !::lstat(link_path, &st) ) {
4280 ::remove(link_path);
4286 eprintf("copy/link to self, skippped: %s", path);
4290 if( save_mode == SAVE_PROJECT_COPY ) {
4291 if( copy_target(real_path, link_path) )
4295 link_target(real_path, link_path,
4296 save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
4300 strcpy(path, link_path);
4302 if( progress->is_cancelled() ) break;
4303 progress->update(i);
4306 progress->stop_progress();
4309 char *cp = strrchr(dir_path,'/');
4310 char *bp = cp ? cp+1 : dir_path;
4311 char filename[BCTEXTLEN];
4312 snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
4313 save_edl->set_path(filename);
4315 save_edl->save_xml(&file, filename);
4316 file.terminate_string();
4318 if( !file.write_to_file(filename) ) {
4319 char string[BCTEXTLEN];
4320 sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
4321 gui->lock_window("SaveProject::run 2");
4322 gui->show_message(string);
4323 gui->unlock_window();
4324 gui->mainmenu->add_load(filename);
4327 eprintf(_("Couldn't open %s."), filename);
4329 save_edl->remove_user();
4332 gui->lock_window("MWindow::save_project");
4333 ArrayList<char*> filenames;
4334 filenames.append(filename);
4335 load_filenames(&filenames);
4336 gui->unlock_window();
4341 static inline int gcd(int m, int n)
4344 if( m < n ) { r = m; m = n; n = r; }
4345 while( (r = m % n) != 0 ) { m = n; n = r; }
4349 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
4352 if(!width || !height) return 1;
4353 if( width == 720 && (height == 480 || height == 576) ) {
4354 w = 4; h = 3; return 0; // for NTSC and PAL
4356 double ar = (double)width / height;
4357 // square-ish pixels
4358 if( EQUIV(ar, 1.0000) ) return 0;
4359 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
4360 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
4361 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
4362 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
4363 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
4364 int ww = width, hh = height;
4365 // numerator, denominator must be under mx
4366 int mx = 255, n = gcd(ww, hh);
4367 if( n > 1 ) { ww /= n; hh /= n; }
4368 // search near height in case extra/missing lines
4369 if( ww >= mx || hh >= mx ) {
4370 double err = height; // +/- 2 percent height
4371 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
4372 int iw = width, ih = height+i;
4373 if( (n=gcd(iw, ih)) > 1 ) {
4374 int u = iw/n; if( u >= mx ) continue;
4375 int v = ih/n; if( v >= mx ) continue;
4376 double r = (double) u/v, er = fabs(ar-r);
4377 if( er >= err ) continue;
4378 err = er; ww = u; hh = v;
4387 void MWindow::reset_caches()
4389 frame_cache->remove_all();
4390 wave_cache->remove_all();
4391 audio_cache->remove_all();
4392 video_cache->remove_all();
4393 if( cwindow->playback_engine ) {
4394 if( cwindow->playback_engine->audio_cache )
4395 cwindow->playback_engine->audio_cache->remove_all();
4396 if( cwindow->playback_engine->video_cache )
4397 cwindow->playback_engine->video_cache->remove_all();
4399 for(int i = 0; i < vwindows.size(); i++) {
4400 VWindow *vwindow = vwindows[i];
4401 if( !vwindow->is_running() ) continue;
4402 if( !vwindow->playback_engine ) continue;
4403 if( vwindow->playback_engine->audio_cache )
4404 vwindow->playback_engine->audio_cache->remove_all();
4405 if( vwindow->playback_engine->video_cache )
4406 vwindow->playback_engine->video_cache->remove_all();
4410 void MWindow::remove_from_caches(Indexable *idxbl)
4412 frame_cache->remove_item(idxbl);
4413 wave_cache->remove_item(idxbl);
4414 if( gui->render_engine &&
4415 gui->render_engine_id == idxbl->id ) {
4416 delete gui->render_engine;
4417 gui->render_engine = 0;
4419 if( gui->resource_thread->render_engine_id == idxbl->id ) {
4420 gui->resource_thread->render_engine_id = -1;
4421 delete gui->resource_thread->render_engine;
4422 gui->resource_thread->render_engine = 0;
4424 if( !idxbl->is_asset ) return;
4425 Asset *asset = (Asset *)idxbl;
4426 audio_cache->delete_entry(asset);
4427 video_cache->delete_entry(asset);
4428 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
4429 cwindow->playback_engine->audio_cache->delete_entry(asset);
4430 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
4431 cwindow->playback_engine->video_cache->delete_entry(asset);
4432 for(int i = 0; i < vwindows.size(); i++) {
4433 VWindow *vwindow = vwindows[i];
4434 if( !vwindow->is_running() ) continue;
4435 if( !vwindow->playback_engine ) continue;
4436 if( vwindow->playback_engine->audio_cache )
4437 vwindow->playback_engine->audio_cache->delete_entry(asset);
4438 if( vwindow->playback_engine->video_cache )
4439 vwindow->playback_engine->video_cache->delete_entry(asset);
4441 for(int i = 0; i < zwindows.size(); i++) {
4442 ZWindow *zwindow = zwindows[i];
4443 if( !zwindow->is_running() ) continue;
4444 if( zwindow->zgui->playback_engine->audio_cache )
4445 zwindow->zgui->playback_engine->audio_cache->delete_entry(asset);
4446 if( zwindow->zgui->playback_engine->video_cache )
4447 zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
4451 void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
4452 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
4454 awindow->gui->close_view_popup();
4456 // Remove from VWindow.
4458 for(int i = 0; i < drag_clips->total; i++) {
4459 for(int j = 0; j < vwindows.size(); j++) {
4460 VWindow *vwindow = vwindows[j];
4461 if( !vwindow->is_running() ) continue;
4462 if(drag_clips->get(i) == vwindow->get_edl()) {
4463 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
4464 vwindow->delete_source(1, 1);
4465 vwindow->gui->unlock_window();
4472 for(int i = 0; i < drag_assets->size(); i++) {
4473 for(int j = 0; j < vwindows.size(); j++) {
4474 VWindow *vwindow = vwindows[j];
4475 if( !vwindow->is_running() ) continue;
4476 if(drag_assets->get(i) == vwindow->get_source()) {
4477 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
4478 vwindow->delete_source(1, 1);
4479 vwindow->gui->unlock_window();
4484 for(int i = 0; i < drag_assets->total; i++) {
4485 Indexable *indexable = drag_assets->get(i);
4486 if(indexable->is_asset) remove_from_caches(indexable);
4489 if( delete_indexes ) {
4490 for(int i = 0; i < drag_assets->size(); i++) {
4491 Indexable *indexable = drag_assets->get(i);
4492 remove_indexfile(indexable);
4497 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
4498 if(push_undo) undo_before();
4499 if(drag_assets) edl->remove_from_project(drag_assets);
4500 if(drag_clips) edl->remove_from_project(drag_clips);
4501 if(redraw) save_backup();
4502 if(push_undo) undo_after(_("remove assets"), LOAD_ALL);
4506 gui->lock_window("MWindow::remove_assets_from_project 3");
4507 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
4508 gui->unlock_window();
4510 // Removes from playback here
4511 sync_parameters(CHANGE_ALL);
4514 awindow->gui->async_update_assets();
4517 void MWindow::remove_assets_from_disk()
4519 remove_assets_from_project(1, 1, 1,
4520 session->drag_assets, session->drag_clips);
4523 for(int i = 0; i < session->drag_assets->total; i++)
4525 remove(session->drag_assets->get(i)->path);
4529 void MWindow::dump_plugins(FILE *fp)
4531 if( !plugindb ) return;
4532 for(int i = 0; i < plugindb->total; i++)
4534 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
4535 " synth=%d transition=%d theme=%d %s\n",
4536 plugindb->get(i)->plugin_type,
4537 plugindb->get(i)->audio,
4538 plugindb->get(i)->video,
4539 plugindb->get(i)->realtime,
4540 plugindb->get(i)->multichannel,
4541 plugindb->get(i)->get_synthesis(),
4542 plugindb->get(i)->transition,
4543 plugindb->get(i)->theme,
4544 plugindb->get(i)->title);
4548 void MWindow::dump_edl(FILE *fp)
4554 void MWindow::dump_undo(FILE *fp)
4560 void MWindow::dump_exe(FILE *fp)
4562 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
4563 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
4565 int ret = -1, n = 100;
4566 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
4567 exe_path[len] = 0; strcpy(proc_path, exe_path);
4570 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
4573 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
4574 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
4575 struct tm *tm = localtime(&st.st_mtime);
4577 strftime(mtime, sizeof(mtime), "%F %T", tm);
4578 fprintf(fp,"mtime: %s\n", mtime);
4580 // people hit ctl-c waiting for this
4581 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
4582 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
4585 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
4586 int64_t maxsz = 1024*pagsz;
4587 int64_t size = st.st_size, pos = 0;
4589 while( (bfrsz = size-pos) > 0 ) {
4590 if( bfrsz > maxsz ) bfrsz = maxsz;
4591 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
4592 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
4593 if( bfr == MAP_FAILED ) break;
4594 sha1.addBytes(bfr, bfrsz);
4599 ret = pos < size ? EIO : 0;
4600 fprintf(fp, "SHA1: ");
4601 uint8_t digest[20]; sha1.computeHash(digest);
4602 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
4603 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
4604 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
4609 void MWindow::trap_hook(FILE *fp, void *vp)
4611 MWindow *mwindow = (MWindow *)vp;
4612 // fprintf(fp, "\nPLUGINS:\n");
4613 // mwindow->dump_plugins(fp);
4614 fprintf(fp, "\nEDL:\n");
4615 mwindow->dump_edl(fp);
4616 fprintf(fp, "\nUNDO:\n");
4617 mwindow->dump_undo(fp);
4618 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
4619 mwindow->dump_exe(fp);
4627 int MWindow::save_defaults()
4629 gui->save_defaults(defaults);
4630 edl->save_defaults(defaults);
4631 session->save_defaults(defaults);
4632 preferences->save_defaults(defaults);
4634 for(int i = 0; i < plugin_guis->total; i++)
4636 // Pointer comparison
4637 plugin_guis->get(i)->save_defaults();
4639 awindow->save_defaults(defaults);
4645 int MWindow::run_script(FileXML *script)
4647 int result = 0, result2 = 0;
4648 while(!result && !result2)
4650 result = script->read_tag();
4653 if(script->tag.title_is("new_project"))
4655 // Run new in immediate mode.
4656 // gui->mainmenu->new_project->run_script(script);
4659 if(script->tag.title_is("record"))
4661 // Run record as a thread. It is a terminal command.
4663 // Will read the complete scipt file without letting record read it if not
4669 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
4676 // ================================= synchronization
4679 int MWindow::interrupt_indexes()
4681 mainprogress->cancelled = 1;
4682 mainindexes->interrupt_build();
4688 void MWindow::next_time_format()
4690 switch(edl->session->time_format)
4692 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
4693 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
4694 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4695 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
4696 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
4697 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
4698 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
4701 time_format_common();
4704 void MWindow::prev_time_format()
4706 switch(edl->session->time_format)
4708 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
4709 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
4710 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
4711 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
4712 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
4713 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
4714 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
4717 time_format_common();
4720 void MWindow::time_format_common()
4722 gui->lock_window("MWindow::next_time_format");
4723 gui->redraw_time_dependancies();
4726 char string[BCTEXTLEN], string2[BCTEXTLEN];
4727 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
4728 gui->show_message(string);
4730 gui->unlock_window();
4734 int MWindow::set_filename(const char *filename)
4736 if( filename != session->filename )
4737 strcpy(session->filename, filename);
4738 if( filename != edl->path )
4739 strcpy(edl->path, filename);
4743 if(filename[0] == 0)
4745 gui->set_title(PROGRAM_NAME);
4750 char string[BCTEXTLEN], string2[BCTEXTLEN];
4751 dir.extract_name(string, filename);
4752 sprintf(string2, PROGRAM_NAME ": %s", string);
4753 gui->set_title(string2);
4766 int MWindow::set_loop_boundaries()
4768 double start = edl->local_session->get_selectionstart();
4769 double end = edl->local_session->get_selectionend();
4777 if(edl->tracks->total_length())
4780 end = edl->tracks->total_length();
4787 if(edl->local_session->loop_playback && start != end)
4789 edl->local_session->loop_start = start;
4790 edl->local_session->loop_end = end;
4801 int MWindow::reset_meters()
4803 cwindow->gui->lock_window("MWindow::reset_meters 1");
4804 cwindow->gui->meters->reset_meters();
4805 cwindow->gui->unlock_window();
4807 for(int j = 0; j < vwindows.size(); j++) {
4808 VWindow *vwindow = vwindows[j];
4809 if( !vwindow->is_running() ) continue;
4810 vwindow->gui->lock_window("MWindow::reset_meters 2");
4811 vwindow->gui->meters->reset_meters();
4812 vwindow->gui->unlock_window();
4815 lwindow->gui->lock_window("MWindow::reset_meters 3");
4816 lwindow->gui->panel->reset_meters();
4817 lwindow->gui->unlock_window();
4819 gui->lock_window("MWindow::reset_meters 4");
4820 gui->reset_meters();
4821 gui->unlock_window();
4826 void MWindow::resync_guis()
4830 gui->lock_window("MWindow::resync_guis");
4831 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
4832 gui->unlock_window();
4834 cwindow->gui->lock_window("MWindow::resync_guis");
4835 cwindow->gui->resize_event(cwindow->gui->get_w(),
4836 cwindow->gui->get_h());
4837 int channels = edl->session->audio_channels;
4838 cwindow->gui->meters->set_meters(channels, 1);
4839 cwindow->gui->flush();
4840 cwindow->gui->unlock_window();
4842 for(int i = 0; i < vwindows.size(); i++) {
4843 VWindow *vwindow = vwindows[i];
4844 if( !vwindow->is_running() ) continue;
4845 vwindow->gui->lock_window("MWindow::resync_guis");
4846 vwindow->gui->resize_event(vwindow->gui->get_w(),
4847 vwindow->gui->get_h());
4848 vwindow->gui->meters->set_meters(channels, 1);
4849 vwindow->gui->flush();
4850 vwindow->gui->unlock_window();
4853 lwindow->gui->lock_window("MWindow::resync_guis");
4854 lwindow->gui->panel->set_meters(channels, 1);
4855 lwindow->gui->flush();
4856 lwindow->gui->unlock_window();
4859 if(((edl->session->output_w % 4) ||
4860 (edl->session->output_h % 4)) &&
4861 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
4863 MainError::show_error(
4864 _("This project's dimensions are not multiples of 4 so\n"
4865 "it can't be rendered by OpenGL."));
4870 sync_parameters(CHANGE_ALL);
4873 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
4875 File *file = new File;
4876 EDLSession *session = edl->session;
4877 double old_framerate = session->frame_rate;
4878 double old_samplerate = session->sample_rate;
4879 int old_auto_keyframes = session->auto_keyframes;
4880 session->auto_keyframes = 0;
4881 int result = file->open_file(preferences, asset, 1, 0);
4882 if( !result && delete_tracks > 0 )
4884 int video_layers = asset->get_video_layers();
4885 if( !result && asset->video_data && vstream < video_layers ) {
4886 // try to get asset up to date, may fail
4887 file->select_video_stream(asset, vstream);
4888 // either way use what was/is there.
4889 double framerate = asset->get_frame_rate();
4890 int width = asset->get_w();
4891 int height = asset->get_h();
4893 // must be multiple of 4 for opengl
4894 width = (width+3) & ~3; height = (height+3) & ~3;
4896 int driver = session->playback_config->vconfig->driver;
4897 int color_model = file->get_best_colormodel(asset, driver);
4898 // color_model = BC_CModels::is_yuv(color_model) ?
4899 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
4900 // BC_CModels::is_float(color_model) ?
4901 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
4902 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
4903 // have alpha for now
4904 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
4905 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
4906 session->color_model = color_model;
4907 session->output_w = width;
4908 session->output_h = height;
4909 session->frame_rate = framerate;
4910 // not, asset->actual_width/actual_height
4911 asset->width = session->output_w;
4912 asset->height = session->output_h;
4913 asset->frame_rate = session->frame_rate;
4914 create_aspect_ratio(session->aspect_w, session->aspect_h,
4915 session->output_w, session->output_h);
4916 Track *track = edl->tracks->first;
4917 for( Track *next_track=0; track; track=next_track ) {
4918 next_track = track->next;
4919 if( track->data_type != TRACK_VIDEO ) continue;
4920 if( delete_tracks ) {
4921 Edit *edit = track->edits->first;
4922 for( Edit *next_edit=0; edit; edit=next_edit ) {
4923 next_edit = edit->next;
4924 if( edit->channel != vstream ||
4925 !edit->asset || !edit->asset->is_asset ||
4926 !asset->equivalent(*edit->asset,1,1,edl) )
4930 if( track->edits->first ) {
4931 track->track_w = edl->session->output_w;
4932 track->track_h = edl->session->output_h;
4934 else if( delete_tracks )
4935 edl->tracks->delete_track(track);
4938 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4940 if( !result && asset->audio_data && asset->channels > 0 ) {
4941 session->sample_rate = asset->get_sample_rate();
4942 int64_t channel_mask = 0;
4943 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4944 file->get_audio_for_video(vstream, astream, channel_mask);
4945 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4946 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4948 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4949 if( channels < 1 ) channels = 1;
4950 if( channels > 6 ) channels = 6;
4951 session->audio_tracks = session->audio_channels = channels;
4953 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4954 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4955 remap_audio(MWindow::AUDIO_1_TO_1);
4957 if( delete_tracks ) {
4958 Track *track = edl->tracks->first;
4959 for( Track *next_track=0; track; track=next_track ) {
4960 next_track = track->next;
4961 if( track->data_type != TRACK_AUDIO ) continue;
4962 Edit *edit = track->edits->first;
4963 for( Edit *next_edit=0; edit; edit=next_edit ) {
4964 next_edit = edit->next;
4965 if( !((1<<edit->channel) & channel_mask) ||
4966 !edit->asset || !edit->asset->is_asset ||
4967 !asset->equivalent(*edit->asset,1,1,edl) )
4970 if( !track->edits->first )
4971 edl->tracks->delete_track(track);
4975 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4978 session->auto_keyframes = old_auto_keyframes;
4979 if( !result && delete_tracks > 0 ) {
4981 undo_after(_("select asset"), LOAD_ALL);
4987 int MWindow::select_asset(int vtrack, int delete_tracks)
4989 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4991 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4992 if( !track ) return 1;
4993 Edit *edit = track->edits->first;
4994 if( !edit ) return 1;
4995 Asset *asset = edit->asset;
4996 if( !asset || !asset->is_asset ) return 1;
4997 return select_asset(asset, edit->channel, 0, delete_tracks);
5000 void MWindow::dump_plugindb(FILE *fp)
5002 if( !plugindb ) return;
5003 for(int i = 0; i < plugindb->total; i++)
5004 plugindb->get(i)->dump(fp);
5007 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
5010 double unit_position = edl->local_session->get_selectionstart(1);
5011 unit_position = patch->track->to_units(unit_position, 0);
5013 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
5014 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5017 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
5020 double unit_position = edl->local_session->get_selectionstart(1);
5021 unit_position = patch->track->to_units(unit_position, 0);
5023 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
5024 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5027 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
5030 double unit_position = edl->local_session->get_selectionstart(1);
5031 unit_position = patch->track->to_units(unit_position, 0);
5033 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
5034 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
5037 PatchGUI *MWindow::get_patchgui(Track *track)
5039 PatchGUI *patchgui = 0;
5040 TimelinePane **panes = gui->pane;
5041 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
5042 if( !panes[i] ) continue;
5043 PatchBay *patchbay = panes[i]->patchbay;
5044 if( !patchbay ) continue;
5045 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
5046 if( patchbay->patches.values[j]->track == track )
5047 patchgui = patchbay->patches.values[j];