Skip to content

Commit

Permalink
Fix musescore#22382 Part 1: Add a shortcut to toggle hear when playin…
Browse files Browse the repository at this point in the history
…g editing
  • Loading branch information
pacebes committed Nov 27, 2024
1 parent eef395b commit ae2de3d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void NoteInputPreferencesModel::setPlayNotesWhenEditing(bool value)

playbackConfiguration()->setPlayNotesWhenEditing(value);
emit playNotesWhenEditingChanged(value);
playbackController()->toggleHearPlaybackWhenEditing();
}

void NoteInputPreferencesModel::setNotePlayDurationMilliseconds(int duration)
Expand Down
2 changes: 2 additions & 0 deletions src/appshell/view/preferences/noteinputpreferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +58,7 @@ class NoteInputPreferencesModel : public QObject, public muse::Injectable
muse::Inject<notation::INotationConfiguration> notationConfiguration = { this };
muse::Inject<playback::IPlaybackConfiguration> playbackConfiguration = { this };
muse::Inject<mu::engraving::IEngravingConfiguration> engravingConfiguration = { this };
muse::Inject<mu::playback::IPlaybackController> playbackController = { };

public:
explicit NoteInputPreferencesModel(QObject* parent = nullptr);
Expand Down
49 changes: 15 additions & 34 deletions src/notation/internal/notationuiactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 16 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 @@ -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];
Expand Down Expand Up @@ -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);
}
5 changes: 5 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 Expand Up @@ -241,6 +244,8 @@ class PlaybackController : public IPlaybackController, public muse::actions::Act
DrumsetLoader m_drumsetLoader;

bool m_measureInputLag = false;

bool m_hearPlaybackWhenEditing;
};
}

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/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

0 comments on commit ae2de3d

Please sign in to comment.