visualizer: set refresh rate to 0.5 sec if mpd is not playing
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "status.h"
|
#include "status.h"
|
||||||
#include "tag_editor.h"
|
#include "tag_editor.h"
|
||||||
|
#include "visualizer.h"
|
||||||
|
|
||||||
using Global::myScreen;
|
using Global::myScreen;
|
||||||
using Global::wFooter;
|
using Global::wFooter;
|
||||||
@@ -324,7 +325,8 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
|||||||
}
|
}
|
||||||
if (changed.PlayerState)
|
if (changed.PlayerState)
|
||||||
{
|
{
|
||||||
switch (Mpd.GetState())
|
MPD::PlayerState state = Mpd.GetState();
|
||||||
|
switch (state)
|
||||||
{
|
{
|
||||||
case MPD::psUnknown:
|
case MPD::psUnknown:
|
||||||
{
|
{
|
||||||
@@ -366,9 +368,17 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
player_state.clear();
|
player_state.clear();
|
||||||
|
# ifdef ENABLE_VISUALIZER
|
||||||
|
if (myScreen == myVisualizer)
|
||||||
|
myVisualizer->Main()->Clear();
|
||||||
|
# endif // ENABLE_VISUALIZER
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# ifdef ENABLE_VISUALIZER
|
||||||
|
if (myScreen == myVisualizer)
|
||||||
|
wFooter->SetTimeout(state == MPD::psPlay ? Visualizer::WindowTimeout : ncmpcpp_window_timeout);
|
||||||
|
# endif // ENABLE_VISUALIZER
|
||||||
if (Config.new_design)
|
if (Config.new_design)
|
||||||
{
|
{
|
||||||
*wHeader << XY(0, 1) << fmtBold << player_state << fmtBoldEnd;
|
*wHeader << XY(0, 1) << fmtBold << player_state << fmtBoldEnd;
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ const unsigned Visualizer::Samples = 2048;
|
|||||||
const unsigned Visualizer::FFTResults = Samples/2+1;
|
const unsigned Visualizer::FFTResults = Samples/2+1;
|
||||||
#endif // HAVE_FFTW3_H
|
#endif // HAVE_FFTW3_H
|
||||||
|
|
||||||
|
int Visualizer::WindowTimeout = 1000/25; /* 25 fps */
|
||||||
|
|
||||||
void Visualizer::Init()
|
void Visualizer::Init()
|
||||||
{
|
{
|
||||||
w = new Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
|
w = new Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
|
||||||
@@ -82,7 +84,7 @@ void Visualizer::SwitchTo()
|
|||||||
itsTimer.tv_usec = 0;
|
itsTimer.tv_usec = 0;
|
||||||
|
|
||||||
if (itsFifo >= 0)
|
if (itsFifo >= 0)
|
||||||
Global::wFooter->SetTimeout(1000/25);
|
Global::wFooter->SetTimeout(WindowTimeout);
|
||||||
Global::RedrawHeader = 1;
|
Global::RedrawHeader = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +105,11 @@ void Visualizer::Update()
|
|||||||
if (itsFifo < 0)
|
if (itsFifo < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if mpd is stopped, clear the screen
|
// it supports only PCM in format 44100:16:1
|
||||||
if (!Mpd.isPlaying())
|
static int16_t buf[Samples];
|
||||||
{
|
ssize_t data = read(itsFifo, buf, sizeof(buf));
|
||||||
w->Clear();
|
if (data < 0) // no data available in fifo
|
||||||
w->Refresh();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (itsOutputID != -1 && Global::Timer.tv_sec > itsTimer.tv_sec+Config.visualizer_sync_interval)
|
if (itsOutputID != -1 && Global::Timer.tv_sec > itsTimer.tv_sec+Config.visualizer_sync_interval)
|
||||||
{
|
{
|
||||||
@@ -119,12 +119,6 @@ void Visualizer::Update()
|
|||||||
gettimeofday(&itsTimer, 0);
|
gettimeofday(&itsTimer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// it supports only PCM in format 44100:16:1
|
|
||||||
static int16_t buf[Samples];
|
|
||||||
ssize_t data = read(itsFifo, buf, sizeof(buf));
|
|
||||||
if (data < 0) // no data available in fifo
|
|
||||||
return;
|
|
||||||
|
|
||||||
w->Clear();
|
w->Clear();
|
||||||
# ifdef HAVE_FFTW3_H
|
# ifdef HAVE_FFTW3_H
|
||||||
Config.visualizer_use_wave ? DrawSoundWave(buf, data) : DrawFrequencySpectrum(buf, data);
|
Config.visualizer_use_wave ? DrawSoundWave(buf, data) : DrawFrequencySpectrum(buf, data);
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ class Visualizer : public Screen<Window>
|
|||||||
void ResetFD();
|
void ResetFD();
|
||||||
void FindOutputID();
|
void FindOutputID();
|
||||||
|
|
||||||
|
static int WindowTimeout;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init();
|
virtual void Init();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user