Repository navigation
11098 fix assert on device change - #11245
saintmatthieu merged 11 commits into
Conversation
|
@CodeRabbit review |
✅ Action performedReview finished.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR introduces a Estimated code review effort: 4 (Complex) | ~75 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant PlaybackController
participant Transport
participant Au3Player
User->>PlaybackController: togglePlayAction()
PlaybackController->>Transport: togglePlay(ignoreSelection)
Transport->>Au3Player: play() / pause() / stop() / seek()
Au3Player-->>Transport: isPlayingChanged notification
Transport-->>PlaybackController: isPlayAllowedChanged notification
sequenceDiagram
participant CommonAudioApiConfigurationModel
participant Transport
participant AudioDevicesProvider
participant Au3Player
CommonAudioApiConfigurationModel->>Transport: setAudioOutputDevice(device)
Transport->>Au3Player: stop() if playing/paused
Transport->>AudioDevicesProvider: apply device change
Transport->>Au3Player: resume/play if previously playing
Related Issues: None identified from provided data. Related PRs: None identified from provided data. Suggested labels: playback, refactor, tests Suggested reviewers: None identified from provided data. 🐰 A rabbit hops through transport lanes, 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Warning Review ran into problems🔥 ProblemsLinked repositories: Your configuration references 1 linked repositories, but your current plan allows 0. Analyzed ``, skipped Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 53c8ecaa-3d20-4298-b3e8-b76813b40452
📥 Commits
Reviewing files that changed from the base of the PR and between d6610f0 and 254ccb5f906987b6c17a48d4517c11009c210351.
📒 Files selected for processing (11)
CMakeLists.txtsrc/au3audio/CMakeLists.txtsrc/au3audio/internal/au3audiodevicesprovider.cppsrc/au3audio/internal/au3audiodevicesprovider.hsrc/au3audio/tests/CMakeLists.txtsrc/au3audio/tests/au3audiodevicesprovider_tests.cppsrc/au3audio/tests/mocks/audioenginemock.hsrc/playback/internal/playbackcontroller.cppsrc/playback/internal/playbackcontroller.hsrc/playback/tests/environment.cppsrc/playback/tests/playbackcontroller_tests.cpp
254ccb5 to
8be9d3d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/au3audio/tests/au3audiodevicesprovider_tests.cpp (1)
19-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a dedicated null-engine test case.
Au3AudioDevicesProviderTests::SetUp()always setsm_provider->audioEngine, so this suite only exercises engine-present paths. Add one test that leavesaudioEngineunset and verifieshandleDeviceChange()returns safely without engine calls.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 0d3e9a06-5e70-4716-a469-f4ddbe3b3bcb
📥 Commits
Reviewing files that changed from the base of the PR and between 254ccb5f906987b6c17a48d4517c11009c210351 and 8be9d3d48cc1cc95e367cf31f7a7c0f71ce9658f.
📒 Files selected for processing (10)
CMakeLists.txtsrc/au3audio/CMakeLists.txtsrc/au3audio/internal/au3audiodevicesprovider.hsrc/au3audio/tests/CMakeLists.txtsrc/au3audio/tests/au3audiodevicesprovider_tests.cppsrc/au3audio/tests/mocks/audioenginemock.hsrc/playback/internal/playbackcontroller.cppsrc/playback/internal/playbackcontroller.hsrc/playback/tests/environment.cppsrc/playback/tests/playbackcontroller_tests.cpp
✅ Files skipped from review due to trivial changes (4)
- src/au3audio/internal/au3audiodevicesprovider.h
- src/au3audio/CMakeLists.txt
- CMakeLists.txt
- src/playback/internal/playbackcontroller.h
🚧 Files skipped from review as they are similar to previous changes (4)
- src/au3audio/tests/CMakeLists.txt
- src/playback/tests/environment.cpp
- src/au3audio/tests/mocks/audioenginemock.h
- src/playback/tests/playbackcontroller_tests.cpp
8be9d3d to
6873658
Compare
luapmartin
left a comment
There was a problem hiding this comment.
looks ok, should we add a bounds check guard new test for the device id fallback ?
|
also you might want to adjust those commit message as we don't restore the paused state in practice |
6873658 to
0acc4a4
Compare
| EXPECT_CALL(*m_audioEngine, stopMonitoring()).Times(1); | ||
| EXPECT_CALL(*m_audioEngine, stopStream()).Times(0); | ||
| EXPECT_CALL(*m_audioEngine, handleDeviceChange()).Times(1); | ||
|
|
There was a problem hiding this comment.
is the monitoring resumed?
| handleDeviceChange(); | ||
| } |
There was a problem hiding this comment.
after that should we check that the stream and/or monitoring restarted?
There was a problem hiding this comment.
It definitely should!
There was a problem hiding this comment.
... although ... not at this lower device-provider level. This is something for the playback controller tests. But good catch! Will address it there.
| EXPECT_CALL(*m_recordController, isRecording()) | ||
| .WillRepeatedly(Return(true)); | ||
|
|
||
| //! [THEN] The stream is stopped but playback is not resumed | ||
| EXPECT_CALL(*m_player, stop()).Times(1); | ||
| EXPECT_CALL(*m_player, play()).Times(0); | ||
| EXPECT_CALL(*m_player, pause()).Times(0); | ||
|
|
||
| //! [WHEN] The device is changed | ||
| changeAudioDevice([this]() { m_events.push_back("apply"); }); |
There was a problem hiding this comment.
here we might also want to test the recordController stops ? not only the player
0acc4a4 to
608846f
Compare
There was a problem hiding this comment.
Actionable comments posted: 6
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 8e8e00d4-ac90-4aeb-9ae2-20f5d2dfdfab
📥 Commits
Reviewing files that changed from the base of the PR and between 0acc4a4449b75eacbb5e7fc16d050d47e53f38f8 and 608846f3a6bd6173c0c715402cc81f3def27fe60.
📒 Files selected for processing (42)
CMakeLists.txtsrc/appshell/internal/startupscenario.hsrc/au3audio/CMakeLists.txtsrc/au3audio/internal/au3audiodevicesprovider.cppsrc/au3audio/internal/au3audiodevicesprovider.hsrc/au3audio/tests/CMakeLists.txtsrc/au3audio/tests/au3audiodevicesprovider_tests.cppsrc/au3audio/tests/mocks/audioenginemock.hsrc/context/internal/uicontextresolver.hsrc/effects/builtin_collection/dynamics/timeline/dynamicsplaystatemodel.hsrc/effects/effects_base/internal/effectsactionscontroller.hsrc/importexport/export/internal/au3/au3exporter.hsrc/importexport/export/view/exportpreferencesmodel.hsrc/playback/CMakeLists.txtsrc/playback/iaudioconfigurationscenario.hsrc/playback/internal/audioconfigurationscenario.cppsrc/playback/internal/audioconfigurationscenario.hsrc/playback/internal/playbackcontroller.cppsrc/playback/internal/playbackcontroller.hsrc/playback/internal/transportscenario.cppsrc/playback/internal/transportscenario.hsrc/playback/itransportscenario.hsrc/playback/playbackmodule.cppsrc/playback/playbackmodule.hsrc/playback/tests/environment.cppsrc/playback/tests/playbackcontroller_tests.cppsrc/playback/view/common/playbackstatemodel.hsrc/playback/view/panels/playbackmeterpanelmodel.hsrc/playback/view/toolbars/playbacktoolbarlevelitem.hsrc/preferences/qml/Audacity/Preferences/commonaudioapiconfigurationmodel.cppsrc/preferences/qml/Audacity/Preferences/commonaudioapiconfigurationmodel.hsrc/preferences/qml/Audacity/Preferences/internal/AudioApiSection.qmlsrc/preferences/qml/Audacity/Preferences/internal/BufferAndLatencySection.qmlsrc/preferences/qml/Audacity/Preferences/internal/SampleRateSection.qmlsrc/projectscene/view/common/trackviewstatemodel.hsrc/projectscene/view/timeline/playregioncontroller.hsrc/projectscene/view/timeline/playregionmodel.hsrc/projectscene/view/timeline/timelinecontext.hsrc/projectscene/view/toolbars/playbacktoolbarmodel.hsrc/record/internal/au3/au3audioinput.hsrc/record/internal/recordcontroller.hsrc/trackedit/internal/trackeditinteraction.h
💤 Files with no reviewable changes (2)
- src/preferences/qml/Audacity/Preferences/internal/SampleRateSection.qml
- src/preferences/qml/Audacity/Preferences/internal/AudioApiSection.qml
✅ Files skipped from review due to trivial changes (3)
- src/effects/effects_base/internal/effectsactionscontroller.h
- src/playback/iaudioconfigurationscenario.h
- src/playback/playbackmodule.h
🚧 Files skipped from review as they are similar to previous changes (7)
- src/au3audio/internal/au3audiodevicesprovider.h
- src/au3audio/CMakeLists.txt
- CMakeLists.txt
- src/playback/tests/environment.cpp
- src/au3audio/tests/CMakeLists.txt
- src/au3audio/internal/au3audiodevicesprovider.cpp
- src/au3audio/tests/mocks/audioenginemock.h
608846f to
7c44b33
Compare
|
@codereabbit review |
|
Partially resolves #9180 |
|
@CodeRabbit full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/playback/internal/au3/au3playback.cpp (1)
8-18: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRebind the global player when the active project changes
PlaybackContext::onInit()eagerly creates one player, andAu3Playback::player()only callsglobalContext()->setPlayer(m_player)on first access.GlobalContextholds a singlePlaybackState, so with multiple open projects the app-wide playback state can stay attached to whichever project touched playback first. Re-sync it on project activation, or make the single-project assumption explicit.src/playback/internal/playbackcontroller.cpp (1)
222-229: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winResolve the input-channel index before applying it.
Line 228 passes
input-channels_indexdirectly as the channel count, unlike the API/device handlers that resolve indices to selected values. Selecting the first entry can send0channels and misconfigure recording input; resolve and bounds-check against the available channel options before callingtransport()->setInputChannels(...).Proposed fix
void PlaybackController::setInputChannels(const muse::actions::ActionQuery& q) { IF_ASSERT_FAILED(q.contains("input-channels_index")) { return; } - transport()->setInputChannels(q.param("input-channels_index").toInt()); + const int index = q.param("input-channels_index").toInt(); + const auto& options = audioDevicesProvider()->inputChannels(); + IF_ASSERT_FAILED(index >= 0 && index < static_cast<int>(options.size())) { + return; + } + + transport()->setInputChannels(options.at(index)); }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: d2abe8dc-031e-4cf6-ae13-5036ee27c557
📥 Commits
Reviewing files that changed from the base of the PR and between 15de5c5 and 217c257f5feda0a44924c242e3ca97419a20adad.
📒 Files selected for processing (65)
CMakeLists.txtsrc/appshell/internal/startupscenario.cppsrc/appshell/internal/startupscenario.hsrc/au3audio/CMakeLists.txtsrc/au3audio/internal/au3audiodevicesprovider.cppsrc/au3audio/internal/au3audiodevicesprovider.hsrc/au3audio/tests/CMakeLists.txtsrc/au3audio/tests/au3audiodevicesprovider_tests.cppsrc/au3audio/tests/mocks/audioenginemock.hsrc/context/internal/uicontextresolver.cppsrc/context/internal/uicontextresolver.hsrc/effects/builtin_collection/dynamics/timeline/dynamicsplaystatemodel.cppsrc/effects/builtin_collection/dynamics/timeline/dynamicsplaystatemodel.hsrc/effects/effects_base/internal/effectsactionscontroller.cppsrc/effects/effects_base/internal/effectsactionscontroller.hsrc/importexport/export/internal/au3/au3exporter.cppsrc/importexport/export/internal/au3/au3exporter.hsrc/importexport/export/view/exportpreferencesmodel.cppsrc/importexport/export/view/exportpreferencesmodel.hsrc/playback/CMakeLists.txtsrc/playback/internal/au3/au3playback.cppsrc/playback/internal/au3/au3playback.hsrc/playback/internal/au3/au3player.cppsrc/playback/internal/au3/au3player.hsrc/playback/internal/playbackcontroller.cppsrc/playback/internal/playbackcontroller.hsrc/playback/internal/playbackuiactions.cppsrc/playback/internal/playbackuiactions.hsrc/playback/internal/transport.cppsrc/playback/internal/transport.hsrc/playback/iplaybackcontroller.hsrc/playback/iplayer.hsrc/playback/itransport.hsrc/playback/playbackmodule.cppsrc/playback/playbackmodule.hsrc/playback/tests/CMakeLists.txtsrc/playback/tests/environment.cppsrc/playback/tests/mocks/playermock.hsrc/playback/tests/transport_tests.cppsrc/playback/view/common/playbackstatemodel.cppsrc/playback/view/common/playbackstatemodel.hsrc/playback/view/panels/playbackmeterpanelmodel.cppsrc/playback/view/panels/playbackmeterpanelmodel.hsrc/playback/view/toolbars/playbacktoolbarlevelitem.cppsrc/playback/view/toolbars/playbacktoolbarlevelitem.hsrc/preferences/qml/Audacity/Preferences/commonaudioapiconfigurationmodel.cppsrc/preferences/qml/Audacity/Preferences/commonaudioapiconfigurationmodel.hsrc/preferences/qml/Audacity/Preferences/internal/AudioApiSection.qmlsrc/preferences/qml/Audacity/Preferences/internal/BufferAndLatencySection.qmlsrc/preferences/qml/Audacity/Preferences/internal/SampleRateSection.qmlsrc/projectscene/view/common/trackviewstatemodel.cppsrc/projectscene/view/common/trackviewstatemodel.hsrc/projectscene/view/timeline/playregioncontroller.cppsrc/projectscene/view/timeline/playregioncontroller.hsrc/projectscene/view/timeline/playregionmodel.cppsrc/projectscene/view/timeline/playregionmodel.hsrc/projectscene/view/timeline/timelinecontext.cppsrc/projectscene/view/timeline/timelinecontext.hsrc/projectscene/view/toolbars/playbacktoolbarmodel.cppsrc/projectscene/view/toolbars/playbacktoolbarmodel.hsrc/record/internal/au3/au3audioinput.cppsrc/record/internal/au3/au3audioinput.hsrc/record/internal/recordcontroller.cppsrc/record/internal/recordcontroller.hsrc/trackedit/internal/trackeditinteraction.h
💤 Files with no reviewable changes (5)
- src/playback/iplaybackcontroller.h
- src/playback/view/toolbars/playbacktoolbarlevelitem.h
- src/preferences/qml/Audacity/Preferences/internal/SampleRateSection.qml
- src/playback/view/panels/playbackmeterpanelmodel.h
- src/preferences/qml/Audacity/Preferences/internal/AudioApiSection.qml
| /** | ||
| * @brief Toggle play when already playing with run from start position | ||
| * @details User clicked play with Shift modifier | ||
| * Playback should run from start position | ||
| */ | ||
| TEST_F(PlaybackControllerTests, TogglePlay_WhenPlaying_PlayAgain) | ||
| TEST_F(TransportTests, TogglePlay_WhenPlaying_PlayAgain) | ||
| { | ||
| //! [GIVEN] Playback is running | ||
| ON_CALL(*m_player, playbackStatus()) | ||
| .WillByDefault(Return(PlaybackStatus::Running)); | ||
|
|
||
| //! [GIVEN] Play with Shift modifier | ||
| ON_CALL(*m_application, keyboardModifiers()) | ||
| .WillByDefault(Return(Qt::ShiftModifier)); | ||
|
|
||
| //! [THEN] Player should stop playing | ||
| EXPECT_CALL(*m_player, stop()) | ||
| .Times(1); | ||
|
|
||
| //! [WHEN] Toggle play | ||
| togglePlay(); | ||
| //! [WHEN] Toggle play ignoring selection (Shift+Space) | ||
| m_transport->togglePlay(true /* ignoreSelection */); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Test doesn't verify the "run from start position" behavior it documents.
The docstring claims playback should "run from start position" when toggling play again while playing (ignore-selection), but the test only asserts stop() is called once — there's no EXPECT_CALL on play() or seek(...) to confirm playback actually restarts from the beginning. Since m_player is a NiceMock, an unmocked play() call is silently allowed either way, so this test would pass even if the restart-from-start behavior is missing entirely.
This is particularly relevant since PR comments flag that "the paused state is not actually restored in practice" for this same play/pause/resume flow — this test gap could be masking that exact issue.
There was a problem hiding this comment.
Will look closer, but note that this test case is almost a verbatim of TEST_F(PlaybackControllerTests, TogglePlay_WhenPlaying_PlayAgain) currently on master.
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
git fetch origin main --depth=50 2>&1 | tail -5 || true
git log --oneline -3 origin/main -- src/playback/tests/ 2>&1 || true
# Find the base commit for this PR branch
git merge-base HEAD origin/main 2>&1 || true
</dev/nullLength of output: 3425
@saintmatthieu, you're right — I traced through the diff again and confirmed this test is a near-1:1 carryover: the only changes are the rename from PlaybackControllerTests to TransportTests and swapping the keyboardModifiers()/togglePlay() plumbing for the direct m_transport->togglePlay(true /* ignoreSelection */) call. No assertions were added or removed around play()/seek() — the gap (missing verification that playback actually restarts from position 0 after stop) already exists on master.
So this isn't a regression introduced by this PR, just a pre-existing test coverage gap that happened to catch my eye during the migration review. Given that, I won't insist on it blocking this PR. If you'd like, I can help draft a small follow-up test addition (e.g., asserting seek(0.0, _) and play() after stop() in this scenario) either here or as a separate issue — your call.
🧬 Code Graph Analysis Results
src/playback/tests/mocks/playermock.h (lines 10-59)
namespace au::playback {
class PlayerMock : public IPlayer
{
public:
MOCK_METHOD(bool, isBusy, (), (const, override));
MOCK_METHOD(void, play, (), (override));
MOCK_METHOD(void, seek, (const muse::secs_t, bool), (override));
MOCK_METHOD(void, rewind, (), (override));
MOCK_METHOD(void, stop, (), (override));
MOCK_METHOD(void, pause, (), (override));
MOCK_METHOD(void, resume, (), (override));
MOCK_METHOD(bool, isRunning, (), (const, override));
MOCK_METHOD(PlaybackStatus, playbackStatus, (), (const, override));
MOCK_METHOD(muse::async::Channel<PlaybackStatus>, playbackStatusChanged, (), (const, override));
MOCK_METHOD(muse::ValNt<bool>, reachedEnd, (), (const, override));
MOCK_METHOD(PlaybackRegion, playbackRegion, (), (const, override));
MOCK_METHOD(void, setPlaybackRegion, (const PlaybackRegion&), (override));
MOCK_METHOD(PlaybackRegion, loopRegion, (), (const, override));
MOCK_METHOD(void, loopEditingBegin, (), (override));
MOCK_METHOD(void, loopEditingEnd, (), (override));
MOCK_METHOD(void, setLoopRegion, (const PlaybackRegion&), (override));
MOCK_METHOD(void, setLoopRegionStart, (const muse::secs_t time), (override));
MOCK_METHOD(void, setLoopRegionEnd, (const muse::secs_t time), (override));
MOCK_METHOD(void, clearLoopRegion, (), (override));
MOCK_METHOD(muse::async::Notification, loopRegionChanged, (), (const, override));
MOCK_METHOD(bool, isLoopRegionClear, (), (const, override));
MOCK_METHOD(void, setLoopRegionActive, (const bool), (override));
MOCK_METHOD(bool, isLoopRegionActive, (), (const, override));
MOCK_METHOD(muse::secs_t, playbackPosition, (), (const, override));
MOCK_METHOD(void, updatePlaybackPosition, (), (override));
MOCK_METHOD(muse::async::Channel<muse::secs_t>, playbackPositionChanged, (), (const, override));
MOCK_METHOD(muse::Ret, playTracks, (TrackList&, double, double, const PlayTracksOptions&), (override));
MOCK_METHOD(muse::async::Notification, isPlayingChanged, (), (const, override));
//! The raw status predicates derive from playbackStatus() so tests can drive
//! the whole transport state machine by stubbing a single getter.
bool isPlaying() const override { return playbackStatus() == PlaybackStatus::Running; }
bool isPaused() const override { return playbackStatus() == PlaybackStatus::Paused; }
bool isStopped() const override { return playbackStatus() == PlaybackStatus::Stopped; }
};
}src/playback/tests/mocks/playbackmock.h (lines 10-17)
namespace au::playback {
class PlaybackMock : public IPlayback
{
public:
MOCK_METHOD(std::shared_ptr<IPlayer>, player, (TrackSequenceId), (const, override));
MOCK_METHOD(std::shared_ptr<IAudioOutput>, audioOutput, (), (const, override));
};
}🧠 Learnings used
Learnt from: saintmatthieu
Repo: audacity/audacity PR: 10597
File: src/effects/effects_base/internal/au3/au3audiopluginmetareader.cpp:61-68
Timestamp: 2026-03-31T16:35:57.623Z
Learning: In Audacity’s codebase, `IF_ASSERT_FAILED(condition)` is a failure-only conditional: it executes its body when `condition` is falsy (i.e., the assertion fails). Treat patterns like `IF_ASSERT_FAILED(x) { return ...; }` as correct early-return control flow rather than a control-flow bug, since the body runs exactly on assertion failure (like `if (!condition)`, but with assertion triggering).
Learnt from: DPDmancul
Repo: audacity/audacity PR: 10776
File: src/tracks/ui/TextEditHelper.cpp:99-112
Timestamp: 2026-04-22T21:55:54.795Z
Learning: When handling wxWidgets keyboard modifier flags, treat `wxMOD_CONTROL` (0x0002) as the physical Ctrl key on all platforms. On macOS, the Command key is `wxMOD_META` (0x0008), not `wxMOD_CONTROL`. Use `wxMOD_CMD` as an alias (it maps to `wxMOD_META` on macOS and `wxMOD_CONTROL` on Windows/Linux). Therefore, a mask such as `wxMOD_SHIFT | wxMOD_ALTGR` (0x0007) will not match Command key combinations on macOS because `wxMOD_META` (0x0008) is outside that mask; only flag/mask modifier logic accordingly.
217c257 to
9df4e97
Compare
9df4e97 to
ee38692
Compare
b3a4cd3 to
b67b7c3
Compare
|
Is this solving the exact same problem as here? |
There was a problem hiding this comment.
Oops - thanks.
b67b7c3 to
4adc6a5
Compare
|
@saintmatthieu I simply asked whether they solve the same problem. And why did you choose a new approach and If this approach is better, will we replace the old one in trackedit? |
|
@Eism in the trackedit case I think the decorator pattern makes sense because it allows to eliminate the dependency of TrackeditOperationController on playback and record. In this case, |
4adc6a5 to
9993fc3
Compare
9993fc3 to
70c2335
Compare
70c2335 to
e1b952a
Compare
e1b952a to
46c8e59
Compare
…ntroller into Au3Player Move isPlayAllowed, isPlaying/isPaused/isStopped, totalPlayTime, and loop-region handling (toggle, set-to-selection, set-region-in-out, selection-follows-loop) out of PlaybackController and into Au3Player, the only IPlayer implementation. PlaybackController keeps implementing IPlaybackController but forwards to the player in place; consumers and behaviour are unchanged. Also regroups the remaining pass-through methods by topic (status, loop region, transport) for readability. No behaviour change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ntroller Now that PlaybackController only forwarded IPlaybackController to the player, delete the interface and the forwarding layer and point every consumer at the player via IPlayback::player(). PlaybackController is left as the thin action listener it now is, no longer module-exported. No behaviour change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…anges during playback Switching the audio host, playback/recording device, or recording-channel count while a stream was open used to hit an assert or leave the engine busy. The player now brackets each change with withStreamRestart(): stop, apply the change, and resume from the same position if the user was actively playing. Rescanning devices and recording-channel-count changes are routed through the same mechanism, so they behave like any other device change. With this in place, drop the `enabled: !isPlaying` guards on the host/device/recording-channel/sample-rate/buffer controls in Preferences, and route their changes through the player too. Adds a device-change orchestration/teardown test suite for Au3AudioDevicesProvider (new au3audio test target + audio engine mock). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…yer into a Transport class Move the higher-level playback/pause/stop/seek/device-change orchestration that used to live in Au3Player into a new Transport class, sitting between PlaybackController and the player. This re-opens a seam for mocking the player, so the former PlaybackController unit tests are reinstated as TransportTests, driving Transport through a player mock.
A host/device/channel change or rescan unconditionally stopped input monitoring to perform the low-level switch, but nothing started it back up: the user silently lost input metering for good. Capture whether monitoring was on beforehand (recording the owning project before the stop resets it) and resume it once the switch is done, in IAudioEngine/Au3AudioEngine and the device provider, with a regression test.
Add regression coverage for three PR audacity#11245 QA checklist behaviors that were implemented but untested: resuming at the interrupted position, a later Stop still returning to the original seek anchor rather than the resume position, and Play after a paused device change resuming from the paused position.
Rename playbackcontroller.h/cpp to transportactionscontroller.h/cpp and the class itself to match what it now is: the UI action listener that forwards to Transport, not a playback implementation. Includes follow-up clean-up in the renamed file.
…state across a device change Round out device-change handling with the position/selection edge cases: - setInputChannels() skips the stream teardown when the channel count is unchanged. - withStreamRestart() stops the capture stream via the record machinery (record()->stop()) during a device action; Au3Player::stop() early-returns while recording, so the previous unconditional player()->stop() was a no-op and left the capture stream open, hitting the exact AudioIOBase::HandleDeviceChange() assert this branch fixes. - Reinstate the selection end on resume: player()->seek() collapses the player's region as a side effect, so the pre-device-change region bounds are captured and reapplied on resume instead of overrunning to the end of the project. - A fresh region change (not just an explicit seek) now clears any pending paused-resume position, so a selection made after a device-change-while- paused isn't discarded in favour of the stale position. - Resume at the interrupted position by handing it straight to player()->play() as the stream start position, instead of seeking and rewriting play-region/session state: no seek, no play-region write, a bounded selection keeps its own end, an active loop resumes inside its bounds and wraps as usual, and a later stop still returns to the seek anchor. - Loop-playback resume is covered end-to-end: IPlayer::play() takes an optional start position, threaded down to au3's AudioIOStartStreamOptions::pStartTime, so switching devices mid-loop resumes at the interrupted position instead of the loop start. - m_pausedResumePos is reset on stop, and parameter naming in TransportActionsController / AudioSetupContextMenuModel is made consistent.
46c8e59 to
0d40ce9
Compare
Original PR: #11245 Resolves: #11098 Resolves: #9443 Resolves: #11102 - [x] I signed [CLA](https://www.audacityteam.org/cla/) - [x] The title of the pull request describes an issue it addresses - [x] If changes are extensive, then there is a sequence of easily reviewable commits - [x] Each commit's message describes its purpose and effects - [x] There are no behavior changes unnecessary for the stated purpose of the PR Recommended: - [ ] Each commit compiles and runs on my machine without known undesirable changes of behavior QA: - [ ] Testflow test cases have been run
Resolves: #11098 #9443
Some operations cannot technically be done with running IO streams: changing audio host or device, number of input channels, buffer size, etc.
A simple solution is to grey all these out. User-friendlier is to implement a workaround whereby, upon such action, the streams are automatically stopped and, if appropriate, resumed afterwards.
This requires more transport-level logic, and, unfortunately, some refactoring. Existing alike logic lives in
PlaybackController, which was initially probably intended to be just an "action controller" (likeProjectActionsController) and now mixes up both. Rather than making it even worse, this PR intends to clean that up first: extract this logic in a new injectable,ITransport.After the refactoring commits, this PR implements the above-mentioned automations.
Leftovers
Remaining things to clean up:
IAudioEngineinterface still has references to legacyAudacityProjectclassRecommended:
QA
Setup: Use a machine with ≥2 playback devices and ≥2 recording devices (or ≥2 audio hosts/APIs) so you can switch between them.
Don't enable looping: there is currently a bug when enabled (ticket exists) that hides this PR's fixes
Test primarily on Windows + WASAPI (the config reported in #11098)
The device-related actions are
Other audio-related settings such as buffer length, default sample rate, etc., don't need an interrupt - they'll be taken into account on the next playback. (Those precise actions weren't discussed with @teetow, but I guess their impact may be too small to be worth the implementation effort, albeit low.)