Skip to content

Commit

Permalink
Track: Make property naming consistent and use new NOTIFY signal scheme
Browse files Browse the repository at this point in the history
For native properties without any derived properties provide the new
value if possible. For properties with derived properties use the name
of the native property, reuse the signal for all derived properties, and
don't provide any value.
  • Loading branch information
Holzhaus committed May 29, 2021
1 parent 978ab2c commit 640a59d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 67 deletions.
48 changes: 22 additions & 26 deletions src/mixer/basetrackplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,7 @@ TrackPointer BaseTrackPlayerImpl::loadFakeTrack(bool bPlay, double filebpm) {
m_pLoadedTrack = pTrack;
if (m_pLoadedTrack) {
// Listen for updates to the file's BPM
connect(m_pLoadedTrack.get(),
&Track::bpmUpdated,
m_pFileBPM.get(),
QOverload<double>::of(&ControlObject::set));

connect(m_pLoadedTrack.get(),
&Track::keyUpdated,
m_pKey.get(),
&ControlProxy::set);

// Listen for updates to the file's Replay Gain
connect(m_pLoadedTrack.get(),
&Track::replayGainUpdated,
this,
&BaseTrackPlayerImpl::slotSetReplayGain);

connect(m_pLoadedTrack.get(),
&Track::colorUpdated,
this,
&BaseTrackPlayerImpl::slotSetTrackColor);
connectLoadedTrack();
}

// Request a new track from EngineBuffer
Expand Down Expand Up @@ -349,17 +330,32 @@ TrackPointer BaseTrackPlayerImpl::unloadTrack() {

void BaseTrackPlayerImpl::connectLoadedTrack() {
connect(m_pLoadedTrack.get(),
&Track::bpmUpdated,
m_pFileBPM.get(),
QOverload<double>::of(&ControlObject::set));
&Track::bpmChanged,
this,
[this] {
TrackPointer pTrack = m_pLoadedTrack;
if (pTrack) {
m_pFileBPM->set(pTrack->getBpm());
}
});

connect(m_pLoadedTrack.get(),
&Track::keyUpdated,
m_pKey.get(),
&ControlProxy::set);
&Track::keyChanged,
this,
[this] {
TrackPointer pTrack = m_pLoadedTrack;
if (pTrack) {
const auto key = pTrack->getKeys().getGlobalKey();
m_pKey->set(static_cast<double>(key));
}
});

// Listen for updates to the file's Replay Gain
connect(m_pLoadedTrack.get(),
&Track::replayGainUpdated,
this,
&BaseTrackPlayerImpl::slotSetReplayGain);

connect(m_pLoadedTrack.get(),
&Track::colorUpdated,
this,
Expand Down
35 changes: 10 additions & 25 deletions src/track/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ void Track::replaceMetadataFromSource(
beatsAndBpmModified = trySetBpmWhileLocked(importedBpm.getValue());
}
modified |= beatsAndBpmModified;
const auto newBpm = getBpmWhileLocked();

auto keysModified = false;
if (importedKey != mixxx::track::io::key::INVALID) {
Expand All @@ -190,7 +189,6 @@ void Track::replaceMetadataFromSource(
mixxx::track::io::key::FILE_METADATA);
}
modified |= keysModified;
const auto newKey = m_record.getGlobalKey();

// Import track color from Serato tags if available
const auto newColor = m_record.getMetadata().getTrackInfo().getSeratoTags().getTrackColor();
Expand All @@ -206,10 +204,10 @@ void Track::replaceMetadataFromSource(
markDirtyAndUnlock(&lock);

if (beatsAndBpmModified) {
emitBeatsAndBpmUpdated(newBpm);
emitBeatsAndBpmUpdated();
}
if (keysModified) {
emitKeysUpdated(newKey);
emit keyChanged();
}
if (oldReplayGain != newReplayGain) {
emit replayGainUpdated(newReplayGain);
Expand Down Expand Up @@ -304,12 +302,10 @@ bool Track::replaceRecord(
markDirtyAndUnlock(&locked);

if (bpmUpdatedFlag) {
emit bpmUpdated(newBpm.getValue());
emit beatsUpdated();
emit bpmTextChanged();
emitBeatsAndBpmUpdated();
}
if (oldKey != newKey) {
emitKeysUpdated(newKey);
emit keyChanged();
}
if (oldReplayGain != newReplayGain) {
emit replayGainUpdated(newReplayGain);
Expand Down Expand Up @@ -437,16 +433,13 @@ void Track::afterBeatsAndBpmUpdated(
QMutexLocker* pLock) {
DEBUG_ASSERT(pLock);

const auto bpm = getBpmWhileLocked();
markDirtyAndUnlock(pLock);
emitBeatsAndBpmUpdated(bpm);
emitBeatsAndBpmUpdated();
}

void Track::emitBeatsAndBpmUpdated(
mixxx::Bpm newBpm) {
emit bpmUpdated(newBpm.getValue());
void Track::emitBeatsAndBpmUpdated() {
emit bpmChanged();
emit beatsUpdated();
emit bpmTextChanged();
}

void Track::emitMetadataChanged() {
Expand All @@ -461,12 +454,11 @@ void Track::emitMetadataChanged() {
emit trackNumberChanged(getTrackNumber());
emit trackTotalChanged(getTrackTotal());
emit commentChanged(getComment());
emit bpmTextChanged();
emit bpmChanged();
emit timesPlayedChanged();
emit durationChanged();
emit infoChanged();
emit keysUpdated();
emit bpmUpdated(getBpm());
emit keyChanged();
}

void Track::setMetadataSynchronized(bool metadataSynchronized) {
Expand Down Expand Up @@ -1328,15 +1320,8 @@ void Track::setRating (int rating) {
}

void Track::afterKeysUpdated(QMutexLocker* pLock) {
const auto newKey = m_record.getGlobalKey();
markDirtyAndUnlock(pLock);
emitKeysUpdated(newKey);
}

void Track::emitKeysUpdated(mixxx::track::io::key::ChromaticKey newKey) {
// New key might be INVALID. We don't care.
emit keyUpdated(KeyUtils::keyToNumericValue(newKey));
emit keysUpdated();
emit keyChanged();
}

void Track::setKeys(const Keys& keys) {
Expand Down
26 changes: 10 additions & 16 deletions src/track/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,15 @@ class Track : public QObject {
Q_PROPERTY(QString trackTotal READ getTrackTotal WRITE setTrackTotal NOTIFY trackTotalChanged)
Q_PROPERTY(int timesPlayed READ getTimesPlayed NOTIFY timesPlayedChanged)
Q_PROPERTY(QString comment READ getComment WRITE setComment NOTIFY commentChanged)
Q_PROPERTY(double bpm READ getBpm NOTIFY bpmUpdated)
Q_PROPERTY(QString bpmFormatted READ getBpmText STORED false NOTIFY bpmTextChanged)
Q_PROPERTY(QString key READ getKeyText WRITE setKeyText NOTIFY keysUpdated)
Q_PROPERTY(double bpm READ getBpm NOTIFY bpmChanged)
Q_PROPERTY(QString bpmText READ getBpmText STORED false NOTIFY bpmChanged)
Q_PROPERTY(QString keyText READ getKeyText WRITE setKeyText NOTIFY keyChanged)
Q_PROPERTY(double duration READ getDuration NOTIFY durationChanged)
Q_PROPERTY(QString durationFormatted READ getDurationTextSeconds
Q_PROPERTY(QString durationText READ getDurationTextSeconds STORED false NOTIFY durationChanged)
Q_PROPERTY(QString durationTextCentiseconds READ getDurationTextCentiseconds
STORED false NOTIFY durationChanged)
Q_PROPERTY(QString durationTextMilliseconds READ getDurationTextMilliseconds
STORED false NOTIFY durationChanged)
Q_PROPERTY(QString durationFormattedCentiseconds READ
getDurationTextCentiseconds
STORED false NOTIFY durationChanged)
Q_PROPERTY(QString durationFormattedMilliseconds READ
getDurationTextMilliseconds
STORED false NOTIFY durationChanged)
Q_PROPERTY(QString info READ getInfo STORED false NOTIFY infoChanged)
Q_PROPERTY(QString titleInfo READ getTitleInfo STORED false NOTIFY infoChanged)

Expand Down Expand Up @@ -381,18 +378,16 @@ class Track : public QObject {
void trackNumberChanged(const QString&);
void trackTotalChanged(const QString&);
void commentChanged(const QString&);
void bpmTextChanged();
void bpmChanged();
void keyChanged();
void timesPlayedChanged();
void durationChanged();
void infoChanged();

void waveformUpdated();
void waveformSummaryUpdated();
void coverArtUpdated();
void bpmUpdated(double bpm);
void beatsUpdated();
void keyUpdated(double key);
void keysUpdated();
void replayGainUpdated(mixxx::ReplayGain replayGain);
void colorUpdated(const mixxx::RgbColor::optional_t& color);
void cuesUpdated();
Expand Down Expand Up @@ -424,10 +419,9 @@ class Track : public QObject {
void setDirtyAndUnlock(QMutexLocker* pLock, bool bDirty);

void afterKeysUpdated(QMutexLocker* pLock);
void emitKeysUpdated(mixxx::track::io::key::ChromaticKey newKey);

void afterBeatsAndBpmUpdated(QMutexLocker* pLock);
void emitBeatsAndBpmUpdated(mixxx::Bpm newBpm);
void emitBeatsAndBpmUpdated();

/// Emits a changed signal for each Q_PROPERTY
void emitMetadataChanged();
Expand Down

0 comments on commit 640a59d

Please sign in to comment.