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
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
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
00159 exit(0);
00160
00161 SET_TRACE
00162 delete mainprogress;
00163 delete audio_cache;
00164 delete video_cache;
00165 delete frame_cache;
00166 if(gui) delete gui;
00167 delete undo;
00168 delete preferences;
00169 delete defaults;
00170 delete render;
00171
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
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
00199 strcat(string, "Cinelerra_rc");
00200 }
00201
00202 void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
00203 {
00204 char path[BCTEXTLEN];
00205
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
00236 if(fs->is_dir(path))
00237 {
00238 continue;
00239 }
00240 else
00241 {
00242
00243 fs->complete_path(path);
00244
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
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
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
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
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
00371 #ifndef DO_STATIC
00372 init_plugin_path(preferences,
00373 plugindb,
00374 &cinelerra_fs,
00375 splash_window,
00376 &counter);
00377 #else
00378
00379 #endif
00380
00381
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
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
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
00480 fs.set_filter("*.idx");
00481 fs.complete_path(preferences->index_directory);
00482 fs.update(preferences->index_directory);
00483
00484
00485
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
00504 while(total_excess > 0)
00505 {
00506
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
00521 fs.join_names(string,
00522 preferences->index_directory,
00523 fs.dir_list.values[oldest_item]->name);
00524
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
00531 strcpy(string2, string);
00532 char *ptr = strrchr(string2, '.');
00533 if(ptr)
00534 {
00535
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
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
00592 theme->Theme::initialize();
00593
00594 theme->initialize();
00595
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
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
00660
00661
00662
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
00672
00673
00674
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
00686 ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED);
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
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
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
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
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
00817
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
00832 int result = 0;
00833 for(int i = 0; i < filenames->total; i++)
00834 {
00835
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
00842
00843
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
00873 case FILE_OK:
00874
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
00905 if(load_mode == LOAD_REPLACE ||
00906 load_mode == LOAD_REPLACE_CONCATENATE)
00907 {
00908 set_filename("");
00909
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
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
00925 case FILE_UNRECOGNIZED_CODEC:
00926 {
00927
00928 IndexFile indexfile(this);
00929 result = indexfile.open_index(this, new_asset);
00930 if(!result)
00931 {
00932 indexfile.close_index();
00933 }
00934
00935
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
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 defaults->update("AUDIO_CHANNELS", new_asset->channels);
00982 defaults->update("SAMPLE_RATE", new_asset->sample_rate);
00983 defaults->update("AUDIO_BITS", new_asset->bits);
00984 defaults->update("BYTE_ORDER", new_asset->byte_order);
00985 defaults->update("SIGNED_", new_asset->signed_);
00986 defaults->update("HEADER", new_asset->header);
00987 save_defaults();
00988 }
00989
00990
00991 if(!result)
00992 {
00993
00994 delete new_file;
00995 new_file = new File;
00996 result = new_file->open_file(preferences, new_asset, 1, 0, 0, 0);
00997
00998 if(load_mode != LOAD_RESOURCESONLY)
00999 {
01000 asset_to_edl(new_edl, new_asset);
01001 new_edls.append(new_edl);
01002 Garbage::delete_object(new_asset);
01003 new_asset = 0;
01004 }
01005 else
01006 {
01007 new_assets.append(new_asset);
01008 }
01009 }
01010 else
01011 {
01012 result = 1;
01013 }
01014 break;
01015 }
01016
01017 case FILE_IS_XML:
01018 {
01019 FileXML xml_file;
01020 xml_file.read_from_file(filenames->values[i]);
01021
01022 new_edl->load_xml(plugindb, &xml_file, LOAD_ALL);
01023 test_plugins(new_edl, filenames->values[i]);
01024
01025
01026 strcpy(new_asset->reel_name, "");
01027 reel_number = -1;
01028
01029 if(load_mode == LOAD_REPLACE ||
01030 load_mode == LOAD_REPLACE_CONCATENATE)
01031 {
01032 strcpy(session->filename, filenames->values[i]);
01033 strcpy(new_edl->local_session->clip_title, filenames->values[i]);
01034 if(update_filename)
01035 set_filename(new_edl->local_session->clip_title);
01036 }
01037
01038 new_edls.append(new_edl);
01039 result = 0;
01040 break;
01041 }
01042 }
01043
01044 SET_TRACE
01045 if(result)
01046 {
01047 delete new_edl;
01048 Garbage::delete_object(new_asset);
01049 new_edl = 0;
01050 new_asset = 0;
01051 }
01052 SET_TRACE
01053
01054
01055 new_files.append(new_file);
01056 SET_TRACE
01057 }
01058
01059
01060
01061 if(!result) gui->statusbar->default_message();
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072 if(new_edls.total)
01073 {
01074
01075 if(load_mode == LOAD_PASTE)
01076 {
01077 double start = edl->local_session->get_selectionstart();
01078 double end = edl->local_session->get_selectionend();
01079 if(!EQUIV(start, end))
01080 edl->clear(start,
01081 end,
01082 edl->session->labels_follow_edits,
01083 edl->session->plugins_follow_edits);
01084 }
01085
01086 paste_edls(&new_edls,
01087 load_mode,
01088 0,
01089 -1,
01090 edl->session->labels_follow_edits,
01091 edl->session->plugins_follow_edits,
01092 0);
01093 }
01094
01095
01096
01097
01098
01099
01100
01101
01102 if(new_assets.total)
01103 {
01104 for(int i = 0; i < new_assets.total; i++)
01105 {
01106 Asset *new_asset = new_assets.values[i];
01107 File *new_file = 0;
01108 File *index_file = 0;
01109 int got_it = 0;
01110 for(int j = 0; j < new_files.total; j++)
01111 {
01112 new_file = new_files.values[j];
01113 if(!strcmp(new_file->asset->path,
01114 new_asset->path))
01115 {
01116 got_it = 1;
01117 break;
01118 }
01119 }
01120
01121 mainindexes->add_next_asset(got_it ? new_file : 0,
01122 new_asset);
01123 edl->assets->update(new_asset);
01124
01125 }
01126
01127
01128
01129 mainindexes->start_build();
01130 }
01131
01132
01133 update_project(load_mode);
01134 SET_TRACE
01135
01136
01137
01138 new_edls.remove_all_objects();
01139 SET_TRACE
01140 for(int i = 0; i < new_assets.total; i++)
01141 Garbage::delete_object(new_assets.values[i]);
01142 SET_TRACE
01143 new_assets.remove_all();
01144 SET_TRACE
01145 new_files.remove_all_objects();
01146
01147 SET_TRACE
01148 undo->update_undo(_("load"), LOAD_ALL, 0);
01149
01150
01151 SET_TRACE
01152 gui->stop_hourglass();
01153 SET_TRACE
01154
01155 return 0;
01156 }
01157
01158
01159
01160
01161 void MWindow::test_plugins(EDL *new_edl, char *path)
01162 {
01163 char string[BCTEXTLEN];
01164
01165 for(Track *track = new_edl->tracks->first; track; track = track->next)
01166 {
01167 for(int k = 0; k < track->plugin_set.total; k++)
01168 {
01169 PluginSet *plugin_set = track->plugin_set.values[k];
01170 for(Plugin *plugin = (Plugin*)plugin_set->first;
01171 plugin;
01172 plugin = (Plugin*)plugin->next)
01173 {
01174 if(plugin->plugin_type == PLUGIN_STANDALONE)
01175 {
01176
01177 int plugin_found = 0;
01178 for(int j = 0; j < plugindb->total; j++)
01179 {
01180 PluginServer *server = plugindb->values[j];
01181 if(!strcasecmp(server->title, plugin->title) &&
01182 ((track->data_type == TRACK_AUDIO && server->audio) ||
01183 (track->data_type == TRACK_VIDEO && server->video)) &&
01184 (!server->transition))
01185 plugin_found = 1;
01186 }
01187 if (!plugin_found)
01188 {
01189 sprintf(string,
01190 "The effect '%s' in file '%s' is not part of your installation of Cinelerra.\n"
01191 "The project won't be rendered as it was meant and Cinelerra might crash.\n",
01192 plugin->title,
01193 path);
01194 MainError::show_error(string);
01195 }
01196 }
01197 }
01198 }
01199 for(Edit *edit = (Edit*)track->edits->first;
01200 edit;
01201 edit = (Edit*)edit->next)
01202 {
01203 if (edit->transition)
01204 {
01205
01206 int transition_found = 0;
01207 for(int j = 0; j < plugindb->total; j++)
01208 {
01209 PluginServer *server = plugindb->values[j];
01210 if(!strcasecmp(server->title, edit->transition->title) &&
01211 ((track->data_type == TRACK_AUDIO && server->audio) ||
01212 (track->data_type == TRACK_VIDEO && server->video)) &&
01213 (server->transition))
01214 transition_found = 1;
01215 }
01216 if (!transition_found)
01217 {
01218 sprintf(string,
01219 "The transition '%s' in file '%s' is not part of your installation of Cinelerra.\n"
01220 "The project won't be rendered as it was meant and Cinelerra might crash.\n",
01221 edit->transition->title,
01222 path);
01223 MainError::show_error(string);
01224 }
01225 }
01226 }
01227 }
01228 }
01229
01230
01231 void MWindow::init_shm()
01232 {
01233
01234 FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
01235 if(fd)
01236 {
01237 fprintf(fd, "0x7fffffff");
01238 fclose(fd);
01239 }
01240 fd = 0;
01241
01242 fd = fopen("/proc/sys/kernel/shmmax", "r");
01243 if(!fd)
01244 {
01245 MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
01246 return;
01247 }
01248
01249 int64_t result = 0;
01250 fscanf(fd, "%lld", &result);
01251 fclose(fd);
01252 fd = 0;
01253 if(result < 0x7fffffff)
01254 {
01255 eprintf("WARNING: /proc/sys/kernel/shmmax is 0x%llx, which is too low.\n"
01256 "Before running Cinelerra do the following as root:\n"
01257 "echo \"0x7fffffff\" > /proc/sys/kernel/shmmax\n",
01258 result);
01259 }
01260 }
01261
01262
01263
01264 void MWindow::create_objects(int want_gui,
01265 int want_new,
01266 char *config_path)
01267 {
01268 char string[BCTEXTLEN];
01269 FileSystem fs;
01270 edl = 0;
01271
01272
01273
01274 init_3d();
01275 remove_thread = new RemoveThread;
01276 remove_thread->create_objects();
01277 show_splash();
01278
01279
01280
01281 init_signals();
01282
01283 init_error();
01284
01285 SET_TRACE
01286
01287 init_defaults(defaults, config_path);
01288 SET_TRACE
01289 init_preferences();
01290 SET_TRACE
01291 init_plugins(preferences, plugindb, splash_window);
01292 if(splash_window) splash_window->operation->update(_("Initializing GUI"));
01293 SET_TRACE
01294 init_theme();
01295
01296 SET_TRACE
01297 init_edl();
01298
01299 SET_TRACE
01300 init_awindow();
01301 SET_TRACE
01302 init_compositor();
01303 SET_TRACE
01304 init_levelwindow();
01305 SET_TRACE
01306 init_viewer();
01307 SET_TRACE
01308 init_cache();
01309 SET_TRACE
01310 init_indexes();
01311 SET_TRACE
01312 init_channeldb();
01313 SET_TRACE
01314
01315 init_gui();
01316 init_gwindow();
01317 SET_TRACE
01318 init_render();
01319 init_brender();
01320 init_exportedl();
01321 mainprogress = new MainProgress(this, gui);
01322 undo = new MainUndo(this);
01323
01324 plugin_guis = new ArrayList<PluginServer*>;
01325
01326 SET_TRACE
01327 if(session->show_vwindow) vwindow->gui->show_window();
01328 if(session->show_cwindow) cwindow->gui->show_window();
01329 if(session->show_awindow) awindow->gui->show_window();
01330 if(session->show_lwindow) lwindow->gui->show_window();
01331 if(session->show_gwindow) gwindow->gui->show_window();
01332 SET_TRACE
01333
01334
01335 gui->mainmenu->load_defaults(defaults);
01336 SET_TRACE
01337 gui->mainmenu->update_toggles(0);
01338 SET_TRACE
01339 gui->patchbay->update();
01340 SET_TRACE
01341 gui->canvas->draw();
01342 SET_TRACE
01343 gui->cursor->draw(1);
01344 SET_TRACE
01345 gui->show_window();
01346 gui->raise_window();
01347
01348 if(preferences->use_tipwindow)
01349 init_tipwindow();
01350
01351 SET_TRACE
01352
01353 hide_splash();
01354 SET_TRACE
01355 init_shm();
01356 }
01357
01358
01359 void MWindow::show_splash()
01360 {
01361 #include "data/heroine_logo12_png.h"
01362 VFrame *frame = new VFrame(heroine_logo12_png);
01363 BC_DisplayInfo display_info;
01364 splash_window = new SplashGUI(frame,
01365 display_info.get_root_w() / 2 - frame->get_w() / 2,
01366 display_info.get_root_h() / 2 - frame->get_h() / 2);
01367 splash_window->create_objects();
01368 }
01369
01370 void MWindow::hide_splash()
01371 {
01372 if(splash_window)
01373 delete splash_window;
01374 splash_window = 0;
01375 }
01376
01377
01378 void MWindow::start()
01379 {
01380 ENABLE_BUFFER
01381 vwindow->start();
01382 awindow->start();
01383 cwindow->start();
01384 lwindow->start();
01385 gwindow->start();
01386 Thread::start();
01387 playback_3d->start();
01388 }
01389
01390 void MWindow::run()
01391 {
01392 gui->run_window();
01393 }
01394
01395 void MWindow::show_vwindow()
01396 {
01397 session->show_vwindow = 1;
01398 vwindow->gui->lock_window("MWindow::show_vwindow");
01399 vwindow->gui->show_window();
01400 vwindow->gui->raise_window();
01401 vwindow->gui->flush();
01402 vwindow->gui->unlock_window();
01403 gui->mainmenu->show_vwindow->set_checked(1);
01404 }
01405
01406 void MWindow::show_awindow()
01407 {
01408 session->show_awindow = 1;
01409 awindow->gui->lock_window("MWindow::show_awindow");
01410 awindow->gui->show_window();
01411 awindow->gui->raise_window();
01412 awindow->gui->flush();
01413 awindow->gui->unlock_window();
01414 gui->mainmenu->show_awindow->set_checked(1);
01415 }
01416
01417 void MWindow::show_cwindow()
01418 {
01419 session->show_cwindow = 1;
01420 cwindow->show_window();
01421 gui->mainmenu->show_cwindow->set_checked(1);
01422 }
01423
01424 void MWindow::show_gwindow()
01425 {
01426 session->show_gwindow = 1;
01427
01428 gwindow->gui->lock_window("MWindow::show_gwindow");
01429 gwindow->gui->show_window();
01430 gwindow->gui->raise_window();
01431 gwindow->gui->flush();
01432 gwindow->gui->unlock_window();
01433
01434 gui->mainmenu->show_gwindow->set_checked(1);
01435 }
01436
01437 void MWindow::show_lwindow()
01438 {
01439 session->show_lwindow = 1;
01440 lwindow->gui->lock_window("MWindow::show_lwindow");
01441 lwindow->gui->show_window();
01442 lwindow->gui->raise_window();
01443 lwindow->gui->flush();
01444 lwindow->gui->unlock_window();
01445 gui->mainmenu->show_lwindow->set_checked(1);
01446 }
01447
01448 void MWindow::tile_windows()
01449 {
01450 session->default_window_positions();
01451 gui->default_positions();
01452 }
01453
01454 void MWindow::toggle_loop_playback()
01455 {
01456 edl->local_session->loop_playback = !edl->local_session->loop_playback;
01457 set_loop_boundaries();
01458 save_backup();
01459
01460 gui->canvas->draw_overlays();
01461 gui->canvas->flash();
01462 sync_parameters(CHANGE_PARAMS);
01463 }
01464
01465 void MWindow::set_titles(int value)
01466 {
01467 edl->session->show_titles = value;
01468 trackmovement(edl->local_session->track_start);
01469 }
01470
01471 void MWindow::set_auto_keyframes(int value)
01472 {
01473 gui->lock_window("MWindow::set_auto_keyframes");
01474 edl->session->auto_keyframes = value;
01475 gui->mbuttons->edit_panel->keyframe->update(value);
01476 gui->flush();
01477 gui->unlock_window();
01478 cwindow->gui->lock_window("MWindow::set_auto_keyframes");
01479 cwindow->gui->edit_panel->keyframe->update(value);
01480 cwindow->gui->flush();
01481 cwindow->gui->unlock_window();
01482 }
01483
01484 int MWindow::set_editing_mode(int new_editing_mode)
01485 {
01486 gui->lock_window("MWindow::set_editing_mode");
01487 edl->session->editing_mode = new_editing_mode;
01488 gui->mbuttons->edit_panel->editing_mode = edl->session->editing_mode;
01489 gui->mbuttons->edit_panel->update();
01490 gui->canvas->update_cursor();
01491 gui->unlock_window();
01492 cwindow->gui->lock_window("MWindow::set_editing_mode");
01493 cwindow->gui->edit_panel->update();
01494 cwindow->gui->edit_panel->editing_mode = edl->session->editing_mode;
01495 cwindow->gui->unlock_window();
01496 return 0;
01497 }
01498
01499 void MWindow::toggle_editing_mode()
01500 {
01501 int mode = edl->session->editing_mode;
01502 if( mode == EDITING_ARROW )
01503 set_editing_mode(EDITING_IBEAM);
01504 else
01505 set_editing_mode(EDITING_ARROW);
01506 }
01507
01508
01509 void MWindow::set_labels_follow_edits(int value)
01510 {
01511 gui->lock_window("MWindow::set_labels_follow_edits");
01512 edl->session->labels_follow_edits = value;
01513 gui->mbuttons->edit_panel->locklabels->update(value);
01514 gui->mainmenu->labels_follow_edits->set_checked(value);
01515 gui->flush();
01516 gui->unlock_window();
01517 }
01518
01519 void MWindow::sync_parameters(int change_type)
01520 {
01521
01522
01523 if(cwindow->playback_engine->is_playing_back)
01524 {
01525 if(change_type == CHANGE_PARAMS)
01526 {
01527
01528 cwindow->playback_engine->sync_parameters(edl);
01529 }
01530 else
01531
01532 {
01533 int command = cwindow->playback_engine->command->command;
01534 cwindow->playback_engine->que->send_command(STOP,
01535 CHANGE_NONE,
01536 0,
01537 0);
01538
01539
01540
01541
01542 cwindow->playback_engine->interrupt_playback(0);
01543 cwindow->playback_engine->que->send_command(command,
01544 change_type,
01545 edl,
01546 1,
01547 0);
01548 }
01549 }
01550 else
01551 {
01552 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
01553 change_type,
01554 edl,
01555 1);
01556 }
01557 }
01558
01559 void MWindow::age_caches()
01560 {
01561 int64_t prev_memory_usage;
01562 int64_t memory_usage;
01563 int result = 0;
01564 do
01565 {
01566 memory_usage = audio_cache->get_memory_usage(1) +
01567 video_cache->get_memory_usage(1) +
01568 frame_cache->get_memory_usage() +
01569 wave_cache->get_memory_usage();
01570
01571 if(memory_usage > preferences->cache_size)
01572 {
01573 int target = 1;
01574 int oldest1 = audio_cache->get_oldest();
01575 int oldest2 = video_cache->get_oldest();
01576 if(oldest2 < oldest1) target = 2;
01577 int oldest3 = frame_cache->get_oldest();
01578 if(oldest3 < oldest1 && oldest3 < oldest2) target = 3;
01579 int oldest4 = wave_cache->get_oldest();
01580 if(oldest4 < oldest3 && oldest4 < oldest2 && oldest4 < oldest1) target = 4;
01581 switch(target)
01582 {
01583 case 1: audio_cache->delete_oldest(); break;
01584 case 2: video_cache->delete_oldest(); break;
01585 case 3: frame_cache->delete_oldest(); break;
01586 case 4: wave_cache->delete_oldest(); break;
01587 }
01588 }
01589 prev_memory_usage = memory_usage;
01590 memory_usage = audio_cache->get_memory_usage(1) +
01591 video_cache->get_memory_usage(1) +
01592 frame_cache->get_memory_usage() +
01593 wave_cache->get_memory_usage();
01594 }while(!result &&
01595 prev_memory_usage != memory_usage &&
01596 memory_usage > preferences->cache_size);
01597 }
01598
01599 void MWindow::show_plugin(Plugin *plugin)
01600 {
01601 int done = 0;
01602
01603 plugin_gui_lock->lock("MWindow::show_plugin");
01604 for(int i = 0; i < plugin_guis->total; i++)
01605 {
01606
01607 if(plugin_guis->values[i]->plugin == plugin)
01608 {
01609 plugin_guis->values[i]->raise_window();
01610 done = 1;
01611 break;
01612 }
01613 }
01614
01615
01616 if(!done)
01617 {
01618 if(!plugin->track)
01619 {
01620 printf("MWindow::show_plugin track not defined.\n");
01621 }
01622 PluginServer *server = scan_plugindb(plugin->title,
01623 plugin->track->data_type);
01624
01625
01626 if(server && server->uses_gui)
01627 {
01628 PluginServer *gui = plugin_guis->append(new PluginServer(*server));
01629
01630 gui->set_mwindow(this);
01631 gui->open_plugin(0, preferences, edl, plugin, -1);
01632 gui->show_gui();
01633 plugin->show = 1;
01634 }
01635 }
01636 plugin_gui_lock->unlock();
01637
01638 }
01639
01640 void MWindow::hide_plugin(Plugin *plugin, int lock)
01641 {
01642 plugin->show = 0;
01643 gui->lock_window("MWindow::hide_plugin");
01644 gui->update(0, 1, 0, 0, 0, 0, 0);
01645 gui->unlock_window();
01646
01647 if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
01648 for(int i = 0; i < plugin_guis->total; i++)
01649 {
01650 if(plugin_guis->values[i]->plugin == plugin)
01651 {
01652 PluginServer *ptr = plugin_guis->values[i];
01653 plugin_guis->remove(ptr);
01654 if(lock) plugin_gui_lock->unlock();
01655
01656 delete ptr;
01657 return;
01658 }
01659 }
01660 if(lock) plugin_gui_lock->unlock();
01661
01662 }
01663
01664 void MWindow::hide_plugins()
01665 {
01666 plugin_gui_lock->lock("MWindow::hide_plugins");
01667 plugin_guis->remove_all_objects();
01668 plugin_gui_lock->unlock();
01669 }
01670
01671 void MWindow::update_plugin_guis()
01672 {
01673 plugin_gui_lock->lock("MWindow::update_plugin_guis");
01674
01675 for(int i = 0; i < plugin_guis->total; i++)
01676 {
01677 plugin_guis->values[i]->update_gui();
01678 }
01679 plugin_gui_lock->unlock();
01680 }
01681
01682 int MWindow::plugin_gui_open(Plugin *plugin)
01683 {
01684 int result = 0;
01685 plugin_gui_lock->lock("MWindow::plugin_gui_open");
01686 for(int i = 0; i < plugin_guis->total; i++)
01687 {
01688 if(plugin_guis->values[i]->plugin->identical_location(plugin))
01689 {
01690 result = 1;
01691 break;
01692 }
01693 }
01694 plugin_gui_lock->unlock();
01695 return result;
01696 }
01697
01698 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
01699 {
01700 plugin_gui_lock->lock("MWindow::render_plugin_gui");
01701 for(int i = 0; i < plugin_guis->total; i++)
01702 {
01703 if(plugin_guis->values[i]->plugin->identical_location(plugin))
01704 {
01705 plugin_guis->values[i]->render_gui(data);
01706 break;
01707 }
01708 }
01709 plugin_gui_lock->unlock();
01710 }
01711
01712 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
01713 {
01714 plugin_gui_lock->lock("MWindow::render_plugin_gui");
01715 for(int i = 0; i < plugin_guis->total; i++)
01716 {
01717 if(plugin_guis->values[i]->plugin->identical_location(plugin))
01718 {
01719 plugin_guis->values[i]->render_gui(data, size);
01720 break;
01721 }
01722 }
01723 plugin_gui_lock->unlock();
01724 }
01725
01726
01727 void MWindow::update_plugin_states()
01728 {
01729 plugin_gui_lock->lock("MWindow::update_plugin_states");
01730 for(int i = 0; i < plugin_guis->total; i++)
01731 {
01732 int result = 0;
01733
01734 Plugin *src_plugin = plugin_guis->values[i]->plugin;
01735 PluginServer *src_plugingui = plugin_guis->values[i];
01736
01737
01738 for(Track *track = edl->tracks->first;
01739 track && !result;
01740 track = track->next)
01741 {
01742 for(int j = 0;
01743 j < track->plugin_set.total && !result;
01744 j++)
01745 {
01746 PluginSet *plugin_set = track->plugin_set.values[j];
01747 for(Plugin *plugin = (Plugin*)plugin_set->first;
01748 plugin && !result;
01749 plugin = (Plugin*)plugin->next)
01750 {
01751 if(plugin == src_plugin &&
01752 !strcmp(plugin->title, src_plugingui->title)) result = 1;
01753 }
01754 }
01755 }
01756
01757
01758
01759 if(!result)
01760 {
01761 hide_plugin(src_plugin, 0);
01762 i--;
01763 }
01764 }
01765 plugin_gui_lock->unlock();
01766 }
01767
01768
01769 void MWindow::update_plugin_titles()
01770 {
01771 for(int i = 0; i < plugin_guis->total; i++)
01772 {
01773 plugin_guis->values[i]->update_title();
01774 }
01775 }
01776
01777 int MWindow::asset_to_edl(EDL *new_edl,
01778 Asset *new_asset,
01779 RecordLabels *labels)
01780 {
01781
01782
01783
01784
01785
01786
01787 if(new_asset->video_data)
01788 {
01789 new_edl->session->video_tracks = new_asset->layers;
01790
01791
01792
01793 }
01794 else
01795 new_edl->session->video_tracks = 0;
01796
01797
01798
01799
01800
01801
01802 if(new_asset->audio_data)
01803 {
01804 new_edl->session->audio_tracks = new_asset->channels;
01805
01806 }
01807 else
01808 new_edl->session->audio_tracks = 0;
01809
01810
01811 new_edl->create_default_tracks();
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829 new_edl->insert_asset(new_asset, 0, 0, labels);
01830
01831
01832
01833 if(edl->session->cursor_on_frames)
01834 {
01835 double edl_length = new_edl->tracks->total_length_framealigned(edl->session->frame_rate);
01836 new_edl->tracks->clear(edl_length, new_edl->tracks->total_length() + 100, 1);
01837 new_edl->tracks->loaded_lengths_to_tracklengths(1);
01838 }
01839
01840
01841
01842
01843 char string[BCTEXTLEN];
01844 FileSystem fs;
01845 fs.extract_name(string, new_asset->path);
01846
01847
01848 strcpy(new_edl->local_session->clip_title, string);
01849
01850
01851
01852 return 0;
01853 }
01854
01855
01856 void MWindow::update_project(int load_mode)
01857 {
01858 restart_brender();
01859 edl->tracks->update_y_pixels(theme);
01860
01861
01862 gui->update(1, 1, 1, 1, 1, 1, 1);
01863
01864 cwindow->update(0, 0, 1, 1, 1);
01865
01866
01867 if(load_mode == LOAD_REPLACE ||
01868 load_mode == LOAD_REPLACE_CONCATENATE)
01869 {
01870 vwindow->change_source();
01871 }
01872 else
01873 {
01874 vwindow->update(1);
01875 }
01876
01877 cwindow->gui->lock_window("Mwindow::update_project");
01878 cwindow->gui->slider->set_position();
01879 cwindow->gui->timebar->update(1, 1);
01880 cwindow->gui->unlock_window();
01881 cwindow->playback_engine->que->send_command(CURRENT_FRAME,
01882 CHANGE_ALL,
01883 edl,
01884 1);
01885
01886 awindow->gui->async_update_assets();
01887 gui->flush();
01888 }
01889
01890
01891 void MWindow::rebuild_indices()
01892 {
01893 char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
01894
01895 for(int i = 0; i < session->drag_assets->total; i++)
01896 {
01897
01898
01899 IndexFile::get_index_filename(source_filename,
01900 preferences->index_directory,
01901 index_filename,
01902 session->drag_assets->values[i]->path);
01903 remove(index_filename);
01904
01905 session->drag_assets->values[i]->index_status = INDEX_NOTTESTED;
01906 mainindexes->add_next_asset(0, session->drag_assets->values[i]);
01907 }
01908 mainindexes->start_build();
01909 }
01910
01911
01912 void MWindow::save_backup()
01913 {
01914 FileXML file;
01915 edl->set_project_path(session->filename);
01916 edl->save_xml(plugindb,
01917 &file,
01918 BACKUP_PATH,
01919 0,
01920 0);
01921 file.terminate_string();
01922 char path[BCTEXTLEN];
01923 FileSystem fs;
01924 strcpy(path, BACKUP_PATH);
01925 fs.complete_path(path);
01926
01927 if(file.write_to_file(path))
01928 {
01929 char string2[256];
01930 sprintf(string2, _("Couldn't open %s for writing."), BACKUP_PATH);
01931 gui->show_message(string2);
01932 }
01933 }
01934
01935
01936 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
01937 {
01938 int denominator;
01939 if(!width || !height) return 1;
01940 float fraction = (float)width / height;
01941
01942 for(denominator = 1;
01943 denominator < 100 &&
01944 fabs(fraction * denominator - (int)(fraction * denominator)) > .001;
01945 denominator++)
01946 ;
01947
01948 w = denominator * width / height;
01949 h = denominator;
01950 return 0;
01951 }
01952
01953 void MWindow::reset_caches()
01954 {
01955 frame_cache->remove_all();
01956 wave_cache->remove_all();
01957 audio_cache->remove_all();
01958 video_cache->remove_all();
01959 if(cwindow->playback_engine && cwindow->playback_engine->audio_cache)
01960 cwindow->playback_engine->audio_cache->remove_all();
01961 if(cwindow->playback_engine && cwindow->playback_engine->video_cache)
01962 cwindow->playback_engine->video_cache->remove_all();
01963 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
01964 vwindow->playback_engine->audio_cache->remove_all();
01965 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
01966 vwindow->playback_engine->video_cache->remove_all();
01967 }
01968
01969 void MWindow::remove_asset_from_caches(Asset *asset)
01970 {
01971 frame_cache->remove_asset(asset);
01972 wave_cache->remove_asset(asset);
01973 audio_cache->delete_entry(asset);
01974 video_cache->delete_entry(asset);
01975 if(cwindow->playback_engine && cwindow->playback_engine->audio_cache)
01976 cwindow->playback_engine->audio_cache->delete_entry(asset);
01977 if(cwindow->playback_engine && cwindow->playback_engine->video_cache)
01978 cwindow->playback_engine->video_cache->delete_entry(asset);
01979 if(vwindow->playback_engine && vwindow->playback_engine->audio_cache)
01980 vwindow->playback_engine->audio_cache->delete_entry(asset);
01981 if(vwindow->playback_engine && vwindow->playback_engine->video_cache)
01982 vwindow->playback_engine->video_cache->delete_entry(asset);
01983 }
01984
01985
01986
01987 void MWindow::remove_assets_from_project(int push_undo)
01988 {
01989 for(int i = 0; i < session->drag_assets->total; i++)
01990 {
01991 Asset *asset = session->drag_assets->values[i];
01992 remove_asset_from_caches(asset);
01993 }
01994
01995
01996 for(int i = 0; i < session->drag_clips->total; i++)
01997 {
01998 if(session->drag_clips->values[i] == vwindow->get_edl())
01999 {
02000 vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
02001 vwindow->remove_source();
02002 vwindow->gui->unlock_window();
02003 }
02004 }
02005
02006 for(int i = 0; i < session->drag_assets->total; i++)
02007 {
02008 if(session->drag_assets->values[i] == vwindow->get_asset())
02009 {
02010 vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
02011 vwindow->remove_source();
02012 vwindow->gui->unlock_window();
02013 }
02014 }
02015
02016 edl->remove_from_project(session->drag_assets);
02017 edl->remove_from_project(session->drag_clips);
02018 save_backup();
02019 if(push_undo) undo->update_undo(_("remove assets"), LOAD_ALL);
02020 restart_brender();
02021
02022 gui->lock_window("MWindow::remove_assets_from_project 3");
02023 gui->update(1,
02024 1,
02025 1,
02026 1,
02027 0,
02028 1,
02029 0);
02030 gui->unlock_window();
02031
02032 awindow->gui->async_update_assets();
02033
02034
02035 sync_parameters(CHANGE_ALL);
02036 }
02037
02038 void MWindow::remove_assets_from_disk()
02039 {
02040
02041 for(int i = 0; i < session->drag_assets->total; i++)
02042 {
02043 remove(session->drag_assets->values[i]->path);
02044 }
02045
02046 remove_assets_from_project(1);
02047 }
02048
02049 void MWindow::dump_plugins()
02050 {
02051 for(int i = 0; i < plugindb->total; i++)
02052 {
02053 printf("audio=%d video=%d realtime=%d transition=%d theme=%d %s\n",
02054 plugindb->values[i]->audio,
02055 plugindb->values[i]->video,
02056 plugindb->values[i]->realtime,
02057 plugindb->values[i]->transition,
02058 plugindb->values[i]->theme,
02059 plugindb->values[i]->title);
02060 }
02061 }
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087 int MWindow::save_defaults()
02088 {
02089 gui->save_defaults(defaults);
02090 edl->save_defaults(defaults);
02091 session->save_defaults(defaults);
02092 preferences->save_defaults(defaults);
02093
02094 defaults->save();
02095 return 0;
02096 }
02097
02098 int MWindow::run_script(FileXML *script)
02099 {
02100 int result = 0, result2 = 0;
02101 while(!result && !result2)
02102 {
02103 result = script->read_tag();
02104 if(!result)
02105 {
02106 if(script->tag.title_is("new_project"))
02107 {
02108
02109
02110 }
02111 else
02112 if(script->tag.title_is("record"))
02113 {
02114
02115 ;
02116
02117
02118 result2 = 1;
02119 }
02120 else
02121 {
02122 printf("MWindow::run_script: Unrecognized command: %s\n",script->tag.get_title() );
02123 }
02124 }
02125 }
02126 return result2;
02127 }
02128
02129
02130
02131
02132 int MWindow::interrupt_indexes()
02133 {
02134 mainindexes->interrupt_build();
02135 return 0;
02136 }
02137
02138
02139
02140 void MWindow::next_time_format()
02141 {
02142 switch(edl->session->time_format)
02143 {
02144 case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
02145 case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
02146 case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
02147 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
02148 case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
02149 case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
02150 case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
02151 }
02152
02153 time_format_common();
02154 }
02155
02156 void MWindow::prev_time_format()
02157 {
02158 switch(edl->session->time_format)
02159 {
02160 case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
02161 case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
02162 case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
02163 case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
02164 case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
02165 case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
02166 case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
02167 }
02168
02169 time_format_common();
02170 }
02171
02172 void MWindow::time_format_common()
02173 {
02174 gui->lock_window("MWindow::next_time_format");
02175 gui->redraw_time_dependancies();
02176 char string[BCTEXTLEN], string2[BCTEXTLEN];
02177 sprintf(string, _("Using %s."), Units::print_time_format(edl->session->time_format, string2));
02178 gui->show_message(string);
02179 gui->flush();
02180 gui->unlock_window();
02181 }
02182
02183
02184 int MWindow::set_filename(char *filename)
02185 {
02186 strcpy(session->filename, filename);
02187 if(gui)
02188 {
02189 if(filename[0] == 0)
02190 {
02191 gui->set_title(PROGRAM_NAME);
02192 }
02193 else
02194 {
02195 FileSystem dir;
02196 char string[BCTEXTLEN], string2[BCTEXTLEN];
02197 dir.extract_name(string, filename);
02198 sprintf(string2, PROGRAM_NAME ": %s", string);
02199 gui->set_title(string2);
02200 }
02201 }
02202 return 0;
02203 }
02204
02205
02206
02207
02208
02209
02210
02211
02212 int MWindow::set_loop_boundaries()
02213 {
02214 double start = edl->local_session->get_selectionstart();
02215 double end = edl->local_session->get_selectionend();
02216
02217 if(start !=
02218 end)
02219 {
02220 ;
02221 }
02222 else
02223 if(edl->tracks->total_length())
02224 {
02225 start = 0;
02226 end = edl->tracks->total_length();
02227 }
02228 else
02229 {
02230 start = end = 0;
02231 }
02232
02233 if(edl->local_session->loop_playback && start != end)
02234 {
02235 edl->local_session->loop_start = start;
02236 edl->local_session->loop_end = end;
02237 }
02238 return 0;
02239 }
02240
02241
02242
02243
02244
02245
02246
02247 int MWindow::reset_meters()
02248 {
02249 cwindow->gui->lock_window("MWindow::reset_meters 1");
02250 cwindow->gui->meters->reset_meters();
02251 cwindow->gui->unlock_window();
02252
02253 vwindow->gui->lock_window("MWindow::reset_meters 2");
02254 vwindow->gui->meters->reset_meters();
02255 vwindow->gui->unlock_window();
02256
02257 lwindow->gui->lock_window("MWindow::reset_meters 3");
02258 lwindow->gui->panel->reset_meters();
02259 lwindow->gui->unlock_window();
02260
02261 gui->lock_window("MWindow::reset_meters 4");
02262 gui->patchbay->reset_meters();
02263 gui->unlock_window();
02264 return 0;
02265 }
02266