Skip to content

Commit

Permalink
- added FixObjectArray.fromBase64(), toBase64()
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Jan 31, 2024
1 parent 93c450f commit eab7b75
Show file tree
Hide file tree
Showing 5 changed files with 4,641 additions and 4,598 deletions.
8 changes: 4 additions & 4 deletions hi_core/hi_components/floating_layout/BackendPanelTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ struct AudioTimelineObject : public TimelineObjectBase

if (sampleRate != reader->sampleRate)
{
LagrangeInterpolator interpolator;
LagrangeInterpolator interpolators[2];
auto ratio = sampleRate / reader->sampleRate;

AudioSampleBuffer newBuffer(2, reader->lengthInSamples * ratio);

interpolator.process(ratio, content.getReadPointer(0), newBuffer.getWritePointer(0), newBuffer.getNumSamples());
interpolator.process(ratio, content.getReadPointer(1), newBuffer.getWritePointer(1), newBuffer.getNumSamples());
interpolators[0].process(1.0 / ratio, content.getReadPointer(0), newBuffer.getWritePointer(0), newBuffer.getNumSamples());
interpolators[1].process(1.0 / ratio, content.getReadPointer(1), newBuffer.getWritePointer(1), newBuffer.getNumSamples());

std::swap(content, newBuffer);
}
Expand Down
26 changes: 24 additions & 2 deletions hi_scripting/scripting/api/FixLayoutObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,8 @@ struct Array::Wrapper
API_METHOD_WRAPPER_2(Array, copy);
API_VOID_METHOD_WRAPPER_0(Array, sort);
API_METHOD_WRAPPER_0(Array, size);
API_METHOD_WRAPPER_0(Array, toBase64);
API_METHOD_WRAPPER_1(Array, fromBase64);
};

Array::Array(ProcessorWithScriptingContent* s, int numElements):
Expand All @@ -841,6 +843,8 @@ Array::Array(ProcessorWithScriptingContent* s, int numElements):
ADD_API_METHOD_2(copy);
ADD_API_METHOD_0(size);
ADD_API_METHOD_0(sort);
ADD_API_METHOD_0(toBase64);
ADD_API_METHOD_1(fromBase64);
}

void Array::assign(const int index, var newValue)
Expand Down Expand Up @@ -987,8 +991,6 @@ bool Array::copy(String propertyName, var target)

auto ptr = data + offset;



if (auto b = target.getBuffer())
{
if (numElements != b->size)
Expand Down Expand Up @@ -1020,6 +1022,26 @@ bool Array::copy(String propertyName, var target)
return false;
}

String Array::toBase64() const
{
MemoryBlock mb(data, numAllocated);
return mb.toBase64Encoding();
}

bool Array::fromBase64(const String& b64)
{
MemoryBlock mb;
mb.fromBase64Encoding(b64);

if(mb.getSize() == numAllocated)
{
memcpy(data, mb.getData(), numAllocated);
return true;
}

return false;
}

int Array::size() const
{
return (int)numElements;
Expand Down
6 changes: 6 additions & 0 deletions hi_scripting/scripting/api/FixLayoutObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ struct Array : public LayoutBase,
/** Copies the property from each element into a buffer (or array). */
bool copy(String propertyName, var target);

/** Exports the memory region of the entire array as Base64 encoded string. */
String toBase64() const;

/** Restores an array from a previously exported state. */
bool fromBase64(const String& b64);

/** Returns the size of the array. */
virtual int size() const;

Expand Down

0 comments on commit eab7b75

Please sign in to comment.