annotate audio/EffectWrapper.h @ 758:5b6655449ba6

Refuse to nest OSC invocations
author Chris Cannam
date Wed, 29 Apr 2020 15:27:13 +0100
parents 54393ed09d65
children
rev   line source
Chris@739 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@739 2
Chris@739 3 /*
Chris@739 4 Sonic Visualiser
Chris@739 5 An audio file viewer and annotation editor.
Chris@739 6 Centre for Digital Music, Queen Mary, University of London.
Chris@739 7
Chris@739 8 This program is free software; you can redistribute it and/or
Chris@739 9 modify it under the terms of the GNU General Public License as
Chris@739 10 published by the Free Software Foundation; either version 2 of the
Chris@739 11 License, or (at your option) any later version. See the file
Chris@739 12 COPYING included with this distribution for more information.
Chris@739 13 */
Chris@739 14
Chris@739 15 #ifndef SV_EFFECT_WRAPPER_H
Chris@739 16 #define SV_EFFECT_WRAPPER_H
Chris@739 17
Chris@739 18 #include "bqaudioio/ApplicationPlaybackSource.h"
Chris@739 19
Chris@739 20 #include "base/BaseTypes.h"
Chris@739 21 #include "base/RingBuffer.h"
Chris@739 22
Chris@739 23 #include "plugin/RealTimePluginInstance.h"
Chris@739 24
Chris@739 25 #include <vector>
Chris@739 26 #include <mutex>
Chris@739 27 #include <memory>
Chris@739 28
Chris@739 29 /**
Chris@739 30 * A breakfastquay::ApplicationPlaybackSource wrapper that applies a
Chris@739 31 * real-time effect plugin.
Chris@739 32 */
Chris@739 33 class EffectWrapper : public breakfastquay::ApplicationPlaybackSource
Chris@739 34 {
Chris@739 35 public:
Chris@739 36 /**
Chris@739 37 * Create a wrapper around the given ApplicationPlaybackSource,
Chris@739 38 * implementing another ApplicationPlaybackSource interface that
Chris@739 39 * draws from the same source data but with an effect optionally
Chris@739 40 * applied.
Chris@739 41 *
Chris@739 42 * The wrapper does not take ownership of the wrapped
Chris@739 43 * ApplicationPlaybackSource, whose lifespan must exceed that of
Chris@739 44 * this object.
Chris@739 45 */
Chris@739 46 EffectWrapper(ApplicationPlaybackSource *source);
Chris@739 47 ~EffectWrapper();
Chris@739 48
Chris@739 49 /**
Chris@739 50 * Set the effect to apply. The effect instance is shared with the
Chris@739 51 * caller: the expectation is that the caller may continue to
Chris@739 52 * modify its parameters etc during auditioning. Replaces any
Chris@739 53 * instance previously set.
Chris@739 54 */
Chris@739 55 void setEffect(std::weak_ptr<RealTimePluginInstance>);
Chris@739 56
Chris@739 57 /**
Chris@749 58 * Return true if an effect is currently set to be applied.
Chris@749 59 */
Chris@749 60 bool haveEffect() const;
Chris@749 61
Chris@749 62 /**
Chris@739 63 * Remove any applied effect without setting another one.
Chris@739 64 */
Chris@739 65 void clearEffect();
Chris@739 66
Chris@739 67 /**
Chris@739 68 * Bypass or un-bypass the effect.
Chris@739 69 */
Chris@739 70 void setBypassed(bool bypassed);
Chris@739 71
Chris@739 72 /**
Chris@739 73 * Return true if the effect is bypassed.
Chris@739 74 */
Chris@739 75 bool isBypassed() const;
Chris@739 76
Chris@739 77 /**
Chris@739 78 * Clear any buffered data.
Chris@739 79 */
Chris@739 80 void reset();
Chris@739 81
Chris@739 82 // These functions are passed through to the wrapped
Chris@739 83 // ApplicationPlaybackSource
Chris@739 84
Chris@739 85 std::string getClientName() const override;
Chris@739 86 int getApplicationSampleRate() const override;
Chris@739 87 int getApplicationChannelCount() const override;
Chris@739 88
Chris@739 89 void setSystemPlaybackBlockSize(int) override;
Chris@739 90 void setSystemPlaybackSampleRate(int) override;
Chris@739 91 void setSystemPlaybackChannelCount(int) override;
Chris@739 92 void setSystemPlaybackLatency(int) override;
Chris@739 93
Chris@739 94 void setOutputLevels(float peakLeft, float peakRight) override;
Chris@739 95 void audioProcessingOverload() override;
Chris@739 96
Chris@739 97 /**
Chris@739 98 * Request some samples from the wrapped
Chris@739 99 * ApplicationPlaybackSource, apply effect if set, and return them
Chris@739 100 * to the target
Chris@739 101 */
Chris@739 102 int getSourceSamples(float *const *samples, int nchannels, int nframes)
Chris@739 103 override;
Chris@739 104
Chris@739 105 private:
Chris@739 106 ApplicationPlaybackSource *m_source;
Chris@739 107 std::weak_ptr<RealTimePluginInstance> m_effect;
Chris@739 108 bool m_bypassed;
Chris@739 109 bool m_failed;
Chris@739 110 int m_channelCount;
Chris@739 111 std::vector<RingBuffer<float>> m_effectOutputBuffers;
Chris@739 112 mutable std::mutex m_mutex;
Chris@739 113
Chris@739 114 EffectWrapper(const EffectWrapper &)=delete;
Chris@739 115 EffectWrapper &operator=(const EffectWrapper &)=delete;
Chris@739 116 };
Chris@739 117
Chris@739 118 #endif
Chris@739 119
Chris@739 120