/* requirement driven design do we store graphs as files or in a db with UUID as key? we traverse the graph as recursive function calls until we satisfy all dependencies NO NODE HAS MORE THAN ONE OUTPUT WE DON'T LINK TO AN OUTPUT OBJECT WE LINK TO THE NODE - GET_OUTPUT IS THE RENDER FUNCTION ??the only node with more than 1 output is audio? ??lets rethink this ??audio analysis nodes can be seperate - they can all load from the same audio file - were gonna have to process each pass ??output splitter? channel splitter? these can be done as 1 object per channel? ??I think so settings - how do we deal with settings being controllable signal inputs can have a gui representation as well other gui items don't have an input scaling to come time is always in floating points seconds - time has to be requested when rendering - either a preview what about testing a float for equality? maybe we should look at time in int (frames) - - what does this imply is it easier to have a function like: bool Same_frame(float time1, float time2); nb where a signal enters a channel comp input - it is duplicated - so nodes should cache a value (more for time effects) sql stuff NB best way to use is: interface uploads audio and makes thumbnail: graph determines what kind of audio analysis is used by referring to plugins jesus where is it hanging in the frigging debugger GOOD GOOD GOOD next - build signal_output and make a working chain with dummy data */ #include #include #include "Poco/Net/HTTPServer.h" #include "Poco/Net/HTTPResponse.h" #include "Poco/UUID.h" #include "Poco/UUIDGenerator.h" #include "Poco/Notification.h" #include "Poco/NotificationCenter.h" #include "Poco/Observer.h" #include "Poco/ThreadPool.h" #include "Poco/Thread.h" #include "Poco/Task.h" #include "Poco/Runnable.h" #include "Poco/Mutex.h" #include "Poco/Random.h" #include "Poco/AutoPtr.h" #include "Poco/File.h" #include using Poco::UUID; using Poco::UUIDGenerator; using Poco::Net::HTTPResponse; #include "vampHost.h" #include "xmlIO.h" namespace Rotor { #define IDLE 0 #define ANALYSING_AUDIO 1 #define AUDIO_READY 2 #define CREATING_PREVIEW 3 #define PREVIEW_READY 4 #define RENDERING 5 #define RENDER_READY 6 #define ANALYSE_AUDIO 1 #define PREVIEW 2 #define RENDER 3 //forward declaration class Node; class Render_status{ public: int id; float progress; }; class Render_requirements{ public: int num_performances; int num_clips; }; class Command_response{ public: Command_response() { status=Poco::Net::HTTPResponse::HTTP_OK; } std::string description; Poco::Net::HTTPResponse::HTTPStatus status; }; class Input{ public: Input(const string &_desc): description(_desc){}; Node* connection; string description; }; class Image_input: public Input{ public: }; class Signal_input: public Input{ public: bool connect(Node* source); Signal_input(const string &_desc): Input(_desc){}; }; class Node{ public: Node(){}; virtual ~Node(){}; Node(map &settings){ cerr << "Node:"; for (map::iterator it=settings.begin();it!=settings.end();++it) { cerr << it->first << "," << it->second << " "; } cerr << endl; description=settings["description"];type=settings["type"];output_type=settings["output"];ID=settings["ID"]; }; UUID uid; //every usable node has a UUID int id; vector inputs; //simple node has signal inputs and outputs void create_signal_input(const string &description) {inputs.push_back(new Signal_input(description));}; void gather_inputs(const float &time) { for (uint i=0;iconnection) inputs[i]->connection->get_output(time); } } float get_output(const float &time) { //default is to pass through first input, if disconnected returns 0 cerr << "getting output for " << type << "," << ID << endl; if (inputs.size()) { if (inputs[0]->connection) return inputs[0]->connection->get_output(time); } return 0.0f; } string description; string type; string output_type; string ID; }; class Image{ char* data; }; class Signal_node: public Node{ public: Signal_node(){}; Signal_node(map &settings){ cerr << "Signal_node:"; for (map::iterator it=settings.begin();it!=settings.end();++it) { cerr << it->first << "," << it->second << " "; } cerr << endl; description=settings["description"];type=settings["type"];output_type=settings["output"];ID=settings["ID"]; }; }; class Image_node: public Node{ public: vector image_inputs; //image node also has image inputs and outputs void gather_inputs(const float &time) { Node::gather_inputs(time); for (uint i=0;iget_output(time); } } Image* get_output(float time){ //sample implementation gather_inputs(time); //do something with the inputs //and then return ((Image_node*)image_inputs[0].connection)->image; } void get_preview(float time); Image* image; //this can be privately allocated or just passed on as the node see fit private: float image_time; }; //actual nodes------------------------------------------------- class Audio_analysis: public Signal_node { public: Audio_analysis(){}; Audio_analysis(map &settings) { cerr << "Audio analysis:"; for (map::iterator it=settings.begin();it!=settings.end();++it) { cerr << it->first << "," << it->second << " "; } cerr << endl; description=settings["description"];type=settings["type"];output_type=settings["output"];ID=settings["ID"]; }; float get_output(const float &time) { float t=time; return t; } }; class Is_new_integer: public Signal_node { //does this require knowing what the framerate is? //for now, assume 25 //what to cache? for now, don't cache public: Is_new_integer(){}; Is_new_integer(map &settings) { cerr << "Is new integer:"; for (map::iterator it=settings.begin();it!=settings.end();++it) { cerr << it->first << "," << it->second << " "; } cerr << endl; description=settings["description"];type=settings["type"];output_type=settings["output"];ID=settings["ID"]; }; float get_output(const float &time) { if (((int)Node::get_output(time))>((int)Node::get_output(time-.04))) return 1.0f; else return 0.0f; } }; class Signal_output: public Signal_node { public: Signal_output(){}; Signal_output(map &settings) { cerr << "Signal output:"; for (map::iterator it=settings.begin();it!=settings.end();++it) { cerr << it->first << "," << it->second << " "; } cerr << endl; description=settings["description"];type=settings["type"];output_type=settings["output"];ID=settings["ID"]; }; bool render(const float duration, const float framerate,string &xml_out); }; //------------------------------------------------------------------- class Node_factory{ public: Node_factory(); template T* clone(T* proto,map &settings) { cerr << "Factory settings: "; for (map::iterator it=settings.begin();it!=settings.end();++it) { cerr << it->first << "," << it->second << " "; } cerr << endl; return new T(settings); } void add_type(string type,Node* proto){ type_map[type]=proto; }; Node* create(map &settings){ if (type_map.find(settings["type"])!=type_map.end()) { cerr << "Factory: creating " << settings["type"] << endl; return clone(type_map[settings["type"]],settings); } else return NULL; }; private: map type_map; }; class Graph{ public: Graph(){framerate=25.0f;duration=10.0f;}; Graph(const string& _uid,const string& _desc){ uid=_uid;description=_desc;framerate=25.0f;duration=10.0f;}; string uid; //every version of a graph has a UUID, no particular need to actually read its data(?) //?? is it faster than using strings?? string description; std::unordered_map nodes; Node* find(const string &type){ for (std::unordered_map::iterator it=nodes.begin();it!=nodes.end();++it) { if (it->second->type==type) return it->second; } return NULL; }; bool signal_render(const float _fr,string &signal_xml) { if (_fr>.001) framerate=_fr; if (find("signal_output")) { Signal_output *signal_output=dynamic_cast(find("signal_output")); return signal_output->render(duration,framerate,signal_xml); } else return false; } private: Node_factory factory; float framerate; float duration; }; class Render_context: public Poco::Task { //Poco task object //manages a 'patchbay' //high level interfaces for the wizard //and low level interface onto the graph public: Render_context(const std::string& name): Task(name) { state=IDLE; }; void runTask(); void add_queue(int item); Command_response session_command(const std::vector& command); Render_status get_status(); void cancel(); //interrupt locking process int make_preview(int nodeID, float time); //starts a frame preview - returns status code - how to retrieve? int load_graph(Poco::UUID uid); bool load_graph(string graph_filename); //should eventually be as above UUID save_graph(); //returns UUID of saved graph int load_audio(string filename); Render_requirements get_requirements(); int load_video(int num,string filename); //can be performance or clip private: int state; float progress; //for a locking process: audio analysis or rendering std::deque work_queue; Poco::Mutex mutex; //lock for access from parent thread std::string audio_filename; vampHost::QMAnalyser audio_analyser; xmlIO xml; Graph graph; Node_factory factory; }; } /* coding style Types begin with a capital, use underscore as a seperator instances begin with a small letter */