1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#include "CLAMRemoteController.hxx"
unsigned int numports=4;
namespace CLAM
{
CLAMRemoteController::CLAMRemoteController()
{
CreateStructure();
ProcessPorts();
}
CLAMRemoteController::~CLAMRemoteController()
{
std::cerr << " DELETED" << std::endl;
for (LADSPAInControlList::iterator it=mInControlList.begin(); it!=mInControlList.end(); it++)
delete it->processing;
for (std::vector<OSCSender*>::iterator it=mSenderList.begin(); it!=mSenderList.end(); it++)
delete *it;
std::cerr << " DELETED OK!" << std::endl;
}
void CLAMRemoteController::CreateStructure()
{
std::cerr << " constructor" << std::endl;
std::string xmlfile="/home/xoliver/CLAM/build/Examples/CLAMRemoteController/remoteList.xml";
try
{
XmlStorage::Restore( mRemoteControlList, xmlfile);
}
catch ( XmlStorageErr err)
{
std::cerr << "CLAM::CLAMRemoteController WARNING: error opening configuration file <"
<< xmlfile << "> . Plugin not loaded" <<std::endl;
return;
}
LADSPAInfo<ExternInControl> info;
mLastValues=new TData[mRemoteControlList.GetList().size()];
int i=0;
for ( std::list<RemoteControlPair>::iterator it=mRemoteControlList.GetList().begin(); it!=mRemoteControlList.GetList().end(); it++)
{
//Create ExternInControl
info.name=it->GetName();
info.processing=new ExternInControl( it->GetControlConfig() );
mInControlList.push_back(info);
//Create OSCSender
mSenderList.push_back( new OSCSender( it->GetSenderConfig() ) );
mLastValues[i++]=0.0;
}
}
void CLAMRemoteController::ProcessPorts()
{
//Create the two input channels
mPortList[0].name="LeftIn";
mPortList[0].processing=NULL;
mPortList[1].name="RightIn";
mPortList[1].processing=NULL;
//Create the two output channels
mPortList[2].name="LeftOut";
mPortList[2].processing=NULL;
mPortList[3].name="RightOut";
mPortList[3].processing=NULL;
}
void CLAMRemoteController::FillPortInfo( LADSPA_PortDescriptor* descriptors, char** names, LADSPA_PortRangeHint* rangehints )
{
int currentport=0;
//Manage InPorts
descriptors[currentport] = (LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO);
names[currentport] = dupstr( mPortList[currentport].name.c_str() );
rangehints[currentport].HintDescriptor = 0;
currentport++;
descriptors[currentport] = (LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO);
names[currentport] = dupstr( mPortList[currentport].name.c_str() );
rangehints[currentport].HintDescriptor = 0;
currentport++;
//Manage OutPorts
descriptors[currentport] = (LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO);
names[currentport] = dupstr( mPortList[currentport].name.c_str() );
rangehints[currentport].HintDescriptor = 0;
currentport++;
descriptors[currentport] = (LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO);
names[currentport] = dupstr( mPortList[currentport].name.c_str() );
rangehints[currentport].HintDescriptor = 0;
currentport++;
//Manage InControls (ExternInControls)
for (LADSPAInControlList::iterator it=mInControlList.begin(); it!=mInControlList.end(); it++)
{
descriptors[currentport] = (LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL);
names[currentport] = dupstr( it->name.c_str() );
//Obt processingConfig, i defineix cada param
ExternInControlConfig& conf=const_cast<ExternInControlConfig&>(
dynamic_cast<const ExternInControlConfig&>(
it->processing->GetConfig() ));
rangehints[currentport].LowerBound=(LADSPA_Data)conf.GetMinValue();
rangehints[currentport].UpperBound=(LADSPA_Data)conf.GetMaxValue();
rangehints[currentport].HintDescriptor = (LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE);
currentport++;
}
}
void CLAMRemoteController::Run( unsigned long nsamples )
{
ProcessInControlValues();
CopyInPortsToOutputPorts(nsamples);
}
void CLAMRemoteController::CopyInPortsToOutputPorts( unsigned long nsamples )
{
for (unsigned long i=0; i<nsamples; i++)
{
//Simply copy input buffers to output ones
mPortList[2].dataBuffer[i]=mPortList[0].dataBuffer[i];
mPortList[3].dataBuffer[i]=mPortList[1].dataBuffer[i];
}
}
void CLAMRemoteController::ProcessInControlValues()
{
int i=0;
for (LADSPAInControlList::iterator it=mInControlList.begin(); it!=mInControlList.end(); it++)
{
if ( (TData) *(it->dataBuffer) != mLastValues[i] )
{
SendFloatToInControl(*(mSenderList.at(i)),"input",(TData) *(it->dataBuffer));
mLastValues[i]= (TData) *(it->dataBuffer);
}
i++;
}
}
void CLAMRemoteController::ConnectTo(unsigned long port, LADSPA_Data * data)
{
if ( port<numports )
mPortList[port].dataBuffer=data;
else //Input controls
mInControlList.at( port-numports ).dataBuffer=data;
}
} //end namespace CLAM
|