Skip to content

Commit

Permalink
Changes to revive and complete PR musescore#22991.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatters1 committed Sep 17, 2024
1 parent eeda31d commit 02aac71
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <set>

#include "infrastructure/messagebox.h"
#include "notation/internal/notationconfiguration.h"

#include "accidental.h"
#include "articulation.h"
Expand Down Expand Up @@ -1587,7 +1588,7 @@ NoteVal Score::noteVal(int pitch) const

// if transposing, interpret MIDI pitch as representing desired written pitch
// set pitch based on corresponding sounding pitch
if (!style().styleB(Sid::concertPitch)) {
if (!style().styleB(Sid::concertPitch) && notationConfiguration()->pianoKeyboardUseNotatedPitch().val) {
nval.pitch += st->part()->instrument(inputState().tick())->transpose().chromatic;
}
// let addPitch calculate tpc values from pitch
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/dom/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ namespace mu::engraving::compat {
class WriteScoreHook;
}

namespace mu::notation {
class INotationConfiguration;
}

namespace mu::engraving {
class Articulation;
class Audio;
Expand Down Expand Up @@ -273,6 +277,7 @@ class Score : public EngravingObject, public muse::Injectable
muse::Inject<IEngravingFontsProvider> engravingFonts = { this };
muse::Inject<muse::IApplication> application = { this };
muse::Inject<IEngravingElementsProvider> elementsProvider = { this };
muse::Inject<mu::notation::INotationConfiguration> notationConfiguration = { this };

// internal
muse::Inject<rendering::IScoreRenderer> renderer = { this };
Expand Down
3 changes: 3 additions & 0 deletions src/notation/inotationconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class INotationConfiguration : MODULE_EXPORT_INTERFACE
virtual muse::ValCh<int> pianoKeyboardNumberOfKeys() const = 0;
virtual void setPianoKeyboardNumberOfKeys(int number) = 0;

virtual muse::ValCh<bool> pianoKeyboardUseNotatedPitch() const = 0;
virtual void setPianoKeyboardUseNotatedPitch(bool useNotatedPitch) = 0;

// TODO: Delete when the new percussion panel is finished
virtual bool useNewPercussionPanel() const = 0;
virtual void setUseNewPercussionPanel(bool use) = 0;
Expand Down
17 changes: 17 additions & 0 deletions src/notation/internal/notationconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static const Settings::Key NEED_TO_SHOW_ADD_FIGURED_BASS_ERROR_MESSAGE_KEY(modul
static const Settings::Key NEED_TO_SHOW_ADD_GUITAR_BEND_ERROR_MESSAGE_KEY(module_name, "ui/dialogs/needToShowAddGuitarBendErrorMessage");

static const Settings::Key PIANO_KEYBOARD_NUMBER_OF_KEYS(module_name, "pianoKeyboard/numberOfKeys");
static const Settings::Key PIANO_KEYBOARD_PITCH_STATE(module_name, "pianoKeyboard/useNotatedPitch");

static const Settings::Key USE_NEW_PERCUSSION_PANEL_KEY(module_name, "ui/useNewPercussionPanel");
static const Settings::Key AUTO_SHOW_PERCUSSION_PANEL_KEY(module_name, "ui/autoShowPercussionPanel");
Expand Down Expand Up @@ -220,6 +221,12 @@ void NotationConfiguration::init()
m_pianoKeyboardNumberOfKeys.set(val.toInt());
});

settings()->setDefaultValue(PIANO_KEYBOARD_PITCH_STATE, Val(true));
m_pianoKeyboardUseNotatedPitch.val = settings()->value(PIANO_KEYBOARD_PITCH_STATE).toBool();
settings()->valueChanged(PIANO_KEYBOARD_PITCH_STATE).onReceive(this, [this](const Val& val) {
m_pianoKeyboardUseNotatedPitch.set(val.toBool());
});

settings()->setDefaultValue(USE_NEW_PERCUSSION_PANEL_KEY, Val(false));
settings()->setDefaultValue(AUTO_SHOW_PERCUSSION_PANEL_KEY, Val(true));

Expand Down Expand Up @@ -919,6 +926,16 @@ void NotationConfiguration::setPianoKeyboardNumberOfKeys(int number)
settings()->setSharedValue(PIANO_KEYBOARD_NUMBER_OF_KEYS, Val(number));
}

ValCh<bool> NotationConfiguration::pianoKeyboardUseNotatedPitch() const
{
return m_pianoKeyboardUseNotatedPitch;
}

void NotationConfiguration::setPianoKeyboardUseNotatedPitch(bool useNotatedPitch)
{
settings()->setSharedValue(PIANO_KEYBOARD_PITCH_STATE, Val(useNotatedPitch));
}

muse::io::path_t NotationConfiguration::firstScoreOrderListPath() const
{
return settings()->value(FIRST_SCORE_ORDER_LIST_KEY).toString();
Expand Down
4 changes: 4 additions & 0 deletions src/notation/internal/notationconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class NotationConfiguration : public INotationConfiguration, public muse::async:
muse::ValCh<int> pianoKeyboardNumberOfKeys() const override;
void setPianoKeyboardNumberOfKeys(int number) override;

muse::ValCh<bool> pianoKeyboardUseNotatedPitch() const override;
void setPianoKeyboardUseNotatedPitch(bool useNotatedPitch) override;

bool useNewPercussionPanel() const override;
void setUseNewPercussionPanel(bool use) override;

Expand Down Expand Up @@ -231,6 +234,7 @@ class NotationConfiguration : public INotationConfiguration, public muse::async:
muse::async::Notification m_isPlayRepeatsChanged;
muse::async::Notification m_isPlayChordSymbolsChanged;
muse::ValCh<int> m_pianoKeyboardNumberOfKeys;
muse::ValCh<bool> m_pianoKeyboardUseNotatedPitch;
muse::async::Channel<QColor> m_anchorColorChanged;

int m_styleDialogLastPageIndex = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/notation/tests/mocks/notationconfigurationmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ class NotationConfigurationMock : public INotationConfiguration
MOCK_METHOD(muse::ValCh<int>, pianoKeyboardNumberOfKeys, (), (const, override));
MOCK_METHOD(void, setPianoKeyboardNumberOfKeys, (int), (override));

MOCK_METHOD(muse::ValCh<bool>, pianoKeyboardUseNotatedPitch, (), (const, override));
MOCK_METHOD(void, setPianoKeyboardUseNotatedPitch, (bool), (override));

MOCK_METHOD(bool, useNewPercussionPanel, (), (const, override));
MOCK_METHOD(void, setUseNewPercussionPanel, (bool), (override));

Expand Down
9 changes: 7 additions & 2 deletions src/notation/view/pianokeyboard/pianokeyboardcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ void PianoKeyboardController::updateNotesKeys(const std::vector<const Note*>& re
};

for (const mu::engraving::Note* note : receivedNotes) {
newKeys.insert(static_cast<piano_key_t>(note->epitch()));
newKeys.insert(static_cast<piano_key_t>(useNotatedPitch() ? note->epitch() : note->ppitch()));
for (const mu::engraving::Note* otherNote : note->chord()->notes()) {
newOtherNotesInChord.insert(static_cast<piano_key_t>(otherNote->epitch()));
newOtherNotesInChord.insert(static_cast<piano_key_t>(useNotatedPitch() ? otherNote->epitch() : otherNote->ppitch()));
}
}
}
Expand Down Expand Up @@ -175,3 +175,8 @@ INotationPtr PianoKeyboardController::currentNotation() const
{
return context()->currentNotation();
}

bool PianoKeyboardController::useNotatedPitch() const
{
return configuration()->pianoKeyboardUseNotatedPitch().val;
}
3 changes: 3 additions & 0 deletions src/notation/view/pianokeyboard/pianokeyboardcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace mu::notation {
class PianoKeyboardController : public muse::Injectable, public muse::async::Asyncable
{
muse::Inject<INotationConfiguration> configuration = { this };
muse::Inject<context::IGlobalContext> context = { this };

public:
Expand All @@ -45,6 +46,8 @@ class PianoKeyboardController : public muse::Injectable, public muse::async::Asy

bool isFromMidi() const;

bool useNotatedPitch() const;

private:
INotationPtr currentNotation() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using namespace muse::uicomponents;

static const ActionCode SET_KEY_WIDTH_SCALING_CODE("piano-keyboard-set-key-width-scaling");
static const ActionCode SET_NUMBER_OF_KEYS_CODE("piano-keyboard-set-number-of-keys");
static const ActionCode SET_NOTATED_PITCH_CODE("piano-keyboard-toggle-notated-pitch");

PianoKeyboardPanelContextMenuModel::PianoKeyboardPanelContextMenuModel(QObject* parent)
: AbstractMenuModel(parent)
Expand All @@ -44,7 +45,8 @@ PianoKeyboardPanelContextMenuModel::PianoKeyboardPanelContextMenuModel(QObject*
void PianoKeyboardPanelContextMenuModel::load()
{
MenuItemList items {
makeViewMenu()
makeViewMenu(),
makePitchMenu(),
};

setItems(items);
Expand All @@ -71,6 +73,35 @@ int PianoKeyboardPanelContextMenuModel::numberOfKeys() const
return configuration()->pianoKeyboardNumberOfKeys().val;
}

MenuItem* PianoKeyboardPanelContextMenuModel::makePitchMenu()
{
MenuItemList items;

std::vector<std::pair<muse::TranslatableString, bool> > possibleNotationStates {
{ muse::TranslatableString("notation", "Use notated pitch"), true },
{ muse::TranslatableString("notation", "Use playback pitch"), false },
};

for (auto [title, notationState] : possibleNotationStates) {
items << makeToggleNotatedPitchItem(title, notationState);
}

configuration()->pianoKeyboardUseNotatedPitch().ch.onReceive(this, [this](bool) {
emit pianoKeyboardUseNotatedPitchChanged();
});

dispatcher()->reg(this, SET_NOTATED_PITCH_CODE, [this](const ActionData& args) {
IF_ASSERT_FAILED(args.count() > 0) {
return;
}

configuration()->setPianoKeyboardUseNotatedPitch(args.arg<bool>(0));
emit pianoKeyboardUseNotatedPitchChanged();
});

return makeMenu(muse::TranslatableString("notation", "Pitch mode for transposing instruments"), items);
}

MenuItem* PianoKeyboardPanelContextMenuModel::makeViewMenu()
{
MenuItemList items;
Expand Down Expand Up @@ -167,6 +198,31 @@ MenuItem* PianoKeyboardPanelContextMenuModel::makeNumberOfKeysItem(const muse::T
return item;
}

MenuItem* PianoKeyboardPanelContextMenuModel::makeToggleNotatedPitchItem(const muse::TranslatableString& title, bool isNotatedPitch)
{
UiAction action;
action.title = title;
action.code = SET_NOTATED_PITCH_CODE;
action.checkable = Checkable::Yes;

MenuItem* item = new MenuItem(action, this);
item->setId(QString::fromStdString(SET_NOTATED_PITCH_CODE) + (isNotatedPitch ? "-notated" : "-playback"));

ValCh<bool> currentState = configuration()->pianoKeyboardUseNotatedPitch();

bool checked = !(isNotatedPitch ^ currentState.val);
item->setState(UiActionState::make_enabled(checked));

currentState.ch.onReceive(item, [item, isNotatedPitch](bool s) {
bool checked = !(isNotatedPitch ^ s);
item->setState(UiActionState::make_enabled(checked));
});

item->setArgs(ActionData::make_arg1<bool>(isNotatedPitch));

return item;
}

void PianoKeyboardPanelContextMenuModel::updateKeyWidthScalingItems()
{
qreal roundedCurrentScaling = NORMAL_KEY_WIDTH_SCALING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ class PianoKeyboardPanelContextMenuModel : public muse::uicomponents::AbstractMe
void keyWidthScalingChanged();
void setKeyWidthScalingRequested(qreal scaling);
void numberOfKeysChanged();
void pianoKeyboardUseNotatedPitchChanged();

private:
muse::uicomponents::MenuItem* makeViewMenu();
muse::uicomponents::MenuItem* makePitchMenu();

muse::uicomponents::MenuItem* makeKeyWidthScalingItem(const muse::TranslatableString& title, qreal scaling);
muse::uicomponents::MenuItem* makeNumberOfKeysItem(const muse::TranslatableString& title, int numberOfKeys);

muse::uicomponents::MenuItem* makeToggleNotatedPitchItem(const muse::TranslatableString& title, bool isNotatedPitch);

void updateKeyWidthScalingItems();

muse::uicomponents::MenuItemList m_keyWidthScalingItems;
Expand Down
10 changes: 10 additions & 0 deletions src/stubs/notation/notationconfigurationstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@ void NotationConfigurationStub::setPianoKeyboardNumberOfKeys(int)
{
}

ValCh<bool> NotationConfigurationStub::pianoKeyboardUseNotatedPitch() const
{
static ValCh<bool> vch;
return vch;
}

void NotationConfigurationStub::setPianoKeyboardUseNotatedPitch(bool)
{
}

bool NotationConfigurationStub::useNewPercussionPanel() const
{
return false
Expand Down
3 changes: 3 additions & 0 deletions src/stubs/notation/notationconfigurationstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ class NotationConfigurationStub : public INotationConfiguration
ValCh<int> pianoKeyboardNumberOfKeys() const override;
void setPianoKeyboardNumberOfKeys(int number) override;

ValCh<bool> pianoKeyboardUseNotatedPitch() const override;
void setPianoKeyboardUseNotatedPitch(bool value) override;

bool useNewPercussionPanel() const override;
void setUseNewPercussionPanel(bool use) override;

Expand Down

0 comments on commit 02aac71

Please sign in to comment.