mixer_track效果器

This commit is contained in:
Nanako 2024-06-04 13:52:38 +08:00
parent 5153256907
commit 1b4ee22c95
10 changed files with 69 additions and 11 deletions

View File

@ -29,6 +29,9 @@ void audio_device_manager::init(singleton_initliazer& initliazer) {
output_params_.nChannels = get_output_channel_count();
output_params_.firstChannel = 0;
buffer_size_ = 512;
#if USE_DOUBLE_SAMPLE
spdlog::info("using double sample");
#endif
}
void audio_device_manager::release(singleton_release_guard& release_guard) {
@ -152,13 +155,13 @@ void audio_device_manager::render_thread() {
for (auto& render_buffer : render_buffers_)
render_buffer.SetCapacity(frames * 3);
while (!render_thread_should_stop_) {
// const float milliseconds = 1.f / (rate / (frames / 4)) * 1e4;
const float milliseconds = frames / rate * 1000; // 512 / 48000
while (!render_thread_should_stop_) {
g_audio_thread_hub.process_messages();
if (render_buffers_[0].Remainder() < frames) {
// std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<uint64_t>(milliseconds)));
std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<uint64_t>(milliseconds)));
// std::this_thread::yield();
continue;
}
g_midi_sequencer.process(rate, frames);

View File

@ -8,6 +8,9 @@
mixer_track::~mixer_track() {
delete channel_interface_;
channel_interface_ = nullptr;
for (auto e : effects) {
delete_effect(this, e);
}
}
void mixer_track::init() {
@ -23,6 +26,9 @@ void mixer_track::init() {
void mixer_track::add_effect(plugin_host* in_effect) {
g_audio_thread_hub.push_message([in_effect, this] {
in_effect->owner_tracks.push_back(this);
in_effect->channel->set_input_channel(channel_interface_->output_channel_nodes);
in_effect->channel->set_output_channel(channel_interface_->output_channel_nodes);
effects.push_back(in_effect);
g_main_thread_hub.push_message([in_effect, this] {
on_add_effect.broadcast(in_effect);
});
@ -32,7 +38,11 @@ void mixer_track::add_effect(plugin_host* in_effect) {
void mixer_track::remove_effect(plugin_host* in_effect) {
on_remove_effect.broadcast(in_effect);
g_audio_thread_hub.push_message([in_effect, this] {
in_effect->owner_tracks.erase(std::remove(in_effect->owner_tracks.begin(), in_effect->owner_tracks.end(), this), in_effect->owner_tracks.end());
auto remove_effect_track = std::remove(in_effect->owner_tracks.begin(), in_effect->owner_tracks.end(), this);
in_effect->owner_tracks.erase(remove_effect_track, in_effect->owner_tracks.end());
auto remove_effect = std::remove(effects.begin(), effects.end(), in_effect);
effects.erase(remove_effect, effects.end());
});
}
@ -69,3 +79,10 @@ void instrument_track::rename(const std::string& in_name) {
std::string instrument_track::get_name() const {
return instrument_->name;
}
void delete_effect(mixer_track* track, plugin_host* host) {
track->remove_effect(host);
g_audio_thread_hub.push_message([host](){
delete host;
});
}

View File

@ -18,7 +18,7 @@ struct mixer_track_link {
float send_level;
};
class mixer_track {
class CORE_API mixer_track {
public:
explicit mixer_track(mixer_track_type in_type) : type_(in_type) {
ui_buffers = std::make_shared<circular_buffer_vector_type>();
@ -80,3 +80,5 @@ public:
private:
std::string name_;
};
CORE_API void delete_effect(mixer_track* track, plugin_host* host);

View File

@ -24,3 +24,15 @@ float host_param::get_value() const
return 0;
return host_->get_param_value(index_);
}
const std::string& host_param::get_name() const {
if (name_.empty())
name_ = host_->get_parameter_name(index_);
return name_;
}
const std::string &host_param::get_label() const {
if (label_.empty())
label_ = host_->get_parameter_label(index_);
return label_;
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "extern.h"
#include <string>
#include <cstdint>
class plugin_host;
@ -9,7 +10,8 @@ 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]] const std::string& get_name() const;
[[nodiscard]] const std::string& get_label() const;
[[nodiscard]] bool is_valid() const { return is_valid_; }
void set_value(float in_value);
[[nodiscard]] float get_value() const;
@ -19,7 +21,8 @@ public:
}
private:
int32_t index_ = -1;
std::string name_;
mutable std::string name_;
mutable std::string label_;
plugin_host* host_;
bool is_valid_ = false;
};

View File

@ -10,6 +10,13 @@
class mixer_track;
class channel_interface;
struct host_param_info {
std::string name;
std::string label;
float min_value;
float max_value;
};
class CORE_API plugin_host {
friend class window_manager;
public:
@ -40,6 +47,7 @@ public:
[[nodiscard]] virtual std::string load_vendor() const { return ""; }
[[nodiscard]] virtual std::string get_parameter_name(int index) const = 0;
[[nodiscard]] virtual std::string get_parameter_label(int index) const { return ""; };
[[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;

View File

@ -30,6 +30,11 @@ void plugin_host_manager::release(singleton_release_guard& release_guard) {
plugin_hosts_.clear();
}
plugin_host *plugin_host_manager::create_effect_plugin_host(const char *path) {
auto host = load_plugin(path);
return host;
}
plugin_host* plugin_host_manager::create_instrument_plugin_host(const char* path) {
auto host = load_plugin(path);
if (host) {

View File

@ -13,6 +13,7 @@ public:
void release(singleton_release_guard& release_guard) override;
plugin_host* create_effect_plugin_host(const char* path);
plugin_host* create_instrument_plugin_host(const char* path);
void remove_instrument_plugin_host(plugin_host* host);

View File

@ -278,8 +278,14 @@ VstIntPtr vst2_plugin_host::dispatch(VstInt32 opcode, VstInt32 index, VstIntPtr
}
std::string vst2_plugin_host::get_parameter_name(int index) const {
char buffer[kVstMaxParamStrLen];
dispatch(effGetParamDisplay, index, 0, buffer);
char buffer[64]{0};
dispatch(effGetParamName, index, 0, buffer);
return buffer;
}
std::string vst2_plugin_host::get_parameter_label(int index) const {
char buffer[64]{0};
dispatch(effGetParamLabel, index, 0, buffer);
return buffer;
}

View File

@ -12,7 +12,7 @@ public:
bool load_plugin(const char* path) override;
void set_enabled(bool enabled) override;
bool is_enabled() const override;
[[nodiscard]] bool is_enabled() const override;
void on_update_sample_rate(double sample_rate) override;
void on_update_buffer_size(int buffer_size) override;
@ -27,6 +27,7 @@ public:
void get_editor_size(uint32_t& width, uint32_t& height) const override;
// [[nodiscard]] ImVec2 get_editor_size() const override;
[[nodiscard]] std::string get_parameter_name(int index) const override;
[[nodiscard]]std::string get_parameter_label(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;