compact_sets/supercollider/osc_receiver.scd
Michael Winter 6ab162003e Add OSC playback to path navigator webapp
- Add /api/set-fundamental and /api/play-freq endpoints to server.py
- Add send_single method to osc_sender.py for sending single frequencies
- Add fundamental frequency input and click handler to path_navigator.html
- Distinguish between click (play) and drag (move) on nodes
- Add osc_receiver.scd for SuperCollider to receive /freq messages
2026-04-01 11:23:24 +02:00

36 lines
1,010 B
Plaintext

// 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 {
// Define synth on the server (2-second ring)
SynthDef(\sineTone, {
|freq = 440, amp = 0.15|
var env = EnvGen.kr(
Env([0, 1, 1, 0], [0.05, 0.1, 1.85], \sin),
doneAction: Done.freeSelf
);
Out.ar(0, SinOsc.ar(freq) * env * amp);
}).add;
// Wait for synth to be added to server
s.sync;
// OSC handler for /freq messages
~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]);
});
});
}, '/freq');
"OSC receiver ready on port 57120".postln;
"Click nodes in webapp to play".postln;
// Keep alive
while { true } { 10.wait; };
}