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->set_selectionstart(0);
1426 edl->local_session->set_selectionend(0);
1432 update_project(load_mode);
1434 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1436 for(int i = 0; i < new_edls.size(); i++)
1438 new_edls.get(i)->remove_user();
1440 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1442 new_edls.remove_all();
1444 for(int i = 0; i < new_assets.size(); i++)
1446 new_assets.get(i)->Garbage::remove_user();
1449 new_assets.remove_all();
1450 new_files.remove_all_objects();
1452 undo->update_undo_after(_("load"), LOAD_ALL);
1454 if(load_mode == LOADMODE_REPLACE ||
1455 load_mode == LOADMODE_REPLACE_CONCATENATE)
1457 session->changes_made = 0;
1461 session->changes_made = 1;
1464 gui->stop_hourglass();
1467 if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
1474 void MWindow::test_plugins(EDL *new_edl, char *path)
1476 char string[BCTEXTLEN];
1478 // Do a check weather plugins exist
1479 for(Track *track = new_edl->tracks->first; track; track = track->next)
1481 for(int k = 0; k < track->plugin_set.total; k++)
1483 PluginSet *plugin_set = track->plugin_set.values[k];
1484 for(Plugin *plugin = (Plugin*)plugin_set->first;
1486 plugin = (Plugin*)plugin->next)
1488 if(plugin->plugin_type == PLUGIN_STANDALONE)
1490 // ok we need to find it in plugindb
1491 int plugin_found = 0;
1493 for(int j = 0; j < plugindb->size(); j++)
1495 PluginServer *server = plugindb->get(j);
1497 !strcasecmp(server->title, plugin->title) &&
1498 ((track->data_type == TRACK_AUDIO && server->audio) ||
1499 (track->data_type == TRACK_VIDEO && server->video)) &&
1500 (!server->transition))
1507 "The effect '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1508 "The project won't be rendered as it was meant and Cinelerra might crash.\n",
1511 MainError::show_error(string);
1517 for(Edit *edit = (Edit*)track->edits->first;
1519 edit = (Edit*)edit->next)
1521 if (edit->transition)
1523 // ok we need to find transition in plugindb
1525 int transition_found = 0;
1526 for(int j = 0; j < plugindb->size(); j++)
1528 PluginServer *server = plugindb->get(j);
1530 !strcasecmp(server->title, edit->transition->title) &&
1531 ((track->data_type == TRACK_AUDIO && server->audio) ||
1532 (track->data_type == TRACK_VIDEO && server->video)) &&
1533 (server->transition))
1534 transition_found = 1;
1537 if (!transition_found)
1540 "The transition '%s' in file '%s' is not part of your installation of Cinelerra.\n"
1541 "The project won't be rendered as it was meant and Cinelerra might crash.\n",
1542 edit->transition->title,
1544 MainError::show_error(string);
1552 void MWindow::init_shm()
1554 // Fix shared memory
1555 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
1557 fprintf(fd, "0x7fffffff");
1562 fd = fopen("/proc/sys/kernel/shmmax", "r");
1564 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
1569 fscanf(fd, _LD, &result);
1572 if(result < 0x7fffffff) {
1573 char string[BCTEXTLEN];
1574 sprintf(string, "MWindow::init_shm: /proc/sys/kernel/shmmax is 0x" _LX ".\n"
1575 "you probably need to be root, or:\n"
1576 "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
1577 "before trying to start cinelerra.\n"
1578 "It should be at least 0x7fffffff for Cinelerra.\n", result);
1579 MainError::show_error(string);
1584 void MWindow::init_fileserver(Preferences *preferences)
1587 if( !file_server && preferences->file_forking ) {
1588 file_server = new FileServer(preferences);
1589 file_server->start();
1594 void MWindow::create_objects(int want_gui,
1599 const int debug = 0;
1600 if(debug) PRINT_TRACE
1602 // For some reason, init_signals must come after show_splash or the signals won't
1605 if(debug) PRINT_TRACE
1608 if(debug) PRINT_TRACE
1611 if(debug) PRINT_TRACE
1612 init_defaults(defaults, config_path);
1614 init_plugins(this, preferences);
1615 if(debug) PRINT_TRACE
1616 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1617 if(debug) PRINT_TRACE
1619 if(debug) PRINT_TRACE
1622 char string[BCTEXTLEN];
1623 strcpy(string, preferences->plugin_dir);
1624 strcat(string, "/fonts");
1625 BC_Resources::init_fontconfig(string);
1626 if(debug) PRINT_TRACE
1628 // Initialize before too much else is running
1629 // Preferences & theme are required for building MPEG table of contents
1630 init_fileserver(preferences);
1632 // Default project created here
1634 if(debug) PRINT_TRACE
1637 if(debug) PRINT_TRACE
1642 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1644 //printf("MWindow::create_objects %d session->show_vwindow=%d\n", __LINE__, session->show_vwindow);
1645 if(session->show_vwindow)
1646 get_viewer(1, DEFAULT_VWINDOW);
1647 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1650 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1653 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1656 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1658 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1661 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1665 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1667 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1669 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1672 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1673 mainprogress = new MainProgress(this, gui);
1674 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1675 undo = new MainUndo(this);
1677 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1679 plugin_guis = new ArrayList<PluginServer*>;
1680 dead_plugins = new ArrayList<PluginServer*>;
1681 keyframe_threads = new ArrayList<KeyFrameThread*>;
1683 if(debug) printf("MWindow::create_objects %d vwindows=%d show_vwindow=%d\n",
1686 session->show_vwindow);
1688 // Show all vwindows
1689 // if(session->show_vwindow)
1691 // for(int j = 0; j < vwindows.size(); j++)
1693 // VWindow *vwindow = vwindows.get(j);
1694 // if(debug) printf("MWindow::create_objects %d vwindow=%p\n",
1697 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1698 // vwindow->gui->lock_window("MWindow::create_objects 1");
1699 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1700 // vwindow->gui->show_window();
1701 // if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1702 // vwindow->gui->unlock_window();
1707 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1709 if(session->show_cwindow)
1711 cwindow->gui->lock_window("MWindow::create_objects 1");
1712 cwindow->gui->show_window();
1713 cwindow->gui->unlock_window();
1716 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1717 if(session->show_awindow)
1719 awindow->gui->lock_window("MWindow::create_objects 1");
1720 awindow->gui->show_window();
1721 awindow->gui->unlock_window();
1724 if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
1725 if(session->show_lwindow)
1727 lwindow->gui->lock_window("MWindow::create_objects 1");
1728 lwindow->gui->show_window();
1729 lwindow->gui->unlock_window();
1732 if(debug) printf("MWindow::create_objects %d total_time=%d gwindow=%p\n",
1734 (int)timer.get_difference(),
1736 if(session->show_gwindow)
1738 gwindow->gui->lock_window("MWindow::create_objects 1");
1739 gwindow->gui->show_window();
1740 gwindow->gui->unlock_window();
1743 if(debug) PRINT_TRACE
1745 gui->lock_window("MWindow::create_objects 1");
1746 gui->mainmenu->load_defaults(defaults);
1747 gui->mainmenu->update_toggles(0);
1748 gui->update_patchbay();
1749 gui->draw_canvas(0, 0);
1750 gui->draw_cursor(1);
1752 gui->raise_window();
1753 gui->unlock_window();
1755 if(debug) PRINT_TRACE
1759 if(preferences->use_tipwindow)
1761 if(debug) PRINT_TRACE
1763 gui->add_keyboard_listener(
1764 (int (BC_WindowBase::*)(BC_WindowBase *))
1765 &MWindowGUI::keyboard_listener);
1769 if(debug) PRINT_TRACE
1771 BC_WindowBase::get_resources()->vframe_shm = 1;
1776 void MWindow::show_splash()
1778 #include "data/heroine_logo11_png.h"
1779 VFrame *frame = new VFrame(heroine_logo11_png);
1780 BC_DisplayInfo display_info;
1781 splash_window = new SplashGUI(frame,
1782 display_info.get_root_w() / 2 - frame->get_w() / 2,
1783 display_info.get_root_h() / 2 - frame->get_h() / 2);
1784 splash_window->create_objects();
1787 void MWindow::hide_splash()
1790 delete splash_window;
1795 void MWindow::start()
1799 // vwindows.get(DEFAULT_VWINDOW)->start();
1810 playback_3d->start();
1819 void MWindow::show_vwindow()
1821 int total_running = 0;
1822 session->show_vwindow = 1;
1825 // Raise all windows which are visible
1826 for(int j = 0; j < vwindows.size(); j++)
1828 VWindow *vwindow = vwindows.get(j);
1829 if(vwindow->is_running())
1831 vwindow->gui->lock_window("MWindow::show_vwindow");
1832 vwindow->gui->show_window(0);
1833 vwindow->gui->raise_window();
1834 vwindow->gui->flush();
1835 vwindow->gui->unlock_window();
1840 //printf("MWindow::show_vwindow %d %d\n", __LINE__, vwindows.size());
1841 // If no windows visible
1844 get_viewer(1, DEFAULT_VWINDOW);
1847 gui->mainmenu->show_vwindow->set_checked(1);
1850 void MWindow::show_awindow()
1852 session->show_awindow = 1;
1853 awindow->gui->lock_window("MWindow::show_awindow");
1854 awindow->gui->show_window();
1855 awindow->gui->raise_window();
1856 awindow->gui->flush();
1857 awindow->gui->unlock_window();
1858 gui->mainmenu->show_awindow->set_checked(1);
1861 char *MWindow::get_cwindow_display()
1863 char *x11_host = screens < 2 || session->window_config == 0 ?
1864 session->a_x11_host : session->b_x11_host;
1865 return *x11_host ? x11_host : 0;
1868 void MWindow::show_cwindow()
1870 session->show_cwindow = 1;
1871 cwindow->show_window();
1872 gui->mainmenu->show_cwindow->set_checked(1);
1875 void MWindow::show_gwindow()
1877 session->show_gwindow = 1;
1879 gwindow->gui->lock_window("MWindow::show_gwindow");
1880 gwindow->gui->show_window();
1881 gwindow->gui->raise_window();
1882 gwindow->gui->flush();
1883 gwindow->gui->unlock_window();
1885 gui->mainmenu->show_gwindow->set_checked(1);
1888 void MWindow::show_lwindow()
1890 session->show_lwindow = 1;
1891 lwindow->gui->lock_window("MWindow::show_lwindow");
1892 lwindow->gui->show_window();
1893 lwindow->gui->raise_window();
1894 lwindow->gui->flush();
1895 lwindow->gui->unlock_window();
1896 gui->mainmenu->show_lwindow->set_checked(1);
1899 int MWindow::tile_windows(int window_config)
1901 int need_reload = 0;
1902 int play_config = window_config==0 ? 0 : 1;
1903 edl->session->playback_config->load_defaults(defaults, play_config);
1904 session->default_window_positions(window_config);
1905 if( screens == 1 ) {
1906 gui->default_positions();
1907 sync_parameters(CHANGE_ALL);
1914 void MWindow::toggle_loop_playback()
1916 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1917 set_loop_boundaries();
1920 gui->draw_overlays(1);
1921 sync_parameters(CHANGE_PARAMS);
1924 //void MWindow::set_titles(int value)
1926 // edl->session->show_titles = value;
1927 // trackmovement(edl->local_session->track_start);
1930 void MWindow::set_screens(int value)
1935 void MWindow::set_auto_keyframes(int value, int lock_mwindow, int lock_cwindow)
1937 if(lock_mwindow) gui->lock_window("MWindow::set_auto_keyframes");
1938 edl->session->auto_keyframes = value;
1939 gui->mbuttons->edit_panel->keyframe->update(value);
1941 if(lock_mwindow) gui->unlock_window();
1943 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1944 cwindow->gui->edit_panel->keyframe->update(value);
1945 cwindow->gui->flush();
1946 if(lock_cwindow) cwindow->gui->unlock_window();
1949 void MWindow::set_keyframe_type(int mode)
1951 gui->lock_window("MWindow::set_keyframe_type");
1952 edl->local_session->floatauto_type = mode;
1953 gui->mainmenu->update_toggles(0);
1954 gui->unlock_window();
1957 int MWindow::set_editing_mode(int new_editing_mode, int lock_mwindow, int lock_cwindow)
1959 if(lock_mwindow) gui->lock_window("MWindow::set_editing_mode");
1960 edl->session->editing_mode = new_editing_mode;
1961 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1962 gui->mbuttons->edit_panel->update();
1963 gui->set_editing_mode(1);
1964 if(lock_mwindow) gui->unlock_window();
1967 if(lock_cwindow) cwindow->gui->lock_window("MWindow::set_editing_mode");
1968 cwindow->gui->edit_panel->update();
1969 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1970 if(lock_cwindow) cwindow->gui->unlock_window();
1975 void MWindow::sync_parameters(int change_type)
1978 // Sync engines which are playing back
1979 if(cwindow->playback_engine->is_playing_back)
1981 if(change_type == CHANGE_PARAMS)
1983 // TODO: block keyframes until synchronization is done
1984 cwindow->playback_engine->sync_parameters(edl);
1989 int command = cwindow->playback_engine->command->command;
1990 cwindow->playback_engine->que->send_command(STOP,
1994 // Waiting for tracking to finish would make the restart position more
1995 // accurate but it can't lock the window to stop tracking for some reason.
1996 // Not waiting for tracking gives a faster response but restart position is
1997 // only as accurate as the last tracking update.
1998 cwindow->playback_engine->interrupt_playback(0);
1999 cwindow->playback_engine->que->send_command(command,
2008 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2015 void MWindow::age_caches()
2017 // printf("MWindow::age_caches %d %lld %lld %lld %lld\n",
2019 // preferences->cache_size,
2020 // audio_cache->get_memory_usage(1),
2021 // video_cache->get_memory_usage(1),
2022 // frame_cache->get_memory_usage(),
2023 // wave_cache->get_memory_usage(),
2025 frame_cache->age_cache(512);
2026 wave_cache->age_cache(8192);
2028 int64_t memory_usage;
2029 int64_t prev_memory_usage = 0;
2031 int64_t video_size = (int64_t)(preferences->cache_size * 0.80);
2032 while( !result && prev_memory_usage !=
2033 (memory_usage=video_cache->get_memory_usage(1)) &&
2034 memory_usage > video_size ) {
2035 video_cache->delete_oldest();
2036 prev_memory_usage = memory_usage;
2039 prev_memory_usage = 0;
2041 int64_t audio_size = (int64_t)(preferences->cache_size * 0.20);
2042 while( !result && prev_memory_usage !=
2043 (memory_usage=audio_cache->get_memory_usage(1)) &&
2044 memory_usage > audio_size ) {
2045 audio_cache->delete_oldest();
2046 prev_memory_usage = memory_usage;
2050 void MWindow::reset_android_remote()
2052 gui->use_android_remote(preferences->android_remote);
2056 void MWindow::show_keyframe_gui(Plugin *plugin)
2058 keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
2059 // Find existing thread
2060 for(int i = 0; i < keyframe_threads->size(); i++)
2062 if(keyframe_threads->get(i)->plugin == plugin)
2064 keyframe_threads->get(i)->start_window(plugin, 0);
2065 keyframe_gui_lock->unlock();
2070 // Find unused thread
2071 for(int i = 0; i < keyframe_threads->size(); i++)
2073 if(!keyframe_threads->get(i)->plugin)
2075 keyframe_threads->get(i)->start_window(plugin, 0);
2076 keyframe_gui_lock->unlock();
2081 // Create new thread
2082 KeyFrameThread *thread = new KeyFrameThread(this);
2083 keyframe_threads->append(thread);
2084 thread->start_window(plugin, 0);
2086 keyframe_gui_lock->unlock();
2093 void MWindow::show_plugin(Plugin *plugin)
2098 // Remove previously deleted plugin GUIs
2099 dead_plugin_lock->lock("MWindow::delete_plugin");
2100 for(int i = 0; i < dead_plugins->size(); i++)
2102 delete dead_plugins->get(i);
2104 dead_plugins->remove_all();
2105 dead_plugin_lock->unlock();
2107 //printf("MWindow::show_plugin %d\n", __LINE__);
2111 plugin_gui_lock->lock("MWindow::show_plugin");
2112 for(int i = 0; i < plugin_guis->total; i++)
2114 // Pointer comparison
2115 if(plugin_guis->values[i]->plugin == plugin)
2117 plugin_guis->values[i]->raise_window();
2124 //printf("MWindow::show_plugin 1\n");
2129 printf("MWindow::show_plugin track not defined.\n");
2131 PluginServer *server = scan_plugindb(plugin->title,
2132 plugin->track->data_type);
2134 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
2135 if(server && server->uses_gui)
2137 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
2138 // Needs mwindow to do GUI
2139 gui->set_mwindow(this);
2140 gui->open_plugin(0, preferences, edl, plugin);
2145 plugin_gui_lock->unlock();
2146 //printf("MWindow::show_plugin %d\n", __LINE__);
2149 //printf("MWindow::show_plugin 2\n");
2152 void MWindow::hide_plugin(Plugin *plugin, int lock)
2155 // Update the toggle
2156 gui->lock_window("MWindow::hide_plugin");
2157 gui->update(0, 1, 0, 0, 0, 0, 0);
2158 gui->unlock_window();
2160 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
2161 for(int i = 0; i < plugin_guis->total; i++)
2163 if(plugin_guis->values[i]->plugin == plugin)
2165 PluginServer *ptr = plugin_guis->values[i];
2166 plugin_guis->remove(ptr);
2167 if(lock) plugin_gui_lock->unlock();
2168 // Last command executed in client side close
2169 // Schedule for deletion
2176 if(lock) plugin_gui_lock->unlock();
2179 void MWindow::delete_plugin(PluginServer *plugin)
2181 dead_plugin_lock->lock("MWindow::delete_plugin");
2182 dead_plugins->append(plugin);
2183 dead_plugin_lock->unlock();
2186 void MWindow::hide_plugins()
2188 plugin_gui_lock->lock("MWindow::hide_plugins 1");
2189 while(plugin_guis->size())
2191 PluginServer *ptr = plugin_guis->get(0);
2192 plugin_guis->remove(ptr);
2193 plugin_gui_lock->unlock();
2194 // Last command executed in client side close
2195 // Schedule for deletion
2198 plugin_gui_lock->lock("MWindow::hide_plugins 2");
2200 plugin_gui_lock->unlock();
2202 hide_keyframe_guis();
2205 void MWindow::hide_keyframe_guis()
2207 keyframe_gui_lock->lock("MWindow::hide_keyframe_guis");
2208 for(int i = 0; i < keyframe_threads->size(); i++)
2210 keyframe_threads->get(i)->close_window();
2212 keyframe_gui_lock->unlock();
2215 void MWindow::hide_keyframe_gui(Plugin *plugin)
2217 keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
2218 for(int i = 0; i < keyframe_threads->size(); i++)
2220 if(keyframe_threads->get(i)->plugin == plugin)
2222 keyframe_threads->get(i)->close_window();
2226 keyframe_gui_lock->unlock();
2229 void MWindow::update_keyframe_guis()
2231 // Send new configuration to keyframe GUI's
2232 keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
2233 for(int i = 0; i < keyframe_threads->size(); i++)
2235 KeyFrameThread *ptr = keyframe_threads->get(i);
2236 if(edl->tracks->plugin_exists(ptr->plugin))
2240 ptr->close_window();
2243 keyframe_gui_lock->unlock();
2246 void MWindow::update_plugin_guis(int do_keyframe_guis)
2248 // Send new configuration to plugin GUI's
2249 plugin_gui_lock->lock("MWindow::update_plugin_guis");
2251 for(int i = 0; i < plugin_guis->size(); i++)
2253 PluginServer *ptr = plugin_guis->get(i);
2254 if(edl->tracks->plugin_exists(ptr->plugin))
2258 // Schedule for deletion if no plugin
2259 plugin_guis->remove_number(i);
2268 // Change plugin variable if not visible
2269 Track *track = edl->tracks->first;
2272 for(int i = 0; i < track->plugin_set.size(); i++)
2274 Plugin *plugin = (Plugin*)track->plugin_set.get(i)->first;
2278 for(int i = 0; i < plugin_guis->size(); i++)
2280 PluginServer *server = plugin_guis->get(i);
2281 if(server->plugin == plugin)
2288 if(!got_it) plugin->show = 0;
2290 plugin = (Plugin*)plugin->next;
2294 track = track->next;
2297 plugin_gui_lock->unlock();
2300 if(do_keyframe_guis) update_keyframe_guis();
2303 int MWindow::plugin_gui_open(Plugin *plugin)
2306 plugin_gui_lock->lock("MWindow::plugin_gui_open");
2307 for(int i = 0; i < plugin_guis->total; i++)
2309 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2315 plugin_gui_lock->unlock();
2319 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
2321 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2322 for(int i = 0; i < plugin_guis->total; i++)
2324 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2326 plugin_guis->values[i]->render_gui(data);
2330 plugin_gui_lock->unlock();
2333 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
2335 plugin_gui_lock->lock("MWindow::render_plugin_gui");
2336 for(int i = 0; i < plugin_guis->total; i++)
2338 if(plugin_guis->values[i]->plugin->identical_location(plugin))
2340 plugin_guis->values[i]->render_gui(data, size);
2344 plugin_gui_lock->unlock();
2348 void MWindow::update_plugin_states()
2350 plugin_gui_lock->lock("MWindow::update_plugin_states");
2351 for(int i = 0; i < plugin_guis->total; i++)
2355 Plugin *src_plugin = plugin_guis->values[i]->plugin;
2356 PluginServer *src_plugingui = plugin_guis->values[i];
2358 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
2359 for(Track *track = edl->tracks->first;
2361 track = track->next)
2364 j < track->plugin_set.total && !result;
2367 PluginSet *plugin_set = track->plugin_set.values[j];
2368 for(Plugin *plugin = (Plugin*)plugin_set->first;
2370 plugin = (Plugin*)plugin->next)
2372 if(plugin == src_plugin &&
2373 !strcmp(plugin->title, src_plugingui->title)) result = 1;
2379 // Doesn't exist anymore
2382 hide_plugin(src_plugin, 0);
2386 plugin_gui_lock->unlock();
2390 void MWindow::update_plugin_titles()
2392 for(int i = 0; i < plugin_guis->total; i++)
2394 plugin_guis->values[i]->update_title();
2398 int MWindow::asset_to_edl(EDL *new_edl,
2400 RecordLabels *labels)
2402 const int debug = 0;
2403 if(debug) printf("MWindow::asset_to_edl %d new_asset->layers=%d\n",
2406 // Keep frame rate, sample rate, and output size unchanged.
2407 // These parameters would revert the project if VWindow displayed an asset
2408 // of different size than the project.
2409 if(new_asset->video_data)
2411 new_edl->session->video_tracks = new_asset->layers;
2414 new_edl->session->video_tracks = 0;
2416 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2422 if(new_asset->audio_data)
2424 new_edl->session->audio_tracks = new_asset->channels;
2427 new_edl->session->audio_tracks = 0;
2428 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2430 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2431 new_edl->create_default_tracks();
2432 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
2433 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2437 //printf("MWindow::asset_to_edl 3\n");
2438 new_edl->insert_asset(new_asset,
2443 //printf("MWindow::asset_to_edl 3\n");
2444 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2450 char string[BCTEXTLEN];
2452 fs.extract_name(string, new_asset->path);
2453 //printf("MWindow::asset_to_edl 3\n");
2455 strcpy(new_edl->local_session->clip_title, string);
2456 //printf("MWindow::asset_to_edl 4 %s\n", string);
2457 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
2462 int MWindow::edl_to_nested(EDL *new_edl,
2466 // Keep frame rate, sample rate, and output size unchanged.
2467 // These parameters would revert the project if VWindow displayed an asset
2468 // of different size than the project.
2472 // Nest all video & audio outputs
2473 new_edl->session->video_tracks = 1;
2474 new_edl->session->audio_tracks = nested_edl->session->audio_channels;
2475 new_edl->create_default_tracks();
2479 new_edl->insert_asset(0,
2485 char string[BCTEXTLEN];
2487 fs.extract_name(string, nested_edl->path);
2488 //printf("MWindow::edl_to_nested %p %s\n", nested_edl, nested_edl->path);
2490 strcpy(new_edl->local_session->clip_title, string);
2495 // Reset everything after a load.
2496 void MWindow::update_project(int load_mode)
2498 const int debug = 0;
2500 if(debug) PRINT_TRACE
2502 edl->tracks->update_y_pixels(theme);
2504 if(debug) PRINT_TRACE
2506 if(load_mode == LOADMODE_REPLACE ||
2507 load_mode == LOADMODE_REPLACE_CONCATENATE)
2512 gui->update(1, 1, 1, 1, 1, 1, 1);
2513 if(debug) PRINT_TRACE
2514 gui->unlock_window();
2516 cwindow->gui->lock_window("MWindow::update_project 1");
2517 cwindow->update(0, 0, 1, 1, 1);
2518 cwindow->gui->unlock_window();
2520 if(debug) PRINT_TRACE
2522 // Close all the vwindows
2523 if(load_mode == LOADMODE_REPLACE ||
2524 load_mode == LOADMODE_REPLACE_CONCATENATE)
2526 if(debug) PRINT_TRACE
2527 int first_vwindow = 0;
2528 if(session->show_vwindow) first_vwindow = 1;
2529 // Change visible windows to no source
2530 for(int i = 0; i < first_vwindow && i < vwindows.size(); i++)
2532 vwindows.get(i)->change_source(-1);
2535 // Close remaining windows
2536 for(int i = first_vwindow; i < vwindows.size(); i++)
2538 vwindows.get(i)->close_window();
2540 if(debug) PRINT_TRACE
2545 VWindow *vwindow = vwindows.get(DEFAULT_VWINDOW);
2546 if(vwindow->is_running())
2548 vwindow->gui->lock_window("MWindow::update_project");
2550 vwindow->gui->unlock_window();
2554 if(debug) PRINT_TRACE
2555 cwindow->gui->lock_window("MWindow::update_project 2");
2556 cwindow->gui->timebar->update(0);
2557 cwindow->gui->unlock_window();
2559 if(debug) PRINT_TRACE
2560 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2565 if(debug) PRINT_TRACE
2567 awindow->gui->lock_window("MWindow::update_project");
2568 awindow->gui->update_assets();
2569 awindow->gui->flush();
2570 awindow->gui->unlock_window();
2572 if(debug) PRINT_TRACE
2574 gui->lock_window("MWindow::update_project");
2576 if(debug) PRINT_TRACE
2579 void MWindow::remove_indexfile(Indexable *indexable)
2581 if( !indexable->is_asset ) return;
2582 Asset *asset = (Asset *)indexable;
2584 IndexFile::delete_index(preferences, asset, ".toc");
2585 IndexFile::delete_index(preferences, asset, ".idx");
2588 void MWindow::rebuild_indices()
2590 for(int i = 0; i < session->drag_assets->total; i++)
2592 Indexable *indexable = session->drag_assets->values[i];
2593 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
2594 remove_indexfile(indexable);
2595 // Schedule index build
2596 IndexState *index_state = indexable->index_state;
2597 index_state->index_status = INDEX_NOTTESTED;
2598 if( indexable->is_asset ) {
2599 Asset *asset = (Asset *)indexable;
2600 if( asset->format != FILE_PCM )
2601 asset->reset_audio();
2602 asset->reset_video();
2604 mainindexes->add_next_asset(0, indexable);
2606 mainindexes->start_build();
2610 void MWindow::save_backup()
2613 edl->set_path(session->filename);
2614 edl->save_xml(&file,
2618 file.terminate_string();
2619 char path[BCTEXTLEN];
2621 strcpy(path, BACKUP_PATH);
2622 fs.complete_path(path);
2624 if(file.write_to_file(path))
2627 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
2628 gui->show_message(string2);
2632 void MWindow::load_backup()
2634 ArrayList<char*> path_list;
2635 path_list.set_array_delete();
2637 char string[BCTEXTLEN];
2638 strcpy(string, BACKUP_PATH);
2640 fs.complete_path(string);
2642 path_list.append(out_path = new char[strlen(string) + 1]);
2643 strcpy(out_path, string);
2645 load_filenames(&path_list, LOADMODE_REPLACE, 0);
2646 edl->local_session->clip_title[0] = 0;
2647 // This is unique to backups since the path of the backup is different than the
2648 // path of the project.
2649 set_filename(edl->path);
2650 path_list.remove_all_objects();
2654 static inline int gcd(int m, int n)
2657 if( m < n ) { r = m; m = n; n = r; }
2658 while( (r = m % n) != 0 ) { m = n; n = r; }
2662 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
2664 if(!width || !height) return 1;
2665 double ar = (double)width / height;
2666 int ww = width, hh = height;
2667 // numerator, denominator must be under mx
2668 int mx = 255, n = gcd(ww, hh);
2669 if( n > 1 ) { ww /= n; hh /= n; }
2670 // search near height in case extra/missing lines
2671 if( ww >= mx || hh >= mx ) {
2672 double err = height; // +/- 2 percent height
2673 for( int m=2*height/100, i=1; m>0; i=i>0 ? -i : (--m, -i+1) ) {
2674 int iw = width, ih = height+i;
2675 if( (n=gcd(iw, ih)) > 1 ) {
2676 int u = iw/n; if( u >= mx ) continue;
2677 int v = ih/n; if( v >= mx ) continue;
2678 double r = (double) u/v, er = fabs(ar-r);
2679 if( er >= err ) continue;
2680 err = er; ww = u; hh = v;
2689 void MWindow::reset_caches()
2691 frame_cache->remove_all();
2692 wave_cache->remove_all();
2693 audio_cache->remove_all();
2694 video_cache->remove_all();
2695 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2696 cwindow->playback_engine->audio_cache->remove_all();
2697 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2698 cwindow->playback_engine->video_cache->remove_all();
2700 for(int i = 0; i < vwindows.size(); i++)
2702 VWindow *vwindow = vwindows.get(i);
2703 if(vwindow->is_running())
2705 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2706 vwindow->playback_engine->audio_cache->remove_all();
2707 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2708 vwindow->playback_engine->video_cache->remove_all();
2713 void MWindow::remove_asset_from_caches(Asset *asset)
2715 frame_cache->remove_asset(asset);
2716 wave_cache->remove_asset(asset);
2717 audio_cache->delete_entry(asset);
2718 video_cache->delete_entry(asset);
2719 if( cwindow->playback_engine && cwindow->playback_engine->audio_cache )
2720 cwindow->playback_engine->audio_cache->delete_entry(asset);
2721 if( cwindow->playback_engine && cwindow->playback_engine->video_cache )
2722 cwindow->playback_engine->video_cache->delete_entry(asset);
2723 for(int i = 0; i < vwindows.size(); i++)
2725 VWindow *vwindow = vwindows.get(i);
2726 if(vwindow->is_running())
2728 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
2729 vwindow->playback_engine->audio_cache->delete_entry(asset);
2730 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
2731 vwindow->playback_engine->video_cache->delete_entry(asset);
2738 void MWindow::remove_assets_from_project(int push_undo)
2740 for(int i = 0; i < session->drag_assets->total; i++)
2742 Indexable *indexable = session->drag_assets->values[i];
2743 if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
2746 // Remove from VWindow.
2747 for(int i = 0; i < session->drag_clips->total; i++)
2749 for(int j = 0; j < vwindows.size(); j++)
2751 VWindow *vwindow = vwindows.get(j);
2752 if(vwindow->is_running())
2754 if(session->drag_clips->values[i] == vwindow->get_edl())
2756 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
2757 vwindow->delete_source(1, 1);
2758 vwindow->gui->unlock_window();
2764 for(int i = 0; i < session->drag_assets->size(); i++)
2766 for(int j = 0; j < vwindows.size(); j++)
2768 VWindow *vwindow = vwindows.get(j);
2769 if(vwindow->is_running())
2771 if(session->drag_assets->get(i) == vwindow->get_source())
2773 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
2774 vwindow->delete_source(1, 1);
2775 vwindow->gui->unlock_window();
2781 if(push_undo) undo->update_undo_before();
2782 edl->remove_from_project(session->drag_assets);
2783 edl->remove_from_project(session->drag_clips);
2785 if(push_undo) undo->update_undo_after(_("remove assets"), LOAD_ALL);
2788 gui->lock_window("MWindow::remove_assets_from_project 3");
2796 gui->unlock_window();
2798 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
2799 awindow->gui->update_assets();
2800 awindow->gui->flush();
2801 awindow->gui->unlock_window();
2803 // Removes from playback here
2804 sync_parameters(CHANGE_ALL);
2807 void MWindow::remove_assets_from_disk()
2810 for(int i = 0; i < session->drag_assets->total; i++)
2812 remove(session->drag_assets->values[i]->path);
2815 remove_assets_from_project(1);
2818 void MWindow::dump_plugins(FILE *fp)
2820 if( !plugindb ) return;
2821 for(int i = 0; i < plugindb->total; i++)
2823 fprintf(fp, "audio=%d video=%d rt=%d multi=%d"
2824 " synth=%d transition=%d theme=%d %s\n",
2825 plugindb->values[i]->audio,
2826 plugindb->values[i]->video,
2827 plugindb->values[i]->realtime,
2828 plugindb->values[i]->multichannel,
2829 plugindb->values[i]->get_synthesis(),
2830 plugindb->values[i]->transition,
2831 plugindb->values[i]->theme,
2832 plugindb->values[i]->title);
2836 void MWindow::dump_edl(FILE *fp)
2842 void MWindow::dump_undo(FILE *fp)
2848 void MWindow::dump_exe(FILE *fp)
2850 char proc_path[BCTEXTLEN], exe_path[BCTEXTLEN];
2851 sprintf(proc_path, "/proc/%d/exe", (int)getpid());
2852 int len = readlink(proc_path, exe_path, sizeof(exe_path));
2853 if( len < 0 ) { fprintf(fp,"readlink: %m\n"); return; }
2856 if( stat(exe_path,&st) ) { fprintf(fp,"stat: %m\n"); return; }
2857 fprintf(fp, "path: %s = %9jd bytes\n",exe_path,st.st_size);
2858 int fd = open(exe_path,O_RDONLY);
2859 if( fd < 0 ) { fprintf(fp,"open: %m\n"); return; }
2860 uint8_t buf[65536]; SHA1 sha1;
2861 while( (len=read(fd,buf,sizeof(buf))) > 0 ) {
2862 sha1.addBytes(buf, len);
2865 fprintf(fp, "SHA1: ");
2866 uint8_t digest[20]; sha1.computeHash(digest);
2867 for( int i=0; i<20; ++i ) fprintf(fp, "%02x", digest[i]);
2872 void MWindow::trap_hook(FILE *fp, void *vp)
2874 MWindow *mwindow = (MWindow *)vp;
2875 fprintf(fp, "\nEXE:\n");
2876 mwindow->dump_exe(fp);
2877 fprintf(fp, "\nPLUGINS:\n");
2878 mwindow->dump_plugins(fp);
2879 fprintf(fp, "\nEDL:\n");
2880 mwindow->dump_edl(fp);
2881 fprintf(fp, "\nUNDO:\n");
2882 mwindow->dump_undo(fp);
2890 int MWindow::save_defaults()
2892 gui->save_defaults(defaults);
2893 edl->save_defaults(defaults);
2894 session->save_defaults(defaults);
2895 preferences->save_defaults(defaults);
2897 for(int i = 0; i < plugin_guis->total; i++)
2899 // Pointer comparison
2900 plugin_guis->values[i]->save_defaults();
2907 int MWindow::run_script(FileXML *script)
2909 int result = 0, result2 = 0;
2910 while(!result && !result2)
2912 result = script->read_tag();
2915 if(script->tag.title_is("new_project"))
2917 // Run new in immediate mode.
2918 // gui->mainmenu->new_project->run_script(script);
2921 if(script->tag.title_is("record"))
2923 // Run record as a thread. It is a terminal command.
2925 // Will read the complete scipt file without letting record read it if not
2931 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
2938 // ================================= synchronization
2941 int MWindow::interrupt_indexes()
2943 mainindexes->interrupt_build();
2949 void MWindow::next_time_format()
2951 switch(edl->session->time_format)
2953 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
2954 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
2955 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2956 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
2957 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
2958 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
2959 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
2962 time_format_common();
2965 void MWindow::prev_time_format()
2967 switch(edl->session->time_format)
2969 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
2970 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
2971 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
2972 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
2973 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
2974 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
2975 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
2978 time_format_common();
2981 void MWindow::time_format_common()
2983 gui->lock_window("MWindow::next_time_format");
2984 gui->redraw_time_dependancies();
2987 char string[BCTEXTLEN], string2[BCTEXTLEN];
2988 sprintf(string, _("Using %s"), Units::print_time_format(edl->session->time_format, string2));
2989 gui->show_message(string);
2991 gui->unlock_window();
2995 int MWindow::set_filename(const char *filename)
2997 if( filename != session->filename )
2998 strcpy(session->filename, filename);
2999 if( filename != edl->path )
3000 strcpy(edl->path, filename);
3004 if(filename[0] == 0)
3006 gui->set_title(PROGRAM_NAME);
3011 char string[BCTEXTLEN], string2[BCTEXTLEN];
3012 dir.extract_name(string, filename);
3013 sprintf(string2, PROGRAM_NAME ": %s", string);
3014 gui->set_title(string2);
3027 int MWindow::set_loop_boundaries()
3029 double start = edl->local_session->get_selectionstart();
3030 double end = edl->local_session->get_selectionend();
3038 if(edl->tracks->total_length())
3041 end = edl->tracks->total_length();
3048 if(edl->local_session->loop_playback && start != end)
3050 edl->local_session->loop_start = start;
3051 edl->local_session->loop_end = end;
3062 int MWindow::reset_meters()
3064 cwindow->gui->lock_window("MWindow::reset_meters 1");
3065 cwindow->gui->meters->reset_meters();
3066 cwindow->gui->unlock_window();
3068 for(int j = 0; j < vwindows.size(); j++)
3070 VWindow *vwindow = vwindows.get(j);
3071 if(vwindow->is_running())
3073 vwindow->gui->lock_window("MWindow::reset_meters 2");
3074 vwindow->gui->meters->reset_meters();
3075 vwindow->gui->unlock_window();
3079 lwindow->gui->lock_window("MWindow::reset_meters 3");
3080 lwindow->gui->panel->reset_meters();
3081 lwindow->gui->unlock_window();
3083 gui->lock_window("MWindow::reset_meters 4");
3084 gui->reset_meters();
3085 gui->unlock_window();
3090 void MWindow::resync_guis()
3094 gui->lock_window("MWindow::resync_guis");
3095 gui->update(1, 1, 1, 1, 1, 1, 0);
3096 gui->unlock_window();
3098 cwindow->gui->lock_window("MWindow::resync_guis");
3099 cwindow->gui->resize_event(cwindow->gui->get_w(),
3100 cwindow->gui->get_h());
3101 int channels = edl->session->audio_channels;
3102 cwindow->gui->meters->set_meters(channels, 1);
3103 cwindow->gui->flush();
3104 cwindow->gui->unlock_window();
3106 for(int i = 0; i < vwindows.size(); i++)
3108 VWindow *vwindow = vwindows.get(i);
3109 vwindow->gui->lock_window("MWindow::resync_guis");
3110 vwindow->gui->resize_event(vwindow->gui->get_w(),
3111 vwindow->gui->get_h());
3112 vwindow->gui->meters->set_meters(channels, 1);
3113 vwindow->gui->flush();
3114 vwindow->gui->unlock_window();
3117 lwindow->gui->lock_window("MWindow::resync_guis");
3118 lwindow->gui->panel->set_meters(channels, 1);
3119 lwindow->gui->flush();
3120 lwindow->gui->unlock_window();
3123 if(((edl->session->output_w % 4) ||
3124 (edl->session->output_h % 4)) &&
3125 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
3127 MainError::show_error(
3128 _("This project's dimensions are not multiples of 4 so\n"
3129 "it can't be rendered by OpenGL."));
3134 sync_parameters(CHANGE_ALL);
3137 int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tracks)
3139 File *file = new File;
3140 EDLSession *session = edl->session;
3141 double old_framerate = session->frame_rate;
3142 double old_samplerate = session->sample_rate;
3143 int result = file->open_file(preferences, asset, 1, 0);
3144 if( !result && delete_tracks > 0 )
3145 undo->update_undo_before();
3146 if( !result && asset->get_video_layers() > 0 ) {
3147 // try to get asset up to date, may fail
3148 file->select_video_stream(asset, vstream);
3149 // either way use what was/is there.
3150 double framerate = asset->get_frame_rate();
3151 int width = asset->get_w();
3152 int height = asset->get_h();
3153 // must be multiple of 4 for opengl
3154 width = (width+3) & ~3; height = (height+3) & ~3;
3155 int driver = session->playback_config->vconfig->driver;
3156 int color_model = file->get_best_colormodel(asset, driver);
3157 color_model = BC_CModels::is_yuv(color_model) ?
3158 BC_CModels::has_alpha(color_model) ? BC_YUVA8888 : BC_YUV888 :
3159 BC_CModels::is_float(color_model) ?
3160 BC_CModels::has_alpha(color_model) ? BC_RGBA_FLOAT : BC_RGB_FLOAT :
3161 BC_CModels::has_alpha(color_model) ? BC_RGBA8888 : BC_RGB888;
3162 session->color_model = color_model;
3163 session->output_w = width;
3164 session->output_h = height;
3165 session->frame_rate = framerate;
3166 // not, asset->actual_width/actual_height
3167 asset->width = session->output_w;
3168 asset->height = session->output_h;
3169 asset->frame_rate = session->frame_rate;
3170 create_aspect_ratio(session->aspect_w, session->aspect_h,
3171 session->output_w, session->output_h);
3172 Track *track = edl->tracks->first;
3173 for( Track *next_track=0; track; track=next_track ) {
3174 next_track = track->next;
3175 if( track->data_type != TRACK_VIDEO ) continue;
3176 if( delete_tracks ) {
3177 Edit *edit = track->edits->first;
3178 for( Edit *next_edit=0; edit; edit=next_edit ) {
3179 next_edit = edit->next;
3180 if( edit->channel != vstream ||
3181 !edit->asset || !edit->asset->is_asset ||
3182 *asset != *edit->asset )
3186 if( track->edits->first ) {
3187 track->track_w = edl->session->output_w;
3188 track->track_h = edl->session->output_h;
3190 else if( delete_tracks )
3191 edl->tracks->delete_track(track);
3193 edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
3195 if( !result && asset->channels > 0 ) {
3196 session->sample_rate = asset->get_sample_rate();
3197 int64_t channel_mask = 0;
3198 int astrm = file->get_audio_for_video(vstream, astream, channel_mask);
3199 if( astrm >= 0 ) file->select_audio_stream(asset, astrm);
3200 if( astrm < 0 || !channel_mask ) channel_mask = (1<<asset->channels)-1;
3202 for( uint64_t mask=channel_mask; mask!=0; mask>>=1 ) channels += mask & 1;
3203 if( channels > 6 ) channels = 6;
3204 session->audio_tracks = session->audio_channels = channels;
3205 switch( channels ) {
3207 session->achannel_positions[0] = 90;
3208 session->achannel_positions[1] = 150;
3209 session->achannel_positions[2] = 30;
3210 session->achannel_positions[3] = 210;
3211 session->achannel_positions[4] = 330;
3212 session->achannel_positions[5] = 270;
3215 session->achannel_positions[0] = 180;
3216 session->achannel_positions[1] = 0;
3219 remap_audio(MWindow::AUDIO_1_TO_1);
3221 if( delete_tracks ) {
3222 Track *track = edl->tracks->first;
3223 for( Track *next_track=0; track; track=next_track ) {
3224 next_track = track->next;
3225 if( track->data_type != TRACK_AUDIO ) continue;
3226 Edit *edit = track->edits->first;
3227 for( Edit *next_edit=0; edit; edit=next_edit ) {
3228 next_edit = edit->next;
3229 if( !((1<<edit->channel) & channel_mask) ||
3230 !edit->asset || !edit->asset->is_asset ||
3231 *asset != *edit->asset )
3234 if( !track->edits->first )
3235 edl->tracks->delete_track(track);
3239 edl->resample(old_samplerate, session->sample_rate, TRACK_AUDIO);
3242 if( !result && delete_tracks > 0 ) {
3244 undo->update_undo_after(_("select asset"), LOAD_ALL);
3250 int MWindow::select_asset(int vtrack, int delete_tracks)
3252 Track *track = edl->tracks->get(vtrack, TRACK_VIDEO);
3253 if( !track ) return 1;
3254 Edit *edit = track->edits->first;
3255 if( !edit ) return 1;
3256 Asset *asset = edit->asset;
3257 if( !asset || !asset->is_asset ) return 1;
3258 return select_asset(asset, edit->channel, -1, delete_tracks);
3261 void MWindow::dump_plugindb(FILE *fp)
3263 if( !plugindb ) return;
3264 for(int i = 0; i < plugindb->total; i++)
3265 plugindb->values[i]->dump(fp);