diff options
author | Andrzej Rybczak <andrzej@rybczak.net> | 2020-12-21 10:55:46 +0100 |
---|---|---|
committer | Andrzej Rybczak <andrzej@rybczak.net> | 2020-12-21 10:55:46 +0100 |
commit | 3d5d1f4d54a426cc4a4ca839b313597ab668a3ce (patch) | |
tree | 3aa8e7f0ccae461b97a39071e30c076aa7d31195 | |
parent | 37af7d805209b5402495b104ad4ff50f132d6004 (diff) |
Fix crash on startup with Visualizer as the initial screen
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/screens/visualizer.cpp | 21 | ||||
-rw-r--r-- | src/screens/visualizer.h | 1 |
3 files changed, 15 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ea0270fc..a836d345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # ncmpcpp-0.10 (????-??-??) * Add support for fetching lyrics from musixmatch.com. * Fix intermittent failures of the Genius fetcher. +* Fix crash on startup with Visualizer as the initial screen. # ncmpcpp-0.9 (2020-12-20) * Fix various Mopidy specific bugs. diff --git a/src/screens/visualizer.cpp b/src/screens/visualizer.cpp index c60c1dc3..ce1c4105 100644 --- a/src/screens/visualizer.cpp +++ b/src/screens/visualizer.cpp @@ -69,6 +69,8 @@ const NC::FormattedColor &toColor(size_t number, size_t max, bool wrap = true) Visualizer::Visualizer() : Screen(NC::Window(0, MainStartY, COLS, MainHeight, "", NC::Color::Default, NC::Border())) +, m_output_id(-1) +, m_reset_output(false) , m_source_fd(-1) , m_sample_consumption_rate(5) , m_sample_consumption_rate_up_ctr(0) @@ -103,14 +105,7 @@ void Visualizer::switchTo() SwitchTo::execute(this); Clear(); OpenDataSource(); - // Disable and enable FIFO to get rid of the difference between audio and - // visualization. - if (m_output_id != -1) - { - Mpd.DisableOutput(m_output_id); - usleep(50000); - Mpd.EnableOutput(m_output_id); - } + m_reset_output = true; drawHeader(); # ifdef HAVE_FFTW3_H GenLogspace(); @@ -142,6 +137,16 @@ void Visualizer::update() if (m_source_fd < 0) return; + // Disable and enable FIFO to get rid of the difference between audio and + // visualization. + if (m_reset_output && m_output_id != -1) + { + Mpd.DisableOutput(m_output_id); + usleep(50000); + Mpd.EnableOutput(m_output_id); + m_reset_output = false; + } + // PCM in format 44100:16:1 (for mono visualization) and // 44100:16:2 (for stereo visualization) is supported. ssize_t bytes_read = read(m_source_fd, m_incoming_samples.data(), diff --git a/src/screens/visualizer.h b/src/screens/visualizer.h index fbe0e271..170a1ed7 100644 --- a/src/screens/visualizer.h +++ b/src/screens/visualizer.h @@ -87,6 +87,7 @@ private: void (Visualizer::*drawStereo)(const int16_t *, const int16_t *, ssize_t, size_t); int m_output_id; + bool m_reset_output; int m_source_fd; std::string m_source_location; |