comparison src/Analyser.cpp @ 6:ab5b3300ba1a

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