How to update ITextControl with an int or double (Helpful for newbs)
Hello Everyone,
a few weeks ago i started with wdl-ol and struggled a while with simply updating an ITextControl. now i found a solution and i want to share it with you.
Scenario: You have an ItextControl and you want to update its value from an int variable. Our example: display of current Sampleposition
//===================================
//in PluginName.h you add your ITextControl* under public: (in our case //showSamplePos):
//===================================
class PluginName : public IPlug
{
public:
PluginName(IPlugInstanceInfo instanceInfo);
~PluginName();
ITextControl* showSamplePos;
//===============================
//in PluginName.cpp you add:
//===============================
int SamplePos = 0;
IText textProps2(18, &COLOR_WHITE, "Tahoma", IText::kStyleNormal, IText::kAlignCenter, 0, IText::kQualityDefault);
//tempRect values (left-edge, top-edge, right-edge, bottom-edge)
// our rectangle goes from 100px to 200px horizontally and from 30px to 50px vertically
IRECT tmpRect1(100, 30, 200, 50);
showSamplePos = new ITextControl(this, tmpRect1, &textProps2, "Sampleposition");
pGraphics->AttachControl(showSamplePos);
// shows you the borders of your GUI objects
pGraphics->ShowControlBounds(true);
//=====================================
//the following goes in your ProcessDoubleReplacing Function in PluginName.cpp
//=====================================
SamplePos = (int)GetSamplePos();
//ITextControl accepts only chars so doubles floats ints etc. need to be converted to char
std::string str1 = std::to_string(SamplePos);
char *charSamplePos = new char[str1.length() + 1];
strcpy(charSamplePos, str1.c_str());
//updating the ITextControl "showSamplePos" with the char "charSamplePos"
showSamplePos->SetTextFromPlug(charSamplePos);
//================================================== =
//From what i know Samplepos is only increasing, when your plugin runs in a host,
//because Samplepos is a host function - so when you test this, compile it to a
//plugin - not standalone - in order to see the "realtime" Sampleposition working.
Last edited by jan hase; 11-27-2017 at 08:24 PM.
Reason: problem solved
|