pd-andy / elm-audio-graph / AudioGraph

Info about the library.

Definition


type AudioGraph
    = AudioGraph ({ nodes : Dict String Node, connections : List Connection })

An AudioGraph represents the structure of a Web Audio processing graph. It is very similar to the Graph Object Model available in the Soundstage javascript package.

A dictionary of Nodes stores all the currently registered graph nodes (more on those later), and a separate list tracks how Nodes are connected to one another.

Typically you won't need to create more than one AudioGraph.

emptyAudioGraph : AudioGraph

To construct an Audio Graph, start with the emptyAudioGraph which has no tracked connections and a singular Output node. The Output node represents the Web Audio context destination and has a pre-defined Node.ID of "_output".

type alias Model =
    AudioGraph

init : Model
init =
    emptyAudioGraph

Types


type alias Connection =
( ( Node.ID
, Units.ChannelNumber )
, ( Node.ID
, Units.ChannelNumber ) 
)

Represents a connection from one audio node to another. Simply a type alias for a tuple of tuples. Each inner tuple contains a NodeID and a channel number that corresponds either to an output (left tuple) or input (right tuple).

Refer to individual audio nodes for a list of input/output channels.

connectionFrom : Node.ID -> Units.ChannelNumber -> Node.ID -> Units.ChannelNumber -> Connection

Helper function to create a connection.

Graph Manipulations

addNode : Node -> AudioGraph -> AudioGraph

Insert a new node into the audio graph. Returns a new audio graph with the added node.

Note: This will replace an existing node of the same Node.ID.

getNode : Node.ID -> AudioGraph -> Maybe Node

Look up a node in the audio graph by Node.ID. Returns Just Node if found or Nothing if not.

removeNode : Node.ID -> AudioGraph -> AudioGraph

Remove a node from the audio graph. This is a NoOp if no node with the supplied Node.ID exists in the graph. Returns a new audio graph with the matching node removed.

addConnection : Connection -> AudioGraph -> AudioGraph

Add a connection to the audio graph. Currently there is no guard against duplicate connections, this is planned for the future.

removeConnection : Connection -> AudioGraph -> AudioGraph

Remove a connection from the audio graph.