Repository navigation
[Playback] Cache Player instance within Playback #397
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,8 +48,12 @@ void Player::init() | |
| }); | ||
|
|
||
| Msg msg = rpc::make_request(ctxId(), MsgCode::GetPlaybackStatus); | ||
| channel()->send(msg, [this](const Msg& res) { | ||
| channel()->send(msg, [this, alive = std::weak_ptr<bool>(m_alive)](const Msg& res) { | ||
| ONLY_AUDIO_MAIN_THREAD; | ||
| if (alive.expired()) { | ||
| return; | ||
| } | ||
|
|
||
| Ret ret; | ||
| PlaybackStatus status = PlaybackStatus::Stopped; | ||
| StreamId streamId = 0; | ||
|
|
@@ -58,6 +62,7 @@ void Player::init() | |
| } | ||
|
|
||
| if (ret) { | ||
| m_playbackStatusStreamId = streamId; | ||
| channel()->addReceiveStream(StreamName::PlaybackStatusStream, streamId, m_playbackStatusChanged); | ||
| //! NOTE Send initial state | ||
| m_playbackStatusChanged.send(status); | ||
|
|
@@ -73,8 +78,12 @@ void Player::init() | |
| }); | ||
|
|
||
| Msg msg = rpc::make_request(ctxId(), MsgCode::GetPlaybackPosition); | ||
| channel()->send(msg, [this](const Msg& res) { | ||
| channel()->send(msg, [this, alive = std::weak_ptr<bool>(m_alive)](const Msg& res) { | ||
| ONLY_AUDIO_MAIN_THREAD; | ||
| if (alive.expired()) { | ||
| return; | ||
| } | ||
|
|
||
| Ret ret; | ||
| secs_t pos = 0.0; | ||
| StreamId streamId = 0; | ||
|
|
@@ -83,6 +92,7 @@ void Player::init() | |
| } | ||
|
|
||
| if (ret) { | ||
| m_playbackPositionStreamId = streamId; | ||
| channel()->addReceiveStream(StreamName::PlaybackPositionStream, streamId, m_playbackPositionChanged); | ||
| //! NOTE Send initial state | ||
| m_playbackPositionChanged.send(pos); | ||
|
|
@@ -93,6 +103,26 @@ void Player::init() | |
| } | ||
| } | ||
|
|
||
| void Player::deinit() | ||
| { | ||
| ONLY_AUDIO_MAIN_THREAD; | ||
|
|
||
| m_alive.reset(); | ||
|
|
||
| if (m_playbackStatusStreamId != 0) { | ||
| channel()->removeStream(m_playbackStatusStreamId); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| m_playbackStatusStreamId = 0; | ||
| } | ||
|
|
||
| if (m_playbackPositionStreamId != 0) { | ||
| channel()->removeStream(m_playbackPositionStreamId); | ||
| m_playbackPositionStreamId = 0; | ||
| } | ||
|
|
||
| m_playbackStatusChanged.disconnect(this); | ||
| m_playbackPositionChanged.disconnect(this); | ||
| } | ||
|
|
||
| async::Promise<Ret> Player::prepareToPlay() | ||
| { | ||
| ONLY_AUDIO_MAIN_THREAD; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-3.0-only | ||
| * MuseScore-CLA-applies | ||
| * | ||
| * MuseScore | ||
| * Music Composition & Notation | ||
| * | ||
| * Copyright (C) 2026 MuseScore Limited and others | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 3 as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <gmock/gmock.h> | ||
|
|
||
| #include "audio/main/istartaudiocontroller.h" | ||
|
|
||
| namespace muse::audio { | ||
| class StartAudioControllerMock : public IStartAudioController | ||
| { | ||
| public: | ||
| MOCK_METHOD(void, startAudioProcessing, (const IApplication::RunMode&), (override)); | ||
| MOCK_METHOD(void, stopAudioProcessing, (), (override)); | ||
|
|
||
| MOCK_METHOD(bool, isAudioStarted, (), (const, override)); | ||
| MOCK_METHOD(async::Channel<bool>, isAudioStartedChanged, (), (const, override)); | ||
| }; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.