diff --git a/src/musikcube/CMakeLists.txt b/src/musikcube/CMakeLists.txt index 30060590a..6bc9927df 100644 --- a/src/musikcube/CMakeLists.txt +++ b/src/musikcube/CMakeLists.txt @@ -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 diff --git a/src/musikcube/app/overlay/EqualizerOverlay.cpp b/src/musikcube/app/overlay/EqualizerOverlay.cpp new file mode 100644 index 000000000..aebd3f765 --- /dev/null +++ b/src/musikcube/app/overlay/EqualizerOverlay.cpp @@ -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 +#include + +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 EqualizerOverlay::FindPlugin() { + std::shared_ptr result; + using Deleter = PluginFactory::ReleaseDeleter; + PluginFactory::Instance().QueryInterface( + "GetPlugin", + [&result](IPlugin* unused, std::shared_ptr plugin, const std::string& fn) { + if (std::string(plugin->Guid()) == SUPEREQ_PLUGIN_GUID) { + result = plugin; + } + }); + return result; +} diff --git a/src/musikcube/app/overlay/EqualizerOverlay.h b/src/musikcube/app/overlay/EqualizerOverlay.h new file mode 100644 index 000000000..e34ce12e0 --- /dev/null +++ b/src/musikcube/app/overlay/EqualizerOverlay.h @@ -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 +#include +#include +#include +#include +#include +#include + +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 +#endif + { + public: + static void ShowOverlay(); + static std::shared_ptr FindPlugin(); + + virtual void Layout() override; + virtual bool KeyPress(const std::string& key) override; + + private: + EqualizerOverlay(); + + std::shared_ptr plugin; + std::shared_ptr prefs; + std::shared_ptr enabledCb; + std::shared_ptr listView; + }; + } +} diff --git a/src/musikcube/app/overlay/ServerOverlay.cpp b/src/musikcube/app/overlay/ServerOverlay.cpp index 6f2594686..a8e2129f2 100644 --- a/src/musikcube/app/overlay/ServerOverlay.cpp +++ b/src/musikcube/app/overlay/ServerOverlay.cpp @@ -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())) diff --git a/src/musikcube/app/util/GlobalHotkeys.cpp b/src/musikcube/app/util/GlobalHotkeys.cpp index f7c4d271c..eead00cbe 100755 --- a/src/musikcube/app/util/GlobalHotkeys.cpp +++ b/src/musikcube/app/util/GlobalHotkeys.cpp @@ -36,12 +36,12 @@ #include "GlobalHotkeys.h" #include "Hotkeys.h" -#include #include +#include +#include #include #include - #include 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; } diff --git a/src/musikcube/app/util/Hotkeys.cpp b/src/musikcube/app/util/Hotkeys.cpp index ece849c5d..ad24e1e1b 100755 --- a/src/musikcube/app/util/Hotkeys.cpp +++ b/src/musikcube/app/util/Hotkeys.cpp @@ -114,6 +114,8 @@ static std::unordered_map 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_TO_DEFAULT = { { Id::ToggleVisualizer, "v" }, + { Id::ShowEqualizer, "^E" }, + { Id::RescanMetadata, "^R"}, { Id::HotkeysResetToDefault, "M-r" }, diff --git a/src/musikcube/app/util/Hotkeys.h b/src/musikcube/app/util/Hotkeys.h index 62ccd8f7f..2a6151c04 100755 --- a/src/musikcube/app/util/Hotkeys.h +++ b/src/musikcube/app/util/Hotkeys.h @@ -74,6 +74,7 @@ namespace musik { /* views */ ViewRefresh, ToggleVisualizer, + ShowEqualizer, /* playback */ ToggleMute, diff --git a/src/musikcube/cursespp/Colors.h b/src/musikcube/cursespp/Colors.h index c313970fb..85ff3eabb 100755 --- a/src/musikcube/cursespp/Colors.h +++ b/src/musikcube/cursespp/Colors.h @@ -35,6 +35,7 @@ #pragma once #include "curses_config.h" +#include #define CURSESPP_DEFAULT_COLOR -1LL diff --git a/src/musikcube/cursespp/OverlayBase.h b/src/musikcube/cursespp/OverlayBase.h index 3b7b47495..c4d3b31e5 100644 --- a/src/musikcube/cursespp/OverlayBase.h +++ b/src/musikcube/cursespp/OverlayBase.h @@ -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; }