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