Implemented note name formatting

This commit is contained in:
Eism 2021-06-08 17:58:01 +02:00
parent 2c7b175e0d
commit 31367d7ad7
4 changed files with 103 additions and 2 deletions

View file

@ -80,6 +80,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/xmlreader.h
${CMAKE_CURRENT_LIST_DIR}/xmlwriter.cpp
${CMAKE_CURRENT_LIST_DIR}/xmlwriter.h
${CMAKE_CURRENT_LIST_DIR}/utils.cpp
${CMAKE_CURRENT_LIST_DIR}/utils.h
${CMAKE_CURRENT_LIST_DIR}/internal/globalconfiguration.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/globalconfiguration.h
${CMAKE_CURRENT_LIST_DIR}/internal/interactive.cpp

View file

@ -0,0 +1,67 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* 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 "utils.h"
#include "translation.h"
using namespace mu;
static const std::vector<std::string> noteHeadNamesLower = {
trc("global", "c"),
trc("global", "c♯"),
trc("global", "d"),
trc("global", "d♯"),
trc("global", "e"),
trc("global", "f"),
trc("global", "f♯"),
trc("global", "g"),
trc("global", "g♯"),
trc("global", "a"),
trc("global", "a♯"),
trc("global", "b")
};
static const std::vector<std::string> noteHeadNamesUpper = {
trc("global", "C"),
trc("global", "C♯"),
trc("global", "D"),
trc("global", "D♯"),
trc("global", "E"),
trc("global", "F"),
trc("global", "F♯"),
trc("global", "G"),
trc("global", "G♯"),
trc("global", "A"),
trc("global", "A♯"),
trc("global", "B")
};
std::string mu::pitchToString(int pitch)
{
if (pitch < 0 || pitch > 127) {
return std::string();
}
int octave = (pitch / 12) - 1;
int i = pitch % 12;
return octave < 0 ? noteHeadNamesUpper[i] : (noteHeadNamesLower[i] + std::to_string(octave));
}

View file

@ -0,0 +1,31 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* 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/>.
*/
#ifndef MU_FRAMEWORK_UTILS_H
#define MU_FRAMEWORK_UTILS_H
#include <string>
namespace mu {
std::string pitchToString(int pitch);
}
#endif // MU_FRAMEWORK_GLOBAL_H

View file

@ -23,6 +23,7 @@
#include "editmidimappingmodel.h"
#include "log.h"
#include "utils.h"
#include "translation.h"
using namespace mu::shortcuts;
@ -90,10 +91,10 @@ QString EditMidiMappingModel::eventName(const RemoteEvent& event) const
QString title;
if (event.type == RemoteEventType::Note) {
return qtrc("shortcuts", "Note ") + QString::number(event.value);
return qtrc("shortcuts", "Note ") + QString::fromStdString(pitchToString(event.value));
} else if (event.type == RemoteEventType::Controller) {
return qtrc("shortcuts", "Controller ") + QString::number(event.value);
}
return qtrc("shortcuts", "None"); // todo
return qtrc("shortcuts", "None");
}