HDK
|
This example shows how to create a CHOP generator, create tracks and add handles to the graph. The channels generated are "stairs" - flat with periodic jumps.
These code fragments are taken from CHOP_Stair.C.
The first two headers are required for all HDK OPs, while the last three headers are generally required for most CHOP nodes.
The first two includes are required when using CHOP viewport handle.
This chunk of code creates the parameter dialog for the CHOP. Wherever possible, use the standard names, defaults and ranges found in PRM_ChopShared.h.
This CHOP, like many CHOPs, defines the C and NC local variables. C is the local variable for the currently cooking track, while NC is the total number of tracks in the clip.
The stair CHOP is derived directly from CHOP_Node. We initialize our local variables to nice initial values.
The updateParmsFlags() method only enables the default value parameter when one of the extend conditions uses the "default value" setting.
This method fetches the frame range of the CHOP, ensuring it is valid.
The Stair CHOP has interactive handles that are drawn in the CHOP viewer. All of these handles are interactive unless they have been overridden by a channel, in which case they merely become guides. This CHOP has two handles which adjust the start and end time of the clip, and a third handle which moves vertically to adjust the height of a stair.
This method creates the handles for the viewer to draw. Each handle is passed a unique ID so that the corresponding handleChanged()
can determine which handle was moved.
This method processes user interaction and sets parameters accordingly. The handle changed by the user is indicated by the handle
parameter, while the specifics of the change are pass in hdata
(including the X and Y position).
If the shift
flag is set, the node should show its parm dialog and the handle displays its current value in the viewport. Do not modify any values in this case.
Otherwise, the handle directly affects the parameter it affects using one of the OP_Parameter::setFloat() or setInt() methods.
This overridden virtual method allows generator CHOPs to be shifted by certain downstream CHOPs (such as the interpolate CHOP). The only thing that needs to be done is to modify the CHOP so that the start time is set to the new_offset
parameter.
This portion of the cook method sets up all the attributes of the clip - the frame range, sample rate, and tracks to create. Since this is a generator CHOP, all these values are derived from parameters, rather than inputs.
The next part of the cook method creates each track, assigns the extend conditions to it, and then fills in the data. Parameters are re-evaluated for each track, in case the local variable 'C' is used in an expression for one of the parameters (which corresponds to our my_C
data member).
Finally, the CHOP is registered. Since it is a generator, it has no inputs and it sets the OP_FLAG_GENERATOR flag.