CLAM-Development  1.4.0
LadspaProcessingExporter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef LadspaProcessingExporter_hxx
23 #define LadspaProcessingExporter_hxx
24 
25 #include "Audio.hxx"
26 #include "AudioOutPort.hxx"
27 #include "AudioInPort.hxx"
28 #include "OutControl.hxx"
29 #include "Processing.hxx"
30 #include "ProcessingFactory.hxx"
31 #include "LadspaLibrary.hxx"
32 
33 namespace CLAM
34 {
35 namespace Hidden
36 {
38 {
39  std::vector<LADSPA_Data *> _portBuffers;
40  LADSPA_Data ** _outportBuffers;
41  LADSPA_Data ** _inportBuffers;
42  LADSPA_Data ** _incontrolBuffers;
43  LADSPA_Data ** _outcontrolBuffers;
44  std::vector<AudioOutPort*> mWrappersList;
45  unsigned _nInPorts;
46  unsigned _nOutPorts;
47  unsigned _nInControls;
48  unsigned _nOutControls;
49 private:
50  Processing * _proc;
51 public:
52 // Ladspa entry points
53  // Instantiate
55  : _proc(0)
56  {
57  SetProcessing(processing);
58  }
59  ProcessingClass2LadspaBase(const std::string & className)
60  : _proc(0)
61  {
62  SetProcessing(ProcessingFactory::GetInstance().Create(className));
63  }
64  void Instantiate()
65  {
66  _portBuffers.resize(NPorts());
67 
68  _incontrolBuffers = &(_portBuffers[0]);
69  _outcontrolBuffers = _incontrolBuffers + _nInControls;
70  _inportBuffers = _outcontrolBuffers + _nOutControls;
71  _outportBuffers = _inportBuffers + _nInPorts;
72 
73  mWrappersList.resize(_nInPorts);
74  for (unsigned i=0; i<mWrappersList.size(); i++)
75  {
76  mWrappersList[i] = new AudioOutPort("out", 0 );
77  mWrappersList[i]->ConnectToIn( _proc->GetInPort(i) );
78  }
79  }
80 
81  void Activate()
82  {
83  _proc->Start();
84  }
85  void ConnectPort(unsigned long port, LADSPA_Data * data)
86  {
87  _portBuffers[port] = data;
88  }
89  void Run(unsigned long sampleCount)
90  {
91  DoControls();
92  SetPortSizes(sampleCount);
93  DoProc(sampleCount);
94  }
95  void Deactivate()
96  {
97  _proc->Stop();
98  }
99 
100  // CleanUp
102  {
103  for (unsigned i=0; i<mWrappersList.size(); i++)
104  delete mWrappersList[i];
105  SetProcessing(0);
106  }
107 
108 private:
109  void DoProc(unsigned long nSamples);
110  void DoControls();
111  void SetPortSizes(int size);
112 
113 
114 // Pre instantiation interface
115 public:
116  LADSPA_Descriptor * CreateDescriptor(unsigned long id,
117  const std::string & maker, const std::string & copyright);
118 private:
119  void SetPortsAndControls(LADSPA_Descriptor *& descriptor);
120 
121 // Helper shortcuts
122 private:
123  void SetProcessing(Processing * processing)
124  {
125  if (_proc) delete _proc;
126  _proc = processing;
127  _nInPorts = _proc?_proc->GetNInPorts():0;
128  _nOutPorts = _proc?_proc->GetNOutPorts():0;
129  _nInControls = _proc?_proc->GetNInControls():0;
130  _nOutControls = _proc?_proc->GetNOutControls():0;
131  }
132 
133  const char * GetInControlName(int id) const;
134  const char * GetOutControlName(int id) const;
135  const char * GetInPortName(int id) const;
136  const char * GetOutPortName(int id) const;
137 
138  unsigned NPorts() const
139  {
140  return _nInPorts + _nOutPorts + _nInControls + _nOutControls;
141  }
142 
143 };
144 }
145 
146 template <typename ProcessingType>
148 {
149 public:
150  LadspaProcessingExporter(LadspaLibrary & library, unsigned long id,
151  const std::string & maker, const std::string & copyright)
152  {
153  Hidden::ProcessingClass2LadspaBase adapter(new ProcessingType);
154  LADSPA_Descriptor * descriptor = adapter.CreateDescriptor(id,maker,copyright);
155  library.AddPluginType(descriptor);
156  }
157 };
158 
159 }
160 
161 
162 #endif//LadspaProcessingExporter_hxx
163