diff --git a/core/audio/plugin_host/host_param.cpp b/core/audio/plugin_host/host_param.cpp new file mode 100644 index 0000000..274888c --- /dev/null +++ b/core/audio/plugin_host/host_param.cpp @@ -0,0 +1,26 @@ +// +// Created by Nanako on 24-5-30. +// + +#include "host_param.h" + +#include "plugin_host.h" + +host_param::host_param(plugin_host* host, int32_t index) : host_(host), index_(index) +{ + is_valid_= host->is_param_index_valid(index_); +} + +void host_param::set_value(float in_value) +{ + if (!is_valid()) + return; + host_->set_param_value(index_, in_value); +} + +float host_param::get_value() const +{ + if (!is_valid()) + return 0; + return host_->get_param_value(index_); +} diff --git a/core/audio/plugin_host/host_param.h b/core/audio/plugin_host/host_param.h new file mode 100644 index 0000000..fea4c2d --- /dev/null +++ b/core/audio/plugin_host/host_param.h @@ -0,0 +1,25 @@ +#pragma once +#include "extern.h" +#include + +class plugin_host; + +class CORE_API host_param +{ +public: + host_param(plugin_host* host, int32_t index); + [[nodiscard]] int32_t get_index() const { return index_; } + [[nodiscard]] const std::string& get_name() const { return name_; } + [[nodiscard]] bool is_valid() const { return is_valid_; } + void set_value(float in_value); + [[nodiscard]] float get_value() const; + + explicit operator bool() const { + return is_valid(); + } +private: + int32_t index_ = -1; + std::string name_; + plugin_host* host_; + bool is_valid_ = false; +}; diff --git a/core/audio/plugin_host/plugin_host.h b/core/audio/plugin_host/plugin_host.h index b63d62c..bef083f 100644 --- a/core/audio/plugin_host/plugin_host.h +++ b/core/audio/plugin_host/plugin_host.h @@ -3,6 +3,7 @@ #include #include #include "extern.h" +#include "host_param.h" #include "audio/misc/circular_audio_buffer.h" #include "misc/delegates.h" @@ -38,7 +39,11 @@ public: [[nodiscard]] virtual std::string load_name() const { return ""; } [[nodiscard]] virtual std::string load_vendor() const { return ""; } - virtual std::string get_parameter_name(int index) const { return ""; } + [[nodiscard]] virtual std::string get_parameter_name(int index) const = 0; + [[nodiscard]] virtual int32_t get_param_count() const = 0; + [[nodiscard]] virtual bool is_param_index_valid(const int32_t index) const { return index >= 0 && index < get_param_count(); } + virtual void set_param_value(int32_t index, float value) = 0; + virtual float get_param_value(int32_t index) = 0; void init_channel_interface(); @@ -48,6 +53,7 @@ public: std::vector owner_tracks; bool editor_opened = false; std::shared_ptr ui_buffers; + multicast_delegate on_param_changed; protected: void create_and_open_editor(); void destroy_editor(); diff --git a/core/audio/plugin_host/vst2/vst2_plugin_host.cpp b/core/audio/plugin_host/vst2/vst2_plugin_host.cpp index 5d7f2bd..03d10ea 100644 --- a/core/audio/plugin_host/vst2/vst2_plugin_host.cpp +++ b/core/audio/plugin_host/vst2/vst2_plugin_host.cpp @@ -278,7 +278,27 @@ VstIntPtr vst2_plugin_host::dispatch(VstInt32 opcode, VstInt32 index, VstIntPtr } std::string vst2_plugin_host::get_parameter_name(int index) const { - char buffer[256]; - dispatch(effGetParamName, index, 0, buffer); + char buffer[kVstMaxParamStrLen]; + dispatch(effGetParamDisplay, index, 0, buffer); return buffer; } + +int32_t vst2_plugin_host::get_param_count() const +{ + if (!effect_) + return 0; + return effect_->numParams; +} + +void vst2_plugin_host::set_param_value(int32_t index, float value) +{ + if (effect_) + effect_->setParameter(effect_, index, value); +} + +float vst2_plugin_host::get_param_value(int32_t index) +{ + if (!effect_) + return 0; + return effect_->getParameter(effect_, index); +} diff --git a/core/audio/plugin_host/vst2/vst2_plugin_host.h b/core/audio/plugin_host/vst2/vst2_plugin_host.h index 083b280..1ca1468 100644 --- a/core/audio/plugin_host/vst2/vst2_plugin_host.h +++ b/core/audio/plugin_host/vst2/vst2_plugin_host.h @@ -26,7 +26,10 @@ public: [[nodiscard]] bool has_editor() const override; void get_editor_size(uint32_t& width, uint32_t& height) const override; // [[nodiscard]] ImVec2 get_editor_size() const override; - std::string get_parameter_name(int index) const override; + [[nodiscard]] std::string get_parameter_name(int index) const override; + [[nodiscard]] int32_t get_param_count() const override; + void set_param_value(int32_t index, float value) override; + float get_param_value(int32_t index) override; [[nodiscard]] std::string load_name() const override; [[nodiscard]] std::string load_vendor() const override;