make remaining single-windowed screens' main windows non-pointer
This commit is contained in:
@@ -1282,7 +1282,7 @@ void SaveTagChanges::Run()
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
if (myScreen == myTinyTagEditor)
|
||||
{
|
||||
myTinyTagEditor->main()->highlight(myTinyTagEditor->main()->size()-2); // Save
|
||||
myTinyTagEditor->main().highlight(myTinyTagEditor->main().size()-2); // Save
|
||||
myTinyTagEditor->enterPressed();
|
||||
}
|
||||
else if (myScreen->activeWindow() == myTagEditor->TagTypes)
|
||||
|
||||
@@ -56,8 +56,8 @@ Clock::Clock()
|
||||
{
|
||||
Width = Config.clock_display_seconds ? 60 : 40;
|
||||
|
||||
itsPane = new NC::Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
|
||||
w = new NC::Window((COLS-Width)/2, (MainHeight-Height)/2+MainStartY, Width, Height-1, "", Config.main_color, NC::Border(Config.main_color));
|
||||
m_pane = NC::Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
|
||||
w = NC::Window((COLS-Width)/2, (MainHeight-Height)/2+MainStartY, Width, Height-1, "", Config.main_color, NC::Border(Config.main_color));
|
||||
}
|
||||
|
||||
void Clock::resize()
|
||||
@@ -66,12 +66,12 @@ void Clock::resize()
|
||||
getWindowResizeParams(x_offset, width);
|
||||
|
||||
// used for clearing area out of clock window while resizing terminal
|
||||
itsPane->resize(width, MainHeight);
|
||||
itsPane->moveTo(x_offset, MainStartY);
|
||||
itsPane->refresh();
|
||||
m_pane.resize(width, MainHeight);
|
||||
m_pane.moveTo(x_offset, MainStartY);
|
||||
m_pane.refresh();
|
||||
|
||||
if (Width <= width && Height <= MainHeight)
|
||||
w->moveTo(x_offset+(width-Width)/2, MainStartY+(MainHeight-Height)/2);
|
||||
w.moveTo(x_offset+(width-Width)/2, MainStartY+(MainHeight-Height)/2);
|
||||
}
|
||||
|
||||
void Clock::switchTo()
|
||||
@@ -102,10 +102,10 @@ void Clock::switchTo()
|
||||
myScreen = this;
|
||||
drawHeader();
|
||||
Prepare();
|
||||
itsPane->refresh();
|
||||
m_pane.refresh();
|
||||
// clearing screen apparently fixes the problem with last digits being misrendered
|
||||
w->clear();
|
||||
w->display();
|
||||
w.clear();
|
||||
w.display();
|
||||
}
|
||||
|
||||
std::wstring Clock::title()
|
||||
@@ -115,7 +115,7 @@ std::wstring Clock::title()
|
||||
|
||||
void Clock::update()
|
||||
{
|
||||
if (Width > itsPane->getWidth() || Height > MainHeight)
|
||||
if (Width > m_pane.getWidth() || Height > MainHeight)
|
||||
{
|
||||
using Global::myLockedScreen;
|
||||
using Global::myInactiveScreen;
|
||||
@@ -145,7 +145,7 @@ void Clock::update()
|
||||
char buf[64];
|
||||
strftime(buf, 64, "%x", time);
|
||||
attron(COLOR_PAIR(Config.main_color));
|
||||
mvprintw(w->getStarty()+w->getHeight(), w->getStartX()+(w->getWidth()-strlen(buf))/2, "%s", buf);
|
||||
mvprintw(w.getStarty()+w.getHeight(), w.getStartX()+(w.getWidth()-strlen(buf))/2, "%s", buf);
|
||||
attroff(COLOR_PAIR(Config.main_color));
|
||||
refresh();
|
||||
|
||||
@@ -155,7 +155,7 @@ void Clock::update()
|
||||
next[k] = 0;
|
||||
for (int s = 1; s >= 0; --s)
|
||||
{
|
||||
*w << (s ? NC::fmtReverse : NC::fmtReverseEnd);
|
||||
w << (s ? NC::fmtReverse : NC::fmtReverseEnd);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
long a = (newer[i] ^ older[i]) & (s ? newer : older)[i];
|
||||
@@ -168,10 +168,10 @@ void Clock::update()
|
||||
{
|
||||
if (!(a & (t << 1)))
|
||||
{
|
||||
w->goToXY(2*j+2, i);
|
||||
w.goToXY(2*j+2, i);
|
||||
}
|
||||
if (Config.clock_display_seconds || j < 18)
|
||||
*w << " ";
|
||||
w << " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,7 +182,7 @@ void Clock::update()
|
||||
}
|
||||
}
|
||||
}
|
||||
w->refresh();
|
||||
w.refresh();
|
||||
}
|
||||
|
||||
void Clock::Prepare()
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "window.h"
|
||||
#include "screen.h"
|
||||
|
||||
struct Clock : public Screen<NC::Window *>
|
||||
struct Clock : public Screen<NC::Window>
|
||||
{
|
||||
Clock();
|
||||
|
||||
@@ -51,7 +51,7 @@ protected:
|
||||
virtual bool isLockable() OVERRIDE { return false; }
|
||||
|
||||
private:
|
||||
NC::Window *itsPane;
|
||||
NC::Window m_pane;
|
||||
|
||||
static void Prepare();
|
||||
static void Set(int, int);
|
||||
|
||||
@@ -36,13 +36,12 @@ using Global::myScreen;
|
||||
Outputs *myOutputs;
|
||||
|
||||
Outputs::Outputs()
|
||||
: Screen(NC::Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone))
|
||||
{
|
||||
w = new NC::Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
|
||||
w->cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->centeredCursor(Config.centered_cursor);
|
||||
w->setHighlightColor(Config.main_highlight_color);
|
||||
w->setItemDisplayer(Display::Outputs);
|
||||
|
||||
w.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w.centeredCursor(Config.centered_cursor);
|
||||
w.setHighlightColor(Config.main_highlight_color);
|
||||
w.setItemDisplayer(Display::Outputs);
|
||||
FetchList();
|
||||
}
|
||||
|
||||
@@ -62,7 +61,7 @@ void Outputs::switchTo()
|
||||
if (myScreen != this && myScreen->isTabbable())
|
||||
Global::myPrevScreen = myScreen;
|
||||
myScreen = this;
|
||||
w->Window::clear();
|
||||
w.Window::clear();
|
||||
drawHeader();
|
||||
}
|
||||
|
||||
@@ -70,8 +69,8 @@ void Outputs::resize()
|
||||
{
|
||||
size_t x_offset, width;
|
||||
getWindowResizeParams(x_offset, width);
|
||||
w->resize(width, MainHeight);
|
||||
w->moveTo(x_offset, MainStartY);
|
||||
w.resize(width, MainHeight);
|
||||
w.moveTo(x_offset, MainStartY);
|
||||
hasToBeResized = 0;
|
||||
}
|
||||
|
||||
@@ -82,15 +81,15 @@ std::wstring Outputs::title()
|
||||
|
||||
void Outputs::enterPressed()
|
||||
{
|
||||
if (w->current().value().isEnabled())
|
||||
if (w.current().value().isEnabled())
|
||||
{
|
||||
if (Mpd.DisableOutput(w->choice()))
|
||||
Statusbar::msg("Output \"%s\" disabled", w->current().value().name().c_str());
|
||||
if (Mpd.DisableOutput(w.choice()))
|
||||
Statusbar::msg("Output \"%s\" disabled", w.current().value().name().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mpd.EnableOutput(w->choice()))
|
||||
Statusbar::msg("Output \"%s\" enabled", w->current().value().name().c_str());
|
||||
if (Mpd.EnableOutput(w.choice()))
|
||||
Statusbar::msg("Output \"%s\" enabled", w.current().value().name().c_str());
|
||||
}
|
||||
if (!Mpd.SupportsIdle())
|
||||
FetchList();
|
||||
@@ -98,11 +97,11 @@ void Outputs::enterPressed()
|
||||
|
||||
void Outputs::mouseButtonPressed(MEVENT me)
|
||||
{
|
||||
if (w->empty() || !w->hasCoords(me.x, me.y) || size_t(me.y) >= w->size())
|
||||
if (w.empty() || !w.hasCoords(me.x, me.y) || size_t(me.y) >= w.size())
|
||||
return;
|
||||
if (me.bstate & BUTTON1_PRESSED || me.bstate & BUTTON3_PRESSED)
|
||||
{
|
||||
w->Goto(me.y);
|
||||
w.Goto(me.y);
|
||||
if (me.bstate & BUTTON3_PRESSED)
|
||||
enterPressed();
|
||||
}
|
||||
@@ -112,12 +111,12 @@ void Outputs::mouseButtonPressed(MEVENT me)
|
||||
|
||||
void Outputs::FetchList()
|
||||
{
|
||||
w->clear();
|
||||
w.clear();
|
||||
auto outputs = Mpd.GetOutputs();
|
||||
for (auto o = outputs.begin(); o != outputs.end(); ++o)
|
||||
w->addItem(*o, o->isEnabled());
|
||||
w.addItem(*o, o->isEnabled());
|
||||
if (myScreen == this)
|
||||
w->refresh();
|
||||
w.refresh();
|
||||
}
|
||||
|
||||
#endif // ENABLE_OUTPUTS
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "mpdpp.h"
|
||||
#include "screen.h"
|
||||
|
||||
struct Outputs : public Screen<NC::Menu<MPD::Output> *>
|
||||
struct Outputs : public Screen<NC::Menu<MPD::Output>>
|
||||
{
|
||||
Outputs();
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ void Status::Changes::playerState()
|
||||
player_state.clear();
|
||||
# ifdef ENABLE_VISUALIZER
|
||||
if (isVisible(myVisualizer))
|
||||
myVisualizer->main()->clear();
|
||||
myVisualizer->main().clear();
|
||||
# endif // ENABLE_VISUALIZER
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -46,20 +46,20 @@ using Global::myOldScreen;
|
||||
TinyTagEditor *myTinyTagEditor;
|
||||
|
||||
TinyTagEditor::TinyTagEditor()
|
||||
: Screen(NC::Menu<NC::Buffer>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone))
|
||||
{
|
||||
w = new NC::Menu<NC::Buffer>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
|
||||
w->setHighlightColor(Config.main_highlight_color);
|
||||
w->cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->centeredCursor(Config.centered_cursor);
|
||||
w->setItemDisplayer(Display::Default<NC::Buffer>);
|
||||
w.setHighlightColor(Config.main_highlight_color);
|
||||
w.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w.centeredCursor(Config.centered_cursor);
|
||||
w.setItemDisplayer(Display::Default<NC::Buffer>);
|
||||
}
|
||||
|
||||
void TinyTagEditor::resize()
|
||||
{
|
||||
size_t x_offset, width;
|
||||
getWindowResizeParams(x_offset, width);
|
||||
w->resize(width, MainHeight);
|
||||
w->moveTo(x_offset, MainStartY);
|
||||
w.resize(width, MainHeight);
|
||||
w.moveTo(x_offset, MainStartY);
|
||||
hasToBeResized = 0;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ std::wstring TinyTagEditor::title()
|
||||
|
||||
void TinyTagEditor::enterPressed()
|
||||
{
|
||||
size_t option = w->choice();
|
||||
size_t option = w.choice();
|
||||
Statusbar::lock();
|
||||
if (option < 19) // separator after comment
|
||||
{
|
||||
@@ -111,9 +111,9 @@ void TinyTagEditor::enterPressed()
|
||||
Statusbar::put() << NC::fmtBold << SongInfo::Tags[pos].Name << ": " << NC::fmtBoldEnd;
|
||||
itsEdited.setTags(SongInfo::Tags[pos].Set, Global::wFooter->getString(
|
||||
itsEdited.getTags(SongInfo::Tags[pos].Get, Config.tags_separator)), Config.tags_separator);
|
||||
w->at(option).value().clear();
|
||||
w->at(option).value() << NC::fmtBold << SongInfo::Tags[pos].Name << ':' << NC::fmtBoldEnd << ' ';
|
||||
ShowTag(w->at(option).value(), itsEdited.getTags(SongInfo::Tags[pos].Get, Config.tags_separator));
|
||||
w.at(option).value().clear();
|
||||
w.at(option).value() << NC::fmtBold << SongInfo::Tags[pos].Name << ':' << NC::fmtBoldEnd << ' ';
|
||||
ShowTag(w.at(option).value(), itsEdited.getTags(SongInfo::Tags[pos].Get, Config.tags_separator));
|
||||
}
|
||||
else if (option == 20)
|
||||
{
|
||||
@@ -124,8 +124,8 @@ void TinyTagEditor::enterPressed()
|
||||
filename = filename.substr(0, dot);
|
||||
std::string new_name = Global::wFooter->getString(filename);
|
||||
itsEdited.setNewURI(new_name + extension);
|
||||
w->at(option).value().clear();
|
||||
w->at(option).value() << NC::fmtBold << "Filename:" << NC::fmtBoldEnd << ' ' << (itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI());
|
||||
w.at(option).value().clear();
|
||||
w.at(option).value() << NC::fmtBold << "Filename:" << NC::fmtBoldEnd << ' ' << (itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI());
|
||||
}
|
||||
Statusbar::unlock();
|
||||
|
||||
@@ -154,15 +154,15 @@ void TinyTagEditor::enterPressed()
|
||||
|
||||
void TinyTagEditor::mouseButtonPressed(MEVENT me)
|
||||
{
|
||||
if (w->empty() || !w->hasCoords(me.x, me.y) || size_t(me.y) >= w->size())
|
||||
if (w.empty() || !w.hasCoords(me.x, me.y) || size_t(me.y) >= w.size())
|
||||
return;
|
||||
if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED))
|
||||
{
|
||||
if (!w->Goto(me.y))
|
||||
if (!w.Goto(me.y))
|
||||
return;
|
||||
if (me.bstate & BUTTON3_PRESSED)
|
||||
{
|
||||
w->refresh();
|
||||
w.refresh();
|
||||
enterPressed();
|
||||
}
|
||||
}
|
||||
@@ -190,47 +190,47 @@ bool TinyTagEditor::getTags()
|
||||
std::string ext = itsEdited.getURI();
|
||||
ext = lowercase(ext.substr(ext.rfind(".")+1));
|
||||
|
||||
w->clear();
|
||||
w->reset();
|
||||
w.clear();
|
||||
w.reset();
|
||||
|
||||
w->resizeList(24);
|
||||
w.resizeList(24);
|
||||
|
||||
for (size_t i = 0; i < 7; ++i)
|
||||
w->at(i).setInactive(true);
|
||||
w.at(i).setInactive(true);
|
||||
|
||||
w->at(7).setSeparator(true);
|
||||
w->at(19).setSeparator(true);
|
||||
w->at(21).setSeparator(true);
|
||||
w.at(7).setSeparator(true);
|
||||
w.at(19).setSeparator(true);
|
||||
w.at(21).setSeparator(true);
|
||||
|
||||
if (!Tags::extendedSetSupported(f.file()))
|
||||
{
|
||||
w->at(10).setInactive(true);
|
||||
w.at(10).setInactive(true);
|
||||
for (size_t i = 15; i <= 17; ++i)
|
||||
w->at(i).setInactive(true);
|
||||
w.at(i).setInactive(true);
|
||||
}
|
||||
|
||||
w->highlight(8);
|
||||
w.highlight(8);
|
||||
|
||||
w->at(0).value() << NC::fmtBold << Config.color1 << "Song name: " << NC::fmtBoldEnd << Config.color2 << itsEdited.getName() << NC::clEnd;
|
||||
w->at(1).value() << NC::fmtBold << Config.color1 << "Location in DB: " << NC::fmtBoldEnd << Config.color2;
|
||||
ShowTag(w->at(1).value(), itsEdited.getDirectory());
|
||||
w->at(1).value() << NC::clEnd;
|
||||
w->at(3).value() << NC::fmtBold << Config.color1 << "Length: " << NC::fmtBoldEnd << Config.color2 << itsEdited.getLength() << NC::clEnd;
|
||||
w->at(4).value() << NC::fmtBold << Config.color1 << "Bitrate: " << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << NC::clEnd;
|
||||
w->at(5).value() << NC::fmtBold << Config.color1 << "Sample rate: " << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << NC::clEnd;
|
||||
w->at(6).value() << NC::fmtBold << Config.color1 << "Channels: " << NC::fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << NC::clDefault;
|
||||
w.at(0).value() << NC::fmtBold << Config.color1 << "Song name: " << NC::fmtBoldEnd << Config.color2 << itsEdited.getName() << NC::clEnd;
|
||||
w.at(1).value() << NC::fmtBold << Config.color1 << "Location in DB: " << NC::fmtBoldEnd << Config.color2;
|
||||
ShowTag(w.at(1).value(), itsEdited.getDirectory());
|
||||
w.at(1).value() << NC::clEnd;
|
||||
w.at(3).value() << NC::fmtBold << Config.color1 << "Length: " << NC::fmtBoldEnd << Config.color2 << itsEdited.getLength() << NC::clEnd;
|
||||
w.at(4).value() << NC::fmtBold << Config.color1 << "Bitrate: " << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << NC::clEnd;
|
||||
w.at(5).value() << NC::fmtBold << Config.color1 << "Sample rate: " << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << NC::clEnd;
|
||||
w.at(6).value() << NC::fmtBold << Config.color1 << "Channels: " << NC::fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << NC::clDefault;
|
||||
|
||||
unsigned pos = 8;
|
||||
for (const SongInfo::Metadata *m = SongInfo::Tags; m->Name; ++m, ++pos)
|
||||
{
|
||||
w->at(pos).value() << NC::fmtBold << m->Name << ":" << NC::fmtBoldEnd << ' ';
|
||||
ShowTag(w->at(pos).value(), itsEdited.getTags(m->Get, Config.tags_separator));
|
||||
w.at(pos).value() << NC::fmtBold << m->Name << ":" << NC::fmtBoldEnd << ' ';
|
||||
ShowTag(w.at(pos).value(), itsEdited.getTags(m->Get, Config.tags_separator));
|
||||
}
|
||||
|
||||
w->at(20).value() << NC::fmtBold << "Filename:" << NC::fmtBoldEnd << ' ' << itsEdited.getName();
|
||||
w.at(20).value() << NC::fmtBold << "Filename:" << NC::fmtBoldEnd << ' ' << itsEdited.getName();
|
||||
|
||||
w->at(22).value() << "Save";
|
||||
w->at(23).value() << "Cancel";
|
||||
w.at(22).value() << "Save";
|
||||
w.at(23).value() << "Cancel";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "mutable_song.h"
|
||||
#include "screen.h"
|
||||
|
||||
struct TinyTagEditor : public Screen<NC::Menu<NC::Buffer> *>
|
||||
struct TinyTagEditor : public Screen<NC::Menu<NC::Buffer>>
|
||||
{
|
||||
TinyTagEditor();
|
||||
|
||||
|
||||
@@ -45,17 +45,16 @@ Visualizer *myVisualizer;
|
||||
const int Visualizer::WindowTimeout = 1000/25; /* 25 fps */
|
||||
|
||||
Visualizer::Visualizer()
|
||||
: Screen(NC::Window(0, MainStartY, COLS, MainHeight, "", Config.visualizer_color, NC::brNone))
|
||||
{
|
||||
w = new NC::Window(0, MainStartY, COLS, MainHeight, "", Config.visualizer_color, NC::brNone);
|
||||
|
||||
ResetFD();
|
||||
itsSamples = Config.visualizer_in_stereo ? 4096 : 2048;
|
||||
m_samples = Config.visualizer_in_stereo ? 4096 : 2048;
|
||||
# ifdef HAVE_FFTW3_H
|
||||
itsFFTResults = itsSamples/2+1;
|
||||
itsFreqsMagnitude = new unsigned[itsFFTResults];
|
||||
itsInput = static_cast<double *>(fftw_malloc(sizeof(double)*itsSamples));
|
||||
itsOutput = static_cast<fftw_complex *>(fftw_malloc(sizeof(fftw_complex)*itsFFTResults));
|
||||
itsPlan = fftw_plan_dft_r2c_1d(itsSamples, itsInput, itsOutput, FFTW_ESTIMATE);
|
||||
m_fftw_results = m_samples/2+1;
|
||||
m_freq_magnitudes = new unsigned[m_fftw_results];
|
||||
m_fftw_input = static_cast<double *>(fftw_malloc(sizeof(double)*m_samples));
|
||||
m_fftw_output = static_cast<fftw_complex *>(fftw_malloc(sizeof(fftw_complex)*m_fftw_results));
|
||||
m_fftw_plan = fftw_plan_dft_r2c_1d(m_samples, m_fftw_input, m_fftw_output, FFTW_ESTIMATE);
|
||||
# endif // HAVE_FFTW3_H
|
||||
|
||||
FindOutputID();
|
||||
@@ -79,14 +78,14 @@ void Visualizer::switchTo()
|
||||
Global::myPrevScreen = myScreen;
|
||||
myScreen = this;
|
||||
drawHeader();
|
||||
w->clear();
|
||||
w.clear();
|
||||
|
||||
SetFD();
|
||||
|
||||
itsTimer.tv_sec = 0;
|
||||
itsTimer.tv_usec = 0;
|
||||
m_timer.tv_sec = 0;
|
||||
m_timer.tv_usec = 0;
|
||||
|
||||
if (itsFifo >= 0)
|
||||
if (m_fifo >= 0)
|
||||
Global::wFooter->setTimeout(WindowTimeout);
|
||||
}
|
||||
|
||||
@@ -94,8 +93,8 @@ void Visualizer::resize()
|
||||
{
|
||||
size_t x_offset, width;
|
||||
getWindowResizeParams(x_offset, width);
|
||||
w->resize(width, MainHeight);
|
||||
w->moveTo(x_offset, MainStartY);
|
||||
w.resize(width, MainHeight);
|
||||
w.moveTo(x_offset, MainStartY);
|
||||
hasToBeResized = 0;
|
||||
}
|
||||
|
||||
@@ -106,21 +105,21 @@ std::wstring Visualizer::title()
|
||||
|
||||
void Visualizer::update()
|
||||
{
|
||||
if (itsFifo < 0)
|
||||
if (m_fifo < 0)
|
||||
return;
|
||||
|
||||
// PCM in format 44100:16:1 (for mono visualization) and 44100:16:2 (for stereo visualization) is supported
|
||||
int16_t buf[itsSamples];
|
||||
ssize_t data = read(itsFifo, buf, sizeof(buf));
|
||||
int16_t buf[m_samples];
|
||||
ssize_t data = read(m_fifo, buf, sizeof(buf));
|
||||
if (data < 0) // no data available in fifo
|
||||
return;
|
||||
|
||||
if (itsOutputID != -1 && Global::Timer.tv_sec > itsTimer.tv_sec+Config.visualizer_sync_interval)
|
||||
if (m_output_id != -1 && Global::Timer.tv_sec > m_timer.tv_sec+Config.visualizer_sync_interval)
|
||||
{
|
||||
Mpd.DisableOutput(itsOutputID);
|
||||
Mpd.DisableOutput(m_output_id);
|
||||
usleep(50000);
|
||||
Mpd.EnableOutput(itsOutputID);
|
||||
itsTimer = Global::Timer;
|
||||
Mpd.EnableOutput(m_output_id);
|
||||
m_timer = Global::Timer;
|
||||
}
|
||||
|
||||
void (Visualizer::*draw)(int16_t *, ssize_t, size_t, size_t);
|
||||
@@ -131,7 +130,7 @@ void Visualizer::update()
|
||||
# endif // HAVE_FFTW3_H
|
||||
draw = &Visualizer::DrawSoundWave;
|
||||
|
||||
w->clear();
|
||||
w.clear();
|
||||
ssize_t samples_read = data/sizeof(int16_t);
|
||||
if (Config.visualizer_in_stereo)
|
||||
{
|
||||
@@ -147,7 +146,7 @@ void Visualizer::update()
|
||||
}
|
||||
else
|
||||
(this->*draw)(buf, samples_read, 0, MainHeight);
|
||||
w->refresh();
|
||||
w.refresh();
|
||||
}
|
||||
|
||||
void Visualizer::spacePressed()
|
||||
@@ -160,10 +159,10 @@ void Visualizer::spacePressed()
|
||||
|
||||
void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, size_t height)
|
||||
{
|
||||
const int samples_per_col = samples/w->getWidth();
|
||||
const int samples_per_col = samples/w.getWidth();
|
||||
const int half_height = height/2;
|
||||
double prev_point_pos = 0;
|
||||
const size_t win_width = w->getWidth();
|
||||
const size_t win_width = w.getWidth();
|
||||
for (size_t i = 0; i < win_width; ++i)
|
||||
{
|
||||
double point_pos = 0;
|
||||
@@ -172,7 +171,7 @@ void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, s
|
||||
point_pos /= samples_per_col;
|
||||
point_pos /= std::numeric_limits<int16_t>::max();
|
||||
point_pos *= half_height;
|
||||
*w << NC::XY(i, y_offset+half_height+point_pos) << Config.visualizer_chars[0];
|
||||
w << NC::XY(i, y_offset+half_height+point_pos) << Config.visualizer_chars[0];
|
||||
if (i && abs(prev_point_pos-point_pos) > 2)
|
||||
{
|
||||
// if gap is too big. intermediate values are needed
|
||||
@@ -180,7 +179,7 @@ void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, s
|
||||
const int breakpoint = std::max(prev_point_pos, point_pos);
|
||||
const int half = (prev_point_pos+point_pos)/2;
|
||||
for (int k = std::min(prev_point_pos, point_pos)+1; k < breakpoint; k += 2)
|
||||
*w << NC::XY(i-(k < half), y_offset+half_height+k) << Config.visualizer_chars[0];
|
||||
w << NC::XY(i-(k < half), y_offset+half_height+k) << Config.visualizer_chars[0];
|
||||
}
|
||||
prev_point_pos = point_pos;
|
||||
}
|
||||
@@ -189,58 +188,58 @@ void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, s
|
||||
#ifdef HAVE_FFTW3_H
|
||||
void Visualizer::DrawFrequencySpectrum(int16_t *buf, ssize_t samples, size_t y_offset, size_t height)
|
||||
{
|
||||
for (unsigned i = 0, j = 0; i < itsSamples; ++i)
|
||||
for (unsigned i = 0, j = 0; i < m_samples; ++i)
|
||||
{
|
||||
if (j < samples)
|
||||
itsInput[i] = buf[j++];
|
||||
m_fftw_input[i] = buf[j++];
|
||||
else
|
||||
itsInput[i] = 0;
|
||||
m_fftw_input[i] = 0;
|
||||
}
|
||||
|
||||
fftw_execute(itsPlan);
|
||||
fftw_execute(m_fftw_plan);
|
||||
|
||||
// count magnitude of each frequency and scale it to fit the screen
|
||||
for (unsigned i = 0; i < itsFFTResults; ++i)
|
||||
itsFreqsMagnitude[i] = sqrt(itsOutput[i][0]*itsOutput[i][0] + itsOutput[i][1]*itsOutput[i][1])/1e5*height/5;
|
||||
for (unsigned i = 0; i < m_fftw_results; ++i)
|
||||
m_freq_magnitudes[i] = sqrt(m_fftw_output[i][0]*m_fftw_output[i][0] + m_fftw_output[i][1]*m_fftw_output[i][1])/1e5*height/5;
|
||||
|
||||
const size_t win_width = w->getWidth();
|
||||
const int freqs_per_col = itsFFTResults/win_width /* cut bandwidth a little to achieve better look */ * 7/10;
|
||||
const size_t win_width = w.getWidth();
|
||||
const int freqs_per_col = m_fftw_results/win_width /* cut bandwidth a little to achieve better look */ * 7/10;
|
||||
for (size_t i = 0; i < win_width; ++i)
|
||||
{
|
||||
size_t bar_height = 0;
|
||||
for (int j = 0; j < freqs_per_col; ++j)
|
||||
bar_height += itsFreqsMagnitude[i*freqs_per_col+j];
|
||||
bar_height += m_freq_magnitudes[i*freqs_per_col+j];
|
||||
bar_height = std::min(bar_height/freqs_per_col, height);
|
||||
const size_t start_y = y_offset > 0 ? y_offset : height-bar_height;
|
||||
const size_t stop_y = std::min(bar_height+start_y, w->getHeight());
|
||||
const size_t stop_y = std::min(bar_height+start_y, w.getHeight());
|
||||
for (size_t j = start_y; j < stop_y; ++j)
|
||||
*w << NC::XY(i, j) << Config.visualizer_chars[1];
|
||||
w << NC::XY(i, j) << Config.visualizer_chars[1];
|
||||
}
|
||||
}
|
||||
#endif // HAVE_FFTW3_H
|
||||
|
||||
void Visualizer::SetFD()
|
||||
{
|
||||
if (itsFifo < 0 && (itsFifo = open(Config.visualizer_fifo_path.c_str(), O_RDONLY | O_NONBLOCK)) < 0)
|
||||
if (m_fifo < 0 && (m_fifo = open(Config.visualizer_fifo_path.c_str(), O_RDONLY | O_NONBLOCK)) < 0)
|
||||
Statusbar::msg("Couldn't open \"%s\" for reading PCM data: %s", Config.visualizer_fifo_path.c_str(), strerror(errno));
|
||||
}
|
||||
|
||||
void Visualizer::ResetFD()
|
||||
{
|
||||
itsFifo = -1;
|
||||
m_fifo = -1;
|
||||
}
|
||||
|
||||
void Visualizer::FindOutputID()
|
||||
{
|
||||
itsOutputID = -1;
|
||||
m_output_id = -1;
|
||||
if (!Config.visualizer_output_name.empty())
|
||||
{
|
||||
size_t i = 0;
|
||||
auto outputs = Mpd.GetOutputs();
|
||||
for (auto o = outputs.begin(); o != outputs.end(); ++o, ++i)
|
||||
if (o->name() == Config.visualizer_output_name)
|
||||
itsOutputID = i;
|
||||
if (itsOutputID == -1)
|
||||
m_output_id = i;
|
||||
if (m_output_id == -1)
|
||||
Statusbar::msg("There is no output named \"%s\"", Config.visualizer_output_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
# include <fftw3.h>
|
||||
#endif
|
||||
|
||||
struct Visualizer : public Screen<NC::Window *>
|
||||
struct Visualizer : public Screen<NC::Window>
|
||||
{
|
||||
Visualizer();
|
||||
|
||||
@@ -67,17 +67,17 @@ private:
|
||||
void DrawFrequencySpectrum(int16_t *, ssize_t, size_t, size_t);
|
||||
# endif // HAVE_FFTW3_H
|
||||
|
||||
int itsOutputID;
|
||||
timeval itsTimer;
|
||||
int m_output_id;
|
||||
timeval m_timer;
|
||||
|
||||
int itsFifo;
|
||||
unsigned itsSamples;
|
||||
int m_fifo;
|
||||
unsigned m_samples;
|
||||
# ifdef HAVE_FFTW3_H
|
||||
unsigned itsFFTResults;
|
||||
unsigned *itsFreqsMagnitude;
|
||||
double *itsInput;
|
||||
fftw_complex *itsOutput;
|
||||
fftw_plan itsPlan;
|
||||
unsigned m_fftw_results;
|
||||
unsigned *m_freq_magnitudes;
|
||||
double *m_fftw_input;
|
||||
fftw_complex *m_fftw_output;
|
||||
fftw_plan m_fftw_plan;
|
||||
# endif // HAVE_FFTW3_H
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user