3 #include "awindowgui.h"
5 #include "batchrender.h"
6 #include "bcdisplayinfo.h"
10 #include "channeldb.h"
12 #include "colormodels.h"
13 #include "cplayback.h"
15 #include "cwindowgui.h"
18 #include "editpanel.h"
20 #include "edlsession.h"
22 #include "fileformat.h"
24 #include "filesystem.h"
26 #include "indexfile.h"
28 #include "levelwindowgui.h"
29 #include "levelwindow.h"
30 #include "loadfile.inc"
31 #include "localsession.h"
32 #include "maincursor.h"
33 #include "mainindexes.h"
35 #include "mainprogress.h"
36 #include "mainsession.h"
40 #include "mwindowgui.h"
44 #include "playbackengine.h"
46 #include "pluginserver.h"
47 #include "pluginset.h"
48 #include "preferences.h"
50 #include "recordlabel.h"
52 #include "samplescroll.h"
53 #include "sighandler.h"
54 #include "splashgui.h"
55 #include "statusbar.h"
57 #include "threadloader.h"
59 #include "trackcanvas.h"
62 #include "trackscroll.h"
64 #include "transition.h"
65 #include "transportque.h"
67 #include "videodevice.inc"
68 #include "videowindow.h"
69 #include "vplayback.h"
70 #include "vwindowgui.h"
84 // Hack for libdv to remove glib dependancy
87 // g_log (const char *log_domain,
89 // const char *format,
95 // g_logv (const char *log_domain,
97 // const char *format,
104 // Hack for XFree86 4.1.0
106 int atexit(void (*function)(void))
121 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
122 brender_lock = new Mutex("MWindow::brender_lock");
125 channeldb_buz = new ChannelDB;
126 channeldb_v4l2jpeg = new ChannelDB;
131 brender_lock->lock("MWindow::~MWindow");
132 if(brender) delete brender;
134 brender_lock->unlock();
139 TRACE("MWindow::~MWindow 1\n");
141 TRACE("MWindow::~MWindow 2\n");
144 TRACE("MWindow::~MWindow 3\n");
145 // Give up and go to a movie
148 TRACE("MWindow::~MWindow 4\n");
150 delete audio_cache; // delete the cache after the assets
151 delete video_cache; // delete the cache after the assets
157 // delete renderlist;
162 plugin_guis->remove_all_objects();
164 delete plugin_gui_lock;
167 void MWindow::init_defaults(Defaults* &defaults, char *config_path)
169 char path[BCTEXTLEN];
170 // Use user supplied path
173 strcpy(path, config_path);
177 // set the .bcast path
180 sprintf(path, "%s", BCASTDIR);
181 fs.complete_path(path);
188 strcat(path, "Cinelerra_rc");
191 defaults = new Defaults(path);
195 void MWindow::init_plugin_path(Preferences *preferences,
196 ArrayList<PluginServer*>* &plugindb,
198 SplashGUI *splash_window,
202 PluginServer *newplugin;
206 for(int i = 0; i < fs->dir_list.total; i++)
208 char path[BCTEXTLEN];
209 strcpy(path, fs->dir_list.values[i]->path);
211 // File is a directory
212 if(!fs->is_dir(path))
218 // Try to query the plugin
219 fs->complete_path(path);
220 //printf("MWindow::init_plugin_path %s\n", path);
221 PluginServer *new_plugin = new PluginServer(path);
222 int result = new_plugin->open_plugin(1, preferences, 0, 0, -1);
226 plugindb->append(new_plugin);
227 new_plugin->close_plugin();
229 splash_window->operation->update(_(new_plugin->title));
232 if(result == PLUGINSERVER_IS_LAD)
235 // Open LAD subplugins
239 new_plugin = new PluginServer(path);
240 result = new_plugin->open_plugin(1,
248 plugindb->append(new_plugin);
249 new_plugin->close_plugin();
251 splash_window->operation->update(_(new_plugin->title));
257 // Plugin failed to open
261 if(splash_window) splash_window->progress->update((*counter)++);
266 void MWindow::init_plugins(Preferences *preferences,
267 ArrayList<PluginServer*>* &plugindb,
268 SplashGUI *splash_window)
270 plugindb = new ArrayList<PluginServer*>;
274 FileSystem cinelerra_fs;
275 ArrayList<FileSystem*> lad_fs;
279 cinelerra_fs.set_filter("[*.plugin][*.so]");
280 result = cinelerra_fs.update(preferences->global_plugin_dir);
285 _("MWindow::init_plugins: couldn't open %s directory\n"),
286 preferences->global_plugin_dir);
289 // Parse LAD environment variable
290 char *env = getenv("LADSPA_PATH");
293 char string[BCTEXTLEN];
297 char *ptr = strchr(ptr1, ':');
305 end = env + strlen(env);
310 int len = end - ptr1;
311 memcpy(string, ptr1, len);
315 FileSystem *fs = new FileSystem;
317 fs->set_filter("*.so");
318 result = fs->update(string);
323 _("MWindow::init_plugins: couldn't open %s directory\n"),
335 int total = cinelerra_fs.total_files();
337 for(int i = 0; i < lad_fs.total; i++)
338 total += lad_fs.values[i]->total_files();
339 if(splash_window) splash_window->progress->update_length(total);
343 init_plugin_path(preferences,
349 // Call automatically generated routine to get plugins
353 for(int i = 0; i < lad_fs.total; i++)
354 init_plugin_path(preferences,
360 lad_fs.remove_all_objects();
363 void MWindow::delete_plugins()
365 for(int i = 0; i < plugindb->total; i++)
367 delete plugindb->values[i];
372 void MWindow::create_plugindb(int do_audio,
377 ArrayList<PluginServer*> &plugindb)
380 for(int i = 0; i < this->plugindb->total; i++)
382 PluginServer *current = this->plugindb->values[i];
384 if(current->audio == do_audio &&
385 current->video == do_video &&
386 (current->realtime == is_realtime || is_realtime < 0) &&
387 current->transition == is_transition &&
388 current->theme == is_theme)
389 plugindb.append(current);
392 // Alphabetize list by title
398 for(int i = 0; i < plugindb.total - 1; i++)
400 PluginServer *value1 = plugindb.values[i];
401 PluginServer *value2 = plugindb.values[i + 1];
402 if(strcmp(_(value1->title), _(value2->title)) > 0)
405 plugindb.values[i] = value2;
406 plugindb.values[i + 1] = value1;
412 PluginServer* MWindow::scan_plugindb(char *title,
417 printf("MWindow::scan_plugindb data_type < 0\n");
421 for(int i = 0; i < plugindb->total; i++)
423 PluginServer *server = plugindb->values[i];
424 if(!strcasecmp(server->title, title) &&
425 ((data_type == TRACK_AUDIO && server->audio) ||
426 (data_type == TRACK_VIDEO && server->video)))
427 return plugindb->values[i];
432 void MWindow::init_preferences()
434 preferences = new Preferences;
435 preferences->load_defaults(defaults);
436 session = new MainSession(this);
437 session->load_defaults(defaults);
440 void MWindow::clean_indexes()
447 char string[BCTEXTLEN];
449 // Delete extra indexes
450 fs.set_filter("*.idx");
451 fs.complete_path(preferences->index_directory);
452 fs.update(preferences->index_directory);
453 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
455 // Eliminate directories
460 for(int i = 0; i < fs.dir_list.total && !result; i++)
462 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
463 if(!fs.is_dir(string))
465 delete fs.dir_list.values[i];
466 fs.dir_list.remove_number(i);
471 total_excess = fs.dir_list.total - preferences->index_count;
473 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
474 while(total_excess > 0)
477 for(int i = 0; i < fs.dir_list.total; i++)
479 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
481 if(i == 0 || fs.get_date(string) <= oldest)
483 oldest = fs.get_date(string);
488 fs.join_names(string, preferences->index_directory, fs.dir_list.values[oldest_item]->name);
490 perror("delete_indexes");
491 delete fs.dir_list.values[oldest_item];
492 fs.dir_list.remove_number(oldest_item);
497 void MWindow::init_awindow()
499 awindow = new AWindow(this);
500 awindow->create_objects();
503 void MWindow::init_theme()
507 for(int i = 0; i < plugindb->total; i++)
509 if(plugindb->values[i]->theme &&
510 !strcasecmp(preferences->theme, plugindb->values[i]->title))
512 PluginServer plugin = *plugindb->values[i];
513 plugin.open_plugin(0, preferences, 0, 0, -1);
514 theme = plugin.new_theme();
515 theme->mwindow = this;
516 strcpy(theme->path, plugin.path);
517 plugin.close_plugin();
523 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
529 // Load images which may have been forgotten
530 theme->Theme::initialize();
535 void MWindow::init_edl()
538 edl->create_objects();
539 edl->load_defaults(defaults);
540 edl->create_default_tracks();
541 edl->tracks->update_y_pixels(theme);
544 void MWindow::init_compositor()
546 cwindow = new CWindow(this);
547 cwindow->create_objects();
550 void MWindow::init_levelwindow()
552 lwindow = new LevelWindow(this);
553 lwindow->create_objects();
556 void MWindow::init_viewer()
558 vwindow = new VWindow(this);
559 vwindow->load_defaults();
560 vwindow->create_objects();
563 void MWindow::init_cache()
565 audio_cache = new CICache(edl, preferences, plugindb);
566 video_cache = new CICache(edl, preferences, plugindb);
569 void MWindow::init_channeldb()
571 channeldb_buz->load("channeldb_buz");
572 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
575 void MWindow::init_menus()
577 char string[BCTEXTLEN];
578 cmodel_to_text(string, BC_RGB888);
579 colormodels.append(new ColormodelItem(string, BC_RGB888));
580 cmodel_to_text(string, BC_RGBA8888);
581 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
582 // cmodel_to_text(string, BC_RGB161616);
583 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
584 // cmodel_to_text(string, BC_RGBA16161616);
585 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
586 cmodel_to_text(string, BC_RGB_FLOAT);
587 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
588 cmodel_to_text(string, BC_RGBA_FLOAT);
589 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
590 cmodel_to_text(string, BC_YUV888);
591 colormodels.append(new ColormodelItem(string, BC_YUV888));
592 cmodel_to_text(string, BC_YUVA8888);
593 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
594 cmodel_to_text(string, BC_YUV161616);
595 colormodels.append(new ColormodelItem(string, BC_YUV161616));
596 cmodel_to_text(string, BC_YUVA16161616);
597 colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
600 void MWindow::init_indexes()
602 mainindexes = new MainIndexes(this);
603 mainindexes->start_loop();
606 void MWindow::init_gui()
608 gui = new MWindowGUI(this);
609 gui->create_objects();
610 gui->load_defaults(defaults);
613 void MWindow::init_signals()
615 sighandler = new SigHandler;
616 sighandler->initialize();
620 void MWindow::init_render()
622 render = new Render(this);
623 // renderlist = new Render(this);
624 batch_render = new BatchRenderThread(this);
627 void MWindow::init_brender()
629 if(preferences->use_brender && !brender)
631 brender_lock->lock("MWindow::init_brender 1");
632 brender = new BRender(this);
633 brender->initialize();
634 session->brender_end = 0;
635 brender_lock->unlock();
638 if(!preferences->use_brender && brender)
640 brender_lock->lock("MWindow::init_brender 2");
643 session->brender_end = 0;
644 brender_lock->unlock();
646 if(brender) brender->restart(edl);
649 void MWindow::restart_brender()
651 //printf("MWindow::restart_brender 1\n");
652 if(brender) brender->restart(edl);
655 void MWindow::stop_brender()
657 if(brender) brender->stop();
660 int MWindow::brender_available(int position)
663 brender_lock->lock("MWindow::brender_available 1");
666 if(brender->map_valid)
668 brender->map_lock->lock("MWindow::brender_available 2");
669 if(position < brender->map_size &&
672 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
673 if(brender->map[position] == BRender::RENDERED)
676 brender->map_lock->unlock();
679 brender_lock->unlock();
683 void MWindow::set_brender_start()
685 edl->session->brender_start = edl->local_session->get_selectionstart();
687 gui->canvas->draw_overlays();
688 gui->canvas->flash();
693 int MWindow::load_filenames(ArrayList<char*> *filenames,
700 TRACE("MWindow::load_filenames 1");
701 ArrayList<EDL*> new_edls;
702 ArrayList<Asset*> new_assets;
704 // Need to stop playback since tracking depends on the EDL not getting
706 cwindow->playback_engine->que->send_command(STOP,
710 vwindow->playback_engine->que->send_command(STOP,
714 cwindow->playback_engine->interrupt_playback(0);
715 vwindow->playback_engine->interrupt_playback(0);
719 // Define new_edls and new_assets to load
721 for(int i = 0; i < filenames->total; i++)
724 File *new_file = new File;
725 Asset *new_asset = new Asset(filenames->values[i]);
726 EDL *new_edl = new EDL;
727 char string[BCTEXTLEN];
729 // Set reel name and number for the asset
730 // If the user wants to overwrite the last used reel number for the clip,
731 // we have to rebuild the index for the file
735 char source_filename[BCTEXTLEN];
736 char index_filename[BCTEXTLEN];
738 strcpy(new_asset->reel_name, reel_name);
739 new_asset->reel_number = reel_number;
741 IndexFile::get_index_filename(source_filename,
742 preferences->index_directory,
745 remove(index_filename);
746 new_asset->index_status = INDEX_NOTTESTED;
749 new_edl->create_objects();
750 new_edl->copy_session(edl);
752 sprintf(string, "Loading %s", new_asset->path);
753 gui->show_message(string, BLACK);
754 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
758 // Convert media file to EDL
760 if(load_mode != LOAD_RESOURCESONLY)
762 asset_to_edl(new_edl, new_asset);
763 new_edls.append(new_edl);
768 new_assets.append(new_asset);
771 // Set filename to nothing for assets since save EDL would overwrite them.
772 if(load_mode == LOAD_REPLACE ||
773 load_mode == LOAD_REPLACE_CONCATENATE)
776 // Reset timeline position
777 new_edl->local_session->view_start = 0;
778 new_edl->local_session->track_start = 0;
785 sprintf(string, _("Failed to open %s"), new_asset->path);
786 gui->show_message(string, RED);
791 case FILE_UNRECOGNIZED_CODEC:
794 IndexFile indexfile(this);
795 result = indexfile.open_index(this, new_asset);
798 indexfile.close_index();
801 // Test existing EDLs
804 for(int j = 0; j < new_edls.total + 1; j++)
807 if(j == new_edls.total)
809 if(old_asset = edl->assets->get_asset(new_asset->path))
811 *new_asset = *old_asset;
817 if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
819 *new_asset = *old_asset;
829 char string[BCTEXTLEN];
831 fs.extract_name(string, new_asset->path);
833 strcat(string, _("'s format couldn't be determined."));
834 new_asset->audio_data = 1;
835 new_asset->format = FILE_PCM;
836 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
837 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
838 new_asset->bits = defaults->get("AUDIO_BITS", 16);
839 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
840 new_asset->signed_ = defaults->get("SIGNED_", 1);
841 new_asset->header = defaults->get("HEADER", 0);
843 FileFormat fwindow(this);
844 fwindow.create_objects(new_asset, string);
845 result = fwindow.run_window();
847 defaults->update("AUDIO_CHANNELS", new_asset->channels);
848 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
849 defaults->update("AUDIO_BITS", new_asset->bits);
850 defaults->update("BYTE_ORDER", new_asset->byte_order);
851 defaults->update("SIGNED_", new_asset->signed_);
852 defaults->update("HEADER", new_asset->header);
859 // Recalculate length
862 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
864 if(load_mode != LOAD_RESOURCESONLY)
866 asset_to_edl(new_edl, new_asset);
867 new_edls.append(new_edl);
872 new_assets.append(new_asset);
885 xml_file.read_from_file(filenames->values[i]);
886 // Load EDL for pasting
887 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
889 // We don't want a valid reel name/number for projects
890 strcpy(new_asset->reel_name, "");
893 // Do a check weather plugins exist
894 for(Track *track = new_edl->tracks->first; track; track = track->next)
896 for(int k = 0; k < track->plugin_set.total; k++)
898 PluginSet *plugin_set = track->plugin_set.values[k];
899 for(Plugin *plugin = (Plugin*)plugin_set->first;
901 plugin = (Plugin*)plugin->next)
903 if(plugin->plugin_type == PLUGIN_STANDALONE)
905 // ok we need to find it in plugindb
906 int plugin_found = 0;
907 for(int j = 0; j < plugindb->total; j++)
909 PluginServer *server = plugindb->values[j];
910 if(!strcasecmp(server->title, plugin->title) &&
911 ((track->data_type == TRACK_AUDIO && server->audio) ||
912 (track->data_type == TRACK_VIDEO && server->video)) &&
913 (!server->transition))
918 printf("\nWARNING: The plugin '%s' named in file '%s' is not part of your installation of Cinelerra. This means project will not be rendered as it was meant and it might result in Cinelerra crushing.\n", plugin->title, filenames->values[i]);
923 for(Edit *edit = (Edit*)track->edits->first;
925 edit = (Edit*)edit->next)
927 if (edit->transition)
929 // ok we need to find transition in plugindb
930 int transition_found = 0;
931 for(int j = 0; j < plugindb->total; j++)
933 PluginServer *server = plugindb->values[j];
934 if(!strcasecmp(server->title, edit->transition->title) &&
935 ((track->data_type == TRACK_AUDIO && server->audio) ||
936 (track->data_type == TRACK_VIDEO && server->video)) &&
937 (server->transition))
938 transition_found = 1;
940 if (!transition_found)
942 printf("\nWARNING: The transition '%s' named in file '%s' is not part of your installation of Cinelerra. This means project will not be rendered as it was meant and it might result in Cinelerra crushing.\n", edit->transition->title, filenames->values[i]);
950 if(load_mode == LOAD_REPLACE ||
951 load_mode == LOAD_REPLACE_CONCATENATE)
953 strcpy(session->filename, filenames->values[i]);
954 strcpy(new_edl->local_session->clip_title, filenames->values[i]);
956 set_filename(new_edl->local_session->clip_title);
959 new_edls.append(new_edl);
976 if(!result) gui->statusbar->default_message();
986 // Don't back up here.
989 // For pasting, clear the active region
990 if(load_mode == LOAD_PASTE)
992 double start = edl->local_session->get_selectionstart();
993 double end = edl->local_session->get_selectionend();
994 if(!EQUIV(start, end))
997 edl->session->labels_follow_edits,
998 edl->session->plugins_follow_edits);
1001 paste_edls(&new_edls,
1005 edl->session->labels_follow_edits,
1006 edl->session->plugins_follow_edits);
1015 if(new_assets.total)
1017 for(int i = 0; i < new_assets.total; i++)
1019 mainindexes->add_next_asset(new_assets.values[i]);
1020 edl->assets->update(new_assets.values[i]);
1024 // Start examining next batch of index files
1025 mainindexes->start_build();
1028 TRACE("MWindow::load_filenames 100");
1029 update_project(load_mode);
1030 TRACE("MWindow::load_filenames 110");
1032 //printf("MWindow::load_filenames 9\n");
1035 new_edls.remove_all_objects();
1036 new_assets.remove_all_objects();
1037 //printf("MWindow::load_filenames 10 %d\n", edl->session->audio_module_fragment);
1039 if(load_mode == LOAD_REPLACE ||
1040 load_mode == LOAD_REPLACE_CONCATENATE)
1041 session->changes_made = 0;
1047 void MWindow::create_objects(int want_gui,
1051 char string[BCTEXTLEN];
1058 // For some reason, init_signals must come after show_splash or the signals won't
1064 TRACE("MWindow::create_objects 1");
1065 init_defaults(defaults, config_path);
1066 TRACE("MWindow::create_objects 2");
1068 TRACE("MWindow::create_objects 3");
1069 init_plugins(preferences, plugindb, splash_window);
1070 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1071 TRACE("MWindow::create_objects 4");
1073 // Default project created here
1074 TRACE("MWindow::create_objects 5");
1077 TRACE("MWindow::create_objects 6");
1079 TRACE("MWindow::create_objects 7");
1081 TRACE("MWindow::create_objects 8");
1083 TRACE("MWindow::create_objects 9");
1085 TRACE("MWindow::create_objects 10");
1087 TRACE("MWindow::create_objects 11");
1089 TRACE("MWindow::create_objects 12");
1091 TRACE("MWindow::create_objects 13");
1094 TRACE("MWindow::create_objects 14");
1097 mainprogress = new MainProgress(this, gui);
1098 undo = new MainUndo(this);
1100 plugin_guis = new ArrayList<PluginServer*>;
1102 TRACE("MWindow::create_objects 15");
1103 if(session->show_vwindow) vwindow->gui->show_window();
1104 if(session->show_cwindow) cwindow->gui->show_window();
1105 if(session->show_awindow) awindow->gui->show_window();
1106 if(session->show_lwindow) lwindow->gui->show_window();
1107 TRACE("MWindow::create_objects 16");
1109 // vwindow->start();
1110 // awindow->start();
1111 // cwindow->start();
1112 // lwindow->start();
1113 //printf("MWindow::create_objects 1");
1115 gui->mainmenu->load_defaults(defaults);
1116 TRACE("MWindow::create_objects 17");
1117 gui->mainmenu->update_toggles();
1118 TRACE("MWindow::create_objects 18");
1119 gui->patchbay->update();
1120 TRACE("MWindow::create_objects 19");
1121 gui->canvas->draw();
1122 TRACE("MWindow::create_objects 20");
1123 gui->cursor->draw();
1124 TRACE("MWindow::create_objects 21");
1125 gui->raise_window();
1126 TRACE("MWindow::create_objects 22");
1128 TRACE("MWindow::create_objects 23");
1135 void MWindow::show_splash()
1137 #include "data/heroine_logo12_png.h"
1138 VFrame *frame = new VFrame(heroine_logo12_png);
1139 BC_DisplayInfo display_info;
1140 splash_window = new SplashGUI(frame,
1141 display_info.get_root_w() / 2 - frame->get_w() / 2,
1142 display_info.get_root_h() / 2 - frame->get_h() / 2);
1143 splash_window->create_objects();
1146 void MWindow::hide_splash()
1149 delete splash_window;
1154 void MWindow::start()
1163 void MWindow::show_vwindow()
1165 session->show_vwindow = 1;
1166 vwindow->gui->lock_window("MWindow::show_vwindow");
1167 vwindow->gui->show_window();
1168 vwindow->gui->raise_window();
1169 vwindow->gui->flush();
1170 vwindow->gui->unlock_window();
1171 gui->mainmenu->show_vwindow->set_checked(1);
1174 void MWindow::show_awindow()
1176 session->show_awindow = 1;
1177 awindow->gui->lock_window("MWindow::show_awindow");
1178 awindow->gui->show_window();
1179 awindow->gui->raise_window();
1180 awindow->gui->flush();
1181 awindow->gui->unlock_window();
1182 gui->mainmenu->show_awindow->set_checked(1);
1185 void MWindow::show_cwindow()
1187 session->show_cwindow = 1;
1188 cwindow->gui->lock_window("MWindow::show_cwindow");
1189 cwindow->gui->show_window();
1190 cwindow->gui->raise_window();
1191 cwindow->gui->flush();
1192 cwindow->gui->unlock_window();
1193 gui->mainmenu->show_cwindow->set_checked(1);
1196 void MWindow::show_lwindow()
1198 session->show_lwindow = 1;
1199 lwindow->gui->lock_window("MWindow::show_lwindow");
1200 lwindow->gui->show_window();
1201 lwindow->gui->raise_window();
1202 lwindow->gui->flush();
1203 lwindow->gui->unlock_window();
1204 gui->mainmenu->show_lwindow->set_checked(1);
1207 void MWindow::tile_windows()
1209 session->default_window_positions();
1210 gui->default_positions();
1213 void MWindow::toggle_loop_playback()
1215 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1216 set_loop_boundaries();
1219 gui->canvas->draw_overlays();
1220 gui->canvas->flash();
1221 sync_parameters(CHANGE_PARAMS);
1224 void MWindow::set_titles(int value)
1226 edl->session->show_titles = value;
1227 trackmovement(edl->local_session->track_start);
1230 void MWindow::set_auto_keyframes(int value)
1232 gui->lock_window("MWindow::set_auto_keyframes");
1233 edl->session->auto_keyframes = value;
1234 gui->mbuttons->edit_panel->keyframe->update(value);
1236 gui->unlock_window();
1237 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1238 cwindow->gui->edit_panel->keyframe->update(value);
1239 cwindow->gui->flush();
1240 cwindow->gui->unlock_window();
1243 int MWindow::set_editing_mode(int new_editing_mode)
1245 gui->lock_window("MWindow::set_editing_mode");
1246 edl->session->editing_mode = new_editing_mode;
1247 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1248 gui->mbuttons->edit_panel->update();
1249 gui->canvas->update_cursor();
1250 gui->unlock_window();
1251 cwindow->gui->lock_window("MWindow::set_editing_mode");
1252 cwindow->gui->edit_panel->update();
1253 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1254 cwindow->gui->unlock_window();
1259 void MWindow::sync_parameters(int change_type)
1262 // Sync engines which are playing back
1263 if(cwindow->playback_engine->is_playing_back)
1265 if(change_type == CHANGE_PARAMS)
1267 // TODO: block keyframes until synchronization is done
1268 cwindow->playback_engine->sync_parameters(edl);
1273 int command = cwindow->playback_engine->command->command;
1274 cwindow->playback_engine->que->send_command(STOP,
1278 // Waiting for tracking to finish would make the restart position more
1279 // accurate but it can't lock the window to stop tracking for some reason.
1280 // Not waiting for tracking gives a faster response but restart position is
1281 // only as accurate as the last tracking update.
1282 cwindow->playback_engine->interrupt_playback(0);
1283 cwindow->playback_engine->que->send_command(command,
1292 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1299 void MWindow::update_caches()
1301 audio_cache->set_edl(edl);
1302 video_cache->set_edl(edl);
1305 void MWindow::show_plugin(Plugin *plugin)
1308 //printf("MWindow::show_plugin 1\n");
1309 plugin_gui_lock->lock("MWindow::show_plugin");
1310 for(int i = 0; i < plugin_guis->total; i++)
1312 // Pointer comparison
1313 if(plugin_guis->values[i]->plugin == plugin)
1315 plugin_guis->values[i]->raise_window();
1321 //printf("MWindow::show_plugin 1\n");
1326 printf("MWindow::show_plugin track not defined.\n");
1328 PluginServer *server = scan_plugindb(plugin->title,
1329 plugin->track->data_type);
1331 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
1332 if(server && server->uses_gui)
1334 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
1335 // Needs mwindow to do GUI
1336 gui->set_mwindow(this);
1337 gui->open_plugin(0, preferences, edl, plugin, -1);
1342 plugin_gui_lock->unlock();
1343 //printf("MWindow::show_plugin 2\n");
1346 void MWindow::hide_plugin(Plugin *plugin, int lock)
1348 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
1350 for(int i = 0; i < plugin_guis->total; i++)
1352 if(plugin_guis->values[i]->plugin == plugin)
1354 PluginServer *ptr = plugin_guis->values[i];
1355 plugin_guis->remove(ptr);
1356 if(lock) plugin_gui_lock->unlock();
1357 // Last command executed in client side close
1362 if(lock) plugin_gui_lock->unlock();
1365 void MWindow::hide_plugins()
1367 plugin_gui_lock->lock("MWindow::hide_plugins");
1368 plugin_guis->remove_all_objects();
1369 plugin_gui_lock->unlock();
1372 void MWindow::update_plugin_guis()
1374 plugin_gui_lock->lock("MWindow::update_plugin_guis");
1376 for(int i = 0; i < plugin_guis->total; i++)
1378 plugin_guis->values[i]->update_gui();
1380 plugin_gui_lock->unlock();
1383 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
1385 plugin_gui_lock->lock("MWindow::render_plugin_gui");
1386 for(int i = 0; i < plugin_guis->total; i++)
1388 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1390 plugin_guis->values[i]->render_gui(data);
1394 plugin_gui_lock->unlock();
1397 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
1399 plugin_gui_lock->lock("MWindow::render_plugin_gui");
1400 for(int i = 0; i < plugin_guis->total; i++)
1402 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1404 plugin_guis->values[i]->render_gui(data, size);
1408 plugin_gui_lock->unlock();
1412 void MWindow::update_plugin_states()
1415 plugin_gui_lock->lock("MWindow::update_plugin_states");
1416 for(int i = 0; i < plugin_guis->total; i++)
1419 Plugin *src_plugin = plugin_guis->values[i]->plugin;
1420 PluginServer *src_plugingui = plugin_guis->values[i];
1422 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
1423 for(Track *track = edl->tracks->first;
1425 track = track->next)
1428 j < track->plugin_set.total && !result;
1431 PluginSet *plugin_set = track->plugin_set.values[j];
1432 for(Plugin *plugin = (Plugin*)plugin_set->first;
1434 plugin = (Plugin*)plugin->next)
1436 if(plugin == src_plugin &&
1437 !strcmp(plugin->title, src_plugingui->title)) result = 1;
1443 // Doesn't exist anymore
1446 hide_plugin(src_plugin, 0);
1450 plugin_gui_lock->unlock();
1454 void MWindow::update_plugin_titles()
1456 for(int i = 0; i < plugin_guis->total; i++)
1458 plugin_guis->values[i]->update_title();
1462 int MWindow::asset_to_edl(EDL *new_edl,
1464 RecordLabels *labels)
1466 //printf("MWindow::asset_to_edl 1\n");
1467 // new_edl->load_defaults(defaults);
1469 // Keep frame rate, sample rate, and output size unchanged.
1470 // These parameters would revert the project if VWindow displayed an asset
1471 // of different size than the project.
1472 if(new_asset->video_data)
1474 new_edl->session->video_tracks = new_asset->layers;
1475 // new_edl->session->frame_rate = new_asset->frame_rate;
1476 // new_edl->session->output_w = new_asset->width;
1477 // new_edl->session->output_h = new_asset->height;
1480 new_edl->session->video_tracks = 0;
1487 if(new_asset->audio_data)
1489 new_edl->session->audio_tracks = new_asset->channels;
1490 // new_edl->session->sample_rate = new_asset->sample_rate;
1493 new_edl->session->audio_tracks = 0;
1494 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1496 new_edl->create_default_tracks();
1497 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1499 // Disable drawing if the file format isn't fast enough.
1500 if(new_asset->format == FILE_MPEG)
1502 for(Track *current = new_edl->tracks->first;
1506 if(current->data_type == TRACK_VIDEO) current->draw = 0;
1512 //printf("MWindow::asset_to_edl 3\n");
1513 new_edl->insert_asset(new_asset, 0, 0, labels);
1514 //printf("MWindow::asset_to_edl 3\n");
1520 char string[BCTEXTLEN];
1522 fs.extract_name(string, new_asset->path);
1523 //printf("MWindow::asset_to_edl 3\n");
1525 strcpy(new_edl->local_session->clip_title, string);
1526 //printf("MWindow::asset_to_edl 4 %s\n", string);
1532 // Reset everything after a load.
1533 void MWindow::update_project(int load_mode)
1536 //TRACE("MWindow::update_project 1");
1537 edl->tracks->update_y_pixels(theme);
1540 //TRACE("MWindow::update_project 2");
1543 TRACE("MWindow::update_project 3");
1544 gui->update(1, 1, 1, 1, 1, 1, 1);
1546 TRACE("MWindow::update_project 4");
1547 cwindow->update(0, 0, 1, 1, 1);
1549 TRACE("MWindow::update_project 5");
1551 if(load_mode == LOAD_REPLACE ||
1552 load_mode == LOAD_REPLACE_CONCATENATE)
1554 vwindow->change_source();
1561 TRACE("MWindow::update_project 6");
1563 cwindow->gui->slider->set_position();
1564 TRACE("MWindow::update_project 6.1");
1565 cwindow->gui->timebar->update(1, 1);
1566 TRACE("MWindow::update_project 6.2");
1567 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1572 TRACE("MWindow::update_project 7");
1573 awindow->gui->lock_window("MWindow::update_project");
1574 awindow->gui->update_assets();
1575 awindow->gui->flush();
1576 awindow->gui->unlock_window();
1578 TRACE("MWindow::update_project 100");
1582 void MWindow::rebuild_indices()
1584 char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
1586 for(int i = 0; i < session->drag_assets->total; i++)
1588 //printf("MWindow::rebuild_indices 1 %s\n", session->drag_assets->values[i]->path);
1590 IndexFile::get_index_filename(source_filename,
1591 preferences->index_directory,
1593 session->drag_assets->values[i]->path);
1594 remove(index_filename);
1595 // Schedule index build
1596 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
1597 mainindexes->add_next_asset(session->drag_assets->values[i]);
1599 mainindexes->start_build();
1603 void MWindow::save_backup()
1606 edl->set_project_path(session->filename);
1607 edl->save_xml(plugindb,
1612 file.terminate_string();
1613 char path[BCTEXTLEN];
1615 strcpy(path, BACKUP_PATH);
1616 fs.complete_path(path);
1618 if(file.write_to_file(path))
1621 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
1622 gui->show_message(string2);
1627 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
1630 float fraction = (float)width / height;
1632 for(denominator = 1;
1633 denominator < 100 &&
1634 fabs(fraction * denominator - (int)(fraction * denominator)) > .001;
1638 w = denominator * width / height;
1644 void MWindow::remove_assets_from_project(int push_undo)
1646 if(push_undo) undo->update_undo_before(_("remove assets"), LOAD_ALL);
1648 // Remove from caches
1649 for(int i = 0; i < session->drag_assets->total; i++)
1651 audio_cache->delete_entry(session->drag_assets->values[i]);
1652 video_cache->delete_entry(session->drag_assets->values[i]);
1655 printf("MWindow::remove_assets_from_project 1\n");
1656 video_cache->dump();
1657 audio_cache->dump();
1658 printf("MWindow::remove_assets_from_project 100\n");
1660 // Remove from VWindow.
1661 for(int i = 0; i < session->drag_clips->total; i++)
1663 if(session->drag_clips->values[i] == vwindow->get_edl())
1665 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
1666 vwindow->remove_source();
1667 vwindow->gui->unlock_window();
1671 for(int i = 0; i < session->drag_assets->total; i++)
1673 if(session->drag_assets->values[i] == vwindow->get_asset())
1675 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
1676 vwindow->remove_source();
1677 vwindow->gui->unlock_window();
1681 edl->remove_from_project(session->drag_assets);
1682 edl->remove_from_project(session->drag_clips);
1684 if(push_undo) undo->update_undo_after();
1687 gui->lock_window("MWindow::remove_assets_from_project 3");
1695 gui->unlock_window();
1697 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
1698 awindow->gui->update_assets();
1699 awindow->gui->flush();
1700 awindow->gui->unlock_window();
1702 // Removes from playback here
1703 sync_parameters(CHANGE_ALL);
1706 void MWindow::remove_assets_from_disk()
1709 for(int i = 0; i < session->drag_assets->total; i++)
1711 remove(session->drag_assets->values[i]->path);
1714 remove_assets_from_project(1);
1717 void MWindow::dump_plugins()
1719 for(int i = 0; i < plugindb->total; i++)
1721 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
1722 plugindb->values[i]->audio,
1723 plugindb->values[i]->video,
1724 plugindb->values[i]->realtime,
1725 plugindb->values[i]->transition,
1726 plugindb->values[i]->theme,
1727 plugindb->values[i]->title);
1755 int MWindow::save_defaults()
1757 gui->save_defaults(defaults);
1758 edl->save_defaults(defaults);
1759 session->save_defaults(defaults);
1760 preferences->save_defaults(defaults);
1766 int MWindow::run_script(FileXML *script)
1768 int result = 0, result2 = 0;
1769 while(!result && !result2)
1771 result = script->read_tag();
1774 if(script->tag.title_is("new_project"))
1776 // Run new in immediate mode.
1777 // gui->mainmenu->new_project->run_script(script);
1780 if(script->tag.title_is("record"))
1782 // Run record as a thread. It is a terminal command.
1784 // Will read the complete scipt file without letting record read it if not
1790 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
1797 // ================================= synchronization
1800 int MWindow::interrupt_indexes()
1802 mainindexes->interrupt_build();
1808 void MWindow::next_time_format()
1810 switch(edl->session->time_format)
1812 case 0: edl->session->time_format = 1; break;
1813 case 1: edl->session->time_format = 2; break;
1814 case 2: edl->session->time_format = 3; break;
1815 case 3: edl->session->time_format = 4; break;
1816 case 4: edl->session->time_format = 5; break;
1817 case 5: edl->session->time_format = 0; break;
1821 gui->redraw_time_dependancies();
1825 char string[BCTEXTLEN], string2[BCTEXTLEN];
1826 sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
1827 gui->show_message(string, BLACK);
1829 gui->unlock_window();
1832 int MWindow::set_filename(char *filename)
1834 strcpy(session->filename, filename);
1837 if(filename[0] == 0)
1839 gui->set_title(PROGRAM_NAME);
1844 char string[BCTEXTLEN], string2[BCTEXTLEN];
1845 dir.extract_name(string, filename);
1846 sprintf(string2, PROGRAM_NAME ": %s", string);
1847 gui->set_title(string2);
1860 int MWindow::set_loop_boundaries()
1862 double start = edl->local_session->get_selectionstart();
1863 double end = edl->local_session->get_selectionend();
1871 if(edl->tracks->total_length())
1874 end = edl->tracks->total_length();
1881 if(edl->local_session->loop_playback && start != end)
1883 edl->local_session->loop_start = start;
1884 edl->local_session->loop_end = end;
1895 int MWindow::reset_meters()
1897 cwindow->gui->lock_window("MWindow::reset_meters 1");
1898 cwindow->gui->meters->reset_meters();
1899 cwindow->gui->unlock_window();
1901 vwindow->gui->lock_window("MWindow::reset_meters 2");
1902 vwindow->gui->meters->reset_meters();
1903 vwindow->gui->unlock_window();
1905 lwindow->gui->lock_window("MWindow::reset_meters 3");
1906 lwindow->gui->panel->reset_meters();
1907 lwindow->gui->unlock_window();
1909 gui->lock_window("MWindow::reset_meters 4");
1910 gui->patchbay->reset_meters();
1911 gui->unlock_window();