新增host_param

This commit is contained in:
2024-05-31 11:29:31 +08:00
parent 2fede28c58
commit 5153256907
5 changed files with 84 additions and 4 deletions

View File

@@ -0,0 +1,26 @@
//
// Created by Nanako on 24-5-30.
//
#include "host_param.h"
#include "plugin_host.h"
host_param::host_param(plugin_host* host, int32_t index) : host_(host), index_(index)
{
is_valid_= host->is_param_index_valid(index_);
}
void host_param::set_value(float in_value)
{
if (!is_valid())
return;
host_->set_param_value(index_, in_value);
}
float host_param::get_value() const
{
if (!is_valid())
return 0;
return host_->get_param_value(index_);
}

View File

@@ -0,0 +1,25 @@
#pragma once
#include "extern.h"
#include <string>
class plugin_host;
class CORE_API host_param
{
public:
host_param(plugin_host* host, int32_t index);
[[nodiscard]] int32_t get_index() const { return index_; }
[[nodiscard]] const std::string& get_name() const { return name_; }
[[nodiscard]] bool is_valid() const { return is_valid_; }
void set_value(float in_value);
[[nodiscard]] float get_value() const;
explicit operator bool() const {
return is_valid();
}
private:
int32_t index_ = -1;
std::string name_;
plugin_host* host_;
bool is_valid_ = false;
};

View File

@@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include "extern.h"
#include "host_param.h"
#include "audio/misc/circular_audio_buffer.h"
#include "misc/delegates.h"
@@ -38,7 +39,11 @@ public:
[[nodiscard]] virtual std::string load_name() const { return ""; }
[[nodiscard]] virtual std::string load_vendor() const { return ""; }
virtual std::string get_parameter_name(int index) const { return ""; }
[[nodiscard]] virtual std::string get_parameter_name(int index) const = 0;
[[nodiscard]] virtual int32_t get_param_count() const = 0;
[[nodiscard]] virtual bool is_param_index_valid(const int32_t index) const { return index >= 0 && index < get_param_count(); }
virtual void set_param_value(int32_t index, float value) = 0;
virtual float get_param_value(int32_t index) = 0;
void init_channel_interface();
@@ -48,6 +53,7 @@ public:
std::vector<mixer_track*> owner_tracks;
bool editor_opened = false;
std::shared_ptr<circular_buffer_vector_type> ui_buffers;
multicast_delegate<void(int32_t index, float value)> on_param_changed;
protected:
void create_and_open_editor();
void destroy_editor();

View File

@@ -278,7 +278,27 @@ VstIntPtr vst2_plugin_host::dispatch(VstInt32 opcode, VstInt32 index, VstIntPtr
}
std::string vst2_plugin_host::get_parameter_name(int index) const {
char buffer[256];
dispatch(effGetParamName, index, 0, buffer);
char buffer[kVstMaxParamStrLen];
dispatch(effGetParamDisplay, index, 0, buffer);
return buffer;
}
int32_t vst2_plugin_host::get_param_count() const
{
if (!effect_)
return 0;
return effect_->numParams;
}
void vst2_plugin_host::set_param_value(int32_t index, float value)
{
if (effect_)
effect_->setParameter(effect_, index, value);
}
float vst2_plugin_host::get_param_value(int32_t index)
{
if (!effect_)
return 0;
return effect_->getParameter(effect_, index);
}

View File

@@ -26,7 +26,10 @@ public:
[[nodiscard]] bool has_editor() const override;
void get_editor_size(uint32_t& width, uint32_t& height) const override;
// [[nodiscard]] ImVec2 get_editor_size() const override;
std::string get_parameter_name(int index) const override;
[[nodiscard]] std::string get_parameter_name(int index) const override;
[[nodiscard]] int32_t get_param_count() const override;
void set_param_value(int32_t index, float value) override;
float get_param_value(int32_t index) override;
[[nodiscard]] std::string load_name() const override;
[[nodiscard]] std::string load_vendor() const override;