r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / mwindow.C
blob5e41066f5a3d137b9af643662fbedb20061ef862
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 "interlacemodes.h"
28 #include "language.h"
29 #include "levelwindowgui.h"
30 #include "levelwindow.h"
31 #include "loadfile.inc"
32 #include "localsession.h"
33 #include "maincursor.h"
34 #include "mainindexes.h"
35 #include "mainmenu.h"
36 #include "mainprogress.h"
37 #include "mainsession.h"
38 #include "mainundo.h"
39 #include "mbuttons.h"
40 #include "mutex.h"
41 #include "mwindowgui.h"
42 #include "mwindow.h"
43 #include "new.h"
44 #include "patchbay.h"
45 #include "playbackengine.h"
46 #include "plugin.h"
47 #include "pluginserver.h"
48 #include "pluginset.h"
49 #include "preferences.h"
50 #include "record.h"
51 #include "recordlabel.h"
52 #include "render.h"
53 #include "samplescroll.h"
54 #include "sighandler.h"
55 #include "splashgui.h"
56 #include "statusbar.h"
57 #include "theme.h"
58 #include "threadloader.h"
59 #include "timebar.h"
60 #include "trackcanvas.h"
61 #include "track.h"
62 #include "tracking.h"
63 #include "trackscroll.h"
64 #include "tracks.h"
65 #include "transition.h"
66 #include "transportque.h"
67 #include "vframe.h"
68 #include "videodevice.inc"
69 #include "videowindow.h"
70 #include "vplayback.h"
71 #include "vwindowgui.h"
72 #include "vwindow.h"
73 #include "zoombar.h"
75 #include <string.h>
79 extern "C"
85 // Hack for libdv to remove glib dependancy
87 // void
88 // g_log (const char    *log_domain,
89 //        int  log_level,
90 //        const char    *format,
91 //        ...)
92 // {
93 // }
94 // 
95 // void
96 // g_logv (const char    *log_domain,
97 //        int  log_level,
98 //        const char    *format,
99 //        ...)
100 // {
101 // }
102 // 
105 // Hack for XFree86 4.1.0
107 int atexit(void (*function)(void))
109         return 0;
120 MWindow::MWindow()
122         plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
123         brender_lock = new Mutex("MWindow::brender_lock");
124         brender = 0;
125         session = 0;
126         channeldb_buz = new ChannelDB;
127         channeldb_v4l2jpeg = new ChannelDB;
130 MWindow::~MWindow()
132         brender_lock->lock("MWindow::~MWindow");
133         if(brender) delete brender;
134         brender = 0;
135         brender_lock->unlock();
136         delete brender_lock;
138         delete mainindexes;
140 TRACE("MWindow::~MWindow 1\n");
141         clean_indexes();
142 TRACE("MWindow::~MWindow 2\n");
144         save_defaults();
145 TRACE("MWindow::~MWindow 3\n");
146 // Give up and go to a movie
147         exit(0);
149 TRACE("MWindow::~MWindow 4\n");
150         delete mainprogress;
151         delete audio_cache;             // delete the cache after the assets
152         delete video_cache;             // delete the cache after the assets
153         if(gui) delete gui;
154         delete undo;
155         delete preferences;
156         delete defaults;
157         delete render;
158 //      delete renderlist;
159         delete awindow;
160         delete vwindow;
161         delete cwindow;
162         delete lwindow;
163         plugin_guis->remove_all_objects();
164         delete plugin_guis;
165         delete plugin_gui_lock;
168 void MWindow::init_defaults(Defaults* &defaults, char *config_path)
170         char path[BCTEXTLEN];
171 // Use user supplied path
172         if(config_path[0])
173         {
174                 strcpy(path, config_path);
175         }
176         else
177         {
178 // set the .bcast path
179                 FileSystem fs;
181                 sprintf(path, "%s", BCASTDIR);
182                 fs.complete_path(path);
183                 if(fs.is_dir(path)) 
184                 {
185                         fs.create_dir(path); 
186                 }
188 // load the defaults
189                 strcat(path, "Cinelerra_rc");
190         }
192         defaults = new Defaults(path);
193         defaults->load();
196 void MWindow::init_plugin_path(Preferences *preferences, 
197         ArrayList<PluginServer*>* &plugindb,
198         FileSystem *fs,
199         SplashGUI *splash_window,
200         int *counter)
202         int result = 0;
203         PluginServer *newplugin;
205         if(!result)
206         {
207                 for(int i = 0; i < fs->dir_list.total; i++)
208                 {
209                         char path[BCTEXTLEN];
210                         strcpy(path, fs->dir_list.values[i]->path);
212 // File is a directory
213                         if(!fs->is_dir(path))
214                         {
215                                 continue;
216                         }
217                         else
218                         {
219 // Try to query the plugin
220                                 fs->complete_path(path);
221 //printf("MWindow::init_plugin_path %s\n", path);
222                                 PluginServer *new_plugin = new PluginServer(path);
223                                 int result = new_plugin->open_plugin(1, preferences, 0, 0, -1);
225                                 if(!result)
226                                 {
227                                         plugindb->append(new_plugin);
228                                         new_plugin->close_plugin();
229                                         if(splash_window)
230                                                 splash_window->operation->update(_(new_plugin->title));
231                                 }
232                                 else
233                                 if(result == PLUGINSERVER_IS_LAD)
234                                 {
235                                         delete new_plugin;
236 // Open LAD subplugins
237                                         int id = 0;
238                                         do
239                                         {
240                                                 new_plugin = new PluginServer(path);
241                                                 result = new_plugin->open_plugin(1,
242                                                         preferences,
243                                                         0,
244                                                         0,
245                                                         id);
246                                                 id++;
247                                                 if(!result)
248                                                 {
249                                                         plugindb->append(new_plugin);
250                                                         new_plugin->close_plugin();
251                                                         if(splash_window)
252                                                                 splash_window->operation->update(_(new_plugin->title));
253                                                 }
254                                         }while(!result);
255                                 }
256                                 else
257                                 {
258 // Plugin failed to open
259                                         delete new_plugin;
260                                 }
261                         }
262                         if(splash_window) splash_window->progress->update((*counter)++);
263                 }
264         }
267 void MWindow::init_plugins(Preferences *preferences, 
268         ArrayList<PluginServer*>* &plugindb,
269         SplashGUI *splash_window)
271         plugindb = new ArrayList<PluginServer*>;
275         FileSystem cinelerra_fs;
276         ArrayList<FileSystem*> lad_fs;
277         int result = 0;
279 // Get directories
280         cinelerra_fs.set_filter("[*.plugin][*.so]");
281         result = cinelerra_fs.update(preferences->global_plugin_dir);
283         if(result)
284         {
285                 fprintf(stderr, 
286                         _("MWindow::init_plugins: couldn't open %s directory\n"),
287                         preferences->global_plugin_dir);
288         }
290 // Parse LAD environment variable
291         char *env = getenv("LADSPA_PATH");
292         if(env)
293         {
294                 char string[BCTEXTLEN];
295                 char *ptr1 = env;
296                 while(ptr1)
297                 {
298                         char *ptr = strchr(ptr1, ':');
299                         char *end;
300                         if(ptr)
301                         {
302                                 end = ptr;
303                         }
304                         else
305                         {
306                                 end = env + strlen(env);
307                         }
309                         if(end > ptr1)
310                         {
311                                 int len = end - ptr1;
312                                 memcpy(string, ptr1, len);
313                                 string[len] = 0;
316                                 FileSystem *fs = new FileSystem;
317                                 lad_fs.append(fs);
318                                 fs->set_filter("*.so");
319                                 result = fs->update(string);
321                                 if(result)
322                                 {
323                                         fprintf(stderr, 
324                                                 _("MWindow::init_plugins: couldn't open %s directory\n"),
325                                                 string);
326                                 }
327                         }
329                         if(ptr)
330                                 ptr1 = ptr + 1;
331                         else
332                                 ptr1 = ptr;
333                 };
334         }
336         int total = cinelerra_fs.total_files();
337         int counter = 0;
338         for(int i = 0; i < lad_fs.total; i++)
339                 total += lad_fs.values[i]->total_files();
340         if(splash_window) splash_window->progress->update_length(total);
342 // Cinelerra
343 #ifndef DO_STATIC
344         init_plugin_path(preferences,
345                 plugindb,
346                 &cinelerra_fs,
347                 splash_window,
348                 &counter);
349 #else
350 // Call automatically generated routine to get plugins
351 #endif
353 // LAD
354         for(int i = 0; i < lad_fs.total; i++)
355                 init_plugin_path(preferences,
356                         plugindb,
357                         lad_fs.values[i],
358                         splash_window,
359                         &counter);
361         lad_fs.remove_all_objects();
364 void MWindow::delete_plugins()
366         for(int i = 0; i < plugindb->total; i++)
367         {
368                 delete plugindb->values[i];
369         }
370         delete plugindb;
373 void MWindow::create_plugindb(int do_audio, 
374                 int do_video, 
375                 int is_realtime, 
376                 int is_transition,
377                 int is_theme,
378                 ArrayList<PluginServer*> &plugindb)
380 // Get plugins
381         for(int i = 0; i < this->plugindb->total; i++)
382         {
383                 PluginServer *current = this->plugindb->values[i];
385                 if(current->audio == do_audio &&
386                         current->video == do_video &&
387                         (current->realtime == is_realtime || is_realtime < 0) &&
388                         current->transition == is_transition &&
389                         current->theme == is_theme)
390                         plugindb.append(current);
391         }
393 // Alphabetize list by title
394         int done = 0;
395         while(!done)
396         {
397                 done = 1;
398                 
399                 for(int i = 0; i < plugindb.total - 1; i++)
400                 {
401                         PluginServer *value1 = plugindb.values[i];
402                         PluginServer *value2 = plugindb.values[i + 1];
403                         if(strcmp(_(value1->title), _(value2->title)) > 0)
404                         {
405                                 done = 0;
406                                 plugindb.values[i] = value2;
407                                 plugindb.values[i + 1] = value1;
408                         }
409                 }
410         }
413 PluginServer* MWindow::scan_plugindb(char *title,
414                 int data_type)
416         if(data_type < 0)
417         {
418                 printf("MWindow::scan_plugindb data_type < 0\n");
419                 return 0;
420         }
422         for(int i = 0; i < plugindb->total; i++)
423         {
424                 PluginServer *server = plugindb->values[i];
425                 if(!strcasecmp(server->title, title) &&
426                 ((data_type == TRACK_AUDIO && server->audio) ||
427                 (data_type == TRACK_VIDEO && server->video))) 
428                         return plugindb->values[i];
429         }
430         return 0;
433 void MWindow::init_preferences()
435         preferences = new Preferences;
436         preferences->load_defaults(defaults);
437         session = new MainSession(this);
438         session->load_defaults(defaults);
441 void MWindow::clean_indexes()
443         FileSystem fs;
444         int total_excess;
445         long oldest;
446         int oldest_item;
447         int result;
448         char string[BCTEXTLEN];
450 // Delete extra indexes
451         fs.set_filter("*.idx");
452         fs.complete_path(preferences->index_directory);
453         fs.update(preferences->index_directory);
454 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
456 // Eliminate directories
457         result = 1;
458         while(result)
459         {
460                 result = 0;
461                 for(int i = 0; i < fs.dir_list.total && !result; i++)
462                 {
463                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
464                         if(!fs.is_dir(string))
465                         {
466                                 delete fs.dir_list.values[i];
467                                 fs.dir_list.remove_number(i);
468                                 result = 1;
469                         }
470                 }
471         }
472         total_excess = fs.dir_list.total - preferences->index_count;
474 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
475         while(total_excess > 0)
476         {
477 // Get oldest
478                 for(int i = 0; i < fs.dir_list.total; i++)
479                 {
480                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
482                         if(i == 0 || fs.get_date(string) <= oldest)
483                         {
484                                 oldest = fs.get_date(string);
485                                 oldest_item = i;
486                         }
487                 }
489                 fs.join_names(string, preferences->index_directory, fs.dir_list.values[oldest_item]->name);
490                 if(remove(string))
491                         perror("delete_indexes");
492                 delete fs.dir_list.values[oldest_item];
493                 fs.dir_list.remove_number(oldest_item);
494                 total_excess--;
495         }
498 void MWindow::init_awindow()
500         awindow = new AWindow(this);
501         awindow->create_objects();
504 void MWindow::init_theme()
506         theme = 0;
508         for(int i = 0; i < plugindb->total; i++)
509         {
510                 if(plugindb->values[i]->theme &&
511                         !strcasecmp(preferences->theme, plugindb->values[i]->title))
512                 {
513                         PluginServer plugin = *plugindb->values[i];
514                         plugin.open_plugin(0, preferences, 0, 0, -1);
515                         theme = plugin.new_theme();
516                         theme->mwindow = this;
517                         strcpy(theme->path, plugin.path);
518                         plugin.close_plugin();
519                 }
520         }
522         if(!theme)
523         {
524                 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
525                 exit(1);
526         }
528 // Load user images
529         theme->initialize();
530 // Load images which may have been forgotten
531         theme->Theme::initialize();
533         theme->check_used();
536 void MWindow::init_edl()
538         edl = new EDL;
539         edl->create_objects();
540     edl->load_defaults(defaults);
541         edl->create_default_tracks();
542         edl->tracks->update_y_pixels(theme);
545 void MWindow::init_compositor()
547         cwindow = new CWindow(this);
548     cwindow->create_objects();
551 void MWindow::init_levelwindow()
553         lwindow = new LevelWindow(this);
554         lwindow->create_objects();
557 void MWindow::init_viewer()
559         vwindow = new VWindow(this);
560         vwindow->load_defaults();
561         vwindow->create_objects();
564 void MWindow::init_cache()
566         audio_cache = new CICache(edl, preferences, plugindb);
567         video_cache = new CICache(edl, preferences, plugindb);
570 void MWindow::init_channeldb()
572         channeldb_buz->load("channeldb_buz");
573         channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
576 void MWindow::init_menus()
578         char string[BCTEXTLEN];
580         // Color Models
581         cmodel_to_text(string, BC_RGB888);
582         colormodels.append(new ColormodelItem(string, BC_RGB888));
583         cmodel_to_text(string, BC_RGBA8888);
584         colormodels.append(new ColormodelItem(string, BC_RGBA8888));
585 //      cmodel_to_text(string, BC_RGB161616);
586 //      colormodels.append(new ColormodelItem(string, BC_RGB161616));
587 //      cmodel_to_text(string, BC_RGBA16161616);
588 //      colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
589         cmodel_to_text(string, BC_RGB_FLOAT);
590         colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
591         cmodel_to_text(string, BC_RGBA_FLOAT);
592         colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
593         cmodel_to_text(string, BC_YUV888);
594         colormodels.append(new ColormodelItem(string, BC_YUV888));
595         cmodel_to_text(string, BC_YUVA8888);
596         colormodels.append(new ColormodelItem(string, BC_YUVA8888));
597         cmodel_to_text(string, BC_YUV161616);
598         colormodels.append(new ColormodelItem(string, BC_YUV161616));
599         cmodel_to_text(string, BC_YUVA16161616);
600         colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
602 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
603                            interlace_project_modes.append(new InterlacemodeItem(string, x));
605 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
606                            interlace_asset_modes.append(new InterlacemodeItem(string, x));
608 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
609                            interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
611         // Interlacing Modes
612         ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
614         ILACEASSETMODELISTADD(BC_ILACE_MODE_ODDLEADS);
615         ILACEPROJECTMODELISTADD(BC_ILACE_MODE_ODDLEADS);
617         ILACEASSETMODELISTADD(BC_ILACE_MODE_EVENLEADS);
618         ILACEPROJECTMODELISTADD(BC_ILACE_MODE_EVENLEADS);
620         ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
621         ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
623         // Interlacing Fixing Methods
624         ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
625         ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
626         ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
629 void MWindow::init_indexes()
631         mainindexes = new MainIndexes(this);
632         mainindexes->start_loop();
635 void MWindow::init_gui()
637         gui = new MWindowGUI(this);
638         gui->create_objects();
639         gui->load_defaults(defaults);
642 void MWindow::init_signals()
644         sighandler = new SigHandler;
645         sighandler->initialize();
646 ENABLE_BUFFER
649 void MWindow::init_render()
651         render = new Render(this);
652 //      renderlist = new Render(this);
653         batch_render = new BatchRenderThread(this);
656 void MWindow::init_brender()
658         if(preferences->use_brender && !brender)
659         {
660                 brender_lock->lock("MWindow::init_brender 1");
661                 brender = new BRender(this);
662                 brender->initialize();
663                 session->brender_end = 0;
664                 brender_lock->unlock();
665         }
666         else
667         if(!preferences->use_brender && brender)
668         {
669                 brender_lock->lock("MWindow::init_brender 2");
670                 delete brender;
671                 brender = 0;
672                 session->brender_end = 0;
673                 brender_lock->unlock();
674         }
675         if(brender) brender->restart(edl);
678 void MWindow::restart_brender()
680 //printf("MWindow::restart_brender 1\n");
681         if(brender) brender->restart(edl);
684 void MWindow::stop_brender()
686         if(brender) brender->stop();
689 int MWindow::brender_available(int position)
691         int result = 0;
692         brender_lock->lock("MWindow::brender_available 1");
693         if(brender)
694         {
695                 if(brender->map_valid)
696                 {
697                         brender->map_lock->lock("MWindow::brender_available 2");
698                         if(position < brender->map_size &&
699                                 position >= 0)
700                         {
701 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
702                                 if(brender->map[position] == BRender::RENDERED)
703                                         result = 1;
704                         }
705                         brender->map_lock->unlock();
706                 }
707         }
708         brender_lock->unlock();
709         return result;
712 void MWindow::set_brender_start()
714         edl->session->brender_start = edl->local_session->get_selectionstart();
715         restart_brender();
716         gui->canvas->draw_overlays();
717         gui->canvas->flash();
722 int MWindow::load_filenames(ArrayList<char*> *filenames, 
723         int load_mode,
724         int update_filename,
725         char *reel_name,
726         int reel_number,
727         int overwrite_reel)
729 TRACE("MWindow::load_filenames 1");
730         ArrayList<EDL*> new_edls;
731         ArrayList<Asset*> new_assets;
733 // Need to stop playback since tracking depends on the EDL not getting
734 // deleted.
735         cwindow->playback_engine->que->send_command(STOP,
736                 CHANGE_NONE, 
737                 0,
738                 0);
739         vwindow->playback_engine->que->send_command(STOP,
740                 CHANGE_NONE, 
741                 0,
742                 0);
743         cwindow->playback_engine->interrupt_playback(0);
744         vwindow->playback_engine->interrupt_playback(0);
748 // Define new_edls and new_assets to load
749         int result = 0;
750         for(int i = 0; i < filenames->total; i++)
751         {
752 // Get type of file
753                 File *new_file = new File;
754                 Asset *new_asset = new Asset(filenames->values[i]);
755                 EDL *new_edl = new EDL;
756                 char string[BCTEXTLEN];
758 // Set reel name and number for the asset
759 // If the user wants to overwrite the last used reel number for the clip,
760 // we have to rebuild the index for the file
762                 if(overwrite_reel)
763                 {
764                         char source_filename[BCTEXTLEN];
765                         char index_filename[BCTEXTLEN];
766                         
767                         strcpy(new_asset->reel_name, reel_name);
768                         new_asset->reel_number = reel_number;
770                         IndexFile::get_index_filename(source_filename,
771                                 preferences->index_directory,
772                                 index_filename,
773                                 new_asset->path);
774                         remove(index_filename);
775                         new_asset->index_status = INDEX_NOTTESTED;
776                 }
777                 
778                 new_edl->create_objects();
779                 new_edl->copy_session(edl);
781                 sprintf(string, "Loading %s", new_asset->path);
782                 gui->show_message(string, BLACK);
783                 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
785                 switch(result)
786                 {
787 // Convert media file to EDL
788                         case FILE_OK:
789                                 if(load_mode != LOAD_RESOURCESONLY)
790                                 {
791                                         asset_to_edl(new_edl, new_asset);
792                                         new_edls.append(new_edl);
793                                         delete new_asset;
794                                 }
795                                 else
796                                 {
797                                         new_assets.append(new_asset);
798                                 }
800 // Set filename to nothing for assets since save EDL would overwrite them.
801                                 if(load_mode == LOAD_REPLACE || 
802                                         load_mode == LOAD_REPLACE_CONCATENATE)
803                                 {
804                                         set_filename("");
805 // Reset timeline position
806                                         new_edl->local_session->view_start = 0;
807                                         new_edl->local_session->track_start = 0;
808                                 }
809                                 result = 0;
810                                 break;
812 // File not found
813                         case FILE_NOT_FOUND:
814                                 sprintf(string, _("Failed to open %s"), new_asset->path);
815                                 gui->show_message(string, RED);
816                                 result = 1;
817                                 break;
819 // Unknown format
820                         case FILE_UNRECOGNIZED_CODEC:
821                         {
822 // Test index file
823                                 IndexFile indexfile(this);
824                                 result = indexfile.open_index(this, new_asset);
825                                 if(!result)
826                                 {
827                                         indexfile.close_index();
828                                 }
830 // Test existing EDLs
831                                 if(result)
832                                 {
833                                         for(int j = 0; j < new_edls.total + 1; j++)
834                                         {
835                                                 Asset *old_asset;
836                                                 if(j == new_edls.total)
837                                                 {
838                                                         if(old_asset = edl->assets->get_asset(new_asset->path))
839                                                         {
840                                                                 *new_asset = *old_asset;
841                                                                 result = 0;
842                                                         }
843                                                 }
844                                                 else
845                                                 {
846                                                         if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
847                                                         {
848                                                                 *new_asset = *old_asset;
849                                                                 result = 0;
850                                                         }
851                                                 }
852                                         }
853                                 }
855 // Prompt user
856                                 if(result)
857                                 {
858                                         char string[BCTEXTLEN];
859                                         FileSystem fs;
860                                         fs.extract_name(string, new_asset->path);
862                                         strcat(string, _("'s format couldn't be determined."));
863                                         new_asset->audio_data = 1;
864                                         new_asset->format = FILE_PCM;
865                                         new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
866                                         new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
867                                         new_asset->bits = defaults->get("AUDIO_BITS", 16);
868                                         new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
869                                         new_asset->signed_ = defaults->get("SIGNED_", 1);
870                                         new_asset->header = defaults->get("HEADER", 0);
872                                         FileFormat fwindow(this);
873                                         fwindow.create_objects(new_asset, string);
874                                         result = fwindow.run_window();
876                                         defaults->update("AUDIO_CHANNELS", new_asset->channels);
877                                         defaults->update("SAMPLE_RATE", new_asset->sample_rate);
878                                         defaults->update("AUDIO_BITS", new_asset->bits);
879                                         defaults->update("BYTE_ORDER", new_asset->byte_order);
880                                         defaults->update("SIGNED_", new_asset->signed_);
881                                         defaults->update("HEADER", new_asset->header);
882                                         save_defaults();
883                                 }
885 // Append to list
886                                 if(!result)
887                                 {
888 // Recalculate length
889                                         delete new_file;
890                                         new_file = new File;
891                                         result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
893                                         if(load_mode != LOAD_RESOURCESONLY)
894                                         {
895                                                 asset_to_edl(new_edl, new_asset);
896                                                 new_edls.append(new_edl);
897                                                 delete new_asset;
898                                         }
899                                         else
900                                         {
901                                                 new_assets.append(new_asset);
902                                         }
903                                 }
904                                 else
905                                 {
906                                         result = 1;
907                                 }
908                                 break;
909                         }
911                         case FILE_IS_XML:
912                         {
913                                 FileXML xml_file;
914                                 xml_file.read_from_file(filenames->values[i]);
915 // Load EDL for pasting
916                                 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
917                                 test_plugins(new_edl, filenames->values[i]);
919 // We don't want a valid reel name/number for projects
920                                 strcpy(new_asset->reel_name, "");
921                                 reel_number = -1;
923                                 if(load_mode == LOAD_REPLACE || 
924                                         load_mode == LOAD_REPLACE_CONCATENATE)
925                                 {
926                                         strcpy(session->filename, filenames->values[i]);
927                                         strcpy(new_edl->local_session->clip_title, filenames->values[i]);
928                                         if(update_filename)
929                                                 set_filename(new_edl->local_session->clip_title);
930                                 }
932                                 new_edls.append(new_edl);
933                                 result = 0;
934                                 break;
935                         }
936                 }
938                 if(result)
939                 {
940                         delete new_edl;
941                         delete new_asset;
942                 }
944                 delete new_file;
945         }
949         if(!result) gui->statusbar->default_message();
958 // Paste them.
959 // Don't back up here.
960         if(new_edls.total)
961         {
962 // For pasting, clear the active region
963                 if(load_mode == LOAD_PASTE)
964                 {
965                         double start = edl->local_session->get_selectionstart();
966                         double end = edl->local_session->get_selectionend();
967                         if(!EQUIV(start, end))
968                                 edl->clear(start, 
969                                         end,
970                                         edl->session->labels_follow_edits,
971                                         edl->session->plugins_follow_edits);
972                 }
974                 paste_edls(&new_edls, 
975                         load_mode,
976                         0,
977                         -1,
978                         edl->session->labels_follow_edits, 
979                         edl->session->plugins_follow_edits);
980         }
988         if(new_assets.total)
989         {
990                 for(int i = 0; i < new_assets.total; i++)
991                 {
992                         mainindexes->add_next_asset(new_assets.values[i]);
993                         edl->assets->update(new_assets.values[i]);
994                 }
997 // Start examining next batch of index files
998                 mainindexes->start_build();
999         }
1001 TRACE("MWindow::load_filenames 100");
1002         update_project(load_mode);
1003 TRACE("MWindow::load_filenames 110");
1005 //printf("MWindow::load_filenames 9\n");
1006 //sleep(10);
1008         new_edls.remove_all_objects();
1009         new_assets.remove_all_objects();
1010 //printf("MWindow::load_filenames 10 %d\n", edl->session->audio_module_fragment);
1012         if(load_mode == LOAD_REPLACE ||
1013                 load_mode == LOAD_REPLACE_CONCATENATE)
1014                 session->changes_made = 0;
1016 UNTRACE
1017         return 0;
1023 void MWindow::test_plugins(EDL *new_edl, char *path)
1025 // Do a check weather plugins exist
1026         for(Track *track = new_edl->tracks->first; track; track = track->next)
1027         {
1028                 for(int k = 0; k < track->plugin_set.total; k++)
1029                 {
1030                         PluginSet *plugin_set = track->plugin_set.values[k];
1031                         for(Plugin *plugin = (Plugin*)plugin_set->first; 
1032                         plugin; 
1033                         plugin = (Plugin*)plugin->next)
1034                         {
1035                                 if(plugin->plugin_type == PLUGIN_STANDALONE)
1036                                 {
1037                                         // ok we need to find it in plugindb
1038                                         int plugin_found = 0;
1039                                         for(int j = 0; j < plugindb->total; j++)
1040                                         {
1041                                                 PluginServer *server = plugindb->values[j];
1042                                                 if(!strcasecmp(server->title, plugin->title) &&
1043                                                         ((track->data_type == TRACK_AUDIO && server->audio) ||
1044                                                         (track->data_type == TRACK_VIDEO && server->video)) &&
1045                                                         (!server->transition))
1046                                                         plugin_found = 1;
1047                                         }
1048                                         if (!plugin_found) 
1049                                         {
1050                                                 printf("\nWARNING: The plugin '%s' named in file '%s' is not part of your installation of Cinelerra. This means project will not be rendered as it was meant and it might result in Cinelerra crashing.\n", plugin->title, path); 
1051                                         }
1052                                 }
1053                         }
1054                 }
1055                 for(Edit *edit = (Edit*)track->edits->first; 
1056                 edit; 
1057                 edit = (Edit*)edit->next)
1058                 {
1059                         if (edit->transition)
1060                         {
1061                                 // ok we need to find transition in plugindb
1062                                 int transition_found = 0;
1063                                 for(int j = 0; j < plugindb->total; j++)
1064                                 {
1065                                         PluginServer *server = plugindb->values[j];
1066                                         if(!strcasecmp(server->title, edit->transition->title) &&
1067                                                 ((track->data_type == TRACK_AUDIO && server->audio) ||
1068                                                 (track->data_type == TRACK_VIDEO && server->video)) &&
1069                                                 (server->transition))
1070                                                 transition_found = 1;
1071                                 }
1072                                 if (!transition_found) 
1073                                 {
1074                                         printf("\nWARNING: The transition '%s' named in file '%s' is not part of your installation of Cinelerra. This means project will not be rendered as it was meant and it might result in Cinelerra crashing.\n", edit->transition->title, path); 
1075                                 }
1076                         }
1077                 }
1078         }
1086 void MWindow::create_objects(int want_gui, 
1087         int want_new,
1088         char *config_path)
1090         char string[BCTEXTLEN];
1091         FileSystem fs;
1092         edl = 0;
1095         show_splash();
1097 // For some reason, init_signals must come after show_splash or the signals won't
1098 // get trapped.
1099         init_signals();
1102         init_menus();
1103 TRACE("MWindow::create_objects 1");
1104         init_defaults(defaults, config_path);
1105 TRACE("MWindow::create_objects 2");
1106         init_preferences();
1107 TRACE("MWindow::create_objects 3");
1108         init_plugins(preferences, plugindb, splash_window);
1109         if(splash_window) splash_window->operation->update(_("Initializing GUI"));
1110 TRACE("MWindow::create_objects 4");
1111         init_theme();
1112 // Default project created here
1113 TRACE("MWindow::create_objects 5");
1114         init_edl();
1116 TRACE("MWindow::create_objects 6");
1117         init_awindow();
1118 TRACE("MWindow::create_objects 7");
1119         init_compositor();
1120 TRACE("MWindow::create_objects 8");
1121         init_levelwindow();
1122 TRACE("MWindow::create_objects 9");
1123         init_viewer();
1124 TRACE("MWindow::create_objects 10");
1125         init_cache();
1126 TRACE("MWindow::create_objects 11");
1127         init_indexes();
1128 TRACE("MWindow::create_objects 12");
1129         init_channeldb();
1130 TRACE("MWindow::create_objects 13");
1132         init_gui();
1133 TRACE("MWindow::create_objects 14");
1134         init_render();
1135         init_brender();
1136         mainprogress = new MainProgress(this, gui);
1137         undo = new MainUndo(this);
1139         plugin_guis = new ArrayList<PluginServer*>;
1141 TRACE("MWindow::create_objects 15");
1142         if(session->show_vwindow) vwindow->gui->show_window();
1143         if(session->show_cwindow) cwindow->gui->show_window();
1144         if(session->show_awindow) awindow->gui->show_window();
1145         if(session->show_lwindow) lwindow->gui->show_window();
1146 TRACE("MWindow::create_objects 16");
1148 //      vwindow->start();
1149 //      awindow->start();
1150 //      cwindow->start();
1151 //      lwindow->start();
1152 //printf("MWindow::create_objects 1");
1154         gui->mainmenu->load_defaults(defaults);
1155 TRACE("MWindow::create_objects 17");
1156         gui->mainmenu->update_toggles();
1157 TRACE("MWindow::create_objects 18");
1158         gui->patchbay->update();
1159 TRACE("MWindow::create_objects 19");
1160         gui->canvas->draw();
1161 TRACE("MWindow::create_objects 20");
1162         gui->cursor->draw();
1163 TRACE("MWindow::create_objects 21");
1164         gui->raise_window();
1165 TRACE("MWindow::create_objects 22");
1166         gui->show_window();
1167 TRACE("MWindow::create_objects 23");
1169         hide_splash();
1170 UNTRACE
1174 void MWindow::show_splash()
1176 #include "data/heroine_logo12_png.h"
1177         VFrame *frame = new VFrame(heroine_logo12_png);
1178         BC_DisplayInfo display_info;
1179         splash_window = new SplashGUI(frame, 
1180                 display_info.get_root_w() / 2 - frame->get_w() / 2,
1181                 display_info.get_root_h() / 2 - frame->get_h() / 2);
1182         splash_window->create_objects();
1185 void MWindow::hide_splash()
1187         if(splash_window)
1188                 delete splash_window;
1189         splash_window = 0;
1193 void MWindow::start()
1195         vwindow->start();
1196         awindow->start();
1197         cwindow->start();
1198         lwindow->start();
1199         gui->run_window();
1202 void MWindow::show_vwindow()
1204         session->show_vwindow = 1;
1205         vwindow->gui->lock_window("MWindow::show_vwindow");
1206         vwindow->gui->show_window();
1207         vwindow->gui->raise_window();
1208         vwindow->gui->flush();
1209         vwindow->gui->unlock_window();
1210         gui->mainmenu->show_vwindow->set_checked(1);
1213 void MWindow::show_awindow()
1215         session->show_awindow = 1;
1216         awindow->gui->lock_window("MWindow::show_awindow");
1217         awindow->gui->show_window();
1218         awindow->gui->raise_window();
1219         awindow->gui->flush();
1220         awindow->gui->unlock_window();
1221         gui->mainmenu->show_awindow->set_checked(1);
1224 void MWindow::show_cwindow()
1226         session->show_cwindow = 1;
1227         cwindow->gui->lock_window("MWindow::show_cwindow");
1228         cwindow->gui->show_window();
1229         cwindow->gui->raise_window();
1230         cwindow->gui->flush();
1231         cwindow->gui->unlock_window();
1232         gui->mainmenu->show_cwindow->set_checked(1);
1235 void MWindow::show_lwindow()
1237         session->show_lwindow = 1;
1238         lwindow->gui->lock_window("MWindow::show_lwindow");
1239         lwindow->gui->show_window();
1240         lwindow->gui->raise_window();
1241         lwindow->gui->flush();
1242         lwindow->gui->unlock_window();
1243         gui->mainmenu->show_lwindow->set_checked(1);
1246 void MWindow::tile_windows()
1248         session->default_window_positions();
1249         gui->default_positions();
1252 void MWindow::toggle_loop_playback()
1254         edl->local_session->loop_playback = !edl->local_session->loop_playback;
1255         set_loop_boundaries();
1256         save_backup();
1258         gui->canvas->draw_overlays();
1259         gui->canvas->flash();
1260         sync_parameters(CHANGE_PARAMS);
1263 void MWindow::set_titles(int value)
1265         edl->session->show_titles = value;
1266         trackmovement(edl->local_session->track_start);
1269 void MWindow::set_auto_keyframes(int value)
1271         gui->lock_window("MWindow::set_auto_keyframes");
1272         edl->session->auto_keyframes = value;
1273         gui->mbuttons->edit_panel->keyframe->update(value);
1274         gui->flush();
1275         gui->unlock_window();
1276         cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1277         cwindow->gui->edit_panel->keyframe->update(value);
1278         cwindow->gui->flush();
1279         cwindow->gui->unlock_window();
1282 int MWindow::set_editing_mode(int new_editing_mode)
1284         gui->lock_window("MWindow::set_editing_mode");
1285         edl->session->editing_mode = new_editing_mode;
1286         gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1287         gui->mbuttons->edit_panel->update();
1288         gui->canvas->update_cursor();
1289         gui->unlock_window();
1290         cwindow->gui->lock_window("MWindow::set_editing_mode");
1291         cwindow->gui->edit_panel->update();
1292         cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1293         cwindow->gui->unlock_window();
1294         return 0;
1298 void MWindow::sync_parameters(int change_type)
1301 // Sync engines which are playing back
1302         if(cwindow->playback_engine->is_playing_back)
1303         {
1304                 if(change_type == CHANGE_PARAMS)
1305                 {
1306 // TODO: block keyframes until synchronization is done
1307                         cwindow->playback_engine->sync_parameters(edl);
1308                 }
1309                 else
1310 // Stop and restart
1311                 {
1312                         int command = cwindow->playback_engine->command->command;
1313                         cwindow->playback_engine->que->send_command(STOP,
1314                                 CHANGE_NONE, 
1315                                 0,
1316                                 0);
1317 // Waiting for tracking to finish would make the restart position more
1318 // accurate but it can't lock the window to stop tracking for some reason.
1319 // Not waiting for tracking gives a faster response but restart position is
1320 // only as accurate as the last tracking update.
1321                         cwindow->playback_engine->interrupt_playback(0);
1322                         cwindow->playback_engine->que->send_command(command,
1323                                         change_type, 
1324                                         edl,
1325                                         1,
1326                                         0);
1327                 }
1328         }
1329         else
1330         {
1331                 cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1332                                                         change_type,
1333                                                         edl,
1334                                                         1);
1335         }
1338 void MWindow::update_caches()
1340         audio_cache->set_edl(edl);
1341         video_cache->set_edl(edl);
1344 void MWindow::show_plugin(Plugin *plugin)
1346         int done = 0;
1347 //printf("MWindow::show_plugin 1\n");
1348         plugin_gui_lock->lock("MWindow::show_plugin");
1349         for(int i = 0; i < plugin_guis->total; i++)
1350         {
1351 // Pointer comparison
1352                 if(plugin_guis->values[i]->plugin == plugin)
1353                 {
1354                         plugin_guis->values[i]->raise_window();
1355                         done = 1;
1356                         break;
1357                 }
1358         }
1360 //printf("MWindow::show_plugin 1\n");
1361         if(!done)
1362         {
1363                 if(!plugin->track)
1364                 {
1365                         printf("MWindow::show_plugin track not defined.\n");
1366                 }
1367                 PluginServer *server = scan_plugindb(plugin->title,
1368                         plugin->track->data_type);
1370 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
1371                 if(server && server->uses_gui)
1372                 {
1373                         PluginServer *gui = plugin_guis->append(new PluginServer(*server));
1374 // Needs mwindow to do GUI
1375                         gui->set_mwindow(this);
1376                         gui->open_plugin(0, preferences, edl, plugin, -1);
1377                         gui->show_gui();
1378                         plugin->show = 1;
1379                 }
1380         }
1381         plugin_gui_lock->unlock();
1382 //printf("MWindow::show_plugin 2\n");
1385 void MWindow::hide_plugin(Plugin *plugin, int lock)
1387         if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
1388         plugin->show = 0;
1389         for(int i = 0; i < plugin_guis->total; i++)
1390         {
1391                 if(plugin_guis->values[i]->plugin == plugin)
1392                 {
1393                         PluginServer *ptr = plugin_guis->values[i];
1394                         plugin_guis->remove(ptr);
1395                         if(lock) plugin_gui_lock->unlock();
1396 // Last command executed in client side close
1397                         delete ptr;
1398                         return;
1399                 }
1400         }
1401         if(lock) plugin_gui_lock->unlock();
1404 void MWindow::hide_plugins()
1406         plugin_gui_lock->lock("MWindow::hide_plugins");
1407         plugin_guis->remove_all_objects();
1408         plugin_gui_lock->unlock();
1411 void MWindow::update_plugin_guis()
1413         plugin_gui_lock->lock("MWindow::update_plugin_guis");
1415         for(int i = 0; i < plugin_guis->total; i++)
1416         {
1417                 plugin_guis->values[i]->update_gui();
1418         }
1419         plugin_gui_lock->unlock();
1422 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
1424         plugin_gui_lock->lock("MWindow::render_plugin_gui");
1425         for(int i = 0; i < plugin_guis->total; i++)
1426         {
1427                 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1428                 {
1429                         plugin_guis->values[i]->render_gui(data);
1430                         break;
1431                 }
1432         }
1433         plugin_gui_lock->unlock();
1436 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
1438         plugin_gui_lock->lock("MWindow::render_plugin_gui");
1439         for(int i = 0; i < plugin_guis->total; i++)
1440         {
1441                 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1442                 {
1443                         plugin_guis->values[i]->render_gui(data, size);
1444                         break;
1445                 }
1446         }
1447         plugin_gui_lock->unlock();
1451 void MWindow::update_plugin_states()
1453         plugin_gui_lock->lock("MWindow::update_plugin_states");
1454         for(int i = 0; i < plugin_guis->total; i++)
1455         {
1456                 int result = 0;
1457 // Get a plugin GUI
1458                 Plugin *src_plugin = plugin_guis->values[i]->plugin;
1459                 PluginServer *src_plugingui = plugin_guis->values[i];
1461 // Search for plugin in EDL.  Only the master EDL shows plugin GUIs.
1462                 for(Track *track = edl->tracks->first; 
1463                         track && !result; 
1464                         track = track->next)
1465                 {
1466                         for(int j = 0; 
1467                                 j < track->plugin_set.total && !result; 
1468                                 j++)
1469                         {
1470                                 PluginSet *plugin_set = track->plugin_set.values[j];
1471                                 for(Plugin *plugin = (Plugin*)plugin_set->first; 
1472                                         plugin && !result; 
1473                                         plugin = (Plugin*)plugin->next)
1474                                 {
1475                                         if(plugin == src_plugin &&
1476                                                 !strcmp(plugin->title, src_plugingui->title)) result = 1;
1477                                 }
1478                         }
1479                 }
1482 // Doesn't exist anymore
1483                 if(!result)
1484                 {
1485                         hide_plugin(src_plugin, 0);
1486                         i--;
1487                 }
1488         }
1489         plugin_gui_lock->unlock();
1493 void MWindow::update_plugin_titles()
1495         for(int i = 0; i < plugin_guis->total; i++)
1496         {
1497                 plugin_guis->values[i]->update_title();
1498         }
1501 int MWindow::asset_to_edl(EDL *new_edl, 
1502         Asset *new_asset, 
1503         RecordLabels *labels)
1505 //printf("MWindow::asset_to_edl 1\n");
1506 //      new_edl->load_defaults(defaults);
1508 // Keep frame rate, sample rate, and output size unchanged.
1509 // These parameters would revert the project if VWindow displayed an asset
1510 // of different size than the project.
1511         if(new_asset->video_data)
1512         {
1513                 new_edl->session->video_tracks = new_asset->layers;
1514 //              new_edl->session->frame_rate = new_asset->frame_rate;
1515 //              new_edl->session->output_w = new_asset->width;
1516 //              new_edl->session->output_h = new_asset->height;
1517         }
1518         else
1519                 new_edl->session->video_tracks = 0;
1526         if(new_asset->audio_data)
1527         {
1528                 new_edl->session->audio_tracks = new_asset->channels;
1529 //              new_edl->session->sample_rate = new_asset->sample_rate;
1530         }
1531         else
1532                 new_edl->session->audio_tracks = 0;
1533 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1535         new_edl->create_default_tracks();
1536 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1538 // Disable drawing if the file format isn't fast enough.
1539 // MPEG is now faster than most other codecs.
1540 //      if(new_asset->format == FILE_MPEG)
1541 //      {
1542 //              for(Track *current = new_edl->tracks->first;
1543 //                      current;
1544 //                      current = NEXT)
1545 //              {
1546 //                      if(current->data_type == TRACK_VIDEO) current->draw = 0;
1547 //              }
1548 //      }
1552 //printf("MWindow::asset_to_edl 3\n");
1553         new_edl->insert_asset(new_asset, 0, 0, labels);
1554 //printf("MWindow::asset_to_edl 3\n");
1560         char string[BCTEXTLEN];
1561         FileSystem fs;
1562         fs.extract_name(string, new_asset->path);
1563 //printf("MWindow::asset_to_edl 3\n");
1565         strcpy(new_edl->local_session->clip_title, string);
1566 //printf("MWindow::asset_to_edl 4 %s\n", string);
1568 //      new_edl->dump();
1569         return 0;
1572 // Reset everything after a load.
1573 void MWindow::update_project(int load_mode)
1575         restart_brender();
1576 //TRACE("MWindow::update_project 1");
1577         edl->tracks->update_y_pixels(theme);
1579 // Draw timeline
1580 //TRACE("MWindow::update_project 2");
1581         update_caches();
1583 TRACE("MWindow::update_project 3");
1584         gui->update(1, 1, 1, 1, 1, 1, 1);
1586 TRACE("MWindow::update_project 4");
1587         cwindow->update(0, 0, 1, 1, 1);
1589 TRACE("MWindow::update_project 5");
1591         if(load_mode == LOAD_REPLACE ||
1592                 load_mode == LOAD_REPLACE_CONCATENATE)
1593         {
1594                 vwindow->change_source();
1595         }
1596         else
1597         {
1598                 vwindow->update(1);
1599         }
1601 TRACE("MWindow::update_project 6");
1603         cwindow->gui->slider->set_position();
1604 TRACE("MWindow::update_project 6.1");
1605         cwindow->gui->timebar->update(1, 1);
1606 TRACE("MWindow::update_project 6.2");
1607         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1608                 CHANGE_ALL,
1609                 edl,
1610                 1);
1612 TRACE("MWindow::update_project 7");
1613         awindow->gui->lock_window("MWindow::update_project");
1614         awindow->gui->update_assets();
1615         awindow->gui->flush();
1616         awindow->gui->unlock_window();
1617         gui->flush();
1618 TRACE("MWindow::update_project 100");
1622 void MWindow::rebuild_indices()
1624         char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
1626         for(int i = 0; i < session->drag_assets->total; i++)
1627         {
1628 //printf("MWindow::rebuild_indices 1 %s\n", session->drag_assets->values[i]->path);
1629 // Erase file
1630                 IndexFile::get_index_filename(source_filename, 
1631                         preferences->index_directory,
1632                         index_filename, 
1633                         session->drag_assets->values[i]->path);
1634                 remove(index_filename);
1635 // Schedule index build
1636                 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
1637                 mainindexes->add_next_asset(session->drag_assets->values[i]);
1638         }
1639         mainindexes->start_build();
1643 void MWindow::save_backup()
1645         FileXML file;
1646         edl->set_project_path(session->filename);
1647         edl->save_xml(plugindb, 
1648                 &file, 
1649                 BACKUP_PATH,
1650                 0,
1651                 0);
1652         file.terminate_string();
1653         char path[BCTEXTLEN];
1654         FileSystem fs;
1655         strcpy(path, BACKUP_PATH);
1656         fs.complete_path(path);
1658         if(file.write_to_file(path))
1659         {
1660                 char string2[256];
1661                 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
1662                 gui->show_message(string2);
1663         }
1667 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
1669         int denominator;
1670         if(!width || !height) return 1;
1671         float fraction = (float)width / height;
1673         for(denominator = 1; 
1674                 denominator < 100 && 
1675                         fabs(fraction * denominator - (int)(fraction * denominator)) > .001; 
1676                 denominator++)
1677                 ;
1679         w = denominator * width / height;
1680         h = denominator;
1681         return 0;
1686 void MWindow::remove_assets_from_project(int push_undo)
1688     if(push_undo) undo->update_undo_before(_("remove assets"), LOAD_ALL);
1690 // Remove from caches
1691         for(int i = 0; i < session->drag_assets->total; i++)
1692         {
1693                 audio_cache->delete_entry(session->drag_assets->values[i]);
1694                 video_cache->delete_entry(session->drag_assets->values[i]);
1695         }
1697 printf("MWindow::remove_assets_from_project 1\n");
1698 video_cache->dump();
1699 audio_cache->dump();
1700 printf("MWindow::remove_assets_from_project 100\n");
1702 // Remove from VWindow.
1703         for(int i = 0; i < session->drag_clips->total; i++)
1704         {
1705                 if(session->drag_clips->values[i] == vwindow->get_edl())
1706                 {
1707                         vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
1708                         vwindow->remove_source();
1709                         vwindow->gui->unlock_window();
1710                 }
1711         }
1712         
1713         for(int i = 0; i < session->drag_assets->total; i++)
1714         {
1715                 if(session->drag_assets->values[i] == vwindow->get_asset())
1716                 {
1717                         vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
1718                         vwindow->remove_source();
1719                         vwindow->gui->unlock_window();
1720                 }
1721         }
1722         
1723         edl->remove_from_project(session->drag_assets);
1724         edl->remove_from_project(session->drag_clips);
1725         save_backup();
1726         if(push_undo) undo->update_undo_after();
1727         restart_brender();
1729         gui->lock_window("MWindow::remove_assets_from_project 3");
1730         gui->update(1,
1731                 1,
1732                 1,
1733                 1,
1734                 0, 
1735                 1,
1736                 0);
1737         gui->unlock_window();
1739         awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
1740         awindow->gui->update_assets();
1741         awindow->gui->flush();
1742         awindow->gui->unlock_window();
1744 // Removes from playback here
1745         sync_parameters(CHANGE_ALL);
1748 void MWindow::remove_assets_from_disk()
1750 // Remove from disk
1751         for(int i = 0; i < session->drag_assets->total; i++)
1752         {
1753                 remove(session->drag_assets->values[i]->path);
1754         }
1756         remove_assets_from_project(1);
1759 void MWindow::dump_plugins()
1761         for(int i = 0; i < plugindb->total; i++)
1762         {
1763                 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
1764                         plugindb->values[i]->audio,
1765                         plugindb->values[i]->video,
1766                         plugindb->values[i]->realtime,
1767                         plugindb->values[i]->transition,
1768                         plugindb->values[i]->theme,
1769                         plugindb->values[i]->title);
1770         }
1797 int MWindow::save_defaults()
1799         gui->save_defaults(defaults);
1800         edl->save_defaults(defaults);
1801         session->save_defaults(defaults);
1802         preferences->save_defaults(defaults);
1804         defaults->save();
1805         return 0;
1808 int MWindow::run_script(FileXML *script)
1810         int result = 0, result2 = 0;
1811         while(!result && !result2)
1812         {
1813                 result = script->read_tag();
1814                 if(!result)
1815                 {
1816                         if(script->tag.title_is("new_project"))
1817                         {
1818 // Run new in immediate mode.
1819 //                              gui->mainmenu->new_project->run_script(script);
1820                         }
1821                         else
1822                         if(script->tag.title_is("record"))
1823                         {
1824 // Run record as a thread.  It is a terminal command.
1825                                 ;
1826 // Will read the complete scipt file without letting record read it if not
1827 // terminated.
1828                                 result2 = 1;
1829                         }
1830                         else
1831                         {
1832                                 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
1833                         }
1834                 }
1835         }
1836         return result2;
1839 // ================================= synchronization
1842 int MWindow::interrupt_indexes()
1844         mainindexes->interrupt_build();
1845         return 0; 
1850 void MWindow::next_time_format()
1852         switch(edl->session->time_format)
1853         {
1854                 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
1855                 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
1856                 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
1857                 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
1858                 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
1859                 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
1860                 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
1861         }
1863         time_format_common();
1866 void MWindow::prev_time_format()
1868         switch(edl->session->time_format)
1869         {
1870                 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
1871                 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
1872                 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
1873                 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
1874                 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
1875                 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
1876                 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
1877         }
1879         time_format_common();
1882 void MWindow::time_format_common()
1884         gui->lock_window("MWindow::next_time_format");
1885         gui->redraw_time_dependancies();
1886         char string[BCTEXTLEN], string2[BCTEXTLEN];
1887         sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
1888         gui->show_message(string, BLACK);
1889         gui->flush();
1890         gui->unlock_window();
1894 int MWindow::set_filename(char *filename)
1896         strcpy(session->filename, filename);
1897         if(gui)
1898         {
1899                 if(filename[0] == 0)
1900                 {
1901                         gui->set_title(PROGRAM_NAME);
1902                 }
1903                 else
1904                 {
1905                         FileSystem dir;
1906                         char string[BCTEXTLEN], string2[BCTEXTLEN];
1907                         dir.extract_name(string, filename);
1908                         sprintf(string2, PROGRAM_NAME ": %s", string);
1909                         gui->set_title(string2);
1910                 }
1911         }
1912         return 0; 
1922 int MWindow::set_loop_boundaries()
1924         double start = edl->local_session->get_selectionstart();
1925         double end = edl->local_session->get_selectionend();
1926         
1927         if(start != 
1928                 end) 
1929         {
1930                 ;
1931         }
1932         else
1933         if(edl->tracks->total_length())
1934         {
1935                 start = 0;
1936                 end = edl->tracks->total_length();
1937         }
1938         else
1939         {
1940                 start = end = 0;
1941         }
1943         if(edl->local_session->loop_playback && start != end)
1944         {
1945                 edl->local_session->loop_start = start;
1946                 edl->local_session->loop_end = end;
1947         }
1948         return 0; 
1957 int MWindow::reset_meters()
1959         cwindow->gui->lock_window("MWindow::reset_meters 1");
1960         cwindow->gui->meters->reset_meters();
1961         cwindow->gui->unlock_window();
1963         vwindow->gui->lock_window("MWindow::reset_meters 2");
1964         vwindow->gui->meters->reset_meters();
1965         vwindow->gui->unlock_window();
1967         lwindow->gui->lock_window("MWindow::reset_meters 3");
1968         lwindow->gui->panel->reset_meters();
1969         lwindow->gui->unlock_window();
1971         gui->lock_window("MWindow::reset_meters 4");
1972         gui->patchbay->reset_meters();
1973         gui->unlock_window();
1974         return 0;