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 PluginServer *theme_plugin = 0;
695 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
696 if( plugindb->get(i)->theme &&
697 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
698 theme_plugin = plugindb->get(i);
702 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
705 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
706 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
708 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
709 if( plugindb->get(i)->theme &&
710 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
711 theme_plugin = plugindb->get(i);
716 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
720 PluginServer *plugin = new PluginServer(*theme_plugin);
721 if( plugin->open_plugin(0, preferences, 0, 0) ) {
722 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
723 theme_plugin->title);
727 theme = plugin->new_theme();
728 theme->mwindow = this;
729 strcpy(theme->path, plugin->path);
732 // Load default images & settings
733 theme->Theme::initialize();
734 // Load user images & settings
736 // Create menus with user colors
737 theme->build_menus();
742 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
745 void MWindow::init_3d()
747 playback_3d = new Playback3D(this);
748 playback_3d->create_objects();
751 void MWindow::init_edl()
754 edl->create_objects();
755 edl->load_defaults(defaults);
756 edl->create_default_tracks();
757 edl->tracks->update_y_pixels(theme);
760 void MWindow::init_compositor()
762 cwindow = new CWindow(this);
763 cwindow->create_objects();
766 void MWindow::init_levelwindow()
768 lwindow = new LevelWindow(this);
769 lwindow->create_objects();
772 VWindow *MWindow::get_viewer(int start_it, int idx)
774 vwindows_lock->lock("MWindow::get_viewer");
775 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
776 if( !vwindow ) idx = vwindows.size();
777 while( !vwindow && --idx >= 0 ) {
778 VWindow *vwin = vwindows[idx];
779 if( !vwin->is_running() || !vwin->get_edl() )
783 vwindow = new VWindow(this);
784 vwindow->load_defaults();
785 vwindow->create_objects();
786 vwindows.append(vwindow);
788 vwindows_lock->unlock();
789 if( start_it ) vwindow->start();
793 void MWindow::init_cache()
795 audio_cache = new CICache(preferences);
796 video_cache = new CICache(preferences);
797 frame_cache = new FrameCache;
798 wave_cache = new WaveCache;
801 void MWindow::init_channeldb()
803 channeldb_buz->load("channeldb_buz");
804 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
807 void MWindow::init_menus()
809 char string[BCTEXTLEN];
810 BC_CModels::to_text(string, BC_RGB888);
811 colormodels.append(new ColormodelItem(string, BC_RGB888));
812 BC_CModels::to_text(string, BC_RGBA8888);
813 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
814 // BC_CModels::to_text(string, BC_RGB161616);
815 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
816 // BC_CModels::to_text(string, BC_RGBA16161616);
817 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
818 BC_CModels::to_text(string, BC_RGB_FLOAT);
819 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
820 BC_CModels::to_text(string, BC_RGBA_FLOAT);
821 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
822 BC_CModels::to_text(string, BC_YUV888);
823 colormodels.append(new ColormodelItem(string, BC_YUV888));
824 BC_CModels::to_text(string, BC_YUVA8888);
825 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
826 // BC_CModels::to_text(string, BC_YUV161616);
827 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
828 // BC_CModels::to_text(string, BC_YUVA16161616);
829 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
832 void MWindow::init_indexes()
834 mainindexes = new MainIndexes(this);
835 mainindexes->start_loop();
838 void MWindow::init_gui()
840 gui = new MWindowGUI(this);
841 gui->lock_window("MWindow::init_gui");
842 gui->create_objects();
843 gui->unlock_window();
844 gui->load_defaults(defaults);
847 void MWindow::init_signals()
849 sighandler = new SigHandler;
850 sighandler->initialize();
854 void MWindow::init_render()
856 render = new Render(this);
857 create_bd = new CreateBD_Thread(this);
858 create_dvd = new CreateDVD_Thread(this);
859 batch_render = new BatchRenderThread(this);
862 void MWindow::init_brender()
864 if(preferences->use_brender && !brender)
866 brender_lock->lock("MWindow::init_brender 1");
867 brender = new BRender(this);
868 brender->initialize();
869 session->brender_end = 0;
870 brender_lock->unlock();
873 if(!preferences->use_brender && brender)
875 brender_lock->lock("MWindow::init_brender 2");
878 session->brender_end = 0;
879 brender_lock->unlock();
881 if(brender) brender->restart(edl);
884 void MWindow::restart_brender()
886 //printf("MWindow::restart_brender 1\n");
887 if(brender) brender->restart(edl);
890 void MWindow::stop_brender()
892 if(brender) brender->stop();
895 int MWindow::brender_available(int position)
898 brender_lock->lock("MWindow::brender_available 1");
901 if(brender->map_valid)
903 brender->map_lock->lock("MWindow::brender_available 2");
904 if(position < brender->map_size &&
907 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
908 if(brender->map[position] == BRender::RENDERED)
911 brender->map_lock->unlock();
914 brender_lock->unlock();
918 void MWindow::set_brender_start()
920 edl->session->brender_start = edl->local_session->get_selectionstart(1);
922 gui->draw_overlays(1);
926 int MWindow::has_commercials()
928 return theme->use_commercials;
931 void MWindow::init_commercials()
934 commercials = new Commercials(this);
935 commercial_active = 0;
938 commercials->add_user();
941 void MWindow::commit_commercial()
943 if( !commercial_active ) return;
944 commercial_active = 0;
945 if( !commercials ) return;
946 commercials->commitDb();
949 void MWindow::undo_commercial()
951 if( !commercial_active ) return;
952 commercial_active = 0;
953 if( !commercials ) return;
954 commercials->undoDb();
957 int MWindow::put_commercial()
959 double start = edl->local_session->get_selectionstart();
960 double end = edl->local_session->get_selectionend();
961 if( start >= end ) return 0;
963 const char *errmsg = 0;
965 Tracks *tracks = edl->tracks;
968 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
969 if( track->data_type != TRACK_VIDEO ) continue;
970 if( !track->record ) continue;
971 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
973 int64_t units_start = track->to_units(start,0);
974 int64_t units_end = track->to_units(end,0);
975 Edits *edits = track->edits;
976 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
977 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
978 if(!edit1 && !edit2) continue; // nothing selected
979 if(!edit2) { // edit2 beyond end of track
981 units_end = edits->length();
983 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
984 Indexable *indexable = edit1->get_source();
985 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
988 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
989 if( track->data_type != TRACK_VIDEO ) continue;
990 if( !track->record ) continue;
991 int64_t units_start = track->to_units(start,0);
992 int64_t units_end = track->to_units(end,0);
993 Edits *edits = track->edits;
994 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
995 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
996 if(!edit1 && !edit2) continue; // nothing selected
997 if(!edit2) { // edit2 beyond end of track
999 units_end = edits->length();
1001 Indexable *indexable = edit1->get_source();
1002 Asset *asset = (Asset *)indexable;
1003 File *file = video_cache->check_out(asset, edl);
1004 if( !file ) { errmsg = _("no file"); break; }
1005 int64_t edit_length = units_end - units_start;
1006 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1007 result = commercials->put_clip(file, edit1->channel,
1008 track->from_units(edit_start), track->from_units(edit_length));
1009 video_cache->check_in(asset);
1010 if( result ) { errmsg = _("db failed"); break; }
1013 char string[BCTEXTLEN];
1014 sprintf(string, _("put_commercial: %s"), errmsg);
1015 MainError::show_error(string);
1022 void MWindow::stop_playback(int wait)
1024 int locked = gui->get_window_lock();
1025 if( locked ) gui->unlock_window();
1027 cwindow->playback_engine->que->send_command(STOP,
1031 cwindow->playback_engine->interrupt_playback(wait);
1033 for(int i = 0; i < vwindows.size(); i++) {
1034 VWindow *vwindow = vwindows[i];
1035 if( !vwindow->is_running() ) continue;
1036 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1037 vwindow->playback_engine->interrupt_playback(wait);
1039 if( locked ) gui->lock_window("MWindow::stop_playback");
1042 int MWindow::load_filenames(ArrayList<char*> *filenames,
1044 int update_filename)
1046 ArrayList<EDL*> new_edls;
1047 ArrayList<Asset*> new_assets;
1048 ArrayList<File*> new_files;
1049 const int debug = 0;
1050 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1053 gui->start_hourglass();
1055 // Need to stop playback since tracking depends on the EDL not getting
1059 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1060 undo->update_undo_before();
1063 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1065 // Define new_edls and new_assets to load
1066 int result = 0, ftype = -1;
1067 for(int i = 0; i < filenames->size(); i++)
1070 File *new_file = new File;
1071 Asset *new_asset = new Asset(filenames->get(i));
1072 EDL *new_edl = new EDL;
1073 char string[BCTEXTLEN];
1075 new_edl->create_objects();
1076 new_edl->copy_session(edl);
1077 new_file->set_program(edl->session->program_no);
1079 sprintf(string, _("Loading %s"), new_asset->path);
1080 gui->show_message(string);
1081 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1083 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1084 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1089 // Convert media file to EDL
1091 // Warn about odd image dimensions
1092 if(new_asset->video_data &&
1093 ((new_asset->width % 2) ||
1094 (new_asset->height % 2)))
1096 char string[BCTEXTLEN];
1097 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1101 MainError::show_error(string);
1104 if(new_asset->program >= 0 &&
1105 edl->session->program_no != new_asset->program)
1107 char string[BCTEXTLEN];
1108 sprintf(string, _("%s's index was built for program number %d\n"
1109 "Playback preference is %d.\n Using program %d."),
1110 new_asset->path, new_asset->program,
1111 edl->session->program_no, new_asset->program);
1112 MainError::show_error(string);
1116 if(load_mode != LOADMODE_RESOURCESONLY)
1119 RecordLabels *labels = edl->session->label_cells ?
1120 new RecordLabels(new_file) : 0;
1122 asset_to_edl(new_edl, new_asset, labels);
1124 new_edls.append(new_edl);
1126 new_asset->Garbage::remove_user();
1132 new_assets.append(new_asset);
1136 // Set filename to nothing for assets since save EDL would overwrite them.
1137 if(load_mode == LOADMODE_REPLACE ||
1138 load_mode == LOADMODE_REPLACE_CONCATENATE)
1141 // Reset timeline position
1142 for(int i = 0; i < TOTAL_PANES; i++)
1144 new_edl->local_session->view_start[i] = 0;
1145 new_edl->local_session->track_start[i] = 0;
1153 case FILE_NOT_FOUND:
1154 sprintf(string, _("Failed to open %s"), new_asset->path);
1155 gui->show_message(string, theme->message_error);
1159 case FILE_UNRECOGNIZED_CODEC:
1162 IndexFile indexfile(this, new_asset);
1163 result = indexfile.open_index();
1166 indexfile.close_index();
1169 // Test existing EDLs
1172 for(int j = 0; j < new_edls.total + 1; j++)
1175 if(j == new_edls.total)
1177 old_asset = edl->assets->get_asset(new_asset->path);
1180 *new_asset = *old_asset;
1186 old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1189 *new_asset = *old_asset;
1199 char string[BCTEXTLEN];
1201 fs.extract_name(string, new_asset->path);
1203 strcat(string, _("'s format couldn't be determined."));
1204 new_asset->audio_data = 1;
1205 new_asset->format = FILE_PCM;
1206 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1207 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1208 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1209 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1210 new_asset->signed_ = defaults->get("SIGNED_", 1);
1211 new_asset->header = defaults->get("HEADER", 0);
1213 FileFormat fwindow(this);
1214 fwindow.create_objects(new_asset, string);
1215 result = fwindow.run_window();
1218 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1219 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1220 defaults->update("AUDIO_BITS", new_asset->bits);
1221 defaults->update("BYTE_ORDER", new_asset->byte_order);
1222 defaults->update("SIGNED_", new_asset->signed_);
1223 defaults->update("HEADER", new_asset->header);
1230 // Recalculate length
1232 new_file = new File;
1233 result = new_file->open_file(preferences, new_asset, 1, 0);
1235 if(load_mode != LOADMODE_RESOURCESONLY)
1237 RecordLabels *labels = edl->session->label_cells ?
1238 new RecordLabels(new_file) : 0;
1239 asset_to_edl(new_edl, new_asset, labels);
1240 new_edls.append(new_edl);
1241 new_asset->Garbage::remove_user();
1247 new_assets.append(new_asset);
1261 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1262 xml_file.read_from_file(filenames->get(i));
1263 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1265 if(load_mode == LOADMODE_NESTED)
1267 // Load temporary EDL for nesting.
1268 EDL *nested_edl = new EDL;
1269 nested_edl->create_objects();
1270 nested_edl->set_path(filenames->get(i));
1271 nested_edl->load_xml(&xml_file, LOAD_ALL);
1272 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1273 edl_to_nested(new_edl, nested_edl);
1274 nested_edl->Garbage::remove_user();
1278 // Load EDL for pasting
1279 new_edl->load_xml(&xml_file, LOAD_ALL);
1280 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1281 test_plugins(new_edl, filenames->get(i));
1282 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1284 if(load_mode == LOADMODE_REPLACE ||
1285 load_mode == LOADMODE_REPLACE_CONCATENATE)
1287 strcpy(session->filename, filenames->get(i));
1288 strcpy(new_edl->local_session->clip_title,
1291 set_filename(new_edl->local_session->clip_title);
1295 new_edls.append(new_edl);
1301 // edls are in new_edls
1302 if( result && new_edl ) new_edl->Garbage::remove_user();
1303 // assets are copied
1304 if( new_asset ) new_asset->Garbage::remove_user();
1306 // Store for testing index
1307 new_files.append(new_file);
1310 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1313 if(!result) gui->statusbar->default_message();
1321 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1324 // Don't back up here.
1327 // For pasting, clear the active region
1328 if(load_mode == LOADMODE_PASTE ||
1329 load_mode == LOADMODE_NESTED)
1331 double start = edl->local_session->get_selectionstart();
1332 double end = edl->local_session->get_selectionend();
1333 if(!EQUIV(start, end))
1336 edl->session->labels_follow_edits,
1337 edl->session->plugins_follow_edits,
1338 edl->session->autos_follow_edits);
1341 paste_edls(&new_edls,
1345 edl->session->labels_follow_edits,
1346 edl->session->plugins_follow_edits,
1347 edl->session->autos_follow_edits);
1353 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1355 // Add new assets to EDL and schedule assets for index building.
1356 int got_indexes = 0;
1357 for(int i = 0; i < new_edls.size(); i++)
1359 EDL *new_edl = new_edls[i];
1360 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1362 mainindexes->add_next_asset(0,
1363 new_edl->nested_edls->get(j));
1365 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1370 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1371 if(new_assets.size())
1373 for(int i = 0; i < new_assets.size(); i++)
1375 Asset *new_asset = new_assets[i];
1379 for(int j = 0; j < new_files.size(); j++)
1381 new_file = new_files[j];
1382 if(!strcmp(new_file->asset->path,
1390 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1392 edl->assets->update(new_asset);
1398 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1400 // Start examining next batch of index files
1401 if(got_indexes) mainindexes->start_build();
1402 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1405 Track *track = edl->tracks->first;
1408 for(int j = 0; j < track->plugin_set.size(); j++)
1410 PluginSet *plugins = track->plugin_set[j];
1411 Plugin *plugin = plugins->get_first_plugin();
1415 if(load_mode == LOADMODE_REPLACE ||
1416 load_mode == LOADMODE_REPLACE_CONCATENATE)
1418 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1421 show_plugin(plugin);
1429 plugin = (Plugin*)plugin->next;
1433 track = track->next;
1436 // if just opening one new resource in replace mode
1437 if( load_mode == LOADMODE_REPLACE && new_edls.size() == 1 &&
1438 ftype != FILE_IS_XML )
1441 edl->local_session->preview_start = 0;
1442 edl->local_session->preview_end = edl->tracks->total_playable_length();
1443 edl->local_session->loop_playback = 0;
1444 edl->local_session->set_selectionstart(0);
1445 edl->local_session->set_selectionend(0);
1450 // need to update undo before project, since mwindow is unlocked & a new load
1451 // can begin here. Should really prevent loading until we're done.
1452 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1453 undo->update_undo_after(_("load"), LOAD_ALL);
1455 for(int i = 0; i < new_edls.size(); i++)
1457 new_edls[i]->remove_user();
1459 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1461 new_edls.remove_all();
1463 for(int i = 0; i < new_assets.size(); i++)
1465 new_assets[i]->Garbage::remove_user();
1468 new_assets.remove_all();
1469 new_files.remove_all_objects();
1472 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1473 if(load_mode == LOADMODE_REPLACE ||
1474 load_mode == LOADMODE_REPLACE_CONCATENATE)
1476 session->changes_made = 0;
1480 session->changes_made = 1;
1483 gui->stop_hourglass();
1486 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1487 update_project(load_mode);
1489 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1497 void MWindow::test_plugins(EDL *new_edl, char *path)
1499 char string[BCTEXTLEN];
1501 // Do a check weather plugins exist
1502 for(Track *track = new_edl->tracks->first; track; track = track->next)
1504 for(int k = 0; k < track->plugin_set.total; k++)
1506 PluginSet *plugin_set = track->plugin_set[k];
1507 for(Plugin *plugin = (Plugin*)plugin_set->first;
1509 plugin = (Plugin*)plugin->next)
1511 if(plugin->plugin_type == PLUGIN_STANDALONE)
1513 // ok we need to find it in plugindb
1514 int plugin_found = 0;
1516 for(int j = 0; j < plugindb->size(); j++)
1518 PluginServer *server = plugindb->get(j);
1520 !strcasecmp(server->title, plugin->title) &&
1521 ((track->data_type == TRACK_AUDIO && server->audio) ||
1522 (track->data_type == TRACK_VIDEO && server->video)) &&
1523 (!server->transition))
1530 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1531 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1532 "effect", plugin->title,
1534 MainError::show_error(string);
1540 for(Edit *edit = (Edit*)track->edits->first;
1542 edit = (Edit*)edit->next)
1544 if (edit->transition)
1546 // ok we need to find transition in plugindb
1548 int transition_found = 0;
1549 for(int j = 0; j < plugindb->size(); j++)
1551 PluginServer *server = plugindb->get(j);
1553 !strcasecmp(server->title, edit->transition->title) &&
1554 ((track->data_type == TRACK_AUDIO && server->audio) ||
1555 (track->data_type == TRACK_VIDEO && server->video)) &&
1556 (server->transition))
1557 transition_found = 1;
1560 if (!transition_found)
1563 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1564 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1565 "transition", edit->transition->title,
1567 MainError::show_error(string);
1575 void MWindow::init_shm()
1577 // Fix shared memory
1578 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1580 fprintf(fd, "0x7fffffff");
1585 fd = fopen("/proc/sys/kernel/shmmax", "r");
1587 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1592 fscanf(fd, _LD, &result);
1595 if(result < 0x7fffffff) {
1596 char string[BCTEXTLEN];
1597 sprintf(string, _("MWindow::init_shm: /proc/sys/kernel/shmmax is 0x" _LX ".\n"
1598 "you probably need to be root, or:\n"
1599 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1600 "before trying to start cinelerra.\n"
1601 "It should be at least 0x7fffffff for Cinelerra.\n"), result);
1602 MainError::show_error(string);
1607 void MWindow::create_objects(int want_gui,
1612 const int debug = 0;
1613 if(debug) PRINT_TRACE
1615 // For some reason, init_signals must come after show_splash or the signals won't
1618 if(debug) PRINT_TRACE
1621 if(debug) PRINT_TRACE
1624 if(debug) PRINT_TRACE
1625 init_defaults(defaults, config_path);
1627 init_plugins(this, preferences);
1628 if(debug) PRINT_TRACE
1629 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1630 if(debug) PRINT_TRACE
1632 if(debug) PRINT_TRACE
1635 char string[BCTEXTLEN];
1636 strcpy(string, preferences->plugin_dir);
1637 strcat(string, "/fonts");
1638 BC_Resources::init_fontconfig(string);
1639 if(debug) PRINT_TRACE
1641 // Initialize before too much else is running
1642 // Preferences & theme are required for building MPEG table of contents
1644 // Default project created here
1646 if(debug) PRINT_TRACE
1649 if(debug) PRINT_TRACE
1654 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1656 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1657 if(session->show_vwindow)
1658 get_viewer(1, DEFAULT_VWINDOW);
1659 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1662 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1665 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1668 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1670 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1673 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());
1679 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());
1684 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1685 mainprogress = new MainProgress(this, gui);
1686 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1687 undo = new MainUndo(this);
1689 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1691 plugin_guis = new ArrayList<PluginServer*>;
1692 dead_plugins = new ArrayList<PluginServer*>;
1693 keyframe_threads = new ArrayList<KeyFrameThread*>;
1695 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1698 session->show_vwindow);
1700 // Show all vwindows
1701 // if(session->show_vwindow) {
1702 // for(int j = 0; j < vwindows.size(); j++) {
1703 // VWindow *vwindow = vwindows[j];
1704 // if( !vwindow->is_running() ) continue;
1705 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1708 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1709 // vwindow->gui->lock_window("MWindow::create_objects 1");
1710 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1711 // vwindow->gui->show_window();
1712 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1713 // vwindow->gui->unlock_window();
1718 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1720 if(session->show_cwindow)
1722 cwindow->gui->lock_window("MWindow::create_objects 1");
1723 cwindow->gui->show_window();
1724 cwindow->gui->unlock_window();
1727 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1728 if(session->show_awindow)
1730 awindow->gui->lock_window("MWindow::create_objects 1");
1731 awindow->gui->show_window();
1732 awindow->gui->unlock_window();
1735 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1736 if(session->show_lwindow)
1738 lwindow->gui->lock_window("MWindow::create_objects 1");
1739 lwindow->gui->show_window();
1740 lwindow->gui->unlock_window();
1743 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1745 (int)timer.get_difference(),
1747 if(session->show_gwindow)
1749 gwindow->gui->lock_window("MWindow::create_objects 1");
1750 gwindow->gui->show_window();
1751 gwindow->gui->unlock_window();
1754 if(debug) PRINT_TRACE
1756 gui->lock_window("MWindow::create_objects 1");
1757 gui->mainmenu->load_defaults(defaults);
1758 gui->mainmenu->update_toggles(0);
1759 gui->update_patchbay();
1760 gui->draw_canvas(0, 0);
1761 gui->draw_cursor(1);
1763 gui->raise_window();
1764 gui->unlock_window();
1766 if(debug) PRINT_TRACE
1770 if(preferences->use_tipwindow)
1772 if(debug) PRINT_TRACE
1774 gui->add_keyboard_listener(
1775 (int (BC_WindowBase::*)(BC_WindowBase *))
1776 &MWindowGUI::keyboard_listener);
1780 if(debug) PRINT_TRACE
1782 BC_WindowBase::get_resources()->vframe_shm = 1;
1787 void MWindow::show_splash()
1789 #include "data/heroine_logo11_png.h"
1790 VFrame *frame = new VFramePng(heroine_logo11_png);
1791 BC_DisplayInfo display_info;
1792 splash_window = new SplashGUI(frame,
1793 display_info.get_root_w() / 2 - frame->get_w() / 2,
1794 display_info.get_root_h() / 2 - frame->get_h() / 2);
1795 splash_window->create_objects();
1798 void MWindow::hide_splash()
1801 delete splash_window;
1806 void MWindow::start()
1810 // vwindows[DEFAULT_VWINDOW]->start();
1821 playback_3d->start();
1830 void MWindow::show_vwindow()
1832 int total_running = 0;
1833 session->show_vwindow = 1;
1835 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
1836 // Raise all windows which are visible
1837 for(int j = 0; j < vwindows.size(); j++) {
1838 VWindow *vwindow = vwindows[j];
1839 if( !vwindow->is_running() ) continue;
1840 vwindow->gui->lock_window("MWindow::show_vwindow");
1841 vwindow->gui->show_window(0);
1842 vwindow->gui->raise_window();
1843 vwindow->gui->flush();
1844 vwindow->gui->unlock_window();
1848 // If no windows visible
1851 get_viewer(1, DEFAULT_VWINDOW);
1854 gui->mainmenu->show_vwindow->set_checked(1);
1857 void MWindow::show_awindow()
1859 session->show_awindow = 1;
1860 awindow->gui->lock_window("MWindow::show_awindow");
1861 awindow->gui->show_window();
1862 awindow->gui->raise_window();
1863 awindow->gui->flush();
1864 awindow->gui->unlock_window();
1865 gui->mainmenu->show_awindow->set_checked(1);
1868 char *MWindow::get_cwindow_display()
1870 char *x11_host = screens < 2 || session->window_config == 0 ?
1871 session->a_x11_host : session->b_x11_host;
1872 return *x11_host ? x11_host : 0;
1875 void MWindow::show_cwindow()
1877 session->show_cwindow = 1;
1878 cwindow->show_window();
1879 gui->mainmenu->show_cwindow->set_checked(1);
1882 void MWindow::show_gwindow()
1884 session->show_gwindow = 1;
1886 gwindow->gui->lock_window("MWindow::show_gwindow");
1887 gwindow->gui->show_window();
1888 gwindow->gui->raise_window();
1889 gwindow->gui->flush();
1890 gwindow->gui->unlock_window();
1892 gui->mainmenu->show_gwindow->set_checked(1);
1895 void MWindow::show_lwindow()
1897 session->show_lwindow = 1;
1898 lwindow->gui->lock_window("MWindow::show_lwindow");
1899 lwindow->gui->show_window();
1900 lwindow->gui->raise_window();
1901 lwindow->gui->flush();
1902 lwindow->gui->unlock_window();
1903 gui->mainmenu->show_lwindow->set_checked(1);
1906 int MWindow::tile_windows(int window_config)
1908 int need_reload = 0;
1909 int play_config = window_config==0 ? 0 : 1;
1910 edl->session->playback_config->load_defaults(defaults, play_config);
1911 session->default_window_positions(window_config);
1912 if( screens == 1 ) {
1913 gui->default_positions();
1914 sync_parameters(CHANGE_ALL);
1921 void MWindow::toggle_loop_playback()
1923 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1924 set_loop_boundaries();
1927 gui->draw_overlays(1);
1928 sync_parameters(CHANGE_PARAMS);
1931 //void MWindow::set_titles(int value)
1933 // edl->session->show_titles = value;
1934 // trackmovement(edl->local_session->track_start);
1937 void MWindow::set_screens(int value)
1942 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
1944 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
1945 edl->session->auto_keyframes = value;
1946 gui->mbuttons->edit_panel->keyframe->update(value);
1948 if(lock_mwindow) gui->unlock_window();
1950 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1951 cwindow->gui->edit_panel->keyframe->update(value);
1952 cwindow->gui->flush();
1953 if(lock_cwindow) cwindow->gui->unlock_window();
1956 void MWindow::set_keyframe_type(int mode)
1958 gui->lock_window("MWindow::set_keyframe_type");
1959 edl->local_session->floatauto_type = mode;
1960 gui->mainmenu->update_toggles(0);
1961 gui->unlock_window();
1964 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
1966 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
1967 edl->session->editing_mode = new_editing_mode;
1968 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1969 gui->mbuttons->edit_panel->update();
1970 gui->set_editing_mode(1);
1971 if(lock_mwindow) gui->unlock_window();
1974 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
1975 cwindow->gui->edit_panel->update();
1976 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1977 if(lock_cwindow) cwindow->gui->unlock_window();
1982 void MWindow::sync_parameters(int change_type)
1984 if( in_destructor ) return;
1986 // Sync engines which are playing back
1987 if(cwindow->playback_engine->is_playing_back)
1989 if(change_type == CHANGE_PARAMS)
1991 // TODO: block keyframes until synchronization is done
1992 cwindow->playback_engine->sync_parameters(edl);
1997 int command = cwindow->playback_engine->command->command;
1998 cwindow->playback_engine->que->send_command(STOP,
2002 // Waiting for tracking to finish would make the restart position more
2003 // accurate but it can't lock the window to stop tracking for some reason.
2004 // Not waiting for tracking gives a faster response but restart position is
2005 // only as accurate as the last tracking update.
2006 cwindow->playback_engine->interrupt_playback(0);
2007 cwindow->playback_engine->que->send_command(command,
2016 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2023 void MWindow::age_caches()
2025 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2027 // preferences->cache_size,
2028 // audio_cache->get_memory_usage(1),
2029 // video_cache->get_memory_usage(1),
2030 // frame_cache->get_memory_usage(),
2031 // wave_cache->get_memory_usage(),
2033 frame_cache->age_cache(512);
2034 wave_cache->age_cache(8192);
2036 int64_t memory_usage;
2037 int64_t prev_memory_usage = 0;
2039 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2040 while( !result && prev_memory_usage !=
2041 (memory_usage=video_cache->get_memory_usage(1)) &&
2042 memory_usage > video_size ) {
2043 video_cache->delete_oldest();
2044 prev_memory_usage = memory_usage;
2047 prev_memory_usage = 0;
2049 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2050 while( !result && prev_memory_usage !=
2051 (memory_usage=audio_cache->get_memory_usage(1)) &&
2052 memory_usage > audio_size ) {
2053 audio_cache->delete_oldest();
2054 prev_memory_usage = memory_usage;
2058 void MWindow::reset_android_remote()
2060 gui->use_android_remote(preferences->android_remote);
2064 void MWindow::show_keyframe_gui(Plugin *plugin)
2066 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2067 // Find existing thread
2068 for(int i = 0; i < keyframe_threads->size(); i++)
2070 if(keyframe_threads->get(i)->plugin == plugin)
2072 keyframe_threads->get(i)->start_window(plugin, 0);
2073 keyframe_gui_lock->unlock();
2078 // Find unused thread
2079 for(int i = 0; i < keyframe_threads->size(); i++)
2081 if(!keyframe_threads->get(i)->plugin)
2083 keyframe_threads->get(i)->start_window(plugin, 0);
2084 keyframe_gui_lock->unlock();
2089 // Create new thread
2090 KeyFrameThread *thread = new KeyFrameThread(this);
2091 keyframe_threads->append(thread);
2092 thread->start_window(plugin, 0);
2094 keyframe_gui_lock->unlock();
2101 void MWindow::show_plugin(Plugin *plugin)
2106 // Remove previously deleted plugin GUIs
2107 dead_plugin_lock->lock("MWindow::delete_plugin");
2108 for(int i = 0; i < dead_plugins->size(); i++)
2110 delete dead_plugins->get(i);
2112 dead_plugins->remove_all();
2113 dead_plugin_lock->unlock();
2115 //printf("MWindow::show_plugin %d\n", __LINE__);
2119 plugin_gui_lock->lock("MWindow::show_plugin");
2120 for(int i = 0; i < plugin_guis->total; i++)
2122 // Pointer comparison
2123 if(plugin_guis->get(i)->plugin == plugin)
2125 plugin_guis->get(i)->raise_window();
2132 //printf("MWindow::show_plugin 1\n");
2137 printf("MWindow::show_plugin track not defined.\n");
2139 PluginServer *server = scan_plugindb(plugin->title,
2140 plugin->track->data_type);
2142 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2143 if(server && server->uses_gui)
2145 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
2146 // Needs mwindow to do GUI
2147 gui->set_mwindow(this);
2148 gui->open_plugin(0, preferences, edl, plugin);
2153 plugin_gui_lock->unlock();
2154 //printf("MWindow::show_plugin %d\n", __LINE__);
2157 //printf("MWindow::show_plugin 2\n");
2160 void MWindow::hide_plugin(Plugin *plugin, int lock)
2163 // Update the toggle
2164 gui->lock_window("MWindow::hide_plugin");
2165 gui->update(0, 1, 0, 0, 0, 0, 0);
2166 gui->unlock_window();
2168 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2169 for(int i = 0; i < plugin_guis->total; i++)
2171 if(plugin_guis->get(i)->plugin == plugin)
2173 PluginServer *ptr = plugin_guis->get(i);
2174 plugin_guis->remove(ptr);
2175 if(lock) plugin_gui_lock->unlock();
2176 // Last command executed in client side close
2177 // Schedule for deletion
2184 if(lock) plugin_gui_lock->unlock();
2187 void MWindow::delete_plugin(PluginServer *plugin)
2189 dead_plugin_lock->lock("MWindow::delete_plugin");
2190 dead_plugins->append(plugin);
2191 dead_plugin_lock->unlock();
2194 void MWindow::hide_plugins()
2196 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2197 while(plugin_guis->size())
2199 PluginServer *ptr = plugin_guis->get(0);
2200 plugin_guis->remove(ptr);
2201 plugin_gui_lock->unlock();
2202 // Last command executed in client side close
2203 // Schedule for deletion
2206 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2208 plugin_gui_lock->unlock();
2210 hide_keyframe_guis();
2213 void MWindow::hide_keyframe_guis()
2215 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2216 for(int i = 0; i < keyframe_threads->size(); i++)
2218 keyframe_threads->get(i)->close_window();
2220 keyframe_gui_lock->unlock();
2223 void MWindow::hide_keyframe_gui(Plugin *plugin)
2225 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2226 for(int i = 0; i < keyframe_threads->size(); i++)
2228 if(keyframe_threads->get(i)->plugin == plugin)
2230 keyframe_threads->get(i)->close_window();
2234 keyframe_gui_lock->unlock();
2237 void MWindow::update_keyframe_guis()
2239 // Send new configuration to keyframe GUI's
2240 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2241 for(int i = 0; i < keyframe_threads->size(); i++)
2243 KeyFrameThread *ptr = keyframe_threads->get(i);
2244 if(edl->tracks->plugin_exists(ptr->plugin))
2248 ptr->close_window();
2251 keyframe_gui_lock->unlock();
2254 void MWindow::update_plugin_guis(int do_keyframe_guis)
2256 // Send new configuration to plugin GUI's
2257 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2259 for(int i = 0; i < plugin_guis->size(); i++)
2261 PluginServer *ptr = plugin_guis->get(i);
2262 if(edl->tracks->plugin_exists(ptr->plugin))
2266 // Schedule for deletion if no plugin
2267 plugin_guis->remove_number(i);
2276 // Change plugin variable if not visible
2277 Track *track = edl->tracks->first;
2280 for(int i = 0; i < track->plugin_set.size(); i++)
2282 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2286 for(int i = 0; i < plugin_guis->size(); i++)
2288 PluginServer *server = plugin_guis->get(i);
2289 if(server->plugin == plugin)
2296 if(!got_it) plugin->show = 0;
2298 plugin = (Plugin*)plugin->next;
2302 track = track->next;
2305 plugin_gui_lock->unlock();
2308 if(do_keyframe_guis) update_keyframe_guis();
2311 int MWindow::plugin_gui_open(Plugin *plugin)
2314 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2315 for(int i = 0; i < plugin_guis->total; i++)
2317 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2323 plugin_gui_lock->unlock();
2327 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2329 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2330 for(int i = 0; i < plugin_guis->total; i++)
2332 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2334 plugin_guis->get(i)->render_gui(data);
2338 plugin_gui_lock->unlock();
2341 void MWindow::render_plugin_gui(void *data, int size, 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->get(i)->plugin->identical_location(plugin))
2348 plugin_guis->get(i)->render_gui(data, size);
2352 plugin_gui_lock->unlock();
2356 void MWindow::update_plugin_states()
2358 plugin_gui_lock->lock("MWindow::update_plugin_states");
2359 for(int i = 0; i < plugin_guis->total; i++)
2363 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2364 PluginServer *src_plugingui = plugin_guis->get(i);
2366 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2367 for(Track *track = edl->tracks->first;
2369 track = track->next)
2372 j < track->plugin_set.total && !result;
2375 PluginSet *plugin_set = track->plugin_set[j];
2376 for(Plugin *plugin = (Plugin*)plugin_set->first;
2378 plugin = (Plugin*)plugin->next)
2380 if(plugin == src_plugin &&
2381 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2387 // Doesn't exist anymore
2390 hide_plugin(src_plugin, 0);
2394 plugin_gui_lock->unlock();
2398 void MWindow::update_plugin_titles()
2400 for(int i = 0; i < plugin_guis->total; i++)
2402 plugin_guis->get(i)->update_title();
2406 int MWindow::asset_to_edl(EDL *new_edl,
2408 RecordLabels *labels)
2410 const int debug = 0;
2411 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2414 // Keep frame rate, sample rate, and output size unchanged.
2415 // These parameters would revert the project if VWindow displayed an asset
2416 // of different size than the project.
2417 if(new_asset->video_data)
2419 new_edl->session->video_tracks = new_asset->layers;
2422 new_edl->session->video_tracks = 0;
2424 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2430 if(new_asset->audio_data)
2432 new_edl->session->audio_tracks = new_asset->channels;
2435 new_edl->session->audio_tracks = 0;
2436 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2438 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2439 new_edl->create_default_tracks();
2440 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2441 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2445 //printf("MWindow::asset_to_edl 3\n");
2446 new_edl->insert_asset(new_asset,
2451 //printf("MWindow::asset_to_edl 3\n");
2452 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2458 char string[BCTEXTLEN];
2460 fs.extract_name(string, new_asset->path);
2461 //printf("MWindow::asset_to_edl 3\n");
2463 strcpy(new_edl->local_session->clip_title, string);
2464 //printf("MWindow::asset_to_edl 4 %s\n", string);
2465 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2470 int MWindow::edl_to_nested(EDL *new_edl,
2474 // Keep frame rate, sample rate, and output size unchanged.
2475 // These parameters would revert the project if VWindow displayed an asset
2476 // of different size than the project.
2480 // Nest all video & audio outputs
2481 new_edl->session->video_tracks = 1;
2482 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2483 new_edl->create_default_tracks();
2487 new_edl->insert_asset(0,
2493 char string[BCTEXTLEN];
2495 fs.extract_name(string, nested_edl->path);
2496 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2498 strcpy(new_edl->local_session->clip_title, string);
2503 // Reset everything after a load.
2504 void MWindow::update_project(int load_mode)
2506 const int debug = 0;
2508 if(debug) PRINT_TRACE
2510 edl->tracks->update_y_pixels(theme);
2512 if(debug) PRINT_TRACE
2514 if(load_mode == LOADMODE_REPLACE ||
2515 load_mode == LOADMODE_REPLACE_CONCATENATE)
2520 gui->update(1, 1, 1, 1, 1, 1, 1);
2521 if(debug) PRINT_TRACE
2522 gui->unlock_window();
2524 cwindow->gui->lock_window("MWindow::update_project 1");
2525 cwindow->update(0, 0, 1, 1, 1);
2526 cwindow->gui->unlock_window();
2528 if(debug) PRINT_TRACE
2530 // Close all the vwindows
2531 if(load_mode == LOADMODE_REPLACE ||
2532 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2533 if(debug) PRINT_TRACE
2534 int first_vwindow = 0;
2535 if(session->show_vwindow) first_vwindow = 1;
2536 // Change visible windows to no source
2537 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2538 VWindow *vwindow = vwindows[i];
2539 if( !vwindow->is_running() ) continue;
2540 vwindow->change_source(-1);
2543 // Close remaining windows
2544 for(int i = first_vwindow; i < vwindows.size(); i++) {
2545 VWindow *vwindow = vwindows[i];
2546 if( !vwindow->is_running() ) continue;
2547 vwindow->close_window();
2549 if(debug) PRINT_TRACE
2551 else if(vwindows.size()) {
2552 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2553 if( vwindow->is_running() ) {
2554 vwindow->gui->lock_window("MWindow::update_project");
2556 vwindow->gui->unlock_window();
2560 if(debug) PRINT_TRACE
2561 cwindow->gui->lock_window("MWindow::update_project 2");
2562 cwindow->gui->timebar->update(0);
2563 cwindow->gui->unlock_window();
2565 if(debug) PRINT_TRACE
2566 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2571 if(debug) PRINT_TRACE
2573 awindow->gui->lock_window("MWindow::update_project");
2574 awindow->gui->update_assets();
2575 awindow->gui->flush();
2576 awindow->gui->unlock_window();
2578 if(debug) PRINT_TRACE
2580 gui->lock_window("MWindow::update_project");
2582 if(debug) PRINT_TRACE
2585 void MWindow::remove_indexfile(Indexable *indexable)
2587 if( !indexable->is_asset ) return;
2588 Asset *asset = (Asset *)indexable;
2590 IndexFile::delete_index(preferences, asset, ".toc");
2591 IndexFile::delete_index(preferences, asset, ".idx");
2592 IndexFile::delete_index(preferences, asset, ".mkr");
2595 void MWindow::rebuild_indices()
2597 for(int i = 0; i < session->drag_assets->total; i++)
2599 Indexable *indexable = session->drag_assets->get(i);
2600 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2601 remove_indexfile(indexable);
2602 // Schedule index build
2603 IndexState *index_state = indexable->index_state;
2604 index_state->index_status = INDEX_NOTTESTED;
2605 if( indexable->is_asset ) {
2606 Asset *asset = (Asset *)indexable;
2607 if( asset->format != FILE_PCM )
2608 asset->reset_audio();
2609 asset->reset_video();
2611 mainindexes->add_next_asset(0, indexable);
2613 mainindexes->start_build();
2617 void MWindow::save_backup()
2620 edl->set_path(session->filename);
2621 edl->save_xml(&file,
2625 file.terminate_string();
2626 char path[BCTEXTLEN];
2628 strcpy(path, BACKUP_PATH);
2629 fs.complete_path(path);
2631 if(file.write_to_file(path))
2634 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2635 gui->show_message(string2);
2639 void MWindow::load_backup()
2641 ArrayList<char*> path_list;
2642 path_list.set_array_delete();
2644 char string[BCTEXTLEN];
2645 strcpy(string, BACKUP_PATH);
2647 fs.complete_path(string);
2649 path_list.append(out_path = new char[strlen(string) + 1]);
2650 strcpy(out_path, string);
2652 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2653 edl->local_session->clip_title[0] = 0;
2654 // This is unique to backups since the path of the backup is different than the
2655 // path of the project.
2656 set_filename(edl->path);
2657 path_list.remove_all_objects();
2661 static inline int gcd(int m, int n)
2664 if( m < n ) { r = m; m = n; n = r; }
2665 while( (r = m % n) != 0 ) { m = n; n = r; }
2669 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2672 if(!width || !height) return 1;
2673 double ar = (double)width / height;
2674 // square-ish pixels
2675 if( EQUIV(ar, 1.0000) ) return 0;
2676 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2677 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2678 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2679 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2680 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2681 int ww = width, hh = height;
2682 // numerator, denominator must be under mx
2683 int mx = 255, n = gcd(ww, hh);
2684 if( n > 1 ) { ww /= n; hh /= n; }
2685 // search near height in case extra/missing lines
2686 if( ww >= mx || hh >= mx ) {
2687 double err = height; // +/- 2 percent height
2688 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2689 int iw = width, ih = height+i;
2690 if( (n=gcd(iw, ih)) > 1 ) {
2691 int u = iw/n; if( u >= mx ) continue;
2692 int v = ih/n; if( v >= mx ) continue;
2693 double r = (double) u/v, er = fabs(ar-r);
2694 if( er >= err ) continue;
2695 err = er; ww = u; hh = v;
2704 void MWindow::reset_caches()
2706 frame_cache->remove_all();
2707 wave_cache->remove_all();
2708 audio_cache->remove_all();
2709 video_cache->remove_all();
2710 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2711 cwindow->playback_engine->audio_cache->remove_all();
2712 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2713 cwindow->playback_engine->video_cache->remove_all();
2715 for(int i = 0; i < vwindows.size(); i++) {
2716 VWindow *vwindow = vwindows[i];
2717 if( !vwindow->is_running() ) continue;
2718 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2719 vwindow->playback_engine->audio_cache->remove_all();
2720 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2721 vwindow->playback_engine->video_cache->remove_all();
2725 void MWindow::remove_asset_from_caches(Asset *asset)
2727 frame_cache->remove_asset(asset);
2728 wave_cache->remove_asset(asset);
2729 audio_cache->delete_entry(asset);
2730 video_cache->delete_entry(asset);
2731 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2732 cwindow->playback_engine->audio_cache->delete_entry(asset);
2733 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2734 cwindow->playback_engine->video_cache->delete_entry(asset);
2735 for(int i = 0; i < vwindows.size(); i++) {
2736 VWindow *vwindow = vwindows[i];
2737 if( !vwindow->is_running() ) continue;
2738 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2739 vwindow->playback_engine->audio_cache->delete_entry(asset);
2740 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2741 vwindow->playback_engine->video_cache->delete_entry(asset);
2746 void MWindow::remove_assets_from_project(int push_undo, int redraw,
2747 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
2749 for(int i = 0; i < session->drag_assets->total; i++) {
2750 Indexable *indexable = session->drag_assets->get(i);
2751 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
2754 // Remove from VWindow.
2755 for(int i = 0; i < session->drag_clips->total; i++) {
2756 for(int j = 0; j < vwindows.size(); j++) {
2757 VWindow *vwindow = vwindows[j];
2758 if( !vwindow->is_running() ) continue;
2759 if(session->drag_clips->get(i) == vwindow->get_edl()) {
2760 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
2761 vwindow->delete_source(1, 1);
2762 vwindow->gui->unlock_window();
2767 for(int i = 0; i < session->drag_assets->size(); i++) {
2768 for(int j = 0; j < vwindows.size(); j++) {
2769 VWindow *vwindow = vwindows[j];
2770 if( !vwindow->is_running() ) continue;
2771 if(session->drag_assets->get(i) == vwindow->get_source()) {
2772 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
2773 vwindow->delete_source(1, 1);
2774 vwindow->gui->unlock_window();
2779 for(int i = 0; i < session->drag_assets->size(); i++) {
2780 Indexable *indexable = session->drag_assets->get(i);
2781 remove_indexfile(indexable);
2784 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2785 if(push_undo) undo->update_undo_before();
2786 if(drag_assets) edl->remove_from_project(drag_assets);
2787 if(drag_clips) edl->remove_from_project(session->drag_clips);
2788 if(redraw) save_backup();
2789 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
2794 gui->lock_window("MWindow::remove_assets_from_project 3");
2802 gui->unlock_window();
2804 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
2805 awindow->gui->update_assets();
2806 awindow->gui->flush();
2807 awindow->gui->unlock_window();
2809 // Removes from playback here
2810 sync_parameters(CHANGE_ALL);
2814 void MWindow::remove_assets_from_disk()
2817 for(int i = 0; i < session->drag_assets->total; i++)
2819 remove(session->drag_assets->get(i)->path);
2822 remove_assets_from_project(1,
2824 session->drag_assets,
2825 session->drag_clips);
2828 void MWindow::dump_plugins(FILE *fp)
2830 if( !plugindb ) return;
2831 for(int i = 0; i < plugindb->total; i++)
2833 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
2834 " synth=%d transition=%d theme=%d %s\n",
2835 plugindb->get(i)->plugin_type,
2836 plugindb->get(i)->audio,
2837 plugindb->get(i)->video,
2838 plugindb->get(i)->realtime,
2839 plugindb->get(i)->multichannel,
2840 plugindb->get(i)->get_synthesis(),
2841 plugindb->get(i)->transition,
2842 plugindb->get(i)->theme,
2843 plugindb->get(i)->title);
2847 void MWindow::dump_edl(FILE *fp)
2853 void MWindow::dump_undo(FILE *fp)
2859 void MWindow::dump_exe(FILE *fp)
2861 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
2862 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
2863 int len = readlink(proc_path, exe_path, sizeof(exe_path));
2864 if( len < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
2867 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
2868 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
2869 int fd = open(exe_path,O_RDONLY);
2870 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
2871 uint8_t buf[65536]; SHA1 sha1;
2872 while( (len=read(fd,buf,sizeof(buf))) > 0 ) {
2873 sha1.addBytes(buf, len);
2876 fprintf(fp, "SHA1: ");
2877 uint8_t digest[20]; sha1.computeHash(digest);
2878 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
2883 void MWindow::trap_hook(FILE *fp, void *vp)
2885 MWindow *mwindow = (MWindow *)vp;
2886 fprintf(fp, "\nEXE:\n");
2887 mwindow->dump_exe(fp);
2888 fprintf(fp, "\nPLUGINS:\n");
2889 mwindow->dump_plugins(fp);
2890 fprintf(fp, "\nEDL:\n");
2891 mwindow->dump_edl(fp);
2892 fprintf(fp, "\nUNDO:\n");
2893 mwindow->dump_undo(fp);
2901 int MWindow::save_defaults()
2903 gui->save_defaults(defaults);
2904 edl->save_defaults(defaults);
2905 session->save_defaults(defaults);
2906 preferences->save_defaults(defaults);
2908 for(int i = 0; i < plugin_guis->total; i++)
2910 // Pointer comparison
2911 plugin_guis->get(i)->save_defaults();
2913 awindow->save_defaults(defaults);
2919 int MWindow::run_script(FileXML *script)
2921 int result = 0, result2 = 0;
2922 while(!result && !result2)
2924 result = script->read_tag();
2927 if(script->tag.title_is("new_project"))
2929 // Run new in immediate mode.
2930 // gui->mainmenu->new_project->run_script(script);
2933 if(script->tag.title_is("record"))
2935 // Run record as a thread. It is a terminal command.
2937 // Will read the complete scipt file without letting record read it if not
2943 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
2950 // ================================= synchronization
2953 int MWindow::interrupt_indexes()
2955 mainindexes->interrupt_build();
2961 void MWindow::next_time_format()
2963 switch(edl->session->time_format)
2965 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
2966 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
2967 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2968 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
2969 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
2970 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
2971 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
2974 time_format_common();
2977 void MWindow::prev_time_format()
2979 switch(edl->session->time_format)
2981 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
2982 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
2983 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
2984 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2985 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
2986 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
2987 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
2990 time_format_common();
2993 void MWindow::time_format_common()
2995 gui->lock_window("MWindow::next_time_format");
2996 gui->redraw_time_dependancies();
2999 char string[BCTEXTLEN], string2[BCTEXTLEN];
3000 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3001 gui->show_message(string);
3003 gui->unlock_window();
3007 int MWindow::set_filename(const char *filename)
3009 if( filename != session->filename )
3010 strcpy(session->filename, filename);
3011 if( filename != edl->path )
3012 strcpy(edl->path, filename);
3016 if(filename[0] == 0)
3018 gui->set_title(PROGRAM_NAME);
3023 char string[BCTEXTLEN], string2[BCTEXTLEN];
3024 dir.extract_name(string, filename);
3025 sprintf(string2, PROGRAM_NAME ": %s", string);
3026 gui->set_title(string2);
3039 int MWindow::set_loop_boundaries()
3041 double start = edl->local_session->get_selectionstart();
3042 double end = edl->local_session->get_selectionend();
3050 if(edl->tracks->total_length())
3053 end = edl->tracks->total_length();
3060 if(edl->local_session->loop_playback && start != end)
3062 edl->local_session->loop_start = start;
3063 edl->local_session->loop_end = end;
3074 int MWindow::reset_meters()
3076 cwindow->gui->lock_window("MWindow::reset_meters 1");
3077 cwindow->gui->meters->reset_meters();
3078 cwindow->gui->unlock_window();
3080 for(int j = 0; j < vwindows.size(); j++) {
3081 VWindow *vwindow = vwindows[j];
3082 if( !vwindow->is_running() ) continue;
3083 vwindow->gui->lock_window("MWindow::reset_meters 2");
3084 vwindow->gui->meters->reset_meters();
3085 vwindow->gui->unlock_window();
3088 lwindow->gui->lock_window("MWindow::reset_meters 3");
3089 lwindow->gui->panel->reset_meters();
3090 lwindow->gui->unlock_window();
3092 gui->lock_window("MWindow::reset_meters 4");
3093 gui->reset_meters();
3094 gui->unlock_window();
3099 void MWindow::resync_guis()
3103 gui->lock_window("MWindow::resync_guis");
3104 gui->update(1, 1, 1, 1, 1, 1, 0);
3105 gui->unlock_window();
3107 cwindow->gui->lock_window("MWindow::resync_guis");
3108 cwindow->gui->resize_event(cwindow->gui->get_w(),
3109 cwindow->gui->get_h());
3110 int channels = edl->session->audio_channels;
3111 cwindow->gui->meters->set_meters(channels, 1);
3112 cwindow->gui->flush();
3113 cwindow->gui->unlock_window();
3115 for(int i = 0; i < vwindows.size(); i++) {
3116 VWindow *vwindow = vwindows[i];
3117 if( !vwindow->is_running() ) continue;
3118 vwindow->gui->lock_window("MWindow::resync_guis");
3119 vwindow->gui->resize_event(vwindow->gui->get_w(),
3120 vwindow->gui->get_h());
3121 vwindow->gui->meters->set_meters(channels, 1);
3122 vwindow->gui->flush();
3123 vwindow->gui->unlock_window();
3126 lwindow->gui->lock_window("MWindow::resync_guis");
3127 lwindow->gui->panel->set_meters(channels, 1);
3128 lwindow->gui->flush();
3129 lwindow->gui->unlock_window();
3132 if(((edl->session->output_w % 4) ||
3133 (edl->session->output_h % 4)) &&
3134 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3136 MainError::show_error(
3137 _("This project's dimensions are not multiples of 4 so\n"
3138 "it can't be rendered by OpenGL."));
3143 sync_parameters(CHANGE_ALL);
3146 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3148 File *file = new File;
3149 EDLSession *session = edl->session;
3150 double old_framerate = session->frame_rate;
3151 double old_samplerate = session->sample_rate;
3152 int result = file->open_file(preferences, asset, 1, 0);
3153 if( !result && delete_tracks > 0 )
3154 undo->update_undo_before();
3155 if( !result && asset->get_video_layers() > 0 ) {
3156 // try to get asset up to date, may fail
3157 file->select_video_stream(asset, vstream);
3158 // either way use what was/is there.
3159 double framerate = asset->get_frame_rate();
3160 int width = asset->get_w();
3161 int height = asset->get_h();
3162 // must be multiple of 4 for opengl
3163 width = (width+3) & ~3; height = (height+3) & ~3;
3164 int driver = session->playback_config->vconfig->driver;
3165 int color_model = file->get_best_colormodel(asset, driver);
3166 color_model = BC_CModels::is_yuv(color_model) ?
3167 BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3168 BC_CModels::is_float(color_model) ?
3169 BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3170 BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3171 session->color_model = color_model;
3172 session->output_w = width;
3173 session->output_h = height;
3174 session->frame_rate = framerate;
3175 // not, asset->actual_width/actual_height
3176 asset->width = session->output_w;
3177 asset->height = session->output_h;
3178 asset->frame_rate = session->frame_rate;
3179 create_aspect_ratio(session->aspect_w, session->aspect_h,
3180 session->output_w, session->output_h);
3181 Track *track = edl->tracks->first;
3182 for( Track *next_track=0; track; track=next_track ) {
3183 next_track = track->next;
3184 if( track->data_type != TRACK_VIDEO ) continue;
3185 if( delete_tracks ) {
3186 Edit *edit = track->edits->first;
3187 for( Edit *next_edit=0; edit; edit=next_edit ) {
3188 next_edit = edit->next;
3189 if( edit->channel != vstream ||
3190 !edit->asset || !edit->asset->is_asset ||
3191 *asset != *edit->asset )
3195 if( track->edits->first ) {
3196 track->track_w = edl->session->output_w;
3197 track->track_h = edl->session->output_h;
3199 else if( delete_tracks )
3200 edl->tracks->delete_track(track);
3202 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3204 if( !result && asset->channels > 0 ) {
3205 session->sample_rate = asset->get_sample_rate();
3206 int64_t channel_mask = 0;
3207 int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
3208 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3209 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3211 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3212 if( channels > 6 ) channels = 6;
3213 session->audio_tracks = session->audio_channels = channels;
3214 switch( channels ) {
3216 session->achannel_positions[0] = 90;
3217 session->achannel_positions[1] = 150;
3218 session->achannel_positions[2] = 30;
3219 session->achannel_positions[3] = 210;
3220 session->achannel_positions[4] = 330;
3221 session->achannel_positions[5] = 270;
3224 session->achannel_positions[0] = 180;
3225 session->achannel_positions[1] = 0;
3228 remap_audio(MWindow::AUDIO_1_TO_1);
3230 if( delete_tracks ) {
3231 Track *track = edl->tracks->first;
3232 for( Track *next_track=0; track; track=next_track ) {
3233 next_track = track->next;
3234 if( track->data_type != TRACK_AUDIO ) continue;
3235 Edit *edit = track->edits->first;
3236 for( Edit *next_edit=0; edit; edit=next_edit ) {
3237 next_edit = edit->next;
3238 if( !((1<<edit->channel) & channel_mask) ||
3239 !edit->asset || !edit->asset->is_asset ||
3240 *asset != *edit->asset )
3243 if( !track->edits->first )
3244 edl->tracks->delete_track(track);
3248 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3251 if( !result && delete_tracks > 0 ) {
3253 undo->update_undo_after(_("select asset"), LOAD_ALL);
3259 int MWindow::select_asset(int vtrack, int delete_tracks)
3261 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3262 if( !track ) return 1;
3263 Edit *edit = track->edits->first;
3264 if( !edit ) return 1;
3265 Asset *asset = edit->asset;
3266 if( !asset || !asset->is_asset ) return 1;
3267 return select_asset(asset, edit->channel, -1, delete_tracks);
3270 void MWindow::dump_plugindb(FILE *fp)
3272 if( !plugindb ) return;
3273 for(int i = 0; i < plugindb->total; i++)
3274 plugindb->get(i)->dump(fp);