If you have parameter data stored in the original parameter block format and want to upgrade to IParamBlock2 you can use the ParamBlock2PLCB
class (Parameter block 2 post-load call-back). An instance of this class is passed to ILoad::RegisterPostLoadCallback()
to enable automatic conversion of old-parameter block versions of the plug-in. Developers give the constructor for this class a ParamVersionDesc
array and the current block descriptor and it will load old parameter block objects into ParamBlock2 objects.
To take advantage of this system the original ParamBlockDesc
is used but now using the newly created parameter Ids. For example:
enum { bend_params,};
// The order here must be the same as the order in the older version PB
enum { bend_angle,
bend_dir,
bend_axis,
bend_fromto,
bend_from,
bend_to,
};
// The old ParamBlockDescID has been updated to use the IDs created in the ENUM
static ParamBlockDescID descVer0[] = {
{ TYPE_FLOAT, NULL, TRUE, bend_angle },
{ TYPE_FLOAT, NULL, TRUE, bend_dir },
{ TYPE_INT, NULL, FALSE, bend_axis } };
// The current version
static ParamBlockDescID descVer1[] = {
{ TYPE_FLOAT, NULL, TRUE, bend_angle },
{ TYPE_FLOAT, NULL, TRUE, bend_dir },
{ TYPE_INT, NULL, FALSE, bend_axis },
{ TYPE_INT, NULL, FALSE, bend_fromto },
{ TYPE_FLOAT, NULL, TRUE, bend_from },
{ TYPE_FLOAT, NULL, TRUE, bend_to } };
#define PBLOCK_LENGTH 6
#define NUM_OLDVERSIONS 2
// Array of old versions
static ParamVersionDesc versions[] = {
ParamVersionDesc(descVer0,3,0),
ParamVersionDesc(descVer1,PBLOCK_LENGTH,1)
};
In the BendMod::Load()
method a callback is registered which maps the incoming IDs to new enumerated IDs. It is important to note that old parameter maps still need to be loaded using the original mapping techniques before the new parameter block ids are used.
IOResult BendMod::Load(ILoad *iload)
{
Modifier::Load(iload);
ParamBlock2PLCB* plcb = new ParamBlock2PLCB(versions, NUM_OLDVERSIONS, &bend_param_blk, this, SIMPMOD_PBLOCKREF);
iload->RegisterPostLoadCallback(plcb);
return IO_OK;
}