Skip to content

add audio toolbar and AudioVolumeSlider widget - #511

Merged
nschimme merged 1 commit into
MUME:masterfrom
nschimme:audio-toolbar
Apr 8, 2026
Merged

add audio toolbar and AudioVolumeSlider widget#511
nschimme merged 1 commit into
MUME:masterfrom
nschimme:audio-toolbar

Conversation

@nschimme

@nschimme nschimme commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Introduce a reusable AudioVolumeSlider widget and integrate an audio toolbar into the main window while tightening audio-related ownership, configuration wiring, and slider behavior.

New Features:

  • Add an audio toolbar to the main window with separate music and sound volume controls backed by configuration.
  • Introduce a reusable AudioVolumeSlider widget that synchronizes music and sound volume with the global audio configuration and can be used across the UI.

Enhancements:

  • Refactor the audio preferences page to use AudioVolumeSlider instances instead of manual slider–configuration wiring.
  • Disable mouse wheel handling on zoom and audio sliders to avoid accidental value changes when scrolling.
  • Strengthen media and audio manager classes with explicit Rule-of-5 helpers, nodiscard annotations, defaulted destructors, and safer member initialization.
  • Guard the AudioVolumeSlider against configuration changes via a lifetime-tracked callback to keep UI volume controls in sync with settings.

Build:

  • Register the new AudioVolumeSlider sources in the main application and test CMake targets.

Tests:

  • Extend TestMainWindow with an audioToolbarTest to verify that AudioVolumeSlider instances stay in sync with configuration changes in both directions.

@sourcery-ai

sourcery-ai Bot commented Apr 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces an AudioVolumeSlider widget that synchronizes music/sound volume with the global audio configuration, integrates it into a new main-window Audio toolbar and the audio preferences page, adds tests for the slider/config interaction, and makes several small refactors/cleanups in media and UI classes.

Sequence diagram for AudioVolumeSlider updating configuration on user change

sequenceDiagram
    actor User
    participant AudioVolumeSlider
    participant QSlider
    participant Configuration
    participant AudioSettings

    User->>AudioVolumeSlider: drag slider to new position
    AudioVolumeSlider->>QSlider: setValue(newValue)
    QSlider-->>AudioVolumeSlider: valueChanged(newValue)
    AudioVolumeSlider->>AudioVolumeSlider: updateToConfig(newValue)
    AudioVolumeSlider->>Configuration: setConfig()
    Configuration-->>AudioVolumeSlider: audio settings reference
    AudioVolumeSlider->>AudioSettings: getMusicVolume()/getSoundVolume()
    AudioSettings-->>AudioVolumeSlider: currentVolume
    AudioVolumeSlider->>AudioSettings: setMusicVolume(newValue) or setSoundVolume(newValue)
    AudioVolumeSlider->>AudioSettings: setUnlocked()
Loading

Sequence diagram for configuration changes propagating back to AudioVolumeSlider

sequenceDiagram
    participant Configuration
    participant AudioSettings
    participant AudioVolumeSlider
    participant QSlider

    AudioVolumeSlider->>Configuration: setConfig().audio.registerChangeCallback(m_lifetime, callback)
    Configuration-->>AudioVolumeSlider: store callback with lifetime

    AudioSettings->>Configuration: internal volume change
    Configuration->>AudioSettings: notify registered callbacks
    AudioSettings-->>AudioVolumeSlider: invoke callback()

    AudioVolumeSlider->>AudioVolumeSlider: updateFromConfig()
    AudioVolumeSlider->>Configuration: getConfig()
    Configuration-->>AudioVolumeSlider: const audio settings
    AudioVolumeSlider->>AudioSettings: getMusicVolume()/getSoundVolume()
    AudioSettings-->>AudioVolumeSlider: actualVolume
    AudioVolumeSlider->>QSlider: setValue(actualVolume) (with SignalBlocker)
    QSlider-->>AudioVolumeSlider: valueChanged(actualVolume)
    AudioVolumeSlider->>AudioVolumeSlider: ignored due to SignalBlocker
Loading

Class diagram for the new AudioVolumeSlider and its integration

classDiagram
    direction LR

    class AudioVolumeSlider {
        <<QSlider>>
        +enum AudioType
        -Signal2Lifetime m_lifetime
        -AudioType m_type
        +AudioVolumeSlider(QWidget *parent)
        +AudioVolumeSlider(AudioType type, QWidget *parent)
        +~AudioVolumeSlider()
        +AudioType audioType() const
        +void setAudioType(AudioType type)
        +void updateFromConfig()
        +void wheelEvent(QWheelEvent *event)
        -void init()
        -void updateToConfig(int value)
    }

    class AudioPage {
        <<QWidget>>
        +void slot_loadConfig()
        +void slot_outputDeviceChanged(int index)
        +void slot_updateDevices()
    }

    class MainWindow {
        <<QMainWindow>>
        -QToolBar *audioToolBar
        +void setupToolBars()
        +void setupMenuBar()
    }

    class AudioSettings {
        <<ConfigSection>>
        +int getMusicVolume() const
        +int getSoundVolume() const
        +void setMusicVolume(int value)
        +void setSoundVolume(int value)
        +void setUnlocked()
        +void registerChangeCallback(Signal2Lifetime &lifetime, std::function<void()> callback)
    }

    class Configuration {
        +static const Configuration &getConfig()
        +static Configuration &setConfig()
        +AudioSettings audio
    }

    class SignalBlocker {
        +SignalBlocker(QSlider &slider)
    }

    class QToolBar
    class QSlider
    class QWidget
    class QMainWindow

    AudioVolumeSlider --|> QSlider
    AudioPage --|> QWidget
    MainWindow --|> QMainWindow

    Configuration o-- AudioSettings : has
    AudioVolumeSlider --> Configuration : uses getConfig
    AudioVolumeSlider --> Configuration : uses setConfig
    AudioVolumeSlider --> AudioSettings : reads_writes
    AudioVolumeSlider --> SignalBlocker : uses

    AudioPage --> AudioVolumeSlider : ui_members
    AudioPage --> Configuration : uses getConfig

    MainWindow --> QToolBar : creates
    MainWindow --> AudioVolumeSlider : embeds_in_audioToolBar
Loading

File-Level Changes

Change Details Files
Add reusable AudioVolumeSlider widget that binds a QSlider to audio configuration for music and sound volumes.
  • Implement AudioVolumeSlider class with AudioType enum, configuration-backed value syncing, and tooltips for music vs sound.
  • Register a configuration change callback via Signal2Lifetime so the slider updates when config changes externally.
  • Block slider signals while applying config-driven updates and ignore wheel events to prevent accidental scrolling changes.
  • Disallow copy/move for AudioVolumeSlider via DELETE_CTORS_AND_ASSIGN_OPS and wire it into the build system.
src/mainwindow/AudioVolumeSlider.h
src/mainwindow/AudioVolumeSlider.cpp
src/CMakeLists.txt
tests/CMakeLists.txt
Integrate AudioVolumeSlider into the main window as a dedicated Audio toolbar.
  • Create audioToolBar member on MainWindow, initialize it in setupToolBars, and hide it by default similar to other toolbars.
  • Add two AudioVolumeSlider instances (Music and Sound) to the toolbar separated by a separator.
  • Expose the Audio toolbar toggle action in the View → Toolbars menu so users can show/hide it.
src/mainwindow/mainwindow.h
src/mainwindow/mainwindow.cpp
Refactor the Audio preferences page to delegate volume handling to AudioVolumeSlider instead of manual slider logic.
  • Replace direct get/set of music/sound volumes on QSlider with calls to AudioVolumeSlider::updateFromConfig().
  • Remove valueChanged connections and slot_musicVolumeChanged/slot_soundsVolumeChanged, moving responsibility into the widget itself.
  • Simplify NO_AUDIO handling by relying on the slider’s own NO_AUDIO gating instead of disabling the UI sliders explicitly.
src/preferences/audiopage.cpp
src/preferences/audiopage.h
src/preferences/audiopage.ui
Add unit tests for audio toolbar/AudioVolumeSlider behavior and wire AudioVolumeSlider into the test target.
  • Extend TestMainWindow with audioToolbarTest that verifies initial slider values, config→slider updates, and slider→config updates for both music and sound.
  • Use QScopeGuard to restore original audio configuration after the test to avoid cross-test contamination.
  • Include AudioVolumeSlider sources in the mainwindow test CMake target and include configuration headers needed for the test.
tests/TestMainWindow.h
tests/TestMainWindow.cpp
tests/CMakeLists.txt
Prevent accidental zoom changes via mouse wheel on MapZoomSlider and apply the same pattern to AudioVolumeSlider.
  • Override MapZoomSlider::wheelEvent to ignore wheel events instead of changing the value.
  • Include QWheelEvent in MapZoomSlider and AudioVolumeSlider implementations and override wheelEvent in AudioVolumeSlider as well.
src/mainwindow/MapZoomSlider.h
src/mainwindow/MapZoomSlider.cpp
src/mainwindow/AudioVolumeSlider.cpp
Minor safety and code-quality improvements in media and other components.
  • Default-initialize various pointer members (DescriptionWidget labels, SfxManager output) and mark some destructors as =default for clarity.
  • Mark MediaLibrary::findAudio/findImage as NODISCARD to avoid accidentally ignoring results.
  • Make MusicManager and SfxManager non-copyable via DELETE_CTORS_AND_ASSIGN_OPS and comment future plan to replace raw array with std::array.
  • Silence unused-parameter warnings in MusicManager::playMusic and SfxManager::startEffect with MAYBE_UNUSED.
  • Switch Mmapper2Group and SliderSpinboxButton destructors to =default for consistency.
src/media/DescriptionWidget.h
src/media/MediaLibrary.h
src/media/MusicManager.h
src/media/MusicManager.cpp
src/media/SfxManager.h
src/media/SfxManager.cpp
src/group/mmapper2group.cpp
src/preferences/AdvancedGraphics.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In AudioVolumeSlider::setAudioType you use toolTip().length() > 0 as an implicit initialization guard; consider replacing this with an explicit boolean flag or a clearer state check to avoid relying on UI text as program logic.
  • Both AudioVolumeSlider and MapZoomSlider override wheelEvent to always ignore() the event; if the intent is to fully disable wheel-based value changes, you may want to document this behavior or consider consuming the event instead to avoid confusing focus/scroll interactions in complex layouts.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In AudioVolumeSlider::setAudioType you use `toolTip().length() > 0` as an implicit initialization guard; consider replacing this with an explicit boolean flag or a clearer state check to avoid relying on UI text as program logic.
- Both AudioVolumeSlider and MapZoomSlider override wheelEvent to always `ignore()` the event; if the intent is to fully disable wheel-based value changes, you may want to document this behavior or consider consuming the event instead to avoid confusing focus/scroll interactions in complex layouts.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@nschimme
nschimme merged commit 5d245c3 into MUME:master Apr 8, 2026
18 checks passed
@nschimme
nschimme deleted the audio-toolbar branch April 8, 2026 00:50
@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.52747% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.21%. Comparing base (91be79e) to head (10162ea).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/mainwindow/mainwindow.cpp 0.00% 9 Missing ⚠️
src/mainwindow/AudioVolumeSlider.cpp 88.23% 6 Missing ⚠️
src/mainwindow/AudioVolumeSlider.h 33.33% 2 Missing ⚠️
src/mainwindow/MapZoomSlider.cpp 0.00% 2 Missing ⚠️
src/preferences/audiopage.cpp 0.00% 2 Missing ⚠️
src/group/mmapper2group.cpp 0.00% 1 Missing ⚠️
src/media/MusicManager.cpp 0.00% 1 Missing ⚠️
src/media/SfxManager.cpp 0.00% 1 Missing ⚠️
src/preferences/AdvancedGraphics.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #511      +/-   ##
==========================================
+ Coverage   25.04%   25.21%   +0.16%     
==========================================
  Files         510      512       +2     
  Lines       42292    42367      +75     
  Branches     4577     4577              
==========================================
+ Hits        10594    10681      +87     
+ Misses      31698    31686      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant