Mercurial > hg > tony
comparison src/Analyser.cpp @ 341:6b57c58b88d2
Cancel async layer creation in Tony when selection is changed during it
author | Chris Cannam |
---|---|
date | Mon, 16 Jun 2014 09:28:12 +0100 |
parents | b176ea403ee8 |
children | f3a9e4abec1b ff00432761ce |
comparison
equal
deleted
inserted
replaced
340:1277a5dd11f6 | 341:6b57c58b88d2 |
---|---|
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 #include "layer/ShowLayerCommand.h" |
36 | 36 |
37 #include <QSettings> | 37 #include <QSettings> |
38 #include <QMutexLocker> | |
38 | 39 |
39 using std::vector; | 40 using std::vector; |
40 | 41 |
41 Analyser::Analyser() : | 42 Analyser::Analyser() : |
42 m_document(0), | 43 m_document(0), |
43 m_fileModel(0), | 44 m_fileModel(0), |
44 m_paneStack(0), | 45 m_paneStack(0), |
45 m_pane(0), | 46 m_pane(0), |
46 m_currentCandidate(-1), | 47 m_currentCandidate(-1), |
47 m_candidatesVisible(false) | 48 m_candidatesVisible(false), |
49 m_currentAsyncHandle(0) | |
48 { | 50 { |
49 QSettings settings; | 51 QSettings settings; |
50 settings.beginGroup("LayerDefaults"); | 52 settings.beginGroup("LayerDefaults"); |
51 settings.setValue | 53 settings.setValue |
52 ("timevalues", | 54 ("timevalues", |
412 } | 414 } |
413 | 415 |
414 QString | 416 QString |
415 Analyser::reAnalyseSelection(Selection sel, FrequencyRange range) | 417 Analyser::reAnalyseSelection(Selection sel, FrequencyRange range) |
416 { | 418 { |
419 QMutexLocker locker(&m_asyncMutex); | |
420 | |
417 if (sel == m_reAnalysingSelection || sel.isEmpty()) return ""; | 421 if (sel == m_reAnalysingSelection || sel.isEmpty()) return ""; |
422 | |
423 if (m_currentAsyncHandle) { | |
424 m_document->cancelAsyncLayerCreation(m_currentAsyncHandle); | |
425 } | |
418 | 426 |
419 if (!m_reAnalysisCandidates.empty()) { | 427 if (!m_reAnalysisCandidates.empty()) { |
420 CommandHistory::getInstance()->startCompoundOperation | 428 CommandHistory::getInstance()->startCompoundOperation |
421 (tr("Discard Previous Candidates"), true); | 429 (tr("Discard Previous Candidates"), true); |
422 discardPitchCandidates(); | 430 discardPitchCandidates(); |
489 | 497 |
490 t.setStartTime(start); | 498 t.setStartTime(start); |
491 t.setDuration(duration); | 499 t.setDuration(duration); |
492 | 500 |
493 transforms.push_back(t); | 501 transforms.push_back(t); |
494 | 502 |
495 m_document->createDerivedLayersAsync(transforms, m_fileModel, this); | 503 m_currentAsyncHandle = |
504 m_document->createDerivedLayersAsync(transforms, m_fileModel, this); | |
496 | 505 |
497 return ""; | 506 return ""; |
498 } | 507 } |
499 | 508 |
500 bool | 509 bool |
522 | 531 |
523 m_candidatesVisible = shown; | 532 m_candidatesVisible = shown; |
524 } | 533 } |
525 | 534 |
526 void | 535 void |
527 Analyser::layersCreated(vector<Layer *> primary, | 536 Analyser::layersCreated(Document::LayerCreationAsyncHandle handle, |
537 vector<Layer *> primary, | |
528 vector<Layer *> additional) | 538 vector<Layer *> additional) |
529 { | 539 { |
530 //!!! how do we know these came from the right selection? user | 540 QMutexLocker locker(&m_asyncMutex); |
531 //!!! might have made another one since this request was issued | 541 |
532 | 542 if (handle != m_currentAsyncHandle || |
533 if (m_reAnalysingSelection == Selection()) { | 543 m_reAnalysingSelection == Selection()) { |
534 // We don't want these (actually, as above, this should check | 544 // We don't want these! |
535 // that the selection is the same as the one requested -- but | |
536 // all we're doing here is checking that the selection exists | |
537 // at all, so hasn't been cleared or the document deleted or | |
538 // whatever) | |
539 for (int i = 0; i < (int)primary.size(); ++i) { | 545 for (int i = 0; i < (int)primary.size(); ++i) { |
540 m_document->deleteLayer(primary[i]); | 546 m_document->deleteLayer(primary[i]); |
541 } | 547 } |
542 for (int i = 0; i < (int)additional.size(); ++i) { | 548 for (int i = 0; i < (int)additional.size(); ++i) { |
543 m_document->deleteLayer(additional[i]); | 549 m_document->deleteLayer(additional[i]); |
544 } | 550 } |
545 return; | 551 return; |
546 } | 552 } |
553 m_currentAsyncHandle = 0; | |
547 | 554 |
548 CommandHistory::getInstance()->startCompoundOperation | 555 CommandHistory::getInstance()->startCompoundOperation |
549 (tr("Re-Analyse Selection"), true); | 556 (tr("Re-Analyse Selection"), true); |
550 | 557 |
551 m_reAnalysisCandidates.clear(); | 558 m_reAnalysisCandidates.clear(); |