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

Replace simple audio #730

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

eRnEgIi
Copy link

@eRnEgIi eRnEgIi commented Nov 25, 2024

This is an attempt to solve the issue #725 by replacing simpleaudio with QSoundEffect from PySide6.QtMultimedia.

It works locally with ubuntu 24.04 and Python 3.12.
I have also tried to remove all dependencies, but I am not sure if I got everything.

Other versions are currently not tested. If I find time I will try to test it at least under windows.
However this is also some kind of playground for me to figure out how to trigger github actions to build the image from the existing build-multi-os workflow. (I have rarely used github at all)

Summary by CodeRabbit

  • New Features

    • Enhanced audio playback using QSoundEffect for improved performance and compatibility.
    • Updated caching and deployment processes for building release packages across multiple operating systems.
  • Bug Fixes

    • Removed the simpleaudio dependency, which may affect audio playback functionality.
  • Documentation

    • Adjustments to configuration files to improve type checking and dependency management.

Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The pull request introduces several modifications across multiple files, primarily focusing on the GitHub Actions workflow for building and deploying AYAB release packages on various operating systems. Enhancements include improved caching strategies, updates to Python versions, and changes to audio handling in the application code. The simpleaudio package has been removed in favor of using PySide6's QSoundEffect for audio playback, and adjustments were made to related configurations and dependency files.

Changes

File Path Change Summary
.github/workflows/build-multi-os.yml Updated workflow for multi-OS builds, added caching steps, specified Python version (3.11.10), streamlined dependencies, and detailed AppImage conversion process.
mypy.ini Removed ignore_missing_imports from [mypy-simpleaudio], retaining it for other sections.
requirements.build.txt Removed simpleaudio==1.0.4 from dependencies.
src/main/python/main/ayab/audio.py Replaced simpleaudio with QSoundEffect for audio playback; updated cache dictionary type and method signatures.

Possibly related PRs


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 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.

@eRnEgIi eRnEgIi marked this pull request as ready for review November 30, 2024 19:22
Copy link
Contributor

@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: 4

🧹 Outside diff range and nitpick comments (2)
src/main/python/main/ayab/audio.py (2)

Line range hint 44-48: Check if QSoundEffect is loaded before playing to avoid runtime errors

Before calling play() on a QSoundEffect instance, it's advisable to check if the sound effect is loaded and ready. This ensures that the sound will play as expected and helps avoid potential issues if the sound file failed to load.

Apply this diff to add a status check:

 wave_obj = self.__wave(sound)
 if wave_obj is None:
     return
 # else
+if wave_obj.status() != QSoundEffect.Status.Ready:
+    return
 wave_obj.play()

37-38: Consider implementing cache eviction to manage memory usage

Currently, self.__cache stores every loaded QSoundEffect indefinitely. If the application plays a large number of different sounds, this may lead to increased memory usage over time. Consider implementing a cache eviction policy or limiting the cache size to manage resources effectively.

For example, you could limit the cache to a maximum number of sounds:

MAX_CACHE_SIZE = 10

And modify the caching logic accordingly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5e781f1 and eb3862f.

📒 Files selected for processing (4)
  • .github/workflows/build-multi-os.yml (0 hunks)
  • mypy.ini (0 hunks)
  • requirements.build.txt (0 hunks)
  • src/main/python/main/ayab/audio.py (4 hunks)
💤 Files with no reviewable changes (3)
  • requirements.build.txt
  • mypy.ini
  • .github/workflows/build-multi-os.yml
🔇 Additional comments (1)
src/main/python/main/ayab/audio.py (1)

Line range hint 1-64: Verify that all references to simpleaudio have been removed from the codebase

As per the PR objectives, you've attempted to remove all dependencies on simpleaudio. To ensure that no references remain, consider running a search across the codebase.

Run the following script to check for any remaining references to simpleaudio:

This will list any files and lines where 'simpleaudio' is still referenced.

✅ Verification successful

All references to simpleaudio have been successfully removed

The comprehensive search across the codebase, including case-insensitive matches and import statements, shows no remaining references to simpleaudio. The code has been successfully migrated to use QSoundEffect from PySide6.QtMultimedia for audio playback.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any occurrences of 'simpleaudio' in the codebase.

# Search for 'simpleaudio' in Python files
rg 'simpleaudio' --glob '*.py'

# Search for 'simpleaudio' in requirements and setup files
rg 'simpleaudio' --glob 'requirements*.txt' --glob 'setup.py' --glob 'mypy.ini'

Length of output: 106


Script:

#!/bin/bash
# Let's try a more comprehensive search including git history and different case variations

# Search for any case variations of simpleaudio in all files
rg -i "simpleaudio"

# Search in git history for recently removed references
git log -p --since="1 month ago" | rg -i "simpleaudio"

# Check for any remaining .wav file handling that might indicate legacy code
ast-grep --pattern 'import $_ from "simpleaudio"'
ast-grep --pattern 'import simpleaudio'

Length of output: 113

src/main/python/main/ayab/audio.py Show resolved Hide resolved
src/main/python/main/ayab/audio.py Show resolved Hide resolved
src/main/python/main/ayab/audio.py Show resolved Hide resolved
src/main/python/main/ayab/audio.py Show resolved Hide resolved
@eRnEgIi
Copy link
Author

eRnEgIi commented Nov 30, 2024

I create a test release under https://github.com/eRnEgIi/ayab-desktop/releases and tested the sound under windows.
(Based on the .exe created from the github action)

It was still working. Linux app-image and MacOS is still untested. Maybe I will find time to test the app image, but I am unable to test the MacOS version.

In theory both should also work... but you never know :)

@dl1com dl1com changed the title Replace simple autdio Replace simple audio Dec 3, 2024
@dl1com
Copy link
Contributor

dl1com commented Dec 3, 2024

@eRnEgIi could you please have a look at the suggestions by @coderabbitai?

Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

@dl1com: I have reviewed the latest changes, and it appears that the previous suggestions have been addressed successfully. There are no remaining references to simpleaudio in the codebase, PySide6.QtMultimedia is being imported correctly in audio.py, and PySide6 is listed in requirements.build.txt. Great job!

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to 'simpleaudio' in the codebase
rg 'simpleaudio'

# Check if 'PySide6.QtMultimedia' is being imported in the codebase
rg 'from PySide6\.QtMultimedia import'

# Check if 'PySide6' is listed in 'requirements.build.txt'
rg 'PySide6' requirements.build.txt

Length of output: 189


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

✅ Actions performed

Comments resolved.

@dl1com dl1com added this to the next milestone Dec 4, 2024
@dl1com
Copy link
Contributor

dl1com commented Dec 4, 2024

LGTM, planning for next release after 1.0

@eRnEgIi
Copy link
Author

eRnEgIi commented Dec 4, 2024

@dl1com thank you for having a look. I am a little confused. Is there anything I should still have a look at or is everything already fine?
My intention was to only do as few changes as possible.

@dl1com
Copy link
Contributor

dl1com commented Dec 9, 2024

@dl1com thank you for having a look. I am a little confused. Is there anything I should still have a look at or is everything already fine? My intention was to only do as few changes as possible.

It's OK for now, thanks. We'll merge it after release of 1.0

@dl1com dl1com linked an issue Dec 13, 2024 that may be closed by this pull request
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.

Hard crash with Python 3.12 and simpleaudio
2 participants