Browse Source

add transport example

Nikolay Suslov 6 years ago
parent
commit
7e82115241

+ 45 - 0
public/defaults/proxy/vwf.example.com/aframe/aentity.js

@@ -140,3 +140,48 @@ this.updateMethod = function (methodName, methodBody, params) {
 this.callMethod = function(methodName, params){
     vwf_view.kernel.callMethod(this.id, methodName, params)
 }
+
+this.step = function(){
+
+    if (this.stepping){
+        this.do();
+    }
+    
+    let t = this.stepTime ? this.stepTime: 0.05;
+
+    this.future(t).step();
+}
+
+this.onGlobalBeat = function(obj) {
+    //dispatch the beat example send OSC
+    let transportNode = this.find('//' + obj.name)[0];
+    let rate = transportNode.animationRate; // 1 by default
+    let drumSeq = [
+    {beat:0, msg: 0},
+    {beat:30, msg: 0}];
+    drumSeq.forEach(el=>{
+      if(el.beat/rate == obj.beat){
+        let msg = {
+            address: "/trigger/sample01",
+            args: [this.time, 'bd_808', 3]
+        };
+        //for synth {beat:0, msg: "A"}
+        //let msg = {
+        // address: "/trigger/synth01",
+        // args: [this.time, 'piano', el.msg, 0.1, 1]};
+
+        // this.sendOSC(msg); 
+        // this.changeVisual();
+      }
+    })
+
+}
+
+this.changeVisual = function() {
+    //code for changing me
+    this.future(0.1).resetVisual();
+}
+
+this.resetVisual = function() {
+
+}

+ 8 - 0
public/defaults/proxy/vwf.example.com/aframe/aentity.vwf.yaml

@@ -46,6 +46,8 @@ properties:
   osc:
   ownedBy:
   class:
+  stepping:
+  globalBeat:
 events:
   positionChanged:
   rotationChanged:
@@ -92,5 +94,11 @@ methods:
     parameters:
       - methodName
       - params
+  onGlobalBeat:
+    parameters:
+      - obj
+  changeVisual:
+  resetVisual:  
+  step:
 scripts:
   - source: "http://vwf.example.com/aframe/aentity.js"

+ 117 - 0
public/defaults/proxy/vwf.example.com/aframe/transport.js

@@ -0,0 +1,117 @@
+this.initialize = function () {
+    //this.createTransportVis();
+
+}
+
+this.simpleVis = function () {
+    return {
+        "extends": "http://vwf.example.com/aframe/abox.vwf",
+        "properties": {
+            "height": 0.3,
+            "width": 0.3,
+            "depth": 0.3,
+            "class": "clickable"
+        },
+        "children": {
+            "material": {
+                "extends": "http://vwf.example.com/aframe/aMaterialComponent.vwf",
+                "type": "component",
+                "properties": {
+                    "color": "red"
+                }
+            },
+            "cursor-listener": {
+                extends: "http://vwf.example.com/aframe/app-cursor-listener-component.vwf",
+                type: "component"
+            }
+
+        }
+    }
+}
+
+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.animationPlay(0,1);
+}
+
+this.animationUpdate = function (time, duration) {
+    //let sceneID = this.find("/")[0].id
+    let rate = this.animationTPS / this.animationRate; // 60/1 by default
+
+    var b = this.beat;
+
+    //console.log('time: ' + time + ' b: ' + this.beat + ' simTime: ' + this.time);
+
+    if (b == rate + 1) { //time == 1 && 
+        this.beat = 0;
+    }
+    else {
+
+        this.doGlobalBeat(time, duration, b);
+        //vwf_view.kernel.fireEvent(this.id, "transportTick", [time, duration, this.beat]);
+
+        if (b / rate == 0) {
+            this.vis.material.color = "white";
+        } else if (b / rate == 1 / 2) {
+            this.vis.material.color = "red";
+        }
+
+        this.beat = this.beat + 1;
+
+    }
+
+
+
+
+}
+
+this.doGlobalBeat = function (time, duration, beat) {
+
+    let allChilds = this.find("//element(*,'http://vwf.example.com/aframe/aentity.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.clickEventMethod = function () {
+            if (this.parent.animationPlaying) {
+                this.parent.stop();
+            } else {
+                this.parent.play();
+            }
+        }
+
+    });
+    this.setupTransport();
+    //this.play();
+}

+ 25 - 0
public/defaults/proxy/vwf.example.com/aframe/transport.vwf.yaml

@@ -0,0 +1,25 @@
+# avatar
+# Copyright 2017 Krestianstvo.org project
+---
+extends: http://vwf.example.com/aframe/aentity.vwf
+type: "transport"
+properties:
+    beat:
+    playing:
+methods:
+    init:
+    simpleVis:
+    animationUpdate:
+        parameters:
+            - time
+            - duration 
+    play:
+    stop:
+    setupTransport:
+    doGlobalBeat:
+        parameters:
+            - time
+            - duration
+            - beat
+scripts:
+- source: "http://vwf.example.com/aframe/transport.js"

+ 5 - 0
public/defaults/worlds/orchestra/appui.js

@@ -0,0 +1,5 @@
+//-----App ui-----
+
+// function createApp() {
+//     return {}
+// }

+ 3 - 0
public/defaults/worlds/orchestra/assets.json

@@ -0,0 +1,3 @@
+{
+    
+}

+ 8 - 0
public/defaults/worlds/orchestra/index.vwf.config.yaml

@@ -0,0 +1,8 @@
+---
+info:
+  title: "VWF & AFrame Example App"
+model:
+  vwf/model/aframe:
+view:
+  vwf/view/aframe:
+  vwf/view/editor-new:

+ 260 - 0
public/defaults/worlds/orchestra/index.vwf.yaml

@@ -0,0 +1,260 @@
+# A-Frame & VWF simple scene
+# Copyright 2017 Krestianstvo.org project
+---
+extends: http://vwf.example.com/aframe/ascene.vwf
+properties:
+  transparent: true
+  assets: "assets.json"
+children:
+  assetBG:
+    extends: http://vwf.example.com/aframe/a-asset-image-item.vwf
+    properties:
+      itemID: "bg"
+      itemSrc: "/defaults/assets/bg.jpg"
+  assetSky:
+    extends: http://vwf.example.com/aframe/a-asset-image-item.vwf
+    properties:
+      itemID: "sky"
+      itemSrc: "/defaults/assets/skyes/sky3.jpg"
+  assetBG2:
+    extends: http://vwf.example.com/aframe/a-asset-image-item.vwf
+    properties:
+      itemID: "bg2"
+      itemSrc: "/defaults/assets/checker.jpg"
+  myLight:
+    extends: http://vwf.example.com/aframe/alight.vwf
+    properties:
+      type: "directional"
+      intensity: 0.5
+      position: "0.5 2.0 1.0"
+      castShadow: true
+  myLight2:
+    extends: http://vwf.example.com/aframe/alight.vwf
+    properties:
+      type: "ambient"
+      intensity: 0.5
+  spaceText:
+    extends: http://vwf.example.com/aframe/atext.vwf
+    properties:
+      value: "Collaborative Orchestra"
+      color: "#ddd"
+      position: "-2 2.5 -2"
+  spaceText2:
+    extends: http://vwf.example.com/aframe/atext.vwf
+    properties:
+      value: "Project by LiveCoding.space"
+      color: "#aaa"
+      position: "1 3 -4"
+  globalTransport:
+    extends: http://vwf.example.com/aframe/transport.vwf
+    properties:
+      position: "2 2 -3"
+  bdrum:
+    extends: http://vwf.example.com/aframe/abox.vwf
+    properties:
+      position: "0 0 -3"
+      rotation: "0 0 0"
+      depth: 1
+      height: 1
+      width: 1
+      class: "hit clickable"
+      globalBeat: true
+    methods:
+      changeVisual:
+        body: | 
+              this.material.color = "white";
+              this.scale = "1.1 1.1 1.1";
+              this.future(0.1).resetVisual();
+      resetVisual:
+        body: | 
+              this.material.color = "red";
+              this.scale = "1 1 1";  
+      onGlobalBeat:
+        parameters:
+          - obj
+        body: |
+                let transportNode = this.find('//' + obj.name)[0];
+                let rate = transportNode.animationRate; // 1 by default
+                let drumSeq = [{beat:0, msg: 0}];
+                drumSeq.forEach(el=>{
+                  if(el.beat/rate == obj.beat){
+                    let msg = {
+                        address: "/trigger/sample01",
+                        args: [this.time, 'bd_808', 3]
+                    };
+                    this.sendOSC(msg); 
+                    this.changeVisual();
+                  }
+                })
+      hitstartEventMethod:
+        body: |
+              this.material.opacity = 0.7
+      hitendEventMethod:
+        body: |
+              this.material.opacity = 1.0
+      clickEventMethod:
+        body: |
+              this.globalBeat = !this.globalBeat
+    children:
+      aabb-collider-listener:
+        extends: http://vwf.example.com/aframe/app-aabb-collider-listener-component.vwf
+        type: "component"
+      cursor-listener:
+        extends: http://vwf.example.com/aframe/app-cursor-listener-component.vwf
+        type: "component"
+      material:
+        extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
+        properties:
+          color: "red"
+  hatt:
+    extends: http://vwf.example.com/aframe/acone.vwf
+    properties:
+      position: "-2 0 -3"
+      rotation: "0 0 0"
+      radius: 0.5
+      height: 1
+      class: "hit clickable"
+      globalBeat: true
+    methods:
+      changeVisual:
+        body: | 
+              this.material.color = "white";
+              this.scale = "1.1 1.1 1.1";
+              this.future(0.1).resetVisual();
+      resetVisual:
+        body: | 
+              this.material.color = "blue";
+              this.scale = "1 1 1";  
+      onGlobalBeat:
+        parameters:
+          - obj
+        body: |
+                let transportNode = this.find('//' + obj.name)[0];
+                let rate = transportNode.animationRate; // 1 by default
+                let drumSeq = [
+                  {beat:0, msg: 0},
+                  {beat:15, msg: 0},
+                  {beat:30, msg: 0},
+                  {beat:45, msg: 0}];
+                drumSeq.forEach(el=>{
+                  if(el.beat/rate == obj.beat){
+                    let msg = {
+                        address: "/trigger/sample02",
+                        args: [this.time, 'drum_cymbal_closed', 0.5]
+                    };
+                    this.sendOSC(msg); 
+                    this.changeVisual();
+                  }
+                })
+      hitstartEventMethod:
+        body: |
+              this.material.opacity = 0.7
+      hitendEventMethod:
+        body: |
+              this.material.opacity = 1.0
+      clickEventMethod:
+        body: |
+              this.globalBeat = !this.globalBeat
+    children:
+      aabb-collider-listener:
+        extends: http://vwf.example.com/aframe/app-aabb-collider-listener-component.vwf
+        type: "component"
+      cursor-listener:
+        extends: http://vwf.example.com/aframe/app-cursor-listener-component.vwf
+        type: "component"
+      material:
+        extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
+        properties:
+          color: "red"
+  synth:
+    extends: http://vwf.example.com/aframe/asphere.vwf
+    properties:
+      position: "2 0 -3"
+      rotation: "0 0 0"
+      radius: 0.5
+      class: "hit clickable"
+      globalBeat: true
+    methods:
+      changeVisual:
+        body: | 
+              this.material.color = "white";
+              this.scale = "1.1 1.1 1.1";
+              this.future(0.1).resetVisual();
+      resetVisual:
+        body: | 
+              this.material.color = "green";
+              this.scale = "1 1 1";  
+      onGlobalBeat:
+        parameters:
+          - obj
+        body: |
+              let transportNode = this.find('//' + obj.name)[0];
+              let rate = transportNode.animationRate; // 1 by default
+              let drumSeq = [
+                {beat:0, msg: "C3"},
+                {beat:15, msg: "E3"},
+                {beat:30, msg: "G3"},
+                {beat:45, msg: "A3"}];
+              drumSeq.forEach(el=>{
+                if(el.beat/rate == obj.beat){
+                  let msg = {
+                    address: "/trigger/synth01",
+                          args: [this.time, 'pluck', el.msg, 0.1, 0.01]
+                  };
+                  this.sendOSC(msg); 
+                  this.changeVisual();
+                }
+              })
+      hitstartEventMethod:
+        body: |
+              this.material.opacity = 0.7
+      hitendEventMethod:
+        body: |
+              this.material.opacity = 1.0
+      clickEventMethod:
+        body: |
+              this.globalBeat = !this.globalBeat
+    children:
+      aabb-collider-listener:
+        extends: http://vwf.example.com/aframe/app-aabb-collider-listener-component.vwf
+        type: "component"
+      cursor-listener:
+        extends: http://vwf.example.com/aframe/app-cursor-listener-component.vwf
+        type: "component"
+      material:
+        extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
+        properties:
+          color: "#e0e014"
+          wireframe: true
+  sky:
+    extends: http://vwf.example.com/aframe/asky.vwf
+    properties:
+    children:
+      material:
+        extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
+        properties:
+          src: "#sky"
+          side: "back"
+          fog: false
+  groundPlane:
+    extends: http://vwf.example.com/aframe/aplane.vwf
+    properties:
+      height: 50
+      width: 50
+      rotation: "-90 0 0"
+    children:
+      material:
+        extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
+        properties:
+          repeat: "10 10"
+          color: "white"
+          src: "#bg2"
+      shadow:
+        extends: http://vwf.example.com/aframe/shadowComponent.vwf
+        properties:
+          receive: true
+methods:
+  initialize:
+    body: |
+          this.globalTransport.init();
+          console.log("INIT TRANSPORT!!!");

+ 14 - 0
public/defaults/worlds/orchestra/info.json

@@ -0,0 +1,14 @@
+{
+    "info": {
+        "en": {
+            "title": "Collaborative Orchestra for VWF & Sonic Pi",
+            "imgUrl": "/defaults/worlds/aframe2/webimg.jpg",
+            "text": "Example app for making music"
+        },
+        "ru": {
+            "title": "Оркестр",
+            "imgUrl": "/defaults/worlds/aframe2/webimg.jpg",
+            "text": "Пример мира с текстурами и моделями"
+        }
+    }
+}

BIN
public/defaults/worlds/orchestra/webimg.jpg


+ 11 - 6
public/vwf/view/editor-new.js

@@ -2629,15 +2629,19 @@ define([
 
                                                     let search = this._methodName+'(';
                                                     let findLine = Object.entries(allLines).filter(el=>el[1].includes(search))[0];
-                                                    let position = {
-                                                        row: findLine[0],
-                                                        column: 0
-                                                    };
-                                                    var Range = ace.require("ace/range").Range;
-                                                    let tempString = "//CLICK FOR CALL AGAIN ";
+                                                    
 
                                                     //TODO: temporal fix for recursive future call from the editor
+                                                    if(findLine) {
                                                     if(findLine[1].includes(search)) {
+
+                                                        let position = {
+                                                            row: findLine[0],
+                                                            column: 0
+                                                        };
+                                                        var Range = ace.require("ace/range").Range;
+                                                        let tempString = "//CLICK FOR CALL AGAIN ";
+
                                                         if(findLine[1].includes(tempString)){
                                                             let newText = findLine[1].replace(tempString, "");
 
@@ -2653,6 +2657,7 @@ define([
                                                                 { body: editor.getValue(), type: "application/javascript", parameters: this._method.parameters });
                                                         }
 
+                                                    }
                                                     }
                                                     self.kernel.callMethod(this._editorNode, this._methodName, params);
                                                 }