sfizz/plugins/vst/SfizzVstEditor.h

89 lines
2.7 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-02-04 02:48:49 +01:00
#include <absl/types/span.h>
2020-11-24 07:24:24 +01:00
#include <mutex>
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-02-04 02:48:49 +01:00
SfizzVstEditor(
SfizzVstController* controller,
absl::Span<FObject*> continuousUpdates,
absl::Span<FObject*> triggerUpdates);
2020-03-05 11:16:47 +01:00
~SfizzVstEditor();
bool PLUGIN_API open(void* parent, const VSTGUI::PlatformType& platformType = VSTGUI::kDefaultNative) override;
void PLUGIN_API close() override;
2020-03-05 18:21:46 +01:00
SfizzVstController* getController() const
{
return static_cast<SfizzVstController*>(Vst::VSTGUIEditor::getController());
}
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
//
void updateState(const SfizzVstState& state);
void updatePlayState(const SfizzPlayState& playState);
2020-12-11 07:21:33 +01:00
2020-11-24 08:24:39 +01:00
private:
void processOscQueue();
2021-02-23 09:27:20 +01:00
void processNoteEventQueue();
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
// editor state
// note: might be updated from a non-UI thread
2020-12-07 09:41:36 +01:00
typedef std::vector<uint8_t> OscByteVec;
std::unique_ptr<OscByteVec> oscQueue_;
2021-02-04 02:48:49 +01:00
std::mutex oscQueueMutex_;
2021-02-23 09:27:20 +01:00
typedef std::vector<std::pair<uint32, float>> NoteEventsVec;
std::unique_ptr<NoteEventsVec> noteEventQueue_;
std::mutex noteEventQueueMutex_;
2021-02-04 02:48:49 +01:00
// subscribed updates
std::vector<IPtr<FObject>> continuousUpdates_;
std::vector<IPtr<FObject>> triggerUpdates_;
2020-03-05 11:16:47 +01:00
};