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"
27 #include "interlacemodes.h"
29 #include "levelwindowgui.h"
30 #include "levelwindow.h"
31 #include "loadfile.inc"
32 #include "localsession.h"
33 #include "maincursor.h"
34 #include "mainindexes.h"
36 #include "mainprogress.h"
37 #include "mainsession.h"
41 #include "mwindowgui.h"
45 #include "playbackengine.h"
47 #include "pluginserver.h"
48 #include "pluginset.h"
49 #include "preferences.h"
51 #include "recordlabel.h"
53 #include "samplescroll.h"
54 #include "sighandler.h"
55 #include "splashgui.h"
56 #include "statusbar.h"
58 #include "threadloader.h"
60 #include "trackcanvas.h"
63 #include "trackscroll.h"
65 #include "transition.h"
66 #include "transportque.h"
68 #include "videodevice.inc"
69 #include "videowindow.h"
70 #include "vplayback.h"
71 #include "vwindowgui.h"
85 // Hack for libdv to remove glib dependancy
88 // g_log (const char *log_domain,
90 // const char *format,
96 // g_logv (const char *log_domain,
98 // const char *format,
105 // Hack for XFree86 4.1.0
107 int atexit(void (*function)(void))
122 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
123 brender_lock = new Mutex("MWindow::brender_lock");
126 channeldb_buz = new ChannelDB;
127 channeldb_v4l2jpeg = new ChannelDB;
132 brender_lock->lock("MWindow::~MWindow");
133 if(brender) delete brender;
135 brender_lock->unlock();
140 TRACE("MWindow::~MWindow 1\n");
142 TRACE("MWindow::~MWindow 2\n");
145 TRACE("MWindow::~MWindow 3\n");
146 // Give up and go to a movie
149 TRACE("MWindow::~MWindow 4\n");
151 delete audio_cache; // delete the cache after the assets
152 delete video_cache; // delete the cache after the assets
158 // delete renderlist;
163 plugin_guis->remove_all_objects();
165 delete plugin_gui_lock;
168 void MWindow::init_defaults(Defaults* &defaults, char *config_path)
170 char path[BCTEXTLEN];
171 // Use user supplied path
174 strcpy(path, config_path);
178 // set the .bcast path
181 sprintf(path, "%s", BCASTDIR);
182 fs.complete_path(path);
189 strcat(path, "Cinelerra_rc");
192 defaults = new Defaults(path);
196 void MWindow::init_plugin_path(Preferences *preferences,
197 ArrayList<PluginServer*>* &plugindb,
199 SplashGUI *splash_window,
203 PluginServer *newplugin;
207 for(int i = 0; i < fs->dir_list.total; i++)
209 char path[BCTEXTLEN];
210 strcpy(path, fs->dir_list.values[i]->path);
212 // File is a directory
213 if(!fs->is_dir(path))
219 // Try to query the plugin
220 fs->complete_path(path);
221 //printf("MWindow::init_plugin_path %s\n", path);
222 PluginServer *new_plugin = new PluginServer(path);
223 int result = new_plugin->open_plugin(1, preferences, 0, 0, -1);
227 plugindb->append(new_plugin);
228 new_plugin->close_plugin();
230 splash_window->operation->update(_(new_plugin->title));
233 if(result == PLUGINSERVER_IS_LAD)
236 // Open LAD subplugins
240 new_plugin = new PluginServer(path);
241 result = new_plugin->open_plugin(1,
249 plugindb->append(new_plugin);
250 new_plugin->close_plugin();
252 splash_window->operation->update(_(new_plugin->title));
258 // Plugin failed to open
262 if(splash_window) splash_window->progress->update((*counter)++);
267 void MWindow::init_plugins(Preferences *preferences,
268 ArrayList<PluginServer*>* &plugindb,
269 SplashGUI *splash_window)
271 plugindb = new ArrayList<PluginServer*>;
275 FileSystem cinelerra_fs;
276 ArrayList<FileSystem*> lad_fs;
280 cinelerra_fs.set_filter("[*.plugin][*.so]");
281 result = cinelerra_fs.update(preferences->global_plugin_dir);
286 _("MWindow::init_plugins: couldn't open %s directory\n"),
287 preferences->global_plugin_dir);
290 // Parse LAD environment variable
291 char *env = getenv("LADSPA_PATH");
294 char string[BCTEXTLEN];
298 char *ptr = strchr(ptr1, ':');
306 end = env + strlen(env);
311 int len = end - ptr1;
312 memcpy(string, ptr1, len);
316 FileSystem *fs = new FileSystem;
318 fs->set_filter("*.so");
319 result = fs->update(string);
324 _("MWindow::init_plugins: couldn't open %s directory\n"),
336 int total = cinelerra_fs.total_files();
338 for(int i = 0; i < lad_fs.total; i++)
339 total += lad_fs.values[i]->total_files();
340 if(splash_window) splash_window->progress->update_length(total);
344 init_plugin_path(preferences,
350 // Call automatically generated routine to get plugins
354 for(int i = 0; i < lad_fs.total; i++)
355 init_plugin_path(preferences,
361 lad_fs.remove_all_objects();
364 void MWindow::delete_plugins()
366 for(int i = 0; i < plugindb->total; i++)
368 delete plugindb->values[i];
373 void MWindow::create_plugindb(int do_audio,
378 ArrayList<PluginServer*> &plugindb)
381 for(int i = 0; i < this->plugindb->total; i++)
383 PluginServer *current = this->plugindb->values[i];
385 if(current->audio == do_audio &&
386 current->video == do_video &&
387 (current->realtime == is_realtime || is_realtime < 0) &&
388 current->transition == is_transition &&
389 current->theme == is_theme)
390 plugindb.append(current);
393 // Alphabetize list by title
399 for(int i = 0; i < plugindb.total - 1; i++)
401 PluginServer *value1 = plugindb.values[i];
402 PluginServer *value2 = plugindb.values[i + 1];
403 if(strcmp(_(value1->title), _(value2->title)) > 0)
406 plugindb.values[i] = value2;
407 plugindb.values[i + 1] = value1;
413 PluginServer* MWindow::scan_plugindb(char *title,
418 printf("MWindow::scan_plugindb data_type < 0\n");
422 for(int i = 0; i < plugindb->total; i++)
424 PluginServer *server = plugindb->values[i];
425 if(!strcasecmp(server->title, title) &&
426 ((data_type == TRACK_AUDIO && server->audio) ||
427 (data_type == TRACK_VIDEO && server->video)))
428 return plugindb->values[i];
433 void MWindow::init_preferences()
435 preferences = new Preferences;
436 preferences->load_defaults(defaults);
437 session = new MainSession(this);
438 session->load_defaults(defaults);
441 void MWindow::clean_indexes()
448 char string[BCTEXTLEN];
450 // Delete extra indexes
451 fs.set_filter("*.idx");
452 fs.complete_path(preferences->index_directory);
453 fs.update(preferences->index_directory);
454 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
456 // Eliminate directories
461 for(int i = 0; i < fs.dir_list.total && !result; i++)
463 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
464 if(!fs.is_dir(string))
466 delete fs.dir_list.values[i];
467 fs.dir_list.remove_number(i);
472 total_excess = fs.dir_list.total - preferences->index_count;
474 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
475 while(total_excess > 0)
478 for(int i = 0; i < fs.dir_list.total; i++)
480 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
482 if(i == 0 || fs.get_date(string) <= oldest)
484 oldest = fs.get_date(string);
489 fs.join_names(string, preferences->index_directory, fs.dir_list.values[oldest_item]->name);
491 perror("delete_indexes");
492 delete fs.dir_list.values[oldest_item];
493 fs.dir_list.remove_number(oldest_item);
498 void MWindow::init_awindow()
500 awindow = new AWindow(this);
501 awindow->create_objects();
504 void MWindow::init_theme()
508 for(int i = 0; i < plugindb->total; i++)
510 if(plugindb->values[i]->theme &&
511 !strcasecmp(preferences->theme, plugindb->values[i]->title))
513 PluginServer plugin = *plugindb->values[i];
514 plugin.open_plugin(0, preferences, 0, 0, -1);
515 theme = plugin.new_theme();
516 theme->mwindow = this;
517 strcpy(theme->path, plugin.path);
518 plugin.close_plugin();
524 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
530 // Load images which may have been forgotten
531 theme->Theme::initialize();
536 void MWindow::init_edl()
539 edl->create_objects();
540 edl->load_defaults(defaults);
541 edl->create_default_tracks();
542 edl->tracks->update_y_pixels(theme);
545 void MWindow::init_compositor()
547 cwindow = new CWindow(this);
548 cwindow->create_objects();
551 void MWindow::init_levelwindow()
553 lwindow = new LevelWindow(this);
554 lwindow->create_objects();
557 void MWindow::init_viewer()
559 vwindow = new VWindow(this);
560 vwindow->load_defaults();
561 vwindow->create_objects();
564 void MWindow::init_cache()
566 audio_cache = new CICache(edl, preferences, plugindb);
567 video_cache = new CICache(edl, preferences, plugindb);
570 void MWindow::init_channeldb()
572 channeldb_buz->load("channeldb_buz");
573 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
576 void MWindow::init_menus()
578 char string[BCTEXTLEN];
581 cmodel_to_text(string, BC_RGB888);
582 colormodels.append(new ColormodelItem(string, BC_RGB888));
583 cmodel_to_text(string, BC_RGBA8888);
584 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
585 // cmodel_to_text(string, BC_RGB161616);
586 // colormodels.append(new ColormodelItem(string, BC_RGB161616));
587 // cmodel_to_text(string, BC_RGBA16161616);
588 // colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
589 cmodel_to_text(string, BC_RGB_FLOAT);
590 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
591 cmodel_to_text(string, BC_RGBA_FLOAT);
592 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
593 cmodel_to_text(string, BC_YUV888);
594 colormodels.append(new ColormodelItem(string, BC_YUV888));
595 cmodel_to_text(string, BC_YUVA8888);
596 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
597 cmodel_to_text(string, BC_YUV161616);
598 colormodels.append(new ColormodelItem(string, BC_YUV161616));
599 cmodel_to_text(string, BC_YUVA16161616);
600 colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
602 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
603 interlace_project_modes.append(new InterlacemodeItem(string, x));
605 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
606 interlace_asset_modes.append(new InterlacemodeItem(string, x));
608 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
609 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
612 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
614 ILACEASSETMODELISTADD(BC_ILACE_MODE_ODDLEADS);
615 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_ODDLEADS);
617 ILACEASSETMODELISTADD(BC_ILACE_MODE_EVENLEADS);
618 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_EVENLEADS);
620 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
621 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
623 // Interlacing Fixing Methods
624 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
625 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
626 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
629 void MWindow::init_indexes()
631 mainindexes = new MainIndexes(this);
632 mainindexes->start_loop();
635 void MWindow::init_gui()
637 gui = new MWindowGUI(this);
638 gui->create_objects();
639 gui->load_defaults(defaults);
642 void MWindow::init_signals()
644 sighandler = new SigHandler;
645 sighandler->initialize();
649 void MWindow::init_render()
651 render = new Render(this);
652 // renderlist = new Render(this);
653 batch_render = new BatchRenderThread(this);
656 void MWindow::init_brender()
658 if(preferences->use_brender && !brender)
660 brender_lock->lock("MWindow::init_brender 1");
661 brender = new BRender(this);
662 brender->initialize();
663 session->brender_end = 0;
664 brender_lock->unlock();
667 if(!preferences->use_brender && brender)
669 brender_lock->lock("MWindow::init_brender 2");
672 session->brender_end = 0;
673 brender_lock->unlock();
675 if(brender) brender->restart(edl);
678 void MWindow::restart_brender()
680 //printf("MWindow::restart_brender 1\n");
681 if(brender) brender->restart(edl);
684 void MWindow::stop_brender()
686 if(brender) brender->stop();
689 int MWindow::brender_available(int position)
692 brender_lock->lock("MWindow::brender_available 1");
695 if(brender->map_valid)
697 brender->map_lock->lock("MWindow::brender_available 2");
698 if(position < brender->map_size &&
701 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
702 if(brender->map[position] == BRender::RENDERED)
705 brender->map_lock->unlock();
708 brender_lock->unlock();
712 void MWindow::set_brender_start()
714 edl->session->brender_start = edl->local_session->get_selectionstart();
716 gui->canvas->draw_overlays();
717 gui->canvas->flash();
722 int MWindow::load_filenames(ArrayList<char*> *filenames,
729 TRACE("MWindow::load_filenames 1");
730 ArrayList<EDL*> new_edls;
731 ArrayList<Asset*> new_assets;
733 // Need to stop playback since tracking depends on the EDL not getting
735 cwindow->playback_engine->que->send_command(STOP,
739 vwindow->playback_engine->que->send_command(STOP,
743 cwindow->playback_engine->interrupt_playback(0);
744 vwindow->playback_engine->interrupt_playback(0);
748 // Define new_edls and new_assets to load
750 for(int i = 0; i < filenames->total; i++)
753 File *new_file = new File;
754 Asset *new_asset = new Asset(filenames->values[i]);
755 EDL *new_edl = new EDL;
756 char string[BCTEXTLEN];
758 // Set reel name and number for the asset
759 // If the user wants to overwrite the last used reel number for the clip,
760 // we have to rebuild the index for the file
764 char source_filename[BCTEXTLEN];
765 char index_filename[BCTEXTLEN];
767 strcpy(new_asset->reel_name, reel_name);
768 new_asset->reel_number = reel_number;
770 IndexFile::get_index_filename(source_filename,
771 preferences->index_directory,
774 remove(index_filename);
775 new_asset->index_status = INDEX_NOTTESTED;
778 new_edl->create_objects();
779 new_edl->copy_session(edl);
781 sprintf(string, "Loading %s", new_asset->path);
782 gui->show_message(string, BLACK);
783 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
787 // Convert media file to EDL
789 if(load_mode != LOAD_RESOURCESONLY)
791 asset_to_edl(new_edl, new_asset);
792 new_edls.append(new_edl);
797 new_assets.append(new_asset);
800 // Set filename to nothing for assets since save EDL would overwrite them.
801 if(load_mode == LOAD_REPLACE ||
802 load_mode == LOAD_REPLACE_CONCATENATE)
805 // Reset timeline position
806 new_edl->local_session->view_start = 0;
807 new_edl->local_session->track_start = 0;
814 sprintf(string, _("Failed to open %s"), new_asset->path);
815 gui->show_message(string, RED);
820 case FILE_UNRECOGNIZED_CODEC:
823 IndexFile indexfile(this);
824 result = indexfile.open_index(this, new_asset);
827 indexfile.close_index();
830 // Test existing EDLs
833 for(int j = 0; j < new_edls.total + 1; j++)
836 if(j == new_edls.total)
838 if(old_asset = edl->assets->get_asset(new_asset->path))
840 *new_asset = *old_asset;
846 if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
848 *new_asset = *old_asset;
858 char string[BCTEXTLEN];
860 fs.extract_name(string, new_asset->path);
862 strcat(string, _("'s format couldn't be determined."));
863 new_asset->audio_data = 1;
864 new_asset->format = FILE_PCM;
865 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
866 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
867 new_asset->bits = defaults->get("AUDIO_BITS", 16);
868 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
869 new_asset->signed_ = defaults->get("SIGNED_", 1);
870 new_asset->header = defaults->get("HEADER", 0);
872 FileFormat fwindow(this);
873 fwindow.create_objects(new_asset, string);
874 result = fwindow.run_window();
876 defaults->update("AUDIO_CHANNELS", new_asset->channels);
877 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
878 defaults->update("AUDIO_BITS", new_asset->bits);
879 defaults->update("BYTE_ORDER", new_asset->byte_order);
880 defaults->update("SIGNED_", new_asset->signed_);
881 defaults->update("HEADER", new_asset->header);
888 // Recalculate length
891 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
893 if(load_mode != LOAD_RESOURCESONLY)
895 asset_to_edl(new_edl, new_asset);
896 new_edls.append(new_edl);
901 new_assets.append(new_asset);
914 xml_file.read_from_file(filenames->values[i]);
915 // Load EDL for pasting
916 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
917 test_plugins(new_edl, filenames->values[i]);
919 // We don't want a valid reel name/number for projects
920 strcpy(new_asset->reel_name, "");
923 if(load_mode == LOAD_REPLACE ||
924 load_mode == LOAD_REPLACE_CONCATENATE)
926 strcpy(session->filename, filenames->values[i]);
927 strcpy(new_edl->local_session->clip_title, filenames->values[i]);
929 set_filename(new_edl->local_session->clip_title);
932 new_edls.append(new_edl);
949 if(!result) gui->statusbar->default_message();
959 // Don't back up here.
962 // For pasting, clear the active region
963 if(load_mode == LOAD_PASTE)
965 double start = edl->local_session->get_selectionstart();
966 double end = edl->local_session->get_selectionend();
967 if(!EQUIV(start, end))
970 edl->session->labels_follow_edits,
971 edl->session->plugins_follow_edits);
974 paste_edls(&new_edls,
978 edl->session->labels_follow_edits,
979 edl->session->plugins_follow_edits);
990 for(int i = 0; i < new_assets.total; i++)
992 mainindexes->add_next_asset(new_assets.values[i]);
993 edl->assets->update(new_assets.values[i]);
997 // Start examining next batch of index files
998 mainindexes->start_build();
1001 TRACE("MWindow::load_filenames 100");
1002 update_project(load_mode);
1003 TRACE("MWindow::load_filenames 110");
1005 //printf("MWindow::load_filenames 9\n");
1008 new_edls.remove_all_objects();
1009 new_assets.remove_all_objects();
1010 //printf("MWindow::load_filenames 10 %d\n", edl->session->audio_module_fragment);
1012 if(load_mode == LOAD_REPLACE ||
1013 load_mode == LOAD_REPLACE_CONCATENATE)
1014 session->changes_made = 0;
1023 void MWindow::test_plugins(EDL *new_edl, char *path)
1025 // Do a check weather plugins exist
1026 for(Track *track = new_edl->tracks->first; track; track = track->next)
1028 for(int k = 0; k < track->plugin_set.total; k++)
1030 PluginSet *plugin_set = track->plugin_set.values[k];
1031 for(Plugin *plugin = (Plugin*)plugin_set->first;
1033 plugin = (Plugin*)plugin->next)
1035 if(plugin->plugin_type == PLUGIN_STANDALONE)
1037 // ok we need to find it in plugindb
1038 int plugin_found = 0;
1039 for(int j = 0; j < plugindb->total; j++)
1041 PluginServer *server = plugindb->values[j];
1042 if(!strcasecmp(server->title, plugin->title) &&
1043 ((track->data_type == TRACK_AUDIO && server->audio) ||
1044 (track->data_type == TRACK_VIDEO && server->video)) &&
1045 (!server->transition))
1050 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);
1055 for(Edit *edit = (Edit*)track->edits->first;
1057 edit = (Edit*)edit->next)
1059 if (edit->transition)
1061 // ok we need to find transition in plugindb
1062 int transition_found = 0;
1063 for(int j = 0; j < plugindb->total; j++)
1065 PluginServer *server = plugindb->values[j];
1066 if(!strcasecmp(server->title, edit->transition->title) &&
1067 ((track->data_type == TRACK_AUDIO && server->audio) ||
1068 (track->data_type == TRACK_VIDEO && server->video)) &&
1069 (server->transition))
1070 transition_found = 1;
1072 if (!transition_found)
1074 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);
1086 void MWindow::create_objects(int want_gui,
1090 char string[BCTEXTLEN];
1097 // For some reason, init_signals must come after show_splash or the signals won't
1103 TRACE("MWindow::create_objects 1");
1104 init_defaults(defaults, config_path);
1105 TRACE("MWindow::create_objects 2");
1107 TRACE("MWindow::create_objects 3");
1108 init_plugins(preferences, plugindb, splash_window);
1109 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1110 TRACE("MWindow::create_objects 4");
1112 // Default project created here
1113 TRACE("MWindow::create_objects 5");
1116 TRACE("MWindow::create_objects 6");
1118 TRACE("MWindow::create_objects 7");
1120 TRACE("MWindow::create_objects 8");
1122 TRACE("MWindow::create_objects 9");
1124 TRACE("MWindow::create_objects 10");
1126 TRACE("MWindow::create_objects 11");
1128 TRACE("MWindow::create_objects 12");
1130 TRACE("MWindow::create_objects 13");
1133 TRACE("MWindow::create_objects 14");
1136 mainprogress = new MainProgress(this, gui);
1137 undo = new MainUndo(this);
1139 plugin_guis = new ArrayList<PluginServer*>;
1141 TRACE("MWindow::create_objects 15");
1142 if(session->show_vwindow) vwindow->gui->show_window();
1143 if(session->show_cwindow) cwindow->gui->show_window();
1144 if(session->show_awindow) awindow->gui->show_window();
1145 if(session->show_lwindow) lwindow->gui->show_window();
1146 TRACE("MWindow::create_objects 16");
1148 // vwindow->start();
1149 // awindow->start();
1150 // cwindow->start();
1151 // lwindow->start();
1152 //printf("MWindow::create_objects 1");
1154 gui->mainmenu->load_defaults(defaults);
1155 TRACE("MWindow::create_objects 17");
1156 gui->mainmenu->update_toggles();
1157 TRACE("MWindow::create_objects 18");
1158 gui->patchbay->update();
1159 TRACE("MWindow::create_objects 19");
1160 gui->canvas->draw();
1161 TRACE("MWindow::create_objects 20");
1162 gui->cursor->draw();
1163 TRACE("MWindow::create_objects 21");
1164 gui->raise_window();
1165 TRACE("MWindow::create_objects 22");
1167 TRACE("MWindow::create_objects 23");
1174 void MWindow::show_splash()
1176 #include "data/heroine_logo12_png.h"
1177 VFrame *frame = new VFrame(heroine_logo12_png);
1178 BC_DisplayInfo display_info;
1179 splash_window = new SplashGUI(frame,
1180 display_info.get_root_w() / 2 - frame->get_w() / 2,
1181 display_info.get_root_h() / 2 - frame->get_h() / 2);
1182 splash_window->create_objects();
1185 void MWindow::hide_splash()
1188 delete splash_window;
1193 void MWindow::start()
1202 void MWindow::show_vwindow()
1204 session->show_vwindow = 1;
1205 vwindow->gui->lock_window("MWindow::show_vwindow");
1206 vwindow->gui->show_window();
1207 vwindow->gui->raise_window();
1208 vwindow->gui->flush();
1209 vwindow->gui->unlock_window();
1210 gui->mainmenu->show_vwindow->set_checked(1);
1213 void MWindow::show_awindow()
1215 session->show_awindow = 1;
1216 awindow->gui->lock_window("MWindow::show_awindow");
1217 awindow->gui->show_window();
1218 awindow->gui->raise_window();
1219 awindow->gui->flush();
1220 awindow->gui->unlock_window();
1221 gui->mainmenu->show_awindow->set_checked(1);
1224 void MWindow::show_cwindow()
1226 session->show_cwindow = 1;
1227 cwindow->gui->lock_window("MWindow::show_cwindow");
1228 cwindow->gui->show_window();
1229 cwindow->gui->raise_window();
1230 cwindow->gui->flush();
1231 cwindow->gui->unlock_window();
1232 gui->mainmenu->show_cwindow->set_checked(1);
1235 void MWindow::show_lwindow()
1237 session->show_lwindow = 1;
1238 lwindow->gui->lock_window("MWindow::show_lwindow");
1239 lwindow->gui->show_window();
1240 lwindow->gui->raise_window();
1241 lwindow->gui->flush();
1242 lwindow->gui->unlock_window();
1243 gui->mainmenu->show_lwindow->set_checked(1);
1246 void MWindow::tile_windows()
1248 session->default_window_positions();
1249 gui->default_positions();
1252 void MWindow::toggle_loop_playback()
1254 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1255 set_loop_boundaries();
1258 gui->canvas->draw_overlays();
1259 gui->canvas->flash();
1260 sync_parameters(CHANGE_PARAMS);
1263 void MWindow::set_titles(int value)
1265 edl->session->show_titles = value;
1266 trackmovement(edl->local_session->track_start);
1269 void MWindow::set_auto_keyframes(int value)
1271 gui->lock_window("MWindow::set_auto_keyframes");
1272 edl->session->auto_keyframes = value;
1273 gui->mbuttons->edit_panel->keyframe->update(value);
1275 gui->unlock_window();
1276 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1277 cwindow->gui->edit_panel->keyframe->update(value);
1278 cwindow->gui->flush();
1279 cwindow->gui->unlock_window();
1282 int MWindow::set_editing_mode(int new_editing_mode)
1284 gui->lock_window("MWindow::set_editing_mode");
1285 edl->session->editing_mode = new_editing_mode;
1286 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1287 gui->mbuttons->edit_panel->update();
1288 gui->canvas->update_cursor();
1289 gui->unlock_window();
1290 cwindow->gui->lock_window("MWindow::set_editing_mode");
1291 cwindow->gui->edit_panel->update();
1292 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1293 cwindow->gui->unlock_window();
1298 void MWindow::sync_parameters(int change_type)
1301 // Sync engines which are playing back
1302 if(cwindow->playback_engine->is_playing_back)
1304 if(change_type == CHANGE_PARAMS)
1306 // TODO: block keyframes until synchronization is done
1307 cwindow->playback_engine->sync_parameters(edl);
1312 int command = cwindow->playback_engine->command->command;
1313 cwindow->playback_engine->que->send_command(STOP,
1317 // Waiting for tracking to finish would make the restart position more
1318 // accurate but it can't lock the window to stop tracking for some reason.
1319 // Not waiting for tracking gives a faster response but restart position is
1320 // only as accurate as the last tracking update.
1321 cwindow->playback_engine->interrupt_playback(0);
1322 cwindow->playback_engine->que->send_command(command,
1331 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1338 void MWindow::update_caches()
1340 audio_cache->set_edl(edl);
1341 video_cache->set_edl(edl);
1344 void MWindow::show_plugin(Plugin *plugin)
1347 //printf("MWindow::show_plugin 1\n");
1348 plugin_gui_lock->lock("MWindow::show_plugin");
1349 for(int i = 0; i < plugin_guis->total; i++)
1351 // Pointer comparison
1352 if(plugin_guis->values[i]->plugin == plugin)
1354 plugin_guis->values[i]->raise_window();
1360 //printf("MWindow::show_plugin 1\n");
1365 printf("MWindow::show_plugin track not defined.\n");
1367 PluginServer *server = scan_plugindb(plugin->title,
1368 plugin->track->data_type);
1370 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
1371 if(server && server->uses_gui)
1373 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
1374 // Needs mwindow to do GUI
1375 gui->set_mwindow(this);
1376 gui->open_plugin(0, preferences, edl, plugin, -1);
1381 plugin_gui_lock->unlock();
1382 //printf("MWindow::show_plugin 2\n");
1385 void MWindow::hide_plugin(Plugin *plugin, int lock)
1387 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
1389 for(int i = 0; i < plugin_guis->total; i++)
1391 if(plugin_guis->values[i]->plugin == plugin)
1393 PluginServer *ptr = plugin_guis->values[i];
1394 plugin_guis->remove(ptr);
1395 if(lock) plugin_gui_lock->unlock();
1396 // Last command executed in client side close
1401 if(lock) plugin_gui_lock->unlock();
1404 void MWindow::hide_plugins()
1406 plugin_gui_lock->lock("MWindow::hide_plugins");
1407 plugin_guis->remove_all_objects();
1408 plugin_gui_lock->unlock();
1411 void MWindow::update_plugin_guis()
1413 plugin_gui_lock->lock("MWindow::update_plugin_guis");
1415 for(int i = 0; i < plugin_guis->total; i++)
1417 plugin_guis->values[i]->update_gui();
1419 plugin_gui_lock->unlock();
1422 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
1424 plugin_gui_lock->lock("MWindow::render_plugin_gui");
1425 for(int i = 0; i < plugin_guis->total; i++)
1427 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1429 plugin_guis->values[i]->render_gui(data);
1433 plugin_gui_lock->unlock();
1436 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
1438 plugin_gui_lock->lock("MWindow::render_plugin_gui");
1439 for(int i = 0; i < plugin_guis->total; i++)
1441 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1443 plugin_guis->values[i]->render_gui(data, size);
1447 plugin_gui_lock->unlock();
1451 void MWindow::update_plugin_states()
1453 plugin_gui_lock->lock("MWindow::update_plugin_states");
1454 for(int i = 0; i < plugin_guis->total; i++)
1458 Plugin *src_plugin = plugin_guis->values[i]->plugin;
1459 PluginServer *src_plugingui = plugin_guis->values[i];
1461 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
1462 for(Track *track = edl->tracks->first;
1464 track = track->next)
1467 j < track->plugin_set.total && !result;
1470 PluginSet *plugin_set = track->plugin_set.values[j];
1471 for(Plugin *plugin = (Plugin*)plugin_set->first;
1473 plugin = (Plugin*)plugin->next)
1475 if(plugin == src_plugin &&
1476 !strcmp(plugin->title, src_plugingui->title)) result = 1;
1482 // Doesn't exist anymore
1485 hide_plugin(src_plugin, 0);
1489 plugin_gui_lock->unlock();
1493 void MWindow::update_plugin_titles()
1495 for(int i = 0; i < plugin_guis->total; i++)
1497 plugin_guis->values[i]->update_title();
1501 int MWindow::asset_to_edl(EDL *new_edl,
1503 RecordLabels *labels)
1505 //printf("MWindow::asset_to_edl 1\n");
1506 // new_edl->load_defaults(defaults);
1508 // Keep frame rate, sample rate, and output size unchanged.
1509 // These parameters would revert the project if VWindow displayed an asset
1510 // of different size than the project.
1511 if(new_asset->video_data)
1513 new_edl->session->video_tracks = new_asset->layers;
1514 // new_edl->session->frame_rate = new_asset->frame_rate;
1515 // new_edl->session->output_w = new_asset->width;
1516 // new_edl->session->output_h = new_asset->height;
1519 new_edl->session->video_tracks = 0;
1526 if(new_asset->audio_data)
1528 new_edl->session->audio_tracks = new_asset->channels;
1529 // new_edl->session->sample_rate = new_asset->sample_rate;
1532 new_edl->session->audio_tracks = 0;
1533 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1535 new_edl->create_default_tracks();
1536 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1538 // Disable drawing if the file format isn't fast enough.
1539 // MPEG is now faster than most other codecs.
1540 // if(new_asset->format == FILE_MPEG)
1542 // for(Track *current = new_edl->tracks->first;
1546 // if(current->data_type == TRACK_VIDEO) current->draw = 0;
1552 //printf("MWindow::asset_to_edl 3\n");
1553 new_edl->insert_asset(new_asset, 0, 0, labels);
1554 //printf("MWindow::asset_to_edl 3\n");
1560 char string[BCTEXTLEN];
1562 fs.extract_name(string, new_asset->path);
1563 //printf("MWindow::asset_to_edl 3\n");
1565 strcpy(new_edl->local_session->clip_title, string);
1566 //printf("MWindow::asset_to_edl 4 %s\n", string);
1572 // Reset everything after a load.
1573 void MWindow::update_project(int load_mode)
1576 //TRACE("MWindow::update_project 1");
1577 edl->tracks->update_y_pixels(theme);
1580 //TRACE("MWindow::update_project 2");
1583 TRACE("MWindow::update_project 3");
1584 gui->update(1, 1, 1, 1, 1, 1, 1);
1586 TRACE("MWindow::update_project 4");
1587 cwindow->update(0, 0, 1, 1, 1);
1589 TRACE("MWindow::update_project 5");
1591 if(load_mode == LOAD_REPLACE ||
1592 load_mode == LOAD_REPLACE_CONCATENATE)
1594 vwindow->change_source();
1601 TRACE("MWindow::update_project 6");
1603 cwindow->gui->slider->set_position();
1604 TRACE("MWindow::update_project 6.1");
1605 cwindow->gui->timebar->update(1, 1);
1606 TRACE("MWindow::update_project 6.2");
1607 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1612 TRACE("MWindow::update_project 7");
1613 awindow->gui->lock_window("MWindow::update_project");
1614 awindow->gui->update_assets();
1615 awindow->gui->flush();
1616 awindow->gui->unlock_window();
1618 TRACE("MWindow::update_project 100");
1622 void MWindow::rebuild_indices()
1624 char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
1626 for(int i = 0; i < session->drag_assets->total; i++)
1628 //printf("MWindow::rebuild_indices 1 %s\n", session->drag_assets->values[i]->path);
1630 IndexFile::get_index_filename(source_filename,
1631 preferences->index_directory,
1633 session->drag_assets->values[i]->path);
1634 remove(index_filename);
1635 // Schedule index build
1636 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
1637 mainindexes->add_next_asset(session->drag_assets->values[i]);
1639 mainindexes->start_build();
1643 void MWindow::save_backup()
1646 edl->set_project_path(session->filename);
1647 edl->save_xml(plugindb,
1652 file.terminate_string();
1653 char path[BCTEXTLEN];
1655 strcpy(path, BACKUP_PATH);
1656 fs.complete_path(path);
1658 if(file.write_to_file(path))
1661 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
1662 gui->show_message(string2);
1667 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
1670 if(!width || !height) return 1;
1671 float fraction = (float)width / height;
1673 for(denominator = 1;
1674 denominator < 100 &&
1675 fabs(fraction * denominator - (int)(fraction * denominator)) > .001;
1679 w = denominator * width / height;
1686 void MWindow::remove_assets_from_project(int push_undo)
1688 if(push_undo) undo->update_undo_before(_("remove assets"), LOAD_ALL);
1690 // Remove from caches
1691 for(int i = 0; i < session->drag_assets->total; i++)
1693 audio_cache->delete_entry(session->drag_assets->values[i]);
1694 video_cache->delete_entry(session->drag_assets->values[i]);
1697 printf("MWindow::remove_assets_from_project 1\n");
1698 video_cache->dump();
1699 audio_cache->dump();
1700 printf("MWindow::remove_assets_from_project 100\n");
1702 // Remove from VWindow.
1703 for(int i = 0; i < session->drag_clips->total; i++)
1705 if(session->drag_clips->values[i] == vwindow->get_edl())
1707 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
1708 vwindow->remove_source();
1709 vwindow->gui->unlock_window();
1713 for(int i = 0; i < session->drag_assets->total; i++)
1715 if(session->drag_assets->values[i] == vwindow->get_asset())
1717 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
1718 vwindow->remove_source();
1719 vwindow->gui->unlock_window();
1723 edl->remove_from_project(session->drag_assets);
1724 edl->remove_from_project(session->drag_clips);
1726 if(push_undo) undo->update_undo_after();
1729 gui->lock_window("MWindow::remove_assets_from_project 3");
1737 gui->unlock_window();
1739 awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
1740 awindow->gui->update_assets();
1741 awindow->gui->flush();
1742 awindow->gui->unlock_window();
1744 // Removes from playback here
1745 sync_parameters(CHANGE_ALL);
1748 void MWindow::remove_assets_from_disk()
1751 for(int i = 0; i < session->drag_assets->total; i++)
1753 remove(session->drag_assets->values[i]->path);
1756 remove_assets_from_project(1);
1759 void MWindow::dump_plugins()
1761 for(int i = 0; i < plugindb->total; i++)
1763 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
1764 plugindb->values[i]->audio,
1765 plugindb->values[i]->video,
1766 plugindb->values[i]->realtime,
1767 plugindb->values[i]->transition,
1768 plugindb->values[i]->theme,
1769 plugindb->values[i]->title);
1797 int MWindow::save_defaults()
1799 gui->save_defaults(defaults);
1800 edl->save_defaults(defaults);
1801 session->save_defaults(defaults);
1802 preferences->save_defaults(defaults);
1808 int MWindow::run_script(FileXML *script)
1810 int result = 0, result2 = 0;
1811 while(!result && !result2)
1813 result = script->read_tag();
1816 if(script->tag.title_is("new_project"))
1818 // Run new in immediate mode.
1819 // gui->mainmenu->new_project->run_script(script);
1822 if(script->tag.title_is("record"))
1824 // Run record as a thread. It is a terminal command.
1826 // Will read the complete scipt file without letting record read it if not
1832 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
1839 // ================================= synchronization
1842 int MWindow::interrupt_indexes()
1844 mainindexes->interrupt_build();
1850 void MWindow::next_time_format()
1852 switch(edl->session->time_format)
1854 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
1855 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
1856 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
1857 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
1858 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
1859 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
1860 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
1863 time_format_common();
1866 void MWindow::prev_time_format()
1868 switch(edl->session->time_format)
1870 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
1871 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
1872 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
1873 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
1874 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
1875 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
1876 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
1879 time_format_common();
1882 void MWindow::time_format_common()
1884 gui->lock_window("MWindow::next_time_format");
1885 gui->redraw_time_dependancies();
1886 char string[BCTEXTLEN], string2[BCTEXTLEN];
1887 sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
1888 gui->show_message(string, BLACK);
1890 gui->unlock_window();
1894 int MWindow::set_filename(char *filename)
1896 strcpy(session->filename, filename);
1899 if(filename[0] == 0)
1901 gui->set_title(PROGRAM_NAME);
1906 char string[BCTEXTLEN], string2[BCTEXTLEN];
1907 dir.extract_name(string, filename);
1908 sprintf(string2, PROGRAM_NAME ": %s", string);
1909 gui->set_title(string2);
1922 int MWindow::set_loop_boundaries()
1924 double start = edl->local_session->get_selectionstart();
1925 double end = edl->local_session->get_selectionend();
1933 if(edl->tracks->total_length())
1936 end = edl->tracks->total_length();
1943 if(edl->local_session->loop_playback && start != end)
1945 edl->local_session->loop_start = start;
1946 edl->local_session->loop_end = end;
1957 int MWindow::reset_meters()
1959 cwindow->gui->lock_window("MWindow::reset_meters 1");
1960 cwindow->gui->meters->reset_meters();
1961 cwindow->gui->unlock_window();
1963 vwindow->gui->lock_window("MWindow::reset_meters 2");
1964 vwindow->gui->meters->reset_meters();
1965 vwindow->gui->unlock_window();
1967 lwindow->gui->lock_window("MWindow::reset_meters 3");
1968 lwindow->gui->panel->reset_meters();
1969 lwindow->gui->unlock_window();
1971 gui->lock_window("MWindow::reset_meters 4");
1972 gui->patchbay->reset_meters();
1973 gui->unlock_window();