Skip to content

Commit a6a6d33

Browse files
Honor an explicit dynamics="0" on MusicXML note import
Backport of musescore#33804 Co-Authored-By: Jonas Högström <jonas.hogstrom@pobox.com>
1 parent 5a8c3d7 commit a6a6d33

4 files changed

Lines changed: 234 additions & 2 deletions

File tree

importexport/musicxml/importmxmlpass2.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6363,7 +6363,11 @@ Note* MusicXMLParserPass2::note(const QString& partId,
63636363
QColor beamColor = QColor::Invalid;
63646364
bool noteheadParentheses = false;
63656365
QString noteheadFilled;
6366-
int velocity = round(_e.attributes().value("dynamics").toDouble() * 0.9);
6366+
// velocity as a percentage of the MIDI 1.0 default forte value of 90;
6367+
// an explicit dynamics="0" means a silent note, which the score model can
6368+
// only represent as velocity 1 (velocity 0 means "unset")
6369+
const bool hasDynamics = _e.attributes().hasAttribute("dynamics");
6370+
const int velocity = std::clamp(int(round(_e.attributes().value("dynamics").toDouble() * 0.9)), 1, 127);
63676371
bool graceSlash = false;
63686372
bool printObject = _e.attributes().value("print-object") != "no";
63696373
bool printLyric = (printObject && _e.attributes().value("print-lyric") != "no") ||_e.attributes().value("print-lyric") == "yes";
@@ -6690,7 +6694,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
66906694
c->setPlayEventType(PlayEventType::User);
66916695
}
66926696

6693-
if (velocity > 0) {
6697+
if (hasDynamics) {
66946698
note->setVeloType(Note::ValueType::USER_VAL);
66956699
note->setVeloOffset(velocity);
66966700
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<score-partwise version="4.0">
3+
<movement-title>Note dynamics attribute</movement-title>
4+
<part-list>
5+
<score-part id="P1">
6+
<part-name>Voice</part-name>
7+
</score-part>
8+
</part-list>
9+
<part id="P1">
10+
<measure number="1">
11+
<attributes>
12+
<divisions>480</divisions>
13+
<key>
14+
<fifths>0</fifths>
15+
</key>
16+
<time>
17+
<beats>5</beats>
18+
<beat-type>4</beat-type>
19+
</time>
20+
<clef>
21+
<sign>G</sign>
22+
<line>2</line>
23+
</clef>
24+
</attributes>
25+
<note>
26+
<pitch>
27+
<step>C</step>
28+
<octave>4</octave>
29+
</pitch>
30+
<duration>480</duration>
31+
<voice>1</voice>
32+
<type>quarter</type>
33+
</note>
34+
<note dynamics="0">
35+
<pitch>
36+
<step>D</step>
37+
<octave>4</octave>
38+
</pitch>
39+
<duration>480</duration>
40+
<voice>1</voice>
41+
<type>quarter</type>
42+
<notehead>x</notehead>
43+
</note>
44+
<note dynamics="50">
45+
<pitch>
46+
<step>E</step>
47+
<octave>4</octave>
48+
</pitch>
49+
<duration>480</duration>
50+
<voice>1</voice>
51+
<type>quarter</type>
52+
</note>
53+
<note dynamics="200">
54+
<pitch>
55+
<step>F</step>
56+
<octave>4</octave>
57+
</pitch>
58+
<duration>480</duration>
59+
<voice>1</voice>
60+
<type>quarter</type>
61+
</note>
62+
<note>
63+
<pitch>
64+
<step>G</step>
65+
<octave>4</octave>
66+
</pitch>
67+
<duration>480</duration>
68+
<voice>1</voice>
69+
<type>quarter</type>
70+
</note>
71+
</measure>
72+
</part>
73+
</score-partwise>
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<museScore version="3.02">
3+
<Score>
4+
<LayerTag id="0" tag="default"></LayerTag>
5+
<currentLayer>0</currentLayer>
6+
<Division>480</Division>
7+
<Style>
8+
<measureSpacing>1</measureSpacing>
9+
<hideEmptyStaves>1</hideEmptyStaves>
10+
<dontHidStavesInFirstSystm>0</dontHidStavesInFirstSystm>
11+
<hideInstrumentNameIfOneInstrument>0</hideInstrumentNameIfOneInstrument>
12+
<subTitleFontSize>14</subTitleFontSize>
13+
<Spatium>1.74978</Spatium>
14+
</Style>
15+
<showInvisible>1</showInvisible>
16+
<showUnprintable>1</showUnprintable>
17+
<showFrames>1</showFrames>
18+
<showMargins>0</showMargins>
19+
<metaTag name="arranger"></metaTag>
20+
<metaTag name="composer"></metaTag>
21+
<metaTag name="copyright"></metaTag>
22+
<metaTag name="lyricist"></metaTag>
23+
<metaTag name="movementNumber"></metaTag>
24+
<metaTag name="movementTitle">Note dynamics attribute</metaTag>
25+
<metaTag name="originalFormat">xml</metaTag>
26+
<metaTag name="poet"></metaTag>
27+
<metaTag name="source"></metaTag>
28+
<metaTag name="translator"></metaTag>
29+
<metaTag name="workNumber"></metaTag>
30+
<metaTag name="workTitle"></metaTag>
31+
<Part>
32+
<Staff id="1">
33+
<StaffType group="pitched">
34+
<name>stdNormal</name>
35+
</StaffType>
36+
<hideWhenEmpty>3</hideWhenEmpty>
37+
</Staff>
38+
<trackName>Voice</trackName>
39+
<Instrument>
40+
<longName>Voice</longName>
41+
<trackName></trackName>
42+
<Articulation>
43+
<velocity>100</velocity>
44+
<gateTime>100</gateTime>
45+
</Articulation>
46+
<Articulation name="staccatissimo">
47+
<velocity>100</velocity>
48+
<gateTime>33</gateTime>
49+
</Articulation>
50+
<Articulation name="staccato">
51+
<velocity>100</velocity>
52+
<gateTime>50</gateTime>
53+
</Articulation>
54+
<Articulation name="portato">
55+
<velocity>100</velocity>
56+
<gateTime>67</gateTime>
57+
</Articulation>
58+
<Articulation name="tenuto">
59+
<velocity>100</velocity>
60+
<gateTime>100</gateTime>
61+
</Articulation>
62+
<Articulation name="marcato">
63+
<velocity>120</velocity>
64+
<gateTime>67</gateTime>
65+
</Articulation>
66+
<Articulation name="sforzato">
67+
<velocity>150</velocity>
68+
<gateTime>100</gateTime>
69+
</Articulation>
70+
<Articulation name="sforzatoStaccato">
71+
<velocity>150</velocity>
72+
<gateTime>50</gateTime>
73+
</Articulation>
74+
<Articulation name="marcatoStaccato">
75+
<velocity>120</velocity>
76+
<gateTime>50</gateTime>
77+
</Articulation>
78+
<Articulation name="marcatoTenuto">
79+
<velocity>120</velocity>
80+
<gateTime>100</gateTime>
81+
</Articulation>
82+
<Channel>
83+
<program value="0"/>
84+
<controller ctrl="10" value="63"/>
85+
</Channel>
86+
</Instrument>
87+
</Part>
88+
<Staff id="1">
89+
<VBox>
90+
<height>10</height>
91+
<Text>
92+
<style>Title</style>
93+
<text>Note dynamics attribute</text>
94+
</Text>
95+
</VBox>
96+
<Measure>
97+
<voice>
98+
<Clef>
99+
<concertClefType>G</concertClefType>
100+
<transposingClefType>G</transposingClefType>
101+
</Clef>
102+
<TimeSig>
103+
<sigN>5</sigN>
104+
<sigD>4</sigD>
105+
</TimeSig>
106+
<Chord>
107+
<durationType>quarter</durationType>
108+
<Note>
109+
<pitch>60</pitch>
110+
<tpc>14</tpc>
111+
</Note>
112+
</Chord>
113+
<Chord>
114+
<durationType>quarter</durationType>
115+
<Note>
116+
<pitch>62</pitch>
117+
<tpc>16</tpc>
118+
<head>cross</head>
119+
<velocity>1</velocity>
120+
<veloType>user</veloType>
121+
</Note>
122+
</Chord>
123+
<Chord>
124+
<durationType>quarter</durationType>
125+
<Note>
126+
<pitch>64</pitch>
127+
<tpc>18</tpc>
128+
<velocity>45</velocity>
129+
<veloType>user</veloType>
130+
</Note>
131+
</Chord>
132+
<Chord>
133+
<durationType>quarter</durationType>
134+
<Note>
135+
<pitch>65</pitch>
136+
<tpc>13</tpc>
137+
<velocity>127</velocity>
138+
<veloType>user</veloType>
139+
</Note>
140+
</Chord>
141+
<Chord>
142+
<durationType>quarter</durationType>
143+
<Note>
144+
<pitch>67</pitch>
145+
<tpc>15</tpc>
146+
</Note>
147+
</Chord>
148+
<BarLine>
149+
</BarLine>
150+
</voice>
151+
</Measure>
152+
</Staff>
153+
</Score>
154+
</museScore>

mtest/musicxml/io/tst_mxml_io.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ private slots:
255255
void noteAttributes2io() { mxmlIoTestRef("testNoteAttributes2"); }
256256
void noteAttributes3() { mxmlIoTest("testNoteAttributes3"); }
257257
void noteColor() { mxmlIoTest("testNoteColor"); }
258+
void noteDynamics() { mxmlImportTestRef("testNoteDynamics"); }
258259
void noteheadNames() { mxmlIoTest("testNoteheadNames"); }
259260
void noteheadParentheses() { mxmlIoTest("testNoteheadParentheses"); }
260261
void noteheads() { mxmlIoTest("testNoteheads"); }

0 commit comments

Comments
 (0)