Chris@739: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@739: Chris@739: /* Chris@739: Sonic Visualiser Chris@739: An audio file viewer and annotation editor. Chris@739: Centre for Digital Music, Queen Mary, University of London. Chris@739: Chris@739: This program is free software; you can redistribute it and/or Chris@739: modify it under the terms of the GNU General Public License as Chris@739: published by the Free Software Foundation; either version 2 of the Chris@739: License, or (at your option) any later version. See the file Chris@739: COPYING included with this distribution for more information. Chris@739: */ Chris@739: Chris@739: #ifndef SV_EFFECT_WRAPPER_H Chris@739: #define SV_EFFECT_WRAPPER_H Chris@739: Chris@739: #include "bqaudioio/ApplicationPlaybackSource.h" Chris@739: Chris@739: #include "base/BaseTypes.h" Chris@739: #include "base/RingBuffer.h" Chris@739: Chris@739: #include "plugin/RealTimePluginInstance.h" Chris@739: Chris@739: #include Chris@739: #include Chris@739: #include Chris@739: Chris@739: /** Chris@739: * A breakfastquay::ApplicationPlaybackSource wrapper that applies a Chris@739: * real-time effect plugin. Chris@739: */ Chris@739: class EffectWrapper : public breakfastquay::ApplicationPlaybackSource Chris@739: { Chris@739: public: Chris@739: /** Chris@739: * Create a wrapper around the given ApplicationPlaybackSource, Chris@739: * implementing another ApplicationPlaybackSource interface that Chris@739: * draws from the same source data but with an effect optionally Chris@739: * applied. Chris@739: * Chris@739: * The wrapper does not take ownership of the wrapped Chris@739: * ApplicationPlaybackSource, whose lifespan must exceed that of Chris@739: * this object. Chris@739: */ Chris@739: EffectWrapper(ApplicationPlaybackSource *source); Chris@739: ~EffectWrapper(); Chris@739: Chris@739: /** Chris@739: * Set the effect to apply. The effect instance is shared with the Chris@739: * caller: the expectation is that the caller may continue to Chris@739: * modify its parameters etc during auditioning. Replaces any Chris@739: * instance previously set. Chris@739: */ Chris@739: void setEffect(std::weak_ptr); Chris@739: Chris@739: /** Chris@749: * Return true if an effect is currently set to be applied. Chris@749: */ Chris@749: bool haveEffect() const; Chris@749: Chris@749: /** Chris@739: * Remove any applied effect without setting another one. Chris@739: */ Chris@739: void clearEffect(); Chris@739: Chris@739: /** Chris@739: * Bypass or un-bypass the effect. Chris@739: */ Chris@739: void setBypassed(bool bypassed); Chris@739: Chris@739: /** Chris@739: * Return true if the effect is bypassed. Chris@739: */ Chris@739: bool isBypassed() const; Chris@739: Chris@739: /** Chris@739: * Clear any buffered data. Chris@739: */ Chris@739: void reset(); Chris@739: Chris@739: // These functions are passed through to the wrapped Chris@739: // ApplicationPlaybackSource Chris@739: Chris@739: std::string getClientName() const override; Chris@739: int getApplicationSampleRate() const override; Chris@739: int getApplicationChannelCount() const override; Chris@739: Chris@739: void setSystemPlaybackBlockSize(int) override; Chris@739: void setSystemPlaybackSampleRate(int) override; Chris@739: void setSystemPlaybackChannelCount(int) override; Chris@739: void setSystemPlaybackLatency(int) override; Chris@739: Chris@739: void setOutputLevels(float peakLeft, float peakRight) override; Chris@739: void audioProcessingOverload() override; Chris@739: Chris@739: /** Chris@739: * Request some samples from the wrapped Chris@739: * ApplicationPlaybackSource, apply effect if set, and return them Chris@739: * to the target Chris@739: */ Chris@739: int getSourceSamples(float *const *samples, int nchannels, int nframes) Chris@739: override; Chris@739: Chris@739: private: Chris@739: ApplicationPlaybackSource *m_source; Chris@739: std::weak_ptr m_effect; Chris@739: bool m_bypassed; Chris@739: bool m_failed; Chris@739: int m_channelCount; Chris@739: std::vector> m_effectOutputBuffers; Chris@739: mutable std::mutex m_mutex; Chris@739: Chris@739: EffectWrapper(const EffectWrapper &)=delete; Chris@739: EffectWrapper &operator=(const EffectWrapper &)=delete; Chris@739: }; Chris@739: Chris@739: #endif Chris@739: Chris@739: