mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-30 06:32:36 +00:00
Added IVisualizer base interface for PCM and Spectrum visualizers. Added
configurable hotkey to show the current visualizer. A couple other small cleanups and fixes.
This commit is contained in:
parent
c2e519ca8c
commit
101d002921
@ -307,17 +307,24 @@ bool Player::Exited() {
|
||||
return (this->state == Player::Quit);
|
||||
}
|
||||
|
||||
static inline void writeToVisualizer(IBuffer *buffer, float *spectrum) {
|
||||
ISpectrumVisualizer* specVis = vis::SpectrumVisualizer();
|
||||
IPcmVisualizer* pcmVis = vis::PcmVisualizer();
|
||||
|
||||
if (specVis && specVis->Visible()) {
|
||||
buffer->Fft(spectrum, FFT_N);
|
||||
vis::SpectrumVisualizer()->Write(spectrum, FFT_N);
|
||||
}
|
||||
else if (pcmVis && pcmVis->Visible()) {
|
||||
vis::PcmVisualizer()->Write(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::OnBufferProcessed(IBuffer *buffer) {
|
||||
bool started = false;
|
||||
bool found = false;
|
||||
|
||||
if (vis::SpectrumVisualizer()) {
|
||||
buffer->Fft(this->spectrum, FFT_N);
|
||||
vis::SpectrumVisualizer()->Write(this->spectrum, FFT_N);
|
||||
}
|
||||
else if (vis::PcmVisualizer()) {
|
||||
vis::PcmVisualizer()->Write(buffer);
|
||||
}
|
||||
writeToVisualizer(buffer, this->spectrum);
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(this->queueMutex);
|
||||
|
@ -91,6 +91,24 @@ namespace musik {
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IVisualizer* SelectedVisualizer() {
|
||||
IVisualizer* vis = SpectrumVisualizer();
|
||||
return vis ? vis : PcmVisualizer();
|
||||
}
|
||||
|
||||
void ToggleSelectedVisualizer() {
|
||||
IVisualizer* vis = SelectedVisualizer();
|
||||
|
||||
if (vis) {
|
||||
if (vis->Visible()) {
|
||||
vis->Hide();
|
||||
}
|
||||
else {
|
||||
vis->Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,12 +35,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <core/config.h>
|
||||
#include <sdk/ISpectrumVisualizer.h>
|
||||
#include <sdk/IPcmVisualizer.h>
|
||||
#include <core/sdk/ISpectrumVisualizer.h>
|
||||
#include <core/sdk/IPcmVisualizer.h>
|
||||
|
||||
namespace musik { namespace core { namespace audio { namespace vis {
|
||||
|
||||
ISpectrumVisualizer* SpectrumVisualizer();
|
||||
IPcmVisualizer* PcmVisualizer();
|
||||
IVisualizer* SelectedVisualizer();
|
||||
void ToggleSelectedVisualizer();
|
||||
|
||||
} } } }
|
||||
|
@ -158,6 +158,7 @@
|
||||
<ClInclude Include="audio\Player.h" />
|
||||
<ClInclude Include="audio\Stream.h" />
|
||||
<ClInclude Include="sdk\ISpectrumVisualizer.h" />
|
||||
<ClInclude Include="sdk\IVisualizer.h" />
|
||||
<ClInclude Include="support\Common.h" />
|
||||
<ClInclude Include="support\NonLibraryTrackHelper.h" />
|
||||
<ClInclude Include="support\PreferenceKeys.h" />
|
||||
|
@ -261,5 +261,8 @@
|
||||
<ClInclude Include="audio\Visualizer.h">
|
||||
<Filter>src\audio</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sdk\IVisualizer.h">
|
||||
<Filter>src\sdk</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -35,10 +35,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "IBuffer.h"
|
||||
#include "IVisualizer.h"
|
||||
|
||||
namespace musik { namespace core { namespace audio {
|
||||
|
||||
class IPcmVisualizer {
|
||||
class IPcmVisualizer : public IVisualizer {
|
||||
public:
|
||||
virtual void Destroy() = 0;
|
||||
virtual void Write(musik::core::audio::IBuffer *target) = 0;
|
||||
|
@ -34,13 +34,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config.h"
|
||||
#include "IMetadataWriter.h"
|
||||
#include "IBuffer.h"
|
||||
#include "IVisualizer.h"
|
||||
|
||||
namespace musik { namespace core { namespace audio {
|
||||
|
||||
class ISpectrumVisualizer {
|
||||
class ISpectrumVisualizer : public IVisualizer {
|
||||
public:
|
||||
virtual void Destroy() = 0;
|
||||
virtual bool Write(float *spectrum, int size) = 0;
|
||||
|
47
src/core/sdk/IVisualizer.h
Normal file
47
src/core/sdk/IVisualizer.h
Normal file
@ -0,0 +1,47 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2016 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
|
||||
|
||||
namespace musik { namespace core { namespace audio {
|
||||
|
||||
class IVisualizer {
|
||||
public:
|
||||
virtual void Show() = 0;
|
||||
virtual void Hide() = 0;
|
||||
virtual bool Visible() = 0;
|
||||
};
|
||||
|
||||
} } }
|
||||
|
@ -36,9 +36,11 @@
|
||||
#include "GlobalHotkeys.h"
|
||||
#include "Hotkeys.h"
|
||||
#include <app/util/Playback.h>
|
||||
#include <core/audio/Visualizer.h>
|
||||
|
||||
using musik::core::LibraryPtr;
|
||||
using musik::core::audio::ITransport;
|
||||
using namespace musik::core::audio;
|
||||
using namespace musik::box;
|
||||
|
||||
GlobalHotkeys::GlobalHotkeys(PlaybackService& playback, LibraryPtr library)
|
||||
@ -96,6 +98,10 @@ bool GlobalHotkeys::Handle(const std::string& kn) {
|
||||
library->Indexer()->Synchronize(true);
|
||||
return true;
|
||||
}
|
||||
else if (Hotkeys::Is(Hotkeys::ToggleVisualizer, kn)) {
|
||||
vis::ToggleSelectedVisualizer();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ static std::unordered_map<std::string, Id> NAME_TO_ID = {
|
||||
|
||||
{ "view_refresh", Id::ViewRefresh },
|
||||
|
||||
{ "toggle_visualizer", Id::ToggleVisualizer },
|
||||
|
||||
{ "metadata_rescan", Id::RescanMetadata }
|
||||
};
|
||||
|
||||
@ -111,6 +113,8 @@ static std::unordered_map<Id, std::string, EnumHasher> ID_TO_DEFAULT = {
|
||||
|
||||
{ Id::ViewRefresh, "KEY_F(5)" },
|
||||
|
||||
{ Id::ToggleVisualizer, "M-v" },
|
||||
|
||||
{ Id::RescanMetadata, "^R"}
|
||||
};
|
||||
|
||||
|
@ -58,8 +58,9 @@ namespace musik {
|
||||
NavigateConsole,
|
||||
NavigateJumpToPlaying,
|
||||
|
||||
/* views, generic */
|
||||
/* views */
|
||||
ViewRefresh,
|
||||
ToggleVisualizer,
|
||||
|
||||
/* playback */
|
||||
TogglePause,
|
||||
|
Loading…
x
Reference in New Issue
Block a user