From 14bd43796914dc15471f1b7a6fee73258c6ee97d Mon Sep 17 00:00:00 2001
From: Joseph <joseph.larralde@gmail.com>
Date: Mon, 29 May 2017 17:55:36 +0200
Subject: [PATCH] clean pipo tools module

---
 .../rapidPiPoTools/rapidPiPoHost.cpp          | 75 ++++++++++---------
 .../rapidPiPoTools/rapidPiPoHost.h            | 21 +++---
 .../rapidPiPoTools/rapidPiPoTools.h           |  5 +-
 3 files changed, 54 insertions(+), 47 deletions(-)

diff --git a/src/signalProcessing/rapidPiPoTools/rapidPiPoHost.cpp b/src/signalProcessing/rapidPiPoTools/rapidPiPoHost.cpp
index 06211c9..8ad567a 100644
--- a/src/signalProcessing/rapidPiPoTools/rapidPiPoHost.cpp
+++ b/src/signalProcessing/rapidPiPoTools/rapidPiPoHost.cpp
@@ -1,4 +1,5 @@
 #include "rapidPiPoHost.h"
+#include <iostream>
 
 //===================== P I P O = H O S T = U T I L S ========================//
 
@@ -12,7 +13,7 @@ static bool getPiPoInstanceAndAttrName(const char *attrName,
 
   if (dot != NULL)
   {
-    unsigned int pipoAttrNameLen = dot - attrName;
+    long pipoAttrNameLen = dot - attrName;
     std::strcpy(pipoAttrName, dot + 1);
 
     if (pipoAttrNameLen > maxWordLen)
@@ -56,7 +57,8 @@ static void fromPiPoStreamAttributes(PiPoStreamAttributes &src,
 
   dst.rate = src.rate;
   dst.offset = src.offset;
-  dst.dims = { src.dims[0], src.dims[1] };
+  dst.width = src.dims[0];
+  dst.height = src.dims[1];
 
   dst.labels = std::vector<std::string>();
 
@@ -78,17 +80,18 @@ static void toPiPoStreamAttributes(pipoStreamAttributes &src,
 
   for (unsigned int i = 0; i < src.labels.size(); ++i)
   {
-    labs[i] = labels[i].c_str();
+    labs[i] = src.labels[i].c_str();
   }
 
   dst = PiPoStreamAttributes(
     src.hasTimeTags,
     src.rate,
     src.offset,
-    { src.dims[0], src.dims[1] },
+    src.width,
+    src.height,
     &labs[0],
     src.hasVarSize,
-    src.domain;
+    src.domain,
     src.maxFrames
   );
 }
@@ -115,7 +118,7 @@ PiPoHost::~PiPoHost()
 }
 
 bool
-PiPoHost::setPiPoGraph(std::string name)
+PiPoHost::setGraph(std::string name)
 {
   if (this->graph != nullptr)
   {
@@ -127,7 +130,7 @@ PiPoHost::setPiPoGraph(std::string name)
   if (this->graph != NULL)
   {
     this->graphName = name;
-    this->graph->connect((PiPo *)this->out);
+    this->graph->setReceiver((PiPo *)this->out);
     return true;
   }
 
@@ -137,7 +140,7 @@ PiPoHost::setPiPoGraph(std::string name)
 }
 
 void
-PiPoHost::clearPiPoGraph()
+PiPoHost::clearGraph()
 {
   if (this->graph != nullptr)
   {
@@ -162,22 +165,25 @@ PiPoHost::getLastFrameOut()
 
 
 
-void
+int
 PiPoHost::setInputStreamAttributes(pipoStreamAttributes &sa, bool propagate)
 {
   toPiPoStreamAttributes(sa, inputStreamAttrs);
 
   if (propagate)
   {
-    this->propagateInputStreamAttributes();
+    return this->propagateInputStreamAttributes();
   }
+    
+  return 0;
 }
 
 pipoStreamAttributes
 PiPoHost::getOutputStreamAttributes()
 {
   pipoStreamAttributes sa;
-  return fromPiPoStreamAttributes(this->outputStreamAttrs, sa);
+  fromPiPoStreamAttributes(this->outputStreamAttrs, sa);
+  return sa;
 }
 
 int
@@ -202,22 +208,22 @@ PiPoHost::frames(double time, double weight, PiPoValue *values, unsigned int siz
 // }
 
 bool
-setAttr(const std::string &attrName, double value)
+PiPoHost::setAttr(const std::string &attrName, double value)
 {
   PiPo::Attr *attr = this->graph->getAttr(attrName.c_str());
   
   if (attr != NULL) {
     int iAttr = attr->getIndex();
-    return this->pipo->setAttr(iAttr, value);
+    return this->graph->setAttr(iAttr, value);
   }
 
   return false;
 }
 
 bool
-setAttr(const std::string &attrName, const std::vector<double> &values)
+PiPoHost::setAttr(const std::string &attrName, const std::vector<double> &values)
 {
-  PiPo::Attr *attr = this->pipo->getAttr(attrName.c_str());
+  PiPo::Attr *attr = this->graph->getAttr(attrName.c_str());
 
   if (attr != NULL) {
     int iAttr = attr->getIndex();
@@ -227,16 +233,16 @@ setAttr(const std::string &attrName, const std::vector<double> &values)
       vals[i] = value;
       i++;
     }
-    return this->pipo->setAttr(iAttr, &vals[0], values.size());
+    return this->graph->setAttr(iAttr, &vals[0], values.size());
   }
 
   return false;
 }
 
 bool
-setAttr(const std::string &attrName, const std::string &value) // for enums
+PiPoHost::setAttr(const std::string &attrName, const std::string &value) // for enums
 {
-  PiPo::Attr *attr = this->pipo->getAttr(attrName.c_str());
+  PiPo::Attr *attr = this->graph->getAttr(attrName.c_str());
   
   if (attr != NULL) {
     int iAttr = attr->getIndex();
@@ -258,21 +264,23 @@ setAttr(const std::string &attrName, const std::string &value) // for enums
 }
 
 
-void
+int
 PiPoHost::propagateInputStreamAttributes()
 {
   if (this->graph != nullptr)
   {
-    this->graph->streamAttributes(this->inputStreamAttrs.hasTimeTags,
-                            this->inputStreamAttrs.rate,
-                            this->inputStreamAttrs.offset,
-                            this->inputStreamAttrs.dims[0],
-                            this->inputStreamAttrs.dims[1],
-                            this->inputStreamAttrs.labels,
-                            this->inputStreamAttrs.hasVarSize,
-                            this->inputStreamAttrs.domain,
-                            this->inputStreamAttrs.maxFrames);
+    return this->graph->streamAttributes(this->inputStreamAttrs.hasTimeTags,
+                                         this->inputStreamAttrs.rate,
+                                         this->inputStreamAttrs.offset,
+                                         this->inputStreamAttrs.dims[0],
+                                         this->inputStreamAttrs.dims[1],
+                                         this->inputStreamAttrs.labels,
+                                         this->inputStreamAttrs.hasVarSize,
+                                         this->inputStreamAttrs.domain,
+                                         this->inputStreamAttrs.maxFrames);
   }
+    
+  return 0;
 }
 
 
@@ -465,6 +473,7 @@ PiPoHost::setOutputAttributes(bool hasTimeTags, double rate, double offset,
   this->outputStreamAttrs.maxFrames = maxFrames; 
 }
 
+/*
 bool
 PiPoHost::getOutputHasTimeTags() {
   return this->outputStreamAttrs.hasTimeTags;
@@ -518,12 +527,6 @@ PiPoHost::getOutputMaxFrames() {
 
 
 
-
-
-
-
-
-
 //===================== PIPO HOST CLASS IMPLEMENTATION =======================//
 
 rapidPiPoHost::rapidPiPoHost(rapidPiPoOwner *rpo) :
@@ -655,7 +658,7 @@ rapidPiPoHost::setInputHasTimeTags(bool hasTimeTags, bool propagate) {
   }
 }
 
-#define MIN_PIPO_SAMPLERATE (1.0 / 31536000000.0) /* once a year */
+#define MIN_PIPO_SAMPLERATE (1.0 / 31536000000.0) // once a year
 #define MAX_PIPO_SAMPLERATE (96000000000.0)
 
 void
@@ -863,6 +866,8 @@ int
 rapidPiPoHost::getOutputMaxFrames() {
   return this->outputStreamAttrs.maxFrames;
 }
+ 
+//*/
 
 // void
 // rapidPiPoHost::setRapidPiPoParam(rapidPiPoParam *param) {
diff --git a/src/signalProcessing/rapidPiPoTools/rapidPiPoHost.h b/src/signalProcessing/rapidPiPoTools/rapidPiPoHost.h
index b665a3f..dce7340 100644
--- a/src/signalProcessing/rapidPiPoTools/rapidPiPoHost.h
+++ b/src/signalProcessing/rapidPiPoTools/rapidPiPoHost.h
@@ -15,19 +15,18 @@ struct pipoStreamAttributes {
   hasTimeTags(false),
   rate(MIN_PIPO_SAMPLERATE),
   offset(0),
+  width(1),
+  height(1),
   labels({ "" }),
   hasVarSize(false),
   domain(0),
-  maxFrames(256)
-  {
-      dims[0] = 1;
-      dims[1] = 1;
-  }
+  maxFrames(256) {}
 
   bool hasTimeTags;
   double rate;
   double offset;
-  unsigned int dims[2]; // width, height (by pipo convention)
+  unsigned int width; // width, height (by pipo convention)
+  unsigned int height;
   std::vector<std::string> labels;
   bool hasVarSize;
   double domain;
@@ -58,15 +57,15 @@ public:
     
     // PiPoObserver *getObserver();
 
-    virtual bool setPiPoGraph(std::string name);
-    virtual void clearPiPoGraph();
+    virtual bool setGraph(std::string name);
+    virtual void clearGraph();
 
     // override this method when inheriting !!!
     virtual void onNewFrameOut(double time, std::vector<PiPoValue> &frame);
     virtual std::vector<PiPoValue> getLastFrameOut();
     
-    virtual int setInputStreamAttributes(pipoStreamAttributes sa, bool propagate = true);
-    virtual pipoStreamAttributes &getOutputStreamAttributes();
+    virtual int setInputStreamAttributes(pipoStreamAttributes &sa, bool propagate = true);
+    virtual pipoStreamAttributes getOutputStreamAttributes();
 
     virtual int frames(double time, double weight, PiPoValue *values, unsigned int size,
                        unsigned int num);
@@ -136,7 +135,7 @@ public:
     // void setPiPoParam(PiPoParam *param);
     //*/
 private:
-    void propagateInputStreamAttributes();
+    int propagateInputStreamAttributes();
     void setOutputAttributes(bool hasTimeTags, double rate, double offset,
                              unsigned int width, unsigned int height,
                              const char **labels, bool hasVarSize,
diff --git a/src/signalProcessing/rapidPiPoTools/rapidPiPoTools.h b/src/signalProcessing/rapidPiPoTools/rapidPiPoTools.h
index 45c381b..04265de 100644
--- a/src/signalProcessing/rapidPiPoTools/rapidPiPoTools.h
+++ b/src/signalProcessing/rapidPiPoTools/rapidPiPoTools.h
@@ -3,4 +3,7 @@
 
 #include "rapidPiPoHost.h"
 
-# endif /* _RAPID_PIPO_TOOLS_H_ */
\ No newline at end of file
+typedef PiPoHost rapidPiPoHost;
+typedef pipoStreamAttributes rapidPiPoStreamAttributes;
+
+# endif /* _RAPID_PIPO_TOOLS_H_ */
-- 
GitLab