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 SV_FEATURE_EXTRACTION_MODEL_TRANSFORMER_H
17 #define SV_FEATURE_EXTRACTION_MODEL_TRANSFORMER_H
18 
19 #include "ModelTransformer.h"
20 
21 #include <QString>
22 #include <QMutex>
23 #include <QWaitCondition>
24 
25 #include <vamp-hostsdk/Plugin.h>
26 
27 #include <iostream>
28 #include <map>
29 
32 
33 class FeatureExtractionModelTransformer : public ModelTransformer // + is a Thread
34 {
35  Q_OBJECT
36 
37 public:
39  const Transform &transform);
40 
47  const Transforms &relatedTransforms);
48 
50 
51  // ModelTransformer method, retrieve the additional models
53  bool willHaveAdditionalOutputModels() override;
54 
55 protected:
56  bool initialise();
57  void deinitialise();
58 
59  void run() override;
60 
61  std::shared_ptr<Vamp::Plugin> m_plugin;
62 
63  // descriptors per transform
64  std::vector<Vamp::Plugin::OutputDescriptor> m_descriptors;
65 
66  // to assign times to FixedSampleRate features
67  std::vector<int> m_fixedRateFeatureNos;
68 
69  // list of plugin output indexes required for this group of transforms
70  std::vector<int> m_outputNos;
71 
72  void createOutputModels(int n);
73 
74  // map from transformNo -> necessity
75  std::map<int, bool> m_needAdditionalModels;
76 
77  // map from transformNo -> binNo -> SparseTimeValueModel id
78  typedef std::map<int, std::map<int, ModelId> > AdditionalModelMap;
79 
80  AdditionalModelMap m_additionalModels;
81 
82  ModelId getAdditionalModel(int transformNo, int binNo);
83 
84  void addFeature(int n,
85  sv_frame_t blockFrame,
86  const Vamp::Plugin::Feature &feature);
87 
88  void setCompletion(int, int);
89 
90  void getFrames(int channelCount, sv_frame_t startFrame, sv_frame_t size,
91  float **buffer);
92 
94  QMutex m_outputMutex;
95  QWaitCondition m_outputsCondition;
96  void awaitOutputModels() override;
97 
98  template <typename T> bool isOutputType(int n) {
99  if (!ModelById::getAs<T>(m_outputs[n])) {
100  return false;
101  } else {
102  return true;
103  }
104  }
105 
106  template <typename T> bool setOutputCompletion(int n, int completion) {
107  auto model = ModelById::getAs<T>(m_outputs[n]);
108  if (!model) {
109  return false;
110  } else {
111  model->setCompletion(completion, true);
112  return true;
113  }
114  }
115 };
116 
117 #endif
118 
void addFeature(int n, sv_frame_t blockFrame, const Vamp::Plugin::Feature &feature)
ModelId getAdditionalModel(int transformNo, int binNo)
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
std::map< int, std::map< int, ModelId > > AdditionalModelMap
std::vector< Transform > Transforms
Definition: Transform.h:204
std::vector< ModelId > Models
std::vector< Vamp::Plugin::OutputDescriptor > m_descriptors
FeatureExtractionModelTransformer(Input input, const Transform &transform)
bool willHaveAdditionalOutputModels() override
Return true if the current transform is one that may produce additional models (to be retrieved throu...
void getFrames(int channelCount, sv_frame_t startFrame, sv_frame_t size, float **buffer)
Models getAdditionalOutputModels() override
Return any additional models that were created during processing.
A model representing a wiggly-line plot with points at arbitrary intervals of the model resolution...
Base class for models containing dense two-dimensional data (value against time). ...
A ModelTransformer turns one data model into another.
Definition: ById.h:115