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"
33 #include "channeldb.h"
34 #include "channelinfo.h"
36 #include "colormodels.h"
37 #include "commercials.h"
38 #include "cplayback.h"
40 #include "cwindowgui.h"
43 #include "devicedvbinput.inc"
44 #include "editpanel.h"
46 #include "edlsession.h"
48 #include "fileformat.h"
50 #include "fileserver.h"
51 #include "filesystem.h"
54 #include "framecache.h"
56 #include "gwindowgui.h"
57 #include "keyframegui.h"
58 #include "indexfile.h"
60 #include "levelwindowgui.h"
61 #include "levelwindow.h"
62 #include "loadfile.inc"
63 #include "localsession.h"
64 #include "maincursor.h"
65 #include "mainerror.h"
66 #include "mainindexes.h"
68 #include "mainprogress.h"
69 #include "mainsession.h"
73 #include "mwindowgui.h"
75 #include "nestededls.h"
78 #include "playback3d.h"
79 #include "playbackengine.h"
81 #include "pluginserver.h"
82 #include "pluginset.h"
83 #include "preferences.h"
85 #include "recordmonitor.h"
86 #include "recordlabel.h"
87 #include "removefile.h"
89 #include "samplescroll.h"
91 #include "sighandler.h"
92 #include "splashgui.h"
93 #include "statusbar.h"
95 #include "threadloader.h"
97 #include "tipwindow.h"
98 #include "trackcanvas.h"
100 #include "tracking.h"
101 #include "trackscroll.h"
103 #include "transition.h"
104 #include "transportque.h"
106 #include "videodevice.inc"
107 #include "videowindow.h"
108 #include "vplayback.h"
109 #include "vwindowgui.h"
111 #include "wavecache.h"
115 #include <sys/stat.h>
124 // Hack for libdv to remove glib dependancy
127 // g_log (const char *log_domain,
129 // const char *format,
135 // g_logv (const char *log_domain,
137 // const char *format,
144 // Hack for XFree86 4.1.0
146 int atexit(void (*function)(void))
157 ArrayList<PluginServer*>* MWindow::plugindb = 0;
158 FileServer* MWindow::file_server = 0;
159 Commercials* MWindow::commercials = 0;
165 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
166 dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
167 vwindows_lock = new Mutex("MWindow::vwindows_lock");
168 brender_lock = new Mutex("MWindow::brender_lock");
169 keyframe_gui_lock = new Mutex("MWindow::keyframe_gui_lock");
177 commercial_active = 0;
188 channeldb_buz = new ChannelDB;
189 channeldb_v4l2jpeg = new ChannelDB;
193 keyframe_threads = 0;
211 // Need to delete brender temporary here.
215 //printf("MWindow::~MWindow %d\n", __LINE__);
217 gui->remote_control->deactivate();
219 gui->channel_info->stop();
220 brender_lock->lock("MWindow::quit");
221 delete brender; brender = 0;
222 brender_lock->unlock();
223 delete create_dvd; create_dvd = 0;
224 delete batch_render; batch_render = 0;
226 if( commercials && !commercials->remove_user() ) commercials = 0;
228 // Save defaults for open plugins
229 plugin_gui_lock->lock("MWindow::~MWindow");
230 for(int i = 0; i < plugin_guis->size(); i++)
232 plugin_guis->get(i)->hide_gui();
234 plugin_gui_lock->unlock();
235 hide_keyframe_guis();
238 // Give up and go to a movie
239 // cant run valgrind if this is used
240 // if( !reload_status ) exit(0);
242 gui->del_keyboard_listener(
243 (int (BC_WindowBase::*)(BC_WindowBase *))
244 &MWindowGUI::keyboard_listener);
246 // release the hounds
247 if( awindow && awindow->gui ) awindow->gui->close(0);
248 if( cwindow && cwindow->gui ) cwindow->gui->close(0);
249 if( lwindow && lwindow->gui ) lwindow->gui->close(0);
250 if( gwindow && gwindow->gui ) gwindow->gui->close(0);
251 if( twindow && twindow->is_running() ) twindow->close_window();
252 vwindows.remove_all_objects();
254 if( awindow ) awindow->join();
255 if( cwindow ) cwindow->join();
256 if( lwindow ) lwindow->join();
257 if( twindow ) twindow->join();
258 if( gwindow ) gwindow->join();
261 // one at a time, or nouveau chokes
262 #define close_gui(win) if( win ) { \
263 if( win->gui ) win->gui->close(0); \
270 vwindows.remove_all_objects();
276 dead_plugins->remove_all();
278 keyframe_threads->remove_all_objects();
279 if( !edl->Garbage::remove_user() ) edl = 0;
280 colormodels.remove_all_objects();
282 delete render; render = 0;
283 delete awindow; awindow = 0;
284 delete lwindow; lwindow = 0;
285 delete twindow; twindow = 0;
286 delete gwindow; gwindow = 0;
287 // must be last or nouveau chokes
288 delete cwindow; cwindow = 0;
289 //delete file_server; file_server = 0; // reusable
290 delete mainindexes; mainindexes = 0;
291 delete mainprogress; mainprogress = 0;
292 delete audio_cache; audio_cache = 0; // delete the cache after the assets
293 delete video_cache; video_cache = 0; // delete the cache after the assets
294 delete frame_cache; frame_cache = 0;
295 delete wave_cache; wave_cache = 0;
296 delete plugin_guis; plugin_guis = 0;
297 delete dead_plugins; dead_plugins = 0;
298 delete keyframe_threads; keyframe_threads = 0;
299 delete undo; undo = 0;
300 delete preferences; preferences = 0;
301 delete session; session = 0;
302 delete defaults; defaults = 0;
303 delete assets; assets = 0;
304 delete splash_window; splash_window = 0;
305 delete theme; theme = 0;
306 delete channeldb_buz;
307 delete channeldb_v4l2jpeg;
308 // This must be last thread to exit
309 delete playback_3d; playback_3d = 0;
310 delete dead_plugin_lock;
311 delete plugin_gui_lock;
312 delete vwindows_lock;
314 delete keyframe_gui_lock;
315 sighandler->terminate();
320 void MWindow::quit(int unlock)
323 if(unlock) gui->unlock_window();
325 brender_lock->lock("MWindow::quit");
326 delete brender; brender = 0;
327 brender_lock->unlock();
333 if(unlock) gui->lock_window("MWindow::quit");
336 void MWindow::init_error()
338 MainError::init_error(this);
341 void MWindow::finit_error()
343 MainError::finit_error();
346 void MWindow::create_defaults_path(char *string, const char *config_file)
348 // set the .bcast path
351 sprintf(string, "%s", BCASTDIR);
352 fs.complete_path(string);
353 if(!fs.is_dir(string))
354 fs.create_dir(string);
357 strcat(string, config_file);
360 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
362 char path[BCTEXTLEN];
363 // Use user supplied path
365 strcpy(path, config_path);
367 create_defaults_path(path, CONFIG_FILE);
369 defaults = new BC_Hash(path);
373 int MWindow::load_plugin_index(MWindow *mwindow, char *path)
376 FILE *fp = fopen(path, "r");
378 char index_line[BCTEXTLEN];
379 int index_version = -1, ret = 0;
380 if( !fgets(index_line, BCTEXTLEN, fp) ||
381 sscanf(index_line, "%d", &index_version) != 1 ||
382 index_version != PLUGIN_FILE_VERSION ) ret = 1;
384 while( !ret && !feof(fp)) {
385 char *sp = index_line, *plugin_path = 0, *plugin_title = 0;
386 if( fgets(sp, BCTEXTLEN, fp) ) {
387 plugin_path = PluginServer::table_quoted_field(sp);
388 if( plugin_exists(plugin_path) ) continue;
389 plugin_title = PluginServer::table_quoted_field(sp);
391 if( plugin_path && plugin_title ) {
392 // Create plugin server from index entry
393 PluginServer *new_plugin = new PluginServer(path, mwindow);
394 new_plugin->set_path(plugin_path);
395 new_plugin->set_title(plugin_title);
396 if( new_plugin->read_table(sp) ) {
400 plugindb->append(new_plugin);
408 void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences, FILE *fp,
409 const char *plug_dir, const char *plug_path, int &idx)
411 char plugin_path[BCTEXTLEN];
412 if( *plug_path != '/' )
413 sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
415 strcpy(plugin_path, plug_path);
417 fs.set_filter( "[*.plugin][*.so]" );
418 int result = fs.update(plugin_path);
419 if( result || !fs.dir_list.total ) return;
422 for( int i=0; i<fs.dir_list.total; ++i ) {
423 char *fs_path = fs.dir_list.values[i]->path;
424 char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
425 const char *dp = plug_dir;
426 while( *bp && *dp && *bp == *dp ) { ++bp; ++dp; }
427 strcpy(plugin_path, !*dp && *bp == '/' ? bp+1 : base_path);
429 if( fs.is_dir(fs_path) ) {
430 init_plugin_index(mwindow, preferences, fp, plug_dir, plugin_path, idx);
433 if( plugin_exists(plugin_path) ) continue;
434 PluginServer *new_plugin = new PluginServer(plugin_path, mwindow);
435 result = new_plugin->open_plugin(1, preferences, 0, 0);
437 new_plugin->write_table(fp,vis_id);
438 new_plugin->close_plugin();
439 new_plugin->delete_this();
442 if( result != PLUGINSERVER_IS_LAD ) continue;
445 PluginServer *new_plugin = new PluginServer(plugin_path, mwindow);
446 new_plugin->set_lad_index(lad_index++);
447 result = new_plugin->open_plugin(1, preferences, 0, 0);
449 new_plugin->write_table(fp,vis_id);
450 new_plugin->close_plugin();
451 new_plugin->delete_this();
456 int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
458 if( !plugindb ) plugindb = new ArrayList<PluginServer*>;
459 char index_path[BCTEXTLEN];
460 sprintf(index_path, "%s/%s", preferences->plugin_dir, PLUGIN_FILE);
461 if( !load_plugin_index(mwindow, index_path) ) return 1;
462 FILE *fp = fopen(index_path,"w");
464 fprintf(stderr," MWindow::init_plugins: "
465 "can't create plugin index: %s\n", index_path);
468 fprintf(fp, "%d\n", PLUGIN_FILE_VERSION);
469 char *plug_path = FileSystem::basepath(preferences->plugin_dir);
471 init_plugin_index(mwindow, preferences, fp, plug_path, ".", dir_id);
474 return load_plugin_index(mwindow, index_path);
477 void MWindow::delete_plugins()
479 plugindb->remove_all_objects();
484 void MWindow::search_plugindb(int do_audio,
489 ArrayList<PluginServer*> &results)
492 for(int i = 0; i < MWindow::plugindb->total; i++)
494 PluginServer *current = MWindow::plugindb->values[i];
496 if(current->audio == do_audio &&
497 current->video == do_video &&
498 (current->realtime == is_realtime || is_realtime < 0) &&
499 current->transition == is_transition &&
500 current->theme == is_theme)
501 results.append(current);
504 // Alphabetize list by title
510 for(int i = 0; i < results.total - 1; i++)
512 PluginServer *value1 = results.values[i];
513 PluginServer *value2 = results.values[i + 1];
514 if(strcmp(_(value1->title), _(value2->title)) > 0)
517 results.values[i] = value2;
518 results.values[i + 1] = value1;
524 PluginServer* MWindow::scan_plugindb(char *title,
529 // printf("MWindow::scan_plugindb data_type < 0\n");
533 for(int i = 0; i < plugindb->total; i++)
535 PluginServer *server = plugindb->values[i];
537 !strcasecmp(server->title, title) &&
539 (data_type == TRACK_AUDIO && server->audio) ||
540 (data_type == TRACK_VIDEO && server->video)))
541 return plugindb->values[i];
546 int MWindow::plugin_exists(char *plugin_path)
548 for( int i=0; i<plugindb->total; ++i ) {
549 PluginServer *server = plugindb->values[i];
550 if( !strcmp(plugin_path, server->get_path()) ) return 1;
555 void MWindow::init_preferences()
557 preferences = new Preferences;
558 preferences->load_defaults(defaults);
559 session = new MainSession(this);
560 session->load_defaults(defaults);
561 // set x11_host, screens, window_config
562 screens = session->set_default_x11_host();
563 BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
564 BC_Signals::set_trap_hook(trap_hook, this);
565 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
566 BC_Signals::set_catch_intr(preferences->trap_sigintr);
569 void MWindow::clean_indexes()
574 int oldest_item = -1;
576 char string[BCTEXTLEN];
577 char string2[BCTEXTLEN];
579 // Delete extra indexes
580 fs.set_filter("*.idx");
581 fs.complete_path(preferences->index_directory);
582 fs.update(preferences->index_directory);
583 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
585 // Eliminate directories
590 for(int i = 0; i < fs.dir_list.total && !result; i++)
592 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
593 if(fs.is_dir(string))
595 delete fs.dir_list.values[i];
596 fs.dir_list.remove_number(i);
601 total_excess = fs.dir_list.total - preferences->index_count;
603 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
604 while(total_excess > 0)
607 for(int i = 0; i < fs.dir_list.total; i++)
609 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
611 if(i == 0 || fs.get_date(string) <= oldest)
613 oldest = fs.get_date(string);
621 fs.join_names(string,
622 preferences->index_directory,
623 fs.dir_list.values[oldest_item]->name);
624 //printf("MWindow::clean_indexes 1 %s\n", string);
626 perror("delete_indexes");
627 delete fs.dir_list.values[oldest_item];
628 fs.dir_list.remove_number(oldest_item);
630 // Remove table of contents if it exists
631 strcpy(string2, string);
632 char *ptr = strrchr(string2, '.');
635 //printf("MWindow::clean_indexes 2 %s\n", string2);
636 sprintf(ptr, ".toc");
645 void MWindow::init_awindow()
647 awindow = new AWindow(this);
648 awindow->create_objects();
651 void MWindow::init_gwindow()
653 gwindow = new GWindow(this);
654 gwindow->create_objects();
657 void MWindow::init_tipwindow()
659 twindow = new TipWindow(this);
663 void MWindow::init_theme()
668 // Replace blond theme with SUV since it doesn't work
669 if(!strcasecmp(preferences->theme, "Blond"))
670 strcpy(preferences->theme, DEFAULT_THEME);
672 PluginServer *theme_plugin = 0;
673 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
674 if( plugindb->values[i]->theme &&
675 !strcasecmp(preferences->theme, plugindb->values[i]->title) )
676 theme_plugin = plugindb->values[i];
680 fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
683 if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
684 fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
686 for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
687 if( plugindb->values[i]->theme &&
688 !strcasecmp(DEFAULT_THEME, plugindb->values[i]->title) )
689 theme_plugin = plugindb->values[i];
694 fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
698 PluginServer plugin = *theme_plugin;
699 if( plugin.open_plugin(0, preferences, 0, 0) ) {
700 fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
701 theme_plugin->title);
705 theme = plugin.new_theme();
706 theme->mwindow = this;
707 strcpy(theme->path, plugin.path);
708 plugin.close_plugin();
710 // Load default images & settings
711 theme->Theme::initialize();
712 // Load user images & settings
714 // Create menus with user colors
715 theme->build_menus();
720 //printf("MWindow::init_theme %d total_time=%d\n", __LINE__, (int)timer.get_difference());
723 void MWindow::init_3d()
725 playback_3d = new Playback3D(this);
726 playback_3d->create_objects();
729 void MWindow::init_edl()
732 edl->create_objects();
733 edl->load_defaults(defaults);
734 edl->create_default_tracks();
735 edl->tracks->update_y_pixels(theme);
738 void MWindow::init_compositor()
740 cwindow = new CWindow(this);
741 cwindow->create_objects();
744 void MWindow::init_levelwindow()
746 lwindow = new LevelWindow(this);
747 lwindow->create_objects();
750 VWindow *MWindow::get_viewer(int start_it, int idx)
752 vwindows_lock->lock("MWindow::get_viewer");
753 VWindow *vwindow = idx >= 0 && idx < vwindows.size() ? vwindows.get(idx) : 0;
754 if( !vwindow ) idx = vwindows.size();
755 while( !vwindow && --idx >= 0 ) {
756 VWindow *vwin = vwindows.get(idx);
757 if( !vwin->is_running() || !vwin->get_edl() )
761 vwindow = new VWindow(this);
762 vwindow->load_defaults();
763 vwindow->create_objects();
764 vwindows.append(vwindow);
766 vwindows_lock->unlock();
767 if( start_it ) vwindow->start();
771 void MWindow::init_cache()
773 audio_cache = new CICache(preferences);
774 video_cache = new CICache(preferences);
775 frame_cache = new FrameCache;
776 wave_cache = new WaveCache;
779 void MWindow::init_channeldb()
781 channeldb_buz->load("channeldb_buz");
782 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
785 void MWindow::init_menus()
787 char string[BCTEXTLEN];
788 cmodel_to_text(string, BC_RGB888);
789 colormodels.append(new ColormodelItem(string, BC_RGB888));
790 cmodel_to_text(string, BC_RGBA8888);
791 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
792 // cmodel_to_text(string, BC_RGB161616);
793 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
794 // cmodel_to_text(string, BC_RGBA16161616);
795 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
796 cmodel_to_text(string, BC_RGB_FLOAT);
797 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
798 cmodel_to_text(string, BC_RGBA_FLOAT);
799 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
800 cmodel_to_text(string, BC_YUV888);
801 colormodels.append(new ColormodelItem(string, BC_YUV888));
802 cmodel_to_text(string, BC_YUVA8888);
803 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
804 // cmodel_to_text(string, BC_YUV161616);
805 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
806 // cmodel_to_text(string, BC_YUVA16161616);
807 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
810 void MWindow::init_indexes()
812 mainindexes = new MainIndexes(this);
813 mainindexes->start_loop();
816 void MWindow::init_gui()
818 gui = new MWindowGUI(this);
819 gui->lock_window("MWindow::init_gui");
820 gui->create_objects();
821 gui->unlock_window();
822 gui->load_defaults(defaults);
825 void MWindow::init_signals()
827 sighandler = new SigHandler;
828 sighandler->initialize();
832 void MWindow::init_render()
834 render = new Render(this);
835 create_dvd = new CreateDVD_Thread(this);
836 batch_render = new BatchRenderThread(this);
839 void MWindow::init_brender()
841 if(preferences->use_brender && !brender)
843 brender_lock->lock("MWindow::init_brender 1");
844 brender = new BRender(this);
845 brender->initialize();
846 session->brender_end = 0;
847 brender_lock->unlock();
850 if(!preferences->use_brender && brender)
852 brender_lock->lock("MWindow::init_brender 2");
855 session->brender_end = 0;
856 brender_lock->unlock();
858 if(brender) brender->restart(edl);
861 void MWindow::restart_brender()
863 //printf("MWindow::restart_brender 1\n");
864 if(brender) brender->restart(edl);
867 void MWindow::stop_brender()
869 if(brender) brender->stop();
872 int MWindow::brender_available(int position)
875 brender_lock->lock("MWindow::brender_available 1");
878 if(brender->map_valid)
880 brender->map_lock->lock("MWindow::brender_available 2");
881 if(position < brender->map_size &&
884 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
885 if(brender->map[position] == BRender::RENDERED)
888 brender->map_lock->unlock();
891 brender_lock->unlock();
895 void MWindow::set_brender_start()
897 edl->session->brender_start = edl->local_session->get_selectionstart(1);
899 gui->draw_overlays(1);
903 int MWindow::has_commercials()
905 return theme->use_commercials;
908 void MWindow::init_commercials()
911 commercials = new Commercials(this);
912 commercial_active = 0;
915 commercials->add_user();
918 void MWindow::commit_commercial()
920 if( !commercial_active ) return;
921 commercial_active = 0;
922 if( !commercials ) return;
923 commercials->commitDb();
926 void MWindow::undo_commercial()
928 if( !commercial_active ) return;
929 commercial_active = 0;
930 if( !commercials ) return;
931 commercials->undoDb();
934 int MWindow::put_commercial()
936 double start = edl->local_session->get_selectionstart();
937 double end = edl->local_session->get_selectionend();
938 if( start >= end ) return 0;
940 const char *errmsg = 0;
942 Tracks *tracks = edl->tracks;
945 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
946 if( track->data_type != TRACK_VIDEO ) continue;
947 if( !track->record ) continue;
948 if( count > 0 ) { errmsg = "multiple video tracks"; break; }
950 int64_t units_start = track->to_units(start,0);
951 int64_t units_end = track->to_units(end,0);
952 Edits *edits = track->edits;
953 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
954 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
955 if(!edit1 && !edit2) continue; // nothing selected
956 if(!edit2) { // edit2 beyond end of track
958 units_end = edits->length();
960 if(edit1 != edit2) { errmsg = "crosses edits"; break; }
961 Indexable *indexable = edit1->get_source();
962 if( !indexable->is_asset ) { errmsg = "not asset"; break; }
965 for(Track *track=tracks->first; track && !errmsg; track=track->next) {
966 if( track->data_type != TRACK_VIDEO ) continue;
967 if( !track->record ) continue;
968 int64_t units_start = track->to_units(start,0);
969 int64_t units_end = track->to_units(end,0);
970 Edits *edits = track->edits;
971 Edit *edit1 = edits->editof(units_start, PLAY_FORWARD, 0);
972 Edit *edit2 = edits->editof(units_end, PLAY_FORWARD, 0);
973 if(!edit1 && !edit2) continue; // nothing selected
974 if(!edit2) { // edit2 beyond end of track
976 units_end = edits->length();
978 Indexable *indexable = edit1->get_source();
979 Asset *asset = (Asset *)indexable;
980 File *file = video_cache->check_out(asset, edl);
981 if( !file ) { errmsg = "no file"; break; }
982 int64_t edit_length = units_end - units_start;
983 int64_t edit_start = units_start - edit1->startproject + edit1->startsource;
984 result = commercials->put_clip(file, edit1->channel,
985 track->from_units(edit_start), track->from_units(edit_length));
986 video_cache->check_in(asset);
987 if( result ) { errmsg = "db failed"; break; }
990 char string[BCTEXTLEN];
991 sprintf(string, "put_commercial: %s", errmsg);
992 MainError::show_error(string);
999 void MWindow::stop_playback(int wait)
1001 int locked = gui->get_window_lock();
1002 if( locked ) gui->unlock_window();
1004 cwindow->playback_engine->que->send_command(STOP,
1008 cwindow->playback_engine->interrupt_playback(wait);
1010 for(int i = 0; i < vwindows.size(); i++)
1012 VWindow *vwindow = vwindows.get(i);
1013 if(vwindow->running())
1015 vwindow->playback_engine->que->send_command(STOP,
1019 vwindow->playback_engine->interrupt_playback(wait);
1022 if( locked ) gui->lock_window("MWindow::stop_playback");
1025 int MWindow::load_filenames(ArrayList<char*> *filenames,
1027 int update_filename)
1029 ArrayList<EDL*> new_edls;
1030 ArrayList<Asset*> new_assets;
1031 ArrayList<File*> new_files;
1032 const int debug = 0;
1033 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1036 gui->start_hourglass();
1038 // Need to stop playback since tracking depends on the EDL not getting
1042 undo->update_undo_before();
1045 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1047 // Define new_edls and new_assets to load
1048 int result = 0, ftype = -1;
1049 for(int i = 0; i < filenames->total; i++)
1052 File *new_file = new File;
1053 Asset *new_asset = new Asset(filenames->values[i]);
1054 EDL *new_edl = new EDL;
1055 char string[BCTEXTLEN];
1057 new_edl->create_objects();
1058 new_edl->copy_session(edl);
1059 new_file->set_program(edl->session->program_no);
1061 sprintf(string, "Loading %s", new_asset->path);
1062 gui->show_message(string);
1063 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1065 ftype = new_file->open_file(preferences, new_asset, 1, 0);
1066 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1071 // Convert media file to EDL
1073 // Warn about odd image dimensions
1074 if(new_asset->video_data &&
1075 ((new_asset->width % 2) ||
1076 (new_asset->height % 2)))
1078 char string[BCTEXTLEN];
1079 sprintf(string, "%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly.",
1083 MainError::show_error(string);
1086 if(new_asset->program >= 0 &&
1087 edl->session->program_no != new_asset->program)
1089 char string[BCTEXTLEN];
1090 sprintf(string, "%s's index was built for program number %d\n"
1091 "Playback preference is %d.\n Using program %d.",
1092 new_asset->path, new_asset->program,
1093 edl->session->program_no, new_asset->program);
1094 MainError::show_error(string);
1098 if(load_mode != LOADMODE_RESOURCESONLY)
1101 RecordLabels *labels = edl->session->label_cells ?
1102 new RecordLabels(new_file) : 0;
1104 asset_to_edl(new_edl, new_asset, labels);
1106 new_edls.append(new_edl);
1108 new_asset->Garbage::remove_user();
1114 new_assets.append(new_asset);
1118 // Set filename to nothing for assets since save EDL would overwrite them.
1119 if(load_mode == LOADMODE_REPLACE ||
1120 load_mode == LOADMODE_REPLACE_CONCATENATE)
1123 // Reset timeline position
1124 for(int i = 0; i < TOTAL_PANES; i++)
1126 new_edl->local_session->view_start[i] = 0;
1127 new_edl->local_session->track_start[i] = 0;
1135 case FILE_NOT_FOUND:
1136 sprintf(string, _("Failed to open %s"), new_asset->path);
1137 gui->show_message(string, theme->message_error);
1141 case FILE_UNRECOGNIZED_CODEC:
1144 IndexFile indexfile(this, new_asset);
1145 result = indexfile.open_index();
1148 indexfile.close_index();
1151 // Test existing EDLs
1154 for(int j = 0; j < new_edls.total + 1; j++)
1157 if(j == new_edls.total)
1159 old_asset = edl->assets->get_asset(new_asset->path);
1162 *new_asset = *old_asset;
1168 old_asset = new_edls.values[j]->assets->get_asset(new_asset->path);
1171 *new_asset = *old_asset;
1181 char string[BCTEXTLEN];
1183 fs.extract_name(string, new_asset->path);
1185 strcat(string, _("'s format couldn't be determined."));
1186 new_asset->audio_data = 1;
1187 new_asset->format = FILE_PCM;
1188 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
1189 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
1190 new_asset->bits = defaults->get("AUDIO_BITS", 16);
1191 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
1192 new_asset->signed_ = defaults->get("SIGNED_", 1);
1193 new_asset->header = defaults->get("HEADER", 0);
1195 FileFormat fwindow(this);
1196 fwindow.create_objects(new_asset, string);
1197 result = fwindow.run_window();
1200 defaults->update("AUDIO_CHANNELS", new_asset->channels);
1201 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
1202 defaults->update("AUDIO_BITS", new_asset->bits);
1203 defaults->update("BYTE_ORDER", new_asset->byte_order);
1204 defaults->update("SIGNED_", new_asset->signed_);
1205 defaults->update("HEADER", new_asset->header);
1212 // Recalculate length
1214 new_file = new File;
1215 result = new_file->open_file(preferences, new_asset, 1, 0);
1217 if(load_mode != LOADMODE_RESOURCESONLY)
1219 RecordLabels *labels = edl->session->label_cells ?
1220 new RecordLabels(new_file) : 0;
1221 asset_to_edl(new_edl, new_asset, labels);
1222 new_edls.append(new_edl);
1223 new_asset->Garbage::remove_user();
1229 new_assets.append(new_asset);
1243 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1244 xml_file.read_from_file(filenames->values[i]);
1245 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1247 if(load_mode == LOADMODE_NESTED)
1249 // Load temporary EDL for nesting.
1250 EDL *nested_edl = new EDL;
1251 nested_edl->create_objects();
1252 nested_edl->set_path(filenames->values[i]);
1253 nested_edl->load_xml(&xml_file, LOAD_ALL);
1254 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
1255 edl_to_nested(new_edl, nested_edl);
1256 nested_edl->Garbage::remove_user();
1260 // Load EDL for pasting
1261 new_edl->load_xml(&xml_file, LOAD_ALL);
1262 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1263 test_plugins(new_edl, filenames->values[i]);
1264 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1266 if(load_mode == LOADMODE_REPLACE ||
1267 load_mode == LOADMODE_REPLACE_CONCATENATE)
1269 strcpy(session->filename, filenames->values[i]);
1270 strcpy(new_edl->local_session->clip_title,
1271 filenames->values[i]);
1273 set_filename(new_edl->local_session->clip_title);
1277 new_edls.append(new_edl);
1283 // edls are in new_edls
1284 if( result && new_edl ) new_edl->Garbage::remove_user();
1285 // assets are copied
1286 if( new_asset ) new_asset->Garbage::remove_user();
1288 // Store for testing index
1289 new_files.append(new_file);
1292 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1295 if(!result) gui->statusbar->default_message();
1303 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1306 // Don't back up here.
1309 // For pasting, clear the active region
1310 if(load_mode == LOADMODE_PASTE ||
1311 load_mode == LOADMODE_NESTED)
1313 double start = edl->local_session->get_selectionstart();
1314 double end = edl->local_session->get_selectionend();
1315 if(!EQUIV(start, end))
1318 edl->session->labels_follow_edits,
1319 edl->session->plugins_follow_edits,
1320 edl->session->autos_follow_edits);
1323 paste_edls(&new_edls,
1327 edl->session->labels_follow_edits,
1328 edl->session->plugins_follow_edits,
1329 edl->session->autos_follow_edits);
1335 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1337 // Add new assets to EDL and schedule assets for index building.
1338 int got_indexes = 0;
1339 for(int i = 0; i < new_edls.size(); i++)
1341 EDL *new_edl = new_edls.get(i);
1342 for(int j = 0; j < new_edl->nested_edls->size(); j++)
1344 mainindexes->add_next_asset(0,
1345 new_edl->nested_edls->get(j));
1347 edl->nested_edls->update_index(new_edl->nested_edls->get(j));
1352 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1353 if(new_assets.size())
1355 for(int i = 0; i < new_assets.size(); i++)
1357 Asset *new_asset = new_assets.get(i);
1361 for(int j = 0; j < new_files.size(); j++)
1363 new_file = new_files.get(j);
1364 if(!strcmp(new_file->asset->path,
1372 mainindexes->add_next_asset(got_it ? new_file : 0, new_asset);
1374 edl->assets->update(new_asset);
1380 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1382 // Start examining next batch of index files
1383 if(got_indexes) mainindexes->start_build();
1384 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1387 Track *track = edl->tracks->first;
1390 for(int j = 0; j < track->plugin_set.size(); j++)
1392 PluginSet *plugins = track->plugin_set.get(j);
1393 Plugin *plugin = plugins->get_first_plugin();
1397 if(load_mode == LOADMODE_REPLACE ||
1398 load_mode == LOADMODE_REPLACE_CONCATENATE)
1400 if(plugin->plugin_type == PLUGIN_STANDALONE &&
1403 show_plugin(plugin);
1411 plugin = (Plugin*)plugin->next;
1415 track = track->next;
1418 // if just opening one new resource in replace mode
1419 if( load_mode == LOADMODE_REPLACE && new_edls.size() == 1 &&
1420 ftype != FILE_IS_XML )
1423 edl->local_session->preview_start = 0;
1424 edl->local_session->preview_end = edl->tracks->total_playable_length();
1425 edl->local_session->loop_playback = 0;
1426 edl->local_session->set_selectionstart(0);
1427 edl->local_session->set_selectionend(0);
1433 update_project(load_mode);
1435 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1437 for(int i = 0; i < new_edls.size(); i++)
1439 new_edls.get(i)->remove_user();
1441 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1443 new_edls.remove_all();
1445 for(int i = 0; i < new_assets.size(); i++)
1447 new_assets.get(i)->Garbage::remove_user();
1450 new_assets.remove_all();
1451 new_files.remove_all_objects();
1453 undo->update_undo_after(_("load"), LOAD_ALL);
1455 if(load_mode == LOADMODE_REPLACE ||
1456 load_mode == LOADMODE_REPLACE_CONCATENATE)
1458 session->changes_made = 0;
1462 session->changes_made = 1;
1465 gui->stop_hourglass();
1468 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1475 void MWindow::test_plugins(EDL *new_edl, char *path)
1477 char string[BCTEXTLEN];
1479 // Do a check weather plugins exist
1480 for(Track *track = new_edl->tracks->first; track; track = track->next)
1482 for(int k = 0; k < track->plugin_set.total; k++)
1484 PluginSet *plugin_set = track->plugin_set.values[k];
1485 for(Plugin *plugin = (Plugin*)plugin_set->first;
1487 plugin = (Plugin*)plugin->next)
1489 if(plugin->plugin_type == PLUGIN_STANDALONE)
1491 // ok we need to find it in plugindb
1492 int plugin_found = 0;
1494 for(int j = 0; j < plugindb->size(); j++)
1496 PluginServer *server = plugindb->get(j);
1498 !strcasecmp(server->title, plugin->title) &&
1499 ((track->data_type == TRACK_AUDIO && server->audio) ||
1500 (track->data_type == TRACK_VIDEO && server->video)) &&
1501 (!server->transition))
1508 "The effect '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1509 "The project won't be rendered as it was meant and Cinelerra might crash.\n",
1512 MainError::show_error(string);
1518 for(Edit *edit = (Edit*)track->edits->first;
1520 edit = (Edit*)edit->next)
1522 if (edit->transition)
1524 // ok we need to find transition in plugindb
1526 int transition_found = 0;
1527 for(int j = 0; j < plugindb->size(); j++)
1529 PluginServer *server = plugindb->get(j);
1531 !strcasecmp(server->title, edit->transition->title) &&
1532 ((track->data_type == TRACK_AUDIO && server->audio) ||
1533 (track->data_type == TRACK_VIDEO && server->video)) &&
1534 (server->transition))
1535 transition_found = 1;
1538 if (!transition_found)
1541 "The transition '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1542 "The project won't be rendered as it was meant and Cinelerra might crash.\n",
1543 edit->transition->title,
1545 MainError::show_error(string);
1553 void MWindow::init_shm()
1555 // Fix shared memory
1556 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1558 fprintf(fd, "0x7fffffff");
1563 fd = fopen("/proc/sys/kernel/shmmax", "r");
1565 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1570 fscanf(fd, _LD, &result);
1573 if(result < 0x7fffffff) {
1574 char string[BCTEXTLEN];
1575 sprintf(string, "MWindow::init_shm: /proc/sys/kernel/shmmax is 0x" _LX ".\n"
1576 "you probably need to be root, or:\n"
1577 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1578 "before trying to start cinelerra.\n"
1579 "It should be at least 0x7fffffff for Cinelerra.\n", result);
1580 MainError::show_error(string);
1585 void MWindow::init_fileserver(Preferences *preferences)
1588 if( !file_server && preferences->file_forking ) {
1589 file_server = new FileServer(preferences);
1590 file_server->start();
1595 void MWindow::create_objects(int want_gui,
1600 const int debug = 0;
1601 if(debug) PRINT_TRACE
1603 // For some reason, init_signals must come after show_splash or the signals won't
1606 if(debug) PRINT_TRACE
1609 if(debug) PRINT_TRACE
1612 if(debug) PRINT_TRACE
1613 init_defaults(defaults, config_path);
1615 init_plugins(this, preferences);
1616 if(debug) PRINT_TRACE
1617 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1618 if(debug) PRINT_TRACE
1620 if(debug) PRINT_TRACE
1623 char string[BCTEXTLEN];
1624 strcpy(string, preferences->plugin_dir);
1625 strcat(string, "/fonts");
1626 BC_Resources::init_fontconfig(string);
1627 if(debug) PRINT_TRACE
1629 // Initialize before too much else is running
1630 // Preferences & theme are required for building MPEG table of contents
1631 init_fileserver(preferences);
1633 // Default project created here
1635 if(debug) PRINT_TRACE
1638 if(debug) PRINT_TRACE
1643 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1645 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1646 if(session->show_vwindow)
1647 get_viewer(1, DEFAULT_VWINDOW);
1648 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1651 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1654 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1657 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1659 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1662 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1666 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1668 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1670 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1673 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1674 mainprogress = new MainProgress(this, gui);
1675 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1676 undo = new MainUndo(this);
1678 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1680 plugin_guis = new ArrayList<PluginServer*>;
1681 dead_plugins = new ArrayList<PluginServer*>;
1682 keyframe_threads = new ArrayList<KeyFrameThread*>;
1684 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1687 session->show_vwindow);
1689 // Show all vwindows
1690 // if(session->show_vwindow)
1692 // for(int j = 0; j < vwindows.size(); j++)
1694 // VWindow *vwindow = vwindows.get(j);
1695 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1698 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1699 // vwindow->gui->lock_window("MWindow::create_objects 1");
1700 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1701 // vwindow->gui->show_window();
1702 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1703 // vwindow->gui->unlock_window();
1708 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1710 if(session->show_cwindow)
1712 cwindow->gui->lock_window("MWindow::create_objects 1");
1713 cwindow->gui->show_window();
1714 cwindow->gui->unlock_window();
1717 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1718 if(session->show_awindow)
1720 awindow->gui->lock_window("MWindow::create_objects 1");
1721 awindow->gui->show_window();
1722 awindow->gui->unlock_window();
1725 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1726 if(session->show_lwindow)
1728 lwindow->gui->lock_window("MWindow::create_objects 1");
1729 lwindow->gui->show_window();
1730 lwindow->gui->unlock_window();
1733 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1735 (int)timer.get_difference(),
1737 if(session->show_gwindow)
1739 gwindow->gui->lock_window("MWindow::create_objects 1");
1740 gwindow->gui->show_window();
1741 gwindow->gui->unlock_window();
1744 if(debug) PRINT_TRACE
1746 gui->lock_window("MWindow::create_objects 1");
1747 gui->mainmenu->load_defaults(defaults);
1748 gui->mainmenu->update_toggles(0);
1749 gui->update_patchbay();
1750 gui->draw_canvas(0, 0);
1751 gui->draw_cursor(1);
1753 gui->raise_window();
1754 gui->unlock_window();
1756 if(debug) PRINT_TRACE
1760 if(preferences->use_tipwindow)
1762 if(debug) PRINT_TRACE
1764 gui->add_keyboard_listener(
1765 (int (BC_WindowBase::*)(BC_WindowBase *))
1766 &MWindowGUI::keyboard_listener);
1770 if(debug) PRINT_TRACE
1772 BC_WindowBase::get_resources()->vframe_shm = 1;
1777 void MWindow::show_splash()
1779 #include "data/heroine_logo11_png.h"
1780 VFrame *frame = new VFrame(heroine_logo11_png);
1781 BC_DisplayInfo display_info;
1782 splash_window = new SplashGUI(frame,
1783 display_info.get_root_w() / 2 - frame->get_w() / 2,
1784 display_info.get_root_h() / 2 - frame->get_h() / 2);
1785 splash_window->create_objects();
1788 void MWindow::hide_splash()
1791 delete splash_window;
1796 void MWindow::start()
1800 // vwindows.get(DEFAULT_VWINDOW)->start();
1811 playback_3d->start();
1820 void MWindow::show_vwindow()
1822 int total_running = 0;
1823 session->show_vwindow = 1;
1826 // Raise all windows which are visible
1827 for(int j = 0; j < vwindows.size(); j++)
1829 VWindow *vwindow = vwindows.get(j);
1830 if(vwindow->is_running())
1832 vwindow->gui->lock_window("MWindow::show_vwindow");
1833 vwindow->gui->show_window(0);
1834 vwindow->gui->raise_window();
1835 vwindow->gui->flush();
1836 vwindow->gui->unlock_window();
1841 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
1842 // If no windows visible
1845 get_viewer(1, DEFAULT_VWINDOW);
1848 gui->mainmenu->show_vwindow->set_checked(1);
1851 void MWindow::show_awindow()
1853 session->show_awindow = 1;
1854 awindow->gui->lock_window("MWindow::show_awindow");
1855 awindow->gui->show_window();
1856 awindow->gui->raise_window();
1857 awindow->gui->flush();
1858 awindow->gui->unlock_window();
1859 gui->mainmenu->show_awindow->set_checked(1);
1862 char *MWindow::get_cwindow_display()
1864 char *x11_host = screens < 2 || session->window_config == 0 ?
1865 session->a_x11_host : session->b_x11_host;
1866 return *x11_host ? x11_host : 0;
1869 void MWindow::show_cwindow()
1871 session->show_cwindow = 1;
1872 cwindow->show_window();
1873 gui->mainmenu->show_cwindow->set_checked(1);
1876 void MWindow::show_gwindow()
1878 session->show_gwindow = 1;
1880 gwindow->gui->lock_window("MWindow::show_gwindow");
1881 gwindow->gui->show_window();
1882 gwindow->gui->raise_window();
1883 gwindow->gui->flush();
1884 gwindow->gui->unlock_window();
1886 gui->mainmenu->show_gwindow->set_checked(1);
1889 void MWindow::show_lwindow()
1891 session->show_lwindow = 1;
1892 lwindow->gui->lock_window("MWindow::show_lwindow");
1893 lwindow->gui->show_window();
1894 lwindow->gui->raise_window();
1895 lwindow->gui->flush();
1896 lwindow->gui->unlock_window();
1897 gui->mainmenu->show_lwindow->set_checked(1);
1900 int MWindow::tile_windows(int window_config)
1902 int need_reload = 0;
1903 int play_config = window_config==0 ? 0 : 1;
1904 edl->session->playback_config->load_defaults(defaults, play_config);
1905 session->default_window_positions(window_config);
1906 if( screens == 1 ) {
1907 gui->default_positions();
1908 sync_parameters(CHANGE_ALL);
1915 void MWindow::toggle_loop_playback()
1917 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1918 set_loop_boundaries();
1921 gui->draw_overlays(1);
1922 sync_parameters(CHANGE_PARAMS);
1925 //void MWindow::set_titles(int value)
1927 // edl->session->show_titles = value;
1928 // trackmovement(edl->local_session->track_start);
1931 void MWindow::set_screens(int value)
1936 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
1938 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
1939 edl->session->auto_keyframes = value;
1940 gui->mbuttons->edit_panel->keyframe->update(value);
1942 if(lock_mwindow) gui->unlock_window();
1944 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1945 cwindow->gui->edit_panel->keyframe->update(value);
1946 cwindow->gui->flush();
1947 if(lock_cwindow) cwindow->gui->unlock_window();
1950 void MWindow::set_keyframe_type(int mode)
1952 gui->lock_window("MWindow::set_keyframe_type");
1953 edl->local_session->floatauto_type = mode;
1954 gui->mainmenu->update_toggles(0);
1955 gui->unlock_window();
1958 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
1960 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
1961 edl->session->editing_mode = new_editing_mode;
1962 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1963 gui->mbuttons->edit_panel->update();
1964 gui->set_editing_mode(1);
1965 if(lock_mwindow) gui->unlock_window();
1968 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
1969 cwindow->gui->edit_panel->update();
1970 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1971 if(lock_cwindow) cwindow->gui->unlock_window();
1976 void MWindow::sync_parameters(int change_type)
1979 // Sync engines which are playing back
1980 if(cwindow->playback_engine->is_playing_back)
1982 if(change_type == CHANGE_PARAMS)
1984 // TODO: block keyframes until synchronization is done
1985 cwindow->playback_engine->sync_parameters(edl);
1990 int command = cwindow->playback_engine->command->command;
1991 cwindow->playback_engine->que->send_command(STOP,
1995 // Waiting for tracking to finish would make the restart position more
1996 // accurate but it can't lock the window to stop tracking for some reason.
1997 // Not waiting for tracking gives a faster response but restart position is
1998 // only as accurate as the last tracking update.
1999 cwindow->playback_engine->interrupt_playback(0);
2000 cwindow->playback_engine->que->send_command(command,
2009 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2016 void MWindow::age_caches()
2018 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2020 // preferences->cache_size,
2021 // audio_cache->get_memory_usage(1),
2022 // video_cache->get_memory_usage(1),
2023 // frame_cache->get_memory_usage(),
2024 // wave_cache->get_memory_usage(),
2026 frame_cache->age_cache(512);
2027 wave_cache->age_cache(8192);
2029 int64_t memory_usage;
2030 int64_t prev_memory_usage = 0;
2032 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2033 while( !result && prev_memory_usage !=
2034 (memory_usage=video_cache->get_memory_usage(1)) &&
2035 memory_usage > video_size ) {
2036 video_cache->delete_oldest();
2037 prev_memory_usage = memory_usage;
2040 prev_memory_usage = 0;
2042 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2043 while( !result && prev_memory_usage !=
2044 (memory_usage=audio_cache->get_memory_usage(1)) &&
2045 memory_usage > audio_size ) {
2046 audio_cache->delete_oldest();
2047 prev_memory_usage = memory_usage;
2051 void MWindow::reset_android_remote()
2053 gui->use_android_remote(preferences->android_remote);
2057 void MWindow::show_keyframe_gui(Plugin *plugin)
2059 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2060 // Find existing thread
2061 for(int i = 0; i < keyframe_threads->size(); i++)
2063 if(keyframe_threads->get(i)->plugin == plugin)
2065 keyframe_threads->get(i)->start_window(plugin, 0);
2066 keyframe_gui_lock->unlock();
2071 // Find unused thread
2072 for(int i = 0; i < keyframe_threads->size(); i++)
2074 if(!keyframe_threads->get(i)->plugin)
2076 keyframe_threads->get(i)->start_window(plugin, 0);
2077 keyframe_gui_lock->unlock();
2082 // Create new thread
2083 KeyFrameThread *thread = new KeyFrameThread(this);
2084 keyframe_threads->append(thread);
2085 thread->start_window(plugin, 0);
2087 keyframe_gui_lock->unlock();
2094 void MWindow::show_plugin(Plugin *plugin)
2099 // Remove previously deleted plugin GUIs
2100 dead_plugin_lock->lock("MWindow::delete_plugin");
2101 for(int i = 0; i < dead_plugins->size(); i++)
2103 delete dead_plugins->get(i);
2105 dead_plugins->remove_all();
2106 dead_plugin_lock->unlock();
2108 //printf("MWindow::show_plugin %d\n", __LINE__);
2112 plugin_gui_lock->lock("MWindow::show_plugin");
2113 for(int i = 0; i < plugin_guis->total; i++)
2115 // Pointer comparison
2116 if(plugin_guis->values[i]->plugin == plugin)
2118 plugin_guis->values[i]->raise_window();
2125 //printf("MWindow::show_plugin 1\n");
2130 printf("MWindow::show_plugin track not defined.\n");
2132 PluginServer *server = scan_plugindb(plugin->title,
2133 plugin->track->data_type);
2135 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2136 if(server && server->uses_gui)
2138 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
2139 // Needs mwindow to do GUI
2140 gui->set_mwindow(this);
2141 gui->open_plugin(0, preferences, edl, plugin);
2146 plugin_gui_lock->unlock();
2147 //printf("MWindow::show_plugin %d\n", __LINE__);
2150 //printf("MWindow::show_plugin 2\n");
2153 void MWindow::hide_plugin(Plugin *plugin, int lock)
2156 // Update the toggle
2157 gui->lock_window("MWindow::hide_plugin");
2158 gui->update(0, 1, 0, 0, 0, 0, 0);
2159 gui->unlock_window();
2161 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2162 for(int i = 0; i < plugin_guis->total; i++)
2164 if(plugin_guis->values[i]->plugin == plugin)
2166 PluginServer *ptr = plugin_guis->values[i];
2167 plugin_guis->remove(ptr);
2168 if(lock) plugin_gui_lock->unlock();
2169 // Last command executed in client side close
2170 // Schedule for deletion
2177 if(lock) plugin_gui_lock->unlock();
2180 void MWindow::delete_plugin(PluginServer *plugin)
2182 dead_plugin_lock->lock("MWindow::delete_plugin");
2183 dead_plugins->append(plugin);
2184 dead_plugin_lock->unlock();
2187 void MWindow::hide_plugins()
2189 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2190 while(plugin_guis->size())
2192 PluginServer *ptr = plugin_guis->get(0);
2193 plugin_guis->remove(ptr);
2194 plugin_gui_lock->unlock();
2195 // Last command executed in client side close
2196 // Schedule for deletion
2199 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2201 plugin_gui_lock->unlock();
2203 hide_keyframe_guis();
2206 void MWindow::hide_keyframe_guis()
2208 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2209 for(int i = 0; i < keyframe_threads->size(); i++)
2211 keyframe_threads->get(i)->close_window();
2213 keyframe_gui_lock->unlock();
2216 void MWindow::hide_keyframe_gui(Plugin *plugin)
2218 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2219 for(int i = 0; i < keyframe_threads->size(); i++)
2221 if(keyframe_threads->get(i)->plugin == plugin)
2223 keyframe_threads->get(i)->close_window();
2227 keyframe_gui_lock->unlock();
2230 void MWindow::update_keyframe_guis()
2232 // Send new configuration to keyframe GUI's
2233 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2234 for(int i = 0; i < keyframe_threads->size(); i++)
2236 KeyFrameThread *ptr = keyframe_threads->get(i);
2237 if(edl->tracks->plugin_exists(ptr->plugin))
2241 ptr->close_window();
2244 keyframe_gui_lock->unlock();
2247 void MWindow::update_plugin_guis(int do_keyframe_guis)
2249 // Send new configuration to plugin GUI's
2250 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2252 for(int i = 0; i < plugin_guis->size(); i++)
2254 PluginServer *ptr = plugin_guis->get(i);
2255 if(edl->tracks->plugin_exists(ptr->plugin))
2259 // Schedule for deletion if no plugin
2260 plugin_guis->remove_number(i);
2269 // Change plugin variable if not visible
2270 Track *track = edl->tracks->first;
2273 for(int i = 0; i < track->plugin_set.size(); i++)
2275 Plugin *plugin = (Plugin*)track->plugin_set.get(i)->first;
2279 for(int i = 0; i < plugin_guis->size(); i++)
2281 PluginServer *server = plugin_guis->get(i);
2282 if(server->plugin == plugin)
2289 if(!got_it) plugin->show = 0;
2291 plugin = (Plugin*)plugin->next;
2295 track = track->next;
2298 plugin_gui_lock->unlock();
2301 if(do_keyframe_guis) update_keyframe_guis();
2304 int MWindow::plugin_gui_open(Plugin *plugin)
2307 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2308 for(int i = 0; i < plugin_guis->total; i++)
2310 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2316 plugin_gui_lock->unlock();
2320 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2322 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2323 for(int i = 0; i < plugin_guis->total; i++)
2325 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2327 plugin_guis->values[i]->render_gui(data);
2331 plugin_gui_lock->unlock();
2334 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2336 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2337 for(int i = 0; i < plugin_guis->total; i++)
2339 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2341 plugin_guis->values[i]->render_gui(data, size);
2345 plugin_gui_lock->unlock();
2349 void MWindow::update_plugin_states()
2351 plugin_gui_lock->lock("MWindow::update_plugin_states");
2352 for(int i = 0; i < plugin_guis->total; i++)
2356 Plugin *src_plugin = plugin_guis->values[i]->plugin;
2357 PluginServer *src_plugingui = plugin_guis->values[i];
2359 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2360 for(Track *track = edl->tracks->first;
2362 track = track->next)
2365 j < track->plugin_set.total && !result;
2368 PluginSet *plugin_set = track->plugin_set.values[j];
2369 for(Plugin *plugin = (Plugin*)plugin_set->first;
2371 plugin = (Plugin*)plugin->next)
2373 if(plugin == src_plugin &&
2374 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2380 // Doesn't exist anymore
2383 hide_plugin(src_plugin, 0);
2387 plugin_gui_lock->unlock();
2391 void MWindow::update_plugin_titles()
2393 for(int i = 0; i < plugin_guis->total; i++)
2395 plugin_guis->values[i]->update_title();
2399 int MWindow::asset_to_edl(EDL *new_edl,
2401 RecordLabels *labels)
2403 const int debug = 0;
2404 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2407 // Keep frame rate, sample rate, and output size unchanged.
2408 // These parameters would revert the project if VWindow displayed an asset
2409 // of different size than the project.
2410 if(new_asset->video_data)
2412 new_edl->session->video_tracks = new_asset->layers;
2415 new_edl->session->video_tracks = 0;
2417 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2423 if(new_asset->audio_data)
2425 new_edl->session->audio_tracks = new_asset->channels;
2428 new_edl->session->audio_tracks = 0;
2429 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2431 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2432 new_edl->create_default_tracks();
2433 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2434 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2438 //printf("MWindow::asset_to_edl 3\n");
2439 new_edl->insert_asset(new_asset,
2444 //printf("MWindow::asset_to_edl 3\n");
2445 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2451 char string[BCTEXTLEN];
2453 fs.extract_name(string, new_asset->path);
2454 //printf("MWindow::asset_to_edl 3\n");
2456 strcpy(new_edl->local_session->clip_title, string);
2457 //printf("MWindow::asset_to_edl 4 %s\n", string);
2458 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2463 int MWindow::edl_to_nested(EDL *new_edl,
2467 // Keep frame rate, sample rate, and output size unchanged.
2468 // These parameters would revert the project if VWindow displayed an asset
2469 // of different size than the project.
2473 // Nest all video & audio outputs
2474 new_edl->session->video_tracks = 1;
2475 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2476 new_edl->create_default_tracks();
2480 new_edl->insert_asset(0,
2486 char string[BCTEXTLEN];
2488 fs.extract_name(string, nested_edl->path);
2489 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2491 strcpy(new_edl->local_session->clip_title, string);
2496 // Reset everything after a load.
2497 void MWindow::update_project(int load_mode)
2499 const int debug = 0;
2501 if(debug) PRINT_TRACE
2503 edl->tracks->update_y_pixels(theme);
2505 if(debug) PRINT_TRACE
2507 if(load_mode == LOADMODE_REPLACE ||
2508 load_mode == LOADMODE_REPLACE_CONCATENATE)
2513 gui->update(1, 1, 1, 1, 1, 1, 1);
2514 if(debug) PRINT_TRACE
2515 gui->unlock_window();
2517 cwindow->gui->lock_window("MWindow::update_project 1");
2518 cwindow->update(0, 0, 1, 1, 1);
2519 cwindow->gui->unlock_window();
2521 if(debug) PRINT_TRACE
2523 // Close all the vwindows
2524 if(load_mode == LOADMODE_REPLACE ||
2525 load_mode == LOADMODE_REPLACE_CONCATENATE)
2527 if(debug) PRINT_TRACE
2528 int first_vwindow = 0;
2529 if(session->show_vwindow) first_vwindow = 1;
2530 // Change visible windows to no source
2531 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++)
2533 vwindows.get(i)->change_source(-1);
2536 // Close remaining windows
2537 for(int i = first_vwindow; i < vwindows.size(); i++)
2539 vwindows.get(i)->close_window();
2541 if(debug) PRINT_TRACE
2546 VWindow *vwindow = vwindows.get(DEFAULT_VWINDOW);
2547 if(vwindow->is_running())
2549 vwindow->gui->lock_window("MWindow::update_project");
2551 vwindow->gui->unlock_window();
2555 if(debug) PRINT_TRACE
2556 cwindow->gui->lock_window("MWindow::update_project 2");
2557 cwindow->gui->timebar->update(0);
2558 cwindow->gui->unlock_window();
2560 if(debug) PRINT_TRACE
2561 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2566 if(debug) PRINT_TRACE
2568 awindow->gui->lock_window("MWindow::update_project");
2569 awindow->gui->update_assets();
2570 awindow->gui->flush();
2571 awindow->gui->unlock_window();
2573 if(debug) PRINT_TRACE
2575 gui->lock_window("MWindow::update_project");
2577 if(debug) PRINT_TRACE
2580 void MWindow::remove_indexfile(Indexable *indexable)
2582 if( !indexable->is_asset ) return;
2583 Asset *asset = (Asset *)indexable;
2585 IndexFile::delete_index(preferences, asset, ".toc");
2586 IndexFile::delete_index(preferences, asset, ".idx");
2589 void MWindow::rebuild_indices()
2591 for(int i = 0; i < session->drag_assets->total; i++)
2593 Indexable *indexable = session->drag_assets->values[i];
2594 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2595 remove_indexfile(indexable);
2596 // Schedule index build
2597 IndexState *index_state = indexable->index_state;
2598 index_state->index_status = INDEX_NOTTESTED;
2599 if( indexable->is_asset ) {
2600 Asset *asset = (Asset *)indexable;
2601 if( asset->format != FILE_PCM )
2602 asset->reset_audio();
2603 asset->reset_video();
2605 mainindexes->add_next_asset(0, indexable);
2607 mainindexes->start_build();
2611 void MWindow::save_backup()
2614 edl->set_path(session->filename);
2615 edl->save_xml(&file,
2619 file.terminate_string();
2620 char path[BCTEXTLEN];
2622 strcpy(path, BACKUP_PATH);
2623 fs.complete_path(path);
2625 if(file.write_to_file(path))
2628 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2629 gui->show_message(string2);
2633 void MWindow::load_backup()
2635 ArrayList<char*> path_list;
2636 path_list.set_array_delete();
2638 char string[BCTEXTLEN];
2639 strcpy(string, BACKUP_PATH);
2641 fs.complete_path(string);
2643 path_list.append(out_path = new char[strlen(string) + 1]);
2644 strcpy(out_path, string);
2646 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2647 edl->local_session->clip_title[0] = 0;
2648 // This is unique to backups since the path of the backup is different than the
2649 // path of the project.
2650 set_filename(edl->path);
2651 path_list.remove_all_objects();
2655 static inline int gcd(int m, int n)
2658 if( m < n ) { r = m; m = n; n = r; }
2659 while( (r = m % n) != 0 ) { m = n; n = r; }
2663 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2666 if(!width || !height) return 1;
2667 double ar = (double)width / height;
2668 // square-ish pixels
2669 if( EQUIV(ar, 1.0000) ) return 0;
2670 if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; }
2671 if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; }
2672 if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; }
2673 if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; }
2674 if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; }
2675 int ww = width, hh = height;
2676 // numerator, denominator must be under mx
2677 int mx = 255, n = gcd(ww, hh);
2678 if( n > 1 ) { ww /= n; hh /= n; }
2679 // search near height in case extra/missing lines
2680 if( ww >= mx || hh >= mx ) {
2681 double err = height; // +/- 2 percent height
2682 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2683 int iw = width, ih = height+i;
2684 if( (n=gcd(iw, ih)) > 1 ) {
2685 int u = iw/n; if( u >= mx ) continue;
2686 int v = ih/n; if( v >= mx ) continue;
2687 double r = (double) u/v, er = fabs(ar-r);
2688 if( er >= err ) continue;
2689 err = er; ww = u; hh = v;
2698 void MWindow::reset_caches()
2700 frame_cache->remove_all();
2701 wave_cache->remove_all();
2702 audio_cache->remove_all();
2703 video_cache->remove_all();
2704 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2705 cwindow->playback_engine->audio_cache->remove_all();
2706 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2707 cwindow->playback_engine->video_cache->remove_all();
2709 for(int i = 0; i < vwindows.size(); i++)
2711 VWindow *vwindow = vwindows.get(i);
2712 if(vwindow->is_running())
2714 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2715 vwindow->playback_engine->audio_cache->remove_all();
2716 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2717 vwindow->playback_engine->video_cache->remove_all();
2722 void MWindow::remove_asset_from_caches(Asset *asset)
2724 frame_cache->remove_asset(asset);
2725 wave_cache->remove_asset(asset);
2726 audio_cache->delete_entry(asset);
2727 video_cache->delete_entry(asset);
2728 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2729 cwindow->playback_engine->audio_cache->delete_entry(asset);
2730 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2731 cwindow->playback_engine->video_cache->delete_entry(asset);
2732 for(int i = 0; i < vwindows.size(); i++)
2734 VWindow *vwindow = vwindows.get(i);
2735 if(vwindow->is_running())
2737 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2738 vwindow->playback_engine->audio_cache->delete_entry(asset);
2739 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2740 vwindow->playback_engine->video_cache->delete_entry(asset);
2747 void MWindow::remove_assets_from_project(int push_undo)
2749 for(int i = 0; i < session->drag_assets->total; i++)
2751 Indexable *indexable = session->drag_assets->values[i];
2752 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
2755 // Remove from VWindow.
2756 for(int i = 0; i < session->drag_clips->total; i++)
2758 for(int j = 0; j < vwindows.size(); j++)
2760 VWindow *vwindow = vwindows.get(j);
2761 if(vwindow->is_running())
2763 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();
2773 for(int i = 0; i < session->drag_assets->size(); i++)
2775 for(int j = 0; j < vwindows.size(); j++)
2777 VWindow *vwindow = vwindows.get(j);
2778 if(vwindow->is_running())
2780 if(session->drag_assets->get(i) == vwindow->get_source())
2782 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
2783 vwindow->delete_source(1, 1);
2784 vwindow->gui->unlock_window();
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++)
3079 VWindow *vwindow = vwindows.get(j);
3080 if(vwindow->is_running())
3082 vwindow->gui->lock_window("MWindow::reset_meters 2");
3083 vwindow->gui->meters->reset_meters();
3084 vwindow->gui->unlock_window();
3088 lwindow->gui->lock_window("MWindow::reset_meters 3");
3089 lwindow->gui->panel->reset_meters();
3090 lwindow->gui->unlock_window();
3092 gui->lock_window("MWindow::reset_meters 4");
3093 gui->reset_meters();
3094 gui->unlock_window();
3099 void MWindow::resync_guis()
3103 gui->lock_window("MWindow::resync_guis");
3104 gui->update(1, 1, 1, 1, 1, 1, 0);
3105 gui->unlock_window();
3107 cwindow->gui->lock_window("MWindow::resync_guis");
3108 cwindow->gui->resize_event(cwindow->gui->get_w(),
3109 cwindow->gui->get_h());
3110 int channels = edl->session->audio_channels;
3111 cwindow->gui->meters->set_meters(channels, 1);
3112 cwindow->gui->flush();
3113 cwindow->gui->unlock_window();
3115 for(int i = 0; i < vwindows.size(); i++)
3117 VWindow *vwindow = vwindows.get(i);
3118 vwindow->gui->lock_window("MWindow::resync_guis");
3119 vwindow->gui->resize_event(vwindow->gui->get_w(),
3120 vwindow->gui->get_h());
3121 vwindow->gui->meters->set_meters(channels, 1);
3122 vwindow->gui->flush();
3123 vwindow->gui->unlock_window();
3126 lwindow->gui->lock_window("MWindow::resync_guis");
3127 lwindow->gui->panel->set_meters(channels, 1);
3128 lwindow->gui->flush();
3129 lwindow->gui->unlock_window();
3132 if(((edl->session->output_w % 4) ||
3133 (edl->session->output_h % 4)) &&
3134 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3136 MainError::show_error(
3137 _("This project's dimensions are not multiples of 4 so\n"
3138 "it can't be rendered by OpenGL."));
3143 sync_parameters(CHANGE_ALL);
3146 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3148 File *file = new File;
3149 EDLSession *session = edl->session;
3150 double old_framerate = session->frame_rate;
3151 double old_samplerate = session->sample_rate;
3152 int result = file->open_file(preferences, asset, 1, 0);
3153 if( !result && delete_tracks > 0 )
3154 undo->update_undo_before();
3155 if( !result && asset->get_video_layers() > 0 ) {
3156 // try to get asset up to date, may fail
3157 file->select_video_stream(asset, vstream);
3158 // either way use what was/is there.
3159 double framerate = asset->get_frame_rate();
3160 int width = asset->get_w();
3161 int height = asset->get_h();
3162 // must be multiple of 4 for opengl
3163 width = (width+3) & ~3; height = (height+3) & ~3;
3164 int driver = session->playback_config->vconfig->driver;
3165 int color_model = file->get_best_colormodel(asset, driver);
3166 color_model = BC_CModels::is_yuv(color_model) ?
3167 BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3168 BC_CModels::is_float(color_model) ?
3169 BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3170 BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3171 session->color_model = color_model;
3172 session->output_w = width;
3173 session->output_h = height;
3174 session->frame_rate = framerate;
3175 // not, asset->actual_width/actual_height
3176 asset->width = session->output_w;
3177 asset->height = session->output_h;
3178 asset->frame_rate = session->frame_rate;
3179 create_aspect_ratio(session->aspect_w, session->aspect_h,
3180 session->output_w, session->output_h);
3181 Track *track = edl->tracks->first;
3182 for( Track *next_track=0; track; track=next_track ) {
3183 next_track = track->next;
3184 if( track->data_type != TRACK_VIDEO ) continue;
3185 if( delete_tracks ) {
3186 Edit *edit = track->edits->first;
3187 for( Edit *next_edit=0; edit; edit=next_edit ) {
3188 next_edit = edit->next;
3189 if( edit->channel != vstream ||
3190 !edit->asset || !edit->asset->is_asset ||
3191 *asset != *edit->asset )
3195 if( track->edits->first ) {
3196 track->track_w = edl->session->output_w;
3197 track->track_h = edl->session->output_h;
3199 else if( delete_tracks )
3200 edl->tracks->delete_track(track);
3202 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3204 if( !result && asset->channels > 0 ) {
3205 session->sample_rate = asset->get_sample_rate();
3206 int64_t channel_mask = 0;
3207 int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
3208 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3209 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3211 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3212 if( channels > 6 ) channels = 6;
3213 session->audio_tracks = session->audio_channels = channels;
3214 switch( channels ) {
3216 session->achannel_positions[0] = 90;
3217 session->achannel_positions[1] = 150;
3218 session->achannel_positions[2] = 30;
3219 session->achannel_positions[3] = 210;
3220 session->achannel_positions[4] = 330;
3221 session->achannel_positions[5] = 270;
3224 session->achannel_positions[0] = 180;
3225 session->achannel_positions[1] = 0;
3228 remap_audio(MWindow::AUDIO_1_TO_1);
3230 if( delete_tracks ) {
3231 Track *track = edl->tracks->first;
3232 for( Track *next_track=0; track; track=next_track ) {
3233 next_track = track->next;
3234 if( track->data_type != TRACK_AUDIO ) continue;
3235 Edit *edit = track->edits->first;
3236 for( Edit *next_edit=0; edit; edit=next_edit ) {
3237 next_edit = edit->next;
3238 if( !((1<<edit->channel) & channel_mask) ||
3239 !edit->asset || !edit->asset->is_asset ||
3240 *asset != *edit->asset )
3243 if( !track->edits->first )
3244 edl->tracks->delete_track(track);
3248 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3251 if( !result && delete_tracks > 0 ) {
3253 undo->update_undo_after(_("select asset"), LOAD_ALL);
3259 int MWindow::select_asset(int vtrack, int delete_tracks)
3261 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3262 if( !track ) return 1;
3263 Edit *edit = track->edits->first;
3264 if( !edit ) return 1;
3265 Asset *asset = edit->asset;
3266 if( !asset || !asset->is_asset ) return 1;
3267 return select_asset(asset, edit->channel, -1, delete_tracks);
3270 void MWindow::dump_plugindb(FILE *fp)
3272 if( !plugindb ) return;
3273 for(int i = 0; i < plugindb->total; i++)
3274 plugindb->values[i]->dump(fp);