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;
237 // Need to delete brender temporary here.
240 run_lock->lock("MWindow::~MWindow");
242 //printf("MWindow::~MWindow %d\n", __LINE__);
243 gui->remote_control->deactivate();
246 gui->channel_info->stop();
248 delete create_bd; create_bd = 0;
249 delete create_dvd; create_dvd = 0;
250 delete batch_render; batch_render = 0;
251 delete render; render = 0;
253 if( commercials && !commercials->remove_user() ) commercials = 0;
255 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
256 // Save defaults for open plugins
257 plugin_gui_lock->lock("MWindow::~MWindow");
258 for(int i = 0; i < plugin_guis->size(); i++) {
259 plugin_guis->get(i)->hide_gui();
260 delete_plugin(plugin_guis->get(i));
262 plugin_gui_lock->unlock();
263 hide_keyframe_guis();
266 // Give up and go to a movie
267 // cant run valgrind if this is used
269 gui->del_keyboard_listener(
270 (int (BC_WindowBase::*)(BC_WindowBase *))
271 &MWindowGUI::keyboard_listener);
273 // release the hounds
274 if( awindow && awindow->gui ) awindow->gui->close(0);
275 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
276 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
277 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
278 if( twindow && twindow->is_running() ) twindow->close_window();
279 if( wwindow && wwindow->is_running() ) wwindow->close_window();
280 vwindows.remove_all_objects();
281 zwindows.remove_all_objects();
283 if( awindow ) awindow->join();
284 if( cwindow ) cwindow->join();
285 if( lwindow ) lwindow->join();
286 if( twindow ) twindow->join();
287 if( wwindow ) wwindow->join();
288 if( gwindow ) gwindow->join();
291 // one at a time, or nouveau chokes
292 #define close_gui(win) if( win ) { \
293 if( win->gui ) win->gui->close(0); \
301 vwindows.remove_all_objects();
302 zwindows.remove_all_objects();
307 dead_plugins->remove_all_objects();
308 // must delete theme before destroying plugindb
309 // theme destructor will be deleted by delete_plugins
310 delete theme; theme = 0;
313 keyframe_threads->remove_all_objects();
314 colormodels.remove_all_objects();
315 delete awindow; awindow = 0;
316 delete lwindow; lwindow = 0;
317 delete twindow; twindow = 0;
318 delete wwindow; wwindow = 0;
319 delete gwindow; gwindow = 0;
320 delete cwindow; cwindow = 0;
322 //delete file_server; file_server = 0; // reusable
323 delete mainindexes; mainindexes = 0;
324 delete mainprogress; mainprogress = 0;
325 delete audio_cache; audio_cache = 0; // delete the cache after the assets
326 delete video_cache; video_cache = 0; // delete the cache after the assets
327 delete frame_cache; frame_cache = 0;
328 delete wave_cache; wave_cache = 0;
329 delete plugin_guis; plugin_guis = 0;
330 delete dead_plugins; dead_plugins = 0;
331 delete keyframe_threads; keyframe_threads = 0;
332 delete undo; undo = 0;
333 delete preferences; preferences = 0;
334 delete exportedl; exportedl = 0;
335 delete session; session = 0;
336 delete defaults; defaults = 0;
337 delete assets; assets = 0;
338 delete splash_window; splash_window = 0;
339 if( !edl->Garbage::remove_user() ) edl = 0;
340 delete channeldb_buz;
341 delete channeldb_v4l2jpeg;
342 // This must be last thread to exit
343 delete playback_3d; playback_3d = 0;
344 delete dead_plugin_lock;
345 delete plugin_gui_lock;
346 delete vwindows_lock;
347 delete zwindows_lock;
349 delete keyframe_gui_lock;
350 colormodels.remove_all_objects();
351 interlace_project_modes.remove_all_objects();
352 interlace_asset_modes.remove_all_objects();
353 interlace_asset_fixmethods.remove_all_objects();
354 sighandler->terminate();
365 void MWindow::init_error()
367 MainError::init_error(this);
370 void MWindow::finit_error()
372 MainError::finit_error();
375 void MWindow::create_defaults_path(char *string, const char *config_file)
377 // set the .bcast path
380 sprintf(string, "%s/", File::get_config_path());
381 fs.complete_path(string);
382 if(!fs.is_dir(string))
383 fs.create_dir(string);
386 strcat(string, config_file);
388 const char *MWindow::default_std()
390 char buf[BCTEXTLEN], *p = 0;
392 int fd = open(TIMEZONE_NAME, O_RDONLY);
394 int l = read(fd, buf, sizeof(buf)-1);
397 if( buf[l-1] == '\n' ) --l;
403 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
406 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
407 p += strlen(ZONEINFO_STR);
412 for( int i=0; ntsc_zones[i]; ++i ) {
413 if( !strcmp(ntsc_zones[i], p) )
420 for( int i=0; ntsc_zones[i]; ++i ) {
421 if( !strcmp(ntsc_zones[i], p) )
426 //__timezone: Seconds west of UTC. 240sec/deg
427 double tz_deg = -__timezone / 240.;
428 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
429 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
432 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
434 struct formatpresets *fpr;
436 for(fpr = &format_presets[0]; fpr->name; fpr++)
438 if(strcmp(_(fpr->name), preset) == 0)
440 session->audio_channels = fpr->audio_channels;
441 session->audio_tracks = fpr->audio_tracks;
442 session->sample_rate = fpr->sample_rate;
443 session->video_channels = fpr->video_channels;
444 session->video_tracks = fpr->video_tracks;
445 session->frame_rate = fpr->frame_rate;
446 session->output_w = fpr->output_w;
447 session->output_h = fpr->output_h;
448 session->aspect_w = fpr->aspect_w;
449 session->aspect_h = fpr->aspect_h;
450 session->interlace_mode = fpr->interlace_mode;
451 session->color_model = fpr->color_model;
457 const char *MWindow::get_preset_name(int index)
459 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
461 return _(format_presets[index].name);
465 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
467 char path[BCTEXTLEN];
468 // Use user supplied path
470 strcpy(path, config_path);
472 create_defaults_path(path, CONFIG_FILE);
474 defaults = new BC_Hash(path);
479 void MWindow::check_language()
481 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
482 const char *env_lang = getenv("LANGUAGE");
483 if( !env_lang ) env_lang = getenv("LC_ALL");
484 if( !env_lang ) env_lang = getenv("LANG");
486 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
487 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
488 env_lang = curr_lang;
490 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
491 defaults->get("LAST_LANG",last_lang);
492 if( strcmp(env_lang,last_lang)) {
493 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
494 defaults->update("LAST_LANG",env_lang);
495 char plugin_path[BCTEXTLEN];
496 create_defaults_path(plugin_path, PLUGIN_FILE);
497 ::remove(plugin_path);
498 char ladspa_path[BCTEXTLEN];
499 create_defaults_path(ladspa_path, LADSPA_FILE);
500 ::remove(ladspa_path);
503 if( strlen(env_lang) > 1 &&
504 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
505 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
508 strcpy(cin_lang, "en");
511 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
513 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
515 const char *dp = plug_dir;
516 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
517 bp = !*dp && *bp == '/' ? bp+1 : base_path;
523 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
526 FILE *fp = fopen(index_path, "r");
530 char index_line[BCTEXTLEN];
531 int index_version = -1, len = strlen(plugin_dir);
532 if( !fgets(index_line, BCTEXTLEN, fp) ||
533 sscanf(index_line, "%d", &index_version) != 1 ||
534 index_version != PLUGIN_FILE_VERSION ||
535 !fgets(index_line, BCTEXTLEN, fp) ||
536 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
537 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
539 ArrayList<PluginServer*> plugins;
540 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
541 if( index_line[0] == ';' ) continue;
542 if( index_line[0] == '#' ) continue;
543 int type = PLUGIN_TYPE_UNKNOWN;
544 char path[BCTEXTLEN], title[BCTEXTLEN];
546 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
549 PluginServer *server = 0;
551 case PLUGIN_TYPE_BUILTIN:
552 case PLUGIN_TYPE_EXECUTABLE:
553 case PLUGIN_TYPE_LADSPA: {
554 char plugin_path[BCTEXTLEN]; struct stat st;
555 sprintf(plugin_path, "%s/%s", plugin_dir, path);
556 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
559 server = new PluginServer(mwindow, plugin_path, type);
561 case PLUGIN_TYPE_FFMPEG: {
562 server = new_ffmpeg_server(mwindow, path);
565 if( !server ) continue;
566 plugins.append(server);
567 // Create plugin server from index entry
568 server->set_title(title);
569 if( server->read_table(index_line) ) {
576 ret = check_plugin_index(plugins, plugin_dir, ".");
579 add_plugins(plugins);
581 plugins.remove_all_objects();
586 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
587 const char *plug_dir, const char *plug_path)
589 char plugin_path[BCTEXTLEN];
590 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
592 fs.set_filter( "[*.plugin][*.so]" );
593 if( fs.update(plugin_path) )
596 for( int i=0; i<fs.dir_list.total; ++i ) {
597 char fs_path[BCTEXTLEN];
598 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
599 if( fs.is_dir(fs_path) ) {
600 get_plugin_path(plugin_path, plug_dir, fs_path);
601 if( check_plugin_index(plugins, plug_dir, plugin_path) )
604 else if( !plugin_exists(fs_path, plugins) )
611 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
614 plugindb = new ArrayList<PluginServer*>;
616 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
617 create_defaults_path(index_path, PLUGIN_FILE);
618 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
619 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
620 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
621 printf("init plugin index: %s\n", plugin_path);
622 FILE *fp = fopen(index_path,"w");
624 fprintf(stderr,_("MWindow::init_plugins: "
625 "can't create plugin index: %s\n"), index_path);
628 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
629 fprintf(fp, "%s\n", plugin_path);
630 init_plugin_index(mwindow, preferences, fp, plugin_path);
631 init_ffmpeg_index(mwindow, preferences, fp);
633 return load_plugin_index(mwindow, index_path, plugin_path);
636 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
638 char *path = getenv("LADSPA_PATH");
639 char ladspa_path[BCTEXTLEN];
641 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
644 for( int len=0; *path; path+=len ) {
645 char *cp = strchr(path,':');
646 len = !cp ? strlen(path) : cp-path;
647 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
648 memcpy(plugin_path, path, len); plugin_path[len] = 0;
650 char *plugin_dir = FileSystem::basepath(plugin_path);
651 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
652 create_defaults_path(index_path, LADSPA_FILE);
653 cp = index_path + strlen(index_path);
654 for( char *bp=plugin_path; *bp!=0; ++bp )
655 *cp++ = *bp=='/' ? '_' : *bp;
657 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
658 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
659 load_plugin_index(mwindow, index_path, plugin_path);
664 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
665 FILE *fp, const char *plugin_dir)
667 int idx = PLUGIN_IDS;
669 for( int i=0; i<plugindb->size(); ++i ) {
670 PluginServer *server = plugindb->get(i);
671 if( server->dir_idx >= idx )
672 idx = server->dir_idx+1;
675 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
678 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
679 const char *index_path, const char *plugin_dir)
681 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
682 strcpy(plugin_path, path); delete [] path;
683 printf("init ladspa index: %s\n", plugin_dir);
684 FILE *fp = fopen(index_path,"w");
686 fprintf(stderr,_("MWindow::init_ladspa_index: "
687 "can't create plugin index: %s\n"), index_path);
690 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
691 fprintf(fp, "%s\n", plugin_dir);
692 init_plugin_index(mwindow, preferences, fp, plugin_path);
697 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
698 const char *plug_dir, const char *plug_path, int &idx)
700 char plugin_path[BCTEXTLEN];
701 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
703 fs.set_filter( "[*.plugin][*.so]" );
704 int result = fs.update(plugin_path);
705 if( result || !fs.dir_list.total ) return;
708 for( int i=0; i<fs.dir_list.total; ++i ) {
709 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
710 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
711 get_plugin_path(path, plug_dir, fs_path);
712 if( fs.is_dir(fs_path) ) {
713 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
716 if( plugin_exists(path) ) continue;
718 if( stat(fs_path, &st) ) continue;
719 int64_t mtime = st.st_mtime;
720 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
721 result = server.open_plugin(1, preferences, 0, 0);
723 server.write_table(fp, path, vis_id, mtime);
724 server.close_plugin();
726 else if( result == PLUGINSERVER_IS_LAD ) {
729 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
730 ladspa.set_lad_index(lad_index++);
731 result = ladspa.open_plugin(1, preferences, 0, 0);
733 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
734 ladspa.close_plugin();
740 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
742 for( int i=0; i<plugins.size(); ++i )
743 plugindb->append(plugins[i]);
744 plugins.remove_all();
747 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
749 const char *cfg_path = File::get_cindat_path();
750 char msg_path[BCTEXTLEN];
752 if( BC_Resources::language[0] ) {
753 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
755 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 int idx = plugins.size();
779 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
781 delete [] plugins[idx]->tip;
782 plugins[idx]->tip = cstrdup(text);
786 if( done > 0 ) break;
788 char *dp = strchr(cp, ':');
790 printf("plugin tips: error on line %d\n", no);
794 while( cp < dp ) *bp++ = *cp++;
799 while( *cp == ' ' || *cp == '\t' ) ++cp;
800 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
805 void MWindow::delete_plugins()
807 plugindb->remove_all_objects();
812 void MWindow::search_plugindb(int do_audio,
817 ArrayList<PluginServer*> &results)
820 for(int i = 0; i < MWindow::plugindb->total; i++)
822 PluginServer *current = MWindow::plugindb->get(i);
824 if(current->audio == do_audio &&
825 current->video == do_video &&
826 (current->realtime == is_realtime || is_realtime < 0) &&
827 current->transition == is_transition &&
828 current->theme == is_theme)
829 results.append(current);
832 // Alphabetize list by title
838 for(int i = 0; i < results.total - 1; i++)
840 PluginServer *value1 = results[i];
841 PluginServer *value2 = results[i + 1];
842 if(strcmp(_(value1->title), _(value2->title)) > 0)
846 results[i + 1] = value1;
852 PluginServer* MWindow::scan_plugindb(char *title,
857 // printf("MWindow::scan_plugindb data_type < 0\n");
861 for(int i = 0; i < plugindb->total; i++)
863 PluginServer *server = plugindb->get(i);
865 !strcasecmp(server->title, title) &&
867 (data_type == TRACK_AUDIO && server->audio) ||
868 (data_type == TRACK_VIDEO && server->video)))
869 return plugindb->get(i);
874 // repair session files with xlated plugin titles
875 void MWindow::fix_plugin_title(char *title)
877 for(int i = 0; i < plugindb->total; i++) {
878 PluginServer *server = plugindb->get(i);
879 if( !server->title ) continue;
880 const char *server_title = server->title;
881 if( !bstrcasecmp(title, _(server_title)) ) {
882 strcpy(title, server_title);
888 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
890 for( int i=0; i<plugins.size(); ++i )
891 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
895 int MWindow::plugin_exists(char *plugin_path)
897 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
900 void MWindow::init_preferences()
902 preferences = new Preferences;
903 preferences->load_defaults(defaults);
904 session = new MainSession(this);
905 session->load_defaults(defaults);
906 // set x11_host, screens, window_config
907 screens = session->set_default_x11_host();
908 BC_Signals::set_trap_hook(trap_hook, this);
909 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
910 BC_Signals::set_catch_intr(preferences->trap_sigintr);
911 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
912 BC_Trace::enable_locks();
915 BC_Trace::disable_locks();
917 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
918 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
919 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
920 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
923 void MWindow::clean_indexes()
928 int oldest_item = -1;
930 char string[BCTEXTLEN];
931 char string2[BCTEXTLEN];
933 // Delete extra indexes
934 fs.set_filter("*.idx");
935 fs.complete_path(preferences->index_directory);
936 fs.update(preferences->index_directory);
937 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
939 // Eliminate directories
944 for(int i = 0; i < fs.dir_list.total && !result; i++)
946 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
947 if(fs.is_dir(string))
949 delete fs.dir_list[i];
950 fs.dir_list.remove_number(i);
955 total_excess = fs.dir_list.total - preferences->index_count;
957 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
958 while(total_excess > 0)
961 for(int i = 0; i < fs.dir_list.total; i++)
963 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
965 if(i == 0 || fs.get_date(string) <= oldest)
967 oldest = fs.get_date(string);
975 fs.join_names(string,
976 preferences->index_directory,
977 fs.dir_list[oldest_item]->name);
978 //printf("MWindow::clean_indexes 1 %s\n", string);
980 perror("delete_indexes");
981 delete fs.dir_list[oldest_item];
982 fs.dir_list.remove_number(oldest_item);
984 // Remove table of contents if it exists
985 strcpy(string2, string);
986 char *ptr = strrchr(string2, '.');
989 //printf("MWindow::clean_indexes 2 %s\n", string2);
990 sprintf(ptr, ".toc");
992 sprintf(ptr, ".mkr");
1001 void MWindow::init_awindow()
1003 awindow = new AWindow(this);
1004 awindow->create_objects();
1007 void MWindow::init_gwindow()
1009 gwindow = new GWindow(this);
1010 gwindow->create_objects();
1013 void MWindow::init_tipwindow()
1015 TipWindow::load_tips(cin_lang);
1017 twindow = new TipWindow(this);
1021 void MWindow::show_warning(int *do_warning, const char *text)
1023 if( do_warning && !*do_warning ) return;
1025 wwindow = new WWindow(this);
1026 wwindow->show_warning(do_warning, text);
1029 int MWindow::wait_warning()
1031 return wwindow->wait_result();
1034 void MWindow::init_theme()
1039 PluginServer *theme_plugin = 0;
1040 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1041 if( plugindb->get(i)->theme &&
1042 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1043 theme_plugin = plugindb->get(i);
1047 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1048 preferences->theme);
1050 const char *default_theme = DEFAULT_THEME;
1051 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1052 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1054 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1055 if( plugindb->get(i)->theme &&
1056 !strcasecmp(default_theme, plugindb->get(i)->title) )
1057 theme_plugin = plugindb->get(i);
1062 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1066 PluginServer *plugin = new PluginServer(*theme_plugin);
1067 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1068 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1069 theme_plugin->title);
1073 theme = plugin->new_theme();
1074 theme->mwindow = this;
1075 strcpy(theme->path, plugin->path);
1078 // Load default images & settings
1079 theme->Theme::initialize();
1080 // Load user images & settings
1081 theme->initialize();
1082 // Create menus with user colors
1083 theme->build_menus();
1086 theme->sort_image_sets();
1087 theme->check_used();
1088 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1091 void MWindow::init_3d()
1093 playback_3d = new Playback3D(this);
1094 playback_3d->create_objects();
1097 void MWindow::init_edl()
1100 edl->create_objects();
1101 fill_preset_defaults(default_standard, edl->session);
1102 edl->load_defaults(defaults);
1103 edl->session->brender_start = edl->session->brender_end = 0;
1104 edl->create_default_tracks();
1105 edl->tracks->update_y_pixels(theme);
1108 void MWindow::init_compositor()
1110 cwindow = new CWindow(this);
1111 cwindow->create_objects();
1114 void MWindow::init_levelwindow()
1116 lwindow = new LevelWindow(this);
1117 lwindow->create_objects();
1120 VWindow *MWindow::get_viewer(int start_it, int idx)
1122 vwindows_lock->lock("MWindow::get_viewer");
1123 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1124 if( !vwindow ) idx = vwindows.size();
1125 while( !vwindow && --idx >= 0 ) {
1126 VWindow *vwin = vwindows[idx];
1127 if( !vwin->is_running() || !vwin->get_edl() )
1131 vwindow = new VWindow(this);
1132 vwindow->load_defaults();
1133 vwindow->create_objects();
1134 vwindows.append(vwindow);
1136 vwindows_lock->unlock();
1137 if( start_it ) vwindow->start();
1141 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1143 zwindows_lock->lock("MWindow::get_mixer");
1144 if( !mixer ) mixer = edl->mixers.new_mixer();
1145 ZWindow *zwindow = 0;
1146 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1147 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1149 zwindows.append(zwindow = new ZWindow(this));
1150 zwindow->idx = mixer->idx;
1151 zwindows_lock->unlock();
1155 void MWindow::del_mixer(ZWindow *zwindow)
1157 zwindows_lock->lock("MWindow::del_mixer 0");
1158 edl->mixers.del_mixer(zwindow->idx);
1160 if( session->selected_zwindow >= 0 ) {
1161 int i = zwindows.number_of(zwindow);
1162 if( i >= 0 && i < session->selected_zwindow )
1163 --session->selected_zwindow;
1164 else if( i == session->selected_zwindow )
1165 session->selected_zwindow = -1;
1167 zwindows_lock->unlock();
1168 gui->lock_window("MWindow::del_mixer 1");
1169 gui->update_mixers(0, -1);
1170 gui->unlock_window();
1173 void MWindow::start_mixer()
1176 ZWindow *zwindow = get_mixer(mixer);
1177 const char *title = 0;
1179 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1180 PatchGUI *patchgui = get_patchgui(track);
1181 if( !patchgui || !patchgui->mixer ) continue;
1182 mixer->mixer_ids.append(track->get_mixer_id());
1183 if( !title ) title = track->title;
1186 session->selected_zwindow = -1;
1187 gui->lock_window("MWindow::start_mixer");
1188 gui->update_mixers(0, 0);
1189 gui->unlock_window();
1191 zwindow->set_title(title);
1196 int MWindow::mixer_track_active(Track *track)
1198 int i = session->selected_zwindow;
1199 if( i < 0 || i >= zwindows.size() ) return 0;
1200 ZWindow *zwindow = zwindows[i];
1201 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1202 if( !mixer ) return 0;
1203 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1204 return n >= 0 ? 1 : 0;
1207 void MWindow::update_mixer_tracks()
1209 zwindows_lock->lock("MixPatch::handle_event");
1210 int i = session->selected_zwindow;
1211 if( i >= 0 && i < zwindows.size() ) {
1212 ZWindow *zwindow = zwindows[i];
1213 zwindow->update_mixer_ids();
1215 zwindows_lock->unlock();
1218 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1219 int use_inout, int update_refresh, int toggle_audio, int loop_play)
1221 zwindows_lock->lock("MWindow::queue_mixers");
1222 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1223 ZWindow *zwindow = zwindows[vidx];
1224 if( zwindow->idx < 0 ) continue;
1225 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1226 if( !mixer || !mixer->mixer_ids.size() ) continue;
1228 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1229 if( track->data_type != TRACK_VIDEO ) continue;
1230 int mixer_id = track->get_mixer_id();
1231 k = mixer->mixer_ids.size();
1232 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1234 if( k < 0 ) continue;
1235 EDL *mixer_edl = new EDL(this->edl);
1236 mixer_edl->create_objects();
1237 mixer_edl->copy_all(edl);
1238 mixer_edl->remove_vwindow_edls();
1239 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1240 k = mixer->mixer_ids.size();
1241 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1244 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1247 track->record = track->play = 0;
1249 zwindow->change_source(mixer_edl);
1250 zwindow->issue_command(command,
1251 wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
1253 zwindows_lock->unlock();
1256 void MWindow::refresh_mixers(int dir)
1258 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1259 queue_mixers(edl,command,0,0,1,0,0);
1262 void MWindow::stop_mixers()
1264 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1265 ZWindow *zwindow = zwindows[vidx];
1266 if( zwindow->idx < 0 ) continue;
1267 zwindow->issue_command(STOP, 0, 0, 0, 0, 0);
1271 void MWindow::close_mixers()
1273 zwindows_lock->lock("MWindow::close_mixers");
1274 for( int i=0; i<zwindows.size(); ++i ) {
1275 ZWindow *zwindow = zwindows[i];
1276 if( zwindow->idx < 0 ) continue;
1277 ZWindowGUI *zgui = zwindow->zgui;
1278 zgui->lock_window("MWindow::select_zwindow 0");
1280 zgui->unlock_window();
1282 zwindows_lock->unlock();
1283 for( int i=0; i<zwindows.size(); ++i ) {
1284 ZWindow *zwindow = zwindows[i];
1285 if( zwindow->idx < 0 ) continue;
1286 zwindow->close_window();
1290 ZWindow *MWindow::create_mixer(Indexable *indexable)
1292 ArrayList<Indexable*> new_assets;
1293 new_assets.append(indexable);
1294 Track *track = edl->tracks->last;
1295 load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
1296 track = !track ? edl->tracks->first : track->next;
1298 ZWindow *zwindow = get_mixer(mixer);
1300 track->play = track->record = 0;
1301 if( track->data_type == TRACK_VIDEO ) {
1302 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1304 mixer->mixer_ids.append(track->get_mixer_id());
1305 track = track->next;
1307 if( indexable->is_asset ) {
1308 char *path = indexable->path;
1309 char *tp = strrchr(path, '/');
1310 if( !tp ) tp = path; else ++tp;
1311 zwindow->set_title(tp);
1314 char *title = ((EDL*)indexable)->local_session->clip_title;
1315 zwindow->set_title(title);
1320 void MWindow::create_mixers()
1322 if( !session->drag_assets->size() &&
1323 !session->drag_clips->size() ) return;
1324 undo->update_undo_before();
1327 ArrayList<ZWindow *>new_mixers;
1329 for( int i=0; i<session->drag_assets->size(); ++i ) {
1330 Indexable *indexable = session->drag_assets->get(i);
1331 ZWindow *zwindow = create_mixer(indexable);
1332 new_mixers.append(zwindow);
1334 for( int i=0; i<session->drag_clips->size(); ++i ) {
1335 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1336 ZWindow *zwindow = create_mixer(indexable);
1337 new_mixers.append(zwindow);
1341 for( int i=0; i<new_mixers.size(); ++i )
1342 new_mixers[i]->start();
1346 undo->update_undo_after(_("create mixers"), LOAD_ALL);
1348 gui->update(1, 2, 1, 1, 1, 1, 0);
1349 sync_parameters(CHANGE_ALL);
1352 void MWindow::open_mixers()
1354 for( int i=0; i<edl->mixers.size(); ++i ) {
1355 Mixer *mixer = edl->mixers[i];
1356 ZWindow *zwindow = get_mixer(mixer);
1357 zwindow->set_title(mixer->title);
1363 int MWindow::select_zwindow(ZWindow *zwindow)
1365 int ret = 0, n = zwindows.number_of(zwindow);
1366 if( session->selected_zwindow != n ) {
1367 session->selected_zwindow = n;
1368 for( int i=0; i<zwindows.size(); ++i ) {
1369 ZWindow *zwindow = zwindows[i];
1370 if( zwindow->idx < 0 ) continue;
1371 ZWindowGUI *zgui = zwindow->zgui;
1372 zgui->lock_window("MWindow::select_zwindow 0");
1373 zwindow->highlighted = i == n ? 1 : 0;
1374 if( zgui->draw_overlays() )
1375 zgui->canvas->get_canvas()->flash(1);
1376 zgui->unlock_window();
1379 gui->lock_window("MWindow::select_window 1");
1380 gui->update_mixers(0, -1);
1381 gui->unlock_window();
1386 void MWindow::tile_mixers()
1389 for( int i=0; i<zwindows.size(); ++i ) {
1390 ZWindow *zwindow = zwindows[i];
1391 if( zwindow->idx < 0 ) continue;
1395 int zn = ceil(sqrt(nz));
1396 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1397 int y1 = 1, y2 = gui->get_y();
1398 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1399 if( x1 < 0 ) x1 = 0;
1400 if( y1 < 0 ) y1 = 0;
1401 if( x2 > rw ) x2 = rw;
1402 if( y2 > rh ) y2 = rh;
1403 int dx = x2 - x1, dy = y2 - y1;
1405 int lt = BC_DisplayInfo::get_left_border();
1406 int top = BC_DisplayInfo::get_top_border();
1407 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1408 int bh = top + BC_DisplayInfo::get_bottom_border();
1409 int zx = 0, zy = 0; // window origins
1410 int mw = 10+10, mh = 10+10; // canvas margins
1411 int rsz = 0, n = 0, dz = 0;
1412 int ow = edl->session->output_w, oh = edl->session->output_h;
1413 for( int i=0; i<zwindows.size(); ++i ) {
1414 ZWindow *zwindow = zwindows[i];
1415 if( zwindow->idx < 0 ) continue;
1416 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1417 if( rsz < hh ) rsz = hh;
1418 int xx = zx + x1, yy = zy + y1;
1419 int mx = x2 - zw, my = y2 - zh;
1420 if( xx > mx ) xx = mx;
1421 if( yy > my ) yy = my;
1422 xx += lt + dz; yy += top + dz;
1423 zwindow->reposition(xx,yy, ww,hh);
1424 if( zwindow->running() ) {
1425 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1426 gui->lock_window("MWindow::tile_mixers");
1427 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1428 gui->unlock_window();
1432 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1441 void MWindow::init_cache()
1443 audio_cache = new CICache(preferences);
1444 video_cache = new CICache(preferences);
1445 frame_cache = new FrameCache;
1446 wave_cache = new WaveCache;
1449 void MWindow::init_channeldb()
1451 channeldb_buz->load("channeldb_buz");
1452 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1455 void MWindow::init_menus()
1457 char string[BCTEXTLEN];
1460 BC_CModels::to_text(string, BC_RGB888);
1461 colormodels.append(new ColormodelItem(string, BC_RGB888));
1462 BC_CModels::to_text(string, BC_RGBA8888);
1463 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1464 // BC_CModels::to_text(string, BC_RGB161616);
1465 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1466 // BC_CModels::to_text(string, BC_RGBA16161616);
1467 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1468 BC_CModels::to_text(string, BC_RGB_FLOAT);
1469 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1470 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1471 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1472 BC_CModels::to_text(string, BC_YUV888);
1473 colormodels.append(new ColormodelItem(string, BC_YUV888));
1474 BC_CModels::to_text(string, BC_YUVA8888);
1475 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1476 // BC_CModels::to_text(string, BC_YUV161616);
1477 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1478 // BC_CModels::to_text(string, BC_YUVA16161616);
1479 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1481 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1482 interlace_project_modes.append(new InterlacemodeItem(string, x));
1484 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1485 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1487 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1488 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1490 // Interlacing Modes
1491 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1493 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1494 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1496 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1497 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1499 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1500 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1502 // Interlacing Fixing Methods
1503 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1504 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1505 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1508 void MWindow::init_indexes()
1510 mainindexes = new MainIndexes(this);
1511 mainindexes->start_loop();
1514 void MWindow::init_gui()
1516 gui = new MWindowGUI(this);
1517 gui->lock_window("MWindow::init_gui");
1518 gui->create_objects();
1519 gui->unlock_window();
1520 gui->load_defaults(defaults);
1523 void MWindow::init_signals()
1525 sighandler = new SigHandler;
1526 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1530 void MWindow::init_render()
1532 render = new Render(this);
1533 create_bd = new CreateBD_Thread(this);
1534 create_dvd = new CreateDVD_Thread(this);
1535 batch_render = new BatchRenderThread(this);
1538 void MWindow::init_exportedl()
1540 exportedl = new ExportEDL(this);
1543 void MWindow::init_brender()
1545 if(preferences->use_brender && !brender)
1547 brender_lock->lock("MWindow::init_brender 1");
1548 brender = new BRender(this);
1549 brender->initialize();
1550 session->brender_end = 0;
1551 brender_lock->unlock();
1554 if(!preferences->use_brender && brender)
1556 brender_lock->lock("MWindow::init_brender 2");
1559 session->brender_end = 0;
1560 brender_lock->unlock();
1566 void MWindow::restart_brender()
1568 //printf("MWindow::restart_brender 1\n");
1569 if( !brender_active || !preferences->use_brender ) return;
1570 if( !brender ) return;
1571 brender->restart(edl);
1574 void MWindow::stop_brender()
1576 if( !brender ) return;
1577 // cannot be holding mwindow->gui display lock
1581 int MWindow::brender_available(int position)
1584 brender_lock->lock("MWindow::brender_available 1");
1585 if(brender && brender_active)
1587 if(brender->map_valid)
1589 brender->map_lock->lock("MWindow::brender_available 2");
1590 if(position < brender->map_size &&
1593 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1594 if(brender->map[position] == BRender::RENDERED)
1597 brender->map_lock->unlock();
1600 brender_lock->unlock();
1604 void MWindow::set_brender_active(int v, int update)
1606 if( !preferences->use_brender ) v = 0;
1608 gui->mainmenu->brender_active->set_checked(v);
1610 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1611 edl->session->brender_end = edl->local_session->get_selectionend(1);
1613 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1614 edl->session->brender_end = edl->tracks->total_video_length();
1619 edl->session->brender_start = edl->session->brender_end = 0;
1620 gui->unlock_window();
1622 gui->lock_window("MWindow::set_brender_active");
1625 gui->update_timebar(0);
1626 gui->draw_overlays(1);
1630 int MWindow::has_commercials()
1632 return theme->use_commercials;
1635 void MWindow::init_commercials()
1637 if( !commercials ) {
1638 commercials = new Commercials(this);
1639 commercial_active = 0;
1642 commercials->add_user();
1645 void MWindow::commit_commercial()
1647 if( !commercial_active ) return;
1648 commercial_active = 0;
1649 if( !commercials ) return;
1650 commercials->commitDb();
1653 void MWindow::undo_commercial()
1655 if( !commercial_active ) return;
1656 commercial_active = 0;
1657 if( !commercials ) return;
1658 commercials->undoDb();
1661 int MWindow::put_commercial()
1663 double start = edl->local_session->get_selectionstart();
1664 double end = edl->local_session->get_selectionend();
1665 if( start >= end ) return 0;
1667 const char *errmsg = 0;
1669 Tracks *tracks = edl->tracks;
1672 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1673 if( track->data_type != TRACK_VIDEO ) continue;
1674 if( !track->record ) continue;
1675 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1677 int64_t units_start = track->to_units(start,0);
1678 int64_t units_end = track->to_units(end,0);
1679 Edits *edits = track->edits;
1680 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1681 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1682 if(!edit1 && !edit2) continue; // nothing selected
1683 if(!edit2) { // edit2 beyond end of track
1684 edit2 = edits->last;
1685 units_end = edits->length();
1687 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1688 Indexable *indexable = edit1->get_source();
1689 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1692 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1693 if( track->data_type != TRACK_VIDEO ) continue;
1694 if( !track->record ) continue;
1695 int64_t units_start = track->to_units(start,0);
1696 int64_t units_end = track->to_units(end,0);
1697 Edits *edits = track->edits;
1698 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1699 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1700 if(!edit1 && !edit2) continue; // nothing selected
1701 if(!edit2) { // edit2 beyond end of track
1702 edit2 = edits->last;
1703 units_end = edits->length();
1705 Indexable *indexable = edit1->get_source();
1706 Asset *asset = (Asset *)indexable;
1707 File *file = video_cache->check_out(asset, edl);
1708 if( !file ) { errmsg = _("no file"); break; }
1709 int64_t edit_length = units_end - units_start;
1710 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1711 result = commercials->put_clip(file, edit1->channel,
1712 track->from_units(edit_start), track->from_units(edit_length));
1713 video_cache->check_in(asset);
1714 if( result ) { errmsg = _("db failed"); break; }
1717 char string[BCTEXTLEN];
1718 sprintf(string, _("put_commercial: %s"), errmsg);
1719 MainError::show_error(string);
1726 void MWindow::stop_playback(int wait)
1728 gui->stop_drawing();
1730 cwindow->stop_playback(wait);
1732 for(int i = 0; i < vwindows.size(); i++) {
1733 VWindow *vwindow = vwindows[i];
1734 if( !vwindow->is_running() ) continue;
1735 vwindow->stop_playback(wait);
1737 for(int i = 0; i < zwindows.size(); i++) {
1738 ZWindow *zwindow = zwindows[i];
1739 if( zwindow->idx < 0 ) continue;
1740 zwindow->stop_playback(wait);
1744 void MWindow::stop_transport()
1746 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1749 int MWindow::load_filenames(ArrayList<char*> *filenames,
1751 int update_filename)
1753 ArrayList<EDL*> new_edls;
1754 ArrayList<Asset*> new_assets;
1755 ArrayList<File*> new_files;
1756 const int debug = 0;
1757 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1760 gui->start_hourglass();
1762 // Need to stop playback since tracking depends on the EDL not getting
1764 gui->unlock_window();
1766 gui->lock_window("MWindow::load_filenames 0");
1768 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1769 undo->update_undo_before();
1772 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1774 // Define new_edls and new_assets to load
1775 int result = 0, ftype = -1;
1777 for( int i=0; i<filenames->size(); ++i ) {
1779 File *new_file = new File;
1780 Asset *new_asset = new Asset(filenames->get(i));
1781 EDL *new_edl = new EDL;
1782 char string[BCTEXTLEN];
1784 new_edl->create_objects();
1785 new_edl->copy_session(edl);
1786 new_file->set_program(edl->session->program_no);
1788 sprintf(string, _("Loading %s"), new_asset->path);
1789 gui->show_message(string);
1790 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1792 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1793 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1797 // Convert media file to EDL
1799 // Warn about odd image dimensions
1800 if( new_asset->video_data &&
1801 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1802 char string[BCTEXTLEN];
1803 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1804 new_asset->path, new_asset->width, new_asset->height);
1805 MainError::show_error(string);
1808 if( new_asset->program >= 0 &&
1809 edl->session->program_no != new_asset->program ) {
1810 char string[BCTEXTLEN];
1811 sprintf(string, _("%s's index was built for program number %d\n"
1812 "Playback preference is %d.\n Using program %d."),
1813 new_asset->path, new_asset->program,
1814 edl->session->program_no, new_asset->program);
1815 MainError::show_error(string);
1818 if( load_mode != LOADMODE_RESOURCESONLY ) {
1819 RecordLabels *labels = edl->session->label_cells ?
1820 new RecordLabels(new_file) : 0;
1821 asset_to_edl(new_edl, new_asset, labels);
1822 new_edls.append(new_edl);
1823 new_edl->add_user();
1827 new_assets.append(new_asset);
1828 new_asset->add_user();
1831 // Set filename to nothing for assets since save EDL would overwrite them.
1832 if( load_mode == LOADMODE_REPLACE ||
1833 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1835 // Reset timeline position
1836 for( int i=0; i<TOTAL_PANES; ++i ) {
1837 new_edl->local_session->view_start[i] = 0;
1838 new_edl->local_session->track_start[i] = 0;
1846 case FILE_NOT_FOUND:
1847 sprintf(string, _("Failed to open %s"), new_asset->path);
1848 gui->show_message(string, theme->message_error);
1849 gui->update_default_message();
1853 case FILE_UNRECOGNIZED_CODEC: {
1855 { IndexFile indexfile(this, new_asset);
1856 if( !(result = indexfile.open_index()) )
1857 indexfile.close_index(); }
1859 // Test existing EDLs
1860 for( int j=0; result && j<new_edls.total; ++j ) {
1861 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1863 new_asset->copy_from(old_asset,1);
1868 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1870 new_asset->copy_from(old_asset,1);
1877 char string[BCTEXTLEN];
1879 fs.extract_name(string, new_asset->path);
1881 strcat(string, _("'s format couldn't be determined."));
1882 new_asset->audio_data = 1;
1883 new_asset->format = FILE_PCM;
1884 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1885 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1886 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1887 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1888 new_asset->signed_ = defaults->get("SIGNED_", 1);
1889 new_asset->header = defaults->get("HEADER", 0);
1891 FileFormat fwindow(this);
1892 fwindow.create_objects(new_asset, string);
1893 result = fwindow.run_window();
1895 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1896 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1897 defaults->update("AUDIO_BITS", new_asset->bits);
1898 defaults->update("BYTE_ORDER", new_asset->byte_order);
1899 defaults->update("SIGNED_", new_asset->signed_);
1900 defaults->update("HEADER", new_asset->header);
1906 // Recalculate length
1908 new_file = new File;
1909 result = new_file->open_file(preferences, new_asset, 1, 0);
1911 if( load_mode != LOADMODE_RESOURCESONLY ) {
1912 RecordLabels *labels = edl->session->label_cells ?
1913 new RecordLabels(new_file) : 0;
1914 asset_to_edl(new_edl, new_asset, labels);
1915 new_edls.append(new_edl);
1916 new_edl->add_user();
1920 new_assets.append(new_asset);
1921 new_asset->add_user();
1931 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1932 xml_file.read_from_file(filenames->get(i));
1933 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1934 const char *cin_version = 0;
1935 while( !xml_file.read_tag() ) {
1936 if( xml_file.tag.title_is("EDL") ) {
1937 cin_version = xml_file.tag.get_property("VERSION");
1942 if( !cin_version ) {
1943 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1944 char string[BCTEXTLEN];
1945 sprintf(string,_("Unknown %s"), filenames->get(i));
1946 gui->show_message(string);
1950 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1951 char string[BCTEXTLEN];
1952 snprintf(string, sizeof(string),
1953 _("Warning: XML from cinelerra version %s\n"
1954 "Session data may be incompatible."), cin_version);
1955 show_warning(&preferences->warn_version, string);
1957 if( load_mode == LOADMODE_NESTED ) {
1958 // Load temporary EDL for nesting.
1959 EDL *nested_edl = new EDL;
1960 nested_edl->create_objects();
1961 nested_edl->load_xml(&xml_file, LOAD_ALL);
1962 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1963 new_edl->create_nested(nested_edl);
1964 new_edl->set_path(filenames->get(i));
1965 nested_edl->Garbage::remove_user();
1968 // Load EDL for pasting
1969 new_edl->load_xml(&xml_file, LOAD_ALL);
1970 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1971 test_plugins(new_edl, filenames->get(i));
1972 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1974 if( load_mode == LOADMODE_REPLACE ||
1975 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1976 strcpy(session->filename, filenames->get(i));
1977 strcpy(new_edl->local_session->clip_title,
1980 set_filename(new_edl->local_session->clip_title);
1982 else if( load_mode == LOADMODE_RESOURCESONLY ) {
1983 strcpy(new_edl->local_session->clip_title,
1986 time_t t = !stat(filenames->get(i),&st) ?
1987 st.st_mtime : time(&t);
1988 ctime_r(&t, new_edl->local_session->clip_notes);
1992 new_edls.append(new_edl);
1993 new_edl->add_user();
1998 new_edl->Garbage::remove_user();
1999 new_asset->Garbage::remove_user();
2001 // Store for testing index
2002 new_files.append(new_file);
2005 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2009 gui->reset_default_message();
2010 gui->default_message();
2014 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2017 // Don't back up here.
2020 // For pasting, clear the active region
2021 if(load_mode == LOADMODE_PASTE ||
2022 load_mode == LOADMODE_NESTED)
2024 double start = edl->local_session->get_selectionstart();
2025 double end = edl->local_session->get_selectionend();
2026 if(!EQUIV(start, end))
2029 edl->session->labels_follow_edits,
2030 edl->session->plugins_follow_edits,
2031 edl->session->autos_follow_edits);
2034 paste_edls(&new_edls, load_mode, 0, -1,
2035 edl->session->labels_follow_edits,
2036 edl->session->plugins_follow_edits,
2037 edl->session->autos_follow_edits,
2044 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2046 // Add new assets to EDL and schedule assets for index building.
2047 int got_indexes = 0;
2048 for( int i=0; i<new_edls.size(); ++i ) {
2049 EDL *new_edl = new_edls[i];
2050 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2051 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2052 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2058 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2059 for( int i=0; i<new_assets.size(); ++i ) {
2060 Asset *new_asset = new_assets[i];
2064 for( int j=0; j<new_files.size(); ++j ) {
2065 new_file = new_files[j];
2066 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2072 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2073 edl->assets->update(new_asset);
2076 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2078 // Start examining next batch of index files
2079 if(got_indexes) mainindexes->start_build();
2080 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2083 Track *track = edl->tracks->first;
2086 for(int j = 0; j < track->plugin_set.size(); j++)
2088 PluginSet *plugins = track->plugin_set[j];
2089 Plugin *plugin = plugins->get_first_plugin();
2093 if(load_mode == LOADMODE_REPLACE ||
2094 load_mode == LOADMODE_REPLACE_CONCATENATE)
2096 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2099 show_plugin(plugin);
2103 plugin = (Plugin*)plugin->next;
2107 track = track->next;
2110 // if just opening one new resource in replace mode
2111 if( ftype != FILE_IS_XML &&
2112 ( load_mode == LOADMODE_REPLACE ||
2113 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2115 edl->session->proxy_scale = 1;
2116 edl->session->proxy_use_scaler = 0;
2117 edl->session->proxy_auto_scale = 0;
2118 edl->local_session->preview_start = 0;
2119 edl->local_session->preview_end = 0;
2120 edl->local_session->loop_playback = 0;
2121 edl->local_session->set_selectionstart(0);
2122 edl->local_session->set_selectionend(0);
2123 set_brender_active(0, 0);
2128 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2129 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2130 ArrayList<Indexable *> orig_idxbls;
2131 for( int i=0; i<new_assets.size(); ++i )
2132 orig_idxbls.append(new_assets.get(i));
2133 for( int i=0; i<new_edls.size(); ++i ) {
2134 EDL *new_edl = new_edls[i];
2135 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2136 if( track->data_type != TRACK_VIDEO ) continue;
2137 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2138 Indexable *idxbl = (Indexable *)edit->asset;
2139 if( !idxbl ) continue;
2140 if( !idxbl->have_video() ) continue;
2141 if( edit->channel != 0 ) continue; // first layer only
2142 orig_idxbls.append(edit->asset);
2146 gui->unlock_window(); // to update progress bar
2147 render_proxy(orig_idxbls);
2148 gui->lock_window("MWindow::load_filenames");
2151 // need to update undo before project, since mwindow is unlocked & a new load
2152 // can begin here. Should really prevent loading until we're done.
2153 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2154 undo->update_undo_after(_("load"), LOAD_ALL);
2156 for(int i = 0; i < new_edls.size(); i++)
2158 new_edls[i]->remove_user();
2160 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2162 new_edls.remove_all();
2164 for(int i = 0; i < new_assets.size(); i++)
2166 new_assets[i]->Garbage::remove_user();
2169 new_assets.remove_all();
2170 new_files.remove_all_objects();
2173 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2174 if(load_mode == LOADMODE_REPLACE ||
2175 load_mode == LOADMODE_REPLACE_CONCATENATE)
2177 session->changes_made = 0;
2181 session->changes_made = 1;
2184 gui->stop_hourglass();
2187 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2188 update_project(load_mode);
2190 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2195 void MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2197 Asset *format_asset = new Asset;
2198 format_asset->format = FILE_FFMPEG;
2199 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2200 ProxyRender proxy_render(this, format_asset);
2201 int new_scale = edl->session->proxy_scale;
2202 int use_scaler = edl->session->proxy_use_scaler;
2204 for( int i=0; i<new_idxbls.size(); ++i ) {
2205 Indexable *orig = new_idxbls.get(i);
2206 Asset *proxy = proxy_render.add_original(orig, new_scale);
2207 if( !proxy ) continue;
2209 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2210 int got_it = exists && // if proxy exists, and is newer than orig
2211 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2212 if( got_it ) continue;
2213 proxy_render.add_needed(orig, proxy);
2216 // render needed proxies
2217 int result = proxy_render.create_needed_proxies(new_scale);
2219 add_proxy(use_scaler,
2220 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2222 format_asset->remove_user();
2225 void MWindow::test_plugins(EDL *new_edl, char *path)
2227 char string[BCTEXTLEN];
2229 // Do a check whether plugins exist
2230 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2231 for( int k=0; k<track->plugin_set.total; ++k ) {
2232 PluginSet *plugin_set = track->plugin_set[k];
2233 for( Plugin *plugin = (Plugin*)plugin_set->first;
2234 plugin; plugin = (Plugin*)plugin->next ) {
2235 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2236 // ok we need to find it in plugindb
2237 PluginServer *server =
2238 scan_plugindb(plugin->title, track->data_type);
2239 if( !server || server->transition ) {
2241 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2242 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2243 "effect", _(plugin->title), path);
2244 MainError::show_error(string);
2249 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2250 if( !edit->transition ) continue;
2251 // ok we need to find transition in plugindb
2252 PluginServer *server =
2253 scan_plugindb(edit->transition->title, track->data_type);
2254 if( !server || !server->transition ) {
2256 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2257 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2258 "transition", _(edit->transition->title), path);
2259 MainError::show_error(string);
2266 void MWindow::init_shm(const char *pfn, int64_t min)
2269 // Fix shared memory
2270 FILE *fd = fopen(pfn, "r");
2272 fscanf(fd, "%jd", &result);
2274 if( result >= min ) return;
2277 fd = fopen(pfn, "w");
2279 fprintf(fd, "0x%jx", min);
2283 fd = fopen(pfn, "r");
2285 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2289 fscanf(fd, "%jd", &result);
2291 if( result < min ) {
2292 eprintf(_("MWindow::init_shm: %s is %p.\n"
2293 "you probably need to be root, or:\n"
2294 "as root, run: echo 0x%jx > %s\n"
2295 "before trying to start cinelerra.\n"
2296 "It should be at least 0x%jx for Cinelerra.\n"),
2297 pfn, (void *)result, min, pfn, min);
2301 void MWindow::create_objects(int want_gui,
2305 const int debug = 0;
2306 if(debug) PRINT_TRACE
2308 // For some reason, init_signals must come after show_splash or the signals won't
2311 if(debug) PRINT_TRACE
2314 if(debug) PRINT_TRACE
2317 if(debug) PRINT_TRACE
2318 default_standard = default_std();
2319 init_defaults(defaults, config_path);
2323 splash_window->operation->update(_("Initializing Plugins"));
2324 init_plugins(this, preferences);
2325 if(debug) PRINT_TRACE
2326 init_ladspa_plugins(this, preferences);
2327 if(debug) PRINT_TRACE
2328 init_plugin_tips(*plugindb, cin_lang);
2330 splash_window->operation->update(_("Initializing GUI"));
2331 if(debug) PRINT_TRACE
2334 if(debug) PRINT_TRACE
2338 splash_window->operation->update(_("Initializing Fonts"));
2339 char string[BCTEXTLEN];
2340 strcpy(string, preferences->plugin_dir);
2341 strcat(string, "/" FONT_SEARCHPATH);
2342 BC_Resources::init_fontconfig(string);
2343 if(debug) PRINT_TRACE
2345 // Initialize before too much else is running
2346 // Preferences & theme are required for building MPEG table of contents
2348 // Default project created here
2350 if(debug) PRINT_TRACE
2353 if(debug) PRINT_TRACE
2358 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2361 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2363 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2364 if(session->show_vwindow)
2365 get_viewer(1, DEFAULT_VWINDOW);
2366 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2369 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2372 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2375 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2378 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2381 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());
2389 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2390 mainprogress = new MainProgress(this, gui);
2391 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2392 undo = new MainUndo(this);
2394 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2396 plugin_guis = new ArrayList<PluginServer*>;
2397 dead_plugins = new ArrayList<PluginServer*>;
2398 keyframe_threads = new ArrayList<KeyFrameThread*>;
2400 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2403 session->show_vwindow);
2405 // Show all vwindows
2406 // if(session->show_vwindow) {
2407 // for(int j = 0; j < vwindows.size(); j++) {
2408 // VWindow *vwindow = vwindows[j];
2409 // if( !vwindow->is_running() ) continue;
2410 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2413 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2414 // vwindow->gui->lock_window("MWindow::create_objects 1");
2415 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2416 // vwindow->gui->show_window();
2417 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2418 // vwindow->gui->unlock_window();
2423 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2425 if(session->show_cwindow)
2427 cwindow->gui->lock_window("MWindow::create_objects 1");
2428 cwindow->gui->show_window();
2429 cwindow->gui->unlock_window();
2432 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2433 if(session->show_awindow)
2435 awindow->gui->lock_window("MWindow::create_objects 1");
2436 awindow->gui->show_window();
2437 awindow->gui->unlock_window();
2440 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2441 if(session->show_lwindow)
2443 lwindow->gui->lock_window("MWindow::create_objects 1");
2444 lwindow->gui->show_window();
2445 lwindow->gui->unlock_window();
2448 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2450 (int)timer.get_difference(),
2452 if(session->show_gwindow)
2454 gwindow->gui->lock_window("MWindow::create_objects 1");
2455 gwindow->gui->show_window();
2456 gwindow->gui->unlock_window();
2459 if(debug) PRINT_TRACE
2461 gui->lock_window("MWindow::create_objects 1");
2462 gui->mainmenu->load_defaults(defaults);
2463 gui->mainmenu->update_toggles(0);
2464 gui->update_patchbay();
2465 gui->draw_canvas(0, 0);
2466 gui->draw_cursor(1);
2468 gui->raise_window();
2469 gui->unlock_window();
2471 if(debug) PRINT_TRACE
2473 if(preferences->use_tipwindow)
2475 if(debug) PRINT_TRACE
2477 gui->add_keyboard_listener(
2478 (int (BC_WindowBase::*)(BC_WindowBase *))
2479 &MWindowGUI::keyboard_listener);
2482 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2483 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2484 if(debug) PRINT_TRACE
2486 BC_WindowBase::get_resources()->vframe_shm = 1;
2490 void MWindow::show_splash()
2492 #include "data/heroine_logo9_png.h"
2493 VFrame *frame = new VFramePng(heroine_logo9_png);
2494 BC_DisplayInfo dpyi;
2495 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2496 int rr = (rw < rh ? rw : rh) / 4;
2497 splash_window = new SplashGUI(frame, rr, rr);
2498 splash_window->create_objects();
2501 void MWindow::hide_splash()
2504 delete splash_window;
2509 void MWindow::start()
2513 // vwindows[DEFAULT_VWINDOW]->start();
2524 playback_3d->start();
2530 run_lock->lock("MWindow::run");
2534 brender_lock->lock("MWindow::run 1");
2535 delete brender; brender = 0;
2536 brender_lock->unlock();
2538 interrupt_indexes();
2544 void MWindow::show_vwindow()
2546 int total_running = 0;
2547 session->show_vwindow = 1;
2549 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2550 // Raise all windows which are visible
2551 for(int j = 0; j < vwindows.size(); j++) {
2552 VWindow *vwindow = vwindows[j];
2553 if( !vwindow->is_running() ) continue;
2554 vwindow->gui->lock_window("MWindow::show_vwindow");
2555 vwindow->gui->show_window(0);
2556 vwindow->gui->raise_window();
2557 vwindow->gui->flush();
2558 vwindow->gui->unlock_window();
2562 // If no windows visible
2565 get_viewer(1, DEFAULT_VWINDOW);
2568 gui->mainmenu->show_vwindow->set_checked(1);
2571 void MWindow::show_awindow()
2573 session->show_awindow = 1;
2574 awindow->gui->lock_window("MWindow::show_awindow");
2575 awindow->gui->show_window();
2576 awindow->gui->raise_window();
2577 awindow->gui->flush();
2578 awindow->gui->unlock_window();
2579 gui->mainmenu->show_awindow->set_checked(1);
2582 char *MWindow::get_cwindow_display()
2584 char *x11_host = screens < 2 || session->window_config == 0 ?
2585 session->a_x11_host : session->b_x11_host;
2586 return *x11_host ? x11_host : 0;
2589 void MWindow::show_cwindow()
2591 session->show_cwindow = 1;
2592 cwindow->show_window();
2593 gui->mainmenu->show_cwindow->set_checked(1);
2596 void MWindow::show_gwindow()
2598 session->show_gwindow = 1;
2600 gwindow->gui->lock_window("MWindow::show_gwindow");
2601 gwindow->gui->show_window();
2602 gwindow->gui->raise_window();
2603 gwindow->gui->flush();
2604 gwindow->gui->unlock_window();
2606 gui->mainmenu->show_gwindow->set_checked(1);
2608 void MWindow::hide_gwindow()
2610 session->show_gwindow = 0;
2612 gwindow->gui->lock_window("MWindow::show_gwindow");
2613 gwindow->gui->hide_window();
2614 gwindow->gui->unlock_window();
2617 void MWindow::show_lwindow()
2619 session->show_lwindow = 1;
2620 lwindow->gui->lock_window("MWindow::show_lwindow");
2621 lwindow->gui->show_window();
2622 lwindow->gui->raise_window();
2623 lwindow->gui->flush();
2624 lwindow->gui->unlock_window();
2625 gui->mainmenu->show_lwindow->set_checked(1);
2628 int MWindow::tile_windows(int window_config)
2630 int need_reload = 0;
2631 int play_config = window_config==0 ? 0 : 1;
2632 edl->session->playback_config->load_defaults(defaults, play_config);
2633 session->default_window_positions(window_config);
2634 if( screens == 1 ) {
2635 gui->default_positions();
2636 sync_parameters(CHANGE_ALL);
2643 void MWindow::toggle_loop_playback()
2645 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2646 set_loop_boundaries();
2649 gui->draw_overlays(1);
2650 sync_parameters(CHANGE_PARAMS);
2653 //void MWindow::set_titles(int value)
2655 // edl->session->show_titles = value;
2656 // trackmovement(edl->local_session->track_start);
2659 void MWindow::set_screens(int value)
2664 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2666 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2667 edl->session->auto_keyframes = value;
2668 gui->mbuttons->edit_panel->keyframe->update(value);
2670 if(lock_mwindow) gui->unlock_window();
2672 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2673 cwindow->gui->edit_panel->keyframe->update(value);
2674 cwindow->gui->flush();
2675 if(lock_cwindow) cwindow->gui->unlock_window();
2678 void MWindow::set_auto_visibility(Autos *autos, int value)
2680 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2681 edl->session->auto_conf->plugins = value;
2682 else if( autos->autoidx >= 0 )
2683 edl->session->auto_conf->autos[autos->autoidx] = value;
2687 gui->update(0, 1, 0, 0, 0, 0, 0);
2688 gui->mainmenu->update_toggles(1);
2689 gui->unlock_window();
2690 gwindow->gui->update_toggles(1);
2691 gui->lock_window("MWindow::set_auto_visibility");
2694 void MWindow::set_keyframe_type(int mode)
2696 gui->lock_window("MWindow::set_keyframe_type");
2697 edl->local_session->floatauto_type = mode;
2698 gui->mainmenu->update_toggles(0);
2699 gui->unlock_window();
2702 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2704 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2705 edl->session->editing_mode = new_editing_mode;
2706 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2707 gui->mbuttons->edit_panel->update();
2708 gui->set_editing_mode(1);
2709 if(lock_mwindow) gui->unlock_window();
2712 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2713 cwindow->gui->edit_panel->update();
2714 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2715 if(lock_cwindow) cwindow->gui->unlock_window();
2719 void MWindow::toggle_editing_mode()
2721 int mode = edl->session->editing_mode;
2722 if( mode == EDITING_ARROW )
2723 set_editing_mode(EDITING_IBEAM, 0, 1);
2725 set_editing_mode(EDITING_ARROW, 0, 1);
2729 void MWindow::set_labels_follow_edits(int value)
2731 gui->lock_window("MWindow::set_labels_follow_edits");
2732 edl->session->labels_follow_edits = value;
2733 gui->mbuttons->edit_panel->locklabels->update(value);
2734 gui->mainmenu->labels_follow_edits->set_checked(value);
2736 gui->unlock_window();
2739 void MWindow::sync_parameters(int change_type)
2741 if( in_destructor ) return;
2743 // Sync engines which are playing back
2744 if(cwindow->playback_engine->is_playing_back)
2746 if(change_type == CHANGE_PARAMS)
2748 // TODO: block keyframes until synchronization is done
2749 cwindow->playback_engine->sync_parameters(edl);
2754 int command = cwindow->playback_engine->command->command;
2755 cwindow->playback_engine->que->send_command(STOP,
2759 // Waiting for tracking to finish would make the restart position more
2760 // accurate but it can't lock the window to stop tracking for some reason.
2761 // Not waiting for tracking gives a faster response but restart position is
2762 // only as accurate as the last tracking update.
2763 cwindow->playback_engine->interrupt_playback(0);
2764 cwindow->playback_engine->que->send_command(command,
2773 cwindow->refresh_frame(change_type);
2777 void MWindow::age_caches()
2779 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2781 // preferences->cache_size,
2782 // audio_cache->get_memory_usage(1),
2783 // video_cache->get_memory_usage(1),
2784 // frame_cache->get_memory_usage(),
2785 // wave_cache->get_memory_usage(),
2787 frame_cache->age_cache(512);
2788 wave_cache->age_cache(8192);
2790 int64_t memory_usage;
2791 int64_t prev_memory_usage = 0;
2793 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2794 while( !result && prev_memory_usage !=
2795 (memory_usage=video_cache->get_memory_usage(1)) &&
2796 memory_usage > video_size ) {
2797 video_cache->delete_oldest();
2798 prev_memory_usage = memory_usage;
2801 prev_memory_usage = 0;
2803 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2804 while( !result && prev_memory_usage !=
2805 (memory_usage=audio_cache->get_memory_usage(1)) &&
2806 memory_usage > audio_size ) {
2807 audio_cache->delete_oldest();
2808 prev_memory_usage = memory_usage;
2812 void MWindow::reset_android_remote()
2814 gui->use_android_remote(preferences->android_remote);
2818 void MWindow::show_keyframe_gui(Plugin *plugin)
2820 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2821 // Find existing thread
2822 for(int i = 0; i < keyframe_threads->size(); i++)
2824 if(keyframe_threads->get(i)->plugin == plugin)
2826 keyframe_threads->get(i)->start_window(plugin, 0);
2827 keyframe_gui_lock->unlock();
2832 // Find unused thread
2833 for(int i = 0; i < keyframe_threads->size(); i++)
2835 if(!keyframe_threads->get(i)->plugin)
2837 keyframe_threads->get(i)->start_window(plugin, 0);
2838 keyframe_gui_lock->unlock();
2843 // Create new thread
2844 KeyFrameThread *thread = new KeyFrameThread(this);
2845 keyframe_threads->append(thread);
2846 thread->start_window(plugin, 0);
2848 keyframe_gui_lock->unlock();
2855 void MWindow::show_plugin(Plugin *plugin)
2860 // Remove previously deleted plugin GUIs
2861 dead_plugin_lock->lock("MWindow::show_plugin");
2862 dead_plugins->remove_all_objects();
2863 dead_plugin_lock->unlock();
2865 //printf("MWindow::show_plugin %d\n", __LINE__);
2869 plugin_gui_lock->lock("MWindow::show_plugin");
2870 for(int i = 0; i < plugin_guis->total; i++)
2872 // Pointer comparison
2873 if(plugin_guis->get(i)->plugin == plugin)
2875 plugin_guis->get(i)->raise_window();
2882 //printf("MWindow::show_plugin 1\n");
2883 if( !done && !plugin->track ) {
2884 printf("MWindow::show_plugin track not defined.\n");
2888 PluginServer *server = scan_plugindb(plugin->title,
2889 plugin->track->data_type);
2891 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2892 if(server && server->uses_gui)
2894 PluginServer *gui = new PluginServer(*server);
2895 plugin_guis->append(gui);
2896 // Needs mwindow to do GUI
2897 gui->set_mwindow(this);
2898 gui->open_plugin(0, preferences, edl, plugin);
2903 plugin_gui_lock->unlock();
2904 //printf("MWindow::show_plugin %d\n", __LINE__);
2907 //printf("MWindow::show_plugin 2\n");
2910 void MWindow::hide_plugin(Plugin *plugin, int lock)
2913 // Update the toggle
2914 gui->lock_window("MWindow::hide_plugin");
2915 gui->update(0, 1, 0, 0, 0, 0, 0);
2916 gui->unlock_window();
2918 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2919 for(int i = 0; i < plugin_guis->total; i++)
2921 if(plugin_guis->get(i)->plugin == plugin)
2923 PluginServer *ptr = plugin_guis->get(i);
2924 plugin_guis->remove(ptr);
2925 if(lock) plugin_gui_lock->unlock();
2926 // Last command executed in client side close
2927 // Schedule for deletion
2934 if(lock) plugin_gui_lock->unlock();
2937 void MWindow::delete_plugin(PluginServer *plugin)
2939 dead_plugin_lock->lock("MWindow::delete_plugin");
2940 dead_plugins->append(plugin);
2941 dead_plugin_lock->unlock();
2944 void MWindow::hide_plugins()
2946 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2947 while(plugin_guis->size())
2949 PluginServer *ptr = plugin_guis->get(0);
2950 plugin_guis->remove(ptr);
2951 plugin_gui_lock->unlock();
2952 // Last command executed in client side close
2953 // Schedule for deletion
2956 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2958 plugin_gui_lock->unlock();
2960 hide_keyframe_guis();
2963 void MWindow::hide_keyframe_guis()
2965 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2966 for(int i = 0; i < keyframe_threads->size(); i++)
2968 keyframe_threads->get(i)->close_window();
2970 keyframe_gui_lock->unlock();
2973 void MWindow::hide_keyframe_gui(Plugin *plugin)
2975 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2976 for(int i = 0; i < keyframe_threads->size(); i++)
2978 if(keyframe_threads->get(i)->plugin == plugin)
2980 keyframe_threads->get(i)->close_window();
2984 keyframe_gui_lock->unlock();
2987 void MWindow::update_keyframe_guis()
2989 // Send new configuration to keyframe GUI's
2990 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2991 for(int i = 0; i < keyframe_threads->size(); i++)
2993 KeyFrameThread *ptr = keyframe_threads->get(i);
2994 if(edl->tracks->plugin_exists(ptr->plugin))
2998 ptr->close_window();
3001 keyframe_gui_lock->unlock();
3004 void MWindow::update_plugin_guis(int do_keyframe_guis)
3006 // Send new configuration to plugin GUI's
3007 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3009 for(int i = 0; i < plugin_guis->size(); i++)
3011 PluginServer *ptr = plugin_guis->get(i);
3012 if(edl->tracks->plugin_exists(ptr->plugin))
3016 // Schedule for deletion if no plugin
3017 plugin_guis->remove_number(i);
3026 // Change plugin variable if not visible
3027 Track *track = edl->tracks->first;
3030 for(int i = 0; i < track->plugin_set.size(); i++)
3032 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3036 for(int i = 0; i < plugin_guis->size(); i++)
3038 PluginServer *server = plugin_guis->get(i);
3039 if(server->plugin == plugin)
3046 if(!got_it) plugin->show = 0;
3048 plugin = (Plugin*)plugin->next;
3052 track = track->next;
3055 plugin_gui_lock->unlock();
3058 if(do_keyframe_guis) update_keyframe_guis();
3061 int MWindow::plugin_gui_open(Plugin *plugin)
3064 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3065 for(int i = 0; i < plugin_guis->total; i++)
3067 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3073 plugin_gui_lock->unlock();
3077 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3079 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3080 for(int i = 0; i < plugin_guis->total; i++)
3082 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3084 plugin_guis->get(i)->render_gui(data);
3088 plugin_gui_lock->unlock();
3091 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3093 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3094 for(int i = 0; i < plugin_guis->total; i++)
3096 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3098 plugin_guis->get(i)->render_gui(data, size);
3102 plugin_gui_lock->unlock();
3106 void MWindow::update_plugin_states()
3108 plugin_gui_lock->lock("MWindow::update_plugin_states");
3109 for(int i = 0; i < plugin_guis->total; i++)
3113 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3114 PluginServer *src_plugingui = plugin_guis->get(i);
3116 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3117 for(Track *track = edl->tracks->first;
3119 track = track->next)
3122 j < track->plugin_set.total && !result;
3125 PluginSet *plugin_set = track->plugin_set[j];
3126 for(Plugin *plugin = (Plugin*)plugin_set->first;
3128 plugin = (Plugin*)plugin->next)
3130 if(plugin == src_plugin &&
3131 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3137 // Doesn't exist anymore
3140 hide_plugin(src_plugin, 0);
3144 plugin_gui_lock->unlock();
3148 void MWindow::update_plugin_titles()
3150 for(int i = 0; i < plugin_guis->total; i++)
3152 plugin_guis->get(i)->update_title();
3156 int MWindow::asset_to_edl(EDL *new_edl,
3158 RecordLabels *labels)
3160 const int debug = 0;
3161 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3164 // Keep frame rate, sample rate, and output size unchanged.
3165 // These parameters would revert the project if VWindow displayed an asset
3166 // of different size than the project.
3167 if(new_asset->video_data)
3169 new_edl->session->video_tracks = new_asset->layers;
3172 new_edl->session->video_tracks = 0;
3174 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3180 if(new_asset->audio_data)
3182 new_edl->session->audio_tracks = new_asset->channels;
3185 new_edl->session->audio_tracks = 0;
3186 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3188 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3189 new_edl->create_default_tracks();
3190 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3191 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3195 //printf("MWindow::asset_to_edl 3\n");
3196 new_edl->insert_asset(new_asset,
3201 //printf("MWindow::asset_to_edl 3\n");
3202 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3204 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3205 if(edl->session->cursor_on_frames)
3207 double length = new_edl->tracks->total_length();
3208 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3209 new_edl->tracks->clear(length, edl_length, 1, 1);
3215 char string[BCTEXTLEN];
3217 fs.extract_name(string, new_asset->path);
3218 //printf("MWindow::asset_to_edl 3\n");
3220 strcpy(new_edl->local_session->clip_title, string);
3221 //printf("MWindow::asset_to_edl 4 %s\n", string);
3222 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3228 // Reset everything after a load.
3229 void MWindow::update_project(int load_mode)
3231 const int debug = 0;
3233 if(debug) PRINT_TRACE
3234 edl->tracks->update_y_pixels(theme);
3236 if(debug) PRINT_TRACE
3238 if(load_mode == LOADMODE_REPLACE ||
3239 load_mode == LOADMODE_REPLACE_CONCATENATE)
3244 gui->update(1, 1, 1, 1, 1, 1, 1);
3245 if(debug) PRINT_TRACE
3246 gui->unlock_window();
3249 cwindow->gui->lock_window("MWindow::update_project 1");
3250 cwindow->update(0, 0, 1, 1, 1);
3251 cwindow->gui->unlock_window();
3253 if(debug) PRINT_TRACE
3255 // Close all the vwindows
3256 if( load_mode == LOADMODE_REPLACE ||
3257 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3258 if(debug) PRINT_TRACE
3259 int first_vwindow = 0;
3260 if(session->show_vwindow) first_vwindow = 1;
3261 // Change visible windows to no source
3262 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3263 VWindow *vwindow = vwindows[i];
3264 if( !vwindow->is_running() ) continue;
3265 vwindow->change_source(-1);
3268 // Close remaining windows
3269 for(int i = first_vwindow; i < vwindows.size(); i++) {
3270 VWindow *vwindow = vwindows[i];
3271 if( !vwindow->is_running() ) continue;
3272 vwindow->close_window();
3274 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3275 VWindow *vwindow = get_viewer(1, -1);
3276 vwindow->change_source(i);
3278 if(debug) PRINT_TRACE
3282 for( int i=0; i<edl->mixers.size(); ++i ) {
3283 Mixer *mixer = edl->mixers[i];
3284 ZWindow *zwindow = get_mixer(mixer);
3285 zwindow->set_title(mixer->title);
3290 if(vwindows.size()) {
3291 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3292 if( vwindow->is_running() ) {
3293 vwindow->gui->lock_window("MWindow::update_project");
3295 vwindow->gui->unlock_window();
3300 if(debug) PRINT_TRACE
3301 cwindow->gui->lock_window("MWindow::update_project 2");
3302 cwindow->gui->timebar->update(0);
3303 cwindow->gui->unlock_window();
3305 if(debug) PRINT_TRACE
3306 cwindow->refresh_frame(CHANGE_ALL);
3308 awindow->gui->async_update_assets();
3309 if(debug) PRINT_TRACE
3311 gui->lock_window("MWindow::update_project");
3312 gui->update_mixers(0, 0);
3314 if(debug) PRINT_TRACE
3317 void MWindow::remove_indexfile(Indexable *indexable)
3319 if( !indexable->is_asset ) return;
3320 Asset *asset = (Asset *)indexable;
3322 IndexFile::delete_index(preferences, asset, ".toc");
3323 IndexFile::delete_index(preferences, asset, ".idx");
3324 IndexFile::delete_index(preferences, asset, ".mkr");
3327 void MWindow::rebuild_indices()
3329 for(int i = 0; i < session->drag_assets->total; i++)
3331 Indexable *indexable = session->drag_assets->get(i);
3332 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3333 remove_indexfile(indexable);
3334 // Schedule index build
3335 IndexState *index_state = indexable->index_state;
3336 index_state->index_status = INDEX_NOTTESTED;
3337 if( indexable->is_asset ) {
3338 Asset *asset = (Asset *)indexable;
3339 if( asset->format != FILE_PCM ) {
3340 asset->format = FILE_UNKNOWN;
3341 asset->reset_audio();
3343 asset->reset_video();
3344 remove_asset_from_caches(asset);
3345 // File file; // re-probe the asset
3346 // file.open_file(preferences, asset, 1, 0);
3348 mainindexes->add_next_asset(0, indexable);
3350 mainindexes->start_build();
3354 void MWindow::save_backup()
3358 edl->set_path(session->filename);
3359 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3360 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3361 File::get_config_path(), BACKUP_FILE);
3362 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3363 File::get_config_path(), BACKUP_FILE1);
3364 rename(backup_path, backup_path1);
3365 edl->save_xml(&file, backup_path);
3366 file.terminate_string();
3368 fs.complete_path(backup_path);
3370 if(file.write_to_file(backup_path))
3373 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3374 gui->show_message(string2);
3378 void MWindow::load_backup()
3380 ArrayList<char*> path_list;
3381 path_list.set_array_delete();
3383 char backup_path[BCTEXTLEN];
3384 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3385 File::get_config_path(), BACKUP_FILE);
3387 fs.complete_path(backup_path);
3389 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3390 strcpy(out_path, backup_path);
3392 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3393 edl->local_session->clip_title[0] = 0;
3394 // This is unique to backups since the path of the backup is different than the
3395 // path of the project.
3396 set_filename(edl->path);
3397 path_list.remove_all_objects();
3402 void MWindow::save_undo_data()
3404 char perpetual_path[BCTEXTLEN];
3405 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3406 File::get_config_path(), PERPETUAL_FILE);
3407 FILE *fp = fopen(perpetual_path,"w");
3413 void MWindow::load_undo_data()
3415 char perpetual_path[BCTEXTLEN];
3416 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3417 File::get_config_path(), PERPETUAL_FILE);
3418 FILE *fp = fopen(perpetual_path,"r");
3424 static inline int gcd(int m, int n)
3427 if( m < n ) { r = m; m = n; n = r; }
3428 while( (r = m % n) != 0 ) { m = n; n = r; }
3432 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3435 if(!width || !height) return 1;
3436 if( width == 720 && (height == 480 || height == 576) ) {
3437 w = 4; h = 3; return 0; // for NTSC and PAL
3439 double ar = (double)width / height;
3440 // square-ish pixels
3441 if( EQUIV(ar, 1.0000) ) return 0;
3442 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3443 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3444 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3445 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3446 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3447 int ww = width, hh = height;
3448 // numerator, denominator must be under mx
3449 int mx = 255, n = gcd(ww, hh);
3450 if( n > 1 ) { ww /= n; hh /= n; }
3451 // search near height in case extra/missing lines
3452 if( ww >= mx || hh >= mx ) {
3453 double err = height; // +/- 2 percent height
3454 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3455 int iw = width, ih = height+i;
3456 if( (n=gcd(iw, ih)) > 1 ) {
3457 int u = iw/n; if( u >= mx ) continue;
3458 int v = ih/n; if( v >= mx ) continue;
3459 double r = (double) u/v, er = fabs(ar-r);
3460 if( er >= err ) continue;
3461 err = er; ww = u; hh = v;
3470 void MWindow::reset_caches()
3472 frame_cache->remove_all();
3473 wave_cache->remove_all();
3474 audio_cache->remove_all();
3475 video_cache->remove_all();
3476 if( cwindow->playback_engine ) {
3477 if( cwindow->playback_engine->audio_cache )
3478 cwindow->playback_engine->audio_cache->remove_all();
3479 if( cwindow->playback_engine->video_cache )
3480 cwindow->playback_engine->video_cache->remove_all();
3482 for(int i = 0; i < vwindows.size(); i++) {
3483 VWindow *vwindow = vwindows[i];
3484 if( !vwindow->is_running() ) continue;
3485 if( !vwindow->playback_engine ) continue;
3486 if( vwindow->playback_engine->audio_cache )
3487 vwindow->playback_engine->audio_cache->remove_all();
3488 if( vwindow->playback_engine->video_cache )
3489 vwindow->playback_engine->video_cache->remove_all();
3493 void MWindow::remove_asset_from_caches(Asset *asset)
3495 frame_cache->remove_asset(asset);
3496 wave_cache->remove_asset(asset);
3497 audio_cache->delete_entry(asset);
3498 video_cache->delete_entry(asset);
3499 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3500 cwindow->playback_engine->audio_cache->delete_entry(asset);
3501 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3502 cwindow->playback_engine->video_cache->delete_entry(asset);
3503 for(int i = 0; i < vwindows.size(); i++) {
3504 VWindow *vwindow = vwindows[i];
3505 if( !vwindow->is_running() ) continue;
3506 if( !vwindow->playback_engine ) continue;
3507 if( vwindow->playback_engine->audio_cache )
3508 vwindow->playback_engine->audio_cache->delete_entry(asset);
3509 if( vwindow->playback_engine->video_cache )
3510 vwindow->playback_engine->video_cache->delete_entry(asset);
3515 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3516 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3518 for(int i = 0; i < drag_assets->total; i++) {
3519 Indexable *indexable = drag_assets->get(i);
3520 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3523 // Remove from VWindow.
3524 for(int i = 0; i < session->drag_clips->total; i++) {
3525 for(int j = 0; j < vwindows.size(); j++) {
3526 VWindow *vwindow = vwindows[j];
3527 if( !vwindow->is_running() ) continue;
3528 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3529 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3530 vwindow->delete_source(1, 1);
3531 vwindow->gui->unlock_window();
3536 for(int i = 0; i < drag_assets->size(); i++) {
3537 for(int j = 0; j < vwindows.size(); j++) {
3538 VWindow *vwindow = vwindows[j];
3539 if( !vwindow->is_running() ) continue;
3540 if(drag_assets->get(i) == vwindow->get_source()) {
3541 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3542 vwindow->delete_source(1, 1);
3543 vwindow->gui->unlock_window();
3548 for(int i = 0; i < drag_assets->size(); i++) {
3549 Indexable *indexable = drag_assets->get(i);
3550 remove_indexfile(indexable);
3553 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3554 if(push_undo) undo->update_undo_before();
3555 if(drag_assets) edl->remove_from_project(drag_assets);
3556 if(drag_clips) edl->remove_from_project(drag_clips);
3557 if(redraw) save_backup();
3558 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3562 gui->lock_window("MWindow::remove_assets_from_project 3");
3563 gui->update(1, 1, 1, 1, 0, 1, 0);
3564 gui->unlock_window();
3566 // Removes from playback here
3567 sync_parameters(CHANGE_ALL);
3570 awindow->gui->async_update_assets();
3573 void MWindow::remove_assets_from_disk()
3576 for(int i = 0; i < session->drag_assets->total; i++)
3578 remove(session->drag_assets->get(i)->path);
3581 remove_assets_from_project(1,
3583 session->drag_assets,
3584 session->drag_clips);
3587 void MWindow::dump_plugins(FILE *fp)
3589 if( !plugindb ) return;
3590 for(int i = 0; i < plugindb->total; i++)
3592 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3593 " synth=%d transition=%d theme=%d %s\n",
3594 plugindb->get(i)->plugin_type,
3595 plugindb->get(i)->audio,
3596 plugindb->get(i)->video,
3597 plugindb->get(i)->realtime,
3598 plugindb->get(i)->multichannel,
3599 plugindb->get(i)->get_synthesis(),
3600 plugindb->get(i)->transition,
3601 plugindb->get(i)->theme,
3602 plugindb->get(i)->title);
3606 void MWindow::dump_edl(FILE *fp)
3612 void MWindow::dump_undo(FILE *fp)
3618 void MWindow::dump_exe(FILE *fp)
3620 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3621 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3623 int ret = -1, n = 100;
3624 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3625 exe_path[len] = 0; strcpy(proc_path, exe_path);
3628 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3631 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3632 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3633 struct tm *tm = localtime(&st.st_mtime);
3635 strftime(mtime, sizeof(mtime), "%F %T", tm);
3636 fprintf(fp,"mtime: %s\n", mtime);
3638 // people hit ctl-c waiting for this
3639 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3640 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3643 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3644 int64_t maxsz = 1024*pagsz;
3645 int64_t size = st.st_size, pos = 0;
3647 while( (bfrsz = size-pos) > 0 ) {
3648 if( bfrsz > maxsz ) bfrsz = maxsz;
3649 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3650 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3651 if( bfr == MAP_FAILED ) break;
3652 sha1.addBytes(bfr, bfrsz);
3657 ret = pos < size ? EIO : 0;
3658 fprintf(fp, "SHA1: ");
3659 uint8_t digest[20]; sha1.computeHash(digest);
3660 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3661 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3662 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3667 void MWindow::trap_hook(FILE *fp, void *vp)
3669 MWindow *mwindow = (MWindow *)vp;
3670 // fprintf(fp, "\nPLUGINS:\n");
3671 // mwindow->dump_plugins(fp);
3672 fprintf(fp, "\nEDL:\n");
3673 mwindow->dump_edl(fp);
3674 fprintf(fp, "\nUNDO:\n");
3675 mwindow->dump_undo(fp);
3676 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
3677 mwindow->dump_exe(fp);
3685 int MWindow::save_defaults()
3687 gui->save_defaults(defaults);
3688 edl->save_defaults(defaults);
3689 session->save_defaults(defaults);
3690 preferences->save_defaults(defaults);
3692 for(int i = 0; i < plugin_guis->total; i++)
3694 // Pointer comparison
3695 plugin_guis->get(i)->save_defaults();
3697 awindow->save_defaults(defaults);
3703 int MWindow::run_script(FileXML *script)
3705 int result = 0, result2 = 0;
3706 while(!result && !result2)
3708 result = script->read_tag();
3711 if(script->tag.title_is("new_project"))
3713 // Run new in immediate mode.
3714 // gui->mainmenu->new_project->run_script(script);
3717 if(script->tag.title_is("record"))
3719 // Run record as a thread. It is a terminal command.
3721 // Will read the complete scipt file without letting record read it if not
3727 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3734 // ================================= synchronization
3737 int MWindow::interrupt_indexes()
3739 mainprogress->cancelled = 1;
3740 mainindexes->interrupt_build();
3746 void MWindow::next_time_format()
3748 switch(edl->session->time_format)
3750 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3751 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3752 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3753 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3754 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3755 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3756 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3759 time_format_common();
3762 void MWindow::prev_time_format()
3764 switch(edl->session->time_format)
3766 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3767 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3768 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3769 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3770 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3771 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3772 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3775 time_format_common();
3778 void MWindow::time_format_common()
3780 gui->lock_window("MWindow::next_time_format");
3781 gui->redraw_time_dependancies();
3784 char string[BCTEXTLEN], string2[BCTEXTLEN];
3785 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3786 gui->show_message(string);
3788 gui->unlock_window();
3792 int MWindow::set_filename(const char *filename)
3794 if( filename != session->filename )
3795 strcpy(session->filename, filename);
3796 if( filename != edl->path )
3797 strcpy(edl->path, filename);
3801 if(filename[0] == 0)
3803 gui->set_title(PROGRAM_NAME);
3808 char string[BCTEXTLEN], string2[BCTEXTLEN];
3809 dir.extract_name(string, filename);
3810 sprintf(string2, PROGRAM_NAME ": %s", string);
3811 gui->set_title(string2);
3824 int MWindow::set_loop_boundaries()
3826 double start = edl->local_session->get_selectionstart();
3827 double end = edl->local_session->get_selectionend();
3835 if(edl->tracks->total_length())
3838 end = edl->tracks->total_length();
3845 if(edl->local_session->loop_playback && start != end)
3847 edl->local_session->loop_start = start;
3848 edl->local_session->loop_end = end;
3859 int MWindow::reset_meters()
3861 cwindow->gui->lock_window("MWindow::reset_meters 1");
3862 cwindow->gui->meters->reset_meters();
3863 cwindow->gui->unlock_window();
3865 for(int j = 0; j < vwindows.size(); j++) {
3866 VWindow *vwindow = vwindows[j];
3867 if( !vwindow->is_running() ) continue;
3868 vwindow->gui->lock_window("MWindow::reset_meters 2");
3869 vwindow->gui->meters->reset_meters();
3870 vwindow->gui->unlock_window();
3873 lwindow->gui->lock_window("MWindow::reset_meters 3");
3874 lwindow->gui->panel->reset_meters();
3875 lwindow->gui->unlock_window();
3877 gui->lock_window("MWindow::reset_meters 4");
3878 gui->reset_meters();
3879 gui->unlock_window();
3884 void MWindow::resync_guis()
3888 gui->lock_window("MWindow::resync_guis");
3889 gui->update(1, 1, 1, 1, 1, 1, 0);
3890 gui->unlock_window();
3892 cwindow->gui->lock_window("MWindow::resync_guis");
3893 cwindow->gui->resize_event(cwindow->gui->get_w(),
3894 cwindow->gui->get_h());
3895 int channels = edl->session->audio_channels;
3896 cwindow->gui->meters->set_meters(channels, 1);
3897 cwindow->gui->flush();
3898 cwindow->gui->unlock_window();
3900 for(int i = 0; i < vwindows.size(); i++) {
3901 VWindow *vwindow = vwindows[i];
3902 if( !vwindow->is_running() ) continue;
3903 vwindow->gui->lock_window("MWindow::resync_guis");
3904 vwindow->gui->resize_event(vwindow->gui->get_w(),
3905 vwindow->gui->get_h());
3906 vwindow->gui->meters->set_meters(channels, 1);
3907 vwindow->gui->flush();
3908 vwindow->gui->unlock_window();
3911 lwindow->gui->lock_window("MWindow::resync_guis");
3912 lwindow->gui->panel->set_meters(channels, 1);
3913 lwindow->gui->flush();
3914 lwindow->gui->unlock_window();
3917 if(((edl->session->output_w % 4) ||
3918 (edl->session->output_h % 4)) &&
3919 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3921 MainError::show_error(
3922 _("This project's dimensions are not multiples of 4 so\n"
3923 "it can't be rendered by OpenGL."));
3928 sync_parameters(CHANGE_ALL);
3931 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3933 File *file = new File;
3934 EDLSession *session = edl->session;
3935 double old_framerate = session->frame_rate;
3936 double old_samplerate = session->sample_rate;
3937 int old_auto_keyframes = session->auto_keyframes;
3938 session->auto_keyframes = 0;
3939 int result = file->open_file(preferences, asset, 1, 0);
3940 if( !result && delete_tracks > 0 )
3941 undo->update_undo_before();
3942 int video_layers = asset->get_video_layers();
3943 if( !result && asset->video_data && vstream < video_layers ) {
3944 // try to get asset up to date, may fail
3945 file->select_video_stream(asset, vstream);
3946 // either way use what was/is there.
3947 double framerate = asset->get_frame_rate();
3948 int width = asset->get_w();
3949 int height = asset->get_h();
3950 // must be multiple of 4 for opengl
3951 width = (width+3) & ~3; height = (height+3) & ~3;
3952 int driver = session->playback_config->vconfig->driver;
3953 int color_model = file->get_best_colormodel(asset, driver);
3954 // color_model = BC_CModels::is_yuv(color_model) ?
3955 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3956 // BC_CModels::is_float(color_model) ?
3957 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3958 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3959 // have alpha for now
3960 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3961 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3962 session->color_model = color_model;
3963 session->output_w = width;
3964 session->output_h = height;
3965 session->frame_rate = framerate;
3966 // not, asset->actual_width/actual_height
3967 asset->width = session->output_w;
3968 asset->height = session->output_h;
3969 asset->frame_rate = session->frame_rate;
3970 create_aspect_ratio(session->aspect_w, session->aspect_h,
3971 session->output_w, session->output_h);
3972 Track *track = edl->tracks->first;
3973 for( Track *next_track=0; track; track=next_track ) {
3974 next_track = track->next;
3975 if( track->data_type != TRACK_VIDEO ) continue;
3976 if( delete_tracks ) {
3977 Edit *edit = track->edits->first;
3978 for( Edit *next_edit=0; edit; edit=next_edit ) {
3979 next_edit = edit->next;
3980 if( edit->channel != vstream ||
3981 !edit->asset || !edit->asset->is_asset ||
3982 !asset->equivalent(*edit->asset,1,1,edl) )
3986 if( track->edits->first ) {
3987 track->track_w = edl->session->output_w;
3988 track->track_h = edl->session->output_h;
3990 else if( delete_tracks )
3991 edl->tracks->delete_track(track);
3994 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3996 if( !result && asset->audio_data && asset->channels > 0 ) {
3997 session->sample_rate = asset->get_sample_rate();
3998 int64_t channel_mask = 0;
3999 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
4000 file->get_audio_for_video(vstream, astream, channel_mask);
4001 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
4002 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
4004 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4005 if( channels < 1 ) channels = 1;
4006 if( channels > 6 ) channels = 6;
4007 session->audio_tracks = session->audio_channels = channels;
4009 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4010 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4011 remap_audio(MWindow::AUDIO_1_TO_1);
4013 if( delete_tracks ) {
4014 Track *track = edl->tracks->first;
4015 for( Track *next_track=0; track; track=next_track ) {
4016 next_track = track->next;
4017 if( track->data_type != TRACK_AUDIO ) continue;
4018 Edit *edit = track->edits->first;
4019 for( Edit *next_edit=0; edit; edit=next_edit ) {
4020 next_edit = edit->next;
4021 if( !((1<<edit->channel) & channel_mask) ||
4022 !edit->asset || !edit->asset->is_asset ||
4023 !asset->equivalent(*edit->asset,1,1,edl) )
4026 if( !track->edits->first )
4027 edl->tracks->delete_track(track);
4031 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4034 session->auto_keyframes = old_auto_keyframes;
4035 if( !result && delete_tracks > 0 ) {
4037 undo->update_undo_after(_("select asset"), LOAD_ALL);
4043 int MWindow::select_asset(int vtrack, int delete_tracks)
4045 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4047 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4048 if( !track ) return 1;
4049 Edit *edit = track->edits->first;
4050 if( !edit ) return 1;
4051 Asset *asset = edit->asset;
4052 if( !asset || !asset->is_asset ) return 1;
4053 return select_asset(asset, edit->channel, 0, delete_tracks);
4056 void MWindow::dump_plugindb(FILE *fp)
4058 if( !plugindb ) return;
4059 for(int i = 0; i < plugindb->total; i++)
4060 plugindb->get(i)->dump(fp);
4063 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4066 double unit_position = edl->local_session->get_selectionstart(1);
4067 unit_position = patch->track->to_units(unit_position, 0);
4069 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4070 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4073 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4076 double unit_position = edl->local_session->get_selectionstart(1);
4077 unit_position = patch->track->to_units(unit_position, 0);
4079 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4080 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4083 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4086 double unit_position = edl->local_session->get_selectionstart(1);
4087 unit_position = patch->track->to_units(unit_position, 0);
4089 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4090 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4093 PatchGUI *MWindow::get_patchgui(Track *track)
4095 PatchGUI *patchgui = 0;
4096 TimelinePane **panes = gui->pane;
4097 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4098 if( !panes[i] ) continue;
4099 PatchBay *patchbay = panes[i]->patchbay;
4100 if( !patchbay ) continue;
4101 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4102 if( patchbay->patches.values[j]->track == track )
4103 patchgui = patchbay->patches.values[j];