REF / Music API / Envelope

Ascene . Agraph . Aengine
Anode . Modulator . Envelope
Songbook . Song . TimeKeeper
Voices . SampleMgr . StreamMgr
Loader . Async . Plot
Random . Rhythm . Util
MIDI . OSC . HID . Piano
Music Theory with Tonal

right-click to navigate to page sections


The purpose of class Envelope is to programmatically evaluate an LFO envelope function as used by Envelope Editor, Hz.LFO, and Hz.ModLFO

Envelope API

// To use the API, construct and initialize an instance of the class like so:
let myenv = new Envelope();
myenv.InitJSON(somejson);

// Next, invoke one of the evaluation method. Rinse and repeat.
let val = myenv.EvaluateOne(.5);

Here are the available methods.

Method Description
Init(obj) Initialize from an object representation as produced by JSON.parse
InitJSON(str) Parses the contents of a .knt or .vitallfo file
EvaluateOne(t) Returns a value between 0 and 1 representing the envelope function at t (0-1)
Render(npts) Returns an array of npts values representing the entire envelope.

Envelope File Format (.knt)

The .knt file format is a single JSON object with these fields:

Field Description
name string: describes the shape of the envelope
smooth boolean: global smoothing
data an array of triples representing t, y and power. Thus the number of knots is the length of this array divided by 3. t and y are (0-1) and power is (-5-5)
prefs an optional object containing preview/sonification parameters
Example .knt File
{
  "name":"Weird Step",
  "smooth":false,
  "data":[
     0,1,-3.401787519454956,
     0.10631868243217468,0.017857134342193604,4.633926868438721,
     0.3212454915046692,0.13214224576950073,-2.4107143878936768,
     0.8373624086380005,1,0,
     1,1,0
  ]
}
home .. topics .. interface .. reference .. examples .. tipjar