svcore  1.9
FeatureExtractionModelTransformer.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_
17 #define _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_
18 
19 #include "ModelTransformer.h"
20 
21 #include <QString>
22 
23 #include <vamp-hostsdk/Plugin.h>
24 
25 #include <iostream>
26 #include <map>
27 
30 
32 {
33  Q_OBJECT
34 
35 public:
37  const Transform &transform);
38 
39  // Obtain outputs for a set of transforms that all use the same
40  // plugin and input (but with different outputs). i.e. run the
41  // plugin once only and collect more than one output from it.
43  const Transforms &relatedTransforms);
44 
46 
47  // ModelTransformer method, retrieve the additional models
50 
51 protected:
52  bool initialise();
53 
54  virtual void run();
55 
56  Vamp::Plugin *m_plugin;
57  std::vector<Vamp::Plugin::OutputDescriptor *> m_descriptors; // per transform
58  std::vector<int> m_fixedRateFeatureNos; // to assign times to FixedSampleRate features
59  std::vector<int> m_outputNos; // list of plugin output indexes required for this group of transforms
60 
61  void createOutputModels(int n);
62 
63  std::map<int, bool> m_needAdditionalModels; // transformNo -> necessity
64  typedef std::map<int, std::map<int, SparseTimeValueModel *> > AdditionalModelMap;
66  SparseTimeValueModel *getAdditionalModel(int transformNo, int binNo);
67 
68  void addFeature(int n,
69  int blockFrame,
70  const Vamp::Plugin::Feature &feature);
71 
72  void setCompletion(int, int);
73 
74  void getFrames(int channelCount, long startFrame, long size,
75  float **buffer);
76 
77  // just casts
78 
80 
81  template <typename ModelClass> bool isOutput(int n) {
82  return dynamic_cast<ModelClass *>(m_outputs[n]) != 0;
83  }
84 
85  template <typename ModelClass> ModelClass *getConformingOutput(int n) {
86  if ((int)m_outputs.size() > n) {
87  ModelClass *mc = dynamic_cast<ModelClass *>(m_outputs[n]);
88  if (!mc) {
89  std::cerr << "FeatureExtractionModelTransformer::getOutput: Output model not conformable" << std::endl;
90  }
91  return mc;
92  } else {
93  std::cerr << "FeatureExtractionModelTransformer::getOutput: No such output number " << n << std::endl;
94  return 0;
95  }
96  }
97 };
98 
99 #endif
100 
bool willHaveAdditionalOutputModels()
Return true if the current transform is one that may produce additional models (to be retrieved throu...
std::vector< Transform > Transforms
Definition: Transform.h:200
SparseTimeValueModel * getAdditionalModel(int transformNo, int binNo)
void getFrames(int channelCount, long startFrame, long size, float **buffer)
Models getAdditionalOutputModels()
Return any additional models that were created during processing.
std::vector< Model * > Models
std::map< int, std::map< int, SparseTimeValueModel * > > AdditionalModelMap
FeatureExtractionModelTransformer(Input input, const Transform &transform)
void addFeature(int n, int blockFrame, const Vamp::Plugin::Feature &feature)
Base class for models containing dense two-dimensional data (value against time).
std::vector< Vamp::Plugin::OutputDescriptor * > m_descriptors
A ModelTransformer turns one data model into another.