transport.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. this.initialize = function () {
  2. //this.createTransportVis();
  3. }
  4. this.simpleVis = function () {
  5. return {
  6. "extends": "proxy/two/rectangle.vwf",
  7. "properties": {
  8. "height": 25,
  9. "width": 25,
  10. "fill": "#ddd"
  11. }
  12. }
  13. }
  14. this.stop = function () {
  15. this.animationStop();
  16. this.playing = false;
  17. }
  18. this.play = function () {
  19. this.beat = 0;
  20. this.animationPlay(0, this.animationDuration);
  21. this.playing = true;
  22. }
  23. this.setupTransport = function () {
  24. this.beat = 0;
  25. this.animationLoop = true;
  26. this.animationDuration = 1;
  27. this.animationRate = 1;
  28. this.animationTPS = 30;
  29. //this.animationPlay(0,1);
  30. }
  31. this.animationUpdate = function (time, duration) {
  32. //let sceneID = this.find("/")[0].id
  33. let rate = this.animationTPS / this.animationRate; // 60/1 by default
  34. var b = this.beat;
  35. //console.log('b: ' + this.beat + ' t: ' + time + ' ta: ' + this.time);
  36. if (time == this.animationDuration) { //time == 1 &&
  37. this.beat = 0;
  38. //this.doGlobalBeat(time, duration, b);
  39. } else {
  40. if(this.beat !== rate) {
  41. this.doGlobalBeat(time, duration, b)
  42. }
  43. this.beat = this.beat + 1;
  44. }
  45. }
  46. this.resetVisual = function(){
  47. this.vis.fill = "#ddd";
  48. }
  49. this.changeVisual = function(){
  50. this.vis.fill = "green";
  51. //this.future(0.5).resetVisual();
  52. }
  53. this.doGlobalBeat = function (time, duration, beat) {
  54. this.changeVisual();
  55. let allChilds = this.find("//element(*,'proxy/two/node.vwf')"); //this.children
  56. allChilds.forEach(el => {
  57. if (el.globalBeat) {
  58. let obj = {
  59. name: this.name,
  60. time: time,
  61. duration: duration,
  62. beat: beat
  63. }
  64. el.onGlobalBeat(obj);
  65. }
  66. })
  67. }
  68. this.init = function () {
  69. this.children.create("vis", this.simpleVis(), function (child) {
  70. child.mousedownEvent = function () {
  71. if (this.parent.animationPlaying) {
  72. this.parent.stop();
  73. this.parent.resetVisual();
  74. } else {
  75. this.parent.play();
  76. this.parent.changeVisual();
  77. }
  78. }
  79. });
  80. this.setupTransport();
  81. //this.play();
  82. }