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

virtualvnode.C

Go to the documentation of this file.
00001 #include "asset.h"
00002 #include "automation.h"
00003 #include "bcsignals.h"
00004 #include "clip.h"
00005 #include "edit.h"
00006 #include "edits.h"
00007 #include "edl.h"
00008 #include "edlsession.h"
00009 #include "fadeengine.h"
00010 #include "floatauto.h"
00011 #include "floatautos.h"
00012 #include "intauto.h"
00013 #include "intautos.h"
00014 #include "maskengine.h"
00015 #include "mwindow.h"
00016 #include "module.h"
00017 #include "overlayframe.h"
00018 #include "playabletracks.h"
00019 #include "plugin.h"
00020 #include "preferences.h"
00021 #include "renderengine.h"
00022 #include "transition.h"
00023 #include "transportque.h"
00024 #include "vattachmentpoint.h"
00025 #include "vedit.h"
00026 #include "vframe.h"
00027 #include "virtualvconsole.h"
00028 #include "virtualvnode.h"
00029 #include "vmodule.h"
00030 #include "vrender.h"
00031 #include "vtrack.h"
00032 
00033 #include <string.h>
00034 
00035 
00036 VirtualVNode::VirtualVNode(RenderEngine *renderengine, 
00037                 VirtualConsole *vconsole, 
00038                 Module *real_module, 
00039                 Plugin *real_plugin,
00040                 Track *track, 
00041                 VirtualNode *parent_node)
00042  : VirtualNode(renderengine, 
00043                 vconsole, 
00044                 real_module, 
00045                 real_plugin,
00046                 track, 
00047                 parent_node)
00048 {
00049         VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
00050         fader = new FadeEngine(renderengine->preferences->processors);
00051         masker = new MaskEngine(renderengine->preferences->processors);
00052 }
00053 
00054 VirtualVNode::~VirtualVNode()
00055 {
00056         delete fader;
00057         delete masker;
00058 }
00059 
00060 VirtualNode* VirtualVNode::create_module(Plugin *real_plugin, 
00061                                                         Module *real_module, 
00062                                                         Track *track)
00063 {
00064         return new VirtualVNode(renderengine, 
00065                 vconsole, 
00066                 real_module,
00067                 0,
00068                 track,
00069                 this);
00070 }
00071 
00072 
00073 VirtualNode* VirtualVNode::create_plugin(Plugin *real_plugin)
00074 {
00075         return new VirtualVNode(renderengine, 
00076                 vconsole, 
00077                 0,
00078                 real_plugin,
00079                 track,
00080                 this);
00081 }
00082 
00083 int VirtualVNode::read_data(VFrame *output_temp,
00084         int64_t start_position,
00085         double frame_rate)
00086 {
00087         VirtualNode *previous_plugin = 0;
00088 SET_TRACE
00089 
00090         if(!output_temp) printf("VirtualVNode::read_data output_temp=%p\n", output_temp);
00091 SET_TRACE
00092 
00093         if(vconsole->debug_tree) 
00094                 printf("  VirtualVNode::read_data position=%lld rate=%f title=%s\n", 
00095                         start_position,
00096                         frame_rate,
00097                         track->title);
00098 
00099 // This is a plugin on parent module with a preceeding effect.
00100 // Get data from preceeding effect on parent module.
00101         if(parent_node && (previous_plugin = parent_node->get_previous_plugin(this)))
00102         {
00103                 return ((VirtualVNode*)previous_plugin)->render(output_temp,
00104                         start_position,
00105                         frame_rate);
00106         }
00107         else
00108 // First plugin on parent module.
00109 // Read data from parent module
00110         if(parent_node)
00111         {
00112                 return ((VirtualVNode*)parent_node)->read_data(output_temp,
00113                         start_position,
00114                         frame_rate);
00115         }
00116         else
00117         {
00118 // This is the first node in the tree
00119                 return ((VModule*)real_module)->render(output_temp,
00120                         start_position,
00121                         renderengine->command->get_direction(),
00122                         frame_rate,
00123                         0,
00124                         vconsole->debug_tree);
00125         }
00126 SET_TRACE
00127 
00128         return 0;
00129 }
00130 
00131 
00132 int VirtualVNode::render(VFrame *output_temp, 
00133         int64_t start_position,
00134         double frame_rate)
00135 {
00136         VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
00137         if(real_module)
00138         {
00139 SET_TRACE
00140                 render_as_module(vrender->video_out, 
00141                         output_temp,
00142                         start_position,
00143                         frame_rate);
00144 SET_TRACE
00145         }
00146         else
00147         if(real_plugin)
00148         {
00149                 render_as_plugin(output_temp,
00150                         start_position,
00151                         frame_rate);
00152         }
00153         return 0;
00154 }
00155 
00156 void VirtualVNode::render_as_plugin(VFrame *output_temp, 
00157         int64_t start_position,
00158         double frame_rate)
00159 {
00160         if(!attachment ||
00161                 !real_plugin ||
00162                 !real_plugin->on) return;
00163 
00164 
00165         if(vconsole->debug_tree) 
00166                 printf("  VirtualVNode::render_as_plugin title=%s\n", track->title);
00167 
00168         ((VAttachmentPoint*)attachment)->render(
00169                 output_temp,
00170                 plugin_buffer_number,
00171                 start_position,
00172                 frame_rate,
00173                 vconsole->debug_tree);
00174 }
00175 
00176 
00177 int VirtualVNode::render_as_module(VFrame **video_out, 
00178         VFrame *output_temp,
00179         int64_t start_position,
00180         double frame_rate)
00181 {
00182 
00183         int direction = renderengine->command->get_direction();
00184         double edl_rate = renderengine->edl->session->frame_rate;
00185 
00186         if(vconsole->debug_tree) 
00187                 printf("  VirtualVNode::render_as_module title=%s\n", track->title);
00188 SET_TRACE
00189 
00190 // Process last subnode.  This propogates up the chain of subnodes and finishes
00191 // the chain.
00192         if(subnodes.total)
00193         {
00194                 VirtualVNode *node = (VirtualVNode*)subnodes.values[subnodes.total - 1];
00195                 node->render(output_temp,
00196                         start_position,
00197                         frame_rate);
00198         }
00199         else
00200 // Read data from previous entity
00201         {
00202                 read_data(output_temp,
00203                         start_position,
00204                         frame_rate);
00205         }
00206 SET_TRACE
00207 
00208         render_fade(output_temp,
00209                                 start_position,
00210                                 frame_rate,
00211                                 track->automation->autos[AUTOMATION_FADE],
00212                                 direction);
00213 SET_TRACE
00214 
00215 // Apply mask to output
00216         masker->do_mask(output_temp, 
00217                 start_position,
00218                 frame_rate,
00219                 edl_rate,
00220                 (MaskAutos*)track->automation->autos[AUTOMATION_MASK], 
00221                 direction);
00222 SET_TRACE
00223 
00224 
00225 // overlay on the final output
00226 // Get mute status
00227         int mute_constant;
00228         int mute_fragment = 1;
00229         int64_t mute_position = 0;
00230 
00231 
00232 // Is frame muted?
00233         get_mute_fragment(start_position,
00234                         mute_constant, 
00235                         mute_fragment, 
00236                         (Autos*)((VTrack*)track)->automation->autos[AUTOMATION_MUTE],
00237                         direction,
00238                         0);
00239 SET_TRACE
00240 
00241         if(!mute_constant)
00242         {
00243 // Fragment is playable
00244                 render_projector(output_temp,
00245                         video_out,
00246                         start_position,
00247                         frame_rate);
00248         }
00249 SET_TRACE
00250 
00251         Edit *edit = 0;
00252         if(renderengine->show_tc)
00253                 renderengine->vrender->insert_timecode(edit,
00254                         start_position,
00255                         output_temp);
00256 
00257         return 0;
00258 }
00259 
00260 int VirtualVNode::render_fade(VFrame *output,        
00261 // start of input fragment in project if forward / end of input fragment if reverse
00262 // relative to requested frame rate
00263                         int64_t start_position, 
00264                         double frame_rate, 
00265                         Autos *autos,
00266                         int direction)
00267 {
00268         double slope, intercept;
00269         int64_t slope_len = 1;
00270         FloatAuto *previous = 0;
00271         FloatAuto *next = 0;
00272         double edl_rate = renderengine->edl->session->frame_rate;
00273         int64_t start_position_project = (int64_t)(start_position * 
00274                 edl_rate /
00275                 frame_rate);
00276 
00277         if(vconsole->debug_tree) 
00278                 printf("  VirtualVNode::render_fade title=%s\n", track->title);
00279 
00280         intercept = ((FloatAutos*)autos)->get_value(start_position_project, 
00281                 direction,
00282                 previous,
00283                 next);
00284 
00285 
00286 //      CLAMP(intercept, 0, 100);
00287 
00288 
00289 // Can't use overlay here because overlayer blends the frame with itself.
00290 // The fade engine can compensate for lack of alpha channels by reducing the 
00291 // color components.
00292         if(!EQUIV(intercept / 100, 1))
00293         {
00294                 fader->do_fade(output, output, intercept / 100);
00295         }
00296 
00297         return 0;
00298 }
00299 
00300 // Start of input fragment in project if forward.  End of input fragment if reverse.
00301 int VirtualVNode::render_projector(VFrame *input,
00302                         VFrame **output,
00303                         int64_t start_position,
00304                         double frame_rate)
00305 {
00306         float in_x1, in_y1, in_x2, in_y2;
00307         float out_x1, out_y1, out_x2, out_y2;
00308         double edl_rate = renderengine->edl->session->frame_rate;
00309         int64_t start_position_project = (int64_t)(start_position * 
00310                 edl_rate /
00311                 frame_rate);
00312         VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
00313         if(vconsole->debug_tree) 
00314                 printf("  VirtualVNode::render_projector title=%s\n", track->title);
00315 
00316         for(int i = 0; i < MAX_CHANNELS; i++)
00317         {
00318                 if(output[i])
00319                 {
00320                         ((VTrack*)track)->calculate_output_transfer(i,
00321                                 start_position_project,
00322                                 renderengine->command->get_direction(),
00323                                 in_x1, 
00324                                 in_y1, 
00325                                 in_x2, 
00326                                 in_y2,
00327                                 out_x1, 
00328                                 out_y1, 
00329                                 out_x2, 
00330                                 out_y2);
00331 
00332                         in_x2 += in_x1;
00333                         in_y2 += in_y1;
00334                         out_x2 += out_x1;
00335                         out_y2 += out_y1;
00336 
00337 //for(int j = 0; j < input->get_w() * 3 * 5; j++)
00338 //      input->get_rows()[0][j] = 255;
00339 // 
00340                         if(out_x2 > out_x1 && 
00341                                 out_y2 > out_y1 && 
00342                                 in_x2 > in_x1 && 
00343                                 in_y2 > in_y1)
00344                         {
00345                                 int direction = renderengine->command->get_direction();
00346                                 IntAuto *mode_keyframe = 0;
00347                                 mode_keyframe = 
00348                                         (IntAuto*)track->automation->autos[AUTOMATION_MODE]->get_prev_auto(
00349                                                 start_position_project, 
00350                                                 direction,
00351                                                 (Auto* &)mode_keyframe);
00352 
00353                                 int mode = mode_keyframe->value;
00354 
00355 // Fade is performed in render_fade so as to allow this module
00356 // to be chained in another module, thus only 4 component colormodels
00357 // can do dissolves, although a blend equation is still required for 3 component
00358 // colormodels since fractional translation requires blending.
00359 
00360 // If this is the only playable video track and the mode_keyframe is "normal"
00361 // the mode keyframe may be overridden with "replace".  Replace is faster.
00362                                 if(mode == TRANSFER_NORMAL &&
00363                                         vconsole->total_entry_nodes == 1)
00364                                         mode = TRANSFER_REPLACE;
00365 
00366 
00367                                 vrender->overlayer->overlay(output[i], 
00368                                         input,
00369                                         in_x1, 
00370                                         in_y1, 
00371                                         in_x2, 
00372                                         in_y2,
00373                                         out_x1, 
00374                                         out_y1, 
00375                                         out_x2, 
00376                                         out_y2, 
00377                                         1,
00378                                         mode, 
00379                                         renderengine->edl->session->interpolation_type);
00380                         }
00381 // for(int j = 0; j < output[i]->get_w() * 3 * 5; j++)
00382 //      output[i]->get_rows()[0][j] = 255;
00383                 }
00384         }
00385         return 0;
00386 }
00387 

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