#include "rotor.h" using namespace Rotor; string soname="qm-vamp-plugins"; string id="qm-tempotracker"; string myname=""; string output=""; int outputNo=0; void Render_context::runTask() { while (!isCancelled()) { int cmd=0; mutex.lock(); if (work_queue.size()){ cmd=work_queue[0]; work_queue.pop_front(); } mutex.unlock(); if (cmd==ANALYSE_AUDIO) { state=ANALYSING_AUDIO; audio_analyser.process(audio_filename); //vampHost::runPlugin("","qm-vamp-plugins","qm-tempotracker", "",0, audio_filename, cerr,true); state=AUDIO_READY; } sleep(100); } printf("Rotor: stopping thread\n"); } void Render_context::add_queue(int item) { mutex.lock(); work_queue.push_back(item); mutex.unlock(); } Command_response Render_context::session_command(const std::vector& command){ //method,id,command1,{command2,}{body} //here we allow the controlling server to communicate with running tasks Command_response response; if (command[2]=="audio") { if (command[0]=="PUT") { //get audio file location and initiate analysis if (command.size()>2) { if (state==IDLE) { //check file exists Poco::File f=Poco::File(command[3]); if (f.exists()) { //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? audio_filename=command[3]; //for now, store session variables in memory add_queue(ANALYSE_AUDIO); response.description="Starting audio analysis: "+command[3]+"\n"; } else { response.status=HTTPResponse::HTTP_NOT_FOUND; response.description="File "+command[3]+" not found\n"; } } else { response.status=HTTPResponse::HTTP_BAD_REQUEST; response.description="Rotor: session busy\n"; } } } if (command[0]=="GET") { if (state==ANALYSING_AUDIO) { response.description="Rotor: analysing audio\n"; char c[20]; sprintf(c,"%02f",audio_analyser.get_progress()); response.description+=""+string(c)+"\n"; } if (state==AUDIO_READY) { //not sure about this-- should this state be retained? //can the data only be read once? //for now response.description="Rotor: audio ready\n"; response.description+=""; for (auto& i: audio_analyser.beats) { //is actually giving no data? char c[20]; sprintf(c,"%02f",i); response.description+=""+string(c)+""; } response.description+="\n"; state=IDLE; } } } if (command[2]=="graph") { 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 Poco::File f=Poco::File(command[3]); if (f.exists()) { string graph_filename=command[3]; if (load_graph(graph_filename)) { response.description="Rotor: loaded graph "+command[3]+"\n"; } else { response.status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; //~/sources/poco-1.4.6-all/Net/include/Poco/Net/HTTPResponse.h response.description="Rotor: could not load graph "+command[3]+"\n"; } } else { response.status=HTTPResponse::HTTP_NOT_FOUND; response.description="File "+command[3]+" not found\n"; } } } } } return response; } bool Render_context::load_graph(string graph_filename){ return true; }