Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

render.C

Go to the documentation of this file.
00001 #include "arender.h"
00002 #include "asset.h"
00003 #include "auto.h"
00004 #include "batchrender.h"
00005 #include "bcprogressbox.h"
00006 #include "cache.h"
00007 #include "clip.h"
00008 #include "compresspopup.h"
00009 #include "condition.h"
00010 #include "confirmsave.h"
00011 #include "cwindowgui.h"
00012 #include "cwindow.h"
00013 #include "defaults.h"
00014 #include "edits.h"
00015 #include "edl.h"
00016 #include "edlsession.h"
00017 #include "errorbox.h"
00018 #include "file.h"
00019 #include "filesystem.h"
00020 #include "filexml.h"
00021 #include "formatcheck.h"
00022 #include "formatpopup.h"
00023 #include "formattools.h"
00024 #include "labels.h"
00025 #include "language.h"
00026 #include "loadmode.h"
00027 #include "localsession.h"
00028 #include "mainprogress.h"
00029 #include "mainsession.h"
00030 #include "mainundo.h"
00031 #include "module.h"
00032 #include "mutex.h"
00033 #include "mwindowgui.h"
00034 #include "mwindow.h"
00035 #include "packagedispatcher.h"
00036 #include "packagerenderer.h"
00037 #include "patchbay.h"
00038 #include "playabletracks.h"
00039 #include "preferences.h"
00040 #include "quicktime.h"
00041 #include "renderfarm.h"
00042 #include "render.h"
00043 #include "statusbar.h"
00044 #include "theme.h"
00045 #include "timebar.h"
00046 #include "tracks.h"
00047 #include "transportque.h"
00048 #include "vedit.h"
00049 #include "vframe.h"
00050 #include "videoconfig.h"
00051 #include "vrender.h"
00052 
00053 #include <ctype.h>
00054 #include <string.h>
00055 
00056 
00057 
00058 RenderItem::RenderItem(MWindow *mwindow)
00059  : BC_MenuItem(_("Render..."), "Shift+R", 'R')
00060 {
00061         this->mwindow = mwindow;
00062         set_shift(1);
00063 }
00064 
00065 int RenderItem::handle_event() 
00066 {
00067         mwindow->render->start_interactive();
00068         return 1;
00069 }
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 RenderProgress::RenderProgress(MWindow *mwindow, Render *render)
00081  : Thread()
00082 {
00083         this->mwindow = mwindow;
00084         this->render = render;
00085         last_value = 0;
00086         Thread::set_synchronous(1);
00087 }
00088 
00089 RenderProgress::~RenderProgress()
00090 {
00091         Thread::cancel();
00092         Thread::join();
00093 }
00094 
00095 
00096 void RenderProgress::run()
00097 {
00098         Thread::disable_cancel();
00099         while(1)
00100         {
00101                 if(render->total_rendered != last_value)
00102                 {
00103                         render->progress->update(render->total_rendered);
00104                         last_value = render->total_rendered;
00105                 }
00106 
00107                 Thread::enable_cancel();
00108                 sleep(1);
00109                 Thread::disable_cancel();
00110         }
00111 }
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 MainPackageRenderer::MainPackageRenderer(Render *render)
00123  : PackageRenderer()
00124 {
00125         this->render = render;
00126 }
00127 
00128 
00129 
00130 MainPackageRenderer::~MainPackageRenderer()
00131 {
00132 }
00133 
00134 
00135 int MainPackageRenderer::get_master()
00136 {
00137         return 1;
00138 }
00139 
00140 int MainPackageRenderer::get_result()
00141 {
00142         return render->result;
00143 }
00144 
00145 void MainPackageRenderer::set_result(int value)
00146 {
00147         if(value)
00148                 render->result = value;
00149 }
00150 
00151 void MainPackageRenderer::set_progress(int64_t value)
00152 {
00153         render->counter_lock->lock("MainPackageRenderer::set_progress");
00154         render->total_rendered += value;
00155 
00156 // If non interactive, print progress out
00157         if(!render->progress)
00158         {
00159                 int64_t current_eta = render->progress_timer->get_scaled_difference(1000);
00160                 if(current_eta - render->last_eta > 1000)
00161                 {
00162                         double eta = 0;
00163 
00164 
00165                         if(render->total_rendered)
00166                         {
00167                                 eta = current_eta /
00168                                         1000 *
00169                                         render->progress_max /
00170                                         render->total_rendered -
00171                                         current_eta /
00172                                         1000;
00173                         }
00174 
00175                         char string[BCTEXTLEN];
00176                         Units::totext(string, 
00177                                 eta,
00178                                 TIME_HMS2);
00179 
00180                         printf("\r%d%% ETA: %s      ", (int)(100 * 
00181                                 (float)render->total_rendered / 
00182                                         render->progress_max),
00183                                 string);
00184                         fflush(stdout);
00185                         render->last_eta = current_eta;
00186                 }
00187         }
00188 
00189         render->counter_lock->unlock();
00190 }
00191 
00192 int MainPackageRenderer::progress_cancelled()
00193 {
00194         return (render->progress && render->progress->is_cancelled()) || 
00195                 render->batch_cancelled;
00196 }
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 Render::Render(MWindow *mwindow)
00210  : Thread(0, 0, 0)
00211 {
00212         this->mwindow = mwindow;
00213         if(mwindow) plugindb = mwindow->plugindb;
00214         in_progress = 0;
00215         progress = 0;
00216         preferences = 0;
00217         elapsed_time = 0.0;
00218         package_lock = new Mutex("Render::package_lock");
00219         counter_lock = new Mutex("Render::counter_lock");
00220         completion = new Condition(0, "Render::completion");
00221         progress_timer = new Timer;
00222 }
00223 
00224 Render::~Render()
00225 {
00226         delete package_lock;
00227         delete counter_lock;
00228         delete completion;
00229         if(preferences) delete preferences;
00230         delete progress_timer;
00231 }
00232 
00233 void Render::start_interactive()
00234 {
00235         if(!Thread::running())
00236         {
00237                 mode = Render::INTERACTIVE;
00238                 this->jobs = 0;
00239                 batch_cancelled = 0;
00240                 completion->reset();
00241                 Thread::start();
00242         }
00243         else
00244         {
00245                 // raise the window if rendering hasn't started yet
00246                 if (render_window && ! in_progress) {
00247                         render_window->raise_window();
00248                 }
00249                 else {
00250                         ErrorBox error_box(PROGRAM_NAME ": Error",
00251                                            mwindow->gui->get_abs_cursor_x(1),
00252                                            mwindow->gui->get_abs_cursor_y(1));
00253                         error_box.create_objects("Already rendering");
00254                         error_box.run_window();
00255                 }
00256         }
00257 }
00258 
00259 void Render::start_batches(ArrayList<BatchRenderJob*> *jobs)
00260 {
00261         batch_cancelled = 0;
00262         if(!Thread::running())
00263         {
00264                 mode = Render::BATCH;
00265                 this->jobs = jobs;
00266                 completion->reset();
00267                 Thread::start();
00268         }
00269         else
00270         {
00271                 ErrorBox error_box(PROGRAM_NAME ": Error",
00272                         mwindow->gui->get_abs_cursor_x(1),
00273                         mwindow->gui->get_abs_cursor_y(1));
00274                 error_box.create_objects("Already rendering");
00275                 error_box.run_window();
00276         }
00277 }
00278 
00279 void Render::start_batches(ArrayList<BatchRenderJob*> *jobs,
00280         Defaults *boot_defaults,
00281         Preferences *preferences,
00282         ArrayList<PluginServer*> *plugindb)
00283 {
00284         mode = Render::BATCH;
00285         batch_cancelled = 0;
00286         this->jobs = jobs;
00287         this->preferences = preferences;
00288         this->plugindb = plugindb;
00289 
00290         completion->reset();
00291         run();
00292         this->preferences = 0;
00293 }
00294 
00295 void Render::stop_operation()
00296 {
00297         if(Thread::running())
00298         {
00299                 batch_cancelled = 1;
00300 // Wait for completion
00301                 completion->lock("Render::stop_operation");
00302                 completion->reset();
00303         }
00304 }
00305 
00306 
00307 void Render::run()
00308 {
00309         int format_error;
00310 
00311 
00312         result = 0;
00313 
00314         if(mode == Render::INTERACTIVE)
00315         {
00316 // Fix the asset for rendering
00317                 Asset *asset = new Asset;
00318                 load_defaults(asset);
00319                 check_asset(mwindow->edl, *asset);
00320 
00321 // Get format from user
00322                 if(!result)
00323                 {
00324                         do
00325                         {
00326                                 format_error = 0;
00327                                 result = 0;
00328 
00329                                 {
00330                                         render_window = new RenderWindow(mwindow, this, asset);
00331                                         render_window->create_objects();
00332                                         result = render_window->run_window();
00333                                         if (! result) {
00334                                                 // add to recentlist only on OK
00335                                                 render_window->format_tools->path_recent->add_item(FILE_FORMAT_PREFIX(asset->format), asset->path);
00336                                         }
00337                                         delete render_window;
00338                                         render_window = 0;
00339                                 }
00340 
00341                                 if(!result)
00342                                 {
00343 // Check the asset format for errors.
00344                                         FormatCheck format_check(asset);
00345                                         format_error = format_check.check_format();
00346                                 }
00347                         }while(format_error && !result);
00348                 }
00349 
00350                 save_defaults(asset);
00351                 mwindow->save_defaults();
00352 
00353                 if(!result) render(1, asset, mwindow->edl, strategy);
00354 
00355                 delete asset;
00356         }
00357         else
00358         if(mode == Render::BATCH)
00359         {
00360                 for(int i = 0; i < jobs->total && !result; i++)
00361                 {
00362                         BatchRenderJob *job = jobs->values[i];
00363                         if(job->enabled)
00364                         {
00365                                 if(mwindow)
00366                                 {
00367                                         mwindow->batch_render->update_active(i);
00368                                 }
00369                                 else
00370                                 {
00371                                         printf("Render::run: %s\n", job->edl_path);
00372                                 }
00373 
00374 
00375                                 FileXML *file = new FileXML;
00376                                 EDL *edl = new EDL;
00377                                 edl->create_objects();
00378                                 file->read_from_file(job->edl_path);
00379                                 if(!plugindb && mwindow)
00380                                         plugindb = mwindow->plugindb;
00381                                 edl->load_xml(plugindb, file, LOAD_ALL);
00382 
00383                                 render(0, job->asset, edl, job->strategy);
00384 
00385                                 delete edl;
00386                                 delete file;
00387                                 if(!result)
00388                                 {
00389                                         if(mwindow)
00390                                                 mwindow->batch_render->update_done(i, 1, elapsed_time);
00391                                         else
00392                                         {
00393                                                 char string[BCTEXTLEN];
00394                                                 elapsed_time = 
00395                                                         (double)progress_timer->get_scaled_difference(1);
00396                                                 Units::totext(string,
00397                                                         elapsed_time,
00398                                                         TIME_HMS2);
00399                                                 printf("Render::run: done in %s\n", string);
00400                                         }
00401                                 }
00402                                 else
00403                                 {
00404                                         if(mwindow)
00405                                                 mwindow->batch_render->update_active(-1);
00406                                         else
00407                                                 printf("Render::run: failed\n");
00408                                 }
00409                         }
00410                 }
00411 
00412                 if(mwindow)
00413                 {
00414                         mwindow->batch_render->update_active(-1);
00415                         mwindow->batch_render->update_done(-1, 0, 0);
00416                 }
00417         }
00418 }
00419 
00420 
00421 
00422 int Render::check_asset(EDL *edl, Asset &asset)
00423 {
00424         if(asset.video_data && 
00425                 edl->tracks->playable_video_tracks() &&
00426                 File::supports_video(asset.format))
00427         {
00428                 asset.video_data = 1;
00429                 asset.layers = 1;
00430                 asset.width = edl->session->output_w;
00431                 asset.height = edl->session->output_h;
00432                 asset.interlace_mode = edl->session->interlace_mode;
00433                 asset.tcstart = (int64_t) (edl->session->get_frame_offset() +
00434                         edl->local_session->get_selectionstart() *
00435                                 edl->session->frame_rate);
00436                 asset.tcend = (int64_t) (edl->session->get_frame_offset() +
00437                         edl->local_session->get_selectionend() *
00438                                 edl->session->frame_rate);
00439         }
00440         else
00441         {
00442                 asset.video_data = 0;
00443                 asset.layers = 0;
00444                 asset.tcstart = 0;
00445                 asset.tcend = 0;
00446         }
00447 
00448         if(asset.audio_data && 
00449                 edl->tracks->playable_audio_tracks() &&
00450                 File::supports_audio(asset.format))
00451         {
00452                 asset.audio_data = 1;
00453                 asset.channels = edl->session->audio_channels;
00454                 if(asset.format == FILE_MOV) asset.byte_order = 0;
00455                 asset.tcstart = (int64_t) (edl->session->get_frame_offset() +
00456                         edl->local_session->get_selectionstart() *
00457                                 edl->session->sample_rate);
00458                 asset.tcend = (int64_t) (edl->session->get_frame_offset() +
00459                         edl->local_session->get_selectionend() *
00460                                 edl->session->sample_rate);
00461         }
00462         else
00463         {
00464                 asset.audio_data = 0;
00465                 asset.channels = 0;
00466                 asset.tcstart = 0;
00467                 asset.tcend = 0;
00468         }
00469 
00470         if(!asset.audio_data &&
00471                 !asset.video_data)
00472         {
00473                 return 1;
00474         }
00475         return 0;
00476 }
00477 
00478 int Render::fix_strategy(int strategy, int use_renderfarm)
00479 {
00480         if(use_renderfarm)
00481         {
00482                 if(strategy == FILE_PER_LABEL)
00483                         strategy = FILE_PER_LABEL_FARM;
00484                 else
00485                 if(strategy == SINGLE_PASS)
00486                         strategy = SINGLE_PASS_FARM;
00487         }
00488         else
00489         {
00490                 if(strategy == FILE_PER_LABEL_FARM)
00491                         strategy = FILE_PER_LABEL;
00492                 else
00493                 if(strategy == SINGLE_PASS_FARM)
00494                         strategy = SINGLE_PASS;
00495         }
00496         return strategy;
00497 }
00498 
00499 void Render::start_progress()
00500 {
00501         char filename[BCTEXTLEN];
00502         char string[BCTEXTLEN];
00503         FileSystem fs;
00504 
00505         progress_max = Units::to_int64(default_asset->sample_rate * 
00506                         (total_end - total_start)) +
00507                 Units::to_int64(preferences->render_preroll * 
00508                         packages->total_allocated * 
00509                         default_asset->sample_rate);
00510         progress_timer->update();
00511         last_eta = 0;
00512         if(mwindow)
00513         {
00514 // Generate the progress box
00515                 fs.extract_name(filename, default_asset->path);
00516                 sprintf(string, _("Rendering %s..."), filename);
00517 
00518 // Don't bother with the filename since renderfarm defeats the meaning
00519                 progress = mwindow->mainprogress->start_progress(_("Rendering..."), 
00520                         progress_max);
00521                 render_progress = new RenderProgress(mwindow, this);
00522                 render_progress->start();
00523         }
00524 }
00525 
00526 void Render::stop_progress()
00527 {
00528         if(progress)
00529         {
00530                 char string[BCTEXTLEN], string2[BCTEXTLEN];
00531                 delete render_progress;
00532                 progress->get_time(string);
00533                 elapsed_time = progress->get_time();
00534                 progress->stop_progress();
00535                 delete progress;
00536 
00537                 sprintf(string2, _("Rendering took %s"), string);
00538                 mwindow->gui->lock_window("");
00539                 mwindow->gui->show_message(string2);
00540                 mwindow->gui->stop_hourglass();
00541                 mwindow->gui->unlock_window();
00542         }
00543         progress = 0;
00544 }
00545 
00546 
00547 
00548 int Render::render(int test_overwrite, 
00549         Asset *asset,
00550         EDL *edl,
00551         int strategy)
00552 {
00553         char string[BCTEXTLEN];
00554 // Total length in seconds
00555         double total_length;
00556         int last_audio_buffer;
00557         RenderFarmServer *farm_server = 0;
00558         FileSystem fs;
00559         int total_digits;      // Total number of digits including padding the user specified.
00560         int number_start;      // Character in the filename path at which the number begins
00561         int current_number;    // The number the being injected into the filename.
00562 // Pointer from file
00563 // (VFrame*)(VFrame array [])(Channel [])
00564         VFrame ***video_output;
00565 // Pointer to output buffers
00566         VFrame *video_output_ptr[MAX_CHANNELS];
00567         double *audio_output_ptr[MAX_CHANNELS];
00568         int done = 0;
00569         in_progress = 1;
00570 
00571 
00572         this->default_asset = asset;
00573         progress = 0;
00574         result = 0;
00575 
00576         if(mwindow)
00577         {
00578                 if(!preferences)
00579                         preferences = new Preferences;
00580 
00581                 preferences->copy_from(mwindow->preferences);
00582         }
00583 
00584 
00585 // Create rendering command
00586         command = new TransportCommand;
00587         command->command = NORMAL_FWD;
00588         command->get_edl()->copy_all(edl);
00589         command->change_type = CHANGE_ALL;
00590 // Get highlighted playback range
00591         command->set_playback_range();
00592 // Adjust playback range with in/out points
00593         command->adjust_playback_range();
00594         packages = new PackageDispatcher;
00595 
00596 
00597 // Configure preview monitor
00598         VideoOutConfig vconfig;
00599         PlaybackConfig *playback_config = new PlaybackConfig;
00600         for(int i = 0; i < MAX_CHANNELS; i++)
00601         {
00602                 vconfig.do_channel[i] = (i < command->get_edl()->session->video_channels);
00603                 playback_config->vconfig->do_channel[i] = (i < command->get_edl()->session->video_channels);
00604                 playback_config->aconfig->do_channel[i] = (i < command->get_edl()->session->audio_channels);
00605         }
00606 
00607 // Create caches
00608         audio_cache = new CICache(command->get_edl(), preferences, plugindb);
00609         video_cache = new CICache(command->get_edl(), preferences, plugindb);
00610 
00611         default_asset->frame_rate = command->get_edl()->session->frame_rate;
00612         default_asset->sample_rate = command->get_edl()->session->sample_rate;
00613 
00614 // Conform asset to EDL.  Find out if any tracks are playable.
00615         result = check_asset(command->get_edl(), *default_asset);
00616 
00617         if(!result)
00618         {
00619 // Get total range to render
00620                 total_start = command->start_position;
00621                 total_end = command->end_position;
00622                 total_length = total_end - total_start;
00623 
00624 // Nothing to render
00625                 if(EQUIV(total_length, 0))
00626                 {
00627                         result = 1;
00628                 }
00629         }
00630 
00631 
00632 
00633 
00634 
00635 
00636 
00637 // Generate packages
00638         if(!result)
00639         {
00640 // Stop background rendering
00641                 if(mwindow) mwindow->stop_brender();
00642 
00643                 fs.complete_path(default_asset->path);
00644                 strategy = Render::fix_strategy(strategy, preferences->use_renderfarm);
00645 
00646                 result = packages->create_packages(mwindow,
00647                         command->get_edl(),
00648                         preferences,
00649                         strategy, 
00650                         default_asset, 
00651                         total_start, 
00652                         total_end,
00653                         test_overwrite);
00654         }
00655 
00656 
00657 
00658 
00659 
00660 
00661 
00662 
00663 
00664 
00665         done = 0;
00666         total_rendered = 0;
00667         frames_per_second = 0;
00668 
00669         if(!result)
00670         {
00671 // Start dispatching external jobs
00672                 if(mwindow)
00673                 {
00674                         mwindow->gui->lock_window("Render::render 1");
00675                         mwindow->gui->show_message(_("Starting render farm"));
00676                         mwindow->gui->start_hourglass();
00677                         mwindow->gui->unlock_window();
00678                 }
00679                 else
00680                 {
00681                         printf("Render::render: starting render farm\n");
00682                 }
00683 
00684                 if(strategy == SINGLE_PASS_FARM || strategy == FILE_PER_LABEL_FARM)
00685                 {
00686                         farm_server = new RenderFarmServer(plugindb, 
00687                                 packages,
00688                                 preferences, 
00689                                 1,
00690                                 &result,
00691                                 &total_rendered,
00692                                 counter_lock,
00693                                 default_asset,
00694                                 command->get_edl(),
00695                                 0);
00696                         result = farm_server->start_clients();
00697 
00698                         if(result)
00699                         {
00700                                 if(mwindow)
00701                                 {
00702                                         mwindow->gui->lock_window("Render::render 2");
00703                                         mwindow->gui->show_message(_("Failed to start render farm"),
00704                                                 mwindow->theme->message_error);
00705                                         mwindow->gui->stop_hourglass();
00706                                         mwindow->gui->unlock_window();
00707                                 }
00708                                 else
00709                                 {
00710                                         printf("Render::render: Failed to start render farm\n");
00711                                 }
00712                         }
00713                 }
00714         }
00715 
00716 
00717 
00718 
00719 // Perform local rendering
00720 
00721 
00722         if(!result)
00723         {
00724                 start_progress();
00725         
00726 
00727 
00728 
00729                 MainPackageRenderer package_renderer(this);
00730                 result = package_renderer.initialize(mwindow,
00731                                 command->get_edl(),   // Copy of master EDL
00732                                 preferences, 
00733                                 default_asset,
00734                                 plugindb);
00735 
00736 
00737 
00738 
00739 
00740 
00741 
00742                 while(!result)
00743                 {
00744 // Get unfinished job
00745                         RenderPackage *package;
00746 
00747                         if(strategy == SINGLE_PASS_FARM)
00748                         {
00749                                 package = packages->get_package(frames_per_second, -1, 1);
00750                         }
00751                         else
00752                         {
00753                                 package = packages->get_package(0, -1, 1);
00754                         }
00755 
00756 // Exit point
00757                         if(!package) 
00758                         {
00759                                 done = 1;
00760                                 break;
00761                         }
00762 
00763 
00764 
00765                         Timer timer;
00766                         timer.update();
00767 
00768                         if(package_renderer.render_package(package))
00769                                 result = 1;
00770 
00771 // Result is also set directly by the RenderFarm.
00772 
00773                         frames_per_second = (double)(package->video_end - package->video_start) / 
00774                                 (double)(timer.get_difference() / 1000);
00775 
00776 
00777                 } // file_number
00778 
00779 
00780 
00781 //printf("Render::run: Session finished.\n");
00782 
00783 
00784 //printf("Render::render 80\n");
00785 
00786 
00787 
00788                 if(strategy == SINGLE_PASS_FARM || strategy == FILE_PER_LABEL_FARM)
00789                 {
00790                         farm_server->wait_clients();
00791                 }
00792 
00793 //printf("Render::render 90\n");
00794 
00795 // Notify of error
00796                 if(result && 
00797                         (!progress || !progress->is_cancelled()) &&
00798                         !batch_cancelled)
00799                 {
00800                         if(mwindow)
00801                         {
00802                                 ErrorBox error_box(PROGRAM_NAME ": Error",
00803                                         mwindow->gui->get_abs_cursor_x(1),
00804                                         mwindow->gui->get_abs_cursor_y(1));
00805                                 error_box.create_objects(_("Error rendering data."));
00806                                 error_box.run_window();
00807                         }
00808                         else
00809                         {
00810                                 printf("Render::render: Error rendering data\n");
00811                         }
00812                 }
00813 
00814 // Delete the progress box
00815                 stop_progress();
00816 
00817 //printf("Render::render 100\n");
00818 
00819 
00820 
00821 
00822         }
00823 
00824 
00825 // Paste all packages into timeline if desired
00826 
00827         if(!result && 
00828                 load_mode != LOAD_NOTHING && 
00829                 mwindow &&
00830                 mode != Render::BATCH)
00831         {
00832                 mwindow->gui->lock_window("Render::render 3");
00833 
00834 
00835 
00836 
00837                 ArrayList<Asset*> *assets = packages->get_asset_list();
00838                 if(load_mode == LOAD_PASTE)
00839                         mwindow->clear(0);
00840                 mwindow->load_assets(assets, 
00841                         -1, 
00842                         load_mode,
00843                         0,
00844                         0,
00845                         mwindow->edl->session->labels_follow_edits,
00846                         mwindow->edl->session->plugins_follow_edits);
00847                 assets->remove_all_objects();
00848                 delete assets;
00849 
00850 
00851                 mwindow->save_backup();
00852                 mwindow->undo->update_undo(_("render"), LOAD_ALL);
00853                 mwindow->update_plugin_guis();
00854                 mwindow->gui->update(1, 
00855                         2,
00856                         1,
00857                         1,
00858                         1,
00859                         1,
00860                         0);
00861                 mwindow->sync_parameters(CHANGE_ALL);
00862                 mwindow->gui->unlock_window();
00863         }
00864 
00865 
00866 // Disable hourglass
00867         if(mwindow)
00868         {
00869                 mwindow->gui->lock_window("Render::render 3");
00870                 mwindow->gui->stop_hourglass();
00871                 mwindow->gui->unlock_window();
00872         }
00873 
00874 //printf("Render::render 110\n");
00875 // Need to restart because brender always stops before render.
00876         if(mwindow)
00877                 mwindow->restart_brender();
00878         if(farm_server) delete farm_server;
00879         delete command;
00880         delete playback_config;
00881         delete audio_cache;
00882         delete video_cache;
00883 // Must delete packages after server
00884         delete packages;
00885         in_progress = 0;
00886         completion->unlock();
00887 //printf("Render::render 120\n");
00888 
00889         return result;
00890 }
00891 
00892 
00893 void Render::create_filename(char *path, 
00894         char *default_path, 
00895         int current_number,
00896         int total_digits,
00897         int number_start)
00898 {
00899         int i, j, k;
00900         int len = strlen(default_path);
00901         char printf_string[BCTEXTLEN];
00902         int found_number = 0;
00903 
00904         for(i = 0, j = 0; i < number_start; i++, j++)
00905         {
00906                 printf_string[j] = default_path[i];
00907         }
00908 
00909 // Found the number
00910         sprintf(&printf_string[j], "%%0%dd", total_digits);
00911         j = strlen(printf_string);
00912         i += total_digits;
00913 
00914 // Copy remainder of string
00915         for( ; i < len; i++, j++)
00916         {
00917                 printf_string[j] = default_path[i];
00918         }
00919         printf_string[j] = 0;
00920 // Print the printf argument to the path
00921         sprintf(path, printf_string, current_number);
00922 }
00923 
00924 void Render::get_starting_number(char *path, 
00925         int &current_number,
00926         int &number_start, 
00927         int &total_digits,
00928         int min_digits)
00929 {
00930         int i, j;
00931         int len = strlen(path);
00932         char number_text[BCTEXTLEN];
00933         char *ptr = 0;
00934         char *ptr2 = 0;
00935 
00936         total_digits = 0;
00937         number_start = 0;
00938 
00939 // Search for last /
00940         ptr2 = strrchr(path, '/');
00941 
00942 // Search for first 0 after last /.
00943         if(ptr2)
00944                 ptr = strchr(ptr2, '0');
00945 
00946         if(ptr && isdigit(*ptr))
00947         {
00948                 number_start = ptr - path;
00949 
00950 // Store the first number
00951                 char *ptr2 = number_text;
00952                 while(isdigit(*ptr))
00953                         *ptr2++ = *ptr++;
00954                 *ptr2++ = 0;
00955                 current_number = atol(number_text);
00956                 total_digits = strlen(number_text);
00957         }
00958 
00959 
00960 // No number found or number not long enough
00961         if(total_digits < min_digits)
00962         {
00963                 current_number = 1;
00964                 number_start = len;
00965                 total_digits = min_digits;
00966         }
00967 }
00968 
00969 
00970 
00971 
00972 
00973 
00974 
00975 int Render::load_defaults(Asset *asset)
00976 {
00977         strategy = mwindow->defaults->get("RENDER_STRATEGY", SINGLE_PASS);
00978         load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOAD_NEW_TRACKS);
00979 
00980 
00981         asset->load_defaults(mwindow->defaults, 
00982                 "RENDER_", 
00983                 1,
00984                 1,
00985                 1,
00986                 1,
00987                 1);
00988 
00989 
00990         return 0;
00991 }
00992 
00993 int Render::save_defaults(Asset *asset)
00994 {
00995         mwindow->defaults->update("RENDER_STRATEGY", strategy);
00996         mwindow->defaults->update("RENDER_LOADMODE", load_mode);
00997 
00998 
00999 
01000 
01001         asset->save_defaults(mwindow->defaults, 
01002                 "RENDER_",
01003                 1,
01004                 1,
01005                 1,
01006                 1,
01007                 1);
01008 
01009         return 0;
01010 }
01011 
01012 
01013 
01014 
01015 #define WIDTH 410
01016 #define HEIGHT 360
01017 
01018 
01019 RenderWindow::RenderWindow(MWindow *mwindow, Render *render, Asset *asset)
01020  : BC_Window(PROGRAM_NAME ": Render", 
01021         mwindow->gui->get_root_w(0, 1) / 2 - WIDTH / 2,
01022         mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2,
01023         WIDTH, 
01024         HEIGHT,
01025         (int)BC_INFINITY,
01026         (int)BC_INFINITY,
01027         0,
01028         0,
01029         1)
01030 {
01031         this->mwindow = mwindow;
01032         this->render = render;
01033         this->asset = asset;
01034 }
01035 
01036 RenderWindow::~RenderWindow()
01037 {
01038         delete format_tools;
01039         delete loadmode;
01040 }
01041 
01042 
01043 
01044 int RenderWindow::create_objects()
01045 {
01046         int x = 5, y = 5;
01047         add_subwindow(new BC_Title(x, 
01048                 y, 
01049                 (char*)((render->strategy == FILE_PER_LABEL || 
01050                                 render->strategy == FILE_PER_LABEL_FARM) ? 
01051                         _("Select the first file to render to:") : 
01052                         _("Select a file to render to:"))));
01053         y += 25;
01054 
01055         format_tools = new FormatTools(mwindow,
01056                                         this, 
01057                                         asset);
01058         format_tools->create_objects(x, 
01059                 y, 
01060                 1, 
01061                 1, 
01062                 1, 
01063                 1, 
01064                 0,
01065                 1,
01066                 0,
01067                 0,
01068                 &render->strategy,
01069                 0);
01070 
01071         loadmode = new LoadMode(mwindow, this, x, y, &render->load_mode, 1);
01072         loadmode->create_objects();
01073 
01074         add_subwindow(new BC_OKButton(this));
01075         add_subwindow(new BC_CancelButton(this));
01076         show_window();
01077         return 0;
01078 }

Generated on Sun Jan 8 13:39:00 2006 for Cinelerra-svn by  doxygen 1.4.4