-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.h
143 lines (104 loc) · 2.9 KB
/
node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#pragma once
#include "en.h"
#include "host.h"
namespace En
{
class NodeGroup;
class VstNode;
class MixerNode;
class MidiInputNode;
class Node : public QObject
{
Q_OBJECT
public:
class Factory
{
public:
virtual Node* create(Host*) = 0;
virtual ~Factory() {}
};
private:
NodeGroup* m_nodeGroup;
// position in node graph.
QPointF m_position;
protected:
class ChannelData {
public:
QString name;
QVector<float> buffer;
ChannelData(const QString& name, size_t bufferSize)
: name(name)
, buffer(bufferSize) {}
// why the fuck is this necessary to use ChannelData in a QVector?
ChannelData() {}
};
QVector<ChannelData> m_inputChannelData; // WARNING: unused buffer ATM
QVector<ChannelData> m_outputChannelData;
public:
static int blockSize() {
return 512;
}
// Turns out, probably didn't need this...
struct Visitor {
virtual void visit(Node* node) { Q_UNUSED(node); }
virtual void visit(VstNode* node);
virtual void visit(MixerNode* node);
virtual void visit(MidiInputNode* node);
};
static const float* s_nullInputBuffer;
Node()
: m_nodeGroup(0)
{
}
virtual ~Node()
{
// disable this for now - we break because by this point
// of destruction we cannot check our own inputs!
// if (nodeGroup()) {
// nodeGroup()->removeNode(this);
// }
}
virtual NodeGroup* nodeGroup() const {
return m_nodeGroup;
}
void setNodeGroup(NodeGroup* nodeGroup) {
// WARNING: this doesn't actually add this node to the group!
m_nodeGroup = nodeGroup;
}
virtual void accept(Visitor&) {}
int numInputChannels() const {
return m_inputChannelData.count();
}
int numOutputChannels() const {
return m_outputChannelData.count();
}
float* outputChannelBuffer(int channelIndex) {
return m_outputChannelData[channelIndex].buffer.data();
}
const float* outputChannelBufferConst(int channelIndex) const {
if (channelIndex >= numOutputChannels()) {
return s_nullInputBuffer;
}
return m_outputChannelData[channelIndex].buffer.constData();
}
virtual QList<QByteArray> midiEvents() const {
return QList<QByteArray>();
}
virtual QString displayLabel() const = 0;
QPointF position() const {
return m_position;
}
void setPosition(const QPointF& position) {
//qDebug() << "Setting node position to" << position;
m_position = position;
}
virtual void openEditorWindow()
{
// do nothing for this virtual base method
}
virtual QList<Node*> inputs() const = 0;
virtual void removeInput(Node* node) = 0;
void disconnectNode();
virtual void processAudio() = 0;
};
} // namespace En