Ensure EqualizerOverlay stays in sync with settings from the remote client.

This commit is contained in:
casey langen 2018-12-28 13:55:43 -08:00
parent 5e0c230470
commit 458bbbb8e8
3 changed files with 21 additions and 2 deletions

View File

@ -84,6 +84,13 @@ static void saveEnvironment() {
}
}
static void broadcastEqualizerUpdated() {
if (::messageQueue) {
::messageQueue->Broadcast(
Message::Create(nullptr, message::EqualizerUpdated));
}
}
static void getEqualizerPluginAndPrefs(
std::shared_ptr<IPlugin>& plugin,
std::shared_ptr<Preferences>& prefs)
@ -275,6 +282,7 @@ static class Environment: public IEnvironment {
for (size_t i = 0; i < EqualizerBandCount; i++) {
target[i] = prefs->GetDouble(std::to_string(EqualizerBands[i]), 0.0);
}
return true;
}
@ -295,6 +303,7 @@ static class Environment: public IEnvironment {
prefs->SetDouble(std::to_string(EqualizerBands[i]), values[i]);
}
plugin->Reload();
broadcastEqualizerUpdated();
return true;
}
@ -314,7 +323,7 @@ static class Environment: public IEnvironment {
}
virtual void SetEqualizerEnabled(bool enabled) {
virtual void SetEqualizerEnabled(bool enabled) override {
std::shared_ptr<IPlugin> plugin;
std::shared_ptr<Preferences> prefs;
getEqualizerPluginAndPrefs(plugin, prefs);
@ -323,6 +332,7 @@ static class Environment: public IEnvironment {
if (prefs->GetBool("enabled", false) != enabled) {
prefs->SetBool("enabled", enabled);
plugin->Reload();
broadcastEqualizerUpdated();
}
}
}

View File

@ -44,6 +44,7 @@ namespace musik {
static const int PlaylistRenamed = First + 3;
static const int PlaylistDeleted = First + 4;
static const int EnvironmentUpdated = First + 5;
static const int EqualizerUpdated = First + 6;
static const int User = 4096;
}

View File

@ -42,6 +42,7 @@
#include <cursespp/SingleLineEntry.h>
#include <cursespp/Text.h>
#include <core/support/Messages.h>
#include <core/plugin/PluginFactory.h>
#include <app/util/Messages.h>
@ -143,10 +144,13 @@ EqualizerOverlay::EqualizerOverlay()
}
EqualizerOverlay::~EqualizerOverlay() {
MessageQueue().UnregisterForBroadcasts(this);
}
void EqualizerOverlay::ShowOverlay() {
App::Overlays().Push(std::make_shared<EqualizerOverlay>());
auto overlay = std::make_shared<EqualizerOverlay>();
App::Overlays().Push(overlay);
MessageQueue().RegisterForBroadcasts(overlay);
}
std::shared_ptr<IPlugin> EqualizerOverlay::FindPlugin() {
@ -214,6 +218,10 @@ void EqualizerOverlay::ProcessMessage(musik::core::runtime::IMessage &message) {
if (message.Type() == message::UpdateEqualizer) {
this->plugin->Reload();
}
else if (message.Type() == musik::core::message::EqualizerUpdated) {
this->enabledCb->SetChecked(this->prefs->GetBool("enabled", false));
this->listView->OnAdapterChanged();
}
}
void EqualizerOverlay::UpdateSelectedBand(double delta) {