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 "bcdisplayinfo.h"
31 #include "bcsignals.h"
38 #include "channeldb.h"
39 #include "channelinfo.h"
42 #include "bccmodels.h"
43 #include "commercials.h"
44 #include "cplayback.h"
46 #include "cwindowgui.h"
48 #include "cwindowtool.h"
50 #include "devicedvbinput.inc"
51 #include "dvdcreate.h"
52 #include "editpanel.h"
54 #include "edlsession.h"
56 #include "fileformat.h"
58 #include "filesystem.h"
60 #include "floatautos.h"
61 #include "framecache.h"
63 #include "gwindowgui.h"
64 #include "keyframegui.h"
65 #include "indexfile.h"
67 #include "interlacemodes.h"
69 #include "levelwindowgui.h"
70 #include "levelwindow.h"
71 #include "loadfile.inc"
72 #include "localsession.h"
73 #include "maincursor.h"
74 #include "mainerror.h"
75 #include "mainindexes.h"
77 #include "mainprogress.h"
78 #include "mainsession.h"
82 #include "mwindowgui.h"
87 #include "playback3d.h"
88 #include "playbackengine.h"
90 #include "pluginserver.h"
91 #include "pluginset.h"
92 #include "preferences.h"
95 #include "recordmonitor.h"
96 #include "recordlabel.h"
97 #include "removefile.h"
99 #include "resourcethread.h"
100 #include "samplescroll.h"
102 #include "sighandler.h"
103 #include "splashgui.h"
104 #include "statusbar.h"
106 #include "threadloader.h"
108 #include "timelinepane.h"
109 #include "tipwindow.h"
110 #include "trackcanvas.h"
112 #include "tracking.h"
113 #include "trackscroll.h"
115 #include "transition.h"
116 #include "transportque.h"
119 #include "versioninfo.h"
120 #include "videodevice.inc"
121 #include "videowindow.h"
122 #include "vplayback.h"
123 #include "vwindowgui.h"
125 #include "wavecache.h"
129 #include "zwindowgui.h"
130 #include "exportedl.h"
132 #include "defaultformats.h"
133 #include "ntsczones.h"
140 #include <sys/types.h>
141 #include <sys/stat.h>
142 #include <sys/time.h>
143 #include <sys/mman.h>
154 // Hack for libdv to remove glib dependancy
157 // g_log (const char *log_domain,
159 // const char *format,
165 // g_logv (const char *log_domain,
167 // const char *format,
177 ArrayList<PluginServer*>* MWindow::plugindb = 0;
178 Commercials* MWindow::commercials = 0;
184 run_lock = new Mutex("MWindow::run_lock");
185 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
186 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
187 vwindows_lock = new Mutex("MWindow::vwindows_lock");
188 zwindows_lock = new Mutex("MWindow::zwindows_lock");
189 brender_lock = new Mutex("MWindow::brender_lock");
190 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
198 commercial_active = 0;
210 strcpy(cin_lang,"en");
211 channeldb_buz = new ChannelDB;
212 channeldb_v4l2jpeg = new ChannelDB;
215 keyframe_threads = 0;
237 // Need to delete brender temporary here.
240 run_lock->lock("MWindow::~MWindow");
242 //printf("MWindow::~MWindow %d\n", __LINE__);
243 gui->remote_control->deactivate();
246 gui->channel_info->stop();
249 delete create_bd; create_bd = 0;
250 delete create_dvd; create_dvd = 0;
251 delete batch_render; batch_render = 0;
252 delete render; render = 0;
254 if( commercials && !commercials->remove_user() ) commercials = 0;
256 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
257 // Save defaults for open plugins
258 plugin_gui_lock->lock("MWindow::~MWindow");
259 for(int i = 0; i < plugin_guis->size(); i++) {
260 plugin_guis->get(i)->hide_gui();
261 delete_plugin(plugin_guis->get(i));
263 plugin_gui_lock->unlock();
264 hide_keyframe_guis();
267 // Give up and go to a movie
268 // cant run valgrind if this is used
270 gui->del_keyboard_listener(
271 (int (BC_WindowBase::*)(BC_WindowBase *))
272 &MWindowGUI::keyboard_listener);
274 // release the hounds
275 if( awindow && awindow->gui ) awindow->gui->close(0);
276 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
277 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
278 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
279 if( twindow && twindow->is_running() ) twindow->close_window();
280 if( wwindow && wwindow->is_running() ) wwindow->close_window();
281 vwindows.remove_all_objects();
282 zwindows.remove_all_objects();
284 if( awindow ) awindow->join();
285 if( cwindow ) cwindow->join();
286 if( lwindow ) lwindow->join();
287 if( twindow ) twindow->join();
288 if( wwindow ) wwindow->join();
289 if( gwindow ) gwindow->join();
292 // one at a time, or nouveau chokes
293 #define close_gui(win) if( win ) { \
294 if( win->gui ) win->gui->close(0); \
302 vwindows.remove_all_objects();
303 zwindows.remove_all_objects();
308 dead_plugins->remove_all_objects();
309 // must delete theme before destroying plugindb
310 // theme destructor will be deleted by delete_plugins
311 delete theme; theme = 0;
314 keyframe_threads->remove_all_objects();
315 colormodels.remove_all_objects();
316 delete awindow; awindow = 0;
317 delete lwindow; lwindow = 0;
318 delete twindow; twindow = 0;
319 delete wwindow; wwindow = 0;
320 delete gwindow; gwindow = 0;
321 delete cwindow; cwindow = 0;
323 delete mainindexes; mainindexes = 0;
324 delete mainprogress; mainprogress = 0;
325 delete audio_cache; audio_cache = 0; // delete the cache after the assets
326 delete video_cache; video_cache = 0; // delete the cache after the assets
327 delete frame_cache; frame_cache = 0;
328 delete wave_cache; wave_cache = 0;
329 delete plugin_guis; plugin_guis = 0;
330 delete dead_plugins; dead_plugins = 0;
331 delete keyframe_threads; keyframe_threads = 0;
332 delete undo; undo = 0;
333 delete preferences; preferences = 0;
334 delete exportedl; exportedl = 0;
335 delete session; session = 0;
336 delete defaults; defaults = 0;
337 delete assets; assets = 0;
338 delete splash_window; splash_window = 0;
339 if( !edl->Garbage::remove_user() ) edl = 0;
340 delete channeldb_buz;
341 delete channeldb_v4l2jpeg;
342 // This must be last thread to exit
343 delete playback_3d; playback_3d = 0;
344 delete dead_plugin_lock;
345 delete plugin_gui_lock;
346 delete vwindows_lock;
347 delete zwindows_lock;
349 delete keyframe_gui_lock;
350 colormodels.remove_all_objects();
351 interlace_project_modes.remove_all_objects();
352 interlace_asset_modes.remove_all_objects();
353 interlace_asset_fixmethods.remove_all_objects();
354 sighandler->terminate();
365 void MWindow::init_error()
367 MainError::init_error(this);
370 void MWindow::finit_error()
372 MainError::finit_error();
375 void MWindow::create_defaults_path(char *string, const char *config_file)
377 // set the .bcast path
380 sprintf(string, "%s/", File::get_config_path());
381 fs.complete_path(string);
382 if(!fs.is_dir(string))
383 fs.create_dir(string);
386 strcat(string, config_file);
388 const char *MWindow::default_std()
390 char buf[BCTEXTLEN], *p = 0;
392 int fd = open(TIMEZONE_NAME, O_RDONLY);
394 int l = read(fd, buf, sizeof(buf)-1);
397 if( buf[l-1] == '\n' ) --l;
403 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
406 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
407 p += strlen(ZONEINFO_STR);
412 for( int i=0; ntsc_zones[i]; ++i ) {
413 if( !strcmp(ntsc_zones[i], p) )
420 for( int i=0; ntsc_zones[i]; ++i ) {
421 if( !strcmp(ntsc_zones[i], p) )
426 //__timezone: Seconds west of UTC. 240sec/deg
427 double tz_deg = -__timezone / 240.;
428 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
429 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
432 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
434 struct formatpresets *fpr;
436 for(fpr = &format_presets[0]; fpr->name; fpr++)
438 if(strcmp(_(fpr->name), preset) == 0)
440 session->audio_channels = fpr->audio_channels;
441 session->audio_tracks = fpr->audio_tracks;
442 session->sample_rate = fpr->sample_rate;
443 session->video_channels = fpr->video_channels;
444 session->video_tracks = fpr->video_tracks;
445 session->frame_rate = fpr->frame_rate;
446 session->output_w = fpr->output_w;
447 session->output_h = fpr->output_h;
448 session->aspect_w = fpr->aspect_w;
449 session->aspect_h = fpr->aspect_h;
450 session->interlace_mode = fpr->interlace_mode;
451 session->color_model = fpr->color_model;
457 const char *MWindow::get_preset_name(int index)
459 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
461 return _(format_presets[index].name);
465 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
467 char path[BCTEXTLEN];
468 // Use user supplied path
470 strcpy(path, config_path);
472 create_defaults_path(path, CONFIG_FILE);
475 defaults = new BC_Hash(path);
480 void MWindow::check_language()
482 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
483 const char *env_lang = getenv("LANGUAGE");
484 if( !env_lang ) env_lang = getenv("LC_ALL");
485 if( !env_lang ) env_lang = getenv("LANG");
487 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
488 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
489 env_lang = curr_lang;
491 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
492 defaults->get("LAST_LANG",last_lang);
493 if( strcmp(env_lang,last_lang)) {
494 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
495 defaults->update("LAST_LANG",env_lang);
496 char plugin_path[BCTEXTLEN];
497 create_defaults_path(plugin_path, PLUGIN_FILE);
498 ::remove(plugin_path);
499 char ladspa_path[BCTEXTLEN];
500 create_defaults_path(ladspa_path, LADSPA_FILE);
501 ::remove(ladspa_path);
504 if( strlen(env_lang) > 1 &&
505 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
506 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
509 strcpy(cin_lang, "en");
512 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
514 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
516 const char *dp = plug_dir;
517 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
518 bp = !*dp && *bp == '/' ? bp+1 : base_path;
524 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
527 FILE *fp = fopen(index_path, "r");
531 char index_line[BCTEXTLEN];
532 int index_version = -1, len = strlen(plugin_dir);
533 if( !fgets(index_line, BCTEXTLEN, fp) ||
534 sscanf(index_line, "%d", &index_version) != 1 ||
535 index_version != PLUGIN_FILE_VERSION ||
536 !fgets(index_line, BCTEXTLEN, fp) ||
537 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
538 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
540 ArrayList<PluginServer*> plugins;
541 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
542 if( index_line[0] == ';' ) continue;
543 if( index_line[0] == '#' ) continue;
544 int type = PLUGIN_TYPE_UNKNOWN;
545 char path[BCTEXTLEN], title[BCTEXTLEN];
547 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
550 PluginServer *server = 0;
552 case PLUGIN_TYPE_BUILTIN:
553 case PLUGIN_TYPE_EXECUTABLE:
554 case PLUGIN_TYPE_LADSPA: {
555 char plugin_path[BCTEXTLEN]; struct stat st;
556 sprintf(plugin_path, "%s/%s", plugin_dir, path);
557 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
560 server = new PluginServer(mwindow, plugin_path, type);
562 case PLUGIN_TYPE_FFMPEG: {
563 server = new_ffmpeg_server(mwindow, path);
565 case PLUGIN_TYPE_LV2: {
566 server = new_lv2_server(mwindow, path);
569 if( !server ) continue;
570 plugins.append(server);
571 // Create plugin server from index entry
572 server->set_title(title);
573 if( server->read_table(index_line) ) {
580 ret = check_plugin_index(plugins, plugin_dir, ".");
583 add_plugins(plugins);
585 plugins.remove_all_objects();
590 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
591 const char *plug_dir, const char *plug_path)
593 char plugin_path[BCTEXTLEN];
594 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
596 fs.set_filter( "[*.plugin][*.so]" );
597 if( fs.update(plugin_path) )
600 for( int i=0; i<fs.dir_list.total; ++i ) {
601 char fs_path[BCTEXTLEN];
602 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
603 if( fs.is_dir(fs_path) ) {
604 get_plugin_path(plugin_path, plug_dir, fs_path);
605 if( check_plugin_index(plugins, plug_dir, plugin_path) )
608 else if( !plugin_exists(fs_path, plugins) )
615 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
618 plugindb = new ArrayList<PluginServer*>;
620 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
621 create_defaults_path(index_path, PLUGIN_FILE);
622 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
623 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
624 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
625 printf("init plugin index: %s\n", plugin_path);
626 FILE *fp = fopen(index_path,"w");
628 fprintf(stderr,_("MWindow::init_plugins: "
629 "can't create plugin index: %s\n"), index_path);
632 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
633 fprintf(fp, "%s\n", plugin_path);
634 init_plugin_index(mwindow, preferences, fp, plugin_path);
635 init_ffmpeg_index(mwindow, preferences, fp);
636 init_lv2_index(mwindow, preferences, fp);
638 return load_plugin_index(mwindow, index_path, plugin_path);
641 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
643 char *path = getenv("LADSPA_PATH");
644 char ladspa_path[BCTEXTLEN];
646 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
649 for( int len=0; *path; path+=len ) {
650 char *cp = strchr(path,':');
651 len = !cp ? strlen(path) : cp-path;
652 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
653 memcpy(plugin_path, path, len); plugin_path[len] = 0;
655 char *plugin_dir = FileSystem::basepath(plugin_path);
656 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
657 create_defaults_path(index_path, LADSPA_FILE);
658 cp = index_path + strlen(index_path);
659 for( char *bp=plugin_path; *bp!=0; ++bp )
660 *cp++ = *bp=='/' ? '_' : *bp;
662 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
663 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
664 load_plugin_index(mwindow, index_path, plugin_path);
669 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
670 FILE *fp, const char *plugin_dir)
672 int idx = PLUGIN_IDS;
674 for( int i=0; i<plugindb->size(); ++i ) {
675 PluginServer *server = plugindb->get(i);
676 if( server->dir_idx >= idx )
677 idx = server->dir_idx+1;
680 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
683 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
684 const char *plug_dir, const char *plug_path, int &idx)
686 char plugin_path[BCTEXTLEN];
687 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
689 fs.set_filter( "[*.plugin][*.so]" );
690 int result = fs.update(plugin_path);
691 if( result || !fs.dir_list.total ) return;
694 for( int i=0; i<fs.dir_list.total; ++i ) {
695 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
696 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
697 get_plugin_path(path, plug_dir, fs_path);
698 if( fs.is_dir(fs_path) ) {
699 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
702 if( plugin_exists(path) ) continue;
704 if( stat(fs_path, &st) ) continue;
705 int64_t mtime = st.st_mtime;
706 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
707 result = server.open_plugin(1, preferences, 0, 0);
709 server.write_table(fp, path, vis_id, mtime);
710 server.close_plugin();
712 else if( result == PLUGINSERVER_IS_LAD ) {
715 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
716 ladspa.set_lad_index(lad_index++);
717 result = ladspa.open_plugin(1, preferences, 0, 0);
719 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
720 ladspa.close_plugin();
726 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
728 for( int i=0; i<plugins.size(); ++i )
729 plugindb->append(plugins[i]);
730 plugins.remove_all();
733 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
735 const char *dat_path = File::get_cindat_path();
736 char msg_path[BCTEXTLEN];
738 if( BC_Resources::language[0] ) {
739 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
741 fp = fopen(msg_path, "r");
744 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
746 fp = fopen(msg_path, "r");
749 char text[BCTEXTLEN];
750 char *tp = text, *ep = tp + sizeof(text)-1;
751 char title[BCTEXTLEN];
756 char line[BCTEXTLEN], *cp = line;
757 if( fgets(line,sizeof(line)-1,fp) ) {
758 if( *cp == '#' ) continue;
759 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
762 if( tp > text && *--tp == '\n' ) *tp = 0;
764 int idx = plugins.size();
765 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
767 delete [] plugins[idx]->tip;
768 plugins[idx]->tip = cstrdup(text);
772 if( done > 0 ) break;
774 char *dp = strchr(cp, ':');
776 printf("plugin tips: error on line %d\n", no);
780 while( cp < dp ) *bp++ = *cp++;
785 while( *cp == ' ' || *cp == '\t' ) ++cp;
786 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
791 void MWindow::delete_plugins()
793 plugindb->remove_all_objects();
798 void MWindow::search_plugindb(int do_audio,
803 ArrayList<PluginServer*> &results)
806 for(int i = 0; i < MWindow::plugindb->total; i++)
808 PluginServer *current = MWindow::plugindb->get(i);
810 if(current->audio == do_audio &&
811 current->video == do_video &&
812 (current->realtime == is_realtime || is_realtime < 0) &&
813 current->transition == is_transition &&
814 current->theme == is_theme)
815 results.append(current);
818 // Alphabetize list by title
824 for(int i = 0; i < results.total - 1; i++)
826 PluginServer *value1 = results[i];
827 PluginServer *value2 = results[i + 1];
828 if(strcmp(_(value1->title), _(value2->title)) > 0)
832 results[i + 1] = value1;
838 PluginServer* MWindow::scan_plugindb(char *title,
843 // printf("MWindow::scan_plugindb data_type < 0\n");
847 for(int i = 0; i < plugindb->total; i++)
849 PluginServer *server = plugindb->get(i);
851 !strcasecmp(server->title, title) &&
853 (data_type == TRACK_AUDIO && server->audio) ||
854 (data_type == TRACK_VIDEO && server->video)))
855 return plugindb->get(i);
860 // repair session files with xlated plugin titles
861 void MWindow::fix_plugin_title(char *title)
863 for(int i = 0; i < plugindb->total; i++) {
864 PluginServer *server = plugindb->get(i);
865 if( !server->title ) continue;
866 const char *server_title = server->title;
867 if( !bstrcasecmp(title, _(server_title)) ) {
868 strcpy(title, server_title);
874 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
876 for( int i=0; i<plugins.size(); ++i )
877 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
881 int MWindow::plugin_exists(char *plugin_path)
883 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
886 void MWindow::remove_plugin_index()
888 char index_path[BCTEXTLEN];
889 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
890 ::remove(index_path);
893 void MWindow::init_preferences()
895 preferences = new Preferences;
896 preferences->load_defaults(defaults);
897 const char *lv2_path = getenv("LV2_PATH");
898 if( lv2_path && strcmp(lv2_path, preferences->lv2_path) ) {
899 strncpy(preferences->lv2_path, lv2_path, sizeof(preferences->lv2_path));
900 remove_plugin_index();
902 else if( !lv2_path && preferences->lv2_path[0] ) {
903 File::setenv_path("LV2_PATH",preferences->lv2_path, 0);
905 session = new MainSession(this);
906 session->load_defaults(defaults);
907 // set x11_host, screens, window_config
908 screens = session->set_default_x11_host();
909 BC_Signals::set_trap_hook(trap_hook, this);
910 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
911 BC_Signals::set_catch_intr(preferences->trap_sigintr);
912 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
913 BC_Trace::enable_locks();
916 BC_Trace::disable_locks();
918 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
919 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
920 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
921 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
924 void MWindow::clean_indexes()
929 int oldest_item = -1;
931 char string[BCTEXTLEN];
932 char string2[BCTEXTLEN];
934 // Delete extra indexes
935 fs.set_filter("*.idx");
936 fs.complete_path(preferences->index_directory);
937 fs.update(preferences->index_directory);
938 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
940 // Eliminate directories
945 for(int i = 0; i < fs.dir_list.total && !result; i++)
947 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
948 if(fs.is_dir(string))
950 delete fs.dir_list[i];
951 fs.dir_list.remove_number(i);
956 total_excess = fs.dir_list.total - preferences->index_count;
958 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
959 while(total_excess > 0)
962 for(int i = 0; i < fs.dir_list.total; i++)
964 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
966 if(i == 0 || fs.get_date(string) <= oldest)
968 oldest = fs.get_date(string);
976 fs.join_names(string,
977 preferences->index_directory,
978 fs.dir_list[oldest_item]->name);
979 //printf("MWindow::clean_indexes 1 %s\n", string);
981 perror("delete_indexes");
982 delete fs.dir_list[oldest_item];
983 fs.dir_list.remove_number(oldest_item);
985 // Remove table of contents if it exists
986 strcpy(string2, string);
987 char *ptr = strrchr(string2, '.');
990 //printf("MWindow::clean_indexes 2 %s\n", string2);
991 sprintf(ptr, ".toc");
993 sprintf(ptr, ".mkr");
1002 void MWindow::init_awindow()
1004 awindow = new AWindow(this);
1005 awindow->create_objects();
1008 void MWindow::init_gwindow()
1010 gwindow = new GWindow(this);
1011 gwindow->create_objects();
1014 void MWindow::init_tipwindow()
1016 TipWindow::load_tips(cin_lang);
1018 twindow = new TipWindow(this);
1022 void MWindow::show_warning(int *do_warning, const char *text)
1024 if( do_warning && !*do_warning ) return;
1026 wwindow = new WWindow(this);
1027 wwindow->show_warning(do_warning, text);
1030 int MWindow::wait_warning()
1032 return wwindow->wait_result();
1035 void MWindow::init_theme()
1040 PluginServer *theme_plugin = 0;
1041 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1042 if( plugindb->get(i)->theme &&
1043 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1044 theme_plugin = plugindb->get(i);
1048 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1049 preferences->theme);
1051 const char *default_theme = DEFAULT_THEME;
1052 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1053 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1055 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1056 if( plugindb->get(i)->theme &&
1057 !strcasecmp(default_theme, plugindb->get(i)->title) )
1058 theme_plugin = plugindb->get(i);
1063 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1067 PluginServer *plugin = new PluginServer(*theme_plugin);
1068 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1069 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1070 theme_plugin->title);
1074 theme = plugin->new_theme();
1075 theme->mwindow = this;
1076 strcpy(theme->path, plugin->path);
1079 // Load default images & settings
1080 theme->Theme::initialize();
1081 // Load user images & settings
1082 theme->initialize();
1083 // Create menus with user colors
1084 theme->build_menus();
1087 theme->sort_image_sets();
1088 theme->check_used();
1089 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1092 void MWindow::init_3d()
1094 playback_3d = new Playback3D(this);
1095 playback_3d->create_objects();
1098 void MWindow::init_edl()
1101 edl->create_objects();
1102 fill_preset_defaults(default_standard, edl->session);
1103 edl->load_defaults(defaults);
1104 edl->session->brender_start = edl->session->brender_end = 0;
1105 edl->create_default_tracks();
1106 edl->tracks->update_y_pixels(theme);
1109 void MWindow::init_compositor()
1111 cwindow = new CWindow(this);
1112 cwindow->create_objects();
1115 void MWindow::init_levelwindow()
1117 lwindow = new LevelWindow(this);
1118 lwindow->create_objects();
1121 VWindow *MWindow::get_viewer(int start_it, int idx)
1123 vwindows_lock->lock("MWindow::get_viewer");
1124 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1125 if( !vwindow ) idx = vwindows.size();
1126 while( !vwindow && --idx >= 0 ) {
1127 VWindow *vwin = vwindows[idx];
1128 if( !vwin->is_running() || !vwin->get_edl() )
1132 vwindow = new VWindow(this);
1133 vwindow->load_defaults();
1134 vwindow->create_objects();
1135 vwindows.append(vwindow);
1137 vwindows_lock->unlock();
1138 if( start_it ) vwindow->start();
1142 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1144 zwindows_lock->lock("MWindow::get_mixer");
1145 if( !mixer ) mixer = edl->mixers.new_mixer();
1146 ZWindow *zwindow = 0;
1147 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1148 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1150 zwindows.append(zwindow = new ZWindow(this));
1151 zwindow->idx = mixer->idx;
1152 zwindows_lock->unlock();
1156 void MWindow::del_mixer(ZWindow *zwindow)
1158 zwindows_lock->lock("MWindow::del_mixer 0");
1159 edl->mixers.del_mixer(zwindow->idx);
1160 if( session->selected_zwindow >= 0 ) {
1161 int i = zwindows.number_of(zwindow);
1162 if( i >= 0 && i < session->selected_zwindow )
1163 --session->selected_zwindow;
1164 else if( i == session->selected_zwindow )
1165 session->selected_zwindow = -1;
1167 zwindows_lock->unlock();
1168 gui->lock_window("MWindow::del_mixer 1");
1169 gui->update_mixers(0, -1);
1170 gui->unlock_window();
1173 void MWindow::start_mixer()
1176 ZWindow *zwindow = get_mixer(mixer);
1177 const char *title = 0;
1179 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1180 PatchGUI *patchgui = get_patchgui(track);
1181 if( !patchgui || !patchgui->mixer ) continue;
1182 mixer->mixer_ids.append(track->get_mixer_id());
1183 if( !title ) title = track->title;
1186 session->selected_zwindow = -1;
1187 gui->lock_window("MWindow::start_mixer");
1188 gui->update_mixers(0, 0);
1189 gui->unlock_window();
1191 zwindow->set_title(title);
1196 int MWindow::mixer_track_active(Track *track)
1198 int i = session->selected_zwindow;
1199 if( i < 0 || i >= zwindows.size() ) return 0;
1200 ZWindow *zwindow = zwindows[i];
1201 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1202 if( !mixer ) return 0;
1203 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1204 return n >= 0 ? 1 : 0;
1207 void MWindow::update_mixer_tracks()
1209 zwindows_lock->lock("MixPatch::handle_event");
1210 int i = session->selected_zwindow;
1211 if( i >= 0 && i < zwindows.size() ) {
1212 ZWindow *zwindow = zwindows[i];
1213 zwindow->update_mixer_ids();
1215 zwindows_lock->unlock();
1218 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1219 int use_inout, int update_refresh, int toggle_audio, int loop_play)
1221 zwindows_lock->lock("MWindow::queue_mixers");
1222 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1223 ZWindow *zwindow = zwindows[vidx];
1224 if( zwindow->idx < 0 ) continue;
1225 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1226 if( !mixer || !mixer->mixer_ids.size() ) continue;
1228 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1229 if( track->data_type != TRACK_VIDEO ) continue;
1230 int mixer_id = track->get_mixer_id();
1231 k = mixer->mixer_ids.size();
1232 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1234 if( k < 0 ) continue;
1235 EDL *mixer_edl = new EDL(this->edl);
1236 mixer_edl->create_objects();
1237 mixer_edl->copy_all(edl);
1238 mixer_edl->remove_vwindow_edls();
1239 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1240 k = mixer->mixer_ids.size();
1241 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1244 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1247 track->record = track->play = 0;
1249 zwindow->change_source(mixer_edl);
1250 zwindow->issue_command(command,
1251 wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
1253 zwindows_lock->unlock();
1256 void MWindow::refresh_mixers(int dir)
1258 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1259 queue_mixers(edl,command,0,0,1,0,0);
1262 void MWindow::stop_mixers()
1264 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1265 ZWindow *zwindow = zwindows[vidx];
1266 if( zwindow->idx < 0 ) continue;
1267 zwindow->issue_command(STOP, 0, 0, 0, 0, 0);
1271 void MWindow::close_mixers(int destroy)
1273 zwindows_lock->lock("MWindow::close_mixers");
1274 for( int i=zwindows.size(); --i>=0; ) {
1275 ZWindow *zwindow = zwindows[i];
1276 if( zwindow->idx < 0 ) continue;
1277 zwindow->destroy = destroy;
1278 ZWindowGUI *zgui = zwindow->zgui;
1279 zgui->lock_window("MWindow::select_zwindow 0");
1281 zgui->unlock_window();
1283 zwindows_lock->unlock();
1284 for( int i=0; i<zwindows.size(); ++i ) {
1285 ZWindow *zwindow = zwindows[i];
1286 if( zwindow->idx < 0 ) continue;
1287 zwindow->close_window();
1291 ZWindow *MWindow::create_mixer(Indexable *indexable)
1293 ArrayList<Indexable*> new_assets;
1294 new_assets.append(indexable);
1295 Track *track = edl->tracks->last;
1296 load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
1297 track = !track ? edl->tracks->first : track->next;
1299 ZWindow *zwindow = get_mixer(mixer);
1301 track->play = track->record = 0;
1302 if( track->data_type == TRACK_VIDEO ) {
1303 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1305 mixer->mixer_ids.append(track->get_mixer_id());
1306 track = track->next;
1308 if( indexable->is_asset ) {
1309 char *path = indexable->path;
1310 char *tp = strrchr(path, '/');
1311 if( !tp ) tp = path; else ++tp;
1312 zwindow->set_title(tp);
1315 char *title = ((EDL*)indexable)->local_session->clip_title;
1316 zwindow->set_title(title);
1321 void MWindow::create_mixers()
1323 if( !session->drag_assets->size() &&
1324 !session->drag_clips->size() ) return;
1325 undo->update_undo_before();
1328 ArrayList<ZWindow *>new_mixers;
1330 for( int i=0; i<session->drag_assets->size(); ++i ) {
1331 Indexable *indexable = session->drag_assets->get(i);
1332 if( !indexable->have_video() ) continue;
1333 ZWindow *zwindow = create_mixer(indexable);
1334 new_mixers.append(zwindow);
1336 for( int i=0; i<session->drag_clips->size(); ++i ) {
1337 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1338 if( !indexable->have_video() ) continue;
1339 ZWindow *zwindow = create_mixer(indexable);
1340 new_mixers.append(zwindow);
1344 for( int i=0; i<new_mixers.size(); ++i )
1345 new_mixers[i]->start();
1349 undo->update_undo_after(_("create mixers"), LOAD_ALL);
1351 gui->update(1, 2, 1, 1, 1, 1, 0);
1352 sync_parameters(CHANGE_ALL);
1355 void MWindow::open_mixers()
1357 for( int i=0; i<edl->mixers.size(); ++i ) {
1358 Mixer *mixer = edl->mixers[i];
1359 ZWindow *zwindow = get_mixer(mixer);
1360 zwindow->set_title(mixer->title);
1366 int MWindow::select_zwindow(ZWindow *zwindow)
1368 int ret = 0, n = zwindows.number_of(zwindow);
1369 if( session->selected_zwindow != n ) {
1370 session->selected_zwindow = n;
1371 for( int i=0; i<zwindows.size(); ++i ) {
1372 ZWindow *zwindow = zwindows[i];
1373 if( zwindow->idx < 0 ) continue;
1374 ZWindowGUI *zgui = zwindow->zgui;
1375 zgui->lock_window("MWindow::select_zwindow 0");
1376 zwindow->highlighted = i == n ? 1 : 0;
1377 if( zgui->draw_overlays() )
1378 zgui->canvas->get_canvas()->flash(1);
1379 zgui->unlock_window();
1382 gui->lock_window("MWindow::select_window 1");
1383 gui->update_mixers(0, -1);
1384 gui->unlock_window();
1389 void MWindow::tile_mixers()
1392 for( int i=0; i<zwindows.size(); ++i ) {
1393 ZWindow *zwindow = zwindows[i];
1394 if( zwindow->idx < 0 ) continue;
1398 int zn = ceil(sqrt(nz));
1399 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1400 int y1 = 1, y2 = gui->get_y();
1401 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1402 if( x1 < 0 ) x1 = 0;
1403 if( y1 < 0 ) y1 = 0;
1404 if( x2 > rw ) x2 = rw;
1405 if( y2 > rh ) y2 = rh;
1406 int dx = x2 - x1, dy = y2 - y1;
1408 int lt = BC_DisplayInfo::get_left_border();
1409 int top = BC_DisplayInfo::get_top_border();
1410 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1411 int bh = top + BC_DisplayInfo::get_bottom_border();
1412 int zx = 0, zy = 0; // window origins
1413 int mw = 10+10, mh = 10+10; // canvas margins
1414 int rsz = 0, n = 0, dz = 0;
1415 int ow = edl->session->output_w, oh = edl->session->output_h;
1416 for( int i=0; i<zwindows.size(); ++i ) {
1417 ZWindow *zwindow = zwindows[i];
1418 if( zwindow->idx < 0 ) continue;
1419 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1420 if( rsz < hh ) rsz = hh;
1421 int xx = zx + x1, yy = zy + y1;
1422 int mx = x2 - zw, my = y2 - zh;
1423 if( xx > mx ) xx = mx;
1424 if( yy > my ) yy = my;
1425 xx += lt + dz; yy += top + dz;
1426 zwindow->reposition(xx,yy, ww,hh);
1427 if( zwindow->running() ) {
1428 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1429 gui->lock_window("MWindow::tile_mixers");
1430 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1431 gui->unlock_window();
1435 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1444 void MWindow::init_cache()
1446 audio_cache = new CICache(preferences);
1447 video_cache = new CICache(preferences);
1448 frame_cache = new FrameCache;
1449 wave_cache = new WaveCache;
1452 void MWindow::init_channeldb()
1454 channeldb_buz->load("channeldb_buz");
1455 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1458 void MWindow::init_menus()
1460 char string[BCTEXTLEN];
1463 BC_CModels::to_text(string, BC_RGB888);
1464 colormodels.append(new ColormodelItem(string, BC_RGB888));
1465 BC_CModels::to_text(string, BC_RGBA8888);
1466 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1467 // BC_CModels::to_text(string, BC_RGB161616);
1468 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1469 // BC_CModels::to_text(string, BC_RGBA16161616);
1470 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1471 BC_CModels::to_text(string, BC_RGB_FLOAT);
1472 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1473 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1474 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1475 BC_CModels::to_text(string, BC_YUV888);
1476 colormodels.append(new ColormodelItem(string, BC_YUV888));
1477 BC_CModels::to_text(string, BC_YUVA8888);
1478 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1479 // BC_CModels::to_text(string, BC_YUV161616);
1480 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1481 // BC_CModels::to_text(string, BC_YUVA16161616);
1482 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1484 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1485 interlace_project_modes.append(new InterlacemodeItem(string, x));
1487 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1488 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1490 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1491 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1493 // Interlacing Modes
1494 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1496 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1497 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1499 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1500 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1502 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1503 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1505 // Interlacing Fixing Methods
1506 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1507 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1508 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1511 void MWindow::init_indexes()
1513 mainindexes = new MainIndexes(this);
1514 mainindexes->start_loop();
1517 void MWindow::init_gui()
1519 gui = new MWindowGUI(this);
1520 gui->lock_window("MWindow::init_gui");
1521 gui->create_objects();
1522 gui->unlock_window();
1523 gui->load_defaults(defaults);
1526 void MWindow::init_signals()
1528 sighandler = new SigHandler;
1529 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1533 void MWindow::init_render()
1535 render = new Render(this);
1536 create_bd = new CreateBD_Thread(this);
1537 create_dvd = new CreateDVD_Thread(this);
1538 batch_render = new BatchRenderThread(this);
1541 void MWindow::init_exportedl()
1543 exportedl = new ExportEDL(this);
1546 void MWindow::init_brender()
1548 if(preferences->use_brender && !brender)
1550 brender_lock->lock("MWindow::init_brender 1");
1551 brender = new BRender(this);
1552 brender->initialize();
1553 session->brender_end = 0;
1554 brender_lock->unlock();
1557 if(!preferences->use_brender && brender)
1559 brender_lock->lock("MWindow::init_brender 2");
1562 session->brender_end = 0;
1563 brender_lock->unlock();
1569 void MWindow::restart_brender()
1571 //printf("MWindow::restart_brender 1\n");
1572 if( !brender_active || !preferences->use_brender ) return;
1573 if( !brender ) return;
1574 brender->restart(edl);
1577 void MWindow::stop_brender()
1579 if( !brender ) return;
1580 // cannot be holding mwindow->gui display lock
1584 int MWindow::brender_available(int position)
1587 brender_lock->lock("MWindow::brender_available 1");
1588 if(brender && brender_active)
1590 if(brender->map_valid)
1592 brender->map_lock->lock("MWindow::brender_available 2");
1593 if(position < brender->map_size &&
1596 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1597 if(brender->map[position] == BRender::RENDERED)
1600 brender->map_lock->unlock();
1603 brender_lock->unlock();
1607 void MWindow::set_brender_active(int v, int update)
1609 if( !preferences->use_brender ) v = 0;
1611 gui->mainmenu->brender_active->set_checked(v);
1613 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1614 edl->session->brender_end = edl->local_session->get_selectionend(1);
1616 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1617 edl->session->brender_end = edl->tracks->total_video_length();
1622 edl->session->brender_start = edl->session->brender_end = 0;
1623 gui->unlock_window();
1625 gui->lock_window("MWindow::set_brender_active");
1628 gui->update_timebar(0);
1629 gui->draw_overlays(1);
1633 int MWindow::has_commercials()
1635 #ifdef HAVE_COMMERCIAL
1636 return theme->use_commercials;
1642 void MWindow::init_commercials()
1644 #ifdef HAVE_COMMERCIAL
1645 if( !commercials ) {
1646 commercials = new Commercials(this);
1647 commercial_active = 0;
1650 commercials->add_user();
1654 void MWindow::commit_commercial()
1656 #ifdef HAVE_COMMERCIAL
1657 if( !commercial_active ) return;
1658 commercial_active = 0;
1659 if( !commercials ) return;
1660 commercials->commitDb();
1664 void MWindow::undo_commercial()
1666 #ifdef HAVE_COMMERCIAL
1667 if( !commercial_active ) return;
1668 commercial_active = 0;
1669 if( !commercials ) return;
1670 commercials->undoDb();
1674 int MWindow::put_commercial()
1677 #ifdef HAVE_COMMERCIAL
1678 double start = edl->local_session->get_selectionstart();
1679 double end = edl->local_session->get_selectionend();
1680 if( start >= end ) return 0;
1682 const char *errmsg = 0;
1684 Tracks *tracks = edl->tracks;
1686 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1687 if( track->data_type != TRACK_VIDEO ) continue;
1688 if( !track->record ) continue;
1689 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1691 int64_t units_start = track->to_units(start,0);
1692 int64_t units_end = track->to_units(end,0);
1693 Edits *edits = track->edits;
1694 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1695 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1696 if(!edit1 && !edit2) continue; // nothing selected
1697 if(!edit2) { // edit2 beyond end of track
1698 edit2 = edits->last;
1699 units_end = edits->length();
1701 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1702 Indexable *indexable = edit1->get_source();
1703 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1706 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1707 if( track->data_type != TRACK_VIDEO ) continue;
1708 if( !track->record ) continue;
1709 int64_t units_start = track->to_units(start,0);
1710 int64_t units_end = track->to_units(end,0);
1711 Edits *edits = track->edits;
1712 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1713 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1714 if(!edit1 && !edit2) continue; // nothing selected
1715 if(!edit2) { // edit2 beyond end of track
1716 edit2 = edits->last;
1717 units_end = edits->length();
1719 Indexable *indexable = edit1->get_source();
1720 Asset *asset = (Asset *)indexable;
1721 File *file = video_cache->check_out(asset, edl);
1722 if( !file ) { errmsg = _("no file"); break; }
1723 int64_t edit_length = units_end - units_start;
1724 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1725 result = commercials->put_clip(file, edit1->channel,
1726 track->from_units(edit_start), track->from_units(edit_length));
1727 video_cache->check_in(asset);
1728 if( result ) { errmsg = _("db failed"); break; }
1731 char string[BCTEXTLEN];
1732 sprintf(string, _("put_commercial: %s"), errmsg);
1733 MainError::show_error(string);
1741 void MWindow::stop_playback(int wait)
1743 gui->stop_drawing();
1745 cwindow->stop_playback(wait);
1747 for(int i = 0; i < vwindows.size(); i++) {
1748 VWindow *vwindow = vwindows[i];
1749 if( !vwindow->is_running() ) continue;
1750 vwindow->stop_playback(wait);
1752 for(int i = 0; i < zwindows.size(); i++) {
1753 ZWindow *zwindow = zwindows[i];
1754 if( zwindow->idx < 0 ) continue;
1755 zwindow->stop_playback(wait);
1759 void MWindow::stop_transport()
1761 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1764 void MWindow::beep(double freq, double secs, double gain)
1766 if( !proxy_beep ) proxy_beep = new ProxyBeep(this);
1767 proxy_beep->tone(freq, secs, gain);
1770 int MWindow::load_filenames(ArrayList<char*> *filenames,
1772 int update_filename)
1774 ArrayList<EDL*> new_edls;
1775 ArrayList<Asset*> new_assets;
1776 ArrayList<File*> new_files;
1777 const int debug = 0;
1778 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1781 gui->start_hourglass();
1783 // Need to stop playback since tracking depends on the EDL not getting
1785 gui->unlock_window();
1787 gui->lock_window("MWindow::load_filenames 0");
1789 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1790 undo->update_undo_before();
1793 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1795 // Define new_edls and new_assets to load
1796 int result = 0, ftype = -1;
1798 for( int i=0; i<filenames->size(); ++i ) {
1800 File *new_file = new File;
1801 Asset *new_asset = new Asset(filenames->get(i));
1802 EDL *new_edl = new EDL;
1803 char string[BCTEXTLEN];
1805 new_edl->create_objects();
1806 new_edl->copy_session(edl);
1807 new_file->set_program(edl->session->program_no);
1809 sprintf(string, _("Loading %s"), new_asset->path);
1810 gui->show_message(string);
1811 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1813 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1814 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1818 // Convert media file to EDL
1820 // Warn about odd image dimensions
1821 if( new_asset->video_data &&
1822 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1823 char string[BCTEXTLEN];
1824 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1825 new_asset->path, new_asset->width, new_asset->height);
1826 MainError::show_error(string);
1829 if( new_asset->program >= 0 &&
1830 edl->session->program_no != new_asset->program ) {
1831 char string[BCTEXTLEN];
1832 sprintf(string, _("%s's index was built for program number %d\n"
1833 "Playback preference is %d.\n Using program %d."),
1834 new_asset->path, new_asset->program,
1835 edl->session->program_no, new_asset->program);
1836 MainError::show_error(string);
1839 if( load_mode != LOADMODE_RESOURCESONLY ) {
1840 RecordLabels *labels = edl->session->label_cells ?
1841 new RecordLabels(new_file) : 0;
1842 asset_to_edl(new_edl, new_asset, labels);
1843 new_edls.append(new_edl);
1844 new_edl->add_user();
1848 new_assets.append(new_asset);
1849 new_asset->add_user();
1852 // Set filename to nothing for assets since save EDL would overwrite them.
1853 if( load_mode == LOADMODE_REPLACE ||
1854 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1856 // Reset timeline position
1857 for( int i=0; i<TOTAL_PANES; ++i ) {
1858 new_edl->local_session->view_start[i] = 0;
1859 new_edl->local_session->track_start[i] = 0;
1867 case FILE_NOT_FOUND:
1868 sprintf(string, _("Failed to open %s"), new_asset->path);
1869 gui->show_message(string, theme->message_error);
1870 gui->update_default_message();
1874 case FILE_UNRECOGNIZED_CODEC: {
1876 { IndexFile indexfile(this, new_asset);
1877 if( !(result = indexfile.open_index()) )
1878 indexfile.close_index(); }
1880 // Test existing EDLs
1881 for( int j=0; result && j<new_edls.total; ++j ) {
1882 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1884 new_asset->copy_from(old_asset,1);
1889 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1891 new_asset->copy_from(old_asset,1);
1898 char string[BCTEXTLEN];
1900 fs.extract_name(string, new_asset->path);
1902 strcat(string, _("'s format couldn't be determined."));
1903 new_asset->audio_data = 1;
1904 new_asset->format = FILE_PCM;
1905 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1906 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1907 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1908 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1909 new_asset->signed_ = defaults->get("SIGNED_", 1);
1910 new_asset->header = defaults->get("HEADER", 0);
1912 FileFormat fwindow(this);
1913 fwindow.create_objects(new_asset, string);
1914 result = fwindow.run_window();
1916 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1917 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1918 defaults->update("AUDIO_BITS", new_asset->bits);
1919 defaults->update("BYTE_ORDER", new_asset->byte_order);
1920 defaults->update("SIGNED_", new_asset->signed_);
1921 defaults->update("HEADER", new_asset->header);
1927 // Recalculate length
1929 new_file = new File;
1930 result = new_file->open_file(preferences, new_asset, 1, 0);
1932 if( load_mode != LOADMODE_RESOURCESONLY ) {
1933 RecordLabels *labels = edl->session->label_cells ?
1934 new RecordLabels(new_file) : 0;
1935 asset_to_edl(new_edl, new_asset, labels);
1936 new_edls.append(new_edl);
1937 new_edl->add_user();
1941 new_assets.append(new_asset);
1942 new_asset->add_user();
1952 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1953 xml_file.read_from_file(filenames->get(i));
1954 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1955 const char *cin_version = 0;
1956 while( !xml_file.read_tag() ) {
1957 if( xml_file.tag.title_is("EDL") ) {
1958 cin_version = xml_file.tag.get_property("VERSION");
1963 if( !cin_version ) {
1964 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1965 char string[BCTEXTLEN];
1966 sprintf(string,_("Unknown %s"), filenames->get(i));
1967 gui->show_message(string);
1971 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1972 char string[BCTEXTLEN];
1973 snprintf(string, sizeof(string),
1974 _("Warning: XML from cinelerra version %s\n"
1975 "Session data may be incompatible."), cin_version);
1976 show_warning(&preferences->warn_version, string);
1978 if( load_mode == LOADMODE_NESTED ) {
1979 // Load temporary EDL for nesting.
1980 EDL *nested_edl = new EDL;
1981 nested_edl->create_objects();
1982 nested_edl->load_xml(&xml_file, LOAD_ALL);
1983 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1984 new_edl->create_nested(nested_edl);
1985 new_edl->set_path(filenames->get(i));
1986 nested_edl->Garbage::remove_user();
1989 // Load EDL for pasting
1990 new_edl->load_xml(&xml_file, LOAD_ALL);
1991 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1992 test_plugins(new_edl, filenames->get(i));
1993 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1995 if( load_mode == LOADMODE_REPLACE ||
1996 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1997 strcpy(session->filename, filenames->get(i));
1998 strcpy(new_edl->local_session->clip_title,
2001 set_filename(new_edl->local_session->clip_title);
2003 else if( load_mode == LOADMODE_RESOURCESONLY ) {
2004 strcpy(new_edl->local_session->clip_title,
2007 time_t t = !stat(filenames->get(i),&st) ?
2008 st.st_mtime : time(&t);
2009 ctime_r(&t, new_edl->local_session->clip_notes);
2013 new_edls.append(new_edl);
2014 new_edl->add_user();
2019 new_edl->Garbage::remove_user();
2020 new_asset->Garbage::remove_user();
2022 // Store for testing index
2023 new_files.append(new_file);
2026 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2030 gui->reset_default_message();
2031 gui->default_message();
2035 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2038 // Don't back up here.
2041 // For pasting, clear the active region
2042 if(load_mode == LOADMODE_PASTE ||
2043 load_mode == LOADMODE_NESTED)
2045 double start = edl->local_session->get_selectionstart();
2046 double end = edl->local_session->get_selectionend();
2047 if(!EQUIV(start, end))
2050 edl->session->labels_follow_edits,
2051 edl->session->plugins_follow_edits,
2052 edl->session->autos_follow_edits);
2055 paste_edls(&new_edls, load_mode, 0, -1,
2056 edl->session->labels_follow_edits,
2057 edl->session->plugins_follow_edits,
2058 edl->session->autos_follow_edits,
2065 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2067 // Add new assets to EDL and schedule assets for index building.
2068 int got_indexes = 0;
2069 for( int i=0; i<new_edls.size(); ++i ) {
2070 EDL *new_edl = new_edls[i];
2071 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2072 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2073 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2079 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2080 for( int i=0; i<new_assets.size(); ++i ) {
2081 Asset *new_asset = new_assets[i];
2085 for( int j=0; j<new_files.size(); ++j ) {
2086 new_file = new_files[j];
2087 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2093 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2094 edl->assets->update(new_asset);
2097 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2099 // Start examining next batch of index files
2100 if(got_indexes) mainindexes->start_build();
2101 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2104 Track *track = edl->tracks->first;
2107 for(int j = 0; j < track->plugin_set.size(); j++)
2109 PluginSet *plugins = track->plugin_set[j];
2110 Plugin *plugin = plugins->get_first_plugin();
2114 if(load_mode == LOADMODE_REPLACE ||
2115 load_mode == LOADMODE_REPLACE_CONCATENATE)
2117 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2120 show_plugin(plugin);
2124 plugin = (Plugin*)plugin->next;
2128 track = track->next;
2131 // if just opening one new resource in replace mode
2132 if( ftype != FILE_IS_XML &&
2133 ( load_mode == LOADMODE_REPLACE ||
2134 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2136 edl->session->proxy_scale = 1;
2137 edl->session->proxy_use_scaler = 0;
2138 edl->session->proxy_auto_scale = 0;
2139 edl->session->proxy_beep = 0;
2140 edl->local_session->preview_start = 0;
2141 edl->local_session->preview_end = 0;
2142 edl->local_session->loop_playback = 0;
2143 edl->local_session->set_selectionstart(0);
2144 edl->local_session->set_selectionend(0);
2145 set_brender_active(0, 0);
2150 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2151 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2152 ArrayList<Indexable *> orig_idxbls;
2153 for( int i=0; i<new_assets.size(); ++i )
2154 orig_idxbls.append(new_assets.get(i));
2155 for( int i=0; i<new_edls.size(); ++i ) {
2156 EDL *new_edl = new_edls[i];
2157 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2158 if( track->data_type != TRACK_VIDEO ) continue;
2159 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2160 Indexable *idxbl = (Indexable *)edit->asset;
2161 if( !idxbl ) continue;
2162 if( !idxbl->have_video() ) continue;
2163 if( edit->channel != 0 ) continue; // first layer only
2164 orig_idxbls.append(edit->asset);
2168 gui->unlock_window(); // to update progress bar
2169 int ret = render_proxy(orig_idxbls);
2170 gui->lock_window("MWindow::load_filenames");
2171 if( ret >= 0 && edl->session->proxy_beep ) {
2173 beep(2000., 1.5, 0.5);
2175 beep(4000., 0.25, 0.5);
2179 // need to update undo before project, since mwindow is unlocked & a new load
2180 // can begin here. Should really prevent loading until we're done.
2181 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2182 undo->update_undo_after(_("load"), LOAD_ALL);
2184 for(int i = 0; i < new_edls.size(); i++)
2186 new_edls[i]->remove_user();
2188 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2190 new_edls.remove_all();
2192 for(int i = 0; i < new_assets.size(); i++)
2194 new_assets[i]->Garbage::remove_user();
2197 new_assets.remove_all();
2198 new_files.remove_all_objects();
2201 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2202 if(load_mode == LOADMODE_REPLACE ||
2203 load_mode == LOADMODE_REPLACE_CONCATENATE)
2205 session->changes_made = 0;
2209 session->changes_made = 1;
2212 gui->stop_hourglass();
2215 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2216 update_project(load_mode);
2218 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2223 int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2225 Asset *format_asset = new Asset;
2226 format_asset->format = FILE_FFMPEG;
2227 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2228 ProxyRender proxy_render(this, format_asset);
2229 int new_scale = edl->session->proxy_scale;
2230 int use_scaler = edl->session->proxy_use_scaler;
2232 for( int i=0; i<new_idxbls.size(); ++i ) {
2233 Indexable *orig = new_idxbls.get(i);
2234 Asset *proxy = proxy_render.add_original(orig, new_scale);
2235 if( !proxy ) continue;
2237 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2238 int got_it = exists && // if proxy exists, and is newer than orig
2239 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2240 if( got_it ) continue;
2241 proxy_render.add_needed(orig, proxy);
2244 // render needed proxies
2245 int result = proxy_render.create_needed_proxies(new_scale);
2247 add_proxy(use_scaler,
2248 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2250 format_asset->remove_user();
2251 return !result ? proxy_render.needed_proxies.size() : -1;
2254 void MWindow::test_plugins(EDL *new_edl, char *path)
2256 char string[BCTEXTLEN];
2258 // Do a check whether plugins exist
2259 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2260 for( int k=0; k<track->plugin_set.total; ++k ) {
2261 PluginSet *plugin_set = track->plugin_set[k];
2262 for( Plugin *plugin = (Plugin*)plugin_set->first;
2263 plugin; plugin = (Plugin*)plugin->next ) {
2264 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2265 // ok we need to find it in plugindb
2266 PluginServer *server =
2267 scan_plugindb(plugin->title, track->data_type);
2268 if( !server || server->transition ) {
2270 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2271 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2272 "effect", _(plugin->title), path);
2273 MainError::show_error(string);
2278 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2279 if( !edit->transition ) continue;
2280 // ok we need to find transition in plugindb
2281 PluginServer *server =
2282 scan_plugindb(edit->transition->title, track->data_type);
2283 if( !server || !server->transition ) {
2285 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2286 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2287 "transition", _(edit->transition->title), path);
2288 MainError::show_error(string);
2295 void MWindow::init_shm(const char *pfn, int64_t min)
2298 // Fix shared memory
2299 FILE *fd = fopen(pfn, "r");
2301 fscanf(fd, "%jd", &result);
2303 if( result >= min ) return;
2306 fd = fopen(pfn, "w");
2308 fprintf(fd, "0x%jx", min);
2311 fd = fopen(pfn, "r");
2313 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2317 fscanf(fd, "%jd", &result);
2319 if( result < min ) {
2320 eprintf(_("MWindow::init_shm: %s is %p.\n"
2321 "you probably need to be root, or:\n"
2322 "as root, run: echo 0x%jx > %s\n"
2323 "before trying to start cinelerra.\n"
2324 "It should be at least 0x%jx for Cinelerra.\n"),
2325 pfn, (void *)result, min, pfn, min);
2329 void MWindow::create_objects(int want_gui,
2333 const int debug = 0;
2334 if(debug) PRINT_TRACE
2336 // For some reason, init_signals must come after show_splash or the signals won't
2339 if(debug) PRINT_TRACE
2342 if(debug) PRINT_TRACE
2345 if(debug) PRINT_TRACE
2346 default_standard = default_std();
2347 init_defaults(defaults, config_path);
2351 splash_window->operation->update(_("Initializing Plugins"));
2352 init_plugins(this, preferences);
2353 if(debug) PRINT_TRACE
2354 init_ladspa_plugins(this, preferences);
2355 if(debug) PRINT_TRACE
2356 init_plugin_tips(*plugindb, cin_lang);
2358 splash_window->operation->update(_("Initializing GUI"));
2359 if(debug) PRINT_TRACE
2362 if(debug) PRINT_TRACE
2366 splash_window->operation->update(_("Initializing Fonts"));
2367 char string[BCTEXTLEN];
2368 strcpy(string, preferences->plugin_dir);
2369 strcat(string, "/" FONT_SEARCHPATH);
2370 BC_Resources::init_fontconfig(string);
2371 if(debug) PRINT_TRACE
2373 // Default project created here
2375 if(debug) PRINT_TRACE
2378 if(debug) PRINT_TRACE
2383 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2386 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2388 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2389 if(session->show_vwindow)
2390 get_viewer(1, DEFAULT_VWINDOW);
2391 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2394 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2397 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2400 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2403 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2406 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2409 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2414 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2415 mainprogress = new MainProgress(this, gui);
2416 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2417 undo = new MainUndo(this);
2419 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2421 plugin_guis = new ArrayList<PluginServer*>;
2422 dead_plugins = new ArrayList<PluginServer*>;
2423 keyframe_threads = new ArrayList<KeyFrameThread*>;
2425 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2428 session->show_vwindow);
2430 // Show all vwindows
2431 // if(session->show_vwindow) {
2432 // for(int j = 0; j < vwindows.size(); j++) {
2433 // VWindow *vwindow = vwindows[j];
2434 // if( !vwindow->is_running() ) continue;
2435 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2438 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2439 // vwindow->gui->lock_window("MWindow::create_objects 1");
2440 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2441 // vwindow->gui->show_window();
2442 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2443 // vwindow->gui->unlock_window();
2448 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2450 if(session->show_cwindow)
2452 cwindow->gui->lock_window("MWindow::create_objects 1");
2453 cwindow->gui->show_window();
2454 cwindow->gui->unlock_window();
2457 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2458 if(session->show_awindow)
2460 awindow->gui->lock_window("MWindow::create_objects 1");
2461 awindow->gui->show_window();
2462 awindow->gui->unlock_window();
2465 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2466 if(session->show_lwindow)
2468 lwindow->gui->lock_window("MWindow::create_objects 1");
2469 lwindow->gui->show_window();
2470 lwindow->gui->unlock_window();
2473 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2475 (int)timer.get_difference(),
2477 if(session->show_gwindow)
2479 gwindow->gui->lock_window("MWindow::create_objects 1");
2480 gwindow->gui->show_window();
2481 gwindow->gui->unlock_window();
2484 if(debug) PRINT_TRACE
2486 gui->lock_window("MWindow::create_objects 1");
2487 gui->mainmenu->load_defaults(defaults);
2488 gui->mainmenu->update_toggles(0);
2489 gui->update_patchbay();
2490 gui->draw_canvas(0, 0);
2491 gui->draw_cursor(1);
2493 gui->raise_window();
2494 gui->unlock_window();
2496 if(debug) PRINT_TRACE
2498 if(preferences->use_tipwindow)
2500 if(debug) PRINT_TRACE
2502 gui->add_keyboard_listener(
2503 (int (BC_WindowBase::*)(BC_WindowBase *))
2504 &MWindowGUI::keyboard_listener);
2507 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2508 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2509 if(debug) PRINT_TRACE
2511 BC_WindowBase::get_resources()->vframe_shm = 1;
2515 void MWindow::show_splash()
2517 #include "data/heroine_logo9_png.h"
2518 VFrame *frame = new VFramePng(heroine_logo9_png);
2519 BC_DisplayInfo dpyi;
2520 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2521 int rr = (rw < rh ? rw : rh) / 4;
2522 splash_window = new SplashGUI(frame, rr, rr);
2523 splash_window->create_objects();
2526 void MWindow::hide_splash()
2529 delete splash_window;
2534 void MWindow::start()
2538 // vwindows[DEFAULT_VWINDOW]->start();
2549 playback_3d->start();
2555 run_lock->lock("MWindow::run");
2559 brender_lock->lock("MWindow::run 1");
2560 delete brender; brender = 0;
2561 brender_lock->unlock();
2563 interrupt_indexes();
2569 void MWindow::show_vwindow()
2571 int total_running = 0;
2572 session->show_vwindow = 1;
2574 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2575 // Raise all windows which are visible
2576 for(int j = 0; j < vwindows.size(); j++) {
2577 VWindow *vwindow = vwindows[j];
2578 if( !vwindow->is_running() ) continue;
2579 vwindow->gui->lock_window("MWindow::show_vwindow");
2580 vwindow->gui->show_window(0);
2581 vwindow->gui->raise_window();
2582 vwindow->gui->flush();
2583 vwindow->gui->unlock_window();
2587 // If no windows visible
2590 get_viewer(1, DEFAULT_VWINDOW);
2593 gui->mainmenu->show_vwindow->set_checked(1);
2596 void MWindow::show_awindow()
2598 session->show_awindow = 1;
2599 awindow->gui->lock_window("MWindow::show_awindow");
2600 awindow->gui->show_window();
2601 awindow->gui->raise_window();
2602 awindow->gui->flush();
2603 awindow->gui->unlock_window();
2604 gui->mainmenu->show_awindow->set_checked(1);
2607 char *MWindow::get_cwindow_display()
2609 char *x11_host = screens < 2 || session->window_config == 0 ?
2610 session->a_x11_host : session->b_x11_host;
2611 return *x11_host ? x11_host : 0;
2614 void MWindow::show_cwindow()
2616 session->show_cwindow = 1;
2617 cwindow->show_window();
2618 gui->mainmenu->show_cwindow->set_checked(1);
2621 void MWindow::show_gwindow()
2623 session->show_gwindow = 1;
2625 gwindow->gui->lock_window("MWindow::show_gwindow");
2626 gwindow->gui->show_window();
2627 gwindow->gui->raise_window();
2628 gwindow->gui->flush();
2629 gwindow->gui->unlock_window();
2631 gui->mainmenu->show_gwindow->set_checked(1);
2633 void MWindow::hide_gwindow()
2635 session->show_gwindow = 0;
2637 gwindow->gui->lock_window("MWindow::show_gwindow");
2638 gwindow->gui->hide_window();
2639 gwindow->gui->unlock_window();
2642 void MWindow::show_lwindow()
2644 session->show_lwindow = 1;
2645 lwindow->gui->lock_window("MWindow::show_lwindow");
2646 lwindow->gui->show_window();
2647 lwindow->gui->raise_window();
2648 lwindow->gui->flush();
2649 lwindow->gui->unlock_window();
2650 gui->mainmenu->show_lwindow->set_checked(1);
2653 int MWindow::tile_windows(int window_config)
2655 int need_reload = 0;
2656 int play_config = window_config==0 ? 0 : 1;
2657 edl->session->playback_config->load_defaults(defaults, play_config);
2658 session->default_window_positions(window_config);
2659 if( screens == 1 ) {
2660 gui->default_positions();
2661 sync_parameters(CHANGE_ALL);
2668 void MWindow::toggle_loop_playback()
2670 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2671 set_loop_boundaries();
2674 gui->draw_overlays(1);
2675 sync_parameters(CHANGE_PARAMS);
2678 //void MWindow::set_titles(int value)
2680 // edl->session->show_titles = value;
2681 // trackmovement(edl->local_session->track_start);
2684 void MWindow::set_screens(int value)
2689 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2691 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2692 edl->session->auto_keyframes = value;
2693 gui->mbuttons->edit_panel->keyframe->update(value);
2695 if(lock_mwindow) gui->unlock_window();
2697 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2698 cwindow->gui->edit_panel->keyframe->update(value);
2699 cwindow->gui->flush();
2700 if(lock_cwindow) cwindow->gui->unlock_window();
2703 void MWindow::set_auto_visibility(Autos *autos, int value)
2705 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2706 edl->session->auto_conf->plugins = value;
2707 else if( autos->autoidx >= 0 )
2708 edl->session->auto_conf->autos[autos->autoidx] = value;
2712 gui->update(0, 1, 0, 0, 0, 0, 0);
2713 gui->mainmenu->update_toggles(1);
2714 gui->unlock_window();
2715 gwindow->gui->update_toggles(1);
2716 gui->lock_window("MWindow::set_auto_visibility");
2719 void MWindow::set_keyframe_type(int mode)
2721 gui->lock_window("MWindow::set_keyframe_type");
2722 edl->local_session->floatauto_type = mode;
2723 gui->mainmenu->update_toggles(0);
2724 gui->unlock_window();
2727 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2729 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2730 edl->session->editing_mode = new_editing_mode;
2731 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2732 gui->mbuttons->edit_panel->update();
2733 gui->set_editing_mode(1);
2734 if(lock_mwindow) gui->unlock_window();
2737 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2738 cwindow->gui->edit_panel->update();
2739 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2740 if(lock_cwindow) cwindow->gui->unlock_window();
2744 void MWindow::toggle_editing_mode()
2746 int mode = edl->session->editing_mode;
2747 if( mode == EDITING_ARROW )
2748 set_editing_mode(EDITING_IBEAM, 0, 1);
2750 set_editing_mode(EDITING_ARROW, 0, 1);
2754 void MWindow::set_labels_follow_edits(int value)
2756 gui->lock_window("MWindow::set_labels_follow_edits");
2757 edl->session->labels_follow_edits = value;
2758 gui->mbuttons->edit_panel->locklabels->update(value);
2759 gui->mainmenu->labels_follow_edits->set_checked(value);
2761 gui->unlock_window();
2764 void MWindow::sync_parameters(int change_type)
2766 if( in_destructor ) return;
2768 // Sync engines which are playing back
2769 if(cwindow->playback_engine->is_playing_back)
2771 if(change_type == CHANGE_PARAMS)
2773 // TODO: block keyframes until synchronization is done
2774 cwindow->playback_engine->sync_parameters(edl);
2779 int command = cwindow->playback_engine->command->command;
2780 cwindow->playback_engine->que->send_command(STOP,
2784 // Waiting for tracking to finish would make the restart position more
2785 // accurate but it can't lock the window to stop tracking for some reason.
2786 // Not waiting for tracking gives a faster response but restart position is
2787 // only as accurate as the last tracking update.
2788 cwindow->playback_engine->interrupt_playback(0);
2789 cwindow->playback_engine->que->send_command(command,
2798 cwindow->refresh_frame(change_type);
2802 void MWindow::age_caches()
2804 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2806 // preferences->cache_size,
2807 // audio_cache->get_memory_usage(1),
2808 // video_cache->get_memory_usage(1),
2809 // frame_cache->get_memory_usage(),
2810 // wave_cache->get_memory_usage(),
2812 frame_cache->age_cache(512);
2813 wave_cache->age_cache(8192);
2815 int64_t memory_usage;
2816 int64_t prev_memory_usage = 0;
2818 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2819 while( !result && prev_memory_usage !=
2820 (memory_usage=video_cache->get_memory_usage(1)) &&
2821 memory_usage > video_size ) {
2822 video_cache->delete_oldest();
2823 prev_memory_usage = memory_usage;
2826 prev_memory_usage = 0;
2828 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2829 while( !result && prev_memory_usage !=
2830 (memory_usage=audio_cache->get_memory_usage(1)) &&
2831 memory_usage > audio_size ) {
2832 audio_cache->delete_oldest();
2833 prev_memory_usage = memory_usage;
2837 void MWindow::reset_android_remote()
2839 gui->use_android_remote(preferences->android_remote);
2843 void MWindow::show_keyframe_gui(Plugin *plugin)
2845 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2846 // Find existing thread
2847 for(int i = 0; i < keyframe_threads->size(); i++)
2849 if(keyframe_threads->get(i)->plugin == plugin)
2851 keyframe_threads->get(i)->start_window(plugin, 0);
2852 keyframe_gui_lock->unlock();
2857 // Find unused thread
2858 for(int i = 0; i < keyframe_threads->size(); i++)
2860 if(!keyframe_threads->get(i)->plugin)
2862 keyframe_threads->get(i)->start_window(plugin, 0);
2863 keyframe_gui_lock->unlock();
2868 // Create new thread
2869 KeyFrameThread *thread = new KeyFrameThread(this);
2870 keyframe_threads->append(thread);
2871 thread->start_window(plugin, 0);
2873 keyframe_gui_lock->unlock();
2880 void MWindow::show_plugin(Plugin *plugin)
2885 // Remove previously deleted plugin GUIs
2886 dead_plugin_lock->lock("MWindow::show_plugin");
2887 dead_plugins->remove_all_objects();
2888 dead_plugin_lock->unlock();
2890 //printf("MWindow::show_plugin %d\n", __LINE__);
2894 plugin_gui_lock->lock("MWindow::show_plugin");
2895 for(int i = 0; i < plugin_guis->total; i++)
2897 // Pointer comparison
2898 if(plugin_guis->get(i)->plugin == plugin)
2900 plugin_guis->get(i)->raise_window();
2907 //printf("MWindow::show_plugin 1\n");
2908 if( !done && !plugin->track ) {
2909 printf("MWindow::show_plugin track not defined.\n");
2913 PluginServer *server = scan_plugindb(plugin->title,
2914 plugin->track->data_type);
2916 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2917 if(server && server->uses_gui)
2919 PluginServer *gui = new PluginServer(*server);
2920 plugin_guis->append(gui);
2921 // Needs mwindow to do GUI
2922 gui->set_mwindow(this);
2923 gui->open_plugin(0, preferences, edl, plugin);
2928 plugin_gui_lock->unlock();
2929 //printf("MWindow::show_plugin %d\n", __LINE__);
2932 //printf("MWindow::show_plugin 2\n");
2935 void MWindow::hide_plugin(Plugin *plugin, int lock)
2938 // Update the toggle
2939 gui->lock_window("MWindow::hide_plugin");
2940 gui->update(0, 1, 0, 0, 0, 0, 0);
2941 gui->unlock_window();
2943 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2944 for(int i = 0; i < plugin_guis->total; i++)
2946 if(plugin_guis->get(i)->plugin == plugin)
2948 PluginServer *ptr = plugin_guis->get(i);
2949 plugin_guis->remove(ptr);
2950 if(lock) plugin_gui_lock->unlock();
2951 // Last command executed in client side close
2952 // Schedule for deletion
2959 if(lock) plugin_gui_lock->unlock();
2962 void MWindow::delete_plugin(PluginServer *plugin)
2964 dead_plugin_lock->lock("MWindow::delete_plugin");
2965 dead_plugins->append(plugin);
2966 dead_plugin_lock->unlock();
2969 void MWindow::hide_plugins()
2971 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2972 while(plugin_guis->size())
2974 PluginServer *ptr = plugin_guis->get(0);
2975 plugin_guis->remove(ptr);
2976 plugin_gui_lock->unlock();
2977 // Last command executed in client side close
2978 // Schedule for deletion
2981 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2983 plugin_gui_lock->unlock();
2985 hide_keyframe_guis();
2988 void MWindow::hide_keyframe_guis()
2990 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2991 for(int i = 0; i < keyframe_threads->size(); i++)
2993 keyframe_threads->get(i)->close_window();
2995 keyframe_gui_lock->unlock();
2998 void MWindow::hide_keyframe_gui(Plugin *plugin)
3000 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
3001 for(int i = 0; i < keyframe_threads->size(); i++)
3003 if(keyframe_threads->get(i)->plugin == plugin)
3005 keyframe_threads->get(i)->close_window();
3009 keyframe_gui_lock->unlock();
3012 void MWindow::update_keyframe_guis()
3014 // Send new configuration to keyframe GUI's
3015 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
3016 for(int i = 0; i < keyframe_threads->size(); i++)
3018 KeyFrameThread *ptr = keyframe_threads->get(i);
3019 if(edl->tracks->plugin_exists(ptr->plugin))
3023 ptr->close_window();
3026 keyframe_gui_lock->unlock();
3029 void MWindow::update_plugin_guis(int do_keyframe_guis)
3031 // Send new configuration to plugin GUI's
3032 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3034 for(int i = 0; i < plugin_guis->size(); i++)
3036 PluginServer *ptr = plugin_guis->get(i);
3037 if(edl->tracks->plugin_exists(ptr->plugin))
3041 // Schedule for deletion if no plugin
3042 plugin_guis->remove_number(i);
3051 // Change plugin variable if not visible
3052 Track *track = edl->tracks->first;
3055 for(int i = 0; i < track->plugin_set.size(); i++)
3057 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3061 for(int i = 0; i < plugin_guis->size(); i++)
3063 PluginServer *server = plugin_guis->get(i);
3064 if(server->plugin == plugin)
3071 if(!got_it) plugin->show = 0;
3073 plugin = (Plugin*)plugin->next;
3077 track = track->next;
3080 plugin_gui_lock->unlock();
3083 if(do_keyframe_guis) update_keyframe_guis();
3086 int MWindow::plugin_gui_open(Plugin *plugin)
3089 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3090 for(int i = 0; i < plugin_guis->total; i++)
3092 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3098 plugin_gui_lock->unlock();
3102 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3104 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3105 for(int i = 0; i < plugin_guis->total; i++)
3107 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3109 plugin_guis->get(i)->render_gui(data);
3113 plugin_gui_lock->unlock();
3116 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3118 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3119 for(int i = 0; i < plugin_guis->total; i++)
3121 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3123 plugin_guis->get(i)->render_gui(data, size);
3127 plugin_gui_lock->unlock();
3131 void MWindow::update_plugin_states()
3133 plugin_gui_lock->lock("MWindow::update_plugin_states");
3134 for(int i = 0; i < plugin_guis->total; i++)
3138 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3139 PluginServer *src_plugingui = plugin_guis->get(i);
3141 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3142 for(Track *track = edl->tracks->first;
3144 track = track->next)
3147 j < track->plugin_set.total && !result;
3150 PluginSet *plugin_set = track->plugin_set[j];
3151 for(Plugin *plugin = (Plugin*)plugin_set->first;
3153 plugin = (Plugin*)plugin->next)
3155 if(plugin == src_plugin &&
3156 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3162 // Doesn't exist anymore
3165 hide_plugin(src_plugin, 0);
3169 plugin_gui_lock->unlock();
3173 void MWindow::update_plugin_titles()
3175 for(int i = 0; i < plugin_guis->total; i++)
3177 plugin_guis->get(i)->update_title();
3181 int MWindow::asset_to_edl(EDL *new_edl,
3183 RecordLabels *labels)
3185 const int debug = 0;
3186 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3189 // Keep frame rate, sample rate, and output size unchanged.
3190 // These parameters would revert the project if VWindow displayed an asset
3191 // of different size than the project.
3192 if(new_asset->video_data)
3194 new_edl->session->video_tracks = new_asset->layers;
3197 new_edl->session->video_tracks = 0;
3199 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3205 if(new_asset->audio_data)
3207 new_edl->session->audio_tracks = new_asset->channels;
3210 new_edl->session->audio_tracks = 0;
3211 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3213 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3214 new_edl->create_default_tracks();
3215 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3216 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3220 //printf("MWindow::asset_to_edl 3\n");
3221 new_edl->insert_asset(new_asset,
3226 //printf("MWindow::asset_to_edl 3\n");
3227 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3229 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3230 if(edl->session->cursor_on_frames)
3232 double length = new_edl->tracks->total_length();
3233 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3234 new_edl->tracks->clear(length, edl_length, 1, 1);
3240 char string[BCTEXTLEN];
3242 fs.extract_name(string, new_asset->path);
3243 //printf("MWindow::asset_to_edl 3\n");
3245 strcpy(new_edl->local_session->clip_title, string);
3246 //printf("MWindow::asset_to_edl 4 %s\n", string);
3247 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3253 // Reset everything after a load.
3254 void MWindow::update_project(int load_mode)
3256 const int debug = 0;
3258 if(debug) PRINT_TRACE
3259 edl->tracks->update_y_pixels(theme);
3261 if(debug) PRINT_TRACE
3263 if(load_mode == LOADMODE_REPLACE ||
3264 load_mode == LOADMODE_REPLACE_CONCATENATE)
3269 gui->update(1, 1, 1, 1, 1, 1, 1);
3270 if(debug) PRINT_TRACE
3271 gui->unlock_window();
3274 cwindow->gui->lock_window("MWindow::update_project 1");
3275 cwindow->update(0, 0, 1, 1, 1);
3276 cwindow->gui->unlock_window();
3278 if(debug) PRINT_TRACE
3280 // Close all the vwindows
3281 if( load_mode == LOADMODE_REPLACE ||
3282 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3283 if(debug) PRINT_TRACE
3284 int first_vwindow = 0;
3285 if(session->show_vwindow) first_vwindow = 1;
3286 // Change visible windows to no source
3287 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3288 VWindow *vwindow = vwindows[i];
3289 if( !vwindow->is_running() ) continue;
3290 vwindow->change_source(-1);
3293 // Close remaining windows
3294 for(int i = first_vwindow; i < vwindows.size(); i++) {
3295 VWindow *vwindow = vwindows[i];
3296 if( !vwindow->is_running() ) continue;
3297 vwindow->close_window();
3299 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3300 VWindow *vwindow = get_viewer(1, -1);
3301 vwindow->change_source(i);
3303 if(debug) PRINT_TRACE
3307 for( int i=0; i<edl->mixers.size(); ++i ) {
3308 Mixer *mixer = edl->mixers[i];
3309 ZWindow *zwindow = get_mixer(mixer);
3310 zwindow->set_title(mixer->title);
3315 if(vwindows.size()) {
3316 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3317 if( vwindow->is_running() ) {
3318 vwindow->gui->lock_window("MWindow::update_project");
3320 vwindow->gui->unlock_window();
3325 if(debug) PRINT_TRACE
3326 cwindow->gui->lock_window("MWindow::update_project 2");
3327 cwindow->gui->timebar->update(0);
3328 cwindow->gui->unlock_window();
3330 if(debug) PRINT_TRACE
3331 cwindow->refresh_frame(CHANGE_ALL);
3333 awindow->gui->async_update_assets();
3334 if(debug) PRINT_TRACE
3336 gui->lock_window("MWindow::update_project");
3337 gui->update_mixers(0, 0);
3339 if(debug) PRINT_TRACE
3342 void MWindow::remove_indexfile(Indexable *indexable)
3344 if( !indexable->is_asset ) return;
3345 Asset *asset = (Asset *)indexable;
3347 IndexFile::delete_index(preferences, asset, ".toc");
3348 IndexFile::delete_index(preferences, asset, ".idx");
3349 IndexFile::delete_index(preferences, asset, ".mkr");
3352 void MWindow::rebuild_indices()
3354 for(int i = 0; i < session->drag_assets->total; i++)
3356 Indexable *indexable = session->drag_assets->get(i);
3357 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3358 remove_indexfile(indexable);
3359 // Schedule index build
3360 IndexState *index_state = indexable->index_state;
3361 index_state->index_status = INDEX_NOTTESTED;
3362 if( indexable->is_asset ) {
3363 Asset *asset = (Asset *)indexable;
3364 if( asset->format != FILE_PCM ) {
3365 asset->format = FILE_UNKNOWN;
3366 asset->reset_audio();
3368 asset->reset_video();
3369 remove_asset_from_caches(asset);
3370 // File file; // re-probe the asset
3371 // file.open_file(preferences, asset, 1, 0);
3373 mainindexes->add_next_asset(0, indexable);
3375 mainindexes->start_build();
3379 void MWindow::save_backup()
3383 edl->set_path(session->filename);
3384 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3385 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3386 File::get_config_path(), BACKUP_FILE);
3387 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3388 File::get_config_path(), BACKUP_FILE1);
3389 rename(backup_path, backup_path1);
3390 edl->save_xml(&file, backup_path);
3391 file.terminate_string();
3393 fs.complete_path(backup_path);
3395 if(file.write_to_file(backup_path))
3398 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3399 gui->show_message(string2);
3403 void MWindow::load_backup()
3405 ArrayList<char*> path_list;
3406 path_list.set_array_delete();
3408 char backup_path[BCTEXTLEN];
3409 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3410 File::get_config_path(), BACKUP_FILE);
3412 fs.complete_path(backup_path);
3414 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3415 strcpy(out_path, backup_path);
3417 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3418 edl->local_session->clip_title[0] = 0;
3419 // This is unique to backups since the path of the backup is different than the
3420 // path of the project.
3421 set_filename(edl->path);
3422 path_list.remove_all_objects();
3427 void MWindow::save_undo_data()
3429 char perpetual_path[BCTEXTLEN];
3430 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3431 File::get_config_path(), PERPETUAL_FILE);
3432 FILE *fp = fopen(perpetual_path,"w");
3438 void MWindow::load_undo_data()
3440 char perpetual_path[BCTEXTLEN];
3441 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3442 File::get_config_path(), PERPETUAL_FILE);
3443 FILE *fp = fopen(perpetual_path,"r");
3449 static inline int gcd(int m, int n)
3452 if( m < n ) { r = m; m = n; n = r; }
3453 while( (r = m % n) != 0 ) { m = n; n = r; }
3457 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3460 if(!width || !height) return 1;
3461 if( width == 720 && (height == 480 || height == 576) ) {
3462 w = 4; h = 3; return 0; // for NTSC and PAL
3464 double ar = (double)width / height;
3465 // square-ish pixels
3466 if( EQUIV(ar, 1.0000) ) return 0;
3467 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3468 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3469 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3470 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3471 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3472 int ww = width, hh = height;
3473 // numerator, denominator must be under mx
3474 int mx = 255, n = gcd(ww, hh);
3475 if( n > 1 ) { ww /= n; hh /= n; }
3476 // search near height in case extra/missing lines
3477 if( ww >= mx || hh >= mx ) {
3478 double err = height; // +/- 2 percent height
3479 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3480 int iw = width, ih = height+i;
3481 if( (n=gcd(iw, ih)) > 1 ) {
3482 int u = iw/n; if( u >= mx ) continue;
3483 int v = ih/n; if( v >= mx ) continue;
3484 double r = (double) u/v, er = fabs(ar-r);
3485 if( er >= err ) continue;
3486 err = er; ww = u; hh = v;
3495 void MWindow::reset_caches()
3497 frame_cache->remove_all();
3498 wave_cache->remove_all();
3499 audio_cache->remove_all();
3500 video_cache->remove_all();
3501 if( cwindow->playback_engine ) {
3502 if( cwindow->playback_engine->audio_cache )
3503 cwindow->playback_engine->audio_cache->remove_all();
3504 if( cwindow->playback_engine->video_cache )
3505 cwindow->playback_engine->video_cache->remove_all();
3507 for(int i = 0; i < vwindows.size(); i++) {
3508 VWindow *vwindow = vwindows[i];
3509 if( !vwindow->is_running() ) continue;
3510 if( !vwindow->playback_engine ) continue;
3511 if( vwindow->playback_engine->audio_cache )
3512 vwindow->playback_engine->audio_cache->remove_all();
3513 if( vwindow->playback_engine->video_cache )
3514 vwindow->playback_engine->video_cache->remove_all();
3518 void MWindow::remove_asset_from_caches(Asset *asset)
3520 frame_cache->remove_asset(asset);
3521 wave_cache->remove_asset(asset);
3522 audio_cache->delete_entry(asset);
3523 video_cache->delete_entry(asset);
3524 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3525 cwindow->playback_engine->audio_cache->delete_entry(asset);
3526 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3527 cwindow->playback_engine->video_cache->delete_entry(asset);
3528 for(int i = 0; i < vwindows.size(); i++) {
3529 VWindow *vwindow = vwindows[i];
3530 if( !vwindow->is_running() ) continue;
3531 if( !vwindow->playback_engine ) continue;
3532 if( vwindow->playback_engine->audio_cache )
3533 vwindow->playback_engine->audio_cache->delete_entry(asset);
3534 if( vwindow->playback_engine->video_cache )
3535 vwindow->playback_engine->video_cache->delete_entry(asset);
3540 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3541 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3543 for(int i = 0; i < drag_assets->total; i++) {
3544 Indexable *indexable = drag_assets->get(i);
3545 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3548 // Remove from VWindow.
3549 for(int i = 0; i < session->drag_clips->total; i++) {
3550 for(int j = 0; j < vwindows.size(); j++) {
3551 VWindow *vwindow = vwindows[j];
3552 if( !vwindow->is_running() ) continue;
3553 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3554 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3555 vwindow->delete_source(1, 1);
3556 vwindow->gui->unlock_window();
3561 for(int i = 0; i < drag_assets->size(); i++) {
3562 for(int j = 0; j < vwindows.size(); j++) {
3563 VWindow *vwindow = vwindows[j];
3564 if( !vwindow->is_running() ) continue;
3565 if(drag_assets->get(i) == vwindow->get_source()) {
3566 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3567 vwindow->delete_source(1, 1);
3568 vwindow->gui->unlock_window();
3573 for(int i = 0; i < drag_assets->size(); i++) {
3574 Indexable *indexable = drag_assets->get(i);
3575 remove_indexfile(indexable);
3578 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3579 if(push_undo) undo->update_undo_before();
3580 if(drag_assets) edl->remove_from_project(drag_assets);
3581 if(drag_clips) edl->remove_from_project(drag_clips);
3582 if(redraw) save_backup();
3583 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3587 gui->lock_window("MWindow::remove_assets_from_project 3");
3588 gui->update(1, 1, 1, 1, 0, 1, 0);
3589 gui->unlock_window();
3591 // Removes from playback here
3592 sync_parameters(CHANGE_ALL);
3595 awindow->gui->async_update_assets();
3598 void MWindow::remove_assets_from_disk()
3601 for(int i = 0; i < session->drag_assets->total; i++)
3603 remove(session->drag_assets->get(i)->path);
3606 remove_assets_from_project(1,
3608 session->drag_assets,
3609 session->drag_clips);
3612 void MWindow::dump_plugins(FILE *fp)
3614 if( !plugindb ) return;
3615 for(int i = 0; i < plugindb->total; i++)
3617 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3618 " synth=%d transition=%d theme=%d %s\n",
3619 plugindb->get(i)->plugin_type,
3620 plugindb->get(i)->audio,
3621 plugindb->get(i)->video,
3622 plugindb->get(i)->realtime,
3623 plugindb->get(i)->multichannel,
3624 plugindb->get(i)->get_synthesis(),
3625 plugindb->get(i)->transition,
3626 plugindb->get(i)->theme,
3627 plugindb->get(i)->title);
3631 void MWindow::dump_edl(FILE *fp)
3637 void MWindow::dump_undo(FILE *fp)
3643 void MWindow::dump_exe(FILE *fp)
3645 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3646 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3648 int ret = -1, n = 100;
3649 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3650 exe_path[len] = 0; strcpy(proc_path, exe_path);
3653 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3656 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3657 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3658 struct tm *tm = localtime(&st.st_mtime);
3660 strftime(mtime, sizeof(mtime), "%F %T", tm);
3661 fprintf(fp,"mtime: %s\n", mtime);
3663 // people hit ctl-c waiting for this
3664 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3665 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3668 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3669 int64_t maxsz = 1024*pagsz;
3670 int64_t size = st.st_size, pos = 0;
3672 while( (bfrsz = size-pos) > 0 ) {
3673 if( bfrsz > maxsz ) bfrsz = maxsz;
3674 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3675 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3676 if( bfr == MAP_FAILED ) break;
3677 sha1.addBytes(bfr, bfrsz);
3682 ret = pos < size ? EIO : 0;
3683 fprintf(fp, "SHA1: ");
3684 uint8_t digest[20]; sha1.computeHash(digest);
3685 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3686 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3687 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3692 void MWindow::trap_hook(FILE *fp, void *vp)
3694 MWindow *mwindow = (MWindow *)vp;
3695 // fprintf(fp, "\nPLUGINS:\n");
3696 // mwindow->dump_plugins(fp);
3697 fprintf(fp, "\nEDL:\n");
3698 mwindow->dump_edl(fp);
3699 fprintf(fp, "\nUNDO:\n");
3700 mwindow->dump_undo(fp);
3701 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
3702 mwindow->dump_exe(fp);
3710 int MWindow::save_defaults()
3712 gui->save_defaults(defaults);
3713 edl->save_defaults(defaults);
3714 session->save_defaults(defaults);
3715 preferences->save_defaults(defaults);
3717 for(int i = 0; i < plugin_guis->total; i++)
3719 // Pointer comparison
3720 plugin_guis->get(i)->save_defaults();
3722 awindow->save_defaults(defaults);
3728 int MWindow::run_script(FileXML *script)
3730 int result = 0, result2 = 0;
3731 while(!result && !result2)
3733 result = script->read_tag();
3736 if(script->tag.title_is("new_project"))
3738 // Run new in immediate mode.
3739 // gui->mainmenu->new_project->run_script(script);
3742 if(script->tag.title_is("record"))
3744 // Run record as a thread. It is a terminal command.
3746 // Will read the complete scipt file without letting record read it if not
3752 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3759 // ================================= synchronization
3762 int MWindow::interrupt_indexes()
3764 mainprogress->cancelled = 1;
3765 mainindexes->interrupt_build();
3771 void MWindow::next_time_format()
3773 switch(edl->session->time_format)
3775 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3776 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3777 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3778 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3779 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3780 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3781 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3784 time_format_common();
3787 void MWindow::prev_time_format()
3789 switch(edl->session->time_format)
3791 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3792 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3793 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3794 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3795 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3796 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3797 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3800 time_format_common();
3803 void MWindow::time_format_common()
3805 gui->lock_window("MWindow::next_time_format");
3806 gui->redraw_time_dependancies();
3809 char string[BCTEXTLEN], string2[BCTEXTLEN];
3810 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3811 gui->show_message(string);
3813 gui->unlock_window();
3817 int MWindow::set_filename(const char *filename)
3819 if( filename != session->filename )
3820 strcpy(session->filename, filename);
3821 if( filename != edl->path )
3822 strcpy(edl->path, filename);
3826 if(filename[0] == 0)
3828 gui->set_title(PROGRAM_NAME);
3833 char string[BCTEXTLEN], string2[BCTEXTLEN];
3834 dir.extract_name(string, filename);
3835 sprintf(string2, PROGRAM_NAME ": %s", string);
3836 gui->set_title(string2);
3849 int MWindow::set_loop_boundaries()
3851 double start = edl->local_session->get_selectionstart();
3852 double end = edl->local_session->get_selectionend();
3860 if(edl->tracks->total_length())
3863 end = edl->tracks->total_length();
3870 if(edl->local_session->loop_playback && start != end)
3872 edl->local_session->loop_start = start;
3873 edl->local_session->loop_end = end;
3884 int MWindow::reset_meters()
3886 cwindow->gui->lock_window("MWindow::reset_meters 1");
3887 cwindow->gui->meters->reset_meters();
3888 cwindow->gui->unlock_window();
3890 for(int j = 0; j < vwindows.size(); j++) {
3891 VWindow *vwindow = vwindows[j];
3892 if( !vwindow->is_running() ) continue;
3893 vwindow->gui->lock_window("MWindow::reset_meters 2");
3894 vwindow->gui->meters->reset_meters();
3895 vwindow->gui->unlock_window();
3898 lwindow->gui->lock_window("MWindow::reset_meters 3");
3899 lwindow->gui->panel->reset_meters();
3900 lwindow->gui->unlock_window();
3902 gui->lock_window("MWindow::reset_meters 4");
3903 gui->reset_meters();
3904 gui->unlock_window();
3909 void MWindow::resync_guis()
3913 gui->lock_window("MWindow::resync_guis");
3914 gui->update(1, 1, 1, 1, 1, 1, 0);
3915 gui->unlock_window();
3917 cwindow->gui->lock_window("MWindow::resync_guis");
3918 cwindow->gui->resize_event(cwindow->gui->get_w(),
3919 cwindow->gui->get_h());
3920 int channels = edl->session->audio_channels;
3921 cwindow->gui->meters->set_meters(channels, 1);
3922 cwindow->gui->flush();
3923 cwindow->gui->unlock_window();
3925 for(int i = 0; i < vwindows.size(); i++) {
3926 VWindow *vwindow = vwindows[i];
3927 if( !vwindow->is_running() ) continue;
3928 vwindow->gui->lock_window("MWindow::resync_guis");
3929 vwindow->gui->resize_event(vwindow->gui->get_w(),
3930 vwindow->gui->get_h());
3931 vwindow->gui->meters->set_meters(channels, 1);
3932 vwindow->gui->flush();
3933 vwindow->gui->unlock_window();
3936 lwindow->gui->lock_window("MWindow::resync_guis");
3937 lwindow->gui->panel->set_meters(channels, 1);
3938 lwindow->gui->flush();
3939 lwindow->gui->unlock_window();
3942 if(((edl->session->output_w % 4) ||
3943 (edl->session->output_h % 4)) &&
3944 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3946 MainError::show_error(
3947 _("This project's dimensions are not multiples of 4 so\n"
3948 "it can't be rendered by OpenGL."));
3953 sync_parameters(CHANGE_ALL);
3956 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3958 File *file = new File;
3959 EDLSession *session = edl->session;
3960 double old_framerate = session->frame_rate;
3961 double old_samplerate = session->sample_rate;
3962 int old_auto_keyframes = session->auto_keyframes;
3963 session->auto_keyframes = 0;
3964 int result = file->open_file(preferences, asset, 1, 0);
3965 if( !result && delete_tracks > 0 )
3966 undo->update_undo_before();
3967 int video_layers = asset->get_video_layers();
3968 if( !result && asset->video_data && vstream < video_layers ) {
3969 // try to get asset up to date, may fail
3970 file->select_video_stream(asset, vstream);
3971 // either way use what was/is there.
3972 double framerate = asset->get_frame_rate();
3973 int width = asset->get_w();
3974 int height = asset->get_h();
3975 // must be multiple of 4 for opengl
3976 width = (width+3) & ~3; height = (height+3) & ~3;
3977 int driver = session->playback_config->vconfig->driver;
3978 int color_model = file->get_best_colormodel(asset, driver);
3979 // color_model = BC_CModels::is_yuv(color_model) ?
3980 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3981 // BC_CModels::is_float(color_model) ?
3982 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3983 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3984 // have alpha for now
3985 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3986 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3987 session->color_model = color_model;
3988 session->output_w = width;
3989 session->output_h = height;
3990 session->frame_rate = framerate;
3991 // not, asset->actual_width/actual_height
3992 asset->width = session->output_w;
3993 asset->height = session->output_h;
3994 asset->frame_rate = session->frame_rate;
3995 create_aspect_ratio(session->aspect_w, session->aspect_h,
3996 session->output_w, session->output_h);
3997 Track *track = edl->tracks->first;
3998 for( Track *next_track=0; track; track=next_track ) {
3999 next_track = track->next;
4000 if( track->data_type != TRACK_VIDEO ) continue;
4001 if( delete_tracks ) {
4002 Edit *edit = track->edits->first;
4003 for( Edit *next_edit=0; edit; edit=next_edit ) {
4004 next_edit = edit->next;
4005 if( edit->channel != vstream ||
4006 !edit->asset || !edit->asset->is_asset ||
4007 !asset->equivalent(*edit->asset,1,1,edl) )
4011 if( track->edits->first ) {
4012 track->track_w = edl->session->output_w;
4013 track->track_h = edl->session->output_h;
4015 else if( delete_tracks )
4016 edl->tracks->delete_track(track);
4019 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
4021 if( !result && asset->audio_data && asset->channels > 0 ) {
4022 session->sample_rate = asset->get_sample_rate();
4023 int64_t channel_mask = 0;
4024 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4025 file->get_audio_for_video(vstream, astream, channel_mask);
4026 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4027 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4029 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4030 if( channels < 1 ) channels = 1;
4031 if( channels > 6 ) channels = 6;
4032 session->audio_tracks = session->audio_channels = channels;
4034 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4035 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4036 remap_audio(MWindow::AUDIO_1_TO_1);
4038 if( delete_tracks ) {
4039 Track *track = edl->tracks->first;
4040 for( Track *next_track=0; track; track=next_track ) {
4041 next_track = track->next;
4042 if( track->data_type != TRACK_AUDIO ) continue;
4043 Edit *edit = track->edits->first;
4044 for( Edit *next_edit=0; edit; edit=next_edit ) {
4045 next_edit = edit->next;
4046 if( !((1<<edit->channel) & channel_mask) ||
4047 !edit->asset || !edit->asset->is_asset ||
4048 !asset->equivalent(*edit->asset,1,1,edl) )
4051 if( !track->edits->first )
4052 edl->tracks->delete_track(track);
4056 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4059 session->auto_keyframes = old_auto_keyframes;
4060 if( !result && delete_tracks > 0 ) {
4062 undo->update_undo_after(_("select asset"), LOAD_ALL);
4068 int MWindow::select_asset(int vtrack, int delete_tracks)
4070 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4072 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4073 if( !track ) return 1;
4074 Edit *edit = track->edits->first;
4075 if( !edit ) return 1;
4076 Asset *asset = edit->asset;
4077 if( !asset || !asset->is_asset ) return 1;
4078 return select_asset(asset, edit->channel, 0, delete_tracks);
4081 void MWindow::dump_plugindb(FILE *fp)
4083 if( !plugindb ) return;
4084 for(int i = 0; i < plugindb->total; i++)
4085 plugindb->get(i)->dump(fp);
4088 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4091 double unit_position = edl->local_session->get_selectionstart(1);
4092 unit_position = patch->track->to_units(unit_position, 0);
4094 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4095 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4098 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4101 double unit_position = edl->local_session->get_selectionstart(1);
4102 unit_position = patch->track->to_units(unit_position, 0);
4104 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4105 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4108 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4111 double unit_position = edl->local_session->get_selectionstart(1);
4112 unit_position = patch->track->to_units(unit_position, 0);
4114 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4115 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4118 PatchGUI *MWindow::get_patchgui(Track *track)
4120 PatchGUI *patchgui = 0;
4121 TimelinePane **panes = gui->pane;
4122 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4123 if( !panes[i] ) continue;
4124 PatchBay *patchbay = panes[i]->patchbay;
4125 if( !patchbay ) continue;
4126 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4127 if( patchbay->patches.values[j]->track == track )
4128 patchgui = patchbay->patches.values[j];