annotate transform/FeatureExtractionModelTransformer.h @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents 5f8fbbde08ff
children
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@1581 16 #ifndef SV_FEATURE_EXTRACTION_MODEL_TRANSFORMER_H
Chris@1581 17 #define SV_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@1236 33 class FeatureExtractionModelTransformer : public ModelTransformer // + is a Thread
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@1739 41 /**
Chris@1739 42 * Obtain outputs for a set of transforms that all use the same
Chris@1739 43 * plugin and input (but with different outputs). i.e. run the
Chris@1739 44 * plugin once only and collect more than one output from it.
Chris@1739 45 */
Chris@848 46 FeatureExtractionModelTransformer(Input input,
Chris@859 47 const Transforms &relatedTransforms);
gyorgyf@786 48
Chris@331 49 virtual ~FeatureExtractionModelTransformer();
Chris@320 50
Chris@877 51 // ModelTransformer method, retrieve the additional models
Chris@1580 52 Models getAdditionalOutputModels() override;
Chris@1580 53 bool willHaveAdditionalOutputModels() override;
Chris@877 54
Chris@320 55 protected:
Chris@849 56 bool initialise();
Chris@1237 57 void deinitialise();
Chris@849 58
Chris@1580 59 void run() override;
Chris@320 60
Chris@1830 61 std::shared_ptr<Vamp::Plugin> m_plugin;
Chris@1739 62
Chris@1739 63 // descriptors per transform
Chris@1739 64 std::vector<Vamp::Plugin::OutputDescriptor> m_descriptors;
Chris@1739 65
Chris@1739 66 // to assign times to FixedSampleRate features
Chris@1739 67 std::vector<int> m_fixedRateFeatureNos;
Chris@1739 68
Chris@1739 69 // list of plugin output indexes required for this group of transforms
Chris@1739 70 std::vector<int> m_outputNos;
Chris@320 71
Chris@876 72 void createOutputModels(int n);
Chris@876 73
Chris@1739 74 // map from transformNo -> necessity
Chris@1739 75 std::map<int, bool> m_needAdditionalModels;
Chris@1739 76
Chris@1739 77 // map from transformNo -> binNo -> SparseTimeValueModel id
Chris@1739 78 typedef std::map<int, std::map<int, ModelId> > AdditionalModelMap;
Chris@1739 79
Chris@876 80 AdditionalModelMap m_additionalModels;
Chris@1739 81
Chris@1739 82 ModelId getAdditionalModel(int transformNo, int binNo);
Chris@876 83
Chris@850 84 void addFeature(int n,
Chris@1039 85 sv_frame_t blockFrame,
Chris@1429 86 const Vamp::Plugin::Feature &feature);
Chris@320 87
Chris@850 88 void setCompletion(int, int);
Chris@320 89
Chris@1039 90 void getFrames(int channelCount, sv_frame_t startFrame, sv_frame_t size,
Chris@363 91 float **buffer);
Chris@320 92
Chris@1211 93 bool m_haveOutputs;
Chris@1211 94 QMutex m_outputMutex;
Chris@1211 95 QWaitCondition m_outputsCondition;
Chris@1580 96 void awaitOutputModels() override;
Chris@1211 97
Chris@1740 98 template <typename T> bool isOutputType(int n) {
Chris@1740 99 if (!ModelById::getAs<T>(m_outputs[n])) {
Chris@1740 100 return false;
Chris@1740 101 } else {
Chris@1740 102 return true;
Chris@1740 103 }
Chris@441 104 }
Chris@441 105
Chris@1740 106 template <typename T> bool setOutputCompletion(int n, int completion) {
Chris@1740 107 auto model = ModelById::getAs<T>(m_outputs[n]);
Chris@1740 108 if (!model) {
Chris@1740 109 return false;
Chris@849 110 } else {
Chris@1740 111 model->setCompletion(completion, true);
Chris@1740 112 return true;
Chris@849 113 }
Chris@320 114 }
Chris@320 115 };
Chris@320 116
Chris@320 117 #endif
Chris@320 118