diff --git a/ToposServer/index.js b/ToposServer/index.js index 2f39aa4..01b5bdf 100644 --- a/ToposServer/index.js +++ b/ToposServer/index.js @@ -1,18 +1,18 @@ -const WebSocket = require('ws'); -const osc = require('osc'); +const WebSocket = require("ws"); +const osc = require("osc"); const wss = new WebSocket.Server({ port: 3000 }); -console.log('WebSocket server started on ws://localhost:3000'); +console.log("WebSocket server started on ws://localhost:3000"); -wss.on('connection', function(ws) { - console.log('> Client connected'); +wss.on("connection", function (ws) { + console.log("> Client connected"); - ws.on('message', function(data) { + ws.on("message", function (data) { try { const message = JSON.parse(data); sendOscMessage(message); } catch (error) { - console.error('> Error processing message:', error); + console.error("> Error processing message:", error); } }); }); @@ -22,15 +22,14 @@ function sendOscMessage(message) { localAddress: "127.0.0.1", localPort: 3000, remoteAddress: "127.0.0.1", - remotePort: 3333, + remotePort: message.port, }); - udpPort.on("ready", function() { - console.log('> OSC Message:', message); + udpPort.on("ready", function () { + console.log("> OSC Message:", message); udpPort.send(message); udpPort.close(); }); udpPort.open(); } - diff --git a/src/classes/SoundEvent.ts b/src/classes/SoundEvent.ts index 087df91..166540a 100644 --- a/src/classes/SoundEvent.ts +++ b/src/classes/SoundEvent.ts @@ -48,6 +48,7 @@ export class SoundEvent extends AudibleEvent { lfo: ["lfo"], znoise: ["znoise"], address: ["address", "add"], + port: ["port"], noise: ["noise"], zmod: ["zmod"], zcrush: ["zcrush"], @@ -450,8 +451,14 @@ export class SoundEvent extends AudibleEvent { // const filteredEvent = filterObject(event, ["analyze","note","dur","freq","s"]); const filteredEvent = event; // No need for note if there is freq - if (filteredEvent.freq) { delete filteredEvent.note; } - superdough(filteredEvent, this.nudge - this.app.clock.deviation, filteredEvent.dur); + if (filteredEvent.freq) { + delete filteredEvent.note; + } + superdough( + filteredEvent, + this.nudge - this.app.clock.deviation, + filteredEvent.dur + ); } }; @@ -463,15 +470,17 @@ export class SoundEvent extends AudibleEvent { for (const event of events) { const filteredEvent = event; - let oscAddress = this.values["address"]?.startsWith('/') ? this.values["address"] : `/${this.values["address"]}` || "/topos"; + let oscAddress = "address" in event ? event.address : "/topos"; + oscAddress = oscAddress?.startsWith("/") ? oscAddress : "/" + oscAddress; - - if (filteredEvent.freq) { delete filteredEvent.note; } + if (filteredEvent.freq) { + delete filteredEvent.note; + } sendToServer({ address: oscAddress, message: event, - timetag: Math.round(Date.now() + this.nudge - this.app.clock.deviation) - } as OSCMessage) + timetag: Math.round(Date.now() + this.nudge - this.app.clock.deviation), + } as OSCMessage); } - } + }; }