visualizer: add support for multiple colors
This commit is contained in:
@@ -629,9 +629,16 @@ bool Configuration::read(const std::string &config_path)
|
|||||||
p.add("active_column_color", assign_default(
|
p.add("active_column_color", assign_default(
|
||||||
active_column_color, NC::Color::Red
|
active_column_color, NC::Color::Red
|
||||||
));
|
));
|
||||||
p.add("visualizer_color", assign_default(
|
p.add("visualizer_colors", option_parser::worker([this](std::string &&v) {
|
||||||
visualizer_color, NC::Color::Yellow
|
boost::sregex_token_iterator i(v.begin(), v.end(), boost::regex("\\w+")), j;
|
||||||
));
|
for (; i != j; ++i)
|
||||||
|
{
|
||||||
|
auto color = stringToColor(*i);
|
||||||
|
visualizer_colors.push_back(color);
|
||||||
|
}
|
||||||
|
}, [this] {
|
||||||
|
visualizer_colors = { NC::Color::Blue, NC::Color::Cyan, NC::Color::Green, NC::Color::Yellow, NC::Color::Red };
|
||||||
|
}));
|
||||||
p.add("window_border_color", assign_default(
|
p.add("window_border_color", assign_default(
|
||||||
window_border, NC::Border::Green
|
window_border, NC::Border::Green
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ struct Configuration
|
|||||||
NC::Color statusbar_color;
|
NC::Color statusbar_color;
|
||||||
NC::Color alternative_ui_separator_color;
|
NC::Color alternative_ui_separator_color;
|
||||||
NC::Color active_column_color;
|
NC::Color active_column_color;
|
||||||
NC::Color visualizer_color;
|
std::vector<NC::Color> visualizer_colors;
|
||||||
|
|
||||||
NC::Border window_border;
|
NC::Border window_border;
|
||||||
NC::Border active_window_border;
|
NC::Border active_window_border;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ const int fps = 25;
|
|||||||
}
|
}
|
||||||
|
|
||||||
Visualizer::Visualizer()
|
Visualizer::Visualizer()
|
||||||
: Screen(NC::Window(0, MainStartY, COLS, MainHeight, "", Config.visualizer_color, NC::Border::None))
|
: Screen(NC::Window(0, MainStartY, COLS, MainHeight, "", NC::Color::Default, NC::Border::None))
|
||||||
{
|
{
|
||||||
ResetFD();
|
ResetFD();
|
||||||
m_samples = 44100/fps;
|
m_samples = 44100/fps;
|
||||||
@@ -176,15 +176,26 @@ 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 << NC::XY(i, y_offset+half_height+point_pos) << Config.visualizer_chars[0];
|
point_pos = std::round(point_pos);
|
||||||
if (i && fabs(prev_point_pos-point_pos) > 2)
|
|
||||||
|
w << NC::XY(i, y_offset+half_height+point_pos)
|
||||||
|
<< Config.visualizer_colors[std::min(size_t(std::abs(point_pos) / (double)half_height *
|
||||||
|
Config.visualizer_colors.size()), Config.visualizer_colors.size() - 1)]
|
||||||
|
<< Config.visualizer_chars[0]
|
||||||
|
<< NC::Color::End;
|
||||||
|
|
||||||
|
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
|
||||||
// since without them all we see are blinking points
|
// since without them all we see are blinking points
|
||||||
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 << 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_colors[std::min(size_t(std::abs(k) / (double)half_height *
|
||||||
|
Config.visualizer_colors.size()), Config.visualizer_colors.size() - 1)]
|
||||||
|
<< Config.visualizer_chars[0]
|
||||||
|
<< NC::Color::End;
|
||||||
}
|
}
|
||||||
prev_point_pos = point_pos;
|
prev_point_pos = point_pos;
|
||||||
}
|
}
|
||||||
@@ -225,7 +236,17 @@ void Visualizer::DrawFrequencySpectrum(int16_t *buf, ssize_t samples, size_t y_o
|
|||||||
const size_t start_y = y_offset > 0 ? y_offset : height-bar_real_height;
|
const size_t start_y = y_offset > 0 ? y_offset : height-bar_real_height;
|
||||||
const size_t stop_y = std::min(bar_real_height+start_y, w.getHeight());
|
const size_t stop_y = std::min(bar_real_height+start_y, w.getHeight());
|
||||||
for (size_t j = start_y; j < stop_y; ++j)
|
for (size_t j = start_y; j < stop_y; ++j)
|
||||||
w << NC::XY(i, j) << Config.visualizer_chars[1];
|
{
|
||||||
|
w << NC::XY(i, j);
|
||||||
|
if (Config.visualizer_in_stereo)
|
||||||
|
w << Config.visualizer_colors[std::abs(int(j - w.getHeight() / 2)) /
|
||||||
|
((double)w.getHeight() / 2) * Config.visualizer_colors.size()];
|
||||||
|
else
|
||||||
|
w << Config.visualizer_colors[std::abs(int((double)j / stop_y * Config.visualizer_colors.size()) -
|
||||||
|
int(Config.visualizer_colors.size() - 1))];
|
||||||
|
w << Config.visualizer_chars[1]
|
||||||
|
<< NC::Color::End;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // HAVE_FFTW3_H
|
#endif // HAVE_FFTW3_H
|
||||||
|
|||||||
Reference in New Issue
Block a user