From ae2de3d28c06be22dabd38601ca727a7b77e878f Mon Sep 17 00:00:00 2001 From: Pedro Acebes Date: Thu, 28 Nov 2024 00:50:18 +0100 Subject: [PATCH] Fix #22382 Part 1: Add a shortcut to toggle hear when playing editing --- .../preferences/noteinputpreferencesmodel.cpp | 1 + .../preferences/noteinputpreferencesmodel.h | 2 + src/notation/internal/notationuiactions.cpp | 49 ++++++------------- src/playback/internal/playbackcontroller.cpp | 17 ++++++- src/playback/internal/playbackcontroller.h | 5 ++ src/playback/internal/playbackuiactions.cpp | 17 +++++++ src/playback/internal/playbackuiactions.h | 2 + src/playback/iplaybackcontroller.h | 2 + .../tests/mocks/playbackcontrollermock.h | 2 + src/playback/view/playbacktoolbarmodel.cpp | 8 +++ 10 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/appshell/view/preferences/noteinputpreferencesmodel.cpp b/src/appshell/view/preferences/noteinputpreferencesmodel.cpp index 3637bb07d9936..3f18d03386b2c 100644 --- a/src/appshell/view/preferences/noteinputpreferencesmodel.cpp +++ b/src/appshell/view/preferences/noteinputpreferencesmodel.cpp @@ -124,6 +124,7 @@ void NoteInputPreferencesModel::setPlayNotesWhenEditing(bool value) playbackConfiguration()->setPlayNotesWhenEditing(value); emit playNotesWhenEditingChanged(value); + playbackController()->toggleHearPlaybackWhenEditing(); } void NoteInputPreferencesModel::setNotePlayDurationMilliseconds(int duration) diff --git a/src/appshell/view/preferences/noteinputpreferencesmodel.h b/src/appshell/view/preferences/noteinputpreferencesmodel.h index 78c77ea6da1ee..56120816e07a4 100644 --- a/src/appshell/view/preferences/noteinputpreferencesmodel.h +++ b/src/appshell/view/preferences/noteinputpreferencesmodel.h @@ -29,6 +29,7 @@ #include "shortcuts/ishortcutsconfiguration.h" #include "notation/inotationconfiguration.h" #include "playback/iplaybackconfiguration.h" +#include "playback/iplaybackcontroller.h" namespace mu::appshell { class NoteInputPreferencesModel : public QObject, public muse::Injectable @@ -57,6 +58,7 @@ class NoteInputPreferencesModel : public QObject, public muse::Injectable muse::Inject notationConfiguration = { this }; muse::Inject playbackConfiguration = { this }; muse::Inject engravingConfiguration = { this }; + muse::Inject playbackController = { }; public: explicit NoteInputPreferencesModel(QObject* parent = nullptr); diff --git a/src/notation/internal/notationuiactions.cpp b/src/notation/internal/notationuiactions.cpp index 083c97e70d587..57928fbccb879 100644 --- a/src/notation/internal/notationuiactions.cpp +++ b/src/notation/internal/notationuiactions.cpp @@ -133,13 +133,13 @@ const UiActionList NotationUiActions::m_actions = { ), UiAction("up-chord", mu::context::UiCtxProjectOpened, - mu::context::CTX_NOTATION_LIST_SELECTION, + mu::context::CTX_NOTATION_FOCUSED, TranslatableString("action", "Up note in chord"), TranslatableString("action", "Select note/rest above") ), UiAction("down-chord", mu::context::UiCtxProjectOpened, - mu::context::CTX_NOTATION_LIST_SELECTION, + mu::context::CTX_NOTATION_FOCUSED, TranslatableString("action", "Down note in chord"), TranslatableString("action", "Select note/rest below") ), @@ -563,11 +563,11 @@ const UiActionList NotationUiActions::m_actions = { TranslatableString("action", "Measure properties…"), TranslatableString("action", "Measure properties…") ), - UiAction("measures-per-system", + UiAction("add-remove-breaks", mu::context::UiCtxProjectOpened, mu::context::CTX_NOTATION_OPENED, - TranslatableString("action", "Measures per s&ystem…"), - TranslatableString("action", "Measures per system…") + TranslatableString("action", "Add/remove s&ystem breaks…"), + TranslatableString("action", "Add/remove system breaks…") ), UiAction("undo", mu::context::UiCtxProjectOpened, @@ -631,26 +631,6 @@ const UiActionList NotationUiActions::m_actions = { TranslatableString("action", "Add/remove page break"), TranslatableString("action", "Add/remove page break") ), - UiAction("move-measure-to-prev-system", - mu::context::UiCtxProjectOpened, - mu::context::CTX_NOTATION_FOCUSED, - TranslatableString("action", "Move measure to previous system"), - TranslatableString("action", "Move measure to previous system"), - IconCode::Code::ARROW_UP - ), - UiAction("move-measure-to-next-system", - mu::context::UiCtxProjectOpened, - mu::context::CTX_NOTATION_FOCUSED, - TranslatableString("action", "Move measure to next system"), - TranslatableString("action", "Move measure to next system"), - IconCode::Code::ARROW_DOWN - ), - UiAction("make-into-system", - mu::context::UiCtxProjectOpened, - mu::context::CTX_NOTATION_FOCUSED, - TranslatableString("action", "Make measure(s) into one system"), - TranslatableString("action", "Make measure(s) into one system") - ), UiAction("section-break", mu::context::UiCtxProjectOpened, mu::context::CTX_NOTATION_OPENED, @@ -862,7 +842,7 @@ const UiActionList NotationUiActions::m_actions = { mu::context::CTX_NOTATION_OPENED, TranslatableString("action", "Add brackets to accidental"), TranslatableString("action", "Add brackets to accidental"), - IconCode::Code::BRACKET_PARENTHESES_SQUARE + IconCode::Code::BRACKET ), UiAction("add-braces", mu::context::UiCtxProjectOpened, @@ -1602,19 +1582,12 @@ const UiActionList NotationUiActions::m_actions = { TranslatableString("action", "Repeat selection"), TranslatableString("action", "Repeat selection") ), - UiAction("toggle-score-lock", + UiAction("lock", mu::context::UiCtxProjectOpened, mu::context::CTX_ANY, TranslatableString("action", "Toggle score lock"), TranslatableString("action", "Toggle score lock") ), - UiAction("toggle-system-lock", - mu::context::UiCtxProjectOpened, - mu::context::CTX_ANY, - TranslatableString("action", "Toggle system lock"), - TranslatableString("action", "Toggle system lock"), - IconCode::Code::SYSTEM_LOCK - ), UiAction("enh-both", mu::context::UiCtxProjectOpened, mu::context::CTX_ANY, @@ -2042,6 +2015,14 @@ const UiActionList NotationUiActions::m_actions = { IconCode::Code::EDIT, Checkable::Yes ), + 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 + ), UiAction("toggle-insert-mode", mu::context::UiCtxProjectOpened, mu::context::CTX_ANY, diff --git a/src/playback/internal/playbackcontroller.cpp b/src/playback/internal/playbackcontroller.cpp index daa99f461276c..a76fc2238b689 100644 --- a/src/playback/internal/playbackcontroller.cpp +++ b/src/playback/internal/playbackcontroller.cpp @@ -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() { @@ -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(); @@ -1436,7 +1438,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]; @@ -1631,3 +1634,15 @@ muse::audio::secs_t PlaybackController::playedTickToSecs(int tick) const { return secs_t(notationPlayback()->playedTickToSec(tick)); } + +void PlaybackController::toggleHearPlaybackWhenEditing() +{ + // Just to check if the function has been called from noteinputpreferencesmodel or from playbackcontroller + // If the configuration() stored value is the same as the local value we have been called from playbackcontroller to change the value + if (m_hearPlaybackWhenEditing == configuration()->playNotesWhenEditing()) { + configuration()->setPlayNotesWhenEditing(!m_hearPlaybackWhenEditing); + } + m_hearPlaybackWhenEditing = !m_hearPlaybackWhenEditing; + + notifyActionCheckedChanged(TOGGLE_HEAR_PLAYBACK_WHEN_EDITING); +} diff --git a/src/playback/internal/playbackcontroller.h b/src/playback/internal/playbackcontroller.h index 78262d878dfbe..4fce01b701869 100644 --- a/src/playback/internal/playbackcontroller.h +++ b/src/playback/internal/playbackcontroller.h @@ -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; @@ -241,6 +244,8 @@ class PlaybackController : public IPlaybackController, public muse::actions::Act DrumsetLoader m_drumsetLoader; bool m_measureInputLag = false; + + bool m_hearPlaybackWhenEditing; }; } diff --git a/src/playback/internal/playbackuiactions.cpp b/src/playback/internal/playbackuiactions.cpp index 050f01372ecfc..d7b259c5b67be 100644 --- a/src/playback/internal/playbackuiactions.cpp +++ b/src/playback/internal/playbackuiactions.cpp @@ -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, @@ -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; @@ -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; diff --git a/src/playback/internal/playbackuiactions.h b/src/playback/internal/playbackuiactions.h index f3ab0f98b63cb..4a187bb468c1d 100644 --- a/src/playback/internal/playbackuiactions.h +++ b/src/playback/internal/playbackuiactions.h @@ -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(); @@ -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 m_controller; muse::async::Channel m_actionEnabledChanged; diff --git a/src/playback/iplaybackcontroller.h b/src/playback/iplaybackcontroller.h index c1d277ab26bbb..b5e99eaaf2d42 100644 --- a/src/playback/iplaybackcontroller.h +++ b/src/playback/iplaybackcontroller.h @@ -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; }; } diff --git a/src/playback/tests/mocks/playbackcontrollermock.h b/src/playback/tests/mocks/playbackcontrollermock.h index 716724e53c392..ed423474e88dc 100644 --- a/src/playback/tests/mocks/playbackcontrollermock.h +++ b/src/playback/tests/mocks/playbackcontrollermock.h @@ -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)); }; } diff --git a/src/playback/view/playbacktoolbarmodel.cpp b/src/playback/view/playbacktoolbarmodel.cpp index f23477da80018..ac52d827f3cf0 100644 --- a/src/playback/view/playbacktoolbarmodel.cpp +++ b/src/playback/view/playbacktoolbarmodel.cpp @@ -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(); }