Skip to content

Commit

Permalink
Change storage of notehead type and group in notes
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Oct 18, 2016
1 parent 7f9585a commit ffedbba
Show file tree
Hide file tree
Showing 31 changed files with 1,881 additions and 318 deletions.
125 changes: 95 additions & 30 deletions libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,100 @@ static const SymId noteHeads[2][int(NoteHead::Group::HEAD_GROUPS)][int(NoteHead:
}
};

struct NoteHeadName {
const char* name;
const char* username;
};

// same order as NoteHead::Group
static const char* noteHeadNames[] = {
QT_TRANSLATE_NOOP("noteheadnames", "Normal"),
QT_TRANSLATE_NOOP("noteheadnames", "Cross"),
QT_TRANSLATE_NOOP("noteheadnames", "Diamond"),
QT_TRANSLATE_NOOP("noteheadnames", "Triangle"),
QT_TRANSLATE_NOOP("noteheadnames", "Mi"),
QT_TRANSLATE_NOOP("noteheadnames", "Slash"),
QT_TRANSLATE_NOOP("noteheadnames", "XCircle"),
QT_TRANSLATE_NOOP("noteheadnames", "Do"),
QT_TRANSLATE_NOOP("noteheadnames", "Re"),
QT_TRANSLATE_NOOP("noteheadnames", "Fa"),
QT_TRANSLATE_NOOP("noteheadnames", "La"),
QT_TRANSLATE_NOOP("noteheadnames", "Ti"),
QT_TRANSLATE_NOOP("noteheadnames", "Sol"),
QT_TRANSLATE_NOOP("noteheadnames", "Alt. Brevis")
static NoteHeadName noteHeadGroupNames[] = {
{"normal", QT_TRANSLATE_NOOP("noteheadnames", "Normal") },
{"cross", QT_TRANSLATE_NOOP("noteheadnames", "Cross") },
{"diamond", QT_TRANSLATE_NOOP("noteheadnames", "Diamond") },
{"triangle", QT_TRANSLATE_NOOP("noteheadnames", "Triangle") },
{"mi", QT_TRANSLATE_NOOP("noteheadnames", "Mi") },
{"slash", QT_TRANSLATE_NOOP("noteheadnames", "Slash") },
{"xcircle", QT_TRANSLATE_NOOP("noteheadnames", "XCircle") },
{"do", QT_TRANSLATE_NOOP("noteheadnames", "Do") },
{"re", QT_TRANSLATE_NOOP("noteheadnames", "Re") },
{"fa", QT_TRANSLATE_NOOP("noteheadnames", "Fa") },
{"la", QT_TRANSLATE_NOOP("noteheadnames", "La") },
{"ti", QT_TRANSLATE_NOOP("noteheadnames", "Ti") },
{"sol", QT_TRANSLATE_NOOP("noteheadnames", "Sol") },
{"altbrevis", QT_TRANSLATE_NOOP("noteheadnames", "Alt. Brevis") }
};

// same order as NoteHead::Type
static NoteHeadName noteHeadTypeNames[] = {
{"auto", QT_TRANSLATE_NOOP("noteheadnames", "Auto") },
{"whole", QT_TRANSLATE_NOOP("noteheadnames", "Whole") },
{"half", QT_TRANSLATE_NOOP("noteheadnames", "Half") },
{"quarter", QT_TRANSLATE_NOOP("noteheadnames", "Quarter") },
{"breve", QT_TRANSLATE_NOOP("noteheadnames", "Breve") },
};

//---------------------------------------------------------
// group2userName
//---------------------------------------------------------

QString NoteHead::group2userName(NoteHead::Group group)
{
return qApp->translate("noteheadnames", noteHeadGroupNames[int(group)].username);
}

//---------------------------------------------------------
// type2userName
//---------------------------------------------------------

QString NoteHead::type2userName(NoteHead::Type type)
{
return qApp->translate("noteheadnames", noteHeadTypeNames[int(type) + 1].username);
}

//---------------------------------------------------------
// group2name
//---------------------------------------------------------

QString NoteHead::group2name(NoteHead::Group group)
{
return noteHeadGroupNames[int(group)].name;
}

//---------------------------------------------------------
// type2name
//---------------------------------------------------------

QString NoteHead::type2name(NoteHead::Type type)
{
return noteHeadTypeNames[int(type) + 1].name;
}

//---------------------------------------------------------
// name2group
//---------------------------------------------------------

NoteHead::Group NoteHead::name2group(QString s)
{
for (int i = 0; i < int(NoteHead::Group::HEAD_GROUPS); ++i) {
if (noteHeadGroupNames[i].name == s)
return NoteHead::Group(i);
}
return NoteHead::Group::HEAD_NORMAL;
}

//---------------------------------------------------------
// name2type
//---------------------------------------------------------

NoteHead::Type NoteHead::name2type(QString s)
{
for (int i = 0; i <= int(NoteHead::Type::HEAD_TYPES); ++i) {
if (noteHeadTypeNames[i].name == s)
return NoteHead::Type(i - 1);
}
return NoteHead::Type::HEAD_AUTO;
}

//---------------------------------------------------------
// noteHead
//---------------------------------------------------------
Expand All @@ -128,12 +204,13 @@ SymId Note::noteHead(int direction, NoteHead::Group g, NoteHead::Type t)

//---------------------------------------------------------
// headGroup
// used only when dropping a notehead from the palette
// they are either half note, either double whole
//---------------------------------------------------------

NoteHead::Group NoteHead::headGroup() const
{
Group group = Group::HEAD_INVALID;

for (int i = 0; i < int(Group::HEAD_GROUPS); ++i) {
if (noteHeads[0][i][1] == _sym || noteHeads[0][i][3] == _sym) {
group = (Group)i;
Expand Down Expand Up @@ -902,10 +979,7 @@ bool Note::readProperties(XmlReader& e)
else if (tag == "ghost")
setGhost(e.readInt());
else if (tag == "headType")
if (score()->mscVersion() <= 114)
setProperty(P_ID::HEAD_TYPE, Ms::getProperty(P_ID::HEAD_TYPE, e).toInt() - 1);
else
setProperty(P_ID::HEAD_TYPE, Ms::getProperty(P_ID::HEAD_TYPE, e).toInt());
setProperty(P_ID::HEAD_TYPE, Ms::getProperty(P_ID::HEAD_TYPE, e));
else if (tag == "veloType")
setProperty(P_ID::VELO_TYPE, Ms::getProperty(P_ID::VELO_TYPE, e));
else if (tag == "line")
Expand Down Expand Up @@ -2427,22 +2501,13 @@ int Note::qmlDotsCount()
return _dots.size();
}

//---------------------------------------------------------
// groupToGroupName
//---------------------------------------------------------

const char* NoteHead::groupToGroupName(NoteHead::Group group)
{
return noteHeadNames[int(group)];
}

//---------------------------------------------------------
// subtypeName
//---------------------------------------------------------

QString Note::subtypeName() const
{
return qApp->translate("noteheadnames", NoteHead::groupToGroupName(_headGroup));
return NoteHead::group2userName(_headGroup);
}

//---------------------------------------------------------
Expand Down
10 changes: 6 additions & 4 deletions libmscore/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ class NoteHead : public Symbol {

Group headGroup() const;

static const char* groupToGroupName(Group group);
static QString group2userName(Group group);
static QString type2userName(Type type);
static QString group2name(Group group);
static QString type2name(Type type);
static Group name2group(QString s);
static Type name2type(QString s);
};

//---------------------------------------------------------
Expand Down Expand Up @@ -463,9 +468,6 @@ class Note : public Element {
int onTimeType() const { return _onTimeType; }
};

// extern const SymId noteHeads[2][int(NoteHead::Group::HEAD_GROUPS)][int(NoteHead::Type::HEAD_TYPES)];


} // namespace Ms

Q_DECLARE_METATYPE(Ms::NoteHead::Group);
Expand Down
8 changes: 6 additions & 2 deletions libmscore/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ static const PropertyData propertyList[] = {
{ P_ID::LINE, false, "line", P_TYPE::INT },
{ P_ID::FIXED, false, "fixed", P_TYPE::BOOL },
{ P_ID::FIXED_LINE, false, "fixedLine", P_TYPE::INT },
{ P_ID::HEAD_TYPE, false, "headType", P_TYPE::INT },
{ P_ID::HEAD_GROUP, false, "head", P_TYPE::INT },
{ P_ID::HEAD_TYPE, false, "headType", P_TYPE::HEAD_TYPE },
{ P_ID::HEAD_GROUP, false, "head", P_TYPE::HEAD_GROUP },
{ P_ID::VELO_TYPE, false, "veloType", P_TYPE::VALUE_TYPE },
{ P_ID::VELO_OFFSET, false, "velocity", P_TYPE::INT },
{ P_ID::ARTICULATION_ANCHOR, false, "anchor", P_TYPE::INT },
Expand Down Expand Up @@ -400,6 +400,10 @@ QVariant getProperty(P_ID id, XmlReader& e)
case P_TYPE::SYMID:
return QVariant::fromValue(Sym::name2id(e.readElementText()));
break;
case P_TYPE::HEAD_GROUP:
return QVariant::fromValue(NoteHead::name2group(e.readElementText()));;
case P_TYPE::HEAD_TYPE:
return QVariant::fromValue(NoteHead::name2type(e.readElementText()));
case P_TYPE::POINT_MM: // not supported
case P_TYPE::TDURATION:
case P_TYPE::SIZE_MM:
Expand Down
2 changes: 2 additions & 0 deletions libmscore/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ enum class P_TYPE : char {
INT_LIST,
GLISSANDO_STYLE,
BARLINE_TYPE,
HEAD_TYPE, // enum class Notehead::Type
HEAD_GROUP, // enum class Notehead::Group
ZERO_INT, // displayed with offset +1
};

Expand Down
69 changes: 69 additions & 0 deletions libmscore/read114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,75 @@ static void readNote(Note* note, XmlReader& e)
e.skipCurrentElement(); // ignore manual layout in older scores
else if (tag == "move")
note->chord()->setStaffMove(e.readInt());
else if (tag == "head") {
int i = e.readInt();
NoteHead::Group val;
switch (i) {
case 1:
val = NoteHead::Group::HEAD_CROSS;
break;
case 2:
val = NoteHead::Group::HEAD_DIAMOND;
break;
case 3:
val = NoteHead::Group::HEAD_TRIANGLE;
break;
case 4:
val = NoteHead::Group::HEAD_MI;
break;
case 5:
val = NoteHead::Group::HEAD_SLASH;
break;
case 6:
val = NoteHead::Group::HEAD_XCIRCLE;
break;
case 7:
val = NoteHead::Group::HEAD_DO;
break;
case 8:
val = NoteHead::Group::HEAD_RE;
break;
case 9:
val = NoteHead::Group::HEAD_FA;
break;
case 10:
val = NoteHead::Group::HEAD_LA;
break;
case 11:
val = NoteHead::Group::HEAD_TI;
break;
case 12:
val = NoteHead::Group::HEAD_SOL;
break;
case 13:
val = NoteHead::Group::HEAD_BREVIS_ALT;
break;
default:
val = NoteHead::Group::HEAD_NORMAL;
}
note->setHeadGroup(val);
}
else if (tag == "headType") {
int i = e.readInt();
NoteHead::Type val;
switch (i) {
case 1:
val = NoteHead::Type::HEAD_WHOLE;
break;
case 2:
val = NoteHead::Type::HEAD_HALF;
break;
case 3:
val = NoteHead::Type::HEAD_QUARTER;
break;
case 4:
val = NoteHead::Type::HEAD_BREVIS;
break;
default:
val = NoteHead::Type::HEAD_AUTO;
}
note->setHeadType(val);
}
else if (note->readProperties(e))
;
else
Expand Down
69 changes: 69 additions & 0 deletions libmscore/read206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,75 @@ static void readNote(Note* note, XmlReader& e)
readAccidental(a, e);
note->add(a);
}
else if (tag == "head") {
int i = e.readInt();
NoteHead::Group val;
switch (i) {
case 1:
val = NoteHead::Group::HEAD_CROSS;
break;
case 2:
val = NoteHead::Group::HEAD_DIAMOND;
break;
case 3:
val = NoteHead::Group::HEAD_TRIANGLE;
break;
case 4:
val = NoteHead::Group::HEAD_MI;
break;
case 5:
val = NoteHead::Group::HEAD_SLASH;
break;
case 6:
val = NoteHead::Group::HEAD_XCIRCLE;
break;
case 7:
val = NoteHead::Group::HEAD_DO;
break;
case 8:
val = NoteHead::Group::HEAD_RE;
break;
case 9:
val = NoteHead::Group::HEAD_FA;
break;
case 10:
val = NoteHead::Group::HEAD_LA;
break;
case 11:
val = NoteHead::Group::HEAD_TI;
break;
case 12:
val = NoteHead::Group::HEAD_SOL;
break;
case 13:
val = NoteHead::Group::HEAD_BREVIS_ALT;
break;
default:
val = NoteHead::Group::HEAD_NORMAL;
}
note->setHeadGroup(val);
}
else if (tag == "headType") {
int i = e.readInt();
NoteHead::Type val;
switch (i) {
case 0:
val = NoteHead::Type::HEAD_WHOLE;
break;
case 1:
val = NoteHead::Type::HEAD_HALF;
break;
case 2:
val = NoteHead::Type::HEAD_QUARTER;
break;
case 3:
val = NoteHead::Type::HEAD_BREVIS;
break;
default:
val = NoteHead::Type::HEAD_AUTO;;
}
note->setHeadType(val);
}
else if (note->readProperties(e))
;
else
Expand Down
6 changes: 6 additions & 0 deletions libmscore/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,12 @@ void Xml::tag(P_ID id, QVariant data, QVariant defaultData)
case P_TYPE::BARLINE_TYPE:
tag(name, BarLine::barLineTypeName(BarLineType(data.toInt())));
break;
case P_TYPE::HEAD_GROUP:
tag(name, NoteHead::group2name(NoteHead::Group(data.toInt())));
break;
case P_TYPE::HEAD_TYPE:
tag(name, NoteHead::type2name(NoteHead::Type(data.toInt())));
break;
default:
Q_ASSERT(false);
}
Expand Down
Loading

0 comments on commit ffedbba

Please sign in to comment.