2026-04-01 11:23:24 +02:00
|
|
|
// osc_receiver.scd - OSC receiver for webapp
|
|
|
|
|
// Run this in SuperCollider: sclang supercollider/osc_receiver.scd
|
|
|
|
|
// Then click nodes in the webapp to play tones
|
|
|
|
|
|
|
|
|
|
s.boot;
|
|
|
|
|
s.waitForBoot {
|
2026-04-01 21:53:33 +02:00
|
|
|
|
|
|
|
|
// Define synth on the server with long attack and decay
|
2026-04-01 11:23:24 +02:00
|
|
|
SynthDef(\sineTone, {
|
|
|
|
|
|freq = 440, amp = 0.15|
|
|
|
|
|
var env = EnvGen.kr(
|
2026-04-01 21:53:33 +02:00
|
|
|
Env([0, 1, 0.8, 0], [2, 3.0, 3], \sin),
|
2026-04-01 11:23:24 +02:00
|
|
|
doneAction: Done.freeSelf
|
|
|
|
|
);
|
|
|
|
|
Out.ar(0, SinOsc.ar(freq) * env * amp);
|
|
|
|
|
}).add;
|
2026-04-01 21:53:33 +02:00
|
|
|
|
2026-04-01 11:23:24 +02:00
|
|
|
// Wait for synth to be added to server
|
|
|
|
|
s.sync;
|
2026-04-01 21:53:33 +02:00
|
|
|
|
|
|
|
|
// OSC handler for /freq messages - explicitly bind to port 57120
|
2026-04-01 11:23:24 +02:00
|
|
|
~oscHandler = OSCFunc({ |msg, time, addr, recvPort|
|
|
|
|
|
if (msg.size >= 3, {
|
|
|
|
|
var freq = msg[2].asFloat;
|
|
|
|
|
if (freq > 0, {
|
|
|
|
|
Synth(\sineTone, [\freq, freq, \amp, 0.15]);
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-04-01 21:53:33 +02:00
|
|
|
}, '/freq', nil, 57120);
|
|
|
|
|
|
2026-04-01 11:23:24 +02:00
|
|
|
"OSC receiver ready on port 57120".postln;
|
|
|
|
|
"Click nodes in webapp to play".postln;
|
2026-04-01 21:53:33 +02:00
|
|
|
|
2026-04-01 11:23:24 +02:00
|
|
|
// Keep alive
|
|
|
|
|
while { true } { 10.wait; };
|
|
|
|
|
}
|