Skip to content

Commit

Permalink
fix #41291: Switching concert pitch when using transposing instrument…
Browse files Browse the repository at this point in the history
…s augments the keysignature on each line
  • Loading branch information
wschweer committed Dec 15, 2014
1 parent d31aa84 commit 567b73c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 88 deletions.
16 changes: 7 additions & 9 deletions libmscore/edit.cpp
Expand Up @@ -2351,7 +2351,7 @@ MeasureBase* Score::insertMeasure(Element::Type type, MeasureBase* measure, bool

if (tick == 0) {
//
// remove time and key signatures
// remove clef, time and key signatures
//
for (int staffIdx = 0; staffIdx < nstaves(); ++staffIdx) {
for (Segment* s = score->firstSegment(); s && s->tick() == 0; s = s->next()) {
Expand All @@ -2361,23 +2361,21 @@ MeasureBase* Score::insertMeasure(Element::Type type, MeasureBase* measure, bool
if (e->type() == Element::Type::KEYSIG) {
KeySig* ks = static_cast<KeySig*>(e);
ksl.append(ks);
undo(new RemoveElement(ks));
if (ks->segment()->isEmpty())
undoRemoveElement(ks->segment());
}
else if (e->type() == Element::Type::TIMESIG) {
TimeSig* ts = static_cast<TimeSig*>(e);
tsl.append(ts);
undo(new RemoveElement(ts));
if (ts->segment()->isEmpty())
undoRemoveElement(ts->segment());
}
else if (e->type() == Element::Type::CLEF) {
Clef* clef = static_cast<Clef*>(e);
cl.append(clef);
}
else
e = 0;
if (e) {
undo(new RemoveElement(e));
if (clef->segment()->isEmpty())
undoRemoveElement(clef->segment());
if (s->isEmpty())
undoRemoveElement(s);
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion libmscore/score.cpp
Expand Up @@ -1700,8 +1700,16 @@ Measure* Score::lastMeasureMM() const

Segment* Score::firstSegment(Segment::Type segType) const
{
Segment* seg;
Measure* m = firstMeasure();
Segment* seg = m ? m->first(segType) : 0;
if (!m)
seg = 0;
else {
seg = m->first();
if (seg && !(seg->segmentType() & segType))
seg = seg->next1(segType);
}

#ifdef SCRIPT_INTERFACE
// if called from QML/JS, tell QML engine not to garbage collect this object
if (seg)
Expand Down
19 changes: 15 additions & 4 deletions libmscore/transpose.cpp
Expand Up @@ -467,12 +467,23 @@ void Score::transposeKeys(int staffStart, int staffEnd, int tickStart, int tickE
if (s->tick() == 0)
createKey = false;
KeySig* ks = static_cast<KeySig*>(s->element(staffIdx * VOICES));
if (ks && !ks->isCustom()) {
if (!ks)
continue;
if (ks->generated())
continue;
if (!ks->isCustom()) {
Key key = st->key(s->tick());
Key nKey = transposeKey(key, interval);
KeySigEvent ke;
ke.setKey(nKey);
undo(new ChangeKeySig(ks, ke, ks->showCourtesy()));
if (nKey == Key::C) {
undo(new RemoveElement(ks));
if (s->isEmpty())
undo(new RemoveElement(s));
}
else {
KeySigEvent ke;
ke.setKey(nKey);
undo(new ChangeKeySig(ks, ke, ks->showCourtesy()));
}
}
}
if (createKey && firstMeasure()) {
Expand Down
14 changes: 7 additions & 7 deletions libmscore/undo.cpp
Expand Up @@ -470,7 +470,6 @@ void Score::undoChangeKeySig(Staff* ostaff, int tick, KeySigEvent key)
{
KeySig* lks = 0;
foreach (Staff* staff, ostaff->staffList()) {

if (staff->isDrumStaff())
continue;

Expand All @@ -485,11 +484,13 @@ void Score::undoChangeKeySig(Staff* ostaff, int tick, KeySigEvent key)
int track = staffIdx * VOICES;
KeySig* ks = static_cast<KeySig*>(s->element(track));

int diff = -staff->part()->instr()->transpose().chromatic;
Interval interval = staff->part()->instr()->transpose();
KeySigEvent nkey = key;
if (diff && !score->styleB(StyleIdx::concertPitch) && !nkey.custom())
nkey.setKey(transposeKey(key.key(), diff));

bool concertPitch = score->styleB(StyleIdx::concertPitch);
if (interval.chromatic && !concertPitch && !nkey.custom()) {
interval.flip();
nkey.setKey(transposeKey(key.key(), interval));
}
if (ks) {
ks->undoChangeProperty(P_ID::GENERATED, false);
undo(new ChangeKeySig(ks, nkey, ks->showCourtesy()));
Expand Down Expand Up @@ -2086,9 +2087,8 @@ void ChangeKeySig::flip()
keysig->setShowCourtesy(showCourtesy);
keysig->measure()->setDirty();

keysig->staff()->setKey(keysig->segment()->tick(), keysig->keySigEvent());

int tick = keysig->segment()->tick();

// update keys if keysig was not generated
if (!keysig->generated())
keysig->staff()->setKey(tick, ks);
Expand Down
1 change: 0 additions & 1 deletion mscore/debugger/debugger.cpp
Expand Up @@ -2470,7 +2470,6 @@ void KeySigView::setElement(Element* e)
KeySigEvent ev = ks->keySigEvent();
keysig.showCourtesySig->setChecked(ks->showCourtesy());
keysig.accidentalType->setValue(int(ev.key()));
// keysig.customType->setValue(ev.customType());
keysig.custom->setChecked(ev.custom());
keysig.invalid->setChecked(!ev.isValid());
}
Expand Down
14 changes: 0 additions & 14 deletions mscore/debugger/keysig.ui
Expand Up @@ -55,13 +55,6 @@
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label_10">
<property name="text">
<string notr="true">customType</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="accidentalType">
<property name="readOnly">
Expand Down Expand Up @@ -96,13 +89,6 @@
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QSpinBox" name="customType">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="showCourtesySig">
<property name="text">
Expand Down
64 changes: 15 additions & 49 deletions mscore/musescore.cpp
Expand Up @@ -2912,44 +2912,10 @@ void MuseScore::setPos(int t)
}

//---------------------------------------------------------
// undo
// undoRedo
//---------------------------------------------------------

void MuseScore::undo()
{
if (_sstate == STATE_EDIT
|| _sstate == STATE_LYRICS_EDIT
|| _sstate == STATE_HARMONY_FIGBASS_EDIT
|| _sstate == STATE_TEXT_EDIT) {
cv->postCmd("escape");
qApp->processEvents();
}
if (cv)
cv->startUndoRedo();
if (cs)
cs->undo()->undo();
if (cv) {
if (cs->inputState().segment())
setPos(cs->inputState().tick());
if (cs->noteEntryMode() && !cv->noteEntryMode()) {
// enter note entry mode
cv->postCmd("note-input");
}
else if (!cs->noteEntryMode() && cv->noteEntryMode()) {
// leave note entry mode
cv->postCmd("escape");
}
cs->endUndoRedo();
updateInputState(cs);
}
endCmd();
}

//---------------------------------------------------------
// redo
//---------------------------------------------------------

void MuseScore::redo()
void MuseScore::undoRedo(bool undo)
{
if (_sstate == STATE_EDIT
|| _sstate == STATE_TEXT_EDIT
Expand All @@ -2960,8 +2926,12 @@ void MuseScore::redo()
}
if (cv)
cv->startUndoRedo();
if (cs)
cs->undo()->redo();
if (cs) {
if (undo)
cs->undo()->undo();
else
cs->undo()->redo();
}
if (cv) {
if (cs->inputState().segment())
setPos(cs->inputState().tick());
Expand All @@ -2977,6 +2947,8 @@ void MuseScore::redo()
updateInputState(cs);
}
endCmd();
if (_inspector)
_inspector->reset();
}

//---------------------------------------------------------
Expand Down Expand Up @@ -3990,7 +3962,7 @@ void MuseScore::cmd(QAction* a, const QString& cmd)
showLayerManager();
else if (cmd == "backspace") {
if (_sstate != STATE_NORMAL )
undo();
undoRedo(true);
#ifdef Q_OS_MAC
else if (cs) {
cs->startCmd();
Expand All @@ -4005,16 +3977,10 @@ void MuseScore::cmd(QAction* a, const QString& cmd)
decMag();
else if (cmd == "midi-on")
midiinToggled(a->isChecked());
else if (cmd == "undo") {
undo();
if (_inspector)
_inspector->reset();
}
else if (cmd == "redo") {
redo();
if (_inspector)
_inspector->reset();
}
else if (cmd == "undo")
undoRedo(true);
else if (cmd == "redo")
undoRedo(false);
else if (cmd == "toggle-palette")
showPalette(a->isChecked());
else if (cmd == "startcenter")
Expand Down
3 changes: 1 addition & 2 deletions mscore/musescore.h
Expand Up @@ -387,8 +387,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
int pluginIdxFromPath(QString pluginPath);
void startDebugger();
void midiinToggled(bool);
void undo();
void redo();
void undoRedo(bool undo);
void showPalette(bool);
void showInspector(bool);
void showOmrPanel(bool);
Expand Down
2 changes: 1 addition & 1 deletion mtest/libmscore/parts/part-all-uinsertmeasures.mscx
Expand Up @@ -194,7 +194,7 @@
<Segment>
<subtype>0</subtype>
<off2 x="0" y="0"/>
<pos x="34.0159" y="6.60645"/>
<pos x="33.6127" y="6.60645"/>
</Segment>
</HairPin>
<Chord>
Expand Down

0 comments on commit 567b73c

Please sign in to comment.