fleshing out a bit

This commit is contained in:
2023-11-22 15:34:21 +01:00
parent fa67fdc2e5
commit 8195511332
2 changed files with 27 additions and 19 deletions

View File

@ -1,18 +1,18 @@
const WebSocket = require('ws'); const WebSocket = require("ws");
const osc = require('osc'); const osc = require("osc");
const wss = new WebSocket.Server({ port: 3000 }); 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) { wss.on("connection", function (ws) {
console.log('> Client connected'); console.log("> Client connected");
ws.on('message', function(data) { ws.on("message", function (data) {
try { try {
const message = JSON.parse(data); const message = JSON.parse(data);
sendOscMessage(message); sendOscMessage(message);
} catch (error) { } 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", localAddress: "127.0.0.1",
localPort: 3000, localPort: 3000,
remoteAddress: "127.0.0.1", remoteAddress: "127.0.0.1",
remotePort: 3333, remotePort: message.port,
}); });
udpPort.on("ready", function() { udpPort.on("ready", function () {
console.log('> OSC Message:', message); console.log("> OSC Message:", message);
udpPort.send(message); udpPort.send(message);
udpPort.close(); udpPort.close();
}); });
udpPort.open(); udpPort.open();
} }

View File

@ -48,6 +48,7 @@ export class SoundEvent extends AudibleEvent {
lfo: ["lfo"], lfo: ["lfo"],
znoise: ["znoise"], znoise: ["znoise"],
address: ["address", "add"], address: ["address", "add"],
port: ["port"],
noise: ["noise"], noise: ["noise"],
zmod: ["zmod"], zmod: ["zmod"],
zcrush: ["zcrush"], zcrush: ["zcrush"],
@ -450,8 +451,14 @@ export class SoundEvent extends AudibleEvent {
// const filteredEvent = filterObject(event, ["analyze","note","dur","freq","s"]); // const filteredEvent = filterObject(event, ["analyze","note","dur","freq","s"]);
const filteredEvent = event; const filteredEvent = event;
// No need for note if there is freq // No need for note if there is freq
if (filteredEvent.freq) { delete filteredEvent.note; } if (filteredEvent.freq) {
superdough(filteredEvent, this.nudge - this.app.clock.deviation, filteredEvent.dur); 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) { for (const event of events) {
const filteredEvent = event; 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) {
if (filteredEvent.freq) { delete filteredEvent.note; } delete filteredEvent.note;
}
sendToServer({ sendToServer({
address: oscAddress, address: oscAddress,
message: event, message: event,
timetag: Math.round(Date.now() + this.nudge - this.app.clock.deviation) timetag: Math.round(Date.now() + this.nudge - this.app.clock.deviation),
} as OSCMessage) } as OSCMessage);
} }
} };
} }