enums: implement operator{<<,>>} for VisualizerType and use it
This commit is contained in:
@@ -137,3 +137,40 @@ std::istream &operator>>(std::istream &is, Design &ui)
|
|||||||
is.setstate(std::ios::failbit);
|
is.setstate(std::ios::failbit);
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream& os, VisualizerType vt)
|
||||||
|
{
|
||||||
|
switch (vt)
|
||||||
|
{
|
||||||
|
case VisualizerType::Wave:
|
||||||
|
os << "sound wave";
|
||||||
|
break;
|
||||||
|
case VisualizerType::WaveFilled:
|
||||||
|
os << "sound wave filled";
|
||||||
|
break;
|
||||||
|
case VisualizerType::Spectrum:
|
||||||
|
os << "frequency spectrum";
|
||||||
|
break;
|
||||||
|
case VisualizerType::Ellipse:
|
||||||
|
os << "sound ellipse";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::istream &operator>>(std::istream& is, VisualizerType &vt)
|
||||||
|
{
|
||||||
|
std::string svt;
|
||||||
|
is >> svt;
|
||||||
|
if (svt == "wave")
|
||||||
|
vt = VisualizerType::Wave;
|
||||||
|
else if (svt == "wave_filled")
|
||||||
|
vt = VisualizerType::WaveFilled;
|
||||||
|
else if (svt == "spectrum")
|
||||||
|
vt = VisualizerType::Spectrum;
|
||||||
|
else if (svt == "ellipse")
|
||||||
|
vt = VisualizerType::Ellipse;
|
||||||
|
else
|
||||||
|
is.setstate(std::ios::failbit);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,5 +40,7 @@ std::ostream &operator<<(std::ostream &os, Design ui);
|
|||||||
std::istream &operator>>(std::istream &is, Design &ui);
|
std::istream &operator>>(std::istream &is, Design &ui);
|
||||||
|
|
||||||
enum class VisualizerType { Wave, WaveFilled, Spectrum, Ellipse };
|
enum class VisualizerType { Wave, WaveFilled, Spectrum, Ellipse };
|
||||||
|
std::ostream &operator<<(std::ostream &os, VisualizerType vt);
|
||||||
|
std::istream &operator>>(std::istream &is, VisualizerType &vt);
|
||||||
|
|
||||||
#endif // NCMPCPP_ENUMS_H
|
#endif // NCMPCPP_ENUMS_H
|
||||||
|
|||||||
@@ -230,9 +230,8 @@ bool Configuration::read(const std::string &config_path)
|
|||||||
visualizer_sync_interval, 30, [](unsigned v) {
|
visualizer_sync_interval, 30, [](unsigned v) {
|
||||||
return boost::posix_time::seconds(v);
|
return boost::posix_time::seconds(v);
|
||||||
}));
|
}));
|
||||||
p.add("visualizer_type", option_parser::worker([this](std::string &&v) {
|
p.add("visualizer_type", assign_default(
|
||||||
visualizer_type = stringToVisualizerType( v );
|
visualizer_type, VisualizerType::Wave
|
||||||
}, defaults_to(visualizer_type, VisualizerType::Wave)
|
|
||||||
));
|
));
|
||||||
p.add("visualizer_look", assign_default<std::string>(
|
p.add("visualizer_look", assign_default<std::string>(
|
||||||
visualizer_chars, "●▮", [](std::string &&s) {
|
visualizer_chars, "●▮", [](std::string &&s) {
|
||||||
|
|||||||
@@ -43,20 +43,6 @@ NC::Color stringToColor(const std::string &color)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
VisualizerType stringToVisualizerType(const std::string &visualizerType)
|
|
||||||
{
|
|
||||||
VisualizerType result = VisualizerType::Wave;
|
|
||||||
if (visualizerType == "wave")
|
|
||||||
result = VisualizerType::Wave;
|
|
||||||
else if (visualizerType == "spectrum")
|
|
||||||
result = VisualizerType::Spectrum;
|
|
||||||
else if (visualizerType == "wave_filled")
|
|
||||||
result = VisualizerType::WaveFilled;
|
|
||||||
else if (visualizerType == "ellipse")
|
|
||||||
result = VisualizerType::Ellipse;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NC::Border stringToBorder(const std::string &border)
|
NC::Border stringToBorder(const std::string &border)
|
||||||
{
|
{
|
||||||
NC::Border result = NC::Border::None;
|
NC::Border result = NC::Border::None;
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
#include "enums.h"
|
#include "enums.h"
|
||||||
|
|
||||||
NC::Color stringToColor(const std::string &color);
|
NC::Color stringToColor(const std::string &color);
|
||||||
VisualizerType stringToVisualizerType(const std::string &visualizerType);
|
|
||||||
NC::Border stringToBorder(const std::string &border);
|
NC::Border stringToBorder(const std::string &border);
|
||||||
|
|
||||||
std::string tagTypeToString(mpd_tag_type tag);
|
std::string tagTypeToString(mpd_tag_type tag);
|
||||||
|
|||||||
@@ -189,31 +189,22 @@ int Visualizer::windowTimeout()
|
|||||||
|
|
||||||
void Visualizer::spacePressed()
|
void Visualizer::spacePressed()
|
||||||
{
|
{
|
||||||
std::string visualizerName;
|
switch (Config.visualizer_type)
|
||||||
if (Config.visualizer_type == VisualizerType::Wave)
|
|
||||||
{
|
{
|
||||||
Config.visualizer_type = VisualizerType::WaveFilled;
|
case VisualizerType::Wave:
|
||||||
visualizerName = "sound wave filled";
|
Config.visualizer_type = VisualizerType::WaveFilled;
|
||||||
|
break;
|
||||||
|
case VisualizerType::WaveFilled:
|
||||||
|
Config.visualizer_type = VisualizerType::Spectrum;
|
||||||
|
break;
|
||||||
|
case VisualizerType::Spectrum:
|
||||||
|
Config.visualizer_type = VisualizerType::Ellipse;
|
||||||
|
break;
|
||||||
|
case VisualizerType::Ellipse:
|
||||||
|
Config.visualizer_type = VisualizerType::Wave;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (Config.visualizer_type == VisualizerType::WaveFilled && Config.visualizer_in_stereo)
|
Statusbar::printf("Visualization type: %1%", Config.visualizer_type);
|
||||||
{
|
|
||||||
Config.visualizer_type = VisualizerType::Ellipse;
|
|
||||||
visualizerName = "sound ellipse";
|
|
||||||
}
|
|
||||||
# ifdef HAVE_FFTW3_H
|
|
||||||
else if (Config.visualizer_type == VisualizerType::Ellipse || Config.visualizer_type == VisualizerType::WaveFilled)
|
|
||||||
{
|
|
||||||
Config.visualizer_type = VisualizerType::Spectrum;
|
|
||||||
visualizerName = "frequency spectrum";
|
|
||||||
}
|
|
||||||
# endif // HAVE_FFTW3_H
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Config.visualizer_type = VisualizerType::Wave;
|
|
||||||
visualizerName = "sound wave";
|
|
||||||
}
|
|
||||||
|
|
||||||
Statusbar::printf("Visualization type: %1%", visualizerName.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visualizer::DrawSoundWaveStereo(int16_t *buf_left, int16_t *buf_right, ssize_t samples, size_t height)
|
void Visualizer::DrawSoundWaveStereo(int16_t *buf_left, int16_t *buf_right, ssize_t samples, size_t height)
|
||||||
|
|||||||
Reference in New Issue
Block a user