Started stubbing out an EqualizerOverlay

This commit is contained in:
casey langen 2018-12-18 19:35:05 -08:00
parent b190afd805
commit db37f5e5f0
9 changed files with 183 additions and 24 deletions

View File

@ -15,6 +15,7 @@ set (CUBE_SRCS
./app/model/HotkeysAdapter.cpp
./app/overlay/BrowseOverlays.cpp
./app/overlay/ColorThemeOverlay.cpp
./app/overlay/EqualizerOverlay.cpp
./app/overlay/LastFmOverlay.cpp
./app/overlay/LocaleOverlay.cpp
./app/overlay/PlaybackOverlays.cpp

View File

@ -0,0 +1,74 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2017 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "EqualizerOverlay.h"
#include <cursespp/Screen.h>
#include <core/plugin/PluginFactory.h>
using namespace cursespp;
using namespace musik::core;
using namespace musik::core::sdk;
using namespace musik::cube;
static const std::string SUPEREQ_PLUGIN_GUID = "6f0ed53b-0f13-4220-9b0a-ca496b6421cc";
static std::string formatBandRow(const std::string& band, float value) {
return band + "khz";
}
static int calculateWidth() {
return (int)(0.8f * Screen::GetWidth());
}
EqualizerOverlay::EqualizerOverlay()
: OverlayBase() {
this->plugin = this->FindPlugin();
this->prefs = Preferences::ForPlugin(this->plugin->Name());
}
void EqualizerOverlay::ShowOverlay() {
}
std::shared_ptr<IPlugin> EqualizerOverlay::FindPlugin() {
std::shared_ptr<IPlugin> result;
using Deleter = PluginFactory::ReleaseDeleter<IPlugin>;
PluginFactory::Instance().QueryInterface<IPlugin, Deleter>(
"GetPlugin",
[&result](IPlugin* unused, std::shared_ptr<IPlugin> plugin, const std::string& fn) {
if (std::string(plugin->Guid()) == SUPEREQ_PLUGIN_GUID) {
result = plugin;
}
});
return result;
}

View File

@ -0,0 +1,68 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2017 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <core/sdk/IPlugin.h>
#include <core/support/Preferences.h>
#include <cursespp/OverlayBase.h>
#include <cursespp/Checkbox.h>
#include <cursespp/ListWindow.h>
#include <sigslot/sigslot.h>
#include <memory>
namespace musik {
namespace cube {
class EqualizerOverlay: public cursespp::OverlayBase, public sigslot::has_slots<>
#if (__clang_major__ == 7 && __clang_minor__ == 3)
, public std::enable_shared_from_this<EqualizerOverlay>
#endif
{
public:
static void ShowOverlay();
static std::shared_ptr<musik::core::sdk::IPlugin> FindPlugin();
virtual void Layout() override;
virtual bool KeyPress(const std::string& key) override;
private:
EqualizerOverlay();
std::shared_ptr<musik::core::sdk::IPlugin> plugin;
std::shared_ptr<musik::core::Preferences> prefs;
std::shared_ptr<cursespp::Checkbox> enabledCb;
std::shared_ptr<cursespp::ListWindow> listView;
};
}
}

View File

@ -65,28 +65,6 @@ static const char* KEY_PASSWORD = "password";
#define DEFAULT_HEIGHT 18
#define DEFAULT_WIDTH 45
static void applyLabelOverlayStyle(TextLabel& label) {
label.SetContentColor(CURSESPP_OVERLAY_CONTENT);
}
static void applyCheckboxOverlayStyle(Checkbox& cb) {
cb.SetContentColor(CURSESPP_OVERLAY_CONTENT);
cb.SetFocusedContentColor(CURSESPP_OVERLAY_TEXT_FOCUSED);
}
static void applyInputOverlayStyle(TextInput& input) {
if (input.GetStyle() == TextInput::StyleBox) {
input.SetFrameColor(CURSESPP_OVERLAY_FRAME);
input.SetContentColor(CURSESPP_OVERLAY_CONTENT);
input.SetFocusedFrameColor(CURSESPP_OVERLAY_INPUT_FRAME);
input.SetFocusedContentColor(CURSESPP_OVERLAY_CONTENT);
}
else {
input.SetContentColor(CURSESPP_OVERLAY_CONTENT);
input.SetFocusedContentColor(CURSESPP_OVERLAY_TEXT_FOCUSED);
}
}
#define RIGHT(x) (x->GetX() + x->GetWidth())
#define TEXT_WIDTH(x) ((int) u8cols(x->GetText()))

View File

@ -36,12 +36,12 @@
#include "GlobalHotkeys.h"
#include "Hotkeys.h"
#include <app/overlay/VisualizerOverlay.h>
#include <app/overlay/BrowseOverlays.h>
#include <app/overlay/EqualizerOverlay.h>
#include <app/overlay/VisualizerOverlay.h>
#include <app/util/Playback.h>
#include <core/audio/Visualizer.h>
#include <core/support/Playback.h>
using namespace musik::core;
@ -126,6 +126,12 @@ bool GlobalHotkeys::Handle(const std::string& kn) {
}
return true;
}
else if (Hotkeys::Is(Hotkeys::ShowEqualizer, kn)) {
if (EqualizerOverlay::FindPlugin()) {
EqualizerOverlay::ShowOverlay();
}
return true;
}
return false;
}

View File

@ -114,6 +114,8 @@ static std::unordered_map<std::string, Id> NAME_TO_ID = {
{ "toggle_visualizer", Id::ToggleVisualizer },
{ "show_equalizer", Id::ShowEqualizer },
{ "metadata_rescan", Id::RescanMetadata },
{ "hotkeys_reset_to_default", Id::HotkeysResetToDefault },
@ -195,6 +197,8 @@ static std::unordered_map<Id, std::string, EnumHasher> ID_TO_DEFAULT = {
{ Id::ToggleVisualizer, "v" },
{ Id::ShowEqualizer, "^E" },
{ Id::RescanMetadata, "^R"},
{ Id::HotkeysResetToDefault, "M-r" },

View File

@ -74,6 +74,7 @@ namespace musik {
/* views */
ViewRefresh,
ToggleVisualizer,
ShowEqualizer,
/* playback */
ToggleMute,

View File

@ -35,6 +35,7 @@
#pragma once
#include "curses_config.h"
#include <string>
#define CURSESPP_DEFAULT_COLOR -1LL

View File

@ -34,9 +34,13 @@
#pragma once
#include "Colors.h"
#include "IOverlay.h"
#include "LayoutBase.h"
#include "OverlayStack.h"
#include "TextLabel.h"
#include "Checkbox.h"
#include "TextInput.h"
namespace cursespp {
class OverlayBase : public LayoutBase, public IOverlay {
@ -68,6 +72,28 @@ namespace cursespp {
}
protected:
static void applyLabelOverlayStyle(TextLabel& label) {
label.SetContentColor(CURSESPP_OVERLAY_CONTENT);
}
static void applyCheckboxOverlayStyle(Checkbox& cb) {
cb.SetContentColor(CURSESPP_OVERLAY_CONTENT);
cb.SetFocusedContentColor(CURSESPP_OVERLAY_TEXT_FOCUSED);
}
static void applyInputOverlayStyle(TextInput& input) {
if (input.GetStyle() == TextInput::StyleBox) {
input.SetFrameColor(CURSESPP_OVERLAY_FRAME);
input.SetContentColor(CURSESPP_OVERLAY_CONTENT);
input.SetFocusedFrameColor(CURSESPP_OVERLAY_INPUT_FRAME);
input.SetFocusedContentColor(CURSESPP_OVERLAY_CONTENT);
}
else {
input.SetContentColor(CURSESPP_OVERLAY_CONTENT);
input.SetFocusedContentColor(CURSESPP_OVERLAY_TEXT_FOCUSED);
}
}
OverlayStack* GetOverlayStack() {
return this->stack;
}