Essentia  2.1-beta5-dev
streamingalgorithmcomposite.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2016 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Essentia
5  *
6  * Essentia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef ESSENTIA_STREAMINGALGORITHMCOMPOSITE_H
21 #define ESSENTIA_STREAMINGALGORITHMCOMPOSITE_H
22 
23 #include "streamingalgorithm.h"
24 #include "sourceproxy.h"
25 #include "sinkproxy.h"
26 
27 namespace essentia {
28 namespace streaming {
29 
30 
31 class ProcessStep {
32 protected:
33  std::string _type;
35 public:
36  ProcessStep(const std::string& type, Algorithm* algo) : _type(type), _algo(algo) {}
37  const std::string& type() const { return _type; }
38  Algorithm* algorithm() { return _algo; }
39 };
40 
41 class ChainFrom : public ProcessStep {
42 public:
43  ChainFrom(Algorithm* algo) : ProcessStep("chain", algo) {}
44 };
45 
46 class SingleShot : public ProcessStep {
47 public:
48  SingleShot(Algorithm* algo) : ProcessStep("single", algo) {}
49 };
50 
51 
52 class AlgorithmComposite : public Algorithm {
53 
54  public:
55 
56  // Those are available here because it doesn't make sense to require an
57  // acquire/release size from a proxy source/sink
58  void declareInput(SinkBase& sink, const std::string& name, const std::string& desc);
59  void declareOutput(SourceBase& source, const std::string& name, const std::string& desc);
60 
61  // Those are here because otherwise they'd be shadowed
62  void declareInput(SinkBase& sink, int n, const std::string& name, const std::string& desc) {
63  Algorithm::declareInput(sink, n, name, desc);
64  }
65  void declareInput(SinkBase& sink, int acquireSize, int releaseSize, const std::string& name, const std::string& desc) {
66  Algorithm::declareInput(sink, acquireSize, releaseSize, name, desc);
67  }
68  void declareOutput(SourceBase& source, int n, const std::string& name, const std::string& desc) {
69  Algorithm::declareOutput(source, n, name, desc);
70  }
71  void declareOutput(SourceBase& source, int acquireSize, int releaseSize, const std::string& name, const std::string& desc) {
72  Algorithm::declareOutput(source, acquireSize, releaseSize, name, desc);
73  }
74 
75 
81 
82  // needs to be declared so that the scheduler knows what to do with this
83  virtual void declareProcessOrder() = 0;
84 
85  // TODO: can we make this return a const vector<ProcessStep>& instead?
86  // No: because we need to call the declareProcessOrder just at the moment we need
87  // to know it and not before, because the process order might be dependent on
88  // the configuration of the algorithm, e.g. see ReplayGain implementation
89  std::vector<ProcessStep> processOrder();
90 
95  void reset();
96 
97  void declareProcessStep(const ProcessStep& step);
98 
99 protected:
100  std::vector<ProcessStep> _processOrder;
101 };
102 
103 
104 } // namespace streaming
105 } // namespace essentia
106 
107 #endif // ESSENTIA_STREAMINGALGORITHMCOMPOSITE_H
Definition: streamingalgorithmcomposite.h:31
SingleShot(Algorithm *algo)
Definition: streamingalgorithmcomposite.h:48
void declareInput(SinkBase &sink, const std::string &name, const std::string &desc)
Definition: sourcebase.h:52
Algorithm * _algo
Definition: streamingalgorithmcomposite.h:34
const std::string & type() const
Definition: streamingalgorithmcomposite.h:37
void declareInput(SinkBase &sink, int acquireSize, int releaseSize, const std::string &name, const std::string &desc)
Definition: streamingalgorithmcomposite.h:65
void declareOutput(SourceBase &source, const std::string &name, const std::string &desc)
ProcessStep(const std::string &type, Algorithm *algo)
Definition: streamingalgorithmcomposite.h:36
void declareOutput(SourceBase &source, int acquireSize, int releaseSize, const std::string &name, const std::string &desc)
Definition: streamingalgorithmcomposite.h:71
Definition: streamingalgorithmcomposite.h:52
Algorithm * algorithm()
Definition: streamingalgorithmcomposite.h:38
Definition: streamingalgorithmcomposite.h:46
std::vector< ProcessStep > _processOrder
Definition: streamingalgorithmcomposite.h:100
Definition: sinkbase.h:52
void declareOutput(SourceBase &source, int n, const std::string &name, const std::string &desc)
Definition: streamingalgorithmcomposite.h:68
ChainFrom(Algorithm *algo)
Definition: streamingalgorithmcomposite.h:43
AlgorithmStatus
Definition: streamingalgorithm.h:106
std::string _type
Definition: streamingalgorithmcomposite.h:33
Definition: streamingalgorithmcomposite.h:41
Definition: algorithm.h:28
Definition: streamingalgorithm.h:140
void declareInput(SinkBase &sink, int n, const std::string &name, const std::string &desc)
Definition: streamingalgorithmcomposite.h:62
Definition: streamingalgorithm.h:109
AlgorithmStatus process()
Definition: streamingalgorithmcomposite.h:80