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@226
|
49 // Discard any layers etc associated with the current document
|
Chris@226
|
50 void fileClosed();
|
gyorgyf@45
|
51
|
gyorgyf@45
|
52 void setIntelligentActions(bool);
|
Chris@6
|
53
|
Chris@227
|
54 bool getDisplayFrequencyExtents(float &min, float &max);
|
Chris@227
|
55 bool setDisplayFrequencyExtents(float min, float max);
|
Chris@227
|
56
|
Chris@128
|
57 enum Component {
|
Chris@128
|
58 Audio,
|
Chris@128
|
59 PitchTrack,
|
Chris@128
|
60 Notes,
|
Chris@145
|
61 Spectrogram,
|
Chris@128
|
62 };
|
Chris@128
|
63
|
Chris@128
|
64 bool isVisible(Component c) const;
|
Chris@128
|
65 void setVisible(Component c, bool v);
|
Chris@144
|
66 void toggleVisible(Component c) { setVisible(c, !isVisible(c)); }
|
Chris@128
|
67
|
Chris@128
|
68 bool isAudible(Component c) const;
|
Chris@128
|
69 void setAudible(Component c, bool v);
|
Chris@144
|
70 void toggleAudible(Component c) { setAudible(c, !isAudible(c)); }
|
Chris@128
|
71
|
Chris@128
|
72 void cycleStatus(Component c) {
|
Chris@128
|
73 if (isVisible(c)) {
|
Chris@128
|
74 if (isAudible(c)) {
|
Chris@128
|
75 setVisible(c, false);
|
Chris@128
|
76 setAudible(c, false);
|
Chris@128
|
77 } else {
|
Chris@128
|
78 setAudible(c, true);
|
Chris@128
|
79 }
|
Chris@128
|
80 } else {
|
Chris@128
|
81 setVisible(c, true);
|
Chris@128
|
82 setAudible(c, false);
|
Chris@128
|
83 }
|
Chris@128
|
84 }
|
Chris@128
|
85
|
Chris@158
|
86 float getGain(Component c) const;
|
Chris@158
|
87 void setGain(Component c, float gain);
|
Chris@158
|
88
|
Chris@158
|
89 float getPan(Component c) const;
|
Chris@158
|
90 void setPan(Component c, float pan);
|
Chris@158
|
91
|
Chris@139
|
92 void getEnclosingSelectionScope(size_t f, size_t &f0, size_t &f1);
|
Chris@139
|
93
|
Chris@192
|
94 struct FrequencyRange {
|
Chris@192
|
95 FrequencyRange() : min(0), max(0) { }
|
Chris@192
|
96 FrequencyRange(float min_, float max_) : min(min_), max(max_) { }
|
Chris@192
|
97 bool isConstrained() const { return min != max; }
|
Chris@192
|
98 float min;
|
Chris@192
|
99 float max;
|
Chris@192
|
100 };
|
Chris@192
|
101
|
Chris@164
|
102 /**
|
Chris@165
|
103 * Analyse the selection and schedule asynchronous adds of
|
Chris@165
|
104 * candidate layers for the region it contains. Returns "" on
|
Chris@192
|
105 * success or a user-readable error string on failure. If the
|
Chris@192
|
106 * frequency range isConstrained(), analysis will be constrained
|
Chris@192
|
107 * to that range.
|
Chris@164
|
108 */
|
Chris@192
|
109 QString reAnalyseSelection(Selection sel, FrequencyRange range);
|
Chris@164
|
110
|
Chris@167
|
111 /**
|
Chris@184
|
112 * Return true if the analysed pitch candidates are currently
|
Chris@199
|
113 * visible (they are hidden from the call to reAnalyseSelection
|
Chris@199
|
114 * until they are requested through showPitchCandidates()). Note
|
Chris@199
|
115 * that this may return true even when no pitch candidate layers
|
Chris@199
|
116 * actually exist yet, because they are constructed
|
Chris@199
|
117 * asynchronously. If that is the case, then the layers will
|
Chris@199
|
118 * appear when they are created (otherwise they will remain hidden
|
Chris@199
|
119 * after creation).
|
Chris@184
|
120 */
|
Chris@184
|
121 bool arePitchCandidatesShown() const;
|
Chris@184
|
122
|
Chris@184
|
123 /**
|
Chris@199
|
124 * Show or hide the analysed pitch candidate layers. This is reset
|
Chris@199
|
125 * (to "hide") with each new call to reAnalyseSelection. Because
|
Chris@199
|
126 * the layers are created asynchronously, setting this to true
|
Chris@199
|
127 * does not guarantee that they appear immediately, only that they
|
Chris@199
|
128 * will appear once they have been created.
|
Chris@184
|
129 */
|
Chris@184
|
130 void showPitchCandidates(bool shown);
|
Chris@184
|
131
|
Chris@184
|
132 /**
|
Chris@167
|
133 * If a re-analysis has been activated, switch the selected area
|
Chris@167
|
134 * of the main pitch track to a different candidate from the
|
Chris@167
|
135 * analysis results.
|
Chris@167
|
136 */
|
Chris@167
|
137 void switchPitchCandidate(Selection sel, bool up);
|
Chris@167
|
138
|
Chris@167
|
139 /**
|
Chris@199
|
140 * Return true if it is possible to switch up to another pitch
|
Chris@199
|
141 * candidate. This may mean that the currently selected pitch
|
Chris@199
|
142 * candidate is not the highest, or it may mean that no alternate
|
Chris@199
|
143 * pitch candidate has been selected at all yet (but some are
|
Chris@199
|
144 * available).
|
Chris@199
|
145 */
|
Chris@199
|
146 bool haveHigherPitchCandidate() const;
|
Chris@199
|
147
|
Chris@199
|
148 /**
|
Chris@199
|
149 * Return true if it is possible to switch down to another pitch
|
Chris@199
|
150 * candidate. This may mean that the currently selected pitch
|
Chris@199
|
151 * candidate is not the lowest, or it may mean that no alternate
|
Chris@199
|
152 * pitch candidate has been selected at all yet (but some are
|
Chris@199
|
153 * available).
|
Chris@199
|
154 */
|
Chris@199
|
155 bool haveLowerPitchCandidate() const;
|
Chris@199
|
156
|
Chris@199
|
157 /**
|
Chris@184
|
158 * Delete the pitch estimates from the selected area of the main
|
Chris@168
|
159 * pitch track.
|
Chris@168
|
160 */
|
Chris@184
|
161 void deletePitches(Selection sel);
|
Chris@168
|
162
|
Chris@168
|
163 /**
|
Chris@168
|
164 * Move the main pitch track and any active analysis candidate
|
Chris@168
|
165 * tracks up or down an octave in the selected area.
|
Chris@168
|
166 */
|
Chris@168
|
167 void shiftOctave(Selection sel, bool up);
|
Chris@168
|
168
|
Chris@168
|
169 /**
|
Chris@199
|
170 * Remove any re-analysis layers and also reset the pitch track in
|
Chris@194
|
171 * the given selection to its state prior to the last re-analysis,
|
Chris@199
|
172 * abandoning any changes made since then. No re-analysis layers
|
Chris@199
|
173 * will be available until after the next call to
|
Chris@199
|
174 * reAnalyseSelection.
|
Chris@167
|
175 */
|
Chris@199
|
176 void abandonReAnalysis(Selection sel);
|
Chris@167
|
177
|
Chris@174
|
178 /**
|
Chris@174
|
179 * Import the pitch track from the given layer into our
|
Chris@174
|
180 * pitch-track layer.
|
Chris@174
|
181 */
|
Chris@174
|
182 void takePitchTrackFrom(Layer *layer);
|
Chris@174
|
183
|
Chris@174
|
184 Pane *getPane() {
|
Chris@174
|
185 return m_pane;
|
Chris@174
|
186 }
|
Chris@174
|
187
|
Chris@174
|
188 Layer *getLayer(Component type) {
|
Chris@174
|
189 return m_layers[type];
|
Chris@174
|
190 }
|
Chris@174
|
191
|
Chris@128
|
192 signals:
|
Chris@128
|
193 void layersChanged();
|
Chris@128
|
194
|
Chris@6
|
195 protected:
|
Chris@6
|
196 Document *m_document;
|
Chris@6
|
197 WaveFileModel *m_fileModel;
|
Chris@133
|
198 PaneStack *m_paneStack;
|
Chris@6
|
199 Pane *m_pane;
|
Chris@165
|
200
|
Chris@128
|
201 mutable std::map<Component, Layer *> m_layers;
|
Chris@132
|
202
|
Chris@194
|
203 Clipboard m_preAnalysis;
|
Chris@165
|
204 Selection m_reAnalysingSelection;
|
Chris@165
|
205 std::vector<Layer *> m_reAnalysisCandidates;
|
Chris@167
|
206 int m_currentCandidate;
|
Chris@184
|
207 bool m_candidatesVisible;
|
Chris@165
|
208
|
Chris@161
|
209 QString addVisualisations();
|
Chris@161
|
210 QString addWaveform();
|
Chris@161
|
211 QString addAnalyses();
|
Chris@161
|
212
|
Chris@199
|
213 void discardPitchCandidates();
|
Chris@199
|
214
|
Chris@163
|
215 // Document::LayerCreationHandler method
|
Chris@163
|
216 void layersCreated(std::vector<Layer *>, std::vector<Layer *>);
|
Chris@163
|
217
|
Chris@132
|
218 void saveState(Component c) const;
|
Chris@132
|
219 void loadState(Component c);
|
Chris@6
|
220 };
|
Chris@6
|
221
|
Chris@6
|
222 #endif
|