83 lines
2.7 KiB
C++
83 lines
2.7 KiB
C++
#include "mixer_track.h"
|
|
|
|
#include "channel_interface.h"
|
|
#include "audio/device/audio_device_manager.h"
|
|
#include "audio/plugin_host/plugin_host.h"
|
|
#include "audio/plugin_host/plugin_host_manager.h"
|
|
#include "thread_message/thread_message_hubs.h"
|
|
|
|
mixer_track::~mixer_track() {
|
|
free_pool_obj(channel_interface_);
|
|
for (auto e : effects_) {
|
|
// e->on_latency_changed.remove_all(this);
|
|
get_plugin_host_manager()->remove_effect_plugin_host(e);
|
|
}
|
|
}
|
|
|
|
void mixer_track::init() {
|
|
const uint32_t channel_count = g_audio_device_manager.get_output_channel_count();
|
|
uint32_t block_size = g_audio_device_manager.get_buffer_size();
|
|
buffer_.resize(channel_count, block_size);
|
|
|
|
ui_buffers_.resize(channel_count);
|
|
for (auto& buffer : ui_buffers_) {
|
|
buffer.set_capacity(block_size * 2);
|
|
}
|
|
|
|
channel_interface_ = get_pool_obj<mixer_channel_interface>(this);
|
|
}
|
|
|
|
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);
|
|
});
|
|
}
|
|
|
|
void mixer_track::remove_effect(plugin_host* in_effect) {
|
|
in_effect->try_close_editor();
|
|
g_audio_thread_hub.push_message([in_effect, this] {
|
|
const auto f = std::ranges::find(effects_, in_effect);
|
|
effects_.erase(f);
|
|
});
|
|
get_plugin_host_manager()->remove_effect_plugin_host(in_effect);
|
|
}
|
|
|
|
void mixer_track::process(uint32_t in_frames) {
|
|
for (auto effect : effects_) effect->process(in_frames);
|
|
buffer_.multiple(get_volume());
|
|
}
|
|
|
|
auto mixer_track::get_latency() const -> int32_t {
|
|
int32_t latency = 0;
|
|
for (const auto effect : effects_) {
|
|
latency += effect->get_latency();
|
|
}
|
|
return latency;
|
|
}
|
|
|
|
void mixer_track::push_ui_buffer(const audio_buffer& in_buffer) {
|
|
auto headers = in_buffer.get_headers_vector();
|
|
for (const auto& header : std::ranges::views::zip(headers, ui_buffers_)) {
|
|
const auto& [in, out] = header;
|
|
out.push(in, in_buffer.get_num_samples());
|
|
}
|
|
}
|
|
|
|
instrument_track::instrument_track(plugin_host* in_instrument): mixer_track(type)
|
|
, instrument_(in_instrument) {}
|
|
|
|
void instrument_track::rename(const std::string& in_name) {
|
|
instrument_->name = in_name;
|
|
}
|
|
|
|
auto instrument_track::get_name() const -> std::string {
|
|
return instrument_->name;
|
|
}
|
|
|
|
auto instrument_track::get_latency() const -> int32_t {
|
|
return mixer_track::get_latency() + instrument_->get_latency() + instrument_->get_user_latency();
|
|
}
|