Skip to content
Merged
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
47 changes: 43 additions & 4 deletions Source/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ Object::Object(pd::WeakReference object, Canvas* parent)
initialise();

setType("", object);

if (auto obj = object.get<t_object>()) {
String objectName = obj.ptr->te_g.g_pd->c_name->s_name;
updateObjectActivityPolicy(objectName);
}
}

Object::~Object()
Expand All @@ -72,6 +77,28 @@ Object::~Object()
cnv->selectedComponents.removeChangeListener(this);
}

void Object::updateObjectActivityPolicy(String objectName)
{
switch(hash(objectName)){
case hash("r"):
case hash("receive"):
case hash("s"):
case hash("send"):
// Symbol objects trigger their own activity and recursively activate within GOPs
objectActivityPolicy = ObjectActivityPolicy::Recursive;
break;
case hash("inlet"):
case hash("outlet"):
// Iolets trigger activity of themselves and parent GOP only
objectActivityPolicy = ObjectActivityPolicy::Parent;
break;
default:
// All other objects trigger their own activity only
objectActivityPolicy = ObjectActivityPolicy::Self;
break;
}
}

Rectangle<int> Object::getObjectBounds()
{
return getBounds().reduced(margin) - cnv->canvasOrigin;
Expand Down Expand Up @@ -370,6 +397,8 @@ void Object::setType(String const& newType, pd::WeakReference existingObject)
// Change object type
String type = newType.upToFirstOccurrenceOf(" ", false, false);

updateObjectActivityPolicy(type);

pd::WeakReference objectPtr = nullptr;
// "exists" indicates that this object already exists in pd
// When setting exists to true, the gui needs to be assigned already
Expand Down Expand Up @@ -487,15 +516,25 @@ String Object::getType(bool withOriginPrefix) const
return String();
}

void Object::triggerOverlayActiveState()
void Object::triggerOverlayActiveState(bool recursive)
{
if (rateReducer.tooFast())
return;

// propagate the activity overlay upwards if object is inside GOP
if (auto parentObject = findParentComponentOfClass<Object>())
parentObject->triggerOverlayActiveState();
// If object was triggered by a recursive object, trigger all parent canvases activity
if (recursive) {
if (auto parentObject = findParentComponentOfClass<Object>())
parentObject->triggerOverlayActiveState(true);
}

// Check this objects activity policy type, if it's not self activity trigger,
// then trigger parent GOP if it has one, call with recursive argument if
// this object is set to recursive triggering (for symbol objects only)
else if (objectActivityPolicy != ObjectActivityPolicy::Self) {
if (auto parentObject = findParentComponentOfClass<Object>()) {
parentObject->triggerOverlayActiveState(objectActivityPolicy == ObjectActivityPolicy::Recursive);
}
}
if (!cnv->shouldShowObjectActivity())
return;

Expand Down
29 changes: 28 additions & 1 deletion Source/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Object : public Component

bool hitTest(int x, int y) override;

void triggerOverlayActiveState();
void triggerOverlayActiveState(bool recursive = false);

bool validResizeZone = false;

Expand Down Expand Up @@ -134,11 +134,38 @@ class Object : public Component

std::function<bool(int x, int y)> transparentHitTest = nullptr;

/**
* @enum ObjectActivityPolicy
* @brief Controls the way object activity propagates upwards inside GOPs.
*
* This enum defines the different ways in which an object's activity can propagate
* through its parent hierarchy. It specifies whether to limit the activity to the object
* itself, its direct parent, or all parents recursively.
*
* @var ObjectActivityPolicy::Self
* Trigger object's own activity only.
*
* @var ObjectActivityPolicy::Parent
* Trigger activity of object itself, and direct parent GOP only.
*
* @var ObjectActivityPolicy::Recursive
* Trigger activity of object itself, and all parent GOPs recursively.
*/
enum ObjectActivityPolicy {
Self,
Parent,
Recursive
};

ObjectActivityPolicy objectActivityPolicy = ObjectActivityPolicy::Self;

private:
void initialise();

void updateTooltips();

void updateObjectActivityPolicy(String objectName);

void openNewObjectEditor();

bool checkIfHvccCompatible() const;
Expand Down