blob: 8085e260b557ec432c2d1e9088a5d8d873052aaa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#include "track/trackmetadata.h"
#include "audio/streaminfo.h"
#include "util/logger.h"
namespace mixxx {
namespace {
const Logger kLogger("TrackMetadata");
} // anonymous namespace
/*static*/ constexpr int TrackMetadata::kCalendarYearInvalid;
bool TrackMetadata::updateAudioPropertiesFromStream(
const audio::StreamInfo& streamInfo) {
bool changed = false;
const auto streamChannelCount =
streamInfo.getSignalInfo().getChannelCount();
if (streamChannelCount.isValid() &&
streamChannelCount != getChannelCount()) {
if (getChannelCount().isValid()) {
kLogger.debug()
<< "Modifying channel count:"
<< getChannelCount()
<< "->"
<< streamChannelCount;
}
setChannelCount(streamChannelCount);
changed = true;
}
const auto streamSampleRate =
streamInfo.getSignalInfo().getSampleRate();
if (streamSampleRate.isValid() &&
streamSampleRate != getSampleRate()) {
if (getSampleRate().isValid()) {
kLogger.debug()
<< "Modifying sample rate:"
<< getSampleRate()
<< "->"
<< streamSampleRate;
}
setSampleRate(streamSampleRate);
changed = true;
}
const auto streamBitrate =
streamInfo.getBitrate();
if (streamBitrate.isValid() &&
streamBitrate != getBitrate()) {
if (getBitrate().isValid()) {
kLogger.debug()
<< "Modifying bitrate:"
<< getBitrate()
<< "->"
<< streamBitrate;
}
setBitrate(streamBitrate);
changed = true;
}
const auto streamDuration =
streamInfo.getDuration();
if (streamDuration > Duration::empty() &&
streamDuration != getDuration()) {
if (getDuration() > Duration::empty()) {
kLogger.debug()
<< "Modifying duration:"
<< getDuration()
<< "->"
<< streamDuration;
}
setDuration(streamDuration);
changed = true;
}
return changed;
}
int TrackMetadata::parseCalendarYear(QString year, bool* pValid) {
const QDateTime dateTime(parseDateTime(year));
if (0 < dateTime.date().year()) {
if (pValid) {
*pValid = true;
}
return dateTime.date().year();
} else {
bool calendarYearValid = false;
// Ignore everything beginning with the first dash '-'
// to successfully parse the calendar year of incomplete
// dates like yyyy-MM or 2015-W07.
const QString calendarYearSection(year.section('-', 0, 0).trimmed());
const int calendarYear = calendarYearSection.toInt(&calendarYearValid);
if (calendarYearValid) {
calendarYearValid = 0 < calendarYear;
}
if (pValid) {
*pValid = calendarYearValid;
}
if (calendarYearValid) {
return calendarYear;
} else {
return kCalendarYearInvalid;
}
}
}
QString TrackMetadata::formatCalendarYear(QString year, bool* pValid) {
bool calendarYearValid = false;
int calendarYear = parseCalendarYear(year, &calendarYearValid);
if (pValid) {
*pValid = calendarYearValid;
}
if (calendarYearValid) {
return QString::number(calendarYear);
} else {
return QString(); // empty string
}
}
QString TrackMetadata::reformatYear(QString year) {
const QDateTime dateTime(parseDateTime(year));
if (dateTime.isValid()) {
// date/time
return formatDateTime(dateTime);
}
const QDate date(dateTime.date());
if (date.isValid()) {
// only date
return formatDate(date);
}
bool calendarYearValid = false;
const QString calendarYear(formatCalendarYear(year, &calendarYearValid));
if (calendarYearValid) {
// only calendar year
return calendarYear;
}
// just trim and simplify whitespaces
return year.simplified();
}
void TrackMetadata::normalizeBeforeExport() {
refAlbumInfo().normalizeBeforeExport();
refTrackInfo().normalizeBeforeExport();
}
bool TrackMetadata::anyFileTagsModified(
const TrackMetadata& importedFromFile,
Bpm::Comparison cmpBpm) const {
// NOTE(uklotzde): The read-only audio properties that are stored
// directly as members of this class might differ after they have
// been updated while decoding audio data. They are read-only and
// must not be considered when exporting metadata!
return getAlbumInfo() != importedFromFile.getAlbumInfo() ||
!getTrackInfo().compareEq(importedFromFile.getTrackInfo(), cmpBpm);
}
bool operator==(const TrackMetadata& lhs, const TrackMetadata& rhs) {
return lhs.getAlbumInfo() == rhs.getAlbumInfo() &&
lhs.getTrackInfo() == rhs.getTrackInfo() &&
lhs.getChannelCount() == rhs.getChannelCount() &&
lhs.getSampleRate() == rhs.getSampleRate() &&
lhs.getBitrate() == rhs.getBitrate() &&
lhs.getDuration() == rhs.getDuration();
}
QDebug operator<<(QDebug dbg, const TrackMetadata& arg) {
dbg << "TrackMetadata{";
arg.dbgTrackInfo(dbg);
arg.dbgAlbumInfo(dbg);
arg.dbgBitrate(dbg);
arg.dbgChannelCount(dbg);
arg.dbgDuration(dbg);
arg.dbgSampleRate(dbg);
dbg << '}';
return dbg;
}
} //namespace mixxx
|