Skip to content

Commit

Permalink
- added support for fix objects when using Math.from0to1 / Math.to0to1
Browse files Browse the repository at this point in the history
- added Math.skew()
- added Math.smoothstep()
  • Loading branch information
christoph-hart committed Dec 19, 2023
1 parent dd46ff4 commit 5d502a1
Show file tree
Hide file tree
Showing 5 changed files with 4,580 additions and 4,482 deletions.
18 changes: 18 additions & 0 deletions hi_scripting/scripting/api/FixLayoutObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ juce::uint32 LayoutBase::Helpers::getTypeSize(DataType type)
}
}

int LayoutBase::Helpers::createHash(MemoryLayoutItem::List list)
{
String s;

for(auto l: list)
{
s << l->id;
s << (uint8)l->type;
}

return s.hash();
}

LayoutBase::~LayoutBase()
{}

Expand Down Expand Up @@ -310,6 +323,8 @@ Factory::Factory(ProcessorWithScriptingContent* s, const var& d) :
addConstant("prototype", d);
layout = createLayout(allocator, d, &initResult);

typeHash = Helpers::createHash(layout);

compareFunction = BIND_MEMBER_FUNCTION_2(Factory::compare);
}

Expand Down Expand Up @@ -607,6 +622,7 @@ void ObjectReference::init(LayoutBase* referencedLayout, uint8* preallocatedData

layoutReference = referencedLayout;
layout = referencedLayout->layout;
typeHash = Helpers::createHash(layout);

jassert(allocator->validMemoryAccess(data));
jassert(allocator->validMemoryAccess(data + getElementSizeInBytes() - 1));
Expand Down Expand Up @@ -890,6 +906,8 @@ void Array::init(LayoutBase* parent)
elementSize = getElementSizeInBytes();
numAllocated = getElementSizeInBytes() * (numElements);

typeHash = Helpers::createHash(layout);

if (numAllocated > 0)
{
data = allocator->allocate((int)numAllocated);
Expand Down
9 changes: 9 additions & 0 deletions hi_scripting/scripting/api/FixLayoutObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct LayoutBase
static DataType getTypeFromVar(const var& value, Result* r);
static int getElementSizeFromVar(const var& value, Result* r);
static uint32 getTypeSize(DataType type);
static int createHash(MemoryLayoutItem::List list);
};

virtual ~LayoutBase();;
Expand All @@ -112,6 +113,8 @@ struct LayoutBase
Allocator::Ptr allocator;
MemoryLayoutItem::List layout;

int typeHash = 0;

protected:

LayoutBase();
Expand Down Expand Up @@ -450,6 +453,12 @@ struct Factory : public LayoutBase,
/** Registers a function that will be used for comparison. If you pass in a string it will only compare the given property. */
void setCompareFunction(var newCompareFunction);

/** Returns the hash code for the memory layout which factors in member IDs, order and type. */
int getTypeHash() const
{
return typeHash;
}

// ============================================================================================================

int compare(ObjectReference::Ptr v1, ObjectReference::Ptr v2);;
Expand Down
Loading

1 comment on commit 5d502a1

@aaronventure
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's HISEscript for the exponential curve / curved smoothstep, if you think that would be a good thing to include as well

	inline function exponentialCurve(min, max, midpoint, alpha) 
	{
	    local a = Math.log((max - min) / (midpoint - min));
    	    local b = Math.log(2);
    	    local exponent = a / b;
    	    return min + (max - min) * Math.pow(alpha, exponent);
	}
	
	inline function reverseExponentialCurve(min, max, midpoint, value)  
	{
	    local a = Math.log((max - min) / (midpoint - min));
	    local b = Math.log(2);
	    local exponent = a / b;
	    return Math.pow((value - min) / (max - min), 1 / exponent);
	}

Please sign in to comment.