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: #include "Analyser.h" Chris@6: Chris@6: #include "transform/TransformFactory.h" Chris@6: #include "transform/ModelTransformer.h" gyorgyf@14: #include "transform/FeatureExtractionModelTransformer.h" Chris@6: #include "framework/Document.h" Chris@6: #include "data/model/WaveFileModel.h" Chris@6: #include "view/Pane.h" Chris@6: #include "view/PaneStack.h" Chris@6: #include "layer/Layer.h" Chris@6: #include "layer/TimeValueLayer.h" matthiasm@13: #include "layer/NoteLayer.h" matthiasm@11: #include "layer/FlexiNoteLayer.h" Chris@6: #include "layer/ColourDatabase.h" gyorgyf@16: #include "layer/LayerFactory.h" Chris@6: Chris@83: #include Chris@83: Chris@6: Analyser::Analyser() : Chris@6: m_document(0), Chris@6: m_fileModel(0), Chris@54: m_pane(0), Chris@54: m_flexiNoteLayer(0) Chris@6: { Chris@83: QSettings settings; Chris@83: settings.beginGroup("LayerDefaults"); Chris@83: settings.setValue Chris@83: ("timevalues", Chris@83: QString("") Chris@83: .arg(int(TimeValueLayer::LogScale)) Chris@83: .arg(int(TimeValueLayer::PlotDiscreteCurves)) Chris@83: .arg(27.5f).arg(880.f)); // temporary values: better get the real extents of the data from the model Chris@83: settings.setValue Chris@83: ("flexinotes", Chris@83: QString("") Chris@83: .arg(int(FlexiNoteLayer::AutoAlignScale))); Chris@83: settings.endGroup(); Chris@6: } Chris@6: Chris@6: Analyser::~Analyser() Chris@6: { Chris@6: } Chris@6: Chris@6: void Chris@6: Analyser::newFileLoaded(Document *doc, WaveFileModel *model, Chris@6: PaneStack *paneStack, Pane *pane) Chris@6: { Chris@6: m_document = doc; Chris@6: m_fileModel = model; Chris@6: m_pane = pane; Chris@6: Chris@83: QString base = "vamp:pyin:pyin:"; Chris@83: QString f0out = "smoothedpitchtrack"; Chris@83: QString noteout = "notes"; Chris@6: Chris@6: // We don't want a waveform in the main pane. We must have a Chris@6: // main-model layer of some sort, but the layers created by Chris@6: // transforms are derived layers, so we'll create a time ruler for Chris@6: // the main-model layer. It could subsequently be hidden if we Chris@6: // didn't want it Chris@6: Chris@6: m_document->addLayerToView Chris@6: (m_pane, m_document->createMainModelLayer(LayerFactory::TimeRuler)); Chris@6: Chris@83: Transforms transforms; Chris@83: Chris@83: TransformFactory *tf = TransformFactory::getInstance(); Chris@83: if (!tf->haveTransform(base + f0out) || !tf->haveTransform(base + noteout)) { Chris@83: std::cerr << "ERROR: Analyser::newFileLoaded: Transform unknown" << std::endl; Chris@83: return; Chris@6: } Chris@6: Chris@83: Transform t = tf->getDefaultTransformFor Chris@83: (base + f0out, m_fileModel->getSampleRate()); Chris@83: t.setStepSize(256); Chris@83: t.setBlockSize(2048); Chris@6: Chris@83: transforms.push_back(t); Chris@83: Chris@83: t.setOutput(noteout); Chris@83: Chris@83: transforms.push_back(t); Chris@83: Chris@83: std::vector layers = Chris@83: m_document->createDerivedLayers(transforms, m_fileModel); Chris@83: Chris@83: if (!layers.empty()) { Chris@83: Chris@83: ColourDatabase *cdb = ColourDatabase::getInstance(); Chris@83: Chris@83: for (int i = 0; i < (int)layers.size(); ++i) { Chris@83: Chris@83: SingleColourLayer *scl = dynamic_cast Chris@83: (layers[i]); Chris@83: Chris@83: if (scl) { Chris@83: if (i == 0) { Chris@83: scl->setBaseColour(cdb->getColourIndex(tr("Black"))); Chris@83: } else { Chris@83: scl->setBaseColour(cdb->getColourIndex(tr("Bright Blue"))); Chris@83: } Chris@83: } Chris@83: Chris@83: m_document->addLayerToView(m_pane, layers[i]); Chris@83: } Chris@83: Chris@83: m_flexiNoteLayer = dynamic_cast Chris@83: (layers[layers.size()-1]); Chris@83: paneStack->setCurrentLayer(m_pane, m_flexiNoteLayer); Chris@6: } Chris@6: } Chris@6: gyorgyf@45: void gyorgyf@45: Analyser::setIntelligentActions(bool on) gyorgyf@45: { gyorgyf@45: std::cerr << "toggle setIntelligentActions " << on << std::endl; Chris@70: if (m_flexiNoteLayer) { Chris@70: m_flexiNoteLayer->setIntelligentActions(on); Chris@70: } gyorgyf@45: }