ParameterPort
parent
a28d6e48b6
commit
e63c93e146
|
@ -81,6 +81,7 @@ void Port::cleanConnections() {
|
|||
std::shared_ptr<Port> Port::makePort(DataType dt) {
|
||||
if (dt == Audio) return std::make_shared<AudioPort>();
|
||||
if (dt == Command) return std::make_shared<CommandPort>();
|
||||
if (dt == Parameter) return std::make_shared<ParameterPort>();
|
||||
// fallback
|
||||
return std::make_shared<Port>();
|
||||
}
|
||||
|
|
|
@ -87,3 +87,33 @@ void CommandPort::push(std::vector<uint8_t> v) {
|
|||
data = static_cast<uint8_t*>(audioEngine->tickAlloc(dataSize));
|
||||
memcpy(data, v.data(), dataSize);
|
||||
}
|
||||
|
||||
void ParameterPort::pull() {
|
||||
auto t = audioEngine->curTickId();
|
||||
if (tickUpdatedOn == t) return;
|
||||
lock.lock();
|
||||
if (tickUpdatedOn == t) { lock.unlock(); return; } // someone else got here before us
|
||||
|
||||
buf = nullptr;
|
||||
if (type == Input) {
|
||||
if (isConnected()) {
|
||||
if (auto p = std::static_pointer_cast<ParameterPort>(connections[0].lock()); p) {
|
||||
p->pull();
|
||||
buf = p->buf;
|
||||
size = p->size;
|
||||
}
|
||||
}
|
||||
} else if (auto pt = std::static_pointer_cast<ParameterPort>(passthroughTo.lock()); pt && pt->dataType() == Parameter) {
|
||||
pt->pull();
|
||||
buf = pt->buf;
|
||||
size = pt->size;
|
||||
}
|
||||
if (!buf) { // no buffer pulled from input or passthrough; create a new one
|
||||
size = audioEngine->curTickSize();
|
||||
buf = static_cast<double*>(audioEngine->tickAlloc(size * sizeof(double)));
|
||||
std::fill_n(buf, size, std::numeric_limits<double>::quiet_NaN());
|
||||
}
|
||||
|
||||
tickUpdatedOn = t;
|
||||
lock.unlock();
|
||||
}
|
||||
|
|
|
@ -57,4 +57,20 @@ namespace Xybrid::Data {
|
|||
/// Push a data buffer
|
||||
void push(std::vector<uint8_t>);
|
||||
};
|
||||
|
||||
class ParameterPort : public Port {
|
||||
public:
|
||||
double* buf;
|
||||
size_t size;
|
||||
|
||||
ParameterPort() = default;
|
||||
~ParameterPort() override = default;
|
||||
|
||||
double& operator[](size_t at) { return buf[at]; }
|
||||
double& at(size_t at) { return buf[at]; }
|
||||
|
||||
Port::DataType dataType() const override { return Port::Parameter; }
|
||||
|
||||
void pull() override;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue