// ---------------------------------------------------------------------------- void ofxThermitrack::processDataMultiPoints(){ points.clear(); // put data into string string temp = ""; for(int i=0; i<dataIn.size(); i++){ temp += (char)dataIn[i]; } // how many points are there? string numponts = temp.substr(1, 2); int nPoints = ofToInt(numponts); // todo: tidy this up, commented out for now if(nPoints > 0){ /* // get the string without the first 4 chars temp = temp.substr(4, temp.size()); // split the string into an array vector<string> vecstrResult; int startpos=0; int endpos = temp.find_first_of(",", startpos); while (endpos != -1){ vecstrResult.push_back(temp.substr(startpos, endpos-startpos)); // add to vector startpos = endpos+1; //jump past sep endpos = temp.find_first_of(",", startpos); // find next if(endpos==-1){ //lastone, so no 2nd param required to go to end of string vecstrResult.push_back(temp.substr(startpos)); } } for(int i=0; i<nPoints; i++){ //trackedPoints.push_back( irisysTrackPoint() ); //trackedPoints[i].id = (myNum*100)+ofToInt(vecstrResult[i*3]); // trackedPoints[i].pos.x = ofToInt(vecstrResult[(i*3)+1]); //trackedPoints[i].pos.y = ofToInt(vecstrResult[(i*3)+2]); //trackedPoints[i].posNormalised.x = trackedPoints[i].pos.x / pointMaxPosVal; //trackedPoints[i].posNormalised.y = trackedPoints[i].pos.y / pointMaxPosVal; //float txNorm = tx / (float)THERMITRACK_POINTS_MAXWIDTH; //float tyNorm = ty / (float)THERMITRACK_POINTS_MAXWIDTH; //addPoint(id, txNorm, tyNorm); }*/ } }
void ofApp::onFlipHorizChanged(const void * guiSender,bool & value){ ofParameter<int> * p = ( ofParameter<int> * ) guiSender; string idName = p->getName(); char lastChar = idName.at( idName.length() - 1 ); int camIdNumber= ofToInt(ofToString(lastChar))-1; cameras[camIdNumber]->setFlip(camParams[camIdNumber].camflipHoriz, camParams[camIdNumber].camflipVert); ofxOscMessage flipMessage; flipMessage.setAddress("/"+ofToString(camIdNumber+1)+"/flip" ); flipMessage.addIntArg(camParams[camIdNumber].camflipVert); flipMessage.addIntArg(camParams[camIdNumber].camflipHoriz); sender.sendMessage(flipMessage); }
void Session::newPosition(){ if(index < counter){ for(int i = 0; i < speed; i ++){ if(index < counter) { vector<string> tokens = ofSplitString(rows[index], ";"); float pos_x = ofToFloat(tokens[0]); float pos_y = ofToFloat(tokens[1]); int x = ofToInt(tokens[2]); int y = ofToInt(tokens[3]); int z = ofToInt(tokens[4]); app->addData(pos_x, pos_y, x, y, z); index = index + 1; } else{ break; } } } }
void mui::TextureAtlas::load( string absXmlPath, string absImgPath ){ ofLoadImage(tex, absImgPath); tex.setTextureWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); tex.setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); ofXml xml(absXmlPath); // xml.setTo(""); xml.setTo( "//" ); int numTiles = xml.getNumChildren(); for( int i = 0; i < numTiles; i++ ){ xml.setToChild(i); ofRectangle rect; rect.x = ofToInt(xml.getAttribute("x")); rect.y = ofToInt(xml.getAttribute("y")); rect.width = ofToInt(xml.getAttribute("w")); rect.height = ofToInt(xml.getAttribute("h")); rects[xml.getAttribute("n")] = rect; xml.setToParent(); } loaded = true; }
//-------------------------------------------------------------- void testApp::stringCutter(string str, vector<int> &ch, char knife){ std::stringstream tmpstr; ch.clear(); for(int i=0; i<str.length(); i++){ if(str[i] == knife){ int tmpi = ofToInt(tmpstr.str()); ch.push_back(tmpi); tmpstr.str(""); continue; }else{ tmpstr << str[i]; } } }
void testApp::processSerial() { // We read as many bytes as we can while(serial.available() > 0) { char myByte = serial.readByte(); // Read a single byte if(myByte == '\r') {} // Ignore carriage return else if(myByte == '\n') // Newline signals the end of a potentiometer value { potValue = ofToInt(buffer); buffer.clear(); } else buffer += myByte; // Append current char to our buffer } }
void cyrilApp::reloadFileBuffer(std::string filePath) { //cout << "File = " << filePath << endl; ofFile file = ofFile(filePath); if (file.getExtension() == "cy") { int whichEditor = ofToInt(removeExtension(file.getFileName())); if (whichEditor >= 0 && whichEditor <= 9) { editor.loadFile(filePath, whichEditor); //editor.update(); if (running[whichEditor]) { editor.currentBuffer = whichEditor; runScript(this); } } } if (file.getExtension() == "png") { //cout << "Loading image " << file.getFileName() << endl; int whichImg = ofToInt(removeExtension(file.getFileName())); (*_state.img)[whichImg] = new ofImage(filePath); //cout << "Loaded image type = " << ((*_state.img)[whichImg]->type) << endl; //(*_state.img)[whichImg]->setImageType(OF_IMAGE_COLOR_ALPHA); (*_state.img)[whichImg]->setAnchorPercent(0.5, 0.5); } }
void ParticleHandler::loadModel(string name){ bool addFaceCenter = true; string path="/Users/Tintamar/Work/BO/Chrone/tests/"; if(name=="")path+= "pyramid.obj"; else path+=name; ofFile file(path); ofBuffer buf= file.readToBuffer(); ofBuffer::Lines lines = buf.getLines(); int numVec = 0,numFace=0; for(auto l:lines){ if(l[0] == 'v'){ numVec++; } if (l[0] == 'f'){ numFace++; } } numParticles = numVec+(addFaceCenter?numFace:0); side = pow((double)numParticles,0.334); positionInit.resize(numParticles, MyMatrixType::ColsAtCompileTime); int idx=0; double wi = getWidthSpace()/2.0; for(auto l:lines){ if(l[0] == 'v'){ vector<string> ll = ofSplitString(l, " "); positionInit.row(idx)[0] = ofToFloat(ll[1])*wi; positionInit.row(idx)[1] = ofToFloat(ll[2])*wi; positionInit.row(idx)[2] = ofToFloat(ll[3])*wi; idx++; } if(l[0]=='f' && addFaceCenter){ vector<string> ll = ofSplitString(l, " "); int numCoins = ll.size()-1; Array<MatReal,3,1> middle; middle.setZero(); for(int i = 0 ; i < numCoins ; i++){ middle+=positionInit.row(ofToInt(ll[i+1])); } middle/=numCoins; positionInit.row(idx) = middle; idx++; } } setNumParticles(numParticles); }
void ofxPulseSensor::update(){ #ifdef TARGET_RASPBERRY_PI // GET THE DATA FROM YOUR RaspberryPi GPIO // Signal = analogIn.value; pushNewData(); #else // GET THE DATA FROM ARDUINO // string serialIn; unsigned char buffer[1]; while( serial.readBytes(buffer,1) > 0){ if (buffer[0] == '\n'){ break; } serialIn.push_back(buffer[0]); }; if ( serialIn[0] == 'B' ){ serialIn.erase(0,1); // Un comment to check your parameters // // cout << "Arduino BPM " << ofToInt(serialIn) << endl; // BPM = ofToInt(serialIn); } if ( serialIn[0] == 'Q' ){ serialIn.erase(0,1); // Un comment to check your parameters // // cout << "Arduino IBI " << ofToInt(serialIn) << endl; // IBI = ofToInt(serialIn); } if ( serialIn[0] == 'S' ){ serialIn.erase(0,1); Signal = ofToInt(serialIn); pushNewData(); } #endif cleanData(); calculateBPM(); }
void XBScene1::initStones() { svg.load("resources/Esc1Pianov02.svg"); //cout << "Scene 1 piano svg has " << ofToString(svg.getNumPath()) << endl; for (int i = 1; i < svg.getNumPath(); i++) { ofPath p = svg.getPathAt(i); // cout << "Path " << i << " ID: " << svg.getPathIdAt(i) << endl; // svg defaults to non zero winding which doesn't look so good as contours p.setPolyWindingMode(OF_POLY_WINDING_ODD); vector<ofPolyline> &lines = const_cast<vector<ofPolyline> &>(p.getOutline()); // for every line create a shape centered at zero and store its centroid for (int j = 0; j < (int) lines.size(); j++) { ofPolyline pl = lines[j].getResampledBySpacing(10); expandingPolyLine epl; epl.life = 0; epl.centroid = pl.getCentroid2D(); vector<ofPoint> points = pl.getVertices(); for (int k = 0; k < points.size(); k++) { // store the polyline for now epl.line.addVertex(points[k].x - epl.centroid.x, points[k].y - epl.centroid.y); // create a path out of the polyline so it can be drawn filled if (i == 0) { epl.path.newSubPath(); epl.path.moveTo(points[k].x - epl.centroid.x, points[k].y - epl.centroid.y); } else { epl.path.lineTo(points[k].x - epl.centroid.x, points[k].y - epl.centroid.y); } } epl.path.close(); epl.line.close(); stones.push_back(epl); } } string filePath = "resources/mapping_35_rows_midi.txt"; //Load file placed in bin/data ofFile file(filePath); if (!file.exists()) { ofLogError("The file " + filePath + " is missing"); } ofBuffer buffer(file); //Read file line by line for (ofBuffer::Line it = buffer.getLines().begin(), end = buffer.getLines().end(); it != end; ++it) { string line = *it; midiToRowMapping.push_back(ofToInt(line)); } }
void ofApp:: onHueChange(const void * guiSender,int & value){ ofParameter<int> * p = ( ofParameter<int> * ) guiSender; string idName = p->getName(); char lastChar = idName.at( idName.length() - 1 ); int camIdNumber= ofToInt(ofToString(lastChar))-1; if (!camParams[camIdNumber].camAutoBalance) { cameras[camIdNumber]->setHue(uint8_t(camParams[camIdNumber].camHue)); } ofxOscMessage hueMessage; hueMessage.setAddress("/"+ofToString(camIdNumber+1)+"/hue" ); hueMessage.addIntArg(camParams[camIdNumber].camHue); sender.sendMessage(hueMessage); }
void ofApp:: onGainChange(const void * guiSender,int & value){ ofParameter<int> * p = ( ofParameter<int> * ) guiSender; string idName = p->getName(); char lastChar = idName.at( idName.length() - 1 ); int camIdNumber= ofToInt(ofToString(lastChar))-1; if (!camParams[camIdNumber].camAutoGain) { cameras[camIdNumber]->setGain(uint8_t(camParams[camIdNumber].camGain)); } ofxOscMessage gainMessage; gainMessage.setAddress("/"+ofToString(camIdNumber+1)+"/gain" ); gainMessage.addIntArg(camParams[camIdNumber].camGain); sender.sendMessage(gainMessage); }
//---------------------------------------------------- // ON CURL response to JSON API // // Get curl response and send to correct Customer // void ofApp::urlResponse(ofHttpResponse &response){ int _customerIndex; ofLog() << "URL RESPONSE Name: " << response.request.name << " ID : " << ofToString(response.request.getID()); if(response.status==200) { _customerIndex = ofToInt(response.request.name); arrCustomers[_customerIndex].handleApiResponse(response.data.getText()); } }
Pager::Pager(map<string, string> &_attrs) : GuiNode(){ attrs = _attrs; pageDims.x = ofToInt(attrs["columns"]); pageDims.y = ofToInt(attrs["rows"]); numItemsPerPage = pageDims.x * pageDims.y; itemDims.x = 245; itemDims.y = 138; currentPage = 0; initialize(); exit = new GuiButton("cuts/exit_big.png"); exit->setPosition(ofVec2f(pos.x + 1320,pos.y - 200)); exit->setAttr("action", "close"); exit->setAttr("sfx","button11"); dir = _attrs["directory"]; if(dir == "audio/user"){ bReloader = true; } else { bReloader = false; } populate(dir); setPositions(); SubObMediator::Instance()->addObserver("audio-recording-complete", this); SubObMediator::Instance()->addObserver("button", this); }
void GuiNode::initialize(){ type = attrs["type"]; name = attrs["name"]; pos = stringToVec2f(attrs["pos"]); haveDelay = false; checkDelay = false; map<string,string>::iterator mIter; mIter = attrs.find("delay"); if(mIter != attrs.end()){ haveDelay = true; checkDelay = false; delayTime = ofToInt(attrs["delay"]); cout << "Setting Timer to " << delayTime << endl; } //size = stringToVec2f(attrs["size"]); }
//-------------------------------------------------------------- void ofApp::setup(){ viewParams.setName("View"); viewParams.add(scale.set("Zoom", 0.05, 0.05, 1)); viewParams.add(drawTrackPoints.set("Draw Tracker Points", true)); viewParams.add(drawMesh.set("Draw Point Cloud", true)); oscParameters.setName("OSC"); oscParameters.add(oscPort.set("OSC Port", "7777")); panel.setup(); panel.add(viewParams); panel.add(oscParameters); panel.loadFromFile("settimgs.xml"); receiver.setup(ofToInt(oscPort)); }
void PagerItem::makePreview(){ if(itemType != "audio"){ preview.loadImage(attrs["preview"]); } mediaPreview = new GuiMediaPreview(attrs); if(itemType == "audio"){ mediaPreview->setPosition(ofVec2f(-80,-80)); } else { mediaPreview->setPosition(ofVec2f(407,278)); } durationInt = ofToInt(duration); previewSheet = new GuiSheet(); previewSheet->addNode(mediaPreview); GuiConfigurator::Instance()->addSheet(attrs["path"],previewSheet); size.x = 253; size.y = 148; }
int OpponentModeller::getTotalHands() { string id = "0"; vector<string> r; vector< vector<string> > result = _db->query("SELECT COUNT(hand_id) FROM Hand WHERE hand_id IS NOT NULL;"); for(vector<vector<string> >::iterator it = result.begin(); it < result.end(); ++it) { vector<string> row = *it; r.push_back( row.at(0) ); } id = r[0]; r.clear(); r.shrink_to_fit(); result.clear(); result.shrink_to_fit(); return ofToInt(id); }
void ofApp::parseOsc(){ ofxOscMessage m; hasOSC = false; clusterUpdated = false; while(osc.getNextMessage(m)){ hasOSC = true; vector<string> ad =ofSplitString(m.getAddress(),"/"); // ofLog() << m.getAddress(); if(ad[1] == "attractor"){ int attractor = m.getArgAsInt32(0); string attractName = ofToString(attractor); if(m.getNumArgs() == 2){ attractors.erase(attractName); } else{ attractors[attractName] = ofVec3f(m.getArgAsFloat(1),m.getArgAsFloat(2),m.getNumArgs()==4?m.getArgAsFloat(3):0); } } if(ad.size()<2 )continue; if(ad[1] == "enveloppes"){ if(m.getNumArgs()!=enveloppes.size()){enveloppes.resize(m.getNumArgs());} for(int i = 0 ; i < m.getNumArgs();i++){enveloppes[i] = m.getArgAsFloat(i);} } if(ad.size()<3)continue; int num = ofToInt(ad[1]); if(ad[2] == "HPCP"){ if(m.getNumArgs()!=HPCP.size()){HPCP.resize(m.getNumArgs());} for(int i = 0 ; i < m.getNumArgs();i++){HPCP[i] = m.getArgAsFloat(i);} } else if(ad[2] == "MFCC"){ if(m.getNumArgs()!=MFCC.size()){MFCC.resize(m.getNumArgs());} for(int i = 0 ; i < m.getNumArgs();i++){MFCC[i] = (1+m.getArgAsFloat(i))/2;} } else if(ad[2] == "cluster"){ cluster = m.getArgAsInt(0); clusterUpdated = true; } } }
void Pager::populate(string _dir){ lister.allowExt("xml"); lister.listDir(dir); string folder = dir + "/"; for(int i = 0; i < lister.size(); i++){ PagerItem *tmpItemPtr = new PagerItem(lister.getPath(i)); tmpItemPtr->setAttr("target", activeTimeline); if(bReloader){ tmpItemPtr->setReloader(); } if(!bReloader && tmpItemPtr->getItemType() == "audio"){ int index = ofToInt(tmpItemPtr->getItemIndex()); items[index] = tmpItemPtr; } else { items[i] = tmpItemPtr; } } }
//---------- void TypeSelection::refresh() { if (this->connection) { auto & databse = this->connection->getConnection(); if (databse.isConnected()) { auto cacheSelection = this->getSelectionIndex(); this->clearOptions(); this->databaseID.clear(); auto result = databse.select("facetypes"); for(auto resultRow : result) { this->addOption(resultRow["NameShort"]); this->databaseID.insert(pair<string, int>(resultRow["NameShort"], ofToInt(resultRow["id"]))); } this->setSelection(cacheSelection); } } }
void SoundManager::setIndividualSampleVolume(const SoundObject& sample) { vector <string> splitString = ofSplitString(sample.getName(), "_"); for (vector <string>::reverse_iterator rit = splitString.rbegin(); rit!=splitString.rend(); ++rit) { if(ofIsStringInString((*rit), "vol")) { m_individualSampleVolume = (float)(ofToInt((*rit)))/100.0f; std::cout <<m_dateManager->getTime()<<"- SoundManager-> setSamples: individual volume: "<< m_individualSampleVolume << std::endl; return; } } m_individualSampleVolume = m_masterSampleVolume; std::cout <<m_dateManager->getTime()<<"- SoundManager-> setSamples: individual volume: "<< m_individualSampleVolume << std::endl; }
void setInputAudioDevice(){ auto device_list = sound.getDeviceList(); std::string device_name; for(auto i = 0; i < device_list.size(); ++i){ if(i == device_list.size()-1){ device_name += ofToString(device_list[i]); }else{ device_name += ofToString(device_list[i]) + "\n"; } } int selected_device_id = ofToInt(ofSystemTextBoxDialog(device_name)); sound.setDeviceID(selected_device_id); sound.setup(this, 0, 2, kSampleRate, kBufferSize, 4); left.assign(kBufferSize, 0.f); right.assign(kBufferSize, 0.f); }
void ofxCUPS::updatePrinterInfo() { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printerName.c_str(), NULL, num_dests, dests); const char *value; value = cupsGetOption("printer-state", dest->num_options, dest->options); // printf("%s printer-state: %s\n", dest->name, value ? value : "no description"); setPrinterState(ofToInt(value)); value = cupsGetOption("printer-state-reasons", dest->num_options, dest->options); // printf("%s printer-state-reasons: %s\n", dest->name, value ? value : "(no description)"); setPrinterInfo(ofToString(value)); cupsFreeDests(num_dests, dests); }
ofInterObj * demoAnim::searchForObject(ofTag & tag, int & _x, int & _y) { ofInterObj * ret=0; string where=tag.getAttribute("where"); string xTemp=tag.getAttribute("x"); string yTemp=tag.getAttribute("y"); vector<string> whSplit = ofSplitString(where, "[]."); if(whSplit[0]=="sidebar"){ if(whSplit.size()==2) ret=((*sideBar)[ofToInt(whSplit[1])]); if(whSplit.size()==3) ret=&((*(*sideBar)[ofToInt(whSplit[1])])[ofToInt(whSplit[2])]); } if(whSplit[0]=="openBar"){ if(whSplit.size()==2&&sideBar->openBar()){ if(whSplit[1]=="drop") ret=&((as_dynamic(sideBar->openBar()))->select); else ret=&((*(sideBar->openBar()))[ofToInt(whSplit[1])]); } } else if(whSplit[0]=="sidebarButton"){ if(whSplit.size()==2) ret=&((*sideBar)[ofToInt(whSplit[1])])->button; } else if(whSplit[0]=="base"){ if(whSplit.size()==1) ret=&(blocks->base); else if(whSplit.size()>=2&&whSplit[1]=="last") ret=searchBlock(whSplit,blocks->base.blocksOn.back(),2); else if(whSplit.size()>=2) ret=searchBlock(whSplit,blocks->base.blocksOn[ofToInt(whSplit[1])],2); } else if(whSplit[0]=="upload"){ ret=&blocks->base.uploadBut; //TODO: update the base block to include the upload button. } else if(whSplit[0]=="test"){ ret=&blocks->base.testBut; } vector<string> xSpl = ofSplitString(xTemp, "+-/*"); if(xSpl.size()==1) _x=ofToInt(xSpl[0]); else if(xSpl.size()==2) _x=operaterByChar(ret->w,xTemp[xSpl[0].length()],ofToFloat(xSpl[1])); vector<string> ySpl = ofSplitString(yTemp, "+-/*"); if(ySpl.size()==1) _y=ofToInt(ySpl[0]); else if(ySpl.size()==2) _y=operaterByChar(ret->h,yTemp[ySpl[0].length()],ofToFloat(ySpl[1])); return ret; }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ // do some typing! if ( key != OF_KEY_RETURN ){ if ( key == OF_KEY_BACKSPACE ){ if ( toSend.length() > 0 ){ toSend.erase(toSend.end()-1); } } else { toSend += key; } } else { // send to all clients string toSendy = "{\"red\":\"123\",\"green\":\"255\",\"blue\":\"100\"}"; server.send( toSendy ); messages.push_back("Sent: '" + toSendy + "' to "+ ofToString(server.getConnections().size())+" websockets" ); toSend = ""; } cout << toSend << " " << ofToInt("k") << endl; }
void ofApp:: onAutoGainAndShutterChange(const void * guiSender,bool & value){ ofParameter<int> * p = ( ofParameter<int> * ) guiSender; string idName = p->getName(); char lastChar = idName.at( idName.length() - 1 ); int camIdNumber= ofToInt(ofToString(lastChar))-1; cameras[camIdNumber]->setAutogain(camParams[camIdNumber].camAutoGain); ofxOscMessage autoGainMessage; autoGainMessage.setAddress("/"+ofToString(camIdNumber+1)+"/autoGain" ); autoGainMessage.addIntArg(camParams[camIdNumber].camAutoGain); sender.sendMessage(autoGainMessage); if (!cameras[camIdNumber]->getAutogain()) { cameras[camIdNumber]->setExposure(uint8_t(camParams[camIdNumber].camExposure)); cameras[camIdNumber]->setGain(uint8_t(camParams[camIdNumber].camGain)); } }
//-------------------------------------------------------------- // Reads and parses a message from the server. //-------------------------------------------------------------- void mpeClientTCP::read(string _serverInput) { out("Receiving: " + _serverInput); char c = _serverInput.at(0); if (c == 'G' || c == 'B' || c == 'I') { if (!allConnected) { if (DEBUG) out("all connected!"); allConnected = true; } // split into frame message and data message vector<string> info = ofSplitString(_serverInput, ":"); vector<string> frameMessage = ofSplitString(info[0], ","); int fc = ofToInt(frameMessage[1]); if (info.size() > 1) { // there is a message here with the frame event info.erase(info.begin()); dataMessage.clear(); dataMessage = info; bMessageAvailable = true; } else { bMessageAvailable = false; } // assume no arrays are available bIntsAvailable = false; bBytesAvailable = false; if (fc == frameCount) { rendering = true; frameCount++; // calculate new framerate float ms = getElapsedSeconds()*1000.0 - lastMs; fps = 1000.f / ms; lastMs = getElapsedSeconds()*1000.0; if (!autoMode) { parent->frameEvent(); } } } }
//-------------------------------------------------------------- void testApp::bangFired(ofxTLBangEventArgs& bang){ //This is our own custom flag protocol to enslave playback //on the sub timelines //a flag that is start 3 or stop 2 will start and stop those timelines vector<string> command = ofSplitString(bang.flag, " "); if(command.size() == 2){ int trackIndex = ofToInt(command[1]); if(trackIndex >= 0 && trackIndex < sublines.size()){ if(command[0] == "start"){ sublines[trackIndex]->play(); } else if(command[0] == "stop"){ sublines[trackIndex]->stop(); } } } }
//-------------------------------------------------------------- void galaxieApp::onNewMessage(string & byteReceived){ sendedByte = ofToInt(byteReceived); cout << "[Arduino] " << sendedByte << "\n"; if (sendedByte == 0) sendedByte = SENSOR_MAX + 100; if (stateGalaxie->getCurrentSceneID() == 3) { if (sendedByte < SENSOR_MAX) { countChange = 0; } else { if (countChange >= 0) countChange++; if (countChange > 20) { stateGalaxie->goToScene(INTERACTION); countChange = -1; } } } stateGalaxie->onNewMessage(byteReceived); }