T11: IPC param sync 2 chieu native<->JS (setParamNormalized/setParameter, vst_param_changed event, guard chong loop)
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "public.sdk/source/vst/hosting/module.h"
|
||||
#include "public.sdk/source/vst/hosting/plugprovider.h"
|
||||
#include "public.sdk/source/common/commonstringconvert.h"
|
||||
#include "pluginterfaces/base/funknown.h"
|
||||
#include "pluginterfaces/gui/iplugview.h"
|
||||
#include "pluginterfaces/vst/ivstaudioprocessor.h"
|
||||
@@ -35,7 +36,12 @@ using namespace Steinberg::Vst;
|
||||
|
||||
namespace {
|
||||
|
||||
// ComponentHandler tối thiểu — T11: performEdit → JS param sync.
|
||||
// Callback param: plugin đổi param trong editor → đẩy lên host (T11).
|
||||
// handle = instance handle; paramId = ParamID; valueNormalized 0..1.
|
||||
typedef void (__cdecl* SF_ParamChangedCallback)(int32 handle, int32 paramId,
|
||||
double valueNormalized, void* userdata);
|
||||
|
||||
// ComponentHandler tối thiểu — T11: performEdit → callback param sync.
|
||||
class ComponentHandler : public IComponentHandler
|
||||
{
|
||||
public:
|
||||
@@ -55,12 +61,26 @@ public:
|
||||
uint32 PLUGIN_API addRef () override { return 1; }
|
||||
uint32 PLUGIN_API release () override { return 1; }
|
||||
tresult PLUGIN_API beginEdit (ParamID /*id*/) override { return kResultOk; }
|
||||
tresult PLUGIN_API performEdit (ParamID /*id*/, ParamValue /*valueNormalized*/) override
|
||||
tresult PLUGIN_API performEdit (ParamID id, ParamValue valueNormalized) override
|
||||
{
|
||||
if (cb)
|
||||
cb (handle, static_cast<int32> (id), static_cast<double> (valueNormalized), userdata);
|
||||
return kResultOk;
|
||||
}
|
||||
tresult PLUGIN_API endEdit (ParamID /*id*/) override { return kResultOk; }
|
||||
tresult PLUGIN_API restartComponent (int32 /*flags*/) override { return kResultOk; }
|
||||
|
||||
void setCallback (int32 h, SF_ParamChangedCallback c, void* u)
|
||||
{
|
||||
handle = h;
|
||||
cb = c;
|
||||
userdata = u;
|
||||
}
|
||||
|
||||
private:
|
||||
int32 handle = 0;
|
||||
SF_ParamChangedCallback cb = nullptr;
|
||||
void* userdata = nullptr;
|
||||
};
|
||||
|
||||
struct Instance
|
||||
@@ -233,4 +253,75 @@ __declspec (dllexport) int32 SF_VST3_Resize (int32 handle, int32 w, int32 h)
|
||||
return -2;
|
||||
}
|
||||
|
||||
// Đăng ký callback param (T11): plugin đổi param trong editor → cb(handle,
|
||||
// paramId, valueNormalized, userdata). userdata là con trỏ do host giữ.
|
||||
__declspec (dllexport) int32 SF_VST3_SetParamCallback (int32 handle,
|
||||
SF_ParamChangedCallback cb,
|
||||
void* userdata)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (g_mutex);
|
||||
auto it = g_instances.find (handle);
|
||||
if (it == g_instances.end ())
|
||||
return -1;
|
||||
it->second->handler.setCallback (handle, cb, userdata);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// JS automation → setParamNormalized (T11).
|
||||
__declspec (dllexport) int32 SF_VST3_SetParam (int32 handle, int32 paramId, double valueNormalized)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (g_mutex);
|
||||
auto it = g_instances.find (handle);
|
||||
if (it == g_instances.end ())
|
||||
return -1;
|
||||
if (!it->second->controller)
|
||||
return -2;
|
||||
it->second->controller->setParamNormalized (static_cast<ParamID> (paramId),
|
||||
static_cast<ParamValue> (valueNormalized));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Số tham số plugin (để JS dựng UI param list).
|
||||
__declspec (dllexport) int32 SF_VST3_GetParamCount (int32 handle)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (g_mutex);
|
||||
auto it = g_instances.find (handle);
|
||||
if (it == g_instances.end ())
|
||||
return -1;
|
||||
if (!it->second->controller)
|
||||
return -2;
|
||||
return static_cast<int32> (it->second->controller->getParameterCount ());
|
||||
}
|
||||
|
||||
// Thông tin param thứ index (0-based): id + tên (title) + giá trị normalized.
|
||||
// Trả 0 nếu OK; -1 bad handle; -2 no controller; -3 index ngoài phạm vi.
|
||||
__declspec (dllexport) int32 SF_VST3_GetParamInfo (int32 handle, int32 index,
|
||||
int32* out_id, char* out_title,
|
||||
int32 title_cap, double* out_value)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (g_mutex);
|
||||
auto it = g_instances.find (handle);
|
||||
if (it == g_instances.end ())
|
||||
return -1;
|
||||
IEditController* ctrl = it->second->controller;
|
||||
if (!ctrl)
|
||||
return -2;
|
||||
if (index < 0 || static_cast<uint32> (index) >= ctrl->getParameterCount ())
|
||||
return -3;
|
||||
ParameterInfo info = {};
|
||||
if (ctrl->getParameterInfo (static_cast<int32> (index), info) != kResultTrue)
|
||||
return -3;
|
||||
if (out_id)
|
||||
*out_id = static_cast<int32> (info.id);
|
||||
if (out_title && title_cap > 0)
|
||||
{
|
||||
std::string titleUtf8 = StringConvert::convert (std::u16string (info.title));
|
||||
std::strncpy (out_title, titleUtf8.c_str (), static_cast<size_t> (title_cap - 1));
|
||||
out_title[title_cap - 1] = '\0';
|
||||
}
|
||||
if (out_value)
|
||||
*out_value = static_cast<double> (ctrl->getParamNormalized (info.id));
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user