annotate src/Analyser.h @ 402:a0eedd10dee3 cxx11-types

Merge from default branch
author Chris Cannam
date Mon, 23 Mar 2015 10:33:32 +0000
parents ffd1a89a68fa 6f7133733032
children cc33cdb114f6
rev   line source
Chris@6 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@6 2
Chris@6 3 /*
Chris@6 4 Tony
Chris@6 5 An intonation analysis and annotation tool
Chris@6 6 Centre for Digital Music, Queen Mary, University of London.
Chris@6 7 This file copyright 2006-2012 Chris Cannam and QMUL.
Chris@6 8
Chris@6 9 This program is free software; you can redistribute it and/or
Chris@6 10 modify it under the terms of the GNU General Public License as
Chris@6 11 published by the Free Software Foundation; either version 2 of the
Chris@6 12 License, or (at your option) any later version. See the file
Chris@6 13 COPYING included with this distribution for more information.
Chris@6 14 */
Chris@6 15
Chris@6 16 #ifndef ANALYSER_H
Chris@6 17 #define ANALYSER_H
Chris@6 18
Chris@6 19 #include <QObject>
Chris@191 20 #include <QRect>
Chris@341 21 #include <QMutex>
Chris@6 22
Chris@128 23 #include <map>
Chris@163 24 #include <vector>
Chris@163 25
Chris@163 26 #include "framework/Document.h"
Chris@164 27 #include "base/Selection.h"
Chris@194 28 #include "base/Clipboard.h"
Chris@6 29
Chris@6 30 class WaveFileModel;
Chris@6 31 class Pane;
Chris@6 32 class PaneStack;
Chris@6 33 class Layer;
Chris@128 34 class TimeValueLayer;
Chris@128 35 class Layer;
Chris@6 36
Chris@163 37 class Analyser : public QObject,
Chris@163 38 public Document::LayerCreationHandler
Chris@6 39 {
Chris@6 40 Q_OBJECT
Chris@6 41
Chris@6 42 public:
Chris@6 43 Analyser();
Chris@6 44 virtual ~Analyser();
Chris@6 45
Chris@140 46 // Process new main model, add derived layers; return "" on success or error string on failure
Chris@140 47 QString newFileLoaded(Document *newDocument, WaveFileModel *model,
Chris@140 48 PaneStack *paneStack, Pane *pane);
Chris@226 49
Chris@325 50 // Remove any derived layers, process the main model, add derived layers; return "" on success or error string on failure
Chris@325 51 QString analyseExistingFile();
Chris@325 52
Chris@226 53 // Discard any layers etc associated with the current document
Chris@226 54 void fileClosed();
gyorgyf@45 55
gyorgyf@45 56 void setIntelligentActions(bool);
Chris@6 57
Chris@399 58 bool getDisplayFrequencyExtents(double &min, double &max);
Chris@399 59 bool setDisplayFrequencyExtents(double min, double max);
Chris@227 60
Chris@314 61 // Return completion %age for initial analysis -- 100 means it's done
Chris@314 62 int getInitialAnalysisCompletion();
Chris@314 63
Chris@128 64 enum Component {
Chris@242 65 Audio = 0,
Chris@242 66 PitchTrack = 1,
Chris@242 67 Notes = 2,
Chris@242 68 Spectrogram = 3,
Chris@128 69 };
Chris@128 70
Chris@128 71 bool isVisible(Component c) const;
Chris@128 72 void setVisible(Component c, bool v);
Chris@144 73 void toggleVisible(Component c) { setVisible(c, !isVisible(c)); }
Chris@128 74
Chris@128 75 bool isAudible(Component c) const;
Chris@128 76 void setAudible(Component c, bool v);
Chris@144 77 void toggleAudible(Component c) { setAudible(c, !isAudible(c)); }
Chris@128 78
Chris@128 79 void cycleStatus(Component c) {
Chris@128 80 if (isVisible(c)) {
Chris@128 81 if (isAudible(c)) {
Chris@128 82 setVisible(c, false);
Chris@128 83 setAudible(c, false);
Chris@128 84 } else {
Chris@128 85 setAudible(c, true);
Chris@128 86 }
Chris@128 87 } else {
Chris@128 88 setVisible(c, true);
Chris@128 89 setAudible(c, false);
Chris@128 90 }
Chris@128 91 }
Chris@128 92
Chris@260 93 WaveFileModel *getMainModel() const {
Chris@260 94 return m_fileModel;
Chris@260 95 }
Chris@260 96
Chris@158 97 float getGain(Component c) const;
Chris@158 98 void setGain(Component c, float gain);
Chris@158 99
Chris@158 100 float getPan(Component c) const;
Chris@158 101 void setPan(Component c, float pan);
Chris@158 102
Chris@399 103 void getEnclosingSelectionScope(sv_frame_t f, sv_frame_t &f0, sv_frame_t &f1);
Chris@139 104
Chris@192 105 struct FrequencyRange {
Chris@192 106 FrequencyRange() : min(0), max(0) { }
Chris@399 107 FrequencyRange(double min_, double max_) : min(min_), max(max_) { }
Chris@192 108 bool isConstrained() const { return min != max; }
Chris@399 109 double min;
Chris@399 110 double max;
Chris@396 111 bool operator==(const FrequencyRange &r) {
Chris@396 112 return min == r.min && max == r.max;
Chris@396 113 }
Chris@192 114 };
Chris@192 115
Chris@164 116 /**
Chris@165 117 * Analyse the selection and schedule asynchronous adds of
Chris@165 118 * candidate layers for the region it contains. Returns "" on
Chris@192 119 * success or a user-readable error string on failure. If the
Chris@192 120 * frequency range isConstrained(), analysis will be constrained
Chris@192 121 * to that range.
Chris@164 122 */
Chris@192 123 QString reAnalyseSelection(Selection sel, FrequencyRange range);
Chris@164 124
Chris@167 125 /**
Chris@184 126 * Return true if the analysed pitch candidates are currently
Chris@199 127 * visible (they are hidden from the call to reAnalyseSelection
Chris@199 128 * until they are requested through showPitchCandidates()). Note
Chris@199 129 * that this may return true even when no pitch candidate layers
Chris@199 130 * actually exist yet, because they are constructed
Chris@199 131 * asynchronously. If that is the case, then the layers will
Chris@199 132 * appear when they are created (otherwise they will remain hidden
Chris@199 133 * after creation).
Chris@184 134 */
Chris@184 135 bool arePitchCandidatesShown() const;
Chris@184 136
Chris@184 137 /**
Chris@199 138 * Show or hide the analysed pitch candidate layers. This is reset
Chris@199 139 * (to "hide") with each new call to reAnalyseSelection. Because
Chris@199 140 * the layers are created asynchronously, setting this to true
Chris@199 141 * does not guarantee that they appear immediately, only that they
Chris@199 142 * will appear once they have been created.
Chris@184 143 */
Chris@184 144 void showPitchCandidates(bool shown);
Chris@184 145
Chris@184 146 /**
Chris@167 147 * If a re-analysis has been activated, switch the selected area
Chris@167 148 * of the main pitch track to a different candidate from the
Chris@167 149 * analysis results.
Chris@167 150 */
Chris@167 151 void switchPitchCandidate(Selection sel, bool up);
Chris@167 152
Chris@167 153 /**
Chris@199 154 * Return true if it is possible to switch up to another pitch
Chris@199 155 * candidate. This may mean that the currently selected pitch
Chris@199 156 * candidate is not the highest, or it may mean that no alternate
Chris@199 157 * pitch candidate has been selected at all yet (but some are
Chris@199 158 * available).
Chris@199 159 */
Chris@199 160 bool haveHigherPitchCandidate() const;
Chris@199 161
Chris@199 162 /**
Chris@199 163 * Return true if it is possible to switch down to another pitch
Chris@199 164 * candidate. This may mean that the currently selected pitch
Chris@199 165 * candidate is not the lowest, or it may mean that no alternate
Chris@199 166 * pitch candidate has been selected at all yet (but some are
Chris@199 167 * available).
Chris@199 168 */
Chris@199 169 bool haveLowerPitchCandidate() const;
Chris@199 170
Chris@199 171 /**
Chris@184 172 * Delete the pitch estimates from the selected area of the main
Chris@168 173 * pitch track.
Chris@168 174 */
Chris@184 175 void deletePitches(Selection sel);
Chris@168 176
Chris@168 177 /**
Chris@168 178 * Move the main pitch track and any active analysis candidate
Chris@168 179 * tracks up or down an octave in the selected area.
Chris@168 180 */
Chris@168 181 void shiftOctave(Selection sel, bool up);
Chris@168 182
Chris@168 183 /**
Chris@199 184 * Remove any re-analysis layers and also reset the pitch track in
Chris@194 185 * the given selection to its state prior to the last re-analysis,
Chris@199 186 * abandoning any changes made since then. No re-analysis layers
Chris@199 187 * will be available until after the next call to
Chris@199 188 * reAnalyseSelection.
Chris@167 189 */
Chris@199 190 void abandonReAnalysis(Selection sel);
Chris@167 191
Chris@174 192 /**
Chris@269 193 * Remove any re-analysis layers, without any expectation of
Chris@269 194 * adding them later, unlike showPitchCandidates(false), and
Chris@269 195 * without changing the current pitch track, unlike
Chris@269 196 * abandonReAnalysis().
Chris@269 197 */
Chris@269 198 void clearReAnalysis();
Chris@269 199
Chris@269 200 /**
Chris@174 201 * Import the pitch track from the given layer into our
Chris@174 202 * pitch-track layer.
Chris@174 203 */
Chris@174 204 void takePitchTrackFrom(Layer *layer);
Chris@174 205
Chris@174 206 Pane *getPane() {
Chris@174 207 return m_pane;
Chris@174 208 }
Chris@174 209
Chris@174 210 Layer *getLayer(Component type) {
Chris@174 211 return m_layers[type];
Chris@174 212 }
Chris@174 213
Chris@128 214 signals:
Chris@128 215 void layersChanged();
Chris@314 216 void initialAnalysisCompleted();
Chris@128 217
Chris@242 218 protected slots:
Chris@242 219 void layerAboutToBeDeleted(Layer *);
Chris@314 220 void layerCompletionChanged();
Chris@396 221 void reAnalyseRegion(int, int, float, float);
Chris@398 222 void materialiseReAnalysis();
Chris@242 223
Chris@6 224 protected:
Chris@6 225 Document *m_document;
Chris@6 226 WaveFileModel *m_fileModel;
Chris@133 227 PaneStack *m_paneStack;
Chris@6 228 Pane *m_pane;
Chris@165 229
Chris@128 230 mutable std::map<Component, Layer *> m_layers;
Chris@132 231
Chris@194 232 Clipboard m_preAnalysis;
Chris@165 233 Selection m_reAnalysingSelection;
Chris@396 234 FrequencyRange m_reAnalysingRange;
Chris@165 235 std::vector<Layer *> m_reAnalysisCandidates;
Chris@167 236 int m_currentCandidate;
Chris@184 237 bool m_candidatesVisible;
Chris@341 238 Document::LayerCreationAsyncHandle m_currentAsyncHandle;
Chris@341 239 QMutex m_asyncMutex;
Chris@165 240
Chris@326 241 QString doAllAnalyses(bool withPitchTrack);
Chris@325 242
Chris@161 243 QString addVisualisations();
Chris@161 244 QString addWaveform();
Chris@161 245 QString addAnalyses();
Chris@161 246
Chris@199 247 void discardPitchCandidates();
Chris@260 248
Chris@260 249 void stackLayers();
Chris@199 250
Chris@163 251 // Document::LayerCreationHandler method
Chris@341 252 void layersCreated(Document::LayerCreationAsyncHandle,
Chris@341 253 std::vector<Layer *>, std::vector<Layer *>);
Chris@163 254
Chris@132 255 void saveState(Component c) const;
Chris@132 256 void loadState(Component c);
Chris@6 257 };
Chris@6 258
Chris@6 259 #endif