Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions framework/audio/engine/internal/audiofactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ FxChainPtr AudioFactory::makeMasterFxChain(const AudioFxChain& fxChain) const
std::vector<IFxProcessorPtr> fxlist = fxResolver()->resolveMasterFxList(fxChain, audioEngine()->outputSpec());

FxChainPtr chain = std::make_shared<FxChain>();
for (const auto& fx : fxlist) {
chain->add(std::make_shared<FxNode>(fx));
}

chain->setName("FxChain [master]");
chain->setFxList(fxlist);
chain->setFxChainSpec(fxChain);

return chain;
Expand All @@ -96,11 +94,14 @@ FxChainPtr AudioFactory::makeMasterFxChain(const AudioFxChain& fxChain) const
FxChainPtr AudioFactory::makeTrackFxChain(const TrackId trackId, const AudioFxChain& fxChain) const
{
std::vector<IFxProcessorPtr> fxlist = fxResolver()->resolveFxList(trackId, fxChain, audioEngine()->outputSpec());

FxChainPtr chain = std::make_shared<FxChain>();
for (const auto& fx : fxlist) {
chain->add(std::make_shared<FxNode>(fx));
if (trackId == MASTER_TRACK_ID) {
chain->setName("FxChain [master]");
} else {
chain->setName("FxChain [track " + std::to_string(trackId) + "]");
}

chain->setFxList(fxlist);
chain->setFxChainSpec(fxChain);

return chain;
Expand Down
2 changes: 1 addition & 1 deletion framework/audio/engine/internal/nodes/eventaudionode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void EventAudioNode::applyInputParams(const AudioInputParams& requiredParams)
m_synth->setMode(ProcessMode::Idle);
}

setName(std::string("Source[") + m_synth->name() + "] ");
setName(std::string("Source[") + m_synth->name() + "]");

m_params = m_synth->params();
m_paramsChanges.send(m_params);
Expand Down
51 changes: 32 additions & 19 deletions framework/audio/engine/internal/nodes/fxchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,35 @@
*/

#include "fxchain.h"
#include "fxnode.h"

#include "log.h"

using namespace muse;
using namespace muse::audio;
using namespace muse::audio::engine;

void FxChain::add(FxNodePtr fx)
void FxChain::setFxList(const std::vector<IFxProcessorPtr>& fxList)
{
IF_ASSERT_FAILED(fx) {
return;
}
clear();

ChainNode<FxChainTag>::add(fx);
for (auto it = fxList.rbegin(); it != fxList.rend(); ++it) {
FxNodePtr node = std::make_shared<FxNode>(*it);
doAdd(node);

fx->paramsChanged().onReceive(this, [this](const AudioFxParams& fxParams) {
m_fxChainSpec.insert_or_assign(fxParams.chainOrder, fxParams);
m_fxChainSpecChanged.send(m_fxChainSpec);
updateShouldProcessDuringSilence();
}, async::Asyncable::Mode::SetReplace);
node->paramsChanged().onReceive(this, [this](const AudioFxParams& fxParams) {
m_fxChainSpec.insert_or_assign(fxParams.chainOrder, fxParams);
m_fxChainSpecChanged.send(m_fxChainSpec);
updateShouldProcessDuringSilence();
}, async::Asyncable::Mode::SetReplace);
}

rebuild();
updateShouldProcessDuringSilence();
}

void FxChain::remove(FxNodePtr fx)
{
IF_ASSERT_FAILED(fx) {
return;
if (!name().empty() && !m_nodes.empty()) {
LOGD() << name() << ": " << m_nodes.front()->dump();
}

ChainNode<FxChainTag>::remove(fx);

fx->paramsChanged().disconnect(this);
}

void FxChain::setFxChainSpec(const AudioFxChain& fxChainSpec)
Expand Down Expand Up @@ -117,6 +113,23 @@ void FxChain::setPlayheadPosition(PlayheadPositionPtr playheadPosition)
}
}

void FxChain::rebuild()
{
for (size_t i = 1; i < m_nodes.size(); ++i) {
IAudioNodePtr& prev = m_nodes.at(i - 1);
IAudioNodePtr& curr = m_nodes.at(i);
curr->disconnectAll();
curr->connect(prev); // prev->input = curr
}
}

void FxChain::doSelfProcess(float* buffer, samples_t samplesPerChannel)
{
if (!m_nodes.empty()) {
m_nodes.front()->process(buffer, samplesPerChannel);
}
}

void FxChain::updateShouldProcessDuringSilence()
{
bool shouldProcessDuringSilence = false;
Expand Down
12 changes: 7 additions & 5 deletions framework/audio/engine/internal/nodes/fxchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#pragma once

#include "chainnode.h"
#include "fxnode.h"
#include "audio/engine/ifxprocessor.h"
#include "audio/engine/iplayhead.h"

#include "async/asyncable.h"
#include "async/channel.h"

Expand All @@ -38,11 +40,9 @@ namespace muse::audio::engine {
class FxChain : public ChainNode<FxChainTag>, public async::Asyncable
{
public:
void setFxList(const std::vector<IFxProcessorPtr>& fxList);

void add(FxNodePtr fx);
void remove(FxNodePtr fx);

//! NOTE Must be setted after adding all nodes to the chain
//! NOTE Must be set after adding all nodes to the chain
void setFxChainSpec(const AudioFxChain& fxChainSpec);
const AudioFxChain& fxChainSpec() const;
async::Channel<AudioFxChain> fxChainSpecChanged() const;
Expand All @@ -53,6 +53,8 @@ class FxChain : public ChainNode<FxChainTag>, public async::Asyncable
async::Channel<bool> shouldProcessDuringSilenceChanged() const;

private:
void rebuild() override;
void doSelfProcess(float* buffer, samples_t samplesPerChannel) override;

void updateShouldProcessDuringSilence();

Expand Down
2 changes: 1 addition & 1 deletion framework/audio/engine/internal/nodes/fxnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FxNode::FxNode(IFxProcessorPtr fxProcessor, PlayheadPositionPtr playheadPosition
{
assert(m_fxProcessor && "FxNode requires a non-null IFxProcessor");

setName(std::string("Fx[") + m_fxProcessor->name() + "] ");
setName(std::string("Fx[") + m_fxProcessor->name() + "]");
}

void FxNode::setPlayheadPosition(PlayheadPositionPtr playheadPosition)
Expand Down