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 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();
}

View File

@ -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);
}
}
};
}