Skip to content

Commit 063be20

Browse files
committed
fix arpeggio and tremolo audio rendering
1 parent c9b1e8c commit 063be20

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

libmscore/rendermidi.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ static void collectNote(EventMap* events, int channel, const Note* note, int vel
138138
if (chord->isGrace()) {
139139
chord = static_cast<Chord*>(chord->parent());
140140
tieLen = 0;
141-
ticks = chord->duration().ticks();
141+
ticks = chord->actualTicks();
142142
}
143143
else {
144-
ticks = chord->duration().ticks();
144+
ticks = chord->actualTicks();
145145
tieLen = note->playTicks() - ticks;
146146
}
147147
int tick1 = chord->tick() + tickOffset;
@@ -541,9 +541,10 @@ static QList<NoteEventList> renderChord(Chord* chord, int gateTime, int ontime)
541541
//
542542
Tremolo* tremolo = chord->tremolo();
543543
if (tremolo) {
544-
int n = 1 << tremolo->lines();
545-
int l = 1000 / n;
544+
//int n = 1 << tremolo->lines();
545+
//int l = 1000 / n;
546546
if (chord->tremoloChordType() == TremoloFirstNote) {
547+
int t = MScore::division / (1 << tremolo->lines());
547548
Segment::SegmentTypes st = Segment::SegChordRest;
548549
Segment* seg2 = seg->next(st);
549550
int track = chord->track();
@@ -552,24 +553,35 @@ static QList<NoteEventList> renderChord(Chord* chord, int gateTime, int ontime)
552553
Chord* c2 = seg2 ? static_cast<Chord*>(seg2->element(track)) : 0;
553554
if (c2 && c2->type() == Element::CHORD) {
554555
int tnotes = qMin(notes, c2->notes().size());
556+
int tticks = chord->actualTicks() * 2; // use twice the size
557+
int n = tticks / t;
555558
n /= 2;
559+
int l = 2000 * t / tticks;
556560
for (int k = 0; k < tnotes; ++k) {
557561
NoteEventList* events = &ell[k];
558562
events->clear();
559563
int p1 = chord->notes()[k]->pitch();
560564
int p2 = c2->notes()[k]->pitch();
565+
int dpitch = p2 - p1;
561566
for (int i = 0; i < n; ++i) {
562-
events->append(NoteEvent(p1, l * i * 2, l));
563-
events->append(NoteEvent(p2, l * i * 2 + l, l));
567+
events->append(NoteEvent(0, l * i * 2, l));
568+
events->append(NoteEvent(dpitch, l * i * 2 + l, l));
564569
}
565570
}
566571
}
567572
else
568573
qDebug("Chord::renderTremolo: cannot find 2. chord\n");
569574
}
570575
else if (chord->tremoloChordType() == TremoloSecondNote) {
576+
for (int k = 0; k < notes; ++k) {
577+
NoteEventList* events = &(ell)[k];
578+
events->clear();
579+
}
571580
}
572581
else if (chord->tremoloChordType() == TremoloSingle) {
582+
int t = MScore::division / (1 << (tremolo->lines() + chord->durationType().hooks()));
583+
int n = chord->durationTicks() / t;
584+
int l = 1000 / n;
573585
for (int k = 0; k < notes; ++k) {
574586
NoteEventList* events = &(ell)[k];
575587
events->clear();
@@ -595,11 +607,13 @@ static QList<NoteEventList> renderChord(Chord* chord, int gateTime, int ontime)
595607
end = -1;
596608
step = -1;
597609
}
610+
int j = 0;
598611
for (int i = start; i != end; i += step) {
599612
NoteEventList* events = &(ell)[i];
600613
events->clear();
601-
int ot = (l * i * 1000) / chord->upNote()->playTicks();
614+
int ot = (l * j * 1000) / chord->upNote()->playTicks();
602615
events->append(NoteEvent(0, ot, 1000 - ot));
616+
j++;
603617
}
604618
}
605619

@@ -658,7 +672,7 @@ static QList<NoteEventList> renderChord(Chord* chord, int gateTime, int ontime)
658672
for (int i = 0; i < notes; ++i) {
659673
NoteEventList* el = &ell[i];
660674
int nn = el->size();
661-
if (nn == 0) {
675+
if (nn == 0 && chord->tremoloChordType() != TremoloSecondNote) {
662676
el->append(NoteEvent(0, ontime, 1000-ontime));
663677
++nn;
664678
}

0 commit comments

Comments
 (0)