add: add OfxPropertySuite

This commit is contained in:
Mike Solar
2025-08-15 13:36:05 +08:00
parent a0a0bea87f
commit 7ff76427f9
3 changed files with 320 additions and 302 deletions
+181 -9
View File
@@ -24,20 +24,192 @@ olive::plugin::OlivePlugin::~OlivePlugin()
free(p); free(p);
} }
} }
void olive::plugin::OlivePlugin::setProp(QString key, int index, Value val) OfxStatus olive::plugin::OlivePlugin::getProp(QString key, int index,
char **str)
{ {
props[key][index]=std::move(val); *str=nullptr;
} if (stringProps.contains(key)) {
if (stringProps[key].count()>index) {
OfxStatus olive::plugin::OlivePlugin::getProp(QString key, int index, Value &val) *str=stringProps[key][index];
{
if (props.contains(key)) {
if (props[key].contains(index)) {
val = props[key][index];
return kOfxStatOK; return kOfxStatOK;
} }
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
return kOfxStatErrUnknown; return kOfxStatErrUnknown;
} }
OfxStatus olive::plugin::OlivePlugin::getPropN(QString key,
char ***str)
{
*str=nullptr;
if (stringProps.contains(key)) {
*str=stringProps[key].data();
return kOfxStatOK;
}
return kOfxStatErrUnknown;
}
OfxStatus olive::plugin::OlivePlugin::getProp(QString key, int index,
void **str)
{
*str=nullptr;
if (pointerProps.contains(key)) {
if (pointerProps[key].count()>index) {
*str=pointerProps[key][index];
return kOfxStatOK;
}
return kOfxStatErrBadIndex;
}
return kOfxStatErrUnknown;
}
OfxStatus olive::plugin::OlivePlugin::getPropN(QString key,
void ***p)
{
*p=nullptr;
if (pointerProps.contains(key)) {
*p=pointerProps[key].data();
return kOfxStatOK;
}
return kOfxStatErrUnknown;
}
OfxStatus olive::plugin::OlivePlugin::getProp(QString key, int index,
int* p)
{
*p=0;
if (intProps.contains(key)) {
if (intProps[key].count()>index) {
*p=intProps[key][index];
return kOfxStatOK;
}
return kOfxStatErrBadIndex;
}
return kOfxStatErrUnknown;
}
OfxStatus olive::plugin::OlivePlugin::getPropN(QString key,
int **p)
{
*p=nullptr;
if (intProps.contains(key)) {
*p=intProps[key].data();
return kOfxStatOK;
}
return kOfxStatErrUnknown;
}
OfxStatus olive::plugin::OlivePlugin::getProp(QString key, int index,
double* p)
{
*p=0;
if (doubleProps.contains(key)) {
if (doubleProps[key].count()>index) {
*p=doubleProps[key][index];
return kOfxStatOK;
}
return kOfxStatErrBadIndex;
}
return kOfxStatErrUnknown;
}
OfxStatus olive::plugin::OlivePlugin::getPropN(QString key,
double **p)
{
*p=nullptr;
if (doubleProps.contains(key)) {
*p=doubleProps[key].data();
return kOfxStatOK;
}
return kOfxStatErrUnknown;
}
OfxStatus olive::plugin::OlivePlugin::setProp(QString key, int index, char *str)
{
char *p=(char*)calloc(strlen(str)+1,sizeof(char));
strcpy(p,str);
if (stringProps.contains(key)) {
if (stringProps[key].count()>index) {
stringProps[key].insert(index, p);
return kOfxStatOK;
}
stringProps[key].emplace_back(p);
return kOfxStatOK;
}
QVector<char *> vec;
vec.emplace_back(str);
stringProps[key]=vec;
return kOfxStatOK;
}
OfxStatus olive::plugin::OlivePlugin::setPropN(QString key, int count, char **strs)
{
QVector<char *> vector;
for (int i=0;i<count;i++) {
char *p=(char*)calloc(strlen(strs[i])+1,sizeof(char));
strcpy(p,strs[i]);
vector.emplace_back(p);
}
stringProps[key]=vector;
}
OfxStatus olive::plugin::OlivePlugin::setProp(QString key, int index, void *p)
{
if (pointerProps.contains(key)) {
if (pointerProps[key].count()>index) {
pointerProps[key].insert(index, p);
return kOfxStatOK;
}
pointerProps[key].emplace_back(p);
return kOfxStatOK;
}
QVector<void *> vec;
vec.emplace_back(p);
pointerProps[key]=vec;
return kOfxStatOK;
}
OfxStatus olive::plugin::OlivePlugin::setPropN(QString key,int count, void **ps)
{
QVector<void *> vector;
vector.reserve(count);
memcpy(vector.data(), ps, sizeof(void *)*count);
pointerProps[key]=vector;
return kOfxStatOK;
}
OfxStatus olive::plugin::OlivePlugin::setProp(QString key, int index, int p)
{
if (intProps.contains(key)) {
if (intProps[key].count()>index) {
intProps[key].insert(index, p);
return kOfxStatOK;
}
intProps[key].emplace_back(p);
return kOfxStatOK;
}
QVector<int> vec;
vec.emplace_back(p);
intProps[key]=vec;
return kOfxStatOK;
}
OfxStatus olive::plugin::OlivePlugin::setPropN(QString key,int count, int *ps)
{
QVector<int> vector;
vector.reserve(count);
memcpy(vector.data(), ps, sizeof(int)*count);
intProps[key]=vector;
return kOfxStatOK;
}
OfxStatus olive::plugin::OlivePlugin::setProp(QString key, int index, double p)
{
if (doubleProps.contains(key)) {
if (doubleProps[key].count()>index) {
doubleProps[key].insert(index, p);
return kOfxStatOK;
}
doubleProps[key].emplace_back(p);
return kOfxStatOK;
}
QVector<double> vec;
vec.emplace_back(p);
doubleProps[key]=vec;
return kOfxStatOK;
}
OfxStatus olive::plugin::OlivePlugin::setPropN(QString key,int count, double *ps)
{
QVector<double> vector;
vector.reserve(count);
memcpy(vector.data(), ps, sizeof(doubleProps)*count);
doubleProps[key]=vector;
return kOfxStatOK;
}
+24 -255
View File
@@ -18,12 +18,15 @@
#ifndef OLIVE_PLUGIN_H #ifndef OLIVE_PLUGIN_H
#define OLIVE_PLUGIN_H #define OLIVE_PLUGIN_H
#include "OlivePlugin.h"
#include "ofxCore.h" #include "ofxCore.h"
#include <QVariant>
#include <cstdint> #include <cstdint>
#include <QString> #include <QString>
#include <QMap> #include <QMap>
#include <any>
#include <list> #include <list>
#include <OpenImageIO/detail/fmt/chrono.h>
namespace olive namespace olive
{ {
namespace plugin namespace plugin
@@ -32,257 +35,6 @@ class Value;
enum class Type { enum class Type {
FLOAT, STRING, INT, POINTER, ARRAY, NONE FLOAT, STRING, INT, POINTER, ARRAY, NONE
}; };
class Array {
private:
Type type;
int strSize=0;
char** strings;
QVector<void *> pointers;
QVector<int> ints;
QVector<double> 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;i<size;i++) {
int len=strlen(data[i]);
strings[i]=(char*)malloc(sizeof(char)*len);
strncpy(strings[i], data[i], len);
}
strSize=size;
}
void setArray(int *data, size_t size)
{
this->type=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;i<this->strSize;i++) {
free(strings[i]);
}
free(strings);
strings=nullptr;
strings=(char**)malloc(sizeof(char *)*size);
for (int i=0;i<size;i++) {
int len=strlen(data[i]);
strings[i]=(char*)malloc(sizeof(char)*len);
strncpy(strings[i], data[i], len);
}
strSize=size;
}
int size()
{
switch (type) {
case Type::INT: {
return ints.size();
}
case Type::FLOAT: {
return floats.size();
}
case Type::POINTER: {
return pointers.size();
}
case Type::STRING: {
return strSize;
}
}
}
int *getInts(int *size)
{
*size=ints.size();
return ints.data();
}
double *getFLoats(int *size)
{
*size=floats.size();
return floats.data();
}
void **getPointers(int *size)
{
*size=pointers.size();
return pointers.data();
}
char **getStrings(int *size)
{
*size=strSize;
return strings;
}
bool isInt()
{
return type==Type::INT;
}
bool isFloat()
{
return type==Type::FLOAT;
}
bool isString()
{
return type==Type::STRING;
}
bool isPointer()
{
return type==Type::POINTER;
}
};
class Value {
private:
int valueInt=0;
double valueDouble=0;
QString valueString;
void *valuePointer;
Type type=Type::NONE;
Array array;
public:
Value()=default;
Value(int val)
{
valueInt=val;
type=Type::INT;
}
Value(double val)
{
valueDouble=val;
type=Type::FLOAT;
}
Value(QString val)
{
valueString=val;
type=Type::STRING;
}
Value(void *val)
{
valuePointer=val;
type=Type::POINTER;
}
Value(Array val)
{
array=val;
type=Type::ARRAY;
}
void setValue(int64_t val)
{
valueInt=val;
type=Type::INT;
}
void setValue(double val)
{
valueDouble=val;
type=Type::FLOAT;
}
void setValue(QString val)
{
valueString=val;
type=Type::STRING;
}
void setValue(void *val)
{
valuePointer=val;
type=Type::POINTER;
}
void setValue(nullptr_t val)
{
valueInt=0;
valueDouble=0;
valueString=QString();
type=Type::NONE;
}
void setValue(Array val)
{
valueInt=0;
valueDouble=0;
valueString=QString();
array=val;
type=Type::ARRAY;
}
int getInt() const
{
if (type==Type::INT)
return valueInt;
return 0;
}
double getFloat() const
{
if (type==Type::FLOAT)
return valueDouble;
return 0;
}
Array getArray() const
{
if (type==Type::ARRAY)
return array;
return Array();
}
QString getString()
{
return valueString;
}
bool isInt()
{
return type==Type::INT;
}
bool isFloat()
{
return type==Type::FLOAT;
}
bool isString()
{
return type==Type::STRING;
}
bool isPointer()
{
return type==Type::POINTER;
}
bool isArray()
{
return type==Type::ARRAY;
}
bool isNull()
{
return type==Type::NONE;
}
};
struct plugin_mem_ptr { struct plugin_mem_ptr {
void *mem; void *mem;
int32_t count=0; int32_t count=0;
@@ -291,8 +43,22 @@ class OlivePlugin {
public: public:
OlivePlugin()=default; OlivePlugin()=default;
~OlivePlugin(); ~OlivePlugin();
void setProp(QString key, int index, Value val); OfxStatus getProp(QString key, int index, char **str);
OfxStatus getProp(QString key, int index, Value &val); OfxStatus getPropN(QString key, char *** strs);
OfxStatus getProp(QString key, int index, void **p);
OfxStatus getPropN(QString key, void ***ps);
OfxStatus getProp(QString key, int index, int *p);
OfxStatus getPropN(QString key, int **ps);
OfxStatus getProp(QString key, int index, double *p);
OfxStatus getPropN(QString key, double **ps);
OfxStatus setProp(QString key, int index, char *str);
OfxStatus setPropN(QString key,int count, char ** strs);
OfxStatus setProp(QString key, int index, void *p);
OfxStatus setPropN(QString key,int count, void **ps);
OfxStatus setProp(QString key, int index, int p);
OfxStatus setPropN(QString key,int count, int *ps);
OfxStatus setProp(QString key, int index, double p);
OfxStatus setPropN(QString key, int count, double *ps);
void addMem(void *mem) void addMem(void *mem)
{ {
mems.emplace_back(mem); mems.emplace_back(mem);
@@ -301,7 +67,10 @@ private:
uint64_t id; uint64_t id;
QString name; QString name;
QString version; QString version;
QMap<QString, QMap<int, Value>> props; QMap<QString, QVector<char *>> stringProps;
QMap<QString, QVector<int>> intProps;
QMap<QString, QVector<double>> doubleProps;
QMap<QString, QVector<void *>> pointerProps;
std::list<void *> mems; std::list<void *> mems;
}; };
} }
+115 -38
View File
@@ -18,17 +18,17 @@
#include "node/plugins/Plugin.h" #include "node/plugins/Plugin.h"
#include <ofxProperty.h> #include <ofxProperty.h>
#include <OpenImageIO/simd.h>
#include <oneapi/tbb/detail/_template_helpers.h>
OfxStatus propSetPointer(OfxPropertySetHandle properties, OfxStatus propSetPointer(OfxPropertySetHandle properties,
const char *property, int index, void *value) const char *property, int index, void *value)
{ {
olive::plugin::Value val;
if (properties->plugin) { if (properties->plugin) {
if (index<0) { if (index<0) {
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
properties->plugin->setProp(property, index, value); return properties->plugin->setProp(property, index, value);
return kOfxStatOK;
} }
return kOfxStatErrBadHandle; return kOfxStatErrBadHandle;
} }
@@ -36,13 +36,11 @@ OfxStatus propSetPointer(OfxPropertySetHandle properties,
OfxStatus propSetString(OfxPropertySetHandle properties, OfxStatus propSetString(OfxPropertySetHandle properties,
const char *property, int index, const char *value) const char *property, int index, const char *value)
{ {
olive::plugin::Value val;
if (properties->plugin) { if (properties->plugin) {
if (index<0) { if (index<0) {
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
properties->plugin->setProp(property, index, QString(value)); return properties->plugin->setProp(property, index, const_cast<char *>(value));
return kOfxStatOK;
} }
return kOfxStatErrBadHandle; return kOfxStatErrBadHandle;
} }
@@ -50,13 +48,12 @@ OfxStatus propSetString(OfxPropertySetHandle properties,
OfxStatus propSetDouble(OfxPropertySetHandle properties, OfxStatus propSetDouble(OfxPropertySetHandle properties,
const char *property, int index, double value) const char *property, int index, double value)
{ {
olive::plugin::Value val;
if (properties->plugin) { if (properties->plugin) {
if (index<0) { if (index<0) {
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
properties->plugin->setProp(property, index, static_cast<double>(value)); return properties->plugin->setProp(property, index, value);
return kOfxStatOK;
} }
return kOfxStatErrBadHandle; return kOfxStatErrBadHandle;
} }
@@ -64,29 +61,24 @@ OfxStatus propSetDouble(OfxPropertySetHandle properties,
OfxStatus propSetInt(OfxPropertySetHandle properties, const char *property, OfxStatus propSetInt(OfxPropertySetHandle properties, const char *property,
int index, int value) int index, int value)
{ {
olive::plugin::Value val;
if (properties->plugin) { if (properties->plugin) {
if (index<0) { if (index<0) {
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
properties->plugin->setProp(property, index, value); return properties->plugin->setProp(property, index, value);
return kOfxStatOK;
} }
return kOfxStatErrBadHandle; return kOfxStatErrBadHandle;
} }
OfxStatus propSetPointerN(OfxPropertySetHandle properties, OfxStatus propSetPointerN(OfxPropertySetHandle properties,
const char *property, int index, int count, void * const*value) const char *property, int count, void * const*value)
{ {
olive::plugin::Value val;
olive::plugin::Array array(value,count);
val.setValue(array);
if (properties->plugin) { if (properties->plugin) {
if (index<0) { if (count<0) {
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
properties->plugin->setProp(property, index, val); return properties->plugin->setPropN(property, count, const_cast<void**>(value));
return kOfxStatOK;
} }
return kOfxStatErrBadHandle; return kOfxStatErrBadHandle;
} }
@@ -94,47 +86,132 @@ OfxStatus propSetPointerN(OfxPropertySetHandle properties,
OfxStatus propSetStringN(OfxPropertySetHandle properties, OfxStatus propSetStringN(OfxPropertySetHandle properties,
const char *property, int index, int count,const char *const *value) 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 (properties->plugin) {
if (index<0) { if (count<0) {
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
properties->plugin->setProp(property, index, val); return properties->plugin->setPropN(property, count, const_cast<char**>(value));
return kOfxStatOK;
} }
return kOfxStatErrBadHandle; return kOfxStatErrBadHandle;
} }
OfxStatus propSetDoubleN(OfxPropertySetHandle properties, OfxStatus propSetDoubleN(OfxPropertySetHandle properties,
const char *property, int index, int count, const double* value) const char *property,int count, const double* value)
{ {
olive::plugin::Value val;
olive::plugin::Array array(value,count);
val.setValue(array);
if (properties->plugin) { if (properties->plugin) {
if (index<0) { if (count<0) {
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
properties->plugin->setProp(property, index, val); return properties->plugin->setPropN(property, count, const_cast<double *>(value));
return kOfxStatOK;
} }
return kOfxStatErrBadHandle; return kOfxStatErrBadHandle;
} }
OfxStatus propSetIntN(OfxPropertySetHandle properties, const char *property, OfxStatus propSetIntN(OfxPropertySetHandle properties, const char *property,
int index, int count, const int *value) int count, const int *value)
{
if (properties->plugin) {
if (count<0) {
return kOfxStatErrBadIndex;
}
return properties->plugin->setPropN(property, count, const_cast<int *>(value));
}
return kOfxStatErrBadHandle;
}
OfxStatus propGetPointer(OfxPropertySetHandle properties,
const char *property, int index, void **value)
{ {
olive::plugin::Value val;
olive::plugin::Array array(value, count);
val.setValue(array);
if (properties->plugin) { if (properties->plugin) {
if (index<0) { if (index<0) {
return kOfxStatErrBadIndex; return kOfxStatErrBadIndex;
} }
properties->plugin->setProp(property, index, val); return properties->plugin->getProp(property, index, value);
return kOfxStatOK; }
return kOfxStatErrBadHandle;
}
OfxStatus propGetString(OfxPropertySetHandle properties,
const char *property, int index, char **value)
{
std::any val;
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
return properties->plugin->getProp(property, index, value);
}
return kOfxStatErrBadHandle;
}
OfxStatus propGetDouble(OfxPropertySetHandle properties,
const char *property, int index, double *value)
{
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
return properties->plugin->getProp(property, index, value);
}
return kOfxStatErrBadHandle;
}
OfxStatus propGetInt(OfxPropertySetHandle properties, const char *property,
int index, int *value)
{
if (properties->plugin) {
if (index<0) {
return kOfxStatErrBadIndex;
}
return properties->plugin->getProp(property, index, value);
}
return kOfxStatErrBadHandle;
}
OfxStatus propGetPointerN(OfxPropertySetHandle properties,
const char *property, int count, void ***value)
{
if (properties->plugin) {
if (count<0) {
return kOfxStatErrBadIndex;
}
return properties->plugin->getPropN(property, value);
}
return kOfxStatErrBadHandle;
}
OfxStatus propGetStringN(OfxPropertySetHandle properties,
const char *property, int count, char ***value)
{
if (properties->plugin) {
if (count<0) {
return kOfxStatErrBadIndex;
}
return properties->plugin->getPropN(property, value);
}
return kOfxStatErrBadHandle;
}
OfxStatus propSetDoubleN(OfxPropertySetHandle properties,
const char *property, int index, int count, double** value)
{
if (properties->plugin) {
if (count<0) {
return kOfxStatErrBadIndex;
}
return properties->plugin->getPropN(property, value);
}
return kOfxStatErrBadHandle;
}
OfxStatus propSetIntN(OfxPropertySetHandle properties, const char *property,
int index, int count, int **value)
{
if (properties->plugin) {
if (count<0) {
return kOfxStatErrBadIndex;
}
return properties->plugin->getPropN(property, value);
} }
return kOfxStatErrBadHandle; return kOfxStatErrBadHandle;
} }