PDA

View Full Version : Itextcontrol only takes strings?


junioreq
07-19-2010, 01:44 AM
Must be a way of getting around this, I think I did it once but forgot. I need to do some math/conversion on a number before I send it to output for the user to see, obviously a caption control cant do that...

How the heck do I use itext without having it be a string?

Obviously this won't work ;)

pGraphics->AttachControl(new ITextControl(this, &IRECT(10, 100, 10 + 128, 100 + 32), &lFont2, 6*6));

~Rob.

olilarkin
07-19-2010, 03:26 AM
sprintf

http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

junioreq
07-19-2010, 08:19 AM
Thank you, damn, I've never used that, I always ASSUMED it was to print out to the screen like cout.

~Rob.

junioreq
07-19-2010, 09:15 AM
ok, I did this:

double x = 1.f/kratio;
char buf[50];

sprintf(buf, "%f", x);

IText lFont2(28, &COLOR_BLUE, "Courier");

pGraphics->AttachControl(new ITextControl(this, &IRECT(10, 100, 10 + 128, 100 + 32), &lFont2,buf ));


That works. But does not update when the control is moved. so do I have to do soemthing like this?

double x = 1.f/kratio;
char buf[50];

sprintf(buf, "%f", x);

IText lFont2(28, &COLOR_BLUE, "Courier");

ratioreadout = pGraphics->AttachControl(new ITextControl(this, &IRECT(10, 100, 10 + 128, 100 + 32), &lFont2,buf ));


and then at the bottom do something like:

GetGUI()->SetControlFromPlug(ratioreadout, buf); ?

I tried that and got:

.\Citer.cpp(355) : error C2664: 'IGraphics::SetControlFromPlug' : cannot convert parameter 2 from 'char [50]' to 'double'

olilarkin
07-19-2010, 09:22 AM
>But does not update when the control is moved.

This is a slight flaw in the way the iPlug text controls work. see CC's posts on this subject - he created the notion of an "observer" that updates when the user changes a control. personally I have made a knob control that includes a built-in text readout.

oli

junioreq
07-19-2010, 09:26 AM
oh ouch! Yeah, i lack the brain power to use that observer stuff right now lol, damn, I think I'll just put the readouts on the control :)

Thank you....

bvesco
07-20-2010, 12:49 AM
Check the method sigs, the error is right in the text you pasted:

setcontrolfromplug expects a double, not a string
settext expects a string

junioreq
07-21-2010, 06:20 PM
Damn... :( I even tried making a dummy control and putting a caption linked to that control, the control moves but no caption update :(

cc_
07-22-2010, 01:39 AM
It's not that hard to do this with my observer stuff:
http://forum.cockos.com/showthread.php?t=52820
Take a look at the modified IPlugExample in the zip file. There is a display for the pan control, it's only 20 or 30 lines of code.

junioreq
07-22-2010, 11:15 AM
Well, guess I should try. A lot of that stuff, I just can't comprehend what its doing. Don't know, there's just a stumbling block or something. I've come to a standstill with learning new stuff in c++. But again, a lot of it is me not being able to comprehend and nail the logic down. And without the logic, you don't have anything. But maybe I'll spend the day and try out this observer. I know it is very useful for some other things that I want to do, like the increment switches..

EDIT: After messing around for an hour, I can't figure it out, not sure what p is, value, where it gets the values from control lol, that thing is wicked hard to understand. Project scrapped.

Also if you reset a conrtrol using :GetGUI()->SetControlFromPlug(update1, 0.2); it wont update the caption control thats hooked to that control :(

I can't believe its so hard to add the value from control1 + control2 and show it in a damn text box or caption control ughhh...frustrated. - but again, lol if i had to code iplug umm.. there wouldn't be an iplug lol so i guess i can't complain right? lol.

~Rob.

junioreq
07-22-2010, 06:40 PM
Just tried to update my dummy:

GetGUI()->SetParameterFromGUI(kdummy,gain1);

lets say gain1 = 1.00044

Wont take it, only takes normalized values!!! ughhh

Any way to update my control with the value?

got a caption control now, but can't shoot it the values I need to..

~Rob.

junioreq
07-23-2010, 03:27 AM
New idea. Have a set of 6 controls that are images of numbers (number strip as normal). Break up the variable into an array. Let's say gain 1 = 5432

So then I can update each image with its corresponding number:

GetGUI()->SetControlFromPlug(dummycntrl,numArray[0]); which would be 5
GetGUI()->SetControlFromPlug(dummycntrl,numArray[1]); which would be 4
GetGUI()->SetControlFromPlug(dummycntrl,numArray[2]); which would be 3

etc...

That would work, for making a cool odometer style display. But the only way to get that number into an array is by looping. Not sure that would be so efficient to do? Is there maybe a more efficient way to get the gain variable broken up into variables?

~Rob.

cerberus
07-23-2010, 05:05 AM
i hope you solve this, junioreq... i am trying to get a calculated value to display (like a meter) but the only text display option seems to be icaption control, and we can't perform mathematical
operations on it...

bvesco
07-23-2010, 11:00 AM
Check the method sigs, the error is right in the text you pasted:

setcontrolfromplug expects a double, not a string
settext expects a string

I repeat (in caps this time since you missed the last time), YOU'RE USING THE WRONG METHOD. The method you're using is not the right one. Use the method that is the right one. You want to set a text value so use SetText. The method you are trying to use is only for internal control values. The VST spec says all param values are normalized in [0.0, 1.0] and nothing else is permitted. You are using the wrong method. Do not use a method for setting normalized param values to set human readable, non-normalized values. It is the wrong method. Use the other method, or use the normalized value and use the built in IPlug param system to convert it to the human readable value. Do not use the method you are trying to use. Look at the other method sigs and use the one for SetText that takes the string you are trying to display. Please do not continue ignoring my post, it is the answer. I do this in my plugs all the time. This problem is no harder to solve than using the proper control with the proper method on it.

junioreq
07-23-2010, 01:05 PM
Damn, I got schooled. I misunderstood your post.

resultreadout = "nascar1";
ITextControl *pTextControl=new ITextControl((this, &IRECT(10, 100, 10 + 128, 100 + 32), &lFont2,restreadout));
pGraphics->AttachControl(pTextControl);

pTextControl->SetTextFromPlug(blah);

So its gotta go like that I suppose.. or close to that. I was under the impression that the only functions to do that were with the getgui..

~Rob.

Thanks again...

junioreq
07-24-2010, 02:34 AM
pTextControl->SetTextFromPlug(blah);

Wont work unless its right under the text control though.. aka not in the onparam change area where i need it.

bvesco
07-24-2010, 12:51 PM
Well, school is for learning things and that's what this place is for, so it's all good.

SetTextFromPlug(blah); will work from anywhere, not just under the control. Like all functions, it can only be called with a handle to the object, either pointer, reference, or instance. Get one of those on the control you are trying to set text on.