/*
* Klang – a node+text-based synthesizer library
*
* This file is part of the *wellen* library (https://github.com/dennisppaul/wellen).
* Copyright (c) 2022 Dennis P Paul.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* [ NODE_BUFFER ]
* +---------------------+
* | |
* IN00--| SIGNAL SIGNAL |--OUTFF
* | |
* +---------------------+
*/
#ifndef NodeBuffer_hpp
#define NodeBuffer_hpp
#include "KlangNode.hpp"
namespace klang {
class NodeBuffer : public Node {
public:
static const CHANNEL_ID NUM_CH_IN = 1;
static const CHANNEL_ID NUM_CH_OUT = 255;
bool connect(Connection* pConnection, CHANNEL_ID pInChannel) {
if (pInChannel == CH_IN_SIGNAL) {
mConnection_CH_IN_SIGNAL = pConnection;
return true;
}
return false;
}
bool disconnect(CHANNEL_ID pInChannel) {
if (pInChannel == CH_IN_SIGNAL) {
mConnection_CH_IN_SIGNAL = nullptr;
return true;
}
return false;
}
void update(CHANNEL_ID pChannel, float* pAudioBlock) {
if (is_not_updated()) {
if (mConnection_CH_IN_SIGNAL != nullptr) {
mBlock_SIGNAL = AudioBlockPool::instance().request();
mConnection_CH_IN_SIGNAL->update(mBlock_SIGNAL);
}
flag_updated();
}
if (pChannel == CH_OUT_SIGNAL) {
float* mBlockData_IN_SIGNAL = AudioBlockPool::instance().data(mBlock_SIGNAL);
// @TODO(should probably use `std::copy` here)
for (uint16_t i = 0; i < KLANG_SAMPLES_PER_AUDIO_BLOCK; i++) {
pAudioBlock[i] = mBlockData_IN_SIGNAL[i];
}
}
}
bool ouput_allow_multiple_connections() {
return false;
}
void set_command(KLANG_CMD_TYPE pCommand, KLANG_CMD_TYPE* pPayLoad) {}
private:
AUDIO_BLOCK_ID mBlock_SIGNAL = AudioBlockPool::NO_ID;
Connection* mConnection_CH_IN_SIGNAL = nullptr;
};
} // namespace klang
#endif /* NodeBuffer_hpp */