@@ -102,7 +102,7 @@ void Score::pasteChordRest(ChordRest* cr, const Fraction& t)
102102 Transpose::transposeChord (chord, tick);
103103 if (chord->tremoloTwoChord ()) {
104104 twoNoteTremoloFactor = 2 ;
105- } else if (cr->durationTypeTicks () == (cr->actualTicksAt (tick ) * 2 )) {
105+ } else if (cr->durationTypeTicks () == (cr->ticks ( ) * 2 )) {
106106 // this could be the 2nd note of a two-note tremolo
107107 // check previous CR on same track, if it has a two-note tremolo, then set twoNoteTremoloFactor to 2
108108 Segment* seg = measure->undoGetSegment (SegmentType::ChordRest, tick);
@@ -122,7 +122,7 @@ void Score::pasteChordRest(ChordRest* cr, const Fraction& t)
122122 // otherwise, we need to convert to duration rest(s)
123123 // and potentially split the rest up (eg, 5/4 => whole + quarter)
124124 bool convertMeasureRest = cr->isRest () && cr->durationType ().type () == DurationType::V_MEASURE
125- && (tick != measure->tick () || cr->ticks ( ) != measure->ticks ());
125+ && (tick != measure->tick () || cr->actualTicksAt (tick ) != measure->ticks ());
126126
127127 Fraction measureEnd = measure->endTick ();
128128 bool isGrace = cr->isChord () && toChord (cr)->noteType () != NoteType::NORMAL;
@@ -145,40 +145,39 @@ void Score::pasteChordRest(ChordRest* cr, const Fraction& t)
145145 if (cr->isMeasureRepeat ()) {
146146 partialCopy = toMeasureRepeat (cr)->actualTicks () != measure->ticks ();
147147 } else if (!isGrace && !cr->tuplet ()) {
148- partialCopy = cr->durationTypeTicks () != (cr->actualTicksAt (tick ) * twoNoteTremoloFactor);
148+ partialCopy = cr->durationTypeTicks () != (cr->ticks ( ) * twoNoteTremoloFactor);
149149 }
150150
151151 // if note is too long to fit in measure, split it up with a tie across the barline
152152 // exclude tuplets from consideration
153153 // we have already disallowed a tuplet from crossing the barline, so there is no problem here
154154 // but due to rounding, it might appear from actualTicks() that the last note is too long by a couple of ticks
155155
156+ Staff* stf = cr->staff ();
156157 if (!isGrace && !cr->tuplet () && (tick + cr->actualTicksAt (tick) > measureEnd || partialCopy || convertMeasureRest)) {
157158 if (cr->isChord ()) {
158159 // split Chord
159160 Chord* c = toChord (cr);
160- Fraction rest = c->actualTicksAt (tick );
161+ Fraction rest = c->ticks ( );
161162 bool firstpart = true ;
162163 while (rest.isNotZero ()) {
163164 measure = tick2measure (tick);
164165 Chord* c2 = firstpart ? c : toChord (c->clone ());
165166 if (!firstpart) {
166167 c2->removeMarkings (true );
167168 }
168- Fraction mlen = measure->endTick () - tick;
169+ Fraction timeStretch = stf->timeStretch (tick);
170+ Fraction mlen = (measure->endTick () - tick) * timeStretch;
169171 Fraction len = mlen > rest ? rest : mlen;
170- Fraction timeStretch = c2->staff ()->timeStretch (tick);
171- std::vector<TDuration> dl = toRhythmicDurationList (len * timeStretch, false , (tick - measure->tick ()) * timeStretch,
172+ std::vector<TDuration> dl = toRhythmicDurationList (len, false , (tick - measure->tick ()) * timeStretch,
172173 sigmap ()->timesig (tick).nominal (), measure, MAX_DOTS, timeStretch);
173174 if (dl.empty ()) {
174175 LOGD (" Could not make durations for: %d/%d" , len.numerator (), len.denominator ());
175176 return ;
176177 }
177178 TDuration d = dl[0 ];
178- Fraction c2Tick (tick + c->tick ());
179179 c2->setDurationType (d);
180180 c2->setTicks (d.fraction ());
181- rest -= c2->actualTicksAt (c2Tick);
182181 undoAddCR (c2, measure, tick);
183182
184183 std::vector<Note*> nl1 = c->notes ();
@@ -201,9 +200,10 @@ void Score::pasteChordRest(ChordRest* cr, const Fraction& t)
201200 nl2[i]->setTieBack (tie);
202201 }
203202 }
204- c = c2;
203+ rest -= c2->ticks ();
204+ tick += c2->actualTicksAt (tick);
205205 firstpart = false ;
206- tick += c-> actualTicksAt (c2Tick) ;
206+ c = c2 ;
207207 }
208208 } else if (cr->isRest ()) {
209209 // split Rest
@@ -214,34 +214,35 @@ void Score::pasteChordRest(ChordRest* cr, const Fraction& t)
214214 while (!rest.isZero ()) {
215215 Rest* r2 = firstpart ? r : toRest (r->clone ());
216216 measure = tick2measure (tick);
217- Fraction mlen = measure->endTick () - tick;
217+ Fraction timeStretch = stf->timeStretch (tick);
218+ Fraction mlen = (measure->endTick () - tick) * timeStretch;
218219 Fraction len = rest > mlen ? mlen : rest;
219- Fraction timeStretch = r2->staff ()->timeStretch (tick);
220- std::vector<TDuration> dl = toRhythmicDurationList (len * timeStretch, true , (tick - measure->tick ()) * timeStretch,
220+ std::vector<TDuration> dl = toRhythmicDurationList (len, true , (tick - measure->tick ()) * timeStretch,
221221 sigmap ()->timesig (tick).nominal (), measure, MAX_DOTS, timeStretch);
222222 if (dl.empty ()) {
223223 LOGD (" Could not make durations for: %d/%d" , len.numerator (), len.denominator ());
224224 return ;
225225 }
226226 TDuration d = dl[0 ];
227227 r2->setDurationType (d);
228- r2->setTicks (d.isMeasure () ? measure->ticks ( ) : d.fraction ());
228+ r2->setTicks (d.isMeasure () ? measure->stretchedLen (stf ) : d.fraction ());
229229 undoAddCR (r2, measure, tick);
230230 rest -= r2->ticks ();
231231 tick += r2->actualTicksAt (tick);
232232 firstpart = false ;
233233 }
234234 } else if (cr->isMeasureRepeat ()) {
235235 MeasureRepeat* mr = toMeasureRepeat (cr);
236- std::vector<TDuration> list = toDurationList (mr->actualTicks (), true );
236+ std::vector<TDuration> list = toDurationList (mr->ticks (), true );
237237 for (auto dur : list) {
238238 Rest* r = Factory::createRest (this ->dummy ()->segment (), dur);
239239 r->setTrack (cr->track ());
240240 Fraction rest = r->ticks ();
241241 while (!rest.isZero ()) {
242242 Rest* r2 = toRest (r->clone ());
243243 measure = tick2measure (tick);
244- Fraction mlen = measure->endTick () - tick;
244+ Fraction timeStretch = stf->timeStretch (tick);
245+ Fraction mlen = (measure->endTick () - tick) * timeStretch;
245246 Fraction len = rest > mlen ? mlen : rest;
246247 std::vector<TDuration> dl = toDurationList (len, false );
247248 if (dl.empty ()) {
@@ -252,7 +253,7 @@ void Score::pasteChordRest(ChordRest* cr, const Fraction& t)
252253 r2->setTicks (d.fraction ());
253254 r2->setDurationType (d);
254255 undoAddCR (r2, measure, tick);
255- rest -= d. fraction ();
256+ rest -= r2-> ticks ();
256257 tick += r2->actualTicksAt (tick);
257258 }
258259 delete r;
0 commit comments