summaryrefslogtreecommitdiff
path: root/NT
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-05-14 20:06:02 +0100
committerTim Redfern <tim@eclectronics.org>2014-05-14 20:06:02 +0100
commitebc874413991fbc3d07493ece55f88f23e437af6 (patch)
tree0b41617db2be2bdb53e83f1f37c971ced7e4172a /NT
parentf3a687d33486a3d7a644a2110291124cb813cd67 (diff)
NT bugs cleaned and variable array type functional
Diffstat (limited to 'NT')
-rw-r--r--NT/Makefile2
-rw-r--r--NT/src/graph.cpp1
-rw-r--r--NT/src/nodes.cpp1
-rw-r--r--NT/src/rendercontext.cpp35
-rw-r--r--NT/src/rotor.cpp15
-rw-r--r--NT/src/rotor.h138
6 files changed, 116 insertions, 76 deletions
diff --git a/NT/Makefile b/NT/Makefile
index 40abdf9..36008f1 100644
--- a/NT/Makefile
+++ b/NT/Makefile
@@ -8,7 +8,7 @@
MY_CFLAGS = -Wswitch -fpermissive -std=c++11 `pkg-config --cflags --libs gtk+-2.0` -I /usr/include/librsvg-2.0/librsvg -I /usr/include/opencv -I /usr/include/cairo -I /usr/include/jsoncpp
# -I ../ffmpeg
-MY_LIBS = -lgobject-2.0 -lrsvg-2 -lnoise -ljsoncpp -lcairo -lopencv_core -lopencv_video -lopencv_imgproc -lopencv_highgui -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil -lstdc++ -lm
+MY_LIBS = -lffms2 -lgobject-2.0 -lrsvg-2 -lnoise -ljsoncpp -lcairo -lopencv_core -lopencv_video -lopencv_imgproc -lopencv_highgui -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil -lstdc++ -lm
# The linker options.libgstaasinklibgstaasink.so
#MY_LIBS = -lgobject-2.0 -lrsvg-2 -lnoise -lffms2 -ljsoncpp -lcairo -lopencv_core -lopencv_video -lopencv_imgproc -lopencv_highgui -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil -lstdc++ -lm
diff --git a/NT/src/graph.cpp b/NT/src/graph.cpp
index f108f55..5b0a15a 100644
--- a/NT/src/graph.cpp
+++ b/NT/src/graph.cpp
@@ -123,6 +123,7 @@ bool Graph::parse_json(string &data,string &media_path){
check_audio(root["audio"].asString(),media_path);
init(root["id"].asString());
Json::Value jnodes = root["nodes"];
+ //std::cerr<<"json parser found "<<jnodes.size()<<" nodes"<<std::endl;
for ( uint32_t i = 0; i < jnodes.size(); ++i ) {
string node_id=jnodes[i]["id"].asString();
Node* node=factory.create(jnodes[i]);
diff --git a/NT/src/nodes.cpp b/NT/src/nodes.cpp
index e69de29..092c878 100644
--- a/NT/src/nodes.cpp
+++ b/NT/src/nodes.cpp
@@ -0,0 +1 @@
+#include "rotor.h" \ No newline at end of file
diff --git a/NT/src/rendercontext.cpp b/NT/src/rendercontext.cpp
index 77a7701..217a05a 100644
--- a/NT/src/rendercontext.cpp
+++ b/NT/src/rendercontext.cpp
@@ -74,24 +74,27 @@ string Render_context::text_render(string node_id){
}
}
else {
- p=graph.get_node(id);
+ p=graph.get_node(node_id);
if (!p){
- logger.error("text_render: node '"+id+"' not found");
+ logger.error("text_render: node '"+node_id+"' not found");
return "";
}
}
Node_type<string>* s=(dynamic_cast<Node_type<string>*>(p));
if (!s) {
- logger.error("text_render: node '"+id+"' is not a text node");
+ logger.error("text_render: node '"+node_id+"' is not a text node");
return "";
}
string st="";
for (double t=0;t<10.0;t+=0.765){
Frame_parameters f=Frame_parameters(t,25.0,10.0,640,360);
- st+=(dynamic_cast<Node_type<string>*>(p))->get_output(f)+"\n";
+ st+=toString(t)+":"+(dynamic_cast<Node_type<string>*>(p))->get_output(f)+",";
}
return st;
}
+bool Render_context::video_render(std::string output_filename,std::string node_id=""){
+ return true;
+}
void Render_context::session_command(const Session_command& command,xmlIO& XML,HTTPResponse::HTTPStatus& status){
string s;
@@ -259,6 +262,30 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H
status=HTTPResponse::HTTP_OK;
}
}
+ if (command.commands[1]=="text") {
+ if (command.method=="GET") {
+ if(state==IDLE){
+ string text_node=command.body;
+ if (text_node!=""){
+ XML.addValue("data",text_render(text_node));
+ }
+ else {
+ status=HTTPResponse::HTTP_BAD_REQUEST;
+ logger.error("ERROR: Text node not specified");
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_BAD_REQUEST;
+ logger.error("ERROR: Session busy");
+ XML.addValue("error","Session busy");
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_BAD_REQUEST;
+ logger.error("ERROR: Bad request");
+ XML.addValue("error","Bad request");
+ }
+ }
/*
if (command.commands[1]=="signal") {
if (command.method=="GET") { //generate xml from 1st signal output
diff --git a/NT/src/rotor.cpp b/NT/src/rotor.cpp
index 5f75826..997dc4c 100644
--- a/NT/src/rotor.cpp
+++ b/NT/src/rotor.cpp
@@ -9,12 +9,6 @@
using namespace std;
using namespace Rotor;
-std::istream& operator>> (std::istream &in, Rotor::Enum &en)
-{
- in >> en.value;
- return in;
-};
-
string Variable::get_connection_id(){
if (connection) return connection->get_id();
return "";
@@ -23,15 +17,6 @@ string Variable::get_name(){
return name;
}
-template <class T>
-Json::Value Variable_type<T>::to_json(){
- Json::Value json;
- json["type"]=get_type();
- json["name"]=name;
- json["connectable"]=connectable?"yes":"no";
- json["input"]=connection?connection->get_id():"";
- return json;
-}
template <class T>
Json::Value Variable_array_type<T>::to_json(){
diff --git a/NT/src/rotor.h b/NT/src/rotor.h
index 6d56299..485ec8c 100644
--- a/NT/src/rotor.h
+++ b/NT/src/rotor.h
@@ -8,7 +8,11 @@ TJR-Jan-2014
NB when plugging in to framework - convert all cerr messages to logged
-What next?
+Test suite
+
+pipe to send commands?
+
+seperate framework? ie in Python- load server- send http commands
*/
#define ENABLE_TYPENAME(A) template<> struct TypeName<A> { static const char *Get() { return #A; }};
@@ -93,10 +97,15 @@ namespace Rotor {
operator int () const { //overload C style cast to int
return value;
}
- friend std::istream& operator>> (std::istream &in, Rotor::Enum &en);
+ //only works inside class definition?
+ friend std::istream &operator>> (std::istream &in, Rotor::Enum &en) {
+ in >> en.value;
+ return in;
+ };
+ protected:
+ int value;
private:
std::vector<std::string> labels;
- int value;
};
class Audio_frame{
@@ -150,6 +159,47 @@ namespace Rotor {
bool connectable;
std::string input;
};
+ class Node { //base type for node pointers
+ public:
+ Node(){type="";type_id="";id="";description="";};
+ virtual ~Node(){
+ for (auto v:vars){
+ delete v.second;
+ }
+ }
+ bool connect(std::string v,Node *t){
+ auto var=vars.find(v);
+ if (var!=vars.end()){
+ if ((*var).second->connect(t)){
+ return true;
+ }
+ }
+ return false;
+ }
+ std::string get_type(){return type;};
+ std::string& get_id(){return id;};
+ std::string& get_description(){return description;};
+ Json::Value to_json();
+ virtual Node* clone(Json::Value &_settings)=0;
+ virtual std::string get_output_type()=0;
+ void create_connections(std::unordered_map<std::string,Node*> &nodes){
+ Logger& logger = Logger::get(log_id);
+ for (auto var:vars) {
+ if (var.second->create_connection(nodes)) {
+ logger.information("Connected input '"+var.second->get_name()+"' of node '"+id+"' to node "+var.second->get_connection_id());
+ }
+ }
+ }
+ protected:
+ std::unordered_map<std::string,Variable*> vars;
+ std::string type;
+ std::string id;
+ std::string type_id;
+ std::string description;
+ std::string title;
+ std::string ui_type;
+ std::string log_id;
+ };
template <class T> class Variable_type : public Variable {
public:
Variable_type(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true): Variable(_name,_description,_title){
@@ -172,10 +222,17 @@ namespace Rotor {
}
return false;
}
- Json::Value to_json();
- std::string get_type(){ //need this to output node templates
- return TypeName<T>::Get();
- }
+ Json::Value to_json(){
+ Json::Value json;
+ json["type"]=get_type();
+ json["name"]=name;
+ json["connectable"]=connectable?"yes":"no";
+ json["input"]=connection?connection->get_id():"";
+ return json;
+ }
+ std::string get_type(){ //need this to output node templates
+ return TypeName<T>::Get();
+ }
//have to cast connect and get_output to use templated return types
bool connect(Node* target){
if (connectable){
@@ -200,6 +257,7 @@ namespace Rotor {
T value;
};
class Variable_array: public Variable {
+ //base type for a variable amount of inlets
public:
Variable_array(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true): Variable(_name,_description,_title){
connectable=_connectable;
@@ -208,32 +266,41 @@ namespace Rotor {
std::vector<Variable> values;
};
template <class T> class Variable_array_type: public Variable_array {
+ //is it possible to overload array access operator here?
public:
Variable_array_type(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true): Variable_array(_name,_description,_title,connectable){};
void init(Json::Value s){
name=s["name"].asString();
if (!s["input"].empty()){
- add(s["input"].size());
+ for (int i;i<s["input"].size();i++){
+ add(s["input"][i]);
+ values[i].init(s["input"][i]);
+ }
}
}
bool create_connection(std::unordered_map<std::string,Node*> &nodes){
- bool success=true;
+ bool success=false;
//for (auto v:values){ //weirdly does not work even though it seems to! maybe it returns a copy of of the object?
// v.create_connection(nodes);
//}
for (uint32_t i=0;i<values.size();i++) {
- if (!values[i].create_connection(nodes)) success=false;
+ if (values[i].create_connection(nodes)) {
+ success=true;
+ }
}
return success;
}
Json::Value to_json();
- std::string get_type(){
- return TypeName<T>::Get();
- }
+ std::string get_type(){
+ return TypeName<T>::Get();
+ }
bool connect(Node* target){
- //array does not connect this way
+ //array does not connect this way- just connect 1st inlet?
return false;
}
+ void add(Json::Value s){
+ values.push_back(Variable_type<T>(s.get("name","").asString(),s.get("description","").asString(),s.get("title","").asString(),s.get("connectable",false).asBool()));
+ }
void add(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true){
values.push_back(Variable_type<T>(_name,_description,_title,_connectable));
}
@@ -260,48 +327,7 @@ namespace Rotor {
std::vector<Variable_type<T>> values;
T value;
};
- //could specialise a variable type operator double() etc to allow direct cast
- class Node { //base type for node pointers
- public:
- Node(){type="";type_id="";id="";description="";};
- virtual ~Node(){
- for (auto v:vars){
- delete v.second;
- }
- }
- bool connect(std::string v,Node *t){
- auto var=vars.find(v);
- if (var!=vars.end()){
- if ((*var).second->connect(t)){
- return true;
- }
- }
- return false;
- }
- std::string get_type(){return type;};
- std::string& get_id(){return id;};
- std::string& get_description(){return description;};
- Json::Value to_json();
- virtual Node* clone(Json::Value &_settings)=0;
- virtual std::string get_output_type()=0;
- void create_connections(std::unordered_map<std::string,Node*> &nodes){
- Logger& logger = Logger::get(log_id);
- for (auto var:vars) {
- if (var.second->create_connection(nodes)) {
- logger.information("Connected input '"+var.second->get_name()+"' of node '"+id+"' to node "+var.second->get_connection_id());
- }
- }
- }
- protected:
- std::unordered_map<std::string,Variable*> vars;
- std::string type;
- std::string id;
- std::string type_id;
- std::string description;
- std::string title;
- std::string ui_type;
- std::string log_id;
- };
+
template <class NT> class Node_type : public Node {
public:
virtual const NT& get_output(const Frame_parameters &frame){return value;};