annotate src/Analyser.h @ 192:431a95c9d14d

Calculate frequency constraint for region outlining (does not actually do the analysis correctly yet)
author Chris Cannam
date Wed, 05 Mar 2014 09:36:13 +0000
parents 800e65412473
children 34797795a76c
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@6 27
Chris@6 28 class WaveFileModel;
Chris@6 29 class Pane;
Chris@6 30 class PaneStack;
Chris@6 31 class Layer;
Chris@128 32 class TimeValueLayer;
Chris@128 33 class Layer;
Chris@6 34
Chris@163 35 class Analyser : public QObject,
Chris@163 36 public Document::LayerCreationHandler
Chris@6 37 {
Chris@6 38 Q_OBJECT
Chris@6 39
Chris@6 40 public:
Chris@6 41 Analyser();
Chris@6 42 virtual ~Analyser();
Chris@6 43
Chris@140 44 // Process new main model, add derived layers; return "" on success or error string on failure
Chris@140 45 QString newFileLoaded(Document *newDocument, WaveFileModel *model,
Chris@140 46 PaneStack *paneStack, Pane *pane);
gyorgyf@45 47
gyorgyf@45 48 void setIntelligentActions(bool);
Chris@6 49
Chris@128 50 enum Component {
Chris@128 51 Audio,
Chris@128 52 PitchTrack,
Chris@128 53 Notes,
Chris@145 54 Spectrogram,
Chris@128 55 };
Chris@128 56
Chris@128 57 bool isVisible(Component c) const;
Chris@128 58 void setVisible(Component c, bool v);
Chris@144 59 void toggleVisible(Component c) { setVisible(c, !isVisible(c)); }
Chris@128 60
Chris@128 61 bool isAudible(Component c) const;
Chris@128 62 void setAudible(Component c, bool v);
Chris@144 63 void toggleAudible(Component c) { setAudible(c, !isAudible(c)); }
Chris@128 64
Chris@128 65 void cycleStatus(Component c) {
Chris@128 66 if (isVisible(c)) {
Chris@128 67 if (isAudible(c)) {
Chris@128 68 setVisible(c, false);
Chris@128 69 setAudible(c, false);
Chris@128 70 } else {
Chris@128 71 setAudible(c, true);
Chris@128 72 }
Chris@128 73 } else {
Chris@128 74 setVisible(c, true);
Chris@128 75 setAudible(c, false);
Chris@128 76 }
Chris@128 77 }
Chris@128 78
Chris@158 79 float getGain(Component c) const;
Chris@158 80 void setGain(Component c, float gain);
Chris@158 81
Chris@158 82 float getPan(Component c) const;
Chris@158 83 void setPan(Component c, float pan);
Chris@158 84
Chris@139 85 void getEnclosingSelectionScope(size_t f, size_t &f0, size_t &f1);
Chris@139 86
Chris@192 87 struct FrequencyRange {
Chris@192 88 FrequencyRange() : min(0), max(0) { }
Chris@192 89 FrequencyRange(float min_, float max_) : min(min_), max(max_) { }
Chris@192 90 bool isConstrained() const { return min != max; }
Chris@192 91 float min;
Chris@192 92 float max;
Chris@192 93 };
Chris@192 94
Chris@164 95 /**
Chris@165 96 * Analyse the selection and schedule asynchronous adds of
Chris@165 97 * candidate layers for the region it contains. Returns "" on
Chris@192 98 * success or a user-readable error string on failure. If the
Chris@192 99 * frequency range isConstrained(), analysis will be constrained
Chris@192 100 * to that range.
Chris@164 101 */
Chris@192 102 QString reAnalyseSelection(Selection sel, FrequencyRange range);
Chris@164 103
Chris@167 104 /**
Chris@184 105 * Return true if the analysed pitch candidates are currently
Chris@184 106 * visible (by default they are hidden after construction until
Chris@184 107 * the user requests them). Note that the shown/hidden state is
Chris@184 108 * independent of whether any pitch candidates actually exist --
Chris@184 109 * it's possible they might be shown but not have been created yet
Chris@184 110 * because creation (through reAnalyseSelection) is asynchronous.
Chris@184 111 */
Chris@184 112 bool arePitchCandidatesShown() const;
Chris@184 113
Chris@184 114 /**
Chris@184 115 * Show or hide the analysed pitch candidate layers. As in
Chris@184 116 * arePitchCandidatesShown, this is independent of whether the
Chris@184 117 * candidate layers actually exist. Call reAnalyseSelection to
Chris@184 118 * schedule creation of those layers.
Chris@184 119 */
Chris@184 120 void showPitchCandidates(bool shown);
Chris@184 121
Chris@184 122 /**
Chris@167 123 * If a re-analysis has been activated, switch the selected area
Chris@167 124 * of the main pitch track to a different candidate from the
Chris@167 125 * analysis results.
Chris@167 126 */
Chris@167 127 void switchPitchCandidate(Selection sel, bool up);
Chris@167 128
Chris@167 129 /**
Chris@184 130 * Delete the pitch estimates from the selected area of the main
Chris@168 131 * pitch track.
Chris@168 132 */
Chris@184 133 void deletePitches(Selection sel);
Chris@168 134
Chris@168 135 /**
Chris@168 136 * Move the main pitch track and any active analysis candidate
Chris@168 137 * tracks up or down an octave in the selected area.
Chris@168 138 */
Chris@168 139 void shiftOctave(Selection sel, bool up);
Chris@168 140
Chris@168 141 /**
Chris@167 142 * Remove any re-analysis layers.
Chris@167 143 */
Chris@167 144 void clearReAnalysis();
Chris@167 145
Chris@174 146 /**
Chris@174 147 * Import the pitch track from the given layer into our
Chris@174 148 * pitch-track layer.
Chris@174 149 */
Chris@174 150 void takePitchTrackFrom(Layer *layer);
Chris@174 151
Chris@174 152 Pane *getPane() {
Chris@174 153 return m_pane;
Chris@174 154 }
Chris@174 155
Chris@174 156 Layer *getLayer(Component type) {
Chris@174 157 return m_layers[type];
Chris@174 158 }
Chris@174 159
Chris@128 160 signals:
Chris@128 161 void layersChanged();
Chris@128 162
Chris@6 163 protected:
Chris@6 164 Document *m_document;
Chris@6 165 WaveFileModel *m_fileModel;
Chris@133 166 PaneStack *m_paneStack;
Chris@6 167 Pane *m_pane;
Chris@165 168
Chris@128 169 mutable std::map<Component, Layer *> m_layers;
Chris@132 170
Chris@165 171 Selection m_reAnalysingSelection;
Chris@165 172 std::vector<Layer *> m_reAnalysisCandidates;
Chris@167 173 int m_currentCandidate;
Chris@184 174 bool m_candidatesVisible;
Chris@165 175
Chris@161 176 QString addVisualisations();
Chris@161 177 QString addWaveform();
Chris@161 178 QString addAnalyses();
Chris@161 179
Chris@163 180 // Document::LayerCreationHandler method
Chris@163 181 void layersCreated(std::vector<Layer *>, std::vector<Layer *>);
Chris@163 182
Chris@132 183 void saveState(Component c) const;
Chris@132 184 void loadState(Component c);
Chris@6 185 };
Chris@6 186
Chris@6 187 #endif