From a0a0bea87fac72d462c200e5d7c315119fce8fab Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Sun, 10 Aug 2025 21:08:47 +0800 Subject: [PATCH] add: add set property functions --- app/pluginSupport/OlivePlugin.h | 219 ++++++++++++++++++++++++++++---- app/pluginSupport/Property.cpp | 128 ++++++++++++++++--- 2 files changed, 307 insertions(+), 40 deletions(-) diff --git a/app/pluginSupport/OlivePlugin.h b/app/pluginSupport/OlivePlugin.h index 1bcf587ea..1a3f7de6c 100644 --- a/app/pluginSupport/OlivePlugin.h +++ b/app/pluginSupport/OlivePlugin.h @@ -28,63 +28,230 @@ namespace olive { namespace plugin { +class Value; +enum class Type { + FLOAT, STRING, INT, POINTER, ARRAY, NONE +}; +class Array { +private: + Type type; + int strSize=0; + char** strings; + QVector pointers; + QVector ints; + QVector floats; +public: + Array() + { + type=Type::NONE; + } + Array(const int *data, size_t size) + { + this->type=Type::INT; + ints.reserve(size); + std::copy(data, data+size, ints.data()); + } + Array(const double *data, size_t size) + { + this->type=Type::FLOAT; + floats.reserve(size); + std::copy(data, data+size, floats.data()); + } + Array(void * const* data, size_t size) + { + this->type=Type::POINTER; + pointers.reserve(size); + std::copy(data, data+size, pointers.data()); + } + Array(const char * const *data, size_t size) + { + strings=(char**)malloc(sizeof(char *)*size); + for (int i=0;itype=Type::INT; + ints.clear(); + ints.reserve(size); + std::copy(data, data+size, ints.data()); + } + void setArray(double *data, size_t size) + { + this->type=Type::FLOAT; + floats.clear(); + floats.reserve(size); + std::copy(data, data+size, floats.data()); + } + void setArray(void *const*data, size_t size) + { + this->type=Type::POINTER; + pointers.reserve(size); + pointers.clear(); + std::copy(data, data+size, pointers.data()); + } + void setArray(const char * const *data, size_t size) + { + for (int i=0;istrSize;i++) { + free(strings[i]); + } + free(strings); + strings=nullptr; + strings=(char**)malloc(sizeof(char *)*size); + for (int i=0;iplugin) { - OfxStatus status= properties->plugin->getProp(property, index, val); - if (val.isInt()) { - value=calloc(1,sizeof(long)); - *(int64_t*)value=val.getInt(); - properties->plugin->addMem(value); + if (index<0) { + return kOfxStatErrBadIndex; } - else if (val.isFloat()) { - value=calloc(1,sizeof(double)); - *(double*)value=val.getFloat(); - properties->plugin->addMem(value); - } - else if (val.isString()) { - QString str=val.getString(); - value=(void *)calloc(str.size()+1, sizeof(char)); - memcpy(value, str.data(), str.size()); - properties->plugin->addMem(value); - } - return status; + properties->plugin->setProp(property, index, value); + return kOfxStatOK; } return kOfxStatErrBadHandle; +} -} \ No newline at end of file +OfxStatus propSetString(OfxPropertySetHandle properties, + const char *property, int index, const char *value) +{ + olive::plugin::Value val; + if (properties->plugin) { + if (index<0) { + return kOfxStatErrBadIndex; + } + properties->plugin->setProp(property, index, QString(value)); + return kOfxStatOK; + } + return kOfxStatErrBadHandle; +} + +OfxStatus propSetDouble(OfxPropertySetHandle properties, + const char *property, int index, double value) +{ + olive::plugin::Value val; + if (properties->plugin) { + if (index<0) { + return kOfxStatErrBadIndex; + } + properties->plugin->setProp(property, index, static_cast(value)); + return kOfxStatOK; + } + return kOfxStatErrBadHandle; +} + +OfxStatus propSetInt(OfxPropertySetHandle properties, const char *property, + int index, int value) +{ + olive::plugin::Value val; + if (properties->plugin) { + if (index<0) { + return kOfxStatErrBadIndex; + } + properties->plugin->setProp(property, index, value); + return kOfxStatOK; + } + return kOfxStatErrBadHandle; +} + +OfxStatus propSetPointerN(OfxPropertySetHandle properties, + const char *property, int index, int count, void * const*value) +{ + olive::plugin::Value val; + olive::plugin::Array array(value,count); + val.setValue(array); + if (properties->plugin) { + if (index<0) { + return kOfxStatErrBadIndex; + } + properties->plugin->setProp(property, index, val); + return kOfxStatOK; + } + return kOfxStatErrBadHandle; +} + +OfxStatus propSetStringN(OfxPropertySetHandle properties, + const char *property, int index, int count,const char *const *value) +{ + olive::plugin::Value val; + olive::plugin::Array array(value,count); + val.setValue(array); + if (properties->plugin) { + if (index<0) { + return kOfxStatErrBadIndex; + } + properties->plugin->setProp(property, index, val); + return kOfxStatOK; + } + return kOfxStatErrBadHandle; +} + +OfxStatus propSetDoubleN(OfxPropertySetHandle properties, + const char *property, int index, int count, const double* value) +{ + olive::plugin::Value val; + olive::plugin::Array array(value,count); + val.setValue(array); + if (properties->plugin) { + if (index<0) { + return kOfxStatErrBadIndex; + } + properties->plugin->setProp(property, index, val); + return kOfxStatOK; + } + return kOfxStatErrBadHandle; +} + +OfxStatus propSetIntN(OfxPropertySetHandle properties, const char *property, + int index, int count, const int *value) +{ + olive::plugin::Value val; + olive::plugin::Array array(value, count); + val.setValue(array); + if (properties->plugin) { + if (index<0) { + return kOfxStatErrBadIndex; + } + properties->plugin->setProp(property, index, val); + return kOfxStatOK; + } + return kOfxStatErrBadHandle; +}