LadspaProcessingExporter.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef LadspaProcessingExporter_hxx
00023 #define LadspaProcessingExporter_hxx
00024
00025 #include "Audio.hxx"
00026 #include "AudioOutPort.hxx"
00027 #include "AudioInPort.hxx"
00028 #include "OutControl.hxx"
00029 #include "Processing.hxx"
00030 #include "ProcessingFactory.hxx"
00031 #include "LadspaLibrary.hxx"
00032
00033 namespace CLAM
00034 {
00035 namespace Hidden
00036 {
00037 class ProcessingClass2LadspaBase
00038 {
00039 std::vector<LADSPA_Data *> _portBuffers;
00040 LADSPA_Data ** _outportBuffers;
00041 LADSPA_Data ** _inportBuffers;
00042 LADSPA_Data ** _incontrolBuffers;
00043 LADSPA_Data ** _outcontrolBuffers;
00044 std::vector<AudioOutPort*> mWrappersList;
00045 unsigned _nInPorts;
00046 unsigned _nOutPorts;
00047 unsigned _nInControls;
00048 unsigned _nOutControls;
00049 private:
00050 Processing * _proc;
00051 public:
00052
00053
00054 ProcessingClass2LadspaBase(CLAM::Processing * processing)
00055 : _proc(0)
00056 {
00057 SetProcessing(processing);
00058 }
00059 ProcessingClass2LadspaBase(const std::string & className)
00060 : _proc(0)
00061 {
00062 SetProcessing(ProcessingFactory::GetInstance().Create(className));
00063 }
00064 void Instantiate()
00065 {
00066 _portBuffers.resize(NPorts());
00067
00068 _incontrolBuffers = &(_portBuffers[0]);
00069 _outcontrolBuffers = _incontrolBuffers + _nInControls;
00070 _inportBuffers = _outcontrolBuffers + _nOutControls;
00071 _outportBuffers = _inportBuffers + _nInPorts;
00072
00073 mWrappersList.resize(_nInPorts);
00074 for (unsigned i=0; i<mWrappersList.size(); i++)
00075 {
00076 mWrappersList[i] = new AudioOutPort("out", 0 );
00077 mWrappersList[i]->ConnectToIn( _proc->GetInPort(i) );
00078 }
00079 }
00080
00081 void Activate()
00082 {
00083 _proc->Start();
00084 }
00085 void ConnectPort(unsigned long port, LADSPA_Data * data)
00086 {
00087 _portBuffers[port] = data;
00088 }
00089 void Run(unsigned long sampleCount)
00090 {
00091 DoControls();
00092 SetPortSizes(sampleCount);
00093 DoProc(sampleCount);
00094 }
00095 void Deactivate()
00096 {
00097 _proc->Stop();
00098 }
00099
00100
00101 ~ProcessingClass2LadspaBase()
00102 {
00103 for (unsigned i=0; i<mWrappersList.size(); i++)
00104 delete mWrappersList[i];
00105 SetProcessing(0);
00106 }
00107
00108 private:
00109 void DoProc(unsigned long nSamples);
00110 void DoControls();
00111 void SetPortSizes(int size);
00112
00113
00114
00115 public:
00116 LADSPA_Descriptor * CreateDescriptor(unsigned long id,
00117 const std::string & maker, const std::string & copyright);
00118 private:
00119 void SetPortsAndControls(LADSPA_Descriptor *& descriptor);
00120
00121
00122 private:
00123 void SetProcessing(Processing * processing)
00124 {
00125 if (_proc) delete _proc;
00126 _proc = processing;
00127 _nInPorts = _proc?_proc->GetNInPorts():0;
00128 _nOutPorts = _proc?_proc->GetNOutPorts():0;
00129 _nInControls = _proc?_proc->GetNInControls():0;
00130 _nOutControls = _proc?_proc->GetNOutControls():0;
00131 }
00132
00133 const char * GetInControlName(int id) const;
00134 const char * GetOutControlName(int id) const;
00135 const char * GetInPortName(int id) const;
00136 const char * GetOutPortName(int id) const;
00137
00138 unsigned NPorts() const
00139 {
00140 return _nInPorts + _nOutPorts + _nInControls + _nOutControls;
00141 }
00142
00143 };
00144 }
00145
00146 template <typename ProcessingType>
00147 class LadspaProcessingExporter
00148 {
00149 public:
00150 LadspaProcessingExporter(LadspaLibrary & library, unsigned long id,
00151 const std::string & maker, const std::string & copyright)
00152 {
00153 Hidden::ProcessingClass2LadspaBase adapter(new ProcessingType);
00154 LADSPA_Descriptor * descriptor = adapter.CreateDescriptor(id,maker,copyright);
00155 library.AddPluginType(descriptor);
00156 }
00157 };
00158
00159 }
00160
00161
00162 #endif//LadspaProcessingExporter_hxx
00163