comparison src/Analyser.cpp @ 199:0ba33d6c0a71

Properly rationalise the show/hide/add/remove layer logic for pitch candidates: ctrl+return maps through to a show layer command (but the layers remain in the view) while the add/remove layer flow is used for layer creation after selection and for abandoning an edit or discarding a selection.
author Chris Cannam
date Wed, 05 Mar 2014 13:20:26 +0000
parents bb391844e2aa
children 13fc8473002c
comparison
equal deleted inserted replaced
198:bb391844e2aa 199:0ba33d6c0a71
30 #include "layer/ColourDatabase.h" 30 #include "layer/ColourDatabase.h"
31 #include "layer/ColourMapper.h" 31 #include "layer/ColourMapper.h"
32 #include "layer/LayerFactory.h" 32 #include "layer/LayerFactory.h"
33 #include "layer/SpectrogramLayer.h" 33 #include "layer/SpectrogramLayer.h"
34 #include "layer/Colour3DPlotLayer.h" 34 #include "layer/Colour3DPlotLayer.h"
35 #include "layer/ShowLayerCommand.h"
35 36
36 #include <QSettings> 37 #include <QSettings>
37 38
38 using std::vector; 39 using std::vector;
39 40
253 QString 254 QString
254 Analyser::reAnalyseSelection(Selection sel, FrequencyRange range) 255 Analyser::reAnalyseSelection(Selection sel, FrequencyRange range)
255 { 256 {
256 if (sel == m_reAnalysingSelection) return ""; 257 if (sel == m_reAnalysingSelection) return "";
257 258
258 showPitchCandidates(false); 259 discardPitchCandidates();
259 m_reAnalysisCandidates.clear(); 260
260 m_currentCandidate = -1;
261 m_reAnalysingSelection = sel; 261 m_reAnalysingSelection = sel;
262 262
263 m_preAnalysis = Clipboard(); 263 m_preAnalysis = Clipboard();
264 Layer *myLayer = m_layers[PitchTrack]; 264 Layer *myLayer = m_layers[PitchTrack];
265 if (myLayer) { 265 if (myLayer) {
327 { 327 {
328 if (m_candidatesVisible == shown) return; 328 if (m_candidatesVisible == shown) return;
329 329
330 foreach (Layer *layer, m_reAnalysisCandidates) { 330 foreach (Layer *layer, m_reAnalysisCandidates) {
331 if (shown) { 331 if (shown) {
332 m_document->addLayerToView(m_pane, layer); 332 CommandHistory::getInstance()->addCommand
333 (new ShowLayerCommand(m_pane, layer, true,
334 tr("Show Pitch Candidates")));
333 } else { 335 } else {
334 m_document->removeLayerFromView(m_pane, layer); 336 CommandHistory::getInstance()->addCommand
337 (new ShowLayerCommand(m_pane, layer, false,
338 tr("Hide Pitch Candidates")));
335 } 339 }
336 } 340 }
337 341
338 m_candidatesVisible = shown; 342 m_candidatesVisible = shown;
339 } 343 }
342 Analyser::layersCreated(vector<Layer *> primary, 346 Analyser::layersCreated(vector<Layer *> primary,
343 vector<Layer *> additional) 347 vector<Layer *> additional)
344 { 348 {
345 //!!! how do we know these came from the right selection? user 349 //!!! how do we know these came from the right selection? user
346 //!!! might have made another one since this request was issued 350 //!!! might have made another one since this request was issued
351
352 CommandHistory::getInstance()->startCompoundOperation
353 (tr("Re-Analyse Selection"), true);
347 354
348 vector<Layer *> all; 355 vector<Layer *> all;
349 for (int i = 0; i < (int)primary.size(); ++i) { 356 for (int i = 0; i < (int)primary.size(); ++i) {
350 all.push_back(primary[i]); 357 all.push_back(primary[i]);
351 } 358 }
360 if (params) { 367 if (params) {
361 params->setPlayAudible(false); 368 params->setPlayAudible(false);
362 } 369 }
363 t->setBaseColour 370 t->setBaseColour
364 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Orange"))); 371 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Orange")));
365 if (m_candidatesVisible) { 372 m_document->addLayerToView(m_pane, t);
366 m_document->addLayerToView(m_pane, t);
367 }
368 m_reAnalysisCandidates.push_back(t); 373 m_reAnalysisCandidates.push_back(t);
369 } 374 }
370 } 375 }
376
377 if (!all.empty()) {
378 bool show = m_candidatesVisible;
379 m_candidatesVisible = !show; // to ensure the following takes effect
380 showPitchCandidates(show);
381 }
382
383 CommandHistory::getInstance()->endCompoundOperation();
371 384
372 emit layersChanged(); 385 emit layersChanged();
373 } 386 }
374 387
375 bool 388 bool
457 470
458 pitchTrack->deleteSelection(sel); 471 pitchTrack->deleteSelection(sel);
459 } 472 }
460 473
461 void 474 void
462 Analyser::clearReAnalysis(Selection sel) 475 Analyser::abandonReAnalysis(Selection sel)
463 { 476 {
464 showPitchCandidates(false); 477 discardPitchCandidates();
465
466 m_reAnalysisCandidates.clear();
467 m_reAnalysingSelection = Selection();
468 m_currentCandidate = -1;
469 478
470 Layer *myLayer = m_layers[PitchTrack]; 479 Layer *myLayer = m_layers[PitchTrack];
471 if (!myLayer) return; 480 if (!myLayer) return;
472 myLayer->deleteSelection(sel); 481 myLayer->deleteSelection(sel);
473 myLayer->paste(m_pane, m_preAnalysis, 0, false); 482 myLayer->paste(m_pane, m_preAnalysis, 0, false);
474 } 483 }
484
485 void
486 Analyser::discardPitchCandidates()
487 {
488 foreach (Layer *layer, m_reAnalysisCandidates) {
489 // This will cause the layer to be deleted later (ownership is
490 // transferred to the remove command)
491 m_document->removeLayerFromView(m_pane, layer);
492 }
493
494 m_reAnalysisCandidates.clear();
495 m_currentCandidate = -1;
496 m_reAnalysingSelection = Selection();
497 m_candidatesVisible = false;
498 }
475 499
476 void 500 void
477 Analyser::takePitchTrackFrom(Layer *otherLayer) 501 Analyser::takePitchTrackFrom(Layer *otherLayer)
478 { 502 {
479 Layer *myLayer = m_layers[PitchTrack]; 503 Layer *myLayer = m_layers[PitchTrack];