Skip to content

docs(node): add top-level + method docs for GainNode and ConstantSourceNode#586

Open
mvanhorn wants to merge 1 commit intoorottier:mainfrom
mvanhorn:docs/gain-constant-source-method-docs
Open

docs(node): add top-level + method docs for GainNode and ConstantSourceNode#586
mvanhorn wants to merge 1 commit intoorottier:mainfrom
mvanhorn:docs/gain-constant-source-method-docs

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

What

Brings two of the smaller node modules up to the doc standard already used by DelayNode and StereoPannerNode (which #115 cites as the reference quality bar).

Before

/// AudioNode for volume control
pub struct GainNode { ... }

impl GainNode {
    pub fn new<C: BaseAudioContext>(context: &C, options: GainOptions) -> Self { ... }
    pub fn gain(&self) -> &AudioParam { ... }
}

After

  • Top-level explainer for GainNode covering what the node is good for, MDN + spec + see-also links, a runnable # Usage example (one-second linear fade-in), and # Examples pointing at amplitude_modulation / feedback_delay.
  • Method docs on GainNode::new, GainNode::gain, ConstantSourceNode::new, and ConstantSourceNode::offset covering defaults, typical usage, and the automation surface (a-rate, ramp methods).
  • Field-level docstrings on private struct members of GainNode to mirror BiquadFilterNode / StereoPannerNode.

Why

#115 calls out DelayNode as the reference style and notes most other nodes haven't reached that bar. GainNode was the most barebones (single-line struct doc, no method docs at all), so it was the highest-leverage place to start. ConstantSourceNode already had a top-level example but its two methods were undocumented; folded that in to keep this PR a single coherent unit.

Other nodes (e.g. analyser, panner) have many more methods and would each be their own follow-up PR. Happy to take a swing at one of those next if helpful.

Test plan

  • cargo doc --no-default-features --no-deps -- 0 errors, builds cleanly
  • cargo test --no-default-features --doc -- 29 passed (the new # Usage example compiles via no_run like the existing ones)

Refs #115

…ceNode

Two of the smaller node modules had nearly empty rustdoc:

  - GainNode struct: a single line ('AudioNode for volume control'), no
    MDN/spec links, no usage example. Both `new` and `gain()` had no doc
    at all.
  - ConstantSourceNode already had a top-level example, but `new` and
    `offset()` were undocumented.

Bring them up to the standard already used by DelayNode and
StereoPannerNode (referenced in orottier#115 as the reference docs):

  - GainNode: top-level explainer covering what the node is good for,
    MDN + spec + see-also links, runnable `# Usage` example showing a
    one-second linear fade-in, `# Examples` pointing at the
    amplitude_modulation and feedback_delay examples in the repo.
  - GainNode::new + ConstantSourceNode::new: explain when callers should
    prefer the BaseAudioContext factory, and document arguments.
  - GainNode::gain + ConstantSourceNode::offset: describe default value,
    typical usage, and the automation surface (a-rate, ramp methods).
  - GainNode private fields gain/registration/channel_config: matching
    field-level docstrings to mirror BiquadFilterNode/StereoPannerNode.

`cargo doc --no-default-features --no-deps` builds cleanly.
`cargo test --no-default-features --doc` -> 29 passed (the new
`# Usage` example compiles via `no_run` like the existing ones).

Refs orottier#115
Copy link
Copy Markdown
Owner

@orottier orottier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I get another pass? The CI failure is unrelated

impl ConstantSourceNode {
/// Constructs a new `ConstantSourceNode` from explicit options.
///
/// Most callers should prefer [`BaseAudioContext::create_constant_source`],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to frame as an 'alternative' than a pref


/// Returns the offset `AudioParam`.
///
/// The default value is `1.0`. Treat the node as a *constructible*
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some slop in here, keep it tight

Comment thread src/node/gain.rs
}

/// AudioNode for volume control
/// `GainNode` applies a single gain (volume) value to its incoming audio
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For rustdocs, put linebreaks after the first line so it shows that first line as summary

Comment thread src/node/gain.rs
/// # Examples
///
/// - `cargo run --release --example amplitude_modulation`
/// - `cargo run --release --example feedback_delay`
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the best example

Comment thread src/node/gain.rs
impl GainNode {
/// Constructs a new `GainNode` from explicit options.
///
/// Most callers should prefer [`BaseAudioContext::create_gain`], which
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to frame as an 'alternative' than a pref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants