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 "brender.h"
00008 #include "cache.h"
00009 #include "channel.h"
00010 #include "channeldb.h"
00011 #include "clip.h"
00012 #include "colormodels.h"
00013 #include "cplayback.h"
00014 #include "ctimebar.h"
00015 #include "cwindowgui.h"
00016 #include "cwindow.h"
00017 #include "defaults.h"
00018 #include "editpanel.h"
00019 #include "edl.h"
00020 #include "edlsession.h"
00021 #include "errorbox.h"
00022 #include "fileformat.h"
00023 #include "file.h"
00024 #include "filesystem.h"
00025 #include "filexml.h"
00026 #include "gwindow.h"
00027 #include "gwindowgui.h"
00028 #include "indexfile.h"
00029 #include "interlacemodes.h"
00030 #include "language.h"
00031 #include "levelwindowgui.h"
00032 #include "levelwindow.h"
00033 #include "loadfile.inc"
00034 #include "localsession.h"
00035 #include "maincursor.h"
00036 #include "mainindexes.h"
00037 #include "mainmenu.h"
00038 #include "mainprogress.h"
00039 #include "mainsession.h"
00040 #include "mainundo.h"
00041 #include "mbuttons.h"
00042 #include "mutex.h"
00043 #include "mwindowgui.h"
00044 #include "mwindow.h"
00045 #include "new.h"
00046 #include "patchbay.h"
00047 #include "playbackengine.h"
00048 #include "plugin.h"
00049 #include "pluginserver.h"
00050 #include "pluginset.h"
00051 #include "preferences.h"
00052 #include "record.h"
00053 #include "recordlabel.h"
00054 #include "render.h"
00055 #include "samplescroll.h"
00056 #include "sighandler.h"
00057 #include "splashgui.h"
00058 #include "statusbar.h"
00059 #include "theme.h"
00060 #include "threadloader.h"
00061 #include "timebar.h"
00062 #include "tipwindow.h"
00063 #include "trackcanvas.h"
00064 #include "track.h"
00065 #include "tracking.h"
00066 #include "trackscroll.h"
00067 #include "tracks.h"
00068 #include "transition.h"
00069 #include "transportque.h"
00070 #include "vframe.h"
00071 #include "videodevice.inc"
00072 #include "videowindow.h"
00073 #include "vplayback.h"
00074 #include "vwindowgui.h"
00075 #include "vwindow.h"
00076 #include "zoombar.h"
00077
00078 #include <string.h>
00079
00080
00081
00082 extern "C"
00083 {
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 int atexit(void (*function)(void))
00111 {
00112 return 0;
00113 }
00114
00115
00116
00117 }
00118
00119
00120
00121
00122
00123 MWindow::MWindow()
00124 {
00125 plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
00126 brender_lock = new Mutex("MWindow::brender_lock");
00127 brender = 0;
00128 session = 0;
00129 channeldb_buz = new ChannelDB;
00130 channeldb_v4l2jpeg = new ChannelDB;
00131 }
00132
00133 MWindow::~MWindow()
00134 {
00135 brender_lock->lock("MWindow::~MWindow");
00136 if(brender) delete brender;
00137 brender = 0;
00138 brender_lock->unlock();
00139 delete brender_lock;
00140
00141 delete mainindexes;
00142
00143 TRACE("MWindow::~MWindow 1\n");
00144 clean_indexes();
00145 TRACE("MWindow::~MWindow 2\n");
00146
00147 save_defaults();
00148 TRACE("MWindow::~MWindow 3\n");
00149
00150 exit(0);
00151
00152 TRACE("MWindow::~MWindow 4\n");
00153 delete mainprogress;
00154 delete audio_cache;
00155 delete video_cache;
00156 if(gui) delete gui;
00157 delete undo;
00158 delete preferences;
00159 delete defaults;
00160 delete render;
00161
00162 delete awindow;
00163 delete vwindow;
00164 delete cwindow;
00165 delete lwindow;
00166 plugin_guis->remove_all_objects();
00167 delete plugin_guis;
00168 delete plugin_gui_lock;
00169 }
00170
00171 void MWindow::init_defaults(Defaults* &defaults, char *config_path)
00172 {
00173 char path[BCTEXTLEN];
00174
00175 if(config_path[0])
00176 {
00177 strcpy(path, config_path);
00178 }
00179 else
00180 {
00181
00182 FileSystem fs;
00183
00184 sprintf(path, "%s", BCASTDIR);
00185 fs.complete_path(path);
00186 if(fs.is_dir(path))
00187 {
00188 fs.create_dir(path);
00189 }
00190
00191
00192 strcat(path, "Cinelerra_rc");
00193 }
00194
00195 defaults = new Defaults(path);
00196 defaults->load();
00197 }
00198
00199 void MWindow::init_plugin_path(Preferences *preferences,
00200 ArrayList<PluginServer*>* &plugindb,
00201 FileSystem *fs,
00202 SplashGUI *splash_window,
00203 int *counter)
00204 {
00205 int result = 0;
00206 PluginServer *newplugin;
00207
00208 if(!result)
00209 {
00210 for(int i = 0; i < fs->dir_list.total; i++)
00211 {
00212 char path[BCTEXTLEN];
00213 strcpy(path, fs->dir_list.values[i]->path);
00214
00215
00216 if(!fs->is_dir(path))
00217 {
00218 continue;
00219 }
00220 else
00221 {
00222
00223 fs->complete_path(path);
00224
00225 PluginServer *new_plugin = new PluginServer(path);
00226 int result = new_plugin->open_plugin(1, preferences, 0, 0, -1);
00227
00228 if(!result)
00229 {
00230 plugindb->append(new_plugin);
00231 new_plugin->close_plugin();
00232 if(splash_window)
00233 splash_window->operation->update(_(new_plugin->title));
00234 }
00235 else
00236 if(result == PLUGINSERVER_IS_LAD)
00237 {
00238 delete new_plugin;
00239
00240 int id = 0;
00241 do
00242 {
00243 new_plugin = new PluginServer(path);
00244 result = new_plugin->open_plugin(1,
00245 preferences,
00246 0,
00247 0,
00248 id);
00249 id++;
00250 if(!result)
00251 {
00252 plugindb->append(new_plugin);
00253 new_plugin->close_plugin();
00254 if(splash_window)
00255 splash_window->operation->update(_(new_plugin->title));
00256 }
00257 }while(!result);
00258 }
00259 else
00260 {
00261
00262 delete new_plugin;
00263 }
00264 }
00265 if(splash_window) splash_window->progress->update((*counter)++);
00266 }
00267 }
00268 }
00269
00270 void MWindow::init_plugins(Preferences *preferences,
00271 ArrayList<PluginServer*>* &plugindb,
00272 SplashGUI *splash_window)
00273 {
00274 plugindb = new ArrayList<PluginServer*>;
00275
00276
00277
00278 FileSystem cinelerra_fs;
00279 ArrayList<FileSystem*> lad_fs;
00280 int result = 0;
00281
00282
00283 cinelerra_fs.set_filter("[*.plugin][*.so]");
00284 result = cinelerra_fs.update(preferences->global_plugin_dir);
00285
00286 if(result)
00287 {
00288 fprintf(stderr,
00289 _("MWindow::init_plugins: couldn't open %s directory\n"),
00290 preferences->global_plugin_dir);
00291 }
00292
00293
00294 char *env = getenv("LADSPA_PATH");
00295 if(env)
00296 {
00297 char string[BCTEXTLEN];
00298 char *ptr1 = env;
00299 while(ptr1)
00300 {
00301 char *ptr = strchr(ptr1, ':');
00302 char *end;
00303 if(ptr)
00304 {
00305 end = ptr;
00306 }
00307 else
00308 {
00309 end = env + strlen(env);
00310 }
00311
00312 if(end > ptr1)
00313 {
00314 int len = end - ptr1;
00315 memcpy(string, ptr1, len);
00316 string[len] = 0;
00317
00318
00319 FileSystem *fs = new FileSystem;
00320 lad_fs.append(fs);
00321 fs->set_filter("*.so");
00322 result = fs->update(string);
00323
00324 if(result)
00325 {
00326 fprintf(stderr,
00327 _("MWindow::init_plugins: couldn't open %s directory\n"),
00328 string);
00329 }
00330 }
00331
00332 if(ptr)
00333 ptr1 = ptr + 1;
00334 else
00335 ptr1 = ptr;
00336 };
00337 }
00338
00339 int total = cinelerra_fs.total_files();
00340 int counter = 0;
00341 for(int i = 0; i < lad_fs.total; i++)
00342 total += lad_fs.values[i]->total_files();
00343 if(splash_window) splash_window->progress->update_length(total);
00344
00345
00346 #ifndef DO_STATIC
00347 init_plugin_path(preferences,
00348 plugindb,
00349 &cinelerra_fs,
00350 splash_window,
00351 &counter);
00352 #else
00353
00354 #endif
00355
00356
00357 for(int i = 0; i < lad_fs.total; i++)
00358 init_plugin_path(preferences,
00359 plugindb,
00360 lad_fs.values[i],
00361 splash_window,
00362 &counter);
00363
00364 lad_fs.remove_all_objects();
00365 }
00366
00367 void MWindow::delete_plugins()
00368 {
00369 for(int i = 0; i < plugindb->total; i++)
00370 {
00371 delete plugindb->values[i];
00372 }
00373 delete plugindb;
00374 }
00375
00376 void MWindow::create_plugindb(int do_audio,
00377 int do_video,
00378 int is_realtime,
00379 int is_transition,
00380 int is_theme,
00381 ArrayList<PluginServer*> &plugindb)
00382 {
00383
00384 for(int i = 0; i < this->plugindb->total; i++)
00385 {
00386 PluginServer *current = this->plugindb->values[i];
00387
00388 if(current->audio == do_audio &&
00389 current->video == do_video &&
00390 (current->realtime == is_realtime || is_realtime < 0) &&
00391 current->transition == is_transition &&
00392 current->theme == is_theme)
00393 plugindb.append(current);
00394 }
00395
00396
00397 int done = 0;
00398 while(!done)
00399 {
00400 done = 1;
00401
00402 for(int i = 0; i < plugindb.total - 1; i++)
00403 {
00404 PluginServer *value1 = plugindb.values[i];
00405 PluginServer *value2 = plugindb.values[i + 1];
00406 if(strcmp(_(value1->title), _(value2->title)) > 0)
00407 {
00408 done = 0;
00409 plugindb.values[i] = value2;
00410 plugindb.values[i + 1] = value1;
00411 }
00412 }
00413 }
00414 }
00415
00416 PluginServer* MWindow::scan_plugindb(char *title,
00417 int data_type)
00418 {
00419 if(data_type < 0)
00420 {
00421 printf("MWindow::scan_plugindb data_type < 0\n");
00422 return 0;
00423 }
00424
00425 for(int i = 0; i < plugindb->total; i++)
00426 {
00427 PluginServer *server = plugindb->values[i];
00428 if(!strcasecmp(server->title, title) &&
00429 ((data_type == TRACK_AUDIO && server->audio) ||
00430 (data_type == TRACK_VIDEO && server->video)))
00431 return plugindb->values[i];
00432 }
00433 return 0;
00434 }
00435
00436 void MWindow::init_preferences()
00437 {
00438 preferences = new Preferences;
00439 preferences->load_defaults(defaults);
00440 session = new MainSession(this);
00441 session->load_defaults(defaults);
00442 }
00443
00444 void MWindow::clean_indexes()
00445 {
00446 FileSystem fs;
00447 int total_excess;
00448 long oldest;
00449 int oldest_item = -1;
00450 int result;
00451 char string[BCTEXTLEN];
00452 char string2[BCTEXTLEN];
00453
00454
00455 fs.set_filter("*.idx");
00456 fs.complete_path(preferences->index_directory);
00457 fs.update(preferences->index_directory);
00458
00459
00460
00461 result = 1;
00462 while(result)
00463 {
00464 result = 0;
00465 for(int i = 0; i < fs.dir_list.total && !result; i++)
00466 {
00467 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
00468 if(!fs.is_dir(string))
00469 {
00470 delete fs.dir_list.values[i];
00471 fs.dir_list.remove_number(i);
00472 result = 1;
00473 }
00474 }
00475 }
00476 total_excess = fs.dir_list.total - preferences->index_count;
00477
00478
00479 while(total_excess > 0)
00480 {
00481
00482 for(int i = 0; i < fs.dir_list.total; i++)
00483 {
00484 fs.join_names(string, preferences->index_directory, fs.dir_list.values[i]->name);
00485
00486 if(i == 0 || fs.get_date(string) <= oldest)
00487 {
00488 oldest = fs.get_date(string);
00489 oldest_item = i;
00490 }
00491 }
00492
00493 if(oldest_item >= 0)
00494 {
00495
00496 fs.join_names(string,
00497 preferences->index_directory,
00498 fs.dir_list.values[oldest_item]->name);
00499
00500 if(remove(string))
00501 perror("delete_indexes");
00502 delete fs.dir_list.values[oldest_item];
00503 fs.dir_list.remove_number(oldest_item);
00504
00505
00506 strcpy(string2, string);
00507 char *ptr = strrchr(string2, '.');
00508 if(ptr)
00509 {
00510
00511 sprintf(ptr, ".toc");
00512 remove(string2);
00513 }
00514 }
00515
00516 total_excess--;
00517 }
00518 }
00519
00520 void MWindow::init_awindow()
00521 {
00522 awindow = new AWindow(this);
00523 awindow->create_objects();
00524 }
00525
00526 void MWindow::init_gwindow()
00527 {
00528 gwindow = new GWindow(this);
00529 gwindow->create_objects();
00530 }
00531
00532 void MWindow::init_tipwindow()
00533 {
00534 twindow = new TipWindow(this);
00535 twindow->start();
00536 }
00537
00538 void MWindow::init_theme()
00539 {
00540 theme = 0;
00541
00542
00543 if(!strcasecmp(preferences->theme, "Blond"))
00544 strcpy(preferences->theme, DEFAULT_THEME);
00545
00546 for(int i = 0; i < plugindb->total; i++)
00547 {
00548 if(plugindb->values[i]->theme &&
00549 !strcasecmp(preferences->theme, plugindb->values[i]->title))
00550 {
00551 PluginServer plugin = *plugindb->values[i];
00552 plugin.open_plugin(0, preferences, 0, 0, -1);
00553 theme = plugin.new_theme();
00554 theme->mwindow = this;
00555 strcpy(theme->path, plugin.path);
00556 plugin.close_plugin();
00557 }
00558 }
00559
00560 if(!theme)
00561 {
00562 fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
00563 exit(1);
00564 }
00565
00566
00567 theme->Theme::initialize();
00568
00569 theme->initialize();
00570
00571 theme->build_menus();
00572 init_menus();
00573
00574 theme->check_used();
00575 }
00576
00577 void MWindow::init_edl()
00578 {
00579 edl = new EDL;
00580 edl->create_objects();
00581 edl->load_defaults(defaults);
00582 edl->create_default_tracks();
00583 edl->tracks->update_y_pixels(theme);
00584 }
00585
00586 void MWindow::init_compositor()
00587 {
00588 cwindow = new CWindow(this);
00589 cwindow->create_objects();
00590 }
00591
00592 void MWindow::init_levelwindow()
00593 {
00594 lwindow = new LevelWindow(this);
00595 lwindow->create_objects();
00596 }
00597
00598 void MWindow::init_viewer()
00599 {
00600 vwindow = new VWindow(this);
00601 vwindow->load_defaults();
00602 vwindow->create_objects();
00603 }
00604
00605 void MWindow::init_cache()
00606 {
00607 audio_cache = new CICache(edl, preferences, plugindb);
00608 video_cache = new CICache(edl, preferences, plugindb);
00609 }
00610
00611 void MWindow::init_channeldb()
00612 {
00613 channeldb_buz->load("channeldb_buz");
00614 channeldb_v4l2jpeg->load("channeldb_v4l2jpeg");
00615 }
00616
00617 void MWindow::init_menus()
00618 {
00619 char string[BCTEXTLEN];
00620
00621
00622 cmodel_to_text(string, BC_RGB888);
00623 colormodels.append(new ColormodelItem(string, BC_RGB888));
00624 cmodel_to_text(string, BC_RGBA8888);
00625 colormodels.append(new ColormodelItem(string, BC_RGBA8888));
00626
00627
00628
00629
00630 cmodel_to_text(string, BC_RGB_FLOAT);
00631 colormodels.append(new ColormodelItem(string, BC_RGB_FLOAT));
00632 cmodel_to_text(string, BC_RGBA_FLOAT);
00633 colormodels.append(new ColormodelItem(string, BC_RGBA_FLOAT));
00634 cmodel_to_text(string, BC_YUV888);
00635 colormodels.append(new ColormodelItem(string, BC_YUV888));
00636 cmodel_to_text(string, BC_YUVA8888);
00637 colormodels.append(new ColormodelItem(string, BC_YUVA8888));
00638
00639
00640
00641
00642
00643 #define ILACEPROJECTMODELISTADD(x) ilacemode_to_text(string, x); \
00644 interlace_project_modes.append(new InterlacemodeItem(string, x));
00645
00646 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
00647 interlace_asset_modes.append(new InterlacemodeItem(string, x));
00648
00649 #define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
00650 interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
00651
00652
00653 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED);
00654
00655 ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
00656 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
00657
00658 ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
00659 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
00660
00661 ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
00662 ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
00663
00664
00665 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
00666 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
00667 ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
00668 }
00669
00670 void MWindow::init_indexes()
00671 {
00672 mainindexes = new MainIndexes(this);
00673 mainindexes->start_loop();
00674 }
00675
00676 void MWindow::init_gui()
00677 {
00678 gui = new MWindowGUI(this);
00679 gui->create_objects();
00680 gui->load_defaults(defaults);
00681 }
00682
00683 void MWindow::init_signals()
00684 {
00685 sighandler = new SigHandler;
00686 sighandler->initialize();
00687 ENABLE_BUFFER
00688 }
00689
00690 void MWindow::init_render()
00691 {
00692 render = new Render(this);
00693
00694 batch_render = new BatchRenderThread(this);
00695 }
00696
00697 void MWindow::init_brender()
00698 {
00699 if(preferences->use_brender && !brender)
00700 {
00701 brender_lock->lock("MWindow::init_brender 1");
00702 brender = new BRender(this);
00703 brender->initialize();
00704 session->brender_end = 0;
00705 brender_lock->unlock();
00706 }
00707 else
00708 if(!preferences->use_brender && brender)
00709 {
00710 brender_lock->lock("MWindow::init_brender 2");
00711 delete brender;
00712 brender = 0;
00713 session->brender_end = 0;
00714 brender_lock->unlock();
00715 }
00716 if(brender) brender->restart(edl);
00717 }
00718
00719 void MWindow::restart_brender()
00720 {
00721
00722 if(brender) brender->restart(edl);
00723 }
00724
00725 void MWindow::stop_brender()
00726 {
00727 if(brender) brender->stop();
00728 }
00729
00730 int MWindow::brender_available(int position)
00731 {
00732 int result = 0;
00733 brender_lock->lock("MWindow::brender_available 1");
00734 if(brender)
00735 {
00736 if(brender->map_valid)
00737 {
00738 brender->map_lock->lock("MWindow::brender_available 2");
00739 if(position < brender->map_size &&
00740 position >= 0)
00741 {
00742
00743 if(brender->map[position] == BRender::RENDERED)
00744 result = 1;
00745 }
00746 brender->map_lock->unlock();
00747 }
00748 }
00749 brender_lock->unlock();
00750 return result;
00751 }
00752
00753 void MWindow::set_brender_start()
00754 {
00755 edl->session->brender_start = edl->local_session->get_selectionstart();
00756 restart_brender();
00757 gui->canvas->draw_overlays();
00758 gui->canvas->flash();
00759 }
00760
00761
00762
00763 int MWindow::load_filenames(ArrayList<char*> *filenames,
00764 int load_mode,
00765 int update_filename,
00766 char *reel_name,
00767 int reel_number,
00768 int overwrite_reel)
00769 {
00770 TRACE("MWindow::load_filenames 1");
00771 ArrayList<EDL*> new_edls;
00772 ArrayList<Asset*> new_assets;
00773 ArrayList<File*> new_files;
00774
00775 save_defaults();
00776 gui->start_hourglass();
00777
00778
00779
00780 cwindow->playback_engine->que->send_command(STOP,
00781 CHANGE_NONE,
00782 0,
00783 0);
00784 vwindow->playback_engine->que->send_command(STOP,
00785 CHANGE_NONE,
00786 0,
00787 0);
00788 cwindow->playback_engine->interrupt_playback(0);
00789 vwindow->playback_engine->interrupt_playback(0);
00790
00791
00792 TRACE("MWindow::load_filenames 80");
00793
00794
00795 int result = 0;
00796 for(int i = 0; i < filenames->total; i++)
00797 {
00798
00799 File *new_file = new File;
00800 Asset *new_asset = new Asset(filenames->values[i]);
00801 EDL *new_edl = new EDL;
00802 char string[BCTEXTLEN];
00803
00804
00805
00806
00807
00808 if(overwrite_reel)
00809 {
00810 char source_filename[BCTEXTLEN];
00811 char index_filename[BCTEXTLEN];
00812
00813 strcpy(new_asset->reel_name, reel_name);
00814 new_asset->reel_number = reel_number;
00815
00816 IndexFile::get_index_filename(source_filename,
00817 preferences->index_directory,
00818 index_filename,
00819 new_asset->path);
00820 remove(index_filename);
00821 new_asset->index_status = INDEX_NOTTESTED;
00822 }
00823
00824 new_edl->create_objects();
00825 new_edl->copy_session(edl);
00826
00827 sprintf(string, "Loading %s", new_asset->path);
00828 gui->show_message(string);
00829 TRACE("MWindow::load_filenames 81");
00830 result = new_file->open_file(preferences, new_asset, 1, 0, 0, 0);
00831 TRACE("MWindow::load_filenames 82");
00832
00833 switch(result)
00834 {
00835
00836 case FILE_OK:
00837 if(load_mode != LOAD_RESOURCESONLY)
00838 {
00839 TRACE("MWindow::load_filenames 83");
00840 asset_to_edl(new_edl, new_asset);
00841 TRACE("MWindow::load_filenames 84");
00842 new_edls.append(new_edl);
00843 TRACE("MWindow::load_filenames 85");
00844 delete new_asset;
00845 new_asset = 0;
00846 TRACE("MWindow::load_filenames 86");
00847 }
00848 else
00849 {
00850 new_assets.append(new_asset);
00851 }
00852
00853
00854 if(load_mode == LOAD_REPLACE ||
00855 load_mode == LOAD_REPLACE_CONCATENATE)
00856 {
00857 set_filename("");
00858
00859 new_edl->local_session->view_start = 0;
00860 new_edl->local_session->track_start = 0;
00861 }
00862
00863 result = 0;
00864 break;
00865
00866
00867 case FILE_NOT_FOUND:
00868 sprintf(string, _("Failed to open %s"), new_asset->path);
00869 gui->show_message(string, theme->message_error);
00870 result = 1;
00871 break;
00872
00873
00874 case FILE_UNRECOGNIZED_CODEC:
00875 {
00876
00877 IndexFile indexfile(this);
00878 result = indexfile.open_index(this, new_asset);
00879 if(!result)
00880 {
00881 indexfile.close_index();
00882 }
00883
00884
00885 if(result)
00886 {
00887 for(int j = 0; j < new_edls.total + 1; j++)
00888 {
00889 Asset *old_asset;
00890 if(j == new_edls.total)
00891 {
00892 if(old_asset = edl->assets->get_asset(new_asset->path))
00893 {
00894 *new_asset = *old_asset;
00895 result = 0;
00896 }
00897 }
00898 else
00899 {
00900 if(old_asset = new_edls.values[j]->assets->get_asset(new_asset->path))
00901 {
00902 *new_asset = *old_asset;
00903 result = 0;
00904 }
00905 }
00906 }
00907 }
00908
00909
00910 if(result)
00911 {
00912 char string[BCTEXTLEN];
00913 FileSystem fs;
00914 fs.extract_name(string, new_asset->path);
00915
00916 strcat(string, _("'s format couldn't be determined."));
00917 new_asset->audio_data = 1;
00918 new_asset->format = FILE_PCM;
00919 new_asset->channels = defaults->get("AUDIO_CHANNELS", 2);
00920 new_asset->sample_rate = defaults->get("SAMPLE_RATE", 44100);
00921 new_asset->bits = defaults->get("AUDIO_BITS", 16);
00922 new_asset->byte_order = defaults->get("BYTE_ORDER", 1);
00923 new_asset->signed_ = defaults->get("SIGNED_", 1);
00924 new_asset->header = defaults->get("HEADER", 0);
00925
00926 FileFormat fwindow(this);
00927 fwindow.create_objects(new_asset, string);
00928 result = fwindow.run_window();
00929
00930 defaults->update("AUDIO_CHANNELS", new_asset->channels);
00931 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
00932 defaults->update("AUDIO_BITS", new_asset->bits);
00933 defaults->update("BYTE_ORDER", new_asset->byte_order);
00934 defaults->update("SIGNED_", new_asset->signed_);
00935 defaults->update("HEADER", new_asset->header);
00936 save_defaults();
00937 }
00938
00939
00940 if(!result)
00941 {
00942
00943 delete new_file;
00944 new_file = new File;
00945 result = new_file->open_file(preferences, new_asset, 1, 0, 0, 0);
00946
00947 if(load_mode != LOAD_RESOURCESONLY)
00948 {
00949 asset_to_edl(new_edl, new_asset);
00950 new_edls.append(new_edl);
00951 delete new_asset;
00952 new_asset = 0;
00953 }
00954 else
00955 {
00956 new_assets.append(new_asset);
00957 }
00958 }
00959 else
00960 {
00961 result = 1;
00962 }
00963 break;
00964 }
00965
00966 case FILE_IS_XML:
00967 {
00968 FileXML xml_file;
00969 xml_file.read_from_file(filenames->values[i]);
00970
00971 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
00972 test_plugins(new_edl, filenames->values[i]);
00973
00974
00975 strcpy(new_asset->reel_name, "");
00976 reel_number = -1;
00977
00978 if(load_mode == LOAD_REPLACE ||
00979 load_mode == LOAD_REPLACE_CONCATENATE)
00980 {
00981 strcpy(session->filename, filenames->values[i]);
00982 strcpy(new_edl->local_session->clip_title, filenames->values[i]);
00983 if(update_filename)
00984 set_filename(new_edl->local_session->clip_title);
00985 }
00986
00987 new_edls.append(new_edl);
00988 result = 0;
00989 break;
00990 }
00991 }
00992
00993 TRACE("MWindow::load_filenames 87");
00994 if(result)
00995 {
00996 delete new_edl;
00997 delete new_asset;
00998 new_edl = 0;
00999 new_asset = 0;
01000 }
01001 TRACE("MWindow::load_filenames 88");
01002
01003
01004 new_files.append(new_file);
01005 TRACE("MWindow::load_filenames 89");
01006 }
01007
01008
01009
01010 if(!result) gui->statusbar->default_message();
01011
01012
01013
01014 TRACE("MWindow::load_filenames 90");
01015
01016
01017
01018
01019
01020
01021
01022 if(new_edls.total)
01023 {
01024 SET_TRACE
01025
01026 if(load_mode == LOAD_PASTE)
01027 {
01028 SET_TRACE
01029 double start = edl->local_session->get_selectionstart();
01030 SET_TRACE
01031 double end = edl->local_session->get_selectionend();
01032 SET_TRACE
01033 if(!EQUIV(start, end))
01034 edl->clear(start,
01035 end,
01036 edl->session->labels_follow_edits,
01037 edl->session->plugins_follow_edits);
01038 SET_TRACE
01039 }
01040
01041 SET_TRACE
01042 paste_edls(&new_edls,
01043 load_mode,
01044 0,
01045 -1,
01046 edl->session->labels_follow_edits,
01047 edl->session->plugins_follow_edits);
01048 SET_TRACE
01049 }
01050
01051
01052
01053
01054
01055
01056 TRACE("MWindow::load_filenames 91");
01057
01058 if(new_assets.total)
01059 {
01060 for(int i = 0; i < new_assets.total; i++)
01061 {
01062 Asset *new_asset = new_assets.values[i];
01063 File *new_file = 0;
01064 File *index_file = 0;
01065 int got_it = 0;
01066 for(int j = 0; j < new_files.total; j++)
01067 {
01068 new_file = new_files.values[j];
01069 if(!strcmp(new_file->asset->path,
01070 new_asset->path))
01071 {
01072 got_it = 1;
01073 break;
01074 }
01075 }
01076
01077 mainindexes->add_next_asset(got_it ? new_file : 0,
01078 new_assets.values[i]);
01079 edl->assets->update(new_assets.values[i]);
01080 }
01081
01082
01083
01084 mainindexes->start_build();
01085 }
01086
01087 TRACE("MWindow::load_filenames 100");
01088 update_project(load_mode);
01089 TRACE("MWindow::load_filenames 110");
01090
01091
01092
01093
01094 new_edls.remove_all_objects();
01095 TRACE("MWindow::load_filenames 120\n");
01096 new_assets.remove_all_objects();
01097 TRACE("MWindow::load_filenames 130\n");
01098 new_files.remove_all_objects();
01099 TRACE("MWindow::load_filenames 140\n");
01100
01101 undo->update_undo(_("load"), LOAD_ALL, 0);
01102
01103
01104 gui->stop_hourglass();
01105 UNTRACE
01106
01107 return 0;
01108 }
01109
01110
01111
01112
01113 void MWindow::test_plugins(EDL *new_edl, char *path)
01114 {
01115
01116 for(Track *track = new_edl->tracks->first; track; track = track->next)
01117 {
01118 for(int k = 0; k < track->plugin_set.total; k++)
01119 {
01120 PluginSet *plugin_set = track->plugin_set.values[k];
01121 for(Plugin *plugin = (Plugin*)plugin_set->first;
01122 plugin;
01123 plugin = (Plugin*)plugin->next)
01124 {
01125 if(plugin->plugin_type == PLUGIN_STANDALONE)
01126 {
01127
01128 int plugin_found = 0;
01129 for(int j = 0; j < plugindb->total; j++)
01130 {
01131 PluginServer *server = plugindb->values[j];
01132 if(!strcasecmp(server->title, plugin->title) &&
01133 ((track->data_type == TRACK_AUDIO && server->audio) ||
01134 (track->data_type == TRACK_VIDEO && server->video)) &&
01135 (!server->transition))
01136 plugin_found = 1;
01137 }
01138 if (!plugin_found)
01139 {
01140 printf("\nWARNING: The plugin '%s' named in file '%s' is not part of your installation of Cinelerra. This means project will not be rendered as it was meant and it might result in Cinelerra crashing.\n", plugin->title, path);
01141 }
01142 }
01143 }
01144 }
01145 for(Edit *edit = (Edit*)track->edits->first;
01146 edit;
01147 edit = (Edit*)edit->next)
01148 {
01149 if (edit->transition)
01150 {
01151
01152 int transition_found = 0;
01153 for(int j = 0; j < plugindb->total; j++)
01154 {
01155 PluginServer *server = plugindb->values[j];
01156 if(!strcasecmp(server->title, edit->transition->title) &&
01157 ((track->data_type == TRACK_AUDIO && server->audio) ||
01158 (track->data_type == TRACK_VIDEO && server->video)) &&
01159 (server->transition))
01160 transition_found = 1;
01161 }
01162 if (!transition_found)
01163 {
01164 printf("\nWARNING: The transition '%s' named in file '%s' is not part of your installation of Cinelerra. This means project will not be rendered as it was meant and it might result in Cinelerra crashing.\n", edit->transition->title, path);
01165 }
01166 }
01167 }
01168 }
01169 }
01170
01171
01172
01173
01174
01175
01176 void MWindow::create_objects(int want_gui,
01177 int want_new,
01178 char *config_path)
01179 {
01180 char string[BCTEXTLEN];
01181 FileSystem fs;
01182 edl = 0;
01183
01184
01185 show_splash();
01186
01187
01188
01189 init_signals();
01190
01191
01192 TRACE("MWindow::create_objects 1");
01193 init_defaults(defaults, config_path);
01194 TRACE("MWindow::create_objects 2");
01195 init_preferences();
01196 TRACE("MWindow::create_objects 3");
01197 init_plugins(preferences, plugindb, splash_window);
01198 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
01199 TRACE("MWindow::create_objects 4");
01200 init_theme();
01201
01202 TRACE("MWindow::create_objects 5");
01203 init_edl();
01204
01205 TRACE("MWindow::create_objects 6");
01206 init_awindow();
01207 TRACE("MWindow::create_objects 7");
01208 init_compositor();
01209 TRACE("MWindow::create_objects 8");
01210 init_levelwindow();
01211 TRACE("MWindow::create_objects 9");
01212 init_viewer();
01213 TRACE("MWindow::create_objects 10");
01214 init_cache();
01215 TRACE("MWindow::create_objects 11");
01216 init_indexes();
01217 TRACE("MWindow::create_objects 12");
01218 init_channeldb();
01219 TRACE("MWindow::create_objects 13");
01220
01221 init_gui();
01222 init_gwindow();
01223 TRACE("MWindow::create_objects 14");
01224 init_render();
01225 init_brender();
01226 mainprogress = new MainProgress(this, gui);
01227 undo = new MainUndo(this);
01228
01229 plugin_guis = new ArrayList<PluginServer*>;
01230
01231 TRACE("MWindow::create_objects 15");
01232 if(session->show_vwindow) vwindow->gui->show_window();
01233 if(session->show_cwindow) cwindow->gui->show_window();
01234 if(session->show_awindow) awindow->gui->show_window();
01235 if(session->show_lwindow) lwindow->gui->show_window();
01236 if(session->show_gwindow) gwindow->gui->show_window();
01237 TRACE("MWindow::create_objects 16");
01238
01239
01240 gui->mainmenu->load_defaults(defaults);
01241 TRACE("MWindow::create_objects 17");
01242 gui->mainmenu->update_toggles(0);
01243 TRACE("MWindow::create_objects 18");
01244 gui->patchbay->update();
01245 TRACE("MWindow::create_objects 19");
01246 gui->canvas->draw();
01247 TRACE("MWindow::create_objects 20");
01248 gui->cursor->draw();
01249 TRACE("MWindow::create_objects 21");
01250