Skip to content

Commit ff291d2

Browse files
committed
fixup! feat: store tracklist as tag comment on recording
1 parent eba3cfd commit ff291d2

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/encoder/encoder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,22 @@ EncoderRecordingSettingsPointer EncoderFactory::getEncoderRecordingSettings(Enco
158158

159159
void Encoder::addToTracklist(const QString& artist,
160160
const QString& title,
161-
std::chrono::seconds timecode) {
162-
auto recordedDuration = timecode.count();
161+
std::chrono::seconds timestamp) {
162+
auto recordedDurationSeconds = timestamp.count();
163163
m_trackList.append(
164164
QStringLiteral("%1: %2 - %3")
165165
.arg(QString("%1:%2:%3")
166-
.arg(recordedDuration / (60 * 60),
166+
.arg(recordedDurationSeconds / (60 * 60),
167167
2,
168168
'f',
169169
0,
170170
'0') // hours
171-
.arg((recordedDuration / 60) % 60,
171+
.arg((recordedDurationSeconds / 60) % 60,
172172
2,
173173
'f',
174174
0,
175175
'0') // minutes
176-
.arg(recordedDuration % 60, 2, 'f', 0, '0'),
176+
.arg(recordedDurationSeconds % 60, 2, 'f', 0, '0'),
177177
artist.trimmed().isEmpty()
178178
? QObject::tr("(Unknown Artist)")
179179
: artist,

src/encoder/encoder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ class Encoder {
3636
virtual void updateMetaData(const QString& artist,
3737
const QString& title,
3838
const QString& album,
39-
std::chrono::seconds timecode = {}) = 0;
39+
std::chrono::seconds timestamp = {}) = 0;
4040
// called at the end when encoding is finished
4141
virtual void flush() = 0;
4242
// Setup the encoder with the specific settings
4343
virtual void setEncoderSettings(const EncoderSettings& settings) = 0;
4444

4545
protected:
46-
void addToTracklist(const QString& artist, const QString& title, std::chrono::seconds timecode);
46+
void addToTracklist(const QString& artist,
47+
const QString& title,
48+
std::chrono::seconds timestamp);
4749
QStringList getTrackList() const {
4850
return m_trackList;
4951
}

src/encoder/encodermp3.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <lame/lame.h>
44
#include <limits.h>
55
#include <qbytearrayview.h>
6+
#include <qglobal.h>
67
#include <qobject.h>
78
#include <qstringliteral.h>
89

@@ -149,18 +150,19 @@ void EncoderMp3::flush() {
149150
// (ID3v2 & Xing frame) dynamically, but `EncoderCallback` doesn't support
150151
// that so we use the static header padding and truncate the tracklist if
151152
// too long
152-
size_t tracklistMaxSize = kHeaderPadding - numBytes -
153+
qsizetype tracklistMaxByteSize = kHeaderPadding - numBytes -
153154
lame_get_id3v2_tag(m_lameFlags, nullptr, 0);
154-
auto trackList = getTrackList().join("\n");
155+
QByteArray trackList = getTrackList().join("\n").toLocal8Bit();
155156
if (!trackList.isEmpty()) {
156157
// Because of the static header size offset, we need to ensure that the
157158
// tracklist comment won't make the header overflow on the MP3 frames,
158159
// we we truncate to the max value
159-
auto currentSize = static_cast<size_t>(trackList.size());
160-
if (currentSize > tracklistMaxSize - 1) { // -1 since we need a byte for the NULL terminator
161-
trackList = trackList.left(tracklistMaxSize - 4) + "...";
160+
qsizetype currentByteSize = trackList.size();
161+
if (currentByteSize > tracklistMaxByteSize -
162+
1) { // -1 since we need a byte for the NULL terminator
163+
trackList = trackList.left(tracklistMaxByteSize - 4) + "...";
162164
}
163-
id3tag_set_comment(m_lameFlags, trackList.toLatin1());
165+
id3tag_set_comment(m_lameFlags, trackList);
164166
}
165167

166168
size_t id3HeaderNumBytes = lame_get_id3v2_tag(m_lameFlags, nullptr, 0);

0 commit comments

Comments
 (0)