comparison src/Analyser.cpp @ 167:6b6906017536

Choose a different pitch candidate within selection by hitting Return
author Chris Cannam
date Mon, 03 Feb 2014 17:04:03 +0000
parents ebcfb8dce020
children c5e4eaeb9a27
comparison
equal deleted inserted replaced
165:ebcfb8dce020 167:6b6906017536
72 m_paneStack = paneStack; 72 m_paneStack = paneStack;
73 m_pane = pane; 73 m_pane = pane;
74 74
75 m_reAnalysingSelection = Selection(); 75 m_reAnalysingSelection = Selection();
76 m_reAnalysisCandidates.clear(); 76 m_reAnalysisCandidates.clear();
77 m_currentCandidate = -1;
77 78
78 // Note that we need at least one main-model layer (time ruler, 79 // Note that we need at least one main-model layer (time ruler,
79 // waveform or what have you). It could be hidden if we don't want 80 // waveform or what have you). It could be hidden if we don't want
80 // to see it but it must exist. 81 // to see it but it must exist.
81 82
134 135
135 spectrogram->setColourMap((int)ColourMapper::BlackOnWhite); 136 spectrogram->setColourMap((int)ColourMapper::BlackOnWhite);
136 spectrogram->setNormalizeHybrid(true); 137 spectrogram->setNormalizeHybrid(true);
137 // spectrogram->setSmooth(true); 138 // spectrogram->setSmooth(true);
138 // spectrogram->setGain(0.5); //!!! arbitrary at this point 139 // spectrogram->setGain(0.5); //!!! arbitrary at this point
140 spectrogram->setMinFrequency(15);
139 spectrogram->setGain(100); 141 spectrogram->setGain(100);
140 m_document->addLayerToView(m_pane, spectrogram); 142 m_document->addLayerToView(m_pane, spectrogram);
141 spectrogram->setLayerDormant(m_pane, true); 143 spectrogram->setLayerDormant(m_pane, true);
142 144
143 m_layers[Spectrogram] = spectrogram; 145 m_layers[Spectrogram] = spectrogram;
248 QString 250 QString
249 Analyser::reAnalyseSelection(Selection sel) 251 Analyser::reAnalyseSelection(Selection sel)
250 { 252 {
251 if (sel == m_reAnalysingSelection) return ""; 253 if (sel == m_reAnalysingSelection) return "";
252 254
253 foreach (Layer *layer, m_reAnalysisCandidates) { 255 clearReAnalysis();
254 cerr << "deleting previous candidate layer " << layer << endl; 256
255 m_pane->removeLayer(layer);
256 m_document->deleteLayer(layer); // also releases its model
257 }
258 m_reAnalysisCandidates.clear();
259 m_reAnalysingSelection = sel; 257 m_reAnalysingSelection = sel;
260 258
261 TransformFactory *tf = TransformFactory::getInstance(); 259 TransformFactory *tf = TransformFactory::getInstance();
262 260
263 QString plugname = "pYIN"; 261 QString plugname = "pYIN";
303 vector<Layer *> additional) 301 vector<Layer *> additional)
304 { 302 {
305 //!!! how do we know these came from the right selection? user 303 //!!! how do we know these came from the right selection? user
306 //!!! might have made another one since this request was issued 304 //!!! might have made another one since this request was issued
307 305
306 vector<Layer *> all;
308 for (int i = 0; i < (int)primary.size(); ++i) { 307 for (int i = 0; i < (int)primary.size(); ++i) {
309 TimeValueLayer *t = qobject_cast<TimeValueLayer *>(primary[i]); 308 all.push_back(primary[i]);
309 }
310 for (int i = 0; i < (int)additional.size(); ++i) {
311 all.push_back(additional[i]);
312 }
313
314 for (int i = 0; i < (int)all.size(); ++i) {
315 TimeValueLayer *t = qobject_cast<TimeValueLayer *>(all[i]);
310 if (t) { 316 if (t) {
317 PlayParameters *params = t->getPlayParameters();
318 if (params) {
319 params->setPlayAudible(false);
320 }
321 t->setBaseColour
322 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Orange")));
311 m_document->addLayerToView(m_pane, t); 323 m_document->addLayerToView(m_pane, t);
312 m_reAnalysisCandidates.push_back(t); 324 m_reAnalysisCandidates.push_back(t);
313 } 325 }
314 } 326 }
315 327 }
316 for (int i = 0; i < (int)additional.size(); ++i) { 328
317 TimeValueLayer *t = qobject_cast<TimeValueLayer *>(additional[i]); 329 void
318 if (t) { 330 Analyser::switchPitchCandidate(Selection sel, bool up)
319 m_document->addLayerToView(m_pane, t); 331 {
320 m_reAnalysisCandidates.push_back(t); 332 if (m_reAnalysisCandidates.empty()) return;
333
334 if (up) {
335 m_currentCandidate = m_currentCandidate + 1;
336 if (m_currentCandidate >= m_reAnalysisCandidates.size()) {
337 m_currentCandidate = 0;
321 } 338 }
322 } 339 } else {
323 } 340 m_currentCandidate = m_currentCandidate - 1;
341 if (m_currentCandidate < 0) {
342 m_currentCandidate = m_reAnalysisCandidates.size() - 1;
343 }
344 }
345
346 Layer *pitchTrack = m_layers[PitchTrack];
347 if (!pitchTrack) return;
348
349 CommandHistory::getInstance()->startCompoundOperation
350 (tr("Switch Pitch Candidate"), true);
351
352 Clipboard clip;
353 pitchTrack->deleteSelection(sel);
354 m_reAnalysisCandidates[m_currentCandidate]->copy(m_pane, sel, clip);
355 pitchTrack->paste(m_pane, clip, 0, false);
356
357 CommandHistory::getInstance()->endCompoundOperation();
358
359 // raise the pitch track, then notes on top (if present)
360 m_paneStack->setCurrentLayer(m_pane, m_layers[PitchTrack]);
361 if (m_layers[Notes] && !m_layers[Notes]->isLayerDormant(m_pane)) {
362 m_paneStack->setCurrentLayer(m_pane, m_layers[Notes]);
363 }
364 }
365
366 void
367 Analyser::clearReAnalysis()
368 {
369 foreach (Layer *layer, m_reAnalysisCandidates) {
370 m_pane->removeLayer(layer);
371 m_document->deleteLayer(layer); // also releases its model
372 }
373 m_reAnalysisCandidates.clear();
374 m_reAnalysingSelection = Selection();
375 m_currentCandidate = -1;
376 }
324 377
325 void 378 void
326 Analyser::getEnclosingSelectionScope(size_t f, size_t &f0, size_t &f1) 379 Analyser::getEnclosingSelectionScope(size_t f, size_t &f0, size_t &f1)
327 { 380 {
328 FlexiNoteLayer *flexiNoteLayer = 381 FlexiNoteLayer *flexiNoteLayer =
394 Analyser::setVisible(Component c, bool v) 447 Analyser::setVisible(Component c, bool v)
395 { 448 {
396 if (m_layers[c]) { 449 if (m_layers[c]) {
397 m_layers[c]->setLayerDormant(m_pane, !v); 450 m_layers[c]->setLayerDormant(m_pane, !v);
398 451
399 if (v && (c == Notes)) { 452 if (v) {
400 m_paneStack->setCurrentLayer(m_pane, m_layers[c]); 453 if (c == Notes) {
454 m_paneStack->setCurrentLayer(m_pane, m_layers[c]);
455 } else if (c == PitchTrack) {
456 // raise the pitch track, then notes on top (if present)
457 m_paneStack->setCurrentLayer(m_pane, m_layers[c]);
458 if (m_layers[Notes] &&
459 !m_layers[Notes]->isLayerDormant(m_pane)) {
460 m_paneStack->setCurrentLayer(m_pane, m_layers[Notes]);
461 }
462 }
401 } 463 }
402 464
403 m_pane->layerParametersChanged(); 465 m_pane->layerParametersChanged();
404 saveState(c); 466 saveState(c);
405 } 467 }