PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/nodes/vvvv.nodes.animation.js

https://github.com/imclab/vvvv.js
JavaScript | 738 lines | 494 code | 162 blank | 82 comment | 113 complexity | 3f4228d17b01f028f15a80811e95fb86 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, BSD-2-Clause
  1. // VVVV.js -- Visual Web Client Programming
  2. // (c) 2011 Matthias Zauner
  3. // VVVV.js is freely distributable under the MIT license.
  4. // Additional authors of sub components are mentioned at the specific code locations.
  5. /*
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. NODE: LFO (Animation)
  8. Author(s): Matthias Zauner, sebl
  9. Original Node Author(s): VVVV Group
  10. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. */
  12. VVVV.Nodes.LFO = function(id, graph) {
  13. this.constructor(id, "LFO (Animation)", graph);
  14. this.meta = {
  15. authors: ['Matthias Zauner, sebl'],
  16. original_authors: ['VVVV Group'],
  17. credits: [],
  18. compatibility_issues: ['Not spreadable yet']
  19. };
  20. this.auto_evaluate = true;
  21. var PeriodIn = this.addInputPin('Period', [1.0], this);
  22. var PauseIn = this.addInputPin("Pause", [0], this);
  23. var ReverseIn = this.addInputPin("Reverse", [0], this);
  24. var ResetIn = this.addInputPin("Reset", [0], this);
  25. var PhaseIn = this.addInputPin("Phase", [0.0], this);
  26. var outputOut = this.addOutputPin("Output", [0.0], this);
  27. var CyclesOut = this.addOutputPin("Cycles", [0], this);
  28. var current = [];
  29. var cycles = [];
  30. var dt = new Date().getTime();
  31. var lastUpdate = new Date().getTime();
  32. this.evaluate = function() {
  33. var maxSize = this.getMaxInputSliceCount();
  34. dt = new Date().getTime()-lastUpdate;
  35. for (var i=0; i<maxSize; i++) {
  36. var period = PeriodIn.getValue(i % PeriodIn.values.length);
  37. var paused = PauseIn.getValue(i % PauseIn.values.length);
  38. var reverse = ReverseIn.getValue(i % ReverseIn.values.length);
  39. var reset = ResetIn.getValue(i % ResetIn.values.length);
  40. var phase = PhaseIn.getValue(i % PhaseIn.values.length);
  41. if (current[i]==undefined) current[i] = 0.0;
  42. if (cycles[i]==undefined) cycles[i] = 0.0;
  43. if (paused<=0 && period!=0 && isFinite(period)) {
  44. dv = (1/(period*1000)*dt);
  45. if (reverse>0){
  46. dv *= -1;
  47. }
  48. current[i] += dv;
  49. if (current[i]<0) {
  50. cycles[i] -= Math.ceil(-current[i]);
  51. current[i] = 1.0 + current[i];
  52. }
  53. if (current[i]>1){
  54. cycles[i] += Math.floor(current[i]);
  55. }
  56. }
  57. lastUpdate = new Date().getTime();
  58. if (reset>0){
  59. current[i] = 0.0;
  60. }
  61. if (paused<0.5) {
  62. outputOut.setValue(i, (current[i]+phase)%1);
  63. CyclesOut.setValue(i, cycles[i]);
  64. }
  65. current[i] = current[i] %1;
  66. }
  67. outputOut.setSliceCount(maxSize);
  68. CyclesOut.setSliceCount(maxSize);
  69. current.splice(maxSize);
  70. cycles.splice(maxSize);
  71. }
  72. }
  73. VVVV.Nodes.LFO.prototype = new VVVV.Core.Node();
  74. /*
  75. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. NODE: LinearFilter (Animation)
  77. Author(s): Matthias Zauner
  78. Original Node Author(s): VVVV Group
  79. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. */
  81. VVVV.Nodes.LinearFilter = function(id, graph) {
  82. this.constructor(id, "LinearFilter (Animation)", graph);
  83. this.meta = {
  84. authors: ['Matthias Zauner'],
  85. original_authors: ['VVVV Group'],
  86. credits: [],
  87. compatibility_issues: ['Sometimes doesnt stop when target reached', 'Cyclic Pin not implemented', 'Acceleration and Velocitity Out are not set yet']
  88. };
  89. this.auto_evaluate = true;
  90. var positionIn = this.addInputPin("Go To Position", [0.0], this);
  91. var filterTimeIn = this.addInputPin("FilterTime", [1.0], this);
  92. var positionOut = this.addOutputPin("Position Out", [0.0], this);
  93. var velocityOut = this.addOutputPin("Velocity Out", [0.0], this);
  94. var accelerationOut = this.addOutputPin("Acceleration Out", [0.0], this);
  95. var lastUpdate = [];
  96. var currPos = [];
  97. var velocity = [];
  98. var deltaPos = [];
  99. var direction = [];
  100. function sign(n) {
  101. return n>=0;
  102. }
  103. this.evaluate = function() {
  104. var maxSize = this.getMaxInputSliceCount();
  105. var pinsChanged = positionIn.pinIsChanged() || filterTimeIn.pinIsChanged();
  106. for (var i=0; i<maxSize; i++) {
  107. if (lastUpdate[i]==undefined)
  108. lastUpdate[i] = new Date().getTime();
  109. var dt = new Date().getTime()-lastUpdate[i];
  110. var targetPos = parseFloat(positionIn.getValue(i));
  111. var filterTime = parseFloat(filterTimeIn.getValue(i));
  112. if (currPos[i]==undefined)
  113. currPos[i] = targetPos;
  114. if (!isFinite(targetPos) || !isFinite(filterTime)) {
  115. currPos[i] = undefined;
  116. positionOut.setValue(i, undefined);
  117. continue;
  118. }
  119. if (pinsChanged) {
  120. deltaPos[i] = undefined;
  121. direction[i] = sign(targetPos-currPos[i]);
  122. if (filterTime>0)
  123. velocity[i] = (targetPos-currPos[i])/(filterTime*1000);
  124. else
  125. velocity[i] = 0;
  126. }
  127. if (direction[i] == sign(targetPos-currPos[i]))
  128. currPos[i] += velocity[i]*dt;
  129. if (deltaPos[i]!=undefined && sign(targetPos-currPos[i]) != sign(deltaPos[i])) {
  130. velocity[i] = 0;
  131. currPos[i] = targetPos;
  132. }
  133. if (deltaPos[i]!=0)
  134. positionOut.setValue(i, currPos[i]);
  135. deltaPos[i] = targetPos - currPos[i];
  136. lastUpdate[i] = new Date().getTime();
  137. }
  138. if (pinsChanged && positionOut.getSliceCount()!=maxSize) {
  139. lastUpdate.splice(maxSize);
  140. currPos.splice(maxSize);
  141. velocity.splice(maxSize);
  142. deltaPos.splice(maxSize);
  143. positionOut.setSliceCount(maxSize);
  144. }
  145. }
  146. }
  147. VVVV.Nodes.LinearFilter.prototype = new VVVV.Core.Node();
  148. /*
  149. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. NODE: Delay (Animation)
  151. Author(s): Matthias Zauner
  152. Original Node Author(s): VVVV Group
  153. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154. */
  155. VVVV.Nodes.Delay = function(id, graph) {
  156. this.constructor(id, "Delay (Animation)", graph);
  157. this.meta = {
  158. authors: ['Matthias Zauner'],
  159. original_authors: ['VVVV Group'],
  160. credits: [],
  161. compatibility_issues: ['Reset not implemented', 'Linear Mode not implemented']
  162. };
  163. this.auto_evaluate = true;
  164. var inputIn = this.addInputPin("Input", [0.0], this);
  165. var timeIn = this.addInputPin("Time", [1.0], this);
  166. var insertIn = this.addInputPin("Insert", [1], this);
  167. var outputOut = this.addOutputPin("Output", [0.0], this);
  168. var queue = [];
  169. var times = new Array(1024);
  170. /*function reset(value) {
  171. for (var i=0; i<1024; i++) {
  172. queue[i] = value;
  173. times[i] = 0.0;
  174. }
  175. }
  176. reset(0.0);
  177. */
  178. this.evaluate = function() {
  179. var maxSize = this.getMaxInputSliceCount();
  180. now = new Date().getTime();
  181. var pinChanged = inputIn.pinIsChanged();
  182. if (inputIn.getValue(0)==undefined) {
  183. if (pinChanged) {
  184. outputOut.setValue(0, undefined);
  185. }
  186. return;
  187. }
  188. if (insertIn.getValue(0)==1 && (pinChanged || timeIn.pinIsChanged())) {
  189. times.pop();
  190. times.unshift(now);
  191. for (var i=0; i<maxSize; i++) {
  192. if (queue[i]==undefined) {
  193. queue[i] = new Array(1024);
  194. var j = 1024;
  195. while (j--) {
  196. queue[i][j] = 0.0;
  197. }
  198. }
  199. if (queue[i].length>=1024)
  200. queue[i].pop();
  201. queue[i].unshift(inputIn.getValue(i));
  202. }
  203. }
  204. for (var i=0; i<maxSize; i++) {
  205. var dt = now - timeIn.getValue(i)*1000;
  206. var found = false;
  207. for (j=0; j<1024; j++) {
  208. if (times[j]<=dt) {
  209. if (outputOut.values[i]!=queue[i][j]) {
  210. outputOut.setValue(i, queue[i][j]);
  211. }
  212. found = true;
  213. break;
  214. }
  215. }
  216. if (!found && outputOut.values[i]!=0.0) {
  217. outputOut.setValue(i, 0.0);
  218. }
  219. }
  220. outputOut.setSliceCount(maxSize);
  221. queue.splice(maxSize);
  222. }
  223. }
  224. VVVV.Nodes.Delay.prototype = new VVVV.Core.Node();
  225. /*
  226. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  227. NODE: Change (Animation)
  228. Author(s): Matthias Zauner
  229. Original Node Author(s): VVVV Group
  230. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. */
  232. VVVV.Nodes.Change = function(id, graph) {
  233. this.constructor(id, "Change (Animation)", graph);
  234. this.meta = {
  235. authors: ['Matthias Zauner'],
  236. original_authors: ['VVVV Group'],
  237. credits: [],
  238. compatibility_issues: []
  239. };
  240. this.auto_evaluate = true;
  241. var inputIn = this.addInputPin("Input", [0.0], this);
  242. var changeOut = this.addOutputPin("OnChange", [0], this);
  243. var values = [];
  244. this.evaluate = function() {
  245. var maxSize = this.getMaxInputSliceCount();
  246. if (inputIn.pinIsChanged()) {
  247. for (var i=0; i<maxSize; i++) {
  248. if (values[i]!=inputIn.getValue(i)) {
  249. changeOut.setValue(i, 1);
  250. }
  251. else if (changeOut.getValue(i)==1)
  252. changeOut.setValue(i, 0);
  253. values[i] = inputIn.getValue(i);
  254. }
  255. changeOut.setSliceCount(maxSize);
  256. }
  257. else {
  258. for (var i=0; i<maxSize; i++) {
  259. if (changeOut.getValue(i)==1) {
  260. changeOut.setValue(i, 0);
  261. changeOut.setSliceCount(maxSize);
  262. }
  263. }
  264. values[i] = inputIn.getValue(i);
  265. }
  266. }
  267. }
  268. VVVV.Nodes.Change.prototype = new VVVV.Core.Node();
  269. /*
  270. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  271. NODE: TogEdge (Animation)
  272. Author(s): Matthias Zauner
  273. Original Node Author(s): VVVV Group
  274. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  275. */
  276. VVVV.Nodes.TogEdge = function(id, graph) {
  277. this.constructor(id, "TogEdge (Animation)", graph);
  278. this.meta = {
  279. authors: ['Matthias Zauner'],
  280. original_authors: ['VVVV Group'],
  281. credits: [],
  282. compatibility_issues: []
  283. };
  284. this.auto_evaluate = true;
  285. var inputIn = this.addInputPin("Input", [0.0], this);
  286. var upOut = this.addOutputPin("Up Edge", [0], this);
  287. var downOut = this.addOutputPin("Down Edge", [0], this);
  288. var values = [];
  289. this.evaluate = function() {
  290. var maxSize = this.getMaxInputSliceCount();
  291. for (var i=0; i<maxSize; i++) {
  292. if ((Math.round(values[i])<=0 || values[i]==undefined) && Math.round(inputIn.getValue(i))>=1)
  293. upOut.setValue(i, 1);
  294. else if (upOut.values[i]!=0)
  295. upOut.setValue(i, 0);
  296. if (Math.round(values[i])>=1 && Math.round(inputIn.getValue(i))<=0)
  297. downOut.setValue(i, 1);
  298. else if (downOut.values[i]!=0)
  299. downOut.setValue(i, 0);
  300. values[i] = inputIn.getValue(i);
  301. }
  302. upOut.setSliceCount(maxSize);
  303. downOut.setSliceCount(maxSize);
  304. }
  305. }
  306. VVVV.Nodes.TogEdge.prototype = new VVVV.Core.Node();
  307. /*
  308. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  309. NODE: FlipFlop (Animation)
  310. Author(s): Matthias Zauner
  311. Original Node Author(s): VVVV Group
  312. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  313. */
  314. VVVV.Nodes.FlipFlop = function(id, graph) {
  315. this.constructor(id, "FlipFlop (Animation)", graph);
  316. this.meta = {
  317. authors: ['Matthias Zauner'],
  318. original_authors: ['VVVV Group'],
  319. credits: [],
  320. compatibility_issues: []
  321. };
  322. var setIn = this.addInputPin("Set", [0], this);
  323. var resetIn = this.addInputPin("Reset", [0], this);
  324. var outputOut = this.addOutputPin("Output", [0], this);
  325. var inverseOutputOut = this.addOutputPin("Inverse Output", [1], this);
  326. var initialized = false;
  327. this.evaluate = function() {
  328. var maxSize = this.getMaxInputSliceCount();
  329. var currSize = outputOut.getSliceCount();
  330. if (maxSize>currSize) {
  331. for (var i=currSize; i<maxSize; i++) {
  332. outputOut.setValue(i, 0);
  333. inverseOutputOut.setValue(i, 1);
  334. }
  335. }
  336. for (var i=0; i<maxSize; i++) {
  337. var result = undefined;
  338. if (Math.round(resetIn.getValue(i))>=1)
  339. result = 0;
  340. if (Math.round(setIn.getValue(i))>=1)
  341. result = 1;
  342. if (result!=undefined) {
  343. outputOut.setValue(i, result);
  344. inverseOutputOut.setValue(i, 1-result);
  345. }
  346. else if (!initialized) {
  347. outputOut.setValue(i, 0);
  348. inverseOutputOut.setValue(i, 1);
  349. }
  350. }
  351. outputOut.setSliceCount(maxSize);
  352. inverseOutputOut.setSliceCount(maxSize);
  353. initialized = true;
  354. }
  355. }
  356. VVVV.Nodes.FlipFlop.prototype = new VVVV.Core.Node();
  357. /*
  358. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  359. NODE: S+H (Animation)
  360. Author(s): Matthias Zauner
  361. Original Node Author(s): VVVV Group
  362. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  363. */
  364. VVVV.Nodes.SampleAndHold = function(id, graph) {
  365. this.constructor(id, "S+H (Animation)", graph);
  366. this.meta = {
  367. authors: ['Matthias Zauner'],
  368. original_authors: ['VVVV Group'],
  369. credits: [],
  370. compatibility_issues: ['different output slice count in pure VVVV, if Set pin has only one slice']
  371. };
  372. var inputIn = this.addInputPin("Input", [0.0], this);
  373. var setIn = this.addInputPin("Set", [0], this);
  374. var outputOut = this.addOutputPin("Output", [0.0], this);
  375. this.evaluate = function() {
  376. var maxSize = this.getMaxInputSliceCount();
  377. if (setIn.pinIsChanged() || inputIn.pinIsChanged()) {
  378. for (var i=0; i<maxSize; i++) {
  379. if (outputOut.values[i]==undefined) {
  380. outputOut.setValue(i, 0.0);
  381. }
  382. if (Math.round(setIn.getValue(i))>=1) {
  383. outputOut.setValue(i, inputIn.getValue(i));
  384. }
  385. }
  386. outputOut.setSliceCount(maxSize);
  387. }
  388. }
  389. }
  390. VVVV.Nodes.SampleAndHold.prototype = new VVVV.Core.Node();
  391. /*
  392. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393. NODE: FrameDelay (Animation)
  394. Author(s): Matthias Zauner
  395. Original Node Author(s): VVVV Group
  396. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  397. */
  398. VVVV.Nodes.FrameDelay = function(id, graph) {
  399. this.constructor(id, "FrameDelay (Animation)", graph);
  400. this.meta = {
  401. authors: ['Matthias Zauner'],
  402. original_authors: ['VVVV Group'],
  403. credits: [],
  404. compatibility_issues: ['no dynamice pin count']
  405. };
  406. this.delays_output = true;
  407. var input1In = this.addInputPin("Input 1", [0.0], this);
  408. var default1In = this.addInputPin("Default 1", [0.0], this);
  409. var initIn = this.addInputPin("Initialize", [0], this);
  410. var output1Out = this.addOutputPin("Output 1", [0.0], this);
  411. this.evaluate = function() {
  412. var maxSize = this.getMaxInputSliceCount();
  413. for (var i=0; i<maxSize; i++) {
  414. if (initIn.getValue(i)>0.5)
  415. output1Out.setValue(i, default1In.getValue(i));
  416. else
  417. output1Out.setValue(i, input1In.getValue(i));
  418. }
  419. output1Out.setSliceCount(maxSize);
  420. }
  421. }
  422. VVVV.Nodes.FrameDelay.prototype = new VVVV.Core.Node();
  423. /*
  424. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  425. NODE: Toggle (Animation)
  426. Author(s): David Mórász (micro.D)
  427. Original Node Author(s): VVVV Group
  428. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  429. */
  430. VVVV.Nodes.Toggle = function(id, graph) {
  431. this.constructor(id, "Toggle (Animation)", graph);
  432. this.meta = {
  433. authors: ['David Mórász (micro.D)'],
  434. original_authors: ['VVVV Group'],
  435. credits: ['Matthias Zauner'],
  436. compatibility_issues: []
  437. };
  438. this.auto_evaluate = true;
  439. var inputIn = this.addInputPin("Input", [0], this);
  440. var resetIn = this.addInputPin("Reset", [0], this);
  441. var outputOut = this.addOutputPin("Output", [0], this);
  442. var inverseOutputOut = this.addOutputPin("Inverse Output", [1], this);
  443. var initialized = false;
  444. this.evaluate = function() {
  445. var maxSize = this.getMaxInputSliceCount();
  446. var currSize = outputOut.getSliceCount();
  447. if (maxSize>currSize) {
  448. for (var i=currSize; i<maxSize; i++) {
  449. outputOut.setValue(i, 0);
  450. inverseOutputOut.setValue(i, 1);
  451. }
  452. }
  453. for (var i=0; i<maxSize; i++) {
  454. var result = undefined;
  455. if (Math.round(resetIn.getValue(i))>=1)
  456. result = 0;
  457. if (Math.round(inputIn.getValue(i))>=1)
  458. result = 1 - parseFloat(outputOut.getValue(i));
  459. if (result!=undefined && outputOut.getValue(i)!=result) {
  460. outputOut.setValue(i, result);
  461. inverseOutputOut.setValue(i, 1-result);
  462. }
  463. else if (!initialized) {
  464. outputOut.setValue(i, 0);
  465. inverseOutputOut.setValue(i, 1);
  466. }
  467. }
  468. outputOut.setSliceCount(maxSize);
  469. inverseOutputOut.setSliceCount(maxSize);
  470. initialized = true;
  471. }
  472. }
  473. VVVV.Nodes.Toggle.prototype = new VVVV.Core.Node();
  474. /*
  475. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  476. NODE: Counter (Animation)
  477. Author(s): David Mórász (micro.D)
  478. Original Node Author(s): VVVV Group
  479. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  480. */
  481. VVVV.Nodes.Counter = function(id, graph) {
  482. this.constructor(id, "Counter (Animation)", graph);
  483. this.meta = {
  484. authors: ['David Mórász (micro.D)', 'Matthias Zauner'],
  485. original_authors: ['VVVV Group'],
  486. credits: [],
  487. compatibility_issues: []
  488. };
  489. this.auto_evaluate = true;
  490. var upIn = this.addInputPin("Up", [0], this);
  491. var downIn = this.addInputPin("Down", [0], this);
  492. var minIn = this.addInputPin("Minimum", [0], this);
  493. var maxIn = this.addInputPin("Maximum", [15], this);
  494. var incrIn = this.addInputPin("Increment", [1], this);
  495. var defaultIn = this.addInputPin("Default", [0], this);
  496. var resetIn = this.addInputPin("Reset", [0], this);
  497. var modeIn = this.addInputPin("Mode", ['Wrap'], this);
  498. var outputOut = this.addOutputPin("Output", [0.0], this);
  499. var uflowOut = this.addOutputPin("Underflow", [0.0], this);
  500. var oflowOut = this.addOutputPin("Overflow", [0.0], this);
  501. var initialized = false;
  502. this.evaluate = function() {
  503. var maxSize = this.getMaxInputSliceCount();
  504. var doCount = minIn.pinIsChanged() || maxIn.pinIsChanged() || defaultIn.pinIsChanged() || resetIn.pinIsChanged() || modeIn.pinIsChanged();
  505. for (var i=0; i<maxSize; i++) {
  506. if (oflowOut.getValue(i)==1 || !initialized)
  507. oflowOut.setValue(i, 0);
  508. if (uflowOut.getValue(i)==1 || !initialized)
  509. uflowOut.setValue(i, 0);
  510. if (!initialized)
  511. outputOut.setValue(i, 0);
  512. doCount = doCount || upIn.getValue(i)>=.5 || downIn.getValue(i)>=.5;
  513. }
  514. if(doCount)
  515. {
  516. for(var i=0; i<maxSize; i++) {
  517. var incr = parseFloat(incrIn.getValue(i));
  518. var output = i>=outputOut.getSliceCount() ? 0.0 : parseFloat(outputOut.getValue(i));
  519. var max = parseFloat(maxIn.getValue(i));
  520. var min = parseFloat(minIn.getValue(i));
  521. var mode = 0;
  522. if(modeIn.getValue(i)=='Unlimited') mode=1;
  523. if(modeIn.getValue(i)=='Clamp') mode=2;
  524. switch(mode) {
  525. case 1:
  526. if(upIn.getValue(i)>=.5) {
  527. output = output + incr;
  528. }
  529. if(downIn.getValue(i)>=.5) {
  530. output = output - incr;
  531. }
  532. break;
  533. case 2:
  534. if(upIn.getValue(i)>=.5) {
  535. output = output + incr;
  536. }
  537. if(downIn.getValue(i)>=.5) {
  538. output = output - incr;
  539. }
  540. if(output>max) {
  541. output = max;
  542. oflowOut.setValue(i, 1);
  543. }
  544. if(output<min) {
  545. output = min;
  546. uflowOut.setValue(i, 1);
  547. }
  548. break;
  549. default:
  550. if(upIn.getValue(i)>=.5) {
  551. output = output + incr;
  552. }
  553. if(downIn.getValue(i)>=.5) {
  554. output = output - incr;
  555. }
  556. if(output>max) {
  557. output = min;
  558. oflowOut.setValue(i, 1);
  559. }
  560. if(output<min) {
  561. output = max;
  562. uflowOut.setValue(i, 1);
  563. }
  564. }
  565. if (outputOut.getValue(i)!=output)
  566. outputOut.setValue(i, output);
  567. if(resetIn.getValue(i)>=.5) outputOut.setValue(i, defaultIn.getValue(i));
  568. }
  569. outputOut.setSliceCount(maxSize);
  570. uflowOut.setSliceCount(maxSize);
  571. oflowOut.setSliceCount(maxSize);
  572. }
  573. initialized = true;
  574. }
  575. }
  576. VVVV.Nodes.Counter.prototype = new VVVV.Core.Node();