annotate src/Analyser.cpp @ 11:563cc01f2b8d

added references to new FlexiNote layer and model
author matthiasm
date Tue, 26 Mar 2013 14:48:03 +0000
parents ab5b3300ba1a
children 47589fdb0b53
rev   line source
Chris@6 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@6 2
Chris@6 3 /*
Chris@6 4 Tony
Chris@6 5 An intonation analysis and annotation tool
Chris@6 6 Centre for Digital Music, Queen Mary, University of London.
Chris@6 7 This file copyright 2006-2012 Chris Cannam and QMUL.
Chris@6 8
Chris@6 9 This program is free software; you can redistribute it and/or
Chris@6 10 modify it under the terms of the GNU General Public License as
Chris@6 11 published by the Free Software Foundation; either version 2 of the
Chris@6 12 License, or (at your option) any later version. See the file
Chris@6 13 COPYING included with this distribution for more information.
Chris@6 14 */
Chris@6 15
Chris@6 16 #include "Analyser.h"
Chris@6 17
Chris@6 18 #include "transform/TransformFactory.h"
Chris@6 19 #include "transform/ModelTransformer.h"
Chris@6 20 #include "framework/Document.h"
Chris@6 21 #include "data/model/WaveFileModel.h"
Chris@6 22 #include "view/Pane.h"
Chris@6 23 #include "view/PaneStack.h"
Chris@6 24 #include "layer/Layer.h"
Chris@6 25 #include "layer/TimeValueLayer.h"
matthiasm@11 26 #include "layer/FlexiNoteLayer.h"
Chris@6 27 #include "layer/ColourDatabase.h"
Chris@6 28
Chris@6 29 Analyser::Analyser() :
Chris@6 30 m_document(0),
Chris@6 31 m_fileModel(0),
Chris@6 32 m_pane(0)
Chris@6 33 {
Chris@6 34 }
Chris@6 35
Chris@6 36 Analyser::~Analyser()
Chris@6 37 {
Chris@6 38 }
Chris@6 39
Chris@6 40 void
Chris@6 41 Analyser::newFileLoaded(Document *doc, WaveFileModel *model,
Chris@6 42 PaneStack *paneStack, Pane *pane)
Chris@6 43 {
Chris@6 44 m_document = doc;
Chris@6 45 m_fileModel = model;
Chris@6 46 m_pane = pane;
Chris@6 47
Chris@6 48 TransformId f0 = "vamp:cepstral-pitchtracker:cepstral-pitchtracker:f0";
Chris@6 49 TransformId notes = "vamp:cepstral-pitchtracker:cepstral-pitchtracker:notes";
Chris@6 50
Chris@6 51 // We don't want a waveform in the main pane. We must have a
Chris@6 52 // main-model layer of some sort, but the layers created by
Chris@6 53 // transforms are derived layers, so we'll create a time ruler for
Chris@6 54 // the main-model layer. It could subsequently be hidden if we
Chris@6 55 // didn't want it
Chris@6 56
Chris@6 57 m_document->addLayerToView
Chris@6 58 (m_pane, m_document->createMainModelLayer(LayerFactory::TimeRuler));
Chris@6 59
Chris@6 60 Layer *layer = 0;
Chris@6 61
Chris@6 62 layer = addLayerFor(f0);
Chris@6 63
Chris@6 64 if (layer) {
Chris@6 65 TimeValueLayer *tvl = qobject_cast<TimeValueLayer *>(layer);
Chris@6 66 if (tvl) {
Chris@6 67 tvl->setPlotStyle(TimeValueLayer::PlotDiscreteCurves);
Chris@6 68 tvl->setBaseColour(ColourDatabase::getInstance()->
Chris@6 69 getColourIndex(QString("Black")));
Chris@6 70 }
Chris@6 71 }
Chris@6 72
Chris@6 73 layer = addLayerFor(notes);
Chris@6 74
Chris@6 75 if (layer) {
matthiasm@11 76 FlexiNoteLayer *nl = qobject_cast<FlexiNoteLayer *>(layer);
Chris@6 77 if (nl) {
Chris@6 78 nl->setBaseColour(ColourDatabase::getInstance()->
Chris@6 79 getColourIndex(QString("Bright Blue")));
Chris@6 80 }
Chris@6 81 }
Chris@6 82
Chris@6 83 paneStack->setCurrentLayer(m_pane, layer);
Chris@6 84 }
Chris@6 85
Chris@6 86 Layer *
Chris@6 87 Analyser::addLayerFor(TransformId id)
Chris@6 88 {
Chris@6 89 TransformFactory *tf = TransformFactory::getInstance();
Chris@6 90
Chris@6 91 if (!tf->haveTransform(id)) {
Chris@6 92 std::cerr << "ERROR: Analyser::addLayerFor(" << id << "): Transform unknown" << std::endl;
Chris@6 93 return 0;
Chris@6 94 }
Chris@6 95
Chris@6 96 Transform transform = tf->getDefaultTransformFor
Chris@6 97 (id, m_fileModel->getSampleRate());
Chris@6 98
matthiasm@11 99 transform.setStepSize(512);
Chris@6 100 transform.setBlockSize(2048);
Chris@6 101
Chris@6 102 ModelTransformer::Input input(m_fileModel, -1);
Chris@6 103
Chris@6 104 Layer *layer;
Chris@6 105 layer = m_document->createDerivedLayer(transform, m_fileModel);
Chris@6 106 if (layer) {
Chris@6 107 m_document->addLayerToView(m_pane, layer);
Chris@6 108 }
Chris@6 109
Chris@6 110 return layer;
Chris@6 111 }
Chris@6 112