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"
44 #include "devicedvbinput.inc"
45 #include "dvdcreate.h"
46 #include "editpanel.h"
48 #include "edlsession.h"
50 #include "fileformat.h"
52 #include "fileserver.h"
53 #include "filesystem.h"
56 #include "framecache.h"
58 #include "gwindowgui.h"
59 #include "keyframegui.h"
60 #include "indexfile.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 "samplescroll.h"
93 #include "sighandler.h"
94 #include "splashgui.h"
95 #include "statusbar.h"
97 #include "threadloader.h"
99 #include "tipwindow.h"
100 #include "trackcanvas.h"
102 #include "tracking.h"
103 #include "trackscroll.h"
105 #include "transition.h"
106 #include "transportque.h"
108 #include "videodevice.inc"
109 #include "videowindow.h"
110 #include "vplayback.h"
111 #include "vwindowgui.h"
113 #include "wavecache.h"
118 #include <sys/stat.h>
127 // Hack for libdv to remove glib dependancy
130 // g_log (const char *log_domain,
132 // const char *format,
138 // g_logv (const char *log_domain,
140 // const char *format,
147 // Hack for XFree86 4.1.0
149 int atexit(void (*function)(void))
160 ArrayList<PluginServer*>* MWindow::plugindb = 0;
161 FileServer* MWindow::file_server = 0;
162 Commercials* MWindow::commercials = 0;
168 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
169 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
170 vwindows_lock = new Mutex("MWindow::vwindows_lock");
171 brender_lock = new Mutex("MWindow::brender_lock");
172 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
180 commercial_active = 0;
191 channeldb_buz = new ChannelDB;
192 channeldb_v4l2jpeg = new ChannelDB;
196 keyframe_threads = 0;
216 // Need to delete brender temporary here.
220 //printf("MWindow::~MWindow %d\n", __LINE__);
222 gui->remote_control->deactivate();
224 gui->channel_info->stop();
225 brender_lock->lock("MWindow::quit");
226 delete brender; brender = 0;
227 brender_lock->unlock();
228 delete create_bd; create_bd = 0;
229 delete create_dvd; create_dvd = 0;
230 delete batch_render; batch_render = 0;
232 if( commercials && !commercials->remove_user() ) commercials = 0;
234 // Save defaults for open plugins
235 plugin_gui_lock->lock("MWindow::~MWindow");
236 for(int i = 0; i < plugin_guis->size(); i++)
238 plugin_guis->get(i)->hide_gui();
240 plugin_gui_lock->unlock();
241 hide_keyframe_guis();
244 // Give up and go to a movie
245 // cant run valgrind if this is used
246 // if( !reload_status ) exit(0);
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();
285 dead_plugins->remove_all();
287 keyframe_threads->remove_all_objects();
288 if( !edl->Garbage::remove_user() ) edl = 0;
289 colormodels.remove_all_objects();
291 delete render; render = 0;
292 delete awindow; awindow = 0;
293 delete lwindow; lwindow = 0;
294 delete twindow; twindow = 0;
295 delete wwindow; wwindow = 0;
296 delete gwindow; gwindow = 0;
297 // must be last or nouveau chokes
298 delete cwindow; cwindow = 0;
299 //delete file_server; file_server = 0; // reusable
300 delete mainindexes; mainindexes = 0;
301 delete mainprogress; mainprogress = 0;
302 delete audio_cache; audio_cache = 0; // delete the cache after the assets
303 delete video_cache; video_cache = 0; // delete the cache after the assets
304 delete frame_cache; frame_cache = 0;
305 delete wave_cache; wave_cache = 0;
306 delete plugin_guis; plugin_guis = 0;
307 delete dead_plugins; dead_plugins = 0;
308 delete keyframe_threads; keyframe_threads = 0;
309 delete undo; undo = 0;
310 delete preferences; preferences = 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;
316 delete channeldb_buz;
317 delete channeldb_v4l2jpeg;
318 // This must be last thread to exit
319 delete playback_3d; playback_3d = 0;
320 delete dead_plugin_lock;
321 delete plugin_gui_lock;
322 delete vwindows_lock;
324 delete keyframe_gui_lock;
325 sighandler->terminate();
330 void MWindow::quit(int unlock)
333 if(unlock) gui->unlock_window();
335 brender_lock->lock("MWindow::quit");
336 delete brender; brender = 0;
337 brender_lock->unlock();
343 if(unlock) gui->lock_window("MWindow::quit");
346 void MWindow::init_error()
348 MainError::init_error(this);
351 void MWindow::finit_error()
353 MainError::finit_error();
356 void MWindow::create_defaults_path(char *string, const char *config_file)
358 // set the .bcast path
361 sprintf(string, "%s", BCASTDIR);
362 fs.complete_path(string);
363 if(!fs.is_dir(string))
364 fs.create_dir(string);
367 strcat(string, config_file);
370 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
372 char path[BCTEXTLEN];
373 // Use user supplied path
375 strcpy(path, config_path);
377 create_defaults_path(path, CONFIG_FILE);
379 defaults = new BC_Hash(path);
383 int MWindow::load_plugin_index(MWindow *mwindow, char *path)
386 FILE *fp = fopen(path, "r");
388 char index_line[BCTEXTLEN];
389 int index_version = -1, ret = 0;
390 if( !fgets(index_line, BCTEXTLEN, fp) ||
391 sscanf(index_line, "%d", &index_version) != 1 ||
392 index_version != PLUGIN_FILE_VERSION ) ret = 1;
394 while( !ret && !feof(fp)) {
395 if( !fgets(index_line, BCTEXTLEN, fp) ) break;
396 if( index_line[0] == ';' ) continue;
397 if( index_line[0] == '#' ) continue;
398 int type = PLUGIN_TYPE_UNKNOWN;
399 char path[BCTEXTLEN], title[BCTEXTLEN];
400 if( PluginServer::scan_table(index_line, type, path, title) ) continue;
401 PluginServer *server = 0;
403 case PLUGIN_TYPE_BUILTIN:
404 case PLUGIN_TYPE_LADSPA:
405 server = new PluginServer(mwindow, path, type);
407 case PLUGIN_TYPE_FFMPEG: // skip "ff_..."
408 server = new_ffmpeg_server(mwindow, path+3);
411 if( !server ) continue;
412 // Create plugin server from index entry
413 server->set_title(title);
414 if( server->read_table(index_line) ) {
418 plugindb->append(server);
425 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
426 const char *plug_dir, const char *plug_path, int &idx)
428 char plugin_path[BCTEXTLEN];
429 if( *plug_path != '/' )
430 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
432 strcpy(plugin_path, plug_path);
434 fs.set_filter( "[*.plugin][*.so]" );
435 int result = fs.update(plugin_path);
436 if( result || !fs.dir_list.total ) return;
439 for( int i=0; i<fs.dir_list.total; ++i ) {
440 char *fs_path = fs.dir_list.values[i]->path;
441 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
442 const char *dp = plug_dir;
443 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
444 strcpy(plugin_path, !*dp && *bp == '/' ? bp+1 : base_path);
446 if( fs.is_dir(fs_path) ) {
447 init_plugin_index(mwindow, preferences, fp, plug_dir, plugin_path, idx);
450 if( plugin_exists(plugin_path) ) continue;
451 PluginServer *server = new PluginServer(mwindow, plugin_path, PLUGIN_TYPE_UNKNOWN);
452 result = server->open_plugin(1, preferences, 0, 0);
454 server->write_table(fp,vis_id);
455 server->close_plugin();
456 server->delete_this();
459 if( result != PLUGINSERVER_IS_LAD ) continue;
462 PluginServer *server = new PluginServer(mwindow, plugin_path, PLUGIN_TYPE_LADSPA);
463 server->set_lad_index(lad_index++);
464 result = server->open_plugin(1, preferences, 0, 0);
466 server->write_table(fp, PLUGIN_LADSPA_ID);
467 server->close_plugin();
468 server->delete_this();
473 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
476 if( !plugindb ) plugindb = new ArrayList<PluginServer*>;
477 char index_path[BCTEXTLEN];
478 sprintf(index_path, "%s/%s", preferences->plugin_dir, PLUGIN_FILE);
479 if( !load_plugin_index(mwindow, index_path) ) return 1;
480 FILE *fp = fopen(index_path,"w");
482 fprintf(stderr,_("MWindow::init_plugins: "
483 "can't create plugin index: %s\n"), index_path);
486 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
487 char *plug_path = FileSystem::basepath(preferences->plugin_dir);
488 int dir_id = PLUGIN_IDS;
489 init_plugin_index(mwindow, preferences, fp, plug_path, ".", dir_id);
490 init_ffmpeg_index(mwindow, preferences, fp);
493 return load_plugin_index(mwindow, index_path);
496 void MWindow::delete_plugins()
498 plugindb->remove_all_objects();
503 void MWindow::search_plugindb(int do_audio,
508 ArrayList<PluginServer*> &results)
511 for(int i = 0; i < MWindow::plugindb->total; i++)
513 PluginServer *current = MWindow::plugindb->values[i];
515 if(current->audio == do_audio &&
516 current->video == do_video &&
517 (current->realtime == is_realtime || is_realtime < 0) &&
518 current->transition == is_transition &&
519 current->theme == is_theme)
520 results.append(current);
523 // Alphabetize list by title
529 for(int i = 0; i < results.total - 1; i++)
531 PluginServer *value1 = results.values[i];
532 PluginServer *value2 = results.values[i + 1];
533 if(strcmp(_(value1->title), _(value2->title)) > 0)
536 results.values[i] = value2;
537 results.values[i + 1] = value1;
543 PluginServer* MWindow::scan_plugindb(char *title,
548 // printf("MWindow::scan_plugindb data_type < 0\n");
552 for(int i = 0; i < plugindb->total; i++)
554 PluginServer *server = plugindb->values[i];
556 !strcasecmp(server->title, title) &&
558 (data_type == TRACK_AUDIO && server->audio) ||
559 (data_type == TRACK_VIDEO && server->video)))
560 return plugindb->values[i];
565 int MWindow::plugin_exists(char *plugin_path)
567 for( int i=0; i<plugindb->total; ++i ) {
568 PluginServer *server = plugindb->values[i];
569 if( !strcmp(plugin_path, server->get_path()) ) return 1;
574 void MWindow::init_preferences()
576 preferences = new Preferences;
577 preferences->load_defaults(defaults);
578 session = new MainSession(this);
579 session->load_defaults(defaults);
580 // set x11_host, screens, window_config
581 screens = session->set_default_x11_host();
582 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
583 BC_Signals::set_trap_hook(trap_hook, this);
584 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
585 BC_Signals::set_catch_intr(preferences->trap_sigintr);
588 void MWindow::clean_indexes()
593 int oldest_item = -1;
595 char string[BCTEXTLEN];
596 char string2[BCTEXTLEN];
598 // Delete extra indexes
599 fs.set_filter("*.idx");
600 fs.complete_path(preferences->index_directory);
601 fs.update(preferences->index_directory);
602 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
604 // Eliminate directories
609 for(int i = 0; i < fs.dir_list.total && !result; i++)
611 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
612 if(fs.is_dir(string))
614 delete fs.dir_list.values[i];
615 fs.dir_list.remove_number(i);
620 total_excess = fs.dir_list.total - preferences->index_count;
622 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
623 while(total_excess > 0)
626 for(int i = 0; i < fs.dir_list.total; i++)
628 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
630 if(i == 0 || fs.get_date(string) <= oldest)
632 oldest = fs.get_date(string);
640 fs.join_names(string,
641 preferences->index_directory,
642 fs.dir_list.values[oldest_item]->name);
643 //printf("MWindow::clean_indexes 1 %s\n", string);
645 perror("delete_indexes");
646 delete fs.dir_list.values[oldest_item];
647 fs.dir_list.remove_number(oldest_item);
649 // Remove table of contents if it exists
650 strcpy(string2, string);
651 char *ptr = strrchr(string2, '.');
654 //printf("MWindow::clean_indexes 2 %s\n", string2);
655 sprintf(ptr, ".toc");
657 sprintf(ptr, ".mkr");
666 void MWindow::init_awindow()
668 awindow = new AWindow(this);
669 awindow->create_objects();
672 void MWindow::init_gwindow()
674 gwindow = new GWindow(this);
675 gwindow->create_objects();
678 void MWindow::init_tipwindow()
681 twindow = new TipWindow(this);
685 void MWindow::show_warning(int *do_warning, const char *text)
687 if( do_warning && !*do_warning ) return;
689 wwindow = new WWindow(this);
690 wwindow->show_warning(do_warning, text);
693 void MWindow::init_theme()
698 // Replace blond theme with SUV since it doesn't work
699 if(!strcasecmp(preferences->theme, "Blond"))
700 strcpy(preferences->theme, DEFAULT_THEME);
702 PluginServer *theme_plugin = 0;
703 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
704 if( plugindb->values[i]->theme &&
705 !strcasecmp(preferences->theme, plugindb->values[i]->title) )
706 theme_plugin = plugindb->values[i];
710 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
713 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
714 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
716 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
717 if( plugindb->values[i]->theme &&
718 !strcasecmp(DEFAULT_THEME, plugindb->values[i]->title) )
719 theme_plugin = plugindb->values[i];
724 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
728 PluginServer plugin = *theme_plugin;
729 if( plugin.open_plugin(0, preferences, 0, 0) ) {
730 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
731 theme_plugin->title);
735 theme = plugin.new_theme();
736 theme->mwindow = this;
737 strcpy(theme->path, plugin.path);
738 plugin.close_plugin();
740 // Load default images & settings
741 theme->Theme::initialize();
742 // Load user images & settings
744 // Create menus with user colors
745 theme->build_menus();
750 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
753 void MWindow::init_3d()
755 playback_3d = new Playback3D(this);
756 playback_3d->create_objects();
759 void MWindow::init_edl()
762 edl->create_objects();
763 edl->load_defaults(defaults);
764 edl->create_default_tracks();
765 edl->tracks->update_y_pixels(theme);
768 void MWindow::init_compositor()
770 cwindow = new CWindow(this);
771 cwindow->create_objects();
774 void MWindow::init_levelwindow()
776 lwindow = new LevelWindow(this);
777 lwindow->create_objects();
780 VWindow *MWindow::get_viewer(int start_it, int idx)
782 vwindows_lock->lock("MWindow::get_viewer");
783 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows.get(idx) : 0;
784 if( !vwindow ) idx = vwindows.size();
785 while( !vwindow && --idx >= 0 ) {
786 VWindow *vwin = vwindows.get(idx);
787 if( !vwin->is_running() || !vwin->get_edl() )
791 vwindow = new VWindow(this);
792 vwindow->load_defaults();
793 vwindow->create_objects();
794 vwindows.append(vwindow);
796 vwindows_lock->unlock();
797 if( start_it ) vwindow->start();
801 void MWindow::init_cache()
803 audio_cache = new CICache(preferences);
804 video_cache = new CICache(preferences);
805 frame_cache = new FrameCache;
806 wave_cache = new WaveCache;
809 void MWindow::init_channeldb()
811 channeldb_buz->load("channeldb_buz");
812 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
815 void MWindow::init_menus()
817 char string[BCTEXTLEN];
818 BC_CModels::to_text(string, BC_RGB888);
819 colormodels.append(new ColormodelItem(string, BC_RGB888));
820 BC_CModels::to_text(string, BC_RGBA8888);
821 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
822 // BC_CModels::to_text(string, BC_RGB161616);
823 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
824 // BC_CModels::to_text(string, BC_RGBA16161616);
825 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
826 BC_CModels::to_text(string, BC_RGB_FLOAT);
827 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
828 BC_CModels::to_text(string, BC_RGBA_FLOAT);
829 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
830 BC_CModels::to_text(string, BC_YUV888);
831 colormodels.append(new ColormodelItem(string, BC_YUV888));
832 BC_CModels::to_text(string, BC_YUVA8888);
833 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
834 // BC_CModels::to_text(string, BC_YUV161616);
835 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
836 // BC_CModels::to_text(string, BC_YUVA16161616);
837 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
840 void MWindow::init_indexes()
842 mainindexes = new MainIndexes(this);
843 mainindexes->start_loop();
846 void MWindow::init_gui()
848 gui = new MWindowGUI(this);
849 gui->lock_window("MWindow::init_gui");
850 gui->create_objects();
851 gui->unlock_window();
852 gui->load_defaults(defaults);
855 void MWindow::init_signals()
857 sighandler = new SigHandler;
858 sighandler->initialize();
862 void MWindow::init_render()
864 render = new Render(this);
865 create_bd = new CreateBD_Thread(this);
866 create_dvd = new CreateDVD_Thread(this);
867 batch_render = new BatchRenderThread(this);
870 void MWindow::init_brender()
872 if(preferences->use_brender && !brender)
874 brender_lock->lock("MWindow::init_brender 1");
875 brender = new BRender(this);
876 brender->initialize();
877 session->brender_end = 0;
878 brender_lock->unlock();
881 if(!preferences->use_brender && brender)
883 brender_lock->lock("MWindow::init_brender 2");
886 session->brender_end = 0;
887 brender_lock->unlock();
889 if(brender) brender->restart(edl);
892 void MWindow::restart_brender()
894 //printf("MWindow::restart_brender 1\n");
895 if(brender) brender->restart(edl);
898 void MWindow::stop_brender()
900 if(brender) brender->stop();
903 int MWindow::brender_available(int position)
906 brender_lock->lock("MWindow::brender_available 1");
909 if(brender->map_valid)
911 brender->map_lock->lock("MWindow::brender_available 2");
912 if(position < brender->map_size &&
915 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
916 if(brender->map[position] == BRender::RENDERED)
919 brender->map_lock->unlock();
922 brender_lock->unlock();
926 void MWindow::set_brender_start()
928 edl->session->brender_start = edl->local_session->get_selectionstart(1);
930 gui->draw_overlays(1);
934 int MWindow::has_commercials()
936 return theme->use_commercials;
939 void MWindow::init_commercials()
942 commercials = new Commercials(this);
943 commercial_active = 0;
946 commercials->add_user();
949 void MWindow::commit_commercial()
951 if( !commercial_active ) return;
952 commercial_active = 0;
953 if( !commercials ) return;
954 commercials->commitDb();
957 void MWindow::undo_commercial()
959 if( !commercial_active ) return;
960 commercial_active = 0;
961 if( !commercials ) return;
962 commercials->undoDb();
965 int MWindow::put_commercial()
967 double start = edl->local_session->get_selectionstart();
968 double end = edl->local_session->get_selectionend();
969 if( start >= end ) return 0;
971 const char *errmsg = 0;
973 Tracks *tracks = edl->tracks;
976 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
977 if( track->data_type != TRACK_VIDEO ) continue;
978 if( !track->record ) continue;
979 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
981 int64_t units_start = track->to_units(start,0);
982 int64_t units_end = track->to_units(end,0);
983 Edits *edits = track->edits;
984 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
985 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
986 if(!edit1 && !edit2) continue; // nothing selected
987 if(!edit2) { // edit2 beyond end of track
989 units_end = edits->length();
991 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
992 Indexable *indexable = edit1->get_source();
993 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
996 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
997 if( track->data_type != TRACK_VIDEO ) continue;
998 if( !track->record ) continue;
999 int64_t units_start = track->to_units(start,0);
1000 int64_t units_end = track->to_units(end,0);
1001 Edits *edits = track->edits;
1002 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1003 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1004 if(!edit1 && !edit2) continue; // nothing selected
1005 if(!edit2) { // edit2 beyond end of track
1006 edit2 = edits->last;
1007 units_end = edits->length();
1009 Indexable *indexable = edit1->get_source();
1010 Asset *asset = (Asset *)indexable;
1011 File *file = video_cache->check_out(asset, edl);
1012 if( !file ) { errmsg = _("no file"); break; }
1013 int64_t edit_length = units_end - units_start;
1014 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1015 result = commercials->put_clip(file, edit1->channel,
1016 track->from_units(edit_start), track->from_units(edit_length));
1017 video_cache->check_in(asset);
1018 if( result ) { errmsg = _("db failed"); break; }
1021 char string[BCTEXTLEN];
1022 sprintf(string, _("put_commercial: %s"), errmsg);
1023 MainError::show_error(string);
1030 void MWindow::stop_playback(int wait)
1032 int locked = gui->get_window_lock();
1033 if( locked ) gui->unlock_window();
1035 cwindow->playback_engine->que->send_command(STOP,
1039 cwindow->playback_engine->interrupt_playback(wait);
1041 for(int i = 0; i < vwindows.size(); i++) {
1042 VWindow *vwindow = vwindows.get(i);
1043 if( !vwindow->is_running() ) continue;
1044 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1045 vwindow->playback_engine->interrupt_playback(wait);
1047 if( locked ) gui->lock_window("MWindow::stop_playback");
1050 int MWindow::load_filenames(ArrayList<char*> *filenames,
1052 int update_filename)
1054 ArrayList<EDL*> new_edls;
1055 ArrayList<Asset*> new_assets;
1056 ArrayList<File*> new_files;
1057 const int debug = 0;
1058 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1061 gui->start_hourglass();
1063 // Need to stop playback since tracking depends on the EDL not getting
1067 undo->update_undo_before();
1070 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1072 // Define new_edls and new_assets to load
1073 int result = 0, ftype = -1;
1074 for(int i = 0; i < filenames->total; i++)
1077 File *new_file = new File;
1078 Asset *new_asset = new Asset(filenames->values[i]);
1079 EDL *new_edl = new EDL;
1080 char string[BCTEXTLEN];
1082 new_edl->create_objects();
1083 new_edl->copy_session(edl);
1084 new_file->set_program(edl->session->program_no);
1086 sprintf(string, _("Loading %s"), new_asset->path);
1087 gui->show_message(string);
1088 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1090 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1091 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1096 // Convert media file to EDL
1098 // Warn about odd image dimensions
1099 if(new_asset->video_data &&
1100 ((new_asset->width % 2) ||
1101 (new_asset->height % 2)))
1103 char string[BCTEXTLEN];
1104 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1108 MainError::show_error(string);
1111 if(new_asset->program >= 0 &&
1112 edl->session->program_no != new_asset->program)
1114 char string[BCTEXTLEN];
1115 sprintf(string, _("%s's index was built for program number %d\n"
1116 "Playback preference is %d.\n Using program %d."),
1117 new_asset->path, new_asset->program,
1118 edl->session->program_no, new_asset->program);
1119 MainError::show_error(string);
1123 if(load_mode != LOADMODE_RESOURCESONLY)
1126 RecordLabels *labels = edl->session->label_cells ?
1127 new RecordLabels(new_file) : 0;
1129 asset_to_edl(new_edl, new_asset, labels);
1131 new_edls.append(new_edl);
1133 new_asset->Garbage::remove_user();
1139 new_assets.append(new_asset);
1143 // Set filename to nothing for assets since save EDL would overwrite them.
1144 if(load_mode == LOADMODE_REPLACE ||
1145 load_mode == LOADMODE_REPLACE_CONCATENATE)
1148 // Reset timeline position
1149 for(int i = 0; i < TOTAL_PANES; i++)
1151 new_edl->local_session->view_start[i] = 0;
1152 new_edl->local_session->track_start[i] = 0;
1160 case FILE_NOT_FOUND:
1161 sprintf(string, _("Failed to open %s"), new_asset->path);
1162 gui->show_message(string, theme->message_error);
1166 case FILE_UNRECOGNIZED_CODEC:
1169 IndexFile indexfile(this, new_asset);
1170 result = indexfile.open_index();
1173 indexfile.close_index();
1176 // Test existing EDLs
1179 for(int j = 0; j < new_edls.total + 1; j++)
1182 if(j == new_edls.total)
1184 old_asset = edl->assets->get_asset(new_asset->path);
1187 *new_asset = *old_asset;
1193 old_asset = new_edls.values[j]->assets->get_asset(new_asset->path);
1196 *new_asset = *old_asset;
1206 char string[BCTEXTLEN];
1208 fs.extract_name(string, new_asset->path);
1210 strcat(string, _("'s format couldn't be determined."));
1211 new_asset->audio_data = 1;
1212 new_asset->format = FILE_PCM;
1213 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1214 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1215 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1216 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1217 new_asset->signed_ = defaults->get("SIGNED_", 1);
1218 new_asset->header = defaults->get("HEADER", 0);
1220 FileFormat fwindow(this);
1221 fwindow.create_objects(new_asset, string);
1222 result = fwindow.run_window();
1225 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1226 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1227 defaults->update("AUDIO_BITS", new_asset->bits);
1228 defaults->update("BYTE_ORDER", new_asset->byte_order);
1229 defaults->update("SIGNED_", new_asset->signed_);
1230 defaults->update("HEADER", new_asset->header);
1237 // Recalculate length
1239 new_file = new File;
1240 result = new_file->open_file(preferences, new_asset, 1, 0);
1242 if(load_mode != LOADMODE_RESOURCESONLY)
1244 RecordLabels *labels = edl->session->label_cells ?
1245 new RecordLabels(new_file) : 0;
1246 asset_to_edl(new_edl, new_asset, labels);
1247 new_edls.append(new_edl);
1248 new_asset->Garbage::remove_user();
1254 new_assets.append(new_asset);
1268 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1269 xml_file.read_from_file(filenames->values[i]);
1270 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1272 if(load_mode == LOADMODE_NESTED)
1274 // Load temporary EDL for nesting.
1275 EDL *nested_edl = new EDL;
1276 nested_edl->create_objects();
1277 nested_edl->set_path(filenames->values[i]);
1278 nested_edl->load_xml(&xml_file, LOAD_ALL);
1279 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1280 edl_to_nested(new_edl, nested_edl);
1281 nested_edl->Garbage::remove_user();
1285 // Load EDL for pasting
1286 new_edl->load_xml(&xml_file, LOAD_ALL);
1287 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1288 test_plugins(new_edl, filenames->values[i]);
1289 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1291 if(load_mode == LOADMODE_REPLACE ||
1292 load_mode == LOADMODE_REPLACE_CONCATENATE)
1294 strcpy(session->filename, filenames->values[i]);
1295 strcpy(new_edl->local_session->clip_title,
1296 filenames->values[i]);
1298 set_filename(new_edl->local_session->clip_title);
1302 new_edls.append(new_edl);
1308 // edls are in new_edls
1309 if( result && new_edl ) new_edl->Garbage::remove_user();
1310 // assets are copied
1311 if( new_asset ) new_asset->Garbage::remove_user();
1313 // Store for testing index
1314 new_files.append(new_file);
1317 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1320 if(!result) gui->statusbar->default_message();
1328 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1331 // Don't back up here.
1334 // For pasting, clear the active region
1335 if(load_mode == LOADMODE_PASTE ||
1336 load_mode == LOADMODE_NESTED)
1338 double start = edl->local_session->get_selectionstart();
1339 double end = edl->local_session->get_selectionend();
1340 if(!EQUIV(start, end))
1343 edl->session->labels_follow_edits,
1344 edl->session->plugins_follow_edits,
1345 edl->session->autos_follow_edits);
1348 paste_edls(&new_edls,
1352 edl->session->labels_follow_edits,
1353 edl->session->plugins_follow_edits,
1354 edl->session->autos_follow_edits);
1360 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1362 // Add new assets to EDL and schedule assets for index building.
1363 int got_indexes = 0;
1364 for(int i = 0; i < new_edls.size(); i++)
1366 EDL *new_edl = new_edls.get(i);
1367 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1369 mainindexes->add_next_asset(0,
1370 new_edl->nested_edls->get(j));
1372 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1377 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1378 if(new_assets.size())
1380 for(int i = 0; i < new_assets.size(); i++)
1382 Asset *new_asset = new_assets.get(i);
1386 for(int j = 0; j < new_files.size(); j++)
1388 new_file = new_files.get(j);
1389 if(!strcmp(new_file->asset->path,
1397 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1399 edl->assets->update(new_asset);
1405 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1407 // Start examining next batch of index files
1408 if(got_indexes) mainindexes->start_build();
1409 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1412 Track *track = edl->tracks->first;
1415 for(int j = 0; j < track->plugin_set.size(); j++)
1417 PluginSet *plugins = track->plugin_set.get(j);
1418 Plugin *plugin = plugins->get_first_plugin();
1422 if(load_mode == LOADMODE_REPLACE ||
1423 load_mode == LOADMODE_REPLACE_CONCATENATE)
1425 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1428 show_plugin(plugin);
1436 plugin = (Plugin*)plugin->next;
1440 track = track->next;
1443 // if just opening one new resource in replace mode
1444 if( load_mode == LOADMODE_REPLACE && new_edls.size() == 1 &&
1445 ftype != FILE_IS_XML )
1448 edl->local_session->preview_start = 0;
1449 edl->local_session->preview_end = edl->tracks->total_playable_length();
1450 edl->local_session->loop_playback = 0;
1451 edl->local_session->set_selectionstart(0);
1452 edl->local_session->set_selectionend(0);
1458 update_project(load_mode);
1460 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1462 for(int i = 0; i < new_edls.size(); i++)
1464 new_edls.get(i)->remove_user();
1466 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1468 new_edls.remove_all();
1470 for(int i = 0; i < new_assets.size(); i++)
1472 new_assets.get(i)->Garbage::remove_user();
1475 new_assets.remove_all();
1476 new_files.remove_all_objects();
1478 undo->update_undo_after(_("load"), LOAD_ALL);
1480 if(load_mode == LOADMODE_REPLACE ||
1481 load_mode == LOADMODE_REPLACE_CONCATENATE)
1483 session->changes_made = 0;
1487 session->changes_made = 1;
1490 gui->stop_hourglass();
1493 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1500 void MWindow::test_plugins(EDL *new_edl, char *path)
1502 char string[BCTEXTLEN];
1504 // Do a check weather plugins exist
1505 for(Track *track = new_edl->tracks->first; track; track = track->next)
1507 for(int k = 0; k < track->plugin_set.total; k++)
1509 PluginSet *plugin_set = track->plugin_set.values[k];
1510 for(Plugin *plugin = (Plugin*)plugin_set->first;
1512 plugin = (Plugin*)plugin->next)
1514 if(plugin->plugin_type == PLUGIN_STANDALONE)
1516 // ok we need to find it in plugindb
1517 int plugin_found = 0;
1519 for(int j = 0; j < plugindb->size(); j++)
1521 PluginServer *server = plugindb->get(j);
1523 !strcasecmp(server->title, plugin->title) &&
1524 ((track->data_type == TRACK_AUDIO && server->audio) ||
1525 (track->data_type == TRACK_VIDEO && server->video)) &&
1526 (!server->transition))
1533 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1534 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1535 "effect", plugin->title,
1537 MainError::show_error(string);
1543 for(Edit *edit = (Edit*)track->edits->first;
1545 edit = (Edit*)edit->next)
1547 if (edit->transition)
1549 // ok we need to find transition in plugindb
1551 int transition_found = 0;
1552 for(int j = 0; j < plugindb->size(); j++)
1554 PluginServer *server = plugindb->get(j);
1556 !strcasecmp(server->title, edit->transition->title) &&
1557 ((track->data_type == TRACK_AUDIO && server->audio) ||
1558 (track->data_type == TRACK_VIDEO && server->video)) &&
1559 (server->transition))
1560 transition_found = 1;
1563 if (!transition_found)
1566 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1567 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1568 "transition", edit->transition->title,
1570 MainError::show_error(string);
1578 void MWindow::init_shm()
1580 // Fix shared memory
1581 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1583 fprintf(fd, "0x7fffffff");
1588 fd = fopen("/proc/sys/kernel/shmmax", "r");
1590 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1595 fscanf(fd, _LD, &result);
1598 if(result < 0x7fffffff) {
1599 char string[BCTEXTLEN];
1600 sprintf(string, _("MWindow::init_shm: /proc/sys/kernel/shmmax is 0x" _LX ".\n"
1601 "you probably need to be root, or:\n"
1602 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1603 "before trying to start cinelerra.\n"
1604 "It should be at least 0x7fffffff for Cinelerra.\n"), result);
1605 MainError::show_error(string);
1610 void MWindow::init_fileserver(Preferences *preferences)
1613 if( !file_server && preferences->file_forking ) {
1614 file_server = new FileServer(preferences);
1615 file_server->start();
1620 void MWindow::create_objects(int want_gui,
1625 const int debug = 0;
1626 if(debug) PRINT_TRACE
1628 // For some reason, init_signals must come after show_splash or the signals won't
1631 if(debug) PRINT_TRACE
1634 if(debug) PRINT_TRACE
1637 if(debug) PRINT_TRACE
1638 init_defaults(defaults, config_path);
1640 init_plugins(this, preferences);
1641 if(debug) PRINT_TRACE
1642 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1643 if(debug) PRINT_TRACE
1645 if(debug) PRINT_TRACE
1648 char string[BCTEXTLEN];
1649 strcpy(string, preferences->plugin_dir);
1650 strcat(string, "/fonts");
1651 BC_Resources::init_fontconfig(string);
1652 if(debug) PRINT_TRACE
1654 // Initialize before too much else is running
1655 // Preferences & theme are required for building MPEG table of contents
1656 init_fileserver(preferences);
1658 // Default project created here
1660 if(debug) PRINT_TRACE
1663 if(debug) PRINT_TRACE
1668 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1670 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1671 if(session->show_vwindow)
1672 get_viewer(1, DEFAULT_VWINDOW);
1673 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1676 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1679 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1682 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1684 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1687 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1691 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1693 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1695 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1698 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1699 mainprogress = new MainProgress(this, gui);
1700 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1701 undo = new MainUndo(this);
1703 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1705 plugin_guis = new ArrayList<PluginServer*>;
1706 dead_plugins = new ArrayList<PluginServer*>;
1707 keyframe_threads = new ArrayList<KeyFrameThread*>;
1709 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1712 session->show_vwindow);
1714 // Show all vwindows
1715 // if(session->show_vwindow) {
1716 // for(int j = 0; j < vwindows.size(); j++) {
1717 // VWindow *vwindow = vwindows.get(j);
1718 // if( !vwindow->is_running() ) continue;
1719 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1722 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1723 // vwindow->gui->lock_window("MWindow::create_objects 1");
1724 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1725 // vwindow->gui->show_window();
1726 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1727 // vwindow->gui->unlock_window();
1732 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1734 if(session->show_cwindow)
1736 cwindow->gui->lock_window("MWindow::create_objects 1");
1737 cwindow->gui->show_window();
1738 cwindow->gui->unlock_window();
1741 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1742 if(session->show_awindow)
1744 awindow->gui->lock_window("MWindow::create_objects 1");
1745 awindow->gui->show_window();
1746 awindow->gui->unlock_window();
1749 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1750 if(session->show_lwindow)
1752 lwindow->gui->lock_window("MWindow::create_objects 1");
1753 lwindow->gui->show_window();
1754 lwindow->gui->unlock_window();
1757 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1759 (int)timer.get_difference(),
1761 if(session->show_gwindow)
1763 gwindow->gui->lock_window("MWindow::create_objects 1");
1764 gwindow->gui->show_window();
1765 gwindow->gui->unlock_window();
1768 if(debug) PRINT_TRACE
1770 gui->lock_window("MWindow::create_objects 1");
1771 gui->mainmenu->load_defaults(defaults);
1772 gui->mainmenu->update_toggles(0);
1773 gui->update_patchbay();
1774 gui->draw_canvas(0, 0);
1775 gui->draw_cursor(1);
1777 gui->raise_window();
1778 gui->unlock_window();
1780 if(debug) PRINT_TRACE
1784 if(preferences->use_tipwindow)
1786 if(debug) PRINT_TRACE
1788 gui->add_keyboard_listener(
1789 (int (BC_WindowBase::*)(BC_WindowBase *))
1790 &MWindowGUI::keyboard_listener);
1794 if(debug) PRINT_TRACE
1796 BC_WindowBase::get_resources()->vframe_shm = 1;
1801 void MWindow::show_splash()
1803 #include "data/heroine_logo11_png.h"
1804 VFrame *frame = new VFrame(heroine_logo11_png);
1805 BC_DisplayInfo display_info;
1806 splash_window = new SplashGUI(frame,
1807 display_info.get_root_w() / 2 - frame->get_w() / 2,
1808 display_info.get_root_h() / 2 - frame->get_h() / 2);
1809 splash_window->create_objects();
1812 void MWindow::hide_splash()
1815 delete splash_window;
1820 void MWindow::start()
1824 // vwindows.get(DEFAULT_VWINDOW)->start();
1835 playback_3d->start();
1844 void MWindow::show_vwindow()
1846 int total_running = 0;
1847 session->show_vwindow = 1;
1849 // Raise all windows which are visible
1850 for(int j = 0; j < vwindows.size(); j++) {
1851 VWindow *vwindow = vwindows.get(j);
1852 if( !vwindow->is_running() ) continue;
1853 vwindow->gui->lock_window("MWindow::show_vwindow");
1854 vwindow->gui->show_window(0);
1855 vwindow->gui->raise_window();
1856 vwindow->gui->flush();
1857 vwindow->gui->unlock_window();
1861 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
1862 // If no windows visible
1865 get_viewer(1, DEFAULT_VWINDOW);
1868 gui->mainmenu->show_vwindow->set_checked(1);
1871 void MWindow::show_awindow()
1873 session->show_awindow = 1;
1874 awindow->gui->lock_window("MWindow::show_awindow");
1875 awindow->gui->show_window();
1876 awindow->gui->raise_window();
1877 awindow->gui->flush();
1878 awindow->gui->unlock_window();
1879 gui->mainmenu->show_awindow->set_checked(1);
1882 char *MWindow::get_cwindow_display()
1884 char *x11_host = screens < 2 || session->window_config == 0 ?
1885 session->a_x11_host : session->b_x11_host;
1886 return *x11_host ? x11_host : 0;
1889 void MWindow::show_cwindow()
1891 session->show_cwindow = 1;
1892 cwindow->show_window();
1893 gui->mainmenu->show_cwindow->set_checked(1);
1896 void MWindow::show_gwindow()
1898 session->show_gwindow = 1;
1900 gwindow->gui->lock_window("MWindow::show_gwindow");
1901 gwindow->gui->show_window();
1902 gwindow->gui->raise_window();
1903 gwindow->gui->flush();
1904 gwindow->gui->unlock_window();
1906 gui->mainmenu->show_gwindow->set_checked(1);
1909 void MWindow::show_lwindow()
1911 session->show_lwindow = 1;
1912 lwindow->gui->lock_window("MWindow::show_lwindow");
1913 lwindow->gui->show_window();
1914 lwindow->gui->raise_window();
1915 lwindow->gui->flush();
1916 lwindow->gui->unlock_window();
1917 gui->mainmenu->show_lwindow->set_checked(1);
1920 int MWindow::tile_windows(int window_config)
1922 int need_reload = 0;
1923 int play_config = window_config==0 ? 0 : 1;
1924 edl->session->playback_config->load_defaults(defaults, play_config);
1925 session->default_window_positions(window_config);
1926 if( screens == 1 ) {
1927 gui->default_positions();
1928 sync_parameters(CHANGE_ALL);
1935 void MWindow::toggle_loop_playback()
1937 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1938 set_loop_boundaries();
1941 gui->draw_overlays(1);
1942 sync_parameters(CHANGE_PARAMS);
1945 //void MWindow::set_titles(int value)
1947 // edl->session->show_titles = value;
1948 // trackmovement(edl->local_session->track_start);
1951 void MWindow::set_screens(int value)
1956 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
1958 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
1959 edl->session->auto_keyframes = value;
1960 gui->mbuttons->edit_panel->keyframe->update(value);
1962 if(lock_mwindow) gui->unlock_window();
1964 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1965 cwindow->gui->edit_panel->keyframe->update(value);
1966 cwindow->gui->flush();
1967 if(lock_cwindow) cwindow->gui->unlock_window();
1970 void MWindow::set_keyframe_type(int mode)
1972 gui->lock_window("MWindow::set_keyframe_type");
1973 edl->local_session->floatauto_type = mode;
1974 gui->mainmenu->update_toggles(0);
1975 gui->unlock_window();
1978 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
1980 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
1981 edl->session->editing_mode = new_editing_mode;
1982 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1983 gui->mbuttons->edit_panel->update();
1984 gui->set_editing_mode(1);
1985 if(lock_mwindow) gui->unlock_window();
1988 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
1989 cwindow->gui->edit_panel->update();
1990 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1991 if(lock_cwindow) cwindow->gui->unlock_window();
1996 void MWindow::sync_parameters(int change_type)
1998 if( in_destructor ) return;
2000 // Sync engines which are playing back
2001 if(cwindow->playback_engine->is_playing_back)
2003 if(change_type == CHANGE_PARAMS)
2005 // TODO: block keyframes until synchronization is done
2006 cwindow->playback_engine->sync_parameters(edl);
2011 int command = cwindow->playback_engine->command->command;
2012 cwindow->playback_engine->que->send_command(STOP,
2016 // Waiting for tracking to finish would make the restart position more
2017 // accurate but it can't lock the window to stop tracking for some reason.
2018 // Not waiting for tracking gives a faster response but restart position is
2019 // only as accurate as the last tracking update.
2020 cwindow->playback_engine->interrupt_playback(0);
2021 cwindow->playback_engine->que->send_command(command,
2030 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2037 void MWindow::age_caches()
2039 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2041 // preferences->cache_size,
2042 // audio_cache->get_memory_usage(1),
2043 // video_cache->get_memory_usage(1),
2044 // frame_cache->get_memory_usage(),
2045 // wave_cache->get_memory_usage(),
2047 frame_cache->age_cache(512);
2048 wave_cache->age_cache(8192);
2050 int64_t memory_usage;
2051 int64_t prev_memory_usage = 0;
2053 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2054 while( !result && prev_memory_usage !=
2055 (memory_usage=video_cache->get_memory_usage(1)) &&
2056 memory_usage > video_size ) {
2057 video_cache->delete_oldest();
2058 prev_memory_usage = memory_usage;
2061 prev_memory_usage = 0;
2063 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2064 while( !result && prev_memory_usage !=
2065 (memory_usage=audio_cache->get_memory_usage(1)) &&
2066 memory_usage > audio_size ) {
2067 audio_cache->delete_oldest();
2068 prev_memory_usage = memory_usage;
2072 void MWindow::reset_android_remote()
2074 gui->use_android_remote(preferences->android_remote);
2078 void MWindow::show_keyframe_gui(Plugin *plugin)
2080 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2081 // Find existing thread
2082 for(int i = 0; i < keyframe_threads->size(); i++)
2084 if(keyframe_threads->get(i)->plugin == plugin)
2086 keyframe_threads->get(i)->start_window(plugin, 0);
2087 keyframe_gui_lock->unlock();
2092 // Find unused thread
2093 for(int i = 0; i < keyframe_threads->size(); i++)
2095 if(!keyframe_threads->get(i)->plugin)
2097 keyframe_threads->get(i)->start_window(plugin, 0);
2098 keyframe_gui_lock->unlock();
2103 // Create new thread
2104 KeyFrameThread *thread = new KeyFrameThread(this);
2105 keyframe_threads->append(thread);
2106 thread->start_window(plugin, 0);
2108 keyframe_gui_lock->unlock();
2115 void MWindow::show_plugin(Plugin *plugin)
2120 // Remove previously deleted plugin GUIs
2121 dead_plugin_lock->lock("MWindow::delete_plugin");
2122 for(int i = 0; i < dead_plugins->size(); i++)
2124 delete dead_plugins->get(i);
2126 dead_plugins->remove_all();
2127 dead_plugin_lock->unlock();
2129 //printf("MWindow::show_plugin %d\n", __LINE__);
2133 plugin_gui_lock->lock("MWindow::show_plugin");
2134 for(int i = 0; i < plugin_guis->total; i++)
2136 // Pointer comparison
2137 if(plugin_guis->values[i]->plugin == plugin)
2139 plugin_guis->values[i]->raise_window();
2146 //printf("MWindow::show_plugin 1\n");
2151 printf("MWindow::show_plugin track not defined.\n");
2153 PluginServer *server = scan_plugindb(plugin->title,
2154 plugin->track->data_type);
2156 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2157 if(server && server->uses_gui)
2159 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
2160 // Needs mwindow to do GUI
2161 gui->set_mwindow(this);
2162 gui->open_plugin(0, preferences, edl, plugin);
2167 plugin_gui_lock->unlock();
2168 //printf("MWindow::show_plugin %d\n", __LINE__);
2171 //printf("MWindow::show_plugin 2\n");
2174 void MWindow::hide_plugin(Plugin *plugin, int lock)
2177 // Update the toggle
2178 gui->lock_window("MWindow::hide_plugin");
2179 gui->update(0, 1, 0, 0, 0, 0, 0);
2180 gui->unlock_window();
2182 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2183 for(int i = 0; i < plugin_guis->total; i++)
2185 if(plugin_guis->values[i]->plugin == plugin)
2187 PluginServer *ptr = plugin_guis->values[i];
2188 plugin_guis->remove(ptr);
2189 if(lock) plugin_gui_lock->unlock();
2190 // Last command executed in client side close
2191 // Schedule for deletion
2198 if(lock) plugin_gui_lock->unlock();
2201 void MWindow::delete_plugin(PluginServer *plugin)
2203 dead_plugin_lock->lock("MWindow::delete_plugin");
2204 dead_plugins->append(plugin);
2205 dead_plugin_lock->unlock();
2208 void MWindow::hide_plugins()
2210 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2211 while(plugin_guis->size())
2213 PluginServer *ptr = plugin_guis->get(0);
2214 plugin_guis->remove(ptr);
2215 plugin_gui_lock->unlock();
2216 // Last command executed in client side close
2217 // Schedule for deletion
2220 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2222 plugin_gui_lock->unlock();
2224 hide_keyframe_guis();
2227 void MWindow::hide_keyframe_guis()
2229 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2230 for(int i = 0; i < keyframe_threads->size(); i++)
2232 keyframe_threads->get(i)->close_window();
2234 keyframe_gui_lock->unlock();
2237 void MWindow::hide_keyframe_gui(Plugin *plugin)
2239 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2240 for(int i = 0; i < keyframe_threads->size(); i++)
2242 if(keyframe_threads->get(i)->plugin == plugin)
2244 keyframe_threads->get(i)->close_window();
2248 keyframe_gui_lock->unlock();
2251 void MWindow::update_keyframe_guis()
2253 // Send new configuration to keyframe GUI's
2254 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2255 for(int i = 0; i < keyframe_threads->size(); i++)
2257 KeyFrameThread *ptr = keyframe_threads->get(i);
2258 if(edl->tracks->plugin_exists(ptr->plugin))
2262 ptr->close_window();
2265 keyframe_gui_lock->unlock();
2268 void MWindow::update_plugin_guis(int do_keyframe_guis)
2270 // Send new configuration to plugin GUI's
2271 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2273 for(int i = 0; i < plugin_guis->size(); i++)
2275 PluginServer *ptr = plugin_guis->get(i);
2276 if(edl->tracks->plugin_exists(ptr->plugin))
2280 // Schedule for deletion if no plugin
2281 plugin_guis->remove_number(i);
2290 // Change plugin variable if not visible
2291 Track *track = edl->tracks->first;
2294 for(int i = 0; i < track->plugin_set.size(); i++)
2296 Plugin *plugin = (Plugin*)track->plugin_set.get(i)->first;
2300 for(int i = 0; i < plugin_guis->size(); i++)
2302 PluginServer *server = plugin_guis->get(i);
2303 if(server->plugin == plugin)
2310 if(!got_it) plugin->show = 0;
2312 plugin = (Plugin*)plugin->next;
2316 track = track->next;
2319 plugin_gui_lock->unlock();
2322 if(do_keyframe_guis) update_keyframe_guis();
2325 int MWindow::plugin_gui_open(Plugin *plugin)
2328 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2329 for(int i = 0; i < plugin_guis->total; i++)
2331 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2337 plugin_gui_lock->unlock();
2341 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2343 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2344 for(int i = 0; i < plugin_guis->total; i++)
2346 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2348 plugin_guis->values[i]->render_gui(data);
2352 plugin_gui_lock->unlock();
2355 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2357 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2358 for(int i = 0; i < plugin_guis->total; i++)
2360 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2362 plugin_guis->values[i]->render_gui(data, size);
2366 plugin_gui_lock->unlock();
2370 void MWindow::update_plugin_states()
2372 plugin_gui_lock->lock("MWindow::update_plugin_states");
2373 for(int i = 0; i < plugin_guis->total; i++)
2377 Plugin *src_plugin = plugin_guis->values[i]->plugin;
2378 PluginServer *src_plugingui = plugin_guis->values[i];
2380 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2381 for(Track *track = edl->tracks->first;
2383 track = track->next)
2386 j < track->plugin_set.total && !result;
2389 PluginSet *plugin_set = track->plugin_set.values[j];
2390 for(Plugin *plugin = (Plugin*)plugin_set->first;
2392 plugin = (Plugin*)plugin->next)
2394 if(plugin == src_plugin &&
2395 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2401 // Doesn't exist anymore
2404 hide_plugin(src_plugin, 0);
2408 plugin_gui_lock->unlock();
2412 void MWindow::update_plugin_titles()
2414 for(int i = 0; i < plugin_guis->total; i++)
2416 plugin_guis->values[i]->update_title();
2420 int MWindow::asset_to_edl(EDL *new_edl,
2422 RecordLabels *labels)
2424 const int debug = 0;
2425 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2428 // Keep frame rate, sample rate, and output size unchanged.
2429 // These parameters would revert the project if VWindow displayed an asset
2430 // of different size than the project.
2431 if(new_asset->video_data)
2433 new_edl->session->video_tracks = new_asset->layers;
2436 new_edl->session->video_tracks = 0;
2438 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2444 if(new_asset->audio_data)
2446 new_edl->session->audio_tracks = new_asset->channels;
2449 new_edl->session->audio_tracks = 0;
2450 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2452 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2453 new_edl->create_default_tracks();
2454 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2455 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2459 //printf("MWindow::asset_to_edl 3\n");
2460 new_edl->insert_asset(new_asset,
2465 //printf("MWindow::asset_to_edl 3\n");
2466 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2472 char string[BCTEXTLEN];
2474 fs.extract_name(string, new_asset->path);
2475 //printf("MWindow::asset_to_edl 3\n");
2477 strcpy(new_edl->local_session->clip_title, string);
2478 //printf("MWindow::asset_to_edl 4 %s\n", string);
2479 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2484 int MWindow::edl_to_nested(EDL *new_edl,
2488 // Keep frame rate, sample rate, and output size unchanged.
2489 // These parameters would revert the project if VWindow displayed an asset
2490 // of different size than the project.
2494 // Nest all video & audio outputs
2495 new_edl->session->video_tracks = 1;
2496 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2497 new_edl->create_default_tracks();
2501 new_edl->insert_asset(0,
2507 char string[BCTEXTLEN];
2509 fs.extract_name(string, nested_edl->path);
2510 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2512 strcpy(new_edl->local_session->clip_title, string);
2517 // Reset everything after a load.
2518 void MWindow::update_project(int load_mode)
2520 const int debug = 0;
2522 if(debug) PRINT_TRACE
2524 edl->tracks->update_y_pixels(theme);
2526 if(debug) PRINT_TRACE
2528 if(load_mode == LOADMODE_REPLACE ||
2529 load_mode == LOADMODE_REPLACE_CONCATENATE)
2534 gui->update(1, 1, 1, 1, 1, 1, 1);
2535 if(debug) PRINT_TRACE
2536 gui->unlock_window();
2538 cwindow->gui->lock_window("MWindow::update_project 1");
2539 cwindow->update(0, 0, 1, 1, 1);
2540 cwindow->gui->unlock_window();
2542 if(debug) PRINT_TRACE
2544 // Close all the vwindows
2545 if(load_mode == LOADMODE_REPLACE ||
2546 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2547 if(debug) PRINT_TRACE
2548 int first_vwindow = 0;
2549 if(session->show_vwindow) first_vwindow = 1;
2550 // Change visible windows to no source
2551 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2552 VWindow *vwindow = vwindows.get(i);
2553 if( !vwindow->is_running() ) continue;
2554 vwindow->change_source(-1);
2557 // Close remaining windows
2558 for(int i = first_vwindow; i < vwindows.size(); i++) {
2559 VWindow *vwindow = vwindows.get(i);
2560 if( !vwindow->is_running() ) continue;
2561 vwindow->close_window();
2563 if(debug) PRINT_TRACE
2565 else if(vwindows.size()) {
2566 VWindow *vwindow = vwindows.get(DEFAULT_VWINDOW);
2567 if( vwindow->is_running() ) {
2568 vwindow->gui->lock_window("MWindow::update_project");
2570 vwindow->gui->unlock_window();
2574 if(debug) PRINT_TRACE
2575 cwindow->gui->lock_window("MWindow::update_project 2");
2576 cwindow->gui->timebar->update(0);
2577 cwindow->gui->unlock_window();
2579 if(debug) PRINT_TRACE
2580 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2585 if(debug) PRINT_TRACE
2587 awindow->gui->lock_window("MWindow::update_project");
2588 awindow->gui->update_assets();
2589 awindow->gui->flush();
2590 awindow->gui->unlock_window();
2592 if(debug) PRINT_TRACE
2594 gui->lock_window("MWindow::update_project");
2596 if(debug) PRINT_TRACE
2599 void MWindow::remove_indexfile(Indexable *indexable)
2601 if( !indexable->is_asset ) return;
2602 Asset *asset = (Asset *)indexable;
2604 IndexFile::delete_index(preferences, asset, ".toc");
2605 IndexFile::delete_index(preferences, asset, ".idx");
2606 IndexFile::delete_index(preferences, asset, ".mkr");
2609 void MWindow::rebuild_indices()
2611 for(int i = 0; i < session->drag_assets->total; i++)
2613 Indexable *indexable = session->drag_assets->values[i];
2614 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2615 remove_indexfile(indexable);
2616 // Schedule index build
2617 IndexState *index_state = indexable->index_state;
2618 index_state->index_status = INDEX_NOTTESTED;
2619 if( indexable->is_asset ) {
2620 Asset *asset = (Asset *)indexable;
2621 if( asset->format != FILE_PCM )
2622 asset->reset_audio();
2623 asset->reset_video();
2625 mainindexes->add_next_asset(0, indexable);
2627 mainindexes->start_build();
2631 void MWindow::save_backup()
2634 edl->set_path(session->filename);
2635 edl->save_xml(&file,
2639 file.terminate_string();
2640 char path[BCTEXTLEN];
2642 strcpy(path, BACKUP_PATH);
2643 fs.complete_path(path);
2645 if(file.write_to_file(path))
2648 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2649 gui->show_message(string2);
2653 void MWindow::load_backup()
2655 ArrayList<char*> path_list;
2656 path_list.set_array_delete();
2658 char string[BCTEXTLEN];
2659 strcpy(string, BACKUP_PATH);
2661 fs.complete_path(string);
2663 path_list.append(out_path = new char[strlen(string) + 1]);
2664 strcpy(out_path, string);
2666 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2667 edl->local_session->clip_title[0] = 0;
2668 // This is unique to backups since the path of the backup is different than the
2669 // path of the project.
2670 set_filename(edl->path);
2671 path_list.remove_all_objects();
2675 static inline int gcd(int m, int n)
2678 if( m < n ) { r = m; m = n; n = r; }
2679 while( (r = m % n) != 0 ) { m = n; n = r; }
2683 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2686 if(!width || !height) return 1;
2687 double ar = (double)width / height;
2688 // square-ish pixels
2689 if( EQUIV(ar, 1.0000) ) return 0;
2690 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2691 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2692 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2693 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2694 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2695 int ww = width, hh = height;
2696 // numerator, denominator must be under mx
2697 int mx = 255, n = gcd(ww, hh);
2698 if( n > 1 ) { ww /= n; hh /= n; }
2699 // search near height in case extra/missing lines
2700 if( ww >= mx || hh >= mx ) {
2701 double err = height; // +/- 2 percent height
2702 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2703 int iw = width, ih = height+i;
2704 if( (n=gcd(iw, ih)) > 1 ) {
2705 int u = iw/n; if( u >= mx ) continue;
2706 int v = ih/n; if( v >= mx ) continue;
2707 double r = (double) u/v, er = fabs(ar-r);
2708 if( er >= err ) continue;
2709 err = er; ww = u; hh = v;
2718 void MWindow::reset_caches()
2720 frame_cache->remove_all();
2721 wave_cache->remove_all();
2722 audio_cache->remove_all();
2723 video_cache->remove_all();
2724 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2725 cwindow->playback_engine->audio_cache->remove_all();
2726 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2727 cwindow->playback_engine->video_cache->remove_all();
2729 for(int i = 0; i < vwindows.size(); i++) {
2730 VWindow *vwindow = vwindows.get(i);
2731 if( !vwindow->is_running() ) continue;
2732 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2733 vwindow->playback_engine->audio_cache->remove_all();
2734 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2735 vwindow->playback_engine->video_cache->remove_all();
2739 void MWindow::remove_asset_from_caches(Asset *asset)
2741 frame_cache->remove_asset(asset);
2742 wave_cache->remove_asset(asset);
2743 audio_cache->delete_entry(asset);
2744 video_cache->delete_entry(asset);
2745 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2746 cwindow->playback_engine->audio_cache->delete_entry(asset);
2747 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2748 cwindow->playback_engine->video_cache->delete_entry(asset);
2749 for(int i = 0; i < vwindows.size(); i++) {
2750 VWindow *vwindow = vwindows.get(i);
2751 if( !vwindow->is_running() ) continue;
2752 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2753 vwindow->playback_engine->audio_cache->delete_entry(asset);
2754 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2755 vwindow->playback_engine->video_cache->delete_entry(asset);
2761 void MWindow::remove_assets_from_project(int push_undo)
2763 for(int i = 0; i < session->drag_assets->total; i++) {
2764 Indexable *indexable = session->drag_assets->values[i];
2765 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
2768 // Remove from VWindow.
2769 for(int i = 0; i < session->drag_clips->total; i++) {
2770 for(int j = 0; j < vwindows.size(); j++) {
2771 VWindow *vwindow = vwindows.get(j);
2772 if( !vwindow->is_running() ) continue;
2773 if(session->drag_clips->values[i] == vwindow->get_edl()) {
2774 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
2775 vwindow->delete_source(1, 1);
2776 vwindow->gui->unlock_window();
2781 for(int i = 0; i < session->drag_assets->size(); i++) {
2782 for(int j = 0; j < vwindows.size(); j++) {
2783 VWindow *vwindow = vwindows.get(j);
2784 if( !vwindow->is_running() ) continue;
2785 if(session->drag_assets->get(i) == vwindow->get_source()) {
2786 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
2787 vwindow->delete_source(1, 1);
2788 vwindow->gui->unlock_window();
2793 for(int i = 0; i < session->drag_assets->size(); i++) {
2794 Indexable *indexable = session->drag_assets->values[i];
2795 remove_indexfile(indexable);
2798 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2799 if(push_undo) undo->update_undo_before();
2800 edl->remove_from_project(session->drag_assets);
2801 edl->remove_from_project(session->drag_clips);
2803 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
2806 gui->lock_window("MWindow::remove_assets_from_project 3");
2814 gui->unlock_window();
2816 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
2817 awindow->gui->update_assets();
2818 awindow->gui->flush();
2819 awindow->gui->unlock_window();
2821 // Removes from playback here
2822 sync_parameters(CHANGE_ALL);
2825 void MWindow::remove_assets_from_disk()
2828 for(int i = 0; i < session->drag_assets->total; i++)
2830 remove(session->drag_assets->values[i]->path);
2833 remove_assets_from_project(1);
2836 void MWindow::dump_plugins(FILE *fp)
2838 if( !plugindb ) return;
2839 for(int i = 0; i < plugindb->total; i++)
2841 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
2842 " synth=%d transition=%d theme=%d %s\n",
2843 plugindb->values[i]->plugin_type,
2844 plugindb->values[i]->audio,
2845 plugindb->values[i]->video,
2846 plugindb->values[i]->realtime,
2847 plugindb->values[i]->multichannel,
2848 plugindb->values[i]->get_synthesis(),
2849 plugindb->values[i]->transition,
2850 plugindb->values[i]->theme,
2851 plugindb->values[i]->title);
2855 void MWindow::dump_edl(FILE *fp)
2861 void MWindow::dump_undo(FILE *fp)
2867 void MWindow::dump_exe(FILE *fp)
2869 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
2870 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
2871 int len = readlink(proc_path, exe_path, sizeof(exe_path));
2872 if( len < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
2875 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
2876 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
2877 int fd = open(exe_path,O_RDONLY);
2878 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
2879 uint8_t buf[65536]; SHA1 sha1;
2880 while( (len=read(fd,buf,sizeof(buf))) > 0 ) {
2881 sha1.addBytes(buf, len);
2884 fprintf(fp, "SHA1: ");
2885 uint8_t digest[20]; sha1.computeHash(digest);
2886 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
2891 void MWindow::trap_hook(FILE *fp, void *vp)
2893 MWindow *mwindow = (MWindow *)vp;
2894 fprintf(fp, "\nEXE:\n");
2895 mwindow->dump_exe(fp);
2896 fprintf(fp, "\nPLUGINS:\n");
2897 mwindow->dump_plugins(fp);
2898 fprintf(fp, "\nEDL:\n");
2899 mwindow->dump_edl(fp);
2900 fprintf(fp, "\nUNDO:\n");
2901 mwindow->dump_undo(fp);
2909 int MWindow::save_defaults()
2911 gui->save_defaults(defaults);
2912 edl->save_defaults(defaults);
2913 session->save_defaults(defaults);
2914 preferences->save_defaults(defaults);
2916 for(int i = 0; i < plugin_guis->total; i++)
2918 // Pointer comparison
2919 plugin_guis->values[i]->save_defaults();
2921 awindow->save_defaults(defaults);
2927 int MWindow::run_script(FileXML *script)
2929 int result = 0, result2 = 0;
2930 while(!result && !result2)
2932 result = script->read_tag();
2935 if(script->tag.title_is("new_project"))
2937 // Run new in immediate mode.
2938 // gui->mainmenu->new_project->run_script(script);
2941 if(script->tag.title_is("record"))
2943 // Run record as a thread. It is a terminal command.
2945 // Will read the complete scipt file without letting record read it if not
2951 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
2958 // ================================= synchronization
2961 int MWindow::interrupt_indexes()
2963 mainindexes->interrupt_build();
2969 void MWindow::next_time_format()
2971 switch(edl->session->time_format)
2973 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
2974 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
2975 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2976 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
2977 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
2978 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
2979 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
2982 time_format_common();
2985 void MWindow::prev_time_format()
2987 switch(edl->session->time_format)
2989 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
2990 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
2991 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
2992 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2993 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
2994 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
2995 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
2998 time_format_common();
3001 void MWindow::time_format_common()
3003 gui->lock_window("MWindow::next_time_format");
3004 gui->redraw_time_dependancies();
3007 char string[BCTEXTLEN], string2[BCTEXTLEN];
3008 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3009 gui->show_message(string);
3011 gui->unlock_window();
3015 int MWindow::set_filename(const char *filename)
3017 if( filename != session->filename )
3018 strcpy(session->filename, filename);
3019 if( filename != edl->path )
3020 strcpy(edl->path, filename);
3024 if(filename[0] == 0)
3026 gui->set_title(PROGRAM_NAME);
3031 char string[BCTEXTLEN], string2[BCTEXTLEN];
3032 dir.extract_name(string, filename);
3033 sprintf(string2, PROGRAM_NAME ": %s", string);
3034 gui->set_title(string2);
3047 int MWindow::set_loop_boundaries()
3049 double start = edl->local_session->get_selectionstart();
3050 double end = edl->local_session->get_selectionend();
3058 if(edl->tracks->total_length())
3061 end = edl->tracks->total_length();
3068 if(edl->local_session->loop_playback && start != end)
3070 edl->local_session->loop_start = start;
3071 edl->local_session->loop_end = end;
3082 int MWindow::reset_meters()
3084 cwindow->gui->lock_window("MWindow::reset_meters 1");
3085 cwindow->gui->meters->reset_meters();
3086 cwindow->gui->unlock_window();
3088 for(int j = 0; j < vwindows.size(); j++) {
3089 VWindow *vwindow = vwindows.get(j);
3090 if( !vwindow->is_running() ) continue;
3091 vwindow->gui->lock_window("MWindow::reset_meters 2");
3092 vwindow->gui->meters->reset_meters();
3093 vwindow->gui->unlock_window();
3096 lwindow->gui->lock_window("MWindow::reset_meters 3");
3097 lwindow->gui->panel->reset_meters();
3098 lwindow->gui->unlock_window();
3100 gui->lock_window("MWindow::reset_meters 4");
3101 gui->reset_meters();
3102 gui->unlock_window();
3107 void MWindow::resync_guis()
3111 gui->lock_window("MWindow::resync_guis");
3112 gui->update(1, 1, 1, 1, 1, 1, 0);
3113 gui->unlock_window();
3115 cwindow->gui->lock_window("MWindow::resync_guis");
3116 cwindow->gui->resize_event(cwindow->gui->get_w(),
3117 cwindow->gui->get_h());
3118 int channels = edl->session->audio_channels;
3119 cwindow->gui->meters->set_meters(channels, 1);
3120 cwindow->gui->flush();
3121 cwindow->gui->unlock_window();
3123 for(int i = 0; i < vwindows.size(); i++) {
3124 VWindow *vwindow = vwindows.get(i);
3125 if( !vwindow->is_running() ) continue;
3126 vwindow->gui->lock_window("MWindow::resync_guis");
3127 vwindow->gui->resize_event(vwindow->gui->get_w(),
3128 vwindow->gui->get_h());
3129 vwindow->gui->meters->set_meters(channels, 1);
3130 vwindow->gui->flush();
3131 vwindow->gui->unlock_window();
3134 lwindow->gui->lock_window("MWindow::resync_guis");
3135 lwindow->gui->panel->set_meters(channels, 1);
3136 lwindow->gui->flush();
3137 lwindow->gui->unlock_window();
3140 if(((edl->session->output_w % 4) ||
3141 (edl->session->output_h % 4)) &&
3142 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3144 MainError::show_error(
3145 _("This project's dimensions are not multiples of 4 so\n"
3146 "it can't be rendered by OpenGL."));
3151 sync_parameters(CHANGE_ALL);
3154 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3156 File *file = new File;
3157 EDLSession *session = edl->session;
3158 double old_framerate = session->frame_rate;
3159 double old_samplerate = session->sample_rate;
3160 int result = file->open_file(preferences, asset, 1, 0);
3161 if( !result && delete_tracks > 0 )
3162 undo->update_undo_before();
3163 if( !result && asset->get_video_layers() > 0 ) {
3164 // try to get asset up to date, may fail
3165 file->select_video_stream(asset, vstream);
3166 // either way use what was/is there.
3167 double framerate = asset->get_frame_rate();
3168 int width = asset->get_w();
3169 int height = asset->get_h();
3170 // must be multiple of 4 for opengl
3171 width = (width+3) & ~3; height = (height+3) & ~3;
3172 int driver = session->playback_config->vconfig->driver;
3173 int color_model = file->get_best_colormodel(asset, driver);
3174 color_model = BC_CModels::is_yuv(color_model) ?
3175 BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3176 BC_CModels::is_float(color_model) ?
3177 BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3178 BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3179 session->color_model = color_model;
3180 session->output_w = width;
3181 session->output_h = height;
3182 session->frame_rate = framerate;
3183 // not, asset->actual_width/actual_height
3184 asset->width = session->output_w;
3185 asset->height = session->output_h;
3186 asset->frame_rate = session->frame_rate;
3187 create_aspect_ratio(session->aspect_w, session->aspect_h,
3188 session->output_w, session->output_h);
3189 Track *track = edl->tracks->first;
3190 for( Track *next_track=0; track; track=next_track ) {
3191 next_track = track->next;
3192 if( track->data_type != TRACK_VIDEO ) continue;
3193 if( delete_tracks ) {
3194 Edit *edit = track->edits->first;
3195 for( Edit *next_edit=0; edit; edit=next_edit ) {
3196 next_edit = edit->next;
3197 if( edit->channel != vstream ||
3198 !edit->asset || !edit->asset->is_asset ||
3199 *asset != *edit->asset )
3203 if( track->edits->first ) {
3204 track->track_w = edl->session->output_w;
3205 track->track_h = edl->session->output_h;
3207 else if( delete_tracks )
3208 edl->tracks->delete_track(track);
3210 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3212 if( !result && asset->channels > 0 ) {
3213 session->sample_rate = asset->get_sample_rate();
3214 int64_t channel_mask = 0;
3215 int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
3216 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3217 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3219 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3220 if( channels > 6 ) channels = 6;
3221 session->audio_tracks = session->audio_channels = channels;
3222 switch( channels ) {
3224 session->achannel_positions[0] = 90;
3225 session->achannel_positions[1] = 150;
3226 session->achannel_positions[2] = 30;
3227 session->achannel_positions[3] = 210;
3228 session->achannel_positions[4] = 330;
3229 session->achannel_positions[5] = 270;
3232 session->achannel_positions[0] = 180;
3233 session->achannel_positions[1] = 0;
3236 remap_audio(MWindow::AUDIO_1_TO_1);
3238 if( delete_tracks ) {
3239 Track *track = edl->tracks->first;
3240 for( Track *next_track=0; track; track=next_track ) {
3241 next_track = track->next;
3242 if( track->data_type != TRACK_AUDIO ) continue;
3243 Edit *edit = track->edits->first;
3244 for( Edit *next_edit=0; edit; edit=next_edit ) {
3245 next_edit = edit->next;
3246 if( !((1<<edit->channel) & channel_mask) ||
3247 !edit->asset || !edit->asset->is_asset ||
3248 *asset != *edit->asset )
3251 if( !track->edits->first )
3252 edl->tracks->delete_track(track);
3256 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3259 if( !result && delete_tracks > 0 ) {
3261 undo->update_undo_after(_("select asset"), LOAD_ALL);
3267 int MWindow::select_asset(int vtrack, int delete_tracks)
3269 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3270 if( !track ) return 1;
3271 Edit *edit = track->edits->first;
3272 if( !edit ) return 1;
3273 Asset *asset = edit->asset;
3274 if( !asset || !asset->is_asset ) return 1;
3275 return select_asset(asset, edit->channel, -1, delete_tracks);
3278 void MWindow::dump_plugindb(FILE *fp)
3280 if( !plugindb ) return;
3281 for(int i = 0; i < plugindb->total; i++)
3282 plugindb->values[i]->dump(fp);