sfizz/plugins/vst/SfizzVstEditor.h

86 lines
2.6 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
#include "SfizzVstController.h"
2020-08-29 04:54:18 +02:00
#include "editor/EditorController.h"
2020-03-05 11:16:47 +01:00
#include "public.sdk/source/vst/vstguieditor.h"
2021-04-27 17:38:48 +02:00
#include "public.sdk/source/common/threadchecker.h"
2021-02-04 02:48:49 +01:00
#include <absl/types/span.h>
2020-11-24 07:24:24 +01:00
#include <mutex>
2021-04-27 17:38:48 +02:00
#include <set>
2020-08-29 04:54:18 +02:00
class Editor;
2020-03-12 00:41:35 +01:00
#if !defined(__APPLE__) && !defined(_WIN32)
namespace VSTGUI { class RunLoop; }
#endif
2020-03-05 11:16:47 +01:00
using namespace Steinberg;
using namespace VSTGUI;
2020-10-19 02:58:01 +02:00
class SfizzVstEditor : public Vst::VSTGUIEditor,
2021-02-04 02:48:49 +01:00
public EditorController {
2020-03-05 11:16:47 +01:00
public:
2020-12-11 07:21:33 +01:00
using Self = SfizzVstEditor;
2021-04-28 17:19:42 +02:00
SfizzVstEditor(SfizzVstController* controller, absl::Span<FObject*> updates);
2020-03-05 11:16:47 +01:00
~SfizzVstEditor();
2021-04-08 04:43:53 +02:00
bool PLUGIN_API open(void* parent, const VSTGUI::PlatformType& platformType) override;
2020-03-05 11:16:47 +01:00
void PLUGIN_API close() override;
2020-03-05 18:21:46 +01:00
SfizzVstController* getController() const
{
return static_cast<SfizzVstController*>(Vst::VSTGUIEditor::getController());
}
2021-04-14 06:36:17 +02:00
void updateEditorIsOpenParameter();
2020-03-12 00:41:35 +01:00
// VSTGUIEditor
CMessageResult notify(CBaseObject* sender, const char* message) override;
2021-02-04 02:48:49 +01:00
// FObject
void PLUGIN_API update(FUnknown* changedUnknown, int32 message) override;
2020-03-12 00:41:35 +01:00
2020-11-24 07:24:24 +01:00
//
2020-11-24 08:24:39 +01:00
private:
2021-04-28 17:19:42 +02:00
bool processUpdate(FUnknown* changedUnknown, int32 message);
2021-04-27 17:38:48 +02:00
void processParameterUpdates();
void updateParameter(Vst::Parameter* parameterToUpdate);
2020-12-07 09:41:36 +01:00
2020-08-29 04:54:18 +02:00
protected:
// EditorController
void uiSendValue(EditId id, const EditValue& v) override;
void uiBeginSend(EditId id) override;
void uiEndSend(EditId id) override;
2020-10-14 20:04:59 +02:00
void uiSendMIDI(const uint8_t* data, uint32_t len) override;
2020-10-19 02:58:01 +02:00
void uiSendMessage(const char* path, const char* sig, const sfizz_arg_t* args) override;
2020-08-29 04:54:18 +02:00
2020-03-05 11:16:47 +01:00
private:
void loadSfzFile(const std::string& filePath);
2020-06-20 05:49:00 +02:00
void loadScalaFile(const std::string& filePath);
2020-08-29 04:54:18 +02:00
Vst::ParamID parameterOfEditId(EditId id);
2020-03-12 00:41:35 +01:00
2020-08-29 04:54:18 +02:00
std::unique_ptr<Editor> editor_;
2020-08-12 19:23:50 +02:00
2020-03-12 00:41:35 +01:00
#if !defined(__APPLE__) && !defined(_WIN32)
SharedPointer<RunLoop> _runLoop;
#endif
2020-10-19 02:58:01 +02:00
// messaging
std::unique_ptr<uint8[]> oscTemp_;
2020-11-24 07:24:24 +01:00
2021-02-04 02:48:49 +01:00
// subscribed updates
2021-04-28 17:19:42 +02:00
std::vector<IPtr<FObject>> updates_;
2021-04-27 17:38:48 +02:00
// thread safety
std::unique_ptr<Vst::ThreadChecker> threadChecker_;
// parameters to process, whose values have received changes
// Note(jpc) it's because hosts send us parameter updates in the wrong thread..
std::set<Vst::ParamID> parametersToUpdate_;
std::mutex parametersToUpdateMutex_;
2020-03-05 11:16:47 +01:00
};