0.3.0 • Published 3 months ago

rescript-web-audio v0.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

rescript-web-audio

Zero-cost ReScript bindings for the Web Audio API

Installation

pnpm install rescript-web-audio

Then add rescript-web-audio to bs-dependencies in rescript.json.

{
    "name": "my-project",
    "bs-dependencies": ["@rescript/core", "rescript-web-audio"]
}

Usage

This library is heavily inspired by the design of rescript-webapi and ocaml-ffmpeg, which both use phantom types and implementation inheritance to translate an Object Oriented API into the functional paradigm of OCaml. Here is an example of what it looks like in the wild:

open WebAudio

// Constructors become ModuleName.make().
let ctx = AudioContext.make()

let osc = OscillatorNode.make(
  ctx,
  ~options={
    // Strings with a finite number of possible values become polymorphic variants.
    type_: #sine, 
    frequency: 440.0,
  },
)

let gain = GainNode.make(
  ctx,
  ~options={
    gain: 0.3,
  },
)

// Methods become functions.
let _ = OscillatorNode.connectNode(osc, gain)

// Fields become getters (and setters when appropriate).
let _ = GainNode.connectNode(gain, AudioContext.getDestination(ctx))

OscillatorNode.start(osc)
0.3.0

3 months ago

0.2.0

3 months ago

0.1.1

4 months ago

0.1.0

4 months ago