Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 54 additions & 34 deletions libs/openFrameworks/types/ofParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,50 +106,70 @@ ofParameter<void>& ofParameter<void>::set(const std::string & name){
}

void ofParameter<void>::trigger(){
ofNotifyEvent(obj->changedE,this);
// Notify all parents, if there are any.
if(!obj->parents.empty())
// If the object is notifying its parents, just set the value without triggering an event.
if(!obj->bInNotify)
{
// Erase each invalid parent
obj->parents.erase(std::remove_if(obj->parents.begin(),
obj->parents.end(),
[](const std::weak_ptr<ofParameterGroup::Value> & p){ return p.expired(); }),
obj->parents.end());

// notify all leftover (valid) parents of this object's changed value.
// this can't happen in the same iterator as above, because a notified listener
// might perform similar cleanups that would corrupt our iterator
// (which appens for example if the listener calls getFirstParent on us)
for(auto & parent: obj->parents){
auto p = parent.lock();
if(p){
p->notifyParameterChanged(*this);
// Mark the object as in its notification loop.
obj->bInNotify = true;

// Notify any local subscribers.
ofNotifyEvent(obj->changedE, this);

// Notify all parents, if there are any.
if(!obj->parents.empty())
{
// Erase each invalid parent
obj->parents.erase(std::remove_if(obj->parents.begin(),
obj->parents.end(),
[this](const std::weak_ptr<ofParameterGroup::Value> & p){ return p.expired(); }),
obj->parents.end());

// notify all leftover (valid) parents of this object's changed value.
// this can't happen in the same iterator as above, because a notified listener
// might perform similar cleanups that would corrupt our iterator
// (which appens for example if the listener calls getFirstParent on us)
for(auto & parent: obj->parents){
auto p = parent.lock();
if(p){
p->notifyParameterChanged(*this);
}
}
}
obj->bInNotify = false;
}
}

void ofParameter<void>::trigger(const void * sender){
ofNotifyEvent(obj->changedE,sender);
// Notify all parents, if there are any.
if(!obj->parents.empty())
// If the object is notifying its parents, Do not trigger the event.
if(!obj->bInNotify)
{
// Erase each invalid parent
obj->parents.erase(std::remove_if(obj->parents.begin(),
obj->parents.end(),
[](const std::weak_ptr<ofParameterGroup::Value> & p){ return p.expired(); }),
obj->parents.end());

// notify all leftover (valid) parents of this object's changed value.
// this can't happen in the same iterator as above, because a notified listener
// might perform similar cleanups that would corrupt our iterator
// (which appens for example if the listener calls getFirstParent on us)
for(auto & parent: obj->parents){
auto p = parent.lock();
if(p){
p->notifyParameterChanged(*this);
// Mark the object as in its notification loop.
obj->bInNotify = true;

// Notify any local subscribers.
ofNotifyEvent(obj->changedE, this);

// Notify all parents, if there are any.
if(!obj->parents.empty())
{
// Erase each invalid parent
obj->parents.erase(std::remove_if(obj->parents.begin(),
obj->parents.end(),
[this](const std::weak_ptr<ofParameterGroup::Value> & p){ return p.expired(); }),
obj->parents.end());

// notify all leftover (valid) parents of this object's changed value.
// this can't happen in the same iterator as above, because a notified listener
// might perform similar cleanups that would corrupt our iterator
// (which appens for example if the listener calls getFirstParent on us)
for(auto & parent: obj->parents){
auto p = parent.lock();
if(p){
p->notifyParameterChanged(*this);
}
}
}
obj->bInNotify = false;
}
}

Expand Down
5 changes: 4 additions & 1 deletion libs/openFrameworks/types/ofParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1054,14 +1054,17 @@ class ofParameter<void>: public ofAbstractParameter{
class Value{
public:
Value()
:serializable(false){}
:bInNotify(false)
,serializable(false){}

Value(std::string name)
:name(name)
,bInNotify(false)
,serializable(false){}

std::string name;
ofEvent<void> changedE;
bool bInNotify;
bool serializable;
std::vector<std::weak_ptr<ofParameterGroup::Value>> parents;
};
Expand Down