comparison src/Analyser.cpp @ 165:ebcfb8dce020

Replace previous candidates when making a new analysis. Also revert to built-in spectrogram for now (CQ is still pending)
author Chris Cannam
date Fri, 31 Jan 2014 17:54:49 +0000
parents 62ceae757fe0
children 6b6906017536
comparison
equal deleted inserted replaced
164:62ceae757fe0 165:ebcfb8dce020
70 m_document = doc; 70 m_document = doc;
71 m_fileModel = model; 71 m_fileModel = model;
72 m_paneStack = paneStack; 72 m_paneStack = paneStack;
73 m_pane = pane; 73 m_pane = pane;
74 74
75 m_reAnalysingSelection = Selection();
76 m_reAnalysisCandidates.clear();
77
75 // Note that we need at least one main-model layer (time ruler, 78 // Note that we need at least one main-model layer (time ruler,
76 // waveform or what have you). It could be hidden if we don't want 79 // waveform or what have you). It could be hidden if we don't want
77 // to see it but it must exist. 80 // to see it but it must exist.
78 81
79 QString warning, error; 82 QString warning, error;
97 100
98 return warning; 101 return warning;
99 } 102 }
100 103
101 QString 104 QString
102 Analyser::reAnalyseSelection(Selection sel)
103 {
104 return addTestCandidates(sel);
105 }
106
107 QString
108 Analyser::addVisualisations() 105 Analyser::addVisualisations()
109 { 106 {
107 /*
110 TransformFactory *tf = TransformFactory::getInstance(); 108 TransformFactory *tf = TransformFactory::getInstance();
111 109
112 QString name = "Constant-Q"; 110 QString name = "Constant-Q";
113 QString base = "vamp:cqvamp:cqvamp:"; 111 QString base = "vamp:cqvamp:cqvamp:";
114 QString out = "constantq"; 112 QString out = "constantq";
127 125
128 Colour3DPlotLayer *spectrogram = qobject_cast<Colour3DPlotLayer *> 126 Colour3DPlotLayer *spectrogram = qobject_cast<Colour3DPlotLayer *>
129 (m_document->createDerivedLayer(transform, m_fileModel)); 127 (m_document->createDerivedLayer(transform, m_fileModel));
130 128
131 if (!spectrogram) return tr("Transform \"%1\" did not run correctly (no layer or wrong layer type returned)").arg(base + out); 129 if (!spectrogram) return tr("Transform \"%1\" did not run correctly (no layer or wrong layer type returned)").arg(base + out);
132 130 */
133 /* 131
134 SpectrogramLayer *spectrogram = qobject_cast<SpectrogramLayer *> 132 SpectrogramLayer *spectrogram = qobject_cast<SpectrogramLayer *>
135 (m_document->createMainModelLayer(LayerFactory::MelodicRangeSpectrogram)); 133 (m_document->createMainModelLayer(LayerFactory::MelodicRangeSpectrogram));
136 */ 134
137 spectrogram->setColourMap((int)ColourMapper::BlackOnWhite); 135 spectrogram->setColourMap((int)ColourMapper::BlackOnWhite);
138 spectrogram->setNormalizeHybrid(true); 136 spectrogram->setNormalizeHybrid(true);
139 spectrogram->setSmooth(true); 137 // spectrogram->setSmooth(true);
140 spectrogram->setGain(0.5); //!!! arbitrary at this point 138 // spectrogram->setGain(0.5); //!!! arbitrary at this point
139 spectrogram->setGain(100);
141 m_document->addLayerToView(m_pane, spectrogram); 140 m_document->addLayerToView(m_pane, spectrogram);
142 spectrogram->setLayerDormant(m_pane, true); 141 spectrogram->setLayerDormant(m_pane, true);
143 142
144 m_layers[Spectrogram] = spectrogram; 143 m_layers[Spectrogram] = spectrogram;
145 144
245 244
246 return ""; 245 return "";
247 } 246 }
248 247
249 QString 248 QString
250 Analyser::addTestCandidates(Selection sel) 249 Analyser::reAnalyseSelection(Selection sel)
251 { 250 {
251 if (sel == m_reAnalysingSelection) return "";
252
253 foreach (Layer *layer, m_reAnalysisCandidates) {
254 cerr << "deleting previous candidate layer " << layer << endl;
255 m_pane->removeLayer(layer);
256 m_document->deleteLayer(layer); // also releases its model
257 }
258 m_reAnalysisCandidates.clear();
259 m_reAnalysingSelection = sel;
260
252 TransformFactory *tf = TransformFactory::getInstance(); 261 TransformFactory *tf = TransformFactory::getInstance();
253 262
254 QString plugname = "pYIN"; 263 QString plugname = "pYIN";
255 QString base = "vamp:pyin:localcandidatepyin:"; 264 QString base = "vamp:pyin:localcandidatepyin:";
256 QString out = "pitchtrackcandidates"; 265 QString out = "pitchtrackcandidates";
291 300
292 void 301 void
293 Analyser::layersCreated(vector<Layer *> primary, 302 Analyser::layersCreated(vector<Layer *> primary,
294 vector<Layer *> additional) 303 vector<Layer *> additional)
295 { 304 {
305 //!!! how do we know these came from the right selection? user
306 //!!! might have made another one since this request was issued
307
296 for (int i = 0; i < (int)primary.size(); ++i) { 308 for (int i = 0; i < (int)primary.size(); ++i) {
297 TimeValueLayer *t = qobject_cast<TimeValueLayer *>(primary[i]); 309 TimeValueLayer *t = qobject_cast<TimeValueLayer *>(primary[i]);
298 if (t) m_document->addLayerToView(m_pane, t); 310 if (t) {
311 m_document->addLayerToView(m_pane, t);
312 m_reAnalysisCandidates.push_back(t);
313 }
299 } 314 }
300 315
301 for (int i = 0; i < (int)additional.size(); ++i) { 316 for (int i = 0; i < (int)additional.size(); ++i) {
302 TimeValueLayer *t = qobject_cast<TimeValueLayer *>(additional[i]); 317 TimeValueLayer *t = qobject_cast<TimeValueLayer *>(additional[i]);
303 if (t) m_document->addLayerToView(m_pane, t); 318 if (t) {
319 m_document->addLayerToView(m_pane, t);
320 m_reAnalysisCandidates.push_back(t);
321 }
304 } 322 }
305 } 323 }
306 324
307 void 325 void
308 Analyser::getEnclosingSelectionScope(size_t f, size_t &f0, size_t &f1) 326 Analyser::getEnclosingSelectionScope(size_t f, size_t &f0, size_t &f1)