Skip to content

Commit

Permalink
Fix #22382 Part 1: Add a shortcut to toggle hear when playing editing
Browse files Browse the repository at this point in the history
  • Loading branch information
pacebes committed Nov 30, 2024
1 parent eef395b commit 63ba71d
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/playback/internal/playbackconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ void PlaybackConfiguration::init()
m_isAuxChannelVisibleChanged.send(idx, val.toBool());
});
}

settings()->valueChanged(PLAY_NOTES_WHEN_EDITING).onReceive(nullptr, [this](const Val&) {
m_isPlayNotesWhenEditingChanged.notify();
});
}

bool PlaybackConfiguration::playNotesWhenEditing() const
Expand Down Expand Up @@ -161,6 +165,11 @@ void PlaybackConfiguration::setPlayHarmonyWhenEditing(bool value)
settings()->setSharedValue(PLAY_HARMONY_WHEN_EDITING, Val(value));
}

muse::async::Notification PlaybackConfiguration::playNotesWhenEditingChanged() const
{
return m_isPlayNotesWhenEditingChanged;
}

PlaybackCursorType PlaybackConfiguration::cursorType() const
{
return settings()->value(PLAYBACK_CURSOR_TYPE_KEY).toEnum<PlaybackCursorType>();
Expand Down
4 changes: 4 additions & 0 deletions src/playback/internal/playbackconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class PlaybackConfiguration : public IPlaybackConfiguration, public muse::async:
bool playHarmonyWhenEditing() const override;
void setPlayHarmonyWhenEditing(bool value) override;

muse::async::Notification playNotesWhenEditingChanged() const override;

PlaybackCursorType cursorType() const override;

bool isMixerSectionVisible(MixerSectionType sectionType) const override;
Expand Down Expand Up @@ -92,6 +94,8 @@ class PlaybackConfiguration : public IPlaybackConfiguration, public muse::async:
muse::async::Channel<MixerSectionType, bool> m_isMixerSectionVisibleChanged;

muse::async::Channel<bool> m_muteHiddenInstrumentsChanged;

muse::async::Notification m_isPlayNotesWhenEditingChanged;
};
}

Expand Down
15 changes: 14 additions & 1 deletion src/playback/internal/playbackcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static const ActionCode PAN_CODE("pan");
static const ActionCode REPEAT_CODE("repeat");
static const ActionCode PLAY_CHORD_SYMBOLS_CODE("play-chord-symbols");
static const ActionCode PLAYBACK_SETUP("playback-setup");
static const ActionCode TOGGLE_HEAR_PLAYBACK_WHEN_EDITING("toggle-hear-playback-when-editing");

static AudioOutputParams makeReverbOutputParams()
{
Expand Down Expand Up @@ -113,6 +114,7 @@ void PlaybackController::init()
dispatcher()->reg(this, INPUT_SOUNDING_PITCH, [this]() { PlaybackController::setMidiUseWrittenPitch(false); });
dispatcher()->reg(this, COUNT_IN_CODE, this, &PlaybackController::toggleCountIn);
dispatcher()->reg(this, PLAYBACK_SETUP, this, &PlaybackController::openPlaybackSetupDialog);
dispatcher()->reg(this, TOGGLE_HEAR_PLAYBACK_WHEN_EDITING, this, &PlaybackController::toggleHearPlaybackWhenEditing);

globalContext()->currentNotationChanged().onNotify(this, [this]() {
onNotationChanged();
Expand Down Expand Up @@ -140,6 +142,10 @@ void PlaybackController::init()
updateLoop();
});

configuration()->playNotesWhenEditingChanged().onNotify(this, [this]() {
notifyActionCheckedChanged(TOGGLE_HEAR_PLAYBACK_WHEN_EDITING);
});

m_measureInputLag = configuration()->shouldMeasureInputLag();
}

Expand Down Expand Up @@ -1436,7 +1442,8 @@ bool PlaybackController::actionChecked(const ActionCode& actionCode) const
{ PLAY_CHORD_SYMBOLS_CODE, notationConfiguration()->isPlayChordSymbolsEnabled() },
{ PAN_CODE, notationConfiguration()->isAutomaticallyPanEnabled() },
{ METRONOME_CODE, notationConfiguration()->isMetronomeEnabled() },
{ COUNT_IN_CODE, notationConfiguration()->isCountInEnabled() }
{ COUNT_IN_CODE, notationConfiguration()->isCountInEnabled() },
{ TOGGLE_HEAR_PLAYBACK_WHEN_EDITING, configuration()->playNotesWhenEditing() }
};

return isChecked[actionCode];
Expand Down Expand Up @@ -1631,3 +1638,9 @@ muse::audio::secs_t PlaybackController::playedTickToSecs(int tick) const
{
return secs_t(notationPlayback()->playedTickToSec(tick));
}

void PlaybackController::toggleHearPlaybackWhenEditing()
{
bool wasPlayNotesWhenEditing = configuration()->playNotesWhenEditing();
configuration()->setPlayNotesWhenEditing(!wasPlayNotesWhenEditing);
}
3 changes: 3 additions & 0 deletions src/playback/internal/playbackcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class PlaybackController : public IPlaybackController, public muse::actions::Act
void setIsExportingAudio(bool exporting) override;

bool canReceiveAction(const muse::actions::ActionCode& code) const override;

void toggleHearPlaybackWhenEditing() override;

private:
muse::audio::IPlayerPtr currentPlayer() const;

Expand Down
17 changes: 17 additions & 0 deletions src/playback/internal/playbackuiactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ const UiActionList PlaybackUiActions::m_settingsActions = {
// ),
};

const UiActionList PlaybackUiActions::m_hearPlaybackWhenEditingActions = {
UiAction("toggle-hear-playback-when-editing",
mu::context::UiCtxAny,
mu::context::CTX_ANY,
TranslatableString("action", "Toggle hear playback when editing"),
TranslatableString("action", "Toggle hear playback when editing"),
IconCode::Code::EDIT,
Checkable::Yes
),
};

const UiActionList PlaybackUiActions::m_loopBoundaryActions = {
UiAction("loop-in",
mu::context::UiCtxAny,
Expand Down Expand Up @@ -190,6 +201,7 @@ const UiActionList& PlaybackUiActions::actionsList() const
alist.insert(alist.end(), m_midiInputActions.cbegin(), m_midiInputActions.cend());
alist.insert(alist.end(), m_midiInputPitchActions.cbegin(), m_midiInputPitchActions.cend());
alist.insert(alist.end(), m_settingsActions.cbegin(), m_settingsActions.cend());
alist.insert(alist.end(), m_hearPlaybackWhenEditingActions.cbegin(), m_hearPlaybackWhenEditingActions.cend());
alist.insert(alist.end(), m_loopBoundaryActions.cbegin(), m_loopBoundaryActions.cend());
}
return alist;
Expand Down Expand Up @@ -243,6 +255,11 @@ const UiActionList& PlaybackUiActions::loopBoundaryActions()
return m_loopBoundaryActions;
}

const UiActionList& PlaybackUiActions::hearPlaybackWhenEditingActions()
{
return m_hearPlaybackWhenEditingActions;
}

const muse::ui::ToolConfig& PlaybackUiActions::defaultPlaybackToolConfig()
{
static ToolConfig config;
Expand Down
2 changes: 2 additions & 0 deletions src/playback/internal/playbackuiactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PlaybackUiActions : public muse::ui::IUiActionsModule, public muse::async:
static const muse::ui::UiActionList& midiInputActions();
static const muse::ui::UiActionList& midiInputPitchActions();
static const muse::ui::UiActionList& settingsActions();
static const muse::ui::UiActionList& hearPlaybackWhenEditingActions();
static const muse::ui::UiActionList& loopBoundaryActions();

static const muse::ui::ToolConfig& defaultPlaybackToolConfig();
Expand All @@ -60,6 +61,7 @@ class PlaybackUiActions : public muse::ui::IUiActionsModule, public muse::async:
static const muse::ui::UiActionList m_midiInputPitchActions;
static const muse::ui::UiActionList m_settingsActions;
static const muse::ui::UiActionList m_loopBoundaryActions;
static const muse::ui::UiActionList m_hearPlaybackWhenEditingActions;

std::shared_ptr<PlaybackController> m_controller;
muse::async::Channel<muse::actions::ActionCodeList> m_actionEnabledChanged;
Expand Down
2 changes: 2 additions & 0 deletions src/playback/iplaybackconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class IPlaybackConfiguration : MODULE_EXPORT_INTERFACE
virtual bool playHarmonyWhenEditing() const = 0;
virtual void setPlayHarmonyWhenEditing(bool value) = 0;

virtual muse::async::Notification playNotesWhenEditingChanged() const = 0;

virtual PlaybackCursorType cursorType() const = 0;

virtual bool isMixerSectionVisible(MixerSectionType sectionType) const = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/playback/iplaybackcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class IPlaybackController : MODULE_EXPORT_INTERFACE

virtual void setNotation(notation::INotationPtr notation) = 0;
virtual void setIsExportingAudio(bool exporting) = 0;

virtual void toggleHearPlaybackWhenEditing() = 0;
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/playback/tests/mocks/playbackcontrollermock.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class PlaybackControllerMock : public IPlaybackController

MOCK_METHOD(void, setNotation, (notation::INotationPtr), (override));
MOCK_METHOD(void, setIsExportingAudio, (bool), (override));

MOCK_METHOD(void, toggleHearPlaybackWhenEditing, (), (override));
};
}

Expand Down
8 changes: 8 additions & 0 deletions src/playback/view/playbacktoolbarmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ void PlaybackToolBarModel::updateActions()
settingsItems << makeMenuItem(action.code);
}

settingsItems << makeSeparator();

for (const UiAction& action : PlaybackUiActions::hearPlaybackWhenEditingActions()) {
settingsItems << makeMenuItem(action.code);
}

settingsItems << makeSeparator();

if (!m_isToolbarFloating) {
settingsItems << makeSeparator();
}
Expand Down
5 changes: 5 additions & 0 deletions src/stubs/playback/playbackconfigurationstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ void PlaybackConfigurationStub::setPlayHarmonyWhenEditing(bool)
{
}

muse::async::Notification PlaybackConfigurationStub::playNotesWhenEditingChanged() const
{
return muse::async::Notification();
}

PlaybackCursorType PlaybackConfigurationStub::cursorType() const
{
return PlaybackCursorType::SMOOTH;
Expand Down
2 changes: 2 additions & 0 deletions src/stubs/playback/playbackconfigurationstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class PlaybackConfigurationStub : public IPlaybackConfiguration
bool playHarmonyWhenEditing() const override;
void setPlayHarmonyWhenEditing(bool value) override;

muse::async::Notification playNotesWhenEditingChanged() const override;

PlaybackCursorType cursorType() const override;

bool isMixerSectionVisible(MixerSectionType sectionType) const override;
Expand Down
4 changes: 4 additions & 0 deletions src/stubs/playback/playbackcontrollerstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,7 @@ void PlaybackControllerStub::setNotation(notation::INotationPtr)
void PlaybackControllerStub::setIsExportingAudio(bool)
{
}

void PlaybackControllerStub::toggleHearPlaybackWhenEditing()
{
}
2 changes: 2 additions & 0 deletions src/stubs/playback/playbackcontrollerstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class PlaybackControllerStub : public IPlaybackController

void setNotation(notation::INotationPtr notation) override;
void setIsExportingAudio(bool exporting) override;

void toggleHearPlaybackWhenEditing() override;
};
}

Expand Down

0 comments on commit 63ba71d

Please sign in to comment.