| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 | /*The MIT License (MIT)Copyright (c) 2014-2020 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)*/// VWF & Tone driverimport {Fabric} from '/core/vwf/fabric.js';//import * as Tone from '/drivers/view/tonejs/dist/Tone.js';class ToneViewDriver extends Fabric {  constructor(module) {    console.log("ToneViewDriver constructor");    super(module, 'View');  }  factory() {    let _self_ = this;	return this.load(this.module, 		{			initialize: function() {								let self = this;				this.fabric = _self_;				this.nodes = {};				// document.querySelector("button").addEventListener("click", async () => {				// 	await Tone.start();				// 	console.log("context started");				// });				//window._Tone = Tone.default;				// this.osc = osc;				// this.portValue = '8081';				// this.hostValue = 'localhost';				// this.port = null;					//window._osc = this.osc;				// window._OSCManager = this;				},			createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,                childSource, childType, childIndex, childName, callback /* ( ready ) */) {                let self = this;                var node = this.state.nodes[childID];                    // If the "nodes" object does not have this object in it, it must not be one that                // this driver cares about                if (!node) {                    return;				}						this.nodes[childID] = {					id: childID,					extends: childExtendsID,					parent: nodeID,					toneObj: node.toneObj				};								//parent: this.state.nodes[childID].aframeObj			},				firedEvent: function (nodeID, eventName, eventParameters) {			 				let self = this;					// if (eventName == 'sendOSC'){						// var clientThatSatProperty = self.kernel.client();					// var me = self.kernel.moniker();							// // If the transform property was initially updated by this view....					// if (clientThatSatProperty == me) {							// 	if (self.osc !== null) {					// 		if (self.getStatus() == 1) {					// 			self.port.send(eventParameters[0]);					// 			console.log('send: ' + eventParameters[0]);					// 		}					// 	}					// }								// }							},					/*			 * Receives incoming messages			 */			calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {						let self = this;				let node = this.state.nodes[nodeID];                    // If the "nodes" object does not have this object in it, it must not be one that                // this driver cares about                if (!node) {                    return;				}				if (methodName == "triggerAttackRelease") {										if(node.toneObj){						const now = Tone.now()						let notes = methodParameters[0];						// let notes = methodParameters[0].map(el=>{						// 	return Tone.Frequency(el).toNote();						// }) 						if (self.state.isMembraneSynthDefinition(node.prototypes)) {							node.toneObj.triggerAttackRelease(notes[0], methodParameters[1][0], now);						} else if(self.state.isNoiseSynthDefinition(node.prototypes)) {							node.toneObj.triggerAttackRelease("16n", now)						} 						else {							node.toneObj.triggerAttackRelease(notes, methodParameters[1], now, methodParameters[2])						}											}									}				if (methodName == "triggerAttack") {										if(node.toneObj){						const now = Tone.now()						node.toneObj.triggerAttack(methodParameters[0], now, methodParameters[1])					}									}				if (methodName == "triggerRelease") {										if(node.toneObj){						node.toneObj.triggerRelease(methodParameters[0], "+0.1")					}									}								},							});		}}export { ToneViewDriver as default }
 |