Mercurial > hg > tony
changeset 161:afaa4af03b22
Refactor, call to constant-Q plugin instead of spectrogram
author | Chris Cannam |
---|---|
date | Tue, 28 Jan 2014 16:01:06 +0000 |
parents | 106fdf38c6c9 |
children | cc9aa8f4fceb |
files | src/Analyser.cpp src/Analyser.h |
diffstat | 2 files changed, 72 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Analyser.cpp Thu Jan 23 17:18:53 2014 -0500 +++ b/src/Analyser.cpp Tue Jan 28 16:01:06 2014 +0000 @@ -31,6 +31,7 @@ #include "layer/ColourMapper.h" #include "layer/LayerFactory.h" #include "layer/SpectrogramLayer.h" +#include "layer/Colour3DPlotLayer.h" #include <QSettings> @@ -69,26 +70,73 @@ m_paneStack = paneStack; m_pane = pane; - QString plugname = "pYIN"; - QString base = "vamp:pyin:pyin:"; - QString f0out = "smoothedpitchtrack"; - QString noteout = "notes"; + // Note that we need at least one main-model layer (time ruler, + // waveform or what have you). It could be hidden if we don't want + // to see it but it must exist. - // We need at least one main-model layer (time ruler, waveform or - // what have you). It could be hidden if we don't want to see it - // but it must exist. + QString warning, error; + + // This isn't fatal -- we can proceed without + // visualisations. Other failures are fatal though. + warning = addVisualisations(); + + error = addWaveform(); + if (error != "") return error; + + error = addAnalyses(); + if (error != "") return error; + + loadState(Audio); + loadState(PitchTrack); + loadState(Notes); + loadState(Spectrogram); + + emit layersChanged(); + + return warning; +} + +QString +Analyser::addVisualisations() +{ + TransformFactory *tf = TransformFactory::getInstance(); + + QString name = "Constant-Q"; + QString base = "vamp:cqvamp:cqvamp:"; + QString out = "constantq"; // A spectrogram, off by default. Must go at the back because it's // opaque + QString notFound = tr("Transform \"%1\" not found, spectrogram will not be enabled.<br><br>Is the %2 Vamp plugin correctly installed?"); + if (!tf->haveTransform(base + out)) { + return notFound.arg(base + out).arg(name); + } + + Transform transform = tf->getDefaultTransformFor + (base + out, m_fileModel->getSampleRate()); + + Colour3DPlotLayer *spectrogram = qobject_cast<Colour3DPlotLayer *> + (m_document->createDerivedLayer(transform, m_fileModel)); + + if (!spectrogram) return tr("Transform \"%1\" did not run correctly (no layer or wrong layer type returned)").arg(base + out); + +/* SpectrogramLayer *spectrogram = qobject_cast<SpectrogramLayer *> (m_document->createMainModelLayer(LayerFactory::MelodicRangeSpectrogram)); +*/ spectrogram->setColourMap((int)ColourMapper::BlackOnWhite); m_document->addLayerToView(m_pane, spectrogram); spectrogram->setLayerDormant(m_pane, true); m_layers[Spectrogram] = spectrogram; + return ""; +} + +QString +Analyser::addWaveform() +{ // Our waveform layer is just a shadow, light grey and taking up // little space at the bottom @@ -105,10 +153,20 @@ m_document->addLayerToView(m_pane, waveform); m_layers[Audio] = waveform; + return ""; +} + +QString +Analyser::addAnalyses() +{ + TransformFactory *tf = TransformFactory::getInstance(); + + QString plugname = "pYIN"; + QString base = "vamp:pyin:pyin:"; + QString f0out = "smoothedpitchtrack"; + QString noteout = "notes"; Transforms transforms; - - TransformFactory *tf = TransformFactory::getInstance(); /*!!! we could have more than one pitch track... QString cx = "vamp:cepstral-pitchtracker:cepstral-pitchtracker:f0"; @@ -175,14 +233,7 @@ if (params) params->setPlayPan(1); } } - - loadState(Audio); - loadState(PitchTrack); - loadState(Notes); - loadState(Spectrogram); - - emit layersChanged(); - + return ""; }
--- a/src/Analyser.h Thu Jan 23 17:18:53 2014 -0500 +++ b/src/Analyser.h Tue Jan 28 16:01:06 2014 +0000 @@ -89,6 +89,10 @@ Pane *m_pane; mutable std::map<Component, Layer *> m_layers; + QString addVisualisations(); + QString addWaveform(); + QString addAnalyses(); + void saveState(Component c) const; void loadState(Component c); };