{
 "lyplug": 1,
 "manifest": {
  "format": 1,
  "name": "Transient Shaper",
  "author": "Lyreto",
  "version": "1.0.0",
  "kind": "effect",
  "description": "Turns the hit of each sound up or down (Attack) and the ring after it (Sustain). The built-in Transient Shaper, as a Lyreto plugin.",
  "params": [
   {
    "id": "attack",
    "name": "Attack",
    "min": -1,
    "max": 1,
    "default": 0,
    "step": 0.01
   },
   {
    "id": "sustain",
    "name": "Sustain",
    "min": -1,
    "max": 1,
    "default": 0,
    "step": 0.01
   },
   {
    "id": "speed",
    "name": "Speed",
    "min": 0,
    "max": 2,
    "default": 1,
    "options": [
     "Fast (hats, snares)",
     "Medium",
     "Slow (808, pads)"
    ]
   },
   {
    "id": "out",
    "name": "Output",
    "min": -18,
    "max": 12,
    "default": 0,
    "step": 0.5,
    "unit": "dB"
   }
  ],
  "ui": {
   "layout": [
    [
     "attack",
     "sustain",
     "out"
    ],
    [
     "speed"
    ]
   ],
   "accent": "#5cc8ff"
  }
 },
 "code": "// Transient Shaper: a fast and a slow envelope follower; their difference says \"hit\" or \"tail\".\nplugin({\n  create(host) {\n    const SPEEDS = [{ fast: 0.0008, slow: 0.04 }, { fast: 0.0015, slow: 0.09 }, { fast: 0.003, slow: 0.22 }];\n    let ef = 0, es = 0, gs = 1;\n    return {\n      process(input, output, p, frames) {\n        const sp = SPEEDS[Math.max(0, Math.min(2, Math.round(p.speed)))];\n        const kf = 1 - Math.exp(-1 / (sp.fast * host.sampleRate)), ks = 1 - Math.exp(-1 / (sp.slow * host.sampleRate));\n        const outGain = Math.pow(10, p.out / 20);\n        for (let n = 0; n < frames; n++) {\n          let a = 0;\n          for (let c = 0; c < input.length; c++) a = Math.max(a, Math.abs(input[c][n]));\n          ef += (a - ef) * (a > ef ? kf : kf * 0.25);\n          es += (a - es) * (a > es ? ks : ks * 0.3);\n          const d = 20 * Math.log10((ef + 1e-6) / (es + 1e-6));\n          let gdb = d > 0 ? p.attack * Math.min(18, d * 1.5) : p.sustain * Math.min(24, -d * 3);\n          gdb = Math.max(-30, Math.min(18, gdb));\n          gs += (Math.pow(10, gdb / 20) - gs) * 0.02;\n          const g = gs * outGain;\n          for (let c = 0; c < output.length; c++) output[c][n] = input[c][n] * g;\n        }\n      }\n    };\n  }\n});\n"
}