LadspaProcessingExporter.cxx

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 #include <cstdlib>
00023 #include <cstring>
00024 
00025 #include "LadspaProcessingExporter.hxx"
00026 
00027 // LADSPA call backs
00028 extern "C"
00029 {
00030 
00031 static LADSPA_Handle Instantiate(const struct _LADSPA_Descriptor * descriptor,  unsigned long sampleRate)
00032 {
00033         std::string className = std::string(descriptor->Name).substr(5);
00034         CLAM::Hidden::ProcessingClass2LadspaBase * adapter =
00035                 new CLAM::Hidden::ProcessingClass2LadspaBase(className);
00036         adapter->Instantiate();
00037         return adapter;
00038 }
00039 
00040 static void ConnectPort(LADSPA_Handle instance, unsigned long port, LADSPA_Data * data)
00041 {
00042         CLAM::Hidden::ProcessingClass2LadspaBase * adapter = (CLAM::Hidden::ProcessingClass2LadspaBase*)instance;
00043         adapter->ConnectPort(port, data);
00044 }
00045 
00046 static void Activate(LADSPA_Handle instance)
00047 {
00048         CLAM::Hidden::ProcessingClass2LadspaBase* adapter = (CLAM::Hidden::ProcessingClass2LadspaBase*)instance;
00049         adapter->Activate();
00050 }
00051   
00052 static void Run(LADSPA_Handle instance, unsigned long sampleCount)
00053 {
00054         CLAM::Hidden::ProcessingClass2LadspaBase * adapter = (CLAM::Hidden::ProcessingClass2LadspaBase*)instance;
00055         adapter->Run(sampleCount);
00056 }
00057 
00058 static void Deactivate(LADSPA_Handle instance)
00059 {
00060         CLAM::Hidden::ProcessingClass2LadspaBase * adapter = (CLAM::Hidden::ProcessingClass2LadspaBase*)instance;
00061         adapter->Deactivate();
00062 }
00063 
00064 static void CleanUp(LADSPA_Handle instance)
00065 {
00066         CLAM::Hidden::ProcessingClass2LadspaBase * adapter = (CLAM::Hidden::ProcessingClass2LadspaBase*)instance;
00067         delete adapter;
00068 }
00069 }
00070 
00071 namespace CLAM
00072 {
00073 namespace Hidden
00074 {
00075 
00076 LADSPA_Descriptor * ProcessingClass2LadspaBase::CreateDescriptor(unsigned long id,
00077         const std::string & maker, const std::string & copyright)
00078 {
00079         LADSPA_Descriptor * descriptor = new LADSPA_Descriptor;
00080         std::string className = _proc->GetClassName();
00081         descriptor->UniqueID  = id;
00082         descriptor->Label = LadspaLibrary::dupstr(("CLAM_"+className).c_str());
00083         descriptor->Name = LadspaLibrary::dupstr(("CLAM "+className).c_str());
00084         descriptor->Maker = LadspaLibrary::dupstr(maker.c_str());
00085         descriptor->Copyright = LadspaLibrary::dupstr(copyright.c_str());
00086         descriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE; //?
00087         descriptor->PortCount = NPorts();
00088 
00089         descriptor->instantiate  = ::Instantiate;
00090         descriptor->connect_port = ::ConnectPort;
00091         descriptor->activate = ::Activate;
00092         descriptor->run = ::Run;
00093         descriptor->run_adding = 0;
00094         descriptor->set_run_adding_gain = 0;
00095         descriptor->deactivate = ::Deactivate;
00096         descriptor->cleanup = ::CleanUp;
00097 
00098         SetPortsAndControls(descriptor);
00099 
00100         return descriptor;
00101 }
00102 
00103 void ProcessingClass2LadspaBase::SetPortsAndControls(LADSPA_Descriptor *& descriptor)
00104 {
00105         LADSPA_PortDescriptor *& portDescriptors = const_cast<LADSPA_PortDescriptor*&>(descriptor->PortDescriptors);
00106         const char **& portNames = const_cast<const char **&>(descriptor->PortNames);
00107         LADSPA_PortRangeHint *& portRangeHints = const_cast<LADSPA_PortRangeHint *&>(descriptor->PortRangeHints);
00108 
00109         typedef const char * ConstCharPtr;
00110         portNames = new ConstCharPtr[NPorts()];
00111         portDescriptors = new LADSPA_PortDescriptor[NPorts()];
00112         portRangeHints = new LADSPA_PortRangeHint[NPorts()];
00113 
00114         unsigned i=0;
00115         for(unsigned j=0; j<_nInControls; i++, j++)
00116         {
00117                 portDescriptors[i] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL; 
00118                 portNames[i] = LadspaLibrary::dupstr(GetInControlName(j));
00119                 portRangeHints[i].HintDescriptor = 0;
00120         }
00121 
00122         for(unsigned j=0; j<_nOutControls; i++, j++)
00123         {
00124                 portDescriptors[i] = LADSPA_PORT_OUTPUT | LADSPA_PORT_CONTROL; 
00125                 portNames[i] =  LadspaLibrary::dupstr(GetOutControlName(j));
00126                 portRangeHints[i].HintDescriptor = 0;
00127         }
00128         for(unsigned j=0; j<_nInPorts; i++, j++)
00129         {
00130                 portDescriptors[i] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO; 
00131                 portNames[i] =  LadspaLibrary::dupstr(GetInPortName(j));
00132                 portRangeHints[i].HintDescriptor = 0;
00133         }
00134         for(unsigned j=0; j<_nOutPorts; i++, j++)
00135         {
00136                 portDescriptors[i] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO; 
00137                 portNames[i] =  LadspaLibrary::dupstr(GetOutPortName(j));
00138                 portRangeHints[i].HintDescriptor = 0;
00139         }
00140 /*
00141         // pitch
00142         portRangeHints[0].HintDescriptor = (
00143                 LADSPA_HINT_BOUNDED_BELOW |
00144                 LADSPA_HINT_BOUNDED_ABOVE |
00145                 LADSPA_HINT_SAMPLE_RATE |
00146                 LADSPA_HINT_LOGARITHMIC |
00147                 LADSPA_HINT_DEFAULT_440);
00148         portRangeHints[0].LowerBound = 0;
00149         portRangeHints[0].UpperBound = 0.5;
00150            
00151         // amplitude
00152         portRangeHints[1].HintDescriptor = (
00153                 LADSPA_HINT_BOUNDED_BELOW | 
00154                 LADSPA_HINT_BOUNDED_ABOVE |
00155                 LADSPA_HINT_DEFAULT_1);
00156         portRangeHints[1].LowerBound = 0;
00157         portRangeHints[1].UpperBound = 1;
00158                         
00159         // audio output
00160         portRangeHints[2] = 0;
00161 */
00162 }
00163 
00164 void ProcessingClass2LadspaBase::DoControls()
00165 {
00166         for(unsigned i=0;i<_nInControls;i++)
00167                 SendFloatToInControl(*_proc, i,(CLAM::TData)*_incontrolBuffers[i]);
00168         // TODO: No output controls!
00169 }       
00170 
00171 void ProcessingClass2LadspaBase::SetPortSizes(int size)
00172 {               
00173         for(int i=0;i<_nInControls;i++)
00174         {
00175                 if(_proc->GetInPort(i).GetSize() == size ) continue;
00176                 _proc->GetInPort(i).SetSize( size );
00177                 mWrappersList[i]->SetSize( size );
00178         }
00179 
00180         for(int i=0;i<_nOutPorts;i++)
00181         {
00182                 if(_proc->GetOutPort(i).GetSize() == size ) continue;
00183                 _proc->GetOutPort(i).SetSize( size );
00184         }
00185 }
00186 
00187 void ProcessingClass2LadspaBase::DoProc(unsigned long nSamples)
00188 {
00189         for(int i=0;i<_nInPorts;i++)
00190         {
00191                 memcpy( &(mWrappersList[i]->GetData()), _inportBuffers[i], nSamples*sizeof(CLAM::TData) );
00192                 mWrappersList[i]->Produce();
00193         }
00194 
00195         std::vector<CLAM::TData*> dataList(_nOutPorts);
00196         for(int i=0;i<_nOutPorts;i++)
00197         {
00198                 CLAM::OutPortBase & port = _proc->GetOutPort(i);
00199                 CLAM::AudioOutPort & audioPort = dynamic_cast<CLAM::AudioOutPort&>(port);
00200                 dataList[i] = &(audioPort.GetData());
00201         }
00202 
00203         _proc->Do();
00204 
00205         for(int i=0; i<_nOutControls; i++)
00206                 memcpy(_outcontrolBuffers[i], dataList[i], nSamples*sizeof(CLAM::TData) );              
00207 }
00208 
00209 
00210 
00211 const char * ProcessingClass2LadspaBase::GetInControlName(int id) const
00212 {
00213         return _proc->GetInControl(id).GetName().c_str();
00214 }
00215 const char * ProcessingClass2LadspaBase::GetOutControlName(int id) const
00216 {
00217         return _proc->GetOutControl(id).GetName().c_str();
00218 }
00219 const char * ProcessingClass2LadspaBase::GetInPortName(int id) const
00220 {
00221         return _proc->GetInPort(id).GetName().c_str();
00222 }
00223 const char * ProcessingClass2LadspaBase::GetOutPortName(int id) const
00224 {
00225         return _proc->GetOutPort(id).GetName().c_str();
00226 }
00227 
00228 }
00229 }
00230 
Generated by  doxygen 1.6.3