05e4244cc8
- Close other channels' editor windows before attaching a new one (Option B) - needsReload()/setReloading() guard: skip processAudioBlock during terminate+reload teardown to avoid UAF/hang when reopening GUI - Wait for editor registry cleanup (5s timeout) before creating window
50 lines
1.8 KiB
C++
50 lines
1.8 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*/) {}
|
|
|
|
// Real-time Audio PCM Float32 rendering loop
|
|
virtual void processAudioBlock(float* outputL, float* outputR, uint32_t numSamples) = 0;
|
|
};
|
|
|
|
#endif // I_NATIVE_INSTRUMENT_H
|