2 #include "awindowgui.h"
4 #include "bcdisplayinfo.h"
9 #include "colormodels.h"
10 #include "cplayback.h"
12 #include "cwindowgui.h"
15 #include "editpanel.h"
17 #include "edlsession.h"
19 #include "fileformat.h"
21 #include "filesystem.h"
23 #include "indexfile.h"
24 #include "levelwindowgui.h"
25 #include "levelwindow.h"
26 #include "loadfile.inc"
27 #include "localsession.h"
28 #include "mainindexes.h"
30 #include "mainprogress.h"
31 #include "mainsession.h"
35 #include "mwindowgui.h"
39 #include "playbackengine.h"
41 #include "pluginserver.h"
42 #include "pluginset.h"
43 #include "preferences.h"
45 #include "recordlabel.h"
47 #include "samplescroll.h"
48 #include "sighandler.h"
49 #include "splashgui.h"
50 #include "statusbar.h"
52 #include "threadloader.h"
54 #include "trackcanvas.h"
57 #include "trackscroll.h"
59 #include "transportque.h"
61 #include "videodevice.inc"
62 #include "videowindow.h"
63 #include "vplayback.h"
64 #include "vwindowgui.h"
71 #define _(String) gettext(String)
72 #define gettext_noop(String) String
73 #define N_(String) gettext_noop (String)
82 // Hack for libdv to remove glib dependancy
85 // g_log (const char *log_domain,
87 // const char *format,
93 // g_logv (const char *log_domain,
95 // const char *format,
102 // Hack for XFree86 4.1.0
104 int atexit(void (*function)(void))
119 plugin_gui_lock = new Mutex;
120 brender_lock = new Mutex;
127 //printf("MWindow::~MWindow 1\n");
128 brender_lock->lock();
129 if(brender) delete brender;
131 brender_lock->unlock();
133 //printf("MWindow::~MWindow 2\n");
135 //printf("MWindow::~MWindow 1\n");
137 //printf("MWindow::~MWindow 1\n");
138 delete audio_cache; // delete the cache after the assets
139 //printf("MWindow::~MWindow 1\n");
140 delete video_cache; // delete the cache after the assets
141 //printf("MWindow::~MWindow 1\n");
143 //printf("MWindow::~MWindow 1\n");
145 //printf("MWindow::~MWindow 1\n");
147 //printf("MWindow::~MWindow 1\n");
149 //printf("MWindow::~MWindow 1\n");
151 //printf("MWindow::~MWindow 1\n");
153 //printf("MWindow::~MWindow 1\n");
155 //printf("MWindow::~MWindow 1\n");
157 //printf("MWindow::~MWindow 1\n");
160 //printf("MWindow::~MWindow 1\n");
161 plugin_guis->remove_all_objects();
162 //printf("MWindow::~MWindow 2\n");
164 //printf("MWindow::~MWindow 3\n");
165 delete plugin_gui_lock;
166 //printf("MWindow::~MWindow 5\n");
169 void MWindow::init_defaults(Defaults* &defaults)
171 // set the .bcast directory
172 char directory[BCTEXTLEN];
175 sprintf(directory, "%s", BCASTDIR);
176 fs.complete_path(directory);
177 if(fs.is_dir(directory))
179 fs.create_dir(directory);
183 strcat(directory, "Cinelerra_rc");
185 defaults = new Defaults(directory);
189 void MWindow::init_plugin_path(Preferences *preferences,
190 ArrayList<PluginServer*>* &plugindb,
192 SplashGUI *splash_window,
196 PluginServer *newplugin;
200 for(int i = 0; i < fs->dir_list.total; i++)
202 char path[BCTEXTLEN];
203 strcpy(path, fs->dir_list.values[i]->path);
205 // File is a directory
206 if(!fs->is_dir(path))
212 // Try to query the plugin
213 fs->complete_path(path);
214 PluginServer *new_plugin = new PluginServer(path);
215 int result = new_plugin->open_plugin(1, 0, 0);
219 plugindb->append(new_plugin);
220 new_plugin->close_plugin();
222 splash_window->operation->update(new_plugin->title);
225 if(result == PLUGINSERVER_IS_LAD)
228 // Open LAD subplugins
232 new_plugin = new PluginServer(path);
233 result = new_plugin->open_plugin(1,
240 plugindb->append(new_plugin);
241 new_plugin->close_plugin();
243 splash_window->operation->update(new_plugin->title);
249 // Plugin failed to open
253 if(splash_window) splash_window->progress->update((*counter)++);
258 void MWindow::init_plugins(Preferences *preferences,
259 ArrayList<PluginServer*>* &plugindb,
260 SplashGUI *splash_window)
262 plugindb = new ArrayList<PluginServer*>;
264 FileSystem cinelerra_fs;
265 ArrayList<FileSystem*> lad_fs;
269 cinelerra_fs.set_filter("[*.plugin][*.so]");
270 result = cinelerra_fs.update(preferences->global_plugin_dir);
275 _("MWindow::init_plugins: couldn't open %s directory\n"),
276 preferences->global_plugin_dir);
279 // Parse LAD environment variable
280 char *env = getenv("LADSPA_PATH");
283 char string[BCTEXTLEN];
287 char *ptr = strchr(ptr1, ':');
295 end = env + strlen(env);
300 int len = end - ptr1;
301 memcpy(string, ptr1, len);
305 FileSystem *fs = new FileSystem;
307 fs->set_filter("*.so");
308 result = fs->update(string);
313 _("MWindow::init_plugins: couldn't open %s directory\n"),
325 int total = cinelerra_fs.total_files();
327 for(int i = 0; i < lad_fs.total; i++)
328 total += lad_fs.values[i]->total_files();
329 if(splash_window) splash_window->progress->update_length(total);
332 init_plugin_path(preferences,
339 for(int i = 0; i < lad_fs.total; i++)
340 init_plugin_path(preferences,
346 lad_fs.remove_all_objects();
349 void MWindow::delete_plugins()
351 for(int i = 0; i < plugindb->total; i++)
353 delete plugindb->values[i];
358 void MWindow::create_plugindb(int do_audio,
363 ArrayList<PluginServer*> &plugindb)
366 for(int i = 0; i < this->plugindb->total; i++)
368 PluginServer *current = this->plugindb->values[i];
370 if(current->audio == do_audio &&
371 current->video == do_video &&
372 (current->realtime == is_realtime || is_realtime < 0) &&
373 current->transition == is_transition &&
374 current->theme == is_theme)
375 plugindb.append(current);
378 // Alphabetize list by title
384 for(int i = 0; i < plugindb.total - 1; i++)
386 PluginServer *value1 = plugindb.values[i];
387 PluginServer *value2 = plugindb.values[i + 1];
388 if(strcmp(value1->title, value2->title) > 0)
391 plugindb.values[i] = value2;
392 plugindb.values[i + 1] = value1;
398 PluginServer* MWindow::scan_plugindb(char *title)
400 for(int i = 0; i < plugindb->total; i++)
402 if(!strcasecmp(plugindb->values[i]->title, title))
403 return plugindb->values[i];
408 void MWindow::init_preferences()
410 preferences = new Preferences;
411 preferences->load_defaults(defaults);
412 session = new MainSession(this);
413 session->load_defaults(defaults);
416 void MWindow::clean_indexes()
425 // Delete extra indexes
426 fs.set_filter("*.idx");
427 fs.complete_path(preferences->index_directory);
428 fs.update(preferences->index_directory);
429 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
431 // Eliminate directories
436 for(int i = 0; i < fs.dir_list.total && !result; i++)
438 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
439 if(!fs.is_dir(string))
441 delete fs.dir_list.values[i];
442 fs.dir_list.remove_number(i);
447 total_excess = fs.dir_list.total - preferences->index_count;
449 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
450 while(total_excess > 0)
453 for(int i = 0; i < fs.dir_list.total; i++)
455 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
457 if(i == 0 || fs.get_date(string) <= oldest)
459 oldest = fs.get_date(string);
464 fs.join_names(string, preferences->index_directory, fs.dir_list.values[oldest_item]->name);
466 perror("delete_indexes");
467 delete fs.dir_list.values[oldest_item];
468 fs.dir_list.remove_number(oldest_item);
473 void MWindow::init_awindow()
475 awindow = new AWindow(this);
476 awindow->create_objects();
479 void MWindow::init_theme()
483 for(int i = 0; i < plugindb->total; i++)
485 if(plugindb->values[i]->theme &&
486 !strcasecmp(preferences->theme, plugindb->values[i]->title))
488 PluginServer plugin = *plugindb->values[i];
489 plugin.open_plugin(0, 0, 0);
490 theme = plugin.new_theme();
491 theme->mwindow = this;
492 strcpy(theme->path, plugin.path);
493 plugin.close_plugin();
499 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
503 //printf("MWindow::init_theme 3 %p\n", theme);
506 //printf("MWindow::init_theme 4\n");
509 void MWindow::init_edl()
512 edl->create_objects();
513 edl->load_defaults(defaults);
514 edl->create_default_tracks();
515 edl->tracks->update_y_pixels(theme);
518 void MWindow::init_compositor()
520 cwindow = new CWindow(this);
521 cwindow->create_objects();
524 void MWindow::init_levelwindow()
526 lwindow = new LevelWindow(this);
527 lwindow->create_objects();
530 void MWindow::init_viewer()
532 vwindow = new VWindow(this);
533 vwindow->load_defaults();
534 vwindow->create_objects();
537 void MWindow::init_cache()
539 audio_cache = new CICache(edl, preferences, plugindb);
540 video_cache = new CICache(edl, preferences, plugindb);
543 void MWindow::init_tuner(ArrayList<Channel*> &channeldb, char *path)
546 char directory[1024];
551 sprintf(directory, BCASTDIR);
552 fs.complete_path(directory);
553 fs.join_names(directory, directory, path);
554 done = file.read_from_file(directory, 1);
559 channel = new Channel;
560 if(!(done = channel->load(&file)))
561 channeldb.append(channel);
569 void MWindow::save_tuner(ArrayList<Channel*> &channeldb, char *path)
572 char directory[1024];
575 sprintf(directory, BCASTDIR);
576 fs.complete_path(directory);
577 strcat(directory, path);
581 for(int i = 0; i < channeldb.total; i++)
584 channeldb.values[i]->save(&file);
586 file.terminate_string();
587 file.write_to_file(directory);
591 void MWindow::init_menus()
593 char string[BCTEXTLEN];
594 cmodel_to_text(string, BC_RGB888);
595 colormodels.append(new ColormodelItem(string, BC_RGB888));
596 cmodel_to_text(string, BC_RGBA8888);
597 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
598 cmodel_to_text(string, BC_RGB161616);
599 colormodels.append(new ColormodelItem(string, BC_RGB161616));
600 cmodel_to_text(string, BC_RGBA16161616);
601 colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
602 cmodel_to_text(string, BC_YUV888);
603 colormodels.append(new ColormodelItem(string, BC_YUV888));
604 cmodel_to_text(string, BC_YUVA8888);
605 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
606 cmodel_to_text(string, BC_YUV161616);
607 colormodels.append(new ColormodelItem(string, BC_YUV161616));
608 cmodel_to_text(string, BC_YUVA16161616);
609 colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
612 void MWindow::init_indexes()
614 mainindexes = new MainIndexes(this);
615 mainindexes->start_loop();
618 void MWindow::init_gui()
620 gui = new MWindowGUI(this);
621 gui->create_objects();
622 gui->load_defaults(defaults);
625 void MWindow::init_signals()
627 sighandler = new SigHandler;
630 void MWindow::init_render()
632 render = new Render(this);
633 renderlist = new Render(this);
636 void MWindow::init_brender()
638 if(preferences->use_brender && !brender)
640 brender_lock->lock();
641 brender = new BRender(this);
642 brender->initialize();
643 session->brender_end = 0;
644 brender_lock->unlock();
647 if(!preferences->use_brender && brender)
649 brender_lock->lock();
652 session->brender_end = 0;
653 brender_lock->unlock();
655 if(brender) brender->restart(edl);
658 void MWindow::restart_brender()
660 //printf("MWindow::restart_brender 1\n");
661 if(brender) brender->restart(edl);
664 void MWindow::stop_brender()
666 if(brender) brender->stop();
669 int MWindow::brender_available(int position)
672 brender_lock->lock();
675 if(brender->map_valid)
677 brender->map_lock->lock();
678 if(position < brender->map_size &&
681 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
682 if(brender->map[position] == BRender::RENDERED)
685 brender->map_lock->unlock();
688 brender_lock->unlock();
692 void MWindow::set_brender_start()
694 edl->session->brender_start = edl->local_session->get_selectionstart();
696 gui->canvas->draw_overlays();
697 gui->canvas->flash();
702 int MWindow::load_filenames(ArrayList<char*> *filenames, int load_mode)
704 TRON("MWindow::load_filenames\n");
705 ArrayList<EDL*> new_edls;
706 ArrayList<Asset*> new_assets;
707 //printf("load_filenames 1\n");
709 // Need to stop playback since tracking depends on the EDL not getting
711 cwindow->playback_engine->que->send_command(STOP,
715 vwindow->playback_engine->que->send_command(STOP,
719 cwindow->playback_engine->interrupt_playback(0);
720 vwindow->playback_engine->interrupt_playback(0);
724 // Define new_edls and new_assets to load
726 for(int i = 0; i < filenames->total; i++)
729 File *new_file = new File;
730 Asset *new_asset = new Asset(filenames->values[i]);
731 EDL *new_edl = new EDL;
732 char string[BCTEXTLEN];
734 //printf("load_filenames 1\n");
735 new_edl->create_objects();
736 //printf("load_filenames 1\n");
737 new_edl->copy_session(edl);
738 //printf("load_filenames 1\n");
740 sprintf(string, "Loading %s", new_asset->path);
741 //printf("load_filenames 1\n");
742 gui->show_message(string, BLACK);
743 //printf("load_filenames 1\n");
744 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
745 //printf("load_filenames 2\n");
749 // Convert media file to EDL
751 //printf("load_filenames 1.1\n");
752 if(load_mode != LOAD_RESOURCESONLY)
754 asset_to_edl(new_edl, new_asset);
755 //printf("load_filenames 1.2\n");
756 new_edls.append(new_edl);
760 //printf("load_filenames 1.3\n");
762 new_assets.append(new_asset);
764 if(load_mode == LOAD_REPLACE ||
765 load_mode == LOAD_REPLACE_CONCATENATE)
772 sprintf(string, _("Failed to open %s"), new_asset->path);
773 gui->show_message(string, RED);
778 case FILE_UNRECOGNIZED_CODEC:
781 IndexFile indexfile(this);
782 result = indexfile.open_index(this, new_asset);
785 indexfile.close_index();
788 // Test existing EDLs
791 for(int j = 0; j < new_edls.total + 1; j++)
794 if(j == new_edls.total)
796 if(old_asset = edl->assets->get_asset(new_asset->path))
798 *new_asset = *old_asset;
804 if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
806 *new_asset = *old_asset;
816 char string[BCTEXTLEN];
818 fs.extract_name(string, new_asset->path);
820 strcat(string, _("'s format couldn't be determined."));
821 new_asset->audio_data = 1;
822 new_asset->format = FILE_PCM;
823 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
824 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
825 new_asset->bits = defaults->get("AUDIO_BITS", 16);
826 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
827 new_asset->signed_ = defaults->get("SIGNED_", 1);
828 new_asset->header = defaults->get("HEADER", 0);
830 FileFormat fwindow(this);
831 fwindow.create_objects(new_asset, string);
832 result = fwindow.run_window();
834 defaults->update("AUDIO_CHANNELS", new_asset->channels);
835 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
836 defaults->update("AUDIO_BITS", new_asset->bits);
837 defaults->update("BYTE_ORDER", new_asset->byte_order);
838 defaults->update("SIGNED_", new_asset->signed_);
839 defaults->update("HEADER", new_asset->header);
846 // Recalculate length
849 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
851 if(load_mode != LOAD_RESOURCESONLY)
853 asset_to_edl(new_edl, new_asset);
854 //printf("MWindow::load_filenames 1 %d %d\n", new_asset->video_length, new_asset->audio_length);
856 new_edls.append(new_edl);
861 new_assets.append(new_asset);
873 //printf("load_filenames 2\n");
875 xml_file.read_from_file(filenames->values[i]);
876 //printf("load_filenames 3\n");
877 // gui->lock_window();
878 // gui->update_title(session->filename);
879 // gui->unlock_window();
880 // Load EDL for pasting
881 //printf("load_filenames 3\n");
882 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
883 //printf("load_filenames 3\n");
884 if(load_mode == LOAD_REPLACE ||
885 load_mode == LOAD_REPLACE_CONCATENATE)
887 strcpy(session->filename, filenames->values[i]);
888 strcpy(new_edl->local_session->clip_title, filenames->values[i]);
889 set_filename(new_edl->local_session->clip_title);
892 //printf("load_filenames 2\n");
893 new_edls.append(new_edl);
894 //printf("load_filenames 4\n");
899 //printf("load_filenames 4\n");
906 //printf("load_filenames 5\n");
909 //printf("load_filenames 6\n");
912 //printf("MWindow::load_filenames 5 %d\n", new_edls.total);
917 if(!result) gui->statusbar->default_message();
920 //printf("MWindow::load_filenames 7 %d\n", new_edls.total);
928 // Don't back up here.
931 // For pasting, clear the active region
932 if(load_mode == LOAD_PASTE)
934 double start = edl->local_session->get_selectionstart();
935 double end = edl->local_session->get_selectionend();
936 if(!EQUIV(start, end))
939 edl->session->labels_follow_edits,
940 edl->session->plugins_follow_edits);
943 paste_edls(&new_edls,
947 edl->session->labels_follow_edits,
948 edl->session->plugins_follow_edits);
957 //printf("MWindow::load_filenames 8 %d\n", new_edls.total);
962 for(int i = 0; i < new_assets.total; i++)
964 mainindexes->add_next_asset(new_assets.values[i]);
965 edl->assets->update(new_assets.values[i]);
969 // Start examining next batch of index files
970 mainindexes->start_build();
973 update_project(load_mode);
975 //printf("MWindow::load_filenames 9\n");
978 new_edls.remove_all_objects();
979 new_assets.remove_all_objects();
980 //printf("MWindow::load_filenames 10 %d\n", edl->session->audio_module_fragment);
982 if(load_mode == LOAD_REPLACE ||
983 load_mode == LOAD_REPLACE_CONCATENATE)
984 session->changes_made = 0;
986 TROFF("MWindow::load_filenames\n");
990 void MWindow::create_objects(int want_gui, int want_new)
1001 //printf("MWindow::create_objects 1\n");
1002 init_defaults(defaults);
1003 //printf("MWindow::create_objects 1\n");
1005 //printf("MWindow::create_objects 1\n");
1006 init_plugins(preferences, plugindb, splash_window);
1007 splash_window->operation->update(_("Initializing GUI"));
1008 //printf("MWindow::create_objects 1\n");
1010 // Default project created here
1011 //printf("MWindow::create_objects 1\n");
1014 //printf("MWindow::create_objects 1\n");
1016 //printf("MWindow::create_objects 1\n");
1018 //printf("MWindow::create_objects 1\n");
1020 //printf("MWindow::create_objects 1\n");
1022 //printf("MWindow::create_objects 1\n");
1023 init_tuner(channeldb_v4l, "channels_v4l");
1024 //printf("MWindow::create_objects 1\n");
1025 init_tuner(channeldb_buz, "channels_buz");
1026 //printf("MWindow::create_objects 1\n");
1028 //printf("MWindow::create_objects 1\n");
1030 //printf("MWindow::create_objects 1\n");
1032 //printf("MWindow::create_objects 1\n");
1035 mainprogress = new MainProgress(this, gui);
1036 undo = new MainUndo(this);
1038 plugin_guis = new ArrayList<PluginServer*>;
1040 //printf("MWindow::create_objects 1\n");
1041 if(session->show_vwindow) vwindow->gui->show_window();
1042 if(session->show_cwindow) cwindow->gui->show_window();
1043 if(session->show_awindow) awindow->gui->show_window();
1044 if(session->show_lwindow) lwindow->gui->show_window();
1045 //printf("MWindow::create_objects 1\n");
1047 // vwindow->start();
1048 // awindow->start();
1049 // cwindow->start();
1050 // lwindow->start();
1051 //printf("MWindow::create_objects 1\n");
1053 gui->mainmenu->load_defaults(defaults);
1054 //printf("MWindow::create_objects 1\n");
1055 gui->mainmenu->update_toggles();
1056 //printf("MWindow::create_objects 1\n");
1057 gui->patchbay->update();
1058 //printf("MWindow::create_objects 1\n");
1059 gui->canvas->draw();
1060 //printf("MWindow::create_objects 1\n");
1061 gui->cursor->draw();
1062 //printf("MWindow::create_objects 1\n");
1063 gui->raise_window();
1064 //printf("MWindow::create_objects 1\n");
1068 //printf("MWindow::create_objects 2\n");
1072 void MWindow::show_splash()
1074 #include "data/heroine_logo11_png.h"
1075 VFrame *frame = new VFrame(heroine_logo11_png);
1076 BC_DisplayInfo display_info;
1077 splash_window = new SplashGUI(frame,
1078 display_info.get_root_w() / 2 - frame->get_w() / 2,
1079 display_info.get_root_h() / 2 - frame->get_h() / 2);
1080 splash_window->create_objects();
1083 void MWindow::hide_splash()
1085 delete splash_window;
1089 void MWindow::start()
1098 void MWindow::show_vwindow()
1100 session->show_vwindow = 1;
1101 vwindow->gui->lock_window();
1102 vwindow->gui->show_window();
1103 vwindow->gui->raise_window();
1104 vwindow->gui->flush();
1105 vwindow->gui->unlock_window();
1106 gui->mainmenu->show_vwindow->set_checked(1);
1109 void MWindow::show_awindow()
1111 session->show_awindow = 1;
1112 awindow->gui->lock_window();
1113 awindow->gui->show_window();
1114 awindow->gui->raise_window();
1115 awindow->gui->flush();
1116 awindow->gui->unlock_window();
1117 gui->mainmenu->show_awindow->set_checked(1);
1120 void MWindow::show_cwindow()
1122 session->show_cwindow = 1;
1123 cwindow->gui->lock_window();
1124 cwindow->gui->show_window();
1125 cwindow->gui->raise_window();
1126 cwindow->gui->flush();
1127 cwindow->gui->unlock_window();
1128 gui->mainmenu->show_cwindow->set_checked(1);
1131 void MWindow::show_lwindow()
1133 session->show_lwindow = 1;
1134 lwindow->gui->lock_window();
1135 lwindow->gui->show_window();
1136 lwindow->gui->raise_window();
1137 lwindow->gui->flush();
1138 lwindow->gui->unlock_window();
1139 gui->mainmenu->show_lwindow->set_checked(1);
1142 void MWindow::tile_windows()
1144 session->default_window_positions();
1145 gui->default_positions();
1148 void MWindow::toggle_loop_playback()
1150 edl->local_session->loop_playback = !edl->local_session->loop_playback;
1151 set_loop_boundaries();
1154 gui->canvas->draw_overlays();
1155 gui->canvas->flash();
1156 sync_parameters(CHANGE_PARAMS);
1159 void MWindow::set_titles(int value)
1161 edl->session->show_titles = value;
1162 trackmovement(edl->local_session->track_start);
1165 void MWindow::set_auto_keyframes(int value)
1168 edl->session->auto_keyframes = value;
1169 gui->mbuttons->edit_panel->keyframe->update(value);
1171 gui->unlock_window();
1172 cwindow->gui->lock_window();
1173 cwindow->gui->edit_panel->keyframe->update(value);
1174 cwindow->gui->flush();
1175 cwindow->gui->unlock_window();
1178 int MWindow::set_editing_mode(int new_editing_mode)
1181 edl->session->editing_mode = new_editing_mode;
1182 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1183 gui->mbuttons->edit_panel->update();
1184 gui->canvas->update_cursor();
1185 gui->unlock_window();
1186 cwindow->gui->lock_window();
1187 cwindow->gui->edit_panel->update();
1188 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1189 cwindow->gui->unlock_window();
1194 void MWindow::sync_parameters(int change_type)
1197 // Sync engines which are playing back
1198 if(cwindow->playback_engine->is_playing_back)
1200 if(change_type == CHANGE_PARAMS)
1202 // TODO: block keyframes until synchronization is done
1203 cwindow->playback_engine->sync_parameters(edl);
1208 //printf("MWindow::sync_parameters 1\n");
1209 int command = cwindow->playback_engine->command->command;
1210 cwindow->playback_engine->que->send_command(STOP,
1214 //printf("MWindow::sync_parameters 2\n");
1215 // Waiting for tracking to finish would make the restart position more
1216 // accurate but it can't lock the window to stop tracking for some reason.
1217 // Not waiting for tracking gives a faster response but restart position is
1218 // only as accurate as the last tracking update.
1219 cwindow->playback_engine->interrupt_playback(0);
1220 //printf("MWindow::sync_parameters 3\n");
1221 cwindow->playback_engine->que->send_command(command,
1226 //printf("MWindow::sync_parameters 4\n");
1231 //printf("MWindow::sync_parameters 1\n");
1232 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1236 //printf("MWindow::sync_parameters 2\n");
1240 void MWindow::update_caches()
1242 audio_cache->set_edl(edl);
1243 video_cache->set_edl(edl);
1246 void MWindow::show_plugin(Plugin *plugin)
1249 //printf("MWindow::show_plugin 1\n");
1250 plugin_gui_lock->lock();
1251 for(int i = 0; i < plugin_guis->total; i++)
1253 // Pointer comparison
1254 if(plugin_guis->values[i]->plugin == plugin)
1256 plugin_guis->values[i]->raise_window();
1262 //printf("MWindow::show_plugin 1\n");
1265 PluginServer *server = scan_plugindb(plugin->title);
1267 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
1268 if(server && server->uses_gui)
1270 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
1271 // Needs mwindow to do GUI
1272 gui->set_mwindow(this);
1273 gui->open_plugin(0, edl, plugin);
1278 plugin_gui_lock->unlock();
1279 //printf("MWindow::show_plugin 2\n");
1282 void MWindow::hide_plugin(Plugin *plugin, int lock)
1284 if(lock) plugin_gui_lock->lock();
1286 for(int i = 0; i < plugin_guis->total; i++)
1288 //printf("MWindow::hide_plugin 1 %p %p\n", plugin, plugin_guis->values[i]->plugin);
1289 if(plugin_guis->values[i]->plugin == plugin)
1291 //printf("MWindow::hide_plugin 2\n");
1292 PluginServer *ptr = plugin_guis->values[i];
1293 plugin_guis->remove(ptr);
1294 if(lock) plugin_gui_lock->unlock();
1295 // Last command executed in client side close
1300 if(lock) plugin_gui_lock->unlock();
1303 void MWindow::hide_plugins()
1305 plugin_gui_lock->lock();
1306 plugin_guis->remove_all_objects();
1307 plugin_gui_lock->unlock();
1310 void MWindow::update_plugin_guis()
1313 plugin_gui_lock->lock();
1316 for(int i = 0; i < plugin_guis->total; i++)
1318 plugin_guis->values[i]->update_gui();
1320 plugin_gui_lock->unlock();
1323 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
1325 //printf("MWindow::render_plugin_gui 1\n");
1326 plugin_gui_lock->lock();
1327 for(int i = 0; i < plugin_guis->total; i++)
1329 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1331 //printf("MWindow::render_plugin_gui 2\n");
1332 plugin_guis->values[i]->render_gui(data);
1336 plugin_gui_lock->unlock();
1339 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
1341 //printf("MWindow::render_plugin_gui 1\n");
1342 plugin_gui_lock->lock();
1343 for(int i = 0; i < plugin_guis->total; i++)
1345 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1347 //printf("MWindow::render_plugin_gui 2\n");
1348 plugin_guis->values[i]->render_gui(data, size);
1352 plugin_gui_lock->unlock();
1356 void MWindow::update_plugin_states()
1359 plugin_gui_lock->lock();
1360 for(int i = 0; i < plugin_guis->total; i++)
1363 Plugin *src_plugin = plugin_guis->values[i]->plugin;
1364 PluginServer *src_plugingui = plugin_guis->values[i];
1366 // Search for plugin in EDL. Only the master EDL shows plugin GUIs.
1367 for(Track *track = edl->tracks->first;
1369 track = track->next)
1372 j < track->plugin_set.total && !result;
1375 PluginSet *plugin_set = track->plugin_set.values[j];
1376 for(Plugin *plugin = (Plugin*)plugin_set->first;
1378 plugin = (Plugin*)plugin->next)
1380 if(plugin == src_plugin &&
1381 !strcmp(plugin->title, src_plugingui->title)) result = 1;
1387 // Doesn't exist anymore
1390 hide_plugin(src_plugin, 0);
1394 plugin_gui_lock->unlock();
1398 void MWindow::update_plugin_titles()
1400 for(int i = 0; i < plugin_guis->total; i++)
1402 plugin_guis->values[i]->update_title();
1406 int MWindow::asset_to_edl(EDL *new_edl,
1408 RecordLabels *labels)
1410 //printf("MWindow::asset_to_edl 1\n");
1411 // new_edl->load_defaults(defaults);
1413 // Keep frame rate, sample rate, and output size unchanged.
1414 // These parameters would revert the project if VWindow displayed an asset
1415 // of different size than the project.
1416 if(new_asset->video_data)
1418 new_edl->session->video_tracks = new_asset->layers;
1419 // new_edl->session->frame_rate = new_asset->frame_rate;
1420 // new_edl->session->output_w = new_asset->width;
1421 // new_edl->session->output_h = new_asset->height;
1424 new_edl->session->video_tracks = 0;
1431 if(new_asset->audio_data)
1433 new_edl->session->audio_tracks = new_asset->channels;
1434 // new_edl->session->sample_rate = new_asset->sample_rate;
1437 new_edl->session->audio_tracks = 0;
1438 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1440 new_edl->create_default_tracks();
1441 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1443 // Disable drawing if the file format isn't fast enough.
1444 if(new_asset->format == FILE_MPEG)
1446 for(Track *current = new_edl->tracks->first;
1450 if(current->data_type == TRACK_VIDEO) current->draw = 0;
1456 //printf("MWindow::asset_to_edl 3\n");
1457 new_edl->insert_asset(new_asset, 0, 0, labels);
1458 //printf("MWindow::asset_to_edl 3\n");
1464 char string[BCTEXTLEN];
1466 fs.extract_name(string, new_asset->path);
1467 //printf("MWindow::asset_to_edl 3\n");
1469 strcpy(new_edl->local_session->clip_title, string);
1470 //printf("MWindow::asset_to_edl 4 %s\n", string);
1476 // Reset everything after a load.
1477 void MWindow::update_project(int load_mode)
1480 //printf("MWindow::update_project 1\n");
1481 edl->tracks->update_y_pixels(theme);
1484 //printf("MWindow::update_project 1\n");
1487 //printf("MWindow::update_project 1\n");
1488 gui->update(1, 1, 1, 1, 1, 1, 1);
1490 //printf("MWindow::update_project 1\n");
1491 cwindow->update(0, 0, 1, 1, 1);
1493 //printf("MWindow::update_project 1\n");
1495 if(load_mode == LOAD_REPLACE ||
1496 load_mode == LOAD_REPLACE_CONCATENATE)
1498 vwindow->change_source();
1506 cwindow->gui->slider->set_position();
1507 cwindow->gui->timebar->update(1, 1);
1508 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
1513 //printf("MWindow::update_project 1\n");
1514 awindow->gui->lock_window();
1515 //printf("MWindow::update_project 1\n");
1516 awindow->gui->update_assets();
1517 //printf("MWindow::update_project 1\n");
1518 awindow->gui->flush();
1519 //printf("MWindow::update_project 1\n");
1520 awindow->gui->unlock_window();
1521 //printf("MWindow::update_project 12\n");
1523 //printf("MWindow::update_project 13\n");
1527 void MWindow::rebuild_indices()
1529 char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
1531 for(int i = 0; i < session->drag_assets->total; i++)
1533 //printf("MWindow::rebuild_indices 1 %s\n", session->drag_assets->values[i]->path);
1535 IndexFile::get_index_filename(source_filename,
1536 preferences->index_directory,
1538 session->drag_assets->values[i]->path);
1539 remove(index_filename);
1540 // Schedule index build
1541 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
1542 mainindexes->add_next_asset(session->drag_assets->values[i]);
1544 mainindexes->start_build();
1548 void MWindow::save_backup()
1551 edl->save_xml(plugindb,
1556 file.terminate_string();
1557 char path[BCTEXTLEN];
1559 strcpy(path, BACKUP_PATH);
1560 fs.complete_path(path);
1562 if(file.write_to_file(path))
1565 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
1566 gui->show_message(string2);
1571 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
1574 float fraction = (float)width / height;
1576 for(denominator = 1;
1577 denominator < 100 &&
1578 fabs(fraction * denominator - (int)(fraction * denominator)) > .001;
1582 w = denominator * width / height;
1586 void MWindow::render_single()
1588 if(!render->running())
1592 void MWindow::render_list()
1594 if(!renderlist->running())
1595 renderlist->start();
1599 void MWindow::remove_assets_from_project(int push_undo)
1601 if(push_undo) undo->update_undo_before(_("remove assets"), LOAD_ALL);
1603 // Remove from caches
1604 for(int i = 0; i < session->drag_assets->total; i++)
1606 audio_cache->delete_entry(session->drag_assets->values[i]);
1607 video_cache->delete_entry(session->drag_assets->values[i]);
1610 printf("MWindow::remove_assets_from_project 1\n");
1611 video_cache->dump();
1612 audio_cache->dump();
1613 printf("MWindow::remove_assets_from_project 100\n");
1615 // Remove from VWindow.
1616 for(int i = 0; i < session->drag_clips->total; i++)
1618 if(session->drag_clips->values[i] == vwindow->get_edl())
1620 vwindow->gui->lock_window();
1621 vwindow->remove_source();
1622 vwindow->gui->unlock_window();
1626 for(int i = 0; i < session->drag_assets->total; i++)
1628 if(session->drag_assets->values[i] == vwindow->get_asset())
1630 vwindow->gui->lock_window();
1631 vwindow->remove_source();
1632 vwindow->gui->unlock_window();
1636 edl->remove_from_project(session->drag_assets);
1637 edl->remove_from_project(session->drag_clips);
1639 if(push_undo) undo->update_undo_after();
1650 gui->unlock_window();
1652 awindow->gui->lock_window();
1653 awindow->gui->update_assets();
1654 awindow->gui->flush();
1655 awindow->gui->unlock_window();
1657 // Removes from playback here
1658 sync_parameters(CHANGE_ALL);
1661 void MWindow::remove_assets_from_disk()
1664 for(int i = 0; i < session->drag_assets->total; i++)
1666 remove(session->drag_assets->values[i]->path);
1669 remove_assets_from_project(1);
1672 void MWindow::dump_plugins()
1674 for(int i = 0; i < plugindb->total; i++)
1676 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
1677 plugindb->values[i]->audio,
1678 plugindb->values[i]->video,
1679 plugindb->values[i]->realtime,
1680 plugindb->values[i]->transition,
1681 plugindb->values[i]->theme,
1682 plugindb->values[i]->title);
1710 int MWindow::save_defaults()
1712 //printf("MWindow::save_defaults 1\n");
1713 gui->save_defaults(defaults);
1714 edl->save_defaults(defaults);
1715 //printf("MWindow::save_defaults 1\n");
1716 session->save_defaults(defaults);
1717 preferences->save_defaults(defaults);
1718 //printf("MWindow::save_defaults 1\n");
1720 save_tuner(channeldb_v4l, "channels_v4l");
1721 save_tuner(channeldb_buz, "channels_buz");
1722 //printf("MWindow::save_defaults 1\n");
1724 //printf("MWindow::save_defaults 2\n");
1728 int MWindow::run_script(FileXML *script)
1730 int result = 0, result2 = 0;
1731 while(!result && !result2)
1733 result = script->read_tag();
1736 if(script->tag.title_is("new_project"))
1738 // Run new in immediate mode.
1739 // gui->mainmenu->new_project->run_script(script);
1742 if(script->tag.title_is("record"))
1744 // Run record as a thread. It is a terminal command.
1746 // Will read the complete scipt file without letting record read it if not
1752 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
1759 // ================================= synchronization
1762 int MWindow::interrupt_indexes()
1764 mainindexes->interrupt_build();
1770 void MWindow::next_time_format()
1772 switch(edl->session->time_format)
1774 case 0: edl->session->time_format = 1; break;
1775 case 1: edl->session->time_format = 2; break;
1776 case 2: edl->session->time_format = 3; break;
1777 case 3: edl->session->time_format = 4; break;
1778 case 4: edl->session->time_format = 5; break;
1779 case 5: edl->session->time_format = 0; break;
1783 gui->redraw_time_dependancies();
1787 char string[BCTEXTLEN], string2[BCTEXTLEN];
1788 sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
1789 gui->show_message(string, BLACK);
1791 gui->unlock_window();
1794 int MWindow::set_filename(char *filename)
1796 strcpy(session->filename, filename);
1799 if(filename[0] == 0)
1801 gui->set_title(PROGRAM_NAME);
1806 char string[1024], string2[1024];
1807 dir.extract_name(string, filename);
1808 sprintf(string2, PROGRAM_NAME ": %s", string);
1809 gui->set_title(string2);
1822 int MWindow::set_loop_boundaries()
1824 double start = edl->local_session->get_selectionstart();
1825 double end = edl->local_session->get_selectionend();
1833 if(edl->tracks->total_length())
1836 end = edl->tracks->total_length();
1843 if(edl->local_session->loop_playback && start != end)
1845 edl->local_session->loop_start = start;
1846 edl->local_session->loop_end = end;
1857 int MWindow::reset_meters()
1859 cwindow->gui->lock_window();
1860 cwindow->gui->meters->reset_meters();
1861 cwindow->gui->unlock_window();
1863 vwindow->gui->lock_window();
1864 vwindow->gui->meters->reset_meters();
1865 vwindow->gui->unlock_window();
1867 lwindow->gui->lock_window();
1868 lwindow->gui->panel->reset_meters();
1869 lwindow->gui->unlock_window();
1872 gui->patchbay->reset_meters();
1873 gui->unlock_window();