3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "aboutprefs.h"
25 #include "audioalsa.h"
27 #include "awindowgui.h"
29 #include "batchrender.h"
30 #include "bcdisplayinfo.h"
31 #include "bcsignals.h"
38 #include "channeldb.h"
39 #include "channelinfo.h"
42 #include "bccmodels.h"
43 #include "commercials.h"
44 #include "cplayback.h"
46 #include "cwindowgui.h"
48 #include "cwindowtool.h"
50 #include "devicedvbinput.inc"
51 #include "dvdcreate.h"
52 #include "editpanel.h"
54 #include "edlsession.h"
56 #include "fileformat.h"
58 #include "filesystem.h"
60 #include "floatautos.h"
61 #include "framecache.h"
63 #include "gwindowgui.h"
64 #include "keyframegui.h"
65 #include "indexfile.h"
67 #include "interlacemodes.h"
69 #include "levelwindowgui.h"
70 #include "levelwindow.h"
71 #include "loadfile.inc"
72 #include "localsession.h"
73 #include "maincursor.h"
74 #include "mainerror.h"
75 #include "mainindexes.h"
77 #include "mainprogress.h"
78 #include "mainsession.h"
82 #include "mwindowgui.h"
87 #include "playback3d.h"
88 #include "playbackengine.h"
90 #include "pluginserver.h"
91 #include "pluginset.h"
92 #include "preferences.h"
95 #include "recordmonitor.h"
96 #include "recordlabel.h"
97 #include "removefile.h"
99 #include "resourcethread.h"
100 #include "samplescroll.h"
102 #include "sighandler.h"
103 #include "splashgui.h"
104 #include "statusbar.h"
106 #include "threadloader.h"
108 #include "timelinepane.h"
109 #include "tipwindow.h"
110 #include "trackcanvas.h"
112 #include "tracking.h"
113 #include "trackscroll.h"
115 #include "transition.h"
116 #include "transportque.h"
119 #include "versioninfo.h"
120 #include "videodevice.inc"
121 #include "videowindow.h"
122 #include "vplayback.h"
123 #include "vwindowgui.h"
125 #include "wavecache.h"
129 #include "zwindowgui.h"
130 #include "exportedl.h"
132 #include "defaultformats.h"
133 #include "ntsczones.h"
140 #include <sys/types.h>
141 #include <sys/stat.h>
142 #include <sys/time.h>
143 #include <sys/mman.h>
154 // Hack for libdv to remove glib dependancy
157 // g_log (const char *log_domain,
159 // const char *format,
165 // g_logv (const char *log_domain,
167 // const char *format,
177 ArrayList<PluginServer*>* MWindow::plugindb = 0;
178 Commercials* MWindow::commercials = 0;
184 run_lock = new Mutex("MWindow::run_lock");
185 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
186 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
187 vwindows_lock = new Mutex("MWindow::vwindows_lock");
188 zwindows_lock = new Mutex("MWindow::zwindows_lock");
189 brender_lock = new Mutex("MWindow::brender_lock");
190 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
198 commercial_active = 0;
210 strcpy(cin_lang,"en");
211 channeldb_buz = new ChannelDB;
212 channeldb_v4l2jpeg = new ChannelDB;
215 keyframe_threads = 0;
236 // Need to delete brender temporary here.
239 run_lock->lock("MWindow::~MWindow");
241 //printf("MWindow::~MWindow %d\n", __LINE__);
242 gui->remote_control->deactivate();
245 gui->channel_info->stop();
247 delete create_bd; create_bd = 0;
248 delete create_dvd; create_dvd = 0;
249 delete batch_render; batch_render = 0;
250 delete render; render = 0;
252 if( commercials && !commercials->remove_user() ) commercials = 0;
254 if( speed_edl ) { speed_edl->remove_user(); speed_edl = 0; }
255 // Save defaults for open plugins
256 plugin_gui_lock->lock("MWindow::~MWindow");
257 for(int i = 0; i < plugin_guis->size(); i++) {
258 plugin_guis->get(i)->hide_gui();
259 delete_plugin(plugin_guis->get(i));
261 plugin_gui_lock->unlock();
262 hide_keyframe_guis();
265 // Give up and go to a movie
266 // cant run valgrind if this is used
268 gui->del_keyboard_listener(
269 (int (BC_WindowBase::*)(BC_WindowBase *))
270 &MWindowGUI::keyboard_listener);
272 // release the hounds
273 if( awindow && awindow->gui ) awindow->gui->close(0);
274 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
275 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
276 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
277 if( twindow && twindow->is_running() ) twindow->close_window();
278 if( wwindow && wwindow->is_running() ) wwindow->close_window();
279 vwindows.remove_all_objects();
280 zwindows.remove_all_objects();
282 if( awindow ) awindow->join();
283 if( cwindow ) cwindow->join();
284 if( lwindow ) lwindow->join();
285 if( twindow ) twindow->join();
286 if( wwindow ) wwindow->join();
287 if( gwindow ) gwindow->join();
290 // one at a time, or nouveau chokes
291 #define close_gui(win) if( win ) { \
292 if( win->gui ) win->gui->close(0); \
300 vwindows.remove_all_objects();
301 zwindows.remove_all_objects();
306 dead_plugins->remove_all_objects();
307 // must delete theme before destroying plugindb
308 // theme destructor will be deleted by delete_plugins
309 delete theme; theme = 0;
312 keyframe_threads->remove_all_objects();
313 colormodels.remove_all_objects();
314 delete awindow; awindow = 0;
315 delete lwindow; lwindow = 0;
316 delete twindow; twindow = 0;
317 delete wwindow; wwindow = 0;
318 delete gwindow; gwindow = 0;
319 delete cwindow; cwindow = 0;
321 delete mainindexes; mainindexes = 0;
322 delete mainprogress; mainprogress = 0;
323 delete audio_cache; audio_cache = 0; // delete the cache after the assets
324 delete video_cache; video_cache = 0; // delete the cache after the assets
325 delete frame_cache; frame_cache = 0;
326 delete wave_cache; wave_cache = 0;
327 delete plugin_guis; plugin_guis = 0;
328 delete dead_plugins; dead_plugins = 0;
329 delete keyframe_threads; keyframe_threads = 0;
330 delete undo; undo = 0;
331 delete preferences; preferences = 0;
332 delete exportedl; exportedl = 0;
333 delete session; session = 0;
334 delete defaults; defaults = 0;
335 delete assets; assets = 0;
336 delete splash_window; splash_window = 0;
337 if( !edl->Garbage::remove_user() ) edl = 0;
338 delete channeldb_buz;
339 delete channeldb_v4l2jpeg;
340 // This must be last thread to exit
341 delete playback_3d; playback_3d = 0;
342 delete dead_plugin_lock;
343 delete plugin_gui_lock;
344 delete vwindows_lock;
345 delete zwindows_lock;
347 delete keyframe_gui_lock;
348 colormodels.remove_all_objects();
349 interlace_project_modes.remove_all_objects();
350 interlace_asset_modes.remove_all_objects();
351 interlace_asset_fixmethods.remove_all_objects();
352 sighandler->terminate();
363 void MWindow::init_error()
365 MainError::init_error(this);
368 void MWindow::finit_error()
370 MainError::finit_error();
373 void MWindow::create_defaults_path(char *string, const char *config_file)
375 // set the .bcast path
378 sprintf(string, "%s/", File::get_config_path());
379 fs.complete_path(string);
380 if(!fs.is_dir(string))
381 fs.create_dir(string);
384 strcat(string, config_file);
386 const char *MWindow::default_std()
388 char buf[BCTEXTLEN], *p = 0;
390 int fd = open(TIMEZONE_NAME, O_RDONLY);
392 int l = read(fd, buf, sizeof(buf)-1);
395 if( buf[l-1] == '\n' ) --l;
401 int l = readlink(LOCALTIME_LINK, buf, sizeof(buf)-1);
404 if( !(p=strstr(buf, ZONEINFO_STR)) != 0 ) return "PAL";
405 p += strlen(ZONEINFO_STR);
410 for( int i=0; ntsc_zones[i]; ++i ) {
411 if( !strcmp(ntsc_zones[i], p) )
418 for( int i=0; ntsc_zones[i]; ++i ) {
419 if( !strcmp(ntsc_zones[i], p) )
424 //__timezone: Seconds west of UTC. 240sec/deg
425 double tz_deg = -__timezone / 240.;
426 // from Honolulu = -10, to New York = -5, 15deg/hr lat -150..-75
427 return tz_deg >= -10*15 && tz_deg <= -5*15 ? "NTSC" : "PAL";
430 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
432 struct formatpresets *fpr;
434 for(fpr = &format_presets[0]; fpr->name; fpr++)
436 if(strcmp(_(fpr->name), preset) == 0)
438 session->audio_channels = fpr->audio_channels;
439 session->audio_tracks = fpr->audio_tracks;
440 session->sample_rate = fpr->sample_rate;
441 session->video_channels = fpr->video_channels;
442 session->video_tracks = fpr->video_tracks;
443 session->frame_rate = fpr->frame_rate;
444 session->output_w = fpr->output_w;
445 session->output_h = fpr->output_h;
446 session->aspect_w = fpr->aspect_w;
447 session->aspect_h = fpr->aspect_h;
448 session->interlace_mode = fpr->interlace_mode;
449 session->color_model = fpr->color_model;
455 const char *MWindow::get_preset_name(int index)
457 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
459 return _(format_presets[index].name);
463 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
465 char path[BCTEXTLEN];
466 // Use user supplied path
468 strcpy(path, config_path);
470 create_defaults_path(path, CONFIG_FILE);
473 defaults = new BC_Hash(path);
478 void MWindow::check_language()
480 char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
481 const char *env_lang = getenv("LANGUAGE");
482 if( !env_lang ) env_lang = getenv("LC_ALL");
483 if( !env_lang ) env_lang = getenv("LANG");
485 snprintf(curr_lang, sizeof(curr_lang), "%s_%s-%s",
486 BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
487 env_lang = curr_lang;
489 char last_lang[BCTEXTLEN]; last_lang[0] = 0;
490 defaults->get("LAST_LANG",last_lang);
491 if( strcmp(env_lang,last_lang)) {
492 printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
493 defaults->update("LAST_LANG",env_lang);
494 char plugin_path[BCTEXTLEN];
495 create_defaults_path(plugin_path, PLUGIN_FILE);
496 ::remove(plugin_path);
497 char ladspa_path[BCTEXTLEN];
498 create_defaults_path(ladspa_path, LADSPA_FILE);
499 ::remove(ladspa_path);
502 if( strlen(env_lang) > 1 &&
503 ( env_lang[2] == 0 || env_lang[2] == '_' || env_lang[2] == '.' ) ) {
504 cin_lang[0] = env_lang[0]; cin_lang[1] = env_lang[1]; cin_lang[2] = 0;
507 strcpy(cin_lang, "en");
510 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
512 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
514 const char *dp = plug_dir;
515 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
516 bp = !*dp && *bp == '/' ? bp+1 : base_path;
522 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
525 FILE *fp = fopen(index_path, "r");
529 char index_line[BCTEXTLEN];
530 int index_version = -1, len = strlen(plugin_dir);
531 if( !fgets(index_line, BCTEXTLEN, fp) ||
532 sscanf(index_line, "%d", &index_version) != 1 ||
533 index_version != PLUGIN_FILE_VERSION ||
534 !fgets(index_line, BCTEXTLEN, fp) ||
535 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
536 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
538 ArrayList<PluginServer*> plugins;
539 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
540 if( index_line[0] == ';' ) continue;
541 if( index_line[0] == '#' ) continue;
542 int type = PLUGIN_TYPE_UNKNOWN;
543 char path[BCTEXTLEN], title[BCTEXTLEN];
545 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
548 PluginServer *server = 0;
550 case PLUGIN_TYPE_BUILTIN:
551 case PLUGIN_TYPE_EXECUTABLE:
552 case PLUGIN_TYPE_LADSPA: {
553 char plugin_path[BCTEXTLEN]; struct stat st;
554 sprintf(plugin_path, "%s/%s", plugin_dir, path);
555 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
558 server = new PluginServer(mwindow, plugin_path, type);
560 case PLUGIN_TYPE_FFMPEG: {
561 server = new_ffmpeg_server(mwindow, path);
563 case PLUGIN_TYPE_LV2: {
564 server = new_lv2_server(mwindow, path);
567 if( !server ) continue;
568 plugins.append(server);
569 // Create plugin server from index entry
570 server->set_title(title);
571 if( server->read_table(index_line) ) {
578 ret = check_plugin_index(plugins, plugin_dir, ".");
581 add_plugins(plugins);
583 plugins.remove_all_objects();
588 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
589 const char *plug_dir, const char *plug_path)
591 char plugin_path[BCTEXTLEN];
592 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
594 fs.set_filter( "[*.plugin][*.so]" );
595 if( fs.update(plugin_path) )
598 for( int i=0; i<fs.dir_list.total; ++i ) {
599 char fs_path[BCTEXTLEN];
600 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
601 if( fs.is_dir(fs_path) ) {
602 get_plugin_path(plugin_path, plug_dir, fs_path);
603 if( check_plugin_index(plugins, plug_dir, plugin_path) )
606 else if( !plugin_exists(fs_path, plugins) )
613 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
616 plugindb = new ArrayList<PluginServer*>;
618 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
619 create_defaults_path(index_path, PLUGIN_FILE);
620 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
621 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
622 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
623 printf("init plugin index: %s\n", plugin_path);
624 FILE *fp = fopen(index_path,"w");
626 fprintf(stderr,_("MWindow::init_plugins: "
627 "can't create plugin index: %s\n"), index_path);
630 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
631 fprintf(fp, "%s\n", plugin_path);
632 init_plugin_index(mwindow, preferences, fp, plugin_path);
633 init_ffmpeg_index(mwindow, preferences, fp);
634 init_lv2_index(mwindow, preferences, fp);
636 return load_plugin_index(mwindow, index_path, plugin_path);
639 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
641 char *path = getenv("LADSPA_PATH");
642 char ladspa_path[BCTEXTLEN];
644 strncpy(ladspa_path, File::get_ladspa_path(), sizeof(ladspa_path));
647 for( int len=0; *path; path+=len ) {
648 char *cp = strchr(path,':');
649 len = !cp ? strlen(path) : cp-path;
650 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
651 memcpy(plugin_path, path, len); plugin_path[len] = 0;
653 char *plugin_dir = FileSystem::basepath(plugin_path);
654 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
655 create_defaults_path(index_path, LADSPA_FILE);
656 cp = index_path + strlen(index_path);
657 for( char *bp=plugin_path; *bp!=0; ++bp )
658 *cp++ = *bp=='/' ? '_' : *bp;
660 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
661 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
662 load_plugin_index(mwindow, index_path, plugin_path);
667 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
668 FILE *fp, const char *plugin_dir)
670 int idx = PLUGIN_IDS;
672 for( int i=0; i<plugindb->size(); ++i ) {
673 PluginServer *server = plugindb->get(i);
674 if( server->dir_idx >= idx )
675 idx = server->dir_idx+1;
678 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
681 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
682 const char *plug_dir, const char *plug_path, int &idx)
684 char plugin_path[BCTEXTLEN];
685 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
687 fs.set_filter( "[*.plugin][*.so]" );
688 int result = fs.update(plugin_path);
689 if( result || !fs.dir_list.total ) return;
692 for( int i=0; i<fs.dir_list.total; ++i ) {
693 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
694 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
695 get_plugin_path(path, plug_dir, fs_path);
696 if( fs.is_dir(fs_path) ) {
697 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
700 if( plugin_exists(path) ) continue;
702 if( stat(fs_path, &st) ) continue;
703 int64_t mtime = st.st_mtime;
704 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
705 result = server.open_plugin(1, preferences, 0, 0);
707 server.write_table(fp, path, vis_id, mtime);
708 server.close_plugin();
710 else if( result == PLUGINSERVER_IS_LAD ) {
713 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
714 ladspa.set_lad_index(lad_index++);
715 result = ladspa.open_plugin(1, preferences, 0, 0);
717 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
718 ladspa.close_plugin();
724 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
726 for( int i=0; i<plugins.size(); ++i )
727 plugindb->append(plugins[i]);
728 plugins.remove_all();
731 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
733 const char *dat_path = File::get_cindat_path();
734 char msg_path[BCTEXTLEN];
736 if( BC_Resources::language[0] ) {
737 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
739 fp = fopen(msg_path, "r");
742 snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
744 fp = fopen(msg_path, "r");
747 char text[BCTEXTLEN];
748 char *tp = text, *ep = tp + sizeof(text)-1;
749 char title[BCTEXTLEN];
754 char line[BCTEXTLEN], *cp = line;
755 if( fgets(line,sizeof(line)-1,fp) ) {
756 if( *cp == '#' ) continue;
757 done = *cp == ' ' || *cp == '\t' ? 0 : -1;
760 if( tp > text && *--tp == '\n' ) *tp = 0;
762 int idx = plugins.size();
763 while( --idx>=0 && strcmp(plugins[idx]->title, title) );
765 delete [] plugins[idx]->tip;
766 plugins[idx]->tip = cstrdup(text);
770 if( done > 0 ) break;
772 char *dp = strchr(cp, ':');
774 printf("plugin tips: error on line %d\n", no);
778 while( cp < dp ) *bp++ = *cp++;
783 while( *cp == ' ' || *cp == '\t' ) ++cp;
784 for( ; tp<ep && (*tp=*cp)!=0; ++tp,++cp );
789 void MWindow::delete_plugins()
791 plugindb->remove_all_objects();
796 void MWindow::search_plugindb(int do_audio,
801 ArrayList<PluginServer*> &results)
804 for(int i = 0; i < MWindow::plugindb->total; i++)
806 PluginServer *current = MWindow::plugindb->get(i);
808 if(current->audio == do_audio &&
809 current->video == do_video &&
810 (current->realtime == is_realtime || is_realtime < 0) &&
811 current->transition == is_transition &&
812 current->theme == is_theme)
813 results.append(current);
816 // Alphabetize list by title
822 for(int i = 0; i < results.total - 1; i++)
824 PluginServer *value1 = results[i];
825 PluginServer *value2 = results[i + 1];
826 if(strcmp(_(value1->title), _(value2->title)) > 0)
830 results[i + 1] = value1;
836 PluginServer* MWindow::scan_plugindb(char *title,
841 // printf("MWindow::scan_plugindb data_type < 0\n");
845 for(int i = 0; i < plugindb->total; i++)
847 PluginServer *server = plugindb->get(i);
849 !strcasecmp(server->title, title) &&
851 (data_type == TRACK_AUDIO && server->audio) ||
852 (data_type == TRACK_VIDEO && server->video)))
853 return plugindb->get(i);
858 // repair session files with xlated plugin titles
859 void MWindow::fix_plugin_title(char *title)
861 for(int i = 0; i < plugindb->total; i++) {
862 PluginServer *server = plugindb->get(i);
863 if( !server->title ) continue;
864 const char *server_title = server->title;
865 if( !bstrcasecmp(title, _(server_title)) ) {
866 strcpy(title, server_title);
872 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
874 for( int i=0; i<plugins.size(); ++i )
875 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
879 int MWindow::plugin_exists(char *plugin_path)
881 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
884 void MWindow::remove_plugin_index()
886 char index_path[BCTEXTLEN];
887 MWindow::create_defaults_path(index_path, PLUGIN_FILE);
888 ::remove(index_path);
891 void MWindow::init_preferences()
893 preferences = new Preferences;
894 preferences->load_defaults(defaults);
895 const char *lv2_path = getenv("LV2_PATH");
896 if( lv2_path && strcmp(lv2_path, preferences->lv2_path) ) {
897 strncpy(preferences->lv2_path, lv2_path, sizeof(preferences->lv2_path));
898 remove_plugin_index();
900 else if( !lv2_path && preferences->lv2_path[0] ) {
901 File::setenv_path("LV2_PATH",preferences->lv2_path, 0);
903 session = new MainSession(this);
904 session->load_defaults(defaults);
905 // set x11_host, screens, window_config
906 screens = session->set_default_x11_host();
907 BC_Signals::set_trap_hook(trap_hook, this);
908 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
909 BC_Signals::set_catch_intr(preferences->trap_sigintr);
910 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
911 BC_Trace::enable_locks();
914 BC_Trace::disable_locks();
916 BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
917 BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
918 BC_WindowBase::get_resources()->grab_input_focus = preferences->grab_input_focus;
919 YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
922 void MWindow::clean_indexes()
927 int oldest_item = -1;
929 char string[BCTEXTLEN];
930 char string2[BCTEXTLEN];
932 // Delete extra indexes
933 fs.set_filter("*.idx");
934 fs.complete_path(preferences->index_directory);
935 fs.update(preferences->index_directory);
936 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
938 // Eliminate directories
943 for(int i = 0; i < fs.dir_list.total && !result; i++)
945 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
946 if(fs.is_dir(string))
948 delete fs.dir_list[i];
949 fs.dir_list.remove_number(i);
954 total_excess = fs.dir_list.total - preferences->index_count;
956 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
957 while(total_excess > 0)
960 for(int i = 0; i < fs.dir_list.total; i++)
962 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
964 if(i == 0 || fs.get_date(string) <= oldest)
966 oldest = fs.get_date(string);
974 fs.join_names(string,
975 preferences->index_directory,
976 fs.dir_list[oldest_item]->name);
977 //printf("MWindow::clean_indexes 1 %s\n", string);
979 perror("delete_indexes");
980 delete fs.dir_list[oldest_item];
981 fs.dir_list.remove_number(oldest_item);
983 // Remove table of contents if it exists
984 strcpy(string2, string);
985 char *ptr = strrchr(string2, '.');
988 //printf("MWindow::clean_indexes 2 %s\n", string2);
989 sprintf(ptr, ".toc");
991 sprintf(ptr, ".mkr");
1000 void MWindow::init_awindow()
1002 awindow = new AWindow(this);
1003 awindow->create_objects();
1006 void MWindow::init_gwindow()
1008 gwindow = new GWindow(this);
1009 gwindow->create_objects();
1012 void MWindow::init_tipwindow()
1014 TipWindow::load_tips(cin_lang);
1016 twindow = new TipWindow(this);
1020 void MWindow::show_warning(int *do_warning, const char *text)
1022 if( do_warning && !*do_warning ) return;
1024 wwindow = new WWindow(this);
1025 wwindow->show_warning(do_warning, text);
1028 int MWindow::wait_warning()
1030 return wwindow->wait_result();
1033 void MWindow::init_theme()
1038 PluginServer *theme_plugin = 0;
1039 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1040 if( plugindb->get(i)->theme &&
1041 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
1042 theme_plugin = plugindb->get(i);
1046 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
1047 preferences->theme);
1049 const char *default_theme = DEFAULT_THEME;
1050 if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
1051 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
1053 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
1054 if( plugindb->get(i)->theme &&
1055 !strcasecmp(default_theme, plugindb->get(i)->title) )
1056 theme_plugin = plugindb->get(i);
1061 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
1065 PluginServer *plugin = new PluginServer(*theme_plugin);
1066 if( plugin->open_plugin(0, preferences, 0, 0) ) {
1067 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
1068 theme_plugin->title);
1072 theme = plugin->new_theme();
1073 theme->mwindow = this;
1074 strcpy(theme->path, plugin->path);
1077 // Load default images & settings
1078 theme->Theme::initialize();
1079 // Load user images & settings
1080 theme->initialize();
1081 // Create menus with user colors
1082 theme->build_menus();
1085 theme->sort_image_sets();
1086 theme->check_used();
1087 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1090 void MWindow::init_3d()
1092 playback_3d = new Playback3D(this);
1093 playback_3d->create_objects();
1096 void MWindow::init_edl()
1099 edl->create_objects();
1100 fill_preset_defaults(default_standard, edl->session);
1101 edl->load_defaults(defaults);
1102 edl->session->brender_start = edl->session->brender_end = 0;
1103 edl->create_default_tracks();
1104 edl->tracks->update_y_pixels(theme);
1107 void MWindow::init_compositor()
1109 cwindow = new CWindow(this);
1110 cwindow->create_objects();
1113 void MWindow::init_levelwindow()
1115 lwindow = new LevelWindow(this);
1116 lwindow->create_objects();
1119 VWindow *MWindow::get_viewer(int start_it, int idx)
1121 vwindows_lock->lock("MWindow::get_viewer");
1122 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
1123 if( !vwindow ) idx = vwindows.size();
1124 while( !vwindow && --idx >= 0 ) {
1125 VWindow *vwin = vwindows[idx];
1126 if( !vwin->is_running() || !vwin->get_edl() )
1130 vwindow = new VWindow(this);
1131 vwindow->load_defaults();
1132 vwindow->create_objects();
1133 vwindows.append(vwindow);
1135 vwindows_lock->unlock();
1136 if( start_it ) vwindow->start();
1140 ZWindow *MWindow::get_mixer(Mixer *&mixer)
1142 zwindows_lock->lock("MWindow::get_mixer");
1143 if( !mixer ) mixer = edl->mixers.new_mixer();
1144 ZWindow *zwindow = 0;
1145 for( int i=0; !zwindow && i<zwindows.size(); ++i )
1146 if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
1148 zwindows.append(zwindow = new ZWindow(this));
1149 zwindow->idx = mixer->idx;
1150 zwindows_lock->unlock();
1154 void MWindow::del_mixer(ZWindow *zwindow)
1156 zwindows_lock->lock("MWindow::del_mixer 0");
1157 edl->mixers.del_mixer(zwindow->idx);
1159 if( session->selected_zwindow >= 0 ) {
1160 int i = zwindows.number_of(zwindow);
1161 if( i >= 0 && i < session->selected_zwindow )
1162 --session->selected_zwindow;
1163 else if( i == session->selected_zwindow )
1164 session->selected_zwindow = -1;
1166 zwindows_lock->unlock();
1167 gui->lock_window("MWindow::del_mixer 1");
1168 gui->update_mixers(0, -1);
1169 gui->unlock_window();
1172 void MWindow::start_mixer()
1175 ZWindow *zwindow = get_mixer(mixer);
1176 const char *title = 0;
1178 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
1179 PatchGUI *patchgui = get_patchgui(track);
1180 if( !patchgui || !patchgui->mixer ) continue;
1181 mixer->mixer_ids.append(track->get_mixer_id());
1182 if( !title ) title = track->title;
1185 session->selected_zwindow = -1;
1186 gui->lock_window("MWindow::start_mixer");
1187 gui->update_mixers(0, 0);
1188 gui->unlock_window();
1190 zwindow->set_title(title);
1195 int MWindow::mixer_track_active(Track *track)
1197 int i = session->selected_zwindow;
1198 if( i < 0 || i >= zwindows.size() ) return 0;
1199 ZWindow *zwindow = zwindows[i];
1200 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1201 if( !mixer ) return 0;
1202 int n = mixer->mixer_ids.number_of(track->get_mixer_id());
1203 return n >= 0 ? 1 : 0;
1206 void MWindow::update_mixer_tracks()
1208 zwindows_lock->lock("MixPatch::handle_event");
1209 int i = session->selected_zwindow;
1210 if( i >= 0 && i < zwindows.size() ) {
1211 ZWindow *zwindow = zwindows[i];
1212 zwindow->update_mixer_ids();
1214 zwindows_lock->unlock();
1217 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
1218 int use_inout, int update_refresh, int toggle_audio, int loop_play)
1220 zwindows_lock->lock("MWindow::queue_mixers");
1221 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1222 ZWindow *zwindow = zwindows[vidx];
1223 if( zwindow->idx < 0 ) continue;
1224 Mixer *mixer = edl->mixers.get_mixer(zwindow->idx);
1225 if( !mixer || !mixer->mixer_ids.size() ) continue;
1227 for( Track *track = edl->tracks->first; k<0 && track!=0; track=track->next ) {
1228 if( track->data_type != TRACK_VIDEO ) continue;
1229 int mixer_id = track->get_mixer_id();
1230 k = mixer->mixer_ids.size();
1231 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
1233 if( k < 0 ) continue;
1234 EDL *mixer_edl = new EDL(this->edl);
1235 mixer_edl->create_objects();
1236 mixer_edl->copy_all(edl);
1237 mixer_edl->remove_vwindow_edls();
1238 for( Track *track = mixer_edl->tracks->first; track!=0; track=track->next ) {
1239 k = mixer->mixer_ids.size();
1240 while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
1243 track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
1246 track->record = track->play = 0;
1248 zwindow->change_source(mixer_edl);
1249 zwindow->issue_command(command,
1250 wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
1252 zwindows_lock->unlock();
1255 void MWindow::refresh_mixers(int dir)
1257 int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
1258 queue_mixers(edl,command,0,0,1,0,0);
1261 void MWindow::stop_mixers()
1263 for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
1264 ZWindow *zwindow = zwindows[vidx];
1265 if( zwindow->idx < 0 ) continue;
1266 zwindow->issue_command(STOP, 0, 0, 0, 0, 0);
1270 void MWindow::close_mixers()
1272 zwindows_lock->lock("MWindow::close_mixers");
1273 for( int i=0; i<zwindows.size(); ++i ) {
1274 ZWindow *zwindow = zwindows[i];
1275 if( zwindow->idx < 0 ) continue;
1276 ZWindowGUI *zgui = zwindow->zgui;
1277 zgui->lock_window("MWindow::select_zwindow 0");
1279 zgui->unlock_window();
1281 zwindows_lock->unlock();
1282 for( int i=0; i<zwindows.size(); ++i ) {
1283 ZWindow *zwindow = zwindows[i];
1284 if( zwindow->idx < 0 ) continue;
1285 zwindow->close_window();
1289 ZWindow *MWindow::create_mixer(Indexable *indexable)
1291 ArrayList<Indexable*> new_assets;
1292 new_assets.append(indexable);
1293 Track *track = edl->tracks->last;
1294 load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
1295 track = !track ? edl->tracks->first : track->next;
1297 ZWindow *zwindow = get_mixer(mixer);
1299 track->play = track->record = 0;
1300 if( track->data_type == TRACK_VIDEO ) {
1301 sprintf(track->title, _("Mixer %d"), zwindow->idx);
1303 mixer->mixer_ids.append(track->get_mixer_id());
1304 track = track->next;
1306 if( indexable->is_asset ) {
1307 char *path = indexable->path;
1308 char *tp = strrchr(path, '/');
1309 if( !tp ) tp = path; else ++tp;
1310 zwindow->set_title(tp);
1313 char *title = ((EDL*)indexable)->local_session->clip_title;
1314 zwindow->set_title(title);
1319 void MWindow::create_mixers()
1321 if( !session->drag_assets->size() &&
1322 !session->drag_clips->size() ) return;
1323 undo->update_undo_before();
1326 ArrayList<ZWindow *>new_mixers;
1328 for( int i=0; i<session->drag_assets->size(); ++i ) {
1329 Indexable *indexable = session->drag_assets->get(i);
1330 ZWindow *zwindow = create_mixer(indexable);
1331 new_mixers.append(zwindow);
1333 for( int i=0; i<session->drag_clips->size(); ++i ) {
1334 Indexable *indexable = (Indexable*)session->drag_clips->get(i);
1335 ZWindow *zwindow = create_mixer(indexable);
1336 new_mixers.append(zwindow);
1340 for( int i=0; i<new_mixers.size(); ++i )
1341 new_mixers[i]->start();
1345 undo->update_undo_after(_("create mixers"), LOAD_ALL);
1347 gui->update(1, 2, 1, 1, 1, 1, 0);
1348 sync_parameters(CHANGE_ALL);
1351 void MWindow::open_mixers()
1353 for( int i=0; i<edl->mixers.size(); ++i ) {
1354 Mixer *mixer = edl->mixers[i];
1355 ZWindow *zwindow = get_mixer(mixer);
1356 zwindow->set_title(mixer->title);
1362 int MWindow::select_zwindow(ZWindow *zwindow)
1364 int ret = 0, n = zwindows.number_of(zwindow);
1365 if( session->selected_zwindow != n ) {
1366 session->selected_zwindow = n;
1367 for( int i=0; i<zwindows.size(); ++i ) {
1368 ZWindow *zwindow = zwindows[i];
1369 if( zwindow->idx < 0 ) continue;
1370 ZWindowGUI *zgui = zwindow->zgui;
1371 zgui->lock_window("MWindow::select_zwindow 0");
1372 zwindow->highlighted = i == n ? 1 : 0;
1373 if( zgui->draw_overlays() )
1374 zgui->canvas->get_canvas()->flash(1);
1375 zgui->unlock_window();
1378 gui->lock_window("MWindow::select_window 1");
1379 gui->update_mixers(0, -1);
1380 gui->unlock_window();
1385 void MWindow::tile_mixers()
1388 for( int i=0; i<zwindows.size(); ++i ) {
1389 ZWindow *zwindow = zwindows[i];
1390 if( zwindow->idx < 0 ) continue;
1394 int zn = ceil(sqrt(nz));
1395 int x1 = 1 + gui->get_x(), x2 = cwindow->gui->get_x();
1396 int y1 = 1, y2 = gui->get_y();
1397 int rw = gui->get_root_w(0), rh = gui->get_root_h(0);
1398 if( x1 < 0 ) x1 = 0;
1399 if( y1 < 0 ) y1 = 0;
1400 if( x2 > rw ) x2 = rw;
1401 if( y2 > rh ) y2 = rh;
1402 int dx = x2 - x1, dy = y2 - y1;
1404 int lt = BC_DisplayInfo::get_left_border();
1405 int top = BC_DisplayInfo::get_top_border();
1406 int bw = lt + BC_DisplayInfo::get_right_border(); // borders
1407 int bh = top + BC_DisplayInfo::get_bottom_border();
1408 int zx = 0, zy = 0; // window origins
1409 int mw = 10+10, mh = 10+10; // canvas margins
1410 int rsz = 0, n = 0, dz = 0;
1411 int ow = edl->session->output_w, oh = edl->session->output_h;
1412 for( int i=0; i<zwindows.size(); ++i ) {
1413 ZWindow *zwindow = zwindows[i];
1414 if( zwindow->idx < 0 ) continue;
1415 int ww = zw - bw, hh = (ww - mw) * oh / ow + mh, zh = hh + bh;
1416 if( rsz < hh ) rsz = hh;
1417 int xx = zx + x1, yy = zy + y1;
1418 int mx = x2 - zw, my = y2 - zh;
1419 if( xx > mx ) xx = mx;
1420 if( yy > my ) yy = my;
1421 xx += lt + dz; yy += top + dz;
1422 zwindow->reposition(xx,yy, ww,hh);
1423 if( zwindow->running() ) {
1424 ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
1425 gui->lock_window("MWindow::tile_mixers");
1426 gui->BC_WindowBase::reposition_window(xx,yy, ww,hh);
1427 gui->unlock_window();
1431 if( (zy += rsz) > (dy - rsz) ) dz += 10;
1440 void MWindow::init_cache()
1442 audio_cache = new CICache(preferences);
1443 video_cache = new CICache(preferences);
1444 frame_cache = new FrameCache;
1445 wave_cache = new WaveCache;
1448 void MWindow::init_channeldb()
1450 channeldb_buz->load("channeldb_buz");
1451 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1454 void MWindow::init_menus()
1456 char string[BCTEXTLEN];
1459 BC_CModels::to_text(string, BC_RGB888);
1460 colormodels.append(new ColormodelItem(string, BC_RGB888));
1461 BC_CModels::to_text(string, BC_RGBA8888);
1462 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1463 // BC_CModels::to_text(string, BC_RGB161616);
1464 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1465 // BC_CModels::to_text(string, BC_RGBA16161616);
1466 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1467 BC_CModels::to_text(string, BC_RGB_FLOAT);
1468 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1469 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1470 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1471 BC_CModels::to_text(string, BC_YUV888);
1472 colormodels.append(new ColormodelItem(string, BC_YUV888));
1473 BC_CModels::to_text(string, BC_YUVA8888);
1474 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1475 // BC_CModels::to_text(string, BC_YUV161616);
1476 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1477 // BC_CModels::to_text(string, BC_YUVA16161616);
1478 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1480 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1481 interlace_project_modes.append(new InterlacemodeItem(string, x));
1483 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1484 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1486 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1487 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1489 // Interlacing Modes
1490 ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1492 ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
1493 ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
1495 ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1496 ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
1498 ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
1499 ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
1501 // Interlacing Fixing Methods
1502 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
1503 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
1504 ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
1507 void MWindow::init_indexes()
1509 mainindexes = new MainIndexes(this);
1510 mainindexes->start_loop();
1513 void MWindow::init_gui()
1515 gui = new MWindowGUI(this);
1516 gui->lock_window("MWindow::init_gui");
1517 gui->create_objects();
1518 gui->unlock_window();
1519 gui->load_defaults(defaults);
1522 void MWindow::init_signals()
1524 sighandler = new SigHandler;
1525 sighandler->initialize("/tmp/cinelerra_%d.dmp");
1529 void MWindow::init_render()
1531 render = new Render(this);
1532 create_bd = new CreateBD_Thread(this);
1533 create_dvd = new CreateDVD_Thread(this);
1534 batch_render = new BatchRenderThread(this);
1537 void MWindow::init_exportedl()
1539 exportedl = new ExportEDL(this);
1542 void MWindow::init_brender()
1544 if(preferences->use_brender && !brender)
1546 brender_lock->lock("MWindow::init_brender 1");
1547 brender = new BRender(this);
1548 brender->initialize();
1549 session->brender_end = 0;
1550 brender_lock->unlock();
1553 if(!preferences->use_brender && brender)
1555 brender_lock->lock("MWindow::init_brender 2");
1558 session->brender_end = 0;
1559 brender_lock->unlock();
1565 void MWindow::restart_brender()
1567 //printf("MWindow::restart_brender 1\n");
1568 if( !brender_active || !preferences->use_brender ) return;
1569 if( !brender ) return;
1570 brender->restart(edl);
1573 void MWindow::stop_brender()
1575 if( !brender ) return;
1576 // cannot be holding mwindow->gui display lock
1580 int MWindow::brender_available(int position)
1583 brender_lock->lock("MWindow::brender_available 1");
1584 if(brender && brender_active)
1586 if(brender->map_valid)
1588 brender->map_lock->lock("MWindow::brender_available 2");
1589 if(position < brender->map_size &&
1592 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1593 if(brender->map[position] == BRender::RENDERED)
1596 brender->map_lock->unlock();
1599 brender_lock->unlock();
1603 void MWindow::set_brender_active(int v, int update)
1605 if( !preferences->use_brender ) v = 0;
1607 gui->mainmenu->brender_active->set_checked(v);
1609 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1610 edl->session->brender_end = edl->local_session->get_selectionend(1);
1612 if(EQUIV(edl->session->brender_end, edl->session->brender_start)) {
1613 edl->session->brender_end = edl->tracks->total_video_length();
1618 edl->session->brender_start = edl->session->brender_end = 0;
1619 gui->unlock_window();
1621 gui->lock_window("MWindow::set_brender_active");
1624 gui->update_timebar(0);
1625 gui->draw_overlays(1);
1629 int MWindow::has_commercials()
1631 return theme->use_commercials;
1634 void MWindow::init_commercials()
1636 if( !commercials ) {
1637 commercials = new Commercials(this);
1638 commercial_active = 0;
1641 commercials->add_user();
1644 void MWindow::commit_commercial()
1646 if( !commercial_active ) return;
1647 commercial_active = 0;
1648 if( !commercials ) return;
1649 commercials->commitDb();
1652 void MWindow::undo_commercial()
1654 if( !commercial_active ) return;
1655 commercial_active = 0;
1656 if( !commercials ) return;
1657 commercials->undoDb();
1660 int MWindow::put_commercial()
1662 double start = edl->local_session->get_selectionstart();
1663 double end = edl->local_session->get_selectionend();
1664 if( start >= end ) return 0;
1666 const char *errmsg = 0;
1668 Tracks *tracks = edl->tracks;
1671 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1672 if( track->data_type != TRACK_VIDEO ) continue;
1673 if( !track->record ) continue;
1674 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1676 int64_t units_start = track->to_units(start,0);
1677 int64_t units_end = track->to_units(end,0);
1678 Edits *edits = track->edits;
1679 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1680 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1681 if(!edit1 && !edit2) continue; // nothing selected
1682 if(!edit2) { // edit2 beyond end of track
1683 edit2 = edits->last;
1684 units_end = edits->length();
1686 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1687 Indexable *indexable = edit1->get_source();
1688 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1691 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1692 if( track->data_type != TRACK_VIDEO ) continue;
1693 if( !track->record ) continue;
1694 int64_t units_start = track->to_units(start,0);
1695 int64_t units_end = track->to_units(end,0);
1696 Edits *edits = track->edits;
1697 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1698 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1699 if(!edit1 && !edit2) continue; // nothing selected
1700 if(!edit2) { // edit2 beyond end of track
1701 edit2 = edits->last;
1702 units_end = edits->length();
1704 Indexable *indexable = edit1->get_source();
1705 Asset *asset = (Asset *)indexable;
1706 File *file = video_cache->check_out(asset, edl);
1707 if( !file ) { errmsg = _("no file"); break; }
1708 int64_t edit_length = units_end - units_start;
1709 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1710 result = commercials->put_clip(file, edit1->channel,
1711 track->from_units(edit_start), track->from_units(edit_length));
1712 video_cache->check_in(asset);
1713 if( result ) { errmsg = _("db failed"); break; }
1716 char string[BCTEXTLEN];
1717 sprintf(string, _("put_commercial: %s"), errmsg);
1718 MainError::show_error(string);
1725 void MWindow::stop_playback(int wait)
1727 gui->stop_drawing();
1729 cwindow->stop_playback(wait);
1731 for(int i = 0; i < vwindows.size(); i++) {
1732 VWindow *vwindow = vwindows[i];
1733 if( !vwindow->is_running() ) continue;
1734 vwindow->stop_playback(wait);
1736 for(int i = 0; i < zwindows.size(); i++) {
1737 ZWindow *zwindow = zwindows[i];
1738 if( zwindow->idx < 0 ) continue;
1739 zwindow->stop_playback(wait);
1743 void MWindow::stop_transport()
1745 gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
1748 int MWindow::load_filenames(ArrayList<char*> *filenames,
1750 int update_filename)
1752 ArrayList<EDL*> new_edls;
1753 ArrayList<Asset*> new_assets;
1754 ArrayList<File*> new_files;
1755 const int debug = 0;
1756 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1759 gui->start_hourglass();
1761 // Need to stop playback since tracking depends on the EDL not getting
1763 gui->unlock_window();
1765 gui->lock_window("MWindow::load_filenames 0");
1767 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1768 undo->update_undo_before();
1771 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1773 // Define new_edls and new_assets to load
1774 int result = 0, ftype = -1;
1776 for( int i=0; i<filenames->size(); ++i ) {
1778 File *new_file = new File;
1779 Asset *new_asset = new Asset(filenames->get(i));
1780 EDL *new_edl = new EDL;
1781 char string[BCTEXTLEN];
1783 new_edl->create_objects();
1784 new_edl->copy_session(edl);
1785 new_file->set_program(edl->session->program_no);
1787 sprintf(string, _("Loading %s"), new_asset->path);
1788 gui->show_message(string);
1789 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1791 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1792 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1796 // Convert media file to EDL
1798 // Warn about odd image dimensions
1799 if( new_asset->video_data &&
1800 ((new_asset->width % 2) || (new_asset->height % 2)) ) {
1801 char string[BCTEXTLEN];
1802 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1803 new_asset->path, new_asset->width, new_asset->height);
1804 MainError::show_error(string);
1807 if( new_asset->program >= 0 &&
1808 edl->session->program_no != new_asset->program ) {
1809 char string[BCTEXTLEN];
1810 sprintf(string, _("%s's index was built for program number %d\n"
1811 "Playback preference is %d.\n Using program %d."),
1812 new_asset->path, new_asset->program,
1813 edl->session->program_no, new_asset->program);
1814 MainError::show_error(string);
1817 if( load_mode != LOADMODE_RESOURCESONLY ) {
1818 RecordLabels *labels = edl->session->label_cells ?
1819 new RecordLabels(new_file) : 0;
1820 asset_to_edl(new_edl, new_asset, labels);
1821 new_edls.append(new_edl);
1822 new_edl->add_user();
1826 new_assets.append(new_asset);
1827 new_asset->add_user();
1830 // Set filename to nothing for assets since save EDL would overwrite them.
1831 if( load_mode == LOADMODE_REPLACE ||
1832 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1834 // Reset timeline position
1835 for( int i=0; i<TOTAL_PANES; ++i ) {
1836 new_edl->local_session->view_start[i] = 0;
1837 new_edl->local_session->track_start[i] = 0;
1845 case FILE_NOT_FOUND:
1846 sprintf(string, _("Failed to open %s"), new_asset->path);
1847 gui->show_message(string, theme->message_error);
1848 gui->update_default_message();
1852 case FILE_UNRECOGNIZED_CODEC: {
1854 { IndexFile indexfile(this, new_asset);
1855 if( !(result = indexfile.open_index()) )
1856 indexfile.close_index(); }
1858 // Test existing EDLs
1859 for( int j=0; result && j<new_edls.total; ++j ) {
1860 Asset *old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1862 new_asset->copy_from(old_asset,1);
1867 Asset *old_asset = edl->assets->get_asset(new_asset->path);
1869 new_asset->copy_from(old_asset,1);
1876 char string[BCTEXTLEN];
1878 fs.extract_name(string, new_asset->path);
1880 strcat(string, _("'s format couldn't be determined."));
1881 new_asset->audio_data = 1;
1882 new_asset->format = FILE_PCM;
1883 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1884 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1885 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1886 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1887 new_asset->signed_ = defaults->get("SIGNED_", 1);
1888 new_asset->header = defaults->get("HEADER", 0);
1890 FileFormat fwindow(this);
1891 fwindow.create_objects(new_asset, string);
1892 result = fwindow.run_window();
1894 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1895 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1896 defaults->update("AUDIO_BITS", new_asset->bits);
1897 defaults->update("BYTE_ORDER", new_asset->byte_order);
1898 defaults->update("SIGNED_", new_asset->signed_);
1899 defaults->update("HEADER", new_asset->header);
1905 // Recalculate length
1907 new_file = new File;
1908 result = new_file->open_file(preferences, new_asset, 1, 0);
1910 if( load_mode != LOADMODE_RESOURCESONLY ) {
1911 RecordLabels *labels = edl->session->label_cells ?
1912 new RecordLabels(new_file) : 0;
1913 asset_to_edl(new_edl, new_asset, labels);
1914 new_edls.append(new_edl);
1915 new_edl->add_user();
1919 new_assets.append(new_asset);
1920 new_asset->add_user();
1930 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1931 xml_file.read_from_file(filenames->get(i));
1932 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1933 const char *cin_version = 0;
1934 while( !xml_file.read_tag() ) {
1935 if( xml_file.tag.title_is("EDL") ) {
1936 cin_version = xml_file.tag.get_property("VERSION");
1941 if( !cin_version ) {
1942 eprintf(_("XML file %s\n not from cinelerra."),filenames->get(i));
1943 char string[BCTEXTLEN];
1944 sprintf(string,_("Unknown %s"), filenames->get(i));
1945 gui->show_message(string);
1949 if( strcmp(cin_version, CINELERRA_VERSION) ) {
1950 char string[BCTEXTLEN];
1951 snprintf(string, sizeof(string),
1952 _("Warning: XML from cinelerra version %s\n"
1953 "Session data may be incompatible."), cin_version);
1954 show_warning(&preferences->warn_version, string);
1956 if( load_mode == LOADMODE_NESTED ) {
1957 // Load temporary EDL for nesting.
1958 EDL *nested_edl = new EDL;
1959 nested_edl->create_objects();
1960 nested_edl->load_xml(&xml_file, LOAD_ALL);
1961 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1962 new_edl->create_nested(nested_edl);
1963 new_edl->set_path(filenames->get(i));
1964 nested_edl->Garbage::remove_user();
1967 // Load EDL for pasting
1968 new_edl->load_xml(&xml_file, LOAD_ALL);
1969 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1970 test_plugins(new_edl, filenames->get(i));
1971 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1973 if( load_mode == LOADMODE_REPLACE ||
1974 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1975 strcpy(session->filename, filenames->get(i));
1976 strcpy(new_edl->local_session->clip_title,
1979 set_filename(new_edl->local_session->clip_title);
1981 else if( load_mode == LOADMODE_RESOURCESONLY ) {
1982 strcpy(new_edl->local_session->clip_title,
1985 time_t t = !stat(filenames->get(i),&st) ?
1986 st.st_mtime : time(&t);
1987 ctime_r(&t, new_edl->local_session->clip_notes);
1991 new_edls.append(new_edl);
1992 new_edl->add_user();
1997 new_edl->Garbage::remove_user();
1998 new_asset->Garbage::remove_user();
2000 // Store for testing index
2001 new_files.append(new_file);
2004 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2008 gui->reset_default_message();
2009 gui->default_message();
2013 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2016 // Don't back up here.
2019 // For pasting, clear the active region
2020 if(load_mode == LOADMODE_PASTE ||
2021 load_mode == LOADMODE_NESTED)
2023 double start = edl->local_session->get_selectionstart();
2024 double end = edl->local_session->get_selectionend();
2025 if(!EQUIV(start, end))
2028 edl->session->labels_follow_edits,
2029 edl->session->plugins_follow_edits,
2030 edl->session->autos_follow_edits);
2033 paste_edls(&new_edls, load_mode, 0, -1,
2034 edl->session->labels_follow_edits,
2035 edl->session->plugins_follow_edits,
2036 edl->session->autos_follow_edits,
2043 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2045 // Add new assets to EDL and schedule assets for index building.
2046 int got_indexes = 0;
2047 for( int i=0; i<new_edls.size(); ++i ) {
2048 EDL *new_edl = new_edls[i];
2049 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
2050 mainindexes->add_next_asset(0, new_edl->nested_edls[j]);
2051 edl->nested_edls.update_index(new_edl->nested_edls[j]);
2057 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2058 for( int i=0; i<new_assets.size(); ++i ) {
2059 Asset *new_asset = new_assets[i];
2063 for( int j=0; j<new_files.size(); ++j ) {
2064 new_file = new_files[j];
2065 if( !strcmp(new_file->asset->path, new_asset->path) ) {
2071 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
2072 edl->assets->update(new_asset);
2075 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2077 // Start examining next batch of index files
2078 if(got_indexes) mainindexes->start_build();
2079 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2082 Track *track = edl->tracks->first;
2085 for(int j = 0; j < track->plugin_set.size(); j++)
2087 PluginSet *plugins = track->plugin_set[j];
2088 Plugin *plugin = plugins->get_first_plugin();
2092 if(load_mode == LOADMODE_REPLACE ||
2093 load_mode == LOADMODE_REPLACE_CONCATENATE)
2095 if(plugin->plugin_type == PLUGIN_STANDALONE &&
2098 show_plugin(plugin);
2102 plugin = (Plugin*)plugin->next;
2106 track = track->next;
2109 // if just opening one new resource in replace mode
2110 if( ftype != FILE_IS_XML &&
2111 ( load_mode == LOADMODE_REPLACE ||
2112 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
2114 edl->session->proxy_scale = 1;
2115 edl->session->proxy_use_scaler = 0;
2116 edl->session->proxy_auto_scale = 0;
2117 edl->local_session->preview_start = 0;
2118 edl->local_session->preview_end = 0;
2119 edl->local_session->loop_playback = 0;
2120 edl->local_session->set_selectionstart(0);
2121 edl->local_session->set_selectionend(0);
2122 set_brender_active(0, 0);
2127 if( ( edl->session->proxy_auto_scale && edl->session->proxy_scale != 1 ) &&
2128 ( load_mode != LOADMODE_REPLACE && load_mode != LOADMODE_REPLACE_CONCATENATE ) ) {
2129 ArrayList<Indexable *> orig_idxbls;
2130 for( int i=0; i<new_assets.size(); ++i )
2131 orig_idxbls.append(new_assets.get(i));
2132 for( int i=0; i<new_edls.size(); ++i ) {
2133 EDL *new_edl = new_edls[i];
2134 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2135 if( track->data_type != TRACK_VIDEO ) continue;
2136 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2137 Indexable *idxbl = (Indexable *)edit->asset;
2138 if( !idxbl ) continue;
2139 if( !idxbl->have_video() ) continue;
2140 if( edit->channel != 0 ) continue; // first layer only
2141 orig_idxbls.append(edit->asset);
2145 gui->unlock_window(); // to update progress bar
2146 render_proxy(orig_idxbls);
2147 gui->lock_window("MWindow::load_filenames");
2150 // need to update undo before project, since mwindow is unlocked & a new load
2151 // can begin here. Should really prevent loading until we're done.
2152 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2153 undo->update_undo_after(_("load"), LOAD_ALL);
2155 for(int i = 0; i < new_edls.size(); i++)
2157 new_edls[i]->remove_user();
2159 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2161 new_edls.remove_all();
2163 for(int i = 0; i < new_assets.size(); i++)
2165 new_assets[i]->Garbage::remove_user();
2168 new_assets.remove_all();
2169 new_files.remove_all_objects();
2172 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2173 if(load_mode == LOADMODE_REPLACE ||
2174 load_mode == LOADMODE_REPLACE_CONCATENATE)
2176 session->changes_made = 0;
2180 session->changes_made = 1;
2183 gui->stop_hourglass();
2186 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2187 update_project(load_mode);
2189 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
2194 void MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
2196 Asset *format_asset = new Asset;
2197 format_asset->format = FILE_FFMPEG;
2198 format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
2199 ProxyRender proxy_render(this, format_asset);
2200 int new_scale = edl->session->proxy_scale;
2201 int use_scaler = edl->session->proxy_use_scaler;
2203 for( int i=0; i<new_idxbls.size(); ++i ) {
2204 Indexable *orig = new_idxbls.get(i);
2205 Asset *proxy = proxy_render.add_original(orig, new_scale);
2206 if( !proxy ) continue;
2208 int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
2209 int got_it = exists && // if proxy exists, and is newer than orig
2210 fs.get_date(proxy->path) > fs.get_date(orig->path) ? 1 : 0;
2211 if( got_it ) continue;
2212 proxy_render.add_needed(orig, proxy);
2215 // render needed proxies
2216 int result = proxy_render.create_needed_proxies(new_scale);
2218 add_proxy(use_scaler,
2219 &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
2221 format_asset->remove_user();
2224 void MWindow::test_plugins(EDL *new_edl, char *path)
2226 char string[BCTEXTLEN];
2228 // Do a check whether plugins exist
2229 for( Track *track=new_edl->tracks->first; track; track=track->next ) {
2230 for( int k=0; k<track->plugin_set.total; ++k ) {
2231 PluginSet *plugin_set = track->plugin_set[k];
2232 for( Plugin *plugin = (Plugin*)plugin_set->first;
2233 plugin; plugin = (Plugin*)plugin->next ) {
2234 if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
2235 // ok we need to find it in plugindb
2236 PluginServer *server =
2237 scan_plugindb(plugin->title, track->data_type);
2238 if( !server || server->transition ) {
2240 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2241 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2242 "effect", _(plugin->title), path);
2243 MainError::show_error(string);
2248 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2249 if( !edit->transition ) continue;
2250 // ok we need to find transition in plugindb
2251 PluginServer *server =
2252 scan_plugindb(edit->transition->title, track->data_type);
2253 if( !server || !server->transition ) {
2255 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
2256 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
2257 "transition", _(edit->transition->title), path);
2258 MainError::show_error(string);
2265 void MWindow::init_shm(const char *pfn, int64_t min)
2268 // Fix shared memory
2269 FILE *fd = fopen(pfn, "r");
2271 fscanf(fd, "%jd", &result);
2273 if( result >= min ) return;
2276 fd = fopen(pfn, "w");
2278 fprintf(fd, "0x%jx", min);
2281 fd = fopen(pfn, "r");
2283 eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
2287 fscanf(fd, "%jd", &result);
2289 if( result < min ) {
2290 eprintf(_("MWindow::init_shm: %s is %p.\n"
2291 "you probably need to be root, or:\n"
2292 "as root, run: echo 0x%jx > %s\n"
2293 "before trying to start cinelerra.\n"
2294 "It should be at least 0x%jx for Cinelerra.\n"),
2295 pfn, (void *)result, min, pfn, min);
2299 void MWindow::create_objects(int want_gui,
2303 const int debug = 0;
2304 if(debug) PRINT_TRACE
2306 // For some reason, init_signals must come after show_splash or the signals won't
2309 if(debug) PRINT_TRACE
2312 if(debug) PRINT_TRACE
2315 if(debug) PRINT_TRACE
2316 default_standard = default_std();
2317 init_defaults(defaults, config_path);
2321 splash_window->operation->update(_("Initializing Plugins"));
2322 init_plugins(this, preferences);
2323 if(debug) PRINT_TRACE
2324 init_ladspa_plugins(this, preferences);
2325 if(debug) PRINT_TRACE
2326 init_plugin_tips(*plugindb, cin_lang);
2328 splash_window->operation->update(_("Initializing GUI"));
2329 if(debug) PRINT_TRACE
2332 if(debug) PRINT_TRACE
2336 splash_window->operation->update(_("Initializing Fonts"));
2337 char string[BCTEXTLEN];
2338 strcpy(string, preferences->plugin_dir);
2339 strcat(string, "/" FONT_SEARCHPATH);
2340 BC_Resources::init_fontconfig(string);
2341 if(debug) PRINT_TRACE
2343 // Default project created here
2345 if(debug) PRINT_TRACE
2348 if(debug) PRINT_TRACE
2353 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2356 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2358 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
2359 if(session->show_vwindow)
2360 get_viewer(1, DEFAULT_VWINDOW);
2361 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2364 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2367 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2370 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2373 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2376 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2379 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2384 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2385 mainprogress = new MainProgress(this, gui);
2386 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2387 undo = new MainUndo(this);
2389 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2391 plugin_guis = new ArrayList<PluginServer*>;
2392 dead_plugins = new ArrayList<PluginServer*>;
2393 keyframe_threads = new ArrayList<KeyFrameThread*>;
2395 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
2398 session->show_vwindow);
2400 // Show all vwindows
2401 // if(session->show_vwindow) {
2402 // for(int j = 0; j < vwindows.size(); j++) {
2403 // VWindow *vwindow = vwindows[j];
2404 // if( !vwindow->is_running() ) continue;
2405 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
2408 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2409 // vwindow->gui->lock_window("MWindow::create_objects 1");
2410 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2411 // vwindow->gui->show_window();
2412 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2413 // vwindow->gui->unlock_window();
2418 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2420 if(session->show_cwindow)
2422 cwindow->gui->lock_window("MWindow::create_objects 1");
2423 cwindow->gui->show_window();
2424 cwindow->gui->unlock_window();
2427 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2428 if(session->show_awindow)
2430 awindow->gui->lock_window("MWindow::create_objects 1");
2431 awindow->gui->show_window();
2432 awindow->gui->unlock_window();
2435 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
2436 if(session->show_lwindow)
2438 lwindow->gui->lock_window("MWindow::create_objects 1");
2439 lwindow->gui->show_window();
2440 lwindow->gui->unlock_window();
2443 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
2445 (int)timer.get_difference(),
2447 if(session->show_gwindow)
2449 gwindow->gui->lock_window("MWindow::create_objects 1");
2450 gwindow->gui->show_window();
2451 gwindow->gui->unlock_window();
2454 if(debug) PRINT_TRACE
2456 gui->lock_window("MWindow::create_objects 1");
2457 gui->mainmenu->load_defaults(defaults);
2458 gui->mainmenu->update_toggles(0);
2459 gui->update_patchbay();
2460 gui->draw_canvas(0, 0);
2461 gui->draw_cursor(1);
2463 gui->raise_window();
2464 gui->unlock_window();
2466 if(debug) PRINT_TRACE
2468 if(preferences->use_tipwindow)
2470 if(debug) PRINT_TRACE
2472 gui->add_keyboard_listener(
2473 (int (BC_WindowBase::*)(BC_WindowBase *))
2474 &MWindowGUI::keyboard_listener);
2477 init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
2478 init_shm("/proc/sys/kernel/shmmni", 0x4000);
2479 if(debug) PRINT_TRACE
2481 BC_WindowBase::get_resources()->vframe_shm = 1;
2485 void MWindow::show_splash()
2487 #include "data/heroine_logo9_png.h"
2488 VFrame *frame = new VFramePng(heroine_logo9_png);
2489 BC_DisplayInfo dpyi;
2490 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2491 int rr = (rw < rh ? rw : rh) / 4;
2492 splash_window = new SplashGUI(frame, rr, rr);
2493 splash_window->create_objects();
2496 void MWindow::hide_splash()
2499 delete splash_window;
2504 void MWindow::start()
2508 // vwindows[DEFAULT_VWINDOW]->start();
2519 playback_3d->start();
2525 run_lock->lock("MWindow::run");
2529 brender_lock->lock("MWindow::run 1");
2530 delete brender; brender = 0;
2531 brender_lock->unlock();
2533 interrupt_indexes();
2539 void MWindow::show_vwindow()
2541 int total_running = 0;
2542 session->show_vwindow = 1;
2544 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2545 // Raise all windows which are visible
2546 for(int j = 0; j < vwindows.size(); j++) {
2547 VWindow *vwindow = vwindows[j];
2548 if( !vwindow->is_running() ) continue;
2549 vwindow->gui->lock_window("MWindow::show_vwindow");
2550 vwindow->gui->show_window(0);
2551 vwindow->gui->raise_window();
2552 vwindow->gui->flush();
2553 vwindow->gui->unlock_window();
2557 // If no windows visible
2560 get_viewer(1, DEFAULT_VWINDOW);
2563 gui->mainmenu->show_vwindow->set_checked(1);
2566 void MWindow::show_awindow()
2568 session->show_awindow = 1;
2569 awindow->gui->lock_window("MWindow::show_awindow");
2570 awindow->gui->show_window();
2571 awindow->gui->raise_window();
2572 awindow->gui->flush();
2573 awindow->gui->unlock_window();
2574 gui->mainmenu->show_awindow->set_checked(1);
2577 char *MWindow::get_cwindow_display()
2579 char *x11_host = screens < 2 || session->window_config == 0 ?
2580 session->a_x11_host : session->b_x11_host;
2581 return *x11_host ? x11_host : 0;
2584 void MWindow::show_cwindow()
2586 session->show_cwindow = 1;
2587 cwindow->show_window();
2588 gui->mainmenu->show_cwindow->set_checked(1);
2591 void MWindow::show_gwindow()
2593 session->show_gwindow = 1;
2595 gwindow->gui->lock_window("MWindow::show_gwindow");
2596 gwindow->gui->show_window();
2597 gwindow->gui->raise_window();
2598 gwindow->gui->flush();
2599 gwindow->gui->unlock_window();
2601 gui->mainmenu->show_gwindow->set_checked(1);
2603 void MWindow::hide_gwindow()
2605 session->show_gwindow = 0;
2607 gwindow->gui->lock_window("MWindow::show_gwindow");
2608 gwindow->gui->hide_window();
2609 gwindow->gui->unlock_window();
2612 void MWindow::show_lwindow()
2614 session->show_lwindow = 1;
2615 lwindow->gui->lock_window("MWindow::show_lwindow");
2616 lwindow->gui->show_window();
2617 lwindow->gui->raise_window();
2618 lwindow->gui->flush();
2619 lwindow->gui->unlock_window();
2620 gui->mainmenu->show_lwindow->set_checked(1);
2623 int MWindow::tile_windows(int window_config)
2625 int need_reload = 0;
2626 int play_config = window_config==0 ? 0 : 1;
2627 edl->session->playback_config->load_defaults(defaults, play_config);
2628 session->default_window_positions(window_config);
2629 if( screens == 1 ) {
2630 gui->default_positions();
2631 sync_parameters(CHANGE_ALL);
2638 void MWindow::toggle_loop_playback()
2640 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2641 set_loop_boundaries();
2644 gui->draw_overlays(1);
2645 sync_parameters(CHANGE_PARAMS);
2648 //void MWindow::set_titles(int value)
2650 // edl->session->show_titles = value;
2651 // trackmovement(edl->local_session->track_start);
2654 void MWindow::set_screens(int value)
2659 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2661 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2662 edl->session->auto_keyframes = value;
2663 gui->mbuttons->edit_panel->keyframe->update(value);
2665 if(lock_mwindow) gui->unlock_window();
2667 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2668 cwindow->gui->edit_panel->keyframe->update(value);
2669 cwindow->gui->flush();
2670 if(lock_cwindow) cwindow->gui->unlock_window();
2673 void MWindow::set_auto_visibility(Autos *autos, int value)
2675 if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
2676 edl->session->auto_conf->plugins = value;
2677 else if( autos->autoidx >= 0 )
2678 edl->session->auto_conf->autos[autos->autoidx] = value;
2682 gui->update(0, 1, 0, 0, 0, 0, 0);
2683 gui->mainmenu->update_toggles(1);
2684 gui->unlock_window();
2685 gwindow->gui->update_toggles(1);
2686 gui->lock_window("MWindow::set_auto_visibility");
2689 void MWindow::set_keyframe_type(int mode)
2691 gui->lock_window("MWindow::set_keyframe_type");
2692 edl->local_session->floatauto_type = mode;
2693 gui->mainmenu->update_toggles(0);
2694 gui->unlock_window();
2697 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2699 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2700 edl->session->editing_mode = new_editing_mode;
2701 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2702 gui->mbuttons->edit_panel->update();
2703 gui->set_editing_mode(1);
2704 if(lock_mwindow) gui->unlock_window();
2707 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2708 cwindow->gui->edit_panel->update();
2709 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2710 if(lock_cwindow) cwindow->gui->unlock_window();
2714 void MWindow::toggle_editing_mode()
2716 int mode = edl->session->editing_mode;
2717 if( mode == EDITING_ARROW )
2718 set_editing_mode(EDITING_IBEAM, 0, 1);
2720 set_editing_mode(EDITING_ARROW, 0, 1);
2724 void MWindow::set_labels_follow_edits(int value)
2726 gui->lock_window("MWindow::set_labels_follow_edits");
2727 edl->session->labels_follow_edits = value;
2728 gui->mbuttons->edit_panel->locklabels->update(value);
2729 gui->mainmenu->labels_follow_edits->set_checked(value);
2731 gui->unlock_window();
2734 void MWindow::sync_parameters(int change_type)
2736 if( in_destructor ) return;
2738 // Sync engines which are playing back
2739 if(cwindow->playback_engine->is_playing_back)
2741 if(change_type == CHANGE_PARAMS)
2743 // TODO: block keyframes until synchronization is done
2744 cwindow->playback_engine->sync_parameters(edl);
2749 int command = cwindow->playback_engine->command->command;
2750 cwindow->playback_engine->que->send_command(STOP,
2754 // Waiting for tracking to finish would make the restart position more
2755 // accurate but it can't lock the window to stop tracking for some reason.
2756 // Not waiting for tracking gives a faster response but restart position is
2757 // only as accurate as the last tracking update.
2758 cwindow->playback_engine->interrupt_playback(0);
2759 cwindow->playback_engine->que->send_command(command,
2768 cwindow->refresh_frame(change_type);
2772 void MWindow::age_caches()
2774 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2776 // preferences->cache_size,
2777 // audio_cache->get_memory_usage(1),
2778 // video_cache->get_memory_usage(1),
2779 // frame_cache->get_memory_usage(),
2780 // wave_cache->get_memory_usage(),
2782 frame_cache->age_cache(512);
2783 wave_cache->age_cache(8192);
2785 int64_t memory_usage;
2786 int64_t prev_memory_usage = 0;
2788 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2789 while( !result && prev_memory_usage !=
2790 (memory_usage=video_cache->get_memory_usage(1)) &&
2791 memory_usage > video_size ) {
2792 video_cache->delete_oldest();
2793 prev_memory_usage = memory_usage;
2796 prev_memory_usage = 0;
2798 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2799 while( !result && prev_memory_usage !=
2800 (memory_usage=audio_cache->get_memory_usage(1)) &&
2801 memory_usage > audio_size ) {
2802 audio_cache->delete_oldest();
2803 prev_memory_usage = memory_usage;
2807 void MWindow::reset_android_remote()
2809 gui->use_android_remote(preferences->android_remote);
2813 void MWindow::show_keyframe_gui(Plugin *plugin)
2815 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2816 // Find existing thread
2817 for(int i = 0; i < keyframe_threads->size(); i++)
2819 if(keyframe_threads->get(i)->plugin == plugin)
2821 keyframe_threads->get(i)->start_window(plugin, 0);
2822 keyframe_gui_lock->unlock();
2827 // Find unused thread
2828 for(int i = 0; i < keyframe_threads->size(); i++)
2830 if(!keyframe_threads->get(i)->plugin)
2832 keyframe_threads->get(i)->start_window(plugin, 0);
2833 keyframe_gui_lock->unlock();
2838 // Create new thread
2839 KeyFrameThread *thread = new KeyFrameThread(this);
2840 keyframe_threads->append(thread);
2841 thread->start_window(plugin, 0);
2843 keyframe_gui_lock->unlock();
2850 void MWindow::show_plugin(Plugin *plugin)
2855 // Remove previously deleted plugin GUIs
2856 dead_plugin_lock->lock("MWindow::show_plugin");
2857 dead_plugins->remove_all_objects();
2858 dead_plugin_lock->unlock();
2860 //printf("MWindow::show_plugin %d\n", __LINE__);
2864 plugin_gui_lock->lock("MWindow::show_plugin");
2865 for(int i = 0; i < plugin_guis->total; i++)
2867 // Pointer comparison
2868 if(plugin_guis->get(i)->plugin == plugin)
2870 plugin_guis->get(i)->raise_window();
2877 //printf("MWindow::show_plugin 1\n");
2878 if( !done && !plugin->track ) {
2879 printf("MWindow::show_plugin track not defined.\n");
2883 PluginServer *server = scan_plugindb(plugin->title,
2884 plugin->track->data_type);
2886 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2887 if(server && server->uses_gui)
2889 PluginServer *gui = new PluginServer(*server);
2890 plugin_guis->append(gui);
2891 // Needs mwindow to do GUI
2892 gui->set_mwindow(this);
2893 gui->open_plugin(0, preferences, edl, plugin);
2898 plugin_gui_lock->unlock();
2899 //printf("MWindow::show_plugin %d\n", __LINE__);
2902 //printf("MWindow::show_plugin 2\n");
2905 void MWindow::hide_plugin(Plugin *plugin, int lock)
2908 // Update the toggle
2909 gui->lock_window("MWindow::hide_plugin");
2910 gui->update(0, 1, 0, 0, 0, 0, 0);
2911 gui->unlock_window();
2913 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2914 for(int i = 0; i < plugin_guis->total; i++)
2916 if(plugin_guis->get(i)->plugin == plugin)
2918 PluginServer *ptr = plugin_guis->get(i);
2919 plugin_guis->remove(ptr);
2920 if(lock) plugin_gui_lock->unlock();
2921 // Last command executed in client side close
2922 // Schedule for deletion
2929 if(lock) plugin_gui_lock->unlock();
2932 void MWindow::delete_plugin(PluginServer *plugin)
2934 dead_plugin_lock->lock("MWindow::delete_plugin");
2935 dead_plugins->append(plugin);
2936 dead_plugin_lock->unlock();
2939 void MWindow::hide_plugins()
2941 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2942 while(plugin_guis->size())
2944 PluginServer *ptr = plugin_guis->get(0);
2945 plugin_guis->remove(ptr);
2946 plugin_gui_lock->unlock();
2947 // Last command executed in client side close
2948 // Schedule for deletion
2951 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2953 plugin_gui_lock->unlock();
2955 hide_keyframe_guis();
2958 void MWindow::hide_keyframe_guis()
2960 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2961 for(int i = 0; i < keyframe_threads->size(); i++)
2963 keyframe_threads->get(i)->close_window();
2965 keyframe_gui_lock->unlock();
2968 void MWindow::hide_keyframe_gui(Plugin *plugin)
2970 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2971 for(int i = 0; i < keyframe_threads->size(); i++)
2973 if(keyframe_threads->get(i)->plugin == plugin)
2975 keyframe_threads->get(i)->close_window();
2979 keyframe_gui_lock->unlock();
2982 void MWindow::update_keyframe_guis()
2984 // Send new configuration to keyframe GUI's
2985 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2986 for(int i = 0; i < keyframe_threads->size(); i++)
2988 KeyFrameThread *ptr = keyframe_threads->get(i);
2989 if(edl->tracks->plugin_exists(ptr->plugin))
2993 ptr->close_window();
2996 keyframe_gui_lock->unlock();
2999 void MWindow::update_plugin_guis(int do_keyframe_guis)
3001 // Send new configuration to plugin GUI's
3002 plugin_gui_lock->lock("MWindow::update_plugin_guis");
3004 for(int i = 0; i < plugin_guis->size(); i++)
3006 PluginServer *ptr = plugin_guis->get(i);
3007 if(edl->tracks->plugin_exists(ptr->plugin))
3011 // Schedule for deletion if no plugin
3012 plugin_guis->remove_number(i);
3021 // Change plugin variable if not visible
3022 Track *track = edl->tracks->first;
3025 for(int i = 0; i < track->plugin_set.size(); i++)
3027 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
3031 for(int i = 0; i < plugin_guis->size(); i++)
3033 PluginServer *server = plugin_guis->get(i);
3034 if(server->plugin == plugin)
3041 if(!got_it) plugin->show = 0;
3043 plugin = (Plugin*)plugin->next;
3047 track = track->next;
3050 plugin_gui_lock->unlock();
3053 if(do_keyframe_guis) update_keyframe_guis();
3056 int MWindow::plugin_gui_open(Plugin *plugin)
3059 plugin_gui_lock->lock("MWindow::plugin_gui_open");
3060 for(int i = 0; i < plugin_guis->total; i++)
3062 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3068 plugin_gui_lock->unlock();
3072 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
3074 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3075 for(int i = 0; i < plugin_guis->total; i++)
3077 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3079 plugin_guis->get(i)->render_gui(data);
3083 plugin_gui_lock->unlock();
3086 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
3088 plugin_gui_lock->lock("MWindow::render_plugin_gui");
3089 for(int i = 0; i < plugin_guis->total; i++)
3091 if(plugin_guis->get(i)->plugin->identical_location(plugin))
3093 plugin_guis->get(i)->render_gui(data, size);
3097 plugin_gui_lock->unlock();
3101 void MWindow::update_plugin_states()
3103 plugin_gui_lock->lock("MWindow::update_plugin_states");
3104 for(int i = 0; i < plugin_guis->total; i++)
3108 Plugin *src_plugin = plugin_guis->get(i)->plugin;
3109 PluginServer *src_plugingui = plugin_guis->get(i);
3111 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
3112 for(Track *track = edl->tracks->first;
3114 track = track->next)
3117 j < track->plugin_set.total && !result;
3120 PluginSet *plugin_set = track->plugin_set[j];
3121 for(Plugin *plugin = (Plugin*)plugin_set->first;
3123 plugin = (Plugin*)plugin->next)
3125 if(plugin == src_plugin &&
3126 !strcmp(plugin->title, src_plugingui->title)) result = 1;
3132 // Doesn't exist anymore
3135 hide_plugin(src_plugin, 0);
3139 plugin_gui_lock->unlock();
3143 void MWindow::update_plugin_titles()
3145 for(int i = 0; i < plugin_guis->total; i++)
3147 plugin_guis->get(i)->update_title();
3151 int MWindow::asset_to_edl(EDL *new_edl,
3153 RecordLabels *labels)
3155 const int debug = 0;
3156 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
3159 // Keep frame rate, sample rate, and output size unchanged.
3160 // These parameters would revert the project if VWindow displayed an asset
3161 // of different size than the project.
3162 if(new_asset->video_data)
3164 new_edl->session->video_tracks = new_asset->layers;
3167 new_edl->session->video_tracks = 0;
3169 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3175 if(new_asset->audio_data)
3177 new_edl->session->audio_tracks = new_asset->channels;
3180 new_edl->session->audio_tracks = 0;
3181 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3183 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3184 new_edl->create_default_tracks();
3185 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
3186 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3190 //printf("MWindow::asset_to_edl 3\n");
3191 new_edl->insert_asset(new_asset,
3196 //printf("MWindow::asset_to_edl 3\n");
3197 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3199 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
3200 if(edl->session->cursor_on_frames)
3202 double length = new_edl->tracks->total_length();
3203 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
3204 new_edl->tracks->clear(length, edl_length, 1, 1);
3210 char string[BCTEXTLEN];
3212 fs.extract_name(string, new_asset->path);
3213 //printf("MWindow::asset_to_edl 3\n");
3215 strcpy(new_edl->local_session->clip_title, string);
3216 //printf("MWindow::asset_to_edl 4 %s\n", string);
3217 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
3223 // Reset everything after a load.
3224 void MWindow::update_project(int load_mode)
3226 const int debug = 0;
3228 if(debug) PRINT_TRACE
3229 edl->tracks->update_y_pixels(theme);
3231 if(debug) PRINT_TRACE
3233 if(load_mode == LOADMODE_REPLACE ||
3234 load_mode == LOADMODE_REPLACE_CONCATENATE)
3239 gui->update(1, 1, 1, 1, 1, 1, 1);
3240 if(debug) PRINT_TRACE
3241 gui->unlock_window();
3244 cwindow->gui->lock_window("MWindow::update_project 1");
3245 cwindow->update(0, 0, 1, 1, 1);
3246 cwindow->gui->unlock_window();
3248 if(debug) PRINT_TRACE
3250 // Close all the vwindows
3251 if( load_mode == LOADMODE_REPLACE ||
3252 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
3253 if(debug) PRINT_TRACE
3254 int first_vwindow = 0;
3255 if(session->show_vwindow) first_vwindow = 1;
3256 // Change visible windows to no source
3257 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
3258 VWindow *vwindow = vwindows[i];
3259 if( !vwindow->is_running() ) continue;
3260 vwindow->change_source(-1);
3263 // Close remaining windows
3264 for(int i = first_vwindow; i < vwindows.size(); i++) {
3265 VWindow *vwindow = vwindows[i];
3266 if( !vwindow->is_running() ) continue;
3267 vwindow->close_window();
3269 for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
3270 VWindow *vwindow = get_viewer(1, -1);
3271 vwindow->change_source(i);
3273 if(debug) PRINT_TRACE
3277 for( int i=0; i<edl->mixers.size(); ++i ) {
3278 Mixer *mixer = edl->mixers[i];
3279 ZWindow *zwindow = get_mixer(mixer);
3280 zwindow->set_title(mixer->title);
3285 if(vwindows.size()) {
3286 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
3287 if( vwindow->is_running() ) {
3288 vwindow->gui->lock_window("MWindow::update_project");
3290 vwindow->gui->unlock_window();
3295 if(debug) PRINT_TRACE
3296 cwindow->gui->lock_window("MWindow::update_project 2");
3297 cwindow->gui->timebar->update(0);
3298 cwindow->gui->unlock_window();
3300 if(debug) PRINT_TRACE
3301 cwindow->refresh_frame(CHANGE_ALL);
3303 awindow->gui->async_update_assets();
3304 if(debug) PRINT_TRACE
3306 gui->lock_window("MWindow::update_project");
3307 gui->update_mixers(0, 0);
3309 if(debug) PRINT_TRACE
3312 void MWindow::remove_indexfile(Indexable *indexable)
3314 if( !indexable->is_asset ) return;
3315 Asset *asset = (Asset *)indexable;
3317 IndexFile::delete_index(preferences, asset, ".toc");
3318 IndexFile::delete_index(preferences, asset, ".idx");
3319 IndexFile::delete_index(preferences, asset, ".mkr");
3322 void MWindow::rebuild_indices()
3324 for(int i = 0; i < session->drag_assets->total; i++)
3326 Indexable *indexable = session->drag_assets->get(i);
3327 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3328 remove_indexfile(indexable);
3329 // Schedule index build
3330 IndexState *index_state = indexable->index_state;
3331 index_state->index_status = INDEX_NOTTESTED;
3332 if( indexable->is_asset ) {
3333 Asset *asset = (Asset *)indexable;
3334 if( asset->format != FILE_PCM ) {
3335 asset->format = FILE_UNKNOWN;
3336 asset->reset_audio();
3338 asset->reset_video();
3339 remove_asset_from_caches(asset);
3340 // File file; // re-probe the asset
3341 // file.open_file(preferences, asset, 1, 0);
3343 mainindexes->add_next_asset(0, indexable);
3345 mainindexes->start_build();
3349 void MWindow::save_backup()
3353 edl->set_path(session->filename);
3354 char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
3355 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3356 File::get_config_path(), BACKUP_FILE);
3357 snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
3358 File::get_config_path(), BACKUP_FILE1);
3359 rename(backup_path, backup_path1);
3360 edl->save_xml(&file, backup_path);
3361 file.terminate_string();
3363 fs.complete_path(backup_path);
3365 if(file.write_to_file(backup_path))
3368 sprintf(string2, _("Couldn't open %s for writing."), backup_path);
3369 gui->show_message(string2);
3373 void MWindow::load_backup()
3375 ArrayList<char*> path_list;
3376 path_list.set_array_delete();
3378 char backup_path[BCTEXTLEN];
3379 snprintf(backup_path, sizeof(backup_path), "%s/%s",
3380 File::get_config_path(), BACKUP_FILE);
3382 fs.complete_path(backup_path);
3384 path_list.append(out_path = new char[strlen(backup_path) + 1]);
3385 strcpy(out_path, backup_path);
3387 load_filenames(&path_list, LOADMODE_REPLACE, 0);
3388 edl->local_session->clip_title[0] = 0;
3389 // This is unique to backups since the path of the backup is different than the
3390 // path of the project.
3391 set_filename(edl->path);
3392 path_list.remove_all_objects();
3397 void MWindow::save_undo_data()
3399 char perpetual_path[BCTEXTLEN];
3400 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3401 File::get_config_path(), PERPETUAL_FILE);
3402 FILE *fp = fopen(perpetual_path,"w");
3408 void MWindow::load_undo_data()
3410 char perpetual_path[BCTEXTLEN];
3411 snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
3412 File::get_config_path(), PERPETUAL_FILE);
3413 FILE *fp = fopen(perpetual_path,"r");
3419 static inline int gcd(int m, int n)
3422 if( m < n ) { r = m; m = n; n = r; }
3423 while( (r = m % n) != 0 ) { m = n; n = r; }
3427 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
3430 if(!width || !height) return 1;
3431 if( width == 720 && (height == 480 || height == 576) ) {
3432 w = 4; h = 3; return 0; // for NTSC and PAL
3434 double ar = (double)width / height;
3435 // square-ish pixels
3436 if( EQUIV(ar, 1.0000) ) return 0;
3437 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
3438 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
3439 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
3440 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
3441 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
3442 int ww = width, hh = height;
3443 // numerator, denominator must be under mx
3444 int mx = 255, n = gcd(ww, hh);
3445 if( n > 1 ) { ww /= n; hh /= n; }
3446 // search near height in case extra/missing lines
3447 if( ww >= mx || hh >= mx ) {
3448 double err = height; // +/- 2 percent height
3449 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
3450 int iw = width, ih = height+i;
3451 if( (n=gcd(iw, ih)) > 1 ) {
3452 int u = iw/n; if( u >= mx ) continue;
3453 int v = ih/n; if( v >= mx ) continue;
3454 double r = (double) u/v, er = fabs(ar-r);
3455 if( er >= err ) continue;
3456 err = er; ww = u; hh = v;
3465 void MWindow::reset_caches()
3467 frame_cache->remove_all();
3468 wave_cache->remove_all();
3469 audio_cache->remove_all();
3470 video_cache->remove_all();
3471 if( cwindow->playback_engine ) {
3472 if( cwindow->playback_engine->audio_cache )
3473 cwindow->playback_engine->audio_cache->remove_all();
3474 if( cwindow->playback_engine->video_cache )
3475 cwindow->playback_engine->video_cache->remove_all();
3477 for(int i = 0; i < vwindows.size(); i++) {
3478 VWindow *vwindow = vwindows[i];
3479 if( !vwindow->is_running() ) continue;
3480 if( !vwindow->playback_engine ) continue;
3481 if( vwindow->playback_engine->audio_cache )
3482 vwindow->playback_engine->audio_cache->remove_all();
3483 if( vwindow->playback_engine->video_cache )
3484 vwindow->playback_engine->video_cache->remove_all();
3488 void MWindow::remove_asset_from_caches(Asset *asset)
3490 frame_cache->remove_asset(asset);
3491 wave_cache->remove_asset(asset);
3492 audio_cache->delete_entry(asset);
3493 video_cache->delete_entry(asset);
3494 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
3495 cwindow->playback_engine->audio_cache->delete_entry(asset);
3496 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
3497 cwindow->playback_engine->video_cache->delete_entry(asset);
3498 for(int i = 0; i < vwindows.size(); i++) {
3499 VWindow *vwindow = vwindows[i];
3500 if( !vwindow->is_running() ) continue;
3501 if( !vwindow->playback_engine ) continue;
3502 if( vwindow->playback_engine->audio_cache )
3503 vwindow->playback_engine->audio_cache->delete_entry(asset);
3504 if( vwindow->playback_engine->video_cache )
3505 vwindow->playback_engine->video_cache->delete_entry(asset);
3510 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3511 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3513 for(int i = 0; i < drag_assets->total; i++) {
3514 Indexable *indexable = drag_assets->get(i);
3515 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3518 // Remove from VWindow.
3519 for(int i = 0; i < session->drag_clips->total; i++) {
3520 for(int j = 0; j < vwindows.size(); j++) {
3521 VWindow *vwindow = vwindows[j];
3522 if( !vwindow->is_running() ) continue;
3523 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3524 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3525 vwindow->delete_source(1, 1);
3526 vwindow->gui->unlock_window();
3531 for(int i = 0; i < drag_assets->size(); i++) {
3532 for(int j = 0; j < vwindows.size(); j++) {
3533 VWindow *vwindow = vwindows[j];
3534 if( !vwindow->is_running() ) continue;
3535 if(drag_assets->get(i) == vwindow->get_source()) {
3536 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3537 vwindow->delete_source(1, 1);
3538 vwindow->gui->unlock_window();
3543 for(int i = 0; i < drag_assets->size(); i++) {
3544 Indexable *indexable = drag_assets->get(i);
3545 remove_indexfile(indexable);
3548 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3549 if(push_undo) undo->update_undo_before();
3550 if(drag_assets) edl->remove_from_project(drag_assets);
3551 if(drag_clips) edl->remove_from_project(drag_clips);
3552 if(redraw) save_backup();
3553 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3557 gui->lock_window("MWindow::remove_assets_from_project 3");
3558 gui->update(1, 1, 1, 1, 0, 1, 0);
3559 gui->unlock_window();
3561 // Removes from playback here
3562 sync_parameters(CHANGE_ALL);
3565 awindow->gui->async_update_assets();
3568 void MWindow::remove_assets_from_disk()
3571 for(int i = 0; i < session->drag_assets->total; i++)
3573 remove(session->drag_assets->get(i)->path);
3576 remove_assets_from_project(1,
3578 session->drag_assets,
3579 session->drag_clips);
3582 void MWindow::dump_plugins(FILE *fp)
3584 if( !plugindb ) return;
3585 for(int i = 0; i < plugindb->total; i++)
3587 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3588 " synth=%d transition=%d theme=%d %s\n",
3589 plugindb->get(i)->plugin_type,
3590 plugindb->get(i)->audio,
3591 plugindb->get(i)->video,
3592 plugindb->get(i)->realtime,
3593 plugindb->get(i)->multichannel,
3594 plugindb->get(i)->get_synthesis(),
3595 plugindb->get(i)->transition,
3596 plugindb->get(i)->theme,
3597 plugindb->get(i)->title);
3601 void MWindow::dump_edl(FILE *fp)
3607 void MWindow::dump_undo(FILE *fp)
3613 void MWindow::dump_exe(FILE *fp)
3615 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3616 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3618 int ret = -1, n = 100;
3619 for( int len; (len=readlink(proc_path, exe_path, sizeof(exe_path)))>0; --n ) {
3620 exe_path[len] = 0; strcpy(proc_path, exe_path);
3623 if( n < 0 || ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3626 if( stat(proc_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3627 fprintf(fp, "path: %s = %9jd bytes\n",proc_path,st.st_size);
3628 struct tm *tm = localtime(&st.st_mtime);
3630 strftime(mtime, sizeof(mtime), "%F %T", tm);
3631 fprintf(fp,"mtime: %s\n", mtime);
3633 // people hit ctl-c waiting for this
3634 int fd = open(proc_path,O_RDONLY+O_NONBLOCK);
3635 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3638 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3639 int64_t maxsz = 1024*pagsz;
3640 int64_t size = st.st_size, pos = 0;
3642 while( (bfrsz = size-pos) > 0 ) {
3643 if( bfrsz > maxsz ) bfrsz = maxsz;
3644 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3645 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3646 if( bfr == MAP_FAILED ) break;
3647 sha1.addBytes(bfr, bfrsz);
3652 ret = pos < size ? EIO : 0;
3653 fprintf(fp, "SHA1: ");
3654 uint8_t digest[20]; sha1.computeHash(digest);
3655 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3656 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3657 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3662 void MWindow::trap_hook(FILE *fp, void *vp)
3664 MWindow *mwindow = (MWindow *)vp;
3665 // fprintf(fp, "\nPLUGINS:\n");
3666 // mwindow->dump_plugins(fp);
3667 fprintf(fp, "\nEDL:\n");
3668 mwindow->dump_edl(fp);
3669 fprintf(fp, "\nUNDO:\n");
3670 mwindow->dump_undo(fp);
3671 fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
3672 mwindow->dump_exe(fp);
3680 int MWindow::save_defaults()
3682 gui->save_defaults(defaults);
3683 edl->save_defaults(defaults);
3684 session->save_defaults(defaults);
3685 preferences->save_defaults(defaults);
3687 for(int i = 0; i < plugin_guis->total; i++)
3689 // Pointer comparison
3690 plugin_guis->get(i)->save_defaults();
3692 awindow->save_defaults(defaults);
3698 int MWindow::run_script(FileXML *script)
3700 int result = 0, result2 = 0;
3701 while(!result && !result2)
3703 result = script->read_tag();
3706 if(script->tag.title_is("new_project"))
3708 // Run new in immediate mode.
3709 // gui->mainmenu->new_project->run_script(script);
3712 if(script->tag.title_is("record"))
3714 // Run record as a thread. It is a terminal command.
3716 // Will read the complete scipt file without letting record read it if not
3722 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3729 // ================================= synchronization
3732 int MWindow::interrupt_indexes()
3734 mainprogress->cancelled = 1;
3735 mainindexes->interrupt_build();
3741 void MWindow::next_time_format()
3743 switch(edl->session->time_format)
3745 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3746 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3747 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3748 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3749 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3750 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3751 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3754 time_format_common();
3757 void MWindow::prev_time_format()
3759 switch(edl->session->time_format)
3761 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3762 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3763 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3764 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3765 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3766 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3767 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3770 time_format_common();
3773 void MWindow::time_format_common()
3775 gui->lock_window("MWindow::next_time_format");
3776 gui->redraw_time_dependancies();
3779 char string[BCTEXTLEN], string2[BCTEXTLEN];
3780 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3781 gui->show_message(string);
3783 gui->unlock_window();
3787 int MWindow::set_filename(const char *filename)
3789 if( filename != session->filename )
3790 strcpy(session->filename, filename);
3791 if( filename != edl->path )
3792 strcpy(edl->path, filename);
3796 if(filename[0] == 0)
3798 gui->set_title(PROGRAM_NAME);
3803 char string[BCTEXTLEN], string2[BCTEXTLEN];
3804 dir.extract_name(string, filename);
3805 sprintf(string2, PROGRAM_NAME ": %s", string);
3806 gui->set_title(string2);
3819 int MWindow::set_loop_boundaries()
3821 double start = edl->local_session->get_selectionstart();
3822 double end = edl->local_session->get_selectionend();
3830 if(edl->tracks->total_length())
3833 end = edl->tracks->total_length();
3840 if(edl->local_session->loop_playback && start != end)
3842 edl->local_session->loop_start = start;
3843 edl->local_session->loop_end = end;
3854 int MWindow::reset_meters()
3856 cwindow->gui->lock_window("MWindow::reset_meters 1");
3857 cwindow->gui->meters->reset_meters();
3858 cwindow->gui->unlock_window();
3860 for(int j = 0; j < vwindows.size(); j++) {
3861 VWindow *vwindow = vwindows[j];
3862 if( !vwindow->is_running() ) continue;
3863 vwindow->gui->lock_window("MWindow::reset_meters 2");
3864 vwindow->gui->meters->reset_meters();
3865 vwindow->gui->unlock_window();
3868 lwindow->gui->lock_window("MWindow::reset_meters 3");
3869 lwindow->gui->panel->reset_meters();
3870 lwindow->gui->unlock_window();
3872 gui->lock_window("MWindow::reset_meters 4");
3873 gui->reset_meters();
3874 gui->unlock_window();
3879 void MWindow::resync_guis()
3883 gui->lock_window("MWindow::resync_guis");
3884 gui->update(1, 1, 1, 1, 1, 1, 0);
3885 gui->unlock_window();
3887 cwindow->gui->lock_window("MWindow::resync_guis");
3888 cwindow->gui->resize_event(cwindow->gui->get_w(),
3889 cwindow->gui->get_h());
3890 int channels = edl->session->audio_channels;
3891 cwindow->gui->meters->set_meters(channels, 1);
3892 cwindow->gui->flush();
3893 cwindow->gui->unlock_window();
3895 for(int i = 0; i < vwindows.size(); i++) {
3896 VWindow *vwindow = vwindows[i];
3897 if( !vwindow->is_running() ) continue;
3898 vwindow->gui->lock_window("MWindow::resync_guis");
3899 vwindow->gui->resize_event(vwindow->gui->get_w(),
3900 vwindow->gui->get_h());
3901 vwindow->gui->meters->set_meters(channels, 1);
3902 vwindow->gui->flush();
3903 vwindow->gui->unlock_window();
3906 lwindow->gui->lock_window("MWindow::resync_guis");
3907 lwindow->gui->panel->set_meters(channels, 1);
3908 lwindow->gui->flush();
3909 lwindow->gui->unlock_window();
3912 if(((edl->session->output_w % 4) ||
3913 (edl->session->output_h % 4)) &&
3914 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3916 MainError::show_error(
3917 _("This project's dimensions are not multiples of 4 so\n"
3918 "it can't be rendered by OpenGL."));
3923 sync_parameters(CHANGE_ALL);
3926 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3928 File *file = new File;
3929 EDLSession *session = edl->session;
3930 double old_framerate = session->frame_rate;
3931 double old_samplerate = session->sample_rate;
3932 int old_auto_keyframes = session->auto_keyframes;
3933 session->auto_keyframes = 0;
3934 int result = file->open_file(preferences, asset, 1, 0);
3935 if( !result && delete_tracks > 0 )
3936 undo->update_undo_before();
3937 int video_layers = asset->get_video_layers();
3938 if( !result && asset->video_data && vstream < video_layers ) {
3939 // try to get asset up to date, may fail
3940 file->select_video_stream(asset, vstream);
3941 // either way use what was/is there.
3942 double framerate = asset->get_frame_rate();
3943 int width = asset->get_w();
3944 int height = asset->get_h();
3945 // must be multiple of 4 for opengl
3946 width = (width+3) & ~3; height = (height+3) & ~3;
3947 int driver = session->playback_config->vconfig->driver;
3948 int color_model = file->get_best_colormodel(asset, driver);
3949 // color_model = BC_CModels::is_yuv(color_model) ?
3950 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3951 // BC_CModels::is_float(color_model) ?
3952 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3953 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3954 // have alpha for now
3955 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3956 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3957 session->color_model = color_model;
3958 session->output_w = width;
3959 session->output_h = height;
3960 session->frame_rate = framerate;
3961 // not, asset->actual_width/actual_height
3962 asset->width = session->output_w;
3963 asset->height = session->output_h;
3964 asset->frame_rate = session->frame_rate;
3965 create_aspect_ratio(session->aspect_w, session->aspect_h,
3966 session->output_w, session->output_h);
3967 Track *track = edl->tracks->first;
3968 for( Track *next_track=0; track; track=next_track ) {
3969 next_track = track->next;
3970 if( track->data_type != TRACK_VIDEO ) continue;
3971 if( delete_tracks ) {
3972 Edit *edit = track->edits->first;
3973 for( Edit *next_edit=0; edit; edit=next_edit ) {
3974 next_edit = edit->next;
3975 if( edit->channel != vstream ||
3976 !edit->asset || !edit->asset->is_asset ||
3977 !asset->equivalent(*edit->asset,1,1,edl) )
3981 if( track->edits->first ) {
3982 track->track_w = edl->session->output_w;
3983 track->track_h = edl->session->output_h;
3985 else if( delete_tracks )
3986 edl->tracks->delete_track(track);
3989 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3991 if( !result && asset->audio_data && asset->channels > 0 ) {
3992 session->sample_rate = asset->get_sample_rate();
3993 int64_t channel_mask = 0;
3994 int astrm = !asset->video_data || vstream >= video_layers ? -1 :
3995 file->get_audio_for_video(vstream, astream, channel_mask);
3996 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3997 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3999 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
4000 if( channels < 1 ) channels = 1;
4001 if( channels > 6 ) channels = 6;
4002 session->audio_tracks = session->audio_channels = channels;
4004 int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
4005 memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
4006 remap_audio(MWindow::AUDIO_1_TO_1);
4008 if( delete_tracks ) {
4009 Track *track = edl->tracks->first;
4010 for( Track *next_track=0; track; track=next_track ) {
4011 next_track = track->next;
4012 if( track->data_type != TRACK_AUDIO ) continue;
4013 Edit *edit = track->edits->first;
4014 for( Edit *next_edit=0; edit; edit=next_edit ) {
4015 next_edit = edit->next;
4016 if( !((1<<edit->channel) & channel_mask) ||
4017 !edit->asset || !edit->asset->is_asset ||
4018 !asset->equivalent(*edit->asset,1,1,edl) )
4021 if( !track->edits->first )
4022 edl->tracks->delete_track(track);
4026 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
4029 session->auto_keyframes = old_auto_keyframes;
4030 if( !result && delete_tracks > 0 ) {
4032 undo->update_undo_after(_("select asset"), LOAD_ALL);
4038 int MWindow::select_asset(int vtrack, int delete_tracks)
4040 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
4042 track = edl->tracks->get(vtrack, TRACK_AUDIO);
4043 if( !track ) return 1;
4044 Edit *edit = track->edits->first;
4045 if( !edit ) return 1;
4046 Asset *asset = edit->asset;
4047 if( !asset || !asset->is_asset ) return 1;
4048 return select_asset(asset, edit->channel, 0, delete_tracks);
4051 void MWindow::dump_plugindb(FILE *fp)
4053 if( !plugindb ) return;
4054 for(int i = 0; i < plugindb->total; i++)
4055 plugindb->get(i)->dump(fp);
4058 FloatAuto* MWindow::get_float_auto(PatchGUI *patch,int idx)
4061 double unit_position = edl->local_session->get_selectionstart(1);
4062 unit_position = patch->track->to_units(unit_position, 0);
4064 FloatAutos *ptr = (FloatAutos*)patch->track->automation->autos[idx];
4065 return (FloatAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4068 IntAuto* MWindow::get_int_auto(PatchGUI *patch,int idx)
4071 double unit_position = edl->local_session->get_selectionstart(1);
4072 unit_position = patch->track->to_units(unit_position, 0);
4074 IntAutos *ptr = (IntAutos*)patch->track->automation->autos[idx];
4075 return (IntAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4078 PanAuto* MWindow::get_pan_auto(PatchGUI *patch)
4081 double unit_position = edl->local_session->get_selectionstart(1);
4082 unit_position = patch->track->to_units(unit_position, 0);
4084 PanAutos *ptr = (PanAutos*)patch->track->automation->autos[AUTOMATION_PAN];
4085 return (PanAuto*)ptr->get_prev_auto( (long)unit_position, PLAY_FORWARD, current);
4088 PatchGUI *MWindow::get_patchgui(Track *track)
4090 PatchGUI *patchgui = 0;
4091 TimelinePane **panes = gui->pane;
4092 for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
4093 if( !panes[i] ) continue;
4094 PatchBay *patchbay = panes[i]->patchbay;
4095 if( !patchbay ) continue;
4096 for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
4097 if( patchbay->patches.values[j]->track == track )
4098 patchgui = patchbay->patches.values[j];