mirror of
https://github.com/XmengMD/Minixer.git
synced 2026-12-05 08:00:37 +00:00
PluginHost 控制循环(IPC 阻塞读)移入独立后台线程,消息线程进入 runDispatchLoop 驱动插件编辑器 UI;安装与主程序一致的 MixerLookAndFeel,版本号统一取 ProjectInfo。 PluginHostServer 将 wrapper 改为 shared_ptr 并注入编辑器关闭回调;编辑器显示/隐藏经 callAsync 转投消息线程,按消息线程销毁规则释放 GPU 资源;Init 布局设置失败不再回退,插件按默认布局继续出声。 PluginWrapper 编辑器改用独立 PluginEditorWindow(原生标题栏 + 深色背景 + 关闭回调销毁);processBlock 增加常规/回退双路径,按插件实际通道数适配缓冲,解决通道不匹配导致的无声;新增 VST3 外壳插件 name 校验,不符则重建一次。 IPC:命名管道改为字节流模式并将长度头与负载单次写入,消除消息边界错位;共享内存子进程侧映射整个区域,避免映射尺寸不一致;PluginHostClient 通道数钳到至少 2 与子进程 (2,2) 布局对齐,Init 超时放宽至 120s。PluginBridgeNode 统一按立体声总线构建音频图。
119 lines
4.5 KiB
C++
119 lines
4.5 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
PluginWrapper.h
|
|
PluginHost 子进程中的 VST3 插件封装。
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
#include <JuceHeader.h>
|
|
|
|
namespace minixer
|
|
{
|
|
|
|
// 子进程侧插件编辑器所在的独立浮动窗口(定义见 PluginWrapper.cpp)。
|
|
class PluginEditorWindow;
|
|
|
|
//==============================================================================
|
|
/** 封装单个 VST3 插件实例,隐藏 JUCE AudioPluginInstance 的细节。
|
|
|
|
负责加载、总线配置、音频处理、参数/状态读写以及浮动编辑器窗口。
|
|
PluginHostServer 通过本类调用插件,保持控制逻辑与插件操作分离。
|
|
*/
|
|
class PluginWrapper
|
|
{
|
|
public:
|
|
//==============================================================================
|
|
PluginWrapper();
|
|
~PluginWrapper();
|
|
|
|
//==============================================================================
|
|
/** 从完整的 PluginDescription 加载插件并创建实例。
|
|
|
|
对 Waves 等 shell 插件(一个 .vst3 文件内包含多个子插件)必须传入
|
|
包含 uid 的完整描述,否则只会加载该文件里的第一个插件。
|
|
*/
|
|
bool loadFromDescription (const juce::PluginDescription& description,
|
|
double sampleRate,
|
|
int bufferSize,
|
|
juce::String& error);
|
|
|
|
/** 返回是否已成功加载插件。 */
|
|
bool isLoaded() const noexcept { return plugin != nullptr; }
|
|
|
|
/** 返回插件名称。 */
|
|
juce::String getName() const;
|
|
|
|
//==============================================================================
|
|
/** 设置插件主输入/输出总线通道数。 */
|
|
bool setChannelLayout (uint32_t numInputs, uint32_t numOutputs, juce::String& error);
|
|
|
|
/** 准备播放。 */
|
|
void prepareToPlay (double sampleRate, int bufferSize);
|
|
|
|
/** 释放资源。 */
|
|
void releaseResources();
|
|
|
|
//==============================================================================
|
|
/** 处理一帧音频。
|
|
|
|
inputChannels / outputChannels 为非交错 float 指针数组,分别包含
|
|
numInputChannels / numOutputChannels 个通道。
|
|
*/
|
|
void processBlock (const float* const* inputChannels, uint32_t numInputChannels,
|
|
float* const* outputChannels, uint32_t numOutputChannels,
|
|
uint32_t numSamples);
|
|
|
|
//==============================================================================
|
|
void getStateInformation (juce::MemoryBlock& destData);
|
|
void setStateInformation (const juce::MemoryBlock& stateData);
|
|
|
|
void setParameter (int index, float value);
|
|
int getLatencySamples() const;
|
|
|
|
//==============================================================================
|
|
bool hasEditor() const;
|
|
void showEditor (const juce::String& windowTitle, void* parentWindowHandle);
|
|
void hideEditor();
|
|
bool isEditorOpen() const noexcept { return editorWindow != nullptr; }
|
|
|
|
/** 设置编辑器窗口被关闭时应执行的处理器(由宿主服务器注入)。
|
|
|
|
处理器需要持有对 PluginWrapper 的安全生命周期引用(如 weak_ptr),
|
|
避免关闭按钮回调期间对象已被销毁。
|
|
*/
|
|
void setEditorCloseRequestHandler (std::function<void()> handler) noexcept
|
|
{
|
|
editorCloseRequested = std::move (handler);
|
|
}
|
|
|
|
private:
|
|
//==============================================================================
|
|
void closeEditor();
|
|
|
|
/** 确保回退路径的内部缓冲达到指定尺寸(仅在插件通道数超过宿主缓冲时分配)。 */
|
|
void ensureTempBuffer (int numChannels, int numSamples);
|
|
|
|
//==============================================================================
|
|
std::unique_ptr<juce::AudioPluginInstance> plugin;
|
|
std::unique_ptr<juce::AudioProcessorEditor> editor;
|
|
std::unique_ptr<PluginEditorWindow> editorWindow;
|
|
|
|
// 回退路径用的内部处理缓冲(处理结束按可容纳通道数回拷到输出区)。
|
|
juce::AudioBuffer<float> tempBuffer;
|
|
|
|
// 编辑器窗口关闭请求处理器(由宿主服务器注入)。
|
|
std::function<void()> editorCloseRequested;
|
|
|
|
uint32_t currentInputChannels = 2;
|
|
uint32_t currentOutputChannels = 2;
|
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginWrapper)
|
|
};
|
|
|
|
} // namespace minixer
|