annotate src/Analyser.h @ 326:b176ea403ee8

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