3 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "audioalsa.h"
24 #include "awindowgui.h"
26 #include "batchrender.h"
27 #include "bcdisplayinfo.h"
28 #include "bcsignals.h"
34 #include "channeldb.h"
35 #include "channelinfo.h"
37 #include "bccmodels.h"
38 #include "commercials.h"
39 #include "cplayback.h"
41 #include "cwindowgui.h"
44 #include "devicedvbinput.inc"
45 #include "dvdcreate.h"
46 #include "editpanel.h"
48 #include "edlsession.h"
50 #include "fileformat.h"
52 #include "fileserver.h"
53 #include "filesystem.h"
56 #include "framecache.h"
58 #include "gwindowgui.h"
59 #include "keyframegui.h"
60 #include "indexfile.h"
62 #include "levelwindowgui.h"
63 #include "levelwindow.h"
64 #include "loadfile.inc"
65 #include "localsession.h"
66 #include "maincursor.h"
67 #include "mainerror.h"
68 #include "mainindexes.h"
70 #include "mainprogress.h"
71 #include "mainsession.h"
75 #include "mwindowgui.h"
77 #include "nestededls.h"
80 #include "playback3d.h"
81 #include "playbackengine.h"
83 #include "pluginserver.h"
84 #include "pluginset.h"
85 #include "preferences.h"
87 #include "recordmonitor.h"
88 #include "recordlabel.h"
89 #include "removefile.h"
91 #include "samplescroll.h"
93 #include "sighandler.h"
94 #include "splashgui.h"
95 #include "statusbar.h"
97 #include "threadloader.h"
99 #include "tipwindow.h"
100 #include "trackcanvas.h"
102 #include "tracking.h"
103 #include "trackscroll.h"
105 #include "transition.h"
106 #include "transportque.h"
108 #include "videodevice.inc"
109 #include "videowindow.h"
110 #include "vplayback.h"
111 #include "vwindowgui.h"
113 #include "wavecache.h"
118 #include <sys/stat.h>
127 // Hack for libdv to remove glib dependancy
130 // g_log (const char *log_domain,
132 // const char *format,
138 // g_logv (const char *log_domain,
140 // const char *format,
147 // Hack for XFree86 4.1.0
149 int atexit(void (*function)(void))
160 ArrayList<PluginServer*>* MWindow::plugindb = 0;
161 FileServer* MWindow::file_server = 0;
162 Commercials* MWindow::commercials = 0;
168 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
169 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
170 vwindows_lock = new Mutex("MWindow::vwindows_lock");
171 brender_lock = new Mutex("MWindow::brender_lock");
172 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
180 commercial_active = 0;
191 channeldb_buz = new ChannelDB;
192 channeldb_v4l2jpeg = new ChannelDB;
196 keyframe_threads = 0;
216 // Need to delete brender temporary here.
220 //printf("MWindow::~MWindow %d\n", __LINE__);
222 gui->remote_control->deactivate();
224 gui->channel_info->stop();
225 brender_lock->lock("MWindow::quit");
226 delete brender; brender = 0;
227 brender_lock->unlock();
228 delete create_bd; create_bd = 0;
229 delete create_dvd; create_dvd = 0;
230 delete batch_render; batch_render = 0;
232 if( commercials && !commercials->remove_user() ) commercials = 0;
234 // Save defaults for open plugins
235 plugin_gui_lock->lock("MWindow::~MWindow");
236 for(int i = 0; i < plugin_guis->size(); i++)
238 plugin_guis->get(i)->hide_gui();
240 plugin_gui_lock->unlock();
241 hide_keyframe_guis();
244 // Give up and go to a movie
245 // cant run valgrind if this is used
246 // if( !reload_status ) exit(0);
248 gui->del_keyboard_listener(
249 (int (BC_WindowBase::*)(BC_WindowBase *))
250 &MWindowGUI::keyboard_listener);
252 // release the hounds
253 if( awindow && awindow->gui ) awindow->gui->close(0);
254 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
255 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
256 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
257 if( twindow && twindow->is_running() ) twindow->close_window();
258 if( wwindow && wwindow->is_running() ) wwindow->close_window();
259 vwindows.remove_all_objects();
261 if( awindow ) awindow->join();
262 if( cwindow ) cwindow->join();
263 if( lwindow ) lwindow->join();
264 if( twindow ) twindow->join();
265 if( wwindow ) wwindow->join();
266 if( gwindow ) gwindow->join();
269 // one at a time, or nouveau chokes
270 #define close_gui(win) if( win ) { \
271 if( win->gui ) win->gui->close(0); \
279 vwindows.remove_all_objects();
285 dead_plugins->remove_all();
287 keyframe_threads->remove_all_objects();
288 if( !edl->Garbage::remove_user() ) edl = 0;
289 colormodels.remove_all_objects();
291 delete render; render = 0;
292 delete awindow; awindow = 0;
293 delete lwindow; lwindow = 0;
294 delete twindow; twindow = 0;
295 delete wwindow; wwindow = 0;
296 delete gwindow; gwindow = 0;
297 // must be last or nouveau chokes
298 delete cwindow; cwindow = 0;
299 //delete file_server; file_server = 0; // reusable
300 delete mainindexes; mainindexes = 0;
301 delete mainprogress; mainprogress = 0;
302 delete audio_cache; audio_cache = 0; // delete the cache after the assets
303 delete video_cache; video_cache = 0; // delete the cache after the assets
304 delete frame_cache; frame_cache = 0;
305 delete wave_cache; wave_cache = 0;
306 delete plugin_guis; plugin_guis = 0;
307 delete dead_plugins; dead_plugins = 0;
308 delete keyframe_threads; keyframe_threads = 0;
309 delete undo; undo = 0;
310 delete preferences; preferences = 0;
311 delete session; session = 0;
312 delete defaults; defaults = 0;
313 delete assets; assets = 0;
314 delete splash_window; splash_window = 0;
315 delete theme; theme = 0;
316 delete channeldb_buz;
317 delete channeldb_v4l2jpeg;
318 // This must be last thread to exit
319 delete playback_3d; playback_3d = 0;
320 delete dead_plugin_lock;
321 delete plugin_gui_lock;
322 delete vwindows_lock;
324 delete keyframe_gui_lock;
325 sighandler->terminate();
330 void MWindow::quit(int unlock)
333 if(unlock) gui->unlock_window();
335 brender_lock->lock("MWindow::quit");
336 delete brender; brender = 0;
337 brender_lock->unlock();
343 if(unlock) gui->lock_window("MWindow::quit");
346 void MWindow::init_error()
348 MainError::init_error(this);
351 void MWindow::finit_error()
353 MainError::finit_error();
356 void MWindow::create_defaults_path(char *string, const char *config_file)
358 // set the .bcast path
361 sprintf(string, "%s", BCASTDIR);
362 fs.complete_path(string);
363 if(!fs.is_dir(string))
364 fs.create_dir(string);
367 strcat(string, config_file);
370 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
372 char path[BCTEXTLEN];
373 // Use user supplied path
375 strcpy(path, config_path);
377 create_defaults_path(path, CONFIG_FILE);
379 defaults = new BC_Hash(path);
383 int MWindow::load_plugin_index(MWindow *mwindow, char *path)
386 FILE *fp = fopen(path, "r");
388 char index_line[BCTEXTLEN];
389 int index_version = -1, ret = 0;
390 if( !fgets(index_line, BCTEXTLEN, fp) ||
391 sscanf(index_line, "%d", &index_version) != 1 ||
392 index_version != PLUGIN_FILE_VERSION ) ret = 1;
394 while( !ret && !feof(fp)) {
395 char *sp = index_line, *plugin_path = 0, *plugin_title = 0;
396 if( fgets(sp, BCTEXTLEN, fp) ) {
397 plugin_path = PluginServer::table_quoted_field(sp);
398 if( plugin_exists(plugin_path) ) continue;
399 plugin_title = PluginServer::table_quoted_field(sp);
401 if( plugin_path && plugin_title ) {
402 // Create plugin server from index entry
403 PluginServer *new_plugin = new PluginServer(path, mwindow);
404 new_plugin->set_path(plugin_path);
405 new_plugin->set_title(plugin_title);
406 if( new_plugin->read_table(sp) ) {
410 plugindb->append(new_plugin);
418 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
419 const char *plug_dir, const char *plug_path, int &idx)
421 char plugin_path[BCTEXTLEN];
422 if( *plug_path != '/' )
423 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
425 strcpy(plugin_path, plug_path);
427 fs.set_filter( "[*.plugin][*.so]" );
428 int result = fs.update(plugin_path);
429 if( result || !fs.dir_list.total ) return;
432 for( int i=0; i<fs.dir_list.total; ++i ) {
433 char *fs_path = fs.dir_list.values[i]->path;
434 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
435 const char *dp = plug_dir;
436 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
437 strcpy(plugin_path, !*dp && *bp == '/' ? bp+1 : base_path);
439 if( fs.is_dir(fs_path) ) {
440 init_plugin_index(mwindow, preferences, fp, plug_dir, plugin_path, idx);
443 if( plugin_exists(plugin_path) ) continue;
444 PluginServer *new_plugin = new PluginServer(plugin_path, mwindow);
445 result = new_plugin->open_plugin(1, preferences, 0, 0);
447 new_plugin->write_table(fp,vis_id);
448 new_plugin->close_plugin();
449 new_plugin->delete_this();
452 if( result != PLUGINSERVER_IS_LAD ) continue;
455 PluginServer *new_plugin = new PluginServer(plugin_path, mwindow);
456 new_plugin->set_lad_index(lad_index++);
457 result = new_plugin->open_plugin(1, preferences, 0, 0);
459 new_plugin->write_table(fp,vis_id);
460 new_plugin->close_plugin();
461 new_plugin->delete_this();
466 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
468 if( !plugindb ) plugindb = new ArrayList<PluginServer*>;
469 char index_path[BCTEXTLEN];
470 sprintf(index_path, "%s/%s", preferences->plugin_dir, PLUGIN_FILE);
471 if( !load_plugin_index(mwindow, index_path) ) return 1;
472 FILE *fp = fopen(index_path,"w");
474 fprintf(stderr,_("MWindow::init_plugins: "
475 "can't create plugin index: %s\n"), index_path);
478 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
479 char *plug_path = FileSystem::basepath(preferences->plugin_dir);
481 init_plugin_index(mwindow, preferences, fp, plug_path, ".", dir_id);
484 return load_plugin_index(mwindow, index_path);
487 void MWindow::delete_plugins()
489 plugindb->remove_all_objects();
494 void MWindow::search_plugindb(int do_audio,
499 ArrayList<PluginServer*> &results)
502 for(int i = 0; i < MWindow::plugindb->total; i++)
504 PluginServer *current = MWindow::plugindb->values[i];
506 if(current->audio == do_audio &&
507 current->video == do_video &&
508 (current->realtime == is_realtime || is_realtime < 0) &&
509 current->transition == is_transition &&
510 current->theme == is_theme)
511 results.append(current);
514 // Alphabetize list by title
520 for(int i = 0; i < results.total - 1; i++)
522 PluginServer *value1 = results.values[i];
523 PluginServer *value2 = results.values[i + 1];
524 if(strcmp(_(value1->title), _(value2->title)) > 0)
527 results.values[i] = value2;
528 results.values[i + 1] = value1;
534 PluginServer* MWindow::scan_plugindb(char *title,
539 // printf("MWindow::scan_plugindb data_type < 0\n");
543 for(int i = 0; i < plugindb->total; i++)
545 PluginServer *server = plugindb->values[i];
547 !strcasecmp(server->title, title) &&
549 (data_type == TRACK_AUDIO && server->audio) ||
550 (data_type == TRACK_VIDEO && server->video)))
551 return plugindb->values[i];
556 int MWindow::plugin_exists(char *plugin_path)
558 for( int i=0; i<plugindb->total; ++i ) {
559 PluginServer *server = plugindb->values[i];
560 if( !strcmp(plugin_path, server->get_path()) ) return 1;
565 void MWindow::init_preferences()
567 preferences = new Preferences;
568 preferences->load_defaults(defaults);
569 session = new MainSession(this);
570 session->load_defaults(defaults);
571 // set x11_host, screens, window_config
572 screens = session->set_default_x11_host();
573 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
574 BC_Signals::set_trap_hook(trap_hook, this);
575 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
576 BC_Signals::set_catch_intr(preferences->trap_sigintr);
579 void MWindow::clean_indexes()
584 int oldest_item = -1;
586 char string[BCTEXTLEN];
587 char string2[BCTEXTLEN];
589 // Delete extra indexes
590 fs.set_filter("*.idx");
591 fs.complete_path(preferences->index_directory);
592 fs.update(preferences->index_directory);
593 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
595 // Eliminate directories
600 for(int i = 0; i < fs.dir_list.total && !result; i++)
602 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
603 if(fs.is_dir(string))
605 delete fs.dir_list.values[i];
606 fs.dir_list.remove_number(i);
611 total_excess = fs.dir_list.total - preferences->index_count;
613 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
614 while(total_excess > 0)
617 for(int i = 0; i < fs.dir_list.total; i++)
619 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
621 if(i == 0 || fs.get_date(string) <= oldest)
623 oldest = fs.get_date(string);
631 fs.join_names(string,
632 preferences->index_directory,
633 fs.dir_list.values[oldest_item]->name);
634 //printf("MWindow::clean_indexes 1 %s\n", string);
636 perror("delete_indexes");
637 delete fs.dir_list.values[oldest_item];
638 fs.dir_list.remove_number(oldest_item);
640 // Remove table of contents if it exists
641 strcpy(string2, string);
642 char *ptr = strrchr(string2, '.');
645 //printf("MWindow::clean_indexes 2 %s\n", string2);
646 sprintf(ptr, ".toc");
648 sprintf(ptr, ".mkr");
657 void MWindow::init_awindow()
659 awindow = new AWindow(this);
660 awindow->create_objects();
663 void MWindow::init_gwindow()
665 gwindow = new GWindow(this);
666 gwindow->create_objects();
669 void MWindow::init_tipwindow()
672 twindow = new TipWindow(this);
676 void MWindow::show_warning(int *do_warning, const char *text)
678 if( do_warning && !*do_warning ) return;
680 wwindow = new WWindow(this);
681 wwindow->show_warning(do_warning, text);
684 void MWindow::init_theme()
689 // Replace blond theme with SUV since it doesn't work
690 if(!strcasecmp(preferences->theme, "Blond"))
691 strcpy(preferences->theme, DEFAULT_THEME);
693 PluginServer *theme_plugin = 0;
694 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
695 if( plugindb->values[i]->theme &&
696 !strcasecmp(preferences->theme, plugindb->values[i]->title) )
697 theme_plugin = plugindb->values[i];
701 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
704 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
705 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
707 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
708 if( plugindb->values[i]->theme &&
709 !strcasecmp(DEFAULT_THEME, plugindb->values[i]->title) )
710 theme_plugin = plugindb->values[i];
715 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
719 PluginServer plugin = *theme_plugin;
720 if( plugin.open_plugin(0, preferences, 0, 0) ) {
721 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
722 theme_plugin->title);
726 theme = plugin.new_theme();
727 theme->mwindow = this;
728 strcpy(theme->path, plugin.path);
729 plugin.close_plugin();
731 // Load default images & settings
732 theme->Theme::initialize();
733 // Load user images & settings
735 // Create menus with user colors
736 theme->build_menus();
741 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
744 void MWindow::init_3d()
746 playback_3d = new Playback3D(this);
747 playback_3d->create_objects();
750 void MWindow::init_edl()
753 edl->create_objects();
754 edl->load_defaults(defaults);
755 edl->create_default_tracks();
756 edl->tracks->update_y_pixels(theme);
759 void MWindow::init_compositor()
761 cwindow = new CWindow(this);
762 cwindow->create_objects();
765 void MWindow::init_levelwindow()
767 lwindow = new LevelWindow(this);
768 lwindow->create_objects();
771 VWindow *MWindow::get_viewer(int start_it, int idx)
773 vwindows_lock->lock("MWindow::get_viewer");
774 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows.get(idx) : 0;
775 if( !vwindow ) idx = vwindows.size();
776 while( !vwindow && --idx >= 0 ) {
777 VWindow *vwin = vwindows.get(idx);
778 if( !vwin->is_running() || !vwin->get_edl() )
782 vwindow = new VWindow(this);
783 vwindow->load_defaults();
784 vwindow->create_objects();
785 vwindows.append(vwindow);
787 vwindows_lock->unlock();
788 if( start_it ) vwindow->start();
792 void MWindow::init_cache()
794 audio_cache = new CICache(preferences);
795 video_cache = new CICache(preferences);
796 frame_cache = new FrameCache;
797 wave_cache = new WaveCache;
800 void MWindow::init_channeldb()
802 channeldb_buz->load("channeldb_buz");
803 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
806 void MWindow::init_menus()
808 char string[BCTEXTLEN];
809 BC_CModels::to_text(string, BC_RGB888);
810 colormodels.append(new ColormodelItem(string, BC_RGB888));
811 BC_CModels::to_text(string, BC_RGBA8888);
812 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
813 // BC_CModels::to_text(string, BC_RGB161616);
814 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
815 // BC_CModels::to_text(string, BC_RGBA16161616);
816 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
817 BC_CModels::to_text(string, BC_RGB_FLOAT);
818 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
819 BC_CModels::to_text(string, BC_RGBA_FLOAT);
820 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
821 BC_CModels::to_text(string, BC_YUV888);
822 colormodels.append(new ColormodelItem(string, BC_YUV888));
823 BC_CModels::to_text(string, BC_YUVA8888);
824 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
825 // BC_CModels::to_text(string, BC_YUV161616);
826 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
827 // BC_CModels::to_text(string, BC_YUVA16161616);
828 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
831 void MWindow::init_indexes()
833 mainindexes = new MainIndexes(this);
834 mainindexes->start_loop();
837 void MWindow::init_gui()
839 gui = new MWindowGUI(this);
840 gui->lock_window("MWindow::init_gui");
841 gui->create_objects();
842 gui->unlock_window();
843 gui->load_defaults(defaults);
846 void MWindow::init_signals()
848 sighandler = new SigHandler;
849 sighandler->initialize();
853 void MWindow::init_render()
855 render = new Render(this);
856 create_bd = new CreateBD_Thread(this);
857 create_dvd = new CreateDVD_Thread(this);
858 batch_render = new BatchRenderThread(this);
861 void MWindow::init_brender()
863 if(preferences->use_brender && !brender)
865 brender_lock->lock("MWindow::init_brender 1");
866 brender = new BRender(this);
867 brender->initialize();
868 session->brender_end = 0;
869 brender_lock->unlock();
872 if(!preferences->use_brender && brender)
874 brender_lock->lock("MWindow::init_brender 2");
877 session->brender_end = 0;
878 brender_lock->unlock();
880 if(brender) brender->restart(edl);
883 void MWindow::restart_brender()
885 //printf("MWindow::restart_brender 1\n");
886 if(brender) brender->restart(edl);
889 void MWindow::stop_brender()
891 if(brender) brender->stop();
894 int MWindow::brender_available(int position)
897 brender_lock->lock("MWindow::brender_available 1");
900 if(brender->map_valid)
902 brender->map_lock->lock("MWindow::brender_available 2");
903 if(position < brender->map_size &&
906 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
907 if(brender->map[position] == BRender::RENDERED)
910 brender->map_lock->unlock();
913 brender_lock->unlock();
917 void MWindow::set_brender_start()
919 edl->session->brender_start = edl->local_session->get_selectionstart(1);
921 gui->draw_overlays(1);
925 int MWindow::has_commercials()
927 return theme->use_commercials;
930 void MWindow::init_commercials()
933 commercials = new Commercials(this);
934 commercial_active = 0;
937 commercials->add_user();
940 void MWindow::commit_commercial()
942 if( !commercial_active ) return;
943 commercial_active = 0;
944 if( !commercials ) return;
945 commercials->commitDb();
948 void MWindow::undo_commercial()
950 if( !commercial_active ) return;
951 commercial_active = 0;
952 if( !commercials ) return;
953 commercials->undoDb();
956 int MWindow::put_commercial()
958 double start = edl->local_session->get_selectionstart();
959 double end = edl->local_session->get_selectionend();
960 if( start >= end ) return 0;
962 const char *errmsg = 0;
964 Tracks *tracks = edl->tracks;
967 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
968 if( track->data_type != TRACK_VIDEO ) continue;
969 if( !track->record ) continue;
970 if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
972 int64_t units_start = track->to_units(start,0);
973 int64_t units_end = track->to_units(end,0);
974 Edits *edits = track->edits;
975 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
976 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
977 if(!edit1 && !edit2) continue; // nothing selected
978 if(!edit2) { // edit2 beyond end of track
980 units_end = edits->length();
982 if(edit1 != edit2) { errmsg = _("crosses edits"); break; }
983 Indexable *indexable = edit1->get_source();
984 if( !indexable->is_asset ) { errmsg = _("not asset"); break; }
987 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
988 if( track->data_type != TRACK_VIDEO ) continue;
989 if( !track->record ) continue;
990 int64_t units_start = track->to_units(start,0);
991 int64_t units_end = track->to_units(end,0);
992 Edits *edits = track->edits;
993 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
994 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
995 if(!edit1 && !edit2) continue; // nothing selected
996 if(!edit2) { // edit2 beyond end of track
998 units_end = edits->length();
1000 Indexable *indexable = edit1->get_source();
1001 Asset *asset = (Asset *)indexable;
1002 File *file = video_cache->check_out(asset, edl);
1003 if( !file ) { errmsg = _("no file"); break; }
1004 int64_t edit_length = units_end - units_start;
1005 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
1006 result = commercials->put_clip(file, edit1->channel,
1007 track->from_units(edit_start), track->from_units(edit_length));
1008 video_cache->check_in(asset);
1009 if( result ) { errmsg = _("db failed"); break; }
1012 char string[BCTEXTLEN];
1013 sprintf(string, _("put_commercial: %s"), errmsg);
1014 MainError::show_error(string);
1021 void MWindow::stop_playback(int wait)
1023 int locked = gui->get_window_lock();
1024 if( locked ) gui->unlock_window();
1026 cwindow->playback_engine->que->send_command(STOP,
1030 cwindow->playback_engine->interrupt_playback(wait);
1032 for(int i = 0; i < vwindows.size(); i++) {
1033 VWindow *vwindow = vwindows.get(i);
1034 if( !vwindow->is_running() ) continue;
1035 vwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
1036 vwindow->playback_engine->interrupt_playback(wait);
1038 if( locked ) gui->lock_window("MWindow::stop_playback");
1041 int MWindow::load_filenames(ArrayList<char*> *filenames,
1043 int update_filename)
1045 ArrayList<EDL*> new_edls;
1046 ArrayList<Asset*> new_assets;
1047 ArrayList<File*> new_files;
1048 const int debug = 0;
1049 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1052 gui->start_hourglass();
1054 // Need to stop playback since tracking depends on the EDL not getting
1058 undo->update_undo_before();
1061 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1063 // Define new_edls and new_assets to load
1064 int result = 0, ftype = -1;
1065 for(int i = 0; i < filenames->total; i++)
1068 File *new_file = new File;
1069 Asset *new_asset = new Asset(filenames->values[i]);
1070 EDL *new_edl = new EDL;
1071 char string[BCTEXTLEN];
1073 new_edl->create_objects();
1074 new_edl->copy_session(edl);
1075 new_file->set_program(edl->session->program_no);
1077 sprintf(string, _("Loading %s"), new_asset->path);
1078 gui->show_message(string);
1079 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1081 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1082 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1087 // Convert media file to EDL
1089 // Warn about odd image dimensions
1090 if(new_asset->video_data &&
1091 ((new_asset->width % 2) ||
1092 (new_asset->height % 2)))
1094 char string[BCTEXTLEN];
1095 sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
1099 MainError::show_error(string);
1102 if(new_asset->program >= 0 &&
1103 edl->session->program_no != new_asset->program)
1105 char string[BCTEXTLEN];
1106 sprintf(string, _("%s's index was built for program number %d\n"
1107 "Playback preference is %d.\n Using program %d."),
1108 new_asset->path, new_asset->program,
1109 edl->session->program_no, new_asset->program);
1110 MainError::show_error(string);
1114 if(load_mode != LOADMODE_RESOURCESONLY)
1117 RecordLabels *labels = edl->session->label_cells ?
1118 new RecordLabels(new_file) : 0;
1120 asset_to_edl(new_edl, new_asset, labels);
1122 new_edls.append(new_edl);
1124 new_asset->Garbage::remove_user();
1130 new_assets.append(new_asset);
1134 // Set filename to nothing for assets since save EDL would overwrite them.
1135 if(load_mode == LOADMODE_REPLACE ||
1136 load_mode == LOADMODE_REPLACE_CONCATENATE)
1139 // Reset timeline position
1140 for(int i = 0; i < TOTAL_PANES; i++)
1142 new_edl->local_session->view_start[i] = 0;
1143 new_edl->local_session->track_start[i] = 0;
1151 case FILE_NOT_FOUND:
1152 sprintf(string, _("Failed to open %s"), new_asset->path);
1153 gui->show_message(string, theme->message_error);
1157 case FILE_UNRECOGNIZED_CODEC:
1160 IndexFile indexfile(this, new_asset);
1161 result = indexfile.open_index();
1164 indexfile.close_index();
1167 // Test existing EDLs
1170 for(int j = 0; j < new_edls.total + 1; j++)
1173 if(j == new_edls.total)
1175 old_asset = edl->assets->get_asset(new_asset->path);
1178 *new_asset = *old_asset;
1184 old_asset = new_edls.values[j]->assets->get_asset(new_asset->path);
1187 *new_asset = *old_asset;
1197 char string[BCTEXTLEN];
1199 fs.extract_name(string, new_asset->path);
1201 strcat(string, _("'s format couldn't be determined."));
1202 new_asset->audio_data = 1;
1203 new_asset->format = FILE_PCM;
1204 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1205 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1206 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1207 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1208 new_asset->signed_ = defaults->get("SIGNED_", 1);
1209 new_asset->header = defaults->get("HEADER", 0);
1211 FileFormat fwindow(this);
1212 fwindow.create_objects(new_asset, string);
1213 result = fwindow.run_window();
1216 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1217 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1218 defaults->update("AUDIO_BITS", new_asset->bits);
1219 defaults->update("BYTE_ORDER", new_asset->byte_order);
1220 defaults->update("SIGNED_", new_asset->signed_);
1221 defaults->update("HEADER", new_asset->header);
1228 // Recalculate length
1230 new_file = new File;
1231 result = new_file->open_file(preferences, new_asset, 1, 0);
1233 if(load_mode != LOADMODE_RESOURCESONLY)
1235 RecordLabels *labels = edl->session->label_cells ?
1236 new RecordLabels(new_file) : 0;
1237 asset_to_edl(new_edl, new_asset, labels);
1238 new_edls.append(new_edl);
1239 new_asset->Garbage::remove_user();
1245 new_assets.append(new_asset);
1259 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1260 xml_file.read_from_file(filenames->values[i]);
1261 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1263 if(load_mode == LOADMODE_NESTED)
1265 // Load temporary EDL for nesting.
1266 EDL *nested_edl = new EDL;
1267 nested_edl->create_objects();
1268 nested_edl->set_path(filenames->values[i]);
1269 nested_edl->load_xml(&xml_file, LOAD_ALL);
1270 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1271 edl_to_nested(new_edl, nested_edl);
1272 nested_edl->Garbage::remove_user();
1276 // Load EDL for pasting
1277 new_edl->load_xml(&xml_file, LOAD_ALL);
1278 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1279 test_plugins(new_edl, filenames->values[i]);
1280 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1282 if(load_mode == LOADMODE_REPLACE ||
1283 load_mode == LOADMODE_REPLACE_CONCATENATE)
1285 strcpy(session->filename, filenames->values[i]);
1286 strcpy(new_edl->local_session->clip_title,
1287 filenames->values[i]);
1289 set_filename(new_edl->local_session->clip_title);
1293 new_edls.append(new_edl);
1299 // edls are in new_edls
1300 if( result && new_edl ) new_edl->Garbage::remove_user();
1301 // assets are copied
1302 if( new_asset ) new_asset->Garbage::remove_user();
1304 // Store for testing index
1305 new_files.append(new_file);
1308 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1311 if(!result) gui->statusbar->default_message();
1319 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1322 // Don't back up here.
1325 // For pasting, clear the active region
1326 if(load_mode == LOADMODE_PASTE ||
1327 load_mode == LOADMODE_NESTED)
1329 double start = edl->local_session->get_selectionstart();
1330 double end = edl->local_session->get_selectionend();
1331 if(!EQUIV(start, end))
1334 edl->session->labels_follow_edits,
1335 edl->session->plugins_follow_edits,
1336 edl->session->autos_follow_edits);
1339 paste_edls(&new_edls,
1343 edl->session->labels_follow_edits,
1344 edl->session->plugins_follow_edits,
1345 edl->session->autos_follow_edits);
1351 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1353 // Add new assets to EDL and schedule assets for index building.
1354 int got_indexes = 0;
1355 for(int i = 0; i < new_edls.size(); i++)
1357 EDL *new_edl = new_edls.get(i);
1358 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1360 mainindexes->add_next_asset(0,
1361 new_edl->nested_edls->get(j));
1363 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1368 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1369 if(new_assets.size())
1371 for(int i = 0; i < new_assets.size(); i++)
1373 Asset *new_asset = new_assets.get(i);
1377 for(int j = 0; j < new_files.size(); j++)
1379 new_file = new_files.get(j);
1380 if(!strcmp(new_file->asset->path,
1388 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1390 edl->assets->update(new_asset);
1396 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1398 // Start examining next batch of index files
1399 if(got_indexes) mainindexes->start_build();
1400 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1403 Track *track = edl->tracks->first;
1406 for(int j = 0; j < track->plugin_set.size(); j++)
1408 PluginSet *plugins = track->plugin_set.get(j);
1409 Plugin *plugin = plugins->get_first_plugin();
1413 if(load_mode == LOADMODE_REPLACE ||
1414 load_mode == LOADMODE_REPLACE_CONCATENATE)
1416 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1419 show_plugin(plugin);
1427 plugin = (Plugin*)plugin->next;
1431 track = track->next;
1434 // if just opening one new resource in replace mode
1435 if( load_mode == LOADMODE_REPLACE && new_edls.size() == 1 &&
1436 ftype != FILE_IS_XML )
1439 edl->local_session->preview_start = 0;
1440 edl->local_session->preview_end = edl->tracks->total_playable_length();
1441 edl->local_session->loop_playback = 0;
1442 edl->local_session->set_selectionstart(0);
1443 edl->local_session->set_selectionend(0);
1449 update_project(load_mode);
1451 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1453 for(int i = 0; i < new_edls.size(); i++)
1455 new_edls.get(i)->remove_user();
1457 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1459 new_edls.remove_all();
1461 for(int i = 0; i < new_assets.size(); i++)
1463 new_assets.get(i)->Garbage::remove_user();
1466 new_assets.remove_all();
1467 new_files.remove_all_objects();
1469 undo->update_undo_after(_("load"), LOAD_ALL);
1471 if(load_mode == LOADMODE_REPLACE ||
1472 load_mode == LOADMODE_REPLACE_CONCATENATE)
1474 session->changes_made = 0;
1478 session->changes_made = 1;
1481 gui->stop_hourglass();
1484 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1491 void MWindow::test_plugins(EDL *new_edl, char *path)
1493 char string[BCTEXTLEN];
1495 // Do a check weather plugins exist
1496 for(Track *track = new_edl->tracks->first; track; track = track->next)
1498 for(int k = 0; k < track->plugin_set.total; k++)
1500 PluginSet *plugin_set = track->plugin_set.values[k];
1501 for(Plugin *plugin = (Plugin*)plugin_set->first;
1503 plugin = (Plugin*)plugin->next)
1505 if(plugin->plugin_type == PLUGIN_STANDALONE)
1507 // ok we need to find it in plugindb
1508 int plugin_found = 0;
1510 for(int j = 0; j < plugindb->size(); j++)
1512 PluginServer *server = plugindb->get(j);
1514 !strcasecmp(server->title, plugin->title) &&
1515 ((track->data_type == TRACK_AUDIO && server->audio) ||
1516 (track->data_type == TRACK_VIDEO && server->video)) &&
1517 (!server->transition))
1524 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1525 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1526 "effect", plugin->title,
1528 MainError::show_error(string);
1534 for(Edit *edit = (Edit*)track->edits->first;
1536 edit = (Edit*)edit->next)
1538 if (edit->transition)
1540 // ok we need to find transition in plugindb
1542 int transition_found = 0;
1543 for(int j = 0; j < plugindb->size(); j++)
1545 PluginServer *server = plugindb->get(j);
1547 !strcasecmp(server->title, edit->transition->title) &&
1548 ((track->data_type == TRACK_AUDIO && server->audio) ||
1549 (track->data_type == TRACK_VIDEO && server->video)) &&
1550 (server->transition))
1551 transition_found = 1;
1554 if (!transition_found)
1557 _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1558 "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
1559 "transition", edit->transition->title,
1561 MainError::show_error(string);
1569 void MWindow::init_shm()
1571 // Fix shared memory
1572 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1574 fprintf(fd, "0x7fffffff");
1579 fd = fopen("/proc/sys/kernel/shmmax", "r");
1581 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1586 fscanf(fd, _LD, &result);
1589 if(result < 0x7fffffff) {
1590 char string[BCTEXTLEN];
1591 sprintf(string, _("MWindow::init_shm: /proc/sys/kernel/shmmax is 0x" _LX ".\n"
1592 "you probably need to be root, or:\n"
1593 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1594 "before trying to start cinelerra.\n"
1595 "It should be at least 0x7fffffff for Cinelerra.\n"), result);
1596 MainError::show_error(string);
1601 void MWindow::init_fileserver(Preferences *preferences)
1604 if( !file_server && preferences->file_forking ) {
1605 file_server = new FileServer(preferences);
1606 file_server->start();
1611 void MWindow::create_objects(int want_gui,
1616 const int debug = 0;
1617 if(debug) PRINT_TRACE
1619 // For some reason, init_signals must come after show_splash or the signals won't
1622 if(debug) PRINT_TRACE
1625 if(debug) PRINT_TRACE
1628 if(debug) PRINT_TRACE
1629 init_defaults(defaults, config_path);
1631 init_plugins(this, preferences);
1632 if(debug) PRINT_TRACE
1633 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1634 if(debug) PRINT_TRACE
1636 if(debug) PRINT_TRACE
1639 char string[BCTEXTLEN];
1640 strcpy(string, preferences->plugin_dir);
1641 strcat(string, "/fonts");
1642 BC_Resources::init_fontconfig(string);
1643 if(debug) PRINT_TRACE
1645 // Initialize before too much else is running
1646 // Preferences & theme are required for building MPEG table of contents
1647 init_fileserver(preferences);
1649 // Default project created here
1651 if(debug) PRINT_TRACE
1654 if(debug) PRINT_TRACE
1659 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1661 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1662 if(session->show_vwindow)
1663 get_viewer(1, DEFAULT_VWINDOW);
1664 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1667 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());
1675 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1678 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1682 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1684 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1686 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1689 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1690 mainprogress = new MainProgress(this, gui);
1691 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1692 undo = new MainUndo(this);
1694 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1696 plugin_guis = new ArrayList<PluginServer*>;
1697 dead_plugins = new ArrayList<PluginServer*>;
1698 keyframe_threads = new ArrayList<KeyFrameThread*>;
1700 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1703 session->show_vwindow);
1705 // Show all vwindows
1706 // if(session->show_vwindow) {
1707 // for(int j = 0; j < vwindows.size(); j++) {
1708 // VWindow *vwindow = vwindows.get(j);
1709 // if( !vwindow->is_running() ) continue;
1710 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1713 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1714 // vwindow->gui->lock_window("MWindow::create_objects 1");
1715 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1716 // vwindow->gui->show_window();
1717 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1718 // vwindow->gui->unlock_window();
1723 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1725 if(session->show_cwindow)
1727 cwindow->gui->lock_window("MWindow::create_objects 1");
1728 cwindow->gui->show_window();
1729 cwindow->gui->unlock_window();
1732 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1733 if(session->show_awindow)
1735 awindow->gui->lock_window("MWindow::create_objects 1");
1736 awindow->gui->show_window();
1737 awindow->gui->unlock_window();
1740 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1741 if(session->show_lwindow)
1743 lwindow->gui->lock_window("MWindow::create_objects 1");
1744 lwindow->gui->show_window();
1745 lwindow->gui->unlock_window();
1748 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1750 (int)timer.get_difference(),
1752 if(session->show_gwindow)
1754 gwindow->gui->lock_window("MWindow::create_objects 1");
1755 gwindow->gui->show_window();
1756 gwindow->gui->unlock_window();
1759 if(debug) PRINT_TRACE
1761 gui->lock_window("MWindow::create_objects 1");
1762 gui->mainmenu->load_defaults(defaults);
1763 gui->mainmenu->update_toggles(0);
1764 gui->update_patchbay();
1765 gui->draw_canvas(0, 0);
1766 gui->draw_cursor(1);
1768 gui->raise_window();
1769 gui->unlock_window();
1771 if(debug) PRINT_TRACE
1775 if(preferences->use_tipwindow)
1777 if(debug) PRINT_TRACE
1779 gui->add_keyboard_listener(
1780 (int (BC_WindowBase::*)(BC_WindowBase *))
1781 &MWindowGUI::keyboard_listener);
1785 if(debug) PRINT_TRACE
1787 BC_WindowBase::get_resources()->vframe_shm = 1;
1792 void MWindow::show_splash()
1794 #include "data/heroine_logo11_png.h"
1795 VFrame *frame = new VFrame(heroine_logo11_png);
1796 BC_DisplayInfo display_info;
1797 splash_window = new SplashGUI(frame,
1798 display_info.get_root_w() / 2 - frame->get_w() / 2,
1799 display_info.get_root_h() / 2 - frame->get_h() / 2);
1800 splash_window->create_objects();
1803 void MWindow::hide_splash()
1806 delete splash_window;
1811 void MWindow::start()
1815 // vwindows.get(DEFAULT_VWINDOW)->start();
1826 playback_3d->start();
1835 void MWindow::show_vwindow()
1837 int total_running = 0;
1838 session->show_vwindow = 1;
1840 // Raise all windows which are visible
1841 for(int j = 0; j < vwindows.size(); j++) {
1842 VWindow *vwindow = vwindows.get(j);
1843 if( !vwindow->is_running() ) continue;
1844 vwindow->gui->lock_window("MWindow::show_vwindow");
1845 vwindow->gui->show_window(0);
1846 vwindow->gui->raise_window();
1847 vwindow->gui->flush();
1848 vwindow->gui->unlock_window();
1852 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
1853 // If no windows visible
1856 get_viewer(1, DEFAULT_VWINDOW);
1859 gui->mainmenu->show_vwindow->set_checked(1);
1862 void MWindow::show_awindow()
1864 session->show_awindow = 1;
1865 awindow->gui->lock_window("MWindow::show_awindow");
1866 awindow->gui->show_window();
1867 awindow->gui->raise_window();
1868 awindow->gui->flush();
1869 awindow->gui->unlock_window();
1870 gui->mainmenu->show_awindow->set_checked(1);
1873 char *MWindow::get_cwindow_display()
1875 char *x11_host = screens < 2 || session->window_config == 0 ?
1876 session->a_x11_host : session->b_x11_host;
1877 return *x11_host ? x11_host : 0;
1880 void MWindow::show_cwindow()
1882 session->show_cwindow = 1;
1883 cwindow->show_window();
1884 gui->mainmenu->show_cwindow->set_checked(1);
1887 void MWindow::show_gwindow()
1889 session->show_gwindow = 1;
1891 gwindow->gui->lock_window("MWindow::show_gwindow");
1892 gwindow->gui->show_window();
1893 gwindow->gui->raise_window();
1894 gwindow->gui->flush();
1895 gwindow->gui->unlock_window();
1897 gui->mainmenu->show_gwindow->set_checked(1);
1900 void MWindow::show_lwindow()
1902 session->show_lwindow = 1;
1903 lwindow->gui->lock_window("MWindow::show_lwindow");
1904 lwindow->gui->show_window();
1905 lwindow->gui->raise_window();
1906 lwindow->gui->flush();
1907 lwindow->gui->unlock_window();
1908 gui->mainmenu->show_lwindow->set_checked(1);
1911 int MWindow::tile_windows(int window_config)
1913 int need_reload = 0;
1914 int play_config = window_config==0 ? 0 : 1;
1915 edl->session->playback_config->load_defaults(defaults, play_config);
1916 session->default_window_positions(window_config);
1917 if( screens == 1 ) {
1918 gui->default_positions();
1919 sync_parameters(CHANGE_ALL);
1926 void MWindow::toggle_loop_playback()
1928 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1929 set_loop_boundaries();
1932 gui->draw_overlays(1);
1933 sync_parameters(CHANGE_PARAMS);
1936 //void MWindow::set_titles(int value)
1938 // edl->session->show_titles = value;
1939 // trackmovement(edl->local_session->track_start);
1942 void MWindow::set_screens(int value)
1947 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
1949 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
1950 edl->session->auto_keyframes = value;
1951 gui->mbuttons->edit_panel->keyframe->update(value);
1953 if(lock_mwindow) gui->unlock_window();
1955 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1956 cwindow->gui->edit_panel->keyframe->update(value);
1957 cwindow->gui->flush();
1958 if(lock_cwindow) cwindow->gui->unlock_window();
1961 void MWindow::set_keyframe_type(int mode)
1963 gui->lock_window("MWindow::set_keyframe_type");
1964 edl->local_session->floatauto_type = mode;
1965 gui->mainmenu->update_toggles(0);
1966 gui->unlock_window();
1969 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
1971 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
1972 edl->session->editing_mode = new_editing_mode;
1973 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1974 gui->mbuttons->edit_panel->update();
1975 gui->set_editing_mode(1);
1976 if(lock_mwindow) gui->unlock_window();
1979 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
1980 cwindow->gui->edit_panel->update();
1981 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1982 if(lock_cwindow) cwindow->gui->unlock_window();
1987 void MWindow::sync_parameters(int change_type)
1989 if( in_destructor ) return;
1991 // Sync engines which are playing back
1992 if(cwindow->playback_engine->is_playing_back)
1994 if(change_type == CHANGE_PARAMS)
1996 // TODO: block keyframes until synchronization is done
1997 cwindow->playback_engine->sync_parameters(edl);
2002 int command = cwindow->playback_engine->command->command;
2003 cwindow->playback_engine->que->send_command(STOP,
2007 // Waiting for tracking to finish would make the restart position more
2008 // accurate but it can't lock the window to stop tracking for some reason.
2009 // Not waiting for tracking gives a faster response but restart position is
2010 // only as accurate as the last tracking update.
2011 cwindow->playback_engine->interrupt_playback(0);
2012 cwindow->playback_engine->que->send_command(command,
2021 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2028 void MWindow::age_caches()
2030 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2032 // preferences->cache_size,
2033 // audio_cache->get_memory_usage(1),
2034 // video_cache->get_memory_usage(1),
2035 // frame_cache->get_memory_usage(),
2036 // wave_cache->get_memory_usage(),
2038 frame_cache->age_cache(512);
2039 wave_cache->age_cache(8192);
2041 int64_t memory_usage;
2042 int64_t prev_memory_usage = 0;
2044 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2045 while( !result && prev_memory_usage !=
2046 (memory_usage=video_cache->get_memory_usage(1)) &&
2047 memory_usage > video_size ) {
2048 video_cache->delete_oldest();
2049 prev_memory_usage = memory_usage;
2052 prev_memory_usage = 0;
2054 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2055 while( !result && prev_memory_usage !=
2056 (memory_usage=audio_cache->get_memory_usage(1)) &&
2057 memory_usage > audio_size ) {
2058 audio_cache->delete_oldest();
2059 prev_memory_usage = memory_usage;
2063 void MWindow::reset_android_remote()
2065 gui->use_android_remote(preferences->android_remote);
2069 void MWindow::show_keyframe_gui(Plugin *plugin)
2071 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2072 // Find existing thread
2073 for(int i = 0; i < keyframe_threads->size(); i++)
2075 if(keyframe_threads->get(i)->plugin == plugin)
2077 keyframe_threads->get(i)->start_window(plugin, 0);
2078 keyframe_gui_lock->unlock();
2083 // Find unused thread
2084 for(int i = 0; i < keyframe_threads->size(); i++)
2086 if(!keyframe_threads->get(i)->plugin)
2088 keyframe_threads->get(i)->start_window(plugin, 0);
2089 keyframe_gui_lock->unlock();
2094 // Create new thread
2095 KeyFrameThread *thread = new KeyFrameThread(this);
2096 keyframe_threads->append(thread);
2097 thread->start_window(plugin, 0);
2099 keyframe_gui_lock->unlock();
2106 void MWindow::show_plugin(Plugin *plugin)
2111 // Remove previously deleted plugin GUIs
2112 dead_plugin_lock->lock("MWindow::delete_plugin");
2113 for(int i = 0; i < dead_plugins->size(); i++)
2115 delete dead_plugins->get(i);
2117 dead_plugins->remove_all();
2118 dead_plugin_lock->unlock();
2120 //printf("MWindow::show_plugin %d\n", __LINE__);
2124 plugin_gui_lock->lock("MWindow::show_plugin");
2125 for(int i = 0; i < plugin_guis->total; i++)
2127 // Pointer comparison
2128 if(plugin_guis->values[i]->plugin == plugin)
2130 plugin_guis->values[i]->raise_window();
2137 //printf("MWindow::show_plugin 1\n");
2142 printf("MWindow::show_plugin track not defined.\n");
2144 PluginServer *server = scan_plugindb(plugin->title,
2145 plugin->track->data_type);
2147 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2148 if(server && server->uses_gui)
2150 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
2151 // Needs mwindow to do GUI
2152 gui->set_mwindow(this);
2153 gui->open_plugin(0, preferences, edl, plugin);
2158 plugin_gui_lock->unlock();
2159 //printf("MWindow::show_plugin %d\n", __LINE__);
2162 //printf("MWindow::show_plugin 2\n");
2165 void MWindow::hide_plugin(Plugin *plugin, int lock)
2168 // Update the toggle
2169 gui->lock_window("MWindow::hide_plugin");
2170 gui->update(0, 1, 0, 0, 0, 0, 0);
2171 gui->unlock_window();
2173 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2174 for(int i = 0; i < plugin_guis->total; i++)
2176 if(plugin_guis->values[i]->plugin == plugin)
2178 PluginServer *ptr = plugin_guis->values[i];
2179 plugin_guis->remove(ptr);
2180 if(lock) plugin_gui_lock->unlock();
2181 // Last command executed in client side close
2182 // Schedule for deletion
2189 if(lock) plugin_gui_lock->unlock();
2192 void MWindow::delete_plugin(PluginServer *plugin)
2194 dead_plugin_lock->lock("MWindow::delete_plugin");
2195 dead_plugins->append(plugin);
2196 dead_plugin_lock->unlock();
2199 void MWindow::hide_plugins()
2201 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2202 while(plugin_guis->size())
2204 PluginServer *ptr = plugin_guis->get(0);
2205 plugin_guis->remove(ptr);
2206 plugin_gui_lock->unlock();
2207 // Last command executed in client side close
2208 // Schedule for deletion
2211 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2213 plugin_gui_lock->unlock();
2215 hide_keyframe_guis();
2218 void MWindow::hide_keyframe_guis()
2220 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2221 for(int i = 0; i < keyframe_threads->size(); i++)
2223 keyframe_threads->get(i)->close_window();
2225 keyframe_gui_lock->unlock();
2228 void MWindow::hide_keyframe_gui(Plugin *plugin)
2230 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2231 for(int i = 0; i < keyframe_threads->size(); i++)
2233 if(keyframe_threads->get(i)->plugin == plugin)
2235 keyframe_threads->get(i)->close_window();
2239 keyframe_gui_lock->unlock();
2242 void MWindow::update_keyframe_guis()
2244 // Send new configuration to keyframe GUI's
2245 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2246 for(int i = 0; i < keyframe_threads->size(); i++)
2248 KeyFrameThread *ptr = keyframe_threads->get(i);
2249 if(edl->tracks->plugin_exists(ptr->plugin))
2253 ptr->close_window();
2256 keyframe_gui_lock->unlock();
2259 void MWindow::update_plugin_guis(int do_keyframe_guis)
2261 // Send new configuration to plugin GUI's
2262 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2264 for(int i = 0; i < plugin_guis->size(); i++)
2266 PluginServer *ptr = plugin_guis->get(i);
2267 if(edl->tracks->plugin_exists(ptr->plugin))
2271 // Schedule for deletion if no plugin
2272 plugin_guis->remove_number(i);
2281 // Change plugin variable if not visible
2282 Track *track = edl->tracks->first;
2285 for(int i = 0; i < track->plugin_set.size(); i++)
2287 Plugin *plugin = (Plugin*)track->plugin_set.get(i)->first;
2291 for(int i = 0; i < plugin_guis->size(); i++)
2293 PluginServer *server = plugin_guis->get(i);
2294 if(server->plugin == plugin)
2301 if(!got_it) plugin->show = 0;
2303 plugin = (Plugin*)plugin->next;
2307 track = track->next;
2310 plugin_gui_lock->unlock();
2313 if(do_keyframe_guis) update_keyframe_guis();
2316 int MWindow::plugin_gui_open(Plugin *plugin)
2319 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2320 for(int i = 0; i < plugin_guis->total; i++)
2322 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2328 plugin_gui_lock->unlock();
2332 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2334 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2335 for(int i = 0; i < plugin_guis->total; i++)
2337 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2339 plugin_guis->values[i]->render_gui(data);
2343 plugin_gui_lock->unlock();
2346 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2348 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2349 for(int i = 0; i < plugin_guis->total; i++)
2351 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2353 plugin_guis->values[i]->render_gui(data, size);
2357 plugin_gui_lock->unlock();
2361 void MWindow::update_plugin_states()
2363 plugin_gui_lock->lock("MWindow::update_plugin_states");
2364 for(int i = 0; i < plugin_guis->total; i++)
2368 Plugin *src_plugin = plugin_guis->values[i]->plugin;
2369 PluginServer *src_plugingui = plugin_guis->values[i];
2371 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2372 for(Track *track = edl->tracks->first;
2374 track = track->next)
2377 j < track->plugin_set.total && !result;
2380 PluginSet *plugin_set = track->plugin_set.values[j];
2381 for(Plugin *plugin = (Plugin*)plugin_set->first;
2383 plugin = (Plugin*)plugin->next)
2385 if(plugin == src_plugin &&
2386 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2392 // Doesn't exist anymore
2395 hide_plugin(src_plugin, 0);
2399 plugin_gui_lock->unlock();
2403 void MWindow::update_plugin_titles()
2405 for(int i = 0; i < plugin_guis->total; i++)
2407 plugin_guis->values[i]->update_title();
2411 int MWindow::asset_to_edl(EDL *new_edl,
2413 RecordLabels *labels)
2415 const int debug = 0;
2416 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2419 // Keep frame rate, sample rate, and output size unchanged.
2420 // These parameters would revert the project if VWindow displayed an asset
2421 // of different size than the project.
2422 if(new_asset->video_data)
2424 new_edl->session->video_tracks = new_asset->layers;
2427 new_edl->session->video_tracks = 0;
2429 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2435 if(new_asset->audio_data)
2437 new_edl->session->audio_tracks = new_asset->channels;
2440 new_edl->session->audio_tracks = 0;
2441 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2443 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2444 new_edl->create_default_tracks();
2445 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2446 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2450 //printf("MWindow::asset_to_edl 3\n");
2451 new_edl->insert_asset(new_asset,
2456 //printf("MWindow::asset_to_edl 3\n");
2457 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2463 char string[BCTEXTLEN];
2465 fs.extract_name(string, new_asset->path);
2466 //printf("MWindow::asset_to_edl 3\n");
2468 strcpy(new_edl->local_session->clip_title, string);
2469 //printf("MWindow::asset_to_edl 4 %s\n", string);
2470 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2475 int MWindow::edl_to_nested(EDL *new_edl,
2479 // Keep frame rate, sample rate, and output size unchanged.
2480 // These parameters would revert the project if VWindow displayed an asset
2481 // of different size than the project.
2485 // Nest all video & audio outputs
2486 new_edl->session->video_tracks = 1;
2487 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2488 new_edl->create_default_tracks();
2492 new_edl->insert_asset(0,
2498 char string[BCTEXTLEN];
2500 fs.extract_name(string, nested_edl->path);
2501 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2503 strcpy(new_edl->local_session->clip_title, string);
2508 // Reset everything after a load.
2509 void MWindow::update_project(int load_mode)
2511 const int debug = 0;
2513 if(debug) PRINT_TRACE
2515 edl->tracks->update_y_pixels(theme);
2517 if(debug) PRINT_TRACE
2519 if(load_mode == LOADMODE_REPLACE ||
2520 load_mode == LOADMODE_REPLACE_CONCATENATE)
2525 gui->update(1, 1, 1, 1, 1, 1, 1);
2526 if(debug) PRINT_TRACE
2527 gui->unlock_window();
2529 cwindow->gui->lock_window("MWindow::update_project 1");
2530 cwindow->update(0, 0, 1, 1, 1);
2531 cwindow->gui->unlock_window();
2533 if(debug) PRINT_TRACE
2535 // Close all the vwindows
2536 if(load_mode == LOADMODE_REPLACE ||
2537 load_mode == LOADMODE_REPLACE_CONCATENATE) {
2538 if(debug) PRINT_TRACE
2539 int first_vwindow = 0;
2540 if(session->show_vwindow) first_vwindow = 1;
2541 // Change visible windows to no source
2542 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++) {
2543 VWindow *vwindow = vwindows.get(i);
2544 if( !vwindow->is_running() ) continue;
2545 vwindow->change_source(-1);
2548 // Close remaining windows
2549 for(int i = first_vwindow; i < vwindows.size(); i++) {
2550 VWindow *vwindow = vwindows.get(i);
2551 if( !vwindow->is_running() ) continue;
2552 vwindow->close_window();
2554 if(debug) PRINT_TRACE
2556 else if(vwindows.size()) {
2557 VWindow *vwindow = vwindows.get(DEFAULT_VWINDOW);
2558 if( vwindow->is_running() ) {
2559 vwindow->gui->lock_window("MWindow::update_project");
2561 vwindow->gui->unlock_window();
2565 if(debug) PRINT_TRACE
2566 cwindow->gui->lock_window("MWindow::update_project 2");
2567 cwindow->gui->timebar->update(0);
2568 cwindow->gui->unlock_window();
2570 if(debug) PRINT_TRACE
2571 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2576 if(debug) PRINT_TRACE
2578 awindow->gui->lock_window("MWindow::update_project");
2579 awindow->gui->update_assets();
2580 awindow->gui->flush();
2581 awindow->gui->unlock_window();
2583 if(debug) PRINT_TRACE
2585 gui->lock_window("MWindow::update_project");
2587 if(debug) PRINT_TRACE
2590 void MWindow::remove_indexfile(Indexable *indexable)
2592 if( !indexable->is_asset ) return;
2593 Asset *asset = (Asset *)indexable;
2595 IndexFile::delete_index(preferences, asset, ".toc");
2596 IndexFile::delete_index(preferences, asset, ".idx");
2597 IndexFile::delete_index(preferences, asset, ".mkr");
2600 void MWindow::rebuild_indices()
2602 for(int i = 0; i < session->drag_assets->total; i++)
2604 Indexable *indexable = session->drag_assets->values[i];
2605 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2606 remove_indexfile(indexable);
2607 // Schedule index build
2608 IndexState *index_state = indexable->index_state;
2609 index_state->index_status = INDEX_NOTTESTED;
2610 if( indexable->is_asset ) {
2611 Asset *asset = (Asset *)indexable;
2612 if( asset->format != FILE_PCM )
2613 asset->reset_audio();
2614 asset->reset_video();
2616 mainindexes->add_next_asset(0, indexable);
2618 mainindexes->start_build();
2622 void MWindow::save_backup()
2625 edl->set_path(session->filename);
2626 edl->save_xml(&file,
2630 file.terminate_string();
2631 char path[BCTEXTLEN];
2633 strcpy(path, BACKUP_PATH);
2634 fs.complete_path(path);
2636 if(file.write_to_file(path))
2639 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2640 gui->show_message(string2);
2644 void MWindow::load_backup()
2646 ArrayList<char*> path_list;
2647 path_list.set_array_delete();
2649 char string[BCTEXTLEN];
2650 strcpy(string, BACKUP_PATH);
2652 fs.complete_path(string);
2654 path_list.append(out_path = new char[strlen(string) + 1]);
2655 strcpy(out_path, string);
2657 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2658 edl->local_session->clip_title[0] = 0;
2659 // This is unique to backups since the path of the backup is different than the
2660 // path of the project.
2661 set_filename(edl->path);
2662 path_list.remove_all_objects();
2666 static inline int gcd(int m, int n)
2669 if( m < n ) { r = m; m = n; n = r; }
2670 while( (r = m % n) != 0 ) { m = n; n = r; }
2674 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2677 if(!width || !height) return 1;
2678 double ar = (double)width / height;
2679 // square-ish pixels
2680 if( EQUIV(ar, 1.0000) ) return 0;
2681 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2682 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2683 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2684 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2685 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2686 int ww = width, hh = height;
2687 // numerator, denominator must be under mx
2688 int mx = 255, n = gcd(ww, hh);
2689 if( n > 1 ) { ww /= n; hh /= n; }
2690 // search near height in case extra/missing lines
2691 if( ww >= mx || hh >= mx ) {
2692 double err = height; // +/- 2 percent height
2693 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2694 int iw = width, ih = height+i;
2695 if( (n=gcd(iw, ih)) > 1 ) {
2696 int u = iw/n; if( u >= mx ) continue;
2697 int v = ih/n; if( v >= mx ) continue;
2698 double r = (double) u/v, er = fabs(ar-r);
2699 if( er >= err ) continue;
2700 err = er; ww = u; hh = v;
2709 void MWindow::reset_caches()
2711 frame_cache->remove_all();
2712 wave_cache->remove_all();
2713 audio_cache->remove_all();
2714 video_cache->remove_all();
2715 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2716 cwindow->playback_engine->audio_cache->remove_all();
2717 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2718 cwindow->playback_engine->video_cache->remove_all();
2720 for(int i = 0; i < vwindows.size(); i++) {
2721 VWindow *vwindow = vwindows.get(i);
2722 if( !vwindow->is_running() ) continue;
2723 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2724 vwindow->playback_engine->audio_cache->remove_all();
2725 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2726 vwindow->playback_engine->video_cache->remove_all();
2730 void MWindow::remove_asset_from_caches(Asset *asset)
2732 frame_cache->remove_asset(asset);
2733 wave_cache->remove_asset(asset);
2734 audio_cache->delete_entry(asset);
2735 video_cache->delete_entry(asset);
2736 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2737 cwindow->playback_engine->audio_cache->delete_entry(asset);
2738 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2739 cwindow->playback_engine->video_cache->delete_entry(asset);
2740 for(int i = 0; i < vwindows.size(); i++) {
2741 VWindow *vwindow = vwindows.get(i);
2742 if( !vwindow->is_running() ) continue;
2743 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2744 vwindow->playback_engine->audio_cache->delete_entry(asset);
2745 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2746 vwindow->playback_engine->video_cache->delete_entry(asset);
2752 void MWindow::remove_assets_from_project(int push_undo)
2754 for(int i = 0; i < session->drag_assets->total; i++) {
2755 Indexable *indexable = session->drag_assets->values[i];
2756 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
2759 // Remove from VWindow.
2760 for(int i = 0; i < session->drag_clips->total; i++) {
2761 for(int j = 0; j < vwindows.size(); j++) {
2762 VWindow *vwindow = vwindows.get(j);
2763 if( !vwindow->is_running() ) continue;
2764 if(session->drag_clips->values[i] == vwindow->get_edl()) {
2765 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
2766 vwindow->delete_source(1, 1);
2767 vwindow->gui->unlock_window();
2772 for(int i = 0; i < session->drag_assets->size(); i++) {
2773 for(int j = 0; j < vwindows.size(); j++) {
2774 VWindow *vwindow = vwindows.get(j);
2775 if( !vwindow->is_running() ) continue;
2776 if(session->drag_assets->get(i) == vwindow->get_source()) {
2777 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
2778 vwindow->delete_source(1, 1);
2779 vwindow->gui->unlock_window();
2784 for(int i = 0; i < session->drag_assets->size(); i++) {
2785 Indexable *indexable = session->drag_assets->values[i];
2786 remove_indexfile(indexable);
2789 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2790 if(push_undo) undo->update_undo_before();
2791 edl->remove_from_project(session->drag_assets);
2792 edl->remove_from_project(session->drag_clips);
2794 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
2797 gui->lock_window("MWindow::remove_assets_from_project 3");
2805 gui->unlock_window();
2807 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
2808 awindow->gui->update_assets();
2809 awindow->gui->flush();
2810 awindow->gui->unlock_window();
2812 // Removes from playback here
2813 sync_parameters(CHANGE_ALL);
2816 void MWindow::remove_assets_from_disk()
2819 for(int i = 0; i < session->drag_assets->total; i++)
2821 remove(session->drag_assets->values[i]->path);
2824 remove_assets_from_project(1);
2827 void MWindow::dump_plugins(FILE *fp)
2829 if( !plugindb ) return;
2830 for(int i = 0; i < plugindb->total; i++)
2832 fprintf(fp, "audio=%d video=%d rt=%d multi=%d"
2833 " synth=%d transition=%d theme=%d %s\n",
2834 plugindb->values[i]->audio,
2835 plugindb->values[i]->video,
2836 plugindb->values[i]->realtime,
2837 plugindb->values[i]->multichannel,
2838 plugindb->values[i]->get_synthesis(),
2839 plugindb->values[i]->transition,
2840 plugindb->values[i]->theme,
2841 plugindb->values[i]->title);
2845 void MWindow::dump_edl(FILE *fp)
2851 void MWindow::dump_undo(FILE *fp)
2857 void MWindow::dump_exe(FILE *fp)
2859 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
2860 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
2861 int len = readlink(proc_path, exe_path, sizeof(exe_path));
2862 if( len < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
2865 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
2866 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
2867 int fd = open(exe_path,O_RDONLY);
2868 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
2869 uint8_t buf[65536]; SHA1 sha1;
2870 while( (len=read(fd,buf,sizeof(buf))) > 0 ) {
2871 sha1.addBytes(buf, len);
2874 fprintf(fp, "SHA1: ");
2875 uint8_t digest[20]; sha1.computeHash(digest);
2876 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
2881 void MWindow::trap_hook(FILE *fp, void *vp)
2883 MWindow *mwindow = (MWindow *)vp;
2884 fprintf(fp, "\nEXE:\n");
2885 mwindow->dump_exe(fp);
2886 fprintf(fp, "\nPLUGINS:\n");
2887 mwindow->dump_plugins(fp);
2888 fprintf(fp, "\nEDL:\n");
2889 mwindow->dump_edl(fp);
2890 fprintf(fp, "\nUNDO:\n");
2891 mwindow->dump_undo(fp);
2899 int MWindow::save_defaults()
2901 gui->save_defaults(defaults);
2902 edl->save_defaults(defaults);
2903 session->save_defaults(defaults);
2904 preferences->save_defaults(defaults);
2906 for(int i = 0; i < plugin_guis->total; i++)
2908 // Pointer comparison
2909 plugin_guis->values[i]->save_defaults();
2916 int MWindow::run_script(FileXML *script)
2918 int result = 0, result2 = 0;
2919 while(!result && !result2)
2921 result = script->read_tag();
2924 if(script->tag.title_is("new_project"))
2926 // Run new in immediate mode.
2927 // gui->mainmenu->new_project->run_script(script);
2930 if(script->tag.title_is("record"))
2932 // Run record as a thread. It is a terminal command.
2934 // Will read the complete scipt file without letting record read it if not
2940 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
2947 // ================================= synchronization
2950 int MWindow::interrupt_indexes()
2952 mainindexes->interrupt_build();
2958 void MWindow::next_time_format()
2960 switch(edl->session->time_format)
2962 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
2963 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
2964 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2965 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
2966 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
2967 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
2968 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
2971 time_format_common();
2974 void MWindow::prev_time_format()
2976 switch(edl->session->time_format)
2978 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
2979 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
2980 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
2981 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2982 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
2983 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
2984 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
2987 time_format_common();
2990 void MWindow::time_format_common()
2992 gui->lock_window("MWindow::next_time_format");
2993 gui->redraw_time_dependancies();
2996 char string[BCTEXTLEN], string2[BCTEXTLEN];
2997 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
2998 gui->show_message(string);
3000 gui->unlock_window();
3004 int MWindow::set_filename(const char *filename)
3006 if( filename != session->filename )
3007 strcpy(session->filename, filename);
3008 if( filename != edl->path )
3009 strcpy(edl->path, filename);
3013 if(filename[0] == 0)
3015 gui->set_title(PROGRAM_NAME);
3020 char string[BCTEXTLEN], string2[BCTEXTLEN];
3021 dir.extract_name(string, filename);
3022 sprintf(string2, PROGRAM_NAME ": %s", string);
3023 gui->set_title(string2);
3036 int MWindow::set_loop_boundaries()
3038 double start = edl->local_session->get_selectionstart();
3039 double end = edl->local_session->get_selectionend();
3047 if(edl->tracks->total_length())
3050 end = edl->tracks->total_length();
3057 if(edl->local_session->loop_playback && start != end)
3059 edl->local_session->loop_start = start;
3060 edl->local_session->loop_end = end;
3071 int MWindow::reset_meters()
3073 cwindow->gui->lock_window("MWindow::reset_meters 1");
3074 cwindow->gui->meters->reset_meters();
3075 cwindow->gui->unlock_window();
3077 for(int j = 0; j < vwindows.size(); j++) {
3078 VWindow *vwindow = vwindows.get(j);
3079 if( !vwindow->is_running() ) continue;
3080 vwindow->gui->lock_window("MWindow::reset_meters 2");
3081 vwindow->gui->meters->reset_meters();
3082 vwindow->gui->unlock_window();
3085 lwindow->gui->lock_window("MWindow::reset_meters 3");
3086 lwindow->gui->panel->reset_meters();
3087 lwindow->gui->unlock_window();
3089 gui->lock_window("MWindow::reset_meters 4");
3090 gui->reset_meters();
3091 gui->unlock_window();
3096 void MWindow::resync_guis()
3100 gui->lock_window("MWindow::resync_guis");
3101 gui->update(1, 1, 1, 1, 1, 1, 0);
3102 gui->unlock_window();
3104 cwindow->gui->lock_window("MWindow::resync_guis");
3105 cwindow->gui->resize_event(cwindow->gui->get_w(),
3106 cwindow->gui->get_h());
3107 int channels = edl->session->audio_channels;
3108 cwindow->gui->meters->set_meters(channels, 1);
3109 cwindow->gui->flush();
3110 cwindow->gui->unlock_window();
3112 for(int i = 0; i < vwindows.size(); i++) {
3113 VWindow *vwindow = vwindows.get(i);
3114 if( !vwindow->is_running() ) continue;
3115 vwindow->gui->lock_window("MWindow::resync_guis");
3116 vwindow->gui->resize_event(vwindow->gui->get_w(),
3117 vwindow->gui->get_h());
3118 vwindow->gui->meters->set_meters(channels, 1);
3119 vwindow->gui->flush();
3120 vwindow->gui->unlock_window();
3123 lwindow->gui->lock_window("MWindow::resync_guis");
3124 lwindow->gui->panel->set_meters(channels, 1);
3125 lwindow->gui->flush();
3126 lwindow->gui->unlock_window();
3129 if(((edl->session->output_w % 4) ||
3130 (edl->session->output_h % 4)) &&
3131 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3133 MainError::show_error(
3134 _("This project's dimensions are not multiples of 4 so\n"
3135 "it can't be rendered by OpenGL."));
3140 sync_parameters(CHANGE_ALL);
3143 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3145 File *file = new File;
3146 EDLSession *session = edl->session;
3147 double old_framerate = session->frame_rate;
3148 double old_samplerate = session->sample_rate;
3149 int result = file->open_file(preferences, asset, 1, 0);
3150 if( !result && delete_tracks > 0 )
3151 undo->update_undo_before();
3152 if( !result && asset->get_video_layers() > 0 ) {
3153 // try to get asset up to date, may fail
3154 file->select_video_stream(asset, vstream);
3155 // either way use what was/is there.
3156 double framerate = asset->get_frame_rate();
3157 int width = asset->get_w();
3158 int height = asset->get_h();
3159 // must be multiple of 4 for opengl
3160 width = (width+3) & ~3; height = (height+3) & ~3;
3161 int driver = session->playback_config->vconfig->driver;
3162 int color_model = file->get_best_colormodel(asset, driver);
3163 color_model = BC_CModels::is_yuv(color_model) ?
3164 BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3165 BC_CModels::is_float(color_model) ?
3166 BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3167 BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3168 session->color_model = color_model;
3169 session->output_w = width;
3170 session->output_h = height;
3171 session->frame_rate = framerate;
3172 // not, asset->actual_width/actual_height
3173 asset->width = session->output_w;
3174 asset->height = session->output_h;
3175 asset->frame_rate = session->frame_rate;
3176 create_aspect_ratio(session->aspect_w, session->aspect_h,
3177 session->output_w, session->output_h);
3178 Track *track = edl->tracks->first;
3179 for( Track *next_track=0; track; track=next_track ) {
3180 next_track = track->next;
3181 if( track->data_type != TRACK_VIDEO ) continue;
3182 if( delete_tracks ) {
3183 Edit *edit = track->edits->first;
3184 for( Edit *next_edit=0; edit; edit=next_edit ) {
3185 next_edit = edit->next;
3186 if( edit->channel != vstream ||
3187 !edit->asset || !edit->asset->is_asset ||
3188 *asset != *edit->asset )
3192 if( track->edits->first ) {
3193 track->track_w = edl->session->output_w;
3194 track->track_h = edl->session->output_h;
3196 else if( delete_tracks )
3197 edl->tracks->delete_track(track);
3199 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3201 if( !result && asset->channels > 0 ) {
3202 session->sample_rate = asset->get_sample_rate();
3203 int64_t channel_mask = 0;
3204 int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
3205 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3206 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3208 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3209 if( channels > 6 ) channels = 6;
3210 session->audio_tracks = session->audio_channels = channels;
3211 switch( channels ) {
3213 session->achannel_positions[0] = 90;
3214 session->achannel_positions[1] = 150;
3215 session->achannel_positions[2] = 30;
3216 session->achannel_positions[3] = 210;
3217 session->achannel_positions[4] = 330;
3218 session->achannel_positions[5] = 270;
3221 session->achannel_positions[0] = 180;
3222 session->achannel_positions[1] = 0;
3225 remap_audio(MWindow::AUDIO_1_TO_1);
3227 if( delete_tracks ) {
3228 Track *track = edl->tracks->first;
3229 for( Track *next_track=0; track; track=next_track ) {
3230 next_track = track->next;
3231 if( track->data_type != TRACK_AUDIO ) continue;
3232 Edit *edit = track->edits->first;
3233 for( Edit *next_edit=0; edit; edit=next_edit ) {
3234 next_edit = edit->next;
3235 if( !((1<<edit->channel) & channel_mask) ||
3236 !edit->asset || !edit->asset->is_asset ||
3237 *asset != *edit->asset )
3240 if( !track->edits->first )
3241 edl->tracks->delete_track(track);
3245 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3248 if( !result && delete_tracks > 0 ) {
3250 undo->update_undo_after(_("select asset"), LOAD_ALL);
3256 int MWindow::select_asset(int vtrack, int delete_tracks)
3258 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3259 if( !track ) return 1;
3260 Edit *edit = track->edits->first;
3261 if( !edit ) return 1;
3262 Asset *asset = edit->asset;
3263 if( !asset || !asset->is_asset ) return 1;
3264 return select_asset(asset, edit->channel, -1, delete_tracks);
3267 void MWindow::dump_plugindb(FILE *fp)
3269 if( !plugindb ) return;
3270 for(int i = 0; i < plugindb->total; i++)
3271 plugindb->values[i]->dump(fp);