diff --git a/src/core/audio/Visualizer.cpp b/src/core/audio/Visualizer.cpp index 5557abb6d..815ea77b4 100644 --- a/src/core/audio/Visualizer.cpp +++ b/src/core/audio/Visualizer.cpp @@ -37,39 +37,70 @@ #include #include +#include using namespace musik::core::audio; -static std::vector > spectrumVisualizers; -static std::vector > pcmVisualizers; +static std::vector > visualizers; static std::atomic initialized; static std::shared_ptr selectedVisualizer; static ISpectrumVisualizer* spectrumVisualizer = nullptr; static IPcmVisualizer* pcmVisualizer = nullptr; +#define LOWER(x) std::transform(x.begin(), x.end(), x.begin(), tolower); + namespace musik { namespace core { namespace audio { namespace vis { static void init() { - { - typedef PluginFactory::DestroyDeleter Deleter; + /* spectrum visualizers */ + typedef PluginFactory::DestroyDeleter SpectrumDeleter; + std::vector > spectrum; - spectrumVisualizers = PluginFactory::Instance() - .QueryInterface("GetSpectrumVisualizer"); + spectrum = PluginFactory::Instance() + .QueryInterface("GetSpectrumVisualizer"); + + for (auto it = spectrum.begin(); it != spectrum.end(); it++) { + visualizers.push_back(*it); } - { - typedef PluginFactory::DestroyDeleter Deleter; + /* pcm visualizers */ + typedef PluginFactory::DestroyDeleter PcmDeleter; + std::vector > pcm; - pcmVisualizers = PluginFactory::Instance() - .QueryInterface("GetPcmVisualizer"); + pcm = PluginFactory::Instance() + .QueryInterface("GetPcmVisualizer"); + + for (auto it = pcm.begin(); it != pcm.end(); it++) { + visualizers.push_back(*it); } + /* sort 'em by name */ + using V = std::shared_ptr; + + std::sort( + visualizers.begin(), + visualizers.end(), + [](V left, V right) -> bool { + std::string l = left->Name(); + LOWER(l); + std::string r = right->Name(); + LOWER(r); + return l < r; + }); + initialized = true; } + void HideSelectedVisualizer() { + if (selectedVisualizer) { + selectedVisualizer->Hide(); + SetSelectedVisualizer(std::shared_ptr()); + } + } + ISpectrumVisualizer* SpectrumVisualizer() { return spectrumVisualizer; } @@ -79,11 +110,7 @@ namespace musik { } std::shared_ptr GetVisualizer(size_t index) { - if (index < pcmVisualizers.size()) { - return pcmVisualizers.at(index); - } - - return spectrumVisualizers.at(index - pcmVisualizers.size()); + return visualizers.at(index); } size_t VisualizerCount() { @@ -91,7 +118,7 @@ namespace musik { init(); } - return pcmVisualizers.size() + spectrumVisualizers.size(); + return visualizers.size(); } void SetSelectedVisualizer(std::shared_ptr visualizer) { diff --git a/src/core/audio/Visualizer.h b/src/core/audio/Visualizer.h index e93fb1b06..221924ac7 100644 --- a/src/core/audio/Visualizer.h +++ b/src/core/audio/Visualizer.h @@ -47,5 +47,6 @@ namespace musik { namespace core { namespace audio { namespace vis { size_t VisualizerCount(); void SetSelectedVisualizer(std::shared_ptr visualizer); std::shared_ptr SelectedVisualizer(); + void HideSelectedVisualizer(); } } } } diff --git a/src/core/plugin/PluginFactory.cpp b/src/core/plugin/PluginFactory.cpp index 029d754a1..5e642ab60 100644 --- a/src/core/plugin/PluginFactory.cpp +++ b/src/core/plugin/PluginFactory.cpp @@ -79,8 +79,6 @@ PluginFactory::~PluginFactory(void){ loadedDlls.clear(); } -#include - void PluginFactory::LoadPlugins(){ boost::mutex::scoped_lock lock(this->mutex); diff --git a/src/musikbox/Main.cpp b/src/musikbox/Main.cpp index 3e64c060d..b1df4ffda 100644 --- a/src/musikbox/Main.cpp +++ b/src/musikbox/Main.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -148,6 +149,8 @@ int main(int argc, char* argv[]) app.Run(mainLayout); } + musik::core::audio::vis::HideSelectedVisualizer(); + LibraryFactory::Instance().Shutdown(); musik::debug::deinit();