diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/help.cpp | 6 | ||||
-rw-r--r-- | src/settings.cpp | 5 | ||||
-rw-r--r-- | src/settings.h | 1 | ||||
-rw-r--r-- | src/visualizer.cpp | 37 | ||||
-rw-r--r-- | src/visualizer.h | 5 |
5 files changed, 49 insertions, 5 deletions
diff --git a/src/help.cpp b/src/help.cpp index 54f42c5f..57890847 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -298,6 +298,12 @@ void Help::GetKeybindings() # endif // ENABLE_OUTPUTS +# ifdef ENABLE_VISUALIZER + *w << "\n\n " << fmtBold << "Keys - Music visualizer\n -----------------------------------------\n" << fmtBoldEnd; + *w << DisplayKeys(Key.Space) << "Toggle visualization type\n"; +# endif // ENABLE_VISUALIZER + + *w << "\n\n " << fmtBold << "Mouse - Global\n -----------------------------------------\n" << fmtBoldEnd; *w << "\tLeft click on \"Playing/Paused\" " << ": Play/pause\n"; *w << "\tLeft click on progressbar " << ": Go to chosen position in played track\n"; diff --git a/src/settings.cpp b/src/settings.cpp index 9639b534..2bcdeecb 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -306,6 +306,7 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.ask_before_clearing_main_playlist = false; conf.mouse_support = true; conf.new_design = false; + conf.visualizer_use_wave = false; conf.set_window_title = true; conf.mpd_port = 6600; conf.mpd_connection_timeout = 15; @@ -789,6 +790,10 @@ void ReadConfiguration(ncmpcpp_config &conf) { conf.ask_before_clearing_main_playlist = v == "yes"; } + else if (cl.find("visualizer_type") != std::string::npos) + { + conf.visualizer_use_wave = v == "wave"; + } else if (cl.find("mouse_support") != std::string::npos) { conf.mouse_support = v == "yes"; diff --git a/src/settings.h b/src/settings.h index 86c9e5ba..2b755eb3 100644 --- a/src/settings.h +++ b/src/settings.h @@ -203,6 +203,7 @@ struct ncmpcpp_config bool ask_before_clearing_main_playlist; bool mouse_support; bool new_design; + bool visualizer_use_wave; int mpd_port; int mpd_connection_timeout; diff --git a/src/visualizer.cpp b/src/visualizer.cpp index 8e901254..b4f2fcb5 100644 --- a/src/visualizer.cpp +++ b/src/visualizer.cpp @@ -102,6 +102,37 @@ void Visualizer::Update() if (data < 0) // no data available in fifo return; + w->Clear(0); + Config.visualizer_use_wave ? DrawSoundWave(buf, data) : DrawFrequencySpectrum(buf, data); + w->Refresh(); +} + +void Visualizer::SpacePressed() +{ + Config.visualizer_use_wave = !Config.visualizer_use_wave; + ShowMessage("Visualization type: %s", Config.visualizer_use_wave ? "Sound wave" : "Frequency spectrum"); +} + +void Visualizer::DrawSoundWave(int16_t *buf, ssize_t data) +{ + const int samples_per_col = data/sizeof(int16_t)/COLS; + const int half_height = MainHeight/2; + *w << fmtAltCharset; + for (int i = 0; i < COLS; ++i) + { + double point_pos = 0; + for (int j = 0; j < samples_per_col; ++j) + point_pos += buf[i*samples_per_col+j]; + point_pos /= samples_per_col; + point_pos /= std::numeric_limits<int16_t>::max(); + point_pos *= half_height; + *w << XY(i, half_height+point_pos) << '`'; + } + *w << fmtAltCharsetEnd; +} + +void Visualizer::DrawFrequencySpectrum(int16_t *buf, ssize_t data) +{ // zero old values std::fill(buf+data/sizeof(int16_t), buf+Samples, 0); for (unsigned i = 0; i < Samples; ++i) @@ -113,17 +144,15 @@ void Visualizer::Update() for (unsigned i = 0; i < FFTResults; ++i) itsFreqsMagnitude[i] = sqrt(itsOutput[i][0]*itsOutput[i][0] + itsOutput[i][1]*itsOutput[i][1])/1e5*LINES/5; - w->Clear(0); const int freqs_per_col = FFTResults/COLS /* cut bandwidth a little to achieve better look */ * 4/5; for (int i = 0; i < COLS; ++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 = std::min(bar_height/freqs_per_col, Global::MainHeight); - mvwvline(w->Raw(), Global::MainHeight-bar_height, i, 0, bar_height); + bar_height = std::min(bar_height/freqs_per_col, MainHeight); + mvwvline(w->Raw(), MainHeight-bar_height, i, 0, bar_height); } - w->Refresh(); } void Visualizer::SetFD() diff --git a/src/visualizer.h b/src/visualizer.h index cc887720..50f5ad30 100644 --- a/src/visualizer.h +++ b/src/visualizer.h @@ -44,7 +44,7 @@ class Visualizer : public Screen<Window> virtual void Scroll(Where, const int *) { } virtual void EnterPressed() { } - virtual void SpacePressed() { } + virtual void SpacePressed(); virtual void MouseButtonPressed(MEVENT) { } virtual NCurses::List *GetList() { return 0; } @@ -58,6 +58,9 @@ class Visualizer : public Screen<Window> virtual void Init(); private: + void DrawSoundWave(int16_t *, ssize_t); + void DrawFrequencySpectrum(int16_t *, ssize_t); + int itsFifo; unsigned *itsFreqsMagnitude; double *itsInput; |