https://scsynth.org/t/dyngen-dynamic-ugen/12518 scsynth DynGen - Dynamic UGen Resources Libraries and Quarks dscheiba October 31, 2025, 10:33am 1 github.com [DynGen] GitHub - capital-G/DynGen: Run dynamic scripts on a SuperCollider server Run dynamic scripts on a SuperCollider server DynGen is a meta-UGen which allows to write DSP code on the fly using EEL2 as JIT-compiled language. This is essentially the SC equivalent of the gen~ object from Max MSP. An example on how to use it for halfing the amplitude of a given signal. // start the server s.boot; // registers a dyngen script on the server with identifier \simple ~simple = DynGenDef(\simple, "out0 = in0 * 0.5;").add; // spawn a synth which evaluates our script ( Ndef(\x, {DynGen.ar( 1, // numOutputs ~simple, // script to use - can also be DynGenDef(\simple) or \simple SinOsc.ar(200.0)), // ... the inputs to the script }).scope; ) This example isn't too interesting, but we can also use DynGen for oversampling and single sample feedback really easily - e.g. here is the code and a sound snippet for two cross-phase-modulated SinOscs, 128 times oversampled ( ~complex = DynGenDef(\complex, " twopi = 2*$pi; phaseA += 0; phaseB += 0; freqA = in0; freqB = in1; modIndexA = in2; modIndexB = in3; oversample = 128; osSrate = srate * oversample; incA = freqA / osSrate; incB = freqB / osSrate; sumA = 0; sumB = 0; // calculate subsaples loop(oversample, phaseA += incA; phaseB += incB; // wrap phases between [0, 1) phaseA -= floor(phaseA); phaseB -= floor(phaseB); // apply cross-phase modulation phaseA = phaseA + modIndexA * sin(twopi * phaseB); phaseB = phaseB + modIndexB * sin(twopi * phaseA); // accumulate (for downsampling) sumA += sin(twopi * phaseA); sumB += sin(twopi * phaseB); ); // scale down b/c of os out0 = sumA / oversample; out1 = sumB / oversample; ").add; ) ( Ndef(\y, { var sig = DynGen.ar(2, ~complex, \freqA.ar(200.0), \freqB.ar(pi*100), \modA.ar(0.02, spec: [-0.1, 0.1]) * 0.05 * Env.perc(releaseTime: \releaseTime.kr(0.2)).ar(gate: Impulse.ar(\offsetKick.kr(4.0))), \modB.ar(0.0, spec: [-0.1, 0.1]) * 0.05, ); sig * 0.1; }).play.gui; ) /uploads/default/original/2X/2/ 29c4bf2442ab762b8f7ee4755cff430fda0bb96e.mp3 It is also easy to write modulatable delay lines ( ~delayLine = DynGenDef(\delayLine, " buf[in1] = in0; out0 = buf[in2]; ").add; ) ( Ndef(\z, { var bufSize = SinOsc.ar(4.2).range(1000, 2000); var writePos = LFSaw.ar(2.0, 0.02).range(1, bufSize); var readPos = LFSaw.ar(pi, 0.0).range(1, bufSize); var sig = DynGen.ar(1, ~delayLine, SinOsc.ar(100.0), writePos.floor, readPos.floor, ); sig.dup * 0.1; }).play; ) /uploads/default/original/2X/c/ ccc8d3dbcaaf856fccb00b1f9126d6287f618ca1.mp3 When the script of a DynGenDef is updated, it will automatically replace the running UGen, such that livecoding of DSP is now possible. The UGen is still considered beta, so the interface is not stable and is open to change. I still have some open design questions, maybe the community can help me out here. I haven't tried if it works on Windows, so would be great to get some feedback for it. Looking forward to hear some new sounds and see some interesting pseudo UGens popping up :slight_smile: Massive thanks to @Spacechild1 for helping me how to handle NRT/RT synchronization in a good way and giving the initial idea for this during the symposium. 33 Likes jamshark70 October 31, 2025, 10:41am 2 I've hit the :heart: button but that represents about 0.0001% of my actual reaction to this post. :exploding_head: hjh 2 Likes Spacechild1 October 31, 2025, 10:47am 3 # dscheiba: When the script of a DynGenDef is updated, it will automatically replace the running UGen, such that livecoding of DSP is now possible. Yeah!!! (and some more characters) Spacechild1 October 31, 2025, 12:55pm 4 Great work! I just spammed your repo with a few issues :smiley: I think the API is great, but I have a few suggestions. In particular, I don't think that the audio inputs should be provided as varargs, see DynGen UGen inputs should not be varargs * Issue #21 * capital-G/DynGen * GitHub. 1 Like Spacechild1 October 31, 2025, 2:55pm 5 Actually, I'm not too happy about the add method, see concerns about the `add` method * Issue #22 * capital-G/DynGen * GitHub In short, I would prefer something like: // returns the DynGenDef bound to symbol \foo, creating it on demand DynGenDef(\foo); // get \foo def and send code to the Server DynGenDef(\foo).load("some code"); // get \foo def and tell the Server to read the given file DynGenDef(\foo).readFile("myCode.txt"); I don't care too much about the actual method names, but more about the general pattern. dietcv October 31, 2025, 7:49pm 6 haha, i also wanted to double click the :heart: TXMod October 31, 2025, 8:32pm 7 That's great news! Many thanks. prko November 1, 2025, 12:58am 8 Thank you very much for this outstanding achievement. I have just one question regarding the form in which this package will be delivered: * Will it be released in its current form? * Will it be included in the official build? (This seems unlikely due to licensing constraints.) * Will it be included in the official build? (it is unlikely possible due to the lisence...?) * Will it be incorporated into the sc3-plugins? * Or will it be distributed via quarks? If it is to be incorporated into the official build, it would be wonderful to see SuperCollider expanding its support for external languages. For instance: * KaTeX integration within schelp -- which has already been implemented * EEL2 support in sclang via quotation syntax -- currently being developed as part of this contribution Additionally, although still speculative, HTML rendering within schelp could be a truly valuable enhancement if considered in the future. Once again, thank you for your remarkable work. I look forward to seeing how this evolves. jamshark70 November 1, 2025, 8:24am 9 # prko: Will it be released in its current form? It may be premature to decide how a finished version would be released, since the interface hasn't stabilized yet. "Official build" is a very premature question at this point (I think). # prko: it would be wonderful to see SuperCollider expanding its support for external languages Maybe, but that might be a separate topic. I think that implementing an analog to MSP's gen~ doesn't directly have any bearing on importing other languages into other SC contexts. EEL2 support in sclang - Jordan has done some work on language backend extensions, which would make it possible, but I wonder what features it would provide that SC doesn't already have. Also, code-in-quoted-strings works if the code is likely not to have quotes in it (as seems to be the case for the type of DSP code in the top post here). My live coding dialect uses a lot of quote marks and is quite painful to write into SC string literals (which I don't do in a live coding performance, but I do sometimes have to do if I'm running an automated timeline-sequencer that invokes live-coding strings). String literals are more likely to appear in EEL2 scripts doing sclang-type activities, so we'd want to consider carefully whether quoted strings are the right syntactic mechanism. Or maybe an sclang extension here wouldn't be a high priority (whereas a "live code sample-by-sample DSP" UGen does answer a specific need that's been raised for years in the forum and prior mailing lists). hjh 1 Like dscheiba November 2, 2025, 8:56am 10 Thanks for the feedback so far, much appreciated! # prko: + Will it be included in the official build? (This seems unlikely due to licensing constraints.) No - I think the current path of SC is to make things more modular to reduce maintenance work within the core, but there are some plans make working with such modules easier. There are also no licensing issues. Using BSD licensed code in a GPL context is totally fine - the other way around would not be allowed. + Will it be incorporated into the sc3-plugins? No plans on doing that - sc3 plugins is already massive and I don't want to put additional stuff in it - modularity is the way to go. + Or will it be distributed via quarks? Since it needs to contain a binary it can't/shouldn't be distributed as a quark - but there are plans to make the installation and management of modules - such as quarks, server extensions and the 3.15 feature of sclang-extensions aka gluons - much more easy. Hopefully this will be part of the next 3.15 release, so stay tuned for further information on that. # prko: EEL2 support in sclang via quotation syntax -- currently being developed as part of this contribution This extensions does not have any kind of EEL2 support for sclang. You pass a string with EEL2 code from the language to the server, but in this way sclang has support for any language. As hjh pointed out, I don't think that EEL2 support for sclang would be that interesting since it wouldn't you enable to do new things, but there are plans on embedding tidal cycles into sclang - Embedding Tidal cycles in sclang EEL2 syntax allows for strings, but currently it is not enabled within DynGen since I don't know what it would be useful since the server has no way of handling strings. # prko: Additionally, although still speculative, HTML rendering within schelp could be a truly valuable enhancement if considered in the future. A bit OT, but I think it is better to not tie ourselves too much on HTML for documentation since a web browser is a big dependency which I'd ideally like to remove at some point so we can have a smaller footprint of SC installs. 3 Likes smoge November 2, 2025, 5:05pm 11 # jamshark70: Also, code-in-quoted-strings works if the code is likely not to have quotes in it (as seems to be the case for the type of DSP code in the top post here). My live coding dialect uses a lot of quote marks and is quite painful to write into SC string literals (which I don't do in a live coding performance, but I do sometimes have to do if I'm running an automated timeline-sequencer that invokes live-coding strings). String literals are more likely to appear in EEL2 scripts doing sclang-type activities, so we'd want to consider carefully whether quoted strings are the right syntactic mechanism. This particular point reminds me of a past discussion: # A more structured approach to DSLs Development DSL are implemented with the preprocessor operating directly on the text of the code. Languages are structured text. By manipulating the text through code, the structure is lost. This means things like syntax highlighting, formatting and indentation, documentation look, auto complete, and others, will fail. It is also currently very difficult to have multiple DSL at once. I'm proposing we should make DSLs structured, a token in the parser that the tooling doesn't look into (like a string), or w... blazp November 2, 2025, 9:38pm 12 This is great, now I can play with my own reverb, without having to recompile C++. I will test Windows and Linux versions this week. Is there any limitation? Something that a compiled UGen can do that EEL can't? asher November 3, 2025, 1:59am 13 YES!!! So excited to use this. Just wondering if it's possible to use use DynGen with sc buffers? blazp November 5, 2025, 9:40pm 14 I tested on Windows 10, all the examples worked. BTW: the first example on github has a syntax error, the coma after SinOsc is too much. * Home * Categories * Guidelines * Terms of Service * Privacy Policy Powered by Discourse, best viewed with JavaScript enabled