Skip to content

Commit

Permalink
Fix GH#22080: Detect anacrusis when beaming
Browse files Browse the repository at this point in the history
Backport of musescore#22083

Along with fixing some code warnings from QtCreator
  • Loading branch information
XiaoMigros authored and Jojo-Schmitz committed Aug 28, 2024
1 parent 8a09536 commit 0f5697c
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 71 deletions.
7 changes: 3 additions & 4 deletions libmscore/durationtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
//=============================================================================

#include "durationtype.h"
#include "mscore.h"
#include "measure.h"
#include "note.h"
#include "sig.h"
#include "measure.h"

namespace Ms {

Expand Down Expand Up @@ -538,9 +537,9 @@ std::vector<TDuration> toRhythmicDurationList(const Fraction& l, bool isRest, Fr
}

if (nominal.isCompound())
splitCompoundBeatsForList(&dList, l, isRest, rtickStart, nominal, maxDots);
splitCompoundBeatsForList(&dList, l, isRest, rtickStart + msr->anacrusisOffset(), nominal, maxDots);
else
populateRhythmicList(&dList, l, isRest, rtickStart, nominal, maxDots);
populateRhythmicList(&dList, l, isRest, rtickStart + msr->anacrusisOffset(), nominal, maxDots);

return dList;
}
Expand Down
6 changes: 3 additions & 3 deletions libmscore/groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
// the file LICENCE.GPL
//=============================================================================

#include "groups.h"
#include "durationtype.h"
#include "chordrest.h"
#include "groups.h"
#include "measure.h"
#include "staff.h"
#include "tuplet.h"
#include "xml.h"

namespace Ms {
Expand Down Expand Up @@ -81,7 +81,7 @@ Beam::Mode Groups::endBeam(ChordRest* cr, ChordRest* prev)
TDuration d = cr->durationType();
const Groups& g = cr->staff()->group(cr->tick());
Fraction stretch = cr->staff()->timeStretch(cr->tick());
Fraction tick = cr->rtick() * stretch;
Fraction tick = cr->rtick() * stretch + cr->measure()->anacrusisOffset();;

Beam::Mode val = g.beamMode(tick.ticks(), d.type());

Expand Down
25 changes: 23 additions & 2 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2586,8 +2586,18 @@ bool Measure::isFinalMeasureOfSection() const

bool Measure::isAnacrusis() const
{
TimeSigFrac timeSig = score()->sigmap()->timesig(tick().ticks()).nominal();
return irregular() && ticks() < Fraction::fromTicks(timeSig.ticksPerMeasure());
const MeasureBase* pm = prev();
ElementType pt = pm ? pm->type() : ElementType::INVALID;

if (irregular() || !pm
|| pm->lineBreak() || pm->pageBreak() || pm->sectionBreak()
|| pt == ElementType::VBOX || pt == ElementType::HBOX
|| pt == ElementType::FBOX || pt == ElementType::TBOX) {
if (timesig() - ticks() > Fraction(0, 1)) {
return true;
}
}
return false;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -3703,6 +3713,17 @@ Fraction Measure::computeTicks()
return minTick;
}

//---------------------------------------------------------
// anacrusisOffset
// determine if measure is anacrusis
// and return tick offset relative to measure end
//---------------------------------------------------------

Fraction Measure::anacrusisOffset() const
{
return isAnacrusis() ? (timesig() - ticks()) : Fraction(0, 1);
}

//---------------------------------------------------------
// endBarLine
// return the first one
Expand Down
9 changes: 5 additions & 4 deletions libmscore/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
Definition of class Measure.
*/

#include "measurebase.h"
#include "fraction.h"
#include "measurebase.h"
#include "segmentlist.h"

namespace Ms {
Expand Down Expand Up @@ -103,10 +103,10 @@ class Measure final : public MeasureBase {
Measure* cloneMeasure(Score*, const Fraction& tick, TieMap*);

void read(XmlReader&, int idx);
void read(XmlReader& d) { read(d, 0); }
void read(XmlReader& d) override { read(d, 0); }
void readAddConnector(ConnectorInfoReader* info, bool pasteMode) override;
void write(XmlWriter& xml) const override { Element::write(xml); }
void write(XmlWriter&, int, bool writeSystemElements, bool forceTimeSig) const;
void write(XmlWriter&, int, bool writeSystemElements, bool forceTimeSig) const override;
void writeBox(XmlWriter&) const;
void readBox(XmlReader&);
bool isEditable() const override { return false; }
Expand Down Expand Up @@ -160,6 +160,7 @@ class Measure final : public MeasureBase {

void stretchMeasure(qreal stretch);
Fraction computeTicks();
Fraction anacrusisOffset() const;
void layout2();

bool showsMeasureNumber();
Expand Down Expand Up @@ -278,7 +279,7 @@ class Measure final : public MeasureBase {
qreal basicStretch() const;
qreal basicWidth() const;
int layoutWeight(int maxMMRestLength = 0) const;
void computeMinWidth();
void computeMinWidth() override;
void checkHeader();
void checkTrailer();
void setStretchedWidth(qreal);
Expand Down
69 changes: 28 additions & 41 deletions libmscore/rendermidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,45 @@

#include <set>

#include "rendermidi.h"
#include "score.h"
#include "volta.h"
#include "note.h"
#include "arpeggio.h"
#include "articulation.h"
#include "bend.h"
#include "changeMap.h"
#include "chord.h"
#include "durationtype.h"
#include "dynamic.h"
#include "easeInOut.h"
#include "glissando.h"
#include "hairpin.h"
#include "instrument.h"
#include "measure.h"
#include "navigate.h"
#include "note.h"
#include "noteevent.h"
#include "part.h"
#include "chord.h"
#include "trill.h"
#include "vibrato.h"
#include "style.h"
#include "slur.h"
#include "tie.h"
#include "stafftext.h"
#include "rendermidi.h"
#include "repeat.h"
#include "articulation.h"
#include "arpeggio.h"
#include "durationtype.h"
#include "measure.h"
#include "tempo.h"
#include "repeatlist.h"
#include "changeMap.h"
#include "dynamic.h"
#include "navigate.h"
#include "pedal.h"
#include "score.h"
#include "segment.h"
#include "slur.h"
#include "staff.h"
#include "hairpin.h"
#include "bend.h"
#include "stafftextbase.h"
#include "style.h"
#include "sym.h"
#include "synthesizerstate.h"
#include "tempo.h"
#include "tie.h"
#include "tremolo.h"
#include "noteevent.h"
#include "segment.h"
#include "trill.h"
#include "undo.h"
#include "utils.h"
#include "sym.h"
#include "synthesizerstate.h"
#include "easeInOut.h"
#include "vibrato.h"
#include "volta.h"

#include "global/log.h"

#include "audio/midi/event.h"
#include "mscore/preferences.h"

namespace Ms {

Expand Down Expand Up @@ -1190,19 +1189,7 @@ void MidiRenderer::renderSpanners(const Chunk& chunk, EventMap* events)

void Score::swingAdjustParams(Chord* chord, int& gateTime, int& ontime, int swingUnit, int swingRatio)
{
Fraction tick = chord->rtick();
// adjust for anacrusis
Measure* cm = chord->measure();
MeasureBase* pm = cm->prev();
ElementType pt = pm ? pm->type() : ElementType::INVALID;
if (!pm || pm->lineBreak() || pm->pageBreak() || pm->sectionBreak()
|| pt == ElementType::VBOX || pt == ElementType::HBOX
|| pt == ElementType::FBOX || pt == ElementType::TBOX) {
Fraction offset = cm->timesig() - cm->ticks();
if (offset > Fraction(0,1)) {
tick += offset;
}
}
Fraction tick = chord->rtick() + chord->measure()->anacrusisOffset();

int swingBeat = swingUnit * 2;
qreal ticksDuration = (qreal)chord->actualTicks().ticks();
Expand Down
20 changes: 11 additions & 9 deletions mscore/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include "palette.h"
#include "playpanel.h"
#include "preferences.h"
#include "scoretab.h"
#include "scorePreview.h"
#include "scoretab.h"
#include "scoreview.h"
#include "seq.h"
#include "svggenerator.h"
Expand Down Expand Up @@ -59,8 +59,8 @@
#include "libmscore/repeatlist.h"
#include "libmscore/rest.h"
#include "libmscore/score.h"
#include "libmscore/select.h"
#include "libmscore/segment.h"
#include "libmscore/select.h"
#include "libmscore/sig.h"
#include "libmscore/staff.h"
#include "libmscore/stafflines.h"
Expand All @@ -76,18 +76,18 @@
#include "libmscore/utils.h"
#include "libmscore/xml.h"

#include "migration/handlers/edwinstylehandler.h"
#include "migration/handlers/lelandstylehandler.h"
#include "migration/handlers/resetallelementspositionshandler.h"
#include "migration/handlers/styledefaultshandler.h"
#include "migration/scoremigrator_3_6.h"

#ifdef OMR
#include "omr/importpdf.h"
#include "omr/omr.h"
#include "omr/omrpage.h"
#endif

#include "migration/scoremigrator_3_6.h"
#include "migration/handlers/styledefaultshandler.h"
#include "migration/handlers/lelandstylehandler.h"
#include "migration/handlers/edwinstylehandler.h"
#include "migration/handlers/resetallelementspositionshandler.h"

#include "scorecmp/scorecmp.h"

#include "thirdparty/qzip/qzipreader_p.h"
Expand Down Expand Up @@ -797,7 +797,9 @@ MasterScore* MuseScore::getNewFile()
if (measure->timesig() != measure->ticks()) {
if (!linkedToPrevious)
puRests.clear();
std::vector<TDuration> dList = toDurationList(measure->ticks(), false);
std::vector<TDuration> dList = toRhythmicDurationList(
measure->ticks(), true, Fraction(0, 1),
measure->score()->sigmap()->timesig(measure->tick().ticks()).nominal(), measure, 0);
if (!dList.empty()) {
Fraction ltick = tick;
int k = 0;
Expand Down
9 changes: 3 additions & 6 deletions mtest/libmscore/midi/testSwingPickup-ref.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Tick = 0 Type = 176 Pitch = 2 Velocity = 80 Channel = 0
Tick = 0 Type = 3 Pitch = 0 Velocity = 127 Channel = 0
Tick = 48 Type = 144 Pitch = 67 Velocity = 80 Channel = 0
Tick = 239 Type = 144 Pitch = 67 Velocity = 0 Channel = 0
Tick = 240 Type = 144 Pitch = 69 Velocity = 80 Channel = 0
Tick = 480 Type = 4 Pitch = 0 Velocity = 80 Channel = 0
Tick = 240 Type = 4 Pitch = 0 Velocity = 80 Channel = 0
Tick = 527 Type = 144 Pitch = 69 Velocity = 0 Channel = 0
Tick = 528 Type = 144 Pitch = 71 Velocity = 80 Channel = 0
Tick = 719 Type = 144 Pitch = 71 Velocity = 0 Channel = 0
Expand All @@ -19,7 +18,6 @@ Tick = 1488 Type = 144 Pitch = 79 Velocity = 80 Channel =
Tick = 1679 Type = 144 Pitch = 79 Velocity = 0 Channel = 0
Tick = 1680 Type = 4 Pitch = 0 Velocity = 127 Channel = 0
Tick = 2160 Type = 4 Pitch = 0 Velocity = 80 Channel = 0
Tick = 2400 Type = 3 Pitch = 0 Velocity = 127 Channel = 0
Tick = 2448 Type = 144 Pitch = 71 Velocity = 80 Channel = 0
Tick = 2639 Type = 144 Pitch = 71 Velocity = 0 Channel = 0
Tick = 2640 Type = 144 Pitch = 72 Velocity = 80 Channel = 0
Expand All @@ -33,16 +31,15 @@ Tick = 3407 Type = 144 Pitch = 72 Velocity = 0 Channel =
Tick = 3408 Type = 144 Pitch = 76 Velocity = 80 Channel = 0
Tick = 3599 Type = 144 Pitch = 76 Velocity = 0 Channel = 0
Tick = 3600 Type = 4 Pitch = 0 Velocity = 127 Channel = 0
Tick = 3840 Type = 3 Pitch = 0 Velocity = 127 Channel = 0
Tick = 3888 Type = 144 Pitch = 67 Velocity = 80 Channel = 0
Tick = 4079 Type = 144 Pitch = 67 Velocity = 0 Channel = 0
Tick = 4080 Type = 144 Pitch = 69 Velocity = 80 Channel = 0
Tick = 4320 Type = 4 Pitch = 0 Velocity = 80 Channel = 0
Tick = 4080 Type = 4 Pitch = 0 Velocity = 127 Channel = 0
Tick = 4367 Type = 144 Pitch = 69 Velocity = 0 Channel = 0
Tick = 4368 Type = 144 Pitch = 71 Velocity = 80 Channel = 0
Tick = 4559 Type = 144 Pitch = 71 Velocity = 0 Channel = 0
Tick = 4560 Type = 144 Pitch = 72 Velocity = 80 Channel = 0
Tick = 4800 Type = 4 Pitch = 0 Velocity = 127 Channel = 0
Tick = 4560 Type = 4 Pitch = 0 Velocity = 80 Channel = 0
Tick = 4847 Type = 144 Pitch = 72 Velocity = 0 Channel = 0
Tick = 4848 Type = 144 Pitch = 71 Velocity = 80 Channel = 0
Tick = 5039 Type = 144 Pitch = 71 Velocity = 0 Channel = 0
Expand Down
Binary file added vtest/beams-anacrusis-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0f5697c

Please sign in to comment.