创建plugin_host时注册mixer_track
This commit is contained in:
parent
97286e1265
commit
9ba3592e27
@ -10,14 +10,13 @@ window_manager::window_manager() {
|
||||
|
||||
void window_manager::init(singleton_initliazer& initliazer) {
|
||||
singleton_t<window_manager>::init(initliazer);
|
||||
start_idle_thread();
|
||||
// start_idle_thread();
|
||||
}
|
||||
|
||||
void window_manager::release() {
|
||||
singleton_t<window_manager>::release();
|
||||
if (main_window_)
|
||||
glfwDestroyWindow(main_window_);
|
||||
stop_idle_thread();
|
||||
}
|
||||
|
||||
void window_manager::tick() {
|
||||
@ -72,25 +71,6 @@ void window_manager::idle_plugin_host_window() const {
|
||||
}
|
||||
}
|
||||
|
||||
void window_manager::start_idle_thread() {
|
||||
idle_thread_ = std::thread(&window_manager::idle_thread_func, this);
|
||||
idle_thread_.detach();
|
||||
}
|
||||
|
||||
void window_manager::stop_idle_thread() {
|
||||
idle_thread_running_ = false;
|
||||
if (idle_thread_.joinable())
|
||||
idle_thread_.join();
|
||||
}
|
||||
|
||||
void window_manager::idle_thread_func() {
|
||||
idle_thread_running_ = true;
|
||||
while (idle_thread_running_) {
|
||||
idle_plugin_host_window();
|
||||
std::this_thread::yield();
|
||||
}
|
||||
}
|
||||
|
||||
void window_manager::update_host_window() {
|
||||
std::vector<plugin_host*> host_editor_to_close;
|
||||
for (const auto& [host, window]: host_window_map_) {
|
||||
@ -103,4 +83,5 @@ void window_manager::update_host_window() {
|
||||
for (auto host: host_editor_to_close) {
|
||||
host_window_map_.erase(host);
|
||||
}
|
||||
idle_plugin_host_window();
|
||||
}
|
||||
|
@ -26,14 +26,6 @@ public:
|
||||
const char* get_name() override { return "window_manager"; }
|
||||
private:
|
||||
|
||||
#pragma region idle_thread
|
||||
void start_idle_thread();
|
||||
void stop_idle_thread();
|
||||
void idle_thread_func();
|
||||
std::thread idle_thread_;
|
||||
std::atomic_bool idle_thread_running_;
|
||||
#pragma endregion
|
||||
|
||||
void update_host_window();
|
||||
|
||||
GLFWwindow* main_window_;
|
||||
|
@ -25,5 +25,5 @@ protected:
|
||||
virtual bool on_set_buffer_size(uint32_t in_buffer_size) = 0;
|
||||
private:
|
||||
double sample_rate_ = 44100;
|
||||
uint32_t buffer_size_ = 512;
|
||||
uint32_t buffer_size_ = 2048;
|
||||
};
|
||||
|
@ -74,7 +74,7 @@ int port_audio_device::stream_callback(float** input, float** output, unsigned l
|
||||
if (render_buffer_.Num() < frame_count * output_params_.channelCount)
|
||||
return paContinue;
|
||||
for (int i = 0; i < output_params_.channelCount; ++i) {
|
||||
render_buffer_.Pop(input[i], frame_count);
|
||||
render_buffer_.Pop(output[i], frame_count);
|
||||
}
|
||||
return paContinue;
|
||||
}
|
||||
@ -115,6 +115,7 @@ void port_audio_device::stop_render_thread() {
|
||||
void port_audio_device::render_thread() {
|
||||
dummy_track* master = g_mixer.get_master();
|
||||
spdlog::info("port_audio render thread started");
|
||||
render_buffer_.SetCapacity(buffer_size() * 4);
|
||||
while (stream_) {
|
||||
const uint32_t frames = buffer_size();
|
||||
const double rate = sample_rate();
|
||||
|
@ -10,9 +10,9 @@ public:
|
||||
virtual ~channel_interface() = default;
|
||||
|
||||
void set_input_channel(uint32_t node_index, channel_node* node);
|
||||
void set_input_channel(const std::vector<channel_node*>& nodes, uint32_t start_index);
|
||||
void set_input_channel(const std::vector<channel_node*>& nodes, uint32_t start_index = 0);
|
||||
void set_output_channel(uint32_t node_index, channel_node* node);
|
||||
void set_output_channel(const std::vector<channel_node*>& nodes, uint32_t start_index);
|
||||
void set_output_channel(const std::vector<channel_node*>& nodes, uint32_t start_index = 0);
|
||||
|
||||
uint32_t get_input_node_index(channel_node* node);
|
||||
uint32_t get_output_node_index(channel_node* node);
|
||||
|
@ -99,9 +99,9 @@ dummy_track* mixer::create_dummy_track(const std::string& in_name) {
|
||||
return track;
|
||||
}
|
||||
|
||||
instrument_track* mixer::create_instrument_track(const std::string& in_name) {
|
||||
auto* track = new instrument_track();
|
||||
track->rename(in_name);
|
||||
instrument_track* mixer::create_instrument_track(plugin_host* in_instrument) {
|
||||
auto* track = new instrument_track(in_instrument);
|
||||
track->rename(in_instrument->name);
|
||||
track->init();
|
||||
|
||||
mixer_track_link link{};
|
||||
@ -138,6 +138,8 @@ void mixer::process(uint32_t in_frames) {
|
||||
}
|
||||
executor.run(taskflow).wait();
|
||||
post_process(in_frames);
|
||||
dummy_track* master = get_master();
|
||||
master->buffer.multiple(master->volume);
|
||||
}
|
||||
|
||||
void mixer::reset() {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
class plugin_host;
|
||||
class channel_interface;
|
||||
class instrument_track;
|
||||
class mixer_track;
|
||||
@ -18,7 +19,7 @@ public:
|
||||
const char* get_name() override { return "mixer"; }
|
||||
|
||||
dummy_track* create_dummy_track(const std::string& in_name);
|
||||
instrument_track* create_instrument_track(const std::string& in_name);
|
||||
instrument_track* create_instrument_track(plugin_host* in_instrument);
|
||||
void remove_track(mixer_track* track);
|
||||
|
||||
void process(uint32_t in_frames);
|
||||
|
@ -17,7 +17,6 @@ void mixer_track::init() {
|
||||
|
||||
void mixer_track::add_effect(plugin_host* in_effect) {
|
||||
in_effect->owner_tracks.push_back(this);
|
||||
|
||||
}
|
||||
|
||||
void mixer_track::remove_effect(plugin_host* in_effect) {
|
||||
|
@ -50,7 +50,7 @@ private:
|
||||
|
||||
class instrument_track : public mixer_track {
|
||||
public:
|
||||
instrument_track() : mixer_track(mixer_track_type::instrument) {}
|
||||
instrument_track(plugin_host* in_instrument) : mixer_track(mixer_track_type::instrument), instrument_(in_instrument) {}
|
||||
|
||||
void rename(const std::string& in_name) override;
|
||||
[[nodiscard]] std::string get_name() const override;
|
||||
|
@ -5,7 +5,9 @@
|
||||
#include "plugin_host.h"
|
||||
#include "audio/mixer/channel_interface.h"
|
||||
#include "audio/mixer/mixer.h"
|
||||
#include "audio/mixer/mixer_track.h"
|
||||
#include "misc/singleton/singleton_manager.h"
|
||||
#include "thread_message/thread_message_hubs.h"
|
||||
#include "vst2/vst2_plugin_host.h"
|
||||
|
||||
void plugin_host_manager::init(singleton_initliazer& initliazer) {
|
||||
@ -24,8 +26,14 @@ plugin_host* plugin_host_manager::load_plugin(const char* path) {
|
||||
return nullptr;
|
||||
}
|
||||
host->init_channel_interface();
|
||||
plugin_hosts_.push_back(host);
|
||||
host->try_open_editor();
|
||||
g_audio_thread_hub.push_message([this, host]() {
|
||||
instrument_track* instrument_track = g_mixer.create_instrument_track(host);
|
||||
host->channel->set_input_channel(instrument_track->get_channel_interface()->input_channel_nodes);
|
||||
host->channel->set_output_channel(instrument_track->get_channel_interface()->output_channel_nodes);
|
||||
host->owner_tracks.push_back(instrument_track);
|
||||
plugin_hosts_.push_back(host);
|
||||
});
|
||||
return host;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user