12#include "dsp/hart_dsp.hpp"
23template<
typename SampleType>
32 m_numChannels(other.m_numChannels)
34 if (other.dspChain.size() == 0)
37 dspChain.reserve (dspChain.size());
39 for (
auto& dsp : other.dspChain)
40 dspChain.push_back (dsp->copy());
45 m_numChannels (other.m_numChannels),
46 dspChain (std::move (other.dspChain))
48 other.m_numChannels = 0;
60 m_numChannels = other.m_numChannels;
63 if (other.dspChain.size() == 0)
66 for (
auto& dsp : other.dspChain)
67 dspChain.push_back (dsp->copy());
78 m_numChannels = other.m_numChannels;
79 dspChain = std::move (other.dspChain);
80 other.m_numChannels = 0;
109 virtual void prepare (
double sampleRateHz, size_t numOutputChannels, size_t maxBlockSizeFrames) = 0;
136 virtual std::unique_ptr<
Signal<SampleType>>
copy()
const = 0;
150 virtual void represent (std::ostream& stream)
const = 0;
157 dspChain.emplace_back (dsp.copy());
166 dspChain.emplace_back (std::move (dsp));
177 typename =
typename std::enable_if<
180 typename std::decay<DerivedDSP>::type
186 dspChain.emplace_back (
187 hart::make_unique<
typename std::decay<DerivedDSP>::type> (std::forward<DerivedDSP> (dsp))
200 prepare (sampleRateHz
, numOutputChannels
, maxBlockSizeFrames
);
201 const size_t numInputChannels = numOutputChannels;
205 for (
auto& dsp : dspChain)
207 if (! dsp->supportsChannelLayout (numInputChannels, numOutputChannels))
210 if (! dsp->supportsSampleRate (sampleRateHz))
213 dsp->prepareWithEnvelopes (sampleRateHz, numInputChannels, numOutputChannels, maxBlockSizeFrames);
227 for (
auto& dsp : dspChain)
228 dsp->processWithEnvelopes (inputReplacing, output);
238 for (
auto& dsp : dspChain)
246 void representWithDSPChain (std::ostream& stream)
const
250 for (
const auto& dsp : dspChain)
251 stream <<
" >> " << *dsp;
256 using m_SampleType = SampleType;
261 m_numChannels = numChannels;
266 return m_numChannels;
270 size_t m_numChannels = 1;
271 std::vector<std::unique_ptr<
DSP<SampleType>>> dspChain;
277template<
typename SampleType>
278std::ostream& operator<< (std::ostream& stream,
const Signal<SampleType>& signal)
280 signal.representWithDSPChain (stream);
287template<
typename SampleType,
288 typename DerivedDSP,
typename std::enable_if<std::is_base_of<
DSP<SampleType>,
typename std::decay<DerivedDSP>::type>::value>::type>
291 return signal.followedBy (std::move (dsp));
297template<
typename SampleType>
300 return signal.followedBy (dsp);
306template<
typename SampleType>
309 return std::move (signal.followedBy (dsp));
315template<
typename SampleType>
318 signal.followedBy (std::move (dsp));
325template<
typename SampleType>
328 signal.followedBy (std::move (dsp));
329 return std::move (signal);
346#define HART_SIGNAL_DEFINE_COPY_AND_MOVE(ClassName)
347 std::unique_ptr<Signal<SampleType>> copy() const override {
348 return hart::make_unique<ClassName> (*this);
350 std::unique_ptr<Signal<SampleType>> move() override {
351 return hart::make_unique<ClassName> (std::move (*this));
370#define HART_SIGNAL_FORBID_COPY_AND_MOVE
371 std::unique_ptr<Signal<SampleType>> copy() const override {
372 static_assert(false, "This Signal cannot be copied");
375 std::unique_ptr<Signal<SampleType>> move() override {
376 static_assert(false, "This Signal cannot be moved");
381#define HART_SIGNAL_DECLARE_ALIASES_FOR(ClassName)
382 namespace aliases_float{
383 using ClassName = hart::ClassName<float>;
385 namespace aliases_double{
386 using ClassName = hart::ClassName<double>;
virtual void reset()=0
Resets the Signal to initial state.
virtual void represent(std::ostream &stream) const =0
Makes a text representation of this Signal for test failure outputs.
void renderNextBlockWithDSPChain(AudioBuffer< SampleType > &output)
Renders next block audio for the signal and all the effects in the DSP chain.
virtual void resetWithDSPChain()
Resets to Signal and all the effects attached to its DSP chain to initial state.
Signal & followedBy(const DSP< SampleType > &dsp)
Adds a DSP effect to the end of signal's DSP chain by copying it.
Signal(const Signal &other)
Copies other signal.
virtual void renderNextBlock(AudioBuffer< SampleType > &output)=0
Renders next block audio for the signal.
Signal & followedBy(std::unique_ptr< DSP< SampleType > > dsp)
Adds a DSP effect to the end of signal's DSP chain by transfering a smart pointer.
void prepareWithDSPChain(double sampleRateHz, size_t numOutputChannels, size_t maxBlockSizeFrames)
Prepares the signal and all attached effects in the DSP chain for rendering.
void setNumChannels(size_t numChannels)
virtual ~Signal()=default
Destructor.
virtual bool supportsNumChannels(size_t) const
Tells the host whether this Signal is capable of generating audio for a certain amount of cchannels.
virtual bool supportsSampleRate(double) const
Tells whether this Signal supports given sample rate.
Signal(Signal &&other) noexcept
Moves from other signal.
Signal & operator=(Signal &&other) noexcept
Moves from other signal.
virtual std::unique_ptr< Signal< SampleType > > copy() const =0
Returns a smart pointer with a copy of this object.
Signal & followedBy(DerivedDSP &&dsp)
Adds a DSP effect to the end of signal's DSP chain by moving it.
Signal()=default
Default constructor.
Signal & operator=(const Signal &other)
Copies from other signal.
virtual void prepare(double sampleRateHz, size_t numOutputChannels, size_t maxBlockSizeFrames)=0
Prepare the signal for rendering.
virtual std::unique_ptr< Signal< SampleType > > move()=0
Returns a smart pointer with a moved instance of this object.
Signal< SampleType > && operator>>(Signal< SampleType > &&signal, std::unique_ptr< DSP< SampleType > > dsp)
Adds a DSP effect to the end of signal's DSP chain by transfering it.
Signal< SampleType > & operator>>(Signal< SampleType > &signal, const DSP< SampleType > &dsp)
Adds a DSP effect to the end of signal's DSP chain by copying it.
Signal< SampleType > & operator>>(Signal< SampleType > &signal, DerivedDSP &&dsp)
Adds a DSP effect to the end of signal's DSP chain by moving it.
Signal< SampleType > && operator>>(Signal< SampleType > &&signal, const DSP< SampleType > &dsp)
Adds a DSP effect to the end of signal's DSP chain by copying it.
Signal< SampleType > & operator>>(Signal< SampleType > &signal, std::unique_ptr< DSP< SampleType > > dsp)
Adds a DSP effect to the end of signal's DSP chain by transfering it.
#define HART_THROW_OR_RETURN_VOID(ExceptionType, message)