diff options
Diffstat (limited to 'rotord/src')
| -rw-r--r-- | rotord/src/graph.cpp | 38 | ||||
| -rw-r--r-- | rotord/src/rendercontext.cpp | 23 | ||||
| -rw-r--r-- | rotord/src/rendercontext.h | 5 | ||||
| -rwxr-xr-x | rotord/src/rotor.h | 8 |
4 files changed, 42 insertions, 32 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp index 3d0a88b..ae9247b 100644 --- a/rotord/src/graph.cpp +++ b/rotord/src/graph.cpp @@ -77,7 +77,7 @@ bool Graph::preview(xmlIO &XML,string &node,string &_format,int frame,int w,int return false; } -bool Graph::video_render(const string &output_filename,const string &audio_filename,const float framerate,float& progress) { +bool Graph::video_render(const string &output_filename,const float framerate,float& progress) { vector<Node*> loaders=find_nodes("video_loader"); for (auto i:loaders){ if (!dynamic_cast<Video_loader*>(i)->isLoaded) { @@ -109,28 +109,34 @@ bool Graph::load(string data,string media_path){ if (xml.loadFromBuffer(data)){ return parseXml(media_path); } - //cerr<<"Rotor: failed to load graph from string"<<endl; + return parseJson(data,media_path); return false; } bool Graph::loadFile(string &filename,string media_path){ //if (loaded) printf("loading graph: %s\n",(filename).c_str()); - - + if (xml.loadFile(filename)){ + return parseXml(media_path); + } Poco::FileInputStream fis(filename); Poco::CountingInputStream countingIstr(fis); std::string str; Poco::StreamCopier::copyToString(countingIstr, str); - //msg.Message(Poco::format(" Write/Read check : %s", std::string(0 == str.compare(ostrBackup.str()) ? "OK":"NG"))); - //msg.Message(Poco::format(" Characters : %d", countingIstr.chars())); - //msg.Message(Poco::format(" Lines : %d", countingIstr.lines())); - //cerr<<countingIstr.chars()<<" chars, "<<countingIstr.lines()<<endl; - //cerr<<str.size()<<" json chars found"<<endl; - if (xml.loadFile(filename)){ - return parseXml(media_path); - } return parseJson(str,media_path); } +bool Graph::check_audio(string audio,string path){ + if (audio!="") { + Poco::File f=Poco::File(path+audio); + if (f.exists()) { + audio_filename=path+audio; + audio_loaded=true; + cerr<<"Rotor: loading "<<path+audio<<" from graph"<<endl; + return true; + } + cerr<<"Rotor: audio file "<<path+audio<<" not found"<<endl; + } + return false; +} bool Graph::parseJson(string &data,string &media_path){ //cerr<<data<<endl; //cerr<<"Trying to load JSON"<<endl; @@ -145,9 +151,8 @@ bool Graph::parseJson(string &data,string &media_path){ return false; } //we know the json validates so clear the existing graph - if (loaded) nodes.clear(); - string audiotrack=root["audio"].asString(); - if (audiotrack!="") cerr<<"audio track :"<<endl; //need to deal with + nodes.clear(); + check_audio(root["audio"].asString(),media_path); init(root["ID"].asString(),root["description"].asString()); Json::Value jnodes = root["nodes"]; for ( int i = 0; i < jnodes.size(); ++i ) { @@ -254,7 +259,8 @@ bool Graph::parseJson(string &data,string &media_path){ return true; } bool Graph::parseXml(string media_path){ - if (loaded) nodes.clear(); + nodes.clear(); + check_audio(xml.getAttribute("patchbay","audio","",0),media_path); init(xml.getAttribute("patchbay","ID","",0),xml.getValue("patchbay","",0)); if(xml.pushTag("patchbay")) { int n1=xml.getNumTags("node"); diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp index 3f20923..679cea1 100644 --- a/rotord/src/rendercontext.cpp +++ b/rotord/src/rendercontext.cpp @@ -21,20 +21,20 @@ void Render_context::runTask() { for (auto a: analysers) { processors.push_back(dynamic_cast<Audio_processor*>(a)); } - if (load_audio(audio_filename,processors)) { - audio_loaded=true; + if (load_audio(graph.audio_filename,processors)) { + graph.audio_loaded=true; state=IDLE; } else { //an error occurred: TODO have to clean up allocated data. autoptr? - audio_loaded=false; + graph.audio_loaded=false; state=IDLE; } } if(cmd.task==RENDER) { state=RENDERING; renders[cmd.uid]=Render_status(RENDERING); - if(graph.video_render(output_filename,audio_filename,output_framerate,progress)){ + if(graph.video_render(output_filename,output_framerate,progress)){ state=IDLE; renders[cmd.uid].status=RENDER_READY; } @@ -96,8 +96,8 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H if (command.method=="PUT") { //get audio file location and initiate analysis if (command.body!="") { if (state==IDLE) { - audio_filename=media_dir+command.body; //for now, store session variables in memory //check file exists - Poco::File f=Poco::File(audio_filename); + graph.audio_filename=media_dir+command.body; //for now, store session variables in memory //check file exists + Poco::File f=Poco::File(graph.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(Session_task(command.uid,ANALYSE_AUDIO)); @@ -126,7 +126,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H sprintf(c,"%02f",progress); XML.addValue("progress",string(c)); } - else if (audio_loaded) { + else if (graph.audio_loaded) { //not sure about this-- should this state be retained? //can the data only be read once? //for now @@ -142,7 +142,8 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H } if (command.method=="DELETE") { if (state==IDLE) { - audio_filename=""; + graph.audio_filename=""; + graph.audio_loaded=false; logger.information("Audio deleted"); XML.addValue("status","Audio deleted"); status=HTTPResponse::HTTP_OK; @@ -175,7 +176,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H status=HTTPResponse::HTTP_OK; logger.information("Loaded graph from http PUT body"); XML.addValue("status","Loaded graph from PUT body"); - if (audio_loaded) { + if (graph.audio_loaded) { add_queue(Session_task(command.uid,ANALYSE_AUDIO)); status=HTTPResponse::HTTP_OK; logger.information("Starting audio analysis for graph: "+command.commands[0]); @@ -195,7 +196,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H //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 - if (audio_loaded) { + if (graph.audio_loaded) { add_queue(Session_task(command.uid,ANALYSE_AUDIO)); status=HTTPResponse::HTTP_OK; logger.information("Starting audio analysis for graph: "+command.commands[0]); @@ -414,7 +415,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H bool Render_context::load_audio(const string &filename,vector<Audio_processor*> processors){ Logger& logger = Logger::get("Rotor"); - logger.information("Starting audio analysis"); + logger.information("Analysing "+filename); libav::audioloader loader; loader.setup(filename); diff --git a/rotord/src/rendercontext.h b/rotord/src/rendercontext.h index d28cd82..bf7bb11 100644 --- a/rotord/src/rendercontext.h +++ b/rotord/src/rendercontext.h @@ -2,7 +2,6 @@ #define RENDERCONTEXT_H #include "Poco/Task.h" -#include "Poco/File.h" #include "Poco/StringTokenizer.h" #include "rotor.h" @@ -53,7 +52,6 @@ namespace Rotor { audio_thumb=new Audio_thumbnailer(); state=IDLE; output_framerate=25.0f; - audio_loaded=false; xmlIO xml; if(xml.loadFile("settings.xml") ){ @@ -91,7 +89,7 @@ namespace Rotor { std::deque<Session_task> work_queue; std::unordered_map<string,Render_status> renders; Poco::Mutex mutex; //lock for access from parent thread - std::string audio_filename; + std::string output_filename; std::string graph_dir; std::string media_dir; @@ -101,7 +99,6 @@ namespace Rotor { Graph graph; Node_factory factory; float output_framerate; - bool audio_loaded; }; } diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index e96fffd..a769430 100755 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -14,6 +14,7 @@ #include "Poco/Net/HTTPResponse.h" #include "Poco/Logger.h" +#include "Poco/File.h" #include "Poco/Path.h" #include "Poco/Base64Encoder.h" #include "Poco/FileStream.h" @@ -1107,6 +1108,7 @@ namespace Rotor { Graph(){duration=20.0f;loaded = false;outW=640;outH=360;}; Graph(const string& _uid,const string& _desc){ init(_uid,_desc); + audio_loaded=false; }; void init(const string& _uid,const string& _desc){ uid=_uid; @@ -1121,22 +1123,26 @@ namespace Rotor { vector<Node*> find_nodes(const string &type); //could be a way of finding a set based on capabilities? Node* find_node(const string &type); bool signal_render(string &signal_xml,const float framerate); - bool video_render(const string &output_filename,const string &audio_filename,const float framerate,float& progress); + bool video_render(const string &output_filename,const float framerate,float& progress); bool load(string data,string media_path); bool loadFile(string &filename,string media_path); bool parseXml(string media_path); bool parseJson(string &data,string &media_path); bool set_resolution(int w,int h); bool preview(xmlIO &XML,string &node,string &format,int frame,int w,int h); + bool check_audio(string audio,string path); bool print_features(xmlIO &XML,string &node); bool loaded; float duration; float framerate; const string toString(); xmlIO xml; + bool audio_loaded; + string audio_filename; private: Node_factory factory; int outW,outH; + }; class Audio_thumbnailer: public Audio_processor { public: |
