Skip to content

Commit

Permalink
fix #44186: tpc calculated in wrong key with transposing instruments
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed Jan 12, 2015
1 parent e6839d7 commit a668ef0
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2142,14 +2142,16 @@ void Note::setNval(const NoteVal& nval, int tick)
_tpc[0] = nval.tpc1;
_tpc[1] = nval.tpc2;

Interval v = staff()->part()->instr()->transpose();
if (nval.tpc1 == Tpc::TPC_INVALID) {
if (tick == -1)
tick = chord()->tick();
Key key = staff()->key(tick);
if (!concertPitch() && !v.isZero())
key = transposeKey(key, v);
_tpc[0] = pitch2tpc(nval.pitch, key, Prefer::NEAREST);
}
if (nval.tpc2 == Tpc::TPC_INVALID) {
Interval v = staff()->part()->instr()->transpose();
if (v.isZero())
_tpc[1] = _tpc[0];
else {
Expand Down
137 changes: 137 additions & 0 deletions mtest/libmscore/note/tpc-transpose2-ref.mscx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<museScore version="2.00">
<Score>
<LayerTag id="0" tag="default"></LayerTag>
<currentLayer>0</currentLayer>
<Division>480</Division>
<Style>
<concertPitch>1</concertPitch>
<page-layout>
<page-height>1584</page-height>
<page-width>1224</page-width>
<page-margins type="even">
<left-margin>56.6929</left-margin>
<right-margin>90.1417</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>56.6929</left-margin>
<right-margin>90.1417</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
</page-layout>
<Spatium>1.76389</Spatium>
</Style>
<showInvisible>1</showInvisible>
<showUnprintable>1</showUnprintable>
<showFrames>1</showFrames>
<showMargins>0</showMargins>
<metaTag name="arranger"></metaTag>
<metaTag name="composer"></metaTag>
<metaTag name="copyright"></metaTag>
<metaTag name="lyricist"></metaTag>
<metaTag name="movementNumber"></metaTag>
<metaTag name="movementTitle"></metaTag>
<metaTag name="poet"></metaTag>
<metaTag name="source"></metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle"></metaTag>
<PageList>
<Page>
<System>
</System>
</Page>
</PageList>
<Part>
<Staff id="1">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<bracket type="-1" span="0"/>
</Staff>
<trackName>Alto Saxophone</trackName>
<Instrument>
<longName pos="0">Alto Saxophone</longName>
<shortName pos="0">A. Sax.</shortName>
<trackName>Alto Saxophone</trackName>
<minPitchP>49</minPitchP>
<maxPitchP>87</maxPitchP>
<minPitchA>49</minPitchA>
<maxPitchA>82</maxPitchA>
<transposeDiatonic>-5</transposeDiatonic>
<transposeChromatic>-9</transposeChromatic>
<instrumentId>wind.reed.saxophone.alto</instrumentId>
<Articulation>
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="staccatissimo">
<velocity>100</velocity>
<gateTime>33</gateTime>
</Articulation>
<Articulation name="staccato">
<velocity>100</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="portato">
<velocity>100</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="tenuto">
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="marcato">
<velocity>120</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="sforzato">
<velocity>120</velocity>
<gateTime>100</gateTime>
</Articulation>
<Channel>
<program value="65"/>
</Channel>
</Instrument>
</Part>
<Staff id="1">
<Measure number="1">
<KeySig>
<accidental>-3</accidental>
</KeySig>
<TimeSig>
<sigN>4</sigN>
<sigD>4</sigD>
<showCourtesySig>1</showCourtesySig>
</TimeSig>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>56</pitch>
<tpc>10</tpc>
<tpc2>13</tpc2>
</Note>
</Chord>
<Rest>
<durationType>quarter</durationType>
</Rest>
<Rest>
<durationType>half</durationType>
</Rest>
</Measure>
<Measure number="2">
<Rest>
<durationType>measure</durationType>
<duration z="4" n="4"/>
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</Measure>
</Staff>
</Score>
</museScore>
126 changes: 126 additions & 0 deletions mtest/libmscore/note/tpc-transpose2.mscx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<museScore version="2.00">
<Score>
<LayerTag id="0" tag="default"></LayerTag>
<currentLayer>0</currentLayer>
<Division>480</Division>
<Style>
<page-layout>
<page-height>1584</page-height>
<page-width>1224</page-width>
<page-margins type="even">
<left-margin>56.6929</left-margin>
<right-margin>90.1417</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>56.6929</left-margin>
<right-margin>90.1417</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
</page-layout>
<Spatium>1.76389</Spatium>
</Style>
<showInvisible>1</showInvisible>
<showUnprintable>1</showUnprintable>
<showFrames>1</showFrames>
<showMargins>0</showMargins>
<metaTag name="arranger"></metaTag>
<metaTag name="composer"></metaTag>
<metaTag name="copyright"></metaTag>
<metaTag name="lyricist"></metaTag>
<metaTag name="movementNumber"></metaTag>
<metaTag name="movementTitle"></metaTag>
<metaTag name="poet"></metaTag>
<metaTag name="source"></metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle"></metaTag>
<PageList>
<Page>
<System>
</System>
</Page>
</PageList>
<Part>
<Staff id="1">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
<bracket type="-1" span="0"/>
</Staff>
<trackName>Alto Saxophone</trackName>
<Instrument>
<longName pos="0">Alto Saxophone</longName>
<shortName pos="0">A. Sax.</shortName>
<trackName>Alto Saxophone</trackName>
<minPitchP>49</minPitchP>
<maxPitchP>87</maxPitchP>
<minPitchA>49</minPitchA>
<maxPitchA>82</maxPitchA>
<transposeDiatonic>-5</transposeDiatonic>
<transposeChromatic>-9</transposeChromatic>
<instrumentId>wind.reed.saxophone.alto</instrumentId>
<Articulation>
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="staccatissimo">
<velocity>100</velocity>
<gateTime>33</gateTime>
</Articulation>
<Articulation name="staccato">
<velocity>100</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="portato">
<velocity>100</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="tenuto">
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="marcato">
<velocity>120</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="sforzato">
<velocity>120</velocity>
<gateTime>100</gateTime>
</Articulation>
<Channel>
<program value="65"/>
</Channel>
</Instrument>
</Part>
<Staff id="1">
<Measure number="1">
<KeySig>
<accidental>0</accidental>
</KeySig>
<TimeSig>
<sigN>4</sigN>
<sigD>4</sigD>
<showCourtesySig>1</showCourtesySig>
</TimeSig>
<Rest>
<durationType>measure</durationType>
<duration z="4" n="4"/>
</Rest>
</Measure>
<Measure number="2">
<Rest>
<durationType>measure</durationType>
<duration z="4" n="4"/>
</Rest>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</Measure>
</Staff>
</Score>
</museScore>
23 changes: 23 additions & 0 deletions mtest/libmscore/note/tst_note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TestNote : public QObject, public MTest
void grace();
void tpc();
void tpcTranspose();
void tpcTranspose2();
};

//---------------------------------------------------------
Expand Down Expand Up @@ -418,6 +419,28 @@ void TestNote::tpcTranspose()

}

//---------------------------------------------------------
/// tpcTranspose2
/// more tests of note tpc values & transposition
//---------------------------------------------------------

void TestNote::tpcTranspose2() {
Score* score = readScore(DIR + "tpc-transpose2.mscx");
score->doLayout();

score->inputState().setTrack(0);
score->inputState().setSegment(score->tick2segment(0, false, Segment::Type::ChordRest));
score->inputState().setDuration(TDuration::DurationType::V_QUARTER);
score->inputState().setNoteEntryMode(true);
int octave = 5 * 7;
score->cmdAddPitch(octave + 3, false);

score->cmdConcertPitchChanged(true, true);

QVERIFY(saveCompareScore(score, "tpc-transpose2-test.mscx", DIR + "tpc-transpose2-ref.mscx"));

}

QTEST_MAIN(TestNote)

#include "tst_note.moc"
Expand Down

0 comments on commit a668ef0

Please sign in to comment.