diff options
| author | Tim Redfern <tim@getdrop.com> | 2022-09-30 23:24:23 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2022-09-30 23:24:23 +0100 |
| commit | aca6161b1c8ee632e388731084b6158a1483e71a (patch) | |
| tree | d8e039d7d664bfadf836fb45806e8c408288722c /passadesgui/src/ofApp.cpp | |
| parent | a2c919f85c366e02cdc71f0fb46f4ebd4e4afebe (diff) | |
head wreck
Diffstat (limited to 'passadesgui/src/ofApp.cpp')
| -rw-r--r-- | passadesgui/src/ofApp.cpp | 139 |
1 files changed, 129 insertions, 10 deletions
diff --git a/passadesgui/src/ofApp.cpp b/passadesgui/src/ofApp.cpp index 36e0785..e8b8a91 100644 --- a/passadesgui/src/ofApp.cpp +++ b/passadesgui/src/ofApp.cpp @@ -91,7 +91,7 @@ void ofApp::setup(){ drawgui.add(video_speed.setup("playback speed", 1.0, 0.0, 3.0)); drawgui.add(shapes_randomise.setup("randomise shapes", true)); drawgui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 0.8)); - drawgui.add(shapes_duration.setup("shape duration", 5, 0, 25)); + drawgui.add(shapes_duration.setup("shape duration", 5, 0, 250)); drawgui.add(use_mask.setup("use mask", true)); drawgui.add(invert_mask.setup("invert mask", false)); drawgui.add(use_segmenter.setup("use segmenter", false)); @@ -115,7 +115,7 @@ void ofApp::setup(){ audiogui.add(plotter.bars.set("bars",true)); audiogui.add(plotter.mirror.set("mirror",false)); audiogui.add(plotter.width.set("point width", 2, 1, 256)); - audiogui.add(plotter.num_points.set("num points", 50, 1, 64)); + audiogui.add(plotter.num_points.set("num points", 50, 1, 512)); audiogui.add(plotter.history_size.set("num plots", 5, 1, 64)); audiogui.add(plotter.translate.set("translate",ofVec2f(0,0),ofVec2f(-50,-50),ofVec2f(50,50))); audiogui.add(plotter.rotate.set("rotate",0.0f,-10.0f,10.0f)); @@ -128,7 +128,7 @@ void ofApp::setup(){ //============================ MIDI midiIn.listInPorts(); - midiIn.openPort(0); + midiIn.openPort(1); midiIn.addListener(this); //======================================= //positioning interface @@ -755,6 +755,54 @@ void ofApp::drawOutput(ofEventArgs & args){ break; } case SVG_outlines:{ + if (!use_onset||onset_frame<onset_duration||shapes_randomise){ + if (shapes_randomise){ + //if (framecounter==0){ + // select_random_shapes(); + // framecounter=shapes_duration; + //} + select_random_shapes(shapes_duration,!use_onset||onset_frame<onset_duration); + for (auto s:shape_selection){ + if (use_segmenter){ + auto segments=segmenters[s].getSegments(segmenter_number,segmenter_length,phase); + for (auto segment=segments.begin();segment!=segments.end();segment++){ + //polyOutput.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); + polyOutput.push_back(*segment); + } + } + else { + //polyOutput.push_back(colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B))); + polyOutput.push_back(segmenters[s].getPoly()); + } + } + framecounter--; + } + else { + for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ + if (use_segmenter){ + auto segments=shape->getSegments(segmenter_number,segmenter_length,phase); + for (auto segment=segments.begin();segment!=segments.end();segment++){ + //polyOutput.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); + polyOutput.push_back(*segment); + } + } + else { + //polyOutput.push_back(colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B))); + polyOutput.push_back(shape->getPoly()); + } + } + } + if (contour_useColour){ + vector<colourPolyline> newPolys; + for (auto p: polyOutput){ + newPolys.push_back(colourPolyline((ofPolyline)p,ofColor(laser_R,laser_G,laser_B))) ; + } + polyOutput=newPolys; + } + } + break; + } + /*{ if (shapes_randomise){ if (framecounter==0){ select_random_shapes(); @@ -764,11 +812,15 @@ void ofApp::drawOutput(ofEventArgs & args){ if (use_segmenter){ auto segments=segmenters[s].getSegments(segmenter_number,segmenter_length,phase); for (auto segment=segments.begin();segment!=segments.end();segment++){ - polyOutput.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); + polyOutput.push_back(contour_useColour? + colourPolyline(*segment): + colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); } } else { - polyOutput.push_back(colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B))); + polyOutput.push_back(contour_useColour? + colourPolyline(segmenters[s].getPoly()): + colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B))); } } framecounter--; @@ -778,17 +830,21 @@ void ofApp::drawOutput(ofEventArgs & args){ if (use_segmenter){ auto segments=shape->getSegments(segmenter_number,segmenter_length,phase); for (auto segment=segments.begin();segment!=segments.end();segment++){ - polyOutput.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); + polyOutput.push_back(contour_useColour? + colourPolyline(*segment): + colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); } } else { - polyOutput.push_back(colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B))); + polyOutput.push_back(contour_useColour? + colourPolyline(shape->getPoly()): + colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B))); } } } break; - } + }*/ case Audio:{ ofMatrix4x4 x=ofMatrix4x4(1.0f,0.0f,0.0f,0.0f, 0.0f,1.0f,0.0f,0.0f, @@ -1068,7 +1124,49 @@ void ofApp::windowResized(int w, int h){ } -void ofApp::select_random_shapes(){ +float last_frame_time=0.0f; + +void ofApp::select_random_shapes(float duration,bool generate=true){ + float timedelta=ofGetElapsedTimef()-last_frame_time; + last_frame_time=ofGetElapsedTimef(); + //track how long each shape has been selected + for (int i=0;i<shape_selection_durations.size();i++){ + if (shape_selection_durations[i]>0.0f){ + shape_selection_durations[i]=shape_selection_durations[i]-timedelta; + } + } + + shape_selection.clear(); + + for (int i=0;i<shape_selection_durations.size();i++){ + if (shape_selection_durations[i]>0.0f){ + shape_selection.insert(i); + } + } + std::stringstream strom; + for (auto& s:shape_selection){ + strom << s <<":"<<shape_selection_durations[s]<<" "; + } + + //cout << timedelta <<": decay selection: "<<shape_selection.size()<<" shapes (" << strom.str() <<") \n"; + if (generate){ + + while (shape_selection.size()<(segmenters.size()*shapes_amount)){ + int selection=rand()%segmenters.size(); + if (shape_selection.find(selection)==shape_selection.end()){ + shape_selection_durations[selection]=duration+ofRandom(1.0f); + shape_selection.insert(selection); + } + } + std::stringstream strm; + for (auto& s:shape_selection){ + strm << s <<":"<<shape_selection_durations[s]<<" "; + } + } + //cout << "random selection: "<<shape_selection.size()<<" shapes (" << strm.str() <<") \n"; +} +/* +void ofApp::old_select_random_shapes(){ shape_selection.clear(); while (shape_selection.size()<(segmenters.size()*shapes_amount)){ int selection=rand()%segmenters.size(); @@ -1082,6 +1180,7 @@ void ofApp::select_random_shapes(){ } //cout << "randomly selected (" << strm.str() <<") \n"; } +*/ //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ @@ -1108,6 +1207,7 @@ void ofApp::dragEvent(ofDragInfo dragInfo){ if (imagepaths.size()){ segmenters.clear(); + shape_selection_durations.clear(); for (auto& path:imagepaths){ path.setPolyWindingMode(OF_POLY_WINDING_ODD); @@ -1117,12 +1217,31 @@ void ofApp::dragEvent(ofDragInfo dragInfo){ outline.simplify(contour_simplify); strm << outline.size() << " "; segmenters.push_back(lineSegmenter(outline)); + //segmenters.push_back(colourLineSegmenter(outline,path.getStrokeColor())); + shape_selection_durations.push_back(0.0f); } strm << " , "; } + std::stringstream strom; + + shape_selection.clear(); + while (shape_selection.size()<(segmenters.size()*shapes_amount)){ + int selection=(int)ofRandom(0,segmenters.size()); + shape_selection.insert(selection); + } + for (auto s:shape_selection){ + float spawn=(ofRandom(0,(float)shapes_duration)); + shape_selection_durations[s]=spawn; + strom << s << ":"<<spawn<<" "; + } + last_frame_time=ofGetElapsedTimef(); + //cout << "SVG: selected paths [ "<<strom.str() << " ]" <<std::endl; + //cout << "SVG: found " << imagepaths.size() << " paths with " << segmenters.size() << " shapes [ " << strm.str() << " ]" <<std::endl; + //select_random_shapes(shapes_duration); + cout << "SVG: found " << imagepaths.size() << " paths with " << segmenters.size() << " shapes [ " << strm.str() << " ]" <<std::endl; - select_random_shapes(); + select_random_shapes(shapes_duration); } } |
