Skip to content

Commit

Permalink
[nodes] Add a mono merger node
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 2, 2024
1 parent 3e16fc5 commit 3986dc5
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/ossia/dataflow/nodes/merger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,60 @@

namespace ossia::nodes
{
class mono_merger final : public ossia::graph_node
{
int m_count{};

public:
explicit mono_merger(int count)
: m_count{count}
{
for(int i = 0; i < count; i++)
{
auto inl = new ossia::audio_inlet;
inl->target<ossia::audio_port>()->set_channels(1);
m_inlets.push_back(std::move(inl));
}

m_outlets.push_back(new ossia::audio_outlet);
m_outlets.back()->target<ossia::audio_port>()->set_channels(count);
}

~mono_merger() override = default;

void run(const ossia::token_request& t, ossia::exec_state_facade e) noexcept override
{
auto& op = *m_outlets.back()->target<ossia::audio_port>();
op.set_channels(this->m_count);
auto& out = op.get();
std::size_t cur = 0;
for(int i = 0; i < m_count; i++)
{
auto& in = m_inlets[i]->target<ossia::audio_port>()->get();

if(in.size() > 0)
out[cur++] = in[0];
else
out[cur++].resize(e.bufferSize());
}

for(auto& c : out)
{
if(c.size() < e.bufferSize())
{
c.resize(e.bufferSize());
}
}
}

[[nodiscard]] std::string label() const noexcept override { return "Mono Merger"; }
};
class merger final : public ossia::graph_node
{
int m_count{};

public:
merger(int count)
explicit merger(int count)
: m_count{count}
{
for(int i = 0; i < count; i++)
Expand Down

0 comments on commit 3986dc5

Please sign in to comment.