[Clam-devel] 2 small patches

dirk.griffioen dirk.griffioen at barcelonamedia.org
Wed Jun 10 06:12:52 PDT 2009


Hi,

Attached 2 small patches, one for more constness in the backend and the 
second one to remove some duplicate code in the jackbackend.

Regarding these duplicates, most of them stem from the fact the 
operations on in/out (port, file, buffer, xyz) are almost the same (for 
example: AudioSource/Sink only differ in the constness of the 
float/double buffer (which is a duplicate in itself)).

However, I am not quite clear on how to approach this.

One solution could be to use more STL:

template<typename T> struct store : std::unary_function<T, void>
{
  JackConnections& store_;

  store(C& store) : store_(s)
  {
  }

  void operator()(T const& t)
  {
    JackConnection connection;
    connection.processingName = t.PortName();
    connection.outsideConnections = jack_port_get_connections ( 
t.jackPort );
    store_.push_back(connection)
  }
};

void JACKNetworkPlayer::StoreConnections()
{
    std::for_each(_sourceJackBindings.begin(), 
_sourceJackBindings.end(), 
store<SourceJackBinding>(_incomingJackConnections));
    std::for_each(_sinkJackBindings.begin(), _sinkJackBindings.end(), 
store<SinkJackBinding>(_outgoingJackConnections));
}

But this adds the overhead of having lost of function objects, although 
the code now is back to one definition ...

Another to leave the loop (possibly using a (boost) foreach), but to 
factor out the code to one place:

template<typename T>void copy(T const& t)
{
    jack_port_unregister(_jackClient, t.jackPort))
}
 
void JACKNetworkPlayer::UnRegisterPorts()
{
    foreach(sinkJackBinding, SinkJackBindings)
          copy<SinkJackBinding>(sinkJackBinding);

Lastly the argument could be made that as Clam places the emphasis on 
In/Out being of different types the proliferation of code should be 
accepted - but this kind of violates the 'dont repeat yourself' adagium.

What would be preferable?

Dirk



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20090610/98690135/attachment-0003.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: const.patch
Type: text/x-patch
Size: 10088 bytes
Desc: not available
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20090610/98690135/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jacktemplate.patch
Type: text/x-patch
Size: 2860 bytes
Desc: not available
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20090610/98690135/attachment-0007.bin>


More information about the clam-devel mailing list