diff --git a/core/audio/misc/circular_audio_buffer.h b/core/audio/misc/circular_audio_buffer.h index 6b360aa..7c0e076 100644 --- a/core/audio/misc/circular_audio_buffer.h +++ b/core/audio/misc/circular_audio_buffer.h @@ -46,10 +46,22 @@ public: } - circular_audio_buffer(uint32_t InCapacity) { + explicit circular_audio_buffer(uint32_t InCapacity) { SetCapacity(InCapacity); } + // move + circular_audio_buffer(circular_audio_buffer&& InOther) noexcept { + InternalBuffer = std::move(InOther.InternalBuffer); + Capacity = InOther.Capacity; + ReadCounter.store(InOther.ReadCounter); + WriteCounter.store(InOther.WriteCounter); + + InOther.Capacity = 0; + InOther.ReadCounter = 0; + InOther.WriteCounter = 0; + } + void Reset(uint32_t InCapacity = 0) { SetCapacity(InCapacity); } @@ -276,5 +288,8 @@ public: } }; +using ui_buffer_type = circular_audio_buffer; +using ui_buffer_vector_type = std::vector; + #undef checkf #undef check \ No newline at end of file diff --git a/core/audio/mixer/mixer_track.h b/core/audio/mixer/mixer_track.h index 7147849..ca55690 100644 --- a/core/audio/mixer/mixer_track.h +++ b/core/audio/mixer/mixer_track.h @@ -20,9 +20,6 @@ struct mixer_track_link { class mixer_track { public: - using ui_buffer_type = circular_audio_buffer; - using ui_buffer_vector_type = std::vector; - explicit mixer_track(mixer_track_type in_type) : type_(in_type) { ui_buffers = std::make_shared(); } diff --git a/core/audio/plugin_host/plugin_host.cpp b/core/audio/plugin_host/plugin_host.cpp index 58d3d00..d1e2204 100644 --- a/core/audio/plugin_host/plugin_host.cpp +++ b/core/audio/plugin_host/plugin_host.cpp @@ -7,6 +7,16 @@ plugin_host::~plugin_host() { delete channel; } +void plugin_host::on_update_buffer_size(int buffer_size) +{ + ui_buffers = std::make_shared(); + for (uint32_t i = 0; i < get_output_channels(); i++) + { + ui_buffer_type buffer(buffer_size * 3); + ui_buffers->emplace_back(std::move(buffer)); + } +} + void plugin_host::try_open_editor() { if (!has_editor()) return; diff --git a/core/audio/plugin_host/plugin_host.h b/core/audio/plugin_host/plugin_host.h index 13f04fd..744077a 100644 --- a/core/audio/plugin_host/plugin_host.h +++ b/core/audio/plugin_host/plugin_host.h @@ -3,6 +3,7 @@ #include #include #include "extern.h" +#include "audio/misc/circular_audio_buffer.h" #include "misc/delegates.h" class mixer_track; @@ -19,7 +20,7 @@ public: [[nodiscard]] virtual bool is_enabled() const = 0; virtual void on_update_sample_rate(double sample_rate) = 0; - virtual void on_update_buffer_size(int buffer_size) = 0; + virtual void on_update_buffer_size(int buffer_size); [[nodiscard]] virtual uint32_t get_input_channels() const = 0; [[nodiscard]] virtual uint32_t get_output_channels() const = 0; virtual void update_channel_node_name() {} @@ -46,6 +47,7 @@ public: channel_interface* channel = nullptr; std::vector owner_tracks; bool editor_opened = false; + std::shared_ptr ui_buffers; protected: void create_and_open_editor(); void destroy_editor(); diff --git a/core/audio/plugin_host/vst2/vst2_plugin_host.cpp b/core/audio/plugin_host/vst2/vst2_plugin_host.cpp index 25ff103..a477cd9 100644 --- a/core/audio/plugin_host/vst2/vst2_plugin_host.cpp +++ b/core/audio/plugin_host/vst2/vst2_plugin_host.cpp @@ -183,6 +183,7 @@ void vst2_plugin_host::on_update_sample_rate(double sample_rate) { } void vst2_plugin_host::on_update_buffer_size(int buffer_size) { + plugin_host::on_update_buffer_size(buffer_size); dispatch(effSetBlockSize, 0, buffer_size); } @@ -217,6 +218,10 @@ void vst2_plugin_host::update_channel_node_name() { void vst2_plugin_host::process(uint32_t frame_num) { // TODO send midi effect_->processReplacing(effect_, channel->get_input_headers(), channel->get_output_headers(), frame_num); + for (int i = 0; i < ui_buffers->size(); ++i) + { + ui_buffers->at(i).Push(channel->get_output_headers()[i], frame_num); + } } void vst2_plugin_host::idle_editor() {