Chris@6: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@6: Chris@6: /* Chris@6: Tony Chris@6: An intonation analysis and annotation tool Chris@6: Centre for Digital Music, Queen Mary, University of London. Chris@6: This file copyright 2006-2012 Chris Cannam and QMUL. Chris@6: Chris@6: This program is free software; you can redistribute it and/or Chris@6: modify it under the terms of the GNU General Public License as Chris@6: published by the Free Software Foundation; either version 2 of the Chris@6: License, or (at your option) any later version. See the file Chris@6: COPYING included with this distribution for more information. Chris@6: */ Chris@6: Chris@6: #ifndef ANALYSER_H Chris@6: #define ANALYSER_H Chris@6: Chris@6: #include Chris@191: #include Chris@6: Chris@128: #include Chris@163: #include Chris@163: Chris@163: #include "framework/Document.h" Chris@164: #include "base/Selection.h" Chris@6: Chris@6: class WaveFileModel; Chris@6: class Pane; Chris@6: class PaneStack; Chris@6: class Layer; Chris@128: class TimeValueLayer; Chris@128: class Layer; Chris@6: Chris@163: class Analyser : public QObject, Chris@163: public Document::LayerCreationHandler Chris@6: { Chris@6: Q_OBJECT Chris@6: Chris@6: public: Chris@6: Analyser(); Chris@6: virtual ~Analyser(); Chris@6: Chris@140: // Process new main model, add derived layers; return "" on success or error string on failure Chris@140: QString newFileLoaded(Document *newDocument, WaveFileModel *model, Chris@140: PaneStack *paneStack, Pane *pane); gyorgyf@45: gyorgyf@45: void setIntelligentActions(bool); Chris@6: Chris@128: enum Component { Chris@128: Audio, Chris@128: PitchTrack, Chris@128: Notes, Chris@145: Spectrogram, Chris@128: }; Chris@128: Chris@128: bool isVisible(Component c) const; Chris@128: void setVisible(Component c, bool v); Chris@144: void toggleVisible(Component c) { setVisible(c, !isVisible(c)); } Chris@128: Chris@128: bool isAudible(Component c) const; Chris@128: void setAudible(Component c, bool v); Chris@144: void toggleAudible(Component c) { setAudible(c, !isAudible(c)); } Chris@128: Chris@128: void cycleStatus(Component c) { Chris@128: if (isVisible(c)) { Chris@128: if (isAudible(c)) { Chris@128: setVisible(c, false); Chris@128: setAudible(c, false); Chris@128: } else { Chris@128: setAudible(c, true); Chris@128: } Chris@128: } else { Chris@128: setVisible(c, true); Chris@128: setAudible(c, false); Chris@128: } Chris@128: } Chris@128: Chris@158: float getGain(Component c) const; Chris@158: void setGain(Component c, float gain); Chris@158: Chris@158: float getPan(Component c) const; Chris@158: void setPan(Component c, float pan); Chris@158: Chris@139: void getEnclosingSelectionScope(size_t f, size_t &f0, size_t &f1); Chris@139: Chris@164: /** Chris@165: * Analyse the selection and schedule asynchronous adds of Chris@165: * candidate layers for the region it contains. Returns "" on Chris@165: * success or a user-readable error string on failure. Chris@164: */ Chris@164: QString reAnalyseSelection(Selection sel); Chris@164: Chris@167: /** Chris@184: * Return true if the analysed pitch candidates are currently Chris@184: * visible (by default they are hidden after construction until Chris@184: * the user requests them). Note that the shown/hidden state is Chris@184: * independent of whether any pitch candidates actually exist -- Chris@184: * it's possible they might be shown but not have been created yet Chris@184: * because creation (through reAnalyseSelection) is asynchronous. Chris@184: */ Chris@184: bool arePitchCandidatesShown() const; Chris@184: Chris@184: /** Chris@184: * Show or hide the analysed pitch candidate layers. As in Chris@184: * arePitchCandidatesShown, this is independent of whether the Chris@184: * candidate layers actually exist. Call reAnalyseSelection to Chris@184: * schedule creation of those layers. Chris@184: */ Chris@184: void showPitchCandidates(bool shown); Chris@184: Chris@184: /** Chris@167: * If a re-analysis has been activated, switch the selected area Chris@167: * of the main pitch track to a different candidate from the Chris@167: * analysis results. Chris@167: */ Chris@167: void switchPitchCandidate(Selection sel, bool up); Chris@167: Chris@167: /** Chris@184: * Delete the pitch estimates from the selected area of the main Chris@168: * pitch track. Chris@168: */ Chris@184: void deletePitches(Selection sel); Chris@168: Chris@168: /** Chris@168: * Move the main pitch track and any active analysis candidate Chris@168: * tracks up or down an octave in the selected area. Chris@168: */ Chris@168: void shiftOctave(Selection sel, bool up); Chris@168: Chris@168: /** Chris@167: * Remove any re-analysis layers. Chris@167: */ Chris@167: void clearReAnalysis(); Chris@167: Chris@174: /** Chris@174: * Import the pitch track from the given layer into our Chris@174: * pitch-track layer. Chris@174: */ Chris@174: void takePitchTrackFrom(Layer *layer); Chris@174: Chris@174: Pane *getPane() { Chris@174: return m_pane; Chris@174: } Chris@174: Chris@174: Layer *getLayer(Component type) { Chris@174: return m_layers[type]; Chris@174: } Chris@174: Chris@128: signals: Chris@128: void layersChanged(); Chris@128: Chris@191: protected slots: Chris@191: void regionOutlined(QRect); Chris@191: Chris@6: protected: Chris@6: Document *m_document; Chris@6: WaveFileModel *m_fileModel; Chris@133: PaneStack *m_paneStack; Chris@6: Pane *m_pane; Chris@165: Chris@128: mutable std::map m_layers; Chris@132: Chris@165: Selection m_reAnalysingSelection; Chris@165: std::vector m_reAnalysisCandidates; Chris@167: int m_currentCandidate; Chris@184: bool m_candidatesVisible; Chris@165: Chris@161: QString addVisualisations(); Chris@161: QString addWaveform(); Chris@161: QString addAnalyses(); Chris@161: Chris@163: // Document::LayerCreationHandler method Chris@163: void layersCreated(std::vector, std::vector); Chris@163: Chris@132: void saveState(Component c) const; Chris@132: void loadState(Component c); Chris@6: }; Chris@6: Chris@6: #endif