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();
283 dead_plugins->remove_all();
285 keyframe_threads->remove_all_objects();
286 if( !edl->Garbage::remove_user() ) edl = 0;
287 colormodels.remove_all_objects();
289 delete render; render = 0;
290 delete awindow; awindow = 0;
291 delete lwindow; lwindow = 0;
292 delete twindow; twindow = 0;
293 delete wwindow; wwindow = 0;
294 delete gwindow; gwindow = 0;
295 // must be last or nouveau chokes
296 delete cwindow; cwindow = 0;
297 //delete file_server; file_server = 0; // reusable
298 delete mainindexes; mainindexes = 0;
299 delete mainprogress; mainprogress = 0;
300 delete audio_cache; audio_cache = 0; // delete the cache after the assets
301 delete video_cache; video_cache = 0; // delete the cache after the assets
302 delete frame_cache; frame_cache = 0;
303 delete wave_cache; wave_cache = 0;
304 delete plugin_guis; plugin_guis = 0;
305 delete dead_plugins; dead_plugins = 0;
306 delete keyframe_threads; keyframe_threads = 0;
307 delete undo; undo = 0;
308 delete preferences; preferences = 0;
309 delete session; session = 0;
310 delete defaults; defaults = 0;
311 delete assets; assets = 0;
312 delete splash_window; splash_window = 0;
313 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 = new PluginServer(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();
454 server->delete_this();
457 if( result != PLUGINSERVER_IS_LAD ) continue;
460 PluginServer *server = new PluginServer(mwindow, plugin_path, PLUGIN_TYPE_LADSPA);
461 server->set_lad_index(lad_index++);
462 result = server->open_plugin(1, preferences, 0, 0);
464 server->write_table(fp, PLUGIN_LADSPA_ID);
465 server->close_plugin();
466 server->delete_this();
471 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
474 if( !plugindb ) plugindb = new ArrayList<PluginServer*>;
475 char index_path[BCTEXTLEN];
476 sprintf(index_path, "%s/%s", preferences->plugin_dir, PLUGIN_FILE);
477 if( !load_plugin_index(mwindow, index_path) ) return 1;
478 FILE *fp = fopen(index_path,"w");
480 fprintf(stderr,_("MWindow::init_plugins: "
481 "can't create plugin index: %s\n"), index_path);
484 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
485 char *plug_path = FileSystem::basepath(preferences->plugin_dir);
486 int dir_id = PLUGIN_IDS;
487 init_plugin_index(mwindow, preferences, fp, plug_path, ".", dir_id);
488 init_ffmpeg_index(mwindow, preferences, fp);
491 return load_plugin_index(mwindow, index_path);
494 void MWindow::delete_plugins()
496 plugindb->remove_all_objects();
501 void MWindow::search_plugindb(int do_audio,
506 ArrayList<PluginServer*> &results)
509 for(int i = 0; i < MWindow::plugindb->total; i++)
511 PluginServer *current = MWindow::plugindb->get(i);
513 if(current->audio == do_audio &&
514 current->video == do_video &&
515 (current->realtime == is_realtime || is_realtime < 0) &&
516 current->transition == is_transition &&
517 current->theme == is_theme)
518 results.append(current);
521 // Alphabetize list by title
527 for(int i = 0; i < results.total - 1; i++)
529 PluginServer *value1 = results[i];
530 PluginServer *value2 = results[i + 1];
531 if(strcmp(_(value1->title), _(value2->title)) > 0)
535 results[i + 1] = value1;
541 PluginServer* MWindow::scan_plugindb(char *title,
546 // printf("MWindow::scan_plugindb data_type < 0\n");
550 for(int i = 0; i < plugindb->total; i++)
552 PluginServer *server = plugindb->get(i);
554 !strcasecmp(server->title, title) &&
556 (data_type == TRACK_AUDIO && server->audio) ||
557 (data_type == TRACK_VIDEO && server->video)))
558 return plugindb->get(i);
563 int MWindow::plugin_exists(char *plugin_path)
565 for( int i=0; i<plugindb->total; ++i ) {
566 PluginServer *server = plugindb->get(i);
567 if( !strcmp(plugin_path, server->get_path()) ) return 1;
572 void MWindow::init_preferences()
574 preferences = new Preferences;
575 preferences->load_defaults(defaults);
576 session = new MainSession(this);
577 session->load_defaults(defaults);
578 // set x11_host, screens, window_config
579 screens = session->set_default_x11_host();
580 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
581 BC_Signals::set_trap_hook(trap_hook, this);
582 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
583 BC_Signals::set_catch_intr(preferences->trap_sigintr);
586 void MWindow::clean_indexes()
591 int oldest_item = -1;
593 char string[BCTEXTLEN];
594 char string2[BCTEXTLEN];
596 // Delete extra indexes
597 fs.set_filter("*.idx");
598 fs.complete_path(preferences->index_directory);
599 fs.update(preferences->index_directory);
600 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
602 // Eliminate directories
607 for(int i = 0; i < fs.dir_list.total && !result; i++)
609 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
610 if(fs.is_dir(string))
612 delete fs.dir_list[i];
613 fs.dir_list.remove_number(i);
618 total_excess = fs.dir_list.total - preferences->index_count;
620 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
621 while(total_excess > 0)
624 for(int i = 0; i < fs.dir_list.total; i++)
626 fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
628 if(i == 0 || fs.get_date(string) <= oldest)
630 oldest = fs.get_date(string);
638 fs.join_names(string,
639 preferences->index_directory,
640 fs.dir_list[oldest_item]->name);
641 //printf("MWindow::clean_indexes 1 %s\n", string);
643 perror("delete_indexes");
644 delete fs.dir_list[oldest_item];
645 fs.dir_list.remove_number(oldest_item);
647 // Remove table of contents if it exists
648 strcpy(string2, string);
649 char *ptr = strrchr(string2, '.');
652 //printf("MWindow::clean_indexes 2 %s\n", string2);
653 sprintf(ptr, ".toc");
655 sprintf(ptr, ".mkr");
664 void MWindow::init_awindow()
666 awindow = new AWindow(this);
667 awindow->create_objects();
670 void MWindow::init_gwindow()
672 gwindow = new GWindow(this);
673 gwindow->create_objects();
676 void MWindow::init_tipwindow()
679 twindow = new TipWindow(this);
683 void MWindow::show_warning(int *do_warning, const char *text)
685 if( do_warning && !*do_warning ) return;
687 wwindow = new WWindow(this);
688 wwindow->show_warning(do_warning, text);
691 void MWindow::init_theme()
696 // Replace blond theme with SUV since it doesn't work
697 if(!strcasecmp(preferences->theme, "Blond"))
698 strcpy(preferences->theme, DEFAULT_THEME);
700 PluginServer *theme_plugin = 0;
701 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
702 if( plugindb->get(i)->theme &&
703 !strcasecmp(preferences->theme, plugindb->get(i)->title) )
704 theme_plugin = plugindb->get(i);
708 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
711 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
712 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
714 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
715 if( plugindb->get(i)->theme &&
716 !strcasecmp(DEFAULT_THEME, plugindb->get(i)->title) )
717 theme_plugin = plugindb->get(i);
722 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
726 PluginServer plugin = *theme_plugin;
727 if( plugin.open_plugin(0, preferences, 0, 0) ) {
728 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
729 theme_plugin->title);
733 theme = plugin.new_theme();
734 theme->mwindow = this;
735 strcpy(theme->path, plugin.path);
736 plugin.close_plugin();
738 // Load default images & settings
739 theme->Theme::initialize();
740 // Load user images & settings
742 // Create menus with user colors
743 theme->build_menus();
748 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
751 void MWindow::init_3d()
753 playback_3d = new Playback3D(this);
754 playback_3d->create_objects();
757 void MWindow::init_edl()
760 edl->create_objects();
761 edl->load_defaults(defaults);
762 edl->create_default_tracks();
763 edl->tracks->update_y_pixels(theme);
766 void MWindow::init_compositor()
768 cwindow = new CWindow(this);
769 cwindow->create_objects();
772 void MWindow::init_levelwindow()
774 lwindow = new LevelWindow(this);
775 lwindow->create_objects();
778 VWindow *MWindow::get_viewer(int start_it, int idx)
780 vwindows_lock->lock("MWindow::get_viewer");
781 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows[idx] : 0;
782 if( !vwindow ) idx = vwindows.size();
783 while( !vwindow && --idx >= 0 ) {
784 VWindow *vwin = vwindows[idx];
785 if( !vwin->is_running() || !vwin->get_edl() )
789 vwindow = new VWindow(this);
790 vwindow->load_defaults();
791 vwindow->create_objects();
792 vwindows.append(vwindow);
794 vwindows_lock->unlock();
795 if( start_it ) vwindow->start();
799 void MWindow::init_cache()
801 audio_cache = new CICache(preferences);
802 video_cache = new CICache(preferences);
803 frame_cache = new FrameCache;
804 wave_cache = new WaveCache;
807 void MWindow::init_channeldb()
809 channeldb_buz->load("channeldb_buz");
810 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
813 void MWindow::init_menus()
815 char string[BCTEXTLEN];
816 BC_CModels::to_text(string, BC_RGB888);
817 colormodels.append(new ColormodelItem(string, BC_RGB888));
818 BC_CModels::to_text(string, BC_RGBA8888);
819 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
820 // BC_CModels::to_text(string, BC_RGB161616);
821 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
822 // BC_CModels::to_text(string, BC_RGBA16161616);
823 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
824 BC_CModels::to_text(string, BC_RGB_FLOAT);
825 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
826 BC_CModels::to_text(string, BC_RGBA_FLOAT);
827 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
828 BC_CModels::to_text(string, BC_YUV888);
829 colormodels.append(new ColormodelItem(string, BC_YUV888));
830 BC_CModels::to_text(string, BC_YUVA8888);
831 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
832 // BC_CModels::to_text(string, BC_YUV161616);
833 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
834 // BC_CModels::to_text(string, BC_YUVA16161616);
835 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
838 void MWindow::init_indexes()
840 mainindexes = new MainIndexes(this);
841 mainindexes->start_loop();
844 void MWindow::init_gui()
846 gui = new MWindowGUI(this);
847 gui->lock_window("MWindow::init_gui");
848 gui->create_objects();
849 gui->unlock_window();
850 gui->load_defaults(defaults);
853 void MWindow::init_signals()
855 sighandler = new SigHandler;
856 sighandler->initialize();
860 void MWindow::init_render()
862 render = new Render(this);
863 create_bd = new CreateBD_Thread(this);
864 create_dvd = new CreateDVD_Thread(this);
865 batch_render = new BatchRenderThread(this);
868 void MWindow::init_brender()
870 if(preferences->use_brender && !brender)
872 brender_lock->lock("MWindow::init_brender 1");
873 brender = new BRender(this);
874 brender->initialize();
875 session->brender_end = 0;
876 brender_lock->unlock();
879 if(!preferences->use_brender && brender)
881 brender_lock->lock("MWindow::init_brender 2");
884 session->brender_end = 0;
885 brender_lock->unlock();
887 if(brender) brender->restart(edl);
890 void MWindow::restart_brender()
892 //printf("MWindow::restart_brender 1\n");
893 if(brender) brender->restart(edl);
896 void MWindow::stop_brender()
898 if(brender) brender->stop();
901 int MWindow::brender_available(int position)
904 brender_lock->lock("MWindow::brender_available 1");
907 if(brender->map_valid)
909 brender->map_lock->lock("MWindow::brender_available 2");
910 if(position < brender->map_size &&
913 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
914 if(brender->map[position] == BRender::RENDERED)
917 brender->map_lock->unlock();
920 brender_lock->unlock();
924 void MWindow::set_brender_start()
926 edl->session->brender_start = edl->local_session->get_selectionstart(1);
928 gui->draw_overlays(1);
932 int MWindow::has_commercials()
934 return theme->use_commercials;
937 void MWindow::init_commercials()
940 commercials = new Commercials(this);
941 commercial_active = 0;
944 commercials->add_user();
947 void MWindow::commit_commercial()
949 if( !commercial_active ) return;
950 commercial_active = 0;
951 if( !commercials ) return;
952 commercials->commitDb();
955 void MWindow::undo_commercial()
957 if( !commercial_active ) return;
958 commercial_active = 0;
959 if( !commercials ) return;
960 commercials->undoDb();
963 int MWindow::put_commercial()
965 double start = edl->local_session->get_selectionstart();
966 double end = edl->local_session->get_selectionend();
967 if( start >= end ) return 0;
969 const char *errmsg = 0;
971 Tracks *tracks = edl->tracks;
974 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
975 if( track->data_type != TRACK_VIDEO ) continue;
976 if( !track->record ) continue;
977 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
979 int64_t units_start = track->to_units(start,0);
980 int64_t units_end = track->to_units(end,0);
981 Edits *edits = track->edits;
982 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
983 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
984 if(!edit1 && !edit2) continue; // nothing selected
985 if(!edit2) { // edit2 beyond end of track
987 units_end = edits->length();
989 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
990 Indexable *indexable = edit1->get_source();
991 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
994 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
995 if( track->data_type != TRACK_VIDEO ) continue;
996 if( !track->record ) continue;
997 int64_t units_start = track->to_units(start,0);
998 int64_t units_end = track->to_units(end,0);
999 Edits *edits = track->edits;
1000 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
1001 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
1002 if(!edit1 && !edit2) continue; // nothing selected
1003 if(!edit2) { // edit2 beyond end of track
1004 edit2 = edits->last;
1005 units_end = edits->length();
1007 Indexable *indexable = edit1->get_source();
1008 Asset *asset = (Asset *)indexable;
1009 File *file = video_cache->check_out(asset, edl);
1010 if( !file ) { errmsg = _("no file"); break; }
1011 int64_t edit_length = units_end - units_start;
1012 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1013 result = commercials->put_clip(file, edit1->channel,
1014 track->from_units(edit_start), track->from_units(edit_length));
1015 video_cache->check_in(asset);
1016 if( result ) { errmsg = _("db failed"); break; }
1019 char string[BCTEXTLEN];
1020 sprintf(string, _("put_commercial: %s"), errmsg);
1021 MainError::show_error(string);
1028 void MWindow::stop_playback(int wait)
1030 int locked = gui->get_window_lock();
1031 if( locked ) gui->unlock_window();
1033 cwindow->playback_engine->que->send_command(STOP,
1037 cwindow->playback_engine->interrupt_playback(wait);
1039 for(int i = 0; i < vwindows.size(); i++) {
1040 VWindow *vwindow = vwindows[i];
1041 if( !vwindow->is_running() ) continue;
1042 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1043 vwindow->playback_engine->interrupt_playback(wait);
1045 if( locked ) gui->lock_window("MWindow::stop_playback");
1048 int MWindow::load_filenames(ArrayList<char*> *filenames,
1050 int update_filename)
1052 ArrayList<EDL*> new_edls;
1053 ArrayList<Asset*> new_assets;
1054 ArrayList<File*> new_files;
1055 const int debug = 0;
1056 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1059 gui->start_hourglass();
1061 // Need to stop playback since tracking depends on the EDL not getting
1065 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1066 undo->update_undo_before();
1069 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1071 // Define new_edls and new_assets to load
1072 int result = 0, ftype = -1;
1073 for(int i = 0; i < filenames->size(); i++)
1076 File *new_file = new File;
1077 Asset *new_asset = new Asset(filenames->get(i));
1078 EDL *new_edl = new EDL;
1079 char string[BCTEXTLEN];
1081 new_edl->create_objects();
1082 new_edl->copy_session(edl);
1083 new_file->set_program(edl->session->program_no);
1085 sprintf(string, _("Loading %s"), new_asset->path);
1086 gui->show_message(string);
1087 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1089 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1090 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1095 // Convert media file to EDL
1097 // Warn about odd image dimensions
1098 if(new_asset->video_data &&
1099 ((new_asset->width % 2) ||
1100 (new_asset->height % 2)))
1102 char string[BCTEXTLEN];
1103 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1107 MainError::show_error(string);
1110 if(new_asset->program >= 0 &&
1111 edl->session->program_no != new_asset->program)
1113 char string[BCTEXTLEN];
1114 sprintf(string, _("%s's index was built for program number %d\n"
1115 "Playback preference is %d.\n Using program %d."),
1116 new_asset->path, new_asset->program,
1117 edl->session->program_no, new_asset->program);
1118 MainError::show_error(string);
1122 if(load_mode != LOADMODE_RESOURCESONLY)
1125 RecordLabels *labels = edl->session->label_cells ?
1126 new RecordLabels(new_file) : 0;
1128 asset_to_edl(new_edl, new_asset, labels);
1130 new_edls.append(new_edl);
1132 new_asset->Garbage::remove_user();
1138 new_assets.append(new_asset);
1142 // Set filename to nothing for assets since save EDL would overwrite them.
1143 if(load_mode == LOADMODE_REPLACE ||
1144 load_mode == LOADMODE_REPLACE_CONCATENATE)
1147 // Reset timeline position
1148 for(int i = 0; i < TOTAL_PANES; i++)
1150 new_edl->local_session->view_start[i] = 0;
1151 new_edl->local_session->track_start[i] = 0;
1159 case FILE_NOT_FOUND:
1160 sprintf(string, _("Failed to open %s"), new_asset->path);
1161 gui->show_message(string, theme->message_error);
1165 case FILE_UNRECOGNIZED_CODEC:
1168 IndexFile indexfile(this, new_asset);
1169 result = indexfile.open_index();
1172 indexfile.close_index();
1175 // Test existing EDLs
1178 for(int j = 0; j < new_edls.total + 1; j++)
1181 if(j == new_edls.total)
1183 old_asset = edl->assets->get_asset(new_asset->path);
1186 *new_asset = *old_asset;
1192 old_asset = new_edls[j]->assets->get_asset(new_asset->path);
1195 *new_asset = *old_asset;
1205 char string[BCTEXTLEN];
1207 fs.extract_name(string, new_asset->path);
1209 strcat(string, _("'s format couldn't be determined."));
1210 new_asset->audio_data = 1;
1211 new_asset->format = FILE_PCM;
1212 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1213 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1214 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1215 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1216 new_asset->signed_ = defaults->get("SIGNED_", 1);
1217 new_asset->header = defaults->get("HEADER", 0);
1219 FileFormat fwindow(this);
1220 fwindow.create_objects(new_asset, string);
1221 result = fwindow.run_window();
1224 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1225 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1226 defaults->update("AUDIO_BITS", new_asset->bits);
1227 defaults->update("BYTE_ORDER", new_asset->byte_order);
1228 defaults->update("SIGNED_", new_asset->signed_);
1229 defaults->update("HEADER", new_asset->header);
1236 // Recalculate length
1238 new_file = new File;
1239 result = new_file->open_file(preferences, new_asset, 1, 0);
1241 if(load_mode != LOADMODE_RESOURCESONLY)
1243 RecordLabels *labels = edl->session->label_cells ?
1244 new RecordLabels(new_file) : 0;
1245 asset_to_edl(new_edl, new_asset, labels);
1246 new_edls.append(new_edl);
1247 new_asset->Garbage::remove_user();
1253 new_assets.append(new_asset);
1267 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1268 xml_file.read_from_file(filenames->get(i));
1269 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1271 if(load_mode == LOADMODE_NESTED)
1273 // Load temporary EDL for nesting.
1274 EDL *nested_edl = new EDL;
1275 nested_edl->create_objects();
1276 nested_edl->set_path(filenames->get(i));
1277 nested_edl->load_xml(&xml_file, LOAD_ALL);
1278 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1279 edl_to_nested(new_edl, nested_edl);
1280 nested_edl->Garbage::remove_user();
1284 // Load EDL for pasting
1285 new_edl->load_xml(&xml_file, LOAD_ALL);
1286 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1287 test_plugins(new_edl, filenames->get(i));
1288 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1290 if(load_mode == LOADMODE_REPLACE ||
1291 load_mode == LOADMODE_REPLACE_CONCATENATE)
1293 strcpy(session->filename, filenames->get(i));
1294 strcpy(new_edl->local_session->clip_title,
1297 set_filename(new_edl->local_session->clip_title);
1301 new_edls.append(new_edl);
1307 // edls are in new_edls
1308 if( result && new_edl ) new_edl->Garbage::remove_user();
1309 // assets are copied
1310 if( new_asset ) new_asset->Garbage::remove_user();
1312 // Store for testing index
1313 new_files.append(new_file);
1316 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1319 if(!result) gui->statusbar->default_message();
1327 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1330 // Don't back up here.
1333 // For pasting, clear the active region
1334 if(load_mode == LOADMODE_PASTE ||
1335 load_mode == LOADMODE_NESTED)
1337 double start = edl->local_session->get_selectionstart();
1338 double end = edl->local_session->get_selectionend();
1339 if(!EQUIV(start, end))
1342 edl->session->labels_follow_edits,
1343 edl->session->plugins_follow_edits,
1344 edl->session->autos_follow_edits);
1347 paste_edls(&new_edls,
1351 edl->session->labels_follow_edits,
1352 edl->session->plugins_follow_edits,
1353 edl->session->autos_follow_edits);
1359 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1361 // Add new assets to EDL and schedule assets for index building.
1362 int got_indexes = 0;
1363 for(int i = 0; i < new_edls.size(); i++)
1365 EDL *new_edl = new_edls[i];
1366 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1368 mainindexes->add_next_asset(0,
1369 new_edl->nested_edls->get(j));
1371 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1376 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1377 if(new_assets.size())
1379 for(int i = 0; i < new_assets.size(); i++)
1381 Asset *new_asset = new_assets[i];
1385 for(int j = 0; j < new_files.size(); j++)
1387 new_file = new_files[j];
1388 if(!strcmp(new_file->asset->path,
1396 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1398 edl->assets->update(new_asset);
1404 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1406 // Start examining next batch of index files
1407 if(got_indexes) mainindexes->start_build();
1408 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1411 Track *track = edl->tracks->first;
1414 for(int j = 0; j < track->plugin_set.size(); j++)
1416 PluginSet *plugins = track->plugin_set[j];
1417 Plugin *plugin = plugins->get_first_plugin();
1421 if(load_mode == LOADMODE_REPLACE ||
1422 load_mode == LOADMODE_REPLACE_CONCATENATE)
1424 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1427 show_plugin(plugin);
1435 plugin = (Plugin*)plugin->next;
1439 track = track->next;
1442 // if just opening one new resource in replace mode
1443 if( load_mode == LOADMODE_REPLACE && new_edls.size() == 1 &&
1444 ftype != FILE_IS_XML )
1447 edl->local_session->preview_start = 0;
1448 edl->local_session->preview_end = edl->tracks->total_playable_length();
1449 edl->local_session->loop_playback = 0;
1450 edl->local_session->set_selectionstart(0);
1451 edl->local_session->set_selectionend(0);
1456 // need to update undo before project, since mwindow is unlocked & a new load
1457 // can begin here. Should really prevent loading until we're done.
1458 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1459 undo->update_undo_after(_("load"), LOAD_ALL);
1461 for(int i = 0; i < new_edls.size(); i++)
1463 new_edls[i]->remove_user();
1465 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1467 new_edls.remove_all();
1469 for(int i = 0; i < new_assets.size(); i++)
1471 new_assets[i]->Garbage::remove_user();
1474 new_assets.remove_all();
1475 new_files.remove_all_objects();
1478 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1479 if(load_mode == LOADMODE_REPLACE ||
1480 load_mode == LOADMODE_REPLACE_CONCATENATE)
1482 session->changes_made = 0;
1486 session->changes_made = 1;
1489 gui->stop_hourglass();
1492 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1493 update_project(load_mode);
1495 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1503 void MWindow::test_plugins(EDL *new_edl, char *path)
1505 char string[BCTEXTLEN];
1507 // Do a check weather plugins exist
1508 for(Track *track = new_edl->tracks->first; track; track = track->next)
1510 for(int k = 0; k < track->plugin_set.total; k++)
1512 PluginSet *plugin_set = track->plugin_set[k];
1513 for(Plugin *plugin = (Plugin*)plugin_set->first;
1515 plugin = (Plugin*)plugin->next)
1517 if(plugin->plugin_type == PLUGIN_STANDALONE)
1519 // ok we need to find it in plugindb
1520 int plugin_found = 0;
1522 for(int j = 0; j < plugindb->size(); j++)
1524 PluginServer *server = plugindb->get(j);
1526 !strcasecmp(server->title, plugin->title) &&
1527 ((track->data_type == TRACK_AUDIO && server->audio) ||
1528 (track->data_type == TRACK_VIDEO && server->video)) &&
1529 (!server->transition))
1536 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1537 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1538 "effect", plugin->title,
1540 MainError::show_error(string);
1546 for(Edit *edit = (Edit*)track->edits->first;
1548 edit = (Edit*)edit->next)
1550 if (edit->transition)
1552 // ok we need to find transition in plugindb
1554 int transition_found = 0;
1555 for(int j = 0; j < plugindb->size(); j++)
1557 PluginServer *server = plugindb->get(j);
1559 !strcasecmp(server->title, edit->transition->title) &&
1560 ((track->data_type == TRACK_AUDIO && server->audio) ||
1561 (track->data_type == TRACK_VIDEO && server->video)) &&
1562 (server->transition))
1563 transition_found = 1;
1566 if (!transition_found)
1569 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1570 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1571 "transition", edit->transition->title,
1573 MainError::show_error(string);
1581 void MWindow::init_shm()
1583 // Fix shared memory
1584 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1586 fprintf(fd, "0x7fffffff");
1591 fd = fopen("/proc/sys/kernel/shmmax", "r");
1593 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1598 fscanf(fd, _LD, &result);
1601 if(result < 0x7fffffff) {
1602 char string[BCTEXTLEN];
1603 sprintf(string, _("MWindow::init_shm: /proc/sys/kernel/shmmax is 0x" _LX ".\n"
1604 "you probably need to be root, or:\n"
1605 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1606 "before trying to start cinelerra.\n"
1607 "It should be at least 0x7fffffff for Cinelerra.\n"), result);
1608 MainError::show_error(string);
1613 void MWindow::create_objects(int want_gui,
1618 const int debug = 0;
1619 if(debug) PRINT_TRACE
1621 // For some reason, init_signals must come after show_splash or the signals won't
1624 if(debug) PRINT_TRACE
1627 if(debug) PRINT_TRACE
1630 if(debug) PRINT_TRACE
1631 init_defaults(defaults, config_path);
1633 init_plugins(this, preferences);
1634 if(debug) PRINT_TRACE
1635 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1636 if(debug) PRINT_TRACE
1638 if(debug) PRINT_TRACE
1641 char string[BCTEXTLEN];
1642 strcpy(string, preferences->plugin_dir);
1643 strcat(string, "/fonts");
1644 BC_Resources::init_fontconfig(string);
1645 if(debug) PRINT_TRACE
1647 // Initialize before too much else is running
1648 // Preferences & theme are required for building MPEG table of contents
1650 // Default project created here
1652 if(debug) PRINT_TRACE
1655 if(debug) PRINT_TRACE
1660 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1662 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1663 if(session->show_vwindow)
1664 get_viewer(1, DEFAULT_VWINDOW);
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());
1671 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());
1676 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1679 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
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());
1687 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1690 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1691 mainprogress = new MainProgress(this, gui);
1692 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1693 undo = new MainUndo(this);
1695 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1697 plugin_guis = new ArrayList<PluginServer*>;
1698 dead_plugins = new ArrayList<PluginServer*>;
1699 keyframe_threads = new ArrayList<KeyFrameThread*>;
1701 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1704 session->show_vwindow);
1706 // Show all vwindows
1707 // if(session->show_vwindow) {
1708 // for(int j = 0; j < vwindows.size(); j++) {
1709 // VWindow *vwindow = vwindows[j];
1710 // if( !vwindow->is_running() ) continue;
1711 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1714 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1715 // vwindow->gui->lock_window("MWindow::create_objects 1");
1716 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1717 // vwindow->gui->show_window();
1718 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1719 // vwindow->gui->unlock_window();
1724 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1726 if(session->show_cwindow)
1728 cwindow->gui->lock_window("MWindow::create_objects 1");
1729 cwindow->gui->show_window();
1730 cwindow->gui->unlock_window();
1733 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1734 if(session->show_awindow)
1736 awindow->gui->lock_window("MWindow::create_objects 1");
1737 awindow->gui->show_window();
1738 awindow->gui->unlock_window();
1741 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1742 if(session->show_lwindow)
1744 lwindow->gui->lock_window("MWindow::create_objects 1");
1745 lwindow->gui->show_window();
1746 lwindow->gui->unlock_window();
1749 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1751 (int)timer.get_difference(),
1753 if(session->show_gwindow)
1755 gwindow->gui->lock_window("MWindow::create_objects 1");
1756 gwindow->gui->show_window();
1757 gwindow->gui->unlock_window();
1760 if(debug) PRINT_TRACE
1762 gui->lock_window("MWindow::create_objects 1");
1763 gui->mainmenu->load_defaults(defaults);
1764 gui->mainmenu->update_toggles(0);
1765 gui->update_patchbay();
1766 gui->draw_canvas(0, 0);
1767 gui->draw_cursor(1);
1769 gui->raise_window();
1770 gui->unlock_window();
1772 if(debug) PRINT_TRACE
1776 if(preferences->use_tipwindow)
1778 if(debug) PRINT_TRACE
1780 gui->add_keyboard_listener(
1781 (int (BC_WindowBase::*)(BC_WindowBase *))
1782 &MWindowGUI::keyboard_listener);
1786 if(debug) PRINT_TRACE
1788 BC_WindowBase::get_resources()->vframe_shm = 1;
1793 void MWindow::show_splash()
1795 #include "data/heroine_logo11_png.h"
1796 VFrame *frame = new VFrame(heroine_logo11_png);
1797 BC_DisplayInfo display_info;
1798 splash_window = new SplashGUI(frame,
1799 display_info.get_root_w() / 2 - frame->get_w() / 2,
1800 display_info.get_root_h() / 2 - frame->get_h() / 2);
1801 splash_window->create_objects();
1804 void MWindow::hide_splash()
1807 delete splash_window;
1812 void MWindow::start()
1816 // vwindows[DEFAULT_VWINDOW]->start();
1827 playback_3d->start();
1836 void MWindow::show_vwindow()
1838 int total_running = 0;
1839 session->show_vwindow = 1;
1841 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
1842 // Raise all windows which are visible
1843 for(int j = 0; j < vwindows.size(); j++) {
1844 VWindow *vwindow = vwindows[j];
1845 if( !vwindow->is_running() ) continue;
1846 vwindow->gui->lock_window("MWindow::show_vwindow");
1847 vwindow->gui->show_window(0);
1848 vwindow->gui->raise_window();
1849 vwindow->gui->flush();
1850 vwindow->gui->unlock_window();
1854 // If no windows visible
1857 get_viewer(1, DEFAULT_VWINDOW);
1860 gui->mainmenu->show_vwindow->set_checked(1);
1863 void MWindow::show_awindow()
1865 session->show_awindow = 1;
1866 awindow->gui->lock_window("MWindow::show_awindow");
1867 awindow->gui->show_window();
1868 awindow->gui->raise_window();
1869 awindow->gui->flush();
1870 awindow->gui->unlock_window();
1871 gui->mainmenu->show_awindow->set_checked(1);
1874 char *MWindow::get_cwindow_display()
1876 char *x11_host = screens < 2 || session->window_config == 0 ?
1877 session->a_x11_host : session->b_x11_host;
1878 return *x11_host ? x11_host : 0;
1881 void MWindow::show_cwindow()
1883 session->show_cwindow = 1;
1884 cwindow->show_window();
1885 gui->mainmenu->show_cwindow->set_checked(1);
1888 void MWindow::show_gwindow()
1890 session->show_gwindow = 1;
1892 gwindow->gui->lock_window("MWindow::show_gwindow");
1893 gwindow->gui->show_window();
1894 gwindow->gui->raise_window();
1895 gwindow->gui->flush();
1896 gwindow->gui->unlock_window();
1898 gui->mainmenu->show_gwindow->set_checked(1);
1901 void MWindow::show_lwindow()
1903 session->show_lwindow = 1;
1904 lwindow->gui->lock_window("MWindow::show_lwindow");
1905 lwindow->gui->show_window();
1906 lwindow->gui->raise_window();
1907 lwindow->gui->flush();
1908 lwindow->gui->unlock_window();
1909 gui->mainmenu->show_lwindow->set_checked(1);
1912 int MWindow::tile_windows(int window_config)
1914 int need_reload = 0;
1915 int play_config = window_config==0 ? 0 : 1;
1916 edl->session->playback_config->load_defaults(defaults, play_config);
1917 session->default_window_positions(window_config);
1918 if( screens == 1 ) {
1919 gui->default_positions();
1920 sync_parameters(CHANGE_ALL);
1927 void MWindow::toggle_loop_playback()
1929 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1930 set_loop_boundaries();
1933 gui->draw_overlays(1);
1934 sync_parameters(CHANGE_PARAMS);
1937 //void MWindow::set_titles(int value)
1939 // edl->session->show_titles = value;
1940 // trackmovement(edl->local_session->track_start);
1943 void MWindow::set_screens(int value)
1948 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
1950 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
1951 edl->session->auto_keyframes = value;
1952 gui->mbuttons->edit_panel->keyframe->update(value);
1954 if(lock_mwindow) gui->unlock_window();
1956 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1957 cwindow->gui->edit_panel->keyframe->update(value);
1958 cwindow->gui->flush();
1959 if(lock_cwindow) cwindow->gui->unlock_window();
1962 void MWindow::set_keyframe_type(int mode)
1964 gui->lock_window("MWindow::set_keyframe_type");
1965 edl->local_session->floatauto_type = mode;
1966 gui->mainmenu->update_toggles(0);
1967 gui->unlock_window();
1970 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
1972 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
1973 edl->session->editing_mode = new_editing_mode;
1974 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1975 gui->mbuttons->edit_panel->update();
1976 gui->set_editing_mode(1);
1977 if(lock_mwindow) gui->unlock_window();
1980 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
1981 cwindow->gui->edit_panel->update();
1982 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1983 if(lock_cwindow) cwindow->gui->unlock_window();
1988 void MWindow::sync_parameters(int change_type)
1990 if( in_destructor ) return;
1992 // Sync engines which are playing back
1993 if(cwindow->playback_engine->is_playing_back)
1995 if(change_type == CHANGE_PARAMS)
1997 // TODO: block keyframes until synchronization is done
1998 cwindow->playback_engine->sync_parameters(edl);
2003 int command = cwindow->playback_engine->command->command;
2004 cwindow->playback_engine->que->send_command(STOP,
2008 // Waiting for tracking to finish would make the restart position more
2009 // accurate but it can't lock the window to stop tracking for some reason.
2010 // Not waiting for tracking gives a faster response but restart position is
2011 // only as accurate as the last tracking update.
2012 cwindow->playback_engine->interrupt_playback(0);
2013 cwindow->playback_engine->que->send_command(command,
2022 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2029 void MWindow::age_caches()
2031 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2033 // preferences->cache_size,
2034 // audio_cache->get_memory_usage(1),
2035 // video_cache->get_memory_usage(1),
2036 // frame_cache->get_memory_usage(),
2037 // wave_cache->get_memory_usage(),
2039 frame_cache->age_cache(512);
2040 wave_cache->age_cache(8192);
2042 int64_t memory_usage;
2043 int64_t prev_memory_usage = 0;
2045 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2046 while( !result && prev_memory_usage !=
2047 (memory_usage=video_cache->get_memory_usage(1)) &&
2048 memory_usage > video_size ) {
2049 video_cache->delete_oldest();
2050 prev_memory_usage = memory_usage;
2053 prev_memory_usage = 0;
2055 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2056 while( !result && prev_memory_usage !=
2057 (memory_usage=audio_cache->get_memory_usage(1)) &&
2058 memory_usage > audio_size ) {
2059 audio_cache->delete_oldest();
2060 prev_memory_usage = memory_usage;
2064 void MWindow::reset_android_remote()
2066 gui->use_android_remote(preferences->android_remote);
2070 void MWindow::show_keyframe_gui(Plugin *plugin)
2072 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2073 // Find existing thread
2074 for(int i = 0; i < keyframe_threads->size(); i++)
2076 if(keyframe_threads->get(i)->plugin == plugin)
2078 keyframe_threads->get(i)->start_window(plugin, 0);
2079 keyframe_gui_lock->unlock();
2084 // Find unused thread
2085 for(int i = 0; i < keyframe_threads->size(); i++)
2087 if(!keyframe_threads->get(i)->plugin)
2089 keyframe_threads->get(i)->start_window(plugin, 0);
2090 keyframe_gui_lock->unlock();
2095 // Create new thread
2096 KeyFrameThread *thread = new KeyFrameThread(this);
2097 keyframe_threads->append(thread);
2098 thread->start_window(plugin, 0);
2100 keyframe_gui_lock->unlock();
2107 void MWindow::show_plugin(Plugin *plugin)
2112 // Remove previously deleted plugin GUIs
2113 dead_plugin_lock->lock("MWindow::delete_plugin");
2114 for(int i = 0; i < dead_plugins->size(); i++)
2116 delete dead_plugins->get(i);
2118 dead_plugins->remove_all();
2119 dead_plugin_lock->unlock();
2121 //printf("MWindow::show_plugin %d\n", __LINE__);
2125 plugin_gui_lock->lock("MWindow::show_plugin");
2126 for(int i = 0; i < plugin_guis->total; i++)
2128 // Pointer comparison
2129 if(plugin_guis->get(i)->plugin == plugin)
2131 plugin_guis->get(i)->raise_window();
2138 //printf("MWindow::show_plugin 1\n");
2143 printf("MWindow::show_plugin track not defined.\n");
2145 PluginServer *server = scan_plugindb(plugin->title,
2146 plugin->track->data_type);
2148 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2149 if(server && server->uses_gui)
2151 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
2152 // Needs mwindow to do GUI
2153 gui->set_mwindow(this);
2154 gui->open_plugin(0, preferences, edl, plugin);
2159 plugin_gui_lock->unlock();
2160 //printf("MWindow::show_plugin %d\n", __LINE__);
2163 //printf("MWindow::show_plugin 2\n");
2166 void MWindow::hide_plugin(Plugin *plugin, int lock)
2169 // Update the toggle
2170 gui->lock_window("MWindow::hide_plugin");
2171 gui->update(0, 1, 0, 0, 0, 0, 0);
2172 gui->unlock_window();
2174 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2175 for(int i = 0; i < plugin_guis->total; i++)
2177 if(plugin_guis->get(i)->plugin == plugin)
2179 PluginServer *ptr = plugin_guis->get(i);
2180 plugin_guis->remove(ptr);
2181 if(lock) plugin_gui_lock->unlock();
2182 // Last command executed in client side close
2183 // Schedule for deletion
2190 if(lock) plugin_gui_lock->unlock();
2193 void MWindow::delete_plugin(PluginServer *plugin)
2195 dead_plugin_lock->lock("MWindow::delete_plugin");
2196 dead_plugins->append(plugin);
2197 dead_plugin_lock->unlock();
2200 void MWindow::hide_plugins()
2202 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2203 while(plugin_guis->size())
2205 PluginServer *ptr = plugin_guis->get(0);
2206 plugin_guis->remove(ptr);
2207 plugin_gui_lock->unlock();
2208 // Last command executed in client side close
2209 // Schedule for deletion
2212 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2214 plugin_gui_lock->unlock();
2216 hide_keyframe_guis();
2219 void MWindow::hide_keyframe_guis()
2221 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2222 for(int i = 0; i < keyframe_threads->size(); i++)
2224 keyframe_threads->get(i)->close_window();
2226 keyframe_gui_lock->unlock();
2229 void MWindow::hide_keyframe_gui(Plugin *plugin)
2231 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2232 for(int i = 0; i < keyframe_threads->size(); i++)
2234 if(keyframe_threads->get(i)->plugin == plugin)
2236 keyframe_threads->get(i)->close_window();
2240 keyframe_gui_lock->unlock();
2243 void MWindow::update_keyframe_guis()
2245 // Send new configuration to keyframe GUI's
2246 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2247 for(int i = 0; i < keyframe_threads->size(); i++)
2249 KeyFrameThread *ptr = keyframe_threads->get(i);
2250 if(edl->tracks->plugin_exists(ptr->plugin))
2254 ptr->close_window();
2257 keyframe_gui_lock->unlock();
2260 void MWindow::update_plugin_guis(int do_keyframe_guis)
2262 // Send new configuration to plugin GUI's
2263 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2265 for(int i = 0; i < plugin_guis->size(); i++)
2267 PluginServer *ptr = plugin_guis->get(i);
2268 if(edl->tracks->plugin_exists(ptr->plugin))
2272 // Schedule for deletion if no plugin
2273 plugin_guis->remove_number(i);
2282 // Change plugin variable if not visible
2283 Track *track = edl->tracks->first;
2286 for(int i = 0; i < track->plugin_set.size(); i++)
2288 Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
2292 for(int i = 0; i < plugin_guis->size(); i++)
2294 PluginServer *server = plugin_guis->get(i);
2295 if(server->plugin == plugin)
2302 if(!got_it) plugin->show = 0;
2304 plugin = (Plugin*)plugin->next;
2308 track = track->next;
2311 plugin_gui_lock->unlock();
2314 if(do_keyframe_guis) update_keyframe_guis();
2317 int MWindow::plugin_gui_open(Plugin *plugin)
2320 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2321 for(int i = 0; i < plugin_guis->total; i++)
2323 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2329 plugin_gui_lock->unlock();
2333 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2335 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2336 for(int i = 0; i < plugin_guis->total; i++)
2338 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2340 plugin_guis->get(i)->render_gui(data);
2344 plugin_gui_lock->unlock();
2347 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2349 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2350 for(int i = 0; i < plugin_guis->total; i++)
2352 if(plugin_guis->get(i)->plugin->identical_location(plugin))
2354 plugin_guis->get(i)->render_gui(data, size);
2358 plugin_gui_lock->unlock();
2362 void MWindow::update_plugin_states()
2364 plugin_gui_lock->lock("MWindow::update_plugin_states");
2365 for(int i = 0; i < plugin_guis->total; i++)
2369 Plugin *src_plugin = plugin_guis->get(i)->plugin;
2370 PluginServer *src_plugingui = plugin_guis->get(i);
2372 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2373 for(Track *track = edl->tracks->first;
2375 track = track->next)
2378 j < track->plugin_set.total && !result;
2381 PluginSet *plugin_set = track->plugin_set[j];
2382 for(Plugin *plugin = (Plugin*)plugin_set->first;
2384 plugin = (Plugin*)plugin->next)
2386 if(plugin == src_plugin &&
2387 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2393 // Doesn't exist anymore
2396 hide_plugin(src_plugin, 0);
2400 plugin_gui_lock->unlock();
2404 void MWindow::update_plugin_titles()
2406 for(int i = 0; i < plugin_guis->total; i++)
2408 plugin_guis->get(i)->update_title();
2412 int MWindow::asset_to_edl(EDL *new_edl,
2414 RecordLabels *labels)
2416 const int debug = 0;
2417 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2420 // Keep frame rate, sample rate, and output size unchanged.
2421 // These parameters would revert the project if VWindow displayed an asset
2422 // of different size than the project.
2423 if(new_asset->video_data)
2425 new_edl->session->video_tracks = new_asset->layers;
2428 new_edl->session->video_tracks = 0;
2430 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2436 if(new_asset->audio_data)
2438 new_edl->session->audio_tracks = new_asset->channels;
2441 new_edl->session->audio_tracks = 0;
2442 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2444 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2445 new_edl->create_default_tracks();
2446 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2447 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2451 //printf("MWindow::asset_to_edl 3\n");
2452 new_edl->insert_asset(new_asset,
2457 //printf("MWindow::asset_to_edl 3\n");
2458 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2464 char string[BCTEXTLEN];
2466 fs.extract_name(string, new_asset->path);
2467 //printf("MWindow::asset_to_edl 3\n");
2469 strcpy(new_edl->local_session->clip_title, string);
2470 //printf("MWindow::asset_to_edl 4 %s\n", string);
2471 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2476 int MWindow::edl_to_nested(EDL *new_edl,
2480 // Keep frame rate, sample rate, and output size unchanged.
2481 // These parameters would revert the project if VWindow displayed an asset
2482 // of different size than the project.
2486 // Nest all video & audio outputs
2487 new_edl->session->video_tracks = 1;
2488 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2489 new_edl->create_default_tracks();
2493 new_edl->insert_asset(0,
2499 char string[BCTEXTLEN];
2501 fs.extract_name(string, nested_edl->path);
2502 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2504 strcpy(new_edl->local_session->clip_title, string);
2509 // Reset everything after a load.
2510 void MWindow::update_project(int load_mode)
2512 const int debug = 0;
2514 if(debug) PRINT_TRACE
2516 edl->tracks->update_y_pixels(theme);
2518 if(debug) PRINT_TRACE
2520 if(load_mode == LOADMODE_REPLACE ||
2521 load_mode == LOADMODE_REPLACE_CONCATENATE)
2526 gui->update(1, 1, 1, 1, 1, 1, 1);
2527 if(debug) PRINT_TRACE
2528 gui->unlock_window();
2530 cwindow->gui->lock_window("MWindow::update_project 1");
2531 cwindow->update(0, 0, 1, 1, 1);
2532 cwindow->gui->unlock_window();
2534 if(debug) PRINT_TRACE
2536 // Close all the vwindows
2537 if(load_mode == LOADMODE_REPLACE ||
2538 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2539 if(debug) PRINT_TRACE
2540 int first_vwindow = 0;
2541 if(session->show_vwindow) first_vwindow = 1;
2542 // Change visible windows to no source
2543 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2544 VWindow *vwindow = vwindows[i];
2545 if( !vwindow->is_running() ) continue;
2546 vwindow->change_source(-1);
2549 // Close remaining windows
2550 for(int i = first_vwindow; i < vwindows.size(); i++) {
2551 VWindow *vwindow = vwindows[i];
2552 if( !vwindow->is_running() ) continue;
2553 vwindow->close_window();
2555 if(debug) PRINT_TRACE
2557 else if(vwindows.size()) {
2558 VWindow *vwindow = vwindows[DEFAULT_VWINDOW];
2559 if( vwindow->is_running() ) {
2560 vwindow->gui->lock_window("MWindow::update_project");
2562 vwindow->gui->unlock_window();
2566 if(debug) PRINT_TRACE
2567 cwindow->gui->lock_window("MWindow::update_project 2");
2568 cwindow->gui->timebar->update(0);
2569 cwindow->gui->unlock_window();
2571 if(debug) PRINT_TRACE
2572 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2577 if(debug) PRINT_TRACE
2579 awindow->gui->lock_window("MWindow::update_project");
2580 awindow->gui->update_assets();
2581 awindow->gui->flush();
2582 awindow->gui->unlock_window();
2584 if(debug) PRINT_TRACE
2586 gui->lock_window("MWindow::update_project");
2588 if(debug) PRINT_TRACE
2591 void MWindow::remove_indexfile(Indexable *indexable)
2593 if( !indexable->is_asset ) return;
2594 Asset *asset = (Asset *)indexable;
2596 IndexFile::delete_index(preferences, asset, ".toc");
2597 IndexFile::delete_index(preferences, asset, ".idx");
2598 IndexFile::delete_index(preferences, asset, ".mkr");
2601 void MWindow::rebuild_indices()
2603 for(int i = 0; i < session->drag_assets->total; i++)
2605 Indexable *indexable = session->drag_assets->get(i);
2606 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2607 remove_indexfile(indexable);
2608 // Schedule index build
2609 IndexState *index_state = indexable->index_state;
2610 index_state->index_status = INDEX_NOTTESTED;
2611 if( indexable->is_asset ) {
2612 Asset *asset = (Asset *)indexable;
2613 if( asset->format != FILE_PCM )
2614 asset->reset_audio();
2615 asset->reset_video();
2617 mainindexes->add_next_asset(0, indexable);
2619 mainindexes->start_build();
2623 void MWindow::save_backup()
2626 edl->set_path(session->filename);
2627 edl->save_xml(&file,
2631 file.terminate_string();
2632 char path[BCTEXTLEN];
2634 strcpy(path, BACKUP_PATH);
2635 fs.complete_path(path);
2637 if(file.write_to_file(path))
2640 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2641 gui->show_message(string2);
2645 void MWindow::load_backup()
2647 ArrayList<char*> path_list;
2648 path_list.set_array_delete();
2650 char string[BCTEXTLEN];
2651 strcpy(string, BACKUP_PATH);
2653 fs.complete_path(string);
2655 path_list.append(out_path = new char[strlen(string) + 1]);
2656 strcpy(out_path, string);
2658 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2659 edl->local_session->clip_title[0] = 0;
2660 // This is unique to backups since the path of the backup is different than the
2661 // path of the project.
2662 set_filename(edl->path);
2663 path_list.remove_all_objects();
2667 static inline int gcd(int m, int n)
2670 if( m < n ) { r = m; m = n; n = r; }
2671 while( (r = m % n) != 0 ) { m = n; n = r; }
2675 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2678 if(!width || !height) return 1;
2679 double ar = (double)width / height;
2680 // square-ish pixels
2681 if( EQUIV(ar, 1.0000) ) return 0;
2682 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2683 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2684 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2685 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2686 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2687 int ww = width, hh = height;
2688 // numerator, denominator must be under mx
2689 int mx = 255, n = gcd(ww, hh);
2690 if( n > 1 ) { ww /= n; hh /= n; }
2691 // search near height in case extra/missing lines
2692 if( ww >= mx || hh >= mx ) {
2693 double err = height; // +/- 2 percent height
2694 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2695 int iw = width, ih = height+i;
2696 if( (n=gcd(iw, ih)) > 1 ) {
2697 int u = iw/n; if( u >= mx ) continue;
2698 int v = ih/n; if( v >= mx ) continue;
2699 double r = (double) u/v, er = fabs(ar-r);
2700 if( er >= err ) continue;
2701 err = er; ww = u; hh = v;
2710 void MWindow::reset_caches()
2712 frame_cache->remove_all();
2713 wave_cache->remove_all();
2714 audio_cache->remove_all();
2715 video_cache->remove_all();
2716 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2717 cwindow->playback_engine->audio_cache->remove_all();
2718 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2719 cwindow->playback_engine->video_cache->remove_all();
2721 for(int i = 0; i < vwindows.size(); i++) {
2722 VWindow *vwindow = vwindows[i];
2723 if( !vwindow->is_running() ) continue;
2724 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2725 vwindow->playback_engine->audio_cache->remove_all();
2726 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2727 vwindow->playback_engine->video_cache->remove_all();
2731 void MWindow::remove_asset_from_caches(Asset *asset)
2733 frame_cache->remove_asset(asset);
2734 wave_cache->remove_asset(asset);
2735 audio_cache->delete_entry(asset);
2736 video_cache->delete_entry(asset);
2737 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2738 cwindow->playback_engine->audio_cache->delete_entry(asset);
2739 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2740 cwindow->playback_engine->video_cache->delete_entry(asset);
2741 for(int i = 0; i < vwindows.size(); i++) {
2742 VWindow *vwindow = vwindows[i];
2743 if( !vwindow->is_running() ) continue;
2744 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2745 vwindow->playback_engine->audio_cache->delete_entry(asset);
2746 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2747 vwindow->playback_engine->video_cache->delete_entry(asset);
2752 void MWindow::remove_assets_from_project(int push_undo, int redraw,
2753 ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
2755 for(int i = 0; i < session->drag_assets->total; i++) {
2756 Indexable *indexable = session->drag_assets->get(i);
2757 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
2760 // Remove from VWindow.
2761 for(int i = 0; i < session->drag_clips->total; i++) {
2762 for(int j = 0; j < vwindows.size(); j++) {
2763 VWindow *vwindow = vwindows[j];
2764 if( !vwindow->is_running() ) continue;
2765 if(session->drag_clips->get(i) == vwindow->get_edl()) {
2766 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
2767 vwindow->delete_source(1, 1);
2768 vwindow->gui->unlock_window();
2773 for(int i = 0; i < session->drag_assets->size(); i++) {
2774 for(int j = 0; j < vwindows.size(); j++) {
2775 VWindow *vwindow = vwindows[j];
2776 if( !vwindow->is_running() ) continue;
2777 if(session->drag_assets->get(i) == vwindow->get_source()) {
2778 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
2779 vwindow->delete_source(1, 1);
2780 vwindow->gui->unlock_window();
2785 for(int i = 0; i < session->drag_assets->size(); i++) {
2786 Indexable *indexable = session->drag_assets->get(i);
2787 remove_indexfile(indexable);
2790 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2791 if(push_undo) undo->update_undo_before();
2792 if(drag_assets) edl->remove_from_project(drag_assets);
2793 if(drag_clips) edl->remove_from_project(session->drag_clips);
2794 if(redraw) save_backup();
2795 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
2800 gui->lock_window("MWindow::remove_assets_from_project 3");
2808 gui->unlock_window();
2810 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
2811 awindow->gui->update_assets();
2812 awindow->gui->flush();
2813 awindow->gui->unlock_window();
2815 // Removes from playback here
2816 sync_parameters(CHANGE_ALL);
2820 void MWindow::remove_assets_from_disk()
2823 for(int i = 0; i < session->drag_assets->total; i++)
2825 remove(session->drag_assets->get(i)->path);
2828 remove_assets_from_project(1,
2830 session->drag_assets,
2831 session->drag_clips);
2834 void MWindow::dump_plugins(FILE *fp)
2836 if( !plugindb ) return;
2837 for(int i = 0; i < plugindb->total; i++)
2839 fprintf(fp, "type=%d audio=%d video=%d rt=%d multi=%d"
2840 " synth=%d transition=%d theme=%d %s\n",
2841 plugindb->get(i)->plugin_type,
2842 plugindb->get(i)->audio,
2843 plugindb->get(i)->video,
2844 plugindb->get(i)->realtime,
2845 plugindb->get(i)->multichannel,
2846 plugindb->get(i)->get_synthesis(),
2847 plugindb->get(i)->transition,
2848 plugindb->get(i)->theme,
2849 plugindb->get(i)->title);
2853 void MWindow::dump_edl(FILE *fp)
2859 void MWindow::dump_undo(FILE *fp)
2865 void MWindow::dump_exe(FILE *fp)
2867 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
2868 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
2869 int len = readlink(proc_path, exe_path, sizeof(exe_path));
2870 if( len < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
2873 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
2874 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
2875 int fd = open(exe_path,O_RDONLY);
2876 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
2877 uint8_t buf[65536]; SHA1 sha1;
2878 while( (len=read(fd,buf,sizeof(buf))) > 0 ) {
2879 sha1.addBytes(buf, len);
2882 fprintf(fp, "SHA1: ");
2883 uint8_t digest[20]; sha1.computeHash(digest);
2884 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
2889 void MWindow::trap_hook(FILE *fp, void *vp)
2891 MWindow *mwindow = (MWindow *)vp;
2892 fprintf(fp, "\nEXE:\n");
2893 mwindow->dump_exe(fp);
2894 fprintf(fp, "\nPLUGINS:\n");
2895 mwindow->dump_plugins(fp);
2896 fprintf(fp, "\nEDL:\n");
2897 mwindow->dump_edl(fp);
2898 fprintf(fp, "\nUNDO:\n");
2899 mwindow->dump_undo(fp);
2907 int MWindow::save_defaults()
2909 gui->save_defaults(defaults);
2910 edl->save_defaults(defaults);
2911 session->save_defaults(defaults);
2912 preferences->save_defaults(defaults);
2914 for(int i = 0; i < plugin_guis->total; i++)
2916 // Pointer comparison
2917 plugin_guis->get(i)->save_defaults();
2919 awindow->save_defaults(defaults);
2925 int MWindow::run_script(FileXML *script)
2927 int result = 0, result2 = 0;
2928 while(!result && !result2)
2930 result = script->read_tag();
2933 if(script->tag.title_is("new_project"))
2935 // Run new in immediate mode.
2936 // gui->mainmenu->new_project->run_script(script);
2939 if(script->tag.title_is("record"))
2941 // Run record as a thread. It is a terminal command.
2943 // Will read the complete scipt file without letting record read it if not
2949 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
2956 // ================================= synchronization
2959 int MWindow::interrupt_indexes()
2961 mainindexes->interrupt_build();
2967 void MWindow::next_time_format()
2969 switch(edl->session->time_format)
2971 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
2972 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
2973 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2974 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
2975 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
2976 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
2977 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
2980 time_format_common();
2983 void MWindow::prev_time_format()
2985 switch(edl->session->time_format)
2987 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
2988 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
2989 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
2990 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2991 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
2992 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
2993 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
2996 time_format_common();
2999 void MWindow::time_format_common()
3001 gui->lock_window("MWindow::next_time_format");
3002 gui->redraw_time_dependancies();
3005 char string[BCTEXTLEN], string2[BCTEXTLEN];
3006 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
3007 gui->show_message(string);
3009 gui->unlock_window();
3013 int MWindow::set_filename(const char *filename)
3015 if( filename != session->filename )
3016 strcpy(session->filename, filename);
3017 if( filename != edl->path )
3018 strcpy(edl->path, filename);
3022 if(filename[0] == 0)
3024 gui->set_title(PROGRAM_NAME);
3029 char string[BCTEXTLEN], string2[BCTEXTLEN];
3030 dir.extract_name(string, filename);
3031 sprintf(string2, PROGRAM_NAME ": %s", string);
3032 gui->set_title(string2);
3045 int MWindow::set_loop_boundaries()
3047 double start = edl->local_session->get_selectionstart();
3048 double end = edl->local_session->get_selectionend();
3056 if(edl->tracks->total_length())
3059 end = edl->tracks->total_length();
3066 if(edl->local_session->loop_playback && start != end)
3068 edl->local_session->loop_start = start;
3069 edl->local_session->loop_end = end;
3080 int MWindow::reset_meters()
3082 cwindow->gui->lock_window("MWindow::reset_meters 1");
3083 cwindow->gui->meters->reset_meters();
3084 cwindow->gui->unlock_window();
3086 for(int j = 0; j < vwindows.size(); j++) {
3087 VWindow *vwindow = vwindows[j];
3088 if( !vwindow->is_running() ) continue;
3089 vwindow->gui->lock_window("MWindow::reset_meters 2");
3090 vwindow->gui->meters->reset_meters();
3091 vwindow->gui->unlock_window();
3094 lwindow->gui->lock_window("MWindow::reset_meters 3");
3095 lwindow->gui->panel->reset_meters();
3096 lwindow->gui->unlock_window();
3098 gui->lock_window("MWindow::reset_meters 4");
3099 gui->reset_meters();
3100 gui->unlock_window();
3105 void MWindow::resync_guis()
3109 gui->lock_window("MWindow::resync_guis");
3110 gui->update(1, 1, 1, 1, 1, 1, 0);
3111 gui->unlock_window();
3113 cwindow->gui->lock_window("MWindow::resync_guis");
3114 cwindow->gui->resize_event(cwindow->gui->get_w(),
3115 cwindow->gui->get_h());
3116 int channels = edl->session->audio_channels;
3117 cwindow->gui->meters->set_meters(channels, 1);
3118 cwindow->gui->flush();
3119 cwindow->gui->unlock_window();
3121 for(int i = 0; i < vwindows.size(); i++) {
3122 VWindow *vwindow = vwindows[i];
3123 if( !vwindow->is_running() ) continue;
3124 vwindow->gui->lock_window("MWindow::resync_guis");
3125 vwindow->gui->resize_event(vwindow->gui->get_w(),
3126 vwindow->gui->get_h());
3127 vwindow->gui->meters->set_meters(channels, 1);
3128 vwindow->gui->flush();
3129 vwindow->gui->unlock_window();
3132 lwindow->gui->lock_window("MWindow::resync_guis");
3133 lwindow->gui->panel->set_meters(channels, 1);
3134 lwindow->gui->flush();
3135 lwindow->gui->unlock_window();
3138 if(((edl->session->output_w % 4) ||
3139 (edl->session->output_h % 4)) &&
3140 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3142 MainError::show_error(
3143 _("This project's dimensions are not multiples of 4 so\n"
3144 "it can't be rendered by OpenGL."));
3149 sync_parameters(CHANGE_ALL);
3152 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3154 File *file = new File;
3155 EDLSession *session = edl->session;
3156 double old_framerate = session->frame_rate;
3157 double old_samplerate = session->sample_rate;
3158 int result = file->open_file(preferences, asset, 1, 0);
3159 if( !result && delete_tracks > 0 )
3160 undo->update_undo_before();
3161 if( !result && asset->get_video_layers() > 0 ) {
3162 // try to get asset up to date, may fail
3163 file->select_video_stream(asset, vstream);
3164 // either way use what was/is there.
3165 double framerate = asset->get_frame_rate();
3166 int width = asset->get_w();
3167 int height = asset->get_h();
3168 // must be multiple of 4 for opengl
3169 width = (width+3) & ~3; height = (height+3) & ~3;
3170 int driver = session->playback_config->vconfig->driver;
3171 int color_model = file->get_best_colormodel(asset, driver);
3172 color_model = BC_CModels::is_yuv(color_model) ?
3173 BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3174 BC_CModels::is_float(color_model) ?
3175 BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3176 BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3177 session->color_model = color_model;
3178 session->output_w = width;
3179 session->output_h = height;
3180 session->frame_rate = framerate;
3181 // not, asset->actual_width/actual_height
3182 asset->width = session->output_w;
3183 asset->height = session->output_h;
3184 asset->frame_rate = session->frame_rate;
3185 create_aspect_ratio(session->aspect_w, session->aspect_h,
3186 session->output_w, session->output_h);
3187 Track *track = edl->tracks->first;
3188 for( Track *next_track=0; track; track=next_track ) {
3189 next_track = track->next;
3190 if( track->data_type != TRACK_VIDEO ) continue;
3191 if( delete_tracks ) {
3192 Edit *edit = track->edits->first;
3193 for( Edit *next_edit=0; edit; edit=next_edit ) {
3194 next_edit = edit->next;
3195 if( edit->channel != vstream ||
3196 !edit->asset || !edit->asset->is_asset ||
3197 *asset != *edit->asset )
3201 if( track->edits->first ) {
3202 track->track_w = edl->session->output_w;
3203 track->track_h = edl->session->output_h;
3205 else if( delete_tracks )
3206 edl->tracks->delete_track(track);
3208 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3210 if( !result && asset->channels > 0 ) {
3211 session->sample_rate = asset->get_sample_rate();
3212 int64_t channel_mask = 0;
3213 int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
3214 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3215 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3217 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3218 if( channels > 6 ) channels = 6;
3219 session->audio_tracks = session->audio_channels = channels;
3220 switch( channels ) {
3222 session->achannel_positions[0] = 90;
3223 session->achannel_positions[1] = 150;
3224 session->achannel_positions[2] = 30;
3225 session->achannel_positions[3] = 210;
3226 session->achannel_positions[4] = 330;
3227 session->achannel_positions[5] = 270;
3230 session->achannel_positions[0] = 180;
3231 session->achannel_positions[1] = 0;
3234 remap_audio(MWindow::AUDIO_1_TO_1);
3236 if( delete_tracks ) {
3237 Track *track = edl->tracks->first;
3238 for( Track *next_track=0; track; track=next_track ) {
3239 next_track = track->next;
3240 if( track->data_type != TRACK_AUDIO ) continue;
3241 Edit *edit = track->edits->first;
3242 for( Edit *next_edit=0; edit; edit=next_edit ) {
3243 next_edit = edit->next;
3244 if( !((1<<edit->channel) & channel_mask) ||
3245 !edit->asset || !edit->asset->is_asset ||
3246 *asset != *edit->asset )
3249 if( !track->edits->first )
3250 edl->tracks->delete_track(track);
3254 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3257 if( !result && delete_tracks > 0 ) {
3259 undo->update_undo_after(_("select asset"), LOAD_ALL);
3265 int MWindow::select_asset(int vtrack, int delete_tracks)
3267 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3268 if( !track ) return 1;
3269 Edit *edit = track->edits->first;
3270 if( !edit ) return 1;
3271 Asset *asset = edit->asset;
3272 if( !asset || !asset->is_asset ) return 1;
3273 return select_asset(asset, edit->channel, -1, delete_tracks);
3276 void MWindow::dump_plugindb(FILE *fp)
3278 if( !plugindb ) return;
3279 for(int i = 0; i < plugindb->total; i++)
3280 plugindb->get(i)->dump(fp);