r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mwindow.C
blob508665b86ecc2c48095d1c6a294e328c67c0c1d2
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 "transportque.h"
65 #include "vframe.h"
66 #include "videodevice.inc"
67 #include "videowindow.h"
68 #include "vplayback.h"
69 #include "vwindowgui.h"
70 #include "vwindow.h"
71 #include "zoombar.h"
73 #include <string.h>
77 extern "C"
83 // Hack for libdv to remove glib dependancy
85 // void
86 // g_log (const char    *log_domain,
87 //        int  log_level,
88 //        const char    *format,
89 //        ...)
90 // {
91 // }
92 // 
93 // void
94 // g_logv (const char    *log_domain,
95 //        int  log_level,
96 //        const char    *format,
97 //        ...)
98 // {
99 // }
100 // 
103 // Hack for XFree86 4.1.0
105 int atexit(void (*function)(void))
107         return 0;
118 MWindow::MWindow()
120         plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
121         brender_lock = new Mutex("MWindow::brender_lock");
122         brender = 0;
123         session = 0;
124         channeldb_buz = new ChannelDB;
125         channeldb_v4l2jpeg = new ChannelDB;
128 MWindow::~MWindow()
130         brender_lock->lock("MWindow::~MWindow");
131         if(brender) delete brender;
132         brender = 0;
133         brender_lock->unlock();
134         delete brender_lock;
136         delete mainindexes;
138 TRACE("MWindow::~MWindow 1\n");
139         clean_indexes();
140 TRACE("MWindow::~MWindow 2\n");
142         save_defaults();
143 TRACE("MWindow::~MWindow 3\n");
144 // Give up and go to a movie
145         exit(0);
147 TRACE("MWindow::~MWindow 4\n");
148         delete mainprogress;
149         delete audio_cache;             // delete the cache after the assets
150         delete video_cache;             // delete the cache after the assets
151         if(gui) delete gui;
152         delete undo;
153         delete preferences;
154         delete defaults;
155         delete render;
156 //      delete renderlist;
157         delete awindow;
158         delete vwindow;
159         delete cwindow;
160         delete lwindow;
161         plugin_guis->remove_all_objects();
162         delete plugin_guis;
163         delete plugin_gui_lock;
166 void MWindow::init_defaults(Defaults* &defaults, char *config_path)
168         char path[BCTEXTLEN];
169 // Use user supplied path
170         if(config_path[0])
171         {
172                 strcpy(path, config_path);
173         }
174         else
175         {
176 // set the .bcast path
177                 FileSystem fs;
179                 sprintf(path, "%s", BCASTDIR);
180                 fs.complete_path(path);
181                 if(fs.is_dir(path)) 
182                 {
183                         fs.create_dir(path); 
184                 }
186 // load the defaults
187                 strcat(path, "Cinelerra_rc");
188         }
190         defaults = new Defaults(path);
191         defaults->load();
194 void MWindow::init_plugin_path(Preferences *preferences, 
195         ArrayList<PluginServer*>* &plugindb,
196         FileSystem *fs,
197         SplashGUI *splash_window,
198         int *counter)
200         int result = 0;
201         PluginServer *newplugin;
203         if(!result)
204         {
205                 for(int i = 0; i < fs->dir_list.total; i++)
206                 {
207                         char path[BCTEXTLEN];
208                         strcpy(path, fs->dir_list.values[i]->path);
210 // File is a directory
211                         if(!fs->is_dir(path))
212                         {
213                                 continue;
214                         }
215                         else
216                         {
217 // Try to query the plugin
218                                 fs->complete_path(path);
219 //printf("MWindow::init_plugin_path %s\n", path);
220                                 PluginServer *new_plugin = new PluginServer(path);
221                                 int result = new_plugin->open_plugin(1, preferences, 0, 0, -1);
223                                 if(!result)
224                                 {
225                                         plugindb->append(new_plugin);
226                                         new_plugin->close_plugin();
227                                         if(splash_window)
228                                                 splash_window->operation->update(_(new_plugin->title));
229                                 }
230                                 else
231                                 if(result == PLUGINSERVER_IS_LAD)
232                                 {
233                                         delete new_plugin;
234 // Open LAD subplugins
235                                         int id = 0;
236                                         do
237                                         {
238                                                 new_plugin = new PluginServer(path);
239                                                 result = new_plugin->open_plugin(1,
240                                                         preferences,
241                                                         0,
242                                                         0,
243                                                         id);
244                                                 id++;
245                                                 if(!result)
246                                                 {
247                                                         plugindb->append(new_plugin);
248                                                         new_plugin->close_plugin();
249                                                         if(splash_window)
250                                                                 splash_window->operation->update(_(new_plugin->title));
251                                                 }
252                                         }while(!result);
253                                 }
254                                 else
255                                 {
256 // Plugin failed to open
257                                         delete new_plugin;
258                                 }
259                         }
260                         if(splash_window) splash_window->progress->update((*counter)++);
261                 }
262         }
265 void MWindow::init_plugins(Preferences *preferences, 
266         ArrayList<PluginServer*>* &plugindb,
267         SplashGUI *splash_window)
269         plugindb = new ArrayList<PluginServer*>;
273         FileSystem cinelerra_fs;
274         ArrayList<FileSystem*> lad_fs;
275         int result = 0;
277 // Get directories
278         cinelerra_fs.set_filter("[*.plugin][*.so]");
279         result = cinelerra_fs.update(preferences->global_plugin_dir);
281         if(result)
282         {
283                 fprintf(stderr, 
284                         _("MWindow::init_plugins: couldn't open %s directory\n"),
285                         preferences->global_plugin_dir);
286         }
288 // Parse LAD environment variable
289         char *env = getenv("LADSPA_PATH");
290         if(env)
291         {
292                 char string[BCTEXTLEN];
293                 char *ptr1 = env;
294                 while(ptr1)
295                 {
296                         char *ptr = strchr(ptr1, ':');
297                         char *end;
298                         if(ptr)
299                         {
300                                 end = ptr;
301                         }
302                         else
303                         {
304                                 end = env + strlen(env);
305                         }
307                         if(end > ptr1)
308                         {
309                                 int len = end - ptr1;
310                                 memcpy(string, ptr1, len);
311                                 string[len] = 0;
314                                 FileSystem *fs = new FileSystem;
315                                 lad_fs.append(fs);
316                                 fs->set_filter("*.so");
317                                 result = fs->update(string);
319                                 if(result)
320                                 {
321                                         fprintf(stderr, 
322                                                 _("MWindow::init_plugins: couldn't open %s directory\n"),
323                                                 string);
324                                 }
325                         }
327                         if(ptr)
328                                 ptr1 = ptr + 1;
329                         else
330                                 ptr1 = ptr;
331                 };
332         }
334         int total = cinelerra_fs.total_files();
335         int counter = 0;
336         for(int i = 0; i < lad_fs.total; i++)
337                 total += lad_fs.values[i]->total_files();
338         if(splash_window) splash_window->progress->update_length(total);
340 // Cinelerra
341 #ifndef DO_STATIC
342         init_plugin_path(preferences,
343                 plugindb,
344                 &cinelerra_fs,
345                 splash_window,
346                 &counter);
347 #else
348 // Call automatically generated routine to get plugins
349 #endif
351 // LAD
352         for(int i = 0; i < lad_fs.total; i++)
353                 init_plugin_path(preferences,
354                         plugindb,
355                         lad_fs.values[i],
356                         splash_window,
357                         &counter);
359         lad_fs.remove_all_objects();
362 void MWindow::delete_plugins()
364         for(int i = 0; i < plugindb->total; i++)
365         {
366                 delete plugindb->values[i];
367         }
368         delete plugindb;
371 void MWindow::create_plugindb(int do_audio, 
372                 int do_video, 
373                 int is_realtime, 
374                 int is_transition,
375                 int is_theme,
376                 ArrayList<PluginServer*> &plugindb)
378 // Get plugins
379         for(int i = 0; i < this->plugindb->total; i++)
380         {
381                 PluginServer *current = this->plugindb->values[i];
383                 if(current->audio == do_audio &&
384                         current->video == do_video &&
385                         (current->realtime == is_realtime || is_realtime < 0) &&
386                         current->transition == is_transition &&
387                         current->theme == is_theme)
388                         plugindb.append(current);
389         }
391 // Alphabetize list by title
392         int done = 0;
393         while(!done)
394         {
395                 done = 1;
396                 
397                 for(int i = 0; i < plugindb.total - 1; i++)
398                 {
399                         PluginServer *value1 = plugindb.values[i];
400                         PluginServer *value2 = plugindb.values[i + 1];
401                         if(strcmp(value1->title, value2->title) > 0)
402                         {
403                                 done = 0;
404                                 plugindb.values[i] = value2;
405                                 plugindb.values[i + 1] = value1;
406                         }
407                 }
408         }
411 PluginServer* MWindow::scan_plugindb(char *title,
412                 int data_type)
414         if(data_type < 0)
415         {
416                 printf("MWindow::scan_plugindb data_type < 0\n");
417                 return 0;
418         }
420         for(int i = 0; i < plugindb->total; i++)
421         {
422                 PluginServer *server = plugindb->values[i];
423                 if(!strcasecmp(server->title, title) &&
424                 ((data_type == TRACK_AUDIO && server->audio) ||
425                 (data_type == TRACK_VIDEO && server->video))) 
426                         return plugindb->values[i];
427         }
428         return 0;
431 void MWindow::init_preferences()
433         preferences = new Preferences;
434         preferences->load_defaults(defaults);
435         session = new MainSession(this);
436         session->load_defaults(defaults);
439 void MWindow::clean_indexes()
441         FileSystem fs;
442         int total_excess;
443         long oldest;
444         int oldest_item;
445         int result;
446         char string[BCTEXTLEN];
448 // Delete extra indexes
449         fs.set_filter("*.idx");
450         fs.complete_path(preferences->index_directory);
451         fs.update(preferences->index_directory);
452 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
454 // Eliminate directories
455         result = 1;
456         while(result)
457         {
458                 result = 0;
459                 for(int i = 0; i < fs.dir_list.total && !result; i++)
460                 {
461                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
462                         if(!fs.is_dir(string))
463                         {
464                                 delete fs.dir_list.values[i];
465                                 fs.dir_list.remove_number(i);
466                                 result = 1;
467                         }
468                 }
469         }
470         total_excess = fs.dir_list.total - preferences->index_count;
472 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
473         while(total_excess > 0)
474         {
475 // Get oldest
476                 for(int i = 0; i < fs.dir_list.total; i++)
477                 {
478                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
480                         if(i == 0 || fs.get_date(string) <= oldest)
481                         {
482                                 oldest = fs.get_date(string);
483                                 oldest_item = i;
484                         }
485                 }
487                 fs.join_names(string, preferences->index_directory, fs.dir_list.values[oldest_item]->name);
488                 if(remove(string))
489                         perror("delete_indexes");
490                 delete fs.dir_list.values[oldest_item];
491                 fs.dir_list.remove_number(oldest_item);
492                 total_excess--;
493         }
496 void MWindow::init_awindow()
498         awindow = new AWindow(this);
499         awindow->create_objects();
502 void MWindow::init_theme()
504         theme = 0;
506         for(int i = 0; i < plugindb->total; i++)
507         {
508                 if(plugindb->values[i]->theme &&
509                         !strcasecmp(preferences->theme, plugindb->values[i]->title))
510                 {
511                         PluginServer plugin = *plugindb->values[i];
512                         plugin.open_plugin(0, preferences, 0, 0, -1);
513                         theme = plugin.new_theme();
514                         theme->mwindow = this;
515                         strcpy(theme->path, plugin.path);
516                         plugin.close_plugin();
517                 }
518         }
520         if(!theme)
521         {
522                 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
523                 exit(1);
524         }
526 // Load user images
527         theme->initialize();
528 // Load images which may have been forgotten
529         theme->Theme::initialize();
531         theme->check_used();
534 void MWindow::init_edl()
536         edl = new EDL;
537         edl->create_objects();
538     edl->load_defaults(defaults);
539         edl->create_default_tracks();
540         edl->tracks->update_y_pixels(theme);
543 void MWindow::init_compositor()
545         cwindow = new CWindow(this);
546     cwindow->create_objects();
549 void MWindow::init_levelwindow()
551         lwindow = new LevelWindow(this);
552         lwindow->create_objects();
555 void MWindow::init_viewer()
557         vwindow = new VWindow(this);
558         vwindow->load_defaults();
559         vwindow->create_objects();
562 void MWindow::init_cache()
564         audio_cache = new CICache(edl, preferences, plugindb);
565         video_cache = new CICache(edl, preferences, plugindb);
568 void MWindow::init_channeldb()
570         channeldb_buz->load("channeldb_buz");
571         channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
574 void MWindow::init_menus()
576         char string[BCTEXTLEN];
577         cmodel_to_text(string, BC_RGB888);
578         colormodels.append(new ColormodelItem(string, BC_RGB888));
579         cmodel_to_text(string, BC_RGBA8888);
580         colormodels.append(new ColormodelItem(string, BC_RGBA8888));
581 //      cmodel_to_text(string, BC_RGB161616);
582 //      colormodels.append(new ColormodelItem(string, BC_RGB161616));
583 //      cmodel_to_text(string, BC_RGBA16161616);
584 //      colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
585         cmodel_to_text(string, BC_RGB_FLOAT);
586         colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
587         cmodel_to_text(string, BC_RGBA_FLOAT);
588         colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
589         cmodel_to_text(string, BC_YUV888);
590         colormodels.append(new ColormodelItem(string, BC_YUV888));
591         cmodel_to_text(string, BC_YUVA8888);
592         colormodels.append(new ColormodelItem(string, BC_YUVA8888));
593         cmodel_to_text(string, BC_YUV161616);
594         colormodels.append(new ColormodelItem(string, BC_YUV161616));
595         cmodel_to_text(string, BC_YUVA16161616);
596         colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
599 void MWindow::init_indexes()
601         mainindexes = new MainIndexes(this);
602         mainindexes->start_loop();
605 void MWindow::init_gui()
607         gui = new MWindowGUI(this);
608         gui->create_objects();
609         gui->load_defaults(defaults);
612 void MWindow::init_signals()
614         sighandler = new SigHandler;
615         sighandler->initialize();
616 ENABLE_BUFFER
619 void MWindow::init_render()
621         render = new Render(this);
622 //      renderlist = new Render(this);
623         batch_render = new BatchRenderThread(this);
626 void MWindow::init_brender()
628         if(preferences->use_brender && !brender)
629         {
630                 brender_lock->lock("MWindow::init_brender 1");
631                 brender = new BRender(this);
632                 brender->initialize();
633                 session->brender_end = 0;
634                 brender_lock->unlock();
635         }
636         else
637         if(!preferences->use_brender && brender)
638         {
639                 brender_lock->lock("MWindow::init_brender 2");
640                 delete brender;
641                 brender = 0;
642                 session->brender_end = 0;
643                 brender_lock->unlock();
644         }
645         if(brender) brender->restart(edl);
648 void MWindow::restart_brender()
650 //printf("MWindow::restart_brender 1\n");
651         if(brender) brender->restart(edl);
654 void MWindow::stop_brender()
656         if(brender) brender->stop();
659 int MWindow::brender_available(int position)
661         int result = 0;
662         brender_lock->lock("MWindow::brender_available 1");
663         if(brender)
664         {
665                 if(brender->map_valid)
666                 {
667                         brender->map_lock->lock("MWindow::brender_available 2");
668                         if(position < brender->map_size &&
669                                 position >= 0)
670                         {
671 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
672                                 if(brender->map[position] == BRender::RENDERED)
673                                         result = 1;
674                         }
675                         brender->map_lock->unlock();
676                 }
677         }
678         brender_lock->unlock();
679         return result;
682 void MWindow::set_brender_start()
684         edl->session->brender_start = edl->local_session->get_selectionstart();
685         restart_brender();
686         gui->canvas->draw_overlays();
687         gui->canvas->flash();
692 int MWindow::load_filenames(ArrayList<char*> *filenames, 
693         int load_mode,
694         int update_filename)
696 TRACE("MWindow::load_filenames 1");
697         ArrayList<EDL*> new_edls;
698         ArrayList<Asset*> new_assets;
700 // Need to stop playback since tracking depends on the EDL not getting
701 // deleted.
702         cwindow->playback_engine->que->send_command(STOP,
703                 CHANGE_NONE, 
704                 0,
705                 0);
706         vwindow->playback_engine->que->send_command(STOP,
707                 CHANGE_NONE, 
708                 0,
709                 0);
710         cwindow->playback_engine->interrupt_playback(0);
711         vwindow->playback_engine->interrupt_playback(0);
715 // Define new_edls and new_assets to load
716         int result = 0;
717         for(int i = 0; i < filenames->total; i++)
718         {
719 // Get type of file
720                 File *new_file = new File;
721                 Asset *new_asset = new Asset(filenames->values[i]);
722                 EDL *new_edl = new EDL;
723                 char string[BCTEXTLEN];
725                 new_edl->create_objects();
726                 new_edl->copy_session(edl);
728                 sprintf(string, "Loading %s", new_asset->path);
729                 gui->show_message(string, BLACK);
730                 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
732                 switch(result)
733                 {
734 // Convert media file to EDL
735                         case FILE_OK:
736                                 if(load_mode != LOAD_RESOURCESONLY)
737                                 {
738                                         asset_to_edl(new_edl, new_asset);
739                                         new_edls.append(new_edl);
740                                         delete new_asset;
741                                 }
742                                 else
743                                 {
744                                         new_assets.append(new_asset);
745                                 }
747 // Set filename to nothing for assets since save EDL would overwrite them.
748                                 if(load_mode == LOAD_REPLACE || 
749                                         load_mode == LOAD_REPLACE_CONCATENATE)
750                                 {
751                                         set_filename("");
752 // Reset timeline position
753                                         new_edl->local_session->view_start = 0;
754                                         new_edl->local_session->track_start = 0;
755                                 }
756                                 result = 0;
757                                 break;
759 // File not found
760                         case FILE_NOT_FOUND:
761                                 sprintf(string, _("Failed to open %s"), new_asset->path);
762                                 gui->show_message(string, RED);
763                                 result = 1;
764                                 break;
766 // Unknown format
767                         case FILE_UNRECOGNIZED_CODEC:
768                         {
769 // Test index file
770                                 IndexFile indexfile(this);
771                                 result = indexfile.open_index(this, new_asset);
772                                 if(!result)
773                                 {
774                                         indexfile.close_index();
775                                 }
777 // Test existing EDLs
778                                 if(result)
779                                 {
780                                         for(int j = 0; j < new_edls.total + 1; j++)
781                                         {
782                                                 Asset *old_asset;
783                                                 if(j == new_edls.total)
784                                                 {
785                                                         if(old_asset = edl->assets->get_asset(new_asset->path))
786                                                         {
787                                                                 *new_asset = *old_asset;
788                                                                 result = 0;
789                                                         }
790                                                 }
791                                                 else
792                                                 {
793                                                         if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
794                                                         {
795                                                                 *new_asset = *old_asset;
796                                                                 result = 0;
797                                                         }
798                                                 }
799                                         }
800                                 }
802 // Prompt user
803                                 if(result)
804                                 {
805                                         char string[BCTEXTLEN];
806                                         FileSystem fs;
807                                         fs.extract_name(string, new_asset->path);
809                                         strcat(string, _("'s format couldn't be determined."));
810                                         new_asset->audio_data = 1;
811                                         new_asset->format = FILE_PCM;
812                                         new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
813                                         new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
814                                         new_asset->bits = defaults->get("AUDIO_BITS", 16);
815                                         new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
816                                         new_asset->signed_ = defaults->get("SIGNED_", 1);
817                                         new_asset->header = defaults->get("HEADER", 0);
819                                         FileFormat fwindow(this);
820                                         fwindow.create_objects(new_asset, string);
821                                         result = fwindow.run_window();
823                                         defaults->update("AUDIO_CHANNELS", new_asset->channels);
824                                         defaults->update("SAMPLE_RATE", new_asset->sample_rate);
825                                         defaults->update("AUDIO_BITS", new_asset->bits);
826                                         defaults->update("BYTE_ORDER", new_asset->byte_order);
827                                         defaults->update("SIGNED_", new_asset->signed_);
828                                         defaults->update("HEADER", new_asset->header);
829                                         save_defaults();
830                                 }
832 // Append to list
833                                 if(!result)
834                                 {
835 // Recalculate length
836                                         delete new_file;
837                                         new_file = new File;
838                                         result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
840                                         if(load_mode != LOAD_RESOURCESONLY)
841                                         {
842                                                 asset_to_edl(new_edl, new_asset);
843                                                 new_edls.append(new_edl);
844                                                 delete new_asset;
845                                         }
846                                         else
847                                         {
848                                                 new_assets.append(new_asset);
849                                         }
850                                 }
851                                 else
852                                 {
853                                         result = 1;
854                                 }
855                                 break;
856                         }
858                         case FILE_IS_XML:
859                         {
860                                 FileXML xml_file;
861                                 xml_file.read_from_file(filenames->values[i]);
862 // Load EDL for pasting
863                                 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
864                                 if(load_mode == LOAD_REPLACE || 
865                                         load_mode == LOAD_REPLACE_CONCATENATE)
866                                 {
867                                         strcpy(session->filename, filenames->values[i]);
868                                         strcpy(new_edl->local_session->clip_title, filenames->values[i]);
869                                         if(update_filename)
870                                                 set_filename(new_edl->local_session->clip_title);
871                                 }
873                                 new_edls.append(new_edl);
874                                 result = 0;
875                                 break;
876                         }
877                 }
879                 if(result)
880                 {
881                         delete new_edl;
882                         delete new_asset;
883                 }
885                 delete new_file;
886         }
890         if(!result) gui->statusbar->default_message();
899 // Paste them.
900 // Don't back up here.
901         if(new_edls.total)
902         {
903 // For pasting, clear the active region
904                 if(load_mode == LOAD_PASTE)
905                 {
906                         double start = edl->local_session->get_selectionstart();
907                         double end = edl->local_session->get_selectionend();
908                         if(!EQUIV(start, end))
909                                 edl->clear(start, 
910                                         end,
911                                         edl->session->labels_follow_edits,
912                                         edl->session->plugins_follow_edits);
913                 }
915                 paste_edls(&new_edls, 
916                         load_mode,
917                         0,
918                         -1,
919                         edl->session->labels_follow_edits, 
920                         edl->session->plugins_follow_edits);
921         }
929         if(new_assets.total)
930         {
931                 for(int i = 0; i < new_assets.total; i++)
932                 {
933                         mainindexes->add_next_asset(new_assets.values[i]);
934                         edl->assets->update(new_assets.values[i]);
935                 }
938 // Start examining next batch of index files
939                 mainindexes->start_build();
940         }
942 TRACE("MWindow::load_filenames 100");
943         update_project(load_mode);
944 TRACE("MWindow::load_filenames 110");
946 //printf("MWindow::load_filenames 9\n");
947 //sleep(10);
949         new_edls.remove_all_objects();
950         new_assets.remove_all_objects();
951 //printf("MWindow::load_filenames 10 %d\n", edl->session->audio_module_fragment);
953         if(load_mode == LOAD_REPLACE ||
954                 load_mode == LOAD_REPLACE_CONCATENATE)
955                 session->changes_made = 0;
957 UNTRACE
958         return 0;
961 void MWindow::create_objects(int want_gui, 
962         int want_new,
963         char *config_path)
965         char string[BCTEXTLEN];
966         FileSystem fs;
967         edl = 0;
970         show_splash();
972 // For some reason, init_signals must come after show_splash or the signals won't
973 // get trapped.
974         init_signals();
977         init_menus();
978 TRACE("MWindow::create_objects 1");
979         init_defaults(defaults, config_path);
980 TRACE("MWindow::create_objects 2");
981         init_preferences();
982 TRACE("MWindow::create_objects 3");
983         init_plugins(preferences, plugindb, splash_window);
984         if(splash_window) splash_window->operation->update(_("Initializing GUI"));
985 TRACE("MWindow::create_objects 4");
986         init_theme();
987 // Default project created here
988 TRACE("MWindow::create_objects 5");
989         init_edl();
991 TRACE("MWindow::create_objects 6");
992         init_awindow();
993 TRACE("MWindow::create_objects 7");
994         init_compositor();
995 TRACE("MWindow::create_objects 8");
996         init_levelwindow();
997 TRACE("MWindow::create_objects 9");
998         init_viewer();
999 TRACE("MWindow::create_objects 10");
1000         init_cache();
1001 TRACE("MWindow::create_objects 11");
1002         init_indexes();
1003 TRACE("MWindow::create_objects 12");
1004         init_channeldb();
1005 TRACE("MWindow::create_objects 13");
1007         init_gui();
1008 TRACE("MWindow::create_objects 14");
1009         init_render();
1010         init_brender();
1011         mainprogress = new MainProgress(this, gui);
1012         undo = new MainUndo(this);
1014         plugin_guis = new ArrayList<PluginServer*>;
1016 TRACE("MWindow::create_objects 15");
1017         if(session->show_vwindow) vwindow->gui->show_window();
1018         if(session->show_cwindow) cwindow->gui->show_window();
1019         if(session->show_awindow) awindow->gui->show_window();
1020         if(session->show_lwindow) lwindow->gui->show_window();
1021 TRACE("MWindow::create_objects 16");
1023 //      vwindow->start();
1024 //      awindow->start();
1025 //      cwindow->start();
1026 //      lwindow->start();
1027 //printf("MWindow::create_objects 1");
1029         gui->mainmenu->load_defaults(defaults);
1030 TRACE("MWindow::create_objects 17");
1031         gui->mainmenu->update_toggles();
1032 TRACE("MWindow::create_objects 18");
1033         gui->patchbay->update();
1034 TRACE("MWindow::create_objects 19");
1035         gui->canvas->draw();
1036 TRACE("MWindow::create_objects 20");
1037         gui->cursor->draw();
1038 TRACE("MWindow::create_objects 21");
1039         gui->raise_window();
1040 TRACE("MWindow::create_objects 22");
1041         gui->show_window();
1042 TRACE("MWindow::create_objects 23");
1044         hide_splash();
1045 UNTRACE
1049 void MWindow::show_splash()
1051 #include "data/heroine_logo11_png.h"
1052         VFrame *frame = new VFrame(heroine_logo11_png);
1053         BC_DisplayInfo display_info;
1054         splash_window = new SplashGUI(frame, 
1055                 display_info.get_root_w() / 2 - frame->get_w() / 2,
1056                 display_info.get_root_h() / 2 - frame->get_h() / 2);
1057         splash_window->create_objects();
1060 void MWindow::hide_splash()
1062         if(splash_window)
1063                 delete splash_window;
1064         splash_window = 0;
1068 void MWindow::start()
1070         vwindow->start();
1071         awindow->start();
1072         cwindow->start();
1073         lwindow->start();
1074         gui->run_window();
1077 void MWindow::show_vwindow()
1079         session->show_vwindow = 1;
1080         vwindow->gui->lock_window("MWindow::show_vwindow");
1081         vwindow->gui->show_window();
1082         vwindow->gui->raise_window();
1083         vwindow->gui->flush();
1084         vwindow->gui->unlock_window();
1085         gui->mainmenu->show_vwindow->set_checked(1);
1088 void MWindow::show_awindow()
1090         session->show_awindow = 1;
1091         awindow->gui->lock_window("MWindow::show_awindow");
1092         awindow->gui->show_window();
1093         awindow->gui->raise_window();
1094         awindow->gui->flush();
1095         awindow->gui->unlock_window();
1096         gui->mainmenu->show_awindow->set_checked(1);
1099 void MWindow::show_cwindow()
1101         session->show_cwindow = 1;
1102         cwindow->gui->lock_window("MWindow::show_cwindow");
1103         cwindow->gui->show_window();
1104         cwindow->gui->raise_window();
1105         cwindow->gui->flush();
1106         cwindow->gui->unlock_window();
1107         gui->mainmenu->show_cwindow->set_checked(1);
1110 void MWindow::show_lwindow()
1112         session->show_lwindow = 1;
1113         lwindow->gui->lock_window("MWindow::show_lwindow");
1114         lwindow->gui->show_window();
1115         lwindow->gui->raise_window();
1116         lwindow->gui->flush();
1117         lwindow->gui->unlock_window();
1118         gui->mainmenu->show_lwindow->set_checked(1);
1121 void MWindow::tile_windows()
1123         session->default_window_positions();
1124         gui->default_positions();
1127 void MWindow::toggle_loop_playback()
1129         edl->local_session->loop_playback = !edl->local_session->loop_playback;
1130         set_loop_boundaries();
1131         save_backup();
1133         gui->canvas->draw_overlays();
1134         gui->canvas->flash();
1135         sync_parameters(CHANGE_PARAMS);
1138 void MWindow::set_titles(int value)
1140         edl->session->show_titles = value;
1141         trackmovement(edl->local_session->track_start);
1144 void MWindow::set_auto_keyframes(int value)
1146         gui->lock_window("MWindow::set_auto_keyframes");
1147         edl->session->auto_keyframes = value;
1148         gui->mbuttons->edit_panel->keyframe->update(value);
1149         gui->flush();
1150         gui->unlock_window();
1151         cwindow->gui->lock_window("MWindow::set_auto_keyframes");
1152         cwindow->gui->edit_panel->keyframe->update(value);
1153         cwindow->gui->flush();
1154         cwindow->gui->unlock_window();
1157 int MWindow::set_editing_mode(int new_editing_mode)
1159         gui->lock_window("MWindow::set_editing_mode");
1160         edl->session->editing_mode = new_editing_mode;
1161         gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1162         gui->mbuttons->edit_panel->update();
1163         gui->canvas->update_cursor();
1164         gui->unlock_window();
1165         cwindow->gui->lock_window("MWindow::set_editing_mode");
1166         cwindow->gui->edit_panel->update();
1167         cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1168         cwindow->gui->unlock_window();
1169         return 0;
1173 void MWindow::sync_parameters(int change_type)
1176 // Sync engines which are playing back
1177         if(cwindow->playback_engine->is_playing_back)
1178         {
1179                 if(change_type == CHANGE_PARAMS)
1180                 {
1181 // TODO: block keyframes until synchronization is done
1182                         cwindow->playback_engine->sync_parameters(edl);
1183                 }
1184                 else
1185 // Stop and restart
1186                 {
1187                         int command = cwindow->playback_engine->command->command;
1188                         cwindow->playback_engine->que->send_command(STOP,
1189                                 CHANGE_NONE, 
1190                                 0,
1191                                 0);
1192 // Waiting for tracking to finish would make the restart position more
1193 // accurate but it can't lock the window to stop tracking for some reason.
1194 // Not waiting for tracking gives a faster response but restart position is
1195 // only as accurate as the last tracking update.
1196                         cwindow->playback_engine->interrupt_playback(0);
1197                         cwindow->playback_engine->que->send_command(command,
1198                                         change_type, 
1199                                         edl,
1200                                         1,
1201                                         0);
1202                 }
1203         }
1204         else
1205         {
1206                 cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1207                                                         change_type,
1208                                                         edl,
1209                                                         1);
1210         }
1213 void MWindow::update_caches()
1215         audio_cache->set_edl(edl);
1216         video_cache->set_edl(edl);
1219 void MWindow::show_plugin(Plugin *plugin)
1221         int done = 0;
1222 //printf("MWindow::show_plugin 1\n");
1223         plugin_gui_lock->lock("MWindow::show_plugin");
1224         for(int i = 0; i < plugin_guis->total; i++)
1225         {
1226 // Pointer comparison
1227                 if(plugin_guis->values[i]->plugin == plugin)
1228                 {
1229                         plugin_guis->values[i]->raise_window();
1230                         done = 1;
1231                         break;
1232                 }
1233         }
1235 //printf("MWindow::show_plugin 1\n");
1236         if(!done)
1237         {
1238                 if(!plugin->track)
1239                 {
1240                         printf("MWindow::show_plugin track not defined.\n");
1241                 }
1242                 PluginServer *server = scan_plugindb(plugin->title,
1243                         plugin->track->data_type);
1245 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
1246                 if(server && server->uses_gui)
1247                 {
1248                         PluginServer *gui = plugin_guis->append(new PluginServer(*server));
1249 // Needs mwindow to do GUI
1250                         gui->set_mwindow(this);
1251                         gui->open_plugin(0, preferences, edl, plugin, -1);
1252                         gui->show_gui();
1253                         plugin->show = 1;
1254                 }
1255         }
1256         plugin_gui_lock->unlock();
1257 //printf("MWindow::show_plugin 2\n");
1260 void MWindow::hide_plugin(Plugin *plugin, int lock)
1262         if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
1263         plugin->show = 0;
1264         for(int i = 0; i < plugin_guis->total; i++)
1265         {
1266                 if(plugin_guis->values[i]->plugin == plugin)
1267                 {
1268                         PluginServer *ptr = plugin_guis->values[i];
1269                         plugin_guis->remove(ptr);
1270                         if(lock) plugin_gui_lock->unlock();
1271 // Last command executed in client side close
1272                         delete ptr;
1273                         return;
1274                 }
1275         }
1276         if(lock) plugin_gui_lock->unlock();
1279 void MWindow::hide_plugins()
1281         plugin_gui_lock->lock("MWindow::hide_plugins");
1282         plugin_guis->remove_all_objects();
1283         plugin_gui_lock->unlock();
1286 void MWindow::update_plugin_guis()
1288         plugin_gui_lock->lock("MWindow::update_plugin_guis");
1290         for(int i = 0; i < plugin_guis->total; i++)
1291         {
1292                 plugin_guis->values[i]->update_gui();
1293         }
1294         plugin_gui_lock->unlock();
1297 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
1299         plugin_gui_lock->lock("MWindow::render_plugin_gui");
1300         for(int i = 0; i < plugin_guis->total; i++)
1301         {
1302                 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1303                 {
1304                         plugin_guis->values[i]->render_gui(data);
1305                         break;
1306                 }
1307         }
1308         plugin_gui_lock->unlock();
1311 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
1313         plugin_gui_lock->lock("MWindow::render_plugin_gui");
1314         for(int i = 0; i < plugin_guis->total; i++)
1315         {
1316                 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1317                 {
1318                         plugin_guis->values[i]->render_gui(data, size);
1319                         break;
1320                 }
1321         }
1322         plugin_gui_lock->unlock();
1326 void MWindow::update_plugin_states()
1328         int result = 0;
1329         plugin_gui_lock->lock("MWindow::update_plugin_states");
1330         for(int i = 0; i < plugin_guis->total; i++)
1331         {
1332 // Get a plugin GUI
1333                 Plugin *src_plugin = plugin_guis->values[i]->plugin;
1334                 PluginServer *src_plugingui = plugin_guis->values[i];
1336 // Search for plugin in EDL.  Only the master EDL shows plugin GUIs.
1337                 for(Track *track = edl->tracks->first; 
1338                         track && !result; 
1339                         track = track->next)
1340                 {
1341                         for(int j = 0; 
1342                                 j < track->plugin_set.total && !result; 
1343                                 j++)
1344                         {
1345                                 PluginSet *plugin_set = track->plugin_set.values[j];
1346                                 for(Plugin *plugin = (Plugin*)plugin_set->first; 
1347                                         plugin && !result; 
1348                                         plugin = (Plugin*)plugin->next)
1349                                 {
1350                                         if(plugin == src_plugin &&
1351                                                 !strcmp(plugin->title, src_plugingui->title)) result = 1;
1352                                 }
1353                         }
1354                 }
1357 // Doesn't exist anymore
1358                 if(!result)
1359                 {
1360                         hide_plugin(src_plugin, 0);
1361                         i--;
1362                 }
1363         }
1364         plugin_gui_lock->unlock();
1368 void MWindow::update_plugin_titles()
1370         for(int i = 0; i < plugin_guis->total; i++)
1371         {
1372                 plugin_guis->values[i]->update_title();
1373         }
1376 int MWindow::asset_to_edl(EDL *new_edl, 
1377         Asset *new_asset, 
1378         RecordLabels *labels)
1380 //printf("MWindow::asset_to_edl 1\n");
1381 //      new_edl->load_defaults(defaults);
1383 // Keep frame rate, sample rate, and output size unchanged.
1384 // These parameters would revert the project if VWindow displayed an asset
1385 // of different size than the project.
1386         if(new_asset->video_data)
1387         {
1388                 new_edl->session->video_tracks = new_asset->layers;
1389 //              new_edl->session->frame_rate = new_asset->frame_rate;
1390 //              new_edl->session->output_w = new_asset->width;
1391 //              new_edl->session->output_h = new_asset->height;
1392         }
1393         else
1394                 new_edl->session->video_tracks = 0;
1401         if(new_asset->audio_data)
1402         {
1403                 new_edl->session->audio_tracks = new_asset->channels;
1404 //              new_edl->session->sample_rate = new_asset->sample_rate;
1405         }
1406         else
1407                 new_edl->session->audio_tracks = 0;
1408 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1410         new_edl->create_default_tracks();
1411 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1413 // Disable drawing if the file format isn't fast enough.
1414         if(new_asset->format == FILE_MPEG)
1415         {
1416                 for(Track *current = new_edl->tracks->first;
1417                         current;
1418                         current = NEXT)
1419                 {
1420                         if(current->data_type == TRACK_VIDEO) current->draw = 0;
1421                 }
1422         }
1426 //printf("MWindow::asset_to_edl 3\n");
1427         new_edl->insert_asset(new_asset, 0, 0, labels);
1428 //printf("MWindow::asset_to_edl 3\n");
1434         char string[BCTEXTLEN];
1435         FileSystem fs;
1436         fs.extract_name(string, new_asset->path);
1437 //printf("MWindow::asset_to_edl 3\n");
1439         strcpy(new_edl->local_session->clip_title, string);
1440 //printf("MWindow::asset_to_edl 4 %s\n", string);
1442 //      new_edl->dump();
1443         return 0;
1446 // Reset everything after a load.
1447 void MWindow::update_project(int load_mode)
1449         restart_brender();
1450 //TRACE("MWindow::update_project 1");
1451         edl->tracks->update_y_pixels(theme);
1453 // Draw timeline
1454 //TRACE("MWindow::update_project 2");
1455         update_caches();
1457 TRACE("MWindow::update_project 3");
1458         gui->update(1, 1, 1, 1, 1, 1, 1);
1460 TRACE("MWindow::update_project 4");
1461         cwindow->update(0, 0, 1, 1, 1);
1463 TRACE("MWindow::update_project 5");
1465         if(load_mode == LOAD_REPLACE ||
1466                 load_mode == LOAD_REPLACE_CONCATENATE)
1467         {
1468                 vwindow->change_source();
1469         }
1470         else
1471         {
1472                 vwindow->update(1);
1473         }
1475 TRACE("MWindow::update_project 6");
1477         cwindow->gui->slider->set_position();
1478 TRACE("MWindow::update_project 6.1");
1479         cwindow->gui->timebar->update(1, 1);
1480 TRACE("MWindow::update_project 6.2");
1481         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1482                 CHANGE_ALL,
1483                 edl,
1484                 1);
1486 TRACE("MWindow::update_project 7");
1487         awindow->gui->lock_window("MWindow::update_project");
1488         awindow->gui->update_assets();
1489         awindow->gui->flush();
1490         awindow->gui->unlock_window();
1491         gui->flush();
1492 TRACE("MWindow::update_project 100");
1496 void MWindow::rebuild_indices()
1498         char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
1500         for(int i = 0; i < session->drag_assets->total; i++)
1501         {
1502 //printf("MWindow::rebuild_indices 1 %s\n", session->drag_assets->values[i]->path);
1503 // Erase file
1504                 IndexFile::get_index_filename(source_filename, 
1505                         preferences->index_directory,
1506                         index_filename, 
1507                         session->drag_assets->values[i]->path);
1508                 remove(index_filename);
1509 // Schedule index build
1510                 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
1511                 mainindexes->add_next_asset(session->drag_assets->values[i]);
1512         }
1513         mainindexes->start_build();
1517 void MWindow::save_backup()
1519         FileXML file;
1520         edl->set_project_path(session->filename);
1521         edl->save_xml(plugindb, 
1522                 &file, 
1523                 BACKUP_PATH,
1524                 0,
1525                 0);
1526         file.terminate_string();
1527         char path[BCTEXTLEN];
1528         FileSystem fs;
1529         strcpy(path, BACKUP_PATH);
1530         fs.complete_path(path);
1532         if(file.write_to_file(path))
1533         {
1534                 char string2[256];
1535                 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
1536                 gui->show_message(string2);
1537         }
1541 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
1543         int denominator;
1544         float fraction = (float)width / height;
1546         for(denominator = 1; 
1547                 denominator < 100 && 
1548                         fabs(fraction * denominator - (int)(fraction * denominator)) > .001; 
1549                 denominator++)
1550                 ;
1552         w = denominator * width / height;
1553         h = denominator;
1558 void MWindow::remove_assets_from_project(int push_undo)
1560     if(push_undo) undo->update_undo_before(_("remove assets"), LOAD_ALL);
1562 // Remove from caches
1563         for(int i = 0; i < session->drag_assets->total; i++)
1564         {
1565                 audio_cache->delete_entry(session->drag_assets->values[i]);
1566                 video_cache->delete_entry(session->drag_assets->values[i]);
1567         }
1569 printf("MWindow::remove_assets_from_project 1\n");
1570 video_cache->dump();
1571 audio_cache->dump();
1572 printf("MWindow::remove_assets_from_project 100\n");
1574 // Remove from VWindow.
1575         for(int i = 0; i < session->drag_clips->total; i++)
1576         {
1577                 if(session->drag_clips->values[i] == vwindow->get_edl())
1578                 {
1579                         vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
1580                         vwindow->remove_source();
1581                         vwindow->gui->unlock_window();
1582                 }
1583         }
1584         
1585         for(int i = 0; i < session->drag_assets->total; i++)
1586         {
1587                 if(session->drag_assets->values[i] == vwindow->get_asset())
1588                 {
1589                         vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
1590                         vwindow->remove_source();
1591                         vwindow->gui->unlock_window();
1592                 }
1593         }
1594         
1595         edl->remove_from_project(session->drag_assets);
1596         edl->remove_from_project(session->drag_clips);
1597         save_backup();
1598         if(push_undo) undo->update_undo_after();
1599         restart_brender();
1601         gui->lock_window("MWindow::remove_assets_from_project 3");
1602         gui->update(1,
1603                 1,
1604                 1,
1605                 1,
1606                 0, 
1607                 1,
1608                 0);
1609         gui->unlock_window();
1611         awindow->gui->lock_window("MWindow::remove_assets_from_project 4");
1612         awindow->gui->update_assets();
1613         awindow->gui->flush();
1614         awindow->gui->unlock_window();
1616 // Removes from playback here
1617         sync_parameters(CHANGE_ALL);
1620 void MWindow::remove_assets_from_disk()
1622 // Remove from disk
1623         for(int i = 0; i < session->drag_assets->total; i++)
1624         {
1625                 remove(session->drag_assets->values[i]->path);
1626         }
1628         remove_assets_from_project(1);
1631 void MWindow::dump_plugins()
1633         for(int i = 0; i < plugindb->total; i++)
1634         {
1635                 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
1636                         plugindb->values[i]->audio,
1637                         plugindb->values[i]->video,
1638                         plugindb->values[i]->realtime,
1639                         plugindb->values[i]->transition,
1640                         plugindb->values[i]->theme,
1641                         plugindb->values[i]->title);
1642         }
1669 int MWindow::save_defaults()
1671         gui->save_defaults(defaults);
1672         edl->save_defaults(defaults);
1673         session->save_defaults(defaults);
1674         preferences->save_defaults(defaults);
1676         defaults->save();
1677         return 0;
1680 int MWindow::run_script(FileXML *script)
1682         int result = 0, result2 = 0;
1683         while(!result && !result2)
1684         {
1685                 result = script->read_tag();
1686                 if(!result)
1687                 {
1688                         if(script->tag.title_is("new_project"))
1689                         {
1690 // Run new in immediate mode.
1691 //                              gui->mainmenu->new_project->run_script(script);
1692                         }
1693                         else
1694                         if(script->tag.title_is("record"))
1695                         {
1696 // Run record as a thread.  It is a terminal command.
1697                                 ;
1698 // Will read the complete scipt file without letting record read it if not
1699 // terminated.
1700                                 result2 = 1;
1701                         }
1702                         else
1703                         {
1704                                 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
1705                         }
1706                 }
1707         }
1708         return result2;
1711 // ================================= synchronization
1714 int MWindow::interrupt_indexes()
1716         mainindexes->interrupt_build();
1717         return 0; 
1722 void MWindow::next_time_format()
1724         switch(edl->session->time_format)
1725         {
1726                 case 0: edl->session->time_format = 1; break;
1727                 case 1: edl->session->time_format = 2; break;
1728                 case 2: edl->session->time_format = 3; break;
1729                 case 3: edl->session->time_format = 4; break;
1730                 case 4: edl->session->time_format = 5; break;
1731                 case 5: edl->session->time_format = 0; break;
1732         }
1734         gui->lock_window();
1735         gui->redraw_time_dependancies();
1739         char string[BCTEXTLEN], string2[BCTEXTLEN];
1740         sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
1741         gui->show_message(string, BLACK);
1742         gui->flush();
1743         gui->unlock_window();
1746 int MWindow::set_filename(char *filename)
1748         strcpy(session->filename, filename);
1749         if(gui)
1750         {
1751                 if(filename[0] == 0)
1752                 {
1753                         gui->set_title(PROGRAM_NAME);
1754                 }
1755                 else
1756                 {
1757                         FileSystem dir;
1758                         char string[BCTEXTLEN], string2[BCTEXTLEN];
1759                         dir.extract_name(string, filename);
1760                         sprintf(string2, PROGRAM_NAME ": %s", string);
1761                         gui->set_title(string2);
1762                 }
1763         }
1764         return 0; 
1774 int MWindow::set_loop_boundaries()
1776         double start = edl->local_session->get_selectionstart();
1777         double end = edl->local_session->get_selectionend();
1778         
1779         if(start != 
1780                 end) 
1781         {
1782                 ;
1783         }
1784         else
1785         if(edl->tracks->total_length())
1786         {
1787                 start = 0;
1788                 end = edl->tracks->total_length();
1789         }
1790         else
1791         {
1792                 start = end = 0;
1793         }
1795         if(edl->local_session->loop_playback && start != end)
1796         {
1797                 edl->local_session->loop_start = start;
1798                 edl->local_session->loop_end = end;
1799         }
1800         return 0; 
1809 int MWindow::reset_meters()
1811         cwindow->gui->lock_window("MWindow::reset_meters 1");
1812         cwindow->gui->meters->reset_meters();
1813         cwindow->gui->unlock_window();
1815         vwindow->gui->lock_window("MWindow::reset_meters 2");
1816         vwindow->gui->meters->reset_meters();
1817         vwindow->gui->unlock_window();
1819         lwindow->gui->lock_window("MWindow::reset_meters 3");
1820         lwindow->gui->panel->reset_meters();
1821         lwindow->gui->unlock_window();
1823         gui->lock_window("MWindow::reset_meters 4");
1824         gui->patchbay->reset_meters();
1825         gui->unlock_window();
1826         return 0;