//-------------------------------------------------------------- void ofApp::update(){ // update the sound playing system: ofSoundUpdate(); // (5) grab the fft, and put in into a "smoothed" array, // by taking maximums, as peaks and then smoothing downward float * val = ofSoundGetSpectrum(nBandsToGet); // request 128 values for fft for (int i = 0;i < nBandsToGet; i++){ // let the smoothed calue sink to zero fftSmoothed[i] *= 0.96f; // take the max, either the smoothed or the incoming: if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i]; } // ws.play(); serialTest = serial.available(); if (serialTest) { cout << "blahh" << endl; } //@add 2015/10/20 ######################################## serialString = ""; serialString = ofxGetSerialString(serial,'\n'); //read until end of line if (serialString.length() > 0) { readTime = ofGetElapsedTimef(); ofLogVerbose() << "serialString = " << serialString << "\n"; } }
//-------------------------------------------------------------- void testApp::update(){ current_color = ofColor(current_color.r, current_color.g, current_color.b, current_alpha); if(current_sides==0){ current_bk = current_color; current_preview = ofColor(0,0,0); } else { if(current_color.r == current_bk.r && current_color.g == current_bk.g && current_color.b == current_bk.b){ current_preview = ofColor(0,0,0); } else { current_preview = current_color; } } preview_object.update_geometry(current_point, current_sides, current_radius, current_preview, current_z, line, false); for(int i=0; i<objects.size(); i++){ objects[i].update_geometry(objects[i].centroid, objects[i].verticies-1, objects[i].radius, objects[i].color, objects[i].z, objects[i].line, oskar); } ofBackground(current_bk); do { arduino = ofxGetSerialString(serial,';'); //read until end of line if(arduino != ""){ output = arduino; values = ofSplitString(output, " ", true, true); // trues are ignoreempty & trim if(values.size()==20){ current_point.x += ofToInt(values[0]); if(current_point.x > ofGetScreenWidth()+current_radius){ current_point.x = ofGetScreenWidth()+current_radius; } if(current_point.x < -current_radius-5){ current_point.x = -current_radius-5; } current_point.y += -ofToInt(values[1]); if(current_point.y > ofGetScreenHeight()+current_radius){ current_point.y = ofGetScreenHeight()+current_radius; } if(current_point.y < -current_radius-5){ current_point.y = -current_radius-5; } CGPoint point; point.x = current_point.x; point.y = current_point.y; CGWarpMouseCursorPosition(point); if(ofToInt(values[2]) == 1 && j1_up == false){ // J1 UP if(current_object < (objects.size()-1) && objects.size()>0){ current_object++; } else { current_object = 0; } j1_up = true; } else { j1_up = false; } if(ofToInt(values[3]) == 1 && j1_down == false){ // J1 DOWN if((current_object) > -1 && objects.size()>0){ current_object--; } else { current_object = (objects.size()-1); } j1_down = true; } else { j1_down = false; } if(ofToInt(values[4]) == 1 && j1_left == false){ // J1 LEFT if((current_object) > -1 && objects.size()>0){ current_object--; } else { current_object = (objects.size()-1); } j1_left = true; } else { j1_left = false; } if(ofToInt(values[5]) == 1 && j1_right == false){ // J1 RIGHT if(current_object < (objects.size()-1) && objects.size()>0){ current_object++; } else { current_object = 0; } j1_right = true; } else { j1_right = false; } if(ofToInt(values[6]) == 0 && ok_button == false){ // OK button if(current_sides!=0){ if(current_object<0){ if(current_sides!=0){ placeObject(); } } else { edit(); } } ok_button = true; } else { ok_button = false; } if(ofToInt(values[7]) == 0 && delete_button == false){ // DELETE if(current_object>=0){ deleteObject(current_object); } delete_button = true; } else { delete_button = false; } if(values[8] == "0" && j2_up == false){ // J2 UP float bri = current_color.getBrightness(); bri+=step; current_color.setBrightness(bri); j2_up = true; } else { j2_up = false; } if(values[9] == "0" && j2_down == false){ // J2 DOWN float bri = current_color.getBrightness(); bri-=step; current_color.setBrightness(bri); j2_down = true; } else { j2_down = false; } if(values[10] == "0" && j2_left == false){ // J1 LEFT float sat = current_color.getSaturation(); if(sat>step){ sat-=(2*step); current_color.setSaturation(sat); } j2_left = true; } else { j2_left = false; } if(values[11] == "0" && j2_right == false){ // J2 RIGHT float sat = current_color.getSaturation(); if(sat<(255-step)){ sat+=(2*step); current_color.setSaturation(sat); } j2_right = true; } else { j2_right = false; } current_sides = (int)(ofMap(ofToInt(values[12]), 58, 1006, 0, 20)); current_radius = (int)(ofMap(ofToInt(values[13]), 0, 1020, 0, ofGetScreenWidth()/2)); current_color.setHue(ofMap(ofToInt(values[14]), 58, 1021, 0, 255)); current_z = (int)(ofMap(ofToInt(values[15]), 58, 1008, 0, objects.size())); current_alpha = (int)(ofMap(ofToInt(values[16]), 58, 1020, 0, 255)); if(ofToInt(values[17]) == 0 && delete_button == false){ // CLOSE SHAPE line.close(); close = true; } else { close = false; } if(ofToInt(values[18]) == 0 && delete_button == false){ // VERTEX if(current_sides==1){ line.addVertex(current_point); } vertex = true; } else { vertex = false; } if(ofToInt(values[19]) == 0){ // OSKAR MODE oskar = false; } else { oskar = true; } } } if (arduino == "") continue; //do something with str } while (arduino != ""); if(current_sides != 1){ if(line.getArea() != 0){ line.clear(); } } }