summaryrefslogtreecommitdiff
path: root/rotord
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-03-03 20:21:46 +0000
committerComment <tim@gray.(none)>2013-03-03 20:21:46 +0000
commit87b2dabd9dd692aa505ea1327893d719f56fa162 (patch)
treea731429afc7fa2ac4267ef48a07febdea8fa2299 /rotord
parent67a7395433c49c2e3ae193ca983e3349f68268eb (diff)
xml transfusion
Diffstat (limited to 'rotord')
-rw-r--r--rotord/01.xml48
-rwxr-xr-xrotord/ofUtils.cpp745
-rwxr-xr-xrotord/ofUtils.h223
-rw-r--r--rotord/rotor.cpp33
-rwxr-xr-xrotord/rotor.h1
-rwxr-xr-xrotord/xmlIO.cpp2
-rwxr-xr-xrotord/xmlIO.h2
7 files changed, 1046 insertions, 8 deletions
diff --git a/rotord/01.xml b/rotord/01.xml
new file mode 100644
index 0000000..dec3a05
--- /dev/null
+++ b/rotord/01.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<patchbay ID="0f7aa258-7c2f-11e2-abbd-133252267708">Off and on template ©Rotor 2013
+ <node ID="01" type="audioLoader">music track to analyse
+ <output ID="01" type="graph">beat (sawtooth)</output>
+ <output ID="03" type="graph">excitement</output>
+ </node>
+ <node ID="02" type="imageLoader" thumbnail="performance1.jpg">performance take 1
+ <output ID="01" type="image"/>
+ </node>
+ <node ID="03" type="imageLoader" thumbnail="performance1.jpg">performance take 2
+ <output ID="01" type="image"/>
+ </node>
+ <node ID="04" type="==">1
+ <input ID="01" from="01.01" type="graph"/>
+ <output ID="02" type="graph"/>
+ </node>
+ <node ID="05" type="toggle switch" >
+ <input ID="01" from="02.01" type="image"/>
+ <input ID="02" from="03.01" type="image"/>
+ <input ID="03" from="04.02" type="signal"/>
+ <output ID="04" type="image"/>
+ </node>
+ <node ID="06" type="frequency/offset" frequency="0.25" offset="1">
+ <input ID="01" from="01.01" type="graph"/>
+ <output ID="02" type="graph"/>
+ </node>
+ <node ID="07" type="*">2
+ <input ID="01" from="06.02" type="graph"/>
+ <output ID="02" type="graph"/>
+ </node>
+ <node ID="08" type="==">1
+ <input ID="01" from="06.02" type="graph"/>
+ <output ID="02" type="graph"/>
+ </node>
+ <node ID="09" type="videoBank" mode="pingpong">
+ <clip ID="01" file="sample.mov"/>
+ <input ID="01" from="08.02" type="graph"/>cycle switch
+ <output ID="02" type="image"/>
+ </node>
+ <node ID="10" type="shape" mode="triangle">
+ <input ID="01" from="07.02" type="graph"/>scale
+ <output ID="02" type="image"/>
+ </node>
+ <node ID="11" type="channel merge" >
+ <input from="02.01" type="scale"/>
+ <output ID="09" type="image"/>
+ </node>
+</patchbay>
diff --git a/rotord/ofUtils.cpp b/rotord/ofUtils.cpp
new file mode 100755
index 0000000..7d7d9cc
--- /dev/null
+++ b/rotord/ofUtils.cpp
@@ -0,0 +1,745 @@
+#include "ofUtils.h"
+//#include "ofImage.h"
+//#include "ofTypes.h"
+//#include "ofGraphics.h"
+//#include "ofAppRunner.h"
+
+#include "Poco/String.h"
+#include "Poco/LocalDateTime.h"
+#include "Poco/DateTimeFormatter.h"
+
+#include <cctype> // for toupper
+
+
+
+/*
+#ifdef TARGET_WIN32
+ #ifndef _MSC_VER
+ #include <unistd.h> // this if for MINGW / _getcwd
+ #include <sys/param.h> // for MAXPATHLEN
+ #endif
+#endif
+
+
+#if defined(TARGET_OF_IPHONE) || defined(TARGET_OSX ) || defined(TARGET_LINUX)
+ #include <sys/time.h>
+#endif
+
+#ifdef TARGET_OSX
+ #ifndef TARGET_OF_IPHONE
+ #include <mach-o/dyld.h>
+ #include <sys/param.h> // for MAXPATHLEN
+ #endif
+#endif
+
+#ifdef TARGET_WIN32
+ #include <mmsystem.h>
+ #ifdef _MSC_VER
+ #include <direct.h>
+ #endif
+
+#endif
+*/
+
+#ifndef MAXPATHLEN
+ #define MAXPATHLEN 1024
+#endif
+
+
+static bool enableDataPath = true;
+//static unsigned long startTime = ofGetSystemTime(); // better at the first frame ?? (currently, there is some delay from static init, to running.
+//static unsigned long startTimeMicros = ofGetSystemTimeMicros();
+
+/*
+//--------------------------------------
+unsigned long ofGetElapsedTimeMillis(){
+ return ofGetSystemTime() - startTime;
+}
+
+//--------------------------------------
+unsigned long ofGetElapsedTimeMicros(){
+ return ofGetSystemTimeMicros() - startTimeMicros;
+}
+
+//--------------------------------------
+float ofGetElapsedTimef(){
+ return ofGetElapsedTimeMicros() / 1000000.0f;
+}
+
+//--------------------------------------
+void ofResetElapsedTimeCounter(){
+ startTime = ofGetSystemTime();
+ startTimeMicros = ofGetSystemTimeMicros();
+}
+*/
+//=======================================
+// this is from freeglut, and used internally:
+/* Platform-dependent time in milliseconds, as an unsigned 32-bit integer.
+ * This value wraps every 49.7 days, but integer overflows cancel
+ * when subtracting an initial start time, unless the total time exceeds
+ * 32-bit, where the GLUT API return value is also overflowed.
+ */
+/*
+unsigned long ofGetSystemTime( ) {
+ #ifndef TARGET_WIN32
+ struct timeval now;
+ gettimeofday( &now, NULL );
+ return now.tv_usec/1000 + now.tv_sec*1000;
+ #else
+ #if defined(_WIN32_WCE)
+ return GetTickCount();
+ #else
+ return timeGetTime();
+ #endif
+ #endif
+}
+*/
+
+/*
+unsigned long ofGetSystemTimeMicros( ) {
+ #ifndef TARGET_WIN32
+ struct timeval now;
+ gettimeofday( &now, NULL );
+ return now.tv_usec + now.tv_sec*1000000;
+ #else
+ #if defined(_WIN32_WCE)
+ return GetTickCount()*1000;
+ #else
+ return timeGetTime()*1000;
+ #endif
+ #endif
+}
+*/
+//--------------------------------------------------
+unsigned int ofGetUnixTime(){
+ return (unsigned int)time(NULL);
+}
+
+//default ofGetTimestampString returns in this format: 2011-01-15-18-29-35-299
+//--------------------------------------------------
+string ofGetTimestampString(){
+ string timeFormat = "%Y-%m-%d-%H-%M-%S-%i";
+ Poco::LocalDateTime now;
+ return Poco::DateTimeFormatter::format(now, timeFormat);
+}
+
+//specify the string format - eg: %Y-%m-%d-%H-%M-%S-%i ( 2011-01-15-18-29-35-299 )
+//--------------------------------------------------
+string ofGetTimestampString(string timestampFormat){
+ Poco::LocalDateTime now;
+ return Poco::DateTimeFormatter::format(now, timestampFormat);
+}
+
+//--------------------------------------------------
+int ofGetSeconds(){
+ time_t curr;
+ tm local;
+ time(&curr);
+ local =*(localtime(&curr));
+ return local.tm_sec;
+}
+
+//--------------------------------------------------
+int ofGetMinutes(){
+ time_t curr;
+ tm local;
+ time(&curr);
+ local =*(localtime(&curr));
+ return local.tm_min;
+}
+
+//--------------------------------------------------
+int ofGetHours(){
+ time_t curr;
+ tm local;
+ time(&curr);
+ local =*(localtime(&curr));
+ return local.tm_hour;
+}
+
+//--------------------------------------------------
+int ofGetYear(){
+ time_t curr;
+ tm local;
+ time(&curr);
+ local =*(localtime(&curr));
+ int year = local.tm_year + 1900;
+ return year;
+}
+
+//--------------------------------------------------
+int ofGetMonth(){
+ time_t curr;
+ tm local;
+ time(&curr);
+ local =*(localtime(&curr));
+ int month = local.tm_mon + 1;
+ return month;
+}
+
+//--------------------------------------------------
+int ofGetDay(){
+ time_t curr;
+ tm local;
+ time(&curr);
+ local =*(localtime(&curr));
+ return local.tm_mday;
+}
+
+//--------------------------------------------------
+int ofGetWeekday(){
+ time_t curr;
+ tm local;
+ time(&curr);
+ local =*(localtime(&curr));
+ return local.tm_wday;
+}
+
+//--------------------------------------------------
+void ofEnableDataPath(){
+ enableDataPath = true;
+}
+
+//--------------------------------------------------
+void ofDisableDataPath(){
+ enableDataPath = false;
+}
+
+//--------------------------------------------------
+//use ofSetDataPathRoot() to override this
+static string & dataPathRoot(){
+#if defined TARGET_OSX
+ static string * dataPathRoot = new string("../../../data/");
+#elif defined TARGET_ANDROID
+ static string * dataPathRoot = new string("sdcard/");
+#elif defined(TARGET_LINUX)
+ static string * dataPathRoot = new string(ofFilePath::join(ofFilePath::getCurrentExeDir(), "data/"));
+#else
+ static string * dataPathRoot = new string("data/");
+#endif
+ return *dataPathRoot;
+}
+
+static bool & isDataPathSet(){
+ static bool * dataPathSet = new bool(false);
+ return * dataPathSet;
+}
+
+//--------------------------------------------------
+void ofSetDataPathRoot(string newRoot){
+ string newPath = "";
+
+ #ifdef TARGET_OSX
+ #ifndef TARGET_OF_IPHONE
+ char path[MAXPATHLEN];
+ uint32_t size = sizeof(path);
+
+ if (_NSGetExecutablePath(path, &size) == 0){
+ //printf("executable path is %s\n", path);
+ string pathStr = string(path);
+
+ //theo: check this with having '/' as a character in a folder name - OSX treats the '/' as a ':'
+ //checked with spaces too!
+
+ vector < string> pathBrokenUp = ofSplitString( pathStr, "/");
+
+ newPath = "";
+
+ for(int i = 0; i < pathBrokenUp.size()-1; i++){
+ newPath += pathBrokenUp[i];
+ newPath += "/";
+ }
+
+ //cout << newPath << endl; // some sanity checks here
+ //system( "pwd" );
+
+ chdir ( newPath.c_str() );
+ //system("pwd");
+ }else{
+ ofLog(OF_LOG_FATAL_ERROR, "buffer too small; need size %u\n", size);
+ }
+ #endif
+ #endif
+
+ dataPathRoot() = newRoot;
+ isDataPathSet() = true;
+}
+
+//--------------------------------------------------
+string ofToDataPath(string path, bool makeAbsolute){
+
+ if (!isDataPathSet())
+ ofSetDataPathRoot(dataPathRoot());
+
+ if( enableDataPath ){
+
+ //check if absolute path has been passed or if data path has already been applied
+ //do we want to check for C: D: etc ?? like substr(1, 2) == ':' ??
+ if( path.length()==0 || (path.substr(0,1) != "/" && path.substr(1,1) != ":" && path.substr(0,dataPathRoot().length()) != dataPathRoot())){
+ path = dataPathRoot()+path;
+ }
+
+ if(makeAbsolute && (path.length()==0 || path.substr(0,1) != "/")){
+ /*
+ #if !defined( TARGET_OF_IPHONE) & !defined(TARGET_ANDROID)
+
+ #ifndef TARGET_WIN32
+ char currDir[1024];
+ path = "/"+path;
+ path = getcwd(currDir, 1024)+path;
+
+ #else
+
+ char currDir[1024];
+ path = "\\"+path;
+ path = _getcwd(currDir, 1024)+path;
+ std::replace( path.begin(), path.end(), '/', '\\' ); // fix any unixy paths...
+
+
+ #endif
+
+
+ #else
+ //do we need iphone specific code here?
+ #endif
+ */
+ }
+
+ }
+ return path;
+}
+
+//----------------------------------------
+template <>
+string ofToHex(const string& value) {
+ ostringstream out;
+ // how many bytes are in the string
+ int numBytes = value.size();
+ for(int i = 0; i < numBytes; i++) {
+ // print each byte as a 2-character wide hex value
+ out << setfill('0') << setw(2) << hex << (unsigned int) ((unsigned char)value[i]);
+ }
+ return out.str();
+}
+
+//----------------------------------------
+string ofToHex(const char* value) {
+ // this function is necessary if you want to print a string
+ // using a syntax like ofToHex("test")
+ return ofToHex((string) value);
+}
+
+//----------------------------------------
+int ofToInt(const string& intString) {
+ int x = 0;
+ istringstream cur(intString);
+ cur >> x;
+ return x;
+}
+
+//----------------------------------------
+int ofHexToInt(const string& intHexString) {
+ int x = 0;
+ istringstream cur(intHexString);
+ cur >> hex >> x;
+ return x;
+}
+
+//----------------------------------------
+char ofHexToChar(const string& charHexString) {
+ int x = 0;
+ istringstream cur(charHexString);
+ cur >> hex >> x;
+ return (char) x;
+}
+
+//----------------------------------------
+float ofHexToFloat(const string& floatHexString) {
+ union intFloatUnion {
+ int x;
+ float f;
+ } myUnion;
+ myUnion.x = 0;
+ istringstream cur(floatHexString);
+ cur >> hex >> myUnion.x;
+ return myUnion.f;
+}
+
+//----------------------------------------
+string ofHexToString(const string& stringHexString) {
+ stringstream out;
+ stringstream stream(stringHexString);
+ // a hex string has two characters per byte
+ int numBytes = stringHexString.size() / 2;
+ for(int i = 0; i < numBytes; i++) {
+ string curByte;
+ // grab two characters from the hex string
+ stream >> setw(2) >> curByte;
+ // prepare to parse the two characters
+ stringstream curByteStream(curByte);
+ int cur = 0;
+ // parse the two characters as a hex-encoded int
+ curByteStream >> hex >> cur;
+ // add the int as a char to our output stream
+ out << (char) cur;
+ }
+ return out.str();
+}
+
+//----------------------------------------
+float ofToFloat(const string& floatString) {
+ float x = 0;
+ istringstream cur(floatString);
+ cur >> x;
+ return x;
+}
+
+//----------------------------------------
+bool ofToBool(const string& boolString) {
+ static const string trueString = "true";
+ static const string falseString = "false";
+ string lower = Poco::toLower(boolString);
+ if(lower == trueString) {
+ return true;
+ }
+ if(lower == falseString) {
+ return false;
+ }
+ bool x = false;
+ istringstream cur(lower);
+ cur >> x;
+ return x;
+}
+
+//----------------------------------------
+char ofToChar(const string& charString) {
+ char x = '\0';
+ istringstream cur(charString);
+ cur >> x;
+ return x;
+}
+
+//----------------------------------------
+template <> string ofToBinary(const string& value) {
+ stringstream out;
+ int numBytes = value.size();
+ for(int i = 0; i < numBytes; i++) {
+ bitset<8> bitBuffer(value[i]);
+ out << bitBuffer;
+ }
+ return out.str();
+}
+
+//----------------------------------------
+string ofToBinary(const char* value) {
+ // this function is necessary if you want to print a string
+ // using a syntax like ofToBinary("test")
+ return ofToBinary((string) value);
+}
+
+//----------------------------------------
+int ofBinaryToInt(const string& value) {
+ const int intSize = sizeof(int) * 8;
+ bitset<intSize> binaryString(value);
+ return (int) binaryString.to_ulong();
+}
+
+//----------------------------------------
+char ofBinaryToChar(const string& value) {
+ const int charSize = sizeof(char) * 8;
+ bitset<charSize> binaryString(value);
+ return (char) binaryString.to_ulong();
+}
+
+//----------------------------------------
+float ofBinaryToFloat(const string& value) {
+ const int floatSize = sizeof(float) * 8;
+ bitset<floatSize> binaryString(value);
+ union ulongFloatUnion {
+ unsigned long result;
+ float f;
+ } myUFUnion;
+ myUFUnion.result = binaryString.to_ulong();
+ return myUFUnion.f;
+}
+//----------------------------------------
+string ofBinaryToString(const string& value) {
+ ostringstream out;
+ stringstream stream(value);
+ bitset<8> byteString;
+ int numBytes = value.size() / 8;
+ for(int i = 0; i < numBytes; i++) {
+ stream >> byteString;
+ out << (char) byteString.to_ulong();
+ }
+ return out.str();
+}
+
+//--------------------------------------------------
+vector <string> ofSplitString(const string & source, const string & delimiter, bool ignoreEmpty, bool trim) {
+ vector<string> result;
+ if (delimiter.empty()) {
+ result.push_back(source);
+ return result;
+ }
+ string::const_iterator substart = source.begin(), subend;
+ while (true) {
+ subend = search(substart, source.end(), delimiter.begin(), delimiter.end());
+ string sub(substart, subend);
+ if(trim) {
+ Poco::trimInPlace(sub);
+ }
+ if (!ignoreEmpty || !sub.empty()) {
+ result.push_back(sub);
+ }
+ if (subend == source.end()) {
+ break;
+ }
+ substart = subend + delimiter.size();
+ }
+ return result;
+}
+
+//--------------------------------------------------
+string ofJoinString(vector <string> stringElements, const string & delimiter){
+ string resultString = "";
+ int numElements = stringElements.size();
+
+ for(int k = 0; k < numElements; k++){
+ if( k < numElements-1 ){
+ resultString += stringElements[k] + delimiter;
+ } else {
+ resultString += stringElements[k];
+ }
+ }
+
+ return resultString;
+}
+
+//--------------------------------------------------
+void ofStringReplace(string& input, string searchStr, string replaceStr){
+ size_t uPos = 0;
+ size_t uFindLen = searchStr.length();
+ size_t uReplaceLen = replaceStr.length();
+
+ if( uFindLen == 0 ){
+ return;
+ }
+
+ for( ;(uPos = input.find( searchStr, uPos )) != std::string::npos; ){
+ input.replace( uPos, uFindLen, replaceStr );
+ uPos += uReplaceLen;
+ }
+}
+
+//--------------------------------------------------
+bool ofIsStringInString(string haystack, string needle){
+ return ( strstr(haystack.c_str(), needle.c_str() ) != NULL );
+}
+
+//--------------------------------------------------
+string ofToLower(const string & src){
+ string dst(src);
+ transform(src.begin(),src.end(),dst.begin(),::tolower);
+ return dst;
+}
+
+//--------------------------------------------------
+string ofToUpper(const string & src){
+ string dst(src);
+ transform(src.begin(),src.end(),dst.begin(),::toupper);
+ return dst;
+}
+
+//--------------------------------------------------
+string ofVAArgsToString(const char * format, ...){
+ // variadic args to string:
+ // http://www.codeproject.com/KB/string/string_format.aspx
+ static char aux_buffer[10000];
+ string retStr("");
+ if (NULL != format){
+
+ va_list marker;
+
+ // initialize variable arguments
+ va_start(marker, format);
+
+ // Get formatted string length adding one for NULL
+ size_t len = vsprintf(aux_buffer, format, marker) + 1;
+
+ // Reset variable arguments
+ va_end(marker);
+
+ if (len > 0)
+ {
+ va_list args;
+
+ // initialize variable arguments
+ va_start(args, format);
+
+ // Create a char vector to hold the formatted string.
+ vector<char> buffer(len, '\0');
+ vsprintf(&buffer[0], format, args);
+ retStr = &buffer[0];
+ va_end(args);
+ }
+
+ }
+ return retStr;
+}
+
+string ofVAArgsToString(const char * format, va_list args){
+ // variadic args to string:
+ // http://www.codeproject.com/KB/string/string_format.aspx
+ char aux_buffer[10000];
+ string retStr("");
+ if (NULL != format){
+
+ // Get formatted string length adding one for NULL
+ vsprintf(aux_buffer, format, args);
+ retStr = aux_buffer;
+
+ }
+ return retStr;
+}
+
+/*
+//--------------------------------------------------
+void ofLaunchBrowser(string url){
+
+ // http://support.microsoft.com/kb/224816
+
+ //make sure it is a properly formatted url
+ if(Poco::icompare(url.substr(0,7), "http://") != 0 &&
+ Poco::icompare(url.substr(0,8), "https://") != 0) {
+ ofLog(OF_LOG_WARNING, "ofLaunchBrowser: url must begin http:// or https://");
+ return;
+ }
+
+ //----------------------------
+ #ifdef TARGET_WIN32
+ //----------------------------
+
+ #if (_MSC_VER)
+ // microsoft visual studio yaks about strings, wide chars, unicode, etc
+ ShellExecuteA(NULL, "open", url.c_str(),
+ NULL, NULL, SW_SHOWNORMAL);
+ #else
+ ShellExecute(NULL, "open", url.c_str(),
+ NULL, NULL, SW_SHOWNORMAL);
+ #endif
+
+ //----------------------------
+ #endif
+ //----------------------------
+
+ //--------------------------------------
+ #ifdef TARGET_OSX
+ //--------------------------------------
+ // ok gotta be a better way then this,
+ // this is what I found...
+ string commandStr = "open "+url;
+ system(commandStr.c_str());
+ //----------------------------
+ #endif
+ //----------------------------
+
+ //--------------------------------------
+ #ifdef TARGET_LINUX
+ //--------------------------------------
+ string commandStr = "xdg-open "+url;
+ int ret = system(commandStr.c_str());
+ if(ret!=0) ofLog(OF_LOG_ERROR,"ofLaunchBrowser: couldn't open browser");
+ //----------------------------
+ #endif
+ //----------------------------
+}
+
+//--------------------------------------------------
+string ofGetVersionInfo(){
+ string version;
+ stringstream sstr;
+ sstr << "of version: " << OF_VERSION << endl;
+ return sstr.str();
+}
+*/
+//---- new to 006
+//from the forums http://www.openframeworks.cc/forum/viewtopic.php?t=1413
+/*
+//--------------------------------------------------
+void ofSaveScreen(string filename) {
+ ofImage screen;
+ screen.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR);
+ screen.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
+ screen.saveImage(filename);
+}
+
+//--------------------------------------------------
+void ofSaveViewport(string filename) {
+ // because ofSaveScreen doesn't related to viewports
+ ofImage screen;
+ ofRectangle view = ofGetCurrentViewport();
+ screen.allocate(view.width, view.height, OF_IMAGE_COLOR);
+ screen.grabScreen(0, 0, view.width, view.height);
+ screen.saveImage(filename);
+}
+
+//--------------------------------------------------
+int saveImageCounter = 0;
+void ofSaveFrame(bool bUseViewport){
+ string fileName = ofToString(saveImageCounter) + ".png";
+ if (bUseViewport){
+ ofSaveViewport(fileName);
+ } else {
+ ofSaveScreen(fileName);
+ }
+ saveImageCounter++;
+}
+
+//--------------------------------------------------
+string ofSystem(string command){
+ FILE * ret = NULL;
+#ifdef TARGET_WIN32
+ ret = _popen(command.c_str(),"r");
+#else
+ ret = popen(command.c_str(),"r");
+#endif
+
+ string strret;
+ char c;
+
+ if (ret == NULL){
+ ofLogError() << "ofSystem: error opening return file";
+ }else{
+ do {
+ c = fgetc (ret);
+ strret += c;
+ } while (c != EOF);
+ fclose (ret);
+ }
+
+ return strret;
+}
+
+//--------------------------------------------------
+ofTargetPlatform ofGetTargetPlatform(){
+#ifdef TARGET_LINUX
+ if(ofSystem("uname -m").find("x86_64")==0)
+ return OF_TARGET_LINUX64;
+ else
+ return OF_TARGET_LINUX;
+#elif defined(TARGET_OSX)
+ return OF_TARGET_OSX;
+#elif defined(TARGET_WIN32)
+ #if (_MSC_VER)
+ return OF_TARGET_WINVS;
+ #else
+ return OF_TARGET_WINGCC;
+ #endif
+#elif defined(TARGET_ANDROID)
+ return OF_TARGET_ANDROID;
+#elif defined(TARGET_OF_IPHONE)
+ return OF_TARGET_IPHONE;
+#endif
+}
+*/ \ No newline at end of file
diff --git a/rotord/ofUtils.h b/rotord/ofUtils.h
new file mode 100755
index 0000000..0567e22
--- /dev/null
+++ b/rotord/ofUtils.h
@@ -0,0 +1,223 @@
+#pragma once
+
+//#include "ofConstants.h"
+
+
+// core: ---------------------------
+#include <cstdio>
+#include <cstdarg>
+#include <cmath>
+#include <ctime>
+#include <cstdlib>
+#include <string>
+#include <iostream>
+#include <vector>
+#include <cstring>
+#include <sstream> //for ostringsream
+#include <iomanip> //for setprecision
+#include <fstream>
+#include <algorithm>
+
+#include <bitset> // for ofToBinary
+
+
+
+
+//#include "ofLog.h"
+
+/*#ifdef TARGET_WIN32 // for ofLaunchBrowser
+ #include <shellapi.h>
+#endif
+*/
+
+
+using namespace std;
+
+int ofNextPow2(int input);
+
+void ofResetElapsedTimeCounter(); // this happens on the first frame
+float ofGetElapsedTimef();
+unsigned long ofGetElapsedTimeMillis();
+unsigned long ofGetElapsedTimeMicros();
+int ofGetFrameNum();
+
+int ofGetSeconds();
+int ofGetMinutes();
+int ofGetHours();
+
+//number of seconds since 1970
+unsigned int ofGetUnixTime();
+
+
+/*
+unsigned long ofGetSystemTime( ); // system time in milliseconds;
+unsigned long ofGetSystemTimeMicros( ); // system time in microseconds;
+
+ //returns
+string ofGetTimestampString();
+string ofGetTimestampString(string timestampFormat);
+
+
+int ofGetYear();
+int ofGetMonth();
+int ofGetDay();
+int ofGetWeekday();
+
+void ofLaunchBrowser(string url);
+*/
+void ofEnableDataPath();
+void ofDisableDataPath();
+string ofToDataPath(string path, bool absolute=false);
+
+template<class T>
+void ofRandomize(vector<T>& values) {
+ random_shuffle(values.begin(), values.end());
+}
+
+template<class T, class BoolFunction>
+void ofRemove(vector<T>& values, BoolFunction shouldErase) {
+ values.erase(remove_if(values.begin(), values.end(), shouldErase), values.end());
+}
+
+template<class T>
+void ofSort(vector<T>& values) {
+ sort(values.begin(), values.end());
+}
+template<class T, class BoolFunction>
+void ofSort(vector<T>& values, BoolFunction compare) {
+ sort(values.begin(), values.end(), compare);
+}
+
+template <class T>
+unsigned int ofFind(const vector<T>& values, const T& target) {
+ return distance(values.begin(), find(values.begin(), values.end(), target));
+}
+
+template <class T>
+bool ofContains(const vector<T>& values, const T& target) {
+ return ofFind(values, target) != values.size();
+}
+
+//set the root path that ofToDataPath will use to search for files relative to the app
+//the path must have a trailing slash (/) !!!!
+void ofSetDataPathRoot( string root );
+
+template <class T>
+string ofToString(const T& value){
+ ostringstream out;
+ out << value;
+ return out.str();
+}
+
+/// like sprintf "%4f" format, in this example precision=4
+template <class T>
+string ofToString(const T& value, int precision){
+ ostringstream out;
+ out << fixed << setprecision(precision) << value;
+ return out.str();
+}
+
+/// like sprintf "% 4d" or "% 4f" format, in this example width=4, fill=' '
+template <class T>
+string ofToString(const T& value, int width, char fill ){
+ ostringstream out;
+ out << fixed << setfill(fill) << setw(width) << value;
+ return out.str();
+}
+
+/// like sprintf "%04.2d" or "%04.2f" format, in this example precision=2, width=4, fill='0'
+template <class T>
+string ofToString(const T& value, int precision, int width, char fill ){
+ ostringstream out;
+ out << fixed << setfill(fill) << setw(width) << setprecision(precision) << value;
+ return out.str();
+}
+
+template<class T>
+string ofToString(const vector<T>& values) {
+ stringstream out;
+ int n = values.size();
+ out << "{";
+ if(n > 0) {
+ for(int i = 0; i < n - 1; i++) {
+ out << values[i] << ", ";
+ }
+ out << values[n - 1];
+ }
+ out << "}";
+ return out.str();
+}
+
+template <class T>
+string ofToHex(const T& value) {
+ ostringstream out;
+ // pretend that the value is a bunch of bytes
+ unsigned char* valuePtr = (unsigned char*) &value;
+ // the number of bytes is determined by the datatype
+ int numBytes = sizeof(T);
+ // the bytes are stored backwards (least significant first)
+ for(int i = numBytes - 1; i >= 0; i--) {
+ // print each byte out as a 2-character wide hex value
+ out << setfill('0') << setw(2) << hex << (int) valuePtr[i];
+ }
+ return out.str();
+}
+template <>
+string ofToHex(const string& value);
+string ofToHex(const char* value);
+
+int ofHexToInt(const string& intHexString);
+char ofHexToChar(const string& charHexString);
+float ofHexToFloat(const string& floatHexString);
+string ofHexToString(const string& stringHexString);
+
+int ofToInt(const string& intString);
+char ofToChar(const string& charString);
+float ofToFloat(const string& floatString);
+bool ofToBool(const string& boolString);
+
+template <class T>
+string ofToBinary(const T& value) {
+ ostringstream out;
+ const char* data = (const char*) &value;
+ // the number of bytes is determined by the datatype
+ int numBytes = sizeof(T);
+ // the bytes are stored backwards (least significant first)
+ for(int i = numBytes - 1; i >= 0; i--) {
+ bitset<8> cur(data[i]);
+ out << cur;
+ }
+ return out.str();
+}
+template <>
+string ofToBinary(const string& value);
+string ofToBinary(const char* value);
+
+int ofBinaryToInt(const string& value);
+char ofBinaryToChar(const string& value);
+float ofBinaryToFloat(const string& value);
+string ofBinaryToString(const string& value);
+
+string ofGetVersionInfo();
+
+void ofSaveScreen(string filename);
+void ofSaveFrame(bool bUseViewport = false);
+void ofSaveViewport(string filename);
+
+//--------------------------------------------------
+vector <string> ofSplitString(const string & source, const string & delimiter, bool ignoreEmpty = false, bool trim = false);
+string ofJoinString(vector <string> stringElements, const string & delimiter);
+void ofStringReplace(string& input, string searchStr, string replaceStr);
+bool ofIsStringInString(string haystack, string needle);
+
+string ofToLower(const string & src);
+string ofToUpper(const string & src);
+
+string ofVAArgsToString(const char * format, ...);
+string ofVAArgsToString(const char * format, va_list args);
+
+string ofSystem(string command);
+
+//ofTargetPlatform ofGetTargetPlatform();
+
+
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp
index 8af1f0b..8360824 100644
--- a/rotord/rotor.cpp
+++ b/rotord/rotor.cpp
@@ -48,22 +48,22 @@ Command_response Render_context::session_command(const std::vector<std::string>&
//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";
+ response.description="<status context='"+command[1]+"'>Starting audio analysis: "+command[3]+"</status>\n";
}
else {
response.status=HTTPResponse::HTTP_NOT_FOUND;
- response.description="<status>File "+command[3]+" not found</status>\n";
+ response.description="<status context='"+command[1]+"'>File "+command[3]+" not found</status>\n";
}
}
else {
response.status=HTTPResponse::HTTP_BAD_REQUEST;
- response.description="<status>Rotor: session busy</status>\n";
+ response.description="<status context='"+command[1]+"'>Rotor: session busy</status>\n";
}
}
}
if (command[0]=="GET") {
if (state==ANALYSING_AUDIO) {
- response.description="<status>Rotor: analysing audio</status>\n";
+ response.description="<status context='"+command[1]+"'>Rotor: analysing audio</status>\n";
char c[20];
sprintf(c,"%02f",audio_analyser.get_progress());
response.description+="<progress>"+string(c)+"</progress>\n";
@@ -72,7 +72,7 @@ Command_response Render_context::session_command(const std::vector<std::string>&
//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="<status context='"+command[1]+"'>Rotor: audio ready</status>\n";
response.description+="<beats>";
for (auto& i: audio_analyser.beats) { //is actually giving no data?
char c[20];
@@ -88,9 +88,30 @@ Command_response Render_context::session_command(const std::vector<std::string>&
if (command[0]=="PUT") { //get new graph from file
if (command.size()>2) {
//should interrupt whatever is happening?
- //before beggining to load from xml
+ //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="<status context='"+command[1]+"'>Rotor: loaded graph "+command[3]+"</status>\n";
+ }
+ else {
+ response.status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; //~/sources/poco-1.4.6-all/Net/include/Poco/Net/HTTPResponse.h
+ response.description="<status context='"+command[1]+"'>Rotor: could not load graph "+command[3]+"</status>\n";
+ }
+ }
+ else {
+ response.status=HTTPResponse::HTTP_NOT_FOUND;
+ response.description="<status context='"+command[1]+"'>File "+command[3]+" not found</status>\n";
+ }
+ }
}
}
}
return response;
+}
+
+bool Render_context::load_graph(string graph_filename){
+ return true;
} \ No newline at end of file
diff --git a/rotord/rotor.h b/rotord/rotor.h
index 52687ca..7c27c36 100755
--- a/rotord/rotor.h
+++ b/rotord/rotor.h
@@ -145,6 +145,7 @@ namespace Rotor {
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();
diff --git a/rotord/xmlIO.cpp b/rotord/xmlIO.cpp
index 5ff404e..d83380c 100755
--- a/rotord/xmlIO.cpp
+++ b/rotord/xmlIO.cpp
@@ -198,7 +198,7 @@ bool xmlIO::pushTag(const string& tag, int which){
level++;
return true;
}else{
- ofLog( OF_LOG_ERROR, "pushTag - <" + tag + "> tag not found");
+ //ofLog( OF_LOG_ERROR, "pushTag - <" + tag + "> tag not found");
}
return false;
diff --git a/rotord/xmlIO.h b/rotord/xmlIO.h
index 7661acc..84db7ca 100755
--- a/rotord/xmlIO.h
+++ b/rotord/xmlIO.h
@@ -2,7 +2,7 @@
#define __xmlIO_
//#include "ofMain.h"
-//based on xmlIO from openframeworks, manythanks!
+//based on xmlSettings from openframeworks, manythanks!
#include <string.h>
#include <vector>
#include "tinyxml.h"