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;
216 keyframe_threads = 0;
236 // Need to delete brender temporary here.
239 run_lock->lock("MWindow::~MWindow");
241 //printf("MWindow::~MWindow %d\n", __LINE__);
242 gui->remote_control->deactivate();
245 gui->channel_info->stop();
247 delete create_bd; create_bd = 0;
248 delete create_dvd; create_dvd = 0;
249 delete batch_render; batch_render = 0;
250 delete render; render = 0;
252 if( commercials && !commercials->remove_user() ) commercials = 0;
255 // Save defaults for open plugins
256 plugin_gui_lock->lock("MWindow::~MWindow");
257 for(int i = 0; i < plugin_guis->size(); i++) {
258 plugin_guis->get(i)->hide_gui();
259 delete_plugin(plugin_guis->get(i));
261 plugin_gui_lock->unlock();
262 hide_keyframe_guis();
265 // Give up and go to a movie
266 // cant run valgrind if this is used
268 gui->del_keyboard_listener(
269 (int (BC_WindowBase::*)(BC_WindowBase *))
270 &MWindowGUI::keyboard_listener);
272 // release the hounds
273 if( awindow && awindow->gui ) awindow->gui->close(0);
274 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
275 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
276 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
277 if( twindow && twindow->is_running() ) twindow->close_window();
278 if( wwindow && wwindow->is_running() ) wwindow->close_window();
279 vwindows.remove_all_objects();
280 zwindows.remove_all_objects();
282 if( awindow ) awindow->join();
283 if( cwindow ) cwindow->join();
284 if( lwindow ) lwindow->join();
285 if( twindow ) twindow->join();
286 if( wwindow ) wwindow->join();
287 if( gwindow ) gwindow->join();
290 // one at a time, or nouveau chokes
291 #define close_gui(win) if( win ) { \
292 if( win->gui ) win->gui->close(0); \
300 vwindows.remove_all_objects();
301 zwindows.remove_all_objects();
306 dead_plugins->remove_all_objects();
307 // must delete theme before destroying plugindb
308 // theme destructor will be deleted by delete_plugins
309 delete theme; theme = 0;
312 keyframe_threads->remove_all_objects();
313 colormodels.remove_all_objects();
314 delete awindow; awindow = 0;
315 delete lwindow; lwindow = 0;
316 delete twindow; twindow = 0;
317 delete wwindow; wwindow = 0;
318 delete gwindow; gwindow = 0;
319 delete cwindow; cwindow = 0;
321 //delete file_server; file_server = 0; // reusable
322 delete mainindexes; mainindexes = 0;
323 delete mainprogress; mainprogress = 0;
324 delete audio_cache; audio_cache = 0; // delete the cache after the assets
325 delete video_cache; video_cache = 0; // delete the cache after the assets
326 delete frame_cache; frame_cache = 0;
327 delete wave_cache; wave_cache = 0;
328 delete plugin_guis; plugin_guis = 0;
329 delete dead_plugins; dead_plugins = 0;
330 delete keyframe_threads; keyframe_threads = 0;
331 delete undo; undo = 0;
332 delete preferences; preferences = 0;
333 delete exportedl; exportedl = 0;
334 delete session; session = 0;
335 delete defaults; defaults = 0;
336 delete assets; assets = 0;
337 delete splash_window; splash_window = 0;
338 if( !edl->Garbage::remove_user() ) edl = 0;
339 delete channeldb_buz;
340 delete channeldb_v4l2jpeg;
341 // This must be last thread to exit
342 delete playback_3d; playback_3d = 0;
343 delete dead_plugin_lock;
344 delete plugin_gui_lock;
345 delete vwindows_lock;
346 delete zwindows_lock;
348 delete keyframe_gui_lock;
349 colormodels.remove_all_objects();
350 interlace_project_modes.remove_all_objects();
351 interlace_asset_modes.remove_all_objects();
352 interlace_asset_fixmethods.remove_all_objects();
353 sighandler->terminate();
364 void MWindow::init_error()
366 MainError::init_error(this);
369 void MWindow::finit_error()
371 MainError::finit_error();
374 void MWindow::create_defaults_path(char *string, const char *config_file)
376 // set the .bcast path
379 sprintf(string, "%s/", File::get_config_path());
380 fs.complete_path(string);
381 if(!fs.is_dir(string))
382 fs.create_dir(string);
385 strcat(string, config_file);
387 const char *MWindow::default_std()
389 char buf[BCTEXTLEN], *p = 0;
391 int fd = open(TIMEZONE_NAME, O_RDONLY);
393 int l = read(fd, buf, sizeof(buf)-1);
396 if( buf[l-1] == '\n' ) --l;
402 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
405 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
406 p += strlen(ZONEINFO_STR);
411 for( int i=0; ntsc_zones[i]; ++i ) {
412 if( !strcmp(ntsc_zones[i], p) )
419 for( int i=0; ntsc_zones[i]; ++i ) {
420 if( !strcmp(ntsc_zones[i], p) )
425 //__timezone: Seconds west of UTC. 240sec/deg
426 double tz_deg = -__timezone / 240.;
427 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
428 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
431 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
433 struct formatpresets *fpr;
435 for(fpr = &format_presets[0]; fpr->name; fpr++)
437 if(strcmp(_(fpr->name), preset) == 0)
439 session->audio_channels = fpr->audio_channels;
440 session->audio_tracks = fpr->audio_tracks;
441 session->sample_rate = fpr->sample_rate;
442 session->video_channels = fpr->video_channels;
443 session->video_tracks = fpr->video_tracks;
444 session->frame_rate = fpr->frame_rate;
445 session->output_w = fpr->output_w;
446 session->output_h = fpr->output_h;
447 session->aspect_w = fpr->aspect_w;
448 session->aspect_h = fpr->aspect_h;
449 session->interlace_mode = fpr->interlace_mode;
450 session->color_model = fpr->color_model;
456 const char *MWindow::get_preset_name(int index)
458 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
460 return _(format_presets[index].name);
464 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
466 char path[BCTEXTLEN];
467 // Use user supplied path
469 strcpy(path, config_path);
471 create_defaults_path(path, CONFIG_FILE);
473 defaults = new BC_Hash(path);
478 void MWindow::check_language()
480 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
481 const char *env_lang = getenv("LANGUAGE");
482 if( !env_lang ) env_lang = getenv("LC_ALL");
483 if( !env_lang ) env_lang = getenv("LANG");
485 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
486 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
487 env_lang = curr_lang;
489 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
490 defaults->get("LAST_LANG",last_lang);
491 if( strcmp(env_lang,last_lang)) {
492 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
493 defaults->update("LAST_LANG",env_lang);
494 char plugin_path[BCTEXTLEN];
495 create_defaults_path(plugin_path, PLUGIN_FILE);
496 ::remove(plugin_path);
497 char ladspa_path[BCTEXTLEN];
498 create_defaults_path(ladspa_path, LADSPA_FILE);
499 ::remove(ladspa_path);
502 if( strlen(env_lang) > 1 &&
503 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
504 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
507 strcpy(cin_lang, "en");
510 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
512 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
514 const char *dp = plug_dir;
515 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
516 bp = !*dp && *bp == '/' ? bp+1 : base_path;
522 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
525 FILE *fp = fopen(index_path, "r");
529 char index_line[BCTEXTLEN];
530 int index_version = -1, len = strlen(plugin_dir);
531 if( !fgets(index_line, BCTEXTLEN, fp) ||
532 sscanf(index_line, "%d", &index_version) != 1 ||
533 index_version != PLUGIN_FILE_VERSION ||
534 !fgets(index_line, BCTEXTLEN, fp) ||
535 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
536 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
538 ArrayList<PluginServer*> plugins;
539 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
540 if( index_line[0] == ';' ) continue;
541 if( index_line[0] == '#' ) continue;
542 int type = PLUGIN_TYPE_UNKNOWN;
543 char path[BCTEXTLEN], title[BCTEXTLEN];
545 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
548 PluginServer *server = 0;
550 case PLUGIN_TYPE_BUILTIN:
551 case PLUGIN_TYPE_EXECUTABLE:
552 case PLUGIN_TYPE_LADSPA: {
553 char plugin_path[BCTEXTLEN]; struct stat st;
554 sprintf(plugin_path, "%s/%s", plugin_dir, path);
555 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
558 server = new PluginServer(mwindow, plugin_path, type);
560 case PLUGIN_TYPE_FFMPEG: {
561 server = new_ffmpeg_server(mwindow, path);
564 if( !server ) continue;
565 plugins.append(server);
566 // Create plugin server from index entry
567 server->set_title(title);
568 if( server->read_table(index_line) ) {
575 ret = check_plugin_index(plugins, plugin_dir, ".");
578 add_plugins(plugins);
580 plugins.remove_all_objects();
585 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
586 const char *plug_dir, const char *plug_path)
588 char plugin_path[BCTEXTLEN];
589 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
591 fs.set_filter( "[*.plugin][*.so]" );
592 if( fs.update(plugin_path) )
595 for( int i=0; i<fs.dir_list.total; ++i ) {
596 char fs_path[BCTEXTLEN];
597 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
598 if( fs.is_dir(fs_path) ) {
599 get_plugin_path(plugin_path, plug_dir, fs_path);
600 if( check_plugin_index(plugins, plug_dir, plugin_path) )
603 else if( !plugin_exists(fs_path, plugins) )
610 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
613 plugindb = new ArrayList<PluginServer*>;
615 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
616 create_defaults_path(index_path, PLUGIN_FILE);
617 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
618 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
619 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
620 printf("init plugin index: %s\n", plugin_path);
621 FILE *fp = fopen(index_path,"w");
623 fprintf(stderr,_("MWindow::init_plugins: "
624 "can't create plugin index: %s\n"), index_path);
627 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
628 fprintf(fp, "%s\n", plugin_path);
629 init_plugin_index(mwindow, preferences, fp, plugin_path);
630 init_ffmpeg_index(mwindow, preferences, fp);
632 return load_plugin_index(mwindow, index_path, plugin_path);
635 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
637 char *path = getenv("LADSPA_PATH");
638 char ladspa_path[BCTEXTLEN];
640 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
643 for( int len=0; *path; path+=len ) {
644 char *cp = strchr(path,':');
645 len = !cp ? strlen(path) : cp-path;
646 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
647 memcpy(plugin_path, path, len); plugin_path[len] = 0;
649 char *plugin_dir = FileSystem::basepath(plugin_path);
650 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
651 create_defaults_path(index_path, LADSPA_FILE);
652 cp = index_path + strlen(index_path);
653 for( char *bp=plugin_path; *bp!=0; ++bp )
654 *cp++ = *bp=='/' ? '_' : *bp;
656 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
657 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
658 load_plugin_index(mwindow, index_path, plugin_path);
663 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
664 FILE *fp, const char *plugin_dir)
666 int idx = PLUGIN_IDS;
668 for( int i=0; i<plugindb->size(); ++i ) {
669 PluginServer *server = plugindb->get(i);
670 if( server->dir_idx >= idx )
671 idx = server->dir_idx+1;
674 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
677 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
678 const char *index_path, const char *plugin_dir)
680 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
681 strcpy(plugin_path, path); delete [] path;
682 printf("init ladspa index: %s\n", plugin_dir);
683 FILE *fp = fopen(index_path,"w");
685 fprintf(stderr,_("MWindow::init_ladspa_index: "
686 "can't create plugin index: %s\n"), index_path);
689 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
690 fprintf(fp, "%s\n", plugin_dir);
691 init_plugin_index(mwindow, preferences, fp, plugin_path);
696 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
697 const char *plug_dir, const char *plug_path, int &idx)
699 char plugin_path[BCTEXTLEN];
700 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
702 fs.set_filter( "[*.plugin][*.so]" );
703 int result = fs.update(plugin_path);
704 if( result || !fs.dir_list.total ) return;
707 for( int i=0; i<fs.dir_list.total; ++i ) {
708 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
709 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
710 get_plugin_path(path, plug_dir, fs_path);
711 if( fs.is_dir(fs_path) ) {
712 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
715 if( plugin_exists(path) ) continue;
717 if( stat(fs_path, &st) ) continue;
718 int64_t mtime = st.st_mtime;
719 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
720 result = server.open_plugin(1, preferences, 0, 0);
722 server.write_table(fp, path, vis_id, mtime);
723 server.close_plugin();
725 else if( result == PLUGINSERVER_IS_LAD ) {
728 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
729 ladspa.set_lad_index(lad_index++);
730 result = ladspa.open_plugin(1, preferences, 0, 0);
732 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
733 ladspa.close_plugin();
739 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
741 for( int i=0; i<plugins.size(); ++i )
742 plugindb->append(plugins[i]);
743 plugins.remove_all();
746 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
748 const char *cfg_path = File::get_cindat_path();
749 char msg_path[BCTEXTLEN]; int txt = 0;
751 if( BC_Resources::language[0] ) {
752 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
754 fp = fopen(msg_path, "r");
758 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
760 fp = fopen(msg_path, "r");
763 char text[BCTEXTLEN];
764 char *tp = text, *ep = tp + sizeof(text)-1;
765 char title[BCTEXTLEN];
770 char line[BCTEXTLEN], *cp = line;
771 if( fgets(line,sizeof(line)-1,fp) ) {
772 if( *cp == '#' ) continue;
773 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
776 if( tp > text && *--tp == '\n' ) *tp = 0;
778 tp = !txt ? title : _(title);
779 int idx = plugins.size();
780 while( --idx>=0 && strcmp(plugins[idx]->title, tp) );
782 delete [] plugins[idx]->tip;
783 plugins[idx]->tip = cstrdup(text);
787 if( done > 0 ) break;
789 char *dp = strchr(cp, ':');
791 printf("plugin tips: error on line %d\n", no);
795 while( cp < dp ) *bp++ = *cp++;
800 while( *cp == ' ' || *cp == '\t' ) ++cp;
801 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
806 void MWindow::delete_plugins()
808 plugindb->remove_all_objects();
813 void MWindow::search_plugindb(int do_audio,
818 ArrayList<PluginServer*> &results)
821 for(int i = 0; i < MWindow::plugindb->total; i++)
823 PluginServer *current = MWindow::plugindb->get(i);
825 if(current->audio == do_audio &&
826 current->video == do_video &&
827 (current->realtime == is_realtime || is_realtime < 0) &&
828 current->transition == is_transition &&
829 current->theme == is_theme)
830 results.append(current);
833 // Alphabetize list by title
839 for(int i = 0; i < results.total - 1; i++)
841 PluginServer *value1 = results[i];
842 PluginServer *value2 = results[i + 1];
843 if(strcmp(_(value1->title), _(value2->title)) > 0)
847 results[i + 1] = value1;
853 PluginServer* MWindow::scan_plugindb(char *title,
858 // printf("MWindow::scan_plugindb data_type < 0\n");
862 for(int i = 0; i < plugindb->total; i++)
864 PluginServer *server = plugindb->get(i);
866 !strcasecmp(server->title, title) &&
868 (data_type == TRACK_AUDIO && server->audio) ||
869 (data_type == TRACK_VIDEO && server->video)))
870 return plugindb->get(i);
875 // repair session files with xlated plugin titles
876 void MWindow::fix_plugin_title(char *title)
878 for(int i = 0; i < plugindb->total; i++) {
879 PluginServer *server = plugindb->get(i);
880 if( !server->title ) continue;
881 const char *server_title = server->title;
882 if( !bstrcasecmp(title, _(server_title)) ) {
883 strcpy(title, server_title);
889 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
891 for( int i=0; i<plugins.size(); ++i )
892 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
896 int MWindow::plugin_exists(char *plugin_path)
898 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
901 void MWindow::init_preferences()
903 preferences = new Preferences;
904 preferences->load_defaults(defaults);
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);
1161 if( session->selected_zwindow >= 0 ) {
1162 int i = zwindows.number_of(zwindow);
1163 if( i >= 0 && i < session->selected_zwindow )
1164 --session->selected_zwindow;
1165 else if( i == session->selected_zwindow )
1166 session->selected_zwindow = -1;
1168 zwindows_lock->unlock();
1169 gui->lock_window("MWindow::del_mixer 1");
1170 gui->update_mixers(0, -1);
1171 gui->unlock_window();
1174 void MWindow::start_mixer()
1177 ZWindow *zwindow = get_mixer(mixer);
1178 const char *title = 0;
1180 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1181 PatchGUI *patchgui = get_patchgui(track);
1182 if( !patchgui || !patchgui->mixer ) continue;
1183 mixer->mixer_ids.append(track->get_mixer_id());
1184 if( !title ) title = track->title;
1187 session->selected_zwindow = -1;
1188 gui->lock_window("MWindow::start_mixer");
1189 gui->update_mixers(0, 0);
1190 gui->unlock_window();
1192 zwindow->set_title(title);
1197 int MWindow::mixer_track_active(Track *track)
1199 int i = session->selected_zwindow;
1200 if( i < 0 || i >= zwindows.size() ) return 0;
1201 ZWindow *zwindow = zwindows[i];
1202 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1203 if( !mixer ) return 0;
1204 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1205 return n >= 0 ? 1 : 0;
1208 void MWindow::update_mixer_tracks()
1210 zwindows_lock->lock("MixPatch::handle_event");
1211 int i = session->selected_zwindow;
1212 if( i >= 0 && i < zwindows.size() ) {
1213 ZWindow *zwindow = zwindows[i];
1214 zwindow->update_mixer_ids();
1216 zwindows_lock->unlock();
1219 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1220 int use_inout, int update_refresh, int toggle_audio, int loop_play)
1222 zwindows_lock->lock("MWindow::queue_mixers");
1223 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1224 ZWindow *zwindow = zwindows[vidx];
1225 if( zwindow->idx < 0 ) continue;
1226 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1227 if( !mixer || !mixer->mixer_ids.size() ) continue;
1229 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1230 if( track->data_type != TRACK_VIDEO ) continue;
1231 int mixer_id = track->get_mixer_id();
1232 k = mixer->mixer_ids.size();
1233 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1235 if( k < 0 ) continue;
1236 EDL *mixer_edl = new EDL(this->edl);
1237 mixer_edl->create_objects();
1238 mixer_edl->copy_all(edl);
1239 mixer_edl->remove_vwindow_edls();
1240 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1241 k = mixer->mixer_ids.size();
1242 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1245 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1248 track->record = track->play = 0;
1250 zwindow->change_source(mixer_edl);
1251 zwindow->issue_command(command,
1252 wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
1254 zwindows_lock->unlock();
1257 void MWindow::refresh_mixers(int dir)
1259 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1260 queue_mixers(edl,command,0,0,1,0,0);
1263 void MWindow::stop_mixers()
1265 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1266 ZWindow *zwindow = zwindows[vidx];
1267 if( zwindow->idx < 0 ) continue;
1268 zwindow->issue_command(STOP, 0, 0, 0, 0, 0);
1272 void MWindow::close_mixers()
1274 zwindows_lock->lock("MWindow::close_mixers");
1275 for( int i=0; i<zwindows.size(); ++i ) {
1276 ZWindow *zwindow = zwindows[i];
1277 if( zwindow->idx < 0 ) continue;
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 ZWindow *zwindow = create_mixer(indexable);
1333 new_mixers.append(zwindow);
1335 for( int i=0; i<session->drag_clips->size(); ++i ) {
1336 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1337 ZWindow *zwindow = create_mixer(indexable);
1338 new_mixers.append(zwindow);
1342 for( int i=0; i<new_mixers.size(); ++i )
1343 new_mixers[i]->start();
1347 undo->update_undo_after(_("create mixers"), LOAD_ALL);
1349 gui->update(1, 2, 1, 1, 1, 1, 0);
1350 sync_parameters(CHANGE_ALL);
1353 void MWindow::open_mixers()
1355 for( int i=0; i<edl->mixers.size(); ++i ) {
1356 Mixer *mixer = edl->mixers[i];
1357 ZWindow *zwindow = get_mixer(mixer);
1358 zwindow->set_title(mixer->title);
1364 int MWindow::select_zwindow(ZWindow *zwindow)
1366 int ret = 0, n = zwindows.number_of(zwindow);
1367 if( session->selected_zwindow != n ) {
1368 session->selected_zwindow = n;
1369 for( int i=0; i<zwindows.size(); ++i ) {
1370 ZWindow *zwindow = zwindows[i];
1371 if( zwindow->idx < 0 ) continue;
1372 ZWindowGUI *zgui = zwindow->zgui;
1373 zgui->lock_window("MWindow::select_zwindow 0");
1374 zwindow->highlighted = i == n ? 1 : 0;
1375 if( zgui->draw_overlays() )
1376 zgui->canvas->get_canvas()->flash(1);
1377 zgui->unlock_window();
1380 gui->lock_window("MWindow::select_window 1");
1381 gui->update_mixers(0, -1);
1382 gui->unlock_window();
1387 void MWindow::tile_mixers()
1390 for( int i=0; i<zwindows.size(); ++i ) {
1391 ZWindow *zwindow = zwindows[i];
1392 if( zwindow->idx < 0 ) continue;
1396 int zn = ceil(sqrt(nz));
1397 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1398 int y1 = 1, y2 = gui->get_y();
1399 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1400 if( x1 < 0 ) x1 = 0;
1401 if( y1 < 0 ) y1 = 0;
1402 if( x2 > rw ) x2 = rw;
1403 if( y2 > rh ) y2 = rh;
1404 int dx = x2 - x1, dy = y2 - y1;
1406 int lt = BC_DisplayInfo::get_left_border();
1407 int top = BC_DisplayInfo::get_top_border();
1408 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1409 int bh = top + BC_DisplayInfo::get_bottom_border();
1410 int zx = 0, zy = 0; // window origins
1411 int mw = 10+10, mh = 10+10; // canvas margins
1412 int rsz = 0, n = 0, dz = 0;
1413 int ow = edl->session->output_w, oh = edl->session->output_h;
1414 for( int i=0; i<zwindows.size(); ++i ) {
1415 ZWindow *zwindow = zwindows[i];
1416 if( zwindow->idx < 0 ) continue;
1417 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1418 if( rsz < hh ) rsz = hh;
1419 int xx = zx + x1, yy = zy + y1;
1420 int mx = x2 - zw, my = y2 - zh;
1421 if( xx > mx ) xx = mx;
1422 if( yy > my ) yy = my;
1423 xx += lt + dz; yy += top + dz;
1424 zwindow->reposition(xx,yy, ww,hh);
1425 if( zwindow->running() ) {
1426 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1427 gui->lock_window("MWindow::tile_mixers");
1428 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1429 gui->unlock_window();
1433 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1442 void MWindow::init_cache()
1444 audio_cache = new CICache(preferences);
1445 video_cache = new CICache(preferences);
1446 frame_cache = new FrameCache;
1447 wave_cache = new WaveCache;
1450 void MWindow::init_channeldb()
1452 channeldb_buz->load("channeldb_buz");
1453 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1456 void MWindow::init_menus()
1458 char string[BCTEXTLEN];
1461 BC_CModels::to_text(string, BC_RGB888);
1462 colormodels.append(new ColormodelItem(string, BC_RGB888));
1463 BC_CModels::to_text(string, BC_RGBA8888);
1464 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1465 // BC_CModels::to_text(string, BC_RGB161616);
1466 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1467 // BC_CModels::to_text(string, BC_RGBA16161616);
1468 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1469 BC_CModels::to_text(string, BC_RGB_FLOAT);
1470 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1471 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1472 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1473 BC_CModels::to_text(string, BC_YUV888);
1474 colormodels.append(new ColormodelItem(string, BC_YUV888));
1475 BC_CModels::to_text(string, BC_YUVA8888);
1476 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1477 // BC_CModels::to_text(string, BC_YUV161616);
1478 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1479 // BC_CModels::to_text(string, BC_YUVA16161616);
1480 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1482 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1483 interlace_project_modes.append(new InterlacemodeItem(string, x));
1485 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1486 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1488 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1489 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1491 // Interlacing Modes
1492 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1494 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1495 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1497 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1498 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1500 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1501 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1503 // Interlacing Fixing Methods
1504 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1505 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1506 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1509 void MWindow::init_indexes()
1511 mainindexes = new MainIndexes(this);
1512 mainindexes->start_loop();
1515 void MWindow::init_gui()
1517 gui = new MWindowGUI(this);
1518 gui->lock_window("MWindow::init_gui");
1519 gui->create_objects();
1520 gui->unlock_window();
1521 gui->load_defaults(defaults);
1524 void MWindow::init_signals()
1526 sighandler = new SigHandler;
1527 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1531 void MWindow::init_render()
1533 render = new Render(this);
1534 create_bd = new CreateBD_Thread(this);
1535 create_dvd = new CreateDVD_Thread(this);
1536 batch_render = new BatchRenderThread(this);
1539 void MWindow::init_exportedl()
1541 exportedl = new ExportEDL(this);
1544 void MWindow::init_brender()
1546 if(preferences->use_brender && !brender)
1548 brender_lock->lock("MWindow::init_brender 1");
1549 brender = new BRender(this);
1550 brender->initialize();
1551 session->brender_end = 0;
1552 brender_lock->unlock();
1555 if(!preferences->use_brender && brender)
1557 brender_lock->lock("MWindow::init_brender 2");
1560 session->brender_end = 0;
1561 brender_lock->unlock();
1567 void MWindow::restart_brender()
1569 //printf("MWindow::restart_brender 1\n");
1570 if( !brender_active || !preferences->use_brender ) return;
1571 if( !brender ) return;
1572 brender->restart(edl);
1575 void MWindow::stop_brender()
1577 if( !brender ) return;
1578 // cannot be holding mwindow->gui display lock
1582 int MWindow::brender_available(int position)
1585 brender_lock->lock("MWindow::brender_available 1");
1586 if(brender && brender_active)
1588 if(brender->map_valid)
1590 brender->map_lock->lock("MWindow::brender_available 2");
1591 if(position < brender->map_size &&
1594 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1595 if(brender->map[position] == BRender::RENDERED)
1598 brender->map_lock->unlock();
1601 brender_lock->unlock();
1605 void MWindow::set_brender_active(int v, int update)
1607 if( !preferences->use_brender ) v = 0;
1609 gui->mainmenu->brender_active->set_checked(v);
1611 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1612 edl->session->brender_end = edl->local_session->get_selectionend(1);
1614 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1615 edl->session->brender_end = edl->tracks->total_video_length();
1620 edl->session->brender_start = edl->session->brender_end = 0;
1621 gui->unlock_window();
1623 gui->lock_window("MWindow::set_brender_active");
1626 gui->update_timebar(0);
1627 gui->draw_overlays(1);
1631 int MWindow::has_commercials()
1633 return theme->use_commercials;
1636 void MWindow::init_commercials()
1638 if( !commercials ) {
1639 commercials = new Commercials(this);
1640 commercial_active = 0;
1643 commercials->add_user();
1646 void MWindow::commit_commercial()
1648 if( !commercial_active ) return;
1649 commercial_active = 0;
1650 if( !commercials ) return;
1651 commercials->commitDb();
1654 void MWindow::undo_commercial()
1656 if( !commercial_active ) return;
1657 commercial_active = 0;
1658 if( !commercials ) return;
1659 commercials->undoDb();
1662 int MWindow::put_commercial()
1664 double start = edl->local_session->get_selectionstart();
1665 double end = edl->local_session->get_selectionend();
1666 if( start >= end ) return 0;
1668 const char *errmsg = 0;
1670 Tracks *tracks = edl->tracks;
1673 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1674 if( track->data_type != TRACK_VIDEO ) continue;
1675 if( !track->record ) continue;
1676 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1678 int64_t units_start = track->to_units(start,0);
1679 int64_t units_end = track->to_units(end,0);
1680 Edits *edits = track->edits;
1681 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1682 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1683 if(!edit1 && !edit2) continue; // nothing selected
1684 if(!edit2) { // edit2 beyond end of track
1685 edit2 = edits->last;
1686 units_end = edits->length();
1688 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1689 Indexable *indexable = edit1->get_source();
1690 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1693 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1694 if( track->data_type != TRACK_VIDEO ) continue;
1695 if( !track->record ) continue;
1696 int64_t units_start = track->to_units(start,0);
1697 int64_t units_end = track->to_units(end,0);
1698 Edits *edits = track->edits;
1699 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1700 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1701 if(!edit1 && !edit2) continue; // nothing selected
1702 if(!edit2) { // edit2 beyond end of track
1703 edit2 = edits->last;
1704 units_end = edits->length();
1706 Indexable *indexable = edit1->get_source();
1707 Asset *asset = (Asset *)indexable;
1708 File *file = video_cache->check_out(asset, edl);
1709 if( !file ) { errmsg = _("no file"); break; }
1710 int64_t edit_length = units_end - units_start;
1711 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1712 result = commercials->put_clip(file, edit1->channel,
1713 track->from_units(edit_start), track->from_units(edit_length));
1714 video_cache->check_in(asset);
1715 if( result ) { errmsg = _("db failed"); break; }
1718 char string[BCTEXTLEN];
1719 sprintf(string, _("put_commercial: %s"), errmsg);
1720 MainError::show_error(string);
1727 void MWindow::stop_playback(int wait)
1729 gui->stop_drawing();
1731 cwindow->stop_playback(wait);
1733 for(int i = 0; i < vwindows.size(); i++) {
1734 VWindow *vwindow = vwindows[i];
1735 if( !vwindow->is_running() ) continue;
1736 vwindow->stop_playback(wait);
1738 for(int i = 0; i < zwindows.size(); i++) {
1739 ZWindow *zwindow = zwindows[i];
1740 if( zwindow->idx < 0 ) continue;
1741 zwindow->stop_playback(wait);
1745 void MWindow::stop_transport()
1747 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1750 int MWindow::load_filenames(ArrayList<char*> *filenames,
1752 int update_filename)
1754 ArrayList<EDL*> new_edls;
1755 ArrayList<Asset*> new_assets;
1756 ArrayList<File*> new_files;
1757 const int debug = 0;
1758 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1761 gui->start_hourglass();
1763 // Need to stop playback since tracking depends on the EDL not getting
1765 gui->unlock_window();
1767 gui->lock_window("MWindow::load_filenames 0");
1769 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1770 undo->update_undo_before();
1773 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1775 // Define new_edls and new_assets to load
1776 int result = 0, ftype = -1;
1778 for( int i=0; i<filenames->size(); ++i ) {
1780 File *new_file = new File;
1781 Asset *new_asset = new Asset(filenames->get(i));
1782 EDL *new_edl = new EDL;
1783 char string[BCTEXTLEN];
1785 new_edl->create_objects();
1786 new_edl->copy_session(edl);
1787 new_file->set_program(edl->session->program_no);
1789 sprintf(string, _("Loading %s"), new_asset->path);
1790 gui->show_message(string);
1791 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1793 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1794 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1798 // Convert media file to EDL
1800 // Warn about odd image dimensions
1801 if( new_asset->video_data &&
1802 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1803 char string[BCTEXTLEN];
1804 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1805 new_asset->path, new_asset->width, new_asset->height);
1806 MainError::show_error(string);
1809 if( new_asset->program >= 0 &&
1810 edl->session->program_no != new_asset->program ) {
1811 char string[BCTEXTLEN];
1812 sprintf(string, _("%s's index was built for program number %d\n"
1813 "Playback preference is %d.\n Using program %d."),
1814 new_asset->path, new_asset->program,
1815 edl->session->program_no, new_asset->program);
1816 MainError::show_error(string);
1819 if( load_mode != LOADMODE_RESOURCESONLY ) {
1820 RecordLabels *labels = edl->session->label_cells ?
1821 new RecordLabels(new_file) : 0;
1822 asset_to_edl(new_edl, new_asset, labels);
1823 new_edls.append(new_edl);
1824 new_edl->add_user();
1828 new_assets.append(new_asset);
1829 new_asset->add_user();
1832 // Set filename to nothing for assets since save EDL would overwrite them.
1833 if( load_mode == LOADMODE_REPLACE ||
1834 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1836 // Reset timeline position
1837 for( int i=0; i<TOTAL_PANES; ++i ) {
1838 new_edl->local_session->view_start[i] = 0;
1839 new_edl->local_session->track_start[i] = 0;
1847 case FILE_NOT_FOUND:
1848 sprintf(string, _("Failed to open %s"), new_asset->path);
1849 gui->show_message(string, theme->message_error);
1850 gui->update_default_message();
1854 case FILE_UNRECOGNIZED_CODEC: {
1856 { IndexFile indexfile(this, new_asset);
1857 if( !(result = indexfile.open_index()) )
1858 indexfile.close_index(); }
1860 // Test existing EDLs
1861 for( int j=0; result && j<new_edls.total; ++j ) {
1862 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1864 new_asset->copy_from(old_asset,1);
1869 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1871 new_asset->copy_from(old_asset,1);
1878 char string[BCTEXTLEN];
1880 fs.extract_name(string, new_asset->path);
1882 strcat(string, _("'s format couldn't be determined."));
1883 new_asset->audio_data = 1;
1884 new_asset->format = FILE_PCM;
1885 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1886 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1887 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1888 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1889 new_asset->signed_ = defaults->get("SIGNED_", 1);
1890 new_asset->header = defaults->get("HEADER", 0);
1892 FileFormat fwindow(this);
1893 fwindow.create_objects(new_asset, string);
1894 result = fwindow.run_window();
1896 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1897 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1898 defaults->update("AUDIO_BITS", new_asset->bits);
1899 defaults->update("BYTE_ORDER", new_asset->byte_order);
1900 defaults->update("SIGNED_", new_asset->signed_);
1901 defaults->update("HEADER", new_asset->header);
1907 // Recalculate length
1909 new_file = new File;
1910 result = new_file->open_file(preferences, new_asset, 1, 0);
1912 if( load_mode != LOADMODE_RESOURCESONLY ) {
1913 RecordLabels *labels = edl->session->label_cells ?
1914 new RecordLabels(new_file) : 0;
1915 asset_to_edl(new_edl, new_asset, labels);
1916 new_edls.append(new_edl);
1917 new_edl->add_user();
1921 new_assets.append(new_asset);
1922 new_asset->add_user();
1932 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1933 xml_file.read_from_file(filenames->get(i));
1934 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1935 const char *cin_version = 0;
1936 while( !xml_file.read_tag() ) {
1937 if( xml_file.tag.title_is("EDL") ) {
1938 cin_version = xml_file.tag.get_property("VERSION");
1943 if( !cin_version ) {
1944 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1945 char string[BCTEXTLEN];
1946 sprintf(string,_("Unknown %s"), filenames->get(i));
1947 gui->show_message(string);
1951 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1952 char string[BCTEXTLEN];
1953 snprintf(string, sizeof(string),
1954 _("Warning: XML from cinelerra version %s\n"
1955 "Session data may be incompatible."), cin_version);
1956 show_warning(&preferences->warn_version, string);
1958 if( load_mode == LOADMODE_NESTED ) {
1959 // Load temporary EDL for nesting.
1960 EDL *nested_edl = new EDL;
1961 nested_edl->create_objects();
1962 nested_edl->load_xml(&xml_file, LOAD_ALL);
1963 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1964 new_edl->create_nested(nested_edl);
1965 new_edl->set_path(filenames->get(i));
1966 nested_edl->Garbage::remove_user();
1969 // Load EDL for pasting
1970 new_edl->load_xml(&xml_file, LOAD_ALL);
1971 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1972 test_plugins(new_edl, filenames->get(i));
1973 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1975 if( load_mode == LOADMODE_REPLACE ||
1976 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1977 strcpy(session->filename, filenames->get(i));
1978 strcpy(new_edl->local_session->clip_title,
1981 set_filename(new_edl->local_session->clip_title);
1983 else if( load_mode == LOADMODE_RESOURCESONLY ) {
1984 strcpy(new_edl->local_session->clip_title,
1987 time_t t = !stat(filenames->get(i),&st) ?
1988 st.st_mtime : time(&t);
1989 ctime_r(&t, new_edl->local_session->clip_notes);
1993 new_edls.append(new_edl);
1994 new_edl->add_user();
1999 new_edl->Garbage::remove_user();
2000 new_asset->Garbage::remove_user();
2002 // Store for testing index
2003 new_files.append(new_file);
2006 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2010 gui->reset_default_message();
2011 gui->default_message();
2015 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2018 // Don't back up here.
2021 // For pasting, clear the active region
2022 if(load_mode == LOADMODE_PASTE ||
2023 load_mode == LOADMODE_NESTED)
2025 double start = edl->local_session->get_selectionstart();
2026 double end = edl->local_session->get_selectionend();
2027 if(!EQUIV(start, end))
2030 edl->session->labels_follow_edits,
2031 edl->session->plugins_follow_edits,
2032 edl->session->autos_follow_edits);
2035 paste_edls(&new_edls, load_mode, 0, -1,
2036 edl->session->labels_follow_edits,
2037 edl->session->plugins_follow_edits,
2038 edl->session->autos_follow_edits,
2045 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2047 // Add new assets to EDL and schedule assets for index building.
2048 int got_indexes = 0;
2049 for( int i=0; i<new_edls.size(); ++i ) {
2050 EDL *new_edl = new_edls[i];
2051 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2052 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2053 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2059 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2060 for( int i=0; i<new_assets.size(); ++i ) {
2061 Asset *new_asset = new_assets[i];
2065 for( int j=0; j<new_files.size(); ++j ) {
2066 new_file = new_files[j];
2067 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2073 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2074 edl->assets->update(new_asset);
2077 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2079 // Start examining next batch of index files
2080 if(got_indexes) mainindexes->start_build();
2081 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2084 Track *track = edl->tracks->first;
2087 for(int j = 0; j < track->plugin_set.size(); j++)
2089 PluginSet *plugins = track->plugin_set[j];
2090 Plugin *plugin = plugins->get_first_plugin();
2094 if(load_mode == LOADMODE_REPLACE ||
2095 load_mode == LOADMODE_REPLACE_CONCATENATE)
2097 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2100 show_plugin(plugin);
2104 plugin = (Plugin*)plugin->next;
2108 track = track->next;
2111 // if just opening one new resource in replace mode
2112 if( ftype != FILE_IS_XML &&
2113 ( load_mode == LOADMODE_REPLACE ||
2114 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2116 edl->session->proxy_scale = 1;
2117 edl->session->proxy_use_scaler = 0;
2118 edl->session->proxy_auto_scale = 0;
2119 edl->local_session->preview_start = 0;
2120 edl->local_session->preview_end = 0;
2121 edl->local_session->loop_playback = 0;
2122 edl->local_session->set_selectionstart(0);
2123 edl->local_session->set_selectionend(0);
2124 set_brender_active(0, 0);
2129 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2130 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2131 ArrayList<Indexable *> orig_idxbls;
2132 for( int i=0; i<new_assets.size(); ++i )
2133 orig_idxbls.append(new_assets.get(i));
2134 for( int i=0; i<new_edls.size(); ++i ) {
2135 EDL *new_edl = new_edls[i];
2136 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2137 if( track->data_type != TRACK_VIDEO ) continue;
2138 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2139 Indexable *idxbl = (Indexable *)edit->asset;
2140 if( !idxbl ) continue;
2141 if( !idxbl->have_video() ) continue;
2142 if( edit->channel != 0 ) continue; // first layer only
2143 orig_idxbls.append(edit->asset);
2147 gui->unlock_window(); // to update progress bar
2148 render_proxy(orig_idxbls);
2149 gui->lock_window("MWindow::load_filenames");
2152 // need to update undo before project, since mwindow is unlocked & a new load
2153 // can begin here. Should really prevent loading until we're done.
2154 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2155 undo->update_undo_after(_("load"), LOAD_ALL);
2157 for(int i = 0; i < new_edls.size(); i++)
2159 new_edls[i]->remove_user();
2161 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2163 new_edls.remove_all();
2165 for(int i = 0; i < new_assets.size(); i++)
2167 new_assets[i]->Garbage::remove_user();
2170 new_assets.remove_all();
2171 new_files.remove_all_objects();
2174 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2175 if(load_mode == LOADMODE_REPLACE ||
2176 load_mode == LOADMODE_REPLACE_CONCATENATE)
2178 session->changes_made = 0;
2182 session->changes_made = 1;
2185 gui->stop_hourglass();
2188 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2189 update_project(load_mode);
2191 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2196 void MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2198 Asset *format_asset = new Asset;
2199 format_asset->format = FILE_FFMPEG;
2200 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2201 ProxyRender proxy_render(this, format_asset);
2202 int new_scale = edl->session->proxy_scale;
2203 int use_scaler = edl->session->proxy_use_scaler;
2205 for( int i=0; i<new_idxbls.size(); ++i ) {
2206 Indexable *orig = new_idxbls.get(i);
2207 Asset *proxy = proxy_render.add_original(orig, new_scale);
2208 if( !proxy ) continue;
2210 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2211 int got_it = exists && // if proxy exists, and is newer than orig
2212 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2213 if( got_it ) continue;
2214 proxy_render.add_needed(orig, proxy);
2217 // render needed proxies
2218 int result = proxy_render.create_needed_proxies(new_scale);
2220 add_proxy(use_scaler,
2221 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2223 format_asset->remove_user();
2226 void MWindow::test_plugins(EDL *new_edl, char *path)
2228 char string[BCTEXTLEN];
2230 // Do a check whether plugins exist
2231 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2232 for( int k=0; k<track->plugin_set.total; ++k ) {
2233 PluginSet *plugin_set = track->plugin_set[k];
2234 for( Plugin *plugin = (Plugin*)plugin_set->first;
2235 plugin; plugin = (Plugin*)plugin->next ) {
2236 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2237 // ok we need to find it in plugindb
2238 PluginServer *server =
2239 scan_plugindb(plugin->title, track->data_type);
2240 if( !server || server->transition ) {
2242 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2243 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2244 "effect", _(plugin->title), path);
2245 MainError::show_error(string);
2250 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2251 if( !edit->transition ) continue;
2252 // ok we need to find transition in plugindb
2253 PluginServer *server =
2254 scan_plugindb(edit->transition->title, track->data_type);
2255 if( !server || !server->transition ) {
2257 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2258 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2259 "transition", _(edit->transition->title), path);
2260 MainError::show_error(string);
2267 void MWindow::init_shm()
2269 // Fix shared memory
2270 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
2272 fprintf(fd, "0x7fffffff");
2277 fd = fopen("/proc/sys/kernel/shmmax", "r");
2279 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
2284 fscanf(fd, "%jd", &result);
2287 if(result < 0x7fffffff) {
2288 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
2289 "you probably need to be root, or:\n"
2290 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
2291 "before trying to start cinelerra.\n"
2292 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
2296 void MWindow::create_objects(int want_gui,
2300 const int debug = 0;
2301 if(debug) PRINT_TRACE
2303 // For some reason, init_signals must come after show_splash or the signals won't
2306 if(debug) PRINT_TRACE
2309 if(debug) PRINT_TRACE
2312 if(debug) PRINT_TRACE
2313 default_standard = default_std();
2314 init_defaults(defaults, config_path);
2318 splash_window->operation->update(_("Initializing Plugins"));
2319 init_plugins(this, preferences);
2320 if(debug) PRINT_TRACE
2321 init_ladspa_plugins(this, preferences);
2322 if(debug) PRINT_TRACE
2323 init_plugin_tips(*plugindb, cin_lang);
2325 splash_window->operation->update(_("Initializing GUI"));
2326 if(debug) PRINT_TRACE
2329 if(debug) PRINT_TRACE
2333 splash_window->operation->update(_("Initializing Fonts"));
2334 char string[BCTEXTLEN];
2335 strcpy(string, preferences->plugin_dir);
2336 strcat(string, "/" FONT_SEARCHPATH);
2337 BC_Resources::init_fontconfig(string);
2338 if(debug) PRINT_TRACE
2340 // Initialize before too much else is running
2341 // Preferences & theme are required for building MPEG table of contents
2343 // Default project created here
2345 if(debug) PRINT_TRACE
2348 if(debug) PRINT_TRACE
2353 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2356 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2358 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2359 if(session->show_vwindow)
2360 get_viewer(1, DEFAULT_VWINDOW);
2361 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2364 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2367 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2370 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2373 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2376 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2379 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2384 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2385 mainprogress = new MainProgress(this, gui);
2386 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2387 undo = new MainUndo(this);
2389 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2391 plugin_guis = new ArrayList<PluginServer*>;
2392 dead_plugins = new ArrayList<PluginServer*>;
2393 keyframe_threads = new ArrayList<KeyFrameThread*>;
2395 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2398 session->show_vwindow);
2400 // Show all vwindows
2401 // if(session->show_vwindow) {
2402 // for(int j = 0; j < vwindows.size(); j++) {
2403 // VWindow *vwindow = vwindows[j];
2404 // if( !vwindow->is_running() ) continue;
2405 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2408 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2409 // vwindow->gui->lock_window("MWindow::create_objects 1");
2410 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2411 // vwindow->gui->show_window();
2412 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2413 // vwindow->gui->unlock_window();
2418 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2420 if(session->show_cwindow)
2422 cwindow->gui->lock_window("MWindow::create_objects 1");
2423 cwindow->gui->show_window();
2424 cwindow->gui->unlock_window();
2427 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2428 if(session->show_awindow)
2430 awindow->gui->lock_window("MWindow::create_objects 1");
2431 awindow->gui->show_window();
2432 awindow->gui->unlock_window();
2435 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2436 if(session->show_lwindow)
2438 lwindow->gui->lock_window("MWindow::create_objects 1");
2439 lwindow->gui->show_window();
2440 lwindow->gui->unlock_window();
2443 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2445 (int)timer.get_difference(),
2447 if(session->show_gwindow)
2449 gwindow->gui->lock_window("MWindow::create_objects 1");
2450 gwindow->gui->show_window();
2451 gwindow->gui->unlock_window();
2454 if(debug) PRINT_TRACE
2456 gui->lock_window("MWindow::create_objects 1");
2457 gui->mainmenu->load_defaults(defaults);
2458 gui->mainmenu->update_toggles(0);
2459 gui->update_patchbay();
2460 gui->draw_canvas(0, 0);
2461 gui->draw_cursor(1);
2463 gui->raise_window();
2464 gui->unlock_window();
2466 if(debug) PRINT_TRACE
2468 if(preferences->use_tipwindow)
2470 if(debug) PRINT_TRACE
2472 gui->add_keyboard_listener(
2473 (int (BC_WindowBase::*)(BC_WindowBase *))
2474 &MWindowGUI::keyboard_listener);
2478 if(debug) PRINT_TRACE
2480 BC_WindowBase::get_resources()->vframe_shm = 1;
2484 void MWindow::show_splash()
2486 #include "data/heroine_logo9_png.h"
2487 VFrame *frame = new VFramePng(heroine_logo9_png);
2488 BC_DisplayInfo dpyi;
2489 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2490 int rr = (rw < rh ? rw : rh) / 4;
2491 splash_window = new SplashGUI(frame, rr, rr);
2492 splash_window->create_objects();
2495 void MWindow::hide_splash()
2498 delete splash_window;
2503 void MWindow::start()
2507 // vwindows[DEFAULT_VWINDOW]->start();
2518 playback_3d->start();
2524 run_lock->lock("MWindow::run");
2528 brender_lock->lock("MWindow::run 1");
2529 delete brender; brender = 0;
2530 brender_lock->unlock();
2532 interrupt_indexes();
2538 void MWindow::show_vwindow()
2540 int total_running = 0;
2541 session->show_vwindow = 1;
2543 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2544 // Raise all windows which are visible
2545 for(int j = 0; j < vwindows.size(); j++) {
2546 VWindow *vwindow = vwindows[j];
2547 if( !vwindow->is_running() ) continue;
2548 vwindow->gui->lock_window("MWindow::show_vwindow");
2549 vwindow->gui->show_window(0);
2550 vwindow->gui->raise_window();
2551 vwindow->gui->flush();
2552 vwindow->gui->unlock_window();
2556 // If no windows visible
2559 get_viewer(1, DEFAULT_VWINDOW);
2562 gui->mainmenu->show_vwindow->set_checked(1);
2565 void MWindow::show_awindow()
2567 session->show_awindow = 1;
2568 awindow->gui->lock_window("MWindow::show_awindow");
2569 awindow->gui->show_window();
2570 awindow->gui->raise_window();
2571 awindow->gui->flush();
2572 awindow->gui->unlock_window();
2573 gui->mainmenu->show_awindow->set_checked(1);
2576 char *MWindow::get_cwindow_display()
2578 char *x11_host = screens < 2 || session->window_config == 0 ?
2579 session->a_x11_host : session->b_x11_host;
2580 return *x11_host ? x11_host : 0;
2583 void MWindow::show_cwindow()
2585 session->show_cwindow = 1;
2586 cwindow->show_window();
2587 gui->mainmenu->show_cwindow->set_checked(1);
2590 void MWindow::show_gwindow()
2592 session->show_gwindow = 1;
2594 gwindow->gui->lock_window("MWindow::show_gwindow");
2595 gwindow->gui->show_window();
2596 gwindow->gui->raise_window();
2597 gwindow->gui->flush();
2598 gwindow->gui->unlock_window();
2600 gui->mainmenu->show_gwindow->set_checked(1);
2602 void MWindow::hide_gwindow()
2604 session->show_gwindow = 0;
2606 gwindow->gui->lock_window("MWindow::show_gwindow");
2607 gwindow->gui->hide_window();
2608 gwindow->gui->unlock_window();
2611 void MWindow::show_lwindow()
2613 session->show_lwindow = 1;
2614 lwindow->gui->lock_window("MWindow::show_lwindow");
2615 lwindow->gui->show_window();
2616 lwindow->gui->raise_window();
2617 lwindow->gui->flush();
2618 lwindow->gui->unlock_window();
2619 gui->mainmenu->show_lwindow->set_checked(1);
2622 int MWindow::tile_windows(int window_config)
2624 int need_reload = 0;
2625 int play_config = window_config==0 ? 0 : 1;
2626 edl->session->playback_config->load_defaults(defaults, play_config);
2627 session->default_window_positions(window_config);
2628 if( screens == 1 ) {
2629 gui->default_positions();
2630 sync_parameters(CHANGE_ALL);
2637 void MWindow::toggle_loop_playback()
2639 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2640 set_loop_boundaries();
2643 gui->draw_overlays(1);
2644 sync_parameters(CHANGE_PARAMS);
2647 //void MWindow::set_titles(int value)
2649 // edl->session->show_titles = value;
2650 // trackmovement(edl->local_session->track_start);
2653 void MWindow::set_screens(int value)
2658 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2660 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2661 edl->session->auto_keyframes = value;
2662 gui->mbuttons->edit_panel->keyframe->update(value);
2664 if(lock_mwindow) gui->unlock_window();
2666 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2667 cwindow->gui->edit_panel->keyframe->update(value);
2668 cwindow->gui->flush();
2669 if(lock_cwindow) cwindow->gui->unlock_window();
2672 void MWindow::set_auto_visibility(Autos *autos, int value)
2674 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2675 edl->session->auto_conf->plugins = value;
2676 else if( autos->autoidx >= 0 )
2677 edl->session->auto_conf->autos[autos->autoidx] = value;
2681 gui->update(0, 1, 0, 0, 0, 0, 0);
2682 gui->mainmenu->update_toggles(1);
2683 gui->unlock_window();
2684 gwindow->gui->update_toggles(1);
2685 gui->lock_window("MWindow::set_auto_visibility");
2688 void MWindow::set_keyframe_type(int mode)
2690 gui->lock_window("MWindow::set_keyframe_type");
2691 edl->local_session->floatauto_type = mode;
2692 gui->mainmenu->update_toggles(0);
2693 gui->unlock_window();
2696 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2698 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2699 edl->session->editing_mode = new_editing_mode;
2700 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2701 gui->mbuttons->edit_panel->update();
2702 gui->set_editing_mode(1);
2703 if(lock_mwindow) gui->unlock_window();
2706 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2707 cwindow->gui->edit_panel->update();
2708 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2709 if(lock_cwindow) cwindow->gui->unlock_window();
2713 void MWindow::toggle_editing_mode()
2715 int mode = edl->session->editing_mode;
2716 if( mode == EDITING_ARROW )
2717 set_editing_mode(EDITING_IBEAM, 0, 1);
2719 set_editing_mode(EDITING_ARROW, 0, 1);
2723 void MWindow::set_labels_follow_edits(int value)
2725 gui->lock_window("MWindow::set_labels_follow_edits");
2726 edl->session->labels_follow_edits = value;
2727 gui->mbuttons->edit_panel->locklabels->update(value);
2728 gui->mainmenu->labels_follow_edits->set_checked(value);
2730 gui->unlock_window();
2733 void MWindow::sync_parameters(int change_type)
2735 if( in_destructor ) return;
2737 // Sync engines which are playing back
2738 if(cwindow->playback_engine->is_playing_back)
2740 if(change_type == CHANGE_PARAMS)
2742 // TODO: block keyframes until synchronization is done
2743 cwindow->playback_engine->sync_parameters(edl);
2748 int command = cwindow->playback_engine->command->command;
2749 cwindow->playback_engine->que->send_command(STOP,
2753 // Waiting for tracking to finish would make the restart position more
2754 // accurate but it can't lock the window to stop tracking for some reason.
2755 // Not waiting for tracking gives a faster response but restart position is
2756 // only as accurate as the last tracking update.
2757 cwindow->playback_engine->interrupt_playback(0);
2758 cwindow->playback_engine->que->send_command(command,
2767 cwindow->refresh_frame(change_type);
2771 void MWindow::age_caches()
2773 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2775 // preferences->cache_size,
2776 // audio_cache->get_memory_usage(1),
2777 // video_cache->get_memory_usage(1),
2778 // frame_cache->get_memory_usage(),
2779 // wave_cache->get_memory_usage(),
2781 frame_cache->age_cache(512);
2782 wave_cache->age_cache(8192);
2784 int64_t memory_usage;
2785 int64_t prev_memory_usage = 0;
2787 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2788 while( !result && prev_memory_usage !=
2789 (memory_usage=video_cache->get_memory_usage(1)) &&
2790 memory_usage > video_size ) {
2791 video_cache->delete_oldest();
2792 prev_memory_usage = memory_usage;
2795 prev_memory_usage = 0;
2797 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2798 while( !result && prev_memory_usage !=
2799 (memory_usage=audio_cache->get_memory_usage(1)) &&
2800 memory_usage > audio_size ) {
2801 audio_cache->delete_oldest();
2802 prev_memory_usage = memory_usage;
2806 void MWindow::reset_android_remote()
2808 gui->use_android_remote(preferences->android_remote);
2812 void MWindow::show_keyframe_gui(Plugin *plugin)
2814 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2815 // Find existing thread
2816 for(int i = 0; i < keyframe_threads->size(); i++)
2818 if(keyframe_threads->get(i)->plugin == plugin)
2820 keyframe_threads->get(i)->start_window(plugin, 0);
2821 keyframe_gui_lock->unlock();
2826 // Find unused thread
2827 for(int i = 0; i < keyframe_threads->size(); i++)
2829 if(!keyframe_threads->get(i)->plugin)
2831 keyframe_threads->get(i)->start_window(plugin, 0);
2832 keyframe_gui_lock->unlock();
2837 // Create new thread
2838 KeyFrameThread *thread = new KeyFrameThread(this);
2839 keyframe_threads->append(thread);
2840 thread->start_window(plugin, 0);
2842 keyframe_gui_lock->unlock();
2849 void MWindow::show_plugin(Plugin *plugin)
2854 // Remove previously deleted plugin GUIs
2855 dead_plugin_lock->lock("MWindow::show_plugin");
2856 dead_plugins->remove_all_objects();
2857 dead_plugin_lock->unlock();
2859 //printf("MWindow::show_plugin %d\n", __LINE__);
2863 plugin_gui_lock->lock("MWindow::show_plugin");
2864 for(int i = 0; i < plugin_guis->total; i++)
2866 // Pointer comparison
2867 if(plugin_guis->get(i)->plugin == plugin)
2869 plugin_guis->get(i)->raise_window();
2876 //printf("MWindow::show_plugin 1\n");
2877 if( !done && !plugin->track ) {
2878 printf("MWindow::show_plugin track not defined.\n");
2882 PluginServer *server = scan_plugindb(plugin->title,
2883 plugin->track->data_type);
2885 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2886 if(server && server->uses_gui)
2888 PluginServer *gui = new PluginServer(*server);
2889 plugin_guis->append(gui);
2890 // Needs mwindow to do GUI
2891 gui->set_mwindow(this);
2892 gui->open_plugin(0, preferences, edl, plugin);
2897 plugin_gui_lock->unlock();
2898 //printf("MWindow::show_plugin %d\n", __LINE__);
2901 //printf("MWindow::show_plugin 2\n");
2904 void MWindow::hide_plugin(Plugin *plugin, int lock)
2907 // Update the toggle
2908 gui->lock_window("MWindow::hide_plugin");
2909 gui->update(0, 1, 0, 0, 0, 0, 0);
2910 gui->unlock_window();
2912 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2913 for(int i = 0; i < plugin_guis->total; i++)
2915 if(plugin_guis->get(i)->plugin == plugin)
2917 PluginServer *ptr = plugin_guis->get(i);
2918 plugin_guis->remove(ptr);
2919 if(lock) plugin_gui_lock->unlock();
2920 // Last command executed in client side close
2921 // Schedule for deletion
2928 if(lock) plugin_gui_lock->unlock();
2931 void MWindow::delete_plugin(PluginServer *plugin)
2933 dead_plugin_lock->lock("MWindow::delete_plugin");
2934 dead_plugins->append(plugin);
2935 dead_plugin_lock->unlock();
2938 void MWindow::hide_plugins()
2940 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2941 while(plugin_guis->size())
2943 PluginServer *ptr = plugin_guis->get(0);
2944 plugin_guis->remove(ptr);
2945 plugin_gui_lock->unlock();
2946 // Last command executed in client side close
2947 // Schedule for deletion
2950 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2952 plugin_gui_lock->unlock();
2954 hide_keyframe_guis();
2957 void MWindow::hide_keyframe_guis()
2959 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2960 for(int i = 0; i < keyframe_threads->size(); i++)
2962 keyframe_threads->get(i)->close_window();
2964 keyframe_gui_lock->unlock();
2967 void MWindow::hide_keyframe_gui(Plugin *plugin)
2969 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2970 for(int i = 0; i < keyframe_threads->size(); i++)
2972 if(keyframe_threads->get(i)->plugin == plugin)
2974 keyframe_threads->get(i)->close_window();
2978 keyframe_gui_lock->unlock();
2981 void MWindow::update_keyframe_guis()
2983 // Send new configuration to keyframe GUI's
2984 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2985 for(int i = 0; i < keyframe_threads->size(); i++)
2987 KeyFrameThread *ptr = keyframe_threads->get(i);
2988 if(edl->tracks->plugin_exists(ptr->plugin))
2992 ptr->close_window();
2995 keyframe_gui_lock->unlock();
2998 void MWindow::update_plugin_guis(int do_keyframe_guis)
3000 // Send new configuration to plugin GUI's
3001 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3003 for(int i = 0; i < plugin_guis->size(); i++)
3005 PluginServer *ptr = plugin_guis->get(i);
3006 if(edl->tracks->plugin_exists(ptr->plugin))
3010 // Schedule for deletion if no plugin
3011 plugin_guis->remove_number(i);
3020 // Change plugin variable if not visible
3021 Track *track = edl->tracks->first;
3024 for(int i = 0; i < track->plugin_set.size(); i++)
3026 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3030 for(int i = 0; i < plugin_guis->size(); i++)
3032 PluginServer *server = plugin_guis->get(i);
3033 if(server->plugin == plugin)
3040 if(!got_it) plugin->show = 0;
3042 plugin = (Plugin*)plugin->next;
3046 track = track->next;
3049 plugin_gui_lock->unlock();
3052 if(do_keyframe_guis) update_keyframe_guis();
3055 int MWindow::plugin_gui_open(Plugin *plugin)
3058 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3059 for(int i = 0; i < plugin_guis->total; i++)
3061 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3067 plugin_gui_lock->unlock();
3071 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3073 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3074 for(int i = 0; i < plugin_guis->total; i++)
3076 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3078 plugin_guis->get(i)->render_gui(data);
3082 plugin_gui_lock->unlock();
3085 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3087 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3088 for(int i = 0; i < plugin_guis->total; i++)
3090 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3092 plugin_guis->get(i)->render_gui(data, size);
3096 plugin_gui_lock->unlock();
3100 void MWindow::update_plugin_states()
3102 plugin_gui_lock->lock("MWindow::update_plugin_states");
3103 for(int i = 0; i < plugin_guis->total; i++)
3107 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3108 PluginServer *src_plugingui = plugin_guis->get(i);
3110 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3111 for(Track *track = edl->tracks->first;
3113 track = track->next)
3116 j < track->plugin_set.total && !result;
3119 PluginSet *plugin_set = track->plugin_set[j];
3120 for(Plugin *plugin = (Plugin*)plugin_set->first;
3122 plugin = (Plugin*)plugin->next)
3124 if(plugin == src_plugin &&
3125 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3131 // Doesn't exist anymore
3134 hide_plugin(src_plugin, 0);
3138 plugin_gui_lock->unlock();
3142 void MWindow::update_plugin_titles()
3144 for(int i = 0; i < plugin_guis->total; i++)
3146 plugin_guis->get(i)->update_title();
3150 int MWindow::asset_to_edl(EDL *new_edl,
3152 RecordLabels *labels)
3154 const int debug = 0;
3155 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3158 // Keep frame rate, sample rate, and output size unchanged.
3159 // These parameters would revert the project if VWindow displayed an asset
3160 // of different size than the project.
3161 if(new_asset->video_data)
3163 new_edl->session->video_tracks = new_asset->layers;
3166 new_edl->session->video_tracks = 0;
3168 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3174 if(new_asset->audio_data)
3176 new_edl->session->audio_tracks = new_asset->channels;
3179 new_edl->session->audio_tracks = 0;
3180 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3182 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3183 new_edl->create_default_tracks();
3184 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3185 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3189 //printf("MWindow::asset_to_edl 3\n");
3190 new_edl->insert_asset(new_asset,
3195 //printf("MWindow::asset_to_edl 3\n");
3196 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3198 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3199 if(edl->session->cursor_on_frames)
3201 double length = new_edl->tracks->total_length();
3202 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3203 new_edl->tracks->clear(length, edl_length, 1, 1);
3209 char string[BCTEXTLEN];
3211 fs.extract_name(string, new_asset->path);
3212 //printf("MWindow::asset_to_edl 3\n");
3214 strcpy(new_edl->local_session->clip_title, string);
3215 //printf("MWindow::asset_to_edl 4 %s\n", string);
3216 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3222 // Reset everything after a load.
3223 void MWindow::update_project(int load_mode)
3225 const int debug = 0;
3227 if(debug) PRINT_TRACE
3228 edl->tracks->update_y_pixels(theme);
3230 if(debug) PRINT_TRACE
3232 if(load_mode == LOADMODE_REPLACE ||
3233 load_mode == LOADMODE_REPLACE_CONCATENATE)
3238 gui->update(1, 1, 1, 1, 1, 1, 1);
3239 if(debug) PRINT_TRACE
3240 gui->unlock_window();
3243 cwindow->gui->lock_window("MWindow::update_project 1");
3244 cwindow->update(0, 0, 1, 1, 1);
3245 cwindow->gui->unlock_window();
3247 if(debug) PRINT_TRACE
3249 // Close all the vwindows
3250 if( load_mode == LOADMODE_REPLACE ||
3251 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3252 if(debug) PRINT_TRACE
3253 int first_vwindow = 0;
3254 if(session->show_vwindow) first_vwindow = 1;
3255 // Change visible windows to no source
3256 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3257 VWindow *vwindow = vwindows[i];
3258 if( !vwindow->is_running() ) continue;
3259 vwindow->change_source(-1);
3262 // Close remaining windows
3263 for(int i = first_vwindow; i < vwindows.size(); i++) {
3264 VWindow *vwindow = vwindows[i];
3265 if( !vwindow->is_running() ) continue;
3266 vwindow->close_window();
3268 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3269 VWindow *vwindow = get_viewer(1, -1);
3270 vwindow->change_source(i);
3272 if(debug) PRINT_TRACE
3276 for( int i=0; i<edl->mixers.size(); ++i ) {
3277 Mixer *mixer = edl->mixers[i];
3278 ZWindow *zwindow = get_mixer(mixer);
3279 zwindow->set_title(mixer->title);
3284 if(vwindows.size()) {
3285 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3286 if( vwindow->is_running() ) {
3287 vwindow->gui->lock_window("MWindow::update_project");
3289 vwindow->gui->unlock_window();
3294 if(debug) PRINT_TRACE
3295 cwindow->gui->lock_window("MWindow::update_project 2");
3296 cwindow->gui->timebar->update(0);
3297 cwindow->gui->unlock_window();
3299 if(debug) PRINT_TRACE
3300 cwindow->refresh_frame(CHANGE_ALL);
3302 awindow->gui->async_update_assets();
3303 if(debug) PRINT_TRACE
3305 gui->lock_window("MWindow::update_project");
3306 gui->update_mixers(0, 0);
3308 if(debug) PRINT_TRACE
3311 void MWindow::remove_indexfile(Indexable *indexable)
3313 if( !indexable->is_asset ) return;
3314 Asset *asset = (Asset *)indexable;
3316 IndexFile::delete_index(preferences, asset, ".toc");
3317 IndexFile::delete_index(preferences, asset, ".idx");
3318 IndexFile::delete_index(preferences, asset, ".mkr");
3321 void MWindow::rebuild_indices()
3323 for(int i = 0; i < session->drag_assets->total; i++)
3325 Indexable *indexable = session->drag_assets->get(i);
3326 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3327 remove_indexfile(indexable);
3328 // Schedule index build
3329 IndexState *index_state = indexable->index_state;
3330 index_state->index_status = INDEX_NOTTESTED;
3331 if( indexable->is_asset ) {
3332 Asset *asset = (Asset *)indexable;
3333 if( asset->format != FILE_PCM ) {
3334 asset->format = FILE_UNKNOWN;
3335 asset->reset_audio();
3337 asset->reset_video();
3338 remove_asset_from_caches(asset);
3339 // File file; // re-probe the asset
3340 // file.open_file(preferences, asset, 1, 0);
3342 mainindexes->add_next_asset(0, indexable);
3344 mainindexes->start_build();
3348 void MWindow::save_backup()
3352 edl->set_path(session->filename);
3353 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3354 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3355 File::get_config_path(), BACKUP_FILE);
3356 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3357 File::get_config_path(), BACKUP_FILE1);
3358 rename(backup_path, backup_path1);
3359 edl->save_xml(&file, backup_path);
3360 file.terminate_string();
3362 fs.complete_path(backup_path);
3364 if(file.write_to_file(backup_path))
3367 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3368 gui->show_message(string2);
3372 void MWindow::load_backup()
3374 ArrayList<char*> path_list;
3375 path_list.set_array_delete();
3377 char backup_path[BCTEXTLEN];
3378 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3379 File::get_config_path(), BACKUP_FILE);
3381 fs.complete_path(backup_path);
3383 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3384 strcpy(out_path, backup_path);
3386 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3387 edl->local_session->clip_title[0] = 0;
3388 // This is unique to backups since the path of the backup is different than the
3389 // path of the project.
3390 set_filename(edl->path);
3391 path_list.remove_all_objects();
3396 void MWindow::save_undo_data()
3398 char perpetual_path[BCTEXTLEN];
3399 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3400 File::get_config_path(), PERPETUAL_FILE);
3401 FILE *fp = fopen(perpetual_path,"w");
3407 void MWindow::load_undo_data()
3409 char perpetual_path[BCTEXTLEN];
3410 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3411 File::get_config_path(), PERPETUAL_FILE);
3412 FILE *fp = fopen(perpetual_path,"r");
3418 static inline int gcd(int m, int n)
3421 if( m < n ) { r = m; m = n; n = r; }
3422 while( (r = m % n) != 0 ) { m = n; n = r; }
3426 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3429 if(!width || !height) return 1;
3430 if( width == 720 && (height == 480 || height == 576) ) {
3431 w = 4; h = 3; return 0; // for NTSC and PAL
3433 double ar = (double)width / height;
3434 // square-ish pixels
3435 if( EQUIV(ar, 1.0000) ) return 0;
3436 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3437 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3438 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3439 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3440 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3441 int ww = width, hh = height;
3442 // numerator, denominator must be under mx
3443 int mx = 255, n = gcd(ww, hh);
3444 if( n > 1 ) { ww /= n; hh /= n; }
3445 // search near height in case extra/missing lines
3446 if( ww >= mx || hh >= mx ) {
3447 double err = height; // +/- 2 percent height
3448 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3449 int iw = width, ih = height+i;
3450 if( (n=gcd(iw, ih)) > 1 ) {
3451 int u = iw/n; if( u >= mx ) continue;
3452 int v = ih/n; if( v >= mx ) continue;
3453 double r = (double) u/v, er = fabs(ar-r);
3454 if( er >= err ) continue;
3455 err = er; ww = u; hh = v;
3464 void MWindow::reset_caches()
3466 frame_cache->remove_all();
3467 wave_cache->remove_all();
3468 audio_cache->remove_all();
3469 video_cache->remove_all();
3470 if( cwindow->playback_engine ) {
3471 if( cwindow->playback_engine->audio_cache )
3472 cwindow->playback_engine->audio_cache->remove_all();
3473 if( cwindow->playback_engine->video_cache )
3474 cwindow->playback_engine->video_cache->remove_all();
3476 for(int i = 0; i < vwindows.size(); i++) {
3477 VWindow *vwindow = vwindows[i];
3478 if( !vwindow->is_running() ) continue;
3479 if( !vwindow->playback_engine ) continue;
3480 if( vwindow->playback_engine->audio_cache )
3481 vwindow->playback_engine->audio_cache->remove_all();
3482 if( vwindow->playback_engine->video_cache )
3483 vwindow->playback_engine->video_cache->remove_all();
3487 void MWindow::remove_asset_from_caches(Asset *asset)
3489 frame_cache->remove_asset(asset);
3490 wave_cache->remove_asset(asset);
3491 audio_cache->delete_entry(asset);
3492 video_cache->delete_entry(asset);
3493 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3494 cwindow->playback_engine->audio_cache->delete_entry(asset);
3495 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3496 cwindow->playback_engine->video_cache->delete_entry(asset);
3497 for(int i = 0; i < vwindows.size(); i++) {
3498 VWindow *vwindow = vwindows[i];
3499 if( !vwindow->is_running() ) continue;
3500 if( !vwindow->playback_engine ) continue;
3501 if( vwindow->playback_engine->audio_cache )
3502 vwindow->playback_engine->audio_cache->delete_entry(asset);
3503 if( vwindow->playback_engine->video_cache )
3504 vwindow->playback_engine->video_cache->delete_entry(asset);
3509 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3510 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3512 for(int i = 0; i < drag_assets->total; i++) {
3513 Indexable *indexable = drag_assets->get(i);
3514 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3517 // Remove from VWindow.
3518 for(int i = 0; i < session->drag_clips->total; i++) {
3519 for(int j = 0; j < vwindows.size(); j++) {
3520 VWindow *vwindow = vwindows[j];
3521 if( !vwindow->is_running() ) continue;
3522 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3523 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3524 vwindow->delete_source(1, 1);
3525 vwindow->gui->unlock_window();
3530 for(int i = 0; i < drag_assets->size(); i++) {
3531 for(int j = 0; j < vwindows.size(); j++) {
3532 VWindow *vwindow = vwindows[j];
3533 if( !vwindow->is_running() ) continue;
3534 if(drag_assets->get(i) == vwindow->get_source()) {
3535 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3536 vwindow->delete_source(1, 1);
3537 vwindow->gui->unlock_window();
3542 for(int i = 0; i < drag_assets->size(); i++) {
3543 Indexable *indexable = drag_assets->get(i);
3544 remove_indexfile(indexable);
3547 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3548 if(push_undo) undo->update_undo_before();
3549 if(drag_assets) edl->remove_from_project(drag_assets);
3550 if(drag_clips) edl->remove_from_project(drag_clips);
3551 if(redraw) save_backup();
3552 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3556 gui->lock_window("MWindow::remove_assets_from_project 3");
3557 gui->update(1, 1, 1, 1, 0, 1, 0);
3558 gui->unlock_window();
3560 // Removes from playback here
3561 sync_parameters(CHANGE_ALL);
3564 awindow->gui->async_update_assets();
3567 void MWindow::remove_assets_from_disk()
3570 for(int i = 0; i < session->drag_assets->total; i++)
3572 remove(session->drag_assets->get(i)->path);
3575 remove_assets_from_project(1,
3577 session->drag_assets,
3578 session->drag_clips);
3581 void MWindow::dump_plugins(FILE *fp)
3583 if( !plugindb ) return;
3584 for(int i = 0; i < plugindb->total; i++)
3586 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3587 " synth=%d transition=%d theme=%d %s\n",
3588 plugindb->get(i)->plugin_type,
3589 plugindb->get(i)->audio,
3590 plugindb->get(i)->video,
3591 plugindb->get(i)->realtime,
3592 plugindb->get(i)->multichannel,
3593 plugindb->get(i)->get_synthesis(),
3594 plugindb->get(i)->transition,
3595 plugindb->get(i)->theme,
3596 plugindb->get(i)->title);
3600 void MWindow::dump_edl(FILE *fp)
3606 void MWindow::dump_undo(FILE *fp)
3612 void MWindow::dump_exe(FILE *fp)
3614 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3615 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3617 int ret = -1, n = 100;
3618 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3619 exe_path[len] = 0; strcpy(proc_path, exe_path);
3622 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3625 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3626 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3627 struct tm *tm = localtime(&st.st_mtime);
3629 strftime(mtime, sizeof(mtime), "%F %T", tm);
3630 fprintf(fp,"mtime: %s\n", mtime);
3632 // people hit ctl-c waiting for this
3633 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3634 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3637 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3638 int64_t maxsz = 1024*pagsz;
3639 int64_t size = st.st_size, pos = 0;
3641 while( (bfrsz = size-pos) > 0 ) {
3642 if( bfrsz > maxsz ) bfrsz = maxsz;
3643 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3644 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3645 if( bfr == MAP_FAILED ) break;
3646 sha1.addBytes(bfr, bfrsz);
3651 ret = pos < size ? EIO : 0;
3652 fprintf(fp, "SHA1: ");
3653 uint8_t digest[20]; sha1.computeHash(digest);
3654 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3655 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3656 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3661 void MWindow::trap_hook(FILE *fp, void *vp)
3663 MWindow *mwindow = (MWindow *)vp;
3664 // fprintf(fp, "\nPLUGINS:\n");
3665 // mwindow->dump_plugins(fp);
3666 fprintf(fp, "\nEDL:\n");
3667 mwindow->dump_edl(fp);
3668 fprintf(fp, "\nUNDO:\n");
3669 mwindow->dump_undo(fp);
3670 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
3671 mwindow->dump_exe(fp);
3679 int MWindow::save_defaults()
3681 gui->save_defaults(defaults);
3682 edl->save_defaults(defaults);
3683 session->save_defaults(defaults);
3684 preferences->save_defaults(defaults);
3686 for(int i = 0; i < plugin_guis->total; i++)
3688 // Pointer comparison
3689 plugin_guis->get(i)->save_defaults();
3691 awindow->save_defaults(defaults);
3697 int MWindow::run_script(FileXML *script)
3699 int result = 0, result2 = 0;
3700 while(!result && !result2)
3702 result = script->read_tag();
3705 if(script->tag.title_is("new_project"))
3707 // Run new in immediate mode.
3708 // gui->mainmenu->new_project->run_script(script);
3711 if(script->tag.title_is("record"))
3713 // Run record as a thread. It is a terminal command.
3715 // Will read the complete scipt file without letting record read it if not
3721 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3728 // ================================= synchronization
3731 int MWindow::interrupt_indexes()
3733 mainprogress->cancelled = 1;
3734 mainindexes->interrupt_build();
3740 void MWindow::next_time_format()
3742 switch(edl->session->time_format)
3744 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3745 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3746 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3747 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3748 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3749 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3750 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3753 time_format_common();
3756 void MWindow::prev_time_format()
3758 switch(edl->session->time_format)
3760 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3761 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3762 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3763 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3764 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3765 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3766 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3769 time_format_common();
3772 void MWindow::time_format_common()
3774 gui->lock_window("MWindow::next_time_format");
3775 gui->redraw_time_dependancies();
3778 char string[BCTEXTLEN], string2[BCTEXTLEN];
3779 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3780 gui->show_message(string);
3782 gui->unlock_window();
3786 int MWindow::set_filename(const char *filename)
3788 if( filename != session->filename )
3789 strcpy(session->filename, filename);
3790 if( filename != edl->path )
3791 strcpy(edl->path, filename);
3795 if(filename[0] == 0)
3797 gui->set_title(PROGRAM_NAME);
3802 char string[BCTEXTLEN], string2[BCTEXTLEN];
3803 dir.extract_name(string, filename);
3804 sprintf(string2, PROGRAM_NAME ": %s", string);
3805 gui->set_title(string2);
3818 int MWindow::set_loop_boundaries()
3820 double start = edl->local_session->get_selectionstart();
3821 double end = edl->local_session->get_selectionend();
3829 if(edl->tracks->total_length())
3832 end = edl->tracks->total_length();
3839 if(edl->local_session->loop_playback && start != end)
3841 edl->local_session->loop_start = start;
3842 edl->local_session->loop_end = end;
3853 int MWindow::reset_meters()
3855 cwindow->gui->lock_window("MWindow::reset_meters 1");
3856 cwindow->gui->meters->reset_meters();
3857 cwindow->gui->unlock_window();
3859 for(int j = 0; j < vwindows.size(); j++) {
3860 VWindow *vwindow = vwindows[j];
3861 if( !vwindow->is_running() ) continue;
3862 vwindow->gui->lock_window("MWindow::reset_meters 2");
3863 vwindow->gui->meters->reset_meters();
3864 vwindow->gui->unlock_window();
3867 lwindow->gui->lock_window("MWindow::reset_meters 3");
3868 lwindow->gui->panel->reset_meters();
3869 lwindow->gui->unlock_window();
3871 gui->lock_window("MWindow::reset_meters 4");
3872 gui->reset_meters();
3873 gui->unlock_window();
3878 void MWindow::resync_guis()
3882 gui->lock_window("MWindow::resync_guis");
3883 gui->update(1, 1, 1, 1, 1, 1, 0);
3884 gui->unlock_window();
3886 cwindow->gui->lock_window("MWindow::resync_guis");
3887 cwindow->gui->resize_event(cwindow->gui->get_w(),
3888 cwindow->gui->get_h());
3889 int channels = edl->session->audio_channels;
3890 cwindow->gui->meters->set_meters(channels, 1);
3891 cwindow->gui->flush();
3892 cwindow->gui->unlock_window();
3894 for(int i = 0; i < vwindows.size(); i++) {
3895 VWindow *vwindow = vwindows[i];
3896 if( !vwindow->is_running() ) continue;
3897 vwindow->gui->lock_window("MWindow::resync_guis");
3898 vwindow->gui->resize_event(vwindow->gui->get_w(),
3899 vwindow->gui->get_h());
3900 vwindow->gui->meters->set_meters(channels, 1);
3901 vwindow->gui->flush();
3902 vwindow->gui->unlock_window();
3905 lwindow->gui->lock_window("MWindow::resync_guis");
3906 lwindow->gui->panel->set_meters(channels, 1);
3907 lwindow->gui->flush();
3908 lwindow->gui->unlock_window();
3911 if(((edl->session->output_w % 4) ||
3912 (edl->session->output_h % 4)) &&
3913 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3915 MainError::show_error(
3916 _("This project's dimensions are not multiples of 4 so\n"
3917 "it can't be rendered by OpenGL."));
3922 sync_parameters(CHANGE_ALL);
3925 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3927 File *file = new File;
3928 EDLSession *session = edl->session;
3929 double old_framerate = session->frame_rate;
3930 double old_samplerate = session->sample_rate;
3931 int old_auto_keyframes = session->auto_keyframes;
3932 session->auto_keyframes = 0;
3933 int result = file->open_file(preferences, asset, 1, 0);
3934 if( !result && delete_tracks > 0 )
3935 undo->update_undo_before();
3936 int video_layers = asset->get_video_layers();
3937 if( !result && asset->video_data && vstream < video_layers ) {
3938 // try to get asset up to date, may fail
3939 file->select_video_stream(asset, vstream);
3940 // either way use what was/is there.
3941 double framerate = asset->get_frame_rate();
3942 int width = asset->get_w();
3943 int height = asset->get_h();
3944 // must be multiple of 4 for opengl
3945 width = (width+3) & ~3; height = (height+3) & ~3;
3946 int driver = session->playback_config->vconfig->driver;
3947 int color_model = file->get_best_colormodel(asset, driver);
3948 // color_model = BC_CModels::is_yuv(color_model) ?
3949 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3950 // BC_CModels::is_float(color_model) ?
3951 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3952 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3953 // have alpha for now
3954 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3955 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3956 session->color_model = color_model;
3957 session->output_w = width;
3958 session->output_h = height;
3959 session->frame_rate = framerate;
3960 // not, asset->actual_width/actual_height
3961 asset->width = session->output_w;
3962 asset->height = session->output_h;
3963 asset->frame_rate = session->frame_rate;
3964 create_aspect_ratio(session->aspect_w, session->aspect_h,
3965 session->output_w, session->output_h);
3966 Track *track = edl->tracks->first;
3967 for( Track *next_track=0; track; track=next_track ) {
3968 next_track = track->next;
3969 if( track->data_type != TRACK_VIDEO ) continue;
3970 if( delete_tracks ) {
3971 Edit *edit = track->edits->first;
3972 for( Edit *next_edit=0; edit; edit=next_edit ) {
3973 next_edit = edit->next;
3974 if( edit->channel != vstream ||
3975 !edit->asset || !edit->asset->is_asset ||
3976 !asset->equivalent(*edit->asset,1,1,edl) )
3980 if( track->edits->first ) {
3981 track->track_w = edl->session->output_w;
3982 track->track_h = edl->session->output_h;
3984 else if( delete_tracks )
3985 edl->tracks->delete_track(track);
3988 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3990 if( !result && asset->audio_data && asset->channels > 0 ) {
3991 session->sample_rate = asset->get_sample_rate();
3992 int64_t channel_mask = 0;
3993 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
3994 file->get_audio_for_video(vstream, astream, channel_mask);
3995 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3996 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3998 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3999 if( channels < 1 ) channels = 1;
4000 if( channels > 6 ) channels = 6;
4001 session->audio_tracks = session->audio_channels = channels;
4003 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4004 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4005 remap_audio(MWindow::AUDIO_1_TO_1);
4007 if( delete_tracks ) {
4008 Track *track = edl->tracks->first;
4009 for( Track *next_track=0; track; track=next_track ) {
4010 next_track = track->next;
4011 if( track->data_type != TRACK_AUDIO ) continue;
4012 Edit *edit = track->edits->first;
4013 for( Edit *next_edit=0; edit; edit=next_edit ) {
4014 next_edit = edit->next;
4015 if( !((1<<edit->channel) & channel_mask) ||
4016 !edit->asset || !edit->asset->is_asset ||
4017 !asset->equivalent(*edit->asset,1,1,edl) )
4020 if( !track->edits->first )
4021 edl->tracks->delete_track(track);
4025 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4028 session->auto_keyframes = old_auto_keyframes;
4029 if( !result && delete_tracks > 0 ) {
4031 undo->update_undo_after(_("select asset"), LOAD_ALL);
4037 int MWindow::select_asset(int vtrack, int delete_tracks)
4039 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4041 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4042 if( !track ) return 1;
4043 Edit *edit = track->edits->first;
4044 if( !edit ) return 1;
4045 Asset *asset = edit->asset;
4046 if( !asset || !asset->is_asset ) return 1;
4047 return select_asset(asset, edit->channel, 0, delete_tracks);
4050 void MWindow::dump_plugindb(FILE *fp)
4052 if( !plugindb ) return;
4053 for(int i = 0; i < plugindb->total; i++)
4054 plugindb->get(i)->dump(fp);
4057 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4060 double unit_position = edl->local_session->get_selectionstart(1);
4061 unit_position = patch->track->to_units(unit_position, 0);
4063 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4064 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4067 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4070 double unit_position = edl->local_session->get_selectionstart(1);
4071 unit_position = patch->track->to_units(unit_position, 0);
4073 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4074 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4077 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4080 double unit_position = edl->local_session->get_selectionstart(1);
4081 unit_position = patch->track->to_units(unit_position, 0);
4083 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4084 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4087 PatchGUI *MWindow::get_patchgui(Track *track)
4089 PatchGUI *patchgui = 0;
4090 TimelinePane **panes = gui->pane;
4091 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4092 if( !panes[i] ) continue;
4093 PatchBay *patchbay = panes[i]->patchbay;
4094 if( !patchbay ) continue;
4095 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4096 if( patchbay->patches.values[j]->track == track )
4097 patchgui = patchbay->patches.values[j];