Chris@320: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@320: Chris@320: /* Chris@320: Sonic Visualiser Chris@320: An audio file viewer and annotation editor. Chris@320: Centre for Digital Music, Queen Mary, University of London. Chris@320: This file copyright 2006 Chris Cannam and QMUL. Chris@320: Chris@320: This program is free software; you can redistribute it and/or Chris@320: modify it under the terms of the GNU General Public License as Chris@320: published by the Free Software Foundation; either version 2 of the Chris@320: License, or (at your option) any later version. See the file Chris@320: COPYING included with this distribution for more information. Chris@320: */ Chris@320: Chris@849: #ifndef _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_ Chris@849: #define _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_ Chris@320: Chris@350: #include "ModelTransformer.h" Chris@350: Chris@361: #include Chris@1211: #include Chris@1211: #include Chris@361: Chris@475: #include Chris@350: Chris@350: #include Chris@876: #include Chris@320: Chris@320: class DenseTimeValueModel; Chris@876: class SparseTimeValueModel; Chris@320: Chris@350: class FeatureExtractionModelTransformer : public ModelTransformer Chris@320: { Chris@320: Q_OBJECT Chris@320: Chris@320: public: Chris@350: FeatureExtractionModelTransformer(Input input, Chris@859: const Transform &transform); Chris@848: Chris@848: // Obtain outputs for a set of transforms that all use the same Chris@848: // plugin and input (but with different outputs). i.e. run the Chris@848: // plugin once only and collect more than one output from it. Chris@848: FeatureExtractionModelTransformer(Input input, Chris@859: const Transforms &relatedTransforms); gyorgyf@786: Chris@331: virtual ~FeatureExtractionModelTransformer(); Chris@320: Chris@877: // ModelTransformer method, retrieve the additional models Chris@877: Models getAdditionalOutputModels(); Chris@877: bool willHaveAdditionalOutputModels(); Chris@877: Chris@320: protected: Chris@849: bool initialise(); Chris@849: Chris@320: virtual void run(); Chris@320: Chris@320: Vamp::Plugin *m_plugin; Chris@849: std::vector m_descriptors; // per transform Chris@849: std::vector m_fixedRateFeatureNos; // to assign times to FixedSampleRate features Chris@876: std::vector m_outputNos; // list of plugin output indexes required for this group of transforms Chris@320: Chris@876: void createOutputModels(int n); Chris@876: Chris@876: std::map m_needAdditionalModels; // transformNo -> necessity Chris@876: typedef std::map > AdditionalModelMap; Chris@876: AdditionalModelMap m_additionalModels; Chris@876: SparseTimeValueModel *getAdditionalModel(int transformNo, int binNo); Chris@876: Chris@850: void addFeature(int n, Chris@1039: sv_frame_t blockFrame, Chris@320: const Vamp::Plugin::Feature &feature); Chris@320: Chris@850: void setCompletion(int, int); Chris@320: Chris@1039: void getFrames(int channelCount, sv_frame_t startFrame, sv_frame_t size, Chris@363: float **buffer); Chris@320: Chris@1211: bool m_haveOutputs; Chris@1211: QMutex m_outputMutex; Chris@1211: QWaitCondition m_outputsCondition; Chris@1211: void awaitOutputModels(); Chris@1211: Chris@1211: // just casts: Chris@441: Chris@350: DenseTimeValueModel *getConformingInput(); Chris@441: Chris@849: template bool isOutput(int n) { Chris@849: return dynamic_cast(m_outputs[n]) != 0; Chris@441: } Chris@441: Chris@849: template ModelClass *getConformingOutput(int n) { Chris@849: if ((int)m_outputs.size() > n) { Chris@849: ModelClass *mc = dynamic_cast(m_outputs[n]); Chris@849: if (!mc) { Chris@849: std::cerr << "FeatureExtractionModelTransformer::getOutput: Output model not conformable" << std::endl; Chris@849: } Chris@849: return mc; Chris@849: } else { Chris@849: std::cerr << "FeatureExtractionModelTransformer::getOutput: No such output number " << n << std::endl; Chris@849: return 0; Chris@849: } Chris@320: } Chris@320: }; Chris@320: Chris@320: #endif Chris@320: