sfizz/vst/SfizzVstProcessor.h

67 lines
2.2 KiB
C
Raw Normal View History

2020-03-05 11:16:47 +01:00
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
2020-03-05 18:21:46 +01:00
#include "SfizzVstState.h"
#include "RTSemaphore.h"
2020-03-05 11:16:47 +01:00
#include "public.sdk/source/vst/vstaudioeffect.h"
#include "public.sdk/source/vst/utility/ringbuffer.h"
#include <sfizz.hpp>
#include <thread>
#include <mutex>
#include <memory>
using namespace Steinberg;
class SfizzVstProcessor : public Vst::AudioEffect {
public:
SfizzVstProcessor();
~SfizzVstProcessor();
tresult PLUGIN_API initialize(FUnknown* context) override;
tresult PLUGIN_API setBusArrangements(Vst::SpeakerArrangement* inputs, int32 numIns, Vst::SpeakerArrangement* outputs, int32 numOuts) override;
2020-03-05 18:21:46 +01:00
tresult PLUGIN_API setState(IBStream* stream) override;
tresult PLUGIN_API getState(IBStream* stream) override;
void syncStateToSynth();
2020-03-05 11:16:47 +01:00
tresult PLUGIN_API canProcessSampleSize(int32 symbolicSampleSize) override;
tresult PLUGIN_API setActive(TBool state) override;
tresult PLUGIN_API process(Vst::ProcessData& data) override;
2020-03-05 18:21:46 +01:00
void processParameterChanges(Vst::IParameterChanges& pc);
void processControllerChanges(Vst::IParameterChanges& pc);
void processEvents(Vst::IEventList& events);
static int convertVelocityFromFloat(float x);
2020-03-05 11:16:47 +01:00
tresult PLUGIN_API notify(Vst::IMessage* message) override;
static FUnknown* createInstance(void*);
static FUID cid;
// --- Sfizz stuff here below ---
private:
2020-03-05 18:21:46 +01:00
// synth state. acquire processMutex before accessing
2020-03-05 11:16:47 +01:00
std::unique_ptr<sfz::Sfizz> _synth;
2020-03-05 18:21:46 +01:00
SfizzVstState _state;
// worker and thread sync
2020-03-05 11:16:47 +01:00
std::thread _worker;
volatile bool _workRunning = false;
Steinberg::OneReaderOneWriter::RingBuffer<Vst::IMessage*> _fifoToWorker;
RTSemaphore _semaToWorker;
std::mutex _processMutex;
// file modification periodic checker
uint32 _fileChangeCounter = 0;
uint32 _fileChangePeriod = 0;
IPtr<Vst::IMessage> _msgCheckShouldReload;
2020-03-05 11:16:47 +01:00
// worker
void doBackgroundWork();
void stopBackgroundWork();
};