Hi!,
Pau suggest me to try to keep some order on sources and sinks within the
players. Now are using a map, so the order is unpredictable...
The idea is to use the geometry positions on canvas(upper is first)... but
the problem is that actually the only who knows that is the canvas, and for
a while (on loading/pasting) the network, but not the OfflinePlayer...
So... here is a patch with the actual state of my sandbox. Still with debug
messages, and the players are not using the new ordered list..
I send to the list to ask if someone have a better idea to implement it.. If
not, later I will commit this (without the messages), and then I'll use
that on the players..
Best regards,
Natanael.
Index: NetworkEditor/src/MainWindow.hxx
===================================================================
--- NetworkEditor/src/MainWindow.hxx (revision 12483)
+++ NetworkEditor/src/MainWindow.hxx (working copy)
@@ -428,6 +428,7 @@
).arg(_network.GetUnconnectedInPorts().c_str()));
return;
}
+ _canvas->orderSinksAndSources();
_network.Start();
updatePlayStatusIndicator();
}
Index: NetworkEditor/src/NetworkCanvas.hxx
===================================================================
--- NetworkEditor/src/NetworkCanvas.hxx (revision 12483)
+++ NetworkEditor/src/NetworkCanvas.hxx (working copy)
@@ -1405,6 +1405,23 @@
}
}
+ void orderSinksAndSources()
+ {
+ CLAM::BaseNetwork::ProcessingsGeometriesMap processingsGeometriesMap;
+ for (unsigned i=0; i<_processings.size(); i++)
+ {
+ CLAM::BaseNetwork::Geometry processingGeometry;
+ QPoint position = _processings[i]->pos();
+ QSize size = _processings[i]->size();
+ const std::string name=_processings[i]->getName().toStdString();
+ processingGeometry.x=position.x();
+ processingGeometry.y=position.y();
+ processingGeometry.width=size.width();
+ processingGeometry.height=size.height();
+ processingsGeometriesMap.insert(CLAM::BaseNetwork::ProcessingsGeometriesMap::value_type(name,processingGeometry));
+ }
+ _network->OrderSinksAndSources(processingsGeometriesMap);
+ }
bool updateGeometriesOnXML(QPoint offsetPoint=QPoint(0,0))
{
CLAM::BaseNetwork::ProcessingsGeometriesMap processingsGeometriesMap;
Index: CLAM/src/Flow/Networks/FlattenedNetwork.cxx
===================================================================
--- CLAM/src/Flow/Networks/FlattenedNetwork.cxx (revision 12483)
+++ CLAM/src/Flow/Networks/FlattenedNetwork.cxx (working copy)
@@ -32,7 +32,6 @@
# include "ProcessingFactory.hxx"
#endif
#include "CLAMVersion.hxx"
-
namespace CLAM
{
FlattenedNetwork::FlattenedNetwork() :
@@ -148,8 +147,9 @@
void FlattenedNetwork::LoadFrom( Storage & storage)
{
- typedef std::map <std::string, std::string> changeProcNames;
- changeProcNames newProcNames;
+std::cout<<"loadfrom"<<std::endl;
+ typedef std::map <std::string, std::string> NamesMap;
+ NamesMap namesMap;
if (!_setPasteMode) Clear();
XMLAdapter<std::string> strAdapter( _name, "id");
storage.Load(strAdapter);
@@ -159,28 +159,24 @@
{
ProcessingDefinitionAdapter procDefinition;
XMLComponentAdapter xmlAdapter(procDefinition, "processing", true);
- if(storage.Load(xmlAdapter) == false) break;
- std::string name=procDefinition.GetName();
-
- if (!_setPasteMode)
- AddProcessing(name, procDefinition.GetProcessing());
- else
+ if (not storage.Load(xmlAdapter)) break;
+
+ const std::string & definitionName = procDefinition.GetName();
+ CLAM::Processing * processing = procDefinition.GetProcessing();
+ std::string finalName = definitionName;
+ if (_setPasteMode)
{
- std::string newName = GetUnusedName(name,true);
- CLAM::Processing * processing =procDefinition.GetProcessing();
-// std::string key=processing->GetClassName();
-// std::string newName= AddProcessing(key);
- AddProcessing(newName,processing);
- newProcNames.insert(changeProcNames::value_type(name,newName));
- name=newName;
+ finalName = GetUnusedName(definitionName, true);
+ namesMap.insert(std::make_pair(definitionName,finalName));
}
+ AddProcessing(finalName, processing);
// if exists canvas geometries, restore them
if (procDefinition.GetPosition()!="" && procDefinition.GetSize()!="")
{
- Geometry processingGeometry;
- StringPairToInts(procDefinition.GetPosition(),processingGeometry.x,processingGeometry.y);
- StringPairToInts(procDefinition.GetSize(),processingGeometry.width,processingGeometry.height);
- _processingsGeometries.insert(ProcessingsGeometriesMap::value_type(name,processingGeometry));
+ Geometry geometry;
+ StringPairToInts(procDefinition.GetPosition(),geometry.x,geometry.y);
+ StringPairToInts(procDefinition.GetSize(),geometry.width,geometry.height);
+ _processingsGeometries.insert(ProcessingsGeometriesMap::value_type(finalName,geometry));
}
}
@@ -188,24 +184,18 @@
{
ConnectionDefinitionAdapter connectionDefinition;
XMLComponentAdapter xmlAdapter(connectionDefinition, "port_connection", true);
- if (!storage.Load(xmlAdapter)) break;
- const std::string & fullOut = connectionDefinition.GetOutName();
- const std::string & fullIn = connectionDefinition.GetInName();
- try
+ if (not storage.Load(xmlAdapter)) break;
+ std::string fullOut = connectionDefinition.GetOutName();
+ std::string fullIn = connectionDefinition.GetInName();
+ if (_setPasteMode)
{
- if (!_setPasteMode)
- ConnectPorts( fullOut, fullIn );
- else
- {
- const std::string newNameOut = newProcNames.find(GetProcessingIdentifier(fullOut))->second
- +"."+GetConnectorIdentifier(fullOut);
- const std::string newNameIn = newProcNames.find(GetProcessingIdentifier(fullIn))->second
- +"."+GetConnectorIdentifier(fullIn);
- ConnectPorts( newNameOut, newNameIn );
- }
-
+ fullOut = namesMap.find(GetProcessingIdentifier(fullOut))->second
+ +"."+GetConnectorIdentifier(fullOut);
+ fullIn = namesMap.find(GetProcessingIdentifier(fullIn))->second
+ +"."+GetConnectorIdentifier(fullIn);
}
- catch (Err & e) { throw XmlStorageErr(e.what()); }
+ if (not ConnectPorts( fullOut, fullIn ))
+ throw XmlStorageErr(std::string("Unable to connect ports '")+fullOut+"->"+fullIn+".");
}
while(1)
@@ -213,24 +203,20 @@
ConnectionDefinitionAdapter connectionDefinition;
XMLComponentAdapter xmlAdapter(connectionDefinition, "control_connection", true);
if (!storage.Load(xmlAdapter)) break;
- const std::string & fullOut = connectionDefinition.GetOutName();
- const std::string & fullIn = connectionDefinition.GetInName();
- try
+ std::string fullOut = connectionDefinition.GetOutName();
+ std::string fullIn = connectionDefinition.GetInName();
+ if (_setPasteMode)
{
- if (!_setPasteMode)
- ConnectControls( fullOut, fullIn );
- else
- {
- const std::string newNameOut = newProcNames.find(GetProcessingIdentifier(fullOut))->second
- +"."+GetConnectorIdentifier(fullOut);
- const std::string newNameIn = newProcNames.find(GetProcessingIdentifier(fullIn))->second
- +"."+GetConnectorIdentifier(fullIn);
- ConnectControls( newNameOut, newNameIn );
- }
+ fullOut = namesMap.find(GetProcessingIdentifier(fullOut))->second
+ +"."+GetConnectorIdentifier(fullOut);
+ fullIn = namesMap.find(GetProcessingIdentifier(fullIn))->second
+ +"."+GetConnectorIdentifier(fullIn);
}
- catch (Err & e) { throw XmlStorageErr(e.what()); }
+ if (not ConnectControls( fullOut, fullIn ))
+ throw XmlStorageErr(std::string("Unable to connect controls '")+fullOut+"->"+fullIn+".");
}
_setPasteMode=false;
+ OrderSinksAndSources(_processingsGeometries);
}
bool FlattenedNetwork::UpdateSelections (const NamesList & processingsNamesList)
@@ -254,16 +240,32 @@
return true;
}
+
+ const std::list<std::string> FlattenedNetwork::getOrderedSinks() const
+ {
+/* std::list<std::string>::const_iterator it;
+ ProccessingsMap sinksMap;
+ for (it=_orderedSinks.begin();it!=_orderedSinks.end();it++)
+ {
+ sinksMap.insert(_processings.find(it));
+ }
+ return sinksMap;*/
+ return _orderedSinks;
+ }
+ const std::list<std::string> FlattenedNetwork::getOrderedSources() const
+ {
+ return _orderedSources;
+ }
+
bool FlattenedNetwork::SetProcessingsGeometries (const ProcessingsGeometriesMap & processingsGeometries)
{
- _processingsGeometries.clear();
+ _processingsGeometries.clear();
if (processingsGeometries.empty())
return true;
_processingsGeometries=processingsGeometries;
return false;
}
-
const FlattenedNetwork::ProcessingsGeometriesMap FlattenedNetwork::GetAndClearGeometries()
{
const ProcessingsGeometriesMap copyProcessingsGeometry(_processingsGeometries);
@@ -271,6 +273,63 @@
return copyProcessingsGeometry;
}
+
+ const bool FlattenedNetwork::compareGeometriesUpperThan (GeometryWithProcessingName & processingWithGeometry1, GeometryWithProcessingName & processingWithGeometry2)
+ {
+ if (processingWithGeometry1.geometry.y<processingWithGeometry2.geometry.y)
+ return true;
+ return false;
+ }
+
+ void FlattenedNetwork::OrderSinksAndSources (const ProcessingsGeometriesMap & processingsGeometries)
+ {
+std::cout<<"network::ordersinksandsources"<<std::endl;
+std::cout<<processingsGeometries.size()<<std::endl;
+std::cout<<_processings.size()<<std::endl;
+ _orderedSinks.clear();
+ _orderedSources.clear();
+ std::list <GeometryWithProcessingName> sinksGeometriesWithNames,sourcesGeometriesWithNames;
+ ProcessingsGeometriesMap::const_iterator it;
+ for (it=processingsGeometries.begin();it!=processingsGeometries.end();it++)
+ {
+ ProcessingsMap::const_iterator itProcessing=_processings.find(it->first);
+ if (itProcessing==_processings.end())
+ continue;
+ const std::string className=itProcessing->second->GetClassName();
+ if (className!="AudioSink" and className!="AudioSource")
+ continue;
+ GeometryWithProcessingName processingWithGeometry;
+ processingWithGeometry.processingName=it->first;
+ processingWithGeometry.geometry=it->second;
+ if (className=="AudioSink")
+ sinksGeometriesWithNames.push_back(processingWithGeometry);
+ if (className=="AudioSource")
+ sourcesGeometriesWithNames.push_back(processingWithGeometry);
+ }
+ if (sinksGeometriesWithNames.size()!=0)
+ {
+std::cout<<"ordering sinks..."<<std::endl;
+ sinksGeometriesWithNames.sort(compareGeometriesUpperThan);
+ for (std::list<GeometryWithProcessingName>::const_iterator it=sinksGeometriesWithNames.begin();
+ it!=sinksGeometriesWithNames.end();it++)
+ {
+std::cout<<"\t"<<(*it).processingName<<std::endl;
+ _orderedSinks.push_back((*it).processingName);
+ }
+
+ }
+ if (sourcesGeometriesWithNames.size()!=0)
+ {
+std::cout<<"ordering sources..."<<std::endl;
+ sourcesGeometriesWithNames.sort(compareGeometriesUpperThan);
+ for (std::list<GeometryWithProcessingName>::const_iterator it=sourcesGeometriesWithNames.begin();
+ it!=sourcesGeometriesWithNames.end();it++)
+ {
+std::cout<<"\t"<<(*it).processingName<<std::endl;
+ _orderedSources.push_back((*it).processingName);
+ }
+ }
+ }
/* // TODO: use individual geometries loadings/storings??:
const FlattenedNetwork::Geometry FlattenedNetwork::GetAndEraseGeometry(std::string name)
{
@@ -555,16 +614,23 @@
void FlattenedNetwork::Start()
{
+std::cout<<"FlattenedNetwork::Start"<<std::endl;
ProcessingsMap::iterator it;
for (it=BeginProcessings(); it!=EndProcessings(); it++)
{
- if (it->second->IsRunning()) continue;
+ if (it->second->IsRunning())
+{
+std::cout<<"\tIS RUNNING!"<<std::endl;
+ continue;
+}
if (it->second->IsConfigured())
{
+std::cout<<"\tIS CONFIGURED!"<<std::endl;
it->second->Start();
}
else
{
+std::cout<<"\tELSE!"<<std::endl;
std::cerr << "Warning: could not start processing for not being Configured: '" << it->first<< "' of class " << it->second->GetClassName() << std::endl;
}
}
Index: CLAM/src/Flow/Networks/FlattenedNetwork.hxx
===================================================================
--- CLAM/src/Flow/Networks/FlattenedNetwork.hxx (revision 12483)
+++ CLAM/src/Flow/Networks/FlattenedNetwork.hxx (working copy)
@@ -21,6 +21,8 @@
+
+
#ifndef _FlattenedNetwork_hxx_
#define _FlattenedNetwork_hxx_
@@ -37,7 +39,6 @@
//#include "Component.hxx"
//#include "Storage.hxx"
#include "BaseNetwork.hxx"
-
namespace CLAM
{
class NetworkPlayer;
@@ -88,6 +89,13 @@
bool SetProcessingsGeometries (const ProcessingsGeometriesMap & processingsGeometries);
const ProcessingsGeometriesMap GetAndClearGeometries();
+ //! sources and sink order
+ const std::list<std::string> getOrderedSinks() const;
+ const std::list<std::string> getOrderedSources() const;
+ void OrderSinksAndSources(const ProcessingsGeometriesMap &);
+ static const bool compareGeometriesUpperThan(GeometryWithProcessingName &,GeometryWithProcessingName &);
+
+
/*// TODO: make individual geometries loadings/storings??
const Geometry GetAndEraseGeometry(std::string name);*/
//! methods related to connect/disconnect interface
@@ -184,7 +192,11 @@
mutable ProcessingsGeometriesMap _processingsGeometries;
void StringPairToInts(const std::string & geometryInString, int & a, int & b);
const std::string IntsToString (const int & a, const int & b) const;
+
+ std::list <std::string> _orderedSinks;
+ std::list <std::string> _orderedSources;
+
};
}// namespace
Index: CLAM/src/Flow/Networks/BaseNetwork.hxx
===================================================================
--- CLAM/src/Flow/Networks/BaseNetwork.hxx (revision 12483)
+++ CLAM/src/Flow/Networks/BaseNetwork.hxx (working copy)
@@ -44,6 +44,7 @@
typedef std::list<InPortBase *> InPortsList;
typedef struct { int x, y, width, height; } Geometry;
+ typedef struct { std::string processingName; Geometry geometry; } GeometryWithProcessingName;
typedef std::map <std::string, Geometry> ProcessingsGeometriesMap;
typedef struct { std::string sourceName, sinkName; } Connection;
typedef std::list<Connection> ConnectionsList;
@@ -136,6 +137,13 @@
// canvas related geometries
virtual bool SetProcessingsGeometries (const ProcessingsGeometriesMap & processingsGeometries) = 0;
virtual const ProcessingsGeometriesMap GetAndClearGeometries() = 0;
+
+ virtual const std::list<std::string> getOrderedSinks() const = 0;
+ virtual const std::list<std::string> getOrderedSources() const = 0;
+ virtual void OrderSinksAndSources(const ProcessingsGeometriesMap &) = 0;
+
+
+
/*// TODO: make individual geometries loadings/storings??
const Geometry GetAndEraseGeometry(std::string name);*/
Index: CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx (revision 12483)
+++ CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx (working copy)
@@ -83,17 +83,22 @@
void JACKNetworkPlayer::RegisterPorts()
{
+std::cout<<"JACKNetworkPlayer::RegisterPorts"<<std::endl;
RegisterInputPorts( GetNetwork() );
RegisterOutputPorts( GetNetwork() );
}
void JACKNetworkPlayer::RegisterInputPorts(const Network& net)
{
+std::cout<<"JACKNetworkPlayer::RegisterInputPorts"<<std::endl;
CLAM_ASSERT( _sourceJackBindings.empty(),
"JACKNetworkPlayer::RegisterInputPorts() : there are already registered input ports");
-
+ net.getOrderedSources();
+
+
SourceJackBinding pair;
+
//Get them from the Network and add it to local list
for (Network::ProcessingsMap::const_iterator it=net.BeginProcessings(); it!=net.EndProcessings(); it++)
{
@@ -117,10 +122,12 @@
void JACKNetworkPlayer::RegisterOutputPorts(const Network& net)
{
+std::cout<<"JACKNetworkPlayer::RegisterOutputPorts"<<std::endl;
CLAM_ASSERT( _sinkJackBindings.empty(),
- "JACKNetworkPlayer::RegisterOutputPorts() : there are already registered output ports");
-
+ "JACKNetworkPlayer::RegisterOutputPorts() : there are already registered output ports");
+
SinkJackBinding pair;
+ net.getOrderedSinks();
//Get them from the Network and add it to local list
for (Network::ProcessingsMap::const_iterator it=net.BeginProcessings(); it!=net.EndProcessings(); it++)
@@ -202,6 +209,7 @@
void JACKNetworkPlayer::Start()
{
+std::cout<<"JACKNetworkPlayer::Start"<<std::endl;
if (IsPlaying()) return;
if (IsPaused())
{
_______________________________________________
Clam-devel mailing list
[email protected]
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel