Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

ofParameter linked/listening to another

$
0
0

@vollstock wrote:

In my app I would like to be able to linke values of arbitrary parameters.
For this I plan to change all of my member variables to ofParameter.

I understand, that I can add listener methods to them. Like this

myObject.h

[…]
ofParameter<unsigned char> myParameter;

unsigned char getMyParameter();
void setMyParameter(unsigned char value);
void setMyParameterFromListener(unsigned char & value);
[…]

and then add the function as a listener

test1 = new myObject();
test2 = new myObject();

test1->myParameter.addListener(test2, &myObject::setMyParameterFromListener);
test1->setValue(128);

ofLogNotice() << "test1: " << (int)test1->getValue();
ofLogNotice() << "test2: " << (int)test2->getValue();

// [notice ] test1: 128
// [notice ] test2: 128

This way, however I would need to add a method for each and every parameter in each and every class I write :worried:

Is there a direct way to link the value of two ofParameters (of the same type)?

Something like this would be perfect:

test1->myParameter.addListener(test3->myParameter, &ofParameter<unsigned char>::set);

Or even better

test1->myParameter.addListener(test3->myParameter)

Posts: 3

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4929

Latest Images

Trending Articles



Latest Images