Skip to content

Commit

Permalink
Merge pull request #26775 from mathesoncalum/450-porting-2
Browse files Browse the repository at this point in the history
Porting more PRs to 4.5.0
  • Loading branch information
cbjeukendrup authored Feb 26, 2025
2 parents 5571e86 + 4a2d41a commit 9f175c0
Show file tree
Hide file tree
Showing 29 changed files with 310 additions and 160 deletions.
4 changes: 4 additions & 0 deletions src/app/configs/data/shortcuts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,10 @@
<key>toggle-piano-keyboard</key>
<seq>P</seq>
</SC>
<SC>
<key>toggle-percussion-panel</key>
<seq>O</seq>
</SC>
<SC>
<key>next-score</key>
<std>20</std>
Expand Down
4 changes: 4 additions & 0 deletions src/app/configs/data/shortcuts_azerty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,10 @@
<key>toggle-piano-keyboard</key>
<seq>P</seq>
</SC>
<SC>
<key>toggle-percussion-panel</key>
<seq>O</seq>
</SC>
<SC>
<key>next-score</key>
<std>20</std>
Expand Down
4 changes: 4 additions & 0 deletions src/app/configs/data/shortcuts_mac.xml
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,10 @@
<key>toggle-piano-keyboard</key>
<seq>P</seq>
</SC>
<SC>
<key>toggle-percussion-panel</key>
<seq>O</seq>
</SC>
<SC>
<key>next-score</key>
<std>20</std>
Expand Down
28 changes: 16 additions & 12 deletions src/appshell/internal/applicationuiactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ using namespace muse::dock;
static const ActionCode FULL_SCREEN_CODE("fullscreen");
static const ActionCode TOGGLE_NAVIGATOR_ACTION_CODE("toggle-navigator");
static const ActionCode TOGGLE_BRAILLE_ACTION_CODE("toggle-braille-panel");
static const ActionCode TOGGLE_PERCUSSION_PANEL_ACTION_CODE("toggle-percussion-panel");

const UiActionList ApplicationUiActions::m_actions = {
UiAction("quit",
Expand Down Expand Up @@ -194,14 +195,13 @@ const UiActionList ApplicationUiActions::m_actions = {
TranslatableString("action", "Show/hide piano keyboard"),
Checkable::Yes
),
// still in development
// UiAction("toggle-percussion-panel",
// mu::context::UiCtxNotationOpened,
// mu::context::CTX_ANY,
// TranslatableString("action", "Percussion"),
// TranslatableString("action", "Show/hide percussion panel"),
// Checkable::Yes
// ),
UiAction(TOGGLE_PERCUSSION_PANEL_ACTION_CODE,
mu::context::UiCtxProjectOpened,
mu::context::CTX_NOTATION_OPENED,
TranslatableString("action", "Percussion"),
TranslatableString("action", "Show/hide percussion panel"),
Checkable::Yes
),
UiAction("toggle-scorecmp-tool",
mu::context::UiCtxProjectOpened,
mu::context::CTX_NOTATION_OPENED,
Expand Down Expand Up @@ -248,6 +248,10 @@ void ApplicationUiActions::init()
dockWindowProvider()->windowChanged().onNotify(this, [this]() {
listenOpenedDocksChanged(dockWindowProvider()->window());
});

notationConfiguration()->useNewPercussionPanelChanged().onNotify(this, [this]() {
m_actionEnabledChanged.send({ TOGGLE_PERCUSSION_PANEL_ACTION_CODE });
});
}

void ApplicationUiActions::listenOpenedDocksChanged(IDockWindow* window)
Expand Down Expand Up @@ -280,11 +284,11 @@ const muse::ui::UiActionList& ApplicationUiActions::actionsList() const

bool ApplicationUiActions::actionEnabled(const UiAction& act) const
{
if (!m_controller->canReceiveAction(act.code)) {
return false;
if (act.code == TOGGLE_PERCUSSION_PANEL_ACTION_CODE) {
return notationConfiguration()->useNewPercussionPanel();
}

return true;
return m_controller->canReceiveAction(act.code);
}

bool ApplicationUiActions::actionChecked(const UiAction& act) const
Expand Down Expand Up @@ -340,7 +344,7 @@ const QMap<ActionCode, DockName>& ApplicationUiActions::toggleDockActions()
{ "toggle-timeline", TIMELINE_PANEL_NAME },
{ "toggle-mixer", MIXER_PANEL_NAME },
{ "toggle-piano-keyboard", PIANO_KEYBOARD_PANEL_NAME },
{ "toggle-percussion-panel", PERCUSSION_PANEL_NAME },
{ TOGGLE_PERCUSSION_PANEL_ACTION_CODE, PERCUSSION_PANEL_NAME },

{ "toggle-statusbar", NOTATION_STATUSBAR_NAME },
};
Expand Down
2 changes: 2 additions & 0 deletions src/appshell/internal/applicationuiactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "async/asyncable.h"
#include "ui/imainwindow.h"
#include "view/preferences/braillepreferencesmodel.h"
#include "notation/inotationconfiguration.h"

#include "dockwindow/idockwindowprovider.h"

Expand All @@ -39,6 +40,7 @@ class ApplicationUiActions : public muse::ui::IUiActionsModule, public muse::Inj
muse::Inject<muse::dock::IDockWindowProvider> dockWindowProvider = { this };
muse::Inject<IAppShellConfiguration> configuration = { this };
muse::Inject<braille::IBrailleConfiguration> brailleConfiguration = { this };
muse::Inject<mu::notation::INotationConfiguration> notationConfiguration = { this };

public:
ApplicationUiActions(std::shared_ptr<ApplicationActionController> controller, const muse::modularity::ContextPtr& iocCtx);
Expand Down
2 changes: 1 addition & 1 deletion src/appshell/view/appmenumodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ MenuItem* AppMenuModel::makeViewMenu()
makeMenuItem("toggle-timeline"),
makeMenuItem("toggle-mixer"),
makeMenuItem("toggle-piano-keyboard"),
// makeMenuItem("toggle-percussion-panel"), // still in development
makeMenuItem("toggle-percussion-panel"),
makeMenuItem("playback-setup"),
//makeMenuItem("toggle-scorecmp-tool"), // not implemented
makeSeparator(),
Expand Down
114 changes: 58 additions & 56 deletions src/engraving/dom/instrchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,70 +86,72 @@ void InstrumentChange::setInstrument(const Instrument& i)

void InstrumentChange::setupInstrument(const Instrument* instrument)
{
if (m_init) {
Fraction tickStart = segment()->tick();
Part* part = staff()->part();
Interval oldV = part->instrument(tickStart)->transpose();
Interval oldKv = staff()->transpose(tickStart);
Interval v = instrument->transpose();
bool concPitch = style().styleB(Sid::concertPitch);

// change the clef for each staff
for (size_t i = 0; i < part->nstaves(); i++) {
ClefType oldClefType = concPitch ? part->instrument(tickStart)->clefType(i).concertClef
: part->instrument(tickStart)->clefType(i).transposingClef;
ClefType newClefType = concPitch ? instrument->clefType(i).concertClef
: instrument->clefType(i).transposingClef;
// Introduce cleff change only if the new clef *symbol* is different from the old one
if (ClefInfo::symId(oldClefType) != ClefInfo::symId(newClefType)) {
// If instrument change is at the start of a measure, use the measure as the element, as this will place the instrument change before the barline.
EngravingItem* element = rtick().isZero() ? toEngravingItem(findMeasure()) : toEngravingItem(this);
score()->undoChangeClef(part->staff(i), element, newClefType, true);
}
if (!m_init) {
return;
}

Fraction tickStart = segment()->tick();
Part* part = staff()->part();
Interval oldV = part->instrument(tickStart)->transpose();
Interval oldKv = staff()->transpose(tickStart);
Interval v = instrument->transpose();
bool concPitch = style().styleB(Sid::concertPitch);

// change the clef for each staff
for (size_t i = 0; i < part->nstaves(); i++) {
ClefType oldClefType = concPitch ? part->instrument(tickStart)->clefType(i).concertClef
: part->instrument(tickStart)->clefType(i).transposingClef;
ClefType newClefType = concPitch ? instrument->clefType(i).concertClef
: instrument->clefType(i).transposingClef;
// Introduce cleff change only if the new clef *symbol* is different from the old one
if (ClefInfo::symId(oldClefType) != ClefInfo::symId(newClefType)) {
// If instrument change is at the start of a measure, use the measure as the element, as this will place the instrument change before the barline.
EngravingItem* element = rtick().isZero() ? toEngravingItem(findMeasure()) : toEngravingItem(this);
score()->undoChangeClef(part->staff(i), element, newClefType, true);
}
}

// Change key signature if necessary. CAUTION: not necessary in case of octave-transposing!
if ((v.chromatic - oldV.chromatic) % 12) {
for (size_t i = 0; i < part->nstaves(); i++) {
if (!part->staff(i)->keySigEvent(tickStart).isAtonal()) {
KeySigEvent ks;
// Check, if some key signature is already there, if no, mark new one "for instrument change"
Segment* seg = segment()->prev1(SegmentType::KeySig);
voice_idx_t voice = part->staff(i)->idx() * VOICES;
KeySig* ksig = seg ? toKeySig(seg->element(voice)) : nullptr;
bool forInstChange = !(ksig && ksig->tick() == tickStart && !ksig->generated());
ks.setForInstrumentChange(forInstChange);
Key cKey = part->staff(i)->concertKey(tickStart);
ks.setConcertKey(cKey);
score()->undoChangeKeySig(part->staff(i), tickStart, ks);
}
// Change key signature if necessary. CAUTION: not necessary in case of octave-transposing!
if ((v.chromatic - oldV.chromatic) % 12) {
for (size_t i = 0; i < part->nstaves(); i++) {
if (!part->staff(i)->keySigEvent(tickStart).isAtonal()) {
KeySigEvent ks;
// Check, if some key signature is already there, if no, mark new one "for instrument change"
Segment* seg = segment()->prev1(SegmentType::KeySig);
voice_idx_t voice = part->staff(i)->idx() * VOICES;
KeySig* ksig = seg ? toKeySig(seg->element(voice)) : nullptr;
bool forInstChange = !(ksig && ksig->tick() == tickStart && !ksig->generated());
ks.setForInstrumentChange(forInstChange);
Key cKey = part->staff(i)->concertKey(tickStart);
ks.setConcertKey(cKey);
score()->undoChangeKeySig(part->staff(i), tickStart, ks);
}
}
}

// change instrument in all linked scores
for (EngravingObject* se : linkList()) {
InstrumentChange* lic = static_cast<InstrumentChange*>(se);
Instrument* newInstrument = new Instrument(*instrument);
lic->score()->undo(new ChangeInstrument(lic, newInstrument));
}
// change instrument in all linked scores
for (EngravingObject* se : linkList()) {
InstrumentChange* lic = static_cast<InstrumentChange*>(se);
Instrument* newInstrument = new Instrument(*instrument);
lic->score()->undo(new ChangeInstrument(lic, newInstrument));
}

// transpose for current score only
// this automatically propagates to linked scores
if (part->instrument(tickStart)->transpose() != oldV) {
auto i = part->instruments().upper_bound(tickStart.ticks()); // find(), ++i
Fraction tickEnd;
if (i == part->instruments().end()) {
tickEnd = Fraction(-1, 1);
} else {
tickEnd = Fraction::fromTicks(i->first);
}
score()->transpositionChanged(part, oldKv, tickStart, tickEnd);
// transpose for current score only
// this automatically propagates to linked scores
if (part->instrument(tickStart)->transpose() != oldV) {
auto i = part->instruments().upper_bound(tickStart.ticks()); // find(), ++i
Fraction tickEnd;
if (i == part->instruments().end()) {
tickEnd = Fraction(-1, 1);
} else {
tickEnd = Fraction::fromTicks(i->first);
}

//: The text of an "instrument change" marking. It is an instruction to the player to switch to another instrument.
const String newInstrChangeText = muse::mtrc("engraving", "To %1").arg(instrument->trackName());
undoChangeProperty(Pid::TEXT, TextBase::plainToXmlText(newInstrChangeText));
score()->transpositionChanged(part, oldKv, tickStart, tickEnd);
}

//: The text of an "instrument change" marking. It is an instruction to the player to switch to another instrument.
const String newInstrChangeText = muse::mtrc("engraving", "To %1").arg(instrument->trackName());
undoChangeProperty(Pid::TEXT, TextBase::plainToXmlText(newInstrChangeText));
}

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/framework/accessibility/iaccessible.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class IAccessible
Panel,
StaticText,
EditableText,
SilentRole, // avoids reading "button", "text", etc. after item name
Button,
CheckBox,
RadioButton,
Expand Down
21 changes: 21 additions & 0 deletions src/framework/accessibility/internal/accessibleiteminterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ QAccessible::State AccessibleItemInterface::state() const
state.focusable = true;
state.focused = item->accessibleState(IAccessible::State::Focused);
} break;
case IAccessible::Role::SilentRole: {
state.focusable = true;
state.focused = item->accessibleState(IAccessible::State::Focused);
} break;
case IAccessible::Role::List: {
state.active = item->accessibleState(IAccessible::State::Active);
} break;
Expand Down Expand Up @@ -217,6 +221,23 @@ QAccessible::Role AccessibleItemInterface::role() const
case IAccessible::Role::Dialog: return QAccessible::Dialog;
case IAccessible::Role::Panel: return QAccessible::Pane;
case IAccessible::Role::StaticText: return QAccessible::StaticText;
case IAccessible::Role::SilentRole: {
// See https://doc.qt.io/qt-5/qaccessible.html#Role-enum
// We want the screen reader to say the name of the current item and
// nothing else (i.e. not the name followed by "button" or "text").
#if defined(Q_OS_MACOS)
// Good on macOS with VoiceOver.
return QAccessible::StaticText;
// VoiceOver gives unwanted additional output if ListItem is used, and it
// doesn't work at all if the role is TreeItem or Cell.
#else
// Good on Windows with Narrator, NVDA, or JAWS; and on Linux with Orca.
return QAccessible::ListItem;
// Orca is equally happy with the roles TreeItem or Cell, but these cause
// unwanted additional ouput on Windows. StaticText causes unwanted
// additional output on both Linux and Windows.
#endif
}
case IAccessible::Role::EditableText: return QAccessible::EditableText;
case IAccessible::Role::Button: return QAccessible::Button;
case IAccessible::Role::CheckBox: return QAccessible::CheckBox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Item {

signal saveRequested()
signal cancelRequested()
signal clearRequested()
signal keyPressed(var event)

anchors.fill: parent
Expand Down Expand Up @@ -138,6 +139,17 @@ Item {
navigationPanel.section: root.navigationSection
navigationPanel.order: 2

FlatButton {
text: qsTrc("global", "Clear")
buttonRole: ButtonBoxModel.CustomRole
buttonId: ButtonBoxModel.Clear
isLeftSide: true

onClicked: {
root.clearRequested()
}
}

onStandardButtonClicked: function(buttonId) {
if (buttonId === ButtonBoxModel.Cancel) {
root.cancelRequested()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ StyledDialogView {

headerText: qsTrc("shortcuts", "Define keyboard shortcut")

originShortcutText: editShortcutModel.originSequence
//! NOTE: There's no need to actually clear the origin shortcut, we can simply hide it for aesthetic purposes...
originShortcutText: !editShortcutModel.cleared ? editShortcutModel.originSequence : ""
newShortcutText: editShortcutModel.newSequence
informationText: editShortcutModel.conflictWarning

Expand All @@ -76,6 +77,10 @@ StyledDialogView {
root.reject()
}

onClearRequested: {
editShortcutModel.clear()
}

onKeyPressed: function(event) {
editShortcutModel.inputKey(event.key, event.modifiers)
}
Expand Down
15 changes: 13 additions & 2 deletions src/framework/shortcuts/view/editshortcutmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ void EditShortcutModel::load(const QVariant& originShortcut, const QVariantList&
m_originSequence = originShortcutMap.value("sequence").toString();
m_originShortcutTitle = originShortcutMap.value("title").toString();

m_cleared = false;

emit originSequenceChanged();
emit clearedChanged();
}

void EditShortcutModel::clearNewSequence()
Expand Down Expand Up @@ -110,6 +113,14 @@ void EditShortcutModel::inputKey(Qt::Key key, Qt::KeyboardModifiers modifiers)
emit newSequenceChanged();
}

void EditShortcutModel::clear()
{
clearNewSequence();
m_cleared = true;
emit originSequenceChanged();
emit clearedChanged();
}

bool EditShortcutModel::isShiftAllowed(Qt::Key key)
{
if (key >= Qt::Key_A && key <= Qt::Key_Z) {
Expand Down Expand Up @@ -215,8 +226,8 @@ QString EditShortcutModel::conflictWarning() const
void EditShortcutModel::trySave()
{
QString newSequence = this->newSequence();

if (m_originSequence == newSequence) {
const bool alreadyEmpty = originSequenceInNativeFormat().isEmpty() && m_cleared;
if (alreadyEmpty || m_originSequence == newSequence) {
return;
}

Expand Down
Loading

0 comments on commit 9f175c0

Please sign in to comment.