COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 09-20-2016, 04:20 AM   #1
Nowhk
Human being with feelings
 
Join Date: Mar 2016
Posts: 234
Default How would you get control by paramIdx?

Let say I know (because I'm developing it) that some param are linked to one (and only one) control.

How would you get the control instance by paramIdx?

I see this on SetParameterFromPlug:

Code:
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.
	}
}
So I've created (editing the framework itself) this method within IGraphics.cpp:

Code:
IControl *IGraphics::GetControlByParamID(int paramIdx) {
	int n = mControls.GetSize();
	IControl** ppControl = mControls.GetList();

	for (int i = 0; i < n; i++, ++ppControl) {
		IControl *pControl = *ppControl;
		if (pControl->ParamIdx() == paramIdx) {
			return pControl;
			break;
		}
	}

	return NULL;
}
Is this the only way?

This because I need to quickly access to aux params having paramIdx...

Last edited by Nowhk; 09-20-2016 at 06:02 AM.
Nowhk is offline   Reply With Quote
Old 09-20-2016, 11:03 AM   #2
leighhunt
Human being with feelings
 
Join Date: Jun 2016
Location: London, UK
Posts: 51
Default

Hi there,
Funniily enough I am working on a plugin where I wanted to achieve the same goal...
I figured that mControls are written to sequentially when controls are attached.
To save iterating through the whole lot of mControls, you can call mControl.Get(Idx), so adding a variable to iParams (AttachedControl in my case) and calling a method to return it solved the problem for me.
It works a treat in my current project!
This is how the code ended up looking...

if (pParam->AttachedControl) {
IControl* pControlTest = mControls.Get(pParam->GetAttachedControlIdx());
pControlTest->SetValueFromPlug(value);
}

Hope this helps.
Leigh
leighhunt is offline   Reply With Quote
Old 09-21-2016, 12:06 AM   #3
Nowhk
Human being with feelings
 
Join Date: Mar 2016
Posts: 234
Default

Quote:
Originally Posted by leighhunt View Post
Hi there,
Funniily enough I am working on a plugin where I wanted to achieve the same goal...
I figured that mControls are written to sequentially when controls are attached.
To save iterating through the whole lot of mControls, you can call mControl.Get(Idx), so adding a variable to iParams (AttachedControl in my case) and calling a method to return it solved the problem for me.
It works a treat in my current project!
This is how the code ended up looking...

if (pParam->AttachedControl) {
IControl* pControlTest = mControls.Get(pParam->GetAttachedControlIdx());
pControlTest->SetValueFromPlug(value);
}

Hope this helps.
Leigh
Hi, thanks for the reply!
Basically, you added AttachedControl on IParam (which is controlIdx) and create method GetAttachedControlIdx() within IParam to return this controIdx, right?
So you have changed as well AttachControl method (which will add this AttachedControl control id value).

Also: since mControls is protected within IGraphics, where did you call IControl* pControlTest = mControls.Get(pParam->GetAttachedControlIdx());?
Nowhk is offline   Reply With Quote
Old 09-21-2016, 02:13 AM   #4
leighhunt
Human being with feelings
 
Join Date: Jun 2016
Location: London, UK
Posts: 51
Default

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!
leighhunt is offline   Reply With Quote
Old 09-21-2016, 02:27 AM   #5
Nowhk
Human being with feelings
 
Join Date: Mar 2016
Posts: 234
Default

Hi dude I still don't see when/where you call SetAttachedControlIdx (I guess after you create the control?).

Anyway, for what I'm doing, I think I'll stay with my own method, since it will edit framework code less. I just need to catch the instance of the control once, when I create a object. Thus, itering across mControls it's not so important.

Thanks for the helps anyway!
Nowhk is offline   Reply With Quote
Old 09-21-2016, 02:32 AM   #6
leighhunt
Human being with feelings
 
Join Date: Jun 2016
Location: London, UK
Posts: 51
Default

Sure thing!
fyi - I initialize SetAttached ControlIdx() in my main code when I create my IParams. Then call it when I want to attach a control. (Think along the lines of having, say 8 toggles, assigned dynamically to 8x8 IParams).
have fun!
leighhunt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.