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 80d0d9f
Show file tree
Hide file tree
Showing 10 changed files with 64 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(this, [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
3 changes: 3 additions & 0 deletions src/playback/internal/playbackconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PlaybackConfiguration : public IPlaybackConfiguration, public muse::async:
public:
void init();

muse::async::Notification playNotesWhenEditingChanged() const override;
bool playNotesWhenEditing() const override;
void setPlayNotesWhenEditing(bool value) override;

Expand Down Expand Up @@ -92,6 +93,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);
}
2 changes: 2 additions & 0 deletions src/playback/internal/playbackcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class PlaybackController : public IPlaybackController, public muse::actions::Act
void setIsExportingAudio(bool exporting) override;

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

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

Expand Down Expand Up @@ -166,6 +167,7 @@ class PlaybackController : public IPlaybackController, public muse::actions::Act
void setMidiUseWrittenPitch(bool useWrittenPitch);
void toggleCountIn();
void toggleLoopPlayback();
void toggleHearPlaybackWhenEditing();

void openPlaybackSetupDialog();

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

0 comments on commit 80d0d9f

Please sign in to comment.