Mercurial > hg > easaier-soundaccess
changeset 235:7ab3e81f52d4
enable/disable alternatively draw curve and simple mode in the equalizer filter
author | lbajardsilogic |
---|---|
date | Fri, 07 Mar 2008 15:01:27 +0000 |
parents | cff926c60430 |
children | d97cd5461220 |
files | sv/filter/EqualizerFilter.cpp sv/filter/EqualizerFilter.h widgets/Plotter.cpp widgets/Plotter.h widgets/PropertyBox.cpp |
diffstat | 5 files changed, 107 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/sv/filter/EqualizerFilter.cpp Thu Mar 06 17:14:31 2008 +0000 +++ b/sv/filter/EqualizerFilter.cpp Fri Mar 07 15:01:27 2008 +0000 @@ -29,7 +29,7 @@ EqualizerFilter::EqualizerFilter(size_t framesize, QMutex *mutex) : PropertyContainer() , - m_simpleMode(false) , + m_simpleMode(true) , m_nbBand(5), m_framesize(framesize), m_mutex(mutex), @@ -41,10 +41,6 @@ setObjectName("Equalizer"); - for(int i = 0 ; i < m_resolution ; i++){ - m_eqcurve.push_back(0); - } - m_curve = (float *) calloc(m_resolution, sizeof(float)); band = (float **)calloc(m_nbBand, sizeof(float*)); @@ -53,7 +49,18 @@ } m_plotbandcurve=(float *)malloc(sizeof(float)*(m_resolution)); - + + if (m_simpleMode) + { + create_filterbands(); + } + else + { + for(int i = 0 ; i < m_resolution ; i++){ + m_eqcurve.push_back(0); + } + } + setFilterEnabled(false); } @@ -70,13 +77,13 @@ EqualizerFilter::PropertyList EqualizerFilter::getProperties() const { PropertyList list; - list.push_back("Equalizer"); list.push_back("Enable"); - list.push_back("SimpleMode"); for (int i=0; i<m_nbBand; i++) { QString name = "GainBand" + QString::number(i); list.push_back(name); } + list.push_back("DrawCurve"); + list.push_back("Equalizer"); return list; } @@ -84,6 +91,7 @@ { if (name == "Equalizer") return tr("Equalizer"); if (name == "SimpleMode") return tr("Simple Mode"); + if (name == "DrawCurve") return tr("Draw Curve"); return ""; } @@ -91,7 +99,7 @@ { if (name == "Equalizer") return PlotProperty; if (name == "Enable") return InvalidProperty; - if (name == "SimpleMode") return ToggleProperty; + if (name == "DrawCurve") return ToggleProperty; if (name.left(8) == "GainBand") return RangeProperty; return InvalidProperty; } @@ -99,7 +107,8 @@ QString EqualizerFilter::getPropertyGroupName(const PropertyName &name) const { if (name.left(8) == "GainBand") return "GainBand"; - return QString(); + if ((name == "Equalizer") || (name == "DrawCurve")) return "Draw Curve"; + return QString(); } int EqualizerFilter::getPropertyRangeAndValue(const PropertyName &name, @@ -118,9 +127,9 @@ val = (m_enabled ? 1 : 0); } - if (name == "SimpleMode") { + if (name == "DrawCurve") { if (deflt) *deflt = 0; - val = (m_simpleMode ? 1 : 0); + val = (m_simpleMode ? 0 : 1); } if (name.left(8) == "GainBand") { @@ -156,12 +165,13 @@ m_enabled = false; } emit propertyChanged("Enable"); - } else if (name == "SimpleMode"){ - m_simpleMode = (value > 0) ? true : false; + } else if (name == "DrawCurve"){ + m_simpleMode = (value > 0) ? false : true; if (m_simpleMode) { create_filterbands(); } + emit enableDrawCurve(!m_simpleMode); } else if (name.left(8) == "GainBand"){ int i = name.right(1).toInt(); m_gainband[i] = value;
--- a/sv/filter/EqualizerFilter.h Thu Mar 06 17:14:31 2008 +0000 +++ b/sv/filter/EqualizerFilter.h Fri Mar 07 15:01:27 2008 +0000 @@ -64,6 +64,7 @@ void filterEnabled(bool); void signalChanged(float *); void filterChanged(float *); + void enableDrawCurve(bool); public slots : void setFilterEnabled(bool b);
--- a/widgets/Plotter.cpp Thu Mar 06 17:14:31 2008 +0000 +++ b/widgets/Plotter.cpp Fri Mar 07 15:01:27 2008 +0000 @@ -19,7 +19,8 @@ m_signalWidth(400), m_signalHeight(120), m_margin(5), -m_curveMaskActive(false) +m_curveMaskActive(false), +m_enableDrawCurve(false) { //m_curveMask = new int[m_signalWidth]; for(int i = 0 ; i < m_signalWidth ; i++){ @@ -66,84 +67,93 @@ QRect rect(m_margin, m_margin, m_signalWidth + m_margin, m_signalHeight + m_margin); - if (event->button() == Qt::LeftButton) { - if (rect.contains(event->pos())) { - m_curveMaskActive = true; - int x = event->pos().x()- m_margin; - int y = event->pos().y()- m_margin; - m_curveMask[x] = y; - m_lastPoint.setX(x); - m_lastPoint.setY(y); - setCursor(Qt::CrossCursor); - refreshPixmap(); - } - } + if (m_enableDrawCurve) + { + if (event->button() == Qt::LeftButton) { + if (rect.contains(event->pos())) { + m_curveMaskActive = true; + int x = event->pos().x()- m_margin; + int y = event->pos().y()- m_margin; + m_curveMask[x] = y; + m_lastPoint.setX(x); + m_lastPoint.setY(y); + setCursor(Qt::CrossCursor); + refreshPixmap(); + } + } + } } void Plotter::mouseMoveEvent(QMouseEvent *event){ QRect rect(m_margin, m_margin, m_signalWidth + m_margin , m_signalHeight + m_margin); - if(m_curveMaskActive && rect.contains(event->pos())){ - int x = event->pos().x() - m_margin; - int y = event->pos().y() - m_margin; - if(y>m_signalHeight-1) - y= m_signalHeight-1; - if(x>m_signalWidth-1) - y= m_signalWidth-1; - int xlast = m_lastPoint.x(); - int ylast = m_lastPoint.y(); + if (m_enableDrawCurve) + { + if(m_curveMaskActive && rect.contains(event->pos())){ + int x = event->pos().x() - m_margin; + int y = event->pos().y() - m_margin; + if(y>m_signalHeight-1) + y= m_signalHeight-1; + if(x>m_signalWidth-1) + y= m_signalWidth-1; + int xlast = m_lastPoint.x(); + int ylast = m_lastPoint.y(); - //regul mask curve - int minx, maxx, miny, maxy; - if(x>xlast){ - minx = xlast; - maxx = x; - }else{ - minx = x; - maxx = xlast; - } - if(y>ylast){ - miny = ylast; - maxy = y; - }else{ - miny = y; - maxy = ylast; - } + //regul mask curve + int minx, maxx, miny, maxy; + if(x>xlast){ + minx = xlast; + maxx = x; + }else{ + minx = x; + maxx = xlast; + } + if(y>ylast){ + miny = ylast; + maxy = y; + }else{ + miny = y; + maxy = ylast; + } - if((maxx - minx)>1){ - double incr = (double)(maxy - miny)/(double)(maxx - minx); - if(x>xlast){ - for (int i = xlast + 1 ; i < x ; i++){ - if(ylast > y){ - m_curveMask[i] = ylast - (i-xlast)*incr; - }else{ - m_curveMask[i] = ylast + (i-xlast)*incr; + if((maxx - minx)>1){ + double incr = (double)(maxy - miny)/(double)(maxx - minx); + if(x>xlast){ + for (int i = xlast + 1 ; i < x ; i++){ + if(ylast > y){ + m_curveMask[i] = ylast - (i-xlast)*incr; + }else{ + m_curveMask[i] = ylast + (i-xlast)*incr; + } } - } - }else{ - for (int i = xlast - 1 ; i > x ; i--){ - if(ylast > y){ - m_curveMask[i] = ylast + (i-xlast)*incr; - }else{ - m_curveMask[i] = ylast - (i-xlast)*incr; + }else{ + for (int i = xlast - 1 ; i > x ; i--){ + if(ylast > y){ + m_curveMask[i] = ylast + (i-xlast)*incr; + }else{ + m_curveMask[i] = ylast - (i-xlast)*incr; + } } } } + m_curveMask[x] = y; + m_lastPoint.setX(x); + m_lastPoint.setY(y); + refreshPixmap(); } - m_curveMask[x] = y; - m_lastPoint.setX(x); - m_lastPoint.setY(y); - refreshPixmap(); } } void Plotter::mouseReleaseEvent(QMouseEvent *event){ - if ((event->button() == Qt::LeftButton) && m_curveMaskActive) { - m_curveMaskActive = false; - unsetCursor(); - emit filterChanged(m_curveMask); - } + if (m_enableDrawCurve) + { + if ((event->button() == Qt::LeftButton) && m_curveMaskActive) { + m_curveMaskActive = false; + unsetCursor(); + emit filterChanged(m_curveMask); + } + } } void Plotter::drawGrid(QPainter *painter){ @@ -204,4 +214,9 @@ m_curveMask.push_back((int) (m_signalHeight - filter[i]*(m_signalHeight/2-1))); } refreshPixmap(); +} + +void Plotter::enableDrawCurve(bool enable) +{ + m_enableDrawCurve = enable; } \ No newline at end of file
--- a/widgets/Plotter.h Thu Mar 06 17:14:31 2008 +0000 +++ b/widgets/Plotter.h Fri Mar 07 15:01:27 2008 +0000 @@ -39,6 +39,7 @@ public slots: void setCurve(float *); void setFilter(float *); + void enableDrawCurve(bool); protected: @@ -61,6 +62,8 @@ int m_margin; bool m_curveMaskActive; QPoint m_lastPoint; + + bool m_enableDrawCurve; };
--- a/widgets/PropertyBox.cpp Thu Mar 06 17:14:31 2008 +0000 +++ b/widgets/PropertyBox.cpp Fri Mar 07 15:01:27 2008 +0000 @@ -438,6 +438,7 @@ slider->setFixedWidth(48); slider->setFixedHeight(100); m_groupLayouts[groupName]->addWidget(slider); + connect(m_container, SIGNAL(enableDrawCurve(bool)), slider, SLOT(setDisabled(bool))); } else { slider->setFixedWidth(100); @@ -574,6 +575,7 @@ connect(cb, SIGNAL(filterChanged(QVector<float>&)), this, SLOT(propertyControllerChanged(QVector<float>&))); connect(m_container, SIGNAL(signalChanged(float*)), cb, SLOT(setCurve(float*))); connect(m_container, SIGNAL(filterChanged(float*)), cb, SLOT(setFilter(float*))); + connect(m_container, SIGNAL(enableDrawCurve(bool)), cb, SLOT(enableDrawCurve(bool))); connect(cb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); connect(cb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));