annotate plugin/LADSPAPluginInstance.h @ 14:b101cc2ae1ab

* Introduce potentially-separate read and write ring buffers, so we can swap in a new set when something changes -- thus allowing us to respond quickly when something changes during playback, without losing the long buffers * Some fixes for display & editing
author Chris Cannam
date Fri, 27 Jan 2006 18:04:07 +0000
parents d86891498eef
children 2fb933f88604
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@2 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 /*
Chris@0 11 This is a modified version of a source file from the
Chris@0 12 Rosegarden MIDI and audio sequencer and notation editor.
Chris@0 13 This file copyright 2000-2005 Chris Cannam and Richard Bown.
Chris@0 14 */
Chris@0 15
Chris@0 16 #ifndef _LADSPAPLUGININSTANCE_H_
Chris@0 17 #define _LADSPAPLUGININSTANCE_H_
Chris@0 18
Chris@0 19 #include <vector>
Chris@0 20 #include <set>
Chris@0 21 #include <QString>
Chris@0 22
Chris@0 23 #include "api/ladspa.h"
Chris@0 24 #include "RealTimePluginInstance.h"
Chris@0 25
Chris@0 26 // LADSPA plugin instance. LADSPA is a variable block size API, but
Chris@0 27 // for one reason and another it's more convenient to use a fixed
Chris@0 28 // block size in this wrapper.
Chris@0 29 //
Chris@0 30 class LADSPAPluginInstance : public RealTimePluginInstance
Chris@0 31 {
Chris@0 32 public:
Chris@0 33 virtual ~LADSPAPluginInstance();
Chris@0 34
Chris@0 35 virtual bool isOK() const { return m_instanceHandles.size() != 0; }
Chris@0 36
Chris@0 37 int getClientId() const { return m_client; }
Chris@0 38 virtual QString getIdentifier() const { return m_identifier; }
Chris@0 39 int getPosition() const { return m_position; }
Chris@0 40
Chris@0 41 virtual void run(const RealTime &rt);
Chris@0 42
Chris@0 43 virtual unsigned int getParameterCount() const;
Chris@0 44 virtual void setParameterValue(unsigned int parameter, float value);
Chris@0 45 virtual float getParameterValue(unsigned int parameter) const;
Chris@0 46 virtual float getParameterDefault(unsigned int parameter) const;
Chris@0 47
Chris@0 48 virtual size_t getBufferSize() const { return m_blockSize; }
Chris@0 49 virtual size_t getAudioInputCount() const { return m_instanceCount * m_audioPortsIn.size(); }
Chris@0 50 virtual size_t getAudioOutputCount() const { return m_instanceCount * m_audioPortsOut.size(); }
Chris@0 51 virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; }
Chris@0 52 virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; }
Chris@0 53
Chris@0 54 virtual bool isBypassed() const { return m_bypassed; }
Chris@0 55 virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; }
Chris@0 56
Chris@0 57 virtual size_t getLatency();
Chris@0 58
Chris@0 59 virtual void silence();
Chris@0 60 virtual void setIdealChannelCount(size_t channels); // may re-instantiate
Chris@0 61
Chris@0 62 protected:
Chris@0 63 // To be constructed only by LADSPAPluginFactory
Chris@0 64 friend class LADSPAPluginFactory;
Chris@0 65
Chris@0 66 // Constructor that creates the buffers internally
Chris@0 67 //
Chris@0 68 LADSPAPluginInstance(RealTimePluginFactory *factory,
Chris@0 69 int client,
Chris@0 70 QString identifier,
Chris@0 71 int position,
Chris@0 72 unsigned long sampleRate,
Chris@0 73 size_t blockSize,
Chris@0 74 int idealChannelCount,
Chris@0 75 const LADSPA_Descriptor* descriptor);
Chris@0 76
Chris@0 77 // Constructor that uses shared buffers
Chris@0 78 //
Chris@0 79 LADSPAPluginInstance(RealTimePluginFactory *factory,
Chris@0 80 int client,
Chris@0 81 QString identifier,
Chris@0 82 int position,
Chris@0 83 unsigned long sampleRate,
Chris@0 84 size_t blockSize,
Chris@0 85 sample_t **inputBuffers,
Chris@0 86 sample_t **outputBuffers,
Chris@0 87 const LADSPA_Descriptor* descriptor);
Chris@0 88
Chris@0 89 void init(int idealChannelCount = 0);
Chris@0 90 void instantiate(unsigned long sampleRate);
Chris@0 91 void cleanup();
Chris@0 92 void activate();
Chris@0 93 void deactivate();
Chris@0 94
Chris@0 95 // Connection of data (and behind the scenes control) ports
Chris@0 96 //
Chris@0 97 void connectPorts();
Chris@0 98
Chris@0 99 int m_client;
Chris@0 100 int m_position;
Chris@0 101 std::vector<LADSPA_Handle> m_instanceHandles;
Chris@0 102 size_t m_instanceCount;
Chris@0 103 const LADSPA_Descriptor *m_descriptor;
Chris@0 104
Chris@0 105 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsIn;
Chris@0 106 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsOut;
Chris@0 107
Chris@0 108 std::vector<int> m_audioPortsIn;
Chris@0 109 std::vector<int> m_audioPortsOut;
Chris@0 110
Chris@0 111 size_t m_blockSize;
Chris@0 112 sample_t **m_inputBuffers;
Chris@0 113 sample_t **m_outputBuffers;
Chris@0 114 bool m_ownBuffers;
Chris@0 115 size_t m_sampleRate;
Chris@0 116 float *m_latencyPort;
Chris@0 117 bool m_run;
Chris@0 118
Chris@0 119 bool m_bypassed;
Chris@0 120 };
Chris@0 121
Chris@0 122 #endif // _LADSPAPLUGININSTANCE_H_
Chris@0 123