Skip to content

Commit

Permalink
fixed musescore#13698: Disconnect all channels from playback
Browse files Browse the repository at this point in the history
  • Loading branch information
Eism committed Oct 15, 2022
1 parent 644cc12 commit 347b275
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/playback/internal/playbackcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ static const ActionCode PLAYBACK_SETUP("playback-setup");

void PlaybackController::init()
{
m_playbackNotifyReceiver = std::make_shared<async::Asyncable>();

dispatcher()->reg(this, PLAY_CODE, this, &PlaybackController::togglePlay);
dispatcher()->reg(this, STOP_CODE, this, &PlaybackController::pause);
dispatcher()->reg(this, REWIND_CODE, this, &PlaybackController::rewind);
Expand All @@ -77,7 +79,7 @@ void PlaybackController::init()

m_loadingProgress.started.notify();

playback()->addSequence().onResolve(this, [this](const TrackSequenceId& sequenceId) {
playback()->addSequence().onResolve(m_playbackNotifyReceiver.get(), [this](const TrackSequenceId& sequenceId) {
setupNewCurrentSequence(sequenceId);
});
});
Expand Down Expand Up @@ -682,12 +684,7 @@ mu::project::IProjectAudioSettingsPtr PlaybackController::audioSettings() const

void PlaybackController::resetCurrentSequence()
{
playback()->player()->playbackPositionMsecs().resetOnReceive(this);
playback()->player()->playbackStatusChanged().resetOnReceive(this);

playback()->tracks()->inputParamsChanged().resetOnReceive(this);
playback()->audioOutput()->outputParamsChanged().resetOnReceive(this);
playback()->audioOutput()->masterOutputParamsChanged().resetOnReceive(this);
m_playbackNotifyReceiver->disconnectAll();

setCurrentTick(0);
setCurrentPlaybackStatus(PlaybackStatus::Stopped);
Expand Down Expand Up @@ -901,11 +898,12 @@ void PlaybackController::setupNewCurrentSequence(const TrackSequenceId sequenceI

void PlaybackController::subscribeOnAudioParamsChanges()
{
playback()->audioOutput()->masterOutputParamsChanged().onReceive(this, [this](const audio::AudioOutputParams& params) {
playback()->audioOutput()->masterOutputParamsChanged().onReceive(m_playbackNotifyReceiver.get(),
[this](const audio::AudioOutputParams& params) {
audioSettings()->setMasterAudioOutputParams(params);
});

playback()->tracks()->inputParamsChanged().onReceive(this,
playback()->tracks()->inputParamsChanged().onReceive(m_playbackNotifyReceiver.get(),
[this](const TrackSequenceId sequenceId,
const TrackId trackId,
const AudioInputParams& params) {
Expand All @@ -922,7 +920,7 @@ void PlaybackController::subscribeOnAudioParamsChanges()
}
});

playback()->audioOutput()->outputParamsChanged().onReceive(this,
playback()->audioOutput()->outputParamsChanged().onReceive(m_playbackNotifyReceiver.get(),
[this](const TrackSequenceId sequenceId,
const TrackId trackId,
const AudioOutputParams& params) {
Expand Down Expand Up @@ -1005,7 +1003,7 @@ void PlaybackController::setupSequencePlayer()
{
PlaybackCursorType cursorType = configuration()->cursorType();

playback()->player()->playbackPositionMsecs().onReceive(this, [this, cursor = std::move(cursorType)]
playback()->player()->playbackPositionMsecs().onReceive(m_playbackNotifyReceiver.get(), [this, cursor = std::move(cursorType)]
(const TrackSequenceId id, const audio::msecs_t& msecs) {
if (m_currentSequenceId != id) {
return;
Expand All @@ -1022,12 +1020,13 @@ void PlaybackController::setupSequencePlayer()

playback()->player()->setDuration(m_currentSequenceId, notationPlayback()->totalPlayTime());

notationPlayback()->totalPlayTimeChanged().onReceive(this, [this](const audio::msecs_t totalPlaybackTime) {
notationPlayback()->totalPlayTimeChanged().onReceive(m_playbackNotifyReceiver.get(), [this](const audio::msecs_t totalPlaybackTime) {
playback()->player()->setDuration(m_currentSequenceId, totalPlaybackTime);
m_totalPlayTimeChanged.notify();
});

playback()->player()->playbackStatusChanged().onReceive(this, [this](const TrackSequenceId id, const PlaybackStatus status) {
playback()->player()->playbackStatusChanged().onReceive(m_playbackNotifyReceiver.get(),
[this](const TrackSequenceId id, const PlaybackStatus status) {
if (m_currentSequenceId == id) {
setCurrentPlaybackStatus(status);
}
Expand Down
1 change: 1 addition & 0 deletions src/playback/internal/playbackcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class PlaybackController : public IPlaybackController, public actions::Actionabl

async::Channel<audio::TrackId, engraving::InstrumentTrackId> m_trackAdded;
async::Channel<audio::TrackId, engraving::InstrumentTrackId> m_trackRemoved;
std::shared_ptr<async::Asyncable> m_playbackNotifyReceiver = nullptr;

InstrumentTrackIdMap m_trackIdMap;

Expand Down

0 comments on commit 347b275

Please sign in to comment.