|
@@ -0,0 +1,107 @@
|
|
|
+this.initialize = function () {
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+this.simpleVis = function () {
|
|
|
+ return {
|
|
|
+ "extends": "proxy/two/rectangle.vwf",
|
|
|
+ "properties": {
|
|
|
+ "height": 25,
|
|
|
+ "width": 25,
|
|
|
+ "fill": "#ddd"
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+this.stop = function () {
|
|
|
+
|
|
|
+ this.animationStop();
|
|
|
+ this.playing = false;
|
|
|
+}
|
|
|
+
|
|
|
+this.play = function () {
|
|
|
+
|
|
|
+ this.beat = 0;
|
|
|
+ this.animationPlay(0, this.animationDuration);
|
|
|
+ this.playing = true;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+this.setupTransport = function () {
|
|
|
+ this.beat = 0;
|
|
|
+ this.animationLoop = true;
|
|
|
+ this.animationDuration = 1;
|
|
|
+ this.animationRate = 1;
|
|
|
+ this.animationTPS = 30;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+this.animationUpdate = function (time, duration) {
|
|
|
+
|
|
|
+ let rate = this.animationTPS / this.animationRate;
|
|
|
+
|
|
|
+ var b = this.beat;
|
|
|
+
|
|
|
+
|
|
|
+ if (time == this.animationDuration) {
|
|
|
+ this.beat = 0;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if(this.beat !== rate) {
|
|
|
+ this.doGlobalBeat(time, duration, b)
|
|
|
+ }
|
|
|
+
|
|
|
+ this.beat = this.beat + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+this.resetVisual = function(){
|
|
|
+ this.vis.fill = "#ddd";
|
|
|
+}
|
|
|
+
|
|
|
+this.changeVisual = function(){
|
|
|
+ this.vis.fill = "green";
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+this.doGlobalBeat = function (time, duration, beat) {
|
|
|
+
|
|
|
+this.changeVisual();
|
|
|
+
|
|
|
+ let allChilds = this.find("//element(*,'proxy/two/node.vwf')");
|
|
|
+ allChilds.forEach(el => {
|
|
|
+ if (el.globalBeat) {
|
|
|
+ let obj = {
|
|
|
+ name: this.name,
|
|
|
+ time: time,
|
|
|
+ duration: duration,
|
|
|
+ beat: beat
|
|
|
+ }
|
|
|
+ el.onGlobalBeat(obj);
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+this.init = function () {
|
|
|
+
|
|
|
+
|
|
|
+ this.children.create("vis", this.simpleVis(), function (child) {
|
|
|
+
|
|
|
+ child.mousedownEvent = function () {
|
|
|
+ if (this.parent.animationPlaying) {
|
|
|
+ this.parent.stop();
|
|
|
+ this.parent.resetVisual();
|
|
|
+ } else {
|
|
|
+ this.parent.play();
|
|
|
+ this.parent.changeVisual();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ this.setupTransport();
|
|
|
+
|
|
|
+}
|