From 191f90de6d07420c6e9a5dc9ac59f36b241cf14e Mon Sep 17 00:00:00 2001
From: Nanako <469449812@qq.com>
Date: Sun, 26 May 2024 17:55:33 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E6=8F=92?=
 =?UTF-8?q?=E4=BB=B6parameter=E5=90=8D=E7=A7=B0=E6=8E=A5=E5=8F=A3=20?=
 =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=8E=B7=E5=8F=96vst2=E6=9C=80=E5=90=8E?=
 =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=94=B9=E5=8F=98=E7=9A=84parameter?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 core/CMakeLists.txt                              |  6 ++++++
 core/audio/plugin_host/plugin_host.h             |  2 ++
 core/audio/plugin_host/vst2/vst2_plugin_host.cpp | 13 ++++++++++++-
 core/audio/plugin_host/vst2/vst2_plugin_host.h   |  1 +
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index de2c60c..d22af90 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -31,3 +31,9 @@ elseif(APPLE)
 elseif(UNIX AND NOT APPLE)
     target_compile_definitions(${PROJECT_NAME} PUBLIC PLATFORM_WINDOWS=0 PLATFORM_MACOS=0 PLATFORM_LINUX=1 GLFW_EXPOSE_NATIVE_X11)
 endif()
+
+if (CMAKE_BUILD_TYPE MATCHES "Debug")
+    target_compile_definitions(${PROJECT_NAME} PUBLIC BUILD_DEBUG=1)
+else()
+    target_compile_definitions(${PROJECT_NAME} PUBLIC BUILD_DEBUG=0)
+endif()
\ No newline at end of file
diff --git a/core/audio/plugin_host/plugin_host.h b/core/audio/plugin_host/plugin_host.h
index 398b834..13f04fd 100644
--- a/core/audio/plugin_host/plugin_host.h
+++ b/core/audio/plugin_host/plugin_host.h
@@ -37,6 +37,8 @@ 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 ""; }
+
     void init_channel_interface();
 
     std::string name;
diff --git a/core/audio/plugin_host/vst2/vst2_plugin_host.cpp b/core/audio/plugin_host/vst2/vst2_plugin_host.cpp
index 836dfa3..25ff103 100644
--- a/core/audio/plugin_host/vst2/vst2_plugin_host.cpp
+++ b/core/audio/plugin_host/vst2/vst2_plugin_host.cpp
@@ -49,8 +49,13 @@ VstIntPtr vst_master_callback(AEffect* effect, VstInt32 opcode, VstInt32 index,
 {
     switch (opcode)
     {
-        case audioMasterAutomate:
+        case audioMasterAutomate: {
+            auto host = ((vst2_plugin_host *) effect->user);
+#if BUILD_DEBUG
+            spdlog::info("vst2 plugin {} automate, {} index = {}, value = {}", host->name, host->get_parameter_name(index), index, opt);
+#endif
             return 1;
+        }
         case audioMasterVersion:
             return kVstVersion; // 返回插件版本号
         case audioMasterWantMidi:
@@ -261,3 +266,9 @@ void vst2_plugin_host::close_editor() {
 VstIntPtr vst2_plugin_host::dispatch(VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt) const {
     return effect_->dispatcher(effect_, opcode, index, value, ptr, opt);
 }
+
+std::string vst2_plugin_host::get_parameter_name(int index) const {
+    char buffer[256];
+    dispatch(effGetParamName, index, 0, buffer);
+    return buffer;
+}
diff --git a/core/audio/plugin_host/vst2/vst2_plugin_host.h b/core/audio/plugin_host/vst2/vst2_plugin_host.h
index 7b4b5b4..083b280 100644
--- a/core/audio/plugin_host/vst2/vst2_plugin_host.h
+++ b/core/audio/plugin_host/vst2/vst2_plugin_host.h
@@ -26,6 +26,7 @@ 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 load_name() const override;
     [[nodiscard]] std::string load_vendor() const override;