annotate src/Analyser.h @ 174:e33f9d052503

Import pitch-track layer (currently csv-only)
author Chris Cannam
date Wed, 05 Feb 2014 19:23:55 +0000
parents c5e4eaeb9a27
children ea15fa75ae6f
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@6 20
Chris@128 21 #include <map>
Chris@163 22 #include <vector>
Chris@163 23
Chris@163 24 #include "framework/Document.h"
Chris@164 25 #include "base/Selection.h"
Chris@6 26
Chris@6 27 class WaveFileModel;
Chris@6 28 class Pane;
Chris@6 29 class PaneStack;
Chris@6 30 class Layer;
Chris@128 31 class TimeValueLayer;
Chris@128 32 class Layer;
Chris@6 33
Chris@163 34 class Analyser : public QObject,
Chris@163 35 public Document::LayerCreationHandler
Chris@6 36 {
Chris@6 37 Q_OBJECT
Chris@6 38
Chris@6 39 public:
Chris@6 40 Analyser();
Chris@6 41 virtual ~Analyser();
Chris@6 42
Chris@140 43 // Process new main model, add derived layers; return "" on success or error string on failure
Chris@140 44 QString newFileLoaded(Document *newDocument, WaveFileModel *model,
Chris@140 45 PaneStack *paneStack, Pane *pane);
gyorgyf@45 46
gyorgyf@45 47 void setIntelligentActions(bool);
Chris@6 48
Chris@128 49 enum Component {
Chris@128 50 Audio,
Chris@128 51 PitchTrack,
Chris@128 52 Notes,
Chris@145 53 Spectrogram,
Chris@128 54 };
Chris@128 55
Chris@128 56 bool isVisible(Component c) const;
Chris@128 57 void setVisible(Component c, bool v);
Chris@144 58 void toggleVisible(Component c) { setVisible(c, !isVisible(c)); }
Chris@128 59
Chris@128 60 bool isAudible(Component c) const;
Chris@128 61 void setAudible(Component c, bool v);
Chris@144 62 void toggleAudible(Component c) { setAudible(c, !isAudible(c)); }
Chris@128 63
Chris@128 64 void cycleStatus(Component c) {
Chris@128 65 if (isVisible(c)) {
Chris@128 66 if (isAudible(c)) {
Chris@128 67 setVisible(c, false);
Chris@128 68 setAudible(c, false);
Chris@128 69 } else {
Chris@128 70 setAudible(c, true);
Chris@128 71 }
Chris@128 72 } else {
Chris@128 73 setVisible(c, true);
Chris@128 74 setAudible(c, false);
Chris@128 75 }
Chris@128 76 }
Chris@128 77
Chris@158 78 float getGain(Component c) const;
Chris@158 79 void setGain(Component c, float gain);
Chris@158 80
Chris@158 81 float getPan(Component c) const;
Chris@158 82 void setPan(Component c, float pan);
Chris@158 83
Chris@139 84 void getEnclosingSelectionScope(size_t f, size_t &f0, size_t &f1);
Chris@139 85
Chris@164 86 /**
Chris@165 87 * Analyse the selection and schedule asynchronous adds of
Chris@165 88 * candidate layers for the region it contains. Returns "" on
Chris@165 89 * success or a user-readable error string on failure.
Chris@164 90 */
Chris@164 91 QString reAnalyseSelection(Selection sel);
Chris@164 92
Chris@167 93 /**
Chris@167 94 * If a re-analysis has been activated, switch the selected area
Chris@167 95 * of the main pitch track to a different candidate from the
Chris@167 96 * analysis results.
Chris@167 97 */
Chris@167 98 void switchPitchCandidate(Selection sel, bool up);
Chris@167 99
Chris@167 100 /**
Chris@168 101 * Remove the pitch estimates from the selected area of the main
Chris@168 102 * pitch track.
Chris@168 103 */
Chris@168 104 void clearPitches(Selection sel);
Chris@168 105
Chris@168 106 /**
Chris@168 107 * Move the main pitch track and any active analysis candidate
Chris@168 108 * tracks up or down an octave in the selected area.
Chris@168 109 */
Chris@168 110 void shiftOctave(Selection sel, bool up);
Chris@168 111
Chris@168 112 /**
Chris@167 113 * Remove any re-analysis layers.
Chris@167 114 */
Chris@167 115 void clearReAnalysis();
Chris@167 116
Chris@174 117 /**
Chris@174 118 * Import the pitch track from the given layer into our
Chris@174 119 * pitch-track layer.
Chris@174 120 */
Chris@174 121 void takePitchTrackFrom(Layer *layer);
Chris@174 122
Chris@174 123 Pane *getPane() {
Chris@174 124 return m_pane;
Chris@174 125 }
Chris@174 126
Chris@174 127 Layer *getLayer(Component type) {
Chris@174 128 return m_layers[type];
Chris@174 129 }
Chris@174 130
Chris@128 131 signals:
Chris@128 132 void layersChanged();
Chris@128 133
Chris@6 134 protected:
Chris@6 135 Document *m_document;
Chris@6 136 WaveFileModel *m_fileModel;
Chris@133 137 PaneStack *m_paneStack;
Chris@6 138 Pane *m_pane;
Chris@165 139
Chris@128 140 mutable std::map<Component, Layer *> m_layers;
Chris@132 141
Chris@165 142 Selection m_reAnalysingSelection;
Chris@165 143 std::vector<Layer *> m_reAnalysisCandidates;
Chris@167 144 int m_currentCandidate;
Chris@165 145
Chris@161 146 QString addVisualisations();
Chris@161 147 QString addWaveform();
Chris@161 148 QString addAnalyses();
Chris@161 149
Chris@163 150 // Document::LayerCreationHandler method
Chris@163 151 void layersCreated(std::vector<Layer *>, std::vector<Layer *>);
Chris@163 152
Chris@132 153 void saveState(Component c) const;
Chris@132 154 void loadState(Component c);
Chris@6 155 };
Chris@6 156
Chris@6 157 #endif