From 2307a196df62a0467f2640405cc7d80d3a9bc6fe Mon Sep 17 00:00:00 2001 From: Nanako <469449812@qq.com> Date: Wed, 3 Apr 2024 16:44:46 +0800 Subject: [PATCH] =?UTF-8?q?mixer=5Ftrack=E6=96=B0=E5=A2=9Eadd=5Feffect?= =?UTF-8?q?=E5=92=8Cremove=5Feffect=E4=BB=A3=E7=90=86,=20=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0spdlog=E5=92=8Ctaskflow=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/audio/mixer/mixer.cpp | 15 +++++---------- core/audio/mixer/mixer_track.cpp | 13 +++++++++++-- core/audio/mixer/mixer_track.h | 2 ++ third_party/spdlog | 2 +- third_party/taskflow | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/core/audio/mixer/mixer.cpp b/core/audio/mixer/mixer.cpp index 8f0e4b7..ecfc5c3 100644 --- a/core/audio/mixer/mixer.cpp +++ b/core/audio/mixer/mixer.cpp @@ -14,8 +14,7 @@ void build_effect_channel_interface(mixer_track* track, const channel_interface* auto& input_channel_nodes = in_interface->input_channel_nodes; auto& output_channel_nodes = in_interface->output_channel_nodes; // 如果这个效果器需要从其他轨道输入,那么目标轨道的深度就是这个轨道的深度+1 - for (int i = 1; i < input_channel_nodes.size(); ++i) - { + for (int i = 1; i < input_channel_nodes.size(); ++i) { channel_node* node = input_channel_nodes[i]; if (node->type != channel_node_type::mixer) continue; @@ -26,8 +25,7 @@ void build_effect_channel_interface(mixer_track* track, const channel_interface* } // 如果这个效果器需要输出到其他轨道,那么这个轨道的深度就是目标轨道的深度+1 - for (int i = 1; i < output_channel_nodes.size(); ++i) - { + for (int i = 1; i < output_channel_nodes.size(); ++i) { auto* node = output_channel_nodes[i]; if (node->type != channel_node_type::mixer) continue; @@ -41,12 +39,10 @@ void build_effect_channel_interface(mixer_track* track, const channel_interface* int32_t build_process_node_internal(mixer_track* track, std::map& processed_tracks, int32_t layer) { int32_t& track_current_layer = processed_tracks[track]; track_current_layer = std::max(track_current_layer, layer); - for (const mixer_track_link& child_link: track->children) - { + for (const mixer_track_link& child_link: track->children) { mixer_track* ChildTrack = child_link.track; build_process_node_internal(ChildTrack, processed_tracks, layer + 1); - for (const plugin_host* effect: ChildTrack->effects) - { + for (const plugin_host* effect: ChildTrack->effects) { build_effect_channel_interface(ChildTrack, effect->channel, processed_tracks); } } @@ -54,8 +50,7 @@ int32_t build_process_node_internal(mixer_track* track, std::map& processed_tracks) { - for (mixer_track* Track : host->owner_tracks) - { + for (mixer_track* Track : host->owner_tracks) { build_effect_channel_interface(Track, host->channel, processed_tracks); } } diff --git a/core/audio/mixer/mixer_track.cpp b/core/audio/mixer/mixer_track.cpp index 68c2490..320d8a6 100644 --- a/core/audio/mixer/mixer_track.cpp +++ b/core/audio/mixer/mixer_track.cpp @@ -3,6 +3,7 @@ #include "channel_interface.h" #include "audio/device/audio_device_manager.h" #include "audio/plugin_host/plugin_host.h" +#include "thread_message/thread_message_hubs.h" mixer_track::~mixer_track() { @@ -19,11 +20,19 @@ void mixer_track::init() { } void mixer_track::add_effect(plugin_host* in_effect) { - in_effect->owner_tracks.push_back(this); + g_audio_thread_hub.push_message([in_effect, this] { + in_effect->owner_tracks.push_back(this); + g_main_thread_hub.push_message([in_effect, this] { + on_add_effect.broadcast(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()); + }); } void mixer_track::add_child(mixer_track* in_child, float in_send_level) { diff --git a/core/audio/mixer/mixer_track.h b/core/audio/mixer/mixer_track.h index 865a9fb..f683645 100644 --- a/core/audio/mixer/mixer_track.h +++ b/core/audio/mixer/mixer_track.h @@ -46,6 +46,8 @@ public: std::vector effects{}; std::vector children{}; multicast_delegate on_processed; + multicast_delegate on_add_effect; + multicast_delegate on_remove_effect; private: void add_effect_internal(plugin_host* in_effect); const mixer_track_type type_; diff --git a/third_party/spdlog b/third_party/spdlog index a627f5c..f0b96d2 160000 --- a/third_party/spdlog +++ b/third_party/spdlog @@ -1 +1 @@ -Subproject commit a627f5c43a81b2f155f8b06b18c3ea345f1c826b +Subproject commit f0b96d2ad105bbcde2130851e7bb0c033d66ec2f diff --git a/third_party/taskflow b/third_party/taskflow index 10dfa79..1b6cf17 160000 --- a/third_party/taskflow +++ b/third_party/taskflow @@ -1 +1 @@ -Subproject commit 10dfa7920d1a786099a92614c4183f6339975728 +Subproject commit 1b6cf17bb37741103a67cb3698066b6b80def2e0