Re: Announce: scnim - Write SuperCollider UGens in Nim (Proof of Concept)
| Newsgroups | gmane.comp.audio.supercollider.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Carlo, this is an exciting project, thanks for sharing. Nim seems to be an interesting language as well. A while ago, I thought about something like this with Scala Native (http://www.scala-native.org/en/latest/), although I had considered rather to see how to difficult it would be to implement part of the server API, rather than writing UGens that could then be linked back into scsynth. Your documentation will be very useful for similar attempts. Have you gathered any insight into the performance of using Nim for the UGens? best, .h.h. On 10/03/18 03:23, carlo-3+kk896uEWp9MqFnZXqmrwC/[email protected] wrote: > Hi everyone! > > I was toying with the thought of trying the Nim programming language- it > feels a bit like Python or Ruby to work with, which is great for an old > scripter like me, but is compiled to C++ and is just as fast. It also has > very powerful macros, which allows for a lot of work to be done before > compiling- this somewhat resolves the tension between clean code and fast > code, a perfect match for a realtime system. > > So I decided to give it a whirl by writing a SuperCollider UGen in it, and > it works really well! Here's what a basic UGen looks like in Nim: > > > --------- > # ExampleUGens.nim > import > PlugIn,InterfaceTable,Unit,ptrmath > > proc api_version(): int {.cdecl,exportc,dynlib.} = > return sc_api_version; > > proc server_type(): ServerType {.cdecl,exportc,dynlib.}= > return when defined(SUPERNOVA): sc_server_supernova else: > sc_server_scsynth > > var ft: ptr InterfaceTable > > type > Example = object of Unit > > proc next(unit: ptr Example, numSamples: cint) {.cdecl,exportc,dynlib.} = > var > input = unit.mInBuf[] > output = unit.mOutBuf[] > > for i in 0..numSamples: > output[i] = input[i] > > proc ctor(unit: ptr Example) {.cdecl,exportc,dynlib.} = > unit.mCalcFunc = cast[UnitCalcFunc](next) > > proc load(inTable: ptr InterfaceTable) {.cdecl,exportc,dynlib.} = > ft = inTable; > discard ft.fDefineUnit("Example", sizeof(Example), > cast[UnitCtorFunc](ctor), nil, 0'u32) > --------- > > > This is still proof-of-concept and fairly gritty and low-level by Nim > standards, but it's already far cry from the cognitive overhead when writing > C++ UGens directly, especially if you just look at the "next" procedure- the > rest is boilerplate and yet needs to be hidden away. It's also missing > features. > > If you feel like playing with this, here is the repository with some more > details and a runnable example: > > https://github.com/carlocapocasa/scnim > > Have a great time! > > Carlo > > > > > -- > Sent from: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SuperCollider-Developers-New-Use-this-f2681767.html > > _______________________________________________ > sc-dev mailing list > > info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx > archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/ > search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/ >
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEBT+tQEGDjkBMBGwqpkWZo9piTpAFAlqjsJ8ACgkQpkWZo9pi TpAxmhAAi3/CEQFT0gxZSt8IFMFZw69ICWFgl/qPbvsSeFWZaY/XTwLrvdfsmFZ6 /bPhHuy6ttj+usoNy7ljeAEE7BXxUs7tA0ojY3YG8468Xd9wBRJ//Sg7sugQUGns rVYdy8IjRKY5/wkduUrcpG2q1v/D3V8JpSjZmfPxmCeJM7fWlDOWiPbdZGLOShlA 7jYzjQUuSg1TeEd5KoSXTaEJeMWYKZ0BOHj2HOdwjXxG9fu2cJawJVccgXmLo/qX 32m1YAsyJTTVx1a07rFp35xKHSu29a/1VCo2M9VxfsuWepeAO80bYZrOnOpRSaXY C4RnyGwVXwVVv/6MA1sugzv9t6FBIz/28zee8yK+Y9wuzwnxY8oq+h2f0wNROf3t aPzWHVZIfmvmnReyjs6N1nPKugyOln1p6xYiVwP5DSi6j8JHgvdtwETqYAdyQTV1 XIHhrm42oI3HdpxbAchLEdZXzHVNHrbQnfJQ4hFieoT9xXLu9FIsraiiqKUtpcgW 20PREQ+J+9Cmeb7/7p6m3kaQ+EYD9xi1r8poJZtU7i0kZxfWCY/xeVLoVVMEEebz OKwVn5zyYBu60bskvgPZUgl8jyB+U/NZZVLxbFJd29wV6XEPQmuGAh/jguI2bWYo vR5dHaW0PBclcJ+q8XrlmTN1D/34Di0PJ72gweaVIW6HH+ZUqm0= =Wsvw -----END PGP SIGNATURE-----