summaryrefslogtreecommitdiff
path: root/rotord/rotor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/rotor.cpp')
-rw-r--r--rotord/rotor.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp
new file mode 100644
index 0000000..8af1f0b
--- /dev/null
+++ b/rotord/rotor.cpp
@@ -0,0 +1,96 @@
+#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<std::string>& 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="<status>Starting audio analysis: "+command[3]+"</status>\n";
+ }
+ else {
+ response.status=HTTPResponse::HTTP_NOT_FOUND;
+ response.description="<status>File "+command[3]+" not found</status>\n";
+ }
+ }
+ else {
+ response.status=HTTPResponse::HTTP_BAD_REQUEST;
+ response.description="<status>Rotor: session busy</status>\n";
+ }
+ }
+ }
+ if (command[0]=="GET") {
+ if (state==ANALYSING_AUDIO) {
+ response.description="<status>Rotor: analysing audio</status>\n";
+ char c[20];
+ sprintf(c,"%02f",audio_analyser.get_progress());
+ response.description+="<progress>"+string(c)+"</progress>\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="<status>Rotor: audio ready</status>\n";
+ response.description+="<beats>";
+ for (auto& i: audio_analyser.beats) { //is actually giving no data?
+ char c[20];
+ sprintf(c,"%02f",i);
+ response.description+="<beat>"+string(c)+"</beat>";
+ }
+ response.description+="\n</beats>";
+ 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 beggining to load from xml
+ }
+ }
+ }
+ return response;
+} \ No newline at end of file