LadspaProcessingExporter.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Ladspa entry points
00053         // Instantiate
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         // CleanUp
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 // Pre instantiation interface
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 // Helper shortcuts
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 
Generated by  doxygen 1.6.3