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
23 #include "audioalsa.h"
24 #include "awindowgui.h"
26 #include "batchrender.h"
27 #include "bcdisplayinfo.h"
28 #include "bcsignals.h"
34 #include "channeldb.h"
35 #include "channelinfo.h"
37 #include "bccmodels.h"
38 #include "commercials.h"
39 #include "cplayback.h"
41 #include "cwindowgui.h"
43 #include "cwindowtool.h"
45 #include "devicedvbinput.inc"
46 #include "dvdcreate.h"
47 #include "editpanel.h"
49 #include "edlsession.h"
51 #include "fileformat.h"
53 #include "filesystem.h"
55 #include "framecache.h"
57 #include "gwindowgui.h"
58 #include "keyframegui.h"
59 #include "indexfile.h"
60 #include "interlacemodes.h"
62 #include "levelwindowgui.h"
63 #include "levelwindow.h"
64 #include "loadfile.inc"
65 #include "localsession.h"
66 #include "maincursor.h"
67 #include "mainerror.h"
68 #include "mainindexes.h"
70 #include "mainprogress.h"
71 #include "mainsession.h"
75 #include "mwindowgui.h"
77 #include "nestededls.h"
80 #include "playback3d.h"
81 #include "playbackengine.h"
83 #include "pluginserver.h"
84 #include "pluginset.h"
85 #include "preferences.h"
87 #include "recordmonitor.h"
88 #include "recordlabel.h"
89 #include "removefile.h"
91 #include "resourcethread.h"
92 #include "samplescroll.h"
94 #include "sighandler.h"
95 #include "splashgui.h"
96 #include "statusbar.h"
98 #include "threadloader.h"
100 #include "tipwindow.h"
101 #include "trackcanvas.h"
103 #include "tracking.h"
104 #include "trackscroll.h"
106 #include "transition.h"
107 #include "transportque.h"
109 #include "videodevice.inc"
110 #include "videowindow.h"
111 #include "vplayback.h"
112 #include "vwindowgui.h"
114 #include "wavecache.h"
117 #include "exportedl.h"
119 #include "defaultformats.h"
120 #include "ntsczones.h"
122 #include <sys/types.h>
123 #include <sys/stat.h>
126 #include <sys/stat.h>
135 // Hack for libdv to remove glib dependancy
138 // g_log (const char *log_domain,
140 // const char *format,
146 // g_logv (const char *log_domain,
148 // const char *format,
158 ArrayList<PluginServer*>* MWindow::plugindb = 0;
159 Commercials* MWindow::commercials = 0;
165 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
166 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
167 vwindows_lock = new Mutex("MWindow::vwindows_lock");
168 brender_lock = new Mutex("MWindow::brender_lock");
169 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
177 commercial_active = 0;
188 channeldb_buz = new ChannelDB;
189 channeldb_v4l2jpeg = new ChannelDB;
193 keyframe_threads = 0;
213 // Need to delete brender temporary here.
219 //printf("MWindow::~MWindow %d\n", __LINE__);
221 gui->remote_control->deactivate();
224 gui->channel_info->stop();
226 brender_lock->lock("MWindow::quit");
227 delete brender; brender = 0;
228 brender_lock->unlock();
229 delete create_bd; create_bd = 0;
230 delete create_dvd; create_dvd = 0;
231 delete batch_render; batch_render = 0;
233 if( commercials && !commercials->remove_user() ) commercials = 0;
235 // Save defaults for open plugins
236 plugin_gui_lock->lock("MWindow::~MWindow");
237 for(int i = 0; i < plugin_guis->size(); i++) {
238 plugin_guis->get(i)->hide_gui();
239 delete_plugin(plugin_guis->get(i));
241 plugin_gui_lock->unlock();
242 hide_keyframe_guis();
245 // Give up and go to a movie
246 // cant run valgrind if this is used
248 gui->del_keyboard_listener(
249 (int (BC_WindowBase::*)(BC_WindowBase *))
250 &MWindowGUI::keyboard_listener);
252 // release the hounds
253 if( awindow && awindow->gui ) awindow->gui->close(0);
254 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
255 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
256 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
257 if( twindow && twindow->is_running() ) twindow->close_window();
258 if( wwindow && wwindow->is_running() ) wwindow->close_window();
259 vwindows.remove_all_objects();
261 if( awindow ) awindow->join();
262 if( cwindow ) cwindow->join();
263 if( lwindow ) lwindow->join();
264 if( twindow ) twindow->join();
265 if( wwindow ) wwindow->join();
266 if( gwindow ) gwindow->join();
269 // one at a time, or nouveau chokes
270 #define close_gui(win) if( win ) { \
271 if( win->gui ) win->gui->close(0); \
279 vwindows.remove_all_objects();
284 dead_plugins->remove_all_objects();
287 keyframe_threads->remove_all_objects();
288 colormodels.remove_all_objects();
290 delete render; render = 0;
291 delete awindow; awindow = 0;
292 delete lwindow; lwindow = 0;
293 delete twindow; twindow = 0;
294 delete wwindow; wwindow = 0;
295 delete gwindow; gwindow = 0;
296 // must be last or nouveau chokes
297 delete cwindow; cwindow = 0;
298 //delete file_server; file_server = 0; // reusable
299 delete mainindexes; mainindexes = 0;
300 delete mainprogress; mainprogress = 0;
301 delete audio_cache; audio_cache = 0; // delete the cache after the assets
302 delete video_cache; video_cache = 0; // delete the cache after the assets
303 delete frame_cache; frame_cache = 0;
304 delete wave_cache; wave_cache = 0;
305 delete plugin_guis; plugin_guis = 0;
306 delete dead_plugins; dead_plugins = 0;
307 delete keyframe_threads; keyframe_threads = 0;
308 delete undo; undo = 0;
309 delete preferences; preferences = 0;
310 delete exportedl; exportedl = 0;
311 delete session; session = 0;
312 delete defaults; defaults = 0;
313 delete assets; assets = 0;
314 delete splash_window; splash_window = 0;
315 // delete theme; theme = 0; // deleted by delete_plugins
316 if( !edl->Garbage::remove_user() ) edl = 0;
317 delete channeldb_buz;
318 delete channeldb_v4l2jpeg;
319 // This must be last thread to exit
320 delete playback_3d; playback_3d = 0;
321 delete dead_plugin_lock;
322 delete plugin_gui_lock;
323 delete vwindows_lock;
325 delete keyframe_gui_lock;
326 colormodels.remove_all_objects();
327 interlace_project_modes.remove_all_objects();
328 interlace_asset_modes.remove_all_objects();
329 interlace_asset_fixmethods.remove_all_objects();
330 sighandler->terminate();
335 void MWindow::quit(int unlock)
338 if(unlock) gui->unlock_window();
340 brender_lock->lock("MWindow::quit");
341 delete brender; brender = 0;
342 brender_lock->unlock();
348 if(unlock) gui->lock_window("MWindow::quit");
351 void MWindow::init_error()
353 MainError::init_error(this);
356 void MWindow::finit_error()
358 MainError::finit_error();
361 void MWindow::create_defaults_path(char *string, const char *config_file)
363 // set the .bcast path
366 sprintf(string, "%s", BCASTDIR);
367 fs.complete_path(string);
368 if(!fs.is_dir(string))
369 fs.create_dir(string);
372 strcat(string, config_file);
374 const char *MWindow::default_std()
380 if((fd = open(TIMEZONE_NAME, O_RDONLY)) >= 0)
382 l = read(fd, buf, BCTEXTLEN);
387 if(buf[l - 1] == '\n')
394 if((l = readlink(LOCALTIME_LINK, buf, BCTEXTLEN)) > 0)
397 if( (p=strstr(buf, ZONEINFO_STR)) != 0 )
399 p += strlen(ZONEINFO_STR);
408 for(i = 0; ntsc_zones[i]; i++)
409 if(strcmp(ntsc_zones[i], p) == 0)
415 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
417 struct formatpresets *fpr;
419 for(fpr = &format_presets[0]; fpr->name; fpr++)
421 if(strcmp(fpr->name, preset) == 0)
423 session->audio_channels = fpr->audio_channels;
424 session->audio_tracks = fpr->audio_tracks;
425 session->sample_rate = fpr->sample_rate;
426 session->video_channels = fpr->video_channels;
427 session->video_tracks = fpr->video_tracks;
428 session->frame_rate = fpr->frame_rate;
429 session->output_w = fpr->output_w;
430 session->output_h = fpr->output_h;
431 session->aspect_w = fpr->aspect_w;
432 session->aspect_h = fpr->aspect_h;
433 session->interlace_mode = fpr->interlace_mode;
434 session->color_model = fpr->color_model;
440 const char *MWindow::get_preset_name(int index)
442 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
444 return format_presets[index].name;
448 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
450 char path[BCTEXTLEN];
451 // Use user supplied path
453 strcpy(path, config_path);
455 create_defaults_path(path, CONFIG_FILE);
457 defaults = new BC_Hash(path);
461 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
463 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
465 const char *dp = plug_dir;
466 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
467 bp = !*dp && *bp == '/' ? bp+1 : base_path;
473 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
476 FILE *fp = fopen(index_path, "r");
480 char index_line[BCTEXTLEN];
481 int index_version = -1, len = strlen(plugin_dir);
482 if( !fgets(index_line, BCTEXTLEN, fp) ||
483 sscanf(index_line, "%d", &index_version) != 1 ||
484 index_version != PLUGIN_FILE_VERSION ||
485 !fgets(index_line, BCTEXTLEN, fp) ||
486 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
487 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
489 ArrayList<PluginServer*> plugins;
490 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
491 if( index_line[0] == ';' ) continue;
492 if( index_line[0] == '#' ) continue;
493 int type = PLUGIN_TYPE_UNKNOWN;
494 char path[BCTEXTLEN], title[BCTEXTLEN];
496 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
499 PluginServer *server = 0;
501 case PLUGIN_TYPE_BUILTIN:
502 case PLUGIN_TYPE_EXECUTABLE:
503 case PLUGIN_TYPE_LADSPA: {
504 char plugin_path[BCTEXTLEN]; struct stat st;
505 sprintf(plugin_path, "%s/%s", plugin_dir, path);
506 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
509 server = new PluginServer(mwindow, plugin_path, type);
511 case PLUGIN_TYPE_FFMPEG: {
512 server = new_ffmpeg_server(mwindow, path);
515 if( !server ) continue;
516 plugins.append(server);
517 // Create plugin server from index entry
518 server->set_title(title);
519 if( server->read_table(index_line) ) {
526 ret = check_plugin_index(plugins, plugin_dir, ".");
529 add_plugins(plugins);
531 plugins.remove_all_objects();
536 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
537 const char *plug_dir, const char *plug_path)
539 char plugin_path[BCTEXTLEN];
540 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
542 fs.set_filter( "[*.plugin][*.so]" );
543 if( fs.update(plugin_path) )
546 for( int i=0; i<fs.dir_list.total; ++i ) {
547 char fs_path[BCTEXTLEN];
548 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
549 if( fs.is_dir(fs_path) ) {
550 get_plugin_path(plugin_path, plug_dir, fs_path);
551 if( check_plugin_index(plugins, plug_dir, plugin_path) )
554 else if( !plugin_exists(fs_path, plugins) )
561 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
564 plugindb = new ArrayList<PluginServer*>;
566 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
567 create_defaults_path(index_path, PLUGIN_FILE);
568 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
569 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
570 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
571 printf("init plugin index: %s\n", plugin_path);
572 FILE *fp = fopen(index_path,"w");
574 fprintf(stderr,_("MWindow::init_plugins: "
575 "can't create plugin index: %s\n"), index_path);
578 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
579 fprintf(fp, "%s\n", plugin_path);
580 init_plugin_index(mwindow, preferences, fp, plugin_path);
581 init_ffmpeg_index(mwindow, preferences, fp);
583 return load_plugin_index(mwindow, index_path, plugin_path);
586 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
588 char *path = getenv("LADSPA_PATH");
589 char ladspa_path[BCTEXTLEN];
591 get_exe_path(ladspa_path);
592 strcat(ladspa_path, "/ladspa");
595 for( int len=0; *path; path+=len ) {
596 char *cp = strchr(path,':');
597 len = !cp ? strlen(path) : cp-path;
598 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
599 memcpy(plugin_path, path, len); plugin_path[len] = 0;
600 char *plugin_dir = FileSystem::basepath(plugin_path);
601 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
602 create_defaults_path(index_path, LADSPA_FILE);
603 cp = index_path + strlen(index_path);
604 for( char *bp=plugin_path; *bp!=0; ++bp )
605 *cp++ = *bp=='/' ? '_' : *bp;
607 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
608 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
609 load_plugin_index(mwindow, index_path, plugin_path);
614 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
615 FILE *fp, const char *plugin_dir)
617 int idx = PLUGIN_IDS;
619 for( int i=0; i<plugindb->size(); ++i ) {
620 PluginServer *server = plugindb->get(i);
621 if( server->dir_idx >= idx )
622 idx = server->dir_idx+1;
625 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
628 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
629 const char *index_path, const char *plugin_dir)
631 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
632 strcpy(plugin_path, path); delete [] path;
633 printf("init ladspa index: %s\n", plugin_dir);
634 FILE *fp = fopen(index_path,"w");
636 fprintf(stderr,_("MWindow::init_ladspa_index: "
637 "can't create plugin index: %s\n"), index_path);
640 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
641 fprintf(fp, "%s\n", plugin_dir);
642 init_plugin_index(mwindow, preferences, fp, plugin_path);
647 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
648 const char *plug_dir, const char *plug_path, int &idx)
650 char plugin_path[BCTEXTLEN];
651 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
653 fs.set_filter( "[*.plugin][*.so]" );
654 int result = fs.update(plugin_path);
655 if( result || !fs.dir_list.total ) return;
658 for( int i=0; i<fs.dir_list.total; ++i ) {
659 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
660 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
661 get_plugin_path(path, plug_dir, fs_path);
662 if( fs.is_dir(fs_path) ) {
663 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
666 if( plugin_exists(path) ) continue;
668 if( stat(fs_path, &st) ) continue;
669 int64_t mtime = st.st_mtime;
670 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
671 result = server.open_plugin(1, preferences, 0, 0);
673 server.write_table(fp, path, vis_id, mtime);
674 server.close_plugin();
676 else if( result == PLUGINSERVER_IS_LAD ) {
679 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
680 ladspa.set_lad_index(lad_index++);
681 result = ladspa.open_plugin(1, preferences, 0, 0);
683 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
684 ladspa.close_plugin();
690 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
692 for( int i=0; i<plugins.size(); ++i )
693 plugindb->append(plugins[i]);
694 plugins.remove_all();
697 void MWindow::delete_plugins()
699 plugindb->remove_all_objects();
704 void MWindow::search_plugindb(int do_audio,
709 ArrayList<PluginServer*> &results)
712 for(int i = 0; i < MWindow::plugindb->total; i++)
714 PluginServer *current = MWindow::plugindb->get(i);
716 if(current->audio == do_audio &&
717 current->video == do_video &&
718 (current->realtime == is_realtime || is_realtime < 0) &&
719 current->transition == is_transition &&
720 current->theme == is_theme)
721 results.append(current);
724 // Alphabetize list by title
730 for(int i = 0; i < results.total - 1; i++)
732 PluginServer *value1 = results[i];
733 PluginServer *value2 = results[i + 1];
734 if(strcmp(_(value1->title), _(value2->title)) > 0)
738 results[i + 1] = value1;
744 PluginServer* MWindow::scan_plugindb(char *title,
749 // printf("MWindow::scan_plugindb data_type < 0\n");
753 for(int i = 0; i < plugindb->total; i++)
755 PluginServer *server = plugindb->get(i);
757 !strcasecmp(server->title, title) &&
759 (data_type == TRACK_AUDIO && server->audio) ||
760 (data_type == TRACK_VIDEO && server->video)))
761 return plugindb->get(i);
766 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
768 for( int i=0; i<plugins.size(); ++i )
769 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
773 int MWindow::plugin_exists(char *plugin_path)
775 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
778 void MWindow::init_preferences()
780 preferences = new Preferences;
781 preferences->load_defaults(defaults);
782 session = new MainSession(this);
783 session->load_defaults(defaults);
784 // set x11_host, screens, window_config
785 screens = session->set_default_x11_host();
786 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
787 BC_Signals::set_trap_hook(trap_hook, this);
788 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
789 BC_Signals::set_catch_intr(preferences->trap_sigintr);
792 void MWindow::clean_indexes()
797 int oldest_item = -1;
799 char string[BCTEXTLEN];
800 char string2[BCTEXTLEN];
802 // Delete extra indexes
803 fs.set_filter("*.idx");
804 fs.complete_path(preferences->index_directory);
805 fs.update(preferences->index_directory);
806 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
808 // Eliminate directories
813 for(int i = 0; i < fs.dir_list.total && !result; i++)
815 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
816 if(fs.is_dir(string))
818 delete fs.dir_list[i];
819 fs.dir_list.remove_number(i);
824 total_excess = fs.dir_list.total - preferences->index_count;
826 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
827 while(total_excess > 0)
830 for(int i = 0; i < fs.dir_list.total; i++)
832 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
834 if(i == 0 || fs.get_date(string) <= oldest)
836 oldest = fs.get_date(string);
844 fs.join_names(string,
845 preferences->index_directory,
846 fs.dir_list[oldest_item]->name);
847 //printf("MWindow::clean_indexes 1 %s\n", string);
849 perror("delete_indexes");
850 delete fs.dir_list[oldest_item];
851 fs.dir_list.remove_number(oldest_item);
853 // Remove table of contents if it exists
854 strcpy(string2, string);
855 char *ptr = strrchr(string2, '.');
858 //printf("MWindow::clean_indexes 2 %s\n", string2);
859 sprintf(ptr, ".toc");
861 sprintf(ptr, ".mkr");
870 void MWindow::init_awindow()
872 awindow = new AWindow(this);
873 awindow->create_objects();
876 void MWindow::init_gwindow()
878 gwindow = new GWindow(this);
879 gwindow->create_objects();
882 void MWindow::init_tipwindow()
885 twindow = new TipWindow(this);
889 void MWindow::show_warning(int *do_warning, const char *text)
891 if( do_warning && !*do_warning ) return;
893 wwindow = new WWindow(this);
894 wwindow->show_warning(do_warning, text);
897 void MWindow::init_theme()
902 PluginServer *theme_plugin = 0;
903 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
904 if( plugindb->get(i)->theme &&
905 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
906 theme_plugin = plugindb->get(i);
910 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
913 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
914 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
916 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
917 if( plugindb->get(i)->theme &&
918 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
919 theme_plugin = plugindb->get(i);
924 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
928 PluginServer *plugin = new PluginServer(*theme_plugin);
929 if( plugin->open_plugin(0, preferences, 0, 0) ) {
930 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
931 theme_plugin->title);
935 theme = plugin->new_theme();
936 theme->mwindow = this;
937 strcpy(theme->path, plugin->path);
940 // Load default images & settings
941 theme->Theme::initialize();
942 // Load user images & settings
944 // Create menus with user colors
945 theme->build_menus();
950 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
953 void MWindow::init_3d()
955 playback_3d = new Playback3D(this);
956 playback_3d->create_objects();
959 void MWindow::init_edl()
962 edl->create_objects();
963 fill_preset_defaults(default_standard, edl->session);
964 edl->load_defaults(defaults);
965 edl->create_default_tracks();
966 edl->tracks->update_y_pixels(theme);
969 void MWindow::init_compositor()
971 cwindow = new CWindow(this);
972 cwindow->create_objects();
975 void MWindow::init_levelwindow()
977 lwindow = new LevelWindow(this);
978 lwindow->create_objects();
981 VWindow *MWindow::get_viewer(int start_it, int idx)
983 vwindows_lock->lock("MWindow::get_viewer");
984 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
985 if( !vwindow ) idx = vwindows.size();
986 while( !vwindow && --idx >= 0 ) {
987 VWindow *vwin = vwindows[idx];
988 if( !vwin->is_running() || !vwin->get_edl() )
992 vwindow = new VWindow(this);
993 vwindow->load_defaults();
994 vwindow->create_objects();
995 vwindows.append(vwindow);
997 vwindows_lock->unlock();
998 if( start_it ) vwindow->start();
1002 void MWindow::init_cache()
1004 audio_cache = new CICache(preferences);
1005 video_cache = new CICache(preferences);
1006 frame_cache = new FrameCache;
1007 wave_cache = new WaveCache;
1010 void MWindow::init_channeldb()
1012 channeldb_buz->load("channeldb_buz");
1013 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1016 void MWindow::init_menus()
1018 char string[BCTEXTLEN];
1021 BC_CModels::to_text(string, BC_RGB888);
1022 colormodels.append(new ColormodelItem(string, BC_RGB888));
1023 BC_CModels::to_text(string, BC_RGBA8888);
1024 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1025 // BC_CModels::to_text(string, BC_RGB161616);
1026 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1027 // BC_CModels::to_text(string, BC_RGBA16161616);
1028 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1029 BC_CModels::to_text(string, BC_RGB_FLOAT);
1030 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1031 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1032 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1033 BC_CModels::to_text(string, BC_YUV888);
1034 colormodels.append(new ColormodelItem(string, BC_YUV888));
1035 BC_CModels::to_text(string, BC_YUVA8888);
1036 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1037 // BC_CModels::to_text(string, BC_YUV161616);
1038 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1039 // BC_CModels::to_text(string, BC_YUVA16161616);
1040 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1042 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1043 interlace_project_modes.append(new InterlacemodeItem(string, x));
1045 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1046 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1048 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1049 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1051 // Interlacing Modes
1052 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1054 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1055 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1057 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1058 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1060 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1061 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1063 // Interlacing Fixing Methods
1064 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
1065 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
1066 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
1069 void MWindow::init_indexes()
1071 mainindexes = new MainIndexes(this);
1072 mainindexes->start_loop();
1075 void MWindow::init_gui()
1077 gui = new MWindowGUI(this);
1078 gui->lock_window("MWindow::init_gui");
1079 gui->create_objects();
1080 gui->unlock_window();
1081 gui->load_defaults(defaults);
1084 void MWindow::init_signals()
1086 sighandler = new SigHandler;
1087 sighandler->initialize();
1091 void MWindow::init_render()
1093 render = new Render(this);
1094 create_bd = new CreateBD_Thread(this);
1095 create_dvd = new CreateDVD_Thread(this);
1096 batch_render = new BatchRenderThread(this);
1099 void MWindow::init_exportedl()
1101 exportedl = new ExportEDL(this);
1104 void MWindow::init_brender()
1106 if(preferences->use_brender && !brender)
1108 brender_lock->lock("MWindow::init_brender 1");
1109 brender = new BRender(this);
1110 brender->initialize();
1111 session->brender_end = 0;
1112 brender_lock->unlock();
1115 if(!preferences->use_brender && brender)
1117 brender_lock->lock("MWindow::init_brender 2");
1120 session->brender_end = 0;
1121 brender_lock->unlock();
1123 if(brender) brender->restart(edl);
1126 void MWindow::restart_brender()
1128 //printf("MWindow::restart_brender 1\n");
1129 if(brender) brender->restart(edl);
1132 void MWindow::stop_brender()
1134 if(brender) brender->stop();
1137 int MWindow::brender_available(int position)
1140 brender_lock->lock("MWindow::brender_available 1");
1143 if(brender->map_valid)
1145 brender->map_lock->lock("MWindow::brender_available 2");
1146 if(position < brender->map_size &&
1149 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1150 if(brender->map[position] == BRender::RENDERED)
1153 brender->map_lock->unlock();
1156 brender_lock->unlock();
1160 void MWindow::set_brender_start()
1162 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1164 gui->draw_overlays(1);
1168 int MWindow::has_commercials()
1170 return theme->use_commercials;
1173 void MWindow::init_commercials()
1175 if( !commercials ) {
1176 commercials = new Commercials(this);
1177 commercial_active = 0;
1180 commercials->add_user();
1183 void MWindow::commit_commercial()
1185 if( !commercial_active ) return;
1186 commercial_active = 0;
1187 if( !commercials ) return;
1188 commercials->commitDb();
1191 void MWindow::undo_commercial()
1193 if( !commercial_active ) return;
1194 commercial_active = 0;
1195 if( !commercials ) return;
1196 commercials->undoDb();
1199 int MWindow::put_commercial()
1201 double start = edl->local_session->get_selectionstart();
1202 double end = edl->local_session->get_selectionend();
1203 if( start >= end ) return 0;
1205 const char *errmsg = 0;
1207 Tracks *tracks = edl->tracks;
1210 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1211 if( track->data_type != TRACK_VIDEO ) continue;
1212 if( !track->record ) continue;
1213 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1215 int64_t units_start = track->to_units(start,0);
1216 int64_t units_end = track->to_units(end,0);
1217 Edits *edits = track->edits;
1218 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1219 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1220 if(!edit1 && !edit2) continue; // nothing selected
1221 if(!edit2) { // edit2 beyond end of track
1222 edit2 = edits->last;
1223 units_end = edits->length();
1225 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1226 Indexable *indexable = edit1->get_source();
1227 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1230 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1231 if( track->data_type != TRACK_VIDEO ) continue;
1232 if( !track->record ) continue;
1233 int64_t units_start = track->to_units(start,0);
1234 int64_t units_end = track->to_units(end,0);
1235 Edits *edits = track->edits;
1236 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1237 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1238 if(!edit1 && !edit2) continue; // nothing selected
1239 if(!edit2) { // edit2 beyond end of track
1240 edit2 = edits->last;
1241 units_end = edits->length();
1243 Indexable *indexable = edit1->get_source();
1244 Asset *asset = (Asset *)indexable;
1245 File *file = video_cache->check_out(asset, edl);
1246 if( !file ) { errmsg = _("no file"); break; }
1247 int64_t edit_length = units_end - units_start;
1248 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1249 result = commercials->put_clip(file, edit1->channel,
1250 track->from_units(edit_start), track->from_units(edit_length));
1251 video_cache->check_in(asset);
1252 if( result ) { errmsg = _("db failed"); break; }
1255 char string[BCTEXTLEN];
1256 sprintf(string, _("put_commercial: %s"), errmsg);
1257 MainError::show_error(string);
1264 void MWindow::stop_playback(int wait)
1266 int locked = gui->get_window_lock();
1267 if( locked ) gui->unlock_window();
1269 cwindow->playback_engine->que->send_command(STOP,
1273 cwindow->playback_engine->interrupt_playback(wait);
1275 for(int i = 0; i < vwindows.size(); i++) {
1276 VWindow *vwindow = vwindows[i];
1277 if( !vwindow->is_running() ) continue;
1278 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1279 vwindow->playback_engine->interrupt_playback(wait);
1281 if( locked ) gui->lock_window("MWindow::stop_playback");
1284 int MWindow::load_filenames(ArrayList<char*> *filenames,
1286 int update_filename)
1288 ArrayList<EDL*> new_edls;
1289 ArrayList<Asset*> new_assets;
1290 ArrayList<File*> new_files;
1291 const int debug = 0;
1292 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1295 gui->start_hourglass();
1297 // Need to stop playback since tracking depends on the EDL not getting
1301 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1302 undo->update_undo_before();
1305 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1307 // Define new_edls and new_assets to load
1308 int result = 0, ftype = -1;
1309 for(int i = 0; i < filenames->size(); i++)
1312 File *new_file = new File;
1313 Asset *new_asset = new Asset(filenames->get(i));
1314 EDL *new_edl = new EDL;
1315 char string[BCTEXTLEN];
1317 new_edl->create_objects();
1318 new_edl->copy_session(edl);
1319 new_file->set_program(edl->session->program_no);
1321 sprintf(string, _("Loading %s"), new_asset->path);
1322 gui->show_message(string);
1323 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1325 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1326 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1331 // Convert media file to EDL
1333 // Warn about odd image dimensions
1334 if(new_asset->video_data &&
1335 ((new_asset->width % 2) ||
1336 (new_asset->height % 2)))
1338 char string[BCTEXTLEN];
1339 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1343 MainError::show_error(string);
1346 if(new_asset->program >= 0 &&
1347 edl->session->program_no != new_asset->program)
1349 char string[BCTEXTLEN];
1350 sprintf(string, _("%s's index was built for program number %d\n"
1351 "Playback preference is %d.\n Using program %d."),
1352 new_asset->path, new_asset->program,
1353 edl->session->program_no, new_asset->program);
1354 MainError::show_error(string);
1358 if(load_mode != LOADMODE_RESOURCESONLY)
1361 RecordLabels *labels = edl->session->label_cells ?
1362 new RecordLabels(new_file) : 0;
1364 asset_to_edl(new_edl, new_asset, labels);
1366 new_edls.append(new_edl);
1368 new_asset->Garbage::remove_user();
1374 new_assets.append(new_asset);
1378 // Set filename to nothing for assets since save EDL would overwrite them.
1379 if(load_mode == LOADMODE_REPLACE ||
1380 load_mode == LOADMODE_REPLACE_CONCATENATE)
1383 // Reset timeline position
1384 for(int i = 0; i < TOTAL_PANES; i++)
1386 new_edl->local_session->view_start[i] = 0;
1387 new_edl->local_session->track_start[i] = 0;
1395 case FILE_NOT_FOUND:
1396 sprintf(string, _("Failed to open %s"), new_asset->path);
1397 gui->show_message(string, theme->message_error);
1401 case FILE_UNRECOGNIZED_CODEC:
1404 IndexFile indexfile(this, new_asset);
1405 result = indexfile.open_index();
1408 indexfile.close_index();
1411 // Test existing EDLs
1412 for(int j = 0; result && j <= new_edls.total; j++) {
1413 Asset *old_asset = j < new_edls.total ?
1414 new_edls[j]->assets->get_asset(new_asset->path) :
1415 edl->assets->get_asset(new_asset->path);
1417 *new_asset = *old_asset;
1425 char string[BCTEXTLEN];
1427 fs.extract_name(string, new_asset->path);
1429 strcat(string, _("'s format couldn't be determined."));
1430 new_asset->audio_data = 1;
1431 new_asset->format = FILE_PCM;
1432 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1433 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1434 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1435 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1436 new_asset->signed_ = defaults->get("SIGNED_", 1);
1437 new_asset->header = defaults->get("HEADER", 0);
1439 FileFormat fwindow(this);
1440 fwindow.create_objects(new_asset, string);
1441 result = fwindow.run_window();
1444 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1445 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1446 defaults->update("AUDIO_BITS", new_asset->bits);
1447 defaults->update("BYTE_ORDER", new_asset->byte_order);
1448 defaults->update("SIGNED_", new_asset->signed_);
1449 defaults->update("HEADER", new_asset->header);
1456 // Recalculate length
1458 new_file = new File;
1459 result = new_file->open_file(preferences, new_asset, 1, 0);
1461 if(load_mode != LOADMODE_RESOURCESONLY)
1463 RecordLabels *labels = edl->session->label_cells ?
1464 new RecordLabels(new_file) : 0;
1465 asset_to_edl(new_edl, new_asset, labels);
1466 new_edls.append(new_edl);
1467 new_asset->Garbage::remove_user();
1473 new_assets.append(new_asset);
1487 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1488 xml_file.read_from_file(filenames->get(i));
1489 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1491 if(load_mode == LOADMODE_NESTED)
1493 // Load temporary EDL for nesting.
1494 EDL *nested_edl = new EDL;
1495 nested_edl->create_objects();
1496 nested_edl->set_path(filenames->get(i));
1497 nested_edl->load_xml(&xml_file, LOAD_ALL);
1498 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1499 edl_to_nested(new_edl, nested_edl);
1500 nested_edl->Garbage::remove_user();
1504 // Load EDL for pasting
1505 new_edl->load_xml(&xml_file, LOAD_ALL);
1506 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1507 test_plugins(new_edl, filenames->get(i));
1508 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1510 if(load_mode == LOADMODE_REPLACE ||
1511 load_mode == LOADMODE_REPLACE_CONCATENATE)
1513 strcpy(session->filename, filenames->get(i));
1514 strcpy(new_edl->local_session->clip_title,
1517 set_filename(new_edl->local_session->clip_title);
1521 new_edls.append(new_edl);
1527 // edls are in new_edls
1528 if( result && new_edl ) new_edl->Garbage::remove_user();
1529 // assets are copied
1530 if( new_asset ) new_asset->Garbage::remove_user();
1532 // Store for testing index
1533 new_files.append(new_file);
1536 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1539 if(!result) gui->statusbar->default_message();
1547 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1550 // Don't back up here.
1553 // For pasting, clear the active region
1554 if(load_mode == LOADMODE_PASTE ||
1555 load_mode == LOADMODE_NESTED)
1557 double start = edl->local_session->get_selectionstart();
1558 double end = edl->local_session->get_selectionend();
1559 if(!EQUIV(start, end))
1562 edl->session->labels_follow_edits,
1563 edl->session->plugins_follow_edits,
1564 edl->session->autos_follow_edits);
1567 paste_edls(&new_edls,
1571 edl->session->labels_follow_edits,
1572 edl->session->plugins_follow_edits,
1573 edl->session->autos_follow_edits,
1580 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1582 // Add new assets to EDL and schedule assets for index building.
1583 int got_indexes = 0;
1584 for(int i = 0; i < new_edls.size(); i++)
1586 EDL *new_edl = new_edls[i];
1587 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1589 mainindexes->add_next_asset(0,
1590 new_edl->nested_edls->get(j));
1592 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1597 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1598 if(new_assets.size())
1600 for(int i = 0; i < new_assets.size(); i++)
1602 Asset *new_asset = new_assets[i];
1606 for(int j = 0; j < new_files.size(); j++)
1608 new_file = new_files[j];
1609 if(!strcmp(new_file->asset->path,
1617 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1619 edl->assets->update(new_asset);
1625 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1627 // Start examining next batch of index files
1628 if(got_indexes) mainindexes->start_build();
1629 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1632 Track *track = edl->tracks->first;
1635 for(int j = 0; j < track->plugin_set.size(); j++)
1637 PluginSet *plugins = track->plugin_set[j];
1638 Plugin *plugin = plugins->get_first_plugin();
1642 if(load_mode == LOADMODE_REPLACE ||
1643 load_mode == LOADMODE_REPLACE_CONCATENATE)
1645 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1648 show_plugin(plugin);
1656 plugin = (Plugin*)plugin->next;
1660 track = track->next;
1663 // if just opening one new resource in replace mode
1664 if( ftype != FILE_IS_XML &&
1665 ( load_mode == LOADMODE_REPLACE ||
1666 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1668 edl->local_session->preview_start = 0;
1669 edl->local_session->preview_end = edl->tracks->total_playable_length();
1670 edl->local_session->loop_playback = 0;
1671 edl->local_session->set_selectionstart(0);
1672 edl->local_session->set_selectionend(0);
1677 // need to update undo before project, since mwindow is unlocked & a new load
1678 // can begin here. Should really prevent loading until we're done.
1679 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1680 undo->update_undo_after(_("load"), LOAD_ALL);
1682 for(int i = 0; i < new_edls.size(); i++)
1684 new_edls[i]->remove_user();
1686 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1688 new_edls.remove_all();
1690 for(int i = 0; i < new_assets.size(); i++)
1692 new_assets[i]->Garbage::remove_user();
1695 new_assets.remove_all();
1696 new_files.remove_all_objects();
1699 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1700 if(load_mode == LOADMODE_REPLACE ||
1701 load_mode == LOADMODE_REPLACE_CONCATENATE)
1703 session->changes_made = 0;
1707 session->changes_made = 1;
1710 gui->stop_hourglass();
1713 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1714 update_project(load_mode);
1716 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1724 void MWindow::test_plugins(EDL *new_edl, char *path)
1726 char string[BCTEXTLEN];
1728 // Do a check weather plugins exist
1729 for(Track *track = new_edl->tracks->first; track; track = track->next)
1731 for(int k = 0; k < track->plugin_set.total; k++)
1733 PluginSet *plugin_set = track->plugin_set[k];
1734 for(Plugin *plugin = (Plugin*)plugin_set->first;
1736 plugin = (Plugin*)plugin->next)
1738 if(plugin->plugin_type == PLUGIN_STANDALONE)
1740 // ok we need to find it in plugindb
1741 int plugin_found = 0;
1743 for(int j = 0; j < plugindb->size(); j++)
1745 PluginServer *server = plugindb->get(j);
1747 !strcasecmp(server->title, plugin->title) &&
1748 ((track->data_type == TRACK_AUDIO && server->audio) ||
1749 (track->data_type == TRACK_VIDEO && server->video)) &&
1750 (!server->transition))
1757 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1758 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1759 "effect", plugin->title,
1761 MainError::show_error(string);
1767 for(Edit *edit = (Edit*)track->edits->first;
1769 edit = (Edit*)edit->next)
1771 if (edit->transition)
1773 // ok we need to find transition in plugindb
1775 int transition_found = 0;
1776 for(int j = 0; j < plugindb->size(); j++)
1778 PluginServer *server = plugindb->get(j);
1780 !strcasecmp(server->title, edit->transition->title) &&
1781 ((track->data_type == TRACK_AUDIO && server->audio) ||
1782 (track->data_type == TRACK_VIDEO && server->video)) &&
1783 (server->transition))
1784 transition_found = 1;
1787 if (!transition_found)
1790 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1791 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1792 "transition", edit->transition->title,
1794 MainError::show_error(string);
1802 void MWindow::init_shm()
1804 // Fix shared memory
1805 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1807 fprintf(fd, "0x7fffffff");
1812 fd = fopen("/proc/sys/kernel/shmmax", "r");
1814 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1819 fscanf(fd, "%jd", &result);
1822 if(result < 0x7fffffff) {
1823 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1824 "you probably need to be root, or:\n"
1825 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1826 "before trying to start cinelerra.\n"
1827 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1831 void MWindow::create_objects(int want_gui,
1836 const int debug = 0;
1837 if(debug) PRINT_TRACE
1839 // For some reason, init_signals must come after show_splash or the signals won't
1842 if(debug) PRINT_TRACE
1845 if(debug) PRINT_TRACE
1848 if(debug) PRINT_TRACE
1849 default_standard = default_std();
1850 init_defaults(defaults, config_path);
1853 splash_window->operation->update(_("Initializing Plugins"));
1854 init_plugins(this, preferences);
1855 if(debug) PRINT_TRACE
1856 init_ladspa_plugins(this, preferences);
1857 if(debug) PRINT_TRACE
1859 splash_window->operation->update(_("Initializing GUI"));
1860 if(debug) PRINT_TRACE
1863 if(debug) PRINT_TRACE
1867 splash_window->operation->update(_("Initializing Fonts"));
1868 char string[BCTEXTLEN];
1869 strcpy(string, preferences->plugin_dir);
1870 strcat(string, "/" FONT_SEARCHPATH);
1871 BC_Resources::init_fontconfig(string);
1872 if(debug) PRINT_TRACE
1874 // Initialize before too much else is running
1875 // Preferences & theme are required for building MPEG table of contents
1877 // Default project created here
1879 if(debug) PRINT_TRACE
1882 if(debug) PRINT_TRACE
1887 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1889 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1890 if(session->show_vwindow)
1891 get_viewer(1, DEFAULT_VWINDOW);
1892 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1895 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1898 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1901 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1903 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1906 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1910 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1912 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1914 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1918 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1919 mainprogress = new MainProgress(this, gui);
1920 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1921 undo = new MainUndo(this);
1923 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1925 plugin_guis = new ArrayList<PluginServer*>;
1926 dead_plugins = new ArrayList<PluginServer*>;
1927 keyframe_threads = new ArrayList<KeyFrameThread*>;
1929 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1932 session->show_vwindow);
1934 // Show all vwindows
1935 // if(session->show_vwindow) {
1936 // for(int j = 0; j < vwindows.size(); j++) {
1937 // VWindow *vwindow = vwindows[j];
1938 // if( !vwindow->is_running() ) continue;
1939 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1942 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1943 // vwindow->gui->lock_window("MWindow::create_objects 1");
1944 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1945 // vwindow->gui->show_window();
1946 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1947 // vwindow->gui->unlock_window();
1952 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1954 if(session->show_cwindow)
1956 cwindow->gui->lock_window("MWindow::create_objects 1");
1957 cwindow->gui->show_window();
1958 cwindow->gui->unlock_window();
1961 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1962 if(session->show_awindow)
1964 awindow->gui->lock_window("MWindow::create_objects 1");
1965 awindow->gui->show_window();
1966 awindow->gui->unlock_window();
1969 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1970 if(session->show_lwindow)
1972 lwindow->gui->lock_window("MWindow::create_objects 1");
1973 lwindow->gui->show_window();
1974 lwindow->gui->unlock_window();
1977 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1979 (int)timer.get_difference(),
1981 if(session->show_gwindow)
1983 gwindow->gui->lock_window("MWindow::create_objects 1");
1984 gwindow->gui->show_window();
1985 gwindow->gui->unlock_window();
1988 if(debug) PRINT_TRACE
1990 gui->lock_window("MWindow::create_objects 1");
1991 gui->mainmenu->load_defaults(defaults);
1992 gui->mainmenu->update_toggles(0);
1993 gui->update_patchbay();
1994 gui->draw_canvas(0, 0);
1995 gui->draw_cursor(1);
1997 gui->raise_window();
1998 gui->unlock_window();
2000 if(debug) PRINT_TRACE
2002 if(preferences->use_tipwindow)
2004 if(debug) PRINT_TRACE
2006 gui->add_keyboard_listener(
2007 (int (BC_WindowBase::*)(BC_WindowBase *))
2008 &MWindowGUI::keyboard_listener);
2012 if(debug) PRINT_TRACE
2014 BC_WindowBase::get_resources()->vframe_shm = 1;
2018 void MWindow::show_splash()
2020 #include "data/heroine_logo9_png.h"
2021 VFrame *frame = new VFramePng(heroine_logo9_png);
2022 BC_DisplayInfo dpyi;
2023 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2024 int rr = (rw < rh ? rw : rh) / 4;
2025 splash_window = new SplashGUI(frame, rr, rr);
2026 splash_window->create_objects();
2029 void MWindow::hide_splash()
2032 delete splash_window;
2037 void MWindow::start()
2041 // vwindows[DEFAULT_VWINDOW]->start();
2052 playback_3d->start();
2061 void MWindow::show_vwindow()
2063 int total_running = 0;
2064 session->show_vwindow = 1;
2066 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2067 // Raise all windows which are visible
2068 for(int j = 0; j < vwindows.size(); j++) {
2069 VWindow *vwindow = vwindows[j];
2070 if( !vwindow->is_running() ) continue;
2071 vwindow->gui->lock_window("MWindow::show_vwindow");
2072 vwindow->gui->show_window(0);
2073 vwindow->gui->raise_window();
2074 vwindow->gui->flush();
2075 vwindow->gui->unlock_window();
2079 // If no windows visible
2082 get_viewer(1, DEFAULT_VWINDOW);
2085 gui->mainmenu->show_vwindow->set_checked(1);
2088 void MWindow::show_awindow()
2090 session->show_awindow = 1;
2091 awindow->gui->lock_window("MWindow::show_awindow");
2092 awindow->gui->show_window();
2093 awindow->gui->raise_window();
2094 awindow->gui->flush();
2095 awindow->gui->unlock_window();
2096 gui->mainmenu->show_awindow->set_checked(1);
2099 char *MWindow::get_cwindow_display()
2101 char *x11_host = screens < 2 || session->window_config == 0 ?
2102 session->a_x11_host : session->b_x11_host;
2103 return *x11_host ? x11_host : 0;
2106 void MWindow::show_cwindow()
2108 session->show_cwindow = 1;
2109 cwindow->show_window();
2110 gui->mainmenu->show_cwindow->set_checked(1);
2113 void MWindow::show_gwindow()
2115 session->show_gwindow = 1;
2117 gwindow->gui->lock_window("MWindow::show_gwindow");
2118 gwindow->gui->show_window();
2119 gwindow->gui->raise_window();
2120 gwindow->gui->flush();
2121 gwindow->gui->unlock_window();
2123 gui->mainmenu->show_gwindow->set_checked(1);
2126 void MWindow::show_lwindow()
2128 session->show_lwindow = 1;
2129 lwindow->gui->lock_window("MWindow::show_lwindow");
2130 lwindow->gui->show_window();
2131 lwindow->gui->raise_window();
2132 lwindow->gui->flush();
2133 lwindow->gui->unlock_window();
2134 gui->mainmenu->show_lwindow->set_checked(1);
2137 int MWindow::tile_windows(int window_config)
2139 int need_reload = 0;
2140 int play_config = window_config==0 ? 0 : 1;
2141 edl->session->playback_config->load_defaults(defaults, play_config);
2142 session->default_window_positions(window_config);
2143 if( screens == 1 ) {
2144 gui->default_positions();
2145 sync_parameters(CHANGE_ALL);
2152 void MWindow::toggle_loop_playback()
2154 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2155 set_loop_boundaries();
2158 gui->draw_overlays(1);
2159 sync_parameters(CHANGE_PARAMS);
2162 //void MWindow::set_titles(int value)
2164 // edl->session->show_titles = value;
2165 // trackmovement(edl->local_session->track_start);
2168 void MWindow::set_screens(int value)
2173 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2175 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2176 edl->session->auto_keyframes = value;
2177 gui->mbuttons->edit_panel->keyframe->update(value);
2179 if(lock_mwindow) gui->unlock_window();
2181 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2182 cwindow->gui->edit_panel->keyframe->update(value);
2183 cwindow->gui->flush();
2184 if(lock_cwindow) cwindow->gui->unlock_window();
2187 void MWindow::set_keyframe_type(int mode)
2189 gui->lock_window("MWindow::set_keyframe_type");
2190 edl->local_session->floatauto_type = mode;
2191 gui->mainmenu->update_toggles(0);
2192 gui->unlock_window();
2195 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2197 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2198 edl->session->editing_mode = new_editing_mode;
2199 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2200 gui->mbuttons->edit_panel->update();
2201 gui->set_editing_mode(1);
2202 if(lock_mwindow) gui->unlock_window();
2205 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2206 cwindow->gui->edit_panel->update();
2207 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2208 if(lock_cwindow) cwindow->gui->unlock_window();
2212 void MWindow::toggle_editing_mode()
2214 int mode = edl->session->editing_mode;
2215 if( mode == EDITING_ARROW )
2216 set_editing_mode(EDITING_IBEAM, 0, 1);
2218 set_editing_mode(EDITING_ARROW, 0, 1);
2222 void MWindow::set_labels_follow_edits(int value)
2224 gui->lock_window("MWindow::set_labels_follow_edits");
2225 edl->session->labels_follow_edits = value;
2226 gui->mbuttons->edit_panel->locklabels->update(value);
2227 gui->mainmenu->labels_follow_edits->set_checked(value);
2229 gui->unlock_window();
2232 void MWindow::sync_parameters(int change_type)
2234 if( in_destructor ) return;
2236 // Sync engines which are playing back
2237 if(cwindow->playback_engine->is_playing_back)
2239 if(change_type == CHANGE_PARAMS)
2241 // TODO: block keyframes until synchronization is done
2242 cwindow->playback_engine->sync_parameters(edl);
2247 int command = cwindow->playback_engine->command->command;
2248 cwindow->playback_engine->que->send_command(STOP,
2252 // Waiting for tracking to finish would make the restart position more
2253 // accurate but it can't lock the window to stop tracking for some reason.
2254 // Not waiting for tracking gives a faster response but restart position is
2255 // only as accurate as the last tracking update.
2256 cwindow->playback_engine->interrupt_playback(0);
2257 cwindow->playback_engine->que->send_command(command,
2266 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2273 void MWindow::age_caches()
2275 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2277 // preferences->cache_size,
2278 // audio_cache->get_memory_usage(1),
2279 // video_cache->get_memory_usage(1),
2280 // frame_cache->get_memory_usage(),
2281 // wave_cache->get_memory_usage(),
2283 frame_cache->age_cache(512);
2284 wave_cache->age_cache(8192);
2286 int64_t memory_usage;
2287 int64_t prev_memory_usage = 0;
2289 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2290 while( !result && prev_memory_usage !=
2291 (memory_usage=video_cache->get_memory_usage(1)) &&
2292 memory_usage > video_size ) {
2293 video_cache->delete_oldest();
2294 prev_memory_usage = memory_usage;
2297 prev_memory_usage = 0;
2299 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2300 while( !result && prev_memory_usage !=
2301 (memory_usage=audio_cache->get_memory_usage(1)) &&
2302 memory_usage > audio_size ) {
2303 audio_cache->delete_oldest();
2304 prev_memory_usage = memory_usage;
2308 void MWindow::reset_android_remote()
2310 gui->use_android_remote(preferences->android_remote);
2314 void MWindow::show_keyframe_gui(Plugin *plugin)
2316 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2317 // Find existing thread
2318 for(int i = 0; i < keyframe_threads->size(); i++)
2320 if(keyframe_threads->get(i)->plugin == plugin)
2322 keyframe_threads->get(i)->start_window(plugin, 0);
2323 keyframe_gui_lock->unlock();
2328 // Find unused thread
2329 for(int i = 0; i < keyframe_threads->size(); i++)
2331 if(!keyframe_threads->get(i)->plugin)
2333 keyframe_threads->get(i)->start_window(plugin, 0);
2334 keyframe_gui_lock->unlock();
2339 // Create new thread
2340 KeyFrameThread *thread = new KeyFrameThread(this);
2341 keyframe_threads->append(thread);
2342 thread->start_window(plugin, 0);
2344 keyframe_gui_lock->unlock();
2351 void MWindow::show_plugin(Plugin *plugin)
2356 // Remove previously deleted plugin GUIs
2357 dead_plugin_lock->lock("MWindow::show_plugin");
2358 dead_plugins->remove_all_objects();
2359 dead_plugin_lock->unlock();
2361 //printf("MWindow::show_plugin %d\n", __LINE__);
2365 plugin_gui_lock->lock("MWindow::show_plugin");
2366 for(int i = 0; i < plugin_guis->total; i++)
2368 // Pointer comparison
2369 if(plugin_guis->get(i)->plugin == plugin)
2371 plugin_guis->get(i)->raise_window();
2378 //printf("MWindow::show_plugin 1\n");
2383 printf("MWindow::show_plugin track not defined.\n");
2385 PluginServer *server = scan_plugindb(plugin->title,
2386 plugin->track->data_type);
2388 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2389 if(server && server->uses_gui)
2391 PluginServer *gui = new PluginServer(*server);
2392 plugin_guis->append(gui);
2393 // Needs mwindow to do GUI
2394 gui->set_mwindow(this);
2395 gui->open_plugin(0, preferences, edl, plugin);
2400 plugin_gui_lock->unlock();
2401 //printf("MWindow::show_plugin %d\n", __LINE__);
2404 //printf("MWindow::show_plugin 2\n");
2407 void MWindow::hide_plugin(Plugin *plugin, int lock)
2410 // Update the toggle
2411 gui->lock_window("MWindow::hide_plugin");
2412 gui->update(0, 1, 0, 0, 0, 0, 0);
2413 gui->unlock_window();
2415 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2416 for(int i = 0; i < plugin_guis->total; i++)
2418 if(plugin_guis->get(i)->plugin == plugin)
2420 PluginServer *ptr = plugin_guis->get(i);
2421 plugin_guis->remove(ptr);
2422 if(lock) plugin_gui_lock->unlock();
2423 // Last command executed in client side close
2424 // Schedule for deletion
2431 if(lock) plugin_gui_lock->unlock();
2434 void MWindow::delete_plugin(PluginServer *plugin)
2436 dead_plugin_lock->lock("MWindow::delete_plugin");
2437 dead_plugins->append(plugin);
2438 dead_plugin_lock->unlock();
2441 void MWindow::hide_plugins()
2443 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2444 while(plugin_guis->size())
2446 PluginServer *ptr = plugin_guis->get(0);
2447 plugin_guis->remove(ptr);
2448 plugin_gui_lock->unlock();
2449 // Last command executed in client side close
2450 // Schedule for deletion
2453 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2455 plugin_gui_lock->unlock();
2457 hide_keyframe_guis();
2460 void MWindow::hide_keyframe_guis()
2462 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2463 for(int i = 0; i < keyframe_threads->size(); i++)
2465 keyframe_threads->get(i)->close_window();
2467 keyframe_gui_lock->unlock();
2470 void MWindow::hide_keyframe_gui(Plugin *plugin)
2472 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2473 for(int i = 0; i < keyframe_threads->size(); i++)
2475 if(keyframe_threads->get(i)->plugin == plugin)
2477 keyframe_threads->get(i)->close_window();
2481 keyframe_gui_lock->unlock();
2484 void MWindow::update_keyframe_guis()
2486 // Send new configuration to keyframe GUI's
2487 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2488 for(int i = 0; i < keyframe_threads->size(); i++)
2490 KeyFrameThread *ptr = keyframe_threads->get(i);
2491 if(edl->tracks->plugin_exists(ptr->plugin))
2495 ptr->close_window();
2498 keyframe_gui_lock->unlock();
2501 void MWindow::update_plugin_guis(int do_keyframe_guis)
2503 // Send new configuration to plugin GUI's
2504 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2506 for(int i = 0; i < plugin_guis->size(); i++)
2508 PluginServer *ptr = plugin_guis->get(i);
2509 if(edl->tracks->plugin_exists(ptr->plugin))
2513 // Schedule for deletion if no plugin
2514 plugin_guis->remove_number(i);
2523 // Change plugin variable if not visible
2524 Track *track = edl->tracks->first;
2527 for(int i = 0; i < track->plugin_set.size(); i++)
2529 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2533 for(int i = 0; i < plugin_guis->size(); i++)
2535 PluginServer *server = plugin_guis->get(i);
2536 if(server->plugin == plugin)
2543 if(!got_it) plugin->show = 0;
2545 plugin = (Plugin*)plugin->next;
2549 track = track->next;
2552 plugin_gui_lock->unlock();
2555 if(do_keyframe_guis) update_keyframe_guis();
2558 int MWindow::plugin_gui_open(Plugin *plugin)
2561 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2562 for(int i = 0; i < plugin_guis->total; i++)
2564 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2570 plugin_gui_lock->unlock();
2574 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2576 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2577 for(int i = 0; i < plugin_guis->total; i++)
2579 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2581 plugin_guis->get(i)->render_gui(data);
2585 plugin_gui_lock->unlock();
2588 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2590 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2591 for(int i = 0; i < plugin_guis->total; i++)
2593 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2595 plugin_guis->get(i)->render_gui(data, size);
2599 plugin_gui_lock->unlock();
2603 void MWindow::update_plugin_states()
2605 plugin_gui_lock->lock("MWindow::update_plugin_states");
2606 for(int i = 0; i < plugin_guis->total; i++)
2610 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2611 PluginServer *src_plugingui = plugin_guis->get(i);
2613 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2614 for(Track *track = edl->tracks->first;
2616 track = track->next)
2619 j < track->plugin_set.total && !result;
2622 PluginSet *plugin_set = track->plugin_set[j];
2623 for(Plugin *plugin = (Plugin*)plugin_set->first;
2625 plugin = (Plugin*)plugin->next)
2627 if(plugin == src_plugin &&
2628 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2634 // Doesn't exist anymore
2637 hide_plugin(src_plugin, 0);
2641 plugin_gui_lock->unlock();
2645 void MWindow::update_plugin_titles()
2647 for(int i = 0; i < plugin_guis->total; i++)
2649 plugin_guis->get(i)->update_title();
2653 int MWindow::asset_to_edl(EDL *new_edl,
2655 RecordLabels *labels)
2657 const int debug = 0;
2658 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2661 // Keep frame rate, sample rate, and output size unchanged.
2662 // These parameters would revert the project if VWindow displayed an asset
2663 // of different size than the project.
2664 if(new_asset->video_data)
2666 new_edl->session->video_tracks = new_asset->layers;
2669 new_edl->session->video_tracks = 0;
2671 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2677 if(new_asset->audio_data)
2679 new_edl->session->audio_tracks = new_asset->channels;
2682 new_edl->session->audio_tracks = 0;
2683 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2685 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2686 new_edl->create_default_tracks();
2687 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2688 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2692 //printf("MWindow::asset_to_edl 3\n");
2693 new_edl->insert_asset(new_asset,
2698 //printf("MWindow::asset_to_edl 3\n");
2699 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2701 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2702 if(edl->session->cursor_on_frames)
2704 double length = new_edl->tracks->total_length();
2705 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2706 new_edl->tracks->clear(length, edl_length, 1, 1);
2712 char string[BCTEXTLEN];
2714 fs.extract_name(string, new_asset->path);
2715 //printf("MWindow::asset_to_edl 3\n");
2717 strcpy(new_edl->local_session->clip_title, string);
2718 //printf("MWindow::asset_to_edl 4 %s\n", string);
2719 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2724 int MWindow::edl_to_nested(EDL *new_edl,
2728 // Keep frame rate, sample rate, and output size unchanged.
2729 // These parameters would revert the project if VWindow displayed an asset
2730 // of different size than the project.
2734 // Nest all video & audio outputs
2735 new_edl->session->video_tracks = 1;
2736 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2737 new_edl->create_default_tracks();
2741 new_edl->insert_asset(0,
2747 char string[BCTEXTLEN];
2749 fs.extract_name(string, nested_edl->path);
2750 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2752 strcpy(new_edl->local_session->clip_title, string);
2757 // Reset everything after a load.
2758 void MWindow::update_project(int load_mode)
2760 const int debug = 0;
2762 if(debug) PRINT_TRACE
2764 edl->tracks->update_y_pixels(theme);
2766 if(debug) PRINT_TRACE
2768 if(load_mode == LOADMODE_REPLACE ||
2769 load_mode == LOADMODE_REPLACE_CONCATENATE)
2774 gui->update(1, 1, 1, 1, 1, 1, 1);
2775 if(debug) PRINT_TRACE
2776 gui->unlock_window();
2778 cwindow->gui->lock_window("MWindow::update_project 1");
2779 cwindow->update(0, 0, 1, 1, 1);
2780 cwindow->gui->unlock_window();
2782 if(debug) PRINT_TRACE
2784 // Close all the vwindows
2785 if(load_mode == LOADMODE_REPLACE ||
2786 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2787 if(debug) PRINT_TRACE
2788 int first_vwindow = 0;
2789 if(session->show_vwindow) first_vwindow = 1;
2790 // Change visible windows to no source
2791 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2792 VWindow *vwindow = vwindows[i];
2793 if( !vwindow->is_running() ) continue;
2794 vwindow->change_source(-1);
2797 // Close remaining windows
2798 for(int i = first_vwindow; i < vwindows.size(); i++) {
2799 VWindow *vwindow = vwindows[i];
2800 if( !vwindow->is_running() ) continue;
2801 vwindow->close_window();
2803 if(debug) PRINT_TRACE
2805 else if(vwindows.size()) {
2806 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2807 if( vwindow->is_running() ) {
2808 vwindow->gui->lock_window("MWindow::update_project");
2810 vwindow->gui->unlock_window();
2814 if(debug) PRINT_TRACE
2815 cwindow->gui->lock_window("MWindow::update_project 2");
2816 cwindow->gui->timebar->update(0);
2817 cwindow->gui->unlock_window();
2819 if(debug) PRINT_TRACE
2820 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2825 awindow->gui->async_update_assets();
2826 if(debug) PRINT_TRACE
2828 gui->lock_window("MWindow::update_project");
2830 if(debug) PRINT_TRACE
2833 void MWindow::remove_indexfile(Indexable *indexable)
2835 if( !indexable->is_asset ) return;
2836 Asset *asset = (Asset *)indexable;
2838 IndexFile::delete_index(preferences, asset, ".toc");
2839 IndexFile::delete_index(preferences, asset, ".idx");
2840 IndexFile::delete_index(preferences, asset, ".mkr");
2843 void MWindow::rebuild_indices()
2845 for(int i = 0; i < session->drag_assets->total; i++)
2847 Indexable *indexable = session->drag_assets->get(i);
2848 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2849 remove_indexfile(indexable);
2850 // Schedule index build
2851 IndexState *index_state = indexable->index_state;
2852 index_state->index_status = INDEX_NOTTESTED;
2853 if( indexable->is_asset ) {
2854 Asset *asset = (Asset *)indexable;
2855 if( asset->format != FILE_PCM )
2856 asset->reset_audio();
2857 asset->reset_video();
2859 mainindexes->add_next_asset(0, indexable);
2861 mainindexes->start_build();
2865 void MWindow::save_backup()
2868 edl->set_path(session->filename);
2869 edl->save_xml(&file,
2873 file.terminate_string();
2874 char path[BCTEXTLEN];
2876 strcpy(path, BACKUP_PATH);
2877 fs.complete_path(path);
2879 if(file.write_to_file(path))
2882 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2883 gui->show_message(string2);
2887 void MWindow::load_backup()
2889 ArrayList<char*> path_list;
2890 path_list.set_array_delete();
2892 char string[BCTEXTLEN];
2893 strcpy(string, BACKUP_PATH);
2895 fs.complete_path(string);
2897 path_list.append(out_path = new char[strlen(string) + 1]);
2898 strcpy(out_path, string);
2900 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2901 edl->local_session->clip_title[0] = 0;
2902 // This is unique to backups since the path of the backup is different than the
2903 // path of the project.
2904 set_filename(edl->path);
2905 path_list.remove_all_objects();
2909 static inline int gcd(int m, int n)
2912 if( m < n ) { r = m; m = n; n = r; }
2913 while( (r = m % n) != 0 ) { m = n; n = r; }
2917 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2920 if(!width || !height) return 1;
2921 double ar = (double)width / height;
2922 // square-ish pixels
2923 if( EQUIV(ar, 1.0000) ) return 0;
2924 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2925 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2926 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2927 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2928 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2929 int ww = width, hh = height;
2930 // numerator, denominator must be under mx
2931 int mx = 255, n = gcd(ww, hh);
2932 if( n > 1 ) { ww /= n; hh /= n; }
2933 // search near height in case extra/missing lines
2934 if( ww >= mx || hh >= mx ) {
2935 double err = height; // +/- 2 percent height
2936 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2937 int iw = width, ih = height+i;
2938 if( (n=gcd(iw, ih)) > 1 ) {
2939 int u = iw/n; if( u >= mx ) continue;
2940 int v = ih/n; if( v >= mx ) continue;
2941 double r = (double) u/v, er = fabs(ar-r);
2942 if( er >= err ) continue;
2943 err = er; ww = u; hh = v;
2952 void MWindow::reset_caches()
2954 frame_cache->remove_all();
2955 wave_cache->remove_all();
2956 audio_cache->remove_all();
2957 video_cache->remove_all();
2958 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2959 cwindow->playback_engine->audio_cache->remove_all();
2960 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2961 cwindow->playback_engine->video_cache->remove_all();
2963 for(int i = 0; i < vwindows.size(); i++) {
2964 VWindow *vwindow = vwindows[i];
2965 if( !vwindow->is_running() ) continue;
2966 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2967 vwindow->playback_engine->audio_cache->remove_all();
2968 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2969 vwindow->playback_engine->video_cache->remove_all();
2973 void MWindow::remove_asset_from_caches(Asset *asset)
2975 gui->resource_thread->get_video_source(0);
2976 gui->resource_thread->get_audio_source(0);
2977 frame_cache->remove_asset(asset);
2978 wave_cache->remove_asset(asset);
2979 audio_cache->delete_entry(asset);
2980 video_cache->delete_entry(asset);
2981 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2982 cwindow->playback_engine->audio_cache->delete_entry(asset);
2983 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2984 cwindow->playback_engine->video_cache->delete_entry(asset);
2985 for(int i = 0; i < vwindows.size(); i++) {
2986 VWindow *vwindow = vwindows[i];
2987 if( !vwindow->is_running() ) continue;
2988 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2989 vwindow->playback_engine->audio_cache->delete_entry(asset);
2990 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2991 vwindow->playback_engine->video_cache->delete_entry(asset);
2996 void MWindow::remove_assets_from_project(int push_undo, int redraw,
2997 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
2999 for(int i = 0; i < session->drag_assets->total; i++) {
3000 Indexable *indexable = session->drag_assets->get(i);
3001 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3004 // Remove from VWindow.
3005 for(int i = 0; i < session->drag_clips->total; i++) {
3006 for(int j = 0; j < vwindows.size(); j++) {
3007 VWindow *vwindow = vwindows[j];
3008 if( !vwindow->is_running() ) continue;
3009 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3010 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3011 vwindow->delete_source(1, 1);
3012 vwindow->gui->unlock_window();
3017 for(int i = 0; i < session->drag_assets->size(); i++) {
3018 for(int j = 0; j < vwindows.size(); j++) {
3019 VWindow *vwindow = vwindows[j];
3020 if( !vwindow->is_running() ) continue;
3021 if(session->drag_assets->get(i) == vwindow->get_source()) {
3022 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3023 vwindow->delete_source(1, 1);
3024 vwindow->gui->unlock_window();
3029 for(int i = 0; i < session->drag_assets->size(); i++) {
3030 Indexable *indexable = session->drag_assets->get(i);
3031 remove_indexfile(indexable);
3034 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3035 if(push_undo) undo->update_undo_before();
3036 if(drag_assets) edl->remove_from_project(drag_assets);
3037 if(drag_clips) edl->remove_from_project(session->drag_clips);
3038 if(redraw) save_backup();
3039 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3044 gui->lock_window("MWindow::remove_assets_from_project 3");
3052 gui->unlock_window();
3054 // Removes from playback here
3055 sync_parameters(CHANGE_ALL);
3058 awindow->gui->async_update_assets();
3061 void MWindow::remove_assets_from_disk()
3064 for(int i = 0; i < session->drag_assets->total; i++)
3066 remove(session->drag_assets->get(i)->path);
3069 remove_assets_from_project(1,
3071 session->drag_assets,
3072 session->drag_clips);
3075 void MWindow::dump_plugins(FILE *fp)
3077 if( !plugindb ) return;
3078 for(int i = 0; i < plugindb->total; i++)
3080 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3081 " synth=%d transition=%d theme=%d %s\n",
3082 plugindb->get(i)->plugin_type,
3083 plugindb->get(i)->audio,
3084 plugindb->get(i)->video,
3085 plugindb->get(i)->realtime,
3086 plugindb->get(i)->multichannel,
3087 plugindb->get(i)->get_synthesis(),
3088 plugindb->get(i)->transition,
3089 plugindb->get(i)->theme,
3090 plugindb->get(i)->title);
3094 void MWindow::dump_edl(FILE *fp)
3100 void MWindow::dump_undo(FILE *fp)
3106 void MWindow::dump_exe(FILE *fp)
3108 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3109 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3110 int len = readlink(proc_path, exe_path, sizeof(exe_path));
3111 if( len < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3114 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3115 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
3116 int fd = open(exe_path,O_RDONLY);
3117 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3118 uint8_t buf[65536]; SHA1 sha1;
3119 while( (len=read(fd,buf,sizeof(buf))) > 0 ) {
3120 sha1.addBytes(buf, len);
3123 fprintf(fp, "SHA1: ");
3124 uint8_t digest[20]; sha1.computeHash(digest);
3125 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3130 void MWindow::trap_hook(FILE *fp, void *vp)
3132 MWindow *mwindow = (MWindow *)vp;
3133 fprintf(fp, "\nEXE:\n");
3134 mwindow->dump_exe(fp);
3135 fprintf(fp, "\nPLUGINS:\n");
3136 mwindow->dump_plugins(fp);
3137 fprintf(fp, "\nEDL:\n");
3138 mwindow->dump_edl(fp);
3139 fprintf(fp, "\nUNDO:\n");
3140 mwindow->dump_undo(fp);
3148 int MWindow::save_defaults()
3150 gui->save_defaults(defaults);
3151 edl->save_defaults(defaults);
3152 session->save_defaults(defaults);
3153 preferences->save_defaults(defaults);
3155 for(int i = 0; i < plugin_guis->total; i++)
3157 // Pointer comparison
3158 plugin_guis->get(i)->save_defaults();
3160 awindow->save_defaults(defaults);
3166 int MWindow::run_script(FileXML *script)
3168 int result = 0, result2 = 0;
3169 while(!result && !result2)
3171 result = script->read_tag();
3174 if(script->tag.title_is("new_project"))
3176 // Run new in immediate mode.
3177 // gui->mainmenu->new_project->run_script(script);
3180 if(script->tag.title_is("record"))
3182 // Run record as a thread. It is a terminal command.
3184 // Will read the complete scipt file without letting record read it if not
3190 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3197 // ================================= synchronization
3200 int MWindow::interrupt_indexes()
3202 mainprogress->cancelled = 1;
3203 mainindexes->interrupt_build();
3209 void MWindow::next_time_format()
3211 switch(edl->session->time_format)
3213 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3214 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3215 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3216 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3217 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3218 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3219 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3222 time_format_common();
3225 void MWindow::prev_time_format()
3227 switch(edl->session->time_format)
3229 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3230 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3231 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3232 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3233 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3234 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3235 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3238 time_format_common();
3241 void MWindow::time_format_common()
3243 gui->lock_window("MWindow::next_time_format");
3244 gui->redraw_time_dependancies();
3247 char string[BCTEXTLEN], string2[BCTEXTLEN];
3248 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3249 gui->show_message(string);
3251 gui->unlock_window();
3255 int MWindow::set_filename(const char *filename)
3257 if( filename != session->filename )
3258 strcpy(session->filename, filename);
3259 if( filename != edl->path )
3260 strcpy(edl->path, filename);
3264 if(filename[0] == 0)
3266 gui->set_title(PROGRAM_NAME);
3271 char string[BCTEXTLEN], string2[BCTEXTLEN];
3272 dir.extract_name(string, filename);
3273 sprintf(string2, PROGRAM_NAME ": %s", string);
3274 gui->set_title(string2);
3287 int MWindow::set_loop_boundaries()
3289 double start = edl->local_session->get_selectionstart();
3290 double end = edl->local_session->get_selectionend();
3298 if(edl->tracks->total_length())
3301 end = edl->tracks->total_length();
3308 if(edl->local_session->loop_playback && start != end)
3310 edl->local_session->loop_start = start;
3311 edl->local_session->loop_end = end;
3322 int MWindow::reset_meters()
3324 cwindow->gui->lock_window("MWindow::reset_meters 1");
3325 cwindow->gui->meters->reset_meters();
3326 cwindow->gui->unlock_window();
3328 for(int j = 0; j < vwindows.size(); j++) {
3329 VWindow *vwindow = vwindows[j];
3330 if( !vwindow->is_running() ) continue;
3331 vwindow->gui->lock_window("MWindow::reset_meters 2");
3332 vwindow->gui->meters->reset_meters();
3333 vwindow->gui->unlock_window();
3336 lwindow->gui->lock_window("MWindow::reset_meters 3");
3337 lwindow->gui->panel->reset_meters();
3338 lwindow->gui->unlock_window();
3340 gui->lock_window("MWindow::reset_meters 4");
3341 gui->reset_meters();
3342 gui->unlock_window();
3347 void MWindow::resync_guis()
3351 gui->lock_window("MWindow::resync_guis");
3352 gui->update(1, 1, 1, 1, 1, 1, 0);
3353 gui->unlock_window();
3355 cwindow->gui->lock_window("MWindow::resync_guis");
3356 cwindow->gui->resize_event(cwindow->gui->get_w(),
3357 cwindow->gui->get_h());
3358 int channels = edl->session->audio_channels;
3359 cwindow->gui->meters->set_meters(channels, 1);
3360 cwindow->gui->flush();
3361 cwindow->gui->unlock_window();
3363 for(int i = 0; i < vwindows.size(); i++) {
3364 VWindow *vwindow = vwindows[i];
3365 if( !vwindow->is_running() ) continue;
3366 vwindow->gui->lock_window("MWindow::resync_guis");
3367 vwindow->gui->resize_event(vwindow->gui->get_w(),
3368 vwindow->gui->get_h());
3369 vwindow->gui->meters->set_meters(channels, 1);
3370 vwindow->gui->flush();
3371 vwindow->gui->unlock_window();
3374 lwindow->gui->lock_window("MWindow::resync_guis");
3375 lwindow->gui->panel->set_meters(channels, 1);
3376 lwindow->gui->flush();
3377 lwindow->gui->unlock_window();
3380 if(((edl->session->output_w % 4) ||
3381 (edl->session->output_h % 4)) &&
3382 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3384 MainError::show_error(
3385 _("This project's dimensions are not multiples of 4 so\n"
3386 "it can't be rendered by OpenGL."));
3391 sync_parameters(CHANGE_ALL);
3394 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3396 File *file = new File;
3397 EDLSession *session = edl->session;
3398 double old_framerate = session->frame_rate;
3399 double old_samplerate = session->sample_rate;
3400 int result = file->open_file(preferences, asset, 1, 0);
3401 if( !result && delete_tracks > 0 )
3402 undo->update_undo_before();
3403 if( !result && asset->get_video_layers() > 0 ) {
3404 // try to get asset up to date, may fail
3405 file->select_video_stream(asset, vstream);
3406 // either way use what was/is there.
3407 double framerate = asset->get_frame_rate();
3408 int width = asset->get_w();
3409 int height = asset->get_h();
3410 // must be multiple of 4 for opengl
3411 width = (width+3) & ~3; height = (height+3) & ~3;
3412 int driver = session->playback_config->vconfig->driver;
3413 int color_model = file->get_best_colormodel(asset, driver);
3414 // color_model = BC_CModels::is_yuv(color_model) ?
3415 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3416 // BC_CModels::is_float(color_model) ?
3417 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3418 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3419 // have alpha for now
3420 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3421 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3422 session->color_model = color_model;
3423 session->output_w = width;
3424 session->output_h = height;
3425 session->frame_rate = framerate;
3426 // not, asset->actual_width/actual_height
3427 asset->width = session->output_w;
3428 asset->height = session->output_h;
3429 asset->frame_rate = session->frame_rate;
3430 create_aspect_ratio(session->aspect_w, session->aspect_h,
3431 session->output_w, session->output_h);
3432 Track *track = edl->tracks->first;
3433 for( Track *next_track=0; track; track=next_track ) {
3434 next_track = track->next;
3435 if( track->data_type != TRACK_VIDEO ) continue;
3436 if( delete_tracks ) {
3437 Edit *edit = track->edits->first;
3438 for( Edit *next_edit=0; edit; edit=next_edit ) {
3439 next_edit = edit->next;
3440 if( edit->channel != vstream ||
3441 !edit->asset || !edit->asset->is_asset ||
3442 *asset != *edit->asset )
3446 if( track->edits->first ) {
3447 track->track_w = edl->session->output_w;
3448 track->track_h = edl->session->output_h;
3450 else if( delete_tracks )
3451 edl->tracks->delete_track(track);
3453 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3455 if( !result && asset->channels > 0 ) {
3456 session->sample_rate = asset->get_sample_rate();
3457 int64_t channel_mask = 0;
3458 int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
3459 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3460 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3462 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3463 if( channels > 6 ) channels = 6;
3464 session->audio_tracks = session->audio_channels = channels;
3465 switch( channels ) {
3467 session->achannel_positions[0] = 90;
3468 session->achannel_positions[1] = 150;
3469 session->achannel_positions[2] = 30;
3470 session->achannel_positions[3] = 210;
3471 session->achannel_positions[4] = 330;
3472 session->achannel_positions[5] = 270;
3475 session->achannel_positions[0] = 180;
3476 session->achannel_positions[1] = 0;
3479 remap_audio(MWindow::AUDIO_1_TO_1);
3481 if( delete_tracks ) {
3482 Track *track = edl->tracks->first;
3483 for( Track *next_track=0; track; track=next_track ) {
3484 next_track = track->next;
3485 if( track->data_type != TRACK_AUDIO ) continue;
3486 Edit *edit = track->edits->first;
3487 for( Edit *next_edit=0; edit; edit=next_edit ) {
3488 next_edit = edit->next;
3489 if( !((1<<edit->channel) & channel_mask) ||
3490 !edit->asset || !edit->asset->is_asset ||
3491 *asset != *edit->asset )
3494 if( !track->edits->first )
3495 edl->tracks->delete_track(track);
3499 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3502 if( !result && delete_tracks > 0 ) {
3504 undo->update_undo_after(_("select asset"), LOAD_ALL);
3510 int MWindow::select_asset(int vtrack, int delete_tracks)
3512 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3513 if( !track ) return 1;
3514 Edit *edit = track->edits->first;
3515 if( !edit ) return 1;
3516 Asset *asset = edit->asset;
3517 if( !asset || !asset->is_asset ) return 1;
3518 return select_asset(asset, edit->channel, 0, delete_tracks);
3521 void MWindow::dump_plugindb(FILE *fp)
3523 if( !plugindb ) return;
3524 for(int i = 0; i < plugindb->total; i++)
3525 plugindb->get(i)->dump(fp);