• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files

hvirtual/cinelerra/mwindow.C

Go to the documentation of this file.
00001 #include "asset.h"
00002 #include "assets.h"
00003 #include "awindowgui.h"
00004 #include "awindow.h"
00005 #include "batchrender.h"
00006 #include "bcdisplayinfo.h"
00007 #include "bcsignals.h"
00008 #include "brender.h"
00009 #include "cache.h"
00010 #include "channel.h"
00011 #include "channeldb.h"
00012 #include "clip.h"
00013 #include "colormodels.h"
00014 #include "cplayback.h"
00015 #include "ctimebar.h"
00016 #include "cwindowgui.h"
00017 #include "cwindow.h"
00018 #include "bchash.h"
00019 #include "devicedvbinput.inc"
00020 #include "editpanel.h"
00021 #include "edl.h"
00022 #include "edlsession.h"
00023 #include "errorbox.h"
00024 #include "fileformat.h"
00025 #include "file.h"
00026 #include "filesystem.h"
00027 #include "filexml.h"
00028 #include "framecache.h"
00029 #include "gwindow.h"
00030 #include "gwindowgui.h"
00031 #include "indexfile.h"
00032 #include "interlacemodes.h"
00033 #include "language.h"
00034 #include "levelwindowgui.h"
00035 #include "levelwindow.h"
00036 #include "loadfile.inc"
00037 #include "localsession.h"
00038 #include "maincursor.h"
00039 #include "mainerror.h"
00040 #include "mainindexes.h"
00041 #include "mainmenu.h"
00042 #include "mainprogress.h"
00043 #include "mainsession.h"
00044 #include "mainundo.h"
00045 #include "mbuttons.h"
00046 #include "mutex.h"
00047 #include "mwindowgui.h"
00048 #include "mwindow.h"
00049 #include "new.h"
00050 #include "patchbay.h"
00051 #include "playback3d.h"
00052 #include "playbackengine.h"
00053 #include "plugin.h"
00054 #include "pluginserver.h"
00055 #include "pluginset.h"
00056 #include "preferences.h"
00057 #include "record.h"
00058 #include "recordlabel.h"
00059 #include "removethread.h"
00060 #include "render.h"
00061 #include "samplescroll.h"
00062 #include "sighandler.h"
00063 #include "splashgui.h"
00064 #include "statusbar.h"
00065 #include "theme.h"
00066 #include "threadloader.h"
00067 #include "timebar.h"
00068 #include "tipwindow.h"
00069 #include "trackcanvas.h"
00070 #include "track.h"
00071 #include "tracking.h"
00072 #include "trackscroll.h"
00073 #include "tracks.h"
00074 #include "transition.h"
00075 #include "transportque.h"
00076 #include "vframe.h"
00077 #include "videodevice.inc"
00078 #include "videowindow.h"
00079 #include "vplayback.h"
00080 #include "vwindowgui.h"
00081 #include "vwindow.h"
00082 #include "wavecache.h"
00083 #include "zoombar.h"
00084 #include "exportedl.h"
00085 
00086 #include <string.h>
00087 
00088 
00089 
00090 extern "C"
00091 {
00092 
00093 
00094 
00095 
00096 // Hack for libdv to remove glib dependancy
00097 
00098 // void
00099 // g_log (const char    *log_domain,
00100 //        int  log_level,
00101 //        const char    *format,
00102 //        ...)
00103 // {
00104 // }
00105 // 
00106 // void
00107 // g_logv (const char    *log_domain,
00108 //        int  log_level,
00109 //        const char    *format,
00110 //        ...)
00111 // {
00112 // }
00113 // 
00114 
00115 
00116 // Hack for XFree86 4.1.0
00117 
00118 int atexit(void (*function)(void))
00119 {
00120         return 0;
00121 }
00122 
00123 
00124 
00125 }
00126 
00127 
00128 
00129 MWindow::MWindow()
00130  : Thread(1, 0, 0)
00131 {
00132         plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
00133         brender_lock = new Mutex("MWindow::brender_lock");
00134         brender = 0;
00135         session = 0;
00136         channeldb_buz = new ChannelDB;
00137         channeldb_v4l2jpeg = new ChannelDB;
00138         dvb_input = 0;
00139         dvb_input_lock = new Mutex("MWindow::dvb_input_lock");
00140 }
00141 
00142 MWindow::~MWindow()
00143 {
00144         brender_lock->lock("MWindow::~MWindow");
00145         if(brender) delete brender;
00146         brender = 0;
00147         brender_lock->unlock();
00148         delete brender_lock;
00149 
00150         delete mainindexes;
00151 
00152 SET_TRACE
00153         clean_indexes();
00154 SET_TRACE
00155 
00156         save_defaults();
00157 SET_TRACE
00158 // Give up and go to a movie
00159         exit(0);
00160 
00161 SET_TRACE
00162         delete mainprogress;
00163         delete audio_cache;             // delete the cache after the assets
00164         delete video_cache;             // delete the cache after the assets
00165         delete frame_cache;
00166         if(gui) delete gui;
00167         delete undo;
00168         delete preferences;
00169         delete defaults;
00170         delete render;
00171 //      delete renderlist;
00172         delete awindow;
00173         delete vwindow;
00174         delete cwindow;
00175         delete lwindow;
00176         plugin_guis->remove_all_objects();
00177         delete plugin_guis;
00178         delete plugin_gui_lock;
00179 }
00180 
00181 void MWindow::init_error()
00182 {
00183         new MainError(this);
00184 }
00185 
00186 void MWindow::create_defaults_path(char *string)
00187 {
00188 // set the .bcast path
00189         FileSystem fs;
00190 
00191         sprintf(string, "%s", BCASTDIR);
00192         fs.complete_path(string);
00193         if(!fs.is_dir(string)) 
00194         {
00195                 fs.create_dir(string); 
00196         }
00197 
00198 // load the defaults
00199         strcat(string, "Cinelerra_rc");
00200 }
00201 
00202 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
00203 {
00204         char path[BCTEXTLEN];
00205 // Use user supplied path
00206         if(config_path[0])
00207         {
00208                 strcpy(path, config_path);
00209         }
00210         else
00211         {
00212                 create_defaults_path(path);
00213         }
00214 
00215         defaults = new BC_Hash(path);
00216         defaults->load();
00217 }
00218 
00219 void MWindow::init_plugin_path(Preferences *preferences, 
00220         ArrayList<PluginServer*>* &plugindb,
00221         FileSystem *fs,
00222         SplashGUI *splash_window,
00223         int *counter)
00224 {
00225         int result = 0;
00226         PluginServer *newplugin;
00227 
00228         if(!result)
00229         {
00230                 for(int i = 0; i < fs->dir_list.total; i++)
00231                 {
00232                         char path[BCTEXTLEN];
00233                         strcpy(path, fs->dir_list.values[i]->path);
00234 
00235 // File is a directory
00236                         if(fs->is_dir(path))
00237                         {
00238                                 continue;
00239                         }
00240                         else
00241                         {
00242 // Try to query the plugin
00243                                 fs->complete_path(path);
00244 //printf("MWindow::init_plugin_path %s\n", path);
00245                                 PluginServer *new_plugin = new PluginServer(path);
00246                                 int result = new_plugin->open_plugin(1, preferences, 0, 0, -1);
00247 
00248                                 if(!result)
00249                                 {
00250                                         plugindb->append(new_plugin);
00251                                         new_plugin->close_plugin();
00252                                         if(splash_window)
00253                                                 splash_window->operation->update(_(new_plugin->title));
00254                                 }
00255                                 else
00256                                 if(result == PLUGINSERVER_IS_LAD)
00257                                 {
00258                                         delete new_plugin;
00259 // Open LAD subplugins
00260                                         int id = 0;
00261                                         do
00262                                         {
00263                                                 new_plugin = new PluginServer(path);
00264                                                 result = new_plugin->open_plugin(1,
00265                                                         preferences,
00266                                                         0,
00267                                                         0,
00268                                                         id);
00269                                                 id++;
00270                                                 if(!result)
00271                                                 {
00272                                                         plugindb->append(new_plugin);
00273                                                         new_plugin->close_plugin();
00274                                                         if(splash_window)
00275                                                                 splash_window->operation->update(_(new_plugin->title));
00276                                                         else
00277                                                         {
00278                                                         }
00279                                                 }
00280                                         }while(!result);
00281                                 }
00282                                 else
00283                                 {
00284 // Plugin failed to open
00285                                         delete new_plugin;
00286                                 }
00287                         }
00288 
00289                         if(splash_window) splash_window->progress->update((*counter)++);
00290                 }
00291         }
00292 }
00293 
00294 void MWindow::init_plugins(Preferences *preferences, 
00295         ArrayList<PluginServer*>* &plugindb,
00296         SplashGUI *splash_window)
00297 {
00298         plugindb = new ArrayList<PluginServer*>;
00299 
00300 
00301 
00302         FileSystem cinelerra_fs;
00303         ArrayList<FileSystem*> lad_fs;
00304         int result = 0;
00305 
00306 // Get directories
00307         cinelerra_fs.set_filter("[*.plugin][*.so]");
00308         result = cinelerra_fs.update(preferences->global_plugin_dir);
00309 
00310         if(result)
00311         {
00312                 fprintf(stderr, 
00313                         _("MWindow::init_plugins: couldn't open %s directory\n"),
00314                         preferences->global_plugin_dir);
00315         }
00316 
00317 // Parse LAD environment variable
00318         char *env = getenv("LADSPA_PATH");
00319         if(env)
00320         {
00321                 char string[BCTEXTLEN];
00322                 char *ptr1 = env;
00323                 while(ptr1)
00324                 {
00325                         char *ptr = strchr(ptr1, ':');
00326                         char *end;
00327                         if(ptr)
00328                         {
00329                                 end = ptr;
00330                         }
00331                         else
00332                         {
00333                                 end = env + strlen(env);
00334                         }
00335 
00336                         if(end > ptr1)
00337                         {
00338                                 int len = end - ptr1;
00339                                 memcpy(string, ptr1, len);
00340                                 string[len] = 0;
00341 
00342 
00343                                 FileSystem *fs = new FileSystem;
00344                                 lad_fs.append(fs);
00345                                 fs->set_filter("*.so");
00346                                 result = fs->update(string);
00347 
00348                                 if(result)
00349                                 {
00350                                         fprintf(stderr, 
00351                                                 _("MWindow::init_plugins: couldn't open %s directory\n"),
00352                                                 string);
00353                                 }
00354                         }
00355 
00356                         if(ptr)
00357                                 ptr1 = ptr + 1;
00358                         else
00359                                 ptr1 = ptr;
00360                 };
00361         }
00362 
00363         int total = cinelerra_fs.total_files();
00364         int counter = 0;
00365         for(int i = 0; i < lad_fs.total; i++)
00366                 total += lad_fs.values[i]->total_files();
00367         if(splash_window) splash_window->progress->update_length(total);
00368 
00369 
00370 // Cinelerra
00371 #ifndef DO_STATIC
00372         init_plugin_path(preferences,
00373                 plugindb,
00374                 &cinelerra_fs,
00375                 splash_window,
00376                 &counter);
00377 #else
00378 // Call automatically generated routine to get plugins
00379 #endif
00380 
00381 // LAD
00382         for(int i = 0; i < lad_fs.total; i++)
00383                 init_plugin_path(preferences,
00384                         plugindb,
00385                         lad_fs.values[i],
00386                         splash_window,
00387                         &counter);
00388 
00389         lad_fs.remove_all_objects();
00390 }
00391 
00392 void MWindow::delete_plugins()
00393 {
00394         for(int i = 0; i < plugindb->total; i++)
00395         {
00396                 delete plugindb->values[i];
00397         }
00398         delete plugindb;
00399 }
00400 
00401 void MWindow::create_plugindb(int do_audio, 
00402                 int do_video, 
00403                 int is_realtime, 
00404                 int is_transition,
00405                 int is_theme,
00406                 ArrayList<PluginServer*> &plugindb)
00407 {
00408 // Get plugins
00409         for(int i = 0; i < this->plugindb->total; i++)
00410         {
00411                 PluginServer *current = this->plugindb->values[i];
00412 
00413                 if(current->audio == do_audio &&
00414                         current->video == do_video &&
00415                         (current->realtime == is_realtime || is_realtime < 0) &&
00416                         current->transition == is_transition &&
00417                         current->theme == is_theme)
00418                         plugindb.append(current);
00419         }
00420 
00421 // Alphabetize list by title
00422         int done = 0;
00423         while(!done)
00424         {
00425                 done = 1;
00426                 
00427                 for(int i = 0; i < plugindb.total - 1; i++)
00428                 {
00429                         PluginServer *value1 = plugindb.values[i];
00430                         PluginServer *value2 = plugindb.values[i + 1];
00431                         if(strcmp(_(value1->title), _(value2->title)) > 0)
00432                         {
00433                                 done = 0;
00434                                 plugindb.values[i] = value2;
00435                                 plugindb.values[i + 1] = value1;
00436                         }
00437                 }
00438         }
00439 }
00440 
00441 PluginServer* MWindow::scan_plugindb(char *title,
00442                 int data_type)
00443 {
00444         if(data_type < 0)
00445         {
00446                 printf("MWindow::scan_plugindb data_type < 0\n");
00447                 return 0;
00448         }
00449 
00450         for(int i = 0; i < plugindb->total; i++)
00451         {
00452                 PluginServer *server = plugindb->values[i];
00453                 if(!strcasecmp(server->title, title) &&
00454                 ((data_type == TRACK_AUDIO && server->audio) ||
00455                 (data_type == TRACK_VIDEO && server->video))) 
00456                         return plugindb->values[i];
00457         }
00458         return 0;
00459 }
00460 
00461 void MWindow::init_preferences()
00462 {
00463         preferences = new Preferences;
00464         preferences->load_defaults(defaults);
00465         session = new MainSession(this);
00466         session->load_defaults(defaults);
00467 }
00468 
00469 void MWindow::clean_indexes()
00470 {
00471         FileSystem fs;
00472         int total_excess;
00473         long oldest;
00474         int oldest_item = -1;
00475         int result;
00476         char string[BCTEXTLEN];
00477         char string2[BCTEXTLEN];
00478 
00479 // Delete extra indexes
00480         fs.set_filter("*.idx");
00481         fs.complete_path(preferences->index_directory);
00482         fs.update(preferences->index_directory);
00483 //printf("MWindow::clean_indexes 1 %d\n", fs.dir_list.total);
00484 
00485 // Eliminate directories
00486         result = 1;
00487         while(result)
00488         {
00489                 result = 0;
00490                 for(int i = 0; i < fs.dir_list.total && !result; i++)
00491                 {
00492                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
00493                         if(fs.is_dir(string))
00494                         {
00495                                 delete fs.dir_list.values[i];
00496                                 fs.dir_list.remove_number(i);
00497                                 result = 1;
00498                         }
00499                 }
00500         }
00501         total_excess = fs.dir_list.total - preferences->index_count;
00502 
00503 //printf("MWindow::clean_indexes 2 %d\n", fs.dir_list.total);
00504         while(total_excess > 0)
00505         {
00506 // Get oldest
00507                 for(int i = 0; i < fs.dir_list.total; i++)
00508                 {
00509                         fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
00510 
00511                         if(i == 0 || fs.get_date(string) <= oldest)
00512                         {
00513                                 oldest = fs.get_date(string);
00514                                 oldest_item = i;
00515                         }
00516                 }
00517 
00518                 if(oldest_item >= 0)
00519                 {
00520 // Remove index file
00521                         fs.join_names(string, 
00522                                 preferences->index_directory, 
00523                                 fs.dir_list.values[oldest_item]->name);
00524 //printf("MWindow::clean_indexes 1 %s\n", string);
00525                         if(remove(string))
00526                                 perror("delete_indexes");
00527                         delete fs.dir_list.values[oldest_item];
00528                         fs.dir_list.remove_number(oldest_item);
00529 
00530 // Remove table of contents if it exists
00531                         strcpy(string2, string);
00532                         char *ptr = strrchr(string2, '.');
00533                         if(ptr)
00534                         {
00535 //printf("MWindow::clean_indexes 2 %s\n", string2);
00536                                 sprintf(ptr, ".toc");
00537                                 remove(string2);
00538                         }
00539                 }
00540 
00541                 total_excess--;
00542         }
00543 }
00544 
00545 void MWindow::init_awindow()
00546 {
00547         awindow = new AWindow(this);
00548         awindow->create_objects();
00549 }
00550 
00551 void MWindow::init_gwindow()
00552 {
00553         gwindow = new GWindow(this);
00554         gwindow->create_objects();
00555 }
00556 
00557 void MWindow::init_tipwindow()
00558 {
00559         twindow = new TipWindow(this);
00560         twindow->start();
00561 }
00562 
00563 void MWindow::init_theme()
00564 {
00565         theme = 0;
00566 
00567 // Replace blond theme with SUV since it doesn't work
00568         if(!strcasecmp(preferences->theme, "Blond"))
00569                 strcpy(preferences->theme, DEFAULT_THEME);
00570 
00571         for(int i = 0; i < plugindb->total; i++)
00572         {
00573                 if(plugindb->values[i]->theme &&
00574                         !strcasecmp(preferences->theme, plugindb->values[i]->title))
00575                 {
00576                         PluginServer plugin = *plugindb->values[i];
00577                         plugin.open_plugin(0, preferences, 0, 0, -1);
00578                         theme = plugin.new_theme();
00579                         theme->mwindow = this;
00580                         strcpy(theme->path, plugin.path);
00581                         plugin.close_plugin();
00582                 }
00583         }
00584 
00585         if(!theme)
00586         {
00587                 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
00588                 exit(1);
00589         }
00590 
00591 // Load images which may have been forgotten
00592         theme->Theme::initialize();
00593 // Load user images
00594         theme->initialize();
00595 // Create menus with user colors
00596         theme->build_menus();
00597         init_menus();
00598 
00599         theme->check_used();
00600 }
00601 
00602 void MWindow::init_3d()
00603 {
00604         playback_3d = new Playback3D(this);
00605         playback_3d->create_objects();
00606 }
00607 
00608 void MWindow::init_edl()
00609 {
00610         edl = new EDL;
00611         edl->create_objects();
00612     edl->load_defaults(defaults);
00613         edl->create_default_tracks();
00614         edl->tracks->update_y_pixels(theme);
00615 }
00616 
00617 void MWindow::init_compositor()
00618 {
00619         cwindow = new CWindow(this);
00620     cwindow->create_objects();
00621 }
00622 
00623 void MWindow::init_levelwindow()
00624 {
00625         lwindow = new LevelWindow(this);
00626         lwindow->create_objects();
00627 }
00628 
00629 void MWindow::init_viewer()
00630 {
00631         vwindow = new VWindow(this);
00632         vwindow->load_defaults();
00633         vwindow->create_objects();
00634 }
00635 
00636 void MWindow::init_cache()
00637 {
00638         audio_cache = new CICache(preferences, plugindb);
00639         video_cache = new CICache(preferences, plugindb);
00640         frame_cache = new FrameCache;
00641         wave_cache = new WaveCache;
00642 }
00643 
00644 void MWindow::init_channeldb()
00645 {
00646         channeldb_buz->load("channeldb_buz");
00647         channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
00648 }
00649 
00650 void MWindow::init_menus()
00651 {
00652         char string[BCTEXTLEN];
00653 
00654         // Color Models
00655         cmodel_to_text(string, BC_RGB888);
00656         colormodels.append(new ColormodelItem(string, BC_RGB888));
00657         cmodel_to_text(string, BC_RGBA8888);
00658         colormodels.append(new ColormodelItem(string, BC_RGBA8888));
00659 //      cmodel_to_text(string, BC_RGB161616);
00660 //      colormodels.append(new ColormodelItem(string, BC_RGB161616));
00661 //      cmodel_to_text(string, BC_RGBA16161616);
00662 //      colormodels.append(new ColormodelItem(string, BC_RGBA16161616));
00663         cmodel_to_text(string, BC_RGB_FLOAT);
00664         colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
00665         cmodel_to_text(string, BC_RGBA_FLOAT);
00666         colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
00667         cmodel_to_text(string, BC_YUV888);
00668         colormodels.append(new ColormodelItem(string, BC_YUV888));
00669         cmodel_to_text(string, BC_YUVA8888);
00670         colormodels.append(new ColormodelItem(string, BC_YUVA8888));
00671 //      cmodel_to_text(string, BC_YUV161616);
00672 //      colormodels.append(new ColormodelItem(string, BC_YUV161616));
00673 //      cmodel_to_text(string, BC_YUVA16161616);
00674 //      colormodels.append(new ColormodelItem(string, BC_YUVA16161616));
00675 
00676 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
00677                            interlace_project_modes.append(new InterlacemodeItem(string, x));
00678 
00679 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
00680                            interlace_asset_modes.append(new InterlacemodeItem(string, x));
00681 
00682 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
00683                            interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
00684 
00685         // Interlacing Modes
00686         ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
00687 
00688         ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
00689         ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
00690 
00691         ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
00692         ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
00693 
00694         ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
00695         ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
00696 
00697         // Interlacing Fixing Methods
00698         ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
00699         ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
00700         ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
00701 }
00702 
00703 void MWindow::init_indexes()
00704 {
00705         mainindexes = new MainIndexes(this);
00706         mainindexes->start_loop();
00707 }
00708 
00709 void MWindow::init_gui()
00710 {
00711         gui = new MWindowGUI(this);
00712         gui->create_objects();
00713         gui->load_defaults(defaults);
00714 }
00715 
00716 void MWindow::init_signals()
00717 {
00718         sighandler = new SigHandler;
00719         sighandler->initialize();
00720 ENABLE_BUFFER
00721 }
00722 
00723 void MWindow::init_render()
00724 {
00725         render = new Render(this);
00726 //      renderlist = new Render(this);
00727         batch_render = new BatchRenderThread(this);
00728 }
00729 
00730 void MWindow::init_exportedl()
00731 {
00732         exportedl = new ExportEDL(this);
00733 }
00734 
00735 void MWindow::init_brender()
00736 {
00737         if(preferences->use_brender && !brender)
00738         {
00739                 brender_lock->lock("MWindow::init_brender 1");
00740                 brender = new BRender(this);
00741                 brender->initialize();
00742                 session->brender_end = 0;
00743                 brender_lock->unlock();
00744         }
00745         else
00746         if(!preferences->use_brender && brender)
00747         {
00748                 brender_lock->lock("MWindow::init_brender 2");
00749                 delete brender;
00750                 brender = 0;
00751                 session->brender_end = 0;
00752                 brender_lock->unlock();
00753         }
00754         if(brender) brender->restart(edl);
00755 }
00756 
00757 void MWindow::restart_brender()
00758 {
00759 //printf("MWindow::restart_brender 1\n");
00760         if(brender) brender->restart(edl);
00761 }
00762 
00763 void MWindow::stop_brender()
00764 {
00765         if(brender) brender->stop();
00766 }
00767 
00768 int MWindow::brender_available(int position)
00769 {
00770         int result = 0;
00771         brender_lock->lock("MWindow::brender_available 1");
00772         if(brender)
00773         {
00774                 if(brender->map_valid)
00775                 {
00776                         brender->map_lock->lock("MWindow::brender_available 2");
00777                         if(position < brender->map_size &&
00778                                 position >= 0)
00779                         {
00780 //printf("MWindow::brender_available 1 %d %d\n", position, brender->map[position]);
00781                                 if(brender->map[position] == BRender::RENDERED)
00782                                         result = 1;
00783                         }
00784                         brender->map_lock->unlock();
00785                 }
00786         }
00787         brender_lock->unlock();
00788         return result;
00789 }
00790 
00791 void MWindow::set_brender_start()
00792 {
00793         edl->session->brender_start = edl->local_session->get_selectionstart();
00794         restart_brender();
00795         gui->canvas->draw_overlays();
00796         gui->canvas->flash();
00797 }
00798 
00799 
00800 
00801 int MWindow::load_filenames(ArrayList<char*> *filenames, 
00802         int load_mode,
00803         int update_filename,
00804         char *reel_name,
00805         int reel_number,
00806         int overwrite_reel)
00807 {
00808 SET_TRACE
00809         ArrayList<EDL*> new_edls;
00810         ArrayList<Asset*> new_assets;
00811         ArrayList<File*> new_files;
00812 
00813         save_defaults();
00814         gui->start_hourglass();
00815 
00816 // Need to stop playback since tracking depends on the EDL not getting
00817 // deleted.
00818         cwindow->playback_engine->que->send_command(STOP,
00819                 CHANGE_NONE, 
00820                 0,
00821                 0);
00822         vwindow->playback_engine->que->send_command(STOP,
00823                 CHANGE_NONE, 
00824                 0,
00825                 0);
00826         cwindow->playback_engine->interrupt_playback(0);
00827         vwindow->playback_engine->interrupt_playback(0);
00828 
00829 
00830 
00831 // Define new_edls and new_assets to load
00832         int result = 0;
00833         for(int i = 0; i < filenames->total; i++)
00834         {
00835 // Get type of file
00836                 File *new_file = new File;
00837                 Asset *new_asset = new Asset(filenames->values[i]);
00838                 EDL *new_edl = new EDL;
00839                 char string[BCTEXTLEN];
00840 
00841 // Set reel name and number for the asset
00842 // If the user wants to overwrite the last used reel number for the clip,
00843 // we have to rebuild the index for the file
00844 
00845                 if(overwrite_reel)
00846                 {
00847                         char source_filename[BCTEXTLEN];
00848                         char index_filename[BCTEXTLEN];
00849                         
00850                         strcpy(new_asset->reel_name, reel_name);
00851                         new_asset->reel_number = reel_number;
00852 
00853                         IndexFile::get_index_filename(source_filename,
00854                                 preferences->index_directory,
00855                                 index_filename,
00856                                 new_asset->path);
00857                         remove(index_filename);
00858                         new_asset->index_status = INDEX_NOTTESTED;
00859                 }
00860                 
00861                 new_edl->create_objects();
00862                 new_edl->copy_session(edl);
00863 
00864                 sprintf(string, "Loading %s", new_asset->path);
00865                 gui->show_message(string);
00866 SET_TRACE
00867                 result = new_file->open_file(preferences, new_asset, 1, 0, 0, 0);
00868 SET_TRACE
00869 
00870                 switch(result)
00871                 {
00872 // Convert media file to EDL
00873                         case FILE_OK:
00874 // Warn about odd image dimensions
00875                                 if(new_asset->video_data &&
00876                                         ((new_asset->width % 2) ||
00877                                         (new_asset->height % 2)))
00878                                 {
00879                                         char string[BCTEXTLEN];
00880                                         sprintf(string, "%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly.",
00881                                                 new_asset->path,
00882                                                 new_asset->width,
00883                                                 new_asset->height);
00884                                         MainError::show_error(string);
00885                                 }
00886 
00887 
00888                                 if(load_mode != LOAD_RESOURCESONLY)
00889                                 {
00890 SET_TRACE
00891                                         asset_to_edl(new_edl, new_asset);
00892 SET_TRACE
00893                                         new_edls.append(new_edl);
00894 SET_TRACE
00895                                         Garbage::delete_object(new_asset);
00896                                         new_asset = 0;
00897 SET_TRACE
00898                                 }
00899                                 else
00900                                 {
00901                                         new_assets.append(new_asset);
00902                                 }
00903 
00904 // Set filename to nothing for assets since save EDL would overwrite them.
00905                                 if(load_mode == LOAD_REPLACE || 
00906                                         load_mode == LOAD_REPLACE_CONCATENATE)
00907                                 {
00908                                         set_filename("");
00909 // Reset timeline position
00910                                         new_edl->local_session->view_start = 0;
00911                                         new_edl->local_session->track_start = 0;
00912                                 }
00913 
00914                                 result = 0;
00915                                 break;
00916 
00917 // File not found
00918                         case FILE_NOT_FOUND:
00919                                 sprintf(string, _("Failed to open %s"), new_asset->path);
00920                                 gui->show_message(string, theme->message_error);
00921                                 result = 1;
00922                                 break;
00923 
00924 // Unknown format
00925                         case FILE_UNRECOGNIZED_CODEC:
00926                         {
00927 // Test index file
00928                                 IndexFile indexfile(this);
00929                                 result = indexfile.open_index(this, new_asset);
00930                                 if(!result)
00931                                 {
00932                                         indexfile.close_index();
00933                                 }
00934 
00935 // Test existing EDLs
00936                                 if(result)
00937                                 {
00938                                         for(int j = 0; j < new_edls.total + 1; j++)
00939                                         {
00940                                                 Asset *old_asset;
00941                                                 if(j == new_edls.total)
00942                                                 {
00943                                                         if(old_asset = edl->assets->get_asset(new_asset->path))
00944                                                         {
00945                                                                 *new_asset = *old_asset;
00946                                                                 result = 0;
00947                                                         }
00948                                                 }
00949                                                 else
00950                                                 {
00951                                                         if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
00952                                                         {
00953                                                                 *new_asset = *old_asset;
00954                                                                 result = 0;
00955                                                         }
00956                                                 }
00957                                         }
00958                                 }
00959 
00960 // Prompt user
00961                                 if(result)
00962                                 {
00963                                         char string[BCTEXTLEN];
00964                                         FileSystem fs;
00965                                         fs.extract_name(string, new_asset->path);
00966 
00967                                         strcat(string, _("'s format couldn't be determined."));
00968                                         new_asset->audio_data = 1;
00969                                         new_asset->format = FILE_PCM;
00970                                         new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
00971                                         new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
00972                                         new_asset->bits = defaults->get("AUDIO_BITS", 16);
00973                                         new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
00974                                         new_asset->signed_ = defaults->get("SIGNED_", 1);
00975                                         new_asset->header = defaults->get("HEADER", 0);
00976 
00977                                         FileFormat fwindow(this);
00978                                         fwindow.create_objects(new_asset, string);
00979                                         result = fwindow.run_window();
00980 
00981