Mercurial > hg > svgui
changeset 592:a13aa5320221 sonification
Extends the audio feedback of the piano scale to the Spectrum layer (horizontal piano keyboard).
Increase of the piano keyboard width (SpectrogramLayer) and height (SpectrumLayer) for layout purposes. A get method should be added to obtain the scale size parameter outside the layer class.
author | mathieub <mathieu.barthet@eecs.qmul.ac.uk> |
---|---|
date | Wed, 06 Jul 2011 18:05:42 +0100 |
parents | 0946feb81b79 |
children | 5fa210337bee |
files | layer/Layer.h layer/SpectrogramLayer.cpp layer/SpectrumLayer.cpp layer/SpectrumLayer.h view/Pane.cpp view/Pane.h |
diffstat | 6 files changed, 121 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Layer.h Fri Jun 24 16:42:48 2011 +0100 +++ b/layer/Layer.h Wed Jul 06 18:05:42 2011 +0100 @@ -129,6 +129,9 @@ virtual QPixmap getLayerPresentationPixmap(QSize) const { return QPixmap(); } virtual int getVerticalScaleWidth(View *, QPainter &) const { return 0; } + + //virtual int getHorizontalScaleHeight(View *, QPainter &) const { return 0; } //this causes the application to crash at startup? + virtual void paintVerticalScale(View *, QPainter &, QRect) const { } virtual bool getCrosshairExtents(View *, QPainter &, QPoint /* cursorPos */,
--- a/layer/SpectrogramLayer.cpp Fri Jun 24 16:42:48 2011 +0100 +++ b/layer/SpectrogramLayer.cpp Wed Jul 06 18:05:42 2011 +0100 @@ -3274,7 +3274,8 @@ int fw = paint.fontMetrics().width(tr("43Hz")); if (tw < fw) tw = fw; - int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4); + //int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4); + int tickw = (m_frequencyScale == LogFrequencyScale ? 20 : 4); return cw + tickw + tw + 13; } @@ -3292,8 +3293,11 @@ int h = rect.height(), w = rect.width(); - int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4); - int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0); + //int tickw = (m_frequencyScale == LogFrequencyScale ? 10 : 4); + //int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0); + + int tickw = (m_frequencyScale == LogFrequencyScale ? 20 : 4); + int pkw = (m_frequencyScale == LogFrequencyScale ? 20 : 0); size_t bins = m_fftSize / 2; int sr = m_model->getSampleRate(); @@ -3798,7 +3802,9 @@ std::cerr<< "Frequency: " << freq << " " << unit.toStdString() << " (midi pitch = " << midipitch << ")" << std::endl; - v->playExampleNote(midipitch); + if ((midipitch>=0)&&(midipitch<127)) { + v->playExampleNote(midipitch); + } return true;
--- a/layer/SpectrumLayer.cpp Fri Jun 24 16:42:48 2011 +0100 +++ b/layer/SpectrumLayer.cpp Wed Jul 06 18:05:42 2011 +0100 @@ -25,7 +25,7 @@ #include <QPainter> #include <QTextStream> - +#include <QMouseEvent> SpectrumLayer::SpectrumLayer() : m_originModel(0), @@ -673,7 +673,9 @@ int pkh = 0; //!!! if (m_binScale == LogBins) { - pkh = 10; + //pkh = 10; //too small + pkh = 20; + //!!! } paint.save(); @@ -823,6 +825,17 @@ paint.restore(); } +/* +int +SpectrumLayer::getHorizontalScaleHeight(View *v, QPainter &paint) const +{ + int h = v->height(); + int pkh = 10; + + return h - pkh - 1; +}*/ + + void SpectrumLayer::getBiasCurve(BiasCurve &curve) const { @@ -860,4 +873,30 @@ setShowPeaks(showPeaks); } - +bool +SpectrumLayer::scaleClicked(const View *v, QMouseEvent *e) +{ + std::cerr<< "Mouse click detected in the spectrum scale area: (" << e->x() << "," << e->y() << ")" << std::endl; + + float freq; + QString unit; + float *centsOffsetReturn = 0; + float concertA = 0.0; + int midipitch; + + if (getXScaleValue(v, e->x(), freq, unit)) { + + midipitch = Pitch::getPitchForFrequency(freq,centsOffsetReturn,concertA); + + std::cerr<< "Frequency: " << freq << " " << unit.toStdString() << " (midi pitch = " << midipitch << ")" << std::endl; + + if ((midipitch>=0)&&(midipitch<127)) { + v->playExampleNote(midipitch); + } + + return true; + + } else { + return false; + } +}
--- a/layer/SpectrumLayer.h Fri Jun 24 16:42:48 2011 +0100 +++ b/layer/SpectrumLayer.h Wed Jul 06 18:05:42 2011 +0100 @@ -45,6 +45,8 @@ virtual QString getFeatureDescription(View *v, QPoint &) const; + //virtual int getHorizontalScaleHeight(View *, QPainter &) const; + virtual void paint(View *v, QPainter &paint, QRect rect) const; virtual VerticalPosition getPreferredFrameCountPosition() const { @@ -96,6 +98,8 @@ virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; + virtual bool scaleClicked(const View *, QMouseEvent *); + protected slots: void preferenceChanged(PropertyContainer::PropertyName name);
--- a/view/Pane.cpp Fri Jun 24 16:42:48 2011 +0100 +++ b/view/Pane.cpp Wed Jul 06 18:05:42 2011 +0100 @@ -14,7 +14,6 @@ */ #include "Pane.h" -#include "layer/Layer.h" #include "data/model/Model.h" #include "base/ZoomConstraint.h" #include "base/RealTime.h" @@ -1290,7 +1289,65 @@ m_resizing = false; m_editing = false; m_releasing = false; - + + bool scaleclick = false; + + Layer *layer = getTopLayer(); + if (layer) { + LayerFactory::LayerType type = LayerFactory::getInstance()->getLayerType(layer); + + //std::cerr << "hello before switch: " << LayerFactory::getInstance()->getLayerTypeName(type) << std::endl; + + switch(type) { + + case LayerFactory::Spectrogram: + { + std::cerr << "hello spectrogram ("<< e->x() <<", " << e->y() << ")" << std::endl; + } + case LayerFactory::MelodicRangeSpectrogram: + { + std::cerr << "hello melodic ("<< e->x() <<", " << e->y() << ")" << std::endl; + int sw = getVerticalScaleWidth(); + int pkhms = 20; //this value should be retrieved from SpectrogramLayer + int slb = sw - pkhms - 1; //scale left border + + //std::cerr << "slb: "<< slb << std::endl; + + if ((e->x() < sw)&&(e->x() > slb)) { + scaleclick = true; + } + break; + } + case LayerFactory::Spectrum: + { + std::cerr << "hello spectrum ("<< e->x() <<", " << e->y() << ")" << std::endl; + + int h = height(); + int pkhs = 20; //this value should be retrieved from SpectrumLayer + + int sh = h - pkhs - 1; + + //if (e->y() < layer->getHorizontalScaleHeight(this)) { + + if (e->y() > sh) { + scaleclick = true; + } + break; + } + } + + if (scaleclick) { + // Click occurred over the layer's scale area. Ask the layer + // to do something with it: if it does so (i.e. returns true), + // we've nothing else to do + if (layer->scaleClicked(this, e)) { + m_clickedInRange = false; + emit paneInteractedWith(); + return; + } + } + } + /* if (e->x() < getVerticalScaleWidth()) { // Click occurred over the layer's scale area. Ask the layer // to do something with it: if it does so (i.e. returns true), @@ -1304,6 +1361,7 @@ } } } + */ if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton) ||
--- a/view/Pane.h Fri Jun 24 16:42:48 2011 +0100 +++ b/view/Pane.h Wed Jul 06 18:05:42 2011 +0100 @@ -52,6 +52,8 @@ virtual size_t getVerticalScaleWidth() const; + //virtual size_t getHorizontalScaleHeight() const; + virtual QImage *toNewImage(size_t f0, size_t f1); virtual QImage *toNewImage() { return View::toNewImage(); } virtual QSize getImageSize(size_t f0, size_t f1);