#include "channel_interface.h" #include "channel_node.h" #include "mixer.h" channel_interface::channel_interface(uint32_t input_channels, uint32_t output_channels) { const uint32_t input_node_num = input_channels / 2; const uint32_t output_node_num = output_channels / 2; null_channel_node* null_node = null_channel_node::get(); input_headers_.resize(input_channels); output_headers_.resize(output_channels); for (int i = 0; i < input_node_num; ++i) { input_channel_nodes.push_back(null_node); set_input_channel(i, null_node); } for (int i = 0; i < output_node_num; ++i) { output_channel_nodes.push_back(null_node); set_output_channel(i, null_node); } } void channel_interface::set_input_channel(uint32_t node_index, channel_node* node) { if (node_index >= input_channel_nodes.size()) return; input_channel_nodes[node_index] = node; const auto& node_headers = node->get_channel_headers(); input_headers_[node_index * 2] = node_headers[0]; input_headers_[node_index * 2 + 1] = node_headers[1]; g_mixer.request_build_process_node(); } void channel_interface::set_input_channel(const std::vector& nodes, uint32_t start_index) { const uint32_t input_num = std::min(nodes.size() - start_index, input_channel_nodes.size()); for (uint32_t i = 0; i < input_num; ++i) { set_input_channel(i + start_index, nodes[i]); } } void channel_interface::set_output_channel(uint32_t node_index, channel_node* node) { if (node_index >= output_channel_nodes.size()) return; output_channel_nodes[node_index] = node; const auto& node_headers = node->get_channel_headers(); output_headers_[node_index * 2] = node_headers[0]; output_headers_[node_index * 2 + 1] = node_headers[1]; g_mixer.request_build_process_node(); } void channel_interface::set_output_channel(const std::vector& nodes, uint32_t start_index) { const uint32_t output_num = std::min(nodes.size() - start_index, output_channel_nodes.size()); for (uint32_t i = 0; i < output_num; ++i) { set_output_channel(i + start_index, nodes[i]); } } uint32_t channel_interface::get_input_node_index(channel_node* node) { for (int i = 0; i < input_channel_nodes.size(); ++i) { if (input_channel_nodes[i] == node) return i; } return -1; } uint32_t channel_interface::get_output_node_index(channel_node* node) { for (int i = 0; i < output_channel_nodes.size(); ++i) { if (output_channel_nodes[i] == node) return i; } return -1; } void channel_interface::set_input_channel_node_name(uint32_t node_index, uint32_t channel_index, const std::string& name) { input_channel_names_[node_index][channel_index] = name; } void channel_interface::set_output_channel_node_name(uint32_t node_index, uint32_t channel_index, const std::string& name) { output_channel_names_[node_index][channel_index] = name; } std::unordered_map channel_interface::get_input_channel_node_name(uint32_t node_index) { return input_channel_names_[node_index]; } std::unordered_map channel_interface::get_input_channel_node_name(channel_node* node) { uint32_t index = get_input_node_index(node); if (index == -1) return {}; return get_input_channel_node_name(index); } std::unordered_map channel_interface::get_output_channel_node_name(uint32_t node_index) { return output_channel_names_[node_index]; } std::unordered_map channel_interface::get_output_channel_node_name(channel_node* node) { uint32_t index = get_output_node_index(node); if (index == -1) return {}; return get_output_channel_node_name(index); } void channel_interface::remove_track(mixer_track* track) { for (int i = 0; i < input_channel_nodes.size(); ++i) { if (input_channel_nodes[i]->type == channel_node_type::mixer) { auto mixer_node = static_cast(input_channel_nodes[i]); if (mixer_node->get_track() == track) { set_input_channel(i, null_channel_node::get()); } } } for (int i = 0; i < output_channel_nodes.size(); ++i) { if (output_channel_nodes[i]->type == channel_node_type::mixer) { auto mixer_node = static_cast(output_channel_nodes[i]); if (mixer_node->get_track() == track) { set_output_channel(i, null_channel_node::get()); } } } } mixer_channel_interface::mixer_channel_interface(mixer_track* track) : channel_interface(0, 2), track_(track) { node_ = get_pool_obj(this, track, 0); set_output_channel(0, node_); } mixer_channel_interface::~mixer_channel_interface() { free_pool_obj(node_); }