forked from Phantom-Studio/natron-plugins
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathWaveForm.py
381 lines (313 loc) · 12.5 KB
/
WaveForm.py
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# -*- coding: utf-8 -*-
# DO NOT EDIT THIS FILE
# This file was automatically generated by Natron PyPlug exporter version 10.
# Hand-written code should be added in a separate file named WaveFormExt.py
# See http://natron.readthedocs.org/en/master/groups.html#adding-hand-written-code-callbacks-etc
# Note that Viewers are never exported
import NatronEngine
import sys
# Try to import the extensions file where callbacks and hand-written code should be located.
try:
from WaveFormExt import *
except ImportError:
pass
def getPluginID():
return "natron.community.plugins.WaveForm"
def getLabel():
return "WaveForm"
def getVersion():
return 1
def getIconPath():
return "WaveForm.png"
def getGrouping():
return "Community/Utility"
def getPluginDescription():
return "Display a Luminance Waveform of the input.\nYou can also display RGB channels separately.\n\nAs Natron works in linear colorspace , there is an option to specify you display gamma. "
def createInstance(app,group):
# Create all nodes in the group
# Create the parameters of the group node the same way we did for all internal nodes
lastNode = group
# Create the user parameters
lastNode.Controls = lastNode.createPageParam("Controls", "Controls")
param = lastNode.createColorParam("Gamma1value", "Display Gamma", True)
param.setMinimum(0, 0)
param.setDisplayMinimum(0, 0)
param.setDisplayMaximum(4, 0)
param.setDefaultValue(1, 0)
param.restoreDefaultValue(0)
param.setMinimum(0, 1)
param.setDisplayMinimum(0, 1)
param.setDisplayMaximum(4, 1)
param.setDefaultValue(1, 1)
param.restoreDefaultValue(1)
param.setMinimum(0, 2)
param.setDisplayMinimum(0, 2)
param.setDisplayMaximum(4, 2)
param.setDefaultValue(1, 2)
param.restoreDefaultValue(2)
param.setMinimum(0, 3)
param.setDisplayMinimum(0, 3)
param.setDisplayMaximum(4, 3)
param.setDefaultValue(1, 3)
param.restoreDefaultValue(3)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setAddNewLine(True)
param.setAnimationEnabled(True)
param.setValue(2.2, 0)
param.setValue(2.2, 1)
param.setValue(2.2, 2)
param.setValue(2.2, 3)
lastNode.Gamma1value = param
del param
param = lastNode.createIntParam("accel", "Acceleration")
param.setMinimum(1, 0)
param.setMaximum(300, 0)
param.setDisplayMinimum(0, 0)
param.setDisplayMaximum(10, 0)
param.setDefaultValue(2, 0)
param.restoreDefaultValue(0)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("Skips some pixels to give faster result, but less accurate.")
param.setAddNewLine(True)
param.setAnimationEnabled(True)
param.setValue(5, 0)
lastNode.accel = param
del param
param = lastNode.createBooleanParam("rgb", "Show separate RGB waves")
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("Display separate channels instead of Luminance")
param.setAddNewLine(True)
param.setAnimationEnabled(True)
lastNode.rgb = param
del param
# Refresh the GUI with the newly created parameters
lastNode.setPagesOrder(['Controls', 'Node'])
lastNode.refreshUserParamsGUI()
del lastNode
# Start of node "LumaWave"
lastNode = app.createNode("net.sf.openfx.Shadertoy", 1, group)
lastNode.setScriptName("LumaWave")
lastNode.setLabel("LumaWave")
lastNode.setPosition(1234, 559)
lastNode.setSize(80, 43)
lastNode.setColor(0.3, 0.5, 0.2)
groupLumaWave = lastNode
param = lastNode.getParam("paramValueInt0")
if param is not None:
param.setValue(5, 0)
del param
param = lastNode.getParam("imageShaderSource")
if param is not None:
param.setValue("// Luma waveform for Natron (shadertoy OFX ) by sozap\n// you may use it and distribute it as you like ...\n\nuniform int step = 2 ;\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n\t//vec3 img = texture2D(iChannel0, fragCoord.xy / iResolution.xy).rgb;\n\n vec2 uv = fragCoord.xy / iResolution.xy;\n vec2 ds = fragCoord.xy / iResolution.xy;\n\n\tfloat range=1.1260; // used to reduce the waveform\n\n\tfloat col=0.0;\n\tfloat aprox=0.005;\n\tfloat lum=0.0 ;\n\t//int step=10;\n\n\tfor (int i=0; i < iResolution.y ; i+=step){\n\t\tds.y=i/iResolution.y;\n\n\t\tvec3 tmp = texture2D(iChannel0, ds.xy).rgb;\n\n\t\t//rgb to luminance\n\t\tlum = (tmp.x*0.3)+(tmp.y*0.59)+(tmp.z*0.11) ;\n\n\t\tif (lum < (uv.y*range)) {if (lum+aprox > (uv.y*range)) col+=0.02 ;};\n\n\t}\n\n\tvec3 img=vec3((col*step)/7.0,col*step,(col*step)/7.0) ;\n\n\tif (mod(uv.y,.445)<=3./iResolution.y) img.x =0.5 ;\n\n fragColor = vec4(img,1.0);\n}\n")
del param
param = lastNode.getParam("mipmap0")
if param is not None:
param.set("Linear")
del param
param = lastNode.getParam("inputEnable1")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("inputEnable2")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("inputEnable3")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("mouseParams")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("paramCount")
if param is not None:
param.setValue(1, 0)
del param
param = lastNode.getParam("paramType0")
if param is not None:
param.set("int")
del param
param = lastNode.getParam("paramName0")
if param is not None:
param.setValue("step")
del param
param = lastNode.getParam("paramLabel0")
if param is not None:
param.setValue("step")
del param
param = lastNode.getParam("paramDefaultInt0")
if param is not None:
param.setValue(2, 0)
del param
del lastNode
# End of node "LumaWave"
# Start of node "Gamma1"
lastNode = app.createNode("net.sf.openfx.GammaPlugin", 2, group)
lastNode.setScriptName("Gamma1")
lastNode.setLabel("Gamma1")
lastNode.setPosition(1222, 458)
lastNode.setSize(104, 43)
lastNode.setColor(0.48, 0.66, 1)
groupGamma1 = lastNode
param = lastNode.getParam("NatronOfxParamProcessA")
if param is not None:
param.setValue(True)
del param
param = lastNode.getParam("value")
if param is not None:
param.setValue(2.2, 0)
param.setValue(2.2, 1)
param.setValue(2.2, 2)
param.setValue(2.2, 3)
del param
param = lastNode.getParam("invert")
if param is not None:
param.setValue(True)
del param
del lastNode
# End of node "Gamma1"
# Start of node "RGBWave"
lastNode = app.createNode("net.sf.openfx.Shadertoy", 1, group)
lastNode.setScriptName("RGBWave")
lastNode.setLabel("RGBWave")
lastNode.setPosition(1367, 562)
lastNode.setSize(80, 43)
lastNode.setColor(0.3, 0.5, 0.2)
groupRGBWave = lastNode
param = lastNode.getParam("paramValueInt0")
if param is not None:
param.setValue(5, 0)
del param
param = lastNode.getParam("imageShaderSource")
if param is not None:
param.setValue("// RGB waveform for Natron (shadertoy OFX ) by sozap\n// you may use it and distribute it as you like ...\n\nuniform int step = 2 ;\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord.xy / iResolution.xy;\n vec2 ds = fragCoord.xy / iResolution.xy;\n\n\tfloat range=1.1260; // used to reduce the waveform\n\n \tfloat col=0.0;\n\tfloat aprox=0.005;\n\tfloat lum=0.0 ;\n\n\tfloat xstep=(iResolution.x/3);\n\n\t\tfor (int i=0; i < iResolution.y ; i+=step){\n\t\t\tds.y=i/iResolution.y;\n\t\t\tds.x=fragCoord.x / (iResolution.x/3);\n\t\t\tvec3 tmp = texture2D(iChannel0, ds.xy).rgb;\n\n\t\t\tif (fragCoord.x < xstep) lum=tmp.x ;\n\t\t\tif (fragCoord.x > xstep) lum=tmp.y ;\n\t\t\tif (fragCoord.x > (xstep*2)) lum=tmp.z ;\n\n\t\t\tif (lum < (uv.y*range)) {if (lum+aprox > (uv.y*range)) col+=0.02 ;};\n\n\t\t}\n\n\tcol=col*step;\n\tvec3 img=vec3(0.0,0.0,0.0) ;\n\n\t//R\n\tif (fragCoord.x < xstep) img=vec3((col)/7.0,0.01*col,0.01*col) ;\n\n\t//G\n\tif (fragCoord.x > xstep) img=vec3(0.0,(col)/7.0,0.0) ;\n\n\t//B\n\tif (fragCoord.x > (xstep*2)) img=vec3(0.01*col,0.01*col,(col)/7.0) ;\n\n\n\tif (mod(uv.y,.445)<=3./iResolution.y) img.x =0.5 ;\n\n fragColor = vec4(img,1.0);\n}\n")
del param
param = lastNode.getParam("mipmap0")
if param is not None:
param.set("Linear")
del param
param = lastNode.getParam("inputEnable1")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("inputEnable2")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("inputEnable3")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("mouseParams")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("paramCount")
if param is not None:
param.setValue(1, 0)
del param
param = lastNode.getParam("paramType0")
if param is not None:
param.set("int")
del param
param = lastNode.getParam("paramName0")
if param is not None:
param.setValue("step")
del param
param = lastNode.getParam("paramLabel0")
if param is not None:
param.setValue("step")
del param
param = lastNode.getParam("paramDefaultInt0")
if param is not None:
param.setValue(1, 0)
del param
del lastNode
# End of node "RGBWave"
# Start of node "Gamma2"
lastNode = app.createNode("net.sf.openfx.GammaPlugin", 2, group)
lastNode.setScriptName("Gamma2")
lastNode.setLabel("Gamma2")
lastNode.setPosition(1355, 665)
lastNode.setSize(104, 43)
lastNode.setColor(0.48, 0.66, 1)
groupGamma2 = lastNode
param = lastNode.getParam("value")
if param is not None:
param.setValue(1.4, 0)
param.setValue(1.4, 1)
param.setValue(1.4, 2)
param.setValue(1.4, 3)
del param
param = lastNode.getParam("premult")
if param is not None:
param.setValue(True)
del param
del lastNode
# End of node "Gamma2"
# Start of node "Switch1"
lastNode = app.createNode("net.sf.openfx.switchPlugin", 1, group)
lastNode.setScriptName("Switch1")
lastNode.setLabel("Switch1")
lastNode.setPosition(1222, 826)
lastNode.setSize(104, 43)
lastNode.setColor(0.3, 0.37, 0.776)
groupSwitch1 = lastNode
param = lastNode.getParam("which")
if param is not None:
param.setValue(0, 0)
del param
del lastNode
# End of node "Switch1"
# Start of node "Input"
lastNode = app.createNode("fr.inria.built-in.Input", 1, group)
lastNode.setScriptName("Input")
lastNode.setLabel("Input")
lastNode.setPosition(1220, 266)
lastNode.setSize(104, 43)
lastNode.setColor(0.3, 0.5, 0.2)
groupInput = lastNode
del lastNode
# End of node "Input"
# Start of node "Output1"
lastNode = app.createNode("fr.inria.built-in.Output", 1, group)
lastNode.setLabel("Output1")
lastNode.setPosition(1222, 1013)
lastNode.setSize(104, 30)
lastNode.setColor(0.7, 0.7, 0.7)
groupOutput1 = lastNode
del lastNode
# End of node "Output1"
# Now that all nodes are created we can connect them together, restore expressions
groupLumaWave.connectInput(0, groupGamma1)
groupGamma1.connectInput(0, groupInput)
groupRGBWave.connectInput(0, groupGamma1)
groupGamma2.connectInput(0, groupRGBWave)
groupSwitch1.connectInput(0, groupLumaWave)
groupSwitch1.connectInput(1, groupGamma2)
groupOutput1.connectInput(0, groupSwitch1)
param = groupLumaWave.getParam("paramValueInt0")
param.setExpression("thisGroup.accel.get()", False, 0)
del param
param = groupGamma1.getParam("value")
group.getParam("Gamma1value").setAsAlias(param)
del param
param = groupRGBWave.getParam("paramValueInt0")
param.setExpression("thisGroup.accel.get()", False, 0)
del param
param = groupSwitch1.getParam("which")
param.setExpression("thisGroup.rgb.get()", False, 0)
del param
try:
extModule = sys.modules["WaveFormExt"]
except KeyError:
extModule = None
if extModule is not None and hasattr(extModule ,"createInstanceExt") and hasattr(extModule.createInstanceExt,"__call__"):
extModule.createInstanceExt(app,group)