MIDI over WebSocket

This commit is contained in:
tamat
2019-02-13 10:43:55 +01:00
parent 163f28cc29
commit 24a4f3a930
3 changed files with 40 additions and 8 deletions

View File

@@ -19263,7 +19263,23 @@ LGWebSocket.prototype.createSocket = function()
if( data.room && data.room != this.properties.room )
return;
if( e.data.type == 1 )
that.triggerSlot( 0, data );
{
if(data.data.object_class && LiteGraph[data.data.object_class] )
{
var obj = null;
try
{
obj = new LiteGraph[data.data.object_class](data.data);
that.triggerSlot( 0, obj );
}
catch (err)
{
return;
}
}
else
that.triggerSlot( 0, data.data );
}
else
that._last_received_data[ e.data.channel || 0 ] = data.data;
}

View File

@@ -543,9 +543,9 @@ for(var c=0;c<a.numberOfChannels;c++)for(var d=b.getChannelData(c),f=a.getChanne
(function(w){function c(){this.size=[60,20];this.addInput("send",r.ACTION);this.addOutput("received",r.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph",only_send_changes:!0};this._ws=null;this._last_sent_data=[];this._last_received_data=[]}function k(){this.size=[60,20];this.addInput("send",r.ACTION);this.addOutput("received",r.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"tamats.com:55000",room:"lgraph",only_send_changes:!0};
this._server=null;this.createSocket();this._last_sent_data=[];this._last_received_data=[]}var r=w.LiteGraph;c.title="WebSocket";c.desc="Send data through a websocket";c.prototype.onPropertyChanged=function(c,g){"url"==c&&this.createSocket()};c.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.createSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var c=this.properties.room,g=this.properties.only_send_changes,k=1;k<this.inputs.length;++k){var r=this.getInputData(k);
if(null!=r){var w;try{w=JSON.stringify({type:0,room:c,channel:k,data:r})}catch(v){continue}g&&this._last_sent_data[k]==w||(this._last_sent_data[k]=w,this._ws.send(w))}}for(k=1;k<this.outputs.length;++k)this.setOutputData(k,this._last_received_data[k]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};c.prototype.createSocket=function(){var c=this,g=this.properties.url;"ws"!=g.substr(0,2)&&(g="ws://"+g);this._ws=new WebSocket(g);this._ws.onopen=function(){console.log("ready");c.boxcolor="#6C6"};this._ws.onmessage=
function(g){c.boxcolor="#AFA";var k=JSON.parse(g.data);k.room&&k.room!=this.properties.room||(1==g.data.type?c.triggerSlot(0,k):c._last_received_data[g.data.channel||0]=k.data)};this._ws.onerror=function(g){console.log("couldnt connect to websocket");c.boxcolor="#E88"};this._ws.onclose=function(g){console.log("connection closed");c.boxcolor="#000"}};c.prototype.send=function(c){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:c}))};c.prototype.onAction=function(c,
g){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,room:this.properties.room,action:c,data:g})};c.prototype.onGetInputs=function(){return[["in",0]]};c.prototype.onGetOutputs=function(){return[["out",0]]};r.registerNodeType("network/websocket",c);k.title="SillyClient";k.desc="Connects to SillyServer to broadcast messages";k.prototype.onPropertyChanged=function(c,g){var k=this.properties.url+"/"+this.properties.room;this._server&&this._final_url!=k&&(this._server.connect(this.properties.url,
this.properties.room),this._final_url=k)};k.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var c=this.properties.only_send_changes,g=1;g<this.inputs.length;++g){var k=this.getInputData(g);null==k||c&&this._last_sent_data[g]==k||(this._server.sendMessage({type:0,channel:g,data:k}),this._last_sent_data[g]=k)}for(g=1;g<this.outputs.length;++g)this.setOutputData(g,this._last_received_data[g]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};k.prototype.createSocket=function(){var c=
this;"undefined"==typeof SillyClient?(this._error||console.error("SillyClient node cannot be used, you must include SillyServer.js"),this._error=!0):(this._server=new SillyClient,this._server.on_ready=function(){console.log("ready");c.boxcolor="#6C6"},this._server.on_message=function(g,k){var u=null;try{u=JSON.parse(k)}catch(w){return}if(1==u.type)if(u.data.object_class&&r[u.data.object_class]){var v=null;try{v=new r[u.data.object_class](u.data),c.triggerSlot(0,v)}catch(h){return}}else c.triggerSlot(0,
u.data);else c._last_received_data[u.channel||0]=u.data;c.boxcolor="#AFA"},this._server.on_error=function(g){console.log("couldnt connect to websocket");c.boxcolor="#E88"},this._server.on_close=function(g){console.log("connection closed");c.boxcolor="#000"},this.properties.url&&this.properties.room&&(this._server.connect(this.properties.url,this.properties.room),this._final_url=this.properties.url+"/"+this.properties.room))};k.prototype.send=function(c){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,
data:c})};k.prototype.onAction=function(c,g){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,action:c,data:g})};k.prototype.onGetInputs=function(){return[["in",0]]};k.prototype.onGetOutputs=function(){return[["out",0]]};r.registerNodeType("network/sillyclient",k)})(this);
function(g){c.boxcolor="#AFA";var k=JSON.parse(g.data);if(!k.room||k.room==this.properties.room)if(1==g.data.type)if(k.data.object_class&&r[k.data.object_class]){g=null;try{g=new r[k.data.object_class](k.data),c.triggerSlot(0,g)}catch(w){}}else c.triggerSlot(0,k.data);else c._last_received_data[g.data.channel||0]=k.data};this._ws.onerror=function(g){console.log("couldnt connect to websocket");c.boxcolor="#E88"};this._ws.onclose=function(g){console.log("connection closed");c.boxcolor="#000"}};c.prototype.send=
function(c){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:c}))};c.prototype.onAction=function(c,g){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,room:this.properties.room,action:c,data:g})};c.prototype.onGetInputs=function(){return[["in",0]]};c.prototype.onGetOutputs=function(){return[["out",0]]};r.registerNodeType("network/websocket",c);k.title="SillyClient";k.desc="Connects to SillyServer to broadcast messages";k.prototype.onPropertyChanged=
function(c,g){var k=this.properties.url+"/"+this.properties.room;this._server&&this._final_url!=k&&(this._server.connect(this.properties.url,this.properties.room),this._final_url=k)};k.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var c=this.properties.only_send_changes,g=1;g<this.inputs.length;++g){var k=this.getInputData(g);null==k||c&&this._last_sent_data[g]==k||(this._server.sendMessage({type:0,channel:g,data:k}),this._last_sent_data[g]=k)}for(g=1;g<this.outputs.length;++g)this.setOutputData(g,
this._last_received_data[g]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};k.prototype.createSocket=function(){var c=this;"undefined"==typeof SillyClient?(this._error||console.error("SillyClient node cannot be used, you must include SillyServer.js"),this._error=!0):(this._server=new SillyClient,this._server.on_ready=function(){console.log("ready");c.boxcolor="#6C6"},this._server.on_message=function(g,k){var u=null;try{u=JSON.parse(k)}catch(w){return}if(1==u.type)if(u.data.object_class&&r[u.data.object_class]){var v=
null;try{v=new r[u.data.object_class](u.data),c.triggerSlot(0,v)}catch(h){return}}else c.triggerSlot(0,u.data);else c._last_received_data[u.channel||0]=u.data;c.boxcolor="#AFA"},this._server.on_error=function(g){console.log("couldnt connect to websocket");c.boxcolor="#E88"},this._server.on_close=function(g){console.log("connection closed");c.boxcolor="#000"},this.properties.url&&this.properties.room&&(this._server.connect(this.properties.url,this.properties.room),this._final_url=this.properties.url+
"/"+this.properties.room))};k.prototype.send=function(c){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,data:c})};k.prototype.onAction=function(c,g){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,action:c,data:g})};k.prototype.onGetInputs=function(){return[["in",0]]};k.prototype.onGetOutputs=function(){return[["out",0]]};r.registerNodeType("network/sillyclient",k)})(this);

View File

@@ -86,7 +86,23 @@ LGWebSocket.prototype.createSocket = function()
if( data.room && data.room != this.properties.room )
return;
if( e.data.type == 1 )
that.triggerSlot( 0, data );
{
if(data.data.object_class && LiteGraph[data.data.object_class] )
{
var obj = null;
try
{
obj = new LiteGraph[data.data.object_class](data.data);
that.triggerSlot( 0, obj );
}
catch (err)
{
return;
}
}
else
that.triggerSlot( 0, data.data );
}
else
that._last_received_data[ e.data.channel || 0 ] = data.data;
}