Skip to content

Extend audio graph with new methods#266

Merged
waynemwashuma merged 4 commits intowimaengine:devfrom
waynemwashuma:extend-audio-graph-with-new-methods
Sep 27, 2025
Merged

Extend audio graph with new methods#266
waynemwashuma merged 4 commits intowimaengine:devfrom
waynemwashuma:extend-audio-graph-with-new-methods

Conversation

@waynemwashuma
Copy link
Collaborator

@waynemwashuma waynemwashuma commented Sep 27, 2025

Objective

Extends the AudioGraph resource to support dynamic updates and safer lifecycle management of audio nodes. It introduces a new update method, a get accessor, and a stricter node typing system to improve flexibility and maintainability of the audio graph.

Solution

  • Introduced AudioGraphNode type to distinguish between different audio node types and thier variants.
  • Updated the internal graph to store AudioGraphNode instead of raw AudioNode.
    Added the new methods:
  • get: retrieves the node weight for a given node ID.
  • update: replaces an existing node at a given ID with a new one.It
    • Automatically stops and disconnects the old node.
    • Ensures all edges remain connected by reattaching the new node to neighbors.

Showcase

A new update workflow is enabled through the update method:

// Replace an oscillator node with a new one
const nodeId = graph.add(undefined)
graph.update(nodeId, new OscillatorNode(graph.getContext(), { frequency: 440 }))

Switching playback modes dynamically:

if (playback.completed()) {
  graph.update(nodeId, undefined) // stops and clears node automatically
}

Accessing a node:

const node = graph.get(nodeId)
if (node instanceof OscillatorNode) {
  node.frequency.value = 880
}

Migration guide

No breaking changes are introduced.

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Sep 27, 2025
@waynemwashuma waynemwashuma added type:enhancement New feature or request mod:audio labels Sep 27, 2025
@waynemwashuma waynemwashuma marked this pull request as ready for review September 27, 2025 04:58
@waynemwashuma waynemwashuma merged commit 7ed7497 into wimaengine:dev Sep 27, 2025
5 checks passed
@waynemwashuma waynemwashuma deleted the extend-audio-graph-with-new-methods branch September 27, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:audio type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant