r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mwindow.C
blob5cc35c6621d46d61c9db4e489c83ab17d1874527
1 #include "asset.h"
2 #include "assets.h"
3 #include "awindowgui.h"
4 #include "awindow.h"
5 #include "batchrender.h"
6 #include "bcdisplayinfo.h"
7 #include "brender.h"
8 #include "cache.h"
9 #include "channel.h"
10 #include "channeldb.h"
11 #include "clip.h"
12 #include "colormodels.h"
13 #include "cplayback.h"
14 #include "ctimebar.h"
15 #include "cwindowgui.h"
16 #include "cwindow.h"
17 #include "defaults.h"
18 #include "editpanel.h"
19 #include "edl.h"
20 #include "edlsession.h"
21 #include "errorbox.h"
22 #include "fileformat.h"
23 #include "file.h"
24 #include "filesystem.h"
25 #include "filexml.h"
26 #include "indexfile.h"
27 #include "language.h"
28 #include "levelwindowgui.h"
29 #include "levelwindow.h"
30 #include "loadfile.inc"
31 #include "localsession.h"
32 #include "maincursor.h"
33 #include "mainindexes.h"
34 #include "mainmenu.h"
35 #include "mainprogress.h"
36 #include "mainsession.h"
37 #include "mainundo.h"
38 #include "mbuttons.h"
39 #include "mutex.h"
40 #include "mwindowgui.h"
41 #include "mwindow.h"
42 #include "new.h"
43 #include "patchbay.h"
44 #include "playbackengine.h"
45 #include "plugin.h"
46 #include "pluginserver.h"
47 #include "pluginset.h"
48 #include "preferences.h"
49 #include "record.h"
50 #include "recordlabel.h"
51 #include "render.h"
52 #include "samplescroll.h"
53 #include "sighandler.h"
54 #include "splashgui.h"
55 #include "statusbar.h"
56 #include "theme.h"
57 #include "threadloader.h"
58 #include "timebar.h"
59 #include "trackcanvas.h"
60 #include "track.h"
61 #include "tracking.h"
62 #include "trackscroll.h"
63 #include "tracks.h"
64 #include "transition.h"
65 #include "transportque.h"
66 #include "vframe.h"
67 #include "videodevice.inc"
68 #include "videowindow.h"
69 #include "vplayback.h"
70 #include "vwindowgui.h"
71 #include "vwindow.h"
72 #include "zoombar.h"
74 #include <string.h>
78 extern "C"
84 // Hack for libdv to remove glib dependancy
86 // void
87 // g_log (const char    *log_domain,
88 //        int  log_level,
89 //        const char    *format,
90 //        ...)
91 // {
92 // }
93 // 
94 // void
95 // g_logv (const char    *log_domain,
96 //        int  log_level,
97 //        const char    *format,
98 //        ...)
99 // {
100 // }
101 // 
104 // Hack for XFree86 4.1.0
106 int atexit(void (*function)(void))
108         return 0;
119 MWindow::MWindow()
121         plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
122         brender_lock = new Mutex("MWindow::brender_lock");
123         brender = 0;
124         session = 0;
125         channeldb_buz = new ChannelDB;
126         channeldb_v4l2jpeg = new ChannelDB;
129 MWindow::~MWindow()
131         brender_lock->lock("MWindow::~MWindow");
132         if(brender) delete brender;
133         brender = 0;
134         brender_lock->unlock();
135         delete brender_lock;
137         delete mainindexes;
139 TRACE("MWindow::~MWindow 1\n");
140         clean_indexes();
141 TRACE("MWindow::~MWindow 2\n");
143         save_defaults();
144 TRACE("MWindow::~MWindow 3\n");
145 // Give up and go to a movie
146         exit(0);
148 TRACE("MWindow::~MWindow 4\n");
149         delete mainprogress;
150         delete audio_cache;             // delete the cache after the assets
151         delete video_cache;             // delete the cache after the assets
152         if(gui) delete gui;
153         delete undo;
154         delete preferences;
155         delete defaults;
156         delete render;
157 //      delete renderlist;
158         delete awindow;
159         delete vwindow;
160         delete cwindow;
161         delete lwindow;
162         plugin_guis->remove_all_objects();
163         delete plugin_guis;
164         delete plugin_gui_lock;
167 void MWindow::init_defaults(Defaults* &defaults, char *config_path)
169         char path[BCTEXTLEN];
170 // Use user supplied path
171         if(config_path[0])
172         {
173                 strcpy(path, config_path);
174         }
175         else
176         {
177 // set the .bcast path
178                 FileSystem fs;
180                 sprintf(path, "%s", BCASTDIR);
181                 fs.complete_path(path);
182                 if(fs.is_dir(path)) 
183                 {
184                         fs.create_dir(path); 
185                 }
187 // load the defaults
188                 strcat(path, "Cinelerra_rc");
189         }
191         defaults = new Defaults(path);
192         defaults->load();
195 void MWindow::init_plugin_path(Preferences *preferences, 
196         ArrayList<PluginServer*>* &plugindb,
197         FileSystem *fs,
198         SplashGUI *splash_window,
199         int *counter)
201         int result = 0;
202         PluginServer *newplugin;
204         if(!result)
205         {
206                 for(int i = 0; i < fs->dir_list.total; i++)
207                 {
208                         char path[BCTEXTLEN];
209                         strcpy(path, fs->dir_list.values[i]->path);
211 // File is a directory
212                         if(!fs->is_dir(path))
213                         {
214                                 continue;
215                         }
216                         else
217                         {
218 // Try to query the plugin
219                                 fs->complete_path(path);
220 //printf("MWindow::init_plugin_path %s\n", path);
221                                 PluginServer *new_plugin = new PluginServer(path);
222                                 int result = new_plugin->open_plugin(1, preferences, 0, 0, -1);
224                                 if(!result)
225                                 {
226                                         plugindb->append(new_plugin);
227                                         new_plugin->close_plugin();
228                                         if(splash_window)
229                                                 splash_window->operation->update(_(new_plugin->title));
230                                 }
231                                 else
232                                 if(result == PLUGINSERVER_IS_LAD)
233                                 {
234                                         delete new_plugin;
235 // Open LAD subplugins
236                                         int id = 0;
237                                         do
238                                         {
239                                                 new_plugin = new PluginServer(path);
240                                                 result = new_plugin->open_plugin(1,
241                                                         preferences,
242                                                         0,
243                                                         0,
244                                                         id);
245                                                 id++;
246                                                 if(!result)
247                                                 {
248                                                         plugindb->append(new_plugin);
249                                                         new_plugin->close_plugin();
250                                                         if(splash_window)
251                                                                 splash_window->operation->update(_(new_plugin->title));
252                                                 }
253                                         }while(!result);
254                                 }
255                                 else
256                                 {
257 // Plugin failed to open
258                                         delete new_plugin;
259                                 }
260                         }
261                         if(splash_window) splash_window->progress->update((*counter)++);
262                 }
263         }
266 void MWindow::init_plugins(Preferences *preferences, 
267         ArrayList<PluginServer*>* &plugindb,
268         SplashGUI *splash_window)
270         plugindb = new ArrayList<PluginServer*>;
274         FileSystem cinelerra_fs;
275         ArrayList<FileSystem*> lad_fs;
276         int result = 0;
278 // Get directories
279         cinelerra_fs.set_filter("[*.plugin][*.so]");
280         result = cinelerra_fs.update(preferences->global_plugin_dir);
282         if(result)
283         {
284                 fprintf(stderr, 
285                         _("MWindow::init_plugins: couldn't open %s directory\n"),
286                         preferences->global_plugin_dir);
287         }
289 // Parse LAD environment variable
290         char *env = getenv("LADSPA_PATH");
291         if(env)
292         {
293                 char string[BCTEXTLEN];
294                 char *ptr1 = env;
295                 while(ptr1)
296                 {
297                         char *ptr = strchr(ptr1, ':');
298                         char *end;
299                         if(ptr)
300                         {
301                                 end = ptr;
302                         }
303                         else
304                         {
305                                 end = env + strlen(env);
306                         }
308                         if(end > ptr1)
309                         {
310                                 int len = end - ptr1;
311                                 memcpy(string, ptr1, len);
312                                 string[len] = 0;
315                                 FileSystem *fs = new FileSystem;
316                                 lad_fs.append(fs);
317                                 fs->set_filter("*.so");
318                                 result = fs->update(string);
320                                 if(result)
321                                 {
322                                         fprintf(stderr, 
323                                                 _("MWindow::init_plugins: couldn't open %s directory\n"),
324                                                 string);
325                                 }
326                         }
328                         if(ptr)
329                                 ptr1 = ptr + 1;
330                         else
331                                 ptr1 = ptr;
332                 };
333         }
335         int total = cinelerra_fs.total_files();
336         int counter = 0;
337         for(int i = 0; i < lad_fs.total; i++)
338                 total += lad_fs.values[i]->total_files();
339         if(splash_window) splash_window->progress->update_length(total);
341 // Cinelerra
342 #ifndef DO_STATIC
343         init_plugin_path(preferences,
344                 plugindb,
345                 &cinelerra_fs,
346                 splash_window,
347                 &counter);
348 #else
349 // Call automatically generated routine to get plugins
350 #endif
352 // LAD
353         for(int i = 0; i < lad_fs.total; i++)
354                 init_plugin_path(preferences,
355                         plugindb,
356                         lad_fs.values[i],
357                         splash_window,
358                         &counter);
360         lad_fs.remove_all_objects();
363 void MWindow::delete_plugins()
365         for(int i = 0; i < plugindb->total; i++)
366         {
367                 delete plugindb->values[i];
368         }
369         delete plugindb;
372 void MWindow::create_plugindb(int do_audio, 
373                 int do_video, 
374                 int is_realtime, 
375                 int is_transition,
376                 int is_theme,
377                 ArrayList<PluginServer*> &plugindb)
379 // Get plugins
380         for(int i = 0; i < this->plugindb->total; i++)
381         {
382                 PluginServer *current = this->plugindb->values[i];
384                 if(current->audio == do_audio &&
385                         current->video == do_video &&
386                         (current->realtime == is_realtime || is_realtime < 0) &&
387                         current->transition == is_transition &&
388                         current->theme == is_theme)
389                         plugindb.append(current);
390         }
392 // Alphabetize list by title
393         int done = 0;
394         while(!done)
395         {
396                 done = 1;
397                 
398                 for(int i = 0; i < plugindb.total - 1; i++)
399                 {
400                         PluginServer *value1 = plugindb.values[i];
401                         PluginServer *value2 = plugindb.values[i + 1];
402                         if(strcmp(_(value1->title), _(value2->title)) > 0)
403                         {
404                                 done = 0;
405                                 plugindb.values[i] = value2;
406                                 plugindb.values[i + 1] = value1;
407                         }
408                 }
409         }
412 PluginServer* MWindow::scan_plugindb(char *title,
413                 int data_type)
415         if(data_type < 0)
416         {
417                 printf("MWindow::scan_plugindb data_type < 0\n");
418                 return 0;
419         }
421         for(int i = 0; i < plugindb->total; i++)
422         {
423                 PluginServer *server = plugindb->values[i];
424                 if(!strcasecmp(server->title, title) &&
425                 ((data_type == TRACK_AUDIO && server->audio) ||
426                 (data_type == TRACK_VIDEO && server->video))) 
427                         return plugindb->values[i];
428         }
429         return 0;
432 void MWindow::init_preferences()
434         preferences = new Preferences;
435         preferences->load_defaults(defaults);
436         session = new MainSession(this);
437         session->load_defaults(defaults);
440 void MWindow::clean_indexes()
442         FileSystem fs;
443         int total_excess;
444         long oldest;
445         int oldest_item;
446         int result;
447         char string[BCTEXTLEN];
449 // Delete extra indexes
450         fs.set_filter("*.idx");
451         fs.complete_path(preferences->index_directory);
452         fs.update(preferences->index_directory);
453 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
455 // Eliminate directories
456         result = 1;
457         while(result)
458         {
459                 result = 0;
460                 for(int i = 0; i < fs.dir_list.total && !result; i++)
461                 {
462                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
463                         if(!fs.is_dir(string))
464                         {
465                                 delete fs.dir_list.values[i];
466                                 fs.dir_list.remove_number(i);
467                                 result = 1;
468                         }
469                 }
470         }
471         total_excess = fs.dir_list.total - preferences->index_count;
473 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
474         while(total_excess > 0)
475         {
476 // Get oldest
477                 for(int i = 0; i < fs.dir_list.total; i++)
478                 {
479                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
481                         if(i == 0 || fs.get_date(string) <= oldest)
482                         {
483                                 oldest = fs.get_date(string);
484                                 oldest_item = i;
485                         }
486                 }
488                 fs.join_names(string, preferences->index_directory, fs.dir_list.values[oldest_item]->name);
489                 if(remove(string))
490                         perror("delete_indexes");
491                 delete fs.dir_list.values[oldest_item];
492                 fs.dir_list.remove_number(oldest_item);
493                 total_excess--;
494         }
497 void MWindow::init_awindow()
499         awindow = new AWindow(this);
500         awindow->create_objects();
503 void MWindow::init_theme()
505         theme = 0;
507         for(int i = 0; i < plugindb->total; i++)
508         {
509                 if(plugindb->values[i]->theme &&
510                         !strcasecmp(preferences->theme, plugindb->values[i]->title))
511                 {
512                         PluginServer plugin = *plugindb->values[i];
513                         plugin.open_plugin(0, preferences, 0, 0, -1);
514                         theme = plugin.new_theme();
515                         theme->mwindow = this;
516                         strcpy(theme->path, plugin.path);
517                         plugin.close_plugin();
518                 }
519         }
521         if(!theme)
522         {
523                 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
524                 exit(1);
525         }
527 // Load user images
528         theme->initialize();
529 // Load images which may have been forgotten
530         theme->Theme::initialize();
532         theme->check_used();
535 void MWindow::init_edl()
537         edl = new EDL;
538         edl->create_objects();
539     edl->load_defaults(defaults);
540         edl->create_default_tracks();
541         edl->tracks->update_y_pixels(theme);
544 void MWindow::init_compositor()
546         cwindow = new CWindow(this);
547     cwindow->create_objects();
550 void MWindow::init_levelwindow()
552         lwindow = new LevelWindow(this);
553         lwindow->create_objects();
556 void MWindow::init_viewer()
558         vwindow = new VWindow(this);
559         vwindow->load_defaults();
560         vwindow->create_objects();
563 void MWindow::init_cache()
565         audio_cache = new CICache(edl, preferences, plugindb);
566         video_cache = new CICache(edl, preferences, plugindb);
569 void MWindow::init_channeldb()
571         channeldb_buz->load("channeldb_buz");
572         channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
575 void MWindow::init_menus()
577         char string[BCTEXTLEN];
578         cmodel_to_text(string, BC_RGB888);
579         colormodels.append(new ColormodelItem(string, BC_RGB888));
580         cmodel_to_text(string, BC_RGBA8888);
581         colormodels.append(new ColormodelItem(string, BC_RGBA8888));
582 //      cmodel_to_text(string, BC_RGB161616);
583 //      colormodels.append(new ColormodelItem(string, BC_RGB161616));
584 //      cmodel_to_text(string, BC_RGBA16161616);
585 //      colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
586         cmodel_to_text(string, BC_RGB_FLOAT);
587         colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
588         cmodel_to_text(string, BC_RGBA_FLOAT);
589         colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
590         cmodel_to_text(string, BC_YUV888);
591         colormodels.append(new ColormodelItem(string, BC_YUV888));
592         cmodel_to_text(string, BC_YUVA8888);
593         colormodels.append(new ColormodelItem(string, BC_YUVA8888));
594         cmodel_to_text(string, BC_YUV161616);
595         colormodels.append(new ColormodelItem(string, BC_YUV161616));
596         cmodel_to_text(string, BC_YUVA16161616);
597         colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
600 void MWindow::init_indexes()
602         mainindexes = new MainIndexes(this);
603         mainindexes->start_loop();
606 void MWindow::init_gui()
608         gui = new MWindowGUI(this);
609         gui->create_objects();
610         gui->load_defaults(defaults);
613 void MWindow::init_signals()
615         sighandler = new SigHandler;
616         sighandler->initialize();
617 ENABLE_BUFFER
620 void MWindow::init_render()
622         render = new Render(this);
623 //      renderlist = new Render(this);
624         batch_render = new BatchRenderThread(this);
627 void MWindow::init_brender()
629         if(preferences->use_brender && !brender)
630         {
631                 brender_lock->lock("MWindow::init_brender 1");
632                 brender = new BRender(this);
633                 brender->initialize();
634                 session->brender_end = 0;
635                 brender_lock->unlock();
636         }
637         else
638         if(!preferences->use_brender && brender)
639         {
640                 brender_lock->lock("MWindow::init_brender 2");
641                 delete brender;
642                 brender = 0;
643                 session->brender_end = 0;
644                 brender_lock->unlock();
645         }
646         if(brender) brender->restart(edl);
649 void MWindow::restart_brender()
651 //printf("MWindow::restart_brender 1\n");
652         if(brender) brender->restart(edl);
655 void MWindow::stop_brender()
657         if(brender) brender->stop();
660 int MWindow::brender_available(int position)
662         int result = 0;
663         brender_lock->lock("MWindow::brender_available 1");
664         if(brender)
665         {
666                 if(brender->map_valid)
667                 {
668                         brender->map_lock->lock("MWindow::brender_available 2");
669                         if(position < brender->map_size &&
670                                 position >= 0)
671                         {
672 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
673                                 if(brender->map[position] == BRender::RENDERED)
674                                         result = 1;
675                         }
676                         brender->map_lock->unlock();
677                 }
678         }
679         brender_lock->unlock();
680         return result;
683 void MWindow::set_brender_start()
685         edl->session->brender_start = edl->local_session->get_selectionstart();
686         restart_brender();
687         gui->canvas->draw_overlays();
688         gui->canvas->flash();
693 int MWindow::load_filenames(ArrayList<char*> *filenames, 
694         int load_mode,
695         int update_filename,
696         char *reel_name,
697         int reel_number,
698         int overwrite_reel)
700 TRACE("MWindow::load_filenames 1");
701         ArrayList<EDL*> new_edls;
702         ArrayList<Asset*> new_assets;
704 // Need to stop playback since tracking depends on the EDL not getting
705 // deleted.
706         cwindow->playback_engine->que->send_command(STOP,
707                 CHANGE_NONE, 
708                 0,
709                 0);
710         vwindow->playback_engine->que->send_command(STOP,
711                 CHANGE_NONE, 
712                 0,
713                 0);
714         cwindow->playback_engine->interrupt_playback(0);
715         vwindow->playback_engine->interrupt_playback(0);
719 // Define new_edls and new_assets to load
720         int result = 0;
721         for(int i = 0; i < filenames->total; i++)
722         {
723 // Get type of file
724                 File *new_file = new File;
725                 Asset *new_asset = new Asset(filenames->values[i]);
726                 EDL *new_edl = new EDL;
727                 char string[BCTEXTLEN];
729 // Set reel name and number for the asset
730 // If the user wants to overwrite the last used reel number for the clip,
731 // we have to rebuild the index for the file
733                 if(overwrite_reel)
734                 {
735                         char source_filename[BCTEXTLEN];
736                         char index_filename[BCTEXTLEN];
737                         
738                         strcpy(new_asset->reel_name, reel_name);
739                         new_asset->reel_number = reel_number;
741                         IndexFile::get_index_filename(source_filename,
742                                 preferences->index_directory,
743                                 index_filename,
744                                 new_asset->path);
745                         remove(index_filename);
746                         new_asset->index_status = INDEX_NOTTESTED;
747                 }
748                 
749                 new_edl->create_objects();
750                 new_edl->copy_session(edl);
752                 sprintf(string, "Loading %s", new_asset->path);
753                 gui->show_message(string, BLACK);
754                 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
756                 switch(result)
757                 {
758 // Convert media file to EDL
759                         case FILE_OK:
760                                 if(load_mode != LOAD_RESOURCESONLY)
761                                 {
762                                         asset_to_edl(new_edl, new_asset);
763                                         new_edls.append(new_edl);
764                                         delete new_asset;
765                                 }
766                                 else
767                                 {
768                                         new_assets.append(new_asset);
769                                 }
771 // Set filename to nothing for assets since save EDL would overwrite them.
772                                 if(load_mode == LOAD_REPLACE || 
773                                         load_mode == LOAD_REPLACE_CONCATENATE)
774                                 {
775                                         set_filename("");
776 // Reset timeline position
777                                         new_edl->local_session->view_start = 0;
778                                         new_edl->local_session->track_start = 0;
779                                 }
780                                 result = 0;
781                                 break;
783 // File not found
784                         case FILE_NOT_FOUND:
785                                 sprintf(string, _("Failed to open %s"), new_asset->path);
786                                 gui->show_message(string, RED);
787                                 result = 1;
788                                 break;
790 // Unknown format
791                         case FILE_UNRECOGNIZED_CODEC:
792                         {
793 // Test index file
794                                 IndexFile indexfile(this);
795                                 result = indexfile.open_index(this, new_asset);
796                                 if(!result)
797                                 {
798                                         indexfile.close_index();
799                                 }
801 // Test existing EDLs
802                                 if(result)
803                                 {
804                                         for(int j = 0; j < new_edls.total + 1; j++)
805                                         {
806                                                 Asset *old_asset;
807                                                 if(j == new_edls.total)
808                                                 {
809                                                         if(old_asset = edl->assets->get_asset(new_asset->path))
810                                                         {
811                                                                 *new_asset = *old_asset;
812                                                                 result = 0;
813                                                         }
814                                                 }
815                                                 else
816                                                 {
817                                                         if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
818                                                         {
819                                                                 *new_asset = *old_asset;
820                                                                 result = 0;
821                                                         }
822                                                 }
823                                         }
824                                 }
826 // Prompt user
827                                 if(result)
828                                 {
829                                         char string[BCTEXTLEN];
830                                         FileSystem fs;
831                                         fs.extract_name(string, new_asset->path);
833                                         strcat(string, _("'s format couldn't be determined."));
834                                         new_asset->audio_data = 1;
835                                         new_asset->format = FILE_PCM;
836                                         new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
837                                         new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
838                                         new_asset->bits = defaults->get("AUDIO_BITS", 16);
839                                         new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
840                                         new_asset->signed_ = defaults->get("SIGNED_", 1);
841                                         new_asset->header = defaults->get("HEADER", 0);
843                                         FileFormat fwindow(this);
844                                         fwindow.create_objects(new_asset, string);
845                                         result = fwindow.run_window();
847                                         defaults->update("AUDIO_CHANNELS", new_asset->channels);
848                                         defaults->update("SAMPLE_RATE", new_asset->sample_rate);
849                                         defaults->update("AUDIO_BITS", new_asset->bits);
850                                         defaults->update("BYTE_ORDER", new_asset->byte_order);
851                                         defaults->update("SIGNED_", new_asset->signed_);
852                                         defaults->update("HEADER", new_asset->header);
853                                         save_defaults();
854                                 }
856 // Append to list
857                                 if(!result)
858                                 {
859 // Recalculate length
860                                         delete new_file;
861                                         new_file = new File;
862                                         result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
864                                         if(load_mode != LOAD_RESOURCESONLY)
865                                         {
866                                                 asset_to_edl(new_edl, new_asset);
867                                                 new_edls.append(new_edl);
868                                                 delete new_asset;
869                                         }
870                                         else
871                                         {
872                                                 new_assets.append(new_asset);
873                                         }
874                                 }
875                                 else
876                                 {
877                                         result = 1;
878                                 }
879                                 break;
880                         }
882                         case FILE_IS_XML:
883                         {
884                                 FileXML xml_file;
885                                 xml_file.read_from_file(filenames->values[i]);
886 // Load EDL for pasting
887                                 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
889 // We don't want a valid reel name/number for projects
890                                 strcpy(new_asset->reel_name, "");
891                                 reel_number = -1;
893 // Do a check weather plugins exist
894                                 for(Track *track = new_edl->tracks->first; track; track = track->next)
895                                 {
896                                         for(int k = 0; k < track->plugin_set.total; k++)
897                                         {
898                                                 PluginSet *plugin_set = track->plugin_set.values[k];
899                                                 for(Plugin *plugin = (Plugin*)plugin_set->first; 
900                                                 plugin; 
901                                                 plugin = (Plugin*)plugin->next)
902                                                 {
903                                                         if(plugin->plugin_type == PLUGIN_STANDALONE)
904                                                         {
905                                                                 // ok we need to find it in plugindb
906                                                                 int plugin_found = 0;
907                                                                 for(int j = 0; j < plugindb->total; j++)
908                                                                 {
909                                                                         PluginServer *server = plugindb->values[j];
910                                                                         if(!strcasecmp(server->title, plugin->title) &&
911                                                                                 ((track->data_type == TRACK_AUDIO && server->audio) ||
912                                                                                 (track->data_type == TRACK_VIDEO && server->video)) &&
913                                                                                 (!server->transition))
914                                                                                 plugin_found = 1;
915                                                                 }
916                                                                 if (!plugin_found) 
917                                                                 {
918                                                                         printf("\nWARNING: The plugin '%s' named in file '%s' is not part of your installation of Cinelerra. This means project will not be rendered as it was meant and it might result in Cinelerra crushing.\n", plugin->title, filenames->values[i]); 
919                                                                 }
920                                                         }
921                                                 }
922                                         }
923                                         for(Edit *edit = (Edit*)track->edits->first; 
924                                         edit; 
925                                         edit = (Edit*)edit->next)
926                                         {
927                                                 if (edit->transition)
928                                                 {
929                                                         // ok we need to find transition in plugindb
930                                                         int transition_found = 0;
931                                                         for(int j = 0; j < plugindb->total; j++)
932                                                         {
933                                                                 PluginServer *server = plugindb->values[j];
934                                                                 if(!strcasecmp(server->title, edit->transition->title) &&
935                                                                         ((track->data_type == TRACK_AUDIO && server->audio) ||
936                                                                         (track->data_type == TRACK_VIDEO && server->video)) &&
937                                                                         (server->transition))
938                                                                         transition_found = 1;
939                                                         }
940                                                         if (!transition_found) 
941                                                         {
942                                                                 printf("\nWARNING: The transition '%s' named in file '%s' is not part of your installation of Cinelerra. This means project will not be rendered as it was meant and it might result in Cinelerra crushing.\n", edit->transition->title, filenames->values[i]); 
943                                                         }
944                                                 }
945                                         }
946                                 }
950                                 if(load_mode == LOAD_REPLACE || 
951                                         load_mode == LOAD_REPLACE_CONCATENATE)
952                                 {
953                                         strcpy(session->filename, filenames->values[i]);
954                                         strcpy(new_edl->local_session->clip_title, filenames->values[i]);
955                                         if(update_filename)
956                                                 set_filename(new_edl->local_session->clip_title);
957                                 }
959                                 new_edls.append(new_edl);
960                                 result = 0;
961                                 break;
962                         }
963                 }
965                 if(result)
966                 {
967                         delete new_edl;
968                         delete new_asset;
969                 }
971                 delete new_file;
972         }
976         if(!result) gui->statusbar->default_message();
985 // Paste them.
986 // Don't back up here.
987         if(new_edls.total)
988         {
989 // For pasting, clear the active region
990                 if(load_mode == LOAD_PASTE)
991                 {
992                         double start = edl->local_session->get_selectionstart();
993                         double end = edl->local_session->get_selectionend();
994                         if(!EQUIV(start, end))
995                                 edl->clear(start, 
996                                         end,
997                                         edl->session->labels_follow_edits,
998                                         edl->session->plugins_follow_edits);
999                 }
1001                 paste_edls(&new_edls, 
1002                         load_mode,
1003                         0,
1004                         -1,
1005                         edl->session->labels_follow_edits, 
1006                         edl->session->plugins_follow_edits);
1007         }
1015         if(new_assets.total)
1016         {
1017                 for(int i = 0; i < new_assets.total; i++)
1018                 {
1019                         mainindexes->add_next_asset(new_assets.values[i]);
1020                         edl->assets->update(new_assets.values[i]);
1021                 }
1024 // Start examining next batch of index files
1025                 mainindexes->start_build();
1026         }
1028 TRACE("MWindow::load_filenames 100");
1029         update_project(load_mode);
1030 TRACE("MWindow::load_filenames 110");
1032 //printf("MWindow::load_filenames 9\n");
1033 //sleep(10);
1035         new_edls.remove_all_objects();
1036         new_assets.remove_all_objects();
1037 //printf("MWindow::load_filenames 10 %d\n", edl->session->audio_module_fragment);
1039         if(load_mode == LOAD_REPLACE ||
1040                 load_mode == LOAD_REPLACE_CONCATENATE)
1041                 session->changes_made = 0;
1043 UNTRACE
1044         return 0;
1047 void MWindow::create_objects(int want_gui, 
1048         int want_new,
1049         char *config_path)
1051         char string[BCTEXTLEN];
1052         FileSystem fs;
1053         edl = 0;
1056         show_splash();
1058 // For some reason, init_signals must come after show_splash or the signals won't
1059 // get trapped.
1060         init_signals();
1063         init_menus();
1064 TRACE("MWindow::create_objects 1");
1065         init_defaults(defaults, config_path);
1066 TRACE("MWindow::create_objects 2");
1067         init_preferences();
1068 TRACE("MWindow::create_objects 3");
1069         init_plugins(preferences, plugindb, splash_window);
1070         if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1071 TRACE("MWindow::create_objects 4");
1072         init_theme();
1073 // Default project created here
1074 TRACE("MWindow::create_objects 5");
1075         init_edl();
1077 TRACE("MWindow::create_objects 6");
1078         init_awindow();
1079 TRACE("MWindow::create_objects 7");
1080         init_compositor();
1081 TRACE("MWindow::create_objects 8");
1082         init_levelwindow();
1083 TRACE("MWindow::create_objects 9");
1084         init_viewer();
1085 TRACE("MWindow::create_objects 10");
1086         init_cache();
1087 TRACE("MWindow::create_objects 11");
1088         init_indexes();
1089 TRACE("MWindow::create_objects 12");
1090         init_channeldb();
1091 TRACE("MWindow::create_objects 13");
1093         init_gui();
1094 TRACE("MWindow::create_objects 14");
1095         init_render();
1096         init_brender();
1097         mainprogress = new MainProgress(this, gui);
1098         undo = new MainUndo(this);
1100         plugin_guis = new ArrayList<PluginServer*>;
1102 TRACE("MWindow::create_objects 15");
1103         if(session->show_vwindow) vwindow->gui->show_window();
1104         if(session->show_cwindow) cwindow->gui->show_window();
1105         if(session->show_awindow) awindow->gui->show_window();
1106         if(session->show_lwindow) lwindow->gui->show_window();
1107 TRACE("MWindow::create_objects 16");
1109 //      vwindow->start();
1110 //      awindow->start();
1111 //      cwindow->start();
1112 //      lwindow->start();
1113 //printf("MWindow::create_objects 1");
1115         gui->mainmenu->load_defaults(defaults);
1116 TRACE("MWindow::create_objects 17");
1117         gui->mainmenu->update_toggles();
1118 TRACE("MWindow::create_objects 18");
1119         gui->patchbay->update();
1120 TRACE("MWindow::create_objects 19");
1121         gui->canvas->draw();
1122 TRACE("MWindow::create_objects 20");
1123         gui->cursor->draw();
1124 TRACE("MWindow::create_objects 21");
1125         gui->raise_window();
1126 TRACE("MWindow::create_objects 22");
1127         gui->show_window();
1128 TRACE("MWindow::create_objects 23");
1130         hide_splash();
1131 UNTRACE
1135 void MWindow::show_splash()
1137 #include "data/heroine_logo12_png.h"
1138         VFrame *frame = new VFrame(heroine_logo12_png);
1139         BC_DisplayInfo display_info;
1140         splash_window = new SplashGUI(frame, 
1141                 display_info.get_root_w() / 2 - frame->get_w() / 2,
1142                 display_info.get_root_h() / 2 - frame->get_h() / 2);
1143         splash_window->create_objects();
1146 void MWindow::hide_splash()
1148         if(splash_window)
1149                 delete splash_window;
1150         splash_window = 0;
1154 void MWindow::start()
1156         vwindow->start();
1157         awindow->start();
1158         cwindow->start();
1159         lwindow->start();
1160         gui->run_window();
1163 void MWindow::show_vwindow()
1165         session->show_vwindow = 1;
1166         vwindow->gui->lock_window("MWindow::show_vwindow");
1167         vwindow->gui->show_window();
1168         vwindow->gui->raise_window();
1169         vwindow->gui->flush();
1170         vwindow->gui->unlock_window();
1171         gui->mainmenu->show_vwindow->set_checked(1);
1174 void MWindow::show_awindow()
1176         session->show_awindow = 1;
1177         awindow->gui->lock_window("MWindow::show_awindow");
1178         awindow->gui->show_window();
1179         awindow->gui->raise_window();
1180         awindow->gui->flush();
1181         awindow->gui->unlock_window();
1182         gui->mainmenu->show_awindow->set_checked(1);
1185 void MWindow::show_cwindow()
1187         session->show_cwindow = 1;
1188         cwindow->gui->lock_window("MWindow::show_cwindow");
1189         cwindow->gui->show_window();
1190         cwindow->gui->raise_window();
1191         cwindow->gui->flush();
1192         cwindow->gui->unlock_window();
1193         gui->mainmenu->show_cwindow->set_checked(1);
1196 void MWindow::show_lwindow()
1198         session->show_lwindow = 1;
1199         lwindow->gui->lock_window("MWindow::show_lwindow");
1200         lwindow->gui->show_window();
1201         lwindow->gui->raise_window();
1202         lwindow->gui->flush();
1203         lwindow->gui->unlock_window();
1204         gui->mainmenu->show_lwindow->set_checked(1);
1207 void MWindow::tile_windows()
1209         session->default_window_positions();
1210         gui->default_positions();
1213 void MWindow::toggle_loop_playback()
1215         edl->local_session->loop_playback = !edl->local_session->loop_playback;
1216         set_loop_boundaries();
1217         save_backup();
1219         gui->canvas->draw_overlays();
1220         gui->canvas->flash();
1221         sync_parameters(CHANGE_PARAMS);
1224 void MWindow::set_titles(int value)
1226         edl->session->show_titles = value;
1227         trackmovement(edl->local_session->track_start);
1230 void MWindow::set_auto_keyframes(int value)
1232         gui->lock_window("MWindow::set_auto_keyframes");
1233         edl->session->auto_keyframes = value;
1234         gui->mbuttons->edit_panel->keyframe->update(value);
1235         gui->flush();
1236         gui->unlock_window();
1237         cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1238         cwindow->gui->edit_panel->keyframe->update(value);
1239         cwindow->gui->flush();
1240         cwindow->gui->unlock_window();
1243 int MWindow::set_editing_mode(int new_editing_mode)
1245         gui->lock_window("MWindow::set_editing_mode");
1246         edl->session->editing_mode = new_editing_mode;
1247         gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1248         gui->mbuttons->edit_panel->update();
1249         gui->canvas->update_cursor();
1250         gui->unlock_window();
1251         cwindow->gui->lock_window("MWindow::set_editing_mode");
1252         cwindow->gui->edit_panel->update();
1253         cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1254         cwindow->gui->unlock_window();
1255         return 0;
1259 void MWindow::sync_parameters(int change_type)
1262 // Sync engines which are playing back
1263         if(cwindow->playback_engine->is_playing_back)
1264         {
1265                 if(change_type == CHANGE_PARAMS)
1266                 {
1267 // TODO: block keyframes until synchronization is done
1268                         cwindow->playback_engine->sync_parameters(edl);
1269                 }
1270                 else
1271 // Stop and restart
1272                 {
1273                         int command = cwindow->playback_engine->command->command;
1274                         cwindow->playback_engine->que->send_command(STOP,
1275                                 CHANGE_NONE, 
1276                                 0,
1277                                 0);
1278 // Waiting for tracking to finish would make the restart position more
1279 // accurate but it can't lock the window to stop tracking for some reason.
1280 // Not waiting for tracking gives a faster response but restart position is
1281 // only as accurate as the last tracking update.
1282                         cwindow->playback_engine->interrupt_playback(0);
1283                         cwindow->playback_engine->que->send_command(command,
1284                                         change_type, 
1285                                         edl,
1286                                         1,
1287                                         0);
1288                 }
1289         }
1290         else
1291         {
1292                 cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1293                                                         change_type,
1294                                                         edl,
1295                                                         1);
1296         }
1299 void MWindow::update_caches()
1301         audio_cache->set_edl(edl);
1302         video_cache->set_edl(edl);
1305 void MWindow::show_plugin(Plugin *plugin)
1307         int done = 0;
1308 //printf("MWindow::show_plugin 1\n");
1309         plugin_gui_lock->lock("MWindow::show_plugin");
1310         for(int i = 0; i < plugin_guis->total; i++)
1311         {
1312 // Pointer comparison
1313                 if(plugin_guis->values[i]->plugin == plugin)
1314                 {
1315                         plugin_guis->values[i]->raise_window();
1316                         done = 1;
1317                         break;
1318                 }
1319         }
1321 //printf("MWindow::show_plugin 1\n");
1322         if(!done)
1323         {
1324                 if(!plugin->track)
1325                 {
1326                         printf("MWindow::show_plugin track not defined.\n");
1327                 }
1328                 PluginServer *server = scan_plugindb(plugin->title,
1329                         plugin->track->data_type);
1331 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
1332                 if(server && server->uses_gui)
1333                 {
1334                         PluginServer *gui = plugin_guis->append(new PluginServer(*server));
1335 // Needs mwindow to do GUI
1336                         gui->set_mwindow(this);
1337                         gui->open_plugin(0, preferences, edl, plugin, -1);
1338                         gui->show_gui();
1339                         plugin->show = 1;
1340                 }
1341         }
1342         plugin_gui_lock->unlock();
1343 //printf("MWindow::show_plugin 2\n");
1346 void MWindow::hide_plugin(Plugin *plugin, int lock)
1348         if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
1349         plugin->show = 0;
1350         for(int i = 0; i < plugin_guis->total; i++)
1351         {
1352                 if(plugin_guis->values[i]->plugin == plugin)
1353                 {
1354                         PluginServer *ptr = plugin_guis->values[i];
1355                         plugin_guis->remove(ptr);
1356                         if(lock) plugin_gui_lock->unlock();
1357 // Last command executed in client side close
1358                         delete ptr;
1359                         return;
1360                 }
1361         }
1362         if(lock) plugin_gui_lock->unlock();
1365 void MWindow::hide_plugins()
1367         plugin_gui_lock->lock("MWindow::hide_plugins");
1368         plugin_guis->remove_all_objects();
1369         plugin_gui_lock->unlock();
1372 void MWindow::update_plugin_guis()
1374         plugin_gui_lock->lock("MWindow::update_plugin_guis");
1376         for(int i = 0; i < plugin_guis->total; i++)
1377         {
1378                 plugin_guis->values[i]->update_gui();
1379         }
1380         plugin_gui_lock->unlock();
1383 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
1385         plugin_gui_lock->lock("MWindow::render_plugin_gui");
1386         for(int i = 0; i < plugin_guis->total; i++)
1387         {
1388                 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1389                 {
1390                         plugin_guis->values[i]->render_gui(data);
1391                         break;
1392                 }
1393         }
1394         plugin_gui_lock->unlock();
1397 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
1399         plugin_gui_lock->lock("MWindow::render_plugin_gui");
1400         for(int i = 0; i < plugin_guis->total; i++)
1401         {
1402                 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1403                 {
1404                         plugin_guis->values[i]->render_gui(data, size);
1405                         break;
1406                 }
1407         }
1408         plugin_gui_lock->unlock();
1412 void MWindow::update_plugin_states()
1414         int result = 0;
1415         plugin_gui_lock->lock("MWindow::update_plugin_states");
1416         for(int i = 0; i < plugin_guis->total; i++)
1417         {
1418 // Get a plugin GUI
1419                 Plugin *src_plugin = plugin_guis->values[i]->plugin;
1420                 PluginServer *src_plugingui = plugin_guis->values[i];
1422 // Search for plugin in EDL.  Only the master EDL shows plugin GUIs.
1423                 for(Track *track = edl->tracks->first; 
1424                         track && !result; 
1425                         track = track->next)
1426                 {
1427                         for(int j = 0; 
1428                                 j < track->plugin_set.total && !result; 
1429                                 j++)
1430                         {
1431                                 PluginSet *plugin_set = track->plugin_set.values[j];
1432                                 for(Plugin *plugin = (Plugin*)plugin_set->first; 
1433                                         plugin && !result; 
1434                                         plugin = (Plugin*)plugin->next)
1435                                 {
1436                                         if(plugin == src_plugin &&
1437                                                 !strcmp(plugin->title, src_plugingui->title)) result = 1;
1438                                 }
1439                         }
1440                 }
1443 // Doesn't exist anymore
1444                 if(!result)
1445                 {
1446                         hide_plugin(src_plugin, 0);
1447                         i--;
1448                 }
1449         }
1450         plugin_gui_lock->unlock();
1454 void MWindow::update_plugin_titles()
1456         for(int i = 0; i < plugin_guis->total; i++)
1457         {
1458                 plugin_guis->values[i]->update_title();
1459         }
1462 int MWindow::asset_to_edl(EDL *new_edl, 
1463         Asset *new_asset, 
1464         RecordLabels *labels)
1466 //printf("MWindow::asset_to_edl 1\n");
1467 //      new_edl->load_defaults(defaults);
1469 // Keep frame rate, sample rate, and output size unchanged.
1470 // These parameters would revert the project if VWindow displayed an asset
1471 // of different size than the project.
1472         if(new_asset->video_data)
1473         {
1474                 new_edl->session->video_tracks = new_asset->layers;
1475 //              new_edl->session->frame_rate = new_asset->frame_rate;
1476 //              new_edl->session->output_w = new_asset->width;
1477 //              new_edl->session->output_h = new_asset->height;
1478         }
1479         else
1480                 new_edl->session->video_tracks = 0;
1487         if(new_asset->audio_data)
1488         {
1489                 new_edl->session->audio_tracks = new_asset->channels;
1490 //              new_edl->session->sample_rate = new_asset->sample_rate;
1491         }
1492         else
1493                 new_edl->session->audio_tracks = 0;
1494 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1496         new_edl->create_default_tracks();
1497 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1499 // Disable drawing if the file format isn't fast enough.
1500         if(new_asset->format == FILE_MPEG)
1501         {
1502                 for(Track *current = new_edl->tracks->first;
1503                         current;
1504                         current = NEXT)
1505                 {
1506                         if(current->data_type == TRACK_VIDEO) current->draw = 0;
1507                 }
1508         }
1512 //printf("MWindow::asset_to_edl 3\n");
1513         new_edl->insert_asset(new_asset, 0, 0, labels);
1514 //printf("MWindow::asset_to_edl 3\n");
1520         char string[BCTEXTLEN];
1521         FileSystem fs;
1522         fs.extract_name(string, new_asset->path);
1523 //printf("MWindow::asset_to_edl 3\n");
1525         strcpy(new_edl->local_session->clip_title, string);
1526 //printf("MWindow::asset_to_edl 4 %s\n", string);
1528 //      new_edl->dump();
1529         return 0;
1532 // Reset everything after a load.
1533 void MWindow::update_project(int load_mode)
1535         restart_brender();
1536 //TRACE("MWindow::update_project 1");
1537         edl->tracks->update_y_pixels(theme);
1539 // Draw timeline
1540 //TRACE("MWindow::update_project 2");
1541         update_caches();
1543 TRACE("MWindow::update_project 3");
1544         gui->update(1, 1, 1, 1, 1, 1, 1);
1546 TRACE("MWindow::update_project 4");
1547         cwindow->update(0, 0, 1, 1, 1);
1549 TRACE("MWindow::update_project 5");
1551         if(load_mode == LOAD_REPLACE ||
1552                 load_mode == LOAD_REPLACE_CONCATENATE)
1553         {
1554                 vwindow->change_source();
1555         }
1556         else
1557         {
1558                 vwindow->update(1);
1559         }
1561 TRACE("MWindow::update_project 6");
1563         cwindow->gui->slider->set_position();
1564 TRACE("MWindow::update_project 6.1");
1565         cwindow->gui->timebar->update(1, 1);
1566 TRACE("MWindow::update_project 6.2");
1567         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1568                 CHANGE_ALL,
1569                 edl,
1570                 1);
1572 TRACE("MWindow::update_project 7");
1573         awindow->gui->lock_window("MWindow::update_project");
1574         awindow->gui->update_assets();
1575         awindow->gui->flush();
1576         awindow->gui->unlock_window();
1577         gui->flush();
1578 TRACE("MWindow::update_project 100");
1582 void MWindow::rebuild_indices()
1584         char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
1586         for(int i = 0; i < session->drag_assets->total; i++)
1587         {
1588 //printf("MWindow::rebuild_indices 1 %s\n", session->drag_assets->values[i]->path);
1589 // Erase file
1590                 IndexFile::get_index_filename(source_filename, 
1591                         preferences->index_directory,
1592                         index_filename, 
1593                         session->drag_assets->values[i]->path);
1594                 remove(index_filename);
1595 // Schedule index build
1596                 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
1597                 mainindexes->add_next_asset(session->drag_assets->values[i]);
1598         }
1599         mainindexes->start_build();
1603 void MWindow::save_backup()
1605         FileXML file;
1606         edl->set_project_path(session->filename);
1607         edl->save_xml(plugindb, 
1608                 &file, 
1609                 BACKUP_PATH,
1610                 0,
1611                 0);
1612         file.terminate_string();
1613         char path[BCTEXTLEN];
1614         FileSystem fs;
1615         strcpy(path, BACKUP_PATH);
1616         fs.complete_path(path);
1618         if(file.write_to_file(path))
1619         {
1620                 char string2[256];
1621                 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
1622                 gui->show_message(string2);
1623         }
1627 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
1629         int denominator;
1630         float fraction = (float)width / height;
1632         for(denominator = 1; 
1633                 denominator < 100 && 
1634                         fabs(fraction * denominator - (int)(fraction * denominator)) > .001; 
1635                 denominator++)
1636                 ;
1638         w = denominator * width / height;
1639         h = denominator;
1644 void MWindow::remove_assets_from_project(int push_undo)
1646     if(push_undo) undo->update_undo_before(_("remove assets"), LOAD_ALL);
1648 // Remove from caches
1649         for(int i = 0; i < session->drag_assets->total; i++)
1650         {
1651                 audio_cache->delete_entry(session->drag_assets->values[i]);
1652                 video_cache->delete_entry(session->drag_assets->values[i]);
1653         }
1655 printf("MWindow::remove_assets_from_project 1\n");
1656 video_cache->dump();
1657 audio_cache->dump();
1658 printf("MWindow::remove_assets_from_project 100\n");
1660 // Remove from VWindow.
1661         for(int i = 0; i < session->drag_clips->total; i++)
1662         {
1663                 if(session->drag_clips->values[i] == vwindow->get_edl())
1664                 {
1665                         vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
1666                         vwindow->remove_source();
1667                         vwindow->gui->unlock_window();
1668                 }
1669         }
1670         
1671         for(int i = 0; i < session->drag_assets->total; i++)
1672         {
1673                 if(session->drag_assets->values[i] == vwindow->get_asset())
1674                 {
1675                         vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
1676                         vwindow->remove_source();
1677                         vwindow->gui->unlock_window();
1678                 }
1679         }
1680         
1681         edl->remove_from_project(session->drag_assets);
1682         edl->remove_from_project(session->drag_clips);
1683         save_backup();
1684         if(push_undo) undo->update_undo_after();
1685         restart_brender();
1687         gui->lock_window("MWindow::remove_assets_from_project 3");
1688         gui->update(1,
1689                 1,
1690                 1,
1691                 1,
1692                 0, 
1693                 1,
1694                 0);
1695         gui->unlock_window();
1697         awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
1698         awindow->gui->update_assets();
1699         awindow->gui->flush();
1700         awindow->gui->unlock_window();
1702 // Removes from playback here
1703         sync_parameters(CHANGE_ALL);
1706 void MWindow::remove_assets_from_disk()
1708 // Remove from disk
1709         for(int i = 0; i < session->drag_assets->total; i++)
1710         {
1711                 remove(session->drag_assets->values[i]->path);
1712         }
1714         remove_assets_from_project(1);
1717 void MWindow::dump_plugins()
1719         for(int i = 0; i < plugindb->total; i++)
1720         {
1721                 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
1722                         plugindb->values[i]->audio,
1723                         plugindb->values[i]->video,
1724                         plugindb->values[i]->realtime,
1725                         plugindb->values[i]->transition,
1726                         plugindb->values[i]->theme,
1727                         plugindb->values[i]->title);
1728         }
1755 int MWindow::save_defaults()
1757         gui->save_defaults(defaults);
1758         edl->save_defaults(defaults);
1759         session->save_defaults(defaults);
1760         preferences->save_defaults(defaults);
1762         defaults->save();
1763         return 0;
1766 int MWindow::run_script(FileXML *script)
1768         int result = 0, result2 = 0;
1769         while(!result && !result2)
1770         {
1771                 result = script->read_tag();
1772                 if(!result)
1773                 {
1774                         if(script->tag.title_is("new_project"))
1775                         {
1776 // Run new in immediate mode.
1777 //                              gui->mainmenu->new_project->run_script(script);
1778                         }
1779                         else
1780                         if(script->tag.title_is("record"))
1781                         {
1782 // Run record as a thread.  It is a terminal command.
1783                                 ;
1784 // Will read the complete scipt file without letting record read it if not
1785 // terminated.
1786                                 result2 = 1;
1787                         }
1788                         else
1789                         {
1790                                 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
1791                         }
1792                 }
1793         }
1794         return result2;
1797 // ================================= synchronization
1800 int MWindow::interrupt_indexes()
1802         mainindexes->interrupt_build();
1803         return 0; 
1808 void MWindow::next_time_format()
1810         switch(edl->session->time_format)
1811         {
1812                 case 0: edl->session->time_format = 1; break;
1813                 case 1: edl->session->time_format = 2; break;
1814                 case 2: edl->session->time_format = 3; break;
1815                 case 3: edl->session->time_format = 4; break;
1816                 case 4: edl->session->time_format = 5; break;
1817                 case 5: edl->session->time_format = 0; break;
1818         }
1820         gui->lock_window();
1821         gui->redraw_time_dependancies();
1825         char string[BCTEXTLEN], string2[BCTEXTLEN];
1826         sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
1827         gui->show_message(string, BLACK);
1828         gui->flush();
1829         gui->unlock_window();
1832 int MWindow::set_filename(char *filename)
1834         strcpy(session->filename, filename);
1835         if(gui)
1836         {
1837                 if(filename[0] == 0)
1838                 {
1839                         gui->set_title(PROGRAM_NAME);
1840                 }
1841                 else
1842                 {
1843                         FileSystem dir;
1844                         char string[BCTEXTLEN], string2[BCTEXTLEN];
1845                         dir.extract_name(string, filename);
1846                         sprintf(string2, PROGRAM_NAME ": %s", string);
1847                         gui->set_title(string2);
1848                 }
1849         }
1850         return 0; 
1860 int MWindow::set_loop_boundaries()
1862         double start = edl->local_session->get_selectionstart();
1863         double end = edl->local_session->get_selectionend();
1864         
1865         if(start != 
1866                 end) 
1867         {
1868                 ;
1869         }
1870         else
1871         if(edl->tracks->total_length())
1872         {
1873                 start = 0;
1874                 end = edl->tracks->total_length();
1875         }
1876         else
1877         {
1878                 start = end = 0;
1879         }
1881         if(edl->local_session->loop_playback && start != end)
1882         {
1883                 edl->local_session->loop_start = start;
1884                 edl->local_session->loop_end = end;
1885         }
1886         return 0; 
1895 int MWindow::reset_meters()
1897         cwindow->gui->lock_window("MWindow::reset_meters 1");
1898         cwindow->gui->meters->reset_meters();
1899         cwindow->gui->unlock_window();
1901         vwindow->gui->lock_window("MWindow::reset_meters 2");
1902         vwindow->gui->meters->reset_meters();
1903         vwindow->gui->unlock_window();
1905         lwindow->gui->lock_window("MWindow::reset_meters 3");
1906         lwindow->gui->panel->reset_meters();
1907         lwindow->gui->unlock_window();
1909         gui->lock_window("MWindow::reset_meters 4");
1910         gui->patchbay->reset_meters();
1911         gui->unlock_window();
1912         return 0;