{"id":15070119,"url":"https://github.com/crucialfelix/supercolliderjs","last_synced_at":"2025-04-12T23:30:20.791Z","repository":{"id":3956918,"uuid":"5050280","full_name":"crucialfelix/supercolliderjs","owner":"crucialfelix","description":"The JavaScript client library for SuperCollider","archived":false,"fork":false,"pushed_at":"2023-04-14T20:31:42.000Z","size":3107,"stargazers_count":476,"open_issues_count":35,"forks_count":41,"subscribers_count":37,"default_branch":"develop","last_synced_at":"2024-10-30T00:37:21.805Z","etag":null,"topics":["algorithmic-music","audio","audio-applications","audio-library","javascript","livecoding","music","sound","sound-synthesis","supercollider","supercollider-language-interpreter","synthesis-server","typescript"],"latest_commit_sha":null,"homepage":"https://crucialfelix.github.io/supercolliderjs/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crucialfelix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-07-14T19:17:29.000Z","updated_at":"2024-10-20T11:17:08.000Z","dependencies_parsed_at":"2023-07-09T00:16:09.931Z","dependency_job_id":null,"html_url":"https://github.com/crucialfelix/supercolliderjs","commit_stats":{"total_commits":695,"total_committers":4,"mean_commits":173.75,"dds":0.007194244604316502,"last_synced_commit":"2e7c2b4819cd19346656755d1cf37bf6cea37d04"},"previous_names":[],"tags_count":105,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crucialfelix%2Fsupercolliderjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crucialfelix%2Fsupercolliderjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crucialfelix%2Fsupercolliderjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crucialfelix%2Fsupercolliderjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crucialfelix","download_url":"https://codeload.github.com/crucialfelix/supercolliderjs/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647249,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithmic-music","audio","audio-applications","audio-library","javascript","livecoding","music","sound","sound-synthesis","supercollider","supercollider-language-interpreter","synthesis-server","typescript"],"created_at":"2024-09-25T01:48:15.432Z","updated_at":"2025-04-12T23:30:20.764Z","avatar_url":"https://github.com/crucialfelix.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# supercolliderjs\n[![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url]\n\n\u003ci\u003eJavaScript library for the SuperCollider music language and synthesis server\u003c/i\u003e\n\n`supercollider.js` is a full-featured, batteries included client library for the `SuperCollider` audio synthesis server and the SuperCollider language interpreter.\n\nIt can be used for algorithmic composition, live coding, playing sounds with MIDI, audio processing, sound file rendering, data sonification and more.\n\nIt is written in TypeScript and compiled for release as ES2018 (Node \u003e= 10) JavaScript and can be used in Node applications for either JavaScript or TypeScript.\n\n\u003caside class=\"aside\"\u003e\n\u003ch3\u003eSuperCollider\u003c/h3\u003e\n\nSuperCollider is a platform for audio synthesis and algorithmic composition, used by musicians, artists, and researchers working with sound. It is free and open source software available for Windows, Mac OS X, and Linux. \u003ca href=\"https://supercollider.github.io/\" target=\"_blank\"\u003esupercollider.github.io\u003c/a\u003e\n\nIt consists of two parts:\n\n- `scsynth`: A real-time audio synthesis Server that communicates over TCP/IP using the OSC (Open Sound Control) protocol.\n  - High quality accurate and efficient audio engine\n  - Fully adjustable sample rate (192k+) and block size\n  - 32-bit float signal chain\n  - Sampling buffers use 64-bit float\n  - Fast and fluid control rate modulation\n  - [250 Unit generators in SuperCollider](http://doc.sccode.org/Guides/Tour_of_UGens.html)\n  - Hundreds more community contributed UGens\n  - Simple ANSI C plugin API\n  - Supports any number of input and output channels, ideal for large multichannel setups\n  - macOS, linux, windows\n\n- `sclang`: An interpreter and runtime for the SuperCollider programming language. It is similar to Smalltalk or Ruby with syntax similar to C or Javascript.\n\u003c/aside\u003e\n\n## Install\n\n1. Install SuperCollider:\n  https://supercollider.github.io/\n\n2. Install supercolliderjs:\n```shell\nnpm install supercolliderjs\n```\n\n## Examples\n\n\nThere are several interfaces, ranging from low-level (tedious, error-prone) control to higher level constructs.\n\n```js\n// @supercollider/server-plus interface\nconst sc = require(\"supercolliderjs\");\n\nsc.server.boot().then(async server =\u003e {\n  // Compile a SynthDef from inline SuperCollider language code and send it to the server\n  const def = await server.synthDef(\n    \"formant\",\n    `{ |out=0, fundfreq=440, formantfreq=440, bwfreq=100, timeScale=1, pan=0|\n        var saw, envd, panned;\n\n        saw = Formant.ar(fundfreq, formantfreq, bwfreq);\n\n        envd = saw * EnvGen.kr(Env.sine(0.1, 0.2), timeScale: timeScale, doneAction: 2);\n        panned = Pan2.ar(envd * AmpCompA.kr(fundfreq, 0.2, 0.7), pan);\n\n        OffsetOut.ar(out, panned);\n      }`,\n  );\n\n  // Create group at the root\n  const group = server.group();\n\n  const freqSpec = {\n    minval: 100,\n    maxval: 8000,\n    warp: \"exp\",\n  };\n\n  // Map 0..1 to an exponential frequency range from 100..8000\n  const randFreq = () =\u003e sc.map.mapWithSpec(Math.random(), freqSpec);\n\n  // function to spawn one synth event\n  const spawn = dur =\u003e {\n    server.synth(\n      def,\n      {\n        fundfreq: randFreq(),\n        formantfreq: randFreq(),\n        bwfreq: randFreq(),\n        pan: sc.map.linToLin(0, 1, -1, 1, Math.random()),\n        timeScale: dur,\n        // spawn each synth into the same group\n      },\n      group,\n    );\n\n    const next = Math.random() * 0.25;\n\n    // Schedule this function again:\n    setTimeout(() =\u003e spawn(next), next * 1000);\n  };\n\n  // spawn the first event\n  spawn(Math.random());\n}, console.error);\n\n```\n\u003csmall class=\"source-link\"\u003e\u003ca href=https://github.com/crucialfelix/supercolliderjs/blob/develop/examples/server-plus.js\u003esource\u003c/a\u003e\u003c/small\u003e\n\n\n\n### SynthDef and Synth\n\nA SuperCollider SynthDef defines a graph of [Unit generators](https://en.wikipedia.org/wiki/Unit_generator). It wires together inputs and outputs, oscillators and filters. Once it is compiled and sent to the server, then you can create Synths that play that sound.\n\nCurrently supercollider.js uses `sclang` to compile synth defs. Full support for writing and compiling SynthDefs from JavaScript is planned.\n\n```js\nconst sc = require(\"supercolliderjs\");\n\nsc.server.boot().then(async server =\u003e {\n  // Compile and send to server from inline SuperCollider code\n  const pulse = await server.synthDef(\n    \"pulse\",\n    `{ arg out = 0, freq=200;\n    Out.ar(out, Pulse.ar(200, Line.kr(0.01,0.99,8), 0.2))\n  }`,\n  );\n\n  await server.synth(pulse, { freq: 300 });\n\n  // Load and compile from a SuperCollider language file\n  const klang = await server.loadSynthDef(\"klang\", \"./klang.scd\");\n\n  await server.synth(klang);\n\n  // Compile or load many at once\n  const defs = await server.synthDefs({\n    clipNoise: {\n      source: `{ arg out = 0;\n        var clip = LFClipNoise.ar(MouseX.kr(200, 10000, 1), 0.125);\n        Out.ar(out, clip);\n      }`,\n    },\n    lpf: {\n      source: `{ arg in = 0, out = 0;\n        var input = In.ar(in);\n        var lpf = RLPF.ar(input, MouseY.kr(1e2, 2e4, 1), 0.2, 0.2);\n        ReplaceOut.ar(out, lpf);\n      }`,\n    },\n  });\n\n  // Some people pre-compile synth defs to a binary format.\n  // Load a pre-compiled synth def from a binary file.\n  const defLoadMsg = sc.server.msg.defLoad(\"./formant.scsyndef\");\n  // This object has two properties:\n  // .call - the OSCMessage to send\n  // .response - the expected OSCMessage that the server will reply with\n  // Call and wait for the response:\n  await server.callAndResponse(defLoadMsg);\n\n  // Load an entire directory of pre-compiled synth defs\n  // await server.callAndResponse(sc.server.msg.defLoadDir(\"./synthdefs/\"));\n});\n\n```\n\u003csmall class=\"source-link\"\u003e\u003ca href=https://github.com/crucialfelix/supercolliderjs/blob/develop/examples/synthdef-and-synth.js\u003esource\u003c/a\u003e\u003c/small\u003e\n\n\n```js\nconst sc = require(\"supercolliderjs\");\n\nsc.server.boot().then(server =\u003e {\n  const def = server.synthDef(\n    \"bubbles\",\n    `\n      SynthDef(\"bubbles\", { arg out=0, wobble=0.4, innerWobble=8, releaseTime=4;\n        var f, zout;\n        f = LFSaw.kr(wobble, 0, 24, LFSaw.kr([innerWobble, innerWobble / 1.106], 0, 3, 80)).midicps;\n        zout = CombN.ar(SinOsc.ar(f, 0, 0.04), 0.2, 0.2, 4);  // echoing sine wave\n        zout = zout * EnvGen.kr(Env.linen(releaseTime: releaseTime), doneAction: 2);\n        Out.ar(out, zout);\n      });\n    `,\n  );\n\n  setInterval(() =\u003e {\n    server.synth(def, {\n      wobble: Math.random() * 10,\n      innerWobble: Math.random() * 16,\n      releaseTime: Math.random() * 4 + 2,\n    });\n  }, 4000);\n});\n\n```\n\u003csmall class=\"source-link\"\u003e\u003ca href=https://github.com/crucialfelix/supercolliderjs/blob/develop/examples/bubbles.js\u003esource\u003c/a\u003e\u003c/small\u003e\n\n\n[Server Plus](./packages/server-plus/README.md)\n[Server](./packages/server/README.md)\n\n### lang\n\n- Spawns the language interpreter, `sclang`\n- Call SuperCollider code from JavaScript\n\n```js\nconst sc = require(\"supercolliderjs\");\n\nsc.lang.boot().then(async function(lang) {\n  // This function is declared as `async`\n  // so for any function calls that return a Promise we can `await` the result.\n\n  // This is an `async` function, so we can `await` the results of Promises.\n  const pyr8 = await lang.interpret(\"(1..8).pyramid\");\n  console.log(pyr8);\n\n  const threePromises = [16, 24, 32].map(n =\u003e {\n    return lang.interpret(`(1..${n}).pyramid`);\n  });\n\n  // `interpret` many at the same time and wait until all are fulfilled.\n  // Note that `lang` is single threaded,\n  // so the requests will still be processed by the interpreter one at a time.\n  const pyrs = await Promise.all(threePromises);\n  console.log(pyrs);\n\n  // Get a list of all UGen subclasses\n  const allUgens = await lang.interpret(\"UGen.allSubclasses\");\n\n  // Post each one to STDOUT\n  allUgens.forEach(ugenClass =\u003e console.log(ugenClass));\n\n  await lang.quit();\n});\n\n```\n\u003csmall class=\"source-link\"\u003e\u003ca href=https://github.com/crucialfelix/supercolliderjs/blob/develop/examples/lang-interpret.js\u003esource\u003c/a\u003e\u003c/small\u003e\n\n\nDocumentation\n-------------\n\n[Documentation](https://crucialfelix.github.io/supercolliderjs/#/packages/supercolliderjs/api)\n\nCompatibility\n-------------\n\nWorks on Node 10+\n\nSource code is written in TypeScript and is usable in JavaScript [es2018](https://2ality.com/2017/02/ecmascript-2018.html) or [TypeScript](https://www.typescriptlang.org/docs/home.html) projects.\n\nContribute\n----------\n\n- Issue Tracker: https://github.com/crucialfelix/supercolliderjs/issues\n- Source Code: https://github.com/crucialfelix/supercolliderjs\n\nLicense\n-------\n\nMIT license\n\n[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat\n[license-url]: LICENSE\n\n[npm-url]: https://npmjs.org/package/supercolliderjs\n[npm-version-image]: http://img.shields.io/npm/v/supercolliderjs.svg?style=flat\n[npm-downloads-image]: http://img.shields.io/npm/dm/supercolliderjs.svg?style=flat\n\n[travis-url]: http://travis-ci.org/crucialfelix/supercolliderjs\n[travis-image]: https://travis-ci.org/crucialfelix/supercolliderjs.svg?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrucialfelix%2Fsupercolliderjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrucialfelix%2Fsupercolliderjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrucialfelix%2Fsupercolliderjs/lists"}