diff options
| author | Tim Redfern <tim@herge.(none)> | 2013-07-02 17:22:38 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@herge.(none)> | 2013-07-02 17:22:38 +0100 |
| commit | 991099ad1f33d1ed6fd0423964f196b34b0c1669 (patch) | |
| tree | 3831efb2aac6bd473766d277c3bb388343dca931 /rotord/rendercontext.cpp | |
| parent | 0d867b8b615add6e1a5aaa300c5a39b87614d906 (diff) | |
xml with root nodes
Diffstat (limited to 'rotord/rendercontext.cpp')
| -rw-r--r-- | rotord/rendercontext.cpp | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/rotord/rendercontext.cpp b/rotord/rendercontext.cpp index 4be54f1..e31a161 100644 --- a/rotord/rendercontext.cpp +++ b/rotord/rendercontext.cpp @@ -49,7 +49,223 @@ void Render_context::add_queue(int item) { mutex.unlock(); } void Render_context::session_command(const std::vector<std::string>& command,xmlIO& XML,HTTPResponse::HTTPStatus& status){ + status=HTTPResponse::HTTP_BAD_REQUEST; //error by default + if (command[2]=="resolution") { + if (command[0]=="PUT") { + if (command.size()>2) { + if (state==IDLE) { + Poco::StringTokenizer t1(command[3],","); + if (t1.count()>1){ + int w=ofToInt(t1[0]); + int h=ofToInt(t1[1]); + if (graph.set_resolution(w,h)){ + XML.addValue("status","resolution set to "+t1[0]+"x"+t1[1]); + status=HTTPResponse::HTTP_OK; + } + else { + XML.addValue("error","invalid resolution request: "+t1[0]+"x"+t1[1]); + } + } + } + else { + XML.addValue("error","session busy"); + } + } + } + } + if (command[2]=="audio") { + if (command[0]=="PUT") { //get audio file location and initiate analysis + if (command.size()>2) { + if (state==IDLE) { + audio_filename=media_dir+command[3]; //for now, store session variables in memory //check file exists + Poco::File f=Poco::File(audio_filename); + if (f.exists()) { + //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? + add_queue(ANALYSE_AUDIO); + status=HTTPResponse::HTTP_OK; + XML.addValue("status","Starting audio analysis: "+command[3]); + } + else { + status=HTTPResponse::HTTP_NOT_FOUND; + XML.addValue("error",command[3]+" not found"); + } + } + else { + XML.addValue("error","session busy"); + } + } + } + if (command[0]=="GET") { + if (state==ANALYSING_AUDIO) { + status=HTTPResponse::HTTP_OK; + XML.addValue("status","analysing audio"); + char c[20]; + sprintf(c,"%02f",progress); + XML.addValue("progress",string(c)); + } + else if (audio_loaded) { + //not sure about this-- should this state be retained? + //can the data only be read once? + //for now + status=HTTPResponse::HTTP_OK; + XML.addValue("status","audio ready"); + XML.addValue("audio",audio_thumb->print()); + } + else { + XML.addValue("error","no audio loaded"); + } + } + if (command[0]=="DELETE") { + //for now + audio_filename=""; + XML.addValue("status","audio deleted"); + status=HTTPResponse::HTTP_OK; + } + } + if (command[2]=="graph") { + if (command[0]=="GET") { + if (graph.loaded) { + status=HTTPResponse::HTTP_OK; + //XML.addValue("patchbay",graph.toString()); + XML.loadFromBuffer(graph.toString()); + } + else { + XML.addValue("error","graph not loaded: check XML"); + } + } + if (command[0]=="PUT") { //get new graph from file + if (command.size()>2) { + //should interrupt whatever is happening? + //before begining to load from xml + if (state==IDLE) { //eventually not like this + string graph_filename=graph_dir+command[3]; + Poco::File f=Poco::File(graph_filename); + if (f.exists()) { + if (graph.load(graph_filename)) { + status=HTTPResponse::HTTP_OK; + //XML.addValue("patchbay",graph.toString()); + //XML.loadFromBuffer(graph.toString()); + XML=graph.xml; + //the graph could actually contain an xml object and we could just print it here? + //or could our nodes even be subclassed from xml nodes? + //the graph or the audio could load first- have to analyse the audio with vamp after the graph is loaded + //for now the graph must load 1st + } + else { + status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; //~/sources/poco-1.4.6-all/Net/include/Poco/Net/HTTPResponse.h + XML.addValue("error","graph not loaded: check XML"); + } + } + else { + status=HTTPResponse::HTTP_NOT_FOUND; + XML.addValue("error",command[3]+" not found"); + } + } + } + } + if (command[0]=="DELETE") { + //for now + graph=Graph(); + XML.addValue("status","graph deleted"); + status=HTTPResponse::HTTP_OK; + } + } + if (command[2]=="signal") { + if (command[0]=="GET") { //generate xml from 1st signal output + if (state==IDLE) { + //direct call for testing + float framerate=25.0f; + if (command.size()>2) { + framerate=ofToFloat(command[3]); + } + string signal_xml; + if (graph.signal_render(signal_xml,framerate)){ + status=HTTPResponse::HTTP_OK; + XML.addValue("signal",signal_xml); + } + else { + status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; + XML.addValue("error","could not render output signal"); + } + } + else { + status=HTTPResponse::HTTP_NOT_FOUND; + XML.addValue("error","Signal output not found in graph"); + } + } + else { + status=HTTPResponse::HTTP_SERVICE_UNAVAILABLE; + XML.addValue("error","Context busy"); + } + } + if (command[2]=="video") { + if (command[0]=="PUT") { //get vide file location and initiate analysis + if (command.size()>4) { //there should be a filename + a destination node + if (state==IDLE) { + string video_filename=media_dir+command[4]; + //check file exists + Poco::File f=Poco::File(video_filename); + if (f.exists()) { + if (load_video(command[3],video_filename)) { + //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? + //DUMMY RESPONSE + status=HTTPResponse::HTTP_OK; + XML.addValue("status","succesfully loaded "+command[4]+" into video node "+command[3]); + } + else { + status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; + XML.addValue("error","could not load "+command[4]+" into video node "+command[3]); + } + } + else { + status=HTTPResponse::HTTP_NOT_FOUND; + XML.addValue("error",command[4]+" not found"); + } + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + XML.addValue("error","Session busy"); + } + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + XML.addValue("error","Bad request"); + } + } + } + if (command[2]=="render") { + if (command[0]=="GET") { + status=HTTPResponse::HTTP_OK; + XML.addValue("status","Rendering video"); + XML.addValue("progress",ofToString(progress)); + } + if (command[0]=="PUT") { + if (command.size()>2) { + if (state==IDLE) { + output_filename=output_dir+command[3]; + if (command.size()>3) { +// output_framerate=ofToFloat(command[4]); + } + add_queue(RENDER); + status=HTTPResponse::HTTP_OK; + XML.addValue("status","Starting render: "+command[3]); + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + XML.addValue("error","Session busy"); + } + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + XML.addValue("error","No output file specified"); + } + } + if (command[0]=="DELETE") { + status=HTTPResponse::HTTP_OK; + XML.addValue("status","DUMMY RESPONSE: cancelling render"); + } + } } Command_response Render_context::session_command(const std::vector<std::string>& command){ //method,id,command1,{command2,}{body} |
