32 #ifdef USE_LADSPA //TODO alway include it. move conditional code in LFactory.hxx
47 _name(
"Unnamed Network"),
57 if (_flowControl)
delete _flowControl;
58 if (_player)
delete _player;
64 storage.
Store(strAdapter);
68 storage.
Store(versionAdapter);
70 if (not _description.empty())
73 storage.
Store(descriptionAdapter);
76 ProcessingsMap::const_iterator it;
80 const std::string & name = it->first;
81 if (!HasSelectionAndContains(name))
83 std::string processingPosition;
84 std::string processingSize;
86 if (!_processingsGeometries.empty())
88 Geometry & geometry=_processingsGeometries.find(name)->second;
89 processingPosition=IntsToString (geometry.
x, geometry.
y);
90 processingSize=IntsToString (geometry.
width, geometry.
height);
94 storage.
Store(xmlAdapter);
103 const std::string & name = it->first;
106 if (!HasSelectionAndContains(name))
110 for (
unsigned i = 0; i<nOutPorts; i++)
116 std::string outPortName = name +
"." + outport.
GetName();
118 NamesList::iterator namesIterator;
119 for(namesIterator=namesInPorts.begin();
120 namesIterator!=namesInPorts.end();
127 storage.
Store(xmlAdapter);
134 const std::string & name = it->first;
137 if (!HasSelectionAndContains(name))
141 for (
unsigned i = 0; i<nOutControls; i++)
144 std::string outControlName = name+
"." + outControl.
GetName();
146 NamesList::iterator namesIterator;
147 for(namesIterator=namesInControls.begin();
148 namesIterator!=namesInControls.end();
155 storage.
Store(xmlAdapter);
160 InformationTexts::const_iterator ibIt;
165 storage.
Store(xmlAdapter);
168 _selectedProcessings.clear();
169 _processingsGeometries.clear();
174 typedef std::map <std::string, std::string> NamesMap;
176 if (!_setPasteMode)
Clear();
178 storage.
Load(strAdapter);
179 _processingsGeometries.clear();
182 if(not storage.
Load(descriptionAdapter)) _description=
"";
188 if (not storage.
Load(xmlAdapter))
break;
190 const std::string & definitionName = procDefinition.
GetName();
192 std::string finalName = definitionName;
196 namesMap.insert(std::make_pair(definitionName,finalName));
203 StringPairToInts(procDefinition.
GetPosition(),geometry.
x,geometry.
y);
205 _processingsGeometries.insert(ProcessingsGeometriesMap::value_type(finalName,geometry));
213 if (not storage.
Load(xmlAdapter))
break;
214 std::string fullOut = connectionDefinition.
GetOutName();
215 std::string fullIn = connectionDefinition.
GetInName();
225 if (BrokenConnection(fullOut, fullIn))
230 throw XmlStorageErr(std::string(
"Unable to connect ports '")+fullOut+
"->"+fullIn+
".");
238 if (!storage.
Load(xmlAdapter))
break;
239 std::string fullOut = connectionDefinition.
GetOutName();
240 std::string fullIn = connectionDefinition.
GetInName();
249 throw XmlStorageErr(std::string(
"Unable to connect controls '")+fullOut+
"->"+fullIn+
".");
256 if (not storage.
Load(xmlAdapter))
break;
259 myInformationText->
x=infoTextDefinition.
GetCoordX();
260 myInformationText->
y=infoTextDefinition.
GetCoordY();
261 myInformationText->
text=infoTextDefinition.
GetText();
263 _informationTexts.push_back(myInformationText);
272 if (!_selectedProcessings.empty() || processingsNamesList.empty())
274 _selectedProcessings.clear();
277 NamesList::const_iterator namesIterator;
278 for (namesIterator=processingsNamesList.begin();namesIterator!=processingsNamesList.end();namesIterator++)
279 _selectedProcessings.insert(*namesIterator);
283 bool Network::HasSelectionAndContains(
const std::string & name)
const
285 NamesSet::const_iterator itFindSelected = _selectedProcessings.find(name);
286 if (!_selectedProcessings.empty() && itFindSelected==_selectedProcessings.end())
295 for (ProcessingsGeometriesMap::const_iterator it=_processingsGeometries.begin();it!=_processingsGeometries.end();it++)
300 Geometry nullGeometry={0,10000,0,0};
306 std::list <ProcessingAndGeometry> processingsAndGeometries;
308 for (ProcessingsMap::const_iterator it=_processings.begin(); it!=_processings.end(); it++)
317 processingsAndGeometries.push_back(item);
321 for (std::list<ProcessingAndGeometry>::const_iterator it=processingsAndGeometries.begin();
322 it!=processingsAndGeometries.end();it++)
324 orderedProcessings.push_back( it->processing );
327 return orderedProcessings;
332 std::list <ProcessingAndGeometry> processingsAndGeometries;
334 for (ProcessingsMap::const_iterator it=_processings.begin(); it!=_processings.end(); it++)
343 processingsAndGeometries.push_back(item);
347 for (std::list<ProcessingAndGeometry>::const_iterator it=processingsAndGeometries.begin();
348 it!=processingsAndGeometries.end();it++)
350 orderedProcessings.push_back( it->processing );
353 return orderedProcessings;
358 std::list <ProcessingAndGeometry> controlSinksAndGeometries;
360 for (ProcessingsMap::const_iterator it=_processings.begin(); it!=_processings.end(); it++)
364 if (className!=
"ControlSink")
369 controlSinksAndGeometries.push_back(item);
373 for (std::list<ProcessingAndGeometry>::const_iterator it=controlSinksAndGeometries.begin();
374 it!=controlSinksAndGeometries.end();it++)
378 orderedControlSinks.push_back( controlSink );
381 return orderedControlSinks;
386 std::list <ProcessingAndGeometry> controlSourcesAndGeometries;
388 for (ProcessingsMap::const_iterator it=_processings.begin(); it!=_processings.end(); it++)
392 if (className!=
"ControlSource")
397 controlSourcesAndGeometries.push_back(item);
401 for (std::list<ProcessingAndGeometry>::const_iterator it=controlSourcesAndGeometries.begin();
402 it!=controlSourcesAndGeometries.end();it++)
405 CLAM_ASSERT(controlSource,
"Expected an AudioSink");
406 orderedControlSources.push_back( controlSource );
409 return orderedControlSources;
414 _processingsGeometries.clear();
415 if (processingsGeometries.empty())
417 _processingsGeometries=processingsGeometries;
424 _processingsGeometries.clear();
425 return copyProcessingsGeometry;
453 void Network::StringPairToInts(
const std::string & geometryInString,
int & a,
int & b)
455 a=atoi(geometryInString.substr(0,geometryInString.find(
",")).c_str());
456 b=atoi(geometryInString.substr(geometryInString.find(
",")+1,geometryInString.length()).c_str());
459 const std::string Network::IntsToString (
const int & a,
const int & b)
const
461 std::ostringstream stream;
469 if (_flowControl)
delete _flowControl;
470 _flowControl = flowControl;
475 if (_player)
delete _player;
482 if (!_player)
return 512;
487 if (!_player)
return 44100;
495 (
"No processing in the network has the name '"+name+
"'.").c_str());
497 ProcessingsMap::const_iterator it = _processings.find( name );
505 if (!_processings.insert( ProcessingsMap::value_type( name, proc ) ).second )
506 CLAM_ASSERT(
false,
"Network::AddProcessing() Trying to add a processing with a repeated name (key)" );
527 std::string
Network::GetUnusedName(
const std::string& prefix,
const bool cutOnLastSeparator,
const std::string separator )
const
530 std::string newPrefix=prefix;
531 if (cutOnLastSeparator==
true)
533 int lastSeparatorPos=prefix.rfind(separator);
534 if (lastSeparatorPos!=-1)
535 newPrefix=prefix.substr(0,lastSeparatorPos);
538 for (
int i = 0; i<9999999; i++ )
540 std::stringstream tmp;
542 name = i? newPrefix + separator + tmp.str() : newPrefix;
545 CLAM_ASSERT(
false,
"All valid id's for given prefix are exhausted");
552 "Network::RemoveProcessing() - Network should have an attached flow control at this state.");
554 ProcessingsMap::const_iterator i = _processings.find( name );
555 if(i==_processings.end())
557 std::string msg(
"Network::RemoveProcessing() Trying to remove a processing that is not included in the network:");
563 _processings.erase( name );
571 ProcessingsMap::const_iterator i = _processings.find( name );
572 return i!=_processings.end();
577 ProcessingsMap::iterator it = _processings.find( name );
578 CLAM_ASSERT(it!=_processings.end(),
"Wrong processing name to configure in a network");
581 bool ok = proc->Configure( newConfig );
588 ProcessingsMap::iterator it;
589 for( it=_processings.begin(); it!=_processings.end(); it++)
631 outcontrol.
AddLink( incontrol );
731 ProcessingsMap::iterator it;
734 if (it->second->IsRunning())
738 if (it->second->IsConfigured())
744 std::cerr <<
"Warning: could not start processing for not being Configured: '"
745 << it->first<<
"' of class " << it->second->GetClassName() << std::endl;
754 if (_player) _player->
Stop();
755 ProcessingsMap::iterator it;
757 if (it->second->IsRunning())
762 if (_player) _player->
Pause();
774 while( !_processings.empty() )
779 for(
unsigned i=0;i<_informationTexts.size();i++)
783 _informationTexts.clear();
788 return _processings.begin();
793 return _processings.end();
797 return _processings.begin();
802 return _processings.end();
809 _informationTexts.push_back(informationText);
817 _informationTexts.erase(it);
819 std::cerr <<
"Warning: Information Text Box does not exist.";
824 return _informationTexts.begin();
829 return _informationTexts.end();
834 return _informationTexts.begin();
839 return _informationTexts.end();
851 OutPortBase::InPortsList::iterator it;
854 std::string completeName(
GetNetworkId((*it)->GetProcessing()));
856 completeName += (*it)->GetName();
857 consumers.push_back(completeName);
867 std::list<InControlBase*>::iterator it;
872 std::string completeName(
GetNetworkId((*it)->GetProcessing()));
874 completeName += (*it)->GetName();
875 consumers.push_back(completeName);
883 OutPortBase::InPortsList::iterator it;
885 consumers.push_back(*it);
891 ProcessingsMap::const_iterator it;
893 if(it->second == proc )
896 CLAM_ASSERT(
false,
"Trying to get a network id from a processing not present in it");
902 if (oldName==newName)
return true;
903 if( _processings.find( newName ) != _processings.end() )
905 ProcessingsMap::iterator it = _processings.find( oldName );
907 _processings.erase( it );
908 _processings.insert( ProcessingsMap::value_type( newName, proc ) );
922 return _processings.empty();
927 ProcessingsMap::const_iterator it;
929 if(!it->second->IsConfigured())
940 for (
unsigned i = 0; i<nInPorts; i++)
956 for (
unsigned i = 0; i<nInPorts; i++)
960 result+= it->first +
"." + inPort.
GetName() +
"\n";
968 ProcessingsMap::const_iterator it;
970 if(it->second->IsSyncSource())
977 ProcessingsMap::const_iterator it;
979 if(!it->second->SupportsVariableAudioSize())
987 std::ostringstream errorMessage;
988 ProcessingsMap::const_iterator it;
991 if(it->second->IsConfigured())
continue;
992 errorMessage <<
"* Processing '" << it->first <<
"' is misconfigured:\n";
993 errorMessage << it->second->GetConfigErrorMessage() << std::endl;
996 return errorMessage.str();
999 bool Network::BrokenConnection(
const std::string & producer,
const std::string & consumer )
1001 bool brokenConnection =
false;
1007 brokenConnection =
true;
1010 brokenConnection =
true;
1012 if (brokenConnection)
1013 _brokenConnections.push_back(producer +
" -> " + consumer);
1015 return brokenConnection;
1020 std::ostringstream os;
1021 std::copy(_brokenConnections.begin(), _brokenConnections.end(),
1022 std::ostream_iterator<std::string> (os,
"<br/> "));
1024 return std::make_pair(_brokenConnections.size() != 0, os.str());
1029 _brokenConnections.clear();