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 统一按立体声总线构建音频图。
145 lines
3.8 KiB
C++
145 lines
3.8 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
WindowsSharedMemoryRegion.cpp
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#include "WindowsSharedMemoryRegion.h"
|
|
|
|
#if JUCE_WINDOWS
|
|
|
|
namespace minixer
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
juce::String makeMappingName (const juce::String& key)
|
|
{
|
|
return "Local\\" + key + "_AudioShm";
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
//==============================================================================
|
|
WindowsSharedMemoryRegion::WindowsSharedMemoryRegion() = default;
|
|
|
|
WindowsSharedMemoryRegion::~WindowsSharedMemoryRegion()
|
|
{
|
|
close();
|
|
}
|
|
|
|
//==============================================================================
|
|
bool WindowsSharedMemoryRegion::create (const juce::String& key, size_t size)
|
|
{
|
|
return openInternal (key, size, FILE_MAP_ALL_ACCESS, true);
|
|
}
|
|
|
|
//==============================================================================
|
|
bool WindowsSharedMemoryRegion::open (const juce::String& key, size_t size)
|
|
{
|
|
return openInternal (key, size, FILE_MAP_ALL_ACCESS, false);
|
|
}
|
|
|
|
//==============================================================================
|
|
void* WindowsSharedMemoryRegion::getAddress() const
|
|
{
|
|
return address;
|
|
}
|
|
|
|
//==============================================================================
|
|
size_t WindowsSharedMemoryRegion::getSize() const
|
|
{
|
|
return mappedSize;
|
|
}
|
|
|
|
//==============================================================================
|
|
void WindowsSharedMemoryRegion::close()
|
|
{
|
|
if (address != nullptr)
|
|
{
|
|
UnmapViewOfFile (address);
|
|
address = nullptr;
|
|
}
|
|
|
|
if (mapping != nullptr)
|
|
{
|
|
CloseHandle (mapping);
|
|
mapping = nullptr;
|
|
}
|
|
|
|
mappedSize = 0;
|
|
}
|
|
|
|
//==============================================================================
|
|
bool WindowsSharedMemoryRegion::openInternal (const juce::String& key,
|
|
size_t size,
|
|
DWORD access,
|
|
bool createNew)
|
|
{
|
|
close();
|
|
|
|
if (size == 0)
|
|
return false;
|
|
|
|
const auto nameStr = makeMappingName (key);
|
|
const auto* name = nameStr.toWideCharPointer();
|
|
const SIZE_T sz = static_cast<SIZE_T> (size);
|
|
|
|
if (createNew)
|
|
{
|
|
mapping = CreateFileMappingW (INVALID_HANDLE_VALUE,
|
|
nullptr,
|
|
PAGE_READWRITE,
|
|
0,
|
|
static_cast<DWORD> (sz),
|
|
name);
|
|
}
|
|
else
|
|
{
|
|
mapping = OpenFileMappingW (access, FALSE, name);
|
|
}
|
|
|
|
if (mapping == nullptr)
|
|
return false;
|
|
|
|
// 打开侧(子进程)映射整个区域,而不是按本进程推算的尺寸取视图:
|
|
// 主进程按插件描述通道数(可能为 0/不准确)创建映射,尺寸由主进程决定,
|
|
// 子进程只有在读到共享内存头部的 numInputChannels/numOutputChannels 后
|
|
// 才知道真实的缓冲布局;映射整个区域可避免“视图尺寸与主进程映射不一致
|
|
// → MapViewOfFile 失败或后续指针越界”。
|
|
address = MapViewOfFile (mapping, access, 0, 0, createNew ? sz : 0);
|
|
|
|
if (address == nullptr)
|
|
{
|
|
close();
|
|
return false;
|
|
}
|
|
|
|
mappedSize = size;
|
|
|
|
if (createNew)
|
|
ZeroMemory (address, static_cast<SIZE_T> (size));
|
|
|
|
return true;
|
|
}
|
|
|
|
//==============================================================================
|
|
std::unique_ptr<SharedMemoryRegion> createDefaultSharedMemoryRegion()
|
|
{
|
|
return std::make_unique<WindowsSharedMemoryRegion>();
|
|
}
|
|
|
|
} // namespace minixer
|
|
|
|
#else
|
|
|
|
namespace minixer
|
|
{
|
|
std::unique_ptr<SharedMemoryRegion> createDefaultSharedMemoryRegion() { return {}; }
|
|
} // namespace minixer
|
|
|
|
#endif
|