audio-drain/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp

178 lines
5.8 KiB
C++
Raw Normal View History

2016-05-02 22:01:55 +02:00
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <appl/widget/DisplayFrequency.h>
#include <appl/debug.h>
#include <etk/tool.h>
appl::widget::DisplayFrequency::DisplayFrequency() :
2015-03-26 22:28:37 +01:00
m_gainMin(0.0f),
m_gainMax(1.0f),
m_frequencyMin(0.0f),
m_frequencyMax(24000.0f) {
addObjectType("appl::widget::DisplayFrequency");
2015-03-28 19:43:20 +01:00
m_text.setFontSize(13);
}
void appl::widget::DisplayFrequency::init() {
ewol::Widget::init();
markToRedraw();
}
appl::widget::DisplayFrequency::~DisplayFrequency() {
}
2015-03-26 22:28:37 +01:00
void appl::widget::DisplayFrequency::setValue(const std::vector<std::pair<float,float> >& _data) {
2015-03-27 21:40:54 +01:00
m_data.push_back(_data);
markToRedraw();
}
2015-03-26 22:28:37 +01:00
void appl::widget::DisplayFrequency::setGainRange(float _min, float _max) {
m_gainMin = _min;
m_gainMax = _max;
markToRedraw();
}
void appl::widget::DisplayFrequency::setFrequencyRange(float _min, float _max) {
m_frequencyMin = _min;
m_frequencyMax = _max;
markToRedraw();
}
void appl::widget::DisplayFrequency::onDraw() {
m_draw.draw();
2015-03-28 19:43:20 +01:00
m_text.draw();
}
void appl::widget::DisplayFrequency::onRegenerateDisplay() {
//!< Check if we really need to redraw the display, if not needed, we redraw the previous data ...
if (needRedraw() == false) {
return;
}
// remove previous data
m_draw.clear();
2015-03-28 19:43:20 +01:00
m_text.clear();
2015-03-27 21:40:54 +01:00
m_borderSize = m_size * 0.05;
// set background
m_draw.setColor(etk::color::black);
m_draw.setPos(vec2(0,0));
m_draw.rectangleWidth(m_size);
2015-03-27 21:40:54 +01:00
m_draw.setColor(etk::color::gray);
m_draw.setPos(m_borderSize);
m_draw.setThickness(1);
vec2 plop = m_size-m_borderSize;
m_draw.lineTo(vec2(m_borderSize.x(), plop.y()));
m_draw.lineTo(m_size-m_borderSize);
m_draw.lineTo(vec2(plop.x(), m_borderSize.y()));
m_draw.lineTo(m_borderSize);
if (m_data.size() == 0) {
return;
}
2015-03-27 21:40:54 +01:00
// calculate min and Max :
m_gainMax = -999999999.9;
m_gainMin = 9999999999.9;
m_frequencyMin = 99999999.0;
m_frequencyMax = -99999999.0;
2015-03-30 21:00:12 +02:00
bool displayLog = true;
2015-03-27 21:40:54 +01:00
for (size_t kkk=0; kkk<m_data.size(); kkk++) {
for (size_t iii=0; iii<m_data[kkk].size(); ++iii) {
2015-03-28 19:43:20 +01:00
if (std::abs(m_data[kkk][iii].second) != std::numeric_limits<float>::infinity()) {
m_gainMax = std::max(m_gainMax, m_data[kkk][iii].second);
m_gainMin = std::min(m_gainMin, m_data[kkk][iii].second);
2015-04-01 23:18:46 +02:00
//APPL_INFO("plop " << m_data[kkk][iii].second);
2015-03-28 19:43:20 +01:00
}
2015-03-30 21:00:12 +02:00
if (displayLog == false) {
if (std::abs(m_data[kkk][iii].first) != std::numeric_limits<float>::infinity()) {
m_frequencyMax = std::max(m_frequencyMax, m_data[kkk][iii].first);
m_frequencyMin = std::min(m_frequencyMin, m_data[kkk][iii].first);
}
} else {
if (std::abs(m_data[kkk][iii].first) != std::numeric_limits<float>::infinity()) {
if (m_data[kkk][iii].first == 0) {
continue;
}
m_frequencyMax = std::max(m_frequencyMax, std::log(m_data[kkk][iii].first));
m_frequencyMin = std::min(m_frequencyMin, std::log(m_data[kkk][iii].first));
2015-04-01 23:18:46 +02:00
//APPL_INFO("plop " << m_data[kkk][iii].first << " " << std::log(m_data[kkk][iii].first));
2015-03-30 21:00:12 +02:00
}
2015-03-28 19:43:20 +01:00
}
2015-03-27 21:40:54 +01:00
}
}
2015-03-28 19:43:20 +01:00
// TODO : limit unit at a unit value.
2015-04-01 23:18:46 +02:00
m_gainMin = int32_t(m_gainMin - 1);
m_gainMax = int32_t(m_gainMax + 1);
2015-03-28 19:43:20 +01:00
/*
for (size_t iii=0; iii<m_data[0].size() && m_data[1].size(); ++iii) {
APPL_INFO(" f=" << m_data[0][iii].first << " val=" << m_data[0][iii].second << " f=" << m_data[1][iii].first << " val=" << m_data[1][iii].second);
}
*/
// set all the line:
m_draw.setThickness(1);
2015-04-01 23:18:46 +02:00
m_draw.setColor(etk::color::red);
float ratioX = (m_size.x()-m_borderSize.x()*2.0) / (m_frequencyMax - m_frequencyMin);
float ratioY = (m_size.y()-m_borderSize.y()*2.0) / (m_gainMax - m_gainMin);
m_draw.setPos(m_borderSize + vec2(0, ratioY*(- m_gainMin)));
m_draw.lineTo(m_borderSize + vec2(ratioX*(m_frequencyMax - m_frequencyMin), ratioY*(- m_gainMin)));
2015-03-27 21:40:54 +01:00
for (size_t kkk=0; kkk<m_data.size(); ++kkk) {
if (kkk == 0) {
m_draw.setColor(etk::color::green);
} else if (kkk == 0) {
m_draw.setColor(etk::color::orange);
} else {
m_draw.setColor(etk::color::red);
}
2015-03-30 21:00:12 +02:00
if (displayLog == false) {
m_draw.setPos( m_borderSize
+ vec2(ratioX*(m_data[kkk][0].first - m_frequencyMin),
ratioY*(m_data[kkk][0].second - m_gainMin)));
float baseX = 0;
for (size_t iii=1; iii<m_data[kkk].size(); ++iii) {
m_draw.lineTo( m_borderSize
+ vec2(ratioX*(m_data[kkk][iii].first - m_frequencyMin),
ratioY*(m_data[kkk][iii].second - m_gainMin)));
}
} else {
m_draw.setPos( m_borderSize
+ vec2(ratioX*(std::log(m_data[kkk][0].first) - m_frequencyMin),
ratioY*(m_data[kkk][0].second - m_gainMin)));
float baseX = 0;
for (size_t iii=1; iii<m_data[kkk].size(); ++iii) {
m_draw.lineTo( m_borderSize
+ vec2(ratioX*(std::log(m_data[kkk][iii].first) - m_frequencyMin),
ratioY*(m_data[kkk][iii].second - m_gainMin)));
}
2015-03-27 21:40:54 +01:00
}
}
2015-03-28 19:43:20 +01:00
m_text.setDefaultColorFg(etk::color::green);
std::string textToDisplay = etk::to_string(m_frequencyMin) + " Hz";
vec3 size = m_text.calculateSize(textToDisplay);
m_text.setPos(vec2(m_borderSize.x(), m_borderSize.y()-size.y()));
m_text.print(textToDisplay);
textToDisplay = etk::to_string(m_frequencyMax) + " Hz";
size = m_text.calculateSize(textToDisplay);
m_text.setPos(vec2(m_size.x()-m_borderSize.x()-size.x(), m_borderSize.y()-size.y()));
m_text.print(textToDisplay);
textToDisplay = etk::to_string(m_gainMin) + " dB";
size = m_text.calculateSize(textToDisplay);
m_text.setPos(vec2(m_borderSize.x(), m_borderSize.y()));
m_text.print(textToDisplay);
2015-03-27 21:40:54 +01:00
2015-03-28 19:43:20 +01:00
textToDisplay = etk::to_string(m_gainMax) + " dB";
size = m_text.calculateSize(textToDisplay);
m_text.setPos(vec2(m_borderSize.x(), m_size.y() - m_borderSize.y()));
m_text.print(textToDisplay);
}