Skip to content

Commit e22bc62

Browse files
committed
Additional optimizations and updated tests results to comparte with
1 parent e6ef930 commit e22bc62

File tree

10 files changed

+14
-158
lines changed

10 files changed

+14
-158
lines changed

src/importexport/lyricsexport/internal/lrcwriter.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,10 @@ std::map<double, QString> LRCWriter::collectLyrics(const mu::engraving::Score* s
121121
std::map<double, QString> lyrics;
122122
const RepeatList& repeats = score->repeatList();
123123

124-
staff_idx_t lyricsStaff;
125-
voice_idx_t lyricsVoice;
124+
track_idx_t trackNumber;
126125
int lyricNumber;
127126

128-
findStaffVoiceAndLyricToExport(score, lyricsStaff, lyricsVoice, lyricNumber);
127+
findTrackAndLyricToExport(score, trackNumber, lyricNumber);
129128

130129
for (const RepeatSegment* rs : repeats) {
131130
const int tickOffset = rs->utick - rs->tick;
@@ -151,7 +150,7 @@ std::map<double, QString> LRCWriter::collectLyrics(const mu::engraving::Score* s
151150
continue;
152151
}
153152

154-
if ((lyricsStaff == e->staffIdx()) && (lyricsVoice == e->voice()) && (lyricNumber == l->subtype())) {
153+
if ((trackNumber == e->track()) && (lyricNumber == l->subtype())) {
155154
const double time = score->utick2utime(l->tick().ticks() + tickOffset) * 1000;
156155
lyrics.insert_or_assign(time, l->plainText());
157156
}
@@ -172,18 +171,16 @@ QString LRCWriter::formatTimestamp(double ms) const
172171
.arg(static_cast<int>(ms) % 1000 / 10, 2, 10, QLatin1Char('0'));
173172
}
174173

175-
void LRCWriter::findStaffVoiceAndLyricToExport(const mu::engraving::Score* score, mu::engraving::staff_idx_t& staff,
176-
mu::engraving::voice_idx_t& voice, int& lyricNumber)
174+
void LRCWriter::findTrackAndLyricToExport(const engraving::Score* score, mu::engraving::track_idx_t& trackNumber, int& lyricNumber)
177175
{
178176
bool lyricsFound = false;
179-
staff = 0;
180-
voice = 0;
177+
trackNumber = 0;
181178
lyricNumber = 0;
182179

183180
const RepeatList& repeats = score->repeatList();
184181

185182
for (const RepeatSegment* rs : repeats) {
186-
for (const MeasureBase* mb = rs->firstMeasure(); mb; mb = mb->next()) {
183+
for (const MeasureBase* mb : rs->measureList()) {
187184
if (!mb->isMeasure()) {
188185
continue;
189186
}
@@ -206,27 +203,21 @@ void LRCWriter::findStaffVoiceAndLyricToExport(const mu::engraving::Score* score
206203

207204
if (!lyricsFound) {
208205
lyricsFound = true;
209-
staff = e->staffIdx();
210-
voice = e->voice();
206+
trackNumber = e->track();
211207
lyricNumber = l->subtype();
212208
continue;
213209
}
214210

215-
if (staff > e->staffIdx()) {
216-
staff = e->staffIdx();
217-
voice = e->voice();
211+
// We check if we have a better option
212+
if (trackNumber > e->track()) {
213+
trackNumber = e->track();
218214
lyricNumber = l->subtype();
219-
} else if (staff == e->staffIdx()) {
220-
if (voice > e->voice()) {
221-
voice = e->voice();
222-
lyricNumber = l->subtype();
223-
} else if (voice == e->voice()) {
224-
lyricNumber = std::min(lyricNumber, l->subtype());
225-
}
215+
} else if (trackNumber == e->track()) {
216+
lyricNumber = std::min(lyricNumber, l->subtype());
226217
}
227218
}
228219
// If we have already chosen the lowest/prioritized option we can return (no better option available)
229-
if (lyricsFound && (staff == 0) && (voice == 0) && (lyricNumber == 0)) {
220+
if (lyricsFound && (trackNumber == 0) && (lyricNumber == 0)) {
230221
return;
231222
}
232223
}

src/importexport/lyricsexport/internal/lrcwriter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class LRCWriter : public project::INotationWriter
5252
// Core lyric functionality
5353
std::map<double, QString> collectLyrics(const mu::engraving::Score*);
5454
QString formatTimestamp(double ms) const;
55-
void findStaffVoiceAndLyricToExport(const engraving::Score* score, engraving::staff_idx_t& staff, engraving::voice_idx_t& voice,
56-
int& lyricNumber);
55+
void findTrackAndLyricToExport(const engraving::Score* score, mu::engraving::track_idx_t& trackNumber, int& lyricNumber);
5756
};
5857
} // namespace mu::iex::lrcexport

src/importexport/lyricsexport/tests/data/lrc_enhanced_test1_ref.lrc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,3 @@
112112
[00:54.50] <00:54.50> SOneVOne-most
113113
[00:55.00] <00:55.00> SOneVOne-nights,
114114
[00:55.50] <00:55.50> SOneVOne-End
115-
[00:56.00] <00:56.00> SOneVOne-of
116-
[00:56.50] <00:56.50> SOneVOne-rather
117-
[00:57.00] <00:57.00> SOneVOne-more
118-
[00:57.50] <00:57.50> SOneVOne-beef
119-
[00:58.00] <00:58.00> SOneVOne-than
120-
[00:58.50] <00:58.50> SOneVOne-mutton
121-
[00:59.00] <00:59.00> SOneVOne-a
122-
[00:59.50] <00:59.50> SOneVOne-salad
123-
[01:00.00] <01:00.00> SOneVOne-on
124-
[01:00.50] <01:00.50> SOneVOne-most
125-
[01:01.00] <01:01.00> SOneVOne-nights,
126-
[01:01.50] <01:01.50> SOneVOne-End

src/importexport/lyricsexport/tests/data/lrc_enhanced_test3_ref.lrc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
[00:10.50] <00:10.50> SOneVOne-one
99
[00:11.00] <00:11.00> SOneVOne-of
1010
[00:11.50] <00:11.50> SOneVOne-those
11-
[00:12.00] <00:12.00> SOneVOne-gentlement
12-
[00:12.50] <00:12.50> SOneVOne-that
13-
[00:13.00] <00:13.00> SOneVOne-keep
14-
[00:13.50] <00:13.50> SOneVOne-a
1511
[00:14.00] <00:14.00> SOneVOne-mind,-SOneVOne-there
1612
[00:14.50] <00:14.50> SOneVOne-lived
1713
[00:15.00] <00:15.00> SOneVOne-not
@@ -44,14 +40,6 @@
4440
[00:28.50] <00:28.50> SOneVOne-rather
4541
[00:29.00] <00:29.00> SOneVOne-more
4642
[00:29.50] <00:29.50> SOneVOne-beef
47-
[00:30.00] <00:30.00> SOneVOne-than
48-
[00:30.50] <00:30.50> SOneVOne-mutton
49-
[00:31.00] <00:31.00> SOneVOne-a
50-
[00:31.50] <00:31.50> SOneVOne-salad
51-
[00:32.00] <00:32.00> SOneVOne-on
52-
[00:32.50] <00:32.50> SOneVOne-most
53-
[00:33.00] <00:33.00> SOneVOne-nights,
54-
[00:33.50] <00:33.50> SOneVOne-End
5543
[00:36.00] <00:36.00> SOneVOne-mind,-SOneVOne-there
5644
[00:36.50] <00:36.50> SOneVOne-lived
5745
[00:37.00] <00:37.00> SOneVOne-not
@@ -60,10 +48,6 @@
6048
[00:38.50] <00:38.50> SOneVOne-one
6149
[00:39.00] <00:39.00> SOneVOne-of
6250
[00:39.50] <00:39.50> SOneVOne-those
63-
[00:40.00] <00:40.00> SOneVOne-gentlement
64-
[00:40.50] <00:40.50> SOneVOne-that
65-
[00:41.00] <00:41.00> SOneVOne-keep
66-
[00:41.50] <00:41.50> SOneVOne-a
6751
[00:42.00] <00:42.00> SOneVOne-mind,-SOneVOne-there
6852
[00:42.50] <00:42.50> SOneVOne-lived
6953
[00:43.00] <00:43.00> SOneVOne-not
@@ -92,15 +76,3 @@
9276
[00:54.50] <00:54.50> SOneVOne-most
9377
[00:55.00] <00:55.00> SOneVOne-nights,
9478
[00:55.50] <00:55.50> SOneVOne-End
95-
[00:56.00] <00:56.00> SOneVOne-of
96-
[00:56.50] <00:56.50> SOneVOne-rather
97-
[00:57.00] <00:57.00> SOneVOne-more
98-
[00:57.50] <00:57.50> SOneVOne-beef
99-
[00:58.00] <00:58.00> SOneVOne-than
100-
[00:58.50] <00:58.50> SOneVOne-mutton
101-
[00:59.00] <00:59.00> SOneVOne-a
102-
[00:59.50] <00:59.50> SOneVOne-salad
103-
[01:00.00] <01:00.00> SOneVOne-on
104-
[01:00.50] <01:00.50> SOneVOne-most
105-
[01:01.00] <01:01.00> SOneVOne-nights,
106-
[01:01.50] <01:01.50> SOneVOne-End

src/importexport/lyricsexport/tests/data/lrc_enhanced_test4_ref.lrc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
[00:28.50] <00:28.50> STwoVOne-rather
5858
[00:29.00] <00:29.00> STwoVOne-more
5959
[00:29.50] <00:29.50> STwoVOne-beef
60-
[00:30.00] <00:30.00> STwoVOne-than
61-
[00:30.50] <00:30.50> STwoVOne-mutton
62-
[00:31.00] <00:31.00> STwoVOne-a
6360
[00:31.50] <00:31.50> STwoVOne-of
6461
[00:32.00] <00:32.00> STwoVOne-which
6562
[00:32.50] <00:32.50> STwoVOne-I
@@ -109,15 +106,3 @@
109106
[00:54.50] <00:54.50> STwoVOne-most
110107
[00:55.00] <00:55.00> STwoVOne-nights,
111108
[00:55.50] <00:55.50> STwoVOne-End
112-
[00:56.00] <00:56.00> STwoVOne-of
113-
[00:56.50] <00:56.50> STwoVOne-rather
114-
[00:57.00] <00:57.00> STwoVOne-more
115-
[00:57.50] <00:57.50> STwoVOne-beef
116-
[00:58.00] <00:58.00> STwoVOne-than
117-
[00:58.50] <00:58.50> STwoVOne-mutton
118-
[00:59.00] <00:59.00> STwoVOne-a
119-
[00:59.50] <00:59.50> STwoVOne-salad
120-
[01:00.00] <01:00.00> STwoVOne-on
121-
[01:00.50] <01:00.50> STwoVOne-most
122-
[01:01.00] <01:01.00> STwoVOne-nights,
123-
[01:01.50] <01:01.50> STwoVOne-End

src/importexport/lyricsexport/tests/data/lrc_enhanced_test5_ref.lrc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,3 @@
112112
[00:54.50] <00:54.50> SThreeVOne-most
113113
[00:55.00] <00:55.00> SThreeVOne-nights,
114114
[00:55.50] <00:55.50> SThreeVOne-End
115-
[00:56.00] <00:56.00> SThreeVOne-of
116-
[00:56.50] <00:56.50> SThreeVOne-rather
117-
[00:57.00] <00:57.00> SThreeVOne-more
118-
[00:57.50] <00:57.50> SThreeVOne-beef
119-
[00:58.00] <00:58.00> SThreeVOne-than
120-
[00:58.50] <00:58.50> SThreeVOne-mutton
121-
[00:59.00] <00:59.00> SThreeVOne-a
122-
[00:59.50] <00:59.50> SThreeVOne-salad
123-
[01:00.00] <01:00.00> SThreeVOne-on
124-
[01:00.50] <01:00.50> SThreeVOne-most
125-
[01:01.00] <01:01.00> SThreeVOne-nights,
126-
[01:01.50] <01:01.50> SThreeVOne-End

src/importexport/lyricsexport/tests/data/lrc_simple_test1_ref.lrc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,3 @@
112112
[00:54.50]SOneVOne most
113113
[00:55.00]SOneVOne nights,
114114
[00:55.50]SOneVOne End
115-
[00:56.00]SOneVOne of
116-
[00:56.50]SOneVOne rather
117-
[00:57.00]SOneVOne more
118-
[00:57.50]SOneVOne beef
119-
[00:58.00]SOneVOne than
120-
[00:58.50]SOneVOne mutton
121-
[00:59.00]SOneVOne a
122-
[00:59.50]SOneVOne salad
123-
[01:00.00]SOneVOne on
124-
[01:00.50]SOneVOne most
125-
[01:01.00]SOneVOne nights,
126-
[01:01.50]SOneVOne End

src/importexport/lyricsexport/tests/data/lrc_simple_test3_ref.lrc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
[00:10.50]SOneVOne one
99
[00:11.00]SOneVOne of
1010
[00:11.50]SOneVOne those
11-
[00:12.00]SOneVOne gentlement
12-
[00:12.50]SOneVOne that
13-
[00:13.00]SOneVOne keep
14-
[00:13.50]SOneVOne a
1511
[00:14.00]SOneVOne mind, SOneVOne there
1612
[00:14.50]SOneVOne lived
1713
[00:15.00]SOneVOne not
@@ -44,14 +40,6 @@
4440
[00:28.50]SOneVOne rather
4541
[00:29.00]SOneVOne more
4642
[00:29.50]SOneVOne beef
47-
[00:30.00]SOneVOne than
48-
[00:30.50]SOneVOne mutton
49-
[00:31.00]SOneVOne a
50-
[00:31.50]SOneVOne salad
51-
[00:32.00]SOneVOne on
52-
[00:32.50]SOneVOne most
53-
[00:33.00]SOneVOne nights,
54-
[00:33.50]SOneVOne End
5543
[00:36.00]SOneVOne mind, SOneVOne there
5644
[00:36.50]SOneVOne lived
5745
[00:37.00]SOneVOne not
@@ -60,10 +48,6 @@
6048
[00:38.50]SOneVOne one
6149
[00:39.00]SOneVOne of
6250
[00:39.50]SOneVOne those
63-
[00:40.00]SOneVOne gentlement
64-
[00:40.50]SOneVOne that
65-
[00:41.00]SOneVOne keep
66-
[00:41.50]SOneVOne a
6751
[00:42.00]SOneVOne mind, SOneVOne there
6852
[00:42.50]SOneVOne lived
6953
[00:43.00]SOneVOne not
@@ -92,15 +76,3 @@
9276
[00:54.50]SOneVOne most
9377
[00:55.00]SOneVOne nights,
9478
[00:55.50]SOneVOne End
95-
[00:56.00]SOneVOne of
96-
[00:56.50]SOneVOne rather
97-
[00:57.00]SOneVOne more
98-
[00:57.50]SOneVOne beef
99-
[00:58.00]SOneVOne than
100-
[00:58.50]SOneVOne mutton
101-
[00:59.00]SOneVOne a
102-
[00:59.50]SOneVOne salad
103-
[01:00.00]SOneVOne on
104-
[01:00.50]SOneVOne most
105-
[01:01.00]SOneVOne nights,
106-
[01:01.50]SOneVOne End

src/importexport/lyricsexport/tests/data/lrc_simple_test4_ref.lrc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
[00:28.50]STwoVOne rather
5858
[00:29.00]STwoVOne more
5959
[00:29.50]STwoVOne beef
60-
[00:30.00]STwoVOne than
61-
[00:30.50]STwoVOne mutton
62-
[00:31.00]STwoVOne a
6360
[00:31.50]STwoVOne of
6461
[00:32.00]STwoVOne which
6562
[00:32.50]STwoVOne I
@@ -109,15 +106,3 @@
109106
[00:54.50]STwoVOne most
110107
[00:55.00]STwoVOne nights,
111108
[00:55.50]STwoVOne End
112-
[00:56.00]STwoVOne of
113-
[00:56.50]STwoVOne rather
114-
[00:57.00]STwoVOne more
115-
[00:57.50]STwoVOne beef
116-
[00:58.00]STwoVOne than
117-
[00:58.50]STwoVOne mutton
118-
[00:59.00]STwoVOne a
119-
[00:59.50]STwoVOne salad
120-
[01:00.00]STwoVOne on
121-
[01:00.50]STwoVOne most
122-
[01:01.00]STwoVOne nights,
123-
[01:01.50]STwoVOne End

src/importexport/lyricsexport/tests/data/lrc_simple_test5_ref.lrc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,3 @@
112112
[00:54.50]SThreeVOne most
113113
[00:55.00]SThreeVOne nights,
114114
[00:55.50]SThreeVOne End
115-
[00:56.00]SThreeVOne of
116-
[00:56.50]SThreeVOne rather
117-
[00:57.00]SThreeVOne more
118-
[00:57.50]SThreeVOne beef
119-
[00:58.00]SThreeVOne than
120-
[00:58.50]SThreeVOne mutton
121-
[00:59.00]SThreeVOne a
122-
[00:59.50]SThreeVOne salad
123-
[01:00.00]SThreeVOne on
124-
[01:00.50]SThreeVOne most
125-
[01:01.00]SThreeVOne nights,
126-
[01:01.50]SThreeVOne End

0 commit comments

Comments
 (0)