r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mwindow.C
blob9848241ae85f3672d84723b7658545e7bf4461c1
1 #include "assets.h"
2 #include "awindowgui.h"
3 #include "awindow.h"
4 #include "bcdisplayinfo.h"
5 #include "brender.h"
6 #include "cache.h"
7 #include "channel.h"
8 #include "clip.h"
9 #include "colormodels.h"
10 #include "cplayback.h"
11 #include "ctimebar.h"
12 #include "cwindowgui.h"
13 #include "cwindow.h"
14 #include "defaults.h"
15 #include "editpanel.h"
16 #include "edl.h"
17 #include "edlsession.h"
18 #include "errorbox.h"
19 #include "fileformat.h"
20 #include "file.h"
21 #include "filesystem.h"
22 #include "filexml.h"
23 #include "indexfile.h"
24 #include "levelwindowgui.h"
25 #include "levelwindow.h"
26 #include "loadfile.inc"
27 #include "localsession.h"
28 #include "mainindexes.h"
29 #include "mainmenu.h"
30 #include "mainprogress.h"
31 #include "mainsession.h"
32 #include "mainundo.h"
33 #include "mbuttons.h"
34 #include "mutex.h"
35 #include "mwindowgui.h"
36 #include "mwindow.h"
37 #include "new.h"
38 #include "patchbay.h"
39 #include "playbackengine.h"
40 #include "plugin.h"
41 #include "pluginserver.h"
42 #include "pluginset.h"
43 #include "preferences.h"
44 #include "record.h"
45 #include "recordlabel.h"
46 #include "render.h"
47 #include "samplescroll.h"
48 #include "sighandler.h"
49 #include "splashgui.h"
50 #include "statusbar.h"
51 #include "theme.h"
52 #include "threadloader.h"
53 #include "timebar.h"
54 #include "trackcanvas.h"
55 #include "track.h"
56 #include "tracking.h"
57 #include "trackscroll.h"
58 #include "tracks.h"
59 #include "transportque.h"
60 #include "vframe.h"
61 #include "videodevice.inc"
62 #include "videowindow.h"
63 #include "vplayback.h"
64 #include "vwindowgui.h"
65 #include "vwindow.h"
66 #include "zoombar.h"
68 #include <string.h>
70 #include <libintl.h>
71 #define _(String) gettext(String)
72 #define gettext_noop(String) String
73 #define N_(String) gettext_noop (String)
76 extern "C"
82 // Hack for libdv to remove glib dependancy
84 // void
85 // g_log (const char    *log_domain,
86 //        int  log_level,
87 //        const char    *format,
88 //        ...)
89 // {
90 // }
91 // 
92 // void
93 // g_logv (const char    *log_domain,
94 //        int  log_level,
95 //        const char    *format,
96 //        ...)
97 // {
98 // }
99 // 
102 // Hack for XFree86 4.1.0
104 int atexit(void (*function)(void))
106         return 0;
117 MWindow::MWindow()
119         plugin_gui_lock = new Mutex;
120         brender_lock = new Mutex;
121         brender = 0;
122         session = 0;
125 MWindow::~MWindow()
127 //printf("MWindow::~MWindow 1\n");
128         brender_lock->lock();
129         if(brender) delete brender;
130         brender = 0;
131         brender_lock->unlock();
132         delete brender_lock;
133 //printf("MWindow::~MWindow 2\n");
134         clean_indexes();
135 //printf("MWindow::~MWindow 1\n");
136         delete mainprogress;
137 //printf("MWindow::~MWindow 1\n");
138         delete audio_cache;             // delete the cache after the assets
139 //printf("MWindow::~MWindow 1\n");
140         delete video_cache;             // delete the cache after the assets
141 //printf("MWindow::~MWindow 1\n");
142         if(gui) delete gui;
143 //printf("MWindow::~MWindow 1\n");
144         delete undo;
145 //printf("MWindow::~MWindow 1\n");
146         delete preferences;
147 //printf("MWindow::~MWindow 1\n");
148         delete defaults;
149 //printf("MWindow::~MWindow 1\n");
150         delete render;
151 //printf("MWindow::~MWindow 1\n");
152         delete renderlist;
153 //printf("MWindow::~MWindow 1\n");
154         delete awindow;
155 //printf("MWindow::~MWindow 1\n");
156         delete vwindow;
157 //printf("MWindow::~MWindow 1\n");
158         delete cwindow;
159         delete lwindow;
160 //printf("MWindow::~MWindow 1\n");
161         plugin_guis->remove_all_objects();
162 //printf("MWindow::~MWindow 2\n");
163         delete plugin_guis;
164 //printf("MWindow::~MWindow 3\n");
165         delete plugin_gui_lock;
166 //printf("MWindow::~MWindow 5\n");
169 void MWindow::init_defaults(Defaults* &defaults)
171 // set the .bcast directory
172         char directory[BCTEXTLEN];
173         FileSystem fs;
175         sprintf(directory, "%s", BCASTDIR);
176         fs.complete_path(directory);
177         if(fs.is_dir(directory)) 
178         {
179                 fs.create_dir(directory); 
180         }
182 // load the defaults
183         strcat(directory, "Cinelerra_rc");
185         defaults = new Defaults(directory);
186         defaults->load();
189 void MWindow::init_plugin_path(Preferences *preferences, 
190         ArrayList<PluginServer*>* &plugindb,
191         FileSystem *fs,
192         SplashGUI *splash_window,
193         int *counter)
195         int result = 0;
196         PluginServer *newplugin;
198         if(!result)
199         {
200                 for(int i = 0; i < fs->dir_list.total; i++)
201                 {
202                         char path[BCTEXTLEN];
203                         strcpy(path, fs->dir_list.values[i]->path);
205 // File is a directory
206                         if(!fs->is_dir(path))
207                         {
208                                 continue;
209                         }
210                         else
211                         {
212 // Try to query the plugin
213                                 fs->complete_path(path);
214                                 PluginServer *new_plugin = new PluginServer(path);
215                                 int result = new_plugin->open_plugin(1, 0, 0);
217                                 if(!result)
218                                 {
219                                         plugindb->append(new_plugin);
220                                         new_plugin->close_plugin();
221                                         if(splash_window)
222                                                 splash_window->operation->update(new_plugin->title);
223                                 }
224                                 else
225                                 if(result == PLUGINSERVER_IS_LAD)
226                                 {
227                                         delete new_plugin;
228 // Open LAD subplugins
229                                         int id = 0;
230                                         do
231                                         {
232                                                 new_plugin = new PluginServer(path);
233                                                 result = new_plugin->open_plugin(1,
234                                                         0,
235                                                         0,
236                                                         id);
237                                                 id++;
238                                                 if(!result)
239                                                 {
240                                                         plugindb->append(new_plugin);
241                                                         new_plugin->close_plugin();
242                                                         if(splash_window)
243                                                                 splash_window->operation->update(new_plugin->title);
244                                                 }
245                                         }while(!result);
246                                 }
247                                 else
248                                 {
249 // Plugin failed to open
250                                         delete new_plugin;
251                                 }
252                         }
253                         if(splash_window) splash_window->progress->update((*counter)++);
254                 }
255         }
258 void MWindow::init_plugins(Preferences *preferences, 
259         ArrayList<PluginServer*>* &plugindb,
260         SplashGUI *splash_window)
262         plugindb = new ArrayList<PluginServer*>;
264         FileSystem cinelerra_fs;
265         ArrayList<FileSystem*> lad_fs;
266         int result = 0;
268 // Get directories
269         cinelerra_fs.set_filter("[*.plugin][*.so]");
270         result = cinelerra_fs.update(preferences->global_plugin_dir);
272         if(result)
273         {
274                 fprintf(stderr, 
275                         _("MWindow::init_plugins: couldn't open %s directory\n"),
276                         preferences->global_plugin_dir);
277         }
279 // Parse LAD environment variable
280         char *env = getenv("LADSPA_PATH");
281         if(env)
282         {
283                 char string[BCTEXTLEN];
284                 char *ptr1 = env;
285                 while(ptr1)
286                 {
287                         char *ptr = strchr(ptr1, ':');
288                         char *end;
289                         if(ptr)
290                         {
291                                 end = ptr;
292                         }
293                         else
294                         {
295                                 end = env + strlen(env);
296                         }
298                         if(end > ptr1)
299                         {
300                                 int len = end - ptr1;
301                                 memcpy(string, ptr1, len);
302                                 string[len] = 0;
305                                 FileSystem *fs = new FileSystem;
306                                 lad_fs.append(fs);
307                                 fs->set_filter("*.so");
308                                 result = fs->update(string);
310                                 if(result)
311                                 {
312                                         fprintf(stderr, 
313                                                 _("MWindow::init_plugins: couldn't open %s directory\n"),
314                                                 string);
315                                 }
316                         }
318                         if(ptr)
319                                 ptr1 = ptr + 1;
320                         else
321                                 ptr1 = ptr;
322                 };
323         }
325         int total = cinelerra_fs.total_files();
326         int counter = 0;
327         for(int i = 0; i < lad_fs.total; i++)
328                 total += lad_fs.values[i]->total_files();
329         if(splash_window) splash_window->progress->update_length(total);
331 // Cinelerra
332         init_plugin_path(preferences,
333                 plugindb,
334                 &cinelerra_fs,
335                 splash_window,
336                 &counter);
338 // LAD
339         for(int i = 0; i < lad_fs.total; i++)
340                 init_plugin_path(preferences,
341                         plugindb,
342                         lad_fs.values[i],
343                         splash_window,
344                         &counter);
346         lad_fs.remove_all_objects();
349 void MWindow::delete_plugins()
351         for(int i = 0; i < plugindb->total; i++)
352         {
353                 delete plugindb->values[i];
354         }
355         delete plugindb;
358 void MWindow::create_plugindb(int do_audio, 
359                 int do_video, 
360                 int is_realtime, 
361                 int is_transition,
362                 int is_theme,
363                 ArrayList<PluginServer*> &plugindb)
365 // Get plugins
366         for(int i = 0; i < this->plugindb->total; i++)
367         {
368                 PluginServer *current = this->plugindb->values[i];
370                 if(current->audio == do_audio &&
371                         current->video == do_video &&
372                         (current->realtime == is_realtime || is_realtime < 0) &&
373                         current->transition == is_transition &&
374                         current->theme == is_theme)
375                         plugindb.append(current);
376         }
378 // Alphabetize list by title
379         int done = 0;
380         while(!done)
381         {
382                 done = 1;
383                 
384                 for(int i = 0; i < plugindb.total - 1; i++)
385                 {
386                         PluginServer *value1 = plugindb.values[i];
387                         PluginServer *value2 = plugindb.values[i + 1];
388                         if(strcmp(value1->title, value2->title) > 0)
389                         {
390                                 done = 0;
391                                 plugindb.values[i] = value2;
392                                 plugindb.values[i + 1] = value1;
393                         }
394                 }
395         }
398 PluginServer* MWindow::scan_plugindb(char *title)
400         for(int i = 0; i < plugindb->total; i++)
401         {
402                 if(!strcasecmp(plugindb->values[i]->title, title)) 
403                         return plugindb->values[i];
404         }
405         return 0;
408 void MWindow::init_preferences()
410         preferences = new Preferences;
411         preferences->load_defaults(defaults);
412         session = new MainSession(this);
413         session->load_defaults(defaults);
416 void MWindow::clean_indexes()
418         FileSystem fs;
419         int total_excess;
420         long oldest;
421         int oldest_item;
422         int result;
423         char string[1024];
425 // Delete extra indexes
426         fs.set_filter("*.idx");
427         fs.complete_path(preferences->index_directory);
428         fs.update(preferences->index_directory);
429 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
431 // Eliminate directories
432         result = 1;
433         while(result)
434         {
435                 result = 0;
436                 for(int i = 0; i < fs.dir_list.total && !result; i++)
437                 {
438                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
439                         if(!fs.is_dir(string))
440                         {
441                                 delete fs.dir_list.values[i];
442                                 fs.dir_list.remove_number(i);
443                                 result = 1;
444                         }
445                 }
446         }
447         total_excess = fs.dir_list.total - preferences->index_count;
449 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
450         while(total_excess > 0)
451         {
452 // Get oldest
453                 for(int i = 0; i < fs.dir_list.total; i++)
454                 {
455                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
457                         if(i == 0 || fs.get_date(string) <= oldest)
458                         {
459                                 oldest = fs.get_date(string);
460                                 oldest_item = i;
461                         }
462                 }
464                 fs.join_names(string, preferences->index_directory, fs.dir_list.values[oldest_item]->name);
465                 if(remove(string))
466                         perror("delete_indexes");
467                 delete fs.dir_list.values[oldest_item];
468                 fs.dir_list.remove_number(oldest_item);
469                 total_excess--;
470         }
473 void MWindow::init_awindow()
475         awindow = new AWindow(this);
476         awindow->create_objects();
479 void MWindow::init_theme()
481         theme = 0;
483         for(int i = 0; i < plugindb->total; i++)
484         {
485                 if(plugindb->values[i]->theme &&
486                         !strcasecmp(preferences->theme, plugindb->values[i]->title))
487                 {
488                         PluginServer plugin = *plugindb->values[i];
489                         plugin.open_plugin(0, 0, 0);
490                         theme = plugin.new_theme();
491                         theme->mwindow = this;
492                         strcpy(theme->path, plugin.path);
493                         plugin.close_plugin();
494                 }
495         }
497         if(!theme)
498         {
499                 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
500                 exit(1);
501         }
503 //printf("MWindow::init_theme 3 %p\n", theme);
504         theme->initialize();
505         theme->check_used();
506 //printf("MWindow::init_theme 4\n");
509 void MWindow::init_edl()
511         edl = new EDL;
512         edl->create_objects();
513     edl->load_defaults(defaults);
514         edl->create_default_tracks();
515         edl->tracks->update_y_pixels(theme);
518 void MWindow::init_compositor()
520         cwindow = new CWindow(this);
521     cwindow->create_objects();
524 void MWindow::init_levelwindow()
526         lwindow = new LevelWindow(this);
527         lwindow->create_objects();
530 void MWindow::init_viewer()
532         vwindow = new VWindow(this);
533         vwindow->load_defaults();
534         vwindow->create_objects();
537 void MWindow::init_cache()
539         audio_cache = new CICache(edl, preferences, plugindb);
540         video_cache = new CICache(edl, preferences, plugindb);
543 void MWindow::init_tuner(ArrayList<Channel*> &channeldb, char *path)
545         FileSystem fs;
546         char directory[1024];
547         FileXML file;
548         Channel *channel;
549         int done;
551         sprintf(directory, BCASTDIR);
552         fs.complete_path(directory);
553         fs.join_names(directory, directory, path);
554         done = file.read_from_file(directory, 1);
556 // Load channels
557         while(!done)
558         {
559                 channel = new Channel;
560                 if(!(done = channel->load(&file)))
561                         channeldb.append(channel);
562                 else
563                 {
564                         delete channel;
565                 }
566         }
569 void MWindow::save_tuner(ArrayList<Channel*> &channeldb, char *path)
571         FileSystem fs;
572         char directory[1024];
573         FileXML file;
575         sprintf(directory, BCASTDIR);
576         fs.complete_path(directory);
577         strcat(directory, path);
579         if(channeldb.total)
580         {
581                 for(int i = 0; i < channeldb.total; i++)
582                 {
583 // Save channel here
584                         channeldb.values[i]->save(&file);
585                 }
586                 file.terminate_string();
587                 file.write_to_file(directory);
588         }
591 void MWindow::init_menus()
593         char string[BCTEXTLEN];
594         cmodel_to_text(string, BC_RGB888);
595         colormodels.append(new ColormodelItem(string, BC_RGB888));
596         cmodel_to_text(string, BC_RGBA8888);
597         colormodels.append(new ColormodelItem(string, BC_RGBA8888));
598         cmodel_to_text(string, BC_RGB161616);
599         colormodels.append(new ColormodelItem(string, BC_RGB161616));
600         cmodel_to_text(string, BC_RGBA16161616);
601         colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
602         cmodel_to_text(string, BC_YUV888);
603         colormodels.append(new ColormodelItem(string, BC_YUV888));
604         cmodel_to_text(string, BC_YUVA8888);
605         colormodels.append(new ColormodelItem(string, BC_YUVA8888));
606         cmodel_to_text(string, BC_YUV161616);
607         colormodels.append(new ColormodelItem(string, BC_YUV161616));
608         cmodel_to_text(string, BC_YUVA16161616);
609         colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
612 void MWindow::init_indexes()
614         mainindexes = new MainIndexes(this);
615         mainindexes->start_loop();
618 void MWindow::init_gui()
620         gui = new MWindowGUI(this);
621         gui->create_objects();
622         gui->load_defaults(defaults);
625 void MWindow::init_signals()
627         sighandler = new SigHandler;
630 void MWindow::init_render()
632         render = new Render(this);
633         renderlist = new Render(this);
636 void MWindow::init_brender()
638         if(preferences->use_brender && !brender)
639         {
640                 brender_lock->lock();
641                 brender = new BRender(this);
642                 brender->initialize();
643                 session->brender_end = 0;
644                 brender_lock->unlock();
645         }
646         else
647         if(!preferences->use_brender && brender)
648         {
649                 brender_lock->lock();
650                 delete brender;
651                 brender = 0;
652                 session->brender_end = 0;
653                 brender_lock->unlock();
654         }
655         if(brender) brender->restart(edl);
658 void MWindow::restart_brender()
660 //printf("MWindow::restart_brender 1\n");
661         if(brender) brender->restart(edl);
664 void MWindow::stop_brender()
666         if(brender) brender->stop();
669 int MWindow::brender_available(int position)
671         int result = 0;
672         brender_lock->lock();
673         if(brender)
674         {
675                 if(brender->map_valid)
676                 {
677                         brender->map_lock->lock();
678                         if(position < brender->map_size &&
679                                 position >= 0)
680                         {
681 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
682                                 if(brender->map[position] == BRender::RENDERED)
683                                         result = 1;
684                         }
685                         brender->map_lock->unlock();
686                 }
687         }
688         brender_lock->unlock();
689         return result;
692 void MWindow::set_brender_start()
694         edl->session->brender_start = edl->local_session->get_selectionstart();
695         restart_brender();
696         gui->canvas->draw_overlays();
697         gui->canvas->flash();
702 int MWindow::load_filenames(ArrayList<char*> *filenames, int load_mode)
704 TRON("MWindow::load_filenames\n");
705         ArrayList<EDL*> new_edls;
706         ArrayList<Asset*> new_assets;
707 //printf("load_filenames 1\n");
709 // Need to stop playback since tracking depends on the EDL not getting
710 // deleted.
711         cwindow->playback_engine->que->send_command(STOP,
712                 CHANGE_NONE, 
713                 0,
714                 0);
715         vwindow->playback_engine->que->send_command(STOP,
716                 CHANGE_NONE, 
717                 0,
718                 0);
719         cwindow->playback_engine->interrupt_playback(0);
720         vwindow->playback_engine->interrupt_playback(0);
724 // Define new_edls and new_assets to load
725         int result = 0;
726         for(int i = 0; i < filenames->total; i++)
727         {
728 // Get type of file
729                 File *new_file = new File;
730                 Asset *new_asset = new Asset(filenames->values[i]);
731                 EDL *new_edl = new EDL;
732                 char string[BCTEXTLEN];
734 //printf("load_filenames 1\n");
735                 new_edl->create_objects();
736 //printf("load_filenames 1\n");
737                 new_edl->copy_session(edl);
738 //printf("load_filenames 1\n");
740                 sprintf(string, "Loading %s", new_asset->path);
741 //printf("load_filenames 1\n");
742                 gui->show_message(string, BLACK);
743 //printf("load_filenames 1\n");
744                 result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
745 //printf("load_filenames 2\n");
747                 switch(result)
748                 {
749 // Convert media file to EDL
750                         case FILE_OK:
751 //printf("load_filenames 1.1\n");
752                                 if(load_mode != LOAD_RESOURCESONLY)
753                                 {
754                                         asset_to_edl(new_edl, new_asset);
755 //printf("load_filenames 1.2\n");
756                                         new_edls.append(new_edl);
757                                         delete new_asset;
758                                 }
759                                 else
760 //printf("load_filenames 1.3\n");
761                                 {
762                                         new_assets.append(new_asset);
763                                 }
764                                 if(load_mode == LOAD_REPLACE || 
765                                         load_mode == LOAD_REPLACE_CONCATENATE)
766                                         set_filename("");
767                                 result = 0;
768                                 break;
770 // File not found
771                         case FILE_NOT_FOUND:
772                                 sprintf(string, _("Failed to open %s"), new_asset->path);
773                                 gui->show_message(string, RED);
774                                 result = 1;
775                                 break;
777 // Unknown format
778                         case FILE_UNRECOGNIZED_CODEC:
779                         {
780 // Test index file
781                                 IndexFile indexfile(this);
782                                 result = indexfile.open_index(this, new_asset);
783                                 if(!result)
784                                 {
785                                         indexfile.close_index();
786                                 }
788 // Test existing EDLs
789                                 if(result)
790                                 {
791                                         for(int j = 0; j < new_edls.total + 1; j++)
792                                         {
793                                                 Asset *old_asset;
794                                                 if(j == new_edls.total)
795                                                 {
796                                                         if(old_asset = edl->assets->get_asset(new_asset->path))
797                                                         {
798                                                                 *new_asset = *old_asset;
799                                                                 result = 0;
800                                                         }
801                                                 }
802                                                 else
803                                                 {
804                                                         if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
805                                                         {
806                                                                 *new_asset = *old_asset;
807                                                                 result = 0;
808                                                         }
809                                                 }
810                                         }
811                                 }
813 // Prompt user
814                                 if(result)
815                                 {
816                                         char string[BCTEXTLEN];
817                                         FileSystem fs;
818                                         fs.extract_name(string, new_asset->path);
820                                         strcat(string, _("'s format couldn't be determined."));
821                                         new_asset->audio_data = 1;
822                                         new_asset->format = FILE_PCM;
823                                         new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
824                                         new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
825                                         new_asset->bits = defaults->get("AUDIO_BITS", 16);
826                                         new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
827                                         new_asset->signed_ = defaults->get("SIGNED_", 1);
828                                         new_asset->header = defaults->get("HEADER", 0);
830                                         FileFormat fwindow(this);
831                                         fwindow.create_objects(new_asset, string);
832                                         result = fwindow.run_window();
834                                         defaults->update("AUDIO_CHANNELS", new_asset->channels);
835                                         defaults->update("SAMPLE_RATE", new_asset->sample_rate);
836                                         defaults->update("AUDIO_BITS", new_asset->bits);
837                                         defaults->update("BYTE_ORDER", new_asset->byte_order);
838                                         defaults->update("SIGNED_", new_asset->signed_);
839                                         defaults->update("HEADER", new_asset->header);
840                                         save_defaults();
841                                 }
843 // Append to list
844                                 if(!result)
845                                 {
846 // Recalculate length
847                                         delete new_file;
848                                         new_file = new File;
849                                         result = new_file->open_file(plugindb, new_asset, 1, 0, 0, 0);
851                                         if(load_mode != LOAD_RESOURCESONLY)
852                                         {
853                                                 asset_to_edl(new_edl, new_asset);
854 //printf("MWindow::load_filenames 1 %d %d\n", new_asset->video_length, new_asset->audio_length);
855 //new_edl->dump();
856                                                 new_edls.append(new_edl);
857                                                 delete new_asset;
858                                         }
859                                         else
860                                         {
861                                                 new_assets.append(new_asset);
862                                         }
863                                 }
864                                 else
865                                 {
866                                         result = 1;
867                                 }
868                                 break;
869                         }
871                         case FILE_IS_XML:
872                         {
873 //printf("load_filenames 2\n");
874                                 FileXML xml_file;
875                                 xml_file.read_from_file(filenames->values[i]);
876 //printf("load_filenames 3\n");
877 //                              gui->lock_window();
878 //                              gui->update_title(session->filename);
879 //                              gui->unlock_window();
880 // Load EDL for pasting
881 //printf("load_filenames 3\n");
882                                 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
883 //printf("load_filenames 3\n");
884                                 if(load_mode == LOAD_REPLACE || 
885                                         load_mode == LOAD_REPLACE_CONCATENATE)
886                                 {
887                                         strcpy(session->filename, filenames->values[i]);
888                                         strcpy(new_edl->local_session->clip_title, filenames->values[i]);
889                                         set_filename(new_edl->local_session->clip_title);
890                                 }
891 //new_edl->dump();
892 //printf("load_filenames 2\n");
893                                 new_edls.append(new_edl);
894 //printf("load_filenames 4\n");
895                                 result = 0;
896                                 break;
897                         }
898                 }
899 //printf("load_filenames 4\n");
901                 if(result)
902                 {
903                         delete new_edl;
904                         delete new_asset;
905                 }
906 //printf("load_filenames 5\n");
908                 delete new_file;
909 //printf("load_filenames 6\n");
911         }
912 //printf("MWindow::load_filenames 5 %d\n", new_edls.total);
914 //sleep(10);
917         if(!result) gui->statusbar->default_message();
920 //printf("MWindow::load_filenames 7 %d\n", new_edls.total);
927 // Paste them.
928 // Don't back up here.
929         if(new_edls.total)
930         {
931 // For pasting, clear the active region
932                 if(load_mode == LOAD_PASTE)
933                 {
934                         double start = edl->local_session->get_selectionstart();
935                         double end = edl->local_session->get_selectionend();
936                         if(!EQUIV(start, end))
937                                 edl->clear(start, 
938                                         end,
939                                         edl->session->labels_follow_edits,
940                                         edl->session->plugins_follow_edits);
941                 }
943                 paste_edls(&new_edls, 
944                         load_mode,
945                         0,
946                         -1,
947                         edl->session->labels_follow_edits, 
948                         edl->session->plugins_follow_edits);
949         }
957 //printf("MWindow::load_filenames 8 %d\n", new_edls.total);
958 //sleep(10);
960         if(new_assets.total)
961         {
962                 for(int i = 0; i < new_assets.total; i++)
963                 {
964                         mainindexes->add_next_asset(new_assets.values[i]);
965                         edl->assets->update(new_assets.values[i]);
966                 }
969 // Start examining next batch of index files
970                 mainindexes->start_build();
971         }
973         update_project(load_mode);
975 //printf("MWindow::load_filenames 9\n");
976 //sleep(10);
978         new_edls.remove_all_objects();
979         new_assets.remove_all_objects();
980 //printf("MWindow::load_filenames 10 %d\n", edl->session->audio_module_fragment);
982         if(load_mode == LOAD_REPLACE ||
983                 load_mode == LOAD_REPLACE_CONCATENATE)
984                 session->changes_made = 0;
986 TROFF("MWindow::load_filenames\n");
987         return 0;
990 void MWindow::create_objects(int want_gui, int want_new)
992         char string[1024];
993         FileSystem fs;
995         edl = 0;
997         show_splash();
998         init_signals();
1000         init_menus();
1001 //printf("MWindow::create_objects 1\n");
1002         init_defaults(defaults);
1003 //printf("MWindow::create_objects 1\n");
1004         init_preferences();
1005 //printf("MWindow::create_objects 1\n");
1006         init_plugins(preferences, plugindb, splash_window);
1007         splash_window->operation->update(_("Initializing GUI"));
1008 //printf("MWindow::create_objects 1\n");
1009         init_theme();
1010 // Default project created here
1011 //printf("MWindow::create_objects 1\n");
1012         init_edl();
1014 //printf("MWindow::create_objects 1\n");
1015         init_awindow();
1016 //printf("MWindow::create_objects 1\n");
1017         init_compositor();
1018 //printf("MWindow::create_objects 1\n");
1019         init_levelwindow();
1020 //printf("MWindow::create_objects 1\n");
1021         init_viewer();
1022 //printf("MWindow::create_objects 1\n");
1023         init_tuner(channeldb_v4l, "channels_v4l");
1024 //printf("MWindow::create_objects 1\n");
1025         init_tuner(channeldb_buz, "channels_buz");
1026 //printf("MWindow::create_objects 1\n");
1027         init_cache();
1028 //printf("MWindow::create_objects 1\n");
1029         init_indexes();
1030 //printf("MWindow::create_objects 1\n");
1031         init_gui();
1032 //printf("MWindow::create_objects 1\n");
1033         init_render();
1034         init_brender();
1035         mainprogress = new MainProgress(this, gui);
1036         undo = new MainUndo(this);
1038         plugin_guis = new ArrayList<PluginServer*>;
1040 //printf("MWindow::create_objects 1\n");
1041         if(session->show_vwindow) vwindow->gui->show_window();
1042         if(session->show_cwindow) cwindow->gui->show_window();
1043         if(session->show_awindow) awindow->gui->show_window();
1044         if(session->show_lwindow) lwindow->gui->show_window();
1045 //printf("MWindow::create_objects 1\n");
1047 //      vwindow->start();
1048 //      awindow->start();
1049 //      cwindow->start();
1050 //      lwindow->start();
1051 //printf("MWindow::create_objects 1\n");
1053         gui->mainmenu->load_defaults(defaults);
1054 //printf("MWindow::create_objects 1\n");
1055         gui->mainmenu->update_toggles();
1056 //printf("MWindow::create_objects 1\n");
1057         gui->patchbay->update();
1058 //printf("MWindow::create_objects 1\n");
1059         gui->canvas->draw();
1060 //printf("MWindow::create_objects 1\n");
1061         gui->cursor->draw();
1062 //printf("MWindow::create_objects 1\n");
1063         gui->raise_window();
1064 //printf("MWindow::create_objects 1\n");
1065         gui->show_window();
1067         hide_splash();
1068 //printf("MWindow::create_objects 2\n");
1072 void MWindow::show_splash()
1074 #include "data/heroine_logo11_png.h"
1075         VFrame *frame = new VFrame(heroine_logo11_png);
1076         BC_DisplayInfo display_info;
1077         splash_window = new SplashGUI(frame, 
1078                 display_info.get_root_w() / 2 - frame->get_w() / 2,
1079                 display_info.get_root_h() / 2 - frame->get_h() / 2);
1080         splash_window->create_objects();
1083 void MWindow::hide_splash()
1085         delete splash_window;
1089 void MWindow::start()
1091         vwindow->start();
1092         awindow->start();
1093         cwindow->start();
1094         lwindow->start();
1095         gui->run_window();
1098 void MWindow::show_vwindow()
1100         session->show_vwindow = 1;
1101         vwindow->gui->lock_window();
1102         vwindow->gui->show_window();
1103         vwindow->gui->raise_window();
1104         vwindow->gui->flush();
1105         vwindow->gui->unlock_window();
1106         gui->mainmenu->show_vwindow->set_checked(1);
1109 void MWindow::show_awindow()
1111         session->show_awindow = 1;
1112         awindow->gui->lock_window();
1113         awindow->gui->show_window();
1114         awindow->gui->raise_window();
1115         awindow->gui->flush();
1116         awindow->gui->unlock_window();
1117         gui->mainmenu->show_awindow->set_checked(1);
1120 void MWindow::show_cwindow()
1122         session->show_cwindow = 1;
1123         cwindow->gui->lock_window();
1124         cwindow->gui->show_window();
1125         cwindow->gui->raise_window();
1126         cwindow->gui->flush();
1127         cwindow->gui->unlock_window();
1128         gui->mainmenu->show_cwindow->set_checked(1);
1131 void MWindow::show_lwindow()
1133         session->show_lwindow = 1;
1134         lwindow->gui->lock_window();
1135         lwindow->gui->show_window();
1136         lwindow->gui->raise_window();
1137         lwindow->gui->flush();
1138         lwindow->gui->unlock_window();
1139         gui->mainmenu->show_lwindow->set_checked(1);
1142 void MWindow::tile_windows()
1144         session->default_window_positions();
1145         gui->default_positions();
1148 void MWindow::toggle_loop_playback()
1150         edl->local_session->loop_playback = !edl->local_session->loop_playback;
1151         set_loop_boundaries();
1152         save_backup();
1154         gui->canvas->draw_overlays();
1155         gui->canvas->flash();
1156         sync_parameters(CHANGE_PARAMS);
1159 void MWindow::set_titles(int value)
1161         edl->session->show_titles = value;
1162         trackmovement(edl->local_session->track_start);
1165 void MWindow::set_auto_keyframes(int value)
1167         gui->lock_window();
1168         edl->session->auto_keyframes = value;
1169         gui->mbuttons->edit_panel->keyframe->update(value);
1170         gui->flush();
1171         gui->unlock_window();
1172         cwindow->gui->lock_window();
1173         cwindow->gui->edit_panel->keyframe->update(value);
1174         cwindow->gui->flush();
1175         cwindow->gui->unlock_window();
1178 int MWindow::set_editing_mode(int new_editing_mode)
1180         gui->lock_window();
1181         edl->session->editing_mode = new_editing_mode;
1182         gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
1183         gui->mbuttons->edit_panel->update();
1184         gui->canvas->update_cursor();
1185         gui->unlock_window();
1186         cwindow->gui->lock_window();
1187         cwindow->gui->edit_panel->update();
1188         cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
1189         cwindow->gui->unlock_window();
1190         return 0;
1194 void MWindow::sync_parameters(int change_type)
1197 // Sync engines which are playing back
1198         if(cwindow->playback_engine->is_playing_back)
1199         {
1200                 if(change_type == CHANGE_PARAMS)
1201                 {
1202 // TODO: block keyframes until synchronization is done
1203                         cwindow->playback_engine->sync_parameters(edl);
1204                 }
1205                 else
1206 // Stop and restart
1207                 {
1208 //printf("MWindow::sync_parameters 1\n");
1209                         int command = cwindow->playback_engine->command->command;
1210                         cwindow->playback_engine->que->send_command(STOP,
1211                                 CHANGE_NONE, 
1212                                 0,
1213                                 0);
1214 //printf("MWindow::sync_parameters 2\n");
1215 // Waiting for tracking to finish would make the restart position more
1216 // accurate but it can't lock the window to stop tracking for some reason.
1217 // Not waiting for tracking gives a faster response but restart position is
1218 // only as accurate as the last tracking update.
1219                         cwindow->playback_engine->interrupt_playback(0);
1220 //printf("MWindow::sync_parameters 3\n");
1221                         cwindow->playback_engine->que->send_command(command,
1222                                         change_type, 
1223                                         edl,
1224                                         1,
1225                                         0);
1226 //printf("MWindow::sync_parameters 4\n");
1227                 }
1228         }
1229         else
1230         {
1231 //printf("MWindow::sync_parameters 1\n");
1232                 cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1233                                                         change_type,
1234                                                         edl,
1235                                                         1);
1236 //printf("MWindow::sync_parameters 2\n");
1237         }
1240 void MWindow::update_caches()
1242         audio_cache->set_edl(edl);
1243         video_cache->set_edl(edl);
1246 void MWindow::show_plugin(Plugin *plugin)
1248         int done = 0;
1249 //printf("MWindow::show_plugin 1\n");
1250         plugin_gui_lock->lock();
1251         for(int i = 0; i < plugin_guis->total; i++)
1252         {
1253 // Pointer comparison
1254                 if(plugin_guis->values[i]->plugin == plugin)
1255                 {
1256                         plugin_guis->values[i]->raise_window();
1257                         done = 1;
1258                         break;
1259                 }
1260         }
1262 //printf("MWindow::show_plugin 1\n");
1263         if(!done)
1264         {
1265                 PluginServer *server = scan_plugindb(plugin->title);
1267 //printf("MWindow::show_plugin %p %d\n", server, server->uses_gui);
1268                 if(server && server->uses_gui)
1269                 {
1270                         PluginServer *gui = plugin_guis->append(new PluginServer(*server));
1271 // Needs mwindow to do GUI
1272                         gui->set_mwindow(this);
1273                         gui->open_plugin(0, edl, plugin);
1274                         gui->show_gui();
1275                         plugin->show = 1;
1276                 }
1277         }
1278         plugin_gui_lock->unlock();
1279 //printf("MWindow::show_plugin 2\n");
1282 void MWindow::hide_plugin(Plugin *plugin, int lock)
1284         if(lock) plugin_gui_lock->lock();
1285         plugin->show = 0;
1286         for(int i = 0; i < plugin_guis->total; i++)
1287         {
1288 //printf("MWindow::hide_plugin 1 %p %p\n", plugin, plugin_guis->values[i]->plugin);
1289                 if(plugin_guis->values[i]->plugin == plugin)
1290                 {
1291 //printf("MWindow::hide_plugin 2\n");
1292                         PluginServer *ptr = plugin_guis->values[i];
1293                         plugin_guis->remove(ptr);
1294                         if(lock) plugin_gui_lock->unlock();
1295 // Last command executed in client side close
1296                         delete ptr;
1297                         return;
1298                 }
1299         }
1300         if(lock) plugin_gui_lock->unlock();
1303 void MWindow::hide_plugins()
1305         plugin_gui_lock->lock();
1306         plugin_guis->remove_all_objects();
1307         plugin_gui_lock->unlock();
1310 void MWindow::update_plugin_guis()
1313         plugin_gui_lock->lock();
1316         for(int i = 0; i < plugin_guis->total; i++)
1317         {
1318                 plugin_guis->values[i]->update_gui();
1319         }
1320         plugin_gui_lock->unlock();
1323 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
1325 //printf("MWindow::render_plugin_gui 1\n");
1326         plugin_gui_lock->lock();
1327         for(int i = 0; i < plugin_guis->total; i++)
1328         {
1329                 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1330                 {
1331 //printf("MWindow::render_plugin_gui 2\n");
1332                         plugin_guis->values[i]->render_gui(data);
1333                         break;
1334                 }
1335         }
1336         plugin_gui_lock->unlock();
1339 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
1341 //printf("MWindow::render_plugin_gui 1\n");
1342         plugin_gui_lock->lock();
1343         for(int i = 0; i < plugin_guis->total; i++)
1344         {
1345                 if(plugin_guis->values[i]->plugin->identical_location(plugin))
1346                 {
1347 //printf("MWindow::render_plugin_gui 2\n");
1348                         plugin_guis->values[i]->render_gui(data, size);
1349                         break;
1350                 }
1351         }
1352         plugin_gui_lock->unlock();
1356 void MWindow::update_plugin_states()
1358         int result = 0;
1359         plugin_gui_lock->lock();
1360         for(int i = 0; i < plugin_guis->total; i++)
1361         {
1362 // Get a plugin GUI
1363                 Plugin *src_plugin = plugin_guis->values[i]->plugin;
1364                 PluginServer *src_plugingui = plugin_guis->values[i];
1366 // Search for plugin in EDL.  Only the master EDL shows plugin GUIs.
1367                 for(Track *track = edl->tracks->first; 
1368                         track && !result; 
1369                         track = track->next)
1370                 {
1371                         for(int j = 0; 
1372                                 j < track->plugin_set.total && !result; 
1373                                 j++)
1374                         {
1375                                 PluginSet *plugin_set = track->plugin_set.values[j];
1376                                 for(Plugin *plugin = (Plugin*)plugin_set->first; 
1377                                         plugin && !result; 
1378                                         plugin = (Plugin*)plugin->next)
1379                                 {
1380                                         if(plugin == src_plugin &&
1381                                                 !strcmp(plugin->title, src_plugingui->title)) result = 1;
1382                                 }
1383                         }
1384                 }
1387 // Doesn't exist anymore
1388                 if(!result)
1389                 {
1390                         hide_plugin(src_plugin, 0);
1391                         i--;
1392                 }
1393         }
1394         plugin_gui_lock->unlock();
1398 void MWindow::update_plugin_titles()
1400         for(int i = 0; i < plugin_guis->total; i++)
1401         {
1402                 plugin_guis->values[i]->update_title();
1403         }
1406 int MWindow::asset_to_edl(EDL *new_edl, 
1407         Asset *new_asset, 
1408         RecordLabels *labels)
1410 //printf("MWindow::asset_to_edl 1\n");
1411 //      new_edl->load_defaults(defaults);
1413 // Keep frame rate, sample rate, and output size unchanged.
1414 // These parameters would revert the project if VWindow displayed an asset
1415 // of different size than the project.
1416         if(new_asset->video_data)
1417         {
1418                 new_edl->session->video_tracks = new_asset->layers;
1419 //              new_edl->session->frame_rate = new_asset->frame_rate;
1420 //              new_edl->session->output_w = new_asset->width;
1421 //              new_edl->session->output_h = new_asset->height;
1422         }
1423         else
1424                 new_edl->session->video_tracks = 0;
1431         if(new_asset->audio_data)
1432         {
1433                 new_edl->session->audio_tracks = new_asset->channels;
1434 //              new_edl->session->sample_rate = new_asset->sample_rate;
1435         }
1436         else
1437                 new_edl->session->audio_tracks = 0;
1438 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1440         new_edl->create_default_tracks();
1441 //printf("MWindow::asset_to_edl 2 %d %d\n", new_edl->session->video_tracks, new_edl->session->audio_tracks);
1443 // Disable drawing if the file format isn't fast enough.
1444         if(new_asset->format == FILE_MPEG)
1445         {
1446                 for(Track *current = new_edl->tracks->first;
1447                         current;
1448                         current = NEXT)
1449                 {
1450                         if(current->data_type == TRACK_VIDEO) current->draw = 0;
1451                 }
1452         }
1456 //printf("MWindow::asset_to_edl 3\n");
1457         new_edl->insert_asset(new_asset, 0, 0, labels);
1458 //printf("MWindow::asset_to_edl 3\n");
1464         char string[BCTEXTLEN];
1465         FileSystem fs;
1466         fs.extract_name(string, new_asset->path);
1467 //printf("MWindow::asset_to_edl 3\n");
1469         strcpy(new_edl->local_session->clip_title, string);
1470 //printf("MWindow::asset_to_edl 4 %s\n", string);
1472 //      new_edl->dump();
1473         return 0;
1476 // Reset everything after a load.
1477 void MWindow::update_project(int load_mode)
1479         restart_brender();
1480 //printf("MWindow::update_project 1\n");
1481         edl->tracks->update_y_pixels(theme);
1483 // Draw timeline
1484 //printf("MWindow::update_project 1\n");
1485         update_caches();
1487 //printf("MWindow::update_project 1\n");
1488         gui->update(1, 1, 1, 1, 1, 1, 1);
1490 //printf("MWindow::update_project 1\n");
1491         cwindow->update(0, 0, 1, 1, 1);
1493 //printf("MWindow::update_project 1\n");
1495         if(load_mode == LOAD_REPLACE ||
1496                 load_mode == LOAD_REPLACE_CONCATENATE)
1497         {
1498                 vwindow->change_source();
1499         }
1500         else
1501         {
1502                 vwindow->update(1);
1503         }
1506         cwindow->gui->slider->set_position();
1507         cwindow->gui->timebar->update(1, 1);
1508         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1509                 CHANGE_ALL,
1510                 edl,
1511                 1);
1513 //printf("MWindow::update_project 1\n");
1514         awindow->gui->lock_window();
1515 //printf("MWindow::update_project 1\n");
1516         awindow->gui->update_assets();
1517 //printf("MWindow::update_project 1\n");
1518         awindow->gui->flush();
1519 //printf("MWindow::update_project 1\n");
1520         awindow->gui->unlock_window();
1521 //printf("MWindow::update_project 12\n");
1522         gui->flush();
1523 //printf("MWindow::update_project 13\n");
1527 void MWindow::rebuild_indices()
1529         char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
1531         for(int i = 0; i < session->drag_assets->total; i++)
1532         {
1533 //printf("MWindow::rebuild_indices 1 %s\n", session->drag_assets->values[i]->path);
1534 // Erase file
1535                 IndexFile::get_index_filename(source_filename, 
1536                         preferences->index_directory,
1537                         index_filename, 
1538                         session->drag_assets->values[i]->path);
1539                 remove(index_filename);
1540 // Schedule index build
1541                 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
1542                 mainindexes->add_next_asset(session->drag_assets->values[i]);
1543         }
1544         mainindexes->start_build();
1548 void MWindow::save_backup()
1550         FileXML file;
1551         edl->save_xml(plugindb, 
1552                 &file, 
1553                 BACKUP_PATH,
1554                 0,
1555                 0);
1556         file.terminate_string();
1557         char path[BCTEXTLEN];
1558         FileSystem fs;
1559         strcpy(path, BACKUP_PATH);
1560         fs.complete_path(path);
1562         if(file.write_to_file(path))
1563         {
1564                 char string2[256];
1565                 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
1566                 gui->show_message(string2);
1567         }
1571 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
1573         int denominator;
1574         float fraction = (float)width / height;
1576         for(denominator = 1; 
1577                 denominator < 100 && 
1578                         fabs(fraction * denominator - (int)(fraction * denominator)) > .001; 
1579                 denominator++)
1580                 ;
1582         w = denominator * width / height;
1583         h = denominator;
1586 void MWindow::render_single()
1588         if(!render->running())
1589                 render->start();
1592 void MWindow::render_list()
1594         if(!renderlist->running())
1595                 renderlist->start();
1599 void MWindow::remove_assets_from_project(int push_undo)
1601     if(push_undo) undo->update_undo_before(_("remove assets"), LOAD_ALL);
1603 // Remove from caches
1604         for(int i = 0; i < session->drag_assets->total; i++)
1605         {
1606                 audio_cache->delete_entry(session->drag_assets->values[i]);
1607                 video_cache->delete_entry(session->drag_assets->values[i]);
1608         }
1610 printf("MWindow::remove_assets_from_project 1\n");
1611 video_cache->dump();
1612 audio_cache->dump();
1613 printf("MWindow::remove_assets_from_project 100\n");
1615 // Remove from VWindow.
1616         for(int i = 0; i < session->drag_clips->total; i++)
1617         {
1618                 if(session->drag_clips->values[i] == vwindow->get_edl())
1619                 {
1620                         vwindow->gui->lock_window();
1621                         vwindow->remove_source();
1622                         vwindow->gui->unlock_window();
1623                 }
1624         }
1625         
1626         for(int i = 0; i < session->drag_assets->total; i++)
1627         {
1628                 if(session->drag_assets->values[i] == vwindow->get_asset())
1629                 {
1630                         vwindow->gui->lock_window();
1631                         vwindow->remove_source();
1632                         vwindow->gui->unlock_window();
1633                 }
1634         }
1635         
1636         edl->remove_from_project(session->drag_assets);
1637         edl->remove_from_project(session->drag_clips);
1638         save_backup();
1639         if(push_undo) undo->update_undo_after();
1640         restart_brender();
1642         gui->lock_window();
1643         gui->update(1,
1644                 1,
1645                 1,
1646                 1,
1647                 0, 
1648                 1,
1649                 0);
1650         gui->unlock_window();
1652         awindow->gui->lock_window();
1653         awindow->gui->update_assets();
1654         awindow->gui->flush();
1655         awindow->gui->unlock_window();
1657 // Removes from playback here
1658         sync_parameters(CHANGE_ALL);
1661 void MWindow::remove_assets_from_disk()
1663 // Remove from disk
1664         for(int i = 0; i < session->drag_assets->total; i++)
1665         {
1666                 remove(session->drag_assets->values[i]->path);
1667         }
1669         remove_assets_from_project(1);
1672 void MWindow::dump_plugins()
1674         for(int i = 0; i < plugindb->total; i++)
1675         {
1676                 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
1677                         plugindb->values[i]->audio,
1678                         plugindb->values[i]->video,
1679                         plugindb->values[i]->realtime,
1680                         plugindb->values[i]->transition,
1681                         plugindb->values[i]->theme,
1682                         plugindb->values[i]->title);
1683         }
1710 int MWindow::save_defaults()
1712 //printf("MWindow::save_defaults 1\n");
1713         gui->save_defaults(defaults);
1714         edl->save_defaults(defaults);
1715 //printf("MWindow::save_defaults 1\n");
1716         session->save_defaults(defaults);
1717         preferences->save_defaults(defaults);
1718 //printf("MWindow::save_defaults 1\n");
1720         save_tuner(channeldb_v4l, "channels_v4l");
1721         save_tuner(channeldb_buz, "channels_buz");
1722 //printf("MWindow::save_defaults 1\n");
1723         defaults->save();
1724 //printf("MWindow::save_defaults 2\n");
1725         return 0;
1728 int MWindow::run_script(FileXML *script)
1730         int result = 0, result2 = 0;
1731         while(!result && !result2)
1732         {
1733                 result = script->read_tag();
1734                 if(!result)
1735                 {
1736                         if(script->tag.title_is("new_project"))
1737                         {
1738 // Run new in immediate mode.
1739 //                              gui->mainmenu->new_project->run_script(script);
1740                         }
1741                         else
1742                         if(script->tag.title_is("record"))
1743                         {
1744 // Run record as a thread.  It is a terminal command.
1745                                 ;
1746 // Will read the complete scipt file without letting record read it if not
1747 // terminated.
1748                                 result2 = 1;
1749                         }
1750                         else
1751                         {
1752                                 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
1753                         }
1754                 }
1755         }
1756         return result2;
1759 // ================================= synchronization
1762 int MWindow::interrupt_indexes()
1764         mainindexes->interrupt_build();
1765         return 0; 
1770 void MWindow::next_time_format()
1772         switch(edl->session->time_format)
1773         {
1774                 case 0: edl->session->time_format = 1; break;
1775                 case 1: edl->session->time_format = 2; break;
1776                 case 2: edl->session->time_format = 3; break;
1777                 case 3: edl->session->time_format = 4; break;
1778                 case 4: edl->session->time_format = 5; break;
1779                 case 5: edl->session->time_format = 0; break;
1780         }
1782         gui->lock_window();
1783         gui->redraw_time_dependancies();
1787         char string[BCTEXTLEN], string2[BCTEXTLEN];
1788         sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
1789         gui->show_message(string, BLACK);
1790         gui->flush();
1791         gui->unlock_window();
1794 int MWindow::set_filename(char *filename)
1796         strcpy(session->filename, filename);
1797         if(gui)
1798         {
1799                 if(filename[0] == 0)
1800                 {
1801                         gui->set_title(PROGRAM_NAME);
1802                 }
1803                 else
1804                 {
1805                         FileSystem dir;
1806                         char string[1024], string2[1024];
1807                         dir.extract_name(string, filename);
1808                         sprintf(string2, PROGRAM_NAME ": %s", string);
1809                         gui->set_title(string2);
1810                 }
1811         }
1812         return 0; 
1822 int MWindow::set_loop_boundaries()
1824         double start = edl->local_session->get_selectionstart();
1825         double end = edl->local_session->get_selectionend();
1826         
1827         if(start != 
1828                 end) 
1829         {
1830                 ;
1831         }
1832         else
1833         if(edl->tracks->total_length())
1834         {
1835                 start = 0;
1836                 end = edl->tracks->total_length();
1837         }
1838         else
1839         {
1840                 start = end = 0;
1841         }
1843         if(edl->local_session->loop_playback && start != end)
1844         {
1845                 edl->local_session->loop_start = start;
1846                 edl->local_session->loop_end = end;
1847         }
1848         return 0; 
1857 int MWindow::reset_meters()
1859         cwindow->gui->lock_window();
1860         cwindow->gui->meters->reset_meters();
1861         cwindow->gui->unlock_window();
1863         vwindow->gui->lock_window();
1864         vwindow->gui->meters->reset_meters();
1865         vwindow->gui->unlock_window();
1867         lwindow->gui->lock_window();
1868         lwindow->gui->panel->reset_meters();
1869         lwindow->gui->unlock_window();
1871         gui->lock_window();
1872         gui->patchbay->reset_meters();
1873         gui->unlock_window();
1874         return 0;