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 01-19-2017, 06:01 PM   #1
David S
Human being with feelings
 
Join Date: Jan 2017
Posts: 11
Default IParameter Display for Multiple Controls

Hello all,
I am new to IPlug, C++, and programming in general. Thanks to the creators of WDL IPlug, to those who maintain the repositories, and to all of you on this forum who ask and answer questions.
I am currently working on a parameter display class that I wish to be capable of displaying the parameter name/value/label of the last touched control and to be able to also update the last touched control by user text input. So far, it correctly displays the correct information and updates the value of the last touched controls parameter, but the control itself does not graphically update until the target area of the parameter display is clicked again. This is because I am putting:
GetGUI()->SetParameterFromPlug(mParamIdx, Plug->GetParam(mParamIdx)->Value(), false);
in OnMouseDown after PromptUserInput(&mValueRECT); but I don't know where else to put it. What would be ideal (I think), would be if there was a function that would execute upon closing the text prompt by hitting enter or by clicking away from the target area of my Parameter display control.

The Class....
Code:
#pragma once

//***************************************************************************************

// A multibitmap knob with a OnMouseDown function just to let a display control know that it's been clicked
class IKnobMultiControl2 : public IKnobControl
{
public:
    IKnobMultiControl2(IPlugBase* pPlug, int x, int y, int paramIdx, IBitmap* pBitmap,
        EDirection direction = kVertical, double gearing = DEFAULT_GEARING)
        : IKnobControl(pPlug, IRECT(x, y, pBitmap), paramIdx, direction, gearing), mBitmap(*pBitmap) {}
    ~IKnobMultiControl2() {}

    bool Draw(IGraphics* pGraphics)
    {
        int i = 1 + int(0.5 + mValue * (double)(mBitmap.N - 1));
        i = BOUNDED(i, 1, mBitmap.N);
        return pGraphics->DrawBitmap(&mBitmap, &mRECT, i, &mBlend);
    }

    void OnMouseDown(int x, int y, IMouseMod* pMod)
    {
        SetDirty();
    }

private:
    IBitmap mBitmap;
};

//***************************************************************************************

class IParameterDisplay : public IControl
{
private:
    IRECT mNameRECT, mValueRECT;
    int mXover, mHeight, mLength;

public:
    IParameterDisplay(IPlugBase* pPlug, int x, int y, int fontsize, IText* pText)
        : IControl(pPlug, IRECT())
    {
        mText = *pText;
        mParamIdx = 0;
        mHeight = fontsize + 2;
        mLength = mHeight * 10;
        mRECT = IRECT(x, y, x + mLength, y + mHeight);
        mXover = int((mRECT.R - mRECT.L) * 0.56);
        mNameRECT = IRECT(mRECT.L, mRECT.T, mRECT.L + mXover, mRECT.B);
        mValueRECT = IRECT(mRECT.L + mXover, mRECT.T, mRECT.R, mRECT.B);
        mTargetRECT = mValueRECT;
        mDisablePrompt = false;
    }

    ~IParameterDisplay() {}

    bool Draw(IGraphics* pGraphics)
    {
        pGraphics->FillIRect(&COLOR_WHITE, &mNameRECT);
        pGraphics->FillIRect(&COLOR_YELLOW, &mValueRECT);
        char name[30];
        strcpy(name, mPlug->GetParam(mParamIdx)->GetNameForHost());
        char value[30];
        mPlug->GetParam(mParamIdx)->GetDisplayForHost(value);
        strcat(value, " ");
        strcat(value, mPlug->GetParam(mParamIdx)->GetLabelForHost());
        pGraphics->DrawIText(&mText, name, &mNameRECT);

        if (CSTR_NOT_EMPTY(value))
        {
            return pGraphics->DrawIText(&mText, value, &mValueRECT);
        }
        return true;
    }

    void SetParameter(int ParamIdx)
    {
        mParamIdx = ParamIdx;
    }

    void OnMouseDown(int x, int y, IMouseMod* pMod)
    {
        if (mValueRECT.Contains(x, y))
        {
            PromptUserInput(&mValueRECT);
            GetGUI()->SetParameterFromPlug(mParamIdx, mPlug->GetParam(mParamIdx)->Value(), false);
        }
    }

    bool IsDirty() { return true; }
};
//**************************************************************
In the private section of myplug.h
Code:
IParameterDisplay* ParamDisplay;
in the constructor of myplug.cpp
Code:
IText textProps(14, &COLOR_BLACK, "Tahoma", IText::kStyleNormal, IText::kAlignFar, 0, IText::kQualityDefault);
  ParamDisplay = new IParameterDisplay(this, 90, 200, 14, &textProps);//90, 200, 290, 220
  pGraphics->AttachControl(ParamDisplay);
and ParamDisplay->SetParameter(paramIdx) in OnParamChange like this....
Code:
void delaytest::OnParamChange(int paramIdx)
{
  IMutexLock lock(this);
  
  switch (paramIdx)
  {
    case kGain:
      mGain = GetParam(kGain)->Value() / 100.;
      break;
    case kDelayIn:
        mDelayIn = GetParam(kDelayIn)->Value();
        del_L.SetInputLevel(mDelayIn);
        del_R.SetInputLevel(mDelayIn);
        break;
    case kDelayTm_L:
        mDelayTm_L = GetParam(kDelayTm_L)->Value();
        del_L.SetDelayTime(mDelayTm_L);
        break;
    case kDelayTm_R:
        mDelayTm_R = GetParam(kDelayTm_R)->Value();
        del_R.SetDelayTime(mDelayTm_R);
        break;
    case kDelayFdbk_L:
        mDelayFdbk_L = GetParam(kDelayFdbk_L)->Value();
        del_L.SetFeedback(mDelayFdbk_L);
        break;
    case kDelayFdbk_R:
        mDelayFdbk_R = GetParam(kDelayFdbk_R)->Value();
        del_R.SetFeedback(mDelayFdbk_R);
        break;
    default:
      break;
  }
  ParamDisplay->SetParameter(paramIdx);
}
Any help with this would be greatly appreciated....... thanks!
David S is offline   Reply With Quote
Old 01-21-2017, 10:57 PM   #2
David S
Human being with feelings
 
Join Date: Jan 2017
Posts: 11
Default Found a Solution

OK .................. I've got it working.
This may not be the best (or correct) way to do this, but it works on VST 2 and VST 3 builds (Win32) using savihost. I have not tested this control in any DAW yet. It would seem after some reading in IControl.h/.cpp , if you want to set a value from user input, a good place to start just might be...... IControl::SetValueFromUserInput(double value)....

The code pasted below is the modified/functional class. It probably could still use some tweaking. In my first post, I included a slightly modified IKnobMultiControl to use with IParameterDisplay that allows the display to be updated when the knob is just clicked rather than only after its value has been changed by a mouse drag. I imagine that if you would wish to have the same behavior from another control, you would need to add or modify an existing OnMouseDown function with SetDirty();


Code:
class IParameterDisplay : public IControl
{
private:
    IRECT mNameRECT, mValueRECT;
    int mXover, mHeight, mLength;

public:
    IParameterDisplay(IPlugBase* pPlug, int x, int y, int fontsize, IText* pText)
        : IControl(pPlug, IRECT())
    {
        mText = *pText;
        mParamIdx = 0;
        mHeight = fontsize + 2;
        mLength = mHeight * 10;
        mRECT = IRECT(x, y, x + mLength, y + mHeight);
        mXover = int((mRECT.R - mRECT.L) * 0.56);
        mNameRECT = IRECT(mRECT.L, mRECT.T, mRECT.L + mXover, mRECT.B);
        mValueRECT = IRECT(mRECT.L + mXover, mRECT.T, mRECT.R, mRECT.B);
        mTargetRECT = mValueRECT;
        mDisablePrompt = false;
    }

    ~IParameterDisplay() {}

    bool Draw(IGraphics* pGraphics)
    {
        //pGraphics->FillIRect(&COLOR_WHITE, &mNameRECT);
        //pGraphics->FillIRect(&COLOR_YELLOW, &mValueRECT);
        char name[30];
        strcpy(name, mPlug->GetParam(mParamIdx)->GetNameForHost());
        char value[30];
        mPlug->GetParam(mParamIdx)->GetDisplayForHost(value);
        strcat(value, " ");
        strcat(value, mPlug->GetParam(mParamIdx)->GetLabelForHost());
        pGraphics->DrawIText(&mText, name, &mNameRECT);

        if (CSTR_NOT_EMPTY(value))
        {
            return pGraphics->DrawIText(&mText, value, &mValueRECT);
        }
        return true;
    }

    void SetParameter(int ParamIdx)
    {
        mParamIdx = ParamIdx;
    }

    void OnMouseDown(int x, int y, IMouseMod* pMod)
    {
        if (mValueRECT.Contains(x, y))
        {
            PromptUserInput(&mValueRECT);
            GetGUI()->SetParameterFromPlug(mParamIdx, mPlug->GetParam(mParamIdx)->Value(), false);
        }
    }

    void SetValueFromUserInput(double value)
    {
        if (mValue != value)
        {
            mValue = value;
            GetGUI()->SetParameterFromPlug(mParamIdx, mValue, true);
            SetDirty();
            Redraw();
        }
    }

    bool IsDirty() { return true; }
};
David S 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:32 PM.


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