0
|
1 # super rough code
|
|
2
|
|
3 # The magic value
|
|
4 NoChange = "NoChange"
|
|
5
|
|
6 class NodeType:
|
|
7 def __init__(self, iports=None, oports=None):
|
|
8 make_attributes_from_args('iports', 'oports')
|
166
|
9 def process(self,iports,oports):
|
0
|
10 pass
|
|
11 # TODO: handle NoChange stuff
|
|
12
|
|
13 class AddNode(NodeType):
|
|
14 """Adds two nodes together"""
|
|
15 def __init__(self):
|
|
16 NodeType.__init__(self, iports={'in1' : Port, 'in2' : Port},
|
|
17 oports={'out1' : Port})
|
|
18 def process(self, ports):
|
|
19 ports.out1 = ports.in1 + ports.in2
|
|
20
|
|
21 class SumNode(NodeType):
|
|
22 """Adds any number of nodes together"""
|
|
23 def __init__(self, empty_val=0):
|
|
24 NodeType.__init__(self, iports={'in1' : MultiPort},
|
|
25 oports={'out1' : Port})
|
|
26 self.empty_val = 0
|
|
27 def process(self, ports):
|
|
28 val = self.empty_val
|
|
29 for p in ports.in1:
|
|
30 val += p
|
|
31
|
|
32 ports.out1 = val
|
|
33
|
|
34 class FadeNode(NodeType):
|
|
35 """Provides a UI scaler to let you fade a value"""
|
|
36 def __init__(self):
|
166
|
37 NodeType.__init__(self, iports={'in1' : Port(),
|
|
38 'scale1' : Port()},
|
|
39 oports={'out1' : Port()},
|
|
40 def process(self, iports, oports):
|
0
|
41 ports.out1 = ports.in1 * ports.scale1
|
|
42
|
|
43 class FadeConstellation(Constellation):
|
|
44 """This somehow describes the following:
|
|
45
|
|
46 [ ] [ UI.Scale ]
|
|
47 | |
|
|
48 | in | scale
|
|
49 | ____ /
|
|
50 | |
|
|
51 [ FadeNode ]
|
|
52 |
|
|
53 | out
|
|
54 |
|
|
55 [ ]
|
|
56
|
|
57 Maybe this is a group (I like this more):
|
|
58
|
|
59 |
|
|
60 | in
|
|
61 | FadeGroup
|
|
62 - - - - - - - - - - - - -- - -
|
|
63 | | |
|
|
64 | [ UI.Scale ]
|
|
65 | | | |
|
|
66 | in | scale
|
|
67 | | ____ / |
|
|
68 | |
|
|
69 | [ FadeNode ] |
|
|
70 |
|
|
71 | | out |
|
|
72 |
|
|
73 \ - - - - - - - - - - - -- - - /
|
|
74 |
|
|
75 | out
|
|
76 |
|
|
77 """
|
166
|
78
|
|
79 Persistence
|
|
80 node instance saves:
|
|
81 node name, id, and such
|
|
82 input ports:
|
|
83 any port details
|
|
84 what the port connects to
|
|
85 values:
|
|
86 maybe UI.Scale level
|
|
87 maybe group contents
|
|
88
|
|
89
|
|
90 p=InputPort(node=self,minconns=1,maxconns=2) # an input port to this node
|
|
91 p.connect(othernode)
|
|
92 print p.connections()
|
|
93 p.connect(yetanother)
|
|
94
|
|
95 op=OutputPort(node=self) # an output port
|
|
96 print op.connections() # lists all the nodes that call us an input node
|
|
97 op.connect(n) # calls n.connect(self)
|
|
98
|
|
99
|
|
100
|
|
101
|
|
102 Ports
|
|
103 Port: "scalar"
|
|
104 MultiPort: "array of Port"
|
|
105 ^ all wrong
|
|
106
|
|
107 Ports II:
|
|
108 min/max number of connections
|
|
109 (failure to fit these numbers means port is "deactivated")
|
|
110 "Normal" ports are min=1, max=1
|
|
111 "Multiports" are min=0, max=None
|
|
112 "Binary" ports are min=2, max=2
|
|
113 oh yeah, there are two totally different types of ports
|
|
114
|
|
115 Input ports: min/max numbers of connections
|
|
116 store current connections
|
|
117 Output ports: nothing
|
|
118 store nothing!
|
|
119
|
|
120 fake node persistence for subtract node
|
|
121
|
|
122 <!-- "my subtract" is a unique id -->
|
|
123 <!-- drew: there is no such thing as a subtract group -->
|
|
124 <node name="my subtract" type="math.Add">
|
|
125 <inputs>
|
|
126 <port name="in1">
|
|
127 <noderef name="node I"/>
|
|
128 <noderef name="node II"/>
|
|
129 </port>
|
|
130 </inputs>
|
|
131 <state>
|
|
132 </state>
|
|
133
|
|
134 </node>
|
|
135
|
|
136
|
|
137 <node name="the group" type="group">
|
|
138
|
|
139 <!-- all of the port names of the group are being made up right
|
|
140 here- a group has no preset inputs or outputs-->
|
|
141
|
|
142 <inputs>
|
|
143 <port name="group-in 1">
|
|
144 <noderef name="node5"/>
|
|
145 <noderef name="node6"/>
|
|
146 </port>
|
|
147 </inputs>
|
|
148
|
|
149 <state>
|
|
150 <children>
|
|
151 <noderef name="node3">
|
|
152 <connect localPort="in1" groupPort="group-in1"/>
|
|
153 </noderef>
|
|
154 <noderef name="node4">
|
|
155 <connect localPort="in1" groupPort="group-in1"/>
|
|
156 <connect localPort="out1" groupPort="theoutput"/>
|
|
157 </noderef>
|
|
158 </children>
|
|
159
|
|
160 </state>
|
|
161 </node>
|
|
162
|
|
163 <node name="preset value" type="source.Scalar">
|
|
164 <!-- no inputs, node has output only -->
|
|
165 <state>
|
|
166 <value>8.3</value>
|
|
167
|
|
168 <minvalue>0</minvalue>
|
|
169 <maxvalue>100</maxvalue>
|
|
170
|
|
171 <gui>
|
|
172 <slider res=".1" height="200" bgcolor="red"/>
|
|
173 <priority>very high</priority>
|
|
174 <xpos>395</xpos>
|
|
175 <ypos>21</ypos>
|
|
176 </gui>
|
|
177
|
|
178 </state>
|
|
179
|
|
180 </node>
|