Skip to content

Commit

Permalink
EscapeJSonArtistTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
evelynnev committed Jan 21, 2025
1 parent 05b0913 commit 802a84b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ void EngineBuffer::slotTrackLoaded(TrackPointer pTrack,
if (m_pConfig->getValue<bool>(ConfigKey("[OSC]", "OscEnabled"))) {
sendTrackInfoToOscClients(m_pConfig,
getGroup(),
pTrack->getArtist().toLatin1(),
pTrack->getTitle().toLatin1(),
pTrack->getArtist(),
pTrack->getTitle(),
1,
(float)pTrack->getDuration(),
0);
Expand Down
21 changes: 19 additions & 2 deletions src/osc/oscfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
constexpr int OUTPUT_BUFFER_SIZE = 1024;
constexpr int IP_MTU_SIZE = 1536;

#include <QChar>
#include <QDataStream>
#include <QFile>
#include <QSharedPointer>
#include <QString>
#include <iostream>
#include <memory>

Expand All @@ -22,6 +24,21 @@ enum class DefOscBodyType {
FLOATBODY
};

// function to convert and carry special characters in TrackArtist & TrackTitle to ASCII
QString escapeStringToJsonUnicode(const QString& input) {
QString escaped;
for (QChar c : input) {
if (c.isPrint() && c.unicode() < 128) {
// Keep printable ASCII characters as is
escaped += c;
} else {
// Escape non-ASCII and special characters
escaped += QString("\\u%1").arg(c.unicode(), 4, 16, QChar('0')).toUpper();
}
}
return escaped;
}

void sendOscMessage(const char* receiverIp,
int port,
osc::OutboundPacketStream& p,
Expand Down Expand Up @@ -166,15 +183,15 @@ void sendTrackInfoToOscClients(UserSettingsPointer pConfig,
oscGroup,
"TrackArtist",
DefOscBodyType::STRINGBODY,
trackArtist,
escapeStringToJsonUnicode(trackArtist),
0,
0,
0);
oscFunctionsSendPtrType(pConfig,
oscGroup,
"TrackTitle",
DefOscBodyType::STRINGBODY,
trackTitle,
escapeStringToJsonUnicode(trackTitle),
0,
0,
0);
Expand Down

0 comments on commit 802a84b

Please sign in to comment.