77 lines
2.0 KiB
C++
77 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include <QPointer>
|
|
|
|
namespace Xybrid::UI {
|
|
class PortObject;
|
|
}
|
|
|
|
namespace Xybrid::Config {
|
|
class PluginInfo;
|
|
}
|
|
|
|
namespace Xybrid::Data {
|
|
class Graph;
|
|
class Node;
|
|
|
|
class Port : public std::enable_shared_from_this<Port> {
|
|
public:
|
|
enum Type : uint8_t {
|
|
Input, Output
|
|
};
|
|
enum DataType : uint8_t {
|
|
Audio, Command, MIDI, Parameter
|
|
};
|
|
std::weak_ptr<Node> owner;
|
|
std::vector<std::weak_ptr<Port>> connections;
|
|
std::weak_ptr<Port> passthroughFor;
|
|
Type type; // TODO: figure out passthrough?
|
|
uint8_t index;
|
|
size_t tickUpdatedOn = static_cast<size_t>(-1);
|
|
|
|
QPointer<UI::PortObject> obj;
|
|
|
|
std::string name;
|
|
|
|
virtual ~Port();
|
|
|
|
virtual DataType dataType() const { return static_cast<DataType>(-1); }
|
|
virtual bool singleInput() const { return false; }
|
|
virtual bool canConnectTo(DataType) const;
|
|
/*virtual*/ bool connect(std::shared_ptr<Port>);
|
|
/*virtual*/ void disconnect(std::shared_ptr<Port>);
|
|
void cleanConnections();
|
|
|
|
virtual void pull() { } // make sure data for this tick is available
|
|
|
|
static std::shared_ptr<Port> makePort(DataType);
|
|
};
|
|
|
|
class Node : public std::enable_shared_from_this<Node> {
|
|
public:
|
|
std::weak_ptr<Graph> parent;
|
|
int x{}, y{};
|
|
std::string name;
|
|
|
|
std::map<Port::DataType, std::map<uint8_t, std::shared_ptr<Port>>> inputs, outputs;
|
|
|
|
std::shared_ptr<Config::PluginInfo> plugin;
|
|
|
|
virtual ~Node() = default;
|
|
|
|
void parentTo(std::shared_ptr<Graph>);
|
|
|
|
std::shared_ptr<Port> port(Port::Type, Port::DataType, uint8_t, bool addIfNeeded = false);
|
|
std::shared_ptr<Port> addPort(Port::Type, Port::DataType, uint8_t);
|
|
void removePort(Port::Type, Port::DataType, uint8_t);
|
|
|
|
virtual void process() { }
|
|
virtual std::string pluginName() const;
|
|
};
|
|
}
|