central Node serialization, const-correctness, include fix (oops)

portability/boost
zetaPRIME 2019-01-22 15:23:31 -05:00
parent 86a275df82
commit c74f312d2c
16 changed files with 63 additions and 34 deletions

10
notes
View File

@ -47,10 +47,10 @@ TODO {
immediate frontburner {
patchboard copy+paste! cbor array of node objects, position relative to center of viewport
also record connections between those particular nodes!
provide conversions to/from qcborvalue in node.cpp?
while we're here, add file import/export of any given node (still .xyg?)
- provide conversions to/from qcborvalue in node.cpp?
while we're here, add file import/export of any given node (still .xyg? .xyn?)
- fix missing-reset bug!
probably exclude i/o ports from copy+paste lest things futz up on the parent
}
-? return the latency/buffer size to 100ms once multithreading is streamlined
@ -62,10 +62,6 @@ TODO {
bugs to fix {
graph connections sometimes spawn in duplicated :|
- shifted <>? keys still count as different keys for note previewing
- reset is never called when hooking up a node after starting preview; breaks instrumentcore
- ^ on rebuilding queue, call reset on anything that wasn't there before (unordered_set)
on starting playback, sometimes a "thunk" sneaks into the waveform?

View File

@ -204,8 +204,6 @@ void AudioEngine::buildQueue() {
if (auto ptn = pt->owner.lock(); ptn)
qCurrent->push_back(ptn);
// T_ODO: make this not process things the weird way around
// oh, it's working properly... it just processing subgraph before its internally-connected *inputs*
while (!qCurrent->empty()) {
// ... this could be made more efficient with some redundancy checking, but whatever
for (auto n : *qCurrent) {

View File

@ -10,7 +10,7 @@ using namespace Xybrid::Config;
#include "data/graph.h"
using namespace Xybrid::Data;
#include "gadgets/ioport.h"
#include "nodes/gadget/ioport.h"
using Xybrid::Gadgets::IOPort;
#include "util/strings.h"

View File

@ -36,7 +36,7 @@ Graph::Graph() {
// propagate
void Graph::reset() { for (auto c : children) c->reset(); }
void Graph::saveData(QCborMap& m) {
void Graph::saveData(QCborMap& m) const {
// graph properties
// ... maybe there will be some at some point
@ -95,7 +95,7 @@ void Graph::saveData(QCborMap& m) {
}
void Graph::loadData(QCborMap& m) {
void Graph::loadData(const QCborMap& m) {
auto g = std::static_pointer_cast<Graph>(shared_from_this());
// graph properties (none)

View File

@ -14,8 +14,8 @@ namespace Xybrid::Data {
int viewX{}, viewY{};
void reset() override;
void saveData(QCborMap&) override;
void loadData(QCborMap&) override;
void saveData(QCborMap&) const override;
void loadData(const QCborMap&) override;
//std::string pluginName() const override;
void onParent(std::shared_ptr<Graph>) override;

View File

@ -7,6 +7,7 @@ using namespace Xybrid::Data;
#include "ui/patchboard/nodeobject.h"
#include "config/pluginregistry.h"
using namespace Xybrid::Config;
#include "audio/audioengine.h"
using namespace Xybrid::Audio;
@ -17,6 +18,8 @@ using namespace Xybrid::Audio;
#include <QDebug>
#include <QThread>
#include <QCborValue>
#include <QCborMap>
Port::~Port() {
// clean up others' connection lists
@ -74,6 +77,29 @@ std::shared_ptr<Port> Port::makePort(DataType dt) {
return std::make_shared<Port>();
}
std::shared_ptr<Node> Node::fromCbor(const QCborMap& m, std::shared_ptr<Graph> parent) {
auto ch = PluginRegistry::createInstance(m.value("id").toString().toStdString());
ch->parentTo(parent);
ch->name = m.value("name").toString().toStdString();
ch->x = static_cast<int>(m.value("x").toInteger());
ch->y = static_cast<int>(m.value("y").toInteger());
ch->loadData(m);
return ch;
}
std::shared_ptr<Node> Node::fromCbor(const QCborValue& m, std::shared_ptr<Graph> parent) { return fromCbor(m.toMap(), parent); }
QCborMap Node::toCbor() const {
QCborMap m;
if (plugin) m.insert(QString("id"), QString::fromStdString(plugin->id));
if (!name.empty()) m.insert(QString("name"), QString::fromStdString(name));
m.insert(QString("x"), x);
m.insert(QString("y"), y);
saveData(m);
return m;
}
void Node::parentTo(std::shared_ptr<Graph> graph) {
auto t = shared_from_this(); // keep alive during reparenting
if (auto p = parent.lock(); p) {

View File

@ -14,6 +14,9 @@
class QPainter;
class QStyleOptionGraphicsItem;
class QCborValue;
class QCborMap;
namespace Xybrid::UI {
class NodeObject;
class PortObject;
@ -92,8 +95,14 @@ namespace Xybrid::Data {
QPointer<UI::NodeObject> obj;
Node() = default;
virtual ~Node() = default;
static std::shared_ptr<Node> fromCbor(const QCborMap&, std::shared_ptr<Graph> = nullptr);
static std::shared_ptr<Node> fromCbor(const QCborValue&, std::shared_ptr<Graph> = nullptr);
QCborMap toCbor() const;
void parentTo(std::shared_ptr<Graph>);
std::shared_ptr<Port> port(Port::Type, Port::DataType, uint8_t, bool addIfNeeded = false);
@ -107,8 +116,8 @@ namespace Xybrid::Data {
virtual void init() { }
virtual void reset() { }
virtual void saveData(QCborMap&) { }
virtual void loadData(QCborMap&) { }
virtual void saveData(QCborMap&) const { }
virtual void loadData(const QCborMap&) { }
virtual void process() { }
virtual std::string pluginName() const;

View File

@ -66,12 +66,12 @@ void GainBalance::process() { // TODO: lerp from tick to tick?
}
}
void GainBalance::saveData(QCborMap& m) {
void GainBalance::saveData(QCborMap& m) const {
m.insert(QString("gain"), QCborValue(gain));
m.insert(QString("balance"), QCborValue(balance));
}
void GainBalance::loadData(QCborMap& m) {
void GainBalance::loadData(const QCborMap& m) {
gain = m.value("gain").toDouble(0.0);
balance = m.value("balance").toDouble(0.0);
}

View File

@ -18,8 +18,8 @@ namespace Xybrid::Gadgets {
//void onRename() override;
void saveData(QCborMap&) override;
void loadData(QCborMap&) override;
void saveData(QCborMap&) const override;
void loadData(const QCborMap&) override;
//void onUnparent(std::shared_ptr<Data::Graph>) override;
//void onParent(std::shared_ptr<Data::Graph>) override;

View File

@ -95,7 +95,7 @@ void IOPort::onRename() {
}
}
void IOPort::saveData(QCborMap& m) {
void IOPort::saveData(QCborMap& m) const {
QCborMap pm;
pm.insert(QString("type"), Util::enumName(type));
pm.insert(QString("dataType"), Util::enumName(dataType));
@ -103,7 +103,7 @@ void IOPort::saveData(QCborMap& m) {
m.insert(QString("port"), pm);
}
void IOPort::loadData(QCborMap& m) {
void IOPort::loadData(const QCborMap& m) {
auto pm = m.value("port").toMap();
if (pm.empty()) return;
auto pmt = QMetaType::metaObjectForType(QMetaType::type("Xybrid::Data::Port"));

View File

@ -21,8 +21,8 @@ namespace Xybrid::Gadgets {
void onRename() override;
void saveData(QCborMap&) override;
void loadData(QCborMap&) override;
void saveData(QCborMap&) const override;
void loadData(const QCborMap&) override;
void onUnparent(std::shared_ptr<Data::Graph>) override;
void onParent(std::shared_ptr<Data::Graph>) override;

View File

@ -65,11 +65,11 @@ void Transpose::process() {
}
}
void Transpose::saveData(QCborMap& m) {
void Transpose::saveData(QCborMap& m) const {
m.insert(QString("amount"), QCborValue(amount));
}
void Transpose::loadData(QCborMap& m) {
void Transpose::loadData(const QCborMap& m) {
amount = static_cast<int>(m.value("amount").toInteger(0));
}

View File

@ -17,8 +17,8 @@ namespace Xybrid::Gadgets {
//void onRename() override;
void saveData(QCborMap&) override;
void loadData(QCborMap&) override;
void saveData(QCborMap&) const override;
void loadData(const QCborMap&) override;
//void onUnparent(std::shared_ptr<Data::Graph>) override;
//void onParent(std::shared_ptr<Data::Graph>) override;

View File

@ -161,7 +161,7 @@ void I2x03::init() {
void I2x03::reset() { core.reset(); }
void I2x03::process() { core.process(this); }
void I2x03::saveData(QCborMap& m) {
void I2x03::saveData(QCborMap& m) const {
m.insert(QString("wave"), wave);
m.insert(QString("adsr"), adsr);
@ -174,7 +174,7 @@ void I2x03::saveData(QCborMap& m) {
m.insert(QString("pwmPhase"), pwmPhase);
}
void I2x03::loadData(QCborMap& m) {
void I2x03::loadData(const QCborMap& m) {
wave = static_cast<int8_t>(m.value("wave").toInteger(wave));
adsr = m.value("adsr");

View File

@ -26,8 +26,8 @@ namespace Xybrid::Instruments {
//void onRename() override;
void saveData(QCborMap&) override;
void loadData(QCborMap&) override;
void saveData(QCborMap&) const override;
void loadData(const QCborMap&) override;
//void onUnparent(std::shared_ptr<Data::Graph>) override;
//void onParent(std::shared_ptr<Data::Graph>) override;

View File

@ -22,8 +22,8 @@ namespace Xybrid::Instruments {
//void onRename() override;
//void saveData(QCborMap&) override;
//void loadData(QCborMap&) override;
//void saveData(QCborMap&) const override;
//void loadData(const QCborMap&) override;
//void onUnparent(std::shared_ptr<Data::Graph>) override;
//void onParent(std::shared_ptr<Data::Graph>) override;