Skip to content

Commit

Permalink
Fix GH#22313: Set correct stem direction on pasting notes on drum staff
Browse files Browse the repository at this point in the history
Backport of musescore#22575

Plus some includes cleanup
Plus an entirely unrelated debug message fix
  • Loading branch information
miiizen authored and Jojo-Schmitz committed May 14, 2024
1 parent 3f00793 commit b391a7e
Show file tree
Hide file tree
Showing 10 changed files with 948 additions and 93 deletions.
101 changes: 49 additions & 52 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,56 @@
Handling of several GUI commands.
*/

#include <assert.h>

#include "types.h"
#include "musescoreCore.h"
#include "score.h"
#include "utils.h"
#include "key.h"
#include "accidental.h"
#include "articulation.h"
#include "barline.h"
#include "beam.h"
#include "box.h"
#include "chord.h"
#include "chordlist.h"
#include "clef.h"
#include "drumset.h"
#include "dynamic.h"
#include "hairpin.h"
#include "harmony.h"
#include "key.h"
#include "keysig.h"
#include "lyrics.h"
#include "measure.h"
#include "mscore.h"
#include "musescoreCore.h"
#include "navigate.h"
#include "slur.h"
#include "tie.h"
#include "note.h"
#include "noteevent.h"
#include "ottava.h"
#include "page.h"
#include "part.h"
#include "pitchspelling.h"
#include "rehearsalmark.h"
#include "repeat.h"
#include "rest.h"
#include "chord.h"
#include "text.h"
#include "score.h"
#include "segment.h"
#include "sequencer.h"
#include "sig.h"
#include "slur.h"
#include "staff.h"
#include "part.h"
#include "stafftype.h"
#include "stringdata.h"
#include "style.h"
#include "page.h"
#include "barline.h"
#include "tuplet.h"
#include "xml.h"
#include "ottava.h"
#include "trill.h"
#include "pedal.h"
#include "hairpin.h"
#include "textline.h"
#include "keysig.h"
#include "volta.h"
#include "dynamic.h"
#include "box.h"
#include "harmony.h"
#include "sym.h"
#include "system.h"
#include "stafftext.h"
#include "articulation.h"
#include "layoutbreak.h"
#include "drumset.h"
#include "beam.h"
#include "lyrics.h"
#include "pitchspelling.h"
#include "measure.h"
#include "tempo.h"
#include "undo.h"
#include "tie.h"
#include "timesig.h"
#include "repeat.h"
#include "tempotext.h"
#include "noteevent.h"
#include "breath.h"
#include "stringdata.h"
#include "stafftype.h"
#include "segment.h"
#include "chordlist.h"
#include "mscore.h"
#include "accidental.h"
#include "sequencer.h"
#include "tremolo.h"
#include "rehearsalmark.h"
#include "sym.h"
#include "trill.h"
#include "tuplet.h"
#include "types.h"
#include "undo.h"
#include "utils.h"
#include "volta.h"
#include "xml.h"

namespace Ms {

Expand Down Expand Up @@ -1382,10 +1373,16 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest)
Fraction f = dstF;
ChordRest* cr1 = cr;
Chord* oc = 0;
Segment* s = cr->segment();

bool first = true;
Fraction totalLen = cr->rtick() + f;
for (Fraction f2 : qAsConst(flist)) {
for (const Fraction& f2 : flist) {
if (!cr1) {
expandVoice(s, track);
cr1 = toChordRest(s->element(track));
}

f -= f2;
if (totalLen.reduced() > Fraction(1, 1)) {
if (auto nm = cr1->measure()->nextMeasure()) {
Expand Down Expand Up @@ -1469,11 +1466,11 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest)
}
}
}
Measure* m = cr1->measure();
Measure* m1 = m->nextMeasure();
const Measure* m = cr1->measure();
const Measure* m1 = m->nextMeasure();
if (!m1)
break;
Segment* s = m1->first(SegmentType::ChordRest);
s = m1->first(SegmentType::ChordRest);
cr1 = toChordRest(s->element(track));
if (!cr1)
break;
Expand Down
1 change: 1 addition & 0 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ Chord* Score::addChord(const Fraction& tick, TDuration d, Chord* oc, bool genTie
chord->setTrack(oc->track());
chord->setDurationType(d);
chord->setTicks(d.fraction());
chord->setStemDirection(oc->stemDirection());

for (Note* n : oc->notes()) {
Note* nn = new Note(this);
Expand Down
10 changes: 10 additions & 0 deletions libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,7 @@ Element* Note::drop(EditData& data)
{
// calculate correct transposed tpc
Note* n = toNote(e);
const Segment* segment = ch->segment();
Interval v = part()->instrument(ch->tick())->transpose();
v.flip();
n->setTpc2(Ms::transposeTpc(n->tpc1(), v, true));
Expand All @@ -1868,6 +1869,15 @@ Element* Note::drop(EditData& data)
n->tieBack()->setEndNote(n);
this->setTieBack(nullptr);
}
// Set correct stem direction for drum staves
const StaffGroup staffGroup = st->staffType(segment->tick())->group();
Direction stemDirection = Direction::AUTO;
if (staffGroup == StaffGroup::PERCUSSION) {
const Drumset* ds = st->part()->instrument(segment->tick())->drumset();
stemDirection = ds->stemDirection(n->noteVal().pitch);
}
ch->setStemDirection(stemDirection);

score()->undoRemoveElement(this);
score()->undoAddElement(n);
return n;
Expand Down
45 changes: 26 additions & 19 deletions libmscore/paste.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,30 @@
// the file LICENCE.GPL
//=============================================================================

#include "score.h"

#include "rest.h"
#include "staff.h"
#include "measure.h"
#include "harmony.h"
#include "fret.h"
#include "breath.h"
#include "articulation.h"
#include "beam.h"
#include "breath.h"
#include "chord.h"
#include "drumset.h"
#include "figuredbass.h"
#include "ottava.h"
#include "part.h"
#include "lyrics.h"
#include "fret.h"
#include "hairpin.h"
#include "harmony.h"
#include "image.h"
#include "lyrics.h"
#include "measure.h"
#include "part.h"
#include "repeat.h"
#include "rest.h"
#include "score.h"
#include "sig.h"
#include "staff.h"
#include "tie.h"
#include "timesig.h"
#include "tremolo.h"
#include "tuplet.h"
#include "utils.h"
#include "xml.h"
#include "image.h"
#include "repeat.h"
#include "chord.h"
#include "tremolo.h"
#include "slur.h"
#include "articulation.h"
#include "sig.h"

namespace Ms {

Expand Down Expand Up @@ -1011,8 +1009,17 @@ static Note* prepareTarget(ChordRest* target, Note* with, const Fraction& durati
Measure* m = segment->measure()->mmRestFirst();
segment = m->findSegment(SegmentType::ChordRest, m->tick());
}

const Staff* staff = target->staff();
const StaffGroup staffGroup = staff->staffType(segment->tick())->group();
Direction stemDirection = Direction::AUTO;
if (staffGroup == StaffGroup::PERCUSSION) {
const Drumset* ds = staff->part()->instrument(segment->tick())->drumset();
stemDirection = ds->stemDirection(with->noteVal().pitch);
}

segment = target->score()->setNoteRest(segment, target->track(),
with->noteVal(), duration, Direction::AUTO, false, false, &target->score()->inputState());
with->noteVal(), duration, stemDirection, false, false, &target->score()->inputState());
return toChord(segment->nextChordRest(target->track()))->upNote();
}

Expand Down
12 changes: 6 additions & 6 deletions libmscore/sym.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
// the file LICENCE.GPL
//=============================================================================

#include <QDirIterator>

#include "mscore.h"
#include "score.h"
#include "style.h"
#include "sym.h"
#include "utils.h"
#include "score.h"
#include "xml.h"
#include "mscore.h"

#include "mscore/preferences.h"

#include <QDirIterator>

#include FT_GLYPH_H
#include FT_IMAGE_H
Expand Down Expand Up @@ -6655,7 +6655,7 @@ void ScoreFont::scanUserFonts(const QString& path, bool system)
}


qDebug() << "Found" << userfonts.count() << (system ? "system" : "user") << "score fonts in" << path <<".";
qDebug() << "Found" << userfonts.count() << (system ? "system" : "user") << "score font" << (userfonts.count() > 1? "s" : "") << " in" << path <<".";

// TODO: Check for fonts that duplicate built-in fonts
if (!system) // reset list when re-reading due to changed Preferences
Expand Down

0 comments on commit b391a7e

Please sign in to comment.