0d22e8b4d3
JuceFxEngine: requestEditor/pumpEditorQueue/isEditorOpen/takeCapturedState, queue thread-safe, thuc thi tren GUI thread; shutdown() dong editor truoc graph.clear(); prepare() map slot->processor. juce_fx_bridge link juce_gui_basics; target juce_fx_selftest (khong ship) verify open/close/capture voi VST3 that — PASS tren Focusrite fast-compressor_x64. Tien de M2 (GUI thread + host window).
67 lines
3.0 KiB
C++
67 lines
3.0 KiB
C++
// native_bridge/juce_fx/JuceFxEngine.h
|
|
// JUCE AudioProcessorGraph engine (G1): đọc input ring → graph (rỗng) →
|
|
// ghi output ring. Tách khỏi loop để G2 chỉ thêm plugin vào graph.
|
|
#pragma once
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class JuceFxEngine {
|
|
public:
|
|
JuceFxEngine();
|
|
~JuceFxEngine();
|
|
// Không copy.
|
|
JuceFxEngine(const JuceFxEngine&) = delete;
|
|
JuceFxEngine& operator=(const JuceFxEngine&) = delete;
|
|
|
|
// Tạo graph mới (input node -> [VST3 theo chain] -> output node).
|
|
// sampleRate/blockSize đổi → teardown graph cũ + prepare lại (validate
|
|
// header G1). blockSize là kích thước mỗi SHM block (256).
|
|
void prepare(uint32_t sampleRate, uint32_t blockSize);
|
|
// G2: đặt chain (mảng JSON fx_chain) trước prepare — các slot bypass /
|
|
// không phải vst3 / load fail chạy passthrough (latency 0).
|
|
void setChain(const std::string& chainJson);
|
|
// Audio thread: xử lý n mẫu stereo in-place (n <= blockSize * FXRT_IN_SLOTS).
|
|
void process(float* inL, float* inR, uint32_t n);
|
|
// Graph latency samples (G1 chain rỗng = 0; G2 = getLatencySamples thật).
|
|
uint32_t latencySamples() const;
|
|
// Latency thật từng slot theo thứ tự chain (0 = skip/bypass/fail).
|
|
std::vector<uint32_t> entryLatencies() const;
|
|
|
|
// ── Editor host (Phase 2 — Reaper-style): editor của CHÍNH instance DSP
|
|
// trong graph, không instance thứ 2 / không feeder. Audio thread
|
|
// process() KHÔNG bao giờ chạm editor; mọi thao tác đi qua queue và chỉ
|
|
// thực thi trong pumpEditorQueue() trên GUI thread (JUCE message thread).
|
|
enum class EditorAction {
|
|
Open, // tạo editor (createEditorIfNeeded) cho slot — giữ instance DSP
|
|
Close, // huỷ editor, GIỮ instance DSP + state (mở lại nhanh)
|
|
Show, // hiện editor (M2: host window) — chưa tác dụng khi chưa attach
|
|
Hide, // ẩn editor (M2: host window)
|
|
Resize, // đổi kích thước editor (M2: host window)
|
|
Capture // đọc state processor (getStateInformation) -> captured[slot]
|
|
};
|
|
|
|
// Thread-safe (gọi từ bất kỳ thread nào, kể cả ctrl-reader): xếp lệnh.
|
|
// w/h dùng cho Open/Resize (kích thước editor mong muốn).
|
|
void requestEditor(uint32_t slot, EditorAction action, int w = 0, int h = 0);
|
|
|
|
// GUI thread (JUCE message thread): drain queue + thực thi lệnh editor.
|
|
// Trả true nếu xử lý >= 1 lệnh. Không gọi từ audio thread.
|
|
bool pumpEditorQueue();
|
|
|
|
// Thread-safe đọc: slot có editor đang mở không.
|
|
bool isEditorOpen(uint32_t slot) const;
|
|
|
|
// Thread-safe: lấy + xoá state capture gần nhất của slot (rỗng nếu chưa).
|
|
// Raw bytes (chưa base64) — M3 encode khi đẩy về engine Python.
|
|
std::string takeCapturedState(uint32_t slot);
|
|
|
|
void shutdown();
|
|
|
|
private:
|
|
struct Slot; // G2: một mục fx_chain (type/path/presetB64/bypass)
|
|
struct Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|