Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: web audio example #3968

Merged
merged 1 commit into from
Dec 25, 2024
Merged

Fix: web audio example #3968

merged 1 commit into from
Dec 25, 2024

Conversation

katspaugh
Copy link
Owner

@katspaugh katspaugh commented Dec 25, 2024

Short description

Resolves #3821

Implementation details

The Web Audio example is updated to initialize AudioContext on wavesurfer play.

Summary by CodeRabbit

  • New Features

    • Enhanced audio equalizer functionality with real-time gain adjustments via sliders.
    • Integrated media controls directly into the audio player interface.
  • Bug Fixes

    • Improved clarity in event handling for mouse interactions within the regions plugin.
  • Refactor

    • Streamlined handling of the timeOffset property in the timeline plugin, ensuring a default value is set.
  • Chores

    • Code formatting improvements for better readability across various classes and methods.

Copy link

coderabbitai bot commented Dec 25, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/webaudio.js

Oops! Something went wrong! :(

ESLint: 9.17.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

Walkthrough

The pull request introduces modifications to the Web Audio example in examples/webaudio.js and updates to the regions.ts and timeline.ts plugin files. The Web Audio example changes focus on simplifying audio source management and enhancing equalizer functionality by removing the explicit audio element and integrating media controls directly into WaveSurfer. The plugin files receive minor formatting and default value adjustments that do not significantly alter their core functionality.

Changes

File Change Summary
examples/webaudio.js - Removed manual audio element creation
- Added direct URL reference for audio source
- Integrated media controls in WaveSurfer
- Enhanced equalizer with dynamic filter bands and sliders
src/plugins/regions.ts - Reformatted constructor and method signatures
- Minor code readability improvements
src/plugins/timeline.ts - Added default value for timeOffset
- Removed defaultTimeOffset method
- Simplified offset calculation

Sequence Diagram

sequenceDiagram
    participant User
    participant WaveSurfer
    participant AudioContext
    participant Equalizer

    User->>WaveSurfer: Initialize with URL
    WaveSurfer->>AudioContext: Create Media Source
    WaveSurfer->>Equalizer: Setup Filter Bands
    User->>Equalizer: Adjust Slider Gains
    Equalizer->>AudioContext: Modify Frequency Gains
Loading

Assessment against linked issues

Objective Addressed Explanation
Resolve Chrome audio initialization issue [#3821]
Enable gain controls for audio channels

Possibly related PRs

Poem

🎵 In waves of sound, a rabbit's delight,
Equalizers dancing, frequencies bright
Chrome's barriers fall, with sliders so sleek
Audio magic, no longer weak! 🐰🎧

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Deploying wavesurfer-js with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3e8ed03
Status: ✅  Deploy successful!
Preview URL: https://5b9f1c34.wavesurfer-js.pages.dev
Branch Preview URL: https://webaudio.wavesurfer-js.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
examples/webaudio.js (3)

17-17: Potential confusion in click handler naming.
Calling wavesurfer.playPause() inside a 'click' event might confuse new users expecting a separate “play” method. Consider renaming the event or clarifying it in comments.


36-40: Consider a named function or comment for clarity.
Chaining filters via .reduce is concise. A small comment explaining the chaining logic may improve maintainability.


52-66: Random initialization of slider values.
Using random defaults is fine for demos, but might introduce unpredictable behaviors for testing or production. Keep this in mind if consistent start values become necessary.

src/plugins/timeline.ts (1)

254-254: Straightforward timeline offset logic.
(i + this.options.timeOffset) * pxPerSec is concise and clear. Make sure to note in documentation that timeOffset shifts the timeline's labeling rather than the audio playback.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14bb9a3 and 3e8ed03.

📒 Files selected for processing (3)
  • examples/webaudio.js (1 hunks)
  • src/plugins/regions.ts (2 hunks)
  • src/plugins/timeline.ts (3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
examples/webaudio.js

[error] 48-48: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (9)
examples/webaudio.js (5)

5-6: Good introduction of eqBands.
Defining the equalizer bands upfront clarifies the audio processing pipeline.


13-14: Confirm the media file path.
Ensure that '/examples/audio/audio.wav' is correctly spelled and exists in your deployment environment.


19-31: Delay audio context creation until user gesture.
Creating the AudioContext inside once('play') is recommended for modern browser autoplay policies. Great approach!


33-34: Validate autoplay policies for createMediaElementSource.
Some browsers require explicit user gestures prior to creating media nodes. This seems fine since it’s inside the 'play' listener, but keep an eye on older or niche browsers.


42-43: Well-structured output routing.
Connecting the last filter node to audioContext.destination is a standard approach. Looks good!

src/plugins/timeline.ts (2)

28-28: Optional timeOffset property is a neat addition.
It gives developers more flexibility in labeling the timeline beyond the default start time.


39-39: Default value for timeOffset.
Defining a default of 0 is good practice to ensure consistent calculations even if not set by the user.

src/plugins/regions.ts (2)

98-102: Constructor parameter formatting.
Splitting params, totalDuration, and numberOfChannels across lines reads well. No functional changes needed.


270-270: Explicit condition for drag.
Using if (this.drag) this.emit('update-end') is clearer than coupling checks with other logic. Nice improvement.

Comment on lines +45 to +50
sliders.forEach((slider, i) => {
const filter = filters[i]
filter.gain.value = slider.value
slider.oninput = (e) => (filter.gain.value = e.target.value)
})
})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid assignment inside arrow function return.
Static analysis flagged line 48 as confusing because of the inline assignment:

slider.oninput = (e) => (filter.gain.value = e.target.value)

Move the assignment into a block for improved readability:

- slider.oninput = (e) => (filter.gain.value = e.target.value)
+ slider.oninput = (e) => {
+   filter.gain.value = e.target.value
+ }
🧰 Tools
🪛 Biome (1.9.4)

[error] 48-48: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

@katspaugh katspaugh merged commit e1dabf2 into main Dec 25, 2024
6 checks passed
@katspaugh katspaugh deleted the webaudio branch December 25, 2024 08:35
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.

Web Audio example no longer works in Chrome 127.0.6533.100
1 participant