openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.9k stars 2.55k forks source link

ofParameter feature discussion. #1391

Closed openframeworks closed 11 years ago

openframeworks commented 12 years ago

This is a feature discussion issue for what ofParameter and its utility clases should be. What you see below is Work In Progress!! - discussion and comments are especially welcome! I will edit and add pseudo code below as the structure of ofParameter and its utility classes gets more flushed out.

Once we are all agreed - this issue will become the reference page for the code development.

Goal: The idea is that ofParameter essentially can act like a variable within your app. Unlike a typical variable an ofParam has a name, a type and a range.

ofParameter will have several advantages when used in your app. They are:

Current State:

ToDo's

markpitchless commented 12 years ago

Thinking about meta data on the params like min and max for numbers. We could store this as a ParamGroup on the actual parameter. We then have an arbitrary store of named, typed meta data which other addons and your own app code can use.

ofxParameter<int> blur;
blur.meta.set<int>("min", 0);
blur.meta.set<int>("max", 50);

meta is the ParamGroup, set() auto-vivifies a param of the given type if that name does not exist or updates an existing param. Then GUI code etc can just get those values. blur.meta.get("min"). Different addons can doc the names and types of meta params they will use. We get nice extensibility without having to build a big hierarchy of Param classes. Works for the request for a different name to show in the GUI ie a "title" param that the GUI uses if set and falls back to name if not set. GUIs could look for "tooltips", "description" etc. XMLSettings could look for "xml_name", OSC for "osc_name".

ofTheo commented 11 years ago

@arturoc I just took a look at the latest in your branch and I think overall its a really good approach. I just barely understand all the craziness in the ofParameter classes :) but in terms of usage it behaves how I would hope/expect.

I think it would be really great to get this and ofxGui in the next release. It seems really close.

There were a few issues I ran into which I posted as a sep issue here: ( #1692 )

There are also some things which we could add at a later stage like an ofBaseHasParams and potentially a global param register for an app. ie: ofRegisterParameters.

But for now I think what is there is already really useful and could allow for a lot to be built off of it.

arturoc commented 11 years ago

haha, yes ofParameter is crazy, i still need to polish a couple of things and there's some others that i'm kind of dubious. mainly that for ofParameters of an object like ofParameter now you can do:

ofParameter p; p->x;

to access it's properties or methods but thats read only cause we need to make the parameter trigger the event whenever is changed, it works pretty much ok but it can be confusing sometimes when you try to change the values since the correct syntax is kind of weird:

p = ofVec3f(p->x+1,p->y)

instead of p->x++

but haven't found anyway you could detect you are writing to a property of an object from the object itself

ofTheo commented 11 years ago

ohh - I see. hmm could we just force people to use p.get() and p.set() ?

I feel like it could be fair to assume that if you access and modify the objects properties directly that it wouldn't trigger change events.

arturoc commented 11 years ago

even calling methods won't trigger any event since the object is encapsulated in ofParameter, we can overload the -> operator to return a reference to the internal object but once you have that reference you can't detect if it has changed anymore no matter if it's by calling the property directly or using a method, so it's kind of a tough one, most of the time probably we don't need to trigger events but it would be weird if you attach an event to a parameter and sometimes is not triggered

bilderbuchi commented 11 years ago

now that ofParameter has been merged, should we close this or just continue any emerging discussion in this issue?

arturoc commented 11 years ago

i think we can close this, if there are any problems or comments we can open new issues