annotate transform/FeatureExtractionModelTransformer.h @ 1182:a1f410f895d3 3.0-integration

Merge from branch pluginscan
author Chris Cannam
date Fri, 15 Apr 2016 16:26:15 +0100
parents b14064bd1f97
children 5a1198083d9a
rev   line source
Chris@320 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@320 2
Chris@320 3 /*
Chris@320 4 Sonic Visualiser
Chris@320 5 An audio file viewer and annotation editor.
Chris@320 6 Centre for Digital Music, Queen Mary, University of London.
Chris@320 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@320 8
Chris@320 9 This program is free software; you can redistribute it and/or
Chris@320 10 modify it under the terms of the GNU General Public License as
Chris@320 11 published by the Free Software Foundation; either version 2 of the
Chris@320 12 License, or (at your option) any later version. See the file
Chris@320 13 COPYING included with this distribution for more information.
Chris@320 14 */
Chris@320 15
Chris@849 16 #ifndef _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_
Chris@849 17 #define _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_
Chris@320 18
Chris@350 19 #include "ModelTransformer.h"
Chris@350 20
Chris@361 21 #include <QString>
Chris@361 22
Chris@475 23 #include <vamp-hostsdk/Plugin.h>
Chris@350 24
Chris@350 25 #include <iostream>
Chris@876 26 #include <map>
Chris@320 27
Chris@320 28 class DenseTimeValueModel;
Chris@876 29 class SparseTimeValueModel;
Chris@320 30
Chris@350 31 class FeatureExtractionModelTransformer : public ModelTransformer
Chris@320 32 {
Chris@320 33 Q_OBJECT
Chris@320 34
Chris@320 35 public:
Chris@350 36 FeatureExtractionModelTransformer(Input input,
Chris@859 37 const Transform &transform);
Chris@848 38
Chris@848 39 // Obtain outputs for a set of transforms that all use the same
Chris@848 40 // plugin and input (but with different outputs). i.e. run the
Chris@848 41 // plugin once only and collect more than one output from it.
Chris@848 42 FeatureExtractionModelTransformer(Input input,
Chris@859 43 const Transforms &relatedTransforms);
gyorgyf@786 44
Chris@331 45 virtual ~FeatureExtractionModelTransformer();
Chris@320 46
Chris@877 47 // ModelTransformer method, retrieve the additional models
Chris@877 48 Models getAdditionalOutputModels();
Chris@877 49 bool willHaveAdditionalOutputModels();
Chris@877 50
Chris@320 51 protected:
Chris@849 52 bool initialise();
Chris@849 53
Chris@320 54 virtual void run();
Chris@320 55
Chris@320 56 Vamp::Plugin *m_plugin;
Chris@849 57 std::vector<Vamp::Plugin::OutputDescriptor *> m_descriptors; // per transform
Chris@849 58 std::vector<int> m_fixedRateFeatureNos; // to assign times to FixedSampleRate features
Chris@876 59 std::vector<int> m_outputNos; // list of plugin output indexes required for this group of transforms
Chris@320 60
Chris@876 61 void createOutputModels(int n);
Chris@876 62
Chris@876 63 std::map<int, bool> m_needAdditionalModels; // transformNo -> necessity
Chris@876 64 typedef std::map<int, std::map<int, SparseTimeValueModel *> > AdditionalModelMap;
Chris@876 65 AdditionalModelMap m_additionalModels;
Chris@876 66 SparseTimeValueModel *getAdditionalModel(int transformNo, int binNo);
Chris@876 67
Chris@850 68 void addFeature(int n,
Chris@1039 69 sv_frame_t blockFrame,
Chris@320 70 const Vamp::Plugin::Feature &feature);
Chris@320 71
Chris@850 72 void setCompletion(int, int);
Chris@320 73
Chris@1039 74 void getFrames(int channelCount, sv_frame_t startFrame, sv_frame_t size,
Chris@363 75 float **buffer);
Chris@320 76
Chris@320 77 // just casts
Chris@441 78
Chris@350 79 DenseTimeValueModel *getConformingInput();
Chris@441 80
Chris@849 81 template <typename ModelClass> bool isOutput(int n) {
Chris@849 82 return dynamic_cast<ModelClass *>(m_outputs[n]) != 0;
Chris@441 83 }
Chris@441 84
Chris@849 85 template <typename ModelClass> ModelClass *getConformingOutput(int n) {
Chris@849 86 if ((int)m_outputs.size() > n) {
Chris@849 87 ModelClass *mc = dynamic_cast<ModelClass *>(m_outputs[n]);
Chris@849 88 if (!mc) {
Chris@849 89 std::cerr << "FeatureExtractionModelTransformer::getOutput: Output model not conformable" << std::endl;
Chris@849 90 }
Chris@849 91 return mc;
Chris@849 92 } else {
Chris@849 93 std::cerr << "FeatureExtractionModelTransformer::getOutput: No such output number " << n << std::endl;
Chris@849 94 return 0;
Chris@849 95 }
Chris@320 96 }
Chris@320 97 };
Chris@320 98
Chris@320 99 #endif
Chris@320 100