Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Accessibility Panel - Score Style Preset option #23048

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion share/styles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ install(FILES
cchords_sym.xml
DESTINATION ${Mscore_SHARE_NAME}${Mscore_INSTALL_NAME}styles
)

add_subdirectory(MSN)
8 changes: 8 additions & 0 deletions share/styles/MSN/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
install(FILES
16mm_MSN.mss
18mm_MSN.mss
20mm_MSN.mss
22mm_MSN.mss
25mm_MSN.mss
DESTINATION ${Mscore_SHARE_NAME}${Mscore_INSTALL_NAME}styles/MSN
)
14 changes: 13 additions & 1 deletion src/engraving/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ bool MStyle::read(IODevice* device, bool ign)
readVersion(e.attribute("version"));
while (e.readNextStartElement()) {
if (e.name() == "Style") {
m_preset = TConv::fromXml(e.asciiAttribute("preset", "Default"), ScoreStylePreset::DEFAULT);
m_presetedited = e.attribute("edited", String(u"false")) == "true";
read(e, nullptr);
} else {
e.unknown();
Expand Down Expand Up @@ -542,7 +544,17 @@ bool MStyle::write(IODevice* device)

void MStyle::save(XmlWriter& xml, bool optimize)
{
xml.startElement("Style");
muse::XmlStreamWriter::Attributes attributes;

if (preset() != ScoreStylePreset::DEFAULT) {
attributes.push_back({ "preset", TConv::toXml(preset()) });
}

if (presetEdited()) {
attributes.push_back({ "edited", String(u"true") });
}

xml.startElement("Style", attributes);

for (const StyleDef::StyleValue& st : StyleDef::styleValues) {
Sid idx = st.styleIdx();
Expand Down
7 changes: 7 additions & 0 deletions src/engraving/style/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class MStyle
void setDefaultStyleVersion(const int defaultsVersion);
int defaultStyleVersion() const;

ScoreStylePreset preset() const { return m_preset; }
void setPreset(ScoreStylePreset preset) { m_preset = preset; }
bool presetEdited() const { return m_presetedited; }
void setPresetEdited(bool isEdited) { m_presetedited = isEdited; }

bool read(muse::io::IODevice* device, bool ign = false);
bool write(muse::io::IODevice* device);
void save(XmlWriter& xml, bool optimize);
Expand All @@ -100,6 +105,8 @@ class MStyle

void readVersion(String versionTag);
int m_version = 0;
ScoreStylePreset m_preset = ScoreStylePreset::DEFAULT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the type name is mentioned elsewhere on the line, you can also do:

auto m_preset = ScoreStylePreset::DEFAULT;

But writing it explicitly is fine too.

bool m_presetedited = false;
};
} // namespace mu::engraving

Expand Down
10 changes: 10 additions & 0 deletions src/engraving/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,16 @@ struct std::hash<mu::engraving::InstrumentTrackId>
}
};

enum class ScoreStylePreset {
DEFAULT = 0,
MSN_16MM,
MSN_18MM,
MSN_20MM,
MSN_22MM,
MSN_25MM,
MAX_PRESET
};

#ifndef NO_QT_SUPPORT
Q_DECLARE_METATYPE(mu::engraving::BeamMode)
Q_DECLARE_METATYPE(mu::engraving::JumpType)
Expand Down
39 changes: 39 additions & 0 deletions src/engraving/types/typesconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2746,3 +2746,42 @@ String TConv::translatedUserName(Key v, bool isAtonal, bool isCustom)
{
return userName(v, isAtonal, isCustom).translated();
}

const std::array<Item<ScoreStylePreset>, 6> SCORE_STYLE_PRESETS = { {
//: Score notation style: Default
{ ScoreStylePreset::DEFAULT, "Default", muse::TranslatableString("engraving/scorestylepreset", "Default") },
//: Score notation style: Modified Stave Notation (MSN) with 16mm staff size. Intended for visually-impaired musicians.
{ ScoreStylePreset::MSN_16MM, "16mm MSN", muse::TranslatableString("engraving/scorestylepreset", "16mm MSN") },
//: Score notation style: Modified Stave Notation (MSN) with 18mm staff size. Intended for visually-impaired musicians.
{ ScoreStylePreset::MSN_18MM, "18mm MSN", muse::TranslatableString("engraving/scorestylepreset", "18mm MSN") },
//: Score notation style: Modified Stave Notation (MSN) with 20mm staff size. Intended for visually-impaired musicians.
{ ScoreStylePreset::MSN_20MM, "20mm MSN", muse::TranslatableString("engraving/scorestylepreset", "20mm MSN") },
//: Score notation style: Modified Stave Notation (MSN) with 22mm staff size. Intended for visually-impaired musicians.
{ ScoreStylePreset::MSN_22MM, "22mm MSN", muse::TranslatableString("engraving/scorestylepreset", "22mm MSN") },
//: Score notation style: Modified Stave Notation (MSN) with 25mm staff size. Intended for visually-impaired musicians.
{ ScoreStylePreset::MSN_25MM, "25mm MSN", muse::TranslatableString("engraving/scorestylepreset", "25mm MSN") }
} };

AsciiStringView TConv::toXml(ScoreStylePreset preset)
{
return findXmlTagByType<ScoreStylePreset>(SCORE_STYLE_PRESETS, preset);
}

ScoreStylePreset TConv::fromXml(const AsciiStringView& tag, ScoreStylePreset def)
{
if (tag == "Default") {
return def;
}

return findTypeByXmlTag<ScoreStylePreset>(SCORE_STYLE_PRESETS, tag, def);
}

const muse::TranslatableString& TConv::userName(ScoreStylePreset v)
{
return findUserNameByType<ScoreStylePreset>(SCORE_STYLE_PRESETS, v);
}

String TConv::translatedUserName(ScoreStylePreset v)
{
return findUserNameByType<ScoreStylePreset>(SCORE_STYLE_PRESETS, v).translated();
}
6 changes: 6 additions & 0 deletions src/engraving/types/typesconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ class TConv

static AsciiStringView toXml(AutoOnOff autoOnOff);
static AutoOnOff fromXml(const AsciiStringView& str, AutoOnOff def);

static AsciiStringView toXml(ScoreStylePreset preset);
static ScoreStylePreset fromXml(const AsciiStringView& tag, ScoreStylePreset def);

static const TranslatableString& userName(ScoreStylePreset v);
static String translatedUserName(ScoreStylePreset v);
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/inspector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/models/measures/measuressettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/score/scoreappearancesettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/score/scoreappearancesettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/score/scoreaccessibilitysettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/score/scoreaccessibilitysettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/score/scoredisplaysettingsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/models/score/scoredisplaysettingsmodel.h
${CMAKE_CURRENT_LIST_DIR}/models/score/internal/pagetypelistmodel.cpp
Expand Down
1 change: 1 addition & 0 deletions src/inspector/models/abstractinspectormodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class AbstractInspectorModel : public QObject, public muse::async::Asyncable
SECTION_TEXT,
SECTION_SCORE_DISPLAY,
SECTION_SCORE_APPEARANCE,
SECTION_SCORE_ACCESSIBILITY,
SECTION_PARTS,
};
Q_ENUM(InspectorSectionType)
Expand Down
7 changes: 6 additions & 1 deletion src/inspector/models/inspectorlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "text/textsettingsmodel.h"
#include "score/scoredisplaysettingsmodel.h"
#include "score/scoreappearancesettingsmodel.h"
#include "score/scoreaccessibilitysettingsmodel.h"
#include "notation/inotationinteraction.h"

#include "internal/services/elementrepositoryservice.h"
Expand Down Expand Up @@ -73,7 +74,8 @@ void InspectorListModel::buildModelsForEmptySelection()

static const InspectorSectionTypeSet persistentSections {
InspectorSectionType::SECTION_SCORE_DISPLAY,
InspectorSectionType::SECTION_SCORE_APPEARANCE
InspectorSectionType::SECTION_SCORE_APPEARANCE,
InspectorSectionType::SECTION_SCORE_ACCESSIBILITY
};

removeUnusedModels({}, false /*isRangeSelection*/, {}, persistentSections);
Expand Down Expand Up @@ -195,6 +197,9 @@ void InspectorListModel::createModelsBySectionType(const InspectorSectionTypeSet
case InspectorSectionType::SECTION_SCORE_APPEARANCE:
newModel = new ScoreAppearanceSettingsModel(this, m_repository);
break;
case InspectorSectionType::SECTION_SCORE_ACCESSIBILITY:
newModel = new ScoreAccessibilitySettingsModel(this, m_repository);
break;
case InspectorSectionType::SECTION_PARTS:
newModel = new PartsSettingsModel(this, m_repository);
break;
Expand Down
215 changes: 215 additions & 0 deletions src/inspector/models/score/scoreaccessibilitysettingsmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-Studio-CLA-applies
*
* MuseScore Studio
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "scoreaccessibilitysettingsmodel.h"

#include "translation.h"
#include "log.h"
#include "engraving/types/typesconv.h"
#include "framework/global/defer.h"

using namespace mu::inspector;
using namespace mu::engraving;

ScoreAccessibilitySettingsModel::ScoreAccessibilitySettingsModel(QObject* parent, IElementRepositoryService* repository)
: AbstractInspectorModel(parent, repository)
{
setSectionType(InspectorSectionType::SECTION_SCORE_ACCESSIBILITY);
setTitle(muse::qtrc("inspector", "Accessibility"));

globalContext()->currentNotation()->style()->styleChanged().onNotify(this, [this]() {
if (!m_ignoreStyleChange && !m_scoreStylePresetEdited) {
m_scoreStylePresetEdited = true;
globalContext()->currentNotation()->elements()->msScore()->score()->style().setPresetEdited(true);
emit possibleScoreStylePresetsChanged();
emit scoreStylePresetIndexChanged();
}
});
}

void ScoreAccessibilitySettingsModel::createProperties()
{
// Placeholder
}

void ScoreAccessibilitySettingsModel::requestElements()
{
// Placeholder
}

void ScoreAccessibilitySettingsModel::loadProperties()
{
// Placeholder
}

void ScoreAccessibilitySettingsModel::resetProperties()
{
// Placeholder
}

muse::io::path_t ScoreAccessibilitySettingsModel::getStyleFilePath(ScoreStylePreset preset) const
{
muse::io::path_t basePath = globalConfiguration()->appDataPath() + "styles/MSN/";
switch (preset) {
case ScoreStylePreset::DEFAULT:
return engravingConfiguration()->defaultStyleFilePath();
case ScoreStylePreset::MSN_16MM:
return basePath + "16mm_MSN.mss";
case ScoreStylePreset::MSN_18MM:
return basePath + "18mm_MSN.mss";
case ScoreStylePreset::MSN_20MM:
return basePath + "20mm_MSN.mss";
case ScoreStylePreset::MSN_22MM:
return basePath + "22mm_MSN.mss";
case ScoreStylePreset::MSN_25MM:
return basePath + "25mm_MSN.mss";
default:
return muse::io::path_t();
}
}

QVariantList ScoreAccessibilitySettingsModel::possibleScoreStylePresets() const
{
QVariantList presets;

QString text = "text";
QString value = "value";
QString preset = "preset";
QString edited = "edited";

for (int i = 0; i < static_cast<int>(ScoreStylePreset::MAX_PRESET); ++i) {
ScoreStylePreset presetEnum = static_cast<ScoreStylePreset>(i);
QString presetName = TConv::translatedUserName(presetEnum);

presets.append(QVariantMap {
{ text, presetName },
{
value,
QVariantMap {
{ preset, i },
{ edited, false }
}
}
});

if (i == static_cast<int>(m_scoreStylePreset) && m_scoreStylePresetEdited) {
QString editedPresetName = muse::qtrc("inspector", "%1 (edited)").arg(presetName);
presets.append(QVariantMap {
{ text, editedPresetName },
{
value,
QVariantMap {
{ preset, i },
{ edited, true }
}
}
});
}
}

return presets;
}

void ScoreAccessibilitySettingsModel::setScoreStylePresetIndex(int index)
{
int oldIndex = scoreStylePresetIndex();

if (index == oldIndex) {
return;
}

if (m_scoreStylePresetEdited && index > oldIndex) {
--index;
}
shoogle marked this conversation as resolved.
Show resolved Hide resolved

auto selectedPreset = static_cast<ScoreStylePreset>(index);

bool presetChanged = (selectedPreset != m_scoreStylePreset);
bool editedChanged = (m_scoreStylePresetEdited != false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool editedChanged = m_scoreStylePresetEdited; // because index != oldIndex


MStyle& style = globalContext()->currentNotation()->elements()->msScore()->score()->style();

if (presetChanged) {
loadStyle(selectedPreset);
m_scoreStylePreset = selectedPreset;
style.setPreset(selectedPreset);

emit scoreStylePresetIndexChanged();
}

if (editedChanged) {
m_scoreStylePresetEdited = false;
style.setPresetEdited(false);

emit possibleScoreStylePresetsChanged();
emit scoreStylePresetIndexChanged();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You emit scoreStylePresetIndexChanged() twice in this function. That should never happen.

Emitting will cause connected slots to fire (i.e. it will make something happen in the UI), which could potentially be costly in terms of performance. You don't want to emit things more often than you need to.

Normally, it would be better to add a separate conditional block at the end of the function:

if (presetChanged || editedChanged) {
    emit scoreStylePresetIndexChanged();
}

Except in this case you already know that index != oldIndex, so you can do this outside of a conditional block:

emit scoreStylePresetIndexChanged();

That should be the final line of this function.

}
}

void ScoreAccessibilitySettingsModel::loadStyle(ScoreStylePreset preset)
{
muse::io::path_t filePath = getStyleFilePath(preset);
m_ignoreStyleChange = true;
DEFER {
m_ignoreStyleChange = false;
};

if (preset == ScoreStylePreset::DEFAULT && filePath.empty()) {
StyleIdSet emptySet;
globalContext()->currentNotation()->style()->resetAllStyleValues(emptySet);
return;
}

IF_ASSERT_FAILED(!filePath.empty()) {
return;
}

LOGI() << "Loading style from filePath: " << filePath;
globalContext()->currentNotation()->style()->loadStyle(filePath, true);
}

int ScoreAccessibilitySettingsModel::scoreStylePresetIndex() const
{
return static_cast<int>(m_scoreStylePreset) + (m_scoreStylePresetEdited ? 1 : 0);
}

void ScoreAccessibilitySettingsModel::updateScoreStylePreset()
{
MStyle style = globalContext()->currentNotation()->elements()->msScore()->score()->style();
ScoreStylePreset stylePreset = style.preset();
bool stylePresetEdited = style.presetEdited();
bool indexChanged = false;

if (m_scoreStylePreset != stylePreset) {
m_scoreStylePreset = stylePreset;
shoogle marked this conversation as resolved.
Show resolved Hide resolved
indexChanged = true;
}

if (m_scoreStylePresetEdited != stylePresetEdited) {
m_scoreStylePresetEdited = stylePresetEdited;
shoogle marked this conversation as resolved.
Show resolved Hide resolved
emit possibleScoreStylePresetsChanged();
indexChanged = true;
}

if (indexChanged) {
emit scoreStylePresetIndexChanged();
}
}
Loading