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"
127 #include <sys/types.h>
128 #include <sys/stat.h>
129 #include <sys/time.h>
130 #include <sys/mman.h>
141 // Hack for libdv to remove glib dependancy
144 // g_log (const char *log_domain,
146 // const char *format,
152 // g_logv (const char *log_domain,
154 // const char *format,
164 ArrayList<PluginServer*>* MWindow::plugindb = 0;
165 Commercials* MWindow::commercials = 0;
171 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
172 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
173 vwindows_lock = new Mutex("MWindow::vwindows_lock");
174 brender_lock = new Mutex("MWindow::brender_lock");
175 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
183 commercial_active = 0;
194 channeldb_buz = new ChannelDB;
195 channeldb_v4l2jpeg = new ChannelDB;
199 keyframe_threads = 0;
219 // Need to delete brender temporary here.
225 //printf("MWindow::~MWindow %d\n", __LINE__);
227 gui->remote_control->deactivate();
230 gui->channel_info->stop();
232 brender_lock->lock("MWindow::quit");
233 delete brender; brender = 0;
234 brender_lock->unlock();
235 delete create_bd; create_bd = 0;
236 delete create_dvd; create_dvd = 0;
237 delete batch_render; batch_render = 0;
239 if( commercials && !commercials->remove_user() ) commercials = 0;
241 // Save defaults for open plugins
242 plugin_gui_lock->lock("MWindow::~MWindow");
243 for(int i = 0; i < plugin_guis->size(); i++) {
244 plugin_guis->get(i)->hide_gui();
245 delete_plugin(plugin_guis->get(i));
247 plugin_gui_lock->unlock();
248 hide_keyframe_guis();
251 // Give up and go to a movie
252 // cant run valgrind if this is used
254 gui->del_keyboard_listener(
255 (int (BC_WindowBase::*)(BC_WindowBase *))
256 &MWindowGUI::keyboard_listener);
258 // release the hounds
259 if( awindow && awindow->gui ) awindow->gui->close(0);
260 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
261 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
262 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
263 if( twindow && twindow->is_running() ) twindow->close_window();
264 if( wwindow && wwindow->is_running() ) wwindow->close_window();
265 vwindows.remove_all_objects();
267 if( awindow ) awindow->join();
268 if( cwindow ) cwindow->join();
269 if( lwindow ) lwindow->join();
270 if( twindow ) twindow->join();
271 if( wwindow ) wwindow->join();
272 if( gwindow ) gwindow->join();
275 // one at a time, or nouveau chokes
276 #define close_gui(win) if( win ) { \
277 if( win->gui ) win->gui->close(0); \
285 vwindows.remove_all_objects();
290 dead_plugins->remove_all_objects();
293 keyframe_threads->remove_all_objects();
294 colormodels.remove_all_objects();
296 delete render; render = 0;
297 delete awindow; awindow = 0;
298 delete lwindow; lwindow = 0;
299 delete twindow; twindow = 0;
300 delete wwindow; wwindow = 0;
301 delete gwindow; gwindow = 0;
302 // must be last or nouveau chokes
303 delete cwindow; cwindow = 0;
304 //delete file_server; file_server = 0; // reusable
305 delete mainindexes; mainindexes = 0;
306 delete mainprogress; mainprogress = 0;
307 delete audio_cache; audio_cache = 0; // delete the cache after the assets
308 delete video_cache; video_cache = 0; // delete the cache after the assets
309 delete frame_cache; frame_cache = 0;
310 delete wave_cache; wave_cache = 0;
311 delete plugin_guis; plugin_guis = 0;
312 delete dead_plugins; dead_plugins = 0;
313 delete keyframe_threads; keyframe_threads = 0;
314 delete undo; undo = 0;
315 delete preferences; preferences = 0;
316 delete exportedl; exportedl = 0;
317 delete session; session = 0;
318 delete defaults; defaults = 0;
319 delete assets; assets = 0;
320 delete splash_window; splash_window = 0;
321 // delete theme; theme = 0; // deleted by delete_plugins
322 if( !edl->Garbage::remove_user() ) edl = 0;
323 delete channeldb_buz;
324 delete channeldb_v4l2jpeg;
325 // This must be last thread to exit
326 delete playback_3d; playback_3d = 0;
327 delete dead_plugin_lock;
328 delete plugin_gui_lock;
329 delete vwindows_lock;
331 delete keyframe_gui_lock;
332 colormodels.remove_all_objects();
333 interlace_project_modes.remove_all_objects();
334 interlace_asset_modes.remove_all_objects();
335 interlace_asset_fixmethods.remove_all_objects();
336 sighandler->terminate();
341 void MWindow::quit(int unlock)
344 if(unlock) gui->unlock_window();
346 brender_lock->lock("MWindow::quit");
347 delete brender; brender = 0;
348 brender_lock->unlock();
354 if(unlock) gui->lock_window("MWindow::quit");
357 void MWindow::init_error()
359 MainError::init_error(this);
362 void MWindow::finit_error()
364 MainError::finit_error();
367 void MWindow::create_defaults_path(char *string, const char *config_file)
369 // set the .bcast path
372 sprintf(string, "%s", BCASTDIR);
373 fs.complete_path(string);
374 if(!fs.is_dir(string))
375 fs.create_dir(string);
378 strcat(string, config_file);
380 const char *MWindow::default_std()
386 if((fd = open(TIMEZONE_NAME, O_RDONLY)) >= 0)
388 l = read(fd, buf, BCTEXTLEN);
393 if(buf[l - 1] == '\n')
400 if((l = readlink(LOCALTIME_LINK, buf, BCTEXTLEN)) > 0)
403 if( (p=strstr(buf, ZONEINFO_STR)) != 0 )
405 p += strlen(ZONEINFO_STR);
414 for(i = 0; ntsc_zones[i]; i++)
415 if(strcmp(ntsc_zones[i], p) == 0)
421 void MWindow::fill_preset_defaults(const char *preset, EDLSession *session)
423 struct formatpresets *fpr;
425 for(fpr = &format_presets[0]; fpr->name; fpr++)
427 if(strcmp(fpr->name, preset) == 0)
429 session->audio_channels = fpr->audio_channels;
430 session->audio_tracks = fpr->audio_tracks;
431 session->sample_rate = fpr->sample_rate;
432 session->video_channels = fpr->video_channels;
433 session->video_tracks = fpr->video_tracks;
434 session->frame_rate = fpr->frame_rate;
435 session->output_w = fpr->output_w;
436 session->output_h = fpr->output_h;
437 session->aspect_w = fpr->aspect_w;
438 session->aspect_h = fpr->aspect_h;
439 session->interlace_mode = fpr->interlace_mode;
440 session->color_model = fpr->color_model;
446 const char *MWindow::get_preset_name(int index)
448 if(index < 0 || index >= (int)MAX_NUM_PRESETS)
450 return format_presets[index].name;
454 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
456 char path[BCTEXTLEN];
457 // Use user supplied path
459 strcpy(path, config_path);
461 create_defaults_path(path, CONFIG_FILE);
463 defaults = new BC_Hash(path);
467 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
469 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
471 const char *dp = plug_dir;
472 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
473 bp = !*dp && *bp == '/' ? bp+1 : base_path;
479 int MWindow::load_plugin_index(MWindow *mwindow, const char *index_path, const char *plugin_dir)
482 FILE *fp = fopen(index_path, "r");
486 char index_line[BCTEXTLEN];
487 int index_version = -1, len = strlen(plugin_dir);
488 if( !fgets(index_line, BCTEXTLEN, fp) ||
489 sscanf(index_line, "%d", &index_version) != 1 ||
490 index_version != PLUGIN_FILE_VERSION ||
491 !fgets(index_line, BCTEXTLEN, fp) ||
492 (int)strlen(index_line)-1 != len || index_line[len] != '\n' ||
493 strncmp(index_line, plugin_dir, len) != 0 ) ret = 1;
495 ArrayList<PluginServer*> plugins;
496 while( !ret && !feof(fp) && fgets(index_line, BCTEXTLEN, fp) ) {
497 if( index_line[0] == ';' ) continue;
498 if( index_line[0] == '#' ) continue;
499 int type = PLUGIN_TYPE_UNKNOWN;
500 char path[BCTEXTLEN], title[BCTEXTLEN];
502 if( PluginServer::scan_table(index_line, type, path, title, mtime) ) {
505 PluginServer *server = 0;
507 case PLUGIN_TYPE_BUILTIN:
508 case PLUGIN_TYPE_EXECUTABLE:
509 case PLUGIN_TYPE_LADSPA: {
510 char plugin_path[BCTEXTLEN]; struct stat st;
511 sprintf(plugin_path, "%s/%s", plugin_dir, path);
512 if( stat(plugin_path, &st) || st.st_mtime != mtime ) {
515 server = new PluginServer(mwindow, plugin_path, type);
517 case PLUGIN_TYPE_FFMPEG: {
518 server = new_ffmpeg_server(mwindow, path);
521 if( !server ) continue;
522 plugins.append(server);
523 // Create plugin server from index entry
524 server->set_title(title);
525 if( server->read_table(index_line) ) {
532 ret = check_plugin_index(plugins, plugin_dir, ".");
535 add_plugins(plugins);
537 plugins.remove_all_objects();
542 int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
543 const char *plug_dir, const char *plug_path)
545 char plugin_path[BCTEXTLEN];
546 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
548 fs.set_filter( "[*.plugin][*.so]" );
549 if( fs.update(plugin_path) )
552 for( int i=0; i<fs.dir_list.total; ++i ) {
553 char fs_path[BCTEXTLEN];
554 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
555 if( fs.is_dir(fs_path) ) {
556 get_plugin_path(plugin_path, plug_dir, fs_path);
557 if( check_plugin_index(plugins, plug_dir, plugin_path) )
560 else if( !plugin_exists(fs_path, plugins) )
567 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
570 plugindb = new ArrayList<PluginServer*>;
572 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
573 create_defaults_path(index_path, PLUGIN_FILE);
574 char *plugin_dir = FileSystem::basepath(preferences->plugin_dir);
575 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
576 if( !load_plugin_index(mwindow, index_path, plugin_path) ) return 1;
577 printf("init plugin index: %s\n", plugin_path);
578 FILE *fp = fopen(index_path,"w");
580 fprintf(stderr,_("MWindow::init_plugins: "
581 "can't create plugin index: %s\n"), index_path);
584 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
585 fprintf(fp, "%s\n", plugin_path);
586 init_plugin_index(mwindow, preferences, fp, plugin_path);
587 init_ffmpeg_index(mwindow, preferences, fp);
589 return load_plugin_index(mwindow, index_path, plugin_path);
592 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
594 char *path = getenv("LADSPA_PATH");
595 char ladspa_path[BCTEXTLEN];
597 get_exe_path(ladspa_path);
598 strcat(ladspa_path, "/ladspa");
601 for( int len=0; *path; path+=len ) {
602 char *cp = strchr(path,':');
603 len = !cp ? strlen(path) : cp-path;
604 char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
605 memcpy(plugin_path, path, len); plugin_path[len] = 0;
606 char *plugin_dir = FileSystem::basepath(plugin_path);
607 strcpy(plugin_path, plugin_dir); delete [] plugin_dir;
608 create_defaults_path(index_path, LADSPA_FILE);
609 cp = index_path + strlen(index_path);
610 for( char *bp=plugin_path; *bp!=0; ++bp )
611 *cp++ = *bp=='/' ? '_' : *bp;
613 if( !load_plugin_index(mwindow, index_path, plugin_path) ) continue;
614 if( init_ladspa_index(mwindow, preferences, index_path, plugin_path) ) continue;
615 load_plugin_index(mwindow, index_path, plugin_path);
620 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences,
621 FILE *fp, const char *plugin_dir)
623 int idx = PLUGIN_IDS;
625 for( int i=0; i<plugindb->size(); ++i ) {
626 PluginServer *server = plugindb->get(i);
627 if( server->dir_idx >= idx )
628 idx = server->dir_idx+1;
631 scan_plugin_index(mwindow, preferences, fp, plugin_dir, ".", idx);
634 int MWindow::init_ladspa_index(MWindow *mwindow, Preferences *preferences,
635 const char *index_path, const char *plugin_dir)
637 char plugin_path[BCTEXTLEN], *path = FileSystem::basepath(plugin_dir);
638 strcpy(plugin_path, path); delete [] path;
639 printf("init ladspa index: %s\n", plugin_dir);
640 FILE *fp = fopen(index_path,"w");
642 fprintf(stderr,_("MWindow::init_ladspa_index: "
643 "can't create plugin index: %s\n"), index_path);
646 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
647 fprintf(fp, "%s\n", plugin_dir);
648 init_plugin_index(mwindow, preferences, fp, plugin_path);
653 void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
654 const char *plug_dir, const char *plug_path, int &idx)
656 char plugin_path[BCTEXTLEN];
657 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
659 fs.set_filter( "[*.plugin][*.so]" );
660 int result = fs.update(plugin_path);
661 if( result || !fs.dir_list.total ) return;
664 for( int i=0; i<fs.dir_list.total; ++i ) {
665 char fs_path[BCTEXTLEN], path[BCTEXTLEN];
666 get_plugin_path(fs_path, 0, fs.dir_list[i]->path);
667 get_plugin_path(path, plug_dir, fs_path);
668 if( fs.is_dir(fs_path) ) {
669 scan_plugin_index(mwindow, preferences, fp, plug_dir, path, idx);
672 if( plugin_exists(path) ) continue;
674 if( stat(fs_path, &st) ) continue;
675 int64_t mtime = st.st_mtime;
676 PluginServer server(mwindow, fs_path, PLUGIN_TYPE_UNKNOWN);
677 result = server.open_plugin(1, preferences, 0, 0);
679 server.write_table(fp, path, vis_id, mtime);
680 server.close_plugin();
682 else if( result == PLUGINSERVER_IS_LAD ) {
685 PluginServer ladspa(mwindow, fs_path, PLUGIN_TYPE_LADSPA);
686 ladspa.set_lad_index(lad_index++);
687 result = ladspa.open_plugin(1, preferences, 0, 0);
689 ladspa.write_table(fp, path, PLUGIN_LADSPA_ID, mtime);
690 ladspa.close_plugin();
696 void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
698 for( int i=0; i<plugins.size(); ++i )
699 plugindb->append(plugins[i]);
700 plugins.remove_all();
703 void MWindow::delete_plugins()
705 plugindb->remove_all_objects();
710 void MWindow::search_plugindb(int do_audio,
715 ArrayList<PluginServer*> &results)
718 for(int i = 0; i < MWindow::plugindb->total; i++)
720 PluginServer *current = MWindow::plugindb->get(i);
722 if(current->audio == do_audio &&
723 current->video == do_video &&
724 (current->realtime == is_realtime || is_realtime < 0) &&
725 current->transition == is_transition &&
726 current->theme == is_theme)
727 results.append(current);
730 // Alphabetize list by title
736 for(int i = 0; i < results.total - 1; i++)
738 PluginServer *value1 = results[i];
739 PluginServer *value2 = results[i + 1];
740 if(strcmp(_(value1->title), _(value2->title)) > 0)
744 results[i + 1] = value1;
750 PluginServer* MWindow::scan_plugindb(char *title,
755 // printf("MWindow::scan_plugindb data_type < 0\n");
759 for(int i = 0; i < plugindb->total; i++)
761 PluginServer *server = plugindb->get(i);
763 !strcasecmp(server->title, title) &&
765 (data_type == TRACK_AUDIO && server->audio) ||
766 (data_type == TRACK_VIDEO && server->video)))
767 return plugindb->get(i);
772 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
774 for( int i=0; i<plugins.size(); ++i )
775 if( !strcmp(plugin_path, plugins[i]->get_path()) ) return 1;
779 int MWindow::plugin_exists(char *plugin_path)
781 return !plugindb ? 0 : plugin_exists(plugin_path, *plugindb);
784 void MWindow::init_preferences()
786 preferences = new Preferences;
787 preferences->load_defaults(defaults);
788 session = new MainSession(this);
789 session->load_defaults(defaults);
790 // set x11_host, screens, window_config
791 screens = session->set_default_x11_host();
792 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
793 BC_Signals::set_trap_hook(trap_hook, this);
794 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
795 BC_Signals::set_catch_intr(preferences->trap_sigintr);
798 void MWindow::clean_indexes()
803 int oldest_item = -1;
805 char string[BCTEXTLEN];
806 char string2[BCTEXTLEN];
808 // Delete extra indexes
809 fs.set_filter("*.idx");
810 fs.complete_path(preferences->index_directory);
811 fs.update(preferences->index_directory);
812 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
814 // Eliminate directories
819 for(int i = 0; i < fs.dir_list.total && !result; i++)
821 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
822 if(fs.is_dir(string))
824 delete fs.dir_list[i];
825 fs.dir_list.remove_number(i);
830 total_excess = fs.dir_list.total - preferences->index_count;
832 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
833 while(total_excess > 0)
836 for(int i = 0; i < fs.dir_list.total; i++)
838 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
840 if(i == 0 || fs.get_date(string) <= oldest)
842 oldest = fs.get_date(string);
850 fs.join_names(string,
851 preferences->index_directory,
852 fs.dir_list[oldest_item]->name);
853 //printf("MWindow::clean_indexes 1 %s\n", string);
855 perror("delete_indexes");
856 delete fs.dir_list[oldest_item];
857 fs.dir_list.remove_number(oldest_item);
859 // Remove table of contents if it exists
860 strcpy(string2, string);
861 char *ptr = strrchr(string2, '.');
864 //printf("MWindow::clean_indexes 2 %s\n", string2);
865 sprintf(ptr, ".toc");
867 sprintf(ptr, ".mkr");
876 void MWindow::init_awindow()
878 awindow = new AWindow(this);
879 awindow->create_objects();
882 void MWindow::init_gwindow()
884 gwindow = new GWindow(this);
885 gwindow->create_objects();
888 void MWindow::init_tipwindow()
891 twindow = new TipWindow(this);
895 void MWindow::show_warning(int *do_warning, const char *text)
897 if( do_warning && !*do_warning ) return;
899 wwindow = new WWindow(this);
900 wwindow->show_warning(do_warning, text);
903 void MWindow::init_theme()
908 PluginServer *theme_plugin = 0;
909 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
910 if( plugindb->get(i)->theme &&
911 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
912 theme_plugin = plugindb->get(i);
916 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
919 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
920 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
922 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
923 if( plugindb->get(i)->theme &&
924 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
925 theme_plugin = plugindb->get(i);
930 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
934 PluginServer *plugin = new PluginServer(*theme_plugin);
935 if( plugin->open_plugin(0, preferences, 0, 0) ) {
936 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
937 theme_plugin->title);
941 theme = plugin->new_theme();
942 theme->mwindow = this;
943 strcpy(theme->path, plugin->path);
946 // Load default images & settings
947 theme->Theme::initialize();
948 // Load user images & settings
950 // Create menus with user colors
951 theme->build_menus();
956 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
959 void MWindow::init_3d()
961 playback_3d = new Playback3D(this);
962 playback_3d->create_objects();
965 void MWindow::init_edl()
968 edl->create_objects();
969 fill_preset_defaults(default_standard, edl->session);
970 edl->load_defaults(defaults);
971 edl->create_default_tracks();
972 edl->tracks->update_y_pixels(theme);
975 void MWindow::init_compositor()
977 cwindow = new CWindow(this);
978 cwindow->create_objects();
981 void MWindow::init_levelwindow()
983 lwindow = new LevelWindow(this);
984 lwindow->create_objects();
987 VWindow *MWindow::get_viewer(int start_it, int idx)
989 vwindows_lock->lock("MWindow::get_viewer");
990 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
991 if( !vwindow ) idx = vwindows.size();
992 while( !vwindow && --idx >= 0 ) {
993 VWindow *vwin = vwindows[idx];
994 if( !vwin->is_running() || !vwin->get_edl() )
998 vwindow = new VWindow(this);
999 vwindow->load_defaults();
1000 vwindow->create_objects();
1001 vwindows.append(vwindow);
1003 vwindows_lock->unlock();
1004 if( start_it ) vwindow->start();
1008 void MWindow::init_cache()
1010 audio_cache = new CICache(preferences);
1011 video_cache = new CICache(preferences);
1012 frame_cache = new FrameCache;
1013 wave_cache = new WaveCache;
1016 void MWindow::init_channeldb()
1018 channeldb_buz->load("channeldb_buz");
1019 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
1022 void MWindow::init_menus()
1024 char string[BCTEXTLEN];
1027 BC_CModels::to_text(string, BC_RGB888);
1028 colormodels.append(new ColormodelItem(string, BC_RGB888));
1029 BC_CModels::to_text(string, BC_RGBA8888);
1030 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
1031 // BC_CModels::to_text(string, BC_RGB161616);
1032 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
1033 // BC_CModels::to_text(string, BC_RGBA16161616);
1034 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
1035 BC_CModels::to_text(string, BC_RGB_FLOAT);
1036 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
1037 BC_CModels::to_text(string, BC_RGBA_FLOAT);
1038 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
1039 BC_CModels::to_text(string, BC_YUV888);
1040 colormodels.append(new ColormodelItem(string, BC_YUV888));
1041 BC_CModels::to_text(string, BC_YUVA8888);
1042 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
1043 // BC_CModels::to_text(string, BC_YUV161616);
1044 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
1045 // BC_CModels::to_text(string, BC_YUVA16161616);
1046 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
1048 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
1049 interlace_project_modes.append(new InterlacemodeItem(string, x));
1051 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
1052 interlace_asset_modes.append(new InterlacemodeItem(string, x));
1054 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
1055 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
1057 // Interlacing Modes
1058 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
1060 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1061 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
1063 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1064 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
1066 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1067 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
1069 // Interlacing Fixing Methods
1070 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
1071 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
1072 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
1075 void MWindow::init_indexes()
1077 mainindexes = new MainIndexes(this);
1078 mainindexes->start_loop();
1081 void MWindow::init_gui()
1083 gui = new MWindowGUI(this);
1084 gui->lock_window("MWindow::init_gui");
1085 gui->create_objects();
1086 gui->unlock_window();
1087 gui->load_defaults(defaults);
1090 void MWindow::init_signals()
1092 sighandler = new SigHandler;
1093 sighandler->initialize();
1097 void MWindow::init_render()
1099 render = new Render(this);
1100 create_bd = new CreateBD_Thread(this);
1101 create_dvd = new CreateDVD_Thread(this);
1102 batch_render = new BatchRenderThread(this);
1105 void MWindow::init_exportedl()
1107 exportedl = new ExportEDL(this);
1110 void MWindow::init_brender()
1112 if(preferences->use_brender && !brender)
1114 brender_lock->lock("MWindow::init_brender 1");
1115 brender = new BRender(this);
1116 brender->initialize();
1117 session->brender_end = 0;
1118 brender_lock->unlock();
1121 if(!preferences->use_brender && brender)
1123 brender_lock->lock("MWindow::init_brender 2");
1126 session->brender_end = 0;
1127 brender_lock->unlock();
1129 if(brender) brender->restart(edl);
1132 void MWindow::restart_brender()
1134 //printf("MWindow::restart_brender 1\n");
1135 if(brender) brender->restart(edl);
1138 void MWindow::stop_brender()
1140 if(brender) brender->stop();
1143 int MWindow::brender_available(int position)
1146 brender_lock->lock("MWindow::brender_available 1");
1149 if(brender->map_valid)
1151 brender->map_lock->lock("MWindow::brender_available 2");
1152 if(position < brender->map_size &&
1155 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
1156 if(brender->map[position] == BRender::RENDERED)
1159 brender->map_lock->unlock();
1162 brender_lock->unlock();
1166 void MWindow::set_brender_start()
1168 edl->session->brender_start = edl->local_session->get_selectionstart(1);
1170 gui->draw_overlays(1);
1174 int MWindow::has_commercials()
1176 return theme->use_commercials;
1179 void MWindow::init_commercials()
1181 if( !commercials ) {
1182 commercials = new Commercials(this);
1183 commercial_active = 0;
1186 commercials->add_user();
1189 void MWindow::commit_commercial()
1191 if( !commercial_active ) return;
1192 commercial_active = 0;
1193 if( !commercials ) return;
1194 commercials->commitDb();
1197 void MWindow::undo_commercial()
1199 if( !commercial_active ) return;
1200 commercial_active = 0;
1201 if( !commercials ) return;
1202 commercials->undoDb();
1205 int MWindow::put_commercial()
1207 double start = edl->local_session->get_selectionstart();
1208 double end = edl->local_session->get_selectionend();
1209 if( start >= end ) return 0;
1211 const char *errmsg = 0;
1213 Tracks *tracks = edl->tracks;
1216 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1217 if( track->data_type != TRACK_VIDEO ) continue;
1218 if( !track->record ) continue;
1219 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
1221 int64_t units_start = track->to_units(start,0);
1222 int64_t units_end = track->to_units(end,0);
1223 Edits *edits = track->edits;
1224 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1225 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1226 if(!edit1 && !edit2) continue; // nothing selected
1227 if(!edit2) { // edit2 beyond end of track
1228 edit2 = edits->last;
1229 units_end = edits->length();
1231 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
1232 Indexable *indexable = edit1->get_source();
1233 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
1236 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
1237 if( track->data_type != TRACK_VIDEO ) continue;
1238 if( !track->record ) continue;
1239 int64_t units_start = track->to_units(start,0);
1240 int64_t units_end = track->to_units(end,0);
1241 Edits *edits = track->edits;
1242 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1243 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1244 if(!edit1 && !edit2) continue; // nothing selected
1245 if(!edit2) { // edit2 beyond end of track
1246 edit2 = edits->last;
1247 units_end = edits->length();
1249 Indexable *indexable = edit1->get_source();
1250 Asset *asset = (Asset *)indexable;
1251 File *file = video_cache->check_out(asset, edl);
1252 if( !file ) { errmsg = _("no file"); break; }
1253 int64_t edit_length = units_end - units_start;
1254 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1255 result = commercials->put_clip(file, edit1->channel,
1256 track->from_units(edit_start), track->from_units(edit_length));
1257 video_cache->check_in(asset);
1258 if( result ) { errmsg = _("db failed"); break; }
1261 char string[BCTEXTLEN];
1262 sprintf(string, _("put_commercial: %s"), errmsg);
1263 MainError::show_error(string);
1270 void MWindow::stop_playback(int wait)
1272 int locked = gui->get_window_lock();
1273 if( locked ) gui->unlock_window();
1275 cwindow->playback_engine->que->send_command(STOP,
1279 cwindow->playback_engine->interrupt_playback(wait);
1281 for(int i = 0; i < vwindows.size(); i++) {
1282 VWindow *vwindow = vwindows[i];
1283 if( !vwindow->is_running() ) continue;
1284 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1285 vwindow->playback_engine->interrupt_playback(wait);
1287 if( locked ) gui->lock_window("MWindow::stop_playback");
1290 int MWindow::load_filenames(ArrayList<char*> *filenames,
1292 int update_filename)
1294 ArrayList<EDL*> new_edls;
1295 ArrayList<Asset*> new_assets;
1296 ArrayList<File*> new_files;
1297 const int debug = 0;
1298 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1301 gui->start_hourglass();
1303 // Need to stop playback since tracking depends on the EDL not getting
1307 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1308 undo->update_undo_before();
1311 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1313 // Define new_edls and new_assets to load
1314 int result = 0, ftype = -1;
1315 for(int i = 0; i < filenames->size(); i++)
1318 File *new_file = new File;
1319 Asset *new_asset = new Asset(filenames->get(i));
1320 EDL *new_edl = new EDL;
1321 char string[BCTEXTLEN];
1323 new_edl->create_objects();
1324 new_edl->copy_session(edl);
1325 new_file->set_program(edl->session->program_no);
1327 sprintf(string, _("Loading %s"), new_asset->path);
1328 gui->show_message(string);
1329 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1331 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1332 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1337 // Convert media file to EDL
1339 // Warn about odd image dimensions
1340 if(new_asset->video_data &&
1341 ((new_asset->width % 2) ||
1342 (new_asset->height % 2)))
1344 char string[BCTEXTLEN];
1345 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1349 MainError::show_error(string);
1352 if(new_asset->program >= 0 &&
1353 edl->session->program_no != new_asset->program)
1355 char string[BCTEXTLEN];
1356 sprintf(string, _("%s's index was built for program number %d\n"
1357 "Playback preference is %d.\n Using program %d."),
1358 new_asset->path, new_asset->program,
1359 edl->session->program_no, new_asset->program);
1360 MainError::show_error(string);
1364 if(load_mode != LOADMODE_RESOURCESONLY)
1367 RecordLabels *labels = edl->session->label_cells ?
1368 new RecordLabels(new_file) : 0;
1370 asset_to_edl(new_edl, new_asset, labels);
1372 new_edls.append(new_edl);
1374 new_asset->Garbage::remove_user();
1380 new_assets.append(new_asset);
1384 // Set filename to nothing for assets since save EDL would overwrite them.
1385 if(load_mode == LOADMODE_REPLACE ||
1386 load_mode == LOADMODE_REPLACE_CONCATENATE)
1389 // Reset timeline position
1390 for(int i = 0; i < TOTAL_PANES; i++)
1392 new_edl->local_session->view_start[i] = 0;
1393 new_edl->local_session->track_start[i] = 0;
1401 case FILE_NOT_FOUND:
1402 sprintf(string, _("Failed to open %s"), new_asset->path);
1403 gui->show_message(string, theme->message_error);
1407 case FILE_UNRECOGNIZED_CODEC:
1410 IndexFile indexfile(this, new_asset);
1411 result = indexfile.open_index();
1414 indexfile.close_index();
1417 // Test existing EDLs
1418 for(int j = 0; result && j <= new_edls.total; j++) {
1419 Asset *old_asset = j < new_edls.total ?
1420 new_edls[j]->assets->get_asset(new_asset->path) :
1421 edl->assets->get_asset(new_asset->path);
1423 *new_asset = *old_asset;
1431 char string[BCTEXTLEN];
1433 fs.extract_name(string, new_asset->path);
1435 strcat(string, _("'s format couldn't be determined."));
1436 new_asset->audio_data = 1;
1437 new_asset->format = FILE_PCM;
1438 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1439 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1440 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1441 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1442 new_asset->signed_ = defaults->get("SIGNED_", 1);
1443 new_asset->header = defaults->get("HEADER", 0);
1445 FileFormat fwindow(this);
1446 fwindow.create_objects(new_asset, string);
1447 result = fwindow.run_window();
1450 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1451 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1452 defaults->update("AUDIO_BITS", new_asset->bits);
1453 defaults->update("BYTE_ORDER", new_asset->byte_order);
1454 defaults->update("SIGNED_", new_asset->signed_);
1455 defaults->update("HEADER", new_asset->header);
1462 // Recalculate length
1464 new_file = new File;
1465 result = new_file->open_file(preferences, new_asset, 1, 0);
1467 if(load_mode != LOADMODE_RESOURCESONLY)
1469 RecordLabels *labels = edl->session->label_cells ?
1470 new RecordLabels(new_file) : 0;
1471 asset_to_edl(new_edl, new_asset, labels);
1472 new_edls.append(new_edl);
1473 new_asset->Garbage::remove_user();
1479 new_assets.append(new_asset);
1493 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1494 xml_file.read_from_file(filenames->get(i));
1495 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1497 if(load_mode == LOADMODE_NESTED)
1499 // Load temporary EDL for nesting.
1500 EDL *nested_edl = new EDL;
1501 nested_edl->create_objects();
1502 nested_edl->set_path(filenames->get(i));
1503 nested_edl->load_xml(&xml_file, LOAD_ALL);
1504 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1505 edl_to_nested(new_edl, nested_edl);
1506 nested_edl->Garbage::remove_user();
1510 // Load EDL for pasting
1511 new_edl->load_xml(&xml_file, LOAD_ALL);
1512 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1513 test_plugins(new_edl, filenames->get(i));
1514 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1516 if(load_mode == LOADMODE_REPLACE ||
1517 load_mode == LOADMODE_REPLACE_CONCATENATE)
1519 strcpy(session->filename, filenames->get(i));
1520 strcpy(new_edl->local_session->clip_title,
1523 set_filename(new_edl->local_session->clip_title);
1527 new_edls.append(new_edl);
1533 // edls are in new_edls
1534 if( result && new_edl ) new_edl->Garbage::remove_user();
1535 // assets are copied
1536 if( new_asset ) new_asset->Garbage::remove_user();
1538 // Store for testing index
1539 new_files.append(new_file);
1542 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1545 if(!result) gui->statusbar->default_message();
1553 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1556 // Don't back up here.
1559 // For pasting, clear the active region
1560 if(load_mode == LOADMODE_PASTE ||
1561 load_mode == LOADMODE_NESTED)
1563 double start = edl->local_session->get_selectionstart();
1564 double end = edl->local_session->get_selectionend();
1565 if(!EQUIV(start, end))
1568 edl->session->labels_follow_edits,
1569 edl->session->plugins_follow_edits,
1570 edl->session->autos_follow_edits);
1573 paste_edls(&new_edls,
1577 edl->session->labels_follow_edits,
1578 edl->session->plugins_follow_edits,
1579 edl->session->autos_follow_edits,
1586 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1588 // Add new assets to EDL and schedule assets for index building.
1589 int got_indexes = 0;
1590 for(int i = 0; i < new_edls.size(); i++)
1592 EDL *new_edl = new_edls[i];
1593 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1595 mainindexes->add_next_asset(0,
1596 new_edl->nested_edls->get(j));
1598 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1603 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1604 if(new_assets.size())
1606 for(int i = 0; i < new_assets.size(); i++)
1608 Asset *new_asset = new_assets[i];
1612 for(int j = 0; j < new_files.size(); j++)
1614 new_file = new_files[j];
1615 if(!strcmp(new_file->asset->path,
1623 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1625 edl->assets->update(new_asset);
1631 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1633 // Start examining next batch of index files
1634 if(got_indexes) mainindexes->start_build();
1635 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1638 Track *track = edl->tracks->first;
1641 for(int j = 0; j < track->plugin_set.size(); j++)
1643 PluginSet *plugins = track->plugin_set[j];
1644 Plugin *plugin = plugins->get_first_plugin();
1648 if(load_mode == LOADMODE_REPLACE ||
1649 load_mode == LOADMODE_REPLACE_CONCATENATE)
1651 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1654 show_plugin(plugin);
1662 plugin = (Plugin*)plugin->next;
1666 track = track->next;
1669 // if just opening one new resource in replace mode
1670 if( ftype != FILE_IS_XML &&
1671 ( load_mode == LOADMODE_REPLACE ||
1672 load_mode == LOADMODE_REPLACE_CONCATENATE ) ) {
1674 edl->local_session->preview_start = 0;
1675 edl->local_session->preview_end = edl->tracks->total_playable_length();
1676 edl->local_session->loop_playback = 0;
1677 edl->local_session->set_selectionstart(0);
1678 edl->local_session->set_selectionend(0);
1683 // need to update undo before project, since mwindow is unlocked & a new load
1684 // can begin here. Should really prevent loading until we're done.
1685 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1686 undo->update_undo_after(_("load"), LOAD_ALL);
1688 for(int i = 0; i < new_edls.size(); i++)
1690 new_edls[i]->remove_user();
1692 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1694 new_edls.remove_all();
1696 for(int i = 0; i < new_assets.size(); i++)
1698 new_assets[i]->Garbage::remove_user();
1701 new_assets.remove_all();
1702 new_files.remove_all_objects();
1705 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1706 if(load_mode == LOADMODE_REPLACE ||
1707 load_mode == LOADMODE_REPLACE_CONCATENATE)
1709 session->changes_made = 0;
1713 session->changes_made = 1;
1716 gui->stop_hourglass();
1719 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1720 update_project(load_mode);
1722 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1730 void MWindow::test_plugins(EDL *new_edl, char *path)
1732 char string[BCTEXTLEN];
1734 // Do a check weather plugins exist
1735 for(Track *track = new_edl->tracks->first; track; track = track->next)
1737 for(int k = 0; k < track->plugin_set.total; k++)
1739 PluginSet *plugin_set = track->plugin_set[k];
1740 for(Plugin *plugin = (Plugin*)plugin_set->first;
1742 plugin = (Plugin*)plugin->next)
1744 if(plugin->plugin_type == PLUGIN_STANDALONE)
1746 // ok we need to find it in plugindb
1747 int plugin_found = 0;
1749 for(int j = 0; j < plugindb->size(); j++)
1751 PluginServer *server = plugindb->get(j);
1753 !strcasecmp(server->title, plugin->title) &&
1754 ((track->data_type == TRACK_AUDIO && server->audio) ||
1755 (track->data_type == TRACK_VIDEO && server->video)) &&
1756 (!server->transition))
1763 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1764 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1765 "effect", plugin->title,
1767 MainError::show_error(string);
1773 for(Edit *edit = (Edit*)track->edits->first;
1775 edit = (Edit*)edit->next)
1777 if (edit->transition)
1779 // ok we need to find transition in plugindb
1781 int transition_found = 0;
1782 for(int j = 0; j < plugindb->size(); j++)
1784 PluginServer *server = plugindb->get(j);
1786 !strcasecmp(server->title, edit->transition->title) &&
1787 ((track->data_type == TRACK_AUDIO && server->audio) ||
1788 (track->data_type == TRACK_VIDEO && server->video)) &&
1789 (server->transition))
1790 transition_found = 1;
1793 if (!transition_found)
1796 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1797 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1798 "transition", edit->transition->title,
1800 MainError::show_error(string);
1808 void MWindow::init_shm()
1810 // Fix shared memory
1811 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1813 fprintf(fd, "0x7fffffff");
1818 fd = fopen("/proc/sys/kernel/shmmax", "r");
1820 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1825 fscanf(fd, "%jd", &result);
1828 if(result < 0x7fffffff) {
1829 eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
1830 "you probably need to be root, or:\n"
1831 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1832 "before trying to start cinelerra.\n"
1833 "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
1837 void MWindow::create_objects(int want_gui,
1842 const int debug = 0;
1843 if(debug) PRINT_TRACE
1845 // For some reason, init_signals must come after show_splash or the signals won't
1848 if(debug) PRINT_TRACE
1851 if(debug) PRINT_TRACE
1854 if(debug) PRINT_TRACE
1855 default_standard = default_std();
1856 init_defaults(defaults, config_path);
1859 splash_window->operation->update(_("Initializing Plugins"));
1860 init_plugins(this, preferences);
1861 if(debug) PRINT_TRACE
1862 init_ladspa_plugins(this, preferences);
1863 if(debug) PRINT_TRACE
1865 splash_window->operation->update(_("Initializing GUI"));
1866 if(debug) PRINT_TRACE
1869 if(debug) PRINT_TRACE
1873 splash_window->operation->update(_("Initializing Fonts"));
1874 char string[BCTEXTLEN];
1875 strcpy(string, preferences->plugin_dir);
1876 strcat(string, "/" FONT_SEARCHPATH);
1877 BC_Resources::init_fontconfig(string);
1878 if(debug) PRINT_TRACE
1880 // Initialize before too much else is running
1881 // Preferences & theme are required for building MPEG table of contents
1883 // Default project created here
1885 if(debug) PRINT_TRACE
1888 if(debug) PRINT_TRACE
1893 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1895 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1896 if(session->show_vwindow)
1897 get_viewer(1, DEFAULT_VWINDOW);
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());
1904 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1907 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1909 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());
1916 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());
1920 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1924 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1925 mainprogress = new MainProgress(this, gui);
1926 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1927 undo = new MainUndo(this);
1929 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1931 plugin_guis = new ArrayList<PluginServer*>;
1932 dead_plugins = new ArrayList<PluginServer*>;
1933 keyframe_threads = new ArrayList<KeyFrameThread*>;
1935 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1938 session->show_vwindow);
1940 // Show all vwindows
1941 // if(session->show_vwindow) {
1942 // for(int j = 0; j < vwindows.size(); j++) {
1943 // VWindow *vwindow = vwindows[j];
1944 // if( !vwindow->is_running() ) continue;
1945 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1948 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1949 // vwindow->gui->lock_window("MWindow::create_objects 1");
1950 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1951 // vwindow->gui->show_window();
1952 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1953 // vwindow->gui->unlock_window();
1958 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1960 if(session->show_cwindow)
1962 cwindow->gui->lock_window("MWindow::create_objects 1");
1963 cwindow->gui->show_window();
1964 cwindow->gui->unlock_window();
1967 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1968 if(session->show_awindow)
1970 awindow->gui->lock_window("MWindow::create_objects 1");
1971 awindow->gui->show_window();
1972 awindow->gui->unlock_window();
1975 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1976 if(session->show_lwindow)
1978 lwindow->gui->lock_window("MWindow::create_objects 1");
1979 lwindow->gui->show_window();
1980 lwindow->gui->unlock_window();
1983 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1985 (int)timer.get_difference(),
1987 if(session->show_gwindow)
1989 gwindow->gui->lock_window("MWindow::create_objects 1");
1990 gwindow->gui->show_window();
1991 gwindow->gui->unlock_window();
1994 if(debug) PRINT_TRACE
1996 gui->lock_window("MWindow::create_objects 1");
1997 gui->mainmenu->load_defaults(defaults);
1998 gui->mainmenu->update_toggles(0);
1999 gui->update_patchbay();
2000 gui->draw_canvas(0, 0);
2001 gui->draw_cursor(1);
2003 gui->raise_window();
2004 gui->unlock_window();
2006 if(debug) PRINT_TRACE
2008 if(preferences->use_tipwindow)
2010 if(debug) PRINT_TRACE
2012 gui->add_keyboard_listener(
2013 (int (BC_WindowBase::*)(BC_WindowBase *))
2014 &MWindowGUI::keyboard_listener);
2018 if(debug) PRINT_TRACE
2020 BC_WindowBase::get_resources()->vframe_shm = 1;
2024 void MWindow::show_splash()
2026 #include "data/heroine_logo9_png.h"
2027 VFrame *frame = new VFramePng(heroine_logo9_png);
2028 BC_DisplayInfo dpyi;
2029 int rw = dpyi.get_root_w(), rh = dpyi.get_root_h();
2030 int rr = (rw < rh ? rw : rh) / 4;
2031 splash_window = new SplashGUI(frame, rr, rr);
2032 splash_window->create_objects();
2035 void MWindow::hide_splash()
2038 delete splash_window;
2043 void MWindow::start()
2047 // vwindows[DEFAULT_VWINDOW]->start();
2058 playback_3d->start();
2067 void MWindow::show_vwindow()
2069 int total_running = 0;
2070 session->show_vwindow = 1;
2072 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
2073 // Raise all windows which are visible
2074 for(int j = 0; j < vwindows.size(); j++) {
2075 VWindow *vwindow = vwindows[j];
2076 if( !vwindow->is_running() ) continue;
2077 vwindow->gui->lock_window("MWindow::show_vwindow");
2078 vwindow->gui->show_window(0);
2079 vwindow->gui->raise_window();
2080 vwindow->gui->flush();
2081 vwindow->gui->unlock_window();
2085 // If no windows visible
2088 get_viewer(1, DEFAULT_VWINDOW);
2091 gui->mainmenu->show_vwindow->set_checked(1);
2094 void MWindow::show_awindow()
2096 session->show_awindow = 1;
2097 awindow->gui->lock_window("MWindow::show_awindow");
2098 awindow->gui->show_window();
2099 awindow->gui->raise_window();
2100 awindow->gui->flush();
2101 awindow->gui->unlock_window();
2102 gui->mainmenu->show_awindow->set_checked(1);
2105 char *MWindow::get_cwindow_display()
2107 char *x11_host = screens < 2 || session->window_config == 0 ?
2108 session->a_x11_host : session->b_x11_host;
2109 return *x11_host ? x11_host : 0;
2112 void MWindow::show_cwindow()
2114 session->show_cwindow = 1;
2115 cwindow->show_window();
2116 gui->mainmenu->show_cwindow->set_checked(1);
2119 void MWindow::show_gwindow()
2121 session->show_gwindow = 1;
2123 gwindow->gui->lock_window("MWindow::show_gwindow");
2124 gwindow->gui->show_window();
2125 gwindow->gui->raise_window();
2126 gwindow->gui->flush();
2127 gwindow->gui->unlock_window();
2129 gui->mainmenu->show_gwindow->set_checked(1);
2132 void MWindow::show_lwindow()
2134 session->show_lwindow = 1;
2135 lwindow->gui->lock_window("MWindow::show_lwindow");
2136 lwindow->gui->show_window();
2137 lwindow->gui->raise_window();
2138 lwindow->gui->flush();
2139 lwindow->gui->unlock_window();
2140 gui->mainmenu->show_lwindow->set_checked(1);
2143 int MWindow::tile_windows(int window_config)
2145 int need_reload = 0;
2146 int play_config = window_config==0 ? 0 : 1;
2147 edl->session->playback_config->load_defaults(defaults, play_config);
2148 session->default_window_positions(window_config);
2149 if( screens == 1 ) {
2150 gui->default_positions();
2151 sync_parameters(CHANGE_ALL);
2158 void MWindow::toggle_loop_playback()
2160 edl->local_session->loop_playback = !edl->local_session->loop_playback;
2161 set_loop_boundaries();
2164 gui->draw_overlays(1);
2165 sync_parameters(CHANGE_PARAMS);
2168 //void MWindow::set_titles(int value)
2170 // edl->session->show_titles = value;
2171 // trackmovement(edl->local_session->track_start);
2174 void MWindow::set_screens(int value)
2179 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
2181 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
2182 edl->session->auto_keyframes = value;
2183 gui->mbuttons->edit_panel->keyframe->update(value);
2185 if(lock_mwindow) gui->unlock_window();
2187 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
2188 cwindow->gui->edit_panel->keyframe->update(value);
2189 cwindow->gui->flush();
2190 if(lock_cwindow) cwindow->gui->unlock_window();
2193 void MWindow::set_keyframe_type(int mode)
2195 gui->lock_window("MWindow::set_keyframe_type");
2196 edl->local_session->floatauto_type = mode;
2197 gui->mainmenu->update_toggles(0);
2198 gui->unlock_window();
2201 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
2203 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
2204 edl->session->editing_mode = new_editing_mode;
2205 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
2206 gui->mbuttons->edit_panel->update();
2207 gui->set_editing_mode(1);
2208 if(lock_mwindow) gui->unlock_window();
2211 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
2212 cwindow->gui->edit_panel->update();
2213 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
2214 if(lock_cwindow) cwindow->gui->unlock_window();
2218 void MWindow::toggle_editing_mode()
2220 int mode = edl->session->editing_mode;
2221 if( mode == EDITING_ARROW )
2222 set_editing_mode(EDITING_IBEAM, 0, 1);
2224 set_editing_mode(EDITING_ARROW, 0, 1);
2228 void MWindow::set_labels_follow_edits(int value)
2230 gui->lock_window("MWindow::set_labels_follow_edits");
2231 edl->session->labels_follow_edits = value;
2232 gui->mbuttons->edit_panel->locklabels->update(value);
2233 gui->mainmenu->labels_follow_edits->set_checked(value);
2235 gui->unlock_window();
2238 void MWindow::sync_parameters(int change_type)
2240 if( in_destructor ) return;
2242 // Sync engines which are playing back
2243 if(cwindow->playback_engine->is_playing_back)
2245 if(change_type == CHANGE_PARAMS)
2247 // TODO: block keyframes until synchronization is done
2248 cwindow->playback_engine->sync_parameters(edl);
2253 int command = cwindow->playback_engine->command->command;
2254 cwindow->playback_engine->que->send_command(STOP,
2258 // Waiting for tracking to finish would make the restart position more
2259 // accurate but it can't lock the window to stop tracking for some reason.
2260 // Not waiting for tracking gives a faster response but restart position is
2261 // only as accurate as the last tracking update.
2262 cwindow->playback_engine->interrupt_playback(0);
2263 cwindow->playback_engine->que->send_command(command,
2272 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2279 void MWindow::age_caches()
2281 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2283 // preferences->cache_size,
2284 // audio_cache->get_memory_usage(1),
2285 // video_cache->get_memory_usage(1),
2286 // frame_cache->get_memory_usage(),
2287 // wave_cache->get_memory_usage(),
2289 frame_cache->age_cache(512);
2290 wave_cache->age_cache(8192);
2292 int64_t memory_usage;
2293 int64_t prev_memory_usage = 0;
2295 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2296 while( !result && prev_memory_usage !=
2297 (memory_usage=video_cache->get_memory_usage(1)) &&
2298 memory_usage > video_size ) {
2299 video_cache->delete_oldest();
2300 prev_memory_usage = memory_usage;
2303 prev_memory_usage = 0;
2305 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2306 while( !result && prev_memory_usage !=
2307 (memory_usage=audio_cache->get_memory_usage(1)) &&
2308 memory_usage > audio_size ) {
2309 audio_cache->delete_oldest();
2310 prev_memory_usage = memory_usage;
2314 void MWindow::reset_android_remote()
2316 gui->use_android_remote(preferences->android_remote);
2320 void MWindow::show_keyframe_gui(Plugin *plugin)
2322 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2323 // Find existing thread
2324 for(int i = 0; i < keyframe_threads->size(); i++)
2326 if(keyframe_threads->get(i)->plugin == plugin)
2328 keyframe_threads->get(i)->start_window(plugin, 0);
2329 keyframe_gui_lock->unlock();
2334 // Find unused thread
2335 for(int i = 0; i < keyframe_threads->size(); i++)
2337 if(!keyframe_threads->get(i)->plugin)
2339 keyframe_threads->get(i)->start_window(plugin, 0);
2340 keyframe_gui_lock->unlock();
2345 // Create new thread
2346 KeyFrameThread *thread = new KeyFrameThread(this);
2347 keyframe_threads->append(thread);
2348 thread->start_window(plugin, 0);
2350 keyframe_gui_lock->unlock();
2357 void MWindow::show_plugin(Plugin *plugin)
2362 // Remove previously deleted plugin GUIs
2363 dead_plugin_lock->lock("MWindow::show_plugin");
2364 dead_plugins->remove_all_objects();
2365 dead_plugin_lock->unlock();
2367 //printf("MWindow::show_plugin %d\n", __LINE__);
2371 plugin_gui_lock->lock("MWindow::show_plugin");
2372 for(int i = 0; i < plugin_guis->total; i++)
2374 // Pointer comparison
2375 if(plugin_guis->get(i)->plugin == plugin)
2377 plugin_guis->get(i)->raise_window();
2384 //printf("MWindow::show_plugin 1\n");
2389 printf("MWindow::show_plugin track not defined.\n");
2391 PluginServer *server = scan_plugindb(plugin->title,
2392 plugin->track->data_type);
2394 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2395 if(server && server->uses_gui)
2397 PluginServer *gui = new PluginServer(*server);
2398 plugin_guis->append(gui);
2399 // Needs mwindow to do GUI
2400 gui->set_mwindow(this);
2401 gui->open_plugin(0, preferences, edl, plugin);
2406 plugin_gui_lock->unlock();
2407 //printf("MWindow::show_plugin %d\n", __LINE__);
2410 //printf("MWindow::show_plugin 2\n");
2413 void MWindow::hide_plugin(Plugin *plugin, int lock)
2416 // Update the toggle
2417 gui->lock_window("MWindow::hide_plugin");
2418 gui->update(0, 1, 0, 0, 0, 0, 0);
2419 gui->unlock_window();
2421 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2422 for(int i = 0; i < plugin_guis->total; i++)
2424 if(plugin_guis->get(i)->plugin == plugin)
2426 PluginServer *ptr = plugin_guis->get(i);
2427 plugin_guis->remove(ptr);
2428 if(lock) plugin_gui_lock->unlock();
2429 // Last command executed in client side close
2430 // Schedule for deletion
2437 if(lock) plugin_gui_lock->unlock();
2440 void MWindow::delete_plugin(PluginServer *plugin)
2442 dead_plugin_lock->lock("MWindow::delete_plugin");
2443 dead_plugins->append(plugin);
2444 dead_plugin_lock->unlock();
2447 void MWindow::hide_plugins()
2449 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2450 while(plugin_guis->size())
2452 PluginServer *ptr = plugin_guis->get(0);
2453 plugin_guis->remove(ptr);
2454 plugin_gui_lock->unlock();
2455 // Last command executed in client side close
2456 // Schedule for deletion
2459 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2461 plugin_gui_lock->unlock();
2463 hide_keyframe_guis();
2466 void MWindow::hide_keyframe_guis()
2468 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2469 for(int i = 0; i < keyframe_threads->size(); i++)
2471 keyframe_threads->get(i)->close_window();
2473 keyframe_gui_lock->unlock();
2476 void MWindow::hide_keyframe_gui(Plugin *plugin)
2478 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2479 for(int i = 0; i < keyframe_threads->size(); i++)
2481 if(keyframe_threads->get(i)->plugin == plugin)
2483 keyframe_threads->get(i)->close_window();
2487 keyframe_gui_lock->unlock();
2490 void MWindow::update_keyframe_guis()
2492 // Send new configuration to keyframe GUI's
2493 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2494 for(int i = 0; i < keyframe_threads->size(); i++)
2496 KeyFrameThread *ptr = keyframe_threads->get(i);
2497 if(edl->tracks->plugin_exists(ptr->plugin))
2501 ptr->close_window();
2504 keyframe_gui_lock->unlock();
2507 void MWindow::update_plugin_guis(int do_keyframe_guis)
2509 // Send new configuration to plugin GUI's
2510 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2512 for(int i = 0; i < plugin_guis->size(); i++)
2514 PluginServer *ptr = plugin_guis->get(i);
2515 if(edl->tracks->plugin_exists(ptr->plugin))
2519 // Schedule for deletion if no plugin
2520 plugin_guis->remove_number(i);
2529 // Change plugin variable if not visible
2530 Track *track = edl->tracks->first;
2533 for(int i = 0; i < track->plugin_set.size(); i++)
2535 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2539 for(int i = 0; i < plugin_guis->size(); i++)
2541 PluginServer *server = plugin_guis->get(i);
2542 if(server->plugin == plugin)
2549 if(!got_it) plugin->show = 0;
2551 plugin = (Plugin*)plugin->next;
2555 track = track->next;
2558 plugin_gui_lock->unlock();
2561 if(do_keyframe_guis) update_keyframe_guis();
2564 int MWindow::plugin_gui_open(Plugin *plugin)
2567 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2568 for(int i = 0; i < plugin_guis->total; i++)
2570 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2576 plugin_gui_lock->unlock();
2580 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2582 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2583 for(int i = 0; i < plugin_guis->total; i++)
2585 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2587 plugin_guis->get(i)->render_gui(data);
2591 plugin_gui_lock->unlock();
2594 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2596 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2597 for(int i = 0; i < plugin_guis->total; i++)
2599 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2601 plugin_guis->get(i)->render_gui(data, size);
2605 plugin_gui_lock->unlock();
2609 void MWindow::update_plugin_states()
2611 plugin_gui_lock->lock("MWindow::update_plugin_states");
2612 for(int i = 0; i < plugin_guis->total; i++)
2616 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2617 PluginServer *src_plugingui = plugin_guis->get(i);
2619 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2620 for(Track *track = edl->tracks->first;
2622 track = track->next)
2625 j < track->plugin_set.total && !result;
2628 PluginSet *plugin_set = track->plugin_set[j];
2629 for(Plugin *plugin = (Plugin*)plugin_set->first;
2631 plugin = (Plugin*)plugin->next)
2633 if(plugin == src_plugin &&
2634 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2640 // Doesn't exist anymore
2643 hide_plugin(src_plugin, 0);
2647 plugin_gui_lock->unlock();
2651 void MWindow::update_plugin_titles()
2653 for(int i = 0; i < plugin_guis->total; i++)
2655 plugin_guis->get(i)->update_title();
2659 int MWindow::asset_to_edl(EDL *new_edl,
2661 RecordLabels *labels)
2663 const int debug = 0;
2664 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2667 // Keep frame rate, sample rate, and output size unchanged.
2668 // These parameters would revert the project if VWindow displayed an asset
2669 // of different size than the project.
2670 if(new_asset->video_data)
2672 new_edl->session->video_tracks = new_asset->layers;
2675 new_edl->session->video_tracks = 0;
2677 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2683 if(new_asset->audio_data)
2685 new_edl->session->audio_tracks = new_asset->channels;
2688 new_edl->session->audio_tracks = 0;
2689 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2691 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2692 new_edl->create_default_tracks();
2693 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2694 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2698 //printf("MWindow::asset_to_edl 3\n");
2699 new_edl->insert_asset(new_asset,
2704 //printf("MWindow::asset_to_edl 3\n");
2705 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2707 // Align cursor on frames:: clip the new_edl to the minimum of the last joint frame.
2708 if(edl->session->cursor_on_frames)
2710 double length = new_edl->tracks->total_length();
2711 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
2712 new_edl->tracks->clear(length, edl_length, 1, 1);
2718 char string[BCTEXTLEN];
2720 fs.extract_name(string, new_asset->path);
2721 //printf("MWindow::asset_to_edl 3\n");
2723 strcpy(new_edl->local_session->clip_title, string);
2724 //printf("MWindow::asset_to_edl 4 %s\n", string);
2725 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2730 int MWindow::edl_to_nested(EDL *new_edl,
2734 // Keep frame rate, sample rate, and output size unchanged.
2735 // These parameters would revert the project if VWindow displayed an asset
2736 // of different size than the project.
2740 // Nest all video & audio outputs
2741 new_edl->session->video_tracks = 1;
2742 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2743 new_edl->create_default_tracks();
2747 new_edl->insert_asset(0,
2753 char string[BCTEXTLEN];
2755 fs.extract_name(string, nested_edl->path);
2756 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2758 strcpy(new_edl->local_session->clip_title, string);
2763 // Reset everything after a load.
2764 void MWindow::update_project(int load_mode)
2766 const int debug = 0;
2768 if(debug) PRINT_TRACE
2770 edl->tracks->update_y_pixels(theme);
2772 if(debug) PRINT_TRACE
2774 if(load_mode == LOADMODE_REPLACE ||
2775 load_mode == LOADMODE_REPLACE_CONCATENATE)
2780 gui->update(1, 1, 1, 1, 1, 1, 1);
2781 if(debug) PRINT_TRACE
2782 gui->unlock_window();
2784 cwindow->gui->lock_window("MWindow::update_project 1");
2785 cwindow->update(0, 0, 1, 1, 1);
2786 cwindow->gui->unlock_window();
2788 if(debug) PRINT_TRACE
2790 // Close all the vwindows
2791 if(load_mode == LOADMODE_REPLACE ||
2792 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2793 if(debug) PRINT_TRACE
2794 int first_vwindow = 0;
2795 if(session->show_vwindow) first_vwindow = 1;
2796 // Change visible windows to no source
2797 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2798 VWindow *vwindow = vwindows[i];
2799 if( !vwindow->is_running() ) continue;
2800 vwindow->change_source(-1);
2803 // Close remaining windows
2804 for(int i = first_vwindow; i < vwindows.size(); i++) {
2805 VWindow *vwindow = vwindows[i];
2806 if( !vwindow->is_running() ) continue;
2807 vwindow->close_window();
2809 if(debug) PRINT_TRACE
2811 else if(vwindows.size()) {
2812 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2813 if( vwindow->is_running() ) {
2814 vwindow->gui->lock_window("MWindow::update_project");
2816 vwindow->gui->unlock_window();
2820 if(debug) PRINT_TRACE
2821 cwindow->gui->lock_window("MWindow::update_project 2");
2822 cwindow->gui->timebar->update(0);
2823 cwindow->gui->unlock_window();
2825 if(debug) PRINT_TRACE
2826 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2831 awindow->gui->async_update_assets();
2832 if(debug) PRINT_TRACE
2834 gui->lock_window("MWindow::update_project");
2836 if(debug) PRINT_TRACE
2839 void MWindow::remove_indexfile(Indexable *indexable)
2841 if( !indexable->is_asset ) return;
2842 Asset *asset = (Asset *)indexable;
2844 IndexFile::delete_index(preferences, asset, ".toc");
2845 IndexFile::delete_index(preferences, asset, ".idx");
2846 IndexFile::delete_index(preferences, asset, ".mkr");
2849 void MWindow::rebuild_indices()
2851 for(int i = 0; i < session->drag_assets->total; i++)
2853 Indexable *indexable = session->drag_assets->get(i);
2854 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2855 remove_indexfile(indexable);
2856 // Schedule index build
2857 IndexState *index_state = indexable->index_state;
2858 index_state->index_status = INDEX_NOTTESTED;
2859 if( indexable->is_asset ) {
2860 Asset *asset = (Asset *)indexable;
2861 if( asset->format != FILE_PCM )
2862 asset->reset_audio();
2863 asset->reset_video();
2865 mainindexes->add_next_asset(0, indexable);
2867 mainindexes->start_build();
2871 void MWindow::save_backup()
2874 edl->set_path(session->filename);
2875 edl->save_xml(&file,
2879 file.terminate_string();
2880 char path[BCTEXTLEN];
2882 strcpy(path, BACKUP_PATH);
2883 fs.complete_path(path);
2885 if(file.write_to_file(path))
2888 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2889 gui->show_message(string2);
2893 void MWindow::load_backup()
2895 ArrayList<char*> path_list;
2896 path_list.set_array_delete();
2898 char string[BCTEXTLEN];
2899 strcpy(string, BACKUP_PATH);
2901 fs.complete_path(string);
2903 path_list.append(out_path = new char[strlen(string) + 1]);
2904 strcpy(out_path, string);
2906 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2907 edl->local_session->clip_title[0] = 0;
2908 // This is unique to backups since the path of the backup is different than the
2909 // path of the project.
2910 set_filename(edl->path);
2911 path_list.remove_all_objects();
2915 static inline int gcd(int m, int n)
2918 if( m < n ) { r = m; m = n; n = r; }
2919 while( (r = m % n) != 0 ) { m = n; n = r; }
2923 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2926 if(!width || !height) return 1;
2927 double ar = (double)width / height;
2928 // square-ish pixels
2929 if( EQUIV(ar, 1.0000) ) return 0;
2930 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2931 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2932 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2933 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2934 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2935 int ww = width, hh = height;
2936 // numerator, denominator must be under mx
2937 int mx = 255, n = gcd(ww, hh);
2938 if( n > 1 ) { ww /= n; hh /= n; }
2939 // search near height in case extra/missing lines
2940 if( ww >= mx || hh >= mx ) {
2941 double err = height; // +/- 2 percent height
2942 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2943 int iw = width, ih = height+i;
2944 if( (n=gcd(iw, ih)) > 1 ) {
2945 int u = iw/n; if( u >= mx ) continue;
2946 int v = ih/n; if( v >= mx ) continue;
2947 double r = (double) u/v, er = fabs(ar-r);
2948 if( er >= err ) continue;
2949 err = er; ww = u; hh = v;
2958 void MWindow::reset_caches()
2960 frame_cache->remove_all();
2961 wave_cache->remove_all();
2962 audio_cache->remove_all();
2963 video_cache->remove_all();
2964 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2965 cwindow->playback_engine->audio_cache->remove_all();
2966 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2967 cwindow->playback_engine->video_cache->remove_all();
2969 for(int i = 0; i < vwindows.size(); i++) {
2970 VWindow *vwindow = vwindows[i];
2971 if( !vwindow->is_running() ) continue;
2972 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2973 vwindow->playback_engine->audio_cache->remove_all();
2974 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2975 vwindow->playback_engine->video_cache->remove_all();
2979 void MWindow::remove_asset_from_caches(Asset *asset)
2981 gui->resource_thread->get_video_source(0);
2982 gui->resource_thread->get_audio_source(0);
2983 frame_cache->remove_asset(asset);
2984 wave_cache->remove_asset(asset);
2985 audio_cache->delete_entry(asset);
2986 video_cache->delete_entry(asset);
2987 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2988 cwindow->playback_engine->audio_cache->delete_entry(asset);
2989 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2990 cwindow->playback_engine->video_cache->delete_entry(asset);
2991 for(int i = 0; i < vwindows.size(); i++) {
2992 VWindow *vwindow = vwindows[i];
2993 if( !vwindow->is_running() ) continue;
2994 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2995 vwindow->playback_engine->audio_cache->delete_entry(asset);
2996 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2997 vwindow->playback_engine->video_cache->delete_entry(asset);
3002 void MWindow::remove_assets_from_project(int push_undo, int redraw,
3003 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
3005 for(int i = 0; i < session->drag_assets->total; i++) {
3006 Indexable *indexable = session->drag_assets->get(i);
3007 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
3010 // Remove from VWindow.
3011 for(int i = 0; i < session->drag_clips->total; i++) {
3012 for(int j = 0; j < vwindows.size(); j++) {
3013 VWindow *vwindow = vwindows[j];
3014 if( !vwindow->is_running() ) continue;
3015 if(session->drag_clips->get(i) == vwindow->get_edl()) {
3016 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
3017 vwindow->delete_source(1, 1);
3018 vwindow->gui->unlock_window();
3023 for(int i = 0; i < session->drag_assets->size(); i++) {
3024 for(int j = 0; j < vwindows.size(); j++) {
3025 VWindow *vwindow = vwindows[j];
3026 if( !vwindow->is_running() ) continue;
3027 if(session->drag_assets->get(i) == vwindow->get_source()) {
3028 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
3029 vwindow->delete_source(1, 1);
3030 vwindow->gui->unlock_window();
3035 for(int i = 0; i < session->drag_assets->size(); i++) {
3036 Indexable *indexable = session->drag_assets->get(i);
3037 remove_indexfile(indexable);
3040 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
3041 if(push_undo) undo->update_undo_before();
3042 if(drag_assets) edl->remove_from_project(drag_assets);
3043 if(drag_clips) edl->remove_from_project(session->drag_clips);
3044 if(redraw) save_backup();
3045 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
3050 gui->lock_window("MWindow::remove_assets_from_project 3");
3058 gui->unlock_window();
3060 // Removes from playback here
3061 sync_parameters(CHANGE_ALL);
3064 awindow->gui->async_update_assets();
3067 void MWindow::remove_assets_from_disk()
3070 for(int i = 0; i < session->drag_assets->total; i++)
3072 remove(session->drag_assets->get(i)->path);
3075 remove_assets_from_project(1,
3077 session->drag_assets,
3078 session->drag_clips);
3081 void MWindow::dump_plugins(FILE *fp)
3083 if( !plugindb ) return;
3084 for(int i = 0; i < plugindb->total; i++)
3086 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
3087 " synth=%d transition=%d theme=%d %s\n",
3088 plugindb->get(i)->plugin_type,
3089 plugindb->get(i)->audio,
3090 plugindb->get(i)->video,
3091 plugindb->get(i)->realtime,
3092 plugindb->get(i)->multichannel,
3093 plugindb->get(i)->get_synthesis(),
3094 plugindb->get(i)->transition,
3095 plugindb->get(i)->theme,
3096 plugindb->get(i)->title);
3100 void MWindow::dump_edl(FILE *fp)
3106 void MWindow::dump_undo(FILE *fp)
3112 void MWindow::dump_exe(FILE *fp)
3114 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
3115 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
3116 int ret = readlink(proc_path, exe_path, sizeof(exe_path));
3117 if( ret < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
3120 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
3121 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
3122 int fd = open(exe_path,O_RDONLY+O_NONBLOCK);
3123 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
3126 int64_t pagsz = sysconf(_SC_PAGE_SIZE);
3127 int64_t maxsz = 1024*pagsz;
3128 int64_t size = st.st_size, pos = 0;
3130 while( (bfrsz = size-pos) > 0 ) {
3131 if( bfrsz > maxsz ) bfrsz = maxsz;
3132 bfr = (uint8_t *)mmap(NULL, bfrsz, PROT_READ,
3133 MAP_PRIVATE+MAP_NORESERVE+MAP_POPULATE, fd, pos);
3134 if( bfr == MAP_FAILED ) break;
3135 sha1.addBytes(bfr, bfrsz);
3140 ret = pos < size ? EIO : 0;
3141 fprintf(fp, "SHA1: ");
3142 uint8_t digest[20]; sha1.computeHash(digest);
3143 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
3144 if( ret < 0 ) fprintf(fp, " (ret %d)", ret);
3145 if( pos < st.st_size ) fprintf(fp, " (pos %jd)", pos);
3149 void MWindow::trap_hook(FILE *fp, void *vp)
3151 MWindow *mwindow = (MWindow *)vp;
3152 // fprintf(fp, "\nPLUGINS:\n");
3153 // mwindow->dump_plugins(fp);
3154 fprintf(fp, "\nEDL:\n");
3155 mwindow->dump_edl(fp);
3156 fprintf(fp, "\nUNDO:\n");
3157 mwindow->dump_undo(fp);
3158 fprintf(fp, "\nEXE:\n");
3159 mwindow->dump_exe(fp);
3167 int MWindow::save_defaults()
3169 gui->save_defaults(defaults);
3170 edl->save_defaults(defaults);
3171 session->save_defaults(defaults);
3172 preferences->save_defaults(defaults);
3174 for(int i = 0; i < plugin_guis->total; i++)
3176 // Pointer comparison
3177 plugin_guis->get(i)->save_defaults();
3179 awindow->save_defaults(defaults);
3185 int MWindow::run_script(FileXML *script)
3187 int result = 0, result2 = 0;
3188 while(!result && !result2)
3190 result = script->read_tag();
3193 if(script->tag.title_is("new_project"))
3195 // Run new in immediate mode.
3196 // gui->mainmenu->new_project->run_script(script);
3199 if(script->tag.title_is("record"))
3201 // Run record as a thread. It is a terminal command.
3203 // Will read the complete scipt file without letting record read it if not
3209 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
3216 // ================================= synchronization
3219 int MWindow::interrupt_indexes()
3221 mainprogress->cancelled = 1;
3222 mainindexes->interrupt_build();
3228 void MWindow::next_time_format()
3230 switch(edl->session->time_format)
3232 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
3233 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
3234 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3235 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
3236 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
3237 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
3238 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
3241 time_format_common();
3244 void MWindow::prev_time_format()
3246 switch(edl->session->time_format)
3248 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
3249 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
3250 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
3251 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
3252 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
3253 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
3254 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
3257 time_format_common();
3260 void MWindow::time_format_common()
3262 gui->lock_window("MWindow::next_time_format");
3263 gui->redraw_time_dependancies();
3266 char string[BCTEXTLEN], string2[BCTEXTLEN];
3267 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3268 gui->show_message(string);
3270 gui->unlock_window();
3274 int MWindow::set_filename(const char *filename)
3276 if( filename != session->filename )
3277 strcpy(session->filename, filename);
3278 if( filename != edl->path )
3279 strcpy(edl->path, filename);
3283 if(filename[0] == 0)
3285 gui->set_title(PROGRAM_NAME);
3290 char string[BCTEXTLEN], string2[BCTEXTLEN];
3291 dir.extract_name(string, filename);
3292 sprintf(string2, PROGRAM_NAME ": %s", string);
3293 gui->set_title(string2);
3306 int MWindow::set_loop_boundaries()
3308 double start = edl->local_session->get_selectionstart();
3309 double end = edl->local_session->get_selectionend();
3317 if(edl->tracks->total_length())
3320 end = edl->tracks->total_length();
3327 if(edl->local_session->loop_playback && start != end)
3329 edl->local_session->loop_start = start;
3330 edl->local_session->loop_end = end;
3341 int MWindow::reset_meters()
3343 cwindow->gui->lock_window("MWindow::reset_meters 1");
3344 cwindow->gui->meters->reset_meters();
3345 cwindow->gui->unlock_window();
3347 for(int j = 0; j < vwindows.size(); j++) {
3348 VWindow *vwindow = vwindows[j];
3349 if( !vwindow->is_running() ) continue;
3350 vwindow->gui->lock_window("MWindow::reset_meters 2");
3351 vwindow->gui->meters->reset_meters();
3352 vwindow->gui->unlock_window();
3355 lwindow->gui->lock_window("MWindow::reset_meters 3");
3356 lwindow->gui->panel->reset_meters();
3357 lwindow->gui->unlock_window();
3359 gui->lock_window("MWindow::reset_meters 4");
3360 gui->reset_meters();
3361 gui->unlock_window();
3366 void MWindow::resync_guis()
3370 gui->lock_window("MWindow::resync_guis");
3371 gui->update(1, 1, 1, 1, 1, 1, 0);
3372 gui->unlock_window();
3374 cwindow->gui->lock_window("MWindow::resync_guis");
3375 cwindow->gui->resize_event(cwindow->gui->get_w(),
3376 cwindow->gui->get_h());
3377 int channels = edl->session->audio_channels;
3378 cwindow->gui->meters->set_meters(channels, 1);
3379 cwindow->gui->flush();
3380 cwindow->gui->unlock_window();
3382 for(int i = 0; i < vwindows.size(); i++) {
3383 VWindow *vwindow = vwindows[i];
3384 if( !vwindow->is_running() ) continue;
3385 vwindow->gui->lock_window("MWindow::resync_guis");
3386 vwindow->gui->resize_event(vwindow->gui->get_w(),
3387 vwindow->gui->get_h());
3388 vwindow->gui->meters->set_meters(channels, 1);
3389 vwindow->gui->flush();
3390 vwindow->gui->unlock_window();
3393 lwindow->gui->lock_window("MWindow::resync_guis");
3394 lwindow->gui->panel->set_meters(channels, 1);
3395 lwindow->gui->flush();
3396 lwindow->gui->unlock_window();
3399 if(((edl->session->output_w % 4) ||
3400 (edl->session->output_h % 4)) &&
3401 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3403 MainError::show_error(
3404 _("This project's dimensions are not multiples of 4 so\n"
3405 "it can't be rendered by OpenGL."));
3410 sync_parameters(CHANGE_ALL);
3413 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3415 File *file = new File;
3416 EDLSession *session = edl->session;
3417 double old_framerate = session->frame_rate;
3418 double old_samplerate = session->sample_rate;
3419 int result = file->open_file(preferences, asset, 1, 0);
3420 if( !result && delete_tracks > 0 )
3421 undo->update_undo_before();
3422 if( !result && asset->video_data && asset->get_video_layers() > 0 ) {
3423 // try to get asset up to date, may fail
3424 file->select_video_stream(asset, vstream);
3425 // either way use what was/is there.
3426 double framerate = asset->get_frame_rate();
3427 int width = asset->get_w();
3428 int height = asset->get_h();
3429 // must be multiple of 4 for opengl
3430 width = (width+3) & ~3; height = (height+3) & ~3;
3431 int driver = session->playback_config->vconfig->driver;
3432 int color_model = file->get_best_colormodel(asset, driver);
3433 // color_model = BC_CModels::is_yuv(color_model) ?
3434 // BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3435 // BC_CModels::is_float(color_model) ?
3436 // BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3437 // BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3438 // have alpha for now
3439 color_model = BC_CModels::is_yuv(color_model) ? BC_YUVA8888 :
3440 BC_CModels::is_float(color_model) ? BC_RGBA_FLOAT : BC_RGBA8888;
3441 session->color_model = color_model;
3442 session->output_w = width;
3443 session->output_h = height;
3444 session->frame_rate = framerate;
3445 // not, asset->actual_width/actual_height
3446 asset->width = session->output_w;
3447 asset->height = session->output_h;
3448 asset->frame_rate = session->frame_rate;
3449 create_aspect_ratio(session->aspect_w, session->aspect_h,
3450 session->output_w, session->output_h);
3451 Track *track = edl->tracks->first;
3452 for( Track *next_track=0; track; track=next_track ) {
3453 next_track = track->next;
3454 if( track->data_type != TRACK_VIDEO ) continue;
3455 if( delete_tracks ) {
3456 Edit *edit = track->edits->first;
3457 for( Edit *next_edit=0; edit; edit=next_edit ) {
3458 next_edit = edit->next;
3459 if( edit->channel != vstream ||
3460 !edit->asset || !edit->asset->is_asset ||
3461 *asset != *edit->asset )
3465 if( track->edits->first ) {
3466 track->track_w = edl->session->output_w;
3467 track->track_h = edl->session->output_h;
3469 else if( delete_tracks )
3470 edl->tracks->delete_track(track);
3472 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3474 if( !result && asset->audio_data && asset->channels > 0 ) {
3475 session->sample_rate = asset->get_sample_rate();
3476 int64_t channel_mask = 0;
3477 int astrm = !asset->video_data ? -1 :
3478 file->get_audio_for_video(vstream, astream, channel_mask);
3479 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3480 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3482 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3483 if( channels < 1 ) channels = 1;
3484 if( channels > 6 ) channels = 6;
3485 session->audio_tracks = session->audio_channels = channels;
3486 switch( channels ) {
3488 session->achannel_positions[0] = 90;
3489 session->achannel_positions[1] = 150;
3490 session->achannel_positions[2] = 30;
3491 session->achannel_positions[3] = 210;
3492 session->achannel_positions[4] = 330;
3493 session->achannel_positions[5] = 270;
3496 session->achannel_positions[0] = 180;
3497 session->achannel_positions[1] = 0;
3500 session->achannel_positions[1] = 90;
3503 if( !channels ) break;
3504 double t = 0, dt = 360./channels;
3505 for( int i=channels; --i>=0; t+=dt )
3506 session->achannel_positions[i] = int(t+0.5);
3509 remap_audio(MWindow::AUDIO_1_TO_1);
3511 if( delete_tracks ) {
3512 Track *track = edl->tracks->first;
3513 for( Track *next_track=0; track; track=next_track ) {
3514 next_track = track->next;
3515 if( track->data_type != TRACK_AUDIO ) continue;
3516 Edit *edit = track->edits->first;
3517 for( Edit *next_edit=0; edit; edit=next_edit ) {
3518 next_edit = edit->next;
3519 if( !((1<<edit->channel) & channel_mask) ||
3520 !edit->asset || !edit->asset->is_asset ||
3521 *asset != *edit->asset )
3524 if( !track->edits->first )
3525 edl->tracks->delete_track(track);
3529 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3532 if( !result && delete_tracks > 0 ) {
3534 undo->update_undo_after(_("select asset"), LOAD_ALL);
3540 int MWindow::select_asset(int vtrack, int delete_tracks)
3542 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3544 track = edl->tracks->get(vtrack, TRACK_AUDIO);
3545 if( !track ) return 1;
3546 Edit *edit = track->edits->first;
3547 if( !edit ) return 1;
3548 Asset *asset = edit->asset;
3549 if( !asset || !asset->is_asset ) return 1;
3550 return select_asset(asset, edit->channel, 0, delete_tracks);
3553 void MWindow::dump_plugindb(FILE *fp)
3555 if( !plugindb ) return;
3556 for(int i = 0; i < plugindb->total; i++)
3557 plugindb->get(i)->dump(fp);