Skip to content

Commit d96cae9

Browse files
Swiftb0ydaschuer
andcommitted
fix: hotcue comments are utf-16be, regression from mixxxdj#13293
Fixes mixxxdj#14789 Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
1 parent 19cd401 commit d96cae9

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/library/rekordbox/rekordboxfeature.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,18 @@ inline bool instanceof (const T* ptr) {
255255
return dynamic_cast<const Base*>(ptr) != nullptr;
256256
}
257257

258-
QString toUnicode(const std::string& toConvert) {
258+
QString fromUtf16LeString(const std::string& toConvert) {
259+
// Kaitai uses std::string as single container for all string encodings.
259260
return QTextCodec::codecForName("UTF-16LE")
260261
->toUnicode(toConvert.data(), static_cast<int>(toConvert.length()));
261262
}
262263

264+
QString fromUtf16BeString(const std::string& toConvert) {
265+
// Kaitai uses std::string as single container for all string encodings.
266+
int length = static_cast<int>(toConvert.length()) - 2; // strip off trailing nullbyte
267+
return QTextCodec::codecForName("UTF-16BE")->toUnicode(toConvert.data(), length);
268+
}
269+
263270
// Functions getText and parseDeviceDB are roughly based on the following Java file:
264271
// https://github.com/Deep-Symmetry/crate-digger/commit/f09fa9fc097a2a428c43245ddd542ac1370c1adc
265272
// getText is needed because the strings in the PDB file "have a variety of obscure representations".
@@ -278,7 +285,7 @@ QString getText(rekordbox_pdb_t::device_sql_string_t* deviceString) {
278285
} else if (instanceof <rekordbox_pdb_t::device_sql_long_utf16le_t>(deviceString->body())) {
279286
rekordbox_pdb_t::device_sql_long_utf16le_t* longUtf16leString =
280287
static_cast<rekordbox_pdb_t::device_sql_long_utf16le_t*>(deviceString->body());
281-
text = toUnicode(longUtf16leString->text());
288+
text = fromUtf16LeString(longUtf16leString->text());
282289
}
283290

284291
// Some strings read from Rekordbox *.PDB files contain random null characters
@@ -997,7 +1004,7 @@ void readAnalyze(TrackPointer track,
9971004
memory_cue_loop_t memoryCue;
9981005
memoryCue.startPosition = position;
9991006
memoryCue.endPosition = mixxx::audio::kInvalidFramePos;
1000-
memoryCue.comment = toUnicode(cueExtendedEntry->comment());
1007+
memoryCue.comment = fromUtf16BeString(cueExtendedEntry->comment());
10011008
memoryCue.color = colorFromID(static_cast<int>(
10021009
cueExtendedEntry->color_id()));
10031010
memoryCuesAndLoops << memoryCue;
@@ -1016,7 +1023,7 @@ void readAnalyze(TrackPointer track,
10161023
loop.startPosition = position;
10171024
loop.endPosition = mixxx::audio::FramePos(
10181025
sampleRateKhz * static_cast<double>(endTime));
1019-
loop.comment = toUnicode(cueExtendedEntry->comment());
1026+
loop.comment = fromUtf16BeString(cueExtendedEntry->comment());
10201027
loop.color = colorFromID(static_cast<int>(cueExtendedEntry->color_id()));
10211028
memoryCuesAndLoops << loop;
10221029
} break;
@@ -1031,14 +1038,14 @@ void readAnalyze(TrackPointer track,
10311038
position,
10321039
mixxx::audio::kInvalidFramePos,
10331040
hotCueIndex,
1034-
toUnicode(cueExtendedEntry->comment()),
1041+
fromUtf16BeString(cueExtendedEntry->comment()),
10351042
mixxx::RgbColor(qRgb(
10361043
static_cast<int>(
10371044
cueExtendedEntry->color_red()),
10381045
static_cast<int>(
10391046
cueExtendedEntry->color_green()),
10401047
static_cast<int>(cueExtendedEntry
1041-
->color_blue()))));
1048+
->color_blue()))));
10421049
} break;
10431050
}
10441051
}

0 commit comments

Comments
 (0)