Send (flatbuffer) messages from model/UI to engine nodes.

main
Ben Niemann 2021-12-26 00:05:07 +01:00
parent daa8d5752b
commit e0ad86f894
11 changed files with 37 additions and 1 deletions

View File

@ -76,6 +76,7 @@ public:
Status disconnect_ports(uint64_t src_node_id, const std::string& src_port, uint64_t dest_node_id, const std::string& dest_port) override { return Status::Ok(); }
Status set_control_value(uint64_t node_id, const std::string& port, float value) override { return Status::Ok(); }
Status send_node_message (uint64_t node_id, const std::string& msg) override { return Status::Ok(); }
Status connect_io_buffer(uint64_t node_id, size_t idx, const std::string& device, const std::string& port) override { return Status::Ok(); }

View File

@ -74,6 +74,7 @@ public:
virtual Status disconnect_ports(uint64_t src_node_id, const std::string& src_port, uint64_t dest_node_id, const std::string& dest_port) = 0;
virtual Status set_control_value(uint64_t node_id, const std::string& port, float value) = 0;
virtual Status send_node_message(uint64_t node_id, const std::string& msg) = 0;
virtual Status connect_io_buffer(uint64_t node_id, size_t idx, const std::string& device, const std::string& port) = 0;

View File

@ -68,6 +68,7 @@ cdef extern from "noisicaa/engine/engine.h" namespace "noisicaa" nogil:
Status disconnect_ports(uint64_t src_node_id, const string& src_port, uint64_t dest_node_id, const string& dest_port)
Status set_control_value(uint64_t node_id, const string& port, float value)
Status send_node_message(uint64_t node_id, const string& msg)
Status connect_io_buffer(uint64_t node_id, size_t idx, const string& device, const string& port)

View File

@ -154,6 +154,12 @@ cdef class PyEngine:
with nogil:
check(self.__engine.set_control_value(c_node_id, c_port, c_value))
def send_node_message(self, node_id, msg):
cdef uint64_t c_node_id = node_id
cdef string c_msg = msg
with nogil:
check(self.__engine.send_node_message(c_node_id, c_msg))
def connect_io_buffer(self, node_id, idx, device, port):
cdef uint64_t c_node_id = node_id
cdef size_t c_idx = idx

View File

@ -475,6 +475,19 @@ Status EngineImpl::set_control_value(uint64_t node_id, const std::string& port,
return node->set_control_value(port, value);
}
Status EngineImpl::send_node_message(uint64_t node_id, const std::string& msg) {
Node* node;
{
const auto& it = _nodes.find(node_id);
if (it == _nodes.end()) {
return ERROR_STATUS("Node 0x%016lx does not exists.", node_id);
}
node = it->second;
}
return node->handle_message(msg);
}
Status EngineImpl::allocate_io_buffers(uint64_t node_id, std::vector<std::tuple<PortDirection, PortType>>& buffers) {
assert(_io_buffers.find(node_id) == _io_buffers.end());

View File

@ -91,6 +91,7 @@ public:
Status set_control_value(uint64_t node_id, const std::string& port, float value) override;
Status connect_io_buffer(uint64_t node_id, size_t idx, const std::string& device, const std::string& port) override;
Status send_node_message(uint64_t node_id, const std::string& msg) override;
void clear_graph() override;
Status compile_graph() override;

View File

@ -232,6 +232,10 @@ Status Node::set_control_value(const std::string& port_name, float value) {
return Status::Ok();
}
Status Node::handle_message(const std::string& msg) {
return ERROR_STATUS("%s#0x%016llx: Unhandled node message.", _uri.c_str(), _id);
}
Status Node::add_to_program(Program* program) {
_port_buffers.clear();
std::vector<uint32_t> release_buffers;

View File

@ -134,6 +134,7 @@ public:
Status connect_ports(const std::string& dest_port, Node* src_node, const std::string& src_port);
Status disconnect_ports(const std::string& dest_port, Node* src_node, const std::string& src_port);
Status set_control_value(const std::string& port, float value);
virtual Status handle_message(const std::string& msg);
uint32_t port_buffer(uint32_t port_idx) const {
const auto& it = _port_buffers.find(port_idx);

View File

@ -32,6 +32,6 @@ from .base import (
from .project import (
Project,
GraphNode, Port, Connection,
EngineChange, SetControlValue, ConnectIOBuffer,
EngineChange, SetControlValue, ConnectIOBuffer, SendNodeMessage,
)
from .class_registry import ClassRegistry

View File

@ -45,6 +45,11 @@ class ConnectIOBuffer(EngineChange):
self.device = device
self.port = port
class SendNodeMessage(EngineChange):
def __init__(self, nodeId: int, msg: bytes) -> None:
self.nodeId = nodeId
self.msg = msg
class Port(base.BaseObject):
name, nameChanged = base.ScalarProperty('uri', str)

View File

@ -345,5 +345,8 @@ class Project(ui_base.ProjectMixin, ui_base.PropertyContainer, QtCore.QObject):
elif isinstance(change, model_lib.ConnectIOBuffer):
self.engine.connect_io_buffer(change.nodeId, change.idx, change.device, change.port)
elif isinstance(change, model_lib.SendNodeMessage):
self.engine.send_node_message(change.nodeId, change.msg)
else:
raise TypeError(type(change))