Actually implementing the auto replay gain mode
This commit is contained in:
@@ -182,7 +182,7 @@ PlayQueue::updateRadioBtn()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Database::TrackList::pointer
|
Database::TrackList::pointer
|
||||||
PlayQueue::getTrackList()
|
PlayQueue::getTrackList() const
|
||||||
{
|
{
|
||||||
return Database::TrackList::getById(LmsApp->getDbSession(), _tracklistId);
|
return Database::TrackList::getById(LmsApp->getDbSession(), _tracklistId);
|
||||||
}
|
}
|
||||||
@@ -242,7 +242,7 @@ PlayQueue::loadTrack(std::size_t pos, bool play)
|
|||||||
|
|
||||||
trackId = track.id();
|
trackId = track.id();
|
||||||
|
|
||||||
replayGain = getReplayGain(track);
|
replayGain = getReplayGain(pos, track);
|
||||||
|
|
||||||
if (!LmsApp->getUser()->isDemo())
|
if (!LmsApp->getUser()->isDemo())
|
||||||
LmsApp->getUser().modify()->setCurPlayingTrackPos(pos);
|
LmsApp->getUser().modify()->setCurPlayingTrackPos(pos);
|
||||||
@@ -442,27 +442,52 @@ PlayQueue::enqueueRadioTrack()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::optional<float>
|
std::optional<float>
|
||||||
PlayQueue::getReplayGain(const Database::Track::pointer& track) const
|
PlayQueue::getReplayGain(std::size_t pos, const Database::Track::pointer& track) const
|
||||||
{
|
{
|
||||||
const auto& settings {LmsApp->getMediaPlayer()->getSettings()};
|
const auto& settings {LmsApp->getMediaPlayer()->getSettings()};
|
||||||
if (!settings)
|
if (!settings)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
|
std::optional<MediaPlayer::Gain> gain;
|
||||||
|
|
||||||
switch (settings->replayGain.mode)
|
switch (settings->replayGain.mode)
|
||||||
{
|
{
|
||||||
case MediaPlayer::Settings::ReplayGain::Mode::None:
|
case MediaPlayer::Settings::ReplayGain::Mode::None:
|
||||||
return std::nullopt;
|
break;
|
||||||
|
|
||||||
case MediaPlayer::Settings::ReplayGain::Mode::Track:
|
case MediaPlayer::Settings::ReplayGain::Mode::Track:
|
||||||
return track->getTrackReplayGain();
|
gain = track->getTrackReplayGain();
|
||||||
|
break;
|
||||||
|
|
||||||
case MediaPlayer::Settings::ReplayGain::Mode::Release:
|
case MediaPlayer::Settings::ReplayGain::Mode::Release:
|
||||||
return track->getReleaseReplayGain();
|
gain = track->getReleaseReplayGain();
|
||||||
|
break;
|
||||||
|
|
||||||
case MediaPlayer::Settings::ReplayGain::Mode::Auto:
|
case MediaPlayer::Settings::ReplayGain::Mode::Auto:
|
||||||
return track->getTrackReplayGain();
|
{
|
||||||
|
const auto trackList {getTrackList()};
|
||||||
|
const auto prevEntry {pos > 0 ? trackList->getEntry(pos - 1) : Database::TrackListEntry::pointer {}};
|
||||||
|
const auto nextEntry {trackList->getEntry(pos + 1)};
|
||||||
|
const Database::Track::pointer prevTrack {prevEntry ? prevEntry->getTrack() : Database::Track::pointer {}};
|
||||||
|
const Database::Track::pointer nextTrack {nextEntry ? nextEntry->getTrack() : Database::Track::pointer {}};
|
||||||
|
|
||||||
|
if ((prevTrack && prevTrack->getRelease() && prevTrack->getRelease() == track->getRelease())
|
||||||
|
||
|
||||||
|
(nextTrack && nextTrack->getRelease() && nextTrack->getRelease() == track->getRelease()))
|
||||||
|
{
|
||||||
|
gain = track->getReleaseReplayGain();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gain = track->getTrackReplayGain();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gain)
|
||||||
|
return *gain + settings->replayGain.preAmpGain;
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class PlayQueue : public Wt::WTemplate
|
|||||||
Wt::Signal<> trackUnselected;
|
Wt::Signal<> trackUnselected;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Wt::Dbo::ptr<Database::TrackList> getTrackList();
|
Wt::Dbo::ptr<Database::TrackList> getTrackList() const;
|
||||||
|
|
||||||
void clearTracks();
|
void clearTracks();
|
||||||
void enqueueTracks(const std::vector<Database::IdType>& trackIds);
|
void enqueueTracks(const std::vector<Database::IdType>& trackIds);
|
||||||
@@ -77,7 +77,7 @@ class PlayQueue : public Wt::WTemplate
|
|||||||
|
|
||||||
void addRadioTrackFromSimilarity(std::shared_ptr<Similarity::Finder> similarityFinder);
|
void addRadioTrackFromSimilarity(std::shared_ptr<Similarity::Finder> similarityFinder);
|
||||||
void addRadioTrackFromClusters();
|
void addRadioTrackFromClusters();
|
||||||
std::optional<float> getReplayGain(const Wt::Dbo::ptr<Database::Track>& track) const;
|
std::optional<float> getReplayGain(std::size_t pos, const Wt::Dbo::ptr<Database::Track>& track) const;
|
||||||
|
|
||||||
bool _repeatAll {};
|
bool _repeatAll {};
|
||||||
bool _radioMode {};
|
bool _radioMode {};
|
||||||
|
|||||||
Reference in New Issue
Block a user