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 11-17-2017, 12:28 PM   #1
jan hase
Human being with feelings
 
Join Date: Jul 2017
Posts: 25
Default 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
jan hase 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 01:18 AM.


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