Skip to content

Commit f641449

Browse files
committed
fix #30807: [TablEdit import] measures with gaps in voice 1 imported as corrupt
1 parent 1f2c93a commit f641449

File tree

5 files changed

+731
-43
lines changed

5 files changed

+731
-43
lines changed

src/importexport/tabledit/internal/importtef.cpp

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,15 @@ static void addGraceNotesToChord(mu::engraving::Chord* chord, int pitch, int fre
266266
chord->add(cr);
267267
}
268268

269-
static void addRest(Segment* segment, track_idx_t track, TDuration tDuration, Fraction length, muse::draw::Color color)
269+
static void addRest(Segment* segment, track_idx_t track, TDuration tDuration, Fraction length, muse::draw::Color color, bool visible = true)
270270
{
271271
mu::engraving::Rest* rest = Factory::createRest(segment);
272272
if (rest) {
273273
rest->setTrack(track);
274274
rest->setDurationType(tDuration);
275275
rest->setTicks(length);
276276
rest->setColor(color);
277+
rest->setVisible(visible);
277278
segment->add(rest);
278279
}
279280
}
@@ -593,6 +594,70 @@ static void setInstrumentIDs(const std::vector<Part*>& parts)
593594
}
594595
}
595596

597+
//---------------------------------------------------------
598+
// fillGap
599+
//---------------------------------------------------------
600+
601+
// Fill one gap (tstart - tend) in this track in this measure with rest(s).
602+
603+
static void fillGap(Measure* measure, track_idx_t track, const Fraction& tstart, const Fraction& tend)
604+
{
605+
Fraction ctick = tstart;
606+
Fraction restLen = tend - tstart;
607+
LOGN("measure %p track %zu tstart %d tend %d restLen %d len",
608+
measure, track, tstart.ticks(), tend.ticks(), restLen.ticks());
609+
auto durList = toDurationList(restLen, true);
610+
LOGN("durList.size %zu", durList.size());
611+
for (const auto& dur : durList) {
612+
LOGN("type %d dots %d fraction %d/%d", dur.type(), dur.dots(), dur.fraction().numerator(), dur.fraction().denominator());
613+
Segment* s = measure->getSegment(SegmentType::ChordRest, ctick);
614+
addRest(s, track, dur, dur.fraction(), muse::draw::Color::BLACK, false);
615+
ctick += dur.fraction();
616+
}
617+
}
618+
619+
//---------------------------------------------------------
620+
// fillGapsInFirstVoices
621+
//---------------------------------------------------------
622+
623+
// Fill gaps in first voice of every staff in this measure for this part with rest(s).
624+
625+
static void fillGapsInFirstVoices(MasterScore* score)
626+
{
627+
IF_ASSERT_FAILED(score) {
628+
return;
629+
}
630+
631+
for (staff_idx_t idx = 0; idx < score->nstaves(); ++idx) {
632+
for (Measure* measure = score->firstMeasure(); measure; measure = measure->nextMeasure()) {
633+
Fraction measTick = measure->tick();
634+
Fraction measLen = measure->ticks();
635+
Fraction nextMeasTick = measTick + measLen;
636+
LOGN("measure %p idx %zu tick %d - %d (len %d)",
637+
measure, idx, measTick.ticks(), nextMeasTick.ticks(), measLen.ticks());
638+
track_idx_t track = idx * VOICES;
639+
Fraction endOfLastCR = measTick;
640+
for (Segment* s = measure->first(); s; s = s->next()) {
641+
EngravingItem* el = s->element(track);
642+
if (el) {
643+
if (s->isChordRestType()) {
644+
ChordRest* cr = static_cast<ChordRest*>(el);
645+
Fraction crTick = cr->tick();
646+
Fraction crLen = cr->globalTicks();
647+
if (crTick > endOfLastCR) {
648+
fillGap(measure, track, endOfLastCR, crTick);
649+
}
650+
endOfLastCR = crTick + crLen;
651+
}
652+
}
653+
}
654+
if (nextMeasTick > endOfLastCR) {
655+
fillGap(measure, track, endOfLastCR, nextMeasTick);
656+
}
657+
}
658+
}
659+
}
660+
596661
void TablEdit::createScore()
597662
{
598663
MeasureHandler measureHandler;
@@ -603,6 +668,7 @@ void TablEdit::createScore()
603668
createMeasures(measureHandler);
604669
createNotesFrame();
605670
createContents(measureHandler);
671+
fillGapsInFirstVoices(score);
606672
createRepeats();
607673
createTexts();
608674
createLinkedTabs();

src/importexport/tabledit/tests/data/gaps_1.mscx

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -96,64 +96,73 @@
9696
<eid>I_I</eid>
9797
<text><sym>metNoteQuarterUp</sym> = 120</text>
9898
</Tempo>
99-
<location>
100-
<fractions>3/4</fractions>
101-
</location>
102-
<Chord>
99+
<Rest>
103100
<eid>J_J</eid>
101+
<visible>0</visible>
102+
<dots>1</dots>
103+
<durationType>half</durationType>
104+
<NoteDot>
105+
<eid>K_K</eid>
106+
<visible>0</visible>
107+
</NoteDot>
108+
</Rest>
109+
<Chord>
110+
<eid>L_L</eid>
104111
<durationType>quarter</durationType>
105112
<Note>
106-
<eid>K_K</eid>
113+
<eid>M_M</eid>
107114
<pitch>48</pitch>
108115
<tpc>14</tpc>
109116
<fret>3</fret>
110117
<string>4</string>
111118
</Note>
112119
</Chord>
113120
<BarLine>
114-
<eid>L_L</eid>
121+
<eid>N_N</eid>
115122
</BarLine>
116123
</voice>
117124
</Measure>
118125
<Measure>
119-
<eid>M_M</eid>
126+
<eid>O_O</eid>
120127
<voice>
121128
<Chord>
122-
<eid>N_N</eid>
129+
<eid>P_P</eid>
123130
<durationType>whole</durationType>
124131
<Note>
125-
<eid>O_O</eid>
132+
<eid>Q_Q</eid>
126133
<pitch>48</pitch>
127134
<tpc>14</tpc>
128135
<fret>3</fret>
129136
<string>4</string>
130137
</Note>
131138
</Chord>
132139
<BarLine>
133-
<eid>P_P</eid>
140+
<eid>R_R</eid>
134141
</BarLine>
135142
</voice>
136143
</Measure>
137144
<Measure>
138-
<eid>Q_Q</eid>
145+
<eid>S_S</eid>
139146
<voice>
140147
<Chord>
141-
<eid>R_R</eid>
148+
<eid>T_T</eid>
142149
<dots>1</dots>
143150
<durationType>half</durationType>
144151
<Note>
145-
<eid>S_S</eid>
152+
<eid>U_U</eid>
146153
<pitch>48</pitch>
147154
<tpc>14</tpc>
148155
<fret>3</fret>
149156
<string>4</string>
150157
</Note>
151158
</Chord>
152-
<location>
153-
<fractions>1/4</fractions>
154-
</location>
159+
<Rest>
160+
<eid>V_V</eid>
161+
<visible>0</visible>
162+
<durationType>quarter</durationType>
163+
</Rest>
155164
<BarLine>
156-
<eid>T_T</eid>
165+
<eid>W_W</eid>
157166
</BarLine>
158167
</voice>
159168
</Measure>
@@ -162,75 +171,86 @@
162171
<Measure>
163172
<voice>
164173
<KeySig>
165-
<eid>U_U</eid>
174+
<eid>X_X</eid>
166175
<linkedTo>G_G</linkedTo>
167176
<concertKey>0</concertKey>
168177
</KeySig>
169-
<location>
170-
<fractions>3/4</fractions>
171-
</location>
172-
<Chord>
173-
<eid>V_V</eid>
178+
<Rest>
179+
<eid>Y_Y</eid>
174180
<linkedTo>J_J</linkedTo>
181+
<visible>0</visible>
182+
<dots>1</dots>
183+
<durationType>half</durationType>
184+
<NoteDot>
185+
<eid>Z_Z</eid>
186+
<visible>0</visible>
187+
</NoteDot>
188+
</Rest>
189+
<Chord>
190+
<eid>a_a</eid>
191+
<linkedTo>L_L</linkedTo>
175192
<durationType>quarter</durationType>
176193
<Note>
177-
<eid>W_W</eid>
178-
<linkedTo>K_K</linkedTo>
194+
<eid>b_b</eid>
195+
<linkedTo>M_M</linkedTo>
179196
<pitch>48</pitch>
180197
<tpc>14</tpc>
181198
<fret>3</fret>
182199
<string>4</string>
183200
</Note>
184201
</Chord>
185202
<BarLine>
186-
<eid>X_X</eid>
187-
<linkedTo>L_L</linkedTo>
203+
<eid>c_c</eid>
204+
<linkedTo>N_N</linkedTo>
188205
</BarLine>
189206
</voice>
190207
</Measure>
191208
<Measure>
192209
<voice>
193210
<Chord>
194-
<eid>Y_Y</eid>
195-
<linkedTo>N_N</linkedTo>
211+
<eid>d_d</eid>
212+
<linkedTo>P_P</linkedTo>
196213
<durationType>whole</durationType>
197214
<Note>
198-
<eid>Z_Z</eid>
199-
<linkedTo>O_O</linkedTo>
215+
<eid>e_e</eid>
216+
<linkedTo>Q_Q</linkedTo>
200217
<pitch>48</pitch>
201218
<tpc>14</tpc>
202219
<fret>3</fret>
203220
<string>4</string>
204221
</Note>
205222
</Chord>
206223
<BarLine>
207-
<eid>a_a</eid>
208-
<linkedTo>P_P</linkedTo>
224+
<eid>f_f</eid>
225+
<linkedTo>R_R</linkedTo>
209226
</BarLine>
210227
</voice>
211228
</Measure>
212229
<Measure>
213230
<voice>
214231
<Chord>
215-
<eid>b_b</eid>
216-
<linkedTo>R_R</linkedTo>
232+
<eid>g_g</eid>
233+
<linkedTo>T_T</linkedTo>
217234
<dots>1</dots>
218235
<durationType>half</durationType>
219236
<Note>
220-
<eid>c_c</eid>
221-
<linkedTo>S_S</linkedTo>
237+
<eid>h_h</eid>
238+
<linkedTo>U_U</linkedTo>
222239
<pitch>48</pitch>
223240
<tpc>14</tpc>
224241
<fret>3</fret>
225242
<string>4</string>
226243
</Note>
227244
</Chord>
228-
<location>
229-
<fractions>1/4</fractions>
230-
</location>
245+
<Rest>
246+
<eid>i_i</eid>
247+
<linkedTo>V_V</linkedTo>
248+
<visible>0</visible>
249+
<durationType>quarter</durationType>
250+
</Rest>
231251
<BarLine>
232-
<eid>d_d</eid>
233-
<linkedTo>T_T</linkedTo>
252+
<eid>j_j</eid>
253+
<linkedTo>W_W</linkedTo>
234254
</BarLine>
235255
</voice>
236256
</Measure>

0 commit comments

Comments
 (0)