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 "filesystem.h"
55 #include "framecache.h"
57 #include "gwindowgui.h"
58 #include "keyframegui.h"
59 #include "indexfile.h"
61 #include "levelwindowgui.h"
62 #include "levelwindow.h"
63 #include "loadfile.inc"
64 #include "localsession.h"
65 #include "maincursor.h"
66 #include "mainerror.h"
67 #include "mainindexes.h"
69 #include "mainprogress.h"
70 #include "mainsession.h"
74 #include "mwindowgui.h"
76 #include "nestededls.h"
79 #include "playback3d.h"
80 #include "playbackengine.h"
82 #include "pluginserver.h"
83 #include "pluginset.h"
84 #include "preferences.h"
86 #include "recordmonitor.h"
87 #include "recordlabel.h"
88 #include "removefile.h"
90 #include "samplescroll.h"
92 #include "sighandler.h"
93 #include "splashgui.h"
94 #include "statusbar.h"
96 #include "threadloader.h"
98 #include "tipwindow.h"
99 #include "trackcanvas.h"
101 #include "tracking.h"
102 #include "trackscroll.h"
104 #include "transition.h"
105 #include "transportque.h"
107 #include "videodevice.inc"
108 #include "videowindow.h"
109 #include "vplayback.h"
110 #include "vwindowgui.h"
112 #include "wavecache.h"
117 #include <sys/stat.h>
126 // Hack for libdv to remove glib dependancy
129 // g_log (const char *log_domain,
131 // const char *format,
137 // g_logv (const char *log_domain,
139 // const char *format,
146 // Hack for XFree86 4.1.0
148 int atexit(void (*function)(void))
159 ArrayList<PluginServer*>* MWindow::plugindb = 0;
160 Commercials* MWindow::commercials = 0;
166 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
167 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
168 vwindows_lock = new Mutex("MWindow::vwindows_lock");
169 brender_lock = new Mutex("MWindow::brender_lock");
170 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
178 commercial_active = 0;
189 channeldb_buz = new ChannelDB;
190 channeldb_v4l2jpeg = new ChannelDB;
194 keyframe_threads = 0;
214 // Need to delete brender temporary here.
218 //printf("MWindow::~MWindow %d\n", __LINE__);
220 gui->remote_control->deactivate();
222 gui->channel_info->stop();
223 brender_lock->lock("MWindow::quit");
224 delete brender; brender = 0;
225 brender_lock->unlock();
226 delete create_bd; create_bd = 0;
227 delete create_dvd; create_dvd = 0;
228 delete batch_render; batch_render = 0;
230 if( commercials && !commercials->remove_user() ) commercials = 0;
232 // Save defaults for open plugins
233 plugin_gui_lock->lock("MWindow::~MWindow");
234 for(int i = 0; i < plugin_guis->size(); i++)
236 plugin_guis->get(i)->hide_gui();
238 plugin_gui_lock->unlock();
239 hide_keyframe_guis();
242 // Give up and go to a movie
243 // cant run valgrind if this is used
244 // if( !reload_status ) exit(0);
246 gui->del_keyboard_listener(
247 (int (BC_WindowBase::*)(BC_WindowBase *))
248 &MWindowGUI::keyboard_listener);
250 // release the hounds
251 if( awindow && awindow->gui ) awindow->gui->close(0);
252 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
253 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
254 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
255 if( twindow && twindow->is_running() ) twindow->close_window();
256 if( wwindow && wwindow->is_running() ) wwindow->close_window();
257 vwindows.remove_all_objects();
259 if( awindow ) awindow->join();
260 if( cwindow ) cwindow->join();
261 if( lwindow ) lwindow->join();
262 if( twindow ) twindow->join();
263 if( wwindow ) wwindow->join();
264 if( gwindow ) gwindow->join();
267 // one at a time, or nouveau chokes
268 #define close_gui(win) if( win ) { \
269 if( win->gui ) win->gui->close(0); \
277 vwindows.remove_all_objects();
282 dead_plugins->remove_all();
284 keyframe_threads->remove_all_objects();
285 if( !edl->Garbage::remove_user() ) edl = 0;
286 colormodels.remove_all_objects();
288 delete render; render = 0;
289 delete awindow; awindow = 0;
290 delete lwindow; lwindow = 0;
291 delete twindow; twindow = 0;
292 delete wwindow; wwindow = 0;
293 delete gwindow; gwindow = 0;
294 // must be last or nouveau chokes
295 delete cwindow; cwindow = 0;
296 //delete file_server; file_server = 0; // reusable
297 delete mainindexes; mainindexes = 0;
298 delete mainprogress; mainprogress = 0;
299 delete audio_cache; audio_cache = 0; // delete the cache after the assets
300 delete video_cache; video_cache = 0; // delete the cache after the assets
301 delete frame_cache; frame_cache = 0;
302 delete wave_cache; wave_cache = 0;
303 delete plugin_guis; plugin_guis = 0;
304 delete dead_plugins; dead_plugins = 0;
305 delete keyframe_threads; keyframe_threads = 0;
306 delete undo; undo = 0;
307 delete preferences; preferences = 0;
308 delete session; session = 0;
309 delete defaults; defaults = 0;
310 delete assets; assets = 0;
311 delete splash_window; splash_window = 0;
312 delete theme; theme = 0;
314 delete channeldb_buz;
315 delete channeldb_v4l2jpeg;
316 // This must be last thread to exit
317 delete playback_3d; playback_3d = 0;
318 delete dead_plugin_lock;
319 delete plugin_gui_lock;
320 delete vwindows_lock;
322 delete keyframe_gui_lock;
323 sighandler->terminate();
328 void MWindow::quit(int unlock)
331 if(unlock) gui->unlock_window();
333 brender_lock->lock("MWindow::quit");
334 delete brender; brender = 0;
335 brender_lock->unlock();
341 if(unlock) gui->lock_window("MWindow::quit");
344 void MWindow::init_error()
346 MainError::init_error(this);
349 void MWindow::finit_error()
351 MainError::finit_error();
354 void MWindow::create_defaults_path(char *string, const char *config_file)
356 // set the .bcast path
359 sprintf(string, "%s", BCASTDIR);
360 fs.complete_path(string);
361 if(!fs.is_dir(string))
362 fs.create_dir(string);
365 strcat(string, config_file);
368 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
370 char path[BCTEXTLEN];
371 // Use user supplied path
373 strcpy(path, config_path);
375 create_defaults_path(path, CONFIG_FILE);
377 defaults = new BC_Hash(path);
381 int MWindow::load_plugin_index(MWindow *mwindow, char *path)
384 FILE *fp = fopen(path, "r");
386 char index_line[BCTEXTLEN];
387 int index_version = -1, ret = 0;
388 if( !fgets(index_line, BCTEXTLEN, fp) ||
389 sscanf(index_line, "%d", &index_version) != 1 ||
390 index_version != PLUGIN_FILE_VERSION ) ret = 1;
392 while( !ret && !feof(fp)) {
393 if( !fgets(index_line, BCTEXTLEN, fp) ) break;
394 if( index_line[0] == ';' ) continue;
395 if( index_line[0] == '#' ) continue;
396 int type = PLUGIN_TYPE_UNKNOWN;
397 char path[BCTEXTLEN], title[BCTEXTLEN];
398 if( PluginServer::scan_table(index_line, type, path, title) ) continue;
399 PluginServer *server = 0;
401 case PLUGIN_TYPE_BUILTIN:
402 case PLUGIN_TYPE_LADSPA:
403 server = new PluginServer(mwindow, path, type);
405 case PLUGIN_TYPE_FFMPEG: // skip "ff_..."
406 server = new_ffmpeg_server(mwindow, path+3);
409 if( !server ) continue;
410 // Create plugin server from index entry
411 server->set_title(title);
412 if( server->read_table(index_line) ) {
416 plugindb->append(server);
423 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
424 const char *plug_dir, const char *plug_path, int &idx)
426 char plugin_path[BCTEXTLEN];
427 if( *plug_path != '/' )
428 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
430 strcpy(plugin_path, plug_path);
432 fs.set_filter( "[*.plugin][*.so]" );
433 int result = fs.update(plugin_path);
434 if( result || !fs.dir_list.total ) return;
437 for( int i=0; i<fs.dir_list.total; ++i ) {
438 char *fs_path = fs.dir_list[i]->path;
439 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
440 const char *dp = plug_dir;
441 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
442 strcpy(plugin_path, !*dp && *bp == '/' ? bp+1 : base_path);
444 if( fs.is_dir(fs_path) ) {
445 init_plugin_index(mwindow, preferences, fp, plug_dir, plugin_path, idx);
448 if( plugin_exists(plugin_path) ) continue;
449 PluginServer server(mwindow, plugin_path, PLUGIN_TYPE_UNKNOWN);
450 result = server.open_plugin(1, preferences, 0, 0);
452 server.write_table(fp,vis_id);
453 server.close_plugin();
455 else if( result == PLUGINSERVER_IS_LAD ) {
458 PluginServer ladspa(mwindow, plugin_path, PLUGIN_TYPE_LADSPA);
459 ladspa.set_lad_index(lad_index++);
460 result = ladspa.open_plugin(1, preferences, 0, 0);
462 ladspa.write_table(fp, PLUGIN_LADSPA_ID);
463 ladspa.close_plugin();
469 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
472 if( !plugindb ) plugindb = new ArrayList<PluginServer*>;
473 char index_path[BCTEXTLEN];
474 sprintf(index_path, "%s/%s", preferences->plugin_dir, PLUGIN_FILE);
475 if( !load_plugin_index(mwindow, index_path) ) return 1;
476 FILE *fp = fopen(index_path,"w");
478 fprintf(stderr,_("MWindow::init_plugins: "
479 "can't create plugin index: %s\n"), index_path);
482 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
483 char *plug_path = FileSystem::basepath(preferences->plugin_dir);
484 int dir_id = PLUGIN_IDS;
485 init_plugin_index(mwindow, preferences, fp, plug_path, ".", dir_id);
486 init_ffmpeg_index(mwindow, preferences, fp);
489 return load_plugin_index(mwindow, index_path);
492 void MWindow::delete_plugins()
494 plugindb->remove_all_objects();
499 void MWindow::search_plugindb(int do_audio,
504 ArrayList<PluginServer*> &results)
507 for(int i = 0; i < MWindow::plugindb->total; i++)
509 PluginServer *current = MWindow::plugindb->get(i);
511 if(current->audio == do_audio &&
512 current->video == do_video &&
513 (current->realtime == is_realtime || is_realtime < 0) &&
514 current->transition == is_transition &&
515 current->theme == is_theme)
516 results.append(current);
519 // Alphabetize list by title
525 for(int i = 0; i < results.total - 1; i++)
527 PluginServer *value1 = results[i];
528 PluginServer *value2 = results[i + 1];
529 if(strcmp(_(value1->title), _(value2->title)) > 0)
533 results[i + 1] = value1;
539 PluginServer* MWindow::scan_plugindb(char *title,
544 // printf("MWindow::scan_plugindb data_type < 0\n");
548 for(int i = 0; i < plugindb->total; i++)
550 PluginServer *server = plugindb->get(i);
552 !strcasecmp(server->title, title) &&
554 (data_type == TRACK_AUDIO && server->audio) ||
555 (data_type == TRACK_VIDEO && server->video)))
556 return plugindb->get(i);
561 int MWindow::plugin_exists(char *plugin_path)
563 for( int i=0; i<plugindb->total; ++i ) {
564 PluginServer *server = plugindb->get(i);
565 if( !strcmp(plugin_path, server->get_path()) ) return 1;
570 void MWindow::init_preferences()
572 preferences = new Preferences;
573 preferences->load_defaults(defaults);
574 session = new MainSession(this);
575 session->load_defaults(defaults);
576 // set x11_host, screens, window_config
577 screens = session->set_default_x11_host();
578 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
579 BC_Signals::set_trap_hook(trap_hook, this);
580 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
581 BC_Signals::set_catch_intr(preferences->trap_sigintr);
584 void MWindow::clean_indexes()
589 int oldest_item = -1;
591 char string[BCTEXTLEN];
592 char string2[BCTEXTLEN];
594 // Delete extra indexes
595 fs.set_filter("*.idx");
596 fs.complete_path(preferences->index_directory);
597 fs.update(preferences->index_directory);
598 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
600 // Eliminate directories
605 for(int i = 0; i < fs.dir_list.total && !result; i++)
607 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
608 if(fs.is_dir(string))
610 delete fs.dir_list[i];
611 fs.dir_list.remove_number(i);
616 total_excess = fs.dir_list.total - preferences->index_count;
618 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
619 while(total_excess > 0)
622 for(int i = 0; i < fs.dir_list.total; i++)
624 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
626 if(i == 0 || fs.get_date(string) <= oldest)
628 oldest = fs.get_date(string);
636 fs.join_names(string,
637 preferences->index_directory,
638 fs.dir_list[oldest_item]->name);
639 //printf("MWindow::clean_indexes 1 %s\n", string);
641 perror("delete_indexes");
642 delete fs.dir_list[oldest_item];
643 fs.dir_list.remove_number(oldest_item);
645 // Remove table of contents if it exists
646 strcpy(string2, string);
647 char *ptr = strrchr(string2, '.');
650 //printf("MWindow::clean_indexes 2 %s\n", string2);
651 sprintf(ptr, ".toc");
653 sprintf(ptr, ".mkr");
662 void MWindow::init_awindow()
664 awindow = new AWindow(this);
665 awindow->create_objects();
668 void MWindow::init_gwindow()
670 gwindow = new GWindow(this);
671 gwindow->create_objects();
674 void MWindow::init_tipwindow()
677 twindow = new TipWindow(this);
681 void MWindow::show_warning(int *do_warning, const char *text)
683 if( do_warning && !*do_warning ) return;
685 wwindow = new WWindow(this);
686 wwindow->show_warning(do_warning, text);
689 void MWindow::init_theme()
694 // Replace blond theme with SUV since it doesn't work
695 if(!strcasecmp(preferences->theme, "Blond"))
696 strcpy(preferences->theme, DEFAULT_THEME);
698 PluginServer *theme_plugin = 0;
699 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
700 if( plugindb->get(i)->theme &&
701 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
702 theme_plugin = plugindb->get(i);
706 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
709 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
710 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
712 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
713 if( plugindb->get(i)->theme &&
714 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
715 theme_plugin = plugindb->get(i);
720 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
724 PluginServer *plugin = new PluginServer(*theme_plugin);
725 if( plugin->open_plugin(0, preferences, 0, 0) ) {
726 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
727 theme_plugin->title);
731 theme = plugin->new_theme();
732 theme->mwindow = this;
733 strcpy(theme->path, plugin->path);
736 // Load default images & settings
737 theme->Theme::initialize();
738 // Load user images & settings
740 // Create menus with user colors
741 theme->build_menus();
746 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
749 void MWindow::init_3d()
751 playback_3d = new Playback3D(this);
752 playback_3d->create_objects();
755 void MWindow::init_edl()
758 edl->create_objects();
759 edl->load_defaults(defaults);
760 edl->create_default_tracks();
761 edl->tracks->update_y_pixels(theme);
764 void MWindow::init_compositor()
766 cwindow = new CWindow(this);
767 cwindow->create_objects();
770 void MWindow::init_levelwindow()
772 lwindow = new LevelWindow(this);
773 lwindow->create_objects();
776 VWindow *MWindow::get_viewer(int start_it, int idx)
778 vwindows_lock->lock("MWindow::get_viewer");
779 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
780 if( !vwindow ) idx = vwindows.size();
781 while( !vwindow && --idx >= 0 ) {
782 VWindow *vwin = vwindows[idx];
783 if( !vwin->is_running() || !vwin->get_edl() )
787 vwindow = new VWindow(this);
788 vwindow->load_defaults();
789 vwindow->create_objects();
790 vwindows.append(vwindow);
792 vwindows_lock->unlock();
793 if( start_it ) vwindow->start();
797 void MWindow::init_cache()
799 audio_cache = new CICache(preferences);
800 video_cache = new CICache(preferences);
801 frame_cache = new FrameCache;
802 wave_cache = new WaveCache;
805 void MWindow::init_channeldb()
807 channeldb_buz->load("channeldb_buz");
808 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
811 void MWindow::init_menus()
813 char string[BCTEXTLEN];
814 BC_CModels::to_text(string, BC_RGB888);
815 colormodels.append(new ColormodelItem(string, BC_RGB888));
816 BC_CModels::to_text(string, BC_RGBA8888);
817 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
818 // BC_CModels::to_text(string, BC_RGB161616);
819 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
820 // BC_CModels::to_text(string, BC_RGBA16161616);
821 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
822 BC_CModels::to_text(string, BC_RGB_FLOAT);
823 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
824 BC_CModels::to_text(string, BC_RGBA_FLOAT);
825 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
826 BC_CModels::to_text(string, BC_YUV888);
827 colormodels.append(new ColormodelItem(string, BC_YUV888));
828 BC_CModels::to_text(string, BC_YUVA8888);
829 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
830 // BC_CModels::to_text(string, BC_YUV161616);
831 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
832 // BC_CModels::to_text(string, BC_YUVA16161616);
833 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
836 void MWindow::init_indexes()
838 mainindexes = new MainIndexes(this);
839 mainindexes->start_loop();
842 void MWindow::init_gui()
844 gui = new MWindowGUI(this);
845 gui->lock_window("MWindow::init_gui");
846 gui->create_objects();
847 gui->unlock_window();
848 gui->load_defaults(defaults);
851 void MWindow::init_signals()
853 sighandler = new SigHandler;
854 sighandler->initialize();
858 void MWindow::init_render()
860 render = new Render(this);
861 create_bd = new CreateBD_Thread(this);
862 create_dvd = new CreateDVD_Thread(this);
863 batch_render = new BatchRenderThread(this);
866 void MWindow::init_brender()
868 if(preferences->use_brender && !brender)
870 brender_lock->lock("MWindow::init_brender 1");
871 brender = new BRender(this);
872 brender->initialize();
873 session->brender_end = 0;
874 brender_lock->unlock();
877 if(!preferences->use_brender && brender)
879 brender_lock->lock("MWindow::init_brender 2");
882 session->brender_end = 0;
883 brender_lock->unlock();
885 if(brender) brender->restart(edl);
888 void MWindow::restart_brender()
890 //printf("MWindow::restart_brender 1\n");
891 if(brender) brender->restart(edl);
894 void MWindow::stop_brender()
896 if(brender) brender->stop();
899 int MWindow::brender_available(int position)
902 brender_lock->lock("MWindow::brender_available 1");
905 if(brender->map_valid)
907 brender->map_lock->lock("MWindow::brender_available 2");
908 if(position < brender->map_size &&
911 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
912 if(brender->map[position] == BRender::RENDERED)
915 brender->map_lock->unlock();
918 brender_lock->unlock();
922 void MWindow::set_brender_start()
924 edl->session->brender_start = edl->local_session->get_selectionstart(1);
926 gui->draw_overlays(1);
930 int MWindow::has_commercials()
932 return theme->use_commercials;
935 void MWindow::init_commercials()
938 commercials = new Commercials(this);
939 commercial_active = 0;
942 commercials->add_user();
945 void MWindow::commit_commercial()
947 if( !commercial_active ) return;
948 commercial_active = 0;
949 if( !commercials ) return;
950 commercials->commitDb();
953 void MWindow::undo_commercial()
955 if( !commercial_active ) return;
956 commercial_active = 0;
957 if( !commercials ) return;
958 commercials->undoDb();
961 int MWindow::put_commercial()
963 double start = edl->local_session->get_selectionstart();
964 double end = edl->local_session->get_selectionend();
965 if( start >= end ) return 0;
967 const char *errmsg = 0;
969 Tracks *tracks = edl->tracks;
972 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
973 if( track->data_type != TRACK_VIDEO ) continue;
974 if( !track->record ) continue;
975 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
977 int64_t units_start = track->to_units(start,0);
978 int64_t units_end = track->to_units(end,0);
979 Edits *edits = track->edits;
980 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
981 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
982 if(!edit1 && !edit2) continue; // nothing selected
983 if(!edit2) { // edit2 beyond end of track
985 units_end = edits->length();
987 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
988 Indexable *indexable = edit1->get_source();
989 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
992 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
993 if( track->data_type != TRACK_VIDEO ) continue;
994 if( !track->record ) continue;
995 int64_t units_start = track->to_units(start,0);
996 int64_t units_end = track->to_units(end,0);
997 Edits *edits = track->edits;
998 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
999 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1000 if(!edit1 && !edit2) continue; // nothing selected
1001 if(!edit2) { // edit2 beyond end of track
1002 edit2 = edits->last;
1003 units_end = edits->length();
1005 Indexable *indexable = edit1->get_source();
1006 Asset *asset = (Asset *)indexable;
1007 File *file = video_cache->check_out(asset, edl);
1008 if( !file ) { errmsg = _("no file"); break; }
1009 int64_t edit_length = units_end - units_start;
1010 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1011 result = commercials->put_clip(file, edit1->channel,
1012 track->from_units(edit_start), track->from_units(edit_length));
1013 video_cache->check_in(asset);
1014 if( result ) { errmsg = _("db failed"); break; }
1017 char string[BCTEXTLEN];
1018 sprintf(string, _("put_commercial: %s"), errmsg);
1019 MainError::show_error(string);
1026 void MWindow::stop_playback(int wait)
1028 int locked = gui->get_window_lock();
1029 if( locked ) gui->unlock_window();
1031 cwindow->playback_engine->que->send_command(STOP,
1035 cwindow->playback_engine->interrupt_playback(wait);
1037 for(int i = 0; i < vwindows.size(); i++) {
1038 VWindow *vwindow = vwindows[i];
1039 if( !vwindow->is_running() ) continue;
1040 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1041 vwindow->playback_engine->interrupt_playback(wait);
1043 if( locked ) gui->lock_window("MWindow::stop_playback");
1046 int MWindow::load_filenames(ArrayList<char*> *filenames,
1048 int update_filename)
1050 ArrayList<EDL*> new_edls;
1051 ArrayList<Asset*> new_assets;
1052 ArrayList<File*> new_files;
1053 const int debug = 0;
1054 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1057 gui->start_hourglass();
1059 // Need to stop playback since tracking depends on the EDL not getting
1063 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1064 undo->update_undo_before();
1067 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1069 // Define new_edls and new_assets to load
1070 int result = 0, ftype = -1;
1071 for(int i = 0; i < filenames->size(); i++)
1074 File *new_file = new File;
1075 Asset *new_asset = new Asset(filenames->get(i));
1076 EDL *new_edl = new EDL;
1077 char string[BCTEXTLEN];
1079 new_edl->create_objects();
1080 new_edl->copy_session(edl);
1081 new_file->set_program(edl->session->program_no);
1083 sprintf(string, _("Loading %s"), new_asset->path);
1084 gui->show_message(string);
1085 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1087 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1088 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1093 // Convert media file to EDL
1095 // Warn about odd image dimensions
1096 if(new_asset->video_data &&
1097 ((new_asset->width % 2) ||
1098 (new_asset->height % 2)))
1100 char string[BCTEXTLEN];
1101 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1105 MainError::show_error(string);
1108 if(new_asset->program >= 0 &&
1109 edl->session->program_no != new_asset->program)
1111 char string[BCTEXTLEN];
1112 sprintf(string, _("%s's index was built for program number %d\n"
1113 "Playback preference is %d.\n Using program %d."),
1114 new_asset->path, new_asset->program,
1115 edl->session->program_no, new_asset->program);
1116 MainError::show_error(string);
1120 if(load_mode != LOADMODE_RESOURCESONLY)
1123 RecordLabels *labels = edl->session->label_cells ?
1124 new RecordLabels(new_file) : 0;
1126 asset_to_edl(new_edl, new_asset, labels);
1128 new_edls.append(new_edl);
1130 new_asset->Garbage::remove_user();
1136 new_assets.append(new_asset);
1140 // Set filename to nothing for assets since save EDL would overwrite them.
1141 if(load_mode == LOADMODE_REPLACE ||
1142 load_mode == LOADMODE_REPLACE_CONCATENATE)
1145 // Reset timeline position
1146 for(int i = 0; i < TOTAL_PANES; i++)
1148 new_edl->local_session->view_start[i] = 0;
1149 new_edl->local_session->track_start[i] = 0;
1157 case FILE_NOT_FOUND:
1158 sprintf(string, _("Failed to open %s"), new_asset->path);
1159 gui->show_message(string, theme->message_error);
1163 case FILE_UNRECOGNIZED_CODEC:
1166 IndexFile indexfile(this, new_asset);
1167 result = indexfile.open_index();
1170 indexfile.close_index();
1173 // Test existing EDLs
1176 for(int j = 0; j < new_edls.total + 1; j++)
1179 if(j == new_edls.total)
1181 old_asset = edl->assets->get_asset(new_asset->path);
1184 *new_asset = *old_asset;
1190 old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1193 *new_asset = *old_asset;
1203 char string[BCTEXTLEN];
1205 fs.extract_name(string, new_asset->path);
1207 strcat(string, _("'s format couldn't be determined."));
1208 new_asset->audio_data = 1;
1209 new_asset->format = FILE_PCM;
1210 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1211 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1212 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1213 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1214 new_asset->signed_ = defaults->get("SIGNED_", 1);
1215 new_asset->header = defaults->get("HEADER", 0);
1217 FileFormat fwindow(this);
1218 fwindow.create_objects(new_asset, string);
1219 result = fwindow.run_window();
1222 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1223 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1224 defaults->update("AUDIO_BITS", new_asset->bits);
1225 defaults->update("BYTE_ORDER", new_asset->byte_order);
1226 defaults->update("SIGNED_", new_asset->signed_);
1227 defaults->update("HEADER", new_asset->header);
1234 // Recalculate length
1236 new_file = new File;
1237 result = new_file->open_file(preferences, new_asset, 1, 0);
1239 if(load_mode != LOADMODE_RESOURCESONLY)
1241 RecordLabels *labels = edl->session->label_cells ?
1242 new RecordLabels(new_file) : 0;
1243 asset_to_edl(new_edl, new_asset, labels);
1244 new_edls.append(new_edl);
1245 new_asset->Garbage::remove_user();
1251 new_assets.append(new_asset);
1265 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1266 xml_file.read_from_file(filenames->get(i));
1267 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1269 if(load_mode == LOADMODE_NESTED)
1271 // Load temporary EDL for nesting.
1272 EDL *nested_edl = new EDL;
1273 nested_edl->create_objects();
1274 nested_edl->set_path(filenames->get(i));
1275 nested_edl->load_xml(&xml_file, LOAD_ALL);
1276 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1277 edl_to_nested(new_edl, nested_edl);
1278 nested_edl->Garbage::remove_user();
1282 // Load EDL for pasting
1283 new_edl->load_xml(&xml_file, LOAD_ALL);
1284 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1285 test_plugins(new_edl, filenames->get(i));
1286 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1288 if(load_mode == LOADMODE_REPLACE ||
1289 load_mode == LOADMODE_REPLACE_CONCATENATE)
1291 strcpy(session->filename, filenames->get(i));
1292 strcpy(new_edl->local_session->clip_title,
1295 set_filename(new_edl->local_session->clip_title);
1299 new_edls.append(new_edl);
1305 // edls are in new_edls
1306 if( result && new_edl ) new_edl->Garbage::remove_user();
1307 // assets are copied
1308 if( new_asset ) new_asset->Garbage::remove_user();
1310 // Store for testing index
1311 new_files.append(new_file);
1314 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1317 if(!result) gui->statusbar->default_message();
1325 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1328 // Don't back up here.
1331 // For pasting, clear the active region
1332 if(load_mode == LOADMODE_PASTE ||
1333 load_mode == LOADMODE_NESTED)
1335 double start = edl->local_session->get_selectionstart();
1336 double end = edl->local_session->get_selectionend();
1337 if(!EQUIV(start, end))
1340 edl->session->labels_follow_edits,
1341 edl->session->plugins_follow_edits,
1342 edl->session->autos_follow_edits);
1345 paste_edls(&new_edls,
1349 edl->session->labels_follow_edits,
1350 edl->session->plugins_follow_edits,
1351 edl->session->autos_follow_edits);
1357 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1359 // Add new assets to EDL and schedule assets for index building.
1360 int got_indexes = 0;
1361 for(int i = 0; i < new_edls.size(); i++)
1363 EDL *new_edl = new_edls[i];
1364 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1366 mainindexes->add_next_asset(0,
1367 new_edl->nested_edls->get(j));
1369 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1374 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1375 if(new_assets.size())
1377 for(int i = 0; i < new_assets.size(); i++)
1379 Asset *new_asset = new_assets[i];
1383 for(int j = 0; j < new_files.size(); j++)
1385 new_file = new_files[j];
1386 if(!strcmp(new_file->asset->path,
1394 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1396 edl->assets->update(new_asset);
1402 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1404 // Start examining next batch of index files
1405 if(got_indexes) mainindexes->start_build();
1406 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1409 Track *track = edl->tracks->first;
1412 for(int j = 0; j < track->plugin_set.size(); j++)
1414 PluginSet *plugins = track->plugin_set[j];
1415 Plugin *plugin = plugins->get_first_plugin();
1419 if(load_mode == LOADMODE_REPLACE ||
1420 load_mode == LOADMODE_REPLACE_CONCATENATE)
1422 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1425 show_plugin(plugin);
1433 plugin = (Plugin*)plugin->next;
1437 track = track->next;
1440 // if just opening one new resource in replace mode
1441 if( load_mode == LOADMODE_REPLACE && new_edls.size() == 1 &&
1442 ftype != FILE_IS_XML )
1445 edl->local_session->preview_start = 0;
1446 edl->local_session->preview_end = edl->tracks->total_playable_length();
1447 edl->local_session->loop_playback = 0;
1448 edl->local_session->set_selectionstart(0);
1449 edl->local_session->set_selectionend(0);
1454 // need to update undo before project, since mwindow is unlocked & a new load
1455 // can begin here. Should really prevent loading until we're done.
1456 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1457 undo->update_undo_after(_("load"), LOAD_ALL);
1459 for(int i = 0; i < new_edls.size(); i++)
1461 new_edls[i]->remove_user();
1463 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1465 new_edls.remove_all();
1467 for(int i = 0; i < new_assets.size(); i++)
1469 new_assets[i]->Garbage::remove_user();
1472 new_assets.remove_all();
1473 new_files.remove_all_objects();
1476 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1477 if(load_mode == LOADMODE_REPLACE ||
1478 load_mode == LOADMODE_REPLACE_CONCATENATE)
1480 session->changes_made = 0;
1484 session->changes_made = 1;
1487 gui->stop_hourglass();
1490 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1491 update_project(load_mode);
1493 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1501 void MWindow::test_plugins(EDL *new_edl, char *path)
1503 char string[BCTEXTLEN];
1505 // Do a check weather plugins exist
1506 for(Track *track = new_edl->tracks->first; track; track = track->next)
1508 for(int k = 0; k < track->plugin_set.total; k++)
1510 PluginSet *plugin_set = track->plugin_set[k];
1511 for(Plugin *plugin = (Plugin*)plugin_set->first;
1513 plugin = (Plugin*)plugin->next)
1515 if(plugin->plugin_type == PLUGIN_STANDALONE)
1517 // ok we need to find it in plugindb
1518 int plugin_found = 0;
1520 for(int j = 0; j < plugindb->size(); j++)
1522 PluginServer *server = plugindb->get(j);
1524 !strcasecmp(server->title, plugin->title) &&
1525 ((track->data_type == TRACK_AUDIO && server->audio) ||
1526 (track->data_type == TRACK_VIDEO && server->video)) &&
1527 (!server->transition))
1534 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1535 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1536 "effect", plugin->title,
1538 MainError::show_error(string);
1544 for(Edit *edit = (Edit*)track->edits->first;
1546 edit = (Edit*)edit->next)
1548 if (edit->transition)
1550 // ok we need to find transition in plugindb
1552 int transition_found = 0;
1553 for(int j = 0; j < plugindb->size(); j++)
1555 PluginServer *server = plugindb->get(j);
1557 !strcasecmp(server->title, edit->transition->title) &&
1558 ((track->data_type == TRACK_AUDIO && server->audio) ||
1559 (track->data_type == TRACK_VIDEO && server->video)) &&
1560 (server->transition))
1561 transition_found = 1;
1564 if (!transition_found)
1567 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1568 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1569 "transition", edit->transition->title,
1571 MainError::show_error(string);
1579 void MWindow::init_shm()
1581 // Fix shared memory
1582 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1584 fprintf(fd, "0x7fffffff");
1589 fd = fopen("/proc/sys/kernel/shmmax", "r");
1591 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1596 fscanf(fd, _LD, &result);
1599 if(result < 0x7fffffff) {
1600 char string[BCTEXTLEN];
1601 sprintf(string, _("MWindow::init_shm: /proc/sys/kernel/shmmax is 0x" _LX ".\n"
1602 "you probably need to be root, or:\n"
1603 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1604 "before trying to start cinelerra.\n"
1605 "It should be at least 0x7fffffff for Cinelerra.\n"), result);
1606 MainError::show_error(string);
1611 void MWindow::create_objects(int want_gui,
1616 const int debug = 0;
1617 if(debug) PRINT_TRACE
1619 // For some reason, init_signals must come after show_splash or the signals won't
1622 if(debug) PRINT_TRACE
1625 if(debug) PRINT_TRACE
1628 if(debug) PRINT_TRACE
1629 init_defaults(defaults, config_path);
1631 init_plugins(this, preferences);
1632 if(debug) PRINT_TRACE
1633 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1634 if(debug) PRINT_TRACE
1636 if(debug) PRINT_TRACE
1639 char string[BCTEXTLEN];
1640 strcpy(string, preferences->plugin_dir);
1641 strcat(string, "/fonts");
1642 BC_Resources::init_fontconfig(string);
1643 if(debug) PRINT_TRACE
1645 // Initialize before too much else is running
1646 // Preferences & theme are required for building MPEG table of contents
1648 // Default project created here
1650 if(debug) PRINT_TRACE
1653 if(debug) PRINT_TRACE
1658 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1660 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1661 if(session->show_vwindow)
1662 get_viewer(1, DEFAULT_VWINDOW);
1663 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1666 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1669 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1672 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1674 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1677 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1681 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1683 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1685 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1688 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1689 mainprogress = new MainProgress(this, gui);
1690 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1691 undo = new MainUndo(this);
1693 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1695 plugin_guis = new ArrayList<PluginServer*>;
1696 dead_plugins = new ArrayList<PluginServer*>;
1697 keyframe_threads = new ArrayList<KeyFrameThread*>;
1699 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1702 session->show_vwindow);
1704 // Show all vwindows
1705 // if(session->show_vwindow) {
1706 // for(int j = 0; j < vwindows.size(); j++) {
1707 // VWindow *vwindow = vwindows[j];
1708 // if( !vwindow->is_running() ) continue;
1709 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1712 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1713 // vwindow->gui->lock_window("MWindow::create_objects 1");
1714 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1715 // vwindow->gui->show_window();
1716 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1717 // vwindow->gui->unlock_window();
1722 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1724 if(session->show_cwindow)
1726 cwindow->gui->lock_window("MWindow::create_objects 1");
1727 cwindow->gui->show_window();
1728 cwindow->gui->unlock_window();
1731 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1732 if(session->show_awindow)
1734 awindow->gui->lock_window("MWindow::create_objects 1");
1735 awindow->gui->show_window();
1736 awindow->gui->unlock_window();
1739 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1740 if(session->show_lwindow)
1742 lwindow->gui->lock_window("MWindow::create_objects 1");
1743 lwindow->gui->show_window();
1744 lwindow->gui->unlock_window();
1747 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1749 (int)timer.get_difference(),
1751 if(session->show_gwindow)
1753 gwindow->gui->lock_window("MWindow::create_objects 1");
1754 gwindow->gui->show_window();
1755 gwindow->gui->unlock_window();
1758 if(debug) PRINT_TRACE
1760 gui->lock_window("MWindow::create_objects 1");
1761 gui->mainmenu->load_defaults(defaults);
1762 gui->mainmenu->update_toggles(0);
1763 gui->update_patchbay();
1764 gui->draw_canvas(0, 0);
1765 gui->draw_cursor(1);
1767 gui->raise_window();
1768 gui->unlock_window();
1770 if(debug) PRINT_TRACE
1774 if(preferences->use_tipwindow)
1776 if(debug) PRINT_TRACE
1778 gui->add_keyboard_listener(
1779 (int (BC_WindowBase::*)(BC_WindowBase *))
1780 &MWindowGUI::keyboard_listener);
1784 if(debug) PRINT_TRACE
1786 BC_WindowBase::get_resources()->vframe_shm = 1;
1791 void MWindow::show_splash()
1793 #include "data/heroine_logo11_png.h"
1794 VFrame *frame = new VFramePng(heroine_logo11_png);
1795 BC_DisplayInfo display_info;
1796 splash_window = new SplashGUI(frame,
1797 display_info.get_root_w() / 2 - frame->get_w() / 2,
1798 display_info.get_root_h() / 2 - frame->get_h() / 2);
1799 splash_window->create_objects();
1802 void MWindow::hide_splash()
1805 delete splash_window;
1810 void MWindow::start()
1814 // vwindows[DEFAULT_VWINDOW]->start();
1825 playback_3d->start();
1834 void MWindow::show_vwindow()
1836 int total_running = 0;
1837 session->show_vwindow = 1;
1839 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
1840 // Raise all windows which are visible
1841 for(int j = 0; j < vwindows.size(); j++) {
1842 VWindow *vwindow = vwindows[j];
1843 if( !vwindow->is_running() ) continue;
1844 vwindow->gui->lock_window("MWindow::show_vwindow");
1845 vwindow->gui->show_window(0);
1846 vwindow->gui->raise_window();
1847 vwindow->gui->flush();
1848 vwindow->gui->unlock_window();
1852 // If no windows visible
1855 get_viewer(1, DEFAULT_VWINDOW);
1858 gui->mainmenu->show_vwindow->set_checked(1);
1861 void MWindow::show_awindow()
1863 session->show_awindow = 1;
1864 awindow->gui->lock_window("MWindow::show_awindow");
1865 awindow->gui->show_window();
1866 awindow->gui->raise_window();
1867 awindow->gui->flush();
1868 awindow->gui->unlock_window();
1869 gui->mainmenu->show_awindow->set_checked(1);
1872 char *MWindow::get_cwindow_display()
1874 char *x11_host = screens < 2 || session->window_config == 0 ?
1875 session->a_x11_host : session->b_x11_host;
1876 return *x11_host ? x11_host : 0;
1879 void MWindow::show_cwindow()
1881 session->show_cwindow = 1;
1882 cwindow->show_window();
1883 gui->mainmenu->show_cwindow->set_checked(1);
1886 void MWindow::show_gwindow()
1888 session->show_gwindow = 1;
1890 gwindow->gui->lock_window("MWindow::show_gwindow");
1891 gwindow->gui->show_window();
1892 gwindow->gui->raise_window();
1893 gwindow->gui->flush();
1894 gwindow->gui->unlock_window();
1896 gui->mainmenu->show_gwindow->set_checked(1);
1899 void MWindow::show_lwindow()
1901 session->show_lwindow = 1;
1902 lwindow->gui->lock_window("MWindow::show_lwindow");
1903 lwindow->gui->show_window();
1904 lwindow->gui->raise_window();
1905 lwindow->gui->flush();
1906 lwindow->gui->unlock_window();
1907 gui->mainmenu->show_lwindow->set_checked(1);
1910 int MWindow::tile_windows(int window_config)
1912 int need_reload = 0;
1913 int play_config = window_config==0 ? 0 : 1;
1914 edl->session->playback_config->load_defaults(defaults, play_config);
1915 session->default_window_positions(window_config);
1916 if( screens == 1 ) {
1917 gui->default_positions();
1918 sync_parameters(CHANGE_ALL);
1925 void MWindow::toggle_loop_playback()
1927 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1928 set_loop_boundaries();
1931 gui->draw_overlays(1);
1932 sync_parameters(CHANGE_PARAMS);
1935 //void MWindow::set_titles(int value)
1937 // edl->session->show_titles = value;
1938 // trackmovement(edl->local_session->track_start);
1941 void MWindow::set_screens(int value)
1946 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
1948 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
1949 edl->session->auto_keyframes = value;
1950 gui->mbuttons->edit_panel->keyframe->update(value);
1952 if(lock_mwindow) gui->unlock_window();
1954 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1955 cwindow->gui->edit_panel->keyframe->update(value);
1956 cwindow->gui->flush();
1957 if(lock_cwindow) cwindow->gui->unlock_window();
1960 void MWindow::set_keyframe_type(int mode)
1962 gui->lock_window("MWindow::set_keyframe_type");
1963 edl->local_session->floatauto_type = mode;
1964 gui->mainmenu->update_toggles(0);
1965 gui->unlock_window();
1968 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
1970 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
1971 edl->session->editing_mode = new_editing_mode;
1972 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1973 gui->mbuttons->edit_panel->update();
1974 gui->set_editing_mode(1);
1975 if(lock_mwindow) gui->unlock_window();
1978 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
1979 cwindow->gui->edit_panel->update();
1980 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1981 if(lock_cwindow) cwindow->gui->unlock_window();
1986 void MWindow::sync_parameters(int change_type)
1988 if( in_destructor ) return;
1990 // Sync engines which are playing back
1991 if(cwindow->playback_engine->is_playing_back)
1993 if(change_type == CHANGE_PARAMS)
1995 // TODO: block keyframes until synchronization is done
1996 cwindow->playback_engine->sync_parameters(edl);
2001 int command = cwindow->playback_engine->command->command;
2002 cwindow->playback_engine->que->send_command(STOP,
2006 // Waiting for tracking to finish would make the restart position more
2007 // accurate but it can't lock the window to stop tracking for some reason.
2008 // Not waiting for tracking gives a faster response but restart position is
2009 // only as accurate as the last tracking update.
2010 cwindow->playback_engine->interrupt_playback(0);
2011 cwindow->playback_engine->que->send_command(command,
2020 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2027 void MWindow::age_caches()
2029 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2031 // preferences->cache_size,
2032 // audio_cache->get_memory_usage(1),
2033 // video_cache->get_memory_usage(1),
2034 // frame_cache->get_memory_usage(),
2035 // wave_cache->get_memory_usage(),
2037 frame_cache->age_cache(512);
2038 wave_cache->age_cache(8192);
2040 int64_t memory_usage;
2041 int64_t prev_memory_usage = 0;
2043 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2044 while( !result && prev_memory_usage !=
2045 (memory_usage=video_cache->get_memory_usage(1)) &&
2046 memory_usage > video_size ) {
2047 video_cache->delete_oldest();
2048 prev_memory_usage = memory_usage;
2051 prev_memory_usage = 0;
2053 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2054 while( !result && prev_memory_usage !=
2055 (memory_usage=audio_cache->get_memory_usage(1)) &&
2056 memory_usage > audio_size ) {
2057 audio_cache->delete_oldest();
2058 prev_memory_usage = memory_usage;
2062 void MWindow::reset_android_remote()
2064 gui->use_android_remote(preferences->android_remote);
2068 void MWindow::show_keyframe_gui(Plugin *plugin)
2070 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2071 // Find existing thread
2072 for(int i = 0; i < keyframe_threads->size(); i++)
2074 if(keyframe_threads->get(i)->plugin == plugin)
2076 keyframe_threads->get(i)->start_window(plugin, 0);
2077 keyframe_gui_lock->unlock();
2082 // Find unused thread
2083 for(int i = 0; i < keyframe_threads->size(); i++)
2085 if(!keyframe_threads->get(i)->plugin)
2087 keyframe_threads->get(i)->start_window(plugin, 0);
2088 keyframe_gui_lock->unlock();
2093 // Create new thread
2094 KeyFrameThread *thread = new KeyFrameThread(this);
2095 keyframe_threads->append(thread);
2096 thread->start_window(plugin, 0);
2098 keyframe_gui_lock->unlock();
2105 void MWindow::show_plugin(Plugin *plugin)
2110 // Remove previously deleted plugin GUIs
2111 dead_plugin_lock->lock("MWindow::delete_plugin");
2112 for(int i = 0; i < dead_plugins->size(); i++)
2114 delete dead_plugins->get(i);
2116 dead_plugins->remove_all();
2117 dead_plugin_lock->unlock();
2119 //printf("MWindow::show_plugin %d\n", __LINE__);
2123 plugin_gui_lock->lock("MWindow::show_plugin");
2124 for(int i = 0; i < plugin_guis->total; i++)
2126 // Pointer comparison
2127 if(plugin_guis->get(i)->plugin == plugin)
2129 plugin_guis->get(i)->raise_window();
2136 //printf("MWindow::show_plugin 1\n");
2141 printf("MWindow::show_plugin track not defined.\n");
2143 PluginServer *server = scan_plugindb(plugin->title,
2144 plugin->track->data_type);
2146 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2147 if(server && server->uses_gui)
2149 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
2150 // Needs mwindow to do GUI
2151 gui->set_mwindow(this);
2152 gui->open_plugin(0, preferences, edl, plugin);
2157 plugin_gui_lock->unlock();
2158 //printf("MWindow::show_plugin %d\n", __LINE__);
2161 //printf("MWindow::show_plugin 2\n");
2164 void MWindow::hide_plugin(Plugin *plugin, int lock)
2167 // Update the toggle
2168 gui->lock_window("MWindow::hide_plugin");
2169 gui->update(0, 1, 0, 0, 0, 0, 0);
2170 gui->unlock_window();
2172 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2173 for(int i = 0; i < plugin_guis->total; i++)
2175 if(plugin_guis->get(i)->plugin == plugin)
2177 PluginServer *ptr = plugin_guis->get(i);
2178 plugin_guis->remove(ptr);
2179 if(lock) plugin_gui_lock->unlock();
2180 // Last command executed in client side close
2181 // Schedule for deletion
2188 if(lock) plugin_gui_lock->unlock();
2191 void MWindow::delete_plugin(PluginServer *plugin)
2193 dead_plugin_lock->lock("MWindow::delete_plugin");
2194 dead_plugins->append(plugin);
2195 dead_plugin_lock->unlock();
2198 void MWindow::hide_plugins()
2200 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2201 while(plugin_guis->size())
2203 PluginServer *ptr = plugin_guis->get(0);
2204 plugin_guis->remove(ptr);
2205 plugin_gui_lock->unlock();
2206 // Last command executed in client side close
2207 // Schedule for deletion
2210 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2212 plugin_gui_lock->unlock();
2214 hide_keyframe_guis();
2217 void MWindow::hide_keyframe_guis()
2219 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2220 for(int i = 0; i < keyframe_threads->size(); i++)
2222 keyframe_threads->get(i)->close_window();
2224 keyframe_gui_lock->unlock();
2227 void MWindow::hide_keyframe_gui(Plugin *plugin)
2229 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2230 for(int i = 0; i < keyframe_threads->size(); i++)
2232 if(keyframe_threads->get(i)->plugin == plugin)
2234 keyframe_threads->get(i)->close_window();
2238 keyframe_gui_lock->unlock();
2241 void MWindow::update_keyframe_guis()
2243 // Send new configuration to keyframe GUI's
2244 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2245 for(int i = 0; i < keyframe_threads->size(); i++)
2247 KeyFrameThread *ptr = keyframe_threads->get(i);
2248 if(edl->tracks->plugin_exists(ptr->plugin))
2252 ptr->close_window();
2255 keyframe_gui_lock->unlock();
2258 void MWindow::update_plugin_guis(int do_keyframe_guis)
2260 // Send new configuration to plugin GUI's
2261 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2263 for(int i = 0; i < plugin_guis->size(); i++)
2265 PluginServer *ptr = plugin_guis->get(i);
2266 if(edl->tracks->plugin_exists(ptr->plugin))
2270 // Schedule for deletion if no plugin
2271 plugin_guis->remove_number(i);
2280 // Change plugin variable if not visible
2281 Track *track = edl->tracks->first;
2284 for(int i = 0; i < track->plugin_set.size(); i++)
2286 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2290 for(int i = 0; i < plugin_guis->size(); i++)
2292 PluginServer *server = plugin_guis->get(i);
2293 if(server->plugin == plugin)
2300 if(!got_it) plugin->show = 0;
2302 plugin = (Plugin*)plugin->next;
2306 track = track->next;
2309 plugin_gui_lock->unlock();
2312 if(do_keyframe_guis) update_keyframe_guis();
2315 int MWindow::plugin_gui_open(Plugin *plugin)
2318 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2319 for(int i = 0; i < plugin_guis->total; i++)
2321 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2327 plugin_gui_lock->unlock();
2331 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2333 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2334 for(int i = 0; i < plugin_guis->total; i++)
2336 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2338 plugin_guis->get(i)->render_gui(data);
2342 plugin_gui_lock->unlock();
2345 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2347 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2348 for(int i = 0; i < plugin_guis->total; i++)
2350 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2352 plugin_guis->get(i)->render_gui(data, size);
2356 plugin_gui_lock->unlock();
2360 void MWindow::update_plugin_states()
2362 plugin_gui_lock->lock("MWindow::update_plugin_states");
2363 for(int i = 0; i < plugin_guis->total; i++)
2367 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2368 PluginServer *src_plugingui = plugin_guis->get(i);
2370 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2371 for(Track *track = edl->tracks->first;
2373 track = track->next)
2376 j < track->plugin_set.total && !result;
2379 PluginSet *plugin_set = track->plugin_set[j];
2380 for(Plugin *plugin = (Plugin*)plugin_set->first;
2382 plugin = (Plugin*)plugin->next)
2384 if(plugin == src_plugin &&
2385 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2391 // Doesn't exist anymore
2394 hide_plugin(src_plugin, 0);
2398 plugin_gui_lock->unlock();
2402 void MWindow::update_plugin_titles()
2404 for(int i = 0; i < plugin_guis->total; i++)
2406 plugin_guis->get(i)->update_title();
2410 int MWindow::asset_to_edl(EDL *new_edl,
2412 RecordLabels *labels)
2414 const int debug = 0;
2415 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2418 // Keep frame rate, sample rate, and output size unchanged.
2419 // These parameters would revert the project if VWindow displayed an asset
2420 // of different size than the project.
2421 if(new_asset->video_data)
2423 new_edl->session->video_tracks = new_asset->layers;
2426 new_edl->session->video_tracks = 0;
2428 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2434 if(new_asset->audio_data)
2436 new_edl->session->audio_tracks = new_asset->channels;
2439 new_edl->session->audio_tracks = 0;
2440 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2442 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2443 new_edl->create_default_tracks();
2444 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2445 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2449 //printf("MWindow::asset_to_edl 3\n");
2450 new_edl->insert_asset(new_asset,
2455 //printf("MWindow::asset_to_edl 3\n");
2456 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2462 char string[BCTEXTLEN];
2464 fs.extract_name(string, new_asset->path);
2465 //printf("MWindow::asset_to_edl 3\n");
2467 strcpy(new_edl->local_session->clip_title, string);
2468 //printf("MWindow::asset_to_edl 4 %s\n", string);
2469 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2474 int MWindow::edl_to_nested(EDL *new_edl,
2478 // Keep frame rate, sample rate, and output size unchanged.
2479 // These parameters would revert the project if VWindow displayed an asset
2480 // of different size than the project.
2484 // Nest all video & audio outputs
2485 new_edl->session->video_tracks = 1;
2486 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2487 new_edl->create_default_tracks();
2491 new_edl->insert_asset(0,
2497 char string[BCTEXTLEN];
2499 fs.extract_name(string, nested_edl->path);
2500 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2502 strcpy(new_edl->local_session->clip_title, string);
2507 // Reset everything after a load.
2508 void MWindow::update_project(int load_mode)
2510 const int debug = 0;
2512 if(debug) PRINT_TRACE
2514 edl->tracks->update_y_pixels(theme);
2516 if(debug) PRINT_TRACE
2518 if(load_mode == LOADMODE_REPLACE ||
2519 load_mode == LOADMODE_REPLACE_CONCATENATE)
2524 gui->update(1, 1, 1, 1, 1, 1, 1);
2525 if(debug) PRINT_TRACE
2526 gui->unlock_window();
2528 cwindow->gui->lock_window("MWindow::update_project 1");
2529 cwindow->update(0, 0, 1, 1, 1);
2530 cwindow->gui->unlock_window();
2532 if(debug) PRINT_TRACE
2534 // Close all the vwindows
2535 if(load_mode == LOADMODE_REPLACE ||
2536 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2537 if(debug) PRINT_TRACE
2538 int first_vwindow = 0;
2539 if(session->show_vwindow) first_vwindow = 1;
2540 // Change visible windows to no source
2541 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2542 VWindow *vwindow = vwindows[i];
2543 if( !vwindow->is_running() ) continue;
2544 vwindow->change_source(-1);
2547 // Close remaining windows
2548 for(int i = first_vwindow; i < vwindows.size(); i++) {
2549 VWindow *vwindow = vwindows[i];
2550 if( !vwindow->is_running() ) continue;
2551 vwindow->close_window();
2553 if(debug) PRINT_TRACE
2555 else if(vwindows.size()) {
2556 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2557 if( vwindow->is_running() ) {
2558 vwindow->gui->lock_window("MWindow::update_project");
2560 vwindow->gui->unlock_window();
2564 if(debug) PRINT_TRACE
2565 cwindow->gui->lock_window("MWindow::update_project 2");
2566 cwindow->gui->timebar->update(0);
2567 cwindow->gui->unlock_window();
2569 if(debug) PRINT_TRACE
2570 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2575 if(debug) PRINT_TRACE
2577 awindow->gui->lock_window("MWindow::update_project");
2578 awindow->gui->update_assets();
2579 awindow->gui->flush();
2580 awindow->gui->unlock_window();
2582 if(debug) PRINT_TRACE
2584 gui->lock_window("MWindow::update_project");
2586 if(debug) PRINT_TRACE
2589 void MWindow::remove_indexfile(Indexable *indexable)
2591 if( !indexable->is_asset ) return;
2592 Asset *asset = (Asset *)indexable;
2594 IndexFile::delete_index(preferences, asset, ".toc");
2595 IndexFile::delete_index(preferences, asset, ".idx");
2596 IndexFile::delete_index(preferences, asset, ".mkr");
2599 void MWindow::rebuild_indices()
2601 for(int i = 0; i < session->drag_assets->total; i++)
2603 Indexable *indexable = session->drag_assets->get(i);
2604 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2605 remove_indexfile(indexable);
2606 // Schedule index build
2607 IndexState *index_state = indexable->index_state;
2608 index_state->index_status = INDEX_NOTTESTED;
2609 if( indexable->is_asset ) {
2610 Asset *asset = (Asset *)indexable;
2611 if( asset->format != FILE_PCM )
2612 asset->reset_audio();
2613 asset->reset_video();
2615 mainindexes->add_next_asset(0, indexable);
2617 mainindexes->start_build();
2621 void MWindow::save_backup()
2624 edl->set_path(session->filename);
2625 edl->save_xml(&file,
2629 file.terminate_string();
2630 char path[BCTEXTLEN];
2632 strcpy(path, BACKUP_PATH);
2633 fs.complete_path(path);
2635 if(file.write_to_file(path))
2638 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2639 gui->show_message(string2);
2643 void MWindow::load_backup()
2645 ArrayList<char*> path_list;
2646 path_list.set_array_delete();
2648 char string[BCTEXTLEN];
2649 strcpy(string, BACKUP_PATH);
2651 fs.complete_path(string);
2653 path_list.append(out_path = new char[strlen(string) + 1]);
2654 strcpy(out_path, string);
2656 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2657 edl->local_session->clip_title[0] = 0;
2658 // This is unique to backups since the path of the backup is different than the
2659 // path of the project.
2660 set_filename(edl->path);
2661 path_list.remove_all_objects();
2665 static inline int gcd(int m, int n)
2668 if( m < n ) { r = m; m = n; n = r; }
2669 while( (r = m % n) != 0 ) { m = n; n = r; }
2673 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2676 if(!width || !height) return 1;
2677 double ar = (double)width / height;
2678 // square-ish pixels
2679 if( EQUIV(ar, 1.0000) ) return 0;
2680 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2681 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2682 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2683 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2684 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2685 int ww = width, hh = height;
2686 // numerator, denominator must be under mx
2687 int mx = 255, n = gcd(ww, hh);
2688 if( n > 1 ) { ww /= n; hh /= n; }
2689 // search near height in case extra/missing lines
2690 if( ww >= mx || hh >= mx ) {
2691 double err = height; // +/- 2 percent height
2692 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2693 int iw = width, ih = height+i;
2694 if( (n=gcd(iw, ih)) > 1 ) {
2695 int u = iw/n; if( u >= mx ) continue;
2696 int v = ih/n; if( v >= mx ) continue;
2697 double r = (double) u/v, er = fabs(ar-r);
2698 if( er >= err ) continue;
2699 err = er; ww = u; hh = v;
2708 void MWindow::reset_caches()
2710 frame_cache->remove_all();
2711 wave_cache->remove_all();
2712 audio_cache->remove_all();
2713 video_cache->remove_all();
2714 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2715 cwindow->playback_engine->audio_cache->remove_all();
2716 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2717 cwindow->playback_engine->video_cache->remove_all();
2719 for(int i = 0; i < vwindows.size(); i++) {
2720 VWindow *vwindow = vwindows[i];
2721 if( !vwindow->is_running() ) continue;
2722 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2723 vwindow->playback_engine->audio_cache->remove_all();
2724 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2725 vwindow->playback_engine->video_cache->remove_all();
2729 void MWindow::remove_asset_from_caches(Asset *asset)
2731 frame_cache->remove_asset(asset);
2732 wave_cache->remove_asset(asset);
2733 audio_cache->delete_entry(asset);
2734 video_cache->delete_entry(asset);
2735 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2736 cwindow->playback_engine->audio_cache->delete_entry(asset);
2737 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2738 cwindow->playback_engine->video_cache->delete_entry(asset);
2739 for(int i = 0; i < vwindows.size(); i++) {
2740 VWindow *vwindow = vwindows[i];
2741 if( !vwindow->is_running() ) continue;
2742 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2743 vwindow->playback_engine->audio_cache->delete_entry(asset);
2744 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2745 vwindow->playback_engine->video_cache->delete_entry(asset);
2750 void MWindow::remove_assets_from_project(int push_undo, int redraw,
2751 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
2753 for(int i = 0; i < session->drag_assets->total; i++) {
2754 Indexable *indexable = session->drag_assets->get(i);
2755 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
2758 // Remove from VWindow.
2759 for(int i = 0; i < session->drag_clips->total; i++) {
2760 for(int j = 0; j < vwindows.size(); j++) {
2761 VWindow *vwindow = vwindows[j];
2762 if( !vwindow->is_running() ) continue;
2763 if(session->drag_clips->get(i) == vwindow->get_edl()) {
2764 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
2765 vwindow->delete_source(1, 1);
2766 vwindow->gui->unlock_window();
2771 for(int i = 0; i < session->drag_assets->size(); i++) {
2772 for(int j = 0; j < vwindows.size(); j++) {
2773 VWindow *vwindow = vwindows[j];
2774 if( !vwindow->is_running() ) continue;
2775 if(session->drag_assets->get(i) == vwindow->get_source()) {
2776 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
2777 vwindow->delete_source(1, 1);
2778 vwindow->gui->unlock_window();
2783 for(int i = 0; i < session->drag_assets->size(); i++) {
2784 Indexable *indexable = session->drag_assets->get(i);
2785 remove_indexfile(indexable);
2788 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2789 if(push_undo) undo->update_undo_before();
2790 if(drag_assets) edl->remove_from_project(drag_assets);
2791 if(drag_clips) edl->remove_from_project(session->drag_clips);
2792 if(redraw) save_backup();
2793 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
2798 gui->lock_window("MWindow::remove_assets_from_project 3");
2806 gui->unlock_window();
2808 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
2809 awindow->gui->update_assets();
2810 awindow->gui->flush();
2811 awindow->gui->unlock_window();
2813 // Removes from playback here
2814 sync_parameters(CHANGE_ALL);
2818 void MWindow::remove_assets_from_disk()
2821 for(int i = 0; i < session->drag_assets->total; i++)
2823 remove(session->drag_assets->get(i)->path);
2826 remove_assets_from_project(1,
2828 session->drag_assets,
2829 session->drag_clips);
2832 void MWindow::dump_plugins(FILE *fp)
2834 if( !plugindb ) return;
2835 for(int i = 0; i < plugindb->total; i++)
2837 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
2838 " synth=%d transition=%d theme=%d %s\n",
2839 plugindb->get(i)->plugin_type,
2840 plugindb->get(i)->audio,
2841 plugindb->get(i)->video,
2842 plugindb->get(i)->realtime,
2843 plugindb->get(i)->multichannel,
2844 plugindb->get(i)->get_synthesis(),
2845 plugindb->get(i)->transition,
2846 plugindb->get(i)->theme,
2847 plugindb->get(i)->title);
2851 void MWindow::dump_edl(FILE *fp)
2857 void MWindow::dump_undo(FILE *fp)
2863 void MWindow::dump_exe(FILE *fp)
2865 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
2866 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
2867 int len = readlink(proc_path, exe_path, sizeof(exe_path));
2868 if( len < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
2871 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
2872 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
2873 int fd = open(exe_path,O_RDONLY);
2874 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
2875 uint8_t buf[65536]; SHA1 sha1;
2876 while( (len=read(fd,buf,sizeof(buf))) > 0 ) {
2877 sha1.addBytes(buf, len);
2880 fprintf(fp, "SHA1: ");
2881 uint8_t digest[20]; sha1.computeHash(digest);
2882 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
2887 void MWindow::trap_hook(FILE *fp, void *vp)
2889 MWindow *mwindow = (MWindow *)vp;
2890 fprintf(fp, "\nEXE:\n");
2891 mwindow->dump_exe(fp);
2892 fprintf(fp, "\nPLUGINS:\n");
2893 mwindow->dump_plugins(fp);
2894 fprintf(fp, "\nEDL:\n");
2895 mwindow->dump_edl(fp);
2896 fprintf(fp, "\nUNDO:\n");
2897 mwindow->dump_undo(fp);
2905 int MWindow::save_defaults()
2907 gui->save_defaults(defaults);
2908 edl->save_defaults(defaults);
2909 session->save_defaults(defaults);
2910 preferences->save_defaults(defaults);
2912 for(int i = 0; i < plugin_guis->total; i++)
2914 // Pointer comparison
2915 plugin_guis->get(i)->save_defaults();
2917 awindow->save_defaults(defaults);
2923 int MWindow::run_script(FileXML *script)
2925 int result = 0, result2 = 0;
2926 while(!result && !result2)
2928 result = script->read_tag();
2931 if(script->tag.title_is("new_project"))
2933 // Run new in immediate mode.
2934 // gui->mainmenu->new_project->run_script(script);
2937 if(script->tag.title_is("record"))
2939 // Run record as a thread. It is a terminal command.
2941 // Will read the complete scipt file without letting record read it if not
2947 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
2954 // ================================= synchronization
2957 int MWindow::interrupt_indexes()
2959 mainindexes->interrupt_build();
2965 void MWindow::next_time_format()
2967 switch(edl->session->time_format)
2969 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
2970 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
2971 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2972 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
2973 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
2974 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
2975 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
2978 time_format_common();
2981 void MWindow::prev_time_format()
2983 switch(edl->session->time_format)
2985 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
2986 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
2987 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
2988 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2989 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
2990 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
2991 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
2994 time_format_common();
2997 void MWindow::time_format_common()
2999 gui->lock_window("MWindow::next_time_format");
3000 gui->redraw_time_dependancies();
3003 char string[BCTEXTLEN], string2[BCTEXTLEN];
3004 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3005 gui->show_message(string);
3007 gui->unlock_window();
3011 int MWindow::set_filename(const char *filename)
3013 if( filename != session->filename )
3014 strcpy(session->filename, filename);
3015 if( filename != edl->path )
3016 strcpy(edl->path, filename);
3020 if(filename[0] == 0)
3022 gui->set_title(PROGRAM_NAME);
3027 char string[BCTEXTLEN], string2[BCTEXTLEN];
3028 dir.extract_name(string, filename);
3029 sprintf(string2, PROGRAM_NAME ": %s", string);
3030 gui->set_title(string2);
3043 int MWindow::set_loop_boundaries()
3045 double start = edl->local_session->get_selectionstart();
3046 double end = edl->local_session->get_selectionend();
3054 if(edl->tracks->total_length())
3057 end = edl->tracks->total_length();
3064 if(edl->local_session->loop_playback && start != end)
3066 edl->local_session->loop_start = start;
3067 edl->local_session->loop_end = end;
3078 int MWindow::reset_meters()
3080 cwindow->gui->lock_window("MWindow::reset_meters 1");
3081 cwindow->gui->meters->reset_meters();
3082 cwindow->gui->unlock_window();
3084 for(int j = 0; j < vwindows.size(); j++) {
3085 VWindow *vwindow = vwindows[j];
3086 if( !vwindow->is_running() ) continue;
3087 vwindow->gui->lock_window("MWindow::reset_meters 2");
3088 vwindow->gui->meters->reset_meters();
3089 vwindow->gui->unlock_window();
3092 lwindow->gui->lock_window("MWindow::reset_meters 3");
3093 lwindow->gui->panel->reset_meters();
3094 lwindow->gui->unlock_window();
3096 gui->lock_window("MWindow::reset_meters 4");
3097 gui->reset_meters();
3098 gui->unlock_window();
3103 void MWindow::resync_guis()
3107 gui->lock_window("MWindow::resync_guis");
3108 gui->update(1, 1, 1, 1, 1, 1, 0);
3109 gui->unlock_window();
3111 cwindow->gui->lock_window("MWindow::resync_guis");
3112 cwindow->gui->resize_event(cwindow->gui->get_w(),
3113 cwindow->gui->get_h());
3114 int channels = edl->session->audio_channels;
3115 cwindow->gui->meters->set_meters(channels, 1);
3116 cwindow->gui->flush();
3117 cwindow->gui->unlock_window();
3119 for(int i = 0; i < vwindows.size(); i++) {
3120 VWindow *vwindow = vwindows[i];
3121 if( !vwindow->is_running() ) continue;
3122 vwindow->gui->lock_window("MWindow::resync_guis");
3123 vwindow->gui->resize_event(vwindow->gui->get_w(),
3124 vwindow->gui->get_h());
3125 vwindow->gui->meters->set_meters(channels, 1);
3126 vwindow->gui->flush();
3127 vwindow->gui->unlock_window();
3130 lwindow->gui->lock_window("MWindow::resync_guis");
3131 lwindow->gui->panel->set_meters(channels, 1);
3132 lwindow->gui->flush();
3133 lwindow->gui->unlock_window();
3136 if(((edl->session->output_w % 4) ||
3137 (edl->session->output_h % 4)) &&
3138 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3140 MainError::show_error(
3141 _("This project's dimensions are not multiples of 4 so\n"
3142 "it can't be rendered by OpenGL."));
3147 sync_parameters(CHANGE_ALL);
3150 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3152 File *file = new File;
3153 EDLSession *session = edl->session;
3154 double old_framerate = session->frame_rate;
3155 double old_samplerate = session->sample_rate;
3156 int result = file->open_file(preferences, asset, 1, 0);
3157 if( !result && delete_tracks > 0 )
3158 undo->update_undo_before();
3159 if( !result && asset->get_video_layers() > 0 ) {
3160 // try to get asset up to date, may fail
3161 file->select_video_stream(asset, vstream);
3162 // either way use what was/is there.
3163 double framerate = asset->get_frame_rate();
3164 int width = asset->get_w();
3165 int height = asset->get_h();
3166 // must be multiple of 4 for opengl
3167 width = (width+3) & ~3; height = (height+3) & ~3;
3168 int driver = session->playback_config->vconfig->driver;
3169 int color_model = file->get_best_colormodel(asset, driver);
3170 color_model = BC_CModels::is_yuv(color_model) ?
3171 BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3172 BC_CModels::is_float(color_model) ?
3173 BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3174 BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3175 session->color_model = color_model;
3176 session->output_w = width;
3177 session->output_h = height;
3178 session->frame_rate = framerate;
3179 // not, asset->actual_width/actual_height
3180 asset->width = session->output_w;
3181 asset->height = session->output_h;
3182 asset->frame_rate = session->frame_rate;
3183 create_aspect_ratio(session->aspect_w, session->aspect_h,
3184 session->output_w, session->output_h);
3185 Track *track = edl->tracks->first;
3186 for( Track *next_track=0; track; track=next_track ) {
3187 next_track = track->next;
3188 if( track->data_type != TRACK_VIDEO ) continue;
3189 if( delete_tracks ) {
3190 Edit *edit = track->edits->first;
3191 for( Edit *next_edit=0; edit; edit=next_edit ) {
3192 next_edit = edit->next;
3193 if( edit->channel != vstream ||
3194 !edit->asset || !edit->asset->is_asset ||
3195 *asset != *edit->asset )
3199 if( track->edits->first ) {
3200 track->track_w = edl->session->output_w;
3201 track->track_h = edl->session->output_h;
3203 else if( delete_tracks )
3204 edl->tracks->delete_track(track);
3206 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3208 if( !result && asset->channels > 0 ) {
3209 session->sample_rate = asset->get_sample_rate();
3210 int64_t channel_mask = 0;
3211 int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
3212 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3213 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3215 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3216 if( channels > 6 ) channels = 6;
3217 session->audio_tracks = session->audio_channels = channels;
3218 switch( channels ) {
3220 session->achannel_positions[0] = 90;
3221 session->achannel_positions[1] = 150;
3222 session->achannel_positions[2] = 30;
3223 session->achannel_positions[3] = 210;
3224 session->achannel_positions[4] = 330;
3225 session->achannel_positions[5] = 270;
3228 session->achannel_positions[0] = 180;
3229 session->achannel_positions[1] = 0;
3232 remap_audio(MWindow::AUDIO_1_TO_1);
3234 if( delete_tracks ) {
3235 Track *track = edl->tracks->first;
3236 for( Track *next_track=0; track; track=next_track ) {
3237 next_track = track->next;
3238 if( track->data_type != TRACK_AUDIO ) continue;
3239 Edit *edit = track->edits->first;
3240 for( Edit *next_edit=0; edit; edit=next_edit ) {
3241 next_edit = edit->next;
3242 if( !((1<<edit->channel) & channel_mask) ||
3243 !edit->asset || !edit->asset->is_asset ||
3244 *asset != *edit->asset )
3247 if( !track->edits->first )
3248 edl->tracks->delete_track(track);
3252 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3255 if( !result && delete_tracks > 0 ) {
3257 undo->update_undo_after(_("select asset"), LOAD_ALL);
3263 int MWindow::select_asset(int vtrack, int delete_tracks)
3265 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3266 if( !track ) return 1;
3267 Edit *edit = track->edits->first;
3268 if( !edit ) return 1;
3269 Asset *asset = edit->asset;
3270 if( !asset || !asset->is_asset ) return 1;
3271 return select_asset(asset, edit->channel, -1, delete_tracks);
3274 void MWindow::dump_plugindb(FILE *fp)
3276 if( !plugindb ) return;
3277 for(int i = 0; i < plugindb->total; i++)
3278 plugindb->get(i)->dump(fp);