From 49402126871e0febd4c186955440540f01ba75a8 Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Sun, 3 Aug 2025 22:42:05 +0800 Subject: [PATCH] add: some codes about nodes plugin. --- app/node/CMakeLists.txt | 1 + app/node/plugins/CMakeLists.txt | 22 +++++++++++++++ app/node/plugins/Plugin.cpp | 46 ++++++++++++++++++++++++++++++++ app/node/plugins/Plugin.h | 44 ++++++++++++++++++++++++++++++ app/pluginSupport/CMakeLists.txt | 1 + app/pluginSupport/Plugin.cpp | 1 + app/pluginSupport/Plugin.h | 33 ++++++++++++++++------- app/pluginSupport/olive_plugin.h | 46 ++++++++++++++++++++++++++++++++ 8 files changed, 185 insertions(+), 9 deletions(-) create mode 100644 app/node/plugins/CMakeLists.txt create mode 100644 app/node/plugins/Plugin.cpp create mode 100644 app/node/plugins/Plugin.h create mode 100644 app/pluginSupport/olive_plugin.h diff --git a/app/node/CMakeLists.txt b/app/node/CMakeLists.txt index ef1978c21..6c903dacc 100644 --- a/app/node/CMakeLists.txt +++ b/app/node/CMakeLists.txt @@ -27,6 +27,7 @@ add_subdirectory(input) add_subdirectory(keying) add_subdirectory(math) add_subdirectory(output) +add_subdirectory(plugins) add_subdirectory(project) add_subdirectory(time) diff --git a/app/node/plugins/CMakeLists.txt b/app/node/plugins/CMakeLists.txt new file mode 100644 index 000000000..2eb07ea2f --- /dev/null +++ b/app/node/plugins/CMakeLists.txt @@ -0,0 +1,22 @@ +# Olive - Non-Linear Video Editor +# Copyright (C) 2022 Olive Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(OLIVE_SOURCES + ${OLIVE_SOURCES} + node/plugins/Plugin.h + node/plugins/Plugin.cpp + PARENT_SCOPE +) diff --git a/app/node/plugins/Plugin.cpp b/app/node/plugins/Plugin.cpp new file mode 100644 index 000000000..3b096a3ce --- /dev/null +++ b/app/node/plugins/Plugin.cpp @@ -0,0 +1,46 @@ +// +// Created by katherinesolar on 25-8-3. +// + +#include "Plugin.h" +QString olive::plugin::PluginNode::Name() const +{ + if (methods.name) { + char buffer[64]={0}; + bool ok=methods.name(buffer, 64); + if (ok) { + return QString(buffer); + } + } + return ""; +} + +QString olive::plugin::PluginNode::Description() const +{ + if (methods.description) { + char buffer[1024] = { 0 }; + bool ok = methods.description(buffer, 1024); + if (ok) { + return QString(buffer); + } + } + return ""; +} +void olive::plugin::PluginNode::Value(const NodeValueRow &value, + const NodeGlobals &globals, + NodeValueTable *table) const +{ + methods.value(&node_ctx_functions); +} + +QString olive::plugin::PluginNode::id() const +{ + if (methods.id) { + char buffer[64]={0}; + bool ok=methods.id(buffer, 64); + if (ok) { + return QString(buffer); + } + } + return ""; +} \ No newline at end of file diff --git a/app/node/plugins/Plugin.h b/app/node/plugins/Plugin.h new file mode 100644 index 000000000..b8a4f326a --- /dev/null +++ b/app/node/plugins/Plugin.h @@ -0,0 +1,44 @@ +// +// Created by katherinesolar on 25-8-3. +// + +#ifndef PLUGIN_H +#define PLUGIN_H +#include "node/node.h" +#include "pluginSupport/Plugin.h" +#include "pluginSupport/olive_plugin.h" +namespace olive +{ +namespace plugin +{ + +class PluginNode : public olive::Node{ +public: + PluginNode():Node() + { + memset(&methods, 0, sizeof(olive_node_methods)); + }; + explicit PluginNode(struct olive_node_methods methods):Node() + { + this->methods=methods; + } + void setMethods(struct olive_node_methods methods) + { + this->methods=methods; + } + QString Name() const override; + QString id() const override; + QVector Category() const override; + QString Description() const override; + void Value(const NodeValueRow &value, + const NodeGlobals &globals, NodeValueTable *table) const override; +private: + struct olive_node_methods methods; + +}; + +} +} + + +#endif //PLUGIN_H diff --git a/app/pluginSupport/CMakeLists.txt b/app/pluginSupport/CMakeLists.txt index 59c97c6a8..2690f7bb8 100644 --- a/app/pluginSupport/CMakeLists.txt +++ b/app/pluginSupport/CMakeLists.txt @@ -2,5 +2,6 @@ set(OLIVE_SOURCES ${OLIVE_SOURCES} pluginSupport/Plugin.cpp pluginSupport/Plugin.h + pluginSupport/olive_plugin.h PARENT_SCOPE ) \ No newline at end of file diff --git a/app/pluginSupport/Plugin.cpp b/app/pluginSupport/Plugin.cpp index 970578474..4702c159c 100644 --- a/app/pluginSupport/Plugin.cpp +++ b/app/pluginSupport/Plugin.cpp @@ -3,3 +3,4 @@ // #include "Plugin.h" +olive_node_ctx_functions node_ctx_functions; \ No newline at end of file diff --git a/app/pluginSupport/Plugin.h b/app/pluginSupport/Plugin.h index 607477937..7bb2b308e 100644 --- a/app/pluginSupport/Plugin.h +++ b/app/pluginSupport/Plugin.h @@ -4,28 +4,43 @@ #ifndef PLUGIN_H #define PLUGIN_H -#include -#include +#include "olive_plugin.h" + +#include +#include #include + +extern struct olive_node_ctx_functions node_ctx_functions; namespace olive { typedef int(*button_callback_t)(); +typedef int(*node_callback_t)(); namespace plugin { struct Button { - std::string name; + QString name; button_callback_t callback; }; struct Menu { - std::string name; - std::map> buttons; + QString name; + QMap> buttons; +}; +struct Node { + QString name; + QString shortName; + QString id; + QString description; + int categoryId; + QString categoryName; + }; struct Plugin { - std::string name; - std::string version; - std::string author; - std::vector menus; + QString name; + QString version; + QString author; + QList menus; + QList nodes; }; } class Plugin { diff --git a/app/pluginSupport/olive_plugin.h b/app/pluginSupport/olive_plugin.h new file mode 100644 index 000000000..88e995c9f --- /dev/null +++ b/app/pluginSupport/olive_plugin.h @@ -0,0 +1,46 @@ +// +// Created by katherinesolar on 25-8-3. +// + +#ifndef OLIVE_PLUGIN_H +#define OLIVE_PLUGIN_H +#include +struct olive_color { + uint8_t red; + uint8_t green; + uint8_t blue; +}; +struct olive_node_ctx_functions { + bool (*get_ctx_int)(uint64_t handle, char *name, int *val); + bool (*get_ctx_float)(uint64_t handle, char *name, float *out_val); + bool (*get_ctx_rational)(uint64_t handle, char *name, double *out_val); + bool (*get_ctx_bool)(uint64_t handle, char *name, bool *out_val); + bool (*get_ctx_string)(uint64_t handle, char *name, char **out_str); + bool (*get_ctx_font)(uint64_t handle, char *name, char **out_font); + bool (*get_ctx_path)(uint64_t handle, char *name, char **out_path); + bool (*get_sample_buffer_handle)(uint64_t handle, char *name, uint64_t *out_handle); + bool (*get_ctx_samples)(uint64_t handle, char *name, uint64_t *out_handle); + bool (*get_ctx_video_params)(uint64_t handle, char *name, uint64_t *out_params); + bool (*get_ctx_audio_params)(uint64_t handle, char *name, uint64_t *out_params); + bool (*get_ctx_subtitle_params)(uint64_t handle, char *name, uint64_t *out_params); + bool (*get_ctx_bezier)(uint64_t handle, char *name, uint64_t *out_bezier); + bool (*get_ctx_vec2)(uint64_t handle, char *name, double **vec); + bool (*get_ctx_vec3)(uint64_t handle, char *name, double **vec); + bool (*get_ctx_vec4)(uint64_t handle, char *name, double **vec); + + int64_t (*get_size_need)(char *name); + // 下面几个函数请先获取缓冲区大小 + bool (*get_ctx_matrix)(uint64_t handle, char *name, int ***buffer, size_t buffer_size, + int *out_rows, int *out_cols); + bool (*get_ctx_texture)(uint64_t handle, char *name, uint8_t **buffer, size_t buffer_size, + int *out_len); + bool (*get_ctx_binary)(uint64_t handle, char *name, uint8_t* buffer, size_t buffer_size); +}; +struct olive_node_methods { + bool (*name)(char *buffer, size_t buffer_size); //最长63个char + bool (*id)(char *buffer, size_t buffer_size); //最长63个char + bool (*category)(char *buffer, size_t buffer_size); //最长63个char + bool (*description)(char *buffer, size_t buffer_size); //最长1023个char + void (*value)(struct olive_node_ctx_functions *functions); +}; +#endif //OLIVE_PLUGIN_H