annotate src/Analyser.h @ 194:34797795a76c

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