synthdef-json-decoder

decoder for SuperCollider Synth Definition File Format


Keywords
decode, supercollider, synthdef
License
MIT
Install
npm install synthdef-json-decoder@1.0.0

Documentation

synthdef-json-decoder

Build Status NPM Version License

decoder for SuperCollider Synth Definition File Format

Installation

npm install synthdef-json-decoder

API

  • decode(buffer: ArrayBuffer): Object[]

Example

SynthDef("sine", { |amp = 0.5, freq = 440|
   Out.ar(0, SinOsc.ar(freq, 0, amp) ! 2);
}, variants:(alpha:[amp:0.25,freq:880], beta:[freq:1760]))
const fs = require("fs");
const decoder = require("synthdef-json-decoder");

const file = fs.readFileSync("sine.scsyndef");
const buffer = new Uint8Array(file).buffer;
const json = decoder.decode(buffer);

console.log(json);
[
  {
    // the name of the synth definition
    "name": "sine",
    // constant values
    "consts": [ 0 ],
    // initial parameter values
    "paramValues": [ 0.5, 440 ],
    // param indices
    //   { name: the name of the parameter, 
    //     index: its index in the paramValues, 
    //     length: its length in the paramValues }
    "paramIndices": [
      { name: "amp", index: 0, length: 1 },
      { name: "freq", index: 1, length: 1 }
    ],
    // ugen-spec
    //   [ [
    //     the name of the SC unit generator class,
    //     calculation rate (0: Scalar, 1: Control, 2: Audio),
    //     special index,
    //     input-spec,
    //       [ [ index of unit generator, index of unit generator output ]
    //           or [ -1 for a constant, index of constant ] ]
    //     output-spec
    //       [ calculation rate ]
    //   ] ]
    "units": [
      [ "Control"     , 1, 0, [                                ], [ 1, 1 ] ],
      [ "SinOsc"      , 2, 0, [ [  0, 1 ], [ -1, 0 ]           ], [ 2    ] ],
      [ "BinaryOpUGen", 2, 2, [ [  1, 0 ], [  0, 0 ]           ], [ 2    ] ],
      [ "Out"         , 2, 0, [ [ -1, 0 ], [  2, 0 ], [ 2, 0 ] ], [      ] ]
    ],
    // variants
    //   { key: the name of the variant,
    //     values: variant initial parameter values }
    "variants": [
      { name: "beta", values: [ 0.5 , 1760 ] },
      { name: "alpha", values: [ 0.25,  880 ] }
    ]
  }
]

License

MIT