Mercurial > hg > svgui
changeset 602:d030353eb9ac integration_library
Merge from the default branch
author | mathieub <mathieu.barthet@eecs.qmul.ac.uk> |
---|---|
date | Mon, 17 Oct 2011 15:25:57 +0100 |
parents | 2bf6dc6bc4d1 (diff) 3c29f7c1f079 (current diff) |
children | |
files | |
diffstat | 11 files changed, 216 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Layer.h Mon Oct 17 11:57:37 2011 +0100 +++ b/layer/Layer.h Mon Oct 17 15:25:57 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 */, @@ -247,6 +250,14 @@ */ virtual bool editOpen(View *, QMouseEvent *) { return false; } + /** + * A click occurred over the layer's scale area. If the layer has + * a response to this (e.g. play a note corresponding to frequency + * scale), perform it and return true. Return false if this click + * is not meaningful to the layer. + */ + virtual bool scaleClicked(const View *, QMouseEvent *) { return false; } + virtual void moveSelection(Selection, size_t /* newStartFrame */) { } virtual void resizeSelection(Selection, Selection /* newSize */) { } virtual void deleteSelection(Selection) { }
--- a/layer/SpectrogramLayer.cpp Mon Oct 17 11:57:37 2011 +0100 +++ b/layer/SpectrogramLayer.cpp Mon Oct 17 15:25:57 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(); @@ -3781,3 +3785,31 @@ setNormalizeVisibleArea(normalizeVisibleArea); } +bool +SpectrogramLayer::scaleClicked(const View *v, QMouseEvent *e) +{ + //std::cerr<< "Mouse click detected in the spectrogram scale area: (" << e->x() << "," << e->y() << ")" << std::endl; + + float freq; + QString unit; + float *centsOffsetReturn = 0; + float concertA = 0.0; + int midipitch; + + if (getYScaleValue(v, e->y(), 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/SpectrogramLayer.h Mon Oct 17 11:57:37 2011 +0100 +++ b/layer/SpectrogramLayer.h Mon Oct 17 15:25:57 2011 +0100 @@ -227,6 +227,8 @@ virtual const Model *getSliceableModel() const; + virtual bool scaleClicked(const View *, QMouseEvent *); + protected slots: void cacheInvalid(); void cacheInvalid(size_t startFrame, size_t endFrame);
--- a/layer/SpectrumLayer.cpp Mon Oct 17 11:57:37 2011 +0100 +++ b/layer/SpectrumLayer.cpp Mon Oct 17 15:25:57 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 Mon Oct 17 11:57:37 2011 +0100 +++ b/layer/SpectrumLayer.h Mon Oct 17 15:25:57 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 Mon Oct 17 11:57:37 2011 +0100 +++ b/view/Pane.cpp Mon Oct 17 15:25:57 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" @@ -25,6 +24,10 @@ #include "base/Preferences.h" #include "layer/WaveformLayer.h" +#include "layer/LayerFactory.h" +#include "layer/Layer.h" +#include "layer/SpectrogramLayer.h" + //!!! ugh #include "data/model/WaveFileModel.h" @@ -1291,6 +1294,79 @@ 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), + // we've nothing else to do + Layer *layer = getTopLayer(); + if (layer) { + if (layer->scaleClicked(this, e)) { + m_clickedInRange = false; + emit paneInteractedWith(); + return; + } + } + } + */ + if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton) || (mode == ViewManager::MeasureMode &&
--- a/view/Pane.h Mon Oct 17 11:57:37 2011 +0100 +++ b/view/Pane.h Mon Oct 17 15:25:57 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);
--- a/view/View.cpp Mon Oct 17 11:57:37 2011 +0100 +++ b/view/View.cpp Mon Oct 17 15:25:57 2011 +0100 @@ -2365,6 +2365,12 @@ } void +View::playExampleNote(int midiPitch) const +{ + if (m_manager) m_manager->playExampleNote(midiPitch); +} + +void View::toXml(QTextStream &stream, QString indent, QString extraAttributes) const {
--- a/view/View.h Mon Oct 17 11:57:37 2011 +0100 +++ b/view/View.h Mon Oct 17 15:25:57 2011 +0100 @@ -307,6 +307,8 @@ virtual void progressCheckStalledTimerElapsed(); + virtual void playExampleNote(int midiPitch) const; + protected: View(QWidget *, bool showProgress); virtual void paintEvent(QPaintEvent *e);
--- a/view/ViewManager.cpp Mon Oct 17 11:57:37 2011 +0100 +++ b/view/ViewManager.cpp Mon Oct 17 15:25:57 2011 +0100 @@ -48,7 +48,8 @@ m_illuminateLocalFeatures(true), m_showWorkTitle(false), m_lightPalette(QApplication::palette()), - m_darkPalette(QApplication::palette()) + m_darkPalette(QApplication::palette()), + m_minimalModeEnabled(0) { QSettings settings; settings.beginGroup("MainWindow"); @@ -190,6 +191,12 @@ else return m_playbackModel->alignFromReference(frame); } +void +ViewManager::playExampleNote(int midiPitch) +{ + m_playSource->queueExampleNote(midiPitch); +} + bool ViewManager::haveInProgressSelection() const { @@ -637,3 +644,19 @@ return dark; } +void +ViewManager::setMinimalModeEnabled(bool enabled) +{ + if (m_minimalModeEnabled != enabled) { + m_minimalModeEnabled = enabled; + emit minimalModeEnabledChanged(); + if (enabled) emit activity("Activates minimal mode"); + else emit activity("Activates full mode"); + } + + QSettings settings; + settings.beginGroup("MainWindow"); + settings.setValue("minimal-mode-enabled", m_minimalModeEnabled); + settings.endGroup(); +} +
--- a/view/ViewManager.h Mon Oct 17 11:57:37 2011 +0100 +++ b/view/ViewManager.h Mon Oct 17 15:25:57 2011 +0100 @@ -188,6 +188,9 @@ void setGlobalDarkBackground(bool dark); bool getGlobalDarkBackground() const; + void setMinimalModeEnabled(bool enable); + bool getMinimalModeEnabled() const { return m_minimalModeEnabled; }; + signals: /** Emitted when user causes the global centre frame to change. */ void globalCentreFrameChanged(unsigned long frame); @@ -238,11 +241,17 @@ /** Emitted when any loggable activity has occurred. */ void activity(QString); + /** Emitted when the view mode has been toggled. */ + //no slot associated yet with this signal but may be useful; + //changes currently handled by the slot MainWindow::toggleViewMode() + void minimalModeEnabledChanged(); + public slots: void viewCentreFrameChanged(unsigned long, bool, PlaybackFollowMode); void viewZoomLevelChanged(unsigned long, bool); void setGlobalCentreFrame(unsigned long); void setPlaybackFrame(unsigned long); + void playExampleNote(int midiPitch); protected slots: void checkPlayStatus(); @@ -297,6 +306,8 @@ bool m_illuminateLocalFeatures; bool m_showWorkTitle; + bool m_minimalModeEnabled; + QPalette m_lightPalette; QPalette m_darkPalette; };