Files
SonicForgeStudio/native_bridge/include/INativeInstrument.h
T
admin 35499b614c fix(bridge): VSTi GUI crash on instrument switch — PostMessage WM_CLOSE instead of cross-thread DestroyWindow
- LOAD job posts WM_CLOSE to window created on main thread (DestroyWindow from worker crashed 0xc000041d, muting all tracks)
- handleOpenGui + attach jobs skip when Vst3Instrument::hasAttachedView() (state_ && guiAttached_)
- attach failure posts WM_CLOSE; post_close_gui erases entry only when it points at the same hwnd
- cap openVstGuiRetry at 5 to stop frontend retry spam
2026-08-14 10:18:22 +07:00

59 lines
2.5 KiB
C++

// native_bridge/include/INativeInstrument.h
#ifndef I_NATIVE_INSTRUMENT_H
#define I_NATIVE_INSTRUMENT_H
#include <cstdint>
#include <string>
enum class InstrumentType {
VST3,
VST2,
SOUNDFONT_SF2_SF3,
SFZ
};
class INativeInstrument {
public:
virtual ~INativeInstrument() = default;
// Initialize Engine with Sample Rate and Buffer Size
virtual bool init(double sampleRate, uint32_t maxBlockSize) = 0;
// Select Bank and Program Change
virtual void selectProgram(uint32_t channel, uint32_t bank, uint32_t program) = 0;
// Dispatch MIDI Note On / Note Off events
virtual void noteOn(uint32_t channel, uint32_t pitch, float velocity, uint32_t sampleOffset) = 0;
virtual void noteOff(uint32_t channel, uint32_t pitch, uint32_t sampleOffset) = 0;
// MIDI continuous controllers (A12): CC value, program change, 14-bit pitch bend
virtual void controlChange(uint32_t channel, uint32_t cc, uint32_t value) = 0;
virtual void programChange(uint32_t channel, uint32_t program) = 0;
virtual void pitchBend(uint32_t channel, uint32_t bend14) = 0;
// Open/close Native GUI window
virtual bool openGUI(void* parentWindowHandle) = 0;
virtual void closeGUI() = 0;
// VST3 reopen-after-close: the bridge checks before openGUI whether the
// instance must be rebuilt; while it is, the engine sets reloading=true
// and the real-time loop skips processAudioBlock (teardown must not race
// the audio thread — a reload terminates the VST while renderAll may be
// inside processAudioBlock on the same instance).
virtual bool needsReload() const { return false; }
virtual void setReloading(bool /*on*/) {}
// VST3: split openGUI so instance teardown/reload runs on the owning
// apartment thread while view->attached() may run on a temporary thread
// with the channel worker pumping messages (see bridge main.cpp).
virtual bool reloadForGUI() { return true; }
virtual bool attachView(void* /*parentWindowHandle*/) { return false; }
// True while the editor view is attached (GUI window open). The bridge uses
// it to dedupe repeated OPEN_GUI (frontend retry spam) — re-attaching a
// view that is already attached corrupts plugins (Nexus createView→null).
virtual bool hasAttachedView() const { return false; }
// Real-time Audio PCM Float32 rendering loop
virtual void processAudioBlock(float* outputL, float* outputR, uint32_t numSamples) = 0;
};
#endif // I_NATIVE_INSTRUMENT_H