Essentia  2.1-beta5-dev
devnull.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_DEVNULL_H
21 #define ESSENTIA_DEVNULL_H
22 
23 #include "../streamingalgorithm.h"
24 
25 namespace essentia {
26 namespace streaming {
27 
28 template <typename TokenType>
29 class DevNull : public Algorithm {
30  protected:
32 
33  public:
35  static ForcedMutex _devnullInitMutex;
36  static int _devnullId = 0;
37 
38  ForcedMutexLocker lock(_devnullInitMutex);
39 
40  int devnullId = _devnullId++;
41  std::ostringstream name;
42  name << "DevNull<" << nameOfType(typeid(TokenType)) << ">[" << devnullId << "]";
43  setName(name.str());
44  declareInput(_frames, 1, "data", "the incoming data to discard");
45  E_DEBUG(EFactory, "Created " << _name);
46  }
47 
49 
51  int nframes = std::min(_frames.available(),
53  nframes = std::max(nframes, 1); // in case phantomsize == 0
54 
55  EXEC_DEBUG("Consuming " << nframes << " tokens");
56 
57  if (!_frames.acquire(nframes)) {
58  EXEC_DEBUG("Could not consume because not enough input tokens");
59  return NO_INPUT;
60  }
61 
62  // do nothing, only release the tokens we just acquired
63  _frames.release(nframes);
64 
65  return OK;
66  }
67 };
68 
69 
73 };
74 
79 void connect(SourceBase& source, DevNullConnector devnull);
80 
81 inline void operator>>(SourceBase& source, DevNullConnector devnull) {
82  connect(source, devnull);
83 }
84 
85 
89 void disconnect(SourceBase& source, DevNullConnector devnull);
90 
91 } // namespace streaming
92 } // namespace essentia
93 
94 #endif // ESSENTIA_DEVNULL_H
int maxContiguousElements
Definition: types.h:384
DevNull()
Definition: devnull.h:34
void declareInput(SinkBase &sink, const std::string &name, const std::string &desc)
Definition: sourcebase.h:52
void declareParameters()
Definition: devnull.h:48
DevNullConnector
Definition: devnull.h:70
const MultiRateBuffer< TokenType > & buffer() const
Definition: sink.h:45
void connect(SourceBase &source, DevNullConnector devnull)
std::string nameOfType(const std::type_info &type)
const std::string & name() const
Definition: configurable.h:48
void release()
Definition: sink.h:79
void setName(const std::string &name)
Definition: configurable.h:53
std::string _name
Definition: configurable.h:171
void operator>>(SourceBase &source, DevNullConnector devnull)
Definition: devnull.h:81
Definition: streamingalgorithm.h:111
Definition: devnull.h:71
Definition: devnull.h:29
Definition: devnull.h:72
Definition: streamingalgorithm.h:107
AlgorithmStatus
Definition: streamingalgorithm.h:106
Definition: algorithm.h:28
Definition: streamingalgorithm.h:140
void acquire()
Definition: sink.h:67
Definition: threading.h:95
void disconnect(SourceBase &source, DevNullConnector devnull)
Definition: sink.h:35
Definition: threading.h:80
virtual BufferInfo bufferInfo() const =0
#define EXEC_DEBUG(msg)
Definition: debugging.h:161
AlgorithmStatus process()
Definition: devnull.h:50
virtual int available() const
Definition: sink.h:88
#define E_DEBUG(module, msg)
Definition: debugging.h:157
Sink< TokenType > _frames
Definition: devnull.h:31
Definition: debugging.h:44