Node represents a generic audio node.
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 : Basics.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.
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.
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.
getID : Node -> ID
getType : Node -> Type
getParam : String -> Node -> Maybe Param
setParam : String -> Param -> Node -> Node
getInputFromLabel : String -> Node -> AudioGraph.Units.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 -> AudioGraph.Units.ChannelNumber
Searches a nodes inputs by label and returns the channel number that matches. If no match is found, -1 is chosen instead.
desintationNode : Node
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"
.
createOscillatorNode : ID -> Node
Creates an oscillator node representing a Web Audio oscillator
createGainNode : ID -> Node
Creates a gain node representing a Web Audio gain node.
createCustomNode : String -> Dict String Param -> Dict String AudioGraph.Units.ChannelNumber -> Dict String AudioGraph.Units.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 )
]
)