mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-29 19:20:28 +00:00
Added a Replay Gain indicator to the transport view when the current
song has RG applied to it.
This commit is contained in:
parent
42075e3e7f
commit
fcc817ab6a
@ -154,15 +154,11 @@ void LibraryLayout::ShowTrackSearch() {
|
||||
|
||||
void LibraryLayout::InitializeWindows() {
|
||||
this->browseLayout.reset(new BrowseLayout(this->playback, this->library));
|
||||
|
||||
this->nowPlayingLayout.reset(new NowPlayingLayout(this->playback, this->library));
|
||||
|
||||
this->searchLayout.reset(new SearchLayout(this->playback, this->library));
|
||||
this->searchLayout->SearchResultSelected.connect(this, &LibraryLayout::OnSearchResultSelected);
|
||||
|
||||
this->trackSearch.reset(new TrackSearchLayout(this->playback, this->library));
|
||||
|
||||
this->transportView.reset(new TransportWindow(this->playback));
|
||||
this->transportView.reset(new TransportWindow(this->library, this->playback));
|
||||
|
||||
this->AddWindow(this->transportView);
|
||||
this->ShowBrowse();
|
||||
|
@ -44,6 +44,8 @@
|
||||
|
||||
#include <core/debug.h>
|
||||
#include <core/library/LocalLibraryConstants.h>
|
||||
#include <core/library/query/local/ReplayGainQuery.h>
|
||||
#include <core/support/PreferenceKeys.h>
|
||||
#include <core/runtime/Message.h>
|
||||
|
||||
#include <app/util/Hotkeys.h>
|
||||
@ -304,12 +306,16 @@ static inline bool dec(const std::string& kn) {
|
||||
return (Hotkeys::Is(Hotkeys::Left, kn));
|
||||
}
|
||||
|
||||
TransportWindow::TransportWindow(musik::core::audio::PlaybackService& playback)
|
||||
TransportWindow::TransportWindow(
|
||||
musik::core::ILibraryPtr library,
|
||||
musik::core::audio::PlaybackService& playback)
|
||||
: Window(nullptr)
|
||||
, library(library)
|
||||
, displayCache(new TransportDisplayCache())
|
||||
, playback(playback)
|
||||
, transport(playback.GetTransport())
|
||||
, focus(FocusNone) {
|
||||
, focus(FocusNone)
|
||||
, hasReplayGain(false) {
|
||||
Strings.Initialize();
|
||||
this->SetFrameVisible(false);
|
||||
this->playback.TrackChanged.connect(this, &TransportWindow::OnPlaybackServiceTrackChanged);
|
||||
@ -418,6 +424,7 @@ void TransportWindow::ProcessMessage(IMessage &message) {
|
||||
void TransportWindow::OnPlaybackServiceTrackChanged(size_t index, TrackPtr track) {
|
||||
this->currentTrack = track;
|
||||
this->lastTime = DEFAULT_TIME;
|
||||
this->UpdateReplayGainState();
|
||||
DEBOUNCE_REFRESH(TimeSync, 0);
|
||||
}
|
||||
|
||||
@ -441,6 +448,30 @@ void TransportWindow::OnRedraw() {
|
||||
this->Update();
|
||||
}
|
||||
|
||||
void TransportWindow::UpdateReplayGainState() {
|
||||
using Mode = prefs::values::ReplayGainMode;
|
||||
using Query = db::local::ReplayGainQuery;
|
||||
|
||||
this->hasReplayGain = false;
|
||||
auto prefs = Preferences::ForComponent(prefs::components::Playback);
|
||||
|
||||
prefs::values::ReplayGainMode mode = (Mode)
|
||||
prefs->GetInt(prefs::keys::ReplayGainMode.c_str(), (int)Mode::Disabled);
|
||||
|
||||
if (mode != Mode::Disabled) {
|
||||
if (this->currentTrack) {
|
||||
auto query = std::make_shared<Query>(this->currentTrack->GetId());
|
||||
if (this->library->Enqueue(query, ILibrary::QuerySynchronous)) {
|
||||
auto result = query->GetResult();
|
||||
|
||||
this->hasReplayGain = result && (
|
||||
result->albumGain != 1.0f || result->albumPeak != 1.0f ||
|
||||
result->trackGain != 1.0f || result->albumPeak != 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TransportWindow::Update(TimeMode timeMode) {
|
||||
this->Clear();
|
||||
|
||||
@ -513,7 +544,7 @@ void TransportWindow::Update(TimeMode timeMode) {
|
||||
volume += boost::str(boost::format(
|
||||
" %d") % (int)std::round(this->transport.Volume() * 100));
|
||||
|
||||
volume += "%% ";
|
||||
volume += this->hasReplayGain ? "%% " : "%% ";
|
||||
}
|
||||
|
||||
/* repeat mode setup */
|
||||
@ -577,8 +608,11 @@ void TransportWindow::Update(TimeMode timeMode) {
|
||||
const std::string currentTime = musik::glue::duration::Duration(
|
||||
std::min(secondsCurrent, displayCache->secondsTotal));
|
||||
|
||||
const std::string replayGain = this->hasReplayGain ? "RG " : "";
|
||||
|
||||
int bottomRowControlsWidth =
|
||||
displayCache->Columns(volume) - (muted ? 0 : 1) + /* -1 for escaped percent sign when not muted */
|
||||
u8cols(replayGain) +
|
||||
u8cols(currentTime) + 1 + /* +1 for space padding */
|
||||
/* timer track with thumb */
|
||||
1 + displayCache->totalTimeCols + /* +1 for space padding */
|
||||
@ -608,6 +642,10 @@ void TransportWindow::Update(TimeMode timeMode) {
|
||||
checked_wprintw(c, volume.c_str());
|
||||
OFF(c, volumeAttrs);
|
||||
|
||||
ON(c, gb);
|
||||
checked_wprintw(c, "%s", replayGain.c_str());
|
||||
OFF(c, gb);
|
||||
|
||||
ON(c, currentTimeAttrs); /* blink if paused */
|
||||
checked_wprintw(c, "%s ", currentTime.c_str());
|
||||
OFF(c, currentTimeAttrs);
|
||||
|
@ -60,7 +60,10 @@ namespace musik {
|
||||
FocusTime = 2
|
||||
};
|
||||
|
||||
TransportWindow(musik::core::audio::PlaybackService& playback);
|
||||
TransportWindow(
|
||||
musik::core::ILibraryPtr library,
|
||||
musik::core::audio::PlaybackService& playback);
|
||||
|
||||
virtual ~TransportWindow();
|
||||
|
||||
virtual void ProcessMessage(musik::core::runtime::IMessage &message);
|
||||
@ -90,8 +93,11 @@ namespace musik {
|
||||
void OnTransportVolumeChanged();
|
||||
void OnTransportTimeChanged(double time);
|
||||
void OnPlaybackShuffled(bool shuffled);
|
||||
void UpdateReplayGainState();
|
||||
|
||||
bool paused;
|
||||
bool hasReplayGain;
|
||||
musik::core::ILibraryPtr library;
|
||||
musik::core::audio::ITransport& transport;
|
||||
musik::core::audio::PlaybackService& playback;
|
||||
musik::core::TrackPtr currentTrack;
|
||||
|
Loading…
x
Reference in New Issue
Block a user