3 #include "awindowgui.h"
5 #include "batchrender.h"
6 #include "bcdisplayinfo.h"
11 #include "channeldb.h"
13 #include "colormodels.h"
14 #include "cplayback.h"
16 #include "cwindowgui.h"
19 #include "editpanel.h"
21 #include "edlsession.h"
23 #include "fileformat.h"
25 #include "filesystem.h"
28 #include "gwindowgui.h"
29 #include "indexfile.h"
30 #include "interlacemodes.h"
32 #include "levelwindowgui.h"
33 #include "levelwindow.h"
34 #include "loadfile.inc"
35 #include "localsession.h"
36 #include "maincursor.h"
37 #include "mainindexes.h"
39 #include "mainprogress.h"
40 #include "mainsession.h"
44 #include "mwindowgui.h"
48 #include "playbackengine.h"
50 #include "pluginserver.h"
51 #include "pluginset.h"
52 #include "preferences.h"
54 #include "recordlabel.h"
56 #include "samplescroll.h"
57 #include "sighandler.h"
58 #include "splashgui.h"
59 #include "statusbar.h"
61 #include "threadloader.h"
63 #include "tipwindow.h"
64 #include "trackcanvas.h"
67 #include "trackscroll.h"
69 #include "transition.h"
70 #include "transportque.h"
72 #include "videodevice.inc"
73 #include "videowindow.h"
74 #include "vplayback.h"
75 #include "vwindowgui.h"
78 #include "exportedl.h"
90 // Hack for libdv to remove glib dependancy
93 // g_log (const char *log_domain,
95 // const char *format,
101 // g_logv (const char *log_domain,
103 // const char *format,
110 // Hack for XFree86 4.1.0
112 int atexit(void (*function)(void))
125 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
126 brender_lock = new Mutex("MWindow::brender_lock");
129 channeldb_buz = new ChannelDB;
130 channeldb_v4l2jpeg = new ChannelDB;
135 brender_lock->lock("MWindow::~MWindow");
136 if(brender) delete brender;
138 brender_lock->unlock();
149 // Give up and go to a movie
154 delete audio_cache; // delete the cache after the assets
155 delete video_cache; // delete the cache after the assets
161 // delete renderlist;
166 plugin_guis->remove_all_objects();
168 delete plugin_gui_lock;
171 void MWindow::create_defaults_path(char *string)
173 // set the .bcast path
176 sprintf(string, "%s", BCASTDIR);
177 fs.complete_path(string);
178 if(!fs.is_dir(string))
180 fs.create_dir(string);
184 strcat(string, "Cinelerra_rc");
187 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
189 char path[BCTEXTLEN];
190 // Use user supplied path
193 strcpy(path, config_path);
197 create_defaults_path(path);
200 defaults = new BC_Hash(path);
204 void MWindow::init_plugin_path(Preferences *preferences,
205 ArrayList<PluginServer*>* &plugindb,
207 SplashGUI *splash_window,
211 PluginServer *newplugin;
215 for(int i = 0; i < fs->dir_list.total; i++)
217 char path[BCTEXTLEN];
218 strcpy(path, fs->dir_list.values[i]->path);
220 // File is a directory
221 if(!fs->is_dir(path))
227 // Try to query the plugin
228 fs->complete_path(path);
229 //printf("MWindow::init_plugin_path %s\n", path);
230 PluginServer *new_plugin = new PluginServer(path);
231 int result = new_plugin->open_plugin(1, preferences, 0, 0, -1);
235 plugindb->append(new_plugin);
236 new_plugin->close_plugin();
238 splash_window->operation->update(_(new_plugin->title));
241 if(result == PLUGINSERVER_IS_LAD)
244 // Open LAD subplugins
248 new_plugin = new PluginServer(path);
249 result = new_plugin->open_plugin(1,
257 plugindb->append(new_plugin);
258 new_plugin->close_plugin();
260 splash_window->operation->update(_(new_plugin->title));
269 // Plugin failed to open
274 if(splash_window) splash_window->progress->update((*counter)++);
279 void MWindow::init_plugins(Preferences *preferences,
280 ArrayList<PluginServer*>* &plugindb,
281 SplashGUI *splash_window)
283 plugindb = new ArrayList<PluginServer*>;
287 FileSystem cinelerra_fs;
288 ArrayList<FileSystem*> lad_fs;
292 cinelerra_fs.set_filter("[*.plugin][*.so]");
293 result = cinelerra_fs.update(preferences->global_plugin_dir);
298 _("MWindow::init_plugins: couldn't open %s directory\n"),
299 preferences->global_plugin_dir);
302 // Parse LAD environment variable
303 char *env = getenv("LADSPA_PATH");
306 char string[BCTEXTLEN];
310 char *ptr = strchr(ptr1, ':');
318 end = env + strlen(env);
323 int len = end - ptr1;
324 memcpy(string, ptr1, len);
328 FileSystem *fs = new FileSystem;
330 fs->set_filter("*.so");
331 result = fs->update(string);
336 _("MWindow::init_plugins: couldn't open %s directory\n"),
348 int total = cinelerra_fs.total_files();
350 for(int i = 0; i < lad_fs.total; i++)
351 total += lad_fs.values[i]->total_files();
352 if(splash_window) splash_window->progress->update_length(total);
357 init_plugin_path(preferences,
363 // Call automatically generated routine to get plugins
367 for(int i = 0; i < lad_fs.total; i++)
368 init_plugin_path(preferences,
374 lad_fs.remove_all_objects();
377 void MWindow::delete_plugins()
379 for(int i = 0; i < plugindb->total; i++)
381 delete plugindb->values[i];
386 void MWindow::create_plugindb(int do_audio,
391 ArrayList<PluginServer*> &plugindb)
394 for(int i = 0; i < this->plugindb->total; i++)
396 PluginServer *current = this->plugindb->values[i];
398 if(current->audio == do_audio &&
399 current->video == do_video &&
400 (current->realtime == is_realtime || is_realtime < 0) &&
401 current->transition == is_transition &&
402 current->theme == is_theme)
403 plugindb.append(current);
406 // Alphabetize list by title
412 for(int i = 0; i < plugindb.total - 1; i++)
414 PluginServer *value1 = plugindb.values[i];
415 PluginServer *value2 = plugindb.values[i + 1];
416 if(strcmp(_(value1->title), _(value2->title)) > 0)
419 plugindb.values[i] = value2;
420 plugindb.values[i + 1] = value1;
426 PluginServer* MWindow::scan_plugindb(char *title,
431 printf("MWindow::scan_plugindb data_type < 0\n");
435 for(int i = 0; i < plugindb->total; i++)
437 PluginServer *server = plugindb->values[i];
438 if(!strcasecmp(server->title, title) &&
439 ((data_type == TRACK_AUDIO && server->audio) ||
440 (data_type == TRACK_VIDEO && server->video)))
441 return plugindb->values[i];
446 void MWindow::init_preferences()
448 preferences = new Preferences;
449 preferences->load_defaults(defaults);
450 session = new MainSession(this);
451 session->load_defaults(defaults);
454 void MWindow::clean_indexes()
459 int oldest_item = -1;
461 char string[BCTEXTLEN];
462 char string2[BCTEXTLEN];
464 // Delete extra indexes
465 fs.set_filter("*.idx");
466 fs.complete_path(preferences->index_directory);
467 fs.update(preferences->index_directory);
468 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
470 // Eliminate directories
475 for(int i = 0; i < fs.dir_list.total && !result; i++)
477 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
478 if(!fs.is_dir(string))
480 delete fs.dir_list.values[i];
481 fs.dir_list.remove_number(i);
486 total_excess = fs.dir_list.total - preferences->index_count;
488 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
489 while(total_excess > 0)
492 for(int i = 0; i < fs.dir_list.total; i++)
494 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
496 if(i == 0 || fs.get_date(string) <= oldest)
498 oldest = fs.get_date(string);
506 fs.join_names(string,
507 preferences->index_directory,
508 fs.dir_list.values[oldest_item]->name);
509 //printf("MWindow::clean_indexes 1 %s\n", string);
511 perror("delete_indexes");
512 delete fs.dir_list.values[oldest_item];
513 fs.dir_list.remove_number(oldest_item);
515 // Remove table of contents if it exists
516 strcpy(string2, string);
517 char *ptr = strrchr(string2, '.');
520 //printf("MWindow::clean_indexes 2 %s\n", string2);
521 sprintf(ptr, ".toc");
530 void MWindow::init_awindow()
532 awindow = new AWindow(this);
533 awindow->create_objects();
536 void MWindow::init_gwindow()
538 gwindow = new GWindow(this);
539 gwindow->create_objects();
542 void MWindow::init_tipwindow()
544 twindow = new TipWindow(this);
548 void MWindow::init_theme()
552 // Replace blond theme with SUV since it doesn't work
553 if(!strcasecmp(preferences->theme, "Blond"))
554 strcpy(preferences->theme, DEFAULT_THEME);
556 for(int i = 0; i < plugindb->total; i++)
558 if(plugindb->values[i]->theme &&
559 !strcasecmp(preferences->theme, plugindb->values[i]->title))
561 PluginServer plugin = *plugindb->values[i];
562 plugin.open_plugin(0, preferences, 0, 0, -1);
563 theme = plugin.new_theme();
564 theme->mwindow = this;
565 strcpy(theme->path, plugin.path);
566 plugin.close_plugin();
572 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
576 // Load images which may have been forgotten
577 theme->Theme::initialize();
580 // Create menus with user colors
581 theme->build_menus();
587 void MWindow::init_edl()
590 edl->create_objects();
591 edl->load_defaults(defaults);
592 edl->create_default_tracks();
593 edl->tracks->update_y_pixels(theme);
596 void MWindow::init_compositor()
598 cwindow = new CWindow(this);
599 cwindow->create_objects();
602 void MWindow::init_levelwindow()
604 lwindow = new LevelWindow(this);
605 lwindow->create_objects();
608 void MWindow::init_viewer()
610 vwindow = new VWindow(this);
611 vwindow->load_defaults();
612 vwindow->create_objects();
615 void MWindow::init_cache()
617 audio_cache = new CICache(edl, preferences, plugindb);
618 video_cache = new CICache(edl, preferences, plugindb);
621 void MWindow::init_channeldb()
623 channeldb_buz->load("channeldb_buz");
624 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
627 void MWindow::init_menus()
629 char string[BCTEXTLEN];
632 cmodel_to_text(string, BC_RGB888);
633 colormodels.append(new ColormodelItem(string, BC_RGB888));
634 cmodel_to_text(string, BC_RGBA8888);
635 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
636 // cmodel_to_text(string, BC_RGB161616);
637 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
638 // cmodel_to_text(string, BC_RGBA16161616);
639 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
640 cmodel_to_text(string, BC_RGB_FLOAT);
641 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
642 cmodel_to_text(string, BC_RGBA_FLOAT);
643 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
644 cmodel_to_text(string, BC_YUV888);
645 colormodels.append(new ColormodelItem(string, BC_YUV888));
646 cmodel_to_text(string, BC_YUVA8888);
647 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
648 // cmodel_to_text(string, BC_YUV161616);
649 // colormodels.append(new ColormodelItem(string, BC_YUV161616));
650 // cmodel_to_text(string, BC_YUVA16161616);
651 // colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
653 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
654 interlace_project_modes.append(new InterlacemodeItem(string, x));
656 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
657 interlace_asset_modes.append(new InterlacemodeItem(string, x));
659 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
660 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
663 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
665 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
666 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
668 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
669 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
671 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
672 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
674 // Interlacing Fixing Methods
675 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
676 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
677 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
680 void MWindow::init_indexes()
682 mainindexes = new MainIndexes(this);
683 mainindexes->start_loop();
686 void MWindow::init_gui()
688 gui = new MWindowGUI(this);
689 gui->create_objects();
690 gui->load_defaults(defaults);
693 void MWindow::init_signals()
695 sighandler = new SigHandler;
696 sighandler->initialize();
700 void MWindow::init_render()
702 render = new Render(this);
703 // renderlist = new Render(this);
704 batch_render = new BatchRenderThread(this);
707 void MWindow::init_exportedl()
709 exportedl = new ExportEDL(this);
712 void MWindow::init_brender()
714 if(preferences->use_brender && !brender)
716 brender_lock->lock("MWindow::init_brender 1");
717 brender = new BRender(this);
718 brender->initialize();
719 session->brender_end = 0;
720 brender_lock->unlock();
723 if(!preferences->use_brender && brender)
725 brender_lock->lock("MWindow::init_brender 2");
728 session->brender_end = 0;
729 brender_lock->unlock();
731 if(brender) brender->restart(edl);
734 void MWindow::restart_brender()
736 //printf("MWindow::restart_brender 1\n");
737 if(brender) brender->restart(edl);
740 void MWindow::stop_brender()
742 if(brender) brender->stop();
745 int MWindow::brender_available(int position)
748 brender_lock->lock("MWindow::brender_available 1");
751 if(brender->map_valid)
753 brender->map_lock->lock("MWindow::brender_available 2");
754 if(position < brender->map_size &&
757 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
758 if(brender->map[position] == BRender::RENDERED)
761 brender->map_lock->unlock();
764 brender_lock->unlock();
768 void MWindow::set_brender_start()
770 edl->session->brender_start = edl->local_session->get_selectionstart();
772 gui->canvas->draw_overlays();
773 gui->canvas->flash();
778 int MWindow::load_filenames(ArrayList<char*> *filenames,
786 ArrayList<EDL*> new_edls;
787 ArrayList<Asset*> new_assets;
788 ArrayList<File*> new_files;
791 gui->start_hourglass();
793 // Need to stop playback since tracking depends on the EDL not getting
795 cwindow->playback_engine->que->send_command(STOP,
799 vwindow->playback_engine->que->send_command(STOP,
803 cwindow->playback_engine->interrupt_playback(0);
804 vwindow->playback_engine->interrupt_playback(0);
808 // Define new_edls and new_assets to load
810 for(int i = 0; i < filenames->total; i++)
813 File *new_file = new File;
814 Asset *new_asset = new Asset(filenames->values[i]);
815 EDL *new_edl = new EDL;
816 char string[BCTEXTLEN];
818 // Set reel name and number for the asset
819 // If the user wants to overwrite the last used reel number for the clip,
820 // we have to rebuild the index for the file
824 char source_filename[BCTEXTLEN];
825 char index_filename[BCTEXTLEN];
827 strcpy(new_asset->reel_name, reel_name);
828 new_asset->reel_number = reel_number;
830 IndexFile::get_index_filename(source_filename,
831 preferences->index_directory,
834 remove(index_filename);
835 new_asset->index_status = INDEX_NOTTESTED;
838 new_edl->create_objects();
839 new_edl->copy_session(edl);
841 sprintf(string, "Loading %s", new_asset->path);
842 gui->show_message(string);
844 result = new_file->open_file(preferences, new_asset, 1, 0, 0, 0);
849 // Convert media file to EDL
851 if(load_mode != LOAD_RESOURCESONLY)
854 asset_to_edl(new_edl, new_asset);
856 new_edls.append(new_edl);
864 new_assets.append(new_asset);
867 // Set filename to nothing for assets since save EDL would overwrite them.
868 if(load_mode == LOAD_REPLACE ||
869 load_mode == LOAD_REPLACE_CONCATENATE)
872 // Reset timeline position
873 new_edl->local_session->view_start = 0;
874 new_edl->local_session->track_start = 0;
882 sprintf(string, _("Failed to open %s"), new_asset->path);
883 gui->show_message(string, theme->message_error);
888 case FILE_UNRECOGNIZED_CODEC:
891 IndexFile indexfile(this);
892 result = indexfile.open_index(this, new_asset);
895 indexfile.close_index();
898 // Test existing EDLs
901 for(int j = 0; j < new_edls.total + 1; j++)
904 if(j == new_edls.total)
906 if(old_asset = edl->assets->get_asset(new_asset->path))
908 *new_asset = *old_asset;
914 if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
916 *new_asset = *old_asset;
926 char string[BCTEXTLEN];
928 fs.extract_name(string, new_asset->path);
930 strcat(string, _("'s format couldn't be determined."));
931 new_asset->audio_data = 1;
932 new_asset->format = FILE_PCM;
933 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
934 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
935 new_asset->bits = defaults->get("AUDIO_BITS", 16);
936 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
937 new_asset->signed_ = defaults->get("SIGNED_", 1);
938 new_asset->header = defaults->get("HEADER", 0);
940 FileFormat fwindow(this);
941 fwindow.create_objects(new_asset, string);
942 result = fwindow.run_window();
944 defaults->update("AUDIO_CHANNELS", new_asset->channels);
945 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
946 defaults->update("AUDIO_BITS", new_asset->bits);
947 defaults->update("BYTE_ORDER", new_asset->byte_order);
948 defaults->update("SIGNED_", new_asset->signed_);
949 defaults->update("HEADER", new_asset->header);
956 // Recalculate length
959 result = new_file->open_file(preferences, new_asset, 1, 0, 0, 0);
961 if(load_mode != LOAD_RESOURCESONLY)
963 asset_to_edl(new_edl, new_asset);
964 new_edls.append(new_edl);
970 new_assets.append(new_asset);
983 xml_file.read_from_file(filenames->values[i]);
984 // Load EDL for pasting
985 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
986 test_plugins(new_edl, filenames->values[i]);
988 // We don't want a valid reel name/number for projects
989 strcpy(new_asset->reel_name, "");
992 if(load_mode == LOAD_REPLACE ||
993 load_mode == LOAD_REPLACE_CONCATENATE)
995 strcpy(session->filename, filenames->values[i]);
996 strcpy(new_edl->local_session->clip_title, filenames->values[i]);
998 set_filename(new_edl->local_session->clip_title);
1001 new_edls.append(new_edl);
1017 // Store for testing index
1018 new_files.append(new_file);
1024 if(!result) gui->statusbar->default_message();
1034 // Don't back up here.
1037 // For pasting, clear the active region
1038 if(load_mode == LOAD_PASTE)
1040 double start = edl->local_session->get_selectionstart();
1041 double end = edl->local_session->get_selectionend();
1042 if(!EQUIV(start, end))
1045 edl->session->labels_follow_edits,
1046 edl->session->plugins_follow_edits);
1049 paste_edls(&new_edls,
1053 edl->session->labels_follow_edits,
1054 edl->session->plugins_follow_edits);
1062 // Add new assets to EDL and schedule assets for index building.
1063 // Used for loading resources only.
1064 if(new_assets.total)
1066 for(int i = 0; i < new_assets.total; i++)
1068 Asset *new_asset = new_assets.values[i];
1070 File *index_file = 0;
1072 for(int j = 0; j < new_files.total; j++)
1074 new_file = new_files.values[j];
1075 if(!strcmp(new_file->asset->path,
1083 mainindexes->add_next_asset(got_it ? new_file : 0,
1084 new_assets.values[i]);
1085 edl->assets->update(new_assets.values[i]);
1089 // Start examining next batch of index files
1090 mainindexes->start_build();
1094 update_project(load_mode);
1099 new_edls.remove_all_objects();
1101 new_assets.remove_all_objects();
1103 new_files.remove_all_objects();
1106 undo->update_undo(_("load"), LOAD_ALL, 0);
1110 gui->stop_hourglass();
1119 void MWindow::test_plugins(EDL *new_edl, char *path)
1121 // Do a check weather plugins exist
1122 for(Track *track = new_edl->tracks->first; track; track = track->next)
1124 for(int k = 0; k < track->plugin_set.total; k++)
1126 PluginSet *plugin_set = track->plugin_set.values[k];
1127 for(Plugin *plugin = (Plugin*)plugin_set->first;
1129 plugin = (Plugin*)plugin->next)
1131 if(plugin->plugin_type == PLUGIN_STANDALONE)
1133 // ok we need to find it in plugindb
1134 int plugin_found = 0;
1135 for(int j = 0; j < plugindb->total; j++)
1137 PluginServer *server = plugindb->values[j];
1138 if(!strcasecmp(server->title, plugin->title) &&
1139 ((track->data_type == TRACK_AUDIO && server->audio) ||
1140 (track->data_type == TRACK_VIDEO && server->video)) &&
1141 (!server->transition))
1146 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 crashing.\n", plugin->title, path);
1151 for(Edit *edit = (Edit*)track->edits->first;
1153 edit = (Edit*)edit->next)
1155 if (edit->transition)
1157 // ok we need to find transition in plugindb
1158 int transition_found = 0;
1159 for(int j = 0; j < plugindb->total; j++)
1161 PluginServer *server = plugindb->values[j];
1162 if(!strcasecmp(server->title, edit->transition->title) &&
1163 ((track->data_type == TRACK_AUDIO && server->audio) ||
1164 (track->data_type == TRACK_VIDEO && server->video)) &&
1165 (server->transition))
1166 transition_found = 1;
1168 if (!transition_found)
1170 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 crashing.\n", edit->transition->title, path);
1181 void MWindow::create_objects(int want_gui,
1185 char string[BCTEXTLEN];
1192 // For some reason, init_signals must come after show_splash or the signals won't
1199 init_defaults(defaults, config_path);
1203 init_plugins(preferences, plugindb, splash_window);
1204 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1207 // Default project created here
1233 mainprogress = new MainProgress(this, gui);
1234 undo = new MainUndo(this);
1236 plugin_guis = new ArrayList<PluginServer*>;
1239 if(session->show_vwindow) vwindow->gui->show_window();
1240 if(session->show_cwindow) cwindow->gui->show_window();
1241 if(session->show_awindow) awindow->gui->show_window();
1242 if(session->show_lwindow) lwindow->gui->show_window();
1243 if(session->show_gwindow) gwindow->gui->show_window();
1247 gui->mainmenu->load_defaults(defaults);
1249 gui->mainmenu->update_toggles(0);
1251 gui->patchbay->update();
1253 gui->canvas->draw();
1255 gui->cursor->draw(1);
1258 gui->raise_window();
1260 if(preferences->use_tipwindow)
1270 void MWindow::show_splash()
1272 #include "data/heroine_logo12_png.h"
1273 VFrame *frame = new VFrame(heroine_logo12_png);
1274 BC_DisplayInfo display_info;
1275 splash_window = new SplashGUI(frame,
1276 display_info.get_root_w() / 2 - frame->get_w() / 2,
1277 display_info.get_root_h() / 2 - frame->get_h() / 2);
1278 splash_window->create_objects();
1281 void MWindow::hide_splash()
1284 delete splash_window;
1289 void MWindow::start()
1299 void MWindow::show_vwindow()
1301 session->show_vwindow = 1;
1302 vwindow->gui->lock_window("MWindow::show_vwindow");
1303 vwindow->gui->show_window();
1304 vwindow->gui->raise_window();
1305 vwindow->gui->flush();
1306 vwindow->gui->unlock_window();
1307 gui->mainmenu->show_vwindow->set_checked(1);
1310 void MWindow::show_awindow()
1312 session->show_awindow = 1;
1313 awindow->gui->lock_window("MWindow::show_awindow");
1314 awindow->gui->show_window();
1315 awindow->gui->raise_window();
1316 awindow->gui->flush();
1317 awindow->gui->unlock_window();
1318 gui->mainmenu->show_awindow->set_checked(1);
1321 void MWindow::show_cwindow()
1323 session->show_cwindow = 1;
1324 cwindow->show_window();
1325 gui->mainmenu->show_cwindow->set_checked(1);
1328 void MWindow::show_gwindow()
1330 session->show_gwindow = 1;
1332 gwindow->gui->lock_window("MWindow::show_gwindow");
1333 gwindow->gui->show_window();
1334 gwindow->gui->raise_window();
1335 gwindow->gui->flush();
1336 gwindow->gui->unlock_window();
1338 gui->mainmenu->show_gwindow->set_checked(1);
1341 void MWindow::show_lwindow()
1343 session->show_lwindow = 1;
1344 lwindow->gui->lock_window("MWindow::show_lwindow");
1345 lwindow->gui->show_window();
1346 lwindow->gui->raise_window();
1347 lwindow->gui->flush();
1348 lwindow->gui->unlock_window();
1349 gui->mainmenu->show_lwindow->set_checked(1);
1352 void MWindow::tile_windows()
1354 session->default_window_positions();
1355 gui->default_positions();
1358 void MWindow::toggle_loop_playback()
1360 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1361 set_loop_boundaries();
1364 gui->canvas->draw_overlays();
1365 gui->canvas->flash();
1366 sync_parameters(CHANGE_PARAMS);
1369 void MWindow::set_titles(int value)
1371 edl->session->show_titles = value;
1372 trackmovement(edl->local_session->track_start);
1375 void MWindow::set_auto_keyframes(int value)
1377 gui->lock_window("MWindow::set_auto_keyframes");
1378 edl->session->auto_keyframes = value;
1379 gui->mbuttons->edit_panel->keyframe->update(value);
1381 gui->unlock_window();
1382 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1383 cwindow->gui->edit_panel->keyframe->update(value);
1384 cwindow->gui->flush();
1385 cwindow->gui->unlock_window();
1388 int MWindow::set_editing_mode(int new_editing_mode)
1390 gui->lock_window("MWindow::set_editing_mode");
1391 edl->session->editing_mode = new_editing_mode;
1392 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1393 gui->mbuttons->edit_panel->update();
1394 gui->canvas->update_cursor();
1395 gui->unlock_window();
1396 cwindow->gui->lock_window("MWindow::set_editing_mode");
1397 cwindow->gui->edit_panel->update();
1398 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1399 cwindow->gui->unlock_window();
1404 void MWindow::sync_parameters(int change_type)
1407 // Sync engines which are playing back
1408 if(cwindow->playback_engine->is_playing_back)
1410 if(change_type == CHANGE_PARAMS)
1412 // TODO: block keyframes until synchronization is done
1413 cwindow->playback_engine->sync_parameters(edl);
1418 int command = cwindow->playback_engine->command->command;
1419 cwindow->playback_engine->que->send_command(STOP,
1423 // Waiting for tracking to finish would make the restart position more
1424 // accurate but it can't lock the window to stop tracking for some reason.
1425 // Not waiting for tracking gives a faster response but restart position is
1426 // only as accurate as the last tracking update.
1427 cwindow->playback_engine->interrupt_playback(0);
1428 cwindow->playback_engine->que->send_command(command,
1437 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1444 void MWindow::update_caches()
1446 audio_cache->set_edl(edl);
1447 video_cache->set_edl(edl);
1450 void MWindow::show_plugin(Plugin *plugin)
1453 //printf("MWindow::show_plugin 1\n");
1454 plugin_gui_lock->lock("MWindow::show_plugin");
1455 for(int i = 0; i < plugin_guis->total; i++)
1457 // Pointer comparison
1458 if(plugin_guis->values[i]->plugin == plugin)
1460 plugin_guis->values[i]->raise_window();
1466 //printf("MWindow::show_plugin 1\n");
1471 printf("MWindow::show_plugin track not defined.\n");
1473 PluginServer *server = scan_plugindb(plugin->title,
1474 plugin->track->data_type);
1476 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
1477 if(server && server->uses_gui)
1479 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
1480 // Needs mwindow to do GUI
1481 gui->set_mwindow(this);
1482 gui->open_plugin(0, preferences, edl, plugin, -1);
1487 plugin_gui_lock->unlock();
1488 //printf("MWindow::show_plugin 2\n");
1491 void MWindow::hide_plugin(Plugin *plugin, int lock)
1493 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
1495 for(int i = 0; i < plugin_guis->total; i++)
1497 if(plugin_guis->values[i]->plugin == plugin)
1499 PluginServer *ptr = plugin_guis->values[i];
1500 plugin_guis->remove(ptr);
1501 if(lock) plugin_gui_lock->unlock();
1502 // Last command executed in client side close
1507 if(lock) plugin_gui_lock->unlock();
1511 void MWindow::hide_plugins()
1513 plugin_gui_lock->lock("MWindow::hide_plugins");
1514 plugin_guis->remove_all_objects();
1515 plugin_gui_lock->unlock();
1518 void MWindow::update_plugin_guis()
1520 plugin_gui_lock->lock("MWindow::update_plugin_guis");
1522 for(int i = 0; i < plugin_guis->total; i++)
1524 plugin_guis->values[i]->update_gui();
1526 plugin_gui_lock->unlock();
1529 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
1531 plugin_gui_lock->lock("MWindow::render_plugin_gui");
1532 for(int i = 0; i < plugin_guis->total; i++)
1534 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1536 plugin_guis->values[i]->render_gui(data);
1540 plugin_gui_lock->unlock();
1543 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
1545 plugin_gui_lock->lock("MWindow::render_plugin_gui");
1546 for(int i = 0; i < plugin_guis->total; i++)
1548 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1550 plugin_guis->values[i]->render_gui(data, size);
1554 plugin_gui_lock->unlock();
1558 void MWindow::update_plugin_states()
1560 plugin_gui_lock->lock("MWindow::update_plugin_states");
1561 for(int i = 0; i < plugin_guis->total; i++)
1565 Plugin *src_plugin = plugin_guis->values[i]->plugin;
1566 PluginServer *src_plugingui = plugin_guis->values[i];
1568 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
1569 for(Track *track = edl->tracks->first;
1571 track = track->next)
1574 j < track->plugin_set.total && !result;
1577 PluginSet *plugin_set = track->plugin_set.values[j];
1578 for(Plugin *plugin = (Plugin*)plugin_set->first;
1580 plugin = (Plugin*)plugin->next)
1582 if(plugin == src_plugin &&
1583 !strcmp(plugin->title, src_plugingui->title)) result = 1;
1589 // Doesn't exist anymore
1592 hide_plugin(src_plugin, 0);
1596 plugin_gui_lock->unlock();
1600 void MWindow::update_plugin_titles()
1602 for(int i = 0; i < plugin_guis->total; i++)
1604 plugin_guis->values[i]->update_title();
1608 int MWindow::asset_to_edl(EDL *new_edl,
1610 RecordLabels *labels)
1612 //printf("MWindow::asset_to_edl 1\n");
1613 // new_edl->load_defaults(defaults);
1615 // Keep frame rate, sample rate, and output size unchanged.
1616 // These parameters would revert the project if VWindow displayed an asset
1617 // of different size than the project.
1618 if(new_asset->video_data)
1620 new_edl->session->video_tracks = new_asset->layers;
1621 // new_edl->session->frame_rate = new_asset->frame_rate;
1622 // new_edl->session->output_w = new_asset->width;
1623 // new_edl->session->output_h = new_asset->height;
1626 new_edl->session->video_tracks = 0;
1633 if(new_asset->audio_data)
1635 new_edl->session->audio_tracks = new_asset->channels;
1636 // new_edl->session->sample_rate = new_asset->sample_rate;
1639 new_edl->session->audio_tracks = 0;
1640 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1642 new_edl->create_default_tracks();
1643 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1645 // Disable drawing if the file format isn't fast enough.
1646 // MPEG is now faster than most other codecs.
1647 // if(new_asset->format == FILE_MPEG)
1649 // for(Track *current = new_edl->tracks->first;
1653 // if(current->data_type == TRACK_VIDEO) current->draw = 0;
1659 //printf("MWindow::asset_to_edl 3\n");
1660 new_edl->insert_asset(new_asset, 0, 0, labels);
1661 //printf("MWindow::asset_to_edl 3\n");
1667 char string[BCTEXTLEN];
1669 fs.extract_name(string, new_asset->path);
1670 //printf("MWindow::asset_to_edl 3\n");
1672 strcpy(new_edl->local_session->clip_title, string);
1673 //printf("MWindow::asset_to_edl 4 %s\n", string);
1679 // Reset everything after a load.
1680 void MWindow::update_project(int load_mode)
1683 edl->tracks->update_y_pixels(theme);
1688 gui->update(1, 1, 1, 1, 1, 1, 1);
1690 cwindow->update(0, 0, 1, 1, 1);
1693 if(load_mode == LOAD_REPLACE ||
1694 load_mode == LOAD_REPLACE_CONCATENATE)
1696 vwindow->change_source();
1703 cwindow->gui->slider->set_position();
1704 cwindow->gui->timebar->update(1, 1);
1705 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1710 awindow->gui->lock_window("MWindow::update_project");
1711 awindow->gui->update_assets();
1712 awindow->gui->flush();
1713 awindow->gui->unlock_window();
1718 void MWindow::rebuild_indices()
1720 char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
1722 for(int i = 0; i < session->drag_assets->total; i++)
1724 //printf("MWindow::rebuild_indices 1 %s\n", session->drag_assets->values[i]->path);
1726 IndexFile::get_index_filename(source_filename,
1727 preferences->index_directory,
1729 session->drag_assets->values[i]->path);
1730 remove(index_filename);
1731 // Schedule index build
1732 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
1733 mainindexes->add_next_asset(0, session->drag_assets->values[i]);
1735 mainindexes->start_build();
1739 void MWindow::save_backup()
1742 edl->set_project_path(session->filename);
1743 edl->save_xml(plugindb,
1748 file.terminate_string();
1749 char path[BCTEXTLEN];
1751 strcpy(path, BACKUP_PATH);
1752 fs.complete_path(path);
1754 if(file.write_to_file(path))
1757 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
1758 gui->show_message(string2);
1763 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
1766 if(!width || !height) return 1;
1767 float fraction = (float)width / height;
1769 for(denominator = 1;
1770 denominator < 100 &&
1771 fabs(fraction * denominator - (int)(fraction * denominator)) > .001;
1775 w = denominator * width / height;
1782 void MWindow::remove_assets_from_project(int push_undo)
1784 // Remove from caches
1785 for(int i = 0; i < session->drag_assets->total; i++)
1787 audio_cache->delete_entry(session->drag_assets->values[i]);
1788 video_cache->delete_entry(session->drag_assets->values[i]);
1791 video_cache->dump();
1792 audio_cache->dump();
1794 // Remove from VWindow.
1795 for(int i = 0; i < session->drag_clips->total; i++)
1797 if(session->drag_clips->values[i] == vwindow->get_edl())
1799 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
1800 vwindow->remove_source();
1801 vwindow->gui->unlock_window();
1805 for(int i = 0; i < session->drag_assets->total; i++)
1807 if(session->drag_assets->values[i] == vwindow->get_asset())
1809 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
1810 vwindow->remove_source();
1811 vwindow->gui->unlock_window();
1815 edl->remove_from_project(session->drag_assets);
1816 edl->remove_from_project(session->drag_clips);
1818 if(push_undo) undo->update_undo(_("remove assets"), LOAD_ALL);
1821 gui->lock_window("MWindow::remove_assets_from_project 3");
1829 gui->unlock_window();
1831 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
1832 awindow->gui->update_assets();
1833 awindow->gui->flush();
1834 awindow->gui->unlock_window();
1836 // Removes from playback here
1837 sync_parameters(CHANGE_ALL);
1840 void MWindow::remove_assets_from_disk()
1843 for(int i = 0; i < session->drag_assets->total; i++)
1845 remove(session->drag_assets->values[i]->path);
1848 remove_assets_from_project(1);
1851 void MWindow::dump_plugins()
1853 for(int i = 0; i < plugindb->total; i++)
1855 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
1856 plugindb->values[i]->audio,
1857 plugindb->values[i]->video,
1858 plugindb->values[i]->realtime,
1859 plugindb->values[i]->transition,
1860 plugindb->values[i]->theme,
1861 plugindb->values[i]->title);
1889 int MWindow::save_defaults()
1891 gui->save_defaults(defaults);
1892 edl->save_defaults(defaults);
1893 session->save_defaults(defaults);
1894 preferences->save_defaults(defaults);
1900 int MWindow::run_script(FileXML *script)
1902 int result = 0, result2 = 0;
1903 while(!result && !result2)
1905 result = script->read_tag();
1908 if(script->tag.title_is("new_project"))
1910 // Run new in immediate mode.
1911 // gui->mainmenu->new_project->run_script(script);
1914 if(script->tag.title_is("record"))
1916 // Run record as a thread. It is a terminal command.
1918 // Will read the complete scipt file without letting record read it if not
1924 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
1931 // ================================= synchronization
1934 int MWindow::interrupt_indexes()
1936 mainindexes->interrupt_build();
1942 void MWindow::next_time_format()
1944 switch(edl->session->time_format)
1946 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
1947 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
1948 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
1949 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
1950 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
1951 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
1952 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
1955 time_format_common();
1958 void MWindow::prev_time_format()
1960 switch(edl->session->time_format)
1962 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
1963 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
1964 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
1965 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
1966 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
1967 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
1968 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
1971 time_format_common();
1974 void MWindow::time_format_common()
1976 gui->lock_window("MWindow::next_time_format");
1977 gui->redraw_time_dependancies();
1978 char string[BCTEXTLEN], string2[BCTEXTLEN];
1979 sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
1980 gui->show_message(string);
1982 gui->unlock_window();
1986 int MWindow::set_filename(char *filename)
1988 strcpy(session->filename, filename);
1991 if(filename[0] == 0)
1993 gui->set_title(PROGRAM_NAME);
1998 char string[BCTEXTLEN], string2[BCTEXTLEN];
1999 dir.extract_name(string, filename);
2000 sprintf(string2, PROGRAM_NAME ": %s", string);
2001 gui->set_title(string2);
2014 int MWindow::set_loop_boundaries()
2016 double start = edl->local_session->get_selectionstart();
2017 double end = edl->local_session->get_selectionend();
2025 if(edl->tracks->total_length())
2028 end = edl->tracks->total_length();
2035 if(edl->local_session->loop_playback && start != end)
2037 edl->local_session->loop_start = start;
2038 edl->local_session->loop_end = end;
2049 int MWindow::reset_meters()
2051 cwindow->gui->lock_window("MWindow::reset_meters 1");
2052 cwindow->gui->meters->reset_meters();
2053 cwindow->gui->unlock_window();
2055 vwindow->gui->lock_window("MWindow::reset_meters 2");
2056 vwindow->gui->meters->reset_meters();
2057 vwindow->gui->unlock_window();
2059 lwindow->gui->lock_window("MWindow::reset_meters 3");
2060 lwindow->gui->panel->reset_meters();
2061 lwindow->gui->unlock_window();
2063 gui->lock_window("MWindow::reset_meters 4");
2064 gui->patchbay->reset_meters();
2065 gui->unlock_window();