Hi,

Attached a patch to add references and const refs to avoid copying.

Dirk
Index: CLAM/src/Flow/Networks/NetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/NetworkPlayer.cxx	(revision 13271)
+++ CLAM/src/Flow/Networks/NetworkPlayer.cxx	(working copy)
@@ -28,13 +28,13 @@
 	{
 		std::string sourceNames;
 		std::string sinkNames;
-		Network & net = GetNetwork();
-		Network::AudioSources sources = GetAudioSources();
-		Network::AudioSinks sinks = GetAudioSinks();
-		for (Network::AudioSources::iterator it=sources.begin(); it!=sources.end(); it++)
+		Network const& net = GetNetwork();
+		Network::AudioSources const& sources = GetAudioSources();
+		Network::AudioSinks const& sinks = GetAudioSinks();
+		for (Network::AudioSources::const_iterator it=sources.begin(); it!=sources.end(); ++it)
 			sourceNames += " * source:\t"+net.GetNetworkId( *it )+"\n";
 
-		for (Network::AudioSinks::iterator it=sinks.begin(); it!=sinks.end(); it++)
+		for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); ++it)
 			sinkNames += " * sink:\t"+net.GetNetworkId( *it )+"\n";
 			
 
Index: CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx	(revision 13271)
+++ CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.cxx	(working copy)
@@ -89,7 +89,7 @@
 
 void JACKNetworkPlayer::RegisterInputPorts(const Network& net)
 {
-	Network::AudioSources sources=net.getOrderedSources();
+	Network::AudioSources const& sources = net.getOrderedSources();
 
 	CLAM_ASSERT( _sourceJackBindings.empty(),
 		"JACKNetworkPlayer::RegisterInputPorts() : there are already registered input ports");
@@ -99,7 +99,7 @@
 	{
 		std::string processingName = net.GetNetworkId(*it);
 
-		AudioSource::Ports ports = (*it)->GetPorts();
+		AudioSource::Ports const& ports = (*it)->GetPorts();
 		for(unsigned port = 0; port < ports.size(); ++port)
 		{
 				//Get Processing address
@@ -129,7 +129,7 @@
 
 void JACKNetworkPlayer::RegisterOutputPorts(const Network& net)
 {
-	Network::AudioSinks sinks=net.getOrderedSinks();
+	Network::AudioSinks const& sinks = net.getOrderedSinks();
 
 	CLAM_ASSERT( _sinkJackBindings.empty(),
 		"JACKNetworkPlayer::RegisterOutputPorts() : there are already registered output ports");	
@@ -138,7 +138,7 @@
 	{
 		std::string processingName = net.GetNetworkId( *it );
 
-		CLAM::AudioSink::Ports ports = (*it)->GetPorts();
+		AudioSink::Ports const& ports = (*it)->GetPorts();
 		for(unsigned port = 0; port < ports.size(); ++port)
 		{
 				//Get Processing address
Index: CLAM/src/Flow/Networks/BackEnds/MonoOfflineNetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/MonoOfflineNetworkPlayer.cxx	(revision 13271)
+++ CLAM/src/Flow/Networks/BackEnds/MonoOfflineNetworkPlayer.cxx	(working copy)
@@ -50,7 +50,7 @@
 		audioBuffers[fileIndex].SetSize( frameSize );
 		
 		AudioSource& source = *GetAudioSources()[fileIndex];
-		AudioSource::Ports ports = source.GetPorts();
+		AudioSource::Ports const& ports = source.GetPorts();
 		for(unsigned port = 0; port < ports.size(); ++port)
 			source.SetExternalBuffer( &(audioBuffers[fileIndex].GetBuffer()[0]) ,frameSize, port);
 
@@ -76,7 +76,7 @@
 		audioBuffers[fileIndex].SetSize( frameSize );
 
 		AudioSink& sink = *GetAudioSinks()[i];
-		AudioSink::Ports ports = sink.GetPorts();
+		AudioSink::Ports const& ports = sink.GetPorts();
 		for(unsigned port = 0; port < ports.size(); ++port)
 			sink.SetExternalBuffer( &(audioBuffers[fileIndex].GetBuffer()[0]) ,frameSize, port);
 
Index: CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.hxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.hxx	(revision 13271)
+++ CLAM/src/Flow/Networks/BackEnds/JACKNetworkPlayer.hxx	(working copy)
@@ -10,11 +10,13 @@
 
 namespace CLAM
 {
+
 class JACKNetworkPlayer : public NetworkPlayer
 {
 private:
 	//Structures to keep information about every external input and output processing
-	struct SourceJackBinding //TODO use mAudioSources/Sinks in the parent class instead.
+	//TODO use mAudioSources/Sinks in the parent class instead.
+	struct SourceJackBinding 
 	{
 		const char* PortName() 
 		{
@@ -64,7 +66,8 @@
 	std::string _jackClientName;
 
 private:
-        void AddSourceJackBinding(Network::AudioSources::const_iterator& it, std::string const& name, unsigned index);
+	void AddSourceJackBinding(Network::AudioSources::const_iterator& it, 
+							  std::string const& name, unsigned index);
 
 public:
 	JACKNetworkPlayer(const std::string & name="CLAM network player");
@@ -101,9 +104,9 @@
 	void StoreConnections();
 	void RestoreConnections();
 	
-	
 	void AutoConnectPorts();
 };
+
 } //namespace CLAM
 
 #endif
Index: CLAM/src/Flow/Networks/BackEnds/MonoOfflineNetworkPlayer.hxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/MonoOfflineNetworkPlayer.hxx	(revision 13271)
+++ CLAM/src/Flow/Networks/BackEnds/MonoOfflineNetworkPlayer.hxx	(working copy)
@@ -8,21 +8,21 @@
 namespace CLAM
 {
 
-
 class MonoOfflineNetworkPlayer : public NetworkPlayer
 {
 	std::vector<std::string> _filenames;
 	bool _enableLoopInputWavs;
 	float _resultWavsTime;
 
-
 public:
 	MonoOfflineNetworkPlayer()
 		: _enableLoopInputWavs(false)
 		, _resultWavsTime(0.0)
 	{}
+
 	void AddInputFile( const std::string& );
 	void AddOutputFile( const std::string& );
+
 	// base class (virtual) interface:
 	bool IsWorking();
 	std::string NonWorkingReason();
Index: CLAM/src/Flow/Networks/BackEnds/PANetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/PANetworkPlayer.cxx	(revision 13271)
+++ CLAM/src/Flow/Networks/BackEnds/PANetworkPlayer.cxx	(working copy)
@@ -94,22 +94,9 @@
 	if (CheckPaError(Pa_Initialize())) return;
 	displayPADevices();
 
-	int nInChannels = 0;
-	Network::AudioSources const& sources = GetAudioSources();
-    for (Network::AudioSources::const_iterator it=sources.begin(); it!=sources.end(); ++it)
-	{
-		AudioSource::Ports ports = (*it)->GetPorts();
-		nInChannels += ports.size();
-	}
+	int nInChannels = GetSourcesSize();
+	int nOutChannels = GetSinksSize();
 
-	int nOutChannels = 0;
-	Network::AudioSinks sinks = GetAudioSinks();
-	for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); it++)
-	{
-		AudioSink::Ports ports = (*it)->GetPorts();
-		nOutChannels += ports.size();
-	}
-
 	PaHostApiTypeId apiTryList[] = {
 		paDirectSound,
 		paMME, 
@@ -240,7 +227,6 @@
 	return mErrorMessage;
 }
 
-
 bool PANetworkPlayer::CheckPaError(PaError result)
 {
 	mError = result;
@@ -291,11 +277,11 @@
 void PANetworkPlayer::DoInPorts(float** input, unsigned long nframes)
 {
 	int i=0;
-	Network::AudioSources sources=GetAudioSources();
-	for ( Network::AudioSources::iterator it=sources.begin(); it!=sources.end(); it++ )
+	Network::AudioSources const& sources=GetAudioSources();
+	for ( Network::AudioSources::const_iterator it=sources.begin(); it!=sources.end(); it++ )
 	{
-		AudioSource::Ports ports = (*it)->GetPorts();
-		for (unsigned port = 0; port < ports.size(); ++port) 
+		unsigned ports_size = (*it)->GetPorts().size();
+		for (unsigned port = 0; port < ports_size; ++port) 
 			(*it)->SetExternalBuffer( input[i++], nframes, port);
 	}
 }
@@ -303,11 +289,11 @@
 void PANetworkPlayer::DoOutPorts(float** output, unsigned long nframes)
 {
 	int i=0;
-	Network::AudioSinks sinks=GetAudioSinks();
-	for (Network::AudioSinks::iterator it=sinks.begin(); it!=sinks.end(); it++)
+	Network::AudioSinks const& sinks=GetAudioSinks();
+	for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); it++)
 	{
-		AudioSink::Ports ports = (*it)->GetPorts();
-		for (unsigned port = 0; port < ports.size(); ++port) 
+		unsigned ports_size = (*it)->GetPorts().size();
+		for (unsigned port = 0; port < ports_size; ++port) 
 			(*it)->SetExternalBuffer(output[i++], nframes, port);
 	}
 }
@@ -316,12 +302,9 @@
 {
 	unsigned nSinks = 0;
 
-	Network::AudioSinks sinks = GetAudioSinks();
+	Network::AudioSinks const& sinks = GetAudioSinks();
 	for (Network::AudioSinks::const_iterator it=sinks.begin(); it!=sinks.end(); ++it)
-	{
-		CLAM::AudioSink::Ports ports = (*it)->GetPorts();
-		nSinks += ports.size();
-    } 
+		nSinks += (*it)->GetPorts().size();
 
 	for (unsigned i=0; i<nSinks; i++)
 		std::memset(output[i], 0, nframes*sizeof(float));
Index: CLAM/src/Flow/Networks/BackEnds/OfflineNetworkPlayer.cxx
===================================================================
--- CLAM/src/Flow/Networks/BackEnds/OfflineNetworkPlayer.cxx	(revision 13271)
+++ CLAM/src/Flow/Networks/BackEnds/OfflineNetworkPlayer.cxx	(working copy)
@@ -19,8 +19,10 @@
 std::string OfflineNetworkPlayer::NonWorkingReason()
 {
 	std::stringstream ss;
-	ss << GetSourcesSize() << " inputs and " << GetSinksSize() << " outputs needed but just " 
-	   << _inFileNames.size() << " input files provided" << _outFileNames.size() << " output files provided" 
+	ss << GetSourcesSize() << " inputs and " 
+	   << GetSinksSize() << " outputs needed but just " 
+	   << _inFileNames.size() << " input files provided" 
+	   << _outFileNames.size() << " output files provided" 
 	   << std::ends;
 	return ss.str();
 }
@@ -32,15 +34,15 @@
 	
 	Network & net = GetNetwork();
 	
-	Network::AudioSources sources = GetAudioSources();
+	Network::AudioSources const& sources = GetAudioSources();
 	unsigned inFileIndex = 0;
 	unsigned inChannel = 0;
 
-	for (Network::AudioSources::iterator it = sources.begin(); it != sources.end(); ++it)
+	for (Network::AudioSources::const_iterator it = sources.begin(); it != sources.end(); ++it)
 	{
 		std::string processingName = net.GetNetworkId(*it);
 
-		AudioSource::Ports ports = (*it)->GetPorts();
+		AudioSource::Ports const& ports = (*it)->GetPorts();
 		for(unsigned port = 0; port < ports.size(); ++port)
 		{
 			//Register port on the JACK server
@@ -63,15 +65,15 @@
 		}
 	}
 
-	Network::AudioSinks sinks = GetAudioSinks();
+	Network::AudioSinks const& sinks = GetAudioSinks();
 	unsigned outFileIndex = 0;
 	unsigned outChannel = 0;
 
-	for (Network::AudioSinks::iterator it = sinks.begin(); it != sinks.end(); ++it)
+	for (Network::AudioSinks::const_iterator it = sinks.begin(); it != sinks.end(); ++it)
 	{
 		std::string processingName = net.GetNetworkId( *it );
 
-		AudioSink::Ports ports = (*it)->GetPorts();
+		AudioSink::Ports const& ports = (*it)->GetPorts();
 		for(unsigned port = 0; port < ports.size(); ++port)
 		{
 			//Register port on the JACK server
@@ -105,6 +107,7 @@
 	BePlaying();
 
 	const int frameSize = 512;
+	
 	//Open the files, get the total number of channels and the sample rate
 	int sampleRate = 0; 
 	unsigned inputChannelsCount = 0;
@@ -193,7 +196,7 @@
 			inbuffers[sourceIndex].SetSize( frameSize );
 			AudioSource& source = *GetAudioSources()[sourceIndex];
 
-			AudioSource::Ports ports = source.GetPorts();
+			AudioSource::Ports const& ports = source.GetPorts();
 			for(unsigned port = 0; port < ports.size(); ++port)
 				source.SetExternalBuffer( &(inbuffers[sourceIndex][0]),frameSize, port);
 
@@ -230,7 +233,7 @@
 			outbuffers[sinkIndex].SetSize( frameSize );
 			AudioSink& sink = *GetAudioSinks()[sinkIndex];
 
-			AudioSink::Ports ports = sink.GetPorts();
+			AudioSink::Ports const& ports = sink.GetPorts();
 			for(unsigned port = 0; port < ports.size(); ++port)
 				sink.SetExternalBuffer(&(outbuffers[sinkIndex][0]), frameSize, port);
 
@@ -270,7 +273,7 @@
 			//Save the bufferReader into the sources' buffers.
 			for(int frameIndex=0; frameIndex <frameSize; frameIndex ++)
 			{	
-				for(int channel=0; channel < nChannels; channel++)
+				for(unsigned channel=0; channel < nChannels; channel++)
 				{
 					inbuffers[inAudioIndex+channel][frameIndex] = bufferReader[(frameIndex*nChannels)+channel];
 				}
@@ -327,6 +330,7 @@
 	if ( IsStopped() ) 
 		return;
 	BeStopped();
+
 	//TODO close files
 }
 
Index: CLAM/src/Flow/Networks/NetworkPlayer.hxx
===================================================================
--- CLAM/src/Flow/Networks/NetworkPlayer.hxx	(revision 13271)
+++ CLAM/src/Flow/Networks/NetworkPlayer.hxx	(working copy)
@@ -31,18 +31,14 @@
 
 namespace {
 
-template<typename Container, typename Audio>
+template<typename Container>
 unsigned GetSize(Container const& t)
 {
 	unsigned nrOfPorts = 0;
-
 	for (typename Container::const_iterator it = t.begin(); it != t.end(); ++it)
 	{
-		// contained type is not deductable
-		typename Audio::Ports ports = (*it)->GetPorts();
-		nrOfPorts += ports.size();
+		nrOfPorts += (*it)->GetPorts().size();
 	}
-
 	return nrOfPorts;
 }
 
@@ -62,9 +58,9 @@
 	enum Status { Playing=0, Stopped=1, Paused=2 };
 public:
 	NetworkPlayer()
+		: _network(NULL)
+		, _status(Stopped)
 	{
-		_status=Stopped;
-		_network=NULL;
 	}
 
 	virtual ~NetworkPlayer()
@@ -73,19 +69,23 @@
 
 	/// Should return true when the backend is able to run the network
 	virtual bool IsWorking() = 0;
+	
 	/// Whenever the backend is not working, this method returns the reason
 	virtual std::string NonWorkingReason() = 0;
 
 	/// Redefine to add any initialization after being attached to a network
 	/// TODO: Consider removing it as just Jack backend uses it but it is redundant
 	virtual void Init() {}
+	
 	/// Redefine to make the backend ready to process and start the network.
 	/// If IsPlaying() should do nothing.
 	/// If it IsPaused() you should consider just call BePlaying()
 	/// without starting the processings.
 	virtual void Start()=0; // { if (not IsPlaying()) BePlaying(); }
+	
 	/// Redefine it to deactivate the backend.
 	virtual void Stop()=0; // { if (not IsStopped()) BeStopped(); }
+	
 	virtual void Pause() { if (IsPlaying()) BePaused(); }
 
 	void SetNetworkBackLink( Network& net )
@@ -126,12 +126,12 @@
 
 	unsigned GetSourcesSize()
 	{
-		return GetSize<Network::AudioSources, AudioSource>(GetAudioSources());
+		return GetSize<Network::AudioSources>(GetAudioSources());
 	}
 
 	unsigned GetSinksSize()
 	{
-		return GetSize<Network::AudioSinks, AudioSink>(GetAudioSinks());
+		return GetSize<Network::AudioSinks>(GetAudioSinks());
 	}
 
 private:
Index: CLAM/src/Processing/AudioSource.hxx
===================================================================
--- CLAM/src/Processing/AudioSource.hxx	(revision 13271)
+++ CLAM/src/Processing/AudioSource.hxx	(working copy)
@@ -8,7 +8,6 @@
 
 namespace CLAM
 {
-
 	class AudioSource : public Processing
 	{
 	public:
@@ -32,7 +31,6 @@
 		typedef std::vector<Port> Ports;
 
 	private:
-
 		class Config : public ProcessingConfig
 		{
 			DYNAMIC_TYPE_USING_INTERFACE( Config, 1, ProcessingConfig );
Index: CLAM/src/Processing/AudioSink.hxx
===================================================================
--- CLAM/src/Processing/AudioSink.hxx	(revision 13271)
+++ CLAM/src/Processing/AudioSink.hxx	(working copy)
@@ -18,7 +18,6 @@
 			unsigned mBufferSize;
 			AudioInPort* mAudioIn;
 			
-			//resize needs a default constructor
 			Port()
 			: mFloatBuffer(0), mDoubleBuffer(0), mBufferSize(0), mAudioIn(0) 
 			{
_______________________________________________
Clam-devel mailing list
Clam-devel@llistes.projectes.lafarga.org
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel

Reply via email to