pd-andy/elm-audio-graph/1.0.0

NOTE: the latest version is 1.0.1

Renamed to hayleigh-dot-dev/elm-audio-graph. That is where the repository lives now. It has not been published as a package under the new name.

Versions published as pd-andy/elm-audio-graph still install under that name. 2 versions of 2 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/hayleigh-dot-dev/elm-audio-graph.

What we checked: The repo moved to github.com/hayleigh-dot-dev/elm-audio-graph. Rebuilt with git archive from commit 0e3f10cf24d8 of https://github.com/hayleigh-dot-dev/elm-audio-graph (zip prefix pd-andy-elm-audio-graph-0e3f10c/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 55669d85d3bcd6bd24e1ce51d089a9561a474c32.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/pd-andy/elm-audio-graph/zipball/1.0.0/

AudioGraph.Node

Definition

type Node
= Node
{ id : ID
, nodeType : Type
, params : Dict String Param
, inputs : Dict String ChannelNumber
, outputs : Dict String ChannelNumber
}

Node represents a generic audio node.

Types

type ID

A NodeID is used to ensure each node in the graph is unique. This is necessary if you're tracking changes to the graph in javascript when constructing and updating an actual Web Audio graph.

This package does not provide a means of generating NodeIDs, you are free to use other packages and convert the results to a NodeID with the idFromString and idFromInt methods. You may also simply use human readable NodeIDs such as myOsc.

idFromString : String -> ID

Takes a raw string and returns a NodeID.

idFromInt : Int -> ID

Takes any integer and returns a NodeID.

idToString : ID -> String

Converts a NodeID into a raw string. Used when encoding an audio node, but may also be useful in your own code.

type Type
= Destination
| Oscillator
| Gain
| Custom String

In order to construct the real Web Audio graph in javascript, we need to know what each node actually is. Custom types are also supported to allow user-defined audio nodes to be constructed, or third-party / non-standard Web Audio nodes to be represented.

type Param
= Value KValue
| Note MIDI
| Frequency Hertz
| Waveform String

Node params are typed to restrict their values. This type safety ensures that if your elm code compiles then a valid audio graph can be constructed in javascript. The values for each Param are simple type aliases that can be found in AudioGraph.Units and exist solely for more expressive type annotations.

Some utilities for dealing with units can be found in AudioGraph.Utils. Currently only conversion to and from MIDI / Hertz is available.

Node Methods

getParam : String -> Node -> Maybe Param
setParam : String -> Param -> Node -> Node
getInputFromLabel : String -> Node -> ChannelNumber

Searches a nodes inputs by label and returns the channel number that matches. If no match is found, -1 is chosen instead.

getOutputFromLabel : String -> Node -> ChannelNumber

Searches a nodes inputs by label and returns the channel number that matches. If no match is found, -1 is chosen instead.

Node Constructors

The destination node representss the final destination for all audio in the Web Audio Context. This is usually your device's speakers. You won't often need to create a destination node directly, as an emptyAudioGraph already includes one.

The destination has an ID of "_destination".

Creates an oscillator node representing a Web Audio oscillator

Creates a gain node representing a Web Audio gain node.

String
-> Dict String Param
-> Dict String ChannelNumber
-> Dict String ChannelNumber
-> ID
-> Node

You can create your own custom nodes with createCustomNode by simply providing a String to name your new node type, and a dictionary of its default parameters. Finally, passing a ID as usual will construct the new custom node.

You can then partially apply createCustomNode to create your own node generators:

createMyAwesomeNode : ID -> Node
createMyAwesomeNode =
    createCustomNode
        "MyAwesomeNode"
        (Dict.fromList
            [ ( "awesomeness", Value 100.0 )
            ]
        )
        (Dict.fromList
            [ ( "audioIn", 0 )
            , ( "awesomeness", 1 )
            ]
        )
        (Dict.fromList
            [ ( "audioOut", 0 )
            ]
        )