Hi,
So, in IParam.h I added:
Code:
public:
bool AttachedControl; //(flag to tell me if param has control attached, accessed via IParam->AttachedControl)
int GetAttachedControlIdx() { return mAttachedControlIdx; }
void SetAttachedControlIdx(int Idx);
private:
int mAttachedControlIdx;
And in IParam.cpp:
Code:
void IParam::SetAttachedControlIdx(int Idx)
{
mAttachedControlIdx = Idx;
}
fyi - I am attaching and detaching params to/from controls regularly to save on the amount of controls I am using.
Slightly differently to you, I am accessing the mAttachedControlIdx in Graphics.cpp in the SetParameterFromPlug method, which I have edited to:
Code:
void IGraphics::SetParameterFromPlug(int paramIdx, double value, bool normalized)
{
IParam* pParam = mPlug->GetParam(paramIdx);
if (!normalized)
{
value = pParam->GetNormalized(value);
}
bool passer = true;
if (pParam->AttachedControl && pParam->GetAttachedControlIdx() > -1) {
IControl* pControlTest = mControls.Get(pParam->GetAttachedControlIdx());
pControlTest->SetValueFromPlug(value);
passer = false;
}
if (passer) {
int i, n = mControls.GetSize();
IControl** ppControl = mControls.GetList();
for (i = 0; i < n; ++i, ++ppControl)
{
IControl* pControl = *ppControl;
if (pControl->ParamIdx() == paramIdx)
{
//WDL_MutexLock lock(&mMutex);
pControl->SetValueFromPlug(value);
// Could be more than one, don't break until we check them all.
break;
}
// now look for any auxilliary parameters
int auxParamIdx = pControl->AuxParamIdx(paramIdx);
if (auxParamIdx > -1) // there are aux params
{
pControl->SetAuxParamValueFromPlug(auxParamIdx, value);
}
}
}
}
Now, if my iparam is attached to a control using my method I can avoid iterating through all controls, in my case to save the iteration when playing back automation from Reaper to an attached control.
My c++ skills are self taught, so I may / may not be doing things in a sensible way, but it seems to work flawlessly so far!
Edit: Looking at the code above, I could do away with the param->AttachedControl flag and just set the mAttachedControlIdx to -1. I think I'll do that actually!