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@1211
|
22 #include <QMutex>
|
Chris@1211
|
23 #include <QWaitCondition>
|
Chris@361
|
24
|
Chris@475
|
25 #include <vamp-hostsdk/Plugin.h>
|
Chris@350
|
26
|
Chris@350
|
27 #include <iostream>
|
Chris@876
|
28 #include <map>
|
Chris@320
|
29
|
Chris@320
|
30 class DenseTimeValueModel;
|
Chris@876
|
31 class SparseTimeValueModel;
|
Chris@320
|
32
|
Chris@350
|
33 class FeatureExtractionModelTransformer : public ModelTransformer
|
Chris@320
|
34 {
|
Chris@320
|
35 Q_OBJECT
|
Chris@320
|
36
|
Chris@320
|
37 public:
|
Chris@350
|
38 FeatureExtractionModelTransformer(Input input,
|
Chris@859
|
39 const Transform &transform);
|
Chris@848
|
40
|
Chris@848
|
41 // Obtain outputs for a set of transforms that all use the same
|
Chris@848
|
42 // plugin and input (but with different outputs). i.e. run the
|
Chris@848
|
43 // plugin once only and collect more than one output from it.
|
Chris@848
|
44 FeatureExtractionModelTransformer(Input input,
|
Chris@859
|
45 const Transforms &relatedTransforms);
|
gyorgyf@786
|
46
|
Chris@331
|
47 virtual ~FeatureExtractionModelTransformer();
|
Chris@320
|
48
|
Chris@877
|
49 // ModelTransformer method, retrieve the additional models
|
Chris@877
|
50 Models getAdditionalOutputModels();
|
Chris@877
|
51 bool willHaveAdditionalOutputModels();
|
Chris@877
|
52
|
Chris@320
|
53 protected:
|
Chris@849
|
54 bool initialise();
|
Chris@849
|
55
|
Chris@320
|
56 virtual void run();
|
Chris@320
|
57
|
Chris@320
|
58 Vamp::Plugin *m_plugin;
|
Chris@849
|
59 std::vector<Vamp::Plugin::OutputDescriptor *> m_descriptors; // per transform
|
Chris@849
|
60 std::vector<int> m_fixedRateFeatureNos; // to assign times to FixedSampleRate features
|
Chris@876
|
61 std::vector<int> m_outputNos; // list of plugin output indexes required for this group of transforms
|
Chris@320
|
62
|
Chris@876
|
63 void createOutputModels(int n);
|
Chris@876
|
64
|
Chris@876
|
65 std::map<int, bool> m_needAdditionalModels; // transformNo -> necessity
|
Chris@876
|
66 typedef std::map<int, std::map<int, SparseTimeValueModel *> > AdditionalModelMap;
|
Chris@876
|
67 AdditionalModelMap m_additionalModels;
|
Chris@876
|
68 SparseTimeValueModel *getAdditionalModel(int transformNo, int binNo);
|
Chris@876
|
69
|
Chris@850
|
70 void addFeature(int n,
|
Chris@1039
|
71 sv_frame_t blockFrame,
|
Chris@320
|
72 const Vamp::Plugin::Feature &feature);
|
Chris@320
|
73
|
Chris@850
|
74 void setCompletion(int, int);
|
Chris@320
|
75
|
Chris@1039
|
76 void getFrames(int channelCount, sv_frame_t startFrame, sv_frame_t size,
|
Chris@363
|
77 float **buffer);
|
Chris@320
|
78
|
Chris@1211
|
79 bool m_haveOutputs;
|
Chris@1211
|
80 QMutex m_outputMutex;
|
Chris@1211
|
81 QWaitCondition m_outputsCondition;
|
Chris@1211
|
82 void awaitOutputModels();
|
Chris@1211
|
83
|
Chris@1211
|
84 // just casts:
|
Chris@441
|
85
|
Chris@350
|
86 DenseTimeValueModel *getConformingInput();
|
Chris@441
|
87
|
Chris@849
|
88 template <typename ModelClass> bool isOutput(int n) {
|
Chris@849
|
89 return dynamic_cast<ModelClass *>(m_outputs[n]) != 0;
|
Chris@441
|
90 }
|
Chris@441
|
91
|
Chris@849
|
92 template <typename ModelClass> ModelClass *getConformingOutput(int n) {
|
Chris@849
|
93 if ((int)m_outputs.size() > n) {
|
Chris@849
|
94 ModelClass *mc = dynamic_cast<ModelClass *>(m_outputs[n]);
|
Chris@849
|
95 if (!mc) {
|
Chris@849
|
96 std::cerr << "FeatureExtractionModelTransformer::getOutput: Output model not conformable" << std::endl;
|
Chris@849
|
97 }
|
Chris@849
|
98 return mc;
|
Chris@849
|
99 } else {
|
Chris@849
|
100 std::cerr << "FeatureExtractionModelTransformer::getOutput: No such output number " << n << std::endl;
|
Chris@849
|
101 return 0;
|
Chris@849
|
102 }
|
Chris@320
|
103 }
|
Chris@320
|
104 };
|
Chris@320
|
105
|
Chris@320
|
106 #endif
|
Chris@320
|
107
|