settings: make characters used in visualizer customizable

This commit is contained in:
Andrzej Rybczak
2011-12-26 20:13:01 +01:00
parent 955e23c270
commit 12cdede049
5 changed files with 23 additions and 5 deletions

View File

@@ -89,6 +89,8 @@
# #
#visualizer_type = "wave" (spectrum/wave) #visualizer_type = "wave" (spectrum/wave)
# #
#visualizer_look = "◆│"
#
##### system encoding ##### ##### system encoding #####
## ##
## ncmpcpp should detect your charset encoding ## ncmpcpp should detect your charset encoding

View File

@@ -99,6 +99,9 @@ Defines interval between syncing visualizer and audio outputs.
.B visualizer_type = spectrum/wave .B visualizer_type = spectrum/wave
Defines default visualizer type (spectrum is available only if ncmpcpp was compiled with fftw support). Defines default visualizer type (spectrum is available only if ncmpcpp was compiled with fftw support).
.TP .TP
.B visualizer_look = STRING
Defines visualizer's look (string has to be exactly 2 characters long: first one is for wave whereas second for frequency spectrum).
.TP
.B system_encoding = ENCODING .B system_encoding = ENCODING
If you use encoding other than utf8, set it in order to handle utf8 encoded strings properly. If you use encoding other than utf8, set it in order to handle utf8 encoded strings properly.
.TP .TP

View File

@@ -375,6 +375,7 @@ void NcmpcppConfig::SetDefaults()
new_header_second_line = "{{{$4$b%a$/b$9}{ - $7%b$9}{ ($4%y$9)}}|{%D}}"; new_header_second_line = "{{{$4$b%a$/b$9}{ - $7%b$9}{ ($4%y$9)}}|{%D}}";
browser_playlist_prefix << clRed << "(playlist)" << clEnd << ' '; browser_playlist_prefix << clRed << "(playlist)" << clEnd << ' ';
progressbar = U("=>\0"); progressbar = U("=>\0");
visualizer_chars = U("◆│");
pattern = "%n - %t"; pattern = "%n - %t";
selected_item_prefix << clMagenta; selected_item_prefix << clMagenta;
selected_item_suffix << clEnd; selected_item_suffix << clEnd;
@@ -907,6 +908,16 @@ void NcmpcppConfig::Read()
// if two characters were specified, add third one as null // if two characters were specified, add third one as null
progressbar.resize(3); progressbar.resize(3);
} }
else if (name == "visualizer_look")
{
std::basic_string<my_char_t> vc = TO_WSTRING(v);
if (vc.length() != 2)
{
std::cerr << "Warning: length of visualizer_look should be 2, but it's " << vc.length() << ", discarding.\n";
}
else
visualizer_chars = vc;
}
else if (name == "default_tag_editor_pattern") else if (name == "default_tag_editor_pattern")
{ {
if (!v.empty()) if (!v.empty())

View File

@@ -174,6 +174,7 @@ struct NcmpcppConfig
std::string new_header_second_line; std::string new_header_second_line;
std::string lastfm_preferred_language; std::string lastfm_preferred_language;
std::basic_string<my_char_t> progressbar; std::basic_string<my_char_t> progressbar;
std::basic_string<my_char_t> visualizer_chars;
std::string pattern; std::string pattern;

View File

@@ -162,7 +162,6 @@ void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, s
{ {
const int samples_per_col = samples/w->GetWidth(); const int samples_per_col = samples/w->GetWidth();
const int half_height = height/2; const int half_height = height/2;
*w << fmtAltCharset;
double prev_point_pos = 0; 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) for (size_t i = 0; i < win_width; ++i)
@@ -173,7 +172,7 @@ void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, s
point_pos /= samples_per_col; point_pos /= samples_per_col;
point_pos /= std::numeric_limits<int16_t>::max(); point_pos /= std::numeric_limits<int16_t>::max();
point_pos *= half_height; point_pos *= half_height;
*w << XY(i, y_offset+half_height+point_pos) << '`'; *w << XY(i, y_offset+half_height+point_pos) << Config.visualizer_chars[0];
if (i && abs(prev_point_pos-point_pos) > 2) if (i && abs(prev_point_pos-point_pos) > 2)
{ {
// if gap is too big. intermediate values are needed // if gap is too big. intermediate values are needed
@@ -181,11 +180,10 @@ 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 breakpoint = std::max(prev_point_pos, point_pos);
const int half = (prev_point_pos+point_pos)/2; const int half = (prev_point_pos+point_pos)/2;
for (int k = std::min(prev_point_pos, point_pos)+1; k < breakpoint; k += 2) for (int k = std::min(prev_point_pos, point_pos)+1; k < breakpoint; k += 2)
*w << XY(i-(k < half), y_offset+half_height+k) << '`'; *w << XY(i-(k < half), y_offset+half_height+k) << Config.visualizer_chars[0];
} }
prev_point_pos = point_pos; prev_point_pos = point_pos;
} }
*w << fmtAltCharsetEnd;
} }
#ifdef HAVE_FFTW3_H #ifdef HAVE_FFTW3_H
@@ -213,7 +211,10 @@ void Visualizer::DrawFrequencySpectrum(int16_t *buf, ssize_t samples, size_t y_o
for (int j = 0; j < freqs_per_col; ++j) for (int j = 0; j < freqs_per_col; ++j)
bar_height += itsFreqsMagnitude[i*freqs_per_col+j]; bar_height += itsFreqsMagnitude[i*freqs_per_col+j];
bar_height = std::min(bar_height/freqs_per_col, height); bar_height = std::min(bar_height/freqs_per_col, height);
mvwvline(w->Raw(), y_offset > 0 ? y_offset : height-bar_height, i, 0, bar_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());
for (size_t j = start_y; j < stop_y; ++j)
*w << XY(i, j) << Config.visualizer_chars[1];
} }
} }
#endif // HAVE_FFTW3_H #endif // HAVE_FFTW3_H